@voltro/client 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 (111) hide show
  1. package/CHANGELOG.md +1215 -0
  2. package/THIRD-PARTY-NOTICES.md +5 -89
  3. package/dist/analyticsCatalog.js +47 -0
  4. package/dist/apiConnectivity.js +33 -0
  5. package/dist/apiRuntime.js +135 -0
  6. package/dist/apiSupervisor.js +125 -0
  7. package/dist/authRefresh.js +20 -0
  8. package/dist/awaitResolvedApi.js +23 -0
  9. package/dist/bootstrap.d.ts +1144 -0
  10. package/dist/bootstrap.js +8 -0
  11. package/dist/cellMerger.js +6 -0
  12. package/dist/clientDiagnostics.js +94 -0
  13. package/dist/clientErrorBus.js +16 -0
  14. package/dist/clientScheduler.js +31 -0
  15. package/dist/connectionPrerequisite.js +70 -0
  16. package/dist/connectionScope.js +35 -0
  17. package/dist/connectionSetupController.js +206 -0
  18. package/dist/createHooks.js +15 -0
  19. package/dist/deepLink.js +69 -0
  20. package/dist/filters.js +58 -0
  21. package/dist/form.d.ts +8 -11
  22. package/dist/form.js +5 -2
  23. package/dist/formBinding.js +325 -0
  24. package/dist/formData.js +65 -0
  25. package/dist/formFlashId.js +4 -0
  26. package/dist/frameworkRuntimesContext.js +8 -0
  27. package/dist/globalContext.js +10 -0
  28. package/dist/index.d.ts +285 -279
  29. package/dist/index.js +83 -3686
  30. package/dist/liveRowSort.js +66 -0
  31. package/dist/mutationConnectionSetup.js +16 -0
  32. package/dist/mutationIdentity.js +10 -0
  33. package/dist/mutationSerialExecution.js +53 -0
  34. package/dist/mutationsBus.js +40 -0
  35. package/dist/onlineSource.js +13 -0
  36. package/dist/outbox.js +213 -0
  37. package/dist/outboxHttp.js +104 -0
  38. package/dist/outboxState.js +43 -0
  39. package/dist/permissions.js +20 -0
  40. package/dist/platform.js +121 -0
  41. package/dist/preloadSeed.js +47 -0
  42. package/dist/provider.js +22 -0
  43. package/dist/query.js +12 -2
  44. package/dist/recoveryCoordinator.js +195 -0
  45. package/dist/recoveryRetry.js +24 -0
  46. package/dist/richText.js +176 -0
  47. package/dist/rpcErrorBus.js +39 -0
  48. package/dist/rpcErrorKind.js +13 -0
  49. package/dist/runRpc.js +12 -0
  50. package/dist/runtime.d.ts +79 -15
  51. package/dist/runtime.js +16 -129
  52. package/dist/runtimeCapabilities.js +44 -0
  53. package/dist/runtimeContext.js +49 -0
  54. package/dist/schemaFields.js +219 -0
  55. package/dist/scopeMembership.js +12 -0
  56. package/dist/seedResolvers.js +7 -0
  57. package/dist/sequence.js +65 -0
  58. package/dist/serverRequest.js +24 -0
  59. package/dist/serviceClient.js +128 -0
  60. package/dist/squashRpcCause.js +8 -0
  61. package/dist/stableKey.js +21 -0
  62. package/dist/store.js +288 -0
  63. package/dist/storeStorage.js +28 -0
  64. package/dist/subscriptionCache.js +724 -0
  65. package/dist/tagWalk.js +23 -0
  66. package/dist/traceBus.js +10 -0
  67. package/dist/tracking.js +40 -0
  68. package/dist/uploadProgress.js +21 -0
  69. package/dist/useAction.js +101 -0
  70. package/dist/useAgent.js +53 -0
  71. package/dist/useAgentChat.js +43 -0
  72. package/dist/useAgentStream.js +64 -0
  73. package/dist/useApiOnline.js +14 -0
  74. package/dist/useCapabilityManifest.js +101 -0
  75. package/dist/useConnectionSetup.js +28 -0
  76. package/dist/useConnectionStatus.js +38 -0
  77. package/dist/useConnections.js +107 -0
  78. package/dist/useDataCopilot.js +24 -0
  79. package/dist/useDataTable.js +34 -0
  80. package/dist/useDerived.js +22 -0
  81. package/dist/useEvent.js +88 -0
  82. package/dist/useFormBinding.js +476 -0
  83. package/dist/useLocalQuery.js +59 -0
  84. package/dist/useMutation.js +214 -0
  85. package/dist/useOnRpcError.js +13 -0
  86. package/dist/usePreloadedSubscription.js +18 -0
  87. package/dist/usePreview.js +14 -0
  88. package/dist/useProvenance.js +51 -0
  89. package/dist/useQueryField.js +34 -0
  90. package/dist/useRecord.js +12 -0
  91. package/dist/useRefreshSubscriptions.js +22 -0
  92. package/dist/useResourceCan.js +18 -0
  93. package/dist/useResumableAgentStream.js +75 -0
  94. package/dist/useSequence.js +25 -0
  95. package/dist/useSkeleton.js +13 -0
  96. package/dist/useSubscription.js +89 -0
  97. package/dist/useSubscriptionHealth.js +32 -0
  98. package/dist/useTranscription.js +51 -0
  99. package/dist/useUndo.js +33 -0
  100. package/dist/useUndoLog.js +44 -0
  101. package/dist/useUpload.js +296 -0
  102. package/dist/useWindowedSubscription.js +65 -0
  103. package/dist/useWorkflow.js +284 -0
  104. package/dist/useWorkflowRunState.js +93 -0
  105. package/dist/validation.js +39 -0
  106. package/dist/validationMessages.js +5 -0
  107. package/package.json +8 -5
  108. package/dist/authRefresh-C4Ow8HH7.js +0 -346
  109. package/dist/formData-dGz5aoUR.js +0 -649
  110. package/dist/queryOnce-CvdopzOj.js +0 -55
  111. package/dist/runRpc-DvHpFZAZ.js +0 -1034
