thesimplevalidation 1.1.2 → 1.2.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 (44) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +17 -6
  3. package/dist/index.js.map +1 -1
  4. package/dist/src/index.d.ts +8 -8
  5. package/dist/src/index.js +22 -10
  6. package/dist/src/index.js.map +1 -1
  7. package/dist/src/validation-errors-model.d.ts +3 -3
  8. package/dist/src/validation-errors-model.js +2 -2
  9. package/dist/src/validation-model.d.ts +3 -3
  10. package/dist/src/validation-model.js +2 -2
  11. package/dist/src/validation-property-result.d.ts +4 -4
  12. package/dist/src/validation-property-result.js +2 -2
  13. package/dist/src/validation-result.d.ts +8 -8
  14. package/dist/src/validation-result.js +2 -2
  15. package/dist/src/validation-scope.d.ts +19 -19
  16. package/dist/src/validation-scope.js +199 -196
  17. package/dist/src/validation-scope.js.map +1 -1
  18. package/dist/src/validator-setup.d.ts +4 -4
  19. package/dist/src/validator-setup.js +2 -2
  20. package/dist/src/validator.d.ts +8 -8
  21. package/dist/src/validator.js +68 -67
  22. package/dist/src/validator.js.map +1 -1
  23. package/dist/src/validators/boolean/index.d.ts +10 -10
  24. package/dist/src/validators/boolean/index.js +79 -76
  25. package/dist/src/validators/boolean/index.js.map +1 -1
  26. package/dist/src/validators/index.d.ts +5 -5
  27. package/dist/src/validators/index.js +13 -12
  28. package/dist/src/validators/index.js.map +1 -1
  29. package/dist/src/validators/max/index.d.ts +10 -11
  30. package/dist/src/validators/max/index.js +87 -85
  31. package/dist/src/validators/max/index.js.map +1 -1
  32. package/dist/src/validators/min/index.d.ts +10 -11
  33. package/dist/src/validators/min/index.js +88 -86
  34. package/dist/src/validators/min/index.js.map +1 -1
  35. package/dist/src/validators/required/index.d.ts +7 -7
  36. package/dist/src/validators/required/index.js +83 -80
  37. package/dist/src/validators/required/index.js.map +1 -1
  38. package/dist/src/validators/simple/index.d.ts +10 -10
  39. package/dist/src/validators/simple/index.js +75 -72
  40. package/dist/src/validators/simple/index.js.map +1 -1
  41. package/package.json +10 -13
  42. package/src/validation-scope.ts +3 -2
  43. package/src/validators/max/index.ts +7 -9
  44. package/src/validators/min/index.ts +7 -9
@@ -1,10 +1,10 @@
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
+ 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,73 +1,76 @@
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
16
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
17
- return new (P || (P = Promise))(function (resolve, reject) {
18
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
19
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
20
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
21
- step((generator = generator.apply(thisArg, _arguments || [])).next());
22
- });
23
- };
24
- var __generator = (this && this.__generator) || function (thisArg, body) {
25
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
26
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
27
- function verb(n) { return function (v) { return step([n, v]); }; }
28
- function step(op) {
29
- if (f) throw new TypeError("Generator is already executing.");
30
- while (_) try {
31
- 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;
32
- if (y = 0, t) op = [op[0] & 2, t.value];
33
- switch (op[0]) {
34
- case 0: case 1: t = op; break;
35
- case 4: _.label++; return { value: op[1], done: false };
36
- case 5: _.label++; y = op[1]; op = [0]; continue;
37
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
38
- default:
39
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
40
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
41
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
42
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
43
- if (t[2]) _.ops.pop();
44
- _.trys.pop(); continue;
45
- }
46
- op = body.call(thisArg, _);
47
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
48
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
49
- }
50
- };
51
- Object.defineProperty(exports, "__esModule", { value: true });
52
- var validator_1 = require("../../validator");
53
- var SimpleValidator = /** @class */ (function (_super) {
54
- __extends(SimpleValidator, _super);
55
- function SimpleValidator(setup) {
56
- return _super.call(this, setup) || this;
57
- }
58
- SimpleValidator.prototype.isValidInternal = function (_value) {
59
- return __awaiter(this, void 0, void 0, function () {
60
- var isValid;
61
- return __generator(this, function (_a) {
62
- isValid = this.setup.getValidation();
63
- return [2 /*return*/, {
64
- isValid: isValid,
65
- errors: []
66
- }];
67
- });
68
- });
69
- };
70
- return SimpleValidator;
71
- }(validator_1.Validator));
72
- exports.SimpleValidator = SimpleValidator;
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;
73
76
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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"}
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/package.json CHANGED
@@ -1,16 +1,14 @@
1
1
  {
2
2
  "name": "thesimplevalidation",
3
3
  "description": "The simple validation",
4
- "version": "1.1.2",
4
+ "version": "1.2.0",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
7
7
  "build": "tsc",
8
- "lint": "tslint index.ts",
9
- "pretest": "npm run lint",
10
8
  "test": "jest"
11
9
  },
12
10
  "publishConfig": {
13
- "registry": "http://registry.npmjs.org"
11
+ "registry": "https://registry.npmjs.org"
14
12
  },
15
13
  "author": "Alexey Ripenko <alexey@ripenko.ru>",
16
14
  "license": "MIT",
@@ -33,14 +31,13 @@
33
31
  "lodash.keys": "4.2.0"
34
32
  },
