-
Notifications
You must be signed in to change notification settings - Fork 217
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
Fix stream() support for chunked event streams #211
Conversation
expect(await iterator.next()).toEqual({ | ||
done: false, | ||
value: { event: "done", id: "EVENT_2", data: "{}" }, | ||
}); |
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 think this is a bug, rather than a feature because it means that we always need to check event.event === "output"
before accessing event.data
. The toString
function kind of hides this but it doesn't work with JSON.stringify()
.
I think actually we want to return the done event from the iterator rather than yielding it. Then the done
iterator will look like:
expect(await iterator.next()).toEqual({ done: true, value: { event: "done", ... } });
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.
That sounds reasonable to me. Any reason not to make that change to return for done?
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.
It's technically a breaking change, but unclear how much of an issue it would cause. There's nothing you can do with it except listen for it and ignore it.
@mattt can we punt on the |
Closing in favor of #214 |
There's a subtle bug in the current
Stream
implementation where if the server emits lines in several chunks then we get "null" events in the async iterator.For example:
Will result in:
This PR fixes this, plus a few bugs in the
Stream
implementation:decode()
function in theStream
class processes full lines by retaining the last line of the current chunk and appending it to the start of the next chunk before splitting on newlines.validateWebhook
which returns aPromise<boolean>
but is typed to returnboolean
.