1 | /** @module validate */
|
2 | import { IValidationRule } from './IValidationRule';
|
3 | import { Schema } from './Schema';
|
4 | import { ValidationResult } from './ValidationResult';
|
5 | /**
|
6 | * Validation rule that compares two object properties.
|
7 | *
|
8 | * @see [[IValidationRule]]
|
9 | *
|
10 | * ### Example ###
|
11 | *
|
12 | * let schema = new ObjectSchema()
|
13 | * .withRule(new PropertyComparisonRule("field1", "NE", "field2"));
|
14 | *
|
15 | * schema.validate({ field1: 1, field2: 2 }); // Result: no errors
|
16 | * schema.validate({ field1: 1, field2: 1 }); // Result: field1 shall not be equal to field2
|
17 | * schema.validate({}); // Result: no errors
|
18 | */
|
19 | export declare class PropertiesComparisonRule implements IValidationRule {
|
20 | private readonly _property1;
|
21 | private readonly _property2;
|
22 | private readonly _operation;
|
23 | /**
|
24 | * Creates a new validation rule and sets its arguments.
|
25 | *
|
26 | * @param property1 a name of the first property to compare.
|
27 | * @param operation a comparison operation: "==" ("=", "EQ"), "!= " ("<>", "NE"); "<"/">" ("LT"/"GT"), "<="/">=" ("LE"/"GE"); "LIKE".
|
28 | * @param property2 a name of the second property to compare.
|
29 | *
|
30 | * @see [[ObjectComparator.compare]]
|
31 | */
|
32 | constructor(property1: string, operation: string, property2: string);
|
33 | /**
|
34 | * Validates a given value against this rule.
|
35 | *
|
36 | * @param path a dot notation path to the value.
|
37 | * @param schema a schema this rule is called from
|
38 | * @param value a value to be validated.
|
39 | * @param results a list with validation results to add new results.
|
40 | */
|
41 | validate(path: string, schema: Schema, value: any, results: ValidationResult[]): void;
|
42 | }
|