@rulvar/store-sqlite 1.10.0 → 1.12.0

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/index.js +8 -2
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { DatabaseSync } from "node:sqlite";
2
- import { LeaseHeldError } from "@rulvar/core";
2
+ import { JournalOrderViolation, LeaseHeldError } from "@rulvar/core";
3
3
  //#region src/store.ts
4
4
  /**
5
5
  * SqliteStore (M5-T02): JournalStore plus LeasableStore with fencing
@@ -39,6 +39,8 @@ var SqliteStore = class {
39
39
  payload TEXT NOT NULL
40
40
  );
41
41
  CREATE INDEX IF NOT EXISTS entries_by_run ON entries (run_id, id);
42
+ CREATE INDEX IF NOT EXISTS entries_run_seq
43
+ ON entries (run_id, CAST(json_extract(payload, '$.seq') AS INTEGER));
42
44
  CREATE TABLE IF NOT EXISTS meta (
43
45
  run_id TEXT PRIMARY KEY,
44
46
  payload TEXT NOT NULL
@@ -70,7 +72,11 @@ var SqliteStore = class {
70
72
  }
71
73
  async append(runId, e, lease) {
72
74
  if (lease !== void 0) this.assertFencing(lease);
73
- this.db.prepare("INSERT INTO entries (run_id, payload) VALUES (?, ?)").run(runId, JSON.stringify(e));
75
+ if (!Number.isFinite(e.seq)) {
76
+ this.db.prepare("INSERT INTO entries (run_id, payload) VALUES (?, ?)").run(runId, JSON.stringify(e));
77
+ return;
78
+ }
79
+ if (this.db.prepare("INSERT INTO entries (run_id, payload) SELECT ?, ? WHERE NOT EXISTS (SELECT 1 FROM entries WHERE run_id = ? AND CAST(json_extract(payload, '$.seq') AS INTEGER) >= ?)").run(runId, JSON.stringify(e), runId, e.seq).changes === 0) throw new JournalOrderViolation(`SqliteStore: append of seq ${e.seq} to run '${runId}' is not after the stored tail seq; a concurrent writer raced this journal from a stale tail`);
74
80
  }
75
81
  async load(runId) {
76
82
  return this.db.prepare("SELECT payload FROM entries WHERE run_id = ? ORDER BY id").all(runId).map((row) => JSON.parse(row.payload));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulvar/store-sqlite",
3
- "version": "1.10.0",
3
+ "version": "1.12.0",
4
4
  "description": "Rulvar SQLite store implementing JournalStore and LeasableStore with a fencing epoch.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -22,13 +22,13 @@
22
22
  "access": "public"
23
23
  },
24
24
  "dependencies": {
25
- "@rulvar/core": "1.10.0"
25
+ "@rulvar/core": "1.12.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^22.20.0",
29
29
  "tsdown": "^0.22.3",
30
30
  "typescript": "~6.0.3",
31
- "@rulvar/store-conformance": "1.10.0"
31
+ "@rulvar/store-conformance": "1.12.0"
32
32
  },
33
33
  "repository": {
34
34
  "type": "git",