@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
@@ -0,0 +1,34 @@
1
+ import { useFrameworkApi as e } from "./runtimeContext.js";
2
+ import { useSubscription as t } from "./useSubscription.js";
3
+ import { schemaToColumns as n } from "./schemaFields.js";
4
+ import { createLiveRowSorter as r } from "./liveRowSort.js";
5
+ import { useCallback as i, useMemo as a, useRef as o, useState as s } from "react";
6
+ //#region src/useDataTable.ts
7
+ var c = (c, l, u = {}) => {
8
+ let d = e(c), [f, p] = s(u.pageSize), m = a(() => f === void 0 ? u.input ?? {} : {
9
+ ...u.input,
10
+ limit: f
11
+ }, [u.input, f]), h = t(c, l, m), g = d.descriptors[l]?.output, _ = i(() => {
12
+ u.pageSize !== void 0 && p((e) => (e ?? u.pageSize) + u.pageSize);
13
+ }, [u.pageSize]), v = a(() => u.columns ?? (g === void 0 ? [] : n(g)), [u.columns, g]), [y, b] = s(u.initialSort), x = i((e) => {
14
+ b((t) => t?.column === e ? {
15
+ column: e,
16
+ direction: t.direction === "asc" ? "desc" : "asc"
17
+ } : {
18
+ column: e,
19
+ direction: "asc"
20
+ });
21
+ }, []), S = o(void 0);
22
+ return S.current === void 0 && (S.current = r()), {
23
+ columns: v,
24
+ rows: a(() => S.current(h.data ?? [], y), [h.data, y]),
25
+ loading: h.data === void 0,
26
+ error: h.error,
27
+ sort: y,
28
+ toggleSort: x,
29
+ loadMore: _,
30
+ hasMore: f !== void 0 && (h.data?.length ?? 0) >= f
31
+ };
32
+ };
33
+ //#endregion
34
+ export { c as useDataTable };
@@ -0,0 +1,22 @@
1
+ import { useRef as e } from "react";
2
+ //#region src/useDerived.ts
3
+ var t = (e, t) => {
4
+ if (e === t) return !0;
5
+ if (e.length !== t.length) return !1;
6
+ for (let n = 0; n < e.length; n += 1) if (!Object.is(e[n], t[n])) return !1;
7
+ return !0;
8
+ }, n = (e) => Object.keys(e).sort().map((t) => e[t]), r = (n, r) => {
9
+ let i = e(null), a = i.current, o = Object.keys(n), s = a !== null && t(a.insertionKeys, o) ? a.names : [...o].sort(), c = s.map((e) => n[e]);
10
+ return a === null || !t(a.names, s) || !t(a.key, c) ? i.current = {
11
+ insertionKeys: o,
12
+ names: s,
13
+ key: c,
14
+ value: r(n)
15
+ } : s !== a.names && (i.current = {
16
+ ...a,
17
+ insertionKeys: o,
18
+ names: s
19
+ }), i.current.value;
20
+ };
21
+ //#endregion
22
+ export { t as shallowArrayEqual, n as sourceValues, r as useDerived };
@@ -0,0 +1,98 @@
1
+ import { recordClientDiagnostic as e } from "./clientDiagnostics.js";
2
+ import { isUnresolvedApi as t } from "./frameworkRuntimesContext.js";
3
+ import { useFrameworkApi as n } from "./runtimeContext.js";
4
+ import { resolveByTag as r } from "./tagWalk.js";
5
+ import { useEffect as i, useLayoutEffect as a, useMemo as o, useRef as s, useState as c } from "react";
6
+ import { Effect as l, Fiber as u, Schedule as d, Stream as f } from "effect";
7
+ //#region src/useEvent.ts
8
+ var p = {
9
+ status: "idle",
10
+ missed: 0,
11
+ lastMiss: void 0
12
+ }, m = class {
13
+ _tag = "EventStreamClosed";
14
+ };
15
+ function h(h, g, _, v = {}) {
16
+ let { skip: y = !1, apiName: b = "app", onMissed: x } = v, S = n(b), C = g === null ? null : JSON.stringify(Object.entries(g).sort(([e], [t]) => e < t ? -1 : 1)), w = !y && C !== null && !t(S), T = o(() => ({
17
+ resume: /* @__PURE__ */ new Map(),
18
+ runtime: S.runtime,
19
+ client: S.client,
20
+ subject: S.subjectSignal ?? S.recovery?.subjectSignal,
21
+ key: C === null ? null : Object.fromEntries(JSON.parse(C)),
22
+ tag: h.name,
23
+ apiName: b
24
+ }), [
25
+ S.cache,
26
+ b,
27
+ h.name,
28
+ C,
29
+ w
30
+ ]), E = s(null), [D, O] = c(null);
31
+ return a(() => (E.current = {
32
+ scope: T,
33
+ handler: _,
34
+ onMissed: x
35
+ }, () => {
36
+ E.current = null;
37
+ })), i(() => {
38
+ if (!w || T.subject?.aborted) return;
39
+ let t = !1, n = () => !t && !T.subject?.aborted && E.current?.scope === T, i = (e) => {
40
+ n() && O((t) => ({
41
+ scope: T,
42
+ value: e(t?.scope === T ? t.value : p)
43
+ }));
44
+ }, a = (t, r) => {
45
+ !n() || t <= 0 || (e(T.apiName, "event.gap", {
46
+ tag: T.tag,
47
+ missed: t,
48
+ reason: r
49
+ }), i((e) => ({
50
+ ...e,
51
+ missed: e.missed + t,
52
+ lastMiss: {
53
+ count: t,
54
+ reason: r
55
+ }
56
+ })), E.current?.onMissed?.({
57
+ count: t,
58
+ reason: r
59
+ }));
60
+ };
61
+ i((e) => ({
62
+ ...e,
63
+ status: "connecting"
64
+ }));
65
+ let o = l.suspend(() => {
66
+ if (!n()) return l.interrupt;
67
+ let e = [...T.resume].map(([e, t]) => ({
68
+ origin: e,
69
+ n: t
70
+ })), t = r(T.client, T.tag);
71
+ return l.succeed(t({
72
+ key: T.key,
73
+ ...e.length > 0 ? { resume: e } : {}
74
+ }));
75
+ }), s = f.unwrap(o).pipe(f.concat(f.fail(new m())), f.retry(d.min([d.exponential("250 millis", 2), d.spaced("30 seconds")]).pipe(d.jittered, d.tap(() => l.sync(() => i((e) => ({
76
+ ...e,
77
+ status: "connecting"
78
+ }))))))), c = T.runtime.runFork(f.runForEach(s, (e) => l.sync(() => {
79
+ n() && (e._tag === "attached" ? i((e) => ({
80
+ ...e,
81
+ status: "live"
82
+ })) : e._tag === "gap" ? a(e.missed, e.reason) : (T.resume.set(e.origin, Math.max(T.resume.get(e.origin) ?? 0, e.n)), E.current?.handler(e.payload)));
83
+ }))), h = () => {
84
+ t || (t = !0, T.resume.clear(), O((e) => e?.scope === T ? {
85
+ scope: T,
86
+ value: p
87
+ } : e), T.runtime.runFork(l.forkDetach(u.interrupt(c))));
88
+ };
89
+ return T.subject?.addEventListener("abort", h, { once: !0 }), T.subject?.aborted && h(), () => {
90
+ T.subject?.removeEventListener("abort", h), h();
91
+ };
92
+ }, [w, T]), !w || T.subject?.aborted ? p : D?.scope === T ? D.value : {
93
+ ...p,
94
+ status: "connecting"
95
+ };
96
+ }
97
+ //#endregion
98
+ export { h as useEvent };
@@ -0,0 +1,478 @@
1
+ import { globalContext as e } from "./globalContext.js";
2
+ import { useFrameworkApi as t } from "./runtimeContext.js";
3
+ import { useMutation as n } from "./useMutation.js";
4
+ import { schemaToFields as r } from "./schemaFields.js";
5
+ import { resolveValidationMessage as i, restrictToSchema as a, validateFields as o } from "./formBinding.js";
6
+ import { useValidationMessages as s } from "./validationMessages.js";
7
+ import { recoverNativeFormValues as c } from "./formData.js";
8
+ import { useServerRequest as l } from "./serverRequest.js";
9
+ import { createElement as u, useCallback as d, useContext as f, useEffect as ee, useId as p, useLayoutEffect as te, useMemo as m, useRef as h, useState as g, useSyncExternalStore as ne } from "react";
10
+ import { Schema as _ } from "effect";
11
+ import { fieldIssuesOf as re } from "@voltro/protocol";
12
+ import { FormApi as ie } from "@tanstack/form-core";
13
+ import { useStore as ae } from "@tanstack/react-store";
14
+ //#region src/useFormBinding.ts
15
+ var v = Symbol.for("voltro.client.formEngine"), y = e("formFields", void 0), b = (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"], oe = (e, t) => {
16
+ let n = t, r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a, o = (e) => {
17
+ let t = n(e), i = r.get(e);
18
+ return i !== void 0 && b(i, t) ? i : (r.set(e, t), t);
19
+ }, s = () => {
20
+ for (let [e, t] of i) {
21
+ let n = r.get(e);
22
+ if (o(e) !== n) for (let e of [...t]) e();
23
+ }
24
+ };
25
+ return {
26
+ snapshot: o,
27
+ refresh: (e) => {
28
+ n = e, s();
29
+ },
30
+ subscribe: (t, n) => {
31
+ let o = i.get(t);
32
+ if (o === void 0 && (o = /* @__PURE__ */ new Set(), i.set(t, o)), o.add(n), a === void 0) {
33
+ let t = e.subscribe(s);
34
+ a = () => t.unsubscribe();
35
+ }
36
+ let c = o;
37
+ return () => {
38
+ c.delete(n), c.size === 0 && i.get(t) === c && (i.delete(t), r.delete(t)), i.size === 0 && (a?.(), a = void 0);
39
+ };
40
+ }
41
+ };
42
+ }, x = e("formBinding", void 0), se = (e, t) => {
43
+ let n = e;
44
+ for (let e of t.split(".")) {
45
+ if (typeof n != "object" || !n) return;
46
+ n = n[e];
47
+ }
48
+ return n;
49
+ }, ce = (e, t) => {
50
+ let n = `vf-${e}-${t}-`.replace(/[^a-zA-Z0-9_-]/g, "-");
51
+ return (e) => n + `${e}`.replace(/[^a-zA-Z0-9_-]/g, "-");
52
+ }, le = (e, t) => {
53
+ let n = e.map((e) => e.name), r = Object.keys(t), i;
54
+ if (e.length >= 32 && r.length >= 32 && Object.getPrototypeOf(e) === Array.prototype && Object.getOwnPropertyDescriptor(e, "some") === void 0) {
55
+ let t = /* @__PURE__ */ new Set();
56
+ for (let n = 0; n < e.length; n += 1) {
57
+ 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;
58
+ if (a === void 0 || !("value" in a) || typeof a.value != "string") break;
59
+ t.add(a.value), n === e.length - 1 && (i = t);
60
+ }
61
+ }
62
+ return [...n, ...r.filter((t) => i === void 0 ? !e.some((e) => e.name === t) : !i.has(t))];
63
+ }, ue = {
64
+ isTouched: !1,
65
+ isBlurred: !1,
66
+ isDirty: !1,
67
+ isPristine: !0,
68
+ isDefaultValue: !0,
69
+ isValidating: !1,
70
+ errorMap: {},
71
+ errorSourceMap: {}
72
+ }, de = (e) => {
73
+ let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
74
+ for (let r of e) {
75
+ if (t.has(r.name) || t.set(r.name, r), r.widget !== "array" || n.has(r.name)) continue;
76
+ let e = /* @__PURE__ */ new Map();
77
+ for (let t of r.item ?? []) e.has(t.name) || e.set(t.name, t);
78
+ n.set(r.name, e);
79
+ }
80
+ return (e) => {
81
+ let r = t.get(e);
82
+ if (r !== void 0) return r;
83
+ let i = /^(.+?)\.\d+\.(.+)$/.exec(e);
84
+ return i === null ? void 0 : n.get(i[1])?.get(i[2]);
85
+ };
86
+ }, S = (e, r, i) => {
87
+ let a = t(e), o = h(void 0), s = typeof r == "function" ? r(o.current?.state?.values ?? i.defaults ?? {}) : r, c = h(s).current, l = n(e, s), u = i.schema ?? a.descriptors[s]?.input;
88
+ return process.env.NODE_ENV !== "production" && u === void 0 && console.error(`[@voltro/client] useFormBinding('${e}', '${r}'): no input schema. Pass options.schema, or mount the descriptor so its input reaches the client. Rendering no fields; submit skips client-side validation.`), w(e, c, i, u, o, l);
89
+ }, C = (e) => {
90
+ let t = h(void 0);
91
+ return w("local", p(), {
92
+ ...e,
93
+ onSubmit: async ({ input: t }) => e.onSubmit(await _.decodeUnknownPromise(e.schema)(t))
94
+ }, e.schema, t);
95
+ }, w = (e, t, n, u, f, p) => {
96
+ let ne = l(), _ = m(() => u ? r(u) : [], [u]), y = m(() => de(_), [_]), b = m(() => ce(e, t), [e, t]), x = s(), S = n.messages ?? x, C = m(() => ({
97
+ ...n.locale === void 0 ? {} : { locale: n.locale },
98
+ ...S === void 0 ? {} : { messages: S }
99
+ }), [n.locale, S]), w = h(n.asyncFields);
100
+ w.current = n.asyncFields;
101
+ let T = h(n);
102
+ T.current = n;
103
+ let E = h(p);
104
+ E.current = p;
105
+ let D = h(C);
106
+ D.current = C;
107
+ let O = h(u);
108
+ O.current = u;
109
+ let [k, A] = g(() => n.flash?.errors ?? {}), [fe, j] = g(n.flash?.formError), [pe, M] = g(void 0), N = h(void 0), P = h(!1), F = d((e) => {
110
+ let t = O.current;
111
+ if (t === void 0) return [];
112
+ let n = T.current, r = e;
113
+ if (n.toInput !== void 0) try {
114
+ r = n.toInput(e);
115
+ } catch {
116
+ r = e;
117
+ }
118
+ let i = o(t, r, D.current).issues;
119
+ if (n.toInput === void 0) return i;
120
+ let a = n.errorPath ?? {};
121
+ return i.map((t) => {
122
+ let n = a[t.path];
123
+ return n === void 0 ? (se(e, t.path) !== void 0 || t.path.includes("."), t) : {
124
+ ...t,
125
+ path: n
126
+ };
127
+ });
128
+ }, []), I = d((e) => {
129
+ let t = { ...e ?? {} }, n = O.current;
130
+ if (n !== void 0) for (let e of r(n)) (e.widget === "checkbox" || e.widget === "switch") && !(e.name in t) && (t[e.name] = !1);
131
+ return t;
132
+ }, []), me = h(() => Promise.resolve());
133
+ if (f.current === void 0) {
134
+ let e = n.flash, r = e === void 0 ? I(n.defaults) : {
135
+ ...I(n.defaults),
136
+ ...e.values
137
+ }, a = ne === null && u !== void 0 ? c(u, n.formKey ?? e?.formKey ?? t, r) : r;
138
+ f.current = new ie({
139
+ onSubmit: ({ value: e }) => me.current(e),
140
+ defaultValues: a,
141
+ validators: { onChange: ({ value: e }) => {
142
+ let t = F(e);
143
+ if (t.length === 0) return;
144
+ let n = {};
145
+ for (let e of t) e.path !== "" && !(e.path in n) && (n[e.path] = i(e, D.current));
146
+ return { fields: n };
147
+ } }
148
+ });
149
+ }
150
+ let L = f.current, R = L;
151
+ ee(() => R.mount(), [R]);
152
+ let he = n.subscribe ?? "all";
153
+ ae(L.store, (e) => he === "all" ? e : `${e.submissionAttempts}|${String(e.isSubmitting)}|${String(e.isDirty)}|${String(e.isTouched)}`);
154
+ let z = L.store.state.values, B = L.store.state, V = m(() => F(z), [
155
+ F,
156
+ z,
157
+ u,
158
+ n.toInput,
159
+ n.errorPath,
160
+ C
161
+ ]), ge = m(() => {
162
+ let e = /* @__PURE__ */ new Map();
163
+ for (let t of V) e.has(t.path) || e.set(t.path, t);
164
+ return e;
165
+ }, [V]), H = h({
166
+ values: z,
167
+ index: ge
168
+ });
169
+ H.current = {
170
+ values: z,
171
+ index: ge
172
+ };
173
+ let _e = d((e) => {
174
+ let t = L.store.state.values;
175
+ if (H.current.values !== t) {
176
+ let e = /* @__PURE__ */ new Map();
177
+ for (let n of F(t)) e.has(n.path) || e.set(n.path, n);
178
+ H.current = {
179
+ values: t,
180
+ index: e
181
+ };
182
+ }
183
+ return H.current.index.get(e);
184
+ }, [L, F]), U = n.isLoading === !0, ve = n.validate, W = ve?.onChange ?? "afterTouched", ye = ve?.onBlur ?? !0, be = d((e) => {
185
+ if (U) return !1;
186
+ if (L.store.state.submissionAttempts > 0 || W === "always") return !0;
187
+ if (W === "never") return !1;
188
+ let t = R.getFieldMeta(e);
189
+ return t === void 0 ? !1 : ye ? t.isBlurred === !0 : t.isTouched === !0;
190
+ }, [
191
+ L,
192
+ R,
193
+ U,
194
+ W,
195
+ ye
196
+ ]), G = d((e) => {
197
+ let t = k[e];
198
+ if (t !== void 0) return t;
199
+ let n = w.current?.[e];
200
+ if (n !== void 0 && n.status === "invalid") return n.message ?? i({
201
+ id: "validation.invalid",
202
+ fallback: "Invalid value"
203
+ }, D.current);
204
+ if (!be(e)) return;
205
+ let r = _e(e);
206
+ return r === void 0 ? void 0 : i(r, D.current);
207
+ }, [
208
+ k,
209
+ be,
210
+ _e
211
+ ]), K = m(() => {
212
+ let e = {}, t = /* @__PURE__ */ new Set();
213
+ for (let e of V) e.path !== "" && t.add(e.path);
214
+ for (let e of Object.keys(k)) t.add(e);
215
+ for (let [e, n] of Object.entries(w.current ?? {})) n.status === "invalid" && t.add(e);
216
+ for (let n of t) {
217
+ let t = G(n);
218
+ t !== void 0 && (e[n] = t);
219
+ }
220
+ return e;
221
+ }, [
222
+ V,
223
+ k,
224
+ G,
225
+ B.fieldMetaBase,
226
+ B.submissionAttempts,
227
+ n.asyncFields
228
+ ]), q = d((e) => {
229
+ A((t) => {
230
+ if (!(e in t)) return t;
231
+ let n = { ...t };
232
+ return delete n[e], n;
233
+ });
234
+ }, []), J = d((e) => {
235
+ let t = y(e), n = R.getFieldMeta(e), r = G(e), i = b(e), a = w.current?.[e], o = [r === void 0 ? void 0 : `${i}-error`, t?.description === void 0 ? void 0 : `${i}-help`].filter((e) => e !== void 0);
236
+ return {
237
+ value: R.getFieldValue(e),
238
+ setValue: (t) => {
239
+ q(e), !Object.is(R.getFieldValue(e), t) && R.setFieldValue(e, t);
240
+ },
241
+ onBlur: () => {
242
+ R.setFieldMeta(e, (e) => ({
243
+ ...ue,
244
+ ...e ?? {},
245
+ isTouched: !0,
246
+ isBlurred: !0
247
+ }));
248
+ },
249
+ error: r,
250
+ serverError: k[e],
251
+ touched: n?.isTouched === !0,
252
+ blurred: n?.isBlurred === !0,
253
+ dirty: n?.isDirty === !0,
254
+ required: t?.required === !0,
255
+ label: t?.label ?? e,
256
+ widget: t?.widget ?? "text",
257
+ options: t?.options,
258
+ description: t?.description,
259
+ asyncStatus: a?.status ?? "idle",
260
+ a11y: {
261
+ id: i,
262
+ "aria-invalid": r !== void 0 || void 0,
263
+ "aria-required": t?.required === !0 || void 0,
264
+ "aria-describedby": o.length > 0 ? o.join(" ") : void 0
265
+ }
266
+ };
267
+ }, [
268
+ b,
269
+ q,
270
+ R,
271
+ y,
272
+ k,
273
+ G
274
+ ]), Y = h(void 0);
275
+ Y.current === void 0 && (Y.current = oe(L.store, J));
276
+ let xe = Y.current;
277
+ te(() => {
278
+ xe.refresh(J);
279
+ });
280
+ let Se = d((e) => ({
281
+ items: R.getFieldValue(e) ?? [],
282
+ push: (t) => {
283
+ R.pushFieldValue(e, t);
284
+ },
285
+ insert: (t, n) => {
286
+ R.insertFieldValue(e, t, n);
287
+ },
288
+ remove: (t) => {
289
+ R.removeFieldValue(e, t);
290
+ },
291
+ move: (t, n) => {
292
+ R.moveFieldValues(e, t, n);
293
+ },
294
+ swap: (t, n) => {
295
+ R.swapFieldValues(e, t, n);
296
+ },
297
+ field: (t, n) => J(`${e}.${t}.${n}`)
298
+ }), [R, J]), Ce = d((e) => _.filter((t) => t.section === e), [_]), we = d((e, t) => {
299
+ q(e), !Object.is(R.getFieldValue(e), t) && R.setFieldValue(e, t);
300
+ }, [q, R]), Te = d((e) => {
301
+ for (let [t, n] of Object.entries(e)) R.setFieldValue(t, n);
302
+ }, [R]), Ee = d((e) => {
303
+ A({}), j(void 0), M(void 0), N.current = void 0, P.current = !1, e === void 0 ? R.reset() : R.reset(I(e));
304
+ }, [R, I]), De = n.asyncTimeoutMs ?? 5e3, Oe = d(async () => {
305
+ let e = Date.now();
306
+ for (;;) {
307
+ let t = w.current;
308
+ if (t === void 0) return;
309
+ let n = Object.entries(t), r;
310
+ for (let e of n) e[1].status === "checking" && (r ??= []).push(e);
311
+ if (r === void 0) {
312
+ let e = 0;
313
+ for (let t of n) t[1].status === "invalid" && (n[e++] = t);
314
+ n.length = e;
315
+ let t = n;
316
+ if (t.length === 0) return;
317
+ let r = Object.fromEntries(t);
318
+ for (let [e, n] of t) r[e] = n.message ?? i({
319
+ id: "validation.invalid",
320
+ fallback: "Invalid value"
321
+ }, D.current);
322
+ return r;
323
+ }
324
+ if (Date.now() - e > De) {
325
+ let e = Object.fromEntries(r);
326
+ for (let [t] of r) e[t] = i({
327
+ id: "validation.checking",
328
+ fallback: "Still checking…"
329
+ }, D.current);
330
+ return e;
331
+ }
332
+ await new Promise((e) => setTimeout(e, 50));
333
+ }
334
+ }, [De]), X = d(() => {
335
+ let e = globalThis.document;
336
+ if (e?.getElementById === void 0) return;
337
+ let t = le(_, k);
338
+ for (let n of t) if (G(n) !== void 0) {
339
+ e.getElementById(b(n))?.focus?.();
340
+ return;
341
+ }
342
+ }, [
343
+ b,
344
+ _,
345
+ k,
346
+ G
347
+ ]), Z = h(X);
348
+ Z.current = X;
349
+ let ke = d(async () => {
350
+ j(void 0), A({}), M(void 0), N.current = void 0, P.current = !1;
351
+ let e, t = !1;
352
+ if (await R.handleSubmit().catch((n) => {
353
+ t = !0, e = n;
354
+ }), t) throw e;
355
+ return P.current || queueMicrotask(() => {
356
+ Z.current();
357
+ }), N.current;
358
+ }, [R]);
359
+ me.current = (async (e) => {
360
+ let t = T.current, n = e, r = n;
361
+ if (t.toInput !== void 0) try {
362
+ r = t.toInput(n);
363
+ } catch (e) {
364
+ j(e instanceof Error ? e.message : String(e));
365
+ return;
366
+ }
367
+ if (F(n).length > 0) {
368
+ queueMicrotask(() => {
369
+ Z.current();
370
+ });
371
+ return;
372
+ }
373
+ let o = O.current;
374
+ if (o !== void 0) {
375
+ let e = a(o, r);
376
+ 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;
377
+ }
378
+ let s = await Oe();
379
+ if (s !== void 0) {
380
+ A((e) => ({
381
+ ...e,
382
+ ...s
383
+ })), queueMicrotask(() => {
384
+ Z.current();
385
+ });
386
+ return;
387
+ }
388
+ let c = (e) => {
389
+ let t = E.current;
390
+ return t === void 0 ? Promise.reject(/* @__PURE__ */ Error("A schema form submits through its onSubmit callback")) : t.mutate(e);
391
+ };
392
+ try {
393
+ let e = t.onSubmit === void 0 ? await c(r) : await t.onSubmit({
394
+ input: r,
395
+ values: n,
396
+ mutate: c
397
+ });
398
+ N.current = e, P.current = !0, t.onSuccess?.(e);
399
+ } catch (e) {
400
+ let t = re(e);
401
+ if (t.length === 0) {
402
+ M(e), T.current.onError?.(e);
403
+ return;
404
+ }
405
+ let n = {};
406
+ for (let e of t) e.field in n || (n[e.field] = i({
407
+ id: e.message,
408
+ ...e.params === void 0 ? {} : { params: e.params },
409
+ fallback: e.message
410
+ }, D.current));
411
+ A((e) => ({
412
+ ...e,
413
+ ...n
414
+ })), queueMicrotask(() => {
415
+ Z.current();
416
+ });
417
+ }
418
+ });
419
+ let Q = V.length === 0, Ae = Object.values(w.current ?? {}).some((e) => e.status === "checking"), $ = pe ?? p?.error, je = $ !== void 0 && re($).length > 0 ? void 0 : $, Me = Object.keys(K).length, Ne = (() => {
420
+ for (let e of _) if (K[e.name] !== void 0) return e.name;
421
+ let e = Object.keys(K);
422
+ return e.length > 0 ? e[0] : void 0;
423
+ })(), Pe = {
424
+ isDirty: !U && B.isDirty,
425
+ isPristine: B.isPristine,
426
+ isTouched: B.isTouched,
427
+ isValid: Q,
428
+ isValidating: Ae,
429
+ canSubmit: Q && !Ae && !B.isSubmitting && !U,
430
+ isSubmitting: B.isSubmitting,
431
+ isSubmitted: B.isSubmitted,
432
+ isSubmitSuccessful: B.isSubmitSuccessful && P.current,
433
+ submissionAttempts: B.submissionAttempts,
434
+ errorCount: Me,
435
+ firstInvalidPath: Ne,
436
+ pending: p?.pending ?? B.isSubmitting,
437
+ isLoading: U,
438
+ submitError: je,
439
+ data: p?.data ?? N.current
440
+ }, Fe = {
441
+ fields: _,
442
+ values: z,
443
+ errors: K,
444
+ issues: V,
445
+ isValid: Q,
446
+ pending: p?.pending ?? B.isSubmitting,
447
+ submitError: je,
448
+ formError: fe,
449
+ data: p?.data ?? N.current,
450
+ setValue: we,
451
+ setValues: Te,
452
+ reset: Ee,
453
+ submit: ke,
454
+ field: J,
455
+ array: Se,
456
+ section: Ce,
457
+ state: Pe,
458
+ focusFirstInvalid: X
459
+ };
460
+ return Object.defineProperty(Fe, v, {
461
+ value: {
462
+ store: L.store,
463
+ field: J,
464
+ channel: xe
465
+ },
466
+ enumerable: !1
467
+ }), Fe;
468
+ }, T = (e) => {
469
+ let t = e.binding[v];
470
+ return u(x.Provider, { value: e.binding }, u(y.Provider, { value: t?.channel }, e.children));
471
+ }, E = () => f(x);
472
+ function D(e, t) {
473
+ let n = f(y), r = typeof e == "string" ? void 0 : e, i = typeof e == "string" ? e : t, a = r?.[v], o = r === void 0 ? n : a?.channel;
474
+ 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");
475
+ return ne(d((e) => o.subscribe(i, e), [o, i]), d(() => o.snapshot(i), [o, i]), d(() => o.snapshot(i), [o, i]));
476
+ }
477
+ //#endregion
478
+ export { T as FormBindingProvider, S as useFormBinding, E as useFormBindingContext, D as useFormField, C as useSchemaFormBinding };
@@ -0,0 +1,59 @@
1
+ import { useFrameworkApi as e } from "./runtimeContext.js";
2
+ import { useCallback as t, useMemo as n, useRef as r, useSyncExternalStore as i } from "react";
3
+ //#region src/useLocalQuery.ts
4
+ var a = (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)), o = (e, t = {}) => {
5
+ let n = t.limit === void 0 ? void 0 : Math.max(0, Math.trunc(t.limit));
6
+ if (n === 0 || Number.isNaN(n)) return [];
7
+ let r = t.where === void 0 ? [...e] : e.filter(t.where), i = t.orderBy;
8
+ if (i !== void 0) {
9
+ let e = typeof i == "function" ? i : typeof i == "string" ? (e, t) => a(e[i], t[i]) : (e, t) => {
10
+ let [n, r] = typeof i == "string" ? [i, "asc"] : i, o = a(e[n], t[n]);
11
+ return r === "desc" ? -o : o;
12
+ };
13
+ if (n !== void 0 && Number.isFinite(n) && n < r.length / 2) {
14
+ let t = (t, n) => {
15
+ let r = t.row === void 0 ? n.row === void 0 ? 0 : 1 : n.row === void 0 ? -1 : e(t.row, n.row);
16
+ return (Number.isNaN(r) ? 0 : r) || t.index - n.index;
17
+ }, i = [], a = () => {
18
+ let e = 0;
19
+ for (;;) {
20
+ let n = e * 2 + 1, r = n + 1;
21
+ if (n >= i.length) return;
22
+ let a = r < i.length && t(i[r], i[n]) > 0 ? r : n;
23
+ if (t(i[e], i[a]) >= 0) return;
24
+ [i[e], i[a]] = [i[a], i[e]], e = a;
25
+ }
26
+ };
27
+ for (let e = 0; e < r.length; e++) {
28
+ let o = {
29
+ row: r[e],
30
+ index: e
31
+ };
32
+ if (i.length < n) {
33
+ i.push(o);
34
+ let e = i.length - 1;
35
+ for (; e > 0;) {
36
+ let n = e - 1 >> 1;
37
+ if (t(i[n], i[e]) >= 0) break;
38
+ [i[n], i[e]] = [i[e], i[n]], e = n;
39
+ }
40
+ } else t(o, i[0]) < 0 && (i[0] = o, a());
41
+ }
42
+ return i.sort(t).map((e) => e.row);
43
+ }
44
+ r = r.sort(e);
45
+ }
46
+ return t.limit === void 0 ? r : r.slice(0, Math.max(0, t.limit));
47
+ }, s = (a, s, l = {}) => {
48
+ let { cache: u } = e(a), d = i(t((e) => u.subscribeTable(s, e), [u, s]), t(() => u.rowsOf(s), [u, s]), () => c), f = r(l);
49
+ f.current = l;
50
+ let { where: p, orderBy: m, limit: h } = l;
51
+ return n(() => o(d, f.current), [
52
+ d,
53
+ p,
54
+ m,
55
+ h
56
+ ]);
57
+ }, c = [];
58
+ //#endregion
59
+ export { o as runLocalQuery, s as useLocalQuery };