mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 02:11:56 +00:00
feat: setup backups can also take backups
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)(
|
||||
|
||||
21
lib/types.ts
21
lib/types.ts
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user