openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
17 lines • 4.37 kB
JavaScript
import{hasNodeErrorCode as hasErrnoCode,isNodeError as isErrno}from"@openclaw/fs-safe/path";
//!packages/normalization-core/src/record-coerce.ts
function isRecord(e){return e!==null&&typeof e===`object`&&!Array.isArray(e)}function isStringArray(e){return Array.isArray(e)&&e.every(e=>typeof e===`string`)}function asOptionalRecord(e){return isRecord(e)?e:void 0}function asNullableRecord(e){return isRecord(e)?e:null}function asOptionalObjectRecord(e){return e&&typeof e===`object`?e:void 0}
//!packages/normalization-core/src/string-coerce.ts
function normalizeNullableString(e){if(typeof e!==`string`)return null;const t=e.trim();return t?t:null}function normalizeOptionalString(e){return normalizeNullableString(e)??void 0}function readNonBlankString(e){return typeof e===`string`&&e.trim()?e:void 0}function normalizeOptionalLowercaseString(e){return normalizeOptionalString(e)?.toLowerCase()}function normalizeLowercaseStringOrEmpty(e){return normalizeOptionalLowercaseString(e)??``}
//!packages/normalization-core/src/string-normalization.ts
function normalizeStringEntries(e){return(e??[]).map(e=>String(e).trim()).filter(Boolean)}function normalizeStringEntriesLower(e){return normalizeStringEntries(e).map(e=>e.toLowerCase())}function uniqueValues(e){return[...new Set(e)]}function uniqueStrings(e){return uniqueValues(e)}function normalizeUniqueStringEntries(e){return uniqueStrings(normalizeStringEntries(e?[...e]:void 0))}function normalizeUniqueStringEntriesLower(e){return uniqueStrings(normalizeStringEntriesLower(e?[...e]:void 0))}
//!src/infra/prototype-keys.ts
const BLOCKED_OBJECT_KEYS=/* @__PURE__ */ new Set([`__proto__`,`prototype`,`constructor`]);function isBlockedObjectKey(e){return BLOCKED_OBJECT_KEYS.has(e)}
//!src/infra/errno.ts
function isMissingPathError(e){return hasErrnoCode(e,`ENOENT`)||hasErrnoCode(e,`ENOTDIR`)||hasErrnoCode(e,`not-found`)}function ignoreMissingPath(e){if(hasErrnoCode(e,`ENOENT`))return;throw e}
//!src/infra/plain-object.ts
function isPlainObject(e){return typeof e===`object`&&e!==null&&!Array.isArray(e)&&Object.prototype.toString.call(e)===`[object Object]`}
//!src/infra/deep-merge.ts
function sanitizePlainObject(e){const t={};for(const[n,r]of Object.entries(e)){if(isBlockedObjectKey(n))continue;t[n]=isPlainObject(r)?sanitizePlainObject(r):r}return t}function mergeDeep(e,t,n={}){const r=n.arrays??`replace`;const i=n.undefinedValues??`skip`;if(Array.isArray(e)&&Array.isArray(t))return r===`concat`?[...e,...t]:t;if(!isPlainObject(e)||!isPlainObject(t))return t===void 0&&i===`skip`?e:t;const a=sanitizePlainObject(e);for(const[e,o]of Object.entries(t)){if(isBlockedObjectKey(e)||o===void 0&&i===`skip`)continue;const t=a[e];if(isPlainObject(o))a[e]=isPlainObject(t)?mergeDeep(t,o,n):sanitizePlainObject(o);else if(r===`concat`&&Array.isArray(t)&&Array.isArray(o))a[e]=[...t,...o];else a[e]=o}return a}
//!src/shared/global-singleton.ts
const GLOBAL_SINGLETON_RESETS_KEY=Symbol.for(`openclaw.globalSingletonLifecycleResets`);function resolveGlobalSingletonResetRegistry(){const e=globalThis;const t=e[GLOBAL_SINGLETON_RESETS_KEY];if(t instanceof Map)return t;const n=/* @__PURE__ */ new Map;e[GLOBAL_SINGLETON_RESETS_KEY]=n;return n}function readGlobalSingleton(e){const t=globalThis;return Object.hasOwn(t,e)?t[e]:void 0}function resolveGlobalSingleton(e,t,n,r=`close-and-restart`){const i=globalThis;let a;if(Object.hasOwn(i,e))a=i[e];else{a=t();i[e]=a}if(n)resolveGlobalSingletonResetRegistry().set(e,{lifecycle:r,reset:()=>n(a)});return a}function resolveGlobalMap(e,t,n){return resolveGlobalSingleton(e,()=>/* @__PURE__ */ new Map,typeof t===`string`?e=>e.clear():t,typeof t===`string`?t:n)}function resolveGlobalSet(e,t){return resolveGlobalSingleton(e,()=>/* @__PURE__ */ new Set,e=>e.clear(),t)}export{isRecord as C,asOptionalRecord as S,normalizeOptionalLowercaseString as _,mergeDeep as a,asNullableRecord as b,ignoreMissingPath as c,isBlockedObjectKey as d,normalizeStringEntries as f,normalizeNullableString as g,normalizeLowercaseStringOrEmpty as h,resolveGlobalSingleton as i,isErrno as l,normalizeUniqueStringEntriesLower as m,resolveGlobalMap as n,isPlainObject as o,normalizeUniqueStringEntries as p,resolveGlobalSet as r,hasErrnoCode as s,readGlobalSingleton as t,isMissingPathError as u,normalizeOptionalString as v,isStringArray as w,asOptionalObjectRecord as x,readNonBlankString as y};