UNPKG

@nestjs/config

Version:

Nest - modern, fast, powerful node.js web framework (@config)

27 lines (26 loc) • 956 B
import { ConfigModule } from '../index.js'; import { AS_PROVIDER_METHOD_KEY, PARTIAL_CONFIGURATION_KEY, PARTIAL_CONFIGURATION_PROPNAME, } from '../config.constants.js'; import { getConfigToken } from './get-config-token.util.js'; /** * @publicApi * * Registers the configuration object behind a specified token. */ export function registerAs(token, configFactory) { const defineProperty = (key, value) => { Object.defineProperty(configFactory, key, { configurable: false, enumerable: false, value, writable: false, }); }; defineProperty(PARTIAL_CONFIGURATION_KEY, token); defineProperty(PARTIAL_CONFIGURATION_PROPNAME, getConfigToken(token)); defineProperty(AS_PROVIDER_METHOD_KEY, () => ({ imports: [ConfigModule.forFeature(configFactory)], useFactory: (config) => config, inject: [getConfigToken(token)], })); return configFactory; }