@emeryld/rrroutes-client 2.6.10 → 2.6.12

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.
@@ -0,0 +1,13 @@
1
+ import { type AnyLeafLowProfile } from '@emeryld/rrroutes-contract';
2
+ import { type QueryClient } from '@tanstack/react-query';
3
+ import type { BranchBuildOptions, BuiltBranch, BuiltLeafMap, RouteClientFetch } from './routesV3.client.types';
4
+ type BuildBatchBranchDeps = {
5
+ fetchRaw: RouteClientFetch;
6
+ queryClient: QueryClient;
7
+ validateResponses: boolean;
8
+ getBuiltLeaf: (built: unknown) => AnyLeafLowProfile;
9
+ encodeLeafKey: (leaf: AnyLeafLowProfile) => string;
10
+ toArgsTuple: (args: unknown) => unknown[];
11
+ };
12
+ export declare function buildBatchBranch<T extends BuiltLeafMap>(leaves: T, options: BranchBuildOptions, deps: BuildBatchBranchDeps): BuiltBranch<T>;
13
+ export {};
@@ -2,4 +2,4 @@ import type { EventMap, SocketConnectionConfigOutput } from '@emeryld/rrroutes-c
2
2
  import * as React from 'react';
3
3
  import { SocketClient } from './socket.client.core';
4
4
  export declare const SocketCtx: React.Context<SocketClient<any, SocketConnectionConfigOutput> | null>;
5
- export declare function useSocketClient<T extends EventMap, C extends SocketConnectionConfigOutput>(): SocketClient<T, C>;
5
+ export declare function useSocketClient<T extends EventMap, C extends SocketConnectionConfigOutput>(): SocketClient<T, C> | null;
@@ -5,7 +5,7 @@ export type UseSocketConnectionArgs<T extends EventMap, K extends keyof T & stri
5
5
  event: K;
6
6
  rooms?: Rooms;
7
7
  onMessage: (payload: Payload<T, K>, meta?: {
8
- envelope: ServerEnvelope<T, K>;
8
+ envelope: ServerEnvelope<T[K]['__out']>;
9
9
  ctx: ClientCtx;
10
10
  }) => void;
11
11
  onCleanup?: () => void;
@@ -36,7 +36,7 @@ export declare function buildSocketProvider<T extends EventMap, C extends Socket
36
36
  fallback?: React.ReactNode;
37
37
  destroyLeaveMeta: SocketSchemaOutput<C["leaveMetaMessage"]>;
38
38
  }>) => import("react/jsx-runtime").JSX.Element;
39
- useSocketClient: () => SocketClient<T, C>;
39
+ useSocketClient: () => SocketClient<T, C> | null;
40
40
  useSocketConnection: <K extends keyof T & string>(p: UseSocketConnectionArgs<T, K, C>) => void;
41
41
  };
42
42
  export {};
@@ -1,11 +1,11 @@
1
1
  import type { EventMap, Payload, SocketConnectionConfigOutput, SocketSchemaOutput } from '@emeryld/rrroutes-contract';
2
2
  import { SocketClientDebugEvent } from './socket.client.debug';
3
3
  import type { MaybeSocket, SysEventMap } from './socket.client.sys';
