openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 2.46 kB
JavaScript
import{In as e,St as t,Wn as n,si as r,ui as i}from"./disk-budget.worker-sqlite-readonly-worker-Bob4L7Jx.mjs";import{H as a,W as o}from"./disk-budget.worker-sqlite-worker-operation-settlement-B656vNKC.mjs";import{n as s}from"./disk-budget.worker-open-BjgZk-08.mjs";import{f as c}from"./disk-budget.worker-gateway-process-argv-lGmvE77y.mjs";import{C as l,D as u,O as d,S as f,k as p,w as m}from"./disk-budget.worker-kysely-sync-BBbkOhNM.mjs";import h from"node:fs";function tryInspectSqliteReadOnlyInProcess(e,t,n={}){let r=h.realpathSync.native(e),i;try{i=u(r)}catch(e){if(e instanceof f)return;throw e}let a=d(r),o=n.preserveSourceArtifacts===!0,s=!o&&n.allowClosedWal&&!a.wal&&!a.shm&&!a.journal;if(i===`empty`||i===`wal`&&!(a.wal&&a.shm)&&!s||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=u(r)}catch(e){if(e instanceof f)return;throw e}let n=d(r);if(t===`wal`&&!(n.wal&&n.shm)||t===`rollback`&&n.journal&&l(e)||o&&l(e))return;throw e}let n=t(e);return e.exec(`ROLLBACK;`),{value:n}};try{return p(r,`source`,read,{readOnlyShm:o})}catch(e){if(o&&isSqliteCantOpenError(e))return;throw e}}function isSqliteCantOpenError(e){return n(e)===14}function readBackupEngineImage(e,n){try{var r=c();return readEngineAnchorIdentity(r.u(t(e,{readOnly:!0})),n)}catch(e){r.e=e}finally{r.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(n,s,l){if(!s)try{let e=tryInspectSqliteReadOnlyInProcess(n,l);if(e)return e.value}catch(t){if(!(t instanceof a)&&!(t instanceof o)&&!e(t))throw t}let u=await m(n);return i({release(){if(!u.cleanup())throw new r(`SQLite engine inspection cleanup failed: ${n}`)}},`SQLite engine inspection`,()=>{try{var e=c();return l(e.u(t(u.location,{readOnly:!0})))}catch(t){e.e=t}finally{e.d()}})}export{inspectPhysicalStoreInProcess,readBackupEngineImage,readBackupEngineInProcess,readEngineAnchorIdentity};