config 4.4.0 → 5.0.0-alpha.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/async.js DELETED
@@ -1,91 +0,0 @@
1
- const asyncSymbol = Symbol('asyncSymbol');
2
- const { deferConfig } = require('./defer');
3
-
4
- /** @typedef {import('./lib/config').Config} Config */
5
- /** @typedef {import('./defer').DeferredConfig} DeferredConfig */
6
-
7
- /**
8
- * @template T
9
- * @overload
10
- * @param {Promise<T>} promiseOrFunc
11
- * @returns {Promise<T>}
12
- */
13
- /**
14
- * @template T
15
- * @overload
16
- * @param {(config: Config, original: any) => Promise<T>} promiseOrFunc
17
- * @returns {DeferredConfig}
18
- */
19
- /**
20
- * @template T
21
- * @param {Promise<T> | ((config: Config, original: any) => Promise<T>)} promiseOrFunc
22
- * the promise will determine a property's value once resolved
23
- * can also be a function to defer which resolves to a promise
24
- * @returns {Promise<T> | DeferredConfig} a marked promise to be resolve later using `resolveAsyncConfigs`
25
- * @deprecated please use async functions with defer
26
- */
27
- function asyncConfig(promiseOrFunc) {
28
- const { Util } = require('./lib/util.js');
29
- Util.errorOnce("ASYNC_CONFIG", 'config/async.js is deprecated. Please use async functions with the new defer functionality');
30
-
31
- if (typeof promiseOrFunc === 'function') { // also acts as deferConfig
32
- return deferConfig(function (config, original) {
33
- var release;
34
- function registerRelease(resolve) { release = resolve; }
35
- function callFunc() { return promiseOrFunc.call(config, config, original); }
36
- var promise = asyncConfig(new Promise(registerRelease).then(callFunc));
37
- promise.release = release;
38
- return promise;
39
- });
40
- }
41
- var promise = promiseOrFunc;
42
- promise.async = asyncSymbol;
43
- promise.prepare = function(config, prop, property) {
44
- if (promise.release) {
45
- promise.release();
46
- }
47
- return function() {
48
- return promise.then(function(value) {
49
- Object.defineProperty(prop, property, {value: value});
50
- });
51
- };
52
- };
53
- return promise;
54
- }
55
-
56
- /**
57
- * Do not use `config.get` before executing this method, it will freeze the config object.
58
- * @param {Config} config the main config object, returned from require('config')
59
- * @returns {Promise<Config>} once all promises are resolved, return the original config object
60
- * @deprecated please use async functions with defer and Util.resolveAsyncConfigs
61
- */
62
- function resolveAsyncConfigs(config) {
63
- var promises = [];
64
- var resolvers = [];
65
- (function iterate(prop) {
66
- if (prop.constructor === String) {
67
- return;
68
- }
69
-
70
- var propsToSort = Object.keys(prop).filter((property) => prop[property] != null);
71
- propsToSort.sort().forEach(function(property) {
72
- if (prop[property].constructor === Object) {
73
- iterate(prop[property]);
74
- }
75
- else if (prop[property].constructor === Array) {
76
- prop[property].forEach(iterate);
77
- }
78
- else if (prop[property].async === asyncSymbol) {
79
- resolvers.push(prop[property].prepare(config, prop, property));
80
- promises.push(prop[property]);
81
- }
82
- });
83
- })(config);
84
- return Promise.all(promises).then(function() {
85
- resolvers.forEach(function(resolve) { resolve(); });
86
- return config;
87
- });
88
- }
89
-
90
- module.exports.asyncConfig = asyncConfig;
91
- module.exports.resolveAsyncConfigs = resolveAsyncConfigs;
package/defer.js DELETED
@@ -1,19 +0,0 @@
1
- const { deferConfig, DeferredConfig } = require('./lib/defer.js');
2
-
3
- /**
4
- * @deprecated please use the new callback mechanism
5
- * @see lib/defer.js
6
- * @type {typeof import('./lib/defer').deferConfig}
7
- */
8
- module.exports.deferConfig = (...args) => {
9
- const { Util } = require('./lib/util.js');
10
-
11
- Util.errorOnce("DEFER_CONFIG", 'node-config now supports config file callbacks in place of deferConfig(), which is deprecated.');
12
- return deferConfig(...args);
13
- }
14
-
15
- /**
16
- * @deprecated please use the new callback mechanism
17
- * @type {typeof import('./lib/defer').DeferredConfig}
18
- */
19
- module.exports.DeferredConfig = DeferredConfig;
package/raw.js DELETED
@@ -1,16 +0,0 @@
1
- const { Util, RawConfig } = require('./lib/util')
2
-
3
- /**
4
- * @param {any} rawObj
5
- * @returns {RawConfig & { resolve: () => any }}
6
- */
7
- function raw(rawObj) {
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);
11
- }
12
-
13
- /** @deprecated please use callback function */
14
- module.exports.RawConfig = RawConfig;
15
- /** @deprecated please use callback function */
16
- module.exports.raw = raw;