UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

77 lines (76 loc) • 3.45 kB
import { g as prepareSqliteDatabaseAdmission, n as bindSqliteDatabaseAdmission, ot as requireNodeSqlite } from "./sqlite-database-admission-DQIqro3d.mjs"; import { a as getSqliteRuntimeCapabilities } from "./bun-sqlite-library-BvzuPYCx.mjs"; import { u as registerNodeSqliteDisposeCallback } from "./kysely-sync-cache-state-Bb1gOqQO.mjs"; import { a as registerSqliteReaderConnection } from "./sqlite-reader-lifecycle-Cug3fDqm.mjs"; import { g as trackSqliteSchema } from "./sqlite-schema-facts-B1bVE8IB.mjs"; import { r as rememberSqliteBusyTimeout } from "./sqlite-busy-timeout-BEDmnGR_.mjs"; import { pathToFileURL } from "node:url"; import path from "node:path"; //#region src/infra/node-sqlite.ts let bunSqliteNativeCleanupPending = false; function resolveSqliteFilesystemPath(e) { if (process.platform !== "win32") return e; return path.toNamespacedPath(path.resolve(e)); } function resolveNodeSqliteLocation(e) { if (e === "" || e === ":memory:" || e.startsWith("file:")) return e; return resolveSqliteFilesystemPath(e); } /** Preserve native Windows path prefixes before adding SQLite URI parameters. */ function resolveSqliteFileUriPath(e, t) { if (t === "win32") { const t = path.win32.toNamespacedPath(path.win32.resolve(e)); return `file:${encodeURIComponent(t)}`; } return pathToFileURL(path.resolve(e)).href; } /** * Read a WAL database without writing its shared-memory index: no reader mark, no * index rebuild. SQLite reads the WAL itself when no live writer keeps the index valid. */ function resolveReadOnlyShmSqliteFileUri(e, t = process.platform) { return `${resolveSqliteFileUriPath(e, t)}?mode=ro&readonly_shm=1`; } /** Open an existing writable database without SQLite's create-if-missing flag. */ function resolveExistingSqliteFileUri(e, t = process.platform) { return `${resolveSqliteFileUriPath(e, t)}?mode=rw`; } /** Build an immutable SQLite URI without losing the Windows long-path namespace. */ function resolveImmutableSqliteFileUri(e, t = process.platform) { return `${resolveSqliteFileUriPath(e, t)}?mode=ro&immutable=1`; } /** Open node:sqlite through OpenClaw's runtime and filesystem-location boundary. */ function openNodeSqliteDatabase(e, t) { const n = requireNodeSqlite(); const r = resolveNodeSqliteLocation(e); const i = t?.open === false ? void 0 : prepareSqliteDatabaseAdmission(r, { create: t?.readOnly !== true }); const a = new n.DatabaseSync(r, t ?? {}); if (a.isOpen) try { bindSqliteDatabaseAdmission(a, i); } catch (e) { a.close(); throw e; } a.open = () => { const e = prepareSqliteDatabaseAdmission(r, { create: t?.readOnly !== true }); n.DatabaseSync.prototype.open.call(a); try { bindSqliteDatabaseAdmission(a, e); } catch (e) { a.close(); throw e; } }; trackSqliteSchema(a, { DatabaseSync: n.DatabaseSync, StatementSync: n.StatementSync }, t?.readOnly !== true); if (a.isOpen && t?.timeout !== void 0) rememberSqliteBusyTimeout(a, Math.max(0, t.timeout)); if (!getSqliteRuntimeCapabilities().explicitSqliteCloseReleasesNativeResources) registerNodeSqliteDisposeCallback(a, () => { bunSqliteNativeCleanupPending = true; }); registerSqliteReaderConnection(a); return a; } //#endregion export { resolveNodeSqliteLocation as a, resolveImmutableSqliteFileUri as i, openNodeSqliteDatabase as n, resolveReadOnlyShmSqliteFileUri as o, resolveExistingSqliteFileUri as r, resolveSqliteFilesystemPath as s, bunSqliteNativeCleanupPending as t };