@pristine-ts/validation 2.0.4 → 2.0.6
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 +15 -4
- package/dist/lib/cjs/interceptors/body-validation.request-interceptor.js.map +1 -1
- package/dist/lib/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/lib/esm/interceptors/body-validation.request-interceptor.js +17 -6
- package/dist/lib/esm/interceptors/body-validation.request-interceptor.js.map +1 -1
- package/dist/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/types/interceptors/body-validation.request-interceptor.d.ts +3 -2
- package/package.json +6 -6
|
@@ -19,9 +19,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
19
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
|
-
import {
|
|
22
|
+
import { MethodRouterNode, RequestInterceptorPriorityEnum } from "@pristine-ts/networking";
|
|
23
23
|
import { Validator } from "@pristine-ts/class-validator";
|
|
24
|
-
import { moduleScoped, Request, ServiceDefinitionTagEnum, tag, traced } from "@pristine-ts/common";
|
|
24
|
+
import { moduleScoped, Request, ServiceDefinitionTagEnum, tag, traced, ValidationError } from "@pristine-ts/common";
|
|
25
25
|
import { ValidationModuleKeyname } from "../validation.module.keyname";
|
|
26
26
|
import { inject, injectable } from "tsyringe";
|
|
27
27
|
import { bodyValidationMetadataKeyname } from "../decorators/body-validation.decorator";
|
|
@@ -40,8 +40,9 @@ let BodyValidationRequestInterceptor = class BodyValidationRequestInterceptor {
|
|
|
40
40
|
* @param validator The validator that validates objects.
|
|
41
41
|
* @param dataMapper
|
|
42
42
|
*/
|
|
43
|
-
constructor(loghandler, validator, dataMapper) {
|
|
43
|
+
constructor(loghandler, tracingManager, validator, dataMapper) {
|
|
44
44
|
this.loghandler = loghandler;
|
|
45
|
+
this.tracingManager = tracingManager;
|
|
45
46
|
this.validator = validator;
|
|
46
47
|
this.dataMapper = dataMapper;
|
|
47
48
|
this.priority = RequestInterceptorPriorityEnum.BodyMapping - 100;
|
|
@@ -68,8 +69,15 @@ let BodyValidationRequestInterceptor = class BodyValidationRequestInterceptor {
|
|
|
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) {
|
|
72
|
+
this.tracingManager.addMarkerToCurrentSpan("validation.passed", {
|
|
73
|
+
classType: bodyValidator.classType.name,
|
|
74
|
+
});
|
|
71
75
|
return request;
|
|
72
76
|
}
|
|
77
|
+
this.tracingManager.addMarkerToCurrentSpan("validation.failed", {
|
|
78
|
+
classType: bodyValidator.classType.name,
|
|
79
|
+
errorCount: String(errors.length),
|
|
80
|
+
});
|
|
73
81
|
this.loghandler.error(`Error validating body of request.`, {
|
|
74
82
|
eventGroupId: request.groupId,
|
|
75
83
|
highlights: {
|
|
@@ -82,8 +90,10 @@ let BodyValidationRequestInterceptor = class BodyValidationRequestInterceptor {
|
|
|
82
90
|
routeContext: methodNode.route.context,
|
|
83
91
|
},
|
|
84
92
|
});
|
|
85
|
-
// If we received some error while validating we reject by throwing an error.
|
|
86
|
-
|
|
93
|
+
// If we received some error while validating we reject by throwing an error. The
|
|
94
|
+
// `details.errors` array carries the structured class-validator output; the responders
|
|
95
|
+
// surface it to API callers (HTTP body) and CLI users (stderr lines).
|
|
96
|
+
throw new ValidationError("Validation error", { details: { errors } });
|
|
87
97
|
});
|
|
88
98
|
}
|
|
89
99
|
};
|
|
@@ -98,7 +108,8 @@ BodyValidationRequestInterceptor = __decorate([
|
|
|
98
108
|
tag(ServiceDefinitionTagEnum.RequestInterceptor),
|
|
99
109
|
injectable(),
|
|
100
110
|
__param(0, inject("LogHandlerInterface")),
|
|
101
|
-
|
|
111
|
+
__param(1, inject("TracingManagerInterface")),
|
|
112
|
+
__metadata("design:paramtypes", [Object, Object, Validator,
|
|
102
113
|
DataMapper])
|
|
103
114
|
], BodyValidationRequestInterceptor);
|
|
104
115
|
export { BodyValidationRequestInterceptor };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body-validation.request-interceptor.js","sourceRoot":"","sources":["../../../../src/interceptors/body-validation.request-interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"body-validation.request-interceptor.js","sourceRoot":"","sources":["../../../../src/interceptors/body-validation.request-interceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EACL,gBAAgB,EAEhB,8BAA8B,EAC/B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAC,SAAS,EAAC,MAAM,8BAA8B,CAAC;AACvD,OAAO,EAAC,YAAY,EAAE,OAAO,EAAE,wBAAwB,EAAE,GAAG,EAAE,MAAM,EAA2B,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAC3I,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,UAAU,CAAC;AAE5C,OAAO,EAAC,6BAA6B,EAAC,MAAM,yCAAyC,CAAC;AACtF,OAAO,EAAC,UAAU,EAAC,MAAM,kCAAkC,CAAC;AAE5D;;;;GAIG;AAII,IAAM,gCAAgC,GAAtC,MAAM,gCAAgC;IAI3C;;;;;;;OAOG;IACH,YAA2C,UAAgD,EAC5C,cAAwD,EAC1E,SAAoB,EACpB,UAAsB;QAHS,eAAU,GAAV,UAAU,CAAqB;QAC3B,mBAAc,GAAd,cAAc,CAAyB;QAC1E,cAAS,GAAT,SAAS,CAAW;QACpB,eAAU,GAAV,UAAU,CAAY;QAbnD,aAAQ,GAAG,8BAA8B,CAAC,WAAW,GAAG,GAAG,CAAC;IAe5D,CAAC;IAED;;;;;OAKG;IAEG,gBAAgB,CAAC,OAAgB,EAAE,UAA4B;;YACnE,MAA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