MCPcopy Create free account
hub / github.com/node-config/node-config / resolveDeferredConfigs

Method resolveDeferredConfigs

lib/util.js:409–444  ·  view source on GitHub ↗

* * @param {object} config

(config)

Source from the content-addressed store, hash-verified

407 * @param {object} config
408 */
409 static resolveDeferredConfigs(config) {
410 const deferred = [];
411
412 function _iterate (prop) {
413 if (prop == null || prop.constructor === String) {
414 return;
415 }
416
417 // We put the properties we are going to look it in an array to keep the order predictable
418 const propsToSort = Object.keys(prop).filter((property) => prop[property] != null);
419
420 // Second step is to iterate of the elements in a predictable (sorted) order
421 for (let name of propsToSort.sort()) {
422 const property = prop[name];
423
424 if (property.constructor === Object) {
425 _iterate(property);
426 } else if (property.constructor === Array) {
427 property.forEach(function (entry, i) {
428 if (entry instanceof DeferredConfig) {
429 deferred.push(entry.prepare(config, property, i));
430 } else {
431 _iterate(property[i]);
432 }
433 });
434 } else if (property instanceof DeferredConfig) {
435 deferred.push(property.prepare(config, prop, name));
436 }
437 // else: Nothing to do. Keep the property how it is.
438 }
439 }
440
441 _iterate(config);
442
443 deferred.forEach((defer) => { defer.resolve() });
444 }
445
446 /**
447 * Used to resolve configs that have async functions.

Callers 3

scanMethod · 0.80
setModuleDefaultsMethod · 0.80
0-util.jsFile · 0.80

Calls 1

resolveMethod · 0.80

Tested by

no test coverage detected