4
- export type ServerEnvelope<T extends EventMap, K extends keyof T & string> = {
5
- eventName: K;
4
+ export type ServerEnvelope<Payload> = {
5
+ eventName: string;
6
6
  sentAt: string | Date;
7
7
  sentTo: string[];
8
- data?: Payload<T, K>;
8
+ data?: Payload;
9
9
  metadata?: Record<string, unknown>;
10
10
  rooms: string[];
11
11
  };
@@ -115,8 +115,8 @@ export declare class SocketClient<T extends EventMap, C extends SocketConnection
115
115
  emit<K extends keyof T & string>(event: K, payload: Payload<T, K>, metadata?: Record<string, unknown>): void;
116
116
  joinRooms(rooms: string[] | string, meta: SocketSchemaOutput<C['joinMetaMessage']>): Promise<() => Promise<void>>;
117
117
  leaveRooms(rooms: string[] | string, meta: SocketSchemaOutput<C['leaveMetaMessage']>): Promise<void>;
118
- on<K extends keyof T & string>(event: K, handler: (payload: Payload<T, K>, meta?: {
119
- envelope: ServerEnvelope<T, K>;
118
+ on<K extends keyof T & string>(event: K, handler: (payload: T[K]['__out'], meta?: {
119
+ envelope: ServerEnvelope<T[K]['__out']>;
120
120
  ctx: ClientCtx;
121
121
  }) => void): () => void;
122
122
  /**
@@ -1,5 +1,5 @@
1
1
  import type { AnyLeafLowProfile, InferOutput, SocketConnectionConfigOutput, SocketSchemaOutput } from '@emeryld/rrroutes-contract';
2
- import type { DataShape } from '../../routesV3.client.types';
2
+ import type { ArgsFor, DataShape } from '../../routesV3.client.types';
3
3
  export type RoomsInput = string | string[] | undefined | null;
4
4
  export type RoomState<C extends SocketConnectionConfigOutput> = {
5
5
  rooms: string[];
@@ -11,7 +11,7 @@ export type ToRoomsResult<C extends SocketConnectionConfigOutput> = {
11
11
  joinMeta: SocketSchemaOutput<C['joinMetaMessage']>;
12
12
  leaveMeta: SocketSchemaOutput<C['leaveMetaMessage']>;
13
13
  };
14
- export type ToRoomsMapper<L extends AnyLeafLowProfile, C extends SocketConnectionConfigOutput> = (data: InferOutput<L>) => ToRoomsResult<C>;
14
+ export type ToRoomsMapper<L extends AnyLeafLowProfile, C extends SocketConnectionConfigOutput> = (data: InferOutput<L>, args: ArgsFor<L> | undefined) => ToRoomsResult<C>;
15
15
  export declare function roomStateEqual<C extends SocketConnectionConfigOutput>(prev: RoomState<C>, next: RoomState<C>): boolean;
16
16
  export declare function mergeRoomState<L extends AnyLeafLowProfile, C extends SocketConnectionConfigOutput>(prev: RoomState<C>, toRoomsResult: ToRoomsResult<C>): RoomState<C>;
17
- export declare function roomsFromData<L extends AnyLeafLowProfile, C extends SocketConnectionConfigOutput>(data: DataShape<L> | undefined, toRooms: ToRoomsMapper<L, C>): RoomState<C>;
17
+ export declare function roomsFromData<L extends AnyLeafLowProfile, C extends SocketConnectionConfigOutput>(data: DataShape<L> | undefined, args: ArgsFor<L> | undefined, toRooms: ToRoomsMapper<L, C>): RoomState<C>;
@@ -1,4 +1,4 @@
1
- import type { AnyLeafLowProfile, EventMap, Payload, SocketConnectionConfigOutput } from '@emeryld/rrroutes-contract';
1
+ import type { AnyLeafLowProfile, EventMap, SocketConnectionConfigOutput, SocketEvent } from '@emeryld/rrroutes-contract';
2
2
  import type { BuiltInfinite, BuiltQuery, DataShape, InfiniteUseEndpointResultFor, QueryUseEndpointResultFor, UseEndpointArgs } from '../../routesV3.client.types';
3
3
  import type { ClientCtx, ServerEnvelope, SocketClient } from '../socket.client.core';
4
4
  import { type SocketedRouteDebugOptions } from './socket.client.helper.debug';
@@ -7,6 +7,15 @@ export type SocketedBuilt<L extends AnyLeafLowProfile> = L['cfg']['feed'] extend
7
7
  export type SocketedRouteResult<L extends AnyLeafLowProfile> = (L['cfg']['feed'] extends true ? InfiniteUseEndpointResultFor<L> : QueryUseEndpointResultFor<L>) & {
8
8
  rooms: string[];
9
9
  };
10
+ export type ApplySocket<L extends AnyLeafLowProfile, S extends SocketEvent> = (args: {
11
+ prev: DataShape<L> | undefined;
12
+ payload: S['__out'];
13
+ meta: {
14
+ envelope?: ServerEnvelope<S['__out']>;
15
+ ctx?: ClientCtx;
16
+ args: UseEndpointArgs<L>;
17
+ };
18
+ }) => DataShape<L> | undefined | null;
10
19
  export type SocketedRouteOptions<L extends AnyLeafLowProfile, Events extends EventMap, C extends SocketConnectionConfigOutput> = {
11
20
  /** The built route to compose with socket wiring. This should be a route built with the `buildRoute` function */
12
21
  built: SocketedBuilt<L>;
@@ -14,14 +23,10 @@ export type SocketedRouteOptions<L extends AnyLeafLowProfile, Events extends Eve
14
23
  toRooms: ToRoomsMapper<L, C>;
15
24
  /** An object mapping socket event names to functions that apply incoming socket messages to the endpoint data. Each function receives the previous data, the socket message payload, and an optional meta object containing the server envelope and client context. The function should return the new data (new referrence), or null to indicate no change. */
16
25
  applySocket: {
17
- [K in keyof Events & string]?: (prev: DataShape<L> | undefined, payload: Payload<Events, K>, meta: {
18
- envelope?: ServerEnvelope<Events, keyof Events & string>;
19
- ctx?: ClientCtx;
20
- args: UseEndpointArgs<L>;
21
- }) => DataShape<L> | undefined | null;
26
+ [K in keyof Events & string]?: ApplySocket<L, Events[K]>;
22
27
  };
23
28
  /** A hook that returns the SocketClient instance. This is required to access the socket client within the route and apply socket messages. */
24
- useSocketClient: () => SocketClient<Events, C>;
29
+ useSocketClient: () => SocketClient<Events, C> | null;
25
30
  /** Debug options for the socketed route. This is optional and can be used to enable debug logging for the route's internal operations, such as room joining and socket message application.
26
31
  * client: Logs when the socket client becomes available or unavailable.
27
32
  * render: Logs on each render of the route, including whether the client is available and the current rooms.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emeryld/rrroutes-client",
3
- "version": "2.6.10",
3
+ "version": "2.6.12",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",