@athenna/http 4.4.0 → 4.6.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 +30 -31
- package/src/annotations/Controller.js +1 -1
- package/src/annotations/Interceptor.js +1 -1
- package/src/annotations/Middleware.js +1 -1
- package/src/annotations/Terminator.js +1 -1
- package/src/commands/MakeControllerCommand.js +1 -1
- package/src/commands/MakeInterceptorCommand.js +1 -1
- package/src/commands/MakeMiddlewareCommand.js +1 -1
- package/src/commands/MakeTerminatorCommand.js +1 -1
- package/src/commands/RouteListCommand.js +1 -1
- package/src/exceptions/HttpException.js +1 -1
- package/src/exceptions/UndefinedMethodException.js +1 -1
- package/src/handlers/FastifyHandler.js +4 -4
- package/src/handlers/HttpExceptionHandler.js +1 -1
- package/src/kernels/HttpKernel.js +6 -6
- package/src/router/Route.js +8 -8
- package/src/server/ServerImpl.js +4 -4
- package/src/testing/plugins/request/TestRequest.d.ts +1 -1
- package/src/types/index.d.ts +2 -0
- package/src/types/index.js +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/http",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.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>",
|
|
@@ -70,13 +70,13 @@
|
|
|
70
70
|
"fastify": "^4.21.0"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@athenna/artisan": "^4.
|
|
74
|
-
"@athenna/common": "^4.
|
|
75
|
-
"@athenna/config": "^4.
|
|
76
|
-
"@athenna/ioc": "^4.
|
|
77
|
-
"@athenna/logger": "^4.
|
|
78
|
-
"@athenna/test": "^4.
|
|
79
|
-
"@athenna/view": "^4.
|
|
73
|
+
"@athenna/artisan": "^4.9.0",
|
|
74
|
+
"@athenna/common": "^4.10.1",
|
|
75
|
+
"@athenna/config": "^4.4.0",
|
|
76
|
+
"@athenna/ioc": "^4.2.0",
|
|
77
|
+
"@athenna/logger": "^4.3.0",
|
|
78
|
+
"@athenna/test": "^4.5.0",
|
|
79
|
+
"@athenna/view": "^4.2.0",
|
|
80
80
|
"@fastify/cors": "^8.1.1",
|
|
81
81
|
"@fastify/helmet": "^10.0.2",
|
|
82
82
|
"@fastify/rate-limit": "^7.5.0",
|
|
@@ -86,7 +86,6 @@
|
|
|
86
86
|
"@typescript-eslint/parser": "^5.56.0",
|
|
87
87
|
"c8": "^7.12.0",
|
|
88
88
|
"commitizen": "^4.2.6",
|
|
89
|
-
"cross-env": "^7.0.3",
|
|
90
89
|
"cz-conventional-changelog": "^3.3.0",
|
|
91
90
|
"eslint": "^8.36.0",
|
|
92
91
|
"eslint-config-prettier": "^8.8.0",
|
|
@@ -142,7 +141,7 @@
|
|
|
142
141
|
},
|
|
143
142
|
"prettier": {
|
|
144
143
|
"singleQuote": true,
|
|
145
|
-
"trailingComma": "
|
|
144
|
+
"trailingComma": "none",
|
|
146
145
|
"arrowParens": "avoid",
|
|
147
146
|
"endOfLine": "lf",
|
|
148
147
|
"semi": false,
|
|
@@ -209,37 +208,37 @@
|
|
|
209
208
|
"services": [],
|
|
210
209
|
"providers": [],
|
|
211
210
|
"controllers": [
|
|
212
|
-
"#tests/
|
|
213
|
-
"#tests/
|
|
211
|
+
"#tests/fixtures/controllers/HelloController",
|
|
212
|
+
"#tests/fixtures/controllers/DecoratedController"
|
|
214
213
|
],
|
|
215
214
|
"middlewares": [
|
|
216
|
-
"#tests/
|
|
217
|
-
"#tests/
|
|
218
|
-
"#tests/
|
|
219
|
-
"#tests/
|
|
220
|
-
"#tests/
|
|
215
|
+
"#tests/fixtures/middlewares/Middleware",
|
|
216
|
+
"#tests/fixtures/middlewares/ImportedMiddleware",
|
|
217
|
+
"#tests/fixtures/middlewares/DecoratedMiddleware",
|
|
218
|
+
"#tests/fixtures/middlewares/DecoratedInterceptor",
|
|
219
|
+
"#tests/fixtures/middlewares/DecoratedTerminator"
|
|
221
220
|
],
|
|
222
221
|
"namedMiddlewares": {
|
|
223
|
-
"middleware": "#tests/
|
|
224
|
-
"interceptor": "#tests/
|
|
225
|
-
"terminator": "#tests/
|
|
226
|
-
"not-found-middleware": "#tests/
|
|
227
|
-
"not-found-interceptor": "#tests/
|
|
228
|
-
"not-found-terminator": "#tests/
|
|
222
|
+
"middleware": "#tests/fixtures/middlewares/Middleware",
|
|
223
|
+
"interceptor": "#tests/fixtures/middlewares/Interceptor",
|
|
224
|
+
"terminator": "#tests/fixtures/middlewares/Terminator",
|
|
225
|
+
"not-found-middleware": "#tests/fixtures/middlewares/DecoratedMiddleware",
|
|
226
|
+
"not-found-interceptor": "#tests/fixtures/middlewares/DecoratedInterceptor",
|
|
227
|
+
"not-found-terminator": "#tests/fixtures/middlewares/DecoratedTerminator"
|
|
229
228
|
},
|
|
230
229
|
"globalMiddlewares": [
|
|
231
|
-
"#tests/
|
|
232
|
-
"#tests/
|
|
233
|
-
"#tests/
|
|
234
|
-
"#tests/
|
|
235
|
-
"#tests/
|
|
236
|
-
"#tests/
|
|
230
|
+
"#tests/fixtures/middlewares/Middleware",
|
|
231
|
+
"#tests/fixtures/middlewares/Interceptor",
|
|
232
|
+
"#tests/fixtures/middlewares/Terminator",
|
|
233
|
+
"#tests/fixtures/middlewares/DecoratedGlobalMiddleware",
|
|
234
|
+
"#tests/fixtures/middlewares/DecoratedGlobalInterceptor",
|
|
235
|
+
"#tests/fixtures/middlewares/DecoratedGlobalTerminator"
|
|
237
236
|
],
|
|
238
237
|
"commands": {
|
|
239
238
|
"route:list": {
|
|
240
239
|
"path": "#src/commands/RouteListCommand",
|
|
241
|
-
"route": "./tests/
|
|
242
|
-
"kernel": "./tests/
|
|
240
|
+
"route": "./tests/fixtures/routes/http.js",
|
|
241
|
+
"kernel": "./tests/fixtures/kernels/HttpKernel.js"
|
|
243
242
|
},
|
|
244
243
|
"make:controller": "#src/commands/MakeControllerCommand",
|
|
245
244
|
"make:interceptor": "#src/commands/MakeInterceptorCommand",
|
|
@@ -16,7 +16,7 @@ export function Controller(options) {
|
|
|
16
16
|
return (target) => {
|
|
17
17
|
options = Options.create(options, {
|
|
18
18
|
alias: `App/Http/Controllers/${target.name}`,
|
|
19
|
-
type: 'transient'
|
|
19
|
+
type: 'transient'
|
|
20
20
|
});
|
|
21
21
|
const alias = options.alias;
|
|
22
22
|
const createCamelAlias = false;
|
|
@@ -19,7 +19,7 @@ export function Interceptor(options) {
|
|
|
19
19
|
isGlobal: false,
|
|
20
20
|
name: String.toCamelCase(target.name),
|
|
21
21
|
alias: `App/Http/Interceptors/${target.name}`,
|
|
22
|
-
type: 'transient'
|
|
22
|
+
type: 'transient'
|
|
23
23
|
});
|
|
24
24
|
const alias = options.alias;
|
|
25
25
|
const createCamelAlias = false;
|
|
@@ -19,7 +19,7 @@ export function Middleware(options) {
|
|
|
19
19
|
isGlobal: false,
|
|
20
20
|
name: String.toCamelCase(target.name),
|
|
21
21
|
alias: `App/Http/Middlewares/${target.name}`,
|
|
22
|
-
type: 'transient'
|
|
22
|
+
type: 'transient'
|
|
23
23
|
});
|
|
24
24
|
const alias = options.alias;
|
|
25
25
|
const createCamelAlias = false;
|
|
@@ -19,7 +19,7 @@ export function Terminator(options) {
|
|
|
19
19
|
isGlobal: false,
|
|
20
20
|
name: String.toCamelCase(target.name),
|
|
21
21
|
alias: `App/Http/Terminators/${target.name}`,
|
|
22
|
-
type: 'transient'
|
|
22
|
+
type: 'transient'
|
|
23
23
|
});
|
|
24
24
|
const alias = options.alias;
|
|
25
25
|
const createCamelAlias = false;
|
|
@@ -13,7 +13,7 @@ export class UndefinedMethodException extends Exception {
|
|
|
13
13
|
status: 500,
|
|
14
14
|
code: 'E_UNDEFINED_METHOD',
|
|
15
15
|
message: `Cannot register the ${method} method in your Route because it's not defined inside your ${className} class.`,
|
|
16
|
-
help: `Remember defining the method ${method} inside your ${className} class
|
|
16
|
+
help: `Remember defining the method ${method} inside your ${className} class.`
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -28,7 +28,7 @@ export class FastifyHandler {
|
|
|
28
28
|
body: req.body,
|
|
29
29
|
params: req.params,
|
|
30
30
|
queries: req.query,
|
|
31
|
-
headers: req.headers
|
|
31
|
+
headers: req.headers
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
}
|
|
@@ -57,7 +57,7 @@ export class FastifyHandler {
|
|
|
57
57
|
body: res.body,
|
|
58
58
|
params: req.params,
|
|
59
59
|
queries: req.query,
|
|
60
|
-
headers: req.headers
|
|
60
|
+
headers: req.headers
|
|
61
61
|
});
|
|
62
62
|
res.body = payload;
|
|
63
63
|
if (Is.Object(payload)) {
|
|
@@ -82,7 +82,7 @@ export class FastifyHandler {
|
|
|
82
82
|
body: res.body || req.body,
|
|
83
83
|
headers: res.getHeaders(),
|
|
84
84
|
status: res.statusCode,
|
|
85
|
-
responseTime: res.getResponseTime()
|
|
85
|
+
responseTime: res.getResponseTime()
|
|
86
86
|
});
|
|
87
87
|
};
|
|
88
88
|
}
|
|
@@ -101,7 +101,7 @@ export class FastifyHandler {
|
|
|
101
101
|
params: req.params,
|
|
102
102
|
queries: req.query,
|
|
103
103
|
headers: req.headers,
|
|
104
|
-
error
|
|
104
|
+
error
|
|
105
105
|
});
|
|
106
106
|
};
|
|
107
107
|
}
|
|
@@ -30,7 +30,7 @@ export class HttpExceptionHandler {
|
|
|
30
30
|
code: String.toSnakeCase(error.code || error.name).toUpperCase(),
|
|
31
31
|
name: Json.copy(error.name),
|
|
32
32
|
message: Json.copy(error.message),
|
|
33
|
-
stack: Json.copy(error.stack)
|
|
33
|
+
stack: Json.copy(error.stack)
|
|
34
34
|
};
|
|
35
35
|
if (error.help) {
|
|
36
36
|
body.help = Json.copy(error.help);
|
|
@@ -198,19 +198,19 @@ export class HttpKernel {
|
|
|
198
198
|
if (middleware.handle) {
|
|
199
199
|
return {
|
|
200
200
|
alias: `App/Http/Middlewares/${Middleware.name}`,
|
|
201
|
-
namedAlias: `App/Http/Middlewares/Names/${name}
|
|
201
|
+
namedAlias: `App/Http/Middlewares/Names/${name}`
|
|
202
202
|
};
|
|
203
203
|
}
|
|
204
204
|
if (middleware.intercept) {
|
|
205
205
|
return {
|
|
206
206
|
alias: `App/Http/Interceptors/${Middleware.name}`,
|
|
207
|
-
namedAlias: `App/Http/Interceptors/Names/${name}
|
|
207
|
+
namedAlias: `App/Http/Interceptors/Names/${name}`
|
|
208
208
|
};
|
|
209
209
|
}
|
|
210
210
|
if (middleware.terminate) {
|
|
211
211
|
return {
|
|
212
212
|
alias: `App/Http/Terminators/${Middleware.name}`,
|
|
213
|
-
namedAlias: `App/Http/Terminators/Names/${name}
|
|
213
|
+
namedAlias: `App/Http/Terminators/Names/${name}`
|
|
214
214
|
};
|
|
215
215
|
}
|
|
216
216
|
}
|
|
@@ -224,21 +224,21 @@ export class HttpKernel {
|
|
|
224
224
|
return {
|
|
225
225
|
handler: 'handle',
|
|
226
226
|
serverMethod: 'middleware',
|
|
227
|
-
alias: `App/Http/Middlewares/${Middleware.name}
|
|
227
|
+
alias: `App/Http/Middlewares/${Middleware.name}`
|
|
228
228
|
};
|
|
229
229
|
}
|
|
230
230
|
if (middleware.intercept) {
|
|
231
231
|
return {
|
|
232
232
|
handler: 'intercept',
|
|
233
233
|
serverMethod: 'intercept',
|
|
234
|
-
alias: `App/Http/Interceptors/${Middleware.name}
|
|
234
|
+
alias: `App/Http/Interceptors/${Middleware.name}`
|
|
235
235
|
};
|
|
236
236
|
}
|
|
237
237
|
if (middleware.terminate) {
|
|
238
238
|
return {
|
|
239
239
|
handler: 'terminate',
|
|
240
240
|
serverMethod: 'terminate',
|
|
241
|
-
alias: `App/Http/Terminators/${Middleware.name}
|
|
241
|
+
alias: `App/Http/Terminators/${Middleware.name}`
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
244
|
}
|
package/src/router/Route.js
CHANGED
|
@@ -18,9 +18,9 @@ export class Route {
|
|
|
18
18
|
middlewares: {
|
|
19
19
|
middlewares: [],
|
|
20
20
|
terminators: [],
|
|
21
|
-
interceptors: []
|
|
21
|
+
interceptors: []
|
|
22
22
|
},
|
|
23
|
-
fastify: { schema: {} }
|
|
23
|
+
fastify: { schema: {} }
|
|
24
24
|
};
|
|
25
25
|
if (Is.String(handler)) {
|
|
26
26
|
const [controller, method] = handler.split('.');
|
|
@@ -58,7 +58,7 @@ export class Route {
|
|
|
58
58
|
vanillaOptions(options) {
|
|
59
59
|
this.route.fastify = {
|
|
60
60
|
...this.route.fastify,
|
|
61
|
-
...options
|
|
61
|
+
...options
|
|
62
62
|
};
|
|
63
63
|
return this;
|
|
64
64
|
}
|
|
@@ -262,7 +262,7 @@ export class Route {
|
|
|
262
262
|
if (!this.route.fastify.schema.body) {
|
|
263
263
|
this.route.fastify.schema.body = {
|
|
264
264
|
type: 'object',
|
|
265
|
-
properties: {}
|
|
265
|
+
properties: {}
|
|
266
266
|
};
|
|
267
267
|
}
|
|
268
268
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -282,7 +282,7 @@ export class Route {
|
|
|
282
282
|
if (!this.route.fastify.schema.params) {
|
|
283
283
|
this.route.fastify.schema.params = {
|
|
284
284
|
type: 'object',
|
|
285
|
-
properties: {}
|
|
285
|
+
properties: {}
|
|
286
286
|
};
|
|
287
287
|
}
|
|
288
288
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -302,7 +302,7 @@ export class Route {
|
|
|
302
302
|
if (!this.route.fastify.schema.querystring) {
|
|
303
303
|
this.route.fastify.schema.querystring = {
|
|
304
304
|
type: 'object',
|
|
305
|
-
properties: {}
|
|
305
|
+
properties: {}
|
|
306
306
|
};
|
|
307
307
|
}
|
|
308
308
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -371,7 +371,7 @@ export class Route {
|
|
|
371
371
|
if (!this.route.fastify.schema.externalDocs) {
|
|
372
372
|
this.route.fastify.schema.externalDocs = {
|
|
373
373
|
url: '',
|
|
374
|
-
description: ''
|
|
374
|
+
description: ''
|
|
375
375
|
};
|
|
376
376
|
}
|
|
377
377
|
this.route.fastify.schema.externalDocs.url = url;
|
|
@@ -419,7 +419,7 @@ export class Route {
|
|
|
419
419
|
prefixes: this.route.prefixes,
|
|
420
420
|
handler: this.route.handler,
|
|
421
421
|
middlewares: this.route.middlewares,
|
|
422
|
-
fastify: this.route.fastify
|
|
422
|
+
fastify: this.route.fastify
|
|
423
423
|
};
|
|
424
424
|
}
|
|
425
425
|
getUrl() {
|
package/src/server/ServerImpl.js
CHANGED
|
@@ -136,7 +136,7 @@ export class ServerImpl {
|
|
|
136
136
|
options.middlewares = Options.create(options.middlewares, {
|
|
137
137
|
middlewares: [],
|
|
138
138
|
terminators: [],
|
|
139
|
-
interceptors: []
|
|
139
|
+
interceptors: []
|
|
140
140
|
});
|
|
141
141
|
if (options.methods.length === 2 && options.methods.includes('HEAD')) {
|
|
142
142
|
this.route({ ...options, methods: ['GET'] });
|
|
@@ -145,8 +145,8 @@ export class ServerImpl {
|
|
|
145
145
|
methods: ['HEAD'],
|
|
146
146
|
fastify: {
|
|
147
147
|
...options.fastify,
|
|
148
|
-
schema: { ...options.fastify.schema, hide: true }
|
|
149
|
-
}
|
|
148
|
+
schema: { ...options.fastify.schema, hide: true }
|
|
149
|
+
}
|
|
150
150
|
});
|
|
151
151
|
return;
|
|
152
152
|
}
|
|
@@ -159,7 +159,7 @@ export class ServerImpl {
|
|
|
159
159
|
preHandler: options.middlewares.middlewares.map(m => FastifyHandler.handle(m)),
|
|
160
160
|
onSend: options.middlewares.interceptors.map(m => FastifyHandler.intercept(m)),
|
|
161
161
|
onResponse: options.middlewares.terminators.map(m => FastifyHandler.terminate(m)),
|
|
162
|
-
...options.fastify
|
|
162
|
+
...options.fastify
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
165
|
/**
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import { Assert } from '@japa/assert';
|
|
10
|
-
import type { InjectOptions } from '
|
|
10
|
+
import type { InjectOptions } from '#src/types';
|
|
11
11
|
import { TestResponse } from '#src/testing/plugins/request/TestResponse';
|
|
12
12
|
export declare class TestRequest {
|
|
13
13
|
/**
|
package/src/types/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
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
|
+
import { type InjectOptions } from 'fastify';
|
|
10
|
+
export { type InjectOptions };
|
|
9
11
|
export * from '#src/types/contexts/Context';
|
|
10
12
|
export * from '#src/types/contexts/ErrorContext';
|
|
11
13
|
export * from '#src/types/contexts/InterceptContext';
|
package/src/types/index.js
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
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
|
+
import {} from 'fastify';
|
|
10
|
+
export {};
|
|
9
11
|
export * from '#src/types/contexts/Context';
|
|
10
12
|
export * from '#src/types/contexts/ErrorContext';
|
|
11
13
|
export * from '#src/types/contexts/InterceptContext';
|