@athenna/http 4.25.0 → 4.26.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 +4 -1
- package/src/context/Request.d.ts +243 -34
- package/src/context/Request.js +312 -75
- package/src/context/Response.d.ts +210 -5
- package/src/context/Response.js +231 -78
- package/src/handlers/FastifyHandler.js +12 -12
- package/src/server/ServerImpl.js +1 -1
- package/src/types/contexts/Context.d.ts +2 -452
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/http",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.26.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>",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "node node_modules/@athenna/tsconfig/src/build.js",
|
|
31
31
|
"lint:fix": "eslint \"{bin,src,tests}/**/*.ts\" --fix",
|
|
32
|
+
"benchmark": "node --no-warnings --enable-source-maps --import=@athenna/tsconfig tests/benchmarks/ServerTest.ts",
|
|
32
33
|
"test": "npm run --silent lint:fix && node --enable-source-maps --import=@athenna/tsconfig bin/test.ts",
|
|
33
34
|
"test:debug": "cross-env NODE_DEBUG=athenna:* node --inspect --enable-source-maps --import=@athenna/tsconfig bin/test.ts",
|
|
34
35
|
"test:coverage": "c8 npm run --silent test"
|
|
@@ -88,6 +89,7 @@
|
|
|
88
89
|
"@fastify/swagger-ui": "^3.0.0",
|
|
89
90
|
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
90
91
|
"@typescript-eslint/parser": "^6.7.4",
|
|
92
|
+
"autocannon": "^7.15.0",
|
|
91
93
|
"commitizen": "^4.2.6",
|
|
92
94
|
"cz-conventional-changelog": "^3.3.0",
|
|
93
95
|
"eslint": "^8.36.0",
|
|
@@ -100,6 +102,7 @@
|
|
|
100
102
|
"foreground-child": "^2.0.0",
|
|
101
103
|
"husky": "^3.1.0",
|
|
102
104
|
"lint-staged": "^12.5.0",
|
|
105
|
+
"ora": "^8.0.1",
|
|
103
106
|
"prettier": "^2.8.7"
|
|
104
107
|
},
|
|
105
108
|
"c8": {
|
package/src/context/Request.d.ts
CHANGED
|
@@ -6,38 +6,247 @@
|
|
|
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
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
10
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
11
|
-
/// <reference types="node/http.js" />
|
|
12
|
-
/// <reference types="node_modules/got/dist/source/core/timed-out.js" />
|
|
13
|
-
import type { AddressInfo } from 'node:net';
|
|
14
9
|
import type { FastifyRequest } from 'fastify';
|
|
15
|
-
export declare
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
10
|
+
export declare class Request {
|
|
11
|
+
/**
|
|
12
|
+
* The fastify request object.
|
|
13
|
+
*/
|
|
14
|
+
private request;
|
|
15
|
+
constructor(request: FastifyRequest);
|
|
16
|
+
/**
|
|
17
|
+
* Get the request id.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* console.log(request.id) // '12345'
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
get id(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Get the request ip.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* console.log(request.ip) // '192.168.0.1'
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
get ip(): string;
|
|
34
|
+
/**
|
|
35
|
+
* Get the request hostname.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* console.log(request.hostname) // 'localhost'
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
get hostname(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Get the server port.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* console.log(request.port) // 3000
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
get port(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Get the http version.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* console.log(request.version) // 1
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
get version(): string;
|
|
61
|
+
/**
|
|
62
|
+
* Get the request protocol.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* console.log(request.protocol) // 'http'
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
get protocol(): 'http' | 'https';
|
|
70
|
+
/**
|
|
71
|
+
* Get the request method.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* console.log(request.method) // 'GET'
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
get method(): string;
|
|
79
|
+
/**
|
|
80
|
+
* Get the base url from request.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* console.log(request.baseUrl) // '/users/1'
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
get baseUrl(): string;
|
|
88
|
+
/**
|
|
89
|
+
* Get the base url with host and port info from request.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* console.log(request.baseHostUrl) // 'http://localhost:3030/users/1'
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
get baseHostUrl(): string;
|
|
97
|
+
/**
|
|
98
|
+
* Get the route url from request.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* console.log(request.routeUrl) // '/users/:id'
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
get routeUrl(): string;
|
|
106
|
+
/**
|
|
107
|
+
* Get the route url with host and port info from request.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* console.log(request.routeHostUrl) // 'http://localhost:3030/users/:id'
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
get routeHostUrl(): string;
|
|
115
|
+
/**
|
|
116
|
+
* Get the original url from request.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* console.log(request.originalUrl) // '/users/1?query=true'
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
get originalUrl(): string;
|
|
124
|
+
/**
|
|
125
|
+
* Get the original url with host and port info from request.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* console.log(request.originalHostUrl) // 'http://localhost:3000/users/1?query=true'
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
get originalHostUrl(): string;
|
|
133
|
+
/**
|
|
134
|
+
* Get all body from request.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* const { name, email } = request.body
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
get body(): any | any[];
|
|
142
|
+
/**
|
|
143
|
+
* Get all params from request.
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```ts
|
|
147
|
+
* const { id } = request.params
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
get params(): any;
|
|
151
|
+
/**
|
|
152
|
+
* Get all queries from request.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* const { page, limit } = request.queries
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
get queries(): any;
|
|
160
|
+
/**
|
|
161
|
+
* Get all headers from request.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* const { accept } = request.headers
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
get headers(): any;
|
|
169
|
+
/**
|
|
170
|
+
* Get a value from the request params or return
|
|
171
|
+
* the default value.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* const id = request.param('id', '1')
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
param(param: string, defaultValue?: any): any;
|
|
179
|
+
/**
|
|
180
|
+
* Get a value from the request query param or return
|
|
181
|
+
* the default value.
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```ts
|
|
185
|
+
* const page = request.query('page', '1')
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
query(query: string, defaultValue?: any): any;
|
|
189
|
+
/**
|
|
190
|
+
* Get a value from the request header or return
|
|
191
|
+
* the default value.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* const accept = request.header('accept', 'application/json')
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
header(header: string, defaultValue?: any): any;
|
|
199
|
+
/**
|
|
200
|
+
* Get a value from the request body or return
|
|
201
|
+
* the default value.
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* const name = request.input('name', 'lenon')
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
input(key: string, defaultValue?: any): any;
|
|
209
|
+
/**
|
|
210
|
+
* Get a value from the request body or return
|
|
211
|
+
* the default value.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```ts
|
|
215
|
+
* const name = request.payload('name', 'lenon')
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
payload(key: string, defaultValue?: any): any;
|
|
219
|
+
/**
|
|
220
|
+
* Get only the selected values from the request body.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* const body = request.only(['name', 'email'])
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
only(keys: string[]): any;
|
|
228
|
+
/**
|
|
229
|
+
* Get all the values from the request body except the
|
|
230
|
+
* selected ones.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* const body = request.except(['name'])
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
except(keys: string[]): any;
|
|
238
|
+
/**
|
|
239
|
+
* Get the original fastify request.
|
|
240
|
+
*/
|
|
241
|
+
getFastifyRequest(): FastifyRequest;
|
|
242
|
+
/**
|
|
243
|
+
* Add the hostname and port to the url.
|
|
244
|
+
*/
|
|
245
|
+
private getHostUrlFor;
|
|
246
|
+
/**
|
|
247
|
+
* Get the address info of the server. This method will return the
|
|
248
|
+
* port used to listen the server, the family (IPv4, IPv6) and the
|
|
249
|
+
* server address (127.0.0.1).
|
|
250
|
+
*/
|
|
251
|
+
private getAddressInfo;
|
|
252
|
+
}
|