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.
- package/dist/builtins/interaction/Activity.d.ts +1 -0
- package/dist/builtins/interaction/Activity.d.ts.map +1 -1
- package/dist/builtins/interaction/activity/ActivityManager.d.ts.map +1 -1
- package/dist/core/Any.d.ts.map +1 -1
- package/dist/core/Average.d.ts +1 -1
- package/dist/core/Average.d.ts.map +1 -1
- package/dist/core/BoolExp.d.ts.map +1 -1
- package/dist/core/Constraint.d.ts.map +1 -1
- package/dist/core/Count.d.ts +1 -1
- package/dist/core/Count.d.ts.map +1 -1
- package/dist/core/Custom.d.ts.map +1 -1
- package/dist/core/Entity.d.ts.map +1 -1
- package/dist/core/EventSource.d.ts.map +1 -1
- package/dist/core/Every.d.ts +1 -1
- package/dist/core/Every.d.ts.map +1 -1
- package/dist/core/RealTime.d.ts.map +1 -1
- package/dist/core/Relation.d.ts.map +1 -1
- package/dist/core/SideEffect.d.ts.map +1 -1
- package/dist/core/StateMachine.d.ts.map +1 -1
- package/dist/core/Summation.d.ts +1 -1
- package/dist/core/Summation.d.ts.map +1 -1
- package/dist/core/Transform.d.ts +1 -1
- package/dist/core/Transform.d.ts.map +1 -1
- package/dist/core/WeightedSummation.d.ts.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/klassValidation.d.ts +23 -0
- package/dist/core/klassValidation.d.ts.map +1 -0
- package/dist/drivers/Mysql.d.ts +1 -0
- package/dist/drivers/Mysql.d.ts.map +1 -1
- package/dist/drivers/PGLite.d.ts +1 -0
- package/dist/drivers/PGLite.d.ts.map +1 -1
- package/dist/drivers/PostgreSQL.d.ts +1 -0
- package/dist/drivers/PostgreSQL.d.ts.map +1 -1
- package/dist/drivers/SQLite.d.ts.map +1 -1
- package/dist/drivers.js +69 -40
- package/dist/drivers.js.map +1 -1
- package/dist/index.js +4057 -3763
- package/dist/index.js.map +1 -1
- package/dist/runtime/MonoSystem.d.ts +2 -0
- package/dist/runtime/MonoSystem.d.ts.map +1 -1
- package/dist/runtime/migration.d.ts.map +1 -1
- package/dist/storage/erstorage/CreationExecutor.d.ts.map +1 -1
- package/dist/storage/erstorage/FilteredEntityManager.d.ts +2 -2
- package/dist/storage/erstorage/FilteredEntityManager.d.ts.map +1 -1
- package/dist/storage/erstorage/MatchExp.d.ts +1 -1
- package/dist/storage/erstorage/MatchExp.d.ts.map +1 -1
- package/dist/storage/erstorage/NewRecordData.d.ts +13 -0
- package/dist/storage/erstorage/NewRecordData.d.ts.map +1 -1
- package/dist/storage/erstorage/QueryExecutor.d.ts.map +1 -1
- package/dist/storage/erstorage/RecordQueryAgent.d.ts.map +1 -1
- package/dist/storage/erstorage/SQLBuilder.d.ts +3 -1
- package/dist/storage/erstorage/SQLBuilder.d.ts.map +1 -1
- package/dist/storage/erstorage/UpdateExecutor.d.ts.map +1 -1
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/utils.d.ts +3 -0
- package/dist/storage/utils.d.ts.map +1 -1
- 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
|
|
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
|
|
6
|
-
import { PGlite as
|
|
5
|
+
import w from "pg";
|
|
6
|
+
import { PGlite as R } from "@electric-sql/pglite";
|
|
7
7
|
import E from "mysql2/promise";
|
|
8
|
-
let
|
|
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:
|
|
48
|
+
encodeLiteral: b,
|
|
49
49
|
constraints: { unique: !0, filteredUnique: !0, nonNull: !1 }
|
|
50
|
-
}, this.idSystem = new
|
|
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.
|
|
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 === "
|
|
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:
|
|
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
|
|
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
|
|
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
|
-
|
|
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 === "
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 === "
|
|
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
|
-
|
|
1049
|
+
v as MysqlDB,
|
|
1021
1050
|
z as PGLiteDB,
|
|
1022
1051
|
G as PostgreSQLDB,
|
|
1023
1052
|
K as SQLiteDB
|