@voltro/client 0.89.2 → 0.91.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.
- package/CHANGELOG.md +1943 -0
- package/README.md +22 -0
- package/THIRD-PARTY-NOTICES.md +1 -1
- package/dist/analytics.d.ts +68 -0
- package/dist/analytics.js +1 -0
- package/dist/apiRuntime.js +50 -50
- package/dist/apiSupervisor.js +25 -25
- package/dist/awaitResolvedApi.js +42 -16
- package/dist/bootstrap.d.ts +0 -115
- package/dist/bootstrap.js +8 -8
- package/dist/connectionPrerequisite.js +18 -18
- package/dist/connectionSetupController.js +123 -91
- package/dist/createHooks.js +11 -11
- package/dist/form.js +7 -7
- package/dist/index.d.ts +148 -162
- package/dist/index.js +88 -86
- package/dist/invocationWait.js +14 -0
- package/dist/mutationsBus.js +92 -35
- package/dist/outbox.js +137 -108
- package/dist/outboxState.js +7 -0
- package/dist/platform.js +10 -10
- package/dist/query.js +3 -10
- package/dist/rpcCallOnce.js +30 -0
- package/dist/rpcDeclared.js +7 -0
- package/dist/runRpc.js +9 -6
- package/dist/runtime.d.ts +16 -116
- package/dist/runtime.js +16 -16
- package/dist/runtimeContext.js +1 -1
- package/dist/serviceClient.js +23 -23
- package/dist/store.js +3 -3
- package/dist/subscriptionCache.js +1 -1
- package/dist/traceBus.js +7 -1
- package/dist/unknownRpcTag.js +7 -0
- package/dist/uploadBytes.js +83 -0
- package/dist/uploadClient.js +153 -0
- package/dist/useAction.js +148 -74
- package/dist/useAgentChat.js +3 -3
- package/dist/useCapabilityManifest.js +7 -7
- package/dist/useConnectionStatus.js +5 -5
- package/dist/useDataTable.js +4 -4
- package/dist/useEvent.js +22 -22
- package/dist/useFormBinding.js +10 -10
- package/dist/useMutation.js +221 -134
- package/dist/useOnRpcError.js +5 -5
- package/dist/usePreloadedSubscription.js +6 -6
- package/dist/useRpcCaller.js +75 -13
- package/dist/useRpcInvocationOwner.js +29 -0
- package/dist/useSubscription.js +52 -49
- package/dist/useTranscription.js +112 -40
- package/dist/useUpload.js +160 -242
- package/dist/useWorkflow.js +111 -246
- package/dist/workflowClient.js +126 -0
- package/package.json +8 -3
package/dist/useMutation.js
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
1
|
+
import { useFrameworkApi as e } from "./runtimeContext.js";
|
|
2
|
+
import { deferRpcMethod as t, runRpcPromise as n } from "./runRpc.js";
|
|
3
|
+
import { resolveByTag as r } from "./tagWalk.js";
|
|
4
|
+
import { omitMutationInputs as i, omitMutationOutputs as a, startMutation as o } from "./mutationsBus.js";
|
|
5
|
+
import { publishClientTrace as s, publishClientTraceRefusal as c } from "./traceBus.js";
|
|
6
|
+
import { awaitResolvedApi as l, bindResolvedRpcInvocationOwner as u } from "./awaitResolvedApi.js";
|
|
7
|
+
import { useRpcInvocationOwner as d } from "./useRpcInvocationOwner.js";
|
|
8
|
+
import { ConnectionPrerequisiteInvalidated as f } from "./connectionPrerequisite.js";
|
|
9
|
+
import { rpcErrorKind as p } from "./rpcErrorKind.js";
|
|
10
|
+
import { reportUnknownRpcTag as m } from "./unknownRpcTag.js";
|
|
11
|
+
import { recoveryCoordinatorFor as h } from "./recoveryCoordinator.js";
|
|
12
|
+
import { bindMutationConnectionSetup as g, captureMutationConnectionSetup as ee, connectionSetupOwner as _ } from "./mutationConnectionSetup.js";
|
|
13
|
+
import { freshIdempotencyKey as v, withIdempotencyKey as y } from "./mutationIdentity.js";
|
|
14
|
+
import { connectionScopeForRuntime as te } from "./connectionScope.js";
|
|
15
|
+
import { MutationSerialExecutionError as b, makeMutationSerialExecution as x } from "./mutationSerialExecution.js";
|
|
16
|
+
import { useCallback as S, useEffect as C, useMemo as w, useRef as T, useState as E } from "react";
|
|
17
|
+
import { Effect as D } from "effect";
|
|
15
18
|
// src/useMutation.ts
|
|
16
|
-
var
|
|
17
|
-
let r =
|
|
18
|
-
r === void 0 && (r = /* @__PURE__ */ new Map(),
|
|
19
|
+
var O = /* @__PURE__ */ new WeakMap(), ne = (e, t, n) => {
|
|
20
|
+
let r = O.get(e);
|
|
21
|
+
r === void 0 && (r = /* @__PURE__ */ new Map(), O.set(e, r));
|
|
19
22
|
let i = r.get(t);
|
|
20
|
-
return i === void 0 && (i =
|
|
21
|
-
},
|
|
23
|
+
return i === void 0 && (i = x(n), r.set(t, i)), i;
|
|
24
|
+
}, re = (e) => {
|
|
25
|
+
let t = e;
|
|
26
|
+
return t?._tag === "MutationOutputNotRetained" && t.receiptStatus === 200;
|
|
27
|
+
}, k = (e, t) => {
|
|
22
28
|
if (t === void 0 || typeof e != "object" || !e) return e;
|
|
23
29
|
try {
|
|
24
30
|
Object.defineProperty(e, "__voltroTraceId", {
|
|
@@ -28,186 +34,267 @@ var S = /* @__PURE__ */ new WeakMap(), C = (e, t, n) => {
|
|
|
28
34
|
});
|
|
29
35
|
} catch {}
|
|
30
36
|
return e;
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
},
|
|
37
|
+
}, A, j = (e) => {
|
|
38
|
+
A = e;
|
|
39
|
+
}, M = () => A, N = (e, t, n) => typeof e == "function" ? e(t, n) : e, P = 0, ie = () => `mut_${++P}`, ae = (e, t) => ({
|
|
34
40
|
update: (n, r) => {
|
|
35
41
|
e.update(n, r, t);
|
|
36
42
|
},
|
|
37
43
|
forTag: (n, r) => e.forTag(n, r, t)
|
|
38
|
-
}),
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
let
|
|
44
|
+
}), F = (b, x) => {
|
|
45
|
+
let O = e(b), { descriptors: j } = O, M = T(O);
|
|
46
|
+
M.current = O;
|
|
47
|
+
let { owner: P, current: F, assertCurrent: I, assertOwnerCurrent: L } = d(M, b, x), R = j[x], z = R?.outputRetention === "none", B = R?.clientHistory?.input === "omit", V = R?.targets;
|
|
42
48
|
if (process.env.NODE_ENV !== "production") {
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
m("useMutation", b, x, j);
|
|
50
|
+
let e = R?.kind;
|
|
51
|
+
e !== void 0 && e !== "mutation" && console.error(`[@voltro/client] useMutation('${b}', '${x}') targets a ${e}, not a mutation. Use ${e === "action" ? "useAction" : e === "workflow" ? "useWorkflow" : `the ${e} hook`} instead.`);
|
|
45
52
|
}
|
|
46
|
-
let [
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
let [H, U] = E(() => ({
|
|
54
|
+
owner: P,
|
|
55
|
+
pending: !1,
|
|
56
|
+
error: void 0,
|
|
57
|
+
data: void 0
|
|
58
|
+
}));
|
|
59
|
+
C(() => {
|
|
60
|
+
z && (U((e) => e.data === void 0 ? e : {
|
|
61
|
+
...e,
|
|
62
|
+
data: void 0
|
|
63
|
+
}), a(b, x));
|
|
64
|
+
}, [
|
|
65
|
+
z,
|
|
66
|
+
b,
|
|
67
|
+
x
|
|
68
|
+
]), C(() => {
|
|
69
|
+
B && i(b, x);
|
|
70
|
+
}, [
|
|
71
|
+
B,
|
|
72
|
+
b,
|
|
73
|
+
x
|
|
74
|
+
]);
|
|
75
|
+
let W = T(null), G = T(!1), K = T({
|
|
76
|
+
owner: P,
|
|
77
|
+
count: 0
|
|
78
|
+
});
|
|
79
|
+
K.current.owner !== P && (K.current = {
|
|
80
|
+
owner: P,
|
|
81
|
+
count: 0
|
|
82
|
+
}, W.current = null, G.current = !1);
|
|
83
|
+
let q = S(async (e, i) => {
|
|
84
|
+
I();
|
|
85
|
+
let a = P.subject, d = K.current, m = i?.onError !== void 0 || i?.notify?.error !== void 0, g = (t) => {
|
|
86
|
+
I(), i?.onError?.(t, e), I();
|
|
87
|
+
let n = N(i?.notify?.error, t, e);
|
|
88
|
+
I(), n !== void 0 && A?.error(n);
|
|
51
89
|
};
|
|
52
|
-
|
|
53
|
-
let
|
|
54
|
-
|
|
55
|
-
|
|
90
|
+
d.count += 1;
|
|
91
|
+
let _ = () => {
|
|
92
|
+
--d.count, F() && U((e) => e.owner === P ? {
|
|
93
|
+
...e,
|
|
94
|
+
pending: d.count > 0
|
|
95
|
+
} : e);
|
|
96
|
+
};
|
|
97
|
+
U((e) => ({
|
|
98
|
+
owner: P,
|
|
99
|
+
pending: !0,
|
|
100
|
+
error: void 0,
|
|
101
|
+
data: e.owner === P ? e.data : void 0
|
|
102
|
+
}));
|
|
103
|
+
let S, C, w, T, E;
|
|
56
104
|
try {
|
|
57
|
-
|
|
58
|
-
let
|
|
59
|
-
if (
|
|
60
|
-
let
|
|
61
|
-
|
|
105
|
+
T = ee(q);
|
|
106
|
+
let t = M.current.descriptors[x]?.serialize;
|
|
107
|
+
if (t !== void 0) {
|
|
108
|
+
let n = M.current, r = n.recovery ?? h(n.errorBus, b);
|
|
109
|
+
E = ne(n.descriptors, x, t.maxPending ?? 32).reserve(t.key(e), r.subjectSignal);
|
|
62
110
|
}
|
|
63
|
-
|
|
111
|
+
let n = await l(M, b, x);
|
|
112
|
+
if (a.aborted) throw new f("inactive");
|
|
113
|
+
u(P, n), I(), {runtime: S, cache: C, client: w} = n;
|
|
64
114
|
} catch (e) {
|
|
65
|
-
if (
|
|
115
|
+
if (E?.release(), _(), !F()) throw new f("inactive");
|
|
116
|
+
if (U((t) => t.owner === P ? {
|
|
117
|
+
...t,
|
|
118
|
+
error: e
|
|
119
|
+
} : t), M.current.errorBus.emit({
|
|
66
120
|
source: "mutation",
|
|
67
|
-
tag:
|
|
121
|
+
tag: x,
|
|
68
122
|
error: e,
|
|
69
123
|
kind: "client",
|
|
70
124
|
outcome: "not-started"
|
|
71
|
-
}),
|
|
125
|
+
}), m) return g(e);
|
|
72
126
|
throw e;
|
|
73
127
|
}
|
|
74
|
-
let
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
128
|
+
let O = ie(), j = i?.idempotencyKey ?? v(), L = M.current.descriptors[x]?.outputRetention === "none", R = !M.current.descriptors[x] || M.current.descriptors[x]?.clientHistory?.input === "omit", z = o({
|
|
129
|
+
id: O,
|
|
130
|
+
apiName: b,
|
|
131
|
+
tag: x,
|
|
132
|
+
input: R ? void 0 : e,
|
|
133
|
+
...R ? { inputOmitted: !0 } : {},
|
|
134
|
+
...L ? { outputOmitted: !0 } : {}
|
|
135
|
+
}, P.subject), B = W.current, H = G.current;
|
|
82
136
|
try {
|
|
83
|
-
|
|
137
|
+
I(), B ? B(ae(C, O), e) : !H && V && V.length > 0 && C.autoApply(V, e, O);
|
|
84
138
|
} catch (e) {
|
|
85
|
-
if (
|
|
139
|
+
if (E?.release(), _(), C.revertByMutation(O), z.settle({
|
|
86
140
|
status: "error",
|
|
87
141
|
error: e
|
|
88
|
-
}),
|
|
142
|
+
}), !F()) throw new f("inactive");
|
|
143
|
+
if (U((t) => t.owner === P ? {
|
|
144
|
+
...t,
|
|
145
|
+
error: e
|
|
146
|
+
} : t), m) return g(e);
|
|
89
147
|
throw e;
|
|
90
148
|
}
|
|
91
|
-
let
|
|
149
|
+
let J, Y = !1, X, Z, Q, $ = Date.now();
|
|
92
150
|
try {
|
|
93
|
-
if (
|
|
94
|
-
await
|
|
95
|
-
let e = await
|
|
96
|
-
|
|
151
|
+
if (E) {
|
|
152
|
+
await E.ready, I(), E.assertActive();
|
|
153
|
+
let e = await l(M, b, x);
|
|
154
|
+
I(), S = e.runtime, w = e.client;
|
|
97
155
|
}
|
|
98
|
-
let
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
156
|
+
let a = async (i, a, o, c) => {
|
|
157
|
+
I();
|
|
158
|
+
let l = te(i), u = l?.getSnapshot();
|
|
159
|
+
Z = l === void 0 ? void 0 : () => M.current.runtime === i && u !== void 0 && l.getSnapshot() === u, c?.(), E?.assertActive();
|
|
160
|
+
let d = T === void 0 ? void 0 : await T.prepare(i, a);
|
|
161
|
+
u = l?.getSnapshot(), I(), c?.();
|
|
162
|
+
let f = r(a, x), p = y(t(() => {
|
|
163
|
+
I(), c?.(), E?.assertActive();
|
|
164
|
+
let t = f(e);
|
|
165
|
+
return Y = !0, t;
|
|
166
|
+
}), j), m = D.currentSpan.pipe(D.tap((e) => D.sync(() => {
|
|
167
|
+
J = e.traceId, s({
|
|
168
|
+
traceId: e.traceId,
|
|
169
|
+
spanId: e.spanId,
|
|
107
170
|
source: "mutation",
|
|
108
|
-
tag:
|
|
171
|
+
tag: x
|
|
109
172
|
});
|
|
110
|
-
})),
|
|
173
|
+
})), D.catch(() => D.void), D.andThen(D.try({
|
|
111
174
|
try: () => {
|
|
112
|
-
c?.(),
|
|
175
|
+
I(), c?.(), E?.assertActive();
|
|
113
176
|
},
|
|
114
177
|
catch: (e) => e
|
|
115
|
-
})),
|
|
116
|
-
"voltro.api":
|
|
117
|
-
"voltro.mutationId":
|
|
118
|
-
"rpc.tag":
|
|
119
|
-
"voltro.replay":
|
|
178
|
+
})), D.andThen(p)).pipe(D.withSpan(`client.mutation.${x}`, { attributes: {
|
|
179
|
+
"voltro.api": b,
|
|
180
|
+
"voltro.mutationId": O,
|
|
181
|
+
"rpc.tag": x,
|
|
182
|
+
"voltro.replay": o
|
|
120
183
|
} }));
|
|
121
|
-
return d === void 0 ?
|
|
122
|
-
},
|
|
184
|
+
return d === void 0 ? n(i, m) : d.run(m);
|
|
185
|
+
}, o;
|
|
123
186
|
try {
|
|
124
|
-
|
|
187
|
+
o = await a(S, w, !1);
|
|
125
188
|
} catch (e) {
|
|
126
|
-
|
|
127
|
-
|
|
189
|
+
I();
|
|
190
|
+
let t = p(e, Y ? "handler" : "client"), n = k(e, J);
|
|
191
|
+
t === "transport" && (M.current.errorBus.emit({
|
|
128
192
|
source: "mutation",
|
|
129
|
-
tag:
|
|
130
|
-
error:
|
|
131
|
-
kind:
|
|
132
|
-
...
|
|
133
|
-
outcome:
|
|
134
|
-
...
|
|
135
|
-
}),
|
|
136
|
-
let
|
|
137
|
-
if (
|
|
193
|
+
tag: x,
|
|
194
|
+
error: n,
|
|
195
|
+
kind: t,
|
|
196
|
+
...Z === void 0 ? {} : { affectsTransport: Z() },
|
|
197
|
+
outcome: Y ? "unknown" : "not-started",
|
|
198
|
+
...J === void 0 ? {} : { traceId: J }
|
|
199
|
+
}), X = n), I();
|
|
200
|
+
let r = M.current, i = r.recovery ?? h(r.errorBus, b), s = t === "transport" ? i.reserveMutationReplay($) : void 0;
|
|
201
|
+
if (s === void 0) throw n;
|
|
138
202
|
try {
|
|
139
|
-
if (!await
|
|
203
|
+
if (!await i.waitForMutationReplaySupport($) || !await i.waitForProtocolReady($) || !s.isValid()) throw n;
|
|
140
204
|
let e = () => {
|
|
141
|
-
if (!
|
|
205
|
+
if (I(), !s.isValid()) throw n;
|
|
142
206
|
};
|
|
143
207
|
for (;;) {
|
|
144
208
|
e();
|
|
145
|
-
let t = await
|
|
209
|
+
let t = await l(M, b, x);
|
|
146
210
|
try {
|
|
147
|
-
|
|
211
|
+
o = await a(t.runtime, t.client, !0, e);
|
|
148
212
|
break;
|
|
149
213
|
} catch (t) {
|
|
150
214
|
let n = t;
|
|
151
215
|
if (n?._tag !== "MutationInFlight") throw t;
|
|
152
216
|
let r = typeof n.retryAfterMs == "number" && Number.isFinite(n.retryAfterMs) && n.retryAfterMs > 0 ? n.retryAfterMs : 1e3;
|
|
153
|
-
if (r >=
|
|
217
|
+
if (r >= i.replayWindowRemaining($)) throw t;
|
|
154
218
|
await new Promise((e) => setTimeout(e, r)), e();
|
|
155
219
|
}
|
|
156
220
|
}
|
|
157
221
|
} finally {
|
|
158
|
-
|
|
222
|
+
s.release();
|
|
159
223
|
}
|
|
160
224
|
}
|
|
161
|
-
|
|
225
|
+
I();
|
|
226
|
+
let c = L || M.current.descriptors[x]?.outputRetention === "none";
|
|
227
|
+
U((e) => e.owner === P ? {
|
|
228
|
+
...e,
|
|
229
|
+
data: c ? void 0 : o,
|
|
230
|
+
error: void 0
|
|
231
|
+
} : e), I(), z.settle({
|
|
162
232
|
status: "success",
|
|
163
|
-
output:
|
|
164
|
-
|
|
233
|
+
output: c ? void 0 : o,
|
|
234
|
+
...c ? { outputOmitted: !0 } : {}
|
|
235
|
+
}), I(), M.current.errorBus.emitSuccess({
|
|
165
236
|
source: "mutation",
|
|
166
|
-
tag:
|
|
167
|
-
}),
|
|
168
|
-
let
|
|
169
|
-
return
|
|
237
|
+
tag: x
|
|
238
|
+
}), I(), C.confirmByMutation(O), I(), i?.onSuccess?.(o, e), I();
|
|
239
|
+
let u = N(i?.notify?.success, o, e);
|
|
240
|
+
return I(), u !== void 0 && A?.success(u), o;
|
|
170
241
|
} catch (e) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
242
|
+
let t = F();
|
|
243
|
+
!Y || re(e) || t && X === void 0 && p(e, "handler") !== "transport" || (Q = "unknown");
|
|
244
|
+
let n = k(t ? e : new f("inactive"), J);
|
|
245
|
+
if (z.settle({
|
|
174
246
|
status: "error",
|
|
175
247
|
error: n
|
|
176
|
-
}),
|
|
248
|
+
}), C.revertByMutation(O), I(), U((e) => e.owner === P ? {
|
|
249
|
+
...e,
|
|
250
|
+
error: n
|
|
251
|
+
} : e), I(), Object.is(X, n) || (Y && J !== void 0 && p(e, "handler") === "handler" && c({
|
|
252
|
+
traceId: J,
|
|
253
|
+
tag: x
|
|
254
|
+
}), M.current.errorBus.emit({
|
|
177
255
|
source: "mutation",
|
|
178
|
-
tag:
|
|
256
|
+
tag: x,
|
|
179
257
|
error: n,
|
|
180
|
-
kind:
|
|
181
|
-
...
|
|
182
|
-
outcome:
|
|
183
|
-
...
|
|
184
|
-
}),
|
|
258
|
+
kind: Y ? p(e, "handler") : "client",
|
|
259
|
+
...Z === void 0 ? {} : { affectsTransport: Z() },
|
|
260
|
+
outcome: Y && p(e, "handler") === "transport" ? "unknown" : Y ? "known" : "not-started",
|
|
261
|
+
...J === void 0 ? {} : { traceId: J }
|
|
262
|
+
})), I(), m) return g(n);
|
|
185
263
|
throw n;
|
|
186
264
|
} finally {
|
|
187
|
-
|
|
265
|
+
E?.release(Q), _();
|
|
188
266
|
}
|
|
189
267
|
}, [
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
268
|
+
b,
|
|
269
|
+
x,
|
|
270
|
+
V,
|
|
271
|
+
P,
|
|
272
|
+
F,
|
|
273
|
+
I
|
|
274
|
+
]), J = H.owner === P ? H : {
|
|
275
|
+
pending: !1,
|
|
276
|
+
error: void 0,
|
|
277
|
+
data: void 0
|
|
278
|
+
};
|
|
279
|
+
return w(() => {
|
|
195
280
|
let e = {
|
|
196
|
-
mutate:
|
|
197
|
-
pending:
|
|
198
|
-
error:
|
|
199
|
-
data:
|
|
200
|
-
withOptimistic: (t) => (
|
|
201
|
-
withoutOptimistic: () => (
|
|
202
|
-
withConnectionSetup: (t) => (
|
|
281
|
+
mutate: q,
|
|
282
|
+
pending: J.pending,
|
|
283
|
+
error: J.error,
|
|
284
|
+
data: z ? void 0 : J.data,
|
|
285
|
+
withOptimistic: (t) => (L(), W.current = t, e),
|
|
286
|
+
withoutOptimistic: () => (L(), G.current = !0, e),
|
|
287
|
+
withConnectionSetup: (t) => (L(), g(q, _(t, b)), e)
|
|
203
288
|
};
|
|
204
289
|
return e;
|
|
205
290
|
}, [
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
291
|
+
q,
|
|
292
|
+
J.pending,
|
|
293
|
+
J.error,
|
|
294
|
+
J.data,
|
|
295
|
+
b,
|
|
209
296
|
L,
|
|
210
|
-
|
|
297
|
+
z
|
|
211
298
|
]);
|
|
212
299
|
};
|
|
213
|
-
export {
|
|
300
|
+
export { b as MutationSerialExecutionError, v as freshIdempotencyKey, M as getMutationNotifier, j as setMutationNotifier, F as useMutation, y as withIdempotencyKey };
|
package/dist/useOnRpcError.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { useFrameworkApi as e } from "./runtimeContext.js";
|
|
2
|
+
import { recoveryCoordinatorFor as t } from "./recoveryCoordinator.js";
|
|
3
3
|
import { useEffect as n, useRef as r } from "react";
|
|
4
4
|
// src/useOnRpcError.ts
|
|
5
5
|
var i = (i, a) => {
|
|
6
|
-
let o =
|
|
6
|
+
let o = e(i), s = o.recovery ?? t(o.errorBus, i), c = r(a);
|
|
7
7
|
c.current = a, n(() => s.onVisibleError((e) => c.current(e)), [s]);
|
|
8
|
-
}, a = (
|
|
9
|
-
let { errorBus: a } = t
|
|
8
|
+
}, a = (t, i) => {
|
|
9
|
+
let { errorBus: a } = e(t), o = r(i);
|
|
10
10
|
o.current = i, n(() => a.on((e) => o.current(e)), [a]);
|
|
11
11
|
};
|
|
12
12
|
export { a as useOnRawRpcError, i as useOnRpcError };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { readPreloadedSeedOutcome as e, readPreloadedSnapshot as t } from "./preloadSeed.js";
|
|
2
|
+
import { useFrameworkApi as n } from "./runtimeContext.js";
|
|
3
|
+
import { useSubscription as r } from "./useSubscription.js";
|
|
4
4
|
import { useSyncExternalStore as i } from "react";
|
|
5
5
|
// src/usePreloadedSubscription.ts
|
|
6
6
|
var a = () => !0, o = (e) => () => {};
|
|
7
7
|
function s(s, c, l = {}, u = {}) {
|
|
8
|
-
let { recovery: d } =
|
|
8
|
+
let { recovery: d } = n(s), f = i(d?.subscribe ?? o, d?.getPreloadSeedPermission ?? a, a), p = f ? t(s, c, l) : void 0, m = p === void 0 ? u : {
|
|
9
9
|
...u,
|
|
10
10
|
initialSnapshot: p
|
|
11
|
-
}, h =
|
|
12
|
-
return f &&
|
|
11
|
+
}, h = r(s, c, l, m);
|
|
12
|
+
return f && e(s, c, l) === "failed" ? {
|
|
13
13
|
...h,
|
|
14
14
|
preloadFailed: !0
|
|
15
15
|
} : h;
|
package/dist/useRpcCaller.js
CHANGED
|
@@ -1,16 +1,78 @@
|
|
|
1
1
|
import { useFrameworkApi as e } from "./runtimeContext.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { awaitResolvedApi as t, bindResolvedRpcInvocationOwner as n, captureRpcInvocationOwner as r, rpcInvocationOwnerCurrent as i } from "./awaitResolvedApi.js";
|
|
3
|
+
import { ConnectionPrerequisiteInvalidated as a } from "./connectionPrerequisite.js";
|
|
4
|
+
import { rpcCallOnce as o } from "./rpcCallOnce.js";
|
|
5
|
+
import { resolveByTag as s } from "./tagWalk.js";
|
|
6
|
+
import { useEffect as c, useMemo as l, useRef as u, useState as d } from "react";
|
|
6
7
|
// src/useRpcCaller.ts
|
|
7
|
-
var
|
|
8
|
-
let
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
var f = (f) => {
|
|
9
|
+
let p = e(f), m = u({
|
|
10
|
+
apiName: f,
|
|
11
|
+
handleRef: { current: p },
|
|
12
|
+
owner: void 0
|
|
13
|
+
});
|
|
14
|
+
m.current.apiName !== f && (m.current = {
|
|
15
|
+
apiName: f,
|
|
16
|
+
handleRef: { current: p },
|
|
17
|
+
owner: void 0
|
|
18
|
+
});
|
|
19
|
+
let h = m.current.handleRef;
|
|
20
|
+
h.current = p;
|
|
21
|
+
let g = r(p, f, "rpc.caller", m.current.owner);
|
|
22
|
+
m.current.owner = g;
|
|
23
|
+
let _ = g.subject, [, v] = d(0);
|
|
24
|
+
c(() => {
|
|
25
|
+
if (_.aborted) return;
|
|
26
|
+
let e = () => v((e) => e + 1);
|
|
27
|
+
return _.addEventListener("abort", e, { once: !0 }), () => _.removeEventListener("abort", e);
|
|
28
|
+
}, [_]);
|
|
29
|
+
let y = () => {
|
|
30
|
+
if (!i(g, h.current)) throw new a("inactive");
|
|
31
|
+
};
|
|
32
|
+
return l(() => Object.freeze({
|
|
33
|
+
call: (e, t, n) => o(h, f, e, t, n?.signal, "[rpc.call]", g),
|
|
34
|
+
query: async (e, n, r) => {
|
|
35
|
+
y();
|
|
36
|
+
let i = await t(h, f, e, r?.signal);
|
|
37
|
+
if (i.descriptors[e]?.kind !== "query") throw Error(`Voltro: query '${e}' is not a registered query on api '${f}'.`);
|
|
38
|
+
let a = await o({ current: i }, f, e, n ?? {}, r?.signal, "[rpc.query]", g);
|
|
39
|
+
return y(), a;
|
|
40
|
+
},
|
|
41
|
+
subscribe: (e, r, a) => {
|
|
42
|
+
y();
|
|
43
|
+
let o = new AbortController(), c = g.subject, l = !1, u, d = c, p = () => {
|
|
44
|
+
l || (l = !0, o.abort(), d.removeEventListener("abort", p), u?.());
|
|
45
|
+
};
|
|
46
|
+
return d.addEventListener("abort", p, { once: !0 }), t(h, f, e, o.signal).then((t) => {
|
|
47
|
+
if (l) return;
|
|
48
|
+
if (c.aborted) {
|
|
49
|
+
p();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (n(g, t), y(), t.descriptors[e]?.kind !== "query") throw Error(`[rpc.subscribe] ${e}: only queries can be subscribed to`);
|
|
53
|
+
if (d.removeEventListener("abort", p), d = g.subject, d.aborted) {
|
|
54
|
+
p();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
d.addEventListener("abort", p, { once: !0 });
|
|
58
|
+
let o, f = -2, m, _, v = () => {
|
|
59
|
+
if (l || !o) return;
|
|
60
|
+
if (!i(g, h.current)) {
|
|
61
|
+
p();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
let e = o.getSnapshot();
|
|
65
|
+
e.error !== void 0 && e.error !== m && (m = e.error, a.onError?.(e.error)), !l && e.revision >= 0 && e.data !== void 0 && (e.revision !== f || e.data !== _) && (f = e.revision, _ = e.data, a.onValue(e.data));
|
|
66
|
+
};
|
|
67
|
+
o = t.cache.subscribe([e, r], () => s(t.client, e)(r), t.runtime, v), u = o.unsubscribe, l ? u() : v();
|
|
68
|
+
}).catch((e) => {
|
|
69
|
+
!l && i(g, h.current) && a.onError?.(e);
|
|
70
|
+
}), Object.freeze({ unsubscribe: p });
|
|
71
|
+
}
|
|
72
|
+
}), [
|
|
73
|
+
f,
|
|
74
|
+
h,
|
|
75
|
+
g
|
|
76
|
+
]);
|
|
15
77
|
};
|
|
16
|
-
export {
|
|
78
|
+
export { f as useRpcCaller };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { captureRpcInvocationOwner as e, rpcInvocationOwnerCurrent as t } from "./awaitResolvedApi.js";
|
|
2
|
+
import { ConnectionPrerequisiteInvalidated as n } from "./connectionPrerequisite.js";
|
|
3
|
+
import { useCallback as r, useEffect as i, useRef as a, useState as o } from "react";
|
|
4
|
+
// src/useRpcInvocationOwner.ts
|
|
5
|
+
var s = (s, c, l) => {
|
|
6
|
+
let u = a(void 0), d = e(s.current, c, l, u.current);
|
|
7
|
+
u.current = d;
|
|
8
|
+
let f = d.subject, p = a(!0), [, m] = o(0);
|
|
9
|
+
i(() => (p.current = !0, () => {
|
|
10
|
+
p.current = !1;
|
|
11
|
+
}), []), i(() => {
|
|
12
|
+
let e = d.subject;
|
|
13
|
+
if (e.aborted) return;
|
|
14
|
+
let t = () => m((e) => e + 1);
|
|
15
|
+
return e.addEventListener("abort", t, { once: !0 }), () => e.removeEventListener("abort", t);
|
|
16
|
+
}, [d, f]);
|
|
17
|
+
let h = r(() => u.current === d && t(d, s.current), [d, s]), g = r(() => p.current && h(), [h]);
|
|
18
|
+
return {
|
|
19
|
+
owner: d,
|
|
20
|
+
current: g,
|
|
21
|
+
assertCurrent: r(() => {
|
|
22
|
+
if (!g()) throw new n("inactive");
|
|
23
|
+
}, [g]),
|
|
24
|
+
assertOwnerCurrent: r(() => {
|
|
25
|
+
if (!h()) throw new n("inactive");
|
|
26
|
+
}, [h])
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export { s as useRpcInvocationOwner };
|