@voltro/client 0.90.0 → 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.
@@ -1,17 +1,17 @@
1
- import { publishClientTrace as e, publishClientTraceRefusal as t } from "./traceBus.js";
2
- import { rpcErrorKind as n } from "./rpcErrorKind.js";
3
- import { recoveryCoordinatorFor as r } from "./recoveryCoordinator.js";
4
- import { useFrameworkApi as i } from "./runtimeContext.js";
5
- import { connectionScopeForRuntime as a } from "./connectionScope.js";
6
- import { resolveByTag as o } from "./tagWalk.js";
7
- import { reportUnknownRpcTag as s } from "./unknownRpcTag.js";
8
- import { deferRpcMethod as c, runRpcPromise as ee } from "./runRpc.js";
9
- import { ConnectionPrerequisiteInvalidated as l } from "./connectionPrerequisite.js";
10
- import { awaitResolvedApi as u, bindResolvedRpcInvocationOwner as d } from "./awaitResolvedApi.js";
11
- import { useRpcInvocationOwner as f } from "./useRpcInvocationOwner.js";
12
- import { omitMutationInputs as p, omitMutationOutputs as m, startMutation as h } from "./mutationsBus.js";
13
- import { bindMutationConnectionSetup as g, captureMutationConnectionSetup as te, connectionSetupOwner as _ } from "./mutationConnectionSetup.js";
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";
14
13
  import { freshIdempotencyKey as v, withIdempotencyKey as y } from "./mutationIdentity.js";
14
+ import { connectionScopeForRuntime as te } from "./connectionScope.js";
15
15
  import { MutationSerialExecutionError as b, makeMutationSerialExecution as x } from "./mutationSerialExecution.js";
16
16
  import { useCallback as S, useEffect as C, useMemo as w, useRef as T, useState as E } from "react";
17
17
  import { Effect as D } from "effect";
@@ -42,11 +42,11 @@ var O = /* @__PURE__ */ new WeakMap(), ne = (e, t, n) => {
42
42
  },
43
43
  forTag: (n, r) => e.forTag(n, r, t)
