interaqt 4.0.5 → 4.1.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 (59) hide show
  1. package/dist/builtins/interaction/Activity.d.ts +1 -0
  2. package/dist/builtins/interaction/Activity.d.ts.map +1 -1
  3. package/dist/builtins/interaction/activity/ActivityManager.d.ts.map +1 -1
  4. package/dist/core/Any.d.ts.map +1 -1
  5. package/dist/core/Average.d.ts +1 -1
  6. package/dist/core/Average.d.ts.map +1 -1
  7. package/dist/core/BoolExp.d.ts.map +1 -1
  8. package/dist/core/Constraint.d.ts.map +1 -1
  9. package/dist/core/Count.d.ts +1 -1
  10. package/dist/core/Count.d.ts.map +1 -1
  11. package/dist/core/Custom.d.ts.map +1 -1
  12. package/dist/core/Entity.d.ts.map +1 -1
  13. package/dist/core/EventSource.d.ts.map +1 -1
  14. package/dist/core/Every.d.ts +1 -1
  15. package/dist/core/Every.d.ts.map +1 -1
  16. package/dist/core/RealTime.d.ts.map +1 -1
  17. package/dist/core/Relation.d.ts.map +1 -1
  18. package/dist/core/SideEffect.d.ts.map +1 -1
  19. package/dist/core/StateMachine.d.ts.map +1 -1
  20. package/dist/core/Summation.d.ts +1 -1
  21. package/dist/core/Summation.d.ts.map +1 -1
  22. package/dist/core/Transform.d.ts +1 -1
  23. package/dist/core/Transform.d.ts.map +1 -1
  24. package/dist/core/WeightedSummation.d.ts.map +1 -1
  25. package/dist/core/index.d.ts +1 -0
  26. package/dist/core/index.d.ts.map +1 -1
  27. package/dist/core/klassValidation.d.ts +23 -0
  28. package/dist/core/klassValidation.d.ts.map +1 -0
  29. package/dist/drivers/Mysql.d.ts +1 -0
  30. package/dist/drivers/Mysql.d.ts.map +1 -1
  31. package/dist/drivers/PGLite.d.ts +1 -0
  32. package/dist/drivers/PGLite.d.ts.map +1 -1
  33. package/dist/drivers/PostgreSQL.d.ts +1 -0
  34. package/dist/drivers/PostgreSQL.d.ts.map +1 -1
  35. package/dist/drivers/SQLite.d.ts.map +1 -1
  36. package/dist/drivers.js +69 -40
  37. package/dist/drivers.js.map +1 -1
  38. package/dist/index.js +4057 -3763
  39. package/dist/index.js.map +1 -1
  40. package/dist/runtime/MonoSystem.d.ts +2 -0
  41. package/dist/runtime/MonoSystem.d.ts.map +1 -1
  42. package/dist/runtime/migration.d.ts.map +1 -1
  43. package/dist/storage/erstorage/CreationExecutor.d.ts.map +1 -1
  44. package/dist/storage/erstorage/FilteredEntityManager.d.ts +2 -2
  45. package/dist/storage/erstorage/FilteredEntityManager.d.ts.map +1 -1
  46. package/dist/storage/erstorage/MatchExp.d.ts +1 -1
  47. package/dist/storage/erstorage/MatchExp.d.ts.map +1 -1
  48. package/dist/storage/erstorage/NewRecordData.d.ts +13 -0
  49. package/dist/storage/erstorage/NewRecordData.d.ts.map +1 -1
  50. package/dist/storage/erstorage/QueryExecutor.d.ts.map +1 -1
  51. package/dist/storage/erstorage/RecordQueryAgent.d.ts.map +1 -1
  52. package/dist/storage/erstorage/SQLBuilder.d.ts +3 -1
  53. package/dist/storage/erstorage/SQLBuilder.d.ts.map +1 -1
  54. package/dist/storage/erstorage/UpdateExecutor.d.ts.map +1 -1
  55. package/dist/storage/index.d.ts +1 -0
  56. package/dist/storage/index.d.ts.map +1 -1
  57. package/dist/storage/utils.d.ts +3 -0
  58. package/dist/storage/utils.d.ts.map +1 -1
  59. package/package.json +2 -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 m, defaultEncodeLiteral as y, RequireSerializableRetry as b } from "interaqt";
