@voltro/runtime 0.85.0 → 0.87.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 +5987 -0
- package/README.md +43 -0
- package/THIRD-PARTY-NOTICES.md +864 -253
- package/dist/aggregate.js +42 -0
- package/dist/aggregateExtrema.js +80 -0
- package/dist/aggregateIvm.js +115 -0
- package/dist/analyticsMirror.js +228 -0
- package/dist/analyticsSink.js +32 -0
- package/dist/apiKeyUsage.js +33 -0
- package/dist/apiKeys.js +227 -0
- package/dist/apiKeysWiring.js +114 -0
- package/dist/apiRoleBucketSampler.js +64 -0
- package/dist/apiRoleWorkloadHistory.js +56 -0
- package/dist/apiRoleWorkloadMetrics.js +78 -0
- package/dist/apiRoleWorkloadStorage.js +95 -0
- package/dist/approvalBuiltins.js +10 -0
- package/dist/approvals.js +262 -0
- package/dist/authMiddlewareLayer.js +48 -0
- package/dist/bindEvent.js +92 -0
- package/dist/bootListener.js +143 -0
- package/dist/bootRefusal.js +7 -0
- package/dist/bootStoreCodec.js +71 -0
- package/dist/businessRules.js +67 -0
- package/dist/changeClaimsTable.js +12 -0
- package/dist/circuitBreaker.js +1 -0
- package/dist/columnOnUpdate.js +23 -0
- package/dist/composeAnalytics.js +129 -0
- package/dist/computedQuery.js +4 -0
- package/dist/computedQueryCache.js +231 -0
- package/dist/connectionBuiltins.js +81 -0
- package/dist/connectionCredentials.js +66 -0
- package/dist/connectionState.js +34 -0
- package/dist/connectionVault.js +410 -0
- package/dist/connectionsFacade.js +56 -0
- package/dist/coordinatedSchedule.js +145 -0
- package/dist/crdtHistory.js +138 -0
- package/dist/crdtMerge.js +179 -0
- package/dist/crdtVersionsTable.js +25 -0
- package/dist/credentialBound.js +12 -0
- package/dist/crud.js +72 -0
- package/dist/dataStore.js +712 -0
- package/dist/dataloader.js +61 -0
- package/dist/declaredTablesGuard.js +49 -0
- package/dist/defineExecutor.js +4 -0
- package/dist/dependencyGraph.js +32 -0
- package/dist/devices.js +228 -0
- package/dist/devicesWiring.js +168 -0
- package/dist/dialectReplicationAdapter.js +29 -0
- package/dist/dispatcher.js +522 -0
- package/dist/effectStore.js +71 -0
- package/dist/engineClients.js +24 -0
- package/dist/eventBus.js +260 -0
- package/dist/eventPublish.js +49 -0
- package/dist/events.js +193 -0
- package/dist/expectation.js +52 -0
- package/dist/expectationEvaluator.js +308 -0
- package/dist/experiment.js +96 -0
- package/dist/experimentEvaluator.js +245 -0
- package/dist/externalizedTasks.js +38 -0
- package/dist/fieldCipher.js +130 -0
- package/dist/fieldKeyRegistry.js +295 -0
- package/dist/fieldKeyRekey.js +286 -0
- package/dist/fieldKeyScan.js +136 -0
- package/dist/fieldKeyring.js +77 -0
- package/dist/fingerprint.js +21 -0
- package/dist/finops.js +42 -0
- package/dist/finopsAccountant.js +216 -0
- package/dist/handlerBody.js +8 -0
- package/dist/healthProbes.js +55 -0
- package/dist/hot.d.ts +56 -0
- package/dist/hot.js +3 -0
- package/dist/hotDataStore.js +148 -0
- package/dist/hotDataStoreSnapshot.js +98 -0
- package/dist/hotDataStoreTables.js +18 -0
- package/dist/http-range.d.ts +53 -0
- package/dist/http-range.js +52 -0
- package/dist/httpClientSsrf.js +24 -0
- package/dist/httpClientTracing.js +14 -0
- package/dist/httpCompression.js +76 -0
- package/dist/httpInputStream.js +82 -0
- package/dist/httpKeepAlive.js +12 -0
- package/dist/httpRouteMounts.js +48 -0
- package/dist/idempotencyStore.js +110 -0
- package/dist/idleDetector.js +21 -0
- package/dist/index.d.ts +1249 -517
- package/dist/index.js +155 -15292
- package/dist/insertRequiredColumns.js +19 -0
- package/dist/inspectWorkflow.js +1 -0
- package/dist/instanceMembership.js +98 -0
- package/dist/ivm.js +125 -0
- package/dist/kvDataStore.js +86 -0
- package/dist/kvFacade.js +38 -0
- package/dist/matcher.js +304 -0
- package/dist/memoryColumnDefaults.js +11 -0
- package/dist/memoryQueryJoins.js +114 -0
- package/dist/memorySetOperations.js +43 -0
- package/dist/metrics.js +175 -0
- package/dist/observability.js +123 -0
- package/dist/observedGraph.js +52 -0
- package/dist/originGuard.js +116 -0
- package/dist/outbox.js +352 -0
- package/dist/pluginRefRules.js +65 -0
- package/dist/policyGuardResolver.js +55 -0
- package/dist/preview.js +62 -0
- package/dist/projectedRows.js +12 -0
- package/dist/provenance.js +63 -0
- package/dist/rangeIndex.js +89 -0
- package/dist/rawReadScope.js +17 -0
- package/dist/reaction.js +85 -0
- package/dist/reactiveConfig.js +11 -0
- package/dist/readClassification.js +57 -0
- package/dist/readRecorder.js +67 -0
- package/dist/readScopePredicate.js +12 -0
- package/dist/rebac.js +104 -0
- package/dist/rebacInterceptor.js +81 -0
- package/dist/registry.js +29 -0
- package/dist/relevantFields.js +65 -0
- package/dist/replicaHealth.js +42 -0
- package/dist/replicaLocality.js +44 -0
- package/dist/replicaObservations.js +121 -0
- package/dist/replicaSelection.js +32 -0
- package/dist/replicatedDataStore.js +257 -0
- package/dist/requestLoader.js +7 -0
- package/dist/resumeCensus.js +28 -0
- package/dist/revalidation.js +22 -0
- package/dist/rowFilter.js +82 -0
- package/dist/rowStateBytes.js +45 -0
- package/dist/rpcBodyCap.js +63 -0
- package/dist/rpcConnections.js +83 -0
- package/dist/rpcDefectDiagnostics.js +15 -0
- package/dist/rpcServer.js +1065 -0
- package/dist/rpcWorkloadAdmission.js +50 -0
- package/dist/runAsSystem.js +23 -0
- package/dist/rywPositionStore.js +119 -0
- package/dist/schedule.js +23 -0
- package/dist/scheduleBackfillRequests.js +151 -0
- package/dist/scheduleClaimsTable.js +11 -0
- package/dist/scheduleRunsTable.js +37 -0
- package/dist/scheduler.js +840 -0
- package/dist/schemaRegistry.js +65 -0
- package/dist/secretsResolver.js +35 -0
- package/dist/securityHeaders.js +33 -0
- package/dist/servePipeline.js +374 -0
- package/dist/serverOnlyAudit.js +66 -0
- package/dist/serverTracer.js +15 -0
- package/dist/serviceCredentials.js +40 -0
- package/dist/setReadScopes.js +28 -0
- package/dist/singleNodeOrchestrator.js +91 -0
- package/dist/snapshotValueCodec.js +46 -0
- package/dist/sourceResolution.js +52 -0
- package/dist/storeMiddleware.js +882 -0
- package/dist/storeQuery.js +204 -0
- package/dist/storeRead.js +10 -0
- package/dist/subscriber.js +8 -0
- package/dist/subscriptionOutbox.js +139 -0
- package/dist/subscriptionRegistry.js +82 -0
- package/dist/subscriptionResume.js +132 -0
- package/dist/subscriptionSocketMetrics.js +65 -0
- package/dist/systemSubject.js +5 -0
- package/dist/tenantScope.js +11 -0
- package/dist/tenantSelection.js +27 -0
- package/dist/timeline.js +105 -0
- package/dist/traceContext.js +5 -0
- package/dist/traceSink.js +63 -0
- package/dist/traceSpansTable.js +29 -0
- package/dist/traceparent.js +23 -0
- package/dist/transactionSubject.js +12 -0
- package/dist/trustedProxy.js +155 -0
- package/dist/undo.js +129 -0
- package/dist/undoBuiltins.js +69 -0
- package/dist/undoCapture.js +74 -0
- package/dist/undoLogTable.js +16 -0
- package/dist/upsertBinding.js +20 -0
- package/dist/wakeOrchestrator.js +34 -0
- package/dist/wakeRegistry.js +71 -0
- package/dist/wakeRouter.js +63 -0
- package/dist/wakeSupervisor.js +62 -0
- package/dist/wakeupsTable.js +12 -0
- package/dist/webSocketGatewayRuntime.js +154 -0
- package/dist/webhookVerification.js +18 -0
- package/dist/wireColumnStrip.js +84 -0
- package/dist/workflowReadBuiltins.js +87 -0
- package/dist/workflowRuntime.js +708 -0
- package/package.json +19 -7
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { evaluatePredicate as e, getTable as t, isColumnReference as n, preparePredicate as r } from "@voltro/database";
|
|
2
|
+
//#region src/memoryQueryJoins.ts
|
|
3
|
+
var i = (e) => e == null || typeof e == "string" || typeof e == "boolean" || typeof e == "bigint" || typeof e == "number" && !Number.isNaN(e), a = (e, t = /* @__PURE__ */ new WeakSet()) => {
|
|
4
|
+
if (typeof e != "object" || !e || Object.getPrototypeOf(e) !== Object.prototype || t.has(e)) return !1;
|
|
5
|
+
t.add(e);
|
|
6
|
+
for (let t of Reflect.ownKeys(e)) {
|
|
7
|
+
let n = Object.getOwnPropertyDescriptor(e, t);
|
|
8
|
+
if (n === void 0 || !("value" in n)) return !1;
|
|
9
|
+
}
|
|
10
|
+
if ("not" in e) return a(e.not, t);
|
|
11
|
+
let n = "and" in e ? e.and : "or" in e ? e.or : void 0;
|
|
12
|
+
if (!("and" in e) && !("or" in e)) return !0;
|
|
13
|
+
if (!Array.isArray(n) || Object.getPrototypeOf(n) !== Array.prototype || Object.getOwnPropertyDescriptor(n, "forEach") !== void 0) return !1;
|
|
14
|
+
for (let e = 0; e < n.length; e += 1) {
|
|
15
|
+
let r = Object.getOwnPropertyDescriptor(n, String(e));
|
|
16
|
+
if (r === void 0 || !("value" in r) || !a(r.value, t)) return !1;
|
|
17
|
+
}
|
|
18
|
+
return !0;
|
|
19
|
+
}, o = (e, t) => {
|
|
20
|
+
if ("and" in e) {
|
|
21
|
+
let n = [];
|
|
22
|
+
for (let r = 0; r < e.and.length; r += 1) n.push(...o(e.and[r], t));
|
|
23
|
+
return n;
|
|
24
|
+
}
|
|
25
|
+
if (!("op" in e) || e.op !== "eq" || e.path !== void 0 || !n(e.value)) return [];
|
|
26
|
+
let r = e.column, i = e.value.column, a = `${t}.`;
|
|
27
|
+
return r.startsWith(a) === i.startsWith(a) ? [] : [r.startsWith(a) ? [i, r] : [r, i]];
|
|
28
|
+
}, s = (n, s, c, l) => {
|
|
29
|
+
let u = n.alias ?? n.table, d = (n.sourceTable?.tableName === n.table ? n.sourceTable : t(n.table))?.fields ?? {}, f = new Set(Object.keys(d));
|
|
30
|
+
for (let e of s) for (let t of Object.keys(e)) f.add(t);
|
|
31
|
+
let p = [...f], m = typeof u == "string" && s.length >= 16 ? p.map((e) => [e, `${u}.${e}`]) : void 0, h = { ...d };
|
|
32
|
+
for (let [e, t] of Object.entries(d)) h[`${u}.${e}`] = t;
|
|
33
|
+
let g = /* @__PURE__ */ new Set([u]), _ = (e) => {
|
|
34
|
+
let t = {};
|
|
35
|
+
for (let [n, r] of m) {
|
|
36
|
+
let i = e[n] ?? null;
|
|
37
|
+
r in t ? Object.defineProperty(t, r, {
|
|
38
|
+
value: i,
|
|
39
|
+
enumerable: !0,
|
|
40
|
+
writable: !0,
|
|
41
|
+
configurable: !0
|
|
42
|
+
}) : t[r] = i;
|
|
43
|
+
}
|
|
44
|
+
return t;
|
|
45
|
+
}, v = m === void 0 ? s.map((e) => ({
|
|
46
|
+
...e,
|
|
47
|
+
...Object.fromEntries(p.map((t) => [`${u}.${t}`, e[t] ?? null]))
|
|
48
|
+
})) : s.map((e) => ({
|
|
49
|
+
...e,
|
|
50
|
+
..._(e)
|
|
51
|
+
}));
|
|
52
|
+
for (let s of n.joins ?? []) {
|
|
53
|
+
if (g.has(s.alias)) throw Error(`Duplicate query alias: ${s.alias}`);
|
|
54
|
+
g.add(s.alias);
|
|
55
|
+
let u = [...c.get(s.table)?.values() ?? []], d = (s.sourceTable?.tableName === s.table ? s.sourceTable : t(s.table))?.fields ?? {};
|
|
56
|
+
for (let [e, t] of Object.entries(d)) h[`${s.alias}.${e}`] = t;
|
|
57
|
+
let f = new Set(Object.keys(d));
|
|
58
|
+
for (let e of u) for (let t of Object.keys(e)) f.add(t);
|
|
59
|
+
for (let e of n.joinedProjection ?? []) e.source.startsWith(`${s.alias}.`) && f.add(e.source.slice(s.alias.length + 1));
|
|
60
|
+
let p = [...f].map((e) => [e, `${s.alias}.${e}`]), m = u.length < 16 ? (e) => Object.fromEntries(p.map(([t, n]) => [n, e?.[t] ?? null])) : (e) => {
|
|
61
|
+
let t = {};
|
|
62
|
+
for (let [n, r] of p) {
|
|
63
|
+
let i = e?.[n] ?? null;
|
|
64
|
+
r in t ? Object.defineProperty(t, r, {
|
|
65
|
+
value: i,
|
|
66
|
+
enumerable: !0,
|
|
67
|
+
writable: !0,
|
|
68
|
+
configurable: !0
|
|
69
|
+
}) : t[r] = i;
|
|
70
|
+
}
|
|
71
|
+
return t;
|
|
72
|
+
}, _ = u.map(m), y = l(s.on), b, x = _.length * v.length < 16, S = !1, C, w = o(s.on, s.alias), T, E;
|
|
73
|
+
for (let e of w) {
|
|
74
|
+
if (h[e[0]]?.type === "decimal" || h[e[1]]?.type === "decimal" || !_.every((t) => i(t[e[1]]))) continue;
|
|
75
|
+
let t = /* @__PURE__ */ new Map();
|
|
76
|
+
for (let n of _) {
|
|
77
|
+
let r = n[e[1]];
|
|
78
|
+
if (r == null) continue;
|
|
79
|
+
let i = t.get(r);
|
|
80
|
+
i ? i.push(n) : t.set(r, [n]);
|
|
81
|
+
}
|
|
82
|
+
(E === void 0 || t.size > E.size) && (T = e, E = t);
|
|
83
|
+
}
|
|
84
|
+
v = v.flatMap((t) => {
|
|
85
|
+
let n = T === void 0 ? void 0 : t[T[0]], o = E && i(n) ? n == null ? [] : E.get(n) ?? [] : _, c = x ? o.map((e) => ({
|
|
86
|
+
...t,
|
|
87
|
+
...e
|
|
88
|
+
})).filter((t) => e(s.on, t, y, h)) : [];
|
|
89
|
+
if (!x) for (let n of o) {
|
|
90
|
+
let i = {
|
|
91
|
+
...t,
|
|
92
|
+
...n
|
|
93
|
+
};
|
|
94
|
+
if (!S) {
|
|
95
|
+
S = !0;
|
|
96
|
+
let e = Object.getOwnPropertyDescriptor(s, "on");
|
|
97
|
+
e !== void 0 && "value" in e && a(e.value) && (b = r(e.value, y, h));
|
|
98
|
+
}
|
|
99
|
+
(b === void 0 ? e(s.on, i, y, h) : b(i)) && c.push(i);
|
|
100
|
+
}
|
|
101
|
+
return c.length > 0 || s.kind === "inner" ? c : (C ??= m(null), [{
|
|
102
|
+
...t,
|
|
103
|
+
...C
|
|
104
|
+
}]);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
rows: v,
|
|
109
|
+
columns: h,
|
|
110
|
+
project: (e) => n.joinedProjection?.length ? Object.fromEntries(n.joinedProjection.map((t) => [t.outputKey, e[t.source]])) : Object.fromEntries((n.projection ?? p).map((t) => [t, e[t]]))
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
//#endregion
|
|
114
|
+
export { s as memoryQueryJoins };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { decimalEqualityKey as e, getTable as t } from "@voltro/database";
|
|
2
|
+
//#region src/memorySetOperations.ts
|
|
3
|
+
var n = (e, t = !1) => e == null ? ["null"] : e instanceof Date ? t ? ["string", e.toISOString()] : ["date", e.getTime()] : typeof e == "bigint" ? ["bigint", e.toString()] : typeof e == "number" ? t && !Number.isFinite(e) ? ["null"] : ["number", Number.isFinite(e) ? e : String(e)] : typeof e == "object" ? e instanceof ArrayBuffer ? ["bytes", [...new Uint8Array(e)]] : ArrayBuffer.isView(e) ? ["bytes", [...new Uint8Array(e.buffer, e.byteOffset, e.byteLength)]] : Array.isArray(e) ? ["array", e.map((e) => n(e, t))] : ["object", Object.entries(e).filter(([, e]) => e !== void 0).sort(([e], [t]) => e < t ? -1 : +(e > t)).map(([e, r]) => [e, n(r, t)])] : [typeof e, e], r = (t, r, i) => JSON.stringify(r.map((r) => {
|
|
4
|
+
let a = t[r], o = a == null || i[r]?.type !== "decimal" ? null : e(a);
|
|
5
|
+
return o === null ? n(a, i[r]?.type === "json") : ["decimal", o];
|
|
6
|
+
})), i = (e, n) => {
|
|
7
|
+
if (e.setOp) return i(e.setOp.queries[0], n);
|
|
8
|
+
let r = (e.sourceTable ?? t(e.table))?.fields ?? {}, a = { ...r }, o = e.alias ?? e.table;
|
|
9
|
+
for (let [e, t] of Object.entries(r)) a[`${o}.${e}`] = t;
|
|
10
|
+
for (let n of e.joins ?? []) {
|
|
11
|
+
let e = (n.sourceTable ?? t(n.table))?.fields ?? {};
|
|
12
|
+
for (let [t, r] of Object.entries(e)) a[`${n.alias}.${t}`] = r;
|
|
13
|
+
}
|
|
14
|
+
if (e.aggregations?.length) return Object.fromEntries(e.aggregations.map((e) => {
|
|
15
|
+
let t = e.column === void 0 ? { type: "unknown" } : a[e.column] ?? { type: "unknown" }, n = e.op === "count" || e.op === "count-distinct" || e.op === "window-row-number" || e.op === "window-rank" || e.op === "window-dense-rank", r = e.op === "avg" || e.op === "window-avg-over";
|
|
16
|
+
return [e.alias, n ? { type: "integer" } : r && t.type !== "decimal" ? { type: "real" } : t];
|
|
17
|
+
}));
|
|
18
|
+
if (e.joinedProjection) return Object.fromEntries(e.joinedProjection.map((e) => [e.outputKey, a[e.source] ?? { type: "unknown" }]));
|
|
19
|
+
let s = e.projection ?? (Object.keys(r).length > 0 ? Object.keys(r) : [...new Set(n.flatMap((e) => Object.keys(e)))]);
|
|
20
|
+
return Object.fromEntries(s.map((e) => [e, a[e] ?? { type: "unknown" }]));
|
|
21
|
+
}, a = (e, t) => {
|
|
22
|
+
let n = e.setOp;
|
|
23
|
+
if (!n || n.queries.length < 2) throw Error("A set operation requires at least two inputs");
|
|
24
|
+
let a = n.queries.map((e) => ({
|
|
25
|
+
rows: t(e),
|
|
26
|
+
query: e
|
|
27
|
+
})), o = a.map((e) => i(e.query, e.rows)), s = o[0], c = Object.keys(s), l = a.map((e, t) => {
|
|
28
|
+
let n = Object.keys(o[t]);
|
|
29
|
+
if (n.length !== c.length) throw Error("Set operation inputs must have the same column count");
|
|
30
|
+
return e.rows.map((e) => Object.fromEntries(c.map((t, r) => [t, e[n[r]] ?? null])));
|
|
31
|
+
});
|
|
32
|
+
if (n.kind === "union-all") return l.flat();
|
|
33
|
+
let u = (e) => new Map(e.map((e) => [r(e, c, s), e]));
|
|
34
|
+
if (n.kind === "union") return [...u(l.flat()).values()];
|
|
35
|
+
let d = u(l[0]);
|
|
36
|
+
for (let e of l.slice(1)) {
|
|
37
|
+
let t = u(e);
|
|
38
|
+
for (let e of d.keys()) (n.kind === "intersect" ? !t.has(e) : t.has(e)) && d.delete(e);
|
|
39
|
+
}
|
|
40
|
+
return [...d.values()];
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
export { i as memoryOutputColumns, r as memoryRowKey, a as memorySetRows };
|
package/dist/metrics.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { subscriptionSocketMetricSamples as e } from "./subscriptionSocketMetrics.js";
|
|
2
|
+
import { Effect as t, Metric as n } from "effect";
|
|
3
|
+
//#region src/metrics.ts
|
|
4
|
+
var r = n.exponentialBoundaries({
|
|
5
|
+
start: .001,
|
|
6
|
+
factor: 2,
|
|
7
|
+
count: 16
|
|
8
|
+
}), i = n.counter("voltro_rpc_requests_total", { description: "Total RPC handler invocations." }), a = n.counter("voltro_rpc_errors_total", { description: "RPC handler invocations that errored." }), o = n.histogram("voltro_rpc_duration_seconds", {
|
|
9
|
+
boundaries: r,
|
|
10
|
+
description: "RPC handler duration in seconds."
|
|
11
|
+
}), s = n.counter("voltro_http_requests_total", { description: "Total HTTP route invocations." }), c = n.histogram("voltro_http_duration_seconds", {
|
|
12
|
+
boundaries: r,
|
|
13
|
+
description: "HTTP route duration in seconds."
|
|
14
|
+
}), l = n.histogram("voltro_plugin_hook_duration_seconds", {
|
|
15
|
+
boundaries: r,
|
|
16
|
+
description: "Plugin interceptor duration in seconds."
|
|
17
|
+
}), u = n.counter("voltro_plugin_hook_errors_total", { description: "Plugin interceptor invocations that errored." }), d = n.counter("voltro_subscription_deliveries_total", { description: "Total subscription deliveries (snapshot + delta)." }), f = n.histogram("voltro_subscription_delivery_seconds", {
|
|
18
|
+
boundaries: r,
|
|
19
|
+
description: "Subscription delivery produce→push latency in seconds."
|
|
20
|
+
}), p = n.gauge("voltro_subscriptions_active", { description: "Currently-open subscriptions." }), m = n.counter("voltro_schedule_runs_total", { description: "Schedule firings by name + outcome." }), ee = n.histogram("voltro_schedule_duration_seconds", {
|
|
21
|
+
boundaries: r,
|
|
22
|
+
description: "Schedule handler duration in seconds."
|
|
23
|
+
}), h = n.gauge("voltro_schedule_last_success_timestamp_seconds", { description: "UNIX time of the last successful firing, per schedule." }), g = n.gauge("voltro_schedule_queued", { description: "Firings waiting for their turn under onOverlap: 'queue', per schedule, on THIS replica." }), _ = n.histogram("voltro_schedule_queue_wait_seconds", {
|
|
24
|
+
boundaries: r,
|
|
25
|
+
description: "Time a queued firing waited before it started, in seconds."
|
|
26
|
+
}), v = n.counter("voltro_schedule_queue_recoveries_total", { description: "Queued firings whose replica stopped reporting, by what happened to them." }), y = n.counter("voltro_schedule_external_triggers_total", { description: "External trigger arrivals by schedule and decision." }), b = n.counter("voltro_schedule_external_missed_total", { description: "Occurrences of an external schedule that were never triggered." }), x = n.counter("voltro_workflow_runs_total", { description: "Workflow run terminal outcomes by name + status." }), S = n.histogram("voltro_workflow_duration_seconds", {
|
|
27
|
+
boundaries: r,
|
|
28
|
+
description: "Workflow run duration in seconds."
|
|
29
|
+
}), C = n.gauge("voltro_workflow_last_success_timestamp_seconds", { description: "UNIX time of the last successful run, per workflow." }), w = n.counter("voltro_event_published_total", { description: "Events published, by event name." }), T = n.counter("voltro_event_deliveries_total", { description: "Event deliveries handed to a subscriber, by event name." }), E = n.counter("voltro_event_dropped_total", { description: "Event deliveries a subscriber provably lost, by event name + reason." }), D = n.gauge("voltro_event_subscribers", { description: "Currently-attached event subscribers, by event name." }), O = /* @__PURE__ */ new Map(), k = (e, t, r) => {
|
|
30
|
+
let i = O.get(t);
|
|
31
|
+
if (i !== void 0) return i;
|
|
32
|
+
let a = e;
|
|
33
|
+
for (let [e, t] of r) a = n.withAttributes(a, { [e]: t });
|
|
34
|
+
return O.set(t, a), a;
|
|
35
|
+
}, A = () => {
|
|
36
|
+
O.clear();
|
|
37
|
+
}, j = () => O.size, M = (e) => {
|
|
38
|
+
t.runSync(n.update(k(w, `p:${e}`, [["event", e]]), 1));
|
|
39
|
+
}, N = (e, r = 1) => {
|
|
40
|
+
r <= 0 || t.runSync(n.update(k(T, `d:${e}`, [["event", e]]), r));
|
|
41
|
+
}, P = (e, r, i = 1) => {
|
|
42
|
+
i <= 0 || t.runSync(n.update(k(E, `x:${r}:${e}`, [["event", e], ["reason", r]]), i));
|
|
43
|
+
}, te = (e, r) => {
|
|
44
|
+
r !== 0 && t.runSync(n.update(k(D, `s:${e}`, [["event", e]]), r));
|
|
45
|
+
}, F = (e) => {
|
|
46
|
+
let r = e.durationMs / 1e3, d = e.kind === "rpc" ? t.andThen(n.update(i, 1).pipe(t.provideService(n.CurrentMetricAttributes, {
|
|
47
|
+
tag: e.tag,
|
|
48
|
+
status: e.status
|
|
49
|
+
})), t.andThen(n.update(o, r).pipe(t.provideService(n.CurrentMetricAttributes, { tag: e.tag })), e.status === "error" ? n.update(a, 1).pipe(t.provideService(n.CurrentMetricAttributes, { tag: e.tag })) : t.void)) : e.kind === "request" ? t.andThen(n.update(s, 1).pipe(t.provideService(n.CurrentMetricAttributes, {
|
|
50
|
+
route: e.tag,
|
|
51
|
+
status: e.status
|
|
52
|
+
})), n.update(c, r).pipe(t.provideService(n.CurrentMetricAttributes, { route: e.tag }))) : t.andThen(n.update(l, r).pipe(t.provideService(n.CurrentMetricAttributes, { hook: e.tag })), e.status === "error" ? n.update(u, 1).pipe(t.provideService(n.CurrentMetricAttributes, { hook: e.tag })) : t.void);
|
|
53
|
+
t.runSync(d);
|
|
54
|
+
}, I = n.counter("voltro_field_decrypts_total", { description: "Opens of sealed field values, by key id, location (table:column) and outcome." }), L = /* @__PURE__ */ new Map(), R = (e, r, i) => {
|
|
55
|
+
let a = `${e}|${r}`, o = L.get(a) ?? L.set(a, {
|
|
56
|
+
key: e,
|
|
57
|
+
location: r,
|
|
58
|
+
ok: 0,
|
|
59
|
+
failed: 0
|
|
60
|
+
}).get(a);
|
|
61
|
+
o[i] += 1, t.runSync(n.update(k(I, `field|${a}|${i}`, [
|
|
62
|
+
["key", e],
|
|
63
|
+
["location", r],
|
|
64
|
+
["outcome", i]
|
|
65
|
+
]), 1));
|
|
66
|
+
}, z = () => [...L.values()].map((e) => ({ ...e })).sort((e, t) => e.location.localeCompare(t.location) || e.key.localeCompare(t.key)), B = () => {
|
|
67
|
+
L.clear();
|
|
68
|
+
}, V = (e) => e.startsWith("subscription.") ? e.slice(13) : e, H = (e) => {
|
|
69
|
+
let r = V(e.label);
|
|
70
|
+
t.runSync(t.andThen(n.update(d, 1).pipe(t.provideService(n.CurrentMetricAttributes, {
|
|
71
|
+
tag: r,
|
|
72
|
+
kind: e.kind
|
|
73
|
+
})), n.update(f, e.durationMs / 1e3).pipe(t.provideService(n.CurrentMetricAttributes, {
|
|
74
|
+
tag: r,
|
|
75
|
+
kind: e.kind
|
|
76
|
+
}))));
|
|
77
|
+
}, U = /* @__PURE__ */ new Map(), W = (e, r) => {
|
|
78
|
+
let i = V(e), a = Math.max(0, (U.get(i) ?? 0) + r);
|
|
79
|
+
a === 0 ? U.delete(i) : U.set(i, a), t.runSync(n.update(p, a).pipe(t.provideService(n.CurrentMetricAttributes, { tag: i })));
|
|
80
|
+
}, G = (e) => {
|
|
81
|
+
let r = n.update(m, 1).pipe(t.provideService(n.CurrentMetricAttributes, {
|
|
82
|
+
schedule: e.name,
|
|
83
|
+
status: e.status
|
|
84
|
+
})), i = n.update(ee, e.durationMs / 1e3).pipe(t.provideService(n.CurrentMetricAttributes, { schedule: e.name })), a = e.status === "succeeded" && e.completedAtSec !== void 0 ? n.update(h, e.completedAtSec).pipe(t.provideService(n.CurrentMetricAttributes, { schedule: e.name })) : t.void;
|
|
85
|
+
t.runSync(t.andThen(r, t.andThen(i, a)));
|
|
86
|
+
}, K = /* @__PURE__ */ new Map(), q = (e, r) => {
|
|
87
|
+
let i = Math.max(0, (K.get(e) ?? 0) + r);
|
|
88
|
+
i === 0 ? K.delete(e) : K.set(e, i), t.runSync(n.update(g, i).pipe(t.provideService(n.CurrentMetricAttributes, { schedule: e })));
|
|
89
|
+
}, J = (e, r) => {
|
|
90
|
+
t.runSync(n.update(_, r / 1e3).pipe(t.provideService(n.CurrentMetricAttributes, { schedule: e })));
|
|
91
|
+
}, Y = (e, r) => {
|
|
92
|
+
t.runSync(n.update(v, 1).pipe(t.provideService(n.CurrentMetricAttributes, {
|
|
93
|
+
schedule: e,
|
|
94
|
+
outcome: r
|
|
95
|
+
})));
|
|
96
|
+
}, X = (e, r) => {
|
|
97
|
+
t.runSync(n.update(y, 1).pipe(t.provideService(n.CurrentMetricAttributes, {
|
|
98
|
+
schedule: e,
|
|
99
|
+
outcome: r
|
|
100
|
+
})));
|
|
101
|
+
}, Z = (e, r = 1) => {
|
|
102
|
+
r <= 0 || t.runSync(n.update(b, r).pipe(t.provideService(n.CurrentMetricAttributes, { schedule: e })));
|
|
103
|
+
}, Q = (e) => {
|
|
104
|
+
let r = n.update(x, 1).pipe(t.provideService(n.CurrentMetricAttributes, {
|
|
105
|
+
workflow: e.name,
|
|
106
|
+
status: e.status
|
|
107
|
+
})), i = n.update(S, e.durationMs / 1e3).pipe(t.provideService(n.CurrentMetricAttributes, { workflow: e.name })), a = e.status === "succeeded" && e.completedAtSec !== void 0 ? n.update(C, e.completedAtSec).pipe(t.provideService(n.CurrentMetricAttributes, { workflow: e.name })) : t.void;
|
|
108
|
+
t.runSync(t.andThen(r, t.andThen(i, a)));
|
|
109
|
+
}, ne = (e, t) => n.counter(e, t === void 0 ? {} : { description: t }), re = (e, t) => n.gauge(e, t === void 0 ? {} : { description: t }), ie = (e, t = r, i) => n.histogram(e, {
|
|
110
|
+
boundaries: t,
|
|
111
|
+
...i === void 0 ? {} : { description: i }
|
|
112
|
+
}), { exponentialBoundaries: ae, linearBoundaries: oe } = n, $ = n.snapshot.pipe(t.map((e) => e.map((e) => {
|
|
113
|
+
let t = e.id, n = { ...e.attributes ?? {} }, r = e.description === void 0 ? {} : { description: e.description };
|
|
114
|
+
switch (e.type) {
|
|
115
|
+
case "Histogram": return {
|
|
116
|
+
name: t,
|
|
117
|
+
labels: n,
|
|
118
|
+
...r,
|
|
119
|
+
type: "histogram",
|
|
120
|
+
buckets: e.state.buckets.map(([e, t]) => ({
|
|
121
|
+
le: e,
|
|
122
|
+
count: t
|
|
123
|
+
})),
|
|
124
|
+
sum: e.state.sum,
|
|
125
|
+
count: e.state.count
|
|
126
|
+
};
|
|
127
|
+
case "Gauge": return {
|
|
128
|
+
name: t,
|
|
129
|
+
labels: n,
|
|
130
|
+
...r,
|
|
131
|
+
type: "gauge",
|
|
132
|
+
value: Number(e.state.value)
|
|
133
|
+
};
|
|
134
|
+
case "Summary": {
|
|
135
|
+
let i = [];
|
|
136
|
+
for (let [t, n] of e.state.quantiles) n !== void 0 && i.push({
|
|
137
|
+
quantile: t,
|
|
138
|
+
value: n
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
name: t,
|
|
142
|
+
labels: n,
|
|
143
|
+
...r,
|
|
144
|
+
type: "summary",
|
|
145
|
+
sum: e.state.sum,
|
|
146
|
+
count: e.state.count,
|
|
147
|
+
quantiles: i
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
case "Frequency": {
|
|
151
|
+
let i = {};
|
|
152
|
+
for (let [t, n] of e.state.occurrences) i[t] = n;
|
|
153
|
+
return {
|
|
154
|
+
name: t,
|
|
155
|
+
labels: n,
|
|
156
|
+
...r,
|
|
157
|
+
type: "frequency",
|
|
158
|
+
occurrences: i
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
case "Counter": return {
|
|
162
|
+
name: t,
|
|
163
|
+
labels: n,
|
|
164
|
+
...r,
|
|
165
|
+
type: "counter",
|
|
166
|
+
value: Number(e.state.count)
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
})), t.map((t) => {
|
|
170
|
+
let n = e();
|
|
171
|
+
for (let e of n) t.push(e);
|
|
172
|
+
return t;
|
|
173
|
+
})), se = () => t.runSync($);
|
|
174
|
+
//#endregion
|
|
175
|
+
export { ne as counter, j as eventMetricTagCacheSizeForTests, ae as exponentialBoundaries, z as fieldDecryptSnapshot, re as gauge, ie as histogramMetric, oe as linearBoundaries, N as recordEventDelivered, P as recordEventDropped, M as recordEventPublished, te as recordEventSubscribers, Z as recordExternalMissed, X as recordExternalTrigger, R as recordFieldDecrypt, F as recordSample, Y as recordScheduleQueueRecovery, J as recordScheduleQueueWait, q as recordScheduleQueued, G as recordScheduleRun, W as recordSubscriptionActive, H as recordSubscriptionDelivery, Q as recordWorkflowRun, A as resetEventMetricTagCacheForTests, B as resetFieldDecryptCountsForTests, $ as snapshotMetrics, se as snapshotMetricsSync };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { bootRefusal as e } from "./bootRefusal.js";
|
|
2
|
+
import { Context as t, Effect as n, Layer as r, Option as i, Tracer as a } from "effect";
|
|
3
|
+
import { AsyncLocalStorage as o } from "node:async_hooks";
|
|
4
|
+
//#region src/observability.ts
|
|
5
|
+
var s = () => {
|
|
6
|
+
let e = process.env.FRAMEWORK_TRACING?.toLowerCase();
|
|
7
|
+
return e === "console" || e === "otlp" || e === "off" ? e : process.env.OTEL_EXPORTER_OTLP_ENDPOINT || process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ? "otlp" : "off";
|
|
8
|
+
}, c = () => {
|
|
9
|
+
let e = process.env.FRAMEWORK_METRICS?.toLowerCase();
|
|
10
|
+
return e === "console" || e === "otlp" || e === "off" ? e : process.env.OTEL_EXPORTER_OTLP_ENDPOINT || process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT ? "otlp" : "off";
|
|
11
|
+
}, l = (e) => {
|
|
12
|
+
let t = [];
|
|
13
|
+
return e.mode !== "off" && t.push(`trace export is on (mode "${e.mode}" — from FRAMEWORK_TRACING or an OTEL_EXPORTER_OTLP_* endpoint); FRAMEWORK_TRACING=off turns it off`), e.metricsMode !== "off" && t.push(`metrics export is on (mode "${e.metricsMode}" — from FRAMEWORK_METRICS or an OTEL_EXPORTER_OTLP_* endpoint); FRAMEWORK_METRICS=off turns it off`), e.traceSink && t.push(e.traceSinkOrigin ?? "an in-process trace sink is installed"), (e.pluginSpanProcessors > 0 || e.pluginMetricReaders > 0) && t.push("a plugin contributes a span processor or metric reader (an observability plugin such as a vendor exporter); remove the plugin to drop this cause"), t;
|
|
14
|
+
}, u = (e) => [
|
|
15
|
+
"`@effect/opentelemetry` is not installed, and this boot needs the OpenTelemetry SDK because:",
|
|
16
|
+
...e.map((e) => ` - ${e}`),
|
|
17
|
+
"It is an optional peer dependency of @voltro/runtime — needed only for an active tracer layer, and",
|
|
18
|
+
"carrying it unconditionally made every install print unmet-peer warnings for peers it declares and nobody uses.",
|
|
19
|
+
" Install it: pnpm add @effect/opentelemetry",
|
|
20
|
+
" Or remove every cause listed above."
|
|
21
|
+
].join("\n"), d = (t, n = []) => {
|
|
22
|
+
let r = t?.code;
|
|
23
|
+
return r === "ERR_MODULE_NOT_FOUND" || r === "MODULE_NOT_FOUND" ? e(u(n)) : t instanceof Error ? t : Error(String(t));
|
|
24
|
+
}, f = async (e) => {
|
|
25
|
+
let [t, n, r, i, a] = await Promise.all([
|
|
26
|
+
import("@opentelemetry/sdk-trace-base"),
|
|
27
|
+
import("@opentelemetry/sdk-metrics"),
|
|
28
|
+
import("@opentelemetry/exporter-trace-otlp-http"),
|
|
29
|
+
import("@opentelemetry/exporter-metrics-otlp-http"),
|
|
30
|
+
import("@effect/opentelemetry/NodeSdk").catch((t) => {
|
|
31
|
+
throw d(t, e);
|
|
32
|
+
})
|
|
33
|
+
]);
|
|
34
|
+
return {
|
|
35
|
+
sdkTrace: t,
|
|
36
|
+
sdkMetrics: n,
|
|
37
|
+
otlpTrace: r,
|
|
38
|
+
otlpMetrics: i,
|
|
39
|
+
nodeSdk: a
|
|
40
|
+
};
|
|
41
|
+
}, p = (e, t, n) => {
|
|
42
|
+
let { PeriodicExportingMetricReader: r, ConsoleMetricExporter: i, InMemoryMetricExporter: a, AggregationTemporality: o } = e.sdkMetrics;
|
|
43
|
+
if (t === "off") return {
|
|
44
|
+
reader: void 0,
|
|
45
|
+
inMemory: void 0
|
|
46
|
+
};
|
|
47
|
+
if (t === "memory") {
|
|
48
|
+
let e = new a(o.CUMULATIVE);
|
|
49
|
+
return {
|
|
50
|
+
reader: new r({
|
|
51
|
+
exporter: e,
|
|
52
|
+
exportIntervalMillis: n
|
|
53
|
+
}),
|
|
54
|
+
inMemory: e
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
reader: new r({
|
|
59
|
+
exporter: t === "console" ? new i() : new e.otlpMetrics.OTLPMetricExporter(),
|
|
60
|
+
exportIntervalMillis: n
|
|
61
|
+
}),
|
|
62
|
+
inMemory: void 0
|
|
63
|
+
};
|
|
64
|
+
}, m = async (e = {}) => {
|
|
65
|
+
let u = e.mode ?? s(), d = e.metricsMode ?? c(), m = e.extraSpanProcessors ?? [], h = e.extraMetricReaders ?? [];
|
|
66
|
+
if (u === "off" && e.traceSink === void 0 && d === "off" && m.length === 0 && h.length === 0) return {
|
|
67
|
+
layer: r.empty,
|
|
68
|
+
mode: u,
|
|
69
|
+
bufferOnly: !1,
|
|
70
|
+
inMemoryExporter: void 0,
|
|
71
|
+
metricsMode: d,
|
|
72
|
+
inMemoryMetricExporter: void 0
|
|
73
|
+
};
|
|
74
|
+
let g = await f(l({
|
|
75
|
+
mode: u,
|
|
76
|
+
metricsMode: d,
|
|
77
|
+
traceSink: e.traceSink !== void 0,
|
|
78
|
+
traceSinkOrigin: e.traceSinkOrigin,
|
|
79
|
+
pluginSpanProcessors: m.length,
|
|
80
|
+
pluginMetricReaders: h.length
|
|
81
|
+
})), { ConsoleSpanExporter: _, InMemorySpanExporter: v, SimpleSpanProcessor: y, BatchSpanProcessor: b } = g.sdkTrace, x = u === "off", S = e.serviceName ?? process.env.OTEL_SERVICE_NAME ?? "voltro-app", C, w;
|
|
82
|
+
e.spanProcessor ? w = e.spanProcessor : x ? w = void 0 : u === "memory" ? (C = new v(), w = new y(C)) : w = u === "console" ? new y(new _()) : new b(new g.otlpTrace.OTLPTraceExporter());
|
|
83
|
+
let T = [
|
|
84
|
+
...e.traceSink ? [e.traceSink] : [],
|
|
85
|
+
...w ? [w] : [],
|
|
86
|
+
...m
|
|
87
|
+
], E = T.length === 1 ? T[0] : T, { reader: D, inMemory: O } = p(g, d, e.metricExportIntervalMillis ?? (process.env.OTEL_METRIC_EXPORT_INTERVAL ? Number(process.env.OTEL_METRIC_EXPORT_INTERVAL) : 6e4)), k = [...D ? [D] : [], ...h], A = k.length === 0 ? void 0 : k.length === 1 ? k[0] : k, j = {
|
|
88
|
+
serviceName: S,
|
|
89
|
+
...e.serviceVersion ? { serviceVersion: e.serviceVersion } : {},
|
|
90
|
+
...e.resourceAttributes ? { attributes: e.resourceAttributes } : {}
|
|
91
|
+
}, M = g.nodeSdk.layer(() => ({
|
|
92
|
+
resource: j,
|
|
93
|
+
spanProcessor: E,
|
|
94
|
+
...A ? { metricReader: A } : {},
|
|
95
|
+
...e.sampler ? { tracerConfig: { sampler: e.sampler } } : {}
|
|
96
|
+
})), N = new o(), P = (e, t) => e["~effect/Effect/evaluate"](t);
|
|
97
|
+
return {
|
|
98
|
+
layer: r.unwrap(n.map(n.tracer, (e) => {
|
|
99
|
+
let n = e.context;
|
|
100
|
+
return r.succeed(a.Tracer, a.make({
|
|
101
|
+
span(t) {
|
|
102
|
+
let n = i.isNone(t.parent) ? N.getStore() : void 0;
|
|
103
|
+
return e.span(n === void 0 ? t : {
|
|
104
|
+
...t,
|
|
105
|
+
parent: i.some(n),
|
|
106
|
+
root: !1
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
context(e, r) {
|
|
110
|
+
let o = n ?? P, s = i.getOrUndefined(t.getOption(r.context, a.ParentSpan)) ?? N.getStore();
|
|
111
|
+
return s === void 0 ? o(e, r) : N.run(s, () => o(e, r));
|
|
112
|
+
}
|
|
113
|
+
}));
|
|
114
|
+
})).pipe(r.provideMerge(M)),
|
|
115
|
+
mode: u,
|
|
116
|
+
bufferOnly: x,
|
|
117
|
+
inMemoryExporter: C,
|
|
118
|
+
metricsMode: d,
|
|
119
|
+
inMemoryMetricExporter: O
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
//#endregion
|
|
123
|
+
export { m as buildTracingLayer, l as describeOtelReasons, d as otelImportFailure };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { AsyncLocalStorage as e } from "node:async_hooks";
|
|
2
|
+
//#region src/observedGraph.ts
|
|
3
|
+
var t = new e(), n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), i = "\0", a = process.env.VOLTRO_OBSERVE_GRAPH === "1", o = () => {
|
|
4
|
+
a = !0;
|
|
5
|
+
}, s = () => a, c = (e, n) => a ? (r.add(e.tag), t.run(e, n)) : n(), l = (e, r) => {
|
|
6
|
+
if (!a) return;
|
|
7
|
+
let o = t.getStore();
|
|
8
|
+
o !== void 0 && (e.startsWith("_voltro_") || n.add(`${o.tag}${i}${o.kind}${i}${e}${i}${r}`));
|
|
9
|
+
}, u = () => {
|
|
10
|
+
let e = Array(n.size), t = 0;
|
|
11
|
+
for (let r of n) {
|
|
12
|
+
let [n, a, o, s] = r.split(i);
|
|
13
|
+
e[t++] = {
|
|
14
|
+
tag: n,
|
|
15
|
+
kind: a,
|
|
16
|
+
table: o,
|
|
17
|
+
op: s
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
version: 1,
|
|
22
|
+
edges: e.sort((e, t) => e.tag.localeCompare(t.tag) || e.table.localeCompare(t.table) || e.op.localeCompare(t.op)),
|
|
23
|
+
exercised: [...r].sort()
|
|
24
|
+
};
|
|
25
|
+
}, d = () => {
|
|
26
|
+
n.clear(), r.clear();
|
|
27
|
+
}, f = (e) => {
|
|
28
|
+
if (!a) return e;
|
|
29
|
+
let t = Object.create(Object.getPrototypeOf(e));
|
|
30
|
+
for (let n of Reflect.ownKeys(e)) Object.defineProperty(t, n, Object.getOwnPropertyDescriptor(e, n));
|
|
31
|
+
let n = (n, r, i) => {
|
|
32
|
+
let a = e[n];
|
|
33
|
+
if (typeof a != "function") return;
|
|
34
|
+
let o = a;
|
|
35
|
+
t[n] = (...t) => {
|
|
36
|
+
let n = r(t);
|
|
37
|
+
return n !== void 0 && l(n, i), o.apply(e, t);
|
|
38
|
+
};
|
|
39
|
+
}, r = (e) => typeof e[0] == "string" ? e[0] : void 0;
|
|
40
|
+
n("query", (e) => {
|
|
41
|
+
let t = e[0];
|
|
42
|
+
return typeof t?.table == "string" ? t.table : void 0;
|
|
43
|
+
}, "read"), n("insert", r, "insert"), n("insertMany", r, "insert"), n("insertIgnore", r, "insert"), n("insertIgnoreWithOutcome", r, "insert"), n("update", r, "update"), n("updateMany", r, "update"), n("patchJson", r, "update"), n("delete", r, "delete"), n("deleteMany", r, "delete"), n("upsert", r, "upsert");
|
|
44
|
+
let i = e.transactional;
|
|
45
|
+
if (typeof i == "function") {
|
|
46
|
+
let n = i;
|
|
47
|
+
t.transactional = (t) => n.call(e, (e) => t(f(e)));
|
|
48
|
+
}
|
|
49
|
+
return t;
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
export { o as enableGraphObservation, s as isObservingGraph, f as observeStore, u as observedGraph, l as recordTableAccess, d as resetObservedGraph, c as runWithObservedProcedure };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
//#region src/originGuard.ts
|
|
2
|
+
var e = (e) => {
|
|
3
|
+
let t = e.toUpperCase();
|
|
4
|
+
return t !== "GET" && t !== "HEAD" && t !== "OPTIONS";
|
|
5
|
+
}, t = "/_voltro/inspect", n = (e, t) => e === t || e.startsWith(t.endsWith("/") ? t : `${t}/`), r = (e) => {
|
|
6
|
+
let r = [t];
|
|
7
|
+
for (let t of e.webhookPaths ?? []) r.push(t);
|
|
8
|
+
let i = /* @__PURE__ */ new Map();
|
|
9
|
+
for (let t of e.httpRoutes ?? []) {
|
|
10
|
+
let e = t.originGuard === "exempt";
|
|
11
|
+
i.set(t.path, (i.get(t.path) ?? !0) && e);
|
|
12
|
+
}
|
|
13
|
+
for (let [e, t] of i) t && r.push(e);
|
|
14
|
+
return (e) => r.some((t) => n(e, t));
|
|
15
|
+
}, i = {
|
|
16
|
+
"http:": "80",
|
|
17
|
+
"https:": "443",
|
|
18
|
+
"ws:": "80",
|
|
19
|
+
"wss:": "443"
|
|
20
|
+
}, a = (e) => {
|
|
21
|
+
let t = e.trim(), n;
|
|
22
|
+
try {
|
|
23
|
+
n = new URL(t);
|
|
24
|
+
} catch {
|
|
25
|
+
return t.toLowerCase();
|
|
26
|
+
}
|
|
27
|
+
let r = n.protocol.toLowerCase();
|
|
28
|
+
return `${r}//${n.hostname.toLowerCase()}${n.port === "" || n.port === i[r] ? "" : `:${n.port}`}`;
|
|
29
|
+
}, o = (e, t) => {
|
|
30
|
+
if (t === void 0 || t.trim() === "") return !1;
|
|
31
|
+
let n;
|
|
32
|
+
try {
|
|
33
|
+
let t = new URL(e), r = t.protocol.toLowerCase(), a = t.port === "" || t.port === i[r] ? "" : `:${t.port}`;
|
|
34
|
+
n = `${t.hostname.toLowerCase()}${a}`;
|
|
35
|
+
} catch {
|
|
36
|
+
return !1;
|
|
37
|
+
}
|
|
38
|
+
let r = t.trim().toLowerCase(), a = r.lastIndexOf(":");
|
|
39
|
+
if (a > 0 && !r.slice(a + 1).includes("]")) {
|
|
40
|
+
let e = r.slice(a + 1);
|
|
41
|
+
(e === "80" || e === "443") && (r = r.slice(0, a));
|
|
42
|
+
}
|
|
43
|
+
return n === r;
|
|
44
|
+
}, s = /* @__PURE__ */ new Set([
|
|
45
|
+
"localhost",
|
|
46
|
+
"127.0.0.1",
|
|
47
|
+
"::1",
|
|
48
|
+
"0.0.0.0"
|
|
49
|
+
]), c = (e) => {
|
|
50
|
+
let t = e.toLowerCase().replace(/^\[|\]$/g, "");
|
|
51
|
+
return s.has(t) || t.endsWith(".localhost") || t.startsWith("127.");
|
|
52
|
+
}, l = (e, t) => {
|
|
53
|
+
if (t === void 0 || t.trim() === "") return !1;
|
|
54
|
+
let n;
|
|
55
|
+
try {
|
|
56
|
+
n = new URL(e).hostname;
|
|
57
|
+
} catch {
|
|
58
|
+
return !1;
|
|
59
|
+
}
|
|
60
|
+
if (!c(n)) return !1;
|
|
61
|
+
let r = t.trim(), i = r.lastIndexOf(":");
|
|
62
|
+
return i > 0 && !r.slice(i + 1).includes("]") && (r = r.slice(0, i)), c(r);
|
|
63
|
+
}, u = (e) => {
|
|
64
|
+
let { headers: t, config: n } = e;
|
|
65
|
+
if (n.mode === "off") return {
|
|
66
|
+
allowed: !0,
|
|
67
|
+
reason: "guard-off"
|
|
68
|
+
};
|
|
69
|
+
let r = t.origin;
|
|
70
|
+
if (r !== void 0 && r.trim() !== "") {
|
|
71
|
+
if (r.trim().toLowerCase() === "null") return {
|
|
72
|
+
allowed: !1,
|
|
73
|
+
reason: "opaque-origin",
|
|
74
|
+
origin: "null"
|
|
75
|
+
};
|
|
76
|
+
let e = a(r);
|
|
77
|
+
return o(e, t.host) ? {
|
|
78
|
+
allowed: !0,
|
|
79
|
+
reason: "same-origin"
|
|
80
|
+
} : n.allowedOrigins.includes(e) ? {
|
|
81
|
+
allowed: !0,
|
|
82
|
+
reason: "allowlisted"
|
|
83
|
+
} : l(e, t.host) ? {
|
|
84
|
+
allowed: !0,
|
|
85
|
+
reason: "loopback"
|
|
86
|
+
} : {
|
|
87
|
+
allowed: !1,
|
|
88
|
+
reason: "cross-origin",
|
|
89
|
+
origin: e
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
let i = t["sec-fetch-site"];
|
|
93
|
+
if (i !== void 0 && i.trim() !== "") {
|
|
94
|
+
let e = i.trim().toLowerCase();
|
|
95
|
+
return e !== "same-origin" && e !== "none" ? {
|
|
96
|
+
allowed: !1,
|
|
97
|
+
reason: "cross-site-metadata",
|
|
98
|
+
origin: e
|
|
99
|
+
} : {
|
|
100
|
+
allowed: !0,
|
|
101
|
+
reason: "same-origin"
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
allowed: !0,
|
|
106
|
+
reason: "no-browser-origin"
|
|
107
|
+
};
|
|
108
|
+
}, d = (e, t = process.env) => {
|
|
109
|
+
let n = t.VOLTRO_ORIGIN_GUARD?.trim().toLowerCase(), r = e?.mode ?? (n === "off" ? "off" : "same-origin"), i = e?.allowedOrigins;
|
|
110
|
+
return {
|
|
111
|
+
mode: r,
|
|
112
|
+
allowedOrigins: (i !== void 0 && i.length > 0 ? i : (t.VOLTRO_ALLOWED_ORIGINS ?? "").split(",").map((e) => e.trim()).filter((e) => e.length > 0)).map(a)
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
//#endregion
|
|
116
|
+
export { u as classifyRequestOrigin, e as isStateChangingMethod, r as makeOriginGuardExemption, a as normalizeOrigin, d as resolveOriginGuardConfig };
|