@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,20 @@
1
+ import { and as e, eq as t } from "@voltro/database";
2
+ //#region src/upsertBinding.ts
3
+ var n = "id", r = async (r, i, a, o) => {
4
+ let s = o.map((e) => t(e, a[e]));
5
+ if (s.length === 0) return;
6
+ let c = (await r.query({
7
+ table: i,
8
+ predicate: s.length === 1 ? s[0] : e(...s),
9
+ order: [],
10
+ take: 1,
11
+ skip: void 0,
12
+ projection: [n]
13
+ }))[0]?.[n];
14
+ return c === null ? void 0 : c;
15
+ }, i = async (e, t, i, a) => {
16
+ let o = await r(e, t, i, a);
17
+ return o === void 0 ? i[n] : o;
18
+ };
19
+ //#endregion
20
+ export { r as upsertConflictId, i as upsertDestinationId };
@@ -0,0 +1,34 @@
1
+ import { dueWakeups as e, releaseWakeup as t, tryClaimWakeup as n } from "./wakeRegistry.js";
2
+ //#region src/wakeOrchestrator.ts
3
+ var r = async (r) => {
4
+ let i = r.now?.() ?? /* @__PURE__ */ new Date(), a = await e(r.store, i, r.batchLimit ?? 100);
5
+ if (a.length === 0) return 0;
6
+ let o = 0;
7
+ for (let e of a) if (await n(r.store, e)) try {
8
+ await r.adapter.wake(e), o++;
9
+ } catch (n) {
10
+ await t(r.store, e), r.log?.warn("wake: adapter failed — released for retry", {
11
+ tenantId: e.tenantId,
12
+ kind: e.kind,
13
+ refId: e.refId,
14
+ reason: n instanceof Error ? n.message : String(n)
15
+ });
16
+ }
17
+ return o > 0 && r.log?.info("wake: woke due deployments", { count: o }), o;
18
+ }, i = (e, t = 1e3) => {
19
+ let n = !1, i, a = async () => {
20
+ if (!n) {
21
+ try {
22
+ await r(e);
23
+ } catch (t) {
24
+ e.log?.warn("wake: tick failed", { reason: t instanceof Error ? t.message : String(t) });
25
+ }
26
+ n || (i = setTimeout(() => void a(), t));
27
+ }
28
+ };
29
+ return a(), { stop: () => {
30
+ n = !0, i !== void 0 && clearTimeout(i);
31
+ } };
32
+ };
33
+ //#endregion
34
+ export { i as runWakeLoop, r as wakeDueOnce };
@@ -0,0 +1,71 @@
1
+ //#region src/wakeRegistry.ts
2
+ var e = "_voltro_wakeups", t = (e) => `${e.tenantId}:${e.kind}:${e.refId}`, n = (e) => ({
3
+ tenantId: String(e.tenantId),
4
+ kind: String(e.kind),
5
+ refId: String(e.refId),
6
+ wakeAt: e.wakeAt instanceof Date ? e.wakeAt : new Date(String(e.wakeAt)),
7
+ status: e.status === "fired" ? "fired" : "pending"
8
+ }), r = async (n, r) => {
9
+ await n.upsert(e, {
10
+ id: t(r),
11
+ tenantId: r.tenantId,
12
+ kind: r.kind,
13
+ refId: r.refId,
14
+ wakeAt: r.wakeAt,
15
+ status: "pending"
16
+ }, {
17
+ conflictColumns: ["id"],
18
+ update: ["wakeAt", "status"]
19
+ });
20
+ }, i = async (n, r) => n.delete(e, t(r)), a = async (n, r) => await n.update(e, t(r), { status: "fired" }) !== null, o = (e, t) => ({ and: [{
21
+ column: "id",
22
+ op: "eq",
23
+ value: e
24
+ }, {
25
+ column: "status",
26
+ op: "eq",
27
+ value: t
28
+ }] }), s = async (n, r) => await n.updateMany(e, { status: "fired" }, { where: o(t(r), "pending") }) > 0, c = async (n, r) => {
29
+ await n.updateMany(e, { status: "pending" }, { where: o(t(r), "fired") });
30
+ }, l = {
31
+ column: "status",
32
+ op: "eq",
33
+ value: "pending"
34
+ }, u = async (t, r) => {
35
+ let i = {
36
+ table: e,
37
+ predicate: l,
38
+ order: [{
39
+ column: "wakeAt",
40
+ direction: "asc"
41
+ }],
42
+ take: r,
43
+ skip: void 0,
44
+ projection: void 0
45
+ };
46
+ return (await t.query(i)).map(n);
47
+ }, d = async (e, t, n = 500) => {
48
+ let r = await u(e, n), i = t.getTime(), a = 0;
49
+ for (let e of r) e.wakeAt.getTime() <= i && (r[a++] = e);
50
+ return r.length = a, r;
51
+ }, f = async (e) => (await u(e, 1))[0] ?? null, p = {
52
+ column: "status",
53
+ op: "eq",
54
+ value: "fired"
55
+ }, m = async (t, n = {}) => {
56
+ let r = {
57
+ table: e,
58
+ predicate: p,
59
+ order: [{
60
+ column: "wakeAt",
61
+ direction: "asc"
62
+ }],
63
+ take: n.limit ?? 1e3,
64
+ skip: void 0,
65
+ projection: void 0
66
+ }, i = await t.query(r), a = n.firedOlderThan?.getTime(), o = 0;
67
+ for (let n of i) a !== void 0 && (n.wakeAt instanceof Date ? n.wakeAt : new Date(String(n.wakeAt))).getTime() >= a || await t.delete(e, String(n.id)) && o++;
68
+ return o;
69
+ };
70
+ //#endregion
71
+ export { i as cancelWakeup, d as dueWakeups, a as markWakeupFired, f as nextWakeup, m as pruneWakeups, r as registerWakeup, c as releaseWakeup, s as tryClaimWakeup };
@@ -0,0 +1,63 @@
1
+ import * as e from "node:http";
2
+ //#region src/wakeRouter.ts
3
+ var t = () => {
4
+ let e = 0, t = 0;
5
+ return {
6
+ onRequestStart: () => {
7
+ e++;
8
+ },
9
+ onRequestEnd: () => {
10
+ e = Math.max(0, e - 1);
11
+ },
12
+ onConnect: () => {
13
+ t++;
14
+ },
15
+ onDisconnect: () => {
16
+ t = Math.max(0, t - 1);
17
+ },
18
+ inFlightRequests: () => e,
19
+ openConnections: () => t
20
+ };
21
+ }, n = (e) => ({ run: async (t) => (e.onActivity?.(), await e.ensureAwake(), t()) }), r = (t, n, r, i) => new Promise((a, o) => {
22
+ let s = e.request({
23
+ host: r,
24
+ port: i,
25
+ method: t.method,
26
+ path: t.url,
27
+ headers: t.headers
28
+ }, (e) => {
29
+ n.writeHead(e.statusCode ?? 502, e.headers), e.pipe(n), e.on("end", a), e.on("error", o);
30
+ });
31
+ s.on("error", o), t.pipe(s);
32
+ }), i = (t, n, r, i, a) => new Promise((o, s) => {
33
+ let c = e.request({
34
+ host: i,
35
+ port: a,
36
+ method: t.method,
37
+ path: t.url,
38
+ headers: t.headers
39
+ });
40
+ c.on("upgrade", (e, t, i) => {
41
+ i && i.length > 0 && n.unshift(i), r && r.length > 0 && t.unshift(r), n.write("HTTP/1.1 101 Switching Protocols\r\nConnection: Upgrade\r\nUpgrade: websocket\r\n\r\n"), t.pipe(n), n.pipe(t);
42
+ let a = () => {
43
+ t.destroy(), n.destroy(), o();
44
+ };
45
+ n.on("close", a), t.on("close", a), t.on("error", s);
46
+ }), c.on("error", s), c.end();
47
+ }), a = (t) => {
48
+ let a = n({
49
+ ensureAwake: () => t.supervisor.start(),
50
+ ...t.onActivity === void 0 ? {} : { onActivity: t.onActivity }
51
+ }), o = t.activity, s = e.createServer((e, n) => {
52
+ o?.onRequestStart(), n.on("close", () => o?.onRequestEnd()), a.run(() => r(e, n, t.targetHost, t.targetPort)).catch((e) => {
53
+ t.log?.warn("wake-router: proxy failed", { reason: e instanceof Error ? e.message : String(e) }), n.headersSent || n.writeHead(502), n.end("wake/proxy failed");
54
+ });
55
+ });
56
+ return s.on("upgrade", (e, n, r) => {
57
+ o?.onConnect(), n.on("close", () => o?.onDisconnect()), a.run(() => i(e, n, r, t.targetHost, t.targetPort)).catch((e) => {
58
+ t.log?.warn("wake-router: upgrade proxy failed", { reason: e instanceof Error ? e.message : String(e) }), n.destroy();
59
+ });
60
+ }), s;
61
+ };
62
+ //#endregion
63
+ export { t as makeRouterActivity, n as makeWakeGate, a as makeWakeProxyServer };
@@ -0,0 +1,62 @@
1
+ import { spawn as e } from "node:child_process";
2
+ //#region src/wakeSupervisor.ts
3
+ var t = (e) => ({ wake: async () => {
4
+ await e.start();
5
+ } }), n = (e) => new Promise((t) => setTimeout(t, e)), r = (t) => {
6
+ let r = t.fetchImpl ?? fetch, i = t.now ?? Date.now, a = t.sleep ?? n, o = t.spawnImpl ?? e, s = t.startTimeoutMs ?? 3e4, c = t.healthPollMs ?? 200, l = t.stopSignal ?? "SIGTERM", u = t.stopGraceMs ?? 1e4, d, f, p = t.healthCheck ?? ((e) => e.ok), m = async () => {
7
+ try {
8
+ let e = await r(t.healthUrl);
9
+ return p(e);
10
+ } catch {
11
+ return !1;
12
+ }
13
+ }, h = async () => {
14
+ t.log?.info("supervisor: starting app", { command: t.command });
15
+ let e = o(t.command, [...t.args ?? []], {
16
+ env: {
17
+ ...process.env,
18
+ ...t.env ?? {}
19
+ },
20
+ ...t.cwd === void 0 ? {} : { cwd: t.cwd },
21
+ stdio: "inherit"
22
+ });
23
+ d = e, e.on("exit", (n) => {
24
+ d === e && (d = void 0), t.log?.info("supervisor: app exited", { code: n });
25
+ });
26
+ let n = i() + s;
27
+ for (; i() < n;) {
28
+ if (d === void 0) throw Error("supervisor: app process exited before becoming healthy");
29
+ if (await m()) {
30
+ t.log?.info("supervisor: app healthy");
31
+ return;
32
+ }
33
+ await a(c);
34
+ }
35
+ throw await g(), Error(`supervisor: app did not become healthy within ${s}ms`);
36
+ }, g = async () => {
37
+ let e = d;
38
+ if (e === void 0) return;
39
+ d = void 0, t.log?.info("supervisor: stopping app");
40
+ let n = new Promise((t) => e.once("exit", () => t()));
41
+ e.kill(l);
42
+ let r = setTimeout(() => {
43
+ e.kill("SIGKILL");
44
+ }, u);
45
+ try {
46
+ await n;
47
+ } finally {
48
+ clearTimeout(r);
49
+ }
50
+ };
51
+ return {
52
+ isRunning: () => d !== void 0,
53
+ start: async () => {
54
+ d !== void 0 && await m() || (f === void 0 && (f = h().finally(() => {
55
+ f = void 0;
56
+ })), await f);
57
+ },
58
+ stop: g
59
+ };
60
+ };
61
+ //#endregion
62
+ export { t as makeProcessAdapter, r as nodeProcessSupervisor };
@@ -0,0 +1,12 @@
1
+ import { id as e, table as t, text as n, timestamp as r } from "@voltro/database";
2
+ //#region src/wakeupsTable.ts
3
+ var i = t("_voltro_wakeups", {
4
+ id: e({ prefix: "wakeup" }),
5
+ tenantId: n(),
6
+ kind: n(),
7
+ refId: n(),
8
+ wakeAt: r(),
9
+ status: n()
10
+ }).index(["status", "wakeAt"]).index(["tenantId"]);
11
+ //#endregion
12
+ export { i as _voltroWakeupsTable };
@@ -0,0 +1,154 @@
1
+ import { Effect as e, Schema as t } from "effect";
2
+ import { GATEWAY_CREDENTIAL_EXPIRED_CLOSE_CODE as n, Subject as r } from "@voltro/protocol";
3
+ import { Socket as i } from "effect/socket";
4
+ //#region src/webSocketGatewayRuntime.ts
5
+ var a = (a, o, s, c, l, u, d) => e.scoped(e.gen(function* () {
6
+ let f = yield* a.writer, p = yield* e.context(), m = new AbortController(), h = s.limits?.maxMessageBytes ?? 1048576, g = s.limits?.maxPendingBytes ?? 4194304, _ = s.limits?.maxPendingMessages ?? 64, v = [], y = s.limits?.maxInboundMessagesPerSecond, b = s.limits?.burst ?? y ?? 0, x = b, S = performance.now(), C = [], w = 0, T, E = 0, D, O, k, A = 0, j, M = s.auth === "token" ? "waiting" : "admitted", N = c, P = !1, F = !1, I = () => {
7
+ let e = D;
8
+ D = void 0;
9
+ try {
10
+ e?.();
11
+ } catch (e) {
12
+ d(e);
13
+ }
14
+ }, L = (e) => {
15
+ if (!m.signal.aborted) {
16
+ m.abort(e), O !== void 0 && clearTimeout(O), k !== void 0 && clearTimeout(k), v.length = 0, T?.reject(e);
17
+ for (let t = w; t < C.length; t += 1) C[t]?.reject(e);
18
+ C.length = 0, w = 0, E = 0, I();
19
+ }
20
+ }, R = (t = 1e3, n) => {
21
+ m.signal.aborted || (L(Error(n ?? "gateway closed")), !(F || o.destroyed) && (F = !0, j = setTimeout(() => o.destroy(), 1e3), j.unref(), P ? e.runPromiseWith(p)(f.write(new i.CloseEvent(t, n))).catch(() => o.destroy()) : o.destroy()));
22
+ }, z = () => new Promise((e, t) => {
23
+ if (m.signal.aborted || o.destroyed) {
24
+ t(/* @__PURE__ */ Error("gateway closed"));
25
+ return;
26
+ }
27
+ let n = () => {
28
+ t(/* @__PURE__ */ Error("gateway closed"));
29
+ };
30
+ m.signal.addEventListener("abort", n, { once: !0 }), o.write(/* @__PURE__ */ new Uint8Array(), (r) => {
31
+ m.signal.removeEventListener("abort", n), r ? t(r) : e();
32
+ });
33
+ }), B = async () => {
34
+ if (T !== void 0 || m.signal.aborted) return;
35
+ let t = C[w];
36
+ if (t) {
37
+ C[w] = void 0, w += 1, w === C.length ? (C.length = 0, w = 0) : w >= 1024 && w * 2 >= C.length && (C.splice(0, w), w = 0), T = t;
38
+ try {
39
+ if (await e.runPromiseWith(p)(f.write(t.data), { signal: m.signal }), await z(), m.signal.aborted) throw Error("gateway closed");
40
+ t.resolve({ queuedBytes: E - t.size });
41
+ } catch (e) {
42
+ t.reject(e instanceof Error ? e : /* @__PURE__ */ Error("gateway write failed")), R(1011, "gateway write failed");
43
+ } finally {
44
+ m.signal.aborted || (E -= t.size), T = void 0, m.signal.aborted || B();
45
+ }
46
+ }
47
+ }, V = (e) => {
48
+ if (m.signal.aborted) return Promise.reject(/* @__PURE__ */ Error("gateway closed"));
49
+ let t = typeof e == "string" ? Buffer.byteLength(e) : e.byteLength;
50
+ if (t > h) return R(1009, "gateway message too large"), Promise.reject(/* @__PURE__ */ Error("gateway message too large"));
51
+ if (t > g - E || C.length - w + +!!T >= _) return R(1013, "gateway outbound queue exceeded"), Promise.reject(/* @__PURE__ */ Error("gateway outbound queue exceeded"));
52
+ E += t;
53
+ let n = new Promise((n, r) => {
54
+ C.push({
55
+ data: typeof e == "string" ? e : e.slice(),
56
+ size: t,
57
+ resolve: n,
58
+ reject: r
59
+ });
60
+ });
61
+ return B(), n;
62
+ }, H = {
63
+ send: (e) => {
64
+ V(e).catch(() => {});
65
+ },
66
+ sendAsync: V,
67
+ get queuedBytes() {
68
+ return E;
69
+ },
70
+ signal: m.signal,
71
+ close: R,
72
+ onMessage: (e) => {
73
+ m.signal.aborted || v.push(e);
74
+ },
75
+ get subject() {
76
+ return N;
77
+ },
78
+ headers: l,
79
+ path: s.path
80
+ }, U = () => {
81
+ Promise.resolve().then(() => {
82
+ if (!m.signal.aborted) return s.onConnection(H);
83
+ }).then((e) => {
84
+ typeof e == "function" && (D = e), m.signal.aborted && I();
85
+ }, (e) => {
86
+ d(e), R(1011, "gateway setup failed");
87
+ });
88
+ }, W = (e) => {
89
+ if (m.signal.aborted) return !1;
90
+ let t = e - Date.now();
91
+ return t <= 0 ? (R(n, "credential expired"), !1) : (O = setTimeout(() => {
92
+ W(e);
93
+ }, Math.min(t, 2147483647)), O.unref(), !0);
94
+ }, G = (e, n) => {
95
+ M = "verifying";
96
+ let i = Uint8Array.from(e);
97
+ Promise.resolve().then(() => m.signal.aborted ? null : s.verify(i, {
98
+ signal: m.signal,
99
+ headers: l,
100
+ path: s.path,
101
+ receivedAt: n
102
+ })).then((e) => {
103
+ if (!m.signal.aborted) {
104
+ if (performance.now() >= A) R(1008, "gateway token verification timed out");
105
+ else if (e === null) R(1008, "gateway token rejected");
106
+ else {
107
+ if (!e || !t.is(r)(e.subject) || e.credentialExpiresAt !== void 0 && (!Number.isFinite(e.credentialExpiresAt) || !Number.isSafeInteger(Math.ceil(e.credentialExpiresAt * 1e3)))) throw Error("gateway token verifier returned an invalid SubjectResolution");
108
+ N = e.subject, k !== void 0 && clearTimeout(k), (e.credentialExpiresAt === void 0 || W(e.credentialExpiresAt * 1e3)) && (M = "admitted", U());
109
+ }
110
+ }
111
+ }).catch((e) => {
112
+ m.signal.aborted || (d(e), R(1011, "gateway token verification failed"));
113
+ });
114
+ }, K = () => L(/* @__PURE__ */ Error("gateway disconnected")), q = () => R(1011, "gateway transport failed");
115
+ o.once("close", K), o.once("error", q), yield* e.addFinalizer(() => e.sync(() => {
116
+ L(/* @__PURE__ */ Error("gateway stopped")), j !== void 0 && clearTimeout(j), o.off("close", K), o.off("error", q), o.destroy();
117
+ }));
118
+ let J = (e) => {
119
+ if (m.signal.aborted) return;
120
+ let t = performance.now();
121
+ if (e.byteLength > h) R(1009, "gateway message too large");
122
+ else {
123
+ if (y !== void 0) {
124
+ if (x = Math.min(b, x + Math.max(0, t - S) * y / 1e3), S = t, x < 1) {
125
+ R(1008, "gateway inbound rate exceeded");
126
+ return;
127
+ }
128
+ x--;
129
+ }
130
+ if (M !== "admitted" && t >= A) R(1008, "gateway token verification timed out");
131
+ else if (M === "waiting") G(e, t);
132
+ else if (M === "verifying") R(1008, "gateway token verification pending");
133
+ else try {
134
+ for (let n of v) n(e, t);
135
+ } catch (e) {
136
+ d(e), R(1011, "gateway message handler failed");
137
+ }
138
+ }
139
+ }, Y = e.sync(() => {
140
+ if (P = !0, s.auth === "token") {
141
+ let e = s.verificationTimeoutMs ?? 5e3;
142
+ A = performance.now() + e, k = setTimeout(() => R(1008, "gateway token verification timed out"), e), k.unref();
143
+ } else (u === void 0 || W(u)) && U();
144
+ });
145
+ yield* e.gen(function* () {
146
+ let e = yield* a.reader;
147
+ for (yield* Y;;) {
148
+ let t = yield* e.pull;
149
+ for (let e of t) J(typeof e == "string" ? new TextEncoder().encode(e) : e);
150
+ }
151
+ }).pipe(e.ignore);
152
+ }));
153
+ //#endregion
154
+ export { a as runWebSocketGateway };
@@ -0,0 +1,18 @@
1
+ //#region src/webhookVerification.ts
2
+ var e = "voltroWebhookVerification", t = (e) => e === "signature" || e === "provider" || e === "none", n = (n) => {
3
+ if (typeof n != "function" && (typeof n != "object" || !n)) return;
4
+ let r = n[e];
5
+ return t(r) ? r : void 0;
6
+ }, r = class extends Error {
7
+ path;
8
+ name = "UnverifiedWebhookRoute";
9
+ constructor(e) {
10
+ super(`incoming webhook '${e}' is mounted without declaring how it authenticates its caller. An incoming webhook is a public POST that runs your application code, so the framework refuses to mount one that nothing verifies. Declare it on the descriptor:\n · provider: stripeWebhookProvider() — or any provider preset (HMAC + replay window)\n · signature: { _tag: 'hmac', algorithm: 'hmacSha256', header: 'X-Signature', ... }\n · verification: 'provider' — the handler verifies with the provider's own SDK\n · verification: 'none' — deliberately public (gateway / IP allow-list owns it)\nA signature-verified webhook also needs its shared secret in VOLTRO_WEBHOOK_SECRET_<ID>; the framework mints no secret for you.`), this.path = e;
11
+ }
12
+ }, i = (e) => {
13
+ if (e !== void 0) {
14
+ for (let [t, i] of e) if (n(i.handle) === void 0) throw new r(t);
15
+ }
16
+ };
17
+ //#endregion
18
+ export { r as UnverifiedWebhookRoute, e as WEBHOOK_VERIFICATION_PROPERTY, i as assertWebhookRoutesDeclareVerification, n as webhookVerificationOf };
@@ -0,0 +1,84 @@
1
+ import { getTable as e, readableByColumns as t, serverOnlyColumns as n } from "@voltro/database";
2
+ import { ADMIN_SCOPE as r, effectiveScopes as i, hasEffectiveScope as a } from "@voltro/protocol";
3
+ import { types as o } from "node:util";
4
+ //#region src/wireColumnStrip.ts
5
+ var s = Array.prototype.includes, c = (e) => !o.isProxy(e) && Object.getPrototypeOf(e) === Array.prototype && Object.getOwnPropertyDescriptor(Array.prototype, "includes")?.value === s && Reflect.ownKeys(e).every((t) => {
6
+ if (typeof t != "string" || t !== "length" && !/^(0|[1-9][0-9]*)$/.test(t)) return !1;
7
+ let n = Object.getOwnPropertyDescriptor(e, t);
8
+ return "value" in n && (t === "length" || typeof n.value == "string");
9
+ }), l = (e) => !o.isProxy(e) && (Object.getPrototypeOf(e) === Object.prototype || Object.getPrototypeOf(e) === null) && Reflect.ownKeys(e).every((t) => "value" in Object.getOwnPropertyDescriptor(e, t)), u = (t) => {
10
+ let r = e(t);
11
+ return r === void 0 ? [] : n(r);
12
+ }, d = (e, t) => {
13
+ if (t.length === 0) return e;
14
+ let n = !1, r = e.map((e) => {
15
+ let r;
16
+ for (let n of t) Object.prototype.hasOwnProperty.call(e, n) && (r === void 0 && (r = { ...e }), delete r[n]);
17
+ return r === void 0 ? e : (n = !0, r);
18
+ });
19
+ return n ? r : e;
20
+ }, f = (e, t) => d(t, u(e)), p = (o, s) => {
21
+ let u = e(o);
22
+ if (u === void 0) return [];
23
+ let d = n(u), f = t(u);
24
+ if (f.length === 0) return d;
25
+ let p = [...d], m;
26
+ if (f.length >= 256) {
27
+ let e = i(s);
28
+ e.length >= 32 && l(s) && c(e) && f.every((e) => c(e.scopes)) && (m = new Set(e));
29
+ }
30
+ let h = m;
31
+ for (let { column: e, scopes: t } of f) (h === void 0 ? t.some((e) => a(s, e)) : h.has(r) || t.some((e) => h.has(e))) || p.push(e);
32
+ return p;
33
+ }, m = (e, t, n) => d(t, p(e, n)), h = (e, t) => {
34
+ if (typeof e != "object" || !e) return e === void 0 || [
35
+ "string",
36
+ "number",
37
+ "boolean"
38
+ ].includes(typeof e);
39
+ if (o.isProxy(e) || t.has(e)) return !1;
40
+ if (e instanceof Date) return Object.getPrototypeOf(e) === Date.prototype && Reflect.ownKeys(e).length === 0;
41
+ let n = Object.getPrototypeOf(e);
42
+ if (n !== Object.prototype && n !== null && n !== Array.prototype || "toJSON" in e || Array.isArray(e) && ["constructor", "map"].some((t) => Object.hasOwn(e, t))) return !1;
43
+ t.add(e);
44
+ try {
45
+ for (let n of Reflect.ownKeys(e)) {
46
+ let r = Object.getOwnPropertyDescriptor(e, n);
47
+ if (r === void 0 || !("value" in r) || r.enumerable && !h(r.value, t)) return !1;
48
+ }
49
+ return !0;
50
+ } finally {
51
+ t.delete(e);
52
+ }
53
+ }, g = () => {
54
+ let e = /* @__PURE__ */ new WeakMap();
55
+ return (t, n, r) => {
56
+ let i = p(t, r), a = JSON.stringify([t, i]);
57
+ if (i.length === 0) return {
58
+ rows: n,
59
+ visibilityKey: a
60
+ };
61
+ let o = e.get(n);
62
+ if (o === void 0) {
63
+ let t = !1;
64
+ try {
65
+ t = Array.isArray(n) && h(n, /* @__PURE__ */ new Set());
66
+ } catch {}
67
+ o = {
68
+ eligible: t,
69
+ policies: /* @__PURE__ */ new Map()
70
+ }, e.set(n, o);
71
+ }
72
+ if (!o.eligible) return {
73
+ rows: d(n, i),
74
+ visibilityKey: a
75
+ };
76
+ let s = o.policies.get(a);
77
+ return s === void 0 && (s = d(n, i), o.policies.set(a, s)), {
78
+ rows: s,
79
+ visibilityKey: a
80
+ };
81
+ };
82
+ };
83
+ //#endregion
84
+ export { g as createDispatchWireStrip, p as forbiddenColumnsForSubject, u as serverOnlyColumnNames, d as stripColumnsFromRows, m as stripForbiddenForWire, f as stripServerOnlyForWire };
@@ -0,0 +1,87 @@
1
+ import { and as e, eq as t } from "@voltro/database";
2
+ import { ADMIN_SCOPE as n, hasEffectiveScope as r } from "@voltro/protocol";
3
+ import { openWorkflowRow as i } from "@voltro/workflow";
4
+ //#region src/workflowReadBuiltins.ts
5
+ var a = (e) => e.request?.subject ?? null, o = (e, t) => {
6
+ if (typeof e != "object" || !e) return null;
7
+ let n = e[t];
8
+ return typeof n == "string" ? n : null;
9
+ }, s = (e, t) => {
10
+ if (e === null) return !1;
11
+ if (e.type === "system" || r(e, n)) return !0;
12
+ if (e.type === "anonymous" || e.id == null) return !1;
13
+ let i = o(t, "type");
14
+ if (t == null || i === "system") return !1;
15
+ let a = o(t, "tenantId");
16
+ return a === null ? (e.tenantId ?? null) === null && o(t, "id") === e.id : a === (e.tenantId ?? null);
17
+ }, c = (e, t) => {
18
+ let n = a(e);
19
+ return t.filter((e) => s(n, e.subject)).map(i);
20
+ }, l = (e, t, n) => Number.isFinite(e) && e !== void 0 ? Math.min(Math.max(Math.floor(e), 1), n) : t, u = (e, t) => ({
21
+ table: "_voltro_workflow_runs",
22
+ order: [{
23
+ column: "startedAt",
24
+ direction: "desc"
25
+ }],
26
+ predicate: e,
27
+ take: t,
28
+ skip: void 0,
29
+ projection: void 0
30
+ }), d = async (e, n) => {
31
+ let r = (await e.store.query(u(t("id", n), 1)))[0];
32
+ return r !== void 0 && s(a(e), r.subject) ? r : void 0;
33
+ }, f = async (e, n) => {
34
+ let r = await n.store.query(u(t("id", e.id), 1));
35
+ return c(n, r.length > 0 ? r : await n.store.query(u(t("executionId", e.id), 1)));
36
+ }, p = async (n, r) => {
37
+ let i = [...n.tag === void 0 ? [] : [t("tag", n.tag)], ...n.status === void 0 ? [] : [t("status", n.status)]], a = i.length === 0 ? void 0 : i.length === 1 ? i[0] : e(...i);
38
+ return c(r, await r.store.query(u(a, l(n.limit, 100, 500))));
39
+ }, m = async (e, n) => await d(n, e.runId) === void 0 ? [] : n.store.query({
40
+ table: "_voltro_workflow_run_steps",
41
+ order: [{
42
+ column: "startedAt",
43
+ direction: "asc"
44
+ }],
45
+ predicate: t("runId", e.runId),
46
+ take: 1e3,
47
+ skip: void 0,
48
+ projection: void 0
49
+ }).then((e) => e.map(i)), h = async (e, n) => await d(n, e.runId) === void 0 ? [] : n.store.query({
50
+ table: "_voltro_workflow_run_events",
51
+ order: [{
52
+ column: "occurredAt",
53
+ direction: "asc"
54
+ }],
55
+ predicate: t("runId", e.runId),
56
+ take: 1e3,
57
+ skip: void 0,
58
+ projection: void 0
59
+ }).then((e) => e.map(i)), g = (e, t) => ({
60
+ table: "_voltro_workflow_events",
61
+ order: [{
62
+ column: "occurredAt",
63
+ direction: "desc"
64
+ }],
65
+ predicate: e,
66
+ take: t,
67
+ skip: void 0,
68
+ projection: void 0
69
+ }), _ = async (e, n) => {
70
+ let r = e.name === void 0 ? void 0 : t("name", e.name);
71
+ return c(n, await n.store.query(g(r, l(e.limit, 100, 500))));
72
+ }, v = async (e, n) => {
73
+ let r = (await n.store.query(g(t("id", e.eventId), 1)))[0];
74
+ return r === void 0 || !s(a(n), r.subject) ? [] : n.store.query({
75
+ table: "_voltro_workflow_event_deliveries",
76
+ order: [{
77
+ column: "createdAt",
78
+ direction: "asc"
79
+ }],
80
+ predicate: t("eventId", e.eventId),
81
+ take: 500,
82
+ skip: void 0,
83
+ projection: void 0
84
+ });
85
+ };
86
+ //#endregion
87
+ export { _ as workflowDomainEventsExecutor, v as workflowEventDeliveriesExecutor, s as workflowRowVisibleTo, h as workflowRunEventsExecutor, f as workflowRunExecutor, m as workflowRunStepsExecutor, p as workflowRunsExecutor };