openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.71 kB
JavaScript
import"./src-0ci69Prg.mjs";import{t as expectDefined}from"./expect-DkJCbmLj.mjs";import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{t as isBlockedObjectKey}from"./prototype-keys-Dc7Yq32J.mjs";import{t as parseConfigPathArrayIndex}from"./path-array-index-DO9QgC44.mjs";import{isDeepStrictEqual}from"node:util";
//!src/config/config-path-mutation.ts
const MANAGED_CONFIG_UNSET_PATHS=[[`plugins`,`installs`]];const WRITE_PRUNED_OBJECT=Symbol(`write-pruned-object`);function unsetPathForWriteAt(e,t,n){if(n>=t.length)return e;const r=expectDefined(t[n],`path segments entry at depth`);const i=n===t.length-1;if(Array.isArray(e)){const a=parseConfigPathArrayIndex(r);if(a===void 0||a>=e.length)return e;const o=i?WRITE_PRUNED_OBJECT:unsetPathForWriteAt(e[a],t,n+1);if(Object.is(o,e[a]))return e;const s=e.slice();if(o===WRITE_PRUNED_OBJECT)s.splice(a,1);else s[a]=o;return s}if(isBlockedObjectKey(r)||!isRecord(e)||!Object.hasOwn(e,r))return e;const a=i?WRITE_PRUNED_OBJECT:unsetPathForWriteAt(e[r],t,n+1);if(Object.is(a,e[r]))return e;const o={...e};if(a===WRITE_PRUNED_OBJECT)delete o[r];else o[r]=a;return Object.keys(o).length===0?WRITE_PRUNED_OBJECT:o}function applyUnsetPathsForWrite(e,t){let n=e;for(const e of t??[]){if(!Array.isArray(e)||e.length===0)continue;const t=unsetPathForWriteAt(n,e,0);if(t===WRITE_PRUNED_OBJECT)n={};else if(isRecord(t))n=t}return n}function resolveManagedUnsetPathsForWrite(e){const t=[];for(const e of MANAGED_CONFIG_UNSET_PATHS)t.push(Array.from(e));for(const n of e??[]){if(!Array.isArray(n)||n.length===0)continue;if(t.some(e=>isDeepStrictEqual(e,n)))continue;t.push([...n])}return t}export{resolveManagedUnsetPathsForWrite as n,applyUnsetPathsForWrite as t};