@midwayjs/validate 3.7.0 → 3.7.3
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/service.d.ts +2 -2
- package/dist/service.js +6 -20
- package/package.json +6 -6
package/dist/service.d.ts
CHANGED
|
@@ -12,12 +12,12 @@ export declare class ValidateService {
|
|
|
12
12
|
errorStatus?: number;
|
|
13
13
|
locale?: string;
|
|
14
14
|
validationOptions?: Joi.ValidationOptions;
|
|
15
|
-
}): Joi.ValidationResult<T
|
|
15
|
+
}): Joi.ValidationResult<T> | undefined;
|
|
16
16
|
validateWithSchema<T>(schema: ObjectSchema<any>, value: any, options?: {
|
|
17
17
|
errorStatus?: number;
|
|
18
18
|
locale?: string;
|
|
19
19
|
validationOptions?: Joi.ValidationOptions;
|
|
20
|
-
}): Joi.ValidationResult<T
|
|
20
|
+
}): Joi.ValidationResult<T> | undefined;
|
|
21
21
|
getSchema<T extends new (...args: any[]) => any>(ClzType: T): ObjectSchema<any>;
|
|
22
22
|
}
|
|
23
23
|
export declare function getSchema<T extends new (...args: any[]) => any>(ClzType: T): ObjectSchema<any>;
|
package/dist/service.js
CHANGED
|
@@ -27,34 +27,20 @@ let ValidateService = class ValidateService {
|
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
validate(ClzType, value, options = {}) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
options.validationOptions.errors = options.validationOptions.errors || {};
|
|
33
|
-
options.validationOptions.errors.language = (0, i18n_1.formatLocale)(this.i18nService.getAvailableLocale(options.validationOptions.errors.language ||
|
|
34
|
-
options.locale ||
|
|
35
|
-
this.i18nConfig.defaultLocale, 'validate'));
|
|
36
|
-
const rules = (0, core_1.getClassExtendedMetadata)(constants_1.RULES_KEY, ClzType);
|
|
37
|
-
if (rules) {
|
|
38
|
-
const schema = Joi.object(rules);
|
|
39
|
-
const result = schema.validate(value, Object.assign((_a = this.validateConfig.validationOptions) !== null && _a !== void 0 ? _a : {}, {
|
|
40
|
-
messages: this.messages,
|
|
41
|
-
}, (_b = options.validationOptions) !== null && _b !== void 0 ? _b : {}));
|
|
42
|
-
if (result.error) {
|
|
43
|
-
throw new error_1.MidwayValidationError(result.error.message, (_c = options === null || options === void 0 ? void 0 : options.errorStatus) !== null && _c !== void 0 ? _c : this.validateConfig.errorStatus, result.error);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
30
|
+
const objectSchema = this.getSchema(ClzType);
|
|
31
|
+
return this.validateWithSchema(objectSchema, value, options);
|
|
49
32
|
}
|
|
50
33
|
validateWithSchema(schema, value, options = {}) {
|
|
51
34
|
var _a, _b, _c;
|
|
35
|
+
if (!schema) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
52
38
|
options.validationOptions = options.validationOptions || {};
|
|
53
39
|
options.validationOptions.errors = options.validationOptions.errors || {};
|
|
54
40
|
options.validationOptions.errors.language = (0, i18n_1.formatLocale)(this.i18nService.getAvailableLocale(options.validationOptions.errors.language ||
|
|
55
41
|
options.locale ||
|
|
56
42
|
this.i18nConfig.defaultLocale, 'validate'));
|
|
57
|
-
const result = schema.validate(value, Object.assign((_a = this.validateConfig.validationOptions) !== null && _a !== void 0 ? _a : {}, {
|
|
43
|
+
const result = schema.validate(value, Object.assign({}, (_a = this.validateConfig.validationOptions) !== null && _a !== void 0 ? _a : {}, {
|
|
58
44
|
messages: this.messages,
|
|
59
45
|
}, (_b = options.validationOptions) !== null && _b !== void 0 ? _b : {}));
|
|
60
46
|
if (result.error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/validate",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.3",
|
|
4
4
|
"description": "Midway Component for mongoose",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -23,14 +23,14 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@midwayjs/i18n": "^3.7.
|
|
26
|
+
"@midwayjs/i18n": "^3.7.3",
|
|
27
27
|
"joi": "^17.2.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@midwayjs/core": "^3.7.0",
|
|
31
|
-
"@midwayjs/express": "^3.7.
|
|
32
|
-
"@midwayjs/koa": "^3.7.
|
|
33
|
-
"@midwayjs/mock": "^3.7.
|
|
31
|
+
"@midwayjs/express": "^3.7.3",
|
|
32
|
+
"@midwayjs/koa": "^3.7.3",
|
|
33
|
+
"@midwayjs/mock": "^3.7.3"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "8e6c830bca52818e0086873b542423d16e609aef"
|
|
36
36
|
}
|