@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.
package/dist/outbox.js CHANGED
@@ -1,180 +1,180 @@
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 ee } from "./awaitResolvedApi.js";
6
- import { withIdempotencyKey as te } from "./mutationIdentity.js";
7
- import { useApiOnline as a } from "./useApiOnline.js";
8
- import { OutboxState as o } from "./outboxState.js";
9
- import { useCallback as s, useContext as c, useEffect as l, useMemo as ne, useRef as u, useState as d } from "react";
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
+ import { useApiOnline as s } from "./useApiOnline.js";
8
+ import { OutboxState as c } from "./outboxState.js";
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 f = (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
- }], p = (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), m = (e, t) => p(e, t, { status: "sent" }), h = (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), g = (e, t, n) => p(e, t, {
26
+ } : e), v = (e, t, n) => h(e, t, {
27
27
  status: "conflict",
28
28
  error: n
29
- }), _ = (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), v = (e) => e.filter((e) => e.status !== "sent"), y = (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
- }, b = (e) => {
41
+ }, te = (e) => {
42
42
  let t = e;
43
43
  return t?.conflict === !0 || t?._tag === "UndoBoundaryError" && t?.boundary === "conflict";
44
- }, x = (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
- }, S = (f) => {
48
- let { persistence: p, isConflict: m = b, idFor: h, api: g } = f;
49
- if (f.send === void 0 && g === void 0) throw Error("useOutbox: pass `send`, or `api` to send through that api's own mutations.");
50
- let _ = c(t), y = _?.demand;
51
- l(() => {
52
- g !== void 0 && y?.(g);
53
- }, [y, g]);
54
- let S = g === void 0 || _ === null ? void 0 : _.get(g), C = u(S);
55
- C.current = S;
56
- let [re, w] = d(0), [T, E] = d(0), D = a(g), O = f.online ?? D, k = u(void 0), A = u(0);
57
- k.current === void 0 && (k.current = new o());
58
- let j = ne(() => k.current.snapshot(), [re]), M = s((e) => {
59
- e(k.current), w((e) => e + 1);
60
- }, []), N = u(f.retryDelay ?? x);
61
- N.current = f.retryDelay ?? x;
62
- let P = u(f.stamp);
63
- P.current = f.stamp;
64
- let F = u(async () => void 0);
65
- F.current = f.send ?? (async (t) => {
66
- if (C.current === void 0) throw Error(`useOutbox: no mounted api '${g}' — render it inside the framework's runtime provider.`);
67
- let n = C.current, a = n.subjectSignal ?? (n.recovery ?? e(n.errorBus, g)).subjectSignal, o = await ee(C, g, t.tag, a);
68
- if (a?.throwIfAborted(), n.recovery !== void 0 && n.recovery !== o.recovery) throw Error("Outbox API ownership changed before the queued write started");
69
- let s = r(o.client, t.tag);
70
- await i(o.runtime, te(s(t.input), t.id), { signal: a });
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
+ d(() => {
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 });
71
71
  });
72
- let I = u(m);
73
- I.current = m;
74
- let L = u(void 0), R = u(!1), z = u(!0);
75
- l(() => (z.current = !0, () => {
76
- z.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;
77
77
  }), []);
78
- let B = u(0), V = u(Math.random().toString(36).slice(2, 8)), H = u(p === void 0), [U, W] = d(0), G = S === void 0 ? void 0 : S.recovery ?? e(S.errorBus, g), K = G?.subjectSignal;
79
- l(() => {
80
- if (G === void 0) return;
81
- let e = G.subjectSignal;
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;
79
+ d(() => {
80
+ if (K === void 0) return;
81
+ let e = K.subjectSignal;
82
82
  if (e.aborted) return;
83
83
  let t = () => {
84
- A.current++, L.current = void 0, Z(), k.current.reset(), w((e) => e + 1), H.current = p === void 0, R.current = !1, W((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);
85
85
  };
86
86
  return e.addEventListener("abort", t, { once: !0 }), () => {
87
87
  e.removeEventListener("abort", t);
88
88
  };
89
89
  }, [
90
- G,
91
- p,
92
- U
93
- ]), l(() => {
94
- if (p === void 0) return;
90
+ K,
91
+ h,
92
+ W
93
+ ]), d(() => {
94
+ if (h === void 0) return;
95
95
  let e = !1;
96
- return H.current = !1, p.load().then((t) => {
97
- e || (H.current = !0, t.length > 0 && M((e) => e.prepend(t.map((e) => {
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
98
  if (e.status !== "conflict" || !(e.error instanceof Error)) return e;
99
99
  let t = !1;
100
100
  try {
101
- t = I.current(e.error);
101
+ t = L.current(e.error);
102
102
  } catch {}
103
103
  return t ? e : {
104
104
  ...e,
105
105
  status: "failed"
106
106
  };
107
- }))), E((e) => e + 1));
107
+ }))), D((e) => e + 1));
108
108
  }, () => {
109
- e || (H.current = !0, E((e) => e + 1));
109
+ e || (U.current = !0, D((e) => e + 1));
110
110
  }), () => {
111
111
  e = !0;
112
112
  };
113
113
  }, [
114
- p,
115
- M,
116
- U
117
- ]), l(() => {
118
- p !== void 0 && H.current && p.save(v(j)).catch(() => {});
114
+ h,
115
+ N,
116
+ W
117
+ ]), d(() => {
118
+ h !== void 0 && U.current && h.save(b(M)).catch(() => {});
119
119
  }, [
120
- p,
121
- j,
122
- T
120
+ h,
121
+ M,
122
+ E
123
123
  ]);
