@athenna/http 4.33.0 → 4.35.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/package.json +20 -20
- package/src/exceptions/NotFoundValidatorException.d.ts +12 -0
- package/src/exceptions/NotFoundValidatorException.js +19 -0
- package/src/router/Route.d.ts +5 -0
- package/src/router/Route.js +26 -0
- package/src/router/RouteGroup.d.ts +11 -0
- package/src/router/RouteGroup.js +14 -0
- package/src/router/RouteResource.d.ts +9 -0
- package/src/router/RouteResource.js +12 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/http",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.35.0",
|
|
4
4
|
"description": "The Athenna Http server. Built on top of fastify.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "João Lenon <lenon@athenna.io>",
|
|
@@ -74,36 +74,36 @@
|
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@athenna/artisan": "^4.42.0",
|
|
77
|
-
"@athenna/common": "^4.
|
|
78
|
-
"@athenna/config": "^4.
|
|
79
|
-
"@athenna/ioc": "^4.
|
|
80
|
-
"@athenna/logger": "^4.
|
|
81
|
-
"@athenna/test": "^4.
|
|
82
|
-
"@athenna/tsconfig": "^4.
|
|
83
|
-
"@athenna/view": "^4.
|
|
84
|
-
"@fastify/cors": "^8.
|
|
77
|
+
"@athenna/common": "^4.42.0",
|
|
78
|
+
"@athenna/config": "^4.22.0",
|
|
79
|
+
"@athenna/ioc": "^4.21.0",
|
|
80
|
+
"@athenna/logger": "^4.22.0",
|
|
81
|
+
"@athenna/test": "^4.24.0",
|
|
82
|
+
"@athenna/tsconfig": "^4.14.0",
|
|
83
|
+
"@athenna/view": "^4.23.0",
|
|
84
|
+
"@fastify/cors": "^8.5.0",
|
|
85
85
|
"@fastify/helmet": "^11.1.1",
|
|
86
86
|
"@fastify/rate-limit": "^8.1.1",
|
|
87
|
-
"@fastify/static": "^7.0.
|
|
88
|
-
"@fastify/swagger": "^8.
|
|
87
|
+
"@fastify/static": "^7.0.4",
|
|
88
|
+
"@fastify/swagger": "^8.14.0",
|
|
89
89
|
"@fastify/swagger-ui": "^3.0.0",
|
|
90
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
91
|
-
"@typescript-eslint/parser": "^6.
|
|
90
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
91
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
92
92
|
"autocannon": "^7.15.0",
|
|
93
|
-
"commitizen": "^4.
|
|
93
|
+
"commitizen": "^4.3.0",
|
|
94
94
|
"cz-conventional-changelog": "^3.3.0",
|
|
95
|
-
"eslint": "^8.
|
|
96
|
-
"eslint-config-prettier": "^8.
|
|
97
|
-
"eslint-config-standard": "^17.
|
|
98
|
-
"eslint-plugin-import": "^2.
|
|
99
|
-
"eslint-plugin-n": "^15.
|
|
95
|
+
"eslint": "^8.57.0",
|
|
96
|
+
"eslint-config-prettier": "^8.10.0",
|
|
97
|
+
"eslint-config-standard": "^17.1.0",
|
|
98
|
+
"eslint-plugin-import": "^2.29.1",
|
|
99
|
+
"eslint-plugin-n": "^15.7.0",
|
|
100
100
|
"eslint-plugin-prettier": "^4.2.1",
|
|
101
101
|
"eslint-plugin-promise": "^6.1.1",
|
|
102
102
|
"foreground-child": "^2.0.0",
|
|
103
103
|
"husky": "^3.1.0",
|
|
104
104
|
"lint-staged": "^12.5.0",
|
|
105
105
|
"ora": "^8.0.1",
|
|
106
|
-
"prettier": "^2.8.
|
|
106
|
+
"prettier": "^2.8.8"
|
|
107
107
|
},
|
|
108
108
|
"c8": {
|
|
109
109
|
"all": true,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @athenna/ioc
|
|
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 NotFoundValidatorException extends Exception {
|
|
11
|
+
constructor(alias: string, namedAlias: string);
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @athenna/ioc
|
|
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 NotFoundValidatorException extends Exception {
|
|
11
|
+
constructor(alias, namedAlias) {
|
|
12
|
+
super({
|
|
13
|
+
status: 500,
|
|
14
|
+
code: 'E_NOT_FOUND_VALIDATOR_ERROR',
|
|
15
|
+
message: `The validator with ${namedAlias} named alias and ${alias} alias has not been found inside the container.`,
|
|
16
|
+
help: `Remember to register the validator in your .athennarc.json file.`
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/router/Route.d.ts
CHANGED
|
@@ -50,6 +50,11 @@ export declare class Route {
|
|
|
50
50
|
* ```
|
|
51
51
|
*/
|
|
52
52
|
prefix(prefix: string): Route;
|
|
53
|
+
/**
|
|
54
|
+
* Set a named validator, validator closure or a MiddlewareContract implementation
|
|
55
|
+
* in the route.
|
|
56
|
+
*/
|
|
57
|
+
validator(validator: MiddlewareRouteType, prepend?: boolean): Route;
|
|
53
58
|
/**
|
|
54
59
|
* Set a named middleware, middleware closure or a MiddlewareContract implementation
|
|
55
60
|
* in the route.
|
package/src/router/Route.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { Is, Options, Route as RouteHelper } from '@athenna/common';
|
|
10
10
|
import { UndefinedMethodException } from '#src/exceptions/UndefinedMethodException';
|
|
11
|
+
import { NotFoundValidatorException } from '#src/exceptions/NotFoundValidatorException';
|
|
11
12
|
import { NotFoundMiddlewareException } from '#src/exceptions/NotFoundMiddlewareException';
|
|
12
13
|
export class Route {
|
|
13
14
|
constructor(url, methods, handler) {
|
|
@@ -84,6 +85,31 @@ export class Route {
|
|
|
84
85
|
this.route.prefixes.push(prefix);
|
|
85
86
|
return this;
|
|
86
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Set a named validator, validator closure or a MiddlewareContract implementation
|
|
90
|
+
* in the route.
|
|
91
|
+
*/
|
|
92
|
+
validator(validator, prepend = false) {
|
|
93
|
+
const insertionType = prepend ? 'unshift' : 'push';
|
|
94
|
+
if (Is.String(validator)) {
|
|
95
|
+
const namedAlias = `App/Validators/Names/${validator}`;
|
|
96
|
+
const alias = `App/Validators/${validator}`;
|
|
97
|
+
if (!ioc.has(namedAlias) && !ioc.has(alias)) {
|
|
98
|
+
throw new NotFoundValidatorException(alias, namedAlias);
|
|
99
|
+
}
|
|
100
|
+
this.route.middlewares.middlewares[insertionType]((...args) => {
|
|
101
|
+
const mid = ioc.use(namedAlias) || ioc.safeUse(alias);
|
|
102
|
+
return mid.handle.bind(mid)(...args);
|
|
103
|
+
});
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
if (Is.Function(validator)) {
|
|
107
|
+
this.route.middlewares.middlewares[insertionType](validator);
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
this.route.middlewares.middlewares[insertionType](validator.handle.bind(validator));
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
87
113
|
/**
|
|
88
114
|
* Set a named middleware, middleware closure or a MiddlewareContract implementation
|
|
89
115
|
* in the route.
|
|
@@ -37,6 +37,17 @@ export declare class RouteGroup {
|
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
39
|
name(name: string): RouteGroup;
|
|
40
|
+
/**
|
|
41
|
+
* Add a validator to all routes in the group.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* Route.group(() => {
|
|
46
|
+
*
|
|
47
|
+
* }).validator('auth')
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
validator(validator: MiddlewareRouteType): RouteGroup;
|
|
40
51
|
/**
|
|
41
52
|
* Add a middleware to all routes in the group.
|
|
42
53
|
*
|
package/src/router/RouteGroup.js
CHANGED
|
@@ -40,6 +40,20 @@ export class RouteGroup {
|
|
|
40
40
|
this.routes.forEach(route => this.invoke(route, 'name', [name]));
|
|
41
41
|
return this;
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Add a validator to all routes in the group.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* Route.group(() => {
|
|
49
|
+
*
|
|
50
|
+
* }).validator('auth')
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
validator(validator) {
|
|
54
|
+
this.routes.forEach(route => this.invoke(route, 'validator', [validator, true]));
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
43
57
|
/**
|
|
44
58
|
* Add a middleware to all routes in the group.
|
|
45
59
|
*
|
|
@@ -22,6 +22,15 @@ export declare class RouteResource {
|
|
|
22
22
|
*/
|
|
23
23
|
controller: any;
|
|
24
24
|
constructor(resource: string, controller: any);
|
|
25
|
+
/**
|
|
26
|
+
* Set a validator for the route resource.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* Route.resource('/test', 'TestController').validator('auth')
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
validator(validator: MiddlewareRouteType, prepend?: boolean): RouteResource;
|
|
25
34
|
/**
|
|
26
35
|
* Set a middleware for the route resource.
|
|
27
36
|
*
|
|
@@ -18,6 +18,18 @@ export class RouteResource {
|
|
|
18
18
|
this.controller = controller;
|
|
19
19
|
this.buildRoutes();
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Set a validator for the route resource.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* Route.resource('/test', 'TestController').validator('auth')
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
validator(validator, prepend) {
|
|
30
|
+
this.routes.forEach(route => route.validator(validator, prepend));
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
21
33
|
/**
|
|
22
34
|
* Set a middleware for the route resource.
|
|
23
35
|
*
|