Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@backstage/config-loader

Package Overview
Dependencies
Maintainers
3
Versions
864
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@backstage/config-loader - npm Package Compare versions

Comparing version 0.0.0-nightly-20240416021242 to 0.0.0-nightly-20240607021723

12

CHANGELOG.md
# @backstage/config-loader
## 0.0.0-nightly-20240416021242
## 0.0.0-nightly-20240607021723
### Patch Changes
- Updated dependencies
- @backstage/cli-common@0.0.0-nightly-20240607021723
- @backstage/config@1.2.0
- @backstage/errors@1.2.4
- @backstage/types@1.1.1
## 1.8.0
### Minor Changes

@@ -6,0 +16,0 @@

516

dist/index.cjs.js

@@ -58,3 +58,3 @@ 'use strict';

return (_data, context) => {
if ((context == null ? void 0 : context.instancePath) === void 0) {
if (context?.instancePath === void 0) {
return false;

@@ -84,3 +84,3 @@ }

return (_data, context) => {
if ((context == null ? void 0 : context.instancePath) === void 0) {
if (context?.instancePath === void 0) {
return false;

@@ -100,3 +100,3 @@ }

return (_data, context) => {
if ((context == null ? void 0 : context.instancePath) === void 0) {
if (context?.instancePath === void 0) {
return false;

@@ -121,4 +121,3 @@ }

(schema, jsonPtr, _1, _2, _3, parentSchema) => {
var _a, _b;
(_b = schema[inheritedVisibility]) != null ? _b : schema[inheritedVisibility] = (_a = schema == null ? void 0 : schema.deepVisibility) != null ? _a : parentSchema == null ? void 0 : parentSchema[inheritedVisibility];
schema[inheritedVisibility] ??= schema?.deepVisibility ?? parentSchema?.[inheritedVisibility];
if (schema[inheritedVisibility]) {

@@ -128,3 +127,3 @@ const values = [

schema[inheritedVisibility],
parentSchema == null ? void 0 : parentSchema[inheritedVisibility]
parentSchema?.[inheritedVisibility]
];

@@ -139,5 +138,5 @@ const hasFrontend = values.some((e) => e === "frontend");

}
if (options == null ? void 0 : options.noUndeclaredProperties) {
if ((schema == null ? void 0 : schema.type) === "object") {
schema.additionalProperties || (schema.additionalProperties = false);
if (options?.noUndeclaredProperties) {
if (schema?.type === "object") {
schema.additionalProperties ||= false;
}

@@ -158,3 +157,2 @@ }

return (configs) => {
var _a;
const config$1 = config.ConfigReader.fromConfigs(configs).getOptional();

@@ -166,3 +164,3 @@ visibilityByDataPath.clear();

return {
errors: (_a = validate.errors) != null ? _a : [],
errors: validate.errors ?? [],
visibilityByDataPath: new Map(visibilityByDataPath),

@@ -222,3 +220,2 @@ deepVisibilityByDataPath: new Map(deepVisibilityByDataPath),

async function processItem(item) {
var _a, _b, _c, _d;
let pkgPath = item.packagePath;

@@ -247,3 +244,3 @@ if (pkgPath) {

let versions = visitedPackageVersions.get(pkg.name);
if (versions == null ? void 0 : versions.has(pkg.version)) {
if (versions?.has(pkg.version)) {
return;

@@ -257,6 +254,6 @@ }

const depNames = [
...Object.keys((_a = pkg.dependencies) != null ? _a : {}),
...Object.keys((_b = pkg.devDependencies) != null ? _b : {}),
...Object.keys((_c = pkg.optionalDependencies) != null ? _c : {}),
...Object.keys((_d = pkg.peerDependencies) != null ? _d : {})
...Object.keys(pkg.dependencies ?? {}),
...Object.keys(pkg.devDependencies ?? {}),
...Object.keys(pkg.optionalDependencies ?? {}),
...Object.keys(pkg.peerDependencies ?? {})
];

@@ -333,3 +330,2 @@ const hasSchema = "configSchema" in pkg;

const tsSchemas = paths.map((path$1) => {
var _a;
let value;

@@ -347,4 +343,4 @@ try {

);
value = generator == null ? void 0 : generator.getSchemaForSymbol("Config");
const userSymbols = new Set(generator == null ? void 0 : generator.getUserSymbols());
value = generator?.getSchemaForSymbol("Config");
const userSymbols = new Set(generator?.getUserSymbols());
userSymbols.delete("Config");

@@ -357,3 +353,3 @@ if (userSymbols.size !== 0) {

}
const reffedDefs = Object.keys((_a = generator == null ? void 0 : generator.ReffedDefinitions) != null ? _a : {});
const reffedDefs = Object.keys(generator?.ReffedDefinitions ?? {});
if (reffedDefs.length !== 0) {

@@ -380,10 +376,8 @@ const lines = reffedDefs.join(`${os.EOL} `);

function filterByVisibility(data, includeVisibilities, visibilityByDataPath, deepVisibilityByDataPath, deprecationByDataPath, transformFunc, withFilteredKeys, withDeprecatedKeys) {
var _a;
const filteredKeys = new Array();
const deprecatedKeys = new Array();
function transform(jsonVal, visibilityPath, filterPath, inheritedVisibility) {
var _a2, _b;
const visibility = (_a2 = visibilityByDataPath.get(visibilityPath)) != null ? _a2 : inheritedVisibility;
const visibility = visibilityByDataPath.get(visibilityPath) ?? inheritedVisibility;
const isVisible = includeVisibilities.includes(visibility);
const newInheritedVisibility = (_b = deepVisibilityByDataPath.get(visibilityPath)) != null ? _b : inheritedVisibility;
const newInheritedVisibility = deepVisibilityByDataPath.get(visibilityPath) ?? inheritedVisibility;
const deprecation = deprecationByDataPath.get(visibilityPath);

@@ -456,3 +450,3 @@ if (deprecation) {

deprecatedKeys: withDeprecatedKeys ? deprecatedKeys : void 0,
data: (_a = transform(data, "", "", DEFAULT_CONFIG_VISIBILITY)) != null ? _a : {}
data: transform(data, "", "", DEFAULT_CONFIG_VISIBILITY) ?? {}
};

@@ -469,3 +463,2 @@ }

return errors.filter((error) => {
var _a;
if (error.keyword === "type" && ["object", "array"].includes(error.params.type)) {

@@ -484,3 +477,3 @@ return true;

}
const vis = (_a = visibilityByDataPath.get(normalizeAjvPath(error.instancePath))) != null ? _a : DEFAULT_CONFIG_VISIBILITY;
const vis = visibilityByDataPath.get(normalizeAjvPath(error.instancePath)) ?? DEFAULT_CONFIG_VISIBILITY;
return vis && includeVisibilities.includes(vis);

@@ -502,3 +495,2 @@ });

async function loadConfigSchema(options) {
var _a;
let schemas;

@@ -508,7 +500,7 @@ if ("dependencies" in options) {

options.dependencies,
(_a = options.packagePaths) != null ? _a : []
options.packagePaths ?? []
);
} else {
const { serialized } = options;
if ((serialized == null ? void 0 : serialized.backstageConfigSchemaVersion) !== 1) {
if (serialized?.backstageConfigSchemaVersion !== 1) {
throw new Error(

@@ -595,4 +587,3 @@ "Serialized configuration schema is invalid or has an invalid version number"

static create(options) {
var _a;
return new EnvConfigSource((_a = options == null ? void 0 : options.env) != null ? _a : process.env);
return new EnvConfigSource(options?.env ?? process.env);
}

@@ -614,3 +605,2 @@ async *readConfigData() {

function readEnvConfig(env) {
var _a;
let data = void 0;

@@ -624,3 +614,3 @@ for (const [name, value] of Object.entries(env)) {

const keyParts = key.split("_");
let obj = data = data != null ? data : {};
let obj = data = data ?? {};
for (const [index, part] of keyParts.entries()) {

@@ -631,3 +621,3 @@ if (!CONFIG_KEY_PART_PATTERN.test(part)) {

if (index < keyParts.length - 1) {
obj = obj[part] = (_a = obj[part]) != null ? _a : {};
obj = obj[part] = obj[part] ?? {};
if (typeof obj !== "object" || Array.isArray(obj)) {

@@ -807,3 +797,2 @@ const subKey = keyParts.slice(0, index + 1).join("_");

async function transform(inputObj, path, baseDir) {
var _a;
let obj = inputObj;

@@ -819,3 +808,3 @@ let dir = baseDir;

obj = result.value;
dir = (_a = result == null ? void 0 : result.newDir) != null ? _a : dir;
dir = result?.newDir ?? dir;
break;

@@ -853,3 +842,3 @@ }

}
const finalData = await transform(input, "", context == null ? void 0 : context.dir);
const finalData = await transform(input, "", context?.dir);
if (!isObject(finalData)) {

@@ -862,6 +851,3 @@ throw new TypeError("expected object at config root");

const {
substitutionFunc = async (name) => {
var _a;
return (_a = process.env[name]) == null ? void 0 : _a.trim();
},
substitutionFunc = async (name) => process.env[name]?.trim(),
readFile

@@ -879,28 +865,5 @@ } = options;

}
return async (input, ctx) => applyConfigTransforms(input, ctx != null ? ctx : {}, transforms);
return async (input, ctx) => applyConfigTransforms(input, ctx ?? {}, transforms);
}
var __accessCheck$3 = (obj, member, msg) => {
if (!member.has(obj))
throw TypeError("Cannot " + msg);
};
var __privateGet$2 = (obj, member, getter) => {
__accessCheck$3(obj, member, "read from private field");
return getter ? getter.call(obj) : member.get(obj);
};
var __privateAdd$3 = (obj, member, value) => {
if (member.has(obj))
throw TypeError("Cannot add the same private member more than once");
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
};
var __privateSet$2 = (obj, member, value, setter) => {
__accessCheck$3(obj, member, "write to private field");
setter ? setter.call(obj, value) : member.set(obj, value);
return value;
};
var __privateMethod$2 = (obj, member, method) => {
__accessCheck$3(obj, member, "access private method");
return method;
};
var _path, _substitutionFunc, _watch, _waitForEvent, waitForEvent_fn;
async function readFile(path) {

@@ -921,13 +884,3 @@ try {

}
const _FileConfigSource = class _FileConfigSource {
constructor(options) {
__privateAdd$3(this, _waitForEvent);
__privateAdd$3(this, _path, void 0);
__privateAdd$3(this, _substitutionFunc, void 0);
__privateAdd$3(this, _watch, void 0);
var _a;
__privateSet$2(this, _path, options.path);
__privateSet$2(this, _substitutionFunc, options.substitutionFunc);
__privateSet$2(this, _watch, (_a = options.watch) != null ? _a : true);
}
class FileConfigSource {
/**

@@ -947,4 +900,12 @@ * Creates a new config source that loads configuration from the given path.

}
return new _FileConfigSource(options);
return new FileConfigSource(options);
}
#path;
#substitutionFunc;
#watch;
constructor(options) {
this.#path = options.path;
this.#substitutionFunc = options.substitutionFunc;
this.#watch = options.watch ?? true;
}
// Work is duplicated across each read, in practice that should not

@@ -954,15 +915,15 @@ // have any impact since there won't be multiple consumers. If that

async *readConfigData(options) {
const signal = options == null ? void 0 : options.signal;
const configFileName = path.basename(__privateGet$2(this, _path));
const signal = options?.signal;
const configFileName = path.basename(this.#path);
let watchedPaths = null;
let watcher = null;
if (__privateGet$2(this, _watch)) {
if (this.#watch) {
watchedPaths = new Array();
watcher = chokidar__default.default.watch(__privateGet$2(this, _path), {
watcher = chokidar__default.default.watch(this.#path, {
usePolling: process.env.NODE_ENV === "test"
});
}
const dir = path.dirname(__privateGet$2(this, _path));
const dir = path.dirname(this.#path);
const transformer = createConfigTransformer({
substitutionFunc: __privateGet$2(this, _substitutionFunc),
substitutionFunc: this.#substitutionFunc,
readFile: async (path$1) => {

@@ -987,8 +948,8 @@ const fullPath = path.resolve(dir, path$1);

watchedPaths.length = 0;
watcher.add(__privateGet$2(this, _path));
watchedPaths.push(__privateGet$2(this, _path));
watcher.add(this.#path);
watchedPaths.push(this.#path);
}
const content = await readFile(__privateGet$2(this, _path));
const content = await readFile(this.#path);
if (content === void 0) {
throw new errors.NotFoundError(`Config file "${__privateGet$2(this, _path)}" does not exist`);
throw new errors.NotFoundError(`Config file "${this.#path}" does not exist`);
}

@@ -1001,6 +962,6 @@ const parsed = yaml__default.default.parse(content);

const data = await transformer(parsed, { dir });
return [{ data, context: configFileName, path: __privateGet$2(this, _path) }];
return [{ data, context: configFileName, path: this.#path }];
} catch (error) {
throw new Error(
`Failed to read config file at "${__privateGet$2(this, _path)}", ${error.message}`
`Failed to read config file at "${this.#path}", ${error.message}`
);

@@ -1010,11 +971,11 @@ }

const onAbort = () => {
signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
signal?.removeEventListener("abort", onAbort);
if (watcher)
watcher.close();
};
signal == null ? void 0 : signal.addEventListener("abort", onAbort);
signal?.addEventListener("abort", onAbort);
yield { configs: await readConfigFile() };
if (watcher) {
for (; ; ) {
const event = await __privateMethod$2(this, _waitForEvent, waitForEvent_fn).call(this, watcher, signal);
const event = await this.#waitForEvent(watcher, signal);
if (event === "abort") {

@@ -1028,61 +989,47 @@ return;

toString() {
return `FileConfigSource{path="${__privateGet$2(this, _path)}"}`;
return `FileConfigSource{path="${this.#path}"}`;
}
};
_path = new WeakMap();
_substitutionFunc = new WeakMap();
_watch = new WeakMap();
_waitForEvent = new WeakSet();
waitForEvent_fn = function(watcher, signal) {
return new Promise((resolve) => {
function onChange() {
resolve("change");
onDone();
}
function onAbort() {
resolve("abort");
onDone();
}
function onDone() {
watcher.removeListener("change", onChange);
signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
}
watcher.addListener("change", onChange);
signal == null ? void 0 : signal.addEventListener("abort", onAbort);
});
};
let FileConfigSource = _FileConfigSource;
#waitForEvent(watcher, signal) {
return new Promise((resolve) => {
function onChange() {
resolve("change");
onDone();
}
function onAbort() {
resolve("abort");
onDone();
}
function onDone() {
watcher.removeListener("change", onChange);
signal?.removeEventListener("abort", onAbort);
}
watcher.addListener("change", onChange);
signal?.addEventListener("abort", onAbort);
});
}
}
var __defProp$1 = Object.defineProperty;
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField$1 = (obj, key, value) => {
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
var __accessCheck$2 = (obj, member, msg) => {
if (!member.has(obj))
throw TypeError("Cannot " + msg);
};
var __privateAdd$2 = (obj, member, value) => {
if (member.has(obj))
throw TypeError("Cannot add the same private member more than once");
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
};
var __privateMethod$1 = (obj, member, method) => {
__accessCheck$2(obj, member, "access private method");
return method;
};
var _flattenSources, flattenSources_fn, _a;
const sourcesSymbol = Symbol.for(
"@backstage/config-loader#MergedConfigSource.sources"
);
const _MergedConfigSource = class _MergedConfigSource {
class MergedConfigSource {
constructor(sources) {
this.sources = sources;
__publicField$1(this, _a);
this[sourcesSymbol] = this.sources;
}
// An optimization to flatten nested merged sources to avid unnecessary microtasks
static #flattenSources(sources) {
return sources.flatMap((source) => {
if (sourcesSymbol in source && Array.isArray(source[sourcesSymbol])) {
return this.#flattenSources(
source[sourcesSymbol]
);
}
return source;
});
}
static from(sources) {
return new _MergedConfigSource(__privateMethod$1(this, _flattenSources, flattenSources_fn).call(this, sources));
return new MergedConfigSource(this.#flattenSources(sources));
}
[sourcesSymbol];
async *readConfigData(options) {

@@ -1123,16 +1070,3 @@ const its = this.sources.map((source) => source.readConfigData(options));

}
};
_a = sourcesSymbol;
_flattenSources = new WeakSet();
flattenSources_fn = function(sources) {
return sources.flatMap((source) => {
if (sourcesSymbol in source && Array.isArray(source[sourcesSymbol])) {
return __privateMethod$1(this, _flattenSources, flattenSources_fn).call(this, source[sourcesSymbol]);
}
return source;
});
};
// An optimization to flatten nested merged sources to avid unnecessary microtasks
__privateAdd$2(_MergedConfigSource, _flattenSources);
let MergedConfigSource = _MergedConfigSource;
}
function nextWithIndex(iterator, index) {

@@ -1147,42 +1081,4 @@ return iterator.next().then(

var __accessCheck$1 = (obj, member, msg) => {
if (!member.has(obj))
throw TypeError("Cannot " + msg);
};
var __privateGet$1 = (obj, member, getter) => {
__accessCheck$1(obj, member, "read from private field");
return getter ? getter.call(obj) : member.get(obj);
};
var __privateAdd$1 = (obj, member, value) => {
if (member.has(obj))
throw TypeError("Cannot add the same private member more than once");
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
};
var __privateSet$1 = (obj, member, value, setter) => {
__accessCheck$1(obj, member, "write to private field");
setter ? setter.call(obj, value) : member.set(obj, value);
return value;
};
var __privateMethod = (obj, member, method) => {
__accessCheck$1(obj, member, "access private method");
return method;
};
var _url, _reloadIntervalMs, _transformer, _load, load_fn, _wait, wait_fn;
const DEFAULT_RELOAD_INTERVAL = { seconds: 60 };
const _RemoteConfigSource = class _RemoteConfigSource {
constructor(options) {
__privateAdd$1(this, _load);
__privateAdd$1(this, _wait);
__privateAdd$1(this, _url, void 0);
__privateAdd$1(this, _reloadIntervalMs, void 0);
__privateAdd$1(this, _transformer, void 0);
var _a;
__privateSet$1(this, _url, options.url);
__privateSet$1(this, _reloadIntervalMs, types.durationToMilliseconds(
(_a = options.reloadInterval) != null ? _a : DEFAULT_RELOAD_INTERVAL
));
__privateSet$1(this, _transformer, createConfigTransformer({
substitutionFunc: options.substitutionFunc
}));
}
class RemoteConfigSource {
/**

@@ -1202,22 +1098,33 @@ * Creates a new {@link RemoteConfigSource}.

}
return new _RemoteConfigSource(options);
return new RemoteConfigSource(options);
}
#url;
#reloadIntervalMs;
#transformer;
constructor(options) {
this.#url = options.url;
this.#reloadIntervalMs = types.durationToMilliseconds(
options.reloadInterval ?? DEFAULT_RELOAD_INTERVAL
);
this.#transformer = createConfigTransformer({
substitutionFunc: options.substitutionFunc
});
}
async *readConfigData(options) {
var _a;
let data = await __privateMethod(this, _load, load_fn).call(this);
yield { configs: [{ data, context: __privateGet$1(this, _url) }] };
let data = await this.#load();
yield { configs: [{ data, context: this.#url }] };
for (; ; ) {
await __privateMethod(this, _wait, wait_fn).call(this, options == null ? void 0 : options.signal);
if ((_a = options == null ? void 0 : options.signal) == null ? void 0 : _a.aborted) {
await this.#wait(options?.signal);
if (options?.signal?.aborted) {
return;
}
try {
const newData = await __privateMethod(this, _load, load_fn).call(this, options == null ? void 0 : options.signal);
const newData = await this.#load(options?.signal);
if (newData && !isEqual__default.default(data, newData)) {
data = newData;
yield { configs: [{ data, context: __privateGet$1(this, _url) }] };
yield { configs: [{ data, context: this.#url }] };
}
} catch (error) {
if (error.name !== "AbortError") {
console.error(`Failed to read config from ${__privateGet$1(this, _url)}, ${error}`);
console.error(`Failed to read config from ${this.#url}, ${error}`);
}

@@ -1228,49 +1135,37 @@ }

toString() {
return `RemoteConfigSource{path="${__privateGet$1(this, _url)}"}`;
return `RemoteConfigSource{path="${this.#url}"}`;
}
};
_url = new WeakMap();
_reloadIntervalMs = new WeakMap();
_transformer = new WeakMap();
_load = new WeakSet();
load_fn = async function(signal) {
const res = await fetch__default.default(__privateGet$1(this, _url), {
signal
});
if (!res.ok) {
throw await errors.ResponseError.fromResponse(res);
async #load(signal) {
const res = await fetch__default.default(this.#url, {
signal
});
if (!res.ok) {
throw await errors.ResponseError.fromResponse(res);
}
const content = await res.text();
const data = await this.#transformer(yaml__default.default.parse(content));
if (data === null) {
throw new Error("configuration data is null");
} else if (typeof data !== "object") {
throw new Error("configuration data is not an object");
} else if (Array.isArray(data)) {
throw new Error(
"configuration data is an array, expected an object instead"
);
}
return data;
}
const content = await res.text();
const data = await __privateGet$1(this, _transformer).call(this, yaml__default.default.parse(content));
if (data === null) {
throw new Error("configuration data is null");
} else if (typeof data !== "object") {
throw new Error("configuration data is not an object");
} else if (Array.isArray(data)) {
throw new Error(
"configuration data is an array, expected an object instead"
);
async #wait(signal) {
return new Promise((resolve) => {
const timeoutId = setTimeout(onDone, this.#reloadIntervalMs);
signal?.addEventListener("abort", onDone);
function onDone() {
clearTimeout(timeoutId);
signal?.removeEventListener("abort", onDone);
resolve();
}
});
}
return data;
};
_wait = new WeakSet();
wait_fn = async function(signal) {
return new Promise((resolve) => {
const timeoutId = setTimeout(onDone, __privateGet$1(this, _reloadIntervalMs));
signal == null ? void 0 : signal.addEventListener("abort", onDone);
function onDone() {
clearTimeout(timeoutId);
signal == null ? void 0 : signal.removeEventListener("abort", onDone);
resolve();
}
});
};
let RemoteConfigSource = _RemoteConfigSource;
}
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;
};
class ObservableConfigProxy {

@@ -1281,4 +1176,2 @@ constructor(parent, parentKey, abortController) {

this.abortController = abortController;
__publicField(this, "config", new config.ConfigReader({}));
__publicField(this, "subscribers", []);
if (parent && !parentKey) {

@@ -1288,2 +1181,4 @@ throw new Error("parentKey is required if parent is set");

}
config = new config.ConfigReader({});
subscribers = [];
static create(abortController) {

@@ -1329,3 +1224,2 @@ return new ObservableConfigProxy(void 0, void 0, abortController);

select(required) {
var _a;
if (this.parent && this.parentKey) {

@@ -1335,3 +1229,3 @@ if (required) {

}
return (_a = this.parent.select(false)) == null ? void 0 : _a.getOptionalConfig(this.parentKey);
return this.parent.select(false)?.getOptionalConfig(this.parentKey);
}

@@ -1341,8 +1235,6 @@ return this.config;

has(key) {
var _a, _b;
return (_b = (_a = this.select(false)) == null ? void 0 : _a.has(key)) != null ? _b : false;
return this.select(false)?.has(key) ?? false;
}
keys() {
var _a, _b;
return (_b = (_a = this.select(false)) == null ? void 0 : _a.keys()) != null ? _b : [];
return this.select(false)?.keys() ?? [];
}

@@ -1353,4 +1245,3 @@ get(key) {

getOptional(key) {
var _a;
return (_a = this.select(false)) == null ? void 0 : _a.getOptional(key);
return this.select(false)?.getOptional(key);
}

@@ -1361,4 +1252,3 @@ getConfig(key) {

getOptionalConfig(key) {
var _a;
if ((_a = this.select(false)) == null ? void 0 : _a.has(key)) {
if (this.select(false)?.has(key)) {
return new ObservableConfigProxy(this, key);

@@ -1372,4 +1262,3 @@ }

getOptionalConfigArray(key) {
var _a;
return (_a = this.select(false)) == null ? void 0 : _a.getOptionalConfigArray(key);
return this.select(false)?.getOptionalConfigArray(key);
}

@@ -1380,4 +1269,3 @@ getNumber(key) {

getOptionalNumber(key) {
var _a;
return (_a = this.select(false)) == null ? void 0 : _a.getOptionalNumber(key);
return this.select(false)?.getOptionalNumber(key);
}

@@ -1388,4 +1276,3 @@ getBoolean(key) {

getOptionalBoolean(key) {
var _a;
return (_a = this.select(false)) == null ? void 0 : _a.getOptionalBoolean(key);
return this.select(false)?.getOptionalBoolean(key);
}

@@ -1396,4 +1283,3 @@ getString(key) {

getOptionalString(key) {
var _a;
return (_a = this.select(false)) == null ? void 0 : _a.getOptionalString(key);
return this.select(false)?.getOptionalString(key);
}

@@ -1404,4 +1290,3 @@ getStringArray(key) {

getOptionalStringArray(key) {
var _a;
return (_a = this.select(false)) == null ? void 0 : _a.getOptionalStringArray(key);
return this.select(false)?.getOptionalStringArray(key);
}

@@ -1447,4 +1332,3 @@ }

static defaultForTargets(options) {
var _a;
const rootDir = (_a = options.rootDir) != null ? _a : cliCommon.findPaths(process.cwd()).targetRoot;
const rootDir = options.rootDir ?? cliCommon.findPaths(process.cwd()).targetRoot;
const argSources = options.targets.map((arg) => {

@@ -1597,31 +1481,3 @@ if (arg.type === "url") {

var __accessCheck = (obj, member, msg) => {
if (!member.has(obj))
throw TypeError("Cannot " + msg);
};
var __privateGet = (obj, member, getter) => {
__accessCheck(obj, member, "read from private field");
return getter ? getter.call(obj) : member.get(obj);
};
var __privateAdd = (obj, member, value) => {
if (member.has(obj))
throw TypeError("Cannot add the same private member more than once");
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
};
var __privateSet = (obj, member, value, setter) => {
__accessCheck(obj, member, "write to private field");
setter ? setter.call(obj, value) : member.set(obj, value);
return value;
};
var _currentData, _deferred, _context, _abortController;
const _MutableConfigSource = class _MutableConfigSource {
constructor(context, initialData) {
__privateAdd(this, _currentData, void 0);
__privateAdd(this, _deferred, void 0);
__privateAdd(this, _context, void 0);
__privateAdd(this, _abortController, new AbortController());
__privateSet(this, _currentData, initialData);
__privateSet(this, _context, context);
__privateSet(this, _deferred, simpleDefer());
}
class MutableConfigSource {
/**

@@ -1634,17 +1490,25 @@ * Creates a new mutable config source.

static create(options) {
var _a;
return new _MutableConfigSource(
(_a = options == null ? void 0 : options.context) != null ? _a : "mutable-config",
options == null ? void 0 : options.data
return new MutableConfigSource(
options?.context ?? "mutable-config",
options?.data
);
}
#currentData;
#deferred;
#context;
#abortController = new AbortController();
constructor(context, initialData) {
this.#currentData = initialData;
this.#context = context;
this.#deferred = simpleDefer();
}
async *readConfigData(options) {
let deferredPromise = __privateGet(this, _deferred).promise;
if (__privateGet(this, _currentData) !== void 0) {
yield { configs: [{ data: __privateGet(this, _currentData), context: __privateGet(this, _context) }] };
let deferredPromise = this.#deferred.promise;
if (this.#currentData !== void 0) {
yield { configs: [{ data: this.#currentData, context: this.#context }] };
}
for (; ; ) {
const [ok] = await waitOrAbort(deferredPromise, [
options == null ? void 0 : options.signal,
__privateGet(this, _abortController).signal
options?.signal,
this.#abortController.signal
]);

@@ -1654,6 +1518,6 @@ if (!ok) {

}
deferredPromise = __privateGet(this, _deferred).promise;
if (__privateGet(this, _currentData) !== void 0) {
deferredPromise = this.#deferred.promise;
if (this.#currentData !== void 0) {
yield {
configs: [{ data: __privateGet(this, _currentData), context: __privateGet(this, _context) }]
configs: [{ data: this.#currentData, context: this.#context }]
};

@@ -1669,6 +1533,6 @@ }

setData(data) {
if (!__privateGet(this, _abortController).signal.aborted) {
__privateSet(this, _currentData, data);
const oldDeferred = __privateGet(this, _deferred);
__privateSet(this, _deferred, simpleDefer());
if (!this.#abortController.signal.aborted) {
this.#currentData = data;
const oldDeferred = this.#deferred;
this.#deferred = simpleDefer();
oldDeferred.resolve();

@@ -1681,4 +1545,4 @@ }

close() {
__privateSet(this, _currentData, void 0);
__privateGet(this, _abortController).abort();
this.#currentData = void 0;
this.#abortController.abort();
}

@@ -1688,8 +1552,3 @@ toString() {

}
};
_currentData = new WeakMap();
_deferred = new WeakMap();
_context = new WeakMap();
_abortController = new WeakMap();
let MutableConfigSource = _MutableConfigSource;
}

@@ -1714,3 +1573,3 @@ class StaticObservableConfigSource {

});
const signal = options == null ? void 0 : options.signal;
const signal = options?.signal;
if (signal) {

@@ -1801,7 +1660,6 @@ const onAbort = () => {

async function loadConfigReaderLoop() {
var _a, _b, _c, _d;
let loaded = false;
try {
const abortController = new AbortController();
(_b = (_a = options.watch) == null ? void 0 : _a.stopSignal) == null ? void 0 : _b.then(() => abortController.abort());
options.watch?.stopSignal?.then(() => abortController.abort());
for await (const { configs } of source.readConfigData({

@@ -1811,3 +1669,3 @@ signal: abortController.signal

if (loaded) {
(_c = options.watch) == null ? void 0 : _c.onChange(configs);
options.watch?.onChange(configs);
} else {

@@ -1817,3 +1675,3 @@ resolve({ appConfigs: configs });

if (options.watch) {
(_d = options.watch.stopSignal) == null ? void 0 : _d.then(() => abortController.abort());
options.watch.stopSignal?.then(() => abortController.abort());
} else {

@@ -1820,0 +1678,0 @@ abortController.abort();

{
"name": "@backstage/config-loader",
"version": "0.0.0-nightly-20240416021242",
"version": "0.0.0-nightly-20240607021723",
"description": "Config loading functionality used by Backstage backend, and CLI",

@@ -39,3 +39,3 @@ "backstage": {

"dependencies": {
"@backstage/cli-common": "^0.1.13",
"@backstage/cli-common": "^0.0.0-nightly-20240607021723",
"@backstage/config": "^1.2.0",

@@ -58,4 +58,4 @@ "@backstage/errors": "^1.2.4",

"devDependencies": {
"@backstage/backend-test-utils": "^0.0.0-nightly-20240416021242",
"@backstage/cli": "^0.0.0-nightly-20240416021242",
"@backstage/backend-test-utils": "^0.0.0-nightly-20240607021723",
"@backstage/cli": "^0.0.0-nightly-20240607021723",
"@types/json-schema-merge-allof": "^0.6.0",

@@ -62,0 +62,0 @@ "msw": "^1.0.0",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc