@voltro/client 0.84.0 → 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/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 '@effect/rpc';
6
- import { RpcClient } from '@effect/rpc';
7
- import { RpcClientError } from '@effect/rpc';
8
- import { RpcGroup } from '@effect/rpc';
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 '@effect/platform/Socket';
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 @effect/rpc — invariant on purpose — so a
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, protocols?: string | ReadonlyArray<string>) => globalThis.WebSocket;
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.RuntimeFiber<unknown, unknown> | null;
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 {
@@ -518,6 +529,8 @@ export declare class LoadingSubscriptionCache extends SubscriptionCache {
518
529
  };
519
530
  }
520
531
 
532
+ /* Excluded from this release type: makeProtocolOpenRecovery */
533
+
521
534
  export declare const makeServiceClient: (options: ServiceClientOptions) => ServiceClient;
522
535
 
523
536
  /**
@@ -559,6 +572,8 @@ declare interface OptimisticPatch<T = unknown> {
559
572
  /** A successful write stays previewed until a matching post-ACK primary
560
573
  * snapshot supersedes it. A different write's delta proves nothing. */
561
574
  confirmed?: boolean;
575
+ /** Only framework-owned reducers with an unchanged input can reuse a prefix. */
576
+ readonly canReuse?: (() => boolean) | undefined;
562
577
  }
563
578
 
564
579
  /** Publish a client error. Cheap + sync; a broken listener can't break the caller. */
@@ -733,7 +748,7 @@ export declare interface RpcError {
733
748
  * server may have committed before the response disappeared. */
734
749
  readonly outcome?: RpcCallOutcome;
735
750
  /** Trace id of the CLIENT call span. When the server accepted the request,
736
- * @effect/rpc propagates this same id into its span. A transport failure may
751
+ * effect/rpc propagates this same id into its span. A transport failure may
737
752
  * happen before that, so the id is not proof that server logs exist. Present
738
753
  * only when a client span was active. */
739
754
  readonly traceId?: string;
@@ -786,7 +801,7 @@ export declare type RpcErrorKind = 'transport' | 'handler' | 'client' | 'unknown
786
801
  /**
787
802
  * Classify an error whose pipeline location is already known.
788
803
  *
789
- * `RpcClientError` is @effect/rpc's transport failure value. Detect it through
804
+ * `RpcClientError` is effect/rpc's transport failure value. Detect it through
790
805
  * its global TypeId instead of `instanceof`: a browser bundle can contain more
791
806
  * than one physical package copy, while the `Symbol.for` marker remains stable.
792
807
  * Everything else keeps the caller's evidence-based fallback — this helper
@@ -810,7 +825,7 @@ export declare type RpcSuccessListener = (event: RpcSuccess) => void;
810
825
  /**
811
826
  * Run an rpc effect on an api's runtime and resolve it to a promise that
812
827
  * rejects with the FAILURE VALUE ITSELF — the typed error the server declared
813
- * — instead of Effect's `FiberFailure` wrapper.
828
+ * — reduced by the same rule the read path applies to a failed subscription.
814
829
  *
815
830
  * Every write-side hook (`useMutation`, `useAction`, `useWorkflow`,
816
831
  * `useUpload`) goes through here, so `err._tag` means the same thing on both
@@ -869,7 +884,7 @@ export declare interface ServiceClientOptions {
869
884
  }>>;
870
885
  /** How to open a socket. Defaults to the platform's global `WebSocket`
871
886
  * (Node 22+ has one). */
872
- readonly webSocketConstructor?: (url: string, protocols?: string | ReadonlyArray<string>) => globalThis.WebSocket;
887
+ readonly webSocketConstructor?: (url: string, options?: Socket.WebSocketConstructorOptions) => globalThis.WebSocket;
873
888
  /** Default deadline for every call. */
874
889
  readonly defaultTimeoutMs?: number;
875
890
  /**
@@ -914,10 +929,18 @@ export declare const subscribeClientTraces: (listener: ClientTraceListener) => (
914
929
 
915
930
  export declare class SubscriptionCache {
916
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;
917
939
  /** Standing optimistic intents, by mutation id — see `autoApply`. */
918
940
  private readonly intents;
919
941
  private readonly tableRows;
920
942
  private readonly anyListeners;
943
+ private readonly tableListeners;
921
944
  private readonly refreshing;
922
945
  /**
923
946
  * Same-subject runtime replacement. A mutation may settle against the cache
@@ -1173,6 +1196,16 @@ export declare class SubscriptionCache {
1173
1196
  private createStub;
1174
1197
  private freshState;
1175
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;
1176
1209
  private invalidate;
1177
1210
  /**
1178
1211
  * Every row of `table` this cache holds — the client's local replica of the
@@ -1183,6 +1216,8 @@ export declare class SubscriptionCache {
1183
1216
  * for `useSyncExternalStore`.
1184
1217
  */
1185
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;
1186
1221
  /** Call `listener` after any entry changed. Returns the unsubscribe. */
1187
1222
  subscribeAny(listener: () => void): () => void;
1188
1223
  private getSnapshot;
@@ -1369,6 +1404,4 @@ export declare interface SupervisorOptions {
1369
1404
  */
1370
1405
  export declare const wireAuthRefresh: (bus: RpcErrorBus, refreshAuth: () => void, options?: AuthRefreshOptions) => AuthRefreshHandle;
1371
1406
 
1372
- /* Excluded from this release type: withProtocolOpenRecovery */
1373
-
1374
1407
  export { }
package/dist/runtime.js CHANGED
@@ -1,8 +1,8 @@
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-DvHpFZAZ.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-C4Ow8HH7.js";
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
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/platform/Headers";
5
- import { RpcClient as R } from "@effect/rpc";
4
+ import * as L from "effect/http/Headers";
5
+ import { RpcClient as R } from "effect/rpc";
6
6
  import { ApiUnavailable as z, MUTATION_IN_FLIGHT_RETRY_AFTER_MS as B } from "@voltro/protocol";
7
7
  //#region src/serviceClient.ts
8
8
  var V = (e) => e?._tag === "MutationInFlight", H = 1e4, U = (e, t) => {
@@ -17,7 +17,7 @@ var V = (e) => e?._tag === "MutationInFlight", H = 1e4, U = (e, t) => {
17
17
  message: "client closed"
18
18
  }));
19
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));
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
21
  return n = D({
22
22
  name: `service:${e.name}`,
23
23
  wsUrl: t,
@@ -35,7 +35,7 @@ var V = (e) => e?._tag === "MutationInFlight", H = 1e4, U = (e, t) => {
35
35
  message: r
36
36
  }), c = (t) => {
37
37
  let n = e.callHeaders?.() ?? {};
38
- return t.pipe(M.locallyWith(R.currentHeaders, (t) => {
38
+ return t.pipe(M.updateService(R.CurrentHeaders, (t) => {
39
39
  let r = L.set(t, "authorization", `Bearer ${e.token()}`);
40
40
  for (let [e, t] of Object.entries(n)) r = L.set(r, e, t);
41
41
  return r;
@@ -71,13 +71,10 @@ var V = (e) => e?._tag === "MutationInFlight", H = 1e4, U = (e, t) => {
71
71
  schedule: F.spaced(j.millis(B))
72
72
  }));
73
73
  }), g = !1;
74
- return m.pipe(M.timeoutFail({
74
+ return m.pipe(M.timeoutOrElse({
75
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
- }));
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"))));
81
78
  };
82
79
  return {
83
80
  name: e.name,
@@ -126,4 +123,4 @@ var V = (e) => e?._tag === "MutationInFlight", H = 1e4, U = (e, t) => {
126
123
  return new Proxy({}, { get: (e, n) => typeof n == "string" && n !== "then" ? t([n]) : void 0 });
127
124
  };
128
125
  //#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 };
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.84.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",
@@ -50,12 +50,10 @@
50
50
  "dependencies": {
51
51
  "@tanstack/form-core": "^1.33.5",
52
52
  "@tanstack/react-store": "^0.11.1",
53
- "@voltro/protocol": "0.84.0"
53
+ "@voltro/protocol": "0.85.0"
54
54
  },
55
55
  "peerDependencies": {
56
- "@effect/platform": "^0.97.2",
57
- "@effect/rpc": "^0.76.2",
58
- "effect": "^3.22.2",
56
+ "effect": "4.0.1",
59
57
  "react": "^19.0.0"
60
58
  },
61
59
  "peerDependenciesMeta": {