@zodash/onion
Version:
simple onion model
23 lines (22 loc) • 908 B
TypeScript
import { Middleware } from '@zodash/compose';
export interface IOnion<Input, Output, State> {
use(middleware: Middleware<Context<Input, Output, State>>): ThisType<any>;
callback(): (req: Input, res: Output) => Promise<Context<Input, Output, State>>;
execute(input: Input): Promise<Output>;
}
export { Middleware };
export interface Context<Input, Output, State = any> {
input: Input;
state: State;
output: Output;
}
export declare abstract class Onion<Input, Output, State> implements IOnion<Input, Output, State> {
private middlewares;
private handler;
private _callback;
use(middleware: Middleware<Context<Input, Output, State>>): this;
abstract handle(): Middleware<Context<Input, Output, State>>;
callback(): (input: Input, output: Output) => Promise<Context<Input, Output, State>>;
execute(input: Input): Promise<Output>;
private createContext;
}