@athenna/http 5.22.0 → 5.24.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": "5.22.0",
3
+ "version": "5.24.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>",
@@ -74,23 +74,23 @@
74
74
  "#tests": "./tests/index.js"
75
75
  },
76
76
  "devDependencies": {
77
- "@athenna/artisan": "^5.3.0",
78
- "@athenna/common": "^5.4.0",
79
- "@athenna/config": "^5.1.0",
80
- "@athenna/ioc": "^5.0.0",
81
- "@athenna/logger": "^5.1.0",
82
- "@athenna/test": "^5.2.0",
77
+ "@athenna/artisan": "^5.6.0",
78
+ "@athenna/common": "^5.7.0",
79
+ "@athenna/config": "^5.3.0",
80
+ "@athenna/ioc": "^5.1.0",
81
+ "@athenna/logger": "^5.3.0",
82
+ "@athenna/test": "^5.3.0",
83
83
  "@athenna/tsconfig": "^5.0.0",
84
- "@athenna/view": "^5.1.0",
85
- "@athenna/vite": "^5.9.0",
86
- "@fastify/cors": "^10.0.1",
87
- "@fastify/helmet": "^13.0.0",
88
- "@fastify/rate-limit": "^10.2.1",
89
- "@fastify/static": "^8.0.3",
90
- "@fastify/swagger": "^9.4.0",
91
- "@fastify/swagger-ui": "^5.2.0",
92
- "@typescript-eslint/eslint-plugin": "^7.18.0",
93
- "@typescript-eslint/parser": "^7.18.0",
84
+ "@athenna/view": "^5.3.0",
85
+ "@athenna/vite": "^5.12.0",
86
+ "@fastify/cors": "^10.0.2",
87
+ "@fastify/helmet": "^13.0.1",
88
+ "@fastify/rate-limit": "^10.2.2",
89
+ "@fastify/static": "^8.0.4",
90
+ "@fastify/swagger": "^9.4.2",
91
+ "@fastify/swagger-ui": "^5.2.1",
92
+ "@typescript-eslint/eslint-plugin": "^8.21.0",
93
+ "@typescript-eslint/parser": "^8.21.0",
94
94
  "autocannon": "^7.15.0",
95
95
  "commitizen": "^4.3.1",
96
96
  "cz-conventional-changelog": "^3.3.0",
@@ -106,7 +106,7 @@
106
106
  "lint-staged": "^12.5.0",
107
107
  "ora": "^8.1.1",
108
108
  "prettier": "^2.8.8",
109
- "vite": "^6.0.6",
109
+ "vite": "^6.0.11",
110
110
  "vite-plugin-restart": "^0.4.2"
111
111
  },
