@midwayjs/validate 3.5.3 → 3.7.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/dist/configuration.js +4 -5
- package/dist/decorator/rule.js +7 -7
- package/dist/decorator/validate.js +2 -2
- package/dist/dtoHelper.js +5 -5
- package/dist/service.js +9 -9
- package/index.d.ts +2 -1
- package/package.json +7 -8
package/dist/configuration.js
CHANGED
|
@@ -10,7 +10,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.ValidateConfiguration = void 0;
|
|
13
|
-
const decorator_1 = require("@midwayjs/decorator");
|
|
14
13
|
const core_1 = require("@midwayjs/core");
|
|
15
14
|
const constants_1 = require("./constants");
|
|
16
15
|
const util = require("util");
|
|
@@ -24,7 +23,7 @@ let ValidateConfiguration = class ValidateConfiguration {
|
|
|
24
23
|
this.decoratorService.registerMethodHandler(constants_1.VALIDATE_KEY, options => {
|
|
25
24
|
var _a;
|
|
26
25
|
// get param types from method
|
|
27
|
-
const paramTypes = (0,
|
|
26
|
+
const paramTypes = (0, core_1.getMethodParamTypes)(options.target, options.propertyName);
|
|
28
27
|
const validateOptions = (_a = options.metadata) === null || _a === void 0 ? void 0 : _a.options;
|
|
29
28
|
// add aspect method
|
|
30
29
|
return {
|
|
@@ -48,15 +47,15 @@ let ValidateConfiguration = class ValidateConfiguration {
|
|
|
48
47
|
}
|
|
49
48
|
};
|
|
50
49
|
__decorate([
|
|
51
|
-
(0,
|
|
50
|
+
(0, core_1.Inject)(),
|
|
52
51
|
__metadata("design:type", core_1.MidwayDecoratorService)
|
|
53
52
|
], ValidateConfiguration.prototype, "decoratorService", void 0);
|
|
54
53
|
__decorate([
|
|
55
|
-
(0,
|
|
54
|
+
(0, core_1.Inject)(),
|
|
56
55
|
__metadata("design:type", service_1.ValidateService)
|
|
57
56
|
], ValidateConfiguration.prototype, "validateService", void 0);
|
|
58
57
|
ValidateConfiguration = __decorate([
|
|
59
|
-
(0,
|
|
58
|
+
(0, core_1.Configuration)({
|
|
60
59
|
namespace: 'validate',
|
|
61
60
|
imports: [i18n],
|
|
62
61
|
importConfigs: [
|
package/dist/decorator/rule.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RuleType = exports.Rule = void 0;
|
|
4
4
|
const joi = require("joi");
|
|
5
5
|
exports.RuleType = joi;
|
|
6
|
-
const
|
|
6
|
+
const core_1 = require("@midwayjs/core");
|
|
7
7
|
const constants_1 = require("../constants");
|
|
8
8
|
function Rule(rule, options = { required: true }) {
|
|
9
9
|
return function (...args) {
|
|
@@ -12,9 +12,9 @@ function Rule(rule, options = { required: true }) {
|
|
|
12
12
|
const [target, propertyKey] = args;
|
|
13
13
|
if (!joi.isSchema(rule)) {
|
|
14
14
|
rule = joi
|
|
15
|
-
.object((0,
|
|
15
|
+
.object((0, core_1.getClassMetadata)(constants_1.RULES_KEY, rule))
|
|
16
16
|
.meta({ id: rule.name });
|
|
17
|
-
if ((0,
|
|
17
|
+
if ((0, core_1.getPropertyType)(target, propertyKey).name === 'Array') {
|
|
18
18
|
rule = joi.array().items(rule);
|
|
19
19
|
if (options.min) {
|
|
20
20
|
rule = rule.min(options.min);
|
|
@@ -27,20 +27,20 @@ function Rule(rule, options = { required: true }) {
|
|
|
27
27
|
rule = rule.required();
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
(0,
|
|
30
|
+
(0, core_1.attachClassMetadata)(constants_1.RULES_KEY, rule, target, propertyKey);
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
33
|
//类的装饰器
|
|
34
|
-
const rules = (0,
|
|
34
|
+
const rules = (0, core_1.getClassMetadata)(constants_1.RULES_KEY, rule);
|
|
35
35
|
if (rules) {
|
|
36
|
-
let currentRule = (0,
|
|
36
|
+
let currentRule = (0, core_1.getClassMetadata)(constants_1.RULES_KEY, args[0]);
|
|
37
37
|
currentRule = currentRule !== null && currentRule !== void 0 ? currentRule : {};
|
|
38
38
|
Object.keys(rules).map(item => {
|
|
39
39
|
if (!currentRule[item]) {
|
|
40
40
|
currentRule[item] = rules[item];
|
|
41
41
|
}
|
|
42
42
|
});
|
|
43
|
-
(0,
|
|
43
|
+
(0, core_1.saveClassMetadata)(constants_1.RULES_KEY, currentRule, args[0]);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Validate = void 0;
|
|
4
|
-
const
|
|
4
|
+
const core_1 = require("@midwayjs/core");
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
function Validate(options = {}) {
|
|
7
|
-
return (0,
|
|
7
|
+
return (0, core_1.createCustomMethodDecorator)(constants_1.VALIDATE_KEY, {
|
|
8
8
|
options,
|
|
9
9
|
});
|
|
10
10
|
}
|
package/dist/dtoHelper.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OmitDto = exports.PickDto = void 0;
|
|
4
|
-
const
|
|
4
|
+
const core_1 = require("@midwayjs/core");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
function PickDto(dto, keys) {
|
|
7
7
|
const pickedDto = function () { };
|
|
8
8
|
pickedDto.prototype = dto.prototype;
|
|
9
|
-
const fatherRule = (0,
|
|
9
|
+
const fatherRule = (0, core_1.getClassExtendedMetadata)(constants_1.RULES_KEY, dto);
|
|
10
10
|
const pickedRule = {};
|
|
11
11
|
for (const key of keys) {
|
|
12
12
|
if (fatherRule[key]) {
|
|
13
13
|
pickedRule[key] = fatherRule[key];
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
(0,
|
|
16
|
+
(0, core_1.saveClassMetadata)(constants_1.RULES_KEY, pickedRule, pickedDto);
|
|
17
17
|
return pickedDto;
|
|
18
18
|
}
|
|
19
19
|
exports.PickDto = PickDto;
|
|
20
20
|
function OmitDto(dto, keys) {
|
|
21
21
|
const pickedDto = function () { };
|
|
22
22
|
pickedDto.prototype = dto.prototype;
|
|
23
|
-
const fatherRule = (0,
|
|
23
|
+
const fatherRule = (0, core_1.getClassExtendedMetadata)(constants_1.RULES_KEY, dto);
|
|
24
24
|
const pickedRule = Object.assign({}, fatherRule);
|
|
25
25
|
for (const key of keys) {
|
|
26
26
|
delete pickedRule[key];
|
|
27
27
|
}
|
|
28
|
-
(0,
|
|
28
|
+
(0, core_1.saveClassMetadata)(constants_1.RULES_KEY, pickedRule, pickedDto);
|
|
29
29
|
return pickedDto;
|
|
30
30
|
}
|
|
31
31
|
exports.OmitDto = OmitDto;
|
package/dist/service.js
CHANGED
|
@@ -10,7 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.getSchema = exports.ValidateService = void 0;
|
|
13
|
-
const
|
|
13
|
+
const core_1 = require("@midwayjs/core");
|
|
14
14
|
const DefaultConfig = require("./config/config.default");
|
|
15
15
|
const constants_1 = require("./constants");
|
|
16
16
|
const Joi = require("joi");
|
|
@@ -33,7 +33,7 @@ let ValidateService = class ValidateService {
|
|
|
33
33
|
options.validationOptions.errors.language = (0, i18n_1.formatLocale)(this.i18nService.getAvailableLocale(options.validationOptions.errors.language ||
|
|
34
34
|
options.locale ||
|
|
35
35
|
this.i18nConfig.defaultLocale, 'validate'));
|
|
36
|
-
const rules = (0,
|
|
36
|
+
const rules = (0, core_1.getClassExtendedMetadata)(constants_1.RULES_KEY, ClzType);
|
|
37
37
|
if (rules) {
|
|
38
38
|
const schema = Joi.object(rules);
|
|
39
39
|
const result = schema.validate(value, Object.assign((_a = this.validateConfig.validationOptions) !== null && _a !== void 0 ? _a : {}, {
|
|
@@ -69,30 +69,30 @@ let ValidateService = class ValidateService {
|
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
__decorate([
|
|
72
|
-
(0,
|
|
72
|
+
(0, core_1.Config)('validate'),
|
|
73
73
|
__metadata("design:type", Object)
|
|
74
74
|
], ValidateService.prototype, "validateConfig", void 0);
|
|
75
75
|
__decorate([
|
|
76
|
-
(0,
|
|
76
|
+
(0, core_1.Config)('i18n'),
|
|
77
77
|
__metadata("design:type", Object)
|
|
78
78
|
], ValidateService.prototype, "i18nConfig", void 0);
|
|
79
79
|
__decorate([
|
|
80
|
-
(0,
|
|
80
|
+
(0, core_1.Inject)(),
|
|
81
81
|
__metadata("design:type", i18n_1.MidwayI18nServiceSingleton)
|
|
82
82
|
], ValidateService.prototype, "i18nService", void 0);
|
|
83
83
|
__decorate([
|
|
84
|
-
(0,
|
|
84
|
+
(0, core_1.Init)(),
|
|
85
85
|
__metadata("design:type", Function),
|
|
86
86
|
__metadata("design:paramtypes", []),
|
|
87
87
|
__metadata("design:returntype", Promise)
|
|
88
88
|
], ValidateService.prototype, "init", null);
|
|
89
89
|
ValidateService = __decorate([
|
|
90
|
-
(0,
|
|
91
|
-
(0,
|
|
90
|
+
(0, core_1.Provide)(),
|
|
91
|
+
(0, core_1.Scope)(core_1.ScopeEnum.Singleton)
|
|
92
92
|
], ValidateService);
|
|
93
93
|
exports.ValidateService = ValidateService;
|
|
94
94
|
function getSchema(ClzType) {
|
|
95
|
-
const rules = (0,
|
|
95
|
+
const rules = (0, core_1.getClassExtendedMetadata)(constants_1.RULES_KEY, ClzType);
|
|
96
96
|
if (rules) {
|
|
97
97
|
return Joi.object(rules);
|
|
98
98
|
}
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/validate",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "Midway Component for mongoose",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -23,15 +23,14 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@midwayjs/i18n": "^3.
|
|
26
|
+
"@midwayjs/i18n": "^3.7.0",
|
|
27
27
|
"joi": "^17.2.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@midwayjs/core": "^3.
|
|
31
|
-
"@midwayjs/
|
|
32
|
-
"@midwayjs/
|
|
33
|
-
"@midwayjs/
|
|
34
|
-
"@midwayjs/mock": "^3.5.3"
|
|
30
|
+
"@midwayjs/core": "^3.7.0",
|
|
31
|
+
"@midwayjs/express": "^3.7.0",
|
|
32
|
+
"@midwayjs/koa": "^3.7.0",
|
|
33
|
+
"@midwayjs/mock": "^3.7.0"
|
|
35
34
|
},
|
|
36
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "99386083ee26b386fd508b9c892091c914e77535"
|
|
37
36
|
}
|