openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.1 kB
JavaScript
import{Cn as e,Sn as t}from"./openclaw-state-read-subsystem-Dwoo5bcz.mjs";import{a as n,d as r,f as i,o as a,p as o,r as s,s as c}from"./openclaw-state-read-sqlite-post-commit-CsXPYVOo.mjs";const l=t(Symbol.for(`openclaw.sessionRowChanges`),`close-and-restart`),u=t(Symbol.for(`openclaw.sessionRowFactChanges`),`close-and-restart`),d=t(Symbol.for(`openclaw.sessionRowProjectionChanges`),`close-and-restart`),f=e(Symbol.for(`openclaw.sessionRowInvalidationSources`),()=>/* @__PURE__ */ new WeakMap),p=e(Symbol.for(`openclaw.sessionRowPrivateFacts`),()=>/* @__PURE__ */ new WeakMap),m=e(Symbol.for(`openclaw.sessionRowChangeCaptures`),()=>/* @__PURE__ */ new WeakMap),h=e(Symbol.for(`openclaw.sessionRowChangeRevision`),()=>({value:0}));function sessionRowChangeSource(e){return f.get(e)??e}const g={markFactsOnly(e,t){return p.set(e,t),e},subscribe(e){return o(l,e)},subscribeFacts(e){return o(u,e)},subscribeProjection(e){return o(d,e)},invalidate(e){h.value+=1,i(u,e),p.has(e)||i(d,e)},emit(e,t){g.emitBatch([e],t)},emitBatch(e,t,o){let g=t&&r(t);if(g&&s(g))for(let t of m.get(g)??[]){let n=t.length;if(!c(g,{stage:()=>t.push(...e),commit(){},rollback:()=>t.splice(n)}))throw Error(`Session receipt capture requires a transaction publication owner`)}let _=e.filter(e=>!p.has(e)),install=(e,t)=>{let n=[];for(let r of t)i(e,r,e=>n.push(e));if(n.length>0)throw AggregateError(n,`Session committed fact installation failed`)},v={installFacts:()=>{h.value+=1;for(let t of e)p.get(t)?.();install(u,e)},installProjection:()=>{install(d,_)},invalidate(){h.value+=1;let t=e.map(e=>{let t=`sessionKey`in e?{...e,facts:void 0,factsInvalidated:!0}:{...e,factsInvalidated:!0};return f.set(t,sessionRowChangeSource(e)),p.has(e)&&p.set(t,void 0),t}),n=[];for(let[e,r]of[[u,t],[d,t.filter(e=>!p.has(e))]])try{install(e,r)}catch(e){n.push(e)}if(n.length>0)throw AggregateError(n,`Session publication invalidation failed`)},notify:()=>{try{o?.()}finally{for(let e of _)if(`sessionKey`in e){let{facts:t,factsInvalidated:n,...r}=e;i(l,r)}else{let{factsInvalidated:t,...n}=e;i(l,n)}}}};(!g||!a(g,v))&&n(v)}};export{g as t};