import { tagged, type Logger, } from '@monochromatic-dev/module-logger/ts'; import { runPipeAsync, } from './run.ts'; import type { AsyncStep, DeferredArgs, NoStepsAfter1, NoStepsAfter2, NoStepsAfter3, NoStepsAfter4, NoStepsAfter5, NoStepsAfter6, NoStepsAfter7, NoStepsAfter8, NoStepsAfter9, } from './types.ts'; export function pipeAsync( args: { readonly fn1: AsyncStep; readonly l?: Logger; } & NoStepsAfter1, ): (value: TInput | Promise,) => Promise>; export function pipeAsync( args: { readonly fn1: AsyncStep; readonly fn2: AsyncStep; readonly l?: Logger; } & NoStepsAfter2, ): (value: TInput | Promise,) => Promise>; export function pipeAsync( args: { readonly fn1: AsyncStep; readonly fn2: AsyncStep; readonly fn3: AsyncStep; readonly l?: Logger; } & NoStepsAfter3, ): (value: TInput | Promise,) => Promise>; export function pipeAsync( args: { readonly fn1: AsyncStep; readonly fn2: AsyncStep; readonly fn3: AsyncStep; readonly fn4: AsyncStep; readonly l?: Logger; } & NoStepsAfter4, ): (value: TInput | Promise,) => Promise>; export function pipeAsync( args: { readonly fn1: AsyncStep; readonly fn2: AsyncStep; readonly fn3: AsyncStep; readonly fn4: AsyncStep; readonly fn5: AsyncStep; readonly l?: Logger; } & NoStepsAfter5, ): (value: TInput | Promise,) => Promise>; export function pipeAsync( args: { readonly fn1: AsyncStep; readonly fn2: AsyncStep; readonly fn3: AsyncStep; readonly fn4: AsyncStep; readonly fn5: AsyncStep; readonly fn6: AsyncStep; readonly l?: Logger; } & NoStepsAfter6, ): (value: TInput | Promise,) => Promise>; export function pipeAsync( args: { readonly fn1: AsyncStep; readonly fn2: AsyncStep; readonly fn3: AsyncStep; readonly fn4: AsyncStep; readonly fn5: AsyncStep; readonly fn6: AsyncStep; readonly fn7: AsyncStep; readonly l?: Logger; } & NoStepsAfter7, ): (value: TInput | Promise,) => Promise>; export function pipeAsync( args: { readonly fn1: AsyncStep; readonly fn2: AsyncStep; readonly fn3: AsyncStep; readonly fn4: AsyncStep; readonly fn5: AsyncStep; readonly fn6: AsyncStep; readonly fn7: AsyncStep; readonly fn8: AsyncStep; readonly l?: Logger; } & NoStepsAfter8, ): (value: TInput | Promise,) => Promise>; export function pipeAsync< const TInput, TStep1, TStep2, TStep3, TStep4, TStep5, TStep6, TStep7, TStep8, TStep9, >( args: { readonly fn1: AsyncStep; readonly fn2: AsyncStep; readonly fn3: AsyncStep; readonly fn4: AsyncStep; readonly fn5: AsyncStep; readonly fn6: AsyncStep; readonly fn7: AsyncStep; readonly fn8: AsyncStep; readonly fn9: AsyncStep; readonly l?: Logger; } & NoStepsAfter9, ): (value: TInput | Promise,) => Promise>; /** Creates a reusable asynchronous left-to-right pipeline function, delegating each call to {@link runPipeAsync}. @param args - contiguous step functions and optional logger @returns function that applies captured steps to each possibly promised input value @throws {@link PipeStepGapError} or {@link PipeStepOverflowError} when runtime step keys are invalid @throws whatever pipeline step throws or rejects with; the failure propagates unchanged @example ```ts import { pipeAsync } from '\@monochromatic-dev/module-pipe'; const render = pipeAsync({ fn1: (input: number) => input + 1, fn2: async (input) => String(input), }); await render(Promise.resolve(1)); ``` */ export function pipeAsync(args: DeferredArgs,): (value: unknown,) => Promise { /** Applies captured asynchronous steps to a provided value. @param value - input value supplied to the reusable pipeline @returns promise resolving to final pipeline output */ function pipelineAsync(value: unknown,): Promise { /** Logger tagged at the deferred async public API invocation boundary. */ const l = tagged(args.l === undefined ? { tag: pipeAsync.name, } : { tag: pipeAsync.name, l: args.l, },); return runPipeAsync({ ...args, value, l, },); } return pipelineAsync; }