mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 23:20:43 +00:00
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { isDeepStrictEqual } from "node:util";
|
|
import { isPlainObject } from "../utils.js";
|
|
|
|
export function diffConfigPaths(prev: unknown, next: unknown, prefix = ""): string[] {
|
|
if (prev === next) {
|
|
return [];
|
|
}
|
|
if (isPlainObject(prev) && isPlainObject(next)) {
|
|
const keys = new Set([...Object.keys(prev), ...Object.keys(next)]);
|
|
const paths: string[] = [];
|
|
for (const key of keys) {
|
|
const prevValue = prev[key];
|
|
const nextValue = next[key];
|
|
if (prevValue === undefined && nextValue === undefined) {
|
|
continue;
|
|
}
|
|
const childPrefix = prefix ? `${prefix}.${key}` : key;
|
|
const childPaths = diffConfigPaths(prevValue, nextValue, childPrefix);
|
|
if (childPaths.length > 0) {
|
|
paths.push(...childPaths);
|
|
}
|
|
}
|
|
return paths;
|
|
}
|
|
if (Array.isArray(prev) && Array.isArray(next)) {
|
|
// Arrays can contain object entries (for example memory.qmd.paths/scope.rules);
|
|
// compare structurally so identical values are not reported as changed.
|
|
if (isDeepStrictEqual(prev, next)) {
|
|
return [];
|
|
}
|
|
}
|
|
return [prefix || "<root>"];
|
|
}
|