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
Allow Compatible Subscribe Decorators To Contain Extra Data #510
Conversation
Looks like there's an error with the new test added:
Unfortunately I'm not sure how to fix this one, as my TypeScript skills are still in their infancy. I would guess that |
🎉 took a stab and it looks like it passes! |
Hi @shellscape, The idea behind this pull request is truly understandable for sure. At the moment, I'm working on |
@kamilmysliwiec I can certainly understand the time concerns. Please do understand that this is currently blocking our entire company from using Nest as it currently is. While the 5.0.0 release is no doubt very important, publishing a patch release with this improvement would be much appreciated, even if it is temporary with the changes coming down the pipe with 5.0.0. |
Work issues aside, this particular path from one maintainer to another doesn't seem terribly useful as an individual consumer. The current websockets implementation doesn't let you fully leverage The former is benign to anyone using the existing major version range unless they explicitly create a new websockets module that leverages the ability to add additional channel data. The latter on the other hand needs to be finished, then published & then stabilize before the work to update all of our existing services can even begin with all of that assuming the use case is covered in 5.x which means there is a very real chance we are back here having this discussion again two months from now. |
Hmm.. @d3viant0ne @shellscape Just wondering. Why cannot you use just export const SubscribeWsMessage = (channel: string, message: string) => SubscribeMessage({ channel, message } as any); Maybe there're some obstacles that I'm not seeing at the moment(? thinking about clean temporary solution). |
This may be my inexperience with TypeScript, but doesn't this line
|
In this case, it is only additional typing added to increase developer experience. As far as I know, casting to |
I'm not a huge fan of allowing |
I hope that this workaround is fine so far @d3viant0ne @shellscape. Inspired by this pull request, I'm gonna introduce a small enhancement in the nearest release that should simplify using any other ws library and make it much less painful. Thanks @shellscape 🔥 Also, I hope you have not given up with this Ws module! |
thanks @kamilmysliwiec. haven't given up at all! just need to get it published. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This PR proposes to add the ability for both the metadata explorer and the websocket controller to allow custom, compatible
SubscribeMessage
variant decorators additional metadata.Targeted Problem
Both
WebSocketsController
andGatewayMetadataExplorer
are locked into a single-use paradigm: they assume that a subscribe decorator will never provide more data than the message name (aka type). This means that decorators which seek to extend functionality are locked into an inflexible paradigm, making extending such decorators with additional metadata extremely difficult.Use Case
We're currently developing a robust adapter for
ws
. Thews
module differs fromsocket.io
in several ways. One such way is the notable absence of "namespaces," which inws
can be handled simply by filtering and inspecting thepathname
of a connected childWebSocket
.Consider the following decorator:
It's compatible with
SubscribeMessage
and adds additionalchannel
data. This data will then be used byWsAdapter
to filter childWebSocket
connections, and subsequently only make calls to the associated callback(s) if the client sending a message happens to be on a particular channel.The merits of our approach could surely be debated, there may even be better ways to go about this. However, the core issue remains - modifying the code to allow extra metadata to be passed along in
handlers
is a small cost for a large win for extensibility.