knight-validation 3.3.4 → 3.4.1
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/lib/lib/Validator.d.ts +1 -0
- package/lib/lib/Validator.js +25 -4
- package/package.json +1 -1
package/lib/lib/Validator.d.ts
CHANGED
package/lib/lib/Validator.js
CHANGED
|
@@ -21,21 +21,25 @@ class Validator {
|
|
|
21
21
|
this.options = options;
|
|
22
22
|
}
|
|
23
23
|
add(...args) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
let l = log.mt('add');
|
|
26
|
+
l.param('args', args);
|
|
27
|
+
let entries = [];
|
|
24
28
|
if (args[0] instanceof Validator) {
|
|
25
29
|
let validator = args[0];
|
|
26
30
|
for (let propertyConstraint of validator.entries) {
|
|
27
|
-
|
|
31
|
+
entries.push(propertyConstraint);
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
34
|
else if (args[0] instanceof Constraint_1.Constraint) {
|
|
31
|
-
|
|
35
|
+
entries.push({
|
|
32
36
|
properties: [],
|
|
33
37
|
constraint: args[0],
|
|
34
38
|
condition: args.length > 1 ? args[1] : undefined
|
|
35
39
|
});
|
|
36
40
|
}
|
|
37
41
|
else if (typeof args[0] == 'string' && typeof args[1] == 'function') {
|
|
38
|
-
|
|
42
|
+
entries.push({
|
|
39
43
|
properties: [],
|
|
40
44
|
constraint: new QuickConstraint_1.QuickConstraint(args[0], args[1]),
|
|
41
45
|
condition: args.length > 2 ? args[2] : undefined
|
|
@@ -66,13 +70,30 @@ class Validator {
|
|
|
66
70
|
else {
|
|
67
71
|
throw new Error('Invalid parameters');
|
|
68
72
|
}
|
|
69
|
-
|
|
73
|
+
entries.push({
|
|
70
74
|
properties: properties,
|
|
71
75
|
constraint: constraint,
|
|
72
76
|
validator: validator,
|
|
73
77
|
condition: condition
|
|
74
78
|
});
|
|
75
79
|
}
|
|
80
|
+
for (let entry of entries) {
|
|
81
|
+
let propertyExcluded = false;
|
|
82
|
+
if ((entry === null || entry === void 0 ? void 0 : entry.properties.length) == 1 && ((_a = this.options) === null || _a === void 0 ? void 0 : _a.exclude)) {
|
|
83
|
+
for (let property of (_b = this.options) === null || _b === void 0 ? void 0 : _b.exclude) {
|
|
84
|
+
if (property == entry.properties[0]) {
|
|
85
|
+
propertyExcluded = true;
|
|
86
|
+
l.dev('Not adding constraint since the property was excluded', entry);
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (!propertyExcluded) {
|
|
92
|
+
this.entries.push(entry);
|
|
93
|
+
l.dev('Constraint was added', entry);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
l.returning();
|
|
76
97
|
}
|
|
77
98
|
validate(object, options) {
|
|
78
99
|
return __awaiter(this, void 0, void 0, function* () {
|