@athenna/http 3.0.10 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/build/Commands/MakeControllerCommand.d.ts +15 -0
  2. package/build/Commands/MakeControllerCommand.js +42 -0
  3. package/build/Commands/MakeInterceptorCommand.d.ts +15 -0
  4. package/build/Commands/MakeInterceptorCommand.js +42 -0
  5. package/build/Commands/MakeMiddlewareCommand.d.ts +15 -0
  6. package/build/Commands/MakeMiddlewareCommand.js +42 -0
  7. package/build/Commands/MakeTerminatorCommand.d.ts +15 -0
  8. package/build/Commands/MakeTerminatorCommand.js +42 -0
  9. package/build/Commands/RouteListCommand.d.ts +19 -0
  10. package/build/Commands/RouteListCommand.js +62 -0
  11. package/build/Context/Request.d.ts +144 -0
  12. package/build/Context/Request.js +219 -0
  13. package/build/Context/Response.d.ts +67 -0
  14. package/build/Context/Response.js +102 -0
  15. package/build/Contracts/InterceptorContract.d.ts +15 -0
  16. package/build/Contracts/InterceptorContract.js +9 -0
  17. package/build/Contracts/MiddlewareContract.d.ts +15 -0
  18. package/build/Contracts/MiddlewareContract.js +9 -0
  19. package/build/Contracts/TerminatorContract.d.ts +15 -0
  20. package/build/Contracts/TerminatorContract.js +9 -0
  21. package/build/Decorators/Controller.d.ts +14 -0
  22. package/build/Decorators/Controller.js +28 -0
  23. package/build/Decorators/Interceptor.d.ts +14 -0
  24. package/build/Decorators/Interceptor.js +37 -0
  25. package/build/Decorators/Middleware.d.ts +14 -0
  26. package/build/Decorators/Middleware.js +37 -0
  27. package/build/Decorators/Terminator.d.ts +14 -0
  28. package/build/Decorators/Terminator.js +37 -0
  29. package/build/Exceptions/BadGatewayException.d.ts +20 -0
  30. package/build/Exceptions/BadGatewayException.js +22 -0
  31. package/build/Exceptions/BadRequestException.d.ts +20 -0
  32. package/build/Exceptions/BadRequestException.js +22 -0
  33. package/build/Exceptions/ForbiddenException.d.ts +20 -0
  34. package/build/Exceptions/ForbiddenException.js +22 -0
  35. package/build/Exceptions/HttpException.d.ts +20 -0
  36. package/build/Exceptions/HttpException.js +27 -0
  37. package/build/Exceptions/InternalServerException.d.ts +20 -0
  38. package/build/Exceptions/InternalServerException.js +22 -0
  39. package/build/Exceptions/MethodNotAllowedException.d.ts +20 -0
  40. package/build/Exceptions/MethodNotAllowedException.js +22 -0
  41. package/build/Exceptions/NotAcceptableException.d.ts +20 -0
  42. package/build/Exceptions/NotAcceptableException.js +22 -0
  43. package/build/Exceptions/NotFoundException.d.ts +20 -0
  44. package/build/Exceptions/NotFoundException.js +22 -0
  45. package/build/Exceptions/NotImplementedException.d.ts +20 -0
  46. package/build/Exceptions/NotImplementedException.js +22 -0
  47. package/build/Exceptions/PayloadTooLargeException.d.ts +20 -0
  48. package/build/Exceptions/PayloadTooLargeException.js +22 -0
  49. package/build/Exceptions/RequestTimeoutException.d.ts +20 -0
  50. package/build/Exceptions/RequestTimeoutException.js +22 -0
  51. package/build/Exceptions/ServiceUnavailableException.d.ts +20 -0
  52. package/build/Exceptions/ServiceUnavailableException.js +22 -0
  53. package/build/Exceptions/UnauthorizedException.d.ts +20 -0
  54. package/build/Exceptions/UnauthorizedException.js +22 -0
  55. package/build/Exceptions/UndefinedMethodException.d.ts +12 -0
  56. package/build/Exceptions/UndefinedMethodException.js +19 -0
  57. package/build/Exceptions/UnprocessableEntityException.d.ts +20 -0
  58. package/build/Exceptions/UnprocessableEntityException.js +22 -0
  59. package/build/Facades/Route.d.ts +10 -0
  60. package/{src → build}/Facades/Route.js +2 -7
  61. package/build/Facades/Server.d.ts +10 -0
  62. package/{src → build}/Facades/Server.js +2 -7
  63. package/build/Handlers/FastifyHandler.d.ts +41 -0
  64. package/build/Handlers/FastifyHandler.js +116 -0
  65. package/build/Handlers/HttpExceptionHandler.d.ts +31 -0
  66. package/build/Handlers/HttpExceptionHandler.js +82 -0
  67. package/build/Kernels/HttpKernel.d.ts +73 -0
  68. package/build/Kernels/HttpKernel.js +221 -0
  69. package/build/Providers/HttpRouteProvider.d.ts +12 -0
  70. package/build/Providers/HttpRouteProvider.js +15 -0
  71. package/build/Providers/HttpServerProvider.d.ts +13 -0
  72. package/build/Providers/HttpServerProvider.js +25 -0
  73. package/build/Router/Route.d.ts +263 -0
  74. package/build/Router/Route.js +447 -0
  75. package/build/Router/RouteGroup.d.ts +96 -0
  76. package/build/Router/RouteGroup.js +123 -0
  77. package/build/Router/RouteResource.d.ts +108 -0
  78. package/build/Router/RouteResource.js +158 -0
  79. package/build/Router/Router.d.ts +103 -0
  80. package/build/Router/Router.js +188 -0
  81. package/build/Server/ServerImpl.d.ts +129 -0
  82. package/build/Server/ServerImpl.js +213 -0
  83. package/build/Types/Contexts/Context.d.ts +20 -0
  84. package/build/Types/Contexts/Context.js +9 -0
  85. package/build/Types/Contexts/ErrorContext.d.ts +21 -0
  86. package/build/Types/Contexts/ErrorContext.js +9 -0
  87. package/build/Types/Contexts/InterceptContext.d.ts +20 -0
  88. package/build/Types/Contexts/InterceptContext.js +9 -0
  89. package/build/Types/Contexts/TerminateContext.d.ts +21 -0
  90. package/build/Types/Contexts/TerminateContext.js +9 -0
  91. package/build/Types/Controllers/ControllerOptions.d.ts +25 -0
  92. package/build/Types/Controllers/ControllerOptions.js +9 -0
  93. package/build/Types/Middlewares/InterceptorRouteType.d.ts +11 -0
  94. package/build/Types/Middlewares/InterceptorRouteType.js +9 -0
  95. package/build/Types/Middlewares/MiddlewareHandler.d.ts +20 -0
  96. package/build/Types/Middlewares/MiddlewareHandler.js +9 -0
  97. package/build/Types/Middlewares/MiddlewareOptions.d.ts +40 -0
  98. package/build/Types/Middlewares/MiddlewareOptions.js +9 -0
  99. package/build/Types/Middlewares/MiddlewareRouteType.d.ts +11 -0
  100. package/build/Types/Middlewares/MiddlewareRouteType.js +9 -0
  101. package/build/Types/Middlewares/TerminatorRouteType.d.ts +11 -0
  102. package/build/Types/Middlewares/TerminatorRouteType.js +9 -0
  103. package/build/Types/Router/RouteHandler.d.ts +10 -0
  104. package/build/Types/Router/RouteHandler.js +9 -0
  105. package/build/Types/Router/RouteJSON.d.ts +21 -0
  106. package/build/Types/Router/RouteJSON.js +9 -0
  107. package/build/Types/Router/RouteResourceTypes.d.ts +9 -0
  108. package/build/Types/Router/RouteResourceTypes.js +9 -0
  109. package/build/index.d.ts +70 -0
  110. package/build/index.js +48 -0
  111. package/package.json +159 -76
  112. package/templates/controller.edge +8 -36
  113. package/templates/interceptor.edge +8 -0
  114. package/templates/middleware.edge +4 -36
  115. package/templates/terminator.edge +6 -0
  116. package/src/Commands/Make/Controller.js +0 -64
  117. package/src/Commands/Make/Middleware.js +0 -80
  118. package/src/Commands/Route/List.js +0 -107
  119. package/src/Context/Request.js +0 -223
  120. package/src/Context/Response.js +0 -137
  121. package/src/Exceptions/BadGatewayException.js +0 -31
  122. package/src/Exceptions/BadRequestException.js +0 -31
  123. package/src/Exceptions/ForbiddenException.js +0 -31
  124. package/src/Exceptions/HttpException.js +0 -33
  125. package/src/Exceptions/InternalServerException.js +0 -31
  126. package/src/Exceptions/MethodNotAllowedException.js +0 -31
  127. package/src/Exceptions/NotAcceptableException.js +0 -31
  128. package/src/Exceptions/NotFoundException.js +0 -31
  129. package/src/Exceptions/NotImplementedException.js +0 -31
  130. package/src/Exceptions/PayloadTooLargeException.js +0 -31
  131. package/src/Exceptions/RequestTimeoutException.js +0 -31
  132. package/src/Exceptions/ServiceUnavailableException.js +0 -31
  133. package/src/Exceptions/UnauthorizedException.js +0 -31
  134. package/src/Exceptions/UndefinedMethodException.js +0 -30
  135. package/src/Exceptions/UnprocessableEntityException.js +0 -31
  136. package/src/Handlers/FastifyHandler.js +0 -148
  137. package/src/Handlers/HttpExceptionHandler.js +0 -88
  138. package/src/Helpers/HttpLoader.js +0 -38
  139. package/src/Kernels/HttpKernel.js +0 -199
  140. package/src/Providers/ControllerProvider.js +0 -29
  141. package/src/Providers/HttpRouteProvider.js +0 -24
  142. package/src/Providers/HttpServerProvider.js +0 -37
  143. package/src/Providers/MiddlewareProvider.js +0 -29
  144. package/src/Router/Route.js +0 -417
  145. package/src/Router/RouteGroup.js +0 -119
  146. package/src/Router/RouteResource.js +0 -247
  147. package/src/Router/Router.js +0 -313
  148. package/src/Utils/isMiddlewareContract.js +0 -17
  149. package/src/Utils/removeSlashes.js +0 -30
  150. package/src/index.d.ts +0 -1331
  151. package/src/index.js +0 -377
