knight-validation 3.3.2 → 3.3.4
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 -1
- package/lib/lib/Validator.js +19 -3
- package/package.json +1 -1
package/lib/lib/Validator.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare class Validator<T = any> {
|
|
|
20
20
|
add(properties: string[], constraint: Constraint, condition?: (object: T) => Promise<boolean>): void;
|
|
21
21
|
add(properties: string[], constraintName: string, validate: (object: T, properties: string[]) => Promise<Misfit | null>, condition?: (object: T) => Promise<boolean>): void;
|
|
22
22
|
add(property: string, validator: Validator<any>, condition?: (object: T) => Promise<boolean>): void;
|
|
23
|
-
add(validator: Validator
|
|
23
|
+
add(validator: Validator): void;
|
|
24
24
|
validate(object: T, options?: ValidatorOptions): Promise<Misfit[]>;
|
|
25
25
|
}
|
|
26
26
|
export {};
|
package/lib/lib/Validator.js
CHANGED
|
@@ -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
|
}
|
|
@@ -178,7 +184,12 @@ class Validator {
|
|
|
178
184
|
l.dev('Validator returned misfits', subMisfits);
|
|
179
185
|
l.creator('Adding prefix to misfit properties...', `${property}[${i}].`);
|
|
180
186
|
for (let misfit of subMisfits) {
|
|
181
|
-
misfit.
|
|
187
|
+
if (misfit.properties.length == 0) {
|
|
188
|
+
misfit.properties.push(`${property}[${i}]`);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
misfit.addPrefix(`${property}[${i}].`);
|
|
192
|
+
}
|
|
182
193
|
}
|
|
183
194
|
misfittingProperties.push(...entry.properties);
|
|
184
195
|
misfits.push(...subMisfits);
|
|
@@ -194,7 +205,12 @@ class Validator {
|
|
|
194
205
|
l.dev('Validator returned misfits', subMisfits);
|
|
195
206
|
l.creator('Adding prefix to misfit properties...', property + '.');
|
|
196
207
|
for (let misfit of subMisfits) {
|
|
197
|
-
misfit.
|
|
208
|
+
if (misfit.properties.length == 0) {
|
|
209
|
+
misfit.properties.push(property);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
misfit.addPrefix(property + '.');
|
|
213
|
+
}
|
|
198
214
|
}
|
|
199
215
|
misfittingProperties.push(...entry.properties);
|
|
200
216
|
misfits.push(...subMisfits);
|