thesimplevalidation 1.2.0 → 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/dist/ValidationErrorsModel.js +2 -0
- package/dist/ValidationErrorsModel.js.map +1 -0
- 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/dist/{src/validator-setup.d.ts → ValidatorSetup.d.ts} +2 -2
- 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 -17
- 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 +12 -12
- 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 -23
- package/dist/src/index.js.map +0 -1
- package/dist/src/validation-errors-model.js +0 -3
- package/dist/src/validation-errors-model.js.map +0 -1
- 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 -200
- package/dist/src/validation-scope.js.map +0 -1
- 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 -69
- 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 -80
- 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 -14
- package/dist/src/validators/index.js.map +0 -1
- package/dist/src/validators/max/index.d.ts +0 -10
- package/dist/src/validators/max/index.js +0 -88
- package/dist/src/validators/max/index.js.map +0 -1
- package/dist/src/validators/min/index.d.ts +0 -10
- package/dist/src/validators/min/index.js +0 -89
- 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 -84
- 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 -76
- 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-errors-model.ts +0 -3
- package/src/validation-model.ts +0 -3
- package/src/validation-property-result.ts +0 -5
- package/src/validation-result.ts +0 -11
- package/src/validation-scope.ts +0 -119
- package/src/validator-setup.ts +0 -4
- 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 -32
- package/src/validators/min/__tests__/index.test.ts +0 -92
- package/src/validators/min/index.ts +0 -33
- 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
- /package/dist/{src/validation-errors-model.d.ts → ValidationErrorsModel.d.ts} +0 -0
- /package/dist/{src/validation-model.d.ts → ValidationModel.d.ts} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation-result.js","sourceRoot":"","sources":["../../src/validation-result.ts"],"names":[],"mappings":""}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { IValidationPropertyResult } from "./validation-property-result";
|
|
2
|
-
import { IValidationResult } from "./validation-result";
|
|
3
|
-
import { Validator } from "./validator";
|
|
4
|
-
export declare class ValidationScope<TModel extends {}> {
|
|
5
|
-
private setup;
|
|
6
|
-
private originalModel;
|
|
7
|
-
private modelInfo;
|
|
8
|
-
constructor(setup: {
|
|
9
|
-
getModel: () => TModel;
|
|
10
|
-
onValidationChanged?: (result: IValidationResult<TModel>) => Promise<void>;
|
|
11
|
-
});
|
|
12
|
-
useOriginal: (model: TModel) => ValidationScope<TModel>;
|
|
13
|
-
useValidators: <K extends keyof TModel>(key: K, ...validators: Validator<TModel, K, import("./validator-setup").IValidatorSetup<TModel, K>>[]) => ValidationScope<TModel>;
|
|
14
|
-
isPropertyDirty: (field: keyof TModel, key?: string | null) => boolean;
|
|
15
|
-
getOriginalProperty: <K extends keyof TModel>(field: K) => TModel[K];
|
|
16
|
-
isDirty: (...fields: Array<keyof TModel>) => boolean;
|
|
17
|
-
isPropertyValid: <K extends keyof TModel>(field: K) => Promise<IValidationPropertyResult>;
|
|
18
|
-
isValid: () => Promise<IValidationResult<TModel>>;
|
|
19
|
-
}
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
-
if (ar || !(i in from)) {
|
|
41
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
-
ar[i] = from[i];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
-
};
|
|
47
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
|
-
};
|
|
50
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
exports.ValidationScope = void 0;
|
|
52
|
-
var lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep"));
|
|
53
|
-
var lodash_get_1 = __importDefault(require("lodash.get"));
|
|
54
|
-
var lodash_isequal_1 = __importDefault(require("lodash.isequal"));
|
|
55
|
-
var lodash_keys_1 = __importDefault(require("lodash.keys"));
|
|
56
|
-
var ValidationScope = /** @class */ (function () {
|
|
57
|
-
function ValidationScope(setup) {
|
|
58
|
-
var _this = this;
|
|
59
|
-
this.setup = setup;
|
|
60
|
-
this.useOriginal = function (model) {
|
|
61
|
-
_this.originalModel = (0, lodash_clonedeep_1.default)(model);
|
|
62
|
-
return _this;
|
|
63
|
-
};
|
|
64
|
-
this.useValidators = function (key) {
|
|
65
|
-
var validators = [];
|
|
66
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
67
|
-
validators[_i - 1] = arguments[_i];
|
|
68
|
-
}
|
|
69
|
-
_this.modelInfo[key] = {
|
|
70
|
-
validators: validators
|
|
71
|
-
};
|
|
72
|
-
return _this;
|
|
73
|
-
};
|
|
74
|
-
this.isPropertyDirty = function (field, key) {
|
|
75
|
-
if (key === void 0) { key = null; }
|
|
76
|
-
var model = _this.setup.getModel();
|
|
77
|
-
var originalField = _this.originalModel[field];
|
|
78
|
-
var modelField = model[field];
|
|
79
|
-
if (Array.isArray(originalField) && Array.isArray(modelField)) {
|
|
80
|
-
if (originalField.length !== modelField.length)
|
|
81
|
-
return true;
|
|
82
|
-
for (var index = 0; index < originalField.length; index++) {
|
|
83
|
-
if (originalField[index] === modelField[index])
|
|
84
|
-
continue;
|
|
85
|
-
if (key == null)
|
|
86
|
-
return true;
|
|
87
|
-
if ((0, lodash_get_1.default)(originalField[index], key) !== (0, lodash_get_1.default)(modelField[index], key))
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
if (key == null)
|
|
93
|
-
return !(0, lodash_isequal_1.default)(_this.originalModel[field], model[field]);
|
|
94
|
-
return (0, lodash_get_1.default)(_this.originalModel[field], key) !== (0, lodash_get_1.default)(model[field], key);
|
|
95
|
-
};
|
|
96
|
-
this.getOriginalProperty = function (field) {
|
|
97
|
-
return _this.originalModel[field];
|
|
98
|
-
};
|
|
99
|
-
this.isDirty = function () {
|
|
100
|
-
var fields = [];
|
|
101
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
102
|
-
fields[_i] = arguments[_i];
|
|
103
|
-
}
|
|
104
|
-
var _loop_1 = function (property) {
|
|
105
|
-
if (!_this.originalModel.hasOwnProperty(property))
|
|
106
|
-
return "continue";
|
|
107
|
-
if (fields && fields.length > 0) {
|
|
108
|
-
if (!fields.some(function (x) { return x === property; }))
|
|
109
|
-
return "continue";
|
|
110
|
-
}
|
|
111
|
-
if (_this.isPropertyDirty(property))
|
|
112
|
-
return { value: true };
|
|
113
|
-
};
|
|
114
|
-
for (var property in _this.originalModel) {
|
|
115
|
-
var state_1 = _loop_1(property);
|
|
116
|
-
if (typeof state_1 === "object")
|
|
117
|
-
return state_1.value;
|
|
118
|
-
}
|
|
119
|
-
return false;
|
|
120
|
-
};
|
|
121
|
-
this.isPropertyValid = function (field) { return __awaiter(_this, void 0, void 0, function () {
|
|
122
|
-
var isValid, errors, model, value, _i, _a, validator, validatorResult;
|
|
123
|
-
return __generator(this, function (_b) {
|
|
124
|
-
switch (_b.label) {
|
|
125
|
-
case 0:
|
|
126
|
-
if (!(this.modelInfo[field] && this.modelInfo[field].validators && this.modelInfo[field].validators)) return [3 /*break*/, 5];
|
|
127
|
-
isValid = true;
|
|
128
|
-
errors = [];
|
|
129
|
-
model = this.setup.getModel();
|
|
130
|
-
value = model[field];
|
|
131
|
-
_i = 0, _a = this.modelInfo[field].validators;
|
|
132
|
-
_b.label = 1;
|
|
133
|
-
case 1:
|
|
134
|
-
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
135
|
-
validator = _a[_i];
|
|
136
|
-
return [4 /*yield*/, validator.isValid(value, model, field)];
|
|
137
|
-
case 2:
|
|
138
|
-
validatorResult = _b.sent();
|
|
139
|
-
isValid = isValid && validatorResult.isValid;
|
|
140
|
-
if (!validatorResult.isValid)
|
|
141
|
-
errors = __spreadArray(__spreadArray([], errors, true), validatorResult.errors, true);
|
|
142
|
-
_b.label = 3;
|
|
143
|
-
case 3:
|
|
144
|
-
_i++;
|
|
145
|
-
return [3 /*break*/, 1];
|
|
146
|
-
case 4: return [2 /*return*/, {
|
|
147
|
-
isValid: isValid,
|
|
148
|
-
errors: errors
|
|
149
|
-
}];
|
|
150
|
-
case 5: return [2 /*return*/, {
|
|
151
|
-
isValid: true,
|
|
152
|
-
errors: []
|
|
153
|
-
}];
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
}); };
|
|
157
|
-
this.isValid = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
158
|
-
var properties, result, _i, properties_1, property, propertyValidationResult;
|
|
159
|
-
return __generator(this, function (_a) {
|
|
160
|
-
switch (_a.label) {
|
|
161
|
-
case 0:
|
|
162
|
-
properties = (0, lodash_keys_1.default)(this.setup.getModel());
|
|
163
|
-
result = {
|
|
164
|
-
isValid: true,
|
|
165
|
-
errors: [],
|
|
166
|
-
properties: {}
|
|
167
|
-
};
|
|
168
|
-
_i = 0, properties_1 = properties;
|
|
169
|
-
_a.label = 1;
|
|
170
|
-
case 1:
|
|
171
|
-
if (!(_i < properties_1.length)) return [3 /*break*/, 4];
|
|
172
|
-
property = properties_1[_i];
|
|
173
|
-
return [4 /*yield*/, this.isPropertyValid(property)];
|
|
174
|
-
case 2:
|
|
175
|
-
propertyValidationResult = _a.sent();
|
|
176
|
-
result.isValid = result.isValid && propertyValidationResult.isValid;
|
|
177
|
-
result.properties[property] = propertyValidationResult;
|
|
178
|
-
if (!propertyValidationResult.isValid)
|
|
179
|
-
result.errors = __spreadArray(__spreadArray([], result.errors, true), propertyValidationResult.errors, true);
|
|
180
|
-
_a.label = 3;
|
|
181
|
-
case 3:
|
|
182
|
-
_i++;
|
|
183
|
-
return [3 /*break*/, 1];
|
|
184
|
-
case 4:
|
|
185
|
-
if (!(this.setup.onValidationChanged != null)) return [3 /*break*/, 6];
|
|
186
|
-
return [4 /*yield*/, this.setup.onValidationChanged(result)];
|
|
187
|
-
case 5:
|
|
188
|
-
_a.sent();
|
|
189
|
-
_a.label = 6;
|
|
190
|
-
case 6: return [2 /*return*/, result];
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
}); };
|
|
194
|
-
this.originalModel = (0, lodash_clonedeep_1.default)(setup.getModel());
|
|
195
|
-
this.modelInfo = {};
|
|
196
|
-
}
|
|
197
|
-
return ValidationScope;
|
|
198
|
-
}());
|
|
199
|
-
exports.ValidationScope = ValidationScope;
|
|
200
|
-
//# sourceMappingURL=validation-scope.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation-scope.js","sourceRoot":"","sources":["../../src/validation-scope.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sEAAyC;AACzC,0DAA6B;AAC7B,kEAAqC;AACrC,4DAA+B;AAK/B;IAQI,yBAAoB,KAInB;QAJD,iBAOC;QAPmB,UAAK,GAAL,KAAK,CAIxB;QAKM,gBAAW,GAAG,UAAC,KAAa;YAC/B,KAAI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wBACvD,IAAI,CAAC,wBAAwB,CAAC,OAAO;4BAAE,MAAM,CAAC,MAAM,mCAAO,MAAM,CAAC,MAAM,SAAK,wBAAwB,CAAC,MAAM,OAAC,CAAC;;;wBAJ3F,IAAU,CAAA;;;6BAO7B,CAAA,IAAI,CAAC,KAAK,CAAC,mBAAmB,IAAI,IAAI,CAAA,EAAtC,wBAAsC;wBAAE,qBAAM,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAA;;wBAA5C,SAA4C,CAAC;;4BAEzF,sBAAO,MAAM,EAAC;;;aACjB,CAAA;QAhGG,IAAI,CAAC,aAAa,GAAG,IAAA,0BAAS,EAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjD,IAAI,CAAC,SAAS,GAAG,EAAS,CAAC;IAC/B,CAAC;IA+FL,sBAAC;AAAD,CAAC,AA9GD,IA8GC;AA9GY,0CAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validator-setup.js","sourceRoot":"","sources":["../../src/validator-setup.ts"],"names":[],"mappings":""}
|
package/dist/src/validator.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { IValidationPropertyResult } from "./validation-property-result";
|
|
2
|
-
import { IValidatorSetup } from "./validator-setup";
|
|
3
|
-
export declare abstract class Validator<TModel, K extends keyof TModel, TSetup extends IValidatorSetup<TModel, K> = IValidatorSetup<TModel, K>> {
|
|
4
|
-
protected setup: TSetup;
|
|
5
|
-
constructor(setup: TSetup);
|
|
6
|
-
isValid: (value: TModel[K], model: TModel, field: K) => Promise<IValidationPropertyResult>;
|
|
7
|
-
protected abstract isValidInternal(value: TModel[K], model: TModel, field: K): Promise<IValidationPropertyResult>;
|
|
8
|
-
}
|
package/dist/src/validator.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.Validator = void 0;
|
|
40
|
-
var Validator = /** @class */ (function () {
|
|
41
|
-
function Validator(setup) {
|
|
42
|
-
var _this = this;
|
|
43
|
-
this.setup = setup;
|
|
44
|
-
this.isValid = function (value, model, field) { return __awaiter(_this, void 0, void 0, function () {
|
|
45
|
-
var result;
|
|
46
|
-
return __generator(this, function (_a) {
|
|
47
|
-
switch (_a.label) {
|
|
48
|
-
case 0:
|
|
49
|
-
if (this.setup.isDisabled != null && this.setup.isDisabled(value)) {
|
|
50
|
-
return [2 /*return*/, {
|
|
51
|
-
isValid: true,
|
|
52
|
-
errors: []
|
|
53
|
-
}];
|
|
54
|
-
}
|
|
55
|
-
return [4 /*yield*/, this.isValidInternal(value, model, field)];
|
|
56
|
-
case 1:
|
|
57
|
-
result = _a.sent();
|
|
58
|
-
if (result.isValid !== true && this.setup.getErrors != null) {
|
|
59
|
-
result.errors = this.setup.getErrors(value);
|
|
60
|
-
}
|
|
61
|
-
return [2 /*return*/, result];
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}); };
|
|
65
|
-
}
|
|
66
|
-
return Validator;
|
|
67
|
-
}());
|
|
68
|
-
exports.Validator = Validator;
|
|
69
|
-
//# sourceMappingURL=validator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;IAEI,mBAAsB,KAAa;QAAnC,iBAAwC;QAAlB,UAAK,GAAL,KAAK,CAAQ;QAE5B,YAAO,GAAG,UAAO,KAAgB,EAAE,KAAa,EAAE,KAAQ;;;;;wBAC7D,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,IAAI,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;4BAC/D,sBAAO;oCACH,OAAO,EAAE,IAAI;oCACb,MAAM,EAAE,EAAE;iCACb,EAAC;yBACL;wBAEyC,qBAAM,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,EAAA;;wBAAnF,MAAM,GAA8B,SAA+C;wBACzF,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,IAAI,IAAI,EAAE;4BACzD,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;yBAC/C;wBAED,sBAAO,MAAM,EAAC;;;aACjB,CAAA;IAhBsC,CAAC;IAmB5C,gBAAC;AAAD,CAAC,AArBD,IAqBC;AArBqB,8BAAS"}
|
|
@@ -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 IBooleanValidatorSetup<TModel, K extends keyof TModel> extends IValidatorSetup<TModel, K> {
|
|
5
|
-
target: () => boolean;
|
|
6
|
-
}
|
|
7
|
-
export declare class BooleanValidator<TModel, K extends keyof TModel> extends Validator<TModel, K, IBooleanValidatorSetup<TModel, K>> {
|
|
8
|
-
constructor(setup: IBooleanValidatorSetup<TModel, K>);
|
|
9
|
-
isValidInternal(value: TModel[K]): Promise<IValidationPropertyResult>;
|
|
10
|
-
}
|
|
@@ -1,80 +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.BooleanValidator = void 0;
|
|
55
|
-
var validator_1 = require("../../validator");
|
|
56
|
-
var BooleanValidator = /** @class */ (function (_super) {
|
|
57
|
-
__extends(BooleanValidator, _super);
|
|
58
|
-
function BooleanValidator(setup) {
|
|
59
|
-
return _super.call(this, setup) || this;
|
|
60
|
-
}
|
|
61
|
-
BooleanValidator.prototype.isValidInternal = function (value) {
|
|
62
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
-
var isValid, targetValue;
|
|
64
|
-
return __generator(this, function (_a) {
|
|
65
|
-
isValid = true;
|
|
66
|
-
targetValue = this.setup.target();
|
|
67
|
-
if (value != null && typeof value === "boolean") {
|
|
68
|
-
isValid = targetValue === value;
|
|
69
|
-
}
|
|
70
|
-
return [2 /*return*/, {
|
|
71
|
-
isValid: isValid,
|
|
72
|
-
errors: []
|
|
73
|
-
}];
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
return BooleanValidator;
|
|
78
|
-
}(validator_1.Validator));
|
|
79
|
-
exports.BooleanValidator = BooleanValidator;
|
|
80
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/validators/boolean/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,6CAA4C;AAM5C;IAAsE,oCAAuD;IACzH,0BAAY,KAAwC;eAChD,kBAAM,KAAK,CAAC;IAChB,CAAC;IAEY,0CAAe,GAA5B,UAA6B,KAAgB;;;;gBACrC,OAAO,GAAY,IAAI,CAAC;gBACtB,WAAW,GAAY,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;gBAEjD,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE;oBAC7C,OAAO,GAAG,WAAW,KAAK,KAAK,CAAC;iBACnC;gBAED,sBAAO;wBACH,OAAO,EAAE,OAAO;wBAChB,MAAM,EAAE,EAAE;qBACb,EAAC;;;KACL;IACL,uBAAC;AAAD,CAAC,AAlBD,CAAsE,qBAAS,GAkB9E;AAlBY,4CAAgB"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { SimpleValidator, ISimpleValidatorSetup } from "./simple";
|
|
2
|
-
export { BooleanValidator, IBooleanValidatorSetup } from "./boolean";
|
|
3
|
-
export { RequiredValidator } from "./required";
|
|
4
|
-
export { MinValidator, IMinValidatorSetup } from "./min";
|
|
5
|
-
export { MaxValidator, IMaxValidatorSetup } from "./max";
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MaxValidator = exports.MinValidator = exports.RequiredValidator = exports.BooleanValidator = exports.SimpleValidator = void 0;
|
|
4
|
-
var simple_1 = require("./simple");
|
|
5
|
-
Object.defineProperty(exports, "SimpleValidator", { enumerable: true, get: function () { return simple_1.SimpleValidator; } });
|
|
6
|
-
var boolean_1 = require("./boolean");
|
|
7
|
-
Object.defineProperty(exports, "BooleanValidator", { enumerable: true, get: function () { return boolean_1.BooleanValidator; } });
|
|
8
|
-
var required_1 = require("./required");
|
|
9
|
-
Object.defineProperty(exports, "RequiredValidator", { enumerable: true, get: function () { return required_1.RequiredValidator; } });
|
|
10
|
-
var min_1 = require("./min");
|
|
11
|
-
Object.defineProperty(exports, "MinValidator", { enumerable: true, get: function () { return min_1.MinValidator; } });
|
|
12
|
-
var max_1 = require("./max");
|
|
13
|
-
Object.defineProperty(exports, "MaxValidator", { enumerable: true, get: function () { return max_1.MaxValidator; } });
|
|
14
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/validators/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkE;AAAzD,yGAAA,eAAe,OAAA;AACxB,qCAAqE;AAA5D,2GAAA,gBAAgB,OAAA;AACzB,uCAA+C;AAAtC,6GAAA,iBAAiB,OAAA;AAC1B,6BAAyD;AAAhD,mGAAA,YAAY,OAAA;AACrB,6BAAyD;AAAhD,mGAAA,YAAY,OAAA"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { IValidatorSetup } from "../../validator-setup";
|
|
2
|
-
import { IValidationPropertyResult } from "../../validation-property-result";
|
|
3
|
-
import { Validator } from "../../validator";
|
|
4
|
-
export interface IMaxValidatorSetup<TModel, K extends keyof TModel> extends IValidatorSetup<TModel, K> {
|
|
5
|
-
maxValue: () => number;
|
|
6
|
-
}
|
|
7
|
-
export declare class MaxValidator<TModel, K extends keyof TModel> extends Validator<TModel, K, IMaxValidatorSetup<TModel, K>> {
|
|
8
|
-
constructor(setup: IMaxValidatorSetup<TModel, K>);
|
|
9
|
-
isValidInternal(value: TModel[K]): Promise<IValidationPropertyResult>;
|
|
10
|
-
}
|
|
@@ -1,88 +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.MaxValidator = void 0;
|
|
55
|
-
var validator_1 = require("../../validator");
|
|
56
|
-
var MaxValidator = /** @class */ (function (_super) {
|
|
57
|
-
__extends(MaxValidator, _super);
|
|
58
|
-
function MaxValidator(setup) {
|
|
59
|
-
return _super.call(this, setup) || this;
|
|
60
|
-
}
|
|
61
|
-
MaxValidator.prototype.isValidInternal = function (value) {
|
|
62
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
-
var isValid, maxValue;
|
|
64
|
-
return __generator(this, function (_a) {
|
|
65
|
-
isValid = true;
|
|
66
|
-
if (value != null) {
|
|
67
|
-
maxValue = this.setup.maxValue();
|
|
68
|
-
if (Array.isArray(value)) {
|
|
69
|
-
isValid = value.length <= maxValue;
|
|
70
|
-
}
|
|
71
|
-
else if (typeof value === "string") {
|
|
72
|
-
isValid = value.length <= maxValue;
|
|
73
|
-
}
|
|
74
|
-
else if (typeof value === "number") {
|
|
75
|
-
isValid = value <= maxValue;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return [2 /*return*/, {
|
|
79
|
-
isValid: isValid,
|
|
80
|
-
errors: []
|
|
81
|
-
}];
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
return MaxValidator;
|
|
86
|
-
}(validator_1.Validator));
|
|
87
|
-
exports.MaxValidator = MaxValidator;
|
|
88
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/validators/max/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,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,AAvBD,CAAkE,qBAAS,GAuB1E;AAvBY,oCAAY"}
|
|
@@ -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 IMinValidatorSetup<TModel, K extends keyof TModel> extends IValidatorSetup<TModel, K> {
|
|
5
|
-
minValue: () => number;
|
|
6
|
-
}
|
|
7
|
-
export declare class MinValidator<TModel, K extends keyof TModel> extends Validator<TModel, K, IMinValidatorSetup<TModel, K>> {
|
|
8
|
-
constructor(setup: IMinValidatorSetup<TModel, K>);
|
|
9
|
-
isValidInternal(value: TModel[K]): Promise<IValidationPropertyResult>;
|
|
10
|
-
}
|