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