@voltro/protocol 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 (65) hide show
  1. package/CHANGELOG.md +1215 -0
  2. package/README.md +14 -0
  3. package/THIRD-PARTY-NOTICES.md +5 -89
  4. package/dist/apikey.d.ts +32 -34
  5. package/dist/approval.js +64 -0
  6. package/dist/approvalDescriptors.js +26 -0
  7. package/dist/auth.js +369 -0
  8. package/dist/boundedRing.js +27 -0
  9. package/dist/businessRule.js +11 -0
  10. package/dist/connection.js +73 -0
  11. package/dist/devActivity.js +4 -0
  12. package/dist/errorValue.js +21 -0
  13. package/dist/event.js +104 -0
  14. package/dist/idempotency.js +66 -0
  15. package/dist/identity.js +5 -9
  16. package/dist/index.d.ts +1494 -1366
  17. package/dist/index.js +42 -1411
  18. package/dist/inspect.d.ts +88 -88
  19. package/dist/inspect.js +14 -190
  20. package/dist/inspectBackfill.js +52 -0
  21. package/dist/inspectCommandRejection.js +21 -0
  22. package/dist/inspectProjection.js +133 -0
  23. package/dist/inspectStorageProjection.js +86 -0
  24. package/dist/inspectValueIdentity.js +4 -0
  25. package/dist/inspectWorkflowExecution.js +34 -0
  26. package/dist/inspectWorkflowQueuedStart.js +31 -0
  27. package/dist/jsonSchema.js +54 -0
  28. package/dist/jwt.d.ts +32 -34
  29. package/dist/outbox.js +10 -0
  30. package/dist/pairing.js +75 -0
  31. package/dist/plugin.js +61 -0
  32. package/dist/pluginNaming.js +32 -0
  33. package/dist/procedure.js +262 -0
  34. package/dist/publicApi.js +344 -0
  35. package/dist/reactivityChannel.js +34 -0
  36. package/dist/rest.d.ts +105 -57
  37. package/dist/rest.js +259 -437
  38. package/dist/restFormat.js +163 -0
  39. package/dist/rowEquality.js +31 -0
  40. package/dist/rowPatch.js +182 -0
  41. package/dist/schemaShape.js +67 -0
  42. package/dist/scopes.js +240 -0
  43. package/dist/serverErrorBus.js +15 -0
  44. package/dist/serviceCall.js +14 -0
  45. package/dist/session.d.ts +90 -96
  46. package/dist/session.js +13 -15
  47. package/dist/{sessionHeader-DriTZhmv.js → sessionHeader.js} +1 -1
  48. package/dist/storageAccess.js +14 -0
  49. package/dist/storeErrors.js +66 -0
  50. package/dist/storeScreenshots.js +90 -0
  51. package/dist/strictInput.js +27 -0
  52. package/dist/subscriptionEvent.js +37 -0
  53. package/dist/tenantSelection.js +40 -0
  54. package/dist/time.js +7 -0
  55. package/dist/undo.js +38 -0
  56. package/dist/validation.js +39 -0
  57. package/dist/webSocketGateway.js +10 -0
  58. package/dist/workflow.js +297 -0
  59. package/dist/workflowAccess.js +61 -0
  60. package/dist/workflowRestart.js +45 -0
  61. package/dist/workflowRetry.js +44 -0
  62. package/dist/workflowStartOutcome.js +30 -0
  63. package/package.json +4 -8
  64. package/dist/restFormat-EZ8k9ZcQ.js +0 -304
  65. package/dist/scopes-Di756ENh.js +0 -518
