@x-spacy/class-validator 1.2.0 → 1.3.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.
@@ -1,5 +1,12 @@
1
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
+ };
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.IsDocumentConstraint = void 0;
3
10
  exports.IsDocument = IsDocument;
4
11
  const class_validator_1 = require("class-validator");
5
12
  const IsCNPJ_1 = require("../services/IsCNPJ");
@@ -8,43 +15,53 @@ const IsCREF_1 = require("../services/IsCREF");
8
15
  const IsCRM_1 = require("../services/IsCRM");
9
16
  const IsCRN_1 = require("../services/IsCRN");
10
17
  const DocumentTypeEnum_1 = require("../enums/DocumentTypeEnum");
11
- function IsDocument(isDocumentOptions, validationOptions) {
18
+ let IsDocumentConstraint = class IsDocumentConstraint {
19
+ validate(document, args) {
20
+ var _a;
21
+ if (typeof document !== 'string') {
22
+ return false;
23
+ }
24
+ const options = args.constraints[0];
25
+ const instance = args.object;
26
+ const type = (_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : instance.type;
27
+ switch (type) {
28
+ case DocumentTypeEnum_1.DocumentTypeEnum.CPF: {
29
+ return (0, IsCPF_1.isCPF)(document);
30
+ }
31
+ case DocumentTypeEnum_1.DocumentTypeEnum.CNPJ: {
32
+ return (0, IsCNPJ_1.isCNPJ)(document);
33
+ }
34
+ case DocumentTypeEnum_1.DocumentTypeEnum.CRN: {
35
+ return (0, IsCRN_1.isCRN)(document);
36
+ }
37
+ case DocumentTypeEnum_1.DocumentTypeEnum.CREF: {
38
+ return (0, IsCREF_1.isCREF)(document);
39
+ }
40
+ case DocumentTypeEnum_1.DocumentTypeEnum.CRM: {
41
+ return (0, IsCRM_1.isCRM)(document);
42
+ }
43
+ default: {
44
+ return false;
45
+ }
46
+ }
47
+ }
48
+ defaultMessage() {
49
+ return 'Informe um documento válido';
50
+ }
51
+ };
52
+ exports.IsDocumentConstraint = IsDocumentConstraint;
53
+ exports.IsDocumentConstraint = IsDocumentConstraint = __decorate([
54
+ (0, class_validator_1.ValidatorConstraint)({ name: 'IsDocument', async: false })
55
+ ], IsDocumentConstraint);
56
+ function IsDocument(isDocumentOptions = {}, validationOptions) {
12
57
  return function (object, propertyName) {
13
58
  (0, class_validator_1.registerDecorator)({
14
59
  name: 'IsDocument',
15
60
  target: object.constructor,
16
61
  propertyName: propertyName,
17
62
  options: validationOptions,
18
- validator: {
19
- validate(document, _args) {
20
- if (typeof document !== 'string') {
21
- return false;
22
- }
23
- switch (isDocumentOptions.type) {
24
- case DocumentTypeEnum_1.DocumentTypeEnum.CPF: {
25
- return (0, IsCPF_1.isCPF)(document);
26
- }
27
- case DocumentTypeEnum_1.DocumentTypeEnum.CNPJ: {
28
- return (0, IsCNPJ_1.isCNPJ)(document);
29
- }
30
- case DocumentTypeEnum_1.DocumentTypeEnum.CRN: {
31
- return (0, IsCRN_1.isCRN)(document);
32
- }
33
- case DocumentTypeEnum_1.DocumentTypeEnum.CREF: {
34
- return (0, IsCREF_1.isCREF)(document);
35
- }
36
- case DocumentTypeEnum_1.DocumentTypeEnum.CRM: {
37
- return (0, IsCRM_1.isCRM)(document);
38
- }
39
- default: {
40
- return false;
41
- }
42
- }
43
- },
44
- defaultMessage() {
45
- return 'Informe um documento válido';
46
- }
47
- }
63
+ constraints: [isDocumentOptions],
64
+ validator: IsDocumentConstraint
48
65
  });
49
66
  };
50
67
  }
package/dist/index.js CHANGED
@@ -18,4 +18,7 @@ __exportStar(require("./decorators/IsDocument"), exports);
18
18
  __exportStar(require("./enums/DocumentTypeEnum"), exports);
19
19
  __exportStar(require("./services/IsCNPJ"), exports);
20
20
  __exportStar(require("./services/IsCPF"), exports);
21
+ __exportStar(require("./services/IsCREF"), exports);
22
+ __exportStar(require("./services/IsCRM"), exports);
23
+ __exportStar(require("./services/IsCRN"), exports);
21
24
  __exportStar(require("class-validator"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@x-spacy/class-validator",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Validators extension for class-validator lib",
5
5
  "license": "MIT",
6
6
  "private": false,
package/test.js DELETED
@@ -1,5 +0,0 @@
1
- const { isCRM } = require('./dist/services/IsCRM');
2
-
3
- const value = process.argv.slice(2).join(' ');
4
-
5
- console.log(isCRM(value));