@adaptivestone/framework 3.2.2 → 3.4.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/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ### 3.4.0
2
+
3
+ [NEW] now we pass 'req' to validation and casting as a second parameter. This done mostly for custom validators
4
+
5
+ ### 3.3.0
6
+
7
+ [NEW] new command 'SyncIndexes' to sync indexes for mongodb https://framework.adaptivestone.com/docs/cli#syncindexes
8
+ [UPDATE] updated deps
9
+ [FIX] fix documentation generation
10
+
1
11
  ### 3.2.2
2
12
 
3
13
  [UPDATE] add options for i18n to config.
@@ -1,5 +1,4 @@
1
1
  const fs = require('fs').promises;
2
-
3
2
  const AbstractCommand = require('../modules/AbstractCommand');
4
3
 
5
4
  /**
@@ -96,13 +95,18 @@ class GetOpenApiJson extends AbstractCommand {
96
95
  for (const middleware of middlewares) {
97
96
  if (middleware?.authParams?.length) {
98
97
  for (const authParam of middleware.authParams) {
99
- if (!openApi.components.securitySchemes[authParam.name]) {
100
- openApi.components.securitySchemes[authParam.name] =
101
- authParam;
98
+ const { permissions, ...mainFields } = authParam;
99
+ let fullName = authParam.name;
100
+ if (permissions) {
101
+ fullName = `${fullName}-permissions-${permissions}`;
102
+ }
103
+
104
+ if (!openApi.components.securitySchemes[fullName]) {
105
+ openApi.components.securitySchemes[fullName] = mainFields;
102
106
  }
103
107
 
104
108
  securitySchemaNames.push({
105
- [authParam.name]: [],
109
+ [fullName]: [],
106
110
  });
107
111
  }
108
112
  }
@@ -0,0 +1,37 @@
1
+ const path = require('node:path');
2
+ const AbstractCommand = require('../modules/AbstractCommand');
3
+
4
+ class SyncIndexes extends AbstractCommand {
5
+ async run() {
6
+ const files = await this.getFilesPathWithInheritance(
7
+ `${__dirname}/../models`,
8
+ this.app.foldersConfig.models,
9
+ );
10
+ let models = [];
11
+
12
+ for (const file of files) {
13
+ models.push(path.basename(file.file, path.extname(file.file)));
14
+ }
15
+ models = models.sort();
16
+ this.logger.info(`Total found ${models.length} models`);
17
+
18
+ for (const modelName of models) {
19
+ const Model = this.app.getModel(modelName);
20
+ // eslint-disable-next-line no-await-in-loop
21
+ const removedIndexes = await Model.syncIndexes(); // that not a bug. Lets do one by one
22
+ if (removedIndexes.length) {
23
+ this.logger.info(
24
+ `Model - ${modelName} removed indexes: ${removedIndexes}`,
25
+ );
26
+ } else {
27
+ this.logger.info(`Model - ${modelName} NO removed indexes`);
28
+ }
29
+ }
30
+ }
31
+
32
+ static get description() {
33
+ return 'Synchronize indexes defined in models with a real one indexed on the database. Command will remove all indexes from the database that do not exist on model OR have different parameters. Then it will create a new indexes ';
34
+ }
35
+ }
36
+
37
+ module.exports = SyncIndexes;
@@ -98,7 +98,8 @@ class AbstractController extends Base {
98
98
  path: realPath,
99
99
  fullPath,
100
100
  params: middlewareParams,
101
- authParams: MiddlewareFunction?.usedAuthParameters,
101
+ authParams: new MiddlewareFunction(this.app, middlewareParams)
102
+ ?.usedAuthParameters,
102
103
  MiddlewareFunction,
103
104
  });
104
105
  }
@@ -209,6 +210,7 @@ class AbstractController extends Base {
209
210
  try {
210
211
  await routeObject.request.validate(bodyAndQuery, {
211
212
  abortEarly: controllerValidationAbortEarly,
213
+ req,
212
214
  });
213
215
  } catch (e) {
214
216
  let { errors } = e;
@@ -242,6 +244,7 @@ class AbstractController extends Base {
242
244
  bodyAndQuery,
243
245
  {
244
246
  stripUnknown: true,
247
+ req,
245
248
  },
246
249
  );
247
250
  }
package/modules/Base.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const fs = require('fs').promises;
2
- const { join } = require('path');
2
+ const { join, normalize } = require('path');
3
3
 
4
4
  class Base {
5
5
  #realLogger = null;
@@ -108,7 +108,7 @@ class Base {
108
108
  return null;
109
109
  }),
110
110
  );
111
- return allFiles.map((file) => file.replace(`${dir}/`, ''));
111
+ return allFiles.map((file) => file.replace(`${normalize(dir)}/`, ''));
112
112
  }
113
113
 
114
114
  let [internalFiles, externalFiles] = await Promise.all([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptivestone/framework",
3
- "version": "3.2.2",
3
+ "version": "3.4.0",
4
4
  "description": "Adaptive stone node js framework",
5
5
  "main": "src/index.js",
6
6
  "engines": {
@@ -49,7 +49,6 @@
49
49
  "nodemailer": "^6.6.3",
50
50
  "nodemailer-sendmail-transport": "^1.0.2",
51
51
  "nodemailer-stub-transport": "^1.1.0",
52
- "prettier": "^2.3.2",
53
52
  "pug": "^3.0.2",
54
53
  "rate-limiter-flexible": "^2.2.4",
55
54
  "redis": "^4.3.1",
@@ -68,6 +67,7 @@
68
67
  "lint-staged": "^13.0.0",
69
68
  "mongodb-memory-server": "^8.0.2",
70
69
  "nodemon": "^2.0.12",
70
+ "prettier": "^2.3.2",
71
71
  "supertest": "^6.1.4"
72
72
  },
73
73
  "lint-staged": {
@@ -5,7 +5,7 @@ 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
- static get usedAuthParameters() {
8
+ get usedAuthParameters() {
9
9
  return [
10
10
  {
11
11
  name: 'Authorization',