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.
- Added the
Session#batch
method that can be used to batch multiple events into a single transmission over the wire. - Added the
EventBuffer
class 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
,.dispatch
and.flush
methods in favour of using event buffers instead.
- Added the ability to type the
state
property of sessions registered with a Channel via an optional second generic argument to theChannel
constructor. - Added the
DefaultChannelState
interface that may be used via module augmentation to alter the default channel state type for all channels.
- Update the
SessionState
interface 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#flush
method. - Added the
Pragma
,X-Accel-Buffering
headers and add additional values to theCache-Control
default header to further disable all forms of caching. - Added support for supplying the Node HTTP/2 compatibility API
Http2ServerRequest
andHttp2ServerResponse
objects to theSession
constructorreq
andres
parameters, respectively.
- Update the
Session#event
,Session#data
,Session#id
,Session#retry
andSession#comment
methods to write to the internal data buffer instead of sending the field data over the wire immediately. - Update the
Session#dispatch
method to only write a newline (and to the internal data buffer) and not flush the written data to the client. - Update the
Channel#broadcast
method to generate its own custom event ID and thus add it as an additional argument to itsbroadcast
event callback function. - Update the
Channel#register
andChannel#deregister
to not do anything if the channel is already registered or deregistered, respectively. - Update the
Session
constructor optionsheader
field 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-disconnected
being fired after instead of before the session is deregistered.
- Removed the ability to pass
null
toSession#id
. Give no arguments at all instead.
- Removed type-declarations generated from unit testing files.
- Added the ability to the
Session#push
method to set a custom event ID. - Added a new Session
push
event that is emitted with the event data, name and ID when theSession#push
method is called. - Added the
Channel#state
property to have a safe namespace for keeping information attached to the channel.
- Update the arguments for the
Session#push
andChannel#broadcast
methods and their corresponding emitted event callbacks to always have the event data first and event name as an optional argument second. - Update the
Channel#broadcast
method options TypeScript typings to explicitly mandate aboolean
return-type instead of allowing any truthy or falsy value. - Update the
Channel#broadcast
method event name argument to be optional and default to"message"
if not given. - Update the
Session#state
generic argument to default to a newSessionState
interface 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
Events
interfaces toSessionEvents
andChannelEvents
respectively and export them publicly allowing the user to properly type non-inlined event handler callback functions.
- Added the
Session#iterate
method that allows processing iterables and sending yielded values to the client as events. - Added types for
Session
andChannel
event listener callback function arguments. - Added the ability to type
Session#state
using an optional generic argument forcreateSession
and theSession
constructor.
- Rename the
Session#stream
event
option toeventName
.
- Added broadcast channels that allow pushing events to multiple sessions at once.
- Added support for EventStream polyfills
event-source-polyfill
andeventsource-polyfill
. - Added the
Session#state
property to have a safe namespace for keeping information attached to the session.
- Fixed TypeScript types for the
Session#lastId
not being read-only.
- Added an automated keep-alive mechanism that can be enabled or disable in the Session constructor options.
- Added the
Session#isConnected
boolean property.
- Fixed an issue where installing the package using
npm
would throw an error mandating it be installed withpnpm
.