openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 3.73 kB
JavaScript
import{v as e}from"./openclaw-state-read-home-dir-BQZX1pD2.mjs";import{t}from"./openclaw-state-read-promise-like-3qqJObCs.mjs";import{c as n}from"./openclaw-state-read-sqlite-lifecycle-errors-3AcFJUep.mjs";import{t as r}from"./openclaw-state-read-subsystem-DSi0tJn8.mjs";function notifyListeners(e,t,n){for(let r of e)try{r(t)}catch(e){n?.(e)}}function registerListener(e,t){return e.add(t),()=>e.delete(t)}function assertSyncTransactionResult(e){if(t(e))throw Error(`SQLite write transactions must be synchronous; Promise returns are not supported.`)}const i=Symbol.for(`openclaw.postgres-sync-connection`);function isPostgresSqlConnection(e){return i in e&&e[i]===!0}function sqlPublicationAnchor(e){return isPostgresSqlConnection(e)?e.anchor:e}const a=r(`sqlite/publication`);function committedPublicationState(e){return{commit:e.installFacts,prepareObservers:e.installProjection,invalidate:e.invalidate}}function installCommittedState(e,t){let n=/* @__PURE__ */ new Map,install=(e,t)=>{try{t?.()}catch(t){n.set(e,t)}};for(let t of e)install(t,t.commit);let invalidate=()=>{let e=!0;for(let[t,r]of n)try{t.invalidate?t.invalidate(r):e=!1}catch{e=!1}return e};invalidate();for(let t of e)n.has(t)||install(t,t.prepareObservers);let r=invalidate();if(n.size>0)try{a.error(`Committed SQLite facts could not be installed`,{count:n.size,fenced:r})}catch{}if(r)for(let e of t)try{e()}catch{try{a.error(`SQLite post-commit notification failed`)}catch{}}}function publishSqliteCommittedState(e){let t=`installFacts`in e?[e]:e;installCommittedState(t.map(committedPublicationState),t.map(e=>e.notify))}function stageSqliteCommittedPublication(e,t){return stageSqliteTransactionState(e,committedPublicationState(t))?(deferSqlitePostCommitPublication(e,t.notify),!0):!1}const o=e(Symbol.for(`openclaw.sqlitePostCommitPublications`),()=>/* @__PURE__ */ new WeakMap),s=e(Symbol.for(`openclaw.sqliteTransactionState`),()=>/* @__PURE__ */ new WeakMap);function hasSqlitePostCommitScope(e){return o.has(sqlPublicationAnchor(e))}function deferSqlitePostCommitPublication(e,t){let n=o.get(sqlPublicationAnchor(e));return n?(n.push(t),!0):!1}function stageSqliteTransactionState(e,t){let n=s.get(sqlPublicationAnchor(e));return n?(t.stage?.(),n.push({prepareCommit:t.prepareCommit,commit:t.commit,prepareObservers:t.prepareObservers,invalidate:t.invalidate,rollback:t.rollback}),!0):!1}function prepareSqliteTransactionCommit(e){for(let t of s.get(sqlPublicationAnchor(e))??[])t.prepareCommit?.()}function rollbackTransactionState(e,t,r=`rolled-back`){let i=[];for(let n of e.toReversed())try{r===`unknown`&&n.invalidate?n.invalidate(t):n.rollback?.(t)}catch(e){i.push(e)}if(i.length>0)throw n([t,...i],`SQLite transaction and rollback observers failed`,t)}function discardSqliteTransactionState(e,t,n=`unknown`){let r=sqlPublicationAnchor(e);o.get(r)?.splice(0);let i=s.get(r)?.splice(0)??[];o.delete(r),s.delete(r),rollbackTransactionState(i,t,n)}function withSqlitePostCommitPublications(e,t){let n=sqlPublicationAnchor(e),r=e.isTransaction||o.has(n),i=r?o.get(n):[],a=r?s.get(n):[],c=i?.length??0,l=a?.length??0;!r&&i&&a&&(o.set(n,i),s.set(n,a));let u;try{u=t()}catch(e){throw i?.splice(c),rollbackTransactionState(a?.splice(l)??[],e),e}finally{r||(o.delete(n),s.delete(n))}return r||installCommittedState(a??[],i??[]),u}export{publishSqliteCommittedState as a,withSqlitePostCommitPublications as c,sqlPublicationAnchor as d,notifyListeners as f,prepareSqliteTransactionCommit as i,assertSyncTransactionResult as l,discardSqliteTransactionState as n,stageSqliteCommittedPublication as o,registerListener as p,hasSqlitePostCommitScope as r,stageSqliteTransactionState as s,deferSqlitePostCommitPublication as t,isPostgresSqlConnection as u};