UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

74 lines (73 loc) • 2.89 kB
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs"; import { n as safeParseJsonRecord } from "./json-coercion-CaJLaav-.mjs"; import { n as truncateOptionalText } from "./text-truncate-BXvItwne.mjs"; //#region src/state/backup-run-records.contract.ts const BACKUP_RUN_ERROR_MAX_LENGTH = 1200; function resolveBackupRunTarget(e) { return e.kind === "git" ? e.archivePath : e.target; } function resolveBackupRunNamespace(e) { return e.kind === "archive" ? e.location?.namespace ?? e.namespace : void 0; } function isBytes(e) { return typeof e === "number" && Number.isSafeInteger(e) && e >= 0; } function parseLocation(e) { const t = asOptionalRecord(e); if (!t) return; if (typeof t.name !== "string" || typeof t.provider !== "string" || typeof t.locationId !== "string" || typeof t.key !== "string" || typeof t.namespace !== "string" || !isBytes(t.plaintextBytes) || !isBytes(t.storedBytes)) return; return { name: t.name, provider: t.provider, locationId: t.locationId, key: t.key, namespace: t.namespace, plaintextBytes: t.plaintextBytes, storedBytes: t.storedBytes }; } function parseRetention(e) { const t = asOptionalRecord(e); if (!t) return; return isBytes(t.kept) && isBytes(t.deleted) ? { kept: t.kept, deleted: t.deleted } : void 0; } /** One codec for the additive manifest fields; legacy rows need no migration. */ function parseBackupRun(e) { if (e.status !== "ok" && e.status !== "failed") return; const t = safeParseJsonRecord(e.manifest_json); if (!t || t.kind !== "archive" && t.kind !== "sqlite-snapshot" && t.kind !== "git" && t.kind !== "external") return; const n = parseLocation(t.location); const r = parseRetention(t.retention); const i = n?.namespace ?? (typeof t.namespace === "string" ? t.namespace : void 0); return { id: e.id, createdAt: e.created_at, archivePath: e.archive_path, status: e.status, kind: t.kind, ...typeof t.target === "string" ? { target: t.target } : {}, ...i === void 0 ? {} : { namespace: i }, ...typeof t.error === "string" ? { error: t.error } : {}, ...t.pushFailed === true ? { pushFailed: true } : {}, ...isBytes(t.bytes) ? { bytes: t.bytes } : {}, ...n ? { location: n } : {}, ...r ? { retention: r } : {} }; } function serializeBackupRunManifest(e) { return JSON.stringify({ kind: e.kind, target: truncateOptionalText(e.target, 512), namespace: truncateOptionalText(resolveBackupRunNamespace(e), 128), error: truncateOptionalText(e.error, BACKUP_RUN_ERROR_MAX_LENGTH), ...e.pushFailed ? { pushFailed: true } : {}, ...isBytes(e.bytes) ? { bytes: e.bytes } : {}, ...e.location ? { location: e.location } : {}, ...e.retention ? { retention: e.retention } : {} }); } //#endregion export { serializeBackupRunManifest as a, resolveBackupRunTarget as i, parseBackupRun as n, resolveBackupRunNamespace as r, BACKUP_RUN_ERROR_MAX_LENGTH as t };