@rulvar/store-sqlite 1.25.0 → 1.26.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.
- package/dist/index.d.ts +3 -2
- package/dist/index.js +25 -7
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JournalEntry,
|
|
1
|
+
import { JournalEntry, LeasableStore, Lease, MetaLookupStore, RunFilter, RunMeta } from "@rulvar/core";
|
|
2
2
|
|
|
3
3
|
//#region src/store.d.ts
|
|
4
4
|
/** Appendix A interim reference for the sqlite store. */
|
|
@@ -11,7 +11,7 @@ interface SqliteStoreOptions {
|
|
|
11
11
|
/** Injectable clock for lease-expiry tests. */
|
|
12
12
|
now?: () => number;
|
|
13
13
|
}
|
|
14
|
-
declare class SqliteStore implements
|
|
14
|
+
declare class SqliteStore implements MetaLookupStore, LeasableStore {
|
|
15
15
|
private readonly db;
|
|
16
16
|
private readonly ttlMs;
|
|
17
17
|
private readonly now;
|
|
@@ -23,6 +23,7 @@ declare class SqliteStore implements JournalStore, LeasableStore {
|
|
|
23
23
|
append(runId: string, e: JournalEntry, lease?: Lease): Promise<void>;
|
|
24
24
|
load(runId: string): Promise<JournalEntry[]>;
|
|
25
25
|
putMeta(m: RunMeta): Promise<void>;
|
|
26
|
+
getMeta(runId: string): Promise<RunMeta | undefined>;
|
|
26
27
|
listRuns(f?: RunFilter): Promise<RunMeta[]>;
|
|
27
28
|
delete(runId: string): Promise<void>;
|
|
28
29
|
acquire(runId: string, owner: string): Promise<Lease>;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DatabaseSync } from "node:sqlite";
|
|
2
|
-
import { JournalOrderViolation, LeaseHeldError } from "@rulvar/core";
|
|
2
|
+
import { JournalOrderViolation, LeaseHeldError, metaMatchesFilter } from "@rulvar/core";
|
|
3
3
|
//#region src/store.ts
|
|
4
4
|
/**
|
|
5
5
|
* SqliteStore (M5-T02): JournalStore plus LeasableStore with fencing
|
|
@@ -46,6 +46,10 @@ var SqliteStore = class {
|
|
|
46
46
|
run_id TEXT PRIMARY KEY,
|
|
47
47
|
payload TEXT NOT NULL
|
|
48
48
|
);
|
|
49
|
+
CREATE INDEX IF NOT EXISTS meta_by_status
|
|
50
|
+
ON meta (json_extract(payload, '$.status'));
|
|
51
|
+
CREATE INDEX IF NOT EXISTS meta_by_name
|
|
52
|
+
ON meta (json_extract(payload, '$.name'));
|
|
49
53
|
CREATE TABLE IF NOT EXISTS leases (
|
|
50
54
|
run_id TEXT PRIMARY KEY,
|
|
51
55
|
owner TEXT NOT NULL,
|
|
@@ -85,13 +89,27 @@ var SqliteStore = class {
|
|
|
85
89
|
async putMeta(m) {
|
|
86
90
|
this.db.prepare("INSERT INTO meta (run_id, payload) VALUES (?, ?) ON CONFLICT(run_id) DO UPDATE SET payload = excluded.payload").run(m.runId, JSON.stringify(m));
|
|
87
91
|
}
|
|
92
|
+
async getMeta(runId) {
|
|
93
|
+
const row = this.db.prepare("SELECT payload FROM meta WHERE run_id = ?").get(runId);
|
|
94
|
+
return row === void 0 ? void 0 : JSON.parse(row.payload);
|
|
95
|
+
}
|
|
88
96
|
async listRuns(f) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
const where = [];
|
|
98
|
+
const params = [];
|
|
99
|
+
if (f?.status !== void 0 || f?.statuses !== void 0) {
|
|
100
|
+
const wanted = [...f.status === void 0 ? [] : [f.status], ...f.statuses ?? []];
|
|
101
|
+
if (wanted.length === 0) where.push("1 = 0");
|
|
102
|
+
else {
|
|
103
|
+
where.push(`json_extract(payload, '$.status') IN (${wanted.map(() => "?").join(", ")})`);
|
|
104
|
+
params.push(...wanted);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (f?.name !== void 0) {
|
|
108
|
+
where.push("json_extract(payload, '$.name') = ?");
|
|
109
|
+
params.push(f.name);
|
|
110
|
+
}
|
|
111
|
+
const sql = "SELECT payload FROM meta" + (where.length === 0 ? "" : ` WHERE ${where.join(" AND ")}`) + " ORDER BY run_id";
|
|
112
|
+
return this.db.prepare(sql).all(...params).map((row) => JSON.parse(row.payload)).filter((meta) => metaMatchesFilter(meta, f));
|
|
95
113
|
}
|
|
96
114
|
async delete(runId) {
|
|
97
115
|
this.db.exec("BEGIN IMMEDIATE");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulvar/store-sqlite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.26.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.
|
|
25
|
+
"@rulvar/core": "1.26.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.
|
|
31
|
+
"@rulvar/store-conformance": "1.26.0"
|
|
32
32
|
},
|
|
33
33
|
"repository": {
|
|
34
34
|
"type": "git",
|