@supercharge/pipeline
Version:
Run a pipeline of async tasks
85 lines (84 loc) • 1.95 kB
TypeScript
declare type Pipe<T> = PipeableClass<T> | PipeableFunction<T>;
interface PipeableClass<T> {
new (pipeable: T): this;
handle: <R>() => R | Promise<R>;
}
declare type PipeableFunction<T> = <R>(pipeable: T) => R | Promise<R>;
export declare class Pipeline<T> {
/**
* The array of class or function pipes.
*/
private pipes;
/**
* The object that will be sent through the pipeline.
*/
private readonly pipeable;
/**
* The method called on each pipe.
*/
private method;
/**
* Create a new pipeline instance for the given `pipeable`.
*/
constructor(pipeable: T);
/**
* Set the value that will be passed throught the pipeline.
*
* @param {*} pipeable
*
* @returns {Pipeline}
*/
static send<T>(pipeable: T): Pipeline<T>;
/**
* Set the array of pipes.
*
* @param {Array} pipes
*
* @returns {Pipeline}
*/
through(...pipes: Array<Pipe<T>> | Array<Array<Pipe<T>>>): this;
/**
* Set the method name to call on the pipes.
*
* @param {String} method
*
* @returns {Pipeline}
*/
via(method: string): this;
/**
* Run the pipeline and return the result.
*
* @returns {*}
*/
thenReturn<R>(): Promise<R>;
/**
* Run the pipeline with a final destination `callback`.
*
* @param {Function} callback
*
* @returns {*}
*/
then<R>(callback: Function): Promise<R>;
/**
* Returns the closure function to reduce the pipeline.
*
* @returns {Function}
*/
private handle;
/**
* Instantiate the given `Pipe` class and call the handle method.
*
* @param {Class} Pipe
* @param {*} parameters
*
* @returns {*}
*/
private handleClass;
/**
* Returns the initial pipeline value.
*
* @returns {*}
*/
private initial;
}
export {};