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.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -6
- package/dist/index.js.map +1 -1
- package/dist/src/index.d.ts +8 -8
- package/dist/src/index.js +22 -10
- package/dist/src/index.js.map +1 -1
- package/dist/src/validation-errors-model.d.ts +3 -3
- package/dist/src/validation-errors-model.js +2 -2
- package/dist/src/validation-model.d.ts +3 -3
- package/dist/src/validation-model.js +2 -2
- package/dist/src/validation-property-result.d.ts +4 -4
- package/dist/src/validation-property-result.js +2 -2
- package/dist/src/validation-result.d.ts +8 -8
- package/dist/src/validation-result.js +2 -2
- package/dist/src/validation-scope.d.ts +19 -19
- package/dist/src/validation-scope.js +199 -196
- package/dist/src/validation-scope.js.map +1 -1
- package/dist/src/validator-setup.d.ts +4 -4
- package/dist/src/validator-setup.js +2 -2
- package/dist/src/validator.d.ts +8 -8
- package/dist/src/validator.js +68 -67
- package/dist/src/validator.js.map +1 -1
- package/dist/src/validators/boolean/index.d.ts +10 -10
- package/dist/src/validators/boolean/index.js +79 -76
- package/dist/src/validators/boolean/index.js.map +1 -1
- package/dist/src/validators/index.d.ts +5 -5
- package/dist/src/validators/index.js +13 -12
- package/dist/src/validators/index.js.map +1 -1
- package/dist/src/validators/max/index.d.ts +10 -11
- package/dist/src/validators/max/index.js +87 -85
- package/dist/src/validators/max/index.js.map +1 -1
- package/dist/src/validators/min/index.d.ts +10 -11
- package/dist/src/validators/min/index.js +88 -86
- package/dist/src/validators/min/index.js.map +1 -1
- package/dist/src/validators/required/index.d.ts +7 -7
- package/dist/src/validators/required/index.js +83 -80
- package/dist/src/validators/required/index.js.map +1 -1
- package/dist/src/validators/simple/index.d.ts +10 -10
- package/dist/src/validators/simple/index.js +75 -72
- package/dist/src/validators/simple/index.js.map +1 -1
- package/package.json +10 -13
- package/src/validation-scope.ts +3 -2
- package/src/validators/max/index.ts +7 -9
- 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 (
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
d
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
case
|
|
37
|
-
case
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
if (t &&
|
|
43
|
-
if (t[
|
|
44
|
-
_.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
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":"
|
|
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.
|
|
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": "
|
|
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.
|
|
37
|
-
"@types/lodash.get": "4.4.
|
|
38
|
-
"@types/lodash.isequal": "4.5.
|
|
39
|
-
"@types/lodash.keys": "4.2.
|
|
40
|
-
"@types/jest": "
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"jest": "
|
|
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
|
}
|
package/src/validation-scope.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
18
|
-
if (val != null) {
|
|
16
|
+
if (value != null) {
|
|
19
17
|
const maxValue: number = this.setup.maxValue();
|
|
20
|
-
if (Array.isArray(
|
|
21
|
-
isValid =
|
|
22
|
-
} else if (typeof
|
|
23
|
-
isValid =
|
|
24
|
-
} else if (typeof
|
|
25
|
-
isValid =
|
|
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
|
-
|
|
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(
|
|
22
|
-
isValid =
|
|
23
|
-
} else if (typeof
|
|
24
|
-
isValid =
|
|
25
|
-
} else if (typeof
|
|
26
|
-
isValid =
|
|
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
|
|