export interface ILogger { log(msg: string, data?: any): void; warn(msg: string, data?: any): void; error(msg: string, data?: any): void; } export interface IVariable { onValue(callback: (val: T) => void): void; onError(callback: (err: Error) => void): void; current(): T | null; previous(): T | null; } export interface IRemoteOptions { [name: string]: any; } export interface ISchemaMap { [key: string]: object; } export interface IConfigOptions { configPath?: string; configEnv?: string; remoteOptions?: IRemoteOptions; resolvers?: IResolverMap; loaders?: Array; translators?: Array; schemas?: ISchemaMap; } export interface IConsulOptions { consulAddress?: string; consulDc?: string; consulKeys?: string; consulNamespace?: string; } export interface IRemoteOverrides { key: string; [name: string]: string; } export interface IConfigStore { get(key: string): T | null; getAll(...args: Array): Array; getWithDefault(key: string, defaultVal: T): T; } export interface IDynamicConfig { get(key?: string): Promise; watch(key?: string): IVariable; getAll(...args: Array): Promise>; getWithDefault(key: string, defaultVal: T): Promise; getRemoteValue(key: string): Promise; getSecretValue(key: string): Promise; } export interface IConfigTranslator { translate(configValue: any): any; } export declare type ITranslator = (obj: any) => any; export interface IFileLoader { type: string | Array; load(filePath: string): Promise; } export interface ILoadedFile { name: string; config: object; } export interface IResolvers { env: IRemoteResolver; process: IRemoteResolver; remote?: IRemoteResolver; secret?: IRemoteResolver; } export interface IResolverMap { remote?: IRemoteResolver; secret?: IRemoteResolver; } export interface INamedResolvers { [name: string]: IRemoteResolver; } export declare type SetFunction = (key: string, value: T) => void; export declare type RemoteInitializer = (config: IConfigStore, remoteOptions?: IRemoteOptions) => Promise; export declare type ResolverType = 'remote' | 'secret'; export interface IRemoteResolver { type: ResolverType; name: string; init: RemoteInitializer; get(key: string, type?: ObjectType, altKey?: string): Promise; watch(key: string, cb: WatchFunction, type?: ObjectType, altKey?: string): void; } export declare type SourceType = 'local' | 'remote' | 'secret' | 'env' | 'process'; export interface ISource { type: SourceType; name: string; key?: string; altKey?: string; } export declare type ConfigType = 'root' | ObjectType | DeferredType | InvalidType; export declare type ObjectType = 'object' | 'array' | 'string' | 'number' | 'boolean' | 'null'; export declare type DeferredType = 'promise' | 'placeholder'; export declare type InvalidType = 'invalid'; export declare type WatchFunction = (err: Error | undefined, val: T | undefined) => void; export interface IConfigValue { type: ConfigType; watcher: WatchFunction | null; } export interface IConfigError { key: string; message: string; } export interface IBaseConfigValue extends IConfigValue { source: ISource; nullable: boolean; } export declare type ConfigValue = IRootConfigValue | BaseConfigValue; export declare type BaseConfigValue = IObjectConfigValue | IArrayConfigValue | IPrimitiveConfigValue | INullConfigValue | IPromisedConfigValue | IPlaceholderConfigValue | IInvalidConfigValue; export interface IConfigProperties { [name: string]: BaseConfigValue; } export declare type ConfigItems = Array; export interface IRootConfigValue extends IConfigValue { type: 'root'; properties: IConfigProperties; } export interface IObjectConfigValue extends IBaseConfigValue { type: 'object'; properties: IConfigProperties; } export interface IArrayConfigValue extends IBaseConfigValue { type: 'array'; items: ConfigItems; } export interface IPrimitiveConfigValue extends IBaseConfigValue { type: 'string' | 'number' | 'boolean'; value: string | number | boolean; } export interface INullConfigValue extends IBaseConfigValue { type: 'null'; value: null; } export interface IInvalidConfigValue extends IBaseConfigValue { type: 'invalid'; value: null; } export interface IPromisedConfigValue extends IBaseConfigValue { type: 'promise'; value: Promise; } export interface IPlaceholderConfigValue extends IBaseConfigValue { type: 'placeholder'; value: IConfigPlaceholder; } export interface IResolver { name: string; type: ResolverType; } /** * Config placeholder as it appears in the raw config */ export interface IConfigPlaceholder { _source: string; _key: string; _type?: ObjectType; _default?: any; _nullable?: boolean; _altKey?: string; } /** * Config placeholder as is resolved after all resolvers have been registered. * * name - name of remote resolver * key - key to fetch from resolver * type - type of resolver * default - default value if fetching fails */ export interface IResolvedPlaceholder { path: string; resolver: IResolver; key: string; type: ObjectType; nullable: boolean; default?: any; altKey?: string; } export declare type KeyPath = Array; export declare type ObjectUpdate = [KeyPath, Promise]; export declare type PromisedUpdate = [KeyPath, Promise]; export declare type ISchema = IArraySchema | IObjectSchema | IStringSchema | INumberSchema | IBooleanSchema | IAnySchema | INullSchema | IInvalidSchema | IUndefinedSchema; export interface IArraySchema { type: 'array'; items?: ISchema; } export interface IObjectSchema { type: 'object'; properties?: ISchemaMap; required?: Array; } export interface IStringSchema { type: 'string'; } export interface INumberSchema { type: 'number'; } export interface IBooleanSchema { type: 'boolean'; } export interface IAnySchema { } export interface INullSchema { type: 'null'; } export interface IUndefinedSchema { type: 'undefined'; } export interface IInvalidSchema { type: 'invalid'; }