@voltro/runtime 0.3.0 → 0.4.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/CHANGELOG.md +29 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +786 -772
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { ENCRYPTED_PREFIX as e, and as t, attachEagerLoads as n, boolean as r, clearRetentions as i, collectSubqueries as a, contains as o, decryptFieldsOnRead as s, deserializeArraysOnRead as c, encryptFieldsForWrite as l, eq as u, evaluatePredicate as d, generateId as f, getRelations as p, getTable as m, gt as h, gte as g, hasEagerLoads as _, id as v, inSet as y, integer as b,
|
|
2
|
-
import { createCipheriv as
|
|
3
|
-
import { EventEmitter as
|
|
4
|
-
import { ADMIN_SCOPE as
|
|
5
|
-
import { createLogger as
|
|
6
|
-
import { Cause as k, Clock as
|
|
7
|
-
import * as
|
|
8
|
-
import { createServer as
|
|
9
|
-
import { HttpClient as
|
|
10
|
-
import { NodeContext as
|
|
11
|
-
import { Rpc as
|
|
12
|
-
import { defineRestRoute as
|
|
13
|
-
import { AsyncLocalStorage as
|
|
14
|
-
import { SpanKind as
|
|
15
|
-
import { Kv as
|
|
16
|
-
import { apiKeyStrategy as
|
|
17
|
-
import { getCurrentWorkflowExecutionId as
|
|
18
|
-
import { ArrayFormatter as
|
|
19
|
-
import { spawn as
|
|
1
|
+
import { ENCRYPTED_PREFIX as e, and as t, attachEagerLoads as n, boolean as r, clearRetentions as i, collectSubqueries as a, contains as o, decryptFieldsOnRead as s, deserializeArraysOnRead as c, encryptFieldsForWrite as l, eq as u, evaluatePredicate as d, generateId as f, getRelations as p, getTable as m, gt as h, gte as g, hasEagerLoads as _, id as v, inSet as y, integer as b, isEncrypted as x, isNull as S, json as C, listRetentions as ee, lt as te, lte as ne, neq as w, or as re, queryFor as ie, registerRetention as ae, requireTable as oe, retentionTtlMsFromEnv as se, serializeArraysForWrite as ce, sweepRetention as le, table as T, text as E, timestamp as D, walkLeaves as ue } from "@voltro/database";
|
|
2
|
+
import { createCipheriv as de, createDecipheriv as fe, createHash as pe, randomBytes as me, randomUUID as he, scryptSync as ge } from "node:crypto";
|
|
3
|
+
import { EventEmitter as _e } from "node:events";
|
|
4
|
+
import { ADMIN_SCOPE as ve, ConnectionInfo as ye, SubjectService as O, UndoConflict as be, UndoForbidden as xe, UndoNotFound as Se, WorkflowRunHandleSchema as Ce, checkGuardsEffect as we, diffRows as Te, effectiveScopes as Ee, hasEffectiveScope as De, isIdKeyed as Oe, publishServerError as ke, requireScope as Ae, systemSubject as je, tsMs as Me } from "@voltro/protocol";
|
|
5
|
+
import { createLogger as Ne } from "@voltro/logger";
|
|
6
|
+
import { Cause as k, Clock as Pe, Context as Fe, Cron as A, Deferred as Ie, Duration as Le, Effect as j, Either as Re, Exit as ze, Layer as M, ManagedRuntime as Be, Metric as N, MetricBoundaries as Ve, MetricState as He, Option as P, Ref as F, Schema as I, Stream as L, Tracer as Ue } from "effect";
|
|
7
|
+
import * as We from "node:http";
|
|
8
|
+
import { createServer as Ge } from "node:http";
|
|
9
|
+
import { HttpClient as Ke, HttpClientRequest as qe, HttpLayerRouter as R, HttpServer as Je, HttpServerRequest as z, HttpServerResponse as B } from "@effect/platform";
|
|
10
|
+
import { NodeContext as Ye, NodeHttpServer as Xe, NodeRuntime as Ze } from "@effect/platform-node";
|
|
11
|
+
import { Rpc as Qe, RpcSerialization as $e, RpcServer as et } from "@effect/rpc";
|
|
12
|
+
import { defineRestRoute as tt, dispatchSharedPath as nt, requireScope as rt } from "@voltro/protocol/rest";
|
|
13
|
+
import { AsyncLocalStorage as it } from "node:async_hooks";
|
|
14
|
+
import { SpanKind as at, SpanStatusCode as ot } from "@opentelemetry/api";
|
|
15
|
+
import { Kv as st, KvError as ct, KvStore as lt, layerConnections as ut, layerMemory as dt, layerRedis as ft } from "@voltro/kv";
|
|
16
|
+
import { apiKeyStrategy as pt } from "@voltro/protocol/apikey";
|
|
17
|
+
import { getCurrentWorkflowExecutionId as mt, inspectWorkflow as ht } from "@voltro/workflow";
|
|
18
|
+
import { ArrayFormatter as gt } from "effect/ParseResult";
|
|
19
|
+
import { spawn as _t } from "node:child_process";
|
|
20
20
|
//#region src/matcher.ts
|
|
21
|
-
var
|
|
21
|
+
var vt = class {
|
|
22
22
|
byTable = /* @__PURE__ */ new Map();
|
|
23
23
|
register(e) {
|
|
24
24
|
let t = this.byTable.get(e.table);
|
|
@@ -59,9 +59,9 @@ var _t = class {
|
|
|
59
59
|
});
|
|
60
60
|
return { perTable: e };
|
|
61
61
|
}
|
|
62
|
-
},
|
|
62
|
+
}, yt = (e) => {
|
|
63
63
|
let t = [];
|
|
64
|
-
for (let n of
|
|
64
|
+
for (let n of ue(e)) n.conjunctive && n.path === void 0 && (n.op === "eq" && t.push({
|
|
65
65
|
column: n.column,
|
|
66
66
|
values: [n.value]
|
|
67
67
|
}), n.op === "in" && t.push({
|
|
@@ -69,18 +69,18 @@ var _t = class {
|
|
|
69
69
|
values: n.value
|
|
70
70
|
}));
|
|
71
71
|
return t;
|
|
72
|
-
},
|
|
72
|
+
}, bt = (e) => {
|
|
73
73
|
let t = [];
|
|
74
|
-
for (let n of
|
|
74
|
+
for (let n of ue(e)) n.conjunctive && n.path === void 0 && (n.op === "gt" || n.op === "gte" || n.op === "lt" || n.op === "lte") && t.push({
|
|
75
75
|
column: n.column,
|
|
76
76
|
op: n.op,
|
|
77
77
|
threshold: n.value
|
|
78
78
|
});
|
|
79
79
|
return t;
|
|
80
|
-
}, bt = (e, t) => {
|
|
81
|
-
for (let n of ce(e)) if (n.conjunctive && n.path === void 0 && n.op === "eq" && n.column === t) return n.value;
|
|
82
|
-
return null;
|
|
83
80
|
}, xt = (e, t) => {
|
|
81
|
+
for (let n of ue(e)) if (n.conjunctive && n.path === void 0 && n.op === "eq" && n.column === t) return n.value;
|
|
82
|
+
return null;
|
|
83
|
+
}, St = (e, t) => {
|
|
84
84
|
let n = [];
|
|
85
85
|
for (let r of e) {
|
|
86
86
|
let e = t(r);
|
|
@@ -88,8 +88,8 @@ var _t = class {
|
|
|
88
88
|
n.push(`${typeof e}:${String(e)}`);
|
|
89
89
|
}
|
|
90
90
|
return n.join("|");
|
|
91
|
-
},
|
|
92
|
-
let r =
|
|
91
|
+
}, Ct = (e, t) => e === null || t === null ? null : e === t ? 0 : typeof e == typeof t ? e > t ? 1 : -1 : null, wt = (e, t, n) => {
|
|
92
|
+
let r = Ct(e, n);
|
|
93
93
|
if (r === null) return !1;
|
|
94
94
|
switch (t) {
|
|
95
95
|
case "gt": return r > 0;
|
|
@@ -97,7 +97,7 @@ var _t = class {
|
|
|
97
97
|
case "lt": return r < 0;
|
|
98
98
|
case "lte": return r <= 0;
|
|
99
99
|
}
|
|
100
|
-
},
|
|
100
|
+
}, Tt = class {
|
|
101
101
|
columnByTable = /* @__PURE__ */ new Map();
|
|
102
102
|
rangeByTable = /* @__PURE__ */ new Map();
|
|
103
103
|
tupleByTable = /* @__PURE__ */ new Map();
|
|
@@ -105,9 +105,9 @@ var _t = class {
|
|
|
105
105
|
subscriptions = /* @__PURE__ */ new Map();
|
|
106
106
|
register(e) {
|
|
107
107
|
this.columnByTable.has(e.table) || this.columnByTable.set(e.table, /* @__PURE__ */ new Map()), this.rangeByTable.has(e.table) || this.rangeByTable.set(e.table, /* @__PURE__ */ new Map()), this.tupleByTable.has(e.table) || this.tupleByTable.set(e.table, /* @__PURE__ */ new Map()), this.unindexedByTable.has(e.table) || this.unindexedByTable.set(e.table, /* @__PURE__ */ new Set());
|
|
108
|
-
let t =
|
|
108
|
+
let t = yt(e.predicate), n = bt(e.predicate);
|
|
109
109
|
if (e.usingIndex !== void 0) {
|
|
110
|
-
let r = e.usingIndex, i =
|
|
110
|
+
let r = e.usingIndex, i = St(r.fields, (t) => xt(e.predicate, t));
|
|
111
111
|
if (i !== null) {
|
|
112
112
|
let a = `${r.name}|${i}`, o = this.tupleByTable.get(e.table), s = o.get(a);
|
|
113
113
|
s || (s = /* @__PURE__ */ new Set(), o.set(a, s)), s.add(e.id), this.subscriptions.set(e.id, {
|
|
@@ -252,7 +252,7 @@ var _t = class {
|
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
for (let [e, a] of i) {
|
|
255
|
-
let i =
|
|
255
|
+
let i = St(a, (e) => t[e]);
|
|
256
256
|
if (i === null) continue;
|
|
257
257
|
let o = r.get(`${e}|${i}`);
|
|
258
258
|
if (o) for (let e of o) n.add(e);
|
|
@@ -266,7 +266,7 @@ var _t = class {
|
|
|
266
266
|
let a = this.rangeByTable.get(e);
|
|
267
267
|
if (a) for (let [e, r] of a) {
|
|
268
268
|
let i = t[e];
|
|
269
|
-
if (i !== null) for (let [e, t] of r) for (let r of t)
|
|
269
|
+
if (i !== null) for (let [e, t] of r) for (let r of t) wt(i, e, r.threshold) && n.add(r.subId);
|
|
270
270
|
}
|
|
271
271
|
return n;
|
|
272
272
|
}
|
|
@@ -275,7 +275,7 @@ var _t = class {
|
|
|
275
275
|
let e = t[n.column];
|
|
276
276
|
if (n.kind === "eq") {
|
|
277
277
|
if (e !== n.value) return !1;
|
|
278
|
-
} else if (!
|
|
278
|
+
} else if (!wt(e, n.op, n.threshold)) return !1;
|
|
279
279
|
}
|
|
280
280
|
return !0;
|
|
281
281
|
}
|
|
@@ -297,23 +297,23 @@ var _t = class {
|
|
|
297
297
|
}
|
|
298
298
|
return i;
|
|
299
299
|
}
|
|
300
|
-
},
|
|
300
|
+
}, Et = (e) => {
|
|
301
301
|
if (e == null) return null;
|
|
302
|
-
if (Array.isArray(e)) return e.map(
|
|
302
|
+
if (Array.isArray(e)) return e.map(Et);
|
|
303
303
|
if (typeof e == "object") {
|
|
304
304
|
let t = e, n = Object.keys(t).sort(), r = {};
|
|
305
|
-
for (let e of n) r[e] =
|
|
305
|
+
for (let e of n) r[e] = Et(t[e]);
|
|
306
306
|
return r;
|
|
307
307
|
}
|
|
308
308
|
return e;
|
|
309
|
-
},
|
|
310
|
-
let r =
|
|
309
|
+
}, Dt = (e, t, n) => {
|
|
310
|
+
let r = Et({
|
|
311
311
|
table: e,
|
|
312
312
|
predicate: t,
|
|
313
313
|
indexHint: n ?? null
|
|
314
314
|
});
|
|
315
|
-
return
|
|
316
|
-
},
|
|
315
|
+
return pe("sha256").update(JSON.stringify(r)).digest("hex").slice(0, 16);
|
|
316
|
+
}, Ot = class {
|
|
317
317
|
matcher;
|
|
318
318
|
byFingerprint = /* @__PURE__ */ new Map();
|
|
319
319
|
byClient = /* @__PURE__ */ new Map();
|
|
@@ -332,7 +332,7 @@ var _t = class {
|
|
|
332
332
|
} catch {}
|
|
333
333
|
}
|
|
334
334
|
subscribe(e, t, n, r) {
|
|
335
|
-
let i =
|
|
335
|
+
let i = Dt(t, n, r?.name), a = this.byFingerprint.get(i);
|
|
336
336
|
return a ? (a.subscribers.add(e), this.byClient.set(e, i), this.notifyChange(), {
|
|
337
337
|
fingerprint: i,
|
|
338
338
|
deduplicated: !0
|
|
@@ -390,7 +390,7 @@ var _t = class {
|
|
|
390
390
|
});
|
|
391
391
|
return e;
|
|
392
392
|
}
|
|
393
|
-
},
|
|
393
|
+
}, kt = (e, t) => t.length === 0 ? e : [...e].sort((e, n) => {
|
|
394
394
|
for (let r of t) {
|
|
395
395
|
let t = e[r.column], i = n[r.column];
|
|
396
396
|
if (t === i) continue;
|
|
@@ -400,7 +400,7 @@ var _t = class {
|
|
|
400
400
|
return r.direction === "asc" ? a : -a;
|
|
401
401
|
}
|
|
402
402
|
return 0;
|
|
403
|
-
}),
|
|
403
|
+
}), At = (e, t, n) => {
|
|
404
404
|
let r = t.split("."), i = r[0], a = r.slice(1), o = (e) => typeof e == "object" && !!e && !Array.isArray(e), s = e[i], c;
|
|
405
405
|
if (a.length === 0) c = o(s) && o(n) ? {
|
|
406
406
|
...s,
|
|
@@ -418,11 +418,11 @@ var _t = class {
|
|
|
418
418
|
...e,
|
|
419
419
|
[i]: c
|
|
420
420
|
};
|
|
421
|
-
},
|
|
421
|
+
}, jt = (e, t, n) => !e || d(e, t, n), V = (e, t) => {
|
|
422
422
|
let n = /* @__PURE__ */ new Map();
|
|
423
423
|
if (!e) return n;
|
|
424
424
|
for (let r of a(e)) {
|
|
425
|
-
let e = t.get(r.descriptor.table) ?? /* @__PURE__ */ new Map(), i = V(r.descriptor.predicate, t), a =
|
|
425
|
+
let e = t.get(r.descriptor.table) ?? /* @__PURE__ */ new Map(), i = V(r.descriptor.predicate, t), a = Mt(r.descriptor, e, t, i);
|
|
426
426
|
if (r.kind === "exists") n.set(r.descriptor, a.length);
|
|
427
427
|
else {
|
|
428
428
|
let e = r.descriptor.projection, t = /* @__PURE__ */ new Set();
|
|
@@ -437,15 +437,15 @@ var _t = class {
|
|
|
437
437
|
}
|
|
438
438
|
}
|
|
439
439
|
return n;
|
|
440
|
-
},
|
|
441
|
-
let i = r ?? V(e.predicate, n), a = [...t.values()].filter((t) =>
|
|
440
|
+
}, Mt = (e, t, n = /* @__PURE__ */ new Map(), r = null) => {
|
|
441
|
+
let i = r ?? V(e.predicate, n), a = [...t.values()].filter((t) => jt(e.predicate, t, i));
|
|
442
442
|
if (e.aggregations && e.aggregations.length > 0) {
|
|
443
|
-
let t =
|
|
443
|
+
let t = Nt(a, e.aggregations, e.groupBy);
|
|
444
444
|
if (!e.having) return t;
|
|
445
445
|
let r = V(e.having, n);
|
|
446
|
-
return t.filter((t) =>
|
|
446
|
+
return t.filter((t) => jt(e.having, t, r));
|
|
447
447
|
}
|
|
448
|
-
let o =
|
|
448
|
+
let o = kt(a, e.order), s = e.skip ? o.slice(e.skip) : o, c = e.take === void 0 ? s : s.slice(0, e.take);
|
|
449
449
|
if (!e.projection) return c;
|
|
450
450
|
let l = e.projection;
|
|
451
451
|
return c.map((e) => {
|
|
@@ -453,7 +453,7 @@ var _t = class {
|
|
|
453
453
|
for (let n of l) t[n] = e[n];
|
|
454
454
|
return t;
|
|
455
455
|
});
|
|
456
|
-
},
|
|
456
|
+
}, Nt = (e, t, n) => {
|
|
457
457
|
let r = /* @__PURE__ */ new Map();
|
|
458
458
|
for (let t of e) {
|
|
459
459
|
let e = {};
|
|
@@ -471,11 +471,11 @@ var _t = class {
|
|
|
471
471
|
let i = [];
|
|
472
472
|
for (let e of r.values()) {
|
|
473
473
|
let n = { ...e.keyVals };
|
|
474
|
-
for (let r of t) n[r.alias] =
|
|
474
|
+
for (let r of t) n[r.alias] = Pt(r, e.rows);
|
|
475
475
|
i.push(n);
|
|
476
476
|
}
|
|
477
477
|
return i;
|
|
478
|
-
},
|
|
478
|
+
}, Pt = (e, t) => {
|
|
479
479
|
switch (e.op) {
|
|
480
480
|
case "count": return e.column === void 0 ? t.length : t.reduce((t, n) => t + +(n[e.column] !== null && n[e.column] !== void 0), 0);
|
|
481
481
|
case "count-distinct": {
|
|
@@ -519,7 +519,7 @@ var _t = class {
|
|
|
519
519
|
}
|
|
520
520
|
default: throw Error(`computeAggregates: unknown op '${e.op}'`);
|
|
521
521
|
}
|
|
522
|
-
},
|
|
522
|
+
}, Ft = "\0", It = (e, t) => e === null ? t : `${e}${Ft}${t}`, Lt = class e {
|
|
523
523
|
#e;
|
|
524
524
|
#t;
|
|
525
525
|
#n;
|
|
@@ -529,13 +529,13 @@ var _t = class {
|
|
|
529
529
|
return r.#e = t.tables, r.#t = t.emitter, r.#n = t.numericCounters, r;
|
|
530
530
|
}
|
|
531
531
|
constructor(e, t = null) {
|
|
532
|
-
if (this.#r = t, this.#e = /* @__PURE__ */ new Map(), this.#t = new
|
|
532
|
+
if (this.#r = t, this.#e = /* @__PURE__ */ new Map(), this.#t = new _e(), this.#n = /* @__PURE__ */ new Map(), e) for (let [n, r] of Object.entries(e)) {
|
|
533
533
|
let e = /* @__PURE__ */ new Map();
|
|
534
534
|
for (let t of r) {
|
|
535
535
|
let n = t.id;
|
|
536
536
|
n && e.set(n, t);
|
|
537
537
|
}
|
|
538
|
-
this.#e.set(
|
|
538
|
+
this.#e.set(It(t, n), e);
|
|
539
539
|
}
|
|
540
540
|
}
|
|
541
541
|
withNamespace(t) {
|
|
@@ -546,11 +546,11 @@ var _t = class {
|
|
|
546
546
|
}, t);
|
|
547
547
|
}
|
|
548
548
|
#a(e) {
|
|
549
|
-
return
|
|
549
|
+
return It(this.#r, e);
|
|
550
550
|
}
|
|
551
551
|
#o() {
|
|
552
|
-
let e = /* @__PURE__ */ new Map(), t = this.#r === null ? null : `${this.#r}${
|
|
553
|
-
for (let [n, r] of this.#e) t === null ? n.includes(
|
|
552
|
+
let e = /* @__PURE__ */ new Map(), t = this.#r === null ? null : `${this.#r}${Ft}`;
|
|
553
|
+
for (let [n, r] of this.#e) t === null ? n.includes(Ft) || e.set(n, r) : n.startsWith(t) && e.set(n.slice(t.length), r);
|
|
554
554
|
return e;
|
|
555
555
|
}
|
|
556
556
|
#s(e) {
|
|
@@ -558,8 +558,8 @@ var _t = class {
|
|
|
558
558
|
return n || (n = /* @__PURE__ */ new Map(), this.#e.set(t, n)), n;
|
|
559
559
|
}
|
|
560
560
|
async query(e) {
|
|
561
|
-
let t =
|
|
562
|
-
return _(e) ? n(t, e.eager,
|
|
561
|
+
let t = Mt(e, this.#e.get(this.#a(e.table)) ?? /* @__PURE__ */ new Map(), this.#o());
|
|
562
|
+
return _(e) ? n(t, e.eager, oe(e.table), (e) => this.query(e)) : t;
|
|
563
563
|
}
|
|
564
564
|
async insert(e, t) {
|
|
565
565
|
let n = t;
|
|
@@ -588,7 +588,7 @@ var _t = class {
|
|
|
588
588
|
if (!i) return null;
|
|
589
589
|
let a = i.get(t);
|
|
590
590
|
if (!a) return null;
|
|
591
|
-
let o =
|
|
591
|
+
let o = At(a, n, r);
|
|
592
592
|
return i.set(t, o), this.#t.emit("change", {
|
|
593
593
|
table: e,
|
|
594
594
|
op: "update",
|
|
@@ -688,7 +688,7 @@ var _t = class {
|
|
|
688
688
|
}
|
|
689
689
|
}
|
|
690
690
|
async transactional(e) {
|
|
691
|
-
let t = new
|
|
691
|
+
let t = new Rt(this.#u());
|
|
692
692
|
try {
|
|
693
693
|
let n = await e(t);
|
|
694
694
|
return t.commit(), n;
|
|
@@ -724,7 +724,7 @@ var _t = class {
|
|
|
724
724
|
allocateNumericId: (e) => this.#c(e)
|
|
725
725
|
};
|
|
726
726
|
}
|
|
727
|
-
},
|
|
727
|
+
}, Rt = class {
|
|
728
728
|
parent;
|
|
729
729
|
overlay = /* @__PURE__ */ new Map();
|
|
730
730
|
tombstones = /* @__PURE__ */ new Map();
|
|
@@ -754,8 +754,8 @@ var _t = class {
|
|
|
754
754
|
return t || (t = /* @__PURE__ */ new Map(), this.overlay.set(e, t)), t;
|
|
755
755
|
}
|
|
756
756
|
async query(e) {
|
|
757
|
-
let t = this.buildTablesView(e), r =
|
|
758
|
-
return _(e) ? n(r, e.eager,
|
|
757
|
+
let t = this.buildTablesView(e), r = Mt(e, this.materialise(e.table), t);
|
|
758
|
+
return _(e) ? n(r, e.eager, oe(e.table), (e) => this.query(e)) : r;
|
|
759
759
|
}
|
|
760
760
|
async insert(e, t) {
|
|
761
761
|
let n = t;
|
|
@@ -793,7 +793,7 @@ var _t = class {
|
|
|
793
793
|
async patchJson(e, t, n, r) {
|
|
794
794
|
let i = this.materialise(e).get(t);
|
|
795
795
|
if (!i) return null;
|
|
796
|
-
let a =
|
|
796
|
+
let a = At(i, n, r);
|
|
797
797
|
return this.getOrCreateOverlay(e).set(t, a), this.events.push({
|
|
798
798
|
table: e,
|
|
799
799
|
op: "update",
|
|
@@ -894,7 +894,7 @@ var _t = class {
|
|
|
894
894
|
discard() {
|
|
895
895
|
this.settled || (this.settled = !0, this.overlay.clear(), this.tombstones.clear(), this.events.length = 0);
|
|
896
896
|
}
|
|
897
|
-
},
|
|
897
|
+
}, zt = (e) => {
|
|
898
898
|
let t = {}, n = [], r = e;
|
|
899
899
|
for (let e = 0; e < 8 && typeof r == "object" && r; e++) {
|
|
900
900
|
let e = r;
|
|
@@ -905,23 +905,23 @@ var _t = class {
|
|
|
905
905
|
(o || s) && n.push(`${o || "Error"}${s ? `: ${s.slice(0, 200)}` : ""}`), r = e.cause;
|
|
906
906
|
}
|
|
907
907
|
return n.length > 0 && (t.dbCauseChain = n.join(" ← "), t.dbMessage === void 0 && (t.dbMessage = n[n.length - 1])), t;
|
|
908
|
-
},
|
|
908
|
+
}, Bt = (e) => {
|
|
909
909
|
let t = e.dbCode;
|
|
910
910
|
return t === "23503" || e.dbErrno === 1452 || t === 547 || t === "SQLITE_CONSTRAINT_FOREIGNKEY";
|
|
911
|
-
},
|
|
912
|
-
has: (t) =>
|
|
913
|
-
hasAny: (t) => t.some((t) =>
|
|
914
|
-
require: (t) =>
|
|
911
|
+
}, Vt = (e) => ({
|
|
912
|
+
has: (t) => De(e, t),
|
|
913
|
+
hasAny: (t) => t.some((t) => De(e, t)),
|
|
914
|
+
require: (t) => Ae(e, t),
|
|
915
915
|
get scopes() {
|
|
916
|
-
return
|
|
916
|
+
return Ee(e);
|
|
917
917
|
}
|
|
918
|
-
}),
|
|
918
|
+
}), Ht = (e) => {
|
|
919
919
|
let t = /* @__PURE__ */ new Set();
|
|
920
|
-
return
|
|
921
|
-
},
|
|
922
|
-
if (t.add(e.table), e.eager !== void 0 &&
|
|
923
|
-
if (e.ctes !== void 0) for (let n of e.ctes)
|
|
924
|
-
},
|
|
920
|
+
return Ut(e, t), t;
|
|
921
|
+
}, Ut = (e, t) => {
|
|
922
|
+
if (t.add(e.table), e.eager !== void 0 && Wt(e.table, e.eager, t), e.setOp !== void 0) for (let n of e.setOp.queries) Ut(n, t);
|
|
923
|
+
if (e.ctes !== void 0) for (let n of e.ctes) Ut(n.descriptor, t);
|
|
924
|
+
}, Wt = (e, t, n) => {
|
|
925
925
|
let r = p(e);
|
|
926
926
|
if (r !== void 0) for (let [e, i] of Object.entries(t)) {
|
|
927
927
|
let t = r[e];
|
|
@@ -929,13 +929,13 @@ var _t = class {
|
|
|
929
929
|
let a = i === !0 ? {} : i;
|
|
930
930
|
if (t.kind === "manyToMany") {
|
|
931
931
|
let e = t.through().tableName, r = t.target().tableName;
|
|
932
|
-
n.add(e), n.add(r), a.with !== void 0 &&
|
|
932
|
+
n.add(e), n.add(r), a.with !== void 0 && Wt(r, a.with, n);
|
|
933
933
|
} else {
|
|
934
934
|
let e = t.target().tableName;
|
|
935
|
-
n.add(e), a.with !== void 0 &&
|
|
935
|
+
n.add(e), a.with !== void 0 && Wt(e, a.with, n);
|
|
936
936
|
}
|
|
937
937
|
}
|
|
938
|
-
},
|
|
938
|
+
}, Gt = (e) => e.setOp !== void 0 || e.ctes !== void 0 && e.ctes.length > 0 || e.aggregations !== void 0 && e.aggregations.some((e) => e.op.startsWith("window-")), Kt = /* @__PURE__ */ new Set(["*"]), H = (e, t) => {
|
|
939
939
|
if (e !== void 0) {
|
|
940
940
|
if ("not" in e) {
|
|
941
941
|
H(e.not, t);
|
|
@@ -959,7 +959,7 @@ var _t = class {
|
|
|
959
959
|
let r = e.get(t);
|
|
960
960
|
r === void 0 && (r = /* @__PURE__ */ new Set(), e.set(t, r));
|
|
961
961
|
for (let e of n) r.add(e);
|
|
962
|
-
},
|
|
962
|
+
}, qt = (e, t, n) => {
|
|
963
963
|
let r = p(e);
|
|
964
964
|
if (r !== void 0) for (let [i, a] of Object.entries(t)) {
|
|
965
965
|
let t = r[i];
|
|
@@ -967,13 +967,13 @@ var _t = class {
|
|
|
967
967
|
let o = a === !0 ? {} : a;
|
|
968
968
|
if (t.kind === "manyToMany") {
|
|
969
969
|
let r = t.through(), i = t.target();
|
|
970
|
-
U(n, r.tableName, [t.sourceKey, t.targetKey]), U(n, e, ["id"]), U(n, i.tableName, ["id"]),
|
|
970
|
+
U(n, r.tableName, [t.sourceKey, t.targetKey]), U(n, e, ["id"]), U(n, i.tableName, ["id"]), Jt(i.tableName, o, n), o.with !== void 0 && qt(i.tableName, o.with, n);
|
|
971
971
|
continue;
|
|
972
972
|
}
|
|
973
973
|
let s = t.target();
|
|
974
|
-
t.foreignKey !== void 0 && U(n, s.tableName, [t.foreignKey]), t.sourceKey === void 0 ? U(n, e, ["id"]) : U(n, e, [t.sourceKey]), U(n, s.tableName, ["id"]),
|
|
974
|
+
t.foreignKey !== void 0 && U(n, s.tableName, [t.foreignKey]), t.sourceKey === void 0 ? U(n, e, ["id"]) : U(n, e, [t.sourceKey]), U(n, s.tableName, ["id"]), Jt(s.tableName, o, n), o.with !== void 0 && qt(s.tableName, o.with, n);
|
|
975
975
|
}
|
|
976
|
-
},
|
|
976
|
+
}, Jt = (e, t, n) => {
|
|
977
977
|
if (t.where !== void 0) {
|
|
978
978
|
let r = /* @__PURE__ */ new Set();
|
|
979
979
|
H(t.where, r), U(n, e, r);
|
|
@@ -981,10 +981,10 @@ var _t = class {
|
|
|
981
981
|
t.orderBy !== void 0 && U(n, e, t.orderBy.map((e) => e.column));
|
|
982
982
|
let r = m(e);
|
|
983
983
|
r === void 0 ? U(n, e, ["*"]) : U(n, e, Object.keys(r.fields));
|
|
984
|
-
},
|
|
984
|
+
}, Yt = (e) => {
|
|
985
985
|
let t = /* @__PURE__ */ new Map();
|
|
986
|
-
if (
|
|
987
|
-
for (let n of
|
|
986
|
+
if (Gt(e)) {
|
|
987
|
+
for (let n of Ht(e)) U(t, n, ["*"]);
|
|
988
988
|
return t;
|
|
989
989
|
}
|
|
990
990
|
let n = /* @__PURE__ */ new Set();
|
|
@@ -992,40 +992,40 @@ var _t = class {
|
|
|
992
992
|
else n.add("*");
|
|
993
993
|
H(e.predicate, n);
|
|
994
994
|
for (let t of e.order) n.add(t.column);
|
|
995
|
-
return U(t, e.table, n), e.eager !== void 0 &&
|
|
996
|
-
},
|
|
997
|
-
if (e.op === "insert" || e.op === "delete" || e.old === null || e.new === null) return
|
|
995
|
+
return U(t, e.table, n), e.eager !== void 0 && qt(e.table, e.eager, t), t;
|
|
996
|
+
}, Xt = (e) => {
|
|
997
|
+
if (e.op === "insert" || e.op === "delete" || e.old === null || e.new === null) return Kt;
|
|
998
998
|
let t = /* @__PURE__ */ new Set(), n = e.old, r = e.new, i = /* @__PURE__ */ new Set([...Object.keys(n), ...Object.keys(r)]);
|
|
999
999
|
for (let e of i) Object.is(n[e], r[e]) || t.add(e);
|
|
1000
1000
|
return t;
|
|
1001
|
-
},
|
|
1001
|
+
}, Zt = (e, t) => {
|
|
1002
1002
|
let n = t.get(e.table);
|
|
1003
1003
|
if (n === void 0) return !1;
|
|
1004
1004
|
if (n.has("*")) return !0;
|
|
1005
|
-
let r =
|
|
1005
|
+
let r = Xt(e);
|
|
1006
1006
|
if (r.has("*")) return !0;
|
|
1007
1007
|
for (let e of r) if (n.has(e)) return !0;
|
|
1008
1008
|
return !1;
|
|
1009
|
-
}, W =
|
|
1009
|
+
}, W = Ve.exponential({
|
|
1010
1010
|
start: .001,
|
|
1011
1011
|
factor: 2,
|
|
1012
1012
|
count: 16
|
|
1013
|
-
}),
|
|
1014
|
-
let t = e.durationMs / 1e3, n = e.kind === "rpc" ? j.zipRight(N.increment(
|
|
1013
|
+
}), Qt = N.counter("voltro_rpc_requests_total", { description: "Total RPC handler invocations." }), $t = N.counter("voltro_rpc_errors_total", { description: "RPC handler invocations that errored." }), en = N.histogram("voltro_rpc_duration_seconds", W, "RPC handler duration in seconds."), tn = N.counter("voltro_http_requests_total", { description: "Total HTTP route invocations." }), nn = N.histogram("voltro_http_duration_seconds", W, "HTTP route duration in seconds."), rn = N.histogram("voltro_plugin_hook_duration_seconds", W, "Plugin interceptor duration in seconds."), an = N.counter("voltro_plugin_hook_errors_total", { description: "Plugin interceptor invocations that errored." }), on = N.counter("voltro_subscription_deliveries_total", { description: "Total subscription deliveries (snapshot + delta)." }), sn = N.histogram("voltro_subscription_delivery_seconds", W, "Subscription delivery produce→push latency in seconds."), cn = N.gauge("voltro_subscriptions_active", { description: "Currently-open subscriptions." }), ln = (e) => {
|
|
1014
|
+
let t = e.durationMs / 1e3, n = e.kind === "rpc" ? j.zipRight(N.increment(Qt).pipe(j.tagMetrics("tag", e.tag), j.tagMetrics("status", e.status)), j.zipRight(N.update(en, t).pipe(j.tagMetrics("tag", e.tag)), e.status === "error" ? N.increment($t).pipe(j.tagMetrics("tag", e.tag)) : j.void)) : e.kind === "request" ? j.zipRight(N.increment(tn).pipe(j.tagMetrics("route", e.tag), j.tagMetrics("status", e.status)), N.update(nn, t).pipe(j.tagMetrics("route", e.tag))) : j.zipRight(N.update(rn, t).pipe(j.tagMetrics("hook", e.tag)), e.status === "error" ? N.increment(an).pipe(j.tagMetrics("hook", e.tag)) : j.void);
|
|
1015
1015
|
j.runSync(n);
|
|
1016
|
-
},
|
|
1017
|
-
let t =
|
|
1018
|
-
j.runSync(j.zipRight(N.increment(
|
|
1019
|
-
},
|
|
1020
|
-
let n =
|
|
1021
|
-
r === 0 ?
|
|
1022
|
-
},
|
|
1016
|
+
}, un = (e) => e.startsWith("subscription.") ? e.slice(13) : e, dn = (e) => {
|
|
1017
|
+
let t = un(e.label);
|
|
1018
|
+
j.runSync(j.zipRight(N.increment(on).pipe(j.tagMetrics("tag", t), j.tagMetrics("kind", e.kind)), N.update(sn, e.durationMs / 1e3).pipe(j.tagMetrics("tag", t), j.tagMetrics("kind", e.kind))));
|
|
1019
|
+
}, fn = /* @__PURE__ */ new Map(), pn = (e, t) => {
|
|
1020
|
+
let n = un(e), r = Math.max(0, (fn.get(n) ?? 0) + t);
|
|
1021
|
+
r === 0 ? fn.delete(n) : fn.set(n, r), j.runSync(N.set(cn, r).pipe(j.tagMetrics("tag", n)));
|
|
1022
|
+
}, mn = (e, t) => N.counter(e, t === void 0 ? {} : { description: t }), hn = (e, t) => N.gauge(e, t === void 0 ? {} : { description: t }), gn = (e, t = W, n) => N.histogram(e, t, n), _n = (e) => {
|
|
1023
1023
|
let t = {};
|
|
1024
1024
|
for (let n of e) t[n.key] = n.value;
|
|
1025
1025
|
return t;
|
|
1026
|
-
},
|
|
1027
|
-
let t = e.metricKey.name, n =
|
|
1028
|
-
if (
|
|
1026
|
+
}, vn = N.snapshot.pipe(j.map((e) => e.map((e) => {
|
|
1027
|
+
let t = e.metricKey.name, n = _n(e.metricKey.tags), r = P.getOrUndefined(e.metricKey.description), i = r === void 0 ? {} : { description: r }, a = e.metricState;
|
|
1028
|
+
if (He.isHistogramState(a)) return {
|
|
1029
1029
|
name: t,
|
|
1030
1030
|
labels: n,
|
|
1031
1031
|
...i,
|
|
@@ -1037,14 +1037,14 @@ var _t = class {
|
|
|
1037
1037
|
sum: a.sum,
|
|
1038
1038
|
count: a.count
|
|
1039
1039
|
};
|
|
1040
|
-
if (
|
|
1040
|
+
if (He.isGaugeState(a)) return {
|
|
1041
1041
|
name: t,
|
|
1042
1042
|
labels: n,
|
|
1043
1043
|
...i,
|
|
1044
1044
|
type: "gauge",
|
|
1045
1045
|
value: Number(a.value)
|
|
1046
1046
|
};
|
|
1047
|
-
if (
|
|
1047
|
+
if (He.isSummaryState(a)) return {
|
|
1048
1048
|
name: t,
|
|
1049
1049
|
labels: n,
|
|
1050
1050
|
...i,
|
|
@@ -1056,7 +1056,7 @@ var _t = class {
|
|
|
1056
1056
|
value: t.value
|
|
1057
1057
|
}] : [])
|
|
1058
1058
|
};
|
|
1059
|
-
if (
|
|
1059
|
+
if (He.isFrequencyState(a)) {
|
|
1060
1060
|
let e = {};
|
|
1061
1061
|
for (let [t, n] of a.occurrences) e[t] = n;
|
|
1062
1062
|
return {
|
|
@@ -1074,7 +1074,7 @@ var _t = class {
|
|
|
1074
1074
|
type: "counter",
|
|
1075
1075
|
value: Number(a.count)
|
|
1076
1076
|
};
|
|
1077
|
-
}))),
|
|
1077
|
+
}))), yn = () => j.runSync(vn), G = Ne({ scope: "voltro:dispatcher" }), bn = class {
|
|
1078
1078
|
deps;
|
|
1079
1079
|
subscriptionRegistry;
|
|
1080
1080
|
matcher;
|
|
@@ -1084,12 +1084,12 @@ var _t = class {
|
|
|
1084
1084
|
computedSubs = /* @__PURE__ */ new Map();
|
|
1085
1085
|
computedByTable = /* @__PURE__ */ new Map();
|
|
1086
1086
|
constructor(e) {
|
|
1087
|
-
this.deps = e, this.matcher = new
|
|
1087
|
+
this.deps = e, this.matcher = new Tt(), this.subscriptionRegistry = new Ot(this.matcher), this.unsubscribeChange = e.store.onChange((e) => {
|
|
1088
1088
|
this.handleChange(e);
|
|
1089
1089
|
});
|
|
1090
1090
|
}
|
|
1091
1091
|
async subscribe(e, t, n, r, i, a) {
|
|
1092
|
-
let o = `sub_${
|
|
1092
|
+
let o = `sub_${he()}`, s = i ?? `subscription.${e.table}`, c = Ht(e), l = Yt(e);
|
|
1093
1093
|
e.predicate !== void 0 && this.subscriptionRegistry.subscribe(o, e.table, e.predicate, r);
|
|
1094
1094
|
for (let e of c) {
|
|
1095
1095
|
let t = this.dependentByTable.get(e);
|
|
@@ -1106,7 +1106,7 @@ var _t = class {
|
|
|
1106
1106
|
relevantFields: l,
|
|
1107
1107
|
lastDelivered: f,
|
|
1108
1108
|
cacheBinding: a
|
|
1109
|
-
}),
|
|
1109
|
+
}), pn(s, 1), t({
|
|
1110
1110
|
_tag: "snapshot",
|
|
1111
1111
|
revision: 0,
|
|
1112
1112
|
data: f
|
|
@@ -1122,7 +1122,7 @@ var _t = class {
|
|
|
1122
1122
|
durationMs: p - u,
|
|
1123
1123
|
rowCount: f.length
|
|
1124
1124
|
}), () => {
|
|
1125
|
-
this.subscriptions.delete(o),
|
|
1125
|
+
this.subscriptions.delete(o), pn(s, -1), this.subscriptionRegistry.unsubscribe(o);
|
|
1126
1126
|
for (let e of c) {
|
|
1127
1127
|
let t = this.dependentByTable.get(e);
|
|
1128
1128
|
t !== void 0 && (t.delete(o), t.size === 0 && this.dependentByTable.delete(e));
|
|
@@ -1130,17 +1130,17 @@ var _t = class {
|
|
|
1130
1130
|
};
|
|
1131
1131
|
}
|
|
1132
1132
|
async subscribeComputed(e, t, n, r) {
|
|
1133
|
-
let i = `csub_${
|
|
1133
|
+
let i = `csub_${he()}`, a = e.dependentTables, o = {
|
|
1134
1134
|
id: i,
|
|
1135
1135
|
recompute: e.recompute,
|
|
1136
1136
|
tenantId: e.tenantId,
|
|
1137
1137
|
emit: t,
|
|
1138
1138
|
context: n,
|
|
1139
1139
|
label: r ?? "subscription.computed",
|
|
1140
|
-
lastJson:
|
|
1140
|
+
lastJson: xn(e.value),
|
|
1141
1141
|
revision: 0
|
|
1142
1142
|
};
|
|
1143
|
-
this.computedSubs.set(i, o),
|
|
1143
|
+
this.computedSubs.set(i, o), pn(o.label, 1);
|
|
1144
1144
|
for (let e of a) {
|
|
1145
1145
|
let t = this.computedByTable.get(e);
|
|
1146
1146
|
t === void 0 && (t = /* @__PURE__ */ new Set(), this.computedByTable.set(e, t)), t.add(i);
|
|
@@ -1160,7 +1160,7 @@ var _t = class {
|
|
|
1160
1160
|
durationMs: Date.now() - s,
|
|
1161
1161
|
rowCount: 1
|
|
1162
1162
|
}), () => {
|
|
1163
|
-
this.computedSubs.delete(i),
|
|
1163
|
+
this.computedSubs.delete(i), pn(o.label, -1);
|
|
1164
1164
|
for (let e of a) {
|
|
1165
1165
|
let t = this.computedByTable.get(e);
|
|
1166
1166
|
t !== void 0 && (t.delete(i), t.size === 0 && this.computedByTable.delete(e));
|
|
@@ -1170,7 +1170,7 @@ var _t = class {
|
|
|
1170
1170
|
async recomputeComputed(e) {
|
|
1171
1171
|
let t = Date.now();
|
|
1172
1172
|
try {
|
|
1173
|
-
let n = await e.recompute(), r =
|
|
1173
|
+
let n = await e.recompute(), r = xn(n);
|
|
1174
1174
|
if (r === e.lastJson) return;
|
|
1175
1175
|
e.lastJson = r, e.revision += 1;
|
|
1176
1176
|
let i = Date.now();
|
|
@@ -1238,25 +1238,25 @@ var _t = class {
|
|
|
1238
1238
|
G.trace("missing subscription", { subscriberId: t });
|
|
1239
1239
|
continue;
|
|
1240
1240
|
}
|
|
1241
|
-
if (!
|
|
1241
|
+
if (!Zt(e, n.relevantFields)) {
|
|
1242
1242
|
o++;
|
|
1243
1243
|
continue;
|
|
1244
1244
|
}
|
|
1245
1245
|
let r = Date.now();
|
|
1246
1246
|
try {
|
|
1247
1247
|
let i = await this.deps.store.query(n.descriptor), o = n.lastDelivered;
|
|
1248
|
-
if (
|
|
1248
|
+
if (Sn(i, o)) {
|
|
1249
1249
|
G.trace("suppressed no-op delta", {
|
|
1250
1250
|
subscriberId: t,
|
|
1251
1251
|
table: e.table
|
|
1252
1252
|
});
|
|
1253
1253
|
continue;
|
|
1254
1254
|
}
|
|
1255
|
-
n.lastDelivered = i, this.deps.cache !== void 0 && n.cacheBinding !== void 0 && this.deps.cache.put(n.cacheBinding, Array.from(n.dependentTables), i),
|
|
1255
|
+
n.lastDelivered = i, this.deps.cache !== void 0 && n.cacheBinding !== void 0 && this.deps.cache.put(n.cacheBinding, Array.from(n.dependentTables), i), Oe(o) && Oe(i) ? n.emit({
|
|
1256
1256
|
_tag: "delta",
|
|
1257
1257
|
revision: a,
|
|
1258
1258
|
emittedAt: a,
|
|
1259
|
-
patch:
|
|
1259
|
+
patch: Te(o, i)
|
|
1260
1260
|
}) : n.emit({
|
|
1261
1261
|
_tag: "snapshot",
|
|
1262
1262
|
revision: a,
|
|
@@ -1288,44 +1288,44 @@ var _t = class {
|
|
|
1288
1288
|
skipped: o
|
|
1289
1289
|
});
|
|
1290
1290
|
}
|
|
1291
|
-
},
|
|
1291
|
+
}, xn = (e) => {
|
|
1292
1292
|
try {
|
|
1293
1293
|
return JSON.stringify(e) ?? "null";
|
|
1294
1294
|
} catch {
|
|
1295
1295
|
return String(e);
|
|
1296
1296
|
}
|
|
1297
|
-
},
|
|
1297
|
+
}, Sn = (e, t) => {
|
|
1298
1298
|
if (e === t) return !0;
|
|
1299
1299
|
if (e.length !== t.length) return !1;
|
|
1300
1300
|
for (let n = 0; n < e.length; n++) if (JSON.stringify(e[n]) !== JSON.stringify(t[n])) return !1;
|
|
1301
1301
|
return !0;
|
|
1302
|
-
},
|
|
1302
|
+
}, Cn = (e) => typeof e == "object" && !!e && e.__voltroComputed === !0, wn = 1440 * 60 * 1e3, Tn = 3600 * 1e3, K = /* @__PURE__ */ new Map(), En = /* @__PURE__ */ new Set(), Dn = (e, t) => {
|
|
1303
1303
|
K.set(e, {
|
|
1304
1304
|
subject: t,
|
|
1305
1305
|
touchedAt: Date.now()
|
|
1306
1306
|
});
|
|
1307
|
-
for (let n of
|
|
1307
|
+
for (let n of En) try {
|
|
1308
1308
|
n(e, t);
|
|
1309
1309
|
} catch {}
|
|
1310
|
-
},
|
|
1310
|
+
}, On = (e) => {
|
|
1311
1311
|
let t = K.get(e);
|
|
1312
1312
|
if (t) return t.touchedAt = Date.now(), t.subject;
|
|
1313
|
-
},
|
|
1313
|
+
}, kn = (e) => {
|
|
1314
1314
|
K.delete(e);
|
|
1315
|
-
},
|
|
1316
|
-
|
|
1317
|
-
}),
|
|
1318
|
-
let e = Date.now() -
|
|
1315
|
+
}, An = (e) => (En.add(e), () => {
|
|
1316
|
+
En.delete(e);
|
|
1317
|
+
}), jn = setInterval(() => {
|
|
1318
|
+
let e = Date.now() - wn;
|
|
1319
1319
|
for (let [t, n] of K) n.touchedAt < e && K.delete(t);
|
|
1320
|
-
},
|
|
1321
|
-
typeof
|
|
1322
|
-
var q = /* @__PURE__ */ new Map(),
|
|
1320
|
+
}, Tn);
|
|
1321
|
+
typeof jn == "object" && jn && "unref" in jn && jn.unref();
|
|
1322
|
+
var q = /* @__PURE__ */ new Map(), Mn = (e, t) => {
|
|
1323
1323
|
let n = q.get(e);
|
|
1324
1324
|
return n || (n = /* @__PURE__ */ new Set(), q.set(e, n)), n.add(t), () => {
|
|
1325
1325
|
let n = q.get(e);
|
|
1326
1326
|
n && (n.delete(t), n.size === 0 && q.delete(e));
|
|
1327
1327
|
};
|
|
1328
|
-
},
|
|
1328
|
+
}, Nn = (e) => {
|
|
1329
1329
|
let t = q.get(e);
|
|
1330
1330
|
if (t) {
|
|
1331
1331
|
for (let e of [...t]) try {
|
|
@@ -1333,15 +1333,15 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1333
1333
|
} catch {}
|
|
1334
1334
|
q.delete(e);
|
|
1335
1335
|
}
|
|
1336
|
-
},
|
|
1336
|
+
}, Pn = (e) => q.get(e)?.size ?? 0, Fn = () => {
|
|
1337
1337
|
K.clear(), q.clear();
|
|
1338
|
-
},
|
|
1338
|
+
}, In = () => [...K.entries()].map(([e, t]) => ({
|
|
1339
1339
|
clientId: e,
|
|
1340
1340
|
subjectType: t.subject.type,
|
|
1341
1341
|
tenantId: t.subject.tenantId
|
|
1342
|
-
})),
|
|
1342
|
+
})), Ln = /^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/, Rn = (e) => `00-${e.traceId}-${e.spanId}-${e.sampled ? "01" : "00"}`, zn = (e) => {
|
|
1343
1343
|
if (typeof e != "string") return null;
|
|
1344
|
-
let t =
|
|
1344
|
+
let t = Ln.exec(e.trim().toLowerCase());
|
|
1345
1345
|
if (t === null) return null;
|
|
1346
1346
|
let [, n, r, i] = t;
|
|
1347
1347
|
return n === "0".repeat(32) || r === "0".repeat(16) ? null : {
|
|
@@ -1349,14 +1349,14 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1349
1349
|
spanId: r,
|
|
1350
1350
|
sampled: (parseInt(i, 16) & 1) == 1
|
|
1351
1351
|
};
|
|
1352
|
-
},
|
|
1353
|
-
let t =
|
|
1354
|
-
if (t !== null) return
|
|
1352
|
+
}, Bn = (e) => {
|
|
1353
|
+
let t = zn(e);
|
|
1354
|
+
if (t !== null) return Ue.externalSpan({
|
|
1355
1355
|
traceId: t.traceId,
|
|
1356
1356
|
spanId: t.spanId,
|
|
1357
1357
|
sampled: t.sampled
|
|
1358
1358
|
});
|
|
1359
|
-
},
|
|
1359
|
+
}, Vn = new it(), Hn = (e, t) => Vn.run(e, t), Un = () => Vn.getStore(), Wn = (e = {}) => {
|
|
1360
1360
|
let t = e.random ?? Math.random, n = /* @__PURE__ */ new Map(), r = (e) => n.get(e) ?? 0;
|
|
1361
1361
|
return {
|
|
1362
1362
|
pick(e) {
|
|
@@ -1381,7 +1381,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1381
1381
|
}));
|
|
1382
1382
|
}
|
|
1383
1383
|
};
|
|
1384
|
-
},
|
|
1384
|
+
}, Gn = (e = {}) => {
|
|
1385
1385
|
let t = e.thresholdFailures ?? 3, n = e.windowMs ?? 1e4, r = e.blackoutMs ?? 6e4, i = e.now ?? Date.now, a = /* @__PURE__ */ new Map(), o = (e) => {
|
|
1386
1386
|
let t = a.get(e);
|
|
1387
1387
|
return t === void 0 && (t = {
|
|
@@ -1415,7 +1415,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1415
1415
|
}));
|
|
1416
1416
|
}
|
|
1417
1417
|
};
|
|
1418
|
-
},
|
|
1418
|
+
}, Kn = (e = {}) => {
|
|
1419
1419
|
let t = e.now ?? Date.now, n = /* @__PURE__ */ new Map();
|
|
1420
1420
|
return {
|
|
1421
1421
|
get(e) {
|
|
@@ -1438,7 +1438,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1438
1438
|
return n.size;
|
|
1439
1439
|
}
|
|
1440
1440
|
};
|
|
1441
|
-
},
|
|
1441
|
+
}, qn = (e, t) => e === null ? t === void 0 ? "anon:bg" : `anon:${t}` : `subject:${e}`, Jn = (e) => {
|
|
1442
1442
|
let t = e.now ?? Date.now, n = e.keyPrefix ?? "voltro:ryw", r = e.channel ?? `${n}:bus`, i = e.onError ?? ((e, t) => {
|
|
1443
1443
|
process.stderr.write(`[voltro:ryw] redis ${t} failed: ${String(e)}\n`);
|
|
1444
1444
|
}), a = `${process.pid ?? 0}:${Math.random() * 1e9 | 0}:${t()}`, o = /* @__PURE__ */ new Map(), s = (e) => {
|
|
@@ -1497,7 +1497,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1497
1497
|
return o.size;
|
|
1498
1498
|
}
|
|
1499
1499
|
};
|
|
1500
|
-
},
|
|
1500
|
+
}, Yn = Ne({ scope: "voltro:replication" }), Xn = new it(), Zn = (e, t) => Xn.run(e, t), Qn = () => Xn.getStore(), $n = class {
|
|
1501
1501
|
primary;
|
|
1502
1502
|
replicas;
|
|
1503
1503
|
adapter;
|
|
@@ -1510,10 +1510,10 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1510
1510
|
recordRouting;
|
|
1511
1511
|
now;
|
|
1512
1512
|
constructor(e) {
|
|
1513
|
-
this.primary = e.primary, this.replicas = e.replicas, this.adapter = e.replicationAdapter, this.policy = e.rywPolicy ?? "fallback", this.rywTtlMs = e.rywTtlMs ?? 3e4, this.rywMaxWaitMs = e.rywMaxWaitMs ?? 500, this.now = e.now ?? Date.now, this.rywStore = e.rywStore ??
|
|
1513
|
+
this.primary = e.primary, this.replicas = e.replicas, this.adapter = e.replicationAdapter, this.policy = e.rywPolicy ?? "fallback", this.rywTtlMs = e.rywTtlMs ?? 3e4, this.rywMaxWaitMs = e.rywMaxWaitMs ?? 500, this.now = e.now ?? Date.now, this.rywStore = e.rywStore ?? Kn({ now: this.now }), this.selector = e.replicaSelector ?? Wn(), this.health = e.replicaHealth ?? Gn({ now: this.now }), e.recordRouting !== void 0 && (this.recordRouting = e.recordRouting);
|
|
1514
1514
|
}
|
|
1515
1515
|
async query(e) {
|
|
1516
|
-
let t =
|
|
1516
|
+
let t = Xn.getStore(), n = t?.subjectKey ?? "anon:bg";
|
|
1517
1517
|
if (t?.forcePrimary === !0) return this.emitRouting({
|
|
1518
1518
|
target: "primary",
|
|
1519
1519
|
replicaIndex: null,
|
|
@@ -1577,7 +1577,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1577
1577
|
waitMs: 0
|
|
1578
1578
|
}), r;
|
|
1579
1579
|
} catch (r) {
|
|
1580
|
-
return this.health.reportFailure(i, String(r)),
|
|
1580
|
+
return this.health.reportFailure(i, String(r)), Yn.warn("replica query failed; falling back to primary", {
|
|
1581
1581
|
idx: a,
|
|
1582
1582
|
err: r
|
|
1583
1583
|
}), this.emitRouting({
|
|
@@ -1646,7 +1646,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1646
1646
|
fallbackReason: "wait-timeout"
|
|
1647
1647
|
}), this.primary.query(e);
|
|
1648
1648
|
}
|
|
1649
|
-
await
|
|
1649
|
+
await er(10);
|
|
1650
1650
|
}
|
|
1651
1651
|
}
|
|
1652
1652
|
async insert(e, t) {
|
|
@@ -1686,8 +1686,8 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1686
1686
|
return await this.stampPostWrite(), r;
|
|
1687
1687
|
}
|
|
1688
1688
|
async transactional(e) {
|
|
1689
|
-
let t = await
|
|
1690
|
-
subjectKey:
|
|
1689
|
+
let t = await Zn({
|
|
1690
|
+
subjectKey: Xn.getStore()?.subjectKey ?? "anon:bg",
|
|
1691
1691
|
forcePrimary: !0
|
|
1692
1692
|
}, () => this.primary.transactional(e));
|
|
1693
1693
|
return await this.stampPostWrite(), t;
|
|
@@ -1703,7 +1703,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1703
1703
|
}
|
|
1704
1704
|
async stampPostWrite() {
|
|
1705
1705
|
if (this.replicas.length === 0) return;
|
|
1706
|
-
let e =
|
|
1706
|
+
let e = Xn.getStore()?.subjectKey ?? "anon:bg";
|
|
1707
1707
|
try {
|
|
1708
1708
|
let t = await this.adapter.capturePrimaryPosition(this.primary);
|
|
1709
1709
|
this.rywStore.set(e, {
|
|
@@ -1711,29 +1711,29 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1711
1711
|
expiresAt: this.now() + this.rywTtlMs
|
|
1712
1712
|
});
|
|
1713
1713
|
} catch (e) {
|
|
1714
|
-
|
|
1714
|
+
Yn.warn("failed to capture primary position; RYW skipped", { err: e });
|
|
1715
1715
|
}
|
|
1716
1716
|
}
|
|
1717
1717
|
emitRouting(e) {
|
|
1718
1718
|
this.recordRouting?.(e);
|
|
1719
1719
|
}
|
|
1720
|
-
},
|
|
1720
|
+
}, er = (e) => new Promise((t) => setTimeout(t, e)), tr = (e, t, n) => ({
|
|
1721
1721
|
subject: e,
|
|
1722
|
-
traceId: t?.traceId ??
|
|
1722
|
+
traceId: t?.traceId ?? he(),
|
|
1723
1723
|
...t?.spanId === void 0 ? {} : { spanId: t.spanId },
|
|
1724
1724
|
...n === void 0 ? {} : { clientId: n }
|
|
1725
|
-
}),
|
|
1725
|
+
}), nr = j.currentSpan.pipe(j.catchAll(() => j.succeed(void 0))), rr = (e) => ({
|
|
1726
1726
|
traceId: e.traceId,
|
|
1727
1727
|
...e.spanId === void 0 ? {} : { spanId: e.spanId }
|
|
1728
|
-
}),
|
|
1728
|
+
}), ir = (e, t, n) => {
|
|
1729
1729
|
e !== void 0 && (e.attribute("rpc.tag", t), e.attribute("subject.type", n.type), n.tenantId !== void 0 && n.tenantId !== null && e.attribute("tenant.id", n.tenantId));
|
|
1730
|
-
},
|
|
1730
|
+
}, ar = (e, t, n, r, i, a) => L.asyncScoped((o) => j.gen(function* () {
|
|
1731
1731
|
let s = yield* j.tryPromise(() => t.subscribe(e, (e) => {
|
|
1732
1732
|
o.single(e);
|
|
1733
1733
|
}, n, r, i, a)).pipe(j.matchCause({
|
|
1734
|
-
onFailure: (e) => (
|
|
1734
|
+
onFailure: (e) => (dr(`subscription.${i}`, n.traceId, e), {
|
|
1735
1735
|
ok: !1,
|
|
1736
|
-
error:
|
|
1736
|
+
error: hr(e)
|
|
1737
1737
|
}),
|
|
1738
1738
|
onSuccess: (e) => ({
|
|
1739
1739
|
ok: !0,
|
|
@@ -1749,21 +1749,21 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1749
1749
|
}
|
|
1750
1750
|
let c = s.unsubscribe;
|
|
1751
1751
|
if (yield* j.addFinalizer(() => j.sync(() => c())), n.clientId !== void 0) {
|
|
1752
|
-
let e =
|
|
1752
|
+
let e = Mn(n.clientId, () => {
|
|
1753
1753
|
o.end();
|
|
1754
1754
|
});
|
|
1755
1755
|
yield* j.addFinalizer(() => j.sync(() => e()));
|
|
1756
1756
|
}
|
|
1757
|
-
})),
|
|
1757
|
+
})), or = (e, t, n, r) => L.asyncScoped((i) => j.gen(function* () {
|
|
1758
1758
|
let a = yield* j.tryPromise(() => t.subscribeComputed(e, (e) => {
|
|
1759
1759
|
i.single(e._tag === "snapshot" ? {
|
|
1760
1760
|
...e,
|
|
1761
1761
|
computed: !0
|
|
1762
1762
|
} : e);
|
|
1763
1763
|
}, n, r)).pipe(j.matchCause({
|
|
1764
|
-
onFailure: (e) => (
|
|
1764
|
+
onFailure: (e) => (dr(`subscription.${r}`, n.traceId, e), {
|
|
1765
1765
|
ok: !1,
|
|
1766
|
-
error:
|
|
1766
|
+
error: hr(e)
|
|
1767
1767
|
}),
|
|
1768
1768
|
onSuccess: (e) => ({
|
|
1769
1769
|
ok: !0,
|
|
@@ -1779,21 +1779,21 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1779
1779
|
}
|
|
1780
1780
|
let o = a.unsubscribe;
|
|
1781
1781
|
if (yield* j.addFinalizer(() => j.sync(() => o())), n.clientId !== void 0) {
|
|
1782
|
-
let e =
|
|
1782
|
+
let e = Mn(n.clientId, () => {
|
|
1783
1783
|
i.end();
|
|
1784
1784
|
});
|
|
1785
1785
|
yield* j.addFinalizer(() => j.sync(() => e()));
|
|
1786
1786
|
}
|
|
1787
|
-
})),
|
|
1788
|
-
let a = yield*
|
|
1789
|
-
|
|
1790
|
-
let c =
|
|
1787
|
+
})), sr = (e, t, n = "rpc.subscription", r, i) => L.unwrap(j.gen(function* () {
|
|
1788
|
+
let a = yield* O, o = yield* ye, s = yield* nr;
|
|
1789
|
+
ir(s, n, a);
|
|
1790
|
+
let c = tr(a, s, o.clientId), l = qn(a.id, o.clientId), u = Zn({ subjectKey: l }, () => Hn({
|
|
1791
1791
|
traceId: c.traceId,
|
|
1792
1792
|
...c.spanId === void 0 ? {} : { spanId: c.spanId }
|
|
1793
1793
|
}, () => e(c))), d = j.isEffect(u) ? yield* u.pipe(j.matchCause({
|
|
1794
|
-
onFailure: (e) => (
|
|
1794
|
+
onFailure: (e) => (dr(`subscription.${n}`, c.traceId, e), {
|
|
1795
1795
|
ok: !1,
|
|
1796
|
-
error:
|
|
1796
|
+
error: hr(e)
|
|
1797
1797
|
}),
|
|
1798
1798
|
onSuccess: (e) => ({
|
|
1799
1799
|
ok: !0,
|
|
@@ -1808,38 +1808,38 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1808
1808
|
error: d.error
|
|
1809
1809
|
});
|
|
1810
1810
|
let f = d.value;
|
|
1811
|
-
if (
|
|
1811
|
+
if (Cn(f)) return or(f, t, c, n);
|
|
1812
1812
|
let p = f, m = r?.(p);
|
|
1813
|
-
return
|
|
1813
|
+
return ar(p, t, c, m, n, i === void 0 ? void 0 : {
|
|
1814
1814
|
key: i.scope === "subject" ? `${i.baseKey}:s:${l}` : `${i.baseKey}:global`,
|
|
1815
1815
|
ttlMs: i.ttlMs,
|
|
1816
1816
|
swrMs: i.swrMs
|
|
1817
1817
|
});
|
|
1818
|
-
}).pipe(j.withSpan(n, { attributes: { "framework.kind": "subscription" } }))),
|
|
1819
|
-
let n = yield*
|
|
1820
|
-
|
|
1821
|
-
let a =
|
|
1818
|
+
}).pipe(j.withSpan(n, { attributes: { "framework.kind": "subscription" } }))), cr = (e, t = "rpc.stream") => L.unwrap(j.gen(function* () {
|
|
1819
|
+
let n = yield* O, r = yield* ye, i = yield* nr;
|
|
1820
|
+
ir(i, t, n);
|
|
1821
|
+
let a = tr(n, i, r.clientId), o = e(a), s = j.isEffect(o) ? yield* o.pipe(j.orDie) : o;
|
|
1822
1822
|
if (a.clientId === void 0) return s;
|
|
1823
1823
|
let c = a.clientId;
|
|
1824
1824
|
return L.unwrapScoped(j.gen(function* () {
|
|
1825
|
-
let e = yield*
|
|
1826
|
-
|
|
1825
|
+
let e = yield* Ie.make(), t = Mn(c, () => {
|
|
1826
|
+
Ie.unsafeDone(e, j.void);
|
|
1827
1827
|
});
|
|
1828
|
-
return yield* j.addFinalizer(() => j.sync(() => t())), s.pipe(L.interruptWhen(
|
|
1828
|
+
return yield* j.addFinalizer(() => j.sync(() => t())), s.pipe(L.interruptWhen(Ie.await(e)));
|
|
1829
1829
|
}));
|
|
1830
|
-
}).pipe(j.withSpan(t, { attributes: { "framework.kind": "stream" } }))),
|
|
1830
|
+
}).pipe(j.withSpan(t, { attributes: { "framework.kind": "stream" } }))), lr = Ne({ scope: "voltro:rpc" }), ur = Ne({ scope: "voltro:http" }), dr = (e, t, n) => {
|
|
1831
1831
|
if (k.isInterruptedOnly(n)) return;
|
|
1832
|
-
let r = k.squash(n), i = r?._tag, a = r instanceof Error ? r.message : r?.message ?? String(r), o = k.dieOption(n)._tag === "Some", s =
|
|
1832
|
+
let r = k.squash(n), i = r?._tag, a = r instanceof Error ? r.message : r?.message ?? String(r), o = k.dieOption(n)._tag === "Some", s = zt(r), c = {
|
|
1833
1833
|
traceId: t,
|
|
1834
1834
|
...i === void 0 ? {} : { errorTag: i },
|
|
1835
1835
|
...s
|
|
1836
1836
|
}, l = a === "Failed to execute statement" && typeof s.dbMessage == "string" ? s.dbMessage : a;
|
|
1837
|
-
o ?
|
|
1838
|
-
},
|
|
1837
|
+
o ? lr.error(`${e} failed: ${l}`, c) : lr.warn(`${e} failed: ${l}`, c);
|
|
1838
|
+
}, fr = /* @__PURE__ */ new Set(["SqlError", "ResultLengthMismatch"]), pr = (e) => typeof e == "object" && !!e && typeof e._tag == "string" && fr.has(e._tag), mr = (e) => ({
|
|
1839
1839
|
_tag: "InternalError",
|
|
1840
1840
|
message: "internal server error",
|
|
1841
1841
|
traceId: e
|
|
1842
|
-
}),
|
|
1842
|
+
}), hr = (e) => {
|
|
1843
1843
|
let t = k.squash(e);
|
|
1844
1844
|
t && typeof t == "object" && t._tag === "UnknownException" && (t = t.error ?? t.cause ?? t);
|
|
1845
1845
|
let n = t && typeof t == "object" ? t : {}, r = {};
|
|
@@ -1850,19 +1850,19 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1850
1850
|
...typeof i == "string" ? { _tag: i } : {},
|
|
1851
1851
|
message: typeof a == "string" ? a : String(t)
|
|
1852
1852
|
};
|
|
1853
|
-
},
|
|
1854
|
-
let r = yield*
|
|
1855
|
-
|
|
1856
|
-
let o =
|
|
1853
|
+
}, gr = (e, t, n = "rpc.mutation") => j.gen(function* () {
|
|
1854
|
+
let r = yield* O, i = yield* ye, a = yield* nr;
|
|
1855
|
+
ir(a, n, r);
|
|
1856
|
+
let o = tr(r, a, i.clientId), s = Zn({ subjectKey: qn(r.id, i.clientId) }, () => Hn({
|
|
1857
1857
|
traceId: o.traceId,
|
|
1858
1858
|
...o.spanId === void 0 ? {} : { spanId: o.spanId }
|
|
1859
1859
|
}, () => e(t, o)));
|
|
1860
1860
|
return yield* (j.isEffect(s) ? s : j.tryPromise({
|
|
1861
1861
|
try: () => Promise.resolve(s),
|
|
1862
1862
|
catch: (e) => e
|
|
1863
|
-
})).pipe(j.tapErrorCause((e) => j.sync(() =>
|
|
1864
|
-
}).pipe(j.withSpan(n, { attributes: { "framework.kind": "mutation" } })),
|
|
1865
|
-
let t = e.port ?? 4e3, n = e.path ?? "/ws", r =
|
|
1863
|
+
})).pipe(j.tapErrorCause((e) => j.sync(() => dr(n, o.traceId, e))), j.catchIf(pr, () => j.die(mr(o.traceId))), j.annotateLogs(rr(o)));
|
|
1864
|
+
}).pipe(j.withSpan(n, { attributes: { "framework.kind": "mutation" } })), _r = 8 * 1024 * 1024, vr = (e) => {
|
|
1865
|
+
let t = e.port ?? 4e3, n = e.path ?? "/ws", r = Ge(), i = (t) => z.HttpServerRequest.pipe(j.flatMap((t) => j.gen(function* () {
|
|
1866
1866
|
if (!e.inspectRoute) return B.text("inspect route not configured", { status: 404 });
|
|
1867
1867
|
let n = {};
|
|
1868
1868
|
for (let [e, r] of Object.entries(t.headers)) r !== void 0 && (n[e.toLowerCase()] = Array.isArray(r) ? r.join(", ") : r);
|
|
@@ -1938,7 +1938,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1938
1938
|
let t = (e) => z.HttpServerRequest.pipe(j.flatMap((t) => j.gen(function* () {
|
|
1939
1939
|
let n = {};
|
|
1940
1940
|
for (let [e, r] of Object.entries(t.headers)) r !== void 0 && (n[e.toLowerCase()] = Array.isArray(r) ? r.join(", ") : r);
|
|
1941
|
-
let r = t.method !== "GET" && t.method !== "HEAD" ? yield* t.text.pipe(j.orElseSucceed(() => "")) : "", i = new TextEncoder().encode(r), a = t.url.split("?")[0], o =
|
|
1941
|
+
let r = t.method !== "GET" && t.method !== "HEAD" ? yield* t.text.pipe(j.orElseSucceed(() => "")) : "", i = new TextEncoder().encode(r), a = t.url.split("?")[0], o = Bn(n.traceparent), s = yield* j.promise(() => e.handle({
|
|
1942
1942
|
method: t.method,
|
|
1943
1943
|
path: a,
|
|
1944
1944
|
headers: n,
|
|
@@ -1968,8 +1968,8 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1968
1968
|
query: a,
|
|
1969
1969
|
headers: n,
|
|
1970
1970
|
rawBody: o
|
|
1971
|
-
}, c = yield* j.promise(() =>
|
|
1972
|
-
c.status >= 500 &&
|
|
1971
|
+
}, c = yield* j.promise(() => nt(e, s));
|
|
1972
|
+
c.status >= 500 && ur.warn(`${t.method} ${i} → ${c.status}`, {
|
|
1973
1973
|
method: t.method,
|
|
1974
1974
|
path: i,
|
|
1975
1975
|
status: c.status,
|
|
@@ -1981,7 +1981,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1981
1981
|
headers: l
|
|
1982
1982
|
};
|
|
1983
1983
|
return c.body instanceof Uint8Array ? B.uint8Array(c.body, u) : B.text(c.body ?? "", u);
|
|
1984
|
-
})), j.tapErrorCause((t) => k.isInterruptedOnly(t) ? j.void : j.sync(() =>
|
|
1984
|
+
})), j.tapErrorCause((t) => k.isInterruptedOnly(t) ? j.void : j.sync(() => ur.error(`${e.map((e) => e.method).join("|")} ${e[0].path} threw`, { path: e[0].path }, k.squash(t))))), n = /* @__PURE__ */ new Map();
|
|
1985
1985
|
for (let t of e.httpRoutes) {
|
|
1986
1986
|
let e = n.get(t.path);
|
|
1987
1987
|
e ? e.push(t) : n.set(t.path, [t]);
|
|
@@ -1992,13 +1992,13 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
1992
1992
|
});
|
|
1993
1993
|
l = M.mergeAll(...r);
|
|
1994
1994
|
}
|
|
1995
|
-
let u =
|
|
1996
|
-
let e = yield*
|
|
1995
|
+
let u = et.layerProtocolWebsocketRouter({ path: n }), d = et.layer(e.group), f = et.layer(e.group).pipe(M.provide(et.layerProtocolHttpRouter({ path: "/rpc" })), M.provide($e.layerJson), M.provide(e.httpHandlersLayer ?? e.handlersLayer)), p = M.scopedDiscard(j.gen(function* () {
|
|
1996
|
+
let e = yield* et.Protocol;
|
|
1997
1997
|
yield* j.forkScoped(j.gen(function* () {
|
|
1998
1998
|
let t = yield* e.disconnects.take;
|
|
1999
|
-
|
|
1999
|
+
kn(t), Nn(t);
|
|
2000
2000
|
}).pipe(j.forever));
|
|
2001
|
-
})), m = M.mergeAll(d, p).pipe(M.provide(u), M.provide(
|
|
2001
|
+
})), m = M.mergeAll(d, p).pipe(M.provide(u), M.provide($e.layerJson), M.provide(e.handlersLayer)), h = M.mergeAll(m, f, s, c, l), g = e.pluginHttpInterceptor, _ = e.healthCheck, v = Number(process.env.VOLTRO_MAX_RPC_BODY_BYTES), y = e.maxRpcBodyBytes ?? (Number.isFinite(v) && v > 0 ? v : 8388608), b = { "cache-control": "no-store" }, x = (e) => j.gen(function* () {
|
|
2002
2002
|
let t = yield* z.HttpServerRequest, n = {};
|
|
2003
2003
|
for (let [e, r] of Object.entries(t.headers)) r !== void 0 && (n[e.toLowerCase()] = Array.isArray(r) ? r.join(", ") : r);
|
|
2004
2004
|
let r = t.url.indexOf("?"), i = r === -1 ? t.url : t.url.slice(0, r);
|
|
@@ -2039,13 +2039,13 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2039
2039
|
status: l.status,
|
|
2040
2040
|
...l.headers ? { headers: l.headers } : {}
|
|
2041
2041
|
});
|
|
2042
|
-
}), S = M.unwrapEffect(R.toHttpEffect(h).pipe(j.map((e) =>
|
|
2042
|
+
}), S = M.unwrapEffect(R.toHttpEffect(h).pipe(j.map((e) => Je.serve(x(e))))).pipe(M.provide(Xe.layer(() => r, { port: t })), M.provide(Ye.layer));
|
|
2043
2043
|
e.tracerLayer && (S = S.pipe(M.provide(e.tracerLayer)));
|
|
2044
|
-
let C =
|
|
2044
|
+
let C = Ne({ scope: "voltro:rpc" }), ee = M.launch(S).pipe(j.catchAllCause((e) => j.sync(() => {
|
|
2045
2045
|
C.error("rpc server crashed", {}, k.squash(e)), process.exit(1);
|
|
2046
2046
|
})));
|
|
2047
|
-
return
|
|
2048
|
-
},
|
|
2047
|
+
return Ze.runMain(ee, { disableErrorReporting: !0 }), r;
|
|
2048
|
+
}, yr = (e, t = 1e4) => new Promise((n, r) => {
|
|
2049
2049
|
if (e.listening) {
|
|
2050
2050
|
n();
|
|
2051
2051
|
return;
|
|
@@ -2061,13 +2061,13 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2061
2061
|
o(e);
|
|
2062
2062
|
}
|
|
2063
2063
|
a = setTimeout(() => o(/* @__PURE__ */ Error(`rpc server did not bind within ${t}ms`)), t), e.on("listening", s), e.on("error", c);
|
|
2064
|
-
}),
|
|
2064
|
+
}), br = () => {
|
|
2065
2065
|
let e = process.env.FRAMEWORK_TRACING?.toLowerCase();
|
|
2066
2066
|
return e === "console" || e === "otlp" || e === "off" ? e : process.env.OTEL_EXPORTER_OTLP_ENDPOINT || process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ? "otlp" : "off";
|
|
2067
|
-
},
|
|
2067
|
+
}, xr = () => {
|
|
2068
2068
|
let e = process.env.FRAMEWORK_METRICS?.toLowerCase();
|
|
2069
2069
|
return e === "console" || e === "otlp" || e === "off" ? e : process.env.OTEL_EXPORTER_OTLP_ENDPOINT || process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT ? "otlp" : "off";
|
|
2070
|
-
},
|
|
2070
|
+
}, Sr = async () => {
|
|
2071
2071
|
let [e, t, n, r, i] = await Promise.all([
|
|
2072
2072
|
import("@opentelemetry/sdk-trace-base"),
|
|
2073
2073
|
import("@opentelemetry/sdk-metrics"),
|
|
@@ -2082,7 +2082,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2082
2082
|
otlpMetrics: r,
|
|
2083
2083
|
nodeSdk: i
|
|
2084
2084
|
};
|
|
2085
|
-
},
|
|
2085
|
+
}, Cr = (e, t, n) => {
|
|
2086
2086
|
let { PeriodicExportingMetricReader: r, ConsoleMetricExporter: i, InMemoryMetricExporter: a, AggregationTemporality: o } = e.sdkMetrics;
|
|
2087
2087
|
if (t === "off") return {
|
|
2088
2088
|
reader: void 0,
|
|
@@ -2105,8 +2105,8 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2105
2105
|
}),
|
|
2106
2106
|
inMemory: void 0
|
|
2107
2107
|
};
|
|
2108
|
-
},
|
|
2109
|
-
let t = e.mode ??
|
|
2108
|
+
}, wr = async (e = {}) => {
|
|
2109
|
+
let t = e.mode ?? br(), n = e.metricsMode ?? xr(), r = e.extraSpanProcessors ?? [], i = e.extraMetricReaders ?? [];
|
|
2110
2110
|
if (t === "off" && e.traceSink === void 0 && n === "off" && r.length === 0 && i.length === 0) return {
|
|
2111
2111
|
layer: M.empty,
|
|
2112
2112
|
mode: t,
|
|
@@ -2115,13 +2115,13 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2115
2115
|
metricsMode: n,
|
|
2116
2116
|
inMemoryMetricExporter: void 0
|
|
2117
2117
|
};
|
|
2118
|
-
let a = await
|
|
2118
|
+
let a = await Sr(), { ConsoleSpanExporter: o, InMemorySpanExporter: s, SimpleSpanProcessor: c, BatchSpanProcessor: l } = a.sdkTrace, u = t === "off", d = e.serviceName ?? process.env.OTEL_SERVICE_NAME ?? "voltro-app", f, p;
|
|
2119
2119
|
e.spanProcessor ? p = e.spanProcessor : u ? p = void 0 : t === "memory" ? (f = new s(), p = new c(f)) : p = t === "console" ? new c(new o()) : new l(new a.otlpTrace.OTLPTraceExporter());
|
|
2120
2120
|
let m = [
|
|
2121
2121
|
...e.traceSink ? [e.traceSink] : [],
|
|
2122
2122
|
...p ? [p] : [],
|
|
2123
2123
|
...r
|
|
2124
|
-
], h = m.length === 1 ? m[0] : m, { reader: g, inMemory: _ } =
|
|
2124
|
+
], h = m.length === 1 ? m[0] : m, { reader: g, inMemory: _ } = Cr(a, n, e.metricExportIntervalMillis ?? (process.env.OTEL_METRIC_EXPORT_INTERVAL ? Number(process.env.OTEL_METRIC_EXPORT_INTERVAL) : 6e4)), v = [...g ? [g] : [], ...i], y = v.length === 0 ? void 0 : v.length === 1 ? v[0] : v, b = {
|
|
2125
2125
|
serviceName: d,
|
|
2126
2126
|
...e.serviceVersion ? { serviceVersion: e.serviceVersion } : {},
|
|
2127
2127
|
...e.resourceAttributes ? { attributes: e.resourceAttributes } : {}
|
|
@@ -2139,18 +2139,18 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2139
2139
|
metricsMode: n,
|
|
2140
2140
|
inMemoryMetricExporter: _
|
|
2141
2141
|
};
|
|
2142
|
-
},
|
|
2143
|
-
[
|
|
2144
|
-
[
|
|
2145
|
-
[
|
|
2146
|
-
[
|
|
2147
|
-
[
|
|
2148
|
-
},
|
|
2142
|
+
}, Tr = {
|
|
2143
|
+
[at.INTERNAL]: "internal",
|
|
2144
|
+
[at.SERVER]: "server",
|
|
2145
|
+
[at.CLIENT]: "client",
|
|
2146
|
+
[at.PRODUCER]: "producer",
|
|
2147
|
+
[at.CONSUMER]: "consumer"
|
|
2148
|
+
}, Er = (e) => e[0] * 1e3 + e[1] / 1e6, Dr = 512, Or = 48, kr = (e) => {
|
|
2149
2149
|
let t = {}, n = 0;
|
|
2150
2150
|
for (let r in e) {
|
|
2151
|
-
if (n >=
|
|
2151
|
+
if (n >= Or) break;
|
|
2152
2152
|
let i = e[r];
|
|
2153
|
-
if (typeof i == "string") t[r] = i.length >
|
|
2153
|
+
if (typeof i == "string") t[r] = i.length > Dr ? `${i.slice(0, Dr)}…` : i;
|
|
2154
2154
|
else if (typeof i == "number" || typeof i == "boolean" || i == null) t[r] = i;
|
|
2155
2155
|
else {
|
|
2156
2156
|
let e;
|
|
@@ -2159,49 +2159,49 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2159
2159
|
} catch {
|
|
2160
2160
|
e = String(i);
|
|
2161
2161
|
}
|
|
2162
|
-
t[r] = e.length >
|
|
2162
|
+
t[r] = e.length > Dr ? `${e.slice(0, Dr)}…` : e;
|
|
2163
2163
|
}
|
|
2164
2164
|
n++;
|
|
2165
2165
|
}
|
|
2166
2166
|
return t;
|
|
2167
|
-
},
|
|
2168
|
-
[
|
|
2169
|
-
[
|
|
2170
|
-
[
|
|
2171
|
-
},
|
|
2167
|
+
}, Ar = {
|
|
2168
|
+
[ot.UNSET]: "unset",
|
|
2169
|
+
[ot.OK]: "ok",
|
|
2170
|
+
[ot.ERROR]: "error"
|
|
2171
|
+
}, jr = (e) => {
|
|
2172
2172
|
let t = e.spanContext(), n = e.events.length > 0 ? e.events.slice(0, 16).map((e) => ({
|
|
2173
2173
|
name: e.name,
|
|
2174
|
-
tsMs:
|
|
2175
|
-
...e.attributes ? { attributes:
|
|
2174
|
+
tsMs: Er(e.time),
|
|
2175
|
+
...e.attributes ? { attributes: kr(e.attributes) } : {}
|
|
2176
2176
|
})) : void 0;
|
|
2177
2177
|
return {
|
|
2178
2178
|
traceId: t.traceId,
|
|
2179
2179
|
spanId: t.spanId,
|
|
2180
2180
|
parentSpanId: e.parentSpanContext?.spanId ?? null,
|
|
2181
2181
|
name: e.name,
|
|
2182
|
-
kind:
|
|
2183
|
-
attributes:
|
|
2184
|
-
startMs:
|
|
2185
|
-
endMs:
|
|
2186
|
-
durationMs:
|
|
2187
|
-
status:
|
|
2182
|
+
kind: Tr[e.kind] ?? "internal",
|
|
2183
|
+
attributes: kr(e.attributes),
|
|
2184
|
+
startMs: Er(e.startTime),
|
|
2185
|
+
endMs: Er(e.endTime),
|
|
2186
|
+
durationMs: Er(e.duration),
|
|
2187
|
+
status: Ar[e.status.code] ?? "unset",
|
|
2188
2188
|
...e.status.message ? { statusMessage: e.status.message } : {},
|
|
2189
2189
|
...n ? { events: n } : {}
|
|
2190
2190
|
};
|
|
2191
|
-
},
|
|
2191
|
+
}, Mr = (e) => ({
|
|
2192
2192
|
onStart: () => {},
|
|
2193
2193
|
onEnd: (t) => {
|
|
2194
2194
|
try {
|
|
2195
|
-
e(
|
|
2195
|
+
e(jr(t));
|
|
2196
2196
|
} catch {}
|
|
2197
2197
|
},
|
|
2198
2198
|
forceFlush: () => Promise.resolve(),
|
|
2199
2199
|
shutdown: () => Promise.resolve()
|
|
2200
|
-
}),
|
|
2201
|
-
|
|
2202
|
-
},
|
|
2203
|
-
|
|
2204
|
-
},
|
|
2200
|
+
}), Nr = { get: (e) => Promise.resolve(process.env[e]) }, Pr = Nr, Fr = (e) => {
|
|
2201
|
+
Pr = e;
|
|
2202
|
+
}, Ir = () => {
|
|
2203
|
+
Pr = Nr;
|
|
2204
|
+
}, Lr = async (e) => await Pr.get(e) ?? process.env[e], Rr = (e) => process.env[e], zr = (e, t = 6e4, n = () => Date.now()) => {
|
|
2205
2205
|
let r = /* @__PURE__ */ new Map();
|
|
2206
2206
|
return { get: async (i) => {
|
|
2207
2207
|
let a = r.get(i);
|
|
@@ -2212,12 +2212,12 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2212
2212
|
at: n()
|
|
2213
2213
|
}), o;
|
|
2214
2214
|
} };
|
|
2215
|
-
},
|
|
2215
|
+
}, Br = (e) => {
|
|
2216
2216
|
let t = {
|
|
2217
2217
|
accept: "application/json",
|
|
2218
2218
|
...e.headers ?? {}
|
|
2219
2219
|
};
|
|
2220
|
-
if (e.perKey) return
|
|
2220
|
+
if (e.perKey) return zr({ get: async (n) => {
|
|
2221
2221
|
let r = await fetch(`${e.url.replace(/\/$/, "")}/${encodeURIComponent(n)}`, { headers: t });
|
|
2222
2222
|
if (!r.ok) return;
|
|
2223
2223
|
let i = await r.json();
|
|
@@ -2228,43 +2228,52 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2228
2228
|
let t = (await a())[e];
|
|
2229
2229
|
return typeof t == "string" ? t : void 0;
|
|
2230
2230
|
} };
|
|
2231
|
-
},
|
|
2231
|
+
}, Vr = (e) => e === void 0 || e === "env" || typeof e == "object" && e.kind === "env" ? Nr : e.kind === "custom" ? e.backend : e.kind === "http" ? Br(e) : Nr, Hr = (e) => /^[0-9a-f]{64}$/i.test(e) ? Buffer.from(e, "hex") : ge(e, "voltro:field-encryption:v1", 32), Ur = (t) => {
|
|
2232
2232
|
if (t.length !== 32) throw Error(`field cipher key must be 32 bytes, got ${t.length}`);
|
|
2233
2233
|
return {
|
|
2234
2234
|
encrypt: (n) => {
|
|
2235
|
-
let r =
|
|
2235
|
+
let r = me(12), i = de("aes-256-gcm", t, r), a = Buffer.concat([i.update(n, "utf8"), i.final()]), o = i.getAuthTag();
|
|
2236
2236
|
return `${e}${r.toString("base64")}:${o.toString("base64")}:${a.toString("base64")}`;
|
|
2237
2237
|
},
|
|
2238
2238
|
decrypt: (n) => {
|
|
2239
2239
|
let [r, i, a] = n.slice(e.length).split(":");
|
|
2240
2240
|
if (!r || !i || a === void 0) throw Error("field cipher: malformed ciphertext");
|
|
2241
|
-
let o =
|
|
2241
|
+
let o = fe("aes-256-gcm", t, Buffer.from(r, "base64"));
|
|
2242
2242
|
return o.setAuthTag(Buffer.from(i, "base64")), Buffer.concat([o.update(Buffer.from(a, "base64")), o.final()]).toString("utf8");
|
|
2243
2243
|
}
|
|
2244
2244
|
};
|
|
2245
|
-
},
|
|
2246
|
-
|
|
2247
|
-
},
|
|
2245
|
+
}, Wr = (e) => Ur(Hr(e)), Gr, Kr = (e) => {
|
|
2246
|
+
Gr = e;
|
|
2247
|
+
}, qr = () => Gr, Jr = "no field cipher registered — enable `@voltro/plugin-governance` `governancePlugin({ fieldEncryption: { key } })` (or call setFieldCipher) so a key is available.", Yr = (e) => {
|
|
2248
|
+
let t = qr();
|
|
2249
|
+
if (!t) throw Error(`encryptField: ${Jr}`);
|
|
2250
|
+
return t.encrypt(e);
|
|
2251
|
+
}, Xr = (e) => {
|
|
2252
|
+
if (!x(e)) return e;
|
|
2253
|
+
let t = qr();
|
|
2254
|
+
if (!t) throw Error(`decryptField: ${Jr}`);
|
|
2255
|
+
return t.decrypt(e);
|
|
2256
|
+
}, J = "_voltro_idempotency", Zr = (e) => {
|
|
2248
2257
|
if (e == null) return null;
|
|
2249
2258
|
let t = typeof e == "string" ? JSON.parse(e) : e;
|
|
2250
2259
|
return t && typeof t == "object" && "status" in t ? t : null;
|
|
2251
|
-
},
|
|
2260
|
+
}, Qr = (e) => ({
|
|
2252
2261
|
scope: e.scope,
|
|
2253
2262
|
key: e.key,
|
|
2254
2263
|
status: e.status === "completed" ? "completed" : "in_flight",
|
|
2255
|
-
response:
|
|
2256
|
-
createdAt:
|
|
2257
|
-
}),
|
|
2264
|
+
response: Zr(e.response),
|
|
2265
|
+
createdAt: Me(e.createdAt)
|
|
2266
|
+
}), $r = async (e, n, r) => (await e.query({
|
|
2258
2267
|
table: J,
|
|
2259
2268
|
predicate: t(u("scope", n), u("key", r)),
|
|
2260
2269
|
order: [],
|
|
2261
2270
|
take: 1,
|
|
2262
2271
|
skip: void 0,
|
|
2263
2272
|
projection: void 0
|
|
2264
|
-
}))[0] ?? null,
|
|
2273
|
+
}))[0] ?? null, ei = (e) => ({
|
|
2265
2274
|
get: async (t, n) => {
|
|
2266
|
-
let r = await
|
|
2267
|
-
return r ?
|
|
2275
|
+
let r = await $r(e, t, n);
|
|
2276
|
+
return r ? Qr(r) : null;
|
|
2268
2277
|
},
|
|
2269
2278
|
claim: async (t, n, r, i) => {
|
|
2270
2279
|
for (let a = 0; a < 2; a++) {
|
|
@@ -2280,11 +2289,11 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2280
2289
|
createdAt: new Date(r)
|
|
2281
2290
|
}, { conflictColumns: ["scope", "key"] });
|
|
2282
2291
|
if (o.id === a) return "claimed";
|
|
2283
|
-
if (r -
|
|
2292
|
+
if (r - Me(o.createdAt) < i) return Qr(o);
|
|
2284
2293
|
await e.delete(J, o.id);
|
|
2285
2294
|
}
|
|
2286
|
-
let a = await
|
|
2287
|
-
return a ?
|
|
2295
|
+
let a = await $r(e, t, n);
|
|
2296
|
+
return a ? Qr(a) : {
|
|
2288
2297
|
scope: t,
|
|
2289
2298
|
key: n,
|
|
2290
2299
|
status: "in_flight",
|
|
@@ -2293,36 +2302,36 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2293
2302
|
};
|
|
2294
2303
|
},
|
|
2295
2304
|
complete: async (t, n, r, i) => {
|
|
2296
|
-
let a = await
|
|
2305
|
+
let a = await $r(e, t, n);
|
|
2297
2306
|
a && await e.update(J, a.id, {
|
|
2298
2307
|
status: "completed",
|
|
2299
2308
|
response: r
|
|
2300
2309
|
});
|
|
2301
2310
|
},
|
|
2302
2311
|
release: async (t, n) => {
|
|
2303
|
-
let r = await
|
|
2312
|
+
let r = await $r(e, t, n);
|
|
2304
2313
|
r && await e.delete(J, r.id);
|
|
2305
2314
|
}
|
|
2306
|
-
}), Y = "_voltro_kv",
|
|
2315
|
+
}), Y = "_voltro_kv", ti = (e) => {
|
|
2307
2316
|
if (e == null) return null;
|
|
2308
2317
|
if (e instanceof Date) return e.getTime();
|
|
2309
2318
|
if (typeof e == "number") return e;
|
|
2310
2319
|
let t = Date.parse(String(e));
|
|
2311
2320
|
return Number.isNaN(t) ? null : t;
|
|
2312
|
-
},
|
|
2313
|
-
let n =
|
|
2321
|
+
}, ni = (e, t) => {
|
|
2322
|
+
let n = ti(e.expiresAt);
|
|
2314
2323
|
return n !== null && n <= t;
|
|
2315
|
-
},
|
|
2324
|
+
}, ri = (e) => e === null ? null : JSON.parse(e), ii = async (e, t) => (await e.query({
|
|
2316
2325
|
table: Y,
|
|
2317
2326
|
predicate: u("key", t),
|
|
2318
2327
|
order: [],
|
|
2319
2328
|
take: 1,
|
|
2320
2329
|
skip: void 0,
|
|
2321
2330
|
projection: void 0
|
|
2322
|
-
}))[0] ?? null,
|
|
2331
|
+
}))[0] ?? null, ai = (e) => {
|
|
2323
2332
|
let n = (e, t, n) => j.tryPromise({
|
|
2324
2333
|
try: n,
|
|
2325
|
-
catch: (n) => new
|
|
2334
|
+
catch: (n) => new ct({
|
|
2326
2335
|
operation: e,
|
|
2327
2336
|
key: t,
|
|
2328
2337
|
cause: String(n)
|
|
@@ -2330,8 +2339,8 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2330
2339
|
});
|
|
2331
2340
|
return {
|
|
2332
2341
|
get: (t) => n("get", t, async () => {
|
|
2333
|
-
let n = await
|
|
2334
|
-
return n === null ? P.none() :
|
|
2342
|
+
let n = await ii(e, t);
|
|
2343
|
+
return n === null ? P.none() : ni(n, Date.now()) ? (await e.delete(Y, n.id), P.none()) : P.some(ri(n.value));
|
|
2335
2344
|
}),
|
|
2336
2345
|
set: (t, r, i) => n("set", t, async () => {
|
|
2337
2346
|
let n = Date.now(), a = i?.ttlMs !== void 0 && i.ttlMs > 0 ? new Date(n + i.ttlMs) : null, o = f({
|
|
@@ -2354,17 +2363,17 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2354
2363
|
});
|
|
2355
2364
|
}),
|
|
2356
2365
|
delete: (t) => n("delete", t, async () => {
|
|
2357
|
-
let n = await
|
|
2366
|
+
let n = await ii(e, t);
|
|
2358
2367
|
if (n === null) return !1;
|
|
2359
|
-
let r = !
|
|
2368
|
+
let r = !ni(n, Date.now());
|
|
2360
2369
|
return await e.delete(Y, n.id), r;
|
|
2361
2370
|
}),
|
|
2362
2371
|
has: (t) => n("has", t, async () => {
|
|
2363
|
-
let n = await
|
|
2364
|
-
return n === null ? !1 :
|
|
2372
|
+
let n = await ii(e, t);
|
|
2373
|
+
return n === null ? !1 : ni(n, Date.now()) ? (await e.delete(Y, n.id), !1) : !0;
|
|
2365
2374
|
}),
|
|
2366
2375
|
list: (r) => n("list", "", async () => {
|
|
2367
|
-
let n = Date.now(), i =
|
|
2376
|
+
let n = Date.now(), i = re(S("expiresAt"), h("expiresAt", new Date(n))), a = r === "" ? i : t(o("key", r), i), s = await e.query({
|
|
2368
2377
|
table: Y,
|
|
2369
2378
|
predicate: a,
|
|
2370
2379
|
order: [],
|
|
@@ -2372,7 +2381,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2372
2381
|
skip: void 0,
|
|
2373
2382
|
projection: void 0
|
|
2374
2383
|
}), c = [];
|
|
2375
|
-
for (let e of s)
|
|
2384
|
+
for (let e of s) ni(e, n) || (r === "" || e.key.startsWith(r)) && c.push(e.key);
|
|
2376
2385
|
return c;
|
|
2377
2386
|
}),
|
|
2378
2387
|
clear: () => n("clear", "", async () => {
|
|
@@ -2382,8 +2391,8 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2382
2391
|
} });
|
|
2383
2392
|
})
|
|
2384
2393
|
};
|
|
2385
|
-
},
|
|
2386
|
-
let n = (t.KV_BACKEND ?? "database").toLowerCase(), r = n === "redis" ? "redis" : n === "memory" ? "memory" : "database", i = r === "redis" ?
|
|
2394
|
+
}, oi = async ({ store: e, env: t = process.env }) => {
|
|
2395
|
+
let n = (t.KV_BACKEND ?? "database").toLowerCase(), r = n === "redis" ? "redis" : n === "memory" ? "memory" : "database", i = r === "redis" ? ft(t.KV_KEY_PREFIX ? { keyPrefix: t.KV_KEY_PREFIX } : {}).pipe(M.provide(ut)) : r === "memory" ? dt() : M.succeed(lt, lt.of(ai(e))), a = Be.make(st.Default.pipe(M.provide(i))), o = await a.runPromise(st);
|
|
2387
2396
|
return {
|
|
2388
2397
|
kv: {
|
|
2389
2398
|
get: (e) => a.runPromise(o.get(e)).then((e) => P.getOrUndefined(e)),
|
|
@@ -2398,7 +2407,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2398
2407
|
backend: r,
|
|
2399
2408
|
dispose: () => a.dispose()
|
|
2400
2409
|
};
|
|
2401
|
-
},
|
|
2410
|
+
}, si = {
|
|
2402
2411
|
get: () => Promise.resolve(void 0),
|
|
2403
2412
|
getOrElse: (e, t) => Promise.resolve(t()),
|
|
2404
2413
|
set: () => Promise.resolve(),
|
|
@@ -2406,7 +2415,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2406
2415
|
has: () => Promise.resolve(!1),
|
|
2407
2416
|
list: () => Promise.resolve([]),
|
|
2408
2417
|
clear: () => Promise.resolve()
|
|
2409
|
-
},
|
|
2418
|
+
}, ci = "_voltro_api_keys", li = (e) => pe("sha256").update(e, "utf8").digest("hex"), ui = (e = "voltro_") => `${e}${me(30).toString("base64url")}`, di = (e) => ({
|
|
2410
2419
|
id: e.id,
|
|
2411
2420
|
name: e.name,
|
|
2412
2421
|
keyPrefix: e.keyPrefix,
|
|
@@ -2416,17 +2425,17 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2416
2425
|
expiresAt: e.expiresAt,
|
|
2417
2426
|
revokedAt: e.revokedAt,
|
|
2418
2427
|
createdAt: e.createdAt
|
|
2419
|
-
}),
|
|
2428
|
+
}), fi = (e, t) => e.revokedAt === null && (e.expiresAt === null || e.expiresAt > t), pi = (e, t = {}) => {
|
|
2420
2429
|
let n = t.prefix ?? "voltro_", r = async (t) => {
|
|
2421
|
-
let r =
|
|
2430
|
+
let r = ui(n), i = f({
|
|
2422
2431
|
kind: "typeid",
|
|
2423
2432
|
prefix: "apikey"
|
|
2424
|
-
},
|
|
2433
|
+
}, ci), a = t.scopes ?? [], o = t.expiresAt == null ? null : t.expiresAt instanceof Date ? t.expiresAt.getTime() : t.expiresAt;
|
|
2425
2434
|
return await e.insert({
|
|
2426
2435
|
id: i,
|
|
2427
2436
|
tenantId: t.tenantId ?? null,
|
|
2428
2437
|
name: t.name,
|
|
2429
|
-
hashedKey:
|
|
2438
|
+
hashedKey: li(r),
|
|
2430
2439
|
keyPrefix: r.slice(0, n.length + 6),
|
|
2431
2440
|
scopes: a,
|
|
2432
2441
|
lastUsedAt: null,
|
|
@@ -2444,7 +2453,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2444
2453
|
};
|
|
2445
2454
|
}, i = async (t, n = Date.now()) => {
|
|
2446
2455
|
let r = await e.findByHash(t);
|
|
2447
|
-
return !r || !
|
|
2456
|
+
return !r || !fi(r, n) ? null : (await e.patch(r.id, { lastUsedAt: n }), {
|
|
2448
2457
|
id: r.id,
|
|
2449
2458
|
tenantId: r.tenantId ?? "",
|
|
2450
2459
|
scopes: r.scopes ?? []
|
|
@@ -2453,7 +2462,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2453
2462
|
return {
|
|
2454
2463
|
issue: r,
|
|
2455
2464
|
resolveByHash: i,
|
|
2456
|
-
verify: (e, t) => i(
|
|
2465
|
+
verify: (e, t) => i(li(e), t),
|
|
2457
2466
|
revoke: async (t, n = Date.now()) => await e.findById(t) ? (await e.patch(t, { revokedAt: n }), !0) : !1,
|
|
2458
2467
|
rotate: async (t, n = Date.now()) => {
|
|
2459
2468
|
let i = await e.findById(t);
|
|
@@ -2464,9 +2473,9 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2464
2473
|
createdBy: i.createdBy
|
|
2465
2474
|
})) : null;
|
|
2466
2475
|
},
|
|
2467
|
-
list: async (t) => (await e.listByTenant(t)).map(
|
|
2476
|
+
list: async (t) => (await e.listByTenant(t)).map(di)
|
|
2468
2477
|
};
|
|
2469
|
-
},
|
|
2478
|
+
}, mi = () => {
|
|
2470
2479
|
let e = /* @__PURE__ */ new Map();
|
|
2471
2480
|
return {
|
|
2472
2481
|
insert: async (t) => {
|
|
@@ -2483,21 +2492,21 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2483
2492
|
});
|
|
2484
2493
|
}
|
|
2485
2494
|
};
|
|
2486
|
-
},
|
|
2495
|
+
}, hi = (e) => e == null ? null : e instanceof Date ? e.getTime() : typeof e == "number" ? e : typeof e == "string" ? new Date(e).getTime() : null, gi = (e) => ({
|
|
2487
2496
|
id: String(e.id),
|
|
2488
2497
|
tenantId: e.tenantId ?? null,
|
|
2489
2498
|
name: String(e.name),
|
|
2490
2499
|
hashedKey: String(e.hashedKey),
|
|
2491
2500
|
keyPrefix: String(e.keyPrefix),
|
|
2492
2501
|
scopes: e.scopes ?? null,
|
|
2493
|
-
lastUsedAt:
|
|
2494
|
-
expiresAt:
|
|
2495
|
-
revokedAt:
|
|
2502
|
+
lastUsedAt: hi(e.lastUsedAt),
|
|
2503
|
+
expiresAt: hi(e.expiresAt),
|
|
2504
|
+
revokedAt: hi(e.revokedAt),
|
|
2496
2505
|
createdBy: e.createdBy ?? null,
|
|
2497
|
-
createdAt:
|
|
2498
|
-
}),
|
|
2506
|
+
createdAt: hi(e.createdAt) ?? 0
|
|
2507
|
+
}), _i = (e) => {
|
|
2499
2508
|
let t = async (t) => await e.query({
|
|
2500
|
-
table:
|
|
2509
|
+
table: ci,
|
|
2501
2510
|
predicate: t,
|
|
2502
2511
|
order: [],
|
|
2503
2512
|
take: void 0,
|
|
@@ -2515,32 +2524,32 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2515
2524
|
};
|
|
2516
2525
|
return {
|
|
2517
2526
|
insert: async (t) => {
|
|
2518
|
-
await e.insert(
|
|
2527
|
+
await e.insert(ci, n(t));
|
|
2519
2528
|
},
|
|
2520
2529
|
findByHash: async (e) => {
|
|
2521
2530
|
let n = await t(u("hashedKey", e));
|
|
2522
|
-
return n[0] ?
|
|
2531
|
+
return n[0] ? gi(n[0]) : null;
|
|
2523
2532
|
},
|
|
2524
2533
|
findById: async (e) => {
|
|
2525
2534
|
let n = await t(u("id", e));
|
|
2526
|
-
return n[0] ?
|
|
2535
|
+
return n[0] ? gi(n[0]) : null;
|
|
2527
2536
|
},
|
|
2528
|
-
listByTenant: async (e) => (await t(e === null ? void 0 : u("tenantId", e))).map(
|
|
2537
|
+
listByTenant: async (e) => (await t(e === null ? void 0 : u("tenantId", e))).map(gi).filter((t) => e === null || t.tenantId === e),
|
|
2529
2538
|
patch: async (t, r) => {
|
|
2530
|
-
await e.update(
|
|
2539
|
+
await e.update(ci, t, n(r));
|
|
2531
2540
|
}
|
|
2532
2541
|
};
|
|
2533
|
-
},
|
|
2542
|
+
}, vi = (e, t = {}) => pt({
|
|
2534
2543
|
id: "voltro-apikey",
|
|
2535
2544
|
...t.prefix ? { prefix: t.prefix } : {},
|
|
2536
2545
|
resolveKey: (t) => e.resolveByHash(t)
|
|
2537
|
-
}),
|
|
2546
|
+
}), yi = (e) => {
|
|
2538
2547
|
let t = e.subject;
|
|
2539
2548
|
return {
|
|
2540
2549
|
id: t.id ?? null,
|
|
2541
2550
|
tenantId: t.tenantId ?? null
|
|
2542
2551
|
};
|
|
2543
|
-
},
|
|
2552
|
+
}, bi = (e, t = "/v1/api-keys") => {
|
|
2544
2553
|
let n = I.Struct({
|
|
2545
2554
|
id: I.String,
|
|
2546
2555
|
name: I.String,
|
|
@@ -2553,11 +2562,11 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2553
2562
|
createdAt: I.Number
|
|
2554
2563
|
});
|
|
2555
2564
|
return [
|
|
2556
|
-
|
|
2565
|
+
tt({
|
|
2557
2566
|
method: "POST",
|
|
2558
2567
|
path: `${t}/issue`,
|
|
2559
2568
|
summary: "Issue an API key (the token is returned ONCE).",
|
|
2560
|
-
guards: [
|
|
2569
|
+
guards: [rt(ve)],
|
|
2561
2570
|
input: I.Struct({ body: I.Struct({
|
|
2562
2571
|
name: I.String,
|
|
2563
2572
|
scopes: I.optional(I.Array(I.String)),
|
|
@@ -2569,7 +2578,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2569
2578
|
keyPrefix: I.String
|
|
2570
2579
|
}),
|
|
2571
2580
|
handler: async (t, n) => {
|
|
2572
|
-
let r = t.body, i =
|
|
2581
|
+
let r = t.body, i = yi(n), a = await e.issue({
|
|
2573
2582
|
tenantId: i.tenantId,
|
|
2574
2583
|
name: r.name,
|
|
2575
2584
|
...r.scopes ? { scopes: r.scopes } : {},
|
|
@@ -2583,41 +2592,41 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2583
2592
|
};
|
|
2584
2593
|
}
|
|
2585
2594
|
}),
|
|
2586
|
-
|
|
2595
|
+
tt({
|
|
2587
2596
|
method: "GET",
|
|
2588
2597
|
path: t,
|
|
2589
2598
|
summary: "List the caller tenant's API keys (no secrets).",
|
|
2590
|
-
guards: [
|
|
2599
|
+
guards: [rt(ve)],
|
|
2591
2600
|
input: I.Struct({}),
|
|
2592
2601
|
output: I.Struct({ keys: I.Array(n) }),
|
|
2593
|
-
handler: async (t, n) => ({ keys: [...await e.list(
|
|
2602
|
+
handler: async (t, n) => ({ keys: [...await e.list(yi(n).tenantId)] })
|
|
2594
2603
|
}),
|
|
2595
|
-
|
|
2604
|
+
tt({
|
|
2596
2605
|
method: "POST",
|
|
2597
2606
|
path: `${t}/revoke`,
|
|
2598
2607
|
summary: "Revoke an API key by id.",
|
|
2599
|
-
guards: [
|
|
2608
|
+
guards: [rt(ve)],
|
|
2600
2609
|
input: I.Struct({ body: I.Struct({ id: I.String }) }),
|
|
2601
2610
|
output: I.Struct({ ok: I.Boolean }),
|
|
2602
2611
|
handler: async (t, n) => ({ ok: await e.revoke(t.body.id) })
|
|
2603
2612
|
})
|
|
2604
2613
|
];
|
|
2605
|
-
},
|
|
2614
|
+
}, xi = (e) => Qe.make(e.name, {
|
|
2606
2615
|
payload: e.payloadSchema,
|
|
2607
|
-
success:
|
|
2616
|
+
success: Ce,
|
|
2608
2617
|
error: e.errorSchema
|
|
2609
2618
|
}), X = (e, t) => ({
|
|
2610
2619
|
id: t,
|
|
2611
2620
|
workflowName: e,
|
|
2612
2621
|
executionId: t,
|
|
2613
2622
|
status: "running"
|
|
2614
|
-
}),
|
|
2623
|
+
}), Si = X, Ci = (e) => {
|
|
2615
2624
|
let t = k.failureOption(e), n = t._tag === "Some" ? t.value : k.squash(e);
|
|
2616
2625
|
return {
|
|
2617
2626
|
tag: n && typeof n == "object" && "_tag" in n ? String(n._tag) : null,
|
|
2618
2627
|
message: n?.message ?? String(n)
|
|
2619
2628
|
};
|
|
2620
|
-
},
|
|
2629
|
+
}, wi = (e, t, n) => {
|
|
2621
2630
|
if (n === void 0) return {
|
|
2622
2631
|
id: t,
|
|
2623
2632
|
workflowName: e,
|
|
@@ -2632,7 +2641,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2632
2641
|
};
|
|
2633
2642
|
if (typeof n == "object" && n && n._tag === "Complete") {
|
|
2634
2643
|
let r = n.exit;
|
|
2635
|
-
return
|
|
2644
|
+
return ze.isSuccess(r) ? {
|
|
2636
2645
|
id: t,
|
|
2637
2646
|
workflowName: e,
|
|
2638
2647
|
executionId: t,
|
|
@@ -2643,7 +2652,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2643
2652
|
workflowName: e,
|
|
2644
2653
|
executionId: t,
|
|
2645
2654
|
status: "failed",
|
|
2646
|
-
error:
|
|
2655
|
+
error: Ci(r.cause)
|
|
2647
2656
|
};
|
|
2648
2657
|
}
|
|
2649
2658
|
return {
|
|
@@ -2652,15 +2661,15 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2652
2661
|
executionId: t,
|
|
2653
2662
|
status: "running"
|
|
2654
2663
|
};
|
|
2655
|
-
},
|
|
2664
|
+
}, Ti = (e) => new Promise((t) => setTimeout(t, e)), Ei = (e) => {
|
|
2656
2665
|
let t = new Map(e.workflows.map((e) => [e.definition.name, e.definition])), n = (e) => {
|
|
2657
2666
|
let n = t.get(e);
|
|
2658
2667
|
if (!n) throw Error(`Unknown workflow: ${e}`);
|
|
2659
2668
|
return n;
|
|
2660
2669
|
}, r = async (t, r) => {
|
|
2661
2670
|
let i = n(t);
|
|
2662
|
-
return
|
|
2663
|
-
}, i = async () => e.runEffect(
|
|
2671
|
+
return wi(t, r, await e.runEffect(i.poll(r)));
|
|
2672
|
+
}, i = async () => e.runEffect(mt()), a = async (t, r, i) => {
|
|
2664
2673
|
let a = n(t), o;
|
|
2665
2674
|
return i?.callerContext !== void 0 && (o = await e.runEffect(a.executionId(r)), await e.rememberStartContext?.(t, o, i.callerContext)), i?.wait ? (await e.runEffect(a.execute(r)), X(t, o ?? await e.runEffect(a.executionId(r)))) : X(t, await e.runEffect(a.execute(r, { discard: !0 })));
|
|
2666
2675
|
};
|
|
@@ -2700,7 +2709,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2700
2709
|
let e = await r(i, a);
|
|
2701
2710
|
if (e.status === "succeeded" || e.status === "failed" || e.status === "cancelled") return e;
|
|
2702
2711
|
if (o?.timeoutMs !== void 0 && Date.now() - s >= o.timeoutMs) throw Error(`Timed out waiting for workflow '${i}' run '${a}'`);
|
|
2703
|
-
await
|
|
2712
|
+
await Ti(c);
|
|
2704
2713
|
}
|
|
2705
2714
|
}),
|
|
2706
2715
|
cancel: async (t, r) => {
|
|
@@ -2738,7 +2747,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2738
2747
|
return e.retry(t, n);
|
|
2739
2748
|
}
|
|
2740
2749
|
};
|
|
2741
|
-
},
|
|
2750
|
+
}, Di = (e, t) => ({
|
|
2742
2751
|
...e,
|
|
2743
2752
|
start: async (n, r, i) => {
|
|
2744
2753
|
if (i?.wait) throw Error("ctx.workflows.start(..., { wait: true }) is not allowed inside a mutation transaction; start the workflow and wait after commit.");
|
|
@@ -2753,7 +2762,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2753
2762
|
run: async () => {
|
|
2754
2763
|
throw Error("ctx.workflows.run(...) is not allowed inside a mutation transaction; use ctx.workflows.start(...) so the workflow starts after commit.");
|
|
2755
2764
|
}
|
|
2756
|
-
}),
|
|
2765
|
+
}), Oi = (e, t) => ({
|
|
2757
2766
|
...e,
|
|
2758
2767
|
start: (n, r, i) => e.start(n, r, {
|
|
2759
2768
|
...i,
|
|
@@ -2767,7 +2776,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2767
2776
|
...i,
|
|
2768
2777
|
callerContext: t
|
|
2769
2778
|
})
|
|
2770
|
-
}),
|
|
2779
|
+
}), ki = (e) => {
|
|
2771
2780
|
let t = () => {
|
|
2772
2781
|
let t = e();
|
|
2773
2782
|
if (!t) throw Error("Workflow runtime is not ready yet");
|
|
@@ -2788,11 +2797,11 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2788
2797
|
listRuns: ((e) => t().listRuns(e)),
|
|
2789
2798
|
retry: (e, n) => t().retry(e, n)
|
|
2790
2799
|
};
|
|
2791
|
-
},
|
|
2800
|
+
}, Ai = (e, t) => {
|
|
2792
2801
|
let n = {};
|
|
2793
2802
|
for (let r of e) n[r.definition.name] = (e) => (t ? j.promise(() => t.start(r.definition.name, e)) : r.definition.execute(e, { discard: !0 }).pipe(j.map((e) => X(r.definition.name, e)))).pipe(j.withSpan(`workflow.${r.definition.name}`, { attributes: { "framework.kind": "workflow" } }));
|
|
2794
2803
|
return n;
|
|
2795
|
-
},
|
|
2804
|
+
}, ji = (e, t, n) => e.map((e) => e.definition.toLayer(((r, i) => {
|
|
2796
2805
|
let a = t.resolveStartContext?.(e.definition.name, i);
|
|
2797
2806
|
return (a === void 0 ? j.succeed(void 0) : j.promise(() => Promise.resolve(a))).pipe(j.flatMap((a) => {
|
|
2798
2807
|
let o = e.buildExecute(t.buildContext(a, {
|
|
@@ -2803,40 +2812,40 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2803
2812
|
}));
|
|
2804
2813
|
return (n?.(e, o, a) ?? o)(r, i);
|
|
2805
2814
|
}));
|
|
2806
|
-
}))),
|
|
2815
|
+
}))), Mi = (e) => ({
|
|
2807
2816
|
_tag: "workflowEventTrigger",
|
|
2808
2817
|
...e
|
|
2809
|
-
}),
|
|
2818
|
+
}), Ni = Mi, Pi = (e) => typeof e == "object" && !!e && e._tag === "workflowEventTrigger", Fi = () => {
|
|
2810
2819
|
let e = globalThis.crypto;
|
|
2811
2820
|
return typeof e?.randomUUID == "function" ? e.randomUUID() : `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
|
|
2812
|
-
},
|
|
2821
|
+
}, Ii = (e) => `${e}_${Fi()}`, Li = (e) => e.id ?? `${e.event}->${e.workflow}`, Ri = T("_voltro_workflow_events", {
|
|
2813
2822
|
id: v({ prefix: "wfe" }),
|
|
2814
|
-
name:
|
|
2815
|
-
payload:
|
|
2816
|
-
source:
|
|
2817
|
-
subject:
|
|
2818
|
-
traceId:
|
|
2819
|
-
occurredAt:
|
|
2820
|
-
}).index(["name"]).index(["source"]).index(["occurredAt"]).reactive(),
|
|
2823
|
+
name: E(),
|
|
2824
|
+
payload: C(),
|
|
2825
|
+
source: E(),
|
|
2826
|
+
subject: C().nullable(),
|
|
2827
|
+
traceId: E().nullable(),
|
|
2828
|
+
occurredAt: D().default("now")
|
|
2829
|
+
}).index(["name"]).index(["source"]).index(["occurredAt"]).reactive(), zi = T("_voltro_workflow_event_deliveries", {
|
|
2821
2830
|
id: v({ prefix: "wfed" }),
|
|
2822
|
-
eventId:
|
|
2823
|
-
eventName:
|
|
2824
|
-
triggerId:
|
|
2825
|
-
workflowName:
|
|
2826
|
-
executionId:
|
|
2827
|
-
status:
|
|
2831
|
+
eventId: E(),
|
|
2832
|
+
eventName: E(),
|
|
2833
|
+
triggerId: E(),
|
|
2834
|
+
workflowName: E(),
|
|
2835
|
+
executionId: E().nullable(),
|
|
2836
|
+
status: E().oneOf([
|
|
2828
2837
|
"starting",
|
|
2829
2838
|
"started",
|
|
2830
2839
|
"skipped",
|
|
2831
2840
|
"failed"
|
|
2832
2841
|
]).default("starting"),
|
|
2833
|
-
idempotencyKey:
|
|
2842
|
+
idempotencyKey: E().unique(),
|
|
2834
2843
|
skipped: r().default(!1),
|
|
2835
|
-
errorMessage:
|
|
2836
|
-
createdAt:
|
|
2837
|
-
completedAt:
|
|
2838
|
-
}).index(["eventId"]).index(["eventName"]).index(["triggerId"]).index(["workflowName"]).index(["status"]).reactive(),
|
|
2839
|
-
let t = e.makeId ??
|
|
2844
|
+
errorMessage: E().nullable(),
|
|
2845
|
+
createdAt: D().default("now"),
|
|
2846
|
+
completedAt: D().nullable()
|
|
2847
|
+
}).index(["eventId"]).index(["eventName"]).index(["triggerId"]).index(["workflowName"]).index(["status"]).reactive(), Bi = (e) => {
|
|
2848
|
+
let t = e.makeId ?? Ii, n = /* @__PURE__ */ new Map();
|
|
2840
2849
|
for (let t of e.triggers) {
|
|
2841
2850
|
let e = n.get(t.event);
|
|
2842
2851
|
e ? e.push(t) : n.set(t.event, [t]);
|
|
@@ -2877,7 +2886,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2877
2886
|
});
|
|
2878
2887
|
let p = o(n), m = [];
|
|
2879
2888
|
for (let o of p) {
|
|
2880
|
-
let s =
|
|
2889
|
+
let s = Li(o), l = o.workflow, d;
|
|
2881
2890
|
try {
|
|
2882
2891
|
let p = o.idempotencyKey?.(f) ?? `${c}:${s}`;
|
|
2883
2892
|
if (o.filter && !await o.filter(f)) {
|
|
@@ -2980,11 +2989,11 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
2980
2989
|
triggered: m
|
|
2981
2990
|
};
|
|
2982
2991
|
} };
|
|
2983
|
-
},
|
|
2992
|
+
}, Vi = M.effect(Ke.HttpClient, j.map(Ke.HttpClient, (e) => e.pipe(Ke.mapRequestEffect((e) => j.currentSpan.pipe(j.map((t) => e.headers.traceparent === void 0 ? qe.setHeader(e, "traceparent", Rn({
|
|
2984
2993
|
traceId: t.traceId,
|
|
2985
2994
|
spanId: t.spanId,
|
|
2986
2995
|
sampled: t.sampled
|
|
2987
|
-
})) : e), j.catchAll(() => j.succeed(e))))))),
|
|
2996
|
+
})) : e), j.catchAll(() => j.succeed(e))))))), Hi = "voltro/audit", Ui = "voltro/softDelete", Wi = "voltro/tenant", Gi = (e) => {
|
|
2988
2997
|
let t = /* @__PURE__ */ new Map();
|
|
2989
2998
|
for (let n of e) {
|
|
2990
2999
|
let e = /* @__PURE__ */ new Set();
|
|
@@ -3027,48 +3036,48 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3027
3036
|
return !1;
|
|
3028
3037
|
},
|
|
3029
3038
|
idScheme: (e) => t.get(e)?.idScheme,
|
|
3030
|
-
defaultFactories: (e) => t.get(e)?.defaultFactories ??
|
|
3031
|
-
computedFields: (e) => t.get(e)?.computedFields ??
|
|
3039
|
+
defaultFactories: (e) => t.get(e)?.defaultFactories ?? Ki,
|
|
3040
|
+
computedFields: (e) => t.get(e)?.computedFields ?? qi,
|
|
3032
3041
|
insertSchema: (e) => t.get(e)?.insertSchema,
|
|
3033
3042
|
validatePatchSchema: (e) => t.get(e)?.validatePatchSchema
|
|
3034
3043
|
};
|
|
3035
|
-
},
|
|
3044
|
+
}, Ki = /* @__PURE__ */ new Map(), qi = /* @__PURE__ */ new Map(), Ji = Gi([]), Yi = class extends Error {
|
|
3036
3045
|
table;
|
|
3037
3046
|
_tag = "NoRowFound";
|
|
3038
3047
|
constructor(e) {
|
|
3039
3048
|
super(`expected exactly one row in '${e}', found none`), this.table = e, this.name = "NoRowFound";
|
|
3040
3049
|
}
|
|
3041
|
-
},
|
|
3050
|
+
}, Xi = class extends Error {
|
|
3042
3051
|
table;
|
|
3043
3052
|
expected;
|
|
3044
3053
|
_tag = "OptimisticLockError";
|
|
3045
3054
|
constructor(e, t) {
|
|
3046
3055
|
super(`optimistic lock failed on '${e}': expected version ${t}`), this.table = e, this.expected = t, this.name = "OptimisticLockError";
|
|
3047
3056
|
}
|
|
3048
|
-
},
|
|
3049
|
-
if (e.length === 1 &&
|
|
3057
|
+
}, Zi = (e) => typeof e == "object" && !!e && ("and" in e || "or" in e || "not" in e || "op" in e || "subquery" in e), Qi = (e) => {
|
|
3058
|
+
if (e.length === 1 && Zi(e[0])) return e[0];
|
|
3050
3059
|
let t = e[0];
|
|
3051
3060
|
if (e.length === 2) return u(t, e[1]);
|
|
3052
3061
|
let n = e[1], r = e[2];
|
|
3053
3062
|
switch (n) {
|
|
3054
3063
|
case "=": return u(t, r);
|
|
3055
3064
|
case "!=":
|
|
3056
|
-
case "<>": return
|
|
3065
|
+
case "<>": return w(t, r);
|
|
3057
3066
|
case ">": return h(t, r);
|
|
3058
3067
|
case ">=": return g(t, r);
|
|
3059
|
-
case "<": return
|
|
3060
|
-
case "<=": return
|
|
3068
|
+
case "<": return te(t, r);
|
|
3069
|
+
case "<=": return ne(t, r);
|
|
3061
3070
|
case "in": return y(t, r);
|
|
3062
3071
|
case "like":
|
|
3063
3072
|
case "contains":
|
|
3064
3073
|
case "fts": return o(t, r);
|
|
3065
3074
|
default: return u(t, r);
|
|
3066
3075
|
}
|
|
3067
|
-
},
|
|
3076
|
+
}, $i = (e) => {
|
|
3068
3077
|
let t = m(e);
|
|
3069
3078
|
if (t === void 0) throw Error(`unknown table '${e}' — is it declared with table()?`);
|
|
3070
|
-
return
|
|
3071
|
-
},
|
|
3079
|
+
return ie(t);
|
|
3080
|
+
}, ea = class e {
|
|
3072
3081
|
backend;
|
|
3073
3082
|
scope;
|
|
3074
3083
|
table;
|
|
@@ -3082,7 +3091,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3082
3091
|
return new e(this.backend, this.scope, this.table, t, this.skipTenant, this.skipSoftDelete);
|
|
3083
3092
|
}
|
|
3084
3093
|
where(...e) {
|
|
3085
|
-
return this.clone(this.query.where(
|
|
3094
|
+
return this.clone(this.query.where(Qi(e)));
|
|
3086
3095
|
}
|
|
3087
3096
|
orderBy(e, t = "asc") {
|
|
3088
3097
|
return this.clone(this.query.orderBy(e, t));
|
|
@@ -3116,7 +3125,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3116
3125
|
}
|
|
3117
3126
|
scopedQuery() {
|
|
3118
3127
|
let e = this.query, { subject: t, schemaRegistry: n } = this.scope;
|
|
3119
|
-
return !this.skipTenant && n.hasTenant(this.table) && t.tenantId != null && (e = e.where(u("tenantId", t.tenantId))), !this.skipSoftDelete && n.hasSoftDelete(this.table) && (e = e.where(
|
|
3128
|
+
return !this.skipTenant && n.hasTenant(this.table) && t.tenantId != null && (e = e.where(u("tenantId", t.tenantId))), !this.skipSoftDelete && n.hasSoftDelete(this.table) && (e = e.where(S("deletedAt"))), e;
|
|
3120
3129
|
}
|
|
3121
3130
|
async all() {
|
|
3122
3131
|
return this.backend.query(this.scopedQuery().descriptor);
|
|
@@ -3129,7 +3138,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3129
3138
|
}
|
|
3130
3139
|
async one() {
|
|
3131
3140
|
let e = await this.maybeOne();
|
|
3132
|
-
if (e === null) throw new
|
|
3141
|
+
if (e === null) throw new Yi(this.table);
|
|
3133
3142
|
return e;
|
|
3134
3143
|
}
|
|
3135
3144
|
async count() {
|
|
@@ -3142,7 +3151,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3142
3151
|
get descriptor() {
|
|
3143
3152
|
return this.scopedQuery().descriptor;
|
|
3144
3153
|
}
|
|
3145
|
-
},
|
|
3154
|
+
}, ta = class {
|
|
3146
3155
|
backend;
|
|
3147
3156
|
scope;
|
|
3148
3157
|
table;
|
|
@@ -3153,7 +3162,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3153
3162
|
this.backend = e, this.scope = t, this.table = n;
|
|
3154
3163
|
}
|
|
3155
3164
|
where(...e) {
|
|
3156
|
-
let n =
|
|
3165
|
+
let n = Qi(e);
|
|
3157
3166
|
return this.predicate = this.predicate ? t(this.predicate, n) : n, this;
|
|
3158
3167
|
}
|
|
3159
3168
|
unscoped() {
|
|
@@ -3177,13 +3186,13 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3177
3186
|
}
|
|
3178
3187
|
async set(e) {
|
|
3179
3188
|
let t = await this.backend.updateMany(this.table, e, { where: this.scopedWhere() });
|
|
3180
|
-
if (this.expectedVersion !== void 0 && t === 0) throw new
|
|
3189
|
+
if (this.expectedVersion !== void 0 && t === 0) throw new Xi(this.table, this.expectedVersion);
|
|
3181
3190
|
return t;
|
|
3182
3191
|
}
|
|
3183
3192
|
async restore() {
|
|
3184
3193
|
return this.backend.updateMany(this.table, { deletedAt: null }, { where: this.scopedWhere() });
|
|
3185
3194
|
}
|
|
3186
|
-
},
|
|
3195
|
+
}, na = class {
|
|
3187
3196
|
backend;
|
|
3188
3197
|
scope;
|
|
3189
3198
|
table;
|
|
@@ -3193,7 +3202,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3193
3202
|
this.backend = e, this.scope = t, this.table = n;
|
|
3194
3203
|
}
|
|
3195
3204
|
where(...e) {
|
|
3196
|
-
let n =
|
|
3205
|
+
let n = Qi(e);
|
|
3197
3206
|
return this.predicate = this.predicate ? t(this.predicate, n) : n, this;
|
|
3198
3207
|
}
|
|
3199
3208
|
unscoped() {
|
|
@@ -3214,46 +3223,46 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3214
3223
|
async hard() {
|
|
3215
3224
|
return this.backend.deleteMany(this.table, { where: this.scopedWhere() });
|
|
3216
3225
|
}
|
|
3217
|
-
},
|
|
3218
|
-
select: (n) => new
|
|
3219
|
-
updateWhere: (n) => new
|
|
3220
|
-
deleteWhere: (n) => new
|
|
3221
|
-
}),
|
|
3226
|
+
}, ra = (e, t) => ({
|
|
3227
|
+
select: (n) => new ea(e, t, n, $i(n)),
|
|
3228
|
+
updateWhere: (n) => new ta(e, t, n),
|
|
3229
|
+
deleteWhere: (n) => new na(e, t, n)
|
|
3230
|
+
}), ia = class extends I.TaggedError()("TenantScopeViolation", {
|
|
3222
3231
|
table: I.String,
|
|
3223
3232
|
reason: I.String
|
|
3224
|
-
}) {},
|
|
3233
|
+
}) {}, aa = class extends I.TaggedError()("StoreOperationFailed", {
|
|
3225
3234
|
operation: I.String,
|
|
3226
3235
|
table: I.String,
|
|
3227
3236
|
cause: I.String
|
|
3228
|
-
}) {},
|
|
3237
|
+
}) {}, oa = class extends I.TaggedError()("TableValidationFailed", {
|
|
3229
3238
|
table: I.String,
|
|
3230
3239
|
summary: I.String,
|
|
3231
3240
|
issues: I.Array(I.Struct({
|
|
3232
3241
|
path: I.String,
|
|
3233
3242
|
message: I.String
|
|
3234
3243
|
}))
|
|
3235
|
-
}) {},
|
|
3244
|
+
}) {}, sa = "id", ca = (e, t) => {
|
|
3236
3245
|
let n = {};
|
|
3237
3246
|
for (let r of t) e[r] !== void 0 && (n[r] = e[r]);
|
|
3238
3247
|
return n;
|
|
3239
|
-
},
|
|
3240
|
-
throw new
|
|
3248
|
+
}, la = "cannot insert into tenant-scoped table without an authenticated tenant — subject.tenantId is null. Either authenticate first or pass tenantId explicitly in the row (admin tooling).", ua = (e) => {
|
|
3249
|
+
throw new ia({
|
|
3241
3250
|
table: e,
|
|
3242
|
-
reason:
|
|
3251
|
+
reason: la
|
|
3243
3252
|
});
|
|
3244
|
-
},
|
|
3253
|
+
}, da = (e, n) => {
|
|
3245
3254
|
let r = n.subject.id, i = n.subject.tenantId, a = (e, t) => {
|
|
3246
3255
|
let a = { ...t }, o = n.schemaRegistry, s = o.idScheme(e);
|
|
3247
|
-
if (s !== void 0 && a[
|
|
3256
|
+
if (s !== void 0 && a[sa] == null) if (s.kind === "numeric") delete a[sa];
|
|
3248
3257
|
else {
|
|
3249
3258
|
let t = f(s, e);
|
|
3250
|
-
t !== null && (a[
|
|
3259
|
+
t !== null && (a[sa] = t);
|
|
3251
3260
|
}
|
|
3252
3261
|
if (o.hasAudit(e)) {
|
|
3253
3262
|
let e = /* @__PURE__ */ new Date();
|
|
3254
3263
|
"createdAt" in a || (a.createdAt = e), "updatedAt" in a || (a.updatedAt = e), r !== null && ("createdBy" in a || (a.createdBy = r), "updatedBy" in a || (a.updatedBy = r));
|
|
3255
3264
|
}
|
|
3256
|
-
o.hasTenant(e) && ("tenantId" in a || (i === null &&
|
|
3265
|
+
o.hasTenant(e) && ("tenantId" in a || (i === null && ua(e), a.tenantId = i));
|
|
3257
3266
|
let c = o.defaultFactories(e);
|
|
3258
3267
|
if (c.size > 0) for (let [e, t] of c) (!(e in a) || a[e] === void 0) && (a[e] = t());
|
|
3259
3268
|
let l = o.computedFields(e);
|
|
@@ -3268,10 +3277,10 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3268
3277
|
try {
|
|
3269
3278
|
return await r();
|
|
3270
3279
|
} catch (n) {
|
|
3271
|
-
let r =
|
|
3272
|
-
if (
|
|
3280
|
+
let r = zt(n);
|
|
3281
|
+
if (Bt(r)) {
|
|
3273
3282
|
let n = t.tenantId, i = `${r.dbConstraint ?? ""} ${r.dbColumn ?? ""} ${r.dbMessage ?? ""} ${r.dbCauseChain ?? ""}`.toLowerCase();
|
|
3274
|
-
if (i.includes("tenantid") || /\btenants\b/.test(i) || n != null && i.includes(String(n).toLowerCase())) throw new
|
|
3283
|
+
if (i.includes("tenantid") || /\btenants\b/.test(i) || n != null && i.includes(String(n).toLowerCase())) throw new ia({
|
|
3275
3284
|
table: e,
|
|
3276
3285
|
reason: n == null ? "write references a tenant that does not exist" : `tenant '${String(n)}' does not exist — seed the row in \`tenants\`, or fix how the request resolved this tenant (subject.tenantId / the x-tenant header / the dev TENANT fallback)`
|
|
3277
3286
|
});
|
|
@@ -3292,11 +3301,11 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3292
3301
|
if (r === void 0) return t;
|
|
3293
3302
|
let i = I.decodeUnknownEither(r)(t);
|
|
3294
3303
|
if (i._tag === "Right") return t;
|
|
3295
|
-
let a =
|
|
3304
|
+
let a = gt.formatErrorSync(i.left).map((e) => ({
|
|
3296
3305
|
path: e.path.length === 0 ? "<root>" : e.path.join("."),
|
|
3297
3306
|
message: e.message
|
|
3298
3307
|
})), o = a[0];
|
|
3299
|
-
throw new
|
|
3308
|
+
throw new oa({
|
|
3300
3309
|
table: e,
|
|
3301
3310
|
summary: o === void 0 ? "patch validation failed" : `${o.path}: ${o.message}`,
|
|
3302
3311
|
issues: a
|
|
@@ -3309,29 +3318,29 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3309
3318
|
if (r === void 0) return t;
|
|
3310
3319
|
let i = I.decodeUnknownEither(r)(t);
|
|
3311
3320
|
if (i._tag === "Right") return t;
|
|
3312
|
-
let a =
|
|
3321
|
+
let a = gt.formatErrorSync(i.left).map((e) => ({
|
|
3313
3322
|
path: e.path.length === 0 ? "<root>" : e.path.join("."),
|
|
3314
3323
|
message: e.message
|
|
3315
3324
|
})), o = a[0];
|
|
3316
|
-
throw new
|
|
3325
|
+
throw new oa({
|
|
3317
3326
|
table: e,
|
|
3318
3327
|
summary: o === void 0 ? "row validation failed" : `${o.path}: ${o.message}`,
|
|
3319
3328
|
issues: a
|
|
3320
3329
|
});
|
|
3321
3330
|
}, v = n.dialect, y = (e, t) => {
|
|
3322
3331
|
let n = m(e);
|
|
3323
|
-
return l(v ?
|
|
3332
|
+
return l(v ? ce(t, n, v) : t, n, qr());
|
|
3324
3333
|
}, b = (e, t) => {
|
|
3325
|
-
let n = m(e), r = s(t, n,
|
|
3334
|
+
let n = m(e), r = s(t, n, qr());
|
|
3326
3335
|
return v ? c(r, n, v) : r;
|
|
3327
|
-
},
|
|
3336
|
+
}, x = (e) => {
|
|
3328
3337
|
let r = e.table, a = e.predicate;
|
|
3329
3338
|
if (!e.crossTenant && i != null && n.schemaRegistry.hasTenant(r)) {
|
|
3330
3339
|
let e = u("tenantId", i);
|
|
3331
3340
|
a = a ? t(a, e) : e;
|
|
3332
3341
|
}
|
|
3333
3342
|
if (!e.includeDeleted && n.schemaRegistry.hasSoftDelete(r)) {
|
|
3334
|
-
let e =
|
|
3343
|
+
let e = S("deletedAt");
|
|
3335
3344
|
a = a ? t(a, e) : e;
|
|
3336
3345
|
}
|
|
3337
3346
|
return a === e.predicate ? e : {
|
|
@@ -3341,13 +3350,13 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3341
3350
|
}, C = async (t) => {
|
|
3342
3351
|
let n = await e.query(t);
|
|
3343
3352
|
return b(t.table, n);
|
|
3344
|
-
},
|
|
3353
|
+
}, ee = async (e) => C(x(e)), te = async (t, r, i) => {
|
|
3345
3354
|
let a = o(t, i);
|
|
3346
3355
|
if (n.schemaRegistry.computedFields(t).size > 0) {
|
|
3347
3356
|
let n = (await e.query({
|
|
3348
3357
|
table: t,
|
|
3349
3358
|
predicate: {
|
|
3350
|
-
column:
|
|
3359
|
+
column: sa,
|
|
3351
3360
|
op: "eq",
|
|
3352
3361
|
value: r
|
|
3353
3362
|
},
|
|
@@ -3362,23 +3371,23 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3362
3371
|
a = h(t, a);
|
|
3363
3372
|
let s = await e.update(t, r, y(t, a));
|
|
3364
3373
|
return s === null ? null : b(t, [s])[0];
|
|
3365
|
-
},
|
|
3374
|
+
}, ne = async (t, r) => n.schemaRegistry.hasSoftDelete(t) ? await e.update(t, r, g()) !== null : e.delete(t, r), w = async (t, n, r) => e.updateMany(t, y(t, o(t, n)), r), re = async (t, n) => e.deleteMany(t, n), ie = (e, r) => i != null && n.schemaRegistry.hasTenant(e) ? t(r, u("tenantId", i)) : r, ae = async (e, t, n) => w(e, t, {
|
|
3366
3375
|
...n,
|
|
3367
|
-
where:
|
|
3368
|
-
}),
|
|
3376
|
+
where: ie(e, n.where)
|
|
3377
|
+
}), oe = async (e, t) => re(e, {
|
|
3369
3378
|
...t,
|
|
3370
|
-
where:
|
|
3371
|
-
}), se =
|
|
3379
|
+
where: ie(e, t.where)
|
|
3380
|
+
}), se = ra({
|
|
3372
3381
|
query: C,
|
|
3373
|
-
updateMany:
|
|
3374
|
-
deleteMany:
|
|
3382
|
+
updateMany: w,
|
|
3383
|
+
deleteMany: re,
|
|
3375
3384
|
delete: (t, n) => e.delete(t, n)
|
|
3376
3385
|
}, {
|
|
3377
3386
|
subject: n.subject,
|
|
3378
3387
|
schemaRegistry: n.schemaRegistry
|
|
3379
3388
|
});
|
|
3380
3389
|
return {
|
|
3381
|
-
query:
|
|
3390
|
+
query: ee,
|
|
3382
3391
|
insert: async (t, n) => {
|
|
3383
3392
|
let r = a(t, n), i = await d(t, r, () => e.insert(t, y(t, _(t, r))));
|
|
3384
3393
|
return b(t, [i])[0];
|
|
@@ -3392,12 +3401,12 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3392
3401
|
return a === null ? null : b(t, [a])[0];
|
|
3393
3402
|
},
|
|
3394
3403
|
select: se.select,
|
|
3395
|
-
update: ((e, t, n) => t === void 0 ? se.updateWhere(e) :
|
|
3396
|
-
delete: ((e, t) => t === void 0 ? se.deleteWhere(e) :
|
|
3397
|
-
applyDefined:
|
|
3404
|
+
update: ((e, t, n) => t === void 0 ? se.updateWhere(e) : te(e, t, n)),
|
|
3405
|
+
delete: ((e, t) => t === void 0 ? se.deleteWhere(e) : ne(e, t)),
|
|
3406
|
+
applyDefined: ca,
|
|
3398
3407
|
hardDelete: async (t, n) => e.delete(t, n),
|
|
3399
|
-
updateMany:
|
|
3400
|
-
deleteMany:
|
|
3408
|
+
updateMany: ae,
|
|
3409
|
+
deleteMany: oe,
|
|
3401
3410
|
upsert: async (t, n, r) => {
|
|
3402
3411
|
let i = a(t, n), o = await d(t, i, () => e.upsert(t, y(t, _(t, i)), r));
|
|
3403
3412
|
return b(t, [o])[0];
|
|
@@ -3406,34 +3415,34 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3406
3415
|
let i = a(t, n), o = await d(t, i, () => e.insertIgnore(t, y(t, _(t, i)), r));
|
|
3407
3416
|
return b(t, [o])[0];
|
|
3408
3417
|
},
|
|
3409
|
-
transactional: (t) => e.transactional(async (e) => t(
|
|
3418
|
+
transactional: (t) => e.transactional(async (e) => t(da(e, n))),
|
|
3410
3419
|
...e.raw ? { raw: e.raw.bind(e) } : {},
|
|
3411
3420
|
onChange: (t) => e.onChange(t),
|
|
3412
3421
|
injectExternalChange: (t) => e.injectExternalChange(t),
|
|
3413
3422
|
...e.changeScope === void 0 ? {} : { changeScope: e.changeScope }
|
|
3414
3423
|
};
|
|
3415
|
-
},
|
|
3424
|
+
}, fa = class extends I.TaggedError()("CircuitOpen", {
|
|
3416
3425
|
name: I.String,
|
|
3417
3426
|
retryAfterMs: I.Number
|
|
3418
|
-
}) {},
|
|
3427
|
+
}) {}, pa = {
|
|
3419
3428
|
tag: "closed",
|
|
3420
3429
|
failureCount: 0,
|
|
3421
3430
|
halfOpenSuccesses: 0,
|
|
3422
3431
|
openedAt: 0
|
|
3423
|
-
},
|
|
3424
|
-
let t = e.name ?? "circuit", n =
|
|
3432
|
+
}, ma = { make: (e) => j.gen(function* () {
|
|
3433
|
+
let t = e.name ?? "circuit", n = Le.toMillis(Le.decode(e.resetTimeout)), r = e.halfOpenSuccessThreshold ?? 1, i = e.isFailure ?? (() => !0), a = yield* F.make(pa), o = j.gen(function* () {
|
|
3425
3434
|
let e = yield* F.get(a);
|
|
3426
3435
|
if (e.tag === "half-open") {
|
|
3427
3436
|
let t = e.halfOpenSuccesses + 1;
|
|
3428
|
-
yield* F.set(a, t >= r ?
|
|
3437
|
+
yield* F.set(a, t >= r ? pa : {
|
|
3429
3438
|
...e,
|
|
3430
3439
|
halfOpenSuccesses: t
|
|
3431
3440
|
});
|
|
3432
3441
|
return;
|
|
3433
3442
|
}
|
|
3434
|
-
e.failureCount !== 0 && (yield* F.set(a,
|
|
3443
|
+
e.failureCount !== 0 && (yield* F.set(a, pa));
|
|
3435
3444
|
}), s = j.gen(function* () {
|
|
3436
|
-
let t = yield*
|
|
3445
|
+
let t = yield* Pe.currentTimeMillis, n = yield* F.get(a);
|
|
3437
3446
|
if (n.tag === "half-open" || n.tag === "open") {
|
|
3438
3447
|
yield* F.set(a, {
|
|
3439
3448
|
tag: "open",
|
|
@@ -3456,7 +3465,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3456
3465
|
}), c = j.gen(function* () {
|
|
3457
3466
|
let e = yield* F.get(a);
|
|
3458
3467
|
if (e.tag !== "open") return null;
|
|
3459
|
-
let t = (yield*
|
|
3468
|
+
let t = (yield* Pe.currentTimeMillis) - e.openedAt;
|
|
3460
3469
|
return t >= n ? (yield* F.set(a, {
|
|
3461
3470
|
tag: "half-open",
|
|
3462
3471
|
failureCount: 0,
|
|
@@ -3469,7 +3478,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3469
3478
|
if (k.isInterruptedOnly(e)) return j.void;
|
|
3470
3479
|
let t = k.failureOption(e), n = t._tag === "Some" ? t.value : void 0;
|
|
3471
3480
|
return i(n) ? s : j.void;
|
|
3472
|
-
})) : yield* j.fail(new
|
|
3481
|
+
})) : yield* j.fail(new fa({
|
|
3473
3482
|
name: t,
|
|
3474
3483
|
retryAfterMs: n
|
|
3475
3484
|
}));
|
|
@@ -3478,38 +3487,38 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3478
3487
|
value: F.get(a).pipe(j.map((e) => e.tag)),
|
|
3479
3488
|
enumerable: !0
|
|
3480
3489
|
}), Object.defineProperty(u, "reset", {
|
|
3481
|
-
value: F.set(a,
|
|
3490
|
+
value: F.set(a, pa),
|
|
3482
3491
|
enumerable: !0
|
|
3483
3492
|
}), u;
|
|
3484
|
-
}) },
|
|
3485
|
-
|
|
3486
|
-
},
|
|
3487
|
-
|
|
3488
|
-
},
|
|
3489
|
-
let n = t.scopes === void 0 ?
|
|
3493
|
+
}) }, ha, ga = (e) => {
|
|
3494
|
+
ha = e;
|
|
3495
|
+
}, _a = () => {
|
|
3496
|
+
ha = void 0;
|
|
3497
|
+
}, va = async (e, t = {}) => {
|
|
3498
|
+
let n = t.scopes === void 0 ? je(t.id ?? "system") : je(t.id ?? "system", t.scopes), r = t.store ?? ha?.dataStore, i = t.schemaRegistry ?? ha?.schemaRegistry, a = t.dialect ?? ha?.dialect;
|
|
3490
3499
|
if (r === void 0 || i === void 0) throw Error("runAsSystem: no data store available — register one at boot via setSystemStoreHandle({ dataStore, schemaRegistry }) or pass { store, schemaRegistry } in the options.");
|
|
3491
3500
|
return e({
|
|
3492
3501
|
subject: n,
|
|
3493
|
-
store:
|
|
3502
|
+
store: da(r, {
|
|
3494
3503
|
subject: n,
|
|
3495
3504
|
schemaRegistry: i,
|
|
3496
3505
|
...a === void 0 ? {} : { dialect: a }
|
|
3497
3506
|
})
|
|
3498
3507
|
});
|
|
3499
|
-
},
|
|
3508
|
+
}, ya = class extends Fe.Tag("@voltro/EffectStore")() {}, ba = (e, t) => (n) => n instanceof ia ? n : new aa({
|
|
3500
3509
|
operation: e,
|
|
3501
3510
|
table: t,
|
|
3502
3511
|
cause: String(n)
|
|
3503
|
-
}),
|
|
3512
|
+
}), xa = (e, t, n) => j.tryPromise({
|
|
3504
3513
|
try: n,
|
|
3505
|
-
catch:
|
|
3506
|
-
}),
|
|
3507
|
-
query: (t) =>
|
|
3508
|
-
insert: (t, n) =>
|
|
3509
|
-
update: (t, n, r) =>
|
|
3510
|
-
delete: (t, n) =>
|
|
3511
|
-
hardDelete: (t, n) =>
|
|
3512
|
-
}),
|
|
3514
|
+
catch: ba(e, t)
|
|
3515
|
+
}), Sa = (e) => M.succeed(ya, {
|
|
3516
|
+
query: (t) => xa("query", t.table, () => e.query(t)),
|
|
3517
|
+
insert: (t, n) => xa("insert", t, () => e.insert(t, n)),
|
|
3518
|
+
update: (t, n, r) => xa("update", t, () => e.update(t, n, r)),
|
|
3519
|
+
delete: (t, n) => xa("delete", t, () => e.delete(t, n)),
|
|
3520
|
+
hardDelete: (t, n) => xa("hardDelete", t, () => e.hardDelete(t, n))
|
|
3521
|
+
}), Ca = (e) => {
|
|
3513
3522
|
let { currentRegion: t, replicaRegions: n, inner: r } = e, i = (e) => {
|
|
3514
3523
|
if (t === void 0) return {
|
|
3515
3524
|
sameRegion: [],
|
|
@@ -3537,7 +3546,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3537
3546
|
return r.loadSnapshot();
|
|
3538
3547
|
}
|
|
3539
3548
|
};
|
|
3540
|
-
},
|
|
3549
|
+
}, wa = (e = process.env) => {
|
|
3541
3550
|
for (let t of [
|
|
3542
3551
|
"VOLTRO_REGION",
|
|
3543
3552
|
"AWS_REGION",
|
|
@@ -3549,7 +3558,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3549
3558
|
let n = e[t];
|
|
3550
3559
|
if (typeof n == "string" && n.length > 0) return n;
|
|
3551
3560
|
}
|
|
3552
|
-
},
|
|
3561
|
+
}, Ta = () => {
|
|
3553
3562
|
let e = {
|
|
3554
3563
|
primary: 0,
|
|
3555
3564
|
lagByReplica: /* @__PURE__ */ new Map()
|
|
@@ -3574,27 +3583,27 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3574
3583
|
e.lagByReplica.set(t, n);
|
|
3575
3584
|
}
|
|
3576
3585
|
};
|
|
3577
|
-
},
|
|
3586
|
+
}, Ea = Symbol.for("@voltro/ScheduleDefinition"), Da = (e) => typeof e == "object" && !!e && Ea in e, Oa = 30 * 6e4, ka = (e) => {
|
|
3578
3587
|
let t = A.parse(e.cron, e.timezone);
|
|
3579
|
-
if (
|
|
3588
|
+
if (Re.isLeft(t)) throw Error(`defineSchedule("${e.name}"): invalid cron expression "${e.cron}" (tz="${e.timezone}") — ${String(t.left)}`);
|
|
3580
3589
|
if (!e.timezone || e.timezone.trim() === "") throw Error(`defineSchedule("${e.name}"): timezone is required (e.g. "UTC", "Europe/Berlin")`);
|
|
3581
3590
|
if (e.handler === void 0 && e.workflow === void 0) throw Error(`defineSchedule("${e.name}"): define either handler or workflow`);
|
|
3582
3591
|
return {
|
|
3583
3592
|
...e,
|
|
3584
3593
|
onOverlap: e.onOverlap ?? "skip",
|
|
3585
3594
|
backfill: e.backfill ?? "skip",
|
|
3586
|
-
maxRuntimeMs: e.maxRuntimeMs ??
|
|
3587
|
-
[
|
|
3595
|
+
maxRuntimeMs: e.maxRuntimeMs ?? Oa,
|
|
3596
|
+
[Ea]: !0
|
|
3588
3597
|
};
|
|
3589
|
-
},
|
|
3598
|
+
}, Aa = (e) => A.unsafeParse(e.cron, e.timezone), ja = (e, t = /* @__PURE__ */ new Date()) => A.next(Aa(e), t), Z = "_voltro_wakeups", Ma = (e) => `${e.tenantId}:${e.kind}:${e.refId}`, Na = (e) => ({
|
|
3590
3599
|
tenantId: String(e.tenantId),
|
|
3591
3600
|
kind: String(e.kind),
|
|
3592
3601
|
refId: String(e.refId),
|
|
3593
3602
|
wakeAt: e.wakeAt instanceof Date ? e.wakeAt : new Date(String(e.wakeAt)),
|
|
3594
3603
|
status: e.status === "fired" ? "fired" : "pending"
|
|
3595
|
-
}),
|
|
3604
|
+
}), Pa = async (e, t) => {
|
|
3596
3605
|
await e.upsert(Z, {
|
|
3597
|
-
id:
|
|
3606
|
+
id: Ma(t),
|
|
3598
3607
|
tenantId: t.tenantId,
|
|
3599
3608
|
kind: t.kind,
|
|
3600
3609
|
refId: t.refId,
|
|
@@ -3604,7 +3613,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3604
3613
|
conflictColumns: ["id"],
|
|
3605
3614
|
update: ["wakeAt", "status"]
|
|
3606
3615
|
});
|
|
3607
|
-
},
|
|
3616
|
+
}, Fa = async (e, t) => e.delete(Z, Ma(t)), Ia = async (e, t) => await e.update(Z, Ma(t), { status: "fired" }) !== null, La = (e, t) => ({ and: [{
|
|
3608
3617
|
column: "id",
|
|
3609
3618
|
op: "eq",
|
|
3610
3619
|
value: e
|
|
@@ -3612,16 +3621,16 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3612
3621
|
column: "status",
|
|
3613
3622
|
op: "eq",
|
|
3614
3623
|
value: t
|
|
3615
|
-
}] }),
|
|
3616
|
-
await e.updateMany(Z, { status: "pending" }, { where:
|
|
3617
|
-
},
|
|
3624
|
+
}] }), Ra = async (e, t) => await e.updateMany(Z, { status: "fired" }, { where: La(Ma(t), "pending") }) > 0, za = async (e, t) => {
|
|
3625
|
+
await e.updateMany(Z, { status: "pending" }, { where: La(Ma(t), "fired") });
|
|
3626
|
+
}, Ba = {
|
|
3618
3627
|
column: "status",
|
|
3619
3628
|
op: "eq",
|
|
3620
3629
|
value: "pending"
|
|
3621
|
-
},
|
|
3630
|
+
}, Va = async (e, t) => {
|
|
3622
3631
|
let n = {
|
|
3623
3632
|
table: Z,
|
|
3624
|
-
predicate:
|
|
3633
|
+
predicate: Ba,
|
|
3625
3634
|
order: [{
|
|
3626
3635
|
column: "wakeAt",
|
|
3627
3636
|
direction: "asc"
|
|
@@ -3630,18 +3639,18 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3630
3639
|
skip: void 0,
|
|
3631
3640
|
projection: void 0
|
|
3632
3641
|
};
|
|
3633
|
-
return (await e.query(n)).map(
|
|
3634
|
-
},
|
|
3635
|
-
let r = await
|
|
3642
|
+
return (await e.query(n)).map(Na);
|
|
3643
|
+
}, Ha = async (e, t, n = 500) => {
|
|
3644
|
+
let r = await Va(e, n), i = t.getTime();
|
|
3636
3645
|
return r.filter((e) => e.wakeAt.getTime() <= i);
|
|
3637
|
-
},
|
|
3646
|
+
}, Ua = async (e) => (await Va(e, 1))[0] ?? null, Wa = {
|
|
3638
3647
|
column: "status",
|
|
3639
3648
|
op: "eq",
|
|
3640
3649
|
value: "fired"
|
|
3641
|
-
},
|
|
3650
|
+
}, Ga = async (e, t = {}) => {
|
|
3642
3651
|
let n = {
|
|
3643
3652
|
table: Z,
|
|
3644
|
-
predicate:
|
|
3653
|
+
predicate: Wa,
|
|
3645
3654
|
order: [{
|
|
3646
3655
|
column: "wakeAt",
|
|
3647
3656
|
direction: "asc"
|
|
@@ -3652,12 +3661,12 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3652
3661
|
}, r = await e.query(n), i = t.firedOlderThan?.getTime(), a = 0;
|
|
3653
3662
|
for (let t of r) i !== void 0 && (t.wakeAt instanceof Date ? t.wakeAt : new Date(String(t.wakeAt))).getTime() >= i || await e.delete(Z, String(t.id)) && a++;
|
|
3654
3663
|
return a;
|
|
3655
|
-
},
|
|
3664
|
+
}, Ka = {
|
|
3656
3665
|
kind: "single",
|
|
3657
3666
|
tryClaim: async () => !0
|
|
3658
|
-
},
|
|
3667
|
+
}, qa = "_voltro_schedule_claims", Ja = (e, t, n) => {
|
|
3659
3668
|
let r = async (t) => (await e.query({
|
|
3660
|
-
table:
|
|
3669
|
+
table: qa,
|
|
3661
3670
|
order: [],
|
|
3662
3671
|
predicate: void 0,
|
|
3663
3672
|
projection: ["id"],
|
|
@@ -3672,7 +3681,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3672
3681
|
if (await r(s)) return !1;
|
|
3673
3682
|
} catch {}
|
|
3674
3683
|
try {
|
|
3675
|
-
return await e.insert(
|
|
3684
|
+
return await e.insert(qa, {
|
|
3676
3685
|
id: s,
|
|
3677
3686
|
scheduleName: i,
|
|
3678
3687
|
bucket: o,
|
|
@@ -3690,12 +3699,12 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3690
3699
|
}
|
|
3691
3700
|
}
|
|
3692
3701
|
};
|
|
3693
|
-
},
|
|
3702
|
+
}, Ya = "_voltro_schedule_runs", Xa = async (e, t) => {
|
|
3694
3703
|
let { store: n, coordinator: r, buildContext: i, replicaId: a, log: o, onRunEvent: s, interceptFire: c } = t, l = t.dormancy === "sleep", u = t.dormancyTenantId ?? "default", d = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Map(), m = !1, h = new Map(e.map((e) => [e.name, e])), g = (e, t) => {
|
|
3695
|
-
s?.(e,
|
|
3704
|
+
s?.(e, Qa(t));
|
|
3696
3705
|
}, _ = async (e, t, r, i, s, c) => {
|
|
3697
3706
|
try {
|
|
3698
|
-
let o = `sr_${
|
|
3707
|
+
let o = `sr_${he()}`, l = await n.insert(Ya, {
|
|
3699
3708
|
id: o,
|
|
3700
3709
|
name: e.name,
|
|
3701
3710
|
status: i,
|
|
@@ -3720,7 +3729,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3720
3729
|
}
|
|
3721
3730
|
}, v = async (e, t) => {
|
|
3722
3731
|
try {
|
|
3723
|
-
let r = await n.update(
|
|
3732
|
+
let r = await n.update(Ya, e, t);
|
|
3724
3733
|
r && g("update", r);
|
|
3725
3734
|
} catch (t) {
|
|
3726
3735
|
o.warn("schedule: failed to record run finish", {
|
|
@@ -3731,7 +3740,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3731
3740
|
}, y = async (e) => {
|
|
3732
3741
|
try {
|
|
3733
3742
|
let t = await n.query({
|
|
3734
|
-
table:
|
|
3743
|
+
table: Ya,
|
|
3735
3744
|
predicate: {
|
|
3736
3745
|
_tag: "leaf",
|
|
3737
3746
|
column: "status",
|
|
@@ -3796,7 +3805,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3796
3805
|
let n = Q(t).includes("exceeded maxRuntimeMs");
|
|
3797
3806
|
s && await v(s, {
|
|
3798
3807
|
status: "failed",
|
|
3799
|
-
errorTag: n ? "timeout" :
|
|
3808
|
+
errorTag: n ? "timeout" : Za(t),
|
|
3800
3809
|
errorMessage: Q(t),
|
|
3801
3810
|
completedAt: /* @__PURE__ */ new Date(),
|
|
3802
3811
|
durationMs: Date.now() - l
|
|
@@ -3804,7 +3813,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3804
3813
|
name: e.name,
|
|
3805
3814
|
reason: Q(t),
|
|
3806
3815
|
timeout: n
|
|
3807
|
-
}),
|
|
3816
|
+
}), ke({
|
|
3808
3817
|
error: t,
|
|
3809
3818
|
source: "schedule",
|
|
3810
3819
|
name: e.name,
|
|
@@ -3853,8 +3862,8 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3853
3862
|
}
|
|
3854
3863
|
}, C = async (e) => {
|
|
3855
3864
|
try {
|
|
3856
|
-
let t = A.next(
|
|
3857
|
-
await
|
|
3865
|
+
let t = A.next(Aa(e), /* @__PURE__ */ new Date());
|
|
3866
|
+
await Pa(n, {
|
|
3858
3867
|
tenantId: u,
|
|
3859
3868
|
kind: "schedule",
|
|
3860
3869
|
refId: e.name,
|
|
@@ -3866,13 +3875,13 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3866
3875
|
reason: Q(t)
|
|
3867
3876
|
});
|
|
3868
3877
|
}
|
|
3869
|
-
},
|
|
3878
|
+
}, ee = 2147483647, te = (e) => {
|
|
3870
3879
|
if (m) return;
|
|
3871
|
-
let n =
|
|
3880
|
+
let n = Aa(e), r = A.next(n, /* @__PURE__ */ new Date()), i = () => {
|
|
3872
3881
|
if (m) return;
|
|
3873
3882
|
let n = r.getTime() - Date.now();
|
|
3874
|
-
if (n >
|
|
3875
|
-
let t = setTimeout(i,
|
|
3883
|
+
if (n > ee) {
|
|
3884
|
+
let t = setTimeout(i, ee);
|
|
3876
3885
|
d.set(e.name, t);
|
|
3877
3886
|
return;
|
|
3878
3887
|
}
|
|
@@ -3880,17 +3889,17 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3880
3889
|
x(e, r, e.trigger ?? t.defaultTrigger).catch((t) => o.warn("schedule: fire rejected", {
|
|
3881
3890
|
name: e.name,
|
|
3882
3891
|
reason: Q(t)
|
|
3883
|
-
})).finally(() =>
|
|
3892
|
+
})).finally(() => te(e));
|
|
3884
3893
|
}, Math.max(0, n));
|
|
3885
3894
|
d.set(e.name, a);
|
|
3886
3895
|
};
|
|
3887
3896
|
i();
|
|
3888
|
-
},
|
|
3897
|
+
}, ne = async (e) => {
|
|
3889
3898
|
if (e.backfill === "skip") return;
|
|
3890
3899
|
let r;
|
|
3891
3900
|
try {
|
|
3892
3901
|
let t = (await n.query({
|
|
3893
|
-
table:
|
|
3902
|
+
table: Ya,
|
|
3894
3903
|
order: [{
|
|
3895
3904
|
column: "scheduledAt",
|
|
3896
3905
|
direction: "desc"
|
|
@@ -3909,7 +3918,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3909
3918
|
return;
|
|
3910
3919
|
}
|
|
3911
3920
|
if (!r) return;
|
|
3912
|
-
let i =
|
|
3921
|
+
let i = Aa(e), a = [], s = A.next(i, r), c = Date.now();
|
|
3913
3922
|
for (; s.getTime() < c && a.length < 1e3;) a.push(s), s = A.next(i, s);
|
|
3914
3923
|
if (a.length !== 0) if (o.info("schedule: backfill", {
|
|
3915
3924
|
name: e.name,
|
|
@@ -3920,20 +3929,20 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3920
3929
|
let n = a[a.length - 1];
|
|
3921
3930
|
await x(e, n, e.trigger ?? t.defaultTrigger);
|
|
3922
3931
|
} else for (let n of a) await x(e, n, e.trigger ?? t.defaultTrigger);
|
|
3923
|
-
},
|
|
3932
|
+
}, w = e.filter((e) => (e.trigger ?? t.defaultTrigger) === "self");
|
|
3924
3933
|
o.info("scheduler: starting", {
|
|
3925
3934
|
total: e.length,
|
|
3926
|
-
self:
|
|
3927
|
-
external: e.length -
|
|
3935
|
+
self: w.length,
|
|
3936
|
+
external: e.length - w.length,
|
|
3928
3937
|
coordinator: r.kind
|
|
3929
3938
|
});
|
|
3930
|
-
let
|
|
3939
|
+
let re = (t.armSelf ?? !0) && !l;
|
|
3931
3940
|
if (l) {
|
|
3932
|
-
o.info("scheduler: sleep mode — registering wakeups, not arming timers", { count:
|
|
3933
|
-
for (let e of
|
|
3934
|
-
} else if (
|
|
3935
|
-
for (let e of
|
|
3936
|
-
for (let e of
|
|
3941
|
+
o.info("scheduler: sleep mode — registering wakeups, not arming timers", { count: w.length });
|
|
3942
|
+
for (let e of w) await C(e);
|
|
3943
|
+
} else if (re) {
|
|
3944
|
+
for (let e of w) await ne(e);
|
|
3945
|
+
for (let e of w) te(e);
|
|
3937
3946
|
}
|
|
3938
3947
|
return {
|
|
3939
3948
|
fireNow: async (e, t) => {
|
|
@@ -3954,11 +3963,11 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3954
3963
|
d.clear(), o.info("scheduler: stopped");
|
|
3955
3964
|
}
|
|
3956
3965
|
};
|
|
3957
|
-
}, Q = (e) => e?.message ?? String(e),
|
|
3966
|
+
}, Q = (e) => e?.message ?? String(e), Za = (e) => e && typeof e == "object" && "_tag" in e ? String(e._tag) : null, Qa = (e) => {
|
|
3958
3967
|
let t = {};
|
|
3959
3968
|
for (let [n, r] of Object.entries(e)) t[n] = r instanceof Date ? r.toISOString() : r;
|
|
3960
3969
|
return t;
|
|
3961
|
-
},
|
|
3970
|
+
}, $a = (e, t, n, r) => {
|
|
3962
3971
|
let i = !1, a, o = async () => {
|
|
3963
3972
|
if (i) return;
|
|
3964
3973
|
let a = new Date(Math.floor(Date.now() / t) * t), o = !1;
|
|
@@ -3988,96 +3997,96 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
3988
3997
|
i || (i = !0, a && clearInterval(a), a = void 0);
|
|
3989
3998
|
}
|
|
3990
3999
|
};
|
|
3991
|
-
},
|
|
4000
|
+
}, eo = (e) => (t, n, r) => $a(t, n, r, e), to = T("_voltro_schedule_runs", {
|
|
3992
4001
|
id: v({ prefix: "schrun" }),
|
|
3993
|
-
name:
|
|
3994
|
-
status:
|
|
4002
|
+
name: E(),
|
|
4003
|
+
status: E().oneOf([
|
|
3995
4004
|
"running",
|
|
3996
4005
|
"succeeded",
|
|
3997
4006
|
"failed",
|
|
3998
4007
|
"skipped",
|
|
3999
4008
|
"missed"
|
|
4000
4009
|
]).default("running"),
|
|
4001
|
-
trigger:
|
|
4010
|
+
trigger: E().oneOf([
|
|
4002
4011
|
"self",
|
|
4003
4012
|
"external",
|
|
4004
4013
|
"manual"
|
|
4005
4014
|
]).default("self"),
|
|
4006
|
-
scheduledAt:
|
|
4007
|
-
firedAt:
|
|
4008
|
-
completedAt:
|
|
4015
|
+
scheduledAt: D(),
|
|
4016
|
+
firedAt: D().nullable(),
|
|
4017
|
+
completedAt: D().nullable(),
|
|
4009
4018
|
durationMs: b().nullable(),
|
|
4010
|
-
errorTag:
|
|
4011
|
-
errorMessage:
|
|
4012
|
-
coordinationOutcome:
|
|
4019
|
+
errorTag: E().nullable(),
|
|
4020
|
+
errorMessage: E().nullable(),
|
|
4021
|
+
coordinationOutcome: E().oneOf([
|
|
4013
4022
|
"single",
|
|
4014
4023
|
"wonLock",
|
|
4015
4024
|
"lostLock",
|
|
4016
4025
|
"external",
|
|
4017
4026
|
"cluster"
|
|
4018
4027
|
]).nullable(),
|
|
4019
|
-
replicaId:
|
|
4020
|
-
result:
|
|
4021
|
-
}).index(["name", "scheduledAt"]).index(["status"]),
|
|
4028
|
+
replicaId: E().nullable(),
|
|
4029
|
+
result: C().nullable()
|
|
4030
|
+
}).index(["name", "scheduledAt"]).index(["status"]), no = T("_voltro_schedule_claims", {
|
|
4022
4031
|
id: v({ prefix: "schclaim" }),
|
|
4023
|
-
scheduleName:
|
|
4024
|
-
bucket:
|
|
4025
|
-
claimedBy:
|
|
4026
|
-
claimedAt:
|
|
4027
|
-
}).index(["scheduleName", "bucket"]).index(["claimedAt"]),
|
|
4032
|
+
scheduleName: E(),
|
|
4033
|
+
bucket: E(),
|
|
4034
|
+
claimedBy: E(),
|
|
4035
|
+
claimedAt: D()
|
|
4036
|
+
}).index(["scheduleName", "bucket"]).index(["claimedAt"]), ro = T("_voltro_traces", {
|
|
4028
4037
|
id: v({ prefix: "span" }),
|
|
4029
|
-
traceId:
|
|
4030
|
-
spanId:
|
|
4031
|
-
parentSpanId:
|
|
4032
|
-
name:
|
|
4033
|
-
kind:
|
|
4038
|
+
traceId: E(),
|
|
4039
|
+
spanId: E(),
|
|
4040
|
+
parentSpanId: E().nullable(),
|
|
4041
|
+
name: E(),
|
|
4042
|
+
kind: E().oneOf([
|
|
4034
4043
|
"internal",
|
|
4035
4044
|
"server",
|
|
4036
4045
|
"client",
|
|
4037
4046
|
"producer",
|
|
4038
4047
|
"consumer"
|
|
4039
4048
|
]).default("internal"),
|
|
4040
|
-
status:
|
|
4049
|
+
status: E().oneOf([
|
|
4041
4050
|
"ok",
|
|
4042
4051
|
"error",
|
|
4043
4052
|
"unset"
|
|
4044
4053
|
]).default("unset"),
|
|
4045
|
-
statusMessage:
|
|
4046
|
-
startedAt:
|
|
4047
|
-
endedAt:
|
|
4054
|
+
statusMessage: E().nullable(),
|
|
4055
|
+
startedAt: D(),
|
|
4056
|
+
endedAt: D(),
|
|
4048
4057
|
durationMs: b(),
|
|
4049
|
-
attributes:
|
|
4050
|
-
events:
|
|
4051
|
-
}).index(["traceId", "startedAt"]).index(["startedAt"]).index(["status"]),
|
|
4058
|
+
attributes: C().nullable(),
|
|
4059
|
+
events: C().nullable()
|
|
4060
|
+
}).index(["traceId", "startedAt"]).index(["startedAt"]).index(["status"]), io = T("_voltro_undo_log", {
|
|
4052
4061
|
id: v({ prefix: "undo" }),
|
|
4053
|
-
tag:
|
|
4054
|
-
label:
|
|
4055
|
-
subjectId:
|
|
4056
|
-
tenantId:
|
|
4057
|
-
traceId:
|
|
4058
|
-
changes:
|
|
4062
|
+
tag: E(),
|
|
4063
|
+
label: E().nullable(),
|
|
4064
|
+
subjectId: E().nullable(),
|
|
4065
|
+
tenantId: E().nullable(),
|
|
4066
|
+
traceId: E().nullable(),
|
|
4067
|
+
changes: E(),
|
|
4059
4068
|
crossesAction: r().default(!1),
|
|
4060
4069
|
undone: r().default(!1),
|
|
4061
|
-
createdAt:
|
|
4062
|
-
}).index(["subjectId", "createdAt"]).reactive(),
|
|
4070
|
+
createdAt: D().default("now")
|
|
4071
|
+
}).index(["subjectId", "createdAt"]).reactive(), ao = (e = process.env) => {
|
|
4063
4072
|
let t = (e.VOLTRO_UNDO ?? "").toLowerCase();
|
|
4064
4073
|
return t === "on" || t === "1" || t === "true" ? !0 : t === "off" || t === "0" || t === "false" ? !1 : e.NODE_ENV !== "production";
|
|
4065
|
-
},
|
|
4074
|
+
}, oo = (e) => e.startsWith("_voltro"), so = async (e, t, n) => (await e.query({
|
|
4066
4075
|
table: t,
|
|
4067
4076
|
predicate: u("id", n),
|
|
4068
4077
|
order: []
|
|
4069
|
-
}))[0] ?? null,
|
|
4078
|
+
}))[0] ?? null, co = (e, t) => new Proxy(e, { get(e, n, r) {
|
|
4070
4079
|
if (n === "insert") return async (n, r) => {
|
|
4071
4080
|
let i = await e.insert(n, r);
|
|
4072
|
-
return
|
|
4081
|
+
return oo(n) || t({
|
|
4073
4082
|
table: n,
|
|
4074
4083
|
op: "insert",
|
|
4075
4084
|
next: i
|
|
4076
4085
|
}), i;
|
|
4077
4086
|
};
|
|
4078
4087
|
if (n === "update") return async (n, r, i) => {
|
|
4079
|
-
let a =
|
|
4080
|
-
return
|
|
4088
|
+
let a = oo(n) ? null : await so(e, n, r), o = await e.update(n, r, i);
|
|
4089
|
+
return oo(n) || t({
|
|
4081
4090
|
table: n,
|
|
4082
4091
|
op: "update",
|
|
4083
4092
|
id: r,
|
|
@@ -4086,8 +4095,8 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4086
4095
|
}), o;
|
|
4087
4096
|
};
|
|
4088
4097
|
if (n === "delete") return async (n, r) => {
|
|
4089
|
-
let i =
|
|
4090
|
-
return !
|
|
4098
|
+
let i = oo(n) ? null : await so(e, n, r), a = await e.delete(n, r);
|
|
4099
|
+
return !oo(n) && a && t({
|
|
4091
4100
|
table: n,
|
|
4092
4101
|
op: "delete",
|
|
4093
4102
|
id: r,
|
|
@@ -4096,10 +4105,10 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4096
4105
|
};
|
|
4097
4106
|
let i = Reflect.get(e, n, r);
|
|
4098
4107
|
return typeof i == "function" ? i.bind(e) : i;
|
|
4099
|
-
} }),
|
|
4108
|
+
} }), lo = (e) => {
|
|
4100
4109
|
let t = [];
|
|
4101
4110
|
return {
|
|
4102
|
-
tx:
|
|
4111
|
+
tx: co(e, (e) => t.push(e)),
|
|
4103
4112
|
persist: async (e, n) => {
|
|
4104
4113
|
if (t.length === 0 || n.tag.startsWith("__voltro")) return;
|
|
4105
4114
|
let r = n.subject;
|
|
@@ -4115,14 +4124,14 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4115
4124
|
});
|
|
4116
4125
|
}
|
|
4117
4126
|
};
|
|
4118
|
-
},
|
|
4127
|
+
}, uo = (e) => {
|
|
4119
4128
|
if (e.id !== void 0) return e.id;
|
|
4120
4129
|
let t = e.next?.id;
|
|
4121
4130
|
if (typeof t == "string") return t;
|
|
4122
4131
|
let n = e.prev?.id;
|
|
4123
4132
|
return typeof n == "string" ? n : void 0;
|
|
4124
|
-
},
|
|
4125
|
-
let t =
|
|
4133
|
+
}, fo = (e) => {
|
|
4134
|
+
let t = uo(e);
|
|
4126
4135
|
switch (e.op) {
|
|
4127
4136
|
case "insert": return t === void 0 ? null : {
|
|
4128
4137
|
table: e.table,
|
|
@@ -4146,28 +4155,28 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4146
4155
|
row: e.prev
|
|
4147
4156
|
};
|
|
4148
4157
|
}
|
|
4149
|
-
},
|
|
4150
|
-
if (e.crossesAction) throw new
|
|
4158
|
+
}, po = (e) => {
|
|
4159
|
+
if (e.crossesAction) throw new mo(e.invocationId, "action");
|
|
4151
4160
|
let t = [];
|
|
4152
4161
|
for (let n = e.changes.length - 1; n >= 0; --n) {
|
|
4153
|
-
let r =
|
|
4162
|
+
let r = fo(e.changes[n]);
|
|
4154
4163
|
r !== null && t.push(r);
|
|
4155
4164
|
}
|
|
4156
4165
|
return t;
|
|
4157
|
-
},
|
|
4166
|
+
}, mo = class extends Error {
|
|
4158
4167
|
invocationId;
|
|
4159
4168
|
boundary;
|
|
4160
4169
|
_tag = "UndoBoundaryError";
|
|
4161
4170
|
constructor(e, t) {
|
|
4162
4171
|
super(t === "action" ? `cannot undo invocation ${e}: it crossed an action (external side effect)` : `cannot undo invocation ${e}: the row changed since (conflict)`), this.invocationId = e, this.boundary = t, this.name = "UndoBoundaryError";
|
|
4163
4172
|
}
|
|
4164
|
-
},
|
|
4173
|
+
}, ho = (e, t, n = ["updatedAt", "updatedBy"]) => {
|
|
4165
4174
|
if (t == null) return e == null;
|
|
4166
4175
|
if (e == null) return !1;
|
|
4167
4176
|
let r = new Set(n);
|
|
4168
4177
|
for (let [n, i] of Object.entries(t)) if (!r.has(n) && !Object.is(e[n], i) && JSON.stringify(e[n]) !== JSON.stringify(i)) return !1;
|
|
4169
4178
|
return !0;
|
|
4170
|
-
},
|
|
4179
|
+
}, go = class {
|
|
4171
4180
|
capacity;
|
|
4172
4181
|
done = [];
|
|
4173
4182
|
undone = [];
|
|
@@ -4203,7 +4212,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4203
4212
|
redo: [...this.undone]
|
|
4204
4213
|
};
|
|
4205
4214
|
}
|
|
4206
|
-
},
|
|
4215
|
+
}, _o = (e, t = /* @__PURE__ */ new Set()) => e.op === "insert" ? {
|
|
4207
4216
|
table: e.table,
|
|
4208
4217
|
op: "insert",
|
|
4209
4218
|
next: e.new ?? null
|
|
@@ -4220,7 +4229,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4220
4229
|
table: e.table,
|
|
4221
4230
|
op: "delete",
|
|
4222
4231
|
prev: e.old ?? null
|
|
4223
|
-
},
|
|
4232
|
+
}, vo = async (e, t) => {
|
|
4224
4233
|
switch (t.op) {
|
|
4225
4234
|
case "delete":
|
|
4226
4235
|
await e.delete(t.table, t.id);
|
|
@@ -4238,21 +4247,21 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4238
4247
|
await e.insert(t.table, t.row);
|
|
4239
4248
|
return;
|
|
4240
4249
|
}
|
|
4241
|
-
},
|
|
4242
|
-
for (let n of t) await
|
|
4243
|
-
},
|
|
4250
|
+
}, yo = async (e, t) => {
|
|
4251
|
+
for (let n of t) await vo(e, n);
|
|
4252
|
+
}, bo = (e) => e.request?.subject?.id ?? null, xo = (e) => e === !0 || e === 1, So = async (e, t, n) => (await e.query({
|
|
4244
4253
|
table: t,
|
|
4245
4254
|
predicate: u("id", n),
|
|
4246
4255
|
order: []
|
|
4247
|
-
}))[0] ?? null,
|
|
4256
|
+
}))[0] ?? null, Co = (e) => {
|
|
4248
4257
|
try {
|
|
4249
4258
|
let t = JSON.parse(String(e ?? "[]"));
|
|
4250
4259
|
return Array.isArray(t) ? t : [];
|
|
4251
4260
|
} catch {
|
|
4252
4261
|
return [];
|
|
4253
4262
|
}
|
|
4254
|
-
},
|
|
4255
|
-
let n =
|
|
4263
|
+
}, wo = (e) => e.id ?? e.next?.id ?? e.prev?.id, To = async (e, t) => {
|
|
4264
|
+
let n = bo(t);
|
|
4256
4265
|
return [...await t.store.query({
|
|
4257
4266
|
table: "_voltro_undo_log",
|
|
4258
4267
|
predicate: u("subjectId", n),
|
|
@@ -4261,68 +4270,68 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4261
4270
|
id: String(e.id),
|
|
4262
4271
|
tag: String(e.tag ?? ""),
|
|
4263
4272
|
label: e.label ?? null,
|
|
4264
|
-
undone:
|
|
4265
|
-
crossesAction:
|
|
4273
|
+
undone: xo(e.undone),
|
|
4274
|
+
crossesAction: xo(e.crossesAction),
|
|
4266
4275
|
createdAt: String(e.createdAt ?? "")
|
|
4267
4276
|
}));
|
|
4268
|
-
},
|
|
4269
|
-
let n = await
|
|
4270
|
-
if (!n) throw new
|
|
4271
|
-
if ((n.subjectId ?? null) !==
|
|
4277
|
+
}, Eo = async (e, t) => {
|
|
4278
|
+
let n = await So(t.store, "_voltro_undo_log", e.invocationId);
|
|
4279
|
+
if (!n) throw new Se({ invocationId: e.invocationId });
|
|
4280
|
+
if ((n.subjectId ?? null) !== bo(t)) throw new xe({ invocationId: e.invocationId });
|
|
4272
4281
|
return n;
|
|
4273
|
-
},
|
|
4274
|
-
let n = await
|
|
4275
|
-
if (
|
|
4276
|
-
if (
|
|
4282
|
+
}, Do = async (e, t) => {
|
|
4283
|
+
let n = await Eo(e, t);
|
|
4284
|
+
if (xo(n.undone)) return { ok: !0 };
|
|
4285
|
+
if (xo(n.crossesAction)) throw new be({
|
|
4277
4286
|
invocationId: e.invocationId,
|
|
4278
4287
|
reason: "action"
|
|
4279
4288
|
});
|
|
4280
|
-
let r =
|
|
4289
|
+
let r = Co(n.changes);
|
|
4281
4290
|
for (let n of r) {
|
|
4282
|
-
let r =
|
|
4283
|
-
if (r !== void 0 && !
|
|
4291
|
+
let r = wo(n);
|
|
4292
|
+
if (r !== void 0 && !ho(await So(t.store, n.table, r), n.next ?? null)) throw new be({
|
|
4284
4293
|
invocationId: e.invocationId,
|
|
4285
4294
|
reason: "conflict"
|
|
4286
4295
|
});
|
|
4287
4296
|
}
|
|
4288
4297
|
let i = {
|
|
4289
4298
|
invocationId: e.invocationId,
|
|
4290
|
-
subject:
|
|
4299
|
+
subject: bo(t),
|
|
4291
4300
|
changes: r,
|
|
4292
4301
|
crossesAction: !1
|
|
4293
4302
|
};
|
|
4294
|
-
return await
|
|
4295
|
-
},
|
|
4296
|
-
let n = await
|
|
4297
|
-
if (!
|
|
4298
|
-
for (let e of
|
|
4299
|
-
let n =
|
|
4303
|
+
return await yo(t.store, po(i)), await t.store.update("_voltro_undo_log", e.invocationId, { undone: !0 }), { ok: !0 };
|
|
4304
|
+
}, Oo = async (e, t) => {
|
|
4305
|
+
let n = await Eo(e, t);
|
|
4306
|
+
if (!xo(n.undone)) return { ok: !0 };
|
|
4307
|
+
for (let e of Co(n.changes)) {
|
|
4308
|
+
let n = wo(e);
|
|
4300
4309
|
e.op === "insert" && e.next ? await t.store.insert(e.table, e.next) : e.op === "update" && n !== void 0 && e.next ? await t.store.update(e.table, n, e.next) : e.op === "delete" && n !== void 0 && await t.store.delete(e.table, n);
|
|
4301
4310
|
}
|
|
4302
4311
|
return await t.store.update("_voltro_undo_log", e.invocationId, { undone: !1 }), { ok: !0 };
|
|
4303
|
-
},
|
|
4312
|
+
}, ko = (e = process.env) => {
|
|
4304
4313
|
let t = (e.VOLTRO_TIMELINE ?? "").toLowerCase();
|
|
4305
4314
|
return t === "off" || t === "0" || t === "false" ? "off" : t === "all" ? "all" : t === "interesting" || t === "on" || t === "1" || t === "true" ? "interesting" : e.NODE_ENV === "production" ? "off" : "interesting";
|
|
4306
|
-
},
|
|
4315
|
+
}, Ao = /pass(word)?|secret|token|api[_-]?key|authorization|cookie|ssn|credit[_-]?card|card[_-]?number|cvv|encrypted/i, jo = "«redacted»", Mo = (e) => {
|
|
4307
4316
|
if (e == null) return null;
|
|
4308
4317
|
let t = {};
|
|
4309
|
-
for (let [n, r] of Object.entries(e)) t[n] =
|
|
4318
|
+
for (let [n, r] of Object.entries(e)) t[n] = Ao.test(n) ? jo : r;
|
|
4310
4319
|
return t;
|
|
4311
|
-
},
|
|
4320
|
+
}, No = (e) => {
|
|
4312
4321
|
let t = e?.id;
|
|
4313
4322
|
return typeof t == "string" ? t : void 0;
|
|
4314
|
-
},
|
|
4323
|
+
}, Po = (e, t) => {
|
|
4315
4324
|
if (t.op === "insert") {
|
|
4316
|
-
let n =
|
|
4325
|
+
let n = No(t.new);
|
|
4317
4326
|
return n === void 0 ? e : e.filter((e) => e.id !== n);
|
|
4318
4327
|
}
|
|
4319
4328
|
if (t.op === "update") {
|
|
4320
4329
|
if (t.old == null) return e;
|
|
4321
|
-
let n =
|
|
4330
|
+
let n = No(t.new) ?? No(t.old);
|
|
4322
4331
|
return e.map((e) => e.id === n ? t.old : e);
|
|
4323
4332
|
}
|
|
4324
4333
|
return t.old == null ? e : [...e, t.old];
|
|
4325
|
-
},
|
|
4334
|
+
}, Fo = class {
|
|
4326
4335
|
mode;
|
|
4327
4336
|
capacity;
|
|
4328
4337
|
now;
|
|
@@ -4342,8 +4351,8 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4342
4351
|
ts: this.now(),
|
|
4343
4352
|
table: e.table,
|
|
4344
4353
|
op: e.op,
|
|
4345
|
-
old:
|
|
4346
|
-
new:
|
|
4354
|
+
old: Mo(e.old),
|
|
4355
|
+
new: Mo(e.new),
|
|
4347
4356
|
tenantId: n
|
|
4348
4357
|
}), this.ring.length > this.capacity && this.ring.shift(), t;
|
|
4349
4358
|
}
|
|
@@ -4356,23 +4365,23 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4356
4365
|
}
|
|
4357
4366
|
replay(e, t, n) {
|
|
4358
4367
|
let r = this.ring.filter((n) => n.table === e && n.seq > t).sort((e, t) => t.seq - e.seq), i = n;
|
|
4359
|
-
for (let e of r) i =
|
|
4368
|
+
for (let e of r) i = Po(i, e);
|
|
4360
4369
|
return i;
|
|
4361
4370
|
}
|
|
4362
|
-
},
|
|
4363
|
-
|
|
4364
|
-
},
|
|
4365
|
-
let t =
|
|
4371
|
+
}, Io, Lo = () => (Io === void 0 && (Io = new Fo(ko())), Io), Ro = (e) => {
|
|
4372
|
+
Io = e;
|
|
4373
|
+
}, zo = (e) => {
|
|
4374
|
+
let t = Lo();
|
|
4366
4375
|
if (t.enabled) try {
|
|
4367
4376
|
t.record(e);
|
|
4368
4377
|
} catch {}
|
|
4369
|
-
},
|
|
4378
|
+
}, Bo = /* @__PURE__ */ new Set([
|
|
4370
4379
|
"count",
|
|
4371
4380
|
"sum",
|
|
4372
4381
|
"avg",
|
|
4373
4382
|
"min",
|
|
4374
4383
|
"max"
|
|
4375
|
-
]),
|
|
4384
|
+
]), Vo = (e) => {
|
|
4376
4385
|
if (e.joins !== void 0 && e.joins.length > 0) return {
|
|
4377
4386
|
maintainable: !1,
|
|
4378
4387
|
reason: "joins are not maintainable in v1"
|
|
@@ -4394,7 +4403,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4394
4403
|
reason: "v1 maintains exactly one aggregation"
|
|
4395
4404
|
};
|
|
4396
4405
|
let t = e.aggregations[0];
|
|
4397
|
-
return
|
|
4406
|
+
return Bo.has(t.op) ? t.op !== "count" && (t.column === void 0 || t.column.length === 0) ? {
|
|
4398
4407
|
maintainable: !1,
|
|
4399
4408
|
reason: `op '${t.op}' requires a column`
|
|
4400
4409
|
} : {
|
|
@@ -4408,7 +4417,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4408
4417
|
maintainable: !1,
|
|
4409
4418
|
reason: `op '${t.op}' is not maintainable`
|
|
4410
4419
|
};
|
|
4411
|
-
},
|
|
4420
|
+
}, Ho = "\0", $ = (e, t) => t === void 0 || t.length === 0 ? "" : t.map((t) => JSON.stringify(e[t] ?? null)).join(Ho), Uo = (e, t) => t === void 0 ? 0 : Number(e[t] ?? 0), Wo = (e, t) => {
|
|
4412
4421
|
switch (e.op) {
|
|
4413
4422
|
case "count": return t.count;
|
|
4414
4423
|
case "sum": return t.sum ?? 0;
|
|
@@ -4416,10 +4425,10 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4416
4425
|
case "min":
|
|
4417
4426
|
case "max": return t.count > 0 ? t.extreme ?? null : null;
|
|
4418
4427
|
}
|
|
4419
|
-
},
|
|
4428
|
+
}, Go = (e, t) => {
|
|
4420
4429
|
let n = /* @__PURE__ */ new Map();
|
|
4421
4430
|
for (let r of t) {
|
|
4422
|
-
let t = $(r, e.groupBy), i = n.get(t), a =
|
|
4431
|
+
let t = $(r, e.groupBy), i = n.get(t), a = Uo(r, e.column);
|
|
4423
4432
|
if (i === void 0) n.set(t, {
|
|
4424
4433
|
count: 1,
|
|
4425
4434
|
...e.op === "sum" || e.op === "avg" ? { sum: a } : {},
|
|
@@ -4435,10 +4444,10 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4435
4444
|
}
|
|
4436
4445
|
}
|
|
4437
4446
|
return n;
|
|
4438
|
-
},
|
|
4447
|
+
}, Ko = (e, t) => [...t.entries()].map(([t, n]) => ({
|
|
4439
4448
|
groupKey: t,
|
|
4440
|
-
value:
|
|
4441
|
-
})),
|
|
4449
|
+
value: Wo(e, n)
|
|
4450
|
+
})), qo = (e, t, n) => {
|
|
4442
4451
|
let r = new Map(t), i = /* @__PURE__ */ new Set(), a = (t) => {
|
|
4443
4452
|
let n = $(t, e.groupBy), a = r.get(n);
|
|
4444
4453
|
if (a === void 0) return;
|
|
@@ -4447,7 +4456,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4447
4456
|
r.delete(n);
|
|
4448
4457
|
return;
|
|
4449
4458
|
}
|
|
4450
|
-
let s =
|
|
4459
|
+
let s = Uo(t, e.column);
|
|
4451
4460
|
e.op === "min" || e.op === "max" ? (a.extreme !== void 0 && s === a.extreme && i.add(n), r.set(n, {
|
|
4452
4461
|
count: o,
|
|
4453
4462
|
...a.extreme === void 0 ? {} : { extreme: a.extreme }
|
|
@@ -4456,7 +4465,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4456
4465
|
...e.op === "sum" || e.op === "avg" ? { sum: (a.sum ?? 0) - s } : {}
|
|
4457
4466
|
});
|
|
4458
4467
|
}, o = (t) => {
|
|
4459
|
-
let n = $(t, e.groupBy), i = r.get(n), a =
|
|
4468
|
+
let n = $(t, e.groupBy), i = r.get(n), a = Uo(t, e.column);
|
|
4460
4469
|
if (i === void 0) {
|
|
4461
4470
|
r.set(n, {
|
|
4462
4471
|
count: 1,
|
|
@@ -4476,15 +4485,15 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4476
4485
|
state: r,
|
|
4477
4486
|
rescanGroups: [...i]
|
|
4478
4487
|
};
|
|
4479
|
-
},
|
|
4488
|
+
}, Jo = (e, t, n, r) => {
|
|
4480
4489
|
if (n.length === 0) return t;
|
|
4481
|
-
let i = new Set(n), a =
|
|
4490
|
+
let i = new Set(n), a = Go(e, r.filter((t) => i.has($(t, e.groupBy)))), o = new Map(t);
|
|
4482
4491
|
for (let e of i) {
|
|
4483
4492
|
let t = a.get(e);
|
|
4484
4493
|
t === void 0 ? o.delete(e) : o.set(e, t);
|
|
4485
4494
|
}
|
|
4486
4495
|
return o;
|
|
4487
|
-
},
|
|
4496
|
+
}, Yo = class {
|
|
4488
4497
|
shape;
|
|
4489
4498
|
state = /* @__PURE__ */ new Map();
|
|
4490
4499
|
groups = /* @__PURE__ */ new Map();
|
|
@@ -4492,7 +4501,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4492
4501
|
this.shape = e;
|
|
4493
4502
|
}
|
|
4494
4503
|
seed(e) {
|
|
4495
|
-
this.state =
|
|
4504
|
+
this.state = Go(this.shape, e), this.groups.clear();
|
|
4496
4505
|
for (let t of e) {
|
|
4497
4506
|
let e = $(t, this.shape.groupBy);
|
|
4498
4507
|
this.groups.has(e) || this.groups.set(e, this.groupValues(t));
|
|
@@ -4504,14 +4513,14 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4504
4513
|
let e = $(t, this.shape.groupBy);
|
|
4505
4514
|
this.groups.has(e) || this.groups.set(e, this.groupValues(t));
|
|
4506
4515
|
}
|
|
4507
|
-
let n =
|
|
4516
|
+
let n = qo(this.shape, this.state, e);
|
|
4508
4517
|
this.state = n.state;
|
|
4509
4518
|
for (let e of this.groups.keys()) this.state.has(e) || this.groups.delete(e);
|
|
4510
4519
|
return n.rescanGroups;
|
|
4511
4520
|
}
|
|
4512
4521
|
resolveRescan(e, t) {
|
|
4513
4522
|
if (e.length === 0) return;
|
|
4514
|
-
this.state =
|
|
4523
|
+
this.state = Jo(this.shape, this.state, e, t);
|
|
4515
4524
|
let n = new Set(e);
|
|
4516
4525
|
for (let e of t) {
|
|
4517
4526
|
let t = $(e, this.shape.groupBy);
|
|
@@ -4520,7 +4529,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4520
4529
|
for (let e of n) this.state.has(e) || this.groups.delete(e);
|
|
4521
4530
|
}
|
|
4522
4531
|
materialize() {
|
|
4523
|
-
return
|
|
4532
|
+
return Ko(this.shape, this.state).map((e) => ({
|
|
4524
4533
|
groupKey: e.groupKey,
|
|
4525
4534
|
group: this.groups.get(e.groupKey) ?? {},
|
|
4526
4535
|
value: e.value
|
|
@@ -4533,16 +4542,16 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4533
4542
|
for (let r of t) n[r] = e[r];
|
|
4534
4543
|
return n;
|
|
4535
4544
|
}
|
|
4536
|
-
},
|
|
4545
|
+
}, Xo = "admin:full", Zo = class extends I.TaggedError()("AccessDenied", {
|
|
4537
4546
|
action: I.String,
|
|
4538
4547
|
resourceType: I.String,
|
|
4539
4548
|
resourceId: I.String
|
|
4540
|
-
}) {},
|
|
4549
|
+
}) {}, Qo = /* @__PURE__ */ new Map(), $o = (e) => {
|
|
4541
4550
|
if (typeof e.resourceType != "string" || e.resourceType.length === 0) throw Error("defineResourcePolicy: a non-empty `resourceType` is required");
|
|
4542
4551
|
if (e.actions === void 0 || Object.keys(e.actions).length === 0) throw Error(`resource policy '${e.resourceType}': at least one action is required`);
|
|
4543
|
-
if (
|
|
4544
|
-
return
|
|
4545
|
-
},
|
|
4552
|
+
if (Qo.has(e.resourceType)) throw Error(`resource policy '${e.resourceType}' is already registered — types must be unique`);
|
|
4553
|
+
return Qo.set(e.resourceType, e), e;
|
|
4554
|
+
}, es = (e) => Qo.get(e), ts = () => [...Qo.values()], ns = () => Qo.clear(), rs = () => ts().map((e) => {
|
|
4546
4555
|
let t = /* @__PURE__ */ new Set();
|
|
4547
4556
|
for (let n of Object.values(e.actions)) for (let e of n) t.add(e);
|
|
4548
4557
|
for (let [n, r] of Object.entries(e.implies ?? {})) {
|
|
@@ -4555,7 +4564,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4555
4564
|
relations: [...t],
|
|
4556
4565
|
implies: e.implies ?? {}
|
|
4557
4566
|
};
|
|
4558
|
-
}),
|
|
4567
|
+
}), is = (e, t) => {
|
|
4559
4568
|
let n = new Set(e);
|
|
4560
4569
|
if (t === void 0) return n;
|
|
4561
4570
|
let r = [...e];
|
|
@@ -4564,39 +4573,39 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4564
4573
|
for (let i of t[e] ?? []) n.has(i) || (n.add(i), r.push(i));
|
|
4565
4574
|
}
|
|
4566
4575
|
return n;
|
|
4567
|
-
},
|
|
4576
|
+
}, as = (e, t, n, r) => e.id === null ? /* @__PURE__ */ new Set() : is(n.filter((n) => n.subjectId === e.id && n.resourceType === t.type && n.resourceId === t.id).map((e) => e.relation), r.implies), os = (e, t, n, r) => {
|
|
4568
4577
|
if (e.scopes?.includes("admin:full")) return !0;
|
|
4569
4578
|
if (e.id === null || n.tenantId != null && e.tenantId !== n.tenantId) return !1;
|
|
4570
4579
|
let i = r.policy.actions[t];
|
|
4571
4580
|
if (i === void 0 || i.length === 0) return !1;
|
|
4572
|
-
let a =
|
|
4581
|
+
let a = as(e, n, r.tuples, r.policy);
|
|
4573
4582
|
return i.some((e) => a.has(e));
|
|
4574
|
-
},
|
|
4575
|
-
if (!
|
|
4583
|
+
}, ss = (e, t, n, r) => {
|
|
4584
|
+
if (!os(e, t, n, r)) throw new Zo({
|
|
4576
4585
|
action: t,
|
|
4577
4586
|
resourceType: n.type,
|
|
4578
4587
|
resourceId: n.id
|
|
4579
4588
|
});
|
|
4580
|
-
},
|
|
4589
|
+
}, cs = (e, t, n, r, i) => r.filter((r) => os(e, t, {
|
|
4581
4590
|
type: n,
|
|
4582
4591
|
id: r.id,
|
|
4583
4592
|
...r.tenantId === void 0 ? {} : { tenantId: r.tenantId }
|
|
4584
|
-
}, i)),
|
|
4593
|
+
}, i)), ls = (e, t) => {
|
|
4585
4594
|
let n = new Set(t.map((e) => e.id));
|
|
4586
4595
|
return e.filter((e) => !n.has(e.id)).map((e) => e.id);
|
|
4587
|
-
},
|
|
4596
|
+
}, us = T("_voltro_rebac_tuples", {
|
|
4588
4597
|
id: v({ prefix: "rbct" }),
|
|
4589
|
-
subjectId:
|
|
4590
|
-
relation:
|
|
4591
|
-
resourceType:
|
|
4592
|
-
resourceId:
|
|
4593
|
-
tenantId:
|
|
4594
|
-
createdAt:
|
|
4598
|
+
subjectId: E(),
|
|
4599
|
+
relation: E(),
|
|
4600
|
+
resourceType: E(),
|
|
4601
|
+
resourceId: E(),
|
|
4602
|
+
tenantId: E().nullable(),
|
|
4603
|
+
createdAt: D().default("now")
|
|
4595
4604
|
}).index([
|
|
4596
4605
|
"subjectId",
|
|
4597
4606
|
"resourceType",
|
|
4598
4607
|
"resourceId"
|
|
4599
|
-
]).reactive(),
|
|
4608
|
+
]).reactive(), ds = async (e, n, r, i) => n === null ? [] : (await e.query({
|
|
4600
4609
|
table: "_voltro_rebac_tuples",
|
|
4601
4610
|
predicate: t(u("subjectId", n), u("resourceType", r), u("resourceId", i)),
|
|
4602
4611
|
order: [],
|
|
@@ -4608,16 +4617,16 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4608
4617
|
relation: e.relation,
|
|
4609
4618
|
resourceType: e.resourceType,
|
|
4610
4619
|
resourceId: e.resourceId
|
|
4611
|
-
})),
|
|
4620
|
+
})), fs = (e) => ({
|
|
4612
4621
|
id: e.id,
|
|
4613
4622
|
tenantId: e.tenantId,
|
|
4614
4623
|
...e.scopes === void 0 ? {} : { scopes: e.scopes }
|
|
4615
|
-
}),
|
|
4616
|
-
let n = t.getPolicy ??
|
|
4624
|
+
}), ps = (e, t) => {
|
|
4625
|
+
let n = t.getPolicy ?? es;
|
|
4617
4626
|
return (r, i) => {
|
|
4618
4627
|
let a = e[i.tag];
|
|
4619
4628
|
if (a === void 0) return r;
|
|
4620
|
-
let o = n(a.resourceType), s = (e) => j.fail(new
|
|
4629
|
+
let o = n(a.resourceType), s = (e) => j.fail(new Zo({
|
|
4621
4630
|
action: a.action,
|
|
4622
4631
|
resourceType: a.resourceType,
|
|
4623
4632
|
resourceId: e
|
|
@@ -4625,17 +4634,17 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4625
4634
|
if (o === void 0) return s("");
|
|
4626
4635
|
let c = a.resourceId(i.input);
|
|
4627
4636
|
if (c === null || c === "") return s("");
|
|
4628
|
-
let l =
|
|
4637
|
+
let l = fs(i.subject), u = {
|
|
4629
4638
|
type: a.resourceType,
|
|
4630
4639
|
id: c,
|
|
4631
4640
|
tenantId: i.subject.tenantId
|
|
4632
4641
|
};
|
|
4633
|
-
return j.flatMap(j.promise(async () => t.loadTuples(l.id, a.resourceType, c)), (e) =>
|
|
4642
|
+
return j.flatMap(j.promise(async () => t.loadTuples(l.id, a.resourceType, c)), (e) => os(l, a.action, u, {
|
|
4634
4643
|
policy: o,
|
|
4635
4644
|
tuples: e
|
|
4636
4645
|
}) ? r : s(c));
|
|
4637
4646
|
};
|
|
4638
|
-
},
|
|
4647
|
+
}, ms = async (e, n, r) => n === null ? [] : (await e.query({
|
|
4639
4648
|
table: "_voltro_rebac_tuples",
|
|
4640
4649
|
predicate: t(u("subjectId", n), u("resourceType", r)),
|
|
4641
4650
|
order: [],
|
|
@@ -4647,18 +4656,18 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4647
4656
|
relation: e.relation,
|
|
4648
4657
|
resourceType: e.resourceType,
|
|
4649
4658
|
resourceId: e.resourceId
|
|
4650
|
-
})),
|
|
4651
|
-
let t = e.getPolicy ??
|
|
4659
|
+
})), hs = (e) => {
|
|
4660
|
+
let t = e.getPolicy ?? es;
|
|
4652
4661
|
return async (n, r, i, a) => {
|
|
4653
4662
|
let o = t(r);
|
|
4654
4663
|
if (o === void 0) return [];
|
|
4655
|
-
let s =
|
|
4656
|
-
return
|
|
4664
|
+
let s = fs(n);
|
|
4665
|
+
return cs(s, i, r, a, {
|
|
4657
4666
|
policy: o,
|
|
4658
4667
|
tuples: await e.loadSubjectTuples(s.id, r)
|
|
4659
4668
|
});
|
|
4660
4669
|
};
|
|
4661
|
-
},
|
|
4670
|
+
}, gs = (e) => {
|
|
4662
4671
|
if (typeof e.name != "string" || e.name.length === 0) throw Error("defineReaction: a non-empty `name` is required");
|
|
4663
4672
|
if (e.watch === void 0 || typeof e.watch.table != "string" || e.watch.table.length === 0) throw Error(`reaction '${e.name}': watch.table is required`);
|
|
4664
4673
|
if (e.act === void 0 || e.act.kind !== "agent" && e.act.kind !== "workflow") throw Error(`reaction '${e.name}': act must be { kind: 'agent' | 'workflow', … }`);
|
|
@@ -4666,14 +4675,14 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4666
4675
|
if (e.guards.rateLimit !== void 0 && (e.guards.rateLimit.limit <= 0 || e.guards.rateLimit.windowMs <= 0)) throw Error(`reaction '${e.name}': guards.rateLimit needs positive limit + windowMs`);
|
|
4667
4676
|
if (e.guards.costBudgetUsd !== void 0 && e.guards.costBudgetUsd < 0) throw Error(`reaction '${e.name}': guards.costBudgetUsd must be >= 0`);
|
|
4668
4677
|
return e;
|
|
4669
|
-
},
|
|
4678
|
+
}, _s = (e, t) => e === void 0 ? !0 : Array.isArray(e) ? e.includes(t) : e === t, vs = (e) => e.new?.tenantId ?? e.old?.tenantId ?? null, ys = class {
|
|
4670
4679
|
hits = /* @__PURE__ */ new Map();
|
|
4671
4680
|
allow(e, t, n, r) {
|
|
4672
4681
|
let i = r - n, a = (this.hits.get(e) ?? []).filter((e) => e > i);
|
|
4673
4682
|
return a.length >= t ? (this.hits.set(e, a), !1) : (a.push(r), this.hits.set(e, a), !0);
|
|
4674
4683
|
}
|
|
4675
|
-
},
|
|
4676
|
-
if (t.table !== e.watch.table || !
|
|
4684
|
+
}, bs = async (e, t, n) => {
|
|
4685
|
+
if (t.table !== e.watch.table || !_s(e.watch.on, t.op)) return "skipped-op";
|
|
4677
4686
|
if (e.when !== void 0 && !e.when(t)) return "skipped-when";
|
|
4678
4687
|
let r = `${e.name}:${e.guards.dedupeKey(t)}`;
|
|
4679
4688
|
if (await n.dedupe.has(r)) return "skipped-dedupe";
|
|
@@ -4682,26 +4691,26 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4682
4691
|
let t = n.now?.() ?? Date.now();
|
|
4683
4692
|
if (!n.rateLimiter.allow(e.name, i.limit, i.windowMs, t)) return "skipped-ratelimit";
|
|
4684
4693
|
}
|
|
4685
|
-
let a =
|
|
4694
|
+
let a = vs(t);
|
|
4686
4695
|
return e.guards.costBudgetUsd !== void 0 && n.checkBudget !== void 0 && !await n.checkBudget(a, e.guards.costBudgetUsd) ? "skipped-budget" : (await n.runAct(e.act, t, {
|
|
4687
4696
|
id: a,
|
|
4688
4697
|
via: "agent"
|
|
4689
4698
|
}), await n.dedupe.add(r), "acted");
|
|
4690
|
-
},
|
|
4699
|
+
}, xs = T("_voltro_wakeups", {
|
|
4691
4700
|
id: v({ prefix: "wakeup" }),
|
|
4692
|
-
tenantId:
|
|
4693
|
-
kind:
|
|
4694
|
-
refId:
|
|
4695
|
-
wakeAt:
|
|
4696
|
-
status:
|
|
4697
|
-
}).index(["status", "wakeAt"]).index(["tenantId"]),
|
|
4698
|
-
let t = e.now?.() ?? /* @__PURE__ */ new Date(), n = await
|
|
4701
|
+
tenantId: E(),
|
|
4702
|
+
kind: E(),
|
|
4703
|
+
refId: E(),
|
|
4704
|
+
wakeAt: D(),
|
|
4705
|
+
status: E()
|
|
4706
|
+
}).index(["status", "wakeAt"]).index(["tenantId"]), Ss = async (e) => {
|
|
4707
|
+
let t = e.now?.() ?? /* @__PURE__ */ new Date(), n = await Ha(e.store, t, e.batchLimit ?? 100);
|
|
4699
4708
|
if (n.length === 0) return 0;
|
|
4700
4709
|
let r = 0;
|
|
4701
|
-
for (let t of n) if (await
|
|
4710
|
+
for (let t of n) if (await Ra(e.store, t)) try {
|
|
4702
4711
|
await e.adapter.wake(t), r++;
|
|
4703
4712
|
} catch (n) {
|
|
4704
|
-
await
|
|
4713
|
+
await za(e.store, t), e.log?.warn("wake: adapter failed — released for retry", {
|
|
4705
4714
|
tenantId: t.tenantId,
|
|
4706
4715
|
kind: t.kind,
|
|
4707
4716
|
refId: t.refId,
|
|
@@ -4709,11 +4718,11 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4709
4718
|
});
|
|
4710
4719
|
}
|
|
4711
4720
|
return r > 0 && e.log?.info("wake: woke due deployments", { count: r }), r;
|
|
4712
|
-
},
|
|
4721
|
+
}, Cs = (e, t = 1e3) => {
|
|
4713
4722
|
let n = !1, r, i = async () => {
|
|
4714
4723
|
if (!n) {
|
|
4715
4724
|
try {
|
|
4716
|
-
await
|
|
4725
|
+
await Ss(e);
|
|
4717
4726
|
} catch (t) {
|
|
4718
4727
|
e.log?.warn("wake: tick failed", { reason: t instanceof Error ? t.message : String(t) });
|
|
4719
4728
|
}
|
|
@@ -4723,10 +4732,10 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4723
4732
|
return i(), { stop: () => {
|
|
4724
4733
|
n = !0, r !== void 0 && clearTimeout(r);
|
|
4725
4734
|
} };
|
|
4726
|
-
},
|
|
4735
|
+
}, ws = (e) => ({ wake: async () => {
|
|
4727
4736
|
await e.start();
|
|
4728
|
-
} }),
|
|
4729
|
-
let t = e.fetchImpl ?? fetch, n = e.now ?? Date.now, r = e.sleep ??
|
|
4737
|
+
} }), Ts = (e) => new Promise((t) => setTimeout(t, e)), Es = (e) => {
|
|
4738
|
+
let t = e.fetchImpl ?? fetch, n = e.now ?? Date.now, r = e.sleep ?? Ts, i = e.spawnImpl ?? _t, a = e.startTimeoutMs ?? 3e4, o = e.healthPollMs ?? 200, s = e.stopSignal ?? "SIGTERM", c = e.stopGraceMs ?? 1e4, l, u, d = e.healthCheck ?? ((e) => e.ok), f = async () => {
|
|
4730
4739
|
try {
|
|
4731
4740
|
let n = await t(e.healthUrl);
|
|
4732
4741
|
return d(n);
|
|
@@ -4780,11 +4789,11 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4780
4789
|
},
|
|
4781
4790
|
stop: m
|
|
4782
4791
|
};
|
|
4783
|
-
},
|
|
4792
|
+
}, Ds = async (e) => {
|
|
4784
4793
|
if (e.signals.connectedClients() > 0 || e.signals.inFlightRequests() > 0 || e.signals.activeWorkflowExecutions() > 0) return !1;
|
|
4785
|
-
let t = (e.now?.() ?? /* @__PURE__ */ new Date()).getTime() + (e.wakeLookaheadMs ?? 3e4), n = await
|
|
4794
|
+
let t = (e.now?.() ?? /* @__PURE__ */ new Date()).getTime() + (e.wakeLookaheadMs ?? 3e4), n = await Ua(e.store);
|
|
4786
4795
|
return !(n !== null && n.wakeAt.getTime() <= t);
|
|
4787
|
-
},
|
|
4796
|
+
}, Os = (e, t = Date.now) => {
|
|
4788
4797
|
let n;
|
|
4789
4798
|
return {
|
|
4790
4799
|
update: (r) => {
|
|
@@ -4796,7 +4805,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4796
4805
|
n = void 0;
|
|
4797
4806
|
}
|
|
4798
4807
|
};
|
|
4799
|
-
},
|
|
4808
|
+
}, ks = () => {
|
|
4800
4809
|
let e = 0, t = 0;
|
|
4801
4810
|
return {
|
|
4802
4811
|
onRequestStart: () => {
|
|
@@ -4814,8 +4823,8 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4814
4823
|
inFlightRequests: () => e,
|
|
4815
4824
|
openConnections: () => t
|
|
4816
4825
|
};
|
|
4817
|
-
},
|
|
4818
|
-
let o =
|
|
4826
|
+
}, As = (e) => ({ run: async (t) => (e.onActivity?.(), await e.ensureAwake(), t()) }), js = (e, t, n, r) => new Promise((i, a) => {
|
|
4827
|
+
let o = We.request({
|
|
4819
4828
|
host: n,
|
|
4820
4829
|
port: r,
|
|
4821
4830
|
method: e.method,
|
|
@@ -4825,8 +4834,8 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4825
4834
|
t.writeHead(e.statusCode ?? 502, e.headers), e.pipe(t), e.on("end", i), e.on("error", a);
|
|
4826
4835
|
});
|
|
4827
4836
|
o.on("error", a), e.pipe(o);
|
|
4828
|
-
}),
|
|
4829
|
-
let s =
|
|
4837
|
+
}), Ms = (e, t, n, r, i) => new Promise((a, o) => {
|
|
4838
|
+
let s = We.request({
|
|
4830
4839
|
host: r,
|
|
4831
4840
|
port: i,
|
|
4832
4841
|
method: e.method,
|
|
@@ -4840,21 +4849,21 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4840
4849
|
};
|
|
4841
4850
|
t.on("close", s), r.on("close", s), r.on("error", o);
|
|
4842
4851
|
}), s.on("error", o), s.end();
|
|
4843
|
-
}),
|
|
4844
|
-
let t =
|
|
4852
|
+
}), Ns = (e) => {
|
|
4853
|
+
let t = As({
|
|
4845
4854
|
ensureAwake: () => e.supervisor.start(),
|
|
4846
4855
|
...e.onActivity === void 0 ? {} : { onActivity: e.onActivity }
|
|
4847
|
-
}), n = e.activity, r =
|
|
4848
|
-
n?.onRequestStart(), i.on("close", () => n?.onRequestEnd()), t.run(() =>
|
|
4856
|
+
}), n = e.activity, r = We.createServer((r, i) => {
|
|
4857
|
+
n?.onRequestStart(), i.on("close", () => n?.onRequestEnd()), t.run(() => js(r, i, e.targetHost, e.targetPort)).catch((t) => {
|
|
4849
4858
|
e.log?.warn("wake-router: proxy failed", { reason: t instanceof Error ? t.message : String(t) }), i.headersSent || i.writeHead(502), i.end("wake/proxy failed");
|
|
4850
4859
|
});
|
|
4851
4860
|
});
|
|
4852
4861
|
return r.on("upgrade", (r, i, a) => {
|
|
4853
|
-
n?.onConnect(), i.on("close", () => n?.onDisconnect()), t.run(() =>
|
|
4862
|
+
n?.onConnect(), i.on("close", () => n?.onDisconnect()), t.run(() => Ms(r, i, a, e.targetHost, e.targetPort)).catch((t) => {
|
|
4854
4863
|
e.log?.warn("wake-router: upgrade proxy failed", { reason: t instanceof Error ? t.message : String(t) }), i.destroy();
|
|
4855
4864
|
});
|
|
4856
4865
|
}), r;
|
|
4857
|
-
},
|
|
4866
|
+
}, Ps = async (e) => {
|
|
4858
4867
|
try {
|
|
4859
4868
|
return (await e.query({
|
|
4860
4869
|
table: "_voltro_workflow_runs",
|
|
@@ -4871,15 +4880,15 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4871
4880
|
} catch {
|
|
4872
4881
|
return 0;
|
|
4873
4882
|
}
|
|
4874
|
-
},
|
|
4875
|
-
let t =
|
|
4883
|
+
}, Fs = async (e) => {
|
|
4884
|
+
let t = ws(e.supervisor), n = await Ss({
|
|
4876
4885
|
store: e.store,
|
|
4877
4886
|
adapter: t,
|
|
4878
4887
|
...e.now === void 0 ? {} : { now: e.now },
|
|
4879
4888
|
...e.log === void 0 ? {} : { log: e.log }
|
|
4880
4889
|
});
|
|
4881
4890
|
n > 0 && e.idleGate.reset();
|
|
4882
|
-
let r = await
|
|
4891
|
+
let r = await Ds({
|
|
4883
4892
|
store: e.store,
|
|
4884
4893
|
signals: e.signals,
|
|
4885
4894
|
...e.wakeLookaheadMs === void 0 ? {} : { wakeLookaheadMs: e.wakeLookaheadMs },
|
|
@@ -4889,12 +4898,12 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4889
4898
|
woke: n,
|
|
4890
4899
|
stopped: i
|
|
4891
4900
|
};
|
|
4892
|
-
},
|
|
4893
|
-
let t =
|
|
4901
|
+
}, Is = async (e) => {
|
|
4902
|
+
let t = Os(e.idleGraceMs ?? 6e4), n = e.tickMs ?? 1e3, r = ks(), i = 0, a = e.signals === void 0, o = e.signals ?? {
|
|
4894
4903
|
connectedClients: () => r.openConnections(),
|
|
4895
4904
|
inFlightRequests: () => r.inFlightRequests(),
|
|
4896
4905
|
activeWorkflowExecutions: () => i
|
|
4897
|
-
}, s =
|
|
4906
|
+
}, s = Ns({
|
|
4898
4907
|
supervisor: e.supervisor,
|
|
4899
4908
|
targetHost: e.targetHost,
|
|
4900
4909
|
targetPort: e.targetPort,
|
|
@@ -4913,7 +4922,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4913
4922
|
let l = !1, u, d = e.firedRetentionMs ?? 10 * 6e4, f = 0, p = async () => {
|
|
4914
4923
|
if (!l) {
|
|
4915
4924
|
try {
|
|
4916
|
-
if (a && (i = await
|
|
4925
|
+
if (a && (i = await Ps(e.store)), await Fs({
|
|
4917
4926
|
store: e.store,
|
|
4918
4927
|
supervisor: e.supervisor,
|
|
4919
4928
|
signals: o,
|
|
@@ -4921,7 +4930,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4921
4930
|
...e.wakeLookaheadMs === void 0 ? {} : { wakeLookaheadMs: e.wakeLookaheadMs },
|
|
4922
4931
|
...e.log === void 0 ? {} : { log: e.log }
|
|
4923
4932
|
}), f++ % 60 == 0) {
|
|
4924
|
-
let t = await
|
|
4933
|
+
let t = await Ga(e.store, { firedOlderThan: new Date(Date.now() - d) });
|
|
4925
4934
|
t > 0 && e.log?.info("orchestrator: pruned fired wakeups", { count: t });
|
|
4926
4935
|
}
|
|
4927
4936
|
} catch (t) {
|
|
@@ -4936,14 +4945,14 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4936
4945
|
l = !0, u !== void 0 && clearTimeout(u), await new Promise((e) => s.close(() => e()));
|
|
4937
4946
|
}
|
|
4938
4947
|
};
|
|
4939
|
-
},
|
|
4948
|
+
}, Ls = (e) => e, Rs = class extends I.TaggedError()("AnalyticsError", {
|
|
4940
4949
|
provider: I.String,
|
|
4941
4950
|
operation: I.String,
|
|
4942
4951
|
cause: I.String
|
|
4943
|
-
}) {},
|
|
4952
|
+
}) {}, zs = class extends I.TaggedError()("AnalyticsCapabilityNotSupported", {
|
|
4944
4953
|
provider: I.String,
|
|
4945
4954
|
capability: I.String
|
|
4946
|
-
}) {},
|
|
4955
|
+
}) {}, Bs = class extends Fe.Tag("@voltro/AnalyticsSink")() {}, Vs = (e, t) => ({
|
|
4947
4956
|
info: e.info,
|
|
4948
4957
|
track: (n) => e.track(n.tenantId === void 0 ? {
|
|
4949
4958
|
...n,
|
|
@@ -4962,20 +4971,20 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4962
4971
|
tenantId: t
|
|
4963
4972
|
} : n),
|
|
4964
4973
|
...e.mirror === void 0 ? {} : { mirror: e.mirror }
|
|
4965
|
-
}),
|
|
4966
|
-
let e = yield*
|
|
4974
|
+
}), Hs = () => j.gen(function* () {
|
|
4975
|
+
let e = yield* Bs, t = yield* j.serviceOption(O), n = P.match(t, {
|
|
4967
4976
|
onNone: () => null,
|
|
4968
4977
|
onSome: (e) => e.tenantId ?? null
|
|
4969
4978
|
});
|
|
4970
|
-
return n === null ? e :
|
|
4971
|
-
}),
|
|
4972
|
-
let e = (e) => j.fail(new
|
|
4973
|
-
provider:
|
|
4979
|
+
return n === null ? e : Vs(e, n);
|
|
4980
|
+
}), Us = "noop", Ws = () => {
|
|
4981
|
+
let e = (e) => j.fail(new zs({
|
|
4982
|
+
provider: Us,
|
|
4974
4983
|
capability: e
|
|
4975
4984
|
}));
|
|
4976
4985
|
return {
|
|
4977
4986
|
info: {
|
|
4978
|
-
provider:
|
|
4987
|
+
provider: Us,
|
|
4979
4988
|
capabilities: {
|
|
4980
4989
|
track: !0,
|
|
4981
4990
|
aggregate: !1,
|
|
@@ -4989,8 +4998,8 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
4989
4998
|
timeseries: () => e("timeseries"),
|
|
4990
4999
|
topN: () => e("topN")
|
|
4991
5000
|
};
|
|
4992
|
-
},
|
|
4993
|
-
if (e.length === 0) return
|
|
5001
|
+
}, Gs = (e) => {
|
|
5002
|
+
if (e.length === 0) return Ws();
|
|
4994
5003
|
if (e.length === 1) return e[0];
|
|
4995
5004
|
let t = {
|
|
4996
5005
|
provider: "compose",
|
|
@@ -5007,7 +5016,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
5007
5016
|
discard: !0
|
|
5008
5017
|
}), r = (t, n) => {
|
|
5009
5018
|
let r = e.find((e) => e.info.capabilities[t]);
|
|
5010
|
-
return r === void 0 ? j.fail(new
|
|
5019
|
+
return r === void 0 ? j.fail(new zs({
|
|
5011
5020
|
provider: "compose",
|
|
5012
5021
|
capability: t
|
|
5013
5022
|
})) : n(r);
|
|
@@ -5030,11 +5039,11 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
5030
5039
|
topN: (e) => r("topN", (t) => t.topN(e)),
|
|
5031
5040
|
...a === void 0 ? {} : { mirror: a }
|
|
5032
5041
|
};
|
|
5033
|
-
},
|
|
5042
|
+
}, Ks = (e) => {
|
|
5034
5043
|
let t = e.filter((e) => e.dispose !== void 0);
|
|
5035
5044
|
return {
|
|
5036
5045
|
kind: "compose",
|
|
5037
|
-
build: (t) =>
|
|
5046
|
+
build: (t) => Gs(e.map((e) => e.build(t))),
|
|
5038
5047
|
tables: e.flatMap((e) => e.tables ?? []),
|
|
5039
5048
|
initialize: (t) => j.forEach(e, (e) => e.initialize ? e.initialize(t) : j.void, {
|
|
5040
5049
|
concurrency: 1,
|
|
@@ -5045,15 +5054,15 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
5045
5054
|
discard: !0
|
|
5046
5055
|
}) } : {}
|
|
5047
5056
|
};
|
|
5048
|
-
},
|
|
5057
|
+
}, qs = {
|
|
5049
5058
|
kind: "noop",
|
|
5050
|
-
build: () =>
|
|
5051
|
-
},
|
|
5059
|
+
build: () => Ws()
|
|
5060
|
+
}, Js = {
|
|
5052
5061
|
tables: [],
|
|
5053
5062
|
detach: () => {}
|
|
5054
|
-
},
|
|
5063
|
+
}, Ys = (e) => {
|
|
5055
5064
|
let { store: t, sink: n, log: r } = e, i = n.mirror;
|
|
5056
|
-
if (i === void 0 || i.tables.length === 0) return
|
|
5065
|
+
if (i === void 0 || i.tables.length === 0) return Js;
|
|
5057
5066
|
let a = e.run ?? ((e) => j.runPromise(e)), o = i.primaryKey ?? "id", s = new Set(i.tables), c = (e) => {
|
|
5058
5067
|
if (e.op === "delete") {
|
|
5059
5068
|
let t = e.old;
|
|
@@ -5077,11 +5086,11 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
5077
5086
|
tables: i.tables,
|
|
5078
5087
|
detach: l
|
|
5079
5088
|
};
|
|
5080
|
-
},
|
|
5089
|
+
}, Xs = (e) => {
|
|
5081
5090
|
let t = typeof e.refresh == "string" ? { interval: e.refresh } : e.refresh, n = e.strategy ?? "replace";
|
|
5082
5091
|
if (n === "merge" && (e.mergeKey === void 0 || e.mergeKey.length === 0)) throw Error(`defineAggregate("${e.name}"): strategy: 'merge' requires mergeKey — the property on each row to upsert by`);
|
|
5083
5092
|
if (e.incremental !== void 0) {
|
|
5084
|
-
let t =
|
|
5093
|
+
let t = Vo({
|
|
5085
5094
|
aggregations: [{
|
|
5086
5095
|
op: e.incremental.op,
|
|
5087
5096
|
...e.incremental.column === void 0 ? {} : { column: e.incremental.column }
|
|
@@ -5103,38 +5112,38 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
5103
5112
|
build: e.build,
|
|
5104
5113
|
...e.incremental === void 0 ? {} : { incremental: e.incremental }
|
|
5105
5114
|
};
|
|
5106
|
-
},
|
|
5115
|
+
}, Zs = (e) => typeof e == "object" && !!e && e._voltroAggregate === !0, Qs = class extends I.TaggedError()("AggregateStale", {
|
|
5107
5116
|
name: I.String,
|
|
5108
5117
|
ageMs: I.Number,
|
|
5109
5118
|
maxAgeMs: I.Number
|
|
5110
|
-
}) {},
|
|
5119
|
+
}) {}, $s = class extends I.TaggedError()("AggregateNotFound", { name: I.String }) {}, ec = class extends I.TaggedError()("AggregateError", {
|
|
5111
5120
|
name: I.String,
|
|
5112
5121
|
operation: I.String,
|
|
5113
5122
|
cause: I.String
|
|
5114
|
-
}) {},
|
|
5115
|
-
return (yield*
|
|
5116
|
-
}),
|
|
5123
|
+
}) {}, tc = class extends Fe.Tag("@voltro/AggregateRegistry")() {}, nc = (e) => j.gen(function* () {
|
|
5124
|
+
return (yield* tc).getHandle(e);
|
|
5125
|
+
}), rc = (e, n, r) => {
|
|
5117
5126
|
if (e.crossTenant || !n.has(e.table) || r == null) return e;
|
|
5118
5127
|
let i = u("tenantId", r);
|
|
5119
5128
|
return {
|
|
5120
5129
|
...e,
|
|
5121
5130
|
predicate: e.predicate ? t(e.predicate, i) : i
|
|
5122
5131
|
};
|
|
5123
|
-
},
|
|
5132
|
+
}, ic = (e, n) => {
|
|
5124
5133
|
if (e.includeDeleted || !n.has(e.table)) return e;
|
|
5125
|
-
let r =
|
|
5134
|
+
let r = S("deletedAt");
|
|
5126
5135
|
return {
|
|
5127
5136
|
...e,
|
|
5128
5137
|
predicate: e.predicate ? t(e.predicate, r) : r
|
|
5129
5138
|
};
|
|
5130
|
-
},
|
|
5131
|
-
if (
|
|
5139
|
+
}, ac = (e) => j.runPromiseExit(e).then((e) => {
|
|
5140
|
+
if (ze.isSuccess(e)) return e.value;
|
|
5132
5141
|
let t = k.failureOption(e.cause);
|
|
5133
5142
|
throw P.isSome(t) ? t.value : k.squash(e.cause);
|
|
5134
|
-
}),
|
|
5135
|
-
let
|
|
5136
|
-
if (
|
|
5137
|
-
},
|
|
5143
|
+
}), oc = (e, t) => e.pipe(j.provideService(O, t)), sc = async (e, t, n) => {
|
|
5144
|
+
let r = await j.runPromise(we(t, e.guards, n));
|
|
5145
|
+
if (r) throw r;
|
|
5146
|
+
}, cc = async (e) => {
|
|
5138
5147
|
let t = `${e.kind}.${e.name}`, n = Date.now(), r = "ok";
|
|
5139
5148
|
try {
|
|
5140
5149
|
if (e.interceptor) {
|
|
@@ -5149,7 +5158,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
5149
5158
|
traceId: e.requestContext.traceId,
|
|
5150
5159
|
...e.requestContext.spanId === void 0 ? {} : { spanId: e.requestContext.spanId }
|
|
5151
5160
|
}), r = await j.runPromiseExit(n);
|
|
5152
|
-
if (
|
|
5161
|
+
if (ze.isSuccess(r)) return r.value;
|
|
5153
5162
|
throw k.squash(r.cause);
|
|
5154
5163
|
}
|
|
5155
5164
|
return await e.runExecutor();
|
|
@@ -5163,27 +5172,27 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
5163
5172
|
status: r
|
|
5164
5173
|
});
|
|
5165
5174
|
}
|
|
5166
|
-
},
|
|
5175
|
+
}, lc = /* @__PURE__ */ new Set([1213, 1205]), uc = /* @__PURE__ */ new Set([
|
|
5167
5176
|
"ER_LOCK_DEADLOCK",
|
|
5168
5177
|
"ER_LOCK_WAIT_TIMEOUT",
|
|
5169
5178
|
"40001",
|
|
5170
5179
|
"40P01"
|
|
5171
|
-
]),
|
|
5180
|
+
]), dc = (e) => {
|
|
5172
5181
|
let t = e;
|
|
5173
5182
|
for (let e = 0; e < 6 && typeof t == "object" && t; e++) {
|
|
5174
5183
|
let e = t;
|
|
5175
|
-
if (typeof e.errno == "number" &&
|
|
5184
|
+
if (typeof e.errno == "number" && lc.has(e.errno) || typeof e.code == "string" && uc.has(e.code) || typeof e.sqlState == "string" && uc.has(e.sqlState)) return !0;
|
|
5176
5185
|
t = e.cause;
|
|
5177
5186
|
}
|
|
5178
5187
|
return !1;
|
|
5179
|
-
},
|
|
5188
|
+
}, fc = 3, pc = (e) => new Promise((t) => setTimeout(t, e)), mc = async (e) => {
|
|
5180
5189
|
for (let t = 1;; t++) try {
|
|
5181
5190
|
return await e();
|
|
5182
5191
|
} catch (e) {
|
|
5183
|
-
if (t >=
|
|
5184
|
-
await
|
|
5192
|
+
if (t >= fc || !dc(e)) throw e;
|
|
5193
|
+
await pc(t * 20 + Math.floor(Math.random() * 30));
|
|
5185
5194
|
}
|
|
5186
|
-
},
|
|
5195
|
+
}, hc = (e) => (t, n, r) => cc({
|
|
5187
5196
|
name: t.descriptor.name,
|
|
5188
5197
|
kind: "mutation",
|
|
5189
5198
|
input: n,
|
|
@@ -5191,11 +5200,11 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
5191
5200
|
...e.interceptor ? { interceptor: e.interceptor } : {},
|
|
5192
5201
|
...e.recordMetric ? { recordMetric: e.recordMetric } : {},
|
|
5193
5202
|
runExecutor: async () => {
|
|
5194
|
-
|
|
5195
|
-
let i = [], a = await
|
|
5203
|
+
await sc(t.descriptor, r.subject, n);
|
|
5204
|
+
let i = [], a = await mc(async () => (i.length = 0, e.store.transactional(async (a) => {
|
|
5196
5205
|
let o = e.undoCapture?.(a), s = o ? o.tx : a, c = e.buildContext(r, s, { afterCommit: (e) => {
|
|
5197
5206
|
i.push(e);
|
|
5198
|
-
} }), l = t.executor(n, c), u = j.isEffect(l) ? await e.runEffect(
|
|
5207
|
+
} }), l = t.executor(n, c), u = j.isEffect(l) ? await e.runEffect(oc(l, r.subject), c.store) : await l;
|
|
5199
5208
|
return o && await o.persist(c.store, {
|
|
5200
5209
|
tag: t.descriptor.name,
|
|
5201
5210
|
subject: r.subject,
|
|
@@ -5205,34 +5214,39 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
5205
5214
|
for (let e of i) await e();
|
|
5206
5215
|
return a;
|
|
5207
5216
|
}
|
|
5208
|
-
}),
|
|
5217
|
+
}), gc = (e) => e && typeof e == "object" && "descriptor" in e ? e.descriptor : e, _c = (e) => typeof e == "object" && !!e && !Array.isArray(e) && "table" in e && "order" in e, vc = (e) => {
|
|
5209
5218
|
let t = e.descriptor.source;
|
|
5210
5219
|
return t == null ? [] : typeof t == "string" ? [t] : [...t];
|
|
5211
|
-
},
|
|
5220
|
+
}, yc = (e) => (t, n) => (r) => {
|
|
5212
5221
|
let i = e.buildContext(r), a = async () => {
|
|
5213
5222
|
let i = e.buildContext(r), a = t.executor(n, i);
|
|
5214
|
-
return j.isEffect(a) ? j.runPromise(e.provideEffect(
|
|
5223
|
+
return j.isEffect(a) ? j.runPromise(e.provideEffect(oc(a, r.subject), i.store)) : gc(await Promise.resolve(a));
|
|
5215
5224
|
}, o = (n) => {
|
|
5216
|
-
let i =
|
|
5217
|
-
return
|
|
5225
|
+
let i = gc(n);
|
|
5226
|
+
return _c(i) ? e.finalize(i, r) : {
|
|
5218
5227
|
__voltroComputed: !0,
|
|
5219
5228
|
value: i,
|
|
5220
|
-
dependentTables:
|
|
5229
|
+
dependentTables: vc(t),
|
|
5221
5230
|
tenantId: r.subject?.tenantId ?? null,
|
|
5222
5231
|
recompute: a
|
|
5223
5232
|
};
|
|
5224
5233
|
}, s = () => {
|
|
5225
|
-
let a =
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5234
|
+
let a = t.executor(n, i);
|
|
5235
|
+
return j.isEffect(a) ? e.provideEffect(oc(a, r.subject), i.store).pipe(j.map(o)) : a instanceof Promise ? j.promise(() => a).pipe(j.map(o)) : o(a);
|
|
5236
|
+
}, c = () => {
|
|
5237
|
+
let e = t.descriptor.guards;
|
|
5238
|
+
return !e || e.length === 0 ? s() : we(r.subject, e, n).pipe(j.flatMap((e) => {
|
|
5239
|
+
if (e) return j.fail(e);
|
|
5240
|
+
let t = s();
|
|
5241
|
+
return j.isEffect(t) ? t : j.succeed(t);
|
|
5242
|
+
}));
|
|
5229
5243
|
};
|
|
5230
|
-
if (!e.interceptor) return
|
|
5231
|
-
let
|
|
5232
|
-
let e =
|
|
5244
|
+
if (!e.interceptor) return c();
|
|
5245
|
+
let l = j.suspend(() => {
|
|
5246
|
+
let e = c();
|
|
5233
5247
|
return j.isEffect(e) ? e : j.succeed(e);
|
|
5234
5248
|
});
|
|
5235
|
-
return e.interceptor(
|
|
5249
|
+
return e.interceptor(l, {
|
|
5236
5250
|
tag: t.descriptor.name,
|
|
5237
5251
|
kind: "query",
|
|
5238
5252
|
input: n,
|
|
@@ -5240,7 +5254,7 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
5240
5254
|
traceId: r.traceId,
|
|
5241
5255
|
...r.spanId === void 0 ? {} : { spanId: r.spanId }
|
|
5242
5256
|
});
|
|
5243
|
-
},
|
|
5257
|
+
}, bc = (e) => (t, n, r) => cc({
|
|
5244
5258
|
name: t.descriptor.name,
|
|
5245
5259
|
kind: "action",
|
|
5246
5260
|
input: n,
|
|
@@ -5248,16 +5262,16 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
5248
5262
|
...e.interceptor ? { interceptor: e.interceptor } : {},
|
|
5249
5263
|
...e.recordMetric ? { recordMetric: e.recordMetric } : {},
|
|
5250
5264
|
runExecutor: async () => {
|
|
5251
|
-
|
|
5265
|
+
await sc(t.descriptor, r.subject, n);
|
|
5252
5266
|
let i = e.buildContext(r), a = t.executor(n, i);
|
|
5253
|
-
return j.isEffect(a) ? e.runEffect(
|
|
5267
|
+
return j.isEffect(a) ? e.runEffect(oc(a, r.subject), i.store) : a;
|
|
5254
5268
|
}
|
|
5255
|
-
}),
|
|
5269
|
+
}), xc = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" && e.length > 0 ? e : null, Sc = (e) => typeof e == "string" && e.length > 0 ? e : null, Cc = [
|
|
5256
5270
|
"updatedAt",
|
|
5257
5271
|
"createdAt",
|
|
5258
5272
|
"updatedBy",
|
|
5259
5273
|
"createdBy"
|
|
5260
|
-
],
|
|
5274
|
+
], wc = (e) => Cc.some((t) => t in e), Tc = (e, t, n) => {
|
|
5261
5275
|
let r = {
|
|
5262
5276
|
table: t.table,
|
|
5263
5277
|
id: t.id,
|
|
@@ -5272,14 +5286,14 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
5272
5286
|
found: !1
|
|
5273
5287
|
};
|
|
5274
5288
|
let i = t.column === void 0 ? void 0 : e[t.column];
|
|
5275
|
-
if (!
|
|
5289
|
+
if (!wc(e)) return {
|
|
5276
5290
|
...r,
|
|
5277
5291
|
value: i,
|
|
5278
5292
|
lastWrite: null,
|
|
5279
5293
|
attribution: "none",
|
|
5280
5294
|
found: !0
|
|
5281
5295
|
};
|
|
5282
|
-
let a =
|
|
5296
|
+
let a = Sc(e.updatedBy) ?? Sc(e.createdBy), o = xc(e.updatedAt) ?? xc(e.createdAt);
|
|
5283
5297
|
return {
|
|
5284
5298
|
...r,
|
|
5285
5299
|
value: i,
|
|
@@ -5291,12 +5305,12 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
5291
5305
|
attribution: "audit",
|
|
5292
5306
|
found: !0
|
|
5293
5307
|
};
|
|
5294
|
-
},
|
|
5308
|
+
}, Ec = (e, t) => {
|
|
5295
5309
|
let n = e.map((e) => {
|
|
5296
5310
|
let n = e.newValue ?? e.value, r = t.column !== void 0 && n && typeof n == "object" ? n[t.column] : e.newValue ?? e.value;
|
|
5297
5311
|
return {
|
|
5298
|
-
actor: { id:
|
|
5299
|
-
at:
|
|
5312
|
+
actor: { id: Sc(e.actor) ?? Sc(e.changedBy) },
|
|
5313
|
+
at: xc(e.at) ?? xc(e.changedAt),
|
|
5300
5314
|
...e.traceId === void 0 ? {} : { traceId: e.traceId },
|
|
5301
5315
|
value: r
|
|
5302
5316
|
};
|
|
@@ -5311,12 +5325,12 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
5311
5325
|
history: n,
|
|
5312
5326
|
found: n.length > 0
|
|
5313
5327
|
};
|
|
5314
|
-
},
|
|
5328
|
+
}, Dc = (e) => {
|
|
5315
5329
|
let t = e.new?.id;
|
|
5316
5330
|
if (typeof t == "string") return t;
|
|
5317
5331
|
let n = e.old?.id;
|
|
5318
5332
|
return typeof n == "string" ? n : void 0;
|
|
5319
|
-
},
|
|
5333
|
+
}, Oc = (e) => {
|
|
5320
5334
|
let t = {};
|
|
5321
5335
|
if (e.op === "insert") for (let [n, r] of Object.entries(e.new ?? {})) t[n] = {
|
|
5322
5336
|
from: void 0,
|
|
@@ -5336,11 +5350,11 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
5336
5350
|
return {
|
|
5337
5351
|
table: e.table,
|
|
5338
5352
|
op: e.op,
|
|
5339
|
-
id:
|
|
5353
|
+
id: Dc(e),
|
|
5340
5354
|
fields: t
|
|
5341
5355
|
};
|
|
5342
|
-
},
|
|
5343
|
-
let t = e.map(
|
|
5356
|
+
}, kc = (e) => {
|
|
5357
|
+
let t = e.map(Oc);
|
|
5344
5358
|
return {
|
|
5345
5359
|
rows: t,
|
|
5346
5360
|
summary: {
|
|
@@ -5349,21 +5363,21 @@ var q = /* @__PURE__ */ new Map(), jn = (e, t) => {
|
|
|
5349
5363
|
deletes: t.filter((e) => e.op === "delete").length
|
|
5350
5364
|
}
|
|
5351
5365
|
};
|
|
5352
|
-
},
|
|
5366
|
+
}, Ac = class extends Error {
|
|
5353
5367
|
constructor() {
|
|
5354
5368
|
super("voltro:preview-rollback"), this.name = "PreviewRollback";
|
|
5355
5369
|
}
|
|
5356
|
-
},
|
|
5370
|
+
}, jc = async (e, t) => {
|
|
5357
5371
|
let n, r = !1;
|
|
5358
5372
|
try {
|
|
5359
5373
|
await e.transactional(async (e) => {
|
|
5360
|
-
throw n = await t(e), r = !0, new
|
|
5374
|
+
throw n = await t(e), r = !0, new Ac();
|
|
5361
5375
|
});
|
|
5362
5376
|
} catch (e) {
|
|
5363
|
-
if (!(e instanceof
|
|
5377
|
+
if (!(e instanceof Ac)) throw e;
|
|
5364
5378
|
}
|
|
5365
5379
|
if (!r) throw Error("preview: handler did not complete");
|
|
5366
5380
|
return n;
|
|
5367
|
-
},
|
|
5381
|
+
}, Mc = "framework-runtime";
|
|
5368
5382
|
//#endregion
|
|
5369
|
-
export {
|
|
5383
|
+
export { ci as API_KEYS_TABLE, Zo as AccessDenied, ec as AggregateError, Yo as AggregateMaintainer, $s as AggregateNotFound, tc as AggregateRegistry, Qs as AggregateStale, zs as AnalyticsCapabilityNotSupported, Rs as AnalyticsError, Bs as AnalyticsSink, ma as CircuitBreaker, fa as CircuitOpen, _r as DEFAULT_MAX_RPC_BODY_BYTES, na as DeleteBuilder, bn as Dispatcher, ya as EffectStore, Lt as InMemoryDataStore, Tt as IndexedMatcher, vt as LinearScanMatcher, Ve as MetricBoundaries, Us as NOOP_ANALYTICS_PROVIDER, Yi as NoRowFound, Xi as OptimisticLockError, Xo as REBAC_ADMIN_SCOPE, Mc as RUNTIME_NAME, ys as ReactionRateLimiter, $n as ReplicatedDataStore, ea as SelectBuilder, aa as StoreOperationFailed, Ot as SubscriptionRegistry, oa as TableValidationFailed, ia as TenantScopeViolation, Fo as TimelineRecorder, mo as UndoBoundaryError, go as UndoStack, ta as UpdateBuilder, Hi as VOLTRO_AUDIT_MIXIN_ID, Ui as VOLTRO_SOFT_DELETE_MIXIN_ID, Wi as VOLTRO_TENANT_MIXIN_ID, Pn as _connectionStreamCount, Fn as _resetConnectionSubjectsForTest, us as _voltroRebacTuplesTable, no as _voltroScheduleClaimsTable, to as _voltroScheduleRunsTable, ro as _voltroTracesTable, io as _voltroUndoLogTable, xs as _voltroWakeupsTable, zi as _voltroWorkflowEventDeliveriesTable, Ri as _voltroWorkflowEventsTable, bi as apiKeyManagementRoutes, ca as applyDefined, qo as applyDelta, vo as applyInverse, yo as applyInverses, ic as applySoftDeleteScope, rc as applyTenantScope, Do as applyUndoInvocation, ss as assertCan, Ys as attachAnalyticsMirror, yr as awaitServerListening, Dn as bindConnectionSubject, gr as bindMutation, cr as bindStream, sr as bindSubscription, ar as bindSubscriptionUntyped, Go as buildIvmState, kc as buildPreview, ps as buildRebacInterceptor, hs as buildRebacReadFilter, qn as buildSubjectKey, wr as buildTracingLayer, zr as cachedBackend, os as can, Fa as cancelWakeup, Vo as classifyShape, ns as clearResourcePolicies, i as clearRetentions, _a as clearSystemStoreHandle, Aa as compileCron, Ks as composeAnalytics, Gs as composeAnalyticsSinks, In as connectionSubjectsSnapshot, Ps as countRunningWorkflows, mn as counter, Qn as currentRoutingContext, Un as currentTraceContext, _i as dataStoreApiKeyStore, ei as dataStoreIdempotencyStore, ai as dataStoreKvStore, Xr as decryptField, Xs as defineAggregate, Ni as defineEventTrigger, gs as defineReaction, $o as defineResourcePolicy, ka as defineSchedule, Ls as defineSubscriber, Hr as deriveKey, Oc as diffChange, Ha as dueWakeups, as as effectiveRelations, Ji as emptySchemaRegistry, Yr as encryptField, Nr as envSecretsBackend, Bn as externalSpanFromTraceparent, zt as extractDbCause, Dt as fingerprintFor, Rn as formatTraceparent, _o as forwardChangeFromCdc, vi as frameworkApiKeyStrategy, hn as gauge, ui as generateApiKeyToken, On as getConnectionSubject, qr as getFieldCipher, es as getResourcePolicy, Lo as getTimelineRecorder, $ as groupKeyOf, gn as histogramMetric, Ec as historyProvenance, Br as httpSecretsBackend, ht as inspectWorkflow, Nn as interruptConnectionStreams, fo as invertChange, Zs as isAggregateDefinition, Bt as isForeignKeyViolation, Ds as isIdleNow, pr as isInfraError, ho as isSafeToApply, Da as isScheduleDefinition, Pi as isWorkflowEventTriggerDefinition, Wo as ivmValue, Tc as lastWriteProvenance, ts as listResourcePolicies, ee as listRetentions, ds as loadResourceTuples, ms as loadSubjectTuples, Ca as localityAwareSelector, bc as makeActionRunner, Ja as makeAdvisoryLockCoordinator, Ur as makeAesCipher, pi as makeApiKeyService, Vt as makeAppAccess, oi as makeAsyncKv, Mr as makeBufferingSpanProcessor, eo as makeCoordinatedScheduler, Sa as makeEffectStoreLayer, Bi as makeEventsFacade, Wr as makeFieldCipher, ra as makeFluentStore, Os as makeIdleGate, ki as makeLazyWorkflowFacade, hc as makeMutationRunner, Di as makePostCommitWorkflowFacade, ws as makeProcessAdapter, yc as makeQueryDescriptorProducer, ks as makeRouterActivity, Gi as makeSchemaRegistry, lo as makeUndoCapture, As as makeWakeGate, Ns as makeWakeProxyServer, Ei as makeWorkflowFacade, Oi as makeWorkflowFacadeWithCallerContext, Ai as makeWorkflowHandlers, ji as makeWorkflowLayers, Si as makeWorkflowRunHandle, Ia as markWakeupFired, Ko as materializeIvm, mi as memoryApiKeyStore, Ta as memoryReplicationAdapter, Kn as memoryRywPositionStore, ja as nextFiring, Ua as nextWakeup, Es as nodeProcessSupervisor, Ws as noopAnalytics, qs as noopAnalyticsSpec, si as noopKv, An as onBindConnectionSubject, zn as parseTraceparent, Wn as powerOfTwoSelector, jc as previewInRollback, Ga as pruneWakeups, rs as rebacPolicyGraph, ln as recordSample, pn as recordSubscriptionActive, dn as recordSubscriptionDelivery, zo as recordTimelineEvent, Mo as redactRow, Jn as redisRywPositionStore, Oo as redoUndoInvocation, Mn as registerConnectionStream, ae as registerRetention, Pa as registerWakeup, za as releaseWakeup, Gn as replicaHealth, Ir as resetSecretsBackend, wa as resolveCurrentRegion, Ht as resolveDependentTables, Jo as resolveRescan, Lr as resolveSecret, Rr as resolveSecretSync, Vr as resolveSecretsBackend, ko as resolveTimelineMode, se as retentionTtlMsFromEnv, Po as reverseEventOverRows, ls as revokedIds, va as runAsSystem, Fs as runOrchestratorTick, ac as runProvidedEffect, bs as runReaction, Is as runSingleNodeOrchestrator, Cs as runWakeLoop, Zn as runWithRoutingContext, Hn as runWithTraceContext, $a as scheduleCoordinated, Kr as setFieldCipher, Fr as setSecretsBackend, ga as setSystemStoreHandle, Ro as setTimelineRecorderForTest, li as sha256Hex, Ka as singleCoordinator, vn as snapshotMetrics, yn as snapshotMetricsSync, vr as startRpcServer, Xa as startScheduler, le as sweepRetention, po as synthesizeInverse, Vi as tracingHttpClientLayer, Mi as triggerWorkflow, Ra as tryClaimWakeup, kn as unbindConnectionSubject, ao as undoCaptureEnabled, To as undoLogExecutor, nc as useAggregate, Hs as useAnalytics, cs as visibleRows, Ss as wakeDueOnce, xi as workflowToRpc, co as wrapCaptureStore, da as wrapStoreWithMixinBehaviour };
|