@athenna/http 3.0.10 → 3.0.11

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": "3.0.10",
3
+ "version": "3.0.11",
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>",
@@ -57,7 +57,7 @@
57
57
  "fastify": "4.9.2"
58
58
  },
59
59
  "devDependencies": {
60
- "@athenna/artisan": "3.0.9",
60
+ "@athenna/artisan": "3.0.10",
61
61
  "@athenna/common": "3.0.2",
62
62
  "@athenna/config": "3.0.4",
63
63
  "@athenna/ioc": "3.0.2",
@@ -71,6 +71,7 @@
71
71
  "@japa/run-failed-tests": "1.0.7",
72
72
  "@japa/runner": "2.0.7",
73
73
  "@japa/spec-reporter": "1.1.12",
74
+ "@types/commander": "2.12.2",
74
75
  "c8": "7.11.2",
75
76
  "cls-rtracer": "2.6.2",
76
77
  "commitizen": "4.2.5",
@@ -33,8 +33,8 @@ export class MakeController extends Command {
33
33
  * Set additional flags in the commander instance.
34
34
  * This method is executed when registering your command.
35
35
  *
36
- * @param {import('commander').Command} commander
37
- * @return {import('commander').Command}
36
+ * @param {import('@athenna/artisan').Commander} commander
37
+ * @return {import('@athenna/artisan').Commander}
38
38
  */
39
39
  addFlags(commander) {
40
40
  return commander.option(
@@ -33,8 +33,8 @@ export class MakeMiddleware extends Command {
33
33
  * Set additional flags in the commander instance.
34
34
  * This method is executed when registering your command.
35
35
  *
36
- * @param {import('commander').Command} commander
37
- * @return {import('commander').Command}
36
+ * @param {import('@athenna/artisan').Commander} commander
37
+ * @return {import('@athenna/artisan').Commander}
38
38
  */
39
39
  addFlags(commander) {
40
40
  return commander
@@ -35,8 +35,8 @@ export class RouteList extends Command {
35
35
  * Set additional flags in the commander instance.
36
36
  * This method is executed when registering your command.
37
37
  *
38
- * @param {import('commander').Command} commander
39
- * @return {import('commander').Command}
38
+ * @param {import('@athenna/artisan').Commander} commander
39
+ * @return {import('@athenna/artisan').Commander}
40
40
  */
41
41
  addFlags(commander) {
42
42
  return commander.option(
@@ -29,6 +29,15 @@ export class Request {
29
29
  this.#request = request
30
30
  }
31
31
 
32
+ /**
33
+ * Get the request id.
34
+ *
35
+ * @return {string}
36
+ */
37
+ get id() {
38
+ return this.#request.id
39
+ }
40
+
32
41
  /**
33
42
  * Get the request ip.
34
43
  *
@@ -38,6 +47,24 @@ export class Request {
38
47
  return this.#request.ip
39
48
  }
40
49
 
50
+ /**
51
+ * Get the request hostname.
52
+ *
53
+ * @return {string}
54
+ */
55
+ get hostname() {
56
+ return this.#request.hostname
57
+ }
58
+
59
+ /**
60
+ * Get the request protocol.
61
+ *
62
+ * @return {"http"|"https"}
63
+ */
64
+ get protocol() {
65
+ return this.#request.protocol
66
+ }
67
+
41
68
  /**
42
69
  * Get the request method.
43
70
  *
@@ -47,6 +74,15 @@ export class Request {
47
74
  return this.#request.method
48
75
  }
49
76
 
77
+ /**
78
+ * Get the route url from request.
79
+ *
80
+ * @return {string}
81
+ */
82
+ get routeUrl() {
83
+ return this.#request.routerPath
84
+ }
85
+
50
86
  /**
51
87
  * Get the host url from request.
52
88
  *
@@ -117,6 +153,15 @@ export class Request {
117
153
  return this.#request.headers || {}
118
154
  }
119
155
 
156
+ /**
157
+ * Get the server version.
158
+ *
159
+ * @return {string}
160
+ */
161
+ get version() {
162
+ return this.#request.server.version
163
+ }
164
+
120
165
  /**
121
166
  * Get a value from the request params or the default value.
122
167
  *
@@ -25,6 +25,42 @@ export class Response {
25
25
  this.#response = response
26
26
  }
27
27
 
28
+ /**
29
+ * Verify if response has been already sent.
30
+ *
31
+ * @return {boolean}
32
+ */
33
+ get sent() {
34
+ return this.#response.sent
35
+ }
36
+
37
+ /**
38
+ * Get the status code sent in response.
39
+ *
40
+ * @return {number}
41
+ */
42
+ get statusCode() {
43
+ return this.#response.statusCode
44
+ }
45
+
46
+ /**
47
+ * Get the headers sent in response.
48
+ *
49
+ * @return {any}
50
+ */
51
+ get headers() {
52
+ return this.#response.getHeaders()
53
+ }
54
+
55
+ /**
56
+ * Get the response time.
57
+ *
58
+ * @return {number}
59
+ */
60
+ get responseTime() {
61
+ return this.#response.getResponseTime()
62
+ }
63
+
28
64
  /**
29
65
  * Terminate the request sending the response body.
30
66
  *
@@ -360,12 +360,6 @@ export class Route {
360
360
  this.#swaggerOptions.response = {}
361
361
  }
362
362
 
363
- if (!response) {
364
- this.#swaggerOptions.response.default = response
365
-
366
- return this
367
- }
368
-
369
363
  this.#swaggerOptions.response[statusCode] = response
370
364
 
371
365
  return this
package/src/index.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  */
9
9
 
10
10
  import { Facade } from '@athenna/ioc'
11
- import { Exception, Json } from '@athenna/common'
11
+ import { Exception } from '@athenna/common'
12
12
  import { OpenAPIV2, OpenAPIV3 } from 'openapi-types'
13
13
  import { FastifyHelmetOptions } from '@fastify/helmet'
14
14
  import { RateLimitOptions } from '@fastify/rate-limit'
@@ -817,12 +817,34 @@ declare module Router {
817
817
  }
818
818
 
819
819
  export interface RequestContract {
820
+ /**
821
+ * Get the request id.
822
+ *
823
+ * @return {string}
824
+ */
825
+ get id(): string
826
+
820
827
  /**
821
828
  * Get the request ip.
822
829
  *
823
830
  * @return {string}
824
831
  */
825
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
+
826
848
  /**
827
849
  * Get the request method.
828
850
  *
@@ -830,6 +852,13 @@ export interface RequestContract {
830
852
  */
831
853
  get method(): string
832
854
 
855
+ /**
856
+ * Get the route url from request.
857
+ *
858
+ * @return {string}
859
+ */
860
+ get routeUrl(): string
861
+
833
862
  /**
834
863
  * Get the host url from request.
835
864
  *
@@ -879,6 +908,13 @@ export interface RequestContract {
879
908
  */
880
909
  get headers(): any
881
910
 
911
+ /**
912
+ * Get the server version.
913
+ *
914
+ * @return {string}
915
+ */
916
+ get version(): string
917
+
882
918
  /**
883
919
  * Get a value from the request params or the default value.
884
920
  *
@@ -951,6 +987,34 @@ export interface RequestContract {
951
987
  }
952
988
 
953
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
+
954
1018
  /**
955
1019
  * Terminate the request sending the response body.
956
1020
  *