@adaptivestone/framework 5.0.0-alpha.13 → 5.0.0-alpha.15

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,12 @@
1
+ ### 5.0.0-alpha.15
2
+
3
+ [BUG] fix bug with pagination
4
+ [UPDATE] update deps
5
+
6
+ ### 5.0.0-alpha.14
7
+
8
+ [NEW] add types for Abstract model (wip)
9
+
1
10
  ### 5.0.0-alpha.13
2
11
 
3
12
  [UPDATE] update deps
package/helpers/files.js CHANGED
@@ -8,7 +8,7 @@ const getFilesPathWithInheritance = async ({
8
8
  loggerFileType = '',
9
9
  filter: { startWithCapital = true, notTests = true, notHidden = true } = {},
10
10
  }) => {
11
- let [internalFiles, externalFiles] = await Promise.all([
11
+ const [internalFiles, externalFiles] = await Promise.all([
12
12
  fs.readdir(internalFolder, { recursive: true, withFileTypes: true }),
13
13
  fs.readdir(externalFolder, { recursive: true, withFileTypes: true }),
14
14
  ]);
@@ -33,24 +33,24 @@ const getFilesPathWithInheritance = async ({
33
33
  return true;
34
34
  };
35
35
 
36
- internalFiles = internalFiles
36
+ const internalFilesString = internalFiles
37
37
  .filter(filterIndexFile)
38
38
  .map((fileDirent) =>
39
- join(fileDirent.path, fileDirent.name)
39
+ join(fileDirent.parentPath, fileDirent.name)
40
40
  .replace(`${internalFolder}/`, '')
41
41
  .replace(`${internalFolder}`, ''),
42
42
  );
43
- externalFiles = externalFiles
43
+ const externalFilesString = externalFiles
44
44
  .filter(filterIndexFile)
45
45
  .map((fileDirent) =>
46
- join(fileDirent.path, fileDirent.name)
46
+ join(fileDirent.parentPath, fileDirent.name)
47
47
  .replace(`${externalFolder}/`, '')
48
48
  .replace(`${externalFolder}`, ''),
49
49
  );
50
50
 
51
51
  const filesToLoad = [];
52
- for (const file of internalFiles) {
53
- if (externalFiles.includes(file)) {
52
+ for (const file of internalFilesString) {
53
+ if (externalFilesString.includes(file)) {
54
54
  logger(
55
55
  `Skipping register INTERNAL file '${file}' ${
56
56
  loggerFileType ? `of type ${loggerFileType}` : ''
@@ -64,7 +64,7 @@ const getFilesPathWithInheritance = async ({
64
64
  }
65
65
  }
66
66
 
67
- for (const file of externalFiles) {
67
+ for (const file of externalFilesString) {
68
68
  filesToLoad.push({
69
69
  path: join(externalFolder, file),
70
70
  file,
@@ -373,7 +373,7 @@ class AbstractController extends Base {
373
373
  * You should provide path relative to controller and then array of middlewares to apply.
374
374
  * Order is matter.
375
375
  * Be default path apply to ANY' method, but you can preattach 'METHOD' into patch to scope patch to this METHOD
376
- * @returns {Map<string, Array<AbstractMiddleware | [Function, ...any]>>}
376
+ * @returns {Map<string, Array<typeof import('../services/http/middleware/AbstractMiddleware.js').default | [Function, ...any]>>}
377
377
  * @example
378
378
  * return new Map([
379
379
  * ['/*', [GetUserByToken]] // for any method for this controller
@@ -0,0 +1,48 @@
1
+ import Base from './Base.js';
2
+ import { Model, Schema } from 'mongoose';
3
+ import Server from '../server.js';
4
+
5
+ interface AbstractModel<T extends Document> extends Model, Base {
6
+ constructor(app: Server['app'], callback?: () => void);
7
+
8
+ /**
9
+ * Return itself for internal methods.
10
+ */
11
+ getSuper(): this;
12
+
13
+ /**
14
+ * Model schema in Js object (not a mongoose schema).
15
+ */
16
+ get modelSchema(): Object;
17
+
18
+ /**
19
+ * Mongoose schema.
20
+ */
21
+ mongooseSchema: Schema<T>;
22
+
23
+ /**
24
+ * Acces to mongoose model too
25
+ */
26
+ mongooseModel: Model<T>;
27
+
28
+ /**
29
+ * Init custom hooks before model
30
+ */
31
+ initHooks(): void;
32
+ }
33
+
34
+ abstract class AbstractModel<T extends Document>
35
+ extends Model
36
+ implements AbstractModel
37
+ {
38
+ abstract get modelSchema(): Object;
39
+
40
+ /**
41
+ * Return itself for internal methods.
42
+ */
43
+ static abstract getSuper(): this;
44
+
45
+ mongooseSchema: Schema<T> = new Schema<T>(this.modelSchema);
46
+ }
47
+
48
+ export default AbstractModel;
@@ -2,6 +2,10 @@ import mongoose from 'mongoose';
2
2
  import Base from './Base.js';
3
3
 
4
4
  class AbstractModel extends Base {
5
+ mongooseSchema = null;
6
+
7
+ mongooseModel = null;
8
+
5
9
  /**
6
10
  * @param {import('../server.js').default['app']} app //TODO change to *.d.ts as this is a Server, not app
7
11
  * @param function callback optional callback when connection ready
package/modules/Base.d.ts CHANGED
@@ -27,7 +27,7 @@ declare class Base {
27
27
  getFilesPathWithInheritance(
28
28
  internalFolder: string,
29
29
  externalFolder: string,
30
- ): Promise<Dirent[]>;
30
+ ): Promise<{ path: string; file: string }[]>;
31
31
 
32
32
  /**
33
33
  * Return logger group. Just to have all logs groupped logically
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptivestone/framework",
3
- "version": "5.0.0-alpha.13",
3
+ "version": "5.0.0-alpha.15",
4
4
  "description": "Adaptive stone node js framework",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/server.js CHANGED
@@ -66,7 +66,7 @@ class Server {
66
66
 
67
67
  /**
68
68
  * Start server (http + init all http ralated functions)
69
- * @param <Promise>callbackBefore404 code that should be executed before adding page 404
69
+ * @param {Function} callbackBefore404 code that should be executed before adding page 404
70
70
  * @returns {Promise}
71
71
  */
72
72
  async startServer(callbackBefore404 = async () => Promise.resolve()) {
@@ -5,13 +5,14 @@ class GetUserByToken extends AbstractMiddleware {
5
5
  return 'Grab a token and try to parse the user from it. It user exist will add req.appInfo.user variable';
6
6
  }
7
7
 
8
+ // eslint-disable-next-line class-methods-use-this
8
9
  get usedAuthParameters() {
9
10
  return [
10
11
  {
11
12
  name: 'Authorization',
12
13
  type: 'apiKey',
13
14
  in: 'header',
14
- description: this.constructor.description,
15
+ description: GetUserByToken.description,
15
16
  },
16
17
  ];
17
18
  }
@@ -19,8 +19,9 @@ class Pagination extends AbstractMiddleware {
19
19
  async middleware(req, res, next) {
20
20
  let { limit, maxLimit } = this.params;
21
21
 
22
- limit = typeof limit !== 'number' ? parseInt(limit, 10) : 10;
23
- maxLimit = typeof maxLimit !== 'number' ? parseInt(maxLimit, 10) : 100;
22
+ limit = (typeof limit !== 'number' ? parseInt(limit, 10) : limit) || 10;
23
+ maxLimit =
24
+ (typeof maxLimit !== 'number' ? parseInt(maxLimit, 10) : maxLimit) || 100;
24
25
 
25
26
  req.appInfo.pagination = {};
26
27
  req.appInfo.pagination.page =