• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nestjs / nest / ec6d52bd-26c3-40b0-a37f-98f0df3fe2c6

04 Aug 2025 08:02AM UTC coverage: 88.916% (+0.003%) from 88.913%
ec6d52bd-26c3-40b0-a37f-98f0df3fe2c6

Pull #15488

circleci

lifefloating
feat(ws): enhance optimized/dynamic path matching for websocket routes
Pull Request #15488: feat(ws): Support for dynamic path params in websocket, add tests

2744 of 3463 branches covered (79.24%)

10 of 11 new or added lines in 4 files covered. (90.91%)

7292 of 8201 relevant lines covered (88.92%)

16.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/packages/websockets/decorators/ws-param.decorator.ts
1
import { PipeTransform, Type } from '@nestjs/common';
2
import { WsParamtype } from '../enums/ws-paramtype.enum';
1✔
3
import { createPipesWsParamDecorator } from '../utils/param.utils';
1✔
4

5
/**
6
 * WebSocket parameter decorator. Extracts path parameters from the WebSocket URL.
7
 *
8
 * Use this decorator to inject path parameter values from dynamic WebSocket URLs.
9
 * Path parameters are defined in the WebSocket gateway path configuration using
10
 * the same syntax as HTTP controllers (e.g., `:id`, `:userId`).
11
 *
12
 * @example
13
 * ```typescript
14
 * @WebSocketGateway({ path: '/chat/:roomId/socket' })
15
 * export class ChatGateway {
16
 *   @SubscribeMessage('message')
17
 *   handleMessage(
18
 *     @ConnectedSocket() client: WebSocket,
19
 *     @MessageBody() data: any,
20
 *     @WsParam('roomId') roomId: string,
21
 *   ) {
22
 *     // roomId is automatically extracted from the WebSocket URL
23
 *     console.log(`Message received in room: ${roomId}`);
24
 *   }
25
 * }
26
 * ```
27
 *
28
 * @param property - The name of the path parameter to extract (optional)
29
 * @param pipes - Optional transformation/validation pipes
30
 * @returns ParameterDecorator
31
 *
32
 * @publicApi
33
 */
34
export function WsParam(
35
  property?: string,
36
  ...pipes: (Type<PipeTransform> | PipeTransform)[]
37
): ParameterDecorator;
38

39
/**
40
 * WebSocket parameter decorator without property name.
41
 * Returns all path parameters as an object.
42
 *
43
 * @param pipes - Optional transformation/validation pipes
44
 * @returns ParameterDecorator
45
 *
46
 * @publicApi
47
 */
48
export function WsParam(
49
  ...pipes: (Type<PipeTransform> | PipeTransform)[]
50
): ParameterDecorator;
51

52
/**
53
 * Implementation of the WsParam decorator
54
 */
55
export function WsParam(
1✔
56
  property?: string | (Type<PipeTransform> | PipeTransform),
57
  ...pipes: (Type<PipeTransform> | PipeTransform)[]
58
): ParameterDecorator {
NEW
59
  return createPipesWsParamDecorator(WsParamtype.PARAM)(property, ...pipes);
×
60
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc