@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,204 @@
1
+ import { NO_ROW_FILTER as e } from "./rowFilter.js";
2
+ import { Schema as t } from "effect";
3
+ import { and as n, contains as r, eq as i, getTable as a, gt as o, gte as s, inSet as c, isNull as l, lt as u, lte as d, neq as f, queryFor as p, startsWith as m } from "@voltro/database";
4
+ import { NoRowFound as h, NoRowFound as g } from "@voltro/protocol";
5
+ //#region src/storeQuery.ts
6
+ var _ = (e, t) => t === void 0 ? new h(e) : t(e), v = class extends t.TaggedError()("OptimisticLockError", {
7
+ table: t.String,
8
+ expected: t.Number
9
+ }) {
10
+ get message() {
11
+ return `optimistic lock failed on '${this.table}': expected version ${this.expected}`;
12
+ }
13
+ }, y = (e) => typeof e == "object" && !!e && ("and" in e || "or" in e || "not" in e || "op" in e || "subquery" in e), b = (e) => {
14
+ if (e.length === 1 && y(e[0])) return e[0];
15
+ if (e.length !== 2 && e.length !== 3 || typeof e[0] != "string") throw TypeError("where(): pass a predicate, (column, value), or (column, operator, value)");
16
+ let t = e[0];
17
+ if (e.length === 2) return i(t, e[1]);
18
+ let n = e[1], a = e[2];
19
+ switch (n) {
20
+ case "=": return i(t, a);
21
+ case "!=":
22
+ case "<>": return f(t, a);
23
+ case ">": return o(t, a);
24
+ case ">=": return s(t, a);
25
+ case "<": return u(t, a);
26
+ case "<=": return d(t, a);
27
+ case "in": return c(t, a);
28
+ case "contains":
29
+ case "fts": return r(t, a);
30
+ case "startsWith": return m(t, a);
31
+ default: throw TypeError("where(): unsupported comparison operator; use contains or startsWith for text matching");
32
+ }
33
+ }, x = (e) => {
34
+ let t = a(e);
35
+ if (t === void 0) throw Error(`unknown table '${e}' — is it declared with table()?`);
36
+ return p(t);
37
+ }, S = class t {
38
+ backend;
39
+ scope;
40
+ table;
41
+ query;
42
+ skipTenant;
43
+ skipSoftDelete;
44
+ constructor(e, t, n, r, i = !1, a = !1) {
45
+ this.backend = e, this.scope = t, this.table = n, this.query = r, this.skipTenant = i, this.skipSoftDelete = a;
46
+ }
47
+ clone(e) {
48
+ return new t(this.backend, this.scope, this.table, e, this.skipTenant, this.skipSoftDelete);
49
+ }
50
+ where(...e) {
51
+ return this.clone(this.query.where(b(e)));
52
+ }
53
+ orderBy(e, t = "asc") {
54
+ return this.clone(this.query.orderBy(e, t));
55
+ }
56
+ limit(e) {
57
+ return this.clone(this.query.limit(e));
58
+ }
59
+ forUpdate() {
60
+ return this.clone(this.query.forUpdate());
61
+ }
62
+ offset(e) {
63
+ return this.clone(this.query.offset(e));
64
+ }
65
+ select(...e) {
66
+ return this.clone(this.query.select(...e));
67
+ }
68
+ using(e) {
69
+ return this.clone(this.query.using(e));
70
+ }
71
+ with(e) {
72
+ return this.clone(this.query.with(e));
73
+ }
74
+ groupBy(e) {
75
+ return this.clone(this.query.groupBy(e));
76
+ }
77
+ matching(e, t) {
78
+ return this.clone(this.query.matching(e, t));
79
+ }
80
+ unscoped() {
81
+ return new t(this.backend, this.scope, this.table, this.query, !0, this.skipSoftDelete);
82
+ }
83
+ withDeleted() {
84
+ return new t(this.backend, this.scope, this.table, this.query, this.skipTenant, !0);
85
+ }
86
+ scopedQuery() {
87
+ let t = this.query, { subject: n, schemaRegistry: r } = this.scope;
88
+ !this.skipTenant && r.hasTenant(this.table) && n.tenantId != null && (t = t.where(i("tenantId", n.tenantId))), !this.skipSoftDelete && r.hasSoftDelete(this.table) && (t = t.where(l("deletedAt")));
89
+ let a = (this.scope.rowFilter ?? e)(this.table);
90
+ return a !== void 0 && (t = t.where(a)), t;
91
+ }
92
+ async all() {
93
+ return this.backend.query(this.scopedQuery().descriptor);
94
+ }
95
+ async maybeOne() {
96
+ return (await this.backend.query(this.scopedQuery().limit(1).descriptor))[0] ?? null;
97
+ }
98
+ first() {
99
+ return this.maybeOne();
100
+ }
101
+ async one(e) {
102
+ let t = await this.backend.query(this.scopedQuery().limit(2).descriptor), n = t[0];
103
+ if (n === void 0) throw _({
104
+ table: this.table,
105
+ found: 0
106
+ }, e);
107
+ if (t.length > 1) throw _({
108
+ table: this.table,
109
+ found: t.length
110
+ }, e);
111
+ return n;
112
+ }
113
+ async count() {
114
+ let e = (await this.backend.query(this.scopedQuery().count().descriptor))[0]?.count;
115
+ return typeof e == "number" ? e : Number(e ?? 0);
116
+ }
117
+ async exists() {
118
+ return (await this.backend.query(this.scopedQuery().limit(1).descriptor)).length > 0;
119
+ }
120
+ get descriptor() {
121
+ return this.scopedQuery().descriptor;
122
+ }
123
+ }, C = class {
124
+ backend;
125
+ scope;
126
+ table;
127
+ predicate;
128
+ skipTenant = !1;
129
+ expectedVersion;
130
+ constructor(e, t, n) {
131
+ this.backend = e, this.scope = t, this.table = n;
132
+ }
133
+ where(...e) {
134
+ let t = b(e);
135
+ return this.predicate = this.predicate ? n(this.predicate, t) : t, this;
136
+ }
137
+ unscoped() {
138
+ return this.skipTenant = !0, this;
139
+ }
140
+ expectVersion(e) {
141
+ return this.expectedVersion = e, this;
142
+ }
143
+ scopedWhere() {
144
+ let e = this.predicate, { subject: t, schemaRegistry: r } = this.scope;
145
+ if (!this.skipTenant && r.hasTenant(this.table) && t.tenantId != null) {
146
+ let r = i("tenantId", t.tenantId);
147
+ e = e ? n(e, r) : r;
148
+ }
149
+ if (this.expectedVersion !== void 0) {
150
+ let t = i("version", this.expectedVersion);
151
+ e = e ? n(e, t) : t;
152
+ }
153
+ if (e === void 0) throw Error(`update('${this.table}') needs a .where(...) clause`);
154
+ return e;
155
+ }
156
+ async set(e) {
157
+ let t = await this.backend.updateMany(this.table, e, { where: this.scopedWhere() });
158
+ if (this.expectedVersion !== void 0 && t === 0) throw new v({
159
+ table: this.table,
160
+ expected: this.expectedVersion
161
+ });
162
+ return t;
163
+ }
164
+ async restore() {
165
+ return this.backend.updateMany(this.table, { deletedAt: null }, { where: this.scopedWhere() });
166
+ }
167
+ }, w = class {
168
+ backend;
169
+ scope;
170
+ table;
171
+ predicate;
172
+ skipTenant = !1;
173
+ constructor(e, t, n) {
174
+ this.backend = e, this.scope = t, this.table = n;
175
+ }
176
+ where(...e) {
177
+ let t = b(e);
178
+ return this.predicate = this.predicate ? n(this.predicate, t) : t, this;
179
+ }
180
+ unscoped() {
181
+ return this.skipTenant = !0, this;
182
+ }
183
+ scopedWhere() {
184
+ let e = this.predicate, { subject: t, schemaRegistry: r } = this.scope;
185
+ if (!this.skipTenant && r.hasTenant(this.table) && t.tenantId != null) {
186
+ let r = i("tenantId", t.tenantId);
187
+ e = e ? n(e, r) : r;
188
+ }
189
+ if (e === void 0) throw Error(`delete('${this.table}') needs a .where(...) clause`);
190
+ return e;
191
+ }
192
+ async soft() {
193
+ return this.backend.updateMany(this.table, { deletedAt: /* @__PURE__ */ new Date() }, { where: this.scopedWhere() });
194
+ }
195
+ async hard() {
196
+ return this.backend.deleteMany(this.table, { where: this.scopedWhere() });
197
+ }
198
+ }, T = (e, t) => ({
199
+ select: (n) => new S(e, t, n, x(n)),
200
+ updateWhere: (n) => new C(e, t, n),
201
+ deleteWhere: (n) => new w(e, t, n)
202
+ });
203
+ //#endregion
204
+ export { w as DeleteBuilder, g as NoRowFound, v as OptimisticLockError, S as SelectBuilder, C as UpdateBuilder, T as makeFluentStore, _ as missingRowError };
@@ -0,0 +1,10 @@
1
+ //#region src/storeRead.ts
2
+ var e = async (e, t) => {
3
+ let n = "descriptor" in t ? t.descriptor : t;
4
+ return (await e.query({
5
+ ...n,
6
+ take: 1
7
+ }))[0] ?? null;
8
+ };
9
+ //#endregion
10
+ export { e as readMaybeOne };
@@ -0,0 +1,7 @@
1
+ //#region src/subscriber.ts
2
+ var e = (e) => {
3
+ if (e.once !== void 0 && e.eachReplica === !0) throw Error("defineSubscriber: choose either `once` or `eachReplica: true`, not both");
4
+ return e;
5
+ };
6
+ //#endregion
7
+ export { e as defineSubscriber };
@@ -0,0 +1,139 @@
1
+ import { createSubscriptionBufferMetric as e, recordCoalesced as t, recordOverrun as n, recordOversized as r, recordStalled as i } from "./subscriptionSocketMetrics.js";
2
+ import { createRowStateByteEstimator as a } from "./rowStateBytes.js";
3
+ import { MutableList as o } from "effect";
4
+ import { createRowPatchApplier as s, diffRows as c, isIdKeyed as l } from "@voltro/protocol";
5
+ import { createLogger as u } from "@voltro/logger";
6
+ //#region src/subscriptionOutbox.ts
7
+ var d = u({ scope: "voltro:subscription" }), f = 1048576, p = 1e4, m = 262144, h = 5e3, g = Symbol.for("@voltro/runtime/reactiveSocketTunables"), _ = (e) => {
8
+ let t = globalThis;
9
+ t[g] = e;
10
+ }, v = () => globalThis[g] ?? {
11
+ maxBufferedBytes: 1048576,
12
+ overrunAfterMs: 1e4,
13
+ oversizedEventBytes: 262144,
14
+ stallWarnAfterMs: 5e3
15
+ }, y = (e) => {
16
+ try {
17
+ let t = JSON.stringify(e);
18
+ return t === void 0 ? 0 : t.length;
19
+ } catch {
20
+ return 0;
21
+ }
22
+ }, b = (i) => {
23
+ let u = i.now ?? Date.now, f = i.crdt !== void 0 && i.crdt.columns.size > 0 ? i.crdt : void 0, p = f === void 0 ? {} : { mergeCell: f.merge }, m = f === void 0 ? {} : { crdt: {
24
+ columns: f.columns,
25
+ incremental: f.incremental
26
+ } }, h = i.warn ?? ((e, t) => {
27
+ d.warn(e, t);
28
+ }), g, _, v, b = 0, x = o.make(), S, C, w = !1, T = !1, E, D = () => E !== void 0, O = a(), k = s(), A = e(i.label), j = () => {
29
+ g = void 0, k.reset(), O.reset();
30
+ }, M = (e) => {
31
+ if (e._tag === "snapshot") O.reset(), k.reset(), v = e.data;
32
+ else if (e._tag === "delta") {
33
+ let t = v ?? g;
34
+ v = t === void 0 ? void 0 : k.apply(t, e.patch, p);
35
+ }
36
+ }, N = (e) => (t(i.label, b), e._tag === "delta" && v !== void 0 && g !== void 0 && Array.isArray(g) && Array.isArray(v) && l(g) && l(v) ? {
37
+ _tag: "delta",
38
+ revision: e.revision,
39
+ emittedAt: e.emittedAt,
40
+ patch: c(g, v, m)
41
+ } : v === void 0 ? e : e._tag === "snapshot" ? {
42
+ ...e,
43
+ data: v
44
+ } : {
45
+ _tag: "snapshot",
46
+ revision: e.revision,
47
+ data: v
48
+ }), P = (e) => {
49
+ let t = E;
50
+ E = void 0, t?.(e);
51
+ };
52
+ return {
53
+ push: (e) => {
54
+ if (w || T) return;
55
+ let t = y(e._tag === "snapshot" ? e.data : e._tag === "delta" ? e.patch : void 0);
56
+ if (t > i.oversizedEventBytes && (r(i.label), h(`subscription '${i.label}': oversized ${e._tag} (${t} bytes > ${i.oversizedEventBytes})`, {
57
+ label: i.label,
58
+ tag: e._tag,
59
+ bytes: t,
60
+ threshold: i.oversizedEventBytes
61
+ })), e._tag === "error") {
62
+ if (D() && _ === void 0 && x.length === 0) {
63
+ P(e);
64
+ return;
65
+ }
66
+ o.append(x, e);
67
+ return;
68
+ }
69
+ if (D() && _ === void 0) {
70
+ M(e), g = v ?? g, v = void 0, P(e);
71
+ return;
72
+ }
73
+ _ !== void 0 && (b += 1), M(e), _ = e, S === void 0 && (S = u());
74
+ let a = O.estimate(v ?? [], y, e._tag === "delta");
75
+ if (A(a), a > i.maxBufferedBytes) {
76
+ if (C === void 0 && (C = u()), u() - C >= i.overrunAfterMs) {
77
+ T = !0, n(i.label);
78
+ let e = {
79
+ _tag: "SubscriptionOverrun",
80
+ message: `subscription '${i.label}' overran its socket buffer: the consumer stayed ${a} bytes behind (max ${i.maxBufferedBytes}) for ${i.overrunAfterMs}ms. Re-subscribe for a fresh snapshot.`,
81
+ bufferedBytes: a,
82
+ maxBufferedBytes: i.maxBufferedBytes
83
+ };
84
+ _ = void 0, v = void 0, j(), A(0), x = o.make(), o.append(x, {
85
+ _tag: "error",
86
+ error: e
87
+ }), h(`subscription '${i.label}': overrun — closing with SubscriptionOverrun`, {
88
+ label: i.label,
89
+ bufferedBytes: a,
90
+ maxBufferedBytes: i.maxBufferedBytes
91
+ });
92
+ }
93
+ } else C = void 0;
94
+ },
95
+ take: () => {
96
+ if (_ !== void 0) {
97
+ let e = _, t = b > 0 ? N(e) : e;
98
+ return _ = void 0, b = 0, S = void 0, C = void 0, A(0), g = v ?? g, v = void 0, w && j(), Promise.resolve(t);
99
+ }
100
+ if (x.length !== 0) {
101
+ let e = o.take(x);
102
+ return T && x.length === 0 && (w = !0), Promise.resolve(e);
103
+ }
104
+ return w || T ? Promise.resolve(null) : new Promise((e) => {
105
+ E = e;
106
+ });
107
+ },
108
+ overrun: () => T,
109
+ close: () => {
110
+ w = !0, A(0), _ === void 0 || b === 0 ? j() : k.reset(), P(null);
111
+ }
112
+ };
113
+ }, x = async (e, t, n, r) => {
114
+ let a = r?.stallWarnAfterMs ?? v().stallWarnAfterMs, o = r?.warn ?? ((e, t) => {
115
+ d.warn(e, t);
116
+ });
117
+ for (;;) {
118
+ let r = await e.take();
119
+ if (r === null) {
120
+ t.end();
121
+ return;
122
+ }
123
+ let s = setTimeout(() => {
124
+ i(n), o(`subscription '${n}': the transport has not accepted a delivery for ${a}ms — the consumer is not acknowledging chunks. Every effect/rpc Chunk must be answered with { _tag: 'Ack', requestId }; the typed client does this itself, a hand-rolled socket client must. Updates coalesce behind the stall and are delivered once the socket accepts again.`, {
125
+ label: n,
126
+ tag: r._tag,
127
+ stallWarnAfterMs: a
128
+ });
129
+ }, a);
130
+ typeof s == "object" && s && "unref" in s && s.unref();
131
+ try {
132
+ await t.single(r);
133
+ } finally {
134
+ clearTimeout(s);
135
+ }
136
+ }
137
+ };
138
+ //#endregion
139
+ export { f as DEFAULT_SOCKET_MAX_BUFFERED_BYTES, p as DEFAULT_SOCKET_OVERRUN_AFTER_MS, m as DEFAULT_SOCKET_OVERSIZED_EVENT_BYTES, h as DEFAULT_SOCKET_STALL_WARN_AFTER_MS, b as makeSubscriptionOutbox, x as pumpOutbox, v as reactiveSocketTunables, _ as setReactiveSocketTunables };
@@ -0,0 +1,82 @@
1
+ import { fingerprintFor as e } from "./fingerprint.js";
2
+ //#region src/subscriptionRegistry.ts
3
+ var t = class {
4
+ matcher;
5
+ byFingerprint = /* @__PURE__ */ new Map();
6
+ byClient = /* @__PURE__ */ new Map();
7
+ changeListeners = /* @__PURE__ */ new Set();
8
+ constructor(e) {
9
+ this.matcher = e;
10
+ }
11
+ onChange(e) {
12
+ return this.changeListeners.add(e), () => {
13
+ this.changeListeners.delete(e);
14
+ };
15
+ }
16
+ notifyChange() {
17
+ for (let e of this.changeListeners) try {
18
+ e();
19
+ } catch {}
20
+ }
21
+ subscribe(t, n, r, i) {
22
+ let a = e(n, r, i?.name), o = this.byFingerprint.get(a);
23
+ return o ? (o.subscribers.add(t), this.byClient.set(t, a), this.notifyChange(), {
24
+ fingerprint: a,
25
+ deduplicated: !0
26
+ }) : (this.byFingerprint.set(a, {
27
+ table: n,
28
+ predicate: r,
29
+ subscribers: /* @__PURE__ */ new Set([t]),
30
+ ...i === void 0 ? {} : { usingIndex: i }
31
+ }), this.byClient.set(t, a), this.matcher.register({
32
+ id: a,
33
+ table: n,
34
+ predicate: r,
35
+ ...i === void 0 ? {} : { usingIndex: i }
36
+ }), this.notifyChange(), {
37
+ fingerprint: a,
38
+ deduplicated: !1
39
+ });
40
+ }
41
+ unsubscribe(e) {
42
+ let t = this.byClient.get(e);
43
+ if (!t) return;
44
+ let n = this.byFingerprint.get(t);
45
+ n && (n.subscribers.delete(e), this.byClient.delete(e), n.subscribers.size === 0 && (this.matcher.unregister(t, n.table), this.byFingerprint.delete(t)), this.notifyChange());
46
+ }
47
+ notify(e) {
48
+ let t = this.matcher.match(e), n = [];
49
+ for (let e of t) {
50
+ let t = this.byFingerprint.get(e.subId);
51
+ if (t) for (let r of t.subscribers) n.push({
52
+ subscriberId: r,
53
+ fingerprint: e.subId,
54
+ oldMatched: e.oldMatched,
55
+ newMatched: e.newMatched
56
+ });
57
+ }
58
+ return n;
59
+ }
60
+ stats() {
61
+ let e = 0;
62
+ for (let t of this.byFingerprint.values()) e += t.subscribers.size;
63
+ return {
64
+ fingerprints: this.byFingerprint.size,
65
+ subscribers: e,
66
+ dedupRatio: e === 0 ? 1 : this.byFingerprint.size / e
67
+ };
68
+ }
69
+ snapshot() {
70
+ let e = [];
71
+ for (let [t, n] of this.byFingerprint) e.push({
72
+ fingerprint: t,
73
+ table: n.table,
74
+ predicate: n.predicate,
75
+ subscriberCount: n.subscribers.size,
76
+ ...n.usingIndex === void 0 ? {} : { usingIndex: n.usingIndex }
77
+ });
78
+ return e;
79
+ }
80
+ };
81
+ //#endregion
82
+ export { t as SubscriptionRegistry };
@@ -0,0 +1,132 @@
1
+ import { BoundedRing as e } from "@voltro/protocol";
2
+ //#region src/subscriptionResume.ts
3
+ var t = 6e4, n = 256, r = Symbol.for("@voltro/runtime:resume-tunables"), i = (e) => {
4
+ let t = globalThis;
5
+ t[r] = e;
6
+ }, a = () => globalThis[r] ?? {
7
+ windowMs: 6e4,
8
+ maxDeltas: 256
9
+ }, o = (e) => `${e.label}\u0000${e.inputKey}\u0000${e.subjectId}\u0000${e.tenantId}`, s = (e) => {
10
+ let t = (e) => {
11
+ if (Array.isArray(e)) return e.map(t);
12
+ if (typeof e == "object" && e) {
13
+ let n = Object.entries(e).sort(([e], [t]) => e.localeCompare(t));
14
+ for (let e = 0; e < n.length; e++) {
15
+ let r = n[e];
16
+ r[1] = t(r[1]);
17
+ }
18
+ return Object.fromEntries(n);
19
+ }
20
+ return e;
21
+ };
22
+ try {
23
+ return JSON.stringify(t(e)) ?? "undefined";
24
+ } catch {
25
+ return "uncanonical";
26
+ }
27
+ }, c = Symbol.for("@voltro/runtime:resume-rings"), l = () => {
28
+ let e = globalThis;
29
+ return e[c] ??= /* @__PURE__ */ new Map();
30
+ }, u = Symbol.for("@voltro/runtime:resume-cleanup"), d = 32, f = (e, t) => {
31
+ let n = l(), r = globalThis, i = r[u];
32
+ (i === void 0 || i.rings !== n) && (i = {
33
+ rings: n,
34
+ cursor: void 0
35
+ }, r[u] = i), i.cursor ??= n.entries();
36
+ for (let r = 0; r < d; r++) {
37
+ let r = i.cursor.next();
38
+ if (r.done) {
39
+ i.cursor = void 0;
40
+ break;
41
+ }
42
+ let [a, o] = r.value;
43
+ e - o.touchedAt > t && n.delete(a);
44
+ }
45
+ }, p = (e, t, n) => {
46
+ let r = l(), i = r.get(e);
47
+ if (i !== void 0 && t - i.touchedAt > n) r.delete(e);
48
+ else return i;
49
+ }, m = (e) => Number.isNaN(e) ? Infinity : Math.max(0, Math.floor(e)), h = (t, n) => {
50
+ if (n === t.capacity) return;
51
+ let r = Math.max(0, t.deltas.length - n);
52
+ r > 0 && (t.baseRevision = t.deltas.get(r - 1).revision);
53
+ let i = new e(n);
54
+ for (let e = r; e < t.deltas.length; e++) i.push(t.deltas.get(e));
55
+ t.deltas = i, t.capacity = n;
56
+ }, g = (t, n, r = Date.now(), i = a()) => {
57
+ f(r, i.windowMs);
58
+ let s = l(), c = o(t);
59
+ if (n._tag === "error") {
60
+ s.delete(c);
61
+ return;
62
+ }
63
+ if (n._tag === "snapshot") {
64
+ let t = m(i.maxDeltas);
65
+ s.set(c, {
66
+ baseRevision: n.revision,
67
+ headRevision: n.revision,
68
+ deltas: new e(t),
69
+ capacity: t,
70
+ touchedAt: r
71
+ });
72
+ return;
73
+ }
74
+ let u = p(c, r, i.windowMs);
75
+ u !== void 0 && (n.revision <= u.headRevision ? s.delete(c) : (h(u, m(i.maxDeltas)), u.capacity === 0 ? u.baseRevision = n.revision : u.deltas.length === u.capacity && (u.baseRevision = u.deltas.get(0).revision), u.deltas.push({
76
+ revision: n.revision,
77
+ emittedAt: n.emittedAt,
78
+ patch: n.patch
79
+ }), u.headRevision = n.revision, u.touchedAt = r));
80
+ }, _ = (e, t, n = Date.now(), r = a()) => {
81
+ f(n, r.windowMs);
82
+ let i = p(o(e), n, r.windowMs);
83
+ if (i === void 0 || t < i.baseRevision || t > i.headRevision) return { kind: "snapshot" };
84
+ let s = 0, c = i.deltas.length;
85
+ for (; s < c;) {
86
+ let e = s + Math.floor((c - s) / 2);
87
+ i.deltas.get(e).revision > t ? c = e : s = e + 1;
88
+ }
89
+ let l = [];
90
+ for (let e = s; e < i.deltas.length; e++) l.push(i.deltas.get(e));
91
+ return {
92
+ kind: "deltas",
93
+ deltas: l
94
+ };
95
+ }, v = () => {
96
+ l().clear();
97
+ let e = globalThis;
98
+ delete e[u];
99
+ }, y = Symbol.for("@voltro/runtime:resume-detached"), b = () => {
100
+ let e = globalThis;
101
+ return e[y] ??= /* @__PURE__ */ new Map();
102
+ }, x = (e, t, n = a(), r = Date.now) => {
103
+ let i = o(e), s = l(), c = b().get(i);
104
+ c !== void 0 && (clearTimeout(c.timer), c.unsubscribe(), b().delete(i));
105
+ let u = {
106
+ sink: t.sink,
107
+ unsubscribe: t.unsubscribe,
108
+ dead: !1,
109
+ timer: setTimeout(() => {
110
+ b().delete(i), s.delete(i), t.unsubscribe();
111
+ }, n.windowMs)
112
+ };
113
+ typeof u.timer.unref == "function" && u.timer.unref(), t.sink.current = (t) => {
114
+ g(e, t, r(), n), t._tag === "error" && (u.dead = !0);
115
+ }, b().set(i, u);
116
+ }, S = (e, t, n = Date.now(), r = a()) => {
117
+ let i = o(e), s = b().get(i);
118
+ if (s === void 0) return;
119
+ clearTimeout(s.timer), b().delete(i);
120
+ let c = s.dead ? { kind: "snapshot" } : _(e, t, n, r);
121
+ if (c.kind !== "deltas" || c.deltas.length === 0) l().delete(i), s.unsubscribe();
122
+ else return {
123
+ deltas: c.deltas,
124
+ sink: s.sink,
125
+ unsubscribe: s.unsubscribe
126
+ };
127
+ }, C = () => {
128
+ for (let e of b().values()) clearTimeout(e.timer), e.unsubscribe();
129
+ b().clear();
130
+ };
131
+ //#endregion
132
+ export { n as DEFAULT_RESUME_MAX_DELTAS, t as DEFAULT_RESUME_WINDOW_MS, S as adoptDetached, _ as answerResume, s as canonicalInputKey, x as detachForResume, g as recordForResume, C as resetDetachedForTest, v as resetResumeRingsForTest, o as resumeKeyOf, a as resumeTunables, i as setResumeTunables };
@@ -0,0 +1,65 @@
1
+ //#region src/subscriptionSocketMetrics.ts
2
+ var e = Symbol.for("@voltro/runtime/subscriptionSocketMetrics"), t = () => {
3
+ let t = globalThis;
4
+ return t[e] ??= {
5
+ bufferedBytes: /* @__PURE__ */ new Map(),
6
+ bufferOwners: /* @__PURE__ */ new WeakMap(),
7
+ coalescedTotal: /* @__PURE__ */ new Map(),
8
+ overrunTotal: /* @__PURE__ */ new Map(),
9
+ oversizedTotal: /* @__PURE__ */ new Map(),
10
+ stalledTotal: /* @__PURE__ */ new Map()
11
+ };
12
+ }, n = (e, t, n = 1) => {
13
+ e.set(t, (e.get(t) ?? 0) + n);
14
+ }, r = (e, n) => {
15
+ let r = t();
16
+ n === 0 ? r.bufferedBytes.delete(e) : r.bufferedBytes.set(e, n);
17
+ }, i = (e) => {
18
+ let n = {};
19
+ return (r) => {
20
+ let i = t(), a = i.bufferOwners.get(n) ?? 0;
21
+ r === 0 ? i.bufferOwners.delete(n) : i.bufferOwners.set(n, r);
22
+ let o = (i.bufferedBytes.get(e) ?? 0) + r - a;
23
+ o === 0 ? i.bufferedBytes.delete(e) : i.bufferedBytes.set(e, o);
24
+ };
25
+ }, a = (e, r) => {
26
+ n(t().coalescedTotal, e, r);
27
+ }, o = (e) => {
28
+ n(t().overrunTotal, e);
29
+ }, s = (e) => {
30
+ n(t().oversizedTotal, e);
31
+ }, c = (e) => {
32
+ n(t().stalledTotal, e);
33
+ }, l = (e) => {
34
+ let t = 0, n = {};
35
+ for (let [r, i] of e) t += i, n[r] = i;
36
+ return {
37
+ total: t,
38
+ byLabel: n
39
+ };
40
+ }, u = () => {
41
+ let e = t();
42
+ return {
43
+ bufferedBytes: l(e.bufferedBytes),
44
+ coalescedTotal: l(e.coalescedTotal),
45
+ overrunTotal: l(e.overrunTotal),
46
+ oversizedTotal: l(e.oversizedTotal),
47
+ stalledTotal: l(e.stalledTotal)
48
+ };
49
+ }, d = () => {
50
+ let e = t(), n = [], r = (e, t, r, i) => {
51
+ for (let [a, o] of r) n.push({
52
+ name: e,
53
+ type: t,
54
+ labels: { query: a },
55
+ value: o,
56
+ description: i
57
+ });
58
+ };
59
+ return r("voltro_subscription_buffered_bytes", "gauge", e.bufferedBytes, "Estimated pending bytes a blocked subscription consumer is behind (0 rows omitted)."), r("voltro_subscription_coalesced_total", "counter", e.coalescedTotal, "Subscription events collapsed into a newer state while the consumer was blocked."), r("voltro_subscription_overrun_total", "counter", e.overrunTotal, "Subscriptions terminally closed with SubscriptionOverrun (consumer persistently over the buffer threshold)."), r("voltro_subscription_oversized_total", "counter", e.oversizedTotal, "Subscription events exceeding the oversized-event WARN threshold (telemetry, not a cap)."), r("voltro_subscription_stalled_total", "counter", e.stalledTotal, "Subscription deliveries the transport did not accept within reactive.socket.stallWarnAfterMs (the consumer is not acknowledging chunks)."), n;
60
+ }, f = () => {
61
+ let e = t();
62
+ e.bufferOwners = /* @__PURE__ */ new WeakMap(), e.bufferedBytes.clear(), e.coalescedTotal.clear(), e.overrunTotal.clear(), e.oversizedTotal.clear(), e.stalledTotal.clear();
63
+ };
64
+ //#endregion
65
+ export { i as createSubscriptionBufferMetric, a as recordCoalesced, o as recordOverrun, s as recordOversized, c as recordStalled, f as resetSubscriptionSocketMetrics, r as setBufferedBytes, d as subscriptionSocketMetricSamples, u as subscriptionSocketMetricsSnapshot };
@@ -0,0 +1,5 @@
1
+ import { systemSubject as e } from "@voltro/protocol";
2
+ //#region src/systemSubject.ts
3
+ var t = e("system");
4
+ //#endregion
5
+ export { t as SYSTEM_SUBJECT };
@@ -0,0 +1,23 @@
1
+ import { and as e, eq as t, isNull as n } from "@voltro/database";
2
+ //#region src/tenantScope.ts
3
+ var r = (n, r, i) => {
4
+ if (n.crossTenant || !r.has(n.table) || i == null) return n;
5
+ let a = t("tenantId", i);
6
+ return {
7
+ ...n,
8
+ predicate: n.predicate ? e(n.predicate, a) : a
9
+ };
10
+ }, i = (e, t, n) => n === "" && !e.crossTenant && t.has(e.table), a = (e) => e?.type === "user" && e.tenantId === "", o = (t, r) => {
11
+ if (t.includeDeleted || !r.has(t.table)) return t;
12
+ let i = n("deletedAt");
13
+ return {
14
+ ...t,
15
+ predicate: t.predicate ? e(t.predicate, i) : i
16
+ };
17
+ }, s = (e) => (t, n) => {
18
+ e.observe?.beforeScope?.({ ...t }, n);
19
+ let i = o(r(t, e.tenantScopedTables, n.tenantId), e.softDeleteScopedTables);
20
+ return e.observe?.afterScope?.({ ...i }), i;
21
+ };
22
+ //#endregion
23
+ export { o as applySoftDeleteScope, r as applyTenantScope, i as isEmptyTenantScopedRead, a as isOrglessUserSubject, s as makeQueryFinalizer };