Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a decorator to handle @MessageBody of NestJS gateways #557

Open
kevpug opened this issue Aug 23, 2023 · 2 comments
Open

Add a decorator to handle @MessageBody of NestJS gateways #557

kevpug opened this issue Aug 23, 2023 · 2 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@kevpug
Copy link

kevpug commented Aug 23, 2023

A decorator for NestJS Gateways

I was about to pull the trigger to replace my entire validation with Nestia/Typia but didn't because I saw there was no gateway @MessageBody decorator replacement.

Would it be possible to add one ?

@samchon
Copy link
Owner

samchon commented Aug 27, 2023

I don't have insight about this subject. Can you explain me more detaily?

In my case, when websocket being required, I used this library instead.

https://tgrid.com/en

@samchon samchon added the help wanted Extra attention is needed label Aug 27, 2023
@samchon samchon self-assigned this Aug 27, 2023
@kevpug
Copy link
Author

kevpug commented Aug 27, 2023

I'm referring to this: NestJS Gateway
In brief, WebSockets in Nest.js utilize Gateways, marked with @WebSocketGateway(), to facilitate real-time communication. Gateways manage incoming messages using decorators such as @SubscribeMessage(). The @MessageBody() decorator extracts data from incoming messages. These gateways can respond in sync or asynchronously, while lifecycle hooks oversee initialization, connections, and disconnections.

Considering that Nestia Core provides access to essential decorators for safeguarding and validating data within controller routes, could it also potentially introduce a new decorator dedicated to NestJS Gateways? Specifically, a decorator that replaces the existing @MessageBody()? @MessageBody

The logic might resemble the TypedBody decorator, but adjusted to throw a WSException instead of the standard HTTP bad request error. Moreover, it would require utilizing something like context.switchToWs().getData() to retrieve and validate the client's message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants