1.0.1 • Published 7 months ago

pipelineer v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Pipelineer

A generic pipeline / chain of responsibility / middleware library build with Typescript.

Installation

Install pipelineer with npm / yarn

  npm install pipelineer
  yarn add pipelineer

Features

  • Supports Javascript and Typescript
  • Strongly typed with Typescript
  • Lightweight
  • No dependencies

Usage/Examples

Start by writing the middlewares by implementing or instancing the PipelineMiddleware interface.

import { PipelineMiddleware } from 'pipelineer';

class ExampleMiddleware implements PipelineMiddleware<string, string> {
    exec(request: string, next: (request: string) => string | undefined) : string {
        return "my pretty example";
    }
}
const ExampleMiddleware = {
    exec: (request, next) => "my pretty example";
}

Then, create a PipelineFactory and add your middlewares to it.

import { PipelineFactory } from 'pipelineer';

const manager = new PipelineFactory<A, B>();
manager.push(middleware1);
manager.push(middleware2);

Finally, once you added all middlewares, build the pipeline and execute it.

const pipeline = manager.build();
const result = pipeline.exec(request);