forked from typestack/class-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ValidationOptions.ts
57 lines (50 loc) · 1.61 KB
/
ValidationOptions.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
import { ValidationArguments } from '../validation/ValidationArguments';
/**
* Options used to pass to validation decorators.
*/
export interface ValidationOptions {
/**
* Indicates that an object is to be considered object literal record.
*
* For an object-valued property marked as object literal, the object the property holds may neither
* be specifically class-typed nor validated, but all the child values of said object MUST be.
* Effectively, this declares object literal, which will be validated the same way any other
* JavaScript collection does (Array, Map, Set, etc).
* The default is `false`; that is, an object-value must be an instance of a class.
*/
objectLiteral?: boolean;
/**
* Specifies if validated value is an array and each of its items must be validated.
*/
each?: boolean;
/**
* Error message to be used on validation fail.
* Message can be either string or a function that returns a string.
*/
message?: string | ((validationArguments: ValidationArguments) => string);
/**
* Validation groups used for this validation.
*/
groups?: string[];
/**
* Indicates if validation must be performed always, no matter of validation groups used.
*/
always?: boolean;
/*
* A transient set of data passed through to the validation result for response mapping
*/
context?: any;
}
export function isValidationOptions(val: any): val is ValidationOptions {
if (!val) {
return false;
}
return (
'objectLiteral' in val ||
'each' in val ||
'message' in val ||
'groups' in val ||
'always' in val ||
'context' in val
);
}