config 4.2.1 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +23 -17
- package/async.js +29 -7
- package/defer.js +15 -19
- package/lib/config.js +607 -531
- package/lib/defer.js +70 -0
- package/lib/util.js +351 -98
- package/package.json +53 -5
- package/parser.js +90 -5
- package/raw.js +9 -8
- package/tsconfig.json +15 -0
- package/types/async.d.ts +23 -0
- package/types/defer.d.ts +3 -0
- package/types/lib/config.d.ts +368 -0
- package/types/lib/defer.d.ts +33 -0
- package/types/lib/util.d.ts +649 -0
- package/types/parser.d.ts +132 -0
- package/types/raw.d.ts +9 -0
|
@@ -0,0 +1,649 @@
|
|
|
1
|
+
export type Parser = typeof import("./../parser");
|
|
2
|
+
export type BootstrapCallbackContext = {
|
|
3
|
+
util: Util;
|
|
4
|
+
defer: typeof deferConfig;
|
|
5
|
+
raw: typeof RawConfig.raw;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A function for deferred configuration
|
|
9
|
+
*
|
|
10
|
+
* Executable config files can now be initialized by a callback which receives useful
|
|
11
|
+
* context in order to avoid the need for require() or import() calls to config while
|
|
12
|
+
* it is still initializing.
|
|
13
|
+
*/
|
|
14
|
+
export type bootstrapCallback = (context: BootstrapCallbackContext) => any;
|
|
15
|
+
/**
|
|
16
|
+
* A source in the configSources list
|
|
17
|
+
*/
|
|
18
|
+
export type ConfigSource = {
|
|
19
|
+
name: string;
|
|
20
|
+
/**
|
|
21
|
+
* - parsed representation
|
|
22
|
+
*/
|
|
23
|
+
parsed: any;
|
|
24
|
+
/**
|
|
25
|
+
* - unparsed representation of the data
|
|
26
|
+
*/
|
|
27
|
+
original?: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The data used for a Load operation, mostly derived from environment variables
|
|
31
|
+
*/
|
|
32
|
+
export type LoadOptions = {
|
|
33
|
+
/**
|
|
34
|
+
* - config directory location, absolute or relative to cwd()
|
|
35
|
+
*/
|
|
36
|
+
configDir?: string | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* - NODE_ENV value or commo-separated list
|
|
39
|
+
*/
|
|
40
|
+
nodeEnv?: string[] | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* - hostName for host-specific loads
|
|
43
|
+
*/
|
|
44
|
+
hostName?: string | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* - per-process config ID
|
|
47
|
+
*/
|
|
48
|
+
appInstance?: string | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* - don't track sources
|
|
51
|
+
*/
|
|
52
|
+
skipConfigSources?: boolean | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* - allow gitcrypt files
|
|
55
|
+
*/
|
|
56
|
+
gitCrypt?: boolean | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* - alternative parser implementation
|
|
59
|
+
*/
|
|
60
|
+
parser?: Parser | undefined;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Callback for converting loaded data.
|
|
64
|
+
*/
|
|
65
|
+
export type DataConvert = (input: any) => any;
|
|
66
|
+
/**
|
|
67
|
+
* Util functions that do not require the singleton in order to run.
|
|
68
|
+
*/
|
|
69
|
+
export class Util {
|
|
70
|
+
/**
|
|
71
|
+
* <p>Make a configuration property hidden so it doesn't appear when enumerating
|
|
72
|
+
* elements of the object.</p>
|
|
73
|
+
*
|
|
74
|
+
* <p>
|
|
75
|
+
* The property still exists and can be read from and written to, but it won't
|
|
76
|
+
* show up in for ... in loops, Object.keys(), or JSON.stringify() type methods.
|
|
77
|
+
* </p>
|
|
78
|
+
*
|
|
79
|
+
* <p>
|
|
80
|
+
* If the property already exists, it will be made hidden. Otherwise it will
|
|
81
|
+
* be created as a hidden property with the specified value.
|
|
82
|
+
* </p>
|
|
83
|
+
*
|
|
84
|
+
* <p><i>
|
|
85
|
+
* This method was built for hiding configuration values, but it can be applied
|
|
86
|
+
* to <u>any</u> javascript object.
|
|
87
|
+
* </i></p>
|
|
88
|
+
*
|
|
89
|
+
* <p>Example:</p>
|
|
90
|
+
* <pre>
|
|
91
|
+
* const Util = require('config/lib/util.js');
|
|
92
|
+
* ...
|
|
93
|
+
*
|
|
94
|
+
* // Hide the Amazon S3 credentials
|
|
95
|
+
* Util.makeHidden(CONFIG.amazonS3, 'access_id');
|
|
96
|
+
* Util.makeHidden(CONFIG.amazonS3, 'secret_key');
|
|
97
|
+
* </pre>
|
|
98
|
+
*
|
|
99
|
+
* @method makeHidden
|
|
100
|
+
* @param {object} object - The object to make a hidden property into.
|
|
101
|
+
* @param {string} property - The name of the property to make hidden.
|
|
102
|
+
* @param {*=} value - (optional) Set the property value to this (otherwise leave alone)
|
|
103
|
+
* @return {object} - The original object is returned - for chaining.
|
|
104
|
+
*/
|
|
105
|
+
static makeHidden(object: object, property: string, value?: any | undefined): object;
|
|
106
|
+
/**
|
|
107
|
+
* Make a javascript object immutable (assuring it cannot be changed from the current value)
|
|
108
|
+
*
|
|
109
|
+
* All attributes of that object are made immutable, including properties of contained
|
|
110
|
+
* objects, recursively.
|
|
111
|
+
*
|
|
112
|
+
* This operation cannot be undone.
|
|
113
|
+
*
|
|
114
|
+
* <p>Example:</p>
|
|
115
|
+
* <pre>
|
|
116
|
+
* const config = require('config');
|
|
117
|
+
* const myObject = {hello:'world'};
|
|
118
|
+
* Util.makeImmutable(myObject);
|
|
119
|
+
* </pre>
|
|
120
|
+
*
|
|
121
|
+
* @method makeImmutable
|
|
122
|
+
* @param object {Object} - The object to freeze
|
|
123
|
+
* @return object {Object} - The original object is returned - for chaining.
|
|
124
|
+
*/
|
|
125
|
+
static makeImmutable(object: any): any;
|
|
126
|
+
/**
|
|
127
|
+
* Looks into an options object for a specific attribute
|
|
128
|
+
*
|
|
129
|
+
* <p>
|
|
130
|
+
* This method looks into the options object, and if an attribute is defined, returns it,
|
|
131
|
+
* and if not, returns the default value
|
|
132
|
+
* </p>
|
|
133
|
+
*
|
|
134
|
+
* @template T
|
|
135
|
+
* @method getOption
|
|
136
|
+
* @param {Object | undefined} options the options object
|
|
137
|
+
* @param {string} optionName the attribute name to look for
|
|
138
|
+
* @param {T} defaultValue the default in case the options object is empty, or the attribute does not exist.
|
|
139
|
+
* @return {T} options[optionName] if defined, defaultValue if not.
|
|
140
|
+
*/
|
|
141
|
+
static getOption<T>(options: any | undefined, optionName: string, defaultValue: T): T;
|
|
142
|
+
/**
|
|
143
|
+
* Load the individual file configurations.
|
|
144
|
+
*
|
|
145
|
+
* <p>
|
|
146
|
+
* This method builds a map of filename to the configuration object defined
|
|
147
|
+
* by the file. The search order is:
|
|
148
|
+
* </p>
|
|
149
|
+
*
|
|
150
|
+
* <pre>
|
|
151
|
+
* default.EXT
|
|
152
|
+
* (deployment).EXT
|
|
153
|
+
* (hostname).EXT
|
|
154
|
+
* (hostname)-(deployment).EXT
|
|
155
|
+
* local.EXT
|
|
156
|
+
* local-(deployment).EXT
|
|
157
|
+
* </pre>
|
|
158
|
+
*
|
|
159
|
+
* <p>
|
|
160
|
+
* EXT can be yml, yaml, coffee, iced, json, jsonc, cson or js signifying the file type.
|
|
161
|
+
* yaml (and yml) is in YAML format, coffee is a coffee-script, iced is iced-coffee-script,
|
|
162
|
+
* json is in JSON format, jsonc is in JSONC format, cson is in CSON format, properties is
|
|
163
|
+
* in .properties format (http://en.wikipedia.org/wiki/.properties), and js is a javascript
|
|
164
|
+
* executable file that is require()'d with module.exports being the config object.
|
|
165
|
+
* </p>
|
|
166
|
+
*
|
|
167
|
+
* <p>
|
|
168
|
+
* hostname is the $HOST environment variable (or --HOST command line parameter)
|
|
169
|
+
* if set, otherwise the $HOSTNAME environment variable (or --HOSTNAME command
|
|
170
|
+
* line parameter) if set, otherwise the hostname found from
|
|
171
|
+
* require('os').hostname().
|
|
172
|
+
* </p>
|
|
173
|
+
*
|
|
174
|
+
* <p>
|
|
175
|
+
* Once a hostname is found, everything from the first period ('.') onwards
|
|
176
|
+
* is removed. For example, abc.example.com becomes abc
|
|
177
|
+
* </p>
|
|
178
|
+
*
|
|
179
|
+
* <p>
|
|
180
|
+
* (deployment) is the deployment type, found in the $NODE_ENV environment
|
|
181
|
+
* variable (which can be overridden by using $NODE_CONFIG_ENV
|
|
182
|
+
* environment variable). Defaults to 'development'.
|
|
183
|
+
* </p>
|
|
184
|
+
*
|
|
185
|
+
* <p>
|
|
186
|
+
* If the $NODE_APP_INSTANCE environment variable (or --NODE_APP_INSTANCE
|
|
187
|
+
* command line parameter) is set, then files with this appendage will be loaded.
|
|
188
|
+
* See the Multiple Application Instances section of the main documentation page
|
|
189
|
+
* for more information.
|
|
190
|
+
* </p>
|
|
191
|
+
*
|
|
192
|
+
* @method loadFileConfigs
|
|
193
|
+
* @param {LoadOptions | Load} opts parsing options or Load to update
|
|
194
|
+
* @return {Load} loadConfig
|
|
195
|
+
*/
|
|
196
|
+
static loadFileConfigs(opts: LoadOptions | Load): Load;
|
|
197
|
+
/**
|
|
198
|
+
* Return a list of fullFilenames who exists in allowedFiles
|
|
199
|
+
* Ordered according to allowedFiles argument specifications
|
|
200
|
+
*
|
|
201
|
+
* @method locateMatchingFiles
|
|
202
|
+
* @param {string} configDirs the config dir, or multiple dirs separated by a column (:)
|
|
203
|
+
* @param {Object} allowedFiles an object. keys and supported filenames
|
|
204
|
+
* and values are the position in the resolution order
|
|
205
|
+
* @returns {string[]} fullFilenames - path + filename
|
|
206
|
+
*/
|
|
207
|
+
static locateMatchingFiles(configDirs: string, allowedFiles: any): string[];
|
|
208
|
+
/**
|
|
209
|
+
*
|
|
210
|
+
* @param {object} config
|
|
211
|
+
*/
|
|
212
|
+
static resolveDeferredConfigs(config: object): void;
|
|
213
|
+
/**
|
|
214
|
+
* Used to resolve configs that have async functions.
|
|
215
|
+
*
|
|
216
|
+
* NOTE: Do not use `config.get` before executing this method, it will freeze the config object
|
|
217
|
+
*
|
|
218
|
+
* This replaces ./async.js, which is deprecated.
|
|
219
|
+
*
|
|
220
|
+
* @param config
|
|
221
|
+
* @returns {Promise<void>}
|
|
222
|
+
*/
|
|
223
|
+
static resolveAsyncConfigs(config: any): Promise<void>;
|
|
224
|
+
/**
|
|
225
|
+
* Return a deep copy of the specified object using cloneDeep(parent, depth, circular, prototype).
|
|
226
|
+
*
|
|
227
|
+
* This returns a new object with all elements copied from the specified
|
|
228
|
+
* object. Deep copies are made of objects and arrays so you can do anything
|
|
229
|
+
* with the returned object without affecting the input object.
|
|
230
|
+
*
|
|
231
|
+
* @method cloneDeep
|
|
232
|
+
* @param {object} parent The original object to copy from
|
|
233
|
+
* @param {number} [depth=20] Maximum depth
|
|
234
|
+
* @param {boolean} [circular=true] Handle circular references
|
|
235
|
+
* @param {object=} prototype Optional prototype for the new object
|
|
236
|
+
* @return {object} A new object with the elements copied from the parent object
|
|
237
|
+
*
|
|
238
|
+
* This method is copied from https://github.com/pvorb/node-clone/blob/17eea36140d61d97a9954c53417d0e04a00525d9/clone.js
|
|
239
|
+
*
|
|
240
|
+
* Copyright © 2011-2014 Paul Vorbach and contributors.
|
|
241
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
242
|
+
* of this software and associated documentation files (the “Software”), to deal
|
|
243
|
+
* in the Software without restriction, including without limitation the rights
|
|
244
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
245
|
+
* of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
246
|
+
* subject to the following conditions: The above copyright notice and this permission
|
|
247
|
+
* notice shall be included in all copies or substantial portions of the Software.
|
|
248
|
+
*/
|
|
249
|
+
static cloneDeep(parent: object, depth?: number, circular?: boolean, prototype?: object | undefined): object;
|
|
250
|
+
/**
|
|
251
|
+
* Underlying get mechanism
|
|
252
|
+
*
|
|
253
|
+
* @method getPath
|
|
254
|
+
* @param {object} object - Object to get the property for
|
|
255
|
+
* @param {string|string[]} property - The property name to get (as an array or '.' delimited string)
|
|
256
|
+
* @return {*} value - Property value, including undefined if not defined.
|
|
257
|
+
*/
|
|
258
|
+
static getPath(object: object, property: string | string[]): any;
|
|
259
|
+
/**
|
|
260
|
+
* Set objects given a path as a string list
|
|
261
|
+
*
|
|
262
|
+
* @method setPath
|
|
263
|
+
* @param {object} object - Object to set the property on
|
|
264
|
+
* @param {string|string[]} property - The property name to get (as an array or '.' delimited string)
|
|
265
|
+
* @param {*} value - value to set, ignoring null
|
|
266
|
+
* @return {*} - the given value
|
|
267
|
+
*/
|
|
268
|
+
static setPath(object: object, property: string | string[], value: any): any;
|
|
269
|
+
/**
|
|
270
|
+
* Return true if two objects have equal contents.
|
|
271
|
+
*
|
|
272
|
+
* @method equalsDeep
|
|
273
|
+
* @param object1 {Object} The object to compare from
|
|
274
|
+
* @param object2 {Object} The object to compare with
|
|
275
|
+
* @param depth {number} An optional depth to prevent recursion. Default: 20.
|
|
276
|
+
* @return {boolean} True if both objects have equivalent contents
|
|
277
|
+
*/
|
|
278
|
+
static equalsDeep(object1: any, object2: any, depth: number): boolean;
|
|
279
|
+
/**
|
|
280
|
+
* Extend an object, and any object it contains.
|
|
281
|
+
*
|
|
282
|
+
* This does not replace deep objects, but dives into them
|
|
283
|
+
* replacing individual elements instead.
|
|
284
|
+
*
|
|
285
|
+
* @method extendDeep
|
|
286
|
+
* @param mergeInto {Object} The object to merge into
|
|
287
|
+
* @param mergeFrom... {Object} - Any number of objects to merge from
|
|
288
|
+
* @param [depth] {number} An optional depth to prevent recursion. Default: 20.
|
|
289
|
+
* @return {Object} The altered mergeInto object is returned
|
|
290
|
+
*/
|
|
291
|
+
static extendDeep(mergeInto: any, ...vargs: any[]): any;
|
|
292
|
+
/**
|
|
293
|
+
* Is the specified argument a regular javascript object?
|
|
294
|
+
*
|
|
295
|
+
* The argument is an object if it's a JS object, but not an array.
|
|
296
|
+
*
|
|
297
|
+
* @method isObject
|
|
298
|
+
* @param {unknown} obj An argument of any type.
|
|
299
|
+
* @return {obj is object} TRUE if the arg is an object, FALSE if not
|
|
300
|
+
*/
|
|
301
|
+
static isObject(obj: unknown): obj is object;
|
|
302
|
+
/**
|
|
303
|
+
* Is the specified argument a javascript promise?
|
|
304
|
+
*
|
|
305
|
+
* @method isPromise
|
|
306
|
+
* @param {unknown} obj An argument of any type.
|
|
307
|
+
* @returns {obj is Promise} TRUE if the arg is a Promise, FALSE if not
|
|
308
|
+
*/
|
|
309
|
+
static isPromise(obj: unknown): obj is Promise<any>;
|
|
310
|
+
/**
|
|
311
|
+
* Returns a string of flags for regular expression `re`.
|
|
312
|
+
*
|
|
313
|
+
* @param {RegExp} re Regular expression
|
|
314
|
+
* @returns {string} Flags
|
|
315
|
+
*/
|
|
316
|
+
static getRegExpFlags: (re: RegExp) => string;
|
|
317
|
+
/**
|
|
318
|
+
* Returns a new deep copy of the current config object, or any part of the config if provided.
|
|
319
|
+
*
|
|
320
|
+
* @param {Object} config The part of the config to copy and serialize.
|
|
321
|
+
* @returns {Object} The cloned config or part of the config
|
|
322
|
+
*/
|
|
323
|
+
static toObject(config: any): any;
|
|
324
|
+
/**
|
|
325
|
+
* Send a message to console.error once
|
|
326
|
+
* @param {string} key the subject of the error, used to prevent duplicates
|
|
327
|
+
* @param {string} message helpful message for library users
|
|
328
|
+
* @param {...object} args additional arguments to console.error
|
|
329
|
+
*/
|
|
330
|
+
static errorOnce(key: string, message: string, ...args: object[]): void;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* The work horse of loading Config data - without the singleton.
|
|
334
|
+
*
|
|
335
|
+
* This class can be used to execute important workflows, such as build-time validations
|
|
336
|
+
* and Module Defaults.
|
|
337
|
+
*
|
|
338
|
+
* @example
|
|
339
|
+
* //load module defaults
|
|
340
|
+
* const config = require("config");
|
|
341
|
+
* const Load = require("config/util.js").Load;
|
|
342
|
+
*
|
|
343
|
+
* let load = Load.fromEnvironment();
|
|
344
|
+
*
|
|
345
|
+
* load.scan();
|
|
346
|
+
*
|
|
347
|
+
* config.setModuleDefaults("my-module", load.config);
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* // verify configs
|
|
351
|
+
* const Load = require("config/util.js").Load;
|
|
352
|
+
*
|
|
353
|
+
* for (let environment of ["sandbox", "qa", "qa-hyderabad", "perf", "staging", "prod-east-1", "prod-west-2"] {
|
|
354
|
+
* let load = Load.fromEnvironment(environment);
|
|
355
|
+
*
|
|
356
|
+
* load.scan();
|
|
357
|
+
* }
|
|
358
|
+
*
|
|
359
|
+
*
|
|
360
|
+
* @class Load
|
|
361
|
+
*/
|
|
362
|
+
export class Load {
|
|
363
|
+
/**
|
|
364
|
+
* Populate a LoadConfig entirely from environment variables.
|
|
365
|
+
*
|
|
366
|
+
* This is the way a base config is normally accomplished, but not for independent loads.
|
|
367
|
+
*
|
|
368
|
+
* This function exists in part to reduce the circular dependency of variable initializations
|
|
369
|
+
* in the config.js file
|
|
370
|
+
* @param {string} environments the NODE_CONFIG_ENVs you want to load
|
|
371
|
+
* @private
|
|
372
|
+
* @returns {Load}
|
|
373
|
+
*/
|
|
374
|
+
private static fromEnvironment;
|
|
375
|
+
/**
|
|
376
|
+
* @constructor
|
|
377
|
+
* @param {LoadOptions=} options - defaults to reading from environment variables
|
|
378
|
+
* @param {Env=} env - optional Env data, usually from fromEnvironment()
|
|
379
|
+
*/
|
|
380
|
+
constructor(options?: LoadOptions | undefined, env?: Env | undefined);
|
|
381
|
+
/** @type {Env} */
|
|
382
|
+
env: Env;
|
|
383
|
+
/** @type {LoadOptions} */
|
|
384
|
+
options: LoadOptions;
|
|
385
|
+
/** @type {ConfigSource[] | undefined} */
|
|
386
|
+
sources: ConfigSource[] | undefined;
|
|
387
|
+
/** @type {Parser | undefined} */
|
|
388
|
+
parser: Parser | undefined;
|
|
389
|
+
/** @type {Record<string, any>} */
|
|
390
|
+
config: Record<string, any>;
|
|
391
|
+
/** @type {Record<string, any> | undefined} */
|
|
392
|
+
defaults: Record<string, any> | undefined;
|
|
393
|
+
/** @type {Record<string, any> | undefined} */
|
|
394
|
+
unmerged: Record<string, any> | undefined;
|
|
395
|
+
/** @type {boolean} */
|
|
396
|
+
updated: boolean;
|
|
397
|
+
/**
|
|
398
|
+
* Create a snapshot of a Load instance
|
|
399
|
+
* @returns {Load}
|
|
400
|
+
*/
|
|
401
|
+
clone(): Load;
|
|
402
|
+
/**
|
|
403
|
+
* <p>Initialize a parameter from the command line or process environment</p>
|
|
404
|
+
*
|
|
405
|
+
* <p>
|
|
406
|
+
* This method looks for the parameter from the command line in the format
|
|
407
|
+
* --PARAMETER=VALUE, then from the process environment, then from the
|
|
408
|
+
* default specified as an argument.
|
|
409
|
+
* </p>
|
|
410
|
+
*
|
|
411
|
+
* @template T
|
|
412
|
+
* @method initParam
|
|
413
|
+
* @param {string} paramName Name of the parameter
|
|
414
|
+
* @param {T} [defaultValue] Default value of the parameter
|
|
415
|
+
* @return {T} The found value, or default value
|
|
416
|
+
*/
|
|
417
|
+
initParam<T>(paramName: string, defaultValue?: T): T;
|
|
418
|
+
/**
|
|
419
|
+
* <p>Get Command Line Arguments</p>
|
|
420
|
+
*
|
|
421
|
+
* <p>
|
|
422
|
+
* This method allows you to retrieve the value of the specified command line argument.
|
|
423
|
+
* </p>
|
|
424
|
+
*
|
|
425
|
+
* <p>
|
|
426
|
+
* The argument is case sensitive, and must be of the form '--ARG_NAME=value'
|
|
427
|
+
* </p>
|
|
428
|
+
*
|
|
429
|
+
* @method getCmdLineArg
|
|
430
|
+
* @param {string} searchFor The argument name to search for
|
|
431
|
+
* @return {false|string} false if the argument was not found, the argument value if found
|
|
432
|
+
*/
|
|
433
|
+
getCmdLineArg(searchFor: string): false | string;
|
|
434
|
+
/**
|
|
435
|
+
* <p>Get a Config Environment Variable Value</p>
|
|
436
|
+
*
|
|
437
|
+
* <p>
|
|
438
|
+
* This method returns the value of the specified config environment variable,
|
|
439
|
+
* including any defaults or overrides.
|
|
440
|
+
* </p>
|
|
441
|
+
*
|
|
442
|
+
* @method getEnv
|
|
443
|
+
* @param {string} varName The environment variable name
|
|
444
|
+
* @return {string} The value of the environment variable
|
|
445
|
+
*/
|
|
446
|
+
getEnv(varName: string): string;
|
|
447
|
+
/**
|
|
448
|
+
* Set a tracing variable of what was accessed from process.env
|
|
449
|
+
*
|
|
450
|
+
* @see fromEnvironment
|
|
451
|
+
* @param {string} key
|
|
452
|
+
* @param {*} value
|
|
453
|
+
*/
|
|
454
|
+
setEnv(key: string, value: any): void;
|
|
455
|
+
/**
|
|
456
|
+
* Add a set of configurations and record the source
|
|
457
|
+
*
|
|
458
|
+
* @param {string=} name an entry will be added to sources under this name (if given)
|
|
459
|
+
* @param {object=} values values to merge in
|
|
460
|
+
* @param {string=} original Optional unparsed version of the data
|
|
461
|
+
* @return {Load} this
|
|
462
|
+
*/
|
|
463
|
+
addConfig(name?: string | undefined, values?: object | undefined, original?: string | undefined): Load;
|
|
464
|
+
/**
|
|
465
|
+
* scan and load config files in the same manner that config.js does
|
|
466
|
+
*
|
|
467
|
+
* @param {{name: string, config: any}[]=} additional additional values to populate (usually from NODE_CONFIG)
|
|
468
|
+
*/
|
|
469
|
+
scan(additional?: {
|
|
470
|
+
name: string;
|
|
471
|
+
config: any;
|
|
472
|
+
}[] | undefined): void;
|
|
473
|
+
/**
|
|
474
|
+
* Load a file and add it to the configuration
|
|
475
|
+
*
|
|
476
|
+
* @param {string} fullFilename an absolute file path
|
|
477
|
+
* @param {DataConvert=} convert
|
|
478
|
+
* @returns {null}
|
|
479
|
+
*/
|
|
480
|
+
loadFile(fullFilename: string, convert?: DataConvert | undefined): null;
|
|
481
|
+
/**
|
|
482
|
+
* load custom-environment-variables
|
|
483
|
+
*
|
|
484
|
+
* @param extNames {string[]=} extensions
|
|
485
|
+
* @returns {{}}
|
|
486
|
+
*/
|
|
487
|
+
loadCustomEnvVars(extNames?: string[] | undefined): {};
|
|
488
|
+
/**
|
|
489
|
+
* Return the report of where the sources for this load operation came from
|
|
490
|
+
* @returns {ConfigSource[]}
|
|
491
|
+
*/
|
|
492
|
+
getSources(): ConfigSource[];
|
|
493
|
+
/**
|
|
494
|
+
* <p>
|
|
495
|
+
* Set default configurations for a node.js module.
|
|
496
|
+
* </p>
|
|
497
|
+
*
|
|
498
|
+
* <p>
|
|
499
|
+
* This allows module developers to attach their configurations onto the
|
|
500
|
+
* default configuration object so they can be configured by the consumers
|
|
501
|
+
* of the module.
|
|
502
|
+
* </p>
|
|
503
|
+
*
|
|
504
|
+
* <p>Using the function within your module:</p>
|
|
505
|
+
* <pre>
|
|
506
|
+
* load.setModuleDefaults("MyModule", {
|
|
507
|
+
* templateName: "t-50",
|
|
508
|
+
* colorScheme: "green"
|
|
509
|
+
* });
|
|
510
|
+
* <br>
|
|
511
|
+
* // Template name may be overridden by application config files
|
|
512
|
+
* console.log("Template: " + CONFIG.MyModule.templateName);
|
|
513
|
+
* </pre>
|
|
514
|
+
*
|
|
515
|
+
* <p>
|
|
516
|
+
* The above example results in a "MyModule" element of the configuration
|
|
517
|
+
* object, containing an object with the specified default values.
|
|
518
|
+
* </p>
|
|
519
|
+
*
|
|
520
|
+
* @method setModuleDefaults
|
|
521
|
+
* @param moduleName {string} - Name of your module.
|
|
522
|
+
* @param defaultProperties {Object} - The default module configuration.
|
|
523
|
+
* @return {Object} - The module level configuration object.
|
|
524
|
+
*/
|
|
525
|
+
setModuleDefaults(moduleName: string, defaultProperties: any): any;
|
|
526
|
+
/**
|
|
527
|
+
* Parse and return the specified string with the specified format.
|
|
528
|
+
*
|
|
529
|
+
* The format determines the parser to use.
|
|
530
|
+
*
|
|
531
|
+
* json = File is parsed using JSON.parse()
|
|
532
|
+
* yaml (or yml) = Parsed with a YAML parser
|
|
533
|
+
* toml = Parsed with a TOML parser
|
|
534
|
+
* cson = Parsed with a CSON parser
|
|
535
|
+
* hjson = Parsed with a HJSON parser
|
|
536
|
+
* json5 = Parsed with a JSON5 parser
|
|
537
|
+
* properties = Parsed with the 'properties' node package
|
|
538
|
+
* xml = Parsed with a XML parser
|
|
539
|
+
*
|
|
540
|
+
* If the file doesn't exist, a null will be returned. If the file can't be
|
|
541
|
+
* parsed, an exception will be thrown.
|
|
542
|
+
*
|
|
543
|
+
* This method performs synchronous file operations, and should not be called
|
|
544
|
+
* after synchronous module loading.
|
|
545
|
+
*
|
|
546
|
+
* @protected
|
|
547
|
+
* @method parseString
|
|
548
|
+
* @param {string} content The full content
|
|
549
|
+
* @param {string} format The format to be parsed
|
|
550
|
+
* @return {object} configObject The configuration object parsed from the string
|
|
551
|
+
*/
|
|
552
|
+
protected parseString(content: string, format: string): object;
|
|
553
|
+
/**
|
|
554
|
+
* Create a new object patterned after substitutionMap, where:
|
|
555
|
+
* 1. Terminal string values in substitutionMap are used as keys
|
|
556
|
+
* 2. To look up values in a key-value store, variables
|
|
557
|
+
* 3. And parent keys are created as necessary to retain the structure of substitutionMap.
|
|
558
|
+
*
|
|
559
|
+
* @protected
|
|
560
|
+
* @method substituteDeep
|
|
561
|
+
* @param {object} substitutionMap {Object} - an object whose terminal (non-subobject) values are strings
|
|
562
|
+
* @param {Record<string, any>} variables - usually process.env, a flat object used to transform
|
|
563
|
+
* terminal values in a copy of substitutionMap.
|
|
564
|
+
* @returns {Object} - deep copy of substitutionMap with only those paths whose terminal values
|
|
565
|
+
* corresponded to a key in `variables`
|
|
566
|
+
*/
|
|
567
|
+
protected substituteDeep(substitutionMap: object, variables: Record<string, any>): any;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* This is meant to wrap configuration objects that should be left as is,
|
|
571
|
+
* meaning that the object or its prototype will not be modified in any way
|
|
572
|
+
*/
|
|
573
|
+
export class RawConfig {
|
|
574
|
+
/**
|
|
575
|
+
* create a RawConfig
|
|
576
|
+
* @param rawObject {Object} properties we don't want to have manipulated by node-config
|
|
577
|
+
* @returns {RawConfig}
|
|
578
|
+
*/
|
|
579
|
+
static raw(rawObject: any): RawConfig;
|
|
580
|
+
constructor(data: any);
|
|
581
|
+
resolve(): any;
|
|
582
|
+
#private;
|
|
583
|
+
}
|
|
584
|
+
import { deferConfig } from "./defer.js";
|
|
585
|
+
/**
|
|
586
|
+
* Record a set of lookups
|
|
587
|
+
*/
|
|
588
|
+
declare class Env {
|
|
589
|
+
lookups: {};
|
|
590
|
+
/**
|
|
591
|
+
* Create a snapshot of an Env.
|
|
592
|
+
* @returns {Env}
|
|
593
|
+
*/
|
|
594
|
+
clone(): Env;
|
|
595
|
+
/**
|
|
596
|
+
* <p>Initialize a parameter from the command line or process environment</p>
|
|
597
|
+
*
|
|
598
|
+
* <p>
|
|
599
|
+
* This method looks for the parameter from the command line in the format
|
|
600
|
+
* --PARAMETER=VALUE, then from the process environment, then from the
|
|
601
|
+
* default specified as an argument.
|
|
602
|
+
* </p>
|
|
603
|
+
*
|
|
604
|
+
* @template T
|
|
605
|
+
* @method initParam
|
|
606
|
+
* @param {string} paramName Name of the parameter
|
|
607
|
+
* @param {T} [defaultValue] Default value of the parameter
|
|
608
|
+
* @return {T} The found value, or default value
|
|
609
|
+
*/
|
|
610
|
+
initParam<T>(paramName: string, defaultValue?: T): T;
|
|
611
|
+
/**
|
|
612
|
+
* <p>Get Command Line Arguments</p>
|
|
613
|
+
*
|
|
614
|
+
* <p>
|
|
615
|
+
* This method allows you to retrieve the value of the specified command line argument.
|
|
616
|
+
* </p>
|
|
617
|
+
*
|
|
618
|
+
* <p>
|
|
619
|
+
* The argument is case sensitive, and must be of the form '--ARG_NAME=value'
|
|
620
|
+
* </p>
|
|
621
|
+
*
|
|
622
|
+
* @method getCmdLineArg
|
|
623
|
+
* @param {string} searchFor The argument name to search for
|
|
624
|
+
* @return {false|string} false if the argument was not found, the argument value if found
|
|
625
|
+
*/
|
|
626
|
+
getCmdLineArg(searchFor: string): false | string;
|
|
627
|
+
/**
|
|
628
|
+
* <p>Get a Config Environment Variable Value</p>
|
|
629
|
+
*
|
|
630
|
+
* <p>
|
|
631
|
+
* This method returns the value of the specified config environment variable,
|
|
632
|
+
* including any defaults or overrides.
|
|
633
|
+
* </p>
|
|
634
|
+
*
|
|
635
|
+
* @method getEnv
|
|
636
|
+
* @param {string} varName The environment variable name
|
|
637
|
+
* @return {string} The value of the environment variable
|
|
638
|
+
*/
|
|
639
|
+
getEnv(varName: string): string;
|
|
640
|
+
/**
|
|
641
|
+
* Set a tracing variable of what was accessed from process.env
|
|
642
|
+
*
|
|
643
|
+
* @see fromEnvironment
|
|
644
|
+
* @param {string} key
|
|
645
|
+
* @param {*} value
|
|
646
|
+
*/
|
|
647
|
+
setEnv(key: string, value: any): void;
|
|
648
|
+
}
|
|
649
|
+
export {};
|