forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restify.d.ts
612 lines (538 loc) · 19.8 KB
/
restify.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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
// Type definitions for node.js REST framework 2.0
// Project: https://github.com/mcavage/node-restify
// Definitions by: Bret Little <https://github.com/blittle>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
/// <reference path="../bunyan/bunyan.d.ts" />
declare module "restify" {
import http = require('http');
import bunyan = require('bunyan');
import url = require('url');
interface addressInterface {
port: number;
family: string;
address: string;
}
interface requestFileInterface {
path: string;
type: string;
}
/**
* Comes from authorizationParser plugin
*/
interface requestAuthorization {
scheme: string;
credentials: string;
basic?: {
username: string;
password: string;
}
}
interface Request extends http.ServerRequest {
/**
* builds an absolute URI for the request.
* @private
* @function absoluteUri
* @param {String} path a url path
* @returns {String}
*/
absoluteUri: (path: string) => string;
/**
* returns any header off the request. also, 'correct' any
* correctly spelled 'referrer' header to the actual spelling used.
* @public
* @function header
* @param {String} name the name of the header
* @param {String} value default value if header isn't found on the req
* @returns {String}
*/
header: (name: string, value?: string) => string;
/**
* returns any trailer header off the request. also, 'correct' any
* correctly spelled 'referrer' header to the actual spelling used.
* @public
* @function trailer
* @param {String} name the name of the header
* @param {String} value default value if header isn't found on the req
* @returns {String}
*/
trailer: (name: string, value?: string) => string;
/**
* checks if the accept header is present and has the value requested.
* e.g., req.accepts('html');
* @public
* @function accepts
* @param {String | Array} types an array of accept type headers
* @returns {Boolean}
*/
accepts: (types: string | string[]) => boolean;
/**
* checks if the request accepts the encoding types.
* @public
* @function acceptsEncoding
* @param {String | Array} types an array of accept type headers
* @returns {Boolean}
*/
acceptsEncoding: (types: string | string[]) => boolean;
/**
* Check if the incoming request contains the Content-Type header field, and
* if it contains the given mime type.
* @public
* @function is
* @param {String} type a content-type header value
* @returns {Boolean}
*/
is: (type: string) => boolean;
/**
* Check if the incoming request is chunked.
* @public
* @function isChunked
* @returns {Boolean}
*/
isChunked: () => boolean;
/**
* Check if the incoming request is kept alive.
* @public
* @function isKeepAlive
* @returns {Boolean}
*/
isKeepAlive: () => boolean;
/**
* Check if the incoming request has been upgraded.
* @public
* @function isUpgradeRequest
* @returns {Boolean}
*/
isUpgradeRequest: () => boolean;
/**
* Check if the incoming request is an upload verb.
* @public
* @function isUpload
* @returns {Boolean}
*/
isUpload: () => boolean;
/**
* retrieves the user-agent header.
* @public
* @function userAgent
* @returns {String}
*/
userAgent: () => string;
/**
* Start the timer for a request handler function. You must explicitly invoke
* endHandlerTimer() after invoking this function. Otherwise timing information
* will be inaccurate.
* @public
* @function startHandlerTimer
* @param {String} handlerName The name of the handler.
* @returns {undefined}
*/
startHandlerTimer: (handlerName: string) => void;
/**
* Stop the timer for a request handler function.
* @public
* @function endHandlerTimer
* @param {String} handlerName The name of the handler.
* @returns {undefined}
*/
endHandlerTimer: (handlerName: string) => void;
getLogger: (component: string) => any;
/**
* gets the content-length header off the request.
* @public
* @function getContentLength
* @returns {Number}
*/
getContentLength: () => number;
/**
* @see getContentLength
* @function contentLength
*/
contentLength: () => number;
/**
* gets the content-type header.
* @public
* @function getContentType
* @returns {String}
*/
getContentType: () => string;
/**
* @see getContentType
*/
contentType: () => string;
/**
* retrieves the complete URI requested by the client.
* @public
* @function getHref
* @returns {String}
*/
getHref: () => string;
/**
* @see getHref
*/
href: () => string;
log: bunyan.Logger;
/**
* retrieves the request uuid. was created when the request was setup.
* @public
* @function getId
* @returns {String}
*/
getId: () => string;
/**
* @see getId
*/
id: () => string;
/**
* retrieves the cleaned up url path.
* e.g., /foo?a=1 => /foo
* @public
* @function getPath
* @returns {String}
*/
getPath: () => string;
/**
* @see getPath
*/
path: () => string;
/**
* returns the raw query string
* @public
* @function getQuery
* @returns {String}
*/
getQuery: () => string;
/**
* @see getQuery
*/
query: () => string;
secure: boolean;
/**
* returns ms since epoch when request was setup.
* @public
* @function time
* @returns {Number}
*/
time: () => number;
/**
* returns a parsed URL object.
* @public
* @function getUrl
* @returns {Object}
*/
getUrl: () => url.Url;
/**
* returns the accept-version header.
* @public
* @function getVersion
* @returns {String}
*/
getVersion: () => string;
/**
* @see getVersion
*/
version: () => string;
params: any;
files?: { [name: string]: requestFileInterface };
/**
* Check if the incoming request is encrypted.
* @public
* @function isSecure
* @returns {Boolean}
*/
isSecure: () => boolean;
/** available when bodyParser plugin is used */
body?: any;
/** available when authorizationParser plugin is used */
username?: string;
/** available when authorizationParser plugin is used */
authorization?: requestAuthorization;
timers: HandlerTiming[];
}
/**
* Timer object used to identify how long a specific handler took to run
*
* @property {String} name The name of the handler.
* @property {Array} time A tuple of [seconds, nanoseconds], how long the handler took.
*/
interface HandlerTiming {
name: string;
time: [number, number];
}
interface Response extends http.ServerResponse {
header: (key: string, value ?: any) => any;
cache: (type?: any, options?: Object) => any;
status: (code: number) => any;
send: (status?: any, body?: any, headers?: { [header: string]: string }) => any;
json: (status?: any, body?: any, headers?: { [header: string]: string }) => any;
code: number;
contentLength: number;
charSet(value: string): void;
contentType: string;
headers: Object;
id: string;
}
interface RouteSpec {
method: string;
name: string;
path: string | RegExp;
versions: string[];
}
interface Route {
name: string;
method: string;
path: RoutePathRegex;
spec: RouteSpec;
types: string[];
versions: string[];
}
interface RouteOptions {
name: string;
method: string;
path?: string | RegExp;
url?: string | RegExp;
urlParamPattern?: RegExp;
contentType?: string | string[];
versions?: string | string[];
}
interface RoutePathRegex extends RegExp {
restifyParams: string[];
}
interface Router {
name: string;
mounts: { [routeName: string]: Route };
versions: string[];
contentType: string[];
routes: {
DELETE: Route[];
GET: Route[];
HEAD: Route[];
OPTIONS: Route[];
PATCH: Route[];
POST: Route[];
PUT: Route[];
};
log?: any;
toString: () => string;
/**
* Takes an object of route params and query params, and 'renders' a URL
* @param {String} routeName the route name
* @param {Object} params an object of route params
* @param {Object} query an object of query params
* @returns {String}
*/
render: (routeName: string, params: Object, query?: Object) => string;
/**
* adds a route.
* @param {Object} options an options object
* @returns {String} returns the route name if creation is successful.
*/
mount: (options: Object) => string | boolean;
/**
* unmounts a route.
* @param {String} name the route name
* @returns {String} the name of the deleted route (or false if it was not matched)
*/
unmount: (name: string) => string | boolean;
}
interface Server extends http.Server {
use(handler: RequestHandler, ...handlers: RequestHandler[]): Server;
use(handler: RequestHandler[], ...handlers: RequestHandler[]): Server;
use(handler: RequestHandler, ...handlers: RequestHandler[][]): Server;
use(handler: RequestHandler[], ...handlers: RequestHandler[][]): Server;
post(route: any, routeCallBack: RequestHandler, ...routeCallBacks: RequestHandler[]): string;
post(route: any, routeCallBack: RequestHandler[], ...routeCallBacks: RequestHandler[]): string;
post(route: any, routeCallBack: RequestHandler, ...routeCallBacks: RequestHandler[][]): string;
post(route: any, routeCallBack: RequestHandler[], ...routeCallBacks: RequestHandler[][]): string;
patch(route: any, routeCallBack: RequestHandler, ...routeCallBacks: RequestHandler[]): string;
patch(route: any, routeCallBack: RequestHandler[], ...routeCallBacks: RequestHandler[]): string;
patch(route: any, routeCallBack: RequestHandler, ...routeCallBacks: RequestHandler[][]): string;
patch(route: any, routeCallBack: RequestHandler[], ...routeCallBacks: RequestHandler[][]): string;
put(route: any, routeCallBack: RequestHandler, ...routeCallBacks: RequestHandler[]): string;
put(route: any, routeCallBack: RequestHandler[], ...routeCallBacks: RequestHandler[]): string;
put(route: any, routeCallBack: RequestHandler, ...routeCallBacks: RequestHandler[][]): string;
put(route: any, routeCallBack: RequestHandler[], ...routeCallBacks: RequestHandler[][]): string;
del(route: any, routeCallBack: RequestHandler, ...routeCallBacks: RequestHandler[]): string;
del(route: any, routeCallBack: RequestHandler[], ...routeCallBacks: RequestHandler[]): string;
del(route: any, routeCallBack: RequestHandler, ...routeCallBacks: RequestHandler[][]): string;
del(route: any, routeCallBack: RequestHandler[], ...routeCallBacks: RequestHandler[][]): string;
get(route: any, routeCallBack: RequestHandler, ...routeCallBacks: RequestHandler[]): string;
get(route: any, routeCallBack: RequestHandler[], ...routeCallBacks: RequestHandler[]): string;
get(route: any, routeCallBack: RequestHandler, ...routeCallBacks: RequestHandler[][]): string;
get(route: any, routeCallBack: RequestHandler[], ...routeCallBacks: RequestHandler[][]): string;
head(route: any, routeCallBack: RequestHandler, ...routeCallBacks: RequestHandler[]): string;
head(route: any, routeCallBack: RequestHandler[], ...routeCallBacks: RequestHandler[]): string;
head(route: any, routeCallBack: RequestHandler, ...routeCallBacks: RequestHandler[][]): string;
head(route: any, routeCallBack: RequestHandler[], ...routeCallBacks: RequestHandler[][]): string;
opts(route: any, routeCallBack: RequestHandler, ...routeCallBacks: RequestHandler[]): string;
opts(route: any, routeCallBack: RequestHandler[], ...routeCallBacks: RequestHandler[]): string;
opts(route: any, routeCallBack: RequestHandler, ...routeCallBacks: RequestHandler[][]): string;
opts(route: any, routeCallBack: RequestHandler[], ...routeCallBacks: RequestHandler[][]): string;
name: string;
version: string;
log: Object;
acceptable: string[];
url: string;
address: () => addressInterface;
listen(... args: any[]): any;
close(... args: any[]): any;
pre(routeCallBack: RequestHandler): Server;
server: http.Server;
router: Router;
routes: Route[];
toString: () => string;
}
interface ServerOptions {
certificate ?: string;
key ?: string;
formatters ?: Object;
log ?: Object;
name ?: string;
spdy ?: Object;
version ?: string;
responseTimeHeader ?: string;
responseTimeFormatter ?: (durationInMilliseconds: number) => any;
handleUpgrades ?: boolean;
router ?: Router;
}
interface ClientOptions {
accept?: string;
connectTimeout?: number;
dtrace?: Object;
gzip?: Object;
headers?: Object;
log?: Object;
retry?: Object;
signRequest?: Function;
url?: string;
userAgent?: string;
version?: string;
}
interface Client {
get: (path: string, callback?: (err: any, req: Request, res: Response, obj: any) => any) => any;
head: (path: string, callback?: (err: any, req: Request, res: Response) => any) => any;
post: (path: string, object: any, callback?: (err: any, req: Request, res: Response, obj: any) => any) => any;
put: (path: string, object: any, callback?: (err: any, req: Request, res: Response, obj: any) => any) => any;
patch: (path: string, object: any, callback?: (err: any, req: Request, res: Response, obj: any) => any) => any;
del: (path: string, callback?: (err: any, req: Request, res: Response) => any) => any;
basicAuth: (username: string, password: string) => any;
}
interface HttpClient extends Client {
get: (path?: any, callback?: Function) => any;
head: (path?:any, callback?: Function) => any;
post: (opts?: any, callback?: Function) => any;
put: (opts?: any, callback?: Function) => any;
patch: (opts?: any, callback?: Function) => any;
del: (opts?: any, callback?: Function) => any;
}
interface ThrottleOptions {
burst?: number;
rate?: number;
ip?: boolean;
xff?: boolean;
username?: boolean;
tokensTable?: Object;
maxKeys?: number;
overrides?: Object;
}
interface Next {
(err?: any): any;
ifError?: (err?: any) => any;
}
interface RequestHandler {
(req: Request, res: Response, next: Next): any;
}
interface CORS {
(cors?: {
origins?: string[];
credentials?: boolean;
headers?: string[];
}): RequestHandler;
origins: string[];
ALLOW_HEADERS: string[];
credentials: boolean;
}
export function createServer(options?: ServerOptions): Server;
export function createJsonClient(options?: ClientOptions): Client;
export function createStringClient(options?: ClientOptions): Client;
export function createClient(options?: ClientOptions): HttpClient;
export class HttpError { constructor(cause: any, message?: any); }
class DefiniteHttpError {
constructor(message?: any);
constructor(cause: any, message?: any);
}
export class BadRequestError extends DefiniteHttpError {}
export class UnauthorizedError extends DefiniteHttpError {}
export class PaymentRequiredError extends DefiniteHttpError {}
export class ForbiddenError extends DefiniteHttpError {}
export class NotFoundError extends DefiniteHttpError {}
export class MethodNotAllowedError extends DefiniteHttpError {}
export class NotAcceptableError extends DefiniteHttpError {}
export class ProxyAuthenticationRequiredError extends DefiniteHttpError {}
export class RequestTimeoutError extends DefiniteHttpError {}
export class ConflictError extends DefiniteHttpError {}
export class GoneError extends DefiniteHttpError {}
export class LengthRequiredError extends DefiniteHttpError {}
export class RequestEntityTooLargeError extends DefiniteHttpError {}
export class RequesturiTooLargeError extends DefiniteHttpError {}
export class UnsupportedMediaTypeError extends DefiniteHttpError {}
export class RequestedRangeNotSatisfiableError extends DefiniteHttpError {}
export class ExpectationFailedError extends DefiniteHttpError {}
export class ImATeapotError extends DefiniteHttpError {}
export class UnprocessableEntityError extends DefiniteHttpError {}
export class LockedError extends DefiniteHttpError {}
export class FailedDependencyError extends DefiniteHttpError {}
export class UnorderedCollectionError extends DefiniteHttpError {}
export class UpgradeRequiredError extends DefiniteHttpError {}
export class PreconditionRequiredError extends DefiniteHttpError {}
export class TooManyRequestsError extends DefiniteHttpError {}
export class RequestHeaderFieldsTooLargeError extends DefiniteHttpError {}
export class InternalServerError extends DefiniteHttpError {}
export class NotImplementedError extends DefiniteHttpError {}
export class BadGatewayError extends DefiniteHttpError {}
export class ServiceUnavailableError extends DefiniteHttpError {}
export class GatewayTimeoutError extends DefiniteHttpError {}
export class HttpVersionNotSupportedError extends DefiniteHttpError {}
export class VariantAlsoNegotiatesError extends DefiniteHttpError {}
export class InsufficientStorageError extends DefiniteHttpError {}
export class BandwidthLimitExceededError extends DefiniteHttpError {}
export class NotExtendedError extends DefiniteHttpError {}
export class NetworkAuthenticationRequiredError extends DefiniteHttpError {}
export class RestError extends DefiniteHttpError {}
export class PreconditionFailedError extends RestError {}
export class BadDigestError extends RestError {}
export class BadMethodError extends RestError {}
export class InternalError extends RestError {}
export class InvalidArgumentError extends RestError {}
export class InvalidContentError extends RestError {}
export class InvalidCredentialsError extends RestError {}
export class InvalidHeaderError extends RestError {}
export class InvalidVersionError extends RestError {}
export class MissingParameterError extends RestError {}
export class NotAuthorizedError extends RestError {}
export class RequestExpiredError extends RestError {}
export class RequestThrottledError extends RestError {}
export class ResourceNotFoundError extends RestError {}
export class WrongAcceptError extends RestError {}
export function acceptParser(parser: any): RequestHandler;
export function authorizationParser(): RequestHandler;
export function dateParser(skew?: number): RequestHandler;
export function queryParser(options?: Object): RequestHandler;
export function urlEncodedBodyParser(options?: Object): RequestHandler[];
export function jsonp(): RequestHandler;
export function gzipResponse(options?: Object): RequestHandler;
export function bodyParser(options?: Object): RequestHandler[];
export function requestLogger(options?: Object): RequestHandler;
export function serveStatic(options?: Object): RequestHandler;
export function throttle(options?: ThrottleOptions): RequestHandler;
export function conditionalRequest(): RequestHandler[];
export function auditLogger(options?: Object): Function;
export function fullResponse(): RequestHandler;
export var defaultResponseHeaders : any;
export var CORS: CORS;
export module pre {
export function pause(): RequestHandler;
export function sanitizePath(options?: any): RequestHandler;
export function userAgentConnection(options?: any): RequestHandler;
}
}