@nestjs/config
Advanced tools
Comparing version 0.0.4 to 0.0.5
export declare const CONFIGURATION_SERVICE_TOKEN: unique symbol; | ||
export declare const CONFIGURATION_TOKEN = "CONFIGURATION_TOKEN"; | ||
export declare const CONFIGURATION_LOADER = "CONFIGURATION_LOADER"; | ||
export declare const CONFIGURATION_NAMESPACE = "CONFIGURATION_NAMESPACE"; | ||
export declare const PARTIAL_CONFIGURATION_KEY = "PARTIAL_CONFIGURATION"; |
@@ -6,2 +6,2 @@ "use strict"; | ||
exports.CONFIGURATION_LOADER = 'CONFIGURATION_LOADER'; | ||
exports.CONFIGURATION_NAMESPACE = 'CONFIGURATION_NAMESPACE'; | ||
exports.PARTIAL_CONFIGURATION_KEY = 'PARTIAL_CONFIGURATION'; |
import { DynamicModule } from '@nestjs/common'; | ||
export interface ConfigModuleOptions { | ||
isGlobal?: boolean; | ||
ignoreEnvFile?: boolean; | ||
envFilePath?: string; | ||
encoding?: string; | ||
validationSchema?: any; | ||
load?: Array<Record<string, any>>; | ||
} | ||
import { FactoryProvider } from '@nestjs/common/interfaces'; | ||
import { ConfigFactory, ConfigModuleOptions } from './interfaces'; | ||
export declare class ConfigModule { | ||
static forRoot(options?: ConfigModuleOptions): DynamicModule; | ||
static forFeature(config: Record<string, any>): { | ||
static forFeature(config: ConfigFactory): { | ||
module: typeof ConfigModule; | ||
providers: ({ | ||
provide: string; | ||
useValue: Record<string, any>; | ||
} | { | ||
provide: string; | ||
useFactory: (configHost: Record<string, any>) => void; | ||
inject: string[]; | ||
})[]; | ||
exports: { | ||
provide: string; | ||
useValue: Record<string, any>; | ||
}[]; | ||
providers: FactoryProvider<any>[]; | ||
}; | ||
private static loadEnvFile; | ||
private static assignVariablesToProcess; | ||
private static mergePartial; | ||
} |
@@ -24,3 +24,3 @@ "use strict"; | ||
const config_service_1 = require("./config.service"); | ||
const utils_1 = require("./utils"); | ||
const create_config_factory_util_1 = require("./utils/create-config-factory.util"); | ||
const get_registration_token_util_1 = require("./utils/get-registration-token.util"); | ||
@@ -48,19 +48,11 @@ const merge_configs_util_1 = require("./utils/merge-configs.util"); | ||
} | ||
const hasConfigsToLoad = options.load && options.load.length; | ||
const isConfigToLoad = options.load && options.load.length; | ||
const providers = (options.load || []) | ||
.map(item => { | ||
const token = get_registration_token_util_1.getRegistrationToken(item); | ||
if (!token) { | ||
return undefined; | ||
} | ||
return { | ||
provide: utils_1.getConfigToken(token), | ||
useValue: item, | ||
}; | ||
}) | ||
.map(factory => create_config_factory_util_1.createConfigProvider(factory)) | ||
.filter(item => item); | ||
const configProviderTokens = providers.map(item => item.provide); | ||
return { | ||
module: ConfigModule_1, | ||
global: options.isGlobal, | ||
providers: hasConfigsToLoad | ||
providers: isConfigToLoad | ||
? [ | ||
@@ -70,35 +62,25 @@ ...providers, | ||
provide: config_constants_1.CONFIGURATION_LOADER, | ||
useFactory: (configHost) => { | ||
options.load.forEach(item => merge_configs_util_1.mergeConfigObjects(configHost, item)); | ||
useFactory: (host, ...configurations) => { | ||
configurations.forEach((item, index) => this.mergePartial(host, item, providers[index])); | ||
}, | ||
inject: [config_constants_1.CONFIGURATION_TOKEN], | ||
inject: [config_constants_1.CONFIGURATION_TOKEN, ...configProviderTokens], | ||
}, | ||
] | ||
: providers, | ||
exports: [...providers], | ||
}; | ||
} | ||
static forFeature(config) { | ||
const token = get_registration_token_util_1.getRegistrationToken(config); | ||
const providers = token | ||
? [ | ||
{ | ||
provide: utils_1.getConfigToken(token), | ||
useValue: config, | ||
}, | ||
] | ||
: []; | ||
const configProvider = create_config_factory_util_1.createConfigProvider(config); | ||
return { | ||
module: ConfigModule_1, | ||
providers: [ | ||
...providers, | ||
configProvider, | ||
{ | ||
provide: config_constants_1.CONFIGURATION_LOADER, | ||
useFactory: (configHost) => { | ||
merge_configs_util_1.mergeConfigObjects(configHost, config); | ||
useFactory: (host, partialConfig) => { | ||
this.mergePartial(host, partialConfig, configProvider); | ||
}, | ||
inject: [config_constants_1.CONFIGURATION_TOKEN], | ||
inject: [config_constants_1.CONFIGURATION_TOKEN, configProvider.provide], | ||
}, | ||
], | ||
exports: [...providers], | ||
}; | ||
@@ -119,2 +101,7 @@ } | ||
} | ||
static mergePartial(host, item, provider) { | ||
const factoryRef = provider.useFactory; | ||
const token = get_registration_token_util_1.getRegistrationToken(factoryRef); | ||
merge_configs_util_1.mergeConfigObject(host, item, token); | ||
} | ||
}; | ||
@@ -121,0 +108,0 @@ ConfigModule = ConfigModule_1 = __decorate([ |
@@ -5,4 +5,4 @@ "use strict"; | ||
function getRegistrationToken(config) { | ||
return config[config_constants_1.CONFIGURATION_NAMESPACE]; | ||
return config[config_constants_1.PARTIAL_CONFIGURATION_KEY]; | ||
} | ||
exports.getRegistrationToken = getRegistrationToken; |
@@ -1,1 +0,1 @@ | ||
export declare function mergeConfigObjects(configHost: Record<string, any>, obj: Record<string, any>): Record<string, any> | undefined; | ||
export declare function mergeConfigObject(host: Record<string, any>, partial: Record<string, any>, token?: string): Record<string, any> | undefined; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const get_registration_token_util_1 = require("./get-registration-token.util"); | ||
function mergeConfigObjects(configHost, obj) { | ||
const token = get_registration_token_util_1.getRegistrationToken(obj); | ||
function mergeConfigObject(host, partial, token) { | ||
if (token) { | ||
return (configHost[token] = obj); | ||
return (host[token] = partial); | ||
} | ||
Object.assign(configHost, obj); | ||
Object.assign(host, partial); | ||
} | ||
exports.mergeConfigObjects = mergeConfigObjects; | ||
exports.mergeConfigObject = mergeConfigObject; |
@@ -1,1 +0,2 @@ | ||
export declare function registerAs(token: string, config: Record<string, any>): Record<string, any>; | ||
import { ConfigFactory } from '../interfaces'; | ||
export declare function registerAs(token: string, configFactory: ConfigFactory): ConfigFactory; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const config_constants_1 = require("../config.constants"); | ||
function registerAs(token, config) { | ||
Object.defineProperty(config, config_constants_1.CONFIGURATION_NAMESPACE, { | ||
function registerAs(token, configFactory) { | ||
Object.defineProperty(configFactory, config_constants_1.PARTIAL_CONFIGURATION_KEY, { | ||
configurable: false, | ||
@@ -11,4 +11,4 @@ enumerable: false, | ||
}); | ||
return config; | ||
return configFactory; | ||
} | ||
exports.registerAs = registerAs; |
{ | ||
"name": "@nestjs/config", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Nest - modern, fast, powerful node.js web framework (@config)", | ||
@@ -18,3 +18,4 @@ "author": "Kamil Mysliwiec", | ||
"dotenv": "8.2.0", | ||
"lodash.get": "4.4.2" | ||
"lodash.get": "4.4.2", | ||
"uuid": "^3.3.3" | ||
}, | ||
@@ -32,2 +33,3 @@ "devDependencies": { | ||
"@types/node": "7.10.8", | ||
"@types/uuid": "^3.4.6", | ||
"husky": "3.1.0", | ||
@@ -34,0 +36,0 @@ "jest": "24.9.0", |
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
19332
32
326
6
20
+ Addeduuid@^3.3.3
+ Addeduuid@3.4.0(transitive)