openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.25 kB
JavaScript
import{isBigIntObject,isBooleanObject,isNumberObject,isStringObject}from"node:util/types";
//!src/agents/auth-profiles/clone-value.ts
function cloneAuthProfileJsonValue(e){const t=/* @__PURE__ */ new Set;const clone=(e,n)=>{let r=e;if(r!==null&&(typeof r===`object`||typeof r===`bigint`)){const e=Reflect.get(Object(r),`toJSON`);if(typeof e===`function`)r=Reflect.apply(e,r,[n])}if(typeof r===`bigint`||typeof r===`function`||typeof r===`symbol`)throw new TypeError(`AuthProfileStore contains non-JSON value: ${typeof r}`);if(isNumberObject(r))r=Number(r);else if(isStringObject(r))r=String(r);else if(isBooleanObject(r))r=Boolean.prototype.valueOf.call(r);else if(isBigIntObject(r))throw new TypeError(`AuthProfileStore contains non-JSON value: bigint`);if(typeof r===`number`)return Number.isFinite(r)?r===0?0:r:null;if(r===null||typeof r!==`object`)return r;if(t.has(r))throw new TypeError(`AuthProfileStore contains a circular JSON value`);t.add(r);try{if(Array.isArray(r))return Array.from({length:r.length},(e,t)=>clone(r[t],`${t}`)??null);return Object.fromEntries(Object.keys(r).flatMap(e=>{const t=clone(Reflect.get(r,e),e);return t===void 0?[]:[[e,t]]}))}finally{t.delete(r)}};return clone(e,``)}export{cloneAuthProfileJsonValue as t};