UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

50 lines (49 loc) • 1.5 kB
import { l as runOpenClawStateWriteTransaction } from "./openclaw-state-db-ARhwdPJg.mjs"; import { i as restoreHookInstallIfCurrent, r as recordHookInstall } from "./installs-C2M3Yvip.mjs"; //#region src/hooks/install-record-transaction.ts /** Retain hook record and payload compensation until their config owner commits. */ async function stageHookInstall(e) { const { lease: t, payloadTransaction: n } = e; const r = { path: t.databasePath }; let i; try { i = runOpenClawStateWriteTransaction((n) => { t.assertOwnedInTransaction(n.db); e.beforePersistentApply?.(); return recordHookInstall(e.update, { database: n }); }, r); } catch (e) { if (n) try { t.assertOwned(); await n.rollback(); } catch (t) { throw new AggregateError([e, t], "Hook install payload rollback failed", { cause: t }); } throw e; } let a = false; return { async commit() { if (a) return; a = true; try { t.assertOwned(); await n?.commit(); } catch (e) { throw new Error("Hook install committed, but payload backup cleanup failed", { cause: e }); } }, async rollback() { if (a) return; a = true; if (!runOpenClawStateWriteTransaction((e) => { t.assertOwnedInTransaction(e.db); return restoreHookInstallIfCurrent(i, { database: e }); }, r)) throw new Error("Hook install changed before rollback; newer record and payload retained"); t.assertOwned(); await n?.rollback(); } }; } //#endregion export { stageHookInstall as t };