@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.
@@ -1,97 +1,100 @@
1
1
  import { useFrameworkApi as e } from "./runtimeContext.js";
2
2
  import { resolveByTag as t } from "./tagWalk.js";
3
- import { useCallback as n, useMemo as r, useRef as i, useSyncExternalStore as a } from "react";
4
- import { Stream as o } from "effect";
3
+ import { reportUnknownRpcTag as n } from "./unknownRpcTag.js";
4
+ import { useCallback as r, useMemo as i, useRef as a, useSyncExternalStore as o } from "react";
5
+ import { Stream as s } from "effect";
5
6
  // src/useSubscription.ts
6
- var s = Object.freeze({
7
+ var c = Object.freeze({
7
8
  data: void 0,
8
9
  revision: -1,
9
10
  emittedAt: void 0,
10
11
  error: void 0,
11
12
  pendingPatches: 0
12
- }), c = () => s;
13
- function l(l, u, d = {}, f = {}) {
14
- let p = f.skip === !0, { runtime: m, cache: h, client: g, descriptors: _ } = e(l), v = _[u]?.source, y = i(d);
15
- y.current = d;
16
- let b = i(g);
17
- b.current = g;
18
- let x = r(() => JSON.stringify(Object.entries(d).sort(([e], [t]) => e.localeCompare(t))), [d]), S = r(() => {
19
- let e = y.current;
13
+ }), l = () => c;
14
+ function u(u, d, f = {}, p = {}) {
15
+ let m = p.skip === !0, { runtime: h, cache: g, client: _, descriptors: v } = e(u);
16
+ process.env.NODE_ENV !== "production" && !m && n("useSubscription", u, d, v);
17
+ let y = v[d]?.source, b = a(f);
18
+ b.current = f;
19
+ let x = a(_);
20
+ x.current = _;
21
+ let S = i(() => JSON.stringify(Object.entries(f).sort(([e], [t]) => e.localeCompare(t))), [f]), C = i(() => {
22
+ let e = b.current;
20
23
  return {
21
- queryKey: [u, e],
24
+ queryKey: [d, e],
22
25
  fetch: () => {
23
26
  let n;
24
27
  try {
25
- n = t(b.current, u);
28
+ n = t(x.current, d);
26
29
  } catch (e) {
27
- return o.fail(e);
30
+ return s.fail(e);
28
31
  }
29
32
  return n(e);
30
33
  }
31
34
  };
32
- }, [u, x]), C = S.queryKey, w = n((e) => p ? () => {} : h.subscribe(S.queryKey, S.fetch, m, e, v === void 0 ? {} : { source: v }).unsubscribe, [
35
+ }, [d, S]), w = C.queryKey, T = r((e) => m ? () => {} : g.subscribe(C.queryKey, C.fetch, h, e, y === void 0 ? {} : { source: y }).unsubscribe, [
36
+ g,
33
37
  h,
38
+ y,
34
39
  m,
35
- v,
36
- p,
37
- S
38
- ]), T = n(() => p ? s : h.peek(C), [
39
- h,
40
- p,
41
40
  C
42
- ]), E = a(w, T, c), D = E.data !== void 0, O = D && (Array.isArray(E.data) ? E.data.length === 0 : E.data === null), k = {
43
- revision: E.revision,
44
- emittedAt: E.emittedAt,
45
- error: E.error,
46
- pendingPatches: E.pendingPatches
41
+ ]), E = r(() => m ? c : g.peek(w), [
42
+ g,
43
+ m,
44
+ w
45
+ ]), D = o(T, E, l), O = D.data !== void 0, k = O && (Array.isArray(D.data) ? D.data.length === 0 : D.data === null), A = {
46
+ revision: D.revision,
47
+ emittedAt: D.emittedAt,
48
+ error: D.error,
49
+ pendingPatches: D.pendingPatches
47
50
  };
48
- if (f.initialSnapshot !== void 0) {
49
- let e = Array.isArray(f.initialSnapshot) ? f.initialSnapshot.length === 0 : f.initialSnapshot === null;
51
+ if (p.initialSnapshot !== void 0) {
52
+ let e = Array.isArray(p.initialSnapshot) ? p.initialSnapshot.length === 0 : p.initialSnapshot === null;
50
53
  return {
51
- ...k,
52
- data: D ? E.data : f.initialSnapshot,
54
+ ...A,
55
+ data: O ? D.data : p.initialSnapshot,
53
56
  loading: !1,
54
- idle: p,
55
- isEmpty: D ? O : e,
57
+ idle: m,
58
+ isEmpty: O ? k : e,
56
59
  failed: !1
57
60
  };
58
61
  }
59
- return f.fallback === void 0 ? p ? {
60
- ...k,
62
+ return p.fallback === void 0 ? m ? {
63
+ ...A,
61
64
  data: void 0,
62
65
  loading: !1,
63
66
  isEmpty: !1,
64
67
  idle: !0,
65
68
  failed: !1
66
- } : D ? {
67
- ...k,
68
- data: E.data,
69
+ } : O ? {
70
+ ...A,
71
+ data: D.data,
69
72
  loading: !1,
70
- isEmpty: O,
73
+ isEmpty: k,
71
74
  idle: !1,
72
75
  failed: !1
73
- } : k.error === void 0 ? {
74
- ...k,
76
+ } : A.error === void 0 ? {
77
+ ...A,
75
78
  data: void 0,
76
79
  loading: !0,
77
80
  isEmpty: !1,
78
81
  idle: !1,
79
82
  failed: !1
80
83
  } : {
81
- ...k,
84
+ ...A,
82
85
  data: void 0,
83
86
  loading: !1,
84
87
  isEmpty: !1,
85
88
  idle: !1,
86
89
  failed: !0,
87
- error: k.error
90
+ error: A.error
88
91
  } : {
89
- ...k,
90
- data: D ? E.data : f.fallback,
91
- loading: !D && !p,
92
- idle: p,
93
- isEmpty: O,
94
- failed: !D && k.error !== void 0
92
+ ...A,
93
+ data: O ? D.data : p.fallback,
94
+ loading: !O && !m,
95
+ idle: m,
96
+ isEmpty: k,
97
+ failed: !O && A.error !== void 0
95
98
  };
96
99
  }
97
- export { l as useSubscription };
100
+ export { u as useSubscription };
@@ -1,50 +1,122 @@
1
- import { useAction as e } from "./useAction.js";
2
- import { useUpload as t } from "./useUpload.js";
3
- import { useCallback as n, useMemo as r, useRef as i, useState as a } from "react";
1
+ import { useFrameworkApi as e } from "./runtimeContext.js";
2
+ import { ConnectionPrerequisiteInvalidated as t } from "./connectionPrerequisite.js";
3
+ import { bindResolvedRpcInvocationOwner as n } from "./awaitResolvedApi.js";
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";
8
+ import { useCallback as s, useEffect as c, useMemo as l, useRef as u, useState as d } from "react";
4
9
  // src/useTranscription.ts
5
- var o = (o, s) => {
6
- let c = t(o), l = e(o, s.action), [u, d] = a("idle"), [f, p] = a(void 0), [m, h] = a(void 0), g = i(s.extra);
7
- g.current = s.extra;
8
- let _ = n(async (e) => {
9
- h(void 0), p(void 0), d("uploading");
10
- let t;
10
+ var f = (f, p) => {
11
+ let m = e(f), h = u(m);
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(() => ({
14
+ owner: g,
15
+ phase: "idle",
16
+ result: void 0,
17
+ error: void 0
18
+ })), T = u(p.extra);
19
+ T.current = p.extra, c(() => () => {
20
+ let e = x.active;
21
+ e && (e.controller.abort(), S.current === e && (e.resetUpload(), S.current = void 0)), x.active = void 0, w((e) => e.owner === g ? {
22
+ owner: g,
23
+ phase: "idle",
24
+ result: void 0,
25
+ error: void 0
26
+ } : e);
27
+ }, [x, g]);
28
+ let E = s(async (e) => {
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 = {
33
+ controller: new AbortController(),
34
+ resetUpload: y.reset
35
+ }, s = S.current;
36
+ s && (s.controller.abort(), s.resetUpload()), x.active = o, S.current = o, w({
37
+ owner: g,
38
+ phase: "uploading",
39
+ result: void 0,
40
+ error: void 0
41
+ });
42
+ let c, l = () => o.controller.abort(), u = () => {
43
+ c !== g.subject && (c?.removeEventListener("abort", l), c = g.subject, c.addEventListener("abort", l, { once: !0 })), c.aborted && l();
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;
47
+ u();
11
48
  try {
12
- t = await c.upload(e);
13
- } catch (e) {
14
- throw d("error"), h(e), e;
15
- }
16
- d("transcribing");
17
- try {
18
- let e = await l.run({
19
- storageRef: t.id,
20
- ...g.current ?? {}
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({
52
+ owner: g,
53
+ phase: "transcribing",
54
+ result: void 0,
55
+ error: void 0
21
56
  });
22
- return p(e), d("done"), e;
57
+ let r = await i(b.run({
58
+ ...a,
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.");
62
+ return d(), w({
63
+ owner: g,
64
+ phase: "done",
65
+ result: r,
66
+ error: void 0
67
+ }), r;
23
68
  } catch (e) {
24
- throw d("error"), h(e), e;
69
+ let n = _() ? o.controller.signal.aborted || x.active !== o ? new DOMException("transcription aborted", "AbortError") : e : new t("inactive");
70
+ throw f() && w({
71
+ owner: g,
72
+ phase: "error",
73
+ result: void 0,
74
+ error: n
75
+ }), n;
76
+ } finally {
77
+ c?.removeEventListener("abort", l), x.active === o && (x.active = void 0), S.current === o && (S.current = void 0);
25
78
  }
26
- }, [c, l]), v = n(() => {
27
- c.cancel(), d("idle");
28
- }, [c]), y = n(() => {
29
- c.reset(), d("idle"), p(void 0), h(void 0);
30
- }, [c]);
31
- return r(() => ({
32
- phase: u,
33
- progress: u === "uploading" ? c.progress : void 0,
34
- result: f,
35
- error: m ?? c.error,
36
- transcribe: _,
37
- cancel: v,
38
- reset: y
39
- }), [
40
- u,
41
- c.progress,
42
- c.error,
43
- f,
44
- m,
45
- _,
79
+ }, [
46
80
  v,
47
- y
81
+ _,
82
+ x,
83
+ g,
84
+ y.upload,
85
+ y.reset,
86
+ b.run
87
+ ]), D = s(() => {
88
+ _() && (x.active?.controller.abort(), x.active = void 0, y.reset(), S.current = void 0, w({
89
+ owner: g,
90
+ phase: "idle",
91
+ result: void 0,
92
+ error: void 0
93
+ }));
94
+ }, [
95
+ _,
96
+ x,
97
+ g,
98
+ y.reset
99
+ ]), O = D, k = C.owner === g ? C : {
100
+ phase: "idle",
101
+ result: void 0,
102
+ error: void 0
103
+ };
104
+ return l(() => ({
105
+ phase: k.phase,
106
+ progress: k.phase === "uploading" ? y.progress : void 0,
107
+ result: k.result,
108
+ error: k.error,
109
+ transcribe: E,
110
+ cancel: D,
111
+ reset: O
112
+ }), [
113
+ k.phase,
114
+ y.progress,
115
+ k.result,
116
+ k.error,
117
+ E,
118
+ D,
119
+ O
48
120
  ]);
49
121
  };
50
- export { o as useTranscription };
122
+ export { f as useTranscription };