interaqt 2.0.2 → 2.0.4

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 (40) 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/12-data-querying.md +13 -0
  4. package/agent/agentspace/knowledge/usage/18-api-exports-reference.md +1 -0
  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/builtins/interaction/activity/ActivityManager.d.ts.map +1 -1
  10. package/dist/core/Entity.d.ts.map +1 -1
  11. package/dist/core/Property.d.ts.map +1 -1
  12. package/dist/core/Relation.d.ts.map +1 -1
  13. package/dist/drivers/Mysql.d.ts +1 -0
  14. package/dist/drivers/Mysql.d.ts.map +1 -1
  15. package/dist/drivers/PGLite.d.ts +1 -0
  16. package/dist/drivers/PGLite.d.ts.map +1 -1
  17. package/dist/drivers/PostgreSQL.d.ts +1 -0
  18. package/dist/drivers/PostgreSQL.d.ts.map +1 -1
  19. package/dist/drivers/SQLite.d.ts +1 -1
  20. package/dist/drivers/SQLite.d.ts.map +1 -1
  21. package/dist/drivers.js +184 -153
  22. package/dist/drivers.js.map +1 -1
  23. package/dist/index.js +1387 -1279
  24. package/dist/index.js.map +1 -1
  25. package/dist/runtime/ComputationSourceMap.d.ts.map +1 -1
  26. package/dist/runtime/Controller.d.ts.map +1 -1
  27. package/dist/runtime/Scheduler.d.ts +2 -0
  28. package/dist/runtime/Scheduler.d.ts.map +1 -1
  29. package/dist/runtime/System.d.ts +1 -0
  30. package/dist/runtime/System.d.ts.map +1 -1
  31. package/dist/runtime/computations/RealTime.d.ts.map +1 -1
  32. package/dist/storage/erstorage/MatchExp.d.ts.map +1 -1
  33. package/dist/storage/erstorage/QueryExecutor.d.ts.map +1 -1
  34. package/dist/storage/erstorage/RecordQuery.d.ts.map +1 -1
  35. package/dist/storage/erstorage/SQLBuilder.d.ts +8 -2
  36. package/dist/storage/erstorage/SQLBuilder.d.ts.map +1 -1
  37. package/dist/storage/erstorage/UpdateExecutor.d.ts.map +1 -1
  38. package/dist/storage/utils.d.ts +8 -0
  39. package/dist/storage/utils.d.ts.map +1 -1
  40. package/package.json +1 -1
package/dist/drivers.js CHANGED
@@ -1,11 +1,11 @@
1
- import m from "better-sqlite3";
2
- import { sqliteEncodeLiteral as N, dbConsoleLogger as g, asyncInteractionContext as l, ROW_ID_ATTR as p, defaultEncodeLiteral as S, RequireSerializableRetry as I } from "interaqt";
3
- import { AsyncLocalStorage as b } from "node:async_hooks";
4
- import { createHash as A } from "node:crypto";
5
- import L from "pg";
6
- import { PGlite as R } from "@electric-sql/pglite";
1
+ import N from "better-sqlite3";
2
+ import { sqliteEncodeLiteral as I, dbConsoleLogger as S, asyncInteractionContext as l, ROW_ID_ATTR as m, 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 R from "pg";
6
+ import { PGlite as w } from "@electric-sql/pglite";
7
7
  import E from "mysql2/promise";
8
- let w = class {
8
+ let O = class {
9
9
  constructor(e) {
10
10
  this.db = e;
11
11
  }
@@ -44,15 +44,22 @@ class K {
44
44
  name: "sqlite",
45
45
  maxIdentifierLength: 63,
46
46
  supportsCreateIndexIfNotExists: !0,
47
- encodeLiteral: N,
47
+ encodeLiteral: I,
48
48
  constraints: { unique: !0, filteredUnique: !0, nonNull: !1 }
49
- }, this.idSystem = new w(this), this.logger = this.options?.logger || g;
49
+ }, this.idSystem = new O(this), this.logger = this.options?.logger || S;
50
50
  }
51
- async open() {
52
- this.db = new m(this.file, this.options), await this.idSystem.setup();
51
+ async open(e = !1) {
52
+ if (this.db = new N(this.file, this.options), e) {
53
+ const t = this.db.prepare(
54
+ "SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%'"
55
+ ).all();
56
+ for (const s of t)
57
+ this.db.prepare(`DROP TABLE IF EXISTS "${s.name.replace(/"/g, '""')}"`).run();
58
+ }
59
+ await this.idSystem.setup();
53
60
  }
54
61
  async openForSchemaRead() {
55
- this.db = new m(this.file, this.options);
62
+ this.db = new N(this.file, this.options);
56
63
  }
57
64
  async setupInternalComputationState() {
58
65
  await this.scheme(`
@@ -75,40 +82,40 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
75
82
  )`, "setup scoped sequence table");
76
83
  }
77
84
  async query(e, t = [], s = "") {
78
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
85
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((a) => a === !1 ? 0 : a === !0 ? 1 : a);
79
86
  return n.info({
80
87
  type: "query",
81
88
  name: s,
82
89
  sql: e,
83
- params: i
84
- }), this.db.prepare(e).all(...i);
90
+ params: o
91
+ }), this.db.prepare(e).all(...o);
85
92
  }
