@athenna/http 3.0.11 → 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 -77
  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 -268
  120. package/src/Context/Response.js +0 -173
  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 -411
  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 -1395
  151. package/src/index.js +0 -377
package/src/index.d.ts DELETED
@@ -1,1395 +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 } 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 id.
822
- *
823
- * @return {string}
824
- */
825
- get id(): string
826
-
827
- /**
828
- * Get the request ip.
829
- *
830
- * @return {string}
831
- */
832
- get ip(): string
833
-
834
- /**
835
- * Get the request hostname.
836
- *
837
- * @return {string}
838
- */
839
- get hostname(): string
840
-
841
- /**
842
- * Get the request protocol.
843
- *
844
- * @return {"http"|"https"}
845
- */
846
- get protocol(): 'http' | 'https'
847
-
848
- /**
849
- * Get the request method.
850
- *
851
- * @return {string}
852
- */
853
- get method(): string
854
-
855
- /**
856
- * Get the route url from request.
857
- *
858
- * @return {string}
859
- */
860
- get routeUrl(): string
861
-
862
- /**
863
- * Get the host url from request.
864
- *
865
- * @return {string}
866
- */
867
- get hostUrl(): string
868
-
869
- /**
870
- * Get the base request url.
871
- *
872
- * @return {string}
873
- */
874
- get baseUrl(): string
875
-
876
- /**
877
- * Get the original request url.
878
- *
879
- * @return {string}
880
- */
881
- get originalUrl(): string
882
-
883
- /**
884
- * Get all body from request.
885
- *
886
- * @return {any}
887
- */
888
- get body(): any
889
-
890
- /**
891
- * Get all params from request.
892
- *
893
- * @return {any}
894
- */
895
- get params(): any
896
-
897
- /**
898
- * Get all queries from request.
899
- *
900
- * @return {any}
901
- */
902
- get queries(): any
903
-
904
- /**
905
- * Get all headers from request.
906
- *
907
- * @return {any}
908
- */
909
- get headers(): any
910
-
911
- /**
912
- * Get the server version.
913
- *
914
- * @return {string}
915
- */
916
- get version(): string
917
-
918
- /**
919
- * Get a value from the request params or the default value.
920
- *
921
- * @param {string} param
922
- * @param {string} [defaultValue]
923
- * @return {any}
924
- */
925
- param(param, defaultValue): any
926
-
927
- /**
928
- * Get a value from the request query param or the default value.
929
- *
930
- * @param {string} query
931
- * @param {string} [defaultValue]
932
- * @return {any}
933
- */
934
- query(query, defaultValue): any
935
-
936
- /**
937
- * Get a value from the request header or the default value.
938
- *
939
- * @param {string} header
940
- * @param {string} [defaultValue]
941
- * @return {any}
942
- */
943
- header(header, defaultValue): any
944
-
945
- /**
946
- * Get only the selected values from the request body.
947
- *
948
- * @param {string} keys
949
- * @return {any}
950
- */
951
- only(...keys: string[]): any
952
- only(keys: string[]): any
953
-
954
- /**
955
- * Get all the values from the request body except the selected ones.
956
- *
957
- * @param {string[]} keys
958
- * @return {any}
959
- */
960
- except(...keys: string[]): any
961
- except(keys: string): any
962
-
963
- /**
964
- * Get a value from the request body or the default value.
965
- *
966
- * @param {string} key
967
- * @param {any} [defaultValue]
968
- * @return {any}
969
- */
970
- input(key: string, defaultValue?: any): any
971
-
972
- /**
973
- * Get a value from the request body or the default value.
974
- *
975
- * @param {string} key
976
- * @param {any} [defaultValue]
977
- * @return {any}
978
- */
979
- payload(key: string, defaultValue?: any): any
980
-
981
- /**
982
- * Get the default fastify request object.
983
- *
984
- * @return {import('fastify').FastifyRequest}
985
- */
986
- getFastifyRequest(): FastifyRequest
987
- }
988
-
989
- export interface ResponseContract {
990
- /**
991
- * Verify if response has been already sent.
992
- *
993
- * @return {boolean}
994
- */
995
- get sent(): boolean
996
-
997
- /**
998
- * Get the status code sent in response.
999
- *
1000
- * @return {number}
1001
- */
1002
- get statusCode(): number
1003
-
1004
- /**
1005
- * Get the headers sent in response.
1006
- *
1007
- * @return {any}
1008
- */
1009
- get headers(): any
1010
-
1011
- /**
1012
- * Get the response time.
1013
- *
1014
- * @return {number}
1015
- */
1016
- get responseTime(): number
1017
-
1018
- /**
1019
- * Terminate the request sending the response body.
1020
- *
1021
- * @param {any} [data]
1022
- * @return {void}
1023
- */
1024
- send(data?: any): Promise<void>
1025
-
1026
- /**
1027
- * Terminate the request sending the response body.
1028
- *
1029
- * @param {any} [data]
1030
- * @return {void}
1031
- */
1032
- json(data?: any): Promise<void>
1033
-
1034
- /**
1035
- * Apply helmet in response.
1036
- *
1037
- * @param {import('@fastify/helmet').FastifyHelmetOptions} [options]
1038
- * @return {void}
1039
- */
1040
- helmet(options?: FastifyHelmetOptions): Promise<void>
1041
-
1042
- /**
1043
- * Set the response status code.
1044
- *
1045
- * @param {number} code
1046
- * @return {Response}
1047
- */
1048
- status(code: number): this
1049
-
1050
- /**
1051
- * Remove some header from the response.
1052
- *
1053
- * @param {string} header
1054
- * @return {Response}
1055
- */
1056
- removeHeader(header: string): this
1057
-
1058
- /**
1059
- * Add some header to the response.
1060
- *
1061
- * @param {string} header
1062
- * @param {any} value
1063
- * @return {Response}
1064
- */
1065
- header(header: string, value: any): this
1066
-
1067
- /**
1068
- * Only add some header to the response if it's not defined yet.
1069
- *
1070
- * @param {string} header
1071
- * @param {any} value
1072
- * @return {Response}
1073
- */
1074
- safeHeader(header: string, value: any): this
1075
-
1076
- /**
1077
- * Redirect the response to other url with different status code.
1078
- *
1079
- * @return {void}
1080
- */
1081
- redirectTo(url: string): Promise<void> | void
1082
- redirectTo(url: string, statusCode: number): Promise<void> | void
1083
-
1084
- /**
1085
- * Get the default fastify response object.
1086
- *
1087
- * @return {import('fastify').FastifyReply}
1088
- */
1089
- getFastifyResponse(): FastifyReply
1090
- }
1091
-
1092
- export class HttpLoader {
1093
- /**
1094
- * Return all commands from http package.
1095
- *
1096
- * @return {any[]}
1097
- */
1098
- static loadCommands(): any[]
1099
-
1100
- /**
1101
- * Return all custom templates from http package.
1102
- *
1103
- * @return {any[]}
1104
- */
1105
- static loadTemplates(): any[]
1106
- }
1107
-
1108
- export interface ContextContract {
1109
- request: RequestContract
1110
- response: ResponseContract
1111
- data: any
1112
- params: any
1113
- queries: any
1114
- }
1115
-
1116
- export interface ErrorContextContract {
1117
- request: RequestContract
1118
- response: ResponseContract
1119
- params: any
1120
- queries: any
1121
- data: any
1122
- error: any
1123
- }
1124
-
1125
- export interface HandleContextContract {
1126
- request: RequestContract
1127
- response: ResponseContract
1128
- data: any
1129
- params: any
1130
- queries: any
1131
- }
1132
-
1133
- export interface InterceptContextContract {
1134
- request: RequestContract
1135
- response: ResponseContract
1136
- params: any
1137
- queries: any
1138
- body: any
1139
- status: number
1140
- data: any
1141
- }
1142
-
1143
- export interface TerminateContextContract {
1144
- request: RequestContract
1145
- response: ResponseContract
1146
- data: any
1147
- params: any
1148
- queries: any
1149
- body: any
1150
- headers: any
1151
- status: number
1152
- responseTime: number
1153
- }
1154
-
1155
- export interface ErrorHandlerContract {
1156
- (ctx?: ErrorContextContract): Promise<any> | any
1157
- }
1158
-
1159
- export interface HandlerContract {
1160
- (ctx?: ContextContract): Promise<any> | any
1161
- }
1162
-
1163
- export interface HandleHandlerContract {
1164
- (ctx?: InterceptContextContract): Promise<any> | any
1165
- }
1166
-
1167
- export interface InterceptHandlerContract {
1168
- (ctx?: InterceptContextContract): Promise<any> | any
1169
- }
1170
-
1171
- export interface TerminateHandlerContract {
1172
- (ctx?: TerminateContextContract): Promise<any> | any
1173
- }
1174
-
1175
- export interface MiddlewareContract {
1176
- handle?: HandleHandlerContract
1177
- intercept?: InterceptHandlerContract
1178
- terminate?: TerminateHandlerContract
1179
- }
1180
-
1181
- export class HttpException extends Exception {
1182
- /**
1183
- * Creates a new instance of HttpException.
1184
- *
1185
- * @example
1186
- * throw new HttpException()
1187
- * This exception uses the 500 status code and the "E_HTTP_ERROR" code.
1188
- *
1189
- * @param {string} [content]
1190
- * @param {number} [status]
1191
- * @param {string} [code]
1192
- * @param {string|null} [help]
1193
- */
1194
- constructor(
1195
- content?: string,
1196
- status?: number,
1197
- code?: string,
1198
- help?: string | null,
1199
- )
1200
- }
1201
-
1202
- export class BadGatewayException extends Exception {
1203
- /**
1204
- * Creates a new instance of BadGatewayException.
1205
- *
1206
- * @example
1207
- * throw new BadGatewayException()
1208
- * This exception uses the 502 status code and the "E_BAD_GATEWAY_ERROR" code.
1209
- *
1210
- * @param {string} [content]
1211
- * @param {string} [code]
1212
- * @param {string|null} [help]
1213
- */
1214
- constructor(content?: string, code?: string, help?: string | null)
1215
- }
1216
-
1217
- export class BadRequestException extends Exception {
1218
- /**
1219
- * Creates a new instance of BadRequestException.
1220
- *
1221
- * @example
1222
- * throw new BadRequestException()
1223
- * This exception uses the 400 status code and the "E_BAD_REQUEST_ERROR" code.
1224
- *
1225
- * @param {string} [content]
1226
- * @param {string} [code]
1227
- * @param {string|null} [help]
1228
- */
1229
- constructor(content?: string, code?: string, help?: string | null)
1230
- }
1231
-
1232
- export class ForbiddenException extends Exception {
1233
- /**
1234
- * Creates a new instance of ForbiddenException.
1235
- *
1236
- * @example
1237
- * throw new ForbiddenException()
1238
- * This exception uses the 403 status code and the "E_FORBIDDEN_ERROR" code.
1239
- *
1240
- * @param {string} [content]
1241
- * @param {string} [code]
1242
- * @param {string|null} [help]
1243
- */
1244
- constructor(content?: string, code?: string, help?: string | null)
1245
- }
1246
-
1247
- export class InternalServerException extends Exception {
1248
- /**
1249
- * Creates a new instance of InternalServerException.
1250
- *
1251
- * @example
1252
- * throw new InternalServerException()
1253
- * This exception uses the 500 status code and the "E_INTERNAL_ERROR" code.
1254
- *
1255
- * @param {string} [content]
1256
- * @param {string} [code]
1257
- * @param {string|null} [help]
1258
- */
1259
- constructor(content?: string, code?: string, help?: string | null)
1260
- }
1261
-
1262
- export class MethodNotAllowedException extends Exception {
1263
- /**
1264
- * Creates a new instance of MethodNotAllowedException.
1265
- *
1266
- * @example
1267
- * throw new MethodNotAllowedException()
1268
- * This exception uses the 405 status code and the "E_METHOD_NOT_ALLOWED_ERROR" code.
1269
- *
1270
- * @param {string} [content]
1271
- * @param {string} [code]
1272
- * @param {string|null} [help]
1273
- */
1274
- constructor(content?: string, code?: string, help?: string | null)
1275
- }
1276
-
1277
- export class NotAcceptableException extends Exception {
1278
- /**
1279
- * Creates a new instance of NotAcceptableException.
1280
- *
1281
- * @example
1282
- * throw new NotAcceptableException()
1283
- * This exception uses the 406 status code and the "E_NOT_ACCEPTABLE_ERROR" code.
1284
- *
1285
- * @param {string} [content]
1286
- * @param {string} [code]
1287
- * @param {string|null} [help]
1288
- */
1289
- constructor(content?: string, code?: string, help?: string | null)
1290
- }
1291
-
1292
- export class NotFoundException extends Exception {
1293
- /**
1294
- * Creates a new instance of NotFoundException.
1295
- *
1296
- * @example
1297
- * throw new NotFoundException()
1298
- * This exception uses the 404 status code and the "E_NOT_FOUND_ERROR" code.
1299
- *
1300
- * @param {string} [content]
1301
- * @param {string} [code]
1302
- * @param {string|null} [help]
1303
- */
1304
- constructor(content?: string, code?: string, help?: string | null)
1305
- }
1306
-
1307
- export class NotImplementedException extends Exception {
1308
- /**
1309
- * Creates a new instance of NotImplementedException.
1310
- *
1311
- * @example
1312
- * throw new NotImplementedException()
1313
- * This exception uses the 501 status code and the "E_NOT_IMPLEMENTED_ERROR" code.
1314
- *
1315
- * @param {string} [content]
1316
- * @param {string} [code]
1317
- * @param {string|null} [help]
1318
- */
1319
- constructor(content?: string, code?: string, help?: string | null)
1320
- }
1321
-
1322
- export class PayloadTooLargeException extends Exception {
1323
- /**
1324
- * Creates a new instance of PayloadTooLargeException.
1325
- *
1326
- * @example
1327
- * throw new PayloadTooLargeException()
1328
- * This exception uses the 413 status code and the "E_PAYLOAD_TOO_LARGE_ERROR" code.
1329
- *
1330
- * @param {string} [content]
1331
- * @param {string} [code]
1332
- * @param {string|null} [help]
1333
- */
1334
- constructor(content?: string, code?: string, help?: string | null)
1335
- }
1336
-
1337
- export class RequestTimeoutException extends Exception {
1338
- /**
1339
- * Creates a new instance of RequestTimeoutException.
1340
- *
1341
- * @example
1342
- * throw new RequestTimeoutException()
1343
- * This exception uses the 408 status code and the "E_REQUEST_TIMEOUT_ERROR" code.
1344
- *
1345
- * @param {string} [content]
1346
- * @param {string} [code]
1347
- * @param {string|null} [help]
1348
- */
1349
- constructor(content?: string, code?: string, help?: string | null)
1350
- }
1351
-
1352
- export class ServiceUnavailableException extends Exception {
1353
- /**
1354
- * Creates a new instance of ServiceUnavailableException.
1355
- *
1356
- * @example
1357
- * throw new ServiceUnavailableException()
1358
- * This exception uses the 503 status code and the "E_SERVICE_UNAVAILABLE_ERROR" code.
1359
- *
1360
- * @param {string} [content]
1361
- * @param {string} [code]
1362
- * @param {string|null} [help]
1363
- */
1364
- constructor(content?: string, code?: string, help?: string | null)
1365
- }
1366
-
1367
- export class UnauthorizedException extends Exception {
1368
- /**
1369
- * Creates a new instance of UnauthorizedException.
1370
- *
1371
- * @example
1372
- * throw new UnauthorizedException()
1373
- * This exception uses the 401 status code and the "E_UNAUTHORIZED_ERROR" code.
1374
- *
1375
- * @param {string} [content]
1376
- * @param {string} [code]
1377
- * @param {string|null} [help]
1378
- */
1379
- constructor(content?: string, code?: string, help?: string | null)
1380
- }
1381
-
1382
- export class UnprocessableEntityException extends Exception {
1383
- /**
1384
- * Creates a new instance of UnprocessableEntityException.
1385
- *
1386
- * @example
1387
- * throw new UnprocessableEntityException()
1388
- * This exception uses the 422 status code and the "E_UNPROCESSABLE_ENTITY_ERROR" code.
1389
- *
1390
- * @param {string} [content]
1391
- * @param {string} [code]
1392
- * @param {string|null} [help]
1393
- */
1394
- constructor(content?: string, code?: string, help?: string | null)
1395
- }