UNPKG

@akala/core

Version:
53 lines (52 loc) 2.72 kB
import type { AnySyncMiddleware, Middleware, MiddlewareResult, OptionsResponse, SpecialNextParam } from './shared.js'; import { type ExtendableCompositeMiddleware } from './composite-sync.js'; /** * A composite middleware class with priority for synchronous operations. * @template T - The type of the arguments. * @template TSpecialNextParam - The type of the special next parameter. */ export declare class MiddlewareCompositeWithPriority<T extends unknown[], TSpecialNextParam extends string | undefined = SpecialNextParam> implements Middleware<T, TSpecialNextParam>, ExtendableCompositeMiddleware<T> { readonly name?: string; constructor(name?: string); private readonly stack; /** * Adds middleware with a specified priority. * @param {number} priority - The priority of the middleware (the lowest first). * @param {...AnySyncMiddleware<T, TSpecialNextParam>} middlewares - The middlewares to add. * @returns {this} The instance of the middleware composite. */ useMiddleware(priority: number, ...middlewares: AnySyncMiddleware<T, TSpecialNextParam>[]): this; /** * Adds standard middleware with a specified priority. * @param {number} priority - The priority of the middleware (the lowest first). * @param {...Function} middlewares - The middlewares to add. * @returns {this} The instance of the middleware composite. */ use(priority: number, ...middlewares: ((...args: T) => unknown)[]): this; /** * Adds error middleware with a specified priority. * @param {number} priority - The priority of the middleware (the lowest first). * @param {...Function} middlewares - The middlewares to add. * @returns {this} The instance of the middleware composite. */ useError(priority: number, ...middlewares: ((error: Error | OptionsResponse, ...args: T) => unknown)[]): this; /** * Processes the middleware stack. * @param {...T} req - The request parameters. * @returns {X} The result of the middleware processing. */ process<X = unknown>(...req: T): X; /** * Handles errors in the middleware stack. * @param {Error | OptionsResponse} error - The error to handle. * @param {...T} req - The request parameters. * @returns {MiddlewareResult<TSpecialNextParam>} The result of the error handling. */ handleError(error: Error | OptionsResponse, ...req: T): MiddlewareResult<TSpecialNextParam>; /** * Handles the middleware stack. * @param {...T} req - The request parameters. * @returns {MiddlewareResult<TSpecialNextParam>} The result of the middleware handling. */ handle(...req: T): MiddlewareResult<TSpecialNextParam>; }