@adaptivestone/framework 5.0.0-beta.10 → 5.0.0-beta.11

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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 5.0.0-beta.11
2
+
3
+ [NEW] commands typing
4
+ [NEW] commands support TS files
5
+ [UPDATE] update deps
6
+
1
7
  ### 5.0.0-beta.9
2
8
 
3
9
  [BREAKING] move email module to separate package @adaptivestone/framework-module-email. Please use it if you want to send emails
@@ -22,8 +22,14 @@ class ControllerManager extends Base {
22
22
  );
23
23
 
24
24
  controllersToLoad.sort((a, b) => {
25
- if (a.file.toLowerCase().endsWith('index.js')) {
26
- if (b.file.toLowerCase().endsWith('index.js')) {
25
+ if (
26
+ a.file.toLowerCase().endsWith('index.js') ||
27
+ a.file.toLowerCase().endsWith('index.ts')
28
+ ) {
29
+ if (
30
+ b.file.toLowerCase().endsWith('index.js') ||
31
+ b.file.toLowerCase().endsWith('index.ts')
32
+ ) {
27
33
  return 0;
28
34
  }
29
35
  return -1;
package/helpers/files.js CHANGED
@@ -23,7 +23,7 @@ const getFilesPathWithInheritance = async ({
23
23
  // not start with capital
24
24
  return false;
25
25
  }
26
- if (notTests && file.endsWith('.test.js')) {
26
+ if (notTests && (file.endsWith('.test.js') || file.endsWith('.test.ts'))) {
27
27
  return false;
28
28
  }
29
29
  if (notHidden && file[0] === '.') {
@@ -0,0 +1,50 @@
1
+ import type Base from './Base.js';
2
+ import type { ICommandArguments } from '../types/ICommandArguments.d.ts';
3
+
4
+ abstract class AbstractCommand extends Base {
5
+ constructor(
6
+ app: Server['app'],
7
+ commands: { [key: string]: string },
8
+ args: {
9
+ [longOption: string]:
10
+ | undefined
11
+ | string
12
+ | boolean
13
+ | Array<string | boolean>;
14
+ },
15
+ );
16
+
17
+ static get description(): string;
18
+ /**
19
+ * If true, then this command will load models and init mongo connection
20
+ */
21
+ static isShouldInitModels = true;
22
+
23
+ /**
24
+ * Get mongo connection name
25
+ */
26
+ static getMongoConnectionName(
27
+ commandName: string,
28
+ args: {
29
+ [longOption: string]:
30
+ | undefined
31
+ | string
32
+ | boolean
33
+ | Array<string | boolean>;
34
+ },
35
+ ): string;
36
+
37
+ /**
38
+ * You able to add command arguments for parsing there.
39
+ * @see https://nodejs.org/api/util.html#utilparseargsconfig in config.options plus extended with description and required
40
+ * @returns {import("../types/ICommandArguments.d.ts").ICommandArguments}
41
+ */
42
+ static get commandArguments(): ICommandArguments;
43
+
44
+ /**
45
+ * Entry point to every command. This method should be overridden
46
+ */
47
+ async run(): Promise<boolean | unknown>;
48
+ }
49
+
50
+ export default AbstractCommand;
@@ -29,7 +29,7 @@ class AbstractCommand extends Base {
29
29
  /**
30
30
  * You able to add command arguments for parsing there.
31
31
  * @see https://nodejs.org/api/util.html#utilparseargsconfig in config.options plus extended with description and required
32
- * @returns {import("../types/ICommandArguments.js").ICommandArguments}
32
+ * @returns {import("../types/ICommandArguments.d.ts").ICommandArguments}
33
33
  */
34
34
  static get commandArguments() {
35
35
  return {};
@@ -0,0 +1,55 @@
1
+ import type { Router } from 'express';
2
+ import type Base from './Base.js';
3
+
4
+ type TMiddleware = Array<Function | Array<Function, Array<any>>>;
5
+
6
+ class AbstractController extends Base {
7
+ prefix: string;
8
+ router: Router;
9
+ constructor(app: Server['app'], prefix: string, isExpressMergeParams = false);
10
+
11
+ /**
12
+ * Parse middlewares to be an object.
13
+ */
14
+ parseMiddlewares(
15
+ middlewareMap: Map<string, TMiddleware>,
16
+ httpPath: string,
17
+ ): Array<{
18
+ name: string;
19
+ method: string;
20
+ path: string;
21
+ fullPath: string;
22
+ params: Array<any>;
23
+ relatedQueryParameters?: any;
24
+ authParams?: any;
25
+ MiddlewareFunction: Function;
26
+ }>;
27
+
28
+ get routes(): {
29
+ [method: string]: {
30
+ [path: string]: {
31
+ handler: Function;
32
+ middleware?: TMiddleware;
33
+ request?: any;
34
+ query?: any;
35
+ };
36
+ };
37
+ };
38
+
39
+ /**
40
+ * Array of middlewares to append for route
41
+ * You should provide path relative to controller and then array of middlewares to apply.
42
+ * Order is matter.
43
+ * Be default path apply to ANY' method, but you can preattach 'METHOD' into patch to scope patch to this METHOD
44
+ */
45
+ static get middleware(): Map<string, TMiddleware>;
46
+
47
+ getConstructorName(): string;
48
+
49
+ /**
50
+ * Get http path with inheritance of path
51
+ */
52
+ getHttpPath(): string;
53
+ }
54
+
55
+ export default AbstractController;
@@ -13,6 +13,9 @@ import DocumentationGenerator from '../services/documentation/DocumentationGener
13
13
  * In most cases you will want to have a 'home' route that not include controller name. For this case please check ' getHttpPath'
14
14
  */
15
15
  class AbstractController extends Base {
16
+ prefix = '';
17
+ router = null;
18
+
16
19
  constructor(app, prefix, isExpressMergeParams = false) {
17
20
  const time = Date.now();
18
21
  super(app);
@@ -21,16 +24,7 @@ class AbstractController extends Base {
21
24
  mergeParams: isExpressMergeParams,
22
25
  });
23
26
  const { routes } = this;
24
- let httpPath = this.getHttpPath();
25
-
26
- // @ts-ignore
27
- if (this.getExpressPath) {
28
- this.logger.warn(
29
- `getExpressPath deprecated. Please use getHttpPath instead. Will be removed on v5`,
30
- );
31
- // @ts-ignore
32
- httpPath = this.getExpressPath();
33
- }
27
+ const httpPath = this.getHttpPath();
34
28
 
35
29
  /**
36
30
  * Grab route middleware onlo one Map
@@ -2,7 +2,7 @@ import type Base from './Base.js';
2
2
  import { Model, Schema } from 'mongoose';
3
3
  import type Server from '../server.js';
4
4
 
5
- interface AbstractModel<T extends Document> extends Model, Base {
5
+ interface AbstractModel<T extends Document = Document> extends Model, Base {
6
6
  constructor(app: Server['app'], callback?: () => void);
7
7
 
8
8
  /**
@@ -31,7 +31,7 @@ interface AbstractModel<T extends Document> extends Model, Base {
31
31
  initHooks(): void;
32
32
  }
33
33
 
34
- abstract class AbstractModel<T extends Document>
34
+ abstract class AbstractModel<T extends Document = Document>
35
35
  extends Model
36
36
  implements AbstractModel
37
37
  {
@@ -20,9 +20,14 @@ class Cli extends Base {
20
20
  this.server.app.foldersConfig.commands,
21
21
  );
22
22
  for (const com of commandsToLoad) {
23
- if (com.file.endsWith('.js')) {
24
- const c = com.file.replace('.js', '');
25
-
23
+ if (com.file.endsWith('.js') || com.file.endsWith('.ts')) {
24
+ const c = com.file.replace('.js', '').replace('.ts', '');
25
+ if (this.commands[c.toLowerCase()]) {
26
+ this.logger.warn(
27
+ `Command ${c.toLowerCase()} already exists with full path ${this.commands[c.toLowerCase()]}. Possible problems - you have two commands with "ts" and "js" extensions. Skipping...`,
28
+ );
29
+ continue;
30
+ }
26
31
  this.commands[c.toLowerCase()] = com.path;
27
32
  }
28
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptivestone/framework",
3
- "version": "5.0.0-beta.10",
3
+ "version": "5.0.0-beta.11",
4
4
  "description": "Adaptive stone node js framework",
5
5
  "main": "index.js",
6
6
  "type": "module",