@backloghq/opslog 0.8.0 → 0.8.1

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.
Files changed (2) hide show
  1. package/dist/snapshot.js +20 -3
  2. package/package.json +1 -1
package/dist/snapshot.js CHANGED
@@ -27,9 +27,19 @@ export async function loadSnapshot(dir, relativePath) {
27
27
  // Detect format: JSONL (first line is header without "records" key) vs legacy JSON
28
28
  const firstNewline = content.indexOf("\n");
29
29
  const firstLine = firstNewline === -1 ? content : content.slice(0, firstNewline);
30
- const parsed = JSON.parse(firstLine);
30
+ let parsed;
31
+ try {
32
+ parsed = JSON.parse(firstLine);
33
+ }
34
+ catch {
35
+ // First line isn't valid JSON (e.g., pretty-printed legacy JSON starts with "{")
36
+ // Fall back to parsing the full content as legacy JSON
37
+ const snapshot = validateSnapshot(JSON.parse(content));
38
+ const records = new Map(Object.entries(snapshot.records));
39
+ return { records, version: snapshot.version };
40
+ }
31
41
  if ("records" in parsed) {
32
- // Legacy monolithic JSON format
42
+ // Legacy monolithic JSON format (single-line)
33
43
  const snapshot = validateSnapshot(parsed);
34
44
  const records = new Map(Object.entries(snapshot.records));
35
45
  return { records, version: snapshot.version };
@@ -58,7 +68,14 @@ export async function* streamSnapshotFile(dir, relativePath) {
58
68
  const content = await readFile(path, "utf-8");
59
69
  const firstNewline = content.indexOf("\n");
60
70
  const firstLine = firstNewline === -1 ? content : content.slice(0, firstNewline);
61
- const parsed = JSON.parse(firstLine);
71
+ let parsed;
72
+ try {
73
+ parsed = JSON.parse(firstLine);
74
+ }
75
+ catch {
76
+ // Pretty-printed legacy JSON — first line isn't valid JSON
77
+ parsed = JSON.parse(content);
78
+ }
62
79
  if ("records" in parsed) {
63
80
  // Legacy JSON: must load all, then yield
64
81
  const snapshot = validateSnapshot(parsed);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backloghq/opslog",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
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",