package/src/index.d.ts DELETED
@@ -1,1331 +0,0 @@
1
- /**
2
- * @athenna/http
3
- *
4
- * (c) João Lenon <lenon@athenna.io>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
-
10
- import { Facade } from '@athenna/ioc'
11
- import { Exception, Json } from '@athenna/common'
12
- import { OpenAPIV2, OpenAPIV3 } from 'openapi-types'
13
- import { FastifyHelmetOptions } from '@fastify/helmet'
14
- import { RateLimitOptions } from '@fastify/rate-limit'
15
- import { FastifyReply, FastifyRequest, RouteOptions } from 'fastify'
16
-
17
- export const Server: typeof Facade & Http
18
- export const Route: typeof Facade & Router.Router
19
-
20
- interface FastifySwaggerSchema {
21
- hide?: boolean
22
- deprecated?: boolean
23
- tags?: string[]
24
- description?: string
25
- summary?: string
26
- body?: any
27
- response?: any
28
- consumes?: string[]
29
- produces?: string[]
30
- externalDocs?:
31
- | OpenAPIV2.ExternalDocumentationObject
32
- | OpenAPIV3.ExternalDocumentationObject
33
- security?: Array<{ [securityLabel: string]: string[] }>
34
- /**
35
- * OpenAPI operation unique identifier
36
- */
37
- operationId?: string
38
- }
39
-
40
- export class HttpKernel {
41
- /**
42
- * The application's global HTTP middlewares.
43
- *
44
- * This middlewares are run during every request to your http server.
45
- *
46
- * @type {any | Promise<any>}
47
- */
48
- get globalMiddlewares(): any | Promise<any>
49
-
50
- /**
51
- * The application's named HTTP middlewares.
52
- *
53
- * Here you define all your named middlewares to use inside routes/http file.
54
- *
55
- * @type {Record<string, any | Promise<any>>}
56
- */
57
- get namedMiddlewares(): Record<string, any | Promise<any>>
58
-
59
- /**
60
- * Register all global and named middlewares to the server.
61
- *
62
- * @return void
63
- */
64
- registerMiddlewares(): Promise<void>
65
-
66
- /**
67
- * Register cors plugin.
68
- *
69
- * @return {Promise<void>}
70
- */
71
- registerCors(): Promise<void>
72
-
73
- /**
74
- * Register the rTracer plugin.
75
- *
76
- * @return {Promise<void>}
77
- */
78
- registerTracer(): Promise<void>
79
-
80
- /**
81
- * Register helmet plugin.
82
- *
83
- * @return {Promise<void>}
84
- */
85
- registerHelmet(): Promise<void>
86
-
87
- /**
88
- * Register swagger plugin.
89
- *
90
- * @return {Promise<void>}
91
- */
92
- registerSwagger(): Promise<void>
93
-
94
- /**
95
- * Register rate limit plugin.
96
- *
97
- * @return {Promise<void>}
98
- */
99
- registerRateLimit(): Promise<void>
100
-
101
- /**
102
- * Register the default error handler.
103
- *
104
- * @return {Promise<void>}
105
- */
106
- registerErrorHandler(): Promise<void>
107
-
108
- /**
109
- * Register log terminate middleware.
110
- *
111
- * @return {Promise<void>}
112
- */
113
- registerLogMiddleware(): Promise<void>
114
- }
115
-
116
- export class HttpExceptionHandler {
117
- /**
118
- * Error codes that should be ignored by Log.
119
- *
120
- * @type {string[]}
121
- */
122
- get ignoreCodes(): string[]
123
-
124
- /**
125
- * Error statuses that should be ignored by Log.
126
- *
127
- * @type {number[]}
128
- */
129
- get ignoreStatuses(): number[]
130
-
131
- /**
132
- * The global exception handler of all HTTP requests.
133
- *
134
- * @param ctx
135
- */
136
- handle(ctx: ErrorContextContract): Promise<any>
137
- }
138
-
139
- export class Http {
140
- /**
141
- * Set the fastify error handler.
142
- *
143
- * @param {any} handler
144
- * @return {Http}
145
- */
146
- setErrorHandler(handler: ErrorHandlerContract): Http
147
-
148
- /**
149
- * Register a new fastify plugin.
150
- *
151
- * @param {import('fastify').FastifyPluginCallback<import('fastify').FastifyPluginOptions>} plugin
152
- * @param {import('fastify').FastifyRegisterOptions<import('fastify').FastifyPluginOptions>} [options]
153
- * @return {Promise<Http>}
154
- */
155
- register(
156
- plugin: import('fastify').FastifyPluginCallback<
157
- import('fastify').FastifyPluginOptions
158
- >,
159
- options?: import('fastify').FastifyRegisterOptions<
160
- import('fastify').FastifyPluginOptions
161
- >,
162
- ): Promise<Http>
163
-
164
- /**
165
- * Register the cors plugin to fastify server.
166
- *
167
- * @param {import('@fastify/cors').FastifyCorsOptions} [options]
168
- * @return {Promise<Http>}
169
- */
170
- registerCors(options?: import('@fastify/cors').FastifyCorsOptions): Promise<Http>
171
-
172
- /**
173
- * Register the rTracer plugin.
174
- *
175
- * @param {import('cls-rtracer').IFastifyOptions} options
176
- * @return {Promise<Http>}
177
- */
178
- registerTracer(options?: import('cls-rtracer').IFastifyOptions): Promise<Http>
179
-
180
- /**
181
- * Register the helmet plugin to fastify server.
182
- *
183
- * @param {import('@fastify/helmet').FastifyHelmetOptions} [options]
184
- * @return {Promise<Http>}
185
- */
186
- registerHelmet(options?: import('@fastify/helmet').FastifyHelmetOptions): Promise<Http>
187
-
188
- /**
189
- * Register the swagger plugin to fastify server.
190
- *
191
- * @param {import('@fastify/swagger').SwaggerOptions} [options]
192
- * @return {Promise<Http>}
193
- */
194
- registerSwagger(options?: import('@fastify/swagger').SwaggerOptions): Promise<Http>
195
-
196
- /**
197
- * Register the rate limit plugin to fastify server.
198
- *
199
- * @param {import('@fastify/rate-limit').RateLimitOptions} [options]
200
- * @return {Promise<Http>}
201
- */
202
- registerRateLimit(
203
- options?: import('@fastify/rate-limit').RateLimitOptions,
204
- ): Promise<Http>
205
-
206
- /**
207
- * Get the fastify server instance.
208
- *
209
- * @return {import('fastify').FastifyInstance}
210
- */
211
- getFastify(): import('fastify').FastifyInstance
212
-
213
- /**
214
- * Print all routes registered.
215
- *
216
- * @param {import('fastify').PrintRoutesOptions} [options]
217
- * @return {string}
218
- */
219
- getRoutes(options?: import('fastify').PrintRoutesOptions): string
220
-
221
- /**
222
- * Get the server port where http is being running.
223
- *
224
- * @return {number}
225
- */
226
- getPort(): number
227
-
228
- /**
229
- * Get the server http version.
230
- *
231
- * @return {string}
232
- */
233
- getVersion(): string
234
-
235
- /**
236
- * Print all routes registered.
237
- *
238
- * @param {any} handler
239
- * @param {'handle'|'intercept'|'terminate'} type
240
- * @return void
241
- */
242
- use(handler: any, type?: 'handle' | 'intercept' | 'terminate'): void
243
-
244
- /**
245
- * Return a request handler to make internal requests to the Http server.
246
- *
247
- * @param {import('fastify').InjectOptions|string} [options]
248
- * @return {import('light-my-request').Chain,Promise<import('light-my-request').Response>}
249
- */
250
- request(
251
- options?: import('fastify').InjectOptions | string,
252
- ): import('light-my-request').Chain
253
-
254
- /**
255
- * Boot the http server to start listening on port and host defined.
256
- *
257
- * @param {string|number} [port]
258
- * @param {string} [host]
259
- * @return {Promise<string>}
260
- */
261
- listen(port?: string | number, host?: string): Promise<string>
262
-
263
- /**
264
- * Close the http server.
265
- *
266
- * @return {Promise<void>}
267
- */
268
- close(): Promise<void>
269
-
270
- /**
271
- * Add a new route to the http server.
272
- *
273
- * @param {string} url
274
- * @param {string[]} methods
275
- * @param {any} handler
276
- * @param {any} [middlewares]
277
- * @return {void}
278
- */
279
- route(
280
- url: string,
281
- methods: string[],
282
- handler: HandlerContract,
283
- middlewares?: any,
284
- ): void
285
-
286
- /**
287
- * Add a new GET route to the http server.
288
- *
289
- * @param {string} url
290
- * @param {any} handler
291
- * @param {any} [middlewares]
292
- * @return {void}
293
- */
294
- get(url: string, handler: HandlerContract, middlewares?: any): void
295
-
296
- /**
297
- * Add a new HEAD route to the http server.
298
- *
299
- * @param {string} url
300
- * @param {any} handler
301
- * @param {any} [middlewares]
302
- * @return {void}
303
- */
304
- head(url: string, handler: HandlerContract, middlewares?: any): void
305
-
306
- /**
307
- * Add a new POST route to the http server.
308
- *
309
- * @param {string} url
310
- * @param {any} handler
311
- * @param {any} [middlewares]
312
- * @return {void}
313
- */
314
- post(url: string, handler: HandlerContract, middlewares?: any): void
315
-
316
- /**
317
- * Add a new PUT route to the http server.
318
- *
319
- * @param {string} url
320
- * @param {any} handler
321
- * @param {any} [middlewares]
322
- * @return {void}
323
- */
324
- put(url: string, handler: HandlerContract, middlewares?: any): void
325
-
326
- /**
327
- * Add a new PATCH route to the http server.
328
- *
329
- * @param {string} url
330
- * @param {any} handler
331
- * @param {any} [middlewares]
332
- * @return {void}
333
- */
334
- patch(url: string, handler: HandlerContract, middlewares?: any): void
335
-
336
- /**
337
- * Add a new DELETE route to the http server.
338
- *
339
- * @param {string} url
340
- * @param {any} handler
341
- * @param {any} [middlewares]
342
- * @return {void}
343
- */
344
- delete(url: string, handler: HandlerContract, middlewares?: any): void
345
-
346
- /**
347
- * Add a new OPTIONS route to the http server.
348
- *
349
- * @param {string} url
350
- * @param {any} handler
351
- * @param {any} [middlewares]
352
- * @return {void}
353
- */
354
- options(url: string, handler: HandlerContract, middlewares?: any): void
355
- }
356
-
357
- declare module Router {
358
- class Route {
359
- name: string
360
- deleted: boolean
361
-
362
- constructor(
363
- url: string,
364
- methods: string[],
365
- handler: HandlerContract | string,
366
- )
367
-
368
- prefix(prefix): this
369
-
370
- middleware(
371
- middleware: string,
372
- type?: 'handle' | 'intercept' | 'terminate',
373
- prepend?: boolean,
374
- ): this
375
-
376
- middleware(
377
- middleware: MiddlewareContract,
378
- type?: 'handle' | 'intercept' | 'terminate',
379
- prepend?: boolean,
380
- ): this
381
-
382
- middleware(
383
- middleware: HandleHandlerContract,
384
- type?: 'handle',
385
- prepend?: boolean,
386
- ): this
387
-
388
- middleware(
389
- middleware: InterceptHandlerContract,
390
- type?: 'intercept',
391
- prepend?: boolean,
392
- ): this
393
-
394
- middleware(
395
- middleware: TerminateHandlerContract,
396
- type?: 'terminate',
397
- prepend?: boolean,
398
- ): this
399
-
400
- /**
401
- * Set up all helmet options for route.
402
- *
403
- * @param {any} options
404
- * @return {Route}
405
- */
406
- helmet(options: FastifyHelmetOptions): this
407
-
408
- /**
409
- * Set up all swagger options for route.
410
- *
411
- * @param {any} options
412
- * @return {Route}
413
- */
414
- swagger(options: FastifySwaggerSchema): this
415
-
416
- /**
417
- * Set up all rate limit options for route.
418
- *
419
- * @param {any} options
420
- * @return {Route}
421
- */
422
- rateLimit(options: RateLimitOptions): this
423
-
424
- /**
425
- * Set a summary for the route swagger docs.
426
- *
427
- * @param {string} summary
428
- * @return {Route}
429
- */
430
- summary(summary: string): this
431
-
432
- /**
433
- * Set a description for the route swagger docs.
434
- *
435
- * @param {string} description
436
- * @return {Route}
437
- */
438
- description(description: string): this
439
-
440
- /**
441
- * Set tags for the route swagger docs.
442
- *
443
- * @param {string} tags
444
- * @return {Route}
445
- */
446
- tags(...tags: string[]): this
447
-
448
- /**
449
- * Set body param for the route swagger docs.
450
- *
451
- * @param {string} name
452
- * @param {string} [type]
453
- * @param {string} [description]
454
- * @return {Route}
455
- */
456
- body(name: string, type?: string, description?: string): Route
457
-
458
- /**
459
- * Set param for the route swagger docs.
460
- *
461
- * @param {string} name
462
- * @param {string} [type]
463
- * @param {string} [description]
464
- * @return {Route}
465
- */
466
- param(name, type?: string, description?: string): Route
467
-
468
- /**
469
- * Set query string for the route swagger docs.
470
- *
471
- * @param {string} name
472
- * @param {string} [type]
473
- * @param {string} [description]
474
- * @return {Route}
475
- */
476
- queryString(name, type?: string, description?: string): Route
477
-
478
- /**
479
- * Set response for the route swagger docs.
480
- *
481
- * @param {any} response
482
- * @return {Route}
483
- */
484
- response(response: any): this
485
-
486
- /**
487
- * Set response for the route swagger docs.
488
- *
489
- * @param {number} statusCode
490
- * @param {any} response
491
- * @return {Route}
492
- */
493
- response(statusCode: number, response: any): this
494
-
495
- toJSON(): any
496
- }
497
-
498
- export class RouteResource {
499
- routes: Route[]
500
-
501
- constructor(resource: string, controller: any)
502
-
503
- middleware(
504
- middleware: string,
505
- type?: 'handle' | 'intercept' | 'terminate',
506
- prepend?: boolean,
507
- ): this
508
-
509
- middleware(
510
- middleware: MiddlewareContract,
511
- type?: 'handle' | 'intercept' | 'terminate',
512
- prepend?: boolean,
513
- ): this
514
-
515
- middleware(
516
- middleware: HandleHandlerContract,
517
- type?: 'handle',
518
- prepend?: boolean,
519
- ): this
520
-
521
- middleware(
522
- middleware: InterceptHandlerContract,
523
- type?: 'intercept',
524
- prepend?: boolean,
525
- ): this
526
-
527
- middleware(
528
- middleware: TerminateHandlerContract,
529
- type?: 'terminate',
530
- prepend?: boolean,
531
- ): this
532
-
533
- /**
534
- * Register only the methods in the array.
535
- *
536
- * @param {string} names
537
- * @return {RouteResource}
538
- */
539
- only(names: string[]): this
540
- only(...names: string[]): this
541
-
542
- /**
543
- * Register all methods except the methods in the array.
544
- *
545
- * @param {string} names
546
- * @return {RouteResource}
547
- */
548
- except(names: string[]): this
549
- except(...names: string[]): this
550
-
551
- /**
552
- * Set up helmet options for route resource.
553
- *
554
- * @param {FastifyHelmetOptions} options
555
- * @return {RouteResource}
556
- */
557
- helmet(options: FastifyHelmetOptions): this
558
-
559
- /**
560
- * Set up helmet options for route resource.
561
- *
562
- * @param {string} action
563
- * @param {FastifyHelmetOptions} options
564
- * @return {RouteResource}
565
- */
566
- helmet(action: string, options: FastifyHelmetOptions): this
567
-
568
- /**
569
- * Set up swagger options for route resource method.
570
- *
571
- * @param {FastifySwaggerSchema} options
572
- * @return {RouteResource}
573
- */
574
- swagger(options: FastifySwaggerSchema): this
575
-
576
- /**
577
- * Set up swagger options for route resource method.
578
- *
579
- * @param {string} action
580
- * @param {FastifySwaggerSchema} options
581
- * @return {RouteResource}
582
- */
583
- swagger(action: string, options: FastifySwaggerSchema): this
584
-
585
- /**
586
- * Set up rate limit options for route resource method.
587
- *
588
- * @param {RateLimitOptions} options
589
- * @return {RouteResource}
590
- */
591
- rateLimit(options: RateLimitOptions): this
592
-
593
- /**
594
- * Set up rate limit options for route resource method.
595
- *
596
- * @param {string} action
597
- * @param {RateLimitOptions} options
598
- * @return {RouteResource}
599
- */
600
- rateLimit(action: string, options: RateLimitOptions): this
601
- }
602
-
603
- export class RouteGroup {
604
- routes: (Route | RouteResource | RouteGroup)[]
605
-
606
- constructor(routes: (Route | RouteResource | RouteGroup)[])
607
-
608
- prefix(prefix: string): this
609
-
610
- middleware(
611
- middleware: string,
612
- type?: 'handle' | 'intercept' | 'terminate',
613
- prepend?: boolean,
614
- ): this
615
-
616
- middleware(
617
- middleware: MiddlewareContract,
618
- type?: 'handle' | 'intercept' | 'terminate',
619
- prepend?: boolean,
620
- ): this
621
-
622
- middleware(
623
- middleware: HandleHandlerContract,
624
- type?: 'handle',
625
- prepend?: boolean,
626
- ): this
627
-
628
- middleware(
629
- middleware: InterceptHandlerContract,
630
- type?: 'intercept',
631
- prepend?: boolean,
632
- ): this
633
-
634
- middleware(
635
- middleware: TerminateHandlerContract,
636
- type?: 'terminate',
637
- prepend?: boolean,
638
- ): this
639
-
640
- /**
641
- * Set up helmet options for route group.
642
- *
643
- * @param {any} options
644
- * @return {RouteGroup}
645
- */
646
- helmet(options: FastifyHelmetOptions): this
647
-
648
- /**
649
- * Set up swagger options for route group.
650
- *
651
- * @param {any} options
652
- * @return {RouteGroup}
653
- */
654
- swagger(options: FastifySwaggerSchema): this
655
-
656
- /**
657
- * Set up rate limit options for route group.
658
- *
659
- * @param {any} options
660
- * @return {RouteGroup}
661
- */
662
- rateLimit(options: RateLimitOptions): this
663
- }
664
-
665
- export class Router {
666
- /**
667
- * List the routes registered.
668
- *
669
- * @return {any}
670
- */
671
- listRoutes(): any
672
-
673
- /**
674
- * Set the controller instance.
675
- *
676
- * @param {any} controller
677
- * @return {Router}
678
- */
679
- controller(controller: any): Router
680
-
681
- /**
682
- * Register a new route.
683
- *
684
- * @param {string} url
685
- * @param {string[]} methods
686
- * @param {string|any} handler
687
- * @return {Route}
688
- */
689
- route(
690
- url: string,
691
- methods: string[],
692
- handler: string | HandlerContract,
693
- ): Route
694
-
695
- /**
696
- * Register a new vanila route using fastify options
697
- * directly.
698
- *
699
- * @param {import('fastify').RouteOptions} options
700
- * @return {void}
701
- */
702
- vanilaRoute(options: RouteOptions): void
703
-
704
- /**
705
- * Creates a new route group.
706
- *
707
- * @param {() => void} callback
708
- * @return {RouteGroup}
709
- */
710
- group(callback: () => void): RouteGroup
711
-
712
- /**
713
- * Creates a new route resource.
714
- *
715
- * @param {string} resource
716
- * @param {any} controller
717
- * @return {RouteResource}
718
- */
719
- resource(resource: string, controller: any): RouteResource
720
-
721
- /**
722
- * Creates a new redirect route.
723
- *
724
- * @param {string} url
725
- * @param {string} redirectTo
726
- * @param {number} [status]
727
- * @return {Route}
728
- */
729
- redirect(url: string, redirectTo: string, status?: number): Route
730
-
731
- /**
732
- * Register a new get method route.
733
- *
734
- * @param {string} url
735
- * @param {string|any} handler
736
- * @return {Route}
737
- */
738
- get(url: string, handler: string | HandlerContract): Route
739
-
740
- /**
741
- * Register a new head method route.
742
- *
743
- * @param {string} url
744
- * @param {string|any} handler
745
- * @return {Route}
746
- */
747
- head(url: string, handler: string | HandlerContract): Route
748
-
749
- /**
750
- * Register a new post method route.
751
- *
752
- * @param {string} url
753
- * @param {string|any} handler
754
- * @return {Route}
755
- */
756
- post(url: string, handler: string | HandlerContract): Route
757
-
758
- /**
759
- * Register a new put method route.
760
- *
761
- * @param {string} url
762
- * @param {string|any} handler
763
- * @return {Route}
764
- */
765
- put(url: string, handler: string | HandlerContract): Route
766
-
767
- /**
768
- * Register a new patch method route.
769
- *
770
- * @param {string} url
771
- * @param {string|any} handler
772
- * @return {Route}
773
- */
774
- patch(url: string, handler: string | HandlerContract): Route
775
-
776
- /**
777
- * Register a new delete method route.
778
- *
779
- * @param {string} url
780
- * @param {string|any} handler
781
- * @return {Route}
782
- */
783
- delete(url: string, handler: string | HandlerContract): Route
784
-
785
- /**
786
- * Register a new options method route.
787
- *
788
- * @param {string} url
789
- * @param {string|any} handler
790
- * @return {Route}
791
- */
792
- options(url: string, handler: string | HandlerContract): Route
793
-
794
- /**
795
- * Register a new route with all methods.
796
- *
797
- * @param {string} url
798
- * @param {string|any} handler
799
- * @return {Route}
800
- */
801
- any(url: string, handler: string | HandlerContract): Route
802
-
803
- /**
804
- * Register all the routes inside the Server.
805
- *
806
- * @return {Route}
807
- */
808
- register(): Route
809
-
810
- /**
811
- * Transform the routes to JSON Object.
812
- *
813
- * @param {any[]} [routes]
814
- */
815
- toRoutesJSON(routes?: any[]): any
816
- }
817
- }
818
-
819
- export interface RequestContract {
820
- /**
821
- * Get the request ip.
822
- *
823
- * @return {string}
824
- */
825
- get ip(): string
826
- /**
827
- * Get the request method.
828
- *
829
- * @return {string}
830
- */
831
- get method(): string
832
-
833
- /**
834
- * Get the host url from request.
835
- *
836
- * @return {string}
837
- */
838
- get hostUrl(): string
839
-
840
- /**
841
- * Get the base request url.
842
- *
843
- * @return {string}
844
- */
845
- get baseUrl(): string
846
-
847
- /**
848
- * Get the original request url.
849
- *
850
- * @return {string}
851
- */
852
- get originalUrl(): string
853
-
854
- /**
855
- * Get all body from request.
856
- *
857
- * @return {any}
858
- */
859
- get body(): any
860
-
861
- /**
862
- * Get all params from request.
863
- *
864
- * @return {any}
865
- */
866
- get params(): any
867
-
868
- /**
869
- * Get all queries from request.
870
- *
871
- * @return {any}
872
- */
873
- get queries(): any
874
-
875
- /**
876
- * Get all headers from request.
877
- *
878
- * @return {any}
879
- */
880
- get headers(): any
881
-
882
- /**
883
- * Get a value from the request params or the default value.
884
- *
885
- * @param {string} param
886
- * @param {string} [defaultValue]
887
- * @return {any}
888
- */
889
- param(param, defaultValue): any
890
-
891
- /**
892
- * Get a value from the request query param or the default value.
893
- *
894
- * @param {string} query
895
- * @param {string} [defaultValue]
896
- * @return {any}
897
- */
898
- query(query, defaultValue): any
899
-
900
- /**
901
- * Get a value from the request header or the default value.
902
- *
903
- * @param {string} header
904
- * @param {string} [defaultValue]
905
- * @return {any}
906
- */
907
- header(header, defaultValue): any
908
-
909
- /**
910
- * Get only the selected values from the request body.
911
- *
912
- * @param {string} keys
913
- * @return {any}
914
- */
915
- only(...keys: string[]): any
916
- only(keys: string[]): any
917
-
918
- /**
919
- * Get all the values from the request body except the selected ones.
920
- *
921
- * @param {string[]} keys
922
- * @return {any}
923
- */
924
- except(...keys: string[]): any
925
- except(keys: string): any
926
-
927
- /**
928
- * Get a value from the request body or the default value.
929
- *
930
- * @param {string} key
931
- * @param {any} [defaultValue]
932
- * @return {any}
933
- */
934
- input(key: string, defaultValue?: any): any
935
-
936
- /**
937
- * Get a value from the request body or the default value.
938
- *
939
- * @param {string} key
940
- * @param {any} [defaultValue]
941
- * @return {any}
942
- */
943
- payload(key: string, defaultValue?: any): any
944
-
945
- /**
946
- * Get the default fastify request object.
947
- *
948
- * @return {import('fastify').FastifyRequest}
949
- */
950
- getFastifyRequest(): FastifyRequest
951
- }
952
-
953
- export interface ResponseContract {
954
- /**
955
- * Terminate the request sending the response body.
956
- *
957
- * @param {any} [data]
958
- * @return {void}
959
- */
960
- send(data?: any): Promise<void>
961
-
962
- /**
963
- * Terminate the request sending the response body.
964
- *
965
- * @param {any} [data]
966
- * @return {void}
967
- */
968
- json(data?: any): Promise<void>
969
-
970
- /**
971
- * Apply helmet in response.
972
- *
973
- * @param {import('@fastify/helmet').FastifyHelmetOptions} [options]
974
- * @return {void}
975
- */
976
- helmet(options?: FastifyHelmetOptions): Promise<void>
977
-
978
- /**
979
- * Set the response status code.
980
- *
981
- * @param {number} code
982
- * @return {Response}
983
- */
984
- status(code: number): this
985
-
986
- /**
987
- * Remove some header from the response.
988
- *
989
- * @param {string} header
990
- * @return {Response}
991
- */
992
- removeHeader(header: string): this
993
-
994
- /**
995
- * Add some header to the response.
996
- *
997
- * @param {string} header
998
- * @param {any} value
999
- * @return {Response}
1000
- */
1001
- header(header: string, value: any): this
1002
-
1003
- /**
1004
- * Only add some header to the response if it's not defined yet.
1005
- *
1006
- * @param {string} header
1007
- * @param {any} value
1008
- * @return {Response}
1009
- */
1010
- safeHeader(header: string, value: any): this
1011
-
1012
- /**
1013
- * Redirect the response to other url with different status code.
1014
- *
1015
- * @return {void}
1016
- */
1017
- redirectTo(url: string): Promise<void> | void
1018
- redirectTo(url: string, statusCode: number): Promise<void> | void
1019
-
1020
- /**
1021
- * Get the default fastify response object.
1022
- *
1023
- * @return {import('fastify').FastifyReply}
1024
- */
1025
- getFastifyResponse(): FastifyReply
1026
- }
1027
-
1028
- export class HttpLoader {
1029
- /**
1030
- * Return all commands from http package.
1031
- *
1032
- * @return {any[]}
1033
- */
1034
- static loadCommands(): any[]
1035
-
1036
- /**
1037
- * Return all custom templates from http package.
1038
- *
1039
- * @return {any[]}
1040
- */
1041
- static loadTemplates(): any[]
1042
- }
1043
-
1044
- export interface ContextContract {
1045
- request: RequestContract
1046
- response: ResponseContract
1047
- data: any
1048
- params: any
1049
- queries: any
1050
- }
1051
-
1052
- export interface ErrorContextContract {
1053
- request: RequestContract
1054
- response: ResponseContract
1055
- params: any
1056
- queries: any
1057
- data: any
1058
- error: any
1059
- }
1060
-
1061
- export interface HandleContextContract {
1062
- request: RequestContract
1063
- response: ResponseContract
1064
- data: any
1065
- params: any
1066
- queries: any
1067
- }
1068
-
1069
- export interface InterceptContextContract {
1070
- request: RequestContract
1071
- response: ResponseContract
1072
- params: any
1073
- queries: any
1074
- body: any
1075
- status: number
1076
- data: any
1077
- }
1078
-
1079
- export interface TerminateContextContract {
1080
- request: RequestContract
1081
- response: ResponseContract
1082
- data: any
1083
- params: any
1084
- queries: any
1085
- body: any
1086
- headers: any
1087
- status: number
1088
- responseTime: number
1089
- }
1090
-
1091
- export interface ErrorHandlerContract {
1092
- (ctx?: ErrorContextContract): Promise<any> | any
1093
- }
1094
-
1095
- export interface HandlerContract {
1096
- (ctx?: ContextContract): Promise<any> | any
1097
- }
1098
-
1099
- export interface HandleHandlerContract {
1100
- (ctx?: InterceptContextContract): Promise<any> | any
1101
- }
1102
-
1103
- export interface InterceptHandlerContract {
1104
- (ctx?: InterceptContextContract): Promise<any> | any
1105
- }
1106
-
1107
- export interface TerminateHandlerContract {
1108
- (ctx?: TerminateContextContract): Promise<any> | any
1109
- }
1110
-
1111
- export interface MiddlewareContract {
1112
- handle?: HandleHandlerContract
1113
- intercept?: InterceptHandlerContract
1114
- terminate?: TerminateHandlerContract
1115
- }
1116
-
1117
- export class HttpException extends Exception {
1118
- /**
1119
- * Creates a new instance of HttpException.
1120
- *
1121
- * @example
1122
- * throw new HttpException()
1123
- * This exception uses the 500 status code and the "E_HTTP_ERROR" code.
1124
- *
1125
- * @param {string} [content]
1126
- * @param {number} [status]
1127
- * @param {string} [code]
1128
- * @param {string|null} [help]
1129
- */
1130
- constructor(
1131
- content?: string,
1132
- status?: number,
1133
- code?: string,
1134
- help?: string | null,
1135
- )
1136
- }
1137
-
1138
- export class BadGatewayException extends Exception {
1139
- /**
1140
- * Creates a new instance of BadGatewayException.
1141
- *
1142
- * @example
1143
- * throw new BadGatewayException()
1144
- * This exception uses the 502 status code and the "E_BAD_GATEWAY_ERROR" code.
1145
- *
1146
- * @param {string} [content]
1147
- * @param {string} [code]
1148
- * @param {string|null} [help]
1149
- */
1150
- constructor(content?: string, code?: string, help?: string | null)
1151
- }
1152
-
1153
- export class BadRequestException extends Exception {
1154
- /**
1155
- * Creates a new instance of BadRequestException.
1156
- *
1157
- * @example
1158
- * throw new BadRequestException()
1159
- * This exception uses the 400 status code and the "E_BAD_REQUEST_ERROR" code.
1160
- *
1161
- * @param {string} [content]
1162
- * @param {string} [code]
1163
- * @param {string|null} [help]
1164
- */
1165
- constructor(content?: string, code?: string, help?: string | null)
1166
- }
1167
-
1168
- export class ForbiddenException extends Exception {
1169
- /**
1170
- * Creates a new instance of ForbiddenException.
1171
- *
1172
- * @example
1173
- * throw new ForbiddenException()
1174
- * This exception uses the 403 status code and the "E_FORBIDDEN_ERROR" code.
1175
- *
1176
- * @param {string} [content]
1177
- * @param {string} [code]
1178
- * @param {string|null} [help]
1179
- */
1180
- constructor(content?: string, code?: string, help?: string | null)
1181
- }
1182
-
1183
- export class InternalServerException extends Exception {
1184
- /**
1185
- * Creates a new instance of InternalServerException.
1186
- *
1187
- * @example
1188
- * throw new InternalServerException()
1189
- * This exception uses the 500 status code and the "E_INTERNAL_ERROR" code.
1190
- *
1191
- * @param {string} [content]
1192
- * @param {string} [code]
1193
- * @param {string|null} [help]
1194
- */
1195
- constructor(content?: string, code?: string, help?: string | null)
1196
- }
1197
-
1198
- export class MethodNotAllowedException extends Exception {
1199
- /**
1200
- * Creates a new instance of MethodNotAllowedException.
1201
- *
1202
- * @example
1203
- * throw new MethodNotAllowedException()
1204
- * This exception uses the 405 status code and the "E_METHOD_NOT_ALLOWED_ERROR" code.
1205
- *
1206
- * @param {string} [content]
1207
- * @param {string} [code]
1208
- * @param {string|null} [help]
1209
- */
1210
- constructor(content?: string, code?: string, help?: string | null)
1211
- }
1212
-
1213
- export class NotAcceptableException extends Exception {
1214
- /**
1215
- * Creates a new instance of NotAcceptableException.
1216
- *
1217
- * @example
1218
- * throw new NotAcceptableException()
1219
- * This exception uses the 406 status code and the "E_NOT_ACCEPTABLE_ERROR" code.
1220
- *
1221
- * @param {string} [content]
1222
- * @param {string} [code]
1223
- * @param {string|null} [help]
1224
- */
1225
- constructor(content?: string, code?: string, help?: string | null)
1226
- }
1227
-
1228
- export class NotFoundException extends Exception {
1229
- /**
1230
- * Creates a new instance of NotFoundException.
1231
- *
1232
- * @example
1233
- * throw new NotFoundException()
1234
- * This exception uses the 404 status code and the "E_NOT_FOUND_ERROR" code.
1235
- *
1236
- * @param {string} [content]
1237
- * @param {string} [code]
1238
- * @param {string|null} [help]
1239
- */
1240
- constructor(content?: string, code?: string, help?: string | null)
1241
- }
1242
-
1243
- export class NotImplementedException extends Exception {
1244
- /**
1245
- * Creates a new instance of NotImplementedException.
1246
- *
1247
- * @example
1248
- * throw new NotImplementedException()
1249
- * This exception uses the 501 status code and the "E_NOT_IMPLEMENTED_ERROR" code.
1250
- *
1251
- * @param {string} [content]
1252
- * @param {string} [code]
1253
- * @param {string|null} [help]
1254
- */
1255
- constructor(content?: string, code?: string, help?: string | null)
1256
- }
1257
-
1258
- export class PayloadTooLargeException extends Exception {
1259
- /**
1260
- * Creates a new instance of PayloadTooLargeException.
1261
- *
1262
- * @example
1263
- * throw new PayloadTooLargeException()
1264
- * This exception uses the 413 status code and the "E_PAYLOAD_TOO_LARGE_ERROR" code.
1265
- *
1266
- * @param {string} [content]
1267
- * @param {string} [code]
1268
- * @param {string|null} [help]
1269
- */
1270
- constructor(content?: string, code?: string, help?: string | null)
1271
- }
1272
-
1273
- export class RequestTimeoutException extends Exception {
1274
- /**
1275
- * Creates a new instance of RequestTimeoutException.
1276
- *
1277
- * @example
1278
- * throw new RequestTimeoutException()
1279
- * This exception uses the 408 status code and the "E_REQUEST_TIMEOUT_ERROR" code.
1280
- *
1281
- * @param {string} [content]
1282
- * @param {string} [code]
1283
- * @param {string|null} [help]
1284
- */
1285
- constructor(content?: string, code?: string, help?: string | null)
1286
- }
1287
-
1288
- export class ServiceUnavailableException extends Exception {
1289
- /**
1290
- * Creates a new instance of ServiceUnavailableException.
1291
- *
1292
- * @example
1293
- * throw new ServiceUnavailableException()
1294
- * This exception uses the 503 status code and the "E_SERVICE_UNAVAILABLE_ERROR" code.
1295
- *
1296
- * @param {string} [content]
1297
- * @param {string} [code]
1298
- * @param {string|null} [help]
1299
- */
1300
- constructor(content?: string, code?: string, help?: string | null)
1301
- }
1302
-
1303
- export class UnauthorizedException extends Exception {
1304
- /**
1305
- * Creates a new instance of UnauthorizedException.
1306
- *
1307
- * @example
1308
- * throw new UnauthorizedException()
1309
- * This exception uses the 401 status code and the "E_UNAUTHORIZED_ERROR" code.
1310
- *
1311
- * @param {string} [content]
1312
- * @param {string} [code]
1313
- * @param {string|null} [help]
1314
- */
1315
- constructor(content?: string, code?: string, help?: string | null)
1316
- }
1317
-
1318
- export class UnprocessableEntityException extends Exception {
1319
- /**
1320
- * Creates a new instance of UnprocessableEntityException.
1321
- *
1322
- * @example
1323
- * throw new UnprocessableEntityException()
1324
- * This exception uses the 422 status code and the "E_UNPROCESSABLE_ENTITY_ERROR" code.
1325
- *
1326
- * @param {string} [content]
1327
- * @param {string} [code]
1328
- * @param {string|null} [help]
1329
- */
1330
- constructor(content?: string, code?: string, help?: string | null)
1331
- }