UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

159 lines (158 loc) • 5.59 kB
import { n as runtimeProcessEntrypoints } from "./runtime-process-entrypoints-qiyJvDDT.mjs"; import { a as resolveRuntimeWorkerUrl } from "./runtime-worker-url-DRDkoS4J.mjs"; import { l as hasActiveGatewayStateOwner } from "./gateway-state-owner-Bnv5owvG.mjs"; import { n as captureRuntimeWorkerSource } from "./runtime-worker-generation-DBZgwXBG.mjs"; import { a as withDatabaseEngineSelection, r as getScopedDatabaseEngineSelection } from "./context-DE59wyBs.mjs"; import { a as isConfigReadFailure, i as formatInvalidConfigDetails, n as createConfigReadError, r as createInvalidConfigError } from "./io.invalid-config-DK-BYZ4Y.mjs"; import { t as readBackupEngine } from "./physical-store-BRXG56Jw.mjs"; import { n as resolveDatabaseEngineSelection } from "./config-1gpCgiFx.mjs"; import "./physical-store-inspection-C7yPt-uR.mjs"; import "./database-backup.operations-BNuRDpZK.mjs"; import path from "node:path"; import fs from "node:fs/promises"; import { AsyncLocalStorage } from "node:async_hooks"; //#region src/snapshot/database-backup.ts const offlineBackup = new AsyncLocalStorage(); async function runOfflineDatabaseBackup(e, t, n) { const r = offlineBackup.getStore(); if (r) { r.assertCurrent(); return t(r); } const { runWithLocalStateOwner: i } = await import("./local-state-owner-CxFnsNJm.mjs"); const { resolveStateDir: a } = await import("./paths-C9ebzH5f.mjs"); if (hasActiveGatewayStateOwner(path.join(a(), "state", "openclaw.sqlite"))) throw new Error("PostgreSQL backup requires the Gateway stopped; stop through the service owner, then rerun."); const { createConfigIO: o } = await import("./config/config.js"); return i({ method: "backup.create", params: {}, target: e, onForeignOwner: "refuse", runLocal: async ({ assertCurrent: e }) => { e(); const r = n && "config" in n ? n : void 0; let i = r?.config; if (!i) { const t = n && "configPath" in n ? n : void 0; const r = o({ ...n && "configPath" in n ? n : {}, observe: false, pluginValidation: "core-only" }); const a = t?.configSourcePath ? await fs.readFile(t.configSourcePath, "utf8") : void 0; e(); const s = await (a === void 0 ? r.readConfigFileSnapshot() : r.readConfigFileSnapshotFromRaw(a)); e(); if (!s.valid) { const e = formatInvalidConfigDetails(s.issues); throw isConfigReadFailure(s) ? createConfigReadError(s, e) : createInvalidConfigError(s.path, e); } i = s.config; } const a = r?.selection ?? await resolveDatabaseEngineSelection(i); e(); const s = { config: i, assertCurrent: e }; return withDatabaseEngineSelection(a, () => offlineBackup.run(s, () => t(s))); } }); } async function runBackupTask(e, t) { t(); const { WorkerTaskPool: n } = await import("./worker-task-pool-BrtanqWr.mjs"); const r = captureRuntimeWorkerSource(resolveRuntimeWorkerUrl(runtimeProcessEntrypoints.databaseBackup)); const i = getScopedDatabaseEngineSelection() ?? await resolveDatabaseEngineSelection(e.params.config); t(); return withDatabaseEngineSelection(i, async () => { const i = new n({ workerUrl: r.moduleUrl, maxWorkers: 1 }); try { const n = await i.run(e, {}); t(); return n; } finally { await i.close(); } }); } function capturePostgresBackup(e) { if (!("config" in e)) return runOfflineDatabaseBackup(e.sourcePath, ({ config: t, assertCurrent: n }) => capturePostgresBackup({ ...e, config: t, assertCurrent: n, profile: "user-backup" })); const { assertCurrent: t, ...n } = e; return runBackupTask({ operation: "capture", params: n }, t); } async function captureGitPostgresBackup(e) { if ((e.physicalEngine ?? readBackupEngine(e.snapshotPath).engine) !== "postgres") return; await fs.mkdir(e.outputPath, { mode: 448 }); const t = await runOfflineDatabaseBackup(e.snapshotPath, ({ config: t, assertCurrent: n }) => capturePostgresBackup({ sourcePath: e.snapshotPath, directory: path.join(e.outputPath, "postgres"), profile: "user-backup", config: t, assertCurrent: n, ...e.excludeSecrets ? { gitIdentity: e.identity } : {} })); const { gitBackupRedaction: n } = await import("./git-backup-sanitizer-C-cc71fB.mjs"); const r = n(e.identity, new Set(Object.keys(t.verification.tables)), e.excludeSecrets === true, t.source.owner); const i = { schemaVersion: 2, identity: e.identity, postgresSource: { storeId: t.source.storeId, namespace: t.source.namespace }, userVersion: t.exportSchemaVersion, ...r, tables: {} }; await fs.writeFile(path.join(e.outputPath, "manifest.json"), `${JSON.stringify(i, null, 2)}\n`, { mode: 384 }); return i; } function discardPostgresRestores(e, t) { return runBackupTask({ operation: "discard", params: { config: e, namespaces: t } }, () => {}); } function preparePostgresRestore({ assertCurrent: e, ...t }) { return runBackupTask({ operation: "restore", params: t }, e); } /** Resolve physical family identity through the same provider admission as capture. */ function readPostgresBackupFamily(e, t) { return runBackupTask({ operation: "family", params: { sourcePath: e, config: t } }, () => {}); } function fingerprintPostgresBackup(e, t, n) { return runBackupTask({ operation: "fingerprint", params: { sourcePath: e, config: t, pluginOwners: n } }, () => {}); } //#endregion export { preparePostgresRestore as a, fingerprintPostgresBackup as i, capturePostgresBackup as n, readPostgresBackupFamily as o, discardPostgresRestores as r, runOfflineDatabaseBackup as s, captureGitPostgresBackup as t };