@voltro/client 0.85.0 → 0.87.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/CHANGELOG.md +5987 -0
  2. package/THIRD-PARTY-NOTICES.md +1125 -34
  3. package/dist/analyticsCatalog.js +47 -0
  4. package/dist/apiConnectivity.js +33 -0
  5. package/dist/apiRoleTransports.js +48 -0
  6. package/dist/apiRuntime.js +145 -0
  7. package/dist/apiSocketTracker.js +21 -0
  8. package/dist/apiSupervisor.js +136 -0
  9. package/dist/authRefresh.js +20 -0
  10. package/dist/awaitResolvedApi.js +23 -0
  11. package/dist/bootstrap.d.ts +1153 -0
  12. package/dist/bootstrap.js +8 -0
  13. package/dist/cellMerger.js +6 -0
  14. package/dist/clientDiagnostics.js +94 -0
  15. package/dist/clientErrorBus.js +16 -0
  16. package/dist/clientScheduler.js +31 -0
  17. package/dist/connectionPrerequisite.js +70 -0
  18. package/dist/connectionScope.js +47 -0
  19. package/dist/connectionSetupController.js +206 -0
  20. package/dist/createHooks.js +15 -0
  21. package/dist/deepLink.js +69 -0
  22. package/dist/filters.js +58 -0
  23. package/dist/form.d.ts +37 -4
  24. package/dist/form.js +7 -2
  25. package/dist/formBinding.js +325 -0
  26. package/dist/formData.js +127 -0
  27. package/dist/formFlashId.js +4 -0
  28. package/dist/formRejection.js +23 -0
  29. package/dist/formSource.js +13 -0
  30. package/dist/frameworkRuntimesContext.js +8 -0
  31. package/dist/globalContext.js +10 -0
  32. package/dist/index.d.ts +152 -27
  33. package/dist/index.js +87 -4121
  34. package/dist/liveRowSort.js +66 -0
  35. package/dist/mutationConnectionSetup.js +16 -0
  36. package/dist/mutationIdentity.js +10 -0
  37. package/dist/mutationSerialExecution.js +53 -0
  38. package/dist/mutationsBus.js +40 -0
  39. package/dist/onlineSource.js +13 -0
  40. package/dist/outbox.js +213 -0
  41. package/dist/outboxHttp.js +104 -0
  42. package/dist/outboxState.js +43 -0
  43. package/dist/permissions.js +20 -0
  44. package/dist/platform.js +121 -0
  45. package/dist/preloadSeed.js +47 -0
  46. package/dist/provider.js +22 -0
  47. package/dist/query.js +12 -2
  48. package/dist/recoveryCoordinator.js +195 -0
  49. package/dist/recoveryRetry.js +24 -0
  50. package/dist/richText.js +176 -0
  51. package/dist/rpcErrorBus.js +39 -0
  52. package/dist/rpcErrorKind.js +13 -0
  53. package/dist/runRpc.js +12 -0
  54. package/dist/runtime.d.ts +49 -3
  55. package/dist/runtime.js +16 -126
  56. package/dist/runtimeCapabilities.js +44 -0
  57. package/dist/runtimeContext.js +49 -0
  58. package/dist/schemaFields.js +219 -0
  59. package/dist/scopeMembership.js +12 -0
  60. package/dist/seedResolvers.js +7 -0
  61. package/dist/sequence.js +65 -0
  62. package/dist/serverRequest.js +28 -0
  63. package/dist/serviceClient.js +129 -0
  64. package/dist/squashRpcCause.js +8 -0
  65. package/dist/stableKey.js +21 -0
  66. package/dist/store.js +288 -0
  67. package/dist/storeStorage.js +28 -0
  68. package/dist/subscriptionCache.js +724 -0
  69. package/dist/tagWalk.js +23 -0
  70. package/dist/traceBus.js +10 -0
  71. package/dist/tracking.js +40 -0
  72. package/dist/uploadProgress.js +21 -0
  73. package/dist/useAction.js +101 -0
  74. package/dist/useAgent.js +53 -0
  75. package/dist/useAgentChat.js +43 -0
  76. package/dist/useAgentStream.js +64 -0
  77. package/dist/useApiOnline.js +14 -0
  78. package/dist/useCapabilityManifest.js +105 -0
  79. package/dist/useConnectionSetup.js +28 -0
  80. package/dist/useConnectionStatus.js +38 -0
  81. package/dist/useConnections.js +107 -0
  82. package/dist/useDataCopilot.js +24 -0
  83. package/dist/useDataTable.js +34 -0
  84. package/dist/useDerived.js +22 -0
  85. package/dist/useEvent.js +98 -0
  86. package/dist/useFormBinding.js +478 -0
  87. package/dist/useLocalQuery.js +59 -0
  88. package/dist/useMutation.js +214 -0
  89. package/dist/useOnRpcError.js +13 -0
  90. package/dist/usePreloadedSubscription.js +18 -0
  91. package/dist/usePreview.js +14 -0
  92. package/dist/useProvenance.js +51 -0
  93. package/dist/useQueryField.js +34 -0
  94. package/dist/useRecord.js +12 -0
  95. package/dist/useRefreshSubscriptions.js +22 -0
  96. package/dist/useResourceCan.js +18 -0
  97. package/dist/useResumableAgentStream.js +75 -0
  98. package/dist/useRpcCaller.js +17 -0
  99. package/dist/useSequence.js +25 -0
  100. package/dist/useSkeleton.js +13 -0
  101. package/dist/useSubscription.js +98 -0
  102. package/dist/useSubscriptionHealth.js +32 -0
  103. package/dist/useTranscription.js +51 -0
  104. package/dist/useUndo.js +33 -0
  105. package/dist/useUndoLog.js +44 -0
  106. package/dist/useUpload.js +296 -0
  107. package/dist/useWindowedSubscription.js +65 -0
  108. package/dist/useWorkflow.js +284 -0
  109. package/dist/useWorkflowRunState.js +93 -0
  110. package/dist/validation.js +39 -0
  111. package/dist/validationMessages.js +5 -0
  112. package/package.json +7 -2
  113. package/dist/authRefresh-DmfSoCca.js +0 -360
  114. package/dist/formData-BfpBt7BQ.js +0 -769
  115. package/dist/queryOnce-D5Y4V1SB.js +0 -55
  116. package/dist/runRpc-Zfz3w709.js +0 -1172
