UNPKG

libmodulor

Version:

A TypeScript library to create platform-agnostic applications

24 lines (23 loc) 1.91 kB
import type { IncomingMessage, RequestListener, ServerResponse } from 'node:http'; import type { AppManifest } from '../../../app/index.js'; import type { FilePath, HTTPMethod, JSONString, URLPath } from '../../../dt/index.js'; import { CustomError } from '../../../error/index.js'; import { type UCDef, type UCInput, type UCManager, type UCOPIBase, type UCTransportContract } from '../../../uc/index.js'; import type { ServerRequestHandler, ServerRequestHandlerReq, ServerRequestHandlerRes } from '../server/ServerRequestHandler.js'; import type { RouteKey, Router } from './types.js'; export type IncomingMessageEnhanced = IncomingMessage & { bodyRaw?: string; fullURL?: URL; secure?: boolean; }; export declare function assertIncomingMessageEnhanced(req: IncomingMessage): asserts req is IncomingMessageEnhanced; export declare function buildHandler<I extends UCInput | undefined = undefined, OPI0 extends UCOPIBase | undefined = undefined, OPI1 extends UCOPIBase | undefined = undefined>(appManifest: AppManifest, ucd: UCDef<I, OPI0, OPI1>, contract: UCTransportContract, serverRequestHandler: ServerRequestHandler, ucManager: UCManager): RequestListener; export declare function buildRes(res: object | string | CustomError): JSONString; export declare function enhanceIncomingMessage(req: IncomingMessage): Promise<void>; export declare function init(): void; export declare function mountHandler(contract: UCTransportContract, router: Router, handler: RequestListener): void; export declare function mountStaticDir(dirPath: FilePath, router: Router): Promise<void>; export declare function routeKey(method: string, path: string): RouteKey; export declare function routeKeys(method: HTTPMethod, paths: URLPath[]): RouteKey[]; export declare function toReq(req: IncomingMessageEnhanced): ServerRequestHandlerReq; export declare function toRes(res: ServerResponse): ServerRequestHandlerRes;