openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 1.8 kB
JavaScript
import{yt as e}from"./openclaw-state-read-subsystem-Dwoo5bcz.mjs";import{n as t}from"./openclaw-state-read-json-coercion-CAL-_nfN.mjs";import{a as n,r}from"./openclaw-state-read-kysely-sync-Bcu0Qb7F.mjs";import{o as i}from"./openclaw-state-read-openclaw-state-db-schema-helpers-QFZd8aJI.mjs";function isBytes(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>=0}function parseLocation(t){let n=e(t);if(n&&typeof n.name==`string`&&typeof n.provider==`string`&&typeof n.locationId==`string`&&typeof n.key==`string`&&typeof n.namespace==`string`&&isBytes(n.plaintextBytes)&&isBytes(n.storedBytes))return{name:n.name,provider:n.provider,locationId:n.locationId,key:n.key,namespace:n.namespace,plaintextBytes:n.plaintextBytes,storedBytes:n.storedBytes}}function parseRetention(t){let n=e(t);if(n)return isBytes(n.kept)&&isBytes(n.deleted)?{kept:n.kept,deleted:n.deleted}:void 0}function parseBackupRun(e){if(e.status!==`ok`&&e.status!==`failed`)return;let n=t(e.manifest_json);if(!n||n.kind!==`archive`&&n.kind!==`sqlite-snapshot`&&n.kind!==`git`&&n.kind!==`external`)return;let r=parseLocation(n.location),i=parseRetention(n.retention),a=r?.namespace??(typeof n.namespace==`string`?n.namespace:void 0);return{id:e.id,createdAt:e.created_at,archivePath:e.archive_path,status:e.status,kind:n.kind,...typeof n.target==`string`?{target:n.target}:{},...a===void 0?{}:{namespace:a},...typeof n.error==`string`?{error:n.error}:{},...n.pushFailed===!0?{pushFailed:!0}:{},...isBytes(n.bytes)?{bytes:n.bytes}:{},...r?{location:r}:{},...i?{retention:i}:{}}}function readBackupRunsInDatabase(e){return i(e,`backup_runs`)?r(e,n(e).selectFrom(`backup_runs`).selectAll().orderBy(`created_at`,`desc`).orderBy(`id`,`desc`)).rows.flatMap(e=>{let t=parseBackupRun(e);return t?[t]:[]}):[]}export{readBackupRunsInDatabase};