@athenna/http 4.31.0 → 4.32.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@athenna/http",
3
- "version": "4.31.0",
3
+ "version": "4.32.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>",
@@ -36,7 +36,7 @@ export class RouteListCommand extends BaseCommand {
36
36
  table.row([
37
37
  route.methods.map(m => this.paintMethod(m)).join('|'),
38
38
  route.url,
39
- route.name || 'Not found',
39
+ route.name || 'Not defined',
40
40
  route.handler.name || 'closure'
41
41
  ]);
42
42
  });
@@ -76,6 +76,15 @@ export declare class Request {
76
76
  * ```
77
77
  */
78
78
  get method(): string;
79
+ /**
80
+ * Get the route name defined in your route file.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * console.log(request.routeName) // 'users'
85
+ * ```
86
+ */
87
+ get routeName(): string;
79
88
  /**
80
89
  * Get the base url from request.
81
90
  *
@@ -88,6 +88,19 @@ export class Request {
88
88
  get method() {
89
89
  return this.request.method;
90
90
  }
91
+ /**
92
+ * Get the route name defined in your route file.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * console.log(request.routeName) // 'users'
97
+ * ```
98
+ */
99
+ get routeName() {
100
+ // eslint-disable-next-line
101
+ // @ts-ignore
102
+ return this.request.routeOptions.config.name;
103
+ }
91
104
  /**
92
105
  * Get the base url from request.
93
106
  *
@@ -21,7 +21,7 @@ export class Route {
21
21
  terminators: [],
22
22
  interceptors: []
23
23
  },
24
- fastify: { schema: {} }
24
+ fastify: { schema: {}, config: {} }
25
25
  };
26
26
  if (Is.String(handler)) {
27
27
  const [controller, method] = handler.split('.');
@@ -52,6 +52,9 @@ export class Route {
52
52
  */
53
53
  name(name) {
54
54
  this.route.name = name;
55
+ // eslint-disable-next-line
56
+ // @ts-ignore
57
+ this.route.fastify.config.name = name;
55
58
  return this;
56
59
  }
57
60
  /**
@@ -201,9 +204,6 @@ export class Route {
201
204
  * ```
202
205
  */
203
206
  rateLimit(options) {
204
- if (!this.route.fastify.config) {
205
- this.route.fastify.config = {};
206
- }
207
207
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
208
208
  // @ts-ignore
209
209
  this.route.fastify.config.rateLimit = options;
@@ -16,7 +16,7 @@ export declare class RouteGroup {
16
16
  routes: (Route | RouteGroup | RouteResource)[];
17
17
  constructor(routes: (Route | RouteGroup | RouteResource)[]);
18
18
  /**
19
- * Define prefix all the routes in the group.
19
+ * Define prefix for all the routes in the group.
20
20
  *
21
21
  * @example
22
22
  * ```ts
@@ -26,6 +26,17 @@ export declare class RouteGroup {
26
26
  * ```
27
27
  */
28
28
  prefix(prefix: string): RouteGroup;
29
+ /**
30
+ * Define a name for all the routes in the group.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * Route.group(() => {
35
+ *
36
+ * }).name('users')
37
+ * ```
38
+ */
39
+ name(name: string): RouteGroup;
29
40
  /**
30
41
  * Add a middleware to all routes in the group.
31
42
  *
@@ -13,7 +13,7 @@ export class RouteGroup {
13
13
  this.routes = routes;
14
14
  }
15
15
  /**
16
- * Define prefix all the routes in the group.
16
+ * Define prefix for all the routes in the group.
17
17
  *
18
18
  * @example
19
19
  * ```ts
@@ -26,6 +26,20 @@ export class RouteGroup {
26
26
  this.routes.forEach(route => this.invoke(route, 'prefix', [prefix]));
27
27
  return this;
28
28
  }
29
+ /**
30
+ * Define a name for all the routes in the group.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * Route.group(() => {
35
+ *
36
+ * }).name('users')
37
+ * ```
38
+ */
39
+ name(name) {
40
+ this.routes.forEach(route => this.invoke(route, 'name', [name]));
41
+ return this;
42
+ }
29
43
  /**
30
44
  * Add a middleware to all routes in the group.
31
45
  *