thesimplevalidation 1.2.0 → 2.1.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.
Files changed (123) hide show
  1. package/README.md +158 -140
  2. package/dist/Validation.d.ts +16 -0
  3. package/dist/Validation.js +99 -0
  4. package/dist/Validation.js.map +1 -0
  5. package/dist/ValidationErrorsModel.js +2 -0
  6. package/dist/ValidationErrorsModel.js.map +1 -0
  7. package/dist/ValidationModel.js +2 -0
  8. package/dist/ValidationModel.js.map +1 -0
  9. package/dist/ValidationPropertyResult.d.ts +4 -0
  10. package/dist/ValidationPropertyResult.js +2 -0
  11. package/dist/ValidationPropertyResult.js.map +1 -0
  12. package/dist/ValidationResult.d.ts +8 -0
  13. package/dist/ValidationResult.js +2 -0
  14. package/dist/ValidationResult.js.map +1 -0
  15. package/dist/ValidationScope.d.ts +15 -0
  16. package/dist/ValidationScope.js +95 -0
  17. package/dist/ValidationScope.js.map +1 -0
  18. package/dist/Validator.d.ts +10 -0
  19. package/dist/Validator.js +28 -0
  20. package/dist/Validator.js.map +1 -0
  21. package/dist/{src/validator-setup.d.ts → ValidatorSetup.d.ts} +2 -2
  22. package/dist/ValidatorSetup.js +2 -0
  23. package/dist/ValidatorSetup.js.map +1 -0
  24. package/dist/index.d.ts +8 -1
  25. package/dist/index.js +5 -17
  26. package/dist/index.js.map +1 -1
  27. package/dist/validators/boolean/BooleanValidator.d.ts +7 -0
  28. package/dist/validators/boolean/BooleanValidator.js +18 -0
  29. package/dist/validators/boolean/BooleanValidator.js.map +1 -0
  30. package/dist/validators/boolean/BooleanValidatorSetup.d.ts +4 -0
  31. package/dist/validators/boolean/BooleanValidatorSetup.js +2 -0
  32. package/dist/validators/boolean/BooleanValidatorSetup.js.map +1 -0
  33. package/dist/validators/index.d.ts +9 -0
  34. package/dist/validators/index.js +6 -0
  35. package/dist/validators/index.js.map +1 -0
  36. package/dist/validators/max/MaxValidator.d.ts +7 -0
  37. package/dist/validators/max/MaxValidator.js +26 -0
  38. package/dist/validators/max/MaxValidator.js.map +1 -0
  39. package/dist/validators/max/MaxValidatorSetup.d.ts +4 -0
  40. package/dist/validators/max/MaxValidatorSetup.js +2 -0
  41. package/dist/validators/max/MaxValidatorSetup.js.map +1 -0
  42. package/dist/validators/min/MinValidator.d.ts +7 -0
  43. package/dist/validators/min/MinValidator.js +27 -0
  44. package/dist/validators/min/MinValidator.js.map +1 -0
  45. package/dist/validators/min/MinValidatorSetup.d.ts +4 -0
  46. package/dist/validators/min/MinValidatorSetup.js +2 -0
  47. package/dist/validators/min/MinValidatorSetup.js.map +1 -0
  48. package/dist/validators/required/RequiredValidator.d.ts +7 -0
  49. package/dist/validators/required/RequiredValidator.js +21 -0
  50. package/dist/validators/required/RequiredValidator.js.map +1 -0
  51. package/dist/validators/simple/SimpleValidator.d.ts +7 -0
  52. package/dist/validators/simple/SimpleValidator.js +14 -0
  53. package/dist/validators/simple/SimpleValidator.js.map +1 -0
  54. package/dist/validators/simple/SimpleValidatorSetup.d.ts +4 -0
  55. package/dist/validators/simple/SimpleValidatorSetup.js +2 -0
  56. package/dist/validators/simple/SimpleValidatorSetup.js.map +1 -0
  57. package/package.json +12 -12
  58. package/.editorconfig +0 -11
  59. package/.travis.yml +0 -7
  60. package/.yo-rc.json +0 -9
  61. package/dist/src/index.d.ts +0 -8
  62. package/dist/src/index.js +0 -23
  63. package/dist/src/index.js.map +0 -1
  64. package/dist/src/validation-errors-model.js +0 -3
  65. package/dist/src/validation-errors-model.js.map +0 -1
  66. package/dist/src/validation-model.js +0 -3
  67. package/dist/src/validation-model.js.map +0 -1
  68. package/dist/src/validation-property-result.d.ts +0 -4
  69. package/dist/src/validation-property-result.js +0 -3
  70. package/dist/src/validation-property-result.js.map +0 -1
  71. package/dist/src/validation-result.d.ts +0 -8
  72. package/dist/src/validation-result.js +0 -3
  73. package/dist/src/validation-result.js.map +0 -1
  74. package/dist/src/validation-scope.d.ts +0 -19
  75. package/dist/src/validation-scope.js +0 -200
  76. package/dist/src/validation-scope.js.map +0 -1
  77. package/dist/src/validator-setup.js +0 -3
  78. package/dist/src/validator-setup.js.map +0 -1
  79. package/dist/src/validator.d.ts +0 -8
  80. package/dist/src/validator.js +0 -69
  81. package/dist/src/validator.js.map +0 -1
  82. package/dist/src/validators/boolean/index.d.ts +0 -10
  83. package/dist/src/validators/boolean/index.js +0 -80
  84. package/dist/src/validators/boolean/index.js.map +0 -1
  85. package/dist/src/validators/index.d.ts +0 -5
  86. package/dist/src/validators/index.js +0 -14
  87. package/dist/src/validators/index.js.map +0 -1
  88. package/dist/src/validators/max/index.d.ts +0 -10
  89. package/dist/src/validators/max/index.js +0 -88
  90. package/dist/src/validators/max/index.js.map +0 -1
  91. package/dist/src/validators/min/index.d.ts +0 -10
  92. package/dist/src/validators/min/index.js +0 -89
  93. package/dist/src/validators/min/index.js.map +0 -1
  94. package/dist/src/validators/required/index.d.ts +0 -7
  95. package/dist/src/validators/required/index.js +0 -84
  96. package/dist/src/validators/required/index.js.map +0 -1
  97. package/dist/src/validators/simple/index.d.ts +0 -10
  98. package/dist/src/validators/simple/index.js +0 -76
  99. package/dist/src/validators/simple/index.js.map +0 -1
  100. package/index.ts +0 -1
  101. package/jest.config.js +0 -192
  102. package/src/index.ts +0 -9
  103. package/src/validation-errors-model.ts +0 -3
  104. package/src/validation-model.ts +0 -3
  105. package/src/validation-property-result.ts +0 -5
  106. package/src/validation-result.ts +0 -11
  107. package/src/validation-scope.ts +0 -119
  108. package/src/validator-setup.ts +0 -4
  109. package/src/validator.ts +0 -25
  110. package/src/validators/boolean/index.ts +0 -27
  111. package/src/validators/index.ts +0 -5
  112. package/src/validators/max/__tests__/index.test.ts +0 -92
  113. package/src/validators/max/index.ts +0 -32
  114. package/src/validators/min/__tests__/index.test.ts +0 -92
  115. package/src/validators/min/index.ts +0 -33
  116. package/src/validators/required/__tests__/index.test.ts +0 -229
  117. package/src/validators/required/index.ts +0 -24
  118. package/src/validators/simple/index.ts +0 -22
  119. package/thesimplevalidation.code-workspace +0 -10
  120. package/tsconfig.json +0 -23
  121. package/tslint.json +0 -18
  122. /package/dist/{src/validation-errors-model.d.ts → ValidationErrorsModel.d.ts} +0 -0
  123. /package/dist/{src/validation-model.d.ts → ValidationModel.d.ts} +0 -0
