UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.26 kB
import{Lt as e}from"./sqlite-readonly-subsystem-Bfq7Sewc.mjs";import{r as t}from"./sqlite-readonly-path-existence-lfal2A68.mjs";import n from"node:fs";import{AsyncLocalStorage as r}from"node:async_hooks";const i=e(Symbol.for(`openclaw.maintenanceLiveAuthorityReads`),()=>/* @__PURE__ */ new WeakMap);function allowsMaintenanceLiveAuthorityReads(e,n){return hasAdmittedMaintenanceLiveAuthorityReads(e,t(n))}function hasAdmittedMaintenanceLiveAuthorityReads(e,t){for(let n=e;n;n=a.parents.get(n))if(i.get(n)?.has(t))return!0;return!1}function maintenanceOwnerHasSourceCustody(e,t){return e?.ownsSchemaMaintenance?(e.assertReadAdmission(),!allowsMaintenanceLiveAuthorityReads(e,t)):!1}function readCustodiedDrainedSqliteSource(e){if(!maintenanceOwnerHasSourceCustody(getOpenClawDatabaseMaintenanceScope(),e))return;let r=t(e);if(!(n.existsSync(`${r}-journal`)||(n.statSync(`${r}-wal`,{throwIfNoEntry:!1})?.size??0)>0))return n.statSync(r,{bigint:!0})}const a=e(Symbol.for(`openclaw.databaseMaintenanceResources`),()=>({current:new r,claims:/* @__PURE__ */ new WeakMap,parents:/* @__PURE__ */ new WeakMap}));function getOpenClawDatabaseMaintenanceScope(){return a.current.getStore()?.scope}function runOutsideOpenClawDatabaseMaintenanceScope(e){return a.current.exit(e)}function isOpenClawDatabaseMaintenanceResourceOwned(e,t){return a.claims.get(e)?.scope===t}function getOpenClawDatabaseMaintenanceResourceScope(e){return a.claims.get(e)?.scope}function observeOpenClawDatabaseMaintenanceResource(e){if(!e)return;let t=a.claims.get(e),n=getOpenClawDatabaseMaintenanceScope();if(!t)return;let r=commonMaintenanceAncestor(t.scope,n);r!==t.scope&&(t.scope.assertAdmission(),t.release(),a.claims.delete(e),r&&r.own(e,t.phase,t.close))}function commonMaintenanceAncestor(e,t){let n=/* @__PURE__ */ new Set;for(let t=e;t;t=a.parents.get(t))n.add(t);for(let e=t;e;e=a.parents.get(e))if(n.has(e))return e}export{isOpenClawDatabaseMaintenanceResourceOwned as a,runOutsideOpenClawDatabaseMaintenanceScope as c,hasAdmittedMaintenanceLiveAuthorityReads as i,getOpenClawDatabaseMaintenanceResourceScope as n,observeOpenClawDatabaseMaintenanceResource as o,getOpenClawDatabaseMaintenanceScope as r,readCustodiedDrainedSqliteSource as s,allowsMaintenanceLiveAuthorityReads as t};