import { IncomingMessage, ServerResponse, Server } from 'node:http' import { Stats } from 'node:fs' type Maybe = T | null | undefined export const MimeTypeDb: Record> export type Logger = { fatal: (...data: any[]) => void, error: (...data: any[]) => void, warn: (...data: any[]) => void, info: (...data: any[]) => void, debug: (...data: any[]) => void, trace: (...data: any[]) => void, log: (...data: any[]) => void, } export type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'OPTIONS' | 'PATCH' | 'HEAD' export type Context = { log: Logger, req: IncomingMessage, res: ServerResponse>, method: Method, url: string, search: string, state: Record, status: number, query: URLSearchParams, body: any, type: string | null, length: number | null, headers: Record, aborted?: boolean, } export interface BodyHasHandler = { handleRequest: (ctx: Context) => any } export type HandlerSync = (ctx: Context) => void export type HandlerAsync = (ctx: Context) => Promise export type Handler = HandlerSync | HandlerAsync export function QueryHandler(): Handler export function JsonHandler(options: { sizeLimit?: number | null } = {}): Handler export function CorsHandler(options: { allowedMethod?: Maybe, allowedOrigins?: Maybe, allowedHeaders?: Maybe, credentials?: Maybe, exposeHeaders?: Maybe, maxAge?: Maybe, } = {}): Handler export type File = { name: string, path: string, filename: string } export class HttpError { constructor(statusCode: number, message: string, body: any) status: number body: any } export class FileResponse implements BodyHasHandler { constructor(filepath: string, stat: Stats) filepath: string stat: Stats handleRequst(ctx: Context): any } export function FormidableHandler(formidable: any, options: { parseFields?: Maybe, uploadDir?: Maybe, filename?: Maybe<(file: File) => string>, maxFileSize?: Maybe, maxFieldSize?: Maybe, maxFields?: Maybe, rename?: Maybe, } = {}): Handler export class RouterError { constructor(route1: any, route2: any, message: string) routeA: any routeB: any } export type FlaskaRouterMatch = { path: { path: string, handlers: Handler[], }, params: Record, } export class FlaskaRouter { constructor() addRoute(path: string, handler: Handler): void addRoute(path: string, middlewares: Handler | Handler[], handler: Handler): void compile(): void match(url: string): FlaskaRouterMatch | null } export type FlaskaOptions = { defaultHeaders?: Maybe>, log?: Maybe, nonce?: Maybe>, nonceCacheLength: Maybe, appendHeaders?: Maybe>, } export class Flaska { log: Logger server: Server routers: { GET: FlaskaRouter, POST: FlaskaRouter, PUT: FlaskaRouter, DELETE: FlaskaRouter, OPTIONS: FlaskaRouter, PATCH: FlaskaRouter, HEAD: FlaskaRouter, } get: FlaskaRouter['addRoute'] post: FlaskaRouter['addRoute'] put: FlaskaRouter['addRoute'] delete: FlaskaRouter['addRoute'] options: FlaskaRouter['addRoute'] patch: FlaskaRouter['addRoute'] head: FlaskaRouter['addRoute'] constructor(options: FlaskaOptions) devMode(): void on404(handler: Handler): void onerror(handler: Handler): void onreqerror(handler: Handler): void onreserror(handler: Handler): void before(handler: HandlerSync): void beforeAsync(handler: HandlerAsync): void after(handler: HandlerSync): void afterAsync(handler: HandlerAsync): void listen(port: number): void listen(port: number, ip: string): void listen(port: number, cb: () => void): void listen(port: number, ip:string, cb: () => void): void listenAsync(port: number): Promise listenAsync(port: number, ip: string): Promise listenAsync(port: number, cb: () => void): Promise listenAsync(port: number, ip:string, cb: () => void): Promise closeAsync(): Promise }