UNPKG

2.13 kBTypeScriptView Raw
1/** @module validate */
2import { IValidationRule } from './IValidationRule';
3import { ValidationResult } from './ValidationResult';
4import { Schema } from './Schema';
5/**
6 * Schema to validate object properties
7 *
8 * @see [[ObjectSchema]]
9 *
10 * ### Example ###
11 *
12 * let schema = new ObjectSchema()
13 * .withProperty(new PropertySchema("id", TypeCode.String));
14 *
15 * schema.validate({ id: "1", name: "ABC" }); // Result: no errors
16 * schema.validate({ name: "ABC" }); // Result: no errors
17 * schema.validate({ id: 1, name: "ABC" }); // Result: id type mismatch
18 */
19export declare class PropertySchema extends Schema {
20 private _name;
21 private _type;
22 /**
23 * Creates a new validation schema and sets its values.
24 *
25 * @param name (optional) a property name
26 * @param type (optional) a property type
27 * @param required (optional) true to always require non-null values.
28 * @param rules (optional) a list with validation rules.
29 *
30 * @see [[IValidationRule]]
31 * @see [[TypeCode]]
32 */
33 constructor(name?: string, type?: any, required?: boolean, rules?: IValidationRule[]);
34 /**
35 * Gets the property name.
36 *
37 * @returns the property name.
38 */
39 getName(): string;
40 /**
41 * Sets the property name.
42 *
43 * @param value a new property name.
44 */
45 setName(value: string): void;
46 /**
47 * Gets the property type.
48 *
49 * @returns the property type.
50 */
51 getType(): any;
52 /**
53 * Sets a new property type.
54 * The type can be defined as type, type name or [[TypeCode]]
55 *
56 * @param value a new property type.
57 */
58 setType(value: any): void;
59 /**
60 * Validates a given value against the schema and configured validation rules.
61 *
62 * @param path a dot notation path to the value.
63 * @param value a value to be validated.
64 * @param results a list with validation results to add new results.
65 */
66 performValidation(path: string, value: any, results: ValidationResult[]): void;
67}