@athenna/http 3.11.0 → 4.0.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 +238 -234
- package/src/{Decorators → annotations}/Controller.d.ts +1 -1
- package/src/{Decorators → annotations}/Controller.js +2 -0
- package/src/{Decorators → annotations}/Interceptor.d.ts +2 -2
- package/src/{Decorators → annotations}/Interceptor.js +5 -2
- package/src/{Decorators → annotations}/Middleware.d.ts +1 -1
- package/src/{Decorators → annotations}/Middleware.js +4 -1
- package/src/{Decorators → annotations}/Terminator.d.ts +2 -2
- package/src/{Decorators → annotations}/Terminator.js +5 -2
- package/src/{Commands → commands}/MakeControllerCommand.js +0 -1
- package/src/{Commands → commands}/MakeInterceptorCommand.js +0 -1
- package/src/{Commands → commands}/MakeMiddlewareCommand.js +0 -1
- package/src/{Commands → commands}/MakeTerminatorCommand.js +0 -1
- package/src/{Context → context}/Request.d.ts +1 -1
- package/src/{Context → context}/Request.js +0 -4
- package/src/{Context → context}/Response.d.ts +2 -2
- package/src/{Context → context}/Response.js +0 -4
- package/src/debug/index.d.ts +10 -0
- package/src/debug/index.js +10 -0
- package/src/{Exceptions → exceptions}/BadGatewayException.d.ts +1 -1
- package/src/{Exceptions → exceptions}/BadGatewayException.js +1 -1
- package/src/{Exceptions → exceptions}/BadRequestException.d.ts +1 -1
- package/src/{Exceptions → exceptions}/BadRequestException.js +1 -1
- package/src/{Exceptions → exceptions}/ForbiddenException.d.ts +1 -1
- package/src/{Exceptions → exceptions}/ForbiddenException.js +1 -1
- package/src/{Exceptions → exceptions}/HttpException.d.ts +3 -2
- package/src/{Exceptions → exceptions}/InternalServerException.d.ts +1 -1
- package/src/{Exceptions → exceptions}/InternalServerException.js +1 -1
- package/src/{Exceptions → exceptions}/MethodNotAllowedException.d.ts +1 -1
- package/src/{Exceptions → exceptions}/MethodNotAllowedException.js +1 -1
- package/src/{Exceptions → exceptions}/NotAcceptableException.d.ts +1 -1
- package/src/{Exceptions → exceptions}/NotAcceptableException.js +1 -1
- package/src/{Exceptions → exceptions}/NotFoundException.d.ts +1 -1
- package/src/{Exceptions → exceptions}/NotFoundException.js +1 -1
- package/src/{Exceptions → exceptions}/NotImplementedException.d.ts +1 -1
- package/src/{Exceptions → exceptions}/NotImplementedException.js +1 -1
- package/src/{Exceptions → exceptions}/PayloadTooLargeException.d.ts +1 -1
- package/src/{Exceptions → exceptions}/PayloadTooLargeException.js +1 -1
- package/src/{Exceptions → exceptions}/RequestTimeoutException.d.ts +1 -1
- package/src/{Exceptions → exceptions}/RequestTimeoutException.js +1 -1
- package/src/{Exceptions → exceptions}/ServiceUnavailableException.d.ts +1 -1
- package/src/{Exceptions → exceptions}/ServiceUnavailableException.js +1 -1
- package/src/{Exceptions → exceptions}/UnauthorizedException.d.ts +1 -1
- package/src/{Exceptions → exceptions}/UnauthorizedException.js +1 -1
- package/src/{Exceptions → exceptions}/UnprocessableEntityException.d.ts +1 -1
- package/src/{Exceptions → exceptions}/UnprocessableEntityException.js +1 -1
- package/src/{Facades → facades}/Route.d.ts +2 -2
- package/src/{Facades → facades}/Server.d.ts +2 -2
- package/src/{Handlers → handlers}/FastifyHandler.d.ts +4 -4
- package/src/{Handlers → handlers}/FastifyHandler.js +2 -2
- package/src/{Handlers → handlers}/HttpExceptionHandler.d.ts +1 -1
- package/src/{Handlers → handlers}/HttpExceptionHandler.js +6 -6
- package/src/index.d.ts +32 -40
- package/src/index.js +32 -40
- package/src/{Kernels → kernels}/HttpKernel.js +14 -1
- package/src/{Providers → providers}/HttpRouteProvider.js +1 -1
- package/src/{Providers → providers}/HttpServerProvider.js +1 -1
- package/src/{Router → router}/Route.d.ts +3 -9
- package/src/{Router → router}/Route.js +1 -5
- package/src/{Router → router}/RouteGroup.d.ts +3 -5
- package/src/{Router → router}/RouteGroup.js +2 -6
- package/src/{Router → router}/RouteResource.d.ts +2 -5
- package/src/{Router → router}/RouteResource.js +5 -13
- package/src/{Router → router}/Router.d.ts +7 -9
- package/src/{Router → router}/Router.js +15 -17
- package/src/{Server → server}/ServerImpl.d.ts +11 -14
- package/src/{Server → server}/ServerImpl.js +1 -9
- package/src/{Testing/Plugins → testing/plugins}/index.d.ts +5 -5
- package/src/{Testing/Plugins → testing/plugins}/index.js +5 -5
- package/src/{Testing/Plugins/Request → testing/plugins/request}/TestRequest.d.ts +2 -2
- package/src/{Testing/Plugins/Request → testing/plugins/request}/TestRequest.js +7 -5
- package/src/{Testing/Plugins/Request → testing/plugins/request}/TestResponse.d.ts +1 -1
- package/src/{Testing/Plugins/Request → testing/plugins/request}/TestResponse.js +1 -8
- package/src/{Types/Contexts → types/contexts}/Context.d.ts +2 -2
- package/src/types/contexts/Context.js +10 -0
- package/src/{Types/Contexts → types/contexts}/ErrorContext.d.ts +2 -2
- package/src/{Types/Contexts → types/contexts}/ErrorContext.js +2 -1
- package/src/{Types/Contexts → types/contexts}/InterceptContext.d.ts +2 -2
- package/src/{Types/Contexts → types/contexts}/InterceptContext.js +2 -1
- package/src/{Types/Contexts → types/contexts}/TerminateContext.d.ts +2 -2
- package/src/{Types/Contexts → types/contexts}/TerminateContext.js +2 -1
- package/src/{Contracts → types/contracts}/InterceptorContract.d.ts +1 -1
- package/src/{Contracts → types/contracts}/MiddlewareContract.d.ts +1 -1
- package/src/{Contracts → types/contracts}/TerminatorContract.d.ts +1 -1
- package/src/types/index.d.ts +24 -0
- package/src/types/index.js +24 -0
- package/src/{Types/Middlewares → types/middlewares}/InterceptorRouteType.d.ts +2 -2
- package/src/{Types/Middlewares → types/middlewares}/MiddlewareHandler.d.ts +3 -3
- package/src/{Types/Middlewares → types/middlewares}/MiddlewareRouteType.d.ts +2 -2
- package/src/{Types/Middlewares → types/middlewares}/TerminatorRouteType.d.ts +2 -2
- package/src/{Types/Router → types/router}/RouteHandler.d.ts +1 -1
- package/src/{Types/Router/RouteJSON.d.ts → types/router/RouteJson.d.ts} +3 -4
- package/src/Types/Router/RouteJSON.js +0 -9
- package/templates/controller.edge +0 -24
- package/templates/interceptor.edge +0 -8
- package/templates/middleware.edge +0 -6
- package/templates/terminator.edge +0 -6
- /package/src/{Commands → commands}/MakeControllerCommand.d.ts +0 -0
- /package/src/{Commands → commands}/MakeInterceptorCommand.d.ts +0 -0
- /package/src/{Commands → commands}/MakeMiddlewareCommand.d.ts +0 -0
- /package/src/{Commands → commands}/MakeTerminatorCommand.d.ts +0 -0
- /package/src/{Commands → commands}/RouteListCommand.d.ts +0 -0
- /package/src/{Commands → commands}/RouteListCommand.js +0 -0
- /package/src/{Exceptions → exceptions}/HttpException.js +0 -0
- /package/src/{Exceptions → exceptions}/UndefinedMethodException.d.ts +0 -0
- /package/src/{Exceptions → exceptions}/UndefinedMethodException.js +0 -0
- /package/src/{Facades → facades}/Route.js +0 -0
- /package/src/{Facades → facades}/Server.js +0 -0
- /package/src/{Kernels → kernels}/HttpKernel.d.ts +0 -0
- /package/src/{Providers → providers}/HttpRouteProvider.d.ts +0 -0
- /package/src/{Providers → providers}/HttpServerProvider.d.ts +0 -0
- /package/src/{Contracts → types/contracts}/InterceptorContract.js +0 -0
- /package/src/{Contracts → types/contracts}/MiddlewareContract.js +0 -0
- /package/src/{Contracts → types/contracts}/TerminatorContract.js +0 -0
- /package/src/{Types/Controllers → types/controllers}/ControllerOptions.d.ts +0 -0
- /package/src/{Types/Controllers → types/controllers}/ControllerOptions.js +0 -0
- /package/src/{Types/Middlewares → types/middlewares}/InterceptorRouteType.js +0 -0
- /package/src/{Types/Middlewares → types/middlewares}/MiddlewareHandler.js +0 -0
- /package/src/{Types/Middlewares → types/middlewares}/MiddlewareOptions.d.ts +0 -0
- /package/src/{Types/Middlewares → types/middlewares}/MiddlewareOptions.js +0 -0
- /package/src/{Types/Middlewares → types/middlewares}/MiddlewareRouteType.js +0 -0
- /package/src/{Types/Middlewares → types/middlewares}/TerminatorRouteType.js +0 -0
- /package/src/{Types/Router → types/router}/RouteHandler.js +0 -0
- /package/src/{Types/Contexts/Context.js → types/router/RouteJson.js} +0 -0
- /package/src/{Types/Router → types/router}/RouteResourceTypes.d.ts +0 -0
- /package/src/{Types/Router → types/router}/RouteResourceTypes.js +0 -0
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import 'reflect-metadata';
|
|
10
10
|
import { Server } from '#src';
|
|
11
|
+
import { debug } from '#src/debug';
|
|
11
12
|
import { Log } from '@athenna/logger';
|
|
12
13
|
import { Config } from '@athenna/config';
|
|
13
14
|
import { isAbsolute, resolve } from 'node:path';
|
|
14
15
|
import { File, Exec, Is, Module } from '@athenna/common';
|
|
15
|
-
import { HttpExceptionHandler } from '#src/
|
|
16
|
+
import { HttpExceptionHandler } from '#src/handlers/HttpExceptionHandler';
|
|
16
17
|
const corsPlugin = await Module.safeImport('@fastify/cors');
|
|
17
18
|
const helmetPlugin = await Module.safeImport('@fastify/helmet');
|
|
18
19
|
const swaggerPlugin = await Module.safeImport('@fastify/swagger');
|
|
@@ -25,6 +26,7 @@ export class HttpKernel {
|
|
|
25
26
|
*/
|
|
26
27
|
async registerCors() {
|
|
27
28
|
if (!corsPlugin) {
|
|
29
|
+
debug('Not able to register cors plugin. Install @fastify/cors package.');
|
|
28
30
|
return;
|
|
29
31
|
}
|
|
30
32
|
await Server.plugin(corsPlugin, Config.get('http.cors'));
|
|
@@ -34,6 +36,7 @@ export class HttpKernel {
|
|
|
34
36
|
*/
|
|
35
37
|
async registerHelmet() {
|
|
36
38
|
if (!helmetPlugin) {
|
|
39
|
+
debug('Not able to register helmet plugin. Install @fastify/helmet package.');
|
|
37
40
|
return;
|
|
38
41
|
}
|
|
39
42
|
await Server.plugin(helmetPlugin, Config.get('http.helmet'));
|
|
@@ -43,9 +46,11 @@ export class HttpKernel {
|
|
|
43
46
|
*/
|
|
44
47
|
async registerSwagger() {
|
|
45
48
|
if (swaggerPlugin) {
|
|
49
|
+
debug('Not able to register swagger plugin. Install @fastify/swagger package.');
|
|
46
50
|
await Server.plugin(swaggerPlugin, Config.get('http.swagger.configurations'));
|
|
47
51
|
}
|
|
48
52
|
if (swaggerUiPlugin) {
|
|
53
|
+
debug('Not able to register swagger-ui plugin. Install @fastify/swagger-ui package.');
|
|
49
54
|
await Server.plugin(swaggerUiPlugin, Config.get('http.swagger.ui'));
|
|
50
55
|
}
|
|
51
56
|
}
|
|
@@ -54,6 +59,7 @@ export class HttpKernel {
|
|
|
54
59
|
*/
|
|
55
60
|
async registerRateLimit() {
|
|
56
61
|
if (!rateLimitPlugin) {
|
|
62
|
+
debug('Not able to register rate limit plugin. Install @fastify/rate-limit package.');
|
|
57
63
|
return;
|
|
58
64
|
}
|
|
59
65
|
await Server.plugin(rateLimitPlugin, Config.get('http.rateLimit'));
|
|
@@ -66,6 +72,7 @@ export class HttpKernel {
|
|
|
66
72
|
return;
|
|
67
73
|
}
|
|
68
74
|
if (!rTracerPlugin) {
|
|
75
|
+
debug('Not able to register tracer plugin. Install cls-rtracer package.');
|
|
69
76
|
return;
|
|
70
77
|
}
|
|
71
78
|
Server.middleware(async (ctx) => (ctx.data.traceId = rTracerPlugin.id()));
|
|
@@ -77,6 +84,7 @@ export class HttpKernel {
|
|
|
77
84
|
async registerLoggerTerminator() {
|
|
78
85
|
if (!Config.exists('http.logger.enabled') ||
|
|
79
86
|
Config.is('http.logger.enabled', false)) {
|
|
87
|
+
debug('Not able to register http request logger. Enable it in your http.logger.enabled configuration.');
|
|
80
88
|
return;
|
|
81
89
|
}
|
|
82
90
|
Server.terminate(ctx => Log.channelOrVanilla('request').info(ctx));
|
|
@@ -90,6 +98,7 @@ export class HttpKernel {
|
|
|
90
98
|
await Exec.concurrently(controllers, async (path) => {
|
|
91
99
|
const Controller = await this.resolvePath(path);
|
|
92
100
|
if (Reflect.hasMetadata('provider:registered', Controller)) {
|
|
101
|
+
debug('Controller %s already registered by Controller annotation. Skipping registration via HttpKernel.', Controller.name);
|
|
93
102
|
return;
|
|
94
103
|
}
|
|
95
104
|
const createCamelAlias = false;
|
|
@@ -121,6 +130,7 @@ export class HttpKernel {
|
|
|
121
130
|
await Exec.concurrently(Object.keys(namedMiddlewares), async (key) => {
|
|
122
131
|
const Middleware = await this.resolvePath(namedMiddlewares[key]);
|
|
123
132
|
if (Reflect.hasMetadata('provider:registered', Middleware)) {
|
|
133
|
+
debug('Named middleware %s already registered by Middleware annotation. Skipping registration via HttpKernel.', Middleware.name);
|
|
124
134
|
return;
|
|
125
135
|
}
|
|
126
136
|
const createCamelAlias = false;
|
|
@@ -140,6 +150,7 @@ export class HttpKernel {
|
|
|
140
150
|
await Exec.concurrently(globalMiddlewares, async (path) => {
|
|
141
151
|
const Middleware = await this.resolvePath(path);
|
|
142
152
|
if (Reflect.hasMetadata('provider:registered', Middleware)) {
|
|
153
|
+
debug('Global middleware %s already registered by Middleware annotation. Skipping registration via HttpKernel.', Middleware.name);
|
|
143
154
|
return;
|
|
144
155
|
}
|
|
145
156
|
const createCamelAlias = false;
|
|
@@ -153,11 +164,13 @@ export class HttpKernel {
|
|
|
153
164
|
*/
|
|
154
165
|
async registerExceptionHandler(path) {
|
|
155
166
|
if (!path) {
|
|
167
|
+
debug('No custom exception handler path provided for HttpKernel. Using the default one.');
|
|
156
168
|
const handler = new HttpExceptionHandler();
|
|
157
169
|
Server.setErrorHandler(handler.handle.bind(handler));
|
|
158
170
|
return;
|
|
159
171
|
}
|
|
160
172
|
const Handler = await this.resolvePath(path);
|
|
173
|
+
debug('Using custom exception handler %s in HttpKernel.', Handler.name);
|
|
161
174
|
const handler = new Handler();
|
|
162
175
|
Server.setErrorHandler(handler.handle.bind(handler));
|
|
163
176
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
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 { Router } from '#src/
|
|
9
|
+
import { Router } from '#src/router/Router';
|
|
10
10
|
import { ServiceProvider } from '@athenna/ioc';
|
|
11
11
|
export class HttpRouteProvider extends ServiceProvider {
|
|
12
12
|
register() {
|
|
@@ -6,8 +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 { ServerImpl } from '#src/Server/ServerImpl';
|
|
10
9
|
import { ServiceProvider } from '@athenna/ioc';
|
|
10
|
+
import { ServerImpl } from '#src/server/ServerImpl';
|
|
11
11
|
export class HttpServerProvider extends ServiceProvider {
|
|
12
12
|
register() {
|
|
13
13
|
this.container.instance('Athenna/Core/HttpServer', new ServerImpl(), false);
|
|
@@ -6,14 +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 {
|
|
10
|
-
import {
|
|
11
|
-
import { RouteHandler } from '#src/Types/Router/RouteHandler';
|
|
12
|
-
import { HTTPMethods, FastifySchema, RouteOptions } from 'fastify';
|
|
13
|
-
import { MiddlewareRecord } from '#src/Types/Middlewares/MiddlewareHandler';
|
|
14
|
-
import { MiddlewareRouteType } from '#src/Types/Middlewares/MiddlewareRouteType';
|
|
15
|
-
import { TerminatorRouteType } from '#src/Types/Middlewares/TerminatorRouteType';
|
|
16
|
-
import { InterceptorRouteType } from '#src/Types/Middlewares/InterceptorRouteType';
|
|
9
|
+
import type { RouteJson, RouteHandler, RequestHandler, MiddlewareRecord, MiddlewareRouteType, TerminatorRouteType, InterceptorRouteType } from '#src/types';
|
|
10
|
+
import type { HTTPMethods, FastifySchema, RouteOptions } from 'fastify';
|
|
17
11
|
export declare class Route {
|
|
18
12
|
/**
|
|
19
13
|
* Holds all the route implementations to be registered in the Server.
|
|
@@ -257,7 +251,7 @@ export declare class Route {
|
|
|
257
251
|
* Route.toJSON()
|
|
258
252
|
* ```
|
|
259
253
|
*/
|
|
260
|
-
toJSON():
|
|
254
|
+
toJSON(): RouteJson;
|
|
261
255
|
private getUrl;
|
|
262
256
|
private removeSlashes;
|
|
263
257
|
}
|
|
@@ -7,12 +7,8 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import { Is, Route as RouteHelper } from '@athenna/common';
|
|
10
|
-
import { UndefinedMethodException } from '#src/
|
|
10
|
+
import { UndefinedMethodException } from '#src/exceptions/UndefinedMethodException';
|
|
11
11
|
export class Route {
|
|
12
|
-
/**
|
|
13
|
-
* Holds all the route implementations to be registered in the Server.
|
|
14
|
-
*/
|
|
15
|
-
route;
|
|
16
12
|
constructor(url, methods, handler) {
|
|
17
13
|
this.route = {
|
|
18
14
|
url,
|
|
@@ -6,11 +6,9 @@
|
|
|
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 {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { TerminatorRouteType } from '#src/Types/Middlewares/TerminatorRouteType';
|
|
13
|
-
import { InterceptorRouteType } from '#src/Types/Middlewares/InterceptorRouteType';
|
|
9
|
+
import type { MiddlewareRouteType, TerminatorRouteType, InterceptorRouteType } from '#src/types';
|
|
10
|
+
import { Route } from '#src/router/Route';
|
|
11
|
+
import { RouteResource } from '#src/router/RouteResource';
|
|
14
12
|
export declare class RouteGroup {
|
|
15
13
|
/**
|
|
16
14
|
* All routes registered in the group.
|
|
@@ -6,13 +6,9 @@
|
|
|
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 {
|
|
9
|
+
import { Route } from '#src/router/Route';
|
|
10
|
+
import { RouteResource } from '#src/router/RouteResource';
|
|
10
11
|
export class RouteGroup {
|
|
11
|
-
/**
|
|
12
|
-
* All routes registered in the group.
|
|
13
|
-
*/
|
|
14
|
-
// eslint-disable-next-line no-use-before-define
|
|
15
|
-
routes;
|
|
16
12
|
constructor(routes) {
|
|
17
13
|
this.routes = routes;
|
|
18
14
|
}
|
|
@@ -6,11 +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 {
|
|
10
|
-
import {
|
|
11
|
-
import { MiddlewareRouteType } from '#src/Types/Middlewares/MiddlewareRouteType';
|
|
12
|
-
import { InterceptorRouteType } from '#src/Types/Middlewares/InterceptorRouteType';
|
|
13
|
-
import { RouteResourceTypes } from '#src/Types/Router/RouteResourceTypes';
|
|
9
|
+
import type { RouteResourceTypes, TerminatorRouteType, MiddlewareRouteType, InterceptorRouteType } from '#src/types';
|
|
10
|
+
import { Route } from '#src/router/Route';
|
|
14
11
|
export declare class RouteResource {
|
|
15
12
|
/**
|
|
16
13
|
* All routes registered in the resource.
|
|
@@ -6,22 +6,14 @@
|
|
|
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 { Route } from '#src/
|
|
9
|
+
import { Route } from '#src/router/Route';
|
|
10
10
|
import { Is, String } from '@athenna/common';
|
|
11
11
|
export class RouteResource {
|
|
12
|
-
/**
|
|
13
|
-
* All routes registered in the resource.
|
|
14
|
-
*/
|
|
15
|
-
routes = [];
|
|
16
|
-
/**
|
|
17
|
-
* The resource name.
|
|
18
|
-
*/
|
|
19
|
-
resource;
|
|
20
|
-
/**
|
|
21
|
-
* The resource controller.
|
|
22
|
-
*/
|
|
23
|
-
controller;
|
|
24
12
|
constructor(resource, controller) {
|
|
13
|
+
/**
|
|
14
|
+
* All routes registered in the resource.
|
|
15
|
+
*/
|
|
16
|
+
this.routes = [];
|
|
25
17
|
this.resource = resource;
|
|
26
18
|
this.controller = controller;
|
|
27
19
|
this.buildRoutes();
|
|
@@ -6,13 +6,11 @@
|
|
|
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 { Route } from '#src/
|
|
10
|
-
import { RouteGroup } from '#src/
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { RouteHandler } from '#src/Types/Router/RouteHandler';
|
|
15
|
-
import { HTTPMethods, FastifyInstance, RouteOptions } from 'fastify';
|
|
9
|
+
import { Route } from '#src/router/Route';
|
|
10
|
+
import { RouteGroup } from '#src/router/RouteGroup';
|
|
11
|
+
import { RouteResource } from '#src/router/RouteResource';
|
|
12
|
+
import type { RouteJson, RequestHandler, RouteHandler } from '#src/types';
|
|
13
|
+
import type { HTTPMethods, FastifyInstance, RouteOptions } from 'fastify';
|
|
16
14
|
export declare class Router {
|
|
17
15
|
/**
|
|
18
16
|
* All routes registered.
|
|
@@ -29,7 +27,7 @@ export declare class Router {
|
|
|
29
27
|
/**
|
|
30
28
|
* List the routes registered.
|
|
31
29
|
*/
|
|
32
|
-
list():
|
|
30
|
+
list(): RouteJson[];
|
|
33
31
|
/**
|
|
34
32
|
* Set the controller instance.
|
|
35
33
|
*/
|
|
@@ -91,7 +89,7 @@ export declare class Router {
|
|
|
91
89
|
/**
|
|
92
90
|
* Transform some route array to a route json array.
|
|
93
91
|
*/
|
|
94
|
-
toJSON(routes: (Route | RouteGroup | RouteResource)[]):
|
|
92
|
+
toJSON(routes: (Route | RouteGroup | RouteResource)[]): RouteJson[];
|
|
95
93
|
/**
|
|
96
94
|
* Get the most recent route group created.
|
|
97
95
|
*/
|
|
@@ -7,24 +7,22 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import { Is } from '@athenna/common';
|
|
10
|
-
import { Route } from '#src/
|
|
11
|
-
import { Server } from '#src/
|
|
12
|
-
import { RouteGroup } from '#src/
|
|
13
|
-
import { RouteResource } from '#src/
|
|
14
|
-
import { UndefinedMethodException } from '#src/
|
|
10
|
+
import { Route } from '#src/router/Route';
|
|
11
|
+
import { Server } from '#src/facades/Server';
|
|
12
|
+
import { RouteGroup } from '#src/router/RouteGroup';
|
|
13
|
+
import { RouteResource } from '#src/router/RouteResource';
|
|
14
|
+
import { UndefinedMethodException } from '#src/exceptions/UndefinedMethodException';
|
|
15
15
|
export class Router {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*/
|
|
27
|
-
controllerInstance;
|
|
16
|
+
constructor() {
|
|
17
|
+
/**
|
|
18
|
+
* All routes registered.
|
|
19
|
+
*/
|
|
20
|
+
this.routes = [];
|
|
21
|
+
/**
|
|
22
|
+
* Route groups opened.
|
|
23
|
+
*/
|
|
24
|
+
this.openedGroups = [];
|
|
25
|
+
}
|
|
28
26
|
/**
|
|
29
27
|
* List the routes registered.
|
|
30
28
|
*/
|
|
@@ -7,12 +7,9 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
/// <reference types="node" resolution-mode="require"/>
|
|
10
|
-
import { InjectOptions, FastifyInstance, PrintRoutesOptions, FastifyListenOptions, FastifyServerOptions, LightMyRequestChain, LightMyRequestResponse } from 'fastify';
|
|
11
|
-
import { InterceptHandler, TerminateHandler } from '#src/
|
|
12
|
-
import { AddressInfo } from 'node:net';
|
|
13
|
-
import { RouteJSON } from '#src/Types/Router/RouteJSON';
|
|
14
|
-
import { RequestHandler } from '#src/Types/Contexts/Context';
|
|
15
|
-
import { ErrorHandler } from '#src/Types/Contexts/ErrorContext';
|
|
10
|
+
import type { InjectOptions, FastifyInstance, PrintRoutesOptions, FastifyListenOptions, FastifyServerOptions, LightMyRequestChain, LightMyRequestResponse } from 'fastify';
|
|
11
|
+
import type { RouteJson, ErrorHandler, RequestHandler, InterceptHandler, TerminateHandler } from '#src/types';
|
|
12
|
+
import type { AddressInfo } from 'node:net';
|
|
16
13
|
export declare class ServerImpl {
|
|
17
14
|
/**
|
|
18
15
|
* Holds the fastify server instance.
|
|
@@ -97,33 +94,33 @@ export declare class ServerImpl {
|
|
|
97
94
|
/**
|
|
98
95
|
* Add a new route to the http server.
|
|
99
96
|
*/
|
|
100
|
-
route(options:
|
|
97
|
+
route(options: RouteJson): void;
|
|
101
98
|
/**
|
|
102
99
|
* Add a new GET route to the http server.
|
|
103
100
|
*/
|
|
104
|
-
get(options: Omit<
|
|
101
|
+
get(options: Omit<RouteJson, 'methods'>): void;
|
|
105
102
|
/**
|
|
106
103
|
* Add a new HEAD route to the http server.
|
|
107
104
|
*/
|
|
108
|
-
head(options: Omit<
|
|
105
|
+
head(options: Omit<RouteJson, 'methods'>): void;
|
|
109
106
|
/**
|
|
110
107
|
* Add a new POST route to the http server.
|
|
111
108
|
*/
|
|
112
|
-
post(options: Omit<
|
|
109
|
+
post(options: Omit<RouteJson, 'methods'>): void;
|
|
113
110
|
/**
|
|
114
111
|
* Add a new PUT route to the http server.
|
|
115
112
|
*/
|
|
116
|
-
put(options: Omit<
|
|
113
|
+
put(options: Omit<RouteJson, 'methods'>): void;
|
|
117
114
|
/**
|
|
118
115
|
* Add a new PATCH route to the http server.
|
|
119
116
|
*/
|
|
120
|
-
patch(options: Omit<
|
|
117
|
+
patch(options: Omit<RouteJson, 'methods'>): void;
|
|
121
118
|
/**
|
|
122
119
|
* Add a new DELETE route to the http server.
|
|
123
120
|
*/
|
|
124
|
-
delete(options: Omit<
|
|
121
|
+
delete(options: Omit<RouteJson, 'methods'>): void;
|
|
125
122
|
/**
|
|
126
123
|
* Add a new OPTIONS route to the http server.
|
|
127
124
|
*/
|
|
128
|
-
options(options: Omit<
|
|
125
|
+
options(options: Omit<RouteJson, 'methods'>): void;
|
|
129
126
|
}
|
|
@@ -8,16 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import fastify from 'fastify';
|
|
10
10
|
import { Options } from '@athenna/common';
|
|
11
|
-
import { FastifyHandler } from '#src/
|
|
11
|
+
import { FastifyHandler } from '#src/handlers/FastifyHandler';
|
|
12
12
|
export class ServerImpl {
|
|
13
|
-
/**
|
|
14
|
-
* Holds the fastify server instance.
|
|
15
|
-
*/
|
|
16
|
-
fastify;
|
|
17
|
-
/**
|
|
18
|
-
* Set if the Http server is listening for new requests.
|
|
19
|
-
*/
|
|
20
|
-
isListening;
|
|
21
13
|
constructor(options) {
|
|
22
14
|
this.fastify = fastify.fastify(options);
|
|
23
15
|
this.isListening = false;
|
|
@@ -6,15 +6,15 @@
|
|
|
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 { TestRequest } from '
|
|
9
|
+
import { TestRequest } from '#src/testing/plugins/request/TestRequest';
|
|
10
10
|
declare module '@japa/runner' {
|
|
11
11
|
interface TestContext {
|
|
12
12
|
request: TestRequest;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
-
export * from '
|
|
16
|
-
export * from '
|
|
15
|
+
export * from '#src/testing/plugins/request/TestRequest';
|
|
16
|
+
export * from '#src/testing/plugins/request/TestResponse';
|
|
17
17
|
/**
|
|
18
|
-
* Request plugin
|
|
18
|
+
* Request plugin registers the request macro to the test context.
|
|
19
19
|
*/
|
|
20
|
-
export declare function request(): (_config: any, _runner: any, classes: any) =>
|
|
20
|
+
export declare function request(): (_config: any, _runner: any, classes: any) => void;
|
|
@@ -6,14 +6,14 @@
|
|
|
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 { TestRequest } from '
|
|
10
|
-
export * from '
|
|
11
|
-
export * from '
|
|
9
|
+
import { TestRequest } from '#src/testing/plugins/request/TestRequest';
|
|
10
|
+
export * from '#src/testing/plugins/request/TestRequest';
|
|
11
|
+
export * from '#src/testing/plugins/request/TestResponse';
|
|
12
12
|
/**
|
|
13
|
-
* Request plugin
|
|
13
|
+
* Request plugin registers the request macro to the test context.
|
|
14
14
|
*/
|
|
15
15
|
export function request() {
|
|
16
|
-
return
|
|
16
|
+
return function (_config, _runner, classes) {
|
|
17
17
|
classes.TestContext.macro('request', new TestRequest());
|
|
18
18
|
};
|
|
19
19
|
}
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import { Assert } from '@japa/assert';
|
|
10
|
-
import { InjectOptions } from 'fastify';
|
|
11
|
-
import { TestResponse } from '#src/
|
|
10
|
+
import type { InjectOptions } from 'fastify';
|
|
11
|
+
import { TestResponse } from '#src/testing/plugins/request/TestResponse';
|
|
12
12
|
export declare class TestRequest {
|
|
13
13
|
/**
|
|
14
14
|
* Japa assert class instance.
|
|
@@ -8,12 +8,14 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { Server } from '#src';
|
|
10
10
|
import { Assert } from '@japa/assert';
|
|
11
|
-
import { TestResponse } from '#src/
|
|
11
|
+
import { TestResponse } from '#src/testing/plugins/request/TestResponse';
|
|
12
12
|
export class TestRequest {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
constructor() {
|
|
14
|
+
/**
|
|
15
|
+
* Japa assert class instance.
|
|
16
|
+
*/
|
|
17
|
+
this.assert = new Assert();
|
|
18
|
+
}
|
|
17
19
|
/**
|
|
18
20
|
* Instantiate TestResponse class from API response.
|
|
19
21
|
*/
|
|
@@ -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 { Response } from 'light-my-request';
|
|
10
|
+
import type { Response } from 'light-my-request';
|
|
11
11
|
export declare class TestResponse {
|
|
12
12
|
/**
|
|
13
13
|
* Japa assert class instance.
|
|
@@ -6,15 +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 { Assert } from '@japa/assert';
|
|
9
10
|
export class TestResponse {
|
|
10
|
-
/**
|
|
11
|
-
* Japa assert class instance.
|
|
12
|
-
*/
|
|
13
|
-
assert;
|
|
14
|
-
/**
|
|
15
|
-
* Light my request response object.
|
|
16
|
-
*/
|
|
17
|
-
response;
|
|
18
11
|
constructor(assert, response) {
|
|
19
12
|
this.assert = assert;
|
|
20
13
|
this.response = response;
|
|
@@ -6,8 +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 { Request } from '#src/
|
|
10
|
-
import { Response } from '#src/
|
|
9
|
+
import { Request } from '#src/context/Request';
|
|
10
|
+
import { Response } from '#src/context/Response';
|
|
11
11
|
export type Context = {
|
|
12
12
|
request: Request;
|
|
13
13
|
response: Response;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @athenna/http
|
|
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 { Request } from '#src/context/Request';
|
|
10
|
+
import { Response } from '#src/context/Response';
|
|
@@ -6,8 +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 { Request } from '#src/
|
|
10
|
-
import { Response } from '#src/
|
|
9
|
+
import { Request } from '#src/context/Request';
|
|
10
|
+
import { Response } from '#src/context/Response';
|
|
11
11
|
export type ErrorContext = {
|
|
12
12
|
request: Request;
|
|
13
13
|
response: Response;
|
|
@@ -6,8 +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 { Request } from '#src/
|
|
10
|
-
import { Response } from '#src/
|
|
9
|
+
import { Request } from '#src/context/Request';
|
|
10
|
+
import { Response } from '#src/context/Response';
|
|
11
11
|
export type InterceptContext = {
|
|
12
12
|
request: Request;
|
|
13
13
|
response: Response;
|
|
@@ -6,8 +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 { Request } from '#src/
|
|
10
|
-
import { Response } from '#src/
|
|
9
|
+
import { Request } from '#src/context/Request';
|
|
10
|
+
import { Response } from '#src/context/Response';
|
|
11
11
|
export type TerminateContext = {
|
|
12
12
|
request: Request;
|
|
13
13
|
response: Response;
|
|
@@ -6,7 +6,7 @@
|
|
|
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 { InterceptContext } from '#src/
|
|
9
|
+
import type { InterceptContext } from '#src/types/contexts/InterceptContext';
|
|
10
10
|
export interface InterceptorContract {
|
|
11
11
|
/**
|
|
12
12
|
* Intercept the request at the end, before returning the response.
|
|
@@ -6,7 +6,7 @@
|
|
|
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 { Context } from '#src/
|
|
9
|
+
import type { Context } from '#src/types/contexts/Context';
|
|
10
10
|
export interface MiddlewareContract {
|
|
11
11
|
/**
|
|
12
12
|
* Handle the request before going to the route handler.
|
|
@@ -6,7 +6,7 @@
|
|
|
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 { TerminateContext } from '#src/
|
|
9
|
+
import type { TerminateContext } from '#src/types/contexts/TerminateContext';
|
|
10
10
|
export interface TerminatorContract {
|
|
11
11
|
/**
|
|
12
12
|
* Handle the request after the response has been sent.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @athenna/http
|
|
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
|
+
export * from '#src/types/contexts/Context';
|
|
10
|
+
export * from '#src/types/contexts/ErrorContext';
|
|
11
|
+
export * from '#src/types/contexts/InterceptContext';
|
|
12
|
+
export * from '#src/types/contexts/TerminateContext';
|
|
13
|
+
export * from '#src/types/controllers/ControllerOptions';
|
|
14
|
+
export * from '#src/types/contracts/InterceptorContract';
|
|
15
|
+
export * from '#src/types/contracts/MiddlewareContract';
|
|
16
|
+
export * from '#src/types/contracts/TerminatorContract';
|
|
17
|
+
export * from '#src/types/middlewares/InterceptorRouteType';
|
|
18
|
+
export * from '#src/types/middlewares/MiddlewareHandler';
|
|
19
|
+
export * from '#src/types/middlewares/MiddlewareOptions';
|
|
20
|
+
export * from '#src/types/middlewares/MiddlewareRouteType';
|
|
21
|
+
export * from '#src/types/middlewares/TerminatorRouteType';
|
|
22
|
+
export * from '#src/types/router/RouteHandler';
|
|
23
|
+
export * from '#src/types/router/RouteJson';
|
|
24
|
+
export * from '#src/types/router/RouteResourceTypes';
|