UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

56 lines (55 loc) • 2.42 kB
import { i as executeSqliteQuerySync, p as sqliteStringSet, s as getNodeSqliteKysely } from "./kysely-sync-YJo2lmGV.mjs"; import { a as tableExists } from "./openclaw-state-db-schema-helpers-nImZNMq_.mjs"; import { p as isOpenClawStateDatabaseOpen } from "./openclaw-state-db-cache-CkwtTqzF.mjs"; import { d as withExistingOpenClawStateDatabaseArtifactPreservingReadOnly } from "./openclaw-state-db-readonly-B6YHb1oF.mjs"; import { r as assertOpenClawStateDatabaseOwner } from "./openclaw-state-db-maintenance-Dvr7ztmv.mjs"; import "./openclaw-state-db-ARhwdPJg.mjs"; import { i as resolveBackupRunTarget, n as parseBackupRun, r as resolveBackupRunNamespace } from "./backup-run-records.contract.js"; //#region src/state/backup-run-records.kernel.ts /** The caller owns one transaction for both insertion and retention. */ function recordBackupRunInDatabase(e, t) { const n = getNodeSqliteKysely(e); executeSqliteQuerySync(e, n.insertInto("backup_runs").values(t)); const r = readBackupRunsInDatabase(e); const i = new Set(r.slice(0, 200).map((e) => e.id)); const a = /* @__PURE__ */ new Set(); const o = /* @__PURE__ */ new Set(); for (const e of r) { const t = JSON.stringify([ e.kind, e.location?.name ?? resolveBackupRunTarget(e), resolveBackupRunNamespace(e) ]); if (!a.has(t)) { a.add(t); i.add(e.id); } if (e.status === "ok" && !o.has(t)) { o.add(t); i.add(e.id); } } executeSqliteQuerySync(e, n.deleteFrom("backup_runs").where("id", "not in", sqliteStringSet([...i]))); } /** Reads only the bounded ledger, using facts captured by database admission. */ function readBackupRunsInDatabase(e) { if (!tableExists(e, "backup_runs")) return []; return executeSqliteQuerySync(e, getNodeSqliteKysely(e).selectFrom("backup_runs").selectAll().orderBy("created_at", "desc").orderBy("id", "desc")).rows.flatMap((e) => { const t = parseBackupRun(e); return t ? [t] : []; }); } //#endregion //#region src/state/backup-run-records.worker.ts const backupRunOperations = { "backup.recordOutcome": (e, t) => { const n = t.stateOptions(); if (!isOpenClawStateDatabaseOpen(n.path)) { if (!withExistingOpenClawStateDatabaseArtifactPreservingReadOnly(({ db: e }) => { assertOpenClawStateDatabaseOwner(e, { pathname: n.path }); return true; }, n)) return; } return t.write(({ db: t }) => recordBackupRunInDatabase(t, e)); } }; //#endregion export { backupRunOperations };