vigor-fetch 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/index.d.ts +237 -196
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +275 -272
- package/dist/index.mjs +275 -272
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ npm install vigor-fetch
|
|
|
37
37
|
| Auto response parsing | ✅ | ❌ | ✅ | ✅ |
|
|
38
38
|
| Fluent chaining API | ✅ | ❌ | ✅ | ❌ |
|
|
39
39
|
| Concurrency control | ✅ | ❌ | ❌ | ❌ |
|
|
40
|
-
| Lifecycle interceptors | ✅ | ❌ | partial |
|
|
40
|
+
| Lifecycle interceptors | ✅ | ❌ | partial | ✅ |
|
|
41
41
|
| Plugin system | ✅ | ❌ | ❌ | ❌ |
|
|
42
42
|
|
|
43
43
|
## Quick Start
|
|
@@ -195,6 +195,7 @@ vigor.all(tasks: VigorAllTask<T>[])
|
|
|
195
195
|
|------|------|-------------|
|
|
196
196
|
| concurrency | number | Max parallel tasks |
|
|
197
197
|
| jitter | number | Delay randomness |
|
|
198
|
+
| onlySuccess | boolean | Filters Success |
|
|
198
199
|
|
|
199
200
|
|
|
200
201
|
---
|
package/dist/index.d.ts
CHANGED
|
@@ -1,134 +1,166 @@
|
|
|
1
|
-
declare
|
|
1
|
+
declare const VIGOR_ERROR_MESSAGES: {
|
|
2
|
+
readonly TIMEOUT: ({ limit, attempt }: {
|
|
3
|
+
limit: number;
|
|
4
|
+
attempt: number;
|
|
5
|
+
}) => string;
|
|
6
|
+
readonly EXHAUSTED: ({ maxAttempts }: {
|
|
7
|
+
maxAttempts: number;
|
|
8
|
+
}) => string;
|
|
9
|
+
readonly INVALID_URL: ({ received }: {
|
|
10
|
+
received: unknown;
|
|
11
|
+
}) => string;
|
|
12
|
+
readonly INVALID_PROTOCOL: ({ expected, received }: {
|
|
13
|
+
expected: Array<string>;
|
|
14
|
+
received: unknown;
|
|
15
|
+
}) => string;
|
|
16
|
+
readonly FETCH_ERROR: ({ status, statusText, url }: {
|
|
17
|
+
status: number;
|
|
18
|
+
statusText: string;
|
|
19
|
+
url: string;
|
|
20
|
+
}) => string;
|
|
21
|
+
readonly PARSE_FAILED: ({ expected }: {
|
|
22
|
+
expected: unknown;
|
|
23
|
+
}) => string;
|
|
24
|
+
readonly INVALID_TYPE: ({ expected, received }: {
|
|
25
|
+
expected: unknown;
|
|
26
|
+
received: unknown;
|
|
27
|
+
}) => string;
|
|
28
|
+
readonly TARGET_MISSING: () => string;
|
|
29
|
+
readonly REQUEST_FAILED: ({ index, error }: {
|
|
30
|
+
index: number;
|
|
31
|
+
error: Error;
|
|
32
|
+
}) => string;
|
|
33
|
+
readonly UNKNOWN: () => string;
|
|
34
|
+
};
|
|
35
|
+
type VigorErrorCode = keyof typeof VIGOR_ERROR_MESSAGES;
|
|
36
|
+
type ErrorData<C extends VigorErrorCode> = Parameters<typeof VIGOR_ERROR_MESSAGES[C]> extends [infer A] ? A : undefined;
|
|
37
|
+
type VigorErrorOptions<C extends VigorErrorCode> = {
|
|
38
|
+
method?: string;
|
|
39
|
+
cause?: unknown;
|
|
40
|
+
context?: unknown;
|
|
41
|
+
type?: string;
|
|
42
|
+
data: ErrorData<C>;
|
|
43
|
+
};
|
|
44
|
+
declare abstract class VigorError<C extends VigorErrorCode> extends Error {
|
|
2
45
|
readonly timestamp: Date;
|
|
3
46
|
readonly method?: string;
|
|
47
|
+
readonly code: C;
|
|
4
48
|
readonly cause?: unknown;
|
|
5
49
|
readonly context?: unknown;
|
|
6
50
|
readonly type?: string;
|
|
7
|
-
readonly data
|
|
8
|
-
constructor(
|
|
9
|
-
method?: string;
|
|
10
|
-
cause?: unknown;
|
|
11
|
-
context?: unknown;
|
|
12
|
-
type?: string;
|
|
13
|
-
data?: unknown;
|
|
14
|
-
});
|
|
51
|
+
readonly data: ErrorData<C>;
|
|
52
|
+
constructor(code: C, options: VigorErrorOptions<C>);
|
|
15
53
|
}
|
|
16
|
-
declare class VigorRetryError extends VigorError {
|
|
17
|
-
constructor(
|
|
54
|
+
declare class VigorRetryError<C extends "TIMEOUT" | "EXHAUSTED"> extends VigorError<C> {
|
|
55
|
+
constructor(code: C, options: VigorErrorOptions<C>);
|
|
18
56
|
}
|
|
19
|
-
declare class VigorParseError extends VigorError {
|
|
20
|
-
constructor(
|
|
57
|
+
declare class VigorParseError<C extends "PARSE_FAILED" | "INVALID_TYPE" | "TARGET_MISSING"> extends VigorError<C> {
|
|
58
|
+
constructor(code: C, options: VigorErrorOptions<C>);
|
|
21
59
|
}
|
|
22
|
-
declare class VigorFetchError extends VigorError {
|
|
23
|
-
constructor(
|
|
60
|
+
declare class VigorFetchError<C extends "FETCH_ERROR" | "INVALID_URL" | "INVALID_PROTOCOL"> extends VigorError<C> {
|
|
61
|
+
constructor(code: C, options: VigorErrorOptions<C>);
|
|
24
62
|
}
|
|
25
|
-
declare class VigorAllError extends VigorError {
|
|
26
|
-
constructor(
|
|
63
|
+
declare class VigorAllError<C extends "REQUEST_FAILED" | "TARGET_MISSING"> extends VigorError<C> {
|
|
64
|
+
constructor(code: C, options: VigorErrorOptions<C>);
|
|
27
65
|
}
|
|
28
|
-
declare
|
|
66
|
+
declare const EMPTY: unique symbol;
|
|
67
|
+
declare abstract class VigorStatus<T> {
|
|
68
|
+
protected readonly _base: T;
|
|
29
69
|
protected readonly _config: T;
|
|
30
|
-
|
|
31
|
-
private readonly _errorCtor?;
|
|
32
|
-
constructor(_config: T, _ctor: (config: T) => Self, _errorCtor?: (() => new (message: string, data: any) => Error) | undefined);
|
|
33
|
-
protected _create(config: T): Self;
|
|
34
|
-
protected _next(config: Partial<T>): Self;
|
|
70
|
+
constructor(config: Partial<T>, _base: T);
|
|
35
71
|
getConfig(): T;
|
|
36
|
-
|
|
72
|
+
getBase(): T;
|
|
73
|
+
protected _next(config: Partial<T>): this;
|
|
74
|
+
protected _pipsub<C, R extends VigorStatus<C>>(config: C, fn: (r: R) => R, ctor: new (c: C) => R): C;
|
|
37
75
|
}
|
|
76
|
+
type VigorIncludeSpread<T> = Array<(T | Array<T>)>;
|
|
38
77
|
type VigorRetrySettingsConfig<T> = {
|
|
39
78
|
count: number;
|
|
40
79
|
limit: number;
|
|
41
80
|
maxDelay: number;
|
|
42
|
-
default?: T;
|
|
81
|
+
default?: T | typeof EMPTY;
|
|
43
82
|
};
|
|
44
|
-
declare class VigorRetrySettings<T> extends VigorStatus<VigorRetrySettingsConfig<T
|
|
45
|
-
private _base;
|
|
83
|
+
declare class VigorRetrySettings<T> extends VigorStatus<VigorRetrySettingsConfig<T>> {
|
|
46
84
|
constructor(config?: Partial<VigorRetrySettingsConfig<T>>);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
default(obj: T): VigorRetrySettings<T>;
|
|
85
|
+
count(num: number): this;
|
|
86
|
+
limit(num: number): this;
|
|
87
|
+
maxDelay(num: number): this;
|
|
88
|
+
default(obj: T): this;
|
|
52
89
|
}
|
|
53
|
-
type VigorRetryBackoffConfig = {
|
|
90
|
+
type VigorRetryBackoffConfig<T> = {
|
|
54
91
|
initialDelay: number;
|
|
55
92
|
baseDelay: number;
|
|
56
93
|
factor: number;
|
|
57
94
|
jitter: number;
|
|
58
95
|
};
|
|
59
|
-
declare class VigorRetryBackoff extends VigorStatus<VigorRetryBackoffConfig
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
jitter(num: number): VigorRetryBackoff;
|
|
96
|
+
declare class VigorRetryBackoff<T> extends VigorStatus<VigorRetryBackoffConfig<T>> {
|
|
97
|
+
constructor(config?: Partial<VigorRetryBackoffConfig<T>>);
|
|
98
|
+
initialDelay(num: number): this;
|
|
99
|
+
baseDelay(num: number): this;
|
|
100
|
+
factor(num: number): this;
|
|
101
|
+
jitter(num: number): this;
|
|
102
|
+
static randomJitter(num: number): number;
|
|
67
103
|
}
|
|
68
104
|
type VigorRetryBefore<T> = {
|
|
69
|
-
setAttempt
|
|
70
|
-
throwError
|
|
71
|
-
abort
|
|
105
|
+
setAttempt: (attempt: number) => number;
|
|
106
|
+
throwError: (error: Error) => void;
|
|
107
|
+
abort: (error: Error) => void;
|
|
72
108
|
};
|
|
73
109
|
type VigorRetryAfter<T> = {
|
|
74
|
-
setAttempt
|
|
75
|
-
throwError
|
|
76
|
-
setResult
|
|
110
|
+
setAttempt: (attempt: number) => number;
|
|
111
|
+
throwError: (error: Error) => void;
|
|
112
|
+
setResult: (result: T) => T;
|
|
77
113
|
};
|
|
78
114
|
type VigorRetryRetryIf<T> = {
|
|
79
|
-
throwError
|
|
80
|
-
proceedRetry
|
|
81
|
-
cancelRetry
|
|
115
|
+
throwError: (error: Error) => void;
|
|
116
|
+
proceedRetry: () => boolean;
|
|
117
|
+
cancelRetry: (error?: Error) => boolean;
|
|
82
118
|
};
|
|
83
119
|
type VigorRetryOnRetry<T> = {
|
|
84
|
-
setAttempt
|
|
85
|
-
throwError
|
|
86
|
-
setDelay
|
|
120
|
+
setAttempt: (attempt: number) => number;
|
|
121
|
+
throwError: (error: Error) => void;
|
|
122
|
+
setDelay: (delay: number) => number;
|
|
87
123
|
};
|
|
88
124
|
type VigorRetryOnError<T> = {
|
|
89
|
-
setResult
|
|
90
|
-
throwError
|
|
125
|
+
setResult: (result: T) => T;
|
|
126
|
+
throwError: (error: Error) => void;
|
|
91
127
|
};
|
|
92
|
-
type
|
|
93
|
-
type
|
|
94
|
-
type
|
|
95
|
-
type
|
|
96
|
-
type
|
|
128
|
+
type VigorRetryFn<T, O> = (ctx: VigorRetryContext<T>, obj: O) => void | any | Promise<void | any>;
|
|
129
|
+
type VigorRetryBeforeFn<T> = VigorRetryFn<T, VigorRetryBefore<T>>;
|
|
130
|
+
type VigorRetryAfterFn<T> = VigorRetryFn<T, VigorRetryAfter<T>>;
|
|
131
|
+
type VigorRetryOnErrorFn<T> = VigorRetryFn<T, VigorRetryOnError<T>>;
|
|
132
|
+
type VigorRetryOnRetryFn<T> = VigorRetryFn<T, VigorRetryOnRetry<T>>;
|
|
133
|
+
type VigorRetryRetryIfFn<T> = VigorRetryFn<T, VigorRetryRetryIf<T>>;
|
|
97
134
|
type VigorRetryOptionsTask<T> = {
|
|
98
135
|
abort?: (error: Error) => void;
|
|
99
136
|
signal?: AbortSignal;
|
|
100
137
|
};
|
|
101
|
-
type VigorRetryTask<T> = (ctx: VigorRetryContext<T>, obj: VigorRetryOptionsTask<T>) => T | Promise<T>;
|
|
102
138
|
type VigorRetryInterceptorsConfig<T> = {
|
|
103
|
-
before: VigorRetryBeforeFn<T
|
|
104
|
-
after: VigorRetryAfterFn<T
|
|
105
|
-
onError: VigorRetryOnErrorFn<T
|
|
106
|
-
onRetry: VigorRetryOnRetryFn<T
|
|
107
|
-
retryIf: VigorRetryRetryIfFn<T
|
|
108
|
-
};
|
|
109
|
-
declare class VigorRetryInterceptors<T> extends VigorStatus<VigorRetryInterceptorsConfig<T
|
|
110
|
-
private readonly _base;
|
|
139
|
+
before: Array<VigorRetryBeforeFn<T>>;
|
|
140
|
+
after: Array<VigorRetryAfterFn<T>>;
|
|
141
|
+
onError: Array<VigorRetryOnErrorFn<T>>;
|
|
142
|
+
onRetry: Array<VigorRetryOnRetryFn<T>>;
|
|
143
|
+
retryIf: Array<VigorRetryRetryIfFn<T>>;
|
|
144
|
+
};
|
|
145
|
+
declare class VigorRetryInterceptors<T> extends VigorStatus<VigorRetryInterceptorsConfig<T>> {
|
|
111
146
|
constructor(config?: Partial<VigorRetryInterceptorsConfig<T>>);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
retryIf(...funcs: (VigorRetryRetryIfFn<T> | VigorRetryRetryIfFn<T>[])[]): VigorRetryInterceptors<T>;
|
|
147
|
+
before(...funcs: VigorIncludeSpread<VigorRetryBeforeFn<T>>): this;
|
|
148
|
+
after(...funcs: VigorIncludeSpread<VigorRetryAfterFn<T>>): this;
|
|
149
|
+
onError(...funcs: VigorIncludeSpread<VigorRetryOnErrorFn<T>>): this;
|
|
150
|
+
onRetry(...funcs: VigorIncludeSpread<VigorRetryOnRetryFn<T>>): this;
|
|
151
|
+
retryIf(...funcs: VigorIncludeSpread<VigorRetryRetryIfFn<T>>): this;
|
|
118
152
|
}
|
|
153
|
+
type VigorRetryTask<T> = (ctx: VigorRetryContext<T>, obj: VigorRetryOptionsTask<T>) => T | Promise<T>;
|
|
119
154
|
type VigorRetryConfig<T> = {
|
|
120
155
|
target: VigorRetryTask<T>;
|
|
121
156
|
setting: VigorRetrySettingsConfig<T>;
|
|
122
|
-
backoff: VigorRetryBackoffConfig
|
|
157
|
+
backoff: VigorRetryBackoffConfig<T>;
|
|
123
158
|
interceptors: VigorRetryInterceptorsConfig<T>;
|
|
159
|
+
controller: AbortController;
|
|
124
160
|
};
|
|
125
|
-
type VigorRetryContext<T> = {
|
|
126
|
-
target: VigorRetryTask<T>;
|
|
127
|
-
setting: VigorRetrySettingsConfig<T>;
|
|
128
|
-
backoff: VigorRetryBackoffConfig;
|
|
129
|
-
interceptors: VigorRetryInterceptorsConfig<T>;
|
|
161
|
+
type VigorRetryContext<T> = VigorRetryConfig<T> & {
|
|
130
162
|
runtime: {
|
|
131
|
-
result?: T;
|
|
163
|
+
result?: T | typeof EMPTY;
|
|
132
164
|
attempt: number;
|
|
133
165
|
controller: AbortController;
|
|
134
166
|
abortPromise?: Promise<never>;
|
|
@@ -139,32 +171,38 @@ type VigorRetryContext<T> = {
|
|
|
139
171
|
error?: unknown;
|
|
140
172
|
};
|
|
141
173
|
};
|
|
142
|
-
declare class VigorRetry<T> extends VigorStatus<VigorRetryConfig<T
|
|
143
|
-
|
|
144
|
-
private
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
target<U>(func:
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
interceptors(func: (r: VigorRetryInterceptors<T>) => VigorRetryInterceptors<T>): VigorRetry<T>;
|
|
174
|
+
declare class VigorRetry<T> extends VigorStatus<VigorRetryConfig<T>> {
|
|
175
|
+
constructor(config?: Partial<VigorRetryConfig<T>>);
|
|
176
|
+
private _transfer;
|
|
177
|
+
private _calculateDelay;
|
|
178
|
+
createController(): VigorRetryConfig<T>["controller"];
|
|
179
|
+
target<U>(func: VigorRetryConfig<U>["target"]): VigorRetry<U>;
|
|
180
|
+
setting(func: (r: VigorRetrySettings<T>) => VigorRetrySettings<T>): this;
|
|
181
|
+
backoff(func: (r: VigorRetryBackoff<T>) => VigorRetryBackoff<T>): this;
|
|
182
|
+
interceptors(func: (r: VigorRetryInterceptors<T>) => VigorRetryInterceptors<T>): this;
|
|
152
183
|
request(): Promise<T>;
|
|
153
184
|
}
|
|
154
|
-
type VigorParseConfig<T> = {
|
|
185
|
+
type VigorParseConfig<T, O = false> = {
|
|
155
186
|
target?: Response;
|
|
156
|
-
original:
|
|
157
|
-
type?: keyof Response;
|
|
187
|
+
original: O;
|
|
188
|
+
type?: (keyof Response) | undefined;
|
|
158
189
|
result?: T;
|
|
159
190
|
};
|
|
160
|
-
declare class VigorParse<T extends
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
191
|
+
declare class VigorParse<T, O extends boolean = false> extends VigorStatus<VigorParseConfig<T, O>> {
|
|
192
|
+
constructor(config?: Partial<VigorParseConfig<T, O> & {
|
|
193
|
+
original: O;
|
|
194
|
+
}>);
|
|
195
|
+
static stategy: {
|
|
196
|
+
key: RegExp;
|
|
197
|
+
parse: (res: Response) => Promise<any>;
|
|
198
|
+
type: string;
|
|
199
|
+
}[];
|
|
200
|
+
static supported: string[];
|
|
201
|
+
private _transfer;
|
|
202
|
+
target(res: Response): this;
|
|
203
|
+
original<B extends boolean>(bool: B): VigorParse<T, B>;
|
|
204
|
+
type<K extends keyof Response>(type: K): VigorParse<Response[K] extends (...args: any) => Promise<infer R> ? R : never, O>;
|
|
205
|
+
request<U = T>(): Promise<O extends true ? Response : U>;
|
|
168
206
|
}
|
|
169
207
|
type VigorFetchMethods = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS" | "CONNECT" | "TRACE";
|
|
170
208
|
type VigorFetchSettingsConfig<T> = {
|
|
@@ -177,12 +215,10 @@ type VigorFetchSettingsConfig<T> = {
|
|
|
177
215
|
headers?: HeadersInit | Record<string, any>;
|
|
178
216
|
body?: XMLHttpRequestBodyInit | object | null;
|
|
179
217
|
options?: object;
|
|
180
|
-
default?: T;
|
|
218
|
+
default?: T | typeof EMPTY;
|
|
181
219
|
};
|
|
182
|
-
declare class VigorFetchSettings<T> extends VigorStatus<VigorFetchSettingsConfig<T
|
|
183
|
-
private _base;
|
|
220
|
+
declare class VigorFetchSettings<T> extends VigorStatus<VigorFetchSettingsConfig<T>> {
|
|
184
221
|
constructor(config?: Partial<VigorFetchSettingsConfig<T>>);
|
|
185
|
-
getBase(): VigorFetchSettingsConfig<T>;
|
|
186
222
|
origin(str: string): VigorFetchSettings<T>;
|
|
187
223
|
path(...strs: (string | string[])[]): VigorFetchSettings<T>;
|
|
188
224
|
query(obj: object): VigorFetchSettings<T>;
|
|
@@ -209,24 +245,23 @@ type VigorFetchResult<T> = {
|
|
|
209
245
|
setResult?: (result: T) => T;
|
|
210
246
|
throwError?: (error: Error) => void;
|
|
211
247
|
};
|
|
212
|
-
type
|
|
213
|
-
type
|
|
214
|
-
type
|
|
215
|
-
type
|
|
248
|
+
type VigorFetchFn<T, O> = (ctx: VigorFetchContext<T>, obj: O) => void | any | Promise<void | any>;
|
|
249
|
+
type VigorFetchBeforeFn<T> = VigorFetchFn<T, VigorFetchBefore<T>>;
|
|
250
|
+
type VigorFetchAfterFn<T> = VigorFetchFn<T, VigorFetchAfter<T>>;
|
|
251
|
+
type VigorFetchOnErrorFn<T> = VigorFetchFn<T, VigorFetchOnError<T>>;
|
|
252
|
+
type VigorFetchResultFn<T> = VigorFetchFn<T, VigorFetchResult<T>>;
|
|
216
253
|
type VigorFetchInterceptorsConfig<T> = {
|
|
217
254
|
before: VigorFetchBeforeFn<T>[];
|
|
218
255
|
after: VigorFetchAfterFn<T>[];
|
|
219
256
|
onError: VigorFetchOnErrorFn<T>[];
|
|
220
257
|
result: VigorFetchResultFn<T>[];
|
|
221
258
|
};
|
|
222
|
-
declare class VigorFetchInterceptors<T> extends VigorStatus<VigorFetchInterceptorsConfig<T
|
|
223
|
-
private readonly _base;
|
|
259
|
+
declare class VigorFetchInterceptors<T> extends VigorStatus<VigorFetchInterceptorsConfig<T>> {
|
|
224
260
|
constructor(config?: Partial<VigorFetchInterceptorsConfig<T>>);
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
result(...funcs: (VigorFetchResultFn<T> | VigorFetchResultFn<T>[])[]): VigorFetchInterceptors<T>;
|
|
261
|
+
before(...funcs: VigorIncludeSpread<VigorFetchBeforeFn<T>>): VigorFetchInterceptors<T>;
|
|
262
|
+
after(...funcs: VigorIncludeSpread<VigorFetchAfterFn<T>>): VigorFetchInterceptors<T>;
|
|
263
|
+
onError(...funcs: VigorIncludeSpread<VigorFetchOnErrorFn<T>>): VigorFetchInterceptors<T>;
|
|
264
|
+
result(...funcs: VigorIncludeSpread<VigorFetchResultFn<T>>): VigorFetchInterceptors<T>;
|
|
230
265
|
}
|
|
231
266
|
type VigorFetchConfig<T> = {
|
|
232
267
|
setting: VigorFetchSettingsConfig<T>;
|
|
@@ -234,11 +269,7 @@ type VigorFetchConfig<T> = {
|
|
|
234
269
|
parseConfig: VigorParseConfig<T>;
|
|
235
270
|
interceptors: VigorFetchInterceptorsConfig<T>;
|
|
236
271
|
};
|
|
237
|
-
type VigorFetchContext<T> = {
|
|
238
|
-
setting: VigorFetchSettingsConfig<T>;
|
|
239
|
-
retryConfig: VigorRetryConfig<T>;
|
|
240
|
-
parseConfig: VigorParseConfig<T>;
|
|
241
|
-
interceptors: VigorFetchInterceptorsConfig<T>;
|
|
272
|
+
type VigorFetchContext<T> = VigorFetchConfig<T> & {
|
|
242
273
|
runtime: {
|
|
243
274
|
retryEngine?: VigorRetry<T>;
|
|
244
275
|
parseEngine?: VigorParse<T>;
|
|
@@ -247,100 +278,110 @@ type VigorFetchContext<T> = {
|
|
|
247
278
|
baseOptions?: object;
|
|
248
279
|
options?: object;
|
|
249
280
|
response?: Response;
|
|
250
|
-
result?: T;
|
|
281
|
+
result?: T | typeof EMPTY;
|
|
251
282
|
error?: unknown;
|
|
252
283
|
};
|
|
253
284
|
};
|
|
254
|
-
declare class VigorFetch<T
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
interceptors(func: (r: VigorFetchInterceptors<T>) => VigorFetchInterceptors<T>): VigorFetch<T>;
|
|
270
|
-
request(): Promise<T>;
|
|
285
|
+
declare class VigorFetch<T> extends VigorStatus<VigorFetchConfig<T>> {
|
|
286
|
+
constructor(config?: Partial<VigorFetchConfig<T>>);
|
|
287
|
+
origin(str: string): this;
|
|
288
|
+
path(...strs: (string | string[])[]): this;
|
|
289
|
+
query(obj: object): this;
|
|
290
|
+
method(str: VigorFetchMethods): this;
|
|
291
|
+
headers(obj: HeadersInit | Record<string, any>): this;
|
|
292
|
+
body(obj: XMLHttpRequestBodyInit | object | null): this;
|
|
293
|
+
options(obj: object): this;
|
|
294
|
+
setting(func: (r: VigorFetchSettings<T>) => VigorFetchSettings<T>): this;
|
|
295
|
+
interceptors(func: (r: VigorFetchInterceptors<T>) => VigorFetchInterceptors<T>): this;
|
|
296
|
+
retryConfig(func: (r: VigorRetry<T>) => VigorRetry<T>): this;
|
|
297
|
+
parseConfig(func: (r: VigorParse<T>) => VigorParse<T>): this;
|
|
298
|
+
buildUrl(origin: string, path: string[], query: object): string;
|
|
299
|
+
request<U = T>(): Promise<U>;
|
|
271
300
|
}
|
|
272
|
-
type VigorAllSettingsConfig
|
|
301
|
+
type VigorAllSettingsConfig = {
|
|
273
302
|
concurrency: number;
|
|
274
303
|
jitter: number;
|
|
304
|
+
onlySuccess: boolean;
|
|
275
305
|
};
|
|
276
|
-
declare class VigorAllSettings
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
jitter(num: number): VigorAllSettings<T>;
|
|
306
|
+
declare class VigorAllSettings extends VigorStatus<VigorAllSettingsConfig> {
|
|
307
|
+
constructor(config?: Partial<VigorAllSettingsConfig>);
|
|
308
|
+
concurrency(num: number): VigorAllSettings;
|
|
309
|
+
jitter(num: number): VigorAllSettings;
|
|
310
|
+
onlySuccess(bool: boolean): VigorAllSettings;
|
|
282
311
|
}
|
|
283
|
-
type VigorAllBefore
|
|
312
|
+
type VigorAllBefore = {
|
|
284
313
|
throwError?: (error: Error) => void;
|
|
285
314
|
};
|
|
286
|
-
type VigorAllAfter
|
|
287
|
-
setResult?: (result:
|
|
315
|
+
type VigorAllAfter = {
|
|
316
|
+
setResult?: (result: any) => any;
|
|
288
317
|
throwError?: (error: Error) => void;
|
|
289
318
|
};
|
|
290
|
-
type VigorAllOnError
|
|
291
|
-
setResult?: (result:
|
|
319
|
+
type VigorAllOnError = {
|
|
320
|
+
setResult?: (result: any) => any;
|
|
292
321
|
throwError?: (error: Error) => void;
|
|
293
322
|
};
|
|
294
|
-
type VigorAllResult
|
|
295
|
-
setResult?: (result: Array<
|
|
323
|
+
type VigorAllResult = {
|
|
324
|
+
setResult?: (result: Array<any>) => Array<any>;
|
|
296
325
|
throwError?: (error: Error) => void;
|
|
297
326
|
};
|
|
298
|
-
type
|
|
299
|
-
type
|
|
300
|
-
type
|
|
301
|
-
type
|
|
302
|
-
type
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
before(...funcs: (VigorAllBeforeFn
|
|
313
|
-
after(...funcs: (VigorAllAfterFn
|
|
314
|
-
onError(...funcs: (VigorAllOnErrorFn
|
|
315
|
-
result(...funcs: (VigorAllResultFn
|
|
327
|
+
type VigorAllFn<O> = (ctx: VigorAllContext<any>, obj: O) => void | any | Promise<void | any>;
|
|
328
|
+
type VigorAllTaskFn<O> = (ctx: VigorAllTaskContext<any>, obj: O) => void | any | Promise<void | any>;
|
|
329
|
+
type VigorAllBeforeFn = VigorAllTaskFn<VigorAllBefore>;
|
|
330
|
+
type VigorAllAfterFn = VigorAllTaskFn<VigorAllAfter>;
|
|
331
|
+
type VigorAllOnErrorFn = VigorAllTaskFn<VigorAllOnError>;
|
|
332
|
+
type VigorAllResultFn = VigorAllFn<VigorAllResult>;
|
|
333
|
+
type VigorAllInterceptorsConfig = {
|
|
334
|
+
before: VigorAllBeforeFn[];
|
|
335
|
+
after: VigorAllAfterFn[];
|
|
336
|
+
onError: VigorAllOnErrorFn[];
|
|
337
|
+
result: VigorAllResultFn[];
|
|
338
|
+
};
|
|
339
|
+
declare class VigorAllInterceptors extends VigorStatus<VigorAllInterceptorsConfig> {
|
|
340
|
+
constructor(config?: Partial<VigorAllInterceptorsConfig>);
|
|
341
|
+
before(...funcs: (VigorAllBeforeFn | VigorAllBeforeFn[])[]): VigorAllInterceptors;
|
|
342
|
+
after(...funcs: (VigorAllAfterFn | VigorAllAfterFn[])[]): VigorAllInterceptors;
|
|
343
|
+
onError(...funcs: (VigorAllOnErrorFn | VigorAllOnErrorFn[])[]): VigorAllInterceptors;
|
|
344
|
+
result(...funcs: (VigorAllResultFn | VigorAllResultFn[])[]): VigorAllInterceptors;
|
|
316
345
|
}
|
|
317
|
-
type VigorAllOptionsTask
|
|
346
|
+
type VigorAllOptionsTask = {
|
|
318
347
|
abort?: (error: Error) => void;
|
|
319
348
|
signal?: AbortSignal;
|
|
320
349
|
};
|
|
321
|
-
type VigorAllTask<
|
|
322
|
-
type
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
350
|
+
type VigorAllTask<R = any> = (ctx: VigorAllTaskContext<any>, obj: VigorAllOptionsTask) => R | Promise<R>;
|
|
351
|
+
type TaskReturn<T> = T extends VigorAllTask<infer R> ? R : never;
|
|
352
|
+
type MapTasks<T extends readonly VigorAllTask<any>[]> = {
|
|
353
|
+
[K in keyof T]: T[K] extends VigorAllTask<infer R> ? R : never;
|
|
354
|
+
};
|
|
355
|
+
type VigorAllConfig<Tasks extends readonly VigorAllTask<any>[]> = {
|
|
356
|
+
target: Tasks;
|
|
357
|
+
setting: VigorAllSettingsConfig;
|
|
358
|
+
interceptors: VigorAllInterceptorsConfig;
|
|
359
|
+
};
|
|
360
|
+
type VigorAllContext<Tasks extends readonly VigorAllTask<any>[]> = VigorAllConfig<Tasks> & {
|
|
361
|
+
runtime: {
|
|
362
|
+
tasks: {
|
|
363
|
+
[K in keyof Tasks]: Promise<TaskReturn<Tasks[K]>>;
|
|
364
|
+
};
|
|
365
|
+
result: {
|
|
366
|
+
[K in keyof Tasks]: TaskReturn<Tasks[K]> | Error;
|
|
367
|
+
};
|
|
368
|
+
};
|
|
326
369
|
};
|
|
327
|
-
type
|
|
328
|
-
target
|
|
329
|
-
setting: VigorAllSettingsConfig<T>;
|
|
330
|
-
interceptors: VigorAllInterceptorsConfig<T>;
|
|
370
|
+
type VigorAllTaskContext<Task extends VigorAllTask<any>> = {
|
|
371
|
+
target: Task;
|
|
331
372
|
runtime: {
|
|
332
|
-
|
|
333
|
-
|
|
373
|
+
result: TaskReturn<Task> | typeof EMPTY;
|
|
374
|
+
error: unknown;
|
|
375
|
+
jitter: number;
|
|
334
376
|
};
|
|
335
377
|
};
|
|
336
|
-
declare class VigorAll<
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
request(): Promise<(T | Error)[]>;
|
|
378
|
+
declare class VigorAll<Tasks extends readonly VigorAllTask<any>[]> extends VigorStatus<VigorAllConfig<Tasks>> {
|
|
379
|
+
constructor(config?: Partial<VigorAllConfig<Tasks>>);
|
|
380
|
+
private _transfer;
|
|
381
|
+
target<T extends readonly VigorAllTask<any>[]>(...funcs: T): VigorAll<T>;
|
|
382
|
+
setting(func: (r: VigorAllSettings) => VigorAllSettings): this;
|
|
383
|
+
interceptors(func: (r: VigorAllInterceptors) => VigorAllInterceptors): this;
|
|
384
|
+
request(): Promise<MapTasks<Tasks>>;
|
|
344
385
|
}
|
|
345
386
|
type VigorRegistry = {
|
|
346
387
|
VigorRetry: {
|
|
@@ -357,7 +398,7 @@ type VigorRegistry = {
|
|
|
357
398
|
interceptors: typeof VigorFetchInterceptors;
|
|
358
399
|
};
|
|
359
400
|
VigorAll: {
|
|
360
|
-
main:
|
|
401
|
+
main: () => VigorAll<any>;
|
|
361
402
|
error: typeof VigorAllError;
|
|
362
403
|
setting: typeof VigorAllSettings;
|
|
363
404
|
interceptors: typeof VigorAllInterceptors;
|
|
@@ -374,8 +415,8 @@ declare class Vigor {
|
|
|
374
415
|
private readonly registry;
|
|
375
416
|
constructor(config?: Partial<VigorConfig>);
|
|
376
417
|
fetch(origin: string): VigorFetch<unknown>;
|
|
377
|
-
all<T
|
|
378
|
-
parse(response: Response): VigorParse<unknown>;
|
|
418
|
+
all<T extends VigorAllTask<any>[] | readonly VigorAllTask<any>[]>(...args: T extends any ? (T[number] | T)[] : never): VigorAll<VigorAllTask<any>[]>;
|
|
419
|
+
parse(response: Response): VigorParse<unknown, false>;
|
|
379
420
|
retry<T>(fn: VigorRetryTask<T>): VigorRetry<T>;
|
|
380
421
|
use(plugin: (ctx: VigorRegistry, options?: object) => void, options?: object): Vigor;
|
|
381
422
|
}
|