UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

666 lines (665 loc) • 24.4 kB
import { n as containsAsciiControlCharacter } from "./string-normalization-DLmfYZXI.mjs"; import { n as ignoreMissingPath } from "./errno-DFcoqIT9.mjs"; import { w as root } from "./fs-safe-BbWvmdVn.mjs"; import { n as normalizeAgentId, t as isValidAgentId } from "./agent-id-CQjtp2ft.mjs"; import "./session-key-CqAyZeVk.mjs"; import { l as quoteSqliteIdentifier } from "./sqlite-schema-sql-CPyk_2Hd.mjs"; import { t as _usingCtx } from "./usingCtx-rhpPzaNq.mjs"; import { n as resolvePreferredOpenClawTmpDir } from "./tmp-openclaw-dir-Bf0oU1Cn.mjs"; import { i as readPostgresCatalog, r as postgresCatalogQuery, t as assertPostgresCatalog } from "./postgres-catalog-BahDJJPz.mjs"; import { n as openNodeSqliteDatabase } from "./node-sqlite-CU4puofF.mjs"; import { c as sha256File, l as syncDirectory, s as requireDirectorySync } from "./directory-durability-DlnWwNmv.mjs"; import { o as sameFileMutationFingerprint, t as copyFileHandle } from "./file-descriptor-DQ-v5bLt.mjs"; import { Et as _enum, Jn as string, Lt as boolean, Nt as array, Pn as number, Un as record, lr as uuid, qn as strictObject, xn as literal } from "./schemas-Cy6abvsu.mjs"; import { t as datetime } from "./iso-DaJ-ni95.mjs"; import { r as getScopedDatabaseEngineSelection } from "./context-DE59wyBs.mjs"; import { a as resolveSqliteDatabaseFilePaths, t as SQLITE_SIDECAR_SUFFIXES } from "./sqlite-files-rWisKj_V.mjs"; import { a as withDatabasePortPostgres, i as withDatabasePortConnection } from "./port-provider-CZISFP-d.mjs"; import { n as readBackupEngineImage } from "./physical-store-inspection-C7yPt-uR.mjs"; import { t as admitDatabasePortDescriptor } from "./port-descriptor-r7GHhJnm.mjs"; import { i as readDatabasePortAllocations, n as materializeDatabasePort, t as inspectDatabasePort } from "./port.worker-BIwiDJ3h.mjs"; import { t as createGitBackupRowTransform } from "./git-backup-sanitizer-CN-7TbHt.mjs"; import { n as inspectPostgresGeneration, t as fingerprintPostgresGeneration } from "./postgres-generation-D3b-yckQ.mjs"; import fs from "node:fs"; import path from "node:path"; import { randomUUID } from "node:crypto"; import fs$1 from "node:fs/promises"; import { isDeepStrictEqual } from "node:util"; import { sameFileIdentity } from "@openclaw/fs-safe/advanced"; import { withTempWorkspace } from "@openclaw/fs-safe/temp"; //#region src/snapshot/snapshot-provider.ts const SNAPSHOT_MANIFEST_FILENAME = "manifest.json"; const SNAPSHOT_SQLITE_FILENAME = "database.sqlite"; //#endregion //#region src/snapshot/manifest.ts const MAX_MANIFEST_BYTES = 1048576; const MAX_SQLITE_USER_VERSION = 2147483647; const MIN_SQLITE_USER_VERSION = -2147483648; const SNAPSHOT_ID_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,254}$/; const SHA256_PATTERN = /^[a-f0-9]{64}$/; async function hashSnapshotArtifact(e) { const t = await (await root(e)).open(SNAPSHOT_SQLITE_FILENAME, { hardlinks: "reject", symlinks: "reject" }); try { return { ...await hashFileHandle(t.handle), identity: t.exactIdentity }; } finally { await t.handle.close(); } } async function copySnapshotArtifact(e, t) { const n = await (await root(e)).open(SNAPSHOT_SQLITE_FILENAME, { hardlinks: "reject", symlinks: "reject" }); let r; let i; try { r = await fs$1.open(t, "wx+", 384); i = await r.stat({ bigint: true }); const e = await hashFileHandle(n.handle, r); await r.sync(); const a = await r.stat({ bigint: true }); const o = await fs$1.lstat(t, { bigint: true }); if (!sameFileIdentity(i, a) || !sameFileIdentity(i, o)) throw new Error(`Snapshot restore staging file changed during copy: ${t}`); return { ...e, identity: a }; } catch (e) { await r?.close().catch(() => void 0); r = void 0; if (i) { const e = await fs$1.lstat(t, { bigint: true }).catch(() => void 0); if (e && sameFileIdentity(i, e)) await fs$1.unlink(t).catch(() => void 0); } throw e; } finally { await r?.close().catch(() => void 0); await n.handle.close().catch(() => void 0); } } async function hashFileHandle(e, t) { const n = await e.stat({ bigint: true }); let r = 0; if (t) r = await copyFileHandle(e, t); const i = await sha256File(t ?? e); const a = await e.stat({ bigint: true }); if (!sameFileMutationFingerprint(n, a) || t && r !== i.bytes) throw new Error("Snapshot artifact changed while being read."); return { sha256: i.digest, sizeBytes: i.bytes }; } async function writeSnapshotManifest(e, t) { const n = path.join(e, SNAPSHOT_MANIFEST_FILENAME); const r = await fs$1.open(n, "wx+", 384); try { await r.writeFile(`${JSON.stringify(t, null, 2)}\n`, "utf8"); await r.sync(); } finally { await r.close(); } } async function readSnapshotManifest(e) { const t = await root(e); const n = path.join(e, SNAPSHOT_MANIFEST_FILENAME); const r = await t.read(SNAPSHOT_MANIFEST_FILENAME, { hardlinks: "reject", maxBytes: MAX_MANIFEST_BYTES, symlinks: "reject" }); let i; try { i = JSON.parse(r.buffer.toString("utf8")); } catch (e) { throw new Error(`Snapshot manifest is not valid JSON: ${n}`, { cause: e }); } return parseSnapshotManifest(i, n, path.basename(e)); } function parseSnapshotManifest(e, t, n) { const r = requireRecord(e, "manifest", t); requireExactKeys(r, [ "schemaVersion", "snapshotId", "createdAt", "database", "artifact" ]); if (r.schemaVersion !== 1) throw new Error(`Unsupported snapshot manifest schemaVersion ${String(r.schemaVersion)}: ${t}`); const i = requireSnapshotId(r.snapshotId, t); if (i !== n) throw new Error(`Snapshot manifest id ${i} does not match directory ${n}: ${t}`); const a = requireCanonicalTimestamp(r.createdAt, t); const o = parseSnapshotDatabase(r.database, t); const s = requireRecord(r.artifact, "artifact", t); requireExactKeys(s, [ "path", "sha256", "sizeBytes" ]); if (s.path !== "database.sqlite") throw new Error(`Snapshot manifest artifact.path must be ${SNAPSHOT_SQLITE_FILENAME}: ${t}`); if (typeof s.sha256 !== "string" || !SHA256_PATTERN.test(s.sha256)) throw new Error(`Snapshot manifest artifact.sha256 is invalid: ${t}`); if (!Number.isSafeInteger(s.sizeBytes) || Number(s.sizeBytes) <= 0) throw new Error(`Snapshot manifest artifact.sizeBytes is invalid: ${t}`); return { schemaVersion: 1, snapshotId: i, createdAt: a, database: o, artifact: { path: SNAPSHOT_SQLITE_FILENAME, sha256: s.sha256, sizeBytes: Number(s.sizeBytes) } }; } function parseSnapshotDatabase(e, t) { const n = requireRecord(e, "database", t); const r = n.role; const i = requireSafeText(n.basename, "database.basename", t, 255); if (path.basename(i) !== i || i === "." || i === "..") throw new Error(`Snapshot manifest database.basename is invalid: ${t}`); const a = requireSqliteUserVersion(n.userVersion, t); if (r === "global") { requireExactKeys(n, [ "role", "basename", "userVersion" ]); return { role: r, basename: i, userVersion: a }; } if (r === "agent") { requireExactKeys(n, [ "role", "agentId", "basename", "userVersion" ]); const e = requireSafeText(n.agentId, "database.agentId", t, 64); if (!isValidAgentId(e) || normalizeAgentId(e) !== e) throw new Error(`Snapshot manifest database.agentId is invalid: ${t}`); return { role: r, agentId: e, basename: i, userVersion: a }; } if (r === "generic") { requireExactKeys(n, [ "role", "id", "basename", "userVersion" ]); return { role: r, id: requireSafeText(n.id, "database.id", t, 256), basename: i, userVersion: a }; } throw new Error(`Snapshot manifest database.role is invalid: ${t}`); } function requireRecord(e, t, n) { if (!e || typeof e !== "object" || Array.isArray(e)) throw new Error(`Snapshot manifest ${t} must be an object: ${n}`); return e; } function requireExactKeys(e, t) { const n = Object.keys(e).toSorted(); const r = [...t].toSorted(); if (n.length !== r.length || n.some((e, t) => e !== r[t])) throw new Error(`Snapshot manifest fields must be exactly ${t.join(", ")}; got ${n.join(", ")}`); } function requireSnapshotId(e, t) { if (typeof e !== "string" || !SNAPSHOT_ID_PATTERN.test(e)) throw new Error(`Snapshot manifest snapshotId is invalid: ${t}`); return e; } function requireCanonicalTimestamp(e, t) { if (typeof e !== "string") throw new Error(`Snapshot manifest createdAt is invalid: ${t}`); const n = new Date(e); if (!Number.isFinite(n.getTime()) || n.toISOString() !== e) throw new Error(`Snapshot manifest createdAt is not canonical ISO 8601: ${t}`); return e; } function requireSafeText(e, t, n, r) { if (typeof e !== "string" || e.length === 0 || e.length > r || e.trim() !== e || containsAsciiControlCharacter(e)) throw new Error(`Snapshot manifest ${t} is invalid: ${n}`); return e; } function requireSqliteUserVersion(e, t) { if (!Number.isSafeInteger(e) || Number(e) < MIN_SQLITE_USER_VERSION || Number(e) > MAX_SQLITE_USER_VERSION) throw new Error(`Snapshot manifest database.userVersion is invalid: ${t}`); return Number(e); } //#endregion //#region src/snapshot/restore-paths.ts async function assertFreshRestoreTarget(e) { for (const t of resolveSqliteDatabaseFilePaths(e)) if (await fs$1.lstat(t).catch(ignoreMissingPath)) throw new Error(`Fresh SQLite restore path already exists: ${t}`); } function assertNoSqliteSidecarsSync(e, t) { for (const n of SQLITE_SIDECAR_SUFFIXES) { const r = `${e}${n}`; try { fs.lstatSync(r); } catch (e) { ignoreMissingPath(e); continue; } throw new Error(`${t}: ${r}`); } } //#endregion //#region src/snapshot/export-envelope.ts const identifier = string().regex(/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,254}$/); const digest = string().regex(/^[a-f0-9]{64}$/); const version = number().int().nonnegative().max(2147483647); const artifact$1 = strictObject({ sha256: digest, sizeBytes: number().int().positive().safe() }); const table = strictObject({ rows: number().int().nonnegative().safe(), sha256: digest }); const allocation = strictObject({ value: string().regex(/^(0|[1-9][0-9]{0,18})$/).refine((e) => /^[0-9]{1,19}$/.test(e) && BigInt(e) <= 9223372036854775807n), called: boolean() }); const postgresEnvelope = strictObject({ schemaVersion: literal(2), snapshotId: identifier, createdAt: datetime({ precision: 3 }), profile: _enum(["exact", "user-backup"]), source: strictObject({ engine: literal("postgres"), storeId: uuid(), owner: identifier, namespace: identifier, schemaVersion: version }), exportSchemaVersion: version, activeFragments: array(identifier), verification: strictObject({ tables: record(identifier, table), allocations: record(identifier, allocation) }), artifacts: strictObject({ "database.sqlite": artifact$1, "anchor.sqlite": artifact$1 }), sanitizedDifferences: array(identifier) }).refine((e) => e.profile !== "exact" || e.sanitizedDifferences.length === 0, { message: "Exact exports must not contain sanitization differences" }); function parsePostgresEnvelope(e, t) { const n = postgresEnvelope.parse(e); if (n.snapshotId !== t) throw new Error("Export manifest id does not match its directory"); return n; } async function readSnapshotExportEnvelope(e, t = path.basename(e)) { const n = await (await root(e)).read(SNAPSHOT_MANIFEST_FILENAME, { hardlinks: "reject", symlinks: "reject", maxBytes: 1048576 }); const r = JSON.parse(n.buffer.toString("utf8")); if (r && typeof r === "object" && "schemaVersion" in r && r.schemaVersion === 1) return { engine: "sqlite", manifest: parseSnapshotManifest(r, e, t) }; return { engine: "postgres", manifest: parsePostgresEnvelope(r, t) }; } async function writePostgresExportEnvelope(e, t) { const n = parsePostgresEnvelope(t, path.basename(e)); const r = await fs$1.open(path.join(e, SNAPSHOT_MANIFEST_FILENAME), "wx", 384); try { await r.writeFile(`${JSON.stringify(n, null, 2)}\n`); await r.sync(); } finally { await r.close(); } } /** The owner inspects the held anchor, never a separately reopened pathname. */ async function verifyPostgresExportEnvelope(e, t, n, r) { const i = parsePostgresEnvelope(t, path.basename(e)); if (i.profile !== r) throw new Error("Export profile does not match the requested restore"); const a = await root(e); for (const t of ["database.sqlite", "anchor.sqlite"]) { assertNoSqliteSidecarsSync(path.join(e, t), "PostgreSQL export has unexpected SQLite sidecar"); const r = await a.open(t, { hardlinks: "reject", symlinks: "reject" }); try { const e = await r.handle.stat({ bigint: true }); const a = await sha256File(r.handle); const o = i.artifacts[t]; if (a.digest !== o.sha256 || a.bytes !== o.sizeBytes) throw new Error(`Export artifact verification failed: ${t}`); if (t === "anchor.sqlite") { const e = await n(r.handle); if (e.engine !== "postgres" || e.storeId !== i.source.storeId || e.namespace !== i.source.namespace) throw new Error("Export anchor does not match the source store identity"); } if (!sameFileMutationFingerprint(e, await r.handle.stat({ bigint: true }))) throw new Error(`Export artifact changed during verification: ${t}`); } finally { await r.handle.close(); } } } //#endregion //#region src/snapshot/database-backup-core.worker.ts async function captureDatabaseArtifact(e) { try { var t = _usingCtx(); const n = t.a(await fs$1.open(e, fs$1.constants.O_RDONLY | fs$1.constants.O_NOFOLLOW)); const r = await n.stat(); if (!r.isFile() || r.nlink !== 1) throw new Error(`Database artifact must be an unaliased regular file: ${e}`); const { digest: i, bytes: a } = await sha256File(n); return { path: e, sha256: i, size: a }; } catch (e) { t.e = e; } finally { await t.d(); } } async function artifact(e) { const { sha256: t, size: n } = await captureDatabaseArtifact(e); return { sha256: t, sizeBytes: n }; } async function assertDatabaseArtifact(e) { if (!isDeepStrictEqual(await captureDatabaseArtifact(e.path), e)) throw new Error(`Database artifact changed: ${e.path}`); } /** Export from an admitted family into a private capture with its anchor already held. */ async function exportPostgresBackup(e) { const { client: t, descriptor: n, anchor: r } = e; const i = path.join(e.directory, ".export.sqlite"); const a = path.join(e.directory, "database.sqlite"); const o = path.join(e.directory, "anchor.sqlite"); let s; try { var c = _usingCtx(); e.assertCurrent(); await fs$1.writeFile(i, "", { flag: "wx", mode: 384 }); const a = c.u(openNodeSqliteDatabase(i, { readBigInts: true })); const o = await readDatabasePortAllocations({ engine: "postgres", db: t, namespace: r.namespace }, n); s = await materializeDatabasePort({ source: { engine: "postgres", db: t, namespace: r.namespace }, destination: { engine: "sqlite", db: a }, descriptor: n, storeId: r.storeId, sourceAllocations: o, assertCurrent: e.assertCurrent, transformRow: e.gitIdentity ? createGitBackupRowTransform(e.gitIdentity, n.id, new Set(n.tables.map(({ name: e }) => e))) : void 0 }); s.allocations = o; } catch (e) { c.e = e; } finally { c.d(); } const l = []; e.assertCurrent(); if (e.profile === "exact") await fs$1.rename(i, a); else { const { createVerifiedSqliteSnapshot: t } = await import("./sqlite-snapshot-DGhn22ul.mjs"); const { sanitizeOpenClawGlobalStateSnapshot: r } = await import("./openclaw-state-snapshot-sanitizer-CTxg0eOm.mjs"); await t({ sourcePath: i, targetPath: a, sourceAcquisition: { mode: "isolated-process", stagingRoot: e.directory, preserveSourceArtifacts: true }, preserveRowIds: true, async transform(t) { if (e.gitIdentity) l.push("git-exclude-secrets"); const i = t.prepare("SELECT total_changes() AS n").get()?.n; r(t); const { embedSessionColdArchivesInSnapshotInWorker: a } = await import("./session-cold-storage-backup.worker-CygcSqnD.mjs"); await a({ database: t, sourceStorePath: e.sourcePath }); if (t.prepare("SELECT total_changes() AS n").get()?.n !== i) l.push("transient-state"); if (e.gitIdentity) s.tables = (await inspectDatabasePort({ engine: "sqlite", db: t }, n)).tables; } }); await fs$1.unlink(i); } const u = { schemaVersion: 2, snapshotId: path.basename(e.directory), createdAt: (/* @__PURE__ */ new Date()).toISOString(), profile: e.profile, source: { ...r, owner: n.id, schemaVersion: n.version }, exportSchemaVersion: n.version, activeFragments: [...n.activeFragments], verification: s, artifacts: { "database.sqlite": await artifact(a), "anchor.sqlite": await artifact(o) }, sanitizedDifferences: l }; e.assertCurrent(); await writePostgresExportEnvelope(e.directory, u); return u; } /** Restore an already verified capture; the caller owns its client and publication. */ async function restorePostgresBackup(e) { const { client: t, descriptor: n, manifest: r } = e; if (n.version !== r.exportSchemaVersion || n.version !== r.source.schemaVersion) throw new Error("PostgreSQL backup requires its matching family schema version."); const i = `restore_${randomUUID().replaceAll("-", "")}`; try { try { var a = _usingCtx(); const s = a.u(openNodeSqliteDatabase(path.join(e.directory, "database.sqlite"), { readOnly: true, readBigInts: true })); e.assertCurrent(); const c = await materializeDatabasePort({ source: { engine: "sqlite", db: s }, destination: { engine: "postgres", db: t, namespace: i }, descriptor: n, storeId: r.source.storeId, sourceAllocations: r.verification.allocations, activeFragments: r.activeFragments, assertCurrent: e.assertCurrent }); if (e.profile === "exact" && !isDeepStrictEqual(c, r.verification)) throw new Error("Exact PostgreSQL export verification differs from its manifest."); e.assertCurrent(); await fs$1.copyFile(path.join(e.directory, "anchor.sqlite"), e.anchorPath, fs$1.constants.COPYFILE_EXCL); if (!isDeepStrictEqual(await artifact(e.anchorPath), r.artifacts["anchor.sqlite"])) throw new Error("PostgreSQL restore anchor changed during preparation."); try { var o = _usingCtx(); o.u(openNodeSqliteDatabase(e.anchorPath)).prepare("UPDATE openclaw_engine_anchor SET schema = ?").run(i); } catch (e) { o.e = e; } finally { o.d(); } return { namespace: i }; } catch (e) { a.e = e; } finally { a.d(); } } catch (e) { await discardPostgresNamespace(t, i); throw e; } } /** Only namespaces allocated by this restore owner may be discarded. */ async function discardPostgresNamespace(e, t) { if (!/^restore_[a-f0-9]{32}$/.test(t)) throw new Error("Refusing to discard a namespace not allocated by PostgreSQL restore."); await e.query(`DROP SCHEMA IF EXISTS "${t}" CASCADE`); } async function fingerprintPostgresDatabase(e) { const { client: t, anchor: n } = e; await t.query("BEGIN ISOLATION LEVEL REPEATABLE READ READ ONLY"); try { return fingerprintPostgresGeneration(n, await inspectPostgresGeneration(t, n)); } finally { await t.query("ROLLBACK"); } } //#endregion //#region src/snapshot/database-backup.operations.ts async function verifyMatchedPostgresBackup(e, t, n) { if ((await fs$1.readdir(e)).includes(".pending")) throw new Error("PostgreSQL backup is incomplete."); const r = await readSnapshotExportEnvelope(e); if (r.engine !== "postgres") throw new Error("Expected a matched PostgreSQL export."); await verifyPostgresExportEnvelope(e, r.manifest, inspectHeldAnchor, t); if (n && (r.manifest.source.storeId !== n.storeId || r.manifest.source.namespace !== n.namespace)) throw new Error("PostgreSQL backup belongs to a different store."); return r.manifest; } async function inspectHeldAnchor(e) { const t = { rootDir: resolvePreferredOpenClawTmpDir(), prefix: "openclaw-anchor-" }; return await withTempWorkspace(t, async ({ dir: t }) => { const n = path.join(t, "anchor.sqlite"); try { var r = _usingCtx(); const t = r.a(await fs$1.open(n, "wx", 384)); await copyFileHandle(e, t); } catch (e) { r.e = e; } finally { await r.d(); } const i = readBackupEngineImage(n, n); if (i.engine !== "postgres") throw new Error("Export artifact is not a PostgreSQL anchor."); return i; }); } /** Caller retains stopped installation custody until all client/native handles settle. */ async function capturePostgresBackupInWorker(e) { const { createVerifiedSqliteSnapshot: t } = await import("./sqlite-snapshot-DGhn22ul.mjs"); e.assertCurrent(); await fs$1.mkdir(e.directory, { mode: 448 }); await fs$1.writeFile(path.join(e.directory, ".pending"), "", { flag: "wx", mode: 384 }); const n = path.join(e.directory, "anchor.sqlite"); await t({ sourcePath: e.sourcePath, targetPath: n, preserveRowIds: true }); const r = readBackupEngineImage(n, e.sourcePath); if (r.engine !== "postgres") throw new Error("A PostgreSQL backup requires its original anchor."); return await withDatabasePortPostgres(e.config, r, async (t, n) => { const i = await admitDatabasePortDescriptor({ engine: "postgres", db: t, namespace: r.namespace }, n); e.assertCurrent(); const a = await exportPostgresBackup({ ...e, client: t, descriptor: i, anchor: r }); await verifyPostgresExportEnvelope(e.directory, a, inspectHeldAnchor, e.profile); await fs$1.unlink(path.join(e.directory, ".pending")); requireDirectorySync(await syncDirectory(e.directory), "PostgreSQL backup"); requireDirectorySync(await syncDirectory(path.dirname(e.directory)), "PostgreSQL backup parent"); return a; }, e.pluginOwners); } /** Build a new namespace and anchor; the caller alone publishes the anchor. Never drop the old namespace. */ async function preparePostgresRestoreInWorker(e) { const t = await verifyMatchedPostgresBackup(e.directory, e.profile, e.expectedSource); return await withDatabasePortConnection(e.config, async (n) => { const { loadDatabasePortDescriptor: r } = await import("./port-provider-descriptor-B4XIABI5.mjs"); const i = await r(t.source.owner, e.config, { version: t.source.schemaVersion, pluginOwners: e.pluginOwners }); const { namespace: a } = await restorePostgresBackup({ ...e, client: n, descriptor: i, manifest: t }); try { const t = getScopedDatabaseEngineSelection()?.postgres; e.assertCurrent(); await i.admit?.(e.anchorPath, t); if (e.preserveUpdateHistory) { if (!e.expectedSource) throw new Error("PostgreSQL update rollback requires its captured source identity."); const t = e.expectedSource.namespace; const r = [i, ...i.fragments ?? []].find((e) => e.tables.some((e) => e.name === "update_runs")); const o = r?.tables.find((e) => e.name === "update_runs"); if (!r || !o) throw new Error("PostgreSQL rollback cannot preserve the current update history contract."); const s = r.expectedCatalog.filter((e) => e.table === o.name); const c = readPostgresCatalog((await n.query(postgresCatalogQuery(t))).rows[0].catalog); assertPostgresCatalog(c.filter((e) => e.table === o.name), s); const l = o.columns.map(({ name: e }) => quoteSqliteIdentifier(e)).join(", "); await n.query("BEGIN; SET LOCAL synchronous_commit = on"); try { await n.query(`DELETE FROM ${quoteSqliteIdentifier(a)}.update_runs`); await n.query(`INSERT INTO ${quoteSqliteIdentifier(a)}.update_runs (${l}) SELECT ${l} FROM ${quoteSqliteIdentifier(t)}.update_runs`); await n.query("COMMIT"); } catch (e) { await n.query("ROLLBACK"); throw e; } } const { sha256: r, size: o } = await captureDatabaseArtifact(e.anchorPath); return { namespace: a, sha256: r, sizeBytes: o }; } catch (e) { await discardPostgresNamespace(n, a); throw e; } }); } //#endregion export { captureDatabaseArtifact as a, readSnapshotExportEnvelope as c, copySnapshotArtifact as d, hashSnapshotArtifact as f, SNAPSHOT_SQLITE_FILENAME as g, SNAPSHOT_MANIFEST_FILENAME as h, assertDatabaseArtifact as i, assertFreshRestoreTarget as l, writeSnapshotManifest as m, preparePostgresRestoreInWorker as n, discardPostgresNamespace as o, readSnapshotManifest as p, verifyMatchedPostgresBackup as r, fingerprintPostgresDatabase as s, capturePostgresBackupInWorker as t, assertNoSqliteSidecarsSync as u };