@voltro/client 0.86.0 → 0.87.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.
@@ -5,91 +5,92 @@ import { freshIdempotencyKey as r, withIdempotencyKey as i } from "./mutationIde
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";
8
- import { ApiUnavailable as p, MUTATION_IN_FLIGHT_RETRY_AFTER_MS as m } from "@voltro/protocol";
8
+ import { ApiUnavailable as p, MUTATION_IN_FLIGHT_RETRY_AFTER_MS as m, captureApiRoleEndpoints as h } from "@voltro/protocol";
9
9
  //#region src/serviceClient.ts
10
- var h = (e) => e?._tag === "MutationInFlight", g = 1e4, _ = (e, t) => {
10
+ var g = (e) => e?._tag === "MutationInFlight", _ = 1e4, v = (e, t) => {
11
11
  let n = e.descriptors[t]?.kind;
12
12
  return n === "query" || n === "mutation" || n === "action" ? n : void 0;
13
- }, v = (g) => {
14
- let v = g.defaultTimeoutMs ?? 1e4, y, b, x = !1, S = () => {
15
- if (x) return Promise.reject(new p({
16
- api: g.name,
13
+ }, y = (_) => {
14
+ let y = _.roleEndpoints === void 0 ? void 0 : h(_.roleEndpoints), b = _.defaultTimeoutMs ?? 1e4, x, S, C = !1, w = () => {
15
+ if (C) return Promise.reject(new p({
16
+ api: _.name,
17
17
  tag: "",
18
18
  reason: "closed",
19
19
  message: "client closed"
20
20
  }));
21
- if (y !== void 0) return y;
22
- let e = typeof g.wsUrl == "function" ? g.wsUrl() : g.wsUrl, t = g.webSocketConstructor ?? ((e, t) => new globalThis.WebSocket(e, typeof t == "object" && !Array.isArray(t) ? void 0 : t));
23
- return y = n({
24
- name: `service:${g.name}`,
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({
24
+ name: `service:${_.name}`,
25
25
  wsUrl: e,
26
- group: g.group,
27
- headers: async () => ({ authorization: `Bearer ${g.token()}` }),
26
+ roleEndpoints: y,
27
+ group: _.group,
28
+ headers: async () => ({ authorization: `Bearer ${_.token()}` }),
28
29
  webSocketConstructor: t,
29
30
  surfaceAudience: "service"
30
- }).then((e) => (b = e, e), (e) => {
31
- throw y = void 0, e;
32
- }), y;
33
- }, C = (e, t, n) => new p({
34
- api: g.name,
31
+ }).then((e) => (S = e, e), (e) => {
32
+ throw x = void 0, e;
33
+ }), x;
34
+ }, T = (e, t, n) => new p({
35
+ api: _.name,
35
36
  tag: e,
36
37
  reason: t,
37
38
  message: n
38
- }), w = (e) => {
39
- let t = g.callHeaders?.() ?? {};
39
+ }), E = (e) => {
40
+ let t = _.callHeaders?.() ?? {};
40
41
  return e.pipe(o.updateService(f.CurrentHeaders, (e) => {
41
- let n = d.set(e, "authorization", `Bearer ${g.token()}`);
42
+ let n = d.set(e, "authorization", `Bearer ${_.token()}`);
42
43
  for (let [e, r] of Object.entries(t)) n = d.set(n, e, r);
43
44
  return n;
44
45
  }));
45
- }, T = (e) => e.pipe(u.filter((e) => e._tag === "snapshot" || e._tag === "error"), u.runHead, o.flatMap((e) => {
46
+ }, D = (e) => e.pipe(u.filter((e) => e._tag === "snapshot" || e._tag === "error"), u.runHead, o.flatMap((e) => {
46
47
  if (c.isNone(e)) return o.fail(/* @__PURE__ */ Error("the query stream ended before its first snapshot"));
47
48
  let t = e.value;
48
49
  return t._tag === "error" ? o.fail(t.error) : o.succeed(t.data);
49
- })), E = (e, n, s) => {
50
- let c = _(g, e), u = s?.timeoutMs ?? v, d = Date.now(), f = (t) => {
51
- g.onCall?.({
52
- api: g.name,
50
+ })), O = (e, n, s) => {
51
+ let c = v(_, e), u = s?.timeoutMs ?? b, d = Date.now(), f = (t) => {
52
+ _.onCall?.({
53
+ api: _.name,
53
54
  tag: e,
54
55
  durationMs: Date.now() - d,
55
56
  outcome: t
56
57
  });
57
58
  };
58
- if (c === void 0) return o.die(/* @__PURE__ */ Error(`apis.${g.name}: '${e}' is not a service procedure of this api — is the caller built against an older contract?`));
59
+ if (c === void 0) return o.die(/* @__PURE__ */ Error(`apis.${_.name}: '${e}' is not a service procedure of this api — is the caller built against an older contract?`));
59
60
  let p = o.gen(function* () {
60
61
  let u = yield* o.tryPromise({
61
- try: () => S(),
62
- catch: (t) => C(e, x ? "closed" : "transport", `could not build the connection: ${String(t)}`)
62
+ try: () => w(),
63
+ catch: (t) => T(e, C ? "closed" : "transport", `could not build the connection: ${String(t)}`)
63
64
  }), d = t(u.client, e);
64
65
  if (c === "query") {
65
66
  let e = d(n);
66
- return yield* w(T(e));
67
+ return yield* E(D(e));
67
68
  }
68
- let f = s?.idempotencyKey === void 0 && g.ambientIdempotencyKey !== void 0 ? yield* g.ambientIdempotencyKey(e, n) : void 0, p = s?.idempotencyKey ?? f ?? r();
69
- return yield* w(i(d(n), p)).pipe(o.tapError((e) => o.sync(() => {
70
- h(e) && (y = !0);
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(() => {
71
+ g(e) && (h = !0);
71
72
  })), o.retry({
72
- while: h,
73
+ while: g,
73
74
  schedule: l.spaced(a.millis(m))
74
75
  }));
75
- }), y = !1;
76
+ }), h = !1;
76
77
  return p.pipe(o.timeoutOrElse({
77
78
  duration: a.millis(u),
78
- orElse: () => o.fail(C(e, "timeout", y ? `no answer within ${u} ms — an earlier send with this idempotency key is still in flight on the callee` : `no answer within ${u} ms`))
79
- }), o.mapError((t) => t?._tag === "RpcClientError" ? C(e, "transport", String(t.message ?? t)) : t), o.tapError((e) => o.sync(() => f(e?._tag === "ApiUnavailable" ? "unavailable" : "error"))), o.tap(() => o.sync(() => f("ok"))));
79
+ orElse: () => o.fail(T(e, "timeout", h ? `no answer within ${u} ms — an earlier send with this idempotency key is still in flight on the callee` : `no answer within ${u} ms`))
80
+ }), o.mapError((t) => t?._tag === "RpcClientError" ? T(e, "transport", String(t.message ?? t)) : t), o.tapError((e) => o.sync(() => f(e?._tag === "ApiUnavailable" ? "unavailable" : "error"))), o.tap(() => o.sync(() => f("ok"))));
80
81
  };
81
82
  return {
82
- name: g.name,
83
+ name: _.name,
83
84
  call: async (t, n, r) => {
84
- let i = await o.runPromiseExit(E(t, n, r), r?.signal === void 0 ? void 0 : { signal: r.signal });
85
+ let i = await o.runPromiseExit(O(t, n, r), r?.signal === void 0 ? void 0 : { signal: r.signal });
85
86
  if (s.isSuccess(i)) return i.value;
86
87
  throw e(i.cause);
87
88
  },
88
- callEffect: E,
89
+ callEffect: O,
89
90
  subscribe: (e, n, r) => {
90
- if (_(g, e) !== "query") throw Error(`apis.${g.name}: '${e}' is not a query — only a query can be subscribed to`);
91
+ if (v(_, e) !== "query") throw Error(`apis.${_.name}: '${e}' is not a query — only a query can be subscribed to`);
91
92
  let i, a = !1, o = -2, s;
92
- return S().then((c) => {
93
+ return w().then((c) => {
93
94
  if (a) return;
94
95
  let l = [e, n], u = c.cache.subscribe(l, () => t(c.client, e)(n), c.runtime, () => {
95
96
  let e = u.getSnapshot();
@@ -97,19 +98,19 @@ var h = (e) => e?._tag === "MutationInFlight", g = 1e4, _ = (e, t) => {
97
98
  });
98
99
  i = u.unsubscribe;
99
100
  }, (t) => {
100
- r.onError?.(C(e, "transport", `could not build the connection: ${String(t)}`));
101
+ r.onError?.(T(e, "transport", `could not build the connection: ${String(t)}`));
101
102
  }), { unsubscribe: () => {
102
103
  a = !0, i?.();
103
104
  } };
104
105
  },
105
- connected: () => b !== void 0,
106
+ connected: () => S !== void 0,
106
107
  close: async () => {
107
- x = !0;
108
- let e = b;
109
- b = void 0, y = void 0, e !== void 0 && (e.cache.destroy(e.runtime), await e.runtime.dispose());
108
+ C = !0;
109
+ let e = S;
110
+ S = void 0, x = void 0, e !== void 0 && (e.cache.destroy(e.runtime), await e.runtime.dispose());
110
111
  }
111
112
  };
112
- }, y = (e) => {
113
+ }, b = (e) => {
113
114
  let t = (n) => {
114
115
  let r = n.join("."), i = Object.assign((t, n) => e.call(r, t, n), {
115
116
  effect: (t, n) => e.callEffect(r, t, n),
@@ -125,4 +126,4 @@ var h = (e) => e?._tag === "MutationInFlight", g = 1e4, _ = (e, t) => {
125
126
  return new Proxy({}, { get: (e, n) => typeof n == "string" && n !== "then" ? t([n]) : void 0 });
126
127
  };
127
128
  //#endregion
128
- export { g as DEFAULT_SERVICE_CALL_TIMEOUT_MS, v as makeServiceClient, y as serviceApi };
129
+ export { _ as DEFAULT_SERVICE_CALL_TIMEOUT_MS, y as makeServiceClient, b as serviceApi };
@@ -380,10 +380,10 @@ var h = (e) => e === void 0 ? /* @__PURE__ */ Error("[voltro] the subscription f
380
380
  let t = this.entries.get(a(e));
381
381
  return !t?.fetch || !t.runtime || t.subscribers.size === 0 || this.refreshing.has(t) || t.state.base === void 0 && t.state.baseError === void 0 ? !1 : (this.refreshing.add(t), this.reissue(t, t.runtime, !1), !0);
382
382
  }
383
- resumeTransportFailures(e) {
384
- let t = 0;
385
- for (let n of this.entries.values()) n.resumeAfterTransportOpen && (n.fiber !== null || n.fetch === null || n.subscribers.size === 0 ? this.diagnose("subscription.reissue-skipped", n, { reason: n.fiber === null ? n.fetch === null ? "missing-fetch" : "no-subscribers" : "fiber-running" }) : (n.recoveryAttempt += 1, n.recoveryPhase = "awaiting-delivery", n.lastReissueAt = Date.now(), n.recoveryBasePreserved = n.state.base !== void 0, this.diagnose("subscription.reissue-started", n, { basePreserved: n.recoveryBasePreserved }), this.reissue(n, e, !1), this.armRecoveryWatchdog(n), t += 1));
386
- return t;
383
+ resumeTransportFailures(e, t) {
384
+ let n = 0;
385
+ for (let r of this.entries.values()) !r.resumeAfterTransportOpen || t && !t(r.tag) || (r.fiber !== null || r.fetch === null || r.subscribers.size === 0 ? this.diagnose("subscription.reissue-skipped", r, { reason: r.fiber === null ? r.fetch === null ? "missing-fetch" : "no-subscribers" : "fiber-running" }) : (r.recoveryAttempt += 1, r.recoveryPhase = "awaiting-delivery", r.lastReissueAt = Date.now(), r.recoveryBasePreserved = r.state.base !== void 0, this.diagnose("subscription.reissue-started", r, { basePreserved: r.recoveryBasePreserved }), this.reissue(r, e, !1), this.armRecoveryWatchdog(r), n += 1));
386
+ return n;
387
387
  }
388
388
  armRecoveryWatchdog(e) {
389
389
  let t = e.recoveryAttempt;
@@ -1,21 +1,21 @@
1
1
  import { useFrameworkApi as e } from "./runtimeContext.js";
2
2
  import { scopeMembership as t } from "./scopeMembership.js";
3
- import { usePermissions as n } from "./permissions.js";
4
- import { useEffect as r, useState as i } from "react";
3
+ import { ADMIN_SCOPE as n, usePermissions as r } from "./permissions.js";
4
+ import { useEffect as i, useState as a } from "react";
5
5
  //#region src/useCapabilityManifest.ts
6
- var a = (e) => `${e.replace(/\/$/, "")}/_voltro/inspect/manifest`, o = (t) => {
7
- let { inspectBaseUrl: n } = e(t), [o, s] = i({
6
+ var o = (e) => `${e.replace(/\/$/, "")}/_voltro/inspect/manifest`, s = (t) => {
7
+ let { inspectBaseUrl: n } = e(t), [r, s] = a({
8
8
  manifest: void 0,
9
9
  loading: !0,
10
10
  error: void 0
11
11
  });
12
- return r(() => {
12
+ return i(() => {
13
13
  let e = !1;
14
14
  return s({
15
15
  manifest: void 0,
16
16
  loading: !0,
17
17
  error: void 0
18
- }), fetch(a(n ?? "")).then(async (e) => {
18
+ }), fetch(o(n ?? "")).then(async (e) => {
19
19
  if (!e.ok) throw Error(`manifest fetch failed: HTTP ${e.status}`);
20
20
  return await e.json();
21
21
  }).then((t) => {
@@ -33,8 +33,8 @@ var a = (e) => `${e.replace(/\/$/, "")}/_voltro/inspect/manifest`, o = (t) => {
33
33
  }), () => {
34
34
  e = !0;
35
35
  };
36
- }, [t, n]), o;
37
- }, s = (e) => {
36
+ }, [t, n]), r;
37
+ }, c = (e) => {
38
38
  if (Object.getPrototypeOf(e) !== Array.prototype || Object.hasOwn(e, Symbol.iterator)) return !1;
39
39
  for (let t = 0; t < e.length; t++) {
40
40
  let n = Object.getOwnPropertyDescriptor(e, String(t));
@@ -54,24 +54,28 @@ var a = (e) => `${e.replace(/\/$/, "")}/_voltro/inspect/manifest`, o = (t) => {
54
54
  }
55
55
  }
56
56
  return !0;
57
- }, c = (e, t, n) => t.scope.length === 0 || (t.mode === "any" ? t.scope.some((t) => n?.has(t) ?? e.includes(t)) : t.scope.every((t) => n?.has(t) ?? e.includes(t))), l = (e, n) => {
57
+ }, l = (e, t, n) => t.scope.length === 0 || (t.mode === "any" ? t.scope.some((t) => n?.has(t) ?? e.includes(t)) : t.scope.every((t) => n?.has(t) ?? e.includes(t))), u = (e, r) => {
58
58
  if (e === void 0) return "unknown";
59
- if (n.includes("admin:full") || e.length === 0) return "allowed";
60
- let r = e.length >= 32 && n.length >= 32 && !Object.hasOwn(n, "includes") && !Object.hasOwn(n, Symbol.iterator) && s(e) ? t(n) : void 0, i = !1;
59
+ let i = r.includes(n);
60
+ if (e.length === 0) return "allowed";
61
+ let a = e.length >= 32 && r.length >= 32 && !Object.hasOwn(r, "includes") && !Object.hasOwn(r, Symbol.iterator) && c(e) ? t(r) : void 0, o = !1;
61
62
  for (let t of e) if (t.kind !== "open") {
62
- if (t.kind === "policy") i = !0;
63
- else if (!c(n, t, r)) {
64
- if (t.resourceScoped) i = !0;
63
+ if (t.kind === "upgraded") o = !0;
64
+ else if (t.kind === "policy") {
65
+ if (i) continue;
66
+ o = !0;
67
+ } else if (!(i || l(r, t, a))) {
68
+ if (t.resourceScoped) o = !0;
65
69
  else return "denied";
66
70
  }
67
71
  }
68
- return i ? "unknown" : "allowed";
69
- }, u = (e) => (e ?? []).flatMap((e) => e.kind === "scope" ? [...e.scope] : []), d = (e) => {
72
+ return o ? "unknown" : "allowed";
73
+ }, d = (e) => (e ?? []).flatMap((e) => e.kind === "scope" ? [...e.scope] : []), f = (e) => {
70
74
  for (let t of e ?? []) if (t.kind === "open") return t.reason;
71
- }, f = (e) => l(e, n().scopes), p = (e) => e === void 0 ? {} : {
75
+ }, p = (e) => u(e, r().scopes), m = (e) => e === void 0 ? {} : {
72
76
  tag: e.tag,
73
77
  ...e.guards === void 0 ? {} : { guards: e.guards }
74
- }, m = (e) => {
78
+ }, h = (e) => {
75
79
  let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
76
80
  for (let r of e.procedures) if (r.kind === "query") {
77
81
  let e = Array.isArray(r.source) ? r.source : [r.source];
@@ -90,12 +94,12 @@ var a = (e) => `${e.replace(/\/$/, "")}/_voltro/inspect/manifest`, o = (t) => {
90
94
  reactive: e.reactive,
91
95
  ...c === void 0 ? {} : { pkColumn: c },
92
96
  editable: (e.editable ?? !0) && c !== void 0,
93
- list: p(r),
94
- create: p(a),
95
- update: p(o),
96
- delete: p(s)
97
+ list: m(r),
98
+ create: m(a),
99
+ update: m(o),
100
+ delete: m(s)
97
101
  };
98
102
  });
99
103
  };
100
104
  //#endregion
101
- export { l as decideAccess, m as deriveEntityAdmins, a as manifestUrl, d as openAccessReason, u as requiredScopes, f as useAccessDecision, o as useCapabilityManifest };
105
+ export { u as decideAccess, h as deriveEntityAdmins, o as manifestUrl, f as openAccessReason, d as requiredScopes, p as useAccessDecision, s as useCapabilityManifest };
package/dist/useEvent.js CHANGED
@@ -2,87 +2,97 @@ import { recordClientDiagnostic as e } from "./clientDiagnostics.js";
2
2
  import { isUnresolvedApi as t } from "./frameworkRuntimesContext.js";
3
3
  import { useFrameworkApi as n } from "./runtimeContext.js";
4
4
  import { resolveByTag as r } from "./tagWalk.js";
5
- import { useCallback as i, useEffect as a, useRef as o, useState as s } from "react";
6
- import { Effect as c, Fiber as l, Schedule as u, Stream as d } from "effect";
5
+ import { useEffect as i, useLayoutEffect as a, useMemo as o, useRef as s, useState as c } from "react";
6
+ import { Effect as l, Fiber as u, Schedule as d, Stream as f } from "effect";
7
7
  //#region src/useEvent.ts
8
- var f = {
8
+ var p = {
9
9
  status: "idle",
10
10
  missed: 0,
11
11
  lastMiss: void 0
12
- }, p = class {
12
+ }, m = class {
13
13
  _tag = "EventStreamClosed";
14
14
  };
15
- function m(m, h, g, _ = {}) {
16
- let { skip: v = !1, apiName: y = "app", onMissed: b } = _, x = n(y), { runtime: S, client: C } = x, [w, T] = s(f), E = o(g);
17
- E.current = g;
18
- let D = o(b);
19
- D.current = b;
20
- let O = o(C);
21
- O.current = C;
22
- let k = o(S);
23
- k.current = S;
24
- let A = o(/* @__PURE__ */ new Map()), j = h === null ? null : JSON.stringify(Object.entries(h).sort(([e], [t]) => e < t ? -1 : 1)), M = o(h);
25
- M.current = h;
26
- let N = o(null);
27
- N.current !== j && (N.current = j, A.current = /* @__PURE__ */ new Map());
28
- let P = i((t, n) => {
29
- t <= 0 || (e(y, "event.gap", {
30
- tag: m.name,
31
- missed: t,
32
- reason: n
33
- }), T((e) => ({
34
- ...e,
35
- missed: e.missed + t,
36
- lastMiss: {
15
+ function h(h, g, _, v = {}) {
16
+ let { skip: y = !1, apiName: b = "app", onMissed: x } = v, S = n(b), C = g === null ? null : JSON.stringify(Object.entries(g).sort(([e], [t]) => e < t ? -1 : 1)), w = !y && C !== null && !t(S), T = o(() => ({
17
+ resume: /* @__PURE__ */ new Map(),
18
+ runtime: S.runtime,
19
+ client: S.client,
20
+ subject: S.subjectSignal ?? S.recovery?.subjectSignal,
21
+ key: C === null ? null : Object.fromEntries(JSON.parse(C)),
22
+ tag: h.name,
23
+ apiName: b
24
+ }), [
25
+ S.cache,
26
+ b,
27
+ h.name,
28
+ C,
29
+ w
30
+ ]), E = s(null), [D, O] = c(null);
31
+ return a(() => (E.current = {
32
+ scope: T,
33
+ handler: _,
34
+ onMissed: x
35
+ }, () => {
36
+ E.current = null;
37
+ })), i(() => {
38
+ if (!w || T.subject?.aborted) return;
39
+ let t = !1, n = () => !t && !T.subject?.aborted && E.current?.scope === T, i = (e) => {
40
+ n() && O((t) => ({
41
+ scope: T,
42
+ value: e(t?.scope === T ? t.value : p)
43
+ }));
44
+ }, a = (t, r) => {
45
+ !n() || t <= 0 || (e(T.apiName, "event.gap", {
46
+ tag: T.tag,
47
+ missed: t,
48
+ reason: r
49
+ }), i((e) => ({
50
+ ...e,
51
+ missed: e.missed + t,
52
+ lastMiss: {
53
+ count: t,
54
+ reason: r
55
+ }
56
+ })), E.current?.onMissed?.({
37
57
  count: t,
38
- reason: n
39
- }
40
- })), D.current?.({
41
- count: t,
42
- reason: n
43
- }));
44
- }, [y, m.name]), F = !v && j !== null && !t(x);
45
- return a(() => {
46
- if (!F) {
47
- T(f);
48
- return;
49
- }
50
- T((e) => ({
58
+ reason: r
59
+ }));
60
+ };
61
+ i((e) => ({
51
62
  ...e,
52
63
  status: "connecting"
53
64
  }));
54
- let e = 0, t = c.sync(() => {
55
- let e = [];
56
- for (let [t, n] of A.current) e.push({
57
- origin: t,
58
- n
59
- });
60
- return r(O.current, m.name)({
61
- key: M.current,
65
+ let o = l.suspend(() => {
66
+ if (!n()) return l.interrupt;
67
+ let e = [...T.resume].map(([e, t]) => ({
68
+ origin: e,
69
+ n: t
70
+ })), t = r(T.client, T.tag);
71
+ return l.succeed(t({
72
+ key: T.key,
62
73
  ...e.length > 0 ? { resume: e } : {}
63
- });
64
- }), n = d.unwrap(t).pipe(d.tap(() => c.sync(() => {
65
- e = 0;
66
- })), d.concat(d.fail(new p())), d.retry(u.min([u.exponential("250 millis", 2), u.spaced("30 seconds")]).pipe(u.jittered, u.tap(() => c.sync(() => {
67
- e += 1, T((e) => ({
68
- ...e,
69
- status: "connecting"
70
74
  }));
71
- }))))), i = k.current.runFork(d.runForEach(n, (e) => c.sync(() => {
72
- e._tag === "attached" ? T((e) => ({
75
+ }), s = f.unwrap(o).pipe(f.concat(f.fail(new m())), f.retry(d.min([d.exponential("250 millis", 2), d.spaced("30 seconds")]).pipe(d.jittered, d.tap(() => l.sync(() => i((e) => ({
76
+ ...e,
77
+ status: "connecting"
78
+ }))))))), c = T.runtime.runFork(f.runForEach(s, (e) => l.sync(() => {
79
+ n() && (e._tag === "attached" ? i((e) => ({
73
80
  ...e,
74
81
  status: "live"
75
- })) : e._tag === "gap" ? P(e.missed, e.reason) : (A.current.set(e.origin, Math.max(A.current.get(e.origin) ?? 0, e.n)), E.current(e.payload));
76
- })));
77
- return () => {
78
- k.current.runFork(c.forkDetach(l.interrupt(i)));
82
+ })) : e._tag === "gap" ? a(e.missed, e.reason) : (T.resume.set(e.origin, Math.max(T.resume.get(e.origin) ?? 0, e.n)), E.current?.handler(e.payload)));
83
+ }))), h = () => {
84
+ t || (t = !0, T.resume.clear(), O((e) => e?.scope === T ? {
85
+ scope: T,
86
+ value: p
87
+ } : e), T.runtime.runFork(l.forkDetach(u.interrupt(c))));
88
+ };
89
+ return T.subject?.addEventListener("abort", h, { once: !0 }), T.subject?.aborted && h(), () => {
90
+ T.subject?.removeEventListener("abort", h), h();
79
91
  };
80
- }, [
81
- F,
82
- j,
83
- m.name,
84
- P
85
- ]), F ? w : f;
92
+ }, [w, T]), !w || T.subject?.aborted ? p : D?.scope === T ? D.value : {
93
+ ...p,
94
+ status: "connecting"
95
+ };
86
96
  }
87
97
  //#endregion
88
- export { m as useEvent };
98
+ export { h as useEvent };