openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.51 kB
JavaScript
import{a as e,r as t}from"./transcript-gateway-state-owner-errors-LqZAQ-y_.mjs";import{i as n,p as r}from"./transcript-sqlite-error-diagnostics-CLL4Z7ly.mjs";import{S as i,v as a}from"./transcript-sqlite-post-commit-B_pko32i.mjs";import{t as o}from"./transcript-usingCtx-03vOGQ3v.mjs";import{c as s,i as c,l,n as u,r as d,s as f}from"./transcript-sqlite-private-snapshot-fork-CKFbjfTN.mjs";import{t as p}from"./transcript-node-sqlite-RfCz-ZxM.mjs";import{n as m}from"./transcript-open-POEd8M0o.mjs";import h from"node:fs";function tryInspectSqliteReadOnlyInProcess(e,t,n={}){let r=h.realpathSync.native(e),i;try{i=f(r)}catch(e){if(e instanceof u)return;throw e}let a=s(r),o=n.preserveSourceArtifacts===!0,c=!o&&n.allowClosedWal&&!a.wal&&!a.shm&&!a.journal;if(i===`empty`||i===`wal`&&!(a.wal&&a.shm)&&!c||o&&(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=f(r)}catch(e){if(e instanceof u)return;throw e}let n=s(r);if(t===`wal`&&!(n.wal&&n.shm)||t===`rollback`&&n.journal&&d(e)||o&&d(e))return;throw e}let n=t(e);return e.exec(`ROLLBACK;`),{value:n}};try{return l(r,`source`,read,{readOnlyShm:o})}catch(e){if(o&&isSqliteCantOpenError(e))return;throw e}}function isSqliteCantOpenError(e){return r(e)===14}function readBackupEngineImage(e,t){try{var n=o();return readEngineAnchorIdentity(n.u(p(e,{readOnly:!0})),t)}catch(e){n.e=e}finally{n.d()}}function readEngineAnchorIdentity(e,t){let n=m(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,s,l){if(!s)try{let e=tryInspectSqliteReadOnlyInProcess(r,l);if(e)return e.value}catch(r){if(!(r instanceof t)&&!(r instanceof e)&&!n(r))throw r}let u=await c(r);return i({release(){if(!u.cleanup())throw new a(`SQLite engine inspection cleanup failed: ${r}`)}},`SQLite engine inspection`,()=>{try{var e=o();return l(e.u(p(u.location,{readOnly:!0})))}catch(t){e.e=t}finally{e.d()}})}export{inspectPhysicalStoreInProcess,readBackupEngineImage,readBackupEngineInProcess,readEngineAnchorIdentity};