44
44
  }), F = (b, x) => {
45
- let O = i(b), { descriptors: j } = O, M = T(O);
45
+ let O = e(b), { descriptors: j } = O, M = T(O);
46
46
  M.current = O;
47
- let { owner: P, current: F, assertCurrent: I, assertOwnerCurrent: L } = f(M, b, x), R = j[x], z = R?.outputRetention === "none", B = R?.clientHistory?.input === "omit", V = R?.targets;
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;
48
48
  if (process.env.NODE_ENV !== "production") {
49
- s("useMutation", b, x, j);
49
+ m("useMutation", b, x, j);
50
50
  let e = R?.kind;
51
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.`);
52
52
  }
@@ -60,13 +60,13 @@ var O = /* @__PURE__ */ new WeakMap(), ne = (e, t, n) => {
60
60
  z && (U((e) => e.data === void 0 ? e : {
61
61
  ...e,
62
62
  data: void 0
63
- }), m(b, x));
63
+ }), a(b, x));
64
64
  }, [
65
65
  z,
66
66
  b,
67
67
  x
68
68
  ]), C(() => {
69
- B && p(b, x);
69
+ B && i(b, x);
70
70
  }, [
71
71
  B,
72
72
  b,
@@ -80,18 +80,18 @@ var O = /* @__PURE__ */ new WeakMap(), ne = (e, t, n) => {
80
80
  owner: P,
81
81
  count: 0
82
82
  }, W.current = null, G.current = !1);
83
- let q = S(async (i, s) => {
83
+ let q = S(async (e, i) => {
84
84
  I();
85
- let f = P.subject, p = K.current, m = s?.onError !== void 0 || s?.notify?.error !== void 0, g = (e) => {
86
- I(), s?.onError?.(e, i), I();
87
- let t = N(s?.notify?.error, e, i);
88
- I(), t !== void 0 && A?.error(t);
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);
89
89
  };
90
- p.count += 1;
90
+ d.count += 1;
91
91
  let _ = () => {
92
- --p.count, F() && U((e) => e.owner === P ? {
92
+ --d.count, F() && U((e) => e.owner === P ? {
93
93
  ...e,
94
- pending: p.count > 0
94
+ pending: d.count > 0
95
95
  } : e);
96
96
  };
97
97
  U((e) => ({
@@ -102,17 +102,17 @@ var O = /* @__PURE__ */ new WeakMap(), ne = (e, t, n) => {
102
102
  }));
103
103
  let S, C, w, T, E;
104
104
  try {
105
- T = te(q);
106
- let e = M.current.descriptors[x]?.serialize;
107
- if (e !== void 0) {
108
- let t = M.current, n = t.recovery ?? r(t.errorBus, b);
109
- E = ne(t.descriptors, x, e.maxPending ?? 32).reserve(e.key(i), n.subjectSignal);
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);
110
110
  }
111
- let t = await u(M, b, x);
112
- if (f.aborted) throw new l("inactive");
113
- d(P, t), I(), {runtime: S, cache: C, client: w} = t;
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;
114
114
  } catch (e) {
115
- if (E?.release(), _(), !F()) throw new l("inactive");
115
+ if (E?.release(), _(), !F()) throw new f("inactive");
116
116
  if (U((t) => t.owner === P ? {
117
117
  ...t,
118
118
  error: e
@@ -125,21 +125,21 @@ var O = /* @__PURE__ */ new WeakMap(), ne = (e, t, n) => {
125
125
  }), m) return g(e);
126
126
  throw e;
127
127
  }
128
- let O = ie(), j = s?.idempotencyKey ?? v(), L = M.current.descriptors[x]?.outputRetention === "none", R = !M.current.descriptors[x] || M.current.descriptors[x]?.clientHistory?.input === "omit", z = h({
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
129
  id: O,
130
130
  apiName: b,
131
131
  tag: x,
132
- input: R ? void 0 : i,
132
+ input: R ? void 0 : e,
133
133
  ...R ? { inputOmitted: !0 } : {},
134
134
  ...L ? { outputOmitted: !0 } : {}
135
135
  }, P.subject), B = W.current, H = G.current;
136
136
  try {
137
- I(), B ? B(ae(C, O), i) : !H && V && V.length > 0 && C.autoApply(V, i, O);
137
+ I(), B ? B(ae(C, O), e) : !H && V && V.length > 0 && C.autoApply(V, e, O);
138
138
  } catch (e) {
139
139
  if (E?.release(), _(), C.revertByMutation(O), z.settle({
140
140
  status: "error",
141
141
  error: e
142
- }), !F()) throw new l("inactive");
142
+ }), !F()) throw new f("inactive");
143
143
  if (U((t) => t.owner === P ? {
144
144
  ...t,
145
145
  error: e
@@ -150,117 +150,117 @@ var O = /* @__PURE__ */ new WeakMap(), ne = (e, t, n) => {
150
150
  try {
151
151
  if (E) {
152
152
  await E.ready, I(), E.assertActive();
153
- let e = await u(M, b, x);
153
+ let e = await l(M, b, x);
154
154
  I(), S = e.runtime, w = e.client;
155
155
  }
156
- let t = async (t, n, r, s) => {
156
+ let a = async (i, a, o, c) => {
157
157
  I();
158
- let l = a(t), u = l?.getSnapshot();
159
- Z = l === void 0 ? void 0 : () => M.current.runtime === t && u !== void 0 && l.getSnapshot() === u, s?.(), E?.assertActive();
160
- let d = T === void 0 ? void 0 : await T.prepare(t, n);
161
- u = l?.getSnapshot(), I(), s?.();
162
- let f = o(n, x), p = y(c(() => {
163
- I(), s?.(), E?.assertActive();
164
- let e = f(i);
165
- return Y = !0, e;
166
- }), j), m = D.currentSpan.pipe(D.tap((t) => D.sync(() => {
167
- J = t.traceId, e({
168
- traceId: t.traceId,
169
- spanId: t.spanId,
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,
170
170
  source: "mutation",
171
171
  tag: x
172
172
  });
173
173
  })), D.catch(() => D.void), D.andThen(D.try({
174
174
  try: () => {
175
- I(), s?.(), E?.assertActive();
175
+ I(), c?.(), E?.assertActive();
176
176
  },
177
177
  catch: (e) => e
178
178
  })), D.andThen(p)).pipe(D.withSpan(`client.mutation.${x}`, { attributes: {
179
179
  "voltro.api": b,
180
180
  "voltro.mutationId": O,
181
181
  "rpc.tag": x,
182
- "voltro.replay": r
182
+ "voltro.replay": o
183
183
  } }));
184
- return d === void 0 ? ee(t, m) : d.run(m);
185
- }, l;
184
+ return d === void 0 ? n(i, m) : d.run(m);
185
+ }, o;
186
186
  try {
187
- l = await t(S, w, !1);
187
+ o = await a(S, w, !1);
188
188
  } catch (e) {
189
189
  I();
190
- let i = n(e, Y ? "handler" : "client"), a = k(e, J);
191
- i === "transport" && (M.current.errorBus.emit({
190
+ let t = p(e, Y ? "handler" : "client"), n = k(e, J);
191
+ t === "transport" && (M.current.errorBus.emit({
192
192
  source: "mutation",
193
193
  tag: x,
194
- error: a,
195
- kind: i,
194
+ error: n,
195
+ kind: t,
196
196
  ...Z === void 0 ? {} : { affectsTransport: Z() },
197
197
  outcome: Y ? "unknown" : "not-started",
198
198
  ...J === void 0 ? {} : { traceId: J }
199
- }), X = a), I();
200
- let o = M.current, s = o.recovery ?? r(o.errorBus, b), c = i === "transport" ? s.reserveMutationReplay($) : void 0;
201
- if (c === void 0) throw a;
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;
202
202
  try {
203
- if (!await s.waitForMutationReplaySupport($) || !await s.waitForProtocolReady($) || !c.isValid()) throw a;
203
+ if (!await i.waitForMutationReplaySupport($) || !await i.waitForProtocolReady($) || !s.isValid()) throw n;
204
204
  let e = () => {
205
- if (I(), !c.isValid()) throw a;
205
+ if (I(), !s.isValid()) throw n;
206
206
  };
207
207
  for (;;) {
208
208
  e();
209
- let n = await u(M, b, x);
209
+ let t = await l(M, b, x);
210
210
  try {
211
- l = await t(n.runtime, n.client, !0, e);
211
+ o = await a(t.runtime, t.client, !0, e);
212
212
  break;
213
213
  } catch (t) {
214
214
  let n = t;
215
215
  if (n?._tag !== "MutationInFlight") throw t;
216
216
  let r = typeof n.retryAfterMs == "number" && Number.isFinite(n.retryAfterMs) && n.retryAfterMs > 0 ? n.retryAfterMs : 1e3;
217
- if (r >= s.replayWindowRemaining($)) throw t;
217
+ if (r >= i.replayWindowRemaining($)) throw t;
218
218
  await new Promise((e) => setTimeout(e, r)), e();
219
219
  }
220
220
  }
221
221
  } finally {
222
- c.release();
222
+ s.release();
223
223
  }
224
224
  }
225
225
  I();
226
- let d = L || M.current.descriptors[x]?.outputRetention === "none";
226
+ let c = L || M.current.descriptors[x]?.outputRetention === "none";
227
227
  U((e) => e.owner === P ? {
228
228
  ...e,
229
- data: d ? void 0 : l,
229
+ data: c ? void 0 : o,
230
230
  error: void 0
231
231
  } : e), I(), z.settle({
232
232
  status: "success",
233
- output: d ? void 0 : l,
234
- ...d ? { outputOmitted: !0 } : {}
233
+ output: c ? void 0 : o,
234
+ ...c ? { outputOmitted: !0 } : {}
235
235
  }), I(), M.current.errorBus.emitSuccess({
236
236
  source: "mutation",
237
237
  tag: x
238
- }), I(), C.confirmByMutation(O), I(), s?.onSuccess?.(l, i), I();
239
- let f = N(s?.notify?.success, l, i);
240
- return I(), f !== void 0 && A?.success(f), l;
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;
241
241
  } catch (e) {
242
- let r = F();
243
- !Y || re(e) || r && X === void 0 && n(e, "handler") !== "transport" || (Q = "unknown");
244
- let i = k(r ? e : new l("inactive"), J);
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
245
  if (z.settle({
246
246
  status: "error",
247
- error: i
247
+ error: n
248
248
  }), C.revertByMutation(O), I(), U((e) => e.owner === P ? {
249
249
  ...e,
250
- error: i
251
- } : e), I(), Object.is(X, i) || (Y && J !== void 0 && n(e, "handler") === "handler" && t({
250
+ error: n
251
+ } : e), I(), Object.is(X, n) || (Y && J !== void 0 && p(e, "handler") === "handler" && c({
252
252
  traceId: J,
253
253
  tag: x
254
254
  }), M.current.errorBus.emit({
255
255
  source: "mutation",
256
256
  tag: x,
257
- error: i,
258
- kind: Y ? n(e, "handler") : "client",
257
+ error: n,
258
+ kind: Y ? p(e, "handler") : "client",
259
259
  ...Z === void 0 ? {} : { affectsTransport: Z() },
260
- outcome: Y && n(e, "handler") === "transport" ? "unknown" : Y ? "known" : "not-started",
260
+ outcome: Y && p(e, "handler") === "transport" ? "unknown" : Y ? "known" : "not-started",
261
261
  ...J === void 0 ? {} : { traceId: J }
262
- })), I(), m) return g(i);
263
- throw i;
262
+ })), I(), m) return g(n);
263
+ throw n;
264
264
  } finally {
265
265
  E?.release(Q), _();
266
266
  }
@@ -1,12 +1,12 @@
1
- import { recoveryCoordinatorFor as e } from "./recoveryCoordinator.js";
2
- import { useFrameworkApi as t } from "./runtimeContext.js";
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 = t(i), s = o.recovery ?? e(o.errorBus, i), c = r(a);
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 = (e, i) => {
9
- let { errorBus: a } = t(e), o = r(i);
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 { useFrameworkApi as e } from "./runtimeContext.js";
2
- import { useSubscription as t } from "./useSubscription.js";
3
- import { readPreloadedSeedOutcome as n, readPreloadedSnapshot as r } from "./preloadSeed.js";
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 } = e(s), f = i(d?.subscribe ?? o, d?.getPreloadSeedPermission ?? a, a), p = f ? r(s, c, l) : void 0, m = p === void 0 ? u : {
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 = t(s, c, l, m);
12
- return f && n(s, c, l) === "failed" ? {
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;
@@ -1,8 +1,8 @@
1
1
  import { useFrameworkApi as e } from "./runtimeContext.js";
2
- import { resolveByTag as t } from "./tagWalk.js";
3
- import { ConnectionPrerequisiteInvalidated as n } from "./connectionPrerequisite.js";
4
- import { awaitResolvedApi as r, bindResolvedRpcInvocationOwner as i, captureRpcInvocationOwner as a, rpcInvocationOwnerCurrent as o } from "./awaitResolvedApi.js";
5
- import { rpcCallOnce as s } from "./rpcCallOnce.js";
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
6
  import { useEffect as c, useMemo as l, useRef as u, useState as d } from "react";
7
7
  // src/useRpcCaller.ts
8
8
  var f = (f) => {
@@ -18,7 +18,7 @@ var f = (f) => {
18
18
  });
19
19
  let h = m.current.handleRef;
20
20
  h.current = p;
21
- let g = a(p, f, "rpc.caller", m.current.owner);
21
+ let g = r(p, f, "rpc.caller", m.current.owner);
22
22
  m.current.owner = g;
23
23
  let _ = g.subject, [, v] = d(0);
24
24
  c(() => {
@@ -27,46 +27,46 @@ var f = (f) => {
27
27
  return _.addEventListener("abort", e, { once: !0 }), () => _.removeEventListener("abort", e);
28
28
  }, [_]);
29
29
  let y = () => {
30
- if (!o(g, h.current)) throw new n("inactive");
30
+ if (!i(g, h.current)) throw new a("inactive");
31
31
  };
32
32
  return l(() => Object.freeze({
33
- call: (e, t, n) => s(h, f, e, t, n?.signal, "[rpc.call]", g),
34
- query: async (e, t, n) => {
33
+ call: (e, t, n) => o(h, f, e, t, n?.signal, "[rpc.call]", g),
34
+ query: async (e, n, r) => {
35
35
  y();
36
- let i = await r(h, f, e, n?.signal);
36
+ let i = await t(h, f, e, r?.signal);
37
37
  if (i.descriptors[e]?.kind !== "query") throw Error(`Voltro: query '${e}' is not a registered query on api '${f}'.`);
38
- let a = await s({ current: i }, f, e, t ?? {}, n?.signal, "[rpc.query]", g);
38
+ let a = await o({ current: i }, f, e, n ?? {}, r?.signal, "[rpc.query]", g);
39
39
  return y(), a;
40
40
  },
41
- subscribe: (e, n, a) => {
41
+ subscribe: (e, r, a) => {
42
42
  y();
43
- let s = new AbortController(), c = g.subject, l = !1, u, d = c, p = () => {
44
- l || (l = !0, s.abort(), d.removeEventListener("abort", p), u?.());
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
45
  };
46
- return d.addEventListener("abort", p, { once: !0 }), r(h, f, e, s.signal).then((r) => {
46
+ return d.addEventListener("abort", p, { once: !0 }), t(h, f, e, o.signal).then((t) => {
47
47
  if (l) return;
48
48
  if (c.aborted) {
49
49
  p();
50
50
  return;
51
51
  }
52
- if (i(g, r), y(), r.descriptors[e]?.kind !== "query") throw Error(`[rpc.subscribe] ${e}: only queries can be subscribed to`);
52
+ if (n(g, t), y(), t.descriptors[e]?.kind !== "query") throw Error(`[rpc.subscribe] ${e}: only queries can be subscribed to`);
53
53
  if (d.removeEventListener("abort", p), d = g.subject, d.aborted) {
54
54
  p();
55
55
  return;
56
56
  }
57
57
  d.addEventListener("abort", p, { once: !0 });
58
- let s, f = -2, m, _, v = () => {
59
- if (l || !s) return;
60
- if (!o(g, h.current)) {
58
+ let o, f = -2, m, _, v = () => {
59
+ if (l || !o) return;
60
+ if (!i(g, h.current)) {
61
61
  p();
62
62
  return;
63
63
  }
64
- let e = s.getSnapshot();
64
+ let e = o.getSnapshot();
65
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
66
  };
67
- s = r.cache.subscribe([e, n], () => t(r.client, e)(n), r.runtime, v), u = s.unsubscribe, l ? u() : v();
67
+ o = t.cache.subscribe([e, r], () => s(t.client, e)(r), t.runtime, v), u = o.unsubscribe, l ? u() : v();
68
68
  }).catch((e) => {
69
- !l && o(g, h.current) && a.onError?.(e);
69
+ !l && i(g, h.current) && a.onError?.(e);
70
70
  }), Object.freeze({ unsubscribe: p });
71
71
  }
72
72
  }), [
@@ -1,9 +1,9 @@
1
- import { ConnectionPrerequisiteInvalidated as e } from "./connectionPrerequisite.js";
2
- import { captureRpcInvocationOwner as t, rpcInvocationOwnerCurrent as n } from "./awaitResolvedApi.js";
1
+ import { captureRpcInvocationOwner as e, rpcInvocationOwnerCurrent as t } from "./awaitResolvedApi.js";
2
+ import { ConnectionPrerequisiteInvalidated as n } from "./connectionPrerequisite.js";
3
3
  import { useCallback as r, useEffect as i, useRef as a, useState as o } from "react";
4
4
  // src/useRpcInvocationOwner.ts
5
5
  var s = (s, c, l) => {
6
- let u = a(void 0), d = t(s.current, c, l, u.current);
6
+ let u = a(void 0), d = e(s.current, c, l, u.current);
7
7
  u.current = d;
8
8
  let f = d.subject, p = a(!0), [, m] = o(0);
9
9
  i(() => (p.current = !0, () => {
@@ -14,15 +14,15 @@ var s = (s, c, l) => {
14
14
  let t = () => m((e) => e + 1);
15
15
  return e.addEventListener("abort", t, { once: !0 }), () => e.removeEventListener("abort", t);
16
16
  }, [d, f]);
17
- let h = r(() => u.current === d && n(d, s.current), [d, s]), g = r(() => p.current && h(), [h]);
17
+ let h = r(() => u.current === d && t(d, s.current), [d, s]), g = r(() => p.current && h(), [h]);
18
18
  return {
19
19
  owner: d,
20
20
  current: g,
21
21
  assertCurrent: r(() => {
22
- if (!g()) throw new e("inactive");
22
+ if (!g()) throw new n("inactive");
23
23
  }, [g]),
24
24
  assertOwnerCurrent: r(() => {
25
- if (!h()) throw new e("inactive");
25
+ if (!h()) throw new n("inactive");
26
26
  }, [h])
27
27
  };
28
28
  };
@@ -1,16 +1,16 @@
1
- import { useFrameworkApi as e } from "./runtimeContext.js";
2
- import { ConnectionPrerequisiteInvalidated as t } from "./connectionPrerequisite.js";
3
- import { bindResolvedRpcInvocationOwner as n } from "./awaitResolvedApi.js";
1
+ import { useAction as e } from "./useAction.js";
2
+ import { useUpload as t } from "./useUpload.js";
3
+ import { useFrameworkApi as n } from "./runtimeContext.js";
4
4
  import { useRpcInvocationOwner as r } from "./useRpcInvocationOwner.js";
5
- import { waitForInvocation as i } from "./invocationWait.js";
6
- import { useAction as a } from "./useAction.js";
7
- import { useUpload as o } from "./useUpload.js";
5
+ import { bindResolvedRpcInvocationOwner as i } from "./awaitResolvedApi.js";
6
+ import { ConnectionPrerequisiteInvalidated as a } from "./connectionPrerequisite.js";
7
+ import { waitForInvocation as o } from "./invocationWait.js";
8
8
  import { useCallback as s, useEffect as c, useMemo as l, useRef as u, useState as d } from "react";
9
9
  // src/useTranscription.ts
10
10
  var f = (f, p) => {
11
- let m = e(f), h = u(m);
11
+ let m = n(f), h = u(m);
12
12
  h.current = m;
13
- let { owner: g, current: _, assertCurrent: v } = r(h, f, p.action), y = o(f), b = a(f, p.action), x = l(() => ({ active: void 0 }), [g]), S = u(void 0), [C, w] = d(() => ({
13
+ let { owner: g, current: _, assertCurrent: v } = r(h, f, p.action), y = t(f), b = e(f, p.action), x = l(() => ({ active: void 0 }), [g]), S = u(void 0), [C, w] = d(() => ({
14
14
  owner: g,
15
15
  phase: "idle",
16
16
  result: void 0,
@@ -27,54 +27,54 @@ var f = (f, p) => {
27
27
  }, [x, g]);
28
28
  let E = s(async (e) => {
29
29
  if (v(), x.active) throw Error("useTranscription: another transcription is in progress; await it, cancel or reset before starting another.");
30
- let r = T.current ?? {};
31
- if (Object.hasOwn(r, "storageRef")) throw TypeError("useTranscription: extra.storageRef is reserved for the uploaded file.");
32
- let a = { ...r }, o = {
30
+ let t = T.current ?? {};
31
+ if (Object.hasOwn(t, "storageRef")) throw TypeError("useTranscription: extra.storageRef is reserved for the uploaded file.");
32
+ let n = { ...t }, r = {
33
33
  controller: new AbortController(),
34
34
  resetUpload: y.reset
35
35
  }, s = S.current;
36
- s && (s.controller.abort(), s.resetUpload()), x.active = o, S.current = o, w({
36
+ s && (s.controller.abort(), s.resetUpload()), x.active = r, S.current = r, w({
37
37
  owner: g,
38
38
  phase: "uploading",
39
39
  result: void 0,
40
40
  error: void 0
41
41
  });
42
- let c, l = () => o.controller.abort(), u = () => {
42
+ let c, l = () => r.controller.abort(), u = () => {
43
43
  c !== g.subject && (c?.removeEventListener("abort", l), c = g.subject, c.addEventListener("abort", l, { once: !0 })), c.aborted && l();
44
44
  }, d = () => {
45
- if (v(), x.active !== o || o.controller.signal.aborted) throw new DOMException("transcription aborted", "AbortError");
46
- }, f = () => _() && x.active === o && !o.controller.signal.aborted;
45
+ if (v(), x.active !== r || r.controller.signal.aborted) throw new DOMException("transcription aborted", "AbortError");
46
+ }, f = () => _() && x.active === r && !r.controller.signal.aborted;
47
47
  u();
48
48
  try {
49
49
  d();
50
- let t = await i(y.upload(e), o.controller.signal, d);
51
- d(), n(g, h.current), u(), d(), S.current === o && (S.current = void 0), w({
50
+ let t = await o(y.upload(e), r.controller.signal, d);
51
+ d(), i(g, h.current), u(), d(), S.current === r && (S.current = void 0), w({
52
52
  owner: g,
53
53
  phase: "transcribing",
54
54
  result: void 0,
55
55
  error: void 0
56
56
  });
57
- let r = await i(b.run({
58
- ...a,
57
+ let a = await o(b.run({
58
+ ...n,
59
59
  storageRef: t.id
60
- }, { signal: o.controller.signal }), o.controller.signal, d);
61
- if (r == null) throw TypeError("useTranscription: the declared action returned no transcript.");
60
+ }, { signal: r.controller.signal }), r.controller.signal, d);
61
+ if (a == null) throw TypeError("useTranscription: the declared action returned no transcript.");
62
62
  return d(), w({
63
63
  owner: g,
64
64
  phase: "done",
65
- result: r,
65
+ result: a,
66
66
  error: void 0
67
- }), r;
67
+ }), a;
68
68
  } catch (e) {
69
- let n = _() ? o.controller.signal.aborted || x.active !== o ? new DOMException("transcription aborted", "AbortError") : e : new t("inactive");
69
+ let t = _() ? r.controller.signal.aborted || x.active !== r ? new DOMException("transcription aborted", "AbortError") : e : new a("inactive");
70
70
  throw f() && w({
71
71
  owner: g,
72
72
  phase: "error",
73
73
  result: void 0,
74
- error: n
75
- }), n;
74
+ error: t
75
+ }), t;
76
76
  } finally {
77
- c?.removeEventListener("abort", l), x.active === o && (x.active = void 0), S.current === o && (S.current = void 0);
77
+ c?.removeEventListener("abort", l), x.active === r && (x.active = void 0), S.current === r && (S.current = void 0);
78
78
  }
79
79
  }, [
80
80
  v,