UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.33 kB
import{t as SqliteWorkerError}from"./sqlite-worker-error-DHUQ0e2U.mjs";import"./context-DZjni16e.mjs";import{n as getPostgresPool}from"./pool-D39jfLRL.mjs";import"./sqlite-worker-contract-CcRGAuae.mjs";import{p as observeDatabaseRequest}from"./sqlite-transaction-CON-dGDv.mjs";import{a as isSqliteWorkerStoreAvailable,c as openSqliteWorkerStore,f as runSqliteWorkerStoreOperation,p as runSqliteWorkerStoreWrite}from"./sqlite-worker-store-D7HVdJ_q.mjs";import"./config-eTB-xhop.mjs";import{deserialize,serialize}from"node:v8"; //!src/infra/database-engine/worker-store.ts var EngineWorkerStore=class{constructor(e,t,n){this.options=e;this.input=t;this.store=n;this.closed=false}async current(){if(this.closed)throw new SqliteWorkerError(`Database engine store is closed`,`closed`);if(!isSqliteWorkerStoreAvailable(this.store)){this.reopening??=(async()=>{await this.store.close();this.store=await observeDatabaseRequest(this.input?`postgres`:`sqlite`,()=>openSqliteWorkerStore(this.options))})().finally(()=>{this.reopening=void 0});await this.reopening;if(this.closed)throw new SqliteWorkerError(`Database engine store is closed`,`closed`)}return this.store}async execute(e,t){let n=this.store;let r=e;if(this.closed||!isSqliteWorkerStoreAvailable(n)){const t=serialize(e);n=await this.current();r=deserialize(t)}return observeDatabaseRequest(this.input?`postgres`:`sqlite`,()=>n.execute(r,t))}close(){this.closed=true;this.closing??=(async()=>{await this.reopening?.catch(()=>void 0);await observeDatabaseRequest(this.input?`postgres`:`sqlite`,()=>this.store.close())})().catch(e=>{this.closing=void 0;throw e});return this.closing}};async function openEngineWorkerStore(e,t){if(t)getPostgresPool();const n={...e,moduleUrl:new URL(e.moduleUrl),input:deserialize(serialize(e.input))};const r=await observeDatabaseRequest(t?`postgres`:`sqlite`,()=>openSqliteWorkerStore(n));return new EngineWorkerStore(n,t,r)}async function runEngineStoreOperation(e,t,n,r,i,a){const o=e instanceof EngineWorkerStore?await e.current():e;const observed=e=>r({execute:(n,r)=>observeDatabaseRequest(t?`postgres`:`sqlite`,()=>e.execute(n,r))});if(t&&n)return runSqliteWorkerStoreWrite(o,observed,i??(()=>{}),[a]);return i?runSqliteWorkerStoreOperation(o,observed,void 0,i):observed(o)}export{runEngineStoreOperation as n,openEngineWorkerStore as t};