interaqt 2.0.3 → 3.0.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 (75) hide show
  1. package/README.md +1 -1
  2. package/agent/agentspace/knowledge/generator/api-reference.md +2 -9
  3. package/agent/agentspace/knowledge/generator/permission-test-implementation.md +18 -0
  4. package/agent/agentspace/knowledge/generator/test-implementation.md +6 -5
  5. package/agent/agentspace/knowledge/usage/02-define-entities-properties.md +11 -6
  6. package/agent/agentspace/knowledge/usage/04-reactive-computations.md +6 -1
  7. package/agent/agentspace/knowledge/usage/05-interactions.md +51 -60
  8. package/agent/agentspace/knowledge/usage/06-attributive-permissions.md +54 -7
  9. package/agent/agentspace/knowledge/usage/07-payload-parameters.md +95 -72
  10. package/agent/agentspace/knowledge/usage/11-global-dictionaries.md +13 -14
  11. package/agent/agentspace/knowledge/usage/12-data-querying.md +13 -0
  12. package/agent/agentspace/knowledge/usage/13-testing.md +2 -2
  13. package/agent/agentspace/knowledge/usage/14-api-reference.md +24 -66
  14. package/agent/agentspace/knowledge/usage/16-frontend-page-design-guide.md +3 -3
  15. package/agent/agentspace/knowledge/usage/18-api-exports-reference.md +2 -5
  16. package/agent/agentspace/knowledge/usage/README.md +2 -2
  17. package/agent/skill/interaqt-reference.md +6 -18
  18. package/dist/builtins/interaction/Interaction.d.ts +1 -22
  19. package/dist/builtins/interaction/Interaction.d.ts.map +1 -1
  20. package/dist/builtins/interaction/PayloadItem.d.ts +5 -14
  21. package/dist/builtins/interaction/PayloadItem.d.ts.map +1 -1
  22. package/dist/builtins/interaction/activity/ActivityCall.d.ts +2 -5
  23. package/dist/builtins/interaction/activity/ActivityCall.d.ts.map +1 -1
  24. package/dist/builtins/interaction/activity/ActivityManager.d.ts.map +1 -1
  25. package/dist/builtins/interaction/index.d.ts +0 -2
  26. package/dist/builtins/interaction/index.d.ts.map +1 -1
  27. package/dist/core/Entity.d.ts.map +1 -1
  28. package/dist/core/Property.d.ts.map +1 -1
  29. package/dist/core/Relation.d.ts.map +1 -1
  30. package/dist/core/interfaces.d.ts +0 -12
  31. package/dist/core/interfaces.d.ts.map +1 -1
  32. package/dist/drivers/Mysql.d.ts +2 -0
  33. package/dist/drivers/Mysql.d.ts.map +1 -1
  34. package/dist/drivers/PGLite.d.ts +2 -0
  35. package/dist/drivers/PGLite.d.ts.map +1 -1
  36. package/dist/drivers/PostgreSQL.d.ts +2 -0
  37. package/dist/drivers/PostgreSQL.d.ts.map +1 -1
  38. package/dist/drivers/SQLite.d.ts +2 -1
  39. package/dist/drivers/SQLite.d.ts.map +1 -1
  40. package/dist/drivers.js +129 -112
  41. package/dist/drivers.js.map +1 -1
  42. package/dist/index.js +2166 -2311
  43. package/dist/index.js.map +1 -1
  44. package/dist/runtime/Controller.d.ts +11 -0
  45. package/dist/runtime/Controller.d.ts.map +1 -1
  46. package/dist/runtime/MonoSystem.d.ts.map +1 -1
  47. package/dist/runtime/Scheduler.d.ts +7 -0
  48. package/dist/runtime/Scheduler.d.ts.map +1 -1
  49. package/dist/runtime/System.d.ts +2 -0
  50. package/dist/runtime/System.d.ts.map +1 -1
  51. package/dist/runtime/computations/Custom.d.ts.map +1 -1
  52. package/dist/runtime/computations/Transform.d.ts.map +1 -1
  53. package/dist/runtime/computations/TransitionFinder.d.ts.map +1 -1
  54. package/dist/runtime/computations/aggregationTemplate.d.ts.map +1 -1
  55. package/dist/runtime/errors/ConditionErrors.d.ts +2 -5
  56. package/dist/runtime/errors/ConditionErrors.d.ts.map +1 -1
  57. package/dist/runtime/transaction.d.ts.map +1 -1
  58. package/dist/storage/erstorage/EntityToTableMap.d.ts.map +1 -1
  59. package/dist/storage/erstorage/MatchExp.d.ts.map +1 -1
  60. package/dist/storage/erstorage/Modifier.d.ts.map +1 -1
  61. package/dist/storage/erstorage/QueryExecutor.d.ts.map +1 -1
  62. package/dist/storage/erstorage/RecordQuery.d.ts.map +1 -1
  63. package/dist/storage/erstorage/SQLBuilder.d.ts +8 -2
  64. package/dist/storage/erstorage/SQLBuilder.d.ts.map +1 -1
  65. package/dist/storage/erstorage/SchemaDialect.d.ts +1 -0
  66. package/dist/storage/erstorage/SchemaDialect.d.ts.map +1 -1
  67. package/dist/storage/erstorage/Setup.d.ts.map +1 -1
  68. package/dist/storage/erstorage/UpdateExecutor.d.ts.map +1 -1
  69. package/dist/storage/utils.d.ts +8 -0
  70. package/dist/storage/utils.d.ts.map +1 -1
  71. package/package.json +1 -1
  72. package/dist/builtins/interaction/Attributive.d.ts +0 -91
  73. package/dist/builtins/interaction/Attributive.d.ts.map +0 -1
  74. package/dist/builtins/interaction/User.d.ts +0 -10
  75. package/dist/builtins/interaction/User.d.ts.map +0 -1
