@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.
Files changed (184) hide show
  1. package/CHANGELOG.md +5987 -0
  2. package/README.md +43 -0
  3. package/THIRD-PARTY-NOTICES.md +864 -253
  4. package/dist/aggregate.js +42 -0
  5. package/dist/aggregateExtrema.js +80 -0
  6. package/dist/aggregateIvm.js +115 -0
  7. package/dist/analyticsMirror.js +228 -0
  8. package/dist/analyticsSink.js +32 -0
  9. package/dist/apiKeyUsage.js +33 -0
  10. package/dist/apiKeys.js +227 -0
  11. package/dist/apiKeysWiring.js +114 -0
  12. package/dist/apiRoleBucketSampler.js +64 -0
  13. package/dist/apiRoleWorkloadHistory.js +56 -0
  14. package/dist/apiRoleWorkloadMetrics.js +78 -0
  15. package/dist/apiRoleWorkloadStorage.js +95 -0
  16. package/dist/approvalBuiltins.js +10 -0
  17. package/dist/approvals.js +262 -0
  18. package/dist/authMiddlewareLayer.js +48 -0
  19. package/dist/bindEvent.js +92 -0
  20. package/dist/bootListener.js +143 -0
  21. package/dist/bootRefusal.js +7 -0
  22. package/dist/bootStoreCodec.js +71 -0
  23. package/dist/businessRules.js +67 -0
  24. package/dist/changeClaimsTable.js +12 -0
  25. package/dist/circuitBreaker.js +1 -0
  26. package/dist/columnOnUpdate.js +23 -0
  27. package/dist/composeAnalytics.js +129 -0
  28. package/dist/computedQuery.js +4 -0
  29. package/dist/computedQueryCache.js +231 -0
  30. package/dist/connectionBuiltins.js +81 -0
  31. package/dist/connectionCredentials.js +66 -0
  32. package/dist/connectionState.js +34 -0
  33. package/dist/connectionVault.js +410 -0
  34. package/dist/connectionsFacade.js +56 -0
  35. package/dist/coordinatedSchedule.js +145 -0
  36. package/dist/crdtHistory.js +138 -0
  37. package/dist/crdtMerge.js +179 -0
  38. package/dist/crdtVersionsTable.js +25 -0
  39. package/dist/credentialBound.js +12 -0
  40. package/dist/crud.js +72 -0
  41. package/dist/dataStore.js +712 -0
  42. package/dist/dataloader.js +61 -0
  43. package/dist/declaredTablesGuard.js +49 -0
  44. package/dist/defineExecutor.js +4 -0
  45. package/dist/dependencyGraph.js +32 -0
  46. package/dist/devices.js +228 -0
  47. package/dist/devicesWiring.js +168 -0
  48. package/dist/dialectReplicationAdapter.js +29 -0
  49. package/dist/dispatcher.js +522 -0
  50. package/dist/effectStore.js +71 -0
  51. package/dist/engineClients.js +24 -0
  52. package/dist/eventBus.js +260 -0
  53. package/dist/eventPublish.js +49 -0
  54. package/dist/events.js +193 -0
  55. package/dist/expectation.js +52 -0
  56. package/dist/expectationEvaluator.js +308 -0
  57. package/dist/experiment.js +96 -0
  58. package/dist/experimentEvaluator.js +245 -0
  59. package/dist/externalizedTasks.js +38 -0
  60. package/dist/fieldCipher.js +130 -0
  61. package/dist/fieldKeyRegistry.js +295 -0
  62. package/dist/fieldKeyRekey.js +286 -0
  63. package/dist/fieldKeyScan.js +136 -0
  64. package/dist/fieldKeyring.js +77 -0
  65. package/dist/fingerprint.js +21 -0
  66. package/dist/finops.js +42 -0
  67. package/dist/finopsAccountant.js +216 -0
  68. package/dist/handlerBody.js +8 -0
  69. package/dist/healthProbes.js +55 -0
  70. package/dist/hot.d.ts +56 -0
  71. package/dist/hot.js +3 -0
  72. package/dist/hotDataStore.js +148 -0
  73. package/dist/hotDataStoreSnapshot.js +98 -0
  74. package/dist/hotDataStoreTables.js +18 -0
  75. package/dist/http-range.d.ts +53 -0
  76. package/dist/http-range.js +52 -0
  77. package/dist/httpClientSsrf.js +24 -0
  78. package/dist/httpClientTracing.js +14 -0
  79. package/dist/httpCompression.js +76 -0
  80. package/dist/httpInputStream.js +82 -0
  81. package/dist/httpKeepAlive.js +12 -0
  82. package/dist/httpRouteMounts.js +48 -0
  83. package/dist/idempotencyStore.js +110 -0
  84. package/dist/idleDetector.js +21 -0
  85. package/dist/index.d.ts +1249 -517
  86. package/dist/index.js +155 -15292
  87. package/dist/insertRequiredColumns.js +19 -0
  88. package/dist/inspectWorkflow.js +1 -0
  89. package/dist/instanceMembership.js +98 -0
  90. package/dist/ivm.js +125 -0
  91. package/dist/kvDataStore.js +86 -0
  92. package/dist/kvFacade.js +38 -0
  93. package/dist/matcher.js +304 -0
  94. package/dist/memoryColumnDefaults.js +11 -0
  95. package/dist/memoryQueryJoins.js +114 -0
  96. package/dist/memorySetOperations.js +43 -0
  97. package/dist/metrics.js +175 -0
  98. package/dist/observability.js +123 -0
  99. package/dist/observedGraph.js +52 -0
  100. package/dist/originGuard.js +116 -0
  101. package/dist/outbox.js +352 -0
  102. package/dist/pluginRefRules.js +65 -0
  103. package/dist/policyGuardResolver.js +55 -0
  104. package/dist/preview.js +62 -0
  105. package/dist/projectedRows.js +12 -0
  106. package/dist/provenance.js +63 -0
  107. package/dist/rangeIndex.js +89 -0
  108. package/dist/rawReadScope.js +17 -0
  109. package/dist/reaction.js +85 -0
  110. package/dist/reactiveConfig.js +11 -0
  111. package/dist/readClassification.js +57 -0
  112. package/dist/readRecorder.js +67 -0
  113. package/dist/readScopePredicate.js +12 -0
  114. package/dist/rebac.js +104 -0
  115. package/dist/rebacInterceptor.js +81 -0
  116. package/dist/registry.js +29 -0
  117. package/dist/relevantFields.js +65 -0
  118. package/dist/replicaHealth.js +42 -0
  119. package/dist/replicaLocality.js +44 -0
  120. package/dist/replicaObservations.js +121 -0
  121. package/dist/replicaSelection.js +32 -0
  122. package/dist/replicatedDataStore.js +257 -0
  123. package/dist/requestLoader.js +7 -0
  124. package/dist/resumeCensus.js +28 -0
  125. package/dist/revalidation.js +22 -0
  126. package/dist/rowFilter.js +82 -0
  127. package/dist/rowStateBytes.js +45 -0
  128. package/dist/rpcBodyCap.js +63 -0
  129. package/dist/rpcConnections.js +83 -0
  130. package/dist/rpcDefectDiagnostics.js +15 -0
  131. package/dist/rpcServer.js +1065 -0
  132. package/dist/rpcWorkloadAdmission.js +50 -0
  133. package/dist/runAsSystem.js +23 -0
  134. package/dist/rywPositionStore.js +119 -0
  135. package/dist/schedule.js +23 -0
  136. package/dist/scheduleBackfillRequests.js +151 -0
  137. package/dist/scheduleClaimsTable.js +11 -0
  138. package/dist/scheduleRunsTable.js +37 -0
  139. package/dist/scheduler.js +840 -0
  140. package/dist/schemaRegistry.js +65 -0
  141. package/dist/secretsResolver.js +35 -0
  142. package/dist/securityHeaders.js +33 -0
  143. package/dist/servePipeline.js +374 -0
  144. package/dist/serverOnlyAudit.js +66 -0
  145. package/dist/serverTracer.js +15 -0
  146. package/dist/serviceCredentials.js +40 -0
  147. package/dist/setReadScopes.js +28 -0
  148. package/dist/singleNodeOrchestrator.js +91 -0
  149. package/dist/snapshotValueCodec.js +46 -0
  150. package/dist/sourceResolution.js +52 -0
  151. package/dist/storeMiddleware.js +882 -0
  152. package/dist/storeQuery.js +204 -0
  153. package/dist/storeRead.js +10 -0
  154. package/dist/subscriber.js +8 -0
  155. package/dist/subscriptionOutbox.js +139 -0
  156. package/dist/subscriptionRegistry.js +82 -0
  157. package/dist/subscriptionResume.js +132 -0
  158. package/dist/subscriptionSocketMetrics.js +65 -0
  159. package/dist/systemSubject.js +5 -0
  160. package/dist/tenantScope.js +11 -0
  161. package/dist/tenantSelection.js +27 -0
  162. package/dist/timeline.js +105 -0
  163. package/dist/traceContext.js +5 -0
  164. package/dist/traceSink.js +63 -0
  165. package/dist/traceSpansTable.js +29 -0
  166. package/dist/traceparent.js +23 -0
  167. package/dist/transactionSubject.js +12 -0
  168. package/dist/trustedProxy.js +155 -0
  169. package/dist/undo.js +129 -0
  170. package/dist/undoBuiltins.js +69 -0
  171. package/dist/undoCapture.js +74 -0
  172. package/dist/undoLogTable.js +16 -0
  173. package/dist/upsertBinding.js +20 -0
  174. package/dist/wakeOrchestrator.js +34 -0
  175. package/dist/wakeRegistry.js +71 -0
  176. package/dist/wakeRouter.js +63 -0
  177. package/dist/wakeSupervisor.js +62 -0
  178. package/dist/wakeupsTable.js +12 -0
  179. package/dist/webSocketGatewayRuntime.js +154 -0
  180. package/dist/webhookVerification.js +18 -0
  181. package/dist/wireColumnStrip.js +84 -0
  182. package/dist/workflowReadBuiltins.js +87 -0
  183. package/dist/workflowRuntime.js +708 -0
  184. package/package.json +19 -7
