UNPKG

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