import { Backups } from "./Backups" import * as T from "../../../base/lib/types" import { _ } from "../util" export type SetupBackupsParams = | M["volumes"][number][] | ((_: { effects: T.Effects }) => Promise>) type SetupBackupsRes = { createBackup: T.ExpectedExports.createBackup restoreBackup: T.ExpectedExports.restoreBackup } export function setupBackups( options: SetupBackupsParams, ) { let backupsFactory: (_: { effects: T.Effects }) => Promise> if (options instanceof Function) { backupsFactory = options } else { backupsFactory = async () => Backups.withVolumes(...options) } const answer: { createBackup: T.ExpectedExports.createBackup restoreBackup: T.ExpectedExports.restoreBackup } = { get createBackup() { return (async (options) => { return (await backupsFactory(options)).createBackup(options.effects) }) as T.ExpectedExports.createBackup }, get restoreBackup() { return (async (options) => { return (await backupsFactory(options)).restoreBackup(options.effects) }) as T.ExpectedExports.restoreBackup }, } return answer }