@backloghq/opslog 0.1.1 → 0.1.2
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/dist/archive.js +4 -2
- package/dist/manifest.js +4 -3
- package/dist/store.js +1 -1
- package/dist/validate.js +18 -0
- package/package.json +1 -1
package/dist/archive.js
CHANGED
|
@@ -11,8 +11,10 @@ export async function writeArchiveSegment(dir, period, records) {
|
|
|
11
11
|
const parsed = validateArchiveSegment(JSON.parse(content));
|
|
12
12
|
existing = parsed.records;
|
|
13
13
|
}
|
|
14
|
-
catch {
|
|
15
|
-
|
|
14
|
+
catch (err) {
|
|
15
|
+
const isNotFound = err instanceof Error && "code" in err && err.code === "ENOENT";
|
|
16
|
+
if (!isNotFound)
|
|
17
|
+
throw err;
|
|
16
18
|
}
|
|
17
19
|
const merged = { ...existing, ...Object.fromEntries(records) };
|
|
18
20
|
const segment = {
|
package/dist/manifest.js
CHANGED
|
@@ -3,13 +3,14 @@ import { join } from "node:path";
|
|
|
3
3
|
import { validateManifest } from "./validate.js";
|
|
4
4
|
const MANIFEST_FILE = "manifest.json";
|
|
5
5
|
export async function readManifest(dir) {
|
|
6
|
+
let content;
|
|
6
7
|
try {
|
|
7
|
-
|
|
8
|
-
return validateManifest(JSON.parse(content));
|
|
8
|
+
content = await readFile(join(dir, MANIFEST_FILE), "utf-8");
|
|
9
9
|
}
|
|
10
10
|
catch {
|
|
11
|
-
return null;
|
|
11
|
+
return null; // File not found — fresh store
|
|
12
12
|
}
|
|
13
|
+
return validateManifest(JSON.parse(content));
|
|
13
14
|
}
|
|
14
15
|
export async function writeManifest(dir, manifest) {
|
|
15
16
|
const path = join(dir, MANIFEST_FILE);
|
package/dist/store.js
CHANGED
|
@@ -52,7 +52,7 @@ export class Store {
|
|
|
52
52
|
this.activeOpsPath = manifest.activeOps;
|
|
53
53
|
this.created = manifest.stats.created;
|
|
54
54
|
this.archiveSegments = manifest.archiveSegments;
|
|
55
|
-
this.archivedRecordCount = manifest.stats
|
|
55
|
+
this.archivedRecordCount = manifest.stats.archivedRecords;
|
|
56
56
|
// Migrate if needed
|
|
57
57
|
if (storedVersion < this.options.version) {
|
|
58
58
|
for (const [id, record] of this.records) {
|
package/dist/validate.js
CHANGED
|
@@ -23,6 +23,22 @@ export function validateManifest(raw) {
|
|
|
23
23
|
throw new Error("Invalid manifest: missing currentSnapshot");
|
|
24
24
|
if (typeof obj.activeOps !== "string")
|
|
25
25
|
throw new Error("Invalid manifest: missing activeOps");
|
|
26
|
+
if (!Array.isArray(obj.archiveSegments))
|
|
27
|
+
throw new Error("Invalid manifest: archiveSegments must be an array");
|
|
28
|
+
if (typeof obj.stats !== "object" || obj.stats === null || Array.isArray(obj.stats)) {
|
|
29
|
+
throw new Error("Invalid manifest: missing stats");
|
|
30
|
+
}
|
|
31
|
+
const stats = obj.stats;
|
|
32
|
+
if (typeof stats.activeRecords !== "number")
|
|
33
|
+
throw new Error("Invalid manifest: stats.activeRecords must be a number");
|
|
34
|
+
if (typeof stats.archivedRecords !== "number")
|
|
35
|
+
throw new Error("Invalid manifest: stats.archivedRecords must be a number");
|
|
36
|
+
if (typeof stats.opsCount !== "number")
|
|
37
|
+
throw new Error("Invalid manifest: stats.opsCount must be a number");
|
|
38
|
+
if (typeof stats.created !== "string")
|
|
39
|
+
throw new Error("Invalid manifest: stats.created must be a string");
|
|
40
|
+
if (typeof stats.lastCheckpoint !== "string")
|
|
41
|
+
throw new Error("Invalid manifest: stats.lastCheckpoint must be a string");
|
|
26
42
|
return raw;
|
|
27
43
|
}
|
|
28
44
|
export function validateSnapshot(raw) {
|
|
@@ -46,6 +62,8 @@ export function validateArchiveSegment(raw) {
|
|
|
46
62
|
throw new Error("Invalid archive segment: missing version");
|
|
47
63
|
if (typeof obj.period !== "string")
|
|
48
64
|
throw new Error("Invalid archive segment: missing period");
|
|
65
|
+
if (typeof obj.timestamp !== "string")
|
|
66
|
+
throw new Error("Invalid archive segment: missing timestamp");
|
|
49
67
|
if (typeof obj.records !== "object" || obj.records === null || Array.isArray(obj.records)) {
|
|
50
68
|
throw new Error("Invalid archive segment: records must be an object");
|
|
51
69
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backloghq/opslog",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Embedded event-sourced document store. Append-only operation log with immutable snapshots, zero native dependencies.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|