UNPKG

@prostory/mountain

Version:

Yet another HTTP/2 server and client.

42 lines (41 loc) 1.63 kB
import { Request, Response, FormDataDecoded, FormDataOptions } from '../types'; export declare enum BodyType { TEXT = "text", JSON = "json", FORM_DATA = "form-data", URLENCODED = "urlencoded" } export interface GetHeaderFunction { (name: ':path'): string; (name: ':method'): string; (name: ':scheme'): string; (name: ':protocol'): string; (name: ':authority'): string; (name: string): string | undefined; <T>(name: ':path', transformer: (value: string) => T): T; <T>(name: ':method', transformer: (value: string) => T): T; <T>(name: ':scheme', transformer: (value: string) => T): T; <T>(name: ':protocol', transformer: (value: string) => T): T; <T>(name: ':authority', transformer: (value: string) => T): T; <T>(name: string, transformer: (value: string | undefined) => T): T; } export interface GetBodyFunction { (): Promise<void>; (type: BodyType.TEXT): Promise<string>; <T extends object>(type: BodyType.JSON): Promise<T>; <T extends FormDataDecoded>(type: BodyType.FORM_DATA, options?: FormDataOptions): Promise<T>; <T extends Record<string, string>>(type: BodyType.URLENCODED): Promise<T>; } export interface Accessor { body: GetBodyFunction; header: GetHeaderFunction; } export interface RequestAccessor extends Accessor { readonly url: URL; readonly method: string; readonly parameters: ReadonlyArray<string>; } export interface ResponseAccessor extends Accessor { } export declare const accessRequest: (context: Request) => RequestAccessor; export declare const accessResponse: (context: Response) => ResponseAccessor;