feat: setup backups can also take backups

This commit is contained in:
BluJ
2023-05-01 16:21:56 -06:00
parent 447ab65cba
commit 04c8e23e21
3 changed files with 43 additions and 25 deletions

View File

@@ -1,24 +1,43 @@
import { string } from "ts-matches"
import { Backups } from "."
import { GenericManifest } from "../manifest/ManifestTypes"
import { BackupOptions } from "../types"
import { BackupOptions, ExpectedExports } from "../types"
import { _ } from "../util"
export type SetupBackupsParams<M extends GenericManifest> = Array<
keyof M["volumes"] & string
(keyof M["volumes"] & string) | Backups<M>
>
export function setupBackups<M extends GenericManifest>(
...args: _<SetupBackupsParams<M>>
) {
return Backups.volumes(...args).build()
}
export function setupBackupsOptions<M extends GenericManifest>(
options: Partial<BackupOptions>,
...args: _<SetupBackupsParams<M>>
) {
return Backups.with_options(options)
.volumes(...args)
.build()
const backups = Array<Backups<M>>()
const volumes = new Set<keyof M["volumes"] & string>()
for (const arg of args) {
if (arg instanceof Backups) {
backups.push(arg)
} else {
volumes.add(arg)
}
}
backups.push(Backups.volumes(...volumes))
return {
get createBackup() {
return (async (options) => {
for (const backup of backups) {
await backup.build().createBackup(options)
}
}) as ExpectedExports.createBackup
},
get restoreBackup() {
return (async (options) => {
for (const backup of backups) {
await backup.build().restoreBackup(options)
}
}) as ExpectedExports.restoreBackup
},
} satisfies {
createBackup: ExpectedExports.createBackup
restoreBackup: ExpectedExports.restoreBackup
}
}

View File

@@ -7,7 +7,7 @@ import { InterfaceReceipt } from "./interfaceReceipt"
type Daemon<Ids extends string, Command extends string, Id extends string> = {
id: "" extends Id ? never : Id
command: ValidIfNoStupidEscape<Command> | [string, ...string[]]
env?: Record<string, string>
ready: {
display: string | null
fn: () => Promise<CheckResult> | CheckResult
@@ -83,7 +83,7 @@ export class Daemons<Ids extends string> {
daemonsStarted[daemon.id] = requiredPromise.then(async () => {
const { command } = daemon
const child = effects.runDaemon(command)
const child = effects.runDaemon(command, { env: daemon.env })
let currentInput: TriggerInput = {}
const getCurrentInput = () => currentInput
const trigger = (daemon.ready.trigger ?? defaultTrigger)(

View File

@@ -211,16 +211,15 @@ export type Effects = {
runCommand<A extends string>(
command: ValidIfNoStupidEscape<A> | [string, ...string[]],
input?: {
options?: {
timeoutMillis?: number
},
): Promise<string>
runShellDaemon(command: string): {
wait(): Promise<string>
term(): Promise<void>
}
runDaemon<A extends string>(
command: ValidIfNoStupidEscape<A> | [string, ...string[]],
options?: {
env?: Record<string, string>
},
): DaemonReturned
/** Uses the chown on the system */
@@ -232,17 +231,17 @@ export type Effects = {
console: {
/** Log at the trace level */
log(whatToPrint: string): void
log(whatToPrint: string): Promise<void>
/** Log at the trace level */
trace(whatToPrint: string): void
trace(whatToPrint: string): Promise<void>
/** Log at the warn level */
warn(whatToPrint: string): void
warn(whatToPrint: string): Promise<void>
/** Log at the error level */
error(whatToPrint: string): void
error(whatToPrint: string): Promise<void>
/** Log at the debug level */
debug(whatToPrint: string): void
debug(whatToPrint: string): Promise<void>
/** Log at the info level */
info(whatToPrint: string): void
info(whatToPrint: string): Promise<void>
}
/** Sandbox mode lets us read but not write */