124
- let q = u(/* @__PURE__ */ new Set()), J = S === void 0 || n(S) ? void 0 : S.cache;
125
- l(() => {
126
- if (J !== void 0 && S !== void 0) for (let e of j) {
127
- let t = S.descriptors[e.tag]?.targets;
124
+ let J = f(/* @__PURE__ */ new Set()), Y = C === void 0 || a(C) ? void 0 : C.cache;
125
+ d(() => {
126
+ if (Y !== void 0 && C !== void 0) for (let e of M) {
127
+ let t = C.descriptors[e.tag]?.targets;
128
128
  if (e.status === "pending" || e.status === "failed") {
129
- if (q.current.delete(e.id), t === void 0 || t.length === 0 || J.hasIntent(e.id) || typeof e.input != "object" || e.input === null) continue;
130
- J.autoApply(t, e.input, e.id, { standing: !0 });
131
- } else q.current.has(e.id) || (q.current.add(e.id), e.status === "sent" ? J.confirmByMutation(e.id) : J.revertByMutation(e.id));
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;
130
+ Y.autoApply(t, e.input, e.id, { standing: !0 });
131
+ } else J.current.has(e.id) || (J.current.add(e.id), e.status === "sent" ? Y.confirmByMutation(e.id) : Y.revertByMutation(e.id));
132
132
  }
133
133
  }, [
134
- J,
135
- S,
136
- j
134
+ Y,
135
+ C,
136
+ M
137
137
  ]);
138
- let Y = s((e, t, n) => {
139
- if (!z.current || K?.aborted || S !== C.current) throw Error("Outbox ownership changed before enqueue");
140
- let r = n?.stamp ?? P.current?.();
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
141
  if (r !== void 0 && typeof r != "string") throw TypeError("Outbox stamp must be a string");
142
- let i = h?.() ?? `obx_${V.current}_${B.current++}_${e}`;
143
- M((n) => n.append({
142
+ let i = _?.() ?? `obx_${H.current}_${V.current++}_${e}`;
143
+ N((n) => n.append({
144
144
  id: i,
145
145
  tag: e,
146
146
  input: t,
147
147
  status: "pending",
148
148
  attempts: 0,
149
149
  ...r === void 0 ? {} : { stamp: r }
150
- })), E((e) => e + 1);
150
+ })), D((e) => e + 1);
151
151
  }, [
152
- h,
153
- M,
154
- K,
155
- S
156
- ]), X = u(void 0), Z = s(() => {
152
+ _,
153
+ N,
154
+ q,
155
+ C
156
+ ]), X = f(void 0), Z = l(() => {
157
157
  X.current !== void 0 && clearTimeout(X.current), X.current = void 0;
158
158
  }, []);
159
- l(() => Z, [Z]);
160
- let Q = s(() => {
161
- if (!H.current || !z.current) return Promise.resolve();
162
- if (L.current !== void 0) return L.current;
163
- R.current = !1, Z();
164
- let e = A.current, t = Promise.resolve().then(async () => {
165
- for (; z.current && A.current === e;) {
166
- let t = k.current.next();
159
+ d(() => Z, [Z]);
160
+ let Q = l(() => {
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
167
  if (t === void 0) break;
168
168
  try {
169
- if (await F.current(t), !z.current || A.current !== e) break;
170
- M((e) => e.update(t.id, (e) => ({
169
+ if (await I.current(t), !B.current || j.current !== e) break;
170
+ N((e) => e.update(t.id, (e) => ({
171
171
  ...e,
172
172
  status: "sent"
173
173
  })));
174
174
  } catch (n) {
175
- if (!z.current || A.current !== e) break;
176
- let r = I.current(n);
177
- M((e) => e.update(t.id, (e) => r ? {
175
+ if (!B.current || j.current !== e) break;
176
+ let r = L.current(n);
177
+ N((e) => e.update(t.id, (e) => r ? {
178
178
  ...e,
179
179
  status: "conflict",
180
180
  error: n
@@ -183,59 +183,59 @@ var f = (e, t, n, r, i) => [...e, {
183
183
  status: "failed",
184
184
  error: n,
185
185
  attempts: e.attempts + 1
186
- })), R.current = !0, r || (X.current = setTimeout(() => {
186
+ })), z.current = !0, r || (X.current = setTimeout(() => {
187
187
  X.current = void 0, $.current();
188
- }, N.current(t.attempts + 1)));
188
+ }, P.current(t.attempts + 1)));
189
189
  break;
190
190
  }
191
191
  }
192
192
  }).finally(() => {
193
- L.current === t && (L.current = void 0);
193
+ R.current === t && (R.current = void 0);
194
194
  });
195
- return L.current = t, t;
196
- }, [M, Z]), $ = u(Q);
197
- $.current = Q, l(() => {
198
- O ? Q() : Z();
195
+ return R.current = t, t;
196
+ }, [N, Z]), $ = f(Q);
197
+ $.current = Q, d(() => {
198
+ k ? Q() : Z();
199
199
  }, [
200
- O,
200
+ k,
201
201
  Q,
202
202
  Z
203
- ]), l(() => {
204
- O && !R.current && Q();
203
+ ]), d(() => {
204
+ k && !z.current && Q();
205
205
  }, [
206
- T,
207
- O,
206
+ E,
207
+ k,
208
208
  Q
209
209
  ]);
210
- let ie = s((e, t) => {
211
- z.current && !K?.aborted && S === C.current && (M((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" ? {
212
212
  ...e,
213
213
  input: t,
214
214
  status: "pending",
215
215
  error: void 0
216
- } : e)), O && Q());
216
+ } : e)), k && Q());
217
217
  }, [
218
- O,
218
+ k,
219
219
  Q,
220
- M,
221
- K,
222
- S
223
- ]), ae = s((e) => !z.current || K?.aborted || S !== C.current || !k.current.snapshot().some((t) => t.id === e && t.status === "conflict") || (J?.revertByMutation(e), !z.current || K?.aborted || S !== C.current) || !k.current.discardConflict(e) ? !1 : (q.current.delete(e), R.current = !1, w((e) => e + 1), E((e) => e + 1), O && Q(), !0), [
224
- O,
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,
225
225
  Q,
226
- J,
227
- K,
228
- S
226
+ Y,
227
+ q,
228
+ C
229
229
  ]);
230
230
  return {
231
- queue: j,
232
- enqueue: Y,
231
+ queue: M,
232
+ enqueue: re,
233
233
  replay: Q,
234
- online: O,
235
- pending: j.reduce((e, t) => e + +(t.status === "pending" || t.status === "failed"), 0),
236
- conflicts: j.filter((e) => e.status === "conflict"),
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
237
  resolveConflict: ie,
238
238
  discardConflict: ae
239
239
  };
240
240
  };
241
- export { v as clearSent, x as defaultOutboxRetryDelay, f as enqueueEntry, g as markConflict, h as markFailed, m as markSent, y as replayable, _ as resolveConflictEntry, S 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 };
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();
@@ -1,26 +1,26 @@
1
- import { resolveByTag as e } from "./tagWalk.js";
2
- import { runRpcPromise as t } from "./runRpc.js";
3
- import { ConnectionPrerequisiteInvalidated as n } from "./connectionPrerequisite.js";
4
- import { awaitResolvedApi as r, bindResolvedRpcInvocationOwner as i, rpcInvocationOwnerCurrent as a } from "./awaitResolvedApi.js";
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
5
  import { Effect as o, Option as s, Stream as c } from "effect";
6
6
  import { firstEventValue as l } from "@voltro/protocol";
7
7
  // src/rpcCallOnce.ts
8
8
  var u = async (u, d, f, p, m, h, g) => {
9
9
  let _ = () => {
10
- if (g && !a(g, u.current)) throw new n("inactive");
10
+ if (g && !n(g, u.current)) throw new r("inactive");
11
11
  };
12
12
  _();
13
- let v = g?.subject, y = await r(u, d, f, m);
14
- if (v?.aborted) throw new n("inactive");
15
- g && i(g, y), _();
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
16
  let { runtime: b, client: x } = y;
17
17
  m?.throwIfAborted();
18
18
  let S = g ? new AbortController() : void 0, C = g ? [.../* @__PURE__ */ new Set([g.subject, ...m ? [m] : []])] : [], w = () => S?.abort();
19
19
  for (let e of C) e.aborted ? w() : e.addEventListener("abort", w, { once: !0 });
20
20
  try {
21
21
  _();
22
- let n = e(x, f)(p), r = o.isEffect(n), i = r ? n : c.runHead(n).pipe(o.flatMap((e) => s.isNone(e) ? o.fail(/* @__PURE__ */ Error(`${h} ${f}: the query ended before its first snapshot`)) : o.succeed(e.value))), a = await t(b, o.suspend(() => (_(), i)), { signal: S?.signal ?? m });
23
- return _(), r ? a : l(f, a, h);
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
24
  } catch (e) {
25
25
  throw _(), e;
26
26
  } finally {
package/dist/runtime.js CHANGED
@@ -1,16 +1,16 @@
1
- import { publishClientTrace as e, publishClientTraceRefusal as t, subscribeClientTraceRefusals as n, subscribeClientTraces as r } from "./traceBus.js";
2
- import { rememberRpcErrorKind as i, rpcErrorKind as a } from "./rpcErrorKind.js";
3
- import { clearClientDiagnostics as o, clientDiagnosticsSnapshot as s, recordClientDiagnostic as c, subscribeClientDiagnostics as l } from "./clientDiagnostics.js";
4
- import { stableKey as u } from "./stableKey.js";
5
- import { LoadingSubscriptionCache as d, SubscriptionCache as f, supersedesConfirmedPatches as p } from "./subscriptionCache.js";
6
- import { publishClientError as m, reportClientError as h, subscribeClientErrors as g } from "./clientErrorBus.js";
7
- import { RpcErrorBus as _ } from "./rpcErrorBus.js";
8
- import { apiConnectivity as v } from "./apiConnectivity.js";
9
- import { INITIAL_RECOVERY_SNAPSHOT as y, RecoveryCoordinator as b, recoveryCoordinatorFor as x, resolveRecoveryOptions as S } from "./recoveryCoordinator.js";
10
- import { resolveByTag as C } from "./tagWalk.js";
11
- import { buildApiRuntime as w, makeProtocolOpenRecovery as T } from "./apiRuntime.js";
12
- import { startApiSupervisor as E } from "./apiSupervisor.js";
13
- import { runRpcPromise as D } from "./runRpc.js";
14
- import { isUnauthenticated as O, wireAuthRefresh as k } from "./authRefresh.js";
15
- import { DEFAULT_SERVICE_CALL_TIMEOUT_MS as A, makeServiceClient as j, serviceApi as M } from "./serviceClient.js";
16
- export { A as DEFAULT_SERVICE_CALL_TIMEOUT_MS, y as INITIAL_RECOVERY_SNAPSHOT, d as LoadingSubscriptionCache, b as RecoveryCoordinator, _ as RpcErrorBus, f as SubscriptionCache, v as apiConnectivity, w as buildApiRuntime, o as clearClientDiagnostics, s as clientDiagnosticsSnapshot, O as isUnauthenticated, T as makeProtocolOpenRecovery, j as makeServiceClient, m as publishClientError, e as publishClientTrace, t as publishClientTraceRefusal, c as recordClientDiagnostic, x as recoveryCoordinatorFor, i as rememberRpcErrorKind, h as reportClientError, C as resolveByTag, S as resolveRecoveryOptions, a as rpcErrorKind, D as runRpcPromise, M as serviceApi, u as stableKey, E as startApiSupervisor, l as subscribeClientDiagnostics, g as subscribeClientErrors, n as subscribeClientTraceRefusals, r as subscribeClientTraces, p as supersedesConfirmedPatches, k as wireAuthRefresh };
1
+ import { buildApiRuntime as e, makeProtocolOpenRecovery as t } from "./apiRuntime.js";
2
+ import { startApiSupervisor as n } from "./apiSupervisor.js";
3
+ import { LoadingSubscriptionCache as r, SubscriptionCache as i, supersedesConfirmedPatches as a } from "./subscriptionCache.js";
4
+ import { stableKey as o } from "./stableKey.js";
5
+ import { RpcErrorBus as s } from "./rpcErrorBus.js";
6
+ import { INITIAL_RECOVERY_SNAPSHOT as c, RecoveryCoordinator as l, recoveryCoordinatorFor as u, resolveRecoveryOptions as d } from "./recoveryCoordinator.js";
7
+ import { apiConnectivity as f } from "./apiConnectivity.js";
8
+ import { runRpcPromise as p } from "./runRpc.js";
9
+ import { rememberRpcErrorKind as m, rpcErrorKind as h } from "./rpcErrorKind.js";
10
+ import { resolveByTag as g } from "./tagWalk.js";
11
+ import { DEFAULT_SERVICE_CALL_TIMEOUT_MS as _, makeServiceClient as v, serviceApi as y } from "./serviceClient.js";
12
+ import { isUnauthenticated as b, wireAuthRefresh as x } from "./authRefresh.js";
13
+ import { publishClientTrace as S, publishClientTraceRefusal as C, subscribeClientTraceRefusals as w, subscribeClientTraces as T } from "./traceBus.js";
14
+ import { publishClientError as E, reportClientError as D, subscribeClientErrors as O } from "./clientErrorBus.js";
15
+ import { clearClientDiagnostics as k, clientDiagnosticsSnapshot as A, recordClientDiagnostic as j, subscribeClientDiagnostics as M } from "./clientDiagnostics.js";
16
+ export { _ as DEFAULT_SERVICE_CALL_TIMEOUT_MS, c as INITIAL_RECOVERY_SNAPSHOT, r as LoadingSubscriptionCache, l as RecoveryCoordinator, s as RpcErrorBus, i as SubscriptionCache, f as apiConnectivity, e as buildApiRuntime, k as clearClientDiagnostics, A as clientDiagnosticsSnapshot, b as isUnauthenticated, t as makeProtocolOpenRecovery, v as makeServiceClient, E as publishClientError, S as publishClientTrace, C as publishClientTraceRefusal, j as recordClientDiagnostic, u as recoveryCoordinatorFor, m as rememberRpcErrorKind, D as reportClientError, g as resolveByTag, d as resolveRecoveryOptions, h as rpcErrorKind, p as runRpcPromise, y as serviceApi, o as stableKey, n as startApiSupervisor, M as subscribeClientDiagnostics, O as subscribeClientErrors, w as subscribeClientTraceRefusals, T as subscribeClientTraces, a as supersedesConfirmedPatches, x as wireAuthRefresh };
@@ -37,7 +37,7 @@ var l = () => {
37
37
  }, C = () => {
38
38
  let e = o(r);
39
39
  return e ? (b || (b = !0, x !== null && (clearTimeout(x), x = null)), e) : (globalThis.window !== void 0 && !y && !b && x === null && process.env.NODE_ENV !== "production" && (x = setTimeout(() => {
40
- x = null, !(y || b) && (y = !0, console.warn("useFrameworkRuntimes: no <FrameworkRuntimesProvider> in the tree — returning a loading baseline (subscriptions read `undefined`, mutations are no-ops). If this is not an intentional lazy/conditional mount, mount your app via @voltro/web mount() or wrap the subtree in <VoltroRuntimeProvider>."));
40
+ x = null, y || b || (y = !0, console.warn("useFrameworkRuntimes: no <FrameworkRuntimesProvider> in the tree — returning a loading baseline (subscriptions read `undefined`, mutations are no-ops). If this is not an intentional lazy/conditional mount, mount your app via @voltro/web mount() or wrap the subtree in <VoltroRuntimeProvider>."));
41
41
  }, 0)), v);
42
42
  }, w = (e) => {
43
43
  let t = C(), n = t.demand;
@@ -1,7 +1,7 @@
1
- import { squashRpcCause as e } from "./squashRpcCause.js";
2
- import { resolveByTag as t } from "./tagWalk.js";
3
- import { buildApiRuntime as n } from "./apiRuntime.js";
4
- import { freshIdempotencyKey as r, withIdempotencyKey as i } from "./mutationIdentity.js";
1
+ import { buildApiRuntime as e } from "./apiRuntime.js";
2
+ import { freshIdempotencyKey as t, withIdempotencyKey as n } from "./mutationIdentity.js";
3
+ import { squashRpcCause as r } from "./squashRpcCause.js";
4
+ import { resolveByTag as i } from "./tagWalk.js";
5
5
  import { Duration as a, Effect as o, Exit as s, Option as c, Schedule as l, Stream as u } from "effect";
6
6
  import * as d from "effect/http/Headers";
7
7
  import { RpcClient as f } from "effect/rpc";
@@ -19,14 +19,14 @@ var g = (e) => e?._tag === "MutationInFlight", _ = 1e4, v = (e, t) => {
19
19
  message: "client closed"
20
20
  }));
21
21
  if (x !== void 0) return x;
22
- let e = typeof _.wsUrl == "function" ? _.wsUrl() : _.wsUrl, t = _.webSocketConstructor ?? ((e, t) => new globalThis.WebSocket(e, typeof t == "object" && !Array.isArray(t) ? void 0 : t));
23
- return x = n({
22
+ let t = typeof _.wsUrl == "function" ? _.wsUrl() : _.wsUrl, n = _.webSocketConstructor ?? ((e, t) => new globalThis.WebSocket(e, typeof t == "object" && !Array.isArray(t) ? void 0 : t));
23
+ return x = e({
24
24
  name: `service:${_.name}`,
25
- wsUrl: e,
25
+ wsUrl: t,
26
26
  roleEndpoints: y,
27
27
  group: _.group,
28
28
  headers: async () => ({ authorization: `Bearer ${_.token()}` }),
29
- webSocketConstructor: t,
29
+ webSocketConstructor: n,
30
30
  surfaceAudience: "service"
31
31
  }).then((e) => (S = e, e), (e) => {
32
32
  throw x = void 0, e;
@@ -47,7 +47,7 @@ var g = (e) => e?._tag === "MutationInFlight", _ = 1e4, v = (e, t) => {
47
47
  if (c.isNone(e)) return o.fail(/* @__PURE__ */ Error("the query stream ended before its first snapshot"));
48
48
  let t = e.value;
49
49
  return t._tag === "error" ? o.fail(t.error) : o.succeed(t.data);
50
- })), O = (e, n, s) => {
50
+ })), O = (e, r, s) => {
51
51
  let c = v(_, e), u = s?.timeoutMs ?? b, d = Date.now(), f = (t) => {
52
52
  _.onCall?.({
53
53
  api: _.name,
@@ -61,13 +61,13 @@ var g = (e) => e?._tag === "MutationInFlight", _ = 1e4, v = (e, t) => {
61
61
  let u = yield* o.tryPromise({
62
62
  try: () => w(),
63
63
  catch: (t) => T(e, C ? "closed" : "transport", `could not build the connection: ${String(t)}`)
64
- }), d = t(u.client, e);
64
+ }), d = i(u.client, e);
65
65
  if (c === "query") {
66
- let e = d(n);
66
+ let e = d(r);
67
67
  return yield* E(D(e));
68
68
  }
69
- let f = s?.idempotencyKey === void 0 && _.ambientIdempotencyKey !== void 0 ? yield* _.ambientIdempotencyKey(e, n) : void 0, p = s?.idempotencyKey ?? f ?? r();
70
- return yield* E(i(d(n), p)).pipe(o.tapError((e) => o.sync(() => {
69
+ let f = s?.idempotencyKey === void 0 && _.ambientIdempotencyKey !== void 0 ? yield* _.ambientIdempotencyKey(e, r) : void 0, p = s?.idempotencyKey ?? f ?? t();
70
+ return yield* E(n(d(r), p)).pipe(o.tapError((e) => o.sync(() => {
71
71
  g(e) && (h = !0);
72
72
  })), o.retry({
73
73
  while: g,
@@ -81,26 +81,26 @@ var g = (e) => e?._tag === "MutationInFlight", _ = 1e4, v = (e, t) => {
81
81
  };
82
82
  return {
83
83
  name: _.name,
84
- call: async (t, n, r) => {
85
- let i = await o.runPromiseExit(O(t, n, r), r?.signal === void 0 ? void 0 : { signal: r.signal });
84
+ call: async (e, t, n) => {
85
+ let i = await o.runPromiseExit(O(e, t, n), n?.signal === void 0 ? void 0 : { signal: n.signal });
86
86
  if (s.isSuccess(i)) return i.value;
87
- throw e(i.cause);
87
+ throw r(i.cause);
88
88
  },
89
89
  callEffect: O,
90
- subscribe: (e, n, r) => {
90
+ subscribe: (e, t, n) => {
91
91
  if (v(_, e) !== "query") throw Error(`apis.${_.name}: '${e}' is not a query — only a query can be subscribed to`);
92
- let i, a = !1, o = -2, s;
92
+ let r, a = !1, o = -2, s;
93
93
  return w().then((c) => {
94
94
  if (a) return;
95
- let l = [e, n], u = c.cache.subscribe(l, () => t(c.client, e)(n), c.runtime, () => {
95
+ let l = [e, t], u = c.cache.subscribe(l, () => i(c.client, e)(t), c.runtime, () => {
96
96
  let e = u.getSnapshot();
97
- e.error !== void 0 && e.error !== s && (s = e.error, r.onError?.(e.error)), e.revision >= 0 && e.revision !== o && e.data !== void 0 && (o = e.revision, r.onValue(e.data));
97
+ e.error !== void 0 && e.error !== s && (s = e.error, n.onError?.(e.error)), e.revision >= 0 && e.revision !== o && e.data !== void 0 && (o = e.revision, n.onValue(e.data));
98
98
  });
99
- i = u.unsubscribe;
99
+ r = u.unsubscribe;
100
100
  }, (t) => {
101
- r.onError?.(T(e, "transport", `could not build the connection: ${String(t)}`));
101
+ n.onError?.(T(e, "transport", `could not build the connection: ${String(t)}`));
102
102
  }), { unsubscribe: () => {
103
- a = !0, i?.();
103
+ a = !0, r?.();
104
104
  } };
105
105
  },
106
106
  connected: () => S !== void 0,