@midwayjs/decorator 2.13.2 → 2.14.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 +12 -0
- package/README.md +1 -1
- package/dist/annotation/validate.d.ts +7 -1
- package/dist/annotation/validate.js +17 -5
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [2.14.0](https://github.com/midwayjs/midway/compare/v2.13.5...v2.14.0) (2021-12-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* express routing middleware takes effect at the controller level ([#1364](https://github.com/midwayjs/midway/issues/1364)) ([5d5f299](https://github.com/midwayjs/midway/commit/5d5f2992be116ca71b21f01fd782e3a2ac072496))
|
|
12
|
+
* throws http code 422 when validation failed ([#1374](https://github.com/midwayjs/midway/issues/1374)) ([960d259](https://github.com/midwayjs/midway/commit/960d25909191558a4509632333d425be10a04813))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
6
18
|
## [2.13.2](https://github.com/midwayjs/midway/compare/v2.13.1...v2.13.2) (2021-09-09)
|
|
7
19
|
|
|
8
20
|
|
package/README.md
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
interface ValidateOptions {
|
|
2
|
+
isTransform?: boolean;
|
|
3
|
+
errorStatus?: number;
|
|
4
|
+
}
|
|
5
|
+
export declare function CustomValidate(opt: ValidateOptions): (customOpt?: ValidateOptions) => (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
6
|
+
export declare function Validate(opt?: boolean | ValidateOptions): (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => void;
|
|
7
|
+
export {};
|
|
2
8
|
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -1,28 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Validate = void 0;
|
|
3
|
+
exports.Validate = exports.CustomValidate = void 0;
|
|
4
4
|
const __1 = require("..");
|
|
5
5
|
const class_transformer_1 = require("class-transformer");
|
|
6
|
-
const
|
|
7
|
-
function
|
|
6
|
+
const joi = require("joi");
|
|
7
|
+
function CustomValidate(opt) {
|
|
8
|
+
return (customOpt = {}) => Validate({ ...opt, ...customOpt });
|
|
9
|
+
}
|
|
10
|
+
exports.CustomValidate = CustomValidate;
|
|
11
|
+
function Validate(opt = true) {
|
|
8
12
|
return function (target, propertyKey, descriptor) {
|
|
9
13
|
const origin = descriptor.value;
|
|
10
14
|
const paramTypes = (0, __1.getMethodParamTypes)(target, propertyKey);
|
|
15
|
+
const options = typeof opt === 'boolean' ? { isTransform: opt } : opt;
|
|
16
|
+
if (!('isTransform' in options)) {
|
|
17
|
+
options.isTransform = true;
|
|
18
|
+
}
|
|
11
19
|
descriptor.value = function (...args) {
|
|
12
20
|
for (let i = 0; i < paramTypes.length; i++) {
|
|
13
21
|
const item = paramTypes[i];
|
|
14
22
|
const rules = (0, __1.getClassExtendedMetadata)(__1.RULES_KEY, item);
|
|
15
23
|
if (rules) {
|
|
16
|
-
const schema =
|
|
24
|
+
const schema = joi.object(rules);
|
|
17
25
|
const result = schema.validate(args[i]);
|
|
18
26
|
if (result.error) {
|
|
27
|
+
if (options.errorStatus) {
|
|
28
|
+
result.error.status =
|
|
29
|
+
options.errorStatus;
|
|
30
|
+
}
|
|
19
31
|
throw result.error;
|
|
20
32
|
}
|
|
21
33
|
else {
|
|
22
34
|
args[i] = result.value;
|
|
23
35
|
}
|
|
24
36
|
// passed
|
|
25
|
-
if (isTransform) {
|
|
37
|
+
if (options.isTransform) {
|
|
26
38
|
args[i] = (0, class_transformer_1.plainToClass)(item, args[i]);
|
|
27
39
|
}
|
|
28
40
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/decorator",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.0",
|
|
4
4
|
"description": "definition decorator for midway project",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "5fd716b0e731162d8e9f0931790fde7402fb83de"
|
|
45
45
|
}
|