openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.59 kB
JavaScript
import{Q as e,U as t}from"./openclaw-state-read-sqlite-database-admission-CrkztOzk.mjs";import{S as n,v as r}from"./openclaw-state-read-sqlite-post-commit-CsXPYVOo.mjs";import{c as i,i as a,l as o,n as s,r as c,s as l}from"./openclaw-state-read-sqlite-private-snapshot-fork-B2lPOtW3.mjs";import{d as u,p as d}from"./openclaw-state-read-sqlite-worker-operation-settlement-DOkqmUGd.mjs";import{t as f}from"./openclaw-state-read-usingCtx-03vOGQ3v.mjs";import{n as p}from"./openclaw-state-read-open-CVc8tFBD.mjs";import{n as m}from"./openclaw-state-read-node-sqlite-B_Qn1gsS.mjs";import h from"node:fs";function tryInspectSqliteReadOnlyInProcess(e,t,n={}){let r=h.realpathSync.native(e),a;try{a=l(r)}catch(e){if(e instanceof s)return;throw e}let u=i(r),d=n.preserveSourceArtifacts===!0,f=!d&&n.allowClosedWal&&!u.wal&&!u.shm&&!u.journal;if(a===`empty`||a===`wal`&&!(u.wal&&u.shm)&&!f||d&&(a!==`wal`||u.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=l(r)}catch(e){if(e instanceof s)return;throw e}let n=i(r);if(t===`wal`&&!(n.wal&&n.shm)||t===`rollback`&&n.journal&&c(e)||d&&c(e))return;throw e}let n=t(e);return e.exec(`ROLLBACK;`),{value:n}};try{return o(r,`source`,read,{readOnlyShm:d})}catch(e){if(d&&isSqliteCantOpenError(e))return;throw e}}function isSqliteCantOpenError(t){return e(t)===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=p(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(e,i,o){if(!i)try{let t=tryInspectSqliteReadOnlyInProcess(e,o);if(t)return t.value}catch(e){if(!(e instanceof u)&&!(e instanceof d)&&!t(e))throw e}let s=await a(e);return n({release(){if(!s.cleanup())throw new r(`SQLite engine inspection cleanup failed: ${e}`)}},`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};