@backstage/config
Advanced tools
Comparing version 0.0.0-nightly-20240301021339 to 0.0.0-nightly-20240302020838
# @backstage/config | ||
## 0.0.0-nightly-20240301021339 | ||
## 0.0.0-nightly-20240302020838 | ||
### Minor Changes | ||
- 50cf9df: The `ConfigReader` now treats `null` values as present but explicitly undefined, meaning it will not fall back to the next level of configuration. | ||
### Patch Changes | ||
- Updated dependencies | ||
- @backstage/errors@0.0.0-nightly-20240301021339 | ||
- @backstage/errors@0.0.0-nightly-20240302020838 | ||
- @backstage/types@1.1.1 | ||
@@ -10,0 +14,0 @@ |
@@ -6,10 +6,3 @@ 'use strict'; | ||
var errors$1 = require('@backstage/errors'); | ||
var cloneDeep = require('lodash/cloneDeep'); | ||
var mergeWith = require('lodash/mergeWith'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var cloneDeep__default = /*#__PURE__*/_interopDefaultLegacy(cloneDeep); | ||
var mergeWith__default = /*#__PURE__*/_interopDefaultLegacy(mergeWith); | ||
const propsOfHumanDuration = [ | ||
@@ -75,2 +68,33 @@ "years", | ||
} | ||
function cloneDeep(value) { | ||
if (typeof value !== "object" || value === null) { | ||
return value; | ||
} | ||
if (Array.isArray(value)) { | ||
return value.map(cloneDeep); | ||
} | ||
return Object.fromEntries( | ||
Object.entries(value).map(([k, v]) => [k, cloneDeep(v)]) | ||
); | ||
} | ||
function merge(into, from) { | ||
if (into === null) { | ||
return void 0; | ||
} | ||
if (into === void 0) { | ||
return from === void 0 ? void 0 : merge(from); | ||
} | ||
if (typeof into !== "object" || Array.isArray(into)) { | ||
return into; | ||
} | ||
const fromObj = isObject(from) ? from : {}; | ||
const out = {}; | ||
for (const key of /* @__PURE__ */ new Set([...Object.keys(into), ...Object.keys(fromObj)])) { | ||
const val = merge(into[key], fromObj[key]); | ||
if (val !== void 0) { | ||
out[key] = val; | ||
} | ||
} | ||
return out; | ||
} | ||
function typeOf(value) { | ||
@@ -95,4 +119,4 @@ if (value === null) { | ||
}, | ||
missing(key) { | ||
return `Missing required config value at '${key}'`; | ||
missing(key, context) { | ||
return `Missing required config value at '${key}' in '${context}'`; | ||
}, | ||
@@ -146,2 +170,5 @@ convert(key, context, expected) { | ||
const value = this.readValue(key); | ||
if (value === null) { | ||
return false; | ||
} | ||
if (value !== void 0) { | ||
@@ -157,3 +184,8 @@ return true; | ||
const fallbackKeys = (_b = (_a = this.fallback) == null ? void 0 : _a.keys()) != null ? _b : []; | ||
return [.../* @__PURE__ */ new Set([...localKeys, ...fallbackKeys])]; | ||
return [.../* @__PURE__ */ new Set([...localKeys, ...fallbackKeys])].filter( | ||
(k) => { | ||
var _a2; | ||
return ((_a2 = this.data) == null ? void 0 : _a2[k]) !== null; | ||
} | ||
); | ||
} | ||
@@ -164,3 +196,3 @@ /** {@inheritdoc Config.get} */ | ||
if (value === void 0) { | ||
throw new Error(errors.missing(this.fullKey(key != null ? key : ""))); | ||
throw new Error(errors.missing(this.fullKey(key != null ? key : ""), this.context)); | ||
} | ||
@@ -172,4 +204,7 @@ return value; | ||
var _a, _b; | ||
const value = cloneDeep__default["default"](this.readValue(key)); | ||
const value = cloneDeep(this.readValue(key)); | ||
const fallbackValue = (_a = this.fallback) == null ? void 0 : _a.getOptional(key); | ||
if (value === null) { | ||
return void 0; | ||
} | ||
if (value === void 0) { | ||
@@ -187,12 +222,7 @@ if (process.env.NODE_ENV === "development") { | ||
} | ||
return fallbackValue; | ||
return merge(fallbackValue); | ||
} else if (fallbackValue === void 0) { | ||
return value; | ||
return merge(value); | ||
} | ||
return mergeWith__default["default"]( | ||
{}, | ||
{ value: fallbackValue }, | ||
{ value }, | ||
(into, from) => !isObject(from) || !isObject(into) ? from : void 0 | ||
).value; | ||
return merge(value, fallbackValue); | ||
} | ||
@@ -203,3 +233,3 @@ /** {@inheritdoc Config.getConfig} */ | ||
if (value === void 0) { | ||
throw new Error(errors.missing(this.fullKey(key))); | ||
throw new Error(errors.missing(this.fullKey(key), this.context)); | ||
} | ||
@@ -216,2 +246,5 @@ return value; | ||
} | ||
if (value === null) { | ||
return void 0; | ||
} | ||
if (value !== void 0) { | ||
@@ -228,3 +261,3 @@ throw new TypeError( | ||
if (value === void 0) { | ||
throw new Error(errors.missing(this.fullKey(key))); | ||
throw new Error(errors.missing(this.fullKey(key), this.context)); | ||
} | ||
@@ -265,3 +298,3 @@ return value; | ||
if (value === void 0) { | ||
throw new Error(errors.missing(this.fullKey(key))); | ||
throw new Error(errors.missing(this.fullKey(key), this.context)); | ||
} | ||
@@ -291,3 +324,3 @@ return value; | ||
if (value === void 0) { | ||
throw new Error(errors.missing(this.fullKey(key))); | ||
throw new Error(errors.missing(this.fullKey(key), this.context)); | ||
} | ||
@@ -318,3 +351,3 @@ return value; | ||
if (value === void 0) { | ||
throw new Error(errors.missing(this.fullKey(key))); | ||
throw new Error(errors.missing(this.fullKey(key), this.context)); | ||
} | ||
@@ -334,3 +367,3 @@ return value; | ||
if (value === void 0) { | ||
throw new Error(errors.missing(this.fullKey(key))); | ||
throw new Error(errors.missing(this.fullKey(key), this.context)); | ||
} | ||
@@ -381,2 +414,5 @@ return value; | ||
} | ||
if (value === null) { | ||
return void 0; | ||
} | ||
const result = validate(value); | ||
@@ -410,3 +446,3 @@ if (result !== true) { | ||
value = value[part]; | ||
} else if (value !== void 0) { | ||
} else if (value !== void 0 && value !== null) { | ||
const badKey = this.fullKey(parts.slice(0, index).join(".")); | ||
@@ -413,0 +449,0 @@ throw new TypeError( |
import { InputError } from '@backstage/errors'; | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
import mergeWith from 'lodash/mergeWith'; | ||
@@ -65,2 +63,33 @@ const propsOfHumanDuration = [ | ||
} | ||
function cloneDeep(value) { | ||
if (typeof value !== "object" || value === null) { | ||
return value; | ||
} | ||
if (Array.isArray(value)) { | ||
return value.map(cloneDeep); | ||
} | ||
return Object.fromEntries( | ||
Object.entries(value).map(([k, v]) => [k, cloneDeep(v)]) | ||
); | ||
} | ||
function merge(into, from) { | ||
if (into === null) { | ||
return void 0; | ||
} | ||
if (into === void 0) { | ||
return from === void 0 ? void 0 : merge(from); | ||
} | ||
if (typeof into !== "object" || Array.isArray(into)) { | ||
return into; | ||
} | ||
const fromObj = isObject(from) ? from : {}; | ||
const out = {}; | ||
for (const key of /* @__PURE__ */ new Set([...Object.keys(into), ...Object.keys(fromObj)])) { | ||
const val = merge(into[key], fromObj[key]); | ||
if (val !== void 0) { | ||
out[key] = val; | ||
} | ||
} | ||
return out; | ||
} | ||
function typeOf(value) { | ||
@@ -85,4 +114,4 @@ if (value === null) { | ||
}, | ||
missing(key) { | ||
return `Missing required config value at '${key}'`; | ||
missing(key, context) { | ||
return `Missing required config value at '${key}' in '${context}'`; | ||
}, | ||
@@ -136,2 +165,5 @@ convert(key, context, expected) { | ||
const value = this.readValue(key); | ||
if (value === null) { | ||
return false; | ||
} | ||
if (value !== void 0) { | ||
@@ -147,3 +179,8 @@ return true; | ||
const fallbackKeys = (_b = (_a = this.fallback) == null ? void 0 : _a.keys()) != null ? _b : []; | ||
return [.../* @__PURE__ */ new Set([...localKeys, ...fallbackKeys])]; | ||
return [.../* @__PURE__ */ new Set([...localKeys, ...fallbackKeys])].filter( | ||
(k) => { | ||
var _a2; | ||
return ((_a2 = this.data) == null ? void 0 : _a2[k]) !== null; | ||
} | ||
); | ||
} | ||
@@ -154,3 +191,3 @@ /** {@inheritdoc Config.get} */ | ||
if (value === void 0) { | ||
throw new Error(errors.missing(this.fullKey(key != null ? key : ""))); | ||
throw new Error(errors.missing(this.fullKey(key != null ? key : ""), this.context)); | ||
} | ||
@@ -164,2 +201,5 @@ return value; | ||
const fallbackValue = (_a = this.fallback) == null ? void 0 : _a.getOptional(key); | ||
if (value === null) { | ||
return void 0; | ||
} | ||
if (value === void 0) { | ||
@@ -177,12 +217,7 @@ if (process.env.NODE_ENV === "development") { | ||
} | ||
return fallbackValue; | ||
return merge(fallbackValue); | ||
} else if (fallbackValue === void 0) { | ||
return value; | ||
return merge(value); | ||
} | ||
return mergeWith( | ||
{}, | ||
{ value: fallbackValue }, | ||
{ value }, | ||
(into, from) => !isObject(from) || !isObject(into) ? from : void 0 | ||
).value; | ||
return merge(value, fallbackValue); | ||
} | ||
@@ -193,3 +228,3 @@ /** {@inheritdoc Config.getConfig} */ | ||
if (value === void 0) { | ||
throw new Error(errors.missing(this.fullKey(key))); | ||
throw new Error(errors.missing(this.fullKey(key), this.context)); | ||
} | ||
@@ -206,2 +241,5 @@ return value; | ||
} | ||
if (value === null) { | ||
return void 0; | ||
} | ||
if (value !== void 0) { | ||
@@ -218,3 +256,3 @@ throw new TypeError( | ||
if (value === void 0) { | ||
throw new Error(errors.missing(this.fullKey(key))); | ||
throw new Error(errors.missing(this.fullKey(key), this.context)); | ||
} | ||
@@ -255,3 +293,3 @@ return value; | ||
if (value === void 0) { | ||
throw new Error(errors.missing(this.fullKey(key))); | ||
throw new Error(errors.missing(this.fullKey(key), this.context)); | ||
} | ||
@@ -281,3 +319,3 @@ return value; | ||
if (value === void 0) { | ||
throw new Error(errors.missing(this.fullKey(key))); | ||
throw new Error(errors.missing(this.fullKey(key), this.context)); | ||
} | ||
@@ -308,3 +346,3 @@ return value; | ||
if (value === void 0) { | ||
throw new Error(errors.missing(this.fullKey(key))); | ||
throw new Error(errors.missing(this.fullKey(key), this.context)); | ||
} | ||
@@ -324,3 +362,3 @@ return value; | ||
if (value === void 0) { | ||
throw new Error(errors.missing(this.fullKey(key))); | ||
throw new Error(errors.missing(this.fullKey(key), this.context)); | ||
} | ||
@@ -371,2 +409,5 @@ return value; | ||
} | ||
if (value === null) { | ||
return void 0; | ||
} | ||
const result = validate(value); | ||
@@ -400,3 +441,3 @@ if (result !== true) { | ||
value = value[part]; | ||
} else if (value !== void 0) { | ||
} else if (value !== void 0 && value !== null) { | ||
const badKey = this.fullKey(parts.slice(0, index).join(".")); | ||
@@ -403,0 +444,0 @@ throw new TypeError( |
{ | ||
"name": "@backstage/config", | ||
"version": "0.0.0-nightly-20240301021339", | ||
"version": "0.0.0-nightly-20240302020838", | ||
"description": "Config API used by Backstage core, backend, and CLI", | ||
@@ -39,11 +39,10 @@ "backstage": { | ||
"dependencies": { | ||
"@backstage/errors": "^0.0.0-nightly-20240301021339", | ||
"@backstage/types": "^1.1.1", | ||
"lodash": "^4.17.21" | ||
"@backstage/errors": "^0.0.0-nightly-20240302020838", | ||
"@backstage/types": "^1.1.1" | ||
}, | ||
"devDependencies": { | ||
"@backstage/cli": "^0.0.0-nightly-20240301021339", | ||
"@backstage/test-utils": "^0.0.0-nightly-20240301021339" | ||
"@backstage/cli": "^0.0.0-nightly-20240302020838", | ||
"@backstage/test-utils": "^0.0.0-nightly-20240302020838" | ||
}, | ||
"module": "dist/index.esm.js" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
114465
2
1102
- Removedlodash@^4.17.21
- Removedlodash@4.17.21(transitive)