@push.rocks/smartstream 3.4.0 → 3.4.2
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/.smartconfig.json +27 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/smartstream.classes.smartduplex.d.ts +2 -2
- package/dist_ts/smartstream.classes.streamwrapper.js +6 -2
- package/dist_ts/smartstream.functions.d.ts +2 -2
- package/dist_ts/smartstream.functions.js +1 -1
- package/dist_ts_web/00_commitinfo_data.js +1 -1
- package/dist_ts_web/classes.webduplexstream.js +5 -2
- package/license +21 -0
- package/package.json +11 -9
- package/readme.md +145 -15
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/smartstream.classes.smartduplex.ts +4 -4
- package/ts/smartstream.classes.streamwrapper.ts +7 -2
- package/ts/smartstream.functions.ts +2 -2
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/classes.webduplexstream.ts +4 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@git.zone/cli": {
|
|
3
|
+
"projectType": "npm",
|
|
4
|
+
"module": {
|
|
5
|
+
"githost": "code.foss.global",
|
|
6
|
+
"gitscope": "push.rocks",
|
|
7
|
+
"gitrepo": "smartstream",
|
|
8
|
+
"description": "A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.",
|
|
9
|
+
"npmPackagename": "@push.rocks/smartstream",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"projectDomain": "push.rocks"
|
|
12
|
+
},
|
|
13
|
+
"release": {
|
|
14
|
+
"registries": [
|
|
15
|
+
"https://verdaccio.lossless.digital",
|
|
16
|
+
"https://registry.npmjs.org"
|
|
17
|
+
],
|
|
18
|
+
"accessLevel": "public"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"@git.zone/tsdoc": {
|
|
22
|
+
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
|
23
|
+
},
|
|
24
|
+
"@ship.zone/szci": {
|
|
25
|
+
"npmGlobalTools": []
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartstream',
|
|
6
|
-
version: '3.4.
|
|
6
|
+
version: '3.4.2',
|
|
7
7
|
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSx5QkFBeUI7SUFDL0IsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLHNMQUFzTDtDQUNwTSxDQUFBIn0=
|
|
@@ -4,10 +4,10 @@ export interface IStreamTools {
|
|
|
4
4
|
push: (pipeObject: any) => Promise<boolean>;
|
|
5
5
|
}
|
|
6
6
|
export interface IStreamWriteFunction<T, rT> {
|
|
7
|
-
(chunkArg: T, toolsArg: IStreamTools): Promise<rT>;
|
|
7
|
+
(chunkArg: T, toolsArg: IStreamTools): Promise<rT | void | null | undefined>;
|
|
8
8
|
}
|
|
9
9
|
export interface IStreamFinalFunction<rT> {
|
|
10
|
-
(toolsArg: IStreamTools): Promise<rT>;
|
|
10
|
+
(toolsArg: IStreamTools): Promise<rT | void | null | undefined>;
|
|
11
11
|
}
|
|
12
12
|
export interface ISmartDuplexOptions<TInput, TOutput> extends DuplexOptions {
|
|
13
13
|
/**
|
|
@@ -51,11 +51,15 @@ export class StreamWrapper {
|
|
|
51
51
|
for (const customEventObject of this.customEventObjectArray) {
|
|
52
52
|
stream.on(customEventObject.eventName, customEventObject.eventFunction);
|
|
53
53
|
}
|
|
54
|
-
if (!firstIteration) {
|
|
54
|
+
if (!firstIteration && finalStream) {
|
|
55
55
|
finalStream = finalStream.pipe(stream);
|
|
56
56
|
}
|
|
57
57
|
firstIteration = false;
|
|
58
58
|
}
|
|
59
|
+
if (!finalStream) {
|
|
60
|
+
done.resolve();
|
|
61
|
+
return done.promise;
|
|
62
|
+
}
|
|
59
63
|
this.streamStartedDeferred.resolve();
|
|
60
64
|
let resolved = false;
|
|
61
65
|
const safeResolve = () => {
|
|
@@ -70,4 +74,4 @@ export class StreamWrapper {
|
|
|
70
74
|
return done.promise;
|
|
71
75
|
}
|
|
72
76
|
}
|
|
73
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
77
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJlYW0uY2xhc3Nlcy5zdHJlYW13cmFwcGVyLmpzIiwic291cmNlUm9vdCI6Ii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0FBRyxFQUFFO1lBQ3ZCLElBQUksQ0FBQyxRQUFRLEVBQUUsQ0FBQztnQkFDZCxRQUFRLEdBQUcsSUFBSSxDQUFDO2dCQUNoQixJQUFJLENBQUMsT0FBTyxFQUFFLENBQUM7WUFDakIsQ0FBQztRQUNILENBQUMsQ0FBQztRQUVGLFdBQVcsQ0FBQyxFQUFFLENBQUMsS0FBSyxFQUFFLFdBQVcsQ0FBQyxDQUFDO1FBQ25DLFdBQVcsQ0FBQyxFQUFFLENBQUMsT0FBTyxFQUFFLFdBQVcsQ0FBQyxDQUFDO1FBQ3JDLFdBQVcsQ0FBQyxFQUFFLENBQUMsUUFBUSxFQUFFLFdBQVcsQ0FBQyxDQUFDO1FBQ3RDLE9BQU8sSUFBSSxDQUFDLE9BQU8sQ0FBQztJQUN0QixDQUFDO0NBQ0YifQ==
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type DuplexOptions } from 'stream';
|
|
2
2
|
import { SmartDuplex } from './smartstream.classes.smartduplex.js';
|
|
3
3
|
export interface AsyncTransformFunction<TInput, TOutput> {
|
|
4
4
|
(chunkArg: TInput): Promise<TOutput>;
|
|
5
5
|
}
|
|
6
|
-
export declare function createTransformFunction<TInput, TOutput>(asyncFunction: AsyncTransformFunction<TInput, TOutput>, options?:
|
|
6
|
+
export declare function createTransformFunction<TInput, TOutput>(asyncFunction: AsyncTransformFunction<TInput, TOutput>, options?: DuplexOptions): SmartDuplex;
|
|
7
7
|
export declare const createPassThrough: () => SmartDuplex<any, any>;
|
|
@@ -18,4 +18,4 @@ export const createPassThrough = () => {
|
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzdHJlYW0uZnVuY3Rpb25zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzdHJlYW0uZnVuY3Rpb25zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBc0IsTUFBTSxRQUFRLENBQUM7QUFDNUMsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLHNDQUFzQyxDQUFDO0FBTW5FLE1BQU0sVUFBVSx1QkFBdUIsQ0FDckMsYUFBc0QsRUFDdEQsT0FBdUI7SUFFdkIsTUFBTSxpQkFBaUIsR0FBRyxJQUFJLFdBQVcsQ0FBQztRQUN4QyxHQUFHLE9BQU87UUFDVixhQUFhLEVBQUUsS0FBSyxFQUFFLFFBQVEsRUFBRSxRQUFRLEVBQUUsRUFBRTtZQUMxQyxNQUFNLE1BQU0sR0FBRyxNQUFNLGFBQWEsQ0FBQyxRQUFRLENBQUMsQ0FBQztZQUM3QyxPQUFPLE1BQU0sQ0FBQztRQUNoQixDQUFDO0tBQ0YsQ0FBQyxDQUFDO0lBRUgsT0FBTyxpQkFBaUIsQ0FBQztBQUMzQixDQUFDO0FBRUQsTUFBTSxDQUFDLE1BQU0saUJBQWlCLEdBQUcsR0FBRyxFQUFFO0lBQ3BDLE9BQU8sSUFBSSxXQUFXLENBQUM7UUFDckIsVUFBVSxFQUFFLElBQUk7UUFDaEIsYUFBYSxFQUFFLEtBQUssRUFBRSxRQUFRLEVBQUUsUUFBUSxFQUFFLEVBQUU7WUFDMUMsT0FBTyxRQUFRLENBQUM7UUFDbEIsQ0FBQztLQUNGLENBQUMsQ0FBQTtBQUNKLENBQUMsQ0FBQSJ9
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartstream',
|
|
6
|
-
version: '3.4.
|
|
6
|
+
version: '3.4.2',
|
|
7
7
|
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHNfd2ViLzAwX2NvbW1pdGluZm9fZGF0YS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7R0FFRztBQUNILE1BQU0sQ0FBQyxNQUFNLFVBQVUsR0FBRztJQUN4QixJQUFJLEVBQUUseUJBQXlCO0lBQy9CLE9BQU8sRUFBRSxPQUFPO0lBQ2hCLFdBQVcsRUFBRSxzTEFBc0w7Q0FDcE0sQ0FBQSJ9
|
|
@@ -64,7 +64,10 @@ export class WebDuplexStream extends TransformStream {
|
|
|
64
64
|
write: async (writeArg) => await writer.write(writeArg),
|
|
65
65
|
};
|
|
66
66
|
try {
|
|
67
|
-
|
|
67
|
+
const readFunction = this.options.readFunction;
|
|
68
|
+
if (readFunction) {
|
|
69
|
+
await readFunction(tools);
|
|
70
|
+
}
|
|
68
71
|
if (doneSignaled) {
|
|
69
72
|
await writer.close();
|
|
70
73
|
}
|
|
@@ -91,4 +94,4 @@ export class WebDuplexStream extends TransformStream {
|
|
|
91
94
|
return stream;
|
|
92
95
|
}
|
|
93
96
|
}
|
|
94
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
97
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhc3Nlcy53ZWJkdXBsZXhzdHJlYW0uanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90c193ZWIvY2xhc3Nlcy53ZWJkdXBsZXhzdHJlYW0udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLE9BQU8sTUFBTSxjQUFjLENBQUM7QUEwQ3hDLE1BQU0sT0FBTyxlQUE2QyxTQUFRLGVBQWdDO0lBSWhHLFlBQVksVUFBbUQ7UUFDN0QsS0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MsQ0FBQyxDQUFDLGdDQUFnQztnQkFDN0MsT0FBTyxJQUFJLENBQUM7WUFDZCxDQUFDO1NBQ0YsQ0FBQyxDQUFDO1FBRUgsTUFBTSxNQUFNLEdBQUcsTUFBTSxDQUFDLFFBQVEsQ0FBQyxTQUFTLEVBQUUsQ0FBQztRQUMzQyxNQUFNLENBQUMsS0FBSyxDQUFDLFVBQVUsQ0FBQyxDQUFDLElBQUksQ0FBQyxHQUFHLEVBQUUsQ0FBQyxNQUFNLENBQUMsS0FBSyxFQUFFLENBQUMsQ0FBQyxLQUFLLENBQUMsR0FBRyxFQUFFLEdBQUUsQ0FBQyxDQUFDLENBQUM7UUFFcEUsT0FBTyxNQUFNLENBQUM7SUFDaEIsQ0FBQztDQUNGIn0=
|
package/license
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Push.Rocks
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@push.rocks/smartstream",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.",
|
|
6
6
|
"type": "module",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"test": "(tstest test/ --verbose --logfile --timeout 60)",
|
|
13
|
-
"build": "(tsbuild tsfolders
|
|
13
|
+
"build": "(tsbuild tsfolders)"
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
@@ -23,14 +23,13 @@
|
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://code.foss.global/push.rocks/smartstream",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@git.zone/tsbuild": "^4.
|
|
27
|
-
"@git.zone/tsrun": "^2.0.
|
|
28
|
-
"@git.zone/tstest": "^3.
|
|
29
|
-
"@
|
|
30
|
-
"@types/node": "^25.3.3"
|
|
26
|
+
"@git.zone/tsbuild": "^4.4.0",
|
|
27
|
+
"@git.zone/tsrun": "^2.0.2",
|
|
28
|
+
"@git.zone/tstest": "^3.6.3",
|
|
29
|
+
"@types/node": "^25.6.0"
|
|
31
30
|
},
|
|
32
31
|
"dependencies": {
|
|
33
|
-
"@push.rocks/lik": "^6.
|
|
32
|
+
"@push.rocks/lik": "^6.4.1",
|
|
34
33
|
"@push.rocks/smartenv": "^6.0.0",
|
|
35
34
|
"@push.rocks/smartpromise": "^4.2.3",
|
|
36
35
|
"@push.rocks/smartrx": "^3.0.10"
|
|
@@ -47,6 +46,8 @@
|
|
|
47
46
|
"dist_ts_web/**/*",
|
|
48
47
|
"assets/**/*",
|
|
49
48
|
"cli.js",
|
|
49
|
+
".smartconfig.json",
|
|
50
|
+
"license",
|
|
50
51
|
"npmextra.json",
|
|
51
52
|
"readme.md"
|
|
52
53
|
],
|
|
@@ -73,5 +74,6 @@
|
|
|
73
74
|
"buffer",
|
|
74
75
|
"stream utilities",
|
|
75
76
|
"esm"
|
|
76
|
-
]
|
|
77
|
+
],
|
|
78
|
+
"packageManager": "pnpm@10.28.2"
|
|
77
79
|
}
|
package/readme.md
CHANGED
|
@@ -12,7 +12,7 @@ For reporting bugs, issues, or security vulnerabilities, please visit [community
|
|
|
12
12
|
pnpm install @push.rocks/smartstream
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
The package ships with two entry points:
|
|
15
|
+
The package ships with **two entry points** so you can pick exactly what you need:
|
|
16
16
|
|
|
17
17
|
| Entry Point | Import Path | Environment |
|
|
18
18
|
|---|---|---|
|
|
@@ -83,6 +83,8 @@ const splitter = new SmartDuplex<string, string>({
|
|
|
83
83
|
Run cleanup or emit final data when the writable side ends:
|
|
84
84
|
|
|
85
85
|
```typescript
|
|
86
|
+
let runningTotal = 0;
|
|
87
|
+
|
|
86
88
|
const aggregator = new SmartDuplex<number, number>({
|
|
87
89
|
objectMode: true,
|
|
88
90
|
writeFunction: async (chunk, tools) => {
|
|
@@ -95,6 +97,8 @@ const aggregator = new SmartDuplex<number, number>({
|
|
|
95
97
|
});
|
|
96
98
|
```
|
|
97
99
|
|
|
100
|
+
The `finalFunction` can also push multiple chunks via `tools.push()`, just like `writeFunction`.
|
|
101
|
+
|
|
98
102
|
#### Truncating a Stream Early
|
|
99
103
|
|
|
100
104
|
Call `tools.truncate()` inside `writeFunction` to signal that no more data should be read:
|
|
@@ -132,16 +136,36 @@ nodeDuplex.pipe(processTransform).pipe(outputStream);
|
|
|
132
136
|
|
|
133
137
|
#### Getting Web Streams from SmartDuplex
|
|
134
138
|
|
|
135
|
-
Convert a `SmartDuplex` into Web `ReadableStream` + `WritableStream` pair:
|
|
139
|
+
Convert a `SmartDuplex` into a Web `ReadableStream` + `WritableStream` pair:
|
|
136
140
|
|
|
137
141
|
```typescript
|
|
138
142
|
const duplex = new SmartDuplex({
|
|
143
|
+
objectMode: true,
|
|
139
144
|
writeFunction: async (chunk, tools) => {
|
|
140
145
|
return transform(chunk);
|
|
141
146
|
},
|
|
142
147
|
});
|
|
143
148
|
|
|
144
149
|
const { readable, writable } = await duplex.getWebStreams();
|
|
150
|
+
|
|
151
|
+
const writer = writable.getWriter();
|
|
152
|
+
const reader = readable.getReader();
|
|
153
|
+
|
|
154
|
+
// Read and write concurrently to avoid TransformStream backpressure
|
|
155
|
+
const readAll = async () => {
|
|
156
|
+
const results = [];
|
|
157
|
+
while (true) {
|
|
158
|
+
const { value, done } = await reader.read();
|
|
159
|
+
if (done) break;
|
|
160
|
+
results.push(value);
|
|
161
|
+
}
|
|
162
|
+
return results;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const readPromise = readAll();
|
|
166
|
+
await writer.write('hello');
|
|
167
|
+
await writer.close();
|
|
168
|
+
const results = await readPromise;
|
|
145
169
|
```
|
|
146
170
|
|
|
147
171
|
#### Debug Mode
|
|
@@ -186,7 +210,7 @@ pipeline.run()
|
|
|
186
210
|
.catch((err) => console.error('Pipeline failed:', err));
|
|
187
211
|
```
|
|
188
212
|
|
|
189
|
-
You can
|
|
213
|
+
You can listen for custom events across all streams in the pipeline:
|
|
190
214
|
|
|
191
215
|
```typescript
|
|
192
216
|
pipeline.onCustomEvent('progress', () => {
|
|
@@ -194,6 +218,14 @@ pipeline.onCustomEvent('progress', () => {
|
|
|
194
218
|
});
|
|
195
219
|
```
|
|
196
220
|
|
|
221
|
+
You can also await `streamStarted()` to know when the pipeline has been wired up:
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
const runPromise = pipeline.run();
|
|
225
|
+
await pipeline.streamStarted(); // Resolves once pipes are connected
|
|
226
|
+
await runPromise;
|
|
227
|
+
```
|
|
228
|
+
|
|
197
229
|
---
|
|
198
230
|
|
|
199
231
|
### 📥 StreamIntake — Dynamic Data Injection
|
|
@@ -222,7 +254,7 @@ intake.pushData('World');
|
|
|
222
254
|
intake.signalEnd(); // Signal end-of-stream
|
|
223
255
|
```
|
|
224
256
|
|
|
225
|
-
#### Demand-
|
|
257
|
+
#### Demand-Driven Production with Observable
|
|
226
258
|
|
|
227
259
|
`pushNextObservable` emits whenever the stream is ready for more data — perfect for throttled or event-driven producers:
|
|
228
260
|
|
|
@@ -265,7 +297,10 @@ Quickly create a `SmartDuplex` from a simple async mapping function:
|
|
|
265
297
|
```typescript
|
|
266
298
|
import { createTransformFunction } from '@push.rocks/smartstream';
|
|
267
299
|
|
|
268
|
-
const doubler = createTransformFunction<number, number>(
|
|
300
|
+
const doubler = createTransformFunction<number, number>(
|
|
301
|
+
async (n) => n * 2,
|
|
302
|
+
{ objectMode: true }
|
|
303
|
+
);
|
|
269
304
|
|
|
270
305
|
intakeStream.pipe(doubler).pipe(outputStream);
|
|
271
306
|
```
|
|
@@ -299,16 +334,26 @@ const stream = new WebDuplexStream<number, number>({
|
|
|
299
334
|
const writer = stream.writable.getWriter();
|
|
300
335
|
const reader = stream.readable.getReader();
|
|
301
336
|
|
|
302
|
-
//
|
|
337
|
+
// Always read concurrently with writes — TransformStream applies backpressure
|
|
338
|
+
const readPromise = (async () => {
|
|
339
|
+
const results = [];
|
|
340
|
+
while (true) {
|
|
341
|
+
const { value, done } = await reader.read();
|
|
342
|
+
if (done) break;
|
|
343
|
+
results.push(value);
|
|
344
|
+
}
|
|
345
|
+
return results;
|
|
346
|
+
})();
|
|
347
|
+
|
|
303
348
|
await writer.write(5);
|
|
304
349
|
await writer.write(10);
|
|
305
350
|
await writer.close();
|
|
306
351
|
|
|
307
|
-
//
|
|
308
|
-
const { value } = await reader.read(); // 10
|
|
309
|
-
const { value: v2 } = await reader.read(); // 20
|
|
352
|
+
const results = await readPromise; // [10, 20]
|
|
310
353
|
```
|
|
311
354
|
|
|
355
|
+
> 💡 **Tip:** Because `TransformStream` enforces backpressure between its writable and readable sides, you must start reading *before* or *concurrently with* writes. If you await all writes first and then read, the writes will block waiting for the readable side to drain.
|
|
356
|
+
|
|
312
357
|
#### From a Uint8Array
|
|
313
358
|
|
|
314
359
|
```typescript
|
|
@@ -337,11 +382,24 @@ const reader = stream.readable.getReader();
|
|
|
337
382
|
// reads "CHUNK 1", "CHUNK 2"
|
|
338
383
|
```
|
|
339
384
|
|
|
385
|
+
#### Final Function
|
|
386
|
+
|
|
387
|
+
Emit trailing data when the writable side is closed:
|
|
388
|
+
|
|
389
|
+
```typescript
|
|
390
|
+
const stream = new WebDuplexStream<string, string>({
|
|
391
|
+
writeFunction: async (chunk) => chunk,
|
|
392
|
+
finalFunction: async (tools) => {
|
|
393
|
+
tools.push('footer');
|
|
394
|
+
},
|
|
395
|
+
});
|
|
396
|
+
```
|
|
397
|
+
|
|
340
398
|
---
|
|
341
399
|
|
|
342
400
|
### 🔀 Node ↔ Web Stream Converters
|
|
343
401
|
|
|
344
|
-
The `nodewebhelpers` namespace provides bidirectional converters between Node.js and Web Streams:
|
|
402
|
+
The `nodewebhelpers` namespace provides bidirectional converters between Node.js and Web Streams with proper backpressure handling:
|
|
345
403
|
|
|
346
404
|
```typescript
|
|
347
405
|
import { nodewebhelpers } from '@push.rocks/smartstream';
|
|
@@ -381,6 +439,16 @@ const nodeReadable2 = nodewebhelpers.convertWebReadableToNodeReadable(webReadabl
|
|
|
381
439
|
nodeReadable2.pipe(fs.createWriteStream('./copy.bin'));
|
|
382
440
|
```
|
|
383
441
|
|
|
442
|
+
#### Example: Round-Trip Conversion
|
|
443
|
+
|
|
444
|
+
```typescript
|
|
445
|
+
// Node → Web → Node (lossless round-trip)
|
|
446
|
+
const original = fs.createReadStream('./photo.jpg');
|
|
447
|
+
const webStream = nodewebhelpers.convertNodeReadableToWebReadable(original);
|
|
448
|
+
const backToNode = nodewebhelpers.convertWebReadableToNodeReadable(webStream);
|
|
449
|
+
backToNode.pipe(fs.createWriteStream('./photo-copy.jpg'));
|
|
450
|
+
```
|
|
451
|
+
|
|
384
452
|
---
|
|
385
453
|
|
|
386
454
|
### 🏗️ Backpressure Handling
|
|
@@ -417,25 +485,23 @@ fast.end();
|
|
|
417
485
|
|
|
418
486
|
---
|
|
419
487
|
|
|
420
|
-
### 🎯 Real-World Example: Processing Pipeline
|
|
488
|
+
### 🎯 Real-World Example: Log Processing Pipeline
|
|
421
489
|
|
|
422
490
|
```typescript
|
|
423
491
|
import fs from 'fs';
|
|
424
492
|
import { SmartDuplex, StreamWrapper } from '@push.rocks/smartstream';
|
|
425
493
|
|
|
426
|
-
// Read →
|
|
494
|
+
// Read → Parse → Filter → Write
|
|
427
495
|
const pipeline = new StreamWrapper([
|
|
428
496
|
fs.createReadStream('./access.log'),
|
|
429
497
|
new SmartDuplex({
|
|
430
498
|
writeFunction: async (chunk) => {
|
|
431
|
-
// Parse each line
|
|
432
499
|
return chunk.toString().split('\n');
|
|
433
500
|
},
|
|
434
501
|
}),
|
|
435
502
|
new SmartDuplex({
|
|
436
503
|
objectMode: true,
|
|
437
504
|
writeFunction: async (lines: string[], tools) => {
|
|
438
|
-
// Filter and push matching lines
|
|
439
505
|
for (const line of lines) {
|
|
440
506
|
if (line.includes('ERROR')) {
|
|
441
507
|
await tools.push(line + '\n');
|
|
@@ -450,6 +516,70 @@ await pipeline.run();
|
|
|
450
516
|
console.log('Error extraction complete');
|
|
451
517
|
```
|
|
452
518
|
|
|
519
|
+
---
|
|
520
|
+
|
|
521
|
+
### 📋 API Reference
|
|
522
|
+
|
|
523
|
+
#### SmartDuplex
|
|
524
|
+
|
|
525
|
+
| Member | Type | Description |
|
|
526
|
+
|---|---|---|
|
|
527
|
+
| `new SmartDuplex(options?)` | Constructor | Create a new duplex stream |
|
|
528
|
+
| `options.writeFunction` | `(chunk, tools) => Promise<T>` | Transform each chunk; return to push, or use `tools.push()` |
|
|
529
|
+
| `options.finalFunction` | `(tools) => Promise<T>` | Emit final data when writable ends |
|
|
530
|
+
| `options.readFunction` | `() => Promise<void>` | Supply data to the readable side |
|
|
531
|
+
| `options.debug` | `boolean` | Enable internal logging |
|
|
532
|
+
| `options.name` | `string` | Stream name for debug logs |
|
|
533
|
+
| `SmartDuplex.fromBuffer(buf)` | Static | Create a readable stream from a Buffer |
|
|
534
|
+
| `SmartDuplex.fromWebReadableStream(rs)` | Static | Bridge a Web ReadableStream to Node.js Duplex |
|
|
535
|
+
| `duplex.getWebStreams()` | Method | Get `{ readable, writable }` Web Streams pair |
|
|
536
|
+
|
|
537
|
+
#### WebDuplexStream
|
|
538
|
+
|
|
539
|
+
| Member | Type | Description |
|
|
540
|
+
|---|---|---|
|
|
541
|
+
| `new WebDuplexStream(options)` | Constructor | Create a new web transform stream |
|
|
542
|
+
| `options.writeFunction` | `(chunk, tools) => Promise<T>` | Transform each chunk; use `tools.push()` or return |
|
|
543
|
+
| `options.finalFunction` | `(tools) => Promise<T>` | Emit data on flush |
|
|
544
|
+
| `options.readFunction` | `(tools) => Promise<void>` | Supply data via `tools.write()`, signal `tools.done()` |
|
|
545
|
+
| `WebDuplexStream.fromUInt8Array(arr)` | Static | Create a stream from a Uint8Array |
|
|
546
|
+
|
|
547
|
+
#### StreamWrapper
|
|
548
|
+
|
|
549
|
+
| Member | Type | Description |
|
|
550
|
+
|---|---|---|
|
|
551
|
+
| `new StreamWrapper(streams[])` | Constructor | Create a pipeline from an array of streams |
|
|
552
|
+
| `wrapper.run()` | Method | Pipe all streams and return a Promise |
|
|
553
|
+
| `wrapper.streamStarted()` | Method | Promise that resolves when pipes are connected |
|
|
554
|
+
| `wrapper.onCustomEvent(name, fn)` | Method | Listen for custom events across all streams |
|
|
555
|
+
|
|
556
|
+
#### StreamIntake
|
|
557
|
+
|
|
558
|
+
| Member | Type | Description |
|
|
559
|
+
|---|---|---|
|
|
560
|
+
| `new StreamIntake<T>()` | Constructor | Create a new intake stream (object mode) |
|
|
561
|
+
| `intake.pushData(data)` | Method | Push data into the stream |
|
|
562
|
+
| `intake.signalEnd()` | Method | Signal end of stream |
|
|
563
|
+
| `intake.pushNextObservable` | Property | Observable that emits when the stream wants more data |
|
|
564
|
+
| `StreamIntake.fromStream(stream)` | Static | Wrap a Node.js Readable or Web ReadableStream |
|
|
565
|
+
|
|
566
|
+
#### nodewebhelpers
|
|
567
|
+
|
|
568
|
+
| Function | Description |
|
|
569
|
+
|---|---|
|
|
570
|
+
| `createWebReadableStreamFromFile(path)` | File → Web ReadableStream (pull-based backpressure) |
|
|
571
|
+
| `convertWebReadableToNodeReadable(rs)` | Web ReadableStream → Node.js Readable |
|
|
572
|
+
| `convertNodeReadableToWebReadable(ns)` | Node.js Readable → Web ReadableStream (pull-based backpressure) |
|
|
573
|
+
| `convertWebWritableToNodeWritable(ws)` | Web WritableStream → Node.js Writable |
|
|
574
|
+
| `convertNodeWritableToWebWritable(nw)` | Node.js Writable → Web WritableStream |
|
|
575
|
+
|
|
576
|
+
#### Utility Functions
|
|
577
|
+
|
|
578
|
+
| Function | Description |
|
|
579
|
+
|---|---|
|
|
580
|
+
| `createTransformFunction(fn, opts?)` | Create a SmartDuplex from an async mapping function |
|
|
581
|
+
| `createPassThrough()` | Create an object-mode passthrough stream |
|
|
582
|
+
|
|
453
583
|
## License and Legal Information
|
|
454
584
|
|
|
455
585
|
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
|
|
@@ -464,7 +594,7 @@ Use of these trademarks must comply with Task Venture Capital GmbH's Trademark G
|
|
|
464
594
|
|
|
465
595
|
### Company Information
|
|
466
596
|
|
|
467
|
-
Task Venture Capital GmbH
|
|
597
|
+
Task Venture Capital GmbH
|
|
468
598
|
Registered at District Court Bremen HRB 35230 HB, Germany
|
|
469
599
|
|
|
470
600
|
For any legal inquiries or further information, please contact us via email at hello@task.vc.
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartstream',
|
|
6
|
-
version: '3.4.
|
|
6
|
+
version: '3.4.2',
|
|
7
7
|
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
|
|
8
8
|
}
|
|
@@ -7,11 +7,11 @@ export interface IStreamTools {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export interface IStreamWriteFunction<T, rT> {
|
|
10
|
-
(chunkArg: T, toolsArg: IStreamTools): Promise<rT>;
|
|
10
|
+
(chunkArg: T, toolsArg: IStreamTools): Promise<rT | void | null | undefined>;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export interface IStreamFinalFunction<rT> {
|
|
14
|
-
(toolsArg: IStreamTools): Promise<rT>;
|
|
14
|
+
(toolsArg: IStreamTools): Promise<rT | void | null | undefined>;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export interface ISmartDuplexOptions<TInput, TOutput> extends DuplexOptions {
|
|
@@ -92,7 +92,7 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
// INSTANCE
|
|
95
|
-
private backpressuredArray: plugins.lik.BackpressuredArray<TOutput>;
|
|
95
|
+
private backpressuredArray: plugins.lik.BackpressuredArray<TOutput | null>;
|
|
96
96
|
public options: ISmartDuplexOptions<TInput, TOutput>;
|
|
97
97
|
private _consumerWantsData = false;
|
|
98
98
|
private _readFunctionRunning = false;
|
|
@@ -114,7 +114,7 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
|
|
|
114
114
|
)
|
|
115
115
|
);
|
|
116
116
|
this.options = safeOptions;
|
|
117
|
-
this.backpressuredArray = new plugins.lik.BackpressuredArray<TOutput>(
|
|
117
|
+
this.backpressuredArray = new plugins.lik.BackpressuredArray<TOutput | null>(
|
|
118
118
|
this.options.highWaterMark || 1
|
|
119
119
|
);
|
|
120
120
|
}
|
|
@@ -59,7 +59,7 @@ export class StreamWrapper {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
// combine the stream
|
|
62
|
-
let finalStream = null;
|
|
62
|
+
let finalStream: plugins.stream.Duplex | null = null;
|
|
63
63
|
let firstIteration: boolean = true;
|
|
64
64
|
for (const stream of streamExecutionArray) {
|
|
65
65
|
if (firstIteration === true) {
|
|
@@ -71,12 +71,17 @@ export class StreamWrapper {
|
|
|
71
71
|
for (const customEventObject of this.customEventObjectArray) {
|
|
72
72
|
stream.on(customEventObject.eventName, customEventObject.eventFunction);
|
|
73
73
|
}
|
|
74
|
-
if (!firstIteration) {
|
|
74
|
+
if (!firstIteration && finalStream) {
|
|
75
75
|
finalStream = finalStream.pipe(stream);
|
|
76
76
|
}
|
|
77
77
|
firstIteration = false;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
if (!finalStream) {
|
|
81
|
+
done.resolve();
|
|
82
|
+
return done.promise;
|
|
83
|
+
}
|
|
84
|
+
|
|
80
85
|
this.streamStartedDeferred.resolve();
|
|
81
86
|
|
|
82
87
|
let resolved = false;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type DuplexOptions } from 'stream';
|
|
2
2
|
import { SmartDuplex } from './smartstream.classes.smartduplex.js';
|
|
3
3
|
|
|
4
4
|
export interface AsyncTransformFunction<TInput, TOutput> {
|
|
@@ -7,7 +7,7 @@ export interface AsyncTransformFunction<TInput, TOutput> {
|
|
|
7
7
|
|
|
8
8
|
export function createTransformFunction<TInput, TOutput>(
|
|
9
9
|
asyncFunction: AsyncTransformFunction<TInput, TOutput>,
|
|
10
|
-
options?:
|
|
10
|
+
options?: DuplexOptions
|
|
11
11
|
): SmartDuplex {
|
|
12
12
|
const smartDuplexStream = new SmartDuplex({
|
|
13
13
|
...options,
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@push.rocks/smartstream',
|
|
6
|
-
version: '3.4.
|
|
6
|
+
version: '3.4.2',
|
|
7
7
|
description: 'A library to simplify the creation and manipulation of Node.js streams, providing utilities for handling transform, duplex, and readable/writable streams effectively in TypeScript.'
|
|
8
8
|
}
|
|
@@ -112,7 +112,10 @@ export class WebDuplexStream<TInput = any, TOutput = any> extends TransformStrea
|
|
|
112
112
|
};
|
|
113
113
|
|
|
114
114
|
try {
|
|
115
|
-
|
|
115
|
+
const readFunction = this.options.readFunction;
|
|
116
|
+
if (readFunction) {
|
|
117
|
+
await readFunction(tools);
|
|
118
|
+
}
|
|
116
119
|
if (doneSignaled) {
|
|
117
120
|
await writer.close();
|
|
118
121
|
}
|