import { type TransformOptions } from 'stream'; import { SmartDuplex } from './smartstream.classes.smartduplex.js'; export interface AsyncTransformFunction { (chunkArg: TInput): Promise; } export function createTransformFunction( asyncFunction: AsyncTransformFunction, options?: TransformOptions ): SmartDuplex { const smartDuplexStream = new SmartDuplex({ ...options, writeFunction: async (chunkArg, toolsArg) => { const result = await asyncFunction(chunkArg); return result; } }); return smartDuplexStream; } export const createPassThrough = () => { return new SmartDuplex({ objectMode: true, writeFunction: async (chunkArg, toolsArg) => { return chunkArg; } }) }