UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

39 lines (38 loc) • 2.25 kB
import { a as resolveGlobalSingleton } from "./global-singleton-D7yf05nR.mjs"; import { t as listDatabaseEngineStores } from "./registry-Dd7FIY0t.mjs"; import { AsyncLocalStorage } from "node:async_hooks"; //#region src/infra/database-engine/context.ts const state = resolveGlobalSingleton(Symbol.for("openclaw.databaseEngineSelection"), () => ({})); const maintenance = resolveGlobalSingleton(Symbol.for("openclaw.databaseEngineMaintenanceSelection"), () => new AsyncLocalStorage()); /** An explicit SQLite selection is distinct from an entry point awaiting config. */ function getDatabaseEngineSelection() { return maintenance.getStore() ?? state.selection; } /** Config-driven operations reuse only their own captured selection, never a running Gateway's. */ function getScopedDatabaseEngineSelection() { return maintenance.getStore(); } /** Offline transitions keep source and target work scoped without changing the running Gateway. */ function withDatabaseEngineSelection(e, t) { return maintenance.run(e, t); } /** Each store consumes its boot-selected family without resolving configuration again. */ function getDatabaseEngineInput(e) { const t = getDatabaseEngineSelection(); return t?.effectiveEngines[e] === "postgres" ? t.postgres : void 0; } /** Boot owns this process-lifetime fact; asynchronous callers never change it. */ function installDatabaseEngineSelection(e) { if (state.selection) { assertSameDatabaseEngineSelection(state.selection, e); return; } Object.freeze(e.effectiveEngines); if (e.postgres) Object.freeze(e.postgres); state.selection = Object.freeze(e); } function assertSameDatabaseEngineSelection(e, t) { if (e.postgres?.connection !== t.postgres?.connection || e.postgres?.schemaPrefix !== t.postgres?.schemaPrefix || e.postgres?.connectionEnvKey !== t.postgres?.connectionEnvKey || listDatabaseEngineStores().some(({ id: n }) => e.effectiveEngines[n] !== t.effectiveEngines[n])) throw new Error("Database engine selection conflicts with the installed process selection; restart the process to change it"); } //#endregion export { withDatabaseEngineSelection as a, installDatabaseEngineSelection as i, getDatabaseEngineSelection as n, getScopedDatabaseEngineSelection as r, getDatabaseEngineInput as t };