@ahoo-wang/fetcher-eventstream 2.9.6 → 2.9.9
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 +119 -1
- package/README.zh-CN.md +119 -1
- package/dist/eventStreamConverter.d.ts +76 -10
- package/dist/eventStreamConverter.d.ts.map +1 -1
- package/dist/eventStreamResultExtractor.d.ts +35 -8
- package/dist/eventStreamResultExtractor.d.ts.map +1 -1
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +107 -33
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +3 -3
- package/dist/index.umd.js.map +1 -1
- package/dist/jsonServerSentEventTransformStream.d.ts +134 -2
- package/dist/jsonServerSentEventTransformStream.d.ts.map +1 -1
- package/dist/readableStreamAsyncIterable.d.ts +37 -1
- package/dist/readableStreamAsyncIterable.d.ts.map +1 -1
- package/dist/readableStreams.d.ts +21 -0
- package/dist/readableStreams.d.ts.map +1 -1
- package/dist/responses.d.ts +5 -3
- package/dist/responses.d.ts.map +1 -1
- package/dist/serverSentEventTransformStream.d.ts +42 -0
- package/dist/serverSentEventTransformStream.d.ts.map +1 -1
- package/dist/textLineTransformStream.d.ts +64 -3
- package/dist/textLineTransformStream.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Transformer that splits text into lines.
|
|
3
3
|
*
|
|
4
|
-
* This transformer accumulates chunks of text and splits them by newline characters,
|
|
5
|
-
* emitting each line as a separate chunk
|
|
6
|
-
*
|
|
4
|
+
* This transformer accumulates chunks of text and splits them by newline characters ('\n'),
|
|
5
|
+
* emitting each complete line as a separate chunk. It handles partial lines that span multiple
|
|
6
|
+
* input chunks by maintaining an internal buffer. Lines are emitted without the newline character.
|
|
7
|
+
*
|
|
8
|
+
* The transformer handles various edge cases:
|
|
9
|
+
* - Lines that span multiple input chunks
|
|
10
|
+
* - Empty lines (emitted as empty strings)
|
|
11
|
+
* - Text without trailing newlines (buffered until stream ends)
|
|
12
|
+
* - Mixed line endings (only '\n' is recognized as line separator)
|
|
13
|
+
*
|
|
14
|
+
* @implements {Transformer<string, string>}
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const transformer = new TextLineTransformer();
|
|
19
|
+
* // Input: "line1\nline2\npartial"
|
|
20
|
+
* // Output: ["line1", "line2"]
|
|
21
|
+
* // Buffer: "partial"
|
|
22
|
+
*
|
|
23
|
+
* // Later input: "line\n"
|
|
24
|
+
* // Output: ["partialline"]
|
|
25
|
+
* // Buffer: ""
|
|
26
|
+
* ```
|
|
7
27
|
*/
|
|
8
28
|
export declare class TextLineTransformer implements Transformer<string, string> {
|
|
9
29
|
private buffer;
|
|
@@ -23,8 +43,49 @@ export declare class TextLineTransformer implements Transformer<string, string>
|
|
|
23
43
|
}
|
|
24
44
|
/**
|
|
25
45
|
* A TransformStream that splits text into lines.
|
|
46
|
+
*
|
|
47
|
+
* This class provides a convenient way to transform a stream of text chunks into a stream
|
|
48
|
+
* of individual lines. It wraps the TextLineTransformer in a TransformStream for easy
|
|
49
|
+
* integration with other stream processing pipelines.
|
|
50
|
+
*
|
|
51
|
+
* The stream processes text data and emits each line as a separate chunk, handling
|
|
52
|
+
* lines that may span multiple input chunks automatically.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* // Create a line-splitting stream
|
|
57
|
+
* const lineStream = new TextLineTransformStream();
|
|
58
|
+
*
|
|
59
|
+
* // Pipe text through it
|
|
60
|
+
* const lines = textStream.pipeThrough(lineStream);
|
|
61
|
+
*
|
|
62
|
+
* // Process each line
|
|
63
|
+
* for await (const line of lines) {
|
|
64
|
+
* console.log('Line:', line);
|
|
65
|
+
* }
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // Process SSE response line by line
|
|
71
|
+
* const response = await fetch('/api/stream');
|
|
72
|
+
* const lines = response.body!
|
|
73
|
+
* .pipeThrough(new TextDecoderStream())
|
|
74
|
+
* .pipeThrough(new TextLineTransformStream());
|
|
75
|
+
*
|
|
76
|
+
* for await (const line of lines) {
|
|
77
|
+
* if (line.startsWith('data: ')) {
|
|
78
|
+
* console.log('SSE data:', line.substring(6));
|
|
79
|
+
* }
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
26
82
|
*/
|
|
27
83
|
export declare class TextLineTransformStream extends TransformStream<string, string> {
|
|
84
|
+
/**
|
|
85
|
+
* Creates a new TextLineTransformStream instance.
|
|
86
|
+
*
|
|
87
|
+
* Initializes the stream with a TextLineTransformer that handles the line splitting logic.
|
|
88
|
+
*/
|
|
28
89
|
constructor();
|
|
29
90
|
}
|
|
30
91
|
//# sourceMappingURL=textLineTransformStream.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textLineTransformStream.d.ts","sourceRoot":"","sources":["../src/textLineTransformStream.ts"],"names":[],"mappings":"AAaA
|
|
1
|
+
{"version":3,"file":"textLineTransformStream.d.ts","sourceRoot":"","sources":["../src/textLineTransformStream.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,mBAAoB,YAAW,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC;IACrE,OAAO,CAAC,MAAM,CAAM;IAEpB;;;;;OAKG;IACH,SAAS,CACP,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,gCAAgC,CAAC,MAAM,CAAC;IAetD;;;;OAIG;IACH,KAAK,CAAC,UAAU,EAAE,gCAAgC,CAAC,MAAM,CAAC;CAU3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBAAa,uBAAwB,SAAQ,eAAe,CAAC,MAAM,EAAE,MAAM,CAAC;IAC1E;;;;OAIG;;CAIJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ahoo-wang/fetcher-eventstream",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.9",
|
|
4
4
|
"description": "Server-Sent Events (SSE) support for Fetcher HTTP client with native LLM streaming API support. Enables real-time data streaming and token-by-token LLM response handling.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fetch",
|