35
33
  "devDependencies": {
36
- "@types/lodash.clonedeep": "4.5.6",
37
- "@types/lodash.get": "4.4.6",
38
- "@types/lodash.isequal": "4.5.5",
39
- "@types/lodash.keys": "4.2.6",
40
- "@types/jest": "24.0.25",
41
- "tslint": "5.20.1",
42
- "typescript": "3.7.4",
43
- "jest": "24.9.0",
44
- "ts-jest": "24.2.0"
34
+ "@types/lodash.clonedeep": "4.5.7",
35
+ "@types/lodash.get": "4.4.7",
36
+ "@types/lodash.isequal": "4.5.6",
37
+ "@types/lodash.keys": "4.2.7",
38
+ "@types/jest": "29.5.1",
39
+ "typescript": "5.0.4",
40
+ "jest": "29.5.0",
41
+ "ts-jest": "29.1.0"
45
42
  }
46
43
  }
@@ -16,7 +16,8 @@ export class ValidationScope<TModel extends {}> {
16
16
 
17
17
  constructor(private setup: {
18
18
  getModel: () => TModel;
19
- onValidationChanged?: (result: IValidationResult<TModel>, scope: ValidationScope<TModel>) => Promise<void>;
19
+ onValidationChanged?: (result: IValidationResult<TModel>) => Promise<void>;
20
+
20
21
  }) {
21
22
  this.originalModel = cloneDeep(setup.getModel());
22
23
  this.modelInfo = {} as any;
@@ -111,7 +112,7 @@ export class ValidationScope<TModel extends {}> {
111
112
  if (!propertyValidationResult.isValid) result.errors = [...result.errors, ...propertyValidationResult.errors];
112
113
  }
113
114
 
114
- if (this.setup.onValidationChanged != null) await this.setup.onValidationChanged(result, this);
115
+ if (this.setup.onValidationChanged != null) await this.setup.onValidationChanged(result);
115
116
 
116
117
  return result;
117
118
  }
@@ -4,7 +4,6 @@ import { Validator } from "../../validator";
4
4
 
5
5
  export interface IMaxValidatorSetup<TModel, K extends keyof TModel> extends IValidatorSetup<TModel, K> {
6
6
  maxValue: () => number;
7
- converter?: (val: TModel[K]) => unknown;
8
7
  }
9
8
 
10
9
  export class MaxValidator<TModel, K extends keyof TModel> extends Validator<TModel, K, IMaxValidatorSetup<TModel, K>> {
@@ -14,15 +13,14 @@ export class MaxValidator<TModel, K extends keyof TModel> extends Validator<TMod
14
13
 
15
14
  public async isValidInternal(value: TModel[K]): Promise<IValidationPropertyResult> {
16
15
  let isValid: boolean = true;
17
- const val: unknown = this.setup.converter ? this.setup.converter(value) : value;
18
- if (val != null) {
16
+ if (value != null) {
19
17
  const maxValue: number = this.setup.maxValue();
20
- if (Array.isArray(val)) {
21
- isValid = val.length <= maxValue;
22
- } else if (typeof val === "string") {
23
- isValid = val.length <= maxValue;
24
- } else if (typeof val === "number") {
25
- isValid = val <= maxValue;
18
+ if (Array.isArray(value)) {
19
+ isValid = value.length <= maxValue;
20
+ } else if (typeof value === "string") {
21
+ isValid = value.length <= maxValue;
22
+ } else if (typeof value === "number") {
23
+ isValid = value <= maxValue;
26
24
  }
27
25
  }
28
26
 
@@ -4,7 +4,6 @@ import { Validator } from "../../validator";
4
4
 
5
5
  export interface IMinValidatorSetup<TModel, K extends keyof TModel> extends IValidatorSetup<TModel, K> {
6
6
  minValue: () => number;
7
- converter?: (val: TModel[K]) => unknown;
8
7
  }
9
8
 
10
9
  export class MinValidator<TModel, K extends keyof TModel> extends Validator<TModel, K, IMinValidatorSetup<TModel, K>> {
@@ -14,16 +13,15 @@ export class MinValidator<TModel, K extends keyof TModel> extends Validator<TMod
14
13
 
15
14
  public async isValidInternal(value: TModel[K]): Promise<IValidationPropertyResult> {
16
15
  let isValid: boolean = true;
17
- const val: unknown = this.setup.converter ? this.setup.converter(value) : value;
18
- if (val != null) {
16
+ if (value != null) {
19
17
  const minValue: number = this.setup.minValue();
20
18
  // tslint:disable-next-line:prefer-conditional-expression
21
- if (Array.isArray(val)) {
22
- isValid = val.length >= minValue;
23
- } else if (typeof val === "string") {
24
- isValid = val.length >= minValue;
25
- } else if (typeof val === "number") {
26
- isValid = val >= minValue;
19
+ if (Array.isArray(value)) {
20
+ isValid = value.length >= minValue;
21
+ } else if (typeof value === "string") {
22
+ isValid = value.length >= minValue;
23
+ } else if (typeof value === "number") {
24
+ isValid = value >= minValue;
27
25
  }
28
26
  }
29
27