@adaptivestone/framework 3.0.12 → 3.0.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 +15 -1
- package/commands/migration/Create.js +0 -1
- package/commands/migration/Migrate.js +0 -1
- package/config/validate.js +3 -0
- package/models/User.js +2 -2
- package/modules/AbstractController.js +23 -8
- package/modules/Base.d.ts +1 -1
- package/modules/Base.js +5 -5
- package/package.json +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
|
+
### 3.0.15
|
|
2
|
+
|
|
3
|
+
[UPDATE] update deps
|
|
4
|
+
[UPDATE] minimum node version 16
|
|
5
|
+
|
|
6
|
+
### 3.0.14
|
|
7
|
+
|
|
8
|
+
[NEW] now possible to show all errors during validation (default one) by parameter controllerValidationAbortEarly
|
|
9
|
+
[UPDATE] update deps
|
|
10
|
+
|
|
11
|
+
### 3.0.13
|
|
12
|
+
|
|
13
|
+
[UPDATE] bug fix with "mergeParams"
|
|
14
|
+
|
|
1
15
|
### 3.0.12
|
|
2
16
|
|
|
3
|
-
[NEW] ability to pass "mergeParams" options to express
|
|
17
|
+
[NEW] ability to pass "mergeParams" options to express router
|
|
4
18
|
[UPDATE] update deps
|
|
5
19
|
|
|
6
20
|
### 3.0.11
|
package/models/User.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
1
2
|
const bcrypt = require('bcrypt');
|
|
2
3
|
|
|
3
4
|
const AbstractModel = require('../modules/AbstractModel');
|
|
@@ -99,8 +100,7 @@ class User extends AbstractModel {
|
|
|
99
100
|
avatar: this.avatar,
|
|
100
101
|
name: this.name,
|
|
101
102
|
email: this.email,
|
|
102
|
-
|
|
103
|
-
_id: this._id,
|
|
103
|
+
id: this.id,
|
|
104
104
|
isVerified: this.isVerified,
|
|
105
105
|
permissions: this.permissions,
|
|
106
106
|
locale: this.locale,
|
|
@@ -20,11 +20,11 @@ class AbstractController extends Base {
|
|
|
20
20
|
const time = Date.now();
|
|
21
21
|
super(app);
|
|
22
22
|
this.prefix = prefix;
|
|
23
|
-
this.router = express.Router(
|
|
24
|
-
const { routes } = this;
|
|
25
|
-
const expressPath = this.getExpressPath({
|
|
23
|
+
this.router = express.Router({
|
|
26
24
|
mergeParams: isExpressMergeParams,
|
|
27
25
|
});
|
|
26
|
+
const { routes } = this;
|
|
27
|
+
const expressPath = this.getExpressPath();
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Grab route middleware onlo one Map
|
|
@@ -188,7 +188,8 @@ class AbstractController extends Base {
|
|
|
188
188
|
new MiddlewareFunction(this.app, params).getMiddleware(),
|
|
189
189
|
);
|
|
190
190
|
}
|
|
191
|
-
|
|
191
|
+
const { controllerValidationAbortEarly } =
|
|
192
|
+
this.app.getConfig('validate');
|
|
192
193
|
this.router[verb](
|
|
193
194
|
path,
|
|
194
195
|
additionalMiddlewares || [],
|
|
@@ -203,7 +204,9 @@ class AbstractController extends Base {
|
|
|
203
204
|
const bodyAndQuery = merge(req.query, req.body);
|
|
204
205
|
|
|
205
206
|
try {
|
|
206
|
-
await routeObject.request.validate(bodyAndQuery
|
|
207
|
+
await routeObject.request.validate(bodyAndQuery, {
|
|
208
|
+
abortEarly: controllerValidationAbortEarly,
|
|
209
|
+
});
|
|
207
210
|
} catch (e) {
|
|
208
211
|
let { errors } = e;
|
|
209
212
|
// translate it
|
|
@@ -214,10 +217,22 @@ class AbstractController extends Base {
|
|
|
214
217
|
`Request validation failed with message: ${e.message}. errors: ${errors}`,
|
|
215
218
|
);
|
|
216
219
|
|
|
220
|
+
const errorAnswer = {};
|
|
221
|
+
if (!e.inner.length) {
|
|
222
|
+
errorAnswer[e.path] = errors;
|
|
223
|
+
} else {
|
|
224
|
+
e.inner.forEach((err) => {
|
|
225
|
+
errorAnswer[err.path] = err.errors;
|
|
226
|
+
if (req.i18n && err.errors) {
|
|
227
|
+
errorAnswer[err.path] = err.errors.map((err1) =>
|
|
228
|
+
req.i18n.t(err1),
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
217
234
|
return res.status(400).json({
|
|
218
|
-
errors:
|
|
219
|
-
[e.path]: errors,
|
|
220
|
-
},
|
|
235
|
+
errors: errorAnswer,
|
|
221
236
|
});
|
|
222
237
|
}
|
|
223
238
|
req.appInfo.request = routeObject.request.cast(bodyAndQuery, {
|
package/modules/Base.d.ts
CHANGED
package/modules/Base.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/* eslint-disable no-underscore-dangle */
|
|
2
1
|
const fs = require('fs').promises;
|
|
3
2
|
const { join } = require('path');
|
|
4
3
|
|
|
5
4
|
class Base {
|
|
5
|
+
#realLogger = null;
|
|
6
|
+
|
|
6
7
|
constructor(app) {
|
|
7
8
|
this.app = app;
|
|
8
|
-
this._realLogger = null;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -19,12 +19,12 @@ class Base {
|
|
|
19
19
|
* Optimzation to lazy load logger. It will be inited only on request
|
|
20
20
|
*/
|
|
21
21
|
get logger() {
|
|
22
|
-
if (!this
|
|
23
|
-
this
|
|
22
|
+
if (!this.#realLogger) {
|
|
23
|
+
this.#realLogger = this.getLogger(
|
|
24
24
|
this.constructor.loggerGroup + this.getConstructorName(),
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
|
-
return this
|
|
27
|
+
return this.#realLogger;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
/**
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaptivestone/framework",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.15",
|
|
4
4
|
"description": "Adaptive stone node js framework",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=16.0.0"
|
|
8
|
+
},
|
|
6
9
|
"repository": {
|
|
7
10
|
"type": "git",
|
|
8
11
|
"url": "https://gitlab.com/adaptivestone/framework"
|
|
@@ -55,7 +58,7 @@
|
|
|
55
58
|
"eslint-plugin-import": "^2.23.4",
|
|
56
59
|
"eslint-plugin-jest": "^26.0.0",
|
|
57
60
|
"husky": "^7.0.0",
|
|
58
|
-
"jest": "^
|
|
61
|
+
"jest": "^28.0.0",
|
|
59
62
|
"lint-staged": "^12.0.0",
|
|
60
63
|
"mongodb-memory-server": "^8.0.2",
|
|
61
64
|
"nodemon": "^2.0.12",
|