openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
74 lines (73 loc) • 2.34 kB
JavaScript
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs";
import { f as normalizeStringEntries } from "./string-normalization-DLmfYZXI.mjs";
import { t as parseConfigPathArrayIndex } from "./path-array-index-qP-D1DoI.mjs";
import { t as appendConfigPathSegment } from "./dot-path-BJ4tyWKJ.mjs";
import "./utils-C8YECn2Q.mjs";
//#region src/plugins/config-contract-matches.ts
function normalizePathPattern(e) {
return normalizeStringEntries(e.split("."));
}
/** Match declared migration sources without widening a scoped config edit. */
function hasPluginConfigMigrationSource(e) {
return e.pathPatterns?.some((t) => {
const n = normalizePathPattern(t);
return (!e.touchedPaths || e.touchedPaths.some((e) => n.slice(0, e.length).every((t, n) => t === "*" || t === e[n]))) && collectPluginConfigContractMatches({
root: e.root,
pathPattern: t
}).length > 0;
}) ?? false;
}
function parseCanonicalArrayIndex(e, t) {
const n = parseConfigPathArrayIndex(e);
return n !== void 0 && n < t ? n : null;
}
/** Collect concrete config values that match a plugin contract path pattern. */
function collectPluginConfigContractMatches(e) {
const t = normalizePathPattern(e.pathPattern);
if (t.length === 0) return [];
let n = [{
segments: [],
value: e.root
}];
for (const e of t) {
const t = [];
for (const r of n) {
if (e === "*") {
if (Array.isArray(r.value) || isRecord(r.value)) {
const e = Array.isArray(r.value) ? r.value.entries() : Object.entries(r.value);
for (const [n, i] of e) t.push({
segments: [...r.segments, n],
value: i,
parent: r.value
});
}
continue;
}
if (Array.isArray(r.value)) {
const n = parseCanonicalArrayIndex(e, r.value.length);
if (n !== null) t.push({
segments: [...r.segments, n],
value: r.value[n],
parent: r.value
});
continue;
}
if (!isRecord(r.value) || !Object.hasOwn(r.value, e)) continue;
t.push({
segments: [...r.segments, e],
value: r.value[e],
parent: r.value
});
}
n = t;
if (n.length === 0) break;
}
return n.map((e) => ({
path: e.segments.reduce(appendConfigPathSegment, ""),
value: e.value,
parent: e.parent,
key: String(e.segments.at(-1))
}));
}
//#endregion
export { hasPluginConfigMigrationSource as n, collectPluginConfigContractMatches as t };