@voltro/runtime 0.86.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 (70) hide show
  1. package/CHANGELOG.md +5321 -0
  2. package/README.md +43 -0
  3. package/THIRD-PARTY-NOTICES.md +860 -221
  4. package/dist/analyticsSink.js +8 -14
  5. package/dist/apiKeys.js +82 -78
  6. package/dist/apiRoleBucketSampler.js +64 -0
  7. package/dist/apiRoleWorkloadHistory.js +56 -0
  8. package/dist/apiRoleWorkloadMetrics.js +78 -0
  9. package/dist/apiRoleWorkloadStorage.js +95 -0
  10. package/dist/approvals.js +67 -74
  11. package/dist/authMiddlewareLayer.js +7 -6
  12. package/dist/bindEvent.js +48 -28
  13. package/dist/bootListener.js +106 -39
  14. package/dist/bootStoreCodec.js +38 -37
  15. package/dist/circuitBreaker.js +1 -72
  16. package/dist/composeAnalytics.js +31 -10
  17. package/dist/computedQueryCache.js +231 -0
  18. package/dist/connectionsFacade.js +32 -30
  19. package/dist/coordinatedSchedule.js +84 -78
  20. package/dist/dataStore.js +154 -121
  21. package/dist/declaredTablesGuard.js +2 -1
  22. package/dist/dispatcher.js +403 -328
  23. package/dist/effectStore.js +2 -2
  24. package/dist/engineClients.js +24 -0
  25. package/dist/externalizedTasks.js +19 -6
  26. package/dist/fieldCipher.js +109 -40
  27. package/dist/fieldKeyRegistry.js +295 -0
  28. package/dist/fieldKeyRekey.js +286 -0
  29. package/dist/fieldKeyScan.js +136 -0
  30. package/dist/fieldKeyring.js +77 -0
  31. package/dist/hot.d.ts +56 -0
  32. package/dist/hot.js +3 -0
  33. package/dist/hotDataStore.js +148 -0
  34. package/dist/hotDataStoreSnapshot.js +98 -0
  35. package/dist/hotDataStoreTables.js +18 -0
  36. package/dist/http-range.d.ts +53 -0
  37. package/dist/http-range.js +52 -0
  38. package/dist/httpClientSsrf.js +12 -37
  39. package/dist/httpClientTracing.js +12 -9
  40. package/dist/httpCompression.js +17 -17
  41. package/dist/httpInputStream.js +82 -0
  42. package/dist/httpRouteMounts.js +1 -0
  43. package/dist/idempotencyStore.js +92 -52
  44. package/dist/index.d.ts +1164 -451
  45. package/dist/index.js +143 -132
  46. package/dist/kvFacade.js +23 -17
  47. package/dist/memoryQueryJoins.js +16 -16
  48. package/dist/memorySetOperations.js +43 -0
  49. package/dist/metrics.js +38 -24
  50. package/dist/outbox.js +1 -1
  51. package/dist/readRecorder.js +35 -34
  52. package/dist/readScopePredicate.js +12 -0
  53. package/dist/replicatedDataStore.js +22 -4
  54. package/dist/rowFilter.js +56 -39
  55. package/dist/rpcConnections.js +8 -8
  56. package/dist/rpcServer.js +522 -449
  57. package/dist/rpcWorkloadAdmission.js +50 -0
  58. package/dist/rywPositionStore.js +82 -47
  59. package/dist/scheduler.js +6 -1
  60. package/dist/servePipeline.js +215 -146
  61. package/dist/setReadScopes.js +28 -0
  62. package/dist/snapshotValueCodec.js +46 -0
  63. package/dist/sourceResolution.js +34 -24
  64. package/dist/storeMiddleware.js +211 -209
  65. package/dist/subscriber.js +1 -0
  66. package/dist/tenantScope.js +8 -20
  67. package/dist/traceparent.js +8 -19
  68. package/dist/webSocketGatewayRuntime.js +111 -71
  69. package/dist/workflowRuntime.js +9 -9
  70. package/package.json +19 -7
@@ -1,19 +1,22 @@
1
- import { cronForInterval as e, externalizationRefusal as t, registerExternalizedTask as n, unregisterExternalizedTask as r } from "./externalizedTasks.js";
1
+ import { cronForInterval as e, externalizationRefusal as t, registerExternalizedTask as n } from "./externalizedTasks.js";
2
2
  //#region src/coordinatedSchedule.ts
