import type { State } from "./application.js"; import type { Context } from "./context.js"; /** A function for chaining middleware. */ export type Next = () => Promise; /** Middleware are functions which are chained together to deal with * requests. */ export interface Middleware, T extends Context = Context> { (context: T, next: Next): Promise | unknown; } /** Middleware objects allow encapsulation of middleware along with the ability * to initialize the middleware upon listen. */ export interface MiddlewareObject, T extends Context = Context> { /** Optional function for delayed initialization which will be called when * the application starts listening. */ init?: () => Promise | unknown; /** The method to be called to handle the request. */ handleRequest(context: T, next: Next): Promise | unknown; } /** Type that represents {@linkcode Middleware} or * {@linkcode MiddlewareObject}. */ export type MiddlewareOrMiddlewareObject, T extends Context = Context> = Middleware | MiddlewareObject; /** A type guard that returns true if the value is * {@linkcode MiddlewareObject}. */ export declare function isMiddlewareObject, T extends Context = Context>(value: MiddlewareOrMiddlewareObject): value is MiddlewareObject; /** Compose multiple middleware functions into a single middleware function. */ export declare function compose, T extends Context = Context>(middleware: MiddlewareOrMiddlewareObject[]): (context: T, next?: Next) => Promise;