@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
@@ -0,0 +1,22 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export class InternalServerException extends HttpException {
11
+ /**
12
+ * This exception uses the 500 status code and the "E_INTERNAL_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new InternalServerException()
17
+ * ```
18
+ */
19
+ constructor(message = 'Internal server error happened.', help = null) {
20
+ super({ help, message, status: 500, code: 'E_INTERNAL_ERROR' });
21
+ }
22
+ }
@@ -0,0 +1,20 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export declare class MethodNotAllowedException extends HttpException {
11
+ /**
12
+ * This exception uses the 405 status code and the "E_METHOD_NOT_ALLOWED_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new MethodNotAllowedException()
17
+ * ```
18
+ */
19
+ constructor(message?: string, help?: any);
20
+ }
@@ -0,0 +1,22 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export class MethodNotAllowedException extends HttpException {
11
+ /**
12
+ * This exception uses the 405 status code and the "E_METHOD_NOT_ALLOWED_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new MethodNotAllowedException()
17
+ * ```
18
+ */
19
+ constructor(message = 'Method not allowed error happened.', help = null) {
20
+ super({ help, message, status: 405, code: 'E_METHOD_NOT_ALLOWED_ERROR' });
21
+ }
22
+ }
@@ -0,0 +1,20 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export declare class NotAcceptableException extends HttpException {
11
+ /**
12
+ * This exception uses the 406 status code and the "E_NOT_ACCEPTABLE_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new NotAcceptableException()
17
+ * ```
18
+ */
19
+ constructor(message?: string, help?: any);
20
+ }
@@ -0,0 +1,22 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export class NotAcceptableException extends HttpException {
11
+ /**
12
+ * This exception uses the 406 status code and the "E_NOT_ACCEPTABLE_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new NotAcceptableException()
17
+ * ```
18
+ */
19
+ constructor(message = 'Not acceptable error happened.', help = null) {
20
+ super({ help, message, status: 406, code: 'E_NOT_ACCEPTABLE_ERROR' });
21
+ }
22
+ }
@@ -0,0 +1,20 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export declare class NotFoundException extends HttpException {
11
+ /**
12
+ * This exception uses the 404 status code and the "E_NOT_FOUND_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new NotFoundException()
17
+ * ```
18
+ */
19
+ constructor(message?: string, help?: any);
20
+ }
@@ -0,0 +1,22 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export class NotFoundException extends HttpException {
11
+ /**
12
+ * This exception uses the 404 status code and the "E_NOT_FOUND_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new NotFoundException()
17
+ * ```
18
+ */
19
+ constructor(message = 'Not found error happened.', help = null) {
20
+ super({ help, message, status: 404, code: 'E_NOT_FOUND_ERROR' });
21
+ }
22
+ }
@@ -0,0 +1,20 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export declare class NotImplementedException extends HttpException {
11
+ /**
12
+ * This exception uses the 501 status code and the "E_NOT_IMPLEMENTED_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new NotImplementedException()
17
+ * ```
18
+ */
19
+ constructor(message?: string, help?: any);
20
+ }
@@ -0,0 +1,22 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export class NotImplementedException extends HttpException {
11
+ /**
12
+ * This exception uses the 501 status code and the "E_NOT_IMPLEMENTED_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new NotImplementedException()
17
+ * ```
18
+ */
19
+ constructor(message = 'Not implemented error happened.', help = null) {
20
+ super({ help, message, status: 501, code: 'E_NOT_IMPLEMENTED_ERROR' });
21
+ }
22
+ }
@@ -0,0 +1,20 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export declare class PayloadTooLargeException extends HttpException {
11
+ /**
12
+ * This exception uses the 413 status code and the "E_PAYLOAD_TOO_LARGE_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new PayloadTooLargeException()
17
+ * ```
18
+ */
19
+ constructor(message?: string, help?: any);
20
+ }
@@ -0,0 +1,22 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export class PayloadTooLargeException extends HttpException {
11
+ /**
12
+ * This exception uses the 413 status code and the "E_PAYLOAD_TOO_LARGE_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new PayloadTooLargeException()
17
+ * ```
18
+ */
19
+ constructor(message = 'Payload to large error happened.', help = null) {
20
+ super({ help, message, status: 413, code: 'E_PAYLOAD_TOO_LARGE_ERROR' });
21
+ }
22
+ }
@@ -0,0 +1,20 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export declare class RequestTimeoutException extends HttpException {
11
+ /**
12
+ * This exception uses the 408 status code and the "E_REQUEST_TIMEOUT_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new RequestTimeoutException()
17
+ * ```
18
+ */
19
+ constructor(message?: string, help?: any);
20
+ }
@@ -0,0 +1,22 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export class RequestTimeoutException extends HttpException {
11
+ /**
12
+ * This exception uses the 408 status code and the "E_REQUEST_TIMEOUT_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new RequestTimeoutException()
17
+ * ```
18
+ */
19
+ constructor(message = 'Request timeout error happened.', help = null) {
20
+ super({ help, message, status: 408, code: 'E_REQUEST_TIMEOUT_ERROR' });
21
+ }
22
+ }
@@ -0,0 +1,20 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export declare class ServiceUnavailableException extends HttpException {
11
+ /**
12
+ * This exception uses the 503 status code and the "E_SERVICE_UNAVAILABLE_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new ServiceUnavailableException()
17
+ * ```
18
+ */
19
+ constructor(message?: string, help?: any);
20
+ }
@@ -0,0 +1,22 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export class ServiceUnavailableException extends HttpException {
11
+ /**
12
+ * This exception uses the 503 status code and the "E_SERVICE_UNAVAILABLE_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new ServiceUnavailableException()
17
+ * ```
18
+ */
19
+ constructor(message = 'Service unavailable error happened.', help = null) {
20
+ super({ help, message, status: 503, code: 'E_SERVICE_UNAVAILABLE_ERROR' });
21
+ }
22
+ }
@@ -0,0 +1,20 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export declare class UnauthorizedException extends HttpException {
11
+ /**
12
+ * This exception uses the 401 status code and the "E_UNAUTHORIZED_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new UnauthorizedException()
17
+ * ```
18
+ */
19
+ constructor(message?: string, help?: any);
20
+ }
@@ -0,0 +1,22 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export class UnauthorizedException extends HttpException {
11
+ /**
12
+ * This exception uses the 401 status code and the "E_UNAUTHORIZED_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new UnauthorizedException()
17
+ * ```
18
+ */
19
+ constructor(message = 'Unauthorized error happened.', help = null) {
20
+ super({ help, message, status: 401, code: 'E_UNAUTHORIZED_ERROR' });
21
+ }
22
+ }
@@ -0,0 +1,12 @@
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
+ import { Exception } from '@athenna/common';
10
+ export declare class UndefinedMethodException extends Exception {
11
+ constructor(method: string, className: string);
12
+ }
@@ -0,0 +1,19 @@
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
+ import { Exception } from '@athenna/common';
10
+ export class UndefinedMethodException extends Exception {
11
+ constructor(method, className) {
12
+ super({
13
+ status: 500,
14
+ code: 'E_UNDEFINED_METHOD',
15
+ message: `Cannot register the ${method} method in your Route because it's not defined inside your ${className} class.`,
16
+ help: `Remember defining the method ${method} inside your ${className} class.`,
17
+ });
18
+ }
19
+ }
@@ -0,0 +1,20 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export declare class UnprocessableEntityException extends HttpException {
11
+ /**
12
+ * This exception uses the 422 status code and the "E_UNPROCESSABLE_ENTITY_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new UnprocessableEntityException()
17
+ * ```
18
+ */
19
+ constructor(message?: string, help?: any);
20
+ }
@@ -0,0 +1,22 @@
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
+ import { HttpException } from '#src/Exceptions/HttpException';
10
+ export class UnprocessableEntityException extends HttpException {
11
+ /**
12
+ * This exception uses the 422 status code and the "E_UNPROCESSABLE_ENTITY_ERROR" code.
13
+ *
14
+ * @example
15
+ * ```js
16
+ * throw new UnprocessableEntityException()
17
+ * ```
18
+ */
19
+ constructor(message = 'Unprocessable entity error happened.', help = null) {
20
+ super({ help, message, status: 422, code: 'E_UNPROCESSABLE_ENTITY_ERROR' });
21
+ }
22
+ }
@@ -0,0 +1,10 @@
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
+ import { Router } from '#src/Router/Router';
10
+ export declare const Route: import("@athenna/ioc").FacadeType<Router>;
@@ -6,10 +6,5 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
-
10
- import { Facade } from '@athenna/ioc'
11
-
12
- /**
13
- * @type {typeof Facade & import('../Router/Router.js').Router}
14
- */
15
- export const Route = Facade.createFor('Athenna/Core/HttpRoute')
9
+ import { Facade } from '@athenna/ioc';
10
+ export const Route = Facade.createFor('Athenna/Core/HttpRoute');
@@ -0,0 +1,10 @@
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
+ import { ServerImpl } from '#src/Server/ServerImpl';
10
+ export declare const Server: import("@athenna/ioc").FacadeType<ServerImpl>;
@@ -6,10 +6,5 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
-
10
- import { Facade } from '@athenna/ioc'
11
-
12
- /**
13
- * @type {typeof Facade & import('../index.js').Http}
14
- */
15
- export const Server = Facade.createFor('Athenna/Core/HttpServer')
9
+ import { Facade } from '@athenna/ioc';
10
+ export const Server = Facade.createFor('Athenna/Core/HttpServer');
@@ -0,0 +1,41 @@
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
+ /// <reference types="node" resolution-mode="require"/>
10
+ /// <reference types="node/http.js" />
11
+ import { InterceptHandler, TerminateHandler } from '#src/Types/Middlewares/MiddlewareHandler';
12
+ import { RequestHandler } from '#src/Types/Contexts/Context';
13
+ import { ErrorHandler } from '#src/Types/Contexts/ErrorContext';
14
+ import { FastifyReply, FastifyRequest, RouteHandlerMethod } from 'fastify';
15
+ export declare class FastifyHandler {
16
+ /**
17
+ * Parse the fastify request handler and the preHandler hook to an Athenna
18
+ * request handler.
19
+ */
20
+ static request(handler: RequestHandler): RouteHandlerMethod;
21
+ /**
22
+ * Just and alises for the request handler.
23
+ */
24
+ static handle(handler: RequestHandler): RouteHandlerMethod<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, import("fastify").RouteGenericInterface, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, import("fastify").FastifyBaseLogger>;
25
+ /**
26
+ * Parse the fastify onSend hook to an Athenna intercept handler.
27
+ */
28
+ static intercept(handler: InterceptHandler): (req: FastifyRequest, res: FastifyReply, payload: any) => Promise<any>;
29
+ /**
30
+ * Parse the fastify onResponse hook to an Athenna terminate handler.
31
+ */
32
+ static terminate(handler: TerminateHandler): (req: FastifyRequest, res: FastifyReply) => Promise<void>;
33
+ /**
34
+ * Parse the fastify onError hook to an Athenna error handler.
35
+ */
36
+ static error(handler: ErrorHandler): (error: any, req: FastifyRequest, res: FastifyReply) => Promise<void>;
37
+ /**
38
+ * Set the data object in th
39
+ */
40
+ private static setData;
41
+ }
@@ -0,0 +1,116 @@
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
+ import { Is } from '@athenna/common';
10
+ import { Request } from '#src/Context/Request';
11
+ import { Response } from '#src/Context/Response';
12
+ export class FastifyHandler {
13
+ /**
14
+ * Parse the fastify request handler and the preHandler hook to an Athenna
15
+ * request handler.
16
+ */
17
+ static request(handler) {
18
+ return async (req, res) => {
19
+ const request = new Request(req);
20
+ const response = new Response(res);
21
+ this.setData(req);
22
+ await handler({
23
+ request,
24
+ response,
25
+ data: req.data,
26
+ body: req.body,
27
+ params: req.params,
28
+ queries: req.query,
29
+ headers: req.headers,
30
+ });
31
+ };
32
+ }
33
+ /**
34
+ * Just and alises for the request handler.
35
+ */
36
+ static handle(handler) {
37
+ return this.request(handler);
38
+ }
39
+ /**
40
+ * Parse the fastify onSend hook to an Athenna intercept handler.
41
+ */
42
+ static intercept(handler) {
43
+ return async (req, res, payload) => {
44
+ const request = new Request(req);
45
+ const response = new Response(res);
46
+ this.setData(req);
47
+ if (Is.Json(payload)) {
48
+ payload = JSON.parse(payload);
49
+ }
50
+ payload = await handler({
51
+ request,
52
+ response,
53
+ status: response.statusCode,
54
+ data: req.data,
55
+ body: payload,
56
+ params: req.params,
57
+ queries: req.query,
58
+ headers: req.headers,
59
+ });
60
+ if (Is.Object(payload)) {
61
+ payload = JSON.stringify(payload);
62
+ }
63
+ return payload;
64
+ };
65
+ }
66
+ /**
67
+ * Parse the fastify onResponse hook to an Athenna terminate handler.
68
+ */
69
+ static terminate(handler) {
70
+ return async (req, res) => {
71
+ const request = new Request(req);
72
+ const response = new Response(res);
73
+ this.setData(req);
74
+ await handler({
75
+ request,
76
+ response,
77
+ params: req.params,
78
+ queries: req.query,
79
+ data: req.data,
80
+ body: req.body,
81
+ headers: res.getHeaders(),
82
+ status: res.statusCode,
83
+ responseTime: res.getResponseTime(),
84
+ });
85
+ };
86
+ }
87
+ /**
88
+ * Parse the fastify onError hook to an Athenna error handler.
89
+ */
90
+ static error(handler) {
91
+ return async (error, req, res) => {
92
+ const request = new Request(req);
93
+ const response = new Response(res);
94
+ this.setData(req);
95
+ await handler({
96
+ request,
97
+ response,
98
+ data: req.data,
99
+ body: req.body,
100
+ params: req.params,
101
+ queries: req.query,
102
+ headers: req.headers,
103
+ error,
104
+ });
105
+ };
106
+ }
107
+ /**
108
+ * Set the data object in th
109
+ */
110
+ static setData(request) {
111
+ if (request.data) {
112
+ return;
113
+ }
114
+ request.data = {};
115
+ }
116
+ }