86
93
  async update(e, t, s, r = "") {
87
- const n = l.getStore(), i = this.logger.child(n?.logContext || {}), o = `${e} ${s ? `RETURNING ${s} AS id` : ""}`, a = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c === !1 ? 0 : c === !0 ? 1 : c);
88
- return i.info({
94
+ const n = l.getStore(), o = this.logger.child(n?.logContext || {}), a = `${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);
95
+ return o.info({
89
96
  type: "update",
90
97
  name: r,
91
- sql: o,
92
- params: a
93
- }), s ? this.db.prepare(o).all(...a) : this.db.prepare(o).run(...a);
98
+ sql: a,
99
+ params: i
100
+ }), s ? this.db.prepare(a).all(...i) : this.db.prepare(a).run(...i);
94
101
  }
95
102
  async insert(e, t, s = "") {
96
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t.map((a) => typeof a == "object" && a !== null ? JSON.stringify(a) : a === !1 ? 0 : a === !0 ? 1 : a);
103
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i === !1 ? 0 : i === !0 ? 1 : i);
97
104
  return n.info({
98
105
  type: "insert",
99
106
  name: s,
100
107
  sql: e,
101
- params: i
102
- }), this.db.prepare(`${e} RETURNING ${p}`).all(...i)[0];
108
+ params: o
109
+ }), this.db.prepare(`${e} RETURNING ${m}`).all(...o)[0];
103
110
  }
104
111
  async delete(e, t, s = "") {
105
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
112
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((a) => a === !1 ? 0 : a === !0 ? 1 : a);
106
113
  return n.info({
107
114
  type: "delete",
108
115
  name: s,
109
116
  sql: e,
110
- params: i
111
- }), this.db.prepare(e).run(...i);
117
+ params: o
118
+ }), this.db.prepare(e).run(...o);
112
119
  }
113
120
  async scheme(e, t = "") {
114
121
  const s = l.getStore();
@@ -124,13 +131,13 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
124
131
  async getAutoId(e) {
125
132
  return this.idSystem.getAutoId(e);
126
133
  }
127
- parseMatchExpression(e, t, s, r, n, i, o) {
134
+ parseMatchExpression(e, t, s, r, n, o, a) {
128
135
  if (r === "JSON" && t[0].toLowerCase() === "contains")
129
136
  return {
130
137
  fieldValue: `NOT NULL AND EXISTS (
131
138
  SELECT 1
132
139
  FROM json_each(${s})
133
- WHERE json_each.value = ${o()}
140
+ WHERE json_each.value = ${a()}
134
141
  )`,
135
142
  fieldParams: [t[1]]
136
143
  };
@@ -139,8 +146,8 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
139
146
  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
147
  }
141
148
  }
142
- const { Client: d, Pool: C } = L;
143
- let O = class {
149
+ const { Client: g, Pool: C } = R;
150
+ let q = class {
144
151
  constructor(e) {
145
152
  this.db = e, this.initialized = /* @__PURE__ */ new Set(), this.recordToSequenceName = /* @__PURE__ */ new Map();
146
153
  }
@@ -154,7 +161,7 @@ let O = class {
154
161
  return this.sequenceNameForKey(e, e);
155
162
  }
156
163
  sequenceNameForKey(e, t) {
157
- return `seq_${A("sha1").update(e).digest("hex").slice(0, 12)}_${this.sanitizeIdentifierPart(t)}`.slice(0, 63);
164
+ return `seq_${L("sha1").update(e).digest("hex").slice(0, 12)}_${this.sanitizeIdentifierPart(t)}`.slice(0, 63);
158
165
  }
159
166
  quoteIdentifier(e) {
160
167
  return `"${e.replace(/"/g, '""')}"`;
