@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,70 +1,110 @@
1
1
  import { and as e, eq as t, generateId as n, lte as r } from "@voltro/database";
2
- import { freshFor as i, tsMs as a } from "@voltro/protocol";
2
+ import { freshFor as i } from "@voltro/protocol";
3
3
  //#region src/idempotencyStore.ts
4
- var o = "_voltro_idempotency", s = (e) => {
5
- if (e == null) return null;
6
- let t = typeof e == "string" ? JSON.parse(e) : e;
7
- return t && typeof t == "object" && "status" in t ? t : null;
8
- }, c = (e) => ({
9
- scope: e.scope,
10
- key: e.key,
11
- status: e.status === "completed" ? "completed" : "in_flight",
12
- response: s(e.response),
13
- createdAt: a(e.createdAt)
14
- }), l = async (n, r, i) => (await n.query({
15
- table: o,
4
+ var a = "_voltro_idempotency", o = () => /* @__PURE__ */ Error("Stored idempotency receipt is invalid"), s = (e) => {
5
+ if (e === null) return null;
6
+ try {
7
+ let t = typeof e == "string" ? JSON.parse(e) : e;
8
+ if (t === null) return null;
9
+ if (typeof t != "object") throw o();
10
+ let n = Object.getPrototypeOf(t);
11
+ if (n !== Object.prototype && n !== null) throw o();
12
+ let r = Object.getOwnPropertyDescriptor(t, "status"), i = r && "value" in r ? r.value : void 0;
13
+ if (typeof i != "number" || !Number.isInteger(i) || i < 100 || i > 999) throw o();
14
+ let a = Object.getOwnPropertyDescriptor(t, "body");
15
+ if (a && !("value" in a)) throw o();
16
+ let s = a?.value, c = Object.getOwnPropertyDescriptor(t, "rest");
17
+ if (c && !("value" in c)) throw o();
18
+ return {
19
+ status: i,
20
+ body: s,
21
+ ...c ? { rest: c.value } : {}
22
+ };
23
+ } catch {
24
+ throw o();
25
+ }
26
+ }, c = (e) => {
27
+ try {
28
+ let t = e instanceof Date ? Date.prototype.getTime.call(e) : typeof e == "number" || typeof e == "string" ? new Date(e).getTime() : NaN;
29
+ if (!Number.isFinite(t) || typeof e == "number" && t !== e) throw o();
30
+ return t;
31
+ } catch {
32
+ throw o();
33
+ }
34
+ }, l = (e) => {
35
+ if (typeof e.id != "string" || e.id.length === 0 || typeof e.scope != "string" || typeof e.key != "string" || e.status !== "in_flight" && e.status !== "completed" || e.inputHash != null && (typeof e.inputHash != "string" || !/^[0-9a-f]{64}$/.test(e.inputHash))) throw o();
36
+ let t = c(e.createdAt), n = s(e.response);
37
+ if (e.status === "in_flight" != (n === null)) throw o();
38
+ return {
39
+ scope: e.scope,
40
+ key: e.key,
41
+ inputHash: e.inputHash ?? null,
42
+ status: e.status,
43
+ response: n,
44
+ createdAt: t
45
+ };
46
+ }, u = async (n, r, i) => (await n.query({
47
+ table: a,
16
48
  predicate: e(t("scope", r), t("key", i)),
17
49
  order: [],
18
50
  take: 1,
19
51
  skip: void 0,
20
52
  projection: void 0
21
- }))[0] ?? null, u = (a) => ({
53
+ }))[0] ?? null, d = (n) => e(t("id", n.id), t("scope", n.scope), t("key", n.key), t("inputHash", n.inputHash), t("status", "in_flight")), f = (o) => ({
22
54
  get: async (e, t) => {
23
- let n = await l(a, e, t);
24
- return n ? c(n) : null;
55
+ let n = await u(o, e, t);
56
+ return n ? l(n) : null;
25
57
  },
26
- claim: async (s, u, d, f, p) => {
27
- for (let l = 0; l < 2; l++) {
28
- let l = n({
58
+ claim: async (s, c, d, f, p, m) => {
59
+ for (let u = 0; u < 2; u++) {
60
+ let u = n({
29
61
  kind: "typeid",
30
62
  prefix: "idem"
31
- }, o), m = await a.insertIgnore(o, {
32
- id: l,
63
+ }, a), h = await o.insertIgnore(a, {
64
+ id: u,
33
65
  scope: s,
34
- key: u,
66
+ key: c,
67
+ inputHash: d,
35
68
  status: "in_flight",
36
69
  response: null,
37
- createdAt: new Date(d)
38
- }, { conflictColumns: ["scope", "key"] });
39
- if (m.id === l) return "claimed";
40
- let h = c(m), g = i(h.status, f, p);
41
- if (d - h.createdAt < g) return h;
42
- await a.deleteMany(o, { where: e(t("id", m.id), r("createdAt", new Date(d - g))) });
70
+ createdAt: new Date(f)
71
+ }, { conflictColumns: ["scope", "key"] }), g = l(h);
72
+ if (h.id === u) {
73
+ if (g.scope !== s || g.key !== c || g.inputHash !== d || g.status !== "in_flight" || g.response !== null) throw Error("Idempotency acquisition did not retain the expected input witness");
74
+ return {
75
+ kind: "claimed",
76
+ claim: Object.freeze({
77
+ scope: s,
78
+ key: c,
79
+ id: u,
80
+ inputHash: d
81
+ })
82
+ };
83
+ }
84
+ if (g.inputHash !== d) return {
85
+ kind: "existing",
86
+ record: g
87
+ };
88
+ let _ = i(g.status, p, m);
89
+ if (f - g.createdAt < _) return {
90
+ kind: "existing",
91
+ record: g
92
+ };
93
+ await o.deleteMany(a, { where: e(t("id", h.id), t("scope", s), t("key", c), t("inputHash", d), t("status", h.status), r("createdAt", new Date(f - _))) });
43
94
  }
44
- let m = await l(a, s, u);
45
- return m ? c(m) : {
46
- scope: s,
47
- key: u,
48
- status: "in_flight",
49
- response: null,
50
- createdAt: d
51
- };
95
+ let h = await u(o, s, c);
96
+ return h ? {
97
+ kind: "existing",
98
+ record: l(h)
99
+ } : { kind: "conflict" };
52
100
  },
53
- complete: async (e, t, n, r) => {
54
- let i = await l(a, e, t);
55
- i && await a.update(o, i.id, {
56
- status: "completed",
57
- response: n
58
- });
59
- },
60
- renew: async (e, t, n) => {
61
- let r = await l(a, e, t);
62
- r !== null && r.status === "in_flight" && await a.update(o, r.id, { createdAt: new Date(n) });
63
- },
64
- release: async (e, t) => {
65
- let n = await l(a, e, t);
66
- n && await a.delete(o, n.id);
67
- }
101
+ complete: async (e, t, n) => await o.updateMany(a, {
102
+ status: "completed",
103
+ response: t,
104
+ createdAt: new Date(n)
105
+ }, { where: d(e) }) === 1,
106
+ renew: async (e, t) => await o.updateMany(a, { createdAt: new Date(t) }, { where: d(e) }) === 1,
107
+ release: async (e) => await o.deleteMany(a, { where: d(e) }) === 1
68
108
  });
69
109
  //#endregion
70
- export { u as dataStoreIdempotencyStore };
110
+ export { f as dataStoreIdempotencyStore };