Skip to content

zenekron/zecomi

Repository files navigation

zecomi

A simple, general-purpose and type-safe middleware library.

Introduction

zecomi lets you define and compose middlewares in a type-safe fashion while making no assumptions about inputs, outputs or the type of computation being performed.

Usage

import { type Middleware, type Service, ServiceBuilder } from "zecomi";

class MyMiddleware<I, O> implements Middleware<I, O, I, O> {
  public invoke(input: I, next: Service<I, O>): O {
    // ...
    const output = next.invoke(input);
    // ...
    return output;
  }
}

const myService = ServiceBuilder.create<I, O>()
  .use(new MyMiddleware())
  // ...
  .build((input: I): O => {
    // business logic that generates outputs from inputs
  });

You can find more examples in the ./examples folder.

Changelog

View the changelog at CHANGELOG.md