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