openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.74 kB
JavaScript
import{o as resolveGlobalSingleton}from"./global-singleton-DolL9xGt.mjs";import{t as listDatabaseEngineStores}from"./registry-ByN-O5dB.mjs";import{AsyncLocalStorage}from"node:async_hooks";
//!src/infra/database-engine/context.ts
const state=resolveGlobalSingleton(Symbol.for(`openclaw.databaseEngineSelection`),()=>({}));const maintenance=resolveGlobalSingleton(Symbol.for(`openclaw.databaseEngineMaintenanceSelection`),()=>new AsyncLocalStorage);function getDatabaseEngineSelection(){return maintenance.getStore()??state.selection}function getScopedDatabaseEngineSelection(){return maintenance.getStore()}function withDatabaseEngineSelection(e,t){return maintenance.run(e,t)}function getDatabaseEngineInput(e){const t=getDatabaseEngineSelection();return t?.effectiveEngines[e]===`postgres`?t.postgres:void 0}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||e.postgres?.readOnly!==t.postgres?.readOnly||e.postgres?.ownership!==t.postgres?.ownership||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`)}export{withDatabaseEngineSelection as a,installDatabaseEngineSelection as i,getDatabaseEngineSelection as n,getScopedDatabaseEngineSelection as r,getDatabaseEngineInput as t};