forked from koajs/joi-router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
74 lines (62 loc) · 1.64 KB
/
types.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
import * as CoBody from 'co-body'
import * as Koa from 'koa'
type FullHandler = (ctx: Koa.Context, next: Koa.Next) => any
// interface NestedHandler extends ReadonlyArray<Handler> {}
export type NestedHandler = ReadonlyArray<Handler>
export type Handler = FullHandler | NestedHandler
export interface OutputValidationObject<Schema> {
[status: string]: OutputValidation<Schema>
}
export type OutputValidation<Schema> = { body?: Schema; headers?: Schema }
export interface IValidateObject<Schema> {
header?: Schema
query?: Schema
params?: Schema
body?: Schema
maxBody?: number
/**
* status code when validation fails
*/
failure?: number
type?: 'form' | 'json' | 'multipart' | 'stream'
formOptions?: CoBody.Options
jsonOptions?: CoBody.Options
multipartOptions?: CoBody.Options
output?: OutputValidationObject<Schema>
continueOnError?: boolean
}
export interface Config<Meta, Schema> {
pre?: Handler
validate?: IValidateObject<Schema>
meta?: Meta
}
export interface Spec<Meta, Schema> extends Config<Meta, Schema> {
method:
| 'get'
| 'put'
| 'post'
| 'patch'
| 'delete'
| 'del'
| 'options'
| 'head'
path: string | RegExp
handler: Handler
validationEnabled?: boolean
}
export type IValidationError = any
export type IValidationWarning = any
export interface IValidationResult {
value?: any
error?: IValidationError
warning?: IValidationWarning
}
export type Validator = (data: any) => Promise<IValidationResult>
export type ValidatorBuilder<Schema> = (schema: Schema) => Promise<Validator>
export interface IRange {
lower: number
upper: number
}
export interface ContextExtension<Meta, Schema> {
spec: Spec<Meta, Schema>
}