openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.77 kB
JavaScript
import{X as e,at as t}from"./openclaw-state-read-sqlite-database-admission-Ck6VG7rE.mjs";import{a as n,l as r}from"./openclaw-state-read-sqlite-lifecycle-errors-3AcFJUep.mjs";import{d as i,p as a}from"./openclaw-state-read-sqlite-worker-operation-settlement-ogK5IsJy.mjs";import{a as o,n as s,o as c,r as l,t as u}from"./openclaw-state-read-sqlite-readonly-location-DPGzRsxO.mjs";import{t as d}from"./openclaw-state-read-usingCtx-03vOGQ3v.mjs";import{n as f}from"./openclaw-state-read-open-pprz0Grj.mjs";import{n as p}from"./openclaw-state-read-node-sqlite-UqZdY7HG.mjs";import"./openclaw-state-read-sqlite-schema-contract-CE8IFvCt.mjs";import{t as m}from"./openclaw-state-read-sqlite-source-handle-DLUASgzj.mjs";import h from"node:fs";function tryInspectSqliteReadOnlyInProcess(e,t,n={}){let r=h.realpathSync.native(e),i;try{i=o(r)}catch(e){if(e instanceof u)return;throw e}let a=c(r),l=n.preserveSourceArtifacts===!0,d=!l&&n.allowClosedWal&&!a.wal&&!a.shm&&!a.journal;if(i===`empty`||i===`wal`&&!(a.wal&&a.shm)&&!d||l&&(i!==`wal`||a.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=o(r)}catch(e){if(e instanceof u)return;throw e}let n=c(r);if(t===`wal`&&!(n.wal&&n.shm)||t===`rollback`&&n.journal&&s(e)||l&&s(e))return;throw e}let n=t(e);return e.exec(`ROLLBACK;`),{value:n}};try{return m(r,`source`,read,{readOnlyShm:l})}catch(e){if(i===`wal`&&d&&n.snapshotAfterClosedWalFailure||l&&isSqliteCantOpenError(e))return;throw e}}function isSqliteCantOpenError(e){return t(e)===14}function readBackupEngineImage(e,t){try{var n=d();return readEngineAnchorIdentity(n.u(p(e,{readOnly:!0})),t)}catch(e){n.e=e}finally{n.d()}}function readEngineAnchorIdentity(e,t){let n=f(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(t,o,s){if(!o)try{let e=tryInspectSqliteReadOnlyInProcess(t,s);if(e)return e.value}catch(t){if(!(t instanceof i)&&!(t instanceof a)&&!e(t))throw t}let c=await l(t);return r({release(){if(!c.cleanup())throw new n(`SQLite engine inspection cleanup failed: ${t}`)}},`SQLite engine inspection`,()=>{try{var e=d();return s(e.u(p(c.location,{readOnly:!0})))}catch(t){e.e=t}finally{e.d()}})}export{inspectPhysicalStoreInProcess,readBackupEngineImage,readBackupEngineInProcess,readEngineAnchorIdentity};