@adaptivestone/framework 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.
- package/CHANGELOG.md +11 -0
- package/commands/GetOpenApiJson.js +9 -5
- package/commands/SyncIndexes.js +37 -0
- package/config/i18n.js +2 -0
- package/modules/AbstractController.js +2 -1
- package/modules/Base.js +2 -2
- package/package.json +2 -2
- package/services/http/HttpServer.js +2 -2
- package/services/http/middleware/GetUserByToken.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
### 3.3.0
|
|
2
|
+
|
|
3
|
+
[NEW] new command 'SyncIndexes' to sync indexes for mongodb https://framework.adaptivestone.com/docs/cli#syncindexes
|
|
4
|
+
[UPDATE] updated deps
|
|
5
|
+
[FIX] fix documentation generation
|
|
6
|
+
|
|
7
|
+
### 3.2.2
|
|
8
|
+
|
|
9
|
+
[UPDATE] add options for i18n to config.
|
|
10
|
+
[CHANGE] by default i18n not writing missed keys. Can be enabled via config
|
|
11
|
+
|
|
1
12
|
### 3.2.1
|
|
2
13
|
|
|
3
14
|
[UPDATE] updated deps
|
|
@@ -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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
[
|
|
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;
|
package/config/i18n.js
CHANGED
|
@@ -2,6 +2,8 @@ module.exports = {
|
|
|
2
2
|
enabled: true,
|
|
3
3
|
preload: ['en', 'ru'],
|
|
4
4
|
fallbackLng: 'en',
|
|
5
|
+
saveMissing: false,
|
|
6
|
+
debug: false,
|
|
5
7
|
// https://github.com/i18next/i18next-http-middleware#detector-options
|
|
6
8
|
// in additional we have 'xLang' that detect language based on header 'xLang'
|
|
7
9
|
langDetectionOders: ['xLang'], // from order option
|
|
@@ -98,7 +98,8 @@ class AbstractController extends Base {
|
|
|
98
98
|
path: realPath,
|
|
99
99
|
fullPath,
|
|
100
100
|
params: middlewareParams,
|
|
101
|
-
authParams: MiddlewareFunction
|
|
101
|
+
authParams: new MiddlewareFunction(this.app, middlewareParams)
|
|
102
|
+
?.usedAuthParameters,
|
|
102
103
|
MiddlewareFunction,
|
|
103
104
|
});
|
|
104
105
|
}
|
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.
|
|
3
|
+
"version": "3.3.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": {
|
|
@@ -133,8 +133,8 @@ class HttpServer extends Base {
|
|
|
133
133
|
},
|
|
134
134
|
fallbackLng: I18NConfig.fallbackLng,
|
|
135
135
|
preload: I18NConfig.preload,
|
|
136
|
-
saveMissing:
|
|
137
|
-
debug:
|
|
136
|
+
saveMissing: I18NConfig.saveMissing,
|
|
137
|
+
debug: I18NConfig.debug,
|
|
138
138
|
detection: {
|
|
139
139
|
// caches: ['cookie'],
|
|
140
140
|
order: I18NConfig.langDetectionOders || ['xLang'],
|
|
@@ -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
|
-
|
|
8
|
+
get usedAuthParameters() {
|
|
9
9
|
return [
|
|
10
10
|
{
|
|
11
11
|
name: 'Authorization',
|