112
112
  "c8": {
@@ -7,7 +7,8 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  import type { FastifyRequest } from 'fastify';
10
- export declare class Request {
10
+ import { Macroable } from '@athenna/common';
11
+ export declare class Request extends Macroable {
11
12
  /**
12
13
  * The fastify request object.
13
14
  */
@@ -6,9 +6,10 @@
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 { Is, Json } from '@athenna/common';
10
- export class Request {
9
+ import { Is, Json, Macroable } from '@athenna/common';
10
+ export class Request extends Macroable {
11
11
  constructor(request) {
12
+ super();
12
13
  this.request = request;
13
14
  }
14
15
  /**
@@ -6,11 +6,12 @@
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 { Macroable } from '@athenna/common';
9
10
  import type { FastifyReply } from 'fastify';
10
11
  import type { SendOptions } from '@fastify/static';
11
12
  import type { Request } from '#src/context/Request';
12
13
  import type { FastifyHelmetOptions } from '@fastify/helmet';
13
- export declare class Response {
14
+ export declare class Response extends Macroable {
14
15
  /**
15
16
  * The fastify response object.
16
17
  */
@@ -103,26 +104,6 @@ export declare class Response {
103
104
  * ```
104
105
  */
105
106
  view(view: string, data?: any): Promise<this>;
106
- /**
107
- * Terminate the request sending a React component to be rendered.
108
- *
109
- * @example
110
- * ```ts
111
- * return response.render('index')
112
- * return response.render('index', {
113
- * component: 'src/resources/app/app.tsx',
114
- * viewData: {},
115
- * beforeComponentRender: (component) => {
116
- * return component.createApp()
117
- * }
118
- * })
119
- * ```
120
- */
121
- render(view: string, options?: {
122
- component?: string;
123
- viewData?: any;
124
- beforeComponentRender?: (componentModule: any) => any;
125
- }): Promise<this>;
126
107
  /**
127
108
  * Terminate the request sending the response body or not.
128
109
  *
@@ -7,11 +7,10 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  import { View } from '@athenna/view';
10
- import { Server } from '#src/facades/Server';
11
- import { Module, Options } from '@athenna/common';
12
- let reactDom = Module.safeImport('react-dom/server');
13
- export class Response {
10
+ import { Macroable } from '@athenna/common';
11
+ export class Response extends Macroable {
14
12
  constructor(response, request) {
13
+ super();
15
14
  this.response = response;
16
15
  this.request = request;
17
16
  }
@@ -118,45 +117,6 @@ export class Response {
118
117
  .render(view, data);
119
118
  return this.html(content);
120
119
  }
121
- /**
122
- * Terminate the request sending a React component to be rendered.
123
- *
124
- * @example
125
- * ```ts
126
- * return response.render('index')
127
- * return response.render('index', {
128
- * component: 'src/resources/app/app.tsx',
129
- * viewData: {},
130
- * beforeComponentRender: (component) => {
131
- * return component.createApp()
132
- * }
133
- * })
134
- * ```
135
- */
136
- async render(view, options) {
137
- if (!reactDom) {
138
- throw new Error('React is not installed, please run "npm i react react-dom".');
139
- }
140
- reactDom = await reactDom;
141
- options = Options.create(options, {
142
- viewData: {},
143
- component: Config.get('http.vite.ssrEntrypoint'),
144
- beforeComponentRender: options?.component
145
- ? null
146
- : component => {
147
- return component.createApp(this.request.baseUrl);
148
- }
149
- });
150
- const vite = Server.getVitePlugin().getVite();
151
- let component = await vite.ssrLoadModule(options.component);
152
- if (options.beforeComponentRender) {
153
- component = options.beforeComponentRender(component);
154
- }
155
- return this.view(view, {
156
- element: reactDom.renderToString(component),
157
- ...options.viewData
158
- });
159
- }
160
120
  /**
161
121
  * Terminate the request sending the response body or not.
162
122
  *
@@ -8,7 +8,8 @@
8
8
  */
9
9
  import type { RouteJson, RouteHandler, RequestHandler, MiddlewareRecord, MiddlewareRouteType, TerminatorRouteType, InterceptorRouteType } from '#src/types';
10
10
  import type { HTTPMethods, FastifySchema, RouteOptions } from 'fastify';
11
- export declare class Route {
11
+ import { Macroable } from '@athenna/common';
12
+ export declare class Route extends Macroable {
12
13
  /**
13
14
  * Holds all the route implementations to be registered in the Server.
14
15
  */
@@ -6,12 +6,13 @@
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 { Is, Options, Route as RouteHelper } from '@athenna/common';
9
+ import { Is, Options, Macroable, Route as RouteHelper } from '@athenna/common';
10
10
  import { UndefinedMethodException } from '#src/exceptions/UndefinedMethodException';
11
11
  import { NotFoundValidatorException } from '#src/exceptions/NotFoundValidatorException';
12
12
  import { NotFoundMiddlewareException } from '#src/exceptions/NotFoundMiddlewareException';
13
- export class Route {
13
+ export class Route extends Macroable {
14
14
  constructor(url, methods, handler) {
15
+ super();
15
16
  this.route = {
16
17
  url,
17
18
  methods,
@@ -8,8 +8,9 @@
8
8
  */
9
9
  import type { MiddlewareRouteType, TerminatorRouteType, InterceptorRouteType } from '#src/types';
10
10
  import { Route } from '#src/router/Route';
11
+ import { Macroable } from '@athenna/common';
11
12
  import { RouteResource } from '#src/router/RouteResource';
12
- export declare class RouteGroup {
13
+ export declare class RouteGroup extends Macroable {
13
14
  /**
14
15
  * All routes registered in the group.
15
16
  */
@@ -7,9 +7,11 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  import { Route } from '#src/router/Route';
10
+ import { Macroable } from '@athenna/common';
10
11
  import { RouteResource } from '#src/router/RouteResource';
11
- export class RouteGroup {
12
+ export class RouteGroup extends Macroable {
12
13
  constructor(routes) {
14
+ super();
13
15
  this.routes = routes;
14
16
  }
15
17
  /**
@@ -8,7 +8,8 @@
8
8
  */
9
9
  import type { RouteResourceTypes, TerminatorRouteType, MiddlewareRouteType, InterceptorRouteType } from '#src/types';
10
10
  import { Route } from '#src/router/Route';
11
- export declare class RouteResource {
11
+ import { Macroable } from '@athenna/common';
12
+ export declare class RouteResource extends Macroable {
12
13
  /**
13
14
  * All routes registered in the resource.
14
15
  */
@@ -7,9 +7,10 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  import { Route } from '#src/router/Route';
10
- import { Is, String } from '@athenna/common';
11
- export class RouteResource {
10
+ import { Is, String, Macroable } from '@athenna/common';
11
+ export class RouteResource extends Macroable {
12
12
  constructor(resource, controller) {
13
+ super();
13
14
  /**
14
15
  * All routes registered in the resource.
15
16
  */
@@ -7,11 +7,12 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  import { Route } from '#src/router/Route';
10
+ import { Macroable } from '@athenna/common';
10
11
  import { RouteGroup } from '#src/router/RouteGroup';
11
12
  import { RouteResource } from '#src/router/RouteResource';
12
13
  import type { RouteJson, RequestHandler, RouteHandler } from '#src/types';
13
14
  import type { HTTPMethods, FastifyInstance, RouteOptions } from 'fastify';
14
- export declare class Router {
15
+ export declare class Router extends Macroable {
15
16
  /**
16
17
  * All routes registered.
17
18
  */
@@ -6,14 +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 { Is } from '@athenna/common';
10
9
  import { Route } from '#src/router/Route';
11
10
  import { Server } from '#src/facades/Server';
11
+ import { Is, Macroable } from '@athenna/common';
12
12
  import { RouteGroup } from '#src/router/RouteGroup';
13
13
  import { RouteResource } from '#src/router/RouteResource';
14
14
  import { UndefinedMethodException } from '#src/exceptions/UndefinedMethodException';
15
- export class Router {
15
+ export class Router extends Macroable {
16
16
  constructor() {
17
+ super(...arguments);
17
18
  /**
18
19
  * All routes registered.
19
20
  */
@@ -8,9 +8,10 @@
8
8
  */
9
9
  import type { InjectOptions, FastifyInstance, PrintRoutesOptions, FastifyListenOptions, FastifyServerOptions, LightMyRequestChain, LightMyRequestResponse } from 'fastify';
10
10
  import type { RouteJson, ErrorHandler, RequestHandler, InterceptHandler, TerminateHandler, SwaggerDocument } from '#src/types';
11
- import type { FastifyVite } from '@athenna/vite';
12
11
  import type { AddressInfo } from 'node:net';
13
- export declare class ServerImpl {
12
+ import type { FastifyVite } from '@athenna/vite';
13
+ import { Macroable } from '@athenna/common';
14
+ export declare class ServerImpl extends Macroable {
14
15
  /**
15
16
  * Holds the fastify server instance.
16
17
  */
@@ -7,10 +7,11 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  import fastify from 'fastify';
10
- import { Options } from '@athenna/common';
10
+ import { Options, Macroable } from '@athenna/common';
11
11
  import { FastifyHandler } from '#src/handlers/FastifyHandler';
12
- export class ServerImpl {
12
+ export class ServerImpl extends Macroable {
13
13
  constructor(options) {
14
+ super();
14
15
  this.fastify = fastify.fastify({ ...options, exposeHeadRoutes: false });
15
16
  this.isListening = false;
16
17
  this.fastify.decorateReply('body', null);
@@ -7,9 +7,10 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  import { Assert } from '@japa/assert';
10
+ import { Macroable } from '@athenna/common';
10
11
  import type { InjectOptions } from '#src/types';
11
12
  import { TestResponse } from '#src/testing/plugins/request/TestResponse';
12
- export declare class TestRequest {
13
+ export declare class TestRequest extends Macroable {
13
14
  /**
14
15
  * Japa assert class instance.
15
16
  */
@@ -8,9 +8,11 @@
8
8
  */
9
9
  import { Server } from '#src';
10
10
  import { Assert } from '@japa/assert';
11
+ import { Macroable } from '@athenna/common';
11
12
  import { TestResponse } from '#src/testing/plugins/request/TestResponse';
12
- export class TestRequest {
13
+ export class TestRequest extends Macroable {
13
14
  constructor() {
15
+ super(...arguments);
14
16
  /**
15
17
  * Japa assert class instance.
16
18
  */
@@ -7,8 +7,9 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  import { Assert } from '@japa/assert';
10
+ import { Macroable } from '@athenna/common';
10
11
  import type { Response } from 'light-my-request';
11
- export declare class TestResponse {
12
+ export declare class TestResponse extends Macroable {
12
13
  /**
13
14
  * Japa assert class instance.
14
15
  */
@@ -7,8 +7,10 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
  import { Assert } from '@japa/assert';
10
- export class TestResponse {
10
+ import { Macroable } from '@athenna/common';
11
+ export class TestResponse extends Macroable {
11
12
  constructor(assert, response) {
13
+ super();
12
14
  this.assert = assert;
13
15
  this.response = response;
14
16
  }