-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.d.ts
217 lines (204 loc) · 6.12 KB
/
index.d.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/// <reference types="validator" />
declare module 'property-validator' {
import validator from 'validator'
//middleware
export function assertMiddleware(
err: Error,
req: {},
res: {},
next: Function
): void
//result of a validation/assertion
export type ValidateResult = {
valid: boolean
errors: Array<{
field: string
message: string
}>
messages: string[]
}
//error type
export class ValidationError extends Error {
name: 'ValidationError'
message: string
messages: string[]
stack: string
errors: Array<{
field: string
message: string
}>
}
//type of a validation function, typically a wrapper around Validator.js
export type Validator = (subject: {}) => ValidatorResult
//result of a validation function
export type ValidatorResult = {
field: string
message: string
result: boolean
}
//function to change the locals, keeps a fallback to en locals
export function setLocals(locals: {}): void
//request validators
export function validate(
subject: {},
validations: Validator[]
): ValidateResult
export function validateParams(
request: { params: {} },
validations: Validator[]
): ValidateResult
export function validateQuery(
request: { query: {} },
validations: Validator[]
): ValidateResult
export function validateBody(
request: { body: {} },
validations: Validator[]
): ValidateResult
export function validateHeaders(
request: { headers: {} },
validations: Validator[]
): ValidateResult
export function validateAll(
request: { query?: {}; params?: {}; body?: {} },
validations: Validator[]
): ValidateResult
//request assertions
export function assert(subject: {}, validations: Validator[]): ValidateResult
export function assertHeaders(
request: { headers: {} },
validations: Validator[]
): ValidateResult
export function assertParams(
request: { params: {} },
validations: Validator[]
): ValidateResult
export function assertBody(
request: { body: {} },
validations: Validator[]
): ValidateResult
export function assertQuery(
request: { query: {} },
validations: Validator[]
): ValidateResult
export function assertAll(
request: { query?: {}; params?: {}; body?: {} },
validations: Validator[]
): ValidateResult
//special assert which makes a prop optional
export function optional(
validation: Validator,
customMessage?: string
): Validator
//validation functions
export function presence(paramName: string, customMessage?: string): Validator
export function contains(
paramName: string,
str: string,
customMessage?: string
): Validator
export function isAlpha(paramName: string, customMessage?: string): Validator
export function isAlphanumeric(
paramName: string,
customMessage?: string
): Validator
export function isArray(paramName: string, customMessage?: string): Validator
export function isCreditCard(
paramName: string,
customMessage?: string
): Validator
export function isCurrency(
paramName: string,
options: IsCurrencyOptions,
customMessage?: string
): Validator
export function isDate(paramName: string, customMessage?: string): Validator
export function isDecimal(
paramName: string,
customMessage?: string
): Validator
export function isInt(
paramName: string,
options: IsIntOptions,
customMessage?: string
): Validator
export function isJSON(paramName: string, customMessage?: string): Validator
export function isNull(paramName: string, customMessage?: string): Validator
export function isNumeric(
paramName: string,
customMessage?: string
): Validator
export function isURL(
paramName: string,
options: IsURLOptions,
customMessage?: string
): Validator
export function isPlainObject(
paramName: string,
customMessage?: string
): Validator
//same named (pair) validation functions
export function email(paramName: string, customMessage?: string): Validator
export function isEmail(paramName: string, customMessage?: string): Validator
export function equals(
paramName: string,
comparison: string,
customMessage?: string
): Validator
export function isEqual(
paramName: string,
comparison: string,
customMessage?: string
): Validator
export function matches(
paramName: string,
pattern: RegExp | string,
customMessage?: string
): Validator
export function format(
paramName: string,
pattern: RegExp | string,
customMessage?: string
): Validator
export function uuid(
paramName: string,
version?: string,
customMessage?: string
): Validator
export function isUUID(
paramName: string,
version?: string,
customMessage?: string
): Validator
export function isIn(
paramName: string,
values: any[],
customMessage?: string
): Validator
export function oneOf(
paramName: string,
values: any[],
customMessage?: string
): Validator
export function isLength(
paramName: string,
options: IsLengthOptions,
customMessage?: string
): Validator
export function length(
paramName: string,
options: IsLengthOptions,
customMessage?: string
): Validator
//export validator options interfaces
export interface IsByteLengthOptions extends validator.IsByteLengthOptions {}
export interface IsCurrencyOptions extends validator.IsCurrencyOptions {}
export interface IsEmailOptions extends validator.IsEmailOptions {}
export interface IsFQDNOptions extends validator.IsFQDNOptions {}
export interface IsFloatOptions extends validator.IsFloatOptions {}
export interface IsIntOptions extends validator.IsIntOptions {}
export interface IsLengthOptions extends validator.IsLengthOptions {}
export interface IsURLOptions extends validator.IsURLOptions {}
export interface NormalizeEmailOptions
extends validator.NormalizeEmailOptions {}
}