openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 2.35 kB
JavaScript
import{t as toStringifiedError}from"../stringified-error-B2ELAgdP.mjs";import{n as openNodeSqliteDatabase}from"../node-sqlite-DXyF1fBG.mjs";import{r as readSqliteIntegrityFileIdentity}from"../sqlite-file-generation-CHAXRj0p.mjs";import{i as assertSqliteIntegrity,t as SqliteIntegrityError}from"../sqlite-integrity-BzUEDiX5.mjs";import{t as configureSqliteMaintenanceCache}from"../sqlite-maintenance-cache-C2QXuBdj.mjs";import{n as serializeNativeErrorResponse}from"../native-error-response-vI2qu5y2.mjs";import fs from"node:fs";import{constants as constants$1,setPriority}from"node:os";import{deserialize,serialize}from"node:v8";import{performance}from"node:perf_hooks";import{on}from"node:events";
//!src/infra/sqlite-integrity.worker.ts
const synchronous=process.argv[2]===`--check-sync`;if(!synchronous&&(!process.send||!process.disconnect))throw new Error(`SQLite integrity child requires parent IPC.`);function send(e){if(!process.send)throw new Error(`SQLite integrity child requires parent IPC.`);const t=process.send.bind(process);return new Promise((n,r)=>{t(e,e=>{if(e)r(e);else n()})})}function sendPhase(e){return synchronous?Promise.resolve():send({type:`phase`,phase:e})}async function check(e){let t;let n;let r;let i;try{if(e.background)setPriority(0,constants$1.priority.PRIORITY_LOW);await sendPhase(`opening`);readSqliteIntegrityFileIdentity(e.pathname,e.identity);t=openNodeSqliteDatabase(e.pathname,{readOnly:true,timeout:e.busyTimeoutMs});configureSqliteMaintenanceCache(t);readSqliteIntegrityFileIdentity(e.pathname,e.identity);await sendPhase(`checking`);const n=performance.now();try{({staleFts:i}=assertSqliteIntegrity(t,e.databaseLabel,e.integrity))}finally{r=performance.now()-n}}catch(e){n=toStringifiedError(e)}finally{if(t)try{await sendPhase(`closing`)}catch(e){n??=toStringifiedError(e)}try{t?.close()}catch(e){n=toStringifiedError(e)}}let a={ok:true,staleFts:i};if(n)a={ok:false,error:{...serializeNativeErrorResponse(n),...n instanceof SqliteIntegrityError?{findings:n.findings}:{}}};if(r!==void 0)a.checkElapsedMs=r;return a}if(synchronous){const e=deserialize(fs.readFileSync(0));fs.writeFileSync(1,serialize(await check(e)))}else for await(const[e]of on(process,`message`)){if(`type`in e){process.disconnect?.();break}const t=await check(e);await send(t);if(!e.reuse||!t.ok){process.disconnect?.();break}}export{};