@northtalk/ts 0.0.0-stage → 0.2.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 (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -2
  3. package/UNICODE-LICENSE.txt +39 -0
  4. package/base64-DORMd3Hv.js +6621 -0
  5. package/binary-value-CEmh60GC.d.ts +15 -0
  6. package/capabilities-CH0FkRMq.js +1301 -0
  7. package/checker-Dc1jl2WH.js +6657 -0
  8. package/core-DptnvQT9.d.ts +14 -0
  9. package/debug-CQBxKnJB.d.ts +3065 -0
  10. package/debug.d.ts +3 -0
  11. package/debug.js +2 -0
  12. package/driver.d.ts +41 -0
  13. package/driver.js +152 -0
  14. package/encoding-nlrpj-Pb.js +99 -0
  15. package/engine-BGaJ9dAk.js +326 -0
  16. package/engine-vbYInVYF.d.ts +86 -0
  17. package/errors-LYJZ_c8h.js +3735 -0
  18. package/group-B742gg4T.js +10170 -0
  19. package/http-capability-CSTkw1Yt.js +728 -0
  20. package/http.d.ts +59 -0
  21. package/http.js +465 -0
  22. package/index.d.ts +651 -0
  23. package/index.js +44 -0
  24. package/manifest-BscyH_rW.d.ts +70 -0
  25. package/manifest-DjsxDSuB.js +129 -0
  26. package/message-layer.d.ts +12 -0
  27. package/message-layer.js +4 -0
  28. package/notify.d.ts +3 -0
  29. package/notify.js +2 -0
  30. package/objects-DJ3QtCCs.d.ts +640 -0
  31. package/objects-Db7IB5vQ.js +91 -0
  32. package/operation-promises-EgZXG5N_.js +23 -0
  33. package/package.json +70 -4
  34. package/readers-BFPuosPk.d.ts +25 -0
  35. package/readers-CjJHKHvH.js +482 -0
  36. package/request-pump-binary-DdY3X-yl.js +2246 -0
  37. package/router--71qvxtY.js +343 -0
  38. package/router-Zhrw5l__.d.ts +55 -0
  39. package/session.d.ts +9 -0
  40. package/session.js +3510 -0
  41. package/setup.d.ts +3 -0
  42. package/setup.js +193 -0
  43. package/sha256-B_kyYw3Z.js +124 -0
  44. package/sqlite.d.ts +74 -0
  45. package/sqlite.js +529 -0
  46. package/store-capability-OZp4hXmj.js +390 -0
  47. package/store-hJrRULMx.js +60 -0
  48. package/store.d.ts +21 -0
  49. package/store.js +4 -0
  50. package/user-capability-BK4Asg7D.js +276 -0
  51. package/wasm.d.ts +243 -0
  52. package/wasm.js +1737 -0
package/sqlite.js ADDED
@@ -0,0 +1,529 @@
1
+
2
+ import { K as text, _ as dec, t as HostError } from "./errors-LYJZ_c8h.js";
3
+ import { r as decodeValue } from "./readers-CjJHKHvH.js";
4
+ import { t as encodeValue } from "./encoding-nlrpj-Pb.js";
5
+ import { n as hostScriptError } from "./store-capability-OZp4hXmj.js";
6
+ import { r as Stores, t as StoreContentsError } from "./engine-BGaJ9dAk.js";
7
+ import { DatabaseSync } from "node:sqlite";
8
+ //#region src/sqlite/scan.ts
9
+ const isWordChar = (c) => /[\w$]/.test(c) || c.charCodeAt(0) > 127;
10
+ /** Scans `sql` once; strings, quoted names and comments hide what they hold. */
11
+ const scan = (sql) => {
12
+ const ends = [];
13
+ const placeholders = [];
14
+ const content = [];
15
+ let keyword = "";
16
+ let i = 0;
17
+ const closing = (quote) => {
18
+ for (i++; i < sql.length; i++) if (sql[i] === quote) {
19
+ if (quote !== "]" && sql[i + 1] === quote) i++;
20
+ else {
21
+ i++;
22
+ return;
23
+ }
24
+ }
25
+ };
26
+ while (i < sql.length) {
27
+ const c = sql[i];
28
+ if (/\s/.test(c)) i++;
29
+ else if (c === "-" && sql[i + 1] === "-") {
30
+ const end = sql.indexOf("\n", i);
31
+ i = end === -1 ? sql.length : end + 1;
32
+ } else if (c === "/" && sql[i + 1] === "*") {
33
+ const end = sql.indexOf("*/", i + 2);
34
+ i = end === -1 ? sql.length : end + 2;
35
+ } else if (c === ";") {
36
+ ends.push(i);
37
+ i++;
38
+ } else {
39
+ content.push(i);
40
+ if (c === "'" || c === "\"" || c === "`") closing(c);
41
+ else if (c === "[") closing("]");
42
+ else if (c === "?") {
43
+ let j = i + 1;
44
+ while (j < sql.length && /\d/.test(sql[j])) j++;
45
+ placeholders.push([ends.length, j > i + 1 ? {
46
+ kind: "positional",
47
+ index: Number(sql.slice(i + 1, j))
48
+ } : { kind: "positional" }]);
49
+ i = j;
50
+ } else if ((c === ":" || c === "@" || c === "$") && isWordChar(sql[i + 1] ?? " ")) {
51
+ let j = i + 1;
52
+ while (j < sql.length && isWordChar(sql[j])) j++;
53
+ placeholders.push([ends.length, {
54
+ kind: "named",
55
+ prefix: c,
56
+ name: sql.slice(i + 1, j)
57
+ }]);
58
+ i = j;
59
+ } else if (isWordChar(c)) {
60
+ let j = i + 1;
61
+ while (j < sql.length && isWordChar(sql[j])) j++;
62
+ if (!keyword && ends.length === 0) keyword = sql.slice(i, j).toUpperCase();
63
+ i = j;
64
+ } else i++;
65
+ }
66
+ }
67
+ ends.push(sql.length);
68
+ const last = content.at(-1) ?? -1;
69
+ return {
70
+ ends,
71
+ trailing: ends.map((end) => last > end),
72
+ keyword,
73
+ placeholders
74
+ };
75
+ };
76
+ //#endregion
77
+ //#region src/sqlite/database.ts
78
+ /** The table that keeps a database's Stores, which no `sqlite` Grant may use. */
79
+ const STORE_TABLE = "store";
80
+ const OK = { status: "ok" };
81
+ const SQLITE_OK = 0;
82
+ const SQLITE_DENY = 1;
83
+ const PRAGMA = 19;
84
+ const READ = 20;
85
+ const TRANSACTION = 22;
86
+ const ATTACH = 24;
87
+ const DETACH = 25;
88
+ const FUNCTION = 31;
89
+ const SAVEPOINT = 32;
90
+ const TABLE_ARG = {
91
+ 1: 2,
92
+ 2: 1,
93
+ 3: 2,
94
+ 4: 1,
95
+ 5: 2,
96
+ 6: 1,
97
+ 7: 2,
98
+ 8: 1,
99
+ 9: 1,
100
+ 10: 2,
101
+ 11: 1,
102
+ 12: 2,
103
+ 13: 1,
104
+ 14: 2,
105
+ 15: 1,
106
+ 16: 2,
107
+ 17: 1,
108
+ 18: 1,
109
+ 20: 1,
110
+ 23: 1,
111
+ 26: 2,
112
+ 28: 1,
113
+ 29: 1,
114
+ 30: 1
115
+ };
116
+ const READS = /* @__PURE__ */ new Set([
117
+ PRAGMA,
118
+ READ,
119
+ 21,
120
+ FUNCTION,
121
+ 33
122
+ ]);
123
+ const DENIED = /* @__PURE__ */ new Set([
124
+ TRANSACTION,
125
+ ATTACH,
126
+ DETACH,
127
+ SAVEPOINT
128
+ ]);
129
+ const SCHEMA_PRAGMAS = /* @__PURE__ */ new Set([
130
+ "table_info",
131
+ "table_xinfo",
132
+ "index_list",
133
+ "index_info",
134
+ "index_xinfo",
135
+ "foreign_key_list"
136
+ ]);
137
+ const TABLE_PRAGMAS = /* @__PURE__ */ new Set([
138
+ "table_info",
139
+ "table_xinfo",
140
+ "index_list",
141
+ "foreign_key_list"
142
+ ]);
143
+ const CONSTRAINT_KINDS = {
144
+ 2067: "unique",
145
+ 1555: "primary key",
146
+ 1299: "not null",
147
+ 275: "check",
148
+ 787: "foreign key",
149
+ 3091: "datatype",
150
+ 1811: "trigger"
151
+ };
152
+ const failure = (code, fields = []) => hostScriptError(code, fields);
153
+ const sqlFailure = (reason) => failure("sql", [["reason", text(reason)]]);
154
+ const isSqliteFault = (error) => error instanceof Error && (error.code === "ERR_SQLITE_ERROR" || typeof error.errcode === "number");
155
+ const translated = (error) => {
156
+ if (!isSqliteFault(error)) return error;
157
+ const code = error.errcode ?? 1;
158
+ switch (code & 255) {
159
+ case 19: return failure("constraint", [["kind", text(CONSTRAINT_KINDS[code] ?? "other")]]);
160
+ case 5:
161
+ case 6: return failure("sqlite busy");
162
+ default: return sqlFailure(error.message);
163
+ }
164
+ };
165
+ const named = (p) => p.kind === "named";
166
+ const checkParams = (placeholders, params) => {
167
+ const names = placeholders.filter(named);
168
+ if (names.some((p) => p.prefix !== ":")) throw sqlFailure("Only ?, ?NNN and :name placeholders are allowed");
169
+ if (names.length && names.length < placeholders.length) throw sqlFailure("Placeholders are either positional or named");
170
+ if (Array.isArray(params)) {
171
+ if (names.length) throw sqlFailure("A list binds only positional placeholders");
172
+ let count = 0;
173
+ for (const p of placeholders) count = p.kind === "positional" && p.index !== void 0 ? Math.max(count, p.index) : count + 1;
174
+ if (params.length !== count) throw sqlFailure(`The statement has ${count} parameters, and ${params.length} were given`);
175
+ return;
176
+ }
177
+ const map = params;
178
+ if (placeholders.length > names.length) throw sqlFailure("A map binds only :name placeholders");
179
+ const wanted = new Set(names.map((p) => p.name));
180
+ if (wanted.size !== map.size || [...map.keys()].some((k) => !wanted.has(k))) throw sqlFailure(`The statement's parameters are ${[...wanted].map((n) => `:${n}`).join(", ") || "none"}`);
181
+ };
182
+ const authorizer = (access, wrote) => {
183
+ const usable = (table) => {
184
+ if (table === null) return true;
185
+ const name = table.toLowerCase();
186
+ if (name === access.store) return false;
187
+ return !access.tables || name.startsWith("sqlite_") || access.tables.has(name);
188
+ };
189
+ return (action, arg1, arg2) => {
190
+ if (DENIED.has(action)) return SQLITE_DENY;
191
+ if (action === FUNCTION) return arg2?.toLowerCase() === "load_extension" ? SQLITE_DENY : SQLITE_OK;
192
+ if (action === PRAGMA) {
193
+ const pragma = (arg1 ?? "").toLowerCase();
194
+ if (pragma === "user_version") return arg2 === null ? SQLITE_OK : SQLITE_DENY;
195
+ return SCHEMA_PRAGMAS.has(pragma) && (!TABLE_PRAGMAS.has(pragma) || usable(arg2)) ? SQLITE_OK : SQLITE_DENY;
196
+ }
197
+ if (action === READ && arg1?.toLowerCase().startsWith("pragma_") && !SCHEMA_PRAGMAS.has(arg1.toLowerCase().slice(7))) return SQLITE_DENY;
198
+ const at = TABLE_ARG[action];
199
+ if (at && !usable(at === 1 ? arg1 : arg2)) return SQLITE_DENY;
200
+ if (!READS.has(action)) wrote.value = true;
201
+ return SQLITE_OK;
202
+ };
203
+ };
204
+ /** One database a Host offers through `sqlite`, and the Stores it may keep. */
205
+ var SqliteDatabase = class {
206
+ /** Every Grant on the database, and its Stores, map to this coordinator. */
207
+ coordinator;
208
+ /** The Stores, for `storeCapability`, when the database keeps them. */
209
+ stores;
210
+ lock;
211
+ reader;
212
+ writer;
213
+ engine;
214
+ counts;
215
+ holder;
216
+ savepoints = 0;
217
+ committing;
218
+ shared = false;
219
+ groups = /* @__PURE__ */ new WeakMap();
220
+ nextGroup = 0;
221
+ constructor(path, options = {}) {
222
+ if (path === "" || path === ":memory:") throw new HostError("invalid value", "A sqlite database is a file, which its connections share");
223
+ if (typeof DatabaseSync.prototype.setAuthorizer !== "function") throw new HostError("invalid value", "sqlite needs node:sqlite with setAuthorizer, as in Node 24.10 or later");
224
+ const opened = [];
225
+ try {
226
+ this.lock = new DatabaseSync(`${path}-lock`);
227
+ opened.push(this.lock);
228
+ try {
229
+ this.lock.exec("PRAGMA locking_mode = EXCLUSIVE; BEGIN EXCLUSIVE; COMMIT");
230
+ } catch (error) {
231
+ throw new Error(`Another connection holds ${path}`, { cause: error });
232
+ }
233
+ this.writer = new DatabaseSync(path, { enableForeignKeyConstraints: true });
234
+ opened.push(this.writer);
235
+ this.writer.exec("PRAGMA journal_mode = WAL");
236
+ this.reader = new DatabaseSync(path, {
237
+ readOnly: true,
238
+ enableForeignKeyConstraints: true
239
+ });
240
+ opened.push(this.reader);
241
+ this.counts = this.writer.prepare("SELECT changes() AS changes, total_changes() AS total");
242
+ const lifecycle = {
243
+ begin: (context) => this.beginSegment(context),
244
+ commit: (context) => this.commitSegment(context),
245
+ rollback: (context) => this.rollbackSegment(context)
246
+ };
247
+ this.coordinator = lifecycle;
248
+ if (options.stores) {
249
+ const engine = new Stores(this.storeBackend(), options.stores);
250
+ this.engine = engine;
251
+ this.stores = Object.assign(lifecycle, this.storeOperations(engine));
252
+ }
253
+ } catch (error) {
254
+ for (const db of opened.reverse()) db.close();
255
+ throw error;
256
+ }
257
+ }
258
+ /**
259
+ * Marks the database as offered through `sqlite`, as `sqliteDatabases`
260
+ * does. From then on a Store write takes the write lock at its call, so a
261
+ * Store's commit never finds it held (ADR 0070). Until then, a Store's
262
+ * commit takes the lock only for the commit.
263
+ */
264
+ shareWithSqlite() {
265
+ this.shared = true;
266
+ }
267
+ /** Runs SQL directly, outside every Segment and with no authorizer, as for a migration. */
268
+ exec(sql) {
269
+ if (this.holder !== void 0) throw new Error("A Segment holds the database’s write lock");
270
+ this.writer.exec(sql);
271
+ }
272
+ /** Closes the database, discarding any Segment's uncommitted changes. */
273
+ close() {
274
+ this.holder = void 0;
275
+ this.reader.close();
276
+ this.writer.close();
277
+ this.lock.close();
278
+ }
279
+ query(call, sql, params, max) {
280
+ const connection = this.holder === this.key(call) ? this.writer : this.reader;
281
+ return this.statement(connection, call.binding, sql, params, max, true);
282
+ }
283
+ change(call, sql, params, max) {
284
+ this.acquire(call, () => failure("sqlite busy"));
285
+ const before = this.changeCounts().total;
286
+ this.writer.exec("SAVEPOINT northtalk_call");
287
+ try {
288
+ const result = this.statement(this.writer, call.binding, sql, params, max, false);
289
+ const { changes, total } = this.changeCounts();
290
+ this.writer.exec("RELEASE northtalk_call");
291
+ return {
292
+ ...result,
293
+ changes: total > before ? changes : 0
294
+ };
295
+ } catch (error) {
296
+ this.writer.exec("ROLLBACK TO northtalk_call; RELEASE northtalk_call");
297
+ throw error;
298
+ }
299
+ }
300
+ begin(call) {
301
+ this.acquire(call, () => failure("sqlite busy"));
302
+ this.savepoints++;
303
+ this.writer.exec(`SAVEPOINT northtalk_${this.savepoints}`);
304
+ }
305
+ commit(call) {
306
+ this.held(call);
307
+ this.writer.exec(`RELEASE northtalk_${this.savepoints}`);
308
+ this.savepoints--;
309
+ }
310
+ rollback(call) {
311
+ this.held(call);
312
+ const savepoint = `northtalk_${this.savepoints}`;
313
+ this.writer.exec(`ROLLBACK TO ${savepoint}; RELEASE ${savepoint}`);
314
+ this.savepoints--;
315
+ }
316
+ beginSegment(context) {
317
+ return this.engine?.begin(context) ?? OK;
318
+ }
319
+ commitSegment(context) {
320
+ const segment = this.key(context);
321
+ if (this.holder !== segment) return this.engine?.commit(context) ?? OK;
322
+ this.committing = segment;
323
+ try {
324
+ const stored = this.engine?.commit(context);
325
+ if (stored && stored.status !== "ok") {
326
+ this.abandon();
327
+ return stored;
328
+ }
329
+ if (this.holder === segment) this.publish();
330
+ return OK;
331
+ } catch (error) {
332
+ return {
333
+ status: "failed",
334
+ detail: error.message
335
+ };
336
+ } finally {
337
+ this.committing = void 0;
338
+ }
339
+ }
340
+ rollbackSegment(context) {
341
+ if (this.holder === this.key(context)) this.abandon();
342
+ return this.engine?.rollback(context) ?? OK;
343
+ }
344
+ key(at) {
345
+ let group = this.groups.get(at.group);
346
+ if (group === void 0) {
347
+ group = this.nextGroup++;
348
+ this.groups.set(at.group, group);
349
+ }
350
+ return `${group} ${at.segmentId}`;
351
+ }
352
+ acquire(at, busy) {
353
+ const segment = this.key(at);
354
+ if (this.holder === segment) return;
355
+ if (this.holder !== void 0) throw busy();
356
+ try {
357
+ this.writer.exec("BEGIN IMMEDIATE");
358
+ } catch (error) {
359
+ const fault = translated(error);
360
+ throw fault instanceof Error && "code" in fault && fault.code === "sqlite busy" ? busy() : fault;
361
+ }
362
+ this.holder = segment;
363
+ this.savepoints = 0;
364
+ }
365
+ held(call) {
366
+ if (this.holder !== this.key(call) || this.savepoints === 0) throw new Error("No transaction of this Segment is open");
367
+ }
368
+ publish() {
369
+ try {
370
+ this.writer.exec("COMMIT");
371
+ } catch (error) {
372
+ this.abandon();
373
+ throw error;
374
+ }
375
+ this.holder = void 0;
376
+ }
377
+ abandon() {
378
+ if (this.writer.isTransaction) this.writer.exec("ROLLBACK");
379
+ this.holder = void 0;
380
+ }
381
+ changeCounts() {
382
+ const row = this.counts.get();
383
+ return {
384
+ changes: Number(row.changes),
385
+ total: Number(row.total)
386
+ };
387
+ }
388
+ statement(connection, binding, sql, params, max, readOnly) {
389
+ const scanned = scan(sql);
390
+ if (scanned.keyword === "") throw sqlFailure("The SQL holds no statement");
391
+ if (scanned.keyword === "VACUUM") throw sqlFailure("VACUUM is not allowed");
392
+ checkParams(scanned.placeholders.map(([, p]) => p), params);
393
+ const wrote = { value: false };
394
+ connection.setAuthorizer(authorizer({
395
+ store: this.engine ? STORE_TABLE : void 0,
396
+ tables: binding.tables ? new Set(binding.tables.map((t) => t.toLowerCase())) : void 0
397
+ }, wrote));
398
+ try {
399
+ const prepared = this.prepareOne(connection, sql, scanned);
400
+ if (readOnly && wrote.value) throw failure("not read-only");
401
+ prepared.setReturnArrays(true);
402
+ prepared.setReadBigInts(true);
403
+ const columns = prepared.columns().map((c) => c.name);
404
+ const rows = [];
405
+ const bound = Array.isArray(params) ? params : [Object.fromEntries(params)];
406
+ const stepped = prepared.iterate(...bound);
407
+ for (const row of stepped) {
408
+ if (rows.length === max) throw failure("too many rows", [["max", dec(String(max))]]);
409
+ rows.push(row.map((value, i) => decoded(value, columns[i])));
410
+ }
411
+ return {
412
+ columns,
413
+ rows
414
+ };
415
+ } catch (error) {
416
+ throw translated(error);
417
+ } finally {
418
+ connection.setAuthorizer(null);
419
+ }
420
+ }
421
+ prepareOne(connection, sql, scanned) {
422
+ for (const [i, end] of scanned.ends.entries()) {
423
+ if (!scanned.trailing[i]) return connection.prepare(sql);
424
+ try {
425
+ connection.prepare(sql.slice(0, end + 1));
426
+ } catch (error) {
427
+ if (isSqliteFault(error) && /incomplete input/.test(error.message)) continue;
428
+ throw error;
429
+ }
430
+ throw sqlFailure("A call runs one statement");
431
+ }
432
+ throw new Error("A scan always ends at the text’s end");
433
+ }
434
+ storeBackend() {
435
+ this.writer.exec(`CREATE TABLE IF NOT EXISTS ${STORE_TABLE} (name TEXT NOT NULL, key TEXT NOT NULL, value TEXT NOT NULL, PRIMARY KEY (name, key)) WITHOUT ROWID`);
436
+ const select = this.reader.prepare(`SELECT key, value FROM ${STORE_TABLE} WHERE name = ?`);
437
+ const upsert = this.writer.prepare(`INSERT INTO ${STORE_TABLE} (name, key, value) VALUES (?, ?, ?) ON CONFLICT (name, key) DO UPDATE SET value = excluded.value`);
438
+ const remove = this.writer.prepare(`DELETE FROM ${STORE_TABLE} WHERE name = ? AND key = ?`);
439
+ const write = (changes) => {
440
+ for (const [name, values] of changes) for (const [key, value] of values) if (value.kind === "nothing") remove.run(name, key);
441
+ else upsert.run(name, key, encodeValue(value));
442
+ };
443
+ return {
444
+ load: (name) => select.all(name).map(({ key, value }) => [key, decodeValue(value)]),
445
+ save: (changes) => {
446
+ if (this.committing !== void 0) {
447
+ try {
448
+ write(changes);
449
+ } catch (error) {
450
+ this.abandon();
451
+ throw error;
452
+ }
453
+ this.publish();
454
+ return;
455
+ }
456
+ if (this.holder !== void 0) throw new StoreContentsError("A Segment holds the database’s write lock");
457
+ this.writer.exec("BEGIN IMMEDIATE");
458
+ try {
459
+ write(changes);
460
+ } catch (error) {
461
+ this.writer.exec("ROLLBACK");
462
+ throw error;
463
+ }
464
+ this.writer.exec("COMMIT");
465
+ }
466
+ };
467
+ }
468
+ storeWrite(call, key) {
469
+ if (this.shared) this.acquire(call, () => failure("store busy", [["key", text(key)]]));
470
+ }
471
+ storeOperations(engine) {
472
+ return {
473
+ router: engine.router,
474
+ watch: (call, name, prefix, message) => engine.watch(call, name, prefix, message),
475
+ unwatch: (call, name) => engine.unwatch(call, name),
476
+ release: (context) => engine.release(context),
477
+ get: (call, key, fallback) => engine.get(call, key, fallback),
478
+ keys: (call, prefix) => engine.keys(call, prefix),
479
+ set: (call, key, value) => {
480
+ this.storeWrite(call, key);
481
+ engine.set(call, key, value);
482
+ },
483
+ delete: (call, key) => {
484
+ this.storeWrite(call, key);
485
+ engine.delete(call, key);
486
+ },
487
+ increment: (call, key, by) => {
488
+ this.storeWrite(call, key);
489
+ return engine.increment(call, key, by);
490
+ },
491
+ swap: (call, key, expected, replacement) => {
492
+ this.storeWrite(call, key);
493
+ return engine.swap(call, key, expected, replacement);
494
+ },
495
+ entries: (store) => engine.entries(store),
496
+ replace: (store, entries) => engine.replace(store, entries),
497
+ clear: (store) => engine.clear(store)
498
+ };
499
+ }
500
+ };
501
+ const decoded = (value, column) => {
502
+ if (typeof value === "string" && value.includes("�")) throw failure("unrepresentable", [["column", text(column)]]);
503
+ return value;
504
+ };
505
+ /** Opens or creates the database at `path`, which the process holds until `close`. */
506
+ const openSqliteDatabase = (path, options) => new SqliteDatabase(path, options);
507
+ //#endregion
508
+ //#region src/sqlite/index.ts
509
+ /**
510
+ * The implementation over the Host's databases, by the name a binding gives.
511
+ * Each database's Store writes then take its write lock at their call.
512
+ */
513
+ const sqliteDatabases = (databases) => {
514
+ for (const db of Object.values(databases)) db.shareWithSqlite();
515
+ const named = (name) => {
516
+ if (!Object.hasOwn(databases, name)) throw new HostError("invalid value", `No sqlite database is named ${name}`);
517
+ return databases[name];
518
+ };
519
+ return {
520
+ coordinator: (database) => named(database).coordinator,
521
+ query: (call, sql, params, max) => named(call.binding.database).query(call, sql, params, max),
522
+ change: (call, sql, params, max) => named(call.binding.database).change(call, sql, params, max),
523
+ begin: (call) => named(call.binding.database).begin(call),
524
+ commit: (call) => named(call.binding.database).commit(call),
525
+ rollback: (call) => named(call.binding.database).rollback(call)
526
+ };
527
+ };
528
+ //#endregion
529
+ export { STORE_TABLE, SqliteDatabase, openSqliteDatabase, sqliteDatabases };