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/package.json CHANGED
@@ -1,7 +1,48 @@
1
1
  {
2
2
  "name": "config",
3
- "version": "4.2.1",
3
+ "version": "4.4.0",
4
4
  "main": "./lib/config.js",
5
+ "types": "types/lib/config.d.ts",
6
+ "typesVersions": {
7
+ "*": {
8
+ "async": [
9
+ "types/async.d.ts"
10
+ ],
11
+ "async.js": [
12
+ "types/async.d.ts"
13
+ ],
14
+ "defer": [
15
+ "types/defer.d.ts"
16
+ ],
17
+ "defer.js": [
18
+ "types/defer.d.ts"
19
+ ],
20
+ "parser": [
21
+ "types/parser.d.ts"
22
+ ],
23
+ "parser.js": [
24
+ "types/parser.d.ts"
25
+ ],
26
+ "raw": [
27
+ "types/raw.d.ts"
28
+ ],
29
+ "raw.js": [
30
+ "types/raw.d.ts"
31
+ ],
32
+ "lib/defer": [
33
+ "types/lib/defer.d.ts"
34
+ ],
35
+ "lib/defer.js": [
36
+ "types/lib/defer.d.ts"
37
+ ],
38
+ "lib/util": [
39
+ "types/lib/util.d.ts"
40
+ ],
41
+ "lib/util.js": [
42
+ "types/lib/util.d.ts"
43
+ ]
44
+ }
45
+ },
5
46
  "description": "Configuration control for production node deployments",
6
47
  "author": "Loren West <open_source@lorenwest.com>",
7
48
  "homepage": "http://github.com/node-config/node-config.git",
@@ -25,17 +66,18 @@
25
66
  "json5": "^2.2.3"
26
67
  },
27
68
  "devDependencies": {
28
- "@types/node": "^7.0.8",
69
+ "@types/node": "^20.11.30",
29
70
  "c8": "^10.1.3",
30
71
  "coffeescript": "2.2.4",
31
72
  "cson": "^3.0.1",
73
+ "faceoff": "^1.3.0",
32
74
  "hjson": "^1.2.0",
33
75
  "properties": "~1.2.1",
34
76
  "request": "^2.88.2",
35
77
  "semver": "5.3.0",
36
78
  "toml": "^2.0.6",
37
- "ts-node": "^3.3.0",
38
- "typescript": "^2.4.2",
79
+ "ts-node": "^10.9.2",
80
+ "typescript": "5.9.3",
39
81
  "underscore": "^1.8.3",
40
82
  "x2js": "^2.0.1",
41
83
  "yaml": "^2.8.2"
@@ -56,6 +98,12 @@
56
98
  "reporter": "lcov"
57
99
  },
58
100
  "scripts": {
59
- "test": "NODE_OPTIONS='--no-experimental-strip-types' c8 node --test"
101
+ "build:types": "tsc -p tsconfig.json",
102
+ "checkTypes": "npx -y @arethetypeswrong/cli --pack .",
103
+ "types": "npm run build:types && npm run checkTypes",
104
+ "prepublishOnly": "npm run build:types",
105
+ "ci": "npm run types && npm run test",
106
+ "test": "c8 node --no-experimental-strip-types --test",
107
+ "benchmarks": "node --allow-natives-syntax --expose-gc benchmarks/index.js"
60
108
  }
61
109
  }
package/parser.js CHANGED
@@ -35,10 +35,16 @@ var COFFEE_2_DEP = 'coffeescript',
35
35
  TS_DEP = 'ts-node';
36
36
 
37
37
  /**
38
- * @typedef Parser {Object}
38
+ * @template [T=any]
39
+ * @typedef {(filename: string, content: string) => T | undefined} ParserFn<T>
39
40
  */
40
41
  var Parser = module.exports;
41
42
 
