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 { string } from "ts-matches"
import { Backups } from "." import { Backups } from "."
import { GenericManifest } from "../manifest/ManifestTypes" import { GenericManifest } from "../manifest/ManifestTypes"
import { BackupOptions } from "../types" import { BackupOptions, ExpectedExports } from "../types"
import { _ } from "../util" import { _ } from "../util"
export type SetupBackupsParams<M extends GenericManifest> = Array< export type SetupBackupsParams<M extends GenericManifest> = Array<
keyof M["volumes"] & string (keyof M["volumes"] & string) | Backups<M>
> >
export function setupBackups<M extends GenericManifest>( export function setupBackups<M extends GenericManifest>(
...args: _<SetupBackupsParams<M>> ...args: _<SetupBackupsParams<M>>
) { ) {
return Backups.volumes(...args).build() const backups = Array<Backups<M>>()
} const volumes = new Set<keyof M["volumes"] & string>()
for (const arg of args) {
export function setupBackupsOptions<M extends GenericManifest>( if (arg instanceof Backups) {
options: Partial<BackupOptions>, backups.push(arg)
...args: _<SetupBackupsParams<M>> } else {
) { volumes.add(arg)
return Backups.with_options(options) }
.volumes(...args) }
.build() 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> = { type Daemon<Ids extends string, Command extends string, Id extends string> = {
id: "" extends Id ? never : Id id: "" extends Id ? never : Id
command: ValidIfNoStupidEscape<Command> | [string, ...string[]] command: ValidIfNoStupidEscape<Command> | [string, ...string[]]
env?: Record<string, string>
ready: { ready: {
display: string | null display: string | null
fn: () => Promise<CheckResult> | CheckResult fn: () => Promise<CheckResult> | CheckResult
@@ -83,7 +83,7 @@ export class Daemons<Ids extends string> {
daemonsStarted[daemon.id] = requiredPromise.then(async () => { daemonsStarted[daemon.id] = requiredPromise.then(async () => {
const { command } = daemon const { command } = daemon
const child = effects.runDaemon(command) const child = effects.runDaemon(command, { env: daemon.env })
let currentInput: TriggerInput = {} let currentInput: TriggerInput = {}
const getCurrentInput = () => currentInput const getCurrentInput = () => currentInput
const trigger = (daemon.ready.trigger ?? defaultTrigger)( const trigger = (daemon.ready.trigger ?? defaultTrigger)(

View File

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