2
+ import { sqliteEncodeLiteral as b, dbConsoleLogger as S, asyncInteractionContext as l, ROW_ID_ATTR as m, defaultEncodeLiteral as y, RequireSerializableRetry as I } from "interaqt";
3
3
  import { AsyncLocalStorage as A } from "node:async_hooks";
4
4
  import { createHash as L } from "node:crypto";
5
- import R from "pg";
6
- import { PGlite as w } from "@electric-sql/pglite";
5
+ import w from "pg";
6
+ import { PGlite as R } from "@electric-sql/pglite";
7
7
  import E from "mysql2/promise";
8
- let O = class {
8
+ let C = class {
9
9
  constructor(e) {
10
10
  this.db = e;
11
11
  }
@@ -45,9 +45,9 @@ class K {
45
45
  maxIdentifierLength: 63,
46
46
  supportsCreateIndexIfNotExists: !0,
47
47
  enforceMaxIdentifierLength: !1,
48
- encodeLiteral: I,
48
+ encodeLiteral: b,
49
49
  constraints: { unique: !0, filteredUnique: !0, nonNull: !1 }
50
- }, this.idSystem = new O(this), this.logger = this.options?.logger || S;
50
+ }, this.idSystem = new C(this), this.logger = this.options?.logger || S;
51
51
  }
52
52
  async open(e = !1) {
53
53
  if ((!this.db || !this.db.open) && (this.db = new N(this.file, this.options)), e) {
@@ -127,13 +127,17 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
127
127
  }), this.db.prepare(e).run();
128
128
  }
129
129
  async close() {
130
- this.db.close();
130
+ if (!(!this.db || !this.db.open))
131
+ try {
132
+ this.db.close();
133
+ } catch {
134
+ }
131
135
  }
132
136
  async getAutoId(e) {
133
137
  return this.idSystem.getAutoId(e);
134
138
  }
