wj-config
Version:
Javascript configuration module for NodeJS and browser frameworks such as React that works like ASP.net configuration where data sources are specified (usually JSON files) and environment variables can contribute/overwrite values by following a naming con
40 lines • 3.84 kB
TypeScript
import type { ConfigurationValue, IDataSource, IEnvAwareBuilder, IEnvironment, InflateDictionary, InflateKey, MergeResult, Predicate, ProcessFetchResponse, Traits, UrlBuilderSectionWithCheck } from "../wj-config.js";
import { BuilderImpl } from "./BuilderImpl.js";
export interface IEnvironmentSource<TEnvironments extends string> {
name?: string;
environment: IEnvironment<TEnvironments>;
}
export declare class EnvAwareBuilder<TEnvironments extends string, T extends Record<string, any> = {}> implements IEnvAwareBuilder<TEnvironments, T> {
#private;
/**
* Environment source.
*/
private _envSource;
constructor(envSource: IEnvironmentSource<TEnvironments>, impl: BuilderImpl);
add<NewT extends Record<string, any>>(dataSource: IDataSource<NewT>): IEnvAwareBuilder<TEnvironments, MergeResult<T, NewT>>;
addObject<NewT extends Record<string, any>>(obj: NewT | (() => Promise<NewT>)): IEnvAwareBuilder<TEnvironments, MergeResult<T, NewT>>;
addDictionary<TDic extends Record<string, ConfigurationValue>, TSep extends string = ':'>(dictionary: Record<string, ConfigurationValue> | (() => Promise<Record<string, ConfigurationValue>>), hierarchySeparator?: string, prefixOrPredicate?: string | Predicate<string>): IEnvAwareBuilder<TEnvironments, MergeResult<T, InflateDictionary<TDic, TSep>>>;
addEnvironment<TDic extends Record<string, ConfigurationValue>, TPrefix extends string = 'OPT_'>(env: Record<string, ConfigurationValue> | (() => Promise<Record<string, ConfigurationValue>>), prefix?: string): IEnvAwareBuilder<TEnvironments, MergeResult<T, InflateDictionary<TDic, "__", TPrefix>>>;
addFetched<NewT extends Record<string, any>>(input: URL | RequestInfo | (() => Promise<URL | RequestInfo>), required?: boolean, init?: RequestInit, procesFn?: ProcessFetchResponse<NewT>): IEnvAwareBuilder<TEnvironments, MergeResult<T, NewT>>;
addJson<NewT extends Record<string, any>>(json: string | (() => Promise<string>), jsonParser?: JSON, reviver?: (this: any, key: string, value: any) => any): IEnvAwareBuilder<TEnvironments, MergeResult<T, NewT>>;
addSingleValue<TKey extends string, TValue extends ConfigurationValue, TSep extends string = ':'>(path: TKey | (() => Promise<[TKey, TValue]>), valueOrHierarchySeparator?: TValue | TSep, hierarchySeparator?: TSep): IEnvAwareBuilder<TEnvironments, MergeResult<T, InflateKey<TKey, TValue, TSep>>>;
postMerge<U extends Record<string, any> = T>(fn: (config: T) => U | Promise<U>): IEnvAwareBuilder<TEnvironments, U>;
name(name: string): this;
createUrlFunctions<TUrl extends keyof T>(wsPropertyNames: TUrl | TUrl[], routeValuesRegExp?: RegExp): IEnvAwareBuilder<TEnvironments, Omit<T, TUrl> & UrlBuilderSectionWithCheck<T, TUrl>>;
/**
* Boolean flag used to raise an error if there was no call to includeEnvironment() when it is known to be needed.
*/
private _envIsRequired;
/**
* Dictionary of environment names that have been configured with a data source using the addPerEnvironment()
* helper function. The value is the number of times the environment name has been used.
*/
private _perEnvDsCount;
addPerEnvironment<NewT extends Record<string, any>>(addDs: (builder: IEnvAwareBuilder<TEnvironments, T>, envName: TEnvironments) => boolean | string): IEnvAwareBuilder<TEnvironments, MergeResult<T, NewT>>;
when(predicate: Predicate<IEnvironment<TEnvironments> | undefined>, dataSourceName?: string): this;
forEnvironment(envName: Exclude<TEnvironments, undefined>, dataSourceName?: string): this;
whenAllTraits(traits: Traits, dataSourceName?: string): this;
whenAnyTrait(traits: Traits, dataSourceName?: string): this;
build(traceValueSources?: boolean, enforcePerEnvironmentCoverage?: boolean): Promise<T>;
}
//# sourceMappingURL=EnvAwareBuilder.d.ts.map