package/dist/drivers.js CHANGED
@@ -1,11 +1,11 @@
1
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";
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
3
  import { AsyncLocalStorage as A } from "node:async_hooks";
4
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 {
5
+ import R from "pg";
6
+ import { PGlite as w } from "@electric-sql/pglite";
7
+ import E from "mysql2/promise";
8
+ let O = class {
9
9
  constructor(e) {
10
10
  this.db = e;
11
11
  }
@@ -44,12 +44,20 @@ class K {
44
44
  name: "sqlite",
45
45
  maxIdentifierLength: 63,
46
46
  supportsCreateIndexIfNotExists: !0,
47
+ enforceMaxIdentifierLength: !1,
47
48
  encodeLiteral: I,
48
49
  constraints: { unique: !0, filteredUnique: !0, nonNull: !1 }
49
- }, this.idSystem = new C(this), this.logger = this.options?.logger || S;
50
+ }, this.idSystem = new O(this), this.logger = this.options?.logger || S;
50
51
  }
51
- async open() {
52
- this.db = new N(this.file, this.options), await this.idSystem.setup();
52
+ async open(e = !1) {
53
+ if (this.db = new N(this.file, this.options), e) {
54
+ const t = this.db.prepare(
55
+ "SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%'"
56
+ ).all();
57
+ for (const s of t)
58
+ this.db.prepare(`DROP TABLE IF EXISTS "${s.name.replace(/"/g, '""')}"`).run();
59
+ }
60
+ await this.idSystem.setup();
53
61
  }
54
62
  async openForSchemaRead() {
55
63
  this.db = new N(this.file, this.options);
@@ -75,40 +83,40 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
75
83
  )`, "setup scoped sequence table");
76
84
  }
77
85
  async query(e, t = [], s = "") {
78
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
86
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((a) => a === !1 ? 0 : a === !0 ? 1 : a);
79
87
  return n.info({
80
88
  type: "query",
81
89
  name: s,
82
90
  sql: e,
83
- params: a
84
- }), this.db.prepare(e).all(...a);
91
+ params: o
92
+ }), this.db.prepare(e).all(...o);
85
93
  }
86
94
  async update(e, t, s, r = "") {
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
- return a.info({
95
+ 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);
96
+ return o.info({
89
97
  type: "update",
90
98
  name: r,
91
- sql: o,
99
+ sql: a,
92
100
  params: i
93
- }), s ? this.db.prepare(o).all(...i) : this.db.prepare(o).run(...i);
101
+ }), s ? this.db.prepare(a).all(...i) : this.db.prepare(a).run(...i);
94
102
  }
95
103
  async insert(e, t, s = "") {
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);
104
+ 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
105
  return n.info({
98
106
  type: "insert",
99
107
  name: s,
100
108
  sql: e,
101
- params: a
102
- }), this.db.prepare(`${e} RETURNING ${E}`).all(...a)[0];
109
+ params: o
110
+ }), this.db.prepare(`${e} RETURNING ${m}`).all(...o)[0];
103
111
  }
104
112
  async delete(e, t, s = "") {
105
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
113
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((a) => a === !1 ? 0 : a === !0 ? 1 : a);
106
114
  return n.info({
107
115
  type: "delete",
108
116
  name: s,
109
117
  sql: e,
110
- params: a
111
- }), this.db.prepare(e).run(...a);
118
+ params: o
119
+ }), this.db.prepare(e).run(...o);
112
120
  }
113
121
  async scheme(e, t = "") {
114
122
  const s = l.getStore();
@@ -124,13 +132,13 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
124
132
  async getAutoId(e) {
125
133
  return this.idSystem.getAutoId(e);
126
134
  }
127
- parseMatchExpression(e, t, s, r, n, a, o) {
135
+ parseMatchExpression(e, t, s, r, n, o, a) {
128
136
  if (r === "JSON" && t[0].toLowerCase() === "contains")
129
137
  return {
130
138
  fieldValue: `NOT NULL AND EXISTS (
131
139
  SELECT 1
132
140
  FROM json_each(${s})
133
- WHERE json_each.value = ${o()}
141
+ WHERE json_each.value = ${a()}
134
142
  )`,
135
143
  fieldParams: [t[1]]
136
144
  };
@@ -139,7 +147,7 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
139
147
  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
148
  }
141
149
  }
142
- const { Client: g, Pool: O } = w;
150
+ const { Client: g, Pool: C } = R;
143
151
  let q = class {
144
152
  constructor(e) {
145
153
  this.db = e, this.initialized = /* @__PURE__ */ new Set(), this.recordToSequenceName = /* @__PURE__ */ new Map();
@@ -168,9 +176,9 @@ let q = class {
168
176
  for (const r of e) {
169
177
  const n = this.sequenceNameForKey(`${r.tableName}.${r.idField}`, r.tableName);
170
178
  this.recordToSequenceName.set(r.recordName, n);
171
- const a = this.quoteIdentifier(n);
172
- await this.db.scheme(`CREATE SEQUENCE IF NOT EXISTS ${a} START WITH 1`, `create sequence ${r.recordName}`);
173
- const o = await this.db.query(
179
+ const o = this.quoteIdentifier(n);
180
+ await this.db.scheme(`CREATE SEQUENCE IF NOT EXISTS ${o} START WITH 1`, `create sequence ${r.recordName}`);
181
+ const a = await this.db.query(
174
182
  `SELECT COALESCE(MAX("${r.idField}"), 0) AS max FROM ${this.quoteIdentifier(r.tableName)}`,
175
183
  [],
176
184
  `read max id for ${r.recordName}`
@@ -184,8 +192,8 @@ let q = class {
184
192
  );
185
193
  i = Number(u[0]?.last ?? 0);
186
194
  }
187
- const c = Math.max(Number(o[0]?.max ?? 0), i);
188
- s.set(a, Math.max(s.get(a) ?? 0, c)), this.initialized.add(r.recordName);
195
+ const c = Math.max(Number(a[0]?.max ?? 0), i);
196
+ s.set(o, Math.max(s.get(o) ?? 0, c)), this.initialized.add(r.recordName);
189
197
  }
190
198
  for (const [r, n] of s)
191
199
  n >= 1 && await this.db.query(
@@ -207,7 +215,7 @@ let q = class {
207
215
  };
208
216
  class G {
209
217
  constructor(e, t = {}) {
210
- this.database = e, this.options = t, this.transactionContext = new A(), this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.transactionCapability = {
218
+ this.database = e, this.options = t, this.transactionContext = new A(), this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.returnsParsedJSON = !0, this.transactionCapability = {
211
219
  transactions: !0,
212
220
  isolationLevels: ["READ COMMITTED", "SERIALIZABLE"],
213
221
  transactionBoundConnection: !0,
@@ -224,6 +232,7 @@ class G {
224
232
  name: "postgres",
225
233
  maxIdentifierLength: 63,
226
234
  supportsCreateIndexIfNotExists: !0,
235
+ enforceMaxIdentifierLength: !0,
227
236
  encodeLiteral: y,
228
237
  constraints: { unique: !0, filteredUnique: !0, nonNull: !0 }
229
238
  }, this.idSystem = new q(this), this.logger = this.options?.logger || S, this.db = new g({ ...t });
@@ -233,7 +242,13 @@ class G {
233
242
  const t = new g({
234
243
  ...this.options
235
244
  });
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({
245
+ await t.connect();
246
+ try {
247
+ (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}"`));
248
+ } finally {
249
+ await t.end();
250
+ }
251
+ this.pool || (this.pool = this.createPool(), this.db = new g({
237
252
  ...this.options,
238
253
  database: this.database
239
254
  }));
