@rotorsoft/act-sqlite 2.0.2 → 2.1.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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/sqlite-store.d.ts +0 -37
- package/dist/@types/sqlite-store.d.ts.map +1 -1
- package/dist/@types/stream-glob.d.ts +37 -0
- package/dist/@types/stream-glob.d.ts.map +1 -0
- package/dist/index.cjs +59 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +59 -57
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -59,43 +59,6 @@ export interface SqliteConfig {
|
|
|
59
59
|
*/
|
|
60
60
|
pii_encryption?: Encryption;
|
|
61
61
|
}
|
|
62
|
-
/** Translate a stream filter (regex-shaped or plain substring) into a
|
|
63
|
-
* SQLite `GLOB` pattern.
|
|
64
|
-
*
|
|
65
|
-
* `GLOB` — not `LIKE` — because `GLOB` is **case-sensitive**,
|
|
66
|
-
* matching PG's `~` and InMemory's `RegExp`. SQLite's `LIKE` is ASCII
|
|
67
|
-
* case-insensitive, and its per-connection `PRAGMA case_sensitive_like`
|
|
68
|
-
* override is unreliable under libsql's pooled connections (a
|
|
69
|
-
* transaction and a follow-up read can land on different connections).
|
|
70
|
-
* `GLOB` carries its case-sensitivity in the operator itself, so it is
|
|
71
|
-
* correct regardless of which pooled connection runs the statement.
|
|
72
|
-
*
|
|
73
|
-
* Honors `^` / `$` anchors and converts `.*` → `*`, `.` → `?`.
|
|
74
|
-
* Unanchored input gets `*` wildcards on both sides. `GLOB` has no
|
|
75
|
-
* ESCAPE clause and `%` / `_` are ordinary literals under it — so no
|
|
76
|
-
* escaping is needed. The portable grammar rejects `*`, `?`, and `[`
|
|
77
|
-
* as literals (they are metacharacters), so a literal can never collide
|
|
78
|
-
* with a `GLOB` wildcard.
|
|
79
|
-
*
|
|
80
|
-
* Only the portable filter grammar documented on
|
|
81
|
-
* {@link QueryStreams.stream} is convertible: `^` / `$` anchors, `.`,
|
|
82
|
-
* `.*`, and literal characters. Any richer regex syntax throws
|
|
83
|
-
* {@link ValidationError} — a lossy approximation would silently
|
|
84
|
-
* return wrong rows, the worst available failure mode when the filter
|
|
85
|
-
* drives `reset` / `unblock`.
|
|
86
|
-
*
|
|
87
|
-
* Examples:
|
|
88
|
-
* - `^abc$` → `abc` (exact)
|
|
89
|
-
* - `^abc.*` → `abc*` (starts-with)
|
|
90
|
-
* - `.*abc$` → `*abc` (ends-with)
|
|
91
|
-
* - `abc` → `*abc*` (contains)
|
|
92
|
-
* - `a.c` → `*a?c*` (single-char wildcard, contains)
|
|
93
|
-
* - `^a_c$` → `a_c` (literal underscore — ordinary under GLOB)
|
|
94
|
-
* - `(a|b)` → throws {@link ValidationError}
|
|
95
|
-
*
|
|
96
|
-
* @internal exported for testing
|
|
97
|
-
*/
|
|
98
|
-
export declare function streamPatternToGlob(input: string): string;
|
|
99
62
|
/**
|
|
100
63
|
* SQLite event store adapter for [@rotorsoft/act](https://www.npmjs.com/package/@rotorsoft/act).
|
|
101
64
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-store.d.ts","sourceRoot":"","sources":["../../src/sqlite-store.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,MAAM,EACN,YAAY,EACZ,SAAS,EACT,SAAS,EACT,KAAK,EACL,KAAK,EACL,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,OAAO,EACP,KAAK,EACL,YAAY,EACZ,cAAc,EACd,WAAW,EACX,cAAc,EACd,eAAe,EAChB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"sqlite-store.d.ts","sourceRoot":"","sources":["../../src/sqlite-store.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,MAAM,EACN,YAAY,EACZ,SAAS,EACT,SAAS,EACT,KAAK,EACL,KAAK,EACL,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,OAAO,EACP,KAA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AM,GAAG,OAAO,CAAC,MAAM,CAAC,CAQlE;IAMK,QAAQ,CACZ,OAAO,EAAE,KAAK,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACnC,IAAI,CAAC,EAAE,SAAS,CAAC;QACjB,MAAM,CAAC,EAAE,IAAI,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;iBAKW,MAAM;mBACJ,SAAS,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC;iBACnC,IAAI;QA6ElB;IAED;;;;;;;;;;OAUG;IAGG,OAAO,CACX,MAAM,EAAE,CACN,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,OAAO,EAAE,MAAM,OAAO,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,KACpE,OAAO,CAAC,IAAI,CAAC,GACjB,OAAO,CAAC,IAAI,CAAC,CAqCf;IAED;;;;;;;;;;;;;;;;OAgBG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAMhD;CACF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Translate a stream filter (regex-shaped or plain substring) into a
|
|
2
|
+
* SQLite `GLOB` pattern.
|
|
3
|
+
*
|
|
4
|
+
* `GLOB` — not `LIKE` — because `GLOB` is **case-sensitive**,
|
|
5
|
+
* matching PG's `~` and InMemory's `RegExp`. SQLite's `LIKE` is ASCII
|
|
6
|
+
* case-insensitive, and its per-connection `PRAGMA case_sensitive_like`
|
|
7
|
+
* override is unreliable under libsql's pooled connections (a
|
|
8
|
+
* transaction and a follow-up read can land on different connections).
|
|
9
|
+
* `GLOB` carries its case-sensitivity in the operator itself, so it is
|
|
10
|
+
* correct regardless of which pooled connection runs the statement.
|
|
11
|
+
*
|
|
12
|
+
* Honors `^` / `$` anchors and converts `.*` → `*`, `.` → `?`.
|
|
13
|
+
* Unanchored input gets `*` wildcards on both sides. `GLOB` has no
|
|
14
|
+
* ESCAPE clause and `%` / `_` are ordinary literals under it — so no
|
|
15
|
+
* escaping is needed. The portable grammar rejects `*`, `?`, and `[`
|
|
16
|
+
* as literals (they are metacharacters), so a literal can never collide
|
|
17
|
+
* with a `GLOB` wildcard.
|
|
18
|
+
*
|
|
19
|
+
* Only the portable filter grammar documented on
|
|
20
|
+
* {@link QueryStreams.stream} is convertible: `^` / `$` anchors, `.`,
|
|
21
|
+
* `.*`, and literal characters. Any richer regex syntax throws
|
|
22
|
+
* {@link ValidationError} — a lossy approximation would silently
|
|
23
|
+
* return wrong rows, the worst available failure mode when the filter
|
|
24
|
+
* drives `reset` / `unblock`.
|
|
25
|
+
*
|
|
26
|
+
* Examples:
|
|
27
|
+
* - `^abc$` → `abc` (exact)
|
|
28
|
+
* - `^abc.*` → `abc*` (starts-with)
|
|
29
|
+
* - `.*abc$` → `*abc` (ends-with)
|
|
30
|
+
* - `abc` → `*abc*` (contains)
|
|
31
|
+
* - `a.c` → `*a?c*` (single-char wildcard, contains)
|
|
32
|
+
* - `^a_c$` → `a_c` (literal underscore — ordinary under GLOB)
|
|
33
|
+
* - `(a|b)` → throws {@link ValidationError}
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
export declare function stream_glob(input: string): string;
|
|
37
|
+
//# sourceMappingURL=stream-glob.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-glob.d.ts","sourceRoot":"","sources":["../../src/stream-glob.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAmCjD"}
|
package/dist/index.cjs
CHANGED
|
@@ -20,49 +20,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
SqliteStore: () => SqliteStore
|
|
24
|
-
streamPatternToGlob: () => streamPatternToGlob
|
|
23
|
+
SqliteStore: () => SqliteStore
|
|
25
24
|
});
|
|
26
25
|
module.exports = __toCommonJS(index_exports);
|
|
27
26
|
|
|
28
27
|
// src/sqlite-store.ts
|
|
29
28
|
var import_client = require("@libsql/client");
|
|
30
|
-
var
|
|
29
|
+
var import_act2 = require("@rotorsoft/act");
|
|
30
|
+
var import_adapter = require("@rotorsoft/act/adapter");
|
|
31
|
+
var import_types = require("@rotorsoft/act/types");
|
|
31
32
|
var import_act_crypto = require("@rotorsoft/act-crypto");
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
var
|
|
35
|
-
if (typeof url !== "string" || url.trim().length === 0)
|
|
36
|
-
throw new import_act.ValidationError(
|
|
37
|
-
'SqliteStore config \u2014 "url" is required and has no default. Use a file database ("file:myapp.db"), a remote libSQL server ("libsql://\u2026" plus authToken), or ":memory:" for a process-wide shared in-memory database. For isolated throwaway state, prefer InMemoryStore from @rotorsoft/act',
|
|
38
|
-
{ url },
|
|
39
|
-
"missing url"
|
|
40
|
-
);
|
|
41
|
-
if (url.startsWith("file::memory:?") && url.includes("cache=private"))
|
|
42
|
-
throw new import_act.ValidationError(
|
|
43
|
-
'SqliteStore config \u2014 a private in-memory database ("cache=private") cannot back a store: libSQL gives each connection its own database, so writes are accepted and then lost on the next statement. Use ":memory:" for the shared-cache database, a "file:" path, or InMemoryStore from @rotorsoft/act',
|
|
44
|
-
{ url },
|
|
45
|
-
"private in-memory url"
|
|
46
|
-
);
|
|
47
|
-
return is_in_memory_url(url) ? SHARED_MEMORY_URL : url;
|
|
48
|
-
};
|
|
49
|
-
var parse_json = (raw) => JSON.parse(raw);
|
|
50
|
-
var to_committed = (row, prefix = "") => ({
|
|
51
|
-
id: Number(row[`${prefix}id`]),
|
|
52
|
-
stream: row[`${prefix}stream`],
|
|
53
|
-
version: Number(row[`${prefix}version`]),
|
|
54
|
-
created: new Date(row[`${prefix}created`]),
|
|
55
|
-
name: row[`${prefix}name`],
|
|
56
|
-
data: parse_json(row[`${prefix}data`]),
|
|
57
|
-
meta: parse_json(row[`${prefix}meta`])
|
|
58
|
-
});
|
|
59
|
-
var SQLITE_CONSTRAINT_UNIQUE = 2067;
|
|
60
|
-
var is_unique_violation = (e) => {
|
|
61
|
-
const err = e;
|
|
62
|
-
return err?.rawCode === SQLITE_CONSTRAINT_UNIQUE || typeof err?.message === "string" && err.message.includes("UNIQUE constraint failed");
|
|
63
|
-
};
|
|
33
|
+
|
|
34
|
+
// src/stream-glob.ts
|
|
35
|
+
var import_act = require("@rotorsoft/act");
|
|
64
36
|
var PORTABLE_BODY = /^(?:\.\*|\.|[^\\^$.()[\]{}|+?*])*$/;
|
|
65
|
-
function
|
|
37
|
+
function stream_glob(input) {
|
|
66
38
|
let s = input;
|
|
67
39
|
const start = s.startsWith("^");
|
|
68
40
|
const end = s.endsWith("$");
|
|
@@ -95,6 +67,40 @@ function streamPatternToGlob(input) {
|
|
|
95
67
|
}
|
|
96
68
|
return out;
|
|
97
69
|
}
|
|
70
|
+
|
|
71
|
+
// src/sqlite-store.ts
|
|
72
|
+
var SHARED_MEMORY_URL = "file::memory:?cache=shared";
|
|
73
|
+
var is_in_memory_url = (url) => url === ":memory:" || url === "file::memory:" || url.startsWith("file::memory:?");
|
|
74
|
+
var resolve_url = (url) => {
|
|
75
|
+
if (typeof url !== "string" || url.trim().length === 0)
|
|
76
|
+
throw new import_act2.ValidationError(
|
|
77
|
+
'SqliteStore config \u2014 "url" is required and has no default. Use a file database ("file:myapp.db"), a remote libSQL server ("libsql://\u2026" plus authToken), or ":memory:" for a process-wide shared in-memory database. For isolated throwaway state, prefer InMemoryStore from @rotorsoft/act',
|
|
78
|
+
{ url },
|
|
79
|
+
"missing url"
|
|
80
|
+
);
|
|
81
|
+
if (url.startsWith("file::memory:?") && url.includes("cache=private"))
|
|
82
|
+
throw new import_act2.ValidationError(
|
|
83
|
+
'SqliteStore config \u2014 a private in-memory database ("cache=private") cannot back a store: libSQL gives each connection its own database, so writes are accepted and then lost on the next statement. Use ":memory:" for the shared-cache database, a "file:" path, or InMemoryStore from @rotorsoft/act',
|
|
84
|
+
{ url },
|
|
85
|
+
"private in-memory url"
|
|
86
|
+
);
|
|
87
|
+
return is_in_memory_url(url) ? SHARED_MEMORY_URL : url;
|
|
88
|
+
};
|
|
89
|
+
var parse_json = (raw) => JSON.parse(raw);
|
|
90
|
+
var to_committed = (row, prefix = "") => ({
|
|
91
|
+
id: Number(row[`${prefix}id`]),
|
|
92
|
+
stream: row[`${prefix}stream`],
|
|
93
|
+
version: Number(row[`${prefix}version`]),
|
|
94
|
+
created: new Date(row[`${prefix}created`]),
|
|
95
|
+
name: row[`${prefix}name`],
|
|
96
|
+
data: parse_json(row[`${prefix}data`]),
|
|
97
|
+
meta: parse_json(row[`${prefix}meta`])
|
|
98
|
+
});
|
|
99
|
+
var SQLITE_CONSTRAINT_UNIQUE = 2067;
|
|
100
|
+
var is_unique_violation = (e) => {
|
|
101
|
+
const err = e;
|
|
102
|
+
return err?.rawCode === SQLITE_CONSTRAINT_UNIQUE || typeof err?.message === "string" && err.message.includes("UNIQUE constraint failed");
|
|
103
|
+
};
|
|
98
104
|
var SqliteStore = class {
|
|
99
105
|
client;
|
|
100
106
|
// Memoized key resolver for the optional `pii_encryption` envelope.
|
|
@@ -273,7 +279,7 @@ var SqliteStore = class {
|
|
|
273
279
|
// Opens a write transaction: a BEGIN that fails is a {@link StoreError} too.
|
|
274
280
|
_begin(operation) {
|
|
275
281
|
return this.client.transaction("write").catch((e) => {
|
|
276
|
-
throw new
|
|
282
|
+
throw new import_act2.StoreError(operation, { cause: e });
|
|
277
283
|
});
|
|
278
284
|
}
|
|
279
285
|
// One write transaction, in its turn: any failure rolls back and throws a {@link StoreError} naming the operation.
|
|
@@ -286,7 +292,7 @@ var SqliteStore = class {
|
|
|
286
292
|
return result;
|
|
287
293
|
} catch (e) {
|
|
288
294
|
await tx.rollback();
|
|
289
|
-
throw new
|
|
295
|
+
throw new import_act2.StoreError(operation, { cause: e });
|
|
290
296
|
}
|
|
291
297
|
});
|
|
292
298
|
}
|
|
@@ -295,7 +301,7 @@ var SqliteStore = class {
|
|
|
295
301
|
}
|
|
296
302
|
// --- commit: one transaction across every append ---
|
|
297
303
|
async commit(appends, meta) {
|
|
298
|
-
(0,
|
|
304
|
+
(0, import_adapter.checkAppends)(appends);
|
|
299
305
|
if (!appends.length) return [];
|
|
300
306
|
return this._serial(async () => {
|
|
301
307
|
const tx = await this._begin("commit");
|
|
@@ -309,7 +315,7 @@ var SqliteStore = class {
|
|
|
309
315
|
args: [append.stream]
|
|
310
316
|
});
|
|
311
317
|
const current = Number(row.rows[0].v);
|
|
312
|
-
(0,
|
|
318
|
+
(0, import_adapter.checkVersion)(append, current);
|
|
313
319
|
heads.set(append.stream, current);
|
|
314
320
|
}
|
|
315
321
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -349,9 +355,9 @@ var SqliteStore = class {
|
|
|
349
355
|
return committed;
|
|
350
356
|
} catch (e) {
|
|
351
357
|
await tx.rollback();
|
|
352
|
-
if (e instanceof
|
|
353
|
-
if (is_unique_violation(e)) throw (0,
|
|
354
|
-
throw new
|
|
358
|
+
if (e instanceof import_act2.ConcurrencyError) throw e;
|
|
359
|
+
if (is_unique_violation(e)) throw (0, import_adapter.concurrencyError)(appending, head);
|
|
360
|
+
throw new import_act2.StoreError("commit", { cause: e });
|
|
355
361
|
}
|
|
356
362
|
});
|
|
357
363
|
}
|
|
@@ -365,7 +371,7 @@ var SqliteStore = class {
|
|
|
365
371
|
args.push(query.stream);
|
|
366
372
|
} else {
|
|
367
373
|
sql += " AND stream GLOB ?";
|
|
368
|
-
args.push(
|
|
374
|
+
args.push(stream_glob(query.stream));
|
|
369
375
|
}
|
|
370
376
|
}
|
|
371
377
|
if (query?.names !== void 0) {
|
|
@@ -423,8 +429,8 @@ var SqliteStore = class {
|
|
|
423
429
|
// through `prioritize()` instead.
|
|
424
430
|
async subscribe(streams, correlated_at, correlator) {
|
|
425
431
|
for (const { stream, source } of streams) {
|
|
426
|
-
if (source !== void 0 && !(0,
|
|
427
|
-
|
|
432
|
+
if (source !== void 0 && !(0, import_adapter.isStreamName)(source, stream))
|
|
433
|
+
stream_glob(source);
|
|
428
434
|
}
|
|
429
435
|
return this._tx("subscribe", async (tx) => {
|
|
430
436
|
let subscribed = 0;
|
|
@@ -557,7 +563,7 @@ var SqliteStore = class {
|
|
|
557
563
|
priority: Number(row.priority),
|
|
558
564
|
lane: row.lane
|
|
559
565
|
})).sort((a, b) => b.priority - a.priority || a.at - b.at);
|
|
560
|
-
const fair = (0,
|
|
566
|
+
const fair = (0, import_adapter.fairSlots)(lagging);
|
|
561
567
|
const priority_slice = candidates.slice(0, lagging - fair);
|
|
562
568
|
const picked = new Set(priority_slice.map((c) => c.stream));
|
|
563
569
|
const fair_slice = [...candidates].sort((a, b) => a.at - b.at).filter((c) => !picked.has(c.stream)).slice(0, fair);
|
|
@@ -715,7 +721,7 @@ var SqliteStore = class {
|
|
|
715
721
|
args.push(filter.stream);
|
|
716
722
|
} else {
|
|
717
723
|
conditions.push("stream GLOB ?");
|
|
718
|
-
args.push(
|
|
724
|
+
args.push(stream_glob(filter.stream));
|
|
719
725
|
}
|
|
720
726
|
}
|
|
721
727
|
if (filter.source !== void 0) {
|
|
@@ -725,7 +731,7 @@ var SqliteStore = class {
|
|
|
725
731
|
args.push(filter.source);
|
|
726
732
|
} else {
|
|
727
733
|
conditions.push("source GLOB ?");
|
|
728
|
-
args.push(
|
|
734
|
+
args.push(stream_glob(filter.source));
|
|
729
735
|
}
|
|
730
736
|
}
|
|
731
737
|
if (filter.blocked !== void 0) {
|
|
@@ -764,7 +770,7 @@ var SqliteStore = class {
|
|
|
764
770
|
}
|
|
765
771
|
// --- query_streams: read-only introspection with filters ---
|
|
766
772
|
async query_streams(callback, query) {
|
|
767
|
-
const limit = query?.limit ??
|
|
773
|
+
const limit = query?.limit ?? import_types.DEFAULT_QUERY_STREAMS_LIMIT;
|
|
768
774
|
const { clause, args } = this._filter_clause(query ?? {});
|
|
769
775
|
let sql = `SELECT stream, source, at, retry, blocked, error, leased_by, leased_until, priority, lane, deferred_at, correlated_at FROM streams WHERE ${clause}`;
|
|
770
776
|
if (query?.after !== void 0) {
|
|
@@ -848,7 +854,7 @@ var SqliteStore = class {
|
|
|
848
854
|
args.push(input.stream);
|
|
849
855
|
} else {
|
|
850
856
|
where.push(`e.stream GLOB ?`);
|
|
851
|
-
args.push(
|
|
857
|
+
args.push(stream_glob(input.stream));
|
|
852
858
|
}
|
|
853
859
|
}
|
|
854
860
|
if (exclude.length) {
|
|
@@ -1039,7 +1045,7 @@ var SqliteStore = class {
|
|
|
1039
1045
|
sql: "DELETE FROM events WHERE stream = ?",
|
|
1040
1046
|
args: [stream]
|
|
1041
1047
|
});
|
|
1042
|
-
const seed = (0,
|
|
1048
|
+
const seed = (0, import_adapter.seedEvent)(snapshot, meta);
|
|
1043
1049
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1044
1050
|
const ins = await tx.execute({
|
|
1045
1051
|
sql: "INSERT INTO events (stream, version, name, data, meta, created) VALUES (?, 0, ?, ?, ?, ?)",
|
|
@@ -1136,7 +1142,6 @@ var SqliteStore = class {
|
|
|
1136
1142
|
};
|
|
1137
1143
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1138
1144
|
0 && (module.exports = {
|
|
1139
|
-
SqliteStore
|
|
1140
|
-
streamPatternToGlob
|
|
1145
|
+
SqliteStore
|
|
1141
1146
|
});
|
|
1142
1147
|
//# sourceMappingURL=index.cjs.map
|