@pristine-ts/validation 0.0.284 → 0.0.285
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/lib/cjs/interceptors/body-validation.request-interceptor.js +6 -4
- package/dist/lib/cjs/interceptors/body-validation.request-interceptor.js.map +1 -1
- package/dist/lib/esm/interceptors/body-validation.request-interceptor.js +6 -4
- package/dist/lib/esm/interceptors/body-validation.request-interceptor.js.map +1 -1
- package/dist/types/interceptors/body-validation.request-interceptor.d.ts +3 -1
- package/package.json +6 -6
|
@@ -27,8 +27,8 @@ const networking_1 = require("@pristine-ts/networking");
|
|
|
27
27
|
const common_1 = require("@pristine-ts/common");
|
|
28
28
|
const validation_module_keyname_1 = require("../validation.module.keyname");
|
|
29
29
|
const tsyringe_1 = require("tsyringe");
|
|
30
|
-
const class_transformer_1 = require("class-transformer");
|
|
31
30
|
const body_validation_decorator_1 = require("../decorators/body-validation.decorator");
|
|
31
|
+
const data_mapping_common_1 = require("@pristine-ts/data-mapping-common");
|
|
32
32
|
/**
|
|
33
33
|
* This class is an interceptor to validate the body of an incoming request.
|
|
34
34
|
* It is tagged as an RequestInterceptor so it can be automatically injected with the all the other RequestInterceptors.
|
|
@@ -42,9 +42,10 @@ let BodyValidationRequestInterceptor = class BodyValidationRequestInterceptor {
|
|
|
42
42
|
* @param loghandler The log handler to output logs.
|
|
43
43
|
* @param validator The validator that validates objects.
|
|
44
44
|
*/
|
|
45
|
-
constructor(loghandler, validator) {
|
|
45
|
+
constructor(loghandler, validator, dataMapper) {
|
|
46
46
|
this.loghandler = loghandler;
|
|
47
47
|
this.validator = validator;
|
|
48
|
+
this.dataMapper = dataMapper;
|
|
48
49
|
}
|
|
49
50
|
/**
|
|
50
51
|
* Intercepts the request and validates that the body of the request matches the expected class.
|
|
@@ -64,7 +65,7 @@ let BodyValidationRequestInterceptor = class BodyValidationRequestInterceptor {
|
|
|
64
65
|
routeContext: methodNode.route.context,
|
|
65
66
|
}, validation_module_keyname_1.ValidationModuleKeyname);
|
|
66
67
|
// Validates that the body can be mapped to the expected type
|
|
67
|
-
const mappedBody =
|
|
68
|
+
const mappedBody = yield this.dataMapper.autoMap(request.body, bodyValidator.classType);
|
|
68
69
|
// Validates if all the conditions are respected in the expected type.
|
|
69
70
|
const errors = yield this.validator.validate(mappedBody);
|
|
70
71
|
if (errors.length == 0) {
|
|
@@ -81,6 +82,7 @@ exports.BodyValidationRequestInterceptor = BodyValidationRequestInterceptor = __
|
|
|
81
82
|
(0, common_1.tag)(common_1.ServiceDefinitionTagEnum.RequestInterceptor),
|
|
82
83
|
(0, tsyringe_1.injectable)(),
|
|
83
84
|
__param(0, (0, tsyringe_1.inject)("LogHandlerInterface")),
|
|
84
|
-
__metadata("design:paramtypes", [Object, class_validator_1.Validator
|
|
85
|
+
__metadata("design:paramtypes", [Object, class_validator_1.Validator,
|
|
86
|
+
data_mapping_common_1.DataMapper])
|
|
85
87
|
], BodyValidationRequestInterceptor);
|
|
86
88
|
//# sourceMappingURL=body-validation.request-interceptor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-validation.request-interceptor.js","sourceRoot":"","sources":["../../../../src/interceptors/body-validation.request-interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AACA,kEAAuD;AACvD,wDAA4D;AAC5D,gDAAyF;AACzF,4EAAqE;AACrE,uCAA4C;
|
|
1
|
+
{"version":3,"file":"body-validation.request-interceptor.js","sourceRoot":"","sources":["../../../../src/interceptors/body-validation.request-interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AACA,kEAAuD;AACvD,wDAA4D;AAC5D,gDAAyF;AACzF,4EAAqE;AACrE,uCAA4C;AAG5C,uFAAsF;AACtF,0EAA4D;AAE5D;;;;GAIG;AAII,IAAM,gCAAgC,GAAtC,MAAM,gCAAgC;IAEzC;;;;;;OAMG;IACH,YAA4D,UAA+B,EAC9D,SAAoB,EACpB,UA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,8 +24,8 @@ import { BadRequestHttpError } from "@pristine-ts/networking";
|
|
|
24
24
|
import { moduleScoped, ServiceDefinitionTagEnum, tag } from "@pristine-ts/common";
|
|
25
25
|
import { ValidationModuleKeyname } from "../validation.module.keyname";
|
|
26
26
|
import { injectable, inject } from "tsyringe";
|
|
27
|
-
import { plainToInstance } from 'class-transformer';
|
|
28
27
|
import { bodyValidationMetadataKeyname } from "../decorators/body-validation.decorator";
|
|
28
|
+
import { DataMapper } from "@pristine-ts/data-mapping-common";
|
|
29
29
|
/**
|
|
30
30
|
* This class is an interceptor to validate the body of an incoming request.
|
|
31
31
|
* It is tagged as an RequestInterceptor so it can be automatically injected with the all the other RequestInterceptors.
|
|
@@ -39,9 +39,10 @@ let BodyValidationRequestInterceptor = class BodyValidationRequestInterceptor {
|
|
|
39
39
|
* @param loghandler The log handler to output logs.
|
|
40
40
|
* @param validator The validator that validates objects.
|
|
41
41
|
*/
|
|
42
|
-
constructor(loghandler, validator) {
|
|
42
|
+
constructor(loghandler, validator, dataMapper) {
|
|
43
43
|
this.loghandler = loghandler;
|
|
44
44
|
this.validator = validator;
|
|
45
|
+
this.dataMapper = dataMapper;
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
48
|
* Intercepts the request and validates that the body of the request matches the expected class.
|
|
@@ -61,7 +62,7 @@ let BodyValidationRequestInterceptor = class BodyValidationRequestInterceptor {
|
|
|
61
62
|
routeContext: methodNode.route.context,
|
|
62
63
|
}, ValidationModuleKeyname);
|
|
63
64
|
// Validates that the body can be mapped to the expected type
|
|
64
|
-
const mappedBody =
|
|
65
|
+
const mappedBody = yield this.dataMapper.autoMap(request.body, bodyValidator.classType);
|
|
65
66
|
// Validates if all the conditions are respected in the expected type.
|
|
66
67
|
const errors = yield this.validator.validate(mappedBody);
|
|
67
68
|
if (errors.length == 0) {
|
|
@@ -77,7 +78,8 @@ BodyValidationRequestInterceptor = __decorate([
|
|
|
77
78
|
tag(ServiceDefinitionTagEnum.RequestInterceptor),
|
|
78
79
|
injectable(),
|
|
79
80
|
__param(0, inject("LogHandlerInterface")),
|
|
80
|
-
__metadata("design:paramtypes", [Object, Validator
|
|
81
|
+
__metadata("design:paramtypes", [Object, Validator,
|
|
82
|
+
DataMapper])
|
|
81
83
|
], BodyValidationRequestInterceptor);
|
|
82
84
|
export { BodyValidationRequestInterceptor };
|
|
83
85
|
//# sourceMappingURL=body-validation.request-interceptor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-validation.request-interceptor.js","sourceRoot":"","sources":["../../../../src/interceptors/body-validation.request-interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAC,SAAS,EAAC,MAAM,8BAA8B,CAAC;AACvD,OAAO,EAAC,mBAAmB,EAAC,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAC,YAAY,EAAE,wBAAwB,EAAE,GAAG,EAAU,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAC,UAAU,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"body-validation.request-interceptor.js","sourceRoot":"","sources":["../../../../src/interceptors/body-validation.request-interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA,OAAO,EAAC,SAAS,EAAC,MAAM,8BAA8B,CAAC;AACvD,OAAO,EAAC,mBAAmB,EAAC,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAC,YAAY,EAAE,wBAAwB,EAAE,GAAG,EAAU,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAC,UAAU,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAG5C,OAAO,EAAC,6BAA6B,EAAC,MAAM,yCAAyC,CAAC;AACtF,OAAO,EAAC,UAAU,EAAC,MAAM,kCAAkC,CAAC;AAE5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,CAAA;6CACF,SAAS;QACR,UAAU;GAX1C,gCAAgC,CA+C5C"}
|
|
@@ -2,6 +2,7 @@ import { RequestInterceptorInterface, MethodRouterNode } from "@pristine-ts/netw
|
|
|
2
2
|
import { Validator } from "@pristine-ts/class-validator";
|
|
3
3
|
import { Request } from "@pristine-ts/common";
|
|
4
4
|
import { LogHandlerInterface } from "@pristine-ts/logging";
|
|
5
|
+
import { DataMapper } from "@pristine-ts/data-mapping-common";
|
|
5
6
|
/**
|
|
6
7
|
* This class is an interceptor to validate the body of an incoming request.
|
|
7
8
|
* It is tagged as an RequestInterceptor so it can be automatically injected with the all the other RequestInterceptors.
|
|
@@ -10,6 +11,7 @@ import { LogHandlerInterface } from "@pristine-ts/logging";
|
|
|
10
11
|
export declare class BodyValidationRequestInterceptor implements RequestInterceptorInterface {
|
|
11
12
|
private readonly loghandler;
|
|
12
13
|
private readonly validator;
|
|
14
|
+
private readonly dataMapper;
|
|
13
15
|
/**
|
|
14
16
|
* This class is an interceptor to validate the body of an incoming request.
|
|
15
17
|
* It is tagged as an RequestInterceptor so it can be automatically injected with the all the other RequestInterceptors.
|
|
@@ -17,7 +19,7 @@ export declare class BodyValidationRequestInterceptor implements RequestIntercep
|
|
|
17
19
|
* @param loghandler The log handler to output logs.
|
|
18
20
|
* @param validator The validator that validates objects.
|
|
19
21
|
*/
|
|
20
|
-
constructor(loghandler: LogHandlerInterface, validator: Validator);
|
|
22
|
+
constructor(loghandler: LogHandlerInterface, validator: Validator, dataMapper: DataMapper);
|
|
21
23
|
/**
|
|
22
24
|
* Intercepts the request and validates that the body of the request matches the expected class.
|
|
23
25
|
* It also validates the content of properties using the class-validator library.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pristine-ts/validation",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.285",
|
|
4
4
|
"description": "",
|
|
5
5
|
"module": "dist/lib/esm/validation.module.js",
|
|
6
6
|
"main": "dist/lib/cjs/validation.module.js",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@pristine-ts/class-validator": "^1.0.25",
|
|
16
|
-
"@pristine-ts/common": "^0.0.
|
|
17
|
-
"@pristine-ts/core": "^0.0.
|
|
18
|
-
"@pristine-ts/
|
|
19
|
-
"
|
|
16
|
+
"@pristine-ts/common": "^0.0.285",
|
|
17
|
+
"@pristine-ts/core": "^0.0.285",
|
|
18
|
+
"@pristine-ts/data-mapping": "^0.0.285",
|
|
19
|
+
"@pristine-ts/networking": "^0.0.285"
|
|
20
20
|
},
|
|
21
21
|
"files": [
|
|
22
22
|
"dist"
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"src/*.{js,ts}"
|
|
61
61
|
]
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "f1a383ff2f4639468608cf17d92fdf4485a6ba78"
|
|
64
64
|
}
|