@voltro/runtime 0.85.0 → 0.86.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 (160) hide show
  1. package/CHANGELOG.md +666 -0
  2. package/THIRD-PARTY-NOTICES.md +5 -33
  3. package/dist/aggregate.js +42 -0
  4. package/dist/aggregateExtrema.js +80 -0
  5. package/dist/aggregateIvm.js +115 -0
  6. package/dist/analyticsMirror.js +228 -0
  7. package/dist/analyticsSink.js +38 -0
  8. package/dist/apiKeyUsage.js +33 -0
  9. package/dist/apiKeys.js +223 -0
  10. package/dist/apiKeysWiring.js +114 -0
  11. package/dist/approvalBuiltins.js +10 -0
  12. package/dist/approvals.js +269 -0
  13. package/dist/authMiddlewareLayer.js +47 -0
  14. package/dist/bindEvent.js +72 -0
  15. package/dist/bootListener.js +76 -0
  16. package/dist/bootRefusal.js +7 -0
  17. package/dist/bootStoreCodec.js +70 -0
  18. package/dist/businessRules.js +67 -0
  19. package/dist/changeClaimsTable.js +12 -0
  20. package/dist/circuitBreaker.js +72 -0
  21. package/dist/columnOnUpdate.js +23 -0
  22. package/dist/composeAnalytics.js +108 -0
  23. package/dist/computedQuery.js +4 -0
  24. package/dist/connectionBuiltins.js +81 -0
  25. package/dist/connectionCredentials.js +66 -0
  26. package/dist/connectionState.js +34 -0
  27. package/dist/connectionVault.js +410 -0
  28. package/dist/connectionsFacade.js +54 -0
  29. package/dist/coordinatedSchedule.js +139 -0
  30. package/dist/crdtHistory.js +138 -0
  31. package/dist/crdtMerge.js +179 -0
  32. package/dist/crdtVersionsTable.js +25 -0
  33. package/dist/credentialBound.js +12 -0
  34. package/dist/crud.js +72 -0
  35. package/dist/dataStore.js +679 -0
  36. package/dist/dataloader.js +61 -0
  37. package/dist/declaredTablesGuard.js +48 -0
  38. package/dist/defineExecutor.js +4 -0
  39. package/dist/dependencyGraph.js +32 -0
  40. package/dist/devices.js +228 -0
  41. package/dist/devicesWiring.js +168 -0
  42. package/dist/dialectReplicationAdapter.js +29 -0
  43. package/dist/dispatcher.js +447 -0
  44. package/dist/effectStore.js +71 -0
  45. package/dist/eventBus.js +260 -0
  46. package/dist/eventPublish.js +49 -0
  47. package/dist/events.js +193 -0
  48. package/dist/expectation.js +52 -0
  49. package/dist/expectationEvaluator.js +308 -0
  50. package/dist/experiment.js +96 -0
  51. package/dist/experimentEvaluator.js +245 -0
  52. package/dist/externalizedTasks.js +25 -0
  53. package/dist/fieldCipher.js +61 -0
  54. package/dist/fingerprint.js +21 -0
  55. package/dist/finops.js +42 -0
  56. package/dist/finopsAccountant.js +216 -0
  57. package/dist/handlerBody.js +8 -0
  58. package/dist/healthProbes.js +55 -0
  59. package/dist/httpClientSsrf.js +49 -0
  60. package/dist/httpClientTracing.js +11 -0
  61. package/dist/httpCompression.js +76 -0
  62. package/dist/httpKeepAlive.js +12 -0
  63. package/dist/httpRouteMounts.js +47 -0
  64. package/dist/idempotencyStore.js +70 -0
  65. package/dist/idleDetector.js +21 -0
  66. package/dist/index.d.ts +88 -69
  67. package/dist/index.js +144 -15292
  68. package/dist/insertRequiredColumns.js +19 -0
  69. package/dist/inspectWorkflow.js +1 -0
  70. package/dist/instanceMembership.js +98 -0
  71. package/dist/ivm.js +125 -0
  72. package/dist/kvDataStore.js +86 -0
  73. package/dist/kvFacade.js +32 -0
  74. package/dist/matcher.js +304 -0
  75. package/dist/memoryColumnDefaults.js +11 -0
  76. package/dist/memoryQueryJoins.js +114 -0
  77. package/dist/metrics.js +161 -0
  78. package/dist/observability.js +123 -0
  79. package/dist/observedGraph.js +52 -0
  80. package/dist/originGuard.js +116 -0
  81. package/dist/outbox.js +352 -0
  82. package/dist/pluginRefRules.js +65 -0
  83. package/dist/policyGuardResolver.js +55 -0
  84. package/dist/preview.js +62 -0
  85. package/dist/projectedRows.js +12 -0
  86. package/dist/provenance.js +63 -0
  87. package/dist/rangeIndex.js +89 -0
  88. package/dist/rawReadScope.js +17 -0
  89. package/dist/reaction.js +85 -0
  90. package/dist/reactiveConfig.js +11 -0
  91. package/dist/readClassification.js +57 -0
  92. package/dist/readRecorder.js +66 -0
  93. package/dist/rebac.js +104 -0
  94. package/dist/rebacInterceptor.js +81 -0
  95. package/dist/registry.js +29 -0
  96. package/dist/relevantFields.js +65 -0
  97. package/dist/replicaHealth.js +42 -0
  98. package/dist/replicaLocality.js +44 -0
  99. package/dist/replicaObservations.js +121 -0
  100. package/dist/replicaSelection.js +32 -0
  101. package/dist/replicatedDataStore.js +239 -0
  102. package/dist/requestLoader.js +7 -0
  103. package/dist/resumeCensus.js +28 -0
  104. package/dist/revalidation.js +22 -0
  105. package/dist/rowFilter.js +65 -0
  106. package/dist/rowStateBytes.js +45 -0
  107. package/dist/rpcBodyCap.js +63 -0
  108. package/dist/rpcConnections.js +83 -0
  109. package/dist/rpcDefectDiagnostics.js +15 -0
  110. package/dist/rpcServer.js +992 -0
  111. package/dist/runAsSystem.js +23 -0
  112. package/dist/rywPositionStore.js +84 -0
  113. package/dist/schedule.js +23 -0
  114. package/dist/scheduleBackfillRequests.js +151 -0
  115. package/dist/scheduleClaimsTable.js +11 -0
  116. package/dist/scheduleRunsTable.js +37 -0
  117. package/dist/scheduler.js +835 -0
  118. package/dist/schemaRegistry.js +65 -0
  119. package/dist/secretsResolver.js +35 -0
  120. package/dist/securityHeaders.js +33 -0
  121. package/dist/servePipeline.js +305 -0
  122. package/dist/serverOnlyAudit.js +66 -0
  123. package/dist/serverTracer.js +15 -0
  124. package/dist/serviceCredentials.js +40 -0
  125. package/dist/singleNodeOrchestrator.js +91 -0
  126. package/dist/sourceResolution.js +42 -0
  127. package/dist/storeMiddleware.js +880 -0
  128. package/dist/storeQuery.js +204 -0
  129. package/dist/storeRead.js +10 -0
  130. package/dist/subscriber.js +7 -0
  131. package/dist/subscriptionOutbox.js +139 -0
  132. package/dist/subscriptionRegistry.js +82 -0
  133. package/dist/subscriptionResume.js +132 -0
  134. package/dist/subscriptionSocketMetrics.js +65 -0
  135. package/dist/systemSubject.js +5 -0
  136. package/dist/tenantScope.js +23 -0
  137. package/dist/tenantSelection.js +27 -0
  138. package/dist/timeline.js +105 -0
  139. package/dist/traceContext.js +5 -0
  140. package/dist/traceSink.js +63 -0
  141. package/dist/traceSpansTable.js +29 -0
  142. package/dist/traceparent.js +34 -0
  143. package/dist/transactionSubject.js +12 -0
  144. package/dist/trustedProxy.js +155 -0
  145. package/dist/undo.js +129 -0
  146. package/dist/undoBuiltins.js +69 -0
  147. package/dist/undoCapture.js +74 -0
  148. package/dist/undoLogTable.js +16 -0
  149. package/dist/upsertBinding.js +20 -0
  150. package/dist/wakeOrchestrator.js +34 -0
  151. package/dist/wakeRegistry.js +71 -0
  152. package/dist/wakeRouter.js +63 -0
  153. package/dist/wakeSupervisor.js +62 -0
  154. package/dist/wakeupsTable.js +12 -0
  155. package/dist/webSocketGatewayRuntime.js +114 -0
  156. package/dist/webhookVerification.js +18 -0
  157. package/dist/wireColumnStrip.js +84 -0
  158. package/dist/workflowReadBuiltins.js +87 -0
  159. package/dist/workflowRuntime.js +708 -0
  160. package/package.json +7 -7
