@voltro/client 0.84.0 → 0.86.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 +1215 -0
- package/THIRD-PARTY-NOTICES.md +5 -89
- package/dist/analyticsCatalog.js +47 -0
- package/dist/apiConnectivity.js +33 -0
- package/dist/apiRuntime.js +135 -0
- package/dist/apiSupervisor.js +125 -0
- package/dist/authRefresh.js +20 -0
- package/dist/awaitResolvedApi.js +23 -0
- package/dist/bootstrap.d.ts +1144 -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 +35 -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 +8 -11
- package/dist/form.js +5 -2
- package/dist/formBinding.js +325 -0
- package/dist/formData.js +65 -0
- package/dist/formFlashId.js +4 -0
- package/dist/frameworkRuntimesContext.js +8 -0
- package/dist/globalContext.js +10 -0
- package/dist/index.d.ts +285 -279
- package/dist/index.js +83 -3686
- 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 +79 -15
- package/dist/runtime.js +16 -129
- 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 +24 -0
- package/dist/serviceClient.js +128 -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 +101 -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 +88 -0
- package/dist/useFormBinding.js +476 -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/useSequence.js +25 -0
- package/dist/useSkeleton.js +13 -0
- package/dist/useSubscription.js +89 -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 +8 -5
- package/dist/authRefresh-C4Ow8HH7.js +0 -346
- package/dist/formData-dGz5aoUR.js +0 -649
- package/dist/queryOnce-CvdopzOj.js +0 -55
- package/dist/runRpc-DvHpFZAZ.js +0 -1034
package/dist/runtime.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { ClientDescriptor } from '@voltro/protocol';
|
|
2
|
+
import { createRowPatchApplier } from '@voltro/protocol';
|
|
2
3
|
import { Effect } from 'effect';
|
|
3
4
|
import { Fiber } from 'effect';
|
|
4
5
|
import { ManagedRuntime } from 'effect';
|
|
5
|
-
import { Rpc } from '
|
|
6
|
-
import { RpcClient } from '
|
|
7
|
-
import { RpcClientError } from '
|
|
8
|
-
import { RpcGroup } from '
|
|
6
|
+
import { Rpc } from 'effect/rpc';
|
|
7
|
+
import { RpcClient } from 'effect/rpc';
|
|
8
|
+
import { RpcClientError } from 'effect/rpc';
|
|
9
|
+
import { RpcGroup } from 'effect/rpc';
|
|
9
10
|
import { ServiceApi } from '@voltro/protocol';
|
|
10
11
|
import { ServiceCallOptions } from '@voltro/protocol';
|
|
11
12
|
import { ServiceSubscribeHandlers } from '@voltro/protocol';
|
|
12
13
|
import { ServiceSubscription } from '@voltro/protocol';
|
|
13
|
-
import * as Socket from '
|
|
14
|
+
import * as Socket from 'effect/socket/Socket';
|
|
14
15
|
import { Stream } from 'effect';
|
|
15
16
|
import { SubscriptionEvent } from '@voltro/protocol';
|
|
16
17
|
import { TargetRelations } from '@voltro/protocol';
|
|
@@ -152,7 +153,7 @@ export declare interface BuildApiRuntimeOptions {
|
|
|
152
153
|
/**
|
|
153
154
|
* The api's rpc group, as the ERASED `RpcGroup.Any`.
|
|
154
155
|
*
|
|
155
|
-
* `RpcGroup` is declared `in out` in
|
|
156
|
+
* `RpcGroup` is declared `in out` in effect/rpc — invariant on purpose — so a
|
|
156
157
|
* CONCRETE group (the `appGroup` codegen emits) is not assignable to
|
|
157
158
|
* `RpcGroup<Rpc.Any>`, and a boundary typed that way rejects the only value
|
|
158
159
|
* anyone ever passes it. This mirrors what `ApiHandle.client` already does:
|
|
@@ -166,7 +167,7 @@ export declare interface BuildApiRuntimeOptions {
|
|
|
166
167
|
/** How to construct a WebSocket. Web wraps `globalThis.WebSocket` with
|
|
167
168
|
* tracking + a connect-timeout; RN passes a plain `globalThis.WebSocket`.
|
|
168
169
|
* Injected so this module touches no environment global directly. */
|
|
169
|
-
readonly webSocketConstructor: (url: string,
|
|
170
|
+
readonly webSocketConstructor: (url: string, options?: Socket.WebSocketConstructorOptions) => globalThis.WebSocket;
|
|
170
171
|
/**
|
|
171
172
|
* Error channel owned by the logical api mount. A reconnect supervisor passes
|
|
172
173
|
* the SAME instance to every transport generation so a failure emitted by the
|
|
@@ -210,6 +211,7 @@ export declare interface BuiltApiRuntime {
|
|
|
210
211
|
}
|
|
211
212
|
|
|
212
213
|
declare interface CacheEntry {
|
|
214
|
+
rowPatchApplier?: ReturnType<typeof createRowPatchApplier>;
|
|
213
215
|
readonly key: string;
|
|
214
216
|
/** First element of the keyArr — the rpc tag (e.g. 'todos.list'). Used
|
|
215
217
|
* by `forTag()` so callers can patch every sub-key for a tag without
|
|
@@ -227,7 +229,7 @@ declare interface CacheEntry {
|
|
|
227
229
|
/** Subscriber re-render callbacks. */
|
|
228
230
|
subscribers: Set<() => void>;
|
|
229
231
|
/** Fiber running the underlying stream. */
|
|
230
|
-
fiber: Fiber.
|
|
232
|
+
fiber: Fiber.Fiber<unknown, unknown> | null;
|
|
231
233
|
/** The last fiber ended because the rpc transport failed. A later socket
|
|
232
234
|
* `open` re-issues active entries with their last-known-good base intact. */
|
|
233
235
|
resumeAfterTransportOpen: boolean;
|
|
@@ -442,6 +444,15 @@ declare interface EntryState<T> {
|
|
|
442
444
|
/** Cached optimistic snapshot — invalidated on every state change so
|
|
443
445
|
* `getSnapshot` returns a stable reference between mutations. */
|
|
444
446
|
cachedSnapshot: CacheSnapshot<T> | null;
|
|
447
|
+
previewPrefix?: {
|
|
448
|
+
readonly base: T;
|
|
449
|
+
readonly count: number;
|
|
450
|
+
readonly data: T;
|
|
451
|
+
};
|
|
452
|
+
previewBase?: {
|
|
453
|
+
readonly base: T;
|
|
454
|
+
readonly eligible: boolean;
|
|
455
|
+
};
|
|
445
456
|
}
|
|
446
457
|
|
|
447
458
|
export declare interface FrameworkRuntimes {
|
|
@@ -469,6 +480,22 @@ export declare interface FrameworkRuntimes {
|
|
|
469
480
|
* keeps working; absent means "already connected", which is the safe reading.
|
|
470
481
|
*/
|
|
471
482
|
readonly demand?: (apiName: string) => void;
|
|
483
|
+
/**
|
|
484
|
+
* One read through an api's client — the browser half of a loader's
|
|
485
|
+
* `ctx.query`. Supplied by the host that builds the rpc runtime
|
|
486
|
+
* (`VoltroRuntimeProvider`), not by this context: the read reaches the rpc
|
|
487
|
+
* client and with it the Effect runtime, and an app that mounts no api must
|
|
488
|
+
* not load either just because its router can ask. Absent → `ctx.query` is
|
|
489
|
+
* `undefined` in the browser, as it is for an app without apis.
|
|
490
|
+
*/
|
|
491
|
+
readonly queryOnce?: QueryOnce;
|
|
492
|
+
/**
|
|
493
|
+
* Resolves once the rpc runtime behind these apis is loaded. A host that
|
|
494
|
+
* loads it on demand (the web boot keeps it out of an app's first load and
|
|
495
|
+
* fetches it with the first route that reads data) supplies it; absent means
|
|
496
|
+
* the runtime is already there.
|
|
497
|
+
*/
|
|
498
|
+
readonly ready?: () => Promise<void>;
|
|
472
499
|
}
|
|
473
500
|
|
|
474
501
|
/**
|
|
@@ -518,6 +545,8 @@ export declare class LoadingSubscriptionCache extends SubscriptionCache {
|
|
|
518
545
|
};
|
|
519
546
|
}
|
|
520
547
|
|
|
548
|
+
/* Excluded from this release type: makeProtocolOpenRecovery */
|
|
549
|
+
|
|
521
550
|
export declare const makeServiceClient: (options: ServiceClientOptions) => ServiceClient;
|
|
522
551
|
|
|
523
552
|
/**
|
|
@@ -559,6 +588,8 @@ declare interface OptimisticPatch<T = unknown> {
|
|
|
559
588
|
/** A successful write stays previewed until a matching post-ACK primary
|
|
560
589
|
* snapshot supersedes it. A different write's delta proves nothing. */
|
|
561
590
|
confirmed?: boolean;
|
|
591
|
+
/** Only framework-owned reducers with an unchanged input can reuse a prefix. */
|
|
592
|
+
readonly canReuse?: (() => boolean) | undefined;
|
|
562
593
|
}
|
|
563
594
|
|
|
564
595
|
/** Publish a client error. Cheap + sync; a broken listener can't break the caller. */
|
|
@@ -567,6 +598,14 @@ export declare const publishClientError: (event: ClientErrorEvent) => void;
|
|
|
567
598
|
/** Publish a started client trace. Cheap + sync; safe on the hot path. */
|
|
568
599
|
export declare const publishClientTrace: (event: ClientTraceEvent) => void;
|
|
569
600
|
|
|
601
|
+
/** `queryOnce`'s shape, declared here so this module stays free of it. */
|
|
602
|
+
declare type QueryOnce = (handleRef: {
|
|
603
|
+
readonly current: {
|
|
604
|
+
readonly runtime: unknown;
|
|
605
|
+
readonly client: unknown;
|
|
606
|
+
};
|
|
607
|
+
}, apiName: string, tag: string, input: Record<string, unknown> | undefined, signal?: AbortSignal) => Promise<unknown>;
|
|
608
|
+
|
|
570
609
|
export declare type RawTransportStatus = 'connected' | 'disconnected';
|
|
571
610
|
|
|
572
611
|
/** Record one payload-free transition. Safe to call on every production path. */
|
|
@@ -587,6 +626,13 @@ export declare class RecoveryCoordinator {
|
|
|
587
626
|
get options(): ResolvedRecoveryOptions;
|
|
588
627
|
/** Ends on login/logout, tenant change or API disposal, not ordinary reconnect. */
|
|
589
628
|
get subjectSignal(): AbortSignal;
|
|
629
|
+
/** Hydration values belong to the initial subject only. Once identity may
|
|
630
|
+
* have changed, a later generation/remount must obtain its own snapshot.
|
|
631
|
+
* Ordinary transport recovery does not cross this boundary. */
|
|
632
|
+
getPreloadSeedPermission: () => boolean;
|
|
633
|
+
/** A whole-cache resnapshot can follow same-socket re-authentication. Its
|
|
634
|
+
* replacement reads must not reuse the original server-rendered values. */
|
|
635
|
+
invalidatePreloadSeeds(): void;
|
|
590
636
|
getSnapshot: () => RecoverySnapshot;
|
|
591
637
|
/** The SSR / hydration snapshot — see INITIAL_RECOVERY_SNAPSHOT. Stable by
|
|
592
638
|
* reference, so both renders agree and React swaps to the live one after. */
|
|
@@ -618,7 +664,7 @@ export declare class RecoveryCoordinator {
|
|
|
618
664
|
* Disabled is final for the current generation and refuses immediately.
|
|
619
665
|
*/
|
|
620
666
|
reserveMutationReplay(startedAt: number): MutationReplayReservation | undefined;
|
|
621
|
-
waitForProtocolReady(startedAt: number): Promise<boolean>;
|
|
667
|
+
waitForProtocolReady(startedAt: number, signal?: AbortSignal): Promise<boolean>;
|
|
622
668
|
dispose(): void;
|
|
623
669
|
}
|
|
624
670
|
|
|
@@ -733,7 +779,7 @@ export declare interface RpcError {
|
|
|
733
779
|
* server may have committed before the response disappeared. */
|
|
734
780
|
readonly outcome?: RpcCallOutcome;
|
|
735
781
|
/** Trace id of the CLIENT call span. When the server accepted the request,
|
|
736
|
-
*
|
|
782
|
+
* effect/rpc propagates this same id into its span. A transport failure may
|
|
737
783
|
* happen before that, so the id is not proof that server logs exist. Present
|
|
738
784
|
* only when a client span was active. */
|
|
739
785
|
readonly traceId?: string;
|
|
@@ -786,7 +832,7 @@ export declare type RpcErrorKind = 'transport' | 'handler' | 'client' | 'unknown
|
|
|
786
832
|
/**
|
|
787
833
|
* Classify an error whose pipeline location is already known.
|
|
788
834
|
*
|
|
789
|
-
* `RpcClientError` is
|
|
835
|
+
* `RpcClientError` is effect/rpc's transport failure value. Detect it through
|
|
790
836
|
* its global TypeId instead of `instanceof`: a browser bundle can contain more
|
|
791
837
|
* than one physical package copy, while the `Symbol.for` marker remains stable.
|
|
792
838
|
* Everything else keeps the caller's evidence-based fallback — this helper
|
|
@@ -810,7 +856,7 @@ export declare type RpcSuccessListener = (event: RpcSuccess) => void;
|
|
|
810
856
|
/**
|
|
811
857
|
* Run an rpc effect on an api's runtime and resolve it to a promise that
|
|
812
858
|
* rejects with the FAILURE VALUE ITSELF — the typed error the server declared
|
|
813
|
-
* —
|
|
859
|
+
* — reduced by the same rule the read path applies to a failed subscription.
|
|
814
860
|
*
|
|
815
861
|
* Every write-side hook (`useMutation`, `useAction`, `useWorkflow`,
|
|
816
862
|
* `useUpload`) goes through here, so `err._tag` means the same thing on both
|
|
@@ -869,7 +915,7 @@ export declare interface ServiceClientOptions {
|
|
|
869
915
|
}>>;
|
|
870
916
|
/** How to open a socket. Defaults to the platform's global `WebSocket`
|
|
871
917
|
* (Node 22+ has one). */
|
|
872
|
-
readonly webSocketConstructor?: (url: string,
|
|
918
|
+
readonly webSocketConstructor?: (url: string, options?: Socket.WebSocketConstructorOptions) => globalThis.WebSocket;
|
|
873
919
|
/** Default deadline for every call. */
|
|
874
920
|
readonly defaultTimeoutMs?: number;
|
|
875
921
|
/**
|
|
@@ -914,10 +960,18 @@ export declare const subscribeClientTraces: (listener: ClientTraceListener) => (
|
|
|
914
960
|
|
|
915
961
|
export declare class SubscriptionCache {
|
|
916
962
|
private readonly entries;
|
|
963
|
+
private readonly entriesByTable;
|
|
964
|
+
private readonly entriesByTag;
|
|
965
|
+
private readonly entriesByMutation;
|
|
966
|
+
private readonly patchMemberships;
|
|
967
|
+
private readonly entryOrder;
|
|
968
|
+
private orderedMemberships;
|
|
969
|
+
private nextEntryOrder;
|
|
917
970
|
/** Standing optimistic intents, by mutation id — see `autoApply`. */
|
|
918
971
|
private readonly intents;
|
|
919
972
|
private readonly tableRows;
|
|
920
973
|
private readonly anyListeners;
|
|
974
|
+
private readonly tableListeners;
|
|
921
975
|
private readonly refreshing;
|
|
922
976
|
/**
|
|
923
977
|
* Same-subject runtime replacement. A mutation may settle against the cache
|
|
@@ -1173,6 +1227,16 @@ export declare class SubscriptionCache {
|
|
|
1173
1227
|
private createStub;
|
|
1174
1228
|
private freshState;
|
|
1175
1229
|
private startFiber;
|
|
1230
|
+
private sourceTables;
|
|
1231
|
+
private addIndex;
|
|
1232
|
+
private removeIndex;
|
|
1233
|
+
private orderedEntries;
|
|
1234
|
+
private indexSource;
|
|
1235
|
+
private appendPatch;
|
|
1236
|
+
private replacePatches;
|
|
1237
|
+
private indexPatches;
|
|
1238
|
+
private registerEntry;
|
|
1239
|
+
private unindexEntry;
|
|
1176
1240
|
private invalidate;
|
|
1177
1241
|
/**
|
|
1178
1242
|
* Every row of `table` this cache holds — the client's local replica of the
|
|
@@ -1183,6 +1247,8 @@ export declare class SubscriptionCache {
|
|
|
1183
1247
|
* for `useSyncExternalStore`.
|
|
1184
1248
|
*/
|
|
1185
1249
|
rowsOf(table: string): ReadonlyArray<Readonly<Record<string, unknown>>>;
|
|
1250
|
+
/** Subscribe to cache changes affecting this source table only. */
|
|
1251
|
+
subscribeTable(table: string, listener: () => void): () => void;
|
|
1186
1252
|
/** Call `listener` after any entry changed. Returns the unsubscribe. */
|
|
1187
1253
|
subscribeAny(listener: () => void): () => void;
|
|
1188
1254
|
private getSnapshot;
|
|
@@ -1369,6 +1435,4 @@ export declare interface SupervisorOptions {
|
|
|
1369
1435
|
*/
|
|
1370
1436
|
export declare const wireAuthRefresh: (bus: RpcErrorBus, refreshAuth: () => void, options?: AuthRefreshOptions) => AuthRefreshHandle;
|
|
1371
1437
|
|
|
1372
|
-
/* Excluded from this release type: withProtocolOpenRecovery */
|
|
1373
|
-
|
|
1374
1438
|
export { }
|
package/dist/runtime.js
CHANGED
|
@@ -1,129 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
message: "client closed"
|
|
18
|
-
}));
|
|
19
|
-
if (n !== void 0) return n;
|
|
20
|
-
let t = typeof e.wsUrl == "function" ? e.wsUrl() : e.wsUrl, r = e.webSocketConstructor ?? ((e, t) => new globalThis.WebSocket(e, t));
|
|
21
|
-
return n = D({
|
|
22
|
-
name: `service:${e.name}`,
|
|
23
|
-
wsUrl: t,
|
|
24
|
-
group: e.group,
|
|
25
|
-
headers: async () => ({ authorization: `Bearer ${e.token()}` }),
|
|
26
|
-
webSocketConstructor: r,
|
|
27
|
-
surfaceAudience: "service"
|
|
28
|
-
}).then((e) => (i = e, e), (e) => {
|
|
29
|
-
throw n = void 0, e;
|
|
30
|
-
}), n;
|
|
31
|
-
}, s = (t, n, r) => new z({
|
|
32
|
-
api: e.name,
|
|
33
|
-
tag: t,
|
|
34
|
-
reason: n,
|
|
35
|
-
message: r
|
|
36
|
-
}), c = (t) => {
|
|
37
|
-
let n = e.callHeaders?.() ?? {};
|
|
38
|
-
return t.pipe(M.locallyWith(R.currentHeaders, (t) => {
|
|
39
|
-
let r = L.set(t, "authorization", `Bearer ${e.token()}`);
|
|
40
|
-
for (let [e, t] of Object.entries(n)) r = L.set(r, e, t);
|
|
41
|
-
return r;
|
|
42
|
-
}));
|
|
43
|
-
}, l = (e) => e.pipe(I.filter((e) => e._tag === "snapshot" || e._tag === "error"), I.runHead, M.flatMap((e) => {
|
|
44
|
-
if (P.isNone(e)) return M.fail(/* @__PURE__ */ Error("the query stream ended before its first snapshot"));
|
|
45
|
-
let t = e.value;
|
|
46
|
-
return t._tag === "error" ? M.fail(t.error) : M.succeed(t.data);
|
|
47
|
-
})), u = (n, r, i) => {
|
|
48
|
-
let u = U(e, n), d = i?.timeoutMs ?? t, f = Date.now(), p = (t) => {
|
|
49
|
-
e.onCall?.({
|
|
50
|
-
api: e.name,
|
|
51
|
-
tag: n,
|
|
52
|
-
durationMs: Date.now() - f,
|
|
53
|
-
outcome: t
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
if (u === void 0) return M.die(/* @__PURE__ */ Error(`apis.${e.name}: '${n}' is not a service procedure of this api — is the caller built against an older contract?`));
|
|
57
|
-
let m = M.gen(function* () {
|
|
58
|
-
let t = yield* M.tryPromise({
|
|
59
|
-
try: () => o(),
|
|
60
|
-
catch: (e) => s(n, a ? "closed" : "transport", `could not build the connection: ${String(e)}`)
|
|
61
|
-
}), d = h(t.client, n);
|
|
62
|
-
if (u === "query") {
|
|
63
|
-
let e = d(r);
|
|
64
|
-
return yield* c(l(e));
|
|
65
|
-
}
|
|
66
|
-
let f = i?.idempotencyKey === void 0 && e.ambientIdempotencyKey !== void 0 ? yield* e.ambientIdempotencyKey(n, r) : void 0, p = i?.idempotencyKey ?? f ?? O();
|
|
67
|
-
return yield* c(T(d(r), p)).pipe(M.tapError((e) => M.sync(() => {
|
|
68
|
-
V(e) && (g = !0);
|
|
69
|
-
})), M.retry({
|
|
70
|
-
while: V,
|
|
71
|
-
schedule: F.spaced(j.millis(B))
|
|
72
|
-
}));
|
|
73
|
-
}), g = !1;
|
|
74
|
-
return m.pipe(M.timeoutFail({
|
|
75
|
-
duration: j.millis(d),
|
|
76
|
-
onTimeout: () => s(n, "timeout", g ? `no answer within ${d} ms — an earlier send with this idempotency key is still in flight on the callee` : `no answer within ${d} ms`)
|
|
77
|
-
}), M.mapError((e) => e?._tag === "RpcClientError" ? s(n, "transport", String(e.message ?? e)) : e), M.tapBoth({
|
|
78
|
-
onFailure: (e) => M.sync(() => p(e?._tag === "ApiUnavailable" ? "unavailable" : "error")),
|
|
79
|
-
onSuccess: () => M.sync(() => p("ok"))
|
|
80
|
-
}));
|
|
81
|
-
};
|
|
82
|
-
return {
|
|
83
|
-
name: e.name,
|
|
84
|
-
call: async (e, t, n) => {
|
|
85
|
-
let i = await M.runPromiseExit(u(e, t, n), n?.signal === void 0 ? void 0 : { signal: n.signal });
|
|
86
|
-
if (N.isSuccess(i)) return i.value;
|
|
87
|
-
throw r(i.cause);
|
|
88
|
-
},
|
|
89
|
-
callEffect: u,
|
|
90
|
-
subscribe: (t, n, r) => {
|
|
91
|
-
if (U(e, t) !== "query") throw Error(`apis.${e.name}: '${t}' is not a query — only a query can be subscribed to`);
|
|
92
|
-
let i, a = !1, c = -2, l;
|
|
93
|
-
return o().then((e) => {
|
|
94
|
-
if (a) return;
|
|
95
|
-
let o = [t, n], s = e.cache.subscribe(o, () => h(e.client, t)(n), e.runtime, () => {
|
|
96
|
-
let e = s.getSnapshot();
|
|
97
|
-
e.error !== void 0 && e.error !== l && (l = e.error, r.onError?.(e.error)), e.revision >= 0 && e.revision !== c && e.data !== void 0 && (c = e.revision, r.onValue(e.data));
|
|
98
|
-
});
|
|
99
|
-
i = s.unsubscribe;
|
|
100
|
-
}, (e) => {
|
|
101
|
-
r.onError?.(s(t, "transport", `could not build the connection: ${String(e)}`));
|
|
102
|
-
}), { unsubscribe: () => {
|
|
103
|
-
a = !0, i?.();
|
|
104
|
-
} };
|
|
105
|
-
},
|
|
106
|
-
connected: () => i !== void 0,
|
|
107
|
-
close: async () => {
|
|
108
|
-
a = !0;
|
|
109
|
-
let e = i;
|
|
110
|
-
i = void 0, n = void 0, e !== void 0 && (e.cache.destroy(e.runtime), await e.runtime.dispose());
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}, G = (e) => {
|
|
114
|
-
let t = (n) => {
|
|
115
|
-
let r = n.join("."), i = Object.assign((t, n) => e.call(r, t, n), {
|
|
116
|
-
effect: (t, n) => e.callEffect(r, t, n),
|
|
117
|
-
subscribe: (t, n) => e.subscribe(r, t, n)
|
|
118
|
-
});
|
|
119
|
-
return new Proxy(i, { get: (e, r) => {
|
|
120
|
-
if (typeof r == "string") {
|
|
121
|
-
if (r === "effect" || r === "subscribe") return e[r];
|
|
122
|
-
if (r !== "then") return t([...n, r]);
|
|
123
|
-
}
|
|
124
|
-
} });
|
|
125
|
-
};
|
|
126
|
-
return new Proxy({}, { get: (e, n) => typeof n == "string" && n !== "then" ? t([n]) : void 0 });
|
|
127
|
-
};
|
|
128
|
-
//#endregion
|
|
129
|
-
export { H as DEFAULT_SERVICE_CALL_TIMEOUT_MS, v as INITIAL_RECOVERY_SNAPSHOT, m as LoadingSubscriptionCache, f as RecoveryCoordinator, b as RpcErrorBus, d as SubscriptionCache, p as apiConnectivity, D as buildApiRuntime, x as clearClientDiagnostics, C as clientDiagnosticsSnapshot, A as isUnauthenticated, W as makeServiceClient, c as publishClientError, n as publishClientTrace, i as recordClientDiagnostic, s as recoveryCoordinatorFor, S as rememberRpcErrorKind, l as reportClientError, h as resolveByTag, g as resolveRecoveryOptions, a as rpcErrorKind, y as runRpcPromise, G as serviceApi, u as stableKey, w as startApiSupervisor, e as subscribeClientDiagnostics, _ as subscribeClientErrors, t as subscribeClientTraces, o as supersedesConfirmedPatches, E as wireAuthRefresh, k as withProtocolOpenRecovery };
|
|
1
|
+
import { publishClientTrace as e, subscribeClientTraces as t } from "./traceBus.js";
|
|
2
|
+
import { rememberRpcErrorKind as n, rpcErrorKind as r } from "./rpcErrorKind.js";
|
|
3
|
+
import { clearClientDiagnostics as i, clientDiagnosticsSnapshot as a, recordClientDiagnostic as o, subscribeClientDiagnostics as s } from "./clientDiagnostics.js";
|
|
4
|
+
import { stableKey as c } from "./stableKey.js";
|
|
5
|
+
import { LoadingSubscriptionCache as l, SubscriptionCache as u, supersedesConfirmedPatches as d } from "./subscriptionCache.js";
|
|
6
|
+
import { publishClientError as f, reportClientError as p, subscribeClientErrors as m } from "./clientErrorBus.js";
|
|
7
|
+
import { RpcErrorBus as h } from "./rpcErrorBus.js";
|
|
8
|
+
import { apiConnectivity as g } from "./apiConnectivity.js";
|
|
9
|
+
import { INITIAL_RECOVERY_SNAPSHOT as _, RecoveryCoordinator as v, recoveryCoordinatorFor as y, resolveRecoveryOptions as b } from "./recoveryCoordinator.js";
|
|
10
|
+
import { resolveByTag as x } from "./tagWalk.js";
|
|
11
|
+
import { buildApiRuntime as S, makeProtocolOpenRecovery as C } from "./apiRuntime.js";
|
|
12
|
+
import { startApiSupervisor as w } from "./apiSupervisor.js";
|
|
13
|
+
import { runRpcPromise as T } from "./runRpc.js";
|
|
14
|
+
import { isUnauthenticated as E, wireAuthRefresh as D } from "./authRefresh.js";
|
|
15
|
+
import { DEFAULT_SERVICE_CALL_TIMEOUT_MS as O, makeServiceClient as k, serviceApi as A } from "./serviceClient.js";
|
|
16
|
+
export { O as DEFAULT_SERVICE_CALL_TIMEOUT_MS, _ as INITIAL_RECOVERY_SNAPSHOT, l as LoadingSubscriptionCache, v as RecoveryCoordinator, h as RpcErrorBus, u as SubscriptionCache, g as apiConnectivity, S as buildApiRuntime, i as clearClientDiagnostics, a as clientDiagnosticsSnapshot, E as isUnauthenticated, C as makeProtocolOpenRecovery, k as makeServiceClient, f as publishClientError, e as publishClientTrace, o as recordClientDiagnostic, y as recoveryCoordinatorFor, n as rememberRpcErrorKind, p as reportClientError, x as resolveByTag, b as resolveRecoveryOptions, r as rpcErrorKind, T as runRpcPromise, A as serviceApi, c as stableKey, w as startApiSupervisor, s as subscribeClientDiagnostics, m as subscribeClientErrors, t as subscribeClientTraces, d as supersedesConfirmedPatches, D as wireAuthRefresh };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//#region src/runtimeCapabilities.ts
|
|
2
|
+
var e = (e, t, n) => {
|
|
3
|
+
try {
|
|
4
|
+
let r = globalThis.location, i = typeof r == "object" && r ? r.href : void 0, a = new URL(e, i);
|
|
5
|
+
if (a.protocol === "wss:" ? a.protocol = "https:" : a.protocol === "ws:" && (a.protocol = "http:"), n !== void 0) return new URL(n, a).toString();
|
|
6
|
+
let o = `/ws/${t}`;
|
|
7
|
+
if (a.pathname === o) a.pathname = `/_voltro/api/${encodeURIComponent(t)}/_voltro/runtime-capabilities`;
|
|
8
|
+
else {
|
|
9
|
+
let e = a.pathname.lastIndexOf("/");
|
|
10
|
+
a.pathname = `${e <= 0 ? "" : a.pathname.slice(0, e)}/_voltro/runtime-capabilities`;
|
|
11
|
+
}
|
|
12
|
+
return a.search = "", a.hash = "", a.toString();
|
|
13
|
+
} catch {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
}, t = async (t, n, r = fetch, i = 1500, a) => {
|
|
17
|
+
let o = e(t, n, a);
|
|
18
|
+
if (o === void 0) return;
|
|
19
|
+
let s = new AbortController(), c = setTimeout(() => s.abort(), i);
|
|
20
|
+
try {
|
|
21
|
+
let e = await r(o, {
|
|
22
|
+
method: "GET",
|
|
23
|
+
headers: { accept: "application/json" },
|
|
24
|
+
cache: "no-store",
|
|
25
|
+
signal: s.signal
|
|
26
|
+
});
|
|
27
|
+
if (!e.ok) return;
|
|
28
|
+
let t = await e.json();
|
|
29
|
+
if (t.protocol !== 1 || typeof t.mutationReplay != "boolean") return;
|
|
30
|
+
let n = (e) => typeof e == "object" && e && !Array.isArray(e) && Object.values(e).every((e) => typeof e == "string") ? e : void 0, i = n(t.surface), a = n(t.serviceSurface);
|
|
31
|
+
return {
|
|
32
|
+
protocol: 1,
|
|
33
|
+
mutationReplay: t.mutationReplay,
|
|
34
|
+
...i === void 0 ? {} : { surface: i },
|
|
35
|
+
...a === void 0 ? {} : { serviceSurface: a }
|
|
36
|
+
};
|
|
37
|
+
} catch {
|
|
38
|
+
return;
|
|
39
|
+
} finally {
|
|
40
|
+
clearTimeout(c), s.abort();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export { t as readRuntimeCapabilities, e as runtimeCapabilitiesUrl };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { LoadingSubscriptionCache as e } from "./subscriptionCache.js";
|
|
2
|
+
import { RpcErrorBus as t } from "./rpcErrorBus.js";
|
|
3
|
+
import { RecoveryCoordinator as n } from "./recoveryCoordinator.js";
|
|
4
|
+
import { FrameworkRuntimesContext as r, isUnresolvedApi as i, unknownApiError as a } from "./frameworkRuntimesContext.js";
|
|
5
|
+
import { useContext as o, useEffect as s } from "react";
|
|
6
|
+
import { Exit as c } from "effect";
|
|
7
|
+
//#region src/runtimeContext.ts
|
|
8
|
+
var l = () => {
|
|
9
|
+
throw Error("Voltro: rpc / cache calls are not invokable on a not-yet-resolved api — either during SSR, or in the client boot window before the api client resolves");
|
|
10
|
+
}, u = /* @__PURE__ */ new Proxy(() => l(), {
|
|
11
|
+
get: (e, t) => u,
|
|
12
|
+
has: () => !0,
|
|
13
|
+
apply: () => l()
|
|
14
|
+
}), d = Symbol.for("@voltro/client/ssrDescriptors"), f = globalThis, p = f[d] ?? (f[d] = { byApi: /* @__PURE__ */ new Map() }), m = (e, t) => {
|
|
15
|
+
p.byApi.set(e, t);
|
|
16
|
+
}, h = (e) => p.byApi.get(e), g = () => {
|
|
17
|
+
p.byApi.clear();
|
|
18
|
+
}, _ = {
|
|
19
|
+
runtime: { runPromiseExit: () => Promise.resolve(c.die(/* @__PURE__ */ Error("Voltro: mutations are not invokable during SSR"))) },
|
|
20
|
+
cache: /* @__PURE__ */ new e(),
|
|
21
|
+
client: u,
|
|
22
|
+
descriptors: {},
|
|
23
|
+
inspectBaseUrl: "",
|
|
24
|
+
errorBus: /* @__PURE__ */ new t(),
|
|
25
|
+
recovery: /* @__PURE__ */ new n("ssr")
|
|
26
|
+
}, v = {
|
|
27
|
+
get: (e) => {
|
|
28
|
+
let t = h(e);
|
|
29
|
+
return t === void 0 ? _ : {
|
|
30
|
+
..._,
|
|
31
|
+
descriptors: t
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
names: []
|
|
35
|
+
}, y = !1, b = !1, x = null, S = () => {
|
|
36
|
+
y = !1, b = !1, x !== null && (clearTimeout(x), x = null);
|
|
37
|
+
}, C = () => {
|
|
38
|
+
let e = o(r);
|
|
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>."));
|
|
41
|
+
}, 0)), v);
|
|
42
|
+
}, w = (e) => {
|
|
43
|
+
let t = C(), n = t.demand;
|
|
44
|
+
return s(() => {
|
|
45
|
+
n?.(e);
|
|
46
|
+
}, [n, e]), t.get(e);
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { r as FrameworkRuntimesContext, S as _resetFrameworkRuntimesWarning, g as _resetSsrDescriptors, i as isUnresolvedApi, m as registerSsrDescriptors, u as ssrClientProxy, h as ssrDescriptorsFor, _ as ssrStubHandle, a as unknownApiError, w as useFrameworkApi, C as useFrameworkRuntimes };
|