@backstage/config-loader
Advanced tools
Comparing version 0.0.0-nightly-20240730021827 to 0.0.0-nightly-20240731020649
# @backstage/config-loader | ||
## 0.0.0-nightly-20240730021827 | ||
## 0.0.0-nightly-20240731020649 | ||
### Minor Changes | ||
- 274428f: Add configuration key to File and Remote `ConfigSource`s that enables configuration of parsing logic. Previously limited to yaml, these `ConfigSource`s now allow for a multitude of parsing options (e.g. JSON). | ||
### Patch Changes | ||
@@ -17,2 +21,17 @@ | ||
## 1.9.0-next.1 | ||
### Minor Changes | ||
- 274428f: Add configuration key to File and Remote `ConfigSource`s that enables configuration of parsing logic. Previously limited to yaml, these `ConfigSource`s now allow for a multitude of parsing options (e.g. JSON). | ||
### Patch Changes | ||
- 1edd6c2: The `env` option of `ConfigSources.default` now correctly allows undefined members. | ||
- Updated dependencies | ||
- @backstage/cli-common@0.1.14 | ||
- @backstage/config@1.2.0 | ||
- @backstage/errors@1.2.4 | ||
- @backstage/types@1.1.1 | ||
## 1.8.2-next.0 | ||
@@ -19,0 +38,0 @@ |
@@ -840,2 +840,36 @@ 'use strict'; | ||
function simpleDefer() { | ||
let resolve; | ||
const promise = new Promise((_resolve) => { | ||
resolve = _resolve; | ||
}); | ||
return { promise, resolve }; | ||
} | ||
async function waitOrAbort(promise, signal) { | ||
const signals = [signal].flat().filter((x) => !!x); | ||
return new Promise((resolve, reject) => { | ||
if (signals.some((s) => s.aborted)) { | ||
resolve([false]); | ||
} | ||
const onAbort = () => { | ||
resolve([false]); | ||
}; | ||
promise.then( | ||
(value) => { | ||
resolve([true, value]); | ||
signals.forEach((s) => s.removeEventListener("abort", onAbort)); | ||
}, | ||
(error) => { | ||
reject(error); | ||
signals.forEach((s) => s.removeEventListener("abort", onAbort)); | ||
} | ||
); | ||
signals.forEach((s) => s.addEventListener("abort", onAbort)); | ||
}); | ||
} | ||
const parseYamlContent = async ({ contents }) => { | ||
const parsed = yaml__default.default.parse(contents); | ||
return { result: parsed === null ? void 0 : parsed }; | ||
}; | ||
async function readFile(path) { | ||
@@ -876,2 +910,3 @@ try { | ||
#watch; | ||
#parser; | ||
constructor(options) { | ||
@@ -881,2 +916,3 @@ this.#path = options.path; | ||
this.#watch = options.watch ?? true; | ||
this.#parser = options.parser ?? parseYamlContent; | ||
} | ||
@@ -922,8 +958,8 @@ // Work is duplicated across each read, in practice that should not | ||
} | ||
const content = await readFile(this.#path); | ||
if (content === void 0) { | ||
const contents = await readFile(this.#path); | ||
if (contents === void 0) { | ||
throw new errors.NotFoundError(`Config file "${this.#path}" does not exist`); | ||
} | ||
const parsed = yaml__default.default.parse(content); | ||
if (parsed === null) { | ||
const { result: parsed } = await this.#parser({ contents }); | ||
if (parsed === void 0) { | ||
return []; | ||
@@ -1068,2 +1104,3 @@ } | ||
#transformer; | ||
#parser; | ||
constructor(options) { | ||
@@ -1077,2 +1114,3 @@ this.#url = options.url; | ||
}); | ||
this.#parser = options.parser ?? parseYamlContent; | ||
} | ||
@@ -1110,7 +1148,9 @@ async *readConfigData(options) { | ||
} | ||
const content = await res.text(); | ||
const data = await this.#transformer(yaml__default.default.parse(content)); | ||
if (data === null) { | ||
const contents = await res.text(); | ||
const { result: rawData } = await this.#parser({ contents }); | ||
if (rawData === void 0) { | ||
throw new Error("configuration data is null"); | ||
} else if (typeof data !== "object") { | ||
} | ||
const data = await this.#transformer(rawData); | ||
if (typeof data !== "object") { | ||
throw new Error("configuration data is not an object"); | ||
@@ -1407,32 +1447,2 @@ } else if (Array.isArray(data)) { | ||
function simpleDefer() { | ||
let resolve; | ||
const promise = new Promise((_resolve) => { | ||
resolve = _resolve; | ||
}); | ||
return { promise, resolve }; | ||
} | ||
async function waitOrAbort(promise, signal) { | ||
const signals = [signal].flat().filter((x) => !!x); | ||
return new Promise((resolve, reject) => { | ||
if (signals.some((s) => s.aborted)) { | ||
resolve([false]); | ||
} | ||
const onAbort = () => { | ||
resolve([false]); | ||
}; | ||
promise.then( | ||
(value) => { | ||
resolve([true, value]); | ||
signals.forEach((s) => s.removeEventListener("abort", onAbort)); | ||
}, | ||
(error) => { | ||
reject(error); | ||
signals.forEach((s) => s.removeEventListener("abort", onAbort)); | ||
} | ||
); | ||
signals.forEach((s) => s.addEventListener("abort", onAbort)); | ||
}); | ||
} | ||
class MutableConfigSource { | ||
@@ -1439,0 +1449,0 @@ /** |
@@ -247,2 +247,16 @@ import { JSONSchema7 } from 'json-schema'; | ||
type SubstitutionFunc = (name: string) => Promise<string | undefined>; | ||
/** | ||
* A custom function to be used for parsing configuration content. | ||
* | ||
* @remarks | ||
* | ||
* The default parsing function will parse configuration content as yaml. | ||
* | ||
* @public | ||
*/ | ||
type Parser = ({ contents, }: { | ||
contents: string; | ||
}) => Promise<{ | ||
result?: JsonObject; | ||
}>; | ||
@@ -269,2 +283,6 @@ /** | ||
substitutionFunc?: SubstitutionFunc; | ||
/** | ||
* A content parsing function to transform string content to configuration values. | ||
*/ | ||
parser?: Parser; | ||
} | ||
@@ -527,2 +545,6 @@ /** | ||
substitutionFunc?: SubstitutionFunc; | ||
/** | ||
* A content parsing function to transform string content to configuration values. | ||
*/ | ||
parser?: Parser; | ||
} | ||
@@ -619,2 +641,2 @@ /** | ||
export { type AsyncConfigSourceGenerator, type BaseConfigSourcesOptions, type ClosableConfig, type ConfigSchema, type ConfigSchemaProcessingOptions, type ConfigSource, type ConfigSourceData, type ConfigSourceTarget, ConfigSources, type ConfigSourcesDefaultForTargetsOptions, type ConfigSourcesDefaultOptions, type ConfigTarget, type ConfigVisibility, EnvConfigSource, type EnvConfigSourceOptions, type SubstitutionFunc as EnvFunc, FileConfigSource, type FileConfigSourceOptions, type LoadConfigOptions, type LoadConfigOptionsRemote, type LoadConfigOptionsWatch, type LoadConfigResult, type LoadConfigSchemaOptions, MutableConfigSource, type MutableConfigSourceOptions, type ReadConfigDataOptions, RemoteConfigSource, type RemoteConfigSourceOptions, StaticConfigSource, type StaticConfigSourceOptions, type TransformFunc, loadConfig, loadConfigSchema, mergeConfigSchemas, readEnvConfig }; | ||
export { type AsyncConfigSourceGenerator, type BaseConfigSourcesOptions, type ClosableConfig, type ConfigSchema, type ConfigSchemaProcessingOptions, type ConfigSource, type ConfigSourceData, type ConfigSourceTarget, ConfigSources, type ConfigSourcesDefaultForTargetsOptions, type ConfigSourcesDefaultOptions, type ConfigTarget, type ConfigVisibility, EnvConfigSource, type EnvConfigSourceOptions, type SubstitutionFunc as EnvFunc, FileConfigSource, type FileConfigSourceOptions, type LoadConfigOptions, type LoadConfigOptionsRemote, type LoadConfigOptionsWatch, type LoadConfigResult, type LoadConfigSchemaOptions, MutableConfigSource, type MutableConfigSourceOptions, type Parser, type ReadConfigDataOptions, RemoteConfigSource, type RemoteConfigSourceOptions, StaticConfigSource, type StaticConfigSourceOptions, type TransformFunc, loadConfig, loadConfigSchema, mergeConfigSchemas, readEnvConfig }; |
{ | ||
"name": "@backstage/config-loader", | ||
"version": "0.0.0-nightly-20240730021827", | ||
"version": "0.0.0-nightly-20240731020649", | ||
"description": "Config loading functionality used by Backstage backend, and CLI", | ||
@@ -57,4 +57,4 @@ "backstage": { | ||
"devDependencies": { | ||
"@backstage/backend-test-utils": "^0.0.0-nightly-20240730021827", | ||
"@backstage/cli": "^0.0.0-nightly-20240730021827", | ||
"@backstage/backend-test-utils": "^0.0.0-nightly-20240731020649", | ||
"@backstage/cli": "^0.0.0-nightly-20240731020649", | ||
"@types/json-schema-merge-allof": "^0.6.0", | ||
@@ -61,0 +61,0 @@ "msw": "^1.0.0", |
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
255252
2258