You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Socket service supports real-time communication using decorators like @Input, @Emit, and @Args. These decorators are used to define the structure and flow of data during communication with the WebSocket. However, there is a limitation when it comes to handling model serialization, specifically when using the @Emit decorator.
Developers will no longer need to manually handle the serialization of complex data models when using the @Emit decorator. The proposed feature will handle the serialization process based on the provided serialization
Example
We propose adding support for model serialization using the @Emit decorator or by inferring the return type of the method decorated by it.
Using @Emit with explicitly supplied type:
@SocketService("/nsp")exportclassMyWS{
@Input("event")
@Emit("returnEvent",PersonModel)// The second parameter specifies the class to be used for serialization.asyncmyMethod(): Promise<PersonModel>{return{firstName: 'Bob',lastName: 'Diamond'};}}
Using @Emit with Automatic Inference of Return Type:
@SocketService("/nsp")exportclassMyWS{
@Input("event")
@Emit("returnEvent")// The return type of the method will be used to automatically infer the serialization class (PersonModel in this case).asyncmyMethod(): Promise<PersonModel>{return{firstName: 'Bob',lastName: 'Diamond'};}}
This approach should ensure consistency with the @Args decorator, which already allows developers to specify input data structures.
The text was updated successfully, but these errors were encountered:
@derevnjuk I wanted to completely re-use the package code to reuse the @tsed/schema package as much as possible but I didn't have the time. so it's no longer really relevant.
All of stuff described above probably require a huge refactoring of the @tsed/socketio package while is it most simple to create a new package (but maybe I'm wrong now). The problem with this version, is that it doesn't use the @tsed/schema API. It uses its own metadata as you can see. I would have liked to start by migrating the custom metadata to use the JsonEntityStore (@tsed/schema).
If you are motivated to implement these feature, let's Go :)
Information
The Socket service supports real-time communication using decorators like
@Input
,@Emit
, and@Args
. These decorators are used to define the structure and flow of data during communication with the WebSocket. However, there is a limitation when it comes to handling model serialization, specifically when using the@Emit
decorator.Developers will no longer need to manually handle the serialization of complex data models when using the
@Emit
decorator. The proposed feature will handle the serialization process based on the provided serializationExample
We propose adding support for model serialization using the
@Emit
decorator or by inferring the return type of the method decorated by it.Using
@Emit
with explicitly supplied type:Using
@Emit
with Automatic Inference of Return Type:This approach should ensure consistency with the
@Args
decorator, which already allows developers to specify input data structures.The text was updated successfully, but these errors were encountered: