UNPKG

1.77 kBTypeScriptView Raw
1import { Schema } from './Schema';
2import { ValidationResult } from './ValidationResult';
3import { IValidationRule } from './IValidationRule';
4/**
5 * Schema to validate arrays.
6 *
7 * ### Example ###
8 *
9 * let schema = new ArraySchema(TypeCode.String);
10 *
11 * schema.validate(["A", "B", "C"]); // Result: no errors
12 * schema.validate([1, 2, 3]); // Result: element type mismatch
13 * schema.validate("A"); // Result: type mismatch
14 */
15export declare class ArraySchema extends Schema {
16 private _valueType;
17 /**
18 * Creates a new instance of validation schema and sets its values.
19 *
20 * @param valueType a type of array elements. Null means that elements may have any type.
21 * @param required (optional) true to always require non-null values.
22 * @param rules (optional) a list with validation rules.
23 *
24 * @see [[TypeCode]]
25 */
26 constructor(valueType?: any, required?: boolean, rules?: IValidationRule[]);
27 /**
28 * Gets the type of array elements.
29 * Null means that elements may have any type.
30 *
31 * @returns the type of array elements.
32 */
33 getValueType(): any;
34 /**
35 * Sets the type of array elements.
36 * Null means that elements may have any type.
37 *
38 * @param value a type of array elements.
39 */
40 setValueType(value: any): void;
41 /**
42 * Validates a given value against the schema and configured validation rules.
43 *
44 * @param path a dot notation path to the value.
45 * @param value a value to be validated.
46 * @param results a list with validation results to add new results.
47 */
48 protected performValidation(path: string, value: any, results: ValidationResult[]): void;
49}