UNPKG

routup

Version:

Routup is a minimalistic http based routing framework.

90 lines (89 loc) 3.99 kB
import { MethodName } from '../constants'; import type { DispatchEvent, Dispatcher } from '../dispatcher'; import type { HandlerConfig } from '../handler'; import { Handler } from '../handler'; import type { HookDefaultListener, HookErrorListener, HookListener, HookUnsubscribeFn } from '../hook'; import { HookManager, HookName } from '../hook'; import type { Path } from '../path'; import { PathMatcher } from '../path'; import type { Plugin, PluginInstallContext } from '../plugin'; import type { RouterOptionsInput } from '../router-options'; import type { RouterPipelineContext } from './types'; export declare class Router implements Dispatcher { readonly '@instanceof': symbol; /** * An identifier for the router instance. */ readonly id: number; /** * A label for the router instance. */ readonly name?: string; /** * Array of mounted layers, routes & routers. * * @protected */ protected stack: (Router | Handler)[]; /** * Path matcher for the current mount path. * * @protected */ protected pathMatcher: PathMatcher | undefined; /** * A hook manager. * * @protected */ protected hookManager: HookManager; constructor(options?: RouterOptionsInput); matchPath(path: string): boolean; setPath(value?: Path): void; protected executePipelineStep(context: RouterPipelineContext): Promise<void>; protected executePipelineStepStart(context: RouterPipelineContext): Promise<void>; protected executePipelineStepLookup(context: RouterPipelineContext): Promise<void>; protected executePipelineStepChildBefore(context: RouterPipelineContext): Promise<void>; protected executePipelineStepChildAfter(context: RouterPipelineContext): Promise<void>; protected executePipelineStepChildDispatch(context: RouterPipelineContext): Promise<void>; protected executePipelineStepFinish(context: RouterPipelineContext): Promise<void>; dispatch(event: DispatchEvent): Promise<void>; delete(...handlers: (Handler | HandlerConfig)[]): this; delete(path: Path, ...handlers: (Handler | HandlerConfig)[]): this; get(...handlers: (Handler | HandlerConfig)[]): this; get(path: Path, ...handlers: (Handler | HandlerConfig)[]): this; post(...handlers: (Handler | HandlerConfig)[]): this; post(path: Path, ...handlers: (Handler | HandlerConfig)[]): this; put(...handlers: (Handler | HandlerConfig)[]): this; put(path: Path, ...handlers: (Handler | HandlerConfig)[]): this; patch(...handlers: (Handler | HandlerConfig)[]): this; patch(path: Path, ...handlers: (Handler | HandlerConfig)[]): this; head(...handlers: (Handler | HandlerConfig)[]): this; head(path: Path, ...handlers: (Handler | HandlerConfig)[]): this; options(...handlers: (Handler | HandlerConfig)[]): this; options(path: Path, ...handlers: (Handler | HandlerConfig)[]): this; protected useForMethod(method: MethodName, ...input: (Path | Handler | HandlerConfig)[]): void; use(router: Router): this; use(handler: Handler | HandlerConfig): this; use(plugin: Plugin): this; use(path: Path, router: Router): this; use(path: Path, handler: Handler | HandlerConfig): this; use(path: Path, plugin: Plugin): this; protected install(plugin: Plugin, context?: PluginInstallContext): this; /** * Add a hook listener. * * @param name * @param fn */ on(name: `${HookName.DISPATCH_START}` | `${HookName.DISPATCH_END}` | `${HookName.CHILD_DISPATCH_BEFORE}` | `${HookName.CHILD_DISPATCH_AFTER}`, fn: HookDefaultListener): HookUnsubscribeFn; on(name: `${HookName.CHILD_MATCH}`, fn: HookErrorListener): HookUnsubscribeFn; on(name: `${HookName.ERROR}`, fn: HookErrorListener): HookUnsubscribeFn; /** * Remove single or all hook listeners. * * @param name */ off(name: `${HookName}`): this; off(name: `${HookName}`, fn: HookListener): this; }