UNPKG

@akala/core

Version:
21 lines (20 loc) 1.37 kB
import { MiddlewareComposite } from '../middlewares/composite-sync.js'; import type { Middleware, MiddlewareResult, SpecialNextParam } from '../middlewares/shared.js'; import { type UriTemplate } from '../uri-template/index.js'; export interface Routable { path: string; params?: Record<string, unknown>; } export type RouteBuilderArguments = [route: string | UriTemplate]; export type RouteBuilder<T extends [Routable, ...unknown[]], TSpecialNextParam extends SpecialNextParam = SpecialNextParam> = (...args: RouteBuilderArguments) => MiddlewareRoute<T, TSpecialNextParam>; export declare class MiddlewareRoute<T extends [Routable, ...unknown[]], TSpecialNextParam extends SpecialNextParam = SpecialNextParam> extends MiddlewareComposite<T, TSpecialNextParam> { routePath: UriTemplate; constructor(route: string | UriTemplate); route(...args: RouteBuilderArguments): MiddlewareRoute<T, TSpecialNextParam>; isApplicable?: (x: T[0]) => boolean; handle(...context: T): MiddlewareResult<TSpecialNextParam>; useMiddleware(route: string | UriTemplate, ...middlewares: Middleware<T, TSpecialNextParam>[]): this; useMiddleware(...middlewares: Middleware<T, TSpecialNextParam>[]): this; use(route: string | UriTemplate, ...middlewares: ((...args: T) => unknown)[]): this; use(...middlewares: ((...args: T) => unknown)[]): this; }