-
Notifications
You must be signed in to change notification settings - Fork 5
/
typings.d.ts
163 lines (153 loc) · 3.74 KB
/
typings.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
/// <reference types="react" />
import * as Axios from 'axios'
export = ReactUseApi
export as namespace ReactUseApi
declare namespace ReactUseApi {
type Settings = typeof import('./common').defaultSettings
type CustomSettings = Partial<Settings>
type ACTIONS = typeof import('./common').ACTIONS
type InitState = typeof import('./common').initState
type SingleConfig = Axios.AxiosRequestConfig
type MultiConfigs = SingleConfig[]
type Config = SingleConfig | MultiConfigs
type ApiResponse = Axios.AxiosResponse<JsonObject>
type SingleData = JsonObject | undefined | any
type Data = SingleData | SingleData[] | undefined | any
type RequestFn = (
cfg?: ReactUseApi.Config,
keepState?: boolean
) => Promise<any>
interface Context {
settings?: Settings
isSSR?: boolean
collection?: SSRCollection
isConfigured?: boolean
renderSSR?: Settings['renderSSR']
clearCache?: () => void
}
interface CustomContext extends Omit<Context, 'settings'> {
settings?: CustomSettings
}
interface SSRCollection {
ssrConfigs: SSRConfigs[]
cacheKeys: Set<string>
}
interface SSRConfigs {
config: Config
cacheKey: string
}
interface ApiProviderProps {
context?: CustomContext
}
interface Options {
watch?: any[]
dependencies?: dependencies
skip?: boolean
useCache?: boolean
$cacheKey?: string
$hasChangedConfig?: boolean
handleData?: (data: Data, newState: State) => any
shouldRequest?: () => boolean | void
}
interface dependencies {
readonly [key: string]: any
}
interface CacheData {
response?: ApiResponse | ApiResponse[]
error?: Axios.AxiosError
}
interface Action extends CacheData {
type: string
options?: Options
fromCache?: boolean
}
interface State extends InitState, CacheData, JsonObject {
data?: Data
prevData?: Data
prevState?: State
dependencies?: Options['dependencies']
}
interface RefData {
id: number
cacheKey: string
state: State
config: Config
refreshFlag: number
isInit: boolean
isRequesting: boolean
hasFed: boolean
timeoutID: number
useCache: boolean
// options: Options // debug only
}
interface DispatchClusterElement {
id: number
dispatch: React.Dispatch<Action>
refData: RefData
}
interface RECORDS {
[cacheKey: string]: {
dispatches: DispatchClusterElement[]
suspense?: {
promise: Promise<DataResponse>
done: boolean
reference: number
}
} & CacheData
}
type MiddlewareInterrupt = () => void
interface Middleware {
onHandleOptions?: (
config?: Config,
args?: { options: Options },
interrupt?: MiddlewareInterrupt
) => Options
onStart?: (
config?: Config,
args?: { state: State },
interrupt?: MiddlewareInterrupt
) => State
onHandleData?: (
config?: Config,
args?: {
data: Data
response: DataResponse
},
interrupt?: MiddlewareInterrupt
) => Data
onHandleError?: (
config?: Config,
args?: { error: ErrorResponse },
interrupt?: MiddlewareInterrupt
) => any
onSuccess?: (
config?: Config,
args?: {
data: Data
response: DataResponse
},
interrupt?: MiddlewareInterrupt
) => void
onError?: (
config?: Config,
args?: {
error: ErrorResponse
response: DataResponse
},
interrupt?: MiddlewareInterrupt
) => void
onDone: (
config?: Config,
args?: {
data: Data
error: ErrorResponse
response: DataResponse
},
interrupt?: MiddlewareInterrupt
) => void
}
type Middlewares = Middleware[]
interface JsonObject {
[key: string]: any
}
}