refactor(core): dedupe shared config and runtime helpers

This commit is contained in:
Peter Steinberger
2026-02-16 14:52:03 +00:00
parent 544ffbcf7b
commit 04892ee230
68 changed files with 1966 additions and 2018 deletions

View File

@@ -373,6 +373,18 @@ class RedactionError extends Error {
}
}
function restoreOriginalValueOrThrow(params: {
key: string;
path: string;
original: Record<string, unknown>;
}): unknown {
if (params.key in params.original) {
return params.original[params.key];
}
log.warn(`Cannot un-redact config key ${params.path} as it doesn't have any value`);
throw new RedactionError(params.path);
}
/**
* Worker for restoreRedactedValues().
* Used when there are ConfigUiHints available.
@@ -427,12 +439,7 @@ function restoreRedactedValuesWithLookup(
if (lookup.has(candidate)) {
matched = true;
if (value === REDACTED_SENTINEL) {
if (key in orig) {
result[key] = orig[key];
} else {
log.warn(`Cannot un-redact config key ${candidate} as it doesn't have any value`);
throw new RedactionError(candidate);
}
result[key] = restoreOriginalValueOrThrow({ key, path: candidate, original: orig });
} else if (typeof value === "object" && value !== null) {
result[key] = restoreRedactedValuesWithLookup(value, orig[key], lookup, candidate, hints);
}
@@ -442,12 +449,7 @@ function restoreRedactedValuesWithLookup(
if (!matched && isExtensionPath(path)) {
const markedNonSensitive = isExplicitlyNonSensitivePath(hints, [path, wildcardPath]);
if (!markedNonSensitive && isSensitivePath(path) && value === REDACTED_SENTINEL) {
if (key in orig) {
result[key] = orig[key];
} else {
log.warn(`Cannot un-redact config key ${path} as it doesn't have any value`);
throw new RedactionError(path);
}
result[key] = restoreOriginalValueOrThrow({ key, path, original: orig });
} else if (typeof value === "object" && value !== null) {
result[key] = restoreRedactedValuesGuessing(value, orig[key], path, hints);
}
@@ -506,12 +508,7 @@ function restoreRedactedValuesGuessing(
isSensitivePath(path) &&
value === REDACTED_SENTINEL
) {
if (key in orig) {
result[key] = orig[key];
} else {
log.warn(`Cannot un-redact config key ${path} as it doesn't have any value`);
throw new RedactionError(path);
}
result[key] = restoreOriginalValueOrThrow({ key, path, original: orig });
} else if (typeof value === "object" && value !== null) {
result[key] = restoreRedactedValuesGuessing(value, orig[key], path, hints);
} else {