@backloghq/opslog 0.1.2 → 0.1.3
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/README.md +2 -0
- package/dist/store.js +13 -1
- package/dist/validate.js +11 -6
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/store.js
CHANGED
|
@@ -46,7 +46,18 @@ export class Store {
|
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
48
|
// Load existing state
|
|
49
|
-
|
|
49
|
+
let snapshotData;
|
|
50
|
+
try {
|
|
51
|
+
snapshotData = await loadSnapshot(dir, manifest.currentSnapshot);
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
const isNotFound = err instanceof Error && "code" in err && err.code === "ENOENT";
|
|
55
|
+
if (isNotFound) {
|
|
56
|
+
throw new Error(`Snapshot file not found: ${manifest.currentSnapshot}. The data directory may be corrupted.`, { cause: err });
|
|
57
|
+
}
|
|
58
|
+
throw err;
|
|
59
|
+
}
|
|
60
|
+
const { records, version: storedVersion } = snapshotData;
|
|
50
61
|
this.records = records;
|
|
51
62
|
this.version = storedVersion;
|
|
52
63
|
this.activeOpsPath = manifest.activeOps;
|
|
@@ -154,6 +165,7 @@ export class Store {
|
|
|
154
165
|
this.batchOps = [];
|
|
155
166
|
try {
|
|
156
167
|
fn();
|
|
168
|
+
// Empty batches are no-ops — no I/O if fn() didn't call set/delete
|
|
157
169
|
if (this.batchOps.length > 0) {
|
|
158
170
|
await appendOps(join(this.dir, this.activeOpsPath), this.batchOps);
|
|
159
171
|
this.ops.push(...this.batchOps);
|
package/dist/validate.js
CHANGED
|
@@ -17,8 +17,9 @@ export function validateManifest(raw) {
|
|
|
17
17
|
throw new Error("Invalid manifest: not an object");
|
|
18
18
|
}
|
|
19
19
|
const obj = raw;
|
|
20
|
-
if (typeof obj.version !== "number")
|
|
21
|
-
throw new Error("Invalid manifest:
|
|
20
|
+
if (typeof obj.version !== "number" || !Number.isInteger(obj.version) || obj.version < 1) {
|
|
21
|
+
throw new Error("Invalid manifest: version must be a positive integer");
|
|
22
|
+
}
|
|
22
23
|
if (typeof obj.currentSnapshot !== "string")
|
|
23
24
|
throw new Error("Invalid manifest: missing currentSnapshot");
|
|
24
25
|
if (typeof obj.activeOps !== "string")
|
|
@@ -46,8 +47,11 @@ export function validateSnapshot(raw) {
|
|
|
46
47
|
throw new Error("Invalid snapshot: not an object");
|
|
47
48
|
}
|
|
48
49
|
const obj = raw;
|
|
49
|
-
if (typeof obj.version !== "number")
|
|
50
|
-
throw new Error("Invalid snapshot:
|
|
50
|
+
if (typeof obj.version !== "number" || !Number.isInteger(obj.version) || obj.version < 1) {
|
|
51
|
+
throw new Error("Invalid snapshot: version must be a positive integer");
|
|
52
|
+
}
|
|
53
|
+
if (typeof obj.timestamp !== "string")
|
|
54
|
+
throw new Error("Invalid snapshot: missing timestamp");
|
|
51
55
|
if (typeof obj.records !== "object" || obj.records === null || Array.isArray(obj.records)) {
|
|
52
56
|
throw new Error("Invalid snapshot: records must be an object");
|
|
53
57
|
}
|
|
@@ -58,8 +62,9 @@ export function validateArchiveSegment(raw) {
|
|
|
58
62
|
throw new Error("Invalid archive segment: not an object");
|
|
59
63
|
}
|
|
60
64
|
const obj = raw;
|
|
61
|
-
if (typeof obj.version !== "number")
|
|
62
|
-
throw new Error("Invalid archive segment:
|
|
65
|
+
if (typeof obj.version !== "number" || !Number.isInteger(obj.version) || obj.version < 1) {
|
|
66
|
+
throw new Error("Invalid archive segment: version must be a positive integer");
|
|
67
|
+
}
|
|
63
68
|
if (typeof obj.period !== "string")
|
|
64
69
|
throw new Error("Invalid archive segment: missing period");
|
|
65
70
|
if (typeof obj.timestamp !== "string")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backloghq/opslog",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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",
|