openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
32 lines (31 loc) • 1.58 kB
JavaScript
import { a as resolveGlobalSingleton } from "./global-singleton-D7yf05nR.mjs";
import { t as isPromiseLike } from "./promise-like-aMoWEh5w.mjs";
import { threadId } from "node:worker_threads";
//#region src/infra/database-engine/admission-scope.ts
const processRole = resolveGlobalSingleton(Symbol.for("openclaw.databaseProcessRole"), () => ({}));
/** Entry points install this once; embedded Gateways cannot inherit a CLI exception. */
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;
}
/** Undefined until an entry point installs one; embedders keep the shared defaults. */
function getDatabaseProcessRole() {
return processRole.role;
}
let admissionDepth = 0;
/** Temporarily admit synchronous boot and migration SQL on the Gateway main thread. */
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");
}
//#endregion
export { withEngineStoreAdmission as i, getDatabaseProcessRole as n, installDatabaseProcessRole as r, assertEngineStoreExecutionAllowed as t };