@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.
Files changed (53) hide show
  1. package/CHANGELOG.md +1943 -0
  2. package/README.md +22 -0
  3. package/THIRD-PARTY-NOTICES.md +1 -1
  4. package/dist/analytics.d.ts +68 -0
  5. package/dist/analytics.js +1 -0
  6. package/dist/apiRuntime.js +50 -50
  7. package/dist/apiSupervisor.js +25 -25
  8. package/dist/awaitResolvedApi.js +42 -16
  9. package/dist/bootstrap.d.ts +0 -115
  10. package/dist/bootstrap.js +8 -8
  11. package/dist/connectionPrerequisite.js +18 -18
  12. package/dist/connectionSetupController.js +123 -91
  13. package/dist/createHooks.js +11 -11
  14. package/dist/form.js +7 -7
  15. package/dist/index.d.ts +148 -162
  16. package/dist/index.js +88 -86
  17. package/dist/invocationWait.js +14 -0
  18. package/dist/mutationsBus.js +92 -35
  19. package/dist/outbox.js +137 -108
  20. package/dist/outboxState.js +7 -0
  21. package/dist/platform.js +10 -10
  22. package/dist/query.js +3 -10
  23. package/dist/rpcCallOnce.js +30 -0
  24. package/dist/rpcDeclared.js +7 -0
  25. package/dist/runRpc.js +9 -6
  26. package/dist/runtime.d.ts +16 -116
  27. package/dist/runtime.js +16 -16
  28. package/dist/runtimeContext.js +1 -1
  29. package/dist/serviceClient.js +23 -23
  30. package/dist/store.js +3 -3
  31. package/dist/subscriptionCache.js +1 -1
  32. package/dist/traceBus.js +7 -1
  33. package/dist/unknownRpcTag.js +7 -0
  34. package/dist/uploadBytes.js +83 -0
  35. package/dist/uploadClient.js +153 -0
  36. package/dist/useAction.js +148 -74
  37. package/dist/useAgentChat.js +3 -3
  38. package/dist/useCapabilityManifest.js +7 -7
  39. package/dist/useConnectionStatus.js +5 -5
  40. package/dist/useDataTable.js +4 -4
  41. package/dist/useEvent.js +22 -22
  42. package/dist/useFormBinding.js +10 -10
  43. package/dist/useMutation.js +221 -134
  44. package/dist/useOnRpcError.js +5 -5
  45. package/dist/usePreloadedSubscription.js +6 -6
  46. package/dist/useRpcCaller.js +75 -13
  47. package/dist/useRpcInvocationOwner.js +29 -0
  48. package/dist/useSubscription.js +52 -49
  49. package/dist/useTranscription.js +112 -40
  50. package/dist/useUpload.js +160 -242
  51. package/dist/useWorkflow.js +111 -246
  52. package/dist/workflowClient.js +126 -0
  53. package/package.json +8 -3
package/dist/outbox.js CHANGED
@@ -1,118 +1,130 @@
1
- import { recoveryCoordinatorFor as e } from "./recoveryCoordinator.js";
2
- import { FrameworkRuntimesContext as t, isUnresolvedApi as n } from "./frameworkRuntimesContext.js";
3
- import { resolveByTag as r } from "./tagWalk.js";
4
- import { runRpcPromise as i } from "./runRpc.js";
5
- import { awaitResolvedApi as a } from "./awaitResolvedApi.js";
6
- import { withIdempotencyKey as o } from "./mutationIdentity.js";
1
+ import { awaitResolvedApi as e } from "./awaitResolvedApi.js";
2
+ import { withIdempotencyKey as t } from "./mutationIdentity.js";
3
+ import { recoveryCoordinatorFor as n } from "./recoveryCoordinator.js";
4
+ import { runRpcPromise as r } from "./runRpc.js";
5
+ import { FrameworkRuntimesContext as i, isUnresolvedApi as a } from "./frameworkRuntimesContext.js";
6
+ import { resolveByTag as o } from "./tagWalk.js";
7
7
  import { useApiOnline as s } from "./useApiOnline.js";
8
8
  import { OutboxState as c } from "./outboxState.js";
