knight-validation 3.3.3 → 3.4.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/lib/lib/Validator.d.ts +2 -1
- package/lib/lib/Validator.js +18 -0
- package/package.json +1 -1
package/lib/lib/Validator.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Misfit } from 'knight-misfit';
|
|
|
2
2
|
import { Constraint } from './Constraint';
|
|
3
3
|
export interface ValidatorOptions {
|
|
4
4
|
checkOnlyWhatIsThere?: boolean;
|
|
5
|
+
exclude?: string[];
|
|
5
6
|
}
|
|
6
7
|
interface ValidatorEntry<T = any> {
|
|
7
8
|
properties: string[];
|
|
@@ -20,7 +21,7 @@ export declare class Validator<T = any> {
|
|
|
20
21
|
add(properties: string[], constraint: Constraint, condition?: (object: T) => Promise<boolean>): void;
|
|
21
22
|
add(properties: string[], constraintName: string, validate: (object: T, properties: string[]) => Promise<Misfit | null>, condition?: (object: T) => Promise<boolean>): void;
|
|
22
23
|
add(property: string, validator: Validator<any>, condition?: (object: T) => Promise<boolean>): void;
|
|
23
|
-
add(validator: Validator
|
|
24
|
+
add(validator: Validator): void;
|
|
24
25
|
validate(object: T, options?: ValidatorOptions): Promise<Misfit[]>;
|
|
25
26
|
}
|
|
26
27
|
export {};
|
package/lib/lib/Validator.js
CHANGED
|
@@ -21,6 +21,9 @@ 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);
|
|
24
27
|
if (args[0] instanceof Validator) {
|
|
25
28
|
let validator = args[0];
|
|
26
29
|
for (let propertyConstraint of validator.entries) {
|
|
@@ -66,12 +69,27 @@ class Validator {
|
|
|
66
69
|
else {
|
|
67
70
|
throw new Error('Invalid parameters');
|
|
68
71
|
}
|
|
72
|
+
l.dev('properties', properties);
|
|
73
|
+
l.dev('constraint', constraint);
|
|
74
|
+
l.dev('validator', validator);
|
|
75
|
+
l.dev('condition', condition);
|
|
76
|
+
if (properties.length == 1 && ((_a = this.options) === null || _a === void 0 ? void 0 : _a.exclude)) {
|
|
77
|
+
for (let property of (_b = this.options) === null || _b === void 0 ? void 0 : _b.exclude) {
|
|
78
|
+
if (property == properties[0]) {
|
|
79
|
+
l.dev('Not adding constraint since the property was excluded');
|
|
80
|
+
l.returning();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
69
85
|
this.entries.push({
|
|
70
86
|
properties: properties,
|
|
71
87
|
constraint: constraint,
|
|
72
88
|
validator: validator,
|
|
73
89
|
condition: condition
|
|
74
90
|
});
|
|
91
|
+
l.dev('Constraint was added');
|
|
92
|
+
l.returning();
|
|
75
93
|
}
|
|
76
94
|
}
|
|
77
95
|
validate(object, options) {
|