fix(core): avoid extending TransformStream in EventStreamDecoderStream - #78
Conversation
Extending TransformStream resolves the global at module-evaluation time, so importing @standardserver/core crashed on runtimes without it even when the stream class was never used. Compose a TransformStream inside the constructor instead, deferring the global lookup to instantiation.
@standardserver/aws-lambda
@standardserver/core
@standardserver/fastify
@standardserver/fetch
@standardserver/node
@standardserver/peer
@standardserver/shared
commit: |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
EventStreamDecoderStreamnowimplements ReadableWritablePair<EventStreamMessage, string>instead ofextends TransformStream, composing aTransformStreamin the constructor and exposing itsreadable/writablepair — deferring the global-after-reference until an instance is constructed.- New regression test stubs
TransformStreamtoundefinedand re-imports./decoder, verifying module import no longer crashe- resolving the global at import time.
The refactor is sound: ReadableStream/WritableStream are type annotations (type-erased at compile time), so the only runtime global use is the new TransformStream(...) inside the constructor. grep confirms every caller is .pipeThrough(new EventStreamDecoderStream()) (core tests, package/fetch/src/event-stream.ts:9, README), which only needs the ReadableWritablePair shape — nothing relies on instanceof TransformStream. The new test is meaningful (the old extends impl throws on import when the global is undefined) and cleans up via onTestFinished.
DeepSeek Flash (default — pick a model for stronger reviews) | 𝕏
Merging this PR will not alter performance
Comparing Footnotes
|

EventStreamDecoderStreamno longer extendsTransformStream. Extending resolves the global at module-evaluation time, so merely importing@standardserver/corecrashed on runtimes that don't provideTransformStream— even when the stream class was never used. The class now composes aTransformStreamcreated in its constructor and exposes itsreadable/writablepair, so the global is only needed when an instance is actually constructed.Fixes
@standardserver/coreworks on runtimes without a globalTransformStream; only constructingEventStreamDecoderStreamrequires it..pipeThrough(new EventStreamDecoderStream())behaves exactly as before — the class satisfiesReadableWritablePair<EventStreamMessage, string>. The only observable difference is that instances are no longerinstanceof TransformStream(nothing in the repo relied on that).Testing
TransformStreamand asserts a fresh import of the module still succeeds; verified it fails against the previousextendsimplementation.tsc --noEmitis clean forcoreandfetch.