stream: expose stream symbols - #45671
Conversation
|
Review requested:
|
aduh95
left a comment
There was a problem hiding this comment.
If we expose them, we would need to document them. I don't think we want to do that, making symbols part of the public API goes against the idea of using symbols. Can't readable-stream use Reflect.ownKeys or Object.getOwnPropertySymbols to achieve that?
|
How would it do that? I'm not sure how that would work. Especially in a performant way. |
3d26201 to
9b479d6
Compare
const kKey = Symbol('key')
class My { [kKey]() { console.log('hello') }}
const [, symKey] = Reflect.ownKeys(My.prototype)
new My()[symKey]()
// hello |
The symbols are not an a prototype... |
They also work in objects, don't they? const obj = { [Symbol("test")]: 'hey' }
const [symbol] = Reflect.ownKeys(obj)
console.log(obj[symbol]) // heyFor Streams: const str = stream.Readable.from('abc')
const data = Reflect.ownKeys(str)
const kCapture = data[6]
str[kCapture] // false |
|
I still don't see how that will work. Would need to know the static index of the symbol. Which is not possible atm. |
|
This case is similar to |
|
Why don't we use a regular string key to expose these values like what was done in the case of |
|
@nodejs/streams some reviews? |
|
@mcollina We will need this in readable-stream for proper interop. |
|
Adding the
tsc-agenda
|
This comment was marked as outdated.
This comment was marked as outdated.
|
Landed in 8c60add |
|
Note: I believe this change requires an update to the documentation as well. |
This is not intended as a public api. |
This is required for streams interop with e.g. readable-stream. Currently readable-stream helpers will not work with normal node streams which is confusing and bad for the ecosystem. PR-URL: #45671 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
This is required for streams interop with e.g. readable-stream. Currently readable-stream helpers will not work with normal node streams which is confusing and bad for the ecosystem. PR-URL: #45671 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
This is required for streams interop with e.g. readable-stream. Currently readable-stream helpers will not work with normal node streams which is confusing and bad for the ecosystem. PR-URL: #45671 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com>
`stream.isDestroyed()` has been exported since v19.9.0 but was never documented, while its siblings `isErrored()`, `isReadable()` and `isWritable()` all have entries in `doc/api/stream.md`. Unlike those, `isDestroyed()` rejects Web streams: it returns `null` for anything that is not a Node.js stream. The accepted types are therefore documented as `Readable|Writable|Duplex` rather than also listing `ReadableStream`/`WritableStream`. Refs: nodejs#45671 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: YspritanHyzygy <yspritan@gmail.com>
`stream.isDestroyed()` has been exported since v19.9.0 but was never documented, while its siblings `isErrored()`, `isReadable()` and `isWritable()` all have entries in `doc/api/stream.md`. Unlike those, `isDestroyed()` rejects Web streams: it returns `null` for anything that is not a Node.js stream. The accepted types are therefore documented as `Readable|Writable|Duplex` rather than also listing `ReadableStream`/`WritableStream`. Refs: #45671 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: YspritanHyzygy <yspritan@gmail.com> PR-URL: #64789 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
`stream.isDestroyed()` has been exported since v19.9.0 but was never documented, while its siblings `isErrored()`, `isReadable()` and `isWritable()` all have entries in `doc/api/stream.md`. Unlike those, `isDestroyed()` rejects Web streams: it returns `null` for anything that is not a Node.js stream. The accepted types are therefore documented as `Readable|Writable|Duplex` rather than also listing `ReadableStream`/`WritableStream`. Refs: #45671 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: YspritanHyzygy <yspritan@gmail.com> PR-URL: #64789 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
`stream.isDestroyed()` has been exported since v19.9.0 but was never documented, while its siblings `isErrored()`, `isReadable()` and `isWritable()` all have entries in `doc/api/stream.md`. Unlike those, `isDestroyed()` rejects Web streams: it returns `null` for anything that is not a Node.js stream. The accepted types are therefore documented as `Readable|Writable|Duplex` rather than also listing `ReadableStream`/`WritableStream`. Refs: #45671 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: YspritanHyzygy <yspritan@gmail.com> PR-URL: #64789 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
`stream.isDestroyed()` has been exported since v19.9.0 but was never documented, while its siblings `isErrored()`, `isReadable()` and `isWritable()` all have entries in `doc/api/stream.md`. Unlike those, `isDestroyed()` rejects Web streams: it returns `null` for anything that is not a Node.js stream. The accepted types are therefore documented as `Readable|Writable|Duplex` rather than also listing `ReadableStream`/`WritableStream`. Refs: #45671 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: YspritanHyzygy <yspritan@gmail.com> PR-URL: #64789 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
`stream.isDestroyed()` has been exported since v19.9.0 but was never documented, while its siblings `isErrored()`, `isReadable()` and `isWritable()` all have entries in `doc/api/stream.md`. Unlike those, `isDestroyed()` rejects Web streams: it returns `null` for anything that is not a Node.js stream. The accepted types are therefore documented as `Readable|Writable|Duplex` rather than also listing `ReadableStream`/`WritableStream`. Refs: #45671 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: YspritanHyzygy <yspritan@gmail.com> PR-URL: #64789 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
`stream.isDestroyed()` has been exported since v19.9.0 but was never documented, while its siblings `isErrored()`, `isReadable()` and `isWritable()` all have entries in `doc/api/stream.md`. Unlike those, `isDestroyed()` rejects Web streams: it returns `null` for anything that is not a Node.js stream. The accepted types are therefore documented as `Readable|Writable|Duplex` rather than also listing `ReadableStream`/`WritableStream`. Refs: #45671 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: YspritanHyzygy <yspritan@gmail.com> PR-URL: #64789 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This is required for streams interop with e.g. readable-stream. Currently readable-stream helpers will not work with normal node streams which is confusing and bad for the ecosystem.