chore: New sdk things

This commit is contained in:
BluJ
2023-03-06 15:28:11 -07:00
parent 40c75cfcb2
commit b4fc6e891e
19 changed files with 157 additions and 185 deletions

View File

@@ -1,4 +1,3 @@
import { ok } from "../util";
import * as T from "../types";
export const DEFAULT_OPTIONS: T.BackupOptions = {
@@ -41,7 +40,7 @@ export class Backups {
constructor(
private options = DEFAULT_OPTIONS,
private backupSet = [] as BackupSet[]
private backupSet = [] as BackupSet[],
) {}
static volumes(...volumeNames: string[]) {
return new Backups().addSets(
@@ -50,7 +49,7 @@ export class Backups {
srcPath: "./",
dstPath: `./${srcVolume}/`,
dstVolume: Backups.BACKUP,
}))
})),
);
}
static addSets(...options: BackupSet[]) {
@@ -73,12 +72,12 @@ export class Backups {
srcPath: "./",
dstPath: `./${srcVolume}/`,
dstVolume: Backups.BACKUP,
}))
})),
);
}
addSets(...options: BackupSet[]) {
options.forEach((x) =>
this.backupSet.push({ ...x, options: { ...this.options, ...x.options } })
this.backupSet.push({ ...x, options: { ...this.options, ...x.options } }),
);
return this;
}
@@ -99,7 +98,7 @@ export class Backups {
.map((x) => x.dstPath)
.map((x) => x.replace(/\.\/([^]*)\//, "$1"));
const filteredItems = previousItems.filter(
(x) => backupPaths.indexOf(x) === -1
(x) => backupPaths.indexOf(x) === -1,
);
for (const itemToRemove of filteredItems) {
effects.error(`Trying to remove ${itemToRemove}`);
@@ -112,7 +111,7 @@ export class Backups {
effects.removeFile({
volumeId: Backups.BACKUP,
path: itemToRemove,
})
}),
)
.catch(() => {
effects.warn(`Failed to remove ${itemToRemove} from backup volume`);
@@ -135,7 +134,7 @@ export class Backups {
})
.wait();
}
return ok;
return;
};
const restoreBackup: T.ExpectedExports.restoreBackup = async ({
effects,
@@ -160,7 +159,7 @@ export class Backups {
})
.wait();
}
return ok;
return;
};
return { createBackup, restoreBackup };
}