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
+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;