-
Notifications
You must be signed in to change notification settings - Fork 192
/
Copy pathindex.d.ts
executable file
·549 lines (445 loc) · 12.5 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
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
/**
* An Error object used to return an HTTP response error (4xx, 5xx)
*/
export class Boom<Data = any> extends Error {
/**
* Creates a new Boom object using the provided message
*/
constructor(message?: string | Error, options?: Options<Data>);
/**
* Custom error data with additional information specific to the error type
*/
data?: Data;
/**
* isBoom - if true, indicates this is a Boom object instance.
*/
isBoom: boolean;
/**
* Convenience boolean indicating status code >= 500
*/
isServer: boolean;
/**
* The error message
*/
message: string;
/**
* The formatted response
*/
output: Output;
/**
* The constructor used to create the error
*/
typeof: Function;
/**
* Specifies if an error object is a valid boom object
*
* @param debug - A boolean that, when true, does not hide the original 500 error message. Defaults to false.
*/
reformat(debug?: boolean): string;
}
export interface Options<Data> {
/**
* The HTTP status code
*
* @default 500
*/
statusCode?: number;
/**
* Additional error information
*/
data?: Data;
/**
* Constructor reference used to crop the exception call stack output
*/
ctor?: Function;
/**
* Error message string
*
* @default none
*/
message?: string;
/**
* If false, the err provided is a Boom object, and a statusCode or message are provided, the values are ignored
*
* @default true
*/
override?: boolean;
}
export interface Decorate<Decoration> {
/**
* An option with extra properties to set on the error object
*/
decorate?: Decoration;
}
export interface Payload {
/**
* The HTTP status code derived from error.output.statusCode
*/
statusCode: number;
/**
* The HTTP status message derived from statusCode
*/
error: string;
/**
* The error message derived from error.message
*/
message: string;
/**
* Custom properties
*/
[key: string]: unknown;
}
export interface Output {
/**
* The HTTP status code
*/
statusCode: number;
/**
* An object containing any HTTP headers where each key is a header name and value is the header content
*/
headers: { [header: string]: string | string[] | number | undefined };
/**
* The formatted object used as the response payload (stringified)
*/
payload: Payload;
}
/**
* Specifies if an object is a valid boom object
*
* @param obj - The object to assess
* @param statusCode - Optional status code
*
* @returns Returns a boolean stating if the error object is a valid boom object and it has the provided statusCode (if present)
*/
export function isBoom(obj: unknown, statusCode?: number): obj is Boom;
/**
* Specifies if an error object is a valid boom object
*
* @param err - The error object to decorate
* @param options - Options object
*
* @returns A decorated boom object
*/
export function boomify<Data, Decoration>(err: Error, options?: Options<Data> & Decorate<Decoration>): Boom<Data> & Decoration;
// 4xx Errors
/**
* Returns a 400 Bad Request error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 400 bad request error
*/
export function badRequest<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 401 Unauthorized error
*
* @param message - Optional message
*
* @returns A 401 Unauthorized error
*/
export function unauthorized<Data>(message?: string | null): Boom<Data>;
/**
* Returns a 401 Unauthorized error
*
* @param message - Optional message
* @param scheme - the authentication scheme name
* @param attributes - an object of values used to construct the 'WWW-Authenticate' header
*
* @returns A 401 Unauthorized error
*/
export function unauthorized<Data>(message: '' | null, scheme: string, attributes?: string | unauthorized.Attributes): Boom<Data> & unauthorized.MissingAuth;
export function unauthorized<Data>(message: string | null, scheme: string, attributes?: string | unauthorized.Attributes): Boom<Data>;
export namespace unauthorized {
interface Attributes {
[index: string]: number | string | null | undefined;
}
interface MissingAuth {
/**
* Indicate whether the 401 unauthorized error is due to missing credentials (vs. invalid)
*/
isMissing: boolean;
}
}
/**
* Returns a 401 Unauthorized error
*
* @param message - Optional message
* @param wwwAuthenticate - array of string values used to construct the wwwAuthenticate header
*
* @returns A 401 Unauthorized error
*/
export function unauthorized<Data>(message: string | null, wwwAuthenticate: string[]): Boom<Data>;
/**
* Returns a 402 Payment Required error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 402 Payment Required error
*/
export function paymentRequired<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 403 Forbidden error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 403 Forbidden error
*/
export function forbidden<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 404 Not Found error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 404 Not Found error
*/
export function notFound<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 405 Method Not Allowed error
*
* @param message - Optional message
* @param data - Optional additional error data
* @param allow - Optional string or array of strings which is used to set the 'Allow' header
*
* @returns A 405 Method Not Allowed error
*/
export function methodNotAllowed<Data>(message?: string, data?: Data, allow?: string | string[]): Boom<Data>;
/**
* Returns a 406 Not Acceptable error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 406 Not Acceptable error
*/
export function notAcceptable<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 407 Proxy Authentication error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 407 Proxy Authentication error
*/
export function proxyAuthRequired<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 408 Request Time-out error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 408 Request Time-out error
*/
export function clientTimeout<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 409 Conflict error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 409 Conflict error
*/
export function conflict<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 410 Gone error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 410 gone error
*/
export function resourceGone<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 411 Length Required error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 411 Length Required error
*/
export function lengthRequired<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 412 Precondition Failed error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 412 Precondition Failed error
*/
export function preconditionFailed<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 413 Request Entity Too Large error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 413 Request Entity Too Large error
*/
export function entityTooLarge<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 414 Request-URI Too Large error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 414 Request-URI Too Large error
*/
export function uriTooLong<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 415 Unsupported Media Type error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 415 Unsupported Media Type error
*/
export function unsupportedMediaType<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 416 Request Range Not Satisfiable error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 416 Request Range Not Satisfiable error
*/
export function rangeNotSatisfiable<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 417 Expectation Failed error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 417 Expectation Failed error
*/
export function expectationFailed<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 418 I'm a Teapot error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 418 I'm a Teapot error
*/
export function teapot<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 422 Unprocessable Entity error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 422 Unprocessable Entity error
*/
export function badData<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 423 Locked error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 423 Locked error
*/
export function locked<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 424 Failed Dependency error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 424 Failed Dependency error
*/
export function failedDependency<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 425 Too Early error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 425 Too Early error
*/
export function tooEarly<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 428 Precondition Required error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 428 Precondition Required error
*/
export function preconditionRequired<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 429 Too Many Requests error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 429 Too Many Requests error
*/
export function tooManyRequests<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 451 Unavailable For Legal Reasons error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 451 Unavailable for Legal Reasons error
*/
export function illegal<Data>(message?: string, data?: Data): Boom<Data>;
// 5xx Errors
/**
* Returns a internal error (defaults to 500)
*
* @param message - Optional message
* @param data - Optional additional error data
* @param statusCode - Optional status code override. Defaults to 500.
*
* @returns A 500 Internal Server error
*/
export function internal<Data>(message?: string, data?: Data, statusCode?: number): Boom<Data>;
/**
* Returns a 500 Internal Server Error error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 500 Internal Server error
*/
export function badImplementation<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 501 Not Implemented error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 501 Not Implemented error
*/
export function notImplemented<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 502 Bad Gateway error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 502 Bad Gateway error
*/
export function badGateway<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 503 Service Unavailable error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 503 Service Unavailable error
*/
export function serverUnavailable<Data>(message?: string, data?: Data): Boom<Data>;
/**
* Returns a 504 Gateway Time-out error
*
* @param message - Optional message
* @param data - Optional additional error data
*
* @returns A 504 Gateway Time-out error
*/
export function gatewayTimeout<Data>(message?: string, data?: Data): Boom<Data>;