@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.
- package/build/Commands/MakeControllerCommand.d.ts +15 -0
- package/build/Commands/MakeControllerCommand.js +42 -0
- package/build/Commands/MakeInterceptorCommand.d.ts +15 -0
- package/build/Commands/MakeInterceptorCommand.js +42 -0
- package/build/Commands/MakeMiddlewareCommand.d.ts +15 -0
- package/build/Commands/MakeMiddlewareCommand.js +42 -0
- package/build/Commands/MakeTerminatorCommand.d.ts +15 -0
- package/build/Commands/MakeTerminatorCommand.js +42 -0
- package/build/Commands/RouteListCommand.d.ts +19 -0
- package/build/Commands/RouteListCommand.js +62 -0
- package/build/Context/Request.d.ts +144 -0
- package/build/Context/Request.js +219 -0
- package/build/Context/Response.d.ts +67 -0
- package/build/Context/Response.js +102 -0
- package/build/Contracts/InterceptorContract.d.ts +15 -0
- package/build/Contracts/InterceptorContract.js +9 -0
- package/build/Contracts/MiddlewareContract.d.ts +15 -0
- package/build/Contracts/MiddlewareContract.js +9 -0
- package/build/Contracts/TerminatorContract.d.ts +15 -0
- package/build/Contracts/TerminatorContract.js +9 -0
- package/build/Decorators/Controller.d.ts +14 -0
- package/build/Decorators/Controller.js +28 -0
- package/build/Decorators/Interceptor.d.ts +14 -0
- package/build/Decorators/Interceptor.js +37 -0
- package/build/Decorators/Middleware.d.ts +14 -0
- package/build/Decorators/Middleware.js +37 -0
- package/build/Decorators/Terminator.d.ts +14 -0
- package/build/Decorators/Terminator.js +37 -0
- package/build/Exceptions/BadGatewayException.d.ts +20 -0
- package/build/Exceptions/BadGatewayException.js +22 -0
- package/build/Exceptions/BadRequestException.d.ts +20 -0
- package/build/Exceptions/BadRequestException.js +22 -0
- package/build/Exceptions/ForbiddenException.d.ts +20 -0
- package/build/Exceptions/ForbiddenException.js +22 -0
- package/build/Exceptions/HttpException.d.ts +20 -0
- package/build/Exceptions/HttpException.js +27 -0
- package/build/Exceptions/InternalServerException.d.ts +20 -0
- package/build/Exceptions/InternalServerException.js +22 -0
- package/build/Exceptions/MethodNotAllowedException.d.ts +20 -0
- package/build/Exceptions/MethodNotAllowedException.js +22 -0
- package/build/Exceptions/NotAcceptableException.d.ts +20 -0
- package/build/Exceptions/NotAcceptableException.js +22 -0
- package/build/Exceptions/NotFoundException.d.ts +20 -0
- package/build/Exceptions/NotFoundException.js +22 -0
- package/build/Exceptions/NotImplementedException.d.ts +20 -0
- package/build/Exceptions/NotImplementedException.js +22 -0
- package/build/Exceptions/PayloadTooLargeException.d.ts +20 -0
- package/build/Exceptions/PayloadTooLargeException.js +22 -0
- package/build/Exceptions/RequestTimeoutException.d.ts +20 -0
- package/build/Exceptions/RequestTimeoutException.js +22 -0
- package/build/Exceptions/ServiceUnavailableException.d.ts +20 -0
- package/build/Exceptions/ServiceUnavailableException.js +22 -0
- package/build/Exceptions/UnauthorizedException.d.ts +20 -0
- package/build/Exceptions/UnauthorizedException.js +22 -0
- package/build/Exceptions/UndefinedMethodException.d.ts +12 -0
- package/build/Exceptions/UndefinedMethodException.js +19 -0
- package/build/Exceptions/UnprocessableEntityException.d.ts +20 -0
- package/build/Exceptions/UnprocessableEntityException.js +22 -0
- package/build/Facades/Route.d.ts +10 -0
- package/{src → build}/Facades/Route.js +2 -7
- package/build/Facades/Server.d.ts +10 -0
- package/{src → build}/Facades/Server.js +2 -7
- package/build/Handlers/FastifyHandler.d.ts +41 -0
- package/build/Handlers/FastifyHandler.js +116 -0
- package/build/Handlers/HttpExceptionHandler.d.ts +31 -0
- package/build/Handlers/HttpExceptionHandler.js +82 -0
- package/build/Kernels/HttpKernel.d.ts +73 -0
- package/build/Kernels/HttpKernel.js +221 -0
- package/build/Providers/HttpRouteProvider.d.ts +12 -0
- package/build/Providers/HttpRouteProvider.js +15 -0
- package/build/Providers/HttpServerProvider.d.ts +13 -0
- package/build/Providers/HttpServerProvider.js +25 -0
- package/build/Router/Route.d.ts +263 -0
- package/build/Router/Route.js +447 -0
- package/build/Router/RouteGroup.d.ts +96 -0
- package/build/Router/RouteGroup.js +123 -0
- package/build/Router/RouteResource.d.ts +108 -0
- package/build/Router/RouteResource.js +158 -0
- package/build/Router/Router.d.ts +103 -0
- package/build/Router/Router.js +188 -0
- package/build/Server/ServerImpl.d.ts +129 -0
- package/build/Server/ServerImpl.js +213 -0
- package/build/Types/Contexts/Context.d.ts +20 -0
- package/build/Types/Contexts/Context.js +9 -0
- package/build/Types/Contexts/ErrorContext.d.ts +21 -0
- package/build/Types/Contexts/ErrorContext.js +9 -0
- package/build/Types/Contexts/InterceptContext.d.ts +20 -0
- package/build/Types/Contexts/InterceptContext.js +9 -0
- package/build/Types/Contexts/TerminateContext.d.ts +21 -0
- package/build/Types/Contexts/TerminateContext.js +9 -0
- package/build/Types/Controllers/ControllerOptions.d.ts +25 -0
- package/build/Types/Controllers/ControllerOptions.js +9 -0
- package/build/Types/Middlewares/InterceptorRouteType.d.ts +11 -0
- package/build/Types/Middlewares/InterceptorRouteType.js +9 -0
- package/build/Types/Middlewares/MiddlewareHandler.d.ts +20 -0
- package/build/Types/Middlewares/MiddlewareHandler.js +9 -0
- package/build/Types/Middlewares/MiddlewareOptions.d.ts +40 -0
- package/build/Types/Middlewares/MiddlewareOptions.js +9 -0
- package/build/Types/Middlewares/MiddlewareRouteType.d.ts +11 -0
- package/build/Types/Middlewares/MiddlewareRouteType.js +9 -0
- package/build/Types/Middlewares/TerminatorRouteType.d.ts +11 -0
- package/build/Types/Middlewares/TerminatorRouteType.js +9 -0
- package/build/Types/Router/RouteHandler.d.ts +10 -0
- package/build/Types/Router/RouteHandler.js +9 -0
- package/build/Types/Router/RouteJSON.d.ts +21 -0
- package/build/Types/Router/RouteJSON.js +9 -0
- package/build/Types/Router/RouteResourceTypes.d.ts +9 -0
- package/build/Types/Router/RouteResourceTypes.js +9 -0
- package/build/index.d.ts +70 -0
- package/build/index.js +48 -0
- package/package.json +159 -77
- package/templates/controller.edge +8 -36
- package/templates/interceptor.edge +8 -0
- package/templates/middleware.edge +4 -36
- package/templates/terminator.edge +6 -0
- package/src/Commands/Make/Controller.js +0 -64
- package/src/Commands/Make/Middleware.js +0 -80
- package/src/Commands/Route/List.js +0 -107
- package/src/Context/Request.js +0 -268
- package/src/Context/Response.js +0 -173
- package/src/Exceptions/BadGatewayException.js +0 -31
- package/src/Exceptions/BadRequestException.js +0 -31
- package/src/Exceptions/ForbiddenException.js +0 -31
- package/src/Exceptions/HttpException.js +0 -33
- package/src/Exceptions/InternalServerException.js +0 -31
- package/src/Exceptions/MethodNotAllowedException.js +0 -31
- package/src/Exceptions/NotAcceptableException.js +0 -31
- package/src/Exceptions/NotFoundException.js +0 -31
- package/src/Exceptions/NotImplementedException.js +0 -31
- package/src/Exceptions/PayloadTooLargeException.js +0 -31
- package/src/Exceptions/RequestTimeoutException.js +0 -31
- package/src/Exceptions/ServiceUnavailableException.js +0 -31
- package/src/Exceptions/UnauthorizedException.js +0 -31
- package/src/Exceptions/UndefinedMethodException.js +0 -30
- package/src/Exceptions/UnprocessableEntityException.js +0 -31
- package/src/Handlers/FastifyHandler.js +0 -148
- package/src/Handlers/HttpExceptionHandler.js +0 -88
- package/src/Helpers/HttpLoader.js +0 -38
- package/src/Kernels/HttpKernel.js +0 -199
- package/src/Providers/ControllerProvider.js +0 -29
- package/src/Providers/HttpRouteProvider.js +0 -24
- package/src/Providers/HttpServerProvider.js +0 -37
- package/src/Providers/MiddlewareProvider.js +0 -29
- package/src/Router/Route.js +0 -411
- package/src/Router/RouteGroup.js +0 -119
- package/src/Router/RouteResource.js +0 -247
- package/src/Router/Router.js +0 -313
- package/src/Utils/isMiddlewareContract.js +0 -17
- package/src/Utils/removeSlashes.js +0 -30
- package/src/index.d.ts +0 -1395
- package/src/index.js +0 -377
|
@@ -0,0 +1,67 @@
|
|
|
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 { FastifyReply } from 'fastify';
|
|
10
|
+
import { FastifyHelmetOptions } from '@fastify/helmet';
|
|
11
|
+
export declare class Response {
|
|
12
|
+
/**
|
|
13
|
+
* The fastify response object.
|
|
14
|
+
*/
|
|
15
|
+
response: FastifyReply;
|
|
16
|
+
constructor(response: FastifyReply);
|
|
17
|
+
/**
|
|
18
|
+
* Verify if the response has been already sent.
|
|
19
|
+
*/
|
|
20
|
+
get sent(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Get the status code sent in response.
|
|
23
|
+
*/
|
|
24
|
+
get statusCode(): number;
|
|
25
|
+
/**
|
|
26
|
+
* Get the headers sent in response.
|
|
27
|
+
*/
|
|
28
|
+
get headers(): any;
|
|
29
|
+
/**
|
|
30
|
+
* Get the time in MS of how much the request has taken to response.
|
|
31
|
+
*/
|
|
32
|
+
get responseTime(): number;
|
|
33
|
+
/**
|
|
34
|
+
* Terminate the request sending the response body or not.
|
|
35
|
+
*/
|
|
36
|
+
send(data?: any): Promise<Response>;
|
|
37
|
+
/**
|
|
38
|
+
* Set the response status code.
|
|
39
|
+
*/
|
|
40
|
+
status(code: number): Response;
|
|
41
|
+
/**
|
|
42
|
+
* Add some header to the response.
|
|
43
|
+
*/
|
|
44
|
+
header(header: string, value: any): Response;
|
|
45
|
+
/**
|
|
46
|
+
* Verify if response has some header.
|
|
47
|
+
*/
|
|
48
|
+
hasHeader(header: string): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Add some header safelly to the response. This means that the header is not
|
|
51
|
+
* going to be added if is already set.
|
|
52
|
+
*/
|
|
53
|
+
safeHeader(header: string, value: any): Response;
|
|
54
|
+
/**
|
|
55
|
+
* Remove some header from the response.
|
|
56
|
+
*/
|
|
57
|
+
removeHeader(header: string): Response;
|
|
58
|
+
/**
|
|
59
|
+
* Redirect the response to other url. You can also set a different status code
|
|
60
|
+
* for the redirect.
|
|
61
|
+
*/
|
|
62
|
+
redirectTo(url: string, status?: number): Promise<Response>;
|
|
63
|
+
/**
|
|
64
|
+
* Apply helmet in response.
|
|
65
|
+
*/
|
|
66
|
+
helmet(options: FastifyHelmetOptions): Response;
|
|
67
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
export class Response {
|
|
10
|
+
/**
|
|
11
|
+
* The fastify response object.
|
|
12
|
+
*/
|
|
13
|
+
response;
|
|
14
|
+
constructor(response) {
|
|
15
|
+
this.response = response;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Verify if the response has been already sent.
|
|
19
|
+
*/
|
|
20
|
+
get sent() {
|
|
21
|
+
return this.response.sent;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the status code sent in response.
|
|
25
|
+
*/
|
|
26
|
+
get statusCode() {
|
|
27
|
+
return this.response.statusCode;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get the headers sent in response.
|
|
31
|
+
*/
|
|
32
|
+
get headers() {
|
|
33
|
+
return this.response.getHeaders();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get the time in MS of how much the request has taken to response.
|
|
37
|
+
*/
|
|
38
|
+
get responseTime() {
|
|
39
|
+
return this.response.getResponseTime();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Terminate the request sending the response body or not.
|
|
43
|
+
*/
|
|
44
|
+
async send(data) {
|
|
45
|
+
await this.response.send(data);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Set the response status code.
|
|
50
|
+
*/
|
|
51
|
+
status(code) {
|
|
52
|
+
this.response.status(code);
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Add some header to the response.
|
|
57
|
+
*/
|
|
58
|
+
header(header, value) {
|
|
59
|
+
this.response.header(header, value);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Verify if response has some header.
|
|
64
|
+
*/
|
|
65
|
+
hasHeader(header) {
|
|
66
|
+
return this.response.hasHeader(header);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Add some header safelly to the response. This means that the header is not
|
|
70
|
+
* going to be added if is already set.
|
|
71
|
+
*/
|
|
72
|
+
safeHeader(header, value) {
|
|
73
|
+
this.response.header(header, value);
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Remove some header from the response.
|
|
78
|
+
*/
|
|
79
|
+
removeHeader(header) {
|
|
80
|
+
this.response.removeHeader(header);
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Redirect the response to other url. You can also set a different status code
|
|
85
|
+
* for the redirect.
|
|
86
|
+
*/
|
|
87
|
+
async redirectTo(url, status) {
|
|
88
|
+
if (status) {
|
|
89
|
+
await this.response.redirect(status, url);
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
await this.response.redirect(url);
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Apply helmet in response.
|
|
97
|
+
*/
|
|
98
|
+
helmet(options) {
|
|
99
|
+
this.response.helmet(options);
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 { InterceptContext } from '#src/Types/Contexts/InterceptContext';
|
|
10
|
+
export interface InterceptorContract {
|
|
11
|
+
/**
|
|
12
|
+
* Intercept the request at the end, before returning the response.
|
|
13
|
+
*/
|
|
14
|
+
intercept(ctx: InterceptContext): unknown | Promise<unknown>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 { Context } from '#src/Types/Contexts/Context';
|
|
10
|
+
export interface MiddlewareContract {
|
|
11
|
+
/**
|
|
12
|
+
* Handle the request before going to the route handler.
|
|
13
|
+
*/
|
|
14
|
+
handle(ctx: Context): any | Promise<any>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 { TerminateContext } from '#src/Types/Contexts/TerminateContext';
|
|
10
|
+
export interface TerminatorContract {
|
|
11
|
+
/**
|
|
12
|
+
* Handle the request after the response has been sent.
|
|
13
|
+
*/
|
|
14
|
+
terminate(ctx: TerminateContext): any | Promise<any>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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 'reflect-metadata';
|
|
10
|
+
import { ControllerOptions } from '#src/Types/Controllers/ControllerOptions';
|
|
11
|
+
/**
|
|
12
|
+
* Create a controller inside the service provider.
|
|
13
|
+
*/
|
|
14
|
+
export declare function Controller(options?: ControllerOptions): ClassDecorator;
|
|
@@ -0,0 +1,28 @@
|
|
|
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 'reflect-metadata';
|
|
10
|
+
import { Options } from '@athenna/common';
|
|
11
|
+
/**
|
|
12
|
+
* Create a controller inside the service provider.
|
|
13
|
+
*/
|
|
14
|
+
export function Controller(options) {
|
|
15
|
+
return (target) => {
|
|
16
|
+
options = Options.create(options, {
|
|
17
|
+
alias: `App/Http/Controllers/${target.name}`,
|
|
18
|
+
type: 'transient',
|
|
19
|
+
});
|
|
20
|
+
const alias = options.alias;
|
|
21
|
+
const createCamelAlias = false;
|
|
22
|
+
if (ioc.hasDependency(alias)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
ioc[options.type](alias, target, createCamelAlias);
|
|
26
|
+
Reflect.defineMetadata('provider:registered', true, target);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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 'reflect-metadata';
|
|
10
|
+
import { MiddlewareOptions } from '#src/Types/Middlewares/MiddlewareOptions';
|
|
11
|
+
/**
|
|
12
|
+
* Create a interceptor inside the service provider.
|
|
13
|
+
*/
|
|
14
|
+
export declare function Interceptor(options?: MiddlewareOptions): ClassDecorator;
|
|
@@ -0,0 +1,37 @@
|
|
|
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 'reflect-metadata';
|
|
10
|
+
import { Server } from '#src/Facades/Server';
|
|
11
|
+
import { Options, String } from '@athenna/common';
|
|
12
|
+
/**
|
|
13
|
+
* Create a interceptor inside the service provider.
|
|
14
|
+
*/
|
|
15
|
+
export function Interceptor(options) {
|
|
16
|
+
return (target) => {
|
|
17
|
+
options = Options.create(options, {
|
|
18
|
+
isGlobal: false,
|
|
19
|
+
name: String.toCamelCase(target.name),
|
|
20
|
+
alias: `App/Http/Interceptors/${target.name}`,
|
|
21
|
+
type: 'transient',
|
|
22
|
+
});
|
|
23
|
+
const alias = options.alias;
|
|
24
|
+
const createCamelAlias = false;
|
|
25
|
+
if (ioc.hasDependency(alias)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
ioc[options.type](alias, target, createCamelAlias);
|
|
29
|
+
Reflect.defineMetadata('provider:registered', true, target);
|
|
30
|
+
if (!options.isGlobal) {
|
|
31
|
+
ioc.alias(`App/Http/Interceptors/Names/${options.name}`, alias);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const Interceptor = ioc.safeUse(alias);
|
|
35
|
+
Server.intercept(Interceptor.intercept);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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 'reflect-metadata';
|
|
10
|
+
import { MiddlewareOptions } from '#src/Types/Middlewares/MiddlewareOptions';
|
|
11
|
+
/**
|
|
12
|
+
* Create a middleware inside the service provider.
|
|
13
|
+
*/
|
|
14
|
+
export declare function Middleware(options?: MiddlewareOptions): ClassDecorator;
|
|
@@ -0,0 +1,37 @@
|
|
|
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 'reflect-metadata';
|
|
10
|
+
import { Server } from '#src/Facades/Server';
|
|
11
|
+
import { Options, String } from '@athenna/common';
|
|
12
|
+
/**
|
|
13
|
+
* Create a middleware inside the service provider.
|
|
14
|
+
*/
|
|
15
|
+
export function Middleware(options) {
|
|
16
|
+
return (target) => {
|
|
17
|
+
options = Options.create(options, {
|
|
18
|
+
isGlobal: false,
|
|
19
|
+
name: String.toCamelCase(target.name),
|
|
20
|
+
alias: `App/Http/Middlewares/${target.name}`,
|
|
21
|
+
type: 'transient',
|
|
22
|
+
});
|
|
23
|
+
const alias = options.alias;
|
|
24
|
+
const createCamelAlias = false;
|
|
25
|
+
if (ioc.hasDependency(alias)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
ioc[options.type](alias, target, createCamelAlias);
|
|
29
|
+
Reflect.defineMetadata('provider:registered', true, target);
|
|
30
|
+
if (!options.isGlobal) {
|
|
31
|
+
ioc.alias(`App/Http/Middlewares/Names/${options.name}`, alias);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const Middleware = ioc.safeUse(alias);
|
|
35
|
+
Server.middleware(Middleware.handle);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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 'reflect-metadata';
|
|
10
|
+
import { MiddlewareOptions } from '#src/Types/Middlewares/MiddlewareOptions';
|
|
11
|
+
/**
|
|
12
|
+
* Create a middleware inside the service provider.
|
|
13
|
+
*/
|
|
14
|
+
export declare function Terminator(options?: MiddlewareOptions): ClassDecorator;
|
|
@@ -0,0 +1,37 @@
|
|
|
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 'reflect-metadata';
|
|
10
|
+
import { Server } from '#src/Facades/Server';
|
|
11
|
+
import { Options, String } from '@athenna/common';
|
|
12
|
+
/**
|
|
13
|
+
* Create a middleware inside the service provider.
|
|
14
|
+
*/
|
|
15
|
+
export function Terminator(options) {
|
|
16
|
+
return (target) => {
|
|
17
|
+
options = Options.create(options, {
|
|
18
|
+
isGlobal: false,
|
|
19
|
+
name: String.toCamelCase(target.name),
|
|
20
|
+
alias: `App/Http/Terminators/${target.name}`,
|
|
21
|
+
type: 'transient',
|
|
22
|
+
});
|
|
23
|
+
const alias = options.alias;
|
|
24
|
+
const createCamelAlias = false;
|
|
25
|
+
if (ioc.hasDependency(alias)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
ioc[options.type](alias, target, createCamelAlias);
|
|
29
|
+
Reflect.defineMetadata('provider:registered', true, target);
|
|
30
|
+
if (!options.isGlobal) {
|
|
31
|
+
ioc.alias(`App/Http/Terminators/Names/${options.name}`, alias);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const Terminator = ioc.safeUse(alias);
|
|
35
|
+
Server.middleware(Terminator.terminate);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -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 BadGatewayException extends HttpException {
|
|
11
|
+
/**
|
|
12
|
+
* This exception uses the 502 status code and the "E_BAD_GATEWAY_ERROR" code.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```js
|
|
16
|
+
* throw new BadGatewayException()
|
|
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 BadGatewayException extends HttpException {
|
|
11
|
+
/**
|
|
12
|
+
* This exception uses the 502 status code and the "E_BAD_GATEWAY_ERROR" code.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```js
|
|
16
|
+
* throw new BadGatewayException()
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
constructor(message = 'Bad gateway error happened.', help = null) {
|
|
20
|
+
super({ help, message, status: 502, code: 'E_BAD_GATEWAY_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 BadRequestException extends HttpException {
|
|
11
|
+
/**
|
|
12
|
+
* This exception uses the 400 status code and the "E_BAD_REQUEST_ERROR" code.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```js
|
|
16
|
+
* throw new BadRequestException()
|
|
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 BadRequestException extends HttpException {
|
|
11
|
+
/**
|
|
12
|
+
* This exception uses the 400 status code and the "E_BAD_REQUEST_ERROR" code.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```js
|
|
16
|
+
* throw new BadRequestException()
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
constructor(message = 'Bad request error happened.', help = null) {
|
|
20
|
+
super({ help, message, status: 400, code: 'E_BAD_REQUEST_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 ForbiddenException extends HttpException {
|
|
11
|
+
/**
|
|
12
|
+
* This exception uses the 403 status code and the "E_FORBIDDEN_ERROR" code.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```js
|
|
16
|
+
* throw new ForbiddenException()
|
|
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 ForbiddenException extends HttpException {
|
|
11
|
+
/**
|
|
12
|
+
* This exception uses the 403 status code and the "E_FORBIDDEN_ERROR" code.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```js
|
|
16
|
+
* throw new ForbiddenException()
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
constructor(message = 'Forbidden request error happened.', help = null) {
|
|
20
|
+
super({ help, message, status: 403, code: 'E_FORBIDDEN_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 { Exception, ExceptionJSON } from '@athenna/common';
|
|
10
|
+
export declare class HttpException extends Exception {
|
|
11
|
+
/**
|
|
12
|
+
* This exception uses the 500 status code and the "E_HTTP_ERROR" code.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```js
|
|
16
|
+
* throw new HttpException()
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
constructor(options?: ExceptionJSON);
|
|
20
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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, Options } from '@athenna/common';
|
|
10
|
+
export class HttpException extends Exception {
|
|
11
|
+
/**
|
|
12
|
+
* This exception uses the 500 status code and the "E_HTTP_ERROR" code.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```js
|
|
16
|
+
* throw new HttpException()
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
constructor(options = {}) {
|
|
20
|
+
options = Options.create(options, {
|
|
21
|
+
status: 500,
|
|
22
|
+
code: 'E_HTTP_ERROR',
|
|
23
|
+
message: 'An http exception has ocurred.',
|
|
24
|
+
});
|
|
25
|
+
super(options);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -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 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?: string, help?: any);
|
|
20
|
+
}
|