fix(streams): tighten stream typings and guard optional runtime paths for duplex and wrapper utilities
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"@git.zone/cli": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "code.foss.global",
|
||||||
|
"gitscope": "push.rocks",
|
||||||
|
"gitrepo": "smartstream",
|
||||||
|
"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.",
|
||||||
|
"npmPackagename": "@push.rocks/smartstream",
|
||||||
|
"license": "MIT",
|
||||||
|
"projectDomain": "push.rocks"
|
||||||
|
},
|
||||||
|
"release": {
|
||||||
|
"registries": [
|
||||||
|
"https://verdaccio.lossless.digital",
|
||||||
|
"https://registry.npmjs.org"
|
||||||
|
],
|
||||||
|
"accessLevel": "public"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@git.zone/tsdoc": {
|
||||||
|
"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"
|
||||||
|
},
|
||||||
|
"@ship.zone/szci": {
|
||||||
|
"npmGlobalTools": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,13 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2026-04-30 - 3.4.2 - fix(streams)
|
||||||
|
tighten stream typings and guard optional runtime paths for duplex and wrapper utilities
|
||||||
|
|
||||||
|
- allow SmartDuplex write and final handlers to return empty values in addition to transformed output
|
||||||
|
- prevent StreamWrapper from piping or starting when no executable stream chain is produced
|
||||||
|
- guard optional WebDuplexStream readFunction execution before invoking it
|
||||||
|
- update tests and TypeScript configuration to satisfy stricter noImplicitAny checks and newer tstest tooling
|
||||||
|
|
||||||
## 2026-03-02 - 3.4.1 - fix(readme)
|
## 2026-03-02 - 3.4.1 - fix(readme)
|
||||||
improve README: clarify entry points, add Web & Node stream examples, finalization and backpressure tips, and comprehensive API reference
|
improve README: clarify entry points, add Web & Node stream examples, finalization and backpressure tips, and comprehensive API reference
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2016 Push.Rocks
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
+10
-8
@@ -10,7 +10,7 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/ --verbose --logfile --timeout 60)",
|
"test": "(tstest test/ --verbose --logfile --timeout 60)",
|
||||||
"build": "(tsbuild tsfolders --allowimplicitany)"
|
"build": "(tsbuild tsfolders)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -23,14 +23,13 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://code.foss.global/push.rocks/smartstream",
|
"homepage": "https://code.foss.global/push.rocks/smartstream",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^4.1.2",
|
"@git.zone/tsbuild": "^4.4.0",
|
||||||
"@git.zone/tsrun": "^2.0.1",
|
"@git.zone/tsrun": "^2.0.2",
|
||||||
"@git.zone/tstest": "^3.1.8",
|
"@git.zone/tstest": "^3.6.3",
|
||||||
"@push.rocks/tapbundle": "^6.0.3",
|
"@types/node": "^25.6.0"
|
||||||
"@types/node": "^25.3.3"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@push.rocks/lik": "^6.3.1",
|
"@push.rocks/lik": "^6.4.1",
|
||||||
"@push.rocks/smartenv": "^6.0.0",
|
"@push.rocks/smartenv": "^6.0.0",
|
||||||
"@push.rocks/smartpromise": "^4.2.3",
|
"@push.rocks/smartpromise": "^4.2.3",
|
||||||
"@push.rocks/smartrx": "^3.0.10"
|
"@push.rocks/smartrx": "^3.0.10"
|
||||||
@@ -47,6 +46,8 @@
|
|||||||
"dist_ts_web/**/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/**/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
|
".smartconfig.json",
|
||||||
|
"license",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
],
|
],
|
||||||
@@ -73,5 +74,6 @@
|
|||||||
"buffer",
|
"buffer",
|
||||||
"stream utilities",
|
"stream utilities",
|
||||||
"esm"
|
"esm"
|
||||||
]
|
],
|
||||||
|
"packageManager": "pnpm@10.28.2"
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+1584
-4216
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,4 @@
|
|||||||
import { tap, expect } from '@push.rocks/tapbundle';
|
import { tap, expect } from '@git.zone/tstest/tapbundle';
|
||||||
import { SmartDuplex } from '../ts/index.js';
|
import { SmartDuplex } from '../ts/index.js';
|
||||||
|
|
||||||
tap.test('Backpressure: should apply backpressure across piped streams', async (toolsArg) => {
|
tap.test('Backpressure: should apply backpressure across piped streams', async (toolsArg) => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { expect, tap } from '@push.rocks/tapbundle';
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as stream from 'stream';
|
import * as stream from 'stream';
|
||||||
import { nodewebhelpers } from '../ts/index.js';
|
import { nodewebhelpers } from '../ts/index.js';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { expect, tap } from '@push.rocks/tapbundle';
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as smartstream from '../ts/index.js';
|
import * as smartstream from '../ts/index.js';
|
||||||
import { SmartDuplex } from '../ts/smartstream.classes.smartduplex.js';
|
import { SmartDuplex } from '../ts/smartstream.classes.smartduplex.js';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { expect, tap } from '@push.rocks/tapbundle';
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { StreamIntake, SmartDuplex } from '../ts/index.js';
|
import { StreamIntake, SmartDuplex } from '../ts/index.js';
|
||||||
import * as stream from 'stream';
|
import * as stream from 'stream';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { expect, tap } from '@push.rocks/tapbundle';
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { StreamWrapper, SmartDuplex } from '../ts/index.js';
|
import { StreamWrapper, SmartDuplex } from '../ts/index.js';
|
||||||
|
|
||||||
@@ -27,7 +27,8 @@ tap.test('StreamWrapper: should propagate errors', async (tools) => {
|
|||||||
await wrapper.run();
|
await wrapper.run();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
errorCaught = true;
|
errorCaught = true;
|
||||||
expect(err.message).toEqual('intentional error');
|
const message = err instanceof Error ? err.message : String(err);
|
||||||
|
expect(message).toEqual('intentional error');
|
||||||
}
|
}
|
||||||
expect(errorCaught).toBeTrue();
|
expect(errorCaught).toBeTrue();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { expect, tap } from '@push.rocks/tapbundle';
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
import { createTransformFunction, createPassThrough, SmartDuplex, StreamWrapper } from '../ts/index.js';
|
import { createTransformFunction, createPassThrough, SmartDuplex, StreamWrapper } from '../ts/index.js';
|
||||||
|
|
||||||
// =============================================
|
// =============================================
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { expect, tap } from '@push.rocks/tapbundle';
|
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||||
import { WebDuplexStream } from '../ts_web/index.js';
|
import { WebDuplexStream } from '../ts_web/index.js';
|
||||||
|
|
||||||
// Helper: collect all chunks from a readable
|
// Helper: collect all chunks from a readable
|
||||||
async function collectAll<T>(reader: ReadableStreamDefaultReader<T>): Promise<T[]> {
|
async function collectAll<T>(reader: ReadableStreamDefaultReader<T>): Promise<T[]> {
|
||||||
const results: T[] = [];
|
const results: T[] = [];
|
||||||
while (true) {
|
while (true) {
|
||||||
const { value, done } = await reader.read();
|
const result = await reader.read();
|
||||||
if (done) break;
|
if (result.done) break;
|
||||||
results.push(value);
|
results.push(result.value);
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
@@ -70,6 +70,9 @@ tap.test('WebDuplexStream: fromUInt8Array should produce data', async () => {
|
|||||||
|
|
||||||
const { value } = await reader.read();
|
const { value } = await reader.read();
|
||||||
expect(value).toBeTruthy();
|
expect(value).toBeTruthy();
|
||||||
|
if (!value) {
|
||||||
|
throw new Error('Expected fromUInt8Array to produce data');
|
||||||
|
}
|
||||||
expect(value.length).toEqual(5);
|
expect(value.length).toEqual(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartstream',
|
name: '@push.rocks/smartstream',
|
||||||
version: '3.4.1',
|
version: '3.4.2',
|
||||||
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.'
|
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.'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ export interface IStreamTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IStreamWriteFunction<T, rT> {
|
export interface IStreamWriteFunction<T, rT> {
|
||||||
(chunkArg: T, toolsArg: IStreamTools): Promise<rT>;
|
(chunkArg: T, toolsArg: IStreamTools): Promise<rT | void | null | undefined>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IStreamFinalFunction<rT> {
|
export interface IStreamFinalFunction<rT> {
|
||||||
(toolsArg: IStreamTools): Promise<rT>;
|
(toolsArg: IStreamTools): Promise<rT | void | null | undefined>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ISmartDuplexOptions<TInput, TOutput> extends DuplexOptions {
|
export interface ISmartDuplexOptions<TInput, TOutput> extends DuplexOptions {
|
||||||
@@ -92,7 +92,7 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// INSTANCE
|
// INSTANCE
|
||||||
private backpressuredArray: plugins.lik.BackpressuredArray<TOutput>;
|
private backpressuredArray: plugins.lik.BackpressuredArray<TOutput | null>;
|
||||||
public options: ISmartDuplexOptions<TInput, TOutput>;
|
public options: ISmartDuplexOptions<TInput, TOutput>;
|
||||||
private _consumerWantsData = false;
|
private _consumerWantsData = false;
|
||||||
private _readFunctionRunning = false;
|
private _readFunctionRunning = false;
|
||||||
@@ -114,7 +114,7 @@ export class SmartDuplex<TInput = any, TOutput = any> extends Duplex {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
this.options = safeOptions;
|
this.options = safeOptions;
|
||||||
this.backpressuredArray = new plugins.lik.BackpressuredArray<TOutput>(
|
this.backpressuredArray = new plugins.lik.BackpressuredArray<TOutput | null>(
|
||||||
this.options.highWaterMark || 1
|
this.options.highWaterMark || 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ export class StreamWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// combine the stream
|
// combine the stream
|
||||||
let finalStream = null;
|
let finalStream: plugins.stream.Duplex | null = null;
|
||||||
let firstIteration: boolean = true;
|
let firstIteration: boolean = true;
|
||||||
for (const stream of streamExecutionArray) {
|
for (const stream of streamExecutionArray) {
|
||||||
if (firstIteration === true) {
|
if (firstIteration === true) {
|
||||||
@@ -71,12 +71,17 @@ export class StreamWrapper {
|
|||||||
for (const customEventObject of this.customEventObjectArray) {
|
for (const customEventObject of this.customEventObjectArray) {
|
||||||
stream.on(customEventObject.eventName, customEventObject.eventFunction);
|
stream.on(customEventObject.eventName, customEventObject.eventFunction);
|
||||||
}
|
}
|
||||||
if (!firstIteration) {
|
if (!firstIteration && finalStream) {
|
||||||
finalStream = finalStream.pipe(stream);
|
finalStream = finalStream.pipe(stream);
|
||||||
}
|
}
|
||||||
firstIteration = false;
|
firstIteration = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!finalStream) {
|
||||||
|
done.resolve();
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
|
||||||
this.streamStartedDeferred.resolve();
|
this.streamStartedDeferred.resolve();
|
||||||
|
|
||||||
let resolved = false;
|
let resolved = false;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { type TransformOptions } from 'stream';
|
import { type DuplexOptions } from 'stream';
|
||||||
import { SmartDuplex } from './smartstream.classes.smartduplex.js';
|
import { SmartDuplex } from './smartstream.classes.smartduplex.js';
|
||||||
|
|
||||||
export interface AsyncTransformFunction<TInput, TOutput> {
|
export interface AsyncTransformFunction<TInput, TOutput> {
|
||||||
@@ -7,7 +7,7 @@ export interface AsyncTransformFunction<TInput, TOutput> {
|
|||||||
|
|
||||||
export function createTransformFunction<TInput, TOutput>(
|
export function createTransformFunction<TInput, TOutput>(
|
||||||
asyncFunction: AsyncTransformFunction<TInput, TOutput>,
|
asyncFunction: AsyncTransformFunction<TInput, TOutput>,
|
||||||
options?: TransformOptions
|
options?: DuplexOptions
|
||||||
): SmartDuplex {
|
): SmartDuplex {
|
||||||
const smartDuplexStream = new SmartDuplex({
|
const smartDuplexStream = new SmartDuplex({
|
||||||
...options,
|
...options,
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartstream',
|
name: '@push.rocks/smartstream',
|
||||||
version: '3.4.1',
|
version: '3.4.2',
|
||||||
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.'
|
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.'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,10 @@ export class WebDuplexStream<TInput = any, TOutput = any> extends TransformStrea
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.options.readFunction(tools);
|
const readFunction = this.options.readFunction;
|
||||||
|
if (readFunction) {
|
||||||
|
await readFunction(tools);
|
||||||
|
}
|
||||||
if (doneSignaled) {
|
if (doneSignaled) {
|
||||||
await writer.close();
|
await writer.close();
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -5,8 +5,10 @@
|
|||||||
"target": "ES2022",
|
"target": "ES2022",
|
||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"moduleResolution": "NodeNext",
|
"moduleResolution": "NodeNext",
|
||||||
|
"noImplicitAny": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"verbatimModuleSyntax": true
|
"verbatimModuleSyntax": true,
|
||||||
|
"types": ["node"]
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"dist_*/**/*.d.ts"
|
"dist_*/**/*.d.ts"
|
||||||
|
|||||||
Reference in New Issue
Block a user