All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
- Fixed a crash that occurred when the underlying socket of the Node request or response did not define an implementation of the
setNoDelaymethod.
- Added support for passing custom connection adapters to the
Sessionconstructor that enables compatibility with any protocol, framework or runtime environment.
- Update event ID generation to use
randomUUIDfrom the Web Crypto API instead ofnode:crypto. - Update Node HTTP/1 and HTTP/2 Compatibility adapters to disable Nagle's algorithm on the underlying socket to reduce latency.
- Fixed a warning being printed by the Node internals when adding more than ten listeners to events emitted by sessions and channels.
- Fixed a crash that occurred when passing a
Requestbut no correspondingResponseobject from the Fetch API to theSessionconstructor. - Fixed a crash that occurred when the request had no
Hostheader when using the Node HTTP/1 or Node HTTP/2 Compatibility API.
- Added support for publishing on the JavaScript Registry (JSR).
- Fixed the
stream,iterateandEventBuffer#clearmethods not having explicit return types, resulting in slow inference in certain environments.
- Added support for the
Sessionconstructor to be able to take in aRequest(and optionally aResponse) object from the Fetch API. - Added the
Session#getRequestandSession#getResponsemethods to retrieve the Fetch APIRequestandResponseobjects, respectively. - Added the
createResponseutility function to create aSessioninstance and immediately return its associatedResponseobject. - Added type overloads for each combination of arguments to
createSessionand theSessionconstructor. - Added support for passing a
ReadableStreamfrom the Web Streams API toSession#streamandEventBuffer#stream.
- Update type of
Sessionconstructoroptions#headersargument to accept anystring->(string | string[] | undefined)type rather than onlyOutgoingHttpHeaders. - Update the
Sessionconstructoroptions#headersargument to omit headers whose values are given asundefined, rather than an empty string. - Update the
Sessionconstructor to throw if given anIncomingMessageorHttp2ServerRequestwith no correspondingServerResponseorHttp2ServerResponse, respectively.
- Fixed connection-specific headers being sent when using HTTP/2, causing the response to be treated as malformed.
- Removed the deprecated Session
.event,.data,.id,.retry,.comment,.dispatchand.flushmethods.
- Update links to point to new documentation website.
- Fixed default state type when creating sessions and channels with
createSessionandcreateChannelbeing set tounknowninstead ofDefaultSessionStateandDefaultChannelState, respectively. - Fixed package directly exporting a single object containing exports, breaking named imports when using ESModules, and instead dual-export two separate builds to support both ESM and CJS.
- Dropped support for Node 17 and below.
- Added the ability to set an initial value for the
stateproperty in theSessionandChannelconstructoroptionsobjects.
- Removed constraints that enforced that
Stategenerics passed toSessionandChannelextend fromRecord<string, unknown>.
- Fixed types for channel and session emitted event names.
- Added the ability to set a custom event ID when using
Channel#broadcast.
- Added the
SseErrorcustom error object that wraps all thrown errors.
- Update the
Session#pushmethod to throw if the session is not connected.
- Fixed session not detecting a response stream disconnect.
- Added the
Session#batchmethod that can be used to batch multiple events into a single transmission over the wire. - Added the
EventBufferclass that can be used to write raw spec-compliant SSE fields into a text buffer that can be sent directly over the wire.
- Deprecate the Session
.event,.data,.id,.retry,.comment,.dispatchand.flushmethods in favour of using event buffers instead.
- Added the ability to type the
stateproperty of sessions registered with a Channel via an optional second generic argument to theChannelconstructor. - Added the
DefaultChannelStateinterface that may be used via module augmentation to alter the default channel state type for all channels.
- Update the
SessionStateinterface to be namedDefaultSessionState.
- Added an internal data buffer to Session that buffers written data internally until it is flushed to the client using the new
Session#flushmethod. - Added the
Pragma,X-Accel-Bufferingheaders and add additional values to theCache-Controldefault header to further disable all forms of caching. - Added support for supplying the Node HTTP/2 compatibility API
Http2ServerRequestandHttp2ServerResponseobjects to theSessionconstructorreqandresparameters, respectively.
- Update the
Session#event,Session#data,Session#id,Session#retryandSession#commentmethods to write to the internal data buffer instead of sending the field data over the wire immediately. - Update the
Session#dispatchmethod to only write a newline (and to the internal data buffer) and not flush the written data to the client. - Update the
Channel#broadcastmethod to generate its own custom event ID and thus add it as an additional argument to itsbroadcastevent callback function. - Update the
Channel#registerandChannel#deregisterto not do anything if the channel is already registered or deregistered, respectively. - Update the
Sessionconstructor optionsheaderfield to overwrite conflicting default headers instead of being ignored. - Update auto-generated event IDs to be guaranteed to be a cryptographically unique string instead of a pseudorandomly generated string of eight characters.
- Fixed the Channel
session-disconnectedbeing fired after instead of before the session is deregistered.
- Removed the ability to pass
nulltoSession#id. Give no arguments at all instead.
- Removed type-declarations generated from unit testing files.
- Added the ability to the
Session#pushmethod to set a custom event ID. - Added a new Session
pushevent that is emitted with the event data, name and ID when theSession#pushmethod is called. - Added the
Channel#stateproperty to have a safe namespace for keeping information attached to the channel.
- Update the arguments for the
Session#pushandChannel#broadcastmethods and their corresponding emitted event callbacks to always have the event data first and event name as an optional argument second. - Update the
Channel#broadcastmethod options TypeScript typings to explicitly mandate abooleanreturn-type instead of allowing any truthy or falsy value. - Update the
Channel#broadcastmethod event name argument to be optional and default to"message"if not given. - Update the
Session#stategeneric argument to default to a newSessionStateinterface that can be augmented via declaration merging to override the session state type for all session objects without explicitly providing a generic argument to each reference toSession. - Rename the Session and Channel
Eventsinterfaces toSessionEventsandChannelEventsrespectively and export them publicly allowing the user to properly type non-inlined event handler callback functions.
- Added the
Session#iteratemethod that allows processing iterables and sending yielded values to the client as events. - Added types for
SessionandChannelevent listener callback function arguments. - Added the ability to type
Session#stateusing an optional generic argument forcreateSessionand theSessionconstructor.
- Rename the
Session#streameventoption toeventName.
- Added broadcast channels that allow pushing events to multiple sessions at once.
- Added support for EventSource polyfills
event-source-polyfillandeventsource-polyfill. - Added the
Session#stateproperty to have a safe namespace for keeping information attached to the session.
- Fixed TypeScript types for the
Session#lastIdnot being read-only.
- Added an automated keep-alive mechanism that can be enabled or disable in the Session constructor options.
- Added the
Session#isConnectedboolean property.
- Fixed an issue where installing the package using
npmwould throw an error mandating it be installed withpnpm.