1 | import { NoInferType, Path, PathValue } from './types';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | declare type ExcludeUndefinedIf<ExcludeUndefined extends boolean, T> = ExcludeUndefined extends true ? Exclude<T, undefined> : T | undefined;
|
9 | export interface ConfigGetOptions {
|
10 | |
11 |
|
12 |
|
13 |
|
14 |
|
15 | infer: true;
|
16 | }
|
17 | declare type KeyOf<T> = keyof T extends never ? string : keyof T;
|
18 | export declare class ConfigService<K = Record<string, unknown>, WasValidated extends boolean = false> {
|
19 | private readonly internalConfig;
|
20 | private set isCacheEnabled(value);
|
21 | private get isCacheEnabled();
|
22 | private readonly cache;
|
23 | private _isCacheEnabled;
|
24 | constructor(internalConfig?: Record<string, any>);
|
25 | /**
|
26 | * Get a configuration value (either custom configuration or process environment variable)
|
27 | * based on property path (you can use dot notation to traverse nested object, e.g. "database.host").
|
28 | * @param propertyPath
|
29 | */
|
30 | get<T = any>(propertyPath: KeyOf<K>): ExcludeUndefinedIf<WasValidated, T>;
|
31 | /**
|
32 | * Get a configuration value (either custom configuration or process environment variable)
|
33 | * based on property path (you can use dot notation to traverse nested object, e.g. "database.host").
|
34 | * @param propertyPath
|
35 | * @param options
|
36 | */
|
37 | get<T = K, P extends Path<T> = any, R = PathValue<T, P>>(propertyPath: P, options: ConfigGetOptions): ExcludeUndefinedIf<WasValidated, R>;
|
38 | /**
|
39 | * Get a configuration value (either custom configuration or process environment variable)
|
40 | * based on property path (you can use dot notation to traverse nested object, e.g. "database.host").
|
41 | * It returns a default value if the key does not exist.
|
42 | * @param propertyPath
|
43 | * @param defaultValue
|
44 | */
|
45 | get<T = any>(propertyPath: KeyOf<K>, defaultValue: NoInferType<T>): T;
|
46 | /**
|
47 | * Get a configuration value (either custom configuration or process environment variable)
|
48 | * based on property path (you can use dot notation to traverse nested object, e.g. "database.host").
|
49 | * It returns a default value if the key does not exist.
|
50 | * @param propertyPath
|
51 | * @param defaultValue
|
52 | * @param options
|
53 | */
|
54 | get<T = K, P extends Path<T> = any, R = PathValue<T, P>>(propertyPath: P, defaultValue: NoInferType<R>, options: ConfigGetOptions): R;
|
55 | private getFromCache;
|
56 | private getFromValidatedEnv;
|
57 | private getFromProcessEnv;
|
58 | private getFromInternalConfig;
|
59 | private setInCacheIfDefined;
|
60 | private isGetOptionsObject;
|
61 | }
|
62 | export {};
|