better-sse 0.15.0 → 0.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -6
- package/build/index.d.mts +10 -7
- package/build/index.d.ts +10 -7
- package/build/index.js +2 -2
- package/build/index.mjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
# Better SSE
|
|
2
2
|
|
|
3
3
|
<p>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
<a href="https://www.npmjs.com/package/better-sse">
|
|
5
|
+
<img src="https://img.shields.io/npm/v/better-sse?color=blue&style=flat-square" alt="npm" />
|
|
6
|
+
</a>
|
|
7
|
+
<a href="https://jsr.io/@mwid/better-sse">
|
|
8
|
+
<img src="https://jsr.io/badges/@mwid/better-sse" alt="jsr" />
|
|
9
|
+
</a>
|
|
10
|
+
<a href="https://github.com/MatthewWid/better-sse/blob/master/LICENSE">
|
|
11
|
+
<img src="https://img.shields.io/npm/l/better-sse?color=green&style=flat-square" alt="MIT license" />
|
|
12
|
+
</a>
|
|
13
|
+
<img src="https://img.shields.io/npm/dt/better-sse?color=grey&style=flat-square" alt="Downloads" />
|
|
14
|
+
<a href="https://github.com/MatthewWid/better-sse">
|
|
15
|
+
<img src="https://img.shields.io/github/stars/MatthewWid/better-sse?style=social" alt="GitHub stars" />
|
|
16
|
+
</a>
|
|
8
17
|
</p>
|
|
9
18
|
|
|
10
19
|
A dead simple, dependency-less, spec-compliant server-sent events implementation written in TypeScript.
|
|
@@ -47,7 +56,7 @@ Read the [Getting Started](https://matthewwid.github.io/better-sse/guides/gettin
|
|
|
47
56
|
|
|
48
57
|
# Installation
|
|
49
58
|
|
|
50
|
-
|
|
59
|
+
Better SSE is published as a package on [npm](https://www.npmjs.com/package/better-sse) and the [JSR](https://jsr.io/@mwid/better-sse). You can install it with any package manager:
|
|
51
60
|
|
|
52
61
|
```sh
|
|
53
62
|
npm install better-sse
|
|
@@ -66,7 +75,7 @@ bun add better-sse
|
|
|
66
75
|
```
|
|
67
76
|
|
|
68
77
|
```sh
|
|
69
|
-
deno install
|
|
78
|
+
deno install jsr:@mwid/better-sse
|
|
70
79
|
```
|
|
71
80
|
|
|
72
81
|
_Better SSE ships with types built in. No need to install from DefinitelyTyped for TypeScript users!_
|
package/build/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as stream from 'stream';
|
|
2
1
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
2
|
import { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
|
3
|
+
import { Readable } from 'node:stream';
|
|
4
4
|
import { EventEmitter } from 'node:events';
|
|
5
5
|
|
|
6
6
|
interface IterateOptions {
|
|
@@ -11,7 +11,9 @@ interface IterateOptions {
|
|
|
11
11
|
*/
|
|
12
12
|
eventName?: string;
|
|
13
13
|
}
|
|
14
|
+
type PushFromIterable = (iterable: Iterable<unknown> | AsyncIterable<unknown>, options?: IterateOptions) => Promise<void>;
|
|
14
15
|
|
|
16
|
+
type WebReadableStream = ReadableStream;
|
|
15
17
|
interface StreamOptions {
|
|
16
18
|
/**
|
|
17
19
|
* Event name/type to be emitted when stream data is sent to the client.
|
|
@@ -20,6 +22,7 @@ interface StreamOptions {
|
|
|
20
22
|
*/
|
|
21
23
|
eventName?: string;
|
|
22
24
|
}
|
|
25
|
+
type PushFromStream = (stream: Readable | WebReadableStream, options?: StreamOptions) => Promise<boolean>;
|
|
23
26
|
|
|
24
27
|
type SanitizerFunction = (text: string) => string;
|
|
25
28
|
|
|
@@ -118,9 +121,9 @@ declare class EventBuffer {
|
|
|
118
121
|
* @param stream - Readable stream to consume data from.
|
|
119
122
|
* @param options - Event name to use for each event created.
|
|
120
123
|
*
|
|
121
|
-
* @returns A promise that resolves or rejects based on the success of the stream write finishing.
|
|
124
|
+
* @returns A promise that resolves with `true` or rejects based on the success of the stream write finishing.
|
|
122
125
|
*/
|
|
123
|
-
stream:
|
|
126
|
+
stream: PushFromStream;
|
|
124
127
|
/**
|
|
125
128
|
* Iterate over an iterable and write yielded values as events into the buffer.
|
|
126
129
|
*
|
|
@@ -132,7 +135,7 @@ declare class EventBuffer {
|
|
|
132
135
|
*
|
|
133
136
|
* @returns A promise that resolves once all data has been successfully yielded from the iterable.
|
|
134
137
|
*/
|
|
135
|
-
iterate:
|
|
138
|
+
iterate: PushFromIterable;
|
|
136
139
|
/**
|
|
137
140
|
* Clear the contents of the buffer.
|
|
138
141
|
*/
|
|
@@ -339,9 +342,9 @@ declare class Session<State = DefaultSessionState> extends TypedEmitter<SessionE
|
|
|
339
342
|
* @param stream - Readable stream to consume data from.
|
|
340
343
|
* @param options - Options to alter how the stream is flushed to the client.
|
|
341
344
|
*
|
|
342
|
-
* @returns A promise that resolves or rejects based on the success of the stream write finishing.
|
|
345
|
+
* @returns A promise that resolves with `true` or rejects based on the success of the stream write finishing.
|
|
343
346
|
*/
|
|
344
|
-
stream:
|
|
347
|
+
stream: PushFromStream;
|
|
345
348
|
/**
|
|
346
349
|
* Iterate over an iterable and send yielded values as events to the client.
|
|
347
350
|
*
|
|
@@ -353,7 +356,7 @@ declare class Session<State = DefaultSessionState> extends TypedEmitter<SessionE
|
|
|
353
356
|
*
|
|
354
357
|
* @returns A promise that resolves once all data has been successfully yielded from the iterable.
|
|
355
358
|
*/
|
|
356
|
-
iterate:
|
|
359
|
+
iterate: PushFromIterable;
|
|
357
360
|
/**
|
|
358
361
|
* Batch and send multiple events at once.
|
|
359
362
|
*
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as stream from 'stream';
|
|
2
1
|
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
2
|
import { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
|
3
|
+
import { Readable } from 'node:stream';
|
|
4
4
|
import { EventEmitter } from 'node:events';
|
|
5
5
|
|
|
6
6
|
interface IterateOptions {
|
|
@@ -11,7 +11,9 @@ interface IterateOptions {
|
|
|
11
11
|
*/
|
|
12
12
|
eventName?: string;
|
|
13
13
|
}
|
|
14
|
+
type PushFromIterable = (iterable: Iterable<unknown> | AsyncIterable<unknown>, options?: IterateOptions) => Promise<void>;
|
|
14
15
|
|
|
16
|
+
type WebReadableStream = ReadableStream;
|
|
15
17
|
interface StreamOptions {
|
|
16
18
|
/**
|
|
17
19
|
* Event name/type to be emitted when stream data is sent to the client.
|
|
@@ -20,6 +22,7 @@ interface StreamOptions {
|
|
|
20
22
|
*/
|
|
21
23
|
eventName?: string;
|
|
22
24
|
}
|
|
25
|
+
type PushFromStream = (stream: Readable | WebReadableStream, options?: StreamOptions) => Promise<boolean>;
|
|
23
26
|
|
|
24
27
|
type SanitizerFunction = (text: string) => string;
|
|
25
28
|
|
|
@@ -118,9 +121,9 @@ declare class EventBuffer {
|
|
|
118
121
|
* @param stream - Readable stream to consume data from.
|
|
119
122
|
* @param options - Event name to use for each event created.
|
|
120
123
|
*
|
|
121
|
-
* @returns A promise that resolves or rejects based on the success of the stream write finishing.
|
|
124
|
+
* @returns A promise that resolves with `true` or rejects based on the success of the stream write finishing.
|
|
122
125
|
*/
|
|
123
|
-
stream:
|
|
126
|
+
stream: PushFromStream;
|
|
124
127
|
/**
|
|
125
128
|
* Iterate over an iterable and write yielded values as events into the buffer.
|
|
126
129
|
*
|
|
@@ -132,7 +135,7 @@ declare class EventBuffer {
|
|
|
132
135
|
*
|
|
133
136
|
* @returns A promise that resolves once all data has been successfully yielded from the iterable.
|
|
134
137
|
*/
|
|
135
|
-
iterate:
|
|
138
|
+
iterate: PushFromIterable;
|
|
136
139
|
/**
|
|
137
140
|
* Clear the contents of the buffer.
|
|
138
141
|
*/
|
|
@@ -339,9 +342,9 @@ declare class Session<State = DefaultSessionState> extends TypedEmitter<SessionE
|
|
|
339
342
|
* @param stream - Readable stream to consume data from.
|
|
340
343
|
* @param options - Options to alter how the stream is flushed to the client.
|
|
341
344
|
*
|
|
342
|
-
* @returns A promise that resolves or rejects based on the success of the stream write finishing.
|
|
345
|
+
* @returns A promise that resolves with `true` or rejects based on the success of the stream write finishing.
|
|
343
346
|
*/
|
|
344
|
-
stream:
|
|
347
|
+
stream: PushFromStream;
|
|
345
348
|
/**
|
|
346
349
|
* Iterate over an iterable and send yielded values as events to the client.
|
|
347
350
|
*
|
|
@@ -353,7 +356,7 @@ declare class Session<State = DefaultSessionState> extends TypedEmitter<SessionE
|
|
|
353
356
|
*
|
|
354
357
|
* @returns A promise that resolves once all data has been successfully yielded from the iterable.
|
|
355
358
|
*/
|
|
356
|
-
iterate:
|
|
359
|
+
iterate: PushFromIterable;
|
|
357
360
|
/**
|
|
358
361
|
* Batch and send multiple events at once.
|
|
359
362
|
*
|
package/build/index.js
CHANGED
|
@@ -200,7 +200,7 @@ var EventBuffer = class {
|
|
|
200
200
|
* @param stream - Readable stream to consume data from.
|
|
201
201
|
* @param options - Event name to use for each event created.
|
|
202
202
|
*
|
|
203
|
-
* @returns A promise that resolves or rejects based on the success of the stream write finishing.
|
|
203
|
+
* @returns A promise that resolves with `true` or rejects based on the success of the stream write finishing.
|
|
204
204
|
*/
|
|
205
205
|
stream = createPushFromStream(this.push);
|
|
206
206
|
/**
|
|
@@ -624,7 +624,7 @@ var Session = class extends TypedEmitter {
|
|
|
624
624
|
* @param stream - Readable stream to consume data from.
|
|
625
625
|
* @param options - Options to alter how the stream is flushed to the client.
|
|
626
626
|
*
|
|
627
|
-
* @returns A promise that resolves or rejects based on the success of the stream write finishing.
|
|
627
|
+
* @returns A promise that resolves with `true` or rejects based on the success of the stream write finishing.
|
|
628
628
|
*/
|
|
629
629
|
stream = createPushFromStream(this.push);
|
|
630
630
|
/**
|
package/build/index.mjs
CHANGED
|
@@ -170,7 +170,7 @@ var EventBuffer = class {
|
|
|
170
170
|
* @param stream - Readable stream to consume data from.
|
|
171
171
|
* @param options - Event name to use for each event created.
|
|
172
172
|
*
|
|
173
|
-
* @returns A promise that resolves or rejects based on the success of the stream write finishing.
|
|
173
|
+
* @returns A promise that resolves with `true` or rejects based on the success of the stream write finishing.
|
|
174
174
|
*/
|
|
175
175
|
stream = createPushFromStream(this.push);
|
|
176
176
|
/**
|
|
@@ -594,7 +594,7 @@ var Session = class extends TypedEmitter {
|
|
|
594
594
|
* @param stream - Readable stream to consume data from.
|
|
595
595
|
* @param options - Options to alter how the stream is flushed to the client.
|
|
596
596
|
*
|
|
597
|
-
* @returns A promise that resolves or rejects based on the success of the stream write finishing.
|
|
597
|
+
* @returns A promise that resolves with `true` or rejects based on the success of the stream write finishing.
|
|
598
598
|
*/
|
|
599
599
|
stream = createPushFromStream(this.push);
|
|
600
600
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-sse",
|
|
3
3
|
"description": "Dead simple, dependency-less, spec-compliant server-sent events implementation written in TypeScript.",
|
|
4
|
-
"version": "0.15.
|
|
4
|
+
"version": "0.15.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Matthew W. <matthew.widdi@gmail.com>",
|
|
7
7
|
"repository": "github:MatthewWid/better-sse",
|