openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.15 kB
JavaScript
import{l as runOpenClawStateWriteTransaction}from"./openclaw-state-db-BlgxYkYw.mjs";import{i as restoreHookInstallIfCurrent,r as recordHookInstall}from"./installs-DthN4quj.mjs";
//!src/hooks/install-record-transaction.ts
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()}}}export{stageHookInstall as t};