Skip to content

Commit 95cca7b

Browse files
committed
refactor: extract named backup facade
1 parent f50045e commit 95cca7b

3 files changed

Lines changed: 64 additions & 6 deletions

File tree

lib/storage.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
migrateV1ToV3,
5757
type RateLimitStateV3,
5858
} from "./storage/migrations.js";
59+
import { exportNamedBackupEntry } from "./storage/named-backup-entry.js";
5960
import {
6061
collectNamedBackups,
6162
type NamedBackupSummary,
@@ -825,14 +826,13 @@ export async function exportNamedBackup(
825826
name: string,
826827
options?: { force?: boolean },
827828
): Promise<string> {
828-
return exportNamedBackupFile(
829+
return exportNamedBackupEntry({
829830
name,
830-
{
831-
getStoragePath,
832-
exportAccounts,
833-
},
834831
options,
835-
);
832+
exportNamedBackupFile,
833+
getStoragePath,
834+
exportAccounts,
835+
});
836836
}
837837

838838
export function getFlaggedAccountsPath(): string {

lib/storage/named-backup-entry.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export async function exportNamedBackupEntry(params: {
2+
name: string;
3+
options?: { force?: boolean };
4+
exportNamedBackupFile: (
5+
name: string,
6+
deps: {
7+
getStoragePath: () => string;
8+
exportAccounts: (
9+
filePath: string,
10+
force?: boolean,
11+
beforeCommit?: (resolvedPath: string) => Promise<void> | void,
12+
) => Promise<void>;
13+
},
14+
options?: { force?: boolean },
15+
) => Promise<string>;
16+
getStoragePath: () => string;
17+
exportAccounts: (
18+
filePath: string,
19+
force?: boolean,
20+
beforeCommit?: (resolvedPath: string) => Promise<void> | void,
21+
) => Promise<void>;
22+
}): Promise<string> {
23+
return params.exportNamedBackupFile(
24+
params.name,
25+
{
26+
getStoragePath: params.getStoragePath,
27+
exportAccounts: params.exportAccounts,
28+
},
29+
params.options,
30+
);
31+
}

test/named-backup-entry.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { describe, expect, it, vi } from "vitest";
2+
import { exportNamedBackupEntry } from "../lib/storage/named-backup-entry.js";
3+
4+
describe("named backup entry", () => {
5+
it("passes name, deps, and options through to the named backup exporter", async () => {
6+
const exportNamedBackupFile = vi.fn(async () => "/tmp/backup.json");
7+
const exportAccounts = vi.fn(async () => undefined);
8+
9+
const result = await exportNamedBackupEntry({
10+
name: "manual-backup",
11+
options: { force: true },
12+
exportNamedBackupFile,
13+
getStoragePath: () => "/tmp/accounts.json",
14+
exportAccounts,
15+
});
16+
17+
expect(exportNamedBackupFile).toHaveBeenCalledWith(
18+
"manual-backup",
19+
{
20+
getStoragePath: expect.any(Function),
21+
exportAccounts,
22+
},
23+
{ force: true },
24+
);
25+
expect(result).toBe("/tmp/backup.json");
26+
});
27+
});

0 commit comments

Comments
 (0)