@backstage/config
Advanced tools
Comparing version 0.0.0-nightly-20230620022155 to 0.0.0-nightly-20230830021355
# @backstage/config | ||
## 0.0.0-nightly-20230620022155 | ||
## 0.0.0-nightly-20230830021355 | ||
### Minor Changes | ||
- 62f448edb0b5: Added a `readDurationFromConfig` function | ||
### Patch Changes | ||
- Updated dependencies | ||
- @backstage/types@0.0.0-nightly-20230620022155 | ||
- @backstage/errors@1.2.1 | ||
- @backstage/types@1.1.0 | ||
## 1.1.0-next.0 | ||
### Minor Changes | ||
- 62f448edb0b5: Added a `readDurationFromConfig` function | ||
### Patch Changes | ||
- Updated dependencies | ||
- @backstage/errors@1.2.1 | ||
- @backstage/types@1.1.0 | ||
## 1.0.8 | ||
### Patch Changes | ||
- Updated dependencies | ||
- @backstage/types@1.1.0 | ||
## 1.0.7 | ||
@@ -11,0 +35,0 @@ |
@@ -5,2 +5,3 @@ 'use strict'; | ||
var errors$1 = require('@backstage/errors'); | ||
var cloneDeep = require('lodash/cloneDeep'); | ||
@@ -14,2 +15,58 @@ var mergeWith = require('lodash/mergeWith'); | ||
const propsOfHumanDuration = [ | ||
"years", | ||
"months", | ||
"weeks", | ||
"days", | ||
"hours", | ||
"minutes", | ||
"seconds", | ||
"milliseconds" | ||
]; | ||
function readDurationFromConfig(config, options) { | ||
let root; | ||
let found = false; | ||
const result = {}; | ||
try { | ||
root = (options == null ? void 0 : options.key) ? config.getConfig(options.key) : config; | ||
for (const prop of propsOfHumanDuration) { | ||
const value = root.getOptionalNumber(prop); | ||
if (value !== void 0) { | ||
result[prop] = value; | ||
found = true; | ||
} | ||
} | ||
} catch (error) { | ||
throw new errors$1.InputError(`Failed to read duration from config, ${error}`); | ||
} | ||
try { | ||
if (!found) { | ||
const good = propsOfHumanDuration.map((p) => `'${p}'`).join(", "); | ||
throw new Error(`Needs one or more of ${good}`); | ||
} | ||
const invalidProps = root.keys().filter((prop) => !propsOfHumanDuration.includes(prop)); | ||
if (invalidProps.length) { | ||
const what = invalidProps.length === 1 ? "property" : "properties"; | ||
const bad = invalidProps.map((p) => `'${p}'`).join(", "); | ||
const good = propsOfHumanDuration.map((p) => `'${p}'`).join(", "); | ||
throw new Error( | ||
`Unknown ${what} ${bad}; expected one or more of ${good}` | ||
); | ||
} | ||
} catch (error) { | ||
let prefix = "Failed to read duration from config"; | ||
if (options == null ? void 0 : options.key) { | ||
prefix += ` at '${options.key}'`; | ||
} | ||
throw new errors$1.InputError(`${prefix}, ${error}`); | ||
} | ||
return result; | ||
} | ||
var __defProp = Object.defineProperty; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __publicField = (obj, key, value) => { | ||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
return value; | ||
}; | ||
const CONFIG_KEY_PART_PATTERN = /^[a-z][a-z0-9]*(?:[-_][a-z][a-z0-9]*)*$/i; | ||
@@ -51,3 +108,11 @@ function isObject(value) { | ||
this.prefix = prefix; | ||
this.notifiedFilteredKeys = /* @__PURE__ */ new Set(); | ||
/** | ||
* A set of key paths that where removed from the config due to not being visible. | ||
* | ||
* This was added as a mutable private member to avoid changes to the public API. | ||
* Its only purpose of this is to warn users of missing visibility when running | ||
* the frontend in development mode. | ||
*/ | ||
__publicField(this, "filteredKeys"); | ||
__publicField(this, "notifiedFilteredKeys", /* @__PURE__ */ new Set()); | ||
} | ||
@@ -344,2 +409,3 @@ /** | ||
exports.ConfigReader = ConfigReader; | ||
exports.readDurationFromConfig = readDurationFromConfig; | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,2 +0,3 @@ | ||
import { JsonPrimitive as JsonPrimitive$1, JsonObject as JsonObject$1, JsonArray as JsonArray$1, JsonValue as JsonValue$1 } from '@backstage/types'; | ||
import { JsonPrimitive as JsonPrimitive$1, JsonObject as JsonObject$1, JsonArray as JsonArray$1, JsonValue as JsonValue$1, HumanDuration } from '@backstage/types'; | ||
import { Config as Config$1 } from '@backstage/config'; | ||
@@ -33,2 +34,21 @@ /** | ||
/** | ||
* Reads a duration from a config object. | ||
* | ||
* @public | ||
* @remarks | ||
* | ||
* This does not support optionality; if you want to support optional durations, | ||
* you need to first check the presence of the target with `config.has(...)` and | ||
* then call this function. | ||
* | ||
* @param config - A configuration object | ||
* @param key - If specified, read the duration from the given subkey | ||
* under the config object | ||
* @returns A duration object | ||
*/ | ||
declare function readDurationFromConfig(config: Config$1, options?: { | ||
key?: string; | ||
}): HumanDuration; | ||
/** | ||
* A serialized form of configuration data that carries additional context. | ||
@@ -215,2 +235,2 @@ * | ||
export { AppConfig, Config, ConfigReader, JsonArray, JsonObject, JsonPrimitive, JsonValue }; | ||
export { AppConfig, Config, ConfigReader, JsonArray, JsonObject, JsonPrimitive, JsonValue, readDurationFromConfig }; |
@@ -0,4 +1,61 @@ | ||
import { InputError } from '@backstage/errors'; | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
import mergeWith from 'lodash/mergeWith'; | ||
const propsOfHumanDuration = [ | ||
"years", | ||
"months", | ||
"weeks", | ||
"days", | ||
"hours", | ||
"minutes", | ||
"seconds", | ||
"milliseconds" | ||
]; | ||
function readDurationFromConfig(config, options) { | ||
let root; | ||
let found = false; | ||
const result = {}; | ||
try { | ||
root = (options == null ? void 0 : options.key) ? config.getConfig(options.key) : config; | ||
for (const prop of propsOfHumanDuration) { | ||
const value = root.getOptionalNumber(prop); | ||
if (value !== void 0) { | ||
result[prop] = value; | ||
found = true; | ||
} | ||
} | ||
} catch (error) { | ||
throw new InputError(`Failed to read duration from config, ${error}`); | ||
} | ||
try { | ||
if (!found) { | ||
const good = propsOfHumanDuration.map((p) => `'${p}'`).join(", "); | ||
throw new Error(`Needs one or more of ${good}`); | ||
} | ||
const invalidProps = root.keys().filter((prop) => !propsOfHumanDuration.includes(prop)); | ||
if (invalidProps.length) { | ||
const what = invalidProps.length === 1 ? "property" : "properties"; | ||
const bad = invalidProps.map((p) => `'${p}'`).join(", "); | ||
const good = propsOfHumanDuration.map((p) => `'${p}'`).join(", "); | ||
throw new Error( | ||
`Unknown ${what} ${bad}; expected one or more of ${good}` | ||
); | ||
} | ||
} catch (error) { | ||
let prefix = "Failed to read duration from config"; | ||
if (options == null ? void 0 : options.key) { | ||
prefix += ` at '${options.key}'`; | ||
} | ||
throw new InputError(`${prefix}, ${error}`); | ||
} | ||
return result; | ||
} | ||
var __defProp = Object.defineProperty; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __publicField = (obj, key, value) => { | ||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
return value; | ||
}; | ||
const CONFIG_KEY_PART_PATTERN = /^[a-z][a-z0-9]*(?:[-_][a-z][a-z0-9]*)*$/i; | ||
@@ -40,3 +97,11 @@ function isObject(value) { | ||
this.prefix = prefix; | ||
this.notifiedFilteredKeys = /* @__PURE__ */ new Set(); | ||
/** | ||
* A set of key paths that where removed from the config due to not being visible. | ||
* | ||
* This was added as a mutable private member to avoid changes to the public API. | ||
* Its only purpose of this is to warn users of missing visibility when running | ||
* the frontend in development mode. | ||
*/ | ||
__publicField(this, "filteredKeys"); | ||
__publicField(this, "notifiedFilteredKeys", /* @__PURE__ */ new Set()); | ||
} | ||
@@ -332,3 +397,3 @@ /** | ||
export { ConfigReader }; | ||
export { ConfigReader, readDurationFromConfig }; | ||
//# sourceMappingURL=index.esm.js.map |
{ | ||
"name": "@backstage/config", | ||
"description": "Config API used by Backstage core, backend, and CLI", | ||
"version": "0.0.0-nightly-20230620022155", | ||
"version": "0.0.0-nightly-20230830021355", | ||
"publishConfig": { | ||
@@ -35,8 +35,9 @@ "access": "public", | ||
"dependencies": { | ||
"@backstage/types": "^0.0.0-nightly-20230620022155", | ||
"@backstage/errors": "^1.2.1", | ||
"@backstage/types": "^1.1.0", | ||
"lodash": "^4.17.21" | ||
}, | ||
"devDependencies": { | ||
"@backstage/cli": "^0.0.0-nightly-20230620022155", | ||
"@backstage/test-utils": "^0.0.0-nightly-20230620022155", | ||
"@backstage/cli": "^0.0.0-nightly-20230830021355", | ||
"@backstage/test-utils": "^0.0.0-nightly-20230830021355", | ||
"@types/node": "^16.0.0" | ||
@@ -43,0 +44,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
105730
1023
3
+ Added@backstage/errors@^1.2.1
+ Added@backstage/errors@1.2.7(transitive)
+ Added@backstage/types@1.2.1(transitive)
+ Addedserialize-error@8.1.0(transitive)
+ Addedtype-fest@0.20.2(transitive)
- Removed@backstage/types@0.0.0-nightly-20250114022708(transitive)
Updated@backstage/types@^1.1.0