@@ -168,24 +175,24 @@ let O = class {
168
175
  for (const r of e) {
169
176
  const n = this.sequenceNameForKey(`${r.tableName}.${r.idField}`, r.tableName);
170
177
  this.recordToSequenceName.set(r.recordName, n);
171
- const i = this.quoteIdentifier(n);
172
- await this.db.scheme(`CREATE SEQUENCE IF NOT EXISTS ${i} START WITH 1`, `create sequence ${r.recordName}`);
173
- const o = await this.db.query(
178
+ const o = this.quoteIdentifier(n);
179
+ await this.db.scheme(`CREATE SEQUENCE IF NOT EXISTS ${o} START WITH 1`, `create sequence ${r.recordName}`);
180
+ const a = await this.db.query(
174
181
  `SELECT COALESCE(MAX("${r.idField}"), 0) AS max FROM ${this.quoteIdentifier(r.tableName)}`,
175
182
  [],
176
183
  `read max id for ${r.recordName}`
177
184
  );
178
- let a = 0;
185
+ let i = 0;
179
186
  if (t) {
180
- const T = await this.db.query(
187
+ const u = await this.db.query(
181
188
  'SELECT COALESCE(MAX("last"), 0) AS last FROM "_IDS_" WHERE "name" = $1',
182
189
  [r.recordName],
183
190
  `read legacy id for ${r.recordName}`
184
191
  );
185
- a = Number(T[0]?.last ?? 0);
192
+ i = Number(u[0]?.last ?? 0);
186
193
  }
187
- const c = Math.max(Number(o[0]?.max ?? 0), a);
188
- s.set(i, Math.max(s.get(i) ?? 0, c)), this.initialized.add(r.recordName);
194
+ const c = Math.max(Number(a[0]?.max ?? 0), i);
195
+ s.set(o, Math.max(s.get(o) ?? 0, c)), this.initialized.add(r.recordName);
189
196
  }
190
197
  for (const [r, n] of s)
191
198
  n >= 1 && await this.db.query(
@@ -205,9 +212,9 @@ let O = class {
205
212
  ))[0].id;
206
213
  }
207
214
  };
208
- class W {
215
+ class G {
209
216
  constructor(e, t = {}) {
210
- this.database = e, this.options = t, this.transactionContext = new b(), this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.transactionCapability = {
217
+ this.database = e, this.options = t, this.transactionContext = new A(), this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.returnsParsedJSON = !0, this.transactionCapability = {
211
218
  transactions: !0,
212
219
  isolationLevels: ["READ COMMITTED", "SERIALIZABLE"],
213
220
  transactionBoundConnection: !0,
@@ -224,22 +231,22 @@ class W {
224
231
  name: "postgres",
225
232
  maxIdentifierLength: 63,
226
233
  supportsCreateIndexIfNotExists: !0,
227
- encodeLiteral: S,
234
+ encodeLiteral: y,
228
235
  constraints: { unique: !0, filteredUnique: !0, nonNull: !0 }
229
- }, this.idSystem = new O(this), this.logger = this.options?.logger || g, this.db = new d({ ...t });
236
+ }, this.idSystem = new q(this), this.logger = this.options?.logger || S, this.db = new g({ ...t });
230
237
  }
231
238
  async open(e = !1) {
232
239
  this.pool && e && (await this.pool.end(), this.pool = void 0);
233
- const t = new d({
240
+ const t = new g({
234
241
  ...this.options
235
242
  });
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({
243
+ 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
244
  ...this.options,
238
245
  database: this.database
239
246
  }));
240
247
  }
241
248
  async openForSchemaRead() {
242
- this.pool || (this.pool = this.createPool(), this.db = new d({
249
+ this.pool || (this.pool = this.createPool(), this.db = new g({
243
250
  ...this.options,
244
251
  database: this.database
245
252
  }));
@@ -269,7 +276,7 @@ class W {
269
276
  const s = this.transactionContext.getStore();
270
277
  if (s && s.depth > 0) {
271
278
  if (s.isolation !== "SERIALIZABLE" && (e.isolation ?? "READ COMMITTED") === "SERIALIZABLE")
272
- throw new I(`${e.name || "nested transaction"} requires SERIALIZABLE isolation`);
279
+ throw new b(`${e.name || "nested transaction"} requires SERIALIZABLE isolation`);
273
280
  s.depth++;
274
281
  try {
275
282
  return await t();
@@ -279,21 +286,21 @@ class W {
279
286
  }
280
287
  if (!this.pool)
281
288
  throw new Error("PostgreSQL pool is not initialized. Call open() before starting a transaction.");
282
- const r = e.isolation ?? "READ COMMITTED", n = await this.pool.connect(), i = { client: n, depth: 1, isolation: r };
283
- let o = !1;
289
+ const r = e.isolation ?? "READ COMMITTED", n = await this.pool.connect(), o = { client: n, depth: 1, isolation: r };
290
+ let a = !1;
284
291
  try {
285
292
  await n.query(`BEGIN ISOLATION LEVEL ${r}`);
286
- const a = await this.transactionContext.run(i, t);
287
- return await n.query("COMMIT"), a;
288
- } catch (a) {
293
+ const i = await this.transactionContext.run(o, t);
294
+ return await n.query("COMMIT"), i;
295
+ } catch (i) {
289
296
  try {
290
297
  await n.query("ROLLBACK");
291
298
  } finally {
292
- n.release(), o = !0;
299
+ n.release(), a = !0;
293
300
  }
294
- throw a;
301
+ throw i;
295
302
  } finally {
296
- o || n.release();
303
+ a || n.release();
297
304
  }
298
305
  }
299
306
  async setupInternalComputationState() {
@@ -317,42 +324,42 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
317
324
  )`, "setup scoped sequence table");
318
325
  }
319
326
  async query(e, t = [], s = "") {
320
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t;
327
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t;
321
328
  return n.info({
322
329
  type: "query",
323
330
  name: s,
324
331
  sql: e,
325
- params: i
326
- }), (await this.getQueryable().query(e, i)).rows;
332
+ params: o
333
+ }), (await this.getQueryable().query(e, o)).rows;
327
334
  }
328
335
  async update(e, t, s, r = "") {
329
- const n = l.getStore(), i = this.logger.child(n?.logContext || {}), o = `${e} ${s ? `RETURNING "${s}" AS id` : ""}`, a = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c);
330
- return i.info({
336
+ const n = l.getStore(), o = this.logger.child(n?.logContext || {}), a = `${e} ${s ? `RETURNING "${s}" AS id` : ""}`, i = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c);
337
+ return o.info({
331
338
  type: "update",
332
339
  name: r,
333
- sql: o,
334
- params: a
335
- }), (await this.getQueryable().query(o, a)).rows;
340
+ sql: a,
341
+ params: i
342
+ }), (await this.getQueryable().query(a, i)).rows;
336
343
  }
337
344
  async insert(e, t, s = "") {
338
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t.map((a) => typeof a == "object" && a !== null ? JSON.stringify(a) : a);
345
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i);
339
346
  n.info({
340
347
  type: "insert",
341
348
  name: s,
342
349
  sql: e,
343
- params: i
350
+ params: o
344
351
  });
345
- const o = `${e} RETURNING "${p}"`;
346
- return (await this.getQueryable().query(o, i)).rows[0];
352
+ const a = `${e} RETURNING "${m}"`;
353
+ return (await this.getQueryable().query(a, o)).rows[0];
347
354
  }
348
355
  async delete(e, t, s = "") {
349
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t;
356
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t;
350
357
  return n.info({
351
358
  type: "delete",
352
359
  name: s,
353
360
  sql: e,
354
- params: i
355
- }), (await this.getQueryable().query(e, i)).rows;
361
+ params: o
362
+ }), (await this.getQueryable().query(e, o)).rows;
356
363
  }
357
364
  async scheme(e, t = "") {
358
365
  const s = l.getStore();
@@ -371,20 +378,28 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
371
378
  setupRecordSequences(e) {
372
379
  return this.idSystem.setupSequences(e);
373
380
  }
374
- parseMatchExpression(e, t, s, r, n, i, o) {
381
+ parseMatchExpression(e, t, s, r, n, o, a) {
375
382
  if (r === "JSON") {
376
383
  if (t[0].toLowerCase() === "contains") {
377
- const a = s.split(".").map((c) => `"${c}"`).join(".");
384
+ const c = s.split(".").map((u) => `"${u}"`).join(".");
378
385
  return {
379
- fieldValue: `IS NOT NULL AND ${o()} = ANY (SELECT json_array_elements_text(${a}))`,
386
+ fieldValue: `IS NOT NULL AND ${a()} = ANY (SELECT json_array_elements_text(${c}))`,
380
387
  fieldParams: [t[1]]
381
388
  };
382
389
  }
383
390
  if (t[0] === "=" || t[0] === "!=")
384
391
  return {
385
- fieldValue: `IS NOT NULL AND ${s.split(".").map((c) => `"${c}"`).join(".")}::jsonb ${t[0]} ${o()}::jsonb`,
392
+ fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")}::jsonb ${t[0]} ${a()}::jsonb`,
386
393
  fieldParams: [JSON.stringify(t[1])]
387
394
  };
395
+ const i = t[0].toLowerCase();
396
+ if ((i === "in" || i === "not in") && Array.isArray(t[1]) && t[1].length > 0) {
397
+ const c = s.split(".").map((h) => `"${h}"`).join("."), u = t[1].map(() => `${a()}::jsonb`).join(",");
398
+ return {
399
+ fieldValue: `IS NOT NULL AND ${c}::jsonb ${i === "in" ? "IN" : "NOT IN"} (${u})`,
400
+ fieldParams: t[1].map((h) => JSON.stringify(h))
401
+ };
402
+ }
388
403
  }
389
404
  }
390
405
  getPlaceholder() {
@@ -395,8 +410,8 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
395
410
  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;
396
411
  }
397
412
  }
398
- const f = "0123456789abcdef";
399
- class h {
413
+ const p = "0123456789abcdef";
414
+ class f {
400
415
  /** @param bytes - The 16-byte byte array representation. */
401
416
  constructor(e) {
402
417
  this.bytes = e;
@@ -413,7 +428,7 @@ class h {
413
428
  static ofInner(e) {
414
429
  if (e.length !== 16)
415
430
  throw new TypeError("not 128-bit length");
416
- return new h(e);
431
+ return new f(e);
417
432
  }
418
433
  /**
419
434
  * Builds a byte array from UUIDv7 field values.
@@ -428,7 +443,7 @@ class h {
428
443
  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)
429
444
  throw new RangeError("invalid field value");
430
445
  const n = new Uint8Array(16);
431
- 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);
446
+ 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);
432
447
  }
433
448
  /**
434
449
  * Builds a byte array from a string representation.
@@ -446,28 +461,28 @@ class h {
446
461
  */
447
462
  static parse(e) {
448
463
  var t, s, r, n;
449
- let i;
464
+ let o;
450
465
  switch (e.length) {
451
466
  case 32:
452
- i = (t = /^[0-9a-f]{32}$/i.exec(e)) === null || t === void 0 ? void 0 : t[0];
467
+ o = (t = /^[0-9a-f]{32}$/i.exec(e)) === null || t === void 0 ? void 0 : t[0];
453
468
  break;
454
469
  case 36:
455
- i = (s = /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i.exec(e)) === null || s === void 0 ? void 0 : s.slice(1, 6).join("");
470
+ o = (s = /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i.exec(e)) === null || s === void 0 ? void 0 : s.slice(1, 6).join("");
456
471
  break;
457
472
  case 38:
458
- i = (r = /^\{([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})\}$/i.exec(e)) === null || r === void 0 ? void 0 : r.slice(1, 6).join("");
473
+ o = (r = /^\{([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})\}$/i.exec(e)) === null || r === void 0 ? void 0 : r.slice(1, 6).join("");
459
474
  break;
460
475
  case 45:
461
- i = (n = /^urn:uuid:([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i.exec(e)) === null || n === void 0 ? void 0 : n.slice(1, 6).join("");
476
+ o = (n = /^urn:uuid:([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i.exec(e)) === null || n === void 0 ? void 0 : n.slice(1, 6).join("");
462
477
  break;
463
478
  }
464
- if (i) {
465
- const o = new Uint8Array(16);
466
- for (let a = 0; a < 16; a += 4) {
467
- const c = parseInt(i.substring(2 * a, 2 * a + 8), 16);
468
- o[a + 0] = c >>> 24, o[a + 1] = c >>> 16, o[a + 2] = c >>> 8, o[a + 3] = c;
479
+ if (o) {
480
+ const a = new Uint8Array(16);
481
+ for (let i = 0; i < 16; i += 4) {
482
+ const c = parseInt(o.substring(2 * i, 2 * i + 8), 16);
483
+ a[i + 0] = c >>> 24, a[i + 1] = c >>> 16, a[i + 2] = c >>> 8, a[i + 3] = c;
469
484
  }
470
- return new h(o);
485
+ return new f(a);
471
486
  } else
472
487
  throw new SyntaxError("could not parse UUID string");
473
488
  }
@@ -478,7 +493,7 @@ class h {
478
493
  toString() {
479
494
  let e = "";
480
495
  for (let t = 0; t < this.bytes.length; t++)
481
- e += f.charAt(this.bytes[t] >>> 4), e += f.charAt(this.bytes[t] & 15), (t === 3 || t === 5 || t === 7 || t === 9) && (e += "-");
496
+ e += p.charAt(this.bytes[t] >>> 4), e += p.charAt(this.bytes[t] & 15), (t === 3 || t === 5 || t === 7 || t === 9) && (e += "-");
482
497
  return e;
483
498
  }
484
499
  /**
@@ -488,7 +503,7 @@ class h {
488
503
  toHex() {
489
504
  let e = "";
490
505
  for (let t = 0; t < this.bytes.length; t++)
491
- e += f.charAt(this.bytes[t] >>> 4), e += f.charAt(this.bytes[t] & 15);
506
+ e += p.charAt(this.bytes[t] >>> 4), e += p.charAt(this.bytes[t] & 15);
492
507
  return e;
493
508
  }
494
509
  /** @returns The 8-4-4-4-12 canonical hexadecimal string representation. */
@@ -526,7 +541,7 @@ class h {
526
541
  }
527
542
  /** Creates an object from `this`. */
528
543
  clone() {
529
- return new h(this.bytes.slice(0));
544
+ return new f(this.bytes.slice(0));
530
545
  }
531
546
  /** Returns true if `this` is equivalent to `other`. */
532
547
  equals(e) {
@@ -545,14 +560,14 @@ class h {
545
560
  return 0;
546
561
  }
547
562
  }
548
- class q {
563
+ class $ {
549
564
  /**
550
565
  * Creates a generator object with the default random number generator, or
551
566
  * with the specified one if passed as an argument. The specified random
552
567
  * number generator should be cryptographically strong and securely seeded.
553
568
  */
554
569
  constructor(e) {
555
- this.timestamp = 0, this.counter = 0, this.random = e ?? _();
570
+ this.timestamp = 0, this.counter = 0, this.random = e ?? D();
556
571
  }
557
572
  /**
558
573
  * Generates a new UUIDv7 object from the current timestamp, or resets the
@@ -624,7 +639,7 @@ class q {
624
639
  this.counter++, this.counter > 4398046511103 && (this.timestamp++, this.resetCounter());
625
640
  else
626
641
  return;
627
- return h.fromFieldsV7(this.timestamp, Math.trunc(this.counter / 2 ** 30), this.counter & 2 ** 30 - 1, this.random.nextUint32());
642
+ return f.fromFieldsV7(this.timestamp, Math.trunc(this.counter / 2 ** 30), this.counter & 2 ** 30 - 1, this.random.nextUint32());
628
643
  }
629
644
  /** Initializes the counter at a 42-bit random integer. */
630
645
  resetCounter() {
@@ -637,19 +652,19 @@ class q {
637
652
  */
638
653
  generateV4() {
639
654
  const e = new Uint8Array(Uint32Array.of(this.random.nextUint32(), this.random.nextUint32(), this.random.nextUint32(), this.random.nextUint32()).buffer);
640
- return e[6] = 64 | e[6] >>> 4, e[8] = 128 | e[8] >>> 2, h.ofInner(e);
655
+ return e[6] = 64 | e[6] >>> 4, e[8] = 128 | e[8] >>> 2, f.ofInner(e);
641
656
  }
642
657
  }
643
- const _ = () => {
658
+ const D = () => {
644
659
  if (typeof crypto < "u" && typeof crypto.getRandomValues < "u")
645
- return new D();
660
+ return new _();
646
661
  if (typeof UUIDV7_DENY_WEAK_RNG < "u" && UUIDV7_DENY_WEAK_RNG)
647
662
  throw new Error("no cryptographically strong RNG available");
648
663
  return {
649
664
  nextUint32: () => Math.trunc(Math.random() * 65536) * 65536 + Math.trunc(Math.random() * 65536)
650
665
  };
651
666
  };
652
- class D {
667
+ class _ {
653
668
  constructor() {
654
669
  this.buffer = new Uint32Array(8), this.cursor = 65535;
655
670
  }
@@ -657,9 +672,9 @@ class D {
657
672
  return this.cursor >= this.buffer.length && (crypto.getRandomValues(this.buffer), this.cursor = 0), this.buffer[this.cursor++];
658
673
  }
659
674
  }
660
- let y;
661
- const $ = () => U().toString(), U = () => (y || (y = new q())).generate();
662
- let x = class {
675
+ let T;
676
+ const U = () => x().toString(), x = () => (T || (T = new $())).generate();
677
+ let P = class {
663
678
  constructor(e) {
664
679
  this.db = e;
665
680
  }
@@ -667,12 +682,12 @@ let x = class {
667
682
  return this.db.scheme('CREATE Table IF NOT EXISTS "_IDS_" (last INTEGER, name TEXT)');
668
683
  }
669
684
  async getAutoId(e) {
670
- return $();
685
+ return U();
671
686
  }
672
687
  };
673
- class v {
688
+ class z {
674
689
  constructor(e, t = {}) {
675
- this.database = e, this.options = t, this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.transactionCapability = {
690
+ this.database = e, this.options = t, this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.returnsParsedJSON = !0, this.transactionCapability = {
676
691
  transactions: !0,
677
692
  isolationLevels: ["READ COMMITTED", "SERIALIZABLE"],
678
693
  transactionBoundConnection: !1,
@@ -692,9 +707,9 @@ class v {
692
707
  name: "postgres",
693
708
  maxIdentifierLength: 63,
694
709
  supportsCreateIndexIfNotExists: !0,
695
- encodeLiteral: S,
710
+ encodeLiteral: y,
696
711
  constraints: { unique: !0, filteredUnique: !0, nonNull: !0 }
697
- }, this.idSystem = new x(this), this.logger = this.options?.logger || g, this.db = new R(this.database);
712
+ }, this.idSystem = new P(this), this.logger = this.options?.logger || S, this.db = new w(this.database);
698
713
  }
699
714
  async open(e = !1) {
700
715
  if (e) {
@@ -741,44 +756,44 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
741
756
  });
742
757
  try {
743
758
  return (await this.db.query(e, t)).rows;
744
- } catch (i) {
759
+ } catch (o) {
745
760
  throw n.error({
746
761
  type: "query",
747
762
  name: s,
748
763
  sql: e,
749
764
  params: t,
750
- error: i instanceof Error ? i.message : String(i)
751
- }), i;
765
+ error: o instanceof Error ? o.message : String(o)
766
+ }), o;
752
767
  }
753
768
  }
754
769
  async update(e, t, s, r = "") {
755
- const n = l.getStore(), i = this.logger.child(n?.logContext || {}), o = `${e} ${s ? `RETURNING "${s}" AS id` : ""}`, a = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c);
756
- return i.info({
770
+ const n = l.getStore(), o = this.logger.child(n?.logContext || {}), a = `${e} ${s ? `RETURNING "${s}" AS id` : ""}`, i = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c);
771
+ return o.info({
757
772
  type: "update",
758
773
  name: r,
759
- sql: o,
760
- params: a
761
- }), (await this.db.query(o, a)).rows;
774
+ sql: a,
775
+ params: i
776
+ }), (await this.db.query(a, i)).rows;
762
777
  }
763
778
  async insert(e, t, s = "") {
764
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t.map((a) => typeof a == "object" && a !== null ? JSON.stringify(a) : a);
779
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i);
765
780
  n.info({
766
781
  type: "insert",
767
782
  name: s,
768
783
  sql: e,
769
- params: i
784
+ params: o
770
785
  });
771
- const o = `${e} RETURNING "${p}"`;
786
+ const a = `${e} RETURNING "${m}"`;
772
787
  try {
773
- return (await this.db.query(o, i)).rows[0];
774
- } catch (a) {
788
+ return (await this.db.query(a, o)).rows[0];
789
+ } catch (i) {
775
790
  throw n.error({
776
791
  type: "insert",
777
792
  name: s,
778
- sql: o,
779
- params: i,
780
- error: a instanceof Error ? a.message : String(a)
781
- }), a;
793
+ sql: a,
794
+ params: o,
795
+ error: i instanceof Error ? i.message : String(i)
796
+ }), i;
782
797
  }
783
798
  }
784
799
  async delete(e, t, s = "") {
@@ -814,20 +829,28 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
814
829
  async getAutoId(e) {
815
830
  return this.idSystem.getAutoId(e);
816
831
  }
817
- parseMatchExpression(e, t, s, r, n, i, o) {
832
+ parseMatchExpression(e, t, s, r, n, o, a) {
818
833
  if (r.toLowerCase() === "json") {
819
834
  if (t[0].toLowerCase() === "contains") {
820
- const a = s.split(".").map((c) => `"${c}"`).join(".");
835
+ const c = s.split(".").map((u) => `"${u}"`).join(".");
821
836
  return {
822
- fieldValue: `IS NOT NULL AND ${o()} = ANY (SELECT json_array_elements_text(${a}))`,
837
+ fieldValue: `IS NOT NULL AND ${a()} = ANY (SELECT json_array_elements_text(${c}))`,
823
838
  fieldParams: [t[1]]
824
839
  };
825
840
  }
826
841
  if (t[0] === "=" || t[0] === "!=")
827
842
  return {
828
- fieldValue: `IS NOT NULL AND ${s.split(".").map((c) => `"${c}"`).join(".")}::jsonb ${t[0]} ${o()}::jsonb`,
843
+ fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")}::jsonb ${t[0]} ${a()}::jsonb`,
829
844
  fieldParams: [JSON.stringify(t[1])]
830
845
  };
846
+ const i = t[0].toLowerCase();
847
+ if ((i === "in" || i === "not in") && Array.isArray(t[1]) && t[1].length > 0) {
848
+ const c = s.split(".").map((h) => `"${h}"`).join("."), u = t[1].map(() => `${a()}::jsonb`).join(",");
849
+ return {
850
+ fieldValue: `IS NOT NULL AND ${c}::jsonb ${i === "in" ? "IN" : "NOT IN"} (${u})`,
851
+ fieldParams: t[1].map((h) => JSON.stringify(h))
852
+ };
853
+ }
831
854
  }
832
855
  }
833
856
  getPlaceholder() {
@@ -861,9 +884,9 @@ ON DUPLICATE KEY UPDATE last = LAST_INSERT_ID(last + 1)`,
861
884
  }), t;
862
885
  }
863
886
  }
864
- class k {
887
+ class H {
865
888
  constructor(e, t = {}) {
866
- this.database = e, this.options = t, this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.transactionCapability = {
889
+ this.database = e, this.options = t, this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.returnsParsedJSON = !0, this.transactionCapability = {
867
890
  transactions: !1,
868
891
  isolationLevels: [],
869
892
  transactionBoundConnection: !1,
@@ -876,9 +899,9 @@ class k {
876
899
  name: "mysql",
877
900
  maxIdentifierLength: 64,
878
901
  supportsCreateIndexIfNotExists: !1,
879
- encodeLiteral: S,
902
+ encodeLiteral: y,
880
903
  constraints: { unique: !1, filteredUnique: !1, nonNull: !1 }
881
- }, this.idSystem = new M(this), this.logger = this.options?.logger || g;
904
+ }, this.idSystem = new M(this), this.logger = this.options?.logger || S;
882
905
  }
883
906
  async open(e = !1) {
884
907
  const t = await E.createConnection({
@@ -903,42 +926,42 @@ class k {
903
926
  }), await this.db.connect(), await this.db.query("SET sql_mode='ANSI_QUOTES'"));
904
927
  }
905
928
  async query(e, t = [], s = "") {
906
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
929
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((a) => a === !1 ? 0 : a === !0 ? 1 : a);
907
930
  return n.info({
908
931
  type: "query",
909
932
  name: s,
910
933
  sql: e,
911
- params: i
912
- }), (await this.db.query(e, i))[0];
934
+ params: o
935
+ }), (await this.db.query(e, o))[0];
913
936
  }
914
937
  async update(e, t, s, r = "") {
915
- const n = l.getStore(), i = this.logger.child(n?.logContext || {}), o = t.map((a) => typeof a == "object" && a !== null ? JSON.stringify(a) : a === !1 ? 0 : a === !0 ? 1 : a);
916
- return i.info({
938
+ const n = l.getStore(), o = this.logger.child(n?.logContext || {}), a = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i === !1 ? 0 : i === !0 ? 1 : i);
939
+ return o.info({
917
940
  type: "update",
918
941
  name: r,
919
942
  sql: e,
920
- params: o
921
- }), (await this.db.query(e, o))[0];
943
+ params: a
944
+ }), (await this.db.query(e, a))[0];
922
945
  }
923
946
  async insert(e, t, s = "") {
924
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c === !1 ? 0 : c === !0 ? 1 : c);
947
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((c) => typeof c == "object" && c !== null ? JSON.stringify(c) : c === !1 ? 0 : c === !0 ? 1 : c);
925
948
  n.info({
926
949
  type: "insert",
927
950
  name: s,
928
951
  sql: e,
929
- params: i
930
- }), await this.db.query(e, i);
931
- const [o] = await this.db.query("SELECT LAST_INSERT_ID();");
932
- return { id: o[0]["LAST_INSERT_ID()"] };
952
+ params: o
953
+ }), await this.db.query(e, o);
954
+ const [a] = await this.db.query("SELECT LAST_INSERT_ID();");
955
+ return { id: a[0]["LAST_INSERT_ID()"] };
933
956
  }
934
957
  async delete(e, t, s = "") {
935
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), i = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
958
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((a) => a === !1 ? 0 : a === !0 ? 1 : a);
936
959
  return n.info({
937
960
  type: "delete",
938
961
  name: s,
939
962
  sql: e,
940
- params: i
941
- }), (await this.db.query(e, i))[0];
963
+ params: o
964
+ }), (await this.db.query(e, o))[0];
942
965
  }
943
966
  async scheme(e, t = "") {
944
967
  const s = l.getStore();
@@ -954,18 +977,26 @@ class k {
954
977
  async getAutoId(e) {
955
978
  return this.idSystem.getAutoId(e);
956
979
  }
957
- parseMatchExpression(e, t, s, r, n, i, o) {
980
+ parseMatchExpression(e, t, s, r, n, o, a) {
958
981
  if (r === "JSON") {
959
982
  if (t[0].toLowerCase() === "contains")
960
983
  return {
961
- fieldValue: `IS NOT NULL AND JSON_CONTAINS(${s.split(".").map((c) => `"${c}"`).join(".")}, ${o()}, '$')`,
984
+ fieldValue: `IS NOT NULL AND JSON_CONTAINS(${s.split(".").map((u) => `"${u}"`).join(".")}, ${a()}, '$')`,
962
985
  fieldParams: [JSON.stringify(t[1])]
963
986
  };
964
987
  if (t[0] === "=" || t[0] === "!=")
965
988
  return {
966
- fieldValue: `IS NOT NULL AND ${s.split(".").map((c) => `"${c}"`).join(".")} ${t[0]} CAST(${o()} AS JSON)`,
989
+ fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")} ${t[0]} CAST(${a()} AS JSON)`,
967
990
  fieldParams: [JSON.stringify(t[1])]
968
991
  };
992
+ const i = t[0].toLowerCase();
993
+ if ((i === "in" || i === "not in") && Array.isArray(t[1]) && t[1].length > 0) {
994
+ const c = s.split(".").map((h) => `"${h}"`).join("."), u = t[1].map(() => `CAST(${a()} AS JSON)`).join(",");
995
+ return {
996
+ fieldValue: `IS NOT NULL AND ${c} ${i === "in" ? "IN" : "NOT IN"} (${u})`,
997
+ fieldParams: t[1].map((h) => JSON.stringify(h))
998
+ };
999
+ }
969
1000
  }
970
1001
  }
971
1002
  getPlaceholder() {
@@ -976,9 +1007,9 @@ class k {
976
1007
  }
977
1008
  }
978
1009
  export {
979
- k as MysqlDB,
980
- v as PGLiteDB,
981
- W as PostgreSQLDB,
1010
+ H as MysqlDB,
1011
+ z as PGLiteDB,
1012
+ G as PostgreSQLDB,
982
1013
  K as SQLiteDB
983
1014
  };
984
1015
  //# sourceMappingURL=drivers.js.map