UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 2.61 kB
import{u as registerNodeSqliteDisposeCallback}from"./kysely-sync-cache-state-CObqh5XE.mjs";import{Dt as registerSqliteReaderConnection,Q as requireNodeSqlite,g as prepareSqliteDatabaseAdmission,n as bindSqliteDatabaseAdmission,yt as getSqliteRuntimeCapabilities}from"./sqlite-database-admission-BikxIIFA.mjs";import{P as rememberSqliteBusyTimeout,l as trackSqliteSchema}from"./sqlite-schema-facts-x2rWNNBl.mjs";import path from"node:path";import{pathToFileURL}from"node:url"; //!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)}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}function resolveReadOnlyShmSqliteFileUri(e,t=process.platform){return`${resolveSqliteFileUriPath(e,t)}?mode=ro&readonly_shm=1`}function resolveExistingSqliteFileUri(e,t=process.platform){return`${resolveSqliteFileUriPath(e,t)}?mode=rw`}function resolveImmutableSqliteFileUri(e,t=process.platform){return`${resolveSqliteFileUriPath(e,t)}?mode=ro&immutable=1`}function openNodeSqliteDatabase(e,t,n){const r=requireNodeSqlite();const i=resolveNodeSqliteLocation(e);const a=t?.open===false?void 0:prepareSqliteDatabaseAdmission(i,{create:t?.readOnly!==true});if(t?.open!==false&&n!==void 0&&a!==n)throw new Error(`SQLite staging database changed before native open`);const o=new r.DatabaseSync(i,t??{});if(o.isOpen)try{bindSqliteDatabaseAdmission(o,a)}catch(e){o.close();throw e}o.open=()=>{const e=prepareSqliteDatabaseAdmission(i,{create:t?.readOnly!==true});if(n!==void 0&&e!==n)throw new Error(`SQLite staging database changed before native open`);r.DatabaseSync.prototype.open.call(o);try{bindSqliteDatabaseAdmission(o,e)}catch(e){o.close();throw e}};trackSqliteSchema(o,{DatabaseSync:r.DatabaseSync,StatementSync:r.StatementSync},t?.readOnly!==true);if(o.isOpen&&t?.timeout!==void 0)rememberSqliteBusyTimeout(o,Math.max(0,t.timeout));if(!getSqliteRuntimeCapabilities().explicitSqliteCloseReleasesNativeResources)registerNodeSqliteDisposeCallback(o,()=>{bunSqliteNativeCleanupPending=true});registerSqliteReaderConnection(o);return o}export{resolveSqliteFilesystemPath as a,resolveReadOnlyShmSqliteFileUri as i,resolveExistingSqliteFileUri as n,resolveImmutableSqliteFileUri as r,openNodeSqliteDatabase as t};