-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
337 lines (273 loc) · 11.3 KB
/
index.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
import { BaseContextClass, Router } from 'egg';
import { Observable } from 'rxjs';
export 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 enum RequestMethod {
GET = '0',
POST = '1',
PUT = '2',
DELETE = '3',
PATCH = '4',
ALL = '5',
OPTIONS = '6',
HEAD = '7',
}
type ParamData = object | string | number;
type Paramtype = 'BODY' | 'QUERY' | 'PARAM' | 'CUSTOM';
interface GetFileStreamOptions {
requireFile?: boolean; // required file submit, default is true
defCharset?: string;
limits?: {
fieldNameSize?: number;
fieldSize?: number;
fields?: number;
fileSize?: number;
files?: number;
parts?: number;
headerPairs?: number;
};
checkFile?(
fieldname: string,
file: any,
filename: string,
encoding: string,
mimetype: string
): void | Error;
}
interface GetFilesStreamOptions extends GetFileStreamOptions {
autoFields?: boolean;
}
interface ParamRouterOptions {
routerName?: string;
middleware?: (string | Function)[],
}
export function Injectable(): any;
export function Request(): (target, key, index: number) => any;
export function Response(): (target, key, index: number) => any;
export function Req(): (target, key, index: number) => any;
export function Res(): (target, key, index: number) => any;
export function Headers(property?: string): (target, key, index: number) => any;
export function Session(): (target, key, index: number) => any;
export function UploadedFile(): (target, key, index: number) => any;
export function UploadedFiles(): (target, key, index: number) => any;
export function UploadedFileStream(opts?: GetFileStreamOptions): (target, key, index: number) => any;
export function UploadedFilesStream(opts?: GetFilesStreamOptions): (target, key, index: number) => any;
export function Param(): (target, key, index: number) => any;
export function Param(...pipes: (Type<PipeTransform> | PipeTransform)[]): (target, key, index: number) => any;
export function Param(property: string, ...pipes: (Type<PipeTransform> | PipeTransform)[]): (target, key, index: number) => any;
export function Query(): (target, key, index: number) => any;
export function Query(...pipes: (Type<PipeTransform> | PipeTransform)[]): (target, key, index: number) => any;
export function Query(property: string, ...pipes: (Type<PipeTransform> | PipeTransform)[]): (target, key, index: number) => any;
export function Body(): (target, key, index: number) => any;
export function Body(...pipes: (Type<PipeTransform> | PipeTransform)[]): (target, key, index: number) => any;
export function Body(property: string, ...pipes: (Type<PipeTransform> | PipeTransform)[]): (target, key, index: number) => any;
export function Head(path?: string, routerOptions?: ParamRouterOptions): (target, key, descriptor: PropertyDescriptor) => any;
export function Get(path?: string, routerOptions?: ParamRouterOptions): (target, key, descriptor: PropertyDescriptor) => any;
export function All(path?: string, routerOptions?: ParamRouterOptions): (target, key, descriptor: PropertyDescriptor) => any;
export function Post(path?: string, routerOptions?: ParamRouterOptions): (target, key, descriptor: PropertyDescriptor) => any;
export function Delete(path?: string, routerOptions?: ParamRouterOptions): (target, key, descriptor: PropertyDescriptor) => any;
export function Options(path?: string, routerOptions?: ParamRouterOptions): (target, key, descriptor: PropertyDescriptor) => any;
export function Put(path?: string, routerOptions?: ParamRouterOptions): (target, key, descriptor: PropertyDescriptor) => any;
export function Patch(path?: string, routerOptions?: ParamRouterOptions): (target, key, descriptor: PropertyDescriptor) => any;
export function Render(template: string): (target, key, descriptor: PropertyDescriptor) => any;
export function Header(name: string, value: string): (target, key, descriptor: PropertyDescriptor) => any;
export function Header(obj: object): (target, key, descriptor: PropertyDescriptor) => any;
export function HttpCode(statusCode: number): (target, key, descriptor: PropertyDescriptor) => any;
export function UsePipes(...pipes: (PipeTransform | Function)[]): any;
export function UseGuards(...guards: (CanActivate | Function)[]): any;
export function UseInterceptors(...interceptors: (EggInterceptor | Function)[]): any;
export function UseFilters(...filters: (ExceptionFilter | Function)[]): any;
export function Controller(path?: string, routerOptions?: { sensitive?: boolean; middleware?: (string | Function)[]; }): (target: object) => any;
export function Resources(name: string, options?: { name?: string; middleware?: (string | Function)[], }): (target: object) => any;
export function Restful(name: string, options?: { name?: string; middleware?: (string | Function)[], }): (target: object) => any;
export function Priority(priority?: number): (target: object) => any
interface ArgumentMetadata {
readonly type: Paramtype;
readonly metatype?: new (...args) => any | undefined;
readonly data?: string | undefined;
}
interface Type<T> extends Function {
new(...args: any[]): T;
}
// interface RouteInfo {
// readonly path: string;
// readonly method: RequestMethod;
// }
interface ExecutionContext {
getClass<T = any>(): Type<T>; // use for class
getHandler(): Function; // classMethod
}
// interface IMiddleware {
// apply(...middleware: (Function | any)[]): this;
// forRoutes(...routes: (string | RouteInfo | object)[]): this;
// exclude(...routes: Array<string | RouteInfo>): this;
// }
export abstract class CanActivate extends BaseContextClass {
constructor(...args: any[]);
abstract canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean>;
}
export interface CallHandler<T = any> {
handle(): Observable<T>;
}
export abstract class EggInterceptor<T = any, R = any> extends BaseContextClass {
constructor(...args: any[]);
abstract intercept(
context: ExecutionContext,
call$: CallHandler<T>,
): Observable<R> | Promise<Observable<R>>;
}
export abstract class PipeTransform<T = any, R = any> extends BaseContextClass {
constructor(...args: any[]);
abstract transform(value: T, metadata: ArgumentMetadata): R;
}
export abstract class ExceptionFilter<T = any> extends BaseContextClass {
constructor(...args: any[]);
abstract catch(exception: T): any;
}
export function Catch(...exceptions: Type<any>[]): any;
export function createParamDecorator(factory: (data, req) => any): (data?: any, ...pipes) => any;
// export class MiddlewareConsumer {
// static setRouter(router: Router): IMiddleware;
// static apply(...middleware: (Function | any)[]): IMiddleware;
// }
export function ReflectMetadata(metadataKey, metadataValue): (target, key?, descriptor?) => any;
export class HttpException extends Error {
readonly message: any;
constructor(response: string | object, status: number);
getResponse(): string | object;
getStatus(): number;
}
export class ForbiddenException extends HttpException {
constructor(message?: string | object | any, error = 'Forbidden');
}
export class BadRequestException extends HttpException {
constructor(message?: string | object | any, error = 'Bad Request');
}
export class UnauthorizedException extends HttpException {
constructor(message?: string | object | any, error = 'Unauthorized');
}
export class NotFoundException extends HttpException {
constructor(message?: string | object | any, error = 'Not Found');
}
export class NotAcceptableException extends HttpException {
constructor(message?: string | object | any, error = 'Not Acceptable');
}
export class RequestTimeoutException extends HttpException {
constructor(message?: string | object | any, error = 'Request Timeout');
}
export class ConflictException extends HttpException {
constructor(message?: string | object | any, error = 'Conflict');
}
export class GoneException extends HttpException {
constructor(message?: string | object | any, error = 'Gone');
}
export class PayloadTooLargeException extends HttpException {
constructor(message?: string | object | any, error = 'Payload Too Large');
}
export class UnsupportedMediaTypeException extends HttpException {
constructor(message?: string | object | any, error = 'Unsupported Media Type');
}
export class UnprocessableEntityException extends HttpException {
constructor(message?: string | object | any, error = 'Unprocessable Entity');
}
export class InternalServerErrorException extends HttpException {
constructor(message?: string | object | any, error = 'Internal Server Error');
}
export class NotImplementedException extends HttpException {
constructor(message?: string | object | any, error = 'Not Implemented');
}
export class BadGatewayException extends HttpException {
constructor(message?: string | object | any, error = 'Bad Gateway');
}
export class ServiceUnavailableException extends HttpException {
constructor(message?: string | object | any, error = 'Service Unavailable');
}
export class GatewayTimeoutException extends HttpException {
constructor(message?: string | object | any, error = 'Gateway Timeout');
}
interface ValidatorOptions {
skipMissingProperties?: boolean;
whitelist?: boolean;
forbidNonWhitelisted?: boolean;
groups?: string[];
dismissDefaultMessages?: boolean;
validationError?: {
target?: boolean;
value?: boolean;
};
forbidUnknownValues?: boolean;
}
interface ValidationPipeOptions extends ValidatorOptions {
transform?: boolean;
disableErrorMessages?: boolean;
}
export class ParseIntPipe extends PipeTransform {
transform(value: string, metadata: ArgumentMetadata): any;
}
export class ValidationPipe extends PipeTransform {
constructor(options?: ValidationPipeOptions);
transform(value, metadata: ArgumentMetadata);
}
export class ClassSerializerInterceptor extends EggInterceptor {
intercept(context: ExecutionContext, call$: Observable<any>): Observable<any>;
}
export abstract class RestController extends BaseContextClass {
// get /posts/new
new(...params: any[]): Promise<any>;
// get /posts
index(...params: any[]): Promise<any>;
// get /posts/:id
show(...params: any[]): Promise<any>;
// get /posts/:id/edit
edit(...params: any[]): Promise<any>;
// post /posts
create(...params: any[]): Promise<any>;
// patch /posts/:id
update(...params: any[]): Promise<any>;
// delete /posts/:id
destroy(...params: any[]): Promise<any>
}