@voltro/client 0.85.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 +5987 -0
- package/THIRD-PARTY-NOTICES.md +1125 -34
- package/dist/analyticsCatalog.js +47 -0
- package/dist/apiConnectivity.js +33 -0
- package/dist/apiRoleTransports.js +48 -0
- package/dist/apiRuntime.js +145 -0
- package/dist/apiSocketTracker.js +21 -0
- package/dist/apiSupervisor.js +136 -0
- package/dist/authRefresh.js +20 -0
- package/dist/awaitResolvedApi.js +23 -0
- package/dist/bootstrap.d.ts +1153 -0
- package/dist/bootstrap.js +8 -0
- package/dist/cellMerger.js +6 -0
- package/dist/clientDiagnostics.js +94 -0
- package/dist/clientErrorBus.js +16 -0
- package/dist/clientScheduler.js +31 -0
- package/dist/connectionPrerequisite.js +70 -0
- package/dist/connectionScope.js +47 -0
- package/dist/connectionSetupController.js +206 -0
- package/dist/createHooks.js +15 -0
- package/dist/deepLink.js +69 -0
- package/dist/filters.js +58 -0
- package/dist/form.d.ts +37 -4
- package/dist/form.js +7 -2
- package/dist/formBinding.js +325 -0
- package/dist/formData.js +127 -0
- package/dist/formFlashId.js +4 -0
- package/dist/formRejection.js +23 -0
- package/dist/formSource.js +13 -0
- package/dist/frameworkRuntimesContext.js +8 -0
- package/dist/globalContext.js +10 -0
- package/dist/index.d.ts +152 -27
- package/dist/index.js +87 -4121
- package/dist/liveRowSort.js +66 -0
- package/dist/mutationConnectionSetup.js +16 -0
- package/dist/mutationIdentity.js +10 -0
- package/dist/mutationSerialExecution.js +53 -0
- package/dist/mutationsBus.js +40 -0
- package/dist/onlineSource.js +13 -0
- package/dist/outbox.js +213 -0
- package/dist/outboxHttp.js +104 -0
- package/dist/outboxState.js +43 -0
- package/dist/permissions.js +20 -0
- package/dist/platform.js +121 -0
- package/dist/preloadSeed.js +47 -0
- package/dist/provider.js +22 -0
- package/dist/query.js +12 -2
- package/dist/recoveryCoordinator.js +195 -0
- package/dist/recoveryRetry.js +24 -0
- package/dist/richText.js +176 -0
- package/dist/rpcErrorBus.js +39 -0
- package/dist/rpcErrorKind.js +13 -0
- package/dist/runRpc.js +12 -0
- package/dist/runtime.d.ts +49 -3
- package/dist/runtime.js +16 -126
- package/dist/runtimeCapabilities.js +44 -0
- package/dist/runtimeContext.js +49 -0
- package/dist/schemaFields.js +219 -0
- package/dist/scopeMembership.js +12 -0
- package/dist/seedResolvers.js +7 -0
- package/dist/sequence.js +65 -0
- package/dist/serverRequest.js +28 -0
- package/dist/serviceClient.js +129 -0
- package/dist/squashRpcCause.js +8 -0
- package/dist/stableKey.js +21 -0
- package/dist/store.js +288 -0
- package/dist/storeStorage.js +28 -0
- package/dist/subscriptionCache.js +724 -0
- package/dist/tagWalk.js +23 -0
- package/dist/traceBus.js +10 -0
- package/dist/tracking.js +40 -0
- package/dist/uploadProgress.js +21 -0
- package/dist/useAction.js +101 -0
- package/dist/useAgent.js +53 -0
- package/dist/useAgentChat.js +43 -0
- package/dist/useAgentStream.js +64 -0
- package/dist/useApiOnline.js +14 -0
- package/dist/useCapabilityManifest.js +105 -0
- package/dist/useConnectionSetup.js +28 -0
- package/dist/useConnectionStatus.js +38 -0
- package/dist/useConnections.js +107 -0
- package/dist/useDataCopilot.js +24 -0
- package/dist/useDataTable.js +34 -0
- package/dist/useDerived.js +22 -0
- package/dist/useEvent.js +98 -0
- package/dist/useFormBinding.js +478 -0
- package/dist/useLocalQuery.js +59 -0
- package/dist/useMutation.js +214 -0
- package/dist/useOnRpcError.js +13 -0
- package/dist/usePreloadedSubscription.js +18 -0
- package/dist/usePreview.js +14 -0
- package/dist/useProvenance.js +51 -0
- package/dist/useQueryField.js +34 -0
- package/dist/useRecord.js +12 -0
- package/dist/useRefreshSubscriptions.js +22 -0
- package/dist/useResourceCan.js +18 -0
- package/dist/useResumableAgentStream.js +75 -0
- package/dist/useRpcCaller.js +17 -0
- package/dist/useSequence.js +25 -0
- package/dist/useSkeleton.js +13 -0
- package/dist/useSubscription.js +98 -0
- package/dist/useSubscriptionHealth.js +32 -0
- package/dist/useTranscription.js +51 -0
- package/dist/useUndo.js +33 -0
- package/dist/useUndoLog.js +44 -0
- package/dist/useUpload.js +296 -0
- package/dist/useWindowedSubscription.js +65 -0
- package/dist/useWorkflow.js +284 -0
- package/dist/useWorkflowRunState.js +93 -0
- package/dist/validation.js +39 -0
- package/dist/validationMessages.js +5 -0
- package/package.json +7 -2
- package/dist/authRefresh-DmfSoCca.js +0 -360
- package/dist/formData-BfpBt7BQ.js +0 -769
- package/dist/queryOnce-D5Y4V1SB.js +0 -55
- package/dist/runRpc-Zfz3w709.js +0 -1172
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Schema as e, SchemaIssue as t } from "effect";
|
|
2
|
+
//#region src/analyticsCatalog.ts
|
|
3
|
+
var n = (e, t) => ({
|
|
4
|
+
name: e,
|
|
5
|
+
payload: t
|
|
6
|
+
}), r = (n, r) => {
|
|
7
|
+
let i = e.decodeUnknownResult(n.payload, { errors: "all" })(r);
|
|
8
|
+
if (i._tag === "Success") return {
|
|
9
|
+
valid: !0,
|
|
10
|
+
errors: {}
|
|
11
|
+
};
|
|
12
|
+
let a = {};
|
|
13
|
+
for (let e of t.makeFormatterStandardSchemaV1()(i.failure.issue).issues) a[(e.path ?? []).join(".") || "(root)"] = e.message;
|
|
14
|
+
return {
|
|
15
|
+
valid: !1,
|
|
16
|
+
errors: a
|
|
17
|
+
};
|
|
18
|
+
}, i = (e) => {
|
|
19
|
+
let t = new Map(e.map((e) => [e.name, e]));
|
|
20
|
+
return {
|
|
21
|
+
names: [...t.keys()].sort(),
|
|
22
|
+
get: (e) => t.get(e),
|
|
23
|
+
events: e
|
|
24
|
+
};
|
|
25
|
+
}, a = (e, t) => {
|
|
26
|
+
let n = i(e);
|
|
27
|
+
return {
|
|
28
|
+
track: (e, i) => {
|
|
29
|
+
let a = n.get(e);
|
|
30
|
+
if (a === void 0) process.env.NODE_ENV !== "production" && console.error(`[@voltro/client] analytics.track: unknown event '${e}' (not in the catalog)`);
|
|
31
|
+
else {
|
|
32
|
+
if (process.env.NODE_ENV !== "production") {
|
|
33
|
+
let t = r(a, i);
|
|
34
|
+
t.valid || console.error(`[@voltro/client] analytics.track('${e}'): payload failed its schema`, t.errors);
|
|
35
|
+
}
|
|
36
|
+
t({
|
|
37
|
+
event: e,
|
|
38
|
+
...i
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
names: n.names,
|
|
43
|
+
catalog: n
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
//#endregion
|
|
47
|
+
export { a as createAnalytics, n as defineEvent, i as eventCatalog, r as validateEventPayload };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/apiConnectivity.ts
|
|
2
|
+
var e = Symbol.for("voltro.client.connectivity"), t = () => {
|
|
3
|
+
let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Set(), n = () => {
|
|
4
|
+
for (let e of t) try {
|
|
5
|
+
e();
|
|
6
|
+
} catch {}
|
|
7
|
+
};
|
|
8
|
+
return {
|
|
9
|
+
online: (t) => {
|
|
10
|
+
let n = [];
|
|
11
|
+
if (t === void 0) for (let t of e.values()) for (let e of t) n.push(e);
|
|
12
|
+
else for (let r of e.get(t) ?? []) n.push(r);
|
|
13
|
+
if (n.length !== 0) return n.some((e) => e.connected());
|
|
14
|
+
},
|
|
15
|
+
subscribe: (e) => (t.add(e), () => {
|
|
16
|
+
t.delete(e);
|
|
17
|
+
}),
|
|
18
|
+
register: (t, r) => {
|
|
19
|
+
let i = e.get(t) ?? /* @__PURE__ */ new Set();
|
|
20
|
+
return i.add(r), e.set(t, i), n(), () => {
|
|
21
|
+
i.delete(r), i.size === 0 && e.delete(t), n();
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
notify: n
|
|
25
|
+
};
|
|
26
|
+
}, n = () => {
|
|
27
|
+
let n = globalThis;
|
|
28
|
+
return n[e] ??= t();
|
|
29
|
+
}, r = (e, t) => n().register(e, { connected: t }), i = () => {
|
|
30
|
+
n().notify();
|
|
31
|
+
}, a = () => n();
|
|
32
|
+
//#endregion
|
|
33
|
+
export { a as apiConnectivity, i as notifyApiTransportChanged, r as registerApiTransport };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { resolveByTag as e } from "./tagWalk.js";
|
|
2
|
+
import { Context as t, Option as n } from "effect";
|
|
3
|
+
import { RpcGroup as r, RpcSchema as i } from "effect/rpc";
|
|
4
|
+
import { EventRpcWorkload as a, apiRoleEndpointUrl as o, captureApiRoleEndpoints as s, selectApiRoleEndpoint as c } from "@voltro/protocol";
|
|
5
|
+
//#region src/apiRoleTransports.ts
|
|
6
|
+
var l = (e, l, u) => {
|
|
7
|
+
let d = e;
|
|
8
|
+
if (u === void 0) return [{
|
|
9
|
+
name: "default",
|
|
10
|
+
url: l,
|
|
11
|
+
group: d,
|
|
12
|
+
tags: new Set(d.requests.keys())
|
|
13
|
+
}];
|
|
14
|
+
let f = s(u), p = /* @__PURE__ */ new Map();
|
|
15
|
+
for (let e of d.requests.values()) {
|
|
16
|
+
let r = e, s = n.isSome(t.getOption(r.annotations, a)) ? "events" : i.isStreamSchema(r.successSchema) ? "subscriptions" : "rpc", u = c(f, e._tag, s), d = p.get(u.role) ?? {
|
|
17
|
+
url: o(l, u, "websocket"),
|
|
18
|
+
requests: []
|
|
19
|
+
};
|
|
20
|
+
d.requests.push(e), p.set(u.role, d);
|
|
21
|
+
}
|
|
22
|
+
return [...p].map(([e, t]) => ({
|
|
23
|
+
name: e,
|
|
24
|
+
url: t.url,
|
|
25
|
+
group: r.make(...t.requests).annotateMerge(d.annotations),
|
|
26
|
+
tags: new Set(t.requests.map((e) => e._tag))
|
|
27
|
+
}));
|
|
28
|
+
}, u = (t) => {
|
|
29
|
+
let n = Object.create(null);
|
|
30
|
+
for (let r of t) for (let t of r.tags) {
|
|
31
|
+
let i = t.split("."), a = n;
|
|
32
|
+
for (let e of i.slice(0, -1)) {
|
|
33
|
+
Object.hasOwn(a, e) || (a[e] = Object.create(null));
|
|
34
|
+
let t = a[e];
|
|
35
|
+
if (t === null || typeof t != "object" && typeof t != "function") throw Error("Invalid RPC namespace collision");
|
|
36
|
+
a = t;
|
|
37
|
+
}
|
|
38
|
+
let o = i[i.length - 1], s = e(r.client, t), c = (...e) => s(...e);
|
|
39
|
+
if (Object.hasOwn(a, o)) {
|
|
40
|
+
if (typeof a[o] == "function") throw Error("Duplicate routed RPC tag");
|
|
41
|
+
Object.assign(c, a[o]);
|
|
42
|
+
}
|
|
43
|
+
a[o] = c;
|
|
44
|
+
}
|
|
45
|
+
return n;
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
export { u as combineApiRoleClients, l as planApiRoleTransports };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { recordClientDiagnostic as e } from "./clientDiagnostics.js";
|
|
2
|
+
import { SubscriptionCache as t } from "./subscriptionCache.js";
|
|
3
|
+
import { RpcErrorBus as n } from "./rpcErrorBus.js";
|
|
4
|
+
import { makeRecoveryRetry as r } from "./recoveryRetry.js";
|
|
5
|
+
import { recoveryCoordinatorFor as i } from "./recoveryCoordinator.js";
|
|
6
|
+
import { makeClientScheduler as a } from "./clientScheduler.js";
|
|
7
|
+
import { readRuntimeCapabilities as o } from "./runtimeCapabilities.js";
|
|
8
|
+
import { ConnectionScope as s, combineConnectionScopes as c, registerConnectionScope as l } from "./connectionScope.js";
|
|
9
|
+
import { resolveByTag as u } from "./tagWalk.js";
|
|
10
|
+
import { combineApiRoleClients as d, planApiRoleTransports as f } from "./apiRoleTransports.js";
|
|
11
|
+
import { Context as p, Effect as m, Layer as h, ManagedRuntime as g, Result as _, Scheduler as v, Schema as y, Stream as b } from "effect";
|
|
12
|
+
import * as x from "effect/http/Headers";
|
|
13
|
+
import { RpcClient as S, RpcSerialization as C } from "effect/rpc";
|
|
14
|
+
import { compareSurfaces as w, groupShapeDigests as T } from "@voltro/protocol";
|
|
15
|
+
import * as E from "effect/socket/Socket";
|
|
16
|
+
//#region src/apiRuntime.ts
|
|
17
|
+
var D = async (t, n, r, i) => {
|
|
18
|
+
if (r !== void 0) try {
|
|
19
|
+
let a = await r({
|
|
20
|
+
apiName: t,
|
|
21
|
+
descriptors: i
|
|
22
|
+
});
|
|
23
|
+
return e(t, "runtime.mirror", {
|
|
24
|
+
generation: n,
|
|
25
|
+
mirrored: a !== void 0
|
|
26
|
+
}), a;
|
|
27
|
+
} catch (r) {
|
|
28
|
+
e(t, "runtime.mirror", {
|
|
29
|
+
generation: n,
|
|
30
|
+
mirrored: !1,
|
|
31
|
+
errorName: r instanceof Error ? r.name : typeof r
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
}, O = (e, t = new s()) => {
|
|
36
|
+
let n;
|
|
37
|
+
return {
|
|
38
|
+
wrap: (e) => E.Socket.of({
|
|
39
|
+
...e,
|
|
40
|
+
reader: m.gen(function* () {
|
|
41
|
+
let r = t.begin();
|
|
42
|
+
yield* m.addFinalizer(() => m.sync(() => {
|
|
43
|
+
n === r && (n = void 0), r.close();
|
|
44
|
+
}));
|
|
45
|
+
let i = yield* e.reader;
|
|
46
|
+
return n = r, i;
|
|
47
|
+
})
|
|
48
|
+
}),
|
|
49
|
+
hooks: {
|
|
50
|
+
onConnect: m.sync(() => {
|
|
51
|
+
let t = n;
|
|
52
|
+
n = void 0, t?.open() !== void 0 && e();
|
|
53
|
+
}),
|
|
54
|
+
onDisconnect: m.void
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}, k = 3, A = (t, n, r) => {
|
|
58
|
+
let i;
|
|
59
|
+
try {
|
|
60
|
+
i = w(T(n), r);
|
|
61
|
+
} catch {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
let { differing: a, missingHere: o } = i;
|
|
65
|
+
if (a.length === 0 && o.length === 0) return;
|
|
66
|
+
e(t, "runtime.surface-mismatch", {
|
|
67
|
+
differing: a.length,
|
|
68
|
+
missingHere: o.length,
|
|
69
|
+
first: a[0] ?? o[0] ?? null
|
|
70
|
+
});
|
|
71
|
+
let s = [...a, ...o].slice(0, k), c = a.length + o.length - s.length;
|
|
72
|
+
console.warn(`[voltro] the api client this page loaded does not match what the '${t}' server binds: ${s.join(", ")}${c > 0 ? ` and ${c} more` : ""}. Responses for those procedures may decode against the wrong schema — a field the server sends and this client does not know is dropped silently. Reload; if it persists, stop the dev server, delete \`.framework/.vite\`, and start it again.`);
|
|
73
|
+
}, j = async (w) => {
|
|
74
|
+
let { name: T, wsUrl: k, group: j, headers: M, webSocketConstructor: N } = w, P = f(j, k, w.roleEndpoints), F = w.generation ?? 0;
|
|
75
|
+
e(T, "runtime.build-started", { generation: F });
|
|
76
|
+
let I = w.errorBus ?? new n(), L = w.recovery ?? i(I, T), R = L.subjectSignal;
|
|
77
|
+
o(k, T, fetch, 1500, L.options.capabilitiesUrl).then((t) => {
|
|
78
|
+
L.setMutationReplaySupported(t?.mutationReplay === !0, F), e(T, "runtime.capabilities", {
|
|
79
|
+
mutationReplay: t?.mutationReplay === !0,
|
|
80
|
+
discovered: t !== void 0
|
|
81
|
+
});
|
|
82
|
+
let n = w.surfaceAudience === "service" ? t?.serviceSurface : t?.surface;
|
|
83
|
+
n !== void 0 && A(T, j, n);
|
|
84
|
+
});
|
|
85
|
+
let z = w.descriptors ?? {}, B = await D(T, F, w.mirror, z), V = new t({
|
|
86
|
+
errorBus: I,
|
|
87
|
+
apiName: T,
|
|
88
|
+
...B === void 0 ? {} : { mirror: B }
|
|
89
|
+
}), H = P.map(() => new s()), U = c(H), W;
|
|
90
|
+
class G extends p.Service()(`@voltro/client/AppClient/${T}`) {}
|
|
91
|
+
let K = h.succeed(E.WebSocketConstructor, N), q = P.map((e, t) => p.Service(`@voltro/client/Role/${T}/${t}/${e.name}`)), J = P.map((t, n) => {
|
|
92
|
+
let i = r(L.options.retry, (n, r) => {
|
|
93
|
+
e(T, "socket.retry-scheduled", {
|
|
94
|
+
generation: F,
|
|
95
|
+
role: t.name,
|
|
96
|
+
attempt: n,
|
|
97
|
+
delayMs: r,
|
|
98
|
+
owner: "socket"
|
|
99
|
+
});
|
|
100
|
+
}), a = E.layerWebSocket(t.url).pipe(h.provide(K)), o = O(() => {
|
|
101
|
+
i.reset();
|
|
102
|
+
let n = W === void 0 ? 0 : V.resumeTransportFailures(W, w.roleEndpoints === void 0 ? void 0 : (e) => e !== void 0 && t.tags.has(e));
|
|
103
|
+
e(T, "protocol.ready", {
|
|
104
|
+
generation: F,
|
|
105
|
+
role: t.name,
|
|
106
|
+
resumed: n
|
|
107
|
+
}), U.scope.getSnapshot() !== void 0 && L.protocolReady();
|
|
108
|
+
}, H[n]), s = h.effect(E.Socket, m.map(E.Socket, o.wrap)).pipe(h.provide(a)), c = h.effect(S.Protocol, S.makeProtocolSocket({ retryPolicy: i.schedule })).pipe(h.provide(C.layerJson), h.provide(s), h.provide(h.succeed(S.ConnectionHooks, o.hooks)));
|
|
109
|
+
return h.effect(q[n], S.make(t.group)).pipe(h.provide(c));
|
|
110
|
+
}), Y = typeof M == "function" ? await M() : M, X = J.reduce((e, t) => h.merge(e, t), h.empty), Z = h.effect(G, m.map(m.all(q.map((e) => e)), (e) => d(e.map((e, t) => ({
|
|
111
|
+
client: e,
|
|
112
|
+
tags: P[t].tags
|
|
113
|
+
}))))).pipe(h.provide(X)), ee = h.effectDiscard(m.acquireRelease(m.void, () => m.sync(U.close))), te = Y ? h.succeed(S.CurrentHeaders, x.fromInput(Y)) : h.empty, Q = a(), $ = g.make(h.mergeAll(Z, te, ee).pipe(h.provideMerge(h.succeed(v.Scheduler, Q))));
|
|
114
|
+
W = $, l(W, U.scope);
|
|
115
|
+
try {
|
|
116
|
+
let t = await $.runPromise(G);
|
|
117
|
+
e(T, "runtime.resolved", {
|
|
118
|
+
generation: F,
|
|
119
|
+
scheduler: Q.yieldChannel
|
|
120
|
+
});
|
|
121
|
+
let n = (B?.warmTags ?? []).filter((e) => {
|
|
122
|
+
let t = z[e]?.input;
|
|
123
|
+
return t !== void 0 && _.isSuccess(y.decodeUnknownResult(t)({}));
|
|
124
|
+
}).map((e) => [e, {}]);
|
|
125
|
+
for (let [e, r] of [...B?.warm ?? [], ...n]) {
|
|
126
|
+
let n = z[e]?.source;
|
|
127
|
+
V.subscribe([e, r], () => b.suspend(() => u(t, e)(r)), $, () => {}, n === void 0 ? {} : { source: n });
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
runtime: $,
|
|
131
|
+
client: t,
|
|
132
|
+
cache: V,
|
|
133
|
+
errorBus: I,
|
|
134
|
+
recovery: L,
|
|
135
|
+
subjectSignal: R
|
|
136
|
+
};
|
|
137
|
+
} catch (t) {
|
|
138
|
+
throw e(T, "runtime.failed", {
|
|
139
|
+
generation: F,
|
|
140
|
+
errorName: t instanceof Error ? t.name : typeof t
|
|
141
|
+
}), await $.dispose(), U.close(), t;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
//#endregion
|
|
145
|
+
export { j as buildApiRuntime, O as makeProtocolOpenRecovery };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { planApiRoleTransports as e } from "./apiRoleTransports.js";
|
|
2
|
+
//#region src/apiSocketTracker.ts
|
|
3
|
+
var t = (e, t, n) => {
|
|
4
|
+
let r = new Map(e.map((e) => [e, { open: !1 }])), i = !1;
|
|
5
|
+
return { begin: (e) => {
|
|
6
|
+
if (!r.has(e)) throw Error("Unexpected API role socket endpoint");
|
|
7
|
+
let a = { open: !1 };
|
|
8
|
+
r.set(e, a), i && (i = !1, n("close"));
|
|
9
|
+
let o = !1;
|
|
10
|
+
return {
|
|
11
|
+
open: () => {
|
|
12
|
+
o || r.get(e) !== a || a.open || (a.open = !0, !i && [...r.values()].every((e) => e.open) && (i = !0, t()));
|
|
13
|
+
},
|
|
14
|
+
issue: (t) => {
|
|
15
|
+
o || r.get(e) !== a || (o = !0, a.open = !1, i = !1, n(t));
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
} };
|
|
19
|
+
}, n = (n, r, i, a, o) => t(e(n, r, i).map((e) => e.url), a, o);
|
|
20
|
+
//#endregion
|
|
21
|
+
export { n as makeApiRoleSocketTracker, t as makeApiSocketTracker };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { recordClientDiagnostic as e } from "./clientDiagnostics.js";
|
|
2
|
+
import { RpcErrorBus as t } from "./rpcErrorBus.js";
|
|
3
|
+
import { recoveryRetryDelay as n } from "./recoveryRetry.js";
|
|
4
|
+
import { RecoveryCoordinator as r } from "./recoveryCoordinator.js";
|
|
5
|
+
//#region src/apiSupervisor.ts
|
|
6
|
+
var i = (e, t, n) => ({
|
|
7
|
+
resolved: null,
|
|
8
|
+
retryToken: 0,
|
|
9
|
+
failureCount: 0,
|
|
10
|
+
generation: 0,
|
|
11
|
+
reconnectStatusDispose: null,
|
|
12
|
+
everOpened: !1,
|
|
13
|
+
wedgeStop: null,
|
|
14
|
+
subjectMayHaveChanged: !1,
|
|
15
|
+
swapWaiters: [],
|
|
16
|
+
errorBus: e,
|
|
17
|
+
recovery: t,
|
|
18
|
+
stopRecoveryError: e.on((e) => t.observeError(e)),
|
|
19
|
+
stopRecoverySuccess: e.onSuccess((e) => t.observeSuccess(e)),
|
|
20
|
+
ownsRecovery: n
|
|
21
|
+
}), a = (e) => {
|
|
22
|
+
e.wedgeStop !== null && (e.wedgeStop(), e.wedgeStop = null);
|
|
23
|
+
}, o = (e) => {
|
|
24
|
+
e.cache.destroy(e.runtime), e.runtime.dispose();
|
|
25
|
+
}, s = (s) => {
|
|
26
|
+
let c = s.apis, l = s.buildClient, u = s.onChange, d = s.stableWindowMs ?? 5e3, f = s.scheduler?.setTimeout ?? ((e, t) => setTimeout(e, t)), p = s.scheduler?.clearTimeout ?? ((e) => {
|
|
27
|
+
clearTimeout(e);
|
|
28
|
+
}), m = s.scheduler?.queueMicrotask ?? queueMicrotask, h = s.onReconnecting, g = s.wedgeBackstop, _ = /* @__PURE__ */ new Map();
|
|
29
|
+
for (let e of c) {
|
|
30
|
+
let n = s.errorBusFor?.(e.name) ?? new t(), a = s.recoveryFor?.(e.name, e.recovery), o = a ?? new r(e.name, e.recovery);
|
|
31
|
+
_.set(e.name, i(n, o, a === void 0));
|
|
32
|
+
}
|
|
33
|
+
let v = !1, y = /* @__PURE__ */ new Set(), b = (e, t) => {
|
|
34
|
+
let n = f(() => {
|
|
35
|
+
y.delete(n), e();
|
|
36
|
+
}, t);
|
|
37
|
+
return y.add(n), n;
|
|
38
|
+
}, x = () => {
|
|
39
|
+
if (v) return;
|
|
40
|
+
let e = /* @__PURE__ */ new Map();
|
|
41
|
+
for (let [t, n] of _) n.resolved && e.set(t, n.resolved);
|
|
42
|
+
u(e, c.every((t) => e.has(t.name)));
|
|
43
|
+
}, S = (e, t) => {
|
|
44
|
+
t.failureCount += 1, !t.reconnectStatusDispose && h && (t.reconnectStatusDispose = h(e.name)), g && t.everOpened && t.failureCount >= g.afterFailures && t.wedgeStop === null && (t.wedgeStop = g.arm(e.name));
|
|
45
|
+
}, C = (t) => {
|
|
46
|
+
if (v) return;
|
|
47
|
+
let r = _.get(t.name);
|
|
48
|
+
if (!r) return;
|
|
49
|
+
S(t, r);
|
|
50
|
+
let i = s.retryDelayMs?.(r.failureCount) ?? n(r.recovery.options.retry, r.failureCount);
|
|
51
|
+
e(t.name, "socket.retry-scheduled", {
|
|
52
|
+
generation: r.generation,
|
|
53
|
+
attempt: r.failureCount,
|
|
54
|
+
delayMs: i,
|
|
55
|
+
owner: "runtime-build"
|
|
56
|
+
});
|
|
57
|
+
let a = ++r.retryToken;
|
|
58
|
+
b(() => {
|
|
59
|
+
v || r.retryToken === a && (r.generation += 1, w(t));
|
|
60
|
+
}, i);
|
|
61
|
+
}, w = async (t) => {
|
|
62
|
+
if (v) return;
|
|
63
|
+
let n = _.get(t.name);
|
|
64
|
+
if (!n) return;
|
|
65
|
+
let r = n.generation, i = () => {
|
|
66
|
+
if (v || n.generation !== r) return;
|
|
67
|
+
n.everOpened = !0, a(n), n.reconnectStatusDispose &&= (n.reconnectStatusDispose(), null), n.retryToken++;
|
|
68
|
+
let e = n.failureCount;
|
|
69
|
+
b(() => {
|
|
70
|
+
v || n.failureCount === e && (n.failureCount = 0);
|
|
71
|
+
}, d);
|
|
72
|
+
}, s = (e) => {
|
|
73
|
+
v || n.generation !== r || (n.recovery.transportIssue(), S(t, n));
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
let a = await l(t, r, i, s, n.errorBus, n.recovery);
|
|
77
|
+
if (v || n.generation !== r) {
|
|
78
|
+
o(a);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
let c = n.resolved, u = n.subjectMayHaveChanged, d = c && !u ? a.cache.seedStaleFrom(c.cache) : 0;
|
|
82
|
+
n.subjectMayHaveChanged = !1, n.resolved = a, e(t.name, "runtime.swapped", {
|
|
83
|
+
generation: r,
|
|
84
|
+
replaced: c !== null,
|
|
85
|
+
seeded: d,
|
|
86
|
+
subjectMayHaveChanged: u
|
|
87
|
+
}), x(), c && o(c);
|
|
88
|
+
let f = n.swapWaiters.filter((e) => e.generation <= r);
|
|
89
|
+
n.swapWaiters = n.swapWaiters.filter((e) => e.generation > r);
|
|
90
|
+
for (let e of f) e.resolve();
|
|
91
|
+
} catch {
|
|
92
|
+
if (v || n.generation !== r) return;
|
|
93
|
+
C(t);
|
|
94
|
+
}
|
|
95
|
+
}, T = (e) => {
|
|
96
|
+
if (!v) for (let t of c) {
|
|
97
|
+
let n = _.get(t.name);
|
|
98
|
+
n && (e && (n.subjectMayHaveChanged = !0), n.retryToken += 1, n.generation += 1, e && n.recovery.resetForSubjectChange(n.generation), n.failureCount = 0, a(n), w(t));
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
return c.length === 0 ? (u(/* @__PURE__ */ new Map(), !0), {
|
|
102
|
+
dispose: () => {
|
|
103
|
+
v = !0;
|
|
104
|
+
},
|
|
105
|
+
reconnect: () => Promise.resolve(),
|
|
106
|
+
refreshAuth: () => {}
|
|
107
|
+
}) : (m(() => {
|
|
108
|
+
if (!v) for (let e of c) w(e);
|
|
109
|
+
}), {
|
|
110
|
+
dispose: () => {
|
|
111
|
+
if (!v) {
|
|
112
|
+
v = !0;
|
|
113
|
+
for (let e of y) p(e);
|
|
114
|
+
y.clear();
|
|
115
|
+
for (let [, e] of _) {
|
|
116
|
+
e.resolved && o(e.resolved), e.reconnectStatusDispose && e.reconnectStatusDispose(), a(e), e.stopRecoveryError(), e.stopRecoverySuccess(), e.ownsRecovery && e.recovery.dispose();
|
|
117
|
+
for (let t of e.swapWaiters) t.resolve();
|
|
118
|
+
e.swapWaiters = [];
|
|
119
|
+
}
|
|
120
|
+
for (let t of c) e(t.name, "runtime.disposed");
|
|
121
|
+
_.clear();
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
reconnect: () => v ? Promise.resolve() : (T(!0), Promise.all([..._.values()].map((e) => new Promise((t) => {
|
|
125
|
+
e.swapWaiters.push({
|
|
126
|
+
generation: e.generation,
|
|
127
|
+
resolve: t
|
|
128
|
+
});
|
|
129
|
+
}))).then(() => void 0)),
|
|
130
|
+
refreshAuth: () => {
|
|
131
|
+
T(!1);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
//#endregion
|
|
136
|
+
export { s as startApiSupervisor };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/authRefresh.ts
|
|
2
|
+
var e = (e) => e?._tag === "Unauthenticated", t = (t, n, r = {}) => {
|
|
3
|
+
let i = r.cooldownMs ?? 15e3, a = r.maxConsecutive ?? 3, o = r.now ?? (() => Date.now()), s = -Infinity, c = 0, l = t.on((t) => {
|
|
4
|
+
if (!e(t.error) || c >= a) return;
|
|
5
|
+
let r = o();
|
|
6
|
+
r - s < i || (s = r, c += 1, n());
|
|
7
|
+
}), u = t.onSuccess(() => {
|
|
8
|
+
c = 0;
|
|
9
|
+
});
|
|
10
|
+
return {
|
|
11
|
+
dispose: () => {
|
|
12
|
+
l(), u();
|
|
13
|
+
},
|
|
14
|
+
noteSuccess: () => {
|
|
15
|
+
c = 0;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { e as isUnauthenticated, t as wireAuthRefresh };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isUnresolvedApi as e } from "./frameworkRuntimesContext.js";
|
|
2
|
+
import { ConnectionPrerequisiteInvalidated as t } from "./connectionPrerequisite.js";
|
|
3
|
+
//#region src/awaitResolvedApi.ts
|
|
4
|
+
var n = 15e3, r = async (t, r, i, a) => {
|
|
5
|
+
if (a?.throwIfAborted(), !e(t.current)) return t.current;
|
|
6
|
+
let o = Date.now() + n;
|
|
7
|
+
for (; Date.now() < o;) if (await new Promise((e) => setTimeout(e, 16)), a?.throwIfAborted(), !e(t.current)) return t.current;
|
|
8
|
+
throw Error(`Voltro: the api "${r}" did not resolve within ${n}ms, so ${i} was never sent. This is not the boot window — that is waited out. Check that "${r}" is a configured api name and that its client could connect.`);
|
|
9
|
+
}, i = async (n, i, a) => {
|
|
10
|
+
let o = e(n.current) ? void 0 : n.current.recovery, s = o?.subjectSignal, c = await r(n, i, a), l = c.recovery;
|
|
11
|
+
if (s?.aborted || o !== void 0 && l !== o) throw new t("inactive");
|
|
12
|
+
if (l === void 0) return c;
|
|
13
|
+
let u = s ?? l.subjectSignal, d = Date.now();
|
|
14
|
+
for (;;) {
|
|
15
|
+
let e = await l.waitForProtocolReady(d, u);
|
|
16
|
+
if (u.aborted || l.subjectSignal !== u) throw new t("inactive");
|
|
17
|
+
if (!e) throw new t("timeout");
|
|
18
|
+
if (c = await r(n, i, a), u.aborted || c.recovery !== l) throw new t("inactive");
|
|
19
|
+
if (l.getSnapshot().rawTransport === "connected") return c;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { n as RESOLVE_TIMEOUT_MS, i as awaitReadyApi, r as awaitResolvedApi };
|