-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.ts
77 lines (67 loc) · 1.43 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
75
76
77
export interface Headers {
[key: string]: string
}
export interface BaseResponse {
status: number
statusText: string
url: string
headers: Headers
}
export interface SuccessResponse<T = any> extends BaseResponse {
data: T
type: 'success'
}
export interface ErrorResponse<T = any> extends BaseResponse {
data: T
type: 'error'
}
export interface ExceptionResponse {
data: Error
type: 'exception'
}
export type Response<T = any, ET = any> = SuccessResponse<T> | ErrorResponse<ET> | ExceptionResponse
export interface Retry<T = any, ET = any> {
retries: number
delay: number
multiplier?: number
shouldRetry?: (response: Response<T, ET>, retryInfo: { retries: number; delay: number }) => boolean
}
export type Method =
| 'delete'
| 'get'
| 'head'
| 'options'
| 'patch'
| 'post'
| 'put'
| 'DELETE'
| 'GET'
| 'HEAD'
| 'OPTIONS'
| 'PATCH'
| 'POST'
| 'PUT'
export interface Options<T = any, ET = any> {
method?: Method
body?: any
params?: {}
headers?: Headers
retry?: Retry<T, ET>
stringify?: (obj?: {}) => string
jsonOut?: boolean
timeout?: number
[others: string]: any
}
export interface RequestFn {
<T = any, ET = any>(url: string, options?: Options<T, ET>): Promise<Response<T, ET>>
}
export interface RequestMod extends RequestFn {
delete: RequestFn
del: RequestFn
get: RequestFn
head: RequestFn
options: RequestFn
patch: RequestFn
post: RequestFn
put: RequestFn
}