vigor-fetch 2.0.0 → 2.0.2
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 +60 -1
- package/dist/index.d.ts +363 -101
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +707 -448
- package/dist/index.mjs +700 -448
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,8 +15,11 @@ Vigor provides a fluent, chainable API for building robust network logic with bu
|
|
|
15
15
|
- ⚡ **Zero Dependencies** — Built on native Fetch + AbortController
|
|
16
16
|
- 🪝 **Powerful Interceptors** — Lifecycle hooks for full control flow
|
|
17
17
|
- 🧠 **TypeScript First** — Fully typed inference across all modules
|
|
18
|
+
|
|
19
|
+
|
|
18
20
|
---
|
|
19
21
|
|
|
22
|
+
|
|
20
23
|
## Installation
|
|
21
24
|
|
|
22
25
|
```bash
|
|
@@ -47,10 +50,12 @@ const data = await vigor
|
|
|
47
50
|
.request()
|
|
48
51
|
```
|
|
49
52
|
|
|
50
|
-
# 🛠️ Vigor API Reference
|
|
53
|
+
# 🛠️ Vigor API Reference
|
|
54
|
+
|
|
51
55
|
|
|
52
56
|
---
|
|
53
57
|
|
|
58
|
+
|
|
54
59
|
# 📡 vigor.fetch(origin)
|
|
55
60
|
|
|
56
61
|
vigor.fetch(origin: string)
|
|
@@ -72,8 +77,10 @@ vigor.fetch(origin: string)
|
|
|
72
77
|
| interceptors | (fn: (i: VigorFetchInterceptors) => VigorFetchInterceptors) => VigorFetch | Lifecycle hooks |
|
|
73
78
|
| request | () => Promise<T> | Execute request |
|
|
74
79
|
|
|
80
|
+
|
|
75
81
|
---
|
|
76
82
|
|
|
83
|
+
|
|
77
84
|
## ⚙️ fetch().setting(s => s)
|
|
78
85
|
|
|
79
86
|
| Field | Type | Description |
|
|
@@ -89,8 +96,10 @@ vigor.fetch(origin: string)
|
|
|
89
96
|
| options | object | Fetch options |
|
|
90
97
|
| default | T | Fallback value |
|
|
91
98
|
|
|
99
|
+
|
|
92
100
|
---
|
|
93
101
|
|
|
102
|
+
|
|
94
103
|
## 🧩 fetch().interceptors(i => i)
|
|
95
104
|
|
|
96
105
|
| Hook | Signature | Description |
|
|
@@ -100,8 +109,10 @@ vigor.fetch(origin: string)
|
|
|
100
109
|
| onError | (ctx, { setResult, throwError }) => void | Error handler |
|
|
101
110
|
| result | (ctx, { setResult, throwError }) => void | Final result hook |
|
|
102
111
|
|
|
112
|
+
|
|
103
113
|
---
|
|
104
114
|
|
|
115
|
+
|
|
105
116
|
# 🔁 vigor.retry(task)
|
|
106
117
|
|
|
107
118
|
vigor.retry(task: VigorRetryTask<T>)
|
|
@@ -117,8 +128,10 @@ vigor.retry(task: VigorRetryTask<T>)
|
|
|
117
128
|
| request | () => Promise<T> | Execute retry flow |
|
|
118
129
|
| createController | () => (error: Error) => void | Abort controller |
|
|
119
130
|
|
|
131
|
+
|
|
120
132
|
---
|
|
121
133
|
|
|
134
|
+
|
|
122
135
|
## ⚙️ retry().setting(s => s)
|
|
123
136
|
|
|
124
137
|
| Field | Type | Description |
|
|
@@ -128,8 +141,10 @@ vigor.retry(task: VigorRetryTask<T>)
|
|
|
128
141
|
| maxDelay | number | Max delay cap |
|
|
129
142
|
| default | T | Fallback value |
|
|
130
143
|
|
|
144
|
+
|
|
131
145
|
---
|
|
132
146
|
|
|
147
|
+
|
|
133
148
|
## 📈 retry().backoff(b => b)
|
|
134
149
|
|
|
135
150
|
| Field | Type | Description |
|
|
@@ -139,8 +154,10 @@ vigor.retry(task: VigorRetryTask<T>)
|
|
|
139
154
|
| factor | number | Exponential multiplier |
|
|
140
155
|
| jitter | number | Random noise |
|
|
141
156
|
|
|
157
|
+
|
|
142
158
|
---
|
|
143
159
|
|
|
160
|
+
|
|
144
161
|
## 🧩 retry().interceptors(i => i)
|
|
145
162
|
|
|
146
163
|
| Hook | Signature | Description |
|
|
@@ -151,8 +168,10 @@ vigor.retry(task: VigorRetryTask<T>)
|
|
|
151
168
|
| onRetry | (ctx, { setDelay }) => void | Retry event |
|
|
152
169
|
| retryIf | (ctx, { proceedRetry, cancelRetry }) => void | Retry decision |
|
|
153
170
|
|
|
171
|
+
|
|
154
172
|
---
|
|
155
173
|
|
|
174
|
+
|
|
156
175
|
# ⚡ vigor.all(tasks)
|
|
157
176
|
|
|
158
177
|
vigor.all(tasks: VigorAllTask<T>[])
|
|
@@ -166,8 +185,10 @@ vigor.all(tasks: VigorAllTask<T>[])
|
|
|
166
185
|
| interceptors | (fn: (i: VigorAllInterceptors) => VigorAllInterceptors) => VigorAll | Hooks |
|
|
167
186
|
| request | () => Promise<Array<T | Error>> | Execute all tasks |
|
|
168
187
|
|
|
188
|
+
|
|
169
189
|
---
|
|
170
190
|
|
|
191
|
+
|
|
171
192
|
## ⚙️ all().setting(s => s)
|
|
172
193
|
|
|
173
194
|
| Field | Type | Description |
|
|
@@ -175,8 +196,10 @@ vigor.all(tasks: VigorAllTask<T>[])
|
|
|
175
196
|
| concurrency | number | Max parallel tasks |
|
|
176
197
|
| jitter | number | Delay randomness |
|
|
177
198
|
|
|
199
|
+
|
|
178
200
|
---
|
|
179
201
|
|
|
202
|
+
|
|
180
203
|
## 🧩 all().interceptors(i => i)
|
|
181
204
|
|
|
182
205
|
| Hook | Signature | Description |
|
|
@@ -186,8 +209,10 @@ vigor.all(tasks: VigorAllTask<T>[])
|
|
|
186
209
|
| onError | (ctx, { setResult }) => void | Error handling |
|
|
187
210
|
| result | (ctx, { setResult }) => void | Final aggregation |
|
|
188
211
|
|
|
212
|
+
|
|
189
213
|
---
|
|
190
214
|
|
|
215
|
+
|
|
191
216
|
# 🧪 vigor.parse(response)
|
|
192
217
|
|
|
193
218
|
vigor.parse(response: Response)
|
|
@@ -199,8 +224,10 @@ vigor.parse(response: Response)
|
|
|
199
224
|
| type | keyof Response | Force parse type |
|
|
200
225
|
| request | () => Promise<T> | Execute parsing |
|
|
201
226
|
|
|
227
|
+
|
|
202
228
|
---
|
|
203
229
|
|
|
230
|
+
|
|
204
231
|
# 🚀 vigor.fetch examples
|
|
205
232
|
|
|
206
233
|
## GET request
|
|
@@ -274,8 +301,11 @@ vigor.retry(async (ctx, { signal }) => {
|
|
|
274
301
|
)
|
|
275
302
|
.request()
|
|
276
303
|
```
|
|
304
|
+
|
|
305
|
+
|
|
277
306
|
---
|
|
278
307
|
|
|
308
|
+
|
|
279
309
|
## retryIf control
|
|
280
310
|
```ts
|
|
281
311
|
vigor.retry(async () => {
|
|
@@ -293,8 +323,11 @@ vigor.retry(async () => {
|
|
|
293
323
|
)
|
|
294
324
|
.request()
|
|
295
325
|
```
|
|
326
|
+
|
|
327
|
+
|
|
296
328
|
---
|
|
297
329
|
|
|
330
|
+
|
|
298
331
|
## abort controller
|
|
299
332
|
```ts
|
|
300
333
|
const retry = vigor.retry(async (ctx, { signal }) => {
|
|
@@ -310,8 +343,11 @@ setTimeout(() => {
|
|
|
310
343
|
|
|
311
344
|
await retry.request()
|
|
312
345
|
```
|
|
346
|
+
|
|
347
|
+
|
|
313
348
|
---
|
|
314
349
|
|
|
350
|
+
|
|
315
351
|
# ⚡ vigor.all examples
|
|
316
352
|
```ts
|
|
317
353
|
vigor.all([
|
|
@@ -320,7 +356,11 @@ vigor.all([
|
|
|
320
356
|
async () => fetch("https://api.com/c").then(r => r.json())
|
|
321
357
|
]).request()
|
|
322
358
|
```
|
|
359
|
+
|
|
360
|
+
|
|
323
361
|
---
|
|
362
|
+
|
|
363
|
+
|
|
324
364
|
```ts
|
|
325
365
|
vigor.all([
|
|
326
366
|
async () => "A",
|
|
@@ -335,7 +375,11 @@ vigor.all([
|
|
|
335
375
|
)
|
|
336
376
|
.request()
|
|
337
377
|
```
|
|
378
|
+
|
|
379
|
+
|
|
338
380
|
---
|
|
381
|
+
|
|
382
|
+
|
|
339
383
|
```ts
|
|
340
384
|
vigor.all([
|
|
341
385
|
async () => "ok1",
|
|
@@ -343,15 +387,21 @@ vigor.all([
|
|
|
343
387
|
async () => "ok2"
|
|
344
388
|
]).request()
|
|
345
389
|
```
|
|
390
|
+
|
|
346
391
|
---
|
|
347
392
|
|
|
393
|
+
|
|
348
394
|
# 🧪 vigor.parse examples
|
|
349
395
|
```ts
|
|
350
396
|
const res = await fetch("https://api.com/data")
|
|
351
397
|
|
|
352
398
|
vigor.parse(res).request()
|
|
353
399
|
```
|
|
400
|
+
|
|
401
|
+
|
|
354
402
|
---
|
|
403
|
+
|
|
404
|
+
|
|
355
405
|
```ts
|
|
356
406
|
const img = await fetch("https://api.com/image.png")
|
|
357
407
|
|
|
@@ -359,7 +409,11 @@ vigor.parse(img)
|
|
|
359
409
|
.type("blob")
|
|
360
410
|
.request()
|
|
361
411
|
```
|
|
412
|
+
|
|
413
|
+
|
|
362
414
|
---
|
|
415
|
+
|
|
416
|
+
|
|
363
417
|
```ts
|
|
364
418
|
const raw = await fetch("https://api.com")
|
|
365
419
|
|
|
@@ -367,8 +421,11 @@ vigor.parse(raw)
|
|
|
367
421
|
.original(true)
|
|
368
422
|
.request()
|
|
369
423
|
```
|
|
424
|
+
|
|
425
|
+
|
|
370
426
|
---
|
|
371
427
|
|
|
428
|
+
|
|
372
429
|
# 🔥 full pipeline example
|
|
373
430
|
```ts
|
|
374
431
|
vigor.fetch("https://api.example.com")
|
|
@@ -403,4 +460,6 @@ vigor.fetch("https://api.example.com")
|
|
|
403
460
|
)
|
|
404
461
|
.request()
|
|
405
462
|
```
|
|
463
|
+
|
|
464
|
+
|
|
406
465
|
---
|