@voltro/runtime 0.22.1 → 0.23.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 +316 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +667 -664
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { ENCRYPTED_PREFIX as e, and as t, attachEagerLoads as n, attributionFields as r, boolean as i, clearRetentions as a, collectSubqueries as o, contains as s, decryptFieldsOnRead as c, deserializeArraysOnRead as l, encryptFieldsForWrite as u, eq as d, evaluatePredicate as f, generateId as p, getRelations as m, getTable as h, gt as g, gte as _, hasEagerLoads as v, id as y, inSet as
|
|
2
|
-
import { createCipheriv as
|
|
3
|
-
import { EventEmitter as
|
|
4
|
-
import { ADMIN_SCOPE as
|
|
5
|
-
import { createLogger as
|
|
6
|
-
import { Cause as
|
|
7
|
-
import * as
|
|
8
|
-
import { createServer as
|
|
9
|
-
import { HttpClient as
|
|
1
|
+
import { ENCRYPTED_PREFIX as e, and as t, attachEagerLoads as n, attributionFields as r, boolean as i, clearRetentions as a, collectSubqueries as o, contains as s, decryptFieldsOnRead as c, deserializeArraysOnRead as l, encryptFieldsForWrite as u, eq as d, evaluatePredicate as f, generateId as p, getRelations as m, getTable as h, gt as g, gte as _, hasEagerLoads as v, id as y, inSet as ee, integer as b, isEncrypted as x, isNull as S, isTableReactive as C, json as w, listRetentions as te, lt as T, lte as ne, missingConflictColumns as re, missingRequiredColumns as ie, neq as E, or as ae, queryFor as oe, raiseChangeListenerCeiling as se, registerRetention as ce, requireTable as le, retentionTtlMsFromEnv as ue, runWithWriteAttribution as de, serializeArraysForWrite as fe, serverOnlyColumns as pe, stampGeneratedId as me, startsWith as he, sweepRetention as ge, table as D, text as O, timestamp as k, walkLeaves as _e } from "@voltro/database";
|
|
2
|
+
import { createCipheriv as ve, createDecipheriv as ye, createHash as be, randomBytes as xe, randomUUID as Se, scryptSync as Ce } from "node:crypto";
|
|
3
|
+
import { EventEmitter as we } from "node:events";
|
|
4
|
+
import { ADMIN_SCOPE as Te, APIKEY_ISSUE_ORG_SCOPE as Ee, APIKEY_ISSUE_OTHER_SCOPE as De, APIKEY_ISSUE_SELF_SCOPE as Oe, ConnectionHandshakeFailed as A, ConnectionInfo as ke, ConnectionKindMismatch as Ae, ConnectionNotDeclared as je, ConnectionSubjectRequired as Me, ScopeError as Ne, SubjectService as Pe, UndoConflict as Fe, UndoForbidden as Ie, UndoNotFound as Le, WorkflowRunHandleSchema as Re, checkGuardsEffect as ze, diffRows as Be, effectiveScopes as Ve, hasEffectiveScope as He, isIdKeyed as Ue, publishServerError as We, requireScope as Ge, setPolicyGuardResolver as Ke, systemSubject as qe, tsMs as Je } from "@voltro/protocol";
|
|
5
|
+
import { createLogger as j } from "@voltro/logger";
|
|
6
|
+
import { Cause as M, Clock as Ye, Context as Xe, Cron as Ze, Deferred as Qe, Duration as $e, Effect as N, Either as et, Exit as tt, Fiber as nt, Layer as P, ManagedRuntime as rt, Metric as F, MetricBoundaries as it, MetricState as at, Option as ot, Ref as I, Schedule as st, Schema as L, Stream as R, Tracer as ct } from "effect";
|
|
7
|
+
import * as lt from "node:http";
|
|
8
|
+
import { createServer as ut } from "node:http";
|
|
9
|
+
import { HttpClient as z, HttpClientRequest as dt, HttpLayerRouter as B, HttpServer as ft, HttpServerRequest as pt, HttpServerResponse as V } from "@effect/platform";
|
|
10
10
|
import { NodeContext as mt, NodeHttpServer as ht } from "@effect/platform-node";
|
|
11
11
|
import { Rpc as gt, RpcSerialization as _t, RpcServer as vt } from "@effect/rpc";
|
|
12
12
|
import { defineRestRoute as yt, dispatchSharedPath as bt, requireAnyScope as xt, requireScope as St } from "@voltro/protocol/rest";
|
|
@@ -61,7 +61,7 @@ var Rt = class {
|
|
|
61
61
|
}
|
|
62
62
|
}, zt = (e) => {
|
|
63
63
|
let t = [];
|
|
64
|
-
for (let n of
|
|
64
|
+
for (let n of _e(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({
|
|
@@ -71,14 +71,14 @@ var Rt = class {
|
|
|
71
71
|
return t;
|
|
72
72
|
}, Bt = (e) => {
|
|
73
73
|
let t = [];
|
|
74
|
-
for (let n of
|
|
74
|
+
for (let n of _e(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
80
|
}, Vt = (e, t) => {
|
|
81
|
-
for (let n of
|
|
81
|
+
for (let n of _e(e)) if (n.conjunctive && n.path === void 0 && n.op === "eq" && n.column === t) return n.value;
|
|
82
82
|
return null;
|
|
83
83
|
}, Ht = (e, t) => {
|
|
84
84
|
let n = [];
|
|
@@ -312,7 +312,7 @@ var Rt = class {
|
|
|
312
312
|
predicate: t,
|
|
313
313
|
indexHint: n ?? null
|
|
314
314
|
});
|
|
315
|
-
return
|
|
315
|
+
return be("sha256").update(JSON.stringify(r)).digest("hex").slice(0, 16);
|
|
316
316
|
}, Jt = class {
|
|
317
317
|
matcher;
|
|
318
318
|
byFingerprint = /* @__PURE__ */ new Map();
|
|
@@ -523,7 +523,7 @@ var Rt = class {
|
|
|
523
523
|
#e;
|
|
524
524
|
#t;
|
|
525
525
|
#n(e) {
|
|
526
|
-
|
|
526
|
+
C(e.table) && this.#t.emit("change", {
|
|
527
527
|
...r(),
|
|
528
528
|
...e
|
|
529
529
|
});
|
|
@@ -535,7 +535,7 @@ var Rt = class {
|
|
|
535
535
|
return r.#e = t.tables, r.#t = t.emitter, r.#r = t.numericCounters, r;
|
|
536
536
|
}
|
|
537
537
|
constructor(e, t = null) {
|
|
538
|
-
if (this.#i = t, this.#e = /* @__PURE__ */ new Map(), this.#t = new
|
|
538
|
+
if (this.#i = t, this.#e = /* @__PURE__ */ new Map(), this.#t = new we(), se(this.#t), this.#r = /* @__PURE__ */ new Map(), e) for (let [n, r] of Object.entries(e)) {
|
|
539
539
|
let e = /* @__PURE__ */ new Map();
|
|
540
540
|
for (let t of r) {
|
|
541
541
|
let n = t.id;
|
|
@@ -565,10 +565,10 @@ var Rt = class {
|
|
|
565
565
|
}
|
|
566
566
|
async query(e) {
|
|
567
567
|
let t = Qt(e, this.#e.get(this.#o(e.table)) ?? /* @__PURE__ */ new Map(), this.#s());
|
|
568
|
-
return v(e) ? n(t, e.eager,
|
|
568
|
+
return v(e) ? n(t, e.eager, le(e.table), (e) => this.query(e)) : t;
|
|
569
569
|
}
|
|
570
570
|
async insert(e, t) {
|
|
571
|
-
t =
|
|
571
|
+
t = me(e, t);
|
|
572
572
|
let n = t;
|
|
573
573
|
if (n.id === void 0) {
|
|
574
574
|
let r = this.#l(e);
|
|
@@ -762,10 +762,10 @@ var Rt = class {
|
|
|
762
762
|
}
|
|
763
763
|
async query(e) {
|
|
764
764
|
let t = this.buildTablesView(e), r = Qt(e, this.materialise(e.table), t);
|
|
765
|
-
return v(e) ? n(r, e.eager,
|
|
765
|
+
return v(e) ? n(r, e.eager, le(e.table), (e) => this.query(e)) : r;
|
|
766
766
|
}
|
|
767
767
|
async insert(e, t) {
|
|
768
|
-
t =
|
|
768
|
+
t = me(e, t);
|
|
769
769
|
let n = t;
|
|
770
770
|
n.id === void 0 && (n = {
|
|
771
771
|
...t,
|
|
@@ -917,11 +917,11 @@ var Rt = class {
|
|
|
917
917
|
let t = e.dbCode;
|
|
918
918
|
return t === "23503" || e.dbErrno === 1452 || t === 547 || t === "SQLITE_CONSTRAINT_FOREIGNKEY";
|
|
919
919
|
}, cn = (e) => ({
|
|
920
|
-
has: (t) =>
|
|
921
|
-
hasAny: (t) => t.some((t) =>
|
|
922
|
-
require: (t) =>
|
|
920
|
+
has: (t) => He(e, t),
|
|
921
|
+
hasAny: (t) => t.some((t) => He(e, t)),
|
|
922
|
+
require: (t) => Ge(e, t),
|
|
923
923
|
get scopes() {
|
|
924
|
-
return
|
|
924
|
+
return Ve(e);
|
|
925
925
|
}
|
|
926
926
|
}), ln = (e) => {
|
|
927
927
|
let t = /* @__PURE__ */ new Set();
|
|
@@ -1014,26 +1014,26 @@ var Rt = class {
|
|
|
1014
1014
|
if (r.has("*")) return !0;
|
|
1015
1015
|
for (let e of r) if (n.has(e)) return !0;
|
|
1016
1016
|
return !1;
|
|
1017
|
-
}, bn =
|
|
1017
|
+
}, bn = it.exponential({
|
|
1018
1018
|
start: .001,
|
|
1019
1019
|
factor: 2,
|
|
1020
1020
|
count: 16
|
|
1021
|
-
}), xn =
|
|
1022
|
-
let t = e.durationMs / 1e3, n = e.kind === "rpc" ?
|
|
1023
|
-
|
|
1021
|
+
}), xn = F.counter("voltro_rpc_requests_total", { description: "Total RPC handler invocations." }), Sn = F.counter("voltro_rpc_errors_total", { description: "RPC handler invocations that errored." }), Cn = F.histogram("voltro_rpc_duration_seconds", bn, "RPC handler duration in seconds."), wn = F.counter("voltro_http_requests_total", { description: "Total HTTP route invocations." }), Tn = F.histogram("voltro_http_duration_seconds", bn, "HTTP route duration in seconds."), En = F.histogram("voltro_plugin_hook_duration_seconds", bn, "Plugin interceptor duration in seconds."), Dn = F.counter("voltro_plugin_hook_errors_total", { description: "Plugin interceptor invocations that errored." }), On = F.counter("voltro_subscription_deliveries_total", { description: "Total subscription deliveries (snapshot + delta)." }), kn = F.histogram("voltro_subscription_delivery_seconds", bn, "Subscription delivery produce→push latency in seconds."), An = F.gauge("voltro_subscriptions_active", { description: "Currently-open subscriptions." }), jn = (e) => {
|
|
1022
|
+
let t = e.durationMs / 1e3, n = e.kind === "rpc" ? N.zipRight(F.increment(xn).pipe(N.tagMetrics("tag", e.tag), N.tagMetrics("status", e.status)), N.zipRight(F.update(Cn, t).pipe(N.tagMetrics("tag", e.tag)), e.status === "error" ? F.increment(Sn).pipe(N.tagMetrics("tag", e.tag)) : N.void)) : e.kind === "request" ? N.zipRight(F.increment(wn).pipe(N.tagMetrics("route", e.tag), N.tagMetrics("status", e.status)), F.update(Tn, t).pipe(N.tagMetrics("route", e.tag))) : N.zipRight(F.update(En, t).pipe(N.tagMetrics("hook", e.tag)), e.status === "error" ? F.increment(Dn).pipe(N.tagMetrics("hook", e.tag)) : N.void);
|
|
1023
|
+
N.runSync(n);
|
|
1024
1024
|
}, Mn = (e) => e.startsWith("subscription.") ? e.slice(13) : e, Nn = (e) => {
|
|
1025
1025
|
let t = Mn(e.label);
|
|
1026
|
-
|
|
1027
|
-
}, Pn = /* @__PURE__ */ new Map(),
|
|
1026
|
+
N.runSync(N.zipRight(F.increment(On).pipe(N.tagMetrics("tag", t), N.tagMetrics("kind", e.kind)), F.update(kn, e.durationMs / 1e3).pipe(N.tagMetrics("tag", t), N.tagMetrics("kind", e.kind))));
|
|
1027
|
+
}, Pn = /* @__PURE__ */ new Map(), Fn = (e, t) => {
|
|
1028
1028
|
let n = Mn(e), r = Math.max(0, (Pn.get(n) ?? 0) + t);
|
|
1029
|
-
r === 0 ? Pn.delete(n) : Pn.set(n, r),
|
|
1030
|
-
},
|
|
1029
|
+
r === 0 ? Pn.delete(n) : Pn.set(n, r), N.runSync(F.set(An, r).pipe(N.tagMetrics("tag", n)));
|
|
1030
|
+
}, In = (e, t) => F.counter(e, t === void 0 ? {} : { description: t }), Ln = (e, t) => F.gauge(e, t === void 0 ? {} : { description: t }), Rn = (e, t = bn, n) => F.histogram(e, t, n), zn = (e) => {
|
|
1031
1031
|
let t = {};
|
|
1032
1032
|
for (let n of e) t[n.key] = n.value;
|
|
1033
1033
|
return t;
|
|
1034
|
-
},
|
|
1035
|
-
let t = e.metricKey.name, n =
|
|
1036
|
-
if (
|
|
1034
|
+
}, Bn = F.snapshot.pipe(N.map((e) => e.map((e) => {
|
|
1035
|
+
let t = e.metricKey.name, n = zn(e.metricKey.tags), r = ot.getOrUndefined(e.metricKey.description), i = r === void 0 ? {} : { description: r }, a = e.metricState;
|
|
1036
|
+
if (at.isHistogramState(a)) return {
|
|
1037
1037
|
name: t,
|
|
1038
1038
|
labels: n,
|
|
1039
1039
|
...i,
|
|
@@ -1045,14 +1045,14 @@ var Rt = class {
|
|
|
1045
1045
|
sum: a.sum,
|
|
1046
1046
|
count: a.count
|
|
1047
1047
|
};
|
|
1048
|
-
if (
|
|
1048
|
+
if (at.isGaugeState(a)) return {
|
|
1049
1049
|
name: t,
|
|
1050
1050
|
labels: n,
|
|
1051
1051
|
...i,
|
|
1052
1052
|
type: "gauge",
|
|
1053
1053
|
value: Number(a.value)
|
|
1054
1054
|
};
|
|
1055
|
-
if (
|
|
1055
|
+
if (at.isSummaryState(a)) return {
|
|
1056
1056
|
name: t,
|
|
1057
1057
|
labels: n,
|
|
1058
1058
|
...i,
|
|
@@ -1064,7 +1064,7 @@ var Rt = class {
|
|
|
1064
1064
|
value: t.value
|
|
1065
1065
|
}] : [])
|
|
1066
1066
|
};
|
|
1067
|
-
if (
|
|
1067
|
+
if (at.isFrequencyState(a)) {
|
|
1068
1068
|
let e = {};
|
|
1069
1069
|
for (let [t, n] of a.occurrences) e[t] = n;
|
|
1070
1070
|
return {
|
|
@@ -1082,25 +1082,25 @@ var Rt = class {
|
|
|
1082
1082
|
type: "counter",
|
|
1083
1083
|
value: Number(a.count)
|
|
1084
1084
|
};
|
|
1085
|
-
}))),
|
|
1086
|
-
|
|
1087
|
-
},
|
|
1088
|
-
if (e === void 0 || t.type === "system") return
|
|
1089
|
-
let r = e.retry ??
|
|
1090
|
-
return (r === !1 ? i :
|
|
1091
|
-
},
|
|
1085
|
+
}))), Vn = () => N.runSync(Bn), Hn = class extends L.TaggedError()("RowFilterUnavailable", { cause: L.String }) {}, Un = st.exponential("20 millis").pipe(st.intersect(st.recurs(2))), Wn, Gn = (e) => {
|
|
1086
|
+
Wn = e;
|
|
1087
|
+
}, Kn = () => Wn, qn = () => void 0, Jn = (e, t) => Yn(Wn, e, t), Yn = (e, t, n) => {
|
|
1088
|
+
if (e === void 0 || t.type === "system") return N.succeed(qn);
|
|
1089
|
+
let r = e.retry ?? Un, i = e.load(t);
|
|
1090
|
+
return (r === !1 ? i : N.retry(i, r)).pipe(N.map((t) => (n) => e.predicate(t, n)), N.catchAll((t) => N.suspend(() => (n?.(t), e.onLoadError === "deny" ? N.succeed(Xn) : N.fail(new Hn({ cause: String(t) }))))));
|
|
1091
|
+
}, Xn = () => ({
|
|
1092
1092
|
column: "id",
|
|
1093
1093
|
op: "isNull"
|
|
1094
|
-
}),
|
|
1094
|
+
}), Zn = (e, n, r) => {
|
|
1095
1095
|
let i = e(n);
|
|
1096
1096
|
return i === void 0 ? r : r ? t(r, i) : i;
|
|
1097
|
-
},
|
|
1098
|
-
let n =
|
|
1097
|
+
}, Qn = (e, t) => {
|
|
1098
|
+
let n = Zn(e, t.table, t.predicate);
|
|
1099
1099
|
return n === t.predicate ? t : {
|
|
1100
1100
|
...t,
|
|
1101
1101
|
predicate: n
|
|
1102
1102
|
};
|
|
1103
|
-
},
|
|
1103
|
+
}, W = j({ scope: "voltro:dispatcher" }), $n = (e) => Array.isArray(e) ? e.length : e == null ? 0 : 1, er = (e) => typeof e == "object" && !!e && e._tag === "ScopeError", tr = class {
|
|
1104
1104
|
deps;
|
|
1105
1105
|
subscriptionRegistry;
|
|
1106
1106
|
matcher;
|
|
@@ -1115,7 +1115,7 @@ var Rt = class {
|
|
|
1115
1115
|
});
|
|
1116
1116
|
}
|
|
1117
1117
|
async subscribe(e, t, n, r, i, a, o, s) {
|
|
1118
|
-
let c = `sub_${
|
|
1118
|
+
let c = `sub_${Se()}`, l = i ?? `subscription.${e.table}`, u = ln(e), d = _n(e);
|
|
1119
1119
|
e.predicate !== void 0 && this.subscriptionRegistry.subscribe(c, e.table, e.predicate, r);
|
|
1120
1120
|
for (let e of u) {
|
|
1121
1121
|
let t = this.dependentByTable.get(e);
|
|
@@ -1129,7 +1129,7 @@ var Rt = class {
|
|
|
1129
1129
|
}
|
|
1130
1130
|
}, h, g;
|
|
1131
1131
|
try {
|
|
1132
|
-
h = s === void 0 ? e :
|
|
1132
|
+
h = s === void 0 ? e : Qn(await s(), e), g = this.deps.cache !== void 0 && a !== void 0 ? await this.deps.cache.wrap(a, p, () => this.deps.store.query(h)) : await this.deps.store.query(h);
|
|
1133
1133
|
} catch (e) {
|
|
1134
1134
|
throw m(), e;
|
|
1135
1135
|
}
|
|
@@ -1146,7 +1146,7 @@ var Rt = class {
|
|
|
1146
1146
|
cacheBinding: a,
|
|
1147
1147
|
reauthorize: o,
|
|
1148
1148
|
refilter: s
|
|
1149
|
-
}),
|
|
1149
|
+
}), Fn(l, 1), t({
|
|
1150
1150
|
_tag: "snapshot",
|
|
1151
1151
|
revision: 0,
|
|
1152
1152
|
data: g
|
|
@@ -1162,16 +1162,16 @@ var Rt = class {
|
|
|
1162
1162
|
durationMs: _ - f,
|
|
1163
1163
|
rowCount: g.length
|
|
1164
1164
|
}), () => {
|
|
1165
|
-
this.subscriptions.delete(c),
|
|
1165
|
+
this.subscriptions.delete(c), Fn(l, -1), m();
|
|
1166
1166
|
};
|
|
1167
1167
|
}
|
|
1168
1168
|
revokeSubscription(e, t, n = "guards no longer satisfied") {
|
|
1169
|
-
this.subscriptions.delete(e.id),
|
|
1169
|
+
this.subscriptions.delete(e.id), Fn(e.label, -1), this.subscriptionRegistry.unsubscribe(e.id);
|
|
1170
1170
|
for (let t of e.dependentTables) {
|
|
1171
1171
|
let n = this.dependentByTable.get(t);
|
|
1172
1172
|
n !== void 0 && (n.delete(e.id), n.size === 0 && this.dependentByTable.delete(t));
|
|
1173
1173
|
}
|
|
1174
|
-
|
|
1174
|
+
W.warn(`subscription revoked mid-stream — ${n}`, {
|
|
1175
1175
|
id: e.id,
|
|
1176
1176
|
label: e.label,
|
|
1177
1177
|
traceId: e.context.traceId
|
|
@@ -1181,12 +1181,12 @@ var Rt = class {
|
|
|
1181
1181
|
});
|
|
1182
1182
|
}
|
|
1183
1183
|
revokeComputed(e, t) {
|
|
1184
|
-
this.computedSubs.delete(e.id),
|
|
1184
|
+
this.computedSubs.delete(e.id), Fn(e.label, -1);
|
|
1185
1185
|
for (let t of e.tables) {
|
|
1186
1186
|
let n = this.computedByTable.get(t);
|
|
1187
1187
|
n !== void 0 && (n.delete(e.id), n.size === 0 && this.computedByTable.delete(t));
|
|
1188
1188
|
}
|
|
1189
|
-
|
|
1189
|
+
W.warn("computed subscription revoked mid-stream — guards no longer satisfied", {
|
|
1190
1190
|
id: e.id,
|
|
1191
1191
|
label: e.label,
|
|
1192
1192
|
traceId: e.context.traceId
|
|
@@ -1196,7 +1196,7 @@ var Rt = class {
|
|
|
1196
1196
|
});
|
|
1197
1197
|
}
|
|
1198
1198
|
async subscribeComputed(e, t, n, r) {
|
|
1199
|
-
let i = `csub_${
|
|
1199
|
+
let i = `csub_${Se()}`, a = e.dependentTables, o = {
|
|
1200
1200
|
id: i,
|
|
1201
1201
|
recompute: e.recompute,
|
|
1202
1202
|
tenantId: e.tenantId,
|
|
@@ -1204,10 +1204,10 @@ var Rt = class {
|
|
|
1204
1204
|
context: n,
|
|
1205
1205
|
label: r ?? "subscription.computed",
|
|
1206
1206
|
tables: a,
|
|
1207
|
-
lastJson:
|
|
1207
|
+
lastJson: nr(e.value),
|
|
1208
1208
|
revision: 0
|
|
1209
1209
|
};
|
|
1210
|
-
this.computedSubs.set(i, o),
|
|
1210
|
+
this.computedSubs.set(i, o), Fn(o.label, 1);
|
|
1211
1211
|
for (let e of a) {
|
|
1212
1212
|
let t = this.computedByTable.get(e);
|
|
1213
1213
|
t === void 0 && (t = /* @__PURE__ */ new Set(), this.computedByTable.set(e, t)), t.add(i);
|
|
@@ -1225,9 +1225,9 @@ var Rt = class {
|
|
|
1225
1225
|
startMs: s,
|
|
1226
1226
|
endMs: Date.now(),
|
|
1227
1227
|
durationMs: Date.now() - s,
|
|
1228
|
-
rowCount:
|
|
1228
|
+
rowCount: $n(e.value)
|
|
1229
1229
|
}), () => {
|
|
1230
|
-
this.computedSubs.delete(i),
|
|
1230
|
+
this.computedSubs.delete(i), Fn(o.label, -1);
|
|
1231
1231
|
for (let e of a) {
|
|
1232
1232
|
let t = this.computedByTable.get(e);
|
|
1233
1233
|
t !== void 0 && (t.delete(i), t.size === 0 && this.computedByTable.delete(e));
|
|
@@ -1237,7 +1237,7 @@ var Rt = class {
|
|
|
1237
1237
|
async recomputeComputed(e) {
|
|
1238
1238
|
let t = Date.now();
|
|
1239
1239
|
try {
|
|
1240
|
-
let n = await e.recompute(), r =
|
|
1240
|
+
let n = await e.recompute(), r = nr(n);
|
|
1241
1241
|
if (r === e.lastJson) return;
|
|
1242
1242
|
e.lastJson = r, e.revision += 1;
|
|
1243
1243
|
let i = Date.now();
|
|
@@ -1253,14 +1253,14 @@ var Rt = class {
|
|
|
1253
1253
|
startMs: t,
|
|
1254
1254
|
endMs: i,
|
|
1255
1255
|
durationMs: i - t,
|
|
1256
|
-
rowCount:
|
|
1256
|
+
rowCount: $n(n)
|
|
1257
1257
|
});
|
|
1258
1258
|
} catch (t) {
|
|
1259
|
-
if (
|
|
1259
|
+
if (er(t)) {
|
|
1260
1260
|
this.revokeComputed(e, t);
|
|
1261
1261
|
return;
|
|
1262
1262
|
}
|
|
1263
|
-
|
|
1263
|
+
W.warn("computed recompute failed; subscriber left on last value", {
|
|
1264
1264
|
id: e.id,
|
|
1265
1265
|
label: e.label,
|
|
1266
1266
|
traceId: e.context.traceId
|
|
@@ -1295,7 +1295,7 @@ var Rt = class {
|
|
|
1295
1295
|
for (let e of n) r.add(e.subscriberId);
|
|
1296
1296
|
let i = this.dependentByTable.get(e.table);
|
|
1297
1297
|
if (i !== void 0) for (let e of i) r.add(e);
|
|
1298
|
-
if (
|
|
1298
|
+
if (W.trace("handleChange", {
|
|
1299
1299
|
table: e.table,
|
|
1300
1300
|
op: e.op,
|
|
1301
1301
|
matcher: n.length,
|
|
@@ -1306,7 +1306,7 @@ var Rt = class {
|
|
|
1306
1306
|
for (let t of r) {
|
|
1307
1307
|
let n = this.subscriptions.get(t);
|
|
1308
1308
|
if (!n) {
|
|
1309
|
-
|
|
1309
|
+
W.trace("missing subscription", { subscriberId: t });
|
|
1310
1310
|
continue;
|
|
1311
1311
|
}
|
|
1312
1312
|
if (!yn(e, n.relevantFields)) {
|
|
@@ -1332,21 +1332,21 @@ var Rt = class {
|
|
|
1332
1332
|
this.revokeSubscription(n, e, "row filter unavailable");
|
|
1333
1333
|
continue;
|
|
1334
1334
|
}
|
|
1335
|
-
i =
|
|
1335
|
+
i = Qn(e, n.baseDescriptor);
|
|
1336
1336
|
}
|
|
1337
1337
|
let o = await this.deps.store.query(i), s = n.lastDelivered;
|
|
1338
|
-
if (
|
|
1339
|
-
|
|
1338
|
+
if (rr(o, s)) {
|
|
1339
|
+
W.trace("suppressed no-op delta", {
|
|
1340
1340
|
subscriberId: t,
|
|
1341
1341
|
table: e.table
|
|
1342
1342
|
});
|
|
1343
1343
|
continue;
|
|
1344
1344
|
}
|
|
1345
|
-
n.lastDelivered = o, this.deps.cache !== void 0 && n.cacheBinding !== void 0 && this.deps.cache.put(n.cacheBinding, Array.from(n.dependentTables), o),
|
|
1345
|
+
n.lastDelivered = o, this.deps.cache !== void 0 && n.cacheBinding !== void 0 && this.deps.cache.put(n.cacheBinding, Array.from(n.dependentTables), o), Ue(s) && Ue(o) ? n.emit({
|
|
1346
1346
|
_tag: "delta",
|
|
1347
1347
|
revision: a,
|
|
1348
1348
|
emittedAt: a,
|
|
1349
|
-
patch:
|
|
1349
|
+
patch: Be(s, o)
|
|
1350
1350
|
}) : n.emit({
|
|
1351
1351
|
_tag: "snapshot",
|
|
1352
1352
|
revision: a,
|
|
@@ -1364,7 +1364,7 @@ var Rt = class {
|
|
|
1364
1364
|
rowCount: o.length
|
|
1365
1365
|
});
|
|
1366
1366
|
} catch (r) {
|
|
1367
|
-
|
|
1367
|
+
W.warn("reactive re-query failed; subscriber left on last snapshot", {
|
|
1368
1368
|
subscriberId: t,
|
|
1369
1369
|
label: n.label,
|
|
1370
1370
|
table: e.table,
|
|
@@ -1372,66 +1372,66 @@ var Rt = class {
|
|
|
1372
1372
|
}, r);
|
|
1373
1373
|
}
|
|
1374
1374
|
}
|
|
1375
|
-
o > 0 &&
|
|
1375
|
+
o > 0 && W.trace("handleChange/prefiltered", {
|
|
1376
1376
|
table: e.table,
|
|
1377
1377
|
op: e.op,
|
|
1378
1378
|
skipped: o
|
|
1379
1379
|
});
|
|
1380
1380
|
}
|
|
1381
|
-
},
|
|
1381
|
+
}, nr = (e) => {
|
|
1382
1382
|
try {
|
|
1383
1383
|
return JSON.stringify(e) ?? "null";
|
|
1384
1384
|
} catch {
|
|
1385
1385
|
return String(e);
|
|
1386
1386
|
}
|
|
1387
|
-
},
|
|
1387
|
+
}, rr = (e, t) => {
|
|
1388
1388
|
if (e === t) return !0;
|
|
1389
1389
|
if (e.length !== t.length) return !1;
|
|
1390
1390
|
for (let n = 0; n < e.length; n++) if (JSON.stringify(e[n]) !== JSON.stringify(t[n])) return !1;
|
|
1391
1391
|
return !0;
|
|
1392
|
-
},
|
|
1393
|
-
|
|
1392
|
+
}, ir = (e) => typeof e == "object" && !!e && e.__voltroComputed === !0, ar = 1440 * 60 * 1e3, or = 3600 * 1e3, sr = /* @__PURE__ */ new Map(), cr = /* @__PURE__ */ new Set(), lr = (e, t) => {
|
|
1393
|
+
sr.set(e, {
|
|
1394
1394
|
subject: t,
|
|
1395
1395
|
touchedAt: Date.now()
|
|
1396
1396
|
});
|
|
1397
|
-
for (let n of
|
|
1397
|
+
for (let n of cr) try {
|
|
1398
1398
|
n(e, t);
|
|
1399
1399
|
} catch {}
|
|
1400
|
-
}, lr = (e) => {
|
|
1401
|
-
let t = or.get(e);
|
|
1402
|
-
if (t) return t.touchedAt = Date.now(), t.subject;
|
|
1403
1400
|
}, ur = (e) => {
|
|
1404
|
-
|
|
1405
|
-
|
|
1401
|
+
let t = sr.get(e);
|
|
1402
|
+
if (t) return t.touchedAt = Date.now(), t.subject;
|
|
1403
|
+
}, dr = (e) => {
|
|
1406
1404
|
sr.delete(e);
|
|
1407
|
-
}
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1405
|
+
}, fr = (e) => (cr.add(e), () => {
|
|
1406
|
+
cr.delete(e);
|
|
1407
|
+
}), pr = setInterval(() => {
|
|
1408
|
+
let e = Date.now() - ar;
|
|
1409
|
+
for (let [t, n] of sr) n.touchedAt < e && sr.delete(t);
|
|
1410
|
+
}, or);
|
|
1411
|
+
typeof pr == "object" && pr && "unref" in pr && pr.unref();
|
|
1412
|
+
var G = /* @__PURE__ */ new Map(), mr = (e, t) => {
|
|
1413
|
+
let n = G.get(e);
|
|
1414
|
+
return n || (n = /* @__PURE__ */ new Set(), G.set(e, n)), n.add(t), () => {
|
|
1415
|
+
let n = G.get(e);
|
|
1416
|
+
n && (n.delete(t), n.size === 0 && G.delete(e));
|
|
1417
1417
|
};
|
|
1418
|
-
},
|
|
1419
|
-
let t =
|
|
1418
|
+
}, hr = (e) => {
|
|
1419
|
+
let t = G.get(e);
|
|
1420
1420
|
if (t) {
|
|
1421
1421
|
for (let e of [...t]) try {
|
|
1422
1422
|
e();
|
|
1423
1423
|
} catch {}
|
|
1424
|
-
|
|
1424
|
+
G.delete(e);
|
|
1425
1425
|
}
|
|
1426
|
-
},
|
|
1427
|
-
|
|
1428
|
-
},
|
|
1426
|
+
}, gr = (e) => G.get(e)?.size ?? 0, _r = () => {
|
|
1427
|
+
sr.clear(), G.clear();
|
|
1428
|
+
}, vr = () => [...sr.entries()].map(([e, t]) => ({
|
|
1429
1429
|
clientId: e,
|
|
1430
1430
|
subjectType: t.subject.type,
|
|
1431
1431
|
tenantId: t.subject.tenantId
|
|
1432
|
-
})),
|
|
1432
|
+
})), yr = /^00-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/, br = (e) => `00-${e.traceId}-${e.spanId}-${e.sampled ? "01" : "00"}`, xr = (e) => {
|
|
1433
1433
|
if (typeof e != "string") return null;
|
|
1434
|
-
let t =
|
|
1434
|
+
let t = yr.exec(e.trim().toLowerCase());
|
|
1435
1435
|
if (t === null) return null;
|
|
1436
1436
|
let [, n, r, i] = t;
|
|
1437
1437
|
return n === "0".repeat(32) || r === "0".repeat(16) ? null : {
|
|
@@ -1439,37 +1439,37 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
1439
1439
|
spanId: r,
|
|
1440
1440
|
sampled: (parseInt(i, 16) & 1) == 1
|
|
1441
1441
|
};
|
|
1442
|
-
},
|
|
1443
|
-
let t =
|
|
1444
|
-
if (t !== null) return
|
|
1442
|
+
}, Sr = (e) => {
|
|
1443
|
+
let t = xr(e);
|
|
1444
|
+
if (t !== null) return ct.externalSpan({
|
|
1445
1445
|
traceId: t.traceId,
|
|
1446
1446
|
spanId: t.spanId,
|
|
1447
1447
|
sampled: t.sampled
|
|
1448
1448
|
});
|
|
1449
|
-
},
|
|
1449
|
+
}, Cr = new Ct(), wr = (e, t) => Cr.run(e, t), Tr = () => Cr.getStore(), Er = (e) => /^[0-9a-f]{64}$/i.test(e) ? Buffer.from(e, "hex") : Ce(e, "voltro:field-encryption:v1", 32), Dr = (t) => {
|
|
1450
1450
|
if (t.length !== 32) throw Error(`field cipher key must be 32 bytes, got ${t.length}`);
|
|
1451
1451
|
return {
|
|
1452
1452
|
encrypt: (n) => {
|
|
1453
|
-
let r =
|
|
1453
|
+
let r = xe(12), i = ve("aes-256-gcm", t, r), a = Buffer.concat([i.update(n, "utf8"), i.final()]), o = i.getAuthTag();
|
|
1454
1454
|
return `${e}${r.toString("base64")}:${o.toString("base64")}:${a.toString("base64")}`;
|
|
1455
1455
|
},
|
|
1456
1456
|
decrypt: (n) => {
|
|
1457
1457
|
let [r, i, a] = n.slice(e.length).split(":");
|
|
1458
1458
|
if (!r || !i || a === void 0) throw Error("field cipher: malformed ciphertext");
|
|
1459
|
-
let o =
|
|
1459
|
+
let o = ye("aes-256-gcm", t, Buffer.from(r, "base64"));
|
|
1460
1460
|
return o.setAuthTag(Buffer.from(i, "base64")), Buffer.concat([o.update(Buffer.from(a, "base64")), o.final()]).toString("utf8");
|
|
1461
1461
|
}
|
|
1462
1462
|
};
|
|
1463
|
-
},
|
|
1464
|
-
|
|
1465
|
-
},
|
|
1466
|
-
let t =
|
|
1467
|
-
if (!t) throw Error(`encryptField: ${
|
|
1463
|
+
}, Or = (e) => Dr(Er(e)), kr, Ar = (e) => {
|
|
1464
|
+
kr = e;
|
|
1465
|
+
}, K = () => kr, jr = "no field cipher registered — enable `@voltro/plugin-governance` `governancePlugin({ fieldEncryption: { key } })` (or call setFieldCipher) so a key is available.", q = (e) => {
|
|
1466
|
+
let t = K();
|
|
1467
|
+
if (!t) throw Error(`encryptField: ${jr}`);
|
|
1468
1468
|
return t.encrypt(e);
|
|
1469
1469
|
}, Mr = (e) => {
|
|
1470
|
-
if (!
|
|
1471
|
-
let t =
|
|
1472
|
-
if (!t) throw Error(`decryptField: ${
|
|
1470
|
+
if (!x(e)) return e;
|
|
1471
|
+
let t = K();
|
|
1472
|
+
if (!t) throw Error(`decryptField: ${jr}`);
|
|
1473
1473
|
return t.decrypt(e);
|
|
1474
1474
|
}, Nr = new Ct(), Pr = /* @__PURE__ */ new Set(), Fr = /* @__PURE__ */ new Set(), Ir = "\0", Lr = process.env.VOLTRO_OBSERVE_GRAPH === "1", Rr = () => {
|
|
1475
1475
|
Lr = !0;
|
|
@@ -1514,16 +1514,16 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
1514
1514
|
t.transactional = (t) => n.call(e, (e) => t(Wr(e)));
|
|
1515
1515
|
}
|
|
1516
1516
|
return t;
|
|
1517
|
-
}, Gr = class extends
|
|
1518
|
-
table:
|
|
1519
|
-
found:
|
|
1517
|
+
}, Gr = class extends L.TaggedError()("NoRowFound", {
|
|
1518
|
+
table: L.String,
|
|
1519
|
+
found: L.Number
|
|
1520
1520
|
}) {
|
|
1521
1521
|
get message() {
|
|
1522
1522
|
return this.found === 0 ? `expected exactly one row in '${this.table}', found none` : `expected exactly one row in '${this.table}', found more than one`;
|
|
1523
1523
|
}
|
|
1524
|
-
}, Kr = class extends
|
|
1525
|
-
table:
|
|
1526
|
-
expected:
|
|
1524
|
+
}, Kr = class extends L.TaggedError()("OptimisticLockError", {
|
|
1525
|
+
table: L.String,
|
|
1526
|
+
expected: L.Number
|
|
1527
1527
|
}) {
|
|
1528
1528
|
get message() {
|
|
1529
1529
|
return `optimistic lock failed on '${this.table}': expected version ${this.expected}`;
|
|
@@ -1536,21 +1536,21 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
1536
1536
|
switch (n) {
|
|
1537
1537
|
case "=": return d(t, r);
|
|
1538
1538
|
case "!=":
|
|
1539
|
-
case "<>": return
|
|
1539
|
+
case "<>": return E(t, r);
|
|
1540
1540
|
case ">": return g(t, r);
|
|
1541
1541
|
case ">=": return _(t, r);
|
|
1542
|
-
case "<": return
|
|
1543
|
-
case "<=": return
|
|
1544
|
-
case "in": return
|
|
1542
|
+
case "<": return T(t, r);
|
|
1543
|
+
case "<=": return ne(t, r);
|
|
1544
|
+
case "in": return ee(t, r);
|
|
1545
1545
|
case "contains":
|
|
1546
1546
|
case "fts": return s(t, r);
|
|
1547
|
-
case "startsWith": return
|
|
1547
|
+
case "startsWith": return he(t, r);
|
|
1548
1548
|
default: return d(t, r);
|
|
1549
1549
|
}
|
|
1550
1550
|
}, Yr = (e) => {
|
|
1551
1551
|
let t = h(e);
|
|
1552
1552
|
if (t === void 0) throw Error(`unknown table '${e}' — is it declared with table()?`);
|
|
1553
|
-
return
|
|
1553
|
+
return oe(t);
|
|
1554
1554
|
}, Xr = class e {
|
|
1555
1555
|
backend;
|
|
1556
1556
|
scope;
|
|
@@ -1599,8 +1599,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
1599
1599
|
}
|
|
1600
1600
|
scopedQuery() {
|
|
1601
1601
|
let e = this.query, { subject: t, schemaRegistry: n } = this.scope;
|
|
1602
|
-
!this.skipTenant && n.hasTenant(this.table) && t.tenantId != null && (e = e.where(d("tenantId", t.tenantId))), !this.skipSoftDelete && n.hasSoftDelete(this.table) && (e = e.where(
|
|
1603
|
-
let r = (this.scope.rowFilter ??
|
|
1602
|
+
!this.skipTenant && n.hasTenant(this.table) && t.tenantId != null && (e = e.where(d("tenantId", t.tenantId))), !this.skipSoftDelete && n.hasSoftDelete(this.table) && (e = e.where(S("deletedAt")));
|
|
1603
|
+
let r = (this.scope.rowFilter ?? qn)(this.table);
|
|
1604
1604
|
return r !== void 0 && (e = e.where(r)), e;
|
|
1605
1605
|
}
|
|
1606
1606
|
async all() {
|
|
@@ -1713,19 +1713,19 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
1713
1713
|
select: (n) => new Xr(e, t, n, Yr(n)),
|
|
1714
1714
|
updateWhere: (n) => new Zr(e, t, n),
|
|
1715
1715
|
deleteWhere: (n) => new Qr(e, t, n)
|
|
1716
|
-
}), ei = class extends
|
|
1717
|
-
table:
|
|
1718
|
-
reason:
|
|
1719
|
-
}) {}, ti = class extends
|
|
1720
|
-
operation:
|
|
1721
|
-
table:
|
|
1722
|
-
cause:
|
|
1723
|
-
}) {}, ni = class extends
|
|
1724
|
-
table:
|
|
1725
|
-
summary:
|
|
1726
|
-
issues:
|
|
1727
|
-
path:
|
|
1728
|
-
message:
|
|
1716
|
+
}), ei = class extends L.TaggedError()("TenantScopeViolation", {
|
|
1717
|
+
table: L.String,
|
|
1718
|
+
reason: L.String
|
|
1719
|
+
}) {}, ti = class extends L.TaggedError()("StoreOperationFailed", {
|
|
1720
|
+
operation: L.String,
|
|
1721
|
+
table: L.String,
|
|
1722
|
+
cause: L.String
|
|
1723
|
+
}) {}, ni = class extends L.TaggedError()("TableValidationFailed", {
|
|
1724
|
+
table: L.String,
|
|
1725
|
+
summary: L.String,
|
|
1726
|
+
issues: L.Array(L.Struct({
|
|
1727
|
+
path: L.String,
|
|
1728
|
+
message: L.String
|
|
1729
1729
|
}))
|
|
1730
1730
|
}) {}, ri = "id", ii = (e) => "descriptor" in e ? e.descriptor : e, ai = (e, t) => {
|
|
1731
1731
|
let n = {};
|
|
@@ -1741,7 +1741,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
1741
1741
|
let t = e.metadata?.userId;
|
|
1742
1742
|
return typeof t == "string" && t !== "" ? t : e.id;
|
|
1743
1743
|
}, li = (e, n) => {
|
|
1744
|
-
let r = Wr(e), i = ci(n.subject), a = n.subject.tenantId, o = n.rowFilter ??
|
|
1744
|
+
let r = Wr(e), i = ci(n.subject), a = n.subject.tenantId, o = n.rowFilter ?? qn, s = (e, t) => {
|
|
1745
1745
|
let r = { ...t }, o = n.schemaRegistry, s = o.idScheme(e);
|
|
1746
1746
|
if (s !== void 0 && r[ri] == null) if (s.kind === "numeric") delete r[ri];
|
|
1747
1747
|
else {
|
|
@@ -1791,7 +1791,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
1791
1791
|
}, _ = (e, t) => {
|
|
1792
1792
|
let r = n.schemaRegistry.validatePatchSchema(e);
|
|
1793
1793
|
if (r === void 0) return t;
|
|
1794
|
-
let i =
|
|
1794
|
+
let i = L.decodeUnknownEither(r)(t);
|
|
1795
1795
|
if (i._tag === "Right") return t;
|
|
1796
1796
|
let a = wt.formatErrorSync(i.left).map((e) => ({
|
|
1797
1797
|
path: e.path.length === 0 ? "<root>" : e.path.join("."),
|
|
@@ -1806,7 +1806,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
1806
1806
|
let e = { deletedAt: /* @__PURE__ */ new Date() };
|
|
1807
1807
|
return i !== null && (e.deletedBy = i), e;
|
|
1808
1808
|
}, y = (e, t, n) => {
|
|
1809
|
-
let r =
|
|
1809
|
+
let r = re(n, t);
|
|
1810
1810
|
if (r.length !== 0) throw new ni({
|
|
1811
1811
|
table: e,
|
|
1812
1812
|
summary: `upsert conflictColumns [${n.map((e) => `'${e}'`).join(", ")}] but the payload is missing ${r.map((e) => `'${e}'`).join(", ")}`,
|
|
@@ -1815,10 +1815,10 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
1815
1815
|
message: "named in conflictColumns but absent from the payload"
|
|
1816
1816
|
}))
|
|
1817
1817
|
});
|
|
1818
|
-
},
|
|
1818
|
+
}, b = (e, t) => {
|
|
1819
1819
|
let r = h(e);
|
|
1820
1820
|
if (r !== void 0) {
|
|
1821
|
-
let n =
|
|
1821
|
+
let n = ie(r, t);
|
|
1822
1822
|
if (n.length > 0) throw new ni({
|
|
1823
1823
|
table: e,
|
|
1824
1824
|
summary: `missing required column${n.length > 1 ? "s" : ""} ${n.map((e) => `'${e}'`).join(", ")} — NOT NULL with no default and not auto-stamped`,
|
|
@@ -1830,7 +1830,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
1830
1830
|
}
|
|
1831
1831
|
let i = n.schemaRegistry.insertSchema(e);
|
|
1832
1832
|
if (i === void 0) return t;
|
|
1833
|
-
let a =
|
|
1833
|
+
let a = L.decodeUnknownEither(i)(t);
|
|
1834
1834
|
if (a._tag === "Right") return t;
|
|
1835
1835
|
let o = wt.formatErrorSync(a.left).map((e) => ({
|
|
1836
1836
|
path: e.path.length === 0 ? "<root>" : e.path.join("."),
|
|
@@ -1841,41 +1841,41 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
1841
1841
|
summary: s === void 0 ? "row validation failed" : `${s.path}: ${s.message}`,
|
|
1842
1842
|
issues: o
|
|
1843
1843
|
});
|
|
1844
|
-
},
|
|
1844
|
+
}, x = n.dialect, C = (e, t) => {
|
|
1845
1845
|
let n = h(e);
|
|
1846
|
-
return u(
|
|
1847
|
-
},
|
|
1846
|
+
return u(x ? fe(t, n, x) : t, n, K());
|
|
1847
|
+
}, w = process.env.VOLTRO_FIELD_DECRYPT_ON_ERROR === "null" ? "null" : "throw", te = j({ scope: "store.fieldEncryption" }), T = /* @__PURE__ */ new Set(), ne = (e) => {
|
|
1848
1848
|
let t = `${e.table}.${e.column}`;
|
|
1849
|
-
|
|
1849
|
+
T.has(t) || (T.add(t), te.warn("encrypted column degraded to null — could not decrypt with the active key", {
|
|
1850
1850
|
table: e.table,
|
|
1851
1851
|
column: e.column,
|
|
1852
1852
|
reason: e.reason,
|
|
1853
1853
|
hint: "VOLTRO_FIELD_DECRYPT_ON_ERROR=null is set — this row was likely encrypted under a different key"
|
|
1854
1854
|
}));
|
|
1855
|
-
},
|
|
1856
|
-
let n = h(e), r = c(t, n,
|
|
1857
|
-
onError:
|
|
1858
|
-
...
|
|
1855
|
+
}, E = (e, t) => {
|
|
1856
|
+
let n = h(e), r = c(t, n, K(), {
|
|
1857
|
+
onError: w,
|
|
1858
|
+
...w === "null" ? { warn: ne } : {}
|
|
1859
1859
|
});
|
|
1860
|
-
return
|
|
1861
|
-
},
|
|
1860
|
+
return x ? l(r, n, x) : r;
|
|
1861
|
+
}, ae = (e) => {
|
|
1862
1862
|
let r = e.table, i = e.predicate;
|
|
1863
1863
|
if (!e.crossTenant && a != null && n.schemaRegistry.hasTenant(r)) {
|
|
1864
1864
|
let e = d("tenantId", a);
|
|
1865
1865
|
i = i ? t(i, e) : e;
|
|
1866
1866
|
}
|
|
1867
1867
|
if (!e.includeDeleted && n.schemaRegistry.hasSoftDelete(r)) {
|
|
1868
|
-
let e =
|
|
1868
|
+
let e = S("deletedAt");
|
|
1869
1869
|
i = i ? t(i, e) : e;
|
|
1870
1870
|
}
|
|
1871
|
-
return i =
|
|
1871
|
+
return i = Zn(o, r, i), i === e.predicate ? e : {
|
|
1872
1872
|
...e,
|
|
1873
1873
|
predicate: i
|
|
1874
1874
|
};
|
|
1875
|
-
},
|
|
1875
|
+
}, oe = async (e) => {
|
|
1876
1876
|
let t = await r.query(e);
|
|
1877
|
-
return
|
|
1878
|
-
},
|
|
1877
|
+
return E(e.table, t);
|
|
1878
|
+
}, se = async (e) => oe(ae(e)), ce = async (e, t, i) => {
|
|
1879
1879
|
let a = f(e, i);
|
|
1880
1880
|
if (n.schemaRegistry.computedFields(e).size > 0) {
|
|
1881
1881
|
let n = (await r.query({
|
|
@@ -1891,30 +1891,30 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
1891
1891
|
projection: void 0
|
|
1892
1892
|
}))[0];
|
|
1893
1893
|
if (n === void 0) return null;
|
|
1894
|
-
a = g(e,
|
|
1894
|
+
a = g(e, E(e, [n])[0], a);
|
|
1895
1895
|
}
|
|
1896
1896
|
a = _(e, a);
|
|
1897
|
-
let o = await r.update(e, t,
|
|
1898
|
-
return o === null ? null :
|
|
1899
|
-
},
|
|
1897
|
+
let o = await r.update(e, t, C(e, a));
|
|
1898
|
+
return o === null ? null : E(e, [o])[0];
|
|
1899
|
+
}, le = async (e, t) => n.schemaRegistry.hasSoftDelete(e) ? await r.update(e, t, v()) !== null : r.delete(e, t), ue = async (e, t, n) => r.updateMany(e, C(e, f(e, t)), n), de = async (e, t) => r.deleteMany(e, t), pe = (e, r) => a != null && n.schemaRegistry.hasTenant(e) ? t(r, d("tenantId", a)) : r, me = async (e, t, n) => ue(e, t, {
|
|
1900
1900
|
...n,
|
|
1901
|
-
where:
|
|
1902
|
-
}),
|
|
1901
|
+
where: pe(e, n.where)
|
|
1902
|
+
}), he = async (e, t) => de(e, {
|
|
1903
1903
|
...t,
|
|
1904
|
-
where:
|
|
1905
|
-
}),
|
|
1906
|
-
query:
|
|
1907
|
-
updateMany:
|
|
1908
|
-
deleteMany:
|
|
1904
|
+
where: pe(e, t.where)
|
|
1905
|
+
}), ge = $r({
|
|
1906
|
+
query: oe,
|
|
1907
|
+
updateMany: ue,
|
|
1908
|
+
deleteMany: de,
|
|
1909
1909
|
delete: (e, t) => r.delete(e, t)
|
|
1910
1910
|
}, {
|
|
1911
1911
|
subject: n.subject,
|
|
1912
1912
|
schemaRegistry: n.schemaRegistry,
|
|
1913
1913
|
rowFilter: o
|
|
1914
|
-
}),
|
|
1915
|
-
let n = t.map((t) => s(e, t)), i = n.map((t) =>
|
|
1916
|
-
return
|
|
1917
|
-
},
|
|
1914
|
+
}), D = ((e, t, n) => t === void 0 ? ge.updateWhere(e) : ce(e, t, n)), O = ((e, t) => t === void 0 ? ge.deleteWhere(e) : le(e, t)), k = async (e, t) => {
|
|
1915
|
+
let n = t.map((t) => s(e, t)), i = n.map((t) => C(e, b(e, t))), a = await m(e, n[0] ?? {}, () => r.insertMany(e, i));
|
|
1916
|
+
return E(e, a);
|
|
1917
|
+
}, _e = (e, t) => {
|
|
1918
1918
|
let n = Object.keys(t);
|
|
1919
1919
|
if (n.length !== 1) throw Error(`store.links('${e}'): anchor must name exactly one source column, got [${n.join(", ")}]`);
|
|
1920
1920
|
let r = n[0], i = t[r], a = h(e);
|
|
@@ -1929,9 +1929,9 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
1929
1929
|
};
|
|
1930
1930
|
};
|
|
1931
1931
|
return {
|
|
1932
|
-
query:
|
|
1932
|
+
query: se,
|
|
1933
1933
|
one: (async (e) => {
|
|
1934
|
-
let t = ii(e), n = await
|
|
1934
|
+
let t = ii(e), n = await se({
|
|
1935
1935
|
...t,
|
|
1936
1936
|
take: 2
|
|
1937
1937
|
}), r = n[0];
|
|
@@ -1945,21 +1945,21 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
1945
1945
|
});
|
|
1946
1946
|
return r;
|
|
1947
1947
|
}),
|
|
1948
|
-
first: (async (e) => (await
|
|
1948
|
+
first: (async (e) => (await se({
|
|
1949
1949
|
...ii(e),
|
|
1950
1950
|
take: 1
|
|
1951
1951
|
}))[0] ?? null),
|
|
1952
|
-
maybeOne: (async (e) => (await
|
|
1952
|
+
maybeOne: (async (e) => (await se({
|
|
1953
1953
|
...ii(e),
|
|
1954
1954
|
take: 1
|
|
1955
1955
|
}))[0] ?? null),
|
|
1956
1956
|
insert: async (e, t) => {
|
|
1957
|
-
let n = s(e, t), i = await m(e, n, () => r.insert(e,
|
|
1958
|
-
return
|
|
1957
|
+
let n = s(e, t), i = await m(e, n, () => r.insert(e, C(e, b(e, n))));
|
|
1958
|
+
return E(e, [i])[0];
|
|
1959
1959
|
},
|
|
1960
|
-
insertMany: (async (e, t) =>
|
|
1960
|
+
insertMany: (async (e, t) => k(e, t)),
|
|
1961
1961
|
links: (e, n) => {
|
|
1962
|
-
let { sourceCol: r, sourceId: i, targetCol: a } =
|
|
1962
|
+
let { sourceCol: r, sourceId: i, targetCol: a } = _e(e, n), o = async () => (await se({
|
|
1963
1963
|
table: e,
|
|
1964
1964
|
predicate: d(r, i),
|
|
1965
1965
|
order: [],
|
|
@@ -1967,12 +1967,12 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
1967
1967
|
skip: void 0,
|
|
1968
1968
|
take: void 0
|
|
1969
1969
|
})).map((e) => String(e[a])), s = async (t) => {
|
|
1970
|
-
t.length !== 0 && await
|
|
1970
|
+
t.length !== 0 && await k(e, t.map((e) => ({
|
|
1971
1971
|
[r]: i,
|
|
1972
1972
|
[a]: e
|
|
1973
1973
|
})));
|
|
1974
1974
|
}, c = async (n) => {
|
|
1975
|
-
n.length !== 0 && await
|
|
1975
|
+
n.length !== 0 && await he(e, { where: t(d(r, i), ee(a, n)) });
|
|
1976
1976
|
};
|
|
1977
1977
|
return {
|
|
1978
1978
|
list: o,
|
|
@@ -1992,7 +1992,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
1992
1992
|
return await c(n), n;
|
|
1993
1993
|
},
|
|
1994
1994
|
setRows: async (n) => {
|
|
1995
|
-
let o = /* @__PURE__ */ new Map(), s = await
|
|
1995
|
+
let o = /* @__PURE__ */ new Map(), s = await se({
|
|
1996
1996
|
table: e,
|
|
1997
1997
|
predicate: d(r, i),
|
|
1998
1998
|
order: [],
|
|
@@ -2014,9 +2014,9 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2014
2014
|
else {
|
|
2015
2015
|
let c = o.get(n), l = {}, u = !1;
|
|
2016
2016
|
for (let [e, t] of Object.entries(s)) e === r || e === a || c[e] !== t && (l[e] = t, u = !0);
|
|
2017
|
-
u && (p.push(n), await
|
|
2017
|
+
u && (p.push(n), await me(e, l, { where: t(d(r, i), d(a, n)) }));
|
|
2018
2018
|
}
|
|
2019
|
-
return m.length > 0 && await
|
|
2019
|
+
return m.length > 0 && await k(e, m), {
|
|
2020
2020
|
added: f,
|
|
2021
2021
|
removed: u,
|
|
2022
2022
|
updated: p
|
|
@@ -2026,26 +2026,26 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2026
2026
|
},
|
|
2027
2027
|
patchJson: async (e, t, n, i) => {
|
|
2028
2028
|
let a = await r.patchJson(e, t, n, i);
|
|
2029
|
-
return a === null ? null :
|
|
2029
|
+
return a === null ? null : E(e, [a])[0];
|
|
2030
2030
|
},
|
|
2031
|
-
select:
|
|
2032
|
-
update:
|
|
2033
|
-
delete:
|
|
2031
|
+
select: ge.select,
|
|
2032
|
+
update: D,
|
|
2033
|
+
delete: O,
|
|
2034
2034
|
applyDefined: ai,
|
|
2035
2035
|
hardDelete: async (e, t) => r.delete(e, t),
|
|
2036
|
-
updateMany:
|
|
2037
|
-
deleteMany:
|
|
2036
|
+
updateMany: me,
|
|
2037
|
+
deleteMany: he,
|
|
2038
2038
|
upsert: async (e, t, n) => {
|
|
2039
2039
|
let i = s(e, t);
|
|
2040
2040
|
y(e, i, n.conflictColumns);
|
|
2041
|
-
let a = await m(e, i, () => r.upsert(e,
|
|
2042
|
-
return
|
|
2041
|
+
let a = await m(e, i, () => r.upsert(e, C(e, b(e, i)), n));
|
|
2042
|
+
return E(e, [a])[0];
|
|
2043
2043
|
},
|
|
2044
2044
|
insertIgnore: async (e, t, n) => {
|
|
2045
2045
|
let i = s(e, t);
|
|
2046
2046
|
y(e, i, n.conflictColumns);
|
|
2047
|
-
let a = await m(e, i, () => r.insertIgnore(e,
|
|
2048
|
-
return
|
|
2047
|
+
let a = await m(e, i, () => r.insertIgnore(e, C(e, b(e, i)), n));
|
|
2048
|
+
return E(e, [a])[0];
|
|
2049
2049
|
},
|
|
2050
2050
|
transactional: (e) => r.transactional(async (t) => e(li(t, n))),
|
|
2051
2051
|
...r.raw ? { raw: r.raw.bind(r) } : {},
|
|
@@ -2194,7 +2194,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2194
2194
|
return o.size;
|
|
2195
2195
|
}
|
|
2196
2196
|
};
|
|
2197
|
-
}, hi =
|
|
2197
|
+
}, hi = j({ scope: "voltro:replication" }), gi = new Ct(), _i = (e, t) => gi.run(e, t), vi = () => gi.getStore(), yi = class {
|
|
2198
2198
|
primary;
|
|
2199
2199
|
replicas;
|
|
2200
2200
|
adapter;
|
|
@@ -2431,33 +2431,33 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2431
2431
|
}, Si = (e, t) => {
|
|
2432
2432
|
let n = xi(e);
|
|
2433
2433
|
return n === void 0 ? t() : Br(n, t);
|
|
2434
|
-
}, Ci = (e, t, n, r) => e === "subject" ? `${t}:s:${n}` : e === "global" ? `${t}:global` : r.tenantId == null ? void 0 : `${t}:t:${r.tenantId}`, wi = (e, t) =>
|
|
2435
|
-
let r =
|
|
2434
|
+
}, Ci = (e, t, n, r) => e === "subject" ? `${t}:s:${n}` : e === "global" ? `${t}:global` : r.tenantId == null ? void 0 : `${t}:t:${r.tenantId}`, wi = (e, t) => N.async((n) => {
|
|
2435
|
+
let r = de(t, () => N.runFork(e));
|
|
2436
2436
|
return r.addObserver((e) => {
|
|
2437
2437
|
n(e);
|
|
2438
|
-
}),
|
|
2438
|
+
}), N.asVoid(nt.interrupt(r));
|
|
2439
2439
|
}), Ti = (e, t, n) => ({
|
|
2440
2440
|
subject: e,
|
|
2441
|
-
traceId: t?.traceId ??
|
|
2441
|
+
traceId: t?.traceId ?? Se(),
|
|
2442
2442
|
...t?.spanId === void 0 ? {} : { spanId: t.spanId },
|
|
2443
2443
|
...n === void 0 ? {} : { clientId: n }
|
|
2444
|
-
}), Ei =
|
|
2444
|
+
}), Ei = N.currentSpan.pipe(N.catchAll(() => N.succeed(void 0))), Di = (e) => ({
|
|
2445
2445
|
traceId: e.traceId,
|
|
2446
2446
|
...e.spanId === void 0 ? {} : { spanId: e.spanId }
|
|
2447
2447
|
}), Oi = (e, t, n) => {
|
|
2448
2448
|
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));
|
|
2449
2449
|
}, ki = (e) => {
|
|
2450
|
-
if (
|
|
2451
|
-
let t = await
|
|
2450
|
+
if (Kn() !== void 0) return async () => {
|
|
2451
|
+
let t = await N.runPromise(N.either(Jn(e, (e) => {
|
|
2452
2452
|
console.error("[voltro] row filter failed to load — subscription", e);
|
|
2453
2453
|
})));
|
|
2454
2454
|
if (t._tag === "Left") throw t.left;
|
|
2455
2455
|
return t.right;
|
|
2456
2456
|
};
|
|
2457
|
-
}, Ai = (e, t, n, r, i, a, o, s) =>
|
|
2458
|
-
let l = yield*
|
|
2457
|
+
}, Ai = (e, t, n, r, i, a, o, s) => R.asyncScoped((c) => N.gen(function* () {
|
|
2458
|
+
let l = yield* N.tryPromise(() => t.subscribe(e, (e) => {
|
|
2459
2459
|
c.single(e);
|
|
2460
|
-
}, n, r, i, a, o, s)).pipe(
|
|
2460
|
+
}, n, r, i, a, o, s)).pipe(N.matchCause({
|
|
2461
2461
|
onFailure: (e) => (zi(`subscription.${i}`, n.traceId, e), {
|
|
2462
2462
|
ok: !1,
|
|
2463
2463
|
error: Ui(e)
|
|
@@ -2475,23 +2475,23 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2475
2475
|
return;
|
|
2476
2476
|
}
|
|
2477
2477
|
let u = l.unsubscribe;
|
|
2478
|
-
if (yield*
|
|
2479
|
-
let e =
|
|
2478
|
+
if (yield* N.addFinalizer(() => N.sync(() => u())), n.clientId !== void 0) {
|
|
2479
|
+
let e = mr(n.clientId, () => {
|
|
2480
2480
|
c.end();
|
|
2481
2481
|
});
|
|
2482
|
-
yield*
|
|
2482
|
+
yield* N.addFinalizer(() => N.sync(() => e()));
|
|
2483
2483
|
}
|
|
2484
2484
|
})), ji = /* @__PURE__ */ new Set(), Mi = () => {
|
|
2485
2485
|
ji.clear();
|
|
2486
2486
|
}, Ni = (e) => {
|
|
2487
2487
|
ji.has(e) || (ji.add(e), process.stderr.write(`[voltro] ${e}: \`cache:\` is declared but NOT applied — this query's handler returns a computed value, and the snapshot cache only wraps a store read. Every subscriber re-runs the handler. Either return a query descriptor (so the read can be cached), or drop \`cache:\` so the declaration matches what happens.\n`));
|
|
2488
|
-
}, Pi = (e, t, n, r) =>
|
|
2489
|
-
let a = yield*
|
|
2488
|
+
}, Pi = (e, t, n, r) => R.asyncScoped((i) => N.gen(function* () {
|
|
2489
|
+
let a = yield* N.tryPromise(() => t.subscribeComputed(e, (e) => {
|
|
2490
2490
|
i.single(e._tag === "snapshot" ? {
|
|
2491
2491
|
...e,
|
|
2492
2492
|
computed: !0
|
|
2493
2493
|
} : e);
|
|
2494
|
-
}, n, r)).pipe(
|
|
2494
|
+
}, n, r)).pipe(N.matchCause({
|
|
2495
2495
|
onFailure: (e) => (zi(`subscription.${r}`, n.traceId, e), {
|
|
2496
2496
|
ok: !1,
|
|
2497
2497
|
error: Ui(e)
|
|
@@ -2509,19 +2509,19 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2509
2509
|
return;
|
|
2510
2510
|
}
|
|
2511
2511
|
let o = a.unsubscribe;
|
|
2512
|
-
if (yield*
|
|
2513
|
-
let e =
|
|
2512
|
+
if (yield* N.addFinalizer(() => N.sync(() => o())), n.clientId !== void 0) {
|
|
2513
|
+
let e = mr(n.clientId, () => {
|
|
2514
2514
|
i.end();
|
|
2515
2515
|
});
|
|
2516
|
-
yield*
|
|
2516
|
+
yield* N.addFinalizer(() => N.sync(() => e()));
|
|
2517
2517
|
}
|
|
2518
|
-
})), Fi = (e, t, n = "rpc.subscription", r, i, a, o) =>
|
|
2519
|
-
let s = yield*
|
|
2518
|
+
})), Fi = (e, t, n = "rpc.subscription", r, i, a, o) => R.unwrap(N.gen(function* () {
|
|
2519
|
+
let s = yield* Pe, c = yield* ke, l = yield* Ei;
|
|
2520
2520
|
Oi(l, n, s);
|
|
2521
|
-
let u = Ti(s, l, c.clientId), d = pi(s.id, c.clientId), f = _i({ subjectKey: d }, () =>
|
|
2521
|
+
let u = Ti(s, l, c.clientId), d = pi(s.id, c.clientId), f = _i({ subjectKey: d }, () => wr({
|
|
2522
2522
|
traceId: u.traceId,
|
|
2523
2523
|
...u.spanId === void 0 ? {} : { spanId: u.spanId }
|
|
2524
|
-
}, () => Si(n, () => e(u)))), p =
|
|
2524
|
+
}, () => Si(n, () => e(u)))), p = N.isEffect(f) ? yield* f.pipe(N.matchCause({
|
|
2525
2525
|
onFailure: (e) => (zi(`subscription.${n}`, u.traceId, e), {
|
|
2526
2526
|
ok: !1,
|
|
2527
2527
|
error: Ui(e)
|
|
@@ -2534,33 +2534,33 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2534
2534
|
ok: !0,
|
|
2535
2535
|
value: f
|
|
2536
2536
|
};
|
|
2537
|
-
if (!p.ok) return
|
|
2537
|
+
if (!p.ok) return R.make({
|
|
2538
2538
|
_tag: "error",
|
|
2539
2539
|
error: p.error
|
|
2540
2540
|
});
|
|
2541
2541
|
let m = p.value;
|
|
2542
|
-
if (
|
|
2542
|
+
if (ir(m)) return i !== void 0 && Ni(n), Pi(m, t, u, n);
|
|
2543
2543
|
let h = m, g = r?.(h), _ = i === void 0 ? void 0 : Ci(i.scope, i.baseKey, d, s);
|
|
2544
2544
|
return Ai(h, t, u, g, n, i === void 0 || _ === void 0 ? void 0 : {
|
|
2545
2545
|
key: _,
|
|
2546
2546
|
ttlMs: i.ttlMs,
|
|
2547
2547
|
swrMs: i.swrMs
|
|
2548
2548
|
}, a?.(s), o?.(s) ?? ki(s));
|
|
2549
|
-
}).pipe(
|
|
2550
|
-
let n = yield*
|
|
2549
|
+
}).pipe(N.withSpan(n, { attributes: { "framework.kind": "subscription" } }))), Ii = (e, t = "rpc.stream") => R.unwrap(N.gen(function* () {
|
|
2550
|
+
let n = yield* Pe, r = yield* ke, i = yield* Ei;
|
|
2551
2551
|
Oi(i, t, n);
|
|
2552
|
-
let a = Ti(n, i, r.clientId), o = Si(t, () => e(a)), s =
|
|
2552
|
+
let a = Ti(n, i, r.clientId), o = Si(t, () => e(a)), s = N.isEffect(o) ? yield* o.pipe(N.orDie) : o;
|
|
2553
2553
|
if (a.clientId === void 0) return s;
|
|
2554
2554
|
let c = a.clientId;
|
|
2555
|
-
return
|
|
2556
|
-
let e = yield*
|
|
2557
|
-
|
|
2555
|
+
return R.unwrapScoped(N.gen(function* () {
|
|
2556
|
+
let e = yield* Qe.make(), t = mr(c, () => {
|
|
2557
|
+
Qe.unsafeDone(e, N.void);
|
|
2558
2558
|
});
|
|
2559
|
-
return yield*
|
|
2559
|
+
return yield* N.addFinalizer(() => N.sync(() => t())), s.pipe(R.interruptWhen(Qe.await(e)));
|
|
2560
2560
|
}));
|
|
2561
|
-
}).pipe(
|
|
2562
|
-
if (
|
|
2563
|
-
let r =
|
|
2561
|
+
}).pipe(N.withSpan(t, { attributes: { "framework.kind": "stream" } }))), Li = j({ scope: "voltro:rpc" }), Ri = j({ scope: "voltro:http" }), zi = (e, t, n) => {
|
|
2562
|
+
if (M.isInterruptedOnly(n)) return;
|
|
2563
|
+
let r = M.squash(n), i = r?._tag, a = r instanceof Error ? r.message : r?.message ?? String(r), o = M.dieOption(n)._tag === "Some", s = on(r), c = {
|
|
2564
2564
|
traceId: t,
|
|
2565
2565
|
...i === void 0 ? {} : { errorTag: i },
|
|
2566
2566
|
...s
|
|
@@ -2575,7 +2575,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2575
2575
|
message: "internal server error",
|
|
2576
2576
|
traceId: e
|
|
2577
2577
|
}), Ui = (e) => {
|
|
2578
|
-
let t =
|
|
2578
|
+
let t = M.squash(e);
|
|
2579
2579
|
if (t && typeof t == "object" && t._tag === "UnknownException" && (t = t.error ?? t.cause ?? t), Vi(t)) return {
|
|
2580
2580
|
_tag: "InternalError",
|
|
2581
2581
|
message: "internal server error"
|
|
@@ -2588,47 +2588,47 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2588
2588
|
...typeof i == "string" ? { _tag: i } : {},
|
|
2589
2589
|
message: typeof a == "string" ? a : String(t)
|
|
2590
2590
|
};
|
|
2591
|
-
}, Wi = (e, t, n = "rpc.mutation") =>
|
|
2592
|
-
let r = yield*
|
|
2591
|
+
}, Wi = (e, t, n = "rpc.mutation") => N.gen(function* () {
|
|
2592
|
+
let r = yield* Pe, i = yield* ke, a = yield* Ei;
|
|
2593
2593
|
Oi(a, n, r);
|
|
2594
2594
|
let o = Ti(r, a, i.clientId), s = pi(r.id, i.clientId), c = {
|
|
2595
2595
|
traceId: o.traceId,
|
|
2596
2596
|
subjectId: ci(r),
|
|
2597
2597
|
procedure: n
|
|
2598
|
-
}, l = _i({ subjectKey: s }, () =>
|
|
2598
|
+
}, l = _i({ subjectKey: s }, () => wr({
|
|
2599
2599
|
traceId: o.traceId,
|
|
2600
2600
|
...o.spanId === void 0 ? {} : { spanId: o.spanId }
|
|
2601
|
-
}, () =>
|
|
2602
|
-
return yield* (
|
|
2601
|
+
}, () => de(c, () => Si(n, () => e(t, o)))));
|
|
2602
|
+
return yield* (N.isEffect(l) ? wi(l, c) : N.tryPromise({
|
|
2603
2603
|
try: () => Promise.resolve(l),
|
|
2604
2604
|
catch: (e) => e
|
|
2605
|
-
})).pipe(
|
|
2606
|
-
}).pipe(
|
|
2607
|
-
let t = e.port ?? 4e3, n = e.path ?? "/ws",
|
|
2605
|
+
})).pipe(N.tapErrorCause((e) => N.sync(() => zi(n, o.traceId, e))), N.catchIf(Vi, () => N.die(Hi(o.traceId))), N.annotateLogs(Di(o)));
|
|
2606
|
+
}).pipe(N.withSpan(n, { attributes: { "framework.kind": "mutation" } })), Gi = 8 * 1024 * 1024, Ki = (e) => {
|
|
2607
|
+
let t = e.port ?? 4e3, n = e.host, r = e.path ?? "/ws", i = ut(), a = (t) => pt.HttpServerRequest.pipe(N.flatMap((t) => N.gen(function* () {
|
|
2608
2608
|
if (!e.inspectRoute) return V.text("inspect route not configured", { status: 404 });
|
|
2609
2609
|
let n = {};
|
|
2610
2610
|
for (let [e, r] of Object.entries(t.headers)) r !== void 0 && (n[e.toLowerCase()] = Array.isArray(r) ? r.join(", ") : r);
|
|
2611
2611
|
let r;
|
|
2612
|
-
t.method !== "GET" && t.method !== "HEAD" && t.method !== "OPTIONS" && (r = yield* t.text.pipe(
|
|
2613
|
-
let i = e.inspectRoute.handle(t.url, n, t.method, r), a = i instanceof Promise ? yield*
|
|
2612
|
+
t.method !== "GET" && t.method !== "HEAD" && t.method !== "OPTIONS" && (r = yield* t.text.pipe(N.orElseSucceed(() => "")));
|
|
2613
|
+
let i = e.inspectRoute.handle(t.url, n, t.method, r), a = i instanceof Promise ? yield* N.promise(() => i) : i;
|
|
2614
2614
|
return a === null ? V.text("inspect route not found", { status: 404 }) : V.text(a.body, {
|
|
2615
2615
|
status: a.status,
|
|
2616
2616
|
contentType: a.contentType,
|
|
2617
2617
|
headers: a.headers ?? {}
|
|
2618
2618
|
});
|
|
2619
|
-
}))),
|
|
2619
|
+
}))), o = () => pt.HttpServerRequest.pipe(N.flatMap((t) => {
|
|
2620
2620
|
let n = e.inspectStream;
|
|
2621
|
-
if (!n) return
|
|
2621
|
+
if (!n) return N.succeed(V.text("inspect stream not configured", { status: 404 }));
|
|
2622
2622
|
let r = {};
|
|
2623
2623
|
for (let [e, n] of Object.entries(t.headers)) n !== void 0 && (r[e.toLowerCase()] = Array.isArray(n) ? n.join(", ") : n);
|
|
2624
2624
|
let i = n.corsHeaders(r.origin);
|
|
2625
|
-
if (n.isDisabled()) return
|
|
2625
|
+
if (n.isDisabled()) return N.succeed(V.text(JSON.stringify({ error: "inspect disabled (VOLTRO_INSPECT=off)" }), {
|
|
2626
2626
|
status: 503,
|
|
2627
2627
|
contentType: "application/json; charset=utf-8",
|
|
2628
2628
|
headers: i
|
|
2629
2629
|
}));
|
|
2630
2630
|
let a = n.authorize(r);
|
|
2631
|
-
if (!a.ok) return
|
|
2631
|
+
if (!a.ok) return N.succeed(V.text(JSON.stringify({
|
|
2632
2632
|
error: "unauthorized",
|
|
2633
2633
|
reason: a.reason
|
|
2634
2634
|
}), {
|
|
@@ -2640,18 +2640,18 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2640
2640
|
if (!f || e.indexOf("event: ") !== 0) return !0;
|
|
2641
2641
|
let t = e.indexOf("\n", 7);
|
|
2642
2642
|
return t < 0 || f.has(e.slice(7, t).trim());
|
|
2643
|
-
}, m =
|
|
2643
|
+
}, m = R.asyncScoped((e) => N.gen(function* () {
|
|
2644
2644
|
if (e.single(o.encode("retry: 5000\n\n")), !u) for (let t of n.replay()) p(t) && e.single(o.encode(t));
|
|
2645
2645
|
let t = n.subscribe((t) => {
|
|
2646
2646
|
p(t) && e.single(o.encode(t));
|
|
2647
2647
|
}), r = setInterval(() => {
|
|
2648
2648
|
e.single(o.encode(n.keepAlive()));
|
|
2649
2649
|
}, s);
|
|
2650
|
-
yield*
|
|
2650
|
+
yield* N.addFinalizer(() => N.sync(() => {
|
|
2651
2651
|
clearInterval(r), t();
|
|
2652
2652
|
}));
|
|
2653
2653
|
}));
|
|
2654
|
-
return
|
|
2654
|
+
return N.succeed(V.stream(m, {
|
|
2655
2655
|
status: 200,
|
|
2656
2656
|
headers: {
|
|
2657
2657
|
"content-type": "text/event-stream; charset=utf-8",
|
|
@@ -2661,31 +2661,31 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2661
2661
|
...i
|
|
2662
2662
|
}
|
|
2663
2663
|
}));
|
|
2664
|
-
})),
|
|
2664
|
+
})), s = B.add("*", "/_voltro/inspect/*", pt.HttpServerRequest.pipe(N.flatMap((t) => N.gen(function* () {
|
|
2665
2665
|
if (!e.inspectRoute) return V.text("inspect route not configured", { status: 404 });
|
|
2666
2666
|
let n = {};
|
|
2667
2667
|
for (let [e, r] of Object.entries(t.headers)) r !== void 0 && (n[e.toLowerCase()] = Array.isArray(r) ? r.join(", ") : r);
|
|
2668
2668
|
let r;
|
|
2669
|
-
t.method !== "GET" && t.method !== "HEAD" && t.method !== "OPTIONS" && (r = yield* t.text.pipe(
|
|
2670
|
-
let i = e.inspectRoute.handle(t.url, n, t.method, r), a = i instanceof Promise ? yield*
|
|
2669
|
+
t.method !== "GET" && t.method !== "HEAD" && t.method !== "OPTIONS" && (r = yield* t.text.pipe(N.orElseSucceed(() => "")));
|
|
2670
|
+
let i = e.inspectRoute.handle(t.url, n, t.method, r), a = i instanceof Promise ? yield* N.promise(() => i) : i;
|
|
2671
2671
|
return a === null ? V.text("inspect route not found", { status: 404 }) : V.text(a.body, {
|
|
2672
2672
|
status: a.status,
|
|
2673
2673
|
contentType: a.contentType,
|
|
2674
2674
|
headers: a.headers ?? {}
|
|
2675
2675
|
});
|
|
2676
|
-
})))),
|
|
2677
|
-
e.inspectRoute !== void 0 && (
|
|
2678
|
-
let
|
|
2676
|
+
})))), c = P.empty;
|
|
2677
|
+
e.inspectRoute !== void 0 && (c = e.inspectStream === void 0 ? P.mergeAll(B.add("*", "/_voltro/inspect", a(!0)), s) : P.mergeAll(B.add("GET", "/_voltro/inspect/stream", o()), B.add("*", "/_voltro/inspect", a(!0)), s));
|
|
2678
|
+
let l = P.empty;
|
|
2679
2679
|
if (e.webhookRoutes !== void 0 && e.webhookRoutes.size > 0) {
|
|
2680
|
-
let t = (e) => pt.HttpServerRequest.pipe(
|
|
2680
|
+
let t = (e) => pt.HttpServerRequest.pipe(N.flatMap((t) => N.gen(function* () {
|
|
2681
2681
|
let n = {};
|
|
2682
2682
|
for (let [e, r] of Object.entries(t.headers)) r !== void 0 && (n[e.toLowerCase()] = Array.isArray(r) ? r.join(", ") : r);
|
|
2683
|
-
let r = t.method !== "GET" && t.method !== "HEAD" ? yield* t.text.pipe(
|
|
2683
|
+
let r = t.method !== "GET" && t.method !== "HEAD" ? yield* t.text.pipe(N.orElseSucceed(() => "")) : "", i = new TextEncoder().encode(r), a = t.url.split("?")[0], o = Sr(n.traceparent), s = yield* N.promise(() => e.handle({
|
|
2684
2684
|
method: t.method,
|
|
2685
2685
|
path: a,
|
|
2686
2686
|
headers: n,
|
|
2687
2687
|
rawBody: i
|
|
2688
|
-
})).pipe(
|
|
2688
|
+
})).pipe(N.withSpan(`webhook${a}`, {
|
|
2689
2689
|
attributes: {
|
|
2690
2690
|
"framework.kind": "webhook",
|
|
2691
2691
|
"http.route": a
|
|
@@ -2697,21 +2697,21 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2697
2697
|
contentType: s.contentType
|
|
2698
2698
|
});
|
|
2699
2699
|
}))), n = Array.from(e.webhookRoutes.entries()).map(([e, n]) => B.add("*", e, t(n)));
|
|
2700
|
-
|
|
2700
|
+
l = P.mergeAll(...n);
|
|
2701
2701
|
}
|
|
2702
|
-
let
|
|
2702
|
+
let u = P.empty;
|
|
2703
2703
|
if (e.httpRoutes !== void 0 && e.httpRoutes.length > 0) {
|
|
2704
|
-
let t = (t) => pt.HttpServerRequest.pipe(
|
|
2704
|
+
let t = (t) => pt.HttpServerRequest.pipe(N.flatMap((n) => N.gen(function* () {
|
|
2705
2705
|
let r = {};
|
|
2706
2706
|
for (let [e, t] of Object.entries(n.headers)) t !== void 0 && (r[e.toLowerCase()] = Array.isArray(t) ? t.join(", ") : t);
|
|
2707
|
-
let i = n.url.indexOf("?"), a = i >= 0 ? n.url.slice(0, i) : n.url, o = i >= 0 ? n.url.slice(i + 1) : "", s = n.method !== "GET" && n.method !== "HEAD" ? new Uint8Array(yield* n.arrayBuffer.pipe(
|
|
2707
|
+
let i = n.url.indexOf("?"), a = i >= 0 ? n.url.slice(0, i) : n.url, o = i >= 0 ? n.url.slice(i + 1) : "", s = n.method !== "GET" && n.method !== "HEAD" ? new Uint8Array(yield* n.arrayBuffer.pipe(N.orElseSucceed(() => /* @__PURE__ */ new ArrayBuffer(0)))) : /* @__PURE__ */ new Uint8Array(), c = e.getStore?.(), l = {
|
|
2708
2708
|
method: n.method,
|
|
2709
2709
|
path: a,
|
|
2710
2710
|
query: o,
|
|
2711
2711
|
headers: r,
|
|
2712
2712
|
rawBody: s,
|
|
2713
2713
|
...c === void 0 ? {} : { store: c }
|
|
2714
|
-
}, u = yield*
|
|
2714
|
+
}, u = yield* N.promise(() => bt(t, l));
|
|
2715
2715
|
u.status >= 500 && Ri.warn(`${n.method} ${a} → ${u.status}`, {
|
|
2716
2716
|
method: n.method,
|
|
2717
2717
|
path: a,
|
|
@@ -2724,14 +2724,14 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2724
2724
|
headers: d
|
|
2725
2725
|
};
|
|
2726
2726
|
if (u.stream !== void 0) {
|
|
2727
|
-
let { subscribe: e, keepAliveMs: t } = u.stream, n = new TextEncoder(), r = t ?? 15e3, i =
|
|
2727
|
+
let { subscribe: e, keepAliveMs: t } = u.stream, n = new TextEncoder(), r = t ?? 15e3, i = R.asyncScoped((t) => N.gen(function* () {
|
|
2728
2728
|
t.single(n.encode("retry: 5000\n\n"));
|
|
2729
2729
|
let i = e((e) => {
|
|
2730
2730
|
t.single(n.encode(e));
|
|
2731
2731
|
}), a = r > 0 ? setInterval(() => {
|
|
2732
2732
|
t.single(n.encode(": keep-alive\n\n"));
|
|
2733
2733
|
}, r) : void 0;
|
|
2734
|
-
yield*
|
|
2734
|
+
yield* N.addFinalizer(() => N.sync(() => {
|
|
2735
2735
|
a !== void 0 && clearInterval(a), i();
|
|
2736
2736
|
}));
|
|
2737
2737
|
}));
|
|
@@ -2747,7 +2747,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2747
2747
|
});
|
|
2748
2748
|
}
|
|
2749
2749
|
return u.body instanceof Uint8Array ? V.uint8Array(u.body, f) : V.text(u.body ?? "", f);
|
|
2750
|
-
})),
|
|
2750
|
+
})), N.tapErrorCause((e) => M.isInterruptedOnly(e) ? N.void : N.sync(() => Ri.error(`${t.map((e) => e.method).join("|")} ${t[0].path} threw`, { path: t[0].path }, M.squash(e))))), n = /* @__PURE__ */ new Map();
|
|
2751
2751
|
for (let t of e.httpRoutes) {
|
|
2752
2752
|
let e = n.get(t.path);
|
|
2753
2753
|
e ? e.push(t) : n.set(t.path, [t]);
|
|
@@ -2756,29 +2756,29 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2756
2756
|
let r = n.length === 1 ? n[0].method : "*", i = t(n);
|
|
2757
2757
|
return [B.add(r, e, i), B.add(r, `${e}/*`, i)];
|
|
2758
2758
|
});
|
|
2759
|
-
|
|
2759
|
+
u = P.mergeAll(...r);
|
|
2760
2760
|
}
|
|
2761
|
-
let
|
|
2761
|
+
let d = vt.layerProtocolWebsocketRouter({ path: r }), f = vt.layer(e.group), p = vt.layer(e.group).pipe(P.provide(vt.layerProtocolHttpRouter({ path: "/rpc" })), P.provide(_t.layerJson), P.provide(e.httpHandlersLayer ?? e.handlersLayer)), m = P.scopedDiscard(N.gen(function* () {
|
|
2762
2762
|
let e = yield* vt.Protocol;
|
|
2763
|
-
yield*
|
|
2763
|
+
yield* N.forkScoped(N.gen(function* () {
|
|
2764
2764
|
let t = yield* e.disconnects.take;
|
|
2765
|
-
|
|
2766
|
-
}).pipe(
|
|
2767
|
-
})),
|
|
2765
|
+
dr(t), hr(t);
|
|
2766
|
+
}).pipe(N.forever));
|
|
2767
|
+
})), h = P.mergeAll(f, m).pipe(P.provide(d), P.provide(_t.layerJson), P.provide(e.handlersLayer)), g = P.mergeAll(h, p, c, l, u), _ = e.pluginHttpInterceptor, v = e.healthCheck, y = Number(process.env.VOLTRO_MAX_RPC_BODY_BYTES), ee = e.maxRpcBodyBytes ?? (Number.isFinite(y) && y > 0 ? y : 8388608), b = { "cache-control": "no-store" }, x = (e) => N.gen(function* () {
|
|
2768
2768
|
let t = yield* pt.HttpServerRequest, n = {};
|
|
2769
2769
|
for (let [e, r] of Object.entries(t.headers)) r !== void 0 && (n[e.toLowerCase()] = Array.isArray(r) ? r.join(", ") : r);
|
|
2770
2770
|
let r = t.url.indexOf("?"), i = r === -1 ? t.url : t.url.slice(0, r);
|
|
2771
2771
|
if (t.method === "POST" && i === "/rpc") {
|
|
2772
2772
|
let e = n["content-length"];
|
|
2773
|
-
if (e !== void 0 && Number(e) >
|
|
2773
|
+
if (e !== void 0 && Number(e) > ee) return V.text("rpc payload too large", {
|
|
2774
2774
|
status: 413,
|
|
2775
2775
|
headers: b
|
|
2776
2776
|
});
|
|
2777
2777
|
}
|
|
2778
|
-
if (
|
|
2778
|
+
if (v && (i === "/internal/liveness" || i === "/internal/readiness")) return i === "/internal/liveness" ? V.text("ok", {
|
|
2779
2779
|
status: 200,
|
|
2780
2780
|
headers: b
|
|
2781
|
-
}) :
|
|
2781
|
+
}) : v.isReady() ? v.ping && !(yield* N.tryPromise(() => v.ping()).pipe(N.orElseSucceed(() => !1))) ? V.text("not-ready: dependency", {
|
|
2782
2782
|
status: 503,
|
|
2783
2783
|
headers: b
|
|
2784
2784
|
}) : V.text("ready", {
|
|
@@ -2788,32 +2788,35 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2788
2788
|
status: 503,
|
|
2789
2789
|
headers: b
|
|
2790
2790
|
});
|
|
2791
|
-
if (!
|
|
2791
|
+
if (!_) return yield* e;
|
|
2792
2792
|
let a = n["x-forwarded-for"], o = a ? a.split(",")[0].trim() : void 0, s;
|
|
2793
2793
|
try {
|
|
2794
2794
|
s = t.source?.socket?.remoteAddress;
|
|
2795
2795
|
} catch {
|
|
2796
2796
|
s = void 0;
|
|
2797
2797
|
}
|
|
2798
|
-
let c = o ?? s, l = yield*
|
|
2798
|
+
let c = o ?? s, l = yield* N.tryPromise(() => _(async () => null, {
|
|
2799
2799
|
method: t.method,
|
|
2800
2800
|
path: i,
|
|
2801
2801
|
headers: n,
|
|
2802
2802
|
remoteAddr: c
|
|
2803
|
-
})).pipe(
|
|
2803
|
+
})).pipe(N.orElseSucceed(() => null));
|
|
2804
2804
|
return l === null ? yield* e : V.text(l.body ?? "", {
|
|
2805
2805
|
status: l.status,
|
|
2806
2806
|
...l.headers ? { headers: l.headers } : {}
|
|
2807
2807
|
});
|
|
2808
|
-
}), S =
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
server
|
|
2808
|
+
}), S = P.unwrapEffect(B.toHttpEffect(g).pipe(N.map((e) => ft.serve(x(e))))).pipe(P.provide(ht.layer(() => i, n === void 0 ? { port: t } : {
|
|
2809
|
+
port: t,
|
|
2810
|
+
host: n
|
|
2811
|
+
})), P.provide(mt.layer));
|
|
2812
|
+
e.tracerLayer && (S = S.pipe(P.provide(e.tracerLayer)));
|
|
2813
|
+
let C = j({ scope: "voltro:rpc" }), w = P.launch(S).pipe(N.catchAllCause((e) => N.sync(() => {
|
|
2814
|
+
C.error("rpc server crashed", {}, M.squash(e)), process.exit(1);
|
|
2815
|
+
}))), te = N.runFork(w);
|
|
2816
|
+
return qi.add(te), $i(), {
|
|
2817
|
+
server: i,
|
|
2815
2818
|
shutdown: async () => {
|
|
2816
|
-
qi.delete(
|
|
2819
|
+
qi.delete(te), await N.runPromise(nt.interrupt(te)).then(() => void 0, () => void 0);
|
|
2817
2820
|
}
|
|
2818
2821
|
};
|
|
2819
2822
|
}, qi = /* @__PURE__ */ new Set(), Ji = /* @__PURE__ */ new Set(), Yi = !1, Xi = (e) => (Ji.add(e), () => {
|
|
@@ -2822,7 +2825,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2822
2825
|
let t = !1, n = () => {
|
|
2823
2826
|
t || (t = !0, clearTimeout(r), e.exit());
|
|
2824
2827
|
}, r = setTimeout(n, e.deadlineMs);
|
|
2825
|
-
r.unref?.(), Promise.all(e.hooks.map((e) => Promise.resolve().then(e).then(() => void 0, () => void 0))).then(() => Promise.all(e.fibers.map((e) =>
|
|
2828
|
+
r.unref?.(), Promise.all(e.hooks.map((e) => Promise.resolve().then(e).then(() => void 0, () => void 0))).then(() => Promise.all(e.fibers.map((e) => N.runPromise(nt.interrupt(e)).then(() => void 0, () => void 0)))).then(n, n);
|
|
2826
2829
|
}, $i = () => {
|
|
2827
2830
|
if (Yi) return;
|
|
2828
2831
|
Yi = !0;
|
|
@@ -2899,7 +2902,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2899
2902
|
}, aa = async (e = {}) => {
|
|
2900
2903
|
let t = e.mode ?? ta(), n = e.metricsMode ?? na(), r = e.extraSpanProcessors ?? [], i = e.extraMetricReaders ?? [];
|
|
2901
2904
|
if (t === "off" && e.traceSink === void 0 && n === "off" && r.length === 0 && i.length === 0) return {
|
|
2902
|
-
layer:
|
|
2905
|
+
layer: P.empty,
|
|
2903
2906
|
mode: t,
|
|
2904
2907
|
bufferOnly: !1,
|
|
2905
2908
|
inMemoryExporter: void 0,
|
|
@@ -2912,14 +2915,14 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
2912
2915
|
...e.traceSink ? [e.traceSink] : [],
|
|
2913
2916
|
...p ? [p] : [],
|
|
2914
2917
|
...r
|
|
2915
|
-
], h = m.length === 1 ? m[0] : m, { reader: g, inMemory: _ } = ia(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,
|
|
2918
|
+
], h = m.length === 1 ? m[0] : m, { reader: g, inMemory: _ } = ia(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, ee = {
|
|
2916
2919
|
serviceName: d,
|
|
2917
2920
|
...e.serviceVersion ? { serviceVersion: e.serviceVersion } : {},
|
|
2918
2921
|
...e.resourceAttributes ? { attributes: e.resourceAttributes } : {}
|
|
2919
2922
|
};
|
|
2920
2923
|
return {
|
|
2921
2924
|
layer: a.nodeSdk.NodeSdk.layer(() => ({
|
|
2922
|
-
resource:
|
|
2925
|
+
resource: ee,
|
|
2923
2926
|
spanProcessor: h,
|
|
2924
2927
|
...y ? { metricReader: y } : {},
|
|
2925
2928
|
...e.sampler ? { tracerConfig: { sampler: e.sampler } } : {}
|
|
@@ -3028,7 +3031,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3028
3031
|
key: e.key,
|
|
3029
3032
|
status: e.status === "completed" ? "completed" : "in_flight",
|
|
3030
3033
|
response: wa(e.response),
|
|
3031
|
-
createdAt:
|
|
3034
|
+
createdAt: Je(e.createdAt)
|
|
3032
3035
|
}), Ea = async (e, n, r) => (await e.query({
|
|
3033
3036
|
table: Ca,
|
|
3034
3037
|
predicate: t(d("scope", n), d("key", r)),
|
|
@@ -3055,7 +3058,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3055
3058
|
createdAt: new Date(r)
|
|
3056
3059
|
}, { conflictColumns: ["scope", "key"] });
|
|
3057
3060
|
if (o.id === a) return "claimed";
|
|
3058
|
-
if (r -
|
|
3061
|
+
if (r - Je(o.createdAt) < i) return Ta(o);
|
|
3059
3062
|
await e.delete(Ca, o.id);
|
|
3060
3063
|
}
|
|
3061
3064
|
let a = await Ea(e, t, n);
|
|
@@ -3095,7 +3098,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3095
3098
|
skip: void 0,
|
|
3096
3099
|
projection: void 0
|
|
3097
3100
|
}))[0] ?? null, Ma = (e) => {
|
|
3098
|
-
let n = (e, t, n) =>
|
|
3101
|
+
let n = (e, t, n) => N.tryPromise({
|
|
3099
3102
|
try: n,
|
|
3100
3103
|
catch: (n) => new kt({
|
|
3101
3104
|
operation: e,
|
|
@@ -3106,7 +3109,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3106
3109
|
return {
|
|
3107
3110
|
get: (t) => n("get", t, async () => {
|
|
3108
3111
|
let n = await ja(e, t);
|
|
3109
|
-
return n === null ?
|
|
3112
|
+
return n === null ? ot.none() : ka(n, Date.now()) ? (await e.delete(J, n.id), ot.none()) : ot.some(Aa(n.value));
|
|
3110
3113
|
}),
|
|
3111
3114
|
set: (t, r, i) => n("set", t, async () => {
|
|
3112
3115
|
let n = Date.now(), a = i?.ttlMs !== void 0 && i.ttlMs > 0 ? new Date(n + i.ttlMs) : null, o = p({
|
|
@@ -3139,7 +3142,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3139
3142
|
return n === null ? !1 : ka(n, Date.now()) ? (await e.delete(J, n.id), !1) : !0;
|
|
3140
3143
|
}),
|
|
3141
3144
|
list: (r) => n("list", "", async () => {
|
|
3142
|
-
let n = Date.now(), i =
|
|
3145
|
+
let n = Date.now(), i = ae(S("expiresAt"), g("expiresAt", new Date(n))), a = r === "" ? i : t(s("key", r), i), o = await e.query({
|
|
3143
3146
|
table: J,
|
|
3144
3147
|
predicate: a,
|
|
3145
3148
|
order: [],
|
|
@@ -3158,10 +3161,10 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3158
3161
|
})
|
|
3159
3162
|
};
|
|
3160
3163
|
}, Na = async ({ store: e, env: t = process.env }) => {
|
|
3161
|
-
let n = (t.KV_BACKEND ?? "database").toLowerCase(), r = n === "redis" ? "redis" : n === "memory" ? "memory" : "database", i = r === "redis" ? Nt(t.KV_KEY_PREFIX ? { keyPrefix: t.KV_KEY_PREFIX } : {}).pipe(
|
|
3164
|
+
let n = (t.KV_BACKEND ?? "database").toLowerCase(), r = n === "redis" ? "redis" : n === "memory" ? "memory" : "database", i = r === "redis" ? Nt(t.KV_KEY_PREFIX ? { keyPrefix: t.KV_KEY_PREFIX } : {}).pipe(P.provide(jt)) : r === "memory" ? Mt() : P.succeed(At, At.of(Ma(e))), a = rt.make(Ot.Default.pipe(P.provide(i))), o = await a.runPromise(Ot);
|
|
3162
3165
|
return {
|
|
3163
3166
|
kv: {
|
|
3164
|
-
get: (e) => a.runPromise(o.get(e)).then((e) =>
|
|
3167
|
+
get: (e) => a.runPromise(o.get(e)).then((e) => ot.getOrUndefined(e)),
|
|
3165
3168
|
getOrElse: (e, t) => a.runPromise(o.getOrElse(e, t)),
|
|
3166
3169
|
set: (e, t, n) => a.runPromise(o.set(e, t, n)),
|
|
3167
3170
|
delete: (e) => a.runPromise(o.delete(e)),
|
|
@@ -3181,7 +3184,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3181
3184
|
has: () => Promise.resolve(!1),
|
|
3182
3185
|
list: () => Promise.resolve([]),
|
|
3183
3186
|
clear: () => Promise.resolve()
|
|
3184
|
-
}, Fa = "_voltro_api_keys", Ia = (e) =>
|
|
3187
|
+
}, Fa = "_voltro_api_keys", Ia = (e) => be("sha256").update(e, "utf8").digest("hex"), La = (e = "voltro_") => `${e}${xe(30).toString("base64url")}`, Ra = (e) => ({
|
|
3185
3188
|
id: e.id,
|
|
3186
3189
|
name: e.name,
|
|
3187
3190
|
keyPrefix: e.keyPrefix,
|
|
@@ -3340,21 +3343,21 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3340
3343
|
scopes: t.scopes ?? []
|
|
3341
3344
|
};
|
|
3342
3345
|
}, Ja = (e, t = "/v1/api-keys") => {
|
|
3343
|
-
let n =
|
|
3344
|
-
id:
|
|
3345
|
-
name:
|
|
3346
|
-
keyPrefix:
|
|
3347
|
-
tenantId:
|
|
3348
|
-
scopes:
|
|
3349
|
-
lastUsedAt:
|
|
3350
|
-
expiresAt:
|
|
3351
|
-
revokedAt:
|
|
3352
|
-
createdAt:
|
|
3353
|
-
createdBy:
|
|
3354
|
-
onBehalfOf:
|
|
3355
|
-
metadata:
|
|
3356
|
-
key:
|
|
3357
|
-
value:
|
|
3346
|
+
let n = L.Struct({
|
|
3347
|
+
id: L.String,
|
|
3348
|
+
name: L.String,
|
|
3349
|
+
keyPrefix: L.String,
|
|
3350
|
+
tenantId: L.NullOr(L.String),
|
|
3351
|
+
scopes: L.Array(L.String),
|
|
3352
|
+
lastUsedAt: L.NullOr(L.Number),
|
|
3353
|
+
expiresAt: L.NullOr(L.Number),
|
|
3354
|
+
revokedAt: L.NullOr(L.Number),
|
|
3355
|
+
createdAt: L.Number,
|
|
3356
|
+
createdBy: L.NullOr(L.String),
|
|
3357
|
+
onBehalfOf: L.NullOr(L.String),
|
|
3358
|
+
metadata: L.optional(L.NullOr(L.Record({
|
|
3359
|
+
key: L.String,
|
|
3360
|
+
value: L.Unknown
|
|
3358
3361
|
})))
|
|
3359
3362
|
});
|
|
3360
3363
|
return [
|
|
@@ -3363,42 +3366,42 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3363
3366
|
path: `${t}/issue`,
|
|
3364
3367
|
summary: "Issue an API key (the token is returned ONCE).",
|
|
3365
3368
|
guards: [xt([
|
|
3366
|
-
we,
|
|
3367
|
-
De,
|
|
3368
3369
|
Te,
|
|
3369
|
-
|
|
3370
|
+
Oe,
|
|
3371
|
+
Ee,
|
|
3372
|
+
De
|
|
3370
3373
|
])],
|
|
3371
|
-
input:
|
|
3372
|
-
name:
|
|
3373
|
-
scopes:
|
|
3374
|
-
expiresInDays:
|
|
3375
|
-
onBehalfOf:
|
|
3374
|
+
input: L.Struct({ body: L.Struct({
|
|
3375
|
+
name: L.String,
|
|
3376
|
+
scopes: L.optional(L.Array(L.String)),
|
|
3377
|
+
expiresInDays: L.optional(L.Number),
|
|
3378
|
+
onBehalfOf: L.optional(L.NullOr(L.String))
|
|
3376
3379
|
}) }),
|
|
3377
|
-
output:
|
|
3378
|
-
id:
|
|
3379
|
-
token:
|
|
3380
|
-
keyPrefix:
|
|
3380
|
+
output: L.Struct({
|
|
3381
|
+
id: L.String,
|
|
3382
|
+
token: L.String,
|
|
3383
|
+
keyPrefix: L.String
|
|
3381
3384
|
}),
|
|
3382
3385
|
handler: async (t, n) => {
|
|
3383
|
-
let r = t.body, i = qa(n), a = new Set(i.scopes), o = (e) => a.has(
|
|
3386
|
+
let r = t.body, i = qa(n), a = new Set(i.scopes), o = (e) => a.has(Te) || a.has(e), s = r.onBehalfOf === void 0 ? i.id : r.onBehalfOf;
|
|
3384
3387
|
if (s === null) {
|
|
3385
|
-
if (!o(
|
|
3386
|
-
required:
|
|
3388
|
+
if (!o(Ee)) throw new Ne({
|
|
3389
|
+
required: Ee,
|
|
3387
3390
|
message: "not allowed to issue an organization key"
|
|
3388
3391
|
});
|
|
3389
3392
|
} else if (s !== i.id) {
|
|
3390
|
-
if (!o(
|
|
3391
|
-
required:
|
|
3393
|
+
if (!o(De)) throw new Ne({
|
|
3394
|
+
required: De,
|
|
3392
3395
|
message: "not allowed to issue a key on behalf of another user"
|
|
3393
3396
|
});
|
|
3394
|
-
} else if (!o(
|
|
3395
|
-
required:
|
|
3397
|
+
} else if (!o(Oe)) throw new Ne({
|
|
3398
|
+
required: Oe,
|
|
3396
3399
|
message: "not allowed to issue an api key"
|
|
3397
3400
|
});
|
|
3398
3401
|
let c = r.scopes ?? [...a];
|
|
3399
|
-
if (!a.has(
|
|
3402
|
+
if (!a.has(Te)) {
|
|
3400
3403
|
let e = c.filter((e) => !a.has(e));
|
|
3401
|
-
if (e.length > 0) throw new
|
|
3404
|
+
if (e.length > 0) throw new Ne({
|
|
3402
3405
|
required: String(e[0]),
|
|
3403
3406
|
message: `cannot issue a key with scopes you do not hold: ${e.join(", ")}`
|
|
3404
3407
|
});
|
|
@@ -3422,18 +3425,18 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3422
3425
|
method: "GET",
|
|
3423
3426
|
path: t,
|
|
3424
3427
|
summary: "List the caller tenant's API keys (no secrets).",
|
|
3425
|
-
guards: [St(
|
|
3426
|
-
input:
|
|
3427
|
-
output:
|
|
3428
|
+
guards: [St(Te)],
|
|
3429
|
+
input: L.Struct({}),
|
|
3430
|
+
output: L.Struct({ keys: L.Array(n) }),
|
|
3428
3431
|
handler: async (t, n) => ({ keys: [...await e.list(qa(n).tenantId)] })
|
|
3429
3432
|
}),
|
|
3430
3433
|
yt({
|
|
3431
3434
|
method: "POST",
|
|
3432
3435
|
path: `${t}/revoke`,
|
|
3433
3436
|
summary: "Revoke an API key by id.",
|
|
3434
|
-
guards: [St(
|
|
3435
|
-
input:
|
|
3436
|
-
output:
|
|
3437
|
+
guards: [St(Te)],
|
|
3438
|
+
input: L.Struct({ body: L.Struct({ id: L.String }) }),
|
|
3439
|
+
output: L.Struct({ ok: L.Boolean }),
|
|
3437
3440
|
handler: async (t, n) => ({ ok: await e.revoke(t.body.id, qa(n).tenantId) })
|
|
3438
3441
|
})
|
|
3439
3442
|
];
|
|
@@ -3441,14 +3444,14 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3441
3444
|
type: "anonymous",
|
|
3442
3445
|
id: null,
|
|
3443
3446
|
tenantId: null
|
|
3444
|
-
}, Xa = class extends
|
|
3447
|
+
}, Xa = class extends Xe.Tag("@voltro/EffectStore")() {}, Za = (e, t) => (n) => n instanceof ei ? n : new ti({
|
|
3445
3448
|
operation: e,
|
|
3446
3449
|
table: t,
|
|
3447
3450
|
cause: String(n)
|
|
3448
|
-
}), Qa = (e, t, n) =>
|
|
3451
|
+
}), Qa = (e, t, n) => N.tryPromise({
|
|
3449
3452
|
try: n,
|
|
3450
3453
|
catch: Za(e, t)
|
|
3451
|
-
}), $a = (e) =>
|
|
3454
|
+
}), $a = (e) => P.succeed(Xa, {
|
|
3452
3455
|
query: ((t) => Qa("query", t.table, () => e.query(t))),
|
|
3453
3456
|
insert: (t, n) => Qa("insert", t, () => e.insert(t, n)),
|
|
3454
3457
|
update: (t, n, r) => Qa("update", t, () => e.update(t, n, r)),
|
|
@@ -3456,7 +3459,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3456
3459
|
hardDelete: (t, n) => Qa("hardDelete", t, () => e.hardDelete(t, n))
|
|
3457
3460
|
}), eo = (e) => gt.make(e.name, {
|
|
3458
3461
|
payload: e.payloadSchema,
|
|
3459
|
-
success:
|
|
3462
|
+
success: Re,
|
|
3460
3463
|
error: e.errorSchema
|
|
3461
3464
|
}), to = (e, t) => ({
|
|
3462
3465
|
id: t,
|
|
@@ -3464,7 +3467,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3464
3467
|
executionId: t,
|
|
3465
3468
|
status: "running"
|
|
3466
3469
|
}), no = to, ro = (e) => {
|
|
3467
|
-
let t =
|
|
3470
|
+
let t = M.failureOption(e), n = t._tag === "Some" ? t.value : M.squash(e);
|
|
3468
3471
|
return {
|
|
3469
3472
|
tag: n && typeof n == "object" && "_tag" in n ? String(n._tag) : null,
|
|
3470
3473
|
message: n?.message ?? String(n)
|
|
@@ -3484,7 +3487,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3484
3487
|
};
|
|
3485
3488
|
if (typeof n == "object" && n && n._tag === "Complete") {
|
|
3486
3489
|
let r = n.exit;
|
|
3487
|
-
return
|
|
3490
|
+
return tt.isSuccess(r) ? {
|
|
3488
3491
|
id: t,
|
|
3489
3492
|
workflowName: e,
|
|
3490
3493
|
executionId: t,
|
|
@@ -3536,7 +3539,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3536
3539
|
}
|
|
3537
3540
|
return n;
|
|
3538
3541
|
}, r = (e, t) => {
|
|
3539
|
-
let n =
|
|
3542
|
+
let n = L.validateEither(e.payloadSchema)(t);
|
|
3540
3543
|
if (n._tag === "Right") return;
|
|
3541
3544
|
let r = typeof t == "object" && t ? Object.keys(t) : [], i = co(e.payloadSchema).filter((e) => !r.includes(e));
|
|
3542
3545
|
throw new oo(e.name, i, Tt.formatErrorSync(n.left));
|
|
@@ -3676,11 +3679,11 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3676
3679
|
};
|
|
3677
3680
|
}, mo = (e, t) => {
|
|
3678
3681
|
let n = {};
|
|
3679
|
-
for (let r of e) n[r.definition.name] = (e) => (t ?
|
|
3682
|
+
for (let r of e) n[r.definition.name] = (e) => (t ? N.promise(() => t.start(r.definition.name, e)) : r.definition.execute(e, { discard: !0 }).pipe(N.map((e) => to(r.definition.name, e)))).pipe(N.withSpan(`workflow.${r.definition.name}`, { attributes: { "framework.kind": "workflow" } }));
|
|
3680
3683
|
return n;
|
|
3681
3684
|
}, ho = (e, t, n) => e.map((e) => e.definition.toLayer(((r, i) => {
|
|
3682
3685
|
let a = t.resolveStartContext?.(e.definition.name, i);
|
|
3683
|
-
return (a === void 0 ?
|
|
3686
|
+
return (a === void 0 ? N.succeed(void 0) : N.promise(() => Promise.resolve(a))).pipe(N.flatMap((a) => {
|
|
3684
3687
|
let o = {
|
|
3685
3688
|
...a,
|
|
3686
3689
|
subject: a?.subject ?? Ya,
|
|
@@ -3690,8 +3693,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3690
3693
|
executionId: i,
|
|
3691
3694
|
parentExecutionId: a?.parentExecutionId ?? null,
|
|
3692
3695
|
parentClosePolicy: a?.parentClosePolicy ?? null
|
|
3693
|
-
}), c = e.buildExecute(s), l = (n?.(e, c, o) ?? c)(r, i), u =
|
|
3694
|
-
return
|
|
3696
|
+
}), c = e.buildExecute(s), l = (n?.(e, c, o) ?? c)(r, i), u = P.succeed(Pe, o.subject), d = s?.store, f = d === void 0 ? l : N.provide(l, $a(d));
|
|
3697
|
+
return N.provide(f, u);
|
|
3695
3698
|
}));
|
|
3696
3699
|
}))), go = (e) => ({
|
|
3697
3700
|
_tag: "workflowEventTrigger",
|
|
@@ -3699,32 +3702,32 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3699
3702
|
}), _o = go, vo = (e) => typeof e == "object" && !!e && e._tag === "workflowEventTrigger", yo = () => {
|
|
3700
3703
|
let e = globalThis.crypto;
|
|
3701
3704
|
return typeof e?.randomUUID == "function" ? e.randomUUID() : `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
|
|
3702
|
-
}, bo = (e) => `${e}_${yo()}`, xo = (e) => e.id ?? `${e.event}->${e.workflow}`, So =
|
|
3705
|
+
}, bo = (e) => `${e}_${yo()}`, xo = (e) => e.id ?? `${e.event}->${e.workflow}`, So = D("_voltro_workflow_events", {
|
|
3703
3706
|
id: y({ prefix: "wfe" }),
|
|
3704
|
-
name:
|
|
3705
|
-
payload:
|
|
3706
|
-
source:
|
|
3707
|
-
subject:
|
|
3708
|
-
traceId:
|
|
3709
|
-
occurredAt:
|
|
3710
|
-
}).index(["name"]).index(["source"]).index(["occurredAt"]), Co =
|
|
3707
|
+
name: O(),
|
|
3708
|
+
payload: w(),
|
|
3709
|
+
source: O(),
|
|
3710
|
+
subject: w().nullable(),
|
|
3711
|
+
traceId: O().nullable(),
|
|
3712
|
+
occurredAt: k().default("now")
|
|
3713
|
+
}).index(["name"]).index(["source"]).index(["occurredAt"]), Co = D("_voltro_workflow_event_deliveries", {
|
|
3711
3714
|
id: y({ prefix: "wfed" }),
|
|
3712
|
-
eventId:
|
|
3713
|
-
eventName:
|
|
3714
|
-
triggerId:
|
|
3715
|
-
workflowName:
|
|
3716
|
-
executionId:
|
|
3717
|
-
status:
|
|
3715
|
+
eventId: O(),
|
|
3716
|
+
eventName: O(),
|
|
3717
|
+
triggerId: O(),
|
|
3718
|
+
workflowName: O(),
|
|
3719
|
+
executionId: O().nullable(),
|
|
3720
|
+
status: O().oneOf([
|
|
3718
3721
|
"starting",
|
|
3719
3722
|
"started",
|
|
3720
3723
|
"skipped",
|
|
3721
3724
|
"failed"
|
|
3722
3725
|
]).default("starting"),
|
|
3723
|
-
idempotencyKey:
|
|
3726
|
+
idempotencyKey: O().unique(),
|
|
3724
3727
|
skipped: i().default(!1),
|
|
3725
|
-
errorMessage:
|
|
3726
|
-
createdAt:
|
|
3727
|
-
completedAt:
|
|
3728
|
+
errorMessage: O().nullable(),
|
|
3729
|
+
createdAt: k().default("now"),
|
|
3730
|
+
completedAt: k().nullable()
|
|
3728
3731
|
}).index(["eventId"]).index(["eventName"]).index(["triggerId"]).index(["workflowName"]).index(["status"]), wo = (e) => {
|
|
3729
3732
|
let t = e.makeId ?? bo, n = /* @__PURE__ */ new Map();
|
|
3730
3733
|
for (let t of e.triggers) {
|
|
@@ -3870,51 +3873,51 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
3870
3873
|
triggered: m
|
|
3871
3874
|
};
|
|
3872
3875
|
} };
|
|
3873
|
-
}, To =
|
|
3876
|
+
}, To = j({ scope: "voltro:outbox" }), Y = "_voltro_outbox", Eo = {
|
|
3874
3877
|
kind: "typeid",
|
|
3875
3878
|
prefix: "obx"
|
|
3876
|
-
}, Do =
|
|
3879
|
+
}, Do = D(Y, {
|
|
3877
3880
|
id: y({ prefix: "obx" }),
|
|
3878
|
-
effect:
|
|
3879
|
-
payload:
|
|
3880
|
-
status:
|
|
3881
|
-
attempts:
|
|
3882
|
-
maxAttempts:
|
|
3883
|
-
nextAttemptAt:
|
|
3884
|
-
idempotencyKey:
|
|
3885
|
-
lastError:
|
|
3886
|
-
subjectId:
|
|
3887
|
-
tenantId:
|
|
3888
|
-
traceId:
|
|
3889
|
-
createdAt:
|
|
3890
|
-
deliveredAt:
|
|
3891
|
-
resendRequestedBy:
|
|
3892
|
-
resendReason:
|
|
3893
|
-
resendCount:
|
|
3881
|
+
effect: O(),
|
|
3882
|
+
payload: w(),
|
|
3883
|
+
status: O(),
|
|
3884
|
+
attempts: b(),
|
|
3885
|
+
maxAttempts: b(),
|
|
3886
|
+
nextAttemptAt: k(),
|
|
3887
|
+
idempotencyKey: O().nullable(),
|
|
3888
|
+
lastError: O().nullable(),
|
|
3889
|
+
subjectId: O().nullable(),
|
|
3890
|
+
tenantId: O().nullable(),
|
|
3891
|
+
traceId: O().nullable(),
|
|
3892
|
+
createdAt: k(),
|
|
3893
|
+
deliveredAt: k().nullable(),
|
|
3894
|
+
resendRequestedBy: O().nullable(),
|
|
3895
|
+
resendReason: O().nullable(),
|
|
3896
|
+
resendCount: b()
|
|
3894
3897
|
}), Oo = "_voltro_outbox_attempts", ko = {
|
|
3895
3898
|
kind: "typeid",
|
|
3896
3899
|
prefix: "obxa"
|
|
3897
|
-
}, Ao =
|
|
3900
|
+
}, Ao = D(Oo, {
|
|
3898
3901
|
id: y({ prefix: "obxa" }),
|
|
3899
|
-
outboxId:
|
|
3900
|
-
effect:
|
|
3901
|
-
attempt:
|
|
3902
|
-
trigger:
|
|
3903
|
-
triggeredBy:
|
|
3904
|
-
reason:
|
|
3905
|
-
outcome:
|
|
3902
|
+
outboxId: O(),
|
|
3903
|
+
effect: O(),
|
|
3904
|
+
attempt: b(),
|
|
3905
|
+
trigger: O().oneOf(["automatic", "manual"]),
|
|
3906
|
+
triggeredBy: O().nullable(),
|
|
3907
|
+
reason: O().nullable(),
|
|
3908
|
+
outcome: O().oneOf([
|
|
3906
3909
|
"delivered",
|
|
3907
3910
|
"failed",
|
|
3908
3911
|
"dead"
|
|
3909
3912
|
]),
|
|
3910
|
-
startedAt:
|
|
3911
|
-
finishedAt:
|
|
3912
|
-
durationMs:
|
|
3913
|
-
error:
|
|
3914
|
-
response:
|
|
3915
|
-
subjectId:
|
|
3916
|
-
tenantId:
|
|
3917
|
-
traceId:
|
|
3913
|
+
startedAt: k(),
|
|
3914
|
+
finishedAt: k(),
|
|
3915
|
+
durationMs: b(),
|
|
3916
|
+
error: O().nullable(),
|
|
3917
|
+
response: w().nullable(),
|
|
3918
|
+
subjectId: O().nullable(),
|
|
3919
|
+
tenantId: O().nullable(),
|
|
3920
|
+
traceId: O().nullable()
|
|
3918
3921
|
}).index(["outboxId", "attempt"]).index(["startedAt"]).index(["outcome"]), jo = (e) => {
|
|
3919
3922
|
if (e.effect.trim() === "") throw Error("defineOutboxHandler: `effect` must be a non-empty name");
|
|
3920
3923
|
if (e.maxAttempts !== void 0 && e.maxAttempts < 1) throw Error(`defineOutboxHandler("${e.effect}"): maxAttempts must be >= 1`);
|
|
@@ -4045,7 +4048,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4045
4048
|
}, zo = async (e) => {
|
|
4046
4049
|
let n = (e.now ?? (() => /* @__PURE__ */ new Date()))(), r = await e.store.query({
|
|
4047
4050
|
table: Y,
|
|
4048
|
-
predicate: t(d("status", "pending"),
|
|
4051
|
+
predicate: t(d("status", "pending"), ne("nextAttemptAt", n)),
|
|
4049
4052
|
order: [{
|
|
4050
4053
|
column: "nextAttemptAt",
|
|
4051
4054
|
direction: "asc"
|
|
@@ -4122,45 +4125,45 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4122
4125
|
dead: o,
|
|
4123
4126
|
skipped: s
|
|
4124
4127
|
};
|
|
4125
|
-
}, Bo =
|
|
4128
|
+
}, Bo = j({ scope: "voltro:connections" }), X = "_voltro_connections", Vo = {
|
|
4126
4129
|
kind: "typeid",
|
|
4127
4130
|
prefix: "conn"
|
|
4128
|
-
}, Ho =
|
|
4131
|
+
}, Ho = D(X, {
|
|
4129
4132
|
id: y({ prefix: "conn" }),
|
|
4130
|
-
connectionId:
|
|
4131
|
-
subjectId:
|
|
4132
|
-
tenantId:
|
|
4133
|
-
kind:
|
|
4134
|
-
status:
|
|
4133
|
+
connectionId: O(),
|
|
4134
|
+
subjectId: O(),
|
|
4135
|
+
tenantId: O().nullable(),
|
|
4136
|
+
kind: O().oneOf(["oauth2", "pat"]),
|
|
4137
|
+
status: O().oneOf([
|
|
4135
4138
|
"connected",
|
|
4136
4139
|
"expired",
|
|
4137
4140
|
"revoked",
|
|
4138
4141
|
"error"
|
|
4139
4142
|
]),
|
|
4140
|
-
accessToken:
|
|
4141
|
-
refreshToken:
|
|
4142
|
-
expiresAt:
|
|
4143
|
-
scopes:
|
|
4144
|
-
accountId:
|
|
4145
|
-
accountLabel:
|
|
4146
|
-
lastError:
|
|
4147
|
-
refreshLockedUntil:
|
|
4148
|
-
metadata:
|
|
4149
|
-
connectedAt:
|
|
4150
|
-
updatedAt:
|
|
4143
|
+
accessToken: O(),
|
|
4144
|
+
refreshToken: O().nullable(),
|
|
4145
|
+
expiresAt: k().nullable(),
|
|
4146
|
+
scopes: O().nullable(),
|
|
4147
|
+
accountId: O().nullable(),
|
|
4148
|
+
accountLabel: O().nullable(),
|
|
4149
|
+
lastError: O().nullable(),
|
|
4150
|
+
refreshLockedUntil: k(),
|
|
4151
|
+
metadata: w().nullable(),
|
|
4152
|
+
connectedAt: k(),
|
|
4153
|
+
updatedAt: k()
|
|
4151
4154
|
}).unique("byConnectionSubject", ["connectionId", "subjectId"]).index(["subjectId"]), Uo = "_voltro_connection_grants", Wo = {
|
|
4152
4155
|
kind: "typeid",
|
|
4153
4156
|
prefix: "cgrant"
|
|
4154
|
-
}, Go =
|
|
4157
|
+
}, Go = D(Uo, {
|
|
4155
4158
|
id: y({ prefix: "cgrant" }),
|
|
4156
|
-
state:
|
|
4157
|
-
connectionId:
|
|
4158
|
-
subjectId:
|
|
4159
|
-
tenantId:
|
|
4160
|
-
codeVerifier:
|
|
4161
|
-
redirectTo:
|
|
4162
|
-
createdAt:
|
|
4163
|
-
expiresAt:
|
|
4159
|
+
state: O().unique(),
|
|
4160
|
+
connectionId: O(),
|
|
4161
|
+
subjectId: O(),
|
|
4162
|
+
tenantId: O().nullable(),
|
|
4163
|
+
codeVerifier: O().nullable(),
|
|
4164
|
+
redirectTo: O(),
|
|
4165
|
+
createdAt: k(),
|
|
4166
|
+
expiresAt: k()
|
|
4164
4167
|
}).index(["expiresAt"]), Ko = /^[a-z][a-z0-9-]*$/, qo = (e) => {
|
|
4165
4168
|
if (!Ko.test(e.id)) throw Error(`defineConnection: id "${e.id}" must be lowercase kebab-case (it becomes a URL path segment).`);
|
|
4166
4169
|
if (e.kind === "oauth2") {
|
|
@@ -4173,7 +4176,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4173
4176
|
}
|
|
4174
4177
|
return e;
|
|
4175
4178
|
}, Jo = (e) => e.label ?? e.id, Yo = (e) => {
|
|
4176
|
-
if (e.length !== 0 &&
|
|
4179
|
+
if (e.length !== 0 && K() === void 0) throw Error(`connections: ${e.length} connection(s) declared (${e.map((e) => e.id).join(", ")}) but no field cipher is registered. Connection tokens are stored encrypted and there is no plaintext fallback. Enable \`@voltro/plugin-governance\` with \`governancePlugin({ fieldEncryption: { key: env.FIELD_ENCRYPTION_KEY } })\` (or call setFieldCipher at boot).`);
|
|
4177
4180
|
}, Xo = (e) => {
|
|
4178
4181
|
let t = /* @__PURE__ */ new Map();
|
|
4179
4182
|
for (let n of e) {
|
|
@@ -4225,8 +4228,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4225
4228
|
tenantId: e.tenantId,
|
|
4226
4229
|
kind: e.definition.kind,
|
|
4227
4230
|
status: "connected",
|
|
4228
|
-
accessToken:
|
|
4229
|
-
refreshToken: e.tokens.refreshToken === void 0 ? null :
|
|
4231
|
+
accessToken: q(e.tokens.accessToken),
|
|
4232
|
+
refreshToken: e.tokens.refreshToken === void 0 ? null : q(e.tokens.refreshToken),
|
|
4230
4233
|
expiresAt: n,
|
|
4231
4234
|
scopes: e.tokens.scopes.length > 0 ? e.tokens.scopes.join(" ") : null,
|
|
4232
4235
|
accountId: e.account?.accountId ?? null,
|
|
@@ -4280,7 +4283,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4280
4283
|
});
|
|
4281
4284
|
i = n.status, a = await n.text();
|
|
4282
4285
|
} catch (t) {
|
|
4283
|
-
throw new
|
|
4286
|
+
throw new A({
|
|
4284
4287
|
connectionId: e.id,
|
|
4285
4288
|
reason: `token endpoint unreachable: ${String(t)}`,
|
|
4286
4289
|
transient: !0
|
|
@@ -4292,12 +4295,12 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4292
4295
|
} catch {
|
|
4293
4296
|
o = {};
|
|
4294
4297
|
}
|
|
4295
|
-
if (i < 200 || i >= 300) throw new
|
|
4298
|
+
if (i < 200 || i >= 300) throw new A({
|
|
4296
4299
|
connectionId: e.id,
|
|
4297
4300
|
reason: `token endpoint ${i}: ${o.error ?? ""} ${o.error_description ?? a.slice(0, 200)}`.trim(),
|
|
4298
4301
|
transient: i >= 500
|
|
4299
4302
|
});
|
|
4300
|
-
if (typeof o.access_token != "string" || o.access_token.length === 0) throw new
|
|
4303
|
+
if (typeof o.access_token != "string" || o.access_token.length === 0) throw new A({
|
|
4301
4304
|
connectionId: e.id,
|
|
4302
4305
|
reason: "token response carried no access_token",
|
|
4303
4306
|
transient: !1
|
|
@@ -4358,14 +4361,14 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4358
4361
|
return ms.set(o, c), c;
|
|
4359
4362
|
}, bs = async (e) => {
|
|
4360
4363
|
let { store: n, subjectId: r, now: i } = e, a = e.definition, o = e.sleep ?? ps, s = a.refreshSkewMs ?? 6e4, c = e.row.id;
|
|
4361
|
-
if (await n.updateMany("_voltro_connections", { refreshLockedUntil: new Date(i() + 3e4) }, { where: t(d("id", c),
|
|
4364
|
+
if (await n.updateMany("_voltro_connections", { refreshLockedUntil: new Date(i() + 3e4) }, { where: t(d("id", c), ne("refreshLockedUntil", new Date(i()))) }) === 0) {
|
|
4362
4365
|
for (let e = 0; e < 10; e++) {
|
|
4363
4366
|
await o(200);
|
|
4364
4367
|
let e = await ts(n, a.id, r);
|
|
4365
4368
|
if (e === void 0) throw new fs(a.id, r);
|
|
4366
4369
|
if (!vs(e, s, i())) return _s(a, e);
|
|
4367
4370
|
}
|
|
4368
|
-
throw new
|
|
4371
|
+
throw new A({
|
|
4369
4372
|
connectionId: a.id,
|
|
4370
4373
|
reason: "another replica held the refresh lease and did not publish a fresh token in time",
|
|
4371
4374
|
transient: !0
|
|
@@ -4377,7 +4380,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4377
4380
|
lastError: "access token expired and no refresh token is on file — reconnect required",
|
|
4378
4381
|
refreshLockedUntil: /* @__PURE__ */ new Date(0),
|
|
4379
4382
|
updatedAt: new Date(i())
|
|
4380
|
-
}), new
|
|
4383
|
+
}), new A({
|
|
4381
4384
|
connectionId: a.id,
|
|
4382
4385
|
reason: "access token expired and no refresh token is on file — reconnect required",
|
|
4383
4386
|
transient: !1
|
|
@@ -4386,7 +4389,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4386
4389
|
try {
|
|
4387
4390
|
u = await ls(a, Mr(String(l)), i);
|
|
4388
4391
|
} catch (e) {
|
|
4389
|
-
let t = e instanceof
|
|
4392
|
+
let t = e instanceof A ? e : new A({
|
|
4390
4393
|
connectionId: a.id,
|
|
4391
4394
|
reason: String(e),
|
|
4392
4395
|
transient: !0
|
|
@@ -4397,7 +4400,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4397
4400
|
refreshLockedUntil: /* @__PURE__ */ new Date(0),
|
|
4398
4401
|
updatedAt: new Date(i()),
|
|
4399
4402
|
...t.transient ? {} : {
|
|
4400
|
-
accessToken:
|
|
4403
|
+
accessToken: q(""),
|
|
4401
4404
|
refreshToken: null,
|
|
4402
4405
|
expiresAt: null
|
|
4403
4406
|
}
|
|
@@ -4409,8 +4412,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4409
4412
|
}
|
|
4410
4413
|
let f = {
|
|
4411
4414
|
status: "connected",
|
|
4412
|
-
accessToken:
|
|
4413
|
-
...u.refreshToken === void 0 ? {} : { refreshToken:
|
|
4415
|
+
accessToken: q(u.accessToken),
|
|
4416
|
+
...u.refreshToken === void 0 ? {} : { refreshToken: q(u.refreshToken) },
|
|
4414
4417
|
expiresAt: u.expiresAt === void 0 ? null : new Date(u.expiresAt),
|
|
4415
4418
|
...u.scopes.length > 0 ? { scopes: u.scopes.join(" ") } : {},
|
|
4416
4419
|
lastError: null,
|
|
@@ -4439,7 +4442,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4439
4442
|
connectionId: n.id,
|
|
4440
4443
|
subjectId: e.subjectId,
|
|
4441
4444
|
tenantId: e.tenantId,
|
|
4442
|
-
codeVerifier: i === null ? null :
|
|
4445
|
+
codeVerifier: i === null ? null : q(i),
|
|
4443
4446
|
redirectTo: Es(e.redirectTo),
|
|
4444
4447
|
createdAt: t,
|
|
4445
4448
|
expiresAt: new Date(t.getTime() + ws)
|
|
@@ -4467,20 +4470,20 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4467
4470
|
skip: void 0,
|
|
4468
4471
|
projection: void 0
|
|
4469
4472
|
}))[0];
|
|
4470
|
-
if (n === void 0) throw new
|
|
4473
|
+
if (n === void 0) throw new A({
|
|
4471
4474
|
connectionId: "unknown",
|
|
4472
4475
|
reason: "unknown or already-used handshake state",
|
|
4473
4476
|
transient: !1
|
|
4474
4477
|
});
|
|
4475
4478
|
await e.store.delete(Uo, n.id);
|
|
4476
4479
|
let r = String(n.connectionId), i = Zo(n.expiresAt);
|
|
4477
|
-
if (i !== null && i.getTime() < t.getTime()) throw new
|
|
4480
|
+
if (i !== null && i.getTime() < t.getTime()) throw new A({
|
|
4478
4481
|
connectionId: r,
|
|
4479
4482
|
reason: "handshake expired — start again",
|
|
4480
4483
|
transient: !1
|
|
4481
4484
|
});
|
|
4482
4485
|
let a = e.registry.get(r);
|
|
4483
|
-
if (a === void 0 || a.kind !== "oauth2") throw new
|
|
4486
|
+
if (a === void 0 || a.kind !== "oauth2") throw new A({
|
|
4484
4487
|
connectionId: r,
|
|
4485
4488
|
reason: "no oauth2 connection is declared under that id",
|
|
4486
4489
|
transient: !1
|
|
@@ -4510,7 +4513,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4510
4513
|
}, As = async (e, t = /* @__PURE__ */ new Date()) => {
|
|
4511
4514
|
let n = await e.query({
|
|
4512
4515
|
table: Uo,
|
|
4513
|
-
predicate:
|
|
4516
|
+
predicate: ne("expiresAt", t),
|
|
4514
4517
|
order: [],
|
|
4515
4518
|
take: void 0,
|
|
4516
4519
|
skip: void 0,
|
|
@@ -4569,11 +4572,11 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4569
4572
|
};
|
|
4570
4573
|
}, Ls = (e, t) => {
|
|
4571
4574
|
let n = e.request?.subject?.id ?? null;
|
|
4572
|
-
if (n === null || n === "") throw new
|
|
4575
|
+
if (n === null || n === "") throw new Me({ connectionId: t });
|
|
4573
4576
|
return n;
|
|
4574
4577
|
}, Rs = (e, t) => {
|
|
4575
4578
|
let n = e.registry.get(t);
|
|
4576
|
-
if (n === void 0) throw new
|
|
4579
|
+
if (n === void 0) throw new je({ connectionId: t });
|
|
4577
4580
|
return n;
|
|
4578
4581
|
}, zs = (e) => async (t, n) => {
|
|
4579
4582
|
let r = n.request?.subject?.id ?? null;
|
|
@@ -4591,7 +4594,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4591
4594
|
})) : as(n.store, e.registry, r);
|
|
4592
4595
|
}, Bs = (e) => async (t, n) => {
|
|
4593
4596
|
let r = Rs(e, t.connectionId), i = Ls(n, t.connectionId);
|
|
4594
|
-
if (r.kind !== "oauth2") throw new
|
|
4597
|
+
if (r.kind !== "oauth2") throw new Ae({
|
|
4595
4598
|
connectionId: t.connectionId,
|
|
4596
4599
|
expected: "oauth2",
|
|
4597
4600
|
actual: r.kind
|
|
@@ -4606,13 +4609,13 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4606
4609
|
});
|
|
4607
4610
|
}, Vs = (e) => async (t, n) => {
|
|
4608
4611
|
let r = Rs(e, t.connectionId), i = Ls(n, t.connectionId);
|
|
4609
|
-
if (r.kind !== "pat") throw new
|
|
4612
|
+
if (r.kind !== "pat") throw new Ae({
|
|
4610
4613
|
connectionId: t.connectionId,
|
|
4611
4614
|
expected: "pat",
|
|
4612
4615
|
actual: r.kind
|
|
4613
4616
|
});
|
|
4614
4617
|
let a = t.token.trim();
|
|
4615
|
-
if (a.length === 0) throw new
|
|
4618
|
+
if (a.length === 0) throw new A({
|
|
4616
4619
|
connectionId: t.connectionId,
|
|
4617
4620
|
reason: "token is empty",
|
|
4618
4621
|
transient: !1
|
|
@@ -4621,7 +4624,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4621
4624
|
if (r.validate !== void 0) try {
|
|
4622
4625
|
o = await r.validate(a);
|
|
4623
4626
|
} catch (e) {
|
|
4624
|
-
throw new
|
|
4627
|
+
throw new A({
|
|
4625
4628
|
connectionId: t.connectionId,
|
|
4626
4629
|
reason: `the provider rejected that token: ${e instanceof Error ? e.message : String(e)}`,
|
|
4627
4630
|
transient: !1
|
|
@@ -4642,10 +4645,10 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4642
4645
|
Rs(e, t.connectionId);
|
|
4643
4646
|
let r = Ls(n, t.connectionId);
|
|
4644
4647
|
return { ok: await is(n.store, t.connectionId, r) };
|
|
4645
|
-
}, Us = "admin:full", Ws = class extends
|
|
4646
|
-
action:
|
|
4647
|
-
resourceType:
|
|
4648
|
-
resourceId:
|
|
4648
|
+
}, Us = "admin:full", Ws = class extends L.TaggedError()("AccessDenied", {
|
|
4649
|
+
action: L.String,
|
|
4650
|
+
resourceType: L.String,
|
|
4651
|
+
resourceId: L.String
|
|
4649
4652
|
}) {}, Gs = /* @__PURE__ */ new Map(), Ks = (e) => {
|
|
4650
4653
|
if (typeof e.resourceType != "string" || e.resourceType.length === 0) throw Error("defineResourcePolicy: a non-empty `resourceType` is required");
|
|
4651
4654
|
if (e.actions === void 0 || Object.keys(e.actions).length === 0) throw Error(`resource policy '${e.resourceType}': at least one action is required`);
|
|
@@ -4695,10 +4698,10 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4695
4698
|
return e.filter((e) => !n.has(e.id)).map((e) => e.id);
|
|
4696
4699
|
}, rc = new Ct(), ic = (e) => {
|
|
4697
4700
|
rc.enterWith(e);
|
|
4698
|
-
}, ac = () => rc.getStore(), oc = (e, t) => rc.run(e, t), sc =
|
|
4701
|
+
}, ac = () => rc.getStore(), oc = (e, t) => rc.run(e, t), sc = j({ scope: "voltro:policy" }), cc, lc = (e) => {
|
|
4699
4702
|
cc = e;
|
|
4700
4703
|
}, uc = () => cc, dc = () => {
|
|
4701
|
-
|
|
4704
|
+
Ke((e) => N.gen(function* () {
|
|
4702
4705
|
let t = qs(e.resourceType);
|
|
4703
4706
|
if (t === void 0) return sc.warn("policy guard denied — no resource policy registered for this type", {
|
|
4704
4707
|
resourceType: e.resourceType,
|
|
@@ -4709,7 +4712,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4709
4712
|
resourceType: e.resourceType,
|
|
4710
4713
|
action: e.action
|
|
4711
4714
|
}), !1;
|
|
4712
|
-
let r = yield*
|
|
4715
|
+
let r = yield* N.tryPromise({
|
|
4713
4716
|
try: async () => n({
|
|
4714
4717
|
subjectId: e.subject.id,
|
|
4715
4718
|
resourceType: e.resourceType,
|
|
@@ -4717,10 +4720,10 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4717
4720
|
load: ac()
|
|
4718
4721
|
}),
|
|
4719
4722
|
catch: (e) => e
|
|
4720
|
-
}).pipe(
|
|
4723
|
+
}).pipe(N.catchAll((t) => (sc.error("policy guard denied — tuple source failed", {
|
|
4721
4724
|
resourceType: e.resourceType,
|
|
4722
4725
|
resourceId: e.resourceId
|
|
4723
|
-
}, t),
|
|
4726
|
+
}, t), N.succeed([])))), i = e.subject;
|
|
4724
4727
|
return $s({
|
|
4725
4728
|
id: e.subject.id,
|
|
4726
4729
|
tenantId: i.tenantId ?? null,
|
|
@@ -4746,7 +4749,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4746
4749
|
if (o.length > 0) {
|
|
4747
4750
|
let r = await e.store.query({
|
|
4748
4751
|
table: t,
|
|
4749
|
-
predicate:
|
|
4752
|
+
predicate: ee("id", o),
|
|
4750
4753
|
order: [],
|
|
4751
4754
|
take: void 0,
|
|
4752
4755
|
skip: void 0,
|
|
@@ -4783,11 +4786,11 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4783
4786
|
load: async (e, t) => (await o(e, [t]))[0] ?? null,
|
|
4784
4787
|
loadMany: (e, t) => o(e, t)
|
|
4785
4788
|
};
|
|
4786
|
-
}, mc =
|
|
4789
|
+
}, mc = P.effect(z.HttpClient, N.map(z.HttpClient, (e) => e.pipe(z.mapRequestEffect((e) => N.currentSpan.pipe(N.map((t) => e.headers.traceparent === void 0 ? dt.setHeader(e, "traceparent", br({
|
|
4787
4790
|
traceId: t.traceId,
|
|
4788
4791
|
spanId: t.spanId,
|
|
4789
4792
|
sampled: t.sampled
|
|
4790
|
-
})) : e),
|
|
4793
|
+
})) : e), N.catchAll(() => N.succeed(e))))))), hc = class extends Error {
|
|
4791
4794
|
url;
|
|
4792
4795
|
reason;
|
|
4793
4796
|
_tag = "SsrfBlockedError";
|
|
@@ -4820,12 +4823,12 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4820
4823
|
return e ? yc(`${n.protocol}//${e[1]}`, t) : _c(r) ? `blocked private/reserved address ${r}` : null;
|
|
4821
4824
|
}
|
|
4822
4825
|
return null;
|
|
4823
|
-
}, bc = (e = {}) =>
|
|
4824
|
-
let n =
|
|
4826
|
+
}, bc = (e = {}) => P.effect(z.HttpClient, N.map(z.HttpClient, (t) => {
|
|
4827
|
+
let n = z.transform(t, (t, n) => N.suspend(() => {
|
|
4825
4828
|
let r = yc(n.url, e);
|
|
4826
|
-
return r === null ? t :
|
|
4829
|
+
return r === null ? t : N.die(new hc(n.url, r));
|
|
4827
4830
|
}));
|
|
4828
|
-
return
|
|
4831
|
+
return z.followRedirects(n, e.maxRedirects ?? 5);
|
|
4829
4832
|
})), xc = (e) => {
|
|
4830
4833
|
let t = e.now ?? Date.now, n = e.intervalMs ?? 3e4, r = e.maxPending ?? 500, i = /* @__PURE__ */ new Map(), a = !1, o = async () => {
|
|
4831
4834
|
if (i.size === 0) return;
|
|
@@ -4905,7 +4908,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4905
4908
|
insertSchema: (e) => t.get(e)?.insertSchema,
|
|
4906
4909
|
validatePatchSchema: (e) => t.get(e)?.validatePatchSchema
|
|
4907
4910
|
};
|
|
4908
|
-
}, Ec = /* @__PURE__ */ new Map(), Dc = /* @__PURE__ */ new Map(), Oc = /* @__PURE__ */ new Set(), kc = Tc([]), Ac =
|
|
4911
|
+
}, Ec = /* @__PURE__ */ new Map(), Dc = /* @__PURE__ */ new Map(), Oc = /* @__PURE__ */ new Set(), kc = Tc([]), Ac = j({ scope: "store.fieldEncryption" }), jc = (e, t) => {
|
|
4909
4912
|
let n = t, r = process.env.VOLTRO_FIELD_DECRYPT_ON_ERROR === "null" ? "null" : "throw", i = /* @__PURE__ */ new Set(), a = (e) => {
|
|
4910
4913
|
let t = `${e.table}.${e.column}`;
|
|
4911
4914
|
i.has(t) || (i.add(t), Ac.warn("encrypted column degraded to null — could not decrypt with the active key", {
|
|
@@ -4916,9 +4919,9 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4916
4919
|
}));
|
|
4917
4920
|
}, o = (e, t) => {
|
|
4918
4921
|
let r = h(e);
|
|
4919
|
-
return u(n ?
|
|
4922
|
+
return u(n ? fe(t, r, n) : t, r, K());
|
|
4920
4923
|
}, s = (e, t) => {
|
|
4921
|
-
let i = h(e), o = c(t, i,
|
|
4924
|
+
let i = h(e), o = c(t, i, K(), {
|
|
4922
4925
|
onError: r,
|
|
4923
4926
|
...r === "null" ? { warn: a } : {}
|
|
4924
4927
|
});
|
|
@@ -4952,7 +4955,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
4952
4955
|
for (let e of t) delete n[e];
|
|
4953
4956
|
return n;
|
|
4954
4957
|
}, Nc = (e, t) => {
|
|
4955
|
-
let n = h(e), r = n === void 0 ? [] :
|
|
4958
|
+
let n = h(e), r = n === void 0 ? [] : pe(n);
|
|
4956
4959
|
return r.length === 0 ? t ?? [] : t === void 0 ? r : [...t, ...r];
|
|
4957
4960
|
}, Pc = (e, t) => t.length === 0 ? e : e.map((e) => Mc(e, t)), Fc = (e, t, n, r, i) => {
|
|
4958
4961
|
let a = {
|
|
@@ -5081,30 +5084,30 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
5081
5084
|
table: t
|
|
5082
5085
|
})) : [], Wc = (e) => {
|
|
5083
5086
|
if (e.length !== 0) return `A cached query shares one entry across tenants:\n${e.map((e) => ` • query '${e.query}' caches scope:'global' while reading '${e.table}', a tenant()-scoped table`).join("\n")}\n\nscope:'global' stores ONE entry for every caller. On a tenant-scoped table the\nrows depend on who asked, so the first caller's rows are served to the next one.\n\nUse scope:'tenant' — one entry per org, none shared across orgs. Use 'subject'\nif the result also depends on WHICH person is asking, and 'global' only for data\nthat depends on neither.`;
|
|
5084
|
-
}, Gc = class extends
|
|
5085
|
-
name:
|
|
5086
|
-
retryAfterMs:
|
|
5087
|
+
}, Gc = class extends L.TaggedError()("CircuitOpen", {
|
|
5088
|
+
name: L.String,
|
|
5089
|
+
retryAfterMs: L.Number
|
|
5087
5090
|
}) {}, Kc = {
|
|
5088
5091
|
tag: "closed",
|
|
5089
5092
|
failureCount: 0,
|
|
5090
5093
|
halfOpenSuccesses: 0,
|
|
5091
5094
|
openedAt: 0
|
|
5092
|
-
}, qc = { make: (e) =>
|
|
5093
|
-
let t = e.name ?? "circuit", n =
|
|
5094
|
-
let e = yield*
|
|
5095
|
+
}, qc = { make: (e) => N.gen(function* () {
|
|
5096
|
+
let t = e.name ?? "circuit", n = $e.toMillis($e.decode(e.resetTimeout)), r = e.halfOpenSuccessThreshold ?? 1, i = e.isFailure ?? (() => !0), a = yield* I.make(Kc), o = N.gen(function* () {
|
|
5097
|
+
let e = yield* I.get(a);
|
|
5095
5098
|
if (e.tag === "half-open") {
|
|
5096
5099
|
let t = e.halfOpenSuccesses + 1;
|
|
5097
|
-
yield*
|
|
5100
|
+
yield* I.set(a, t >= r ? Kc : {
|
|
5098
5101
|
...e,
|
|
5099
5102
|
halfOpenSuccesses: t
|
|
5100
5103
|
});
|
|
5101
5104
|
return;
|
|
5102
5105
|
}
|
|
5103
|
-
e.failureCount !== 0 && (yield*
|
|
5104
|
-
}), s =
|
|
5105
|
-
let t = yield*
|
|
5106
|
+
e.failureCount !== 0 && (yield* I.set(a, Kc));
|
|
5107
|
+
}), s = N.gen(function* () {
|
|
5108
|
+
let t = yield* Ye.currentTimeMillis, n = yield* I.get(a);
|
|
5106
5109
|
if (n.tag === "half-open" || n.tag === "open") {
|
|
5107
|
-
yield*
|
|
5110
|
+
yield* I.set(a, {
|
|
5108
5111
|
tag: "open",
|
|
5109
5112
|
failureCount: e.failureThreshold,
|
|
5110
5113
|
halfOpenSuccesses: 0,
|
|
@@ -5113,7 +5116,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
5113
5116
|
return;
|
|
5114
5117
|
}
|
|
5115
5118
|
let r = n.failureCount + 1;
|
|
5116
|
-
yield*
|
|
5119
|
+
yield* I.set(a, r >= e.failureThreshold ? {
|
|
5117
5120
|
tag: "open",
|
|
5118
5121
|
failureCount: r,
|
|
5119
5122
|
halfOpenSuccesses: 0,
|
|
@@ -5122,32 +5125,32 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
5122
5125
|
...n,
|
|
5123
5126
|
failureCount: r
|
|
5124
5127
|
});
|
|
5125
|
-
}), c =
|
|
5126
|
-
let e = yield*
|
|
5128
|
+
}), c = N.gen(function* () {
|
|
5129
|
+
let e = yield* I.get(a);
|
|
5127
5130
|
if (e.tag !== "open") return null;
|
|
5128
|
-
let t = (yield*
|
|
5129
|
-
return t >= n ? (yield*
|
|
5131
|
+
let t = (yield* Ye.currentTimeMillis) - e.openedAt;
|
|
5132
|
+
return t >= n ? (yield* I.set(a, {
|
|
5130
5133
|
tag: "half-open",
|
|
5131
5134
|
failureCount: 0,
|
|
5132
5135
|
halfOpenSuccesses: 0,
|
|
5133
5136
|
openedAt: e.openedAt
|
|
5134
5137
|
}), null) : n - t;
|
|
5135
|
-
}), l = (e) =>
|
|
5138
|
+
}), l = (e) => N.gen(function* () {
|
|
5136
5139
|
let n = yield* c;
|
|
5137
|
-
return n === null ? yield* e.pipe(
|
|
5138
|
-
if (
|
|
5139
|
-
let t =
|
|
5140
|
-
return i(n) ? s :
|
|
5141
|
-
})) : yield*
|
|
5140
|
+
return n === null ? yield* e.pipe(N.tap(() => o), N.tapErrorCause((e) => {
|
|
5141
|
+
if (M.isInterruptedOnly(e)) return N.void;
|
|
5142
|
+
let t = M.failureOption(e), n = t._tag === "Some" ? t.value : void 0;
|
|
5143
|
+
return i(n) ? s : N.void;
|
|
5144
|
+
})) : yield* N.fail(new Gc({
|
|
5142
5145
|
name: t,
|
|
5143
5146
|
retryAfterMs: n
|
|
5144
5147
|
}));
|
|
5145
5148
|
}), u = ((e) => l(e));
|
|
5146
5149
|
return Object.defineProperty(u, "state", {
|
|
5147
|
-
value:
|
|
5150
|
+
value: I.get(a).pipe(N.map((e) => e.tag)),
|
|
5148
5151
|
enumerable: !0
|
|
5149
5152
|
}), Object.defineProperty(u, "reset", {
|
|
5150
|
-
value:
|
|
5153
|
+
value: I.set(a, Kc),
|
|
5151
5154
|
enumerable: !0
|
|
5152
5155
|
}), u;
|
|
5153
5156
|
}) }, Jc, Yc = (e) => {
|
|
@@ -5155,7 +5158,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
5155
5158
|
}, Xc = () => {
|
|
5156
5159
|
Jc = void 0;
|
|
5157
5160
|
}, Zc = () => Jc, Qc = async (e, t = {}) => {
|
|
5158
|
-
let n = t.scopes === void 0 ?
|
|
5161
|
+
let n = t.scopes === void 0 ? qe(t.id ?? "system") : qe(t.id ?? "system", t.scopes), r = t.store ?? Jc?.dataStore, i = t.schemaRegistry ?? Jc?.schemaRegistry, a = t.dialect ?? Jc?.dialect;
|
|
5159
5162
|
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.");
|
|
5160
5163
|
return e({
|
|
5161
5164
|
subject: n,
|
|
@@ -5231,8 +5234,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
5231
5234
|
}
|
|
5232
5235
|
};
|
|
5233
5236
|
}, nl = Symbol.for("@voltro/ScheduleDefinition"), rl = (e) => typeof e == "object" && !!e && nl in e, il = 30 * 6e4, al = (e) => {
|
|
5234
|
-
let t =
|
|
5235
|
-
if (
|
|
5237
|
+
let t = Ze.parse(e.cron, e.timezone);
|
|
5238
|
+
if (et.isLeft(t)) throw Error(`defineSchedule("${e.name}"): invalid cron expression "${e.cron}" (tz="${e.timezone}") — ${String(t.left)}`);
|
|
5236
5239
|
if (!e.timezone || e.timezone.trim() === "") throw Error(`defineSchedule("${e.name}"): timezone is required (e.g. "UTC", "Europe/Berlin")`);
|
|
5237
5240
|
if (e.handler === void 0 && e.workflow === void 0) throw Error(`defineSchedule("${e.name}"): define either handler or workflow`);
|
|
5238
5241
|
return {
|
|
@@ -5242,7 +5245,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
5242
5245
|
maxRuntimeMs: e.maxRuntimeMs ?? il,
|
|
5243
5246
|
[nl]: !0
|
|
5244
5247
|
};
|
|
5245
|
-
}, ol = (e) =>
|
|
5248
|
+
}, ol = (e) => Ze.unsafeParse(e.cron, e.timezone), sl = (e, t = /* @__PURE__ */ new Date()) => Ze.next(ol(e), t), Z = "_voltro_wakeups", cl = (e) => `${e.tenantId}:${e.kind}:${e.refId}`, ll = (e) => ({
|
|
5246
5249
|
tenantId: String(e.tenantId),
|
|
5247
5250
|
kind: String(e.kind),
|
|
5248
5251
|
refId: String(e.refId),
|
|
@@ -5351,7 +5354,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
5351
5354
|
s?.(e, Al(t));
|
|
5352
5355
|
}, _ = async (e, t, r, i, s, c) => {
|
|
5353
5356
|
try {
|
|
5354
|
-
let o = `sr_${
|
|
5357
|
+
let o = `sr_${Se()}`, l = await n.insert(Dl, {
|
|
5355
5358
|
id: o,
|
|
5356
5359
|
name: e.name,
|
|
5357
5360
|
status: i,
|
|
@@ -5409,7 +5412,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
5409
5412
|
reason: Q(t)
|
|
5410
5413
|
}), !1;
|
|
5411
5414
|
}
|
|
5412
|
-
},
|
|
5415
|
+
}, ee = async (e, t, n, r) => {
|
|
5413
5416
|
let a = /* @__PURE__ */ new Date(), s = await _(e, t, a, "running", n, r), l = Date.now(), u, d = new Promise((t, n) => {
|
|
5414
5417
|
u = setTimeout(() => n(/* @__PURE__ */ Error(`schedule "${e.name}" exceeded maxRuntimeMs=${e.maxRuntimeMs}`)), e.maxRuntimeMs);
|
|
5415
5418
|
}), f = {
|
|
@@ -5464,7 +5467,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
5464
5467
|
timeout: n,
|
|
5465
5468
|
...on(t)
|
|
5466
5469
|
};
|
|
5467
|
-
o.error ? o.error("schedule: handler failed", a) : o.warn("schedule: handler failed", a),
|
|
5470
|
+
o.error ? o.error("schedule: handler failed", a) : o.warn("schedule: handler failed", a), We({
|
|
5468
5471
|
error: t,
|
|
5469
5472
|
source: "schedule",
|
|
5470
5473
|
name: e.name,
|
|
@@ -5477,9 +5480,9 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
5477
5480
|
u && clearTimeout(u);
|
|
5478
5481
|
}
|
|
5479
5482
|
return s;
|
|
5480
|
-
},
|
|
5483
|
+
}, b = async (e, t, n, r) => {
|
|
5481
5484
|
if (n !== "manual" && e.onOverlap === "queue") {
|
|
5482
|
-
let i = (p.get(e.name) ?? Promise.resolve()).then(() =>
|
|
5485
|
+
let i = (p.get(e.name) ?? Promise.resolve()).then(() => x(e, t, n, r));
|
|
5483
5486
|
return p.set(e.name, i.catch(() => {})), i;
|
|
5484
5487
|
}
|
|
5485
5488
|
if (n !== "manual" && e.onOverlap === "skip" && (f.has(e.name) || await y(e.name))) {
|
|
@@ -5489,8 +5492,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
5489
5492
|
scope: f.has(e.name) ? "local" : "cluster"
|
|
5490
5493
|
}), i;
|
|
5491
5494
|
}
|
|
5492
|
-
return
|
|
5493
|
-
},
|
|
5495
|
+
return x(e, t, n, r);
|
|
5496
|
+
}, x = async (e, t, n, i) => {
|
|
5494
5497
|
let a;
|
|
5495
5498
|
if (i !== void 0) a = i;
|
|
5496
5499
|
else if (n === "manual") a = "single";
|
|
@@ -5507,13 +5510,13 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
5507
5510
|
}
|
|
5508
5511
|
f.add(e.name);
|
|
5509
5512
|
try {
|
|
5510
|
-
return await
|
|
5513
|
+
return await ee(e, t, n, a);
|
|
5511
5514
|
} finally {
|
|
5512
5515
|
f.delete(e.name);
|
|
5513
5516
|
}
|
|
5514
|
-
},
|
|
5517
|
+
}, S = async (e) => {
|
|
5515
5518
|
try {
|
|
5516
|
-
let t =
|
|
5519
|
+
let t = Ze.next(ol(e), /* @__PURE__ */ new Date());
|
|
5517
5520
|
await ul(n, {
|
|
5518
5521
|
tenantId: u,
|
|
5519
5522
|
kind: "schedule",
|
|
@@ -5526,26 +5529,26 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
5526
5529
|
reason: Q(t)
|
|
5527
5530
|
});
|
|
5528
5531
|
}
|
|
5529
|
-
},
|
|
5532
|
+
}, C = 2147483647, w = (e) => {
|
|
5530
5533
|
if (m) return;
|
|
5531
|
-
let n = ol(e), r =
|
|
5534
|
+
let n = ol(e), r = Ze.next(n, /* @__PURE__ */ new Date()), i = () => {
|
|
5532
5535
|
if (m) return;
|
|
5533
5536
|
let n = r.getTime() - Date.now();
|
|
5534
|
-
if (n >
|
|
5535
|
-
let t = setTimeout(i,
|
|
5537
|
+
if (n > C) {
|
|
5538
|
+
let t = setTimeout(i, C);
|
|
5536
5539
|
d.set(e.name, t);
|
|
5537
5540
|
return;
|
|
5538
5541
|
}
|
|
5539
5542
|
let a = setTimeout(() => {
|
|
5540
|
-
|
|
5543
|
+
b(e, r, e.trigger ?? t.defaultTrigger).catch((t) => o.warn("schedule: fire rejected", {
|
|
5541
5544
|
name: e.name,
|
|
5542
5545
|
reason: Q(t)
|
|
5543
|
-
})).finally(() =>
|
|
5546
|
+
})).finally(() => w(e));
|
|
5544
5547
|
}, Math.max(0, n));
|
|
5545
5548
|
d.set(e.name, a);
|
|
5546
5549
|
};
|
|
5547
5550
|
i();
|
|
5548
|
-
},
|
|
5551
|
+
}, te = async (e) => {
|
|
5549
5552
|
if (e.backfill === "skip") return;
|
|
5550
5553
|
let r;
|
|
5551
5554
|
try {
|
|
@@ -5569,8 +5572,8 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
5569
5572
|
return;
|
|
5570
5573
|
}
|
|
5571
5574
|
if (!r) return;
|
|
5572
|
-
let i = ol(e), a = [], s =
|
|
5573
|
-
for (; s.getTime() < c && a.length < 1e3;) a.push(s), s =
|
|
5575
|
+
let i = ol(e), a = [], s = Ze.next(i, r), c = Date.now();
|
|
5576
|
+
for (; s.getTime() < c && a.length < 1e3;) a.push(s), s = Ze.next(i, s);
|
|
5574
5577
|
if (a.length !== 0) if (o.info("schedule: backfill", {
|
|
5575
5578
|
name: e.name,
|
|
5576
5579
|
missed: a.length,
|
|
@@ -5578,35 +5581,35 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
5578
5581
|
}), e.backfill === "latest") {
|
|
5579
5582
|
for (let n of a.slice(0, -1)) await _(e, n, null, "missed", e.trigger ?? t.defaultTrigger, "single");
|
|
5580
5583
|
let n = a[a.length - 1];
|
|
5581
|
-
await
|
|
5582
|
-
} else for (let n of a) await
|
|
5583
|
-
},
|
|
5584
|
+
await b(e, n, e.trigger ?? t.defaultTrigger);
|
|
5585
|
+
} else for (let n of a) await b(e, n, e.trigger ?? t.defaultTrigger);
|
|
5586
|
+
}, T = e.filter((e) => (e.trigger ?? t.defaultTrigger) === "self");
|
|
5584
5587
|
o.info("scheduler: starting", {
|
|
5585
5588
|
total: e.length,
|
|
5586
|
-
self:
|
|
5587
|
-
external: e.length -
|
|
5589
|
+
self: T.length,
|
|
5590
|
+
external: e.length - T.length,
|
|
5588
5591
|
coordinator: r.kind
|
|
5589
5592
|
});
|
|
5590
|
-
let
|
|
5593
|
+
let ne = (t.armSelf ?? !0) && !l;
|
|
5591
5594
|
if (l) {
|
|
5592
|
-
o.info("scheduler: sleep mode — registering wakeups, not arming timers", { count:
|
|
5593
|
-
for (let e of
|
|
5594
|
-
} else if (
|
|
5595
|
-
for (let e of
|
|
5596
|
-
for (let e of
|
|
5595
|
+
o.info("scheduler: sleep mode — registering wakeups, not arming timers", { count: T.length });
|
|
5596
|
+
for (let e of T) await S(e);
|
|
5597
|
+
} else if (ne) {
|
|
5598
|
+
for (let e of T) await te(e);
|
|
5599
|
+
for (let e of T) w(e);
|
|
5597
5600
|
}
|
|
5598
5601
|
return {
|
|
5599
5602
|
fireNow: async (e, t) => {
|
|
5600
5603
|
let n = h.get(e);
|
|
5601
5604
|
if (!n) throw Error(`scheduler.fireNow: unknown schedule "${e}"`);
|
|
5602
|
-
let r = await
|
|
5603
|
-
return l && await
|
|
5605
|
+
let r = await b(n, /* @__PURE__ */ new Date(), t);
|
|
5606
|
+
return l && await S(n), r;
|
|
5604
5607
|
},
|
|
5605
5608
|
fireFromCluster: async (e) => {
|
|
5606
5609
|
let t = h.get(e);
|
|
5607
5610
|
if (!t) throw Error(`scheduler.fireFromCluster: unknown schedule "${e}"`);
|
|
5608
|
-
let n = await
|
|
5609
|
-
return l && await
|
|
5611
|
+
let n = await b(t, /* @__PURE__ */ new Date(), "self", "cluster");
|
|
5612
|
+
return l && await S(t), n;
|
|
5610
5613
|
},
|
|
5611
5614
|
shutdown: async () => {
|
|
5612
5615
|
m = !0;
|
|
@@ -5648,77 +5651,77 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
5648
5651
|
i || (i = !0, a && clearInterval(a), a = void 0);
|
|
5649
5652
|
}
|
|
5650
5653
|
};
|
|
5651
|
-
}, Ml = (e) => (t, n, r) => jl(t, n, r, e), Nl =
|
|
5654
|
+
}, Ml = (e) => (t, n, r) => jl(t, n, r, e), Nl = D("_voltro_schedule_runs", {
|
|
5652
5655
|
id: y({ prefix: "schrun" }),
|
|
5653
|
-
name:
|
|
5654
|
-
status:
|
|
5656
|
+
name: O(),
|
|
5657
|
+
status: O().oneOf([
|
|
5655
5658
|
"running",
|
|
5656
5659
|
"succeeded",
|
|
5657
5660
|
"failed",
|
|
5658
5661
|
"skipped",
|
|
5659
5662
|
"missed"
|
|
5660
5663
|
]).default("running"),
|
|
5661
|
-
trigger:
|
|
5664
|
+
trigger: O().oneOf([
|
|
5662
5665
|
"self",
|
|
5663
5666
|
"external",
|
|
5664
5667
|
"manual"
|
|
5665
5668
|
]).default("self"),
|
|
5666
|
-
scheduledAt:
|
|
5667
|
-
firedAt:
|
|
5668
|
-
completedAt:
|
|
5669
|
-
durationMs:
|
|
5670
|
-
errorTag:
|
|
5671
|
-
errorMessage:
|
|
5672
|
-
coordinationOutcome:
|
|
5669
|
+
scheduledAt: k(),
|
|
5670
|
+
firedAt: k().nullable(),
|
|
5671
|
+
completedAt: k().nullable(),
|
|
5672
|
+
durationMs: b().nullable(),
|
|
5673
|
+
errorTag: O().nullable(),
|
|
5674
|
+
errorMessage: O().nullable(),
|
|
5675
|
+
coordinationOutcome: O().oneOf([
|
|
5673
5676
|
"single",
|
|
5674
5677
|
"wonLock",
|
|
5675
5678
|
"lostLock",
|
|
5676
5679
|
"external",
|
|
5677
5680
|
"cluster"
|
|
5678
5681
|
]).nullable(),
|
|
5679
|
-
replicaId:
|
|
5680
|
-
result:
|
|
5681
|
-
}).index(["name", "scheduledAt"]).index(["status"]), Pl =
|
|
5682
|
+
replicaId: O().nullable(),
|
|
5683
|
+
result: w().nullable()
|
|
5684
|
+
}).index(["name", "scheduledAt"]).index(["status"]), Pl = D("_voltro_schedule_claims", {
|
|
5682
5685
|
id: y({ prefix: "schclaim" }),
|
|
5683
|
-
scheduleName:
|
|
5684
|
-
bucket:
|
|
5685
|
-
claimedBy:
|
|
5686
|
-
claimedAt:
|
|
5687
|
-
}).index(["scheduleName", "bucket"]).index(["claimedAt"]), Fl =
|
|
5686
|
+
scheduleName: O(),
|
|
5687
|
+
bucket: O(),
|
|
5688
|
+
claimedBy: O(),
|
|
5689
|
+
claimedAt: k()
|
|
5690
|
+
}).index(["scheduleName", "bucket"]).index(["claimedAt"]), Fl = D("_voltro_traces", {
|
|
5688
5691
|
id: y({ prefix: "span" }),
|
|
5689
|
-
traceId:
|
|
5690
|
-
spanId:
|
|
5691
|
-
parentSpanId:
|
|
5692
|
-
name:
|
|
5693
|
-
kind:
|
|
5692
|
+
traceId: O(),
|
|
5693
|
+
spanId: O(),
|
|
5694
|
+
parentSpanId: O().nullable(),
|
|
5695
|
+
name: O(),
|
|
5696
|
+
kind: O().oneOf([
|
|
5694
5697
|
"internal",
|
|
5695
5698
|
"server",
|
|
5696
5699
|
"client",
|
|
5697
5700
|
"producer",
|
|
5698
5701
|
"consumer"
|
|
5699
5702
|
]).default("internal"),
|
|
5700
|
-
status:
|
|
5703
|
+
status: O().oneOf([
|
|
5701
5704
|
"ok",
|
|
5702
5705
|
"error",
|
|
5703
5706
|
"unset"
|
|
5704
5707
|
]).default("unset"),
|
|
5705
|
-
statusMessage:
|
|
5706
|
-
startedAt:
|
|
5707
|
-
endedAt:
|
|
5708
|
-
durationMs:
|
|
5709
|
-
attributes:
|
|
5710
|
-
events:
|
|
5711
|
-
}).index(["traceId", "startedAt"]).index(["startedAt"]).index(["status"]), Il =
|
|
5708
|
+
statusMessage: O().nullable(),
|
|
5709
|
+
startedAt: k(),
|
|
5710
|
+
endedAt: k(),
|
|
5711
|
+
durationMs: b(),
|
|
5712
|
+
attributes: w().nullable(),
|
|
5713
|
+
events: w().nullable()
|
|
5714
|
+
}).index(["traceId", "startedAt"]).index(["startedAt"]).index(["status"]), Il = D("_voltro_undo_log", {
|
|
5712
5715
|
id: y({ prefix: "undo" }),
|
|
5713
|
-
tag:
|
|
5714
|
-
label:
|
|
5715
|
-
subjectId:
|
|
5716
|
-
tenantId:
|
|
5717
|
-
traceId:
|
|
5718
|
-
changes:
|
|
5716
|
+
tag: O(),
|
|
5717
|
+
label: O().nullable(),
|
|
5718
|
+
subjectId: O().nullable(),
|
|
5719
|
+
tenantId: O().nullable(),
|
|
5720
|
+
traceId: O().nullable(),
|
|
5721
|
+
changes: O(),
|
|
5719
5722
|
crossesAction: i().default(!1),
|
|
5720
5723
|
undone: i().default(!1),
|
|
5721
|
-
createdAt:
|
|
5724
|
+
createdAt: k().default("now")
|
|
5722
5725
|
}).index(["subjectId", "createdAt"]), Ll = (e = process.env) => {
|
|
5723
5726
|
let t = (e.VOLTRO_UNDO ?? "").toLowerCase();
|
|
5724
5727
|
return t === "on" || t === "1" || t === "true" ? !0 : t === "off" || t === "0" || t === "false" ? !1 : e.NODE_ENV !== "production";
|
|
@@ -5927,20 +5930,20 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
5927
5930
|
}));
|
|
5928
5931
|
}, ru = async (e, t) => {
|
|
5929
5932
|
let n = await $l(t.store, "_voltro_undo_log", e.invocationId);
|
|
5930
|
-
if (!n) throw new
|
|
5931
|
-
if ((n.subjectId ?? null) !== Zl(t)) throw new
|
|
5933
|
+
if (!n) throw new Le({ invocationId: e.invocationId });
|
|
5934
|
+
if ((n.subjectId ?? null) !== Zl(t)) throw new Ie({ invocationId: e.invocationId });
|
|
5932
5935
|
return n;
|
|
5933
5936
|
}, iu = async (e, t) => {
|
|
5934
5937
|
let n = await ru(e, t);
|
|
5935
5938
|
if (Ql(n.undone)) return { ok: !0 };
|
|
5936
|
-
if (Ql(n.crossesAction)) throw new
|
|
5939
|
+
if (Ql(n.crossesAction)) throw new Fe({
|
|
5937
5940
|
invocationId: e.invocationId,
|
|
5938
5941
|
reason: "action"
|
|
5939
5942
|
});
|
|
5940
5943
|
let r = eu(n.changes);
|
|
5941
5944
|
for (let n of r) {
|
|
5942
5945
|
let r = tu(n);
|
|
5943
|
-
if (r !== void 0 && !Kl(await $l(t.store, n.table, r), n.next ?? null)) throw new
|
|
5946
|
+
if (r !== void 0 && !Kl(await $l(t.store, n.table, r), n.next ?? null)) throw new Fe({
|
|
5944
5947
|
invocationId: e.invocationId,
|
|
5945
5948
|
reason: "conflict"
|
|
5946
5949
|
});
|
|
@@ -6193,14 +6196,14 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6193
6196
|
for (let r of t) n[r] = e[r];
|
|
6194
6197
|
return n;
|
|
6195
6198
|
}
|
|
6196
|
-
}, Du =
|
|
6199
|
+
}, Du = D("_voltro_rebac_tuples", {
|
|
6197
6200
|
id: y({ prefix: "rbct" }),
|
|
6198
|
-
subjectId:
|
|
6199
|
-
relation:
|
|
6200
|
-
resourceType:
|
|
6201
|
-
resourceId:
|
|
6202
|
-
tenantId:
|
|
6203
|
-
createdAt:
|
|
6201
|
+
subjectId: O(),
|
|
6202
|
+
relation: O(),
|
|
6203
|
+
resourceType: O(),
|
|
6204
|
+
resourceId: O(),
|
|
6205
|
+
tenantId: O().nullable(),
|
|
6206
|
+
createdAt: k().default("now")
|
|
6204
6207
|
}).index([
|
|
6205
6208
|
"subjectId",
|
|
6206
6209
|
"resourceType",
|
|
@@ -6226,7 +6229,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6226
6229
|
return (r, i) => {
|
|
6227
6230
|
let a = e[i.tag];
|
|
6228
6231
|
if (a === void 0) return r;
|
|
6229
|
-
let o = n(a.resourceType), s = (e) =>
|
|
6232
|
+
let o = n(a.resourceType), s = (e) => N.fail(new Ws({
|
|
6230
6233
|
action: a.action,
|
|
6231
6234
|
resourceType: a.resourceType,
|
|
6232
6235
|
resourceId: e
|
|
@@ -6239,7 +6242,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6239
6242
|
id: c,
|
|
6240
6243
|
tenantId: i.subject.tenantId
|
|
6241
6244
|
};
|
|
6242
|
-
return
|
|
6245
|
+
return N.flatMap(N.promise(async () => t.loadTuples(l.id, a.resourceType, c)), (e) => $s(l, a.action, u, {
|
|
6243
6246
|
policy: o,
|
|
6244
6247
|
tuples: e
|
|
6245
6248
|
}) ? r : s(c));
|
|
@@ -6296,13 +6299,13 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6296
6299
|
id: a,
|
|
6297
6300
|
via: "agent"
|
|
6298
6301
|
}), await n.dedupe.add(r), "acted");
|
|
6299
|
-
}, Ru =
|
|
6302
|
+
}, Ru = D("_voltro_wakeups", {
|
|
6300
6303
|
id: y({ prefix: "wakeup" }),
|
|
6301
|
-
tenantId:
|
|
6302
|
-
kind:
|
|
6303
|
-
refId:
|
|
6304
|
-
wakeAt:
|
|
6305
|
-
status:
|
|
6304
|
+
tenantId: O(),
|
|
6305
|
+
kind: O(),
|
|
6306
|
+
refId: O(),
|
|
6307
|
+
wakeAt: k(),
|
|
6308
|
+
status: O()
|
|
6306
6309
|
}).index(["status", "wakeAt"]).index(["tenantId"]), zu = async (e) => {
|
|
6307
6310
|
let t = e.now?.() ?? /* @__PURE__ */ new Date(), n = await vl(e.store, t, e.batchLimit ?? 100);
|
|
6308
6311
|
if (n.length === 0) return 0;
|
|
@@ -6424,7 +6427,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6424
6427
|
openConnections: () => t
|
|
6425
6428
|
};
|
|
6426
6429
|
}, qu = (e) => ({ run: async (t) => (e.onActivity?.(), await e.ensureAwake(), t()) }), Ju = (e, t, n, r) => new Promise((i, a) => {
|
|
6427
|
-
let o =
|
|
6430
|
+
let o = lt.request({
|
|
6428
6431
|
host: n,
|
|
6429
6432
|
port: r,
|
|
6430
6433
|
method: e.method,
|
|
@@ -6435,7 +6438,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6435
6438
|
});
|
|
6436
6439
|
o.on("error", a), e.pipe(o);
|
|
6437
6440
|
}), Yu = (e, t, n, r, i) => new Promise((a, o) => {
|
|
6438
|
-
let s =
|
|
6441
|
+
let s = lt.request({
|
|
6439
6442
|
host: r,
|
|
6440
6443
|
port: i,
|
|
6441
6444
|
method: e.method,
|
|
@@ -6453,7 +6456,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6453
6456
|
let t = qu({
|
|
6454
6457
|
ensureAwake: () => e.supervisor.start(),
|
|
6455
6458
|
...e.onActivity === void 0 ? {} : { onActivity: e.onActivity }
|
|
6456
|
-
}), n = e.activity, r =
|
|
6459
|
+
}), n = e.activity, r = lt.createServer((r, i) => {
|
|
6457
6460
|
n?.onRequestStart(), i.on("close", () => n?.onRequestEnd()), t.run(() => Ju(r, i, e.targetHost, e.targetPort)).catch((t) => {
|
|
6458
6461
|
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");
|
|
6459
6462
|
});
|
|
@@ -6545,14 +6548,14 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6545
6548
|
l = !0, u !== void 0 && clearTimeout(u), await new Promise((e) => s.close(() => e()));
|
|
6546
6549
|
}
|
|
6547
6550
|
};
|
|
6548
|
-
}, ed = (e) => e, td = class extends
|
|
6549
|
-
provider:
|
|
6550
|
-
operation:
|
|
6551
|
-
cause:
|
|
6552
|
-
}) {}, nd = class extends
|
|
6553
|
-
provider:
|
|
6554
|
-
capability:
|
|
6555
|
-
}) {}, rd = class extends
|
|
6551
|
+
}, ed = (e) => e, td = class extends L.TaggedError()("AnalyticsError", {
|
|
6552
|
+
provider: L.String,
|
|
6553
|
+
operation: L.String,
|
|
6554
|
+
cause: L.String
|
|
6555
|
+
}) {}, nd = class extends L.TaggedError()("AnalyticsCapabilityNotSupported", {
|
|
6556
|
+
provider: L.String,
|
|
6557
|
+
capability: L.String
|
|
6558
|
+
}) {}, rd = class extends Xe.Tag("@voltro/AnalyticsSink")() {}, id = (e, t) => ({
|
|
6556
6559
|
info: e.info,
|
|
6557
6560
|
track: (n) => e.track(n.tenantId === void 0 ? {
|
|
6558
6561
|
...n,
|
|
@@ -6571,14 +6574,14 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6571
6574
|
tenantId: t
|
|
6572
6575
|
} : n),
|
|
6573
6576
|
...e.mirror === void 0 ? {} : { mirror: e.mirror }
|
|
6574
|
-
}), ad = () =>
|
|
6575
|
-
let e = yield* rd, t = yield*
|
|
6577
|
+
}), ad = () => N.gen(function* () {
|
|
6578
|
+
let e = yield* rd, t = yield* N.serviceOption(Pe), n = ot.match(t, {
|
|
6576
6579
|
onNone: () => null,
|
|
6577
6580
|
onSome: (e) => e.tenantId ?? null
|
|
6578
6581
|
});
|
|
6579
6582
|
return n === null ? e : id(e, n);
|
|
6580
6583
|
}), od = "noop", sd = () => {
|
|
6581
|
-
let e = (e) =>
|
|
6584
|
+
let e = (e) => N.fail(new nd({
|
|
6582
6585
|
provider: od,
|
|
6583
6586
|
capability: e
|
|
6584
6587
|
}));
|
|
@@ -6593,7 +6596,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6593
6596
|
mirror: !1
|
|
6594
6597
|
}
|
|
6595
6598
|
},
|
|
6596
|
-
track: () =>
|
|
6599
|
+
track: () => N.void,
|
|
6597
6600
|
aggregate: () => e("aggregate"),
|
|
6598
6601
|
timeseries: () => e("timeseries"),
|
|
6599
6602
|
topN: () => e("topN")
|
|
@@ -6611,22 +6614,22 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6611
6614
|
mirror: e.some((e) => e.info.capabilities.mirror)
|
|
6612
6615
|
},
|
|
6613
6616
|
detail: { members: e.map((e) => e.info) }
|
|
6614
|
-
}, n = (t) =>
|
|
6617
|
+
}, n = (t) => N.forEach(e, (e) => e.track(t).pipe(N.catchAll((t) => N.logWarning(`analytics-sink ${e.info.provider} track failed`, { err: t }))), {
|
|
6615
6618
|
concurrency: "unbounded",
|
|
6616
6619
|
discard: !0
|
|
6617
6620
|
}), r = (t, n) => {
|
|
6618
6621
|
let r = e.find((e) => e.info.capabilities[t]);
|
|
6619
|
-
return r === void 0 ?
|
|
6622
|
+
return r === void 0 ? N.fail(new nd({
|
|
6620
6623
|
provider: "compose",
|
|
6621
6624
|
capability: t
|
|
6622
6625
|
})) : n(r);
|
|
6623
6626
|
}, i = e.filter((e) => e.mirror !== void 0), a = i.length === 0 ? void 0 : {
|
|
6624
6627
|
tables: Array.from(new Set(i.flatMap((e) => e.mirror.tables))),
|
|
6625
|
-
upsert: (e, t) =>
|
|
6628
|
+
upsert: (e, t) => N.forEach(i.filter((t) => t.mirror.tables.includes(e)), (n) => n.mirror.upsert(e, t), {
|
|
6626
6629
|
concurrency: "unbounded",
|
|
6627
6630
|
discard: !0
|
|
6628
6631
|
}),
|
|
6629
|
-
remove: (e, t) =>
|
|
6632
|
+
remove: (e, t) => N.forEach(i.filter((t) => t.mirror.tables.includes(e)), (n) => n.mirror.remove(e, t), {
|
|
6630
6633
|
concurrency: "unbounded",
|
|
6631
6634
|
discard: !0
|
|
6632
6635
|
})
|
|
@@ -6645,11 +6648,11 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6645
6648
|
kind: "compose",
|
|
6646
6649
|
build: (t) => cd(e.map((e) => e.build(t))),
|
|
6647
6650
|
tables: e.flatMap((e) => e.tables ?? []),
|
|
6648
|
-
initialize: (t) =>
|
|
6651
|
+
initialize: (t) => N.forEach(e, (e) => e.initialize ? e.initialize(t) : N.void, {
|
|
6649
6652
|
concurrency: 1,
|
|
6650
6653
|
discard: !0
|
|
6651
6654
|
}),
|
|
6652
|
-
...t.length > 0 ? { dispose: (e) =>
|
|
6655
|
+
...t.length > 0 ? { dispose: (e) => N.forEach(t, (t) => t.dispose(e), {
|
|
6653
6656
|
concurrency: 1,
|
|
6654
6657
|
discard: !0
|
|
6655
6658
|
}) } : {}
|
|
@@ -6663,18 +6666,18 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6663
6666
|
}, fd = (e) => {
|
|
6664
6667
|
let { store: t, sink: n, log: r } = e, i = n.mirror;
|
|
6665
6668
|
if (i === void 0 || i.tables.length === 0) return dd;
|
|
6666
|
-
let a = e.run ?? ((e) =>
|
|
6669
|
+
let a = e.run ?? ((e) => N.runPromise(e)), o = i.primaryKey ?? "id", s = new Set(i.tables), c = (e) => {
|
|
6667
6670
|
if (e.op === "delete") {
|
|
6668
6671
|
let t = e.old;
|
|
6669
|
-
if (t === null) return
|
|
6672
|
+
if (t === null) return N.void;
|
|
6670
6673
|
let n = t[o];
|
|
6671
|
-
return n === void 0 ?
|
|
6674
|
+
return n === void 0 ? N.void : i.remove(e.table, n);
|
|
6672
6675
|
}
|
|
6673
6676
|
let t = e.new;
|
|
6674
|
-
return t === null ?
|
|
6677
|
+
return t === null ? N.void : i.upsert(e.table, t);
|
|
6675
6678
|
}, l = t.onChange((e) => {
|
|
6676
6679
|
if (!s.has(e.table)) return;
|
|
6677
|
-
let t = c(e).pipe(
|
|
6680
|
+
let t = c(e).pipe(N.catchAll((t) => N.sync(() => r.warn("analytics-mirror: change forward failed", {
|
|
6678
6681
|
provider: n.info.provider,
|
|
6679
6682
|
table: e.table,
|
|
6680
6683
|
op: e.op,
|
|
@@ -6712,15 +6715,15 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6712
6715
|
build: e.build,
|
|
6713
6716
|
...e.incremental === void 0 ? {} : { incremental: e.incremental }
|
|
6714
6717
|
};
|
|
6715
|
-
}, md = (e) => typeof e == "object" && !!e && e._voltroAggregate === !0, hd = class extends
|
|
6716
|
-
name:
|
|
6717
|
-
ageMs:
|
|
6718
|
-
maxAgeMs:
|
|
6719
|
-
}) {}, gd = class extends
|
|
6720
|
-
name:
|
|
6721
|
-
operation:
|
|
6722
|
-
cause:
|
|
6723
|
-
}) {}, vd = class extends
|
|
6718
|
+
}, md = (e) => typeof e == "object" && !!e && e._voltroAggregate === !0, hd = class extends L.TaggedError()("AggregateStale", {
|
|
6719
|
+
name: L.String,
|
|
6720
|
+
ageMs: L.Number,
|
|
6721
|
+
maxAgeMs: L.Number
|
|
6722
|
+
}) {}, gd = class extends L.TaggedError()("AggregateNotFound", { name: L.String }) {}, _d = class extends L.TaggedError()("AggregateError", {
|
|
6723
|
+
name: L.String,
|
|
6724
|
+
operation: L.String,
|
|
6725
|
+
cause: L.String
|
|
6726
|
+
}) {}, vd = class extends Xe.Tag("@voltro/AggregateRegistry")() {}, yd = (e) => N.gen(function* () {
|
|
6724
6727
|
return (yield* vd).getHandle(e);
|
|
6725
6728
|
}), bd = (e, n, r) => {
|
|
6726
6729
|
if (e.crossTenant || !n.has(e.table) || r == null) return e;
|
|
@@ -6731,21 +6734,21 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6731
6734
|
};
|
|
6732
6735
|
}, xd = (e, t, n) => n === "" && !e.crossTenant && t.has(e.table), Sd = (e) => e?.type === "user" && e.tenantId === "", Cd = (e, n) => {
|
|
6733
6736
|
if (e.includeDeleted || !n.has(e.table)) return e;
|
|
6734
|
-
let r =
|
|
6737
|
+
let r = S("deletedAt");
|
|
6735
6738
|
return {
|
|
6736
6739
|
...e,
|
|
6737
6740
|
predicate: e.predicate ? t(e.predicate, r) : r
|
|
6738
6741
|
};
|
|
6739
|
-
}, wd = (e, t) => t, Td = (e) =>
|
|
6740
|
-
if (
|
|
6741
|
-
let t =
|
|
6742
|
-
throw
|
|
6743
|
-
}), Ed = (e, t) => e.pipe(
|
|
6744
|
-
let r = await
|
|
6742
|
+
}, wd = (e, t) => t, Td = (e) => N.runPromiseExit(e).then((e) => {
|
|
6743
|
+
if (tt.isSuccess(e)) return e.value;
|
|
6744
|
+
let t = M.failureOption(e.cause);
|
|
6745
|
+
throw ot.isSome(t) ? t.value : M.squash(e.cause);
|
|
6746
|
+
}), Ed = (e, t) => e.pipe(N.provideService(Pe, t)), Dd = async (e, t, n) => {
|
|
6747
|
+
let r = await N.runPromise(ze(t, e.guards, n));
|
|
6745
6748
|
if (r) throw r;
|
|
6746
6749
|
}, Od = async (e) => {
|
|
6747
|
-
if (
|
|
6748
|
-
let t = await Td(
|
|
6750
|
+
if (Kn() === void 0) return e;
|
|
6751
|
+
let t = await Td(Jn(e.subject, (e) => {
|
|
6749
6752
|
console.error("[voltro] row filter failed to load", e);
|
|
6750
6753
|
}));
|
|
6751
6754
|
return {
|
|
@@ -6756,7 +6759,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6756
6759
|
let t = `${e.kind}.${e.name}`, n = Date.now(), r = "ok";
|
|
6757
6760
|
try {
|
|
6758
6761
|
if (e.interceptor) {
|
|
6759
|
-
let t =
|
|
6762
|
+
let t = N.tryPromise({
|
|
6760
6763
|
try: () => e.runExecutor(),
|
|
6761
6764
|
catch: (e) => e
|
|
6762
6765
|
}), n = e.interceptor(t, {
|
|
@@ -6766,9 +6769,9 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6766
6769
|
subject: e.requestContext.subject,
|
|
6767
6770
|
traceId: e.requestContext.traceId,
|
|
6768
6771
|
...e.requestContext.spanId === void 0 ? {} : { spanId: e.requestContext.spanId }
|
|
6769
|
-
}), r = await
|
|
6770
|
-
if (
|
|
6771
|
-
throw
|
|
6772
|
+
}), r = await N.runPromiseExit(n);
|
|
6773
|
+
if (tt.isSuccess(r)) return r.value;
|
|
6774
|
+
throw M.squash(r.cause);
|
|
6772
6775
|
}
|
|
6773
6776
|
return await e.runExecutor();
|
|
6774
6777
|
} catch (e) {
|
|
@@ -6814,7 +6817,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6814
6817
|
let i = await Od(r), a = [], o = await Fd(async () => (a.length = 0, e.store.transactional(async (o) => {
|
|
6815
6818
|
let s = e.undoCapture?.(o), c = s ? s.tx : o, l = e.buildContext(i, c, { afterCommit: (e) => {
|
|
6816
6819
|
a.push(e);
|
|
6817
|
-
} }), u = t.executor(n, l), d =
|
|
6820
|
+
} }), u = t.executor(n, l), d = N.isEffect(u) ? await e.runEffect(Ed(u, r.subject), l.store) : await u;
|
|
6818
6821
|
return s && await s.persist(l.store, {
|
|
6819
6822
|
tag: t.descriptor.name,
|
|
6820
6823
|
subject: r.subject,
|
|
@@ -6829,13 +6832,13 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6829
6832
|
return t == null ? [] : typeof t == "string" ? [t] : [...t];
|
|
6830
6833
|
}, Bd = (e, t) => (n) => () => {
|
|
6831
6834
|
let r = e.descriptor.guards;
|
|
6832
|
-
return !r || r.length === 0 ? Promise.resolve(null) :
|
|
6835
|
+
return !r || r.length === 0 ? Promise.resolve(null) : N.runPromise(ze(n, r, t));
|
|
6833
6836
|
}, Vd = (e) => (t, n) => (r) => {
|
|
6834
6837
|
let i = e.buildContext(r), a = Bd(t, n)(r.subject), o = async () => {
|
|
6835
6838
|
let i = await a();
|
|
6836
6839
|
if (i) throw i;
|
|
6837
6840
|
let o = e.buildContext(await Od(r)), s = t.executor(n, o);
|
|
6838
|
-
return
|
|
6841
|
+
return N.isEffect(s) ? N.runPromise(e.provideEffect(Ed(s, r.subject), o.store)) : Ld(await Promise.resolve(s));
|
|
6839
6842
|
}, s = (n) => {
|
|
6840
6843
|
let i = Ld(n);
|
|
6841
6844
|
return Rd(i) ? e.finalize(i, r) : {
|
|
@@ -6847,19 +6850,19 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6847
6850
|
};
|
|
6848
6851
|
}, c = () => {
|
|
6849
6852
|
let a = t.executor(n, i);
|
|
6850
|
-
return
|
|
6853
|
+
return N.isEffect(a) ? e.provideEffect(Ed(a, r.subject), i.store).pipe(N.map(s)) : a instanceof Promise ? N.promise(() => a).pipe(N.map(s)) : s(a);
|
|
6851
6854
|
}, l = () => {
|
|
6852
6855
|
let e = t.descriptor.guards;
|
|
6853
|
-
return !e || e.length === 0 ? c() :
|
|
6854
|
-
if (e) return
|
|
6856
|
+
return !e || e.length === 0 ? c() : ze(r.subject, e, n).pipe(N.flatMap((e) => {
|
|
6857
|
+
if (e) return N.fail(e);
|
|
6855
6858
|
let t = c();
|
|
6856
|
-
return
|
|
6859
|
+
return N.isEffect(t) ? t : N.succeed(t);
|
|
6857
6860
|
}));
|
|
6858
6861
|
};
|
|
6859
6862
|
if (!e.interceptor) return l();
|
|
6860
|
-
let u =
|
|
6863
|
+
let u = N.suspend(() => {
|
|
6861
6864
|
let e = l();
|
|
6862
|
-
return
|
|
6865
|
+
return N.isEffect(e) ? e : N.succeed(e);
|
|
6863
6866
|
});
|
|
6864
6867
|
return e.interceptor(u, {
|
|
6865
6868
|
tag: t.descriptor.name,
|
|
@@ -6870,13 +6873,13 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6870
6873
|
...r.spanId === void 0 ? {} : { spanId: r.spanId }
|
|
6871
6874
|
});
|
|
6872
6875
|
}, Hd = (e) => async (t, n, r) => {
|
|
6873
|
-
let i = await Od(r), a = Vd(e)(t, n)(i), o =
|
|
6874
|
-
return
|
|
6876
|
+
let i = await Od(r), a = Vd(e)(t, n)(i), o = N.isEffect(a) ? await Td(a) : a;
|
|
6877
|
+
return ir(o) ? o.value : e.queryRows(o);
|
|
6875
6878
|
}, Ud = (e) => (t, n, r, i) => {
|
|
6876
6879
|
let a = !1, o;
|
|
6877
6880
|
return (async () => {
|
|
6878
6881
|
try {
|
|
6879
|
-
let s = await Od(r), c = Vd(e)(t, n)(s), l =
|
|
6882
|
+
let s = await Od(r), c = Vd(e)(t, n)(s), l = N.isEffect(c) ? await Td(c) : c, u = (e) => i(e), d = ir(l) ? await e.subscribeComputed(l, u, s) : await e.subscribeDescriptor(l, u, s);
|
|
6880
6883
|
a ? d() : o = d;
|
|
6881
6884
|
} catch (e) {
|
|
6882
6885
|
i({
|
|
@@ -6897,7 +6900,7 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
6897
6900
|
runExecutor: async () => {
|
|
6898
6901
|
await Dd(t.descriptor, r.subject, n);
|
|
6899
6902
|
let i = e.buildContext(await Od(r)), a = t.executor(n, i);
|
|
6900
|
-
return
|
|
6903
|
+
return N.isEffect(a) ? e.runEffect(Ed(a, r.subject), i.store) : a;
|
|
6901
6904
|
}
|
|
6902
6905
|
}), Gd = (e) => e instanceof Date ? e.toISOString() : typeof e == "string" && e.length > 0 ? e : null, Kd = (e) => typeof e == "string" && e.length > 0 ? e : null, qd = [
|
|
6903
6906
|
"updatedAt",
|
|
@@ -7013,4 +7016,4 @@ var K = /* @__PURE__ */ new Map(), pr = (e, t) => {
|
|
|
7013
7016
|
return n;
|
|
7014
7017
|
}, nf = "framework-runtime";
|
|
7015
7018
|
//#endregion
|
|
7016
|
-
export { Fa as API_KEYS_TABLE, Ws as AccessDenied, _d as AggregateError, Eu as AggregateMaintainer, gd as AggregateNotFound, vd as AggregateRegistry, hd as AggregateStale, nd as AnalyticsCapabilityNotSupported, td as AnalyticsError, rd as AnalyticsSink, X as CONNECTIONS_TABLE, Uo as CONNECTION_GRANTS_TABLE, qc as CircuitBreaker, Gc as CircuitOpen, fs as ConnectionNotConnected, Gi as DEFAULT_MAX_RPC_BODY_BYTES, us as DEFAULT_REFRESH_SKEW_MS,
|
|
7019
|
+
export { Fa as API_KEYS_TABLE, Ws as AccessDenied, _d as AggregateError, Eu as AggregateMaintainer, gd as AggregateNotFound, vd as AggregateRegistry, hd as AggregateStale, nd as AnalyticsCapabilityNotSupported, td as AnalyticsError, rd as AnalyticsSink, X as CONNECTIONS_TABLE, Uo as CONNECTION_GRANTS_TABLE, qc as CircuitBreaker, Gc as CircuitOpen, fs as ConnectionNotConnected, Gi as DEFAULT_MAX_RPC_BODY_BYTES, us as DEFAULT_REFRESH_SKEW_MS, Un as DEFAULT_ROW_FILTER_RETRY, Cl as DORMANCY_WAKEUP_TENANT, Qr as DeleteBuilder, tr as Dispatcher, Xa as EffectStore, ws as GRANT_TTL_MS, rn as InMemoryDataStore, Gt as IndexedMatcher, Rt as LinearScanMatcher, it as MetricBoundaries, od as NOOP_ANALYTICS_PROVIDER, qn as NO_ROW_FILTER, Gr as NoRowFound, Oo as OUTBOX_ATTEMPTS_TABLE, Fo as OUTBOX_ATTEMPT_LOG_CAP, Y as OUTBOX_TABLE, Kr as OptimisticLockError, Us as REBAC_ADMIN_SCOPE, ds as REFRESH_LEASE_MS, nf as RUNTIME_NAME, Iu as ReactionRateLimiter, yi as ReplicatedDataStore, Hn as RowFilterUnavailable, Sl as SCHEDULE_SUBJECT, Ya as SYSTEM_SUBJECT, Xr as SelectBuilder, hc as SsrfBlockedError, ti as StoreOperationFailed, Jt as SubscriptionRegistry, ni as TableValidationFailed, ei as TenantScopeViolation, fu as TimelineRecorder, Gl as UndoBoundaryError, ql as UndoStack, Zr as UpdateBuilder, Sc as VOLTRO_AUDIT_MIXIN_ID, Cc as VOLTRO_SOFT_DELETE_MIXIN_ID, wc as VOLTRO_TENANT_MIXIN_ID, oo as WorkflowPayloadError, gr as _connectionStreamCount, _r as _resetConnectionSubjectsForTest, Go as _voltroConnectionGrantsTable, Ho as _voltroConnectionsTable, Du as _voltroRebacTuplesTable, Pl as _voltroScheduleClaimsTable, Nl as _voltroScheduleRunsTable, Fl as _voltroTracesTable, Il as _voltroUndoLogTable, Ru as _voltroWakeupsTable, Co as _voltroWorkflowEventDeliveriesTable, So as _voltroWorkflowEventsTable, ci as actingUserId, Ja as apiKeyManagementRoutes, ai as applyDefined, wu as applyDelta, Yl as applyInverse, Xl as applyInverses, Zn as applyRowFilter, Qn as applyRowFilterToDescriptor, Cd as applySoftDeleteScope, bd as applyTenantScope, iu as applyUndoInvocation, ec as assertCan, Yo as assertConnectionCipherConfigured, fd as attachAnalyticsMirror, ea as awaitServerListening, Po as backoffMs, Os as beginOAuthConnect, lr as bindConnectionSubject, Wi as bindMutation, Ii as bindStream, Fi as bindSubscription, Ai as bindSubscriptionUntyped, Su as buildIvmState, $d as buildPreview, Au as buildRebacInterceptor, Mu as buildRebacReadFilter, pi as buildSubjectKey, aa as buildTracingLayer, Uc as cacheScopeLeaks, ba as cachedBackend, $s as can, dl as cancelWakeup, vu as classifyShape, gs as clearConnectionRefreshFlights, Ys as clearResourcePolicies, a as clearRetentions, Xc as clearSystemStoreHandle, ol as compileCron, ks as completeOAuthConnect, ld as composeAnalytics, cd as composeAnalyticsSinks, Ts as connectionCallbackPath, Jo as connectionLabel, vr as connectionSubjectsSnapshot, Zu as countRunningWorkflows, In as counter, Rc as crud, ac as currentRequestLoader, vi as currentRoutingContext, Tr as currentTraceContext, Ga as dataStoreApiKeyStore, Da as dataStoreIdempotencyStore, Ma as dataStoreKvStore, Mr as decryptField, pd as defineAggregate, qo as defineConnection, _o as defineEventTrigger, wd as defineExecutor, jo as defineOutboxHandler, Nu as defineReaction, Ks as defineResourcePolicy, al as defineSchedule, ed as defineSubscriber, $n as deliveredRowCount, Er as deriveKey, Qd as diffChange, Qi as drainForShutdown, zo as drainOutbox, vl as dueWakeups, Qs as effectiveRelations, kc as emptySchemaRegistry, Rr as enableGraphObservation, q as encryptField, ic as enterRequestLoader, ma as envSecretsBackend, cs as exchangeAuthorizationCode, Sr as externalSpanFromTraceparent, on as extractDbCause, qt as fingerprintFor, is as forgetCredential, Wc as formatCacheScopeLeaks, Hc as formatServerOnlyLeaks, br as formatTraceparent, Jl as forwardChangeFromCdc, Ka as frameworkApiKeyStrategy, Ln as gauge, La as generateApiKeyToken, Ns as getConnectionResolver, ur as getConnectionSubject, K as getFieldCipher, qs as getResourcePolicy, Kn as getRowFilter, Zc as getSystemStoreHandle, mu as getTimelineRecorder, uc as getTupleSource, $ as groupKeyOf, Rn as histogramMetric, Xd as historyProvenance, xa as httpSecretsBackend, It as inspectWorkflow, dc as installPolicyGuardResolver, hr as interruptConnectionStreams, Ul as invertChange, md as isAggregateDefinition, xd as isEmptyTenantScopedRead, sn as isForeignKeyViolation, Wu as isIdleNow, Vi as isInfraError, zr as isObservingGraph, Sd as isOrglessUserSubject, Kl as isSafeToApply, rl as isScheduleDefinition, vo as isWorkflowEventTriggerDefinition, xu as ivmValue, Yd as lastWriteProvenance, as as listConnectionStates, Js as listResourcePolicies, te as listRetentions, Ou as loadResourceTuples, ju as loadSubjectTuples, $c as localityAwareSelector, Wd as makeActionRunner, El as makeAdvisoryLockCoordinator, Dr as makeAesCipher, Ba as makeApiKeyService, xc as makeApiKeyUsageBuffer, Wa as makeApiKeyUsageFlusher, cn as makeAppAccess, Na as makeAsyncKv, pa as makeBufferingSpanProcessor, Xo as makeConnectionRegistry, Fs as makeConnectionResolver, Is as makeConnectionsFacade, Ml as makeCoordinatedScheduler, pc as makeDataLoader, Hs as makeDisconnectConnectionExecutor, $a as makeEffectStoreLayer, wo as makeEventsFacade, Or as makeFieldCipher, $r as makeFluentStore, Gu as makeIdleGate, po as makeLazyWorkflowFacade, zs as makeListConnectionsExecutor, Id as makeMutationRunner, Hd as makeOneShotQueryRunner, No as makeOutboxFacade, uo as makePostCommitWorkflowFacade, Vu as makeProcessAdapter, Vd as makeQueryDescriptorProducer, Bd as makeQueryReauthorizer, Ud as makeQuerySubscriber, Ku as makeRouterActivity, Tc as makeSchemaRegistry, Bs as makeStartConnectionExecutor, Vs as makeSubmitTokenExecutor, Vl as makeUndoCapture, qu as makeWakeGate, Xu as makeWakeProxyServer, lo as makeWorkflowFacade, fo as makeWorkflowFacadeWithCallerContext, mo as makeWorkflowHandlers, ho as makeWorkflowLayers, no as makeWorkflowRunHandle, fl as markWakeupFired, Cu as materializeIvm, Va as memoryApiKeyStore, tl as memoryReplicationAdapter, fi as memoryRywPositionStore, sl as nextFiring, yl as nextWakeup, Uu as nodeProcessSupervisor, sd as noopAnalytics, ud as noopAnalyticsSpec, Pa as noopKv, Wr as observeStore, Hr as observedGraph, fr as onBindConnectionSubject, Xi as onProcessShutdown, Ao as outboxAttemptsTable, Do as outboxTable, xr as parseTraceparent, so as payloadPropertyNames, ui as powerOfTwoSelector, tf as previewInRollback, es as projectConnectionState, xl as pruneWakeups, Xs as rebacPolicyGraph, jn as recordSample, Fn as recordSubscriptionActive, Nn as recordSubscriptionDelivery, Vr as recordTableAccess, gu as recordTimelineEvent, Pc as redactColumns, lu as redactRow, mi as redisRywPositionStore, au as redoUndoInvocation, ls as refreshAccessToken, mr as registerConnectionStream, ce as registerRetention, ul as registerWakeup, hl as releaseWakeup, di as replicaHealth, Mi as resetComputedQueryCacheWarnings, Ur as resetObservedGraph, _a as resetSecretsBackend, ys as resolveConnection, Ps as resolveConnectionForSubject, el as resolveCurrentRegion, ln as resolveDependentTables, Ds as resolveRedirectUri, Tu as resolveRescan, Jn as resolveRowFilterScope, Yn as resolveRowFilterScopeFor, va as resolveSecret, ya as resolveSecretSync, Sa as resolveSecretsBackend, ou as resolveTimelineMode, ue as retentionTtlMsFromEnv, du as reverseEventOverRows, nc as revokedIds, Qc as runAsSystem, Qu as runOrchestratorTick, Td as runProvidedEffect, Lu as runReaction, $u as runSingleNodeOrchestrator, Bu as runWakeLoop, Fd as runWithDeadlockRetry, Br as runWithObservedProcedure, oc as runWithRequestLoader, _i as runWithRoutingContext, wr as runWithTraceContext, Es as sanitizeRedirectTo, jl as scheduleCoordinated, zc as schemaPropertyNames, Vc as serverOnlyLeaks, Ms as setConnectionResolver, Ar as setFieldCipher, Gn as setRowFilter, ga as setSecretsBackend, Yc as setSystemStoreHandle, hu as setTimelineRecorderForTest, lc as setTupleSource, Ia as sha256Hex, wl as singleCoordinator, Bn as snapshotMetrics, Vn as snapshotMetricsSync, bc as ssrfGuardHttpClientLayer, yc as ssrfReason, Ki as startRpcServer, Ol as startScheduler, ns as storeCredential, As as sweepExpiredGrants, ge as sweepRetention, Wl as synthesizeInverse, mc as tracingHttpClientLayer, go as triggerWorkflow, ml as tryClaimWakeup, dr as unbindConnectionSubject, Ll as undoCaptureEnabled, nu as undoLogExecutor, yd as useAggregate, ad as useAnalytics, tc as visibleRows, zu as wakeDueOnce, Od as withRowFilter, eo as workflowToRpc, Bl as wrapCaptureStore, jc as wrapStoreWithBootCodec, li as wrapStoreWithMixinBehaviour };
|