@athenna/http 3.2.1 → 3.3.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.
@@ -12,4 +12,16 @@ export declare class MakeControllerCommand extends BaseCommand {
12
12
  static signature(): string;
13
13
  static description(): string;
14
14
  handle(): Promise<void>;
15
+ /**
16
+ * Get the file path where it will be generated.
17
+ */
18
+ private getFilePath;
19
+ /**
20
+ * Get the destination path for the file that will be generated.
21
+ */
22
+ private getDestinationPath;
23
+ /**
24
+ * Get the import path that should be registered in RC file.
25
+ */
26
+ private getImportPath;
15
27
  }
@@ -13,6 +13,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
13
13
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14
14
  };
15
15
  import { Path } from '@athenna/common';
16
+ import { sep, resolve, isAbsolute } from 'node:path';
16
17
  import { BaseCommand, Argument } from '@athenna/artisan';
17
18
  export class MakeControllerCommand extends BaseCommand {
18
19
  name;
@@ -25,15 +26,41 @@ export class MakeControllerCommand extends BaseCommand {
25
26
  async handle() {
26
27
  this.logger.simple('({bold,green} [ MAKING CONTROLLER ])\n');
27
28
  const file = await this.generator
28
- .path(Path.http(`Controllers/${this.name}.${Path.ext()}`))
29
+ .path(this.getFilePath())
29
30
  .template('controller')
30
31
  .setNameProperties(true)
31
32
  .make();
32
33
  this.logger.success(`Controller ({yellow} "${file.name}") successfully created.`);
33
- const importPath = `#app/Http/Controllers/${file.name}`;
34
+ const importPath = this.getImportPath(file.name);
34
35
  await this.rc.pushTo('controllers', importPath).save();
35
36
  this.logger.success(`Athenna RC updated: ({dim,yellow} [ controllers += "${importPath}" ])`);
36
37
  }
38
+ /**
39
+ * Get the file path where it will be generated.
40
+ */
41
+ getFilePath() {
42
+ return this.getDestinationPath().concat(`${sep}${this.name}.${Path.ext()}`);
43
+ }
44
+ /**
45
+ * Get the destination path for the file that will be generated.
46
+ */
47
+ getDestinationPath() {
48
+ let destination = Config.get('rc.commandsManifest.make:controller.destination', Path.http('Controllers'));
49
+ if (!isAbsolute(destination)) {
50
+ destination = resolve(Path.pwd(), destination);
51
+ }
52
+ return destination;
53
+ }
54
+ /**
55
+ * Get the import path that should be registered in RC file.
56
+ */
57
+ getImportPath(fileName) {
58
+ const destination = this.getDestinationPath();
59
+ return `${destination
60
+ .replace(Path.pwd(), '')
61
+ .replace(/\\/g, '/')
62
+ .replace('/', '#')}/${fileName}`;
63
+ }
37
64
  }
38
65
  __decorate([
39
66
  Argument({
@@ -12,4 +12,16 @@ export declare class MakeInterceptorCommand extends BaseCommand {
12
12
  static signature(): string;
13
13
  static description(): string;
14
14
  handle(): Promise<void>;
15
+ /**
16
+ * Get the file path where it will be generated.
17
+ */
18
+ private getFilePath;
19
+ /**
20
+ * Get the destination path for the file that will be generated.
21
+ */
22
+ private getDestinationPath;
23
+ /**
24
+ * Get the import path that should be registered in RC file.
25
+ */
26
+ private getImportPath;
15
27
  }
@@ -13,6 +13,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
13
13
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14
14
  };
15
15
  import { Path } from '@athenna/common';
16
+ import { sep, resolve, isAbsolute } from 'node:path';
16
17
  import { BaseCommand, Argument } from '@athenna/artisan';
17
18
  export class MakeInterceptorCommand extends BaseCommand {
18
19
  name;
@@ -25,15 +26,41 @@ export class MakeInterceptorCommand extends BaseCommand {
25
26
  async handle() {
26
27
  this.logger.simple('({bold,green} [ MAKING INTERCEPTOR ])\n');
27
28
  const file = await this.generator
28
- .path(Path.http(`Interceptors/${this.name}.${Path.ext()}`))
29
+ .path(this.getFilePath())
29
30
  .template('interceptor')
30
31
  .setNameProperties(true)
31
32
  .make();
32
33
  this.logger.success(`Interceptor ({yellow} "${file.name}") successfully created.`);
33
- const importPath = `#app/Http/Interceptors/${file.name}`;
34
+ const importPath = this.getImportPath(file.name);
34
35
  await this.rc.pushTo('middlewares', importPath).save();
35
36
  this.logger.success(`Athenna RC updated: ({dim,yellow} [ middlewares += "${importPath}" ])`);
36
37
  }
38
+ /**
39
+ * Get the file path where it will be generated.
40
+ */
41
+ getFilePath() {
42
+ return this.getDestinationPath().concat(`${sep}${this.name}.${Path.ext()}`);
43
+ }
44
+ /**
45
+ * Get the destination path for the file that will be generated.
46
+ */
47
+ getDestinationPath() {
48
+ let destination = Config.get('rc.commandsManifest.make:interceptor.destination', Path.http('Interceptors'));
49
+ if (!isAbsolute(destination)) {
50
+ destination = resolve(Path.pwd(), destination);
51
+ }
52
+ return destination;
53
+ }
54
+ /**
55
+ * Get the import path that should be registered in RC file.
56
+ */
57
+ getImportPath(fileName) {
58
+ const destination = this.getDestinationPath();
59
+ return `${destination
60
+ .replace(Path.pwd(), '')
61
+ .replace(/\\/g, '/')
62
+ .replace('/', '#')}/${fileName}`;
63
+ }
37
64
  }
38
65
  __decorate([
39
66
  Argument({
@@ -12,4 +12,16 @@ export declare class MakeMiddlewareCommand extends BaseCommand {
12
12
  static signature(): string;
13
13
  static description(): string;
14
14
  handle(): Promise<void>;
15
+ /**
16
+ * Get the file path where it will be generated.
17
+ */
18
+ private getFilePath;
19
+ /**
20
+ * Get the destination path for the file that will be generated.
21
+ */
22
+ private getDestinationPath;
23
+ /**
24
+ * Get the import path that should be registered in RC file.
25
+ */
26
+ private getImportPath;
15
27
  }
@@ -13,6 +13,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
13
13
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14
14
  };
15
15
  import { Path } from '@athenna/common';
16
+ import { sep, resolve, isAbsolute } from 'node:path';
16
17
  import { BaseCommand, Argument } from '@athenna/artisan';
17
18
  export class MakeMiddlewareCommand extends BaseCommand {
18
19
  name;
@@ -25,15 +26,41 @@ export class MakeMiddlewareCommand extends BaseCommand {
25
26
  async handle() {
26
27
  this.logger.simple('({bold,green} [ MAKING MIDDLEWARE ])\n');
27
28
  const file = await this.generator
28
- .path(Path.http(`Middlewares/${this.name}.${Path.ext()}`))
29
+ .path(this.getFilePath())
29
30
  .template('middleware')
30
31
  .setNameProperties(true)
31
32
  .make();
32
33
  this.logger.success(`Middleware ({yellow} "${file.name}") successfully created.`);
33
- const importPath = `#app/Http/Middlewares/${file.name}`;
34
+ const importPath = this.getImportPath(file.name);
34
35
  await this.rc.pushTo('middlewares', importPath).save();
35
36
  this.logger.success(`Athenna RC updated: ({dim,yellow} [ middlewares += "${importPath}" ])`);
36
37
  }
38
+ /**
39
+ * Get the file path where it will be generated.
40
+ */
41
+ getFilePath() {
42
+ return this.getDestinationPath().concat(`${sep}${this.name}.${Path.ext()}`);
43
+ }
44
+ /**
45
+ * Get the destination path for the file that will be generated.
46
+ */
47
+ getDestinationPath() {
48
+ let destination = Config.get('rc.commandsManifest.make:middleware.destination', Path.http('Middlewares'));
49
+ if (!isAbsolute(destination)) {
50
+ destination = resolve(Path.pwd(), destination);
51
+ }
52
+ return destination;
53
+ }
54
+ /**
55
+ * Get the import path that should be registered in RC file.
56
+ */
57
+ getImportPath(fileName) {
58
+ const destination = this.getDestinationPath();
59
+ return `${destination
60
+ .replace(Path.pwd(), '')
61
+ .replace(/\\/g, '/')
62
+ .replace('/', '#')}/${fileName}`;
63
+ }
37
64
  }
38
65
  __decorate([
39
66
  Argument({
@@ -12,4 +12,16 @@ export declare class MakeTerminatorCommand extends BaseCommand {
12
12
  static signature(): string;
13
13
  static description(): string;
14
14
  handle(): Promise<void>;
15
+ /**
16
+ * Get the file path where it will be generated.
17
+ */
18
+ private getFilePath;
19
+ /**
20
+ * Get the destination path for the file that will be generated.
21
+ */
22
+ private getDestinationPath;
23
+ /**
24
+ * Get the import path that should be registered in RC file.
25
+ */
26
+ private getImportPath;
15
27
  }
@@ -13,6 +13,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
13
13
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14
14
  };
15
15
  import { Path } from '@athenna/common';
16
+ import { sep, resolve, isAbsolute } from 'node:path';
16
17
  import { BaseCommand, Argument } from '@athenna/artisan';
17
18
  export class MakeTerminatorCommand extends BaseCommand {
18
19
  name;
@@ -25,15 +26,41 @@ export class MakeTerminatorCommand extends BaseCommand {
25
26
  async handle() {
26
27
  this.logger.simple('({bold,green} [ MAKING TERMINATOR ])\n');
27
28
  const file = await this.generator
28
- .path(Path.http(`Terminators/${this.name}.${Path.ext()}`))
29
+ .path(this.getFilePath())
29
30
  .template('terminator')
30
31
  .setNameProperties(true)
31
32
  .make();
32
33
  this.logger.success(`Terminator ({yellow} "${file.name}") successfully created.`);
33
- const importPath = `#app/Http/Terminators/${file.name}`;
34
+ const importPath = this.getImportPath(file.name);
34
35
  await this.rc.pushTo('middlewares', importPath).save();
35
36
  this.logger.success(`Athenna RC updated: ({dim,yellow} [ middlewares += "${importPath}" ])`);
36
37
  }
38
+ /**
39
+ * Get the file path where it will be generated.
40
+ */
41
+ getFilePath() {
42
+ return this.getDestinationPath().concat(`${sep}${this.name}.${Path.ext()}`);
43
+ }
44
+ /**
45
+ * Get the destination path for the file that will be generated.
46
+ */
47
+ getDestinationPath() {
48
+ let destination = Config.get('rc.commandsManifest.make:terminator.destination', Path.http('Terminators'));
49
+ if (!isAbsolute(destination)) {
50
+ destination = resolve(Path.pwd(), destination);
51
+ }
52
+ return destination;
53
+ }
54
+ /**
55
+ * Get the import path that should be registered in RC file.
56
+ */
57
+ getImportPath(fileName) {
58
+ const destination = this.getDestinationPath();
59
+ return `${destination
60
+ .replace(Path.pwd(), '')
61
+ .replace(/\\/g, '/')
62
+ .replace('/', '#')}/${fileName}`;
63
+ }
37
64
  }
38
65
  __decorate([
39
66
  Argument({
@@ -8,8 +8,15 @@
8
8
  */
9
9
  import { BaseCommand } from '@athenna/artisan';
10
10
  export declare class RouteListCommand extends BaseCommand {
11
- routeFilePath: any;
12
11
  static signature(): string;
13
12
  static description(): string;
14
13
  handle(): Promise<void>;
14
+ /**
15
+ * Resolve the http routes file.
16
+ */
17
+ private resolveRoute;
18
+ /**
19
+ * Get the http kernel module from RC file or resolve the default one.
20
+ */
21
+ private getHttpKernel;
15
22
  }
@@ -11,7 +11,6 @@ import { Module } from '@athenna/common';
11
11
  import { BaseCommand } from '@athenna/artisan';
12
12
  import { Route, HttpKernel, HttpRouteProvider, HttpServerProvider } from '#src';
13
13
  export class RouteListCommand extends BaseCommand {
14
- routeFilePath = Env('HTTP_ROUTE_FILE_PATH', Path.routes('http.js'));
15
14
  static signature() {
16
15
  return 'route:list';
17
16
  }
@@ -22,10 +21,10 @@ export class RouteListCommand extends BaseCommand {
22
21
  this.logger.simple('({bold,green} [ LISTING ROUTES ])\n');
23
22
  new HttpServerProvider().register();
24
23
  new HttpRouteProvider().register();
25
- const kernel = new HttpKernel();
24
+ const kernel = new (await this.getHttpKernel())();
26
25
  await kernel.registerControllers();
27
26
  await kernel.registerMiddlewares();
28
- await Module.resolve(this.routeFilePath, Config.get('rc.meta'));
27
+ await this.resolveRoute();
29
28
  const routes = Route.list();
30
29
  const table = this.logger.table();
31
30
  table.head('Methods', 'Route', 'Name', 'Handler');
@@ -42,4 +41,19 @@ export class RouteListCommand extends BaseCommand {
42
41
  });
43
42
  table.render();
44
43
  }
44
+ /**
45
+ * Resolve the http routes file.
46
+ */
47
+ async resolveRoute() {
48
+ await Module.resolve(Config.get('rc.commandsManifest.route:list.route', '#routes/http'), Config.get('rc.meta'));
49
+ }
50
+ /**
51
+ * Get the http kernel module from RC file or resolve the default one.
52
+ */
53
+ async getHttpKernel() {
54
+ if (!Config.exists('rc.commandsManifest.route:list.kernel')) {
55
+ return HttpKernel;
56
+ }
57
+ return Module.resolve(Config.get('rc.commandsManifest.route:list.kernel'), Config.get('rc.meta'));
58
+ }
45
59
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@athenna/http",
3
- "version": "3.2.1",
3
+ "version": "3.3.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>",
@@ -63,8 +63,8 @@
63
63
  "fastify": "^4.13.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@athenna/artisan": "^3.2.0",
67
- "@athenna/common": "^3.3.1",
66
+ "@athenna/artisan": "^3.3.0",
67
+ "@athenna/common": "^3.3.3",
68
68
  "@athenna/config": "^3.2.0",
69
69
  "@athenna/ioc": "^3.1.5",
70
70
  "@athenna/logger": "^3.1.5",
@@ -125,7 +125,8 @@
125
125
  "exclude": [
126
126
  "src/Types/*",
127
127
  "src/Contracts/*",
128
- "src/Exceptions/*"
128
+ "src/Exceptions/*",
129
+ "src/Commands/*"
129
130
  ],
130
131
  "reporter": [
131
132
  "text-summary",
@@ -262,7 +263,11 @@
262
263
  "#tests/Stubs/middlewares/DecoratedGlobalTerminator"
263
264
  ],
264
265
  "commandsManifest": {
265
- "route:list": "#src/Commands/RouteListCommand",
266
+ "route:list": {
267
+ "path": "#src/Commands/RouteListCommand",
268
+ "route": "./tests/Stubs/routes/http.js",
269
+ "kernel": "./tests/Stubs/kernels/HttpKernel.js"
270
+ },
266
271
  "make:controller": "#src/Commands/MakeControllerCommand",
267
272
  "make:interceptor": "#src/Commands/MakeInterceptorCommand",
268
273
  "make:middleware": "#src/Commands/MakeMiddlewareCommand",