-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.d.ts
More file actions
65 lines (64 loc) · 1.36 KB
/
types.d.ts
File metadata and controls
65 lines (64 loc) · 1.36 KB
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
declare module 'fetch-extra'
export type Resource = RequestInfo
export type FetchResponse = Response & {
completed: Promise<FetchStats>
}
export type RetryResponse =
| {
resource?: Resource
options?: FetchOptions
}
| boolean
export type RetryDef =
| number
| ((params: RetryFnParams) => Promise<RetryResponse> | RetryResponse)
export declare class FetchState {
id: number | string
resource: Resource
options: FetchOptions
userSignal?: AbortSignal
retry?: RetryDef
attempt: number
completed: Promise<FetchStats>
startTs?: number
bodyTs?: number
size?: number
}
export type FetchStats = {
size: number
duration: number
attempts: number
speed: number
}
export type RetryFnParams = {
state: FetchState
error?: Error
response?: FetchResponse
}
export type ValidateFn = (data: any, state: FetchState) => Promise<void> | void
export type FetchOptions = RequestInit & {
retry?: RetryDef
timeout?: number
timeouts?: {
overall?: number
request?: number
stall?: number
body?: number
}
validate?:
| true
| ValidateFn
| {
response?: boolean | ValidateFn
buffer?: ValidateFn
blob?: ValidateFn
arrayBuffer?: ValidateFn
json?: ValidateFn
text?: ValidateFn
textConverted?: ValidateFn
}
signal?: AbortSignal
// import doesn't work
// limiter?: ReturnType<import('async-sema').RateLimit>
limiter?: () => Promise<void>
}