9
- import { useCallback as l, useContext as u, useEffect as d, useMemo as f, useRef as p, useState as m } from "react";
9
+ import { useCallback as l, useContext as u, useEffect as d, useMemo as ee, useRef as f, useState as p } from "react";
10
10
  // src/outbox.ts
11
- var h = (e, t, n, r, i) => [...e, {
11
+ var m = (e, t, n, r, i) => [...e, {
12
12
  id: t,
13
13
  tag: n,
14
14
  input: r,
15
15
  status: "pending",
16
16
  attempts: 0,
17
17
  ...i === void 0 ? {} : { stamp: i }
18
- }], g = (e, t, n) => e.map((e) => e.id === t ? {
18
+ }], h = (e, t, n) => e.map((e) => e.id === t ? {
19
19
  ...e,
20
20
  ...n
21
- } : e), _ = (e, t) => g(e, t, { status: "sent" }), v = (e, t, n) => e.map((e) => e.id === t ? {
21
+ } : e), g = (e, t) => h(e, t, { status: "sent" }), _ = (e, t, n) => e.map((e) => e.id === t ? {
22
22
  ...e,
23
23
  status: "failed",
24
24
  error: n,
25
25
  attempts: e.attempts + 1
26
- } : e), y = (e, t, n) => g(e, t, {
26
+ } : e), v = (e, t, n) => h(e, t, {
27
27
  status: "conflict",
28
28
  error: n
29
- }), b = (e, t, n) => e.map((e) => e.id === t && e.status === "conflict" ? {
29
+ }), y = (e, t, n) => e.map((e) => e.id === t && e.status === "conflict" ? {
30
30
  ...e,
31
31
  input: n,
32
32
  status: "pending",
33
33
  error: void 0
34
- } : e), x = (e) => e.filter((e) => e.status !== "sent"), S = (e) => {
34
+ } : e), b = (e) => e.filter((e) => e.status !== "sent"), x = (e) => {
35
35
  let t = [];
36
36
  for (let n of e) {
37
37
  if (n.status === "conflict") break;
38
38
  (n.status === "pending" || n.status === "failed") && t.push(n);
39
39
  }
40
40
  return t;
41
- }, ee = (e) => {
41
+ }, te = (e) => {
42
42
  let t = e;
43
43
  return t?.conflict === !0 || t?._tag === "UndoBoundaryError" && t?.boundary === "conflict";
44
- }, C = (e) => {
44
+ }, S = (e) => {
45
45
  let t = Math.min(3e4, 1e3 * 2 ** Math.max(0, e - 1));
46
46
  return t / 2 + t / 2 * Math.random();
47
- }, w = (h) => {
48
- let { persistence: g, isConflict: _ = ee, idFor: v, api: y } = h;
49
- if (h.send === void 0 && y === void 0) throw Error("useOutbox: pass `send`, or `api` to send through that api's own mutations.");
50
- let b = u(t), S = b?.demand;
47
+ }, C = (m) => {
48
+ let { persistence: h, isConflict: g = te, idFor: _, api: v } = m;
49
+ if (m.send === void 0 && v === void 0) throw Error("useOutbox: pass `send`, or `api` to send through that api's own mutations.");
50
+ let y = u(i), x = y?.demand;
51
51
  d(() => {
52
- y !== void 0 && S?.(y);
53
- }, [S, y]);
54
- let w = y === void 0 || b === null ? void 0 : b.get(y), T = p(w);
55
- T.current = w;
56
- let [E, D] = m(0), [O, k] = m(0), A = s(y), j = h.online ?? A, M = p(void 0);
57
- M.current === void 0 && (M.current = new c());
58
- let N = f(() => M.current.snapshot(), [E]), P = l((e) => {
59
- e(M.current), D((e) => e + 1);
60
- }, []), F = p(h.retryDelay ?? C);
61
- F.current = h.retryDelay ?? C;
62
- let I = p(h.stamp);
63
- I.current = h.stamp;
64
- let L = p(async () => void 0);
65
- L.current = h.send ?? (async (e) => {
66
- if (T.current === void 0) throw Error(`useOutbox: no mounted api '${y}' — render it inside the framework's runtime provider.`);
67
- let t = await a(T, y, e.tag), n = r(t.client, e.tag);
68
- await i(t.runtime, o(n(e.input), e.id));
52
+ v !== void 0 && x?.(v);
53
+ }, [x, v]);
54
+ let C = v === void 0 || y === null ? void 0 : y.get(v), w = f(C);
55
+ w.current = C;
56
+ let [ne, T] = p(0), [E, D] = p(0), O = s(v), k = m.online ?? O, A = f(void 0), j = f(0);
57
+ A.current === void 0 && (A.current = new c());
58
+ let M = ee(() => A.current.snapshot(), [ne]), N = l((e) => {
59
+ e(A.current), T((e) => e + 1);
60
+ }, []), P = f(m.retryDelay ?? S);
61
+ P.current = m.retryDelay ?? S;
62
+ let F = f(m.stamp);
63
+ F.current = m.stamp;
64
+ let I = f(async () => void 0);
65
+ I.current = m.send ?? (async (i) => {
66
+ if (w.current === void 0) throw Error(`useOutbox: no mounted api '${v}' — render it inside the framework's runtime provider.`);
67
+ let a = w.current, s = a.subjectSignal ?? (a.recovery ?? n(a.errorBus, v)).subjectSignal, c = await e(w, v, i.tag, s);
68
+ if (s?.throwIfAborted(), a.recovery !== void 0 && a.recovery !== c.recovery) throw Error("Outbox API ownership changed before the queued write started");
69
+ let l = o(c.client, i.tag);
70
+ await r(c.runtime, t(l(i.input), i.id), { signal: s });
69
71
  });
70
- let R = p(_);
71
- R.current = _;
72
- let z = p(void 0), B = p(!1), V = p(!0);
73
- d(() => (V.current = !0, () => {
74
- V.current = !1;
72
+ let L = f(g);
73
+ L.current = g;
74
+ let R = f(void 0), z = f(!1), B = f(!0);
75
+ d(() => (B.current = !0, () => {
76
+ B.current = !1;
75
77
  }), []);
76
- let H = p(0), U = p(Math.random().toString(36).slice(2, 8)), W = p(g === void 0), [G, K] = m(0), q = w === void 0 ? void 0 : w.recovery ?? e(w.errorBus, y);
78
+ let V = f(0), H = f(Math.random().toString(36).slice(2, 8)), U = f(h === void 0), [W, G] = p(0), K = C === void 0 ? void 0 : C.recovery ?? n(C.errorBus, v), q = K?.subjectSignal;
77
79
  d(() => {
78
- if (q === void 0) return;
79
- let e = q.subjectSignal;
80
+ if (K === void 0) return;
81
+ let e = K.subjectSignal;
80
82
  if (e.aborted) return;
81
83
  let t = () => {
82
- M.current.reset(), D((e) => e + 1), W.current = g === void 0, B.current = !1, K((e) => e + 1);
84
+ j.current++, R.current = void 0, Z(), A.current.reset(), T((e) => e + 1), U.current = h === void 0, z.current = !1, G((e) => e + 1);
83
85
  };
84
86
  return e.addEventListener("abort", t, { once: !0 }), () => {
85
87
  e.removeEventListener("abort", t);
86
88
  };
87
89
  }, [
88
- q,
89
- g,
90
- G
90
+ K,
91
+ h,
92
+ W
91
93
  ]), d(() => {
92
- if (g === void 0) return;
94
+ if (h === void 0) return;
93
95
  let e = !1;
94
- return W.current = !1, g.load().then((t) => {
95
- e || (W.current = !0, t.length > 0 && P((e) => e.prepend(t)), k((e) => e + 1));
96
+ return U.current = !1, h.load().then((t) => {
97
+ e || (U.current = !0, t.length > 0 && N((e) => e.prepend(t.map((e) => {
98
+ if (e.status !== "conflict" || !(e.error instanceof Error)) return e;
99
+ let t = !1;
100
+ try {
101
+ t = L.current(e.error);
102
+ } catch {}
103
+ return t ? e : {
104
+ ...e,
105
+ status: "failed"
106
+ };
107
+ }))), D((e) => e + 1));
96
108
  }, () => {
97
- e || (W.current = !0, k((e) => e + 1));
109
+ e || (U.current = !0, D((e) => e + 1));
98
110
  }), () => {
99
111
  e = !0;
100
112
  };
101
113
  }, [
102
- g,
103
- P,
104
- G
114
+ h,
115
+ N,
116
+ W
105
117
  ]), d(() => {
106
- g !== void 0 && W.current && g.save(x(N)).catch(() => {});
118
+ h !== void 0 && U.current && h.save(b(M)).catch(() => {});
107
119
  }, [
108
- g,
109
- N,
110
- O
120
+ h,
121
+ M,
122
+ E
111
123
  ]);
112
- let J = p(/* @__PURE__ */ new Set()), Y = w === void 0 || n(w) ? void 0 : w.cache;
124
+ let J = f(/* @__PURE__ */ new Set()), Y = C === void 0 || a(C) ? void 0 : C.cache;
113
125
  d(() => {
114
- if (Y !== void 0 && w !== void 0) for (let e of N) {
115
- let t = w.descriptors[e.tag]?.targets;
126
+ if (Y !== void 0 && C !== void 0) for (let e of M) {
127
+ let t = C.descriptors[e.tag]?.targets;
116
128
  if (e.status === "pending" || e.status === "failed") {
117
129
  if (J.current.delete(e.id), t === void 0 || t.length === 0 || Y.hasIntent(e.id) || typeof e.input != "object" || e.input === null) continue;
118
130
  Y.autoApply(t, e.input, e.id, { standing: !0 });
@@ -120,93 +132,110 @@ var h = (e, t, n, r, i) => [...e, {
120
132
  }
121
133
  }, [
122
134
  Y,
123
- w,
124
- N
135
+ C,
136
+ M
125
137
  ]);
126
- let te = l((e, t) => {
127
- let n = v?.() ?? `obx_${U.current}_${H.current++}_${e}`;
128
- P((r) => r.append({
129
- id: n,
138
+ let re = l((e, t, n) => {
139
+ if (!B.current || q?.aborted || C !== w.current) throw Error("Outbox ownership changed before enqueue");
140
+ let r = n?.stamp ?? F.current?.();
141
+ if (r !== void 0 && typeof r != "string") throw TypeError("Outbox stamp must be a string");
142
+ let i = _?.() ?? `obx_${H.current}_${V.current++}_${e}`;
143
+ N((n) => n.append({
144
+ id: i,
130
145
  tag: e,
131
146
  input: t,
132
147
  status: "pending",
133
148
  attempts: 0,
134
- ...I.current === void 0 ? {} : { stamp: I.current() }
135
- })), k((e) => e + 1);
136
- }, [v, P]), X = p(void 0), Z = l(() => {
149
+ ...r === void 0 ? {} : { stamp: r }
150
+ })), D((e) => e + 1);
151
+ }, [
152
+ _,
153
+ N,
154
+ q,
155
+ C
156
+ ]), X = f(void 0), Z = l(() => {
137
157
  X.current !== void 0 && clearTimeout(X.current), X.current = void 0;
138
158
  }, []);
139
159
  d(() => Z, [Z]);
140
160
  let Q = l(() => {
141
- if (!W.current || !V.current) return Promise.resolve();
142
- if (z.current !== void 0) return z.current;
143
- B.current = !1, Z();
144
- let e = Promise.resolve().then(async () => {
145
- for (; V.current;) {
146
- let e = M.current.next();
147
- if (e === void 0) break;
161
+ if (!U.current || !B.current) return Promise.resolve();
162
+ if (R.current !== void 0) return R.current;
163
+ z.current = !1, Z();
164
+ let e = j.current, t = Promise.resolve().then(async () => {
165
+ for (; B.current && j.current === e;) {
166
+ let t = A.current.next();
167
+ if (t === void 0) break;
148
168
  try {
149
- if (await L.current(e), !V.current) break;
150
- P((t) => t.update(e.id, (e) => ({
169
+ if (await I.current(t), !B.current || j.current !== e) break;
170
+ N((e) => e.update(t.id, (e) => ({
151
171
  ...e,
152
172
  status: "sent"
153
173
  })));
154
- } catch (t) {
155
- if (!V.current) break;
156
- let n = R.current(t);
157
- P((r) => r.update(e.id, (e) => n ? {
174
+ } catch (n) {
175
+ if (!B.current || j.current !== e) break;
176
+ let r = L.current(n);
177
+ N((e) => e.update(t.id, (e) => r ? {
158
178
  ...e,
159
179
  status: "conflict",
160
- error: t
180
+ error: n
161
181
  } : {
162
182
  ...e,
163
183
  status: "failed",
164
- error: t,
184
+ error: n,
165
185
  attempts: e.attempts + 1
166
- })), B.current = !0, n || (X.current = setTimeout(() => {
186
+ })), z.current = !0, r || (X.current = setTimeout(() => {
167
187
  X.current = void 0, $.current();
168
- }, F.current(e.attempts + 1)));
188
+ }, P.current(t.attempts + 1)));
169
189
  break;
170
190
  }
171
191
  }
172
192
  }).finally(() => {
173
- z.current === e && (z.current = void 0);
193
+ R.current === t && (R.current = void 0);
174
194
  });
175
- return z.current = e, e;
176
- }, [P, Z]), $ = p(Q);
195
+ return R.current = t, t;
196
+ }, [N, Z]), $ = f(Q);
177
197
  $.current = Q, d(() => {
178
- j ? Q() : Z();
198
+ k ? Q() : Z();
179
199
  }, [
180
- j,
200
+ k,
181
201
  Q,
182
202
  Z
183
203
  ]), d(() => {
184
- j && !B.current && Q();
204
+ k && !z.current && Q();
185
205
  }, [
186
- O,
187
- j,
206
+ E,
207
+ k,
188
208
  Q
189
209
  ]);
190
- let ne = l((e, t) => {
191
- P((n) => n.update(e, (e) => e.status === "conflict" ? {
210
+ let ie = l((e, t) => {
211
+ B.current && !q?.aborted && C === w.current && (N((n) => n.update(e, (e) => e.status === "conflict" ? {
192
212
  ...e,
193
213
  input: t,
194
214
  status: "pending",
195
215
  error: void 0
196
- } : e)), j && Q();
216
+ } : e)), k && Q());
197
217
  }, [
198
- j,
218
+ k,
219
+ Q,
220
+ N,
221
+ q,
222
+ C
223
+ ]), ae = l((e) => !B.current || q?.aborted || C !== w.current || !A.current.snapshot().some((t) => t.id === e && t.status === "conflict") || (Y?.revertByMutation(e), !B.current || q?.aborted || C !== w.current) || !A.current.discardConflict(e) ? !1 : (J.current.delete(e), z.current = !1, T((e) => e + 1), D((e) => e + 1), k && Q(), !0), [
224
+ k,
199
225
  Q,
200
- P
226
+ Y,
227
+ q,
228
+ C
201
229
  ]);
202
230
  return {
203
- queue: N,
204
- enqueue: te,
231
+ queue: M,
232
+ enqueue: re,
205
233
  replay: Q,
206
- online: j,
207
- pending: N.reduce((e, t) => e + +(t.status === "pending" || t.status === "failed"), 0),
208
- conflicts: N.filter((e) => e.status === "conflict"),
209
- resolveConflict: ne
234
+ online: k,
235
+ pending: M.reduce((e, t) => e + +(t.status === "pending" || t.status === "failed"), 0),
236
+ conflicts: M.filter((e) => e.status === "conflict"),
237
+ resolveConflict: ie,
238
+ discardConflict: ae
210
239
  };
211
240
  };
212
- export { x as clearSent, C as defaultOutboxRetryDelay, h as enqueueEntry, y as markConflict, v as markFailed, _ as markSent, S as replayable, b as resolveConflictEntry, w as useOutbox };
241
+ export { b as clearSent, S as defaultOutboxRetryDelay, m as enqueueEntry, v as markConflict, _ as markFailed, g as markSent, x as replayable, y as resolveConflictEntry, C as useOutbox };
@@ -30,6 +30,13 @@ var e = class {
30
30
  e !== r && (this.entries[n] = r, r.status !== "sent" && n < this.cursor && (this.cursor = n), this.cached = void 0);
31
31
  }
32
32
  }
33
+ discardConflict(e) {
34
+ if (!(this.positions.get(e) ?? []).some((e) => this.entries[e].status === "conflict")) return !1;
35
+ let t = this.entries.filter((t) => t.id !== e || t.status !== "conflict");
36
+ this.reset();
37
+ for (let e of t) this.append(e);
38
+ return !0;
39
+ }
33
40
  next() {
34
41
  for (; this.cursor < this.entries.length;) {
35
42
  let e = this.entries[this.cursor];
package/dist/platform.js CHANGED
@@ -1,5 +1,5 @@
1
- import { browserStoreStorage as e, setStoreStorage as t } from "./storeStorage.js";
2
- import { browserOnlineSource as n } from "./onlineSource.js";
1
+ import { browserOnlineSource as e } from "./onlineSource.js";
2
+ import { browserStoreStorage as t, setStoreStorage as n } from "./storeStorage.js";
3
3
  import { useSyncExternalStore as r } from "react";
4
4
  // src/platform.ts
5
5
  var i = (e, t = {}) => {
@@ -73,7 +73,7 @@ var i = (e, t = {}) => {
73
73
  if (n === void 0) throw Error("platform: no global WebSocket in this environment");
74
74
  let r = typeof t == "object" && !Array.isArray(t) ? void 0 : t;
75
75
  return r === void 0 ? new n(e) : new n(e, r);
76
- }, p = (t = {}) => {
76
+ }, p = (n = {}) => {
77
77
  let r = typeof window < "u", i = d(), s = r ? navigator.userAgent : "", p = r ? /jsdom/i.test(s) ? "test" : "browser" : "node", m = u();
78
78
  return a({
79
79
  platform: {
@@ -82,14 +82,14 @@ var i = (e, t = {}) => {
82
82
  installed: i
83
83
  },
84
84
  webSocket: f,
85
- storage: e,
85
+ storage: t,
86
86
  secureStorage: o("a browser tab has no secure store a page can read; the session is an HttpOnly cookie the server sets"),
87
- online: n,
87
+ online: e,
88
88
  lifecycle: c,
89
89
  links: l,
90
90
  ...m === void 0 ? {} : { notifications: m },
91
91
  clock: { now: () => Date.now() },
92
- ...t
92
+ ...n
93
93
  });
94
94
  }, m = Symbol.for("@voltro/client/platform"), h = () => {
95
95
  let e = globalThis, t = e[m];
@@ -101,15 +101,15 @@ var i = (e, t = {}) => {
101
101
  };
102
102
  return e[m] = n, n;
103
103
  }, g = (e) => {
104
- let n = h();
105
- n.adapter = e, t(e.storage);
106
- for (let e of n.listeners) e();
104
+ let t = h();
105
+ t.adapter = e, n(e.storage);
106
+ for (let e of t.listeners) e();
107
107
  }, _ = () => {
108
108
  let e = h();
109
109
  return e.adapter === void 0 ? (e.fallback === void 0 && (e.fallback = p()), e.fallback) : e.adapter;
110
110
  }, v = () => h().adapter !== void 0, y = () => {
111
111
  let e = h();
112
- e.adapter = void 0, e.fallback = void 0, t(null);
112
+ e.adapter = void 0, e.fallback = void 0, n(null);
113
113
  for (let t of e.listeners) t();
114
114
  }, b = (e) => {
115
115
  let t = h();
package/dist/query.js CHANGED
@@ -1,11 +1,4 @@
1
- import { resolveByTag as e } from "./tagWalk.js";
2
- import { runRpcPromise as t } from "./runRpc.js";
3
- import { awaitResolvedApi as n } from "./awaitResolvedApi.js";
4
- import { Effect as r, Option as i, Stream as a } from "effect";
5
- import { firstEventValue as o } from "@voltro/protocol";
1
+ import { rpcCallOnce as e } from "./rpcCallOnce.js";
6
2
  // src/queryOnce.ts
7
- var s = async (s, c, l, u, d) => {
8
- let { runtime: f, client: p } = await n(s, c, l), m = e(p, l)(u ?? {}), h = r.isEffect(m) ? m : a.runHead(m).pipe(r.map(i.getOrUndefined)), g = await t(f, h, { signal: d });
9
- return o(l, g, "[loader.query]");
10
- };
11
- export { s as queryOnce };
3
+ var t = async (t, n, r, i, a) => e(t, n, r, i ?? {}, a, "[loader.query]");
4
+ export { t as queryOnce };
@@ -0,0 +1,30 @@
1
+ import { awaitResolvedApi as e, bindResolvedRpcInvocationOwner as t, rpcInvocationOwnerCurrent as n } from "./awaitResolvedApi.js";
2
+ import { ConnectionPrerequisiteInvalidated as r } from "./connectionPrerequisite.js";
3
+ import { runRpcPromise as i } from "./runRpc.js";
4
+ import { resolveByTag as a } from "./tagWalk.js";
5
+ import { Effect as o, Option as s, Stream as c } from "effect";
6
+ import { firstEventValue as l } from "@voltro/protocol";
7
+ // src/rpcCallOnce.ts
8
+ var u = async (u, d, f, p, m, h, g) => {
9
+ let _ = () => {
10
+ if (g && !n(g, u.current)) throw new r("inactive");
11
+ };
12
+ _();
13
+ let v = g?.subject, y = await e(u, d, f, m);
14
+ if (v?.aborted) throw new r("inactive");
15
+ g && t(g, y), _();
16
+ let { runtime: b, client: x } = y;
17
+ m?.throwIfAborted();
18
+ let S = g ? new AbortController() : void 0, C = g ? [.../* @__PURE__ */ new Set([g.subject, ...m ? [m] : []])] : [], w = () => S?.abort();
19
+ for (let e of C) e.aborted ? w() : e.addEventListener("abort", w, { once: !0 });
20
+ try {
21
+ _();
22
+ let e = a(x, f)(p), t = o.isEffect(e), n = t ? e : c.runHead(e).pipe(o.flatMap((e) => s.isNone(e) ? o.fail(/* @__PURE__ */ Error(`${h} ${f}: the query ended before its first snapshot`)) : o.succeed(e.value))), r = await i(b, o.suspend(() => (_(), n)), { signal: S?.signal ?? m });
23
+ return _(), t ? r : l(f, r, h);
24
+ } catch (e) {
25
+ throw _(), e;
26
+ } finally {
27
+ for (let e of C) e.removeEventListener("abort", w);
28
+ }
29
+ };
30
+ export { u as rpcCallOnce };
@@ -0,0 +1,7 @@
1
+ import { useFrameworkApi as e } from "./runtimeContext.js";
2
+ // src/rpcDeclared.ts
3
+ var t = (t, n) => {
4
+ let { descriptors: r } = e(t);
5
+ return Object.hasOwn(r, n) ? !0 : Object.keys(r).length === 0 && void 0;
6
+ };
7
+ export { t as useRpcDeclared };
package/dist/runRpc.js CHANGED
@@ -1,11 +1,14 @@
1
1
  import { squashRpcCause as e } from "./squashRpcCause.js";
2
2
  import { rememberRpcErrorKind as t, rpcErrorKind as n } from "./rpcErrorKind.js";
3
- import { Cause as r, Exit as i, Option as a } from "effect";
3
+ import { Cause as r, Effect as i, Exit as a, Option as o } from "effect";
4
4
  // src/runRpc.ts
5
- var o = async (o, s, c) => {
6
- let l = await o.runPromiseExit(s, c?.signal === void 0 ? void 0 : { signal: c.signal });
7
- if (i.isSuccess(l)) return l.value;
8
- let u = e(l.cause), d = r.findErrorOption(l.cause), f = a.isSome(d) ? n(d.value, "handler") : "unknown";
5
+ var s = (e) => i.try({
6
+ try: e,
7
+ catch: (e) => t(e, n(e, "client"))
8
+ }).pipe(i.flatten), c = async (i, s, c) => {
9
+ let l = await i.runPromiseExit(s, c?.signal === void 0 ? void 0 : { signal: c.signal });
10
+ if (a.isSuccess(l)) return l.value;
11
+ let u = e(l.cause), d = r.findErrorOption(l.cause), f = o.isSome(d) ? n(d.value, "handler") : "unknown";
9
12
  throw t(u, f);
10
13
  };
11
- export { o as runRpcPromise };
14
+ export { s as deferRpcMethod, c as runRpcPromise };