thesimplevalidation 1.1.2 → 2.0.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/README.md +158 -140
- package/dist/Validation.d.ts +16 -0
- package/dist/Validation.js +99 -0
- package/dist/Validation.js.map +1 -0
- package/{src/validation-errors-model.ts → dist/ValidationErrorsModel.d.ts} +3 -3
- package/dist/ValidationErrorsModel.js +2 -0
- package/dist/ValidationErrorsModel.js.map +1 -0
- package/{src/validation-model.ts → dist/ValidationModel.d.ts} +3 -3
- package/dist/ValidationModel.js +2 -0
- package/dist/ValidationModel.js.map +1 -0
- package/dist/ValidationPropertyResult.d.ts +4 -0
- package/dist/ValidationPropertyResult.js +2 -0
- package/dist/ValidationPropertyResult.js.map +1 -0
- package/dist/ValidationResult.d.ts +8 -0
- package/dist/ValidationResult.js +2 -0
- package/dist/ValidationResult.js.map +1 -0
- package/dist/ValidationScope.d.ts +15 -0
- package/dist/ValidationScope.js +95 -0
- package/dist/ValidationScope.js.map +1 -0
- package/dist/Validator.d.ts +10 -0
- package/dist/Validator.js +28 -0
- package/dist/Validator.js.map +1 -0
- package/{src/validator-setup.ts → dist/ValidatorSetup.d.ts} +4 -4
- package/dist/ValidatorSetup.js +2 -0
- package/dist/ValidatorSetup.js.map +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +5 -6
- package/dist/index.js.map +1 -1
- package/dist/validators/boolean/BooleanValidator.d.ts +7 -0
- package/dist/validators/boolean/BooleanValidator.js +18 -0
- package/dist/validators/boolean/BooleanValidator.js.map +1 -0
- package/dist/validators/boolean/BooleanValidatorSetup.d.ts +4 -0
- package/dist/validators/boolean/BooleanValidatorSetup.js +2 -0
- package/dist/validators/boolean/BooleanValidatorSetup.js.map +1 -0
- package/dist/validators/index.d.ts +9 -0
- package/dist/validators/index.js +6 -0
- package/dist/validators/index.js.map +1 -0
- package/dist/validators/max/MaxValidator.d.ts +7 -0
- package/dist/validators/max/MaxValidator.js +26 -0
- package/dist/validators/max/MaxValidator.js.map +1 -0
- package/dist/validators/max/MaxValidatorSetup.d.ts +4 -0
- package/dist/validators/max/MaxValidatorSetup.js +2 -0
- package/dist/validators/max/MaxValidatorSetup.js.map +1 -0
- package/dist/validators/min/MinValidator.d.ts +7 -0
- package/dist/validators/min/MinValidator.js +27 -0
- package/dist/validators/min/MinValidator.js.map +1 -0
- package/dist/validators/min/MinValidatorSetup.d.ts +4 -0
- package/dist/validators/min/MinValidatorSetup.js +2 -0
- package/dist/validators/min/MinValidatorSetup.js.map +1 -0
- package/dist/validators/required/RequiredValidator.d.ts +7 -0
- package/dist/validators/required/RequiredValidator.js +21 -0
- package/dist/validators/required/RequiredValidator.js.map +1 -0
- package/dist/validators/simple/SimpleValidator.d.ts +7 -0
- package/dist/validators/simple/SimpleValidator.js +14 -0
- package/dist/validators/simple/SimpleValidator.js.map +1 -0
- package/dist/validators/simple/SimpleValidatorSetup.d.ts +4 -0
- package/dist/validators/simple/SimpleValidatorSetup.js +2 -0
- package/dist/validators/simple/SimpleValidatorSetup.js.map +1 -0
- package/package.json +13 -16
- package/.editorconfig +0 -11
- package/.travis.yml +0 -7
- package/.yo-rc.json +0 -9
- package/dist/src/index.d.ts +0 -8
- package/dist/src/index.js +0 -11
- package/dist/src/index.js.map +0 -1
- package/dist/src/validation-errors-model.d.ts +0 -3
- package/dist/src/validation-errors-model.js +0 -3
- package/dist/src/validation-errors-model.js.map +0 -1
- package/dist/src/validation-model.d.ts +0 -3
- package/dist/src/validation-model.js +0 -3
- package/dist/src/validation-model.js.map +0 -1
- package/dist/src/validation-property-result.d.ts +0 -4
- package/dist/src/validation-property-result.js +0 -3
- package/dist/src/validation-property-result.js.map +0 -1
- package/dist/src/validation-result.d.ts +0 -8
- package/dist/src/validation-result.js +0 -3
- package/dist/src/validation-result.js.map +0 -1
- package/dist/src/validation-scope.d.ts +0 -19
- package/dist/src/validation-scope.js +0 -197
- package/dist/src/validation-scope.js.map +0 -1
- package/dist/src/validator-setup.d.ts +0 -4
- package/dist/src/validator-setup.js +0 -3
- package/dist/src/validator-setup.js.map +0 -1
- package/dist/src/validator.d.ts +0 -8
- package/dist/src/validator.js +0 -68
- package/dist/src/validator.js.map +0 -1
- package/dist/src/validators/boolean/index.d.ts +0 -10
- package/dist/src/validators/boolean/index.js +0 -77
- package/dist/src/validators/boolean/index.js.map +0 -1
- package/dist/src/validators/index.d.ts +0 -5
- package/dist/src/validators/index.js +0 -13
- package/dist/src/validators/index.js.map +0 -1
- package/dist/src/validators/max/index.d.ts +0 -11
- package/dist/src/validators/max/index.js +0 -86
- package/dist/src/validators/max/index.js.map +0 -1
- package/dist/src/validators/min/index.d.ts +0 -11
- package/dist/src/validators/min/index.js +0 -87
- package/dist/src/validators/min/index.js.map +0 -1
- package/dist/src/validators/required/index.d.ts +0 -7
- package/dist/src/validators/required/index.js +0 -81
- package/dist/src/validators/required/index.js.map +0 -1
- package/dist/src/validators/simple/index.d.ts +0 -10
- package/dist/src/validators/simple/index.js +0 -73
- package/dist/src/validators/simple/index.js.map +0 -1
- package/index.ts +0 -1
- package/jest.config.js +0 -192
- package/src/index.ts +0 -9
- package/src/validation-property-result.ts +0 -5
- package/src/validation-result.ts +0 -11
- package/src/validation-scope.ts +0 -118
- package/src/validator.ts +0 -25
- package/src/validators/boolean/index.ts +0 -27
- package/src/validators/index.ts +0 -5
- package/src/validators/max/__tests__/index.test.ts +0 -92
- package/src/validators/max/index.ts +0 -34
- package/src/validators/min/__tests__/index.test.ts +0 -92
- package/src/validators/min/index.ts +0 -35
- package/src/validators/required/__tests__/index.test.ts +0 -229
- package/src/validators/required/index.ts +0 -24
- package/src/validators/simple/index.ts +0 -22
- package/thesimplevalidation.code-workspace +0 -10
- package/tsconfig.json +0 -23
- package/tslint.json +0 -18
|
@@ -1,87 +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 (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 MinValidator = /** @class */ (function (_super) {
|
|
54
|
-
__extends(MinValidator, _super);
|
|
55
|
-
function MinValidator(setup) {
|
|
56
|
-
return _super.call(this, setup) || this;
|
|
57
|
-
}
|
|
58
|
-
MinValidator.prototype.isValidInternal = function (value) {
|
|
59
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
-
var isValid, val, minValue;
|
|
61
|
-
return __generator(this, function (_a) {
|
|
62
|
-
isValid = true;
|
|
63
|
-
val = this.setup.converter ? this.setup.converter(value) : value;
|
|
64
|
-
if (val != null) {
|
|
65
|
-
minValue = this.setup.minValue();
|
|
66
|
-
// tslint:disable-next-line:prefer-conditional-expression
|
|
67
|
-
if (Array.isArray(val)) {
|
|
68
|
-
isValid = val.length >= minValue;
|
|
69
|
-
}
|
|
70
|
-
else if (typeof val === "string") {
|
|
71
|
-
isValid = val.length >= minValue;
|
|
72
|
-
}
|
|
73
|
-
else if (typeof val === "number") {
|
|
74
|
-
isValid = val >= minValue;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return [2 /*return*/, {
|
|
78
|
-
isValid: isValid,
|
|
79
|
-
errors: []
|
|
80
|
-
}];
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
return MinValidator;
|
|
85
|
-
}(validator_1.Validator));
|
|
86
|
-
exports.MinValidator = MinValidator;
|
|
87
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/validators/min/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,6CAA4C;AAO5C;IAAkE,gCAAmD;IACjH,sBAAY,KAAoC;eAC5C,kBAAM,KAAK,CAAC;IAChB,CAAC;IAEY,sCAAe,GAA5B,UAA6B,KAAgB;;;;gBACrC,OAAO,GAAY,IAAI,CAAC;gBACtB,GAAG,GAAY,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;gBAChF,IAAI,GAAG,IAAI,IAAI,EAAE;oBACP,QAAQ,GAAW,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;oBAC/C,yDAAyD;oBACzD,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;wBACpB,OAAO,GAAG,GAAG,CAAC,MAAM,IAAI,QAAQ,CAAC;qBACpC;yBAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;wBAChC,OAAO,GAAG,GAAG,CAAC,MAAM,IAAI,QAAQ,CAAC;qBACpC;yBAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;wBAChC,OAAO,GAAG,GAAG,IAAI,QAAQ,CAAC;qBAC7B;iBACJ;gBAED,sBAAO;wBACH,OAAO,EAAE,OAAO;wBAChB,MAAM,EAAE,EAAE;qBACb,EAAC;;;KACL;IACL,mBAAC;AAAD,CAAC,AAzBD,CAAkE,qBAAS,GAyB1E;AAzBY,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,81 +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 (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 RequiredValidator = /** @class */ (function (_super) {
|
|
54
|
-
__extends(RequiredValidator, _super);
|
|
55
|
-
function RequiredValidator(setup) {
|
|
56
|
-
if (setup === void 0) { setup = {}; }
|
|
57
|
-
return _super.call(this, setup) || this;
|
|
58
|
-
}
|
|
59
|
-
RequiredValidator.prototype.isValidInternal = function (value) {
|
|
60
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
-
var isValid;
|
|
62
|
-
return __generator(this, function (_a) {
|
|
63
|
-
isValid = true;
|
|
64
|
-
// tslint:disable-next-line:prefer-conditional-expression
|
|
65
|
-
if (Array.isArray(value)) {
|
|
66
|
-
isValid = value.length > 0;
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
isValid = !!value;
|
|
70
|
-
}
|
|
71
|
-
return [2 /*return*/, {
|
|
72
|
-
isValid: isValid,
|
|
73
|
-
errors: []
|
|
74
|
-
}];
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
return RequiredValidator;
|
|
79
|
-
}(validator_1.Validator));
|
|
80
|
-
exports.RequiredValidator = RequiredValidator;
|
|
81
|
-
//# 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,73 +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 (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;
|
|
73
|
-
//# 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";
|
package/src/validation-result.ts
DELETED
package/src/validation-scope.ts
DELETED
|
@@ -1,118 +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>, scope: ValidationScope<TModel>) => Promise<void>;
|
|
20
|
-
}) {
|
|
21
|
-
this.originalModel = cloneDeep(setup.getModel());
|
|
22
|
-
this.modelInfo = {} as any;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public useOriginal = (model: TModel): ValidationScope<TModel> => {
|
|
26
|
-
this.originalModel = cloneDeep(model);
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public useValidators = <K extends keyof TModel>(key: K, ...validators: Array<Validator<TModel, K>>): ValidationScope<TModel> => {
|
|
31
|
-
this.modelInfo[key] = {
|
|
32
|
-
validators: validators
|
|
33
|
-
};
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public isPropertyDirty = (field: keyof TModel, key: string | null = null): boolean => {
|
|
38
|
-
const model: TModel = this.setup.getModel();
|
|
39
|
-
const originalField = this.originalModel[field];
|
|
40
|
-
const modelField = model[field];
|
|
41
|
-
if (Array.isArray(originalField) && Array.isArray(modelField)) {
|
|
42
|
-
if (originalField.length !== modelField.length) return true;
|
|
43
|
-
for (let index = 0; index < originalField.length; index++) {
|
|
44
|
-
if (originalField[index] === modelField[index]) continue;
|
|
45
|
-
if (key == null) return true;
|
|
46
|
-
if (get(originalField[index], key) !== get(modelField[index], key)) return true;
|
|
47
|
-
}
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
if (key == null) return !isEqual(this.originalModel[field], model[field]);
|
|
51
|
-
return get(this.originalModel[field], key) !== get(model[field], key);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public getOriginalProperty = <K extends keyof TModel>(field: K): TModel[K] => {
|
|
55
|
-
return this.originalModel[field];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public isDirty = (...fields: Array<keyof TModel>): boolean => {
|
|
59
|
-
for (const property in this.originalModel) {
|
|
60
|
-
if (!this.originalModel.hasOwnProperty(property)) continue;
|
|
61
|
-
|
|
62
|
-
if (fields && fields.length > 0) {
|
|
63
|
-
if (!fields.some(x => x === property)) continue;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (this.isPropertyDirty(property)) return true;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public isPropertyValid = async <K extends keyof TModel>(field: K): Promise<IValidationPropertyResult> => {
|
|
73
|
-
if (this.modelInfo[field] && this.modelInfo[field].validators && this.modelInfo[field].validators) {
|
|
74
|
-
let isValid: boolean = true;
|
|
75
|
-
let errors: string[] = [];
|
|
76
|
-
|
|
77
|
-
const model: TModel = this.setup.getModel();
|
|
78
|
-
const value: TModel[K] = model[field];
|
|
79
|
-
|
|
80
|
-
for (const validator of this.modelInfo[field].validators) {
|
|
81
|
-
const validatorResult: IValidationPropertyResult = await validator.isValid(value, model, field);
|
|
82
|
-
isValid = isValid && validatorResult.isValid;
|
|
83
|
-
if (!validatorResult.isValid) errors = [...errors, ...validatorResult.errors];
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
isValid: isValid,
|
|
87
|
-
errors: errors
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
isValid: true,
|
|
93
|
-
errors: []
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
public isValid = async (): Promise<IValidationResult<TModel>> => {
|
|
98
|
-
const properties: Array<keyof TModel> = keys(this.setup.getModel()) as Array<keyof TModel>;
|
|
99
|
-
const result: IValidationResult<TModel> = {
|
|
100
|
-
isValid: true,
|
|
101
|
-
errors: [],
|
|
102
|
-
properties: {} as {
|
|
103
|
-
[K in keyof TModel]: IValidationPropertyResult;
|
|
104
|
-
}
|
|
105
|
-
} as IValidationResult<TModel>;
|
|
106
|
-
|
|
107
|
-
for (const property of properties) {
|
|
108
|
-
const propertyValidationResult: IValidationPropertyResult = await this.isPropertyValid(property);
|
|
109
|
-
result.isValid = result.isValid && propertyValidationResult.isValid;
|
|
110
|
-
result.properties[property] = propertyValidationResult;
|
|
111
|
-
if (!propertyValidationResult.isValid) result.errors = [...result.errors, ...propertyValidationResult.errors];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (this.setup.onValidationChanged != null) await this.setup.onValidationChanged(result, this);
|
|
115
|
-
|
|
116
|
-
return result;
|
|
117
|
-
}
|
|
118
|
-
}
|
package/src/validator.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { IValidationPropertyResult } from "./validation-property-result";
|
|
2
|
-
import { IValidatorSetup } from "./validator-setup";
|
|
3
|
-
|
|
4
|
-
export abstract class Validator<TModel, K extends keyof TModel, TSetup extends IValidatorSetup<TModel, K> = IValidatorSetup<TModel, K>> {
|
|
5
|
-
|
|
6
|
-
constructor(protected setup: TSetup) { }
|
|
7
|
-
|
|
8
|
-
public isValid = async (value: TModel[K], model: TModel, field: K): Promise<IValidationPropertyResult> => {
|
|
9
|
-
if (this.setup.isDisabled != null && this.setup.isDisabled(value)) {
|
|
10
|
-
return {
|
|
11
|
-
isValid: true,
|
|
12
|
-
errors: []
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const result: IValidationPropertyResult = await this.isValidInternal(value, model, field);
|
|
17
|
-
if (result.isValid !== true && this.setup.getErrors != null) {
|
|
18
|
-
result.errors = this.setup.getErrors(value);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
protected abstract isValidInternal(value: TModel[K], model: TModel, field: K): Promise<IValidationPropertyResult>;
|
|
25
|
-
}
|