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

stream: expose stream symbols #45671

Merged
merged 1 commit into from
Mar 24, 2023

Conversation

ronag
Copy link
Member

@ronag ronag commented Nov 29, 2022

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.

@ronag ronag requested a review from mcollina November 29, 2022 10:33
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/streams

@ronag ronag added the stream Issues and PRs related to the stream subsystem. label Nov 29, 2022
@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Nov 29, 2022
Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@ronag
Copy link
Member Author

ronag commented Nov 29, 2022

How would it do that? I'm not sure how that would work. Especially in a performant way.

@ErickWendel
Copy link
Member

How would it do that?

const kKey = Symbol('key')
class My { [kKey]() { console.log('hello') }}

const [, symKey] = Reflect.ownKeys(My.prototype) 
new My()[symKey]()
// hello

@ronag
Copy link
Member Author

ronag commented Nov 29, 2022

How would it do that?

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...

@ErickWendel
Copy link
Member

ErickWendel commented Nov 29, 2022

How would it do that?

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]) // hey

For Streams:

const str = stream.Readable.from('abc')
const data = Reflect.ownKeys(str)
const kCapture = data[6]
str[kCapture] // false

@ronag
Copy link
Member Author

ronag commented Nov 29, 2022

I still don't see how that will work. Would need to know the static index of the symbol. Which is not possible atm.

@vweevers
Copy link
Contributor

This case is similar to Symbol.for('nodejs.util.inspect.custom') in its goal to improve portability. How about using global symbols, e.g. Symbol.for('nodejs.stream.destroyed')? The intent would be clearer, compared to exporting symbols.

@RaisinTen
Copy link
Contributor

Why don't we use a regular string key to expose these values like what was done in the case of readable.closed and document that instead? That way, we won't be exposing raw non-global symbols, which aren't meant to be a part of the public API and there would also be no need to use Reflect.ownKeys or Object.getOwnPropertySymbols.

@ronag ronag requested a review from aduh95 November 30, 2022 10:50
@ronag ronag added request-ci Add this label to start a Jenkins CI on a PR. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. and removed needs-ci PRs that need a full CI run. labels Nov 30, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 30, 2022
@nodejs-github-bot
Copy link
Collaborator

@ronag
Copy link
Member Author

ronag commented Dec 19, 2022

@nodejs/streams some reviews?

@ronag
Copy link
Member Author

ronag commented Dec 19, 2022

@mcollina We will need this in readable-stream for proper interop.

@aduh95 aduh95 added the tsc-agenda Issues and PRs to discuss during the meetings of the TSC. label Dec 19, 2022
@aduh95
Copy link
Contributor

aduh95 commented Dec 19, 2022

Adding the tsc-agenda Issues and PRs to discuss during the meetings of the TSC. so we can discuss how to expose internals and what should be the adequate documentation / semver expectations around it.

@ronag ronag added the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 10, 2023
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Mar 10, 2023
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/45671
✔  Done loading data for nodejs/node/pull/45671
----------------------------------- PR info ------------------------------------
Title      stream: expose stream symbols (#45671)
Author     Robert Nagy  (@ronag)
Branch     ronag:expose-stream-symbols -> nodejs:main
Labels     stream, author ready
Commits    1
 - stream: expose stream symbols
Committers 1
 - Robert Nagy 
PR-URL: https://github.com/nodejs/node/pull/45671
Reviewed-By: Matteo Collina 
Reviewed-By: James M Snell 
Reviewed-By: Antoine du Hamel 
Reviewed-By: Benjamin Gruenbaum 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/45671
Reviewed-By: Matteo Collina 
Reviewed-By: James M Snell 
Reviewed-By: Antoine du Hamel 
Reviewed-By: Benjamin Gruenbaum 
--------------------------------------------------------------------------------
   ⚠  Commits were pushed since the last review:
   ⚠  - stream: expose stream symbols
   ℹ  This PR was created on Tue, 29 Nov 2022 10:33:01 GMT
   ✔  Approvals: 4
   ✔  - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/45671#pullrequestreview-1307877767
   ✔  - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/45671#pullrequestreview-1223224391
   ✔  - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/45671#pullrequestreview-1240689090
   ✔  - Benjamin Gruenbaum (@benjamingr): https://github.com/nodejs/node/pull/45671#pullrequestreview-1318093984
   ✘  Last GitHub CI failed
   ℹ  Last Full PR CI on 2023-01-05T18:00:02Z: https://ci.nodejs.org/job/node-test-pull-request/48871/
   ⚠  Commits were pushed after the last Full PR CI run:
   ⚠  - stream: expose stream symbols
- Querying data for job/node-test-pull-request/48871/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/4382938745

@debadree25 debadree25 added request-ci Add this label to start a Jenkins CI on a PR. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Mar 16, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 16, 2023
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@debadree25 debadree25 added the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 24, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 24, 2023
@nodejs-github-bot nodejs-github-bot merged commit 8c60add into nodejs:main Mar 24, 2023
@nodejs-github-bot
Copy link
Collaborator

Landed in 8c60add

@anonrig
Copy link
Member

anonrig commented Mar 24, 2023

Note: I believe this change requires an update to the documentation as well.

@ronag
Copy link
Member Author

ronag commented Mar 24, 2023

Note: I believe this change requires an update to the documentation as well.

This is not intended as a public api.

RafaelGSS pushed a commit that referenced this pull request Apr 5, 2023
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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Debadree Chatterjee <[email protected]>
@RafaelGSS RafaelGSS mentioned this pull request Apr 6, 2023
RafaelGSS pushed a commit that referenced this pull request Apr 7, 2023
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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Debadree Chatterjee <[email protected]>
danielleadams pushed a commit that referenced this pull request Jul 6, 2023
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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Debadree Chatterjee <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.