@@ -0,0 +1,74 @@
1
+ import { eq as e } from "@voltro/database";
2
+ //#region src/undoCapture.ts
3
+ var t = (e = process.env) => {
4
+ let t = (e.VOLTRO_UNDO ?? "").toLowerCase();
5
+ return t === "on" || t === "1" || t === "true" ? !0 : t === "off" || t === "0" || t === "false" ? !1 : e.NODE_ENV !== "production";
6
+ }, n = (e = process.env) => {
7
+ let t = (e.VOLTRO_UNDO ?? "").toLowerCase();
8
+ return t !== "off" && t !== "0" && t !== "false";
9
+ }, r = (e) => e.startsWith("_voltro"), i = async (t, n, r) => (await t.query({
10
+ table: n,
11
+ predicate: e("id", r),
12
+ order: []
13
+ }))[0] ?? null, a = (e, t, n = () => /* @__PURE__ */ new Set()) => new Proxy(e, { get(e, a, o) {
14
+ let s = (e, t) => {
15
+ if (t === null) return null;
16
+ let r = n(e);
17
+ if (r.size === 0) return t;
18
+ let i = {};
19
+ for (let [e, n] of Object.entries(t)) r.has(e) || (i[e] = n);
20
+ return i;
21
+ };
22
+ if (a === "insert") return async (n, i) => {
23
+ let a = await e.insert(n, i);
24
+ return r(n) || t({
25
+ table: n,
26
+ op: "insert",
27
+ next: a
28
+ }), a;
29
+ };
30
+ if (a === "update") return async (a, o, c) => {
31
+ let l = n(a), u = Object.keys(c);
32
+ if (l.size > 0 && u.length > 0 && u.every((e) => l.has(e))) return await e.update(a, o, c);
33
+ let d = r(a) ? null : s(a, await i(e, a, o)), f = await e.update(a, o, c);
34
+ return r(a) || t({
35
+ table: a,
36
+ op: "update",
37
+ id: o,
38
+ prev: d,
39
+ next: s(a, f)
40
+ }), f;
41
+ };
42
+ if (a === "delete") return async (n, a) => {
43
+ let o = r(n) ? null : await i(e, n, a), s = await e.delete(n, a);
44
+ return !r(n) && s && t({
45
+ table: n,
46
+ op: "delete",
47
+ id: a,
48
+ prev: o
49
+ }), s;
50
+ };
51
+ let c = Reflect.get(e, a, o);
52
+ return typeof c == "function" ? c.bind(e) : c;
53
+ } }), o = (e, t = () => /* @__PURE__ */ new Set()) => {
54
+ let n = [];
55
+ return {
56
+ tx: a(e, (e) => n.push(e), t),
57
+ persist: async (e, t) => {
58
+ if (n.length === 0 || t.tag.startsWith("__voltro")) return;
59
+ let r = t.subject;
60
+ await e.insert("_voltro_undo_log", {
61
+ tag: t.tag,
62
+ label: t.tag,
63
+ subjectId: r?.id ?? null,
64
+ tenantId: r?.tenantId ?? null,
65
+ traceId: t.traceId ?? null,
66
+ changes: JSON.stringify(n),
67
+ crossesAction: !1,
68
+ undone: !1
69
+ });
70
+ }
71
+ };
72
+ };
73
+ //#endregion
74
+ export { o as makeUndoCapture, t as undoCaptureEnabled, n as undoSurfaceEnabled, a as wrapCaptureStore };
@@ -0,0 +1,16 @@
1
+ import { boolean as e, id as t, table as n, text as r, timestamp as i } from "@voltro/database";
2
+ //#region src/undoLogTable.ts
3
+ var a = n("_voltro_undo_log", {
4
+ id: t({ prefix: "undo" }),
5
+ tag: r(),
6
+ label: r().nullable(),
7
+ subjectId: r().nullable(),
8
+ tenantId: r().nullable(),
9
+ traceId: r().nullable(),
10
+ changes: r().serverOnly(),
11
+ crossesAction: e().default(!1),
12
+ undone: e().default(!1),
13
+ createdAt: i().default("now")
14
+ }).index(["subjectId", "createdAt"]);
15
+ //#endregion
16
+ export { a as _voltroUndoLogTable };
@@ -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,114 @@
1
+ import { Effect as e } from "effect";
2
+ import { GATEWAY_CREDENTIAL_EXPIRED_CLOSE_CODE as t } from "@voltro/protocol";
3
+ import { Socket as n } from "effect/socket";
4
+ //#region src/webSocketGatewayRuntime.ts
5
+ var r = (r, i, a, o, s, c, l) => e.scoped(e.gen(function* () {
6
+ let u = yield* r.writer, d = yield* e.context(), f = new AbortController(), p = a.limits?.maxMessageBytes ?? 1048576, m = a.limits?.maxPendingBytes ?? 4194304, h = a.limits?.maxPendingMessages ?? 64, g = [], _ = [], v = 0, y, b = 0, x, S, C, w = !1, T = !1, E = () => {
7
+ let e = x;
8
+ x = void 0;
9
+ try {
10
+ e?.();
11
+ } catch (e) {
12
+ l(e);
13
+ }
14
+ }, D = (e) => {
15
+ if (!f.signal.aborted) {
16
+ f.abort(e), S !== void 0 && clearTimeout(S), g.length = 0, y?.reject(e);
17
+ for (let t = v; t < _.length; t += 1) _[t]?.reject(e);
18
+ _.length = 0, v = 0, b = 0, E();
19
+ }
20
+ }, O = (t = 1e3, r) => {
21
+ f.signal.aborted || (D(Error(r ?? "gateway closed")), !(T || i.destroyed) && (T = !0, C = setTimeout(() => i.destroy(), 1e3), C.unref(), w ? e.runPromiseWith(d)(u.write(new n.CloseEvent(t, r))).catch(() => i.destroy()) : i.destroy()));
22
+ }, k = () => new Promise((e, t) => {
23
+ if (f.signal.aborted || i.destroyed) {
24
+ t(/* @__PURE__ */ Error("gateway closed"));
25
+ return;
26
+ }
27
+ let n = () => {
28
+ t(/* @__PURE__ */ Error("gateway closed"));
29
+ };
30
+ f.signal.addEventListener("abort", n, { once: !0 }), i.write(/* @__PURE__ */ new Uint8Array(), (r) => {
31
+ f.signal.removeEventListener("abort", n), r ? t(r) : e();
32
+ });
33
+ }), A = async () => {
34
+ if (y !== void 0 || f.signal.aborted) return;
35
+ let t = _[v];
36
+ if (t) {
37
+ _[v] = void 0, v += 1, v === _.length ? (_.length = 0, v = 0) : v >= 1024 && v * 2 >= _.length && (_.splice(0, v), v = 0), y = t;
38
+ try {
39
+ if (await e.runPromiseWith(d)(u.write(t.data), { signal: f.signal }), await k(), f.signal.aborted) throw Error("gateway closed");
40
+ t.resolve();
41
+ } catch (e) {
42
+ t.reject(e instanceof Error ? e : /* @__PURE__ */ Error("gateway write failed")), O(1011, "gateway write failed");
43
+ } finally {
44
+ f.signal.aborted || (b -= t.size), y = void 0, f.signal.aborted || A();
45
+ }
46
+ }
47
+ }, j = (e) => {
48
+ if (f.signal.aborted) return Promise.reject(/* @__PURE__ */ Error("gateway closed"));
49
+ let t = typeof e == "string" ? Buffer.byteLength(e) : e.byteLength;
50
+ if (t > p) return O(1009, "gateway message too large"), Promise.reject(/* @__PURE__ */ Error("gateway message too large"));
51
+ if (t > m - b || _.length - v + +!!y >= h) return O(1013, "gateway outbound queue exceeded"), Promise.reject(/* @__PURE__ */ Error("gateway outbound queue exceeded"));
52
+ b += t;
53
+ let n = new Promise((n, r) => {
54
+ _.push({
55
+ data: typeof e == "string" ? e : e.slice(),
56
+ size: t,
57
+ resolve: n,
58
+ reject: r
59
+ });
60
+ });
61
+ return A(), n;
62
+ }, M = {
63
+ send: (e) => {
64
+ j(e).catch(() => {});
65
+ },
66
+ sendAsync: j,
67
+ signal: f.signal,
68
+ close: O,
69
+ onMessage: (e) => {
70
+ f.signal.aborted || g.push(e);
71
+ },
72
+ subject: o,
73
+ headers: s,
74
+ path: a.path
75
+ }, N = () => D(/* @__PURE__ */ Error("gateway disconnected")), P = () => O(1011, "gateway transport failed");
76
+ i.once("close", N), i.once("error", P), yield* e.addFinalizer(() => e.sync(() => {
77
+ D(/* @__PURE__ */ Error("gateway stopped")), C !== void 0 && clearTimeout(C), i.off("close", N), i.off("error", P), i.destroy();
78
+ }));
79
+ let F = (e) => {
80
+ if (!f.signal.aborted) {
81
+ if (e.byteLength > p) O(1009, "gateway message too large");
82
+ else try {
83
+ for (let t of g) t(e);
84
+ } catch (e) {
85
+ l(e), O(1011, "gateway message handler failed");
86
+ }
87
+ }
88
+ }, I = e.sync(() => {
89
+ if (w = !0, c !== void 0) {
90
+ let e = c - Date.now();
91
+ if (e <= 0) {
92
+ O(t, "credential expired");
93
+ return;
94
+ }
95
+ S = setTimeout(() => O(t, "credential expired"), e), S.unref();
96
+ }
97
+ Promise.resolve().then(() => {
98
+ if (!f.signal.aborted) return a.onConnection(M);
99
+ }).then((e) => {
100
+ typeof e == "function" && (x = e), f.signal.aborted && E();
101
+ }, (e) => {
102
+ l(e), O(1011, "gateway setup failed");
103
+ });
104
+ });
105
+ yield* e.gen(function* () {
106
+ let e = yield* r.reader;
107
+ for (yield* I;;) {
108
+ let t = yield* e.pull;
109
+ for (let e of t) F(typeof e == "string" ? new TextEncoder().encode(e) : e);
110
+ }
111
+ }).pipe(e.ignore);
112
+ }));
113
+ //#endregion
114
+ export { r 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 };