import { RequestListener } from "http"; import { Logger } from "../common.js"; import { Request, Response, ErrorHandler, Handler, Method, HandlerWithOptions, MinimalRouter, RouterHandlerOptions, RouterJSONDoc, RouterOptions, PathParams, PathPart, PathPartToken, APIRouterOptions, MinimalLogger, SchemaProperties } from "../types.js"; import { ServerOptions } from "https"; /** * Router Public */ export declare class Router implements MinimalRouter { protected config?: RouterOptions | undefined; protected readonly handlers: RouterHandler[]; protected readonly errorHandlers: ErrorHandler[]; readonly listener: RequestListener; serverOptions: ServerOptions; constructor(config?: RouterOptions | undefined); clear(): void; get(path: string | undefined, handler: Array | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router; post(path: string | undefined, handler: Array | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router; patch(path: string | undefined, handler: Array | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router; delete(path: string | undefined, handler: Array | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router; put(path: string | undefined, handler: Array | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router; options(path: string | undefined, handler: Array | Handler | MinimalRouter | HandlerWithOptions, options?: RouterHandlerOptions): Router; use(handler: Array | HandlerWithOptions | Handler | MinimalRouter, path?: string, method?: Method, options?: RouterHandlerOptions): Router; catch(errorHandler: Array | ErrorHandler): Router; run(req: Request, res: Response, pathTokens?: PathPart[], prePathTokens?: PathPartToken[]): Promise; getJSONDoc(doc?: RouterJSONDoc, prePath?: string): RouterJSONDoc; logPaths(logger: MinimalLogger, filter?: (path: string, method: string) => boolean): void; toString(filter?: (path: string, method: string) => boolean): string; } declare class RouterHandler { private readonly originalHandler; readonly path: string | undefined; private readonly method; private readonly tokens; private readonly handler; private readonly isRouter; private readonly options?; constructor(originalHandler: Array | HandlerWithOptions | Handler | MinimalRouter, path: string | undefined, method: Method | undefined, options?: RouterHandlerOptions); getJSONDoc(doc?: RouterJSONDoc, prePath?: string): RouterJSONDoc; invoke(req: Request, res: Response, pathTokens: PathPart[], prePathTokens: PathPartToken[]): Promise; isMatch(method: string | undefined, requestParts: PathPart[], prePathTokens: PathPartToken[]): { match: boolean; params?: PathParams; }; private static pushResults; } /** * Proxy */ export interface ProxyRouterOptions extends RouterOptions { url: string; rejectUnauthorized?: boolean; } declare class ProxyRouter extends Router { private readonly proxyURL; private readonly rejectUnauthorized?; constructor(options: ProxyRouterOptions); run(req: Request, res: Response, pathTokens?: { value: string; lower: string; }[], prePathTokens?: PathPartToken[]): Promise; } export declare function Proxy(options: ProxyRouterOptions): ProxyRouter; export interface StaticRouterOptions extends RouterOptions { directory: string; list?: boolean; allowListJSON?: boolean; allowGetJSON?: boolean; index?: string; index404?: string; index404Status?: number; contentTypes?: any; defaultContentType?: string; } export declare function Static(options: StaticRouterOptions): Router; /** * # APIRouter * * src/server.js * ```typescript *import { App, APIRouter } from "@miqro/core"; *const app = new App(); *app.use(APIRouter({ dirname: resolve(__dirname, "api") })); *app.listen(8080); * ``` * * src/api/user/post.js * * ```typescript *import { ReadBuffer, JSONParser, APIRoute } from "@miqro/core"; * *const route: APIRoute = { * middleware: [ReadBuffer(), JSONParser()], * request: { * query: { ... }, * body: { ... }, * ... * }, * response: { * ... * }, * handler: async (ctx: Context) => { * return { * status: 200, * body: { * status: "OK" * } * }; * } *} *export default route; * ``` */ export declare function APIRouter(options: APIRouterOptions, logger?: Logger): Promise; export {};