/** * This middleware pattern has been grabbed from here: * https://evertpot.com/generic-middleware/ */ /** * 'next' function, passed to a middleware */ export type Next = () => void | Promise; /** * A middleware */ export type Middleware = (context: T, next: Next) => Promise | void; /** * A middleware container and invoker */ export declare class MiddlewareDispatcher { readonly finalMiddlewares: Middleware[]; middlewares: Middleware[]; constructor(finalMiddlewares?: Middleware[]); /** * Add a middleware function. */ use(...middlewares: Middleware[]): void; /** * Add 'final' middlewares that will be added to the end of the * regular middlewares. This allows for finer control when exposing * the @see use functionality to consumers but wanting to ensure that your * final middleware is last to run */ useFinal(...middlewares: Middleware[]): void; /** * Execute the chain of middlewares, in the order they were added on a * given Context. */ dispatch(context: T): Promise; }