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 | /**
|
56 | * Get a configuration value (either custom configuration or process environment variable)
|
57 | * based on property path (you can use dot notation to traverse nested object, e.g. "database.host").
|
58 | * @param propertyPath
|
59 | */
|
60 | getOrThrow<T = any>(propertyPath: KeyOf<K>): Exclude<T, undefined>;
|
61 | /**
|
62 | * Get a configuration value (either custom configuration or process environment variable)
|
63 | * based on property path (you can use dot notation to traverse nested object, e.g. "database.host").
|
64 | * @param propertyPath
|
65 | * @param options
|
66 | */
|
67 | getOrThrow<T = K, P extends Path<T> = any>(propertyPath: P, options: ConfigGetOptions): Exclude<T, undefined>;
|
68 | /**
|
69 | * Get a configuration value (either custom configuration or process environment variable)
|
70 | * based on property path (you can use dot notation to traverse nested object, e.g. "database.host").
|
71 | * It returns a default value if the key does not exist.
|
72 | * If the default value is undefined an exception will be thrown.
|
73 | * @param propertyPath
|
74 | * @param defaultValue
|
75 | */
|
76 | getOrThrow<T = any>(propertyPath: KeyOf<K>, defaultValue: NoInferType<T>): Exclude<T, undefined>;
|
77 | /**
|
78 | * Get a configuration value (either custom configuration or process environment variable)
|
79 | * based on property path (you can use dot notation to traverse nested object, e.g. "database.host").
|
80 | * It returns a default value if the key does not exist.
|
81 | * If the default value is undefined an exception will be thrown.
|
82 | * @param propertyPath
|
83 | * @param defaultValue
|
84 | * @param options
|
85 | */
|
86 | getOrThrow<T = K, P extends Path<T> = any, R = PathValue<T, P>>(propertyPath: P, defaultValue: NoInferType<R>, options: ConfigGetOptions): Exclude<R, undefined>;
|
87 | private getFromCache;
|
88 | private getFromValidatedEnv;
|
89 | private getFromProcessEnv;
|
90 | private getFromInternalConfig;
|
91 | private setInCacheIfDefined;
|
92 | private isGetOptionsObject;
|
93 | }
|
94 | export {};
|