fix(core): update

This commit is contained in:
Philipp Kunz 2023-11-11 19:47:20 +01:00
parent 12c9d8cc9d
commit 7b678cc856
2 changed files with 9 additions and 14 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartstream',
version: '3.0.14',
version: '3.0.15',
description: 'simplifies access to node streams'
}

View File

@ -1,4 +1,5 @@
import { Transform, type TransformCallback, type TransformOptions } from 'stream';
import { SmartDuplex } from './smartstream.classes.smartduplex.js';
export interface AsyncTransformFunction<TInput, TOutput> {
(chunkArg: TInput): Promise<TOutput>;
@ -7,20 +8,14 @@ export interface AsyncTransformFunction<TInput, TOutput> {
export function createTransformFunction<TInput, TOutput>(
asyncFunction: AsyncTransformFunction<TInput, TOutput>,
options?: TransformOptions
): Transform {
const transformStream = new Transform({
): SmartDuplex {
const smartDuplexStream = new SmartDuplex({
...options,
objectMode: true, // Ensure we operate in object mode
async transform(chunk: TInput, encoding: string, callback: TransformCallback) {
try {
const transformed = await asyncFunction(chunk);
this.push(transformed);
callback();
} catch (error) {
callback(error instanceof Error ? error : new Error(String(error)));
writeFunction: async (chunkArg, toolsArg) => {
const result = await asyncFunction(chunkArg);
return result;
}
}
});
})
return transformStream;
return smartDuplexStream;
}