@ahoo-wang/fetcher-eventstream 0.0.3 → 0.0.4
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
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @ahoo-wang/fetcher-eventstream
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@ahoo-wang/fetcher-eventstream)
|
|
4
|
+
[](https://github.com/Ahoo-Wang/fetcher/actions)
|
|
5
|
+
[](https://codecov.io/gh/Ahoo-Wang/Fetcher)
|
|
6
|
+
[](https://github.com/Ahoo-Wang/fetcher/blob/main/LICENSE)
|
|
7
|
+
[](https://www.npmjs.com/package/@ahoo-wang/fetcher-eventstream)
|
|
8
|
+
[](https://bundlephobia.com/package/@ahoo-wang/fetcher-eventstream)
|
|
9
|
+
|
|
3
10
|
Support for text/event-stream in Fetcher, enabling Server-Sent Events (SSE) functionality.
|
|
4
11
|
|
|
5
12
|
## Features
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ServerSentEventStream } from './serverSentEventTransformStream';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Responsible for handling event stream responses, including converting Response to event stream (ReadableStream<ServerSentEvent>).
|
|
4
4
|
*/
|
|
5
5
|
export declare class EventStreamConverter {
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Convert HTTP response to server-sent event stream
|
|
8
8
|
*
|
|
9
|
-
* @param response - HTTP
|
|
10
|
-
* @returns ServerSentEventStream -
|
|
11
|
-
* @throws Error -
|
|
9
|
+
* @param response - HTTP response object, should contain text/event-stream formatted data
|
|
10
|
+
* @returns ServerSentEventStream - Server event stream, can be used to read events sent by the server
|
|
11
|
+
* @throws Error - Throws error when response body is null
|
|
12
12
|
*/
|
|
13
13
|
static toEventStream(response: Response): ServerSentEventStream;
|
|
14
14
|
}
|
package/dist/index.es.js
CHANGED
|
@@ -55,9 +55,9 @@ class u {
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
59
|
-
* @param chunk
|
|
60
|
-
* @param controller
|
|
58
|
+
* Transform input string chunk into ServerSentEvent object
|
|
59
|
+
* @param chunk Input string chunk
|
|
60
|
+
* @param controller Controller for controlling the transform stream
|
|
61
61
|
*/
|
|
62
62
|
transform(t, r) {
|
|
63
63
|
let e = this.currentEvent;
|
|
@@ -84,8 +84,8 @@ class u {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
|
-
*
|
|
88
|
-
* @param controller
|
|
87
|
+
* Called when the stream ends, used to process remaining data
|
|
88
|
+
* @param controller Controller for controlling the transform stream
|
|
89
89
|
*/
|
|
90
90
|
flush(t) {
|
|
91
91
|
let r = this.currentEvent;
|
|
@@ -113,11 +113,11 @@ class m extends TransformStream {
|
|
|
113
113
|
}
|
|
114
114
|
class y {
|
|
115
115
|
/**
|
|
116
|
-
*
|
|
116
|
+
* Convert HTTP response to server-sent event stream
|
|
117
117
|
*
|
|
118
|
-
* @param response - HTTP
|
|
119
|
-
* @returns ServerSentEventStream -
|
|
120
|
-
* @throws Error -
|
|
118
|
+
* @param response - HTTP response object, should contain text/event-stream formatted data
|
|
119
|
+
* @returns ServerSentEventStream - Server event stream, can be used to read events sent by the server
|
|
120
|
+
* @throws Error - Throws error when response body is null
|
|
121
121
|
*/
|
|
122
122
|
static toEventStream(t) {
|
|
123
123
|
if (!t.body)
|
|
@@ -23,20 +23,20 @@ export declare enum ServerSentEventField {
|
|
|
23
23
|
DATA = "data"
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
* ServerSentEventTransformer
|
|
27
|
-
*
|
|
26
|
+
* ServerSentEventTransformer is responsible for converting a string stream into a ServerSentEvent object stream
|
|
27
|
+
* Implements the Transformer interface for processing data transformation in TransformStream
|
|
28
28
|
*/
|
|
29
29
|
export declare class ServerSentEventTransformer implements Transformer<string, ServerSentEvent> {
|
|
30
30
|
private currentEvent;
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
* @param chunk
|
|
34
|
-
* @param controller
|
|
32
|
+
* Transform input string chunk into ServerSentEvent object
|
|
33
|
+
* @param chunk Input string chunk
|
|
34
|
+
* @param controller Controller for controlling the transform stream
|
|
35
35
|
*/
|
|
36
36
|
transform(chunk: string, controller: TransformStreamDefaultController<ServerSentEvent>): void;
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
39
|
-
* @param controller
|
|
38
|
+
* Called when the stream ends, used to process remaining data
|
|
39
|
+
* @param controller Controller for controlling the transform stream
|
|
40
40
|
*/
|
|
41
41
|
flush(controller: TransformStreamDefaultController<ServerSentEvent>): void;
|
|
42
42
|
}
|