@@ -0,0 +1,67 @@
1
+ import { getTable as e } from "@voltro/database";
2
+ import { BusinessRuleViolation as t } from "@voltro/protocol";
3
+ import { log as n } from "@voltro/logger";
4
+ //#region src/businessRules.ts
5
+ var r = (e) => e.startsWith("_voltro"), i = (e) => {
6
+ let t = e?.id;
7
+ return typeof t == "string" ? t : void 0;
8
+ }, a = (e) => {
9
+ let t = /* @__PURE__ */ new Map(), n = (e, n) => {
10
+ if (n == null || r(e)) return;
11
+ let a = i(n);
12
+ a !== void 0 && t.set(`${e}\u0000${a}`, {
13
+ table: e,
14
+ id: a,
15
+ row: n
16
+ });
17
+ };
18
+ return {
19
+ tx: new Proxy(e, { get(e, t, r) {
20
+ if (t === "insert") return async (t, r) => {
21
+ let i = await e.insert.call(e, t, r);
22
+ return n(t, i), i;
23
+ };
24
+ if (t === "update") return async (t, r, i) => {
25
+ let a = await e.update.call(e, t, r, i);
26
+ return n(t, a ?? {
27
+ ...i,
28
+ id: r
29
+ }), a;
30
+ };
31
+ let i = Reflect.get(e, t, r);
32
+ return typeof i == "function" ? i.bind(e) : i;
33
+ } }),
34
+ drain: () => [...t.values()]
35
+ };
36
+ }, o = (e) => {
37
+ if (e !== !0 && e !== void 0) return e === !1 ? {} : e;
38
+ }, s = async (r) => {
39
+ if (r.touched.length === 0) return;
40
+ let i = {
41
+ store: r.store,
42
+ subject: r.subject
43
+ };
44
+ for (let { table: a, row: s } of r.touched) {
45
+ let r = e(a)?.appliedRules;
46
+ if (r !== void 0 && r.length !== 0) for (let e of r) {
47
+ let r = o(await e.predicate(s, i));
48
+ if (r !== void 0) {
49
+ if (e.severity === "warning") n.warn("business rule violated (warning)", {
50
+ rule: e.name,
51
+ table: a,
52
+ ...r.field === void 0 ? {} : { field: r.field },
53
+ ...r.params === void 0 ? {} : { params: r.params }
54
+ });
55
+ else throw new t({
56
+ rule: e.name,
57
+ severity: "error",
58
+ ...r.params === void 0 ? {} : { params: r.params },
59
+ ...r.field === void 0 ? {} : { field: r.field },
60
+ ...r.message === void 0 ? {} : { message: r.message }
61
+ });
62
+ }
63
+ }
64
+ }
65
+ };
66
+ //#endregion
67
+ export { s as evaluateTouchedRules, a as makeRuleCapture };
@@ -0,0 +1,12 @@
1
+ import { id as e, integer as t, table as n, text as r, timestamp as i } from "@voltro/database";
2
+ //#region src/changeClaimsTable.ts
3
+ var a = n("_voltro_change_claims", {
4
+ id: e({ prefix: "chclaim" }),
5
+ scope: r(),
6
+ key: r(),
7
+ claimedBy: r(),
8
+ claimedAt: i(),
9
+ nextSlot: t().default(0)
10
+ }).unique(["scope", "key"]).index(["claimedAt"]);
11
+ //#endregion
12
+ export { a as _voltroChangeClaimsTable };
@@ -0,0 +1 @@
1
+ export { CircuitBreaker, CircuitOpen } from "@voltro/shared";
@@ -0,0 +1,23 @@
1
+ //#region src/columnOnUpdate.ts
2
+ var e = (e) => {
3
+ if (!(e.length < 32 || Object.getPrototypeOf(e) !== Array.prototype || Object.getOwnPropertySymbols(e).length > 0 || Object.hasOwn(e, "includes"))) {
4
+ for (let t = 0; t < e.length; t++) {
5
+ let n = Object.getOwnPropertyDescriptor(e, String(t));
6
+ if (n === void 0 || !("value" in n) || typeof n.value != "string") return;
7
+ }
8
+ return new Set(e);
9
+ }
10
+ }, t = (t, n, r, i = []) => {
11
+ let a = t.tables.get(n)?.onUpdateFields;
12
+ if (a === void 0 || a.size === 0) return r;
13
+ let o = { ...r }, s = a.size >= 32 ? e(i) : void 0;
14
+ for (let [e, t] of a) {
15
+ if (o[e] !== void 0 || (s?.has(e) ?? i.includes(e))) continue;
16
+ t !== "now" && (s = void 0);
17
+ let n = t === "now" ? /* @__PURE__ */ new Date() : t();
18
+ n === void 0 ? delete o[e] : o[e] = n;
19
+ }
20
+ return o;
21
+ };
22
+ //#endregion
23
+ export { t as applyColumnOnUpdate };
@@ -0,0 +1,129 @@
1
+ import { AnalyticsCapabilityNotSupported as e } from "./analyticsSink.js";
2
+ import { Effect as t } from "effect";
3
+ //#region src/composeAnalytics.ts
4
+ var n = "noop", r = () => {
5
+ let r = (r) => t.fail(new e({
6
+ provider: n,
7
+ capability: r
8
+ }));
9
+ return {
10
+ info: {
11
+ provider: n,
12
+ capabilities: {
13
+ track: !0,
14
+ aggregate: !1,
15
+ timeseries: !1,
16
+ topN: !1,
17
+ mirror: !1
18
+ }
19
+ },
20
+ track: () => t.void,
21
+ aggregate: () => r("aggregate"),
22
+ timeseries: () => r("timeseries"),
23
+ topN: () => r("topN")
24
+ };
25
+ }, i = (n) => {
26
+ if (n.length === 0) return r();
27
+ if (n.length === 1) return n[0];
28
+ let i = {
29
+ provider: "compose",
30
+ capabilities: {
31
+ track: n.some((e) => e.info.capabilities.track),
32
+ aggregate: n.some((e) => e.info.capabilities.aggregate),
33
+ timeseries: n.some((e) => e.info.capabilities.timeseries),
34
+ topN: n.some((e) => e.info.capabilities.topN),
35
+ mirror: n.some((e) => e.info.capabilities.mirror)
36
+ },
37
+ detail: { members: n.map((e) => e.info) }
38
+ }, a = (e) => t.forEach(n, (n) => n.track(e).pipe(t.catch((e) => t.logWarning(`analytics-sink ${n.info.provider} track failed`, { err: e }))), {
39
+ concurrency: "unbounded",
40
+ discard: !0
41
+ }), o = (r, i) => {
42
+ let a = n.find((e) => e.info.capabilities[r]);
43
+ return a === void 0 ? t.fail(new e({
44
+ provider: "compose",
45
+ capability: r
46
+ })) : i(a);
47
+ }, s = n.filter((e) => e.mirror !== void 0), c = s.every((e) => {
48
+ let t = Object.getOwnPropertyDescriptor(e, "mirror");
49
+ if (t === void 0 || !("value" in t)) return !1;
50
+ let n = Object.getOwnPropertyDescriptor(t.value, "tables");
51
+ if (n === void 0 || !("value" in n)) return !1;
52
+ let r = n.value;
53
+ if (!Array.isArray(r) || Object.getPrototypeOf(r) !== Array.prototype || r.includes !== Array.prototype.includes || r[Symbol.iterator] !== Array.prototype[Symbol.iterator]) return !1;
54
+ for (let e = 0; e < r.length; e++) {
55
+ let t = Object.getOwnPropertyDescriptor(r, String(e));
56
+ if (t === void 0 || !("value" in t) || typeof t.value != "string") return !1;
57
+ }
58
+ return !0;
59
+ }), l = /* @__PURE__ */ new Map();
60
+ for (let e of c ? s : []) for (let t of new Set(e.mirror.tables)) {
61
+ let n = l.get(t);
62
+ n === void 0 ? l.set(t, [e]) : n.push(e);
63
+ }
64
+ let u = (e) => c ? l.get(e) ?? [] : s.filter((t) => t.mirror.tables.includes(e)), d = s.length === 0 ? void 0 : {
65
+ tables: Array.from(new Set(s.flatMap((e) => e.mirror.tables))),
66
+ upsert: (e) => t.forEach(u(e.table), (t) => t.mirror.upsert(e), {
67
+ concurrency: "unbounded",
68
+ discard: !0
69
+ }),
70
+ remove: (e) => t.forEach(u(e.table), (t) => t.mirror.remove(e), {
71
+ concurrency: "unbounded",
72
+ discard: !0
73
+ }),
74
+ maxVersion: (e) => t.forEach(u(e.table), (t) => t.mirror.maxVersion(e), { concurrency: "unbounded" }).pipe(t.map((e) => {
75
+ let t = null;
76
+ for (let n of e) n !== null && (t = Math.max(t ?? -Infinity, n));
77
+ return t;
78
+ }))
79
+ };
80
+ return {
81
+ info: i,
82
+ track: a,
83
+ aggregate: (e) => o("aggregate", (t) => t.aggregate(e)),
84
+ timeseries: (e) => o("timeseries", (t) => t.timeseries(e)),
85
+ topN: (e) => o("topN", (t) => t.topN(e)),
86
+ ...d === void 0 ? {} : { mirror: d }
87
+ };
88
+ }, a = (e) => {
89
+ let n = [...e], r, a, o = () => t.suspend(() => t.forEach([...r ?? []].reverse(), (e) => e.released ? t.void : (e.released = !0, e.spec.dispose === void 0 ? t.void : t.suspend(() => e.spec.dispose(e.sink)).pipe(t.catchCause(() => t.logWarning("analytics member teardown failed")))), {
90
+ concurrency: 1,
91
+ discard: !0
92
+ })), s = () => t.promise(() => a ??= t.runPromise(o())), c = (e) => {
93
+ if (r !== void 0) throw Error("An analytics composite belongs to one app owner");
94
+ r = [];
95
+ for (let t of n) {
96
+ if (t.sql === "required" && e === void 0) throw Error("Analytics member requires SQL");
97
+ let n = t.sql === "required" ? t.build(e) : t.build();
98
+ r.push({
99
+ spec: t,
100
+ sink: n,
101
+ released: !1
102
+ });
103
+ }
104
+ return i(r.map((e) => e.sink));
105
+ }, l = {
106
+ kind: "compose",
107
+ tables: n.flatMap((e) => e.tables ?? []),
108
+ initialize: () => t.suspend(() => r === void 0 ? t.die(/* @__PURE__ */ Error("Build analytics members before initialization")) : t.forEach(r, (e) => e.spec.initialize === void 0 ? t.void : t.suspend(() => e.spec.initialize(e.sink)), {
109
+ concurrency: 1,
110
+ discard: !0
111
+ }).pipe(t.onError(s))),
112
+ ...n.some((e) => e.dispose !== void 0) ? { dispose: s } : {}
113
+ };
114
+ return n.some((e) => e.sql === "required") ? {
115
+ ...l,
116
+ sql: "required",
117
+ build: (e) => c(e)
118
+ } : {
119
+ ...l,
120
+ sql: "none",
121
+ build: () => c()
122
+ };
123
+ }, o = {
124
+ kind: "noop",
125
+ sql: "none",
126
+ build: () => r()
127
+ };
128
+ //#endregion
129
+ export { n as NOOP_ANALYTICS_PROVIDER, a as composeAnalytics, i as composeAnalyticsSinks, r as noopAnalytics, o as noopAnalyticsSpec };
@@ -0,0 +1,4 @@
1
+ //#region src/computedQuery.ts
2
+ var e = (e) => typeof e == "object" && !!e && e.__voltroComputed === !0;
3
+ //#endregion
4
+ export { e as isComputedQuery };
@@ -0,0 +1,231 @@
1
+ import { canonicalize as e } from "./fingerprint.js";
2
+ import { currentRawReads as t, runWithRawReadScope as n } from "./rawReadScope.js";
3
+ import { classifyRead as r } from "./readClassification.js";
4
+ import { buildSubjectKey as i } from "./rywPositionStore.js";
5
+ import { runWithRoutingContext as a } from "./replicatedDataStore.js";
6
+ import { Effect as o, Option as s, Schema as c } from "effect";
7
+ import { createHash as l } from "node:crypto";
8
+ import { parseRevalidateMs as u, schemaShape as d, shapeDigest as f } from "@voltro/protocol";
9
+ import { AsyncLocalStorage as p } from "node:async_hooks";
10
+ //#region src/computedQueryCache.ts
11
+ var m = Symbol.for("@voltro/runtime:computed-query-cache-capture"), h = () => {
12
+ let e = globalThis, t = e[m];
13
+ return t === void 0 && (t = {
14
+ storage: new p(),
15
+ installed: !1
16
+ }, e[m] = t), t;
17
+ }, g = () => {
18
+ h().installed = !0;
19
+ }, _ = () => h().installed, v = () => {
20
+ h().installed = !1;
21
+ }, y = (e) => {
22
+ let t = h().storage.getStore();
23
+ if (t === void 0) return;
24
+ let { composed: n, restricting: i } = r(e, !1);
25
+ for (let e of n) t.tables.add(e);
26
+ for (let e of i) t.tables.add(e);
27
+ }, b = Symbol.for("@voltro/runtime:query-dependencies"), x = () => {
28
+ let e = globalThis, t = e[b];
29
+ return t === void 0 && (t = { storage: new p() }, e[b] = t), t;
30
+ }, S = () => {
31
+ x().storage.enterWith(/* @__PURE__ */ new Set());
32
+ }, C = () => [...x().storage.getStore() ?? []], w = (e) => {
33
+ x().storage.getStore()?.add(e), h().storage.getStore()?.tables.add(e);
34
+ }, T = (e) => {
35
+ h().storage.getStore()?.volatile.add(e);
36
+ }, E = (e, t) => h().storage.run(e, t), D = () => ({
37
+ tables: /* @__PURE__ */ new Set(),
38
+ caller: /* @__PURE__ */ new Set(),
39
+ volatile: /* @__PURE__ */ new Set()
40
+ }), O = /* @__PURE__ */ new Set([
41
+ "connections",
42
+ "apis",
43
+ "kv",
44
+ "cache",
45
+ "webhooks",
46
+ "workflows",
47
+ "events",
48
+ "outbox",
49
+ "transaction",
50
+ "storeForTenant"
51
+ ]), k = /* @__PURE__ */ new Set(["access", "connectionState"]), A = (e, t, n) => new Proxy(e, { get(e, r) {
52
+ return typeof r == "string" && !t.has(r) && n.caller.add(`subject.${r}`), Reflect.get(e, r, e);
53
+ } }), j = (e, t, n) => {
54
+ let r = e.request, i = r === void 0 ? void 0 : new Proxy(r, { get(e, r) {
55
+ return r === "subject" ? t : ((r === "clientId" || r === "cookieHeader") && n.caller.add(`request.${r}`), Reflect.get(e, r, e));
56
+ } });
57
+ return new Proxy(e, { get(e, t) {
58
+ if (t === "request" && i !== void 0) return i;
59
+ typeof t == "string" && (O.has(t) && n.volatile.add(`ctx.${t}`), k.has(t) && n.caller.add(`ctx.${t}`));
60
+ let r = Reflect.get(e, t, e);
61
+ return typeof r == "function" ? r.bind(e) : r;
62
+ } });
63
+ }, M = /* @__PURE__ */ new WeakMap(), N = (e) => {
64
+ let t = M.get(e);
65
+ return t === void 0 && (t = c.toCodecJson(e), M.set(e, t)), t;
66
+ }, P = /* @__PURE__ */ new WeakMap(), F = (e) => {
67
+ if (e === void 0) return "none";
68
+ let t = P.get(e);
69
+ return t === void 0 && (t = f(d(e.ast)), P.set(e, t)), t;
70
+ }, I = (t) => {
71
+ let n = t.input === void 0 ? s.some(t.decodedInput) : c.encodeUnknownOption(N(t.input))(t.decodedInput);
72
+ if (s.isNone(n)) return { bypass: "input-not-encodable" };
73
+ let r;
74
+ if (t.scope === "global") r = "g";
75
+ else if (t.scope === "tenant") {
76
+ if (t.subject.tenantId == null) return { bypass: "no-tenant" };
77
+ r = `t:${t.subject.tenantId}`;
78
+ } else {
79
+ if (t.subject.type === "anonymous" || t.subject.id == null || t.subject.id === "") return { bypass: "anonymous-subject" };
80
+ r = `s:${t.subject.id}`;
81
+ }
82
+ let i = t.rowFilter === void 0 ? [] : [...t.declaredSources].sort().map((n) => [n, e(t.rowFilter(n) ?? null)]), a;
83
+ try {
84
+ a = JSON.stringify([
85
+ t.codeIdentity,
86
+ F(t.output),
87
+ e(n.value),
88
+ i
89
+ ]);
90
+ } catch {
91
+ return { bypass: "input-not-encodable" };
92
+ }
93
+ let o = l("sha256").update(a).digest("base64url");
94
+ return { key: `cq:${t.name}:${o}:${r}` };
95
+ }, L = (e) => {
96
+ if (e.aborted) return { refused: {
97
+ reason: "aborted",
98
+ detail: []
99
+ } };
100
+ if (e.cacheScope !== "subject" && e.scope.caller.size > 0) return { refused: {
101
+ reason: "caller",
102
+ detail: [...e.scope.caller].sort()
103
+ } };
104
+ if (!e.volatileAllowed && e.scope.volatile.size > 0) return { refused: {
105
+ reason: "volatile",
106
+ detail: [...e.scope.volatile].sort()
107
+ } };
108
+ let t = e.rawReads.filter((e) => e.dependsOn.length === 0).map((e) => e.sql);
109
+ if (t.length > 0) return { refused: {
110
+ reason: "undeclared-raw-read",
111
+ detail: t
112
+ } };
113
+ let n = new Set(e.declaredSources);
114
+ for (let t of e.scope.tables) n.add(t);
115
+ for (let t of e.rawReads) for (let e of t.dependsOn) n.add(e);
116
+ if (e.rowFilter !== void 0) {
117
+ let t = new Set(e.declaredSources), r = [...n].filter((n) => !t.has(n) && e.rowFilter(n) !== void 0).sort();
118
+ if (r.length > 0) return { refused: {
119
+ reason: "row-filter-outside-source",
120
+ detail: r
121
+ } };
122
+ }
123
+ let r = e.output === void 0 ? s.some(e.value) : c.encodeUnknownOption(N(e.output))(e.value);
124
+ if (s.isNone(r)) return { refused: {
125
+ reason: "output-not-encodable",
126
+ detail: []
127
+ } };
128
+ let i;
129
+ try {
130
+ i = Buffer.byteLength(JSON.stringify(r.value) ?? "", "utf8");
131
+ } catch {
132
+ return { refused: {
133
+ reason: "output-not-encodable",
134
+ detail: []
135
+ } };
136
+ }
137
+ return i > e.maxEntryBytes ? { refused: {
138
+ reason: "oversized",
139
+ detail: [`${i} bytes`]
140
+ } } : { store: {
141
+ stored: r.value,
142
+ tags: [...n].sort()
143
+ } };
144
+ }, R = (e, t) => e === void 0 ? s.some(t) : c.decodeUnknownOption(N(e))(t), z = (e, t) => {
145
+ let n = t.detail.join(", ");
146
+ switch (t.reason) {
147
+ case "caller": return `${e}: \`cache:\` result NOT kept — the handler read ${n}, which its cache scope does not key on, so the value is specific to this caller. Use \`scope: 'subject'\`, or derive the result without reading the caller (declare access in \`guards:\`; a membership the handler READS through ctx.store is fine — it becomes a dependency).`;
148
+ case "volatile": return `${e}: \`cache:\` result NOT kept — the handler used ${n}, which no table write invalidates. Declare \`cache: { …, volatile: true }\` to accept the ttl as the bound on that staleness, or drop \`cache:\`.`;
149
+ case "undeclared-raw-read": return `${e}: \`cache:\` result NOT kept — a raw read declares no tables, so no write could invalidate it: ${n}. Declare them: ctx.store.raw(fragment, { dependsOn: ['…'] }).`;
150
+ case "row-filter-outside-source": return `${e}: \`cache:\` result NOT kept — the registered row filter restricts ${n}, which the query reads but does not declare in \`source:\`. Add it to \`source:\` so the entry is keyed by what this caller may see there.`;
151
+ case "output-not-encodable": return `${e}: \`cache:\` result NOT kept — the value does not encode through the query's \`output\` schema.`;
152
+ case "oversized": return `${e}: \`cache:\` result NOT kept — ${n} exceeds the cache's maxEntryBytes.`;
153
+ case "aborted": return `${e}: \`cache:\` result NOT kept — the subscription closed while it was computed.`;
154
+ }
155
+ }, B = (e) => {
156
+ let r = o.suspend(() => {
157
+ let r = D(), s = new Set(e.policy.scope === "tenant" ? ["tenantId"] : []), c = e.policy.scope === "subject" ? e.subject : A(e.subject, s, r), l = j(e.ctx, c, r), u = [], d = e.subject.id ?? "anonymous", f = {
158
+ subjectKey: i(d, void 0),
159
+ forcePrimary: !0
160
+ };
161
+ return o.tryPromise({
162
+ try: () => E(r, () => a(f, () => n(async () => {
163
+ let n = await e.execute(l, c);
164
+ return u = t(), n;
165
+ }))),
166
+ catch: (e) => e
167
+ }).pipe(o.map((t) => {
168
+ let n = new Set(e.sources), i = (e) => [...new Set(e)].filter((e) => !n.has(e)).sort();
169
+ if (e.isDescriptor(t)) return e.onDescriptor(), {
170
+ value: {
171
+ value: t,
172
+ dependencies: []
173
+ },
174
+ notApplicable: !0
175
+ };
176
+ let a = L({
177
+ scope: r,
178
+ cacheScope: e.policy.scope,
179
+ volatileAllowed: e.policy.volatile,
180
+ rawReads: u,
181
+ declaredSources: e.sources,
182
+ rowFilter: e.rowFilter,
183
+ output: e.output,
184
+ value: e.unwrap(t),
185
+ maxEntryBytes: e.cache.maxEntryBytes,
186
+ aborted: e.signal?.aborted === !0
187
+ });
188
+ if ("refused" in a) return a.refused.reason !== "aborted" && e.cache.notice(e.name, a.refused.reason, z(e.name, a.refused)), { value: {
189
+ value: t,
190
+ dependencies: i(r.tables)
191
+ } };
192
+ let o = i(a.store.tags);
193
+ return {
194
+ value: {
195
+ value: t,
196
+ dependencies: o
197
+ },
198
+ store: {
199
+ stored: {
200
+ v: a.store.stored,
201
+ d: o
202
+ },
203
+ tags: a.store.tags
204
+ }
205
+ };
206
+ }));
207
+ });
208
+ return e.cache.wrapDynamic(e.key, {
209
+ ttlMs: e.policy.ttlMs,
210
+ ...e.policy.swrMs === void 0 ? {} : { swrMs: e.policy.swrMs },
211
+ ...e.cache.leaseMs === void 0 ? {} : { leaseMs: e.cache.leaseMs },
212
+ label: e.name
213
+ }, r, (t) => o.succeed(V(e.output, t))).pipe(o.map(({ value: e }) => e));
214
+ }, V = (e, t) => {
215
+ if (typeof t != "object" || !t || !("v" in t) || !("d" in t)) return s.none();
216
+ let n = t;
217
+ return !Array.isArray(n.d) || !n.d.every((e) => typeof e == "string") ? s.none() : s.map(R(e, n.v), (e) => ({
218
+ value: e,
219
+ dependencies: n.d
220
+ }));
221
+ }, H = (e) => {
222
+ let t = u(e.ttl);
223
+ if (t !== null) return {
224
+ ttlMs: t,
225
+ swrMs: e.swr === void 0 ? void 0 : u(e.swr) ?? void 0,
226
+ scope: e.scope,
227
+ volatile: e.volatile === !0
228
+ };
229
+ };
230
+ //#endregion
231
+ export { B as cachedComputedCall, I as computedCacheKey, _ as computedQueryCacheCaptureInstalled, C as currentQueryDependencies, L as decideComputedStore, R as decodeComputedStored, z as describeComputedRefusal, S as enterQueryDependencies, g as installComputedQueryCacheCapture, D as newComputedCaptureScope, y as noteCacheRead, T as noteCacheVolatile, w as noteDependency, j as observedContext, A as observedSubject, H as queryCachePolicy, v as resetComputedQueryCacheCaptureForTests, E as runWithComputedCapture };
@@ -0,0 +1,81 @@
1
+ import { beginOAuthConnect as e, forgetCredential as t, listConnectionStates as n, storeCredential as r } from "./connectionVault.js";
2
+ import { ConnectionHandshakeFailed as i, ConnectionKindMismatch as a, ConnectionNotDeclared as o, ConnectionSubjectRequired as s } from "@voltro/protocol";
3
+ //#region src/connectionBuiltins.ts
4
+ var c = (e, t) => {
5
+ let n = e.request?.subject?.id ?? null;
6
+ if (n === null || n === "") throw new s({ connectionId: t });
7
+ return n;
8
+ }, l = (e, t) => {
9
+ let n = e.registry.get(t);
10
+ if (n === void 0) throw new o({ connectionId: t });
11
+ return n;
12
+ }, u = (e) => async (t, r) => {
13
+ let i = r.request?.subject?.id ?? null;
14
+ return i === null || i === "" ? e.registry.list().map((e) => ({
15
+ connectionId: e.id,
16
+ kind: e.kind,
17
+ label: e.label ?? e.id,
18
+ status: "disconnected",
19
+ accountId: null,
20
+ accountLabel: null,
21
+ scopes: [],
22
+ expiresAt: null,
23
+ lastError: null,
24
+ connectedAt: null
25
+ })) : n(r.store, e.registry, i);
26
+ }, d = (t) => async (n, r) => {
27
+ let i = l(t, n.connectionId), o = c(r, n.connectionId);
28
+ if (i.kind !== "oauth2") throw new a({
29
+ connectionId: n.connectionId,
30
+ expected: "oauth2",
31
+ actual: i.kind
32
+ });
33
+ return e({
34
+ store: r.store,
35
+ definition: i,
36
+ subjectId: o,
37
+ tenantId: r.request?.subject?.tenantId ?? null,
38
+ publicUrl: t.publicUrl,
39
+ ...n.redirectTo === void 0 ? {} : { redirectTo: n.redirectTo }
40
+ });
41
+ }, f = (e) => async (t, n) => {
42
+ let o = l(e, t.connectionId), s = c(n, t.connectionId);
43
+ if (o.kind !== "pat") throw new a({
44
+ connectionId: t.connectionId,
45
+ expected: "pat",
46
+ actual: o.kind
47
+ });
48
+ let u = t.token.trim();
49
+ if (u.length === 0) throw new i({
50
+ connectionId: t.connectionId,
51
+ reason: "token is empty",
52
+ transient: !1
53
+ });
54
+ let d;
55
+ if (o.validate !== void 0) try {
56
+ d = await o.validate(u);
57
+ } catch (e) {
58
+ throw new i({
59
+ connectionId: t.connectionId,
60
+ reason: `the provider rejected that token: ${e instanceof Error ? e.message : String(e)}`,
61
+ transient: !1
62
+ });
63
+ }
64
+ return await r({
65
+ store: n.store,
66
+ definition: o,
67
+ subjectId: s,
68
+ tenantId: n.request?.subject?.tenantId ?? null,
69
+ tokens: {
70
+ accessToken: u,
71
+ scopes: []
72
+ },
73
+ ...d === void 0 ? {} : { account: d }
74
+ }), { ok: !0 };
75
+ }, p = (e) => async (n, r) => {
76
+ l(e, n.connectionId);
77
+ let i = c(r, n.connectionId);
78
+ return { ok: await t(r.store, n.connectionId, i) };
79
+ };
80
+ //#endregion
81
+ export { p as makeDisconnectConnectionExecutor, u as makeListConnectionsExecutor, d as makeStartConnectionExecutor, f as makeSubmitTokenExecutor };
@@ -0,0 +1,66 @@
1
+ //#region src/connectionCredentials.ts
2
+ var e = 36e5, t = Symbol.for("@voltro/runtime/connectionCredentials"), n = globalThis, r = n[t] ??= {
3
+ overrides: /* @__PURE__ */ new Map(),
4
+ credentialExpiry: /* @__PURE__ */ new Map(),
5
+ streamInterrupts: /* @__PURE__ */ new Map()
6
+ }, { overrides: i, credentialExpiry: a, streamInterrupts: o } = r, s = (e, t) => {
7
+ t === void 0 ? a.delete(e) : a.set(e, t);
8
+ }, c = (e) => a.get(e), l = (e, t) => {
9
+ i.set(e, {
10
+ credential: t,
11
+ touchedAt: Date.now()
12
+ });
13
+ }, u = (e) => {
14
+ let t = i.get(e);
15
+ if (t) return t.touchedAt = Date.now(), t.credential;
16
+ }, d = (e) => {
17
+ a.delete(e), i.delete(e);
18
+ }, f = (e, t) => {
19
+ let n = [], r = /* @__PURE__ */ new Set();
20
+ for (let i of (e ?? "").split(";")) {
21
+ let e = i.indexOf("=");
22
+ if (e < 0) continue;
23
+ let a = i.slice(0, e).trim();
24
+ if (a === "") continue;
25
+ let o = t[a];
26
+ o === void 0 ? n.push([a, i.slice(e + 1).trim()]) : (n.push([a, encodeURIComponent(o)]), r.add(a));
27
+ }
28
+ for (let [e, i] of Object.entries(t)) r.has(e) || n.push([e, encodeURIComponent(i)]);
29
+ return n.map(([e, t]) => `${e}=${t}`).join("; ");
30
+ }, p = (e, t) => {
31
+ let n = u(e);
32
+ if (n === void 0) return t;
33
+ let r = { ...t };
34
+ if (n.headers !== void 0) for (let [e, t] of Object.entries(n.headers)) {
35
+ let n = e.toLowerCase();
36
+ delete r[e], r[n] = t;
37
+ }
38
+ if (n.cookies !== void 0) {
39
+ let e = t.cookie ?? t.Cookie;
40
+ delete r.Cookie, r.cookie = f(e, n.cookies);
41
+ }
42
+ return r;
43
+ };
44
+ r.sweepHandle ??= setInterval(() => {
45
+ let e = Date.now() - 864e5;
46
+ for (let [t, n] of i) n.touchedAt < e && i.delete(t);
47
+ }, e), typeof r.sweepHandle == "object" && r.sweepHandle !== null && "unref" in r.sweepHandle && r.sweepHandle.unref();
48
+ var m = (e, t) => {
49
+ let n = o.get(e);
50
+ return n || (n = /* @__PURE__ */ new Set(), o.set(e, n)), n.add(t), () => {
51
+ let n = o.get(e);
52
+ n && (n.delete(t), n.size === 0 && o.delete(e));
53
+ };
54
+ }, h = (e) => {
55
+ let t = o.get(e);
56
+ if (t) {
57
+ for (let e of [...t]) try {
58
+ e();
59
+ } catch {}
60
+ o.delete(e);
61
+ }
62
+ }, g = (e) => o.get(e)?.size ?? 0, _ = () => {
63
+ i.clear(), a.clear(), o.clear();
64
+ };
65
+ //#endregion
66
+ export { g as _connectionStreamCount, _ as _resetConnectionCredentialsForTest, p as applyConnectionCredential, l as bindConnectionCredential, u as getConnectionCredential, c as getCredentialExpiry, h as interruptConnectionStreams, f as mergeCookieHeader, s as recordCredentialExpiry, m as registerConnectionStream, d as unbindConnection };
@@ -0,0 +1,34 @@
1
+ //#region src/connectionState.ts
2
+ var e = Symbol.for("@voltro/runtime/connectionState"), t = globalThis, n = t[e] ??= /* @__PURE__ */ new WeakMap(), r = (e, t) => {
3
+ let r = n.get(e);
4
+ if (r === void 0 && !e.signal.aborted) {
5
+ r = /* @__PURE__ */ new Map(), n.set(e, r);
6
+ let t = r;
7
+ e.signal.addEventListener("abort", () => {
8
+ t.clear(), n.delete(e);
9
+ }, { once: !0 });
10
+ }
11
+ let i = r, a = (n) => {
12
+ let r = () => {
13
+ !e.signal.aborted && i !== void 0 && n(i);
14
+ };
15
+ t === void 0 ? r() : t(async () => {
16
+ r();
17
+ });
18
+ };
19
+ return {
20
+ get: (t) => e.signal.aborted ? void 0 : structuredClone(i?.get(t)),
21
+ has: (t) => !e.signal.aborted && i?.has(t) === !0,
22
+ set: (e, t) => {
23
+ let n = structuredClone(t);
24
+ a((t) => {
25
+ t.set(e, n);
26
+ });
27
+ },
28
+ delete: (e) => a((t) => {
29
+ t.delete(e);
30
+ })
31
+ };
32
+ };
33
+ //#endregion
34
+ export { r as makeConnectionState };