interaqt 2.0.1 → 2.0.3

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 (33) hide show
  1. package/agent/agentspace/knowledge/generator/api-reference.md +14 -1
  2. package/agent/agentspace/knowledge/generator/test-implementation.md +1 -1
  3. package/agent/agentspace/knowledge/usage/13-testing.md +4 -2
  4. package/agent/agentspace/knowledge/usage/18-api-exports-reference.md +11 -8
  5. package/dist/builtins/interaction/Action.d.ts +1 -0
  6. package/dist/builtins/interaction/Action.d.ts.map +1 -1
  7. package/dist/builtins/interaction/Interaction.d.ts.map +1 -1
  8. package/dist/builtins/interaction/activity/ActivityCall.d.ts.map +1 -1
  9. package/dist/core/Entity.d.ts.map +1 -1
  10. package/dist/core/Relation.d.ts.map +1 -1
  11. package/dist/drivers/Mysql.d.ts.map +1 -1
  12. package/dist/drivers/PGLite.d.ts.map +1 -1
  13. package/dist/drivers/PostgreSQL.d.ts.map +1 -1
  14. package/dist/drivers.js +169 -124
  15. package/dist/drivers.js.map +1 -1
  16. package/dist/index.js +4445 -4317
  17. package/dist/index.js.map +1 -1
  18. package/dist/runtime/ComputationSourceMap.d.ts.map +1 -1
  19. package/dist/runtime/Controller.d.ts.map +1 -1
  20. package/dist/runtime/Scheduler.d.ts +2 -0
  21. package/dist/runtime/Scheduler.d.ts.map +1 -1
  22. package/dist/runtime/computations/RealTime.d.ts.map +1 -1
  23. package/dist/runtime/computations/StateMachine.d.ts.map +1 -1
  24. package/dist/storage/erstorage/EntityQueryHandle.d.ts +11 -4
  25. package/dist/storage/erstorage/EntityQueryHandle.d.ts.map +1 -1
  26. package/dist/storage/erstorage/EntityToTableMap.d.ts +1 -0
  27. package/dist/storage/erstorage/EntityToTableMap.d.ts.map +1 -1
  28. package/dist/storage/erstorage/MatchExp.d.ts.map +1 -1
  29. package/dist/storage/erstorage/MergedItemProcessor.d.ts +7 -0
  30. package/dist/storage/erstorage/MergedItemProcessor.d.ts.map +1 -1
  31. package/dist/storage/erstorage/Setup.d.ts +1 -0
  32. package/dist/storage/erstorage/Setup.d.ts.map +1 -1
  33. package/package.json +1 -1
package/dist/drivers.js CHANGED
@@ -1,11 +1,11 @@
1
- import m from "better-sqlite3";
2
- import { sqliteEncodeLiteral as I, dbConsoleLogger as f, asyncInteractionContext as l, ROW_ID_ATTR as p, defaultEncodeLiteral as S, RequireSerializableRetry as N } from "interaqt";
3
- import { AsyncLocalStorage as b } from "node:async_hooks";
4
- import { createHash as A } from "node:crypto";
5
- import R from "pg";
6
- import { PGlite as L } from "@electric-sql/pglite";
7
- import E from "mysql2/promise";
8
- let w = class {
1
+ import N from "better-sqlite3";
2
+ import { sqliteEncodeLiteral as I, dbConsoleLogger as S, asyncInteractionContext as l, ROW_ID_ATTR as E, defaultEncodeLiteral as y, RequireSerializableRetry as b } from "interaqt";
3
+ import { AsyncLocalStorage as A } from "node:async_hooks";
4
+ import { createHash as L } from "node:crypto";
5
+ import w from "pg";
6
+ import { PGlite as R } from "@electric-sql/pglite";
7
+ import m from "mysql2/promise";
8
+ let C = class {
9
9
  constructor(e) {
10
10
  this.db = e;
11
11
  }
@@ -46,13 +46,13 @@ class K {
46
46
  supportsCreateIndexIfNotExists: !0,
47
47
  encodeLiteral: I,
48
48
  constraints: { unique: !0, filteredUnique: !0, nonNull: !1 }
49
- }, this.idSystem = new w(this), this.logger = this.options?.logger || f;
49
+ }, this.idSystem = new C(this), this.logger = this.options?.logger || S;
50
50
  }
51
51
  async open() {
52
- this.db = new m(this.file, this.options), await this.idSystem.setup();
52
+ this.db = new N(this.file, this.options), await this.idSystem.setup();
53
53
  }
54
54
  async openForSchemaRead() {
55
- this.db = new m(this.file, this.options);
55
+ this.db = new N(this.file, this.options);
56
56
  }
