dynamic-config-store
Advanced tools
Comparing version 1.4.0 to 2.0.0
import immer from 'immer'; | ||
import { snakeCase, merge } from 'lodash'; | ||
import { merge, snakeCase } from 'lodash'; | ||
@@ -22,9 +22,9 @@ var datePattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/; | ||
var key = _a[_i]; | ||
var overrideKey = "" + prefix + snakeCase(key).toUpperCase(); | ||
var overrideKey = "".concat(prefix).concat(snakeCase(key).toUpperCase()); | ||
if (obj[key] != null && typeof obj[key] === "object") { | ||
overrideObj[key] = getOverridesFromEnv(overrideKey + "__", obj[key], configNameString); | ||
overrideObj[key] = getOverridesFromEnv("".concat(overrideKey, "__"), obj[key], configNameString); | ||
} | ||
else { | ||
if (typeof processEnv[overrideKey] !== "undefined" && processEnv[overrideKey] != null) { | ||
console.warn("CONFIG" + configNameString + ": found override environment property '" + overrideKey + "'"); | ||
console.warn("CONFIG".concat(configNameString, ": found override environment property '").concat(overrideKey, "'")); | ||
overrideObj[key] = JSON.parse(processEnv[overrideKey], reviveDateObjects); | ||
@@ -58,3 +58,3 @@ } | ||
var envLinksObj = {}; | ||
var configNameString = configName.length > 0 ? " (" + configName + ")" : ""; | ||
var configNameString = configName.length > 0 ? " (".concat(configName, ")") : ""; | ||
for (var _i = 0, _a = Object.keys(envLinks); _i < _a.length; _i++) { | ||
@@ -67,3 +67,3 @@ var key = _a[_i]; | ||
if (required) { | ||
throw new Error("CONFIG" + configNameString + ": property '" + prefixKey + key + "', Couldn't get the REQUIRED environment variable [" + env + "] - you must define it. (alternatively set the link to not-required and provide a default)"); | ||
throw new Error("CONFIG".concat(configNameString, ": property '").concat(prefixKey).concat(key, "', Couldn't get the REQUIRED environment variable [").concat(env, "] - you must define it. (alternatively set the link to not-required and provide a default)")); | ||
} | ||
@@ -79,7 +79,7 @@ /*if (typeof defaultValue === "undefined") { | ||
def = cur.defaultValue; | ||
console.warn("CONFIG" + configNameString + ": property '" + prefixKey + key + "' using default value (" + JSON.stringify(def) + ") because env variable \"" + env + "\" was not set."); | ||
console.warn("CONFIG".concat(configNameString, ": property '").concat(prefixKey).concat(key, "' using default value (").concat(JSON.stringify(def), ") because env variable \"").concat(env, "\" was not set.")); | ||
} | ||
else { | ||
def = values[key]; | ||
console.warn("CONFIG" + configNameString + ": property '" + prefixKey + key + "' couldn't be set from env variable \"" + env + "\" (was not present) - so not changing its value from what was set before (" + def + ")."); | ||
console.warn("CONFIG".concat(configNameString, ": property '").concat(prefixKey).concat(key, "' couldn't be set from env variable \"").concat(env, "\" (was not present) - so not changing its value from what was set before (").concat(def, ").")); | ||
} | ||
@@ -101,3 +101,3 @@ } | ||
else { | ||
throw new Error("CONFIG" + configNameString + ": type of environment link for " + key + " [" + env + "] is of FUNCTION type, but no function has been defined. Check your envLink config."); | ||
throw new Error("CONFIG".concat(configNameString, ": type of environment link for ").concat(key, " [").concat(env, "] is of FUNCTION type, but no function has been defined. Check your envLink config.")); | ||
} | ||
@@ -112,5 +112,5 @@ } | ||
else { | ||
var deeper = getEnvLinksFromEnv(cur, configName, values[key], "" + prefixKey + key + "."); | ||
var deeper = getEnvLinksFromEnv(cur, configName, values[key], "".concat(prefixKey).concat(key, ".")); | ||
if (Object.keys(deeper).length > 0) { | ||
envLinksObj[key] = getEnvLinksFromEnv(cur, configName, values[key], "" + prefixKey + key + "."); | ||
envLinksObj[key] = getEnvLinksFromEnv(cur, configName, values[key], "".concat(prefixKey).concat(key, ".")); | ||
} | ||
@@ -135,6 +135,6 @@ } | ||
try { | ||
this._envOverrides = getOverridesFromEnv(envOverridePrefix, this._values, this._configName.length > 0 ? " (" + this._configName + ")" : ""); | ||
this._envOverrides = getOverridesFromEnv(envOverridePrefix, this._values, this._configName.length > 0 ? " (".concat(this._configName, ")") : ""); | ||
} | ||
catch (e) { | ||
console.error("Your configuration overrides ( prefix: " + envOverridePrefix + " ) need to be JSON parsable - you need to escape string double quotes \\\""); | ||
console.error("Your configuration overrides ( prefix: ".concat(envOverridePrefix, " ) need to be JSON parsable - you need to escape string double quotes \\\"")); | ||
throw e; | ||
@@ -205,3 +205,3 @@ } | ||
export { ETypeOfEnvLink, ConfigStore, __jest_test_internals }; | ||
export { ConfigStore, ETypeOfEnvLink, __jest_test_internals }; | ||
//# sourceMappingURL=index.es5.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.__jest_test_internals = exports.ConfigStore = exports.ETypeOfEnvLink = void 0; | ||
var immer_1 = require("immer"); | ||
@@ -24,9 +25,9 @@ var lodash_1 = require("lodash"); | ||
var key = _a[_i]; | ||
var overrideKey = "" + prefix + lodash_1.snakeCase(key).toUpperCase(); | ||
var overrideKey = "".concat(prefix).concat((0, lodash_1.snakeCase)(key).toUpperCase()); | ||
if (obj[key] != null && typeof obj[key] === "object") { | ||
overrideObj[key] = getOverridesFromEnv(overrideKey + "__", obj[key], configNameString); | ||
overrideObj[key] = getOverridesFromEnv("".concat(overrideKey, "__"), obj[key], configNameString); | ||
} | ||
else { | ||
if (typeof processEnv[overrideKey] !== "undefined" && processEnv[overrideKey] != null) { | ||
console.warn("CONFIG" + configNameString + ": found override environment property '" + overrideKey + "'"); | ||
console.warn("CONFIG".concat(configNameString, ": found override environment property '").concat(overrideKey, "'")); | ||
overrideObj[key] = JSON.parse(processEnv[overrideKey], reviveDateObjects); | ||
@@ -60,3 +61,3 @@ } | ||
var envLinksObj = {}; | ||
var configNameString = configName.length > 0 ? " (" + configName + ")" : ""; | ||
var configNameString = configName.length > 0 ? " (".concat(configName, ")") : ""; | ||
for (var _i = 0, _a = Object.keys(envLinks); _i < _a.length; _i++) { | ||
@@ -69,3 +70,3 @@ var key = _a[_i]; | ||
if (required) { | ||
throw new Error("CONFIG" + configNameString + ": property '" + prefixKey + key + "', Couldn't get the REQUIRED environment variable [" + env + "] - you must define it. (alternatively set the link to not-required and provide a default)"); | ||
throw new Error("CONFIG".concat(configNameString, ": property '").concat(prefixKey).concat(key, "', Couldn't get the REQUIRED environment variable [").concat(env, "] - you must define it. (alternatively set the link to not-required and provide a default)")); | ||
} | ||
@@ -81,7 +82,7 @@ /*if (typeof defaultValue === "undefined") { | ||
def = cur.defaultValue; | ||
console.warn("CONFIG" + configNameString + ": property '" + prefixKey + key + "' using default value (" + JSON.stringify(def) + ") because env variable \"" + env + "\" was not set."); | ||
console.warn("CONFIG".concat(configNameString, ": property '").concat(prefixKey).concat(key, "' using default value (").concat(JSON.stringify(def), ") because env variable \"").concat(env, "\" was not set.")); | ||
} | ||
else { | ||
def = values[key]; | ||
console.warn("CONFIG" + configNameString + ": property '" + prefixKey + key + "' couldn't be set from env variable \"" + env + "\" (was not present) - so not changing its value from what was set before (" + def + ")."); | ||
console.warn("CONFIG".concat(configNameString, ": property '").concat(prefixKey).concat(key, "' couldn't be set from env variable \"").concat(env, "\" (was not present) - so not changing its value from what was set before (").concat(def, ").")); | ||
} | ||
@@ -103,3 +104,3 @@ } | ||
else { | ||
throw new Error("CONFIG" + configNameString + ": type of environment link for " + key + " [" + env + "] is of FUNCTION type, but no function has been defined. Check your envLink config."); | ||
throw new Error("CONFIG".concat(configNameString, ": type of environment link for ").concat(key, " [").concat(env, "] is of FUNCTION type, but no function has been defined. Check your envLink config.")); | ||
} | ||
@@ -114,5 +115,5 @@ } | ||
else { | ||
var deeper = getEnvLinksFromEnv(cur, configName, values[key], "" + prefixKey + key + "."); | ||
var deeper = getEnvLinksFromEnv(cur, configName, values[key], "".concat(prefixKey).concat(key, ".")); | ||
if (Object.keys(deeper).length > 0) { | ||
envLinksObj[key] = getEnvLinksFromEnv(cur, configName, values[key], "" + prefixKey + key + "."); | ||
envLinksObj[key] = getEnvLinksFromEnv(cur, configName, values[key], "".concat(prefixKey).concat(key, ".")); | ||
} | ||
@@ -137,6 +138,6 @@ } | ||
try { | ||
this._envOverrides = getOverridesFromEnv(envOverridePrefix, this._values, this._configName.length > 0 ? " (" + this._configName + ")" : ""); | ||
this._envOverrides = getOverridesFromEnv(envOverridePrefix, this._values, this._configName.length > 0 ? " (".concat(this._configName, ")") : ""); | ||
} | ||
catch (e) { | ||
console.error("Your configuration overrides ( prefix: " + envOverridePrefix + " ) need to be JSON parsable - you need to escape string double quotes \\\""); | ||
console.error("Your configuration overrides ( prefix: ".concat(envOverridePrefix, " ) need to be JSON parsable - you need to escape string double quotes \\\"")); | ||
throw e; | ||
@@ -151,3 +152,3 @@ } | ||
} | ||
this._envLinks = lodash_2.merge({}, this._envLinks, getEnvLinksFromEnv(envLinks, this._configName, this._values)); | ||
this._envLinks = (0, lodash_2.merge)({}, this._envLinks, getEnvLinksFromEnv(envLinks, this._configName, this._values)); | ||
this.finalizeValues(); | ||
@@ -161,3 +162,3 @@ }; | ||
if (envOverridePrefix === void 0) { envOverridePrefix = ""; } | ||
this._values = lodash_2.merge({}, this._values, config); | ||
this._values = (0, lodash_2.merge)({}, this._values, config); | ||
if (envOverridePrefix.length > 0) { | ||
@@ -173,8 +174,8 @@ this.setEnvOverridePrefix(envOverridePrefix); | ||
if (ignoreOverrides || ignoreEnvLinks || ignoreReactions) { | ||
var returnValues = lodash_2.merge({}, this._values); | ||
var returnValues = (0, lodash_2.merge)({}, this._values); | ||
if (!ignoreEnvLinks) { | ||
returnValues = lodash_2.merge(returnValues, this._envLinks); | ||
returnValues = (0, lodash_2.merge)(returnValues, this._envLinks); | ||
} | ||
if (!ignoreOverrides) { | ||
returnValues = lodash_2.merge(returnValues, this._envOverrides); | ||
returnValues = (0, lodash_2.merge)(returnValues, this._envOverrides); | ||
} | ||
@@ -184,3 +185,3 @@ if (!ignoreReactions) { | ||
var changeReaction = _f[_i]; | ||
returnValues = immer_1.default(returnValues, changeReaction); | ||
returnValues = (0, immer_1.default)(returnValues, changeReaction); | ||
} | ||
@@ -199,6 +200,6 @@ } | ||
ConfigStore.prototype.finalizeValues = function () { | ||
this._valuesWithAugmentations = lodash_2.merge({}, this._values, this._envLinks, this._envOverrides); | ||
this._valuesWithAugmentations = (0, lodash_2.merge)({}, this._values, this._envLinks, this._envOverrides); | ||
for (var _i = 0, _a = this._configChangeReactions; _i < _a.length; _i++) { | ||
var changeReaction = _a[_i]; | ||
this._valuesWithAugmentations = immer_1.default(this._valuesWithAugmentations, changeReaction); | ||
this._valuesWithAugmentations = (0, immer_1.default)(this._valuesWithAugmentations, changeReaction); | ||
} | ||
@@ -205,0 +206,0 @@ }; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('immer'), require('lodash')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'immer', 'lodash'], factory) : | ||
(factory((global.index = {}),global.immer,global.lodash)); | ||
}(this, (function (exports,immer,lodash) { 'use strict'; | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.index = {}, global.immer, global.lodash)); | ||
})(this, (function (exports, immer, lodash) { 'use strict'; | ||
immer = immer && immer.hasOwnProperty('default') ? immer['default'] : immer; | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var immer__default = /*#__PURE__*/_interopDefaultLegacy(immer); | ||
var datePattern = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/; | ||
@@ -27,9 +29,9 @@ function isString(value) { | ||
var key = _a[_i]; | ||
var overrideKey = "" + prefix + lodash.snakeCase(key).toUpperCase(); | ||
var overrideKey = "".concat(prefix).concat(lodash.snakeCase(key).toUpperCase()); | ||
if (obj[key] != null && typeof obj[key] === "object") { | ||
overrideObj[key] = getOverridesFromEnv(overrideKey + "__", obj[key], configNameString); | ||
overrideObj[key] = getOverridesFromEnv("".concat(overrideKey, "__"), obj[key], configNameString); | ||
} | ||
else { | ||
if (typeof processEnv[overrideKey] !== "undefined" && processEnv[overrideKey] != null) { | ||
console.warn("CONFIG" + configNameString + ": found override environment property '" + overrideKey + "'"); | ||
console.warn("CONFIG".concat(configNameString, ": found override environment property '").concat(overrideKey, "'")); | ||
overrideObj[key] = JSON.parse(processEnv[overrideKey], reviveDateObjects); | ||
@@ -41,2 +43,3 @@ } | ||
} | ||
exports.ETypeOfEnvLink = void 0; | ||
(function (ETypeOfEnvLink) { | ||
@@ -63,3 +66,3 @@ ETypeOfEnvLink["STRING"] = "STRING"; | ||
var envLinksObj = {}; | ||
var configNameString = configName.length > 0 ? " (" + configName + ")" : ""; | ||
var configNameString = configName.length > 0 ? " (".concat(configName, ")") : ""; | ||
for (var _i = 0, _a = Object.keys(envLinks); _i < _a.length; _i++) { | ||
@@ -72,3 +75,3 @@ var key = _a[_i]; | ||
if (required) { | ||
throw new Error("CONFIG" + configNameString + ": property '" + prefixKey + key + "', Couldn't get the REQUIRED environment variable [" + env + "] - you must define it. (alternatively set the link to not-required and provide a default)"); | ||
throw new Error("CONFIG".concat(configNameString, ": property '").concat(prefixKey).concat(key, "', Couldn't get the REQUIRED environment variable [").concat(env, "] - you must define it. (alternatively set the link to not-required and provide a default)")); | ||
} | ||
@@ -84,7 +87,7 @@ /*if (typeof defaultValue === "undefined") { | ||
def = cur.defaultValue; | ||
console.warn("CONFIG" + configNameString + ": property '" + prefixKey + key + "' using default value (" + JSON.stringify(def) + ") because env variable \"" + env + "\" was not set."); | ||
console.warn("CONFIG".concat(configNameString, ": property '").concat(prefixKey).concat(key, "' using default value (").concat(JSON.stringify(def), ") because env variable \"").concat(env, "\" was not set.")); | ||
} | ||
else { | ||
def = values[key]; | ||
console.warn("CONFIG" + configNameString + ": property '" + prefixKey + key + "' couldn't be set from env variable \"" + env + "\" (was not present) - so not changing its value from what was set before (" + def + ")."); | ||
console.warn("CONFIG".concat(configNameString, ": property '").concat(prefixKey).concat(key, "' couldn't be set from env variable \"").concat(env, "\" (was not present) - so not changing its value from what was set before (").concat(def, ").")); | ||
} | ||
@@ -106,3 +109,3 @@ } | ||
else { | ||
throw new Error("CONFIG" + configNameString + ": type of environment link for " + key + " [" + env + "] is of FUNCTION type, but no function has been defined. Check your envLink config."); | ||
throw new Error("CONFIG".concat(configNameString, ": type of environment link for ").concat(key, " [").concat(env, "] is of FUNCTION type, but no function has been defined. Check your envLink config.")); | ||
} | ||
@@ -117,5 +120,5 @@ } | ||
else { | ||
var deeper = getEnvLinksFromEnv(cur, configName, values[key], "" + prefixKey + key + "."); | ||
var deeper = getEnvLinksFromEnv(cur, configName, values[key], "".concat(prefixKey).concat(key, ".")); | ||
if (Object.keys(deeper).length > 0) { | ||
envLinksObj[key] = getEnvLinksFromEnv(cur, configName, values[key], "" + prefixKey + key + "."); | ||
envLinksObj[key] = getEnvLinksFromEnv(cur, configName, values[key], "".concat(prefixKey).concat(key, ".")); | ||
} | ||
@@ -140,6 +143,6 @@ } | ||
try { | ||
this._envOverrides = getOverridesFromEnv(envOverridePrefix, this._values, this._configName.length > 0 ? " (" + this._configName + ")" : ""); | ||
this._envOverrides = getOverridesFromEnv(envOverridePrefix, this._values, this._configName.length > 0 ? " (".concat(this._configName, ")") : ""); | ||
} | ||
catch (e) { | ||
console.error("Your configuration overrides ( prefix: " + envOverridePrefix + " ) need to be JSON parsable - you need to escape string double quotes \\\""); | ||
console.error("Your configuration overrides ( prefix: ".concat(envOverridePrefix, " ) need to be JSON parsable - you need to escape string double quotes \\\"")); | ||
throw e; | ||
@@ -184,3 +187,3 @@ } | ||
var changeReaction = _f[_i]; | ||
returnValues = immer(returnValues, changeReaction); | ||
returnValues = immer__default["default"](returnValues, changeReaction); | ||
} | ||
@@ -202,3 +205,3 @@ } | ||
var changeReaction = _a[_i]; | ||
this._valuesWithAugmentations = immer(this._valuesWithAugmentations, changeReaction); | ||
this._valuesWithAugmentations = immer__default["default"](this._valuesWithAugmentations, changeReaction); | ||
} | ||
@@ -217,3 +220,3 @@ }; | ||
}))); | ||
})); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "dynamic-config-store", | ||
"version": "1.4.0", | ||
"version": "2.0.0", | ||
"description": "Simple configuration utility for deployments and libraries", | ||
@@ -28,3 +28,3 @@ "keywords": [ | ||
"clean": "rimraf dist", | ||
"build": "tsc --module commonjs && rollup -c rollup.config.ts && typedoc --out docs --target es6 --theme minimal --mode file src", | ||
"build": "tsc --module commonjs && rollup -c rollup.config.ts && typedoc --out docs src/index.ts", | ||
"prepublish": "npm run clean && npm run build", | ||
@@ -48,23 +48,23 @@ "test": "jest" | ||
"dependencies": { | ||
"immer": "^3.1.1", | ||
"lodash": "^4.17.11" | ||
"immer": "^9.0.14", | ||
"lodash": "^4.17.21" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^23.3.9", | ||
"@types/lodash": "^4.14.118", | ||
"@types/node": "^10.12.6", | ||
"jest": "^23.6.0", | ||
"rimraf": "^2.6.2", | ||
"ts-jest": "^23.10.4", | ||
"typedoc": "^0.13.0", | ||
"typescript": "^3.4.5", | ||
"rollup": "^0.66.2", | ||
"rollup-plugin-commonjs": "^9.1.8", | ||
"rollup-plugin-json": "^3.1.0", | ||
"rollup-plugin-node-resolve": "^3.4.0", | ||
"rollup-plugin-sourcemaps": "^0.4.2", | ||
"rollup-plugin-typescript2": "^0.17.0", | ||
"immer": "^3.1.1", | ||
"lodash": "^4.17.11" | ||
"@types/jest": "^27.5.1", | ||
"@types/lodash": "^4.14.182", | ||
"@types/node": "^17.0.35", | ||
"jest": "^28.1.0", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^28.0.2", | ||
"typedoc": "^0.22.15", | ||
"typescript": "^4.6.4", | ||
"rollup": "^2.74.1", | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-json": "^4.0.0", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"rollup-plugin-sourcemaps": "^0.6.3", | ||
"rollup-plugin-typescript2": "^0.31.2", | ||
"immer": "^9.0.14", | ||
"lodash": "^4.17.21" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
89018
670
+ Addedimmer@9.0.21(transitive)
- Removedimmer@3.3.0(transitive)
Updatedimmer@^9.0.14
Updatedlodash@^4.17.21