@@ -245,7 +260,7 @@ class G {
245
260
  }));
246
261
  }
247
262
  createPool() {
248
- const e = new O({
263
+ const e = new C({
249
264
  ...this.options,
250
265
  database: this.database
251
266
  });
@@ -279,21 +294,21 @@ class G {
279
294
  }
280
295
  if (!this.pool)
281
296
  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(), a = { client: n, depth: 1, isolation: r };
283
- let o = !1;
297
+ const r = e.isolation ?? "READ COMMITTED", n = await this.pool.connect(), o = { client: n, depth: 1, isolation: r };
298
+ let a = !1;
284
299
  try {
285
300
  await n.query(`BEGIN ISOLATION LEVEL ${r}`);
286
- const i = await this.transactionContext.run(a, t);
301
+ const i = await this.transactionContext.run(o, t);
287
302
  return await n.query("COMMIT"), i;
288
303
  } catch (i) {
289
304
  try {
290
305
  await n.query("ROLLBACK");
291
306
  } finally {
292
- n.release(), o = !0;
307
+ n.release(), a = !0;
293
308
  }
294
309
  throw i;
295
310
  } finally {
296
- o || n.release();
311
+ a || n.release();
297
312
  }
298
313
  }
299
314
  async setupInternalComputationState() {
@@ -317,42 +332,42 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
317
332
  )`, "setup scoped sequence table");
318
333
  }
319
334
  async query(e, t = [], s = "") {
320
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t;
335
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t;
321
336
  return n.info({
322
337
  type: "query",
323
338
  name: s,
324
339
  sql: e,
325
- params: a
326
- }), (await this.getQueryable().query(e, a)).rows;
340
+ params: o
341
+ }), (await this.getQueryable().query(e, o)).rows;
327
342
  }
328
343
  async update(e, t, s, r = "") {
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
- return a.info({
344
+ 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);
345
+ return o.info({
331
346
  type: "update",
332
347
  name: r,
333
- sql: o,
348
+ sql: a,
334
349
  params: i
335
- }), (await this.getQueryable().query(o, i)).rows;
350
+ }), (await this.getQueryable().query(a, i)).rows;
336
351
  }
337
352
  async insert(e, t, s = "") {
338
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i);
353
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i);
339
354
  n.info({
340
355
  type: "insert",
341
356
  name: s,
342
357
  sql: e,
343
- params: a
358
+ params: o
344
359
  });
345
- const o = `${e} RETURNING "${E}"`;
346
- return (await this.getQueryable().query(o, a)).rows[0];
360
+ const a = `${e} RETURNING "${m}"`;
361
+ return (await this.getQueryable().query(a, o)).rows[0];
347
362
  }
348
363
  async delete(e, t, s = "") {
349
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t;
364
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t;
350
365
  return n.info({
351
366
  type: "delete",
352
367
  name: s,
353
368
  sql: e,
354
- params: a
355
- }), (await this.getQueryable().query(e, a)).rows;
369
+ params: o
370
+ }), (await this.getQueryable().query(e, o)).rows;
356
371
  }
357
372
  async scheme(e, t = "") {
358
373
  const s = l.getStore();
@@ -371,23 +386,23 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
371
386
  setupRecordSequences(e) {
372
387
  return this.idSystem.setupSequences(e);
373
388
  }
374
- parseMatchExpression(e, t, s, r, n, a, o) {
389
+ parseMatchExpression(e, t, s, r, n, o, a) {
375
390
  if (r === "JSON") {
376
391
  if (t[0].toLowerCase() === "contains") {
377
392
  const c = s.split(".").map((u) => `"${u}"`).join(".");
378
393
  return {
379
- fieldValue: `IS NOT NULL AND ${o()} = ANY (SELECT json_array_elements_text(${c}))`,
394
+ fieldValue: `IS NOT NULL AND ${a()} = ANY (SELECT json_array_elements_text(${c}))`,
380
395
  fieldParams: [t[1]]
381
396
  };
382
397
  }
383
398
  if (t[0] === "=" || t[0] === "!=")
384
399
  return {
385
- fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")}::jsonb ${t[0]} ${o()}::jsonb`,
400
+ fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")}::jsonb ${t[0]} ${a()}::jsonb`,
386
401
  fieldParams: [JSON.stringify(t[1])]
387
402
  };
388
403
  const i = t[0].toLowerCase();
389
404
  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(",");
405
+ const c = s.split(".").map((h) => `"${h}"`).join("."), u = t[1].map(() => `${a()}::jsonb`).join(",");
391
406
  return {
392
407
  fieldValue: `IS NOT NULL AND ${c}::jsonb ${i === "in" ? "IN" : "NOT IN"} (${u})`,
393
408
  fieldParams: t[1].map((h) => JSON.stringify(h))
@@ -454,28 +469,28 @@ class f {
454
469
  */
455
470
  static parse(e) {
456
471
  var t, s, r, n;
457
- let a;
472
+ let o;
458
473
  switch (e.length) {
459
474
  case 32:
460
- a = (t = /^[0-9a-f]{32}$/i.exec(e)) === null || t === void 0 ? void 0 : t[0];
475
+ o = (t = /^[0-9a-f]{32}$/i.exec(e)) === null || t === void 0 ? void 0 : t[0];
461
476
  break;
462
477
  case 36:
463
- a = (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("");
478
+ 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("");
464
479
  break;
465
480
  case 38:
466
- a = (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("");
481
+ 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("");
467
482
  break;
468
483
  case 45:
469
- a = (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("");
484
+ 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("");
470
485
  break;
471
486
  }
472
- if (a) {
473
- const o = new Uint8Array(16);
487
+ if (o) {
488
+ const a = new Uint8Array(16);
474
489
  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;
490
+ const c = parseInt(o.substring(2 * i, 2 * i + 8), 16);
491
+ a[i + 0] = c >>> 24, a[i + 1] = c >>> 16, a[i + 2] = c >>> 8, a[i + 3] = c;
477
492
  }
478
- return new f(o);
493
+ return new f(a);
479
494
  } else
480
495
  throw new SyntaxError("could not parse UUID string");
481
496
  }
@@ -667,7 +682,7 @@ class _ {
667
682
  }
668
683
  let T;
669
684
  const U = () => x().toString(), x = () => (T || (T = new $())).generate();
670
- let P = class {
685
+ let M = class {
671
686
  constructor(e) {
672
687
  this.db = e;
673
688
  }
@@ -680,7 +695,7 @@ let P = class {
680
695
  };
681
696
  class z {
682
697
  constructor(e, t = {}) {
683
- this.database = e, this.options = t, this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.transactionCapability = {
698
+ this.database = e, this.options = t, this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.returnsParsedJSON = !0, this.transactionCapability = {
684
699
  transactions: !0,
685
700
  isolationLevels: ["READ COMMITTED", "SERIALIZABLE"],
686
701
  transactionBoundConnection: !1,
@@ -700,9 +715,10 @@ class z {
700
715
  name: "postgres",
701
716
  maxIdentifierLength: 63,
702
717
  supportsCreateIndexIfNotExists: !0,
718
+ enforceMaxIdentifierLength: !0,
703
719
  encodeLiteral: y,
704
720
  constraints: { unique: !0, filteredUnique: !0, nonNull: !0 }
705
- }, this.idSystem = new P(this), this.logger = this.options?.logger || S, this.db = new R(this.database);
721
+ }, this.idSystem = new M(this), this.logger = this.options?.logger || S, this.db = new w(this.database);
706
722
  }
707
723
  async open(e = !1) {
708
724
  if (e) {
@@ -749,42 +765,42 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
749
765
  });
750
766
  try {
751
767
  return (await this.db.query(e, t)).rows;
752
- } catch (a) {
768
+ } catch (o) {
753
769
  throw n.error({
754
770
  type: "query",
755
771
  name: s,
756
772
  sql: e,
757
773
  params: t,
758
- error: a instanceof Error ? a.message : String(a)
759
- }), a;
774
+ error: o instanceof Error ? o.message : String(o)
775
+ }), o;
760
776
  }
761
777
  }
762
778
  async update(e, t, s, r = "") {
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);
764
- return a.info({
779
+ 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);
780
+ return o.info({
765
781
  type: "update",
766
782
  name: r,
767
- sql: o,
783
+ sql: a,
768
784
  params: i
769
- }), (await this.db.query(o, i)).rows;
785
+ }), (await this.db.query(a, i)).rows;
770
786
  }
771
787
  async insert(e, t, s = "") {
772
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i);
788
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((i) => typeof i == "object" && i !== null ? JSON.stringify(i) : i);
773
789
  n.info({
774
790
  type: "insert",
775
791
  name: s,
776
792
  sql: e,
777
- params: a
793
+ params: o
778
794
  });
779
- const o = `${e} RETURNING "${E}"`;
795
+ const a = `${e} RETURNING "${m}"`;
780
796
  try {
781
- return (await this.db.query(o, a)).rows[0];
797
+ return (await this.db.query(a, o)).rows[0];
782
798
  } catch (i) {
783
799
  throw n.error({
784
800
  type: "insert",
785
801
  name: s,
786
- sql: o,
787
- params: a,
802
+ sql: a,
803
+ params: o,
788
804
  error: i instanceof Error ? i.message : String(i)
789
805
  }), i;
790
806
  }
@@ -822,23 +838,23 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
822
838
  async getAutoId(e) {
823
839
  return this.idSystem.getAutoId(e);
824
840
  }
825
- parseMatchExpression(e, t, s, r, n, a, o) {
841
+ parseMatchExpression(e, t, s, r, n, o, a) {
826
842
  if (r.toLowerCase() === "json") {
827
843
  if (t[0].toLowerCase() === "contains") {
828
844
  const c = s.split(".").map((u) => `"${u}"`).join(".");
829
845
  return {
830
- fieldValue: `IS NOT NULL AND ${o()} = ANY (SELECT json_array_elements_text(${c}))`,
846
+ fieldValue: `IS NOT NULL AND ${a()} = ANY (SELECT json_array_elements_text(${c}))`,
831
847
  fieldParams: [t[1]]
832
848
  };
833
849
  }
834
850
  if (t[0] === "=" || t[0] === "!=")
835
851
  return {
836
- fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")}::jsonb ${t[0]} ${o()}::jsonb`,
852
+ fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")}::jsonb ${t[0]} ${a()}::jsonb`,
837
853
  fieldParams: [JSON.stringify(t[1])]
838
854
  };
839
855
  const i = t[0].toLowerCase();
840
856
  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(",");
857
+ const c = s.split(".").map((h) => `"${h}"`).join("."), u = t[1].map(() => `${a()}::jsonb`).join(",");
842
858
  return {
843
859
  fieldValue: `IS NOT NULL AND ${c}::jsonb ${i === "in" ? "IN" : "NOT IN"} (${u})`,
844
860
  fieldParams: t[1].map((h) => JSON.stringify(h))
@@ -854,7 +870,7 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
854
870
  return e === "pk" ? "SERIAL PRIMARY KEY" : e === "id" ? "UUID" : t || e === "object" ? "JSON" : e === "string" ? "TEXT" : e === "boolean" ? "BOOL" : e === "number" ? "DOUBLE PRECISION" : e === "timestamp" ? "TIMESTAMP" : e;
855
871
  }
856
872
  }
857
- class M {
873
+ class P {
858
874
  constructor(e) {
859
875
  this.db = e, this.allocating = Promise.resolve();
860
876
  }
@@ -877,9 +893,9 @@ ON DUPLICATE KEY UPDATE last = LAST_INSERT_ID(last + 1)`,
877
893
  }), t;
878
894
  }
879
895
  }
880
- class Z {
896
+ class H {
881
897
  constructor(e, t = {}) {
882
- this.database = e, this.options = t, this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.transactionCapability = {
898
+ this.database = e, this.options = t, this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.returnsParsedJSON = !0, this.transactionCapability = {
883
899
  transactions: !1,
884
900
  isolationLevels: [],
885
901
  transactionBoundConnection: !1,
@@ -892,12 +908,13 @@ class Z {
892
908
  name: "mysql",
893
909
  maxIdentifierLength: 64,
894
910
  supportsCreateIndexIfNotExists: !1,
911
+ enforceMaxIdentifierLength: !0,
895
912
  encodeLiteral: y,
896
913
  constraints: { unique: !1, filteredUnique: !1, nonNull: !1 }
897
- }, this.idSystem = new M(this), this.logger = this.options?.logger || S;
914
+ }, this.idSystem = new P(this), this.logger = this.options?.logger || S;
898
915
  }
899
916
  async open(e = !1) {
900
- const t = await m.createConnection({
917
+ const t = await E.createConnection({
901
918
  ...this.options
902
919
  });
903
920
  await t.connect();
@@ -907,54 +924,54 @@ class Z {
907
924
  } finally {
908
925
  await t.end();
909
926
  }
910
- this.db = await m.createConnection({
927
+ this.db = await E.createConnection({
911
928
  ...this.options,
912
929
  database: this.database
913
930
  }), await this.db.connect(), await this.db.query("SET sql_mode='ANSI_QUOTES'"), await this.idSystem.setup();
914
931
  }
915
932
  async openForSchemaRead() {
916
- this.db || (this.db = await m.createConnection({
933
+ this.db || (this.db = await E.createConnection({
917
934
  ...this.options,
918
935
  database: this.database
919
936
  }), await this.db.connect(), await this.db.query("SET sql_mode='ANSI_QUOTES'"));
920
937
  }
921
938
  async query(e, t = [], s = "") {
922
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
939
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((a) => a === !1 ? 0 : a === !0 ? 1 : a);
923
940
  return n.info({
924
941
  type: "query",
925
942
  name: s,
926
943
  sql: e,
927
- params: a
928
- }), (await this.db.query(e, a))[0];
944
+ params: o
945
+ }), (await this.db.query(e, o))[0];
929
946
  }
930
947
  async update(e, t, s, r = "") {
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);
932
- return a.info({
948
+ 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);
949
+ return o.info({
933
950
  type: "update",
934
951
  name: r,
935
952
  sql: e,
936
- params: o
937
- }), (await this.db.query(e, o))[0];
953
+ params: a
954
+ }), (await this.db.query(e, a))[0];
938
955
  }
939
956
  async insert(e, t, s = "") {
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);
957
+ 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);
941
958
  n.info({
942
959
  type: "insert",
943
960
  name: s,
944
961
  sql: e,
945
- params: a
946
- }), await this.db.query(e, a);
947
- const [o] = await this.db.query("SELECT LAST_INSERT_ID();");
948
- return { id: o[0]["LAST_INSERT_ID()"] };
962
+ params: o
963
+ }), await this.db.query(e, o);
964
+ const [a] = await this.db.query("SELECT LAST_INSERT_ID();");
965
+ return { id: a[0]["LAST_INSERT_ID()"] };
949
966
  }
950
967
  async delete(e, t, s = "") {
951
- const r = l.getStore(), n = this.logger.child(r?.logContext || {}), a = t.map((o) => o === !1 ? 0 : o === !0 ? 1 : o);
968
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((a) => a === !1 ? 0 : a === !0 ? 1 : a);
952
969
  return n.info({
953
970
  type: "delete",
954
971
  name: s,
955
972
  sql: e,
956
- params: a
957
- }), (await this.db.query(e, a))[0];
973
+ params: o
974
+ }), (await this.db.query(e, o))[0];
958
975
  }
959
976
  async scheme(e, t = "") {
960
977
  const s = l.getStore();
@@ -970,21 +987,21 @@ class Z {
970
987
  async getAutoId(e) {
971
988
  return this.idSystem.getAutoId(e);
972
989
  }
973
- parseMatchExpression(e, t, s, r, n, a, o) {
990
+ parseMatchExpression(e, t, s, r, n, o, a) {
974
991
  if (r === "JSON") {
975
992
  if (t[0].toLowerCase() === "contains")
976
993
  return {
977
- fieldValue: `IS NOT NULL AND JSON_CONTAINS(${s.split(".").map((u) => `"${u}"`).join(".")}, ${o()}, '$')`,
994
+ fieldValue: `IS NOT NULL AND JSON_CONTAINS(${s.split(".").map((u) => `"${u}"`).join(".")}, ${a()}, '$')`,
978
995
  fieldParams: [JSON.stringify(t[1])]
979
996
  };
980
997
  if (t[0] === "=" || t[0] === "!=")
981
998
  return {
982
- fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")} ${t[0]} CAST(${o()} AS JSON)`,
999
+ fieldValue: `IS NOT NULL AND ${s.split(".").map((u) => `"${u}"`).join(".")} ${t[0]} CAST(${a()} AS JSON)`,
983
1000
  fieldParams: [JSON.stringify(t[1])]
984
1001
  };
985
1002
  const i = t[0].toLowerCase();
986
1003
  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(",");
1004
+ const c = s.split(".").map((h) => `"${h}"`).join("."), u = t[1].map(() => `CAST(${a()} AS JSON)`).join(",");
988
1005
  return {
989
1006
  fieldValue: `IS NOT NULL AND ${c} ${i === "in" ? "IN" : "NOT IN"} (${u})`,
990
1007
  fieldParams: t[1].map((h) => JSON.stringify(h))
@@ -1000,7 +1017,7 @@ class Z {
1000
1017
  }
1001
1018
  }
1002
1019
  export {
1003
- Z as MysqlDB,
1020
+ H as MysqlDB,
1004
1021
  z as PGLiteDB,
1005
1022
  G as PostgreSQLDB,
1006
1023
  K as SQLiteDB