57
57
  async setupInternalComputationState() {
58
58
  await this.scheme(`
@@ -75,7 +75,7 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
75
75
  )`, "setup scoped sequence table");
76
76
  }
77
77
  async query(e, t = [], s = "") {
78
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((i) => i === !1 ? 0 : i === !0 ? 1 : i);
78
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
79
79
  return n.info({
80
80
  type: "query",
81
81
  name: s,
@@ -84,25 +84,25 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
84
84
  }), this.db.prepare(e).all(...a);
85
85
  }
86
86
  async update(e, t, s, r = "") {
87
- const n = l.getStore(), a = this.logger.child(n?.logContext || {}), i = `${e} ${s ? `RETURNING ${s} AS id` : ""}`, o = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c === !1 ? 0 : c === !0 ? 1 : c);
87
+ const n = l.getStore(), a = this.logger.child(n?.logContext || {}), o = `${e} ${s ? `RETURNING ${s} AS id` : ""}`, i = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c === !1 ? 0 : c === !0 ? 1 : c);
88
88
  return a.info({
89
89
  type: "update",
90
90
  name: r,
91
- sql: i,
92
- params: o
93
- }), s ? this.db.prepare(i).all(...o) : this.db.prepare(i).run(...o);
91
+ sql: o,
92
+ params: i
93
+ }), s ? this.db.prepare(o).all(...i) : this.db.prepare(o).run(...i);
94
94
  }
95
95
  async insert(e, t, s = "") {
96
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((o) => typeof o == "object" && o !== null ? JSON.stringify(o) : o === !1 ? 0 : o === !0 ? 1 : o);
96
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i === !1 ? 0 : i === !0 ? 1 : i);
97
97
  return n.info({
98
98
  type: "insert",
99
99
  name: s,
100
100
  sql: e,
101
101
  params: a
102
- }), this.db.prepare(`${e} RETURNING ${p}`).all(...a)[0];
102
+ }), this.db.prepare(`${e} RETURNING ${E}`).all(...a)[0];
103
103
  }
