Skip to content

Commit 201bc0d

Browse files
committed
refactor: extract named backups facade
1 parent c1b0ddf commit 201bc0d

3 files changed

Lines changed: 66 additions & 1 deletion

File tree

lib/storage.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {
5757
collectNamedBackups,
5858
type NamedBackupSummary,
5959
} from "./storage/named-backups.js";
60+
import { getNamedBackupsEntry } from "./storage/named-backups-entry.js";
6061
import {
6162
findProjectRoot,
6263
getConfigDir,
@@ -789,7 +790,9 @@ export function buildNamedBackupPath(name: string): string {
789790
}
790791

791792
export async function getNamedBackups(): Promise<NamedBackupSummary[]> {
792-
return collectNamedBackups(getStoragePath(), {
793+
return getNamedBackupsEntry({
794+
getStoragePath,
795+
collectNamedBackups,
793796
loadAccountsFromPath: (path) =>
794797
loadAccountsFromPath(path, {
795798
normalizeAccountStorage,

lib/storage/named-backups-entry.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { NamedBackupSummary } from "../storage.js";
2+
3+
export async function getNamedBackupsEntry(params: {
4+
getStoragePath: () => string;
5+
collectNamedBackups: (
6+
storagePath: string,
7+
deps: {
8+
loadAccountsFromPath: (
9+
path: string,
10+
) => Promise<{ normalized: { accounts: unknown[] } | null }>;
11+
logDebug: (message: string, details: Record<string, unknown>) => void;
12+
},
13+
) => Promise<NamedBackupSummary[]>;
14+
loadAccountsFromPath: (
15+
path: string,
16+
) => Promise<{ normalized: { accounts: unknown[] } | null }>;
17+
logDebug: (message: string, details: Record<string, unknown>) => void;
18+
}): Promise<NamedBackupSummary[]> {
19+
return params.collectNamedBackups(params.getStoragePath(), {
20+
loadAccountsFromPath: params.loadAccountsFromPath,
21+
logDebug: params.logDebug,
22+
});
23+
}

test/named-backups-entry.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { describe, expect, it, vi } from "vitest";
2+
import { getNamedBackupsEntry } from "../lib/storage/named-backups-entry.js";
3+
4+
describe("named backups entry", () => {
5+
it("delegates to collectNamedBackups with resolved storage path and deps", async () => {
6+
const collectNamedBackups = vi.fn(async () => [
7+
{
8+
path: "/tmp/backup.json",
9+
fileName: "backup.json",
10+
accountCount: 1,
11+
mtimeMs: 1,
12+
},
13+
]);
14+
const loadAccountsFromPath = vi.fn(async () => ({
15+
normalized: { accounts: [] },
16+
}));
17+
const logDebug = vi.fn();
18+
19+
const result = await getNamedBackupsEntry({
20+
getStoragePath: () => "/tmp/accounts.json",
21+
collectNamedBackups,
22+
loadAccountsFromPath,
23+
logDebug,
24+
});
25+
26+
expect(collectNamedBackups).toHaveBeenCalledWith("/tmp/accounts.json", {
27+
loadAccountsFromPath,
28+
logDebug,
29+
});
30+
expect(result).toEqual([
31+
{
32+
path: "/tmp/backup.json",
33+
fileName: "backup.json",
34+
accountCount: 1,
35+
mtimeMs: 1,
36+
},
37+
]);
38+
});
39+
});

0 commit comments

Comments
 (0)