A simple, general-purpose and type-safe middleware library.
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.
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.
View the changelog at CHANGELOG.md