@steroidsjs/nest 2.1.1 → 2.2.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/infrastructure/applications/rest/config.d.ts +2 -2
- package/infrastructure/applications/rest/config.js +2 -2
- package/infrastructure/applications/rest/config.js.map +1 -1
- package/infrastructure/decorators/fields/TextField.js +26 -19
- package/infrastructure/decorators/fields/TextField.js.map +1 -1
- package/infrastructure/filters/ValidationExceptionFilter.d.ts +1 -2
- package/infrastructure/filters/ValidationExceptionFilter.js +3 -20
- package/infrastructure/filters/ValidationExceptionFilter.js.map +1 -1
- package/package.json +2 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/usecases/exceptions/ValidationException.d.ts +3 -4
- package/usecases/exceptions/ValidationException.js.map +1 -1
- package/usecases/helpers/ValidationHelper.d.ts +6 -3
- package/usecases/helpers/ValidationHelper.js +80 -43
- package/usecases/helpers/ValidationHelper.js.map +1 -1
- package/usecases/interfaces/IErrorsCompositeObject.d.ts +3 -0
- package/usecases/interfaces/{IFormError.js → IErrorsCompositeObject.js} +1 -1
- package/usecases/interfaces/IErrorsCompositeObject.js.map +1 -0
- package/infrastructure/applications/rest/filters/ValidationExceptionFilterCustom.d.ts +0 -10
- package/infrastructure/applications/rest/filters/ValidationExceptionFilterCustom.js +0 -49
- package/infrastructure/applications/rest/filters/ValidationExceptionFilterCustom.js.map +0 -1
- package/usecases/interfaces/IFormError.d.ts +0 -3
- package/usecases/interfaces/IFormError.js.map +0 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IFormError } from '../interfaces/IFormError';
|
|
1
|
+
import { IErrorsCompositeObject } from '../interfaces/IErrorsCompositeObject';
|
|
3
2
|
export declare class ValidationException {
|
|
4
|
-
errors:
|
|
5
|
-
constructor(errors:
|
|
3
|
+
errors: IErrorsCompositeObject;
|
|
4
|
+
constructor(errors: IErrorsCompositeObject);
|
|
6
5
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValidationException.js","sourceRoot":"","sources":["../../../src/usecases/exceptions/ValidationException.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"ValidationException.js","sourceRoot":"","sources":["../../../src/usecases/exceptions/ValidationException.ts"],"names":[],"mappings":";;;AAEA,MAAa,mBAAmB;IAG5B,YAAY,MAA8B;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AAND,kDAMC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { ValidatorOptions } from 'class-validator';
|
|
1
|
+
import { ValidationError, ValidatorOptions } from 'class-validator';
|
|
2
2
|
import { IValidator, IValidatorParams } from '../interfaces/IValidator';
|
|
3
|
+
import { IErrorsCompositeObject } from '../interfaces/IErrorsCompositeObject';
|
|
3
4
|
export declare function validateOrReject(dto: any, validatorOptions?: ValidatorOptions): Promise<void>;
|
|
4
5
|
export declare class ValidationHelper {
|
|
5
6
|
static validate(dto: any, params?: IValidatorParams, allValidators?: IValidator[]): Promise<void>;
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
static getClassValidatorErrors(dto: any): Promise<IErrorsCompositeObject | null>;
|
|
8
|
+
static getSteroidsErrors(dto: any, params?: IValidatorParams, validatorsInstances?: IValidator[]): Promise<IErrorsCompositeObject | null>;
|
|
9
|
+
protected static getSteroidsFieldValidatorsErrors(dto: any, key: string, params: IValidatorParams, validatorsInstances: IValidator[]): Promise<string[]>;
|
|
10
|
+
static parseClassValidatorErrors(errors: ValidationError[]): IErrorsCompositeObject;
|
|
8
11
|
}
|
|
@@ -12,8 +12,9 @@ const defaultValidatorOptions = {
|
|
|
12
12
|
forbidUnknownValues: false,
|
|
13
13
|
};
|
|
14
14
|
async function validateOrReject(dto, validatorOptions) {
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
15
|
+
const classValidatorErrors = await (0, class_validator_1.validate)(dto, Object.assign(Object.assign({}, defaultValidatorOptions), validatorOptions));
|
|
16
|
+
if (classValidatorErrors.length) {
|
|
17
|
+
const errors = ValidationHelper.parseClassValidatorErrors(classValidatorErrors);
|
|
17
18
|
throw new exceptions_1.ValidationException(errors);
|
|
18
19
|
}
|
|
19
20
|
}
|
|
@@ -21,75 +22,111 @@ exports.validateOrReject = validateOrReject;
|
|
|
21
22
|
class ValidationHelper {
|
|
22
23
|
static async validate(dto, params = null, allValidators = null) {
|
|
23
24
|
var _a;
|
|
24
|
-
await
|
|
25
|
-
const
|
|
25
|
+
const classValidatorErrors = await this.getClassValidatorErrors(dto);
|
|
26
|
+
const steroidsValidatorsErrors = await this.getSteroidsErrors(dto, params, allValidators);
|
|
27
|
+
const errors = (0, lodash_1.mergeWith)(classValidatorErrors, steroidsValidatorsErrors, (objValue, srcValue) => {
|
|
28
|
+
if (Array.isArray(objValue)) {
|
|
29
|
+
return objValue.concat(srcValue);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
26
32
|
if (errors && ((_a = Object.keys(errors)) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
27
33
|
throw new exceptions_1.ValidationException(errors);
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
|
-
static async
|
|
36
|
+
static async getClassValidatorErrors(dto) {
|
|
31
37
|
const errors = await (0, class_validator_1.validate)(dto, defaultValidatorOptions);
|
|
32
38
|
if (errors.length) {
|
|
33
|
-
|
|
39
|
+
return this.parseClassValidatorErrors(errors);
|
|
34
40
|
}
|
|
41
|
+
return null;
|
|
35
42
|
}
|
|
36
|
-
static async
|
|
37
|
-
var _a, _b
|
|
43
|
+
static async getSteroidsErrors(dto, params = null, validatorsInstances = null) {
|
|
44
|
+
var _a, _b;
|
|
38
45
|
if (!dto) {
|
|
39
46
|
return;
|
|
40
47
|
}
|
|
41
48
|
const errors = {};
|
|
42
|
-
const keys = (0, BaseField_1.isMetaClass)(dto.constructor)
|
|
49
|
+
const keys = (0, BaseField_1.isMetaClass)(dto.constructor)
|
|
50
|
+
? (0, BaseField_1.getMetaFields)(dto.constructor)
|
|
51
|
+
: Object.keys(dto);
|
|
43
52
|
for (const key of keys) {
|
|
44
53
|
const value = dto[key];
|
|
45
54
|
const nextParams = Object.assign(Object.assign({}, params), { name: key, prevModel: ((_a = params === null || params === void 0 ? void 0 : params.prevModel) === null || _a === void 0 ? void 0 : _a[key]) || null, nextModel: ((_b = params === null || params === void 0 ? void 0 : params.nextModel) === null || _b === void 0 ? void 0 : _b[key]) || null });
|
|
46
|
-
let
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
errors[key] = Object.assign(Object.assign({}, ((errors === null || errors === void 0 ? void 0 : errors[key]) || {})), { [valueItemIndex]: error });
|
|
53
|
-
}
|
|
55
|
+
let keyErrors = null;
|
|
56
|
+
if (Array.isArray(value)) {
|
|
57
|
+
for (const valueItemIndex in value) {
|
|
58
|
+
const arrayItemErrors = await this.getSteroidsErrors(value[valueItemIndex], nextParams, validatorsInstances);
|
|
59
|
+
if (arrayItemErrors) {
|
|
60
|
+
keyErrors = Object.assign(Object.assign({}, (keyErrors || {})), { [valueItemIndex]: arrayItemErrors });
|
|
54
61
|
}
|
|
55
62
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
63
|
+
}
|
|
64
|
+
else if (value && (0, lodash_1.isObject)(value)) {
|
|
65
|
+
keyErrors = await this.getSteroidsErrors(value, nextParams, validatorsInstances);
|
|
66
|
+
}
|
|
67
|
+
if (keyErrors) {
|
|
68
|
+
errors[key] = keyErrors;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const fieldValidatorsErrors = await this.getSteroidsFieldValidatorsErrors(dto, key, params, validatorsInstances);
|
|
72
|
+
if ((fieldValidatorsErrors === null || fieldValidatorsErrors === void 0 ? void 0 : fieldValidatorsErrors.length) > 0) {
|
|
73
|
+
errors[key] = fieldValidatorsErrors;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (Object.keys(errors).length > 0) {
|
|
77
|
+
return errors;
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
static async getSteroidsFieldValidatorsErrors(dto, key, params, validatorsInstances) {
|
|
82
|
+
let fieldValidatorErrors = [];
|
|
83
|
+
const fieldValidators = (0, Validator_1.getFieldValidators)(dto.constructor, key);
|
|
84
|
+
for (const fieldValidator of fieldValidators) {
|
|
85
|
+
try {
|
|
86
|
+
const validator = (validatorsInstances || []).find(item => {
|
|
87
|
+
try {
|
|
88
|
+
return item instanceof fieldValidator;
|
|
75
89
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
+ ' Please add it to CrudService.validators array.');
|
|
90
|
+
catch (e) {
|
|
91
|
+
return false;
|
|
79
92
|
}
|
|
80
|
-
|
|
93
|
+
});
|
|
94
|
+
if (!validator && typeof fieldValidator === 'function') {
|
|
95
|
+
await fieldValidator(dto, Object.assign(Object.assign({}, params), { name: key }));
|
|
96
|
+
continue;
|
|
81
97
|
}
|
|
98
|
+
if (!validator) {
|
|
99
|
+
throw new Error(`Not found validator instance for "${dto.constructor.name}.${key}"`
|
|
100
|
+
+ ' Please add it to CrudService.validators array.');
|
|
101
|
+
}
|
|
102
|
+
await validator.validate(dto, Object.assign(Object.assign({}, params), { name: key }));
|
|
82
103
|
}
|
|
83
104
|
catch (e) {
|
|
84
105
|
if (e instanceof FieldValidatorException_1.FieldValidatorException) {
|
|
85
|
-
|
|
106
|
+
fieldValidatorErrors.push(e.message);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
throw e;
|
|
86
110
|
}
|
|
87
111
|
}
|
|
88
112
|
}
|
|
89
|
-
|
|
113
|
+
return fieldValidatorErrors;
|
|
114
|
+
}
|
|
115
|
+
static parseClassValidatorErrors(errors) {
|
|
116
|
+
var _a;
|
|
117
|
+
if (!Array.isArray(errors)) {
|
|
90
118
|
return errors;
|
|
91
119
|
}
|
|
92
|
-
|
|
120
|
+
const result = {};
|
|
121
|
+
for (const error of errors) {
|
|
122
|
+
if (error.constraints) {
|
|
123
|
+
result[error.property] = [].concat(Object.values(error.constraints));
|
|
124
|
+
}
|
|
125
|
+
if (((_a = error.children) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
126
|
+
result[error.property] = this.parseClassValidatorErrors(error.children);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
93
130
|
}
|
|
94
131
|
}
|
|
95
132
|
exports.ValidationHelper = ValidationHelper;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValidationHelper.js","sourceRoot":"","sources":["../../../src/usecases/helpers/ValidationHelper.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ValidationHelper.js","sourceRoot":"","sources":["../../../src/usecases/helpers/ValidationHelper.ts"],"names":[],"mappings":";;;AAAA,mCAAsE;AACtE,qDAA4E;AAC5E,8CAAkD;AAElD,mFAA8E;AAC9E,gFAA4F;AAC5F,uDAA2D;AAG3D,MAAM,uBAAuB,GAAqB;IAC9C,SAAS,EAAE,KAAK;IAChB,mBAAmB,EAAE,KAAK;CAC7B,CAAC;AAMK,KAAK,UAAU,gBAAgB,CAAC,GAAQ,EAAE,gBAAmC;IAChF,MAAM,oBAAoB,GAAG,MAAM,IAAA,0BAAQ,EACvC,GAAG,kCACC,uBAAuB,GAAK,gBAAgB,EACnD,CAAC;IACF,IAAI,oBAAoB,CAAC,MAAM,EAAE;QAC7B,MAAM,MAAM,GAAG,gBAAgB,CAAC,yBAAyB,CAAC,oBAAoB,CAAC,CAAC;QAChF,MAAM,IAAI,gCAAmB,CAAC,MAAM,CAAC,CAAC;KACzC;AACL,CA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AC;aACN;YAAC,OAAO,CAAC,EAAE;gBAER,IAAI,CAAC,YAAY,iDAAuB,EAAE;oBACtC,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;iBACxC;qBAAM;oBACH,MAAM,CAAC,CAAC;iBACX;aACJ;SACJ;QAED,OAAO,oBAAoB,CAAC;IAChC,CAAC;IAEM,MAAM,CAAC,yBAAyB,CAAC,MAAyB;;QAC7D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACxB,OAAO,MAAM,CAAC;SACjB;QAED,MAAM,MAAM,GAA2B,EAAE,CAAC;QAC1C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;YACxB,IAAI,KAAK,CAAC,WAAW,EAAE;gBACnB,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;aACxE;YACD,IAAI,CAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,MAAM,IAAG,CAAC,EAAE;gBAC5B,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,yBAAyB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;aAC3E;SACJ;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AA9KD,4CA8KC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IErrorsCompositeObject.js","sourceRoot":"","sources":["../../../src/usecases/interfaces/IErrorsCompositeObject.ts"],"names":[],"mappings":""}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ExceptionFilter, ArgumentsHost } from '@nestjs/common';
|
|
2
|
-
import { ValidationException } from '../../../../usecases/exceptions';
|
|
3
|
-
type ErrorsCompositeObject = {
|
|
4
|
-
[propertyName: string]: string[] | ErrorsCompositeObject;
|
|
5
|
-
};
|
|
6
|
-
export declare class ValidationExceptionFilterCustom implements ExceptionFilter {
|
|
7
|
-
parseErrors(errors: any, contextLanguage: string): Promise<ErrorsCompositeObject>;
|
|
8
|
-
catch(exception: ValidationException, host: ArgumentsHost): Promise<void>;
|
|
9
|
-
}
|
|
10
|
-
export {};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.ValidationExceptionFilterCustom = void 0;
|
|
10
|
-
const common_1 = require("@nestjs/common");
|
|
11
|
-
const class_validator_1 = require("class-validator");
|
|
12
|
-
const exceptions_1 = require("../../../../usecases/exceptions");
|
|
13
|
-
let ValidationExceptionFilterCustom = class ValidationExceptionFilterCustom {
|
|
14
|
-
async parseErrors(errors, contextLanguage) {
|
|
15
|
-
if (!Array.isArray(errors)) {
|
|
16
|
-
return errors;
|
|
17
|
-
}
|
|
18
|
-
return errors
|
|
19
|
-
.filter(error => error instanceof class_validator_1.ValidationError)
|
|
20
|
-
.reduce(async (result, error) => {
|
|
21
|
-
var _a;
|
|
22
|
-
if (((_a = error.children) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
23
|
-
result[error.property] = this.parseErrors(error.children, contextLanguage);
|
|
24
|
-
return result;
|
|
25
|
-
}
|
|
26
|
-
if (!error.constraints) {
|
|
27
|
-
return result;
|
|
28
|
-
}
|
|
29
|
-
result[error.property] = Object.values(error.constraints);
|
|
30
|
-
return result;
|
|
31
|
-
}, {});
|
|
32
|
-
}
|
|
33
|
-
async catch(exception, host) {
|
|
34
|
-
const ctx = host.switchToHttp();
|
|
35
|
-
const response = ctx.getResponse();
|
|
36
|
-
const errors = await this.parseErrors(exception.errors, ctx.getRequest().i18nLang);
|
|
37
|
-
response
|
|
38
|
-
.status(common_1.HttpStatus.OK)
|
|
39
|
-
.json({
|
|
40
|
-
statusCode: common_1.HttpStatus.BAD_REQUEST,
|
|
41
|
-
errors,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
ValidationExceptionFilterCustom = __decorate([
|
|
46
|
-
(0, common_1.Catch)(exceptions_1.ValidationException)
|
|
47
|
-
], ValidationExceptionFilterCustom);
|
|
48
|
-
exports.ValidationExceptionFilterCustom = ValidationExceptionFilterCustom;
|
|
49
|
-
//# sourceMappingURL=ValidationExceptionFilterCustom.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ValidationExceptionFilterCustom.js","sourceRoot":"","sources":["../../../../../src/infrastructure/applications/rest/filters/ValidationExceptionFilterCustom.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAiF;AAEjF,qDAAgD;AAChD,gEAAoE;AAQ7D,IAAM,+BAA+B,GAArC,MAAM,+BAA+B;IACxC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,eAAuB;QAC7C,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACxB,OAAO,MAAM,CAAC;SACjB;QAED,OAAO,MAAM;aACR,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,YAAY,iCAAe,CAAC;aACjD,MAAM,CACH,KAAK,EAAE,MAAW,EAAE,KAAsB,EAAkC,EAAE;;YAC1E,IAAI,CAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,MAAM,IAAG,CAAC,EAAE;gBAC5B,MAAM,CAAC,KAAK,CAAC,QAAQ,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