openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.19 kB
JavaScript
import{o as resolveGlobalSingleton}from"./global-singleton-DolL9xGt.mjs";import{t as isPromiseLike}from"./promise-like-OKzBwzLG.mjs";import{threadId}from"node:worker_threads";
//!src/infra/database-engine/admission-scope.ts
const processRole=resolveGlobalSingleton(Symbol.for(`openclaw.databaseProcessRole`),()=>({}));function installDatabaseProcessRole(e){if(processRole.role&&processRole.role!==e)throw new Error(`Database process role is already ${processRole.role}; cannot become ${e}`);processRole.role??=e}function getDatabaseProcessRole(){return processRole.role}let admissionDepth=0;function withEngineStoreAdmission(e){admissionDepth+=1;try{const t=e();if(isPromiseLike(t))throw new Error(`Database engine admission must remain synchronous`);return t}finally{admissionDepth-=1}}function assertEngineStoreExecutionAllowed(){if(threadId===0&&admissionDepth===0&&processRole.role!==`cli-oneshot`)throw new Error(`PostgreSQL connections must run in a worker; only synchronous admission, migrations, and CLI one-shots may run on the main thread`)}export{withEngineStoreAdmission as i,getDatabaseProcessRole as n,installDatabaseProcessRole as r,assertEngineStoreExecutionAllowed as t};