This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+9
View File
@@ -0,0 +1,9 @@
# The MIT License
Copyright 2022 Harminder Virk, contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+53
View File
@@ -0,0 +1,53 @@
<div align="center">
<img src="https://res.cloudinary.com/adonisjs/image/upload/q_100/v1558612869/adonis-readme_zscycu.jpg" width="600px">
</div>
<br />
<div align="center">
<h3>AdonisJS Config Provider</h3>
<p>Config provider to read AdonisJS application config values without directly relying on hard-coded paths</p>
</div>
<br />
<div align="center">
[![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![synk-image]][synk-url]
</div>
<div align="center">
<h3>
<a href="https://adonisjs.com">
Website
</a>
<span> | </span>
<a href="https://docs.adonisjs.com/guides/config">
Guides
</a>
<span> | </span>
<a href="CONTRIBUTING.md">
Contributing
</a>
</h3>
</div>
<div align="center">
<sub>Built with ❤︎ by <a href="https://twitter.com/AmanVirk1">Harminder Virk</a>
</div>
[gh-workflow-image]: https://img.shields.io/github/workflow/status/adonisjs/config/test?style=for-the-badge
[gh-workflow-url]: https://github.com/adonisjs/config/actions/workflows/test.yml "Github action"
[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
[typescript-url]: "typescript"
[npm-image]: https://img.shields.io/npm/v/@adonisjs/config.svg?style=for-the-badge&logo=npm
[npm-url]: https://npmjs.org/package/@adonisjs/config "npm"
[license-image]: https://img.shields.io/npm/l/@adonisjs/config?color=blueviolet&style=for-the-badge
[license-url]: LICENSE.md "license"
[synk-image]: https://img.shields.io/snyk/vulnerabilities/github/adonisjs/config?label=Synk%20Vulnerabilities&style=for-the-badge
[synk-url]: https://snyk.io/test/github/adonisjs/config?targetFile=package.json "synk"
+68
View File
@@ -0,0 +1,68 @@
declare module '@ioc:Adonis/Core/Config' {
/**
* The config module de-couples the application configuration from the filesystem
* and offers a unified API to read the application configuration. For example:
*
* If a module `X` relies on the `config/database.ts` file, instead of requiring
* it directly from the filesystem, it should use the `ConfigProvider` to
* read the config as `Config.get('database')`.
*
* The values for a specific object property can be read using the dot-notation.
* `Config.get('database.connections.mysql')`.
*
* @singleton
*
* @example
* ```ts
* import Config from '@ioc:Adonis/Core/Config'
* ```
*/
export interface ConfigContract {
/**
* Returns complete config
*/
all(): any;
/**
* Get configuration from a config file and optionally access the object
* properties using the `dot notation`.
*
* @example
* ```ts
* // will read from the `config/database.ts` file
* Config.get('database')
*
* // access `connections.mysql` property
* Config.get('database.connections.mysql')
* ```
*/
get(key: string, defaultValue?: any): any;
/**
* Similar to `Config.get`, but you can also define default values, which
* are merged with the user defined values.
*
* The user defined values are preferred over the default values.
*/
merge(key: string, defaultValues: object, customizer?: Function): any;
/**
* Set/update value for a given path
*/
set(key: string, value: any): void;
/**
* Define default values for a given path. The user defined values will be
* merged with the default values.
*
* This method is mainly used by the providers and not in the user land.
*
* @example
* ```ts
* Config.defaults('database', {
* connection: 'mysql',
* connections: {},
* })
* ```
*/
defaults(key: string, value: any): void;
}
const Config: ConfigContract;
export default Config;
}
+8
View File
@@ -0,0 +1,8 @@
/*
* @adonisjs/config
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
+1
View File
@@ -0,0 +1 @@
export { Config } from './src/Config';
+13
View File
@@ -0,0 +1,13 @@
"use strict";
/*
* @adonisjs/config
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Config = void 0;
var Config_1 = require("./src/Config");
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return Config_1.Config; } });
+82
View File
@@ -0,0 +1,82 @@
/// <reference path="../adonis-typings/config.d.ts" />
import { ConfigContract } from '@ioc:Adonis/Core/Config';
/**
* Config module eases the process of using configuration inside your AdonisJs
* applications.
*
* The config files are stored inside a seperate directory, which are loaded and cached
* on application boot. Later you can access the values using the `dot` syntax.
*
* ## Access values
*
* 1. **Given the config file is stored as `config/app.js` with following content**
*
* ```js
* module.exports = {
* appKey: ''
* }
* ```
*
* 2. **You access the appKey as follows**
*
* ```js
* Config.get('app.appKey')
* ```
*
* **NOTE:**
* The `get` method doesn't raise runtime exceptions when top level objects are missing.
*/
export declare class Config implements ConfigContract {
private config;
constructor(config?: {});
/**
* Returns complete config
*/
all(): {};
/**
* Read value from the pre-loaded config. Make use of the `dot notation`
* syntax to read nested values.
*
* The `defaultValue` is returned when original value is `undefined`.
*
* @example
* ```js
* Config.get('database.mysql')
* ```
*/
get(key: string, defaultValue?: any): any;
/**
* Fetch and merge an object to the existing config. This method is useful
* when you are fetching an object from the config and want to merge
* it with some default values.
*
* An optional customizer can be passed to customize the merge operation.
* The function is directly passed to [lodash.mergeWith](https://lodash.com/docs/4.17.10#mergeWith)
* method.
*
* @example
* ```js
* // Config inside the file will be merged with the given object
*
* Config.merge('database.mysql', {
* host: '127.0.0.1',
* port: 3306
* })
* ```
*/
merge(key: string, defaultValues: object, customizer?: (...args: any[]) => any): any;
/**
* Defaults allows providers to define the default config for a
* module, which is merged with the user config
*/
defaults(key: string, value: any): void;
/**
* Update in memory value of the pre-loaded config
*
* @example
* ```js
* Config.set('database.host', '127.0.0.1')
* ```
*/
set(key: string, value: any): void;
}
+109
View File
@@ -0,0 +1,109 @@
"use strict";
/*
* @adonisjs/config
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Config = void 0;
/// <reference path="../adonis-typings/config.ts" />
const utils_1 = require("@poppinss/utils");
/**
* Config module eases the process of using configuration inside your AdonisJs
* applications.
*
* The config files are stored inside a seperate directory, which are loaded and cached
* on application boot. Later you can access the values using the `dot` syntax.
*
* ## Access values
*
* 1. **Given the config file is stored as `config/app.js` with following content**
*
* ```js
* module.exports = {
* appKey: ''
* }
* ```
*
* 2. **You access the appKey as follows**
*
* ```js
* Config.get('app.appKey')
* ```
*
* **NOTE:**
* The `get` method doesn't raise runtime exceptions when top level objects are missing.
*/
class Config {
constructor(config = {}) {
this.config = config;
}
/**
* Returns complete config
*/
all() {
return this.config;
}
/**
* Read value from the pre-loaded config. Make use of the `dot notation`
* syntax to read nested values.
*
* The `defaultValue` is returned when original value is `undefined`.
*
* @example
* ```js
* Config.get('database.mysql')
* ```
*/
get(key, defaultValue) {
return utils_1.lodash.get(this.config, key, defaultValue);
}
/**
* Fetch and merge an object to the existing config. This method is useful
* when you are fetching an object from the config and want to merge
* it with some default values.
*
* An optional customizer can be passed to customize the merge operation.
* The function is directly passed to [lodash.mergeWith](https://lodash.com/docs/4.17.10#mergeWith)
* method.
*
* @example
* ```js
* // Config inside the file will be merged with the given object
*
* Config.merge('database.mysql', {
* host: '127.0.0.1',
* port: 3306
* })
* ```
*/
merge(key, defaultValues, customizer) {
return utils_1.lodash.mergeWith(defaultValues, this.get(key), customizer);
}
/**
* Defaults allows providers to define the default config for a
* module, which is merged with the user config
*/
defaults(key, value) {
const existingValue = this.get(key);
if (existingValue) {
utils_1.lodash.mergeWith(value, existingValue);
}
this.set(key, value);
}
/**
* Update in memory value of the pre-loaded config
*
* @example
* ```js
* Config.set('database.host', '127.0.0.1')
* ```
*/
set(key, value) {
utils_1.lodash.set(this.config, key, value);
}
}
exports.Config = Config;
+134
View File
@@ -0,0 +1,134 @@
{
"name": "@adonisjs/config",
"version": "3.0.9",
"description": "Config management for AdonisJS framework",
"main": "build/index.js",
"files": [
"build/adonis-typings",
"build/src",
"build/index.d.ts",
"build/index.js"
],
"scripts": {
"mrm": "mrm --preset=@adonisjs/mrm-preset",
"pretest": "npm run lint",
"test": "node -r @adonisjs/require-ts/build/register bin/test.ts",
"version": "npm run build",
"clean": "del build",
"compile": "npm run lint && npm run clean && tsc",
"build": "npm run compile",
"commit": "git-cz",
"release": "np --message=\"chore(release): %s\"",
"format": "prettier --write .",
"prepublishOnly": "npm run build",
"lint": "eslint . --ext=.ts",
"sync-labels": "github-label-sync --labels ./node_modules/@adonisjs/mrm-preset/gh-labels.json adonisjs/config"
},
"keywords": [
"config",
"adonisjs"
],
"author": "virk,adonisjs",
"license": "MIT",
"devDependencies": {
"@adonisjs/mrm-preset": "^5.0.3",
"@adonisjs/require-ts": "^2.0.13",
"@japa/assert": "^1.3.6",
"@japa/run-failed-tests": "^1.1.0",
"@japa/runner": "^2.2.2",
"@japa/spec-reporter": "^1.3.2",
"@types/node": "^18.11.2",
"commitizen": "^4.2.5",
"cz-conventional-changelog": "^3.3.0",
"del-cli": "^5.0.0",
"eslint": "^8.25.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-adonis": "^2.1.1",
"eslint-plugin-prettier": "^4.2.1",
"github-label-sync": "^2.2.0",
"husky": "^8.0.1",
"mrm": "^4.1.13",
"np": "^7.6.2",
"prettier": "^2.7.1",
"typescript": "^4.8.4"
},
"nyc": {
"exclude": [
"test"
],
"extension": [
".ts"
]
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"np": {
"contents": ".",
"anyBranch": false
},
"dependencies": {
"@poppinss/utils": "^5.0.0"
},
"directories": {
"doc": "docs",
"test": "test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/adonisjs/config.git"
},
"bugs": {
"url": "https://github.com/adonisjs/config/issues"
},
"homepage": "https://github.com/adonisjs/config#readme",
"publishConfig": {
"access": "public",
"tag": "latest"
},
"mrmConfig": {
"core": true,
"license": "MIT",
"services": [
"github-actions"
],
"minNodeVersion": "14.15.4",
"probotApps": [
"stale",
"lock"
],
"runGhActionsOnWindows": false
},
"eslintConfig": {
"extends": [
"plugin:adonis/typescriptPackage",
"prettier"
],
"plugins": [
"prettier"
],
"rules": {
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
]
}
},
"eslintIgnore": [
"build"
],
"prettier": {
"trailingComma": "es5",
"semi": false,
"singleQuote": true,
"useTabs": false,
"quoteProps": "consistent",
"bracketSpacing": true,
"arrowParens": "always",
"printWidth": 100
}
}