@@ -0,0 +1,219 @@
1
+ import { Schema as e } from "effect";
2
+ import { finiteNumberView as t } from "@voltro/protocol";
3
+ import * as n from "effect/SchemaAST";
4
+ import * as r from "effect/SchemaRepresentation";
5
+ //#region src/schemaFields.ts
6
+ var i = (e) => ({ voltroField: e }), a = "x-voltro", o = (t) => e.makeFilter(() => !0, { toJsonSchema: () => ({ [a]: t }) }), s = {
7
+ "effect/schema/Date": "date",
8
+ "effect/schema/DateTimeUtc": "date-time"
9
+ }, c = (e) => {
10
+ let t = e.annotations?.representation;
11
+ return typeof t?.id == "string" ? t.id : void 0;
12
+ }, l = (e, t = /* @__PURE__ */ new Map()) => {
13
+ let n = t.get(e);
14
+ if (n !== void 0) return n;
15
+ let r = u(e, t);
16
+ return t.set(e, r), r;
17
+ }, u = (t, r) => {
18
+ let i = [t.annotations, ...(t.checks ?? []).map((e) => e.annotations)].map((e) => e?.voltroField).find((e) => e !== void 0), a = (t) => i === void 0 ? t : e.make(t).check(o(i)).ast;
19
+ if (n.isDeclaration(t)) {
20
+ let e = s[c(t) ?? ""];
21
+ if (e === void 0) return a(t);
22
+ let { title: r, description: i } = t.annotations ?? {};
23
+ return a(new n.String({
24
+ format: e,
25
+ ...typeof r == "string" ? { title: r } : {},
26
+ ...typeof i == "string" ? { description: i } : {}
27
+ }, void 0, void 0, t.context));
28
+ }
29
+ return t.encoding === void 0 ? n.isObjects(t) ? a(new n.Objects(t.propertySignatures.map((e) => new n.PropertySignature(e.name, l(e.type, r))), t.indexSignatures.map((e) => new n.IndexSignature(e.parameter, l(e.type, r))), t.annotations, t.checks, void 0, t.context)) : n.isArrays(t) ? a(new n.Arrays(t.isMutable, t.elements.map((e) => l(e, r)), t.rest.map((e) => l(e, r)), t.annotations, t.checks, void 0, t.context)) : n.isUnion(t) ? a(new n.Union(t.types.map((e) => l(e, r)), t.options, t.annotations, t.checks, void 0, t.context)) : n.isSuspend(t) ? a(new n.Suspend(() => l(t.thunk(), r), t.annotations, t.checks, void 0, t.context)) : a(t) : a(t);
30
+ }, d = "#/$defs/", f = (e) => e.replace(/[_-]+/g, " ").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/\s+/g, " ").trim().replace(/^./, (e) => e.toUpperCase()), p = (e) => {
31
+ let t = e.title;
32
+ if (typeof t != "string") return;
33
+ let n = t.trim();
34
+ return n === "" ? void 0 : n;
35
+ }, m = (e, t) => {
36
+ let n = e;
37
+ for (let e = 0; e < 8; e += 1) {
38
+ let e = n.$ref;
39
+ if (typeof e != "string" || !e.startsWith(d)) return g(n);
40
+ let r = t[e.slice(8)];
41
+ if (!r || typeof r != "object") return g(n);
42
+ n = r;
43
+ }
44
+ return g(n);
45
+ }, h = [
46
+ "Infinity",
47
+ "-Infinity",
48
+ "NaN"
49
+ ], g = (e) => {
50
+ let t = e.anyOf;
51
+ if (!Array.isArray(t) || t.length !== 2) return e;
52
+ let [n, r] = t, i = (e) => e.type === "number" && e.enum === void 0, a = (e) => e.type === "string" && Array.isArray(e.enum) && e.enum.every((e) => h.includes(e));
53
+ if (i(n) && a(r) || i(r) && a(n)) {
54
+ let { anyOf: t, ...n } = e;
55
+ return {
56
+ ...n,
57
+ type: "number"
58
+ };
59
+ }
60
+ return e;
61
+ }, _ = (e) => {
62
+ if (!e || typeof e != "object") return !1;
63
+ let t = e;
64
+ if (t.type === "null" || t.const === null) return !0;
65
+ let n = t.enum;
66
+ return Array.isArray(n) && n.length === 1 && n[0] === null;
67
+ }, v = (e, t) => {
68
+ let n = e.type;
69
+ if (Array.isArray(n) && n.includes("null")) {
70
+ let t = n.filter((e) => e !== "null");
71
+ return {
72
+ node: {
73
+ ...e,
74
+ type: t.length === 1 ? t[0] : t
75
+ },
76
+ nullable: !0
77
+ };
78
+ }
79
+ for (let n of ["anyOf", "oneOf"]) {
80
+ let r = e[n];
81
+ if (!Array.isArray(r)) continue;
82
+ let i, a = 0, o, s = r.length;
83
+ for (let e = 0; e < s; e++) {
84
+ if (!(e in r)) continue;
85
+ let t = r[e];
86
+ _(t) || (a += 1, a === 1 ? i = t : a === 2 ? o = [i, t] : o.push(t));
87
+ }
88
+ if (a !== r.length) return a === 1 ? {
89
+ ...v(m(i, t), t),
90
+ nullable: !0
91
+ } : {
92
+ node: {
93
+ ...e,
94
+ [n]: o ?? []
95
+ },
96
+ nullable: !0
97
+ };
98
+ }
99
+ return {
100
+ node: e,
101
+ nullable: !1
102
+ };
103
+ }, y = (e) => e.map((e) => ({
104
+ value: String(e),
105
+ label: f(String(e))
106
+ })), b = (e) => {
107
+ let t = e.enum;
108
+ if (Array.isArray(t) && t.length > 0) return {
109
+ widget: "select",
110
+ options: y(t)
111
+ };
112
+ let n = e.type, r = Array.isArray(n) ? n.find((e) => e !== "null") : n, i = e.format;
113
+ switch (r) {
114
+ case "string": return i === "date" ? { widget: "date" } : i === "date-time" ? { widget: "datetime" } : { widget: "text" };
115
+ case "integer":
116
+ case "number": return { widget: "number" };
117
+ case "boolean": return { widget: "checkbox" };
118
+ case "array": return { widget: "multi-select" };
119
+ default: return { widget: "custom" };
120
+ }
121
+ }, x = (...e) => {
122
+ for (let t of e) {
123
+ let e = [t, ...Array.isArray(t.allOf) ? t.allOf : []].find((e) => typeof e[a] == "object" && e[a] !== null);
124
+ if (e !== void 0) return e[a];
125
+ }
126
+ return {};
127
+ }, S = 4, C = (e, t, n, r = "", i, a = 0, o = []) => {
128
+ let s = Object.entries(e);
129
+ for (let e = 0; e < s.length; e += 1) {
130
+ let [c, l] = s[e], u = m(l, n), { node: d, nullable: h } = v(u, n), g = m(d, n), _ = x(g, u), y = r === "" ? c : `${r}.${c}`, w = g.properties;
131
+ if (g.type === "object" && w !== void 0 && a < S && _.widget === void 0) {
132
+ C(w, new Set(Array.isArray(g.required) ? g.required : []), n, y, {
133
+ path: _.section ?? y,
134
+ label: _.label ?? p(g) ?? f(c)
135
+ }, a + 1, o);
136
+ continue;
137
+ }
138
+ let { widget: T, options: E } = b(g), D, O = g;
139
+ if (g.type === "array") {
140
+ let e = g.items;
141
+ if (typeof e == "object" && e && !Array.isArray(e)) {
142
+ let t = m(e, n);
143
+ O = {
144
+ ...g,
145
+ items: t
146
+ };
147
+ let r = t.properties;
148
+ t.type === "object" && r !== void 0 && (T = "array", D = C(r, new Set(Array.isArray(t.required) ? t.required : []), n));
149
+ }
150
+ }
151
+ _.widget !== void 0 && (T = _.widget), _.reference !== void 0 && _.widget === void 0 && (T = "reference");
152
+ let k = typeof g.description == "string" ? g.description : void 0, A = _.section ?? i?.path;
153
+ o.push({
154
+ name: y,
155
+ label: _.label ?? p(g) ?? f(c),
156
+ widget: T,
157
+ required: t.has(c),
158
+ nullable: h,
159
+ ...E ? { options: E } : {},
160
+ jsonSchema: O,
161
+ ...A === void 0 ? {} : {
162
+ section: A,
163
+ sectionLabel: i?.label ?? f(A)
164
+ },
165
+ ...k === void 0 ? {} : { description: k },
166
+ ..._.order === void 0 ? {} : { order: _.order },
167
+ ...D === void 0 ? {} : { item: D },
168
+ ..._.reference === void 0 ? {} : { reference: _.reference }
169
+ });
170
+ }
171
+ return o;
172
+ }, w = (e) => {
173
+ let t = !1;
174
+ for (let n = 0; n < e.length; n += 1) if (e[n].order !== void 0) {
175
+ t = !0;
176
+ break;
177
+ }
178
+ if (!t) return e;
179
+ let n = e.map((e, t) => [e, t]).sort((e, t) => (e[0].order ?? e[1]) - (t[0].order ?? t[1]) || e[1] - t[1]);
180
+ for (let t = 0; t < n.length; t += 1) e[t] = n[t][0];
181
+ return e;
182
+ }, T = (n) => {
183
+ try {
184
+ let i = e.make(t(l(n.ast))), a = r.toJsonSchemaDocument(r.toRepresentation(e.toCodecJson(i).ast));
185
+ return {
186
+ root: a.schema,
187
+ defs: a.definitions
188
+ };
189
+ } catch {
190
+ return;
191
+ }
192
+ }, E = (e) => {
193
+ let t = T(e);
194
+ if (t === void 0) return [];
195
+ let { root: n, defs: r } = t, i = m(n, r), a = i.properties;
196
+ return a ? w(C(a, new Set(Array.isArray(i.required) ? i.required : []), r)) : [];
197
+ }, D = (e) => {
198
+ let t = T(e);
199
+ if (t === void 0) return [];
200
+ let { root: n, defs: r } = t, i = m(n, r);
201
+ if (i.type !== "array") return [];
202
+ let a = i.items;
203
+ if (!a || typeof a != "object") return [];
204
+ let o = m(a, r), s = o.properties;
205
+ return s ? C(s, new Set(Array.isArray(o.required) ? o.required : []), r) : [];
206
+ }, O = (e) => {
207
+ let t = [];
208
+ for (let n of e) {
209
+ let e = t[t.length - 1];
210
+ e !== void 0 && e.name === n.section ? e.fields.push(n) : t.push({
211
+ name: n.section,
212
+ label: n.sectionLabel,
213
+ fields: [n]
214
+ });
215
+ }
216
+ return t;
217
+ };
218
+ //#endregion
219
+ export { i as formField, O as formSections, D as schemaToColumns, E as schemaToFields };
@@ -0,0 +1,12 @@
1
+ //#region src/scopeMembership.ts
2
+ var e = (e) => {
3
+ if (!(e.length < 32 || Object.getPrototypeOf(e) !== Array.prototype || e.includes !== Array.prototype.includes || e[Symbol.iterator] !== Array.prototype[Symbol.iterator])) {
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
+ };
11
+ //#endregion
12
+ export { e as scopeMembership };
@@ -0,0 +1,7 @@
1
+ //#region src/seedResolvers.ts
2
+ var e = Symbol.for("@voltro/client/seedResolvers"), t = globalThis, n = t[e] ??= {
3
+ store: null,
4
+ preload: null
5
+ };
6
+ //#endregion
7
+ export { n as seedResolvers };
@@ -0,0 +1,65 @@
1
+ //#region src/sequence.ts
2
+ var e = () => {
3
+ let e = (t) => ({
4
+ steps: t,
5
+ step: ((n, r, i) => e([...t, {
6
+ name: n,
7
+ run: r,
8
+ undo: i?.undo,
9
+ covers: i?.covers ?? [],
10
+ when: i?.when
11
+ }]))
12
+ });
13
+ return e([]);
14
+ }, t = async (e, t = {}) => {
15
+ let n = {}, r = [];
16
+ for (let i of e.steps) if (i.when !== void 0 && !i.when(n)) n[i.name] = void 0;
17
+ else try {
18
+ let e = await i.run(n);
19
+ n[i.name] = e, r.push({
20
+ step: i,
21
+ result: e
22
+ });
23
+ } catch (e) {
24
+ let a = [], o = [], s = [], c = [];
25
+ if (t.compensate !== !1) {
26
+ let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
27
+ for (let i = r.length - 1; i >= 0; i--) {
28
+ let l = r[i], u = l.step.name;
29
+ if (t.has(u)) c.push({
30
+ step: u,
31
+ coveredBy: t.get(u)
32
+ });
33
+ else if (e.has(u)) s.push(u);
34
+ else if (l.step.undo !== void 0) try {
35
+ await l.step.undo(l.result, n), a.push(u);
36
+ for (let t of l.step.covers) e.set(t, u);
37
+ } catch (e) {
38
+ o.push({
39
+ step: u,
40
+ error: e
41
+ });
42
+ for (let e of l.step.covers) t.set(e, u);
43
+ }
44
+ }
45
+ }
46
+ let l = {
47
+ failedStep: i.name,
48
+ compensated: a,
49
+ compensationFailures: o,
50
+ compensationCovered: s,
51
+ compensationUncertain: c
52
+ };
53
+ return t.onError?.(e, l), {
54
+ ok: !1,
55
+ error: e,
56
+ ...l
57
+ };
58
+ }
59
+ return {
60
+ ok: !0,
61
+ data: n
62
+ };
63
+ };
64
+ //#endregion
65
+ export { t as runSequence, e as sequence };
@@ -0,0 +1,24 @@
1
+ import { globalContext as e } from "./globalContext.js";
2
+ import { FORM_FLASH_SCRIPT_ID as t } from "./formFlashId.js";
3
+ import { useContext as n, useMemo as r } from "react";
4
+ import { jsx as i } from "react/jsx-runtime";
5
+ //#region src/serverRequest.tsx
6
+ var a = e("serverRequest", null), o = () => n(a), s = ({ value: e, children: t }) => /* @__PURE__ */ i(a.Provider, {
7
+ value: e,
8
+ children: t
9
+ }), c = (e) => {
10
+ let n = o();
11
+ return r(() => {
12
+ if (n !== null) return n.formFlash?.formKey === e ? n.formFlash : void 0;
13
+ if (typeof document > "u") return;
14
+ let r = document.getElementById(t);
15
+ if (r !== null && r.textContent !== null && r.textContent !== "") try {
16
+ let t = JSON.parse(r.textContent);
17
+ return t.formKey === e ? t : void 0;
18
+ } catch {
19
+ return;
20
+ }
21
+ }, [n, e]);
22
+ };
23
+ //#endregion
24
+ export { a as ServerRequestContext, s as ServerRequestProvider, c as useFormFlash, o as useServerRequest };
@@ -0,0 +1,128 @@
1
+ import { squashRpcCause as e } from "./squashRpcCause.js";
2
+ import { resolveByTag as t } from "./tagWalk.js";
3
+ import { buildApiRuntime as n } from "./apiRuntime.js";
4
+ import { freshIdempotencyKey as r, withIdempotencyKey as i } from "./mutationIdentity.js";
5
+ import { Duration as a, Effect as o, Exit as s, Option as c, Schedule as l, Stream as u } from "effect";
6
+ import * as d from "effect/http/Headers";
7
+ import { RpcClient as f } from "effect/rpc";
8
+ import { ApiUnavailable as p, MUTATION_IN_FLIGHT_RETRY_AFTER_MS as m } from "@voltro/protocol";
9
+ //#region src/serviceClient.ts
10
+ var h = (e) => e?._tag === "MutationInFlight", g = 1e4, _ = (e, t) => {
11
+ let n = e.descriptors[t]?.kind;
12
+ return n === "query" || n === "mutation" || n === "action" ? n : void 0;
13
+ }, v = (g) => {
14
+ let v = g.defaultTimeoutMs ?? 1e4, y, b, x = !1, S = () => {
15
+ if (x) return Promise.reject(new p({
16
+ api: g.name,
17
+ tag: "",
18
+ reason: "closed",
19
+ message: "client closed"
20
+ }));
21
+ if (y !== void 0) return y;
22
+ let e = typeof g.wsUrl == "function" ? g.wsUrl() : g.wsUrl, t = g.webSocketConstructor ?? ((e, t) => new globalThis.WebSocket(e, typeof t == "object" && !Array.isArray(t) ? void 0 : t));
23
+ return y = n({
24
+ name: `service:${g.name}`,
25
+ wsUrl: e,
26
+ group: g.group,
27
+ headers: async () => ({ authorization: `Bearer ${g.token()}` }),
28
+ webSocketConstructor: t,
29
+ surfaceAudience: "service"
30
+ }).then((e) => (b = e, e), (e) => {
31
+ throw y = void 0, e;
32
+ }), y;
33
+ }, C = (e, t, n) => new p({
34
+ api: g.name,
35
+ tag: e,
36
+ reason: t,
37
+ message: n
38
+ }), w = (e) => {
39
+ let t = g.callHeaders?.() ?? {};
40
+ return e.pipe(o.updateService(f.CurrentHeaders, (e) => {
41
+ let n = d.set(e, "authorization", `Bearer ${g.token()}`);
42
+ for (let [e, r] of Object.entries(t)) n = d.set(n, e, r);
43
+ return n;
44
+ }));
45
+ }, T = (e) => e.pipe(u.filter((e) => e._tag === "snapshot" || e._tag === "error"), u.runHead, o.flatMap((e) => {
46
+ if (c.isNone(e)) return o.fail(/* @__PURE__ */ Error("the query stream ended before its first snapshot"));
47
+ let t = e.value;
48
+ return t._tag === "error" ? o.fail(t.error) : o.succeed(t.data);
49
+ })), E = (e, n, s) => {
50
+ let c = _(g, e), u = s?.timeoutMs ?? v, d = Date.now(), f = (t) => {
51
+ g.onCall?.({
52
+ api: g.name,
53
+ tag: e,
54
+ durationMs: Date.now() - d,
55
+ outcome: t
56
+ });
57
+ };
58
+ if (c === void 0) return o.die(/* @__PURE__ */ Error(`apis.${g.name}: '${e}' is not a service procedure of this api — is the caller built against an older contract?`));
59
+ let p = o.gen(function* () {
60
+ let u = yield* o.tryPromise({
61
+ try: () => S(),
62
+ catch: (t) => C(e, x ? "closed" : "transport", `could not build the connection: ${String(t)}`)
63
+ }), d = t(u.client, e);
64
+ if (c === "query") {
65
+ let e = d(n);
66
+ return yield* w(T(e));
67
+ }
68
+ let f = s?.idempotencyKey === void 0 && g.ambientIdempotencyKey !== void 0 ? yield* g.ambientIdempotencyKey(e, n) : void 0, p = s?.idempotencyKey ?? f ?? r();
69
+ return yield* w(i(d(n), p)).pipe(o.tapError((e) => o.sync(() => {
70
+ h(e) && (y = !0);
71
+ })), o.retry({
72
+ while: h,
73
+ schedule: l.spaced(a.millis(m))
74
+ }));
75
+ }), y = !1;
76
+ return p.pipe(o.timeoutOrElse({
77
+ duration: a.millis(u),
78
+ orElse: () => o.fail(C(e, "timeout", y ? `no answer within ${u} ms — an earlier send with this idempotency key is still in flight on the callee` : `no answer within ${u} ms`))
79
+ }), o.mapError((t) => t?._tag === "RpcClientError" ? C(e, "transport", String(t.message ?? t)) : t), o.tapError((e) => o.sync(() => f(e?._tag === "ApiUnavailable" ? "unavailable" : "error"))), o.tap(() => o.sync(() => f("ok"))));
80
+ };
81
+ return {
82
+ name: g.name,
83
+ call: async (t, n, r) => {
84
+ let i = await o.runPromiseExit(E(t, n, r), r?.signal === void 0 ? void 0 : { signal: r.signal });
85
+ if (s.isSuccess(i)) return i.value;
86
+ throw e(i.cause);
87
+ },
88
+ callEffect: E,
89
+ subscribe: (e, n, r) => {
90
+ if (_(g, e) !== "query") throw Error(`apis.${g.name}: '${e}' is not a query — only a query can be subscribed to`);
91
+ let i, a = !1, o = -2, s;
92
+ return S().then((c) => {
93
+ if (a) return;
94
+ let l = [e, n], u = c.cache.subscribe(l, () => t(c.client, e)(n), c.runtime, () => {
95
+ let e = u.getSnapshot();
96
+ e.error !== void 0 && e.error !== s && (s = e.error, r.onError?.(e.error)), e.revision >= 0 && e.revision !== o && e.data !== void 0 && (o = e.revision, r.onValue(e.data));
97
+ });
98
+ i = u.unsubscribe;
99
+ }, (t) => {
100
+ r.onError?.(C(e, "transport", `could not build the connection: ${String(t)}`));
101
+ }), { unsubscribe: () => {
102
+ a = !0, i?.();
103
+ } };
104
+ },
105
+ connected: () => b !== void 0,
106
+ close: async () => {
107
+ x = !0;
108
+ let e = b;
109
+ b = void 0, y = void 0, e !== void 0 && (e.cache.destroy(e.runtime), await e.runtime.dispose());
110
+ }
111
+ };
112
+ }, y = (e) => {
113
+ let t = (n) => {
114
+ let r = n.join("."), i = Object.assign((t, n) => e.call(r, t, n), {
115
+ effect: (t, n) => e.callEffect(r, t, n),
116
+ subscribe: (t, n) => e.subscribe(r, t, n)
117
+ });
118
+ return new Proxy(i, { get: (e, r) => {
119
+ if (typeof r == "string") {
120
+ if (r === "effect" || r === "subscribe") return e[r];
121
+ if (r !== "then") return t([...n, r]);
122
+ }
123
+ } });
124
+ };
125
+ return new Proxy({}, { get: (e, n) => typeof n == "string" && n !== "then" ? t([n]) : void 0 });
126
+ };
127
+ //#endregion
128
+ export { g as DEFAULT_SERVICE_CALL_TIMEOUT_MS, v as makeServiceClient, y as serviceApi };
@@ -0,0 +1,8 @@
1
+ import { Cause as e, Option as t, Schema as n } from "effect";
2
+ //#region src/squashRpcCause.ts
3
+ var r = (r) => {
4
+ let i = e.squash(r);
5
+ return t.isNone(e.findErrorOption(r)) && n.isSchemaError(i) && console.error("[voltro] a value failed its schema in the client — if it is the request payload, the request never reached the server, so no server log has it:\n" + i.message), i;
6
+ };
7
+ //#endregion
8
+ export { r as squashRpcCause };
@@ -0,0 +1,21 @@
1
+ //#region src/stableKey.ts
2
+ var e = (e) => {
3
+ let t = (e) => {
4
+ if (e == null) return "null";
5
+ if (typeof e == "string") return JSON.stringify(e);
6
+ if (typeof e == "number" || typeof e == "boolean") return String(e);
7
+ if (Array.isArray(e)) return `[${e.map(t).join(",")}]`;
8
+ if (typeof e == "object") {
9
+ let n = Object.keys(e).sort(), r = "";
10
+ for (let i = 0; i < n.length; i++) {
11
+ let a = n[i];
12
+ i > 0 && (r += ","), r += `${JSON.stringify(a)}:${t(e[a])}`;
13
+ }
14
+ return `{${r}}`;
15
+ }
16
+ return String(e);
17
+ };
18
+ return t(e);
19
+ };
20
+ //#endregion
21
+ export { e as stableKey };