@emeryld/rrroutes-client 2.2.5 → 2.2.7
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 +0 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +0 -91
- package/dist/index.mjs.map +1 -1
- package/dist/routesV3.client.types.d.ts +12 -11
- package/dist/sockets/socket.client.context.d.ts +6 -6
- package/dist/sockets/socket.client.index.d.ts +3 -4
- package/dist/sockets/socket.client.sys.d.ts +2 -2
- package/package.json +2 -2
- package/dist/sockets/socketedRoute/socket.client.helper.d.ts +0 -54
|
@@ -103,11 +103,11 @@ type QueryOf<L extends AnyLeaf> = InferQuery<L>;
|
|
|
103
103
|
type BodyOf<L extends AnyLeaf> = InferBody<L>;
|
|
104
104
|
type OnReceive<L extends AnyLeaf> = (data: OutputOf<L>) => void;
|
|
105
105
|
/** Variadic args consumed by the direct fetch helper: optional args + body. */
|
|
106
|
-
export type MutationFetchArgs<L extends AnyLeaf> = [...ArgsTuple<L>, BodyOf<L>]
|
|
106
|
+
export type MutationFetchArgs<L extends AnyLeaf> = Prettify<[...ArgsTuple<L>, BodyOf<L>]>;
|
|
107
107
|
/** Signature for the fetch helper returned by mutation builds. */
|
|
108
108
|
export type MutationFetcher<L extends AnyLeaf> = (...args: MutationFetchArgs<L>) => Promise<OutputOf<L>>;
|
|
109
109
|
/** Fetch args for GET endpoints (optionally include a body when a schema exists). */
|
|
110
|
-
type QueryFetchArgs<L extends AnyLeaf> = BodyOf<L> extends never ? ArgsTuple<L> : ArgsTuple<L> | [...ArgsTuple<L>, BodyOf<L>]
|
|
110
|
+
type QueryFetchArgs<L extends AnyLeaf> = BodyOf<L> extends never ? ArgsTuple<L> : Prettify<ArgsTuple<L> | [...ArgsTuple<L>, BodyOf<L>]>;
|
|
111
111
|
/** Optional metadata provided when building a helper (used for debug filtering). */
|
|
112
112
|
export type BuildMeta<Names extends string = string> = {
|
|
113
113
|
/**
|
|
@@ -117,11 +117,11 @@ export type BuildMeta<Names extends string = string> = {
|
|
|
117
117
|
name?: Names;
|
|
118
118
|
};
|
|
119
119
|
/** Object shape the user passes to hooks and helpers (params/query are optional). */
|
|
120
|
-
export type ArgsFor<L extends AnyLeaf> = (ParamsOf<L> extends never ? {} : {
|
|
120
|
+
export type ArgsFor<L extends AnyLeaf> = Prettify<(ParamsOf<L> extends never ? {} : {
|
|
121
121
|
params: ParamsOf<L>;
|
|
122
122
|
}) & (QueryOf<L> extends never ? {} : {
|
|
123
123
|
query: QueryOf<L>;
|
|
124
|
-
})
|
|
124
|
+
})>;
|
|
125
125
|
/** Variadic tuple representation that omits the argument entirely when not needed. */
|
|
126
126
|
export type ArgsTuple<L extends AnyLeaf> = keyof ArgsFor<L> extends never ? [] : [args: ArgsFor<L>];
|
|
127
127
|
/** Cache data shape for setData(...) */
|
|
@@ -130,6 +130,7 @@ type ArgsFromTuple<L extends AnyLeaf, T extends ArgsTuple<L>> = T extends [infer
|
|
|
130
130
|
type ParamsFromArgs<L extends AnyLeaf, T extends ArgsTuple<L>> = ArgsFromTuple<L, T> extends {
|
|
131
131
|
params: infer P;
|
|
132
132
|
} ? P : undefined;
|
|
133
|
+
type SetDataArgs<L extends AnyLeaf> = Prettify<[updater: Updater<DataShape<L>>, ...ArgsTuple<L>]>;
|
|
133
134
|
type QueryFromArgs<L extends AnyLeaf, T extends ArgsTuple<L>> = ArgsFromTuple<L, T> extends {
|
|
134
135
|
query: infer Q;
|
|
135
136
|
} ? Q : undefined;
|
|
@@ -161,13 +162,13 @@ export type MutationBuildOptionsFor<L extends AnyLeaf> = Omit<UseMutationOptions
|
|
|
161
162
|
};
|
|
162
163
|
/** Build options narrowed to the method/feed shape of the leaf. */
|
|
163
164
|
export type BuildOptionsFor<L extends AnyLeaf> = L['method'] extends 'get' ? L['cfg']['feed'] extends true ? InfiniteBuildOptionsFor<L> : QueryBuildOptionsFor<L> : MutationBuildOptionsFor<L>;
|
|
164
|
-
type UseEndpointOptionsFor<L extends AnyLeaf> = {
|
|
165
|
+
type UseEndpointOptionsFor<L extends AnyLeaf> = Prettify<{
|
|
165
166
|
onReceive?: OnReceive<L>;
|
|
166
|
-
}
|
|
167
|
-
export type UseEndpointArgs<L extends AnyLeaf, O> = keyof ArgsFor<L> extends never ? [options?: O] : [args: ArgsFor<L>, options?: O];
|
|
168
|
-
export type QueryUseEndpointOptionsFor<L extends AnyLeaf> = UseEndpointOptionsFor<L
|
|
169
|
-
export type InfiniteUseEndpointOptionsFor<L extends AnyLeaf> = UseEndpointOptionsFor<L
|
|
170
|
-
export type MutationUseEndpointOptionsFor<L extends AnyLeaf> = UseEndpointOptionsFor<L
|
|
167
|
+
}>;
|
|
168
|
+
export type UseEndpointArgs<L extends AnyLeaf, O> = keyof ArgsFor<L> extends never ? [options?: Prettify<O>] : [args: ArgsFor<L>, options?: Prettify<O>];
|
|
169
|
+
export type QueryUseEndpointOptionsFor<L extends AnyLeaf> = Prettify<UseEndpointOptionsFor<L>>;
|
|
170
|
+
export type InfiniteUseEndpointOptionsFor<L extends AnyLeaf> = Prettify<UseEndpointOptionsFor<L>>;
|
|
171
|
+
export type MutationUseEndpointOptionsFor<L extends AnyLeaf> = Prettify<UseEndpointOptionsFor<L>>;
|
|
171
172
|
/** Shared capabilities exposed by every built endpoint helper. */
|
|
172
173
|
export type BuiltCommon<L extends AnyLeaf> = {
|
|
173
174
|
/**
|
|
@@ -186,7 +187,7 @@ export type BuiltCommon<L extends AnyLeaf> = {
|
|
|
186
187
|
* @param updater New value or function applied to existing cache data.
|
|
187
188
|
* @param rest Optional params/query tuple for the leaf.
|
|
188
189
|
*/
|
|
189
|
-
setData: (...args:
|
|
190
|
+
setData: (...args: SetDataArgs<L>) => DataShape<L> | undefined;
|
|
190
191
|
};
|
|
191
192
|
/** Hook+helpers for a standard GET endpoint. */
|
|
192
193
|
export type BuiltQuery<L extends AnyLeaf> = BuiltCommon<L> & {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Socket } from 'socket.io-client';
|
|
3
3
|
import { SocketClient, SocketClientOptions, ClientCtx, ServerEnvelope } from './socket.client.index';
|
|
4
|
-
import { EventMap,
|
|
4
|
+
import { EventMap, SocketConnectionConfigOutput, Payload, SocketSchemaOutput } from '@emeryld/rrroutes-contract';
|
|
5
5
|
/** === Provider-side debug === */
|
|
6
6
|
type HookDebugReason = 'init' | 'change';
|
|
7
7
|
type HookDebugValue = string | number | boolean | null | undefined;
|
|
@@ -33,13 +33,13 @@ export type SocketProviderDebugOptions = {
|
|
|
33
33
|
[P in SocketProviderDebugEvent['type']]?: boolean;
|
|
34
34
|
};
|
|
35
35
|
/** === Types for runtime socket injection === */
|
|
36
|
-
type BaseOptions<T extends EventMap, C extends
|
|
36
|
+
type BaseOptions<T extends EventMap, C extends SocketConnectionConfigOutput> = Omit<SocketClientOptions<T, C>, 'socket'>;
|
|
37
37
|
type ProviderRuntimeSocket = {
|
|
38
38
|
socket: Socket | null;
|
|
39
39
|
} | {
|
|
40
40
|
getSocket: () => Socket | Promise<Socket>;
|
|
41
41
|
};
|
|
42
|
-
export declare function buildSocketProvider<T extends EventMap, C extends
|
|
42
|
+
export declare function buildSocketProvider<T extends EventMap, C extends SocketConnectionConfigOutput>(args: {
|
|
43
43
|
events: T;
|
|
44
44
|
options: Omit<BaseOptions<T, C>, 'debug'> & {
|
|
45
45
|
debug: BaseOptions<T, C>['debug'] & SocketProviderDebugOptions;
|
|
@@ -52,9 +52,9 @@ export declare function buildSocketProvider<T extends EventMap, C extends Socket
|
|
|
52
52
|
useSocketClient: () => SocketClient<T, C>;
|
|
53
53
|
useSocketConnection: <K extends keyof T & string>(p: Parameters<typeof useSocketConnection<T, K, C>>[0]) => void;
|
|
54
54
|
};
|
|
55
|
-
export declare function useSocketClient<T extends EventMap, C extends
|
|
55
|
+
export declare function useSocketClient<T extends EventMap, C extends SocketConnectionConfigOutput>(): SocketClient<T, C>;
|
|
56
56
|
type Rooms = string[] | string | undefined;
|
|
57
|
-
export type UseSocketConnectionArgs<T extends EventMap, K extends keyof T & string, C extends
|
|
57
|
+
export type UseSocketConnectionArgs<T extends EventMap, K extends keyof T & string, C extends SocketConnectionConfigOutput> = {
|
|
58
58
|
event: K;
|
|
59
59
|
rooms?: Rooms;
|
|
60
60
|
onMessage: (payload: Payload<T, K>, meta: {
|
|
@@ -67,5 +67,5 @@ export type UseSocketConnectionArgs<T extends EventMap, K extends keyof T & stri
|
|
|
67
67
|
joinMeta: SocketSchemaOutput<C['joinMetaMessage']>;
|
|
68
68
|
leaveMeta: SocketSchemaOutput<C['leaveMetaMessage']>;
|
|
69
69
|
};
|
|
70
|
-
export declare function useSocketConnection<T extends EventMap, K extends keyof T & string, C extends
|
|
70
|
+
export declare function useSocketConnection<T extends EventMap, K extends keyof T & string, C extends SocketConnectionConfigOutput>(args: UseSocketConnectionArgs<T, K, C>): void;
|
|
71
71
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EventMap,
|
|
1
|
+
import type { EventMap, SocketConnectionConfigOutput, Payload, SocketSchemaOutput } from '@emeryld/rrroutes-contract';
|
|
2
2
|
import type { MaybeSocket, SysEventMap } from './socket.client.sys';
|
|
3
3
|
import { SocketClientDebugEvent } from './socket.client.debug';
|
|
4
4
|
export type ServerEnvelope<T extends EventMap, K extends keyof T & string> = {
|
|
@@ -43,7 +43,7 @@ export type HeartbeatClientOptions = {
|
|
|
43
43
|
/** Give up waiting for pong after this many ms. Default 7_500. */
|
|
44
44
|
timeoutMs?: number;
|
|
45
45
|
};
|
|
46
|
-
export type SocketClientOptions<T extends EventMap = EventMap, C extends
|
|
46
|
+
export type SocketClientOptions<T extends EventMap = EventMap, C extends SocketConnectionConfigOutput = SocketConnectionConfigOutput> = {
|
|
47
47
|
/** Inject an existing socket.io-client Socket. Can be null while bootstrapping. */
|
|
48
48
|
socket: MaybeSocket;
|
|
49
49
|
config: C;
|
|
@@ -52,7 +52,7 @@ export type SocketClientOptions<T extends EventMap = EventMap, C extends SocketC
|
|
|
52
52
|
heartbeat?: HeartbeatClientOptions;
|
|
53
53
|
sys: SysEventMap<T, C>;
|
|
54
54
|
};
|
|
55
|
-
export declare class SocketClient<T extends EventMap, C extends
|
|
55
|
+
export declare class SocketClient<T extends EventMap, C extends SocketConnectionConfigOutput = SocketConnectionConfigOutput> {
|
|
56
56
|
readonly socket: MaybeSocket;
|
|
57
57
|
private readonly events;
|
|
58
58
|
private readonly environment;
|
|
@@ -116,4 +116,3 @@ export declare class SocketClient<T extends EventMap, C extends SocketConnection
|
|
|
116
116
|
}
|
|
117
117
|
export * from './socket.client.context';
|
|
118
118
|
export * from './socket.client.sys';
|
|
119
|
-
export * from './socketedRoute/socket.client.helper';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Socket } from 'socket.io-client';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import type { EventMap,
|
|
3
|
+
import type { EventMap, SocketConnectionConfigOutput, SocketSchemaOutput } from '@emeryld/rrroutes-contract';
|
|
4
4
|
import { SocketClient } from './socket.client.index';
|
|
5
5
|
export type MaybeSocket = Socket | null;
|
|
6
|
-
export type SysEventMap<T extends EventMap, C extends
|
|
6
|
+
export type SysEventMap<T extends EventMap, C extends SocketConnectionConfigOutput = SocketConnectionConfigOutput> = {
|
|
7
7
|
'sys:connect': (args: {
|
|
8
8
|
socket: Socket;
|
|
9
9
|
client: SocketClient<T, C>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emeryld/rrroutes-client",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@jest/globals": "^30.2.0",
|
|
33
|
-
"@types/react": "^18.3.
|
|
33
|
+
"@types/react": "^18.3.27",
|
|
34
34
|
"@types/react-native": "^0.73.0"
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { AnyLeaf, InferOutput, EventMap as ContractEventMap, SocketSchemaOutput, Payload, SocketConnectionConfigOutput } 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 SocketConnectionConfigOutput> = {
|
|
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
|
-
type GetRoutesOf<R extends Record<PropertyKey, AnyLeaf>> = {
|
|
28
|
-
[K in keyof R as R[K] extends GetLeaf ? K : never]: R[K] extends GetLeaf ? R[K] : never;
|
|
29
|
-
};
|
|
30
|
-
type OptionsForGet<L extends GetLeaf> = L['cfg']['feed'] extends true ? InfiniteUseEndpointOptionsFor<L> : QueryUseEndpointOptionsFor<L>;
|
|
31
|
-
export type SocketedRouteHook<Routes extends Record<PropertyKey, GetLeaf>, Names extends string, Events extends ContractEventMap, C extends SocketConnectionConfigOutput> = <K extends keyof Routes & string, Ev extends keyof Events & string>(params: {
|
|
32
|
-
routeKey: K;
|
|
33
|
-
socketEvent: Ev;
|
|
34
|
-
handlers: SocketedHandlers<Routes[K], Events, Ev, C>;
|
|
35
|
-
buildOptions?: BuildOptionsFor<Routes[K]>;
|
|
36
|
-
buildMeta?: BuildMeta<Names>;
|
|
37
|
-
useOptions?: {
|
|
38
|
-
args?: ArgsFor<Routes[K]>;
|
|
39
|
-
options?: OptionsForGet<Routes[K]>;
|
|
40
|
-
};
|
|
41
|
-
}) => {
|
|
42
|
-
data: DataShape<Routes[K]> | undefined;
|
|
43
|
-
rooms: string[];
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Build a hook that wires a GET route (feed or standard) to a socket event:
|
|
47
|
-
* - Keeps React Query cache in sync when socket messages arrive.
|
|
48
|
-
* - Derives and joins rooms from the route’s responses.
|
|
49
|
-
*/
|
|
50
|
-
export declare function createSocketedRouteHook<Routes extends Record<PropertyKey, AnyLeaf>, Names extends string, Events extends ContractEventMap, C extends SocketConnectionConfigOutput>(args: {
|
|
51
|
-
buildRoute: RouterBuilder<Routes, Names>;
|
|
52
|
-
useClient?: () => SocketClient<Events, C>;
|
|
53
|
-
}): SocketedRouteHook<GetRoutesOf<Routes>, Names, Events, C>;
|
|
54
|
-
export {};
|