135
139
  parseMatchExpression(e, t, s, r, n, o, a) {
136
- if (r === "JSON" && t[0].toLowerCase() === "contains")
140
+ if (r.toLowerCase() === "json" && t[0].toLowerCase() === "contains")
137
141
  return {
138
142
  fieldValue: `NOT NULL AND EXISTS (
139
143
  SELECT 1
@@ -147,7 +151,7 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
147
151
  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;
148
152
  }
149
153
  }
150
- const { Client: g, Pool: C } = R;
154
+ const { Client: g, Pool: O } = w;
151
155
  let q = class {
152
156
  constructor(e) {
153
157
  this.db = e, this.initialized = /* @__PURE__ */ new Set(), this.recordToSequenceName = /* @__PURE__ */ new Map();
@@ -235,10 +239,10 @@ class G {
235
239
  enforceMaxIdentifierLength: !0,
236
240
  encodeLiteral: y,
237
241
  constraints: { unique: !0, filteredUnique: !0, nonNull: !0 }
238
- }, this.idSystem = new q(this), this.logger = this.options?.logger || S, this.db = new g({ ...t });
242
+ }, this.closed = !1, this.idSystem = new q(this), this.logger = this.options?.logger || S, this.db = new g({ ...t });
239
243
  }
240
244
  async open(e = !1) {
241
- this.pool && e && (await this.pool.end(), this.pool = void 0);
245
+ this.closed = !1, this.pool && e && (await this.pool.end(), this.pool = void 0);
242
246
  const t = new g({
243
247
  ...this.options
244
248
  });
@@ -260,7 +264,7 @@ class G {
260
264
  }));
261
265
  }
262
266
  createPool() {
263
- const e = new C({
267
+ const e = new O({
264
268
  ...this.options,
265
269
  database: this.database
266
270
  });
@@ -284,7 +288,7 @@ class G {
284
288
  const s = this.transactionContext.getStore();
285
289
  if (s && s.depth > 0) {
286
290
  if (s.isolation !== "SERIALIZABLE" && (e.isolation ?? "READ COMMITTED") === "SERIALIZABLE")
287
- throw new b(`${e.name || "nested transaction"} requires SERIALIZABLE isolation`);
291
+ throw new I(`${e.name || "nested transaction"} requires SERIALIZABLE isolation`);
288
292
  s.depth++;
289
293
  try {
290
294
  return await t();
@@ -377,8 +381,18 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
377
381
  sql: e
378
382
  }), await this.getQueryable().query(e);
379
383
  }
380
- close() {
381
- return this.pool ? this.pool.end() : this.db.end();
384
+ async close() {
385
+ if (!this.closed) {
386
+ if (this.closed = !0, this.pool) {
387
+ await this.pool.end(), this.pool = void 0;
388
+ return;
389
+ }
390
+ if (this.db && typeof this.db.end == "function")
391
+ try {
392
+ await this.db.end();
393
+ } catch {
394
+ }
395
+ }
382
396
  }
383
397
  async getAutoId(e) {
384
398
  return this.idSystem.getAutoId(e);
@@ -387,7 +401,7 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
387
401
  return this.idSystem.setupSequences(e);
388
402
  }
389
403
  parseMatchExpression(e, t, s, r, n, o, a) {
390
- if (r === "JSON") {
404
+ if (r.toLowerCase() === "json") {
391
405
  if (t[0].toLowerCase() === "contains") {
392
406
  const c = s.split(".").map((u) => `"${u}"`).join(".");
393
407
  return {
@@ -718,7 +732,7 @@ class z {
718
732
  enforceMaxIdentifierLength: !0,
719
733
  encodeLiteral: y,
720
734
  constraints: { unique: !0, filteredUnique: !0, nonNull: !0 }
721
- }, this.idSystem = new M(this), this.logger = this.options?.logger || S, this.db = new w(this.database);
735
+ }, this.closed = !1, this.idSystem = new M(this), this.logger = this.options?.logger || S, this.db = new R(this.database);
722
736
  }
723
737
  async open(e = !1) {
724
738
  if (e) {
@@ -832,8 +846,14 @@ CREATE TABLE IF NOT EXISTS "_ScopedSequence_" (
832
846
  }), n;
833
847
  }
834
848
  }
835
- close() {
836
- return this.db.close();
849
+ async close() {
850
+ if (!(this.closed || !this.db)) {
851
+ this.closed = !0;
852
+ try {
853
+ await this.db.close();
854
+ } catch {
855
+ }
856
+ }
837
857
  }
838
858
  async getAutoId(e) {
839
859
  return this.idSystem.getAutoId(e);
@@ -893,7 +913,7 @@ ON DUPLICATE KEY UPDATE last = LAST_INSERT_ID(last + 1)`,
893
913
  }), t;
894
914
  }
895
915
  }
