@pristine-ts/validation 2.0.3 → 2.0.5

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.
@@ -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 { BadRequestHttpError, RequestInterceptorPriorityEnum } from "@pristine-ts/networking";
22
+ import { MethodRouterNode, RequestInterceptorPriorityEnum } from "@pristine-ts/networking";
23
23
  import { Validator } from "@pristine-ts/class-validator";
24
- import { moduleScoped, ServiceDefinitionTagEnum, tag } 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";
@@ -39,13 +39,11 @@ 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
  * @param dataMapper
42
- * @param breadcrumbHandler
43
42
  */
44
- constructor(loghandler, validator, dataMapper, breadcrumbHandler) {
43
+ constructor(loghandler, validator, dataMapper) {
45
44
  this.loghandler = loghandler;
46
45
  this.validator = validator;
47
46
  this.dataMapper = dataMapper;
48
- this.breadcrumbHandler = breadcrumbHandler;
49
47
  this.priority = RequestInterceptorPriorityEnum.BodyMapping - 100;
50
48
  }
51
49
  /**
@@ -56,10 +54,6 @@ let BodyValidationRequestInterceptor = class BodyValidationRequestInterceptor {
56
54
  */
57
55
  interceptRequest(request, methodNode) {
58
56
  return __awaiter(this, void 0, void 0, function* () {
59
- this.breadcrumbHandler.add(request.id, `${ValidationModuleKeyname}:body-validation.request-interceptor:enter`, {
60
- request,
61
- methodNode
62
- });
63
57
  const bodyValidator = methodNode.route.context[bodyValidationMetadataKeyname];
64
58
  if (bodyValidator === undefined || bodyValidator.classType === undefined) {
65
59
  return request;
@@ -88,19 +82,26 @@ let BodyValidationRequestInterceptor = class BodyValidationRequestInterceptor {
88
82
  routeContext: methodNode.route.context,
89
83
  },
90
84
  });
91
- // If we received some error while validating we reject by throwing an error.
92
- throw new BadRequestHttpError("Validation error", errors);
85
+ // If we received some error while validating we reject by throwing an error. The
86
+ // `details.errors` array carries the structured class-validator output; the responders
87
+ // surface it to API callers (HTTP body) and CLI users (stderr lines).
88
+ throw new ValidationError("Validation error", { details: { errors } });
93
89
  });
94
90
  }
95
91
  };
92
+ __decorate([
93
+ traced(),
94
+ __metadata("design:type", Function),
95
+ __metadata("design:paramtypes", [Request, MethodRouterNode]),
96
+ __metadata("design:returntype", Promise)
97
+ ], BodyValidationRequestInterceptor.prototype, "interceptRequest", null);
96
98
  BodyValidationRequestInterceptor = __decorate([
97
99
  moduleScoped(ValidationModuleKeyname),
98
100
  tag(ServiceDefinitionTagEnum.RequestInterceptor),
99
101
  injectable(),
100
102
  __param(0, inject("LogHandlerInterface")),
101
- __param(3, inject("BreadcrumbHandlerInterface")),
102
103
  __metadata("design:paramtypes", [Object, Validator,
103
- DataMapper, Object])
104
+ DataMapper])
104
105
  ], BodyValidationRequestInterceptor);
105
106
  export { BodyValidationRequestInterceptor };
106
107
  //# 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":";;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EACL,mBAAmB,EAGnB,8BAA8B,EAC/B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAC,SAAS,EAAC,MAAM,8BAA8B,CAAC;AACvD,OAAO,EAAC,YAAY,EAAW,wBAAwB,EAAE,GAAG,EAAC,MAAM,qBAAqB,CAAC;AACzF,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA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,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YAEzD,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;gBACvB,OAAO,OAAO,CAAC;YACjB,CAAC;YAGD,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,mCAAmC,EAAE;gBACzD,YAAY,EAAE,OAAO,CAAC,OAAO;gBAC7B,UAAU,EAAE;oBACV,MAAM;oBACN,UAAU;iBACX;gBACD,KAAK,EAAE;oBACL,OAAO;oBACP,UAAU;oBACV,YAAY,EAAE,UAAU,CAAC,KAAK,CAAC,OAAO;iBACvC;aACF,CAAC,CAAA;YAEF,6EAA6E;YAC7E,MAAM,IAAI,mBAAmB,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;QAC5D,CAAC;KAAA;CACF,CAAA;AAtEY,gCAAgC;IAH5C,YAAY,CAAC,uBAAuB,CAAC;IACrC,GAAG,CAAC,wBAAwB,CAAC,kBAAkB,CAAC;IAChD,UAAU,EAAE;IAcE,WAAA,MAAM,CAAC,qBAAqB,CAAC,CAAA;IAG7B,WAAA,MAAM,CAAC,4BAA4B,CAAC,CAAA;6CAFT,SAAS;QACR,UAAU;GAfxC,gCAAgC,CAsE5C"}
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,EAAE,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAClH,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,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