Files
start-os/sdk/lib/backup/setupBackups.ts
Aiden McClelland c174b65465 create version graph to handle migrations (#2708)
* create version graph to handle migrations

* Fix some version alpha test

* connect dataVersion api

* rename init fns

* improve types and add tests

* set data version after backup restore

* chore: Add some types tests for version info

* wip: More changes to versionInfo tests

* wip: fix my stupid

* update mocks

* update runtime

* chore: Fix the loop

---------

Co-authored-by: Jade <2364004+Blu-J@users.noreply.github.com>
Co-authored-by: J H <dragondef@gmail.com>
2024-08-15 20:58:53 +00:00

46 lines
1.2 KiB
TypeScript

import { Backups } from "./Backups"
import * as T from "../types"
import { _ } from "../util"
export type SetupBackupsParams<M extends T.Manifest> = Array<
M["volumes"][number] | Backups<M>
>
export function setupBackups<M extends T.Manifest>(
manifest: M,
...args: _<SetupBackupsParams<M>>
) {
const backups = Array<Backups<M>>()
const volumes = new Set<M["volumes"][0]>()
for (const arg of args) {
if (arg instanceof Backups) {
backups.push(arg)
} else {
volumes.add(arg)
}
}
backups.push(Backups.volumes(...volumes))
const answer: {
createBackup: T.ExpectedExports.createBackup
restoreBackup: T.ExpectedExports.restoreBackup
} = {
get createBackup() {
return (async (options) => {
for (const backup of backups) {
await backup.build(options.pathMaker).createBackup(options)
}
}) as T.ExpectedExports.createBackup
},
get restoreBackup() {
return (async (options) => {
for (const backup of backups) {
await backup.build(options.pathMaker).restoreBackup(options)
}
await options.effects.setDataVersion({ version: manifest.version })
}) as T.ExpectedExports.restoreBackup
},
}
return answer
}