-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
stream: implement fetch body mixin on Readable #39520
Conversation
ad42494
to
bdc3d17
Compare
Not sure if adding properties on core classes should be semver-major? |
Will work on test if there is positive feedback on this approach. |
bdc3d17
to
dccc0e7
Compare
This comment has been minimized.
This comment has been minimized.
9e6a765
to
80db7ac
Compare
@nodejs/streams |
e101b1d
to
e038fba
Compare
Any ideas on how to get around this?
@lpinca @jasnell @mcollina @dnlup https://github.com/visionmedia/superagent/blob/master/src/node/response.js#L36 |
The express stuff can be workaround through, but the superagent issue is maybe more difficult... https://github.com/visionmedia/superagent/blob/master/src/node/response.js#L36 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is doable without massive ecosystem breakage. We need also to consider Duplex
inherit from Readable
, and therefore it will inherit a .json()
method. However express
provides a res.json()
method, which will quickly get confused with this.
I think we are better off with a separate class, or some other utility Readable.toFetchBody(readable).json()
or readable.toFetchBody().json()
.
That kind of kills the use case for me. Can we put it behind a flag passed to the constructor which is disabled by default? |
This means that most Node.js core object would not have those. I'm not sure that's what you would like achieve either. |
Port over PR from node core. It will not be possible to land these changes on core due to ecosystem breakage. Refs: nodejs/node#39520
We wanted to support body mixin in undici |
Taking another look at this I believe this can actually live outside of core (at least for my intended use case). nodejs/undici#907 |
Given the issue described in #39543, can we at least keep |
I'm closing this. It's not possible to do it this way due ecosystem conflicts. If someone wants to pick it up in some other form feel free to branch off this or create an issue for discussion. I'm moving over to extending Readable in user land where needed. nodejs/undici#907 |
If I may give my feedback on this. I am sad that this is closed partially due to an outdated framework/library ( There are no reason not to add this feature inside the core, especially if it is part of a major release (meaning their will be breaking changes). Libraries and frameworks need to adapt. It is not the role of Node.js to be adjusted. Everyone knows that patching/modifying core/native objects is a very bad practice. We should not rely on people who are doing that to keep us from improving Node.js core. |
* stream: implement body mixin on Readable Port over PR from node core. It will not be possible to land these changes on core due to ecosystem breakage. Refs: nodejs/node#39520 * fixup: tests * fixup * fixup * fixuP * fixuP * fixup: remove node specific stuff * fixup: formData * fixup: simplify * fixup * fixup * fixup * fixup: README * fixup
I see (and appreciate) the sentiment but that's not the sort of burden of responsibility Node.js has. Express is used by millions of projects and we can't just break it. What about a |
I'm good with either. |
@benjamingr something like 1b7f509? |
@ronag exactly :) |
Then different kinds of streams can opt-into this by default (so http IncomingRequest stream won't be able to by default but http.get might etc) |
This will make the API even harder to learn/use for folks. |
What do you suggest instead? |
Could there just be a module of stream consumers? import { asJson } from 'stream-readers';
const data = await asJson(stream); I might be missing some context around this PR. |
|
* stream: implement body mixin on Readable Port over PR from node core. It will not be possible to land these changes on core due to ecosystem breakage. Refs: nodejs/node#39520 * fixup: tests * fixup * fixup * fixuP * fixuP * fixup: remove node specific stuff * fixup: formData * fixup: simplify * fixup * fixup * fixup * fixup: README * fixup
* stream: implement body mixin on Readable Port over PR from node core. It will not be possible to land these changes on core due to ecosystem breakage. Refs: nodejs/node#39520 * fixup: tests * fixup * fixup * fixuP * fixuP * fixup: remove node specific stuff * fixup: formData * fixup: simplify * fixup * fixup * fixup * fixup: README * fixup
Make Readable expose the fetch boxy mixin API.
Bypasses webstream glue when possible.
This also makes conversion to webstream faster when the stream is not consumed through
Readable
by bypassing much of theReadable
logic.Refs: https://fetch.spec.whatwg.org/#body-mixin