@voltro/client 0.89.2 → 0.90.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 +1822 -0
- package/README.md +22 -0
- package/dist/analytics.d.ts +68 -0
- package/dist/analytics.js +1 -0
- package/dist/awaitResolvedApi.js +45 -19
- package/dist/bootstrap.d.ts +0 -115
- package/dist/connectionSetupController.js +93 -61
- package/dist/index.d.ts +148 -162
- package/dist/index.js +87 -85
- package/dist/invocationWait.js +14 -0
- package/dist/mutationsBus.js +92 -35
- package/dist/outbox.js +147 -118
- package/dist/outboxState.js +7 -0
- 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/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 +146 -72
- package/dist/useMutation.js +220 -133
- package/dist/useRpcCaller.js +74 -12
- package/dist/useRpcInvocationOwner.js +29 -0
- package/dist/useSubscription.js +52 -49
- package/dist/useTranscription.js +114 -42
- package/dist/useUpload.js +160 -242
- package/dist/useWorkflow.js +111 -246
- package/dist/workflowClient.js +126 -0
- package/package.json +7 -2
package/dist/useAction.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { publishClientTrace as e } from "./traceBus.js";
|
|
2
|
-
import { rpcErrorKind as
|
|
3
|
-
import { useFrameworkApi as
|
|
4
|
-
import { resolveByTag as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
1
|
+
import { publishClientTrace as e, publishClientTraceRefusal as t } from "./traceBus.js";
|
|
2
|
+
import { rpcErrorKind as n } from "./rpcErrorKind.js";
|
|
3
|
+
import { useFrameworkApi as r } from "./runtimeContext.js";
|
|
4
|
+
import { resolveByTag as i } from "./tagWalk.js";
|
|
5
|
+
import { reportUnknownRpcTag as a } from "./unknownRpcTag.js";
|
|
6
|
+
import { deferRpcMethod as o, runRpcPromise as s } from "./runRpc.js";
|
|
7
|
+
import { ConnectionPrerequisiteInvalidated as c } from "./connectionPrerequisite.js";
|
|
8
|
+
import { awaitReadyApi as l, bindResolvedRpcInvocationOwner as u } from "./awaitResolvedApi.js";
|
|
9
|
+
import { useRpcInvocationOwner as d } from "./useRpcInvocationOwner.js";
|
|
10
|
+
import { omitMutationInputs as f, omitMutationOutputs as p, startMutation as m } from "./mutationsBus.js";
|
|
11
|
+
import { freshIdempotencyKey as h, withIdempotencyKey as g } from "./mutationIdentity.js";
|
|
12
|
+
import { getMutationNotifier as _ } from "./useMutation.js";
|
|
13
|
+
import { waitForInvocation as v } from "./invocationWait.js";
|
|
14
|
+
import { useCallback as y, useEffect as b, useMemo as x, useRef as S, useState as C } from "react";
|
|
15
|
+
import { Effect as w } from "effect";
|
|
12
16
|
// src/useAction.ts
|
|
13
|
-
var
|
|
17
|
+
var T = (e, t) => {
|
|
14
18
|
if (t === void 0 || typeof e != "object" || !e) return e;
|
|
15
19
|
try {
|
|
16
20
|
Object.defineProperty(e, "__voltroTraceId", {
|
|
@@ -20,81 +24,151 @@ var g = (e, t) => {
|
|
|
20
24
|
});
|
|
21
25
|
} catch {}
|
|
22
26
|
return e;
|
|
23
|
-
},
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
}, E = (e, t, n) => typeof e == "function" ? e(t, n) : e, D = 0, O = () => `act_${++D}`, k = (D, k) => {
|
|
28
|
+
let A = r(D), { descriptors: j } = A, M = j[k]?.outputRetention === "none", N = j[k]?.clientHistory?.input === "omit", P = S(A);
|
|
29
|
+
P.current = A;
|
|
30
|
+
let { owner: F, current: I, assertCurrent: L } = d(P, D, k);
|
|
31
|
+
if (process.env.NODE_ENV !== "production") {
|
|
32
|
+
a("useAction", D, k, j);
|
|
33
|
+
let e = j[k]?.kind;
|
|
34
|
+
e !== void 0 && e !== "action" && console.error(`[@voltro/client] useAction('${D}', '${k}') targets a ${e}, not an action. Use ${e === "mutation" ? "useMutation" : e === "workflow" ? "useWorkflow" : `the ${e} hook`} instead.`);
|
|
28
35
|
}
|
|
29
|
-
let [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
40
|
-
|
|
36
|
+
let [R, z] = C(() => ({
|
|
37
|
+
owner: F,
|
|
38
|
+
pending: 0,
|
|
39
|
+
error: void 0,
|
|
40
|
+
lastResult: void 0
|
|
41
|
+
}));
|
|
42
|
+
b(() => {
|
|
43
|
+
M && (z((e) => e.lastResult === void 0 ? e : {
|
|
44
|
+
...e,
|
|
45
|
+
lastResult: void 0
|
|
46
|
+
}), p(D, k));
|
|
47
|
+
}, [
|
|
48
|
+
M,
|
|
49
|
+
D,
|
|
50
|
+
k
|
|
51
|
+
]), b(() => {
|
|
52
|
+
N && f(D, k);
|
|
53
|
+
}, [
|
|
54
|
+
N,
|
|
55
|
+
D,
|
|
56
|
+
k
|
|
57
|
+
]);
|
|
58
|
+
let B = y(async (r, a) => {
|
|
59
|
+
let d = a?.signal, f = () => {
|
|
60
|
+
if (L(), d?.aborted) throw new DOMException("action aborted", "AbortError");
|
|
61
|
+
};
|
|
62
|
+
f();
|
|
63
|
+
let p = F.subject, y = a?.onError !== void 0 || a?.notify?.error !== void 0;
|
|
64
|
+
z((e) => ({
|
|
65
|
+
owner: F,
|
|
66
|
+
pending: e.owner === F ? e.pending + 1 : 1,
|
|
67
|
+
error: void 0,
|
|
68
|
+
lastResult: e.owner === F ? e.lastResult : void 0
|
|
69
|
+
}));
|
|
70
|
+
let b = O(), x = a?.idempotencyKey ?? h(), S = !1, C = () => {
|
|
71
|
+
let e = P.current.descriptors[k], t = !e || e.clientHistory?.input === "omit";
|
|
72
|
+
return S = e?.outputRetention === "none", m({
|
|
73
|
+
id: b,
|
|
74
|
+
apiName: D,
|
|
75
|
+
tag: k,
|
|
76
|
+
input: t ? void 0 : r,
|
|
77
|
+
kind: "action",
|
|
78
|
+
...t ? { inputOmitted: !0 } : {},
|
|
79
|
+
...S ? { outputOmitted: !0 } : {}
|
|
80
|
+
}, F.subject);
|
|
81
|
+
}, A = F.resolved ? C() : void 0, j, M = !1;
|
|
41
82
|
try {
|
|
42
|
-
let
|
|
43
|
-
|
|
83
|
+
let t = await l(P, D, k, d);
|
|
84
|
+
if (p.aborted) throw new c("inactive");
|
|
85
|
+
u(F, t), f(), A ??= C(), f();
|
|
86
|
+
let { runtime: n, client: m } = t, h = i(m, k), y = w.currentSpan.pipe(w.tap((t) => w.sync(() => {
|
|
87
|
+
j = t.traceId, e({
|
|
44
88
|
traceId: t.traceId,
|
|
45
89
|
spanId: t.spanId,
|
|
46
90
|
source: "action",
|
|
47
|
-
tag:
|
|
91
|
+
tag: k
|
|
48
92
|
});
|
|
49
|
-
})),
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
93
|
+
})), w.catch(() => w.void), w.andThen(o(() => {
|
|
94
|
+
f();
|
|
95
|
+
let e = h(r);
|
|
96
|
+
return M = !0, g(e, x);
|
|
97
|
+
}))).pipe(w.withSpan(`client.action.${k}`, { attributes: {
|
|
98
|
+
"voltro.api": D,
|
|
99
|
+
"voltro.actionId": b,
|
|
100
|
+
"rpc.tag": k
|
|
101
|
+
} })), T = await v(s(n, y), d, f);
|
|
102
|
+
f();
|
|
103
|
+
let O = S || P.current.descriptors[k]?.outputRetention === "none";
|
|
104
|
+
z((e) => e.owner === F ? {
|
|
105
|
+
...e,
|
|
106
|
+
error: void 0,
|
|
107
|
+
lastResult: O ? void 0 : T
|
|
108
|
+
} : e), f(), A?.settle({
|
|
57
109
|
status: "success",
|
|
58
|
-
output:
|
|
59
|
-
|
|
110
|
+
output: O ? void 0 : T,
|
|
111
|
+
...O ? { outputOmitted: !0 } : {}
|
|
112
|
+
}), f(), P.current.errorBus.emitSuccess({
|
|
60
113
|
source: "action",
|
|
61
|
-
tag:
|
|
62
|
-
}),
|
|
63
|
-
let
|
|
64
|
-
return
|
|
114
|
+
tag: k
|
|
115
|
+
}), f(), a?.onSuccess?.(T, r), f();
|
|
116
|
+
let N = E(a?.notify?.success, T, r);
|
|
117
|
+
return f(), N !== void 0 && _()?.success(N), f(), T;
|
|
65
118
|
} catch (e) {
|
|
66
|
-
let
|
|
67
|
-
if (
|
|
119
|
+
let i = I() && !d?.aborted, o = T(I() ? d?.aborted ? new DOMException("action aborted", "AbortError") : e : new c("inactive"), j);
|
|
120
|
+
if (A?.settle({
|
|
68
121
|
status: "error",
|
|
69
|
-
error:
|
|
70
|
-
}),
|
|
122
|
+
error: o
|
|
123
|
+
}), !i) throw o;
|
|
124
|
+
if (f(), z((e) => e.owner === F ? {
|
|
125
|
+
...e,
|
|
126
|
+
error: o
|
|
127
|
+
} : e), f(), M && j !== void 0 && n(e, "handler") === "handler" && t({
|
|
128
|
+
traceId: j,
|
|
129
|
+
tag: k
|
|
130
|
+
}), P.current.errorBus.emit({
|
|
71
131
|
source: "action",
|
|
72
|
-
tag:
|
|
73
|
-
error:
|
|
74
|
-
kind:
|
|
75
|
-
outcome:
|
|
76
|
-
...
|
|
77
|
-
}), f) {
|
|
78
|
-
|
|
79
|
-
let e =
|
|
80
|
-
e !== void 0 &&
|
|
132
|
+
tag: k,
|
|
133
|
+
error: o,
|
|
134
|
+
kind: M ? n(e, "handler") : "client",
|
|
135
|
+
outcome: M && n(e, "handler") === "transport" ? "unknown" : M ? "known" : "not-started",
|
|
136
|
+
...j === void 0 ? {} : { traceId: j }
|
|
137
|
+
}), f(), y) {
|
|
138
|
+
a?.onError?.(o, r), f();
|
|
139
|
+
let e = E(a?.notify?.error, o, r);
|
|
140
|
+
f(), e !== void 0 && _()?.error(e), f();
|
|
81
141
|
return;
|
|
82
142
|
}
|
|
83
|
-
throw
|
|
143
|
+
throw o;
|
|
84
144
|
} finally {
|
|
85
|
-
|
|
145
|
+
I() && z((e) => e.owner === F ? {
|
|
146
|
+
...e,
|
|
147
|
+
pending: Math.max(0, e.pending - 1)
|
|
148
|
+
} : e);
|
|
86
149
|
}
|
|
87
|
-
}, [
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
150
|
+
}, [
|
|
151
|
+
D,
|
|
152
|
+
k,
|
|
153
|
+
F,
|
|
154
|
+
I,
|
|
155
|
+
L
|
|
156
|
+
]), V = R.owner === F ? R : {
|
|
157
|
+
pending: 0,
|
|
158
|
+
error: void 0,
|
|
159
|
+
lastResult: void 0
|
|
160
|
+
};
|
|
161
|
+
return x(() => ({
|
|
162
|
+
run: B,
|
|
163
|
+
pending: V.pending > 0,
|
|
164
|
+
error: V.error,
|
|
165
|
+
lastResult: M ? void 0 : V.lastResult
|
|
93
166
|
}), [
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
167
|
+
B,
|
|
168
|
+
V.pending,
|
|
169
|
+
V.error,
|
|
170
|
+
V.lastResult,
|
|
171
|
+
M
|
|
98
172
|
]);
|
|
99
173
|
};
|
|
100
|
-
export {
|
|
174
|
+
export { k as useAction };
|