@voltro/client 0.83.1 → 0.85.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 +1191 -0
- package/THIRD-PARTY-NOTICES.md +1 -57
- package/dist/authRefresh-DmfSoCca.js +360 -0
- package/dist/form.d.ts +8 -11
- package/dist/form.js +1 -1
- package/dist/formData-BfpBt7BQ.js +769 -0
- package/dist/index.d.ts +406 -282
- package/dist/index.js +1823 -1355
- package/dist/query.d.ts +25 -0
- package/dist/query.js +2 -0
- package/dist/queryOnce-D5Y4V1SB.js +55 -0
- package/dist/runRpc-Zfz3w709.js +1172 -0
- package/dist/runtime.d.ts +135 -16
- package/dist/runtime.js +48 -50
- package/package.json +8 -5
- package/dist/authRefresh-Cu2A-H5R.js +0 -1272
- package/dist/formData-dGz5aoUR.js +0 -649
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';
|
|
@@ -19,6 +20,22 @@ import { TargetRelations } from '@voltro/protocol';
|
|
|
19
20
|
* React context (and its browser globals) merely to name this Effect type. */
|
|
20
21
|
export declare type AnyRuntime = ManagedRuntime.ManagedRuntime<never, never>;
|
|
21
22
|
|
|
23
|
+
/** The registry's read side, as other packages see it through the slot. */
|
|
24
|
+
export declare interface ApiConnectivity {
|
|
25
|
+
/**
|
|
26
|
+
* Is the transport up? With a name: that api's. Without: any mounted api's
|
|
27
|
+
* — the right default for a writer that does not say which api it talks to,
|
|
28
|
+
* because answering "down" while its own api is up would hold its queue
|
|
29
|
+
* shut. `undefined` when no api (of that name) is mounted: nothing is known.
|
|
30
|
+
*/
|
|
31
|
+
readonly online: (apiName?: string) => boolean | undefined;
|
|
32
|
+
/** Called on every transport change of any api. Returns the unsubscribe. */
|
|
33
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The read side — what `useApiOnline` and other packages consume. */
|
|
37
|
+
export declare const apiConnectivity: () => ApiConnectivity;
|
|
38
|
+
|
|
22
39
|
export declare interface ApiHandle {
|
|
23
40
|
readonly runtime: AnyRuntime;
|
|
24
41
|
readonly cache: SubscriptionCache;
|
|
@@ -136,7 +153,7 @@ export declare interface BuildApiRuntimeOptions {
|
|
|
136
153
|
/**
|
|
137
154
|
* The api's rpc group, as the ERASED `RpcGroup.Any`.
|
|
138
155
|
*
|
|
139
|
-
* `RpcGroup` is declared `in out` in
|
|
156
|
+
* `RpcGroup` is declared `in out` in effect/rpc — invariant on purpose — so a
|
|
140
157
|
* CONCRETE group (the `appGroup` codegen emits) is not assignable to
|
|
141
158
|
* `RpcGroup<Rpc.Any>`, and a boundary typed that way rejects the only value
|
|
142
159
|
* anyone ever passes it. This mirrors what `ApiHandle.client` already does:
|
|
@@ -150,7 +167,7 @@ export declare interface BuildApiRuntimeOptions {
|
|
|
150
167
|
/** How to construct a WebSocket. Web wraps `globalThis.WebSocket` with
|
|
151
168
|
* tracking + a connect-timeout; RN passes a plain `globalThis.WebSocket`.
|
|
152
169
|
* Injected so this module touches no environment global directly. */
|
|
153
|
-
readonly webSocketConstructor: (url: string,
|
|
170
|
+
readonly webSocketConstructor: (url: string, options?: Socket.WebSocketConstructorOptions) => globalThis.WebSocket;
|
|
154
171
|
/**
|
|
155
172
|
* Error channel owned by the logical api mount. A reconnect supervisor passes
|
|
156
173
|
* the SAME instance to every transport generation so a failure emitted by the
|
|
@@ -167,6 +184,16 @@ export declare interface BuildApiRuntimeOptions {
|
|
|
167
184
|
* its concern.
|
|
168
185
|
*/
|
|
169
186
|
readonly surfaceAudience?: 'client' | 'service';
|
|
187
|
+
/**
|
|
188
|
+
* Durable local mirror for this generation's subscription cache — the
|
|
189
|
+
* offline read half of local-first. Resolved once here, before the cache
|
|
190
|
+
* exists; see {@link SubscriptionMirrorSource} for why it is never swapped
|
|
191
|
+
* under a live cache.
|
|
192
|
+
*/
|
|
193
|
+
readonly mirror?: SubscriptionMirrorSource | undefined;
|
|
194
|
+
/** The api's rpc descriptors. Handed to the mirror source, and each warm
|
|
195
|
+
* query's `source` routes queued writes' previews onto it. */
|
|
196
|
+
readonly descriptors?: Readonly<Record<string, ClientDescriptor>> | undefined;
|
|
170
197
|
}
|
|
171
198
|
|
|
172
199
|
export declare type BuildClient = (api: MountedApi, generation: number, onSocketOpen: () => void, onSocketIssue: (kind: SocketIssueKind) => void,
|
|
@@ -184,6 +211,7 @@ export declare interface BuiltApiRuntime {
|
|
|
184
211
|
}
|
|
185
212
|
|
|
186
213
|
declare interface CacheEntry {
|
|
214
|
+
rowPatchApplier?: ReturnType<typeof createRowPatchApplier>;
|
|
187
215
|
readonly key: string;
|
|
188
216
|
/** First element of the keyArr — the rpc tag (e.g. 'todos.list'). Used
|
|
189
217
|
* by `forTag()` so callers can patch every sub-key for a tag without
|
|
@@ -201,7 +229,7 @@ declare interface CacheEntry {
|
|
|
201
229
|
/** Subscriber re-render callbacks. */
|
|
202
230
|
subscribers: Set<() => void>;
|
|
203
231
|
/** Fiber running the underlying stream. */
|
|
204
|
-
fiber: Fiber.
|
|
232
|
+
fiber: Fiber.Fiber<unknown, unknown> | null;
|
|
205
233
|
/** The last fiber ended because the rpc transport failed. A later socket
|
|
206
234
|
* `open` re-issues active entries with their last-known-good base intact. */
|
|
207
235
|
resumeAfterTransportOpen: boolean;
|
|
@@ -312,7 +340,7 @@ export declare interface ClientDiagnosticEvent {
|
|
|
312
340
|
readonly fields: Readonly<Record<string, ClientDiagnosticValue>>;
|
|
313
341
|
}
|
|
314
342
|
|
|
315
|
-
export declare type ClientDiagnosticKind = 'runtime.build-started' | 'runtime.resolved' | 'runtime.failed' | 'runtime.capabilities' | 'runtime.surface-mismatch' | 'runtime.swapped' | 'runtime.disposed' | 'socket.created' | 'socket.raw-open' | 'socket.close' | 'socket.error' | 'socket.connect-timeout' | 'socket.retry-scheduled' | 'socket.frames' | 'protocol.ready' | 'subscription.transport-failed' | 'subscription.reissue-started' | 'subscription.reissue-skipped' | 'subscription.first-delivery' | 'subscription.recovery-stuck' | 'subscription.recovery-timer-late' | 'subscription.health-cleared' | 'event.gap' | 'connection.status' | 'recovery.state' | 'fault.transport-cut';
|
|
343
|
+
export declare type ClientDiagnosticKind = 'runtime.build-started' | 'runtime.resolved' | 'runtime.failed' | 'runtime.capabilities' | 'runtime.surface-mismatch' | 'runtime.mirror' | 'runtime.swapped' | 'runtime.disposed' | 'socket.created' | 'socket.raw-open' | 'socket.close' | 'socket.error' | 'socket.connect-timeout' | 'socket.retry-scheduled' | 'socket.frames' | 'protocol.ready' | 'subscription.transport-failed' | 'subscription.reissue-started' | 'subscription.reissue-skipped' | 'subscription.first-delivery' | 'subscription.recovery-stuck' | 'subscription.recovery-timer-late' | 'subscription.health-cleared' | 'event.gap' | 'connection.status' | 'recovery.state' | 'fault.transport-cut';
|
|
316
344
|
|
|
317
345
|
export declare interface ClientDiagnosticsSnapshot {
|
|
318
346
|
readonly version: 1;
|
|
@@ -416,6 +444,15 @@ declare interface EntryState<T> {
|
|
|
416
444
|
/** Cached optimistic snapshot — invalidated on every state change so
|
|
417
445
|
* `getSnapshot` returns a stable reference between mutations. */
|
|
418
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
|
+
};
|
|
419
456
|
}
|
|
420
457
|
|
|
421
458
|
export declare interface FrameworkRuntimes {
|
|
@@ -492,6 +529,8 @@ export declare class LoadingSubscriptionCache extends SubscriptionCache {
|
|
|
492
529
|
};
|
|
493
530
|
}
|
|
494
531
|
|
|
532
|
+
/* Excluded from this release type: makeProtocolOpenRecovery */
|
|
533
|
+
|
|
495
534
|
export declare const makeServiceClient: (options: ServiceClientOptions) => ServiceClient;
|
|
496
535
|
|
|
497
536
|
/**
|
|
@@ -514,6 +553,9 @@ export declare interface MountedApi {
|
|
|
514
553
|
readonly wsUrl: string;
|
|
515
554
|
readonly headers?: ResolvableHeaders | undefined;
|
|
516
555
|
readonly recovery?: RecoveryOptions | undefined;
|
|
556
|
+
/** Durable local mirror, resolved per transport generation — see
|
|
557
|
+
* `BuildApiRuntimeOptions.mirror`. */
|
|
558
|
+
readonly mirror?: SubscriptionMirrorSource | undefined;
|
|
517
559
|
}
|
|
518
560
|
|
|
519
561
|
export declare interface MutationReplayReservation {
|
|
@@ -530,6 +572,8 @@ declare interface OptimisticPatch<T = unknown> {
|
|
|
530
572
|
/** A successful write stays previewed until a matching post-ACK primary
|
|
531
573
|
* snapshot supersedes it. A different write's delta proves nothing. */
|
|
532
574
|
confirmed?: boolean;
|
|
575
|
+
/** Only framework-owned reducers with an unchanged input can reuse a prefix. */
|
|
576
|
+
readonly canReuse?: (() => boolean) | undefined;
|
|
533
577
|
}
|
|
534
578
|
|
|
535
579
|
/** Publish a client error. Cheap + sync; a broken listener can't break the caller. */
|
|
@@ -704,7 +748,7 @@ export declare interface RpcError {
|
|
|
704
748
|
* server may have committed before the response disappeared. */
|
|
705
749
|
readonly outcome?: RpcCallOutcome;
|
|
706
750
|
/** Trace id of the CLIENT call span. When the server accepted the request,
|
|
707
|
-
*
|
|
751
|
+
* effect/rpc propagates this same id into its span. A transport failure may
|
|
708
752
|
* happen before that, so the id is not proof that server logs exist. Present
|
|
709
753
|
* only when a client span was active. */
|
|
710
754
|
readonly traceId?: string;
|
|
@@ -757,7 +801,7 @@ export declare type RpcErrorKind = 'transport' | 'handler' | 'client' | 'unknown
|
|
|
757
801
|
/**
|
|
758
802
|
* Classify an error whose pipeline location is already known.
|
|
759
803
|
*
|
|
760
|
-
* `RpcClientError` is
|
|
804
|
+
* `RpcClientError` is effect/rpc's transport failure value. Detect it through
|
|
761
805
|
* its global TypeId instead of `instanceof`: a browser bundle can contain more
|
|
762
806
|
* than one physical package copy, while the `Symbol.for` marker remains stable.
|
|
763
807
|
* Everything else keeps the caller's evidence-based fallback — this helper
|
|
@@ -781,7 +825,7 @@ export declare type RpcSuccessListener = (event: RpcSuccess) => void;
|
|
|
781
825
|
/**
|
|
782
826
|
* Run an rpc effect on an api's runtime and resolve it to a promise that
|
|
783
827
|
* rejects with the FAILURE VALUE ITSELF — the typed error the server declared
|
|
784
|
-
* —
|
|
828
|
+
* — reduced by the same rule the read path applies to a failed subscription.
|
|
785
829
|
*
|
|
786
830
|
* Every write-side hook (`useMutation`, `useAction`, `useWorkflow`,
|
|
787
831
|
* `useUpload`) goes through here, so `err._tag` means the same thing on both
|
|
@@ -840,7 +884,7 @@ export declare interface ServiceClientOptions {
|
|
|
840
884
|
}>>;
|
|
841
885
|
/** How to open a socket. Defaults to the platform's global `WebSocket`
|
|
842
886
|
* (Node 22+ has one). */
|
|
843
|
-
readonly webSocketConstructor?: (url: string,
|
|
887
|
+
readonly webSocketConstructor?: (url: string, options?: Socket.WebSocketConstructorOptions) => globalThis.WebSocket;
|
|
844
888
|
/** Default deadline for every call. */
|
|
845
889
|
readonly defaultTimeoutMs?: number;
|
|
846
890
|
/**
|
|
@@ -885,6 +929,18 @@ export declare const subscribeClientTraces: (listener: ClientTraceListener) => (
|
|
|
885
929
|
|
|
886
930
|
export declare class SubscriptionCache {
|
|
887
931
|
private readonly entries;
|
|
932
|
+
private readonly entriesByTable;
|
|
933
|
+
private readonly entriesByTag;
|
|
934
|
+
private readonly entriesByMutation;
|
|
935
|
+
private readonly patchMemberships;
|
|
936
|
+
private readonly entryOrder;
|
|
937
|
+
private orderedMemberships;
|
|
938
|
+
private nextEntryOrder;
|
|
939
|
+
/** Standing optimistic intents, by mutation id — see `autoApply`. */
|
|
940
|
+
private readonly intents;
|
|
941
|
+
private readonly tableRows;
|
|
942
|
+
private readonly anyListeners;
|
|
943
|
+
private readonly tableListeners;
|
|
888
944
|
private readonly refreshing;
|
|
889
945
|
/**
|
|
890
946
|
* Same-subject runtime replacement. A mutation may settle against the cache
|
|
@@ -1006,7 +1062,15 @@ export declare class SubscriptionCache {
|
|
|
1006
1062
|
* these defaults. All patches are tagged with `mutationId` for atomic
|
|
1007
1063
|
* revert.
|
|
1008
1064
|
*/
|
|
1009
|
-
autoApply(targets: ReadonlyArray<AutoApplyTarget>, input: Record<string, unknown>, mutationId: string
|
|
1065
|
+
autoApply(targets: ReadonlyArray<AutoApplyTarget>, input: Record<string, unknown>, mutationId: string, options?: {
|
|
1066
|
+
readonly standing?: boolean;
|
|
1067
|
+
}): void;
|
|
1068
|
+
/** Whether a standing intent for `mutationId` is still held (see
|
|
1069
|
+
* {@link SubscriptionCache.autoApply}). Carried to a same-subject
|
|
1070
|
+
* replacement cache, so a stager can tell "already staged" from "new". */
|
|
1071
|
+
hasIntent(mutationId: string): boolean;
|
|
1072
|
+
private applyIntent;
|
|
1073
|
+
private applyStandingIntents;
|
|
1010
1074
|
/** Drop a specific patch by id. */
|
|
1011
1075
|
private revertPatch;
|
|
1012
1076
|
/**
|
|
@@ -1132,7 +1196,30 @@ export declare class SubscriptionCache {
|
|
|
1132
1196
|
private createStub;
|
|
1133
1197
|
private freshState;
|
|
1134
1198
|
private startFiber;
|
|
1199
|
+
private sourceTables;
|
|
1200
|
+
private addIndex;
|
|
1201
|
+
private removeIndex;
|
|
1202
|
+
private orderedEntries;
|
|
1203
|
+
private indexSource;
|
|
1204
|
+
private appendPatch;
|
|
1205
|
+
private replacePatches;
|
|
1206
|
+
private indexPatches;
|
|
1207
|
+
private registerEntry;
|
|
1208
|
+
private unindexEntry;
|
|
1135
1209
|
private invalidate;
|
|
1210
|
+
/**
|
|
1211
|
+
* Every row of `table` this cache holds — the client's local replica of the
|
|
1212
|
+
* table: the union of the rows of every entry sourced on that table ALONE
|
|
1213
|
+
* (an entry over several tables holds joined shapes, not rows of one),
|
|
1214
|
+
* optimistic previews and mirror-seeded rows included, deduplicated by `id`.
|
|
1215
|
+
* Memoised per table until the next change, so the result is reference-stable
|
|
1216
|
+
* for `useSyncExternalStore`.
|
|
1217
|
+
*/
|
|
1218
|
+
rowsOf(table: string): ReadonlyArray<Readonly<Record<string, unknown>>>;
|
|
1219
|
+
/** Subscribe to cache changes affecting this source table only. */
|
|
1220
|
+
subscribeTable(table: string, listener: () => void): () => void;
|
|
1221
|
+
/** Call `listener` after any entry changed. Returns the unsubscribe. */
|
|
1222
|
+
subscribeAny(listener: () => void): () => void;
|
|
1136
1223
|
private getSnapshot;
|
|
1137
1224
|
private unsubscribe;
|
|
1138
1225
|
/** Start (or restart) the inactive-TTL countdown for `entry`: unless
|
|
@@ -1189,8 +1276,42 @@ export declare interface SubscriptionMirror {
|
|
|
1189
1276
|
readonly data: unknown;
|
|
1190
1277
|
readonly revision: number;
|
|
1191
1278
|
}) => Promise<void>;
|
|
1279
|
+
/**
|
|
1280
|
+
* Queries to keep subscribed for the whole connection generation, as
|
|
1281
|
+
* `[tag, input]` — so they are mirrored, and readable offline, before any
|
|
1282
|
+
* screen ever opened them. Offline coverage is otherwise "what the user
|
|
1283
|
+
* happened to visit"; this makes it a declaration.
|
|
1284
|
+
*/
|
|
1285
|
+
readonly warm?: ReadonlyArray<readonly [tag: string, input: Readonly<Record<string, unknown>>]>;
|
|
1286
|
+
/**
|
|
1287
|
+
* Tags to keep warm with an EMPTY input — each one whose declared input
|
|
1288
|
+
* schema accepts `{}` (a list, a feed, a settings read). The runtime makes
|
|
1289
|
+
* that check against the descriptors; a tag that needs parameters is left
|
|
1290
|
+
* out rather than subscribed into an error.
|
|
1291
|
+
*/
|
|
1292
|
+
readonly warmTags?: ReadonlyArray<string>;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
/** What a {@link SubscriptionMirrorSource} is told about the api it mirrors. */
|
|
1296
|
+
export declare interface SubscriptionMirrorContext {
|
|
1297
|
+
/** The api's mount name (`'app'`). */
|
|
1298
|
+
readonly apiName: string;
|
|
1299
|
+
/** The api's rpc descriptors — each query's `source` table(s) is how a source
|
|
1300
|
+
* derives which queries read local-first tables without being told. */
|
|
1301
|
+
readonly descriptors: Readonly<Record<string, ClientDescriptor>>;
|
|
1192
1302
|
}
|
|
1193
1303
|
|
|
1304
|
+
/**
|
|
1305
|
+
* Where a runtime gets its {@link SubscriptionMirror}: called ONCE per
|
|
1306
|
+
* connection generation, before that generation's cache exists. The cache
|
|
1307
|
+
* keeps what it returned for its whole life, so a mirror is never swapped
|
|
1308
|
+
* under a live cache — a sign-in or tenant switch (`reconnect()`) builds a new
|
|
1309
|
+
* generation, and THAT call resolves the next subject's partition. Resolving
|
|
1310
|
+
* to `undefined` (nobody signed in, no durable storage) mirrors nothing.
|
|
1311
|
+
* `@voltro/local-first`'s `createMirrorSource` is the implementation.
|
|
1312
|
+
*/
|
|
1313
|
+
export declare type SubscriptionMirrorSource = (context: SubscriptionMirrorContext) => SubscriptionMirror | undefined | Promise<SubscriptionMirror | undefined>;
|
|
1314
|
+
|
|
1194
1315
|
/**
|
|
1195
1316
|
* The matching token proves this snapshot was read after the covered ACKs.
|
|
1196
1317
|
* Contents need not equal the preview: server normalisation, no-op writes and
|
|
@@ -1283,6 +1404,4 @@ export declare interface SupervisorOptions {
|
|
|
1283
1404
|
*/
|
|
1284
1405
|
export declare const wireAuthRefresh: (bus: RpcErrorBus, refreshAuth: () => void, options?: AuthRefreshOptions) => AuthRefreshHandle;
|
|
1285
1406
|
|
|
1286
|
-
/* Excluded from this release type: withProtocolOpenRecovery */
|
|
1287
|
-
|
|
1288
1407
|
export { }
|
package/dist/runtime.js
CHANGED
|
@@ -1,50 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
1
|
+
import { C as e, D as t, E as n, O as r, S as i, T as a, _ as o, a as s, d as c, f as l, g as u, h as d, i as f, l as p, m, n as h, o as g, p as _, r as v, t as y, u as b, v as x, w as S, y as C } from "./runRpc-Zfz3w709.js";
|
|
2
|
+
import { a as w, i as T, n as E, o as D, r as O, s as k, t as A } from "./authRefresh-DmfSoCca.js";
|
|
3
|
+
import { Duration as j, Effect as M, Exit as N, Option as P, Schedule as F, Stream as I } from "effect";
|
|
4
|
+
import * as L from "effect/http/Headers";
|
|
5
|
+
import { RpcClient as R } from "effect/rpc";
|
|
6
|
+
import { ApiUnavailable as z, MUTATION_IN_FLIGHT_RETRY_AFTER_MS as B } from "@voltro/protocol";
|
|
6
7
|
//#region src/serviceClient.ts
|
|
7
|
-
var
|
|
8
|
+
var V = (e) => e?._tag === "MutationInFlight", H = 1e4, U = (e, t) => {
|
|
8
9
|
let n = e.descriptors[t]?.kind;
|
|
9
10
|
return n === "query" || n === "mutation" || n === "action" ? n : void 0;
|
|
10
|
-
},
|
|
11
|
-
let t = e.defaultTimeoutMs ?? 1e4, n,
|
|
12
|
-
if (a) return Promise.reject(new
|
|
11
|
+
}, W = (e) => {
|
|
12
|
+
let t = e.defaultTimeoutMs ?? 1e4, n, i, a = !1, o = () => {
|
|
13
|
+
if (a) return Promise.reject(new z({
|
|
13
14
|
api: e.name,
|
|
14
15
|
tag: "",
|
|
15
16
|
reason: "closed",
|
|
16
17
|
message: "client closed"
|
|
17
18
|
}));
|
|
18
19
|
if (n !== void 0) return n;
|
|
19
|
-
let t = typeof e.wsUrl == "function" ? e.wsUrl() : e.wsUrl,
|
|
20
|
-
return n =
|
|
20
|
+
let t = typeof e.wsUrl == "function" ? e.wsUrl() : e.wsUrl, r = e.webSocketConstructor ?? ((e, t) => new globalThis.WebSocket(e, typeof t == "object" && !Array.isArray(t) ? void 0 : t));
|
|
21
|
+
return n = D({
|
|
21
22
|
name: `service:${e.name}`,
|
|
22
23
|
wsUrl: t,
|
|
23
24
|
group: e.group,
|
|
24
25
|
headers: async () => ({ authorization: `Bearer ${e.token()}` }),
|
|
25
|
-
webSocketConstructor:
|
|
26
|
+
webSocketConstructor: r,
|
|
26
27
|
surfaceAudience: "service"
|
|
27
|
-
}).then((e) => (
|
|
28
|
+
}).then((e) => (i = e, e), (e) => {
|
|
28
29
|
throw n = void 0, e;
|
|
29
30
|
}), n;
|
|
30
|
-
}, s = (t, n, r) => new
|
|
31
|
+
}, s = (t, n, r) => new z({
|
|
31
32
|
api: e.name,
|
|
32
33
|
tag: t,
|
|
33
34
|
reason: n,
|
|
34
35
|
message: r
|
|
35
36
|
}), c = (t) => {
|
|
36
37
|
let n = e.callHeaders?.() ?? {};
|
|
37
|
-
return t.pipe(
|
|
38
|
-
let r =
|
|
39
|
-
for (let [e, t] of Object.entries(n)) r =
|
|
38
|
+
return t.pipe(M.updateService(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);
|
|
40
41
|
return r;
|
|
41
42
|
}));
|
|
42
|
-
}, l = (e) => e.pipe(
|
|
43
|
-
if (
|
|
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"));
|
|
44
45
|
let t = e.value;
|
|
45
|
-
return t._tag === "error" ?
|
|
46
|
-
})),
|
|
47
|
-
let u =
|
|
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) => {
|
|
48
49
|
e.onCall?.({
|
|
49
50
|
api: e.name,
|
|
50
51
|
tag: n,
|
|
@@ -52,46 +53,43 @@ var B = (e) => e?._tag === "MutationInFlight", V = 1e4, H = (e, t) => {
|
|
|
52
53
|
outcome: t
|
|
53
54
|
});
|
|
54
55
|
};
|
|
55
|
-
if (u === void 0) return
|
|
56
|
-
let m =
|
|
57
|
-
let t = yield*
|
|
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({
|
|
58
59
|
try: () => o(),
|
|
59
60
|
catch: (e) => s(n, a ? "closed" : "transport", `could not build the connection: ${String(e)}`)
|
|
60
|
-
}), d =
|
|
61
|
+
}), d = h(t.client, n);
|
|
61
62
|
if (u === "query") {
|
|
62
63
|
let e = d(r);
|
|
63
64
|
return yield* c(l(e));
|
|
64
65
|
}
|
|
65
|
-
let f = i?.idempotencyKey === void 0 && e.ambientIdempotencyKey !== void 0 ? yield* e.ambientIdempotencyKey(n, r) : void 0, p = i?.idempotencyKey ?? f ??
|
|
66
|
-
return yield* c(
|
|
67
|
-
|
|
68
|
-
})),
|
|
69
|
-
while:
|
|
70
|
-
schedule:
|
|
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))
|
|
71
72
|
}));
|
|
72
73
|
}), g = !1;
|
|
73
|
-
return m.pipe(
|
|
74
|
-
duration:
|
|
75
|
-
|
|
76
|
-
}),
|
|
77
|
-
onFailure: (e) => j.sync(() => p(e?._tag === "ApiUnavailable" ? "unavailable" : "error")),
|
|
78
|
-
onSuccess: () => j.sync(() => p("ok"))
|
|
79
|
-
}));
|
|
74
|
+
return m.pipe(M.timeoutOrElse({
|
|
75
|
+
duration: j.millis(d),
|
|
76
|
+
orElse: () => M.fail(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.tapError((e) => M.sync(() => p(e?._tag === "ApiUnavailable" ? "unavailable" : "error"))), M.tap(() => M.sync(() => p("ok"))));
|
|
80
78
|
};
|
|
81
79
|
return {
|
|
82
80
|
name: e.name,
|
|
83
81
|
call: async (e, t, n) => {
|
|
84
|
-
let
|
|
85
|
-
if (
|
|
86
|
-
throw i
|
|
82
|
+
let i = await M.runPromiseExit(u(e, t, n), n?.signal === void 0 ? void 0 : { signal: n.signal });
|
|
83
|
+
if (N.isSuccess(i)) return i.value;
|
|
84
|
+
throw r(i.cause);
|
|
87
85
|
},
|
|
88
|
-
callEffect:
|
|
86
|
+
callEffect: u,
|
|
89
87
|
subscribe: (t, n, r) => {
|
|
90
|
-
if (
|
|
88
|
+
if (U(e, t) !== "query") throw Error(`apis.${e.name}: '${t}' is not a query — only a query can be subscribed to`);
|
|
91
89
|
let i, a = !1, c = -2, l;
|
|
92
90
|
return o().then((e) => {
|
|
93
91
|
if (a) return;
|
|
94
|
-
let o = [t, n], s = e.cache.subscribe(o, () =>
|
|
92
|
+
let o = [t, n], s = e.cache.subscribe(o, () => h(e.client, t)(n), e.runtime, () => {
|
|
95
93
|
let e = s.getSnapshot();
|
|
96
94
|
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));
|
|
97
95
|
});
|
|
@@ -102,14 +100,14 @@ var B = (e) => e?._tag === "MutationInFlight", V = 1e4, H = (e, t) => {
|
|
|
102
100
|
a = !0, i?.();
|
|
103
101
|
} };
|
|
104
102
|
},
|
|
105
|
-
connected: () =>
|
|
103
|
+
connected: () => i !== void 0,
|
|
106
104
|
close: async () => {
|
|
107
105
|
a = !0;
|
|
108
|
-
let e =
|
|
109
|
-
|
|
106
|
+
let e = i;
|
|
107
|
+
i = void 0, n = void 0, e !== void 0 && (e.cache.destroy(e.runtime), await e.runtime.dispose());
|
|
110
108
|
}
|
|
111
109
|
};
|
|
112
|
-
},
|
|
110
|
+
}, G = (e) => {
|
|
113
111
|
let t = (n) => {
|
|
114
112
|
let r = n.join("."), i = Object.assign((t, n) => e.call(r, t, n), {
|
|
115
113
|
effect: (t, n) => e.callEffect(r, t, n),
|
|
@@ -125,4 +123,4 @@ var B = (e) => e?._tag === "MutationInFlight", V = 1e4, H = (e, t) => {
|
|
|
125
123
|
return new Proxy({}, { get: (e, n) => typeof n == "string" && n !== "then" ? t([n]) : void 0 });
|
|
126
124
|
};
|
|
127
125
|
//#endregion
|
|
128
|
-
export {
|
|
126
|
+
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, k as makeProtocolOpenRecovery, 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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.85.0",
|
|
4
4
|
"description": "Framework-agnostic client bindings — the typed RpcClient, subscription cache, and reactive data layer the web hooks build on.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|
|
@@ -33,6 +33,11 @@
|
|
|
33
33
|
"types": "./dist/runtime.d.ts",
|
|
34
34
|
"import": "./dist/runtime.js",
|
|
35
35
|
"default": "./dist/runtime.js"
|
|
36
|
+
},
|
|
37
|
+
"./query": {
|
|
38
|
+
"types": "./dist/query.d.ts",
|
|
39
|
+
"import": "./dist/query.js",
|
|
40
|
+
"default": "./dist/query.js"
|
|
36
41
|
}
|
|
37
42
|
},
|
|
38
43
|
"main": "./dist/index.js",
|
|
@@ -45,12 +50,10 @@
|
|
|
45
50
|
"dependencies": {
|
|
46
51
|
"@tanstack/form-core": "^1.33.5",
|
|
47
52
|
"@tanstack/react-store": "^0.11.1",
|
|
48
|
-
"@voltro/protocol": "0.
|
|
53
|
+
"@voltro/protocol": "0.85.0"
|
|
49
54
|
},
|
|
50
55
|
"peerDependencies": {
|
|
51
|
-
"
|
|
52
|
-
"@effect/rpc": "^0.76.2",
|
|
53
|
-
"effect": "^3.22.2",
|
|
56
|
+
"effect": "4.0.1",
|
|
54
57
|
"react": "^19.0.0"
|
|
55
58
|
},
|
|
56
59
|
"peerDependenciesMeta": {
|