knight-validation 3.3.1 → 3.3.3
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.js +28 -4
- package/package.json +1 -1
package/lib/lib/Validator.js
CHANGED
|
@@ -85,7 +85,7 @@ class Validator {
|
|
|
85
85
|
let misfittingProperties = [];
|
|
86
86
|
for (let entry of this.entries) {
|
|
87
87
|
let constraintOrValidatorName = entry.constraint ? (_a = entry.constraint) === null || _a === void 0 ? void 0 : _a.name : entry.validator ? entry.validator.constructor.name : '';
|
|
88
|
-
l.location = ['' + entry.properties + ' ' + constraintOrValidatorName];
|
|
88
|
+
l.location = ['' + JSON.stringify(entry.properties) + ' > ' + constraintOrValidatorName];
|
|
89
89
|
let propertyAlreadyHasAMisfit = false;
|
|
90
90
|
for (let property of entry.properties) {
|
|
91
91
|
if (misfittingProperties.indexOf(property) > -1) {
|
|
@@ -93,6 +93,9 @@ class Validator {
|
|
|
93
93
|
break;
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
|
+
if (entry.properties.length == 0 && misfittingProperties.indexOf(null) > -1) {
|
|
97
|
+
propertyAlreadyHasAMisfit = true;
|
|
98
|
+
}
|
|
96
99
|
if (propertyAlreadyHasAMisfit) {
|
|
97
100
|
l.dev('Property already has misfit. Skipping...');
|
|
98
101
|
continue;
|
|
@@ -126,7 +129,7 @@ class Validator {
|
|
|
126
129
|
l.called('entry.constraint.validate');
|
|
127
130
|
}
|
|
128
131
|
else if (entry.properties.length == 1) {
|
|
129
|
-
l.dev('Constraint is to be applied to one property
|
|
132
|
+
l.dev('Constraint is to be applied to one property');
|
|
130
133
|
let property = entry.properties[0];
|
|
131
134
|
let dotNotation = new DotNotation_1.DotNotation(property);
|
|
132
135
|
let value = dotNotation.get(object);
|
|
@@ -148,6 +151,9 @@ class Validator {
|
|
|
148
151
|
}
|
|
149
152
|
misfit.properties = entry.properties.slice();
|
|
150
153
|
misfittingProperties.push(...entry.properties);
|
|
154
|
+
if (entry.properties.length == 0) {
|
|
155
|
+
misfittingProperties.push(null);
|
|
156
|
+
}
|
|
151
157
|
misfits.push(misfit);
|
|
152
158
|
}
|
|
153
159
|
}
|
|
@@ -160,9 +166,17 @@ class Validator {
|
|
|
160
166
|
let property = entry.properties[0];
|
|
161
167
|
let dotNotation = new DotNotation_1.DotNotation(property);
|
|
162
168
|
let value = dotNotation.get(object);
|
|
169
|
+
if (typeof value != 'object' || value === null) {
|
|
170
|
+
l.dev('Value of the property is not of type object or null. Skipping...', value);
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
163
173
|
if (value instanceof Array) {
|
|
164
174
|
l.dev('Value of the property is an array. Iterating its elements...');
|
|
165
175
|
for (let i = 0; i < value.length; i++) {
|
|
176
|
+
if (typeof value[i] != 'object' || value[i] === null) {
|
|
177
|
+
l.dev('Array element is not of type object or null. Skipping...', value[i]);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
166
180
|
l.calling('entry.validator.validate', value[i], options);
|
|
167
181
|
let subMisfits = yield entry.validator.validate(value[i], options);
|
|
168
182
|
l.called('entry.validator.validate');
|
|
@@ -170,7 +184,12 @@ class Validator {
|
|
|
170
184
|
l.dev('Validator returned misfits', subMisfits);
|
|
171
185
|
l.creator('Adding prefix to misfit properties...', `${property}[${i}].`);
|
|
172
186
|
for (let misfit of subMisfits) {
|
|
173
|
-
misfit.
|
|
187
|
+
if (misfit.properties.length == 0) {
|
|
188
|
+
misfit.properties.push(`${property}[${i}]`);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
misfit.addPrefix(`${property}[${i}].`);
|
|
192
|
+
}
|
|
174
193
|
}
|
|
175
194
|
misfittingProperties.push(...entry.properties);
|
|
176
195
|
misfits.push(...subMisfits);
|
|
@@ -186,7 +205,12 @@ class Validator {
|
|
|
186
205
|
l.dev('Validator returned misfits', subMisfits);
|
|
187
206
|
l.creator('Adding prefix to misfit properties...', property + '.');
|
|
188
207
|
for (let misfit of subMisfits) {
|
|
189
|
-
misfit.
|
|
208
|
+
if (misfit.properties.length == 0) {
|
|
209
|
+
misfit.properties.push(property);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
misfit.addPrefix(property + '.');
|
|
213
|
+
}
|
|
190
214
|
}
|
|
191
215
|
misfittingProperties.push(...entry.properties);
|
|
192
216
|
misfits.push(...subMisfits);
|