UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

1 lines • 2.65 kB
import{a as e,r as t}from"./transcript-gateway-state-owner-errors-C0z_13ZD.mjs";import{i as n,p as r}from"./transcript-sqlite-error-diagnostics-Bzt01wuM.mjs";import{g as i,h as a,m as o,s,v as c,y as l}from"./transcript-sqlite-table-layout-migration-6FYoXQ_h.mjs";import{h as u,y as d}from"./transcript-sqlite-post-commit-BDZjIt2B.mjs";import{t as f}from"./transcript-usingCtx-03vOGQ3v.mjs";import"./transcript-openclaw-agent-db-schema-read-0j86l7zG.mjs";import{q as p}from"./transcript-openclaw-state-db-readonly-wvpVS-us.mjs";import{t as m}from"./transcript-node-sqlite-dPq0UNII.mjs";import h from"node:fs";function tryInspectSqliteReadOnlyInProcess(e,t,n={}){let r=h.realpathSync.native(e),i;try{i=c(r)}catch(e){if(e instanceof o)return;throw e}let s=l(r),u=n.preserveSourceArtifacts===!0,d=!u&&n.allowClosedWal&&!s.wal&&!s.shm&&!s.journal;if(i===`empty`||i===`wal`&&!(s.wal&&s.shm)&&!d||u&&(i!==`wal`||s.journal))return;let read=e=>{try{e.exec(`PRAGMA busy_timeout = 30000; PRAGMA trusted_schema = OFF; BEGIN;`),e.prepare(`PRAGMA schema_version;`).get()}catch(e){let t;try{t=c(r)}catch(e){if(e instanceof o)return;throw e}let n=l(r);if(t===`wal`&&!(n.wal&&n.shm)||t===`rollback`&&n.journal&&a(e)||u&&a(e))return;throw e}let n=t(e);return e.exec(`ROLLBACK;`),{value:n}};try{return p(r,`source`,read,{readOnlyShm:u})}catch(e){if(i===`wal`&&d&&n.snapshotAfterClosedWalFailure||u&&isSqliteCantOpenError(e))return;throw e}}function isSqliteCantOpenError(e){return r(e)===14}function readBackupEngineImage(e,t){try{var n=f();return readEngineAnchorIdentity(n.u(m(e,{readOnly:!0})),t)}catch(e){n.e=e}finally{n.d()}}function readEngineAnchorIdentity(e,t){let n=s(e);if(!n)return{engine:`sqlite`};let r=n[0];if(n.length!==1||r?.engine!==`postgres`||typeof r.store_id!=`string`||typeof r.schema!=`string`||!/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(r.schema))throw Error(`Invalid PostgreSQL anchor: ${t}. Restore its matched backup.`);return{engine:`postgres`,storeId:r.store_id,namespace:r.schema}}async function readBackupEngineInProcess(e,t=!1){return inspectPhysicalStoreInProcess(e,t,t=>readEngineAnchorIdentity(t,e))}async function inspectPhysicalStoreInProcess(r,a,o){if(!a)try{let e=tryInspectSqliteReadOnlyInProcess(r,o);if(e)return e.value}catch(r){if(!(r instanceof t)&&!(r instanceof e)&&!n(r))throw r}let s=await i(r);return d({release(){if(!s.cleanup())throw new u(`SQLite engine inspection cleanup failed: ${r}`)}},`SQLite engine inspection`,()=>{try{var e=f();return o(e.u(m(s.location,{readOnly:!0})))}catch(t){e.e=t}finally{e.d()}})}export{inspectPhysicalStoreInProcess,readBackupEngineImage,readBackupEngineInProcess,readEngineAnchorIdentity};