896
- class H {
916
+ class v {
897
917
  constructor(e, t = {}) {
898
918
  this.database = e, this.options = t, this.supportsSelectForUpdate = !0, this.maxQueryParams = 65e3, this.returnsParsedJSON = !0, this.transactionCapability = {
899
919
  transactions: !1,
@@ -911,23 +931,26 @@ class H {
911
931
  enforceMaxIdentifierLength: !0,
912
932
  encodeLiteral: y,
913
933
  constraints: { unique: !1, filteredUnique: !1, nonNull: !1 }
914
- }, this.idSystem = new P(this), this.logger = this.options?.logger || S;
934
+ }, this.closed = !1, this.idSystem = new P(this), this.logger = this.options?.logger || S;
915
935
  }
916
936
  async open(e = !1) {
917
- const t = await E.createConnection({
918
- ...this.options
919
- });
920
- await t.connect();
921
- try {
922
- const s = `\`${this.database.replace(/`/g, "``")}\``, [r] = await t.query("SHOW DATABASES LIKE ?", [this.database]);
923
- r.length === 0 ? await t.query(`CREATE DATABASE ${s}`) : e && (await t.query(`DROP DATABASE ${s}`), await t.query(`CREATE DATABASE ${s}`));
924
- } finally {
925
- await t.end();
937
+ if (this.closed = !1, this.db && e && (await this.db.end(), this.db = void 0), !this.db) {
938
+ const t = await E.createConnection({
939
+ ...this.options
940
+ });
941
+ await t.connect();
942
+ try {
943
+ const s = `\`${this.database.replace(/`/g, "``")}\``, [r] = await t.query("SHOW DATABASES LIKE ?", [this.database]);
944
+ r.length === 0 ? await t.query(`CREATE DATABASE ${s}`) : e && (await t.query(`DROP DATABASE ${s}`), await t.query(`CREATE DATABASE ${s}`));
945
+ } finally {
946
+ await t.end();
947
+ }
948
+ this.db = await E.createConnection({
949
+ ...this.options,
950
+ database: this.database
951
+ }), await this.db.connect(), await this.db.query("SET sql_mode='ANSI_QUOTES'");
926
952
  }
927
- this.db = await E.createConnection({
928
- ...this.options,
929
- database: this.database
930
- }), await this.db.connect(), await this.db.query("SET sql_mode='ANSI_QUOTES'"), await this.idSystem.setup();
953
+ await this.idSystem.setup();
931
954
  }
932
955
  async openForSchemaRead() {
933
956
  this.db || (this.db = await E.createConnection({
@@ -945,7 +968,7 @@ class H {
945
968
  }), (await this.db.query(e, o))[0];
946
969
  }
947
970
  async update(e, t, s, r = "") {
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);
971
+ const n = l.getStore(), o = this.logger.child(n?.logContext || {}), a = t.map((i) => typeof i == "object" && i !== null && !(i instanceof Date) ? JSON.stringify(i) : i === !1 ? 0 : i === !0 ? 1 : i);
949
972
  return o.info({
950
973
  type: "update",
951
974
  name: r,
@@ -954,7 +977,7 @@ class H {
954
977
  }), (await this.db.query(e, a))[0];
955
978
  }
956
979
  async insert(e, t, s = "") {
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);
980
+ const r = l.getStore(), n = this.logger.child(r?.logContext || {}), o = t.map((c) => typeof c == "object" && c !== null && !(c instanceof Date) ? JSON.stringify(c) : c === !1 ? 0 : c === !0 ? 1 : c);
958
981
  n.info({
959
982
  type: "insert",
960
983
  name: s,
@@ -981,14 +1004,20 @@ class H {
981
1004
  sql: e
982
1005
  }), await this.db.query(e);
983
1006
  }
984
- close() {
985
- return this.db.end();
1007
+ async close() {
1008
+ if (!(this.closed || !this.db)) {
1009
+ this.closed = !0;
1010
+ try {
1011
+ await this.db.end();
1012
+ } catch {
1013
+ }
1014
+ }
986
1015
  }
987
1016
  async getAutoId(e) {
988
1017
  return this.idSystem.getAutoId(e);
989
1018
  }
990
1019
  parseMatchExpression(e, t, s, r, n, o, a) {
991
- if (r === "JSON") {
1020
+ if (r.toLowerCase() === "json") {
992
1021
  if (t[0].toLowerCase() === "contains")
993
1022
  return {
994
1023
  fieldValue: `IS NOT NULL AND JSON_CONTAINS(${s.split(".").map((u) => `"${u}"`).join(".")}, ${a()}, '$')`,
@@ -1017,7 +1046,7 @@ class H {
1017
1046
  }
1018
1047
  }
1019
1048
  export {
1020
- H as MysqlDB,
1049
+ v as MysqlDB,
1021
1050
  z as PGLiteDB,
1022
1051
  G as PostgreSQLDB,
1023
1052
  K as SQLiteDB