package/dist/index.js CHANGED
@@ -1,4122 +1,88 @@
1
- import { A as e, C as t, D as n, E as r, O as i, S as a, T as o, _ as s, a as c, b as l, d as u, f as d, g as f, h as p, i as m, k as h, l as g, m as _, n as v, o as y, p as b, r as x, t as S, u as C, v as w, w as T, x as E, y as D } from "./runRpc-Zfz3w709.js";
2
- import { a as O, c as k, d as A, f as j, i as M, l as N, n as P, o as F, r as I, s as L, t as R, u as ee } from "./queryOnce-D5Y4V1SB.js";
3
- import { a as te, c as z, i as B, n as V, o as ne, r as H, s as re, t as ie } from "./authRefresh-DmfSoCca.js";
4
- import { C as ae, S as oe, _ as se, a as ce, b as le, c as ue, d as de, f as fe, g as pe, h as me, i as he, l as ge, m as _e, n as ve, o as ye, p as be, r as xe, s as Se, t as Ce, u as we, v as Te, w as Ee, x as De, y as Oe } from "./formData-BfpBt7BQ.js";
5
- import { createContext as ke, createElement as Ae, useCallback as U, useContext as je, useDebugValue as Me, useEffect as W, useId as Ne, useLayoutEffect as Pe, useMemo as G, useRef as K, useState as q, useSyncExternalStore as J } from "react";
6
- import { Cause as Fe, Duration as Ie, Effect as Y, Exit as Le, Fiber as Re, Option as ze, Schedule as Be, Schema as Ve, SchemaIssue as He, Semaphore as Ue, Stream as X } from "effect";
7
- import { PAIRING_HOST as We, PAIRING_SCHEME as Ge, PAIRING_STORAGE_KEY as Ke, applyPairing as qe, clearPairing as Je, errorMessage as Ye, errorTag as Xe, fieldIssuesOf as Ze, jsonSchemaDocumentOf as Qe, jsonSchemaOf as $e, pairingLink as et, parsePairingLink as tt, pluginTag as nt, readPairing as rt } from "@voltro/protocol";
8
- import { jsx as it } from "react/jsx-runtime";
9
- import { FormApi as at } from "@tanstack/form-core";
10
- import { useStore as ot } from "@tanstack/react-store";
11
- //#region src/provider.tsx
12
- var st = ({ apis: e, children: t, demand: n }) => {
13
- let r = G(() => ({
14
- get: (t) => {
15
- let n = e.get(t);
16
- if (!n) {
17
- let n = Array.from(e.keys()).join(", ") || "(none mounted)";
18
- throw Error(`@voltro/client: no api named ${JSON.stringify(t)}. Known apis: ${n}`);
19
- }
20
- return n;
21
- },
22
- names: Array.from(e.keys()),
23
- ...n === void 0 ? {} : { demand: n }
24
- }), [e]);
25
- return /* @__PURE__ */ it(I.Provider, {
26
- value: r,
27
- children: t
28
- });
29
- }, ct = Symbol.for("@voltro/client/storeStorageProvider"), lt = () => {
30
- let e = globalThis, t = e[ct];
31
- if (t !== void 0) return t;
32
- let n = {
33
- provider: void 0,
34
- used: !1
35
- };
36
- return e[ct] = n, n;
37
- }, ut = (e) => {
38
- if (typeof window > "u") return null;
39
- try {
40
- return (e === "session" ? window.sessionStorage : window.localStorage) ?? null;
41
- } catch {
42
- return null;
43
- }
44
- }, dt = (e) => {
45
- let t = lt();
46
- t.used && e !== null && console.warn("[voltro] setStoreStorage() was called after a persisted store had already read. That store booted against the previous backing store and will not be re-read. Install storage before the first render — on React Native, after awaiting hydrate()."), t.provider = e ?? void 0;
47
- }, ft = (e) => {
48
- let t = lt();
49
- return t.used = !0, (t.provider ?? ut)(e);
50
- }, pt = () => {
51
- let e = lt();
52
- e.provider = void 0, e.used = !1;
53
- }, mt = (e, t) => {
54
- if (Object.is(e, t)) return !0;
55
- if (typeof e != "object" || typeof t != "object" || e === null || t === null || Array.isArray(e) !== Array.isArray(t)) return !1;
56
- let n = Object.keys(e), r = Object.keys(t);
57
- if (n.length !== r.length) return !1;
58
- for (let r of n) if (!Object.prototype.hasOwnProperty.call(t, r) || !Object.is(e[r], t[r])) return !1;
59
- return !0;
60
- }, ht = 50, gt = /* @__PURE__ */ new Set(), _t = (e, t) => {
61
- gt.has(e) || (gt.add(e), console.warn(t));
62
- }, vt = "\0global", yt = null, bt = (e, t, n) => {
63
- let r = yt?.() ?? null;
64
- if (r === null) return n;
65
- let i = n;
66
- for (let n of r.seeds) n.store === e && n.key === t && (i = {
67
- ...i,
68
- ...n.value
69
- });
70
- return i;
71
- }, xt = (e, t) => {
72
- let n = e(), r = /* @__PURE__ */ new Set(), i = 0, a = 0, o, s, c = () => {
73
- if (i >= ht) throw i = 0, Error(`defineStore: notification depth exceeded ${ht} — a subscriber writes a NEW value every time it is notified, so the store can never settle. Look for a listener calling set() with something derived from the current state without converging.`);
74
- i += 1;
75
- try {
76
- for (let e of [...r]) e();
77
- } finally {
78
- --i;
79
- }
80
- };
81
- return {
82
- get: () => n,
83
- batch: (e, r) => {
84
- a === 0 && (o = n, s = e), a += 1;
85
- let i;
86
- try {
87
- i = r();
88
- } catch (e) {
89
- throw a === 1 && o !== void 0 && (n = o), --a, a === 0 && (o = void 0, s = void 0), e;
90
- }
91
- if (typeof i?.then == "function") throw a === 1 && o !== void 0 && (n = o), --a, a === 0 && (o = void 0, s = void 0), Error(`defineStore: batch('${e}') was given an async function. A batch is synchronous — everything after the first await would land outside it. Await the work first, then batch the writes: \`const r = await load(); store.batch('${e}', () => { … })\`.`);
92
- if (--a, a > 0) return;
93
- let l = o, u = s;
94
- o = void 0, s = void 0, !mt(l, n) && (t(l, n, u), c());
95
- },
96
- set: (e, r) => {
97
- let i = typeof e == "function" ? e(n) : {
98
- ...n,
99
- ...e
100
- };
101
- if (mt(i, n)) return;
102
- let o = n;
103
- n = i, !(a > 0) && (t(o, i, r), c());
104
- },
105
- reset: () => {
106
- let r = e();
107
- if (mt(r, n)) return;
108
- let i = n;
109
- n = r, !(a > 0) && (t(i, r, "reset"), c());
110
- },
111
- subscribe: (e) => (r.add(e), () => {
112
- r.delete(e);
113
- })
114
- };
115
- }, St = 200, Ct = [], wt = /* @__PURE__ */ new Set(), Tt = [], Et = () => Tt, Dt = (e) => (wt.add(e), () => {
116
- wt.delete(e);
117
- }), Ot = () => {
118
- Ct.length = 0, Tt = [];
119
- }, kt = (e, t) => {
120
- let n = Ct[e];
121
- if (n === void 0) return !1;
122
- let r = Nt.get(n.store);
123
- if (r === void 0) return !1;
124
- let i = t === "before" ? n.prev : n.next;
125
- jt = !0;
126
- try {
127
- r.set(() => i, n.key, `travel:${t}`);
128
- } finally {
129
- jt = !1;
130
- }
131
- return !0;
132
- }, At = !1, jt = !1, Mt = (e) => {
133
- Ct.push(e), Ct.length > St && Ct.shift(), Tt = [...Ct];
134
- for (let e of [...wt]) e();
135
- }, Nt = /* @__PURE__ */ new Map(), Pt = /* @__PURE__ */ new Map(), Ft = 0, It = !1, Lt = /* @__PURE__ */ new Map(), Rt = () => (It || (It = !0, queueMicrotask(() => {
136
- Ft += 1, It = !1;
137
- })), Ft), zt = Bt(((/* @__PURE__ */ Error()).stack ?? "").split("\n")[1] ?? "") ?? "";
138
- function Bt(e) {
139
- let t = e.trim().replace(/^at\s+/, ""), n = /\(([^()]+)\)\s*$/.exec(t)?.[1] ?? t;
140
- return n.length > 0 ? n : void 0;
141
- }
142
- var Vt = () => {
143
- let e = (/* @__PURE__ */ Error()).stack;
144
- if (typeof e != "string") return "<unknown>";
145
- for (let t of e.split("\n").slice(1)) {
146
- let e = Bt(t);
147
- if (e === void 0) continue;
148
- let n = e.replace(/:\d+:\d+$/, "");
149
- if (zt === "" || n !== zt.replace(/:\d+:\d+$/, "")) return n;
150
- }
151
- return "<unknown>";
152
- }, Ht = () => [...Nt.values()], Ut = (e, t, n) => {
153
- let r = Vt(), i = Rt(), a = Nt.get(e);
154
- if (a !== void 0) {
155
- let t = Pt.get(e) ?? "<unknown>", n = Lt.get(e) === i;
156
- if (r !== "<unknown>" && r === t && !n) return a;
157
- throw Error(`defineStore: '${e}' is already defined. Store names are the devtools + seed key, so two stores sharing one name would silently share state. Rename one.\n first: ${t}\n second: ${r}`);
158
- }
159
- let o = n?.persist, s = () => ft(o?.storage === "session" ? "session" : "local"), c = () => {
160
- let e = s();
161
- if (e === null || o === void 0) return;
162
- let t;
163
- try {
164
- t = e.getItem(o.key);
165
- } catch {
166
- return;
167
- }
168
- if (t === null) return;
169
- let n;
170
- try {
171
- n = JSON.parse(t);
172
- } catch {
173
- return;
174
- }
175
- return o.migrate ? o.migrate(n) : n;
176
- }, l = (e) => {
177
- let t = s();
178
- if (t === null || o === void 0) return;
179
- let n = o.pick ? o.pick(e) : e;
180
- try {
181
- t.setItem(o.key, JSON.stringify(n));
182
- } catch {}
183
- }, u = /* @__PURE__ */ new Map(), d = (n) => {
184
- let r = n ?? vt, i = u.get(r);
185
- if (i === void 0) {
186
- let a = n;
187
- i = xt(o !== void 0 && n === void 0 ? () => {
188
- let e = t();
189
- return f = e, {
190
- ...e,
191
- ...c() ?? {}
192
- };
193
- } : t, (t, n, r) => {
194
- if (o !== void 0 && a === void 0 && l(n), !At && !jt) {
195
- let e = m(a);
196
- e.steps.length = e.cursor, e.steps.push({
197
- prev: t,
198
- next: n
199
- }), e.steps.length > h && e.steps.shift(), e.cursor = e.steps.length;
200
- }
201
- Mt({
202
- store: e,
203
- ...a === void 0 ? {} : { key: a },
204
- ...r === void 0 ? {} : { label: r },
205
- ...At || jt ? { isUndo: !0 } : {},
206
- prev: t,
207
- next: n,
208
- at: Date.now()
209
- });
210
- }), u.set(r, i);
211
- }
212
- return i;
213
- }, f, p = /* @__PURE__ */ new Map(), m = (e) => {
214
- let t = e ?? vt, n = p.get(t);
215
- return n === void 0 && (n = {
216
- steps: [],
217
- cursor: 0
218
- }, p.set(t, n)), n;
219
- }, h = 100, g = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Map(), v = (e) => {
220
- let t = _.get(e);
221
- t !== void 0 && (clearTimeout(t), _.delete(e)), g.set(e, (g.get(e) ?? 0) + 1);
222
- }, y = (e) => {
223
- let t = (g.get(e) ?? 1) - 1;
224
- if (t > 0) {
225
- g.set(e, t);
226
- return;
227
- }
228
- g.delete(e), _.set(e, setTimeout(() => {
229
- _.delete(e), (g.get(e) ?? 0) === 0 && u.delete(e);
230
- }, 0));
231
- }, b = {
232
- name: e,
233
- use: (t, n) => {
234
- let r = d(n?.key), i = K(t);
235
- i.current = t;
236
- let a = K(n?.equals);
237
- a.current = n?.equals;
238
- let o = K({
239
- state: void 0,
240
- value: void 0,
241
- has: !1
242
- }), s = U((t) => {
243
- let n = o.current;
244
- if (n.has && Object.is(n.state, t)) return n.value;
245
- let r = i.current(t), s = a.current, c = n.has && (s ? s(n.value, r) : Object.is(n.value, r));
246
- if (process.env.NODE_ENV !== "production" && s === void 0 && n.has && !c && typeof r == "object" && r && mt(n.value, r)) {
247
- let t = !0;
248
- try {
249
- t = !Object.is(i.current(n.state), n.value);
250
- } catch {}
251
- _t(e, t ? `[@voltro/client] ${e}.use(): the selector returns a NEW object each call, so the default identity check never sees it as unchanged and this component re-renders on EVERY store change.\n Pass \`{ equals: shallow }\` (exported from @voltro/client), or select a primitive.` : `[@voltro/client] ${e}.use(): this component re-renders on store changes that do not change what it selects. The selector is stable — it returns the same reference for the same state — and the STORE is writing a new value that is equal one level deep (a fresh \`[]\` or \`{}\`, say).\n Pass \`{ equals: shallow }\` (exported from @voltro/client), or stop writing an equal value.`);
252
- }
253
- let l = c ? n.value : r;
254
- return o.current = {
255
- state: t,
256
- value: l,
257
- has: !0
258
- }, l;
259
- }, []), c = n?.key, l = n?.retain === !0, u = U((e) => {
260
- let t = r.subscribe(e);
261
- return c !== void 0 && !l && v(c), () => {
262
- t(), c !== void 0 && !l && y(c);
263
- };
264
- }, [
265
- r,
266
- c,
267
- l
268
- ]), p = U(() => s(r.get()), [r, s]), m = U(() => s(bt(e, n?.key, n?.key === void 0 && f !== void 0 ? f : r.get())), [
269
- r,
270
- n?.key,
271
- s
272
- ]), h = J(u, p, m);
273
- return Me(h), h;
274
- },
275
- instance: d,
276
- get: (e) => d(e).get(),
277
- set: (e, t, n) => {
278
- d(t).set(e, n);
279
- },
280
- batch: (e, t, n) => {
281
- d(n).batch(e, t);
282
- },
283
- undo: (e) => {
284
- let t = m(e);
285
- if (t.cursor === 0) return !1;
286
- --t.cursor, At = !0;
287
- try {
288
- d(e).set(() => t.steps[t.cursor].prev, "undo");
289
- } finally {
290
- At = !1;
291
- }
292
- return !0;
293
- },
294
- redo: (e) => {
295
- let t = m(e);
296
- if (t.cursor >= t.steps.length) return !1;
297
- let n = t.steps[t.cursor];
298
- t.cursor += 1, At = !0;
299
- try {
300
- d(e).set(() => n.next, "redo");
301
- } finally {
302
- At = !1;
303
- }
304
- return !0;
305
- },
306
- canUndo: (e) => m(e).cursor > 0,
307
- canRedo: (e) => {
308
- let t = m(e);
309
- return t.cursor < t.steps.length;
310
- },
311
- release: (e) => {
312
- u.delete(e), p.delete(e);
313
- },
314
- keys: () => {
315
- let e = [];
316
- for (let t of u.keys()) t !== vt && e.push(t);
317
- return e;
318
- }
319
- };
320
- return Nt.set(e, b), Pt.set(e, r), Lt.set(e, i), b;
321
- }, Wt = () => {
322
- Nt.clear(), Pt.clear(), Lt.clear(), gt.clear();
323
- }, Gt = () => ({ seeds: [] }), Kt = (e) => {
324
- yt = e;
325
- }, qt = (e, t, n) => {
326
- let r = yt?.() ?? null;
327
- if (r === null) throw Error(`seedStore('${e.name}') was called outside a server render. Seeding exists to put a value into the SSR hydration payload; on the client, set the store directly instead. (If this IS server code, the render did not install a seed bag — that is a framework bug.)`);
328
- r.seeds.push({
329
- store: e.name,
330
- ...n?.key === void 0 ? {} : { key: n.key },
331
- value: t
332
- });
333
- }, Jt = (e) => {
334
- if (e !== void 0) for (let t of e) {
335
- let e = Nt.get(t.store);
336
- e !== void 0 && e.set(t.value, t.key);
337
- }
338
- }, Yt = {
339
- read: () => typeof navigator > "u" || navigator.onLine,
340
- subscribe: (e) => {
341
- if (typeof window > "u") return () => {};
342
- let t = () => e(!0), n = () => e(!1);
343
- return window.addEventListener("online", t), window.addEventListener("offline", n), () => {
344
- window.removeEventListener("online", t), window.removeEventListener("offline", n);
345
- };
346
- }
347
- }, Xt = (e, t = {}) => {
348
- let n = e.platform.shell !== "browser" && e.platform.shell !== "node" && e.platform.shell !== "test";
349
- return {
350
- offlineStart: e.platform.installed || n,
351
- secureTokenStorage: e.secureStorage.kind !== "none",
352
- push: e.notifications?.pushToken !== void 0,
353
- localNotifications: e.notifications?.show !== void 0,
354
- updates: e.updates !== void 0,
355
- deepLinks: !0,
356
- biometrics: e.biometrics !== void 0,
357
- backgroundSync: e.platform.shell === "tauri" || e.platform.shell === "electron",
358
- installPrompt: e.platform.shell === "browser" && !e.platform.installed,
359
- ...t
360
- };
361
- }, Zt = (e) => {
362
- let { capabilities: t, ...n } = e;
363
- return {
364
- ...n,
365
- capabilities: Xt(n, t)
366
- };
367
- }, Qt = (e) => ({
368
- kind: "none",
369
- get: async () => null,
370
- set: async () => {
371
- throw Error(`secureStorage: ${e}`);
372
- },
373
- delete: async () => {}
374
- }), $t = () => {
375
- let e = /* @__PURE__ */ new Map();
376
- return {
377
- kind: "memory",
378
- get: async (t) => e.get(t) ?? null,
379
- set: async (t, n) => {
380
- e.set(t, n);
381
- },
382
- delete: async (t) => {
383
- e.delete(t);
384
- }
385
- };
386
- }, en = {
387
- read: () => typeof document > "u" ? "active" : document.visibilityState === "hidden" ? "background" : "active",
388
- subscribe: (e) => {
389
- if (typeof document > "u") return () => {};
390
- let t = () => e(document.visibilityState === "hidden" ? "background" : "active");
391
- return document.addEventListener("visibilitychange", t), () => document.removeEventListener("visibilitychange", t);
392
- }
393
- }, tn = {
394
- initialUrl: async () => typeof location > "u" ? null : location.href,
395
- subscribe: () => () => {}
396
- }, nn = () => {
397
- if (typeof Notification > "u") return;
398
- let e = (e) => e === "granted" ? "granted" : e === "denied" ? "denied" : "prompt";
399
- return {
400
- permission: async () => e(Notification.permission),
401
- requestPermission: async () => e(await Notification.requestPermission()),
402
- show: async (e) => {
403
- new Notification(e.title, {
404
- ...e.body === void 0 ? {} : { body: e.body },
405
- ...e.data === void 0 ? {} : { data: e.data }
406
- });
407
- }
408
- };
409
- }, rn = () => {
410
- if (typeof window > "u") return !1;
411
- let e = window.matchMedia;
412
- return typeof e == "function" && e.call(window, "(display-mode: standalone)").matches ? !0 : navigator.standalone === !0;
413
- }, an = (e, t) => {
414
- let n = globalThis.WebSocket;
415
- if (n === void 0) throw Error("platform: no global WebSocket in this environment");
416
- let r = typeof t == "object" && !Array.isArray(t) ? void 0 : t;
417
- return r === void 0 ? new n(e) : new n(e, r);
418
- }, on = (e = {}) => {
419
- let t = typeof window < "u", n = rn(), r = t ? navigator.userAgent : "", i = t ? /jsdom/i.test(r) ? "test" : "browser" : "node", a = nn();
420
- return Zt({
421
- platform: {
422
- kind: n ? "pwa" : "web",
423
- shell: i,
424
- installed: n
425
- },
426
- webSocket: an,
427
- storage: ut,
428
- secureStorage: Qt("a browser tab has no secure store a page can read; the session is an HttpOnly cookie the server sets"),
429
- online: Yt,
430
- lifecycle: en,
431
- links: tn,
432
- ...a === void 0 ? {} : { notifications: a },
433
- clock: { now: () => Date.now() },
434
- ...e
435
- });
436
- }, sn = Symbol.for("@voltro/client/platform"), cn = () => {
437
- let e = globalThis, t = e[sn];
438
- if (t !== void 0) return t;
439
- let n = {
440
- adapter: void 0,
441
- fallback: void 0,
442
- listeners: /* @__PURE__ */ new Set()
443
- };
444
- return e[sn] = n, n;
445
- }, ln = (e) => {
446
- let t = cn();
447
- t.adapter = e, dt(e.storage);
448
- for (let e of t.listeners) e();
449
- }, un = () => {
450
- let e = cn();
451
- return e.adapter === void 0 ? (e.fallback === void 0 && (e.fallback = on()), e.fallback) : e.adapter;
452
- }, dn = () => cn().adapter !== void 0, fn = () => {
453
- let e = cn();
454
- e.adapter = void 0, e.fallback = void 0, dt(null);
455
- for (let t of e.listeners) t();
456
- }, pn = (e) => {
457
- let t = cn();
458
- return t.listeners.add(e), () => {
459
- t.listeners.delete(e);
460
- };
461
- }, mn = () => J(pn, un, un), hn = (e) => mn().extensions?.[e] ?? null, gn = (e) => {
462
- let t = e.pattern;
463
- if (t.length === 0 || t[0] !== "/") throw Error(`defineDeepLink: pattern must start with "/" (got "${t}")`);
464
- return {
465
- _tag: "VoltroDeepLink",
466
- pattern: t,
467
- handler: e.handler
468
- };
469
- }, _n = (e) => {
470
- let t = e, n = /^([a-zA-Z][a-zA-Z0-9+.-]*):\/\//.exec(t);
471
- if (n) {
472
- let e = t.slice(n[0].length), r = n[1].toLowerCase();
473
- if (r === "http" || r === "https") {
474
- let n = e.indexOf("/");
475
- t = n === -1 ? "/" : e.slice(n);
476
- } else t = `/${e}`;
477
- }
478
- let r = t.search(/[?#]/);
479
- r !== -1 && (t = t.slice(0, r));
480
- let i = [];
481
- for (let e of t.split("/")) if (e.length !== 0) try {
482
- i.push(decodeURIComponent(e));
483
- } catch {
484
- i.push(e);
485
- }
486
- return i;
487
- }, vn = (e, t) => {
488
- let n = _n(e), r = _n(t);
489
- if (n.length !== r.length) return null;
490
- let i = {};
491
- for (let e = 0; e < n.length; e++) {
492
- let t = n[e], a = r[e];
493
- if (t.startsWith(":")) {
494
- let e = t.slice(1);
495
- if (e.length === 0) return null;
496
- i[e] = a;
497
- } else if (t !== "*" && t !== a) return null;
498
- }
499
- return i;
500
- }, yn = (e, t) => {
501
- let n = vn(e.pattern, t);
502
- return n === null ? null : (e.handler(n), n);
503
- }, bn = (e, t) => {
504
- let n = "", r = !0;
505
- for (let i of e.split("/")) if (r || (n += "/"), r = !1, !i.startsWith(":")) n += i;
506
- else {
507
- let r = i.slice(1), a = t[r];
508
- if (a === void 0) throw Error(`deepLinkHref: pattern "${e}" needs a ":${r}" param`);
509
- n += encodeURIComponent(a);
510
- }
511
- return n.length === 0 ? "/" : n;
512
- }, xn = (e, t) => {
513
- for (let n of e) {
514
- let e = vn(n.pattern, t);
515
- if (e !== null) return {
516
- descriptor: n,
517
- params: e
518
- };
519
- }
520
- return null;
521
- }, Sn = (e, t) => {
522
- let n = xn(e, t);
523
- if (n === null) return null;
524
- let r = n.descriptor.handler;
525
- return r(n.params), n.params;
526
- }, Cn = Object.freeze({
527
- data: void 0,
528
- revision: -1,
529
- emittedAt: void 0,
530
- error: void 0,
531
- pendingPatches: 0
532
- }), wn = () => Cn;
533
- function Z(e, t, n = {}, r = {}) {
534
- let i = r.skip === !0, { runtime: a, cache: o, client: s, descriptors: c } = A(e), l = c[t]?.source, u = K(n);
535
- u.current = n;
536
- let d = K(s);
537
- d.current = s;
538
- let f = G(() => JSON.stringify(Object.entries(n).sort(([e], [t]) => e.localeCompare(t))), [n]), p = G(() => {
539
- let e = u.current;
540
- return {
541
- queryKey: [t, e],
542
- fetch: () => v(d.current, t)(e)
543
- };
544
- }, [t, f]), m = p.queryKey, h = U((e) => i ? () => {} : o.subscribe(p.queryKey, p.fetch, a, e, l === void 0 ? {} : { source: l }).unsubscribe, [
545
- o,
546
- a,
547
- l,
548
- i,
549
- p
550
- ]), g = U(() => i ? Cn : o.peek(m), [
551
- o,
552
- i,
553
- m
554
- ]), _ = J(h, g, wn), y = _.data !== void 0, b = y && (Array.isArray(_.data) ? _.data.length === 0 : _.data === null), x = {
555
- revision: _.revision,
556
- emittedAt: _.emittedAt,
557
- error: _.error,
558
- pendingPatches: _.pendingPatches
559
- };
560
- if (r.initialSnapshot !== void 0) {
561
- let e = Array.isArray(r.initialSnapshot) ? r.initialSnapshot.length === 0 : r.initialSnapshot === null;
562
- return {
563
- ...x,
564
- data: y ? _.data : r.initialSnapshot,
565
- loading: !1,
566
- idle: i,
567
- isEmpty: y ? b : e,
568
- failed: !1
569
- };
570
- }
571
- return r.fallback === void 0 ? i ? {
572
- ...x,
573
- data: void 0,
574
- loading: !1,
575
- isEmpty: !1,
576
- idle: !0,
577
- failed: !1
578
- } : y ? {
579
- ...x,
580
- data: _.data,
581
- loading: !1,
582
- isEmpty: b,
583
- idle: !1,
584
- failed: !1
585
- } : x.error === void 0 ? {
586
- ...x,
587
- data: void 0,
588
- loading: !0,
589
- isEmpty: !1,
590
- idle: !1,
591
- failed: !1
592
- } : {
593
- ...x,
594
- data: void 0,
595
- loading: !1,
596
- isEmpty: !1,
597
- idle: !1,
598
- failed: !0,
599
- error: x.error
600
- } : {
601
- ...x,
602
- data: y ? _.data : r.fallback,
603
- loading: !y && !i,
604
- idle: i,
605
- isEmpty: b,
606
- failed: !y && x.error !== void 0
607
- };
608
- }
1
+ import { registerCellMerger as e, registeredCellMerger as t } from "./cellMerger.js";
2
+ import { publishClientTrace as n, subscribeClientTraces as r } from "./traceBus.js";
3
+ import { clearClientDiagnostics as i, clientDiagnosticsSnapshot as a, disableClientDiagnosticsPersistence as o, enableClientDiagnosticsPersistence as s, recordClientDiagnostic as c, subscribeClientDiagnostics as l } from "./clientDiagnostics.js";
4
+ import { stableKey as u } from "./stableKey.js";
5
+ import { LoadingSubscriptionCache as d, SubscriptionCache as f, supersedesConfirmedPatches as p } from "./subscriptionCache.js";
6
+ import { publishClientError as m, reportClientError as h, subscribeClientErrors as g } from "./clientErrorBus.js";
7
+ import { RpcErrorBus as _ } from "./rpcErrorBus.js";
8
+ import { apiConnectivity as v } from "./apiConnectivity.js";
9
+ import { INITIAL_RECOVERY_SNAPSHOT as y, RecoveryCoordinator as b, recoveryCoordinatorFor as x, resolveRecoveryOptions as S } from "./recoveryCoordinator.js";
10
+ import { globalContext as C } from "./globalContext.js";
11
+ import { FrameworkRuntimesContext as w, isUnresolvedApi as T, unknownApiError as E } from "./frameworkRuntimesContext.js";
12
+ import { _resetFrameworkRuntimesWarning as D, _resetSsrDescriptors as O, registerSsrDescriptors as k, ssrClientProxy as A, ssrDescriptorsFor as j, ssrStubHandle as M, useFrameworkApi as N, useFrameworkRuntimes as P } from "./runtimeContext.js";
13
+ import { resolveByTag as F } from "./tagWalk.js";
14
+ import { buildApiRuntime as I, makeProtocolOpenRecovery as L } from "./apiRuntime.js";
15
+ import { startApiSupervisor as R } from "./apiSupervisor.js";
16
+ import { FrameworkRuntimesProvider as z } from "./provider.js";
17
+ import { browserStoreStorage as B, resetStoreStorageForTest as V, resolveStoreStorage as H, setStoreStorage as U } from "./storeStorage.js";
18
+ import { applyStoreSeeds as W, clearStoreHistory as G, defineStore as K, definedStores as q, makeStoreSeedBag as J, resetStoreRegistryForTests as Y, seedStore as X, setStoreSeedResolver as Z, shallow as Q, storeHistory as $, subscribeStoreHistory as ee, travelToStoreState as te } from "./store.js";
19
+ import { browserOnlineSource as ne } from "./onlineSource.js";
20
+ import { browserPlatform as re, capabilitiesOf as ie, currentPlatform as ae, definePlatform as oe, installPlatform as se, isPlatformInstalled as ce, isStandaloneDisplay as le, memoryTokenStore as ue, refusingTokenStore as de, resetPlatformForTest as fe, usePlatform as pe, useShellExtension as me } from "./platform.js";
21
+ import { deepLinkHref as he, defineDeepLink as ge, dispatchDeepLink as _e, matchDeepLink as ve, matchFirstDeepLink as ye, runDeepLink as be } from "./deepLink.js";
22
+ import { useSubscription as xe } from "./useSubscription.js";
23
+ import { clearMutations as Se, getMutations as Ce, settleMutation as we, startMutation as Te, subscribeMutations as Ee } from "./mutationsBus.js";
24
+ import { freshIdempotencyKey as De, withIdempotencyKey as Oe } from "./mutationIdentity.js";
25
+ import { MutationSerialExecutionError as ke } from "./mutationSerialExecution.js";
26
+ import { getMutationNotifier as Ae, setMutationNotifier as je, useMutation as Me } from "./useMutation.js";
27
+ import { useAction as Ne } from "./useAction.js";
28
+ import { formField as Pe, formSections as Fe, schemaToColumns as Ie, schemaToFields as Le } from "./schemaFields.js";
29
+ import { decodeFieldIssues as Re, documentLocale as ze, resolveValidationMessage as Be, restrictToSchema as Ve, validateFields as He } from "./formBinding.js";
30
+ import { ValidationMessagesProvider as Ue, useValidationMessages as We } from "./validationMessages.js";
31
+ import { RICH_TEXT_MARKS as Ge, RICH_TEXT_MAX_NODES as Ke, RichTextDocument as qe, emptyRichTextDocument as Je, isRichTextDocument as Ye, isSafeHref as Xe, parseRichText as Ze, richTextToPlainText as Qe, serializeRichText as $e } from "./richText.js";
32
+ import { FORM_FLASH_SCRIPT_ID as et } from "./formFlashId.js";
33
+ import { FORM_CAPTURE_FIELD as tt, FORM_CAPTURE_META_NAME as nt, FORM_KEY_FIELD as rt, FORM_PATH_PREFIX as it, FORM_REDIRECT_FIELD as at, FORM_SOURCE_FIELD as ot, encodeNativeFormCapture as st, formActionPath as ct, formCaptureSource as lt, formSourcePath as ut, readFormCaptureSource as dt } from "./formSource.js";
34
+ import { formDataToInput as ft, recoverNativeFormValues as pt } from "./formData.js";
35
+ import { ServerRequestContext as mt, ServerRequestProvider as ht, useFormCapture as gt, useFormFlash as _t, useServerRequest as vt } from "./serverRequest.js";
36
+ import { FormBindingProvider as yt, useFormBinding as bt, useFormBindingContext as xt, useFormField as St, useSchemaFormBinding as Ct } from "./useFormBinding.js";
37
+ import { useConnectionSetup as wt } from "./useConnectionSetup.js";
38
+ import { createHooks as Tt } from "./createHooks.js";
39
+ import { applyPreloadSeeds as Et, makePreloadSeedBag as Dt, readPreloadedSeedOutcome as Ot, readPreloadedSnapshot as kt, resetPreloadSeeds as At, seedPreloadedSubscription as jt, seedPreloadedSubscriptionFailure as Mt, setPreloadSeedResolver as Nt } from "./preloadSeed.js";
40
+ import { usePreloadedSubscription as Pt } from "./usePreloadedSubscription.js";
41
+ import { useEvent as Ft } from "./useEvent.js";
42
+ import { runSequence as It, sequence as Lt } from "./sequence.js";
43
+ import { useSequence as Rt } from "./useSequence.js";
44
+ import { useRpcCaller as zt } from "./useRpcCaller.js";
45
+ import { useUpload as Bt } from "./useUpload.js";
46
+ import { useTranscription as Vt } from "./useTranscription.js";
47
+ import { useWorkflow as Ht, useWorkflowDomainEvents as Ut, useWorkflowEventDeliveries as Wt, useWorkflowEvents as Gt, useWorkflowRun as Kt, useWorkflowRunEvents as qt, useWorkflowRunSteps as Jt, useWorkflowRuns as Yt, useWorkflowSignal as Xt, useWorkflowUpdate as Zt } from "./useWorkflow.js";
48
+ import { useWorkflowRunState as Qt } from "./useWorkflowRunState.js";
49
+ import { useAgentStream as $t } from "./useAgentStream.js";
50
+ import { resumableConsumeProgram as en, useResumableAgentStream as tn } from "./useResumableAgentStream.js";
51
+ import { useAgentChat as nn } from "./useAgentChat.js";
52
+ import { useAgent as rn } from "./useAgent.js";
53
+ import { useDataCopilot as an } from "./useDataCopilot.js";
54
+ import { useRefreshSubscription as on, useRefreshSubscriptions as sn } from "./useRefreshSubscriptions.js";
55
+ import { queryOnce as cn } from "./query.js";
56
+ import { isUnauthenticated as ln, wireAuthRefresh as un } from "./authRefresh.js";
57
+ import { useOnRawRpcError as dn, useOnRpcError as fn } from "./useOnRpcError.js";
58
+ import { useSubscriptionHealth as pn } from "./useSubscriptionHealth.js";
59
+ import { encodeFormRejection as mn } from "./formRejection.js";
60
+ import { rowsToOptions as hn, useQueryField as gn } from "./useQueryField.js";
61
+ import { useDataTable as _n } from "./useDataTable.js";
62
+ import { provenanceUrl as vn, useProvenance as yn } from "./useProvenance.js";
63
+ import { ADMIN_SCOPE as bn, PermissionProvider as xn, canCall as Sn, canCallAny as Cn, useCan as wn, useCanAny as Tn, usePermissions as En } from "./permissions.js";
64
+ import { decideAccess as Dn, deriveEntityAdmins as On, manifestUrl as kn, openAccessReason as An, requiredScopes as jn, useAccessDecision as Mn, useCapabilityManifest as Nn } from "./useCapabilityManifest.js";
65
+ import { useUndo as Pn } from "./useUndo.js";
66
+ import { UNDO_APPLY_TAG as Fn, UNDO_LOG_TAG as In, UNDO_REDO_TAG as Ln, useUndoLog as Rn } from "./useUndoLog.js";
67
+ import { defineTracking as zn, resolveTrackingEvent as Bn, useTracking as Vn, wrapTrackedCallbacks as Hn } from "./tracking.js";
68
+ import { useFormSkeleton as Un, useTableSkeleton as Wn } from "./useSkeleton.js";
69
+ import { shallowArrayEqual as Gn, sourceValues as Kn, useDerived as qn } from "./useDerived.js";
70
+ import { useResourceCan as Jn, useResourceCans as Yn } from "./useResourceCan.js";
71
+ import { filtersFromSchema as Xn, useQueryFilters as Zn } from "./filters.js";
72
+ import { useRecord as Qn } from "./useRecord.js";
73
+ import { useAsyncValidation as $n, useDebounced as er, validationStatus as tr } from "./validation.js";
74
+ import { createAnalytics as nr, defineEvent as rr, eventCatalog as ir, validateEventPayload as ar } from "./analyticsCatalog.js";
75
+ import { usePreview as or } from "./usePreview.js";
76
+ import { readApiOnline as sr, subscribeApiOnline as cr, useApiOnline as lr } from "./useApiOnline.js";
77
+ import { clearSent as ur, defaultOutboxRetryDelay as dr, enqueueEntry as fr, markConflict as pr, markFailed as mr, markSent as hr, replayable as gr, resolveConflictEntry as _r, useOutbox as vr } from "./outbox.js";
78
+ import { OUTBOX_DB_NAME as yr, OUTBOX_SYNC_TAG as br, drainOutboxInWorker as xr, drainOutboxOverHttp as Sr, indexedDbOutboxPersistence as Cr, rpcHttpOutcome as wr } from "./outboxHttp.js";
79
+ import { computeWindow as Tr, useWindowedSubscription as Er } from "./useWindowedSubscription.js";
80
+ import { useConnectionStatus as Dr } from "./useConnectionStatus.js";
81
+ import { runLocalQuery as Or, useLocalQuery as kr } from "./useLocalQuery.js";
82
+ import { CONNECTIONS_LIST_TAG as Ar, CONNECTION_DISCONNECT_TAG as jr, CONNECTION_START_TAG as Mr, CONNECTION_SUBMIT_TOKEN_TAG as Nr, useConnection as Pr, useConnections as Fr } from "./useConnections.js";
83
+ import { makeApiRoleSocketTracker as Ir, makeApiSocketTracker as Lr } from "./apiSocketTracker.js";
84
+ import { DEV_ACTIVITY_EVENT as Rr, PAIRING_HOST as zr, PAIRING_SCHEME as Br, PAIRING_STORAGE_KEY as Vr, applyPairing as Hr, clearPairing as Ur, errorMessage as Wr, errorTag as Gr, jsonSchemaDocumentOf as Kr, jsonSchemaOf as qr, pairingLink as Jr, parsePairingLink as Yr, readPairing as Xr } from "@voltro/protocol";
85
+ //#region src/index.ts
86
+ var Zr = "framework-client";
609
87
  //#endregion
610
- //#region src/mutationsBus.ts
611
- var Tn = 100, En = [], Dn = /* @__PURE__ */ new Set(), On = [], kn = () => {
612
- On = En.slice();
613
- }, An = () => {
614
- kn();
615
- for (let e of Dn) try {
616
- e();
617
- } catch {}
618
- }, jn = (e) => {
619
- let t = {
620
- ...e,
621
- kind: e.kind ?? "mutation",
622
- status: "pending",
623
- startedAt: Date.now()
624
- };
625
- En.unshift(t), En.length > Tn && (En.length = Tn), An();
626
- }, Mn = (e, t) => {
627
- let n = En.findIndex((t) => t.id === e);
628
- if (n === -1) return;
629
- let r = En[n], i = Date.now();
630
- En[n] = t.status === "success" ? {
631
- ...r,
632
- status: "success",
633
- output: t.output,
634
- settledAt: i,
635
- durationMs: i - r.startedAt
636
- } : {
637
- ...r,
638
- status: "error",
639
- error: t.error,
640
- settledAt: i,
641
- durationMs: i - r.startedAt
642
- }, An();
643
- }, Nn = () => On, Pn = (e) => (Dn.add(e), () => {
644
- Dn.delete(e);
645
- }), Fn = () => {
646
- En.length !== 0 && (En.length = 0, An());
647
- }, In = /* @__PURE__ */ new WeakMap(), Ln = (e, t) => {
648
- let n = Object.freeze({
649
- apiName: e,
650
- kind: "connection-setup"
651
- });
652
- return In.set(n, t), n;
653
- }, Rn = (e, t) => {
654
- let n = In.get(e);
655
- if (n === void 0 || e.apiName !== t) throw Error(`Voltro: connection setup must belong to api "${t}"`);
656
- return n;
657
- }, zn = /* @__PURE__ */ new WeakMap(), Bn = (e, t) => {
658
- zn.set(e, t);
659
- }, Vn = (e) => zn.get(e)?.capture(), Hn = class extends Error {
660
- reason;
661
- _tag = "MutationSerialExecutionError";
662
- constructor(e) {
663
- super(`Serial mutation cannot start: ${e}`), this.reason = e, this.name = "MutationSerialExecutionError";
664
- }
665
- }, Un = (e = 32) => {
666
- if (!Number.isSafeInteger(e) || e < 1) throw RangeError("maxPending must be a positive safe integer");
667
- let t = /* @__PURE__ */ new WeakMap(), n = 0;
668
- return { reserve(r, i) {
669
- if (typeof r != "string" || r.length === 0) throw new Hn("invalid-key");
670
- if (i.aborted) throw new Hn("scope-changed");
671
- let a = t.get(i);
672
- a === void 0 && (a = /* @__PURE__ */ new Map(), t.set(i, a));
673
- let o = a, s = a.get(r);
674
- if (s?.blocked.signal.aborted) throw new Hn("unknown-predecessor");
675
- if (n >= e) throw new Hn("capacity");
676
- s === void 0 && (s = {
677
- semaphore: Ue.makeUnsafe(1),
678
- calls: 0,
679
- blocked: new AbortController()
680
- }, a.set(r, s));
681
- let c = s;
682
- n += 1, c.calls += 1;
683
- let l = new AbortController(), u = () => l.abort();
684
- i.addEventListener("abort", u, { once: !0 }), c.blocked.signal.addEventListener("abort", u, { once: !0 });
685
- let d = () => {
686
- if (i.aborted) throw new Hn("scope-changed");
687
- if (c.blocked.signal.aborted) throw new Hn("unknown-predecessor");
688
- }, f = Y.runPromise(c.semaphore.take(1), { signal: l.signal }), p = f.then(() => {
689
- d();
690
- }, (e) => {
691
- throw d(), e;
692
- });
693
- p.catch(() => {});
694
- let m = !1;
695
- return {
696
- ready: p,
697
- assertActive: d,
698
- release(e) {
699
- m || (m = !0, e === "unknown" && c.blocked.abort(), f.then(() => {
700
- Y.runSync(c.semaphore.release(1));
701
- }, () => {}).finally(() => {
702
- i.removeEventListener("abort", u), c.blocked.signal.removeEventListener("abort", u), --n, --c.calls, c.calls === 0 && !c.blocked.signal.aborted && o.delete(r);
703
- }));
704
- }
705
- };
706
- } };
707
- }, Wn = /* @__PURE__ */ new WeakMap(), Gn = (e, t, n) => {
708
- let r = Wn.get(e);
709
- r === void 0 && (r = /* @__PURE__ */ new Map(), Wn.set(e, r));
710
- let i = r.get(t);
711
- return i === void 0 && (i = Un(n), r.set(t, i)), i;
712
- }, Kn = (e, t) => {
713
- if (t === void 0 || typeof e != "object" || !e) return e;
714
- try {
715
- Object.defineProperty(e, "__voltroTraceId", {
716
- value: t,
717
- enumerable: !1,
718
- configurable: !0
719
- });
720
- } catch {}
721
- return e;
722
- }, qn, Jn = (e) => {
723
- qn = e;
724
- }, Yn = () => qn, Xn = (e, t, n) => typeof e == "function" ? e(t, n) : e, Zn = 0, Qn = () => `mut_${++Zn}`, $n = (e, t) => ({
725
- update: (n, r) => {
726
- e.update(n, r, t);
727
- },
728
- forTag: (n, r) => e.forTag(n, r, t)
729
- }), er = (e, t) => {
730
- let n = A(e), { descriptors: i } = n, a = K(n);
731
- a.current = n;
732
- let s = i[t], l = s?.targets;
733
- if (process.env.NODE_ENV !== "production") {
734
- let n = s?.kind;
735
- n !== void 0 && n !== "mutation" && console.error(`[@voltro/client] useMutation('${e}', '${t}') targets a ${n}, not a mutation. Use ${n === "action" ? "useAction" : n === "workflow" ? "useWorkflow" : `the ${n} hook`} instead.`);
736
- }
737
- let [u, d] = q(!1), [f, p] = q(void 0), [m, h] = q(void 0), g = K(null), _ = K(!1), y = K(0), b = U(async (n, i) => {
738
- let s = i?.onError !== void 0 || i?.notify?.error !== void 0, u = (e) => {
739
- i?.onError?.(e, n);
740
- let t = Xn(i?.notify?.error, e, n);
741
- t !== void 0 && qn?.error(t);
742
- };
743
- y.current += 1;
744
- let f = () => d(--y.current > 0);
745
- d(!0), p(void 0);
746
- let m, x, C, w, T;
747
- try {
748
- w = Vn(b);
749
- let r = a.current.descriptors[t]?.serialize;
750
- if (r !== void 0) {
751
- let i = a.current, o = i.recovery ?? c(i.errorBus, e);
752
- T = Gn(i.descriptors, t, r.maxPending ?? 32).reserve(r.key(n), o.subjectSignal);
753
- }
754
- ({runtime: m, cache: x, client: C} = await P(a, e, t));
755
- } catch (e) {
756
- if (T?.release(), f(), p(e), a.current.errorBus.emit({
757
- source: "mutation",
758
- tag: t,
759
- error: e,
760
- kind: "client",
761
- outcome: "not-started"
762
- }), s) return u(e);
763
- throw e;
764
- }
765
- let E = Qn(), D = i?.idempotencyKey ?? H();
766
- jn({
767
- id: E,
768
- apiName: e,
769
- tag: t,
770
- input: n
771
- });
772
- let O = g.current, k = _.current;
773
- try {
774
- O ? O($n(x, E), n) : !k && l && l.length > 0 && x.autoApply(l, n, E);
775
- } catch (e) {
776
- if (T?.release(), p(e), f(), x.revertByMutation(E), Mn(E, {
777
- status: "error",
778
- error: e
779
- }), s) return u(e);
780
- throw e;
781
- }
782
- let A, j = !1, M, N, F, I = Date.now();
783
- try {
784
- if (T) {
785
- await T.ready, T.assertActive();
786
- let n = await P(a, e, t);
787
- m = n.runtime, C = n.client;
788
- }
789
- let s = async (i, o, s, c) => {
790
- let l = z(i), u = l?.getSnapshot();
791
- N = l === void 0 ? void 0 : () => a.current.runtime === i && u !== void 0 && l.getSnapshot() === u, c?.(), T?.assertActive();
792
- let d = w === void 0 ? void 0 : await w.prepare(i, o);
793
- u = l?.getSnapshot(), c?.();
794
- let f = v(o, t), p = B(f(n), D), m = Y.currentSpan.pipe(Y.tap((e) => Y.sync(() => {
795
- A = e.traceId, r({
796
- traceId: e.traceId,
797
- spanId: e.spanId,
798
- source: "mutation",
799
- tag: t
800
- });
801
- })), Y.catch(() => Y.void), Y.andThen(Y.try({
802
- try: () => {
803
- c?.(), T?.assertActive(), j = !0;
804
- },
805
- catch: (e) => e
806
- })), Y.andThen(p)).pipe(Y.withSpan(`client.mutation.${t}`, { attributes: {
807
- "voltro.api": e,
808
- "voltro.mutationId": E,
809
- "rpc.tag": t,
810
- "voltro.replay": s
811
- } }));
812
- return d === void 0 ? S(i, m) : d.run(m);
813
- }, l;
814
- try {
815
- l = await s(m, C, !1);
816
- } catch (n) {
817
- let r = o(n, j ? "handler" : "client"), i = Kn(n, A);
818
- r === "transport" && (a.current.errorBus.emit({
819
- source: "mutation",
820
- tag: t,
821
- error: i,
822
- kind: r,
823
- ...N === void 0 ? {} : { affectsTransport: N() },
824
- outcome: j ? "unknown" : "not-started",
825
- ...A === void 0 ? {} : { traceId: A }
826
- }), M = i);
827
- let u = a.current, d = u.recovery ?? c(u.errorBus, e), f = r === "transport" ? d.reserveMutationReplay(I) : void 0;
828
- if (f === void 0) throw i;
829
- try {
830
- if (!await d.waitForMutationReplaySupport(I) || !await d.waitForProtocolReady(I) || !f.isValid()) throw i;
831
- let n = () => {
832
- if (!f.isValid()) throw i;
833
- };
834
- for (;;) {
835
- n();
836
- let r = await P(a, e, t);
837
- try {
838
- l = await s(r.runtime, r.client, !0, n);
839
- break;
840
- } catch (e) {
841
- let t = e;
842
- if (t?._tag !== "MutationInFlight") throw e;
843
- let r = typeof t.retryAfterMs == "number" && Number.isFinite(t.retryAfterMs) && t.retryAfterMs > 0 ? t.retryAfterMs : 1e3;
844
- if (r >= d.replayWindowRemaining(I)) throw e;
845
- await new Promise((e) => setTimeout(e, r)), n();
846
- }
847
- }
848
- } finally {
849
- f.release();
850
- }
851
- }
852
- h(l), Mn(E, {
853
- status: "success",
854
- output: l
855
- }), a.current.errorBus.emitSuccess({
856
- source: "mutation",
857
- tag: t
858
- }), x.confirmByMutation(E), i?.onSuccess?.(l, n);
859
- let u = Xn(i?.notify?.success, l, n);
860
- return u !== void 0 && qn?.success(u), l;
861
- } catch (e) {
862
- j && (M !== void 0 || o(e, "handler") === "transport") && (F = "unknown");
863
- let n = Kn(e, A);
864
- if (p(n), Mn(E, {
865
- status: "error",
866
- error: n
867
- }), x.revertByMutation(E), Object.is(M, n) || a.current.errorBus.emit({
868
- source: "mutation",
869
- tag: t,
870
- error: n,
871
- kind: j ? o(e, "handler") : "client",
872
- ...N === void 0 ? {} : { affectsTransport: N() },
873
- outcome: j && o(e, "handler") === "transport" ? "unknown" : j ? "known" : "not-started",
874
- ...A === void 0 ? {} : { traceId: A }
875
- }), s) return u(n);
876
- throw n;
877
- } finally {
878
- T?.release(F), f();
879
- }
880
- }, [
881
- e,
882
- t,
883
- l
884
- ]);
885
- return G(() => {
886
- let t = {
887
- mutate: b,
888
- pending: u,
889
- error: f,
890
- data: m,
891
- withOptimistic: (e) => (g.current = e, t),
892
- withoutOptimistic: () => (_.current = !0, t),
893
- withConnectionSetup: (n) => (Bn(b, Rn(n, e)), t)
894
- };
895
- return t;
896
- }, [
897
- b,
898
- u,
899
- f,
900
- m,
901
- e
902
- ]);
903
- }, tr = (e, t) => {
904
- if (t === void 0 || typeof e != "object" || !e) return e;
905
- try {
906
- Object.defineProperty(e, "__voltroTraceId", {
907
- value: t,
908
- enumerable: !1,
909
- configurable: !0
910
- });
911
- } catch {}
912
- return e;
913
- }, nr = (e, t, n) => typeof e == "function" ? e(t, n) : e, rr = 0, ir = () => `act_${++rr}`, ar = (e, t) => {
914
- let n = A(e), { descriptors: i } = n, a = K(n);
915
- if (a.current = n, process.env.NODE_ENV !== "production") {
916
- let n = i[t]?.kind;
917
- n !== void 0 && n !== "action" && console.error(`[@voltro/client] useAction('${e}', '${t}') targets a ${n}, not an action. Use ${n === "mutation" ? "useMutation" : n === "workflow" ? "useWorkflow" : `the ${n} hook`} instead.`);
918
- }
919
- let [s, c] = q(!1), [l, u] = q(void 0), [d, f] = q(void 0), p = U(async (n, i) => {
920
- let s = i?.onError !== void 0 || i?.notify?.error !== void 0;
921
- c(!0), u(void 0);
922
- let l = ir(), d = i?.idempotencyKey ?? H();
923
- jn({
924
- id: l,
925
- apiName: e,
926
- tag: t,
927
- input: n,
928
- kind: "action"
929
- });
930
- let p, m = !1;
931
- try {
932
- let { runtime: o, client: s } = await P(a, e, t), c = v(s, t), u = Y.currentSpan.pipe(Y.tap((e) => Y.sync(() => {
933
- p = e.traceId, r({
934
- traceId: e.traceId,
935
- spanId: e.spanId,
936
- source: "action",
937
- tag: t
938
- });
939
- })), Y.catch(() => Y.void), Y.andThen(B(c(n), d))).pipe(Y.withSpan(`client.action.${t}`, { attributes: {
940
- "voltro.api": e,
941
- "voltro.actionId": l,
942
- "rpc.tag": t
943
- } }));
944
- m = !0;
945
- let h = await S(o, u);
946
- f(h), Mn(l, {
947
- status: "success",
948
- output: h
949
- }), a.current.errorBus.emitSuccess({
950
- source: "action",
951
- tag: t
952
- }), i?.onSuccess?.(h, n);
953
- let g = nr(i?.notify?.success, h, n);
954
- return g !== void 0 && Yn()?.success(g), h;
955
- } catch (e) {
956
- let r = tr(e, p);
957
- if (u(r), Mn(l, {
958
- status: "error",
959
- error: r
960
- }), a.current.errorBus.emit({
961
- source: "action",
962
- tag: t,
963
- error: r,
964
- kind: m ? o(e, "handler") : "client",
965
- outcome: m && o(e, "handler") === "transport" ? "unknown" : m ? "known" : "not-started",
966
- ...p === void 0 ? {} : { traceId: p }
967
- }), s) {
968
- i?.onError?.(r, n);
969
- let e = nr(i?.notify?.error, r, n);
970
- e !== void 0 && Yn()?.error(e);
971
- return;
972
- }
973
- throw r;
974
- } finally {
975
- c(!1);
976
- }
977
- }, [e, t]);
978
- return G(() => ({
979
- run: p,
980
- pending: s,
981
- error: l,
982
- lastResult: d
983
- }), [
984
- p,
985
- s,
986
- l,
987
- d
988
- ]);
989
- }, or = (e, t) => {
990
- let n = globalThis, r = Symbol.for(`@voltro/web/context:${e}`), i = n[r];
991
- if (i) return i;
992
- let a = ke(t);
993
- return n[r] = a, a;
994
- }, sr = ke(void 0), cr = (e) => Ae(sr.Provider, { value: e.messages }, e.children), lr = () => je(sr), ur = Symbol.for("voltro.client.formEngine"), dr = or("formFields", void 0), fr = (e, t) => Object.is(e.value, t.value) && e.error === t.error && e.serverError === t.serverError && e.touched === t.touched && e.blurred === t.blurred && e.dirty === t.dirty && e.required === t.required && e.label === t.label && e.widget === t.widget && e.options === t.options && e.description === t.description && e.asyncStatus === t.asyncStatus && e.a11y.id === t.a11y.id && e.a11y["aria-invalid"] === t.a11y["aria-invalid"] && e.a11y["aria-required"] === t.a11y["aria-required"] && e.a11y["aria-describedby"] === t.a11y["aria-describedby"], pr = (e, t) => {
995
- let n = t, r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a, o = (e) => {
996
- let t = n(e), i = r.get(e);
997
- return i !== void 0 && fr(i, t) ? i : (r.set(e, t), t);
998
- }, s = () => {
999
- for (let [e, t] of i) {
1000
- let n = r.get(e);
1001
- if (o(e) !== n) for (let e of [...t]) e();
1002
- }
1003
- };
1004
- return {
1005
- snapshot: o,
1006
- refresh: (e) => {
1007
- n = e, s();
1008
- },
1009
- subscribe: (t, n) => {
1010
- let o = i.get(t);
1011
- if (o === void 0 && (o = /* @__PURE__ */ new Set(), i.set(t, o)), o.add(n), a === void 0) {
1012
- let t = e.subscribe(s);
1013
- a = () => t.unsubscribe();
1014
- }
1015
- let c = o;
1016
- return () => {
1017
- c.delete(n), c.size === 0 && i.get(t) === c && (i.delete(t), r.delete(t)), i.size === 0 && (a?.(), a = void 0);
1018
- };
1019
- }
1020
- };
1021
- }, mr = or("formBinding", void 0), hr = (e, t) => {
1022
- let n = e;
1023
- for (let e of t.split(".")) {
1024
- if (typeof n != "object" || !n) return;
1025
- n = n[e];
1026
- }
1027
- return n;
1028
- }, gr = (e, t) => {
1029
- let n = `vf-${e}-${t}-`.replace(/[^a-zA-Z0-9_-]/g, "-");
1030
- return (e) => n + `${e}`.replace(/[^a-zA-Z0-9_-]/g, "-");
1031
- }, _r = (e, t) => {
1032
- let n = e.map((e) => e.name), r = Object.keys(t), i;
1033
- if (e.length >= 32 && r.length >= 32 && Object.getPrototypeOf(e) === Array.prototype && Object.getOwnPropertyDescriptor(e, "some") === void 0) {
1034
- let t = /* @__PURE__ */ new Set();
1035
- for (let n = 0; n < e.length; n += 1) {
1036
- let r = Object.getOwnPropertyDescriptor(e, String(n)), a = r !== void 0 && "value" in r && r.value !== null && typeof r.value == "object" ? Object.getOwnPropertyDescriptor(r.value, "name") : void 0;
1037
- if (a === void 0 || !("value" in a) || typeof a.value != "string") break;
1038
- t.add(a.value), n === e.length - 1 && (i = t);
1039
- }
1040
- }
1041
- return [...n, ...r.filter((t) => i === void 0 ? !e.some((e) => e.name === t) : !i.has(t))];
1042
- }, vr = {
1043
- isTouched: !1,
1044
- isBlurred: !1,
1045
- isDirty: !1,
1046
- isPristine: !0,
1047
- isDefaultValue: !0,
1048
- isValidating: !1,
1049
- errorMap: {},
1050
- errorSourceMap: {}
1051
- }, yr = (e) => {
1052
- let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
1053
- for (let r of e) {
1054
- if (t.has(r.name) || t.set(r.name, r), r.widget !== "array" || n.has(r.name)) continue;
1055
- let e = /* @__PURE__ */ new Map();
1056
- for (let t of r.item ?? []) e.has(t.name) || e.set(t.name, t);
1057
- n.set(r.name, e);
1058
- }
1059
- return (e) => {
1060
- let r = t.get(e);
1061
- if (r !== void 0) return r;
1062
- let i = /^(.+?)\.\d+\.(.+)$/.exec(e);
1063
- return i === null ? void 0 : n.get(i[1])?.get(i[2]);
1064
- };
1065
- }, br = (e, t, n) => {
1066
- let r = A(e), i = K(void 0), a = typeof t == "function" ? t(i.current?.state?.values ?? n.defaults ?? {}) : t, o = K(a).current, s = er(e, a), c = n.schema ?? r.descriptors[a]?.input;
1067
- return process.env.NODE_ENV !== "production" && c === void 0 && console.error(`[@voltro/client] useFormBinding('${e}', '${t}'): no input schema. Pass options.schema, or mount the descriptor so its input reaches the client. Rendering no fields; submit skips client-side validation.`), Sr(e, o, n, c, i, s);
1068
- }, xr = (e) => {
1069
- let t = K(void 0);
1070
- return Sr("local", Ne(), {
1071
- ...e,
1072
- onSubmit: async ({ input: t }) => e.onSubmit(await Ve.decodeUnknownPromise(e.schema)(t))
1073
- }, e.schema, t);
1074
- }, Sr = (e, t, n, r, i, a) => {
1075
- let o = G(() => r ? Ee(r) : [], [r]), s = G(() => yr(o), [o]), c = G(() => gr(e, t), [e, t]), l = lr(), u = n.messages ?? l, d = G(() => ({
1076
- ...n.locale === void 0 ? {} : { locale: n.locale },
1077
- ...u === void 0 ? {} : { messages: u }
1078
- }), [n.locale, u]), f = K(n.asyncFields);
1079
- f.current = n.asyncFields;
1080
- let p = K(n);
1081
- p.current = n;
1082
- let m = K(a);
1083
- m.current = a;
1084
- let h = K(d);
1085
- h.current = d;
1086
- let g = K(r);
1087
- g.current = r;
1088
- let [_, v] = q(() => n.flash?.errors ?? {}), [y, b] = q(n.flash?.formError), [x, S] = q(void 0), C = K(void 0), w = K(!1), T = U((e) => {
1089
- let t = g.current;
1090
- if (t === void 0) return [];
1091
- let n = p.current, r = e;
1092
- if (n.toInput !== void 0) try {
1093
- r = n.toInput(e);
1094
- } catch {
1095
- r = e;
1096
- }
1097
- let i = le(t, r, h.current).issues;
1098
- if (n.toInput === void 0) return i;
1099
- let a = n.errorPath ?? {};
1100
- return i.map((t) => {
1101
- let n = a[t.path];
1102
- return n === void 0 ? (hr(e, t.path) !== void 0 || t.path.includes("."), t) : {
1103
- ...t,
1104
- path: n
1105
- };
1106
- });
1107
- }, []), E = U((e) => {
1108
- let t = { ...e ?? {} }, n = g.current;
1109
- if (n !== void 0) for (let e of Ee(n)) (e.widget === "checkbox" || e.widget === "switch") && !(e.name in t) && (t[e.name] = !1);
1110
- return t;
1111
- }, []), D = K(() => Promise.resolve());
1112
- if (i.current === void 0) {
1113
- let e = n.flash, t = e === void 0 ? E(n.defaults) : {
1114
- ...E(n.defaults),
1115
- ...e.values
1116
- };
1117
- i.current = new at({
1118
- onSubmit: ({ value: e }) => D.current(e),
1119
- defaultValues: t,
1120
- validators: { onChange: ({ value: e }) => {
1121
- let t = T(e);
1122
- if (t.length === 0) return;
1123
- let n = {};
1124
- for (let e of t) e.path !== "" && !(e.path in n) && (n[e.path] = Te(e, h.current));
1125
- return { fields: n };
1126
- } }
1127
- });
1128
- }
1129
- let O = i.current, k = O;
1130
- W(() => k.mount(), [k]);
1131
- let A = n.subscribe ?? "all";
1132
- ot(O.store, (e) => A === "all" ? e : `${e.submissionAttempts}|${String(e.isSubmitting)}|${String(e.isDirty)}|${String(e.isTouched)}`);
1133
- let j = O.store.state.values, M = O.store.state, N = G(() => T(j), [
1134
- T,
1135
- j,
1136
- r,
1137
- n.toInput,
1138
- n.errorPath,
1139
- d
1140
- ]), P = G(() => {
1141
- let e = /* @__PURE__ */ new Map();
1142
- for (let t of N) e.has(t.path) || e.set(t.path, t);
1143
- return e;
1144
- }, [N]), F = K({
1145
- values: j,
1146
- index: P
1147
- });
1148
- F.current = {
1149
- values: j,
1150
- index: P
1151
- };
1152
- let I = U((e) => {
1153
- let t = O.store.state.values;
1154
- if (F.current.values !== t) {
1155
- let e = /* @__PURE__ */ new Map();
1156
- for (let n of T(t)) e.has(n.path) || e.set(n.path, n);
1157
- F.current = {
1158
- values: t,
1159
- index: e
1160
- };
1161
- }
1162
- return F.current.index.get(e);
1163
- }, [O, T]), L = n.isLoading === !0, R = n.validate, ee = R?.onChange ?? "afterTouched", te = R?.onBlur ?? !0, z = U((e) => {
1164
- if (L) return !1;
1165
- if (O.store.state.submissionAttempts > 0 || ee === "always") return !0;
1166
- if (ee === "never") return !1;
1167
- let t = k.getFieldMeta(e);
1168
- return t === void 0 ? !1 : te ? t.isBlurred === !0 : t.isTouched === !0;
1169
- }, [
1170
- O,
1171
- k,
1172
- L,
1173
- ee,
1174
- te
1175
- ]), B = U((e) => {
1176
- let t = _[e];
1177
- if (t !== void 0) return t;
1178
- let n = f.current?.[e];
1179
- if (n !== void 0 && n.status === "invalid") return n.message ?? Te({
1180
- id: "validation.invalid",
1181
- fallback: "Invalid value"
1182
- }, h.current);
1183
- if (!z(e)) return;
1184
- let r = I(e);
1185
- return r === void 0 ? void 0 : Te(r, h.current);
1186
- }, [
1187
- _,
1188
- z,
1189
- I
1190
- ]), V = G(() => {
1191
- let e = {}, t = /* @__PURE__ */ new Set();
1192
- for (let e of N) e.path !== "" && t.add(e.path);
1193
- for (let e of Object.keys(_)) t.add(e);
1194
- for (let [e, n] of Object.entries(f.current ?? {})) n.status === "invalid" && t.add(e);
1195
- for (let n of t) {
1196
- let t = B(n);
1197
- t !== void 0 && (e[n] = t);
1198
- }
1199
- return e;
1200
- }, [
1201
- N,
1202
- _,
1203
- B,
1204
- M.fieldMetaBase,
1205
- M.submissionAttempts,
1206
- n.asyncFields
1207
- ]), ne = U((e) => {
1208
- v((t) => {
1209
- if (!(e in t)) return t;
1210
- let n = { ...t };
1211
- return delete n[e], n;
1212
- });
1213
- }, []), H = U((e) => {
1214
- let t = s(e), n = k.getFieldMeta(e), r = B(e), i = c(e), a = f.current?.[e], o = [r === void 0 ? void 0 : `${i}-error`, t?.description === void 0 ? void 0 : `${i}-help`].filter((e) => e !== void 0);
1215
- return {
1216
- value: k.getFieldValue(e),
1217
- setValue: (t) => {
1218
- ne(e), !Object.is(k.getFieldValue(e), t) && k.setFieldValue(e, t);
1219
- },
1220
- onBlur: () => {
1221
- k.setFieldMeta(e, (e) => ({
1222
- ...vr,
1223
- ...e ?? {},
1224
- isTouched: !0,
1225
- isBlurred: !0
1226
- }));
1227
- },
1228
- error: r,
1229
- serverError: _[e],
1230
- touched: n?.isTouched === !0,
1231
- blurred: n?.isBlurred === !0,
1232
- dirty: n?.isDirty === !0,
1233
- required: t?.required === !0,
1234
- label: t?.label ?? e,
1235
- widget: t?.widget ?? "text",
1236
- options: t?.options,
1237
- description: t?.description,
1238
- asyncStatus: a?.status ?? "idle",
1239
- a11y: {
1240
- id: i,
1241
- "aria-invalid": r !== void 0 || void 0,
1242
- "aria-required": t?.required === !0 || void 0,
1243
- "aria-describedby": o.length > 0 ? o.join(" ") : void 0
1244
- }
1245
- };
1246
- }, [
1247
- c,
1248
- ne,
1249
- k,
1250
- s,
1251
- _,
1252
- B
1253
- ]), re = K(void 0);
1254
- re.current === void 0 && (re.current = pr(O.store, H));
1255
- let ie = re.current;
1256
- Pe(() => {
1257
- ie.refresh(H);
1258
- });
1259
- let ae = U((e) => ({
1260
- items: k.getFieldValue(e) ?? [],
1261
- push: (t) => {
1262
- k.pushFieldValue(e, t);
1263
- },
1264
- insert: (t, n) => {
1265
- k.insertFieldValue(e, t, n);
1266
- },
1267
- remove: (t) => {
1268
- k.removeFieldValue(e, t);
1269
- },
1270
- move: (t, n) => {
1271
- k.moveFieldValues(e, t, n);
1272
- },
1273
- swap: (t, n) => {
1274
- k.swapFieldValues(e, t, n);
1275
- },
1276
- field: (t, n) => H(`${e}.${t}.${n}`)
1277
- }), [k, H]), oe = U((e) => o.filter((t) => t.section === e), [o]), se = U((e, t) => {
1278
- ne(e), !Object.is(k.getFieldValue(e), t) && k.setFieldValue(e, t);
1279
- }, [ne, k]), ce = U((e) => {
1280
- for (let [t, n] of Object.entries(e)) k.setFieldValue(t, n);
1281
- }, [k]), ue = U((e) => {
1282
- v({}), b(void 0), S(void 0), C.current = void 0, w.current = !1, e === void 0 ? k.reset() : k.reset(E(e));
1283
- }, [k, E]), de = n.asyncTimeoutMs ?? 5e3, fe = U(async () => {
1284
- let e = Date.now();
1285
- for (;;) {
1286
- let t = f.current;
1287
- if (t === void 0) return;
1288
- let n = Object.entries(t), r;
1289
- for (let e of n) e[1].status === "checking" && (r ??= []).push(e);
1290
- if (r === void 0) {
1291
- let e = 0;
1292
- for (let t of n) t[1].status === "invalid" && (n[e++] = t);
1293
- n.length = e;
1294
- let t = n;
1295
- if (t.length === 0) return;
1296
- let r = Object.fromEntries(t);
1297
- for (let [e, n] of t) r[e] = n.message ?? Te({
1298
- id: "validation.invalid",
1299
- fallback: "Invalid value"
1300
- }, h.current);
1301
- return r;
1302
- }
1303
- if (Date.now() - e > de) {
1304
- let e = Object.fromEntries(r);
1305
- for (let [t] of r) e[t] = Te({
1306
- id: "validation.checking",
1307
- fallback: "Still checking…"
1308
- }, h.current);
1309
- return e;
1310
- }
1311
- await new Promise((e) => setTimeout(e, 50));
1312
- }
1313
- }, [de]), pe = U(() => {
1314
- let e = globalThis.document;
1315
- if (e?.getElementById === void 0) return;
1316
- let t = _r(o, _);
1317
- for (let n of t) if (B(n) !== void 0) {
1318
- e.getElementById(c(n))?.focus?.();
1319
- return;
1320
- }
1321
- }, [
1322
- c,
1323
- o,
1324
- _,
1325
- B
1326
- ]), me = K(pe);
1327
- me.current = pe;
1328
- let he = U(async () => {
1329
- b(void 0), v({}), S(void 0), C.current = void 0, w.current = !1;
1330
- let e, t = !1;
1331
- if (await k.handleSubmit().catch((n) => {
1332
- t = !0, e = n;
1333
- }), t) throw e;
1334
- return w.current || queueMicrotask(() => {
1335
- me.current();
1336
- }), C.current;
1337
- }, [k]);
1338
- D.current = (async (e) => {
1339
- let t = p.current, n = e, r = n;
1340
- if (t.toInput !== void 0) try {
1341
- r = t.toInput(n);
1342
- } catch (e) {
1343
- b(e instanceof Error ? e.message : String(e));
1344
- return;
1345
- }
1346
- if (T(n).length > 0) {
1347
- queueMicrotask(() => {
1348
- me.current();
1349
- });
1350
- return;
1351
- }
1352
- let i = g.current;
1353
- if (i !== void 0) {
1354
- let e = Oe(i, r);
1355
- e.dropped.length > 0 && process.env.NODE_ENV !== "production" && console.warn(`[@voltro/client] useFormBinding: dropped ${e.dropped.length} value(s) the mutation's input does not declare (${e.dropped.join(", ")}). The server refuses undeclared fields, so they are not sent. Map them with \`toInput\` if they belong in the write; ignore this if they are form-only state.`), r = e.input;
1356
- }
1357
- let a = await fe();
1358
- if (a !== void 0) {
1359
- v((e) => ({
1360
- ...e,
1361
- ...a
1362
- })), queueMicrotask(() => {
1363
- me.current();
1364
- });
1365
- return;
1366
- }
1367
- let o = (e) => {
1368
- let t = m.current;
1369
- return t === void 0 ? Promise.reject(/* @__PURE__ */ Error("A schema form submits through its onSubmit callback")) : t.mutate(e);
1370
- };
1371
- try {
1372
- let e = t.onSubmit === void 0 ? await o(r) : await t.onSubmit({
1373
- input: r,
1374
- values: n,
1375
- mutate: o
1376
- });
1377
- C.current = e, w.current = !0, t.onSuccess?.(e);
1378
- } catch (e) {
1379
- let t = Ze(e);
1380
- if (t.length === 0) {
1381
- S(e), p.current.onError?.(e);
1382
- return;
1383
- }
1384
- let n = {};
1385
- for (let e of t) e.field in n || (n[e.field] = Te({
1386
- id: e.message,
1387
- ...e.params === void 0 ? {} : { params: e.params },
1388
- fallback: e.message
1389
- }, h.current));
1390
- v((e) => ({
1391
- ...e,
1392
- ...n
1393
- })), queueMicrotask(() => {
1394
- me.current();
1395
- });
1396
- }
1397
- });
1398
- let ge = N.length === 0, _e = Object.values(f.current ?? {}).some((e) => e.status === "checking"), ve = x ?? a?.error, ye = ve !== void 0 && Ze(ve).length > 0 ? void 0 : ve, be = Object.keys(V).length, xe = (() => {
1399
- for (let e of o) if (V[e.name] !== void 0) return e.name;
1400
- let e = Object.keys(V);
1401
- return e.length > 0 ? e[0] : void 0;
1402
- })(), Se = {
1403
- isDirty: !L && M.isDirty,
1404
- isPristine: M.isPristine,
1405
- isTouched: M.isTouched,
1406
- isValid: ge,
1407
- isValidating: _e,
1408
- canSubmit: ge && !_e && !M.isSubmitting && !L,
1409
- isSubmitting: M.isSubmitting,
1410
- isSubmitted: M.isSubmitted,
1411
- isSubmitSuccessful: M.isSubmitSuccessful && w.current,
1412
- submissionAttempts: M.submissionAttempts,
1413
- errorCount: be,
1414
- firstInvalidPath: xe,
1415
- pending: a?.pending ?? M.isSubmitting,
1416
- isLoading: L,
1417
- submitError: ye,
1418
- data: a?.data ?? C.current
1419
- }, Ce = {
1420
- fields: o,
1421
- values: j,
1422
- errors: V,
1423
- issues: N,
1424
- isValid: ge,
1425
- pending: a?.pending ?? M.isSubmitting,
1426
- submitError: ye,
1427
- formError: y,
1428
- data: a?.data ?? C.current,
1429
- setValue: se,
1430
- setValues: ce,
1431
- reset: ue,
1432
- submit: he,
1433
- field: H,
1434
- array: ae,
1435
- section: oe,
1436
- state: Se,
1437
- focusFirstInvalid: pe
1438
- };
1439
- return Object.defineProperty(Ce, ur, {
1440
- value: {
1441
- store: O.store,
1442
- field: H,
1443
- channel: ie
1444
- },
1445
- enumerable: !1
1446
- }), Ce;
1447
- }, Cr = (e) => {
1448
- let t = e.binding[ur];
1449
- return Ae(mr.Provider, { value: e.binding }, Ae(dr.Provider, { value: t?.channel }, e.children));
1450
- }, wr = () => je(mr);
1451
- function Tr(e, t) {
1452
- let n = je(dr), r = typeof e == "string" ? void 0 : e, i = typeof e == "string" ? e : t, a = r?.[ur], o = r === void 0 ? n : a?.channel;
1453
- if (o === void 0) throw Error(r === void 0 ? "useFormField(path) found no form binding — mount <FormBindingProvider binding={form}> above this field, or call useFormField(form, path)." : "useFormField: not a useFormBinding result");
1454
- return J(U((e) => o.subscribe(i, e), [o, i]), U(() => o.snapshot(i), [o, i]), U(() => o.snapshot(i), [o, i]));
1455
- }
1456
- //#endregion
1457
- //#region src/connectionPrerequisite.ts
1458
- var Er = "voltro:connection-setup-superseded", Dr = (e) => e.reason === "voltro:connection-setup-superseded" ? "superseded" : "inactive", Q = class extends Error {
1459
- reason;
1460
- _tag = "ConnectionPrerequisiteInvalidated";
1461
- constructor(e) {
1462
- super(`Voltro connection prerequisite: ${e}`), this.reason = e, T(this, e === "connection-unavailable" || e === "connection-changed" ? "transport" : "client");
1463
- }
1464
- }, Or = class {
1465
- #e;
1466
- #t;
1467
- #n = /* @__PURE__ */ new WeakMap();
1468
- #r = /* @__PURE__ */ new WeakSet();
1469
- constructor(e, t) {
1470
- if (!Number.isFinite(t) || t <= 0 || t > 6e4) throw RangeError("Connection prerequisite timeout must be between 0 and 60000 ms");
1471
- this.#e = e, this.#t = t;
1472
- }
1473
- prepare(e, t) {
1474
- let n = z(e)?.getSnapshot();
1475
- if (this.#e.aborted) return Promise.reject(new Q(Dr(this.#e)));
1476
- if (n === void 0) return Promise.reject(new Q("connection-unavailable"));
1477
- let r = this.#n.get(n);
1478
- if (r !== void 0) return r.then((t) => (this.assertCurrent(e, t), t));
1479
- let i = this.#a(e, n, t).pipe(Y.timeoutOrElse({
1480
- duration: this.#t,
1481
- orElse: () => Y.fail(new Q("timeout"))
1482
- })), a = S(e, i).then((t) => {
1483
- let r = Object.freeze({
1484
- lease: n,
1485
- output: t
1486
- });
1487
- return this.#r.add(r), this.assertCurrent(e, r), r;
1488
- });
1489
- return this.#n.set(n, a), a.catch(() => {
1490
- this.#n.get(n) === a && this.#n.delete(n);
1491
- }), a;
1492
- }
1493
- assertCurrent(e, t) {
1494
- if (!this.#r.has(t)) throw new Q(Dr(this.#e));
1495
- this.#i(e, t.lease);
1496
- }
1497
- #i(e, t) {
1498
- if (this.#e.aborted) throw new Q(Dr(this.#e));
1499
- if (t.signal.aborted || z(e)?.getSnapshot() !== t) throw new Q("connection-changed");
1500
- }
1501
- run(e, t, n) {
1502
- let r = Y.try({
1503
- try: () => this.assertCurrent(e, t),
1504
- catch: (e) => e
1505
- }).pipe(Y.andThen(n));
1506
- return S(e, this.#a(e, t.lease, r));
1507
- }
1508
- #a(e, t, n) {
1509
- let r = Y.try({
1510
- try: () => this.#i(e, t),
1511
- catch: (e) => e
1512
- }), i = Y.callback((e) => {
1513
- let n = () => e(Y.fail(new Q(this.#e.aborted ? Dr(this.#e) : "connection-changed")));
1514
- return this.#e.addEventListener("abort", n, { once: !0 }), t.signal.addEventListener("abort", n, { once: !0 }), (this.#e.aborted || t.signal.aborted) && n(), Y.sync(() => {
1515
- this.#e.removeEventListener("abort", n), t.signal.removeEventListener("abort", n);
1516
- });
1517
- });
1518
- return r.pipe(Y.andThen(n), Y.tap(() => r), Y.raceFirst(i));
1519
- }
1520
- }, kr = class {
1521
- #e;
1522
- #t;
1523
- #n;
1524
- #r = /* @__PURE__ */ new Set();
1525
- #i;
1526
- #a = {
1527
- status: "idle",
1528
- data: void 0,
1529
- error: void 0
1530
- };
1531
- #o = 0;
1532
- #s;
1533
- handle;
1534
- constructor(e, t, n) {
1535
- this.#e = e, this.#t = t, this.#n = n, this.handle = Ln(e, { capture: () => this.#f() });
1536
- }
1537
- getSnapshot = () => this.#a;
1538
- subscribe = (e) => (this.#r.add(e), () => {
1539
- this.#r.delete(e);
1540
- });
1541
- clear = (e = !1) => {
1542
- let t = this.#i;
1543
- this.#i = void 0, this.#s = void 0, t?.detachSubject?.(), t?.controller.abort(e ? Er : void 0), this.#h({
1544
- status: "idle",
1545
- data: void 0,
1546
- error: void 0
1547
- });
1548
- };
1549
- async activate(e, t) {
1550
- this.clear(!0);
1551
- let n = new AbortController(), r = {
1552
- input: e,
1553
- key: H(),
1554
- controller: n,
1555
- subject: void 0,
1556
- detachSubject: void 0,
1557
- prerequisite: new Or(n.signal, this.#c(this.#n()).options.replayWindowMs),
1558
- established: !1
1559
- };
1560
- this.#i = r, this.#h({
1561
- status: "pending",
1562
- data: void 0,
1563
- error: void 0
1564
- });
1565
- try {
1566
- let e = await t(), n = await this.#p(r, e.runtime, e.client);
1567
- return this.#l(r), r.prerequisite.assertCurrent(e.runtime, n), r.established = !0, n.output;
1568
- } catch (e) {
1569
- throw this.#i === r && (this.clear(), this.#h({
1570
- status: "error",
1571
- data: void 0,
1572
- error: e
1573
- })), e;
1574
- }
1575
- }
1576
- watch(e) {
1577
- let t = z(e.runtime), n = () => {
1578
- let n = this.#i;
1579
- if (n === void 0 || !n.established || this.#n().runtime !== e.runtime) return;
1580
- if (n.subject !== this.#c(e).subjectSignal) {
1581
- this.clear();
1582
- return;
1583
- }
1584
- let r = t?.getSnapshot();
1585
- (r === void 0 || r !== this.#s || this.#a.status !== "ready") && (this.#s = void 0, this.#h({
1586
- status: "pending",
1587
- data: void 0,
1588
- error: void 0
1589
- }), r !== void 0 && this.#p(n, e.runtime, e.client).catch(() => {}));
1590
- };
1591
- return n(), t?.subscribe(n) ?? (() => {});
1592
- }
1593
- #c(e) {
1594
- return e.recovery ?? c(e.errorBus, this.#e);
1595
- }
1596
- #l(e) {
1597
- if (this.#i !== e || e.controller.signal.aborted) throw new Q(Dr(e.controller.signal));
1598
- }
1599
- #u(e, t, n) {
1600
- this.#l(e);
1601
- let r = this.#n();
1602
- if (e.subject !== void 0 && e.subject !== this.#c(r).subjectSignal) throw new Q("inactive");
1603
- if (r.runtime !== t || r.client !== n) throw new Q("connection-changed");
1604
- return r;
1605
- }
1606
- #d(e, t) {
1607
- if (e.subject !== void 0) return;
1608
- let n = this.#c(t).subjectSignal;
1609
- e.subject = n;
1610
- let r = () => {
1611
- this.#i === e && this.clear();
1612
- };
1613
- n.addEventListener("abort", r, { once: !0 }), e.detachSubject = () => n.removeEventListener("abort", r), n.aborted && r();
1614
- }
1615
- #f() {
1616
- let e = this.#i;
1617
- if (e === void 0) throw new Q("inactive");
1618
- return { prepare: async (t, n) => {
1619
- let r = await this.#p(e, t, n);
1620
- return { run: (i) => e.prerequisite.run(t, r, Y.try({
1621
- try: () => this.#u(e, t, n),
1622
- catch: (e) => e
1623
- }).pipe(Y.andThen(i))) };
1624
- } };
1625
- }
1626
- async #p(e, t, n) {
1627
- let r = this.#u(e, t, n), i = r.descriptors[this.#t];
1628
- if (i?.kind !== "mutation" || i.idempotencyScope !== "connection") throw Error(`Voltro: useConnectionSetup("${this.#t}") requires a mutation declaring idempotencyScope: 'connection'`);
1629
- this.#d(e, r), this.#l(e);
1630
- let a = z(t);
1631
- if (a === void 0) throw new Q("connection-unavailable");
1632
- if (a.getSnapshot() === void 0) {
1633
- let n = Y.callback((t) => {
1634
- let n = () => {
1635
- let n = a.getSnapshot();
1636
- e.controller.signal.aborted ? t(Y.fail(new Q(Dr(e.controller.signal)))) : n !== void 0 && t(Y.succeed(n));
1637
- }, r = a.subscribe(n);
1638
- return e.controller.signal.addEventListener("abort", n, { once: !0 }), n(), Y.sync(() => {
1639
- r(), e.controller.signal.removeEventListener("abort", n);
1640
- });
1641
- }).pipe(Y.timeoutOrElse({
1642
- duration: this.#c(r).options.replayWindowMs,
1643
- orElse: () => Y.fail(new Q("timeout"))
1644
- }));
1645
- await S(t, n);
1646
- }
1647
- this.#u(e, t, n);
1648
- let o = a.getSnapshot();
1649
- try {
1650
- let i = await e.prerequisite.prepare(t, this.#m(e, r));
1651
- return this.#u(e, t, n), this.#s = i.lease, this.#h({
1652
- status: "ready",
1653
- data: i.output,
1654
- error: void 0
1655
- }), this.#u(e, t, n), e.prerequisite.assertCurrent(t, i), i;
1656
- } catch (n) {
1657
- throw this.#i === e && this.#n().runtime === t && a.getSnapshot() === o && this.#h({
1658
- status: "error",
1659
- data: void 0,
1660
- error: n
1661
- }), n;
1662
- }
1663
- }
1664
- #m(e, t) {
1665
- return Y.suspend(() => {
1666
- let n = `setup_${e.key}_${++this.#o}`;
1667
- return jn({
1668
- id: n,
1669
- apiName: this.#e,
1670
- tag: this.#t,
1671
- input: e.input
1672
- }), Y.suspend(() => {
1673
- this.#u(e, t.runtime, t.client);
1674
- let n = v(t.client, this.#t);
1675
- return B(n(e.input), e.key);
1676
- }).pipe(Y.withSpan(`client.connectionSetup.${this.#t}`)).pipe(Y.onExit((e) => Y.sync(() => {
1677
- if (Le.isSuccess(e)) Mn(n, {
1678
- status: "success",
1679
- output: e.value
1680
- }), t.errorBus.emitSuccess({
1681
- source: "mutation",
1682
- tag: this.#t
1683
- });
1684
- else {
1685
- let r = i(e.cause);
1686
- if (Mn(n, {
1687
- status: "error",
1688
- error: r
1689
- }), !Fe.hasInterruptsOnly(e.cause)) {
1690
- let e = o(r, "handler");
1691
- t.errorBus.emit({
1692
- source: "mutation",
1693
- tag: this.#t,
1694
- error: r,
1695
- kind: e,
1696
- outcome: e === "transport" ? "unknown" : "known"
1697
- });
1698
- }
1699
- }
1700
- })));
1701
- });
1702
- }
1703
- #h(e) {
1704
- if (this.#a.status !== e.status || this.#a.data !== e.data || this.#a.error !== e.error) {
1705
- this.#a = e;
1706
- for (let e of this.#r) try {
1707
- e();
1708
- } catch {}
1709
- }
1710
- }
1711
- }, Ar = (e, t) => {
1712
- let n = A(e), r = K(n);
1713
- r.current = n;
1714
- let i = G(() => new kr(e, t, () => r.current), [e, t]), a = U((n) => i.activate(n, () => P(r, e, t)), [
1715
- i,
1716
- e,
1717
- t
1718
- ]), o = J(i.subscribe, i.getSnapshot, i.getSnapshot);
1719
- return W(() => i.watch(r.current), [
1720
- i,
1721
- n.runtime,
1722
- n.client,
1723
- n.recovery
1724
- ]), W(() => () => i.clear(), [i]), {
1725
- ...o,
1726
- handle: i.handle,
1727
- activate: a,
1728
- clear: i.clear,
1729
- ready: o.status === "ready"
1730
- };
1731
- }, jr = Z, Mr = (e) => ({
1732
- useSubscription: (t, n, r) => jr(e, t, n, r),
1733
- useMutation: (t) => er(e, t),
1734
- useConnectionSetup: (t) => Ar(e, t),
1735
- useAction: (t) => ar(e, t),
1736
- useFormBinding: (t, n) => br(e, t, n ?? {})
1737
- }), Nr = () => ({ seeds: [] }), Pr = null, Fr = (e) => {
1738
- Pr = e;
1739
- }, Ir = /* @__PURE__ */ new Map(), Lr = (e, t) => `${e}\u0000${t}`, Rr = (e, t, n, r) => {
1740
- let i = Pr?.() ?? null;
1741
- if (i === null) throw Error(`seedPreloadedSubscription('${e}', '${t}') was called outside a server render. Preload seeds exist to put a subscription's first value into the SSR hydration payload; on the client the live subscription already provides it. (If this IS server code, the render did not install a seed bag — that is a framework bug.)`);
1742
- i.seeds.push({
1743
- api: e,
1744
- key: f([t, n]),
1745
- value: r
1746
- });
1747
- }, zr = (e, t, n) => {
1748
- let r = Pr?.() ?? null;
1749
- r !== null && r.seeds.push({
1750
- api: e,
1751
- key: f([t, n]),
1752
- value: void 0,
1753
- failed: !0
1754
- });
1755
- }, Br = (e) => {
1756
- if (e !== void 0) for (let t of e) Ir.set(Lr(t.api, t.key), {
1757
- value: t.value,
1758
- failed: t.failed === !0
1759
- });
1760
- }, Vr = (e, t, n) => {
1761
- let r = f([t, n]), i = Pr?.() ?? null;
1762
- if (i !== null) {
1763
- for (let t of i.seeds) if (t.api === e && t.key === r) return t.failed === !0 ? void 0 : t.value;
1764
- return;
1765
- }
1766
- let a = Ir.get(Lr(e, r));
1767
- return a === void 0 || a.failed ? void 0 : a.value;
1768
- }, Hr = (e, t, n) => {
1769
- let r = f([t, n]), i = Pr?.() ?? null;
1770
- if (i !== null) {
1771
- for (let t of i.seeds) if (t.api === e && t.key === r) return t.failed === !0 ? "failed" : "seeded";
1772
- return "absent";
1773
- }
1774
- let a = Ir.get(Lr(e, r));
1775
- return a === void 0 ? "absent" : a.failed ? "failed" : "seeded";
1776
- }, Ur = () => {
1777
- Ir.clear();
1778
- };
1779
- //#endregion
1780
- //#region src/usePreloadedSubscription.ts
1781
- function Wr(e, t, n = {}, r = {}) {
1782
- let i = Vr(e, t, n), a = Z(e, t, n, i === void 0 ? r : {
1783
- ...r,
1784
- initialSnapshot: i
1785
- });
1786
- return Hr(e, t, n) === "failed" ? {
1787
- ...a,
1788
- preloadFailed: !0
1789
- } : a;
1790
- }
1791
- //#endregion
1792
- //#region src/useEvent.ts
1793
- var Gr = {
1794
- status: "idle",
1795
- missed: 0,
1796
- lastMiss: void 0
1797
- }, Kr = class {
1798
- _tag = "EventStreamClosed";
1799
- };
1800
- function qr(e, t, n, r = {}) {
1801
- let { skip: i = !1, apiName: o = "app", onMissed: s } = r, c = A(o), { runtime: l, client: u } = c, [d, f] = q(Gr), p = K(n);
1802
- p.current = n;
1803
- let m = K(s);
1804
- m.current = s;
1805
- let h = K(u);
1806
- h.current = u;
1807
- let g = K(l);
1808
- g.current = l;
1809
- let _ = K(/* @__PURE__ */ new Map()), y = t === null ? null : JSON.stringify(Object.entries(t).sort(([e], [t]) => e < t ? -1 : 1)), b = K(t);
1810
- b.current = t;
1811
- let x = K(null);
1812
- x.current !== y && (x.current = y, _.current = /* @__PURE__ */ new Map());
1813
- let S = U((t, n) => {
1814
- t <= 0 || (a(o, "event.gap", {
1815
- tag: e.name,
1816
- missed: t,
1817
- reason: n
1818
- }), f((e) => ({
1819
- ...e,
1820
- missed: e.missed + t,
1821
- lastMiss: {
1822
- count: t,
1823
- reason: n
1824
- }
1825
- })), m.current?.({
1826
- count: t,
1827
- reason: n
1828
- }));
1829
- }, [o, e.name]), C = !i && y !== null && !F(c);
1830
- return W(() => {
1831
- if (!C) {
1832
- f(Gr);
1833
- return;
1834
- }
1835
- f((e) => ({
1836
- ...e,
1837
- status: "connecting"
1838
- }));
1839
- let t = 0, n = Y.sync(() => {
1840
- let t = [];
1841
- for (let [e, n] of _.current) t.push({
1842
- origin: e,
1843
- n
1844
- });
1845
- return v(h.current, e.name)({
1846
- key: b.current,
1847
- ...t.length > 0 ? { resume: t } : {}
1848
- });
1849
- }), r = X.unwrap(n).pipe(X.tap(() => Y.sync(() => {
1850
- t = 0;
1851
- })), X.concat(X.fail(new Kr())), X.retry(Be.min([Be.exponential("250 millis", 2), Be.spaced("30 seconds")]).pipe(Be.jittered, Be.tap(() => Y.sync(() => {
1852
- t += 1, f((e) => ({
1853
- ...e,
1854
- status: "connecting"
1855
- }));
1856
- }))))), i = g.current.runFork(X.runForEach(r, (e) => Y.sync(() => {
1857
- if (e._tag === "attached") {
1858
- f((e) => ({
1859
- ...e,
1860
- status: "live"
1861
- }));
1862
- return;
1863
- }
1864
- if (e._tag === "gap") {
1865
- S(e.missed, e.reason);
1866
- return;
1867
- }
1868
- _.current.set(e.origin, Math.max(_.current.get(e.origin) ?? 0, e.n)), p.current(e.payload);
1869
- })));
1870
- return () => {
1871
- g.current.runFork(Y.forkDetach(Re.interrupt(i)));
1872
- };
1873
- }, [
1874
- C,
1875
- y,
1876
- e.name,
1877
- S
1878
- ]), C ? d : Gr;
1879
- }
1880
- //#endregion
1881
- //#region src/sequence.ts
1882
- var Jr = () => {
1883
- let e = (t) => ({
1884
- steps: t,
1885
- step: ((n, r, i) => e([...t, {
1886
- name: n,
1887
- run: r,
1888
- undo: i?.undo,
1889
- covers: i?.covers ?? [],
1890
- when: i?.when
1891
- }]))
1892
- });
1893
- return e([]);
1894
- }, Yr = async (e, t = {}) => {
1895
- let n = {}, r = [];
1896
- for (let i of e.steps) {
1897
- if (i.when !== void 0 && !i.when(n)) {
1898
- n[i.name] = void 0;
1899
- continue;
1900
- }
1901
- try {
1902
- let e = await i.run(n);
1903
- n[i.name] = e, r.push({
1904
- step: i,
1905
- result: e
1906
- });
1907
- } catch (e) {
1908
- let a = [], o = [], s = [], c = [];
1909
- if (t.compensate !== !1) {
1910
- let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
1911
- for (let i = r.length - 1; i >= 0; i--) {
1912
- let l = r[i], u = l.step.name;
1913
- if (t.has(u)) {
1914
- c.push({
1915
- step: u,
1916
- coveredBy: t.get(u)
1917
- });
1918
- continue;
1919
- }
1920
- if (e.has(u)) {
1921
- s.push(u);
1922
- continue;
1923
- }
1924
- if (l.step.undo !== void 0) try {
1925
- await l.step.undo(l.result, n), a.push(u);
1926
- for (let t of l.step.covers) e.set(t, u);
1927
- } catch (e) {
1928
- o.push({
1929
- step: u,
1930
- error: e
1931
- });
1932
- for (let e of l.step.covers) t.set(e, u);
1933
- }
1934
- }
1935
- }
1936
- let l = {
1937
- failedStep: i.name,
1938
- compensated: a,
1939
- compensationFailures: o,
1940
- compensationCovered: s,
1941
- compensationUncertain: c
1942
- };
1943
- return t.onError?.(e, l), {
1944
- ok: !1,
1945
- error: e,
1946
- ...l
1947
- };
1948
- }
1949
- }
1950
- return {
1951
- ok: !0,
1952
- data: n
1953
- };
1954
- }, Xr = (e = {}) => {
1955
- let [t, n] = q(!1), [r, i] = q(void 0), [a, o] = q(void 0), s = K(e);
1956
- return s.current = e, {
1957
- run: U(async (e, t = {}) => {
1958
- n(!0), i(void 0), o(void 0);
1959
- try {
1960
- let n = await Yr(e, {
1961
- ...s.current,
1962
- ...t
1963
- });
1964
- return n.ok || (i(n.error), o(n.failedStep)), n;
1965
- } finally {
1966
- n(!1);
1967
- }
1968
- }, []),
1969
- pending: t,
1970
- error: r,
1971
- failedStep: a
1972
- };
1973
- }, Zr = (e) => {
1974
- let t = 1;
1975
- for (; t < e;) t *= 2;
1976
- let n = new Float64Array(t * 2);
1977
- return (r, i, a = e) => {
1978
- if (r >= t) {
1979
- let e = t;
1980
- for (; t <= r;) t *= 2;
1981
- let i = new Float64Array(t * 2);
1982
- i.set(n.subarray(e), t);
1983
- for (let e = t - 1; e > 0; e--) i[e] = i[e * 2] + i[e * 2 + 1];
1984
- n = i;
1985
- }
1986
- let o = t + r;
1987
- for (n[o] = i; o > 1;) o = Math.floor(o / 2), n[o] = n[o * 2] + n[o * 2 + 1];
1988
- return n[1] / a;
1989
- };
1990
- }, Qr = "@voltro/plugin-storage", $ = (e) => nt(Qr, e), $r = (e, t, n, r) => new Promise((i, a) => {
1991
- let o = new XMLHttpRequest();
1992
- if (o.open("PUT", e), o.upload.onprogress = (e) => {
1993
- e.lengthComputable && n(e.loaded / e.total);
1994
- }, o.onload = () => {
1995
- if (o.status >= 200 && o.status < 300) {
1996
- let e = o.getResponseHeader("ETag") ?? o.getResponseHeader("etag");
1997
- e ? i(e) : a(/* @__PURE__ */ Error("multipart part: response carried no ETag (the bucket CORS must expose the ETag header)"));
1998
- } else a(Error(`multipart part failed (${o.status}): ${o.responseText || o.statusText}`.trim()));
1999
- }, o.onerror = () => a(/* @__PURE__ */ Error("multipart part: network error")), o.onabort = () => a(new DOMException("upload aborted", "AbortError")), r.aborted) {
2000
- o.abort();
2001
- return;
2002
- }
2003
- r.addEventListener("abort", () => o.abort(), { once: !0 }), o.send(t);
2004
- }), ei = (e, t, n, r, i, a) => new Promise((o, s) => {
2005
- let c = new XMLHttpRequest();
2006
- if (c.open("POST", e), c.setRequestHeader("content-type", t), c.upload.onprogress = (e) => {
2007
- e.lengthComputable && r(e.loaded / e.total);
2008
- }, c.onload = () => {
2009
- if (c.status >= 200 && c.status < 300) {
2010
- if (!a) return o(null);
2011
- try {
2012
- o(JSON.parse(c.responseText));
2013
- } catch {
2014
- s(/* @__PURE__ */ Error("resumable upload: malformed final response"));
2015
- }
2016
- } else s(Error(`resumable chunk failed (${c.status}): ${c.responseText || c.statusText}`.trim()));
2017
- }, c.onerror = () => s(/* @__PURE__ */ Error("resumable chunk: network error")), c.onabort = () => s(new DOMException("upload aborted", "AbortError")), i.aborted) {
2018
- c.abort();
2019
- return;
2020
- }
2021
- i.addEventListener("abort", () => c.abort(), { once: !0 }), c.send(n);
2022
- }), ti = (e, t, n, r, i) => new Promise((a, o) => {
2023
- let s = new XMLHttpRequest();
2024
- if (s.open("PUT", e), s.setRequestHeader("content-type", t), s.upload.onprogress = (e) => {
2025
- e.lengthComputable && r(e.loaded / e.total);
2026
- }, s.onload = () => {
2027
- s.status >= 200 && s.status < 300 ? a() : o(Error(`direct upload failed (${s.status}): ${s.responseText || s.statusText}`.trim()));
2028
- }, s.onerror = () => o(/* @__PURE__ */ Error("direct upload: network error")), s.onabort = () => o(new DOMException("upload aborted", "AbortError")), i.aborted) {
2029
- s.abort();
2030
- return;
2031
- }
2032
- i.addEventListener("abort", () => s.abort(), { once: !0 }), s.send(n);
2033
- }), ni = (e, t, n, r, i) => new Promise((a, o) => {
2034
- let s = new XMLHttpRequest();
2035
- if (s.open("POST", e), s.setRequestHeader("content-type", t), s.upload.onprogress = (e) => {
2036
- e.lengthComputable && r(e.loaded / e.total);
2037
- }, s.onload = () => {
2038
- if (s.status >= 200 && s.status < 300) try {
2039
- a(JSON.parse(s.responseText));
2040
- } catch {
2041
- o(/* @__PURE__ */ Error("storage upload: malformed response"));
2042
- }
2043
- else o(Error(`storage upload failed (${s.status}): ${s.responseText || s.statusText}`.trim()));
2044
- }, s.onerror = () => o(/* @__PURE__ */ Error("storage upload: network error")), s.onabort = () => o(new DOMException("upload aborted", "AbortError")), i.aborted) {
2045
- s.abort();
2046
- return;
2047
- }
2048
- i.addEventListener("abort", () => s.abort(), { once: !0 }), s.send(n);
2049
- }), ri = (e, t = {}) => {
2050
- let n = A(e), { inspectBaseUrl: r } = n, i = K(n);
2051
- i.current = n;
2052
- let [a, s] = q(0), [c, l] = q("idle"), [u, d] = q(void 0), f = K(null), p = U(() => {
2053
- s(0), l("idle"), d(void 0);
2054
- }, []), m = U(() => {
2055
- f.current?.abort();
2056
- }, []), h = U((e) => /^https?:\/\//.test(e) ? e : `${r}${e}`, [r]), g = U(async (n, r, a, o) => {
2057
- let { runtime: s, client: c } = await P(i, e, "storage.upload").catch((e) => {
2058
- throw T(e, "client");
2059
- }), l = Math.max(0, r.retries ?? t.retries ?? 1), u = (n instanceof File, n.type || "application/octet-stream"), d = n instanceof File ? n.name : "blob", f = r.visibility ?? t.visibility, p = r.access ?? t.access, m = r.key ?? t.key, g = r.folder ?? t.folder, _ = r.tags ?? t.tags, y = {
2060
- ...f ? { visibility: f } : {},
2061
- ...p === void 0 ? {} : { access: p },
2062
- ...g ? { folder: g } : {},
2063
- ..._ ? { tags: _ } : {},
2064
- ...r.alt ? { alt: r.alt } : {},
2065
- ...r.caption ? { caption: r.caption } : {}
2066
- }, b = (e) => ({
2067
- id: e.id,
2068
- url: h(e.url),
2069
- name: d,
2070
- mime: e.contentType,
2071
- size: e.size,
2072
- ...e.width === void 0 ? {} : { width: e.width },
2073
- ...e.height === void 0 ? {} : { height: e.height }
2074
- }), x = async () => {
2075
- let e = r.mintTag ?? t.mintTag ?? $("mintUploadTicket"), i = v(c, e), l = await S(s, i({
2076
- contentType: u,
2077
- ...y,
2078
- ...m ? { key: m } : {}
2079
- })), d = await ni(h(l.uploadUrl), u, n, o, a);
2080
- return b(d);
2081
- }, C = async () => {
2082
- let e = r.presignMintTag ?? t.presignMintTag ?? $("mintPresignedUpload"), i = r.finalizeTag ?? t.finalizeTag ?? $("finalizeUpload"), l;
2083
- try {
2084
- let t = v(c, e);
2085
- l = await S(s, t({
2086
- contentType: u,
2087
- ...y
2088
- }));
2089
- } catch {
2090
- return null;
2091
- }
2092
- await ti(l.uploadUrl, u, n, o, a);
2093
- let d = v(c, i), f = await S(s, d({ finalizeToken: l.finalizeToken }));
2094
- return b(f);
2095
- }, w = async () => {
2096
- let e = r.beginResumableTag ?? t.beginResumableTag ?? $("beginResumableUpload"), i = v(c, e), l = n.size, d = r.chunkSize ?? t.chunkSize, f = await S(s, i({
2097
- contentType: u,
2098
- size: l,
2099
- ...y,
2100
- ...d ? { chunkSize: d } : {}
2101
- })), p = h(f.uploadUrl), m = Math.max(1, f.chunkSize), g = Math.max(1, Math.ceil(l / m)), _ = Math.max(0, r.retries ?? t.retries ?? 1), x = 0, C = null;
2102
- for (let e = 0; e < g; e++) {
2103
- let t = e * m, r = Math.min(l, t + m), i = n.slice(t, r), s = e === g - 1, c = r - t, d = 0;
2104
- for (;;) {
2105
- if (a.aborted) throw new DOMException("upload aborted", "AbortError");
2106
- try {
2107
- let t = await ei(`${p}?${`token=${encodeURIComponent(f.resumableToken)}&index=${e}${s ? "&final=1" : ""}`}`, u, i, (e) => o((x + e * c) / l), a, s);
2108
- s && (C = t);
2109
- break;
2110
- } catch (e) {
2111
- if (e instanceof DOMException && e.name === "AbortError" || d++ >= _) throw e;
2112
- }
2113
- }
2114
- x += c, o(x / l);
2115
- }
2116
- if (!C) throw Error("resumable upload produced no final reply");
2117
- return b(C);
2118
- }, E = async () => {
2119
- let e = r.multipartBeginTag ?? t.multipartBeginTag ?? $("beginMultipartUpload"), i = r.multipartSignTag ?? t.multipartSignTag ?? $("signMultipartPart"), l = r.multipartCompleteTag ?? t.multipartCompleteTag ?? $("completeMultipartUpload"), f = r.multipartAbortTag ?? t.multipartAbortTag ?? $("abortMultipartUpload"), p = n.size, m = r.chunkSize ?? t.chunkSize, g;
2120
- try {
2121
- let t = v(c, e);
2122
- g = await S(s, t({
2123
- contentType: u,
2124
- size: p,
2125
- ...y,
2126
- ...m ? { partSize: m } : {}
2127
- }));
2128
- } catch {
2129
- return null;
2130
- }
2131
- let _ = v(c, i), b = v(c, l), x = v(c, f), C = Math.max(1, g.partSize), w = Math.max(1, Math.ceil(p / C)), T = Math.max(0, r.retries ?? t.retries ?? 1), E = [], D = 0;
2132
- try {
2133
- for (let e = 0; e < w; e++) {
2134
- let t = e * C, r = Math.min(p, t + C), i = n.slice(t, r), c = e + 1, l = r - t, u = 0;
2135
- for (;;) {
2136
- if (a.aborted) throw new DOMException("upload aborted", "AbortError");
2137
- try {
2138
- let { url: e } = await S(s, _({
2139
- multipartToken: g.multipartToken,
2140
- partNumber: c
2141
- })), t = await $r(e, i, (e) => o((D + e * l) / p), a);
2142
- E.push({
2143
- partNumber: c,
2144
- etag: t
2145
- });
2146
- break;
2147
- } catch (e) {
2148
- if (e instanceof DOMException && e.name === "AbortError" || u++ >= T) throw e;
2149
- }
2150
- }
2151
- D += l, o(D / p);
2152
- }
2153
- let e = await S(s, b({
2154
- multipartToken: g.multipartToken,
2155
- parts: E
2156
- }));
2157
- return {
2158
- id: e.id,
2159
- url: h(e.url),
2160
- name: d,
2161
- mime: u,
2162
- size: e.size
2163
- };
2164
- } catch (e) {
2165
- try {
2166
- await S(s, x({ multipartToken: g.multipartToken }));
2167
- } catch {}
2168
- throw e;
2169
- }
2170
- };
2171
- if ((r.prefer ?? t.prefer) === "multipart") return await E() || await w();
2172
- if ((r.prefer ?? t.prefer) === "resumable") return await w();
2173
- let D = (r.prefer ?? t.prefer) === "presign", O;
2174
- for (let e = 0; e <= l; e++) {
2175
- if (a.aborted) throw new DOMException("upload aborted", "AbortError");
2176
- try {
2177
- if (D) {
2178
- let e = await C();
2179
- if (e) return e;
2180
- }
2181
- return await x();
2182
- } catch (t) {
2183
- if (t instanceof DOMException && t.name === "AbortError" || (O = t, e === l)) throw t;
2184
- }
2185
- }
2186
- throw O;
2187
- }, [
2188
- e,
2189
- h,
2190
- t.mintTag,
2191
- t.presignMintTag,
2192
- t.finalizeTag,
2193
- t.beginResumableTag,
2194
- t.multipartBeginTag,
2195
- t.multipartSignTag,
2196
- t.multipartCompleteTag,
2197
- t.multipartAbortTag,
2198
- t.chunkSize,
2199
- t.prefer,
2200
- t.visibility,
2201
- t.key,
2202
- t.folder,
2203
- t.tags,
2204
- t.retries
2205
- ]), _ = U(async (e, n = {}) => {
2206
- let r = new AbortController();
2207
- f.current = r, l("uploading"), d(void 0), s(0);
2208
- try {
2209
- let t = await g(e, n, r.signal, s);
2210
- return s(1), l("success"), t;
2211
- } catch (e) {
2212
- throw l("error"), d(e), e instanceof DOMException && e.name === "AbortError" || i.current.errorBus.emit({
2213
- source: "action",
2214
- tag: n.mintTag ?? t.mintTag ?? $("mintUploadTicket"),
2215
- error: e,
2216
- kind: o(e, "unknown"),
2217
- outcome: o(e, "unknown") === "transport" ? "unknown" : "not-applicable"
2218
- }), e;
2219
- }
2220
- }, [g, t.mintTag]), y = U(async (e, n = {}) => {
2221
- if (e.length === 0) return [];
2222
- let r = new AbortController();
2223
- f.current = r, l("uploading"), d(void 0), s(0);
2224
- let a = Math.max(1, n.concurrency ?? t.concurrency ?? 3), c = Array(e.length), u = Zr(e.length), p = 0, m = async () => {
2225
- for (;;) {
2226
- let t = p++;
2227
- if (t >= e.length) return;
2228
- c[t] = await g(e[t], n, r.signal, (n) => {
2229
- s(u(t, n, e.length));
2230
- }), s(u(t, 1, e.length));
2231
- }
2232
- };
2233
- try {
2234
- return await Promise.all(Array.from({ length: Math.min(a, e.length) }, () => m())), s(1), l("success"), c;
2235
- } catch (e) {
2236
- throw r.abort(), l("error"), d(e), e instanceof DOMException && e.name === "AbortError" || i.current.errorBus.emit({
2237
- source: "action",
2238
- tag: n.mintTag ?? t.mintTag ?? $("mintUploadTicket"),
2239
- error: e,
2240
- kind: o(e, "unknown"),
2241
- outcome: o(e, "unknown") === "transport" ? "unknown" : "not-applicable"
2242
- }), e;
2243
- }
2244
- }, [
2245
- g,
2246
- t.concurrency,
2247
- t.mintTag
2248
- ]), b = U((e, t = {}) => {
2249
- e.preventDefault();
2250
- let n = e.dataTransfer ? Array.from(e.dataTransfer.files) : [];
2251
- return n.length ? y(n, t) : Promise.resolve([]);
2252
- }, [y]), x = U((e, t = {}) => {
2253
- let n = e.clipboardData ? Array.from(e.clipboardData.files) : [];
2254
- return n.length ? y(n, t) : Promise.resolve([]);
2255
- }, [y]), C = G(() => ({
2256
- onDragOver: (e) => e.preventDefault(),
2257
- onDrop: (e) => {
2258
- b(e);
2259
- }
2260
- }), [b]);
2261
- return G(() => ({
2262
- upload: _,
2263
- uploadMany: y,
2264
- progress: a,
2265
- status: c,
2266
- error: u,
2267
- cancel: m,
2268
- reset: p,
2269
- onDrop: b,
2270
- onPaste: x,
2271
- dropzoneProps: C
2272
- }), [
2273
- _,
2274
- y,
2275
- a,
2276
- c,
2277
- u,
2278
- m,
2279
- p,
2280
- b,
2281
- x,
2282
- C
2283
- ]);
2284
- }, ii = (e, t) => {
2285
- let n = ri(e), r = ar(e, t.action), [i, a] = q("idle"), [o, s] = q(void 0), [c, l] = q(void 0), u = K(t.extra);
2286
- u.current = t.extra;
2287
- let d = U(async (e) => {
2288
- l(void 0), s(void 0), a("uploading");
2289
- let t;
2290
- try {
2291
- t = await n.upload(e);
2292
- } catch (e) {
2293
- throw a("error"), l(e), e;
2294
- }
2295
- a("transcribing");
2296
- try {
2297
- let e = await r.run({
2298
- storageRef: t.id,
2299
- ...u.current ?? {}
2300
- });
2301
- return s(e), a("done"), e;
2302
- } catch (e) {
2303
- throw a("error"), l(e), e;
2304
- }
2305
- }, [n, r]), f = U(() => {
2306
- n.cancel(), a("idle");
2307
- }, [n]), p = U(() => {
2308
- n.reset(), a("idle"), s(void 0), l(void 0);
2309
- }, [n]);
2310
- return G(() => ({
2311
- phase: i,
2312
- progress: i === "uploading" ? n.progress : void 0,
2313
- result: o,
2314
- error: c ?? n.error,
2315
- transcribe: d,
2316
- cancel: f,
2317
- reset: p
2318
- }), [
2319
- i,
2320
- n.progress,
2321
- n.error,
2322
- o,
2323
- c,
2324
- d,
2325
- f,
2326
- p
2327
- ]);
2328
- }, ai = async (e) => {
2329
- let t = v(e.client, e.tag), n = Y.currentSpan.pipe(Y.tap((t) => Y.sync(() => {
2330
- r({
2331
- traceId: t.traceId,
2332
- spanId: t.spanId,
2333
- source: "mutation",
2334
- tag: e.tag
2335
- });
2336
- })), Y.catch(() => Y.void), Y.andThen(t(e.input)), Y.withSpan(`${e.spanPrefix}.${e.tag}`, { attributes: {
2337
- "voltro.api": e.apiName,
2338
- "rpc.tag": e.tag
2339
- } }));
2340
- return S(e.runtime, n);
2341
- }, oi = (e, t) => {
2342
- let n = A(e), { descriptors: r } = n, i = K(n);
2343
- if (i.current = n, process.env.NODE_ENV !== "production") {
2344
- let n = r[t]?.kind;
2345
- n !== void 0 && n !== "workflow" && console.error(`[@voltro/client] useWorkflow('${e}', '${t}') targets a ${n}, not a workflow. Use ${n === "mutation" ? "useMutation" : n === "action" ? "useAction" : `the ${n} hook`} instead.`);
2346
- }
2347
- let [a, o] = q(!1), [s, c] = q(void 0), [l, u] = q(void 0), d = U(async (n) => {
2348
- o(!0), c(void 0);
2349
- try {
2350
- let { runtime: r, client: a } = await P(i, e, t), o = await ai({
2351
- apiName: e,
2352
- runtime: r,
2353
- client: a,
2354
- tag: t,
2355
- input: n,
2356
- spanPrefix: "client.workflow.start"
2357
- });
2358
- return u(o), o;
2359
- } catch (e) {
2360
- throw c(e), e;
2361
- } finally {
2362
- o(!1);
2363
- }
2364
- }, [e, t]), f = U(async (t) => {
2365
- let n = "__voltro.workflow.queued.cancel", { runtime: r, client: a } = await P(i, e, n);
2366
- return ai({
2367
- apiName: e,
2368
- runtime: r,
2369
- client: a,
2370
- tag: n,
2371
- input: t,
2372
- spanPrefix: "client.workflow.queued.cancel"
2373
- });
2374
- }, [e]), p = U(async (t) => {
2375
- let n = "__voltro.workflow.queued.control", { runtime: r, client: a } = await P(i, e, n), o = v(a, n);
2376
- return S(r, X.runHead(o(t)).pipe(Y.flatMap((e) => {
2377
- if (ze.isSome(e)) {
2378
- if (e.value._tag === "snapshot") return Y.succeed(e.value.data);
2379
- if (e.value._tag === "error") return Y.fail(e.value.error);
2380
- }
2381
- return Y.fail(/* @__PURE__ */ Error("queued workflow control query ended without a snapshot"));
2382
- })));
2383
- }, [e]), m = U(async (t) => {
2384
- let n = "__voltro.workflow.control", { runtime: r, client: a } = await P(i, e, n), o = v(a, n);
2385
- return S(r, X.runHead(o(t)).pipe(Y.flatMap((e) => {
2386
- if (ze.isSome(e)) {
2387
- if (e.value._tag === "snapshot") return Y.succeed(e.value.data);
2388
- if (e.value._tag === "error") return Y.fail(e.value.error);
2389
- }
2390
- return Y.fail(/* @__PURE__ */ Error("workflow control query ended without a snapshot"));
2391
- })));
2392
- }, [e]), h = U(async (t, n) => {
2393
- let { runtime: r, client: a } = await P(i, e, "__voltro.workflow.cancel");
2394
- return ai({
2395
- apiName: e,
2396
- runtime: r,
2397
- client: a,
2398
- tag: "__voltro.workflow.cancel",
2399
- input: {
2400
- ...t,
2401
- ...n === void 0 ? {} : { control: n }
2402
- },
2403
- spanPrefix: "client.workflow.cancel"
2404
- });
2405
- }, [e]), g = U(async (t, n) => {
2406
- let { runtime: r, client: a } = await P(i, e, "__voltro.workflow.resume");
2407
- return ai({
2408
- apiName: e,
2409
- runtime: r,
2410
- client: a,
2411
- tag: "__voltro.workflow.resume",
2412
- input: {
2413
- ...t,
2414
- ...n === void 0 ? {} : { control: n }
2415
- },
2416
- spanPrefix: "client.workflow.resume"
2417
- });
2418
- }, [e]), _ = U(async (t, n, r) => {
2419
- let { runtime: a, client: o } = await P(i, e, "__voltro.workflow.signal");
2420
- return ai({
2421
- apiName: e,
2422
- runtime: a,
2423
- client: o,
2424
- tag: "__voltro.workflow.signal",
2425
- input: {
2426
- id: t.id,
2427
- signalName: n,
2428
- ...r === void 0 ? {} : { payload: r }
2429
- },
2430
- spanPrefix: "client.workflow.signal"
2431
- });
2432
- }, [e]), y = U(async (t, n, r, a) => {
2433
- let { runtime: o, client: s } = await P(i, e, "__voltro.workflow.update");
2434
- return ai({
2435
- apiName: e,
2436
- runtime: o,
2437
- client: s,
2438
- tag: "__voltro.workflow.update",
2439
- input: {
2440
- id: t.id,
2441
- updateName: n,
2442
- ...r === void 0 ? {} : { payload: r },
2443
- ...a?.timeoutMs === void 0 ? {} : { timeoutMs: a.timeoutMs }
2444
- },
2445
- spanPrefix: "client.workflow.update"
2446
- });
2447
- }, [e]);
2448
- return G(() => ({
2449
- start: d,
2450
- cancelQueued: f,
2451
- readQueuedCancellation: p,
2452
- cancel: h,
2453
- readControl: m,
2454
- resume: g,
2455
- signal: _,
2456
- update: y,
2457
- pending: a,
2458
- error: s,
2459
- data: l
2460
- }), [
2461
- d,
2462
- f,
2463
- p,
2464
- h,
2465
- m,
2466
- g,
2467
- _,
2468
- y,
2469
- a,
2470
- s,
2471
- l
2472
- ]);
2473
- }, si = (e) => {
2474
- let t = A(e), n = K(t);
2475
- n.current = t;
2476
- let [r, i] = q(!1), [a, o] = q(void 0), [s, c] = q(void 0), l = U(async (t, r, a) => {
2477
- i(!0), o(void 0);
2478
- try {
2479
- let { runtime: i, client: o } = await P(n, e, "__voltro.workflow.signal"), s = await ai({
2480
- apiName: e,
2481
- runtime: i,
2482
- client: o,
2483
- tag: "__voltro.workflow.signal",
2484
- input: {
2485
- id: t.id,
2486
- signalName: r,
2487
- ...a === void 0 ? {} : { payload: a }
2488
- },
2489
- spanPrefix: "client.workflow.signal"
2490
- });
2491
- return c(s), s;
2492
- } catch (e) {
2493
- throw o(e), e;
2494
- } finally {
2495
- i(!1);
2496
- }
2497
- }, [e]);
2498
- return G(() => ({
2499
- signal: l,
2500
- pending: r,
2501
- error: a,
2502
- data: s
2503
- }), [
2504
- l,
2505
- r,
2506
- a,
2507
- s
2508
- ]);
2509
- }, ci = (e) => {
2510
- let t = A(e), n = K(t);
2511
- n.current = t;
2512
- let [r, i] = q(!1), [a, o] = q(void 0), [s, c] = q(void 0), l = U(async (t, r, a, s) => {
2513
- i(!0), o(void 0);
2514
- try {
2515
- let { runtime: i, client: o } = await P(n, e, "__voltro.workflow.update"), l = await ai({
2516
- apiName: e,
2517
- runtime: i,
2518
- client: o,
2519
- tag: "__voltro.workflow.update",
2520
- input: {
2521
- id: t.id,
2522
- updateName: r,
2523
- ...a === void 0 ? {} : { payload: a },
2524
- ...s?.timeoutMs === void 0 ? {} : { timeoutMs: s.timeoutMs }
2525
- },
2526
- spanPrefix: "client.workflow.update"
2527
- });
2528
- return c(l), l;
2529
- } catch (e) {
2530
- throw o(e), e;
2531
- } finally {
2532
- i(!1);
2533
- }
2534
- }, [e]);
2535
- return G(() => ({
2536
- update: l,
2537
- pending: r,
2538
- error: a,
2539
- data: s
2540
- }), [
2541
- l,
2542
- r,
2543
- a,
2544
- s
2545
- ]);
2546
- }, li = (e, t) => {
2547
- let n = Z(e, "__voltro.workflow.run", t ? { id: t } : {}, { skip: t === void 0 });
2548
- return n.loading || n.idle || n.failed ? {
2549
- ...n,
2550
- run: void 0
2551
- } : {
2552
- ...n,
2553
- run: n.data[0]
2554
- };
2555
- }, ui = (e, t = {}, n = {}) => {
2556
- let r = Z(e, "__voltro.workflow.runs", t, n);
2557
- return r.loading || r.idle || r.failed ? {
2558
- ...r,
2559
- runs: []
2560
- } : {
2561
- ...r,
2562
- runs: r.data
2563
- };
2564
- }, di = (e, t) => {
2565
- let n = Z(e, "__voltro.workflow.run.steps", t ? { runId: t } : {}, { skip: t === void 0 });
2566
- return n.loading || n.idle || n.failed ? {
2567
- ...n,
2568
- steps: []
2569
- } : {
2570
- ...n,
2571
- steps: n.data
2572
- };
2573
- }, fi = (e, t) => {
2574
- let n = Z(e, "__voltro.workflow.run.events", t ? { runId: t } : {}, { skip: t === void 0 });
2575
- return n.loading || n.idle || n.failed ? {
2576
- ...n,
2577
- events: []
2578
- } : {
2579
- ...n,
2580
- events: n.data
2581
- };
2582
- }, pi = fi, mi = (e, t = {}, n = {}) => {
2583
- let r = Z(e, "__voltro.workflow.domainEvents", t, n);
2584
- return r.loading || r.idle || r.failed ? {
2585
- ...r,
2586
- events: []
2587
- } : {
2588
- ...r,
2589
- events: r.data
2590
- };
2591
- }, hi = (e, t) => {
2592
- let n = Z(e, "__voltro.workflow.event.deliveries", t ? { eventId: t } : {}, { skip: t === void 0 });
2593
- return n.loading || n.idle || n.failed ? {
2594
- ...n,
2595
- deliveries: []
2596
- } : {
2597
- ...n,
2598
- deliveries: n.data
2599
- };
2600
- }, gi = (e, t) => {
2601
- let n = e.payload;
2602
- if (!n || typeof n != "object") return;
2603
- let r = n[t];
2604
- return typeof r == "string" ? r : void 0;
2605
- }, _i = (e) => {
2606
- let t = e.payload;
2607
- if (!t || typeof t != "object") return;
2608
- let n = t.updateId;
2609
- return typeof n == "string" ? n : void 0;
2610
- }, vi = (e) => {
2611
- let t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
2612
- for (let r of e) if (r.eventType === "signal-received") {
2613
- let e = gi(r, "signalName");
2614
- e && t.add(e);
2615
- } else if (r.eventType === "update-completed" || r.eventType === "update-failed") {
2616
- let e = _i(r);
2617
- e && n.add(e);
2618
- }
2619
- for (let r = e.length - 1; r >= 0; --r) {
2620
- let i = e[r];
2621
- if (i.eventType === "signal-awaited") {
2622
- let e = gi(i, "signalName");
2623
- if (e && !t.has(e)) return {
2624
- name: e,
2625
- kind: "signal"
2626
- };
2627
- } else if (i.eventType === "update-requested") {
2628
- let e = _i(i), t = gi(i, "updateName");
2629
- if (t && (!e || !n.has(e))) return {
2630
- name: t,
2631
- kind: "update"
2632
- };
2633
- }
2634
- }
2635
- }, yi = (e) => e.find((e) => e.status === "running") || (e.length > 0 ? e[e.length - 1] : void 0), bi = (e, t) => {
2636
- if (!e || e.status !== "failed") return;
2637
- let n = t.find((e) => e.status === "failed");
2638
- return {
2639
- tag: e.errorTag,
2640
- message: e.errorMessage,
2641
- step: n?.stepName
2642
- };
2643
- }, xi = (e, t) => {
2644
- let n = li(e, t), r = di(e, t), i = fi(e, t), a = oi(e, n.run?.tag ?? ""), o = n.run, s = r.steps, c = i.events, l = U(async () => {
2645
- if (!o) throw Error("useWorkflowRunState: no run loaded — cannot cancel");
2646
- await a.cancel({
2647
- workflowName: o.tag,
2648
- executionId: o.executionId
2649
- });
2650
- }, [a, o]), u = U(async () => {
2651
- if (!o) throw Error("useWorkflowRunState: no run loaded — cannot resume");
2652
- await a.resume({
2653
- workflowName: o.tag,
2654
- executionId: o.executionId
2655
- });
2656
- }, [a, o]), d = U((e, n) => {
2657
- if (t === void 0) throw Error("useWorkflowRunState: no run id — cannot signal");
2658
- return a.signal({ id: t }, e, n);
2659
- }, [a, t]), f = U((e, n, r) => {
2660
- if (t === void 0) throw Error("useWorkflowRunState: no run id — cannot update");
2661
- return a.update({ id: t }, e, n, r);
2662
- }, [a, t]);
2663
- return G(() => ({
2664
- run: o,
2665
- status: o?.status,
2666
- steps: s,
2667
- events: c,
2668
- currentStep: yi(s),
2669
- waitingFor: o?.status === "suspended" ? vi(c) : void 0,
2670
- error: bi(o, s),
2671
- traceId: o?.traceId,
2672
- loading: n.data === void 0,
2673
- cancel: l,
2674
- resume: u,
2675
- signal: d,
2676
- update: f
2677
- }), [
2678
- o,
2679
- s,
2680
- c,
2681
- n.data,
2682
- l,
2683
- u,
2684
- d,
2685
- f
2686
- ]);
2687
- }, Si = (e, t) => {
2688
- let { runtime: n, client: r } = A(e), [a, o] = q([]), [s, c] = q("idle"), [l, u] = q(void 0), d = K(null), f = K(null);
2689
- W(() => () => {
2690
- let e = f.current;
2691
- e?.timer !== void 0 && clearTimeout(e.timer), f.current = null;
2692
- let t = d.current;
2693
- d.current = null, t !== null && n.runFork(Re.interrupt(t));
2694
- }, [
2695
- n,
2696
- r,
2697
- t
2698
- ]);
2699
- let p = U(() => {
2700
- let e = f.current;
2701
- e !== null && (e.timer !== void 0 && clearTimeout(e.timer), o(e.events.slice()), f.current = null);
2702
- let t = d.current;
2703
- t && (d.current = null, n.runFork(Re.interrupt(t)), c((e) => e === "streaming" ? "idle" : e));
2704
- }, [n]);
2705
- return {
2706
- events: a,
2707
- status: s,
2708
- error: l,
2709
- start: U((e = {}) => {
2710
- let a = d.current;
2711
- a && n.runFork(Re.interrupt(a));
2712
- let s = f.current;
2713
- s?.timer !== void 0 && clearTimeout(s.timer);
2714
- let l = {
2715
- events: [],
2716
- timer: void 0
2717
- };
2718
- f.current = l, o([]), u(void 0), c("streaming");
2719
- let p = v(r, t)(e), m = () => {
2720
- l.timer !== void 0 && clearTimeout(l.timer), l.timer = void 0, f.current === l && o(l.events.slice());
2721
- }, h = X.runForEachArray(p, (e) => Y.sync(() => {
2722
- if (f.current === l) {
2723
- for (let t of e) l.events.push(t);
2724
- l.timer ??= setTimeout(m, 16);
2725
- }
2726
- })).pipe(Y.matchCause({
2727
- onSuccess: () => {
2728
- f.current === l && (m(), f.current = null, d.current = null, c("done"));
2729
- },
2730
- onFailure: (e) => {
2731
- Fe.hasInterruptsOnly(e) || f.current === l && (m(), f.current = null, d.current = null, u(i(e)), c("error"));
2732
- }
2733
- }));
2734
- d.current = n.runFork(h);
2735
- }, [
2736
- n,
2737
- r,
2738
- t
2739
- ]),
2740
- cancel: p
2741
- };
2742
- }, Ci = (e, t, n, r) => {
2743
- let a = 0, o = !1, s = (e) => Y.sync(() => {
2744
- e.seq <= a || (a = e.seq, n.onEvent(e.event), r.isTerminal(e.event) && (o = !0));
2745
- }), c = (e) => {
2746
- if (typeof e != "object" || !e) return;
2747
- let t = e.name, n = e.message;
2748
- if (typeof t == "string" || typeof n == "string") return `${typeof t == "string" ? t : ""}::${typeof n == "string" ? n : ""}`;
2749
- }, l, u = (e, t, i) => {
2750
- let o = a > t, s = o ? 0 : e + 1, u = i === void 0 ? void 0 : c(i), f = u !== void 0 && u === l && !o;
2751
- if (l = o ? void 0 : u, f || s > r.maxReconnects) return Y.sync(() => {
2752
- n.onError(i ?? /* @__PURE__ */ Error("stream connection lost")), n.onStatus("error");
2753
- });
2754
- let p = Math.min(r.maxBackoffMs, r.backoffMs * 2 ** Math.max(0, s - 1));
2755
- return Y.sync(() => {
2756
- n.onStatus("reconnecting"), n.onReconnect();
2757
- }).pipe(Y.andThen(Y.sleep(Ie.millis(p))), Y.andThen(Y.sync(() => n.onStatus("streaming"))), Y.andThen(d(s)));
2758
- }, d = (r) => Y.suspend(() => {
2759
- let c = a, l = e({
2760
- ...t,
2761
- fromSeq: c
2762
- });
2763
- return X.runForEach(l, s).pipe(Y.matchCauseEffect({
2764
- onSuccess: () => o ? Y.sync(() => n.onStatus("done")) : u(r, c, void 0),
2765
- onFailure: (e) => Fe.hasInterruptsOnly(e) ? Y.void : o ? Y.sync(() => n.onStatus("done")) : u(r, c, i(e))
2766
- }));
2767
- });
2768
- return d(0);
2769
- }, wi = (e) => {
2770
- let t = e?._tag;
2771
- return t === "done" || t === "error";
2772
- }, Ti = (e, t, n = {}) => {
2773
- let { runtime: r, client: i } = A(e), [a, o] = q([]), [s, c] = q("idle"), [l, u] = q(0), [d, f] = q(void 0), p = K(null), m = {
2774
- maxReconnects: n.maxReconnects ?? 6,
2775
- backoffMs: n.backoffMs ?? 400,
2776
- maxBackoffMs: n.maxBackoffMs ?? 8e3,
2777
- isTerminal: n.isTerminal ?? wi
2778
- }, h = U(() => {
2779
- let e = p.current;
2780
- e && (p.current = null, r.runFork(Re.interrupt(e)), c((e) => e === "streaming" || e === "reconnecting" ? "idle" : e));
2781
- }, [r]);
2782
- return {
2783
- events: a,
2784
- status: s,
2785
- reconnects: l,
2786
- error: d,
2787
- start: U((e = {}) => {
2788
- let n = p.current;
2789
- n && r.runFork(Re.interrupt(n)), o([]), f(void 0), u(0), c("streaming");
2790
- let a = v(i, t), s = {
2791
- onEvent: (e) => o((t) => [...t, e]),
2792
- onStatus: c,
2793
- onReconnect: () => u((e) => e + 1),
2794
- onError: f
2795
- };
2796
- p.current = r.runFork(Ci(a, e, s, m));
2797
- }, [
2798
- r,
2799
- i,
2800
- t,
2801
- m.maxReconnects,
2802
- m.backoffMs,
2803
- m.maxBackoffMs,
2804
- m.isTerminal
2805
- ]),
2806
- cancel: h
2807
- };
2808
- }, Ei = (e, t) => e.order - t.order || (e.stepOrder ?? 0) - (t.stepOrder ?? 0), Di = (e) => {
2809
- for (let t = e.length - 1; t >= 0; --t) {
2810
- let n = e[t];
2811
- if (n.role === "user" && n.content) return n.content;
2812
- }
2813
- }, Oi = (e, t, n) => {
2814
- let { threadId: r } = n, i = Z(e, `${t}.messages`, { threadId: r }), a = ar(e, `${t}.send`), o = G(() => [...i.data ?? []].sort(Ei), [i.data]), s = U((e, t = {}) => a.run({
2815
- threadId: r,
2816
- order: i.data?.length ?? 0,
2817
- prompt: e,
2818
- ...t
2819
- }), [
2820
- a,
2821
- r,
2822
- i.data
2823
- ]), c = U(() => {
2824
- let e = Di(o);
2825
- return e === void 0 ? void 0 : s(e);
2826
- }, [o, s]);
2827
- return G(() => ({
2828
- messages: o,
2829
- streaming: o.some((e) => e.streaming),
2830
- loading: i.data === void 0,
2831
- error: i.error ?? a.error,
2832
- send: s,
2833
- regenerate: c,
2834
- sending: a.pending
2835
- }), [
2836
- o,
2837
- i.data,
2838
- i.error,
2839
- a.error,
2840
- a.pending,
2841
- s,
2842
- c
2843
- ]);
2844
- }, ki = (e, t) => {
2845
- let { events: n, status: r, error: i, start: a, cancel: o } = Si(e, t), [s, c] = q([]), l = K(null), u = K({
2846
- events: [],
2847
- count: 0,
2848
- text: ""
2849
- }), d = G(() => {
2850
- let e = u.current, t = n.length >= e.count && (e.count === 0 || n[0] === e.events[0] && n[e.count - 1] === e.events[e.count - 1]), r = t ? e.text : "";
2851
- for (let i = t ? e.count : 0; i < n.length; i++) {
2852
- let e = n[i];
2853
- e._tag === "token" && (r += e.text ?? "");
2854
- }
2855
- return u.current = {
2856
- events: n,
2857
- count: n.length,
2858
- text: r
2859
- }, r;
2860
- }, [n]);
2861
- return W(() => {
2862
- if (r !== "done" || l.current === null) return;
2863
- let e = l.current;
2864
- l.current = null, c((t) => [
2865
- ...t,
2866
- {
2867
- role: "user",
2868
- content: e
2869
- },
2870
- {
2871
- role: "assistant",
2872
- content: d
2873
- }
2874
- ]);
2875
- }, [r, d]), {
2876
- tokens: d,
2877
- history: s,
2878
- status: r,
2879
- error: i,
2880
- send: U((e = {}) => {
2881
- u.current = {
2882
- events: [],
2883
- count: 0,
2884
- text: ""
2885
- };
2886
- let t = e.message;
2887
- l.current = typeof t == "string" ? t : "", a(e);
2888
- }, [a]),
2889
- cancel: o
2890
- };
2891
- }, Ai = (e, t) => {
2892
- let n = ar(e, t), [r, i] = q(void 0), a = U(async (e) => {
2893
- let t = await n.run({ question: e });
2894
- return i(t), t;
2895
- }, [n]), o = U(() => i(void 0), []);
2896
- return G(() => ({
2897
- ask: a,
2898
- answer: r,
2899
- pending: n.pending,
2900
- error: n.error,
2901
- reset: o
2902
- }), [
2903
- a,
2904
- r,
2905
- n.pending,
2906
- n.error,
2907
- o
2908
- ]);
2909
- }, ji = (e) => {
2910
- let { cache: t, runtime: n } = A(e);
2911
- return U(() => {
2912
- t.refreshAll(n);
2913
- }, [t, n]);
2914
- }, Mi = (e, t, n) => {
2915
- let { cache: r } = A(e), i = f([t, n]), a = K([t, n]);
2916
- return a.current = [t, n], G(() => {
2917
- let e = a.current;
2918
- return () => r.refresh(e);
2919
- }, [r, i]);
2920
- }, Ni = (e, t) => {
2921
- let n = A(e), r = n.recovery ?? c(n.errorBus, e), i = K(t);
2922
- i.current = t, W(() => r.onVisibleError((e) => i.current(e)), [r]);
2923
- }, Pi = (e, t) => {
2924
- let { errorBus: n } = A(e), r = K(t);
2925
- r.current = t, W(() => n.on((e) => r.current(e)), [n]);
2926
- }, Fi = {
2927
- failed: [],
2928
- healthy: !0
2929
- }, Ii = (e) => {
2930
- let { errorBus: t } = A(e), [n, r] = q(Fi);
2931
- return W(() => {
2932
- let e = /* @__PURE__ */ new Map(), n = () => {
2933
- let t = [...e.values()].sort((e, t) => t.at - e.at);
2934
- r(t.length === 0 ? Fi : {
2935
- failed: t,
2936
- healthy: !1
2937
- });
2938
- }, i = t.on((t) => {
2939
- e.set(t.tag, {
2940
- tag: t.tag,
2941
- source: t.source,
2942
- error: t.error,
2943
- at: Date.now()
2944
- }), n();
2945
- }), a = t.onSuccess((t) => {
2946
- e.delete(t.tag) && n();
2947
- });
2948
- return () => {
2949
- i(), a();
2950
- };
2951
- }, [t]), n;
2952
- }, Li = or("serverRequest", null), Ri = () => je(Li), zi = ({ value: e, children: t }) => /* @__PURE__ */ it(Li.Provider, {
2953
- value: e,
2954
- children: t
2955
- }), Bi = (e) => {
2956
- let t = Ri();
2957
- return G(() => {
2958
- if (t !== null) return t.formFlash?.formKey === e ? t.formFlash : void 0;
2959
- if (typeof document > "u") return;
2960
- let n = document.getElementById(Ce);
2961
- if (n !== null && n.textContent !== null && n.textContent !== "") try {
2962
- let t = JSON.parse(n.textContent);
2963
- return t.formKey === e ? t : void 0;
2964
- } catch {
2965
- return;
2966
- }
2967
- }, [t, e]);
2968
- }, Vi = (e, t, n) => e.map((e) => {
2969
- let r = String(e[n] ?? ""), i = e[t];
2970
- return {
2971
- value: r,
2972
- label: i == null ? r : String(i)
2973
- };
2974
- }), Hi = (e) => ({ q: e }), Ui = (e, t, n = {}) => {
2975
- let r = n.debounceMs ?? 200, i = n.labelField ?? "name", a = n.valueField ?? "id", o = n.input ?? Hi, [s, c] = q(n.initialTerm ?? ""), [l, u] = q(s);
2976
- W(() => {
2977
- if (s === l) return;
2978
- let e = setTimeout(() => u(s), r);
2979
- return () => clearTimeout(e);
2980
- }, [
2981
- s,
2982
- l,
2983
- r
2984
- ]);
2985
- let d = n.skipUntilTerm === !0 && l.trim() === "", f = Z(e, t, G(() => o(l), [o, l]), { skip: d }), p = G(() => Vi(f.data ?? [], i, a), [
2986
- f.data,
2987
- i,
2988
- a
2989
- ]), m = U((e) => c(e), []);
2990
- return {
2991
- options: p,
2992
- loading: !d && f.data === void 0,
2993
- term: s,
2994
- search: m
2995
- };
2996
- }, Wi = (e, t) => e === t ? 0 : e == null ? 1 : t == null || e < t ? -1 : 1, Gi = (e, t) => [...e].sort((e, n) => Wi(e[t.column], n[t.column]) * (t.direction === "asc" ? 1 : -1)), Ki = () => {
2997
- let e;
2998
- return (t, n) => {
2999
- if (n === void 0) return e = void 0, t;
3000
- let r = () => (e = void 0, Gi(t, n));
3001
- if (t.length < 2048 || Object.getPrototypeOf(t) !== Array.prototype || Object.getOwnPropertySymbols(t).length > 0) return r();
3002
- for (let e = 0; e < t.length; e++) {
3003
- let n = Object.getOwnPropertyDescriptor(t, String(e));
3004
- if (n === void 0 || !("value" in n)) return r();
3005
- }
3006
- let i = [], a, o;
3007
- for (let s = 0; s < t.length; s++) {
3008
- let c = t[s];
3009
- if (typeof c != "object" || !c) return r();
3010
- let l;
3011
- if (e?.sort.column === n.column && e.rows[s] === c) l = e.keys[s];
3012
- else {
3013
- let e = Object.getPrototypeOf(c);
3014
- if (e !== Object.prototype && e !== null) return r();
3015
- let t = Object.getOwnPropertyDescriptor(c, n.column);
3016
- if (t !== void 0 && !("value" in t) || t === void 0 && n.column in c) return r();
3017
- l = t?.value;
3018
- }
3019
- if (l == null) {
3020
- let e = l === null ? "null" : "undefined";
3021
- if (o !== void 0 && e !== o) return r();
3022
- o = e;
3023
- } else {
3024
- let e = typeof l;
3025
- if (e !== "string" && e !== "number" && e !== "boolean" && e !== "bigint" || e === "number" && !Number.isFinite(l) || a !== void 0 && e !== a) return r();
3026
- a = e;
3027
- }
3028
- i.push(l);
3029
- }
3030
- let s = n.direction === "asc" ? 1 : -1, c = (e, t) => Wi(i[e], i[t]) * s || e - t, l = e !== void 0 && e.rows.length === t.length && e.sort.column === n.column && e.sort.direction === n.direction, u;
3031
- if (l) {
3032
- let n = e, r = [], a = !0;
3033
- for (let e = 0; e < t.length; e++) t[e] !== n.rows[e] && (a = !1), Object.is(i[e], n.keys[e]) || r.push(e);
3034
- if (a && r.length === 0) return n.result;
3035
- if (r.length === 0) u = n.order;
3036
- else if (r.length <= 8) {
3037
- let e = new Set(r);
3038
- u = n.order.filter((t) => !e.has(t));
3039
- for (let e of r) {
3040
- let t = 0, n = u.length;
3041
- for (; t < n;) {
3042
- let r = t + n >>> 1;
3043
- c(u[r], e) < 0 ? t = r + 1 : n = r;
3044
- }
3045
- u.splice(t, 0, e);
3046
- }
3047
- } else u = Array.from({ length: t.length }, (e, t) => t).sort(c);
3048
- } else u = Array.from({ length: t.length }, (e, t) => t).sort(c);
3049
- let d = u.map((e) => t[e]);
3050
- return e = {
3051
- rows: t,
3052
- sort: { ...n },
3053
- keys: i,
3054
- order: u,
3055
- result: d
3056
- }, d;
3057
- };
3058
- }, qi = (e, t, n = {}) => {
3059
- let r = A(e), [i, a] = q(n.pageSize), o = Z(e, t, G(() => i === void 0 ? n.input ?? {} : {
3060
- ...n.input,
3061
- limit: i
3062
- }, [n.input, i])), s = r.descriptors[t]?.output, c = U(() => {
3063
- n.pageSize !== void 0 && a((e) => (e ?? n.pageSize) + n.pageSize);
3064
- }, [n.pageSize]), l = G(() => n.columns ?? (s === void 0 ? [] : ae(s)), [n.columns, s]), [u, d] = q(n.initialSort), f = U((e) => {
3065
- d((t) => t?.column === e ? {
3066
- column: e,
3067
- direction: t.direction === "asc" ? "desc" : "asc"
3068
- } : {
3069
- column: e,
3070
- direction: "asc"
3071
- });
3072
- }, []), p = K(void 0);
3073
- return p.current === void 0 && (p.current = Ki()), {
3074
- columns: l,
3075
- rows: G(() => p.current(o.data ?? [], u), [o.data, u]),
3076
- loading: o.data === void 0,
3077
- error: o.error,
3078
- sort: u,
3079
- toggleSort: f,
3080
- loadMore: c,
3081
- hasMore: i !== void 0 && (o.data?.length ?? 0) >= i
3082
- };
3083
- }, Ji = (e, t, n, r) => {
3084
- let i = e.replace(/\/$/, ""), a = new URLSearchParams({
3085
- table: t,
3086
- id: n
3087
- });
3088
- return r !== void 0 && a.set("column", r), `${i}/_voltro/inspect/provenance?${a.toString()}`;
3089
- }, Yi = Ji, Xi = (e, t, n, r) => {
3090
- let { inspectBaseUrl: i } = A(e), [a, o] = q({
3091
- data: void 0,
3092
- loading: !0,
3093
- error: void 0
3094
- });
3095
- return W(() => {
3096
- let e = !1;
3097
- o({
3098
- data: void 0,
3099
- loading: !0,
3100
- error: void 0
3101
- });
3102
- let a = Ji(i ?? "", t, n, r);
3103
- return fetch(a).then(async (e) => {
3104
- if (!e.ok) throw Error(`provenance fetch failed: HTTP ${e.status}`);
3105
- return await e.json();
3106
- }).then((t) => {
3107
- e || o({
3108
- data: t,
3109
- loading: !1,
3110
- error: void 0
3111
- });
3112
- }).catch((t) => {
3113
- e || o({
3114
- data: void 0,
3115
- loading: !1,
3116
- error: t
3117
- });
3118
- }), () => {
3119
- e = !0;
3120
- };
3121
- }, [
3122
- e,
3123
- i,
3124
- t,
3125
- n,
3126
- r
3127
- ]), a;
3128
- }, Zi = (e) => {
3129
- if (!(e.length < 32 || Object.getPrototypeOf(e) !== Array.prototype || e.includes !== Array.prototype.includes || e[Symbol.iterator] !== Array.prototype[Symbol.iterator])) {
3130
- for (let t = 0; t < e.length; t++) {
3131
- let n = Object.getOwnPropertyDescriptor(e, String(t));
3132
- if (n === void 0 || !("value" in n) || typeof n.value != "string") return;
3133
- }
3134
- return new Set(e);
3135
- }
3136
- }, Qi = "admin:full", $i = (e, t) => e.includes("admin:full") ? !0 : typeof t == "string" ? e.includes(t) : t.every((t) => e.includes(t)), ea = (e, t) => t.length === 0 || e.includes("admin:full") ? !0 : t.some((t) => e.includes(t)), ta = ke({ scopes: [] });
3137
- function na(e) {
3138
- let t = Zi(e.scopes), n = t === void 0 ? { scopes: e.scopes } : {
3139
- scopes: e.scopes,
3140
- membership: t
3141
- };
3142
- return Ae(ta.Provider, { value: n }, e.children);
3143
- }
3144
- var ra = () => je(ta), ia = (e) => {
3145
- let t = je(ta);
3146
- return t.membership === void 0 ? $i(t.scopes, e) : t.membership.has("admin:full") ? !0 : typeof e == "string" ? t.membership.has(e) : e.every((e) => t.membership.has(e));
3147
- }, aa = (e) => {
3148
- let t = je(ta);
3149
- return t.membership === void 0 ? ea(t.scopes, e) : e.length === 0 || t.membership.has("admin:full") || e.some((e) => t.membership.has(e));
3150
- }, oa = (e) => `${e.replace(/\/$/, "")}/_voltro/inspect/manifest`, sa = (e) => {
3151
- let { inspectBaseUrl: t } = A(e), [n, r] = q({
3152
- manifest: void 0,
3153
- loading: !0,
3154
- error: void 0
3155
- });
3156
- return W(() => {
3157
- let e = !1;
3158
- return r({
3159
- manifest: void 0,
3160
- loading: !0,
3161
- error: void 0
3162
- }), fetch(oa(t ?? "")).then(async (e) => {
3163
- if (!e.ok) throw Error(`manifest fetch failed: HTTP ${e.status}`);
3164
- return await e.json();
3165
- }).then((t) => {
3166
- e || r({
3167
- manifest: t,
3168
- loading: !1,
3169
- error: void 0
3170
- });
3171
- }).catch((t) => {
3172
- e || r({
3173
- manifest: void 0,
3174
- loading: !1,
3175
- error: t
3176
- });
3177
- }), () => {
3178
- e = !0;
3179
- };
3180
- }, [e, t]), n;
3181
- }, ca = (e) => {
3182
- if (Object.getPrototypeOf(e) !== Array.prototype || Object.hasOwn(e, Symbol.iterator)) return !1;
3183
- for (let t = 0; t < e.length; t++) {
3184
- let n = Object.getOwnPropertyDescriptor(e, String(t));
3185
- if (!n || !("value" in n)) return !1;
3186
- let r = n.value;
3187
- if (Object.getPrototypeOf(r) !== Object.prototype || Object.values(Object.getOwnPropertyDescriptors(r)).some((e) => !("value" in e))) return !1;
3188
- if (r.kind !== "scope") continue;
3189
- let i = r.scope;
3190
- if (Object.getPrototypeOf(i) !== Array.prototype || [
3191
- Symbol.iterator,
3192
- "some",
3193
- "every"
3194
- ].some((e) => Object.hasOwn(i, e))) return !1;
3195
- for (let e = 0; e < i.length; e++) {
3196
- let t = Object.getOwnPropertyDescriptor(i, String(e));
3197
- if (!t || !("value" in t) || typeof t.value != "string") return !1;
3198
- }
3199
- }
3200
- return !0;
3201
- }, la = (e, t, n) => t.scope.length === 0 || (t.mode === "any" ? t.scope.some((t) => n?.has(t) ?? e.includes(t)) : t.scope.every((t) => n?.has(t) ?? e.includes(t))), ua = (e, t) => {
3202
- if (e === void 0) return "unknown";
3203
- if (t.includes("admin:full") || e.length === 0) return "allowed";
3204
- let n = e.length >= 32 && t.length >= 32 && !Object.hasOwn(t, "includes") && !Object.hasOwn(t, Symbol.iterator) && ca(e) ? Zi(t) : void 0, r = !1;
3205
- for (let i of e) if (i.kind !== "open") {
3206
- if (i.kind === "policy") {
3207
- r = !0;
3208
- continue;
3209
- }
3210
- if (!la(t, i, n)) {
3211
- if (i.resourceScoped) {
3212
- r = !0;
3213
- continue;
3214
- }
3215
- return "denied";
3216
- }
3217
- }
3218
- return r ? "unknown" : "allowed";
3219
- }, da = (e) => (e ?? []).flatMap((e) => e.kind === "scope" ? [...e.scope] : []), fa = (e) => {
3220
- for (let t of e ?? []) if (t.kind === "open") return t.reason;
3221
- }, pa = (e) => ua(e, ra().scopes), ma = (e) => e === void 0 ? {} : {
3222
- tag: e.tag,
3223
- ...e.guards === void 0 ? {} : { guards: e.guards }
3224
- }, ha = (e) => {
3225
- let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
3226
- for (let r of e.procedures) if (r.kind === "query") {
3227
- let e = Array.isArray(r.source) ? r.source : [r.source];
3228
- for (let n of e) typeof n == "string" && !t.has(n) && t.set(n, r);
3229
- } else if (r.kind === "mutation") for (let e of r.targets ?? []) {
3230
- let t = n.get(e.table);
3231
- t === void 0 && (t = /* @__PURE__ */ new Map(), n.set(e.table, t)), t.has(e.op) || t.set(e.op, r);
3232
- }
3233
- return e.tables.filter((e) => !e.framework).map((e) => {
3234
- let r = t.get(e.name), i = n.get(e.name), a = i?.get("insert"), o = i?.get("update"), s = i?.get("delete"), c = e.pkColumn ?? (e.columns.some((e) => e.name === "id") ? "id" : void 0);
3235
- return {
3236
- table: e.name,
3237
- columns: e.columns.filter((e) => e.serverOnly !== !0),
3238
- serverOnlyColumns: e.columns.filter((e) => e.serverOnly === !0).map((e) => e.name),
3239
- sensitiveColumns: e.columns.filter((e) => e.sensitive !== void 0).map((e) => e.name),
3240
- reactive: e.reactive,
3241
- ...c === void 0 ? {} : { pkColumn: c },
3242
- editable: (e.editable ?? !0) && c !== void 0,
3243
- list: ma(r),
3244
- create: ma(a),
3245
- update: ma(o),
3246
- delete: ma(s)
3247
- };
3248
- });
3249
- }, ga = (e) => {
3250
- let [t, n] = q([]), [r, i] = q([]), a = U((e) => {
3251
- n((t) => [...t, e]), i([]);
3252
- }, []), o = U(async () => {
3253
- let r = t[t.length - 1];
3254
- r !== void 0 && r.blockedBy === void 0 && (await e.onUndo(r.invocationId), n((e) => e.slice(0, -1)), i((e) => [...e, r]));
3255
- }, [t, e]), s = U(async () => {
3256
- let t = r[r.length - 1];
3257
- t !== void 0 && (await e.onRedo(t.invocationId), i((e) => e.slice(0, -1)), n((e) => [...e, t]));
3258
- }, [r, e]);
3259
- return G(() => {
3260
- let e = t[t.length - 1];
3261
- return {
3262
- record: a,
3263
- undo: o,
3264
- redo: s,
3265
- canUndo: t.length > 0 && e?.blockedBy === void 0,
3266
- canRedo: r.length > 0,
3267
- stack: t,
3268
- nextBlockedBy: e?.blockedBy
3269
- };
3270
- }, [
3271
- t,
3272
- r,
3273
- a,
3274
- o,
3275
- s
3276
- ]);
3277
- }, _a = "__voltro.undo.log", va = "__voltro.undo.apply", ya = "__voltro.undo.redo", ba = (e) => {
3278
- if (e.length < 32 || Object.getPrototypeOf(e) !== Array.prototype || Object.hasOwn(e, "find")) return;
3279
- let t, n;
3280
- for (let r = 0; r < e.length; r += 1) {
3281
- let i = Object.getOwnPropertyDescriptor(e, String(r)), a = i !== void 0 && "value" in i ? i.value : void 0;
3282
- if (typeof a != "object" || !a) return;
3283
- let o = Object.getOwnPropertyDescriptor(a, "undone"), s = Object.getOwnPropertyDescriptor(a, "crossesAction");
3284
- if (o === void 0 || !("value" in o) || typeof o.value != "boolean" || s === void 0 || !("value" in s) || typeof s.value != "boolean") return;
3285
- if (!o.value && !s.value && (t ??= a), o.value && (n ??= a), t !== void 0 && n !== void 0) return r < 32 ? void 0 : {
3286
- nextUndo: t,
3287
- nextRedo: n
3288
- };
3289
- }
3290
- return {
3291
- nextUndo: t,
3292
- nextRedo: n
3293
- };
3294
- }, xa = (e, t) => {
3295
- let n = t?.limit, { data: r } = Z(e, _a, n === void 0 ? {} : { limit: n }), i = er(e, va), a = er(e, ya), o = r ?? [], s = G(() => ba(o), [o]), c = s === void 0 ? o.find((e) => !e.undone && !e.crossesAction) : s.nextUndo, l = s === void 0 ? o.find((e) => e.undone) : s.nextRedo, u = U(async (e) => {
3296
- await i.mutate({ invocationId: e });
3297
- }, [i]), d = U(async (e) => {
3298
- await a.mutate({ invocationId: e });
3299
- }, [a]), f = U(async () => {
3300
- c && await u(c.id);
3301
- }, [c, u]), p = U(async () => {
3302
- l && await d(l.id);
3303
- }, [l, d]);
3304
- return {
3305
- entries: o,
3306
- loading: r === void 0,
3307
- canUndo: c !== void 0,
3308
- canRedo: l !== void 0,
3309
- undo: u,
3310
- redo: d,
3311
- undoLast: f,
3312
- redoLast: p
3313
- };
3314
- }, Sa = (e, t) => ({
3315
- name: e,
3316
- map: t
3317
- }), Ca = (e, t) => e === void 0 ? null : typeof e == "string" ? { event: e } : e(t), wa = /* @__PURE__ */ new Set(["onMount", "onUnmount"]), Ta = (e, t, n) => {
3318
- let r = { ...t };
3319
- for (let [i, a] of Object.entries(e.map)) {
3320
- if (wa.has(i) || a === void 0) continue;
3321
- let e = t[i];
3322
- r[i] = (...r) => {
3323
- let i = Ca(a, t);
3324
- if (i !== null && n(i), typeof e == "function") return e(...r);
3325
- };
3326
- }
3327
- return r;
3328
- }, Ea = (e, t, n) => {
3329
- let r = K({
3330
- spec: e,
3331
- props: t,
3332
- sink: n
3333
- });
3334
- return r.current = {
3335
- spec: e,
3336
- props: t,
3337
- sink: n
3338
- }, W(() => {
3339
- let e = r.current, t = Ca(e.spec.map.onMount, e.props);
3340
- return t !== null && e.sink(t), () => {
3341
- let e = r.current, t = Ca(e.spec.map.onUnmount, e.props);
3342
- t !== null && e.sink(t);
3343
- };
3344
- }, []), G(() => Ta(e, t, n), [
3345
- e,
3346
- t,
3347
- n
3348
- ]);
3349
- }, Da = (e, t) => {
3350
- let n = A(e).descriptors[t]?.input;
3351
- return G(() => n === void 0 ? [] : Ee(n), [n]);
3352
- }, Oa = (e, t) => {
3353
- let n = A(e).descriptors[t]?.output;
3354
- return G(() => n === void 0 ? [] : ae(n), [n]);
3355
- }, ka = (e, t) => {
3356
- if (e === t) return !0;
3357
- if (e.length !== t.length) return !1;
3358
- for (let n = 0; n < e.length; n += 1) if (!Object.is(e[n], t[n])) return !1;
3359
- return !0;
3360
- }, Aa = (e) => Object.keys(e).sort().map((t) => e[t]), ja = (e, t) => {
3361
- let n = K(null), r = n.current, i = Object.keys(e), a = r !== null && ka(r.insertionKeys, i) ? r.names : [...i].sort(), o = a.map((t) => e[t]);
3362
- return r === null || !ka(r.names, a) || !ka(r.key, o) ? n.current = {
3363
- insertionKeys: i,
3364
- names: a,
3365
- key: o,
3366
- value: t(e)
3367
- } : a !== r.names && (n.current = {
3368
- ...r,
3369
- insertionKeys: i,
3370
- names: a
3371
- }), n.current.value;
3372
- }, Ma = (e, t, n, r = {}) => {
3373
- let i = Z(e, t, { ...n }, r);
3374
- return G(() => ({
3375
- allowed: i.data?.allowed === !0,
3376
- pending: i.data === void 0
3377
- }), [i.data]);
3378
- }, Na = (e, t, n, r = {}) => {
3379
- let i = Z(e, t, { ...n }, r);
3380
- return G(() => ({
3381
- allowedIds: new Set(i.data?.allowedIds ?? []),
3382
- pending: i.data === void 0
3383
- }), [i.data]);
3384
- }, Pa = (e) => {
3385
- switch (e) {
3386
- case "select":
3387
- case "radio":
3388
- case "async-select": return "select";
3389
- case "multi-select": return "multi-select";
3390
- case "text":
3391
- case "textarea": return "text";
3392
- case "number": return "number-range";
3393
- case "date":
3394
- case "datetime":
3395
- case "daterange": return "date-range";
3396
- case "checkbox":
3397
- case "switch": return "boolean";
3398
- default: return null;
3399
- }
3400
- }, Fa = (e) => {
3401
- let t = [];
3402
- for (let n of Ee(e)) {
3403
- if (n.name.includes(".")) continue;
3404
- let e = Pa(n.widget);
3405
- e !== null && t.push({
3406
- name: n.name,
3407
- label: n.label,
3408
- kind: e,
3409
- ...n.options ? { options: n.options } : {}
3410
- });
3411
- }
3412
- return t;
3413
- }, Ia = (e) => {
3414
- let t = {};
3415
- for (let [n, r] of Object.entries(e)) r === void 0 || r === "" || Array.isArray(r) && r.length === 0 || (t[n] = r);
3416
- return t;
3417
- }, La = (e, t, n = {}) => {
3418
- let r = A(e).descriptors[t]?.input, i = G(() => r === void 0 ? [] : Fa(r), [r]), [a, o] = q(n.initial ?? {}), s = U((e, t) => {
3419
- o((n) => Ia({
3420
- ...n,
3421
- [e]: t
3422
- }));
3423
- }, []), c = U(() => o({}), []), l = Z(e, t, G(() => Ia(a), [a]));
3424
- return {
3425
- filters: i,
3426
- values: a,
3427
- setFilter: s,
3428
- clear: c,
3429
- rows: l.data ?? [],
3430
- count: l.data?.length,
3431
- loading: l.data === void 0,
3432
- error: l.error
3433
- };
3434
- }, Ra = (e, t, n = {}) => {
3435
- let r = Z(e, t, n), i = r.data;
3436
- return {
3437
- record: Array.isArray(i) ? i[0] : i,
3438
- loading: i === void 0,
3439
- error: r.error
3440
- };
3441
- }, za = (e, t = 300) => {
3442
- let [n, r] = q(e);
3443
- return W(() => {
3444
- let n = setTimeout(() => r(e), t);
3445
- return () => clearTimeout(n);
3446
- }, [e, t]), n;
3447
- }, Ba = (e) => {
3448
- let { value: t, debouncedValue: n, data: r, interpret: i, skipEmpty: a = !0 } = e;
3449
- if (a && t.trim() === "") return {
3450
- status: "idle",
3451
- valid: void 0,
3452
- message: void 0
3453
- };
3454
- if (t !== n || r === void 0) return {
3455
- status: "checking",
3456
- valid: void 0,
3457
- message: void 0
3458
- };
3459
- let o = i(r);
3460
- return {
3461
- status: o.valid ? "valid" : "invalid",
3462
- valid: o.valid,
3463
- message: o.message
3464
- };
3465
- }, Va = (e, t, n, r) => {
3466
- let { input: i, interpret: a, debounceMs: o = 300, skipEmpty: s = !0 } = r, c = za(n, o), l = s && c.trim() === "", u = Z(e, t, G(() => i ? i(c) : { value: c }, [i, c]), { skip: l });
3467
- return Ba({
3468
- value: n,
3469
- debouncedValue: c,
3470
- data: l ? null : u.data,
3471
- interpret: a,
3472
- skipEmpty: s
3473
- });
3474
- }, Ha = (e, t) => ({
3475
- name: e,
3476
- payload: t
3477
- }), Ua = (e, t) => {
3478
- let n = Ve.decodeUnknownResult(e.payload, { errors: "all" })(t);
3479
- if (n._tag === "Success") return {
3480
- valid: !0,
3481
- errors: {}
3482
- };
3483
- let r = {};
3484
- for (let e of He.makeFormatterStandardSchemaV1()(n.failure.issue).issues) r[(e.path ?? []).join(".") || "(root)"] = e.message;
3485
- return {
3486
- valid: !1,
3487
- errors: r
3488
- };
3489
- }, Wa = (e) => {
3490
- let t = new Map(e.map((e) => [e.name, e]));
3491
- return {
3492
- names: [...t.keys()].sort(),
3493
- get: (e) => t.get(e),
3494
- events: e
3495
- };
3496
- }, Ga = (e, t) => {
3497
- let n = Wa(e);
3498
- return {
3499
- track: (e, r) => {
3500
- let i = n.get(e);
3501
- if (i === void 0) {
3502
- process.env.NODE_ENV !== "production" && console.error(`[@voltro/client] analytics.track: unknown event '${e}' (not in the catalog)`);
3503
- return;
3504
- }
3505
- if (process.env.NODE_ENV !== "production") {
3506
- let t = Ua(i, r);
3507
- t.valid || console.error(`[@voltro/client] analytics.track('${e}'): payload failed its schema`, t.errors);
3508
- }
3509
- t({
3510
- event: e,
3511
- ...r
3512
- });
3513
- },
3514
- names: n.names,
3515
- catalog: n
3516
- };
3517
- }, Ka = (e, t) => {
3518
- let n = ar(e, t);
3519
- return {
3520
- preview: U((e) => n.run(e), [n]),
3521
- diff: n.lastResult,
3522
- pending: n.pending,
3523
- error: n.error
3524
- };
3525
- }, qa = () => globalThis.navigator?.onLine !== !1, Ja = (e) => qa() && (g().online(e) ?? !0), Ya = (e) => {
3526
- let t = g().subscribe(e);
3527
- return typeof window > "u" ? t : (window.addEventListener("online", e), window.addEventListener("offline", e), () => {
3528
- t(), window.removeEventListener("online", e), window.removeEventListener("offline", e);
3529
- });
3530
- }, Xa = (e) => {
3531
- let t = U(() => Ja(e), [e]);
3532
- return J(Ya, t, () => !0);
3533
- }, Za = class {
3534
- entries = [];
3535
- positions = /* @__PURE__ */ new Map();
3536
- cursor = 0;
3537
- cached;
3538
- snapshot() {
3539
- return this.cached ??= [...this.entries];
3540
- }
3541
- append(e) {
3542
- let t = this.entries.length;
3543
- this.entries.push(e);
3544
- let n = this.positions.get(e.id);
3545
- n === void 0 ? this.positions.set(e.id, [t]) : n.push(t), this.cached = void 0;
3546
- }
3547
- prepend(e) {
3548
- this.entries = [...e, ...this.entries], this.positions.clear();
3549
- for (let e = 0; e < this.entries.length; e++) {
3550
- let t = this.entries[e].id, n = this.positions.get(t);
3551
- n === void 0 ? this.positions.set(t, [e]) : n.push(e);
3552
- }
3553
- this.cursor = 0, this.cached = void 0;
3554
- }
3555
- reset() {
3556
- this.entries = [], this.positions.clear(), this.cursor = 0, this.cached = void 0;
3557
- }
3558
- update(e, t) {
3559
- for (let n of this.positions.get(e) ?? []) {
3560
- let e = this.entries[n], r = t(e);
3561
- e !== r && (this.entries[n] = r, r.status !== "sent" && n < this.cursor && (this.cursor = n), this.cached = void 0);
3562
- }
3563
- }
3564
- next() {
3565
- for (; this.cursor < this.entries.length;) {
3566
- let e = this.entries[this.cursor];
3567
- if (e.status === "conflict") return;
3568
- if (e.status !== "sent") return e;
3569
- this.cursor++;
3570
- }
3571
- }
3572
- }, Qa = (e, t, n, r, i) => [...e, {
3573
- id: t,
3574
- tag: n,
3575
- input: r,
3576
- status: "pending",
3577
- attempts: 0,
3578
- ...i === void 0 ? {} : { stamp: i }
3579
- }], $a = (e, t, n) => e.map((e) => e.id === t ? {
3580
- ...e,
3581
- ...n
3582
- } : e), eo = (e, t) => $a(e, t, { status: "sent" }), to = (e, t, n) => e.map((e) => e.id === t ? {
3583
- ...e,
3584
- status: "failed",
3585
- error: n,
3586
- attempts: e.attempts + 1
3587
- } : e), no = (e, t, n) => $a(e, t, {
3588
- status: "conflict",
3589
- error: n
3590
- }), ro = (e, t, n) => e.map((e) => e.id === t && e.status === "conflict" ? {
3591
- ...e,
3592
- input: n,
3593
- status: "pending",
3594
- error: void 0
3595
- } : e), io = (e) => e.filter((e) => e.status !== "sent"), ao = (e) => {
3596
- let t = [];
3597
- for (let n of e) {
3598
- if (n.status === "conflict") break;
3599
- (n.status === "pending" || n.status === "failed") && t.push(n);
3600
- }
3601
- return t;
3602
- }, oo = (e) => {
3603
- let t = e;
3604
- return t?.conflict === !0 || t?._tag === "UndoBoundaryError" && t?.boundary === "conflict";
3605
- }, so = (e) => {
3606
- let t = Math.min(3e4, 1e3 * 2 ** Math.max(0, e - 1));
3607
- return t / 2 + t / 2 * Math.random();
3608
- }, co = (e) => {
3609
- let { persistence: t, isConflict: n = oo, idFor: r, api: i } = e;
3610
- if (e.send === void 0 && i === void 0) throw Error("useOutbox: pass `send`, or `api` to send through that api's own mutations.");
3611
- let a = je(I), o = a?.demand;
3612
- W(() => {
3613
- i !== void 0 && o?.(i);
3614
- }, [o, i]);
3615
- let s = i === void 0 || a === null ? void 0 : a.get(i), l = K(s);
3616
- l.current = s;
3617
- let [u, d] = q(0), [f, p] = q(0), m = Xa(i), h = e.online ?? m, g = K(void 0);
3618
- g.current === void 0 && (g.current = new Za());
3619
- let _ = G(() => g.current.snapshot(), [u]), y = U((e) => {
3620
- e(g.current), d((e) => e + 1);
3621
- }, []), b = K(e.retryDelay ?? so);
3622
- b.current = e.retryDelay ?? so;
3623
- let x = K(e.stamp);
3624
- x.current = e.stamp;
3625
- let C = K(async () => void 0);
3626
- C.current = e.send ?? (async (e) => {
3627
- if (l.current === void 0) throw Error(`useOutbox: no mounted api '${i}' — render it inside the framework's runtime provider.`);
3628
- let t = await P(l, i, e.tag), n = v(t.client, e.tag);
3629
- await S(t.runtime, B(n(e.input), e.id));
3630
- });
3631
- let w = K(n);
3632
- w.current = n;
3633
- let T = K(void 0), E = K(!1), D = K(!0);
3634
- W(() => (D.current = !0, () => {
3635
- D.current = !1;
3636
- }), []);
3637
- let O = K(0), k = K(Math.random().toString(36).slice(2, 8)), A = K(t === void 0), [j, M] = q(0), N = s === void 0 ? void 0 : s.recovery ?? c(s.errorBus, i);
3638
- W(() => {
3639
- if (N === void 0) return;
3640
- let e = N.subjectSignal;
3641
- if (e.aborted) return;
3642
- let n = () => {
3643
- g.current.reset(), d((e) => e + 1), A.current = t === void 0, E.current = !1, M((e) => e + 1);
3644
- };
3645
- return e.addEventListener("abort", n, { once: !0 }), () => {
3646
- e.removeEventListener("abort", n);
3647
- };
3648
- }, [
3649
- N,
3650
- t,
3651
- j
3652
- ]), W(() => {
3653
- if (t === void 0) return;
3654
- let e = !1;
3655
- return A.current = !1, t.load().then((t) => {
3656
- e || (A.current = !0, t.length > 0 && y((e) => e.prepend(t)), p((e) => e + 1));
3657
- }, () => {
3658
- e || (A.current = !0, p((e) => e + 1));
3659
- }), () => {
3660
- e = !0;
3661
- };
3662
- }, [
3663
- t,
3664
- y,
3665
- j
3666
- ]), W(() => {
3667
- t !== void 0 && A.current && t.save(io(_)).catch(() => {});
3668
- }, [
3669
- t,
3670
- _,
3671
- f
3672
- ]);
3673
- let L = K(/* @__PURE__ */ new Set()), R = s === void 0 || F(s) ? void 0 : s.cache;
3674
- W(() => {
3675
- if (R !== void 0 && s !== void 0) for (let e of _) {
3676
- let t = s.descriptors[e.tag]?.targets;
3677
- if (e.status === "pending" || e.status === "failed") {
3678
- if (L.current.delete(e.id), t === void 0 || t.length === 0 || R.hasIntent(e.id) || typeof e.input != "object" || e.input === null) continue;
3679
- R.autoApply(t, e.input, e.id, { standing: !0 });
3680
- } else L.current.has(e.id) || (L.current.add(e.id), e.status === "sent" ? R.confirmByMutation(e.id) : R.revertByMutation(e.id));
3681
- }
3682
- }, [
3683
- R,
3684
- s,
3685
- _
3686
- ]);
3687
- let ee = U((e, t) => {
3688
- let n = r?.() ?? `obx_${k.current}_${O.current++}_${e}`;
3689
- y((r) => r.append({
3690
- id: n,
3691
- tag: e,
3692
- input: t,
3693
- status: "pending",
3694
- attempts: 0,
3695
- ...x.current === void 0 ? {} : { stamp: x.current() }
3696
- })), p((e) => e + 1);
3697
- }, [r, y]), te = K(void 0), z = U(() => {
3698
- te.current !== void 0 && clearTimeout(te.current), te.current = void 0;
3699
- }, []);
3700
- W(() => z, [z]);
3701
- let V = U(() => {
3702
- if (!A.current || !D.current) return Promise.resolve();
3703
- if (T.current !== void 0) return T.current;
3704
- E.current = !1, z();
3705
- let e = Promise.resolve().then(async () => {
3706
- for (; D.current;) {
3707
- let e = g.current.next();
3708
- if (e === void 0) break;
3709
- try {
3710
- if (await C.current(e), !D.current) break;
3711
- y((t) => t.update(e.id, (e) => ({
3712
- ...e,
3713
- status: "sent"
3714
- })));
3715
- } catch (t) {
3716
- if (!D.current) break;
3717
- let n = w.current(t);
3718
- y((r) => r.update(e.id, (e) => n ? {
3719
- ...e,
3720
- status: "conflict",
3721
- error: t
3722
- } : {
3723
- ...e,
3724
- status: "failed",
3725
- error: t,
3726
- attempts: e.attempts + 1
3727
- })), E.current = !0, n || (te.current = setTimeout(() => {
3728
- te.current = void 0, ne.current();
3729
- }, b.current(e.attempts + 1)));
3730
- break;
3731
- }
3732
- }
3733
- }).finally(() => {
3734
- T.current === e && (T.current = void 0);
3735
- });
3736
- return T.current = e, e;
3737
- }, [y, z]), ne = K(V);
3738
- ne.current = V, W(() => {
3739
- h ? V() : z();
3740
- }, [
3741
- h,
3742
- V,
3743
- z
3744
- ]), W(() => {
3745
- h && !E.current && V();
3746
- }, [
3747
- f,
3748
- h,
3749
- V
3750
- ]);
3751
- let H = U((e, t) => {
3752
- y((n) => n.update(e, (e) => e.status === "conflict" ? {
3753
- ...e,
3754
- input: t,
3755
- status: "pending",
3756
- error: void 0
3757
- } : e)), h && V();
3758
- }, [
3759
- h,
3760
- V,
3761
- y
3762
- ]);
3763
- return {
3764
- queue: _,
3765
- enqueue: ee,
3766
- replay: V,
3767
- online: h,
3768
- pending: _.reduce((e, t) => e + +(t.status === "pending" || t.status === "failed"), 0),
3769
- conflicts: _.filter((e) => e.status === "conflict"),
3770
- resolveConflict: H
3771
- };
3772
- }, lo = (e) => {
3773
- let t = e;
3774
- return t?.conflict === !0 || t?._tag === "UndoBoundaryError" && t?.boundary === "conflict";
3775
- }, uo = (e) => {
3776
- let t = (Array.isArray(e) ? e : [e]).filter((e) => typeof e == "object" && !!e);
3777
- for (let e of t) {
3778
- if (e._tag === "Chunk") {
3779
- for (let t of e.values ?? []) if (t._tag === "error") return {
3780
- ok: !1,
3781
- error: t.error
3782
- };
3783
- }
3784
- if (e._tag === "Exit" && e.exit?._tag === "Failure") return {
3785
- ok: !1,
3786
- error: e.exit.cause
3787
- };
3788
- }
3789
- return { ok: !0 };
3790
- }, fo = async (e) => {
3791
- let t = e.fetch ?? ((e, t) => fetch(e, t)), n = e.isConflict ?? lo, r = e.queue, i = 0, a = 0, o = 0;
3792
- for (let s of ao(e.queue)) {
3793
- let c;
3794
- try {
3795
- let n = await t(e.url, {
3796
- method: "POST",
3797
- headers: {
3798
- "content-type": "application/json",
3799
- ...e.headers
3800
- },
3801
- body: JSON.stringify({
3802
- _tag: "Request",
3803
- id: s.id,
3804
- tag: s.tag,
3805
- payload: s.input,
3806
- headers: [["idempotency-key", s.id]]
3807
- })
3808
- });
3809
- c = n.ok ? uo(await n.json().catch(() => null)) : {
3810
- ok: !1,
3811
- error: { status: n.status }
3812
- };
3813
- } catch (e) {
3814
- c = {
3815
- ok: !1,
3816
- error: e
3817
- };
3818
- }
3819
- if (c.ok) {
3820
- r = eo(r, s.id), i++;
3821
- continue;
3822
- }
3823
- if (n(c.error)) {
3824
- r = no(r, s.id, c.error), o++;
3825
- continue;
3826
- }
3827
- r = to(r, s.id, c.error), a++;
3828
- break;
3829
- }
3830
- return {
3831
- queue: r,
3832
- sent: i,
3833
- failed: a,
3834
- conflicts: o
3835
- };
3836
- }, po = "voltro-outbox", mo = "outbox", ho = "queue", go = (e, t) => new Promise((n, r) => {
3837
- let i = e.open(t, 1);
3838
- i.onupgradeneeded = () => {
3839
- i.result.objectStoreNames.contains(mo) || i.result.createObjectStore(mo);
3840
- }, i.onsuccess = () => n(i.result), i.onerror = () => r(i.error ?? /* @__PURE__ */ Error("indexedDB open failed"));
3841
- }), _o = (e) => new Promise((t, n) => {
3842
- e.onsuccess = () => t(e.result), e.onerror = () => n(e.error ?? /* @__PURE__ */ Error("indexedDB request failed"));
3843
- }), vo = (e = {}) => {
3844
- let t = e.name ?? "voltro-outbox", n = () => {
3845
- let t = e.indexedDB ?? globalThis.indexedDB;
3846
- if (t === void 0) throw Error("indexedDbOutboxPersistence: no indexedDB in this environment");
3847
- return t;
3848
- };
3849
- return {
3850
- load: async () => {
3851
- let e = await go(n(), t);
3852
- try {
3853
- let t = await _o(e.transaction(mo, "readonly").objectStore(mo).get(ho));
3854
- return Array.isArray(t) ? t : [];
3855
- } finally {
3856
- e.close();
3857
- }
3858
- },
3859
- save: async (e) => {
3860
- let r = await go(n(), t);
3861
- try {
3862
- await _o(r.transaction(mo, "readwrite").objectStore(mo).put(e, ho));
3863
- } finally {
3864
- r.close();
3865
- }
3866
- }
3867
- };
3868
- }, yo = "voltro:outbox", bo = async (e) => {
3869
- let t = e.persistence ?? vo(), n = await t.load(), r = await fo({
3870
- url: e.url,
3871
- queue: n,
3872
- ...e.headers ? { headers: e.headers } : {}
3873
- });
3874
- return r.sent + r.failed + r.conflicts > 0 && await t.save(r.queue), r;
3875
- }, xo = (e) => {
3876
- let { scrollTop: t, viewportHeight: n, rowHeight: r, overscan: i = 5, total: a } = e, o = r > 0 ? r : 1, s = Math.max(0, Math.floor(t / o)), c = Math.ceil(n / o), l = Math.max(0, s - i), u = s + c + i, d = a === void 0 ? u : Math.min(u, a);
3877
- return {
3878
- startIndex: l,
3879
- endIndex: d,
3880
- offset: l,
3881
- limit: Math.max(0, d - l),
3882
- topSpacer: l * r,
3883
- bottomSpacer: a === void 0 ? 0 : Math.max(0, (a - d) * r)
3884
- };
3885
- }, So = (e, t, n) => {
3886
- let { rowHeight: r, viewportHeight: i, overscan: a, total: o, input: s } = n, [c, l] = q(0), u = K(0), d = G(() => xo({
3887
- scrollTop: u.current,
3888
- viewportHeight: i,
3889
- rowHeight: r,
3890
- ...a === void 0 ? {} : { overscan: a },
3891
- ...o === void 0 ? {} : { total: o }
3892
- }), [
3893
- c,
3894
- i,
3895
- r,
3896
- a,
3897
- o
3898
- ]), f = Z(e, t, G(() => ({
3899
- ...s,
3900
- offset: d.offset,
3901
- limit: d.limit
3902
- }), [
3903
- s,
3904
- d.offset,
3905
- d.limit
3906
- ])), p = K(d);
3907
- p.current = d;
3908
- let m = U((e) => {
3909
- let t = e.currentTarget.scrollTop;
3910
- u.current = t;
3911
- let n = xo({
3912
- scrollTop: t,
3913
- viewportHeight: i,
3914
- rowHeight: r,
3915
- ...a === void 0 ? {} : { overscan: a },
3916
- ...o === void 0 ? {} : { total: o }
3917
- }), s = p.current;
3918
- (n.offset !== s.offset || n.limit !== s.limit || n.topSpacer !== s.topSpacer || n.bottomSpacer !== s.bottomSpacer) && (p.current = n, l(t));
3919
- }, [
3920
- i,
3921
- r,
3922
- a,
3923
- o
3924
- ]);
3925
- return {
3926
- rows: f.data ?? [],
3927
- window: d,
3928
- onScroll: m,
3929
- topSpacer: d.topSpacer,
3930
- bottomSpacer: d.bottomSpacer,
3931
- loading: f.data === void 0,
3932
- error: f.error
3933
- };
3934
- }, Co = () => typeof navigator > "u" || navigator.onLine, wo = () => !0, To = (e) => typeof window > "u" ? () => {} : (window.addEventListener("online", e), window.addEventListener("offline", e), () => {
3935
- window.removeEventListener("online", e), window.removeEventListener("offline", e);
3936
- }), Eo = (e) => {
3937
- let t = A(e), n = t.recovery ?? c(t.errorBus, e), r = J(n.subscribe, n.getSnapshot, n.getServerSnapshot ?? (() => x)), i = J(To, Co, wo), o = U(() => n.reportExternalSuccess(), [n]), s = i ? r.status : "offline";
3938
- return W(() => {
3939
- a(e, "connection.status", {
3940
- status: s,
3941
- rawTransport: r.rawTransport,
3942
- online: i,
3943
- failureCount: r.failureCount,
3944
- failedSubscriptions: r.failedSubscriptions.length,
3945
- pendingMutationReplays: r.pendingMutationReplays,
3946
- mutationReplay: r.mutationReplay
3947
- });
3948
- }, [
3949
- e,
3950
- s,
3951
- i,
3952
- r
3953
- ]), {
3954
- status: s,
3955
- rawTransport: r.rawTransport,
3956
- online: i,
3957
- failureCount: r.failureCount,
3958
- lastFailureAt: r.lastFailureAt,
3959
- failedSubscriptions: r.failedSubscriptions,
3960
- pendingMutationReplays: r.pendingMutationReplays,
3961
- mutationReplay: r.mutationReplay,
3962
- reportSuccess: o
3963
- };
3964
- }, Do = (e, t) => e === t ? 0 : e == null ? 1 : t == null ? -1 : e instanceof Date && t instanceof Date ? e.getTime() - t.getTime() : typeof e == "number" && typeof t == "number" ? e - t : String(e).localeCompare(String(t)), Oo = (e, t = {}) => {
3965
- let n = t.limit === void 0 ? void 0 : Math.max(0, Math.trunc(t.limit));
3966
- if (n === 0 || Number.isNaN(n)) return [];
3967
- let r = t.where === void 0 ? [...e] : e.filter(t.where), i = t.orderBy;
3968
- if (i !== void 0) {
3969
- let e = typeof i == "function" ? i : typeof i == "string" ? (e, t) => Do(e[i], t[i]) : (e, t) => {
3970
- let [n, r] = typeof i == "string" ? [i, "asc"] : i, a = Do(e[n], t[n]);
3971
- return r === "desc" ? -a : a;
3972
- };
3973
- if (n !== void 0 && Number.isFinite(n) && n < r.length / 2) {
3974
- let t = (t, n) => {
3975
- let r = t.row === void 0 ? n.row === void 0 ? 0 : 1 : n.row === void 0 ? -1 : e(t.row, n.row);
3976
- return (Number.isNaN(r) ? 0 : r) || t.index - n.index;
3977
- }, i = [], a = () => {
3978
- let e = 0;
3979
- for (;;) {
3980
- let n = e * 2 + 1, r = n + 1;
3981
- if (n >= i.length) return;
3982
- let a = r < i.length && t(i[r], i[n]) > 0 ? r : n;
3983
- if (t(i[e], i[a]) >= 0) return;
3984
- [i[e], i[a]] = [i[a], i[e]], e = a;
3985
- }
3986
- };
3987
- for (let e = 0; e < r.length; e++) {
3988
- let o = {
3989
- row: r[e],
3990
- index: e
3991
- };
3992
- if (i.length < n) {
3993
- i.push(o);
3994
- let e = i.length - 1;
3995
- for (; e > 0;) {
3996
- let n = e - 1 >> 1;
3997
- if (t(i[n], i[e]) >= 0) break;
3998
- [i[n], i[e]] = [i[e], i[n]], e = n;
3999
- }
4000
- } else t(o, i[0]) < 0 && (i[0] = o, a());
4001
- }
4002
- return i.sort(t).map((e) => e.row);
4003
- }
4004
- r = r.sort(e);
4005
- }
4006
- return t.limit === void 0 ? r : r.slice(0, Math.max(0, t.limit));
4007
- }, ko = (e, t, n = {}) => {
4008
- let { cache: r } = A(e), i = J(U((e) => r.subscribeTable(t, e), [r, t]), U(() => r.rowsOf(t), [r, t]), () => Ao), a = K(n);
4009
- a.current = n;
4010
- let { where: o, orderBy: s, limit: c } = n;
4011
- return G(() => Oo(i, a.current), [
4012
- i,
4013
- o,
4014
- s,
4015
- c
4016
- ]);
4017
- }, Ao = [], jo = "__voltro.connections.list", Mo = "__voltro.connections.start", No = "__voltro.connections.submitToken", Po = "__voltro.connections.disconnect", Fo = {
4018
- connectionId: "",
4019
- kind: "oauth2",
4020
- label: "",
4021
- status: "disconnected",
4022
- accountId: null,
4023
- accountLabel: null,
4024
- scopes: [],
4025
- expiresAt: null,
4026
- lastError: null,
4027
- connectedAt: null
4028
- }, Io = (e, t) => {
4029
- if (t === "redirect") {
4030
- globalThis.location.assign(e);
4031
- return;
4032
- }
4033
- globalThis.open(e, "voltro-connect", "width=620,height=760,menubar=no,toolbar=no") === null && globalThis.location.assign(e);
4034
- }, Lo = (e) => {
4035
- if (e.length < 32 || Object.getPrototypeOf(e) !== Array.prototype || Object.hasOwn(e, "find")) return;
4036
- let t = /* @__PURE__ */ new Map();
4037
- for (let n = 0; n < e.length; n += 1) {
4038
- let r = Object.getOwnPropertyDescriptor(e, String(n)), i = r !== void 0 && "value" in r ? r.value : void 0;
4039
- if (typeof i != "object" || !i) return;
4040
- let a = Object.getOwnPropertyDescriptor(i, "connectionId");
4041
- if (a === void 0 || !("value" in a) || typeof a.value != "string") return;
4042
- t.has(a.value) || t.set(a.value, i);
4043
- }
4044
- return t;
4045
- }, Ro = (e) => {
4046
- let { data: t } = Z(e, jo, {}), n = ar(e, Mo), r = er(e, No), i = er(e, Po), a = t ?? [], o = G(() => ({
4047
- calls: 0,
4048
- byId: void 0
4049
- }), [a]), s = n.pending || r.pending || i.pending, c = U((e) => ({
4050
- ...e,
4051
- connected: e.status === "connected",
4052
- needsAttention: e.status === "expired" || e.status === "revoked" || e.status === "error",
4053
- pending: s,
4054
- connect: async (t) => {
4055
- if (e.kind !== "oauth2") throw Error(`connection "${e.connectionId}" is a personal-access-token connection — call submitToken(token), not connect().`);
4056
- let r = t?.redirectTo ?? `${globalThis.location.pathname}${globalThis.location.search}`;
4057
- Io((await n.run({
4058
- connectionId: e.connectionId,
4059
- redirectTo: r
4060
- })).authorizeUrl, t?.mode);
4061
- },
4062
- submitToken: async (t) => {
4063
- if (e.kind !== "pat") throw Error(`connection "${e.connectionId}" uses OAuth — call connect(), not submitToken().`);
4064
- await r.mutate({
4065
- connectionId: e.connectionId,
4066
- token: t
4067
- });
4068
- },
4069
- disconnect: async () => {
4070
- await i.mutate({ connectionId: e.connectionId });
4071
- }
4072
- }), [
4073
- s,
4074
- n,
4075
- r,
4076
- i
4077
- ]), l = U((e) => {
4078
- o.calls === 4 && (o.byId = Lo(a)), o.calls <= 4 && (o.calls += 1);
4079
- let t = o.byId === void 0 ? a.find((t) => t.connectionId === e) : o.byId.get(e);
4080
- return t === void 0 ? void 0 : c(t);
4081
- }, [
4082
- o,
4083
- a,
4084
- c
4085
- ]);
4086
- return {
4087
- connections: a,
4088
- loading: t === void 0,
4089
- get: l,
4090
- pending: s
4091
- };
4092
- }, zo = (e, t) => {
4093
- let n = Ro(e), r = n.get(t);
4094
- return G(() => r === void 0 ? {
4095
- ...Fo,
4096
- connectionId: t,
4097
- label: t,
4098
- connected: !1,
4099
- needsAttention: !1,
4100
- pending: n.pending,
4101
- loading: n.loading,
4102
- connect: async () => {
4103
- throw Error(`connection "${t}" is not declared by this app.`);
4104
- },
4105
- submitToken: async () => {
4106
- throw Error(`connection "${t}" is not declared by this app.`);
4107
- },
4108
- disconnect: async () => {
4109
- throw Error(`connection "${t}" is not declared by this app.`);
4110
- }
4111
- } : {
4112
- ...r,
4113
- loading: n.loading
4114
- }, [
4115
- r,
4116
- t,
4117
- n.loading,
4118
- n.pending
4119
- ]);
4120
- }, Bo = "framework-client";
4121
- //#endregion
4122
- export { Qi as ADMIN_SCOPE, Bo as CLIENT_NAME, jo as CONNECTIONS_LIST_TAG, Po as CONNECTION_DISCONNECT_TAG, Mo as CONNECTION_START_TAG, No as CONNECTION_SUBMIT_TOKEN_TAG, Ce as FORM_FLASH_SCRIPT_ID, ve as FORM_KEY_FIELD, xe as FORM_PATH_PREFIX, he as FORM_REDIRECT_FIELD, Cr as FormBindingProvider, I as FrameworkRuntimesContext, st as FrameworkRuntimesProvider, x as INITIAL_RECOVERY_SNAPSHOT, _ as LoadingSubscriptionCache, Hn as MutationSerialExecutionError, po as OUTBOX_DB_NAME, yo as OUTBOX_SYNC_TAG, We as PAIRING_HOST, Ge as PAIRING_SCHEME, Ke as PAIRING_STORAGE_KEY, na as PermissionProvider, Se as RICH_TEXT_MARKS, ue as RICH_TEXT_MAX_NODES, m as RecoveryCoordinator, ge as RichTextDocument, C as RpcErrorBus, Li as ServerRequestContext, zi as ServerRequestProvider, p as SubscriptionCache, va as UNDO_APPLY_TAG, _a as UNDO_LOG_TAG, ya as UNDO_REDO_TAG, cr as ValidationMessagesProvider, M as _resetFrameworkRuntimesWarning, O as _resetSsrDescriptors, g as apiConnectivity, qe as applyPairing, Br as applyPreloadSeeds, Jt as applyStoreSeeds, Yt as browserOnlineSource, on as browserPlatform, ut as browserStoreStorage, ne as buildApiRuntime, $i as canCall, ea as canCallAny, Xt as capabilitiesOf, w as clearClientDiagnostics, Fn as clearMutations, Je as clearPairing, io as clearSent, Ot as clearStoreHistory, D as clientDiagnosticsSnapshot, xo as computeWindow, Ga as createAnalytics, Mr as createHooks, un as currentPlatform, ua as decideAccess, pe as decodeFieldIssues, bn as deepLinkHref, so as defaultOutboxRetryDelay, gn as defineDeepLink, Ha as defineEvent, Zt as definePlatform, Ut as defineStore, Sa as defineTracking, Ht as definedStores, ha as deriveEntityAdmins, l as disableClientDiagnosticsPersistence, Sn as dispatchDeepLink, se as documentLocale, bo as drainOutboxInWorker, fo as drainOutboxOverHttp, we as emptyRichTextDocument, E as enableClientDiagnosticsPersistence, Qa as enqueueEntry, Ye as errorMessage, Xe as errorTag, Wa as eventCatalog, Fa as filtersFromSchema, ce as formActionPath, ye as formDataToInput, De as formField, oe as formSections, H as freshIdempotencyKey, Yn as getMutationNotifier, Nn as getMutations, or as globalContext, vo as indexedDbOutboxPersistence, ln as installPlatform, dn as isPlatformInstalled, de as isRichTextDocument, fe as isSafeHref, rn as isStandaloneDisplay, ie as isUnauthenticated, F as isUnresolvedApi, Qe as jsonSchemaDocumentOf, $e as jsonSchemaOf, Nr as makePreloadSeedBag, re as makeProtocolOpenRecovery, Gt as makeStoreSeedBag, oa as manifestUrl, no as markConflict, to as markFailed, eo as markSent, vn as matchDeepLink, xn as matchFirstDeepLink, $t as memoryTokenStore, fa as openAccessReason, et as pairingLink, tt as parsePairingLink, be as parseRichText, Yi as provenanceUrl, u as publishClientError, r as publishClientTrace, R as queryOnce, Ja as readApiOnline, rt as readPairing, Hr as readPreloadedSeedOutcome, Vr as readPreloadedSnapshot, a as recordClientDiagnostic, c as recoveryCoordinatorFor, Qt as refusingTokenStore, h as registerCellMerger, L as registerSsrDescriptors, e as registeredCellMerger, ao as replayable, d as reportClientError, da as requiredScopes, fn as resetPlatformForTest, Ur as resetPreloadSeeds, Wt as resetStoreRegistryForTests, pt as resetStoreStorageForTest, v as resolveByTag, ro as resolveConflictEntry, y as resolveRecoveryOptions, ft as resolveStoreStorage, Ca as resolveTrackingEvent, Te as resolveValidationMessage, Oe as restrictToSchema, Ci as resumableConsumeProgram, _e as richTextToPlainText, Vi as rowsToOptions, uo as rpcHttpOutcome, yn as runDeepLink, Oo as runLocalQuery, Yr as runSequence, ae as schemaToColumns, Ee as schemaToFields, Rr as seedPreloadedSubscription, zr as seedPreloadedSubscriptionFailure, qt as seedStore, Jr as sequence, me as serializeRichText, Jn as setMutationNotifier, Fr as setPreloadSeedResolver, Kt as setStoreSeedResolver, dt as setStoreStorage, Mn as settleMutation, mt as shallow, ka as shallowArrayEqual, Aa as sourceValues, k as ssrClientProxy, N as ssrDescriptorsFor, ee as ssrStubHandle, f as stableKey, te as startApiSupervisor, jn as startMutation, Et as storeHistory, Ya as subscribeApiOnline, t as subscribeClientDiagnostics, b as subscribeClientErrors, n as subscribeClientTraces, Pn as subscribeMutations, Dt as subscribeStoreHistory, s as supersedesConfirmedPatches, kt as travelToStoreState, pa as useAccessDecision, ar as useAction, ki as useAgent, Oi as useAgentChat, Si as useAgentStream, Xa as useApiOnline, Va as useAsyncValidation, ia as useCan, aa as useCanAny, sa as useCapabilityManifest, zo as useConnection, Ar as useConnectionSetup, Eo as useConnectionStatus, Ro as useConnections, Ai as useDataCopilot, qi as useDataTable, za as useDebounced, ja as useDerived, qr as useEvent, br as useFormBinding, wr as useFormBindingContext, Tr as useFormField, Bi as useFormFlash, Da as useFormSkeleton, A as useFrameworkApi, j as useFrameworkRuntimes, ko as useLocalQuery, er as useMutation, Pi as useOnRawRpcError, Ni as useOnRpcError, co as useOutbox, ra as usePermissions, mn as usePlatform, Wr as usePreloadedSubscription, Ka as usePreview, Xi as useProvenance, Ui as useQueryField, La as useQueryFilters, Ra as useRecord, Mi as useRefreshSubscription, ji as useRefreshSubscriptions, Ma as useResourceCan, Na as useResourceCans, Ti as useResumableAgentStream, xr as useSchemaFormBinding, Xr as useSequence, Ri as useServerRequest, hn as useShellExtension, Z as useSubscription, Ii as useSubscriptionHealth, Oa as useTableSkeleton, Ea as useTracking, ii as useTranscription, ga as useUndo, xa as useUndoLog, ri as useUpload, lr as useValidationMessages, So as useWindowedSubscription, oi as useWorkflow, mi as useWorkflowDomainEvents, hi as useWorkflowEventDeliveries, pi as useWorkflowEvents, li as useWorkflowRun, fi as useWorkflowRunEvents, xi as useWorkflowRunState, di as useWorkflowRunSteps, ui as useWorkflowRuns, si as useWorkflowSignal, ci as useWorkflowUpdate, Ua as validateEventPayload, le as validateFields, Ba as validationStatus, V as wireAuthRefresh, B as withIdempotencyKey, Ta as wrapTrackedCallbacks };
88
+ export { bn as ADMIN_SCOPE, Zr as CLIENT_NAME, Ar as CONNECTIONS_LIST_TAG, jr as CONNECTION_DISCONNECT_TAG, Mr as CONNECTION_START_TAG, Nr as CONNECTION_SUBMIT_TOKEN_TAG, Rr as DEV_ACTIVITY_EVENT, tt as FORM_CAPTURE_FIELD, nt as FORM_CAPTURE_META_NAME, et as FORM_FLASH_SCRIPT_ID, rt as FORM_KEY_FIELD, it as FORM_PATH_PREFIX, at as FORM_REDIRECT_FIELD, ot as FORM_SOURCE_FIELD, yt as FormBindingProvider, w as FrameworkRuntimesContext, z as FrameworkRuntimesProvider, y as INITIAL_RECOVERY_SNAPSHOT, d as LoadingSubscriptionCache, ke as MutationSerialExecutionError, yr as OUTBOX_DB_NAME, br as OUTBOX_SYNC_TAG, zr as PAIRING_HOST, Br as PAIRING_SCHEME, Vr as PAIRING_STORAGE_KEY, xn as PermissionProvider, Ge as RICH_TEXT_MARKS, Ke as RICH_TEXT_MAX_NODES, b as RecoveryCoordinator, qe as RichTextDocument, _ as RpcErrorBus, mt as ServerRequestContext, ht as ServerRequestProvider, f as SubscriptionCache, Fn as UNDO_APPLY_TAG, In as UNDO_LOG_TAG, Ln as UNDO_REDO_TAG, Ue as ValidationMessagesProvider, D as _resetFrameworkRuntimesWarning, O as _resetSsrDescriptors, v as apiConnectivity, Hr as applyPairing, Et as applyPreloadSeeds, W as applyStoreSeeds, ne as browserOnlineSource, re as browserPlatform, B as browserStoreStorage, I as buildApiRuntime, Sn as canCall, Cn as canCallAny, ie as capabilitiesOf, i as clearClientDiagnostics, Se as clearMutations, Ur as clearPairing, ur as clearSent, G as clearStoreHistory, a as clientDiagnosticsSnapshot, Tr as computeWindow, nr as createAnalytics, Tt as createHooks, ae as currentPlatform, Dn as decideAccess, Re as decodeFieldIssues, he as deepLinkHref, dr as defaultOutboxRetryDelay, ge as defineDeepLink, rr as defineEvent, oe as definePlatform, K as defineStore, zn as defineTracking, q as definedStores, On as deriveEntityAdmins, o as disableClientDiagnosticsPersistence, _e as dispatchDeepLink, ze as documentLocale, xr as drainOutboxInWorker, Sr as drainOutboxOverHttp, Je as emptyRichTextDocument, s as enableClientDiagnosticsPersistence, mn as encodeFormRejection, st as encodeNativeFormCapture, fr as enqueueEntry, Wr as errorMessage, Gr as errorTag, ir as eventCatalog, Xn as filtersFromSchema, ct as formActionPath, lt as formCaptureSource, ft as formDataToInput, Pe as formField, Fe as formSections, ut as formSourcePath, De as freshIdempotencyKey, Ae as getMutationNotifier, Ce as getMutations, C as globalContext, Cr as indexedDbOutboxPersistence, se as installPlatform, ce as isPlatformInstalled, Ye as isRichTextDocument, Xe as isSafeHref, le as isStandaloneDisplay, ln as isUnauthenticated, T as isUnresolvedApi, Kr as jsonSchemaDocumentOf, qr as jsonSchemaOf, Ir as makeApiRoleSocketTracker, Lr as makeApiSocketTracker, Dt as makePreloadSeedBag, L as makeProtocolOpenRecovery, J as makeStoreSeedBag, kn as manifestUrl, pr as markConflict, mr as markFailed, hr as markSent, ve as matchDeepLink, ye as matchFirstDeepLink, ue as memoryTokenStore, An as openAccessReason, Jr as pairingLink, Yr as parsePairingLink, Ze as parseRichText, vn as provenanceUrl, m as publishClientError, n as publishClientTrace, cn as queryOnce, sr as readApiOnline, dt as readFormCaptureSource, Xr as readPairing, Ot as readPreloadedSeedOutcome, kt as readPreloadedSnapshot, c as recordClientDiagnostic, pt as recoverNativeFormValues, x as recoveryCoordinatorFor, de as refusingTokenStore, e as registerCellMerger, k as registerSsrDescriptors, t as registeredCellMerger, gr as replayable, h as reportClientError, jn as requiredScopes, fe as resetPlatformForTest, At as resetPreloadSeeds, Y as resetStoreRegistryForTests, V as resetStoreStorageForTest, F as resolveByTag, _r as resolveConflictEntry, S as resolveRecoveryOptions, H as resolveStoreStorage, Bn as resolveTrackingEvent, Be as resolveValidationMessage, Ve as restrictToSchema, en as resumableConsumeProgram, Qe as richTextToPlainText, hn as rowsToOptions, wr as rpcHttpOutcome, be as runDeepLink, Or as runLocalQuery, It as runSequence, Ie as schemaToColumns, Le as schemaToFields, jt as seedPreloadedSubscription, Mt as seedPreloadedSubscriptionFailure, X as seedStore, Lt as sequence, $e as serializeRichText, je as setMutationNotifier, Nt as setPreloadSeedResolver, Z as setStoreSeedResolver, U as setStoreStorage, we as settleMutation, Q as shallow, Gn as shallowArrayEqual, Kn as sourceValues, A as ssrClientProxy, j as ssrDescriptorsFor, M as ssrStubHandle, u as stableKey, R as startApiSupervisor, Te as startMutation, $ as storeHistory, cr as subscribeApiOnline, l as subscribeClientDiagnostics, g as subscribeClientErrors, r as subscribeClientTraces, Ee as subscribeMutations, ee as subscribeStoreHistory, p as supersedesConfirmedPatches, te as travelToStoreState, E as unknownApiError, Mn as useAccessDecision, Ne as useAction, rn as useAgent, nn as useAgentChat, $t as useAgentStream, lr as useApiOnline, $n as useAsyncValidation, wn as useCan, Tn as useCanAny, Nn as useCapabilityManifest, Pr as useConnection, wt as useConnectionSetup, Dr as useConnectionStatus, Fr as useConnections, an as useDataCopilot, _n as useDataTable, er as useDebounced, qn as useDerived, Ft as useEvent, bt as useFormBinding, xt as useFormBindingContext, gt as useFormCapture, St as useFormField, _t as useFormFlash, Un as useFormSkeleton, N as useFrameworkApi, P as useFrameworkRuntimes, kr as useLocalQuery, Me as useMutation, dn as useOnRawRpcError, fn as useOnRpcError, vr as useOutbox, En as usePermissions, pe as usePlatform, Pt as usePreloadedSubscription, or as usePreview, yn as useProvenance, gn as useQueryField, Zn as useQueryFilters, Qn as useRecord, on as useRefreshSubscription, sn as useRefreshSubscriptions, Jn as useResourceCan, Yn as useResourceCans, tn as useResumableAgentStream, zt as useRpcCaller, Ct as useSchemaFormBinding, Rt as useSequence, vt as useServerRequest, me as useShellExtension, xe as useSubscription, pn as useSubscriptionHealth, Wn as useTableSkeleton, Vn as useTracking, Vt as useTranscription, Pn as useUndo, Rn as useUndoLog, Bt as useUpload, We as useValidationMessages, Er as useWindowedSubscription, Ht as useWorkflow, Ut as useWorkflowDomainEvents, Wt as useWorkflowEventDeliveries, Gt as useWorkflowEvents, Kt as useWorkflowRun, qt as useWorkflowRunEvents, Qt as useWorkflowRunState, Jt as useWorkflowRunSteps, Yt as useWorkflowRuns, Xt as useWorkflowSignal, Zt as useWorkflowUpdate, ar as validateEventPayload, He as validateFields, tr as validationStatus, un as wireAuthRefresh, Oe as withIdempotencyKey, Hn as wrapTrackedCallbacks };