-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhttp.d.ts
171 lines (171 loc) · 5.18 KB
/
http.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/// <reference types="node" />
import { IncomingMessage, OutgoingHttpHeaders, Server, ServerResponse } from "http";
export declare enum HttpStatus {
CONTINUE = 100,
SWITCHING_PROTOCOLS = 101,
PROCESSING = 102,
OK = 200,
CREATED = 201,
ACCEPTED = 202,
NON_AUTHORITATIVE_INFORMATION = 203,
NO_CONTENT = 204,
RESET_CONTENT = 205,
PARTIAL_CONTENT = 206,
AMBIGUOUS = 300,
MOVED_PERMANENTLY = 301,
FOUND = 302,
SEE_OTHER = 303,
NOT_MODIFIED = 304,
TEMPORARY_REDIRECT = 307,
PERMANENT_REDIRECT = 308,
BAD_REQUEST = 400,
UNAUTHORIZED = 401,
PAYMENT_REQUIRED = 402,
FORBIDDEN = 403,
NOT_FOUND = 404,
METHOD_NOT_ALLOWED = 405,
NOT_ACCEPTABLE = 406,
PROXY_AUTHENTICATION_REQUIRED = 407,
REQUEST_TIMEOUT = 408,
CONFLICT = 409,
GONE = 410,
LENGTH_REQUIRED = 411,
PRECONDITION_FAILED = 412,
PAYLOAD_TOO_LARGE = 413,
URI_TOO_LONG = 414,
UNSUPPORTED_MEDIA_TYPE = 415,
REQUESTED_RANGE_NOT_SATISFIABLE = 416,
EXPECTATION_FAILED = 417,
I_AM_A_TEAPOT = 418,
UNPROCESSABLE_ENTITY = 422,
TOO_MANY_REQUESTS = 429,
INTERNAL_SERVER_ERROR = 500,
NOT_IMPLEMENTED = 501,
BAD_GATEWAY = 502,
SERVICE_UNAVAILABLE = 503,
GATEWAY_TIMEOUT = 504,
HTTP_VERSION_NOT_SUPPORTED = 505
}
export interface IResponse extends ServerResponse {
body: any;
}
export interface IApp {
server?: Server;
routes: IRoute[];
base?: string;
next: boolean;
logs?: boolean;
middleware: any[];
resources: any[];
instances: any[];
headers: OutgoingHttpHeaders;
}
export interface IParam {
index?: number;
name?: string;
fn: (req?: IRequest) => void;
}
export interface IRoute {
method: HttpMethodsEnum;
path: string;
name: string;
middleware: any[];
params: IParam[];
fn: any;
httpStatus: HttpStatus;
headers: OutgoingHttpHeaders;
}
export interface IRequest extends IncomingMessage {
query: any;
body: any;
payload: any;
params: any;
parsed: URL;
files: any;
next: any;
route: IRoute;
response: IResponse;
request: IRequest;
context: {
status: HttpStatus;
req: IRequest;
res: IResponse;
headers: any;
params: any;
[key: string]: any;
};
}
export interface IOptions {
port: number | string;
middleware?: any[];
base?: string;
logs?: boolean;
resources?: any[];
}
export interface IContext {
req: IRequest;
res: IResponse;
headers?: OutgoingHttpHeaders;
status?: HttpStatus;
redirect?: string;
[key: string]: any;
}
export interface IException {
message?: string;
error?: any;
statusCode?: number;
}
export declare type INext = (data?: object) => void;
export declare enum HttpMethodsEnum {
GET = "GET",
POST = "POST",
PUT = "PUT",
DELETE = "DELETE",
PATCH = "PATCH",
MIXED = "MIXED",
HEAD = "HEAD",
OPTIONS = "OPTIONS"
}
export declare enum Constants {
INVALID_ROUTE = "Invalid route",
NO_RESPONSE = "No response",
ROUTE_DATA = "__route_data__",
ROUTE_MIDDLEWARE = "__route_middleware__",
ROUTE_PARAMS = "__route_params__"
}
export declare const app: IApp;
export declare const bootstrap: (options: IOptions) => void;
/**
* Resource decorator
* @param path route path
*/
export declare const Resource: (path?: string, options?: {
version: string;
}) => (target: any) => void;
export declare const Before: (...middleware: any[]) => (target: any, name?: string, descriptor?: PropertyDescriptor) => void;
/**
* @Route Decorator
* @param method HttpMethodsEnum
* @param path Route path
*/
export declare const Route: (method: HttpMethodsEnum, path: string, middleware?: any[]) => (target: object, name: string, descriptor: PropertyDescriptor) => void;
export declare const Params: (fn: any) => (target: object, name: string, index: number) => any;
export declare const Get: (path: string) => (target: object, name: string, descriptor: PropertyDescriptor) => void;
export declare const Post: (path: string) => (target: object, name: string, descriptor: PropertyDescriptor) => void;
export declare const Put: (path: string) => (target: object, name: string, descriptor: PropertyDescriptor) => void;
export declare const Patch: (path: string) => (target: object, name: string, descriptor: PropertyDescriptor) => void;
export declare const Delete: (path: string) => (target: object, name: string, descriptor: PropertyDescriptor) => void;
export declare const Mixed: (path: string) => (target: object, name: string, descriptor: PropertyDescriptor) => void;
export declare const Head: (path: string) => (target: object, name: string, descriptor: PropertyDescriptor) => void;
export declare const Options: (path: string) => (target: object, name: string, descriptor: PropertyDescriptor) => void;
export declare const Context: (key?: string) => (target: object, name: string, index: number) => any;
export declare class CustomErrorHandler extends Error {
headers?: OutgoingHttpHeaders;
}
/**
* HttpException error
*/
export declare class HttpException extends CustomErrorHandler {
status: HttpStatus;
constructor(message: string, status?: HttpStatus, headers?: OutgoingHttpHeaders);
}