env-typed-config
Version:
Intuitive, type-safe configuration library for Node.js
37 lines (34 loc) • 1.44 kB
TypeScript
import { ClassConstructor } from 'class-transformer';
import { ValidatorOptions } from 'class-validator';
declare type RawConfig = Record<string, any>;
declare type ConfigLoader = () => RawConfig;
interface TypedConfigOptions<T extends object> {
/**
* The root object for application configuration.
*/
schema: ClassConstructor<T>;
/**
* Function(s) to load configurations, must be synchronous.
*/
load: ConfigLoader | ConfigLoader[];
/**
* Custom function to validate configurations. It takes an object containing environment
* variables as input and outputs validated configurations.
* If exception is thrown in the function it would prevent the application from bootstrapping.
*/
validate?: (config: Record<string, any>) => Record<string, any>;
/**
* Custom function to normalize configurations. It takes an object containing environment
* variables as input and outputs normalized configurations.
*
* This function is executed before validation, and can be used to do type casting,
* variable expanding, etc.
*/
normalize?: (config: Record<string, any>) => Record<string, any>;
/**
* Options passed to validator during validation.
* @see https://github.com/typestack/class-validator
*/
validationOptions?: ValidatorOptions;
}
export { ConfigLoader, RawConfig, TypedConfigOptions };