/
validatable-attribute.ts
144 lines (129 loc) · 5.13 KB
/
validatable-attribute.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
module formsjs {
/**
* The set of supported validation constraints that can be specified for an attribute.
*/
export interface ValidatableAttribute {
/**
* Optional set of acceptable values; any attributes values not within this set will be considered invalid.
*
* <p>Enum validations will fail with a default error message unless overridden with "enumFailureMessage".
*/
enumeration?:Array<any>;
/**
* Optional custom failure message used in the event of a failed "enum" validation.
*
* <p>Use a <code>${value}</code> token to include the attribute's current string value,
* (e.g. if value is "foobar" then "${value} is not allowed" becomes "foobar is not allowed").
*/
enumerationFailureMessage?:string;
/**
* If this attribute is a collection of objects, nested object validation rules belong within this property.
*
* <p>For example, a collection of addresses may be stored within an "addresses" attribute.
* That collection may have overall validation rules (e.g. required, min, max) and rules for individual addresses.
* For example let's say that at least one address is required and that each address must define a "street".
* Such a validation rule may look like this:
*
* <p><code>{
* addresses: {
* required: true,
* min: 1,
* items: {
* street: {
* type: "string"
* required: true
* }
* }
* }
* }</code>
*
* <p>This property is only supported for collection attributes (e.g. <code>type == ValidationType.ARRAY</code>).
*/
items?:ValidationSchema;
/**
* Maximum length/size of attribute.
*
* <p>The attribute type will determine which type of comparison this constraint results in:
* <ul>
* <li>array: Array must contain no more than this number of items
* <li>date: Date must be no later than this value
* <li>number: Numeric value must be <= this value
* <li>string: String length must be <= this value
* </ul>
*
* <p>Max validations will fail with a default error message unless overridden with "maxFailureMessage".
*/
max?:number;
/**
* Optional custom failure message used in the event of a failed "max" validation.
*
* <p>Use a <code>${value}</code> token to include the attribute's current numeric value,
* (e.g. if value is 1.0 then "${value} is not allowed" becomes "1.0 is not allowed").
*/
maxFailureMessage?:string;
/**
* Minimum length/size of attribute.
*
* <p>The attribute type will determine which type of comparison this constraint results in:
* <ul>
* <li>array: Array must contain at least this number of items
* <li>date: Date must be no earlier than this value
* <li>number: Numeric value must be >= this value
* <li>string: String length must be >= this value
* </ul>
*
* <p>Min validations will fail with a default error message unless overridden with "minFailureMessage".
*/
min?:number;
/**
* Optional custom failure message used in the event of a failed "min" validation.
*
* <p>Use a <code>${value}</code> token to include the attribute's current numeric value,
* (e.g. if value is 1.0 then "${value} is not allowed" becomes "1.0 is not allowed").
*/
minFailureMessage?:string;
/**
* Regular expression pattern that string values must match.
*
* <p>Pattern validations will fail with a default error message unless overridden with "patternFailureMessage".
*/
pattern?:RegExp;
/**
* Optional custom failure message used in the event of a failed "pattern" validation.
*
* <p>Use a <code>${value}</code> token to include the attribute's current string value,
* (e.g. if value is "foobar" then "${value} is not allowed" becomes "foobar is not allowed").
*/
patternFailureMessage?:string;
/**
* This attribute is required.
*
* <p>Required validations will fail with a default error message unless overridden with "requiredFailureMessage".
*/
required?:boolean;
/**
* Optional custom failure message used in the event of a failed "required" validation.
*/
requiredFailureMessage?:string;
/**
* Optional primitive attribute type.
*
* <p>If no value is specified this field will be treated as type "string".
* Additional supported types include: "boolean", "integer", and "float".
*
* <p>Type validations will fail with a default error message unless overridden with "typeFailureMessage".
*/
type?:ValidationType;
/**
* Optional custom failure message used in the event of a failed "type" validation.
*
* <p>Use a <code>${value}</code> token to include the attribute's current string value,
* (e.g. if value is "foobar" then "${value} is not an allowed type" becomes "foobar is not an allowed type").
*/
typeFailureMessage?:string;
/**
* Set of custom validator functions; see {@link ValidatorFunction}.
*/
validators?:Array<ValidatorFunction>;
}
}