3
- var i = (e) => {
3
+ var r = (e) => {
4
4
  if (e === void 0) return null;
5
5
  let t = e.nextDueInMs;
6
6
  return {
7
7
  idle: e.idle === !0,
8
8
  ...t === null ? { nextDueInMs: null } : typeof t == "number" && Number.isFinite(t) ? { nextDueInMs: t } : {}
9
9
  };
10
- }, a = /* @__PURE__ */ new WeakMap(), o = (e) => a.get(e)?.() ?? null, s = 3e4, c = (e = process.env) => {
10
+ }, i = /* @__PURE__ */ new WeakMap(), a = (e) => i.get(e)?.() ?? null, o = 3e4, s = (e = process.env) => {
11
11
  let t = e.VOLTRO_POLL_CEILING_MS;
12
- if (t === void 0) return s;
12
+ if (t === void 0) return o;
13
13
  let n = Number(t);
14
- return Number.isFinite(n) && n > 0 ? n : s;
15
- }, l = (o, s, l, d) => {
16
- let f = Math.max(s, d.maxIdleIntervalMs ?? c()), p = !1, m, h = !1, g = s, _ = !1, v = !1, y = 0, b = null, x = {
14
+ return Number.isFinite(n) && n > 0 ? n : o;
15
+ }, c = (a, o, c, u) => {
16
+ let d = Math.max(o, u.maxIdleIntervalMs ?? s()), f = !1, p, m = /* @__PURE__ */ new Set(), h = (e) => {
17
+ let t = Promise.resolve().then(e);
18
+ return m.add(t), t.then(() => m.delete(t), () => m.delete(t)), t;
19
+ }, g, _ = !1, v = o, y = !1, b = !1, x = 0, S = null, C = {
17
20
  ticks: 0,
18
21
  claimWins: 0,
19
22
  claimLosses: 0,
@@ -25,115 +28,118 @@ var i = (e) => {
25
28
  lastWakeAt: null,
26
29
  lastDecision: "starting",
27
30
  lastOutcome: null
28
- }, S = (e) => {
29
- p || (m !== void 0 && clearTimeout(m), m = void 0, b = null, e === "disarm" ? h = !0 : (h = !1, g = Math.max(0, Math.min(e, f)), b = Date.now() + g, m = setTimeout(() => {
30
- C();
31
- }, g), typeof m.unref == "function" && m.unref()));
32
- }, C = async () => {
33
- if (p) return;
34
- if (_) {
35
- v = !0;
31
+ }, w = (e) => {
32
+ f || (g !== void 0 && clearTimeout(g), g = void 0, S = null, e === "disarm" ? _ = !0 : (_ = !1, v = Math.max(0, Math.min(e, d)), S = Date.now() + v, g = setTimeout(() => {
33
+ E();
34
+ }, v), typeof g.unref == "function" && g.unref()));
35
+ }, T = async () => {
36
+ if (f) return;
37
+ if (y) {
38
+ b = !0;
36
39
  return;
37
40
  }
38
- x.ticks++, x.lastTickAt = Date.now(), x.lastOutcome = null, b = null, _ = !0;
39
- let e = new Date(Math.floor(Date.now() / s) * s);
41
+ C.ticks++, C.lastTickAt = Date.now(), C.lastOutcome = null, S = null, y = !0;
42
+ let e = new Date(Math.floor(Date.now() / o) * o);
40
43
  try {
41
44
  let t = !1;
42
45
  try {
43
- t = await d.coordinator.tryClaim(o, e, s);
46
+ t = await u.coordinator.tryClaim(a, e, o);
44
47
  } catch (e) {
45
- x.claimFailures++, x.lastDecision = "claim-failed", d.log?.warn("coordinated schedule: claim check failed — skipping this tick", {
46
- task: o,
48
+ C.claimFailures++, C.lastDecision = "claim-failed", u.log?.warn("coordinated schedule: claim check failed — skipping this tick", {
49
+ task: a,
47
50
  reason: e?.message ?? String(e)
48
- }), S(s);
51
+ }), w(o);
49
52
  return;
50
53
  }
51
54
  if (!t) {
52
- x.claimLosses++, x.lastDecision = "claim-lost", S(s);
55
+ C.claimLosses++, C.lastDecision = "claim-lost", w(o);
53
56
  return;
54
57
  }
58
+ if (f) return;
55
59
  let n;
56
- x.claimWins++;
60
+ C.claimWins++;
57
61
  try {
58
- n = await l();
62
+ n = await c();
59
63
  } catch (e) {
60
- x.taskFailures++, x.lastDecision = "task-failed", d.log?.warn("coordinated schedule: task threw", {
61
- task: o,
64
+ C.taskFailures++, C.lastDecision = "task-failed", u.log?.warn("coordinated schedule: task threw", {
65
+ task: a,
62
66
  reason: e?.message ?? String(e)
63
- }), S(s);
67
+ }), w(o);
64
68
  return;
65
69
  }
66
- x.lastOutcome = i(n);
67
- let r = u(x.lastOutcome ?? void 0, s, g, f, d.disarmWhenIdle ?? !1);
68
- x.lastDecision = r === "disarm" ? "idle-disarmed" : n?.idle ? "idle-backoff" : "active", S(r);
70
+ C.lastOutcome = r(n);
71
+ let i = l(C.lastOutcome ?? void 0, o, v, d, u.disarmWhenIdle ?? !1);
72
+ C.lastDecision = i === "disarm" ? "idle-disarmed" : n?.idle ? "idle-backoff" : "active", w(i);
69
73
  } finally {
70
- _ = !1, v && !p && (v = !1, S(0));
74
+ y = !1, b && !f && (b = !1, w(0));
71
75
  }
72
- }, w = async () => {
73
- x.ticks++, x.lastTickAt = Date.now(), x.lastOutcome = null;
74
- let e = new Date(Math.floor(Date.now() / s) * s), t;
76
+ }, E = () => f ? Promise.resolve() : h(T), D = async () => {
77
+ if (f) throw Error("Coordinated schedule is stopped");
78
+ C.ticks++, C.lastTickAt = Date.now(), C.lastOutcome = null;
79
+ let e = new Date(Math.floor(Date.now() / o) * o), t;
75
80
  try {
76
- t = await (d.externalClaim ?? d.coordinator).tryClaim(o, e, s);
81
+ t = await (u.externalClaim ?? u.coordinator).tryClaim(a, e, o);
77
82
  } catch (e) {
78
- throw x.claimFailures++, x.lastDecision = "claim-failed", e;
83
+ throw C.claimFailures++, C.lastDecision = "claim-failed", e;
79
84
  }
80
- if (!t) return x.claimLosses++, x.lastDecision = "claim-lost", "deduplicated";
81
- x.claimWins++;
85
+ if (!t) return C.claimLosses++, C.lastDecision = "claim-lost", "deduplicated";
86
+ if (f) throw Error("Coordinated schedule is stopped");
87
+ C.claimWins++;
82
88
  try {
83
- let e = await l();
84
- x.lastOutcome = i(e), x.lastDecision = "active";
89
+ let e = await c();
90
+ C.lastOutcome = r(e), C.lastDecision = "active";
85
91
  } catch (e) {
86
- throw x.taskFailures++, x.lastDecision = "task-failed", e;
92
+ throw C.taskFailures++, C.lastDecision = "task-failed", e;
87
93
  }
88
94
  return "ran";
89
- }, T = d.externalize === !0 ? t(o, s) : void 0, E = d.externalize === !0 && T === void 0;
90
- T !== void 0 && d.log?.warn(`coordinated schedule: REFUSING to externalise this task — ${T}`, {
91
- task: o,
92
- intervalMs: s
93
- }), E ? (n({
94
- name: o,
95
- intervalMs: s,
96
- cron: e(s),
97
- run: w
98
- }), d.log?.info("coordinated schedule: externalised — no in-process timer", {
99
- task: o,
100
- intervalMs: s
101
- })) : S(s);
102
- let D = {
103
- name: o,
104
- currentIntervalMs: () => g,
105
- isArmed: () => !p && !h && !E,
95
+ }, O = () => f ? Promise.reject(/* @__PURE__ */ Error("Coordinated schedule is stopped")) : h(D), k = u.externalize === !0 ? t(a, o) : void 0, A = u.externalize === !0 && k === void 0;
96
+ k !== void 0 && u.log?.warn(`coordinated schedule: REFUSING to externalise this task — ${k}`, {
97
+ task: a,
98
+ intervalMs: o
99
+ });
100
+ let j;
101
+ A ? (j = (u.externalTasks?.register ?? n)({
102
+ name: a,
103
+ intervalMs: o,
104
+ cron: e(o),
105
+ run: O
106
+ }), u.log?.info("coordinated schedule: externalised — no in-process timer", {
107
+ task: a,
108
+ intervalMs: o
109
+ })) : w(o);
110
+ let M = {
111
+ name: a,
112
+ currentIntervalMs: () => v,
113
+ isArmed: () => !f && !_ && !A,
106
114
  wake: () => {
107
- if (p) return;
108
- x.wakes++, x.lastWakeAt = Date.now();
115
+ if (f) return;
116
+ C.wakes++, C.lastWakeAt = Date.now();
109
117
  let e = Date.now();
110
- !h && e - y < s ? x.coalescedWakes++ : (x.lastDecision = "wake", y = e, _ ? v = !0 : S(0));
118
+ !_ && e - x < o ? C.coalescedWakes++ : (C.lastDecision = "wake", x = e, y ? b = !0 : w(0));
111
119
  },
112
- stop: () => {
113
- p || (p = !0, m !== void 0 && clearTimeout(m), m = void 0, b = null, E && r(o));
114
- }
120
+ stop: () => (p === void 0 && (f = !0, g !== void 0 && clearTimeout(g), g = void 0, S = null, j?.(), p = Promise.allSettled([...m]).then(() => {})), p)
115
121
  };
116
- return a.set(D, () => ({
117
- ...x,
118
- lastOutcome: x.lastOutcome === null ? null : { ...x.lastOutcome },
119
- task: o,
120
- state: p ? "stopped" : E ? "externalized" : _ ? "running" : h ? "disarmed" : "armed",
121
- baseIntervalMs: s,
122
- currentIntervalMs: g,
123
- maxIdleIntervalMs: f,
124
- nextTickAt: b,
125
- disarmWhenIdle: d.disarmWhenIdle ?? !1
126
- })), D;
127
- }, u = (e, t, n, r, i = !1) => {
122
+ return i.set(M, () => ({
123
+ ...C,
124
+ lastOutcome: C.lastOutcome === null ? null : { ...C.lastOutcome },
125
+ task: a,
126
+ state: f ? "stopped" : A ? "externalized" : y ? "running" : _ ? "disarmed" : "armed",
127
+ baseIntervalMs: o,
128
+ currentIntervalMs: v,
129
+ maxIdleIntervalMs: d,
130
+ nextTickAt: S,
131
+ disarmWhenIdle: u.disarmWhenIdle ?? !1
132
+ })), M;
133
+ }, l = (e, t, n, r, i = !1) => {
128
134
  if (e === void 0 || !e.idle) return t;
129
135
  let a = typeof e.nextDueInMs == "number" && Number.isFinite(e.nextDueInMs) ? e.nextDueInMs : void 0;
130
136
  if (a === void 0 && e.nextDueInMs === null && i) return "disarm";
131
137
  let o = Math.min(Math.max(n, t) * 2, r);
132
138
  return a === void 0 ? o : Math.max(t, i ? a : Math.min(o, a));
133
- }, d = (e) => (t, n, r, i) => l(t, n, r, {
139
+ }, u = (e) => (t, n, r, i) => c(t, n, r, {
134
140
  ...e,
135
141
  ...e.externalizeTask === void 0 ? {} : { externalize: e.externalizeTask(t) },
136
142
  ...i?.disarmWhenIdle === void 0 ? {} : { disarmWhenIdle: i.disarmWhenIdle }
137
143
  });
138
144
  //#endregion
139
- export { s as DEFAULT_MAX_IDLE_INTERVAL_MS, o as inspectCoordinatedSchedule, d as makeCoordinatedScheduler, u as nextDelay, c as readPollCeilingMs, l as scheduleCoordinated };
145
+ export { o as DEFAULT_MAX_IDLE_INTERVAL_MS, a as inspectCoordinatedSchedule, u as makeCoordinatedScheduler, l as nextDelay, s as readPollCeilingMs, c as scheduleCoordinated };