Skip to content

Commit

Permalink
Merge pull request #298 from htdangkhoa/feature/types
Browse files Browse the repository at this point in the history
feat: add common types
  • Loading branch information
htdangkhoa committed May 14, 2024
2 parents 7295ad7 + c46c776 commit a8cb866
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ import * as http from 'http';
import * as http2 from 'http2';

declare module 'pure-http' {
export enum Method {
GET = 'get',
POST = 'post',
PUT = 'put',
PATCH = 'patch',
DELETE = 'delete',
HEAD = 'head',
OPTIONS = 'options',
TRACE = 'trace',
CONNECT = 'connect',
ALL = 'all',
}

export interface ICookieSerializeOptions {
encode?(value: string): string;

Expand Down Expand Up @@ -210,17 +223,25 @@ declare module 'pure-http' {
extends http2.Http2ServerResponse,
IResponse {}

export type IHandlerRequest = IRequestHttp | IRequestHttp2;

export type IHandlerResponse = IResponseHttp | IResponseHttp2;

export interface IHandlerNext {
(error?: unknown): void;
}

export type Handler = (
req: IRequestHttp | IRequestHttp2,
res: IResponseHttp | IResponseHttp2,
next: (error?: unknown) => void,
req: IHandlerRequest,
res: IHandlerResponse,
next: IHandlerNext,
) => void | Promise<unknown>;

export type ErrorHandler = (
error: Error,
req: IRequestHttp | IRequestHttp2,
res: IResponseHttp | IResponseHttp2,
next: (error?: unknown) => void,
req: IHandlerRequest,
res: IHandlerResponse,
next: IHandlerNext,
) => void | Promise<unknown>;

export interface IRouter {
Expand Down

0 comments on commit a8cb866

Please sign in to comment.