UNPKG

1.42 kBTypeScriptView Raw
1/** @module validate */
2import { IValidationRule } from './IValidationRule';
3import { Schema } from './Schema';
4import { ValidationResult } from './ValidationResult';
5/**
6 * Validation rule that check that at least one of the object properties is not null.
7 *
8 * @see [[IValidationRule]]
9 *
10 * ### Example ###
11 *
12 * let schema = new Schema()
13 * .withRule(new AtLeastOneExistsRule("field1", "field2"));
14 *
15 * schema.validate({ field1: 1, field2: "A" }); // Result: no errors
16 * schema.validate({ field1: 1 }); // Result: no errors
17 * schema.validate({ }); // Result: at least one of properties field1, field2 must exist
18 */
19export declare class AtLeastOneExistsRule implements IValidationRule {
20 private readonly _properties;
21 /**
22 * Creates a new validation rule and sets its values
23 *
24 * @param properties a list of property names where at least one property must exist
25 */
26 constructor(...properties: string[]);
27 /**
28 * Validates a given value against this rule.
29 *
30 * @param path a dot notation path to the value.
31 * @param schema a schema this rule is called from
32 * @param value a value to be validated.
33 * @param results a list with validation results to add new results.
34 */
35 validate(path: string, schema: Schema, value: any, results: ValidationResult[]): void;
36}