@@ -1,89 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
- Object.defineProperty(exports, "__esModule", { value: true });
54
- exports.MinValidator = void 0;
55
- var validator_1 = require("../../validator");
56
- var MinValidator = /** @class */ (function (_super) {
57
- __extends(MinValidator, _super);
58
- function MinValidator(setup) {
59
- return _super.call(this, setup) || this;
60
- }
61
- MinValidator.prototype.isValidInternal = function (value) {
62
- return __awaiter(this, void 0, void 0, function () {
63
- var isValid, minValue;
64
- return __generator(this, function (_a) {
65
- isValid = true;
66
- if (value != null) {
67
- minValue = this.setup.minValue();
68
- // tslint:disable-next-line:prefer-conditional-expression
69
- if (Array.isArray(value)) {
70
- isValid = value.length >= minValue;
71
- }
72
- else if (typeof value === "string") {
73
- isValid = value.length >= minValue;
74
- }
75
- else if (typeof value === "number") {
76
- isValid = value >= minValue;
77
- }
78
- }
79
- return [2 /*return*/, {
80
- isValid: isValid,
81
- errors: []
82
- }];
83
- });
84
- });
85
- };
86
- return MinValidator;
87
- }(validator_1.Validator));
88
- exports.MinValidator = MinValidator;
89
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/validators/min/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,6CAA4C;AAM5C;IAAkE,gCAAmD;IACjH,sBAAY,KAAoC;eAC5C,kBAAM,KAAK,CAAC;IAChB,CAAC;IAEY,sCAAe,GAA5B,UAA6B,KAAgB;;;;gBACrC,OAAO,GAAY,IAAI,CAAC;gBAC5B,IAAI,KAAK,IAAI,IAAI,EAAE;oBACT,QAAQ,GAAW,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;oBAC/C,yDAAyD;oBACzD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;wBACtB,OAAO,GAAG,KAAK,CAAC,MAAM,IAAI,QAAQ,CAAC;qBACtC;yBAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;wBAClC,OAAO,GAAG,KAAK,CAAC,MAAM,IAAI,QAAQ,CAAC;qBACtC;yBAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;wBAClC,OAAO,GAAG,KAAK,IAAI,QAAQ,CAAC;qBAC/B;iBACJ;gBAED,sBAAO;wBACH,OAAO,EAAE,OAAO;wBAChB,MAAM,EAAE,EAAE;qBACb,EAAC;;;KACL;IACL,mBAAC;AAAD,CAAC,AAxBD,CAAkE,qBAAS,GAwB1E;AAxBY,oCAAY"}
@@ -1,7 +0,0 @@
1
- import { IValidationPropertyResult } from "../../validation-property-result";
2
- import { IValidatorSetup } from "../../validator-setup";
3
- import { Validator } from "../../validator";
4
- export declare class RequiredValidator<TModel, K extends keyof TModel> extends Validator<TModel, K> {
5
- constructor(setup?: IValidatorSetup<TModel, K>);
6
- isValidInternal(value: TModel[K]): Promise<IValidationPropertyResult>;
7
- }
@@ -1,84 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
- Object.defineProperty(exports, "__esModule", { value: true });
54
- exports.RequiredValidator = void 0;
55
- var validator_1 = require("../../validator");
56
- var RequiredValidator = /** @class */ (function (_super) {
57
- __extends(RequiredValidator, _super);
58
- function RequiredValidator(setup) {
59
- if (setup === void 0) { setup = {}; }
60
- return _super.call(this, setup) || this;
61
- }
62
- RequiredValidator.prototype.isValidInternal = function (value) {
63
- return __awaiter(this, void 0, void 0, function () {
64
- var isValid;
65
- return __generator(this, function (_a) {
66
- isValid = true;
67
- // tslint:disable-next-line:prefer-conditional-expression
68
- if (Array.isArray(value)) {
69
- isValid = value.length > 0;
70
- }
71
- else {
72
- isValid = !!value;
73
- }
74
- return [2 /*return*/, {
75
- isValid: isValid,
76
- errors: []
77
- }];
78
- });
79
- });
80
- };
81
- return RequiredValidator;
82
- }(validator_1.Validator));
83
- exports.RequiredValidator = RequiredValidator;
84
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/validators/required/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,6CAA4C;AAE5C;IAAuE,qCAAoB;IACvF,2BAAY,KAAsC;QAAtC,sBAAA,EAAA,UAAsC;eAC9C,kBAAM,KAAK,CAAC;IAChB,CAAC;IAEY,2CAAe,GAA5B,UAA6B,KAAgB;;;;gBACrC,OAAO,GAAY,IAAI,CAAC;gBAC5B,yDAAyD;gBACzD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;oBACtB,OAAO,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;iBAC9B;qBAAM;oBACH,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC;iBACrB;gBAED,sBAAO;wBACH,OAAO,EAAE,OAAO;wBAChB,MAAM,EAAE,EAAE;qBACb,EAAC;;;KACL;IACL,wBAAC;AAAD,CAAC,AAnBD,CAAuE,qBAAS,GAmB/E;AAnBY,8CAAiB"}
@@ -1,10 +0,0 @@
1
- import { IValidationPropertyResult } from "../../validation-property-result";
2
- import { IValidatorSetup } from "../../validator-setup";
3
- import { Validator } from "../../validator";
4
- export interface ISimpleValidatorSetup<TModel, K extends keyof TModel> extends IValidatorSetup<TModel, K> {
5
- getValidation: () => boolean;
6
- }
7
- export declare class SimpleValidator<TModel, K extends keyof TModel> extends Validator<TModel, K, ISimpleValidatorSetup<TModel, K>> {
8
- constructor(setup: ISimpleValidatorSetup<TModel, K>);
9
- isValidInternal(_value: TModel[K]): Promise<IValidationPropertyResult>;
10
- }
@@ -1,76 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
- Object.defineProperty(exports, "__esModule", { value: true });
54
- exports.SimpleValidator = void 0;
55
- var validator_1 = require("../../validator");
56
- var SimpleValidator = /** @class */ (function (_super) {
57
- __extends(SimpleValidator, _super);
58
- function SimpleValidator(setup) {
59
- return _super.call(this, setup) || this;
60
- }
61
- SimpleValidator.prototype.isValidInternal = function (_value) {
62
- return __awaiter(this, void 0, void 0, function () {
63
- var isValid;
64
- return __generator(this, function (_a) {
65
- isValid = this.setup.getValidation();
66
- return [2 /*return*/, {
67
- isValid: isValid,
68
- errors: []
69
- }];
70
- });
71
- });
72
- };
73
- return SimpleValidator;
74
- }(validator_1.Validator));
75
- exports.SimpleValidator = SimpleValidator;
76
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/validators/simple/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,6CAA4C;AAM5C;IAAqE,mCAAsD;IACvH,yBAAY,KAAuC;eAC/C,kBAAM,KAAK,CAAC;IAChB,CAAC;IAEY,yCAAe,GAA5B,UAA6B,MAAiB;;;;gBACpC,OAAO,GAAY,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;gBAEpD,sBAAO;wBACH,OAAO,EAAE,OAAO;wBAChB,MAAM,EAAE,EAAE;qBACb,EAAC;;;KACL;IACL,sBAAC;AAAD,CAAC,AAbD,CAAqE,qBAAS,GAa7E;AAbY,0CAAe"}
package/index.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src";
package/jest.config.js DELETED
@@ -1,192 +0,0 @@
1
- // For a detailed explanation regarding each configuration property, visit:
2
- // https://jestjs.io/docs/en/configuration.html
3
-
4
- module.exports = {
5
- // All imported modules in your tests should be mocked automatically
6
- // automock: false,
7
-
8
- // Stop running tests after `n` failures
9
- // bail: 0,
10
-
11
- // Respect "browser" field in package.json when resolving modules
12
- // browser: false,
13
-
14
- // The directory where Jest should store its cached dependency information
15
- // cacheDirectory: "C:\\Users\\aripenko\\AppData\\Local\\Temp\\jest",
16
-
17
- // Automatically clear mock calls and instances between every test
18
- clearMocks: true,
19
-
20
- // Indicates whether the coverage information should be collected while executing the test
21
- collectCoverage: true,
22
-
23
- // An array of glob patterns indicating a set of files for which coverage information should be collected
24
- // collectCoverageFrom: null,
25
-
26
- // The directory where Jest should output its coverage files
27
- coverageDirectory: "coverage",
28
-
29
- // An array of regexp pattern strings used to skip coverage collection
30
- // coveragePathIgnorePatterns: [
31
- // "\\\\node_modules\\\\"
32
- // ],
33
-
34
- // A list of reporter names that Jest uses when writing coverage reports
35
- // coverageReporters: [
36
- // "json",
37
- // "text",
38
- // "lcov",
39
- // "clover"
40
- // ],
41
-
42
- // An object that configures minimum threshold enforcement for coverage results
43
- // coverageThreshold: null,
44
-
45
- // A path to a custom dependency extractor
46
- // dependencyExtractor: null,
47
-
48
- // Make calling deprecated APIs throw helpful error messages
49
- // errorOnDeprecated: false,
50
-
51
- // Force coverage collection from ignored files using an array of glob patterns
52
- // forceCoverageMatch: [],
53
-
54
- // A path to a module which exports an async function that is triggered once before all test suites
55
- // globalSetup: null,
56
-
57
- // A path to a module which exports an async function that is triggered once after all test suites
58
- // globalTeardown: null,
59
-
60
- // A set of global variables that need to be available in all test environments
61
- // globals: {
62
-
63
- // },
64
-
65
- // An array of directory names to be searched recursively up from the requiring module's location
66
- moduleDirectories: [
67
- "node_modules",
68
- "src"
69
- ],
70
-
71
- // An array of file extensions your modules use
72
- // moduleFileExtensions: [
73
- // "js",
74
- // "json",
75
- // "jsx",
76
- // "ts",
77
- // "tsx",
78
- // "node"
79
- // ],
80
-
81
- // A map from regular expressions to module names that allow to stub out resources with a single module
82
- moduleNameMapper: {
83
- "^src/(.+)$": "<rootDir>/src/$1"
84
- },
85
-
86
- // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
87
- // modulePathIgnorePatterns: [],
88
-
89
- // Activates notifications for test results
90
- // notify: false,
91
-
92
- // An enum that specifies notification mode. Requires { notify: true }
93
- // notifyMode: "failure-change",
94
-
95
- // A preset that is used as a base for Jest's configuration
96
- // preset: null,
97
-
98
- // Run tests from one or more projects
99
- // projects: null,
100
-
101
- // Use this configuration option to add custom reporters to Jest
102
- // reporters: undefined,
103
-
104
- // Automatically reset mock state between every test
105
- // resetMocks: false,
106
-
107
- // Reset the module registry before running each individual test
108
- // resetModules: false,
109
-
110
- // A path to a custom resolver
111
- // resolver: null,
112
-
113
- // Automatically restore mock state between every test
114
- // restoreMocks: false,
115
-
116
- // The root directory that Jest should scan for tests and modules within
117
- // rootDir: null,
118
-
119
- // A list of paths to directories that Jest should use to search for files in
120
- // roots: [
121
- // "<rootDir>/__tests__"
122
- // ],
123
-
124
- // Allows you to use a custom runner instead of Jest's default test runner
125
- // runner: "jest-runner",
126
-
127
- // The paths to modules that run some code to configure or set up the testing environment before each test
128
- // setupFiles: [],
129
-
130
- // A list of paths to modules that run some code to configure or set up the testing framework before each test
131
- // setupFilesAfterEnv: [],
132
-
133
- // A list of paths to snapshot serializer modules Jest should use for snapshot testing
134
- // snapshotSerializers: [],
135
-
136
- // The test environment that will be used for testing
137
- testEnvironment: "node",
138
-
139
- // Options that will be passed to the testEnvironment
140
- // testEnvironmentOptions: {},
141
-
142
- // Adds a location field to test results
143
- // testLocationInResults: false,
144
-
145
- // The glob patterns Jest uses to detect test files
146
- // testMatch: [
147
- // "**/__tests__/**/*.[jt]s?(x)",
148
- // "**/?(*.)+(spec|test).[tj]s?(x)"
149
- // ],
150
-
151
- // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
152
- // testPathIgnorePatterns: [
153
- // "\\\\node_modules\\\\"
154
- // ],
155
-
156
- // The regexp pattern or array of patterns that Jest uses to detect test files
157
- // testRegex: [],
158
-
159
- // This option allows the use of a custom results processor
160
- // testResultsProcessor: null,
161
-
162
- // This option allows use of a custom test runner
163
- // testRunner: "jasmine2",
164
-
165
- // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
166
- // testURL: "http://localhost",
167
-
168
- // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
169
- // timers: "real",
170
-
171
- // A map from regular expressions to paths to transformers
172
- transform: {
173
- "^.+\\.tsx?$": "ts-jest"
174
- },
175
-
176
- // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
177
- // transformIgnorePatterns: [
178
- // "\\\\node_modules\\\\"
179
- // ],
180
-
181
- // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
182
- // unmockedModulePathPatterns: undefined,
183
-
184
- // Indicates whether each individual test should be reported during the run
185
- // verbose: null,
186
-
187
- // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
188
- // watchPathIgnorePatterns: [],
189
-
190
- // Whether to use watchman for file crawling
191
- // watchman: true,
192
- };
package/src/index.ts DELETED
@@ -1,9 +0,0 @@
1
- export { ValidationScope } from "./validation-scope";
2
- export { ValidationErrorsModel } from "./validation-errors-model";
3
- export { ValidationModel } from "./validation-model";
4
- export { IValidationPropertyResult } from "./validation-property-result";
5
- export { IValidationResult } from "./validation-result";
6
- export { Validator } from "./validator";
7
- export { IValidatorSetup } from "./validator-setup";
8
-
9
- export * from "./validators";
@@ -1,3 +0,0 @@
1
- export type ValidationErrorsModel<TModel> = {
2
- [k in keyof TModel]: string[];
3
- };
@@ -1,3 +0,0 @@
1
- export type ValidationModel<TModel> = {
2
- [K in keyof TModel]: boolean;
3
- };
@@ -1,5 +0,0 @@
1
- export interface IValidationPropertyResult {
2
- isValid: boolean;
3
-
4
- errors: string[];
5
- }
@@ -1,11 +0,0 @@
1
- import { IValidationPropertyResult } from "./validation-property-result";
2
-
3
- export interface IValidationResult<TModel> {
4
- isValid: boolean;
5
-
6
- properties: {
7
- [K in keyof TModel]: IValidationPropertyResult;
8
- };
9
-
10
- errors: string[];
11
- }
@@ -1,119 +0,0 @@
1
- import cloneDeep from "lodash.clonedeep";
2
- import get from "lodash.get";
3
- import isEqual from "lodash.isequal";
4
- import keys from "lodash.keys";
5
- import { IValidationPropertyResult } from "./validation-property-result";
6
- import { IValidationResult } from "./validation-result";
7
- import { Validator } from "./validator";
8
-
9
- export class ValidationScope<TModel extends {}> {
10
- private originalModel: TModel;
11
- private modelInfo: {
12
- [K in keyof TModel]: {
13
- validators: Array<Validator<TModel, K>>
14
- }
15
- };
16
-
17
- constructor(private setup: {
18
- getModel: () => TModel;
19
- onValidationChanged?: (result: IValidationResult<TModel>) => Promise<void>;
20
-
21
- }) {
22
- this.originalModel = cloneDeep(setup.getModel());
23
- this.modelInfo = {} as any;
24
- }
25
-
26
- public useOriginal = (model: TModel): ValidationScope<TModel> => {
27
- this.originalModel = cloneDeep(model);
28
- return this;
29
- }
30
-
31
- public useValidators = <K extends keyof TModel>(key: K, ...validators: Array<Validator<TModel, K>>): ValidationScope<TModel> => {
32
- this.modelInfo[key] = {
33
- validators: validators
34
- };
35
- return this;
36
- }
37
-
38
- public isPropertyDirty = (field: keyof TModel, key: string | null = null): boolean => {
39
- const model: TModel = this.setup.getModel();
40
- const originalField = this.originalModel[field];
41
- const modelField = model[field];
42
- if (Array.isArray(originalField) && Array.isArray(modelField)) {
43
- if (originalField.length !== modelField.length) return true;
44
- for (let index = 0; index < originalField.length; index++) {
45
- if (originalField[index] === modelField[index]) continue;
46
- if (key == null) return true;
47
- if (get(originalField[index], key) !== get(modelField[index], key)) return true;
48
- }
49
- return false;
50
- }
51
- if (key == null) return !isEqual(this.originalModel[field], model[field]);
52
- return get(this.originalModel[field], key) !== get(model[field], key);
53
- }
54
-
55
- public getOriginalProperty = <K extends keyof TModel>(field: K): TModel[K] => {
56
- return this.originalModel[field];
57
- }
58
-
59
- public isDirty = (...fields: Array<keyof TModel>): boolean => {
60
- for (const property in this.originalModel) {
61
- if (!this.originalModel.hasOwnProperty(property)) continue;
62
-
63
- if (fields && fields.length > 0) {
64
- if (!fields.some(x => x === property)) continue;
65
- }
66
-
67
- if (this.isPropertyDirty(property)) return true;
68
- }
69
-
70
- return false;
71
- }
72
-
73
- public isPropertyValid = async <K extends keyof TModel>(field: K): Promise<IValidationPropertyResult> => {
74
- if (this.modelInfo[field] && this.modelInfo[field].validators && this.modelInfo[field].validators) {
75
- let isValid: boolean = true;
76
- let errors: string[] = [];
77
-
78
- const model: TModel = this.setup.getModel();
79
- const value: TModel[K] = model[field];
80
-
81
- for (const validator of this.modelInfo[field].validators) {
82
- const validatorResult: IValidationPropertyResult = await validator.isValid(value, model, field);
83
- isValid = isValid && validatorResult.isValid;
84
- if (!validatorResult.isValid) errors = [...errors, ...validatorResult.errors];
85
- }
86
- return {
87
- isValid: isValid,
88
- errors: errors
89
- };
90
- }
91
-
92
- return {
93
- isValid: true,
94
- errors: []
95
- };
96
- }
97
-
98
- public isValid = async (): Promise<IValidationResult<TModel>> => {
99
- const properties: Array<keyof TModel> = keys(this.setup.getModel()) as Array<keyof TModel>;
100
- const result: IValidationResult<TModel> = {
101
- isValid: true,
102
- errors: [],
103
- properties: {} as {
104
- [K in keyof TModel]: IValidationPropertyResult;
105
- }
106
- } as IValidationResult<TModel>;
107
-
108
- for (const property of properties) {
109
- const propertyValidationResult: IValidationPropertyResult = await this.isPropertyValid(property);
110
- result.isValid = result.isValid && propertyValidationResult.isValid;
111
- result.properties[property] = propertyValidationResult;
112
- if (!propertyValidationResult.isValid) result.errors = [...result.errors, ...propertyValidationResult.errors];
113
- }
114
-
115
- if (this.setup.onValidationChanged != null) await this.setup.onValidationChanged(result);
116
-
117
- return result;
118
- }
119
- }
@@ -1,4 +0,0 @@
1
- export interface IValidatorSetup<TModel, K extends keyof TModel> {
2
- isDisabled?: (value: TModel[K]) => boolean;
3
- getErrors?: (value: TModel[K]) => string[];
4
- }