104
104
  async delete(e, t, s = "") {
105
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((i) => i === !1 ? 0 : i === !0 ? 1 : i);
105
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
106
106
  return n.info({
107
107
  type: "delete",
108
108
  name: s,
@@ -124,13 +124,13 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
124
124
  async getAutoId(e) {
125
125
  return this.idSystem.getAutoId(e);
126
126
  }
127
- parseMatchExpression(e, t, s, r, n, a, i) {
127
+ parseMatchExpression(e, t, s, r, n, a, o) {
128
128
  if (r === "JSON" && t[0].toLowerCase() === "contains")
129
129
  return {
130
130
  fieldValue: `NOT NULL AND EXISTS (
131
131
  SELECT 1
132
132
  FROM json_each(${s})
133
- WHERE json_each.value = ${i()}
133
+ WHERE json_each.value = ${o()}
134
134
  )`,
135
135
  fieldParams: [t[1]]
136
136
  };
@@ -139,8 +139,8 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
139
139
  return e === "pk" ? "INTEGER PRIMARY KEY" : e === "id" ? "INT" : t || e === "object" || e === "json" ? "JSON" : e === "string" ? "TEXT" : e === "boolean" ? "INT(2)" : e === "number" || e === "timestamp" ? "INT" : e;
140
140
  }
141
141
  }
142
- const { Client: d, Pool: C } = R;
143
- let O = class {
142
+ const { Client: g, Pool: O } = w;
143
+ let q = class {
144
144
  constructor(e) {
145
145
  this.db = e, this.initialized = /* @__PURE__ */ new Set(), this.recordToSequenceName = /* @__PURE__ */ new Map();
146
146
  }
@@ -154,7 +154,7 @@ let O = class {
154
154
  return this.sequenceNameForKey(e, e);
155
155
  }
156
156
  sequenceNameForKey(e, t) {
157
- return `seq_${A("sha1").update(e).digest("hex").slice(0, 12)}_${this.sanitizeIdentifierPart(t)}`.slice(0, 63);
157
+ return `seq_${L("sha1").update(e).digest("hex").slice(0, 12)}_${this.sanitizeIdentifierPart(t)}`.slice(0, 63);
158
158
  }
159
159
  quoteIdentifier(e) {
160
160
  return `"${e.replace(/"/g, '""')}"`;
@@ -170,21 +170,21 @@ let O = class {
170
170
  this.recordToSequenceName.set(r.recordName, n);
171
171
  const a = this.quoteIdentifier(n);
172
172
  await this.db.scheme(`CREATE SEQUENCE IF NOT EXISTS ${a} START WITH 1`, `create sequence ${r.recordName}`);
173
- const i = await this.db.query(
173
+ const o = await this.db.query(
174
174
  `SELECT COALESCE(MAX("${r.idField}"), 0) AS max FROM ${this.quoteIdentifier(r.tableName)}`,
175
175
  [],
176
176
  `read max id for ${r.recordName}`
177
177
  );
178
- let o = 0;
178
+ let i = 0;
179
179
  if (t) {
180
- const T = await this.db.query(
180
+ const u = await this.db.query(
181
181
  'SELECT COALESCE(MAX("last"), 0) AS last FROM "_IDS_" WHERE "name" = $1',
182
182
  [r.recordName],
183
183
  `read legacy id for ${r.recordName}`
184
184
  );
185
- o = Number(T[0]?.last ?? 0);
185
+ i = Number(u[0]?.last ?? 0);
186
186
  }
187
- const c = Math.max(Number(i[0]?.max ?? 0), o);
187
+ const c = Math.max(Number(o[0]?.max ?? 0), i);
188
188
  s.set(a, Math.max(s.get(a) ?? 0, c)), this.initialized.add(r.recordName);
189
189
  }
190
190
  for (const [r, n] of s)
@@ -205,9 +205,9 @@ let O = class {
205
205
  ))[0].id;
206
206
  }
207
207
  };
208
- class J {
208
+ class G {
209
209
  constructor(e, t = {}) {
210
- this.database = e, this.options = t, this.transactionContext = new b(), this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.transactionCapability = {
210
+ this.database = e, this.options = t, this.transactionContext = new A(), this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.transactionCapability = {
211
211
  transactions: !0,
212
212
  isolationLevels: ["READ COMMITTED", "SERIALIZABLE"],
213
213
  transactionBoundConnection: !0,
@@ -224,28 +224,28 @@ class J {
224
224
  name: "postgres",
225
225
  maxIdentifierLength: 63,
226
226
  supportsCreateIndexIfNotExists: !0,
227
- encodeLiteral: S,
227
+ encodeLiteral: y,
228
228
  constraints: { unique: !0, filteredUnique: !0, nonNull: !0 }
229
- }, this.idSystem = new O(this), this.logger = this.options?.logger || f, this.db = new d({ ...t });
229
+ }, this.idSystem = new q(this), this.logger = this.options?.logger || S, this.db = new g({ ...t });
230
230
  }
231
231
  async open(e = !1) {
232
232
  this.pool && e && (await this.pool.end(), this.pool = void 0);
233
- const t = new d({
233
+ const t = new g({
234
234
  ...this.options
235
235
  });
236
- await t.connect(), (await t.query("SELECT FROM pg_database WHERE datname = $1", [this.database])).rows.length === 0 ? await t.query(`CREATE DATABASE "${this.database}"`) : e && (await t.query(`DROP DATABASE "${this.database}" WITH (FORCE)`), await t.query(`CREATE DATABASE "${this.database}"`)), await t.end(), this.pool || (this.pool = this.createPool(), this.db = new d({
236
+ await t.connect(), (await t.query("SELECT FROM pg_database WHERE datname = $1", [this.database])).rows.length === 0 ? await t.query(`CREATE DATABASE "${this.database}"`) : e && (await t.query(`DROP DATABASE "${this.database}" WITH (FORCE)`), await t.query(`CREATE DATABASE "${this.database}"`)), await t.end(), this.pool || (this.pool = this.createPool(), this.db = new g({
237
237
  ...this.options,
238
238
  database: this.database
239
239
  }));
240
240
  }
241
241
  async openForSchemaRead() {
242
- this.pool || (this.pool = this.createPool(), this.db = new d({
242
+ this.pool || (this.pool = this.createPool(), this.db = new g({
243
243
  ...this.options,
244
244
  database: this.database
245
245
  }));
246
246
  }
247
247
  createPool() {
248
- const e = new C({
248
+ const e = new O({
249
249
  ...this.options,
250
250
  database: this.database
251
251
  });
@@ -269,7 +269,7 @@ class J {
269
269
  const s = this.transactionContext.getStore();
270
270
  if (s && s.depth > 0) {
271
271
  if (s.isolation !== "SERIALIZABLE" && (e.isolation ?? "READ COMMITTED") === "SERIALIZABLE")
272
- throw new N(`${e.name || "nested transaction"} requires SERIALIZABLE isolation`);
272
+ throw new b(`${e.name || "nested transaction"} requires SERIALIZABLE isolation`);
273
273
  s.depth++;
274
274
  try {
275
275
  return await t();
@@ -280,20 +280,20 @@ class J {
280
280
  if (!this.pool)
281
281
  throw new Error("PostgreSQL pool is not initialized. Call open() before starting a transaction.");
282
282
  const r = e.isolation ?? "READ COMMITTED", n = await this.pool.connect(), a = { client: n, depth: 1, isolation: r };
283
- let i = !1;
283
+ let o = !1;
284
284
  try {
285
285
  await n.query(`BEGIN ISOLATION LEVEL ${r}`);
286
- const o = await this.transactionContext.run(a, t);
287
- return await n.query("COMMIT"), o;
288
- } catch (o) {
286
+ const i = await this.transactionContext.run(a, t);
287
+ return await n.query("COMMIT"), i;
288
+ } catch (i) {
289
289
  try {
290
290
  await n.query("ROLLBACK");
291
291
  } finally {
292
- n.release(), i = !0;
292
+ n.release(), o = !0;
293
293
  }
294
- throw o;
294
+ throw i;
295
295
  } finally {
296
- i || n.release();
296
+ o || n.release();
297
297
  }
298
298
  }
299
299
  async setupInternalComputationState() {
@@ -326,24 +326,24 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
326
326
  }), (await this.getQueryable().query(e, a)).rows;
327
327
  }
328
328
  async update(e, t, s, r = "") {
329
- const n = l.getStore(), a = this.logger.child(n?.logContext || {}), i = `${e} ${s ? `RETURNING "${s}" AS id` : ""}`, o = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c);
329
+ const n = l.getStore(), a = this.logger.child(n?.logContext || {}), o = `${e} ${s ? `RETURNING "${s}" AS id` : ""}`, i = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c);
330
330
  return a.info({
331
331
  type: "update",
332
332
  name: r,
333
- sql: i,
334
- params: o
335
- }), (await this.getQueryable().query(i, o)).rows;
333
+ sql: o,
334
+ params: i
335
+ }), (await this.getQueryable().query(o, i)).rows;
336
336
  }
337
337
  async insert(e, t, s = "") {
338
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((o) => typeof o == "object" && o !== null ? JSON.stringify(o) : o);
338
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i);
339
339
  n.info({
340
340
  type: "insert",
341
341
  name: s,
342
342
  sql: e,
343
343
  params: a
344
344
  });
345
- const i = `${e} RETURNING "${p}"`;
346
- return (await this.getQueryable().query(i, a)).rows[0];
345
+ const o = `${e} RETURNING "${E}"`;
346
+ return (await this.getQueryable().query(o, a)).rows[0];
347
347
  }
348
348
  async delete(e, t, s = "") {
349
349
  const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t;
@@ -371,13 +371,28 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
371
371
  setupRecordSequences(e) {
372
372
  return this.idSystem.setupSequences(e);
373
373
  }
374
- parseMatchExpression(e, t, s, r, n, a, i) {
375
- if (r === "JSON" && t[0].toLowerCase() === "contains") {
376
- const o = s.split(".").map((c) => `"${c}"`).join(".");
377
- return {
378
- fieldValue: `IS NOT NULL AND ${i()} = ANY (SELECT json_array_elements_text(${o}))`,
379
- fieldParams: [t[1]]
380
- };
374
+ parseMatchExpression(e, t, s, r, n, a, o) {
375
+ if (r === "JSON") {
376
+ if (t[0].toLowerCase() === "contains") {
377
+ const c = s.split(".").map((u) => `"${u}"`).join(".");
378
+ return {
379
+ fieldValue: `IS NOT NULL AND ${o()} = ANY (SELECT json_array_elements_text(${c}))`,
380
+ fieldParams: [t[1]]
381
+ };
382
+ }
383
+ if (t[0] === "=" || t[0] === "!=")
384
+ return {
385
+ fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")}::jsonb ${t[0]} ${o()}::jsonb`,
386
+ fieldParams: [JSON.stringify(t[1])]
387
+ };
388
+ const i = t[0].toLowerCase();
389
+ if ((i === "in" || i === "not in") && Array.isArray(t[1]) && t[1].length > 0) {
390
+ const c = s.split(".").map((h) => `"${h}"`).join("."), u = t[1].map(() => `${o()}::jsonb`).join(",");
391
+ return {
392
+ fieldValue: `IS NOT NULL AND ${c}::jsonb ${i === "in" ? "IN" : "NOT IN"} (${u})`,
393
+ fieldParams: t[1].map((h) => JSON.stringify(h))
394
+ };
395
+ }
381
396
  }
382
397
  }
383
398
  getPlaceholder() {
@@ -388,8 +403,8 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
388
403
  return e === "pk" ? "INT GENERATED ALWAYS AS IDENTITY" : e === "id" ? "INT" : t || e === "object" ? "JSON" : e === "string" ? "TEXT" : e === "boolean" ? "BOOLEAN" : e === "number" ? "DOUBLE PRECISION" : e === "timestamp" ? "TIMESTAMP" : e;
389
404
  }
390
405
  }
391
- const g = "0123456789abcdef";
392
- class h {
406
+ const p = "0123456789abcdef";
407
+ class f {
393
408
  /** @param bytes - The 16-byte byte array representation. */
394
409
  constructor(e) {
395
410
  this.bytes = e;
@@ -406,7 +421,7 @@ class h {
406
421
  static ofInner(e) {
407
422
  if (e.length !== 16)
408
423
  throw new TypeError("not 128-bit length");
409
- return new h(e);
424
+ return new f(e);
410
425
  }
411
426
  /**
412
427
  * Builds a byte array from UUIDv7 field values.
@@ -421,7 +436,7 @@ class h {
421
436
  if (!Number.isInteger(e) || !Number.isInteger(t) || !Number.isInteger(s) || !Number.isInteger(r) || e < 0 || t < 0 || s < 0 || r < 0 || e > 281474976710655 || t > 4095 || s > 1073741823 || r > 4294967295)
422
437
  throw new RangeError("invalid field value");
423
438
  const n = new Uint8Array(16);
424
- return n[0] = e / 2 ** 40, n[1] = e / 2 ** 32, n[2] = e / 2 ** 24, n[3] = e / 2 ** 16, n[4] = e / 2 ** 8, n[5] = e, n[6] = 112 | t >>> 8, n[7] = t, n[8] = 128 | s >>> 24, n[9] = s >>> 16, n[10] = s >>> 8, n[11] = s, n[12] = r >>> 24, n[13] = r >>> 16, n[14] = r >>> 8, n[15] = r, new h(n);
439
+ return n[0] = e / 2 ** 40, n[1] = e / 2 ** 32, n[2] = e / 2 ** 24, n[3] = e / 2 ** 16, n[4] = e / 2 ** 8, n[5] = e, n[6] = 112 | t >>> 8, n[7] = t, n[8] = 128 | s >>> 24, n[9] = s >>> 16, n[10] = s >>> 8, n[11] = s, n[12] = r >>> 24, n[13] = r >>> 16, n[14] = r >>> 8, n[15] = r, new f(n);
425
440
  }
426
441
  /**
427
442
  * Builds a byte array from a string representation.
@@ -455,12 +470,12 @@ class h {
455
470
  break;
456
471
  }
457
472
  if (a) {
458
- const i = new Uint8Array(16);
459
- for (let o = 0; o < 16; o += 4) {
460
- const c = parseInt(a.substring(2 * o, 2 * o + 8), 16);
461
- i[o + 0] = c >>> 24, i[o + 1] = c >>> 16, i[o + 2] = c >>> 8, i[o + 3] = c;
473
+ const o = new Uint8Array(16);
474
+ for (let i = 0; i < 16; i += 4) {
475
+ const c = parseInt(a.substring(2 * i, 2 * i + 8), 16);
476
+ o[i + 0] = c >>> 24, o[i + 1] = c >>> 16, o[i + 2] = c >>> 8, o[i + 3] = c;
462
477
  }
463
- return new h(i);
478
+ return new f(o);
464
479
  } else
465
480
  throw new SyntaxError("could not parse UUID string");
466
481
  }
@@ -471,7 +486,7 @@ class h {
471
486
  toString() {
472
487
  let e = "";
473
488
  for (let t = 0; t < this.bytes.length; t++)
474
- e += g.charAt(this.bytes[t] >>> 4), e += g.charAt(this.bytes[t] & 15), (t === 3 || t === 5 || t === 7 || t === 9) && (e += "-");
489
+ e += p.charAt(this.bytes[t] >>> 4), e += p.charAt(this.bytes[t] & 15), (t === 3 || t === 5 || t === 7 || t === 9) && (e += "-");
475
490
  return e;
476
491
  }
477
492
  /**
@@ -481,7 +496,7 @@ class h {
481
496
  toHex() {
482
497
  let e = "";
483
498
  for (let t = 0; t < this.bytes.length; t++)
484
- e += g.charAt(this.bytes[t] >>> 4), e += g.charAt(this.bytes[t] & 15);
499
+ e += p.charAt(this.bytes[t] >>> 4), e += p.charAt(this.bytes[t] & 15);
485
500
  return e;
486
501
  }
487
502
  /** @returns The 8-4-4-4-12 canonical hexadecimal string representation. */
@@ -519,7 +534,7 @@ class h {
519
534
  }
520
535
  /** Creates an object from `this`. */
521
536
  clone() {
522
- return new h(this.bytes.slice(0));
537
+ return new f(this.bytes.slice(0));
523
538
  }
524
539
  /** Returns true if `this` is equivalent to `other`. */
525
540
  equals(e) {
@@ -538,14 +553,14 @@ class h {
538
553
  return 0;
539
554
  }
540
555
  }
541
- class q {
556
+ class $ {
542
557
  /**
543
558
  * Creates a generator object with the default random number generator, or
544
559
  * with the specified one if passed as an argument. The specified random
545
560
  * number generator should be cryptographically strong and securely seeded.
546
561
  */
547
562
  constructor(e) {
548
- this.timestamp = 0, this.counter = 0, this.random = e ?? _();
563
+ this.timestamp = 0, this.counter = 0, this.random = e ?? D();
549
564
  }
550
565
  /**
551
566
  * Generates a new UUIDv7 object from the current timestamp, or resets the
@@ -617,7 +632,7 @@ class q {
617
632
  this.counter++, this.counter > 4398046511103 && (this.timestamp++, this.resetCounter());
618
633
  else
619
634
  return;
620
- return h.fromFieldsV7(this.timestamp, Math.trunc(this.counter / 2 ** 30), this.counter & 2 ** 30 - 1, this.random.nextUint32());
635
+ return f.fromFieldsV7(this.timestamp, Math.trunc(this.counter / 2 ** 30), this.counter & 2 ** 30 - 1, this.random.nextUint32());
621
636
  }
622
637
  /** Initializes the counter at a 42-bit random integer. */
623
638
  resetCounter() {
@@ -630,19 +645,19 @@ class q {
630
645
  */
631
646
  generateV4() {
632
647
  const e = new Uint8Array(Uint32Array.of(this.random.nextUint32(), this.random.nextUint32(), this.random.nextUint32(), this.random.nextUint32()).buffer);
633
- return e[6] = 64 | e[6] >>> 4, e[8] = 128 | e[8] >>> 2, h.ofInner(e);
648
+ return e[6] = 64 | e[6] >>> 4, e[8] = 128 | e[8] >>> 2, f.ofInner(e);
634
649
  }
635
650
  }
636
- const _ = () => {
651
+ const D = () => {
637
652
  if (typeof crypto < "u" && typeof crypto.getRandomValues < "u")
638
- return new D();
653
+ return new _();
639
654
  if (typeof UUIDV7_DENY_WEAK_RNG < "u" && UUIDV7_DENY_WEAK_RNG)
640
655
  throw new Error("no cryptographically strong RNG available");
641
656
  return {
642
657
  nextUint32: () => Math.trunc(Math.random() * 65536) * 65536 + Math.trunc(Math.random() * 65536)
643
658
  };
644
659
  };
645
- class D {
660
+ class _ {
646
661
  constructor() {
647
662
  this.buffer = new Uint32Array(8), this.cursor = 65535;
648
663
  }
@@ -650,9 +665,9 @@ class D {
650
665
  return this.cursor >= this.buffer.length && (crypto.getRandomValues(this.buffer), this.cursor = 0), this.buffer[this.cursor++];
651
666
  }
652
667
  }
653
- let y;
654
- const U = () => $().toString(), $ = () => (y || (y = new q())).generate();
655
- let x = class {
668
+ let T;
669
+ const U = () => x().toString(), x = () => (T || (T = new $())).generate();
670
+ let P = class {
656
671
  constructor(e) {
657
672
  this.db = e;
658
673
  }
@@ -663,7 +678,7 @@ let x = class {
663
678
  return U();
664
679
  }
665
680
  };
666
- class k {
681
+ class z {
667
682
  constructor(e, t = {}) {
668
683
  this.database = e, this.options = t, this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.transactionCapability = {
669
684
  transactions: !0,
@@ -685,9 +700,9 @@ class k {
685
700
  name: "postgres",
686
701
  maxIdentifierLength: 63,
687
702
  supportsCreateIndexIfNotExists: !0,
688
- encodeLiteral: S,
703
+ encodeLiteral: y,
689
704
  constraints: { unique: !0, filteredUnique: !0, nonNull: !0 }
690
- }, this.idSystem = new x(this), this.logger = this.options?.logger || f, this.db = new L(this.database);
705
+ }, this.idSystem = new P(this), this.logger = this.options?.logger || S, this.db = new R(this.database);
691
706
  }
692
707
  async open(e = !1) {
693
708
  if (e) {
@@ -745,33 +760,33 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
745
760
  }
746
761
  }
747
762
  async update(e, t, s, r = "") {
748
- const n = l.getStore(), a = this.logger.child(n?.logContext || {}), i = `${e} ${s ? `RETURNING "${s}" AS id` : ""}`, o = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c);
763
+ const n = l.getStore(), a = this.logger.child(n?.logContext || {}), o = `${e} ${s ? `RETURNING "${s}" AS id` : ""}`, i = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c);
749
764
  return a.info({
750
765
  type: "update",
751
766
  name: r,
752
- sql: i,
753
- params: o
754
- }), (await this.db.query(i, o)).rows;
767
+ sql: o,
768
+ params: i
769
+ }), (await this.db.query(o, i)).rows;
755
770
  }
756
771
  async insert(e, t, s = "") {
757
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((o) => typeof o == "object" && o !== null ? JSON.stringify(o) : o);
772
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i);
758
773
  n.info({
759
774
  type: "insert",
760
775
  name: s,
761
776
  sql: e,
762
777
  params: a
763
778
  });
764
- const i = `${e} RETURNING "${p}"`;
779
+ const o = `${e} RETURNING "${E}"`;
765
780
  try {
766
- return (await this.db.query(i, a)).rows[0];
767
- } catch (o) {
781
+ return (await this.db.query(o, a)).rows[0];
782
+ } catch (i) {
768
783
  throw n.error({
769
784
  type: "insert",
770
785
  name: s,
771
- sql: i,
786
+ sql: o,
772
787
  params: a,
773
- error: o instanceof Error ? o.message : String(o)
774
- }), o;
788
+ error: i instanceof Error ? i.message : String(i)
789
+ }), i;
775
790
  }
776
791
  }
777
792
  async delete(e, t, s = "") {
@@ -807,13 +822,28 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
807
822
  async getAutoId(e) {
808
823
  return this.idSystem.getAutoId(e);
809
824
  }
810
- parseMatchExpression(e, t, s, r, n, a, i) {
811
- if (r.toLowerCase() === "json" && t[0].toLowerCase() === "contains") {
812
- const o = s.split(".").map((c) => `"${c}"`).join(".");
813
- return {
814
- fieldValue: `IS NOT NULL AND ${i()} = ANY (SELECT json_array_elements_text(${o}))`,
815
- fieldParams: [t[1]]
816
- };
825
+ parseMatchExpression(e, t, s, r, n, a, o) {
826
+ if (r.toLowerCase() === "json") {
827
+ if (t[0].toLowerCase() === "contains") {
828
+ const c = s.split(".").map((u) => `"${u}"`).join(".");
829
+ return {
830
+ fieldValue: `IS NOT NULL AND ${o()} = ANY (SELECT json_array_elements_text(${c}))`,
831
+ fieldParams: [t[1]]
832
+ };
833
+ }
834
+ if (t[0] === "=" || t[0] === "!=")
835
+ return {
836
+ fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")}::jsonb ${t[0]} ${o()}::jsonb`,
837
+ fieldParams: [JSON.stringify(t[1])]
838
+ };
839
+ const i = t[0].toLowerCase();
840
+ if ((i === "in" || i === "not in") && Array.isArray(t[1]) && t[1].length > 0) {
841
+ const c = s.split(".").map((h) => `"${h}"`).join("."), u = t[1].map(() => `${o()}::jsonb`).join(",");
842
+ return {
843
+ fieldValue: `IS NOT NULL AND ${c}::jsonb ${i === "in" ? "IN" : "NOT IN"} (${u})`,
844
+ fieldParams: t[1].map((h) => JSON.stringify(h))
845
+ };
846
+ }
817
847
  }
818
848
  }
819
849
  getPlaceholder() {
@@ -847,7 +877,7 @@ ON DUPLICATE KEY UPDATE last = LAST_INSERT_ID(last + 1)`,
847
877
  }), t;
848
878
  }
849
879
  }
850
- class W {
880
+ class Z {
851
881
  constructor(e, t = {}) {
852
882
  this.database = e, this.options = t, this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.transactionCapability = {
853
883
  transactions: !1,
@@ -862,12 +892,12 @@ class W {
862
892
  name: "mysql",
863
893
  maxIdentifierLength: 64,
864
894
  supportsCreateIndexIfNotExists: !1,
865
- encodeLiteral: S,
895
+ encodeLiteral: y,
866
896
  constraints: { unique: !1, filteredUnique: !1, nonNull: !1 }
867
- }, this.idSystem = new M(this), this.logger = this.options?.logger || f;
897
+ }, this.idSystem = new M(this), this.logger = this.options?.logger || S;
868
898
  }
869
899
  async open(e = !1) {
870
- const t = await E.createConnection({
900
+ const t = await m.createConnection({
871
901
  ...this.options
872
902
  });
873
903
  await t.connect();
@@ -877,19 +907,19 @@ class W {
877
907
  } finally {
878
908
  await t.end();
879
909
  }
880
- this.db = await E.createConnection({
910
+ this.db = await m.createConnection({
881
911
  ...this.options,
882
912
  database: this.database
883
913
  }), await this.db.connect(), await this.db.query("SET sql_mode='ANSI_QUOTES'"), await this.idSystem.setup();
884
914
  }
885
915
  async openForSchemaRead() {
886
- this.db || (this.db = await E.createConnection({
916
+ this.db || (this.db = await m.createConnection({
887
917
  ...this.options,
888
918
  database: this.database
889
919
  }), await this.db.connect(), await this.db.query("SET sql_mode='ANSI_QUOTES'"));
890
920
  }
891
921
  async query(e, t = [], s = "") {
892
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((i) => i === !1 ? 0 : i === !0 ? 1 : i);
922
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
893
923
  return n.info({
894
924
  type: "query",
895
925
  name: s,
@@ -898,13 +928,13 @@ class W {
898
928
  }), (await this.db.query(e, a))[0];
899
929
  }
900
930
  async update(e, t, s, r = "") {
901
- const n = l.getStore(), a = this.logger.child(n?.logContext || {}), i = t.map((o) => typeof o == "object" && o !== null ? JSON.stringify(o) : o === !1 ? 0 : o === !0 ? 1 : o);
931
+ const n = l.getStore(), a = this.logger.child(n?.logContext || {}), o = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i === !1 ? 0 : i === !0 ? 1 : i);
902
932
  return a.info({
903
933
  type: "update",
904
934
  name: r,
905
935
  sql: e,
906
- params: i
907
- }), (await this.db.query(e, i))[0];
936
+ params: o
937
+ }), (await this.db.query(e, o))[0];
908
938
  }
909
939
  async insert(e, t, s = "") {
910
940
  const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c === !1 ? 0 : c === !0 ? 1 : c);
@@ -914,11 +944,11 @@ class W {
914
944
  sql: e,
915
945
  params: a
916
946
  }), await this.db.query(e, a);
917
- const [i] = await this.db.query("SELECT LAST_INSERT_ID();");
918
- return { id: i[0]["LAST_INSERT_ID()"] };
947
+ const [o] = await this.db.query("SELECT LAST_INSERT_ID();");
948
+ return { id: o[0]["LAST_INSERT_ID()"] };
919
949
  }
920
950
  async delete(e, t, s = "") {
921
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((i) => i === !1 ? 0 : i === !0 ? 1 : i);
951
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
922
952
  return n.info({
923
953
  type: "delete",
924
954
  name: s,
@@ -940,12 +970,27 @@ class W {
940
970
  async getAutoId(e) {
941
971
  return this.idSystem.getAutoId(e);
942
972
  }
943
- parseMatchExpression(e, t, s, r, n, a, i) {
944
- if (r === "JSON" && t[0].toLowerCase() === "contains")
945
- return {
946
- fieldValue: `IS NOT NULL AND JSON_CONTAINS(${s.split(".").map((c) => `"${c}"`).join(".")}, ${i()}, '$')`,
947
- fieldParams: [JSON.stringify(t[1])]
948
- };
973
+ parseMatchExpression(e, t, s, r, n, a, o) {
974
+ if (r === "JSON") {
975
+ if (t[0].toLowerCase() === "contains")
976
+ return {
977
+ fieldValue: `IS NOT NULL AND JSON_CONTAINS(${s.split(".").map((u) => `"${u}"`).join(".")}, ${o()}, '$')`,
978
+ fieldParams: [JSON.stringify(t[1])]
979
+ };
980
+ if (t[0] === "=" || t[0] === "!=")
981
+ return {
982
+ fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")} ${t[0]} CAST(${o()} AS JSON)`,
983
+ fieldParams: [JSON.stringify(t[1])]
984
+ };
985
+ const i = t[0].toLowerCase();
986
+ if ((i === "in" || i === "not in") && Array.isArray(t[1]) && t[1].length > 0) {
987
+ const c = s.split(".").map((h) => `"${h}"`).join("."), u = t[1].map(() => `CAST(${o()} AS JSON)`).join(",");
988
+ return {
989
+ fieldValue: `IS NOT NULL AND ${c} ${i === "in" ? "IN" : "NOT IN"} (${u})`,
990
+ fieldParams: t[1].map((h) => JSON.stringify(h))
991
+ };
992
+ }
993
+ }
949
994
  }
950
995
  getPlaceholder() {
951
996
  return () => "?";
@@ -955,9 +1000,9 @@ class W {
955
1000
  }
956
1001
  }
957
1002
  export {
958
- W as MysqlDB,
959
- k as PGLiteDB,
960
- J as PostgreSQLDB,
1003
+ Z as MysqlDB,
1004
+ z as PGLiteDB,
1005
+ G as PostgreSQLDB,
961
1006
  K as SQLiteDB
962
1007
  };
963
1008
  //# sourceMappingURL=drivers.js.map