@akala/core
Version:
57 lines (56 loc) • 3.02 kB
TypeScript
import type { AnyAsyncMiddleware, MiddlewareAsync, MiddlewarePromise, OptionsResponse, SpecialNextParam } from './shared.js';
/**
* A composite middleware class with priority for asynchronous operations.
* @template T - The type of the arguments.
* @template TSpecialNextParam - The type of the special next parameter.
*/
export declare class MiddlewareCompositeWithPriorityAsync<T extends unknown[], TSpecialNextParam extends string | undefined = SpecialNextParam> implements MiddlewareAsync<T, TSpecialNextParam> {
readonly name?: string;
/**
* Creates an instance of MiddlewareCompositeWithPriorityAsync.
* @param {string} [name] - The name of the middleware composite.
*/
constructor(name?: string);
private readonly stack;
/**
* Adds middleware to the stack with a specified priority.
* @param {number} priority - The priority of the middleware (the lowest first).
* @param {...AnyAsyncMiddleware<T, TSpecialNextParam>[]} middlewares - The middlewares to add.
* @returns {this} The instance of the middleware composite.
*/
useMiddleware(priority: number, ...middlewares: AnyAsyncMiddleware<T, TSpecialNextParam>[]): this;
/**
* Adds standard middleware to the stack with a specified priority.
* @param {number} priority - The priority of the middleware (the lowest first).
* @param {...((...args: T) => Promise<unknown>)[]} middlewares - The middlewares to add.
* @returns {this} The instance of the middleware composite.
*/
use(priority: number, ...middlewares: ((...args: T) => Promise<unknown>)[]): this;
/**
* Adds error middleware to the stack with a specified priority.
* @param {number} priority - The priority of the middleware (the lowest first).
* @param {...((error: Error | OptionsResponse, ...args: T) => Promise<unknown>)[]} middlewares - The middlewares to add.
* @returns {this} The instance of the middleware composite.
*/
useError(priority: number, ...middlewares: ((error: Error | OptionsResponse, ...args: T) => Promise<unknown>)[]): this;
/**
* Processes the request and returns a promise.
* @template X - The type of the return value.
* @param {...T} req - The request arguments.
* @returns {Promise<X>} A promise that resolves or rejects with the result.
*/
process<X = unknown>(...req: T): Promise<X>;
/**
* Handles errors in the middleware stack.
* @param {Error | OptionsResponse} error - The error to handle.
* @param {...T} req - The request arguments.
* @returns {MiddlewarePromise} A promise that resolves or rejects with the result.
*/
handleError(error: Error | OptionsResponse, ...req: T): MiddlewarePromise;
/**
* Handles the middleware stack.
* @param {...T} req - The request arguments.
* @returns {MiddlewarePromise<TSpecialNextParam>} A promise that resolves or rejects with the result.
*/
handle(...req: T): MiddlewarePromise<TSpecialNextParam>;
}