@voltro/runtime 0.84.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 +1215 -0
  2. package/THIRD-PARTY-NOTICES.md +118 -600
  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 +252 -233
  67. package/dist/index.js +144 -14405
  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 +10 -13
@@ -0,0 +1,72 @@
1
+ import { recordEventDelivered as e, recordEventDropped as t } from "./metrics.js";
2
+ import { registerConnectionStream as n } from "./connectionCredentials.js";
3
+ import { boundByCredential as r } from "./credentialBound.js";
4
+ import { Effect as i, Queue as a, Stream as o } from "effect";
5
+ import { ConnectionInfo as s, SubjectService as c, checkGuardsEffect as l, isOpenAccess as u, recheckGuardsEffect as d } from "@voltro/protocol";
6
+ //#region src/bindEvent.ts
7
+ var f = 64, p = 1, m = (e) => e.kind === "gap" ? {
8
+ _tag: "gap",
9
+ missed: e.missed,
10
+ reason: e.reason
11
+ } : {
12
+ _tag: "event",
13
+ origin: e.envelope.origin,
14
+ n: e.envelope.n,
15
+ emittedAt: e.envelope.emittedAt,
16
+ payload: e.envelope.payload
17
+ }, h = (e) => {
18
+ let t = new Map(e ?? []);
19
+ return (e, n = 0) => {
20
+ let r = t.get(e.origin) ?? 0;
21
+ return t.set(e.origin, Math.max(r, e.n)), r === 0 && n === 0 ? 0 : Math.max(0, e.n - r - 1);
22
+ };
23
+ }, g = (f) => o.unwrap(i.gen(function* () {
24
+ let p = yield* c, g = yield* s, _ = p.tenantId ?? null, v = f.guards === void 0 ? void 0 : f.guards.filter((e) => !u(e));
25
+ if (v !== void 0 && v.length > 0 || p.type === "service") {
26
+ let e = yield* l(p, v ?? [], f.key);
27
+ if (e) return yield* i.fail(e);
28
+ }
29
+ let y = f.bus.deliveryFor(f.event) === "latest", b = yield* a.sliding(f.queueSize ?? (y ? 1 : 64)), x = /* @__PURE__ */ new Map(), S = f.bus.subscribe({
30
+ tenantId: _,
31
+ event: f.event,
32
+ key: f.key,
33
+ options: f.options,
34
+ onAttach: (e) => {
35
+ x = e;
36
+ },
37
+ listener: (e) => {
38
+ i.runSync(a.offer(b, e));
39
+ }
40
+ });
41
+ if (yield* i.addFinalizer(() => i.sync(() => {
42
+ S();
43
+ })), g.clientId !== void 0) {
44
+ let e = n(g.clientId, () => {
45
+ i.runPromise(a.shutdown(b));
46
+ });
47
+ yield* i.addFinalizer(() => i.sync(() => {
48
+ e();
49
+ }));
50
+ }
51
+ let C = y ? () => 0 : h(x), w = () => d(p, v, f.key), T = o.fromQueue(b).pipe(o.flatMap((e) => o.unwrap(w().pipe(i.map((t) => t ? o.fail(t) : E(e))))));
52
+ function E(n) {
53
+ return o.suspend(() => {
54
+ if (n.kind === "gap") return o.make(m(n));
55
+ let r = C(n.envelope, n.prior);
56
+ e(f.event);
57
+ let i = m(n);
58
+ if (r === 0) return o.make(i);
59
+ t(f.event, "buffer", r);
60
+ let a = {
61
+ _tag: "gap",
62
+ missed: r,
63
+ reason: "buffer"
64
+ };
65
+ return o.fromIterable([a, i]);
66
+ });
67
+ }
68
+ let D = { _tag: "attached" };
69
+ return r(o.concat(o.fromIterable([D]), T), g.credentialExpiresAt, o.fromIterable([D]));
70
+ }));
71
+ //#endregion
72
+ export { f as EVENT_CLIENT_QUEUE_SIZE, p as EVENT_LATEST_QUEUE_SIZE, g as bindEvent, h as makeBufferGapDetector };
@@ -0,0 +1,76 @@
1
+ import { answerProbe as e, probeFor as t, resolveHealth as n } from "./healthProbes.js";
2
+ import { createServer as r } from "node:http";
3
+ //#region src/bootListener.ts
4
+ var i = "no-store", a = "1", o = /* @__PURE__ */ new Set(["ready", "draining"]), s = async (s) => {
5
+ let c = s.now ?? Date.now, l = {
6
+ phase: "booting",
7
+ startedAt: c()
8
+ }, u, d, f = () => l.phase === "ready", p = () => o.has(l.phase), m = n(s.health, () => f()), h = s.health?.readiness === void 0 ? async () => f() && (d === void 0 || await d()) : m.readiness, g = {
9
+ ...m,
10
+ readiness: h
11
+ }, _ = () => ({
12
+ phase: l.phase,
13
+ ready: f(),
14
+ elapsedMs: c() - l.startedAt,
15
+ ...l.tablesTotal === void 0 ? {} : { tablesTotal: l.tablesTotal },
16
+ ...l.error === void 0 ? {} : { error: l.error }
17
+ }), v = r((n, r) => {
18
+ let o = n.url ?? "/", s = o.indexOf("?"), c = s === -1 ? o : o.slice(0, s), l = t(g, c);
19
+ l === void 0 ? u !== void 0 && p() ? u.request(n, r) : (r.writeHead(503, {
20
+ "content-type": "text/plain",
21
+ "cache-control": i,
22
+ "retry-after": a
23
+ }), r.end("starting")) : e(g, l, _).then((e) => {
24
+ r.writeHead(e.status, {
25
+ "content-type": e.contentType,
26
+ "cache-control": i
27
+ }), r.end(e.body);
28
+ });
29
+ });
30
+ v.on("upgrade", (e, t, n) => {
31
+ u !== void 0 && p() ? u.upgrade(e, t, n) : t.end(`HTTP/1.1 503 Service Unavailable\r
32
+ Retry-After: ${a}\r\nCache-Control: no-store\r
33
+ Connection: close\r
34
+ Content-Length: 0\r
35
+ \r
36
+ `);
37
+ }), await new Promise((e, t) => {
38
+ let n = (e) => {
39
+ t(e);
40
+ };
41
+ v.once("error", n), v.listen(s.host === void 0 ? { port: s.port } : {
42
+ port: s.port,
43
+ host: s.host
44
+ }, () => {
45
+ v.removeListener("error", n), e();
46
+ });
47
+ });
48
+ let y = v.address()?.port ?? s.port;
49
+ return s.log?.info("listening early — probes answer on the app port from here on", { port: y }), {
50
+ server: v,
51
+ port: y,
52
+ get state() {
53
+ return l;
54
+ },
55
+ set: (e) => {
56
+ l = {
57
+ ...l,
58
+ ...e
59
+ };
60
+ },
61
+ isReady: f,
62
+ delegate: (e) => {
63
+ u = e;
64
+ },
65
+ setDependencyPing: (e) => {
66
+ d = e;
67
+ },
68
+ close: () => new Promise((e) => {
69
+ v.listening ? (v.closeAllConnections(), v.close(() => {
70
+ e();
71
+ })) : e();
72
+ })
73
+ };
74
+ };
75
+ //#endregion
76
+ export { s as bindBootListener };
@@ -0,0 +1,7 @@
1
+ //#region src/bootRefusal.ts
2
+ var e = "VoltroBootRefusal", t = (t) => {
3
+ let n = Error(t);
4
+ return n.name = e, n;
5
+ }, n = (e) => typeof e == "object" && !!e && e.name === "VoltroBootRefusal";
6
+ //#endregion
7
+ export { e as BOOT_REFUSAL_NAME, t as bootRefusal, n as isBootRefusal };
@@ -0,0 +1,70 @@
1
+ import { getFieldCipher as e } from "./fieldCipher.js";
2
+ import { upsertDestinationId as t } from "./upsertBinding.js";
3
+ import { decryptFieldsOnRead as n, deserializeArraysOnRead as r, encryptFieldsForWrite as i, encryptFieldsForWriteBatch as a, encryptedColumnsOf as o, getTable as s, jsonPatchAssignments as c, serializeArraysForWrite as l, upsertUpdateValues as u } from "@voltro/database";
4
+ import { createLogger as d } from "@voltro/logger";
5
+ //#region src/bootStoreCodec.ts
6
+ var f = d({ scope: "store.fieldEncryption" }), p = (d, m) => {
7
+ let h = m, g = process.env.VOLTRO_FIELD_DECRYPT_ON_ERROR === "null" ? "null" : "throw", _ = /* @__PURE__ */ new Set(), v = (e) => {
8
+ let t = `${e.table}.${e.column}`;
9
+ _.has(t) || (_.add(t), f.warn("encrypted column degraded to null — could not decrypt with the active key", {
10
+ table: e.table,
11
+ column: e.column,
12
+ reason: e.reason,
13
+ hint: "VOLTRO_FIELD_DECRYPT_ON_ERROR=null is set — this row was likely encrypted under a different key"
14
+ }));
15
+ }, y = (t, n, r) => {
16
+ let a = s(t), o = h ? l(n, a, h) : n;
17
+ return i(o, a, e(), r);
18
+ }, b = (t, i, a) => {
19
+ let o = s(t), c = n(i, o, e(), {
20
+ onError: g,
21
+ ...g === "null" ? { warn: v } : {},
22
+ ...a === void 0 ? {} : { rowId: a }
23
+ });
24
+ return h ? r(c, o, h) : c;
25
+ }, x = (e, t, n) => t === null ? null : b(e, [t], n)[0];
26
+ return {
27
+ delete: (e, t) => d.delete(e, t),
28
+ deleteMany: (e, t) => d.deleteMany(e, t),
29
+ onChange: (e) => d.onChange(e),
30
+ injectExternalChange: (e) => {
31
+ d.injectExternalChange(e);
32
+ },
33
+ ...d.changeScope === void 0 ? {} : { changeScope: d.changeScope },
34
+ ...d.withNamespace === void 0 ? {} : { withNamespace: (e) => p(d.withNamespace(e), m) },
35
+ ...d.raw === void 0 ? {} : { raw: ((...e) => d.raw(...e)) },
36
+ ...d.close === void 0 ? {} : { close: (e) => d.close(e) },
37
+ ...d.ping === void 0 ? {} : { ping: () => d.ping() },
38
+ query: async (e) => b(e.table, await d.query(e)),
39
+ insert: async (e, t) => x(e, await d.insert(e, y(e, t))),
40
+ insertMany: async (t, n) => {
41
+ let r = s(t), i = h ? n.map((e) => l(e, r, h)) : n, o = a(i, r, e());
42
+ return b(t, await d.insertMany(t, o));
43
+ },
44
+ update: async (e, t, n) => x(e, await d.update(e, t, y(e, n, t)), t),
45
+ updateMany: async (e, t, n) => {
46
+ let r = s(e), i = (r === void 0 ? [] : o(r)).filter((e) => t[e] !== void 0 && t[e] !== null);
47
+ if (i.length > 0) throw Error(`updateMany on the boot store cannot write the .encrypted() column(s) ${i.join(", ")} on "${e}": an encrypted value is bound to its row and a set-based write has no row. Write them through the request-scoped store, or key the write with update(table, id, patch).`);
48
+ return d.updateMany(e, y(e, t), n);
49
+ },
50
+ upsert: async (e, n, r) => {
51
+ let i = u(r), a = await t(d, e, n, r.conflictColumns);
52
+ return x(e, await d.upsert(e, y(e, n, a), {
53
+ ...r,
54
+ ...r.updateValues === void 0 ? {} : { updateValues: y(e, i, a) }
55
+ }), a);
56
+ },
57
+ insertIgnore: async (e, t, n) => x(e, await d.insertIgnore(e, y(e, t), n)),
58
+ insertIgnoreWithOutcome: async (e, t, n) => {
59
+ let r = await d.insertIgnoreWithOutcome(e, y(e, t), n);
60
+ return {
61
+ row: x(e, r.row),
62
+ outcome: r.outcome
63
+ };
64
+ },
65
+ patchJson: async (e, t, n, r, i) => x(e, await d.patchJson(e, t, n, r, y(e, c(t, n, i), t)), t),
66
+ transactional: (e) => d.transactional((t) => e(p(t, m)))
67
+ };
68
+ };
69
+ //#endregion
70
+ export { p as wrapStoreWithBootCodec };
@@ -0,0 +1,67 @@
1
+ import { getTable as e } from "@voltro/database";
2
+ import { BusinessRuleViolation as t } from "@voltro/protocol";
3
+ import { log as n } from "@voltro/logger";
4
+ //#region src/businessRules.ts
5
+ var r = (e) => e.startsWith("_voltro"), i = (e) => {
6
+ let t = e?.id;
7
+ return typeof t == "string" ? t : void 0;
8
+ }, a = (e) => {
9
+ let t = /* @__PURE__ */ new Map(), n = (e, n) => {
10
+ if (n == null || r(e)) return;
11
+ let a = i(n);
12
+ a !== void 0 && t.set(`${e}\u0000${a}`, {
13
+ table: e,
14
+ id: a,
15
+ row: n
16
+ });
17
+ };
18
+ return {
19
+ tx: new Proxy(e, { get(e, t, r) {
20
+ if (t === "insert") return async (t, r) => {
21
+ let i = await e.insert.call(e, t, r);
22
+ return n(t, i), i;
23
+ };
24
+ if (t === "update") return async (t, r, i) => {
25
+ let a = await e.update.call(e, t, r, i);
26
+ return n(t, a ?? {
27
+ ...i,
28
+ id: r
29
+ }), a;
30
+ };
31
+ let i = Reflect.get(e, t, r);
32
+ return typeof i == "function" ? i.bind(e) : i;
33
+ } }),
34
+ drain: () => [...t.values()]
35
+ };
36
+ }, o = (e) => {
37
+ if (e !== !0 && e !== void 0) return e === !1 ? {} : e;
38
+ }, s = async (r) => {
39
+ if (r.touched.length === 0) return;
40
+ let i = {
41
+ store: r.store,
42
+ subject: r.subject
43
+ };
44
+ for (let { table: a, row: s } of r.touched) {
45
+ let r = e(a)?.appliedRules;
46
+ if (r !== void 0 && r.length !== 0) for (let e of r) {
47
+ let r = o(await e.predicate(s, i));
48
+ if (r !== void 0) {
49
+ if (e.severity === "warning") n.warn("business rule violated (warning)", {
50
+ rule: e.name,
51
+ table: a,
52
+ ...r.field === void 0 ? {} : { field: r.field },
53
+ ...r.params === void 0 ? {} : { params: r.params }
54
+ });
55
+ else throw new t({
56
+ rule: e.name,
57
+ severity: "error",
58
+ ...r.params === void 0 ? {} : { params: r.params },
59
+ ...r.field === void 0 ? {} : { field: r.field },
60
+ ...r.message === void 0 ? {} : { message: r.message }
61
+ });
62
+ }
63
+ }
64
+ }
65
+ };
66
+ //#endregion
67
+ export { s as evaluateTouchedRules, a as makeRuleCapture };
@@ -0,0 +1,12 @@
1
+ import { id as e, integer as t, table as n, text as r, timestamp as i } from "@voltro/database";
2
+ //#region src/changeClaimsTable.ts
3
+ var a = n("_voltro_change_claims", {
4
+ id: e({ prefix: "chclaim" }),
5
+ scope: r(),
6
+ key: r(),
7
+ claimedBy: r(),
8
+ claimedAt: i(),
9
+ nextSlot: t().default(0)
10
+ }).unique(["scope", "key"]).index(["claimedAt"]);
11
+ //#endregion
12
+ export { a as _voltroChangeClaimsTable };
@@ -0,0 +1,72 @@
1
+ import { Cause as e, Clock as t, Duration as n, Effect as r, Ref as i, Schema as a } from "effect";
2
+ //#region src/circuitBreaker.ts
3
+ var o = class extends a.TaggedError()("CircuitOpen", {
4
+ name: a.String,
5
+ retryAfterMs: a.Number
6
+ }) {}, s = {
7
+ tag: "closed",
8
+ failureCount: 0,
9
+ halfOpenSuccesses: 0,
10
+ openedAt: 0
11
+ }, c = { make: (a) => r.gen(function* () {
12
+ let c = a.name ?? "circuit", l = n.toMillis(n.fromInputUnsafe(a.resetTimeout)), u = a.halfOpenSuccessThreshold ?? 1, d = a.isFailure ?? (() => !0), f = yield* i.make(s), p = r.gen(function* () {
13
+ let e = yield* i.get(f);
14
+ if (e.tag === "half-open") {
15
+ let t = e.halfOpenSuccesses + 1;
16
+ yield* i.set(f, t >= u ? s : {
17
+ ...e,
18
+ halfOpenSuccesses: t
19
+ });
20
+ } else e.failureCount !== 0 && (yield* i.set(f, s));
21
+ }), m = r.gen(function* () {
22
+ let e = yield* t.currentTimeMillis, n = yield* i.get(f);
23
+ if (n.tag === "half-open" || n.tag === "open") {
24
+ yield* i.set(f, {
25
+ tag: "open",
26
+ failureCount: a.failureThreshold,
27
+ halfOpenSuccesses: 0,
28
+ openedAt: e
29
+ });
30
+ return;
31
+ }
32
+ let r = n.failureCount + 1;
33
+ yield* i.set(f, r >= a.failureThreshold ? {
34
+ tag: "open",
35
+ failureCount: r,
36
+ halfOpenSuccesses: 0,
37
+ openedAt: e
38
+ } : {
39
+ ...n,
40
+ failureCount: r
41
+ });
42
+ }), h = r.gen(function* () {
43
+ let e = yield* i.get(f);
44
+ if (e.tag !== "open") return null;
45
+ let n = (yield* t.currentTimeMillis) - e.openedAt;
46
+ return n >= l ? (yield* i.set(f, {
47
+ tag: "half-open",
48
+ failureCount: 0,
49
+ halfOpenSuccesses: 0,
50
+ openedAt: e.openedAt
51
+ }), null) : l - n;
52
+ }), g = (t) => r.gen(function* () {
53
+ let n = yield* h;
54
+ return n === null ? yield* t.pipe(r.tap(() => p), r.tapCause((t) => {
55
+ if (e.hasInterruptsOnly(t)) return r.void;
56
+ let n = e.findErrorOption(t), i = n._tag === "Some" ? n.value : void 0;
57
+ return d(i) ? m : r.void;
58
+ })) : yield* r.fail(new o({
59
+ name: c,
60
+ retryAfterMs: n
61
+ }));
62
+ }), _ = ((e) => g(e));
63
+ return Object.defineProperty(_, "state", {
64
+ value: i.get(f).pipe(r.map((e) => e.tag)),
65
+ enumerable: !0
66
+ }), Object.defineProperty(_, "reset", {
67
+ value: i.set(f, s),
68
+ enumerable: !0
69
+ }), _;
70
+ }) };
71
+ //#endregion
72
+ export { c as CircuitBreaker, o as CircuitOpen };
@@ -0,0 +1,23 @@
1
+ //#region src/columnOnUpdate.ts
2
+ var e = (e) => {
3
+ if (!(e.length < 32 || Object.getPrototypeOf(e) !== Array.prototype || Object.getOwnPropertySymbols(e).length > 0 || Object.hasOwn(e, "includes"))) {
4
+ for (let t = 0; t < e.length; t++) {
5
+ let n = Object.getOwnPropertyDescriptor(e, String(t));
6
+ if (n === void 0 || !("value" in n) || typeof n.value != "string") return;
7
+ }
8
+ return new Set(e);
9
+ }
10
+ }, t = (t, n, r, i = []) => {
11
+ let a = t.tables.get(n)?.onUpdateFields;
12
+ if (a === void 0 || a.size === 0) return r;
13
+ let o = { ...r }, s = a.size >= 32 ? e(i) : void 0;
14
+ for (let [e, t] of a) {
15
+ if (o[e] !== void 0 || (s?.has(e) ?? i.includes(e))) continue;
16
+ t !== "now" && (s = void 0);
17
+ let n = t === "now" ? /* @__PURE__ */ new Date() : t();
18
+ n === void 0 ? delete o[e] : o[e] = n;
19
+ }
20
+ return o;
21
+ };
22
+ //#endregion
23
+ export { t as applyColumnOnUpdate };
@@ -0,0 +1,108 @@
1
+ import { AnalyticsCapabilityNotSupported as e } from "./analyticsSink.js";
2
+ import { Effect as t } from "effect";
3
+ //#region src/composeAnalytics.ts
4
+ var n = "noop", r = () => {
5
+ let r = (r) => t.fail(new e({
6
+ provider: n,
7
+ capability: r
8
+ }));
9
+ return {
10
+ info: {
11
+ provider: n,
12
+ capabilities: {
13
+ track: !0,
14
+ aggregate: !1,
15
+ timeseries: !1,
16
+ topN: !1,
17
+ mirror: !1
18
+ }
19
+ },
20
+ track: () => t.void,
21
+ aggregate: () => r("aggregate"),
22
+ timeseries: () => r("timeseries"),
23
+ topN: () => r("topN")
24
+ };
25
+ }, i = (n) => {
26
+ if (n.length === 0) return r();
27
+ if (n.length === 1) return n[0];
28
+ let i = {
29
+ provider: "compose",
30
+ capabilities: {
31
+ track: n.some((e) => e.info.capabilities.track),
32
+ aggregate: n.some((e) => e.info.capabilities.aggregate),
33
+ timeseries: n.some((e) => e.info.capabilities.timeseries),
34
+ topN: n.some((e) => e.info.capabilities.topN),
35
+ mirror: n.some((e) => e.info.capabilities.mirror)
36
+ },
37
+ detail: { members: n.map((e) => e.info) }
38
+ }, a = (e) => t.forEach(n, (n) => n.track(e).pipe(t.catch((e) => t.logWarning(`analytics-sink ${n.info.provider} track failed`, { err: e }))), {
39
+ concurrency: "unbounded",
40
+ discard: !0
41
+ }), o = (r, i) => {
42
+ let a = n.find((e) => e.info.capabilities[r]);
43
+ return a === void 0 ? t.fail(new e({
44
+ provider: "compose",
45
+ capability: r
46
+ })) : i(a);
47
+ }, s = n.filter((e) => e.mirror !== void 0), c = s.every((e) => {
48
+ let t = Object.getOwnPropertyDescriptor(e, "mirror");
49
+ if (t === void 0 || !("value" in t)) return !1;
50
+ let n = Object.getOwnPropertyDescriptor(t.value, "tables");
51
+ if (n === void 0 || !("value" in n)) return !1;
52
+ let r = n.value;
53
+ if (!Array.isArray(r) || Object.getPrototypeOf(r) !== Array.prototype || r.includes !== Array.prototype.includes || r[Symbol.iterator] !== Array.prototype[Symbol.iterator]) return !1;
54
+ for (let e = 0; e < r.length; e++) {
55
+ let t = Object.getOwnPropertyDescriptor(r, String(e));
56
+ if (t === void 0 || !("value" in t) || typeof t.value != "string") return !1;
57
+ }
58
+ return !0;
59
+ }), l = /* @__PURE__ */ new Map();
60
+ for (let e of c ? s : []) for (let t of new Set(e.mirror.tables)) {
61
+ let n = l.get(t);
62
+ n === void 0 ? l.set(t, [e]) : n.push(e);
63
+ }
64
+ let u = (e) => c ? l.get(e) ?? [] : s.filter((t) => t.mirror.tables.includes(e)), d = s.length === 0 ? void 0 : {
65
+ tables: Array.from(new Set(s.flatMap((e) => e.mirror.tables))),
66
+ upsert: (e) => t.forEach(u(e.table), (t) => t.mirror.upsert(e), {
67
+ concurrency: "unbounded",
68
+ discard: !0
69
+ }),
70
+ remove: (e) => t.forEach(u(e.table), (t) => t.mirror.remove(e), {
71
+ concurrency: "unbounded",
72
+ discard: !0
73
+ }),
74
+ maxVersion: (e) => t.forEach(u(e.table), (t) => t.mirror.maxVersion(e), { concurrency: "unbounded" }).pipe(t.map((e) => {
75
+ let t = null;
76
+ for (let n of e) n !== null && (t = Math.max(t ?? -Infinity, n));
77
+ return t;
78
+ }))
79
+ };
80
+ return {
81
+ info: i,
82
+ track: a,
83
+ aggregate: (e) => o("aggregate", (t) => t.aggregate(e)),
84
+ timeseries: (e) => o("timeseries", (t) => t.timeseries(e)),
85
+ topN: (e) => o("topN", (t) => t.topN(e)),
86
+ ...d === void 0 ? {} : { mirror: d }
87
+ };
88
+ }, a = (e) => {
89
+ let n = e.filter((e) => e.dispose !== void 0);
90
+ return {
91
+ kind: "compose",
92
+ build: (t) => i(e.map((e) => e.build(t))),
93
+ tables: e.flatMap((e) => e.tables ?? []),
94
+ initialize: (n) => t.forEach(e, (e) => e.initialize ? e.initialize(n) : t.void, {
95
+ concurrency: 1,
96
+ discard: !0
97
+ }),
98
+ ...n.length > 0 ? { dispose: (e) => t.forEach(n, (t) => t.dispose(e), {
99
+ concurrency: 1,
100
+ discard: !0
101
+ }) } : {}
102
+ };
103
+ }, o = {
104
+ kind: "noop",
105
+ build: () => r()
106
+ };
107
+ //#endregion
108
+ export { n as NOOP_ANALYTICS_PROVIDER, a as composeAnalytics, i as composeAnalyticsSinks, r as noopAnalytics, o as noopAnalyticsSpec };
@@ -0,0 +1,4 @@
1
+ //#region src/computedQuery.ts
2
+ var e = (e) => typeof e == "object" && !!e && e.__voltroComputed === !0;
3
+ //#endregion
4
+ export { e as isComputedQuery };
@@ -0,0 +1,81 @@
1
+ import { beginOAuthConnect as e, forgetCredential as t, listConnectionStates as n, storeCredential as r } from "./connectionVault.js";
2
+ import { ConnectionHandshakeFailed as i, ConnectionKindMismatch as a, ConnectionNotDeclared as o, ConnectionSubjectRequired as s } from "@voltro/protocol";
3
+ //#region src/connectionBuiltins.ts
4
+ var c = (e, t) => {
5
+ let n = e.request?.subject?.id ?? null;
6
+ if (n === null || n === "") throw new s({ connectionId: t });
7
+ return n;
8
+ }, l = (e, t) => {
9
+ let n = e.registry.get(t);
10
+ if (n === void 0) throw new o({ connectionId: t });
11
+ return n;
12
+ }, u = (e) => async (t, r) => {
13
+ let i = r.request?.subject?.id ?? null;
14
+ return i === null || i === "" ? e.registry.list().map((e) => ({
15
+ connectionId: e.id,
16
+ kind: e.kind,
17
+ label: e.label ?? e.id,
18
+ status: "disconnected",
19
+ accountId: null,
20
+ accountLabel: null,
21
+ scopes: [],
22
+ expiresAt: null,
23
+ lastError: null,
24
+ connectedAt: null
25
+ })) : n(r.store, e.registry, i);
26
+ }, d = (t) => async (n, r) => {
27
+ let i = l(t, n.connectionId), o = c(r, n.connectionId);
28
+ if (i.kind !== "oauth2") throw new a({
29
+ connectionId: n.connectionId,
30
+ expected: "oauth2",
31
+ actual: i.kind
32
+ });
33
+ return e({
34
+ store: r.store,
35
+ definition: i,
36
+ subjectId: o,
37
+ tenantId: r.request?.subject?.tenantId ?? null,
38
+ publicUrl: t.publicUrl,
39
+ ...n.redirectTo === void 0 ? {} : { redirectTo: n.redirectTo }
40
+ });
41
+ }, f = (e) => async (t, n) => {
42
+ let o = l(e, t.connectionId), s = c(n, t.connectionId);
43
+ if (o.kind !== "pat") throw new a({
44
+ connectionId: t.connectionId,
45
+ expected: "pat",
46
+ actual: o.kind
47
+ });
48
+ let u = t.token.trim();
49
+ if (u.length === 0) throw new i({
50
+ connectionId: t.connectionId,
51
+ reason: "token is empty",
52
+ transient: !1
53
+ });
54
+ let d;
55
+ if (o.validate !== void 0) try {
56
+ d = await o.validate(u);
57
+ } catch (e) {
58
+ throw new i({
59
+ connectionId: t.connectionId,
60
+ reason: `the provider rejected that token: ${e instanceof Error ? e.message : String(e)}`,
61
+ transient: !1
62
+ });
63
+ }
64
+ return await r({
65
+ store: n.store,
66
+ definition: o,
67
+ subjectId: s,
68
+ tenantId: n.request?.subject?.tenantId ?? null,
69
+ tokens: {
70
+ accessToken: u,
71
+ scopes: []
72
+ },
73
+ ...d === void 0 ? {} : { account: d }
74
+ }), { ok: !0 };
75
+ }, p = (e) => async (n, r) => {
76
+ l(e, n.connectionId);
77
+ let i = c(r, n.connectionId);
78
+ return { ok: await t(r.store, n.connectionId, i) };
79
+ };
80
+ //#endregion
81
+ export { p as makeDisconnectConnectionExecutor, u as makeListConnectionsExecutor, d as makeStartConnectionExecutor, f as makeSubmitTokenExecutor };
@@ -0,0 +1,66 @@
1
+ //#region src/connectionCredentials.ts
2
+ var e = 36e5, t = Symbol.for("@voltro/runtime/connectionCredentials"), n = globalThis, r = n[t] ??= {
3
+ overrides: /* @__PURE__ */ new Map(),
4
+ credentialExpiry: /* @__PURE__ */ new Map(),
5
+ streamInterrupts: /* @__PURE__ */ new Map()
6
+ }, { overrides: i, credentialExpiry: a, streamInterrupts: o } = r, s = (e, t) => {
7
+ t === void 0 ? a.delete(e) : a.set(e, t);
8
+ }, c = (e) => a.get(e), l = (e, t) => {
9
+ i.set(e, {
10
+ credential: t,
11
+ touchedAt: Date.now()
12
+ });
13
+ }, u = (e) => {
14
+ let t = i.get(e);
15
+ if (t) return t.touchedAt = Date.now(), t.credential;
16
+ }, d = (e) => {
17
+ a.delete(e), i.delete(e);
18
+ }, f = (e, t) => {
19
+ let n = [], r = /* @__PURE__ */ new Set();
20
+ for (let i of (e ?? "").split(";")) {
21
+ let e = i.indexOf("=");
22
+ if (e < 0) continue;
23
+ let a = i.slice(0, e).trim();
24
+ if (a === "") continue;
25
+ let o = t[a];
26
+ o === void 0 ? n.push([a, i.slice(e + 1).trim()]) : (n.push([a, encodeURIComponent(o)]), r.add(a));
27
+ }
28
+ for (let [e, i] of Object.entries(t)) r.has(e) || n.push([e, encodeURIComponent(i)]);
29
+ return n.map(([e, t]) => `${e}=${t}`).join("; ");
30
+ }, p = (e, t) => {
31
+ let n = u(e);
32
+ if (n === void 0) return t;
33
+ let r = { ...t };
34
+ if (n.headers !== void 0) for (let [e, t] of Object.entries(n.headers)) {
35
+ let n = e.toLowerCase();
36
+ delete r[e], r[n] = t;
37
+ }
38
+ if (n.cookies !== void 0) {
39
+ let e = t.cookie ?? t.Cookie;
40
+ delete r.Cookie, r.cookie = f(e, n.cookies);
41
+ }
42
+ return r;
43
+ };
44
+ r.sweepHandle ??= setInterval(() => {
45
+ let e = Date.now() - 864e5;
46
+ for (let [t, n] of i) n.touchedAt < e && i.delete(t);
47
+ }, e), typeof r.sweepHandle == "object" && r.sweepHandle !== null && "unref" in r.sweepHandle && r.sweepHandle.unref();
48
+ var m = (e, t) => {
49
+ let n = o.get(e);
50
+ return n || (n = /* @__PURE__ */ new Set(), o.set(e, n)), n.add(t), () => {
51
+ let n = o.get(e);
52
+ n && (n.delete(t), n.size === 0 && o.delete(e));
53
+ };
54
+ }, h = (e) => {
55
+ let t = o.get(e);
56
+ if (t) {
57
+ for (let e of [...t]) try {
58
+ e();
59
+ } catch {}
60
+ o.delete(e);
61
+ }
62
+ }, g = (e) => o.get(e)?.size ?? 0, _ = () => {
63
+ i.clear(), a.clear(), o.clear();
64
+ };
65
+ //#endregion
66
+ export { g as _connectionStreamCount, _ as _resetConnectionCredentialsForTest, p as applyConnectionCredential, l as bindConnectionCredential, u as getConnectionCredential, c as getCredentialExpiry, h as interruptConnectionStreams, f as mergeCookieHeader, s as recordCredentialExpiry, m as registerConnectionStream, d as unbindConnection };