Skip to content

Commit 6f3916e

Browse files
committed
Deduplicate flagged storage entry helpers
(cherry picked from commit e78f103)
1 parent 85f6f54 commit 6f3916e

File tree

3 files changed

+2
-60
lines changed

3 files changed

+2
-60
lines changed

lib/storage.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import {
2121
describeAccountSnapshot as describeAccountSnapshotWithDeps,
2222
statSnapshot as statSnapshotWithDeps,
2323
} from "./storage/account-snapshot.js";
24-
import {
25-
exportAccountsSnapshot,
24+
exportAccountsSnapshot,
2625
importAccountsSnapshot,
2726
} from "./storage/account-port.js";
2827
import { saveAccountsToDisk } from "./storage/account-save.js";

lib/storage/account-port.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AccountStorageV3, FlaggedAccountStorageV1 } from "../storage.js";
1+
import type { AccountStorageV3 } from "../storage.js";
22

33
export async function exportAccountsSnapshot(params: {
44
resolvedPath: string;
@@ -103,35 +103,3 @@ export async function importAccountsSnapshot(params: {
103103
return result;
104104
}
105105

106-
export async function saveFlaggedAccountsEntry(params: {
107-
storage: FlaggedAccountStorageV1;
108-
withStorageLock: <T>(fn: () => Promise<T>) => Promise<T>;
109-
saveUnlocked: (storage: FlaggedAccountStorageV1) => Promise<void>;
110-
}): Promise<void> {
111-
return params.withStorageLock(async () => {
112-
await params.saveUnlocked(params.storage);
113-
});
114-
}
115-
116-
export async function clearFlaggedAccountsEntry(params: {
117-
path: string;
118-
withStorageLock: <T>(fn: () => Promise<T>) => Promise<T>;
119-
markerPath: string;
120-
getBackupPaths: () => Promise<string[]>;
121-
clearFlaggedAccountsOnDisk: (args: {
122-
path: string;
123-
markerPath: string;
124-
backupPaths: string[];
125-
logError: (message: string, details: Record<string, unknown>) => void;
126-
}) => Promise<void>;
127-
logError: (message: string, details: Record<string, unknown>) => void;
128-
}): Promise<void> {
129-
return params.withStorageLock(async () => {
130-
await params.clearFlaggedAccountsOnDisk({
131-
path: params.path,
132-
markerPath: params.markerPath,
133-
backupPaths: await params.getBackupPaths(),
134-
logError: params.logError,
135-
});
136-
});
137-
}

test/account-port.test.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,10 @@
11
import { describe, expect, it, vi } from "vitest";
22
import {
3-
clearFlaggedAccountsEntry,
43
exportAccountsSnapshot,
54
importAccountsSnapshot,
6-
saveFlaggedAccountsEntry,
75
} from "../lib/storage/account-port.js";
86

97
describe("account port helpers", () => {
10-
it("delegates flagged save through storage lock", async () => {
11-
const saveUnlocked = vi.fn(async () => undefined);
12-
await saveFlaggedAccountsEntry({
13-
storage: { version: 1, accounts: [] },
14-
withStorageLock: async (fn) => fn(),
15-
saveUnlocked,
16-
});
17-
expect(saveUnlocked).toHaveBeenCalled();
18-
});
19-
20-
it("delegates flagged clear through storage lock", async () => {
21-
const clearFlaggedAccountsOnDisk = vi.fn(async () => undefined);
22-
await clearFlaggedAccountsEntry({
23-
path: "/tmp/flagged.json",
24-
withStorageLock: async (fn) => fn(),
25-
markerPath: "/tmp/flagged.reset",
26-
getBackupPaths: async () => ["/tmp/flagged.json.bak"],
27-
clearFlaggedAccountsOnDisk,
28-
logError: vi.fn(),
29-
});
30-
expect(clearFlaggedAccountsOnDisk).toHaveBeenCalled();
31-
});
32-
338
it("exports transaction snapshot when active", async () => {
349
const exportAccountsToFile = vi.fn(async () => undefined);
3510
await exportAccountsSnapshot({

0 commit comments

Comments
 (0)