@nestjs/config
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -16,4 +16,4 @@ "use strict"; | ||
ConfigHostModule = __decorate([ | ||
common_1.Global(), | ||
common_1.Module({ | ||
(0, common_1.Global)(), | ||
(0, common_1.Module)({ | ||
providers: [ | ||
@@ -20,0 +20,0 @@ { |
@@ -0,1 +1,4 @@ | ||
/** | ||
* Injection tokens | ||
*/ | ||
export declare const CONFIGURATION_SERVICE_TOKEN: unique symbol; | ||
@@ -2,0 +5,0 @@ export declare const CONFIGURATION_TOKEN = "CONFIGURATION_TOKEN"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.VALIDATED_ENV_PROPNAME = exports.PARTIAL_CONFIGURATION_PROPNAME = exports.PARTIAL_CONFIGURATION_KEY = exports.VALIDATED_ENV_LOADER = exports.CONFIGURATION_LOADER = exports.CONFIGURATION_TOKEN = exports.CONFIGURATION_SERVICE_TOKEN = void 0; | ||
/** | ||
* Injection tokens | ||
*/ | ||
exports.CONFIGURATION_SERVICE_TOKEN = Symbol('CONFIG_SERVICE'); | ||
@@ -5,0 +8,0 @@ exports.CONFIGURATION_TOKEN = 'CONFIGURATION_TOKEN'; |
import { DynamicModule } from '@nestjs/common'; | ||
import { ConfigFactory, ConfigModuleOptions } from './interfaces'; | ||
export declare class ConfigModule { | ||
/** | ||
* Loads process environment variables depending on the "ignoreEnvFile" flag and "envFilePath" value. | ||
* Also, registers custom configurations globally. | ||
* @param options | ||
*/ | ||
static forRoot(options?: ConfigModuleOptions): DynamicModule; | ||
/** | ||
* Registers configuration object (partial registration). | ||
* @param config | ||
*/ | ||
static forFeature(config: ConfigFactory): DynamicModule; | ||
@@ -6,0 +15,0 @@ private static loadEnvFile; |
@@ -46,2 +46,7 @@ "use strict"; | ||
let ConfigModule = ConfigModule_1 = class ConfigModule { | ||
/** | ||
* Loads process environment variables depending on the "ignoreEnvFile" flag and "envFilePath" value. | ||
* Also, registers custom configurations globally. | ||
* @param options | ||
*/ | ||
static forRoot(options = {}) { | ||
@@ -72,3 +77,3 @@ let validatedEnvConfig = undefined; | ||
const providers = (options.load || []) | ||
.map(factory => create_config_factory_util_1.createConfigProvider(factory)) | ||
.map(factory => (0, create_config_factory_util_1.createConfigProvider)(factory)) | ||
.filter(item => item); | ||
@@ -115,4 +120,8 @@ const configProviderTokens = providers.map(item => item.provide); | ||
} | ||
/** | ||
* Registers configuration object (partial registration). | ||
* @param config | ||
*/ | ||
static forFeature(config) { | ||
const configProvider = create_config_factory_util_1.createConfigProvider(config); | ||
const configProvider = (0, create_config_factory_util_1.createConfigProvider)(config); | ||
const serviceProvider = { | ||
@@ -142,3 +151,3 @@ provide: config_service_1.ConfigService, | ||
? options.envFilePath | ||
: [options.envFilePath || path_1.resolve(process.cwd(), '.env')]; | ||
: [options.envFilePath || (0, path_1.resolve)(process.cwd(), '.env')]; | ||
let config = {}; | ||
@@ -149,3 +158,3 @@ for (const envFilePath of envFilePaths) { | ||
if (options.expandVariables) { | ||
config = dotenv_expand_1.default({ parsed: config }).parsed || config; | ||
config = (0, dotenv_expand_1.default)({ parsed: config }).parsed || config; | ||
} | ||
@@ -157,3 +166,3 @@ } | ||
static assignVariablesToProcess(config) { | ||
if (!util_1.isObject(config)) { | ||
if (!(0, util_1.isObject)(config)) { | ||
return; | ||
@@ -166,4 +175,4 @@ } | ||
const factoryRef = provider.useFactory; | ||
const token = get_registration_token_util_1.getRegistrationToken(factoryRef); | ||
merge_configs_util_1.mergeConfigObject(host, item, token); | ||
const token = (0, get_registration_token_util_1.getRegistrationToken)(factoryRef); | ||
(0, merge_configs_util_1.mergeConfigObject)(host, item, token); | ||
} | ||
@@ -184,3 +193,3 @@ static getSchemaValidationOptions(options) { | ||
ConfigModule = ConfigModule_1 = __decorate([ | ||
common_1.Module({ | ||
(0, common_1.Module)({ | ||
imports: [config_host_module_1.ConfigHostModule], | ||
@@ -187,0 +196,0 @@ providers: [ |
import { NoInferType, Path, PathValue } from './types'; | ||
export interface ConfigGetOptions { | ||
/** | ||
* If present, "get" method will try to automatically | ||
* infer a type of property based on the type argument | ||
* specified at the "ConfigService" class-level (example: ConfigService<Configuration>). | ||
*/ | ||
infer: true; | ||
@@ -12,6 +17,32 @@ } | ||
constructor(internalConfig?: Record<string, any>); | ||
/** | ||
* Get a configuration value (either custom configuration or process environment variable) | ||
* based on property path (you can use dot notation to traverse nested object, e.g. "database.host"). | ||
* @param propertyPath | ||
*/ | ||
get<T = any>(propertyPath: keyof K): T | undefined; | ||
/** | ||
* Get a configuration value (either custom configuration or process environment variable) | ||
* based on property path (you can use dot notation to traverse nested object, e.g. "database.host"). | ||
* @param propertyPath | ||
* @param options | ||
*/ | ||
get<T = K, P extends Path<T> = any, R = PathValue<T, P>>(propertyPath: P, options: ConfigGetOptions): R | undefined; | ||
/** | ||
* Get a configuration value (either custom configuration or process environment variable) | ||
* based on property path (you can use dot notation to traverse nested object, e.g. "database.host"). | ||
* It returns a default value if the key does not exist. | ||
* @param propertyPath | ||
* @param defaultValue | ||
*/ | ||
get<T = any>(propertyPath: keyof K, defaultValue: NoInferType<T>): T; | ||
get<T = K, P extends Path<T> = any, R = PathValue<T, P>>(propertyPath: P, defaultValue: NoInferType<R>, options: ConfigGetOptions): R | undefined; | ||
/** | ||
* Get a configuration value (either custom configuration or process environment variable) | ||
* based on property path (you can use dot notation to traverse nested object, e.g. "database.host"). | ||
* It returns a default value if the key does not exist. | ||
* @param propertyPath | ||
* @param defaultValue | ||
* @param options | ||
*/ | ||
get<T = K, P extends Path<T> = any, R = PathValue<T, P>>(propertyPath: P, defaultValue: NoInferType<R>, options: ConfigGetOptions): R; | ||
private getFromCache; | ||
@@ -18,0 +49,0 @@ private getFromValidatedEnv; |
@@ -37,5 +37,12 @@ "use strict"; | ||
} | ||
/** | ||
* Get a configuration value (either custom configuration or process environment variable) | ||
* based on property path (you can use dot notation to traverse nested object, e.g. "database.host"). | ||
* It returns a default value if the key does not exist. | ||
* @param propertyPath | ||
* @param defaultValueOrOptions | ||
*/ | ||
get(propertyPath, defaultValueOrOptions, options) { | ||
const validatedEnvValue = this.getFromValidatedEnv(propertyPath); | ||
if (!shared_utils_1.isUndefined(validatedEnvValue)) { | ||
if (!(0, shared_utils_1.isUndefined)(validatedEnvValue)) { | ||
return validatedEnvValue; | ||
@@ -47,7 +54,7 @@ } | ||
const processEnvValue = this.getFromProcessEnv(propertyPath, defaultValue); | ||
if (!shared_utils_1.isUndefined(processEnvValue)) { | ||
if (!(0, shared_utils_1.isUndefined)(processEnvValue)) { | ||
return processEnvValue; | ||
} | ||
const internalValue = this.getFromInternalConfig(propertyPath); | ||
if (!shared_utils_1.isUndefined(internalValue)) { | ||
if (!(0, shared_utils_1.isUndefined)(internalValue)) { | ||
return internalValue; | ||
@@ -58,4 +65,4 @@ } | ||
getFromCache(propertyPath, defaultValue) { | ||
const cachedValue = lodash_get_1.default(this.cache, propertyPath); | ||
return shared_utils_1.isUndefined(cachedValue) | ||
const cachedValue = (0, lodash_get_1.default)(this.cache, propertyPath); | ||
return (0, shared_utils_1.isUndefined)(cachedValue) | ||
? defaultValue | ||
@@ -65,3 +72,3 @@ : cachedValue; | ||
getFromValidatedEnv(propertyPath) { | ||
const validatedEnvValue = lodash_get_1.default(this.internalConfig[config_constants_1.VALIDATED_ENV_PROPNAME], propertyPath); | ||
const validatedEnvValue = (0, lodash_get_1.default)(this.internalConfig[config_constants_1.VALIDATED_ENV_PROPNAME], propertyPath); | ||
return validatedEnvValue; | ||
@@ -71,7 +78,7 @@ } | ||
if (this.isCacheEnabled && | ||
lodash_has_1.default(this.cache, propertyPath)) { | ||
(0, lodash_has_1.default)(this.cache, propertyPath)) { | ||
const cachedValue = this.getFromCache(propertyPath, defaultValue); | ||
return !shared_utils_1.isUndefined(cachedValue) ? cachedValue : defaultValue; | ||
return !(0, shared_utils_1.isUndefined)(cachedValue) ? cachedValue : defaultValue; | ||
} | ||
const processValue = lodash_get_1.default(process.env, propertyPath); | ||
const processValue = (0, lodash_get_1.default)(process.env, propertyPath); | ||
this.setInCacheIfDefined(propertyPath, processValue); | ||
@@ -81,3 +88,3 @@ return processValue; | ||
getFromInternalConfig(propertyPath) { | ||
const internalValue = lodash_get_1.default(this.internalConfig, propertyPath); | ||
const internalValue = (0, lodash_get_1.default)(this.internalConfig, propertyPath); | ||
return internalValue; | ||
@@ -89,3 +96,3 @@ } | ||
} | ||
lodash_set_1.default(this.cache, propertyPath, value); | ||
(0, lodash_set_1.default)(this.cache, propertyPath, value); | ||
} | ||
@@ -97,7 +104,7 @@ isGetOptionsObject(options) { | ||
ConfigService = __decorate([ | ||
common_1.Injectable(), | ||
__param(0, common_1.Optional()), | ||
__param(0, common_1.Inject(config_constants_1.CONFIGURATION_TOKEN)), | ||
(0, common_1.Injectable)(), | ||
__param(0, (0, common_1.Optional)()), | ||
__param(0, (0, common_1.Inject)(config_constants_1.CONFIGURATION_TOKEN)), | ||
__metadata("design:paramtypes", [Object]) | ||
], ConfigService); | ||
exports.ConfigService = ConfigService; |
import { ConfigFactory } from './config-factory.interface'; | ||
export interface ConfigModuleOptions { | ||
/** | ||
* If "true", values from the process.env object will be cached in the memory. | ||
* This improves the overall application performance. | ||
* See: https://github.com/nodejs/node/issues/3104 | ||
*/ | ||
cache?: boolean; | ||
/** | ||
* If "true", registers `ConfigModule` as a global module. | ||
* See: https://docs.nestjs.com/modules#global-modules | ||
*/ | ||
isGlobal?: boolean; | ||
/** | ||
* If "true", environment files (`.env`) will be ignored. | ||
*/ | ||
ignoreEnvFile?: boolean; | ||
/** | ||
* If "true", predefined environment variables will not be validated. | ||
*/ | ||
ignoreEnvVars?: boolean; | ||
/** | ||
* Path to the environment file(s) to be loaded. | ||
*/ | ||
envFilePath?: string | string[]; | ||
/** | ||
* Environment file encoding. | ||
*/ | ||
encoding?: string; | ||
/** | ||
* Custom function to validate environment variables. It takes an object containing environment | ||
* variables as input and outputs validated environment variables. | ||
* If exception is thrown in the function it would prevent the application from bootstrapping. | ||
* Also, environment variables can be edited through this function, changes | ||
* will be reflected in the process.env object. | ||
*/ | ||
validate?: (config: Record<string, any>) => Record<string, any>; | ||
/** | ||
* Environment variables validation schema (Joi). | ||
*/ | ||
validationSchema?: any; | ||
/** | ||
* Schema validation options. | ||
* See: https://joi.dev/api/?v=17.3.0#anyvalidatevalue-options | ||
*/ | ||
validationOptions?: Record<string, any>; | ||
/** | ||
* Array of custom configuration files to be loaded. | ||
* See: https://docs.nestjs.com/techniques/configuration | ||
*/ | ||
load?: Array<ConfigFactory>; | ||
/** | ||
* A boolean value indicating the use of expanded variables. | ||
* If .env contains expanded variables, they'll only be parsed if | ||
* this property is set to true. | ||
*/ | ||
expandVariables?: boolean; | ||
} |
@@ -7,5 +7,5 @@ "use strict"; | ||
function createConfigProvider(factory) { | ||
const uniqId = uuid_1.v4(); | ||
const uniqId = (0, uuid_1.v4)(); | ||
return { | ||
provide: factory.KEY || get_config_token_util_1.getConfigToken(uniqId), | ||
provide: factory.KEY || (0, get_config_token_util_1.getConfigToken)(uniqId), | ||
useFactory: factory, | ||
@@ -12,0 +12,0 @@ inject: [], |
@@ -10,3 +10,3 @@ "use strict"; | ||
if (token) { | ||
lodash_set_1.default(host, token, partial); | ||
(0, lodash_set_1.default)(host, token, partial); | ||
return partial; | ||
@@ -13,0 +13,0 @@ } |
@@ -6,2 +6,5 @@ import { ConfigFactory } from '../interfaces'; | ||
}; | ||
/** | ||
* Registers the configuration object behind a specified token. | ||
*/ | ||
export declare function registerAs<TConfig extends ConfigObject, TFactory extends ConfigFactory = ConfigFactory<TConfig>>(token: string, configFactory: TFactory): TFactory & ConfigFactoryKeyHost; |
@@ -6,2 +6,5 @@ "use strict"; | ||
const get_config_token_util_1 = require("./get-config-token.util"); | ||
/** | ||
* Registers the configuration object behind a specified token. | ||
*/ | ||
function registerAs(token, configFactory) { | ||
@@ -17,3 +20,3 @@ Object.defineProperty(configFactory, config_constants_1.PARTIAL_CONFIGURATION_KEY, { | ||
enumerable: false, | ||
value: get_config_token_util_1.getConfigToken(token), | ||
value: (0, get_config_token_util_1.getConfigToken)(token), | ||
writable: false, | ||
@@ -20,0 +23,0 @@ }); |
{ | ||
"name": "@nestjs/config", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Nest - modern, fast, powerful node.js web framework (@config)", | ||
@@ -29,9 +29,9 @@ "author": "Kamil Mysliwiec", | ||
"devDependencies": { | ||
"@commitlint/cli": "12.1.4", | ||
"@commitlint/config-angular": "12.1.4", | ||
"@nestjs/common": "8.0.4", | ||
"@nestjs/core": "8.0.4", | ||
"@nestjs/platform-express": "8.0.4", | ||
"@nestjs/testing": "8.0.4", | ||
"@types/jest": "26.0.24", | ||
"@commitlint/cli": "13.2.0", | ||
"@commitlint/config-angular": "13.2.0", | ||
"@nestjs/common": "8.0.9", | ||
"@nestjs/core": "8.0.9", | ||
"@nestjs/platform-express": "8.0.9", | ||
"@nestjs/testing": "8.0.9", | ||
"@types/jest": "27.0.2", | ||
"@types/lodash.get": "4.4.6", | ||
@@ -42,18 +42,18 @@ "@types/lodash.has": "4.5.6", | ||
"@types/uuid": "8.3.1", | ||
"@typescript-eslint/eslint-plugin": "4.28.4", | ||
"@typescript-eslint/parser": "4.28.4", | ||
"eslint": "7.31.0", | ||
"@typescript-eslint/eslint-plugin": "4.32.0", | ||
"@typescript-eslint/parser": "4.32.0", | ||
"eslint": "7.32.0", | ||
"eslint-config-prettier": "8.3.0", | ||
"eslint-plugin-import": "2.23.4", | ||
"husky": "7.0.1", | ||
"jest": "27.0.6", | ||
"joi": "17.4.1", | ||
"lint-staged": "11.0.1", | ||
"prettier": "2.3.2", | ||
"eslint-plugin-import": "2.24.2", | ||
"husky": "7.0.2", | ||
"jest": "27.2.4", | ||
"joi": "17.4.2", | ||
"lint-staged": "11.1.2", | ||
"prettier": "2.4.1", | ||
"reflect-metadata": "0.1.13", | ||
"release-it": "14.10.0", | ||
"release-it": "14.11.6", | ||
"rimraf": "3.0.2", | ||
"rxjs": "7.2.0", | ||
"ts-jest": "27.0.4", | ||
"typescript": "4.3.5" | ||
"rxjs": "7.3.1", | ||
"ts-jest": "27.0.5", | ||
"typescript": "4.4.3" | ||
}, | ||
@@ -60,0 +60,0 @@ "peerDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38221
735