@emeryld/rrroutes-client 2.6.0 → 2.6.2

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.
@@ -1,7 +1,7 @@
1
+ import { EventMap, Payload, SocketConnectionConfigOutput, SocketSchemaOutput } from '@emeryld/rrroutes-contract';
1
2
  import * as React from 'react';
2
3
  import { Socket } from 'socket.io-client';
3
- import { SocketClient, SocketClientOptions, ClientCtx, ServerEnvelope } from './socket.client.index';
4
- import { EventMap, SocketConnectionConfigOutput, Payload, SocketSchemaOutput } from '@emeryld/rrroutes-contract';
4
+ import { ClientCtx, ServerEnvelope, SocketClient, SocketClientOptions } from './socket.client.index';
5
5
  /** === Provider-side debug === */
6
6
  type HookDebugReason = 'init' | 'change';
7
7
  type HookDebugValue = string | number | boolean | null | undefined;
@@ -57,7 +57,7 @@ type Rooms = string[] | string | undefined;
57
57
  export type UseSocketConnectionArgs<T extends EventMap, K extends keyof T & string, C extends SocketConnectionConfigOutput> = {
58
58
  event: K;
59
59
  rooms?: Rooms;
60
- onMessage: (payload: Payload<T, K>, meta: {
60
+ onMessage: (payload: Payload<T, K>, meta?: {
61
61
  envelope: ServerEnvelope<T, K>;
62
62
  ctx: ClientCtx;
63
63
  }) => void;
@@ -7,13 +7,13 @@ export type ServerEnvelope<T extends EventMap, K extends keyof T & string> = {
7
7
  sentTo: string[];
8
8
  data?: Payload<T, K>;
9
9
  metadata?: Record<string, unknown>;
10
+ rooms: string[];
10
11
  };
11
12
  export type ClientCtx = {
12
13
  receivedAt: Date;
13
14
  latencyMs?: number;
14
15
  nsp?: string;
15
16
  socketId?: string;
16
- rooms?: string[];
17
17
  socket?: MaybeSocket;
18
18
  reply?: (data?: unknown) => void;
19
19
  };
@@ -101,7 +101,7 @@ export declare class SocketClient<T extends EventMap, C extends SocketConnection
101
101
  emit<K extends keyof T & string>(event: K, payload: Payload<T, K>, metadata?: Record<string, unknown>): void;
102
102
  joinRooms(rooms: string[] | string, meta: SocketSchemaOutput<C['joinMetaMessage']>): Promise<() => Promise<void>>;
103
103
  leaveRooms(rooms: string[] | string, meta: SocketSchemaOutput<C['leaveMetaMessage']>): Promise<void>;
104
- on<K extends keyof T & string>(event: K, handler: (payload: Payload<T, K>, meta: {
104
+ on<K extends keyof T & string>(event: K, handler: (payload: Payload<T, K>, meta?: {
105
105
  envelope: ServerEnvelope<T, K>;
106
106
  ctx: ClientCtx;
107
107
  }) => void): () => void;
@@ -2,6 +2,42 @@ import type { AnyLeafLowProfile, EventMap, InferOutput, Payload, SocketConnectio
2
2
  import type { BuiltInfinite, BuiltQuery, DataShape, InfiniteUseEndpointResultFor, QueryUseEndpointResultFor, UseEndpointArgs } from '../../routesV3.client.types';
3
3
  import type { ClientCtx, ServerEnvelope, SocketClient } from '../socket.client.index';
4
4
  type RoomsInput = string | string[] | undefined | null;
5
+ type HookDebugReason = 'init' | 'change';
6
+ type HookDebugValue = string | number | boolean | null | undefined;
7
+ export type SocketedRouteDebugEvent = {
8
+ type: 'client';
9
+ phase: 'ready' | 'missing';
10
+ err?: string;
11
+ } | {
12
+ type: 'render';
13
+ renderCount: number;
14
+ hasClient: boolean;
15
+ argsKey: string;
16
+ rooms: string[];
17
+ roomsKey: string;
18
+ joinMetaKey: string;
19
+ leaveMetaKey: string;
20
+ } | {
21
+ type: 'hook';
22
+ phase: 'endpoint_on_receive_effect' | 'derive_rooms_effect' | 'join_rooms_effect' | 'apply_socket_effect';
23
+ reason: HookDebugReason;
24
+ changes: Array<{
25
+ dependency: string;
26
+ previous: HookDebugValue;
27
+ next: HookDebugValue;
28
+ }>;
29
+ } | {
30
+ type: 'room';
31
+ phase: 'join_attempt' | 'join_skip' | 'join_error' | 'leave_attempt' | 'leave_skip' | 'leave_error';
32
+ rooms: string[];
33
+ reason?: string;
34
+ err?: string;
35
+ };
36
+ export type SocketedRouteDebugOptions = {
37
+ logger?: (event: SocketedRouteDebugEvent) => void;
38
+ } & {
39
+ [P in SocketedRouteDebugEvent['type']]?: boolean;
40
+ };
5
41
  type SocketedBuilt<L extends AnyLeafLowProfile> = L['cfg']['feed'] extends true ? BuiltInfinite<L> : BuiltQuery<L>;
6
42
  type SocketedRouteResult<L extends AnyLeafLowProfile> = (L['cfg']['feed'] extends true ? InfiniteUseEndpointResultFor<L> : QueryUseEndpointResultFor<L>) & {
7
43
  rooms: string[];
@@ -15,11 +51,13 @@ export type SocketedRouteOptions<L extends AnyLeafLowProfile, Events extends Eve
15
51
  };
16
52
  applySocket: {
17
53
  [K in keyof Events & string]?: (prev: DataShape<L> | undefined, payload: Payload<Events, K>, meta: {
18
- envelope: ServerEnvelope<Events, K>;
19
- ctx: ClientCtx;
54
+ envelope?: ServerEnvelope<Events, keyof Events & string>;
55
+ ctx?: ClientCtx;
56
+ args: UseEndpointArgs<L>;
20
57
  }) => DataShape<L> | undefined;
21
58
  };
22
59
  useSocketClient: () => SocketClient<Events, C>;
60
+ debug?: SocketedRouteDebugOptions;
23
61
  };
24
62
  /**
25
63
  * Compose a GET endpoint with socket wiring:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emeryld/rrroutes-client",
3
- "version": "2.6.0",
3
+ "version": "2.6.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",