From 04c8e23e2186fdfcb7880b7fda677e1aa0dc5647 Mon Sep 17 00:00:00 2001 From: BluJ Date: Mon, 1 May 2023 16:21:56 -0600 Subject: [PATCH] feat: setup backups can also take backups --- lib/backup/setupBackups.ts | 43 +++++++++++++++++++++++++++----------- lib/mainFn/Daemons.ts | 4 ++-- lib/types.ts | 21 +++++++++---------- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/lib/backup/setupBackups.ts b/lib/backup/setupBackups.ts index a32acec..d9ba69c 100644 --- a/lib/backup/setupBackups.ts +++ b/lib/backup/setupBackups.ts @@ -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 = Array< - keyof M["volumes"] & string + (keyof M["volumes"] & string) | Backups > export function setupBackups( ...args: _> ) { - return Backups.volumes(...args).build() -} - -export function setupBackupsOptions( - options: Partial, - ...args: _> -) { - return Backups.with_options(options) - .volumes(...args) - .build() + const backups = Array>() + const volumes = new Set() + 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 + } } diff --git a/lib/mainFn/Daemons.ts b/lib/mainFn/Daemons.ts index f895993..51e591d 100644 --- a/lib/mainFn/Daemons.ts +++ b/lib/mainFn/Daemons.ts @@ -7,7 +7,7 @@ import { InterfaceReceipt } from "./interfaceReceipt" type Daemon = { id: "" extends Id ? never : Id command: ValidIfNoStupidEscape | [string, ...string[]] - + env?: Record ready: { display: string | null fn: () => Promise | CheckResult @@ -83,7 +83,7 @@ export class Daemons { 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)( diff --git a/lib/types.ts b/lib/types.ts index f05dc3b..db43aa4 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -211,16 +211,15 @@ export type Effects = { runCommand( command: ValidIfNoStupidEscape | [string, ...string[]], - input?: { + options?: { timeoutMillis?: number }, ): Promise - runShellDaemon(command: string): { - wait(): Promise - term(): Promise - } runDaemon( command: ValidIfNoStupidEscape | [string, ...string[]], + options?: { + env?: Record + }, ): 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 /** Log at the trace level */ - trace(whatToPrint: string): void + trace(whatToPrint: string): Promise /** Log at the warn level */ - warn(whatToPrint: string): void + warn(whatToPrint: string): Promise /** Log at the error level */ - error(whatToPrint: string): void + error(whatToPrint: string): Promise /** Log at the debug level */ - debug(whatToPrint: string): void + debug(whatToPrint: string): Promise /** Log at the info level */ - info(whatToPrint: string): void + info(whatToPrint: string): Promise } /** Sandbox mode lets us read but not write */