@emeryld/rrroutes-client 2.1.12 → 2.2.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/index.cjs +73 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +72 -0
- package/dist/index.mjs.map +1 -1
- package/dist/routesV3.client.types.d.ts +1 -1
- package/dist/sockets/socket.client.index.d.ts +1 -0
- package/dist/sockets/socketedRoute/socket.client.helper.d.ts +52 -0
- package/package.json +1 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { AnyLeaf, InferOutput, EventMap as ContractEventMap, SocketConnectionConfig, SocketSchemaOutput, Payload } from '@emeryld/rrroutes-contract';
|
|
2
|
+
import type { BuildMeta, BuildOptionsFor, ArgsFor, DataShape, InfiniteUseEndpointOptionsFor, RouterBuilder } from '../../routesV3.client.types';
|
|
3
|
+
import type { ClientCtx, ServerEnvelope, SocketClient } from '../socket.client.index';
|
|
4
|
+
/** Narrow to feed-style GET leaves so `data.pages` is always present. */
|
|
5
|
+
type FeedLeaf = AnyLeaf & {
|
|
6
|
+
method: 'get';
|
|
7
|
+
cfg: {
|
|
8
|
+
feed: true;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
type PageOf<L extends FeedLeaf> = InferOutput<L>;
|
|
12
|
+
type SocketedHandlers<L extends FeedLeaf, E extends ContractEventMap, K extends keyof E & string, C extends SocketConnectionConfig> = {
|
|
13
|
+
/**
|
|
14
|
+
* Derive the full set of rooms to join based on a newly received page plus
|
|
15
|
+
* the current active room list. Return the complete desired list (not a delta).
|
|
16
|
+
*/
|
|
17
|
+
onReceiveRooms?: (page: PageOf<L>, activeRooms: string[]) => string[];
|
|
18
|
+
/**
|
|
19
|
+
* Update the cached route data when a socket message arrives.
|
|
20
|
+
* Return the next cache value (or undefined to keep it unchanged).
|
|
21
|
+
*/
|
|
22
|
+
handleMessage: (prev: DataShape<L> | undefined, payload: Payload<E, K>, meta: {
|
|
23
|
+
envelope: ServerEnvelope<E, K>;
|
|
24
|
+
ctx: ClientCtx;
|
|
25
|
+
}) => DataShape<L> | undefined;
|
|
26
|
+
/** Meta payloads for join/leave messages. */
|
|
27
|
+
joinMeta: SocketSchemaOutput<C['joinMetaMessage']>;
|
|
28
|
+
leaveMeta: SocketSchemaOutput<C['leaveMetaMessage']>;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Build a hook that wires an infinite GET route to a socket event:
|
|
32
|
+
* - Keeps React Query cache in sync when socket messages arrive.
|
|
33
|
+
* - Derives and joins rooms from the route’s feed pages.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createSocketedRouteHook<Routes extends Record<PropertyKey, FeedLeaf>, Names extends string, Events extends ContractEventMap, C extends SocketConnectionConfig>(args: {
|
|
36
|
+
buildRoute: RouterBuilder<Routes, Names>;
|
|
37
|
+
useClient?: () => SocketClient<Events, C>;
|
|
38
|
+
}): <K extends keyof Routes, Ev extends keyof Events & string>(params: {
|
|
39
|
+
routeKey: K;
|
|
40
|
+
socketEvent: Ev;
|
|
41
|
+
handlers: SocketedHandlers<Routes[K], Events, Ev, C>;
|
|
42
|
+
buildOptions?: BuildOptionsFor<Routes[K]>;
|
|
43
|
+
buildMeta?: BuildMeta<Names>;
|
|
44
|
+
useOptions?: {
|
|
45
|
+
args?: ArgsFor<Routes[K]>;
|
|
46
|
+
options?: InfiniteUseEndpointOptionsFor<Routes[K]>;
|
|
47
|
+
};
|
|
48
|
+
}) => {
|
|
49
|
+
data: import("@tanstack/react-query").InfiniteData<InferOutput<Routes[K]>, unknown> | undefined;
|
|
50
|
+
rooms: string[];
|
|
51
|
+
};
|
|
52
|
+
export {};
|