@backloghq/opslog 0.7.0 → 0.7.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 +12 -8
  2. package/package.json +1 -1
package/dist/snapshot.js CHANGED
@@ -1,5 +1,5 @@
1
- import { createReadStream } from "node:fs";
2
- import { readFile, rename, writeFile } from "node:fs/promises";
1
+ import { createReadStream, createWriteStream } from "node:fs";
2
+ import { readFile, rename } from "node:fs/promises";
3
3
  import { createInterface } from "node:readline";
4
4
  import { join } from "node:path";
5
5
  import { validateSnapshot } from "./validate.js";
@@ -7,13 +7,17 @@ export async function writeSnapshot(dir, records, version) {
7
7
  const timestamp = new Date().toISOString();
8
8
  const filename = `snap-${Date.now()}.jsonl`;
9
9
  const path = join(dir, "snapshots", filename);
10
- const lines = [];
11
- lines.push(JSON.stringify({ version, timestamp }));
12
- for (const [id, data] of records) {
13
- lines.push(JSON.stringify({ id, data }));
14
- }
10
+ // Stream line-by-line to avoid V8 string limit at large record counts
15
11
  const tmpPath = path + ".tmp";
16
- await writeFile(tmpPath, lines.join("\n") + "\n", "utf-8");
12
+ await new Promise((resolve, reject) => {
13
+ const ws = createWriteStream(tmpPath, "utf-8");
14
+ ws.on("error", reject);
15
+ ws.write(JSON.stringify({ version, timestamp }) + "\n");
16
+ for (const [id, data] of records) {
17
+ ws.write(JSON.stringify({ id, data }) + "\n");
18
+ }
19
+ ws.end(() => resolve());
20
+ });
17
21
  await rename(tmpPath, path);
18
22
  return `snapshots/${filename}`;
19
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backloghq/opslog",
3
- "version": "0.7.0",
3
+ "version": "0.7.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",