43
+ /**
44
+ * @param {string} filename
45
+ * @param {string} content
46
+ * @returns {object | undefined}
47
+ */
42
48
  Parser.parse = function(filename, content) {
43
49
  var parserName = filename.substr(filename.lastIndexOf('.') +1); // file extension
44
50
  if (typeof definitions[parserName] === 'function') {
@@ -47,6 +53,11 @@ Parser.parse = function(filename, content) {
47
53
  // TODO: decide what to do in case of a missing parser
48
54
  };
49
55
 
56
+ /**
57
+ * @param {string} filename
58
+ * @param {string} content
59
+ * @returns {object}
60
+ */
50
61
  Parser.xmlParser = function(filename, content) {
51
62
  if (!XML) {
52
63
  XML = require(XML_DEP);
@@ -60,6 +71,11 @@ Parser.xmlParser = function(filename, content) {
60
71
  return configObject;
61
72
  };
62
73
 
74
+ /**
75
+ * @param {string} filename
76
+ * @param {string} content
77
+ * @returns {object}
78
+ */
63
79
  Parser.jsParser = function(filename, content) {
64
80
  var configObject = require(filename);
65
81
 
@@ -69,6 +85,11 @@ Parser.jsParser = function(filename, content) {
69
85
  return configObject;
70
86
  };
71
87
 
88
+ /**
89
+ * @param {string} filename
90
+ * @param {string} content
91
+ * @returns {object}
92
+ */
72
93
  Parser.tsParser = function(filename, content) {
73
94
  if (!require.extensions['.ts']) {
74
95
  require(TS_DEP).register({
@@ -93,6 +114,11 @@ Parser.tsParser = function(filename, content) {
93
114
  return configObject;
94
115
  };
95
116
 
117
+ /**
118
+ * @param {string} filename
119
+ * @param {string} content
120
+ * @returns {object}
121
+ */
96
122
  Parser.coffeeParser = function(filename, content) {
97
123
  // .coffee files can be loaded with either coffee-script or iced-coffee-script.
98
124
  // Prefer iced-coffee-script, if it exists.
@@ -125,6 +151,11 @@ Parser.coffeeParser = function(filename, content) {
125
151
  return require(filename);
126
152
  };
127
153
 
154
+ /**
155
+ * @param {string} filename
156
+ * @param {string} content
157
+ * @returns {object | undefined}
158
+ */
128
159
  Parser.icedParser = function(filename, content) {
129
160
  Iced = require(ICED_DEP);
130
161
 
@@ -134,6 +165,11 @@ Parser.icedParser = function(filename, content) {
134
165
  }
135
166
  };
136
167
 
168
+ /**
169
+ * @param {string} filename
170
+ * @param {string} content
171
+ * @returns {object | undefined}
172
+ */
137
173
  Parser.yamlParser = function(filename, content) {
138
174
  if (!Yaml && !JSYaml) {
139
175
  // Lazy loading
@@ -155,6 +191,11 @@ Parser.yamlParser = function(filename, content) {
155
191
  }
156
192
  };
157
193
 
194
+ /**
195
+ * @param {string} filename
196
+ * @param {string} content
197
+ * @returns {object}
198
+ */
158
199
  Parser.jsonParser = function(filename, content) {
159
200
  /**
160
201
  * Default JSON parsing to JSON5 parser.
@@ -164,10 +205,20 @@ Parser.jsonParser = function(filename, content) {
164
205
  return JSON5.parse(content);
165
206
  };
166
207
 
208
+ /**
209
+ * @param {string} filename
210
+ * @param {string} content
211
+ * @returns {object}
212
+ */
167
213
  Parser.json5Parser = function(filename, content) {
168
214
  return JSON5.parse(content);
169
215
  };
170
216
 
217
+ /**
218
+ * @param {string} filename
219
+ * @param {string} content
220
+ * @returns {object}
221
+ */
171
222
  Parser.hjsonParser = function(filename, content) {
172
223
  if (!HJSON) {
173
224
  HJSON = require(HJSON_DEP);
@@ -175,6 +226,11 @@ Parser.hjsonParser = function(filename, content) {
175
226
  return HJSON.parse(content);
176
227
  };
177
228
 
229
+ /**
230
+ * @param {string} filename
231
+ * @param {string} content
232
+ * @returns {object}
233
+ */
178
234
  Parser.tomlParser = function(filename, content) {
179
235
  if(!TOML) {
180
236
  TOML = require(TOML_DEP);
@@ -182,6 +238,11 @@ Parser.tomlParser = function(filename, content) {
182
238
  return TOML.parse(content);
183
239
  };
184
240
 
241
+ /**
242
+ * @param {string} filename
243
+ * @param {string} content
244
+ * @returns {object}
245
+ */
185
246
  Parser.csonParser = function(filename, content) {
186
247
  if (!CSON) {
187
248
  CSON = require(CSON_DEP);
@@ -193,6 +254,11 @@ Parser.csonParser = function(filename, content) {
193
254
  return CSON.parse(content);
194
255
  };
195
256
 
257
+ /**
258
+ * @param {string} filename
259
+ * @param {string} content
260
+ * @returns {object}
261
+ */
196
262
  Parser.propertiesParser = function(filename, content) {
197
263
  if (!PPARSER) {
198
264
  PPARSER = require(PPARSER_DEP);
@@ -207,7 +273,7 @@ Parser.propertiesParser = function(filename, content) {
207
273
  *
208
274
  * @protected
209
275
  * @method stripYamlComments
210
- * @param fileStr {string} The string to strip comments from
276
+ * @param {string} fileStr The string to strip comments from
211
277
  * @return {string} The string with comments stripped.
212
278
  */
213
279
  Parser.stripYamlComments = function(fileStr) {
@@ -220,7 +286,8 @@ Parser.stripYamlComments = function(fileStr) {
220
286
  * Parses the environment variable to the boolean equivalent.
221
287
  * Defaults to false
222
288
  *
223
- * @param {String} content - Environment variable value
289
+ * @param {string} filename - Filename of the env variable (not used)
290
+ * @param {string} content - Environment variable value
224
291
  * @return {boolean} - Boolean value fo the passed variable value
225
292
  */
226
293
  Parser.booleanParser = function(filename, content) {
@@ -231,8 +298,9 @@ Parser.booleanParser = function(filename, content) {
231
298
  * Parses the environment variable to the number equivalent.
232
299
  * Defaults to undefined
233
300
  *
234
- * @param {String} content - Environment variable value
235
- * @return {Number} - Number value fo the passed variable value
301
+ * @param {string} filename - Filename of the env variable (not used)
302
+ * @param {string} content - Environment variable value
303
+ * @return {number} - Number value fo the passed variable value
236
304
  */
237
305
  Parser.numberParser = function(filename, content) {
238
306
  const numberValue = Number(content);
@@ -262,10 +330,18 @@ var definitions = {
262
330
  number: Parser.numberParser
263
331
  };
264
332
 
333
+ /**
334
+ * @param {string} name
335
+ * @returns {ParserFn | undefined}
336
+ */
265
337
  Parser.getParser = function(name) {
266
338
  return definitions[name];
267
339
  };
268
340
 
341
+ /**
342
+ * @param {string} name
343
+ * @param {ParserFn} parser
344
+ */
269
345
  Parser.setParser = function(name, parser) {
270
346
  definitions[name] = parser;
271
347
  if (order.indexOf(name) === -1) {
@@ -273,6 +349,10 @@ Parser.setParser = function(name, parser) {
273
349
  }
274
350
  };
275
351
 
352
+ /**
353
+ * @param {string=} name
354
+ * @returns {string[] | number}
355
+ */
276
356
  Parser.getFilesOrder = function(name) {
277
357
  if (name) {
278
358
  return order.indexOf(name);
@@ -280,6 +360,11 @@ Parser.getFilesOrder = function(name) {
280
360
  return order;
281
361
  };
282
362
 
363
+ /**
364
+ * @param {string|string[]} name
365
+ * @param {number=} newIndex
366
+ * @returns {string[]}
367
+ */
283
368
  Parser.setFilesOrder = function(name, newIndex) {
284
369
  if (Array.isArray(name)) {
285
370
  return order = name;
package/raw.js CHANGED
@@ -1,15 +1,16 @@
1
+ const { Util, RawConfig } = require('./lib/util')
2
+
1
3
  /**
2
- * This is meant to wrap configuration objects that should be left as is,
3
- * meaning that the object or its prototype will not be modified in any way
4
+ * @param {any} rawObj
5
+ * @returns {RawConfig & { resolve: () => any }}
4
6
  */
5
- function RawConfig () {
6
- }
7
-
8
7
  function raw(rawObj) {
9
- var obj = Object.create(RawConfig.prototype);
10
- obj.resolve = function () { return rawObj; }
11
- return obj;
8
+ Util.errorOnce('RAW_CONFIG', 'node-config now supports config file callbacks in place of raw(), which is deprecated.');
9
+
10
+ return RawConfig.raw(rawObj);
12
11
  }
13
12
 
13
+ /** @deprecated please use callback function */
14
14
  module.exports.RawConfig = RawConfig;
15
+ /** @deprecated please use callback function */
15
16
  module.exports.raw = raw;
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "checkJs": false,
5
+ "declaration": true,
6
+ "emitDeclarationOnly": true,
7
+ "outDir": "types",
8
+ "rootDir": ".",
9
+ "module": "commonjs",
10
+ "target": "es2020",
11
+ "skipLibCheck": true
12
+ },
13
+ "include": ["*.js", "lib/**/*.js"],
14
+ "exclude": ["test/**", "tools/**", "coverage/**", "node_modules/**"]
15
+ }
@@ -0,0 +1,23 @@
1
+ export type Config = import("./lib/config").Config;
2
+ export type DeferredConfig = import("./defer").DeferredConfig;
3
+ /**
4
+ * @template T
5
+ * @overload
6
+ * @param {Promise<T>} promiseOrFunc
7
+ * @returns {Promise<T>}
8
+ */
9
+ export function asyncConfig<T>(promiseOrFunc: Promise<T>): Promise<T>;
10
+ /**
11
+ * @template T
12
+ * @overload
13
+ * @param {(config: Config, original: any) => Promise<T>} promiseOrFunc
14
+ * @returns {DeferredConfig}
15
+ */
16
+ export function asyncConfig<T>(promiseOrFunc: (config: Config, original: any) => Promise<T>): DeferredConfig;
17
+ /**
18
+ * Do not use `config.get` before executing this method, it will freeze the config object.
19
+ * @param {Config} config the main config object, returned from require('config')
20
+ * @returns {Promise<Config>} once all promises are resolved, return the original config object
21
+ * @deprecated please use async functions with defer and Util.resolveAsyncConfigs
22
+ */
23
+ export function resolveAsyncConfigs(config: Config): Promise<Config>;
@@ -0,0 +1,3 @@
1
+ export const deferConfig: typeof import("./lib/defer").deferConfig;
2
+ export { DeferredConfig };
3
+ import { DeferredConfig } from "./lib/defer.js";