@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.
- package/CHANGELOG.md +5321 -0
- package/THIRD-PARTY-NOTICES.md +1132 -13
- package/dist/apiRoleTransports.js +48 -0
- package/dist/apiRuntime.js +75 -65
- package/dist/apiSocketTracker.js +21 -0
- package/dist/apiSupervisor.js +16 -5
- package/dist/awaitResolvedApi.js +4 -4
- package/dist/bootstrap.d.ts +9 -0
- package/dist/bootstrap.js +3 -3
- package/dist/connectionScope.js +14 -2
- package/dist/form.d.ts +37 -4
- package/dist/form.js +4 -2
- package/dist/formData.js +72 -10
- package/dist/formRejection.js +23 -0
- package/dist/formSource.js +13 -0
- package/dist/index.d.ts +99 -20
- package/dist/index.js +56 -52
- package/dist/runtime.d.ts +17 -2
- package/dist/serverRequest.js +11 -7
- package/dist/serviceClient.js +49 -48
- package/dist/subscriptionCache.js +4 -4
- package/dist/useCapabilityManifest.js +27 -23
- package/dist/useEvent.js +77 -67
- package/dist/useFormBinding.js +225 -223
- package/dist/useRpcCaller.js +17 -0
- package/dist/useSubscription.js +55 -46
- package/package.json +2 -2
package/dist/serviceClient.js
CHANGED
|
@@ -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
|
|
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
|
-
},
|
|
14
|
-
let
|
|
15
|
-
if (
|
|
16
|
-
api:
|
|
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 (
|
|
22
|
-
let e = typeof
|
|
23
|
-
return
|
|
24
|
-
name: `service:${
|
|
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
|
-
|
|
27
|
-
|
|
26
|
+
roleEndpoints: y,
|
|
27
|
+
group: _.group,
|
|
28
|
+
headers: async () => ({ authorization: `Bearer ${_.token()}` }),
|
|
28
29
|
webSocketConstructor: t,
|
|
29
30
|
surfaceAudience: "service"
|
|
30
|
-
}).then((e) => (
|
|
31
|
-
throw
|
|
32
|
-
}),
|
|
33
|
-
},
|
|
34
|
-
api:
|
|
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
|
-
}),
|
|
39
|
-
let t =
|
|
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 ${
|
|
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
|
-
},
|
|
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
|
-
})),
|
|
50
|
-
let c = _
|
|
51
|
-
|
|
52
|
-
api:
|
|
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.${
|
|
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: () =>
|
|
62
|
-
catch: (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*
|
|
67
|
+
return yield* E(D(e));
|
|
67
68
|
}
|
|
68
|
-
let f = s?.idempotencyKey === void 0 &&
|
|
69
|
-
return yield*
|
|
70
|
-
|
|
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:
|
|
73
|
+
while: g,
|
|
73
74
|
schedule: l.spaced(a.millis(m))
|
|
74
75
|
}));
|
|
75
|
-
}),
|
|
76
|
+
}), h = !1;
|
|
76
77
|
return p.pipe(o.timeoutOrElse({
|
|
77
78
|
duration: a.millis(u),
|
|
78
|
-
orElse: () => o.fail(
|
|
79
|
-
}), o.mapError((t) => t?._tag === "RpcClientError" ?
|
|
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:
|
|
83
|
+
name: _.name,
|
|
83
84
|
call: async (t, n, r) => {
|
|
84
|
-
let i = await o.runPromiseExit(
|
|
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:
|
|
89
|
+
callEffect: O,
|
|
89
90
|
subscribe: (e, n, r) => {
|
|
90
|
-
if (_
|
|
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
|
|
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?.(
|
|
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: () =>
|
|
106
|
+
connected: () => S !== void 0,
|
|
106
107
|
close: async () => {
|
|
107
|
-
|
|
108
|
-
let e =
|
|
109
|
-
|
|
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
|
-
},
|
|
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 {
|
|
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
|
|
385
|
-
for (let
|
|
386
|
-
return
|
|
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 {
|
|
4
|
-
import { useEffect as
|
|
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
|
|
7
|
-
let { inspectBaseUrl: n } = e(t), [
|
|
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
|
|
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(
|
|
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]),
|
|
37
|
-
},
|
|
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
|
-
},
|
|
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
|
-
|
|
60
|
-
|
|
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 === "
|
|
63
|
-
else if (
|
|
64
|
-
if (
|
|
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
|
|
69
|
-
},
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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:
|
|
94
|
-
create:
|
|
95
|
-
update:
|
|
96
|
-
delete:
|
|
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 {
|
|
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 {
|
|
6
|
-
import { Effect as
|
|
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
|
|
8
|
+
var p = {
|
|
9
9
|
status: "idle",
|
|
10
10
|
missed: 0,
|
|
11
11
|
lastMiss: void 0
|
|
12
|
-
},
|
|
12
|
+
}, m = class {
|
|
13
13
|
_tag = "EventStreamClosed";
|
|
14
14
|
};
|
|
15
|
-
function
|
|
16
|
-
let { skip:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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:
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
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
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
origin:
|
|
58
|
-
n
|
|
59
|
-
});
|
|
60
|
-
return
|
|
61
|
-
key:
|
|
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
|
-
}))))),
|
|
72
|
-
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" ?
|
|
76
|
-
})))
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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 {
|
|
98
|
+
export { h as useEvent };
|