@remit/backend 0.0.52 → 0.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/backfill-list-id.ts +17 -3
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
-
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
3
3
|
import { dirname } from "node:path";
|
|
4
4
|
import { logger } from "@remit/logger-lambda";
|
|
5
5
|
import {
|
|
@@ -29,15 +29,29 @@ const CHECKPOINT_PATH =
|
|
|
29
29
|
process.env.LIST_ID_BACKFILL_CHECKPOINT_PATH ??
|
|
30
30
|
"/data/sqlite/list-id-backfill-checkpoint.json";
|
|
31
31
|
|
|
32
|
+
const isCheckpoint = (value: unknown): value is ListIdBackfillCheckpoint => {
|
|
33
|
+
if (typeof value !== "object" || value === null) return false;
|
|
34
|
+
if (!("accountConfigId" in value)) return false;
|
|
35
|
+
const candidate = value as Record<string, unknown>;
|
|
36
|
+
return (
|
|
37
|
+
typeof candidate.accountConfigId === "string" &&
|
|
38
|
+
(candidate.continuationToken === undefined ||
|
|
39
|
+
typeof candidate.continuationToken === "string")
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
32
43
|
const fileCheckpointStore: ListIdBackfillCheckpointStore = {
|
|
33
44
|
load: async () => {
|
|
34
45
|
if (!existsSync(CHECKPOINT_PATH)) return undefined;
|
|
35
46
|
const raw = await readFile(CHECKPOINT_PATH, "utf8");
|
|
36
|
-
|
|
47
|
+
const parsed: unknown = JSON.parse(raw);
|
|
48
|
+
return isCheckpoint(parsed) ? parsed : undefined;
|
|
37
49
|
},
|
|
38
50
|
save: async (checkpoint) => {
|
|
39
51
|
await mkdir(dirname(CHECKPOINT_PATH), { recursive: true });
|
|
40
|
-
|
|
52
|
+
const staging = `${CHECKPOINT_PATH}.writing`;
|
|
53
|
+
await writeFile(staging, JSON.stringify(checkpoint));
|
|
54
|
+
await rename(staging, CHECKPOINT_PATH);
|
|
41
55
|
},
|
|
42
56
|
clear: async () => {
|
|
43
57
|
await rm(CHECKPOINT_PATH, { force: true });
|