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
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src";
|
|
1
|
+
export * from "./src";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./src"), exports);
|
|
7
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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
|
-
export * from "./validators";
|
|
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
|
+
export * from "./validators";
|
package/dist/src/index.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Validator = exports.ValidationScope = void 0;
|
|
18
|
+
var validation_scope_1 = require("./validation-scope");
|
|
19
|
+
Object.defineProperty(exports, "ValidationScope", { enumerable: true, get: function () { return validation_scope_1.ValidationScope; } });
|
|
20
|
+
var validator_1 = require("./validator");
|
|
21
|
+
Object.defineProperty(exports, "Validator", { enumerable: true, get: function () { return validator_1.Validator; } });
|
|
22
|
+
__exportStar(require("./validators"), exports);
|
|
11
23
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uDAAqD;AAA5C,mHAAA,eAAe,OAAA;AAKxB,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAGlB,+CAA6B"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
[k in keyof TModel]: string[];
|
|
3
|
-
};
|
|
1
|
+
export type ValidationErrorsModel<TModel> = {
|
|
2
|
+
[k in keyof TModel]: string[];
|
|
3
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=validation-errors-model.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
[K in keyof TModel]: boolean;
|
|
3
|
-
};
|
|
1
|
+
export type ValidationModel<TModel> = {
|
|
2
|
+
[K in keyof TModel]: boolean;
|
|
3
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=validation-model.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface IValidationPropertyResult {
|
|
2
|
-
isValid: boolean;
|
|
3
|
-
errors: string[];
|
|
4
|
-
}
|
|
1
|
+
export interface IValidationPropertyResult {
|
|
2
|
+
isValid: boolean;
|
|
3
|
+
errors: string[];
|
|
4
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=validation-property-result.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { IValidationPropertyResult } from "./validation-property-result";
|
|
2
|
-
export interface IValidationResult<TModel> {
|
|
3
|
-
isValid: boolean;
|
|
4
|
-
properties: {
|
|
5
|
-
[K in keyof TModel]: IValidationPropertyResult;
|
|
6
|
-
};
|
|
7
|
-
errors: string[];
|
|
8
|
-
}
|
|
1
|
+
import { IValidationPropertyResult } from "./validation-property-result";
|
|
2
|
+
export interface IValidationResult<TModel> {
|
|
3
|
+
isValid: boolean;
|
|
4
|
+
properties: {
|
|
5
|
+
[K in keyof TModel]: IValidationPropertyResult;
|
|
6
|
+
};
|
|
7
|
+
errors: string[];
|
|
8
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
//# sourceMappingURL=validation-result.js.map
|
|
@@ -1,19 +1,19 @@
|
|
|
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
|
|
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) => boolean;
|
|
15
|
-
getOriginalProperty: <K extends keyof TModel>(field: K) => TModel[K];
|
|
16
|
-
isDirty: (...fields:
|
|
17
|
-
isPropertyValid: <K extends keyof TModel>(field: K) => Promise<IValidationPropertyResult>;
|
|
18
|
-
isValid: () => Promise<IValidationResult<TModel>>;
|
|
19
|
-
}
|
|
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,197 +1,200 @@
|
|
|
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 (_) 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
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
validators
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return _this.originalModel[field];
|
|
95
|
-
};
|
|
96
|
-
this.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
var
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
case
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
case
|
|
182
|
-
|
|
183
|
-
return [
|
|
184
|
-
case
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
case
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
|
|
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;
|
|
197
200
|
//# sourceMappingURL=validation-scope.js.map
|