import type { AnySyncMiddleware, Middleware, MiddlewareResult, OptionsResponse, SpecialNextParam } from './shared.js'; export interface ExtendableCompositeMiddleware { } /** * A composite middleware class that allows for the composition of multiple middlewares. */ export declare class MiddlewareComposite implements Middleware, ExtendableCompositeMiddleware { readonly name?: string; /** * Creates an instance of MiddlewareComposite. * @param {string} [name] - The name of the middleware composite. */ constructor(name?: string); /** * Creates a new MiddlewareComposite instance with the provided middlewares. * @param {...AnySyncMiddleware[]} middlewares - The middlewares to be used. * @returns {MiddlewareComposite} A new MiddlewareComposite instance. */ static new(...middlewares: AnySyncMiddleware[]): MiddlewareComposite; private readonly stack; /** * Adds middlewares to the stack. * @param {...AnySyncMiddleware[]} middlewares - The middlewares to be added. * @returns {this} The current instance of MiddlewareComposite. */ useMiddleware(...middlewares: AnySyncMiddleware[]): this; /** * Adds middlewares to the stack. * @param {...((...args: T) => unknown)[]} middlewares - The middlewares to be added. * @returns {this} The current instance of MiddlewareComposite. */ use(...middlewares: ((...args: T) => unknown)[]): this; /** * Adds error middlewares to the stack. * @param {...((error: Error | OptionsResponse, ...args: T) => unknown)[]} middlewares - The error middlewares to be added. * @returns {this} The current instance of MiddlewareComposite. */ useError(...middlewares: ((error: Error | OptionsResponse, ...args: T) => unknown)[]): this; /** * Processes the request using the middlewares in the stack. * @param {...T} req - The request parameters. * @returns {X} The result of the processing. */ process(...req: T): X; /** * Handles errors by processing them through registered error-handling middlewares in the stack. * * This method iterates over each error middleware, allowing them to attempt resolving the error. * Middlewares can return a modified error, propagate it further, or halt processing with 'break'. * * @param {MiddlewareResult} error - The initial error object to handle * @param {...T} req - The original request parameters associated with the error * @returns {MiddlewareResult} The final resolved error or successful result after processing */ handleError(error: MiddlewareResult, ...req: T): MiddlewareResult; /** * Processes the request through all registered middlewares in the stack. * * This method iterates over each middleware in the stack, applying standard middlewares first until an error occurs. * Once an error is detected, subsequent error-handling middlewares take over to resolve or propagate the error. * * @param {...T} req - The request parameters passed to the middleware stack * @returns {MiddlewareResult} The final result from the middleware processing, which may include: * - An Error instance if an unhandled error occurred * - A special 'next' parameter indicating continuation behavior * - Custom response objects based on middleware logic */ handle(...req: T): MiddlewareResult; }