@@ -0,0 +1,262 @@
1
+ import { subscriptionEvent as e } from "./subscriptionEvent.js";
2
+ import { RequestedTenantRefused as t } from "./tenantSelection.js";
3
+ import { Unauthenticated as n } from "./auth.js";
4
+ import { NoSuchResource as r, ScopeError as i, declaresResourceGuard as a, isOpenAccess as o, openAccessSpec as s, serviceAccessSpec as c } from "./scopes.js";
5
+ import { strictInput as l } from "./strictInput.js";
6
+ import { BusinessRuleViolation as u } from "./businessRule.js";
7
+ import { MutationConnectionRequired as d, MutationInFlight as f } from "./idempotency.js";
8
+ import { ValidationError as p, ValidationErrors as m } from "./validation.js";
9
+ import { ApprovalErrors as h } from "./approval.js";
10
+ import { normalizeSource as g } from "./reactivityChannel.js";
11
+ import { Schema as _ } from "effect";
12
+ import { Rpc as v } from "effect/rpc";
13
+ import { VersionConflict as y } from "@voltro/database/wire";
14
+ //#region src/procedure.ts
15
+ var b = (e) => e.internal !== !0, x = (e) => e.service === void 0 ? "client" : "service", S = (e) => b(e) && e.service === void 0, C = (e) => b(e) && e.service !== void 0, w = /^[a-z][a-z0-9-]{0,55}$/i, T = (e) => {
16
+ if (D(e), E(e), e.idempotencyScope !== void 0 && e.idempotencyScope !== "subject" && e.idempotencyScope !== "connection") throw Error(`${e.name}: idempotencyScope must be 'subject' or 'connection'`);
17
+ let t = e.serialize;
18
+ if (t !== void 0) {
19
+ if (typeof t.key != "function") throw Error(`${e.name}: serialize.key must be a function of the input`);
20
+ if (t.maxPending !== void 0 && (!Number.isSafeInteger(t.maxPending) || t.maxPending < 1)) throw Error(`${e.name}: serialize.maxPending must be a positive integer`);
21
+ }
22
+ if (e.idempotencyScope === "connection" && (e.internal === !0 || e.publicApi !== void 0 || e.exposeAsTool !== void 0)) throw Error(`${e.name}: connection-scoped mutations require the native WebSocket RPC surface; internal, publicApi and exposeAsTool cannot establish its connection state`);
23
+ if (Array.isArray(e.guards) && e.guards.length === 0) throw Error(`${e.name}: \`guards: []\` is empty, so it enforces nothing — but it reads\n at the call site as if this procedure were protected. Omit the field for an
24
+ unguarded procedure, or list the scopes required to call it.`);
25
+ let n = typeof e.source == "string" ? [e.source] : Array.isArray(e.source) ? e.source : void 0;
26
+ if (n !== void 0 && (n.length === 0 || n.some((e) => String(e).trim() === ""))) throw Error(`${e.name}: \`source\` is empty, so this query declares reactivity and\n subscribes to nothing — it serves one snapshot and never updates again,
27
+ which is indistinguishable from "nothing changed". Name the table(s) it
28
+ reads, or omit \`source\` for a non-reactive query.`);
29
+ if (e.internal !== !0) return e;
30
+ if (e.openAccess !== void 0) throw Error(`${e.name}: \`internal: true\` cannot be combined with \`openAccess\`.\n \`internal\` takes the procedure OFF the wire, and \`openAccess\` declares who may
31
+ call it there — together they describe a decision about a surface that does not
32
+ exist. Drop \`openAccess\` (an internal procedure needs no wire decision), or drop
33
+ \`internal: true\` if the procedure really is meant to be callable.`);
34
+ if (e.overridesPlugin === !0) throw Error(`${e.name}: \`internal: true\` cannot be combined with \`overridesPlugin\`.\n The override REMOVES the plugin route, and an internal procedure is not
35
+ wire-reachable — so the plugin's route would vanish with nothing callable
36
+ in its place, and callers would get a 404 for something that used to work.`);
37
+ let r = [e.publicApi === void 0 ? void 0 : "publicApi", e.exposeAsTool === void 0 ? void 0 : "exposeAsTool"].filter((e) => e !== void 0);
38
+ if (r.length === 0) return e;
39
+ throw Error(`${e.name}: \`internal: true\` cannot be combined with ${r.map((e) => `\`${e}\``).join(" or ")}. \`internal\` takes the procedure OFF the wire; those put it back ON a different one (${r.includes("publicApi") ? "a REST route" : "an agent tool"}), and that surface is projected without consulting the flag — so the procedure would be unreachable from your client and reachable from the internet. Drop \`internal: true\` if the wider surface is intended, or remove the ${r.join(" / ")} annotation if it is not.`);
40
+ }, E = (e) => {
41
+ let t = e.service;
42
+ if (t === void 0) return;
43
+ let n = t.callers;
44
+ if (!Array.isArray(n) || n.length === 0) throw Error(`${e.name}: \`service.callers\` is empty, so NO app may call this procedure —\n and no browser either. Name the calling app(s), e.g. \`service: { callers: ['worker'] }\`,
45
+ or drop \`service:\` if the procedure is meant for this app's own clients.`);
46
+ let r = n.filter((e) => typeof e != "string" || !w.test(e));
47
+ if (r.length > 0) throw Error(`${e.name}: \`service.callers\` holds ${r.map((e) => JSON.stringify(e)).join(", ")} — a caller is an\n app name (letters, digits, dashes; starting with a letter; at most 56 characters), the same name this app
48
+ lists in \`serviceCallers\` and the caller's credential resolves to.`);
49
+ if (new Set(n).size !== n.length) throw Error(`${e.name}: \`service.callers\` lists the same app twice`);
50
+ let i = [
51
+ e.internal === !0 ? "`internal: true` (it removes the wire surface a service calls over)" : void 0,
52
+ e.publicApi === void 0 ? void 0 : "`publicApi` (a REST route is for callers that are not the listed apps)",
53
+ e.exposeAsTool === void 0 ? void 0 : "`exposeAsTool` (an agent tool is not one of the listed apps)",
54
+ e.requiresApproval === void 0 ? void 0 : "`requiresApproval` (a second HUMAN cannot approve a machine call)",
55
+ e.overridesPlugin === !0 ? "`overridesPlugin` (a plugin route is a client surface; replacing it with a service-only one breaks its clients)" : void 0,
56
+ e.idempotencyScope === "connection" ? "`idempotencyScope: 'connection'` (a service call dedups per service, across reconnects)" : void 0
57
+ ].filter((e) => e !== void 0);
58
+ if (i.length !== 0) throw Error(`${e.name}: \`service:\` cannot be combined with ${i.join("; ")}.\n A service procedure is callable only by the listed apps of this project, over the
59
+ socket, with their service credential. Drop the other field, or drop \`service:\`.`);
60
+ }, D = (e) => {
61
+ let t = e.requiresApproval;
62
+ if (t !== void 0) {
63
+ if (!Array.isArray(t.approvers) || t.approvers.length === 0) throw Error(`${e.name}: \`requiresApproval.approvers\` is empty, so NOBODY can approve this\n procedure and every call would park forever. Name the scope(s) an approver must hold
64
+ — e.g. \`approvers: [{ scope: 'invoices:approve' }]\`.`);
65
+ if (e.openAccess !== void 0) throw Error(`${e.name}: \`requiresApproval\` cannot be combined with \`openAccess\`.\n The self-approval refusal compares subject ids, and an unauthenticated caller has
66
+ none — so on an open procedure every anonymous caller would count as a DIFFERENT
67
+ human from every other, and the second-pair-of-eyes control would enforce nothing.
68
+ Give the procedure a \`guards:\` decision, or drop \`requiresApproval\`.`);
69
+ }
70
+ }, O = (e) => e.action !== void 0 && e.resourceType !== void 0, k = (e) => e.authenticated === !0, A = (e) => e.openAccess !== void 0 || e.guards !== void 0 && e.guards.length > 0, j = (e, t, n, r) => {
71
+ if (r !== void 0) {
72
+ if (n !== void 0 || t !== void 0 && t.length > 0) throw Error(`${e}: \`service:\` is an access decision of its own — only the listed apps may\n call this procedure — so it cannot sit beside \`guards:\` or \`openAccess:\`. A service
73
+ holds no scopes, and no user may call a service procedure. Keep exactly one.`);
74
+ return Array.isArray(r.callers) ? [c(r.callers)] : void 0;
75
+ }
76
+ if (n === void 0) return t;
77
+ if (n.trim() === "") throw Error(`${e}: \`openAccess\` needs a REASON, not an empty string. It is the sentence a\n reviewer reads to decide whether this procedure should really be callable
78
+ without an authorization check — e.g. \`openAccess: 'public pricing, no caller data'\`.`);
79
+ if (t !== void 0 && t.length > 0) throw Error(`${e}: \`openAccess\` and \`guards\` are two different access decisions, so\n declaring both says the procedure is protected AND open. Keep the guards if a
80
+ caller must hold a scope; drop them if anyone may call it.`);
81
+ return [s(n.trim())];
82
+ }, M = (e) => T({
83
+ kind: "query",
84
+ name: e.name,
85
+ input: e.input,
86
+ output: e.output,
87
+ error: e.error ?? _.Never,
88
+ source: g(e.source),
89
+ cache: e.cache,
90
+ guards: j(e.name, e.guards, e.openAccess, e.service),
91
+ openAccess: e.openAccess,
92
+ service: e.service === void 0 ? void 0 : { callers: Array.isArray(e.service.callers) ? [...e.service.callers] : e.service.callers },
93
+ publicApi: e.publicApi,
94
+ exposeAsTool: e.exposeAsTool,
95
+ internal: e.internal,
96
+ overridesPlugin: e.overridesPlugin
97
+ }), N = (e) => T({
98
+ kind: "mutation",
99
+ name: e.name,
100
+ input: e.input,
101
+ output: e.output,
102
+ error: e.error ?? _.Never,
103
+ ...e.idempotencyScope === void 0 ? {} : { idempotencyScope: e.idempotencyScope },
104
+ ...e.serialize === void 0 ? {} : { serialize: e.serialize },
105
+ target: e.target,
106
+ guards: j(e.name, e.guards, e.openAccess, e.service),
107
+ openAccess: e.openAccess,
108
+ service: e.service === void 0 ? void 0 : { callers: Array.isArray(e.service.callers) ? [...e.service.callers] : e.service.callers },
109
+ publicApi: e.publicApi,
110
+ exposeAsTool: e.exposeAsTool,
111
+ requiresApproval: e.requiresApproval,
112
+ internal: e.internal,
113
+ overridesPlugin: e.overridesPlugin
114
+ }), P = (e) => T({
115
+ kind: "action",
116
+ name: e.name,
117
+ input: e.input,
118
+ output: e.output,
119
+ error: e.error ?? _.Never,
120
+ guards: j(e.name, e.guards, e.openAccess, e.service),
121
+ openAccess: e.openAccess,
122
+ service: e.service === void 0 ? void 0 : { callers: Array.isArray(e.service.callers) ? [...e.service.callers] : e.service.callers },
123
+ source: e.source,
124
+ target: e.target,
125
+ publicApi: e.publicApi,
126
+ exposeAsTool: e.exposeAsTool,
127
+ requiresApproval: e.requiresApproval,
128
+ internal: e.internal,
129
+ overridesPlugin: e.overridesPlugin
130
+ }), F = (e) => T({
131
+ kind: "stream",
132
+ name: e.name,
133
+ input: e.input,
134
+ element: e.element,
135
+ error: e.error ?? _.Never,
136
+ internal: e.internal,
137
+ overridesPlugin: e.overridesPlugin,
138
+ guards: j(e.name, e.guards, e.openAccess),
139
+ openAccess: e.openAccess
140
+ }), I = (e, t) => t && t.length > 0 ? _.Union([e, ...t]) : e, L = (e) => e !== void 0 && e.some((e) => !o(e)), R = (e) => _.Union([
141
+ e,
142
+ i,
143
+ n,
144
+ t
145
+ ]), z = (e) => _.Union([e, u]), B = (e) => _.Union([
146
+ e,
147
+ p,
148
+ m
149
+ ]), V = (e, t) => t === void 0 ? e : _.Union([e, h]), H = (e, t) => a(t) ? _.Union([e, r]) : e, U = (e, t, n) => I(W(e, t), n), W = (e, t) => {
150
+ let n = H(R(e.error), e.guards);
151
+ if (t === "stream" || t === "query") return n;
152
+ let r = t === "mutation" ? _.Union([
153
+ z(n),
154
+ f,
155
+ y
156
+ ]) : n;
157
+ return V(B(t === "mutation" && e.idempotencyScope === "connection" ? _.Union([r, d]) : r), e.requiresApproval);
158
+ }, G = {
159
+ query: [
160
+ i,
161
+ n,
162
+ t
163
+ ],
164
+ stream: [
165
+ i,
166
+ n,
167
+ t
168
+ ],
169
+ action: [
170
+ i,
171
+ n,
172
+ t,
173
+ p,
174
+ m
175
+ ],
176
+ mutation: [
177
+ i,
178
+ n,
179
+ t,
180
+ u,
181
+ f,
182
+ y,
183
+ p,
184
+ m
185
+ ]
186
+ }, K = (e, t) => I(H(R(e.errorSchema), e.guards), t), q = (e, t) => ({
187
+ ...e,
188
+ name: t
189
+ }), J = (t, n) => v.make(t.name, {
190
+ payload: l(t.input, t.name, L(t.guards)),
191
+ success: e(t.output),
192
+ error: U(t, "query", n),
193
+ stream: !0
194
+ }), Y = (e, t) => v.make(e.name, {
195
+ payload: l(e.input, e.name, L(e.guards)),
196
+ success: e.output,
197
+ error: U(e, "mutation", t)
198
+ }), X = (e, t) => v.make(e.name, {
199
+ payload: l(e.input, e.name, L(e.guards)),
200
+ success: e.output,
201
+ error: U(e, "action", t)
202
+ }), Z = (e, t) => v.make(e.name, {
203
+ payload: l(e.input, e.name, L(e.guards)),
204
+ success: e.element,
205
+ error: U(e, "stream", t),
206
+ stream: !0
207
+ }), Q = (e) => {
208
+ switch (e.kind) {
209
+ case "query": return J(e);
210
+ case "mutation": return Y(e);
211
+ case "action": return X(e);
212
+ case "stream": return Z(e);
213
+ }
214
+ }, $ = (e) => {
215
+ let t = e.input, n = t === void 0 ? {} : { input: t }, r = e.output, i = r === void 0 ? {} : { output: r };
216
+ if (e.kind === "query") return {
217
+ kind: "query",
218
+ source: e.source,
219
+ ...n,
220
+ ...i
221
+ };
222
+ if (e.kind === "action") return {
223
+ kind: "action",
224
+ ...n,
225
+ ...i
226
+ };
227
+ if (e.kind === "stream") return {
228
+ kind: "stream",
229
+ ...n,
230
+ ...i
231
+ };
232
+ let a = e.target, o = e.idempotencyScope === void 0 ? {} : { idempotencyScope: e.idempotencyScope }, s = e.serialize === void 0 ? {} : { serialize: e.serialize };
233
+ if (a === void 0) return {
234
+ kind: "mutation",
235
+ ...n,
236
+ ...i,
237
+ ...o,
238
+ ...s
239
+ };
240
+ let c = Array.isArray(a) ? a : [a];
241
+ return {
242
+ kind: "mutation",
243
+ ...n,
244
+ ...i,
245
+ ...o,
246
+ ...s,
247
+ targets: c.map((e) => ({
248
+ table: e.table,
249
+ op: e.op,
250
+ ..."order" in e && e.order !== void 0 ? { order: e.order } : {},
251
+ ..."shape" in e && e.shape !== void 0 ? { shape: e.shape } : {},
252
+ ..."identify" in e && e.identify !== void 0 ? { identify: e.identify } : {},
253
+ ..."path" in e && e.path !== void 0 ? { path: e.path } : {},
254
+ ..."by" in e && e.by !== void 0 ? { by: e.by } : {},
255
+ ..."match" in e && e.match !== void 0 ? { match: e.match } : {},
256
+ ..."shapeItem" in e && e.shapeItem !== void 0 ? { shapeItem: e.shapeItem } : {},
257
+ ..."relations" in e && e.relations !== void 0 ? { relations: e.relations } : {}
258
+ }))
259
+ };
260
+ };
261
+ //#endregion
262
+ export { G as FRAMEWORK_WIRE_ERRORS, w as SERVICE_NAME_PATTERN, X as actionToRpc, P as defineAction, N as defineMutation, M as defineQuery, F as defineStream, A as hasAccessDecision, L as hasEnforcedGuard, k as isAuthenticatedGuard, S as isClientReachable, O as isPolicyGuard, C as isServiceReachable, b as isWireReachable, Y as mutationToRpc, $ as normalizeDescriptor, J as queryToRpc, Z as streamToRpc, Q as toRpc, x as wireAudienceOf, U as wireErrorUnion, q as withRpcTag, K as workflowWireErrorUnion };
@@ -0,0 +1,344 @@
1
+ import { schemaShape as e, shapeDigest as t } from "./schemaShape.js";
2
+ import { encodeRestError as n, encodeRestSuccess as r, resolveRestFormat as i, restViewSchema as a, toSnakeCase as o } from "./restFormat.js";
3
+ import { RestRouteError as s, defineRestRoute as c, requireAuthenticated as l, requireScope as u, response as ee, sse as d, sseFrame as f } from "./rest.js";
4
+ import { Effect as p, Schema as m, SchemaGetter as h, SchemaIssue as g } from "effect";
5
+ import * as _ from "effect/SchemaAST";
6
+ //#region src/publicApi.ts
7
+ var v = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? S("", t, n).method : void 0) ?? (e === "query" ? "GET" : "POST"), y = (e, t, n) => C(t.path ?? (t.resource !== void 0 && n !== void 0 ? S(e, t, n).path : `/${t.version ?? "v1"}/${e.replace(/\./g, "/")}`)), b = (e) => {
8
+ let t = e.split("/").pop() ?? e;
9
+ return t.endsWith("ies") ? `${t.slice(0, -3)}y` : t.endsWith("ses") || t.endsWith("xes") ? t.slice(0, -2) : t.endsWith("s") ? t.slice(0, -1) : t;
10
+ }, x = (e, t) => {
11
+ let n = t != null && (typeof t == "object" || typeof t == "function") && "ast" in t ? L(t) : void 0;
12
+ if (n === void 0) return;
13
+ let r = `${b(e)}Id`;
14
+ return n.has(r) ? r : n.has("id") ? "id" : void 0;
15
+ }, S = (e, t, n) => {
16
+ let r = (t.resource ?? "").replace(/^\/+|\/+$/g, ""), i = `/${t.version ?? "v1"}/${r}`, a = x(r, n.input), o = a === void 0 ? i : `${i}/:${a}`, s = e.split(".").pop() ?? e, c = n.target?.op;
17
+ return n.kind === "query" || n.kind === "stream" ? {
18
+ method: "GET",
19
+ path: o
20
+ } : n.kind === "mutation" && c === "insert" ? {
21
+ method: "POST",
22
+ path: i
23
+ } : n.kind === "mutation" && c === "update" ? {
24
+ method: a === void 0 ? "POST" : "PATCH",
25
+ path: o
26
+ } : n.kind === "mutation" && c === "delete" ? {
27
+ method: a === void 0 ? "POST" : "DELETE",
28
+ path: o
29
+ } : {
30
+ method: "POST",
31
+ path: `${o}/${s}`
32
+ };
33
+ }, C = (e) => e.replace(/\{([A-Za-z0-9_]+)\}/g, ":$1"), w = (e) => [...e.matchAll(/:([A-Za-z0-9_]+)/g)].map((e) => e[1]), T = (e) => {
34
+ if (_.isUnion(e)) {
35
+ let t = e.types.filter((e) => !_.isUndefined(e));
36
+ if (t.length === 1) return t[0];
37
+ if (t.length !== e.types.length) return new _.Union(t);
38
+ }
39
+ return e;
40
+ }, E = /^-?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i, D = (e, t) => {
41
+ let n = T(t);
42
+ if (n.encoding !== void 0) return D(e, _.toEncoded(n));
43
+ if (_.isUnion(n)) {
44
+ for (let t of n.types) {
45
+ let n = D(e, t);
46
+ if (n !== e) return n;
47
+ }
48
+ return e;
49
+ }
50
+ if (_.isArrays(n)) {
51
+ let t = Array.isArray(e) ? e : e === void 0 ? void 0 : [e];
52
+ if (t === void 0) return e;
53
+ let r = n.rest[0] ?? n.elements[0];
54
+ return r === void 0 ? t : t.map((e) => D(e, r));
55
+ }
56
+ if (typeof e != "string") return e;
57
+ if (_.isNumber(n)) return E.test(e.trim()) ? Number(e) : e;
58
+ if (_.isBoolean(n)) return e === "true" || e !== "false" && e;
59
+ if (_.isLiteral(n)) {
60
+ let t = n.literal;
61
+ return typeof t == "number" && E.test(e.trim()) && Number(e) === t || typeof t == "boolean" && String(t) === e ? t : e;
62
+ }
63
+ return e;
64
+ }, O = (e, t) => {
65
+ if (typeof e != "object" || !e || Array.isArray(e)) return e;
66
+ let n = T(_.toEncoded(t.ast));
67
+ if (!_.isObjects(n)) return e;
68
+ let r = { ...e };
69
+ for (let e of n.propertySignatures) {
70
+ let t = String(e.name);
71
+ t in r && (r[t] = D(r[t], e.type));
72
+ }
73
+ return r;
74
+ }, k = (e) => {
75
+ let t = T(_.toEncoded(e.ast));
76
+ if (!_.isObjects(t)) return (e) => e;
77
+ let n = t.propertySignatures, r = /* @__PURE__ */ new Map(), i = n.length >= 32 && n.every((e, t) => typeof e.name != "string" || e.name in Object.prototype || r.has(e.name) ? !1 : (r.set(e.name, {
78
+ type: e.type,
79
+ order: t
80
+ }), !0));
81
+ return (e) => {
82
+ if (typeof e != "object" || !e || Array.isArray(e)) return e;
83
+ let t = { ...e }, a = i ? Object.keys(t) : void 0;
84
+ if (a !== void 0 && a.length * 4 < n.length) {
85
+ let e = [];
86
+ for (let t of a) {
87
+ let n = r.get(t);
88
+ n !== void 0 && e.push({
89
+ key: t,
90
+ ...n
91
+ });
92
+ }
93
+ e.sort((e, t) => e.order - t.order);
94
+ for (let { key: n, type: r } of e) t[n] = D(t[n], r);
95
+ } else for (let e of n) {
96
+ let n = String(e.name);
97
+ n in t && (t[n] = D(t[n], e.type));
98
+ }
99
+ return t;
100
+ };
101
+ }, A = (e) => {
102
+ let t = /* @__PURE__ */ new Set();
103
+ if (e === void 0) return t;
104
+ let n = (e) => {
105
+ if (_.isUnion(e)) for (let t of e.types) n(t);
106
+ else if (e.encoding !== void 0 && n(_.toEncoded(e)), _.isObjects(e)) {
107
+ let n = e.propertySignatures.find((e) => e.name === "_tag");
108
+ n !== void 0 && _.isLiteral(n.type) && typeof n.type.literal == "string" && t.add(n.type.literal);
109
+ }
110
+ };
111
+ return n(e.ast), t;
112
+ }, j = (e, t, n) => {
113
+ if (n !== void 0) try {
114
+ let r = m.encodeUnknownSync(n)(e);
115
+ if (typeof r == "object" && r) return {
116
+ error: t,
117
+ ...r
118
+ };
119
+ } catch {}
120
+ let r = { error: t };
121
+ for (let [t, n] of Object.entries(e)) t !== "stack" && t !== "_tag" && (r[t] = n);
122
+ return r;
123
+ }, M = (e, t, n, r = []) => N(e, t, n, r, A), N = (e, t, n, r, i) => {
124
+ if (typeof e != "object" || !e) return e;
125
+ let a = e._tag;
126
+ if (typeof a != "string" || a === "ScopeError" || a === "NoSuchResource") return e;
127
+ if (i(t.error).has(a)) {
128
+ let r = n.errorStatus?.[a] ?? 422;
129
+ return new s(r, j(e, a, t.error));
130
+ }
131
+ let o = r.find((e) => i(e.schema).has(a));
132
+ if (o === void 0) return e;
133
+ let c = n.errorStatus?.[a] ?? o.rest?.status ?? 422, l = o.rest?.headers?.(e);
134
+ return new s(c, j(e, a, o.schema), l);
135
+ }, P = (e, t, r, i, a, o, c) => {
136
+ let l = N(e, t, r, i, c);
137
+ if (!(l instanceof s) || a.errors === "tagged" && a.encodeError === void 0) return l;
138
+ let { error: u, _tag: ee, ...d } = l.body, f = typeof d.message == "string" ? d.message : typeof d.reason == "string" ? d.reason : "", p = n(a, {
139
+ status: l.status,
140
+ tag: u,
141
+ message: f,
142
+ fields: d
143
+ }, {
144
+ ...o,
145
+ status: l.status
146
+ });
147
+ return new s(l.status, p.body, {
148
+ ...l.headers ?? {},
149
+ ...p.headers ?? {}
150
+ }, p.contentType);
151
+ }, F = (e, t) => {
152
+ if (e === void 0) return;
153
+ let n = _.isUnion(e.ast) ? e.ast.types : [e.ast];
154
+ for (let e of n) {
155
+ let n = m.make(e);
156
+ if (A(n).has(t)) return n;
157
+ }
158
+ }, I = (e) => e.split(".").map((e, t) => t === 0 ? e : e.charAt(0).toUpperCase() + e.slice(1)).join("").replace(/[^A-Za-z0-9_]/g, "_"), L = (e) => {
159
+ let t = T(_.toEncoded(e.ast));
160
+ return _.isObjects(t) && t.indexSignatures.length === 0 ? new Set(t.propertySignatures.map((e) => String(e.name))) : void 0;
161
+ }, R = (e, t) => e === t || JSON.stringify(e) === JSON.stringify(t), te = (e) => {
162
+ let t = T(_.toEncoded(e.ast)), n = _.isObjects(t) ? new Map(t.propertySignatures.map((e) => [String(e.name), e.type])) : /* @__PURE__ */ new Map();
163
+ return (e) => {
164
+ let t = {};
165
+ for (let [r, i] of Object.entries(e)) {
166
+ let e = n.get(r);
167
+ t[r] = e === void 0 ? i : D(i, e);
168
+ }
169
+ return t;
170
+ };
171
+ }, z = (e, t) => {
172
+ if (e !== void 0) {
173
+ try {
174
+ return m.encodeUnknownSync(t)(e);
175
+ } catch {}
176
+ try {
177
+ return m.decodeUnknownSync(t)(e), e;
178
+ } catch {}
179
+ return e;
180
+ }
181
+ }, B = (e, t, n) => ({
182
+ ...e.request === void 0 ? {} : { request: z(e.request, t) },
183
+ ...e.response === void 0 ? {} : { response: z(e.response, n) }
184
+ }), ne = () => (e) => {
185
+ if (e.subject.type !== "anonymous") return;
186
+ let t = e.subject.credentialRejected;
187
+ return t === void 0 ? void 0 : {
188
+ status: 401,
189
+ message: t
190
+ };
191
+ }, V = (e, t, n, s = {}) => {
192
+ let b = e.publicApi;
193
+ if (b === void 0) throw Error(`publicApiRoute: descriptor '${e.name}' has no publicApi annotation`);
194
+ let x = i(s.profile, b.format), S = s.pluginErrors ?? [], C = /* @__PURE__ */ new WeakMap(), T = (e) => {
195
+ if (e === void 0) return /* @__PURE__ */ new Set();
196
+ let t = C.get(e.ast);
197
+ if (t !== void 0) return t;
198
+ let n = A(e);
199
+ return C.set(e.ast, n), n;
200
+ }, E = /* @__PURE__ */ new WeakMap(), D = (e, t) => {
201
+ if (e === void 0) return;
202
+ let n = E.get(e.ast);
203
+ if (n === void 0) {
204
+ let t = /* @__PURE__ */ new Map();
205
+ for (let n of _.isUnion(e.ast) ? e.ast.types : [e.ast]) {
206
+ let e = m.make(n);
207
+ for (let n of T(e)) t.has(n) || t.set(n, e);
208
+ }
209
+ n = t, E.set(e.ast, n);
210
+ }
211
+ return n.get(t);
212
+ }, O = {
213
+ kind: e.kind,
214
+ input: e.input,
215
+ target: e.target
216
+ }, j = v(e.kind, b, O), M = (e) => x.naming === "snake_case" ? o(e) : e, N = y(e.name, b, O), F = N.replace(/:([A-Za-z0-9_]+)/g, (e, t) => `:${M(t)}`), z = w(F), V = a(e.input, x), H = k(V), U = te(V), W = L(V);
217
+ if (W !== void 0) {
218
+ for (let t of z) if (!W.has(t)) throw Error(`publicApi: descriptor '${e.name}' — path '${N}' binds ':${t}', and the input declares no field of that name` + (W.size > 0 ? ` (fields: ${[...W].join(", ")})` : " (the input declares no fields)"));
219
+ }
220
+ let G = a(e.output, x), re = m.Struct({ value: V }), K = j !== "GET" && W === void 0;
221
+ if (j !== "GET" && W !== void 0) {
222
+ let e = z.length >= 32 ? new Set(z) : void 0;
223
+ for (let t of W) if (!(e?.has(t) ?? z.includes(t))) {
224
+ K = !0;
225
+ break;
226
+ }
227
+ }
228
+ let q = {
229
+ query: m.Unknown,
230
+ params: m.Unknown,
231
+ form: m.Boolean
232
+ }, ie = (K ? m.Struct({
233
+ ...q,
234
+ body: m.Unknown
235
+ }) : m.Struct(q)).pipe(m.decodeTo(re, {
236
+ decode: h.transformEffect((e) => {
237
+ let t = "body" in e ? e.body : void 0, n = j === "GET" ? H(e.query) : e.form ? H(t ?? {}) : t ?? {}, r = typeof e.params == "object" && e.params !== null ? U(e.params) : {};
238
+ if (typeof n != "object" || !n || Array.isArray(n)) return p.succeed({ value: n });
239
+ let i = n, a = Object.keys(r), o = 0;
240
+ for (let e of a) e in i && !R(i[e], r[e]) && (a[o++] = e);
241
+ if (a.length = o, a.length > 0) {
242
+ let t = j === "GET" ? "query string" : "body";
243
+ return p.fail(new g.InvalidValue({ message: `${a.map((e) => `'${e}'`).join(", ")} ${a.length === 1 ? "is" : "are"} bound by the path and sent with another value in the ${t}` }, e));
244
+ }
245
+ return p.succeed({ value: {
246
+ ...i,
247
+ ...r
248
+ } });
249
+ }),
250
+ encode: h.transform((e) => e)
251
+ })), ae = [
252
+ ne(),
253
+ ...e.openAccess === void 0 ? [l()] : [],
254
+ ...(b.scopes ?? []).map((e) => u(e))
255
+ ], J = (() => {
256
+ let t = e.source;
257
+ return typeof t == "string" ? t : Array.isArray(t) ? t[0] : void 0;
258
+ })(), Y = (t, n = 200) => ({
259
+ tag: e.name,
260
+ method: t.method,
261
+ path: t.path,
262
+ query: t.query,
263
+ source: J,
264
+ status: n
265
+ }), X = b.stream === "sse" && e.kind === "query" && n !== void 0, oe = m.encodeUnknownEffect(G), se = X ? (e, t) => d((r) => n(e.value, t, (e) => {
266
+ r(f(String(e._tag ?? "message"), e));
267
+ })) : async (n, i) => {
268
+ let a;
269
+ try {
270
+ a = await t(n.value, i);
271
+ } catch (t) {
272
+ throw P(t, e, b, S, x, Y(i), T);
273
+ }
274
+ let o = await p.runPromise(oe(a)), s = r(x, o, Y(i));
275
+ return ee(s.body, {
276
+ ...s.headers === void 0 ? {} : { headers: s.headers },
277
+ ...s.contentType === void 0 ? {} : { contentType: s.contentType }
278
+ });
279
+ }, Z = e.error, Q = T(Z), ce = [...Q], $ = [];
280
+ for (let e of ce) {
281
+ let t = D(Z, e);
282
+ t !== void 0 && $.push({
283
+ status: b.errorStatus?.[e] ?? 422,
284
+ tag: e,
285
+ schema: t
286
+ });
287
+ }
288
+ for (let e of S) for (let t of T(e.schema)) {
289
+ if (Q.has(t)) continue;
290
+ let n = b.errorStatus?.[t] ?? e.rest?.status;
291
+ if (n === void 0) continue;
292
+ let r = D(e.schema, t) ?? e.schema;
293
+ $.push({
294
+ status: n,
295
+ tag: t,
296
+ schema: r
297
+ });
298
+ }
299
+ let le = b.security === !1 ? "none" : b.security ?? (e.openAccess === void 0 ? "required" : "optional"), ue = {
300
+ tag: e.name,
301
+ kind: e.kind,
302
+ version: b.version ?? "v1",
303
+ security: le,
304
+ idempotent: b.idempotent === !0,
305
+ input: V,
306
+ pathParams: z,
307
+ output: G,
308
+ source: J,
309
+ errorResponses: $,
310
+ format: x
311
+ };
312
+ return c({
313
+ method: j,
314
+ path: F,
315
+ input: ie,
316
+ output: m.Unknown,
317
+ handler: se,
318
+ ...X ? { streaming: !0 } : {},
319
+ guards: ae,
320
+ operationId: b.operationId ?? I(e.name),
321
+ tags: b.tags ?? [e.name.split(".")[0] ?? e.name],
322
+ projection: ue,
323
+ ...x.etag && j === "GET" && !X ? { etag: !0 } : {},
324
+ ...b.cache !== void 0 && j === "GET" && !X ? { cache: b.cache } : {},
325
+ ...b.example === void 0 ? {} : { example: B(b.example, V, G) },
326
+ ...b.summary === void 0 ? {} : { summary: b.summary },
327
+ ...b.description === void 0 ? {} : { description: b.description },
328
+ ...b.deprecated === void 0 ? {} : { deprecated: b.deprecated },
329
+ ...b.sunset === void 0 ? {} : { sunset: b.sunset }
330
+ });
331
+ }, H = (e, t = {}) => e.filter((e) => e.descriptor.publicApi !== void 0).map((e) => V(e.descriptor, e.invoke, e.subscribe, t)).sort((e, t) => e.path.localeCompare(t.path)), U = (n) => t(n.filter((e) => e.projection !== void 0).map((t) => {
332
+ let n = t.projection, r = {
333
+ tag: n.tag,
334
+ method: t.method,
335
+ path: t.path,
336
+ pathParams: n.pathParams,
337
+ version: n.version,
338
+ security: n.security,
339
+ errors: [...n.errorResponses].map((e) => `${e.status}:${e.tag}`).sort()
340
+ };
341
+ return `${JSON.stringify(r)} ${e(n.input.ast)} ${e(n.output.ast)}`;
342
+ }).sort().join("\n"));
343
+ //#endregion
344
+ export { O as coerceQueryObject, D as coerceQueryValue, H as collectPublicApiRoutes, A as declaredErrorTags, v as derivePublicMethod, y as derivePublicPath, S as deriveResource, F as errorMemberSchema, C as normalizePathParams, I as operationIdOf, w as pathParamNames, M as projectedFailure, V as publicApiRoute, U as publicSurfaceDigest, x as resourceIdField, B as wireExample };
@@ -0,0 +1,34 @@
1
+ //#region src/reactivityChannel.ts
2
+ var e = "channel:", t = Symbol.for("@voltro/protocol/reactivityChannels"), n = globalThis, r = n[t] ?? (n[t] = /* @__PURE__ */ new Map()), i = /^[a-z][a-z0-9-]*(\.[a-z0-9-]+)*$/, a = (t) => {
3
+ if (!i.test(t)) throw Error(`reactivityChannel('${t}'): invalid channel name.\n Use lowercase kebab segments separated by dots — \`presence\`, \`job-queue\`,
4
+ \`billing.usage\`. A \`:\` is refused because it is the namespace separator in
5
+ the routing key (\`${e}<name>\`), and an uppercase letter is\n refused because a key that differs only by case reads as one channel and
6
+ routes as two.`);
7
+ let n = r.get(t);
8
+ if (n !== void 0) return n;
9
+ let a = `${e}${t}`, o = Object.freeze({
10
+ kind: "reactivity-channel",
11
+ name: t,
12
+ key: a,
13
+ toString: () => a
14
+ });
15
+ return r.set(t, o), o;
16
+ }, o = (e) => typeof e == "object" && !!e && e.kind === "reactivity-channel", s = (t) => t.startsWith(e), c = () => new Set([...r.values()].map((e) => e.key)), l = (e) => o(e) ? e.key : e, u = (e) => e === void 0 ? [] : Array.isArray(e) ? e.map(l) : [l(e)], d = (e) => e === void 0 ? void 0 : Array.isArray(e) ? e.map(l) : l(e), f = (e) => {
17
+ let t = c(), n = [];
18
+ for (let r of e) for (let e of u(r.source)) s(e) && !t.has(e) && n.push({
19
+ procedure: r.name,
20
+ key: e
21
+ });
22
+ return n;
23
+ }, p = (e, t) => {
24
+ let n = e?.injectExternalChange;
25
+ return n !== void 0 && (n.call(e, {
26
+ table: t.key,
27
+ op: "update",
28
+ new: {},
29
+ old: {},
30
+ origin: "inline"
31
+ }), !0);
32
+ };
33
+ //#endregion
34
+ export { e as REACTIVITY_CHANNEL_PREFIX, c as declaredReactivityChannelKeys, o as isReactivityChannel, s as isReactivityChannelKey, d as normalizeSource, p as publishReactivity, a as reactivityChannel, u as sourceKeys, f as undeclaredChannelKeys };