vigor-fetch 3.1.1 → 3.1.3
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/dist/index.d.ts +12 -12
- package/dist/index.js +38 -5
- package/dist/index.mjs +38 -5
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -264,8 +264,8 @@ declare class VigorRetry extends VigorStatus<VigorRetryConfig, VigorRetry> {
|
|
|
264
264
|
private _createTimelineHandler;
|
|
265
265
|
private _createInterceptorHandler;
|
|
266
266
|
target(func: VigorRetryConfig["target"]): VigorRetry;
|
|
267
|
-
settings(func: ((s: VigorRetrySettings) => VigorRetrySettings) |
|
|
268
|
-
interceptors(func: ((i: VigorRetryInterceptors) => VigorRetryInterceptors) |
|
|
267
|
+
settings(func: ((s: VigorRetrySettings) => VigorRetrySettings) | VigorRetrySettings | VigorRetrySettings["_config"]): VigorRetry;
|
|
268
|
+
interceptors(func: ((i: VigorRetryInterceptors) => VigorRetryInterceptors) | VigorRetryInterceptors | VigorRetryInterceptors["_config"]): VigorRetry;
|
|
269
269
|
algorithms(func: (a: typeof this.RetryAlgorithms) => {
|
|
270
270
|
_calculateDelay: VigorRetryConfig["algorithm"];
|
|
271
271
|
}): VigorRetry;
|
|
@@ -355,7 +355,7 @@ type VigorParseProcessHandler = {
|
|
|
355
355
|
type VigorParseTimeline<I extends keyof VigorParseInterceptorsFunctions, H extends keyof VigorParseProcessHandler> = {
|
|
356
356
|
PROCESS_HANDLING: {
|
|
357
357
|
type: H;
|
|
358
|
-
data:
|
|
358
|
+
data: VigorParseProcessHandler[H];
|
|
359
359
|
};
|
|
360
360
|
INTERCEPTOR_LOOP_STARTED: {
|
|
361
361
|
interceptorType: I;
|
|
@@ -380,9 +380,9 @@ declare class VigorParse extends VigorStatus<VigorParseConfig, VigorParse> {
|
|
|
380
380
|
private _createTimelineHandler;
|
|
381
381
|
private _createInterceptorHandler;
|
|
382
382
|
target(response: VigorParseConfig["target"]): VigorParse;
|
|
383
|
-
settings(func: ((i: VigorParseSettings) => VigorParseSettings) |
|
|
384
|
-
strategies(func: ((i: VigorParseStrategies) => VigorParseStrategies) |
|
|
385
|
-
interceptors(func: ((i: VigorParseInterceptors) => VigorParseInterceptors) |
|
|
383
|
+
settings(func: ((i: VigorParseSettings) => VigorParseSettings) | VigorParseSettings | VigorParseSettings["_config"]): VigorParse;
|
|
384
|
+
strategies(func: ((i: VigorParseStrategies) => VigorParseStrategies) | VigorParseStrategies | VigorParseStrategies["_config"]): VigorParse;
|
|
385
|
+
interceptors(func: ((i: VigorParseInterceptors) => VigorParseInterceptors) | VigorParseInterceptors | VigorParseInterceptors["_config"]): VigorParse;
|
|
386
386
|
request<R>(config?: VigorParseConfig, timeline?: VigorParseContext["timeline"]): Promise<R>;
|
|
387
387
|
}
|
|
388
388
|
type VigorFetchSettingsConfig = {
|
|
@@ -534,10 +534,10 @@ declare class VigorFetch extends VigorStatus<VigorFetchConfig, VigorFetch> {
|
|
|
534
534
|
body(obj: VigorFetchConfig["options"]["body"]): VigorFetch;
|
|
535
535
|
private _buildUrl;
|
|
536
536
|
private _normalizeOptions;
|
|
537
|
-
settings(func: ((s: VigorFetchSettings) => VigorFetchSettings) |
|
|
538
|
-
interceptors(func: ((s: VigorFetchInterceptors) => VigorFetchInterceptors) |
|
|
539
|
-
retryConfig(func: ((s: VigorRetry) => VigorRetry) |
|
|
540
|
-
parseConfig(func: ((s: VigorParse) => VigorParse) |
|
|
537
|
+
settings(func: ((s: VigorFetchSettings) => VigorFetchSettings) | VigorFetchSettings | VigorFetchSettings["_config"]): VigorFetch;
|
|
538
|
+
interceptors(func: ((s: VigorFetchInterceptors) => VigorFetchInterceptors) | VigorFetchInterceptors | VigorFetchInterceptors["_config"]): VigorFetch;
|
|
539
|
+
retryConfig(func: ((s: VigorRetry) => VigorRetry) | VigorRetry | VigorRetry["_config"]): VigorFetch;
|
|
540
|
+
parseConfig(func: ((s: VigorParse) => VigorParse) | VigorParse | VigorParse["_config"]): VigorFetch;
|
|
541
541
|
request<R>(config?: VigorFetchConfig, timeline?: VigorFetchContext["timeline"]): Promise<R>;
|
|
542
542
|
}
|
|
543
543
|
type VigorAllSettingsConfig = {
|
|
@@ -711,8 +711,8 @@ declare class VigorAll extends VigorStatus<VigorAllConfig, VigorAll> {
|
|
|
711
711
|
private _createEachTimelineHandler;
|
|
712
712
|
private _createEachInterceptorHandler;
|
|
713
713
|
target(...funcs: VigorIncludeSpread<VigorAllConfig["target"][number]>): VigorAll;
|
|
714
|
-
settings(func: ((s: VigorAllSettings) => VigorAllSettings) |
|
|
715
|
-
interceptors(func: ((s: VigorAllInterceptors) => VigorAllInterceptors) |
|
|
714
|
+
settings(func: ((s: VigorAllSettings) => VigorAllSettings) | VigorAllSettings | VigorAllSettings["_config"]): VigorAll;
|
|
715
|
+
interceptors(func: ((s: VigorAllInterceptors) => VigorAllInterceptors) | VigorAllInterceptors | VigorAllInterceptors["_config"]): VigorAll;
|
|
716
716
|
private runTask;
|
|
717
717
|
request<R extends VigorAllContext["result"]>(config?: VigorAllConfig, timeline?: VigorAllContext["timeline"]): Promise<R>;
|
|
718
718
|
}
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const VigorErrorMessageFuncs = {
|
|
6
6
|
INVALID_TARGET: ({ expected, received }) => `Invalid Task: ${typeof received} (expected: ${expected.join(', ')})`,
|
|
7
|
-
EXHAUSTED: ({ maxAttempts }) => `Retry exhausted
|
|
7
|
+
EXHAUSTED: ({ maxAttempts }) => `Retry exhausted, (max ${maxAttempts})`,
|
|
8
8
|
TIMED_OUT: ({ limit, attempt }) => `Timeout: exceeded ${limit}ms (attempt: ${attempt})`,
|
|
9
9
|
INVALID_CONTENT_TYPE: ({ expected, received, response }) => `Invalid Content Type Header: ${typeof received} (expected: ${expected.join(', ')})`,
|
|
10
10
|
PARSER_NOT_FOUND: ({ expected, received, response }) => `Parser Not Found For Header: ${typeof received} (expected: ${expected.join(', ')})`,
|
|
@@ -242,12 +242,18 @@ class VigorRetry extends VigorStatus {
|
|
|
242
242
|
}
|
|
243
243
|
target(func) { return this._next({ target: func }); }
|
|
244
244
|
settings(func) {
|
|
245
|
+
if (func instanceof VigorRetrySettings) {
|
|
246
|
+
return this._next({ settings: func._getConfig() });
|
|
247
|
+
}
|
|
245
248
|
if (typeof func === 'function') {
|
|
246
249
|
return this._next({ settings: func(new VigorRetrySettings(this._config.settings))._getConfig() });
|
|
247
250
|
}
|
|
248
251
|
return this._next({ settings: func });
|
|
249
252
|
}
|
|
250
253
|
interceptors(func) {
|
|
254
|
+
if (func instanceof VigorRetryInterceptors) {
|
|
255
|
+
return this._next({ interceptors: func._getConfig() });
|
|
256
|
+
}
|
|
251
257
|
if (typeof func === 'function') {
|
|
252
258
|
return this._next({ interceptors: func(new VigorRetryInterceptors(this._config.interceptors))._getConfig() });
|
|
253
259
|
}
|
|
@@ -708,18 +714,27 @@ class VigorParse extends VigorStatus {
|
|
|
708
714
|
}
|
|
709
715
|
target(response) { return this._next({ target: response }); }
|
|
710
716
|
settings(func) {
|
|
717
|
+
if (func instanceof VigorParseSettings) {
|
|
718
|
+
return this._next({ settings: func._getConfig() });
|
|
719
|
+
}
|
|
711
720
|
if (typeof func === 'function') {
|
|
712
721
|
return this._next({ settings: func(new VigorParseSettings(this._config.settings))._getConfig() });
|
|
713
722
|
}
|
|
714
723
|
return this._next({ settings: func });
|
|
715
724
|
}
|
|
716
725
|
strategies(func) {
|
|
726
|
+
if (func instanceof VigorParseStrategies) {
|
|
727
|
+
return this._next({ strategies: func._getConfig() });
|
|
728
|
+
}
|
|
717
729
|
if (typeof func === 'function') {
|
|
718
730
|
return this._next({ strategies: func(new VigorParseStrategies(this._config.strategies))._getConfig() });
|
|
719
731
|
}
|
|
720
732
|
return this._next({ strategies: func });
|
|
721
733
|
}
|
|
722
734
|
interceptors(func) {
|
|
735
|
+
if (func instanceof VigorParseInterceptors) {
|
|
736
|
+
return this._next({ interceptors: func._getConfig() });
|
|
737
|
+
}
|
|
723
738
|
if (typeof func === 'function') {
|
|
724
739
|
return this._next({ interceptors: func(new VigorParseInterceptors(this._config.interceptors))._getConfig() });
|
|
725
740
|
}
|
|
@@ -1032,24 +1047,36 @@ class VigorFetch extends VigorStatus {
|
|
|
1032
1047
|
});
|
|
1033
1048
|
}
|
|
1034
1049
|
settings(func) {
|
|
1050
|
+
if (func instanceof VigorFetchSettings) {
|
|
1051
|
+
return this._next({ settings: func._getConfig() });
|
|
1052
|
+
}
|
|
1035
1053
|
if (typeof func === 'function') {
|
|
1036
1054
|
return this._next({ settings: func(new VigorFetchSettings(this._config.settings))._getConfig() });
|
|
1037
1055
|
}
|
|
1038
1056
|
return this._next({ settings: func });
|
|
1039
1057
|
}
|
|
1040
1058
|
interceptors(func) {
|
|
1059
|
+
if (func instanceof VigorFetchInterceptors) {
|
|
1060
|
+
return this._next({ interceptors: func._getConfig() });
|
|
1061
|
+
}
|
|
1041
1062
|
if (typeof func === 'function') {
|
|
1042
1063
|
return this._next({ interceptors: func(new VigorFetchInterceptors(this._config.interceptors))._getConfig() });
|
|
1043
1064
|
}
|
|
1044
1065
|
return this._next({ interceptors: func });
|
|
1045
1066
|
}
|
|
1046
1067
|
retryConfig(func) {
|
|
1068
|
+
if (func instanceof VigorRetry) {
|
|
1069
|
+
return this._next({ retryConfig: func._getConfig() });
|
|
1070
|
+
}
|
|
1047
1071
|
if (typeof func === 'function') {
|
|
1048
1072
|
return this._next({ retryConfig: func(new VigorRetry(this._config.retryConfig))._getConfig() });
|
|
1049
1073
|
}
|
|
1050
1074
|
return this._next({ retryConfig: func });
|
|
1051
1075
|
}
|
|
1052
1076
|
parseConfig(func) {
|
|
1077
|
+
if (func instanceof VigorParse) {
|
|
1078
|
+
return this._next({ parseConfig: func._getConfig() });
|
|
1079
|
+
}
|
|
1053
1080
|
if (typeof func === 'function') {
|
|
1054
1081
|
return this._next({ parseConfig: func(new VigorParse(this._config.parseConfig))._getConfig() });
|
|
1055
1082
|
}
|
|
@@ -1439,12 +1466,18 @@ class VigorAll extends VigorStatus {
|
|
|
1439
1466
|
}
|
|
1440
1467
|
target(...funcs) { return this._next({ target: funcs.flat() }); }
|
|
1441
1468
|
settings(func) {
|
|
1469
|
+
if (func instanceof VigorAllSettings) {
|
|
1470
|
+
return this._next({ settings: func._getConfig() });
|
|
1471
|
+
}
|
|
1442
1472
|
if (typeof func === 'function') {
|
|
1443
1473
|
return this._next({ settings: func(new VigorAllSettings(this._config.settings))._getConfig() });
|
|
1444
1474
|
}
|
|
1445
1475
|
return this._next({ settings: func });
|
|
1446
1476
|
}
|
|
1447
1477
|
interceptors(func) {
|
|
1478
|
+
if (func instanceof VigorAllInterceptors) {
|
|
1479
|
+
return this._next({ interceptors: func._getConfig() });
|
|
1480
|
+
}
|
|
1448
1481
|
if (typeof func === 'function') {
|
|
1449
1482
|
return this._next({ interceptors: func(new VigorAllInterceptors(this._config.interceptors))._getConfig() });
|
|
1450
1483
|
}
|
|
@@ -1599,10 +1632,10 @@ class VigorAll extends VigorStatus {
|
|
|
1599
1632
|
};
|
|
1600
1633
|
for (const task of stats.target) {
|
|
1601
1634
|
let promise;
|
|
1602
|
-
promise = this.runTask(task, { stats, root: ctx }, { acquire, release })
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1635
|
+
promise = this.runTask(task, { stats, root: ctx }, { acquire, release })
|
|
1636
|
+
.then(res => ({ success: true, value: res }))
|
|
1637
|
+
.catch(err => ({ success: false, value: err }))
|
|
1638
|
+
.finally(() => ctx.queue.delete(promise));
|
|
1606
1639
|
ctx.queue.add(promise);
|
|
1607
1640
|
}
|
|
1608
1641
|
addTimeline("QUEUE_REQUEST_STARTED", {
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const VigorErrorMessageFuncs = {
|
|
2
2
|
INVALID_TARGET: ({ expected, received }) => `Invalid Task: ${typeof received} (expected: ${expected.join(', ')})`,
|
|
3
|
-
EXHAUSTED: ({ maxAttempts }) => `Retry exhausted
|
|
3
|
+
EXHAUSTED: ({ maxAttempts }) => `Retry exhausted, (max ${maxAttempts})`,
|
|
4
4
|
TIMED_OUT: ({ limit, attempt }) => `Timeout: exceeded ${limit}ms (attempt: ${attempt})`,
|
|
5
5
|
INVALID_CONTENT_TYPE: ({ expected, received, response }) => `Invalid Content Type Header: ${typeof received} (expected: ${expected.join(', ')})`,
|
|
6
6
|
PARSER_NOT_FOUND: ({ expected, received, response }) => `Parser Not Found For Header: ${typeof received} (expected: ${expected.join(', ')})`,
|
|
@@ -238,12 +238,18 @@ class VigorRetry extends VigorStatus {
|
|
|
238
238
|
}
|
|
239
239
|
target(func) { return this._next({ target: func }); }
|
|
240
240
|
settings(func) {
|
|
241
|
+
if (func instanceof VigorRetrySettings) {
|
|
242
|
+
return this._next({ settings: func._getConfig() });
|
|
243
|
+
}
|
|
241
244
|
if (typeof func === 'function') {
|
|
242
245
|
return this._next({ settings: func(new VigorRetrySettings(this._config.settings))._getConfig() });
|
|
243
246
|
}
|
|
244
247
|
return this._next({ settings: func });
|
|
245
248
|
}
|
|
246
249
|
interceptors(func) {
|
|
250
|
+
if (func instanceof VigorRetryInterceptors) {
|
|
251
|
+
return this._next({ interceptors: func._getConfig() });
|
|
252
|
+
}
|
|
247
253
|
if (typeof func === 'function') {
|
|
248
254
|
return this._next({ interceptors: func(new VigorRetryInterceptors(this._config.interceptors))._getConfig() });
|
|
249
255
|
}
|
|
@@ -704,18 +710,27 @@ class VigorParse extends VigorStatus {
|
|
|
704
710
|
}
|
|
705
711
|
target(response) { return this._next({ target: response }); }
|
|
706
712
|
settings(func) {
|
|
713
|
+
if (func instanceof VigorParseSettings) {
|
|
714
|
+
return this._next({ settings: func._getConfig() });
|
|
715
|
+
}
|
|
707
716
|
if (typeof func === 'function') {
|
|
708
717
|
return this._next({ settings: func(new VigorParseSettings(this._config.settings))._getConfig() });
|
|
709
718
|
}
|
|
710
719
|
return this._next({ settings: func });
|
|
711
720
|
}
|
|
712
721
|
strategies(func) {
|
|
722
|
+
if (func instanceof VigorParseStrategies) {
|
|
723
|
+
return this._next({ strategies: func._getConfig() });
|
|
724
|
+
}
|
|
713
725
|
if (typeof func === 'function') {
|
|
714
726
|
return this._next({ strategies: func(new VigorParseStrategies(this._config.strategies))._getConfig() });
|
|
715
727
|
}
|
|
716
728
|
return this._next({ strategies: func });
|
|
717
729
|
}
|
|
718
730
|
interceptors(func) {
|
|
731
|
+
if (func instanceof VigorParseInterceptors) {
|
|
732
|
+
return this._next({ interceptors: func._getConfig() });
|
|
733
|
+
}
|
|
719
734
|
if (typeof func === 'function') {
|
|
720
735
|
return this._next({ interceptors: func(new VigorParseInterceptors(this._config.interceptors))._getConfig() });
|
|
721
736
|
}
|
|
@@ -1028,24 +1043,36 @@ class VigorFetch extends VigorStatus {
|
|
|
1028
1043
|
});
|
|
1029
1044
|
}
|
|
1030
1045
|
settings(func) {
|
|
1046
|
+
if (func instanceof VigorFetchSettings) {
|
|
1047
|
+
return this._next({ settings: func._getConfig() });
|
|
1048
|
+
}
|
|
1031
1049
|
if (typeof func === 'function') {
|
|
1032
1050
|
return this._next({ settings: func(new VigorFetchSettings(this._config.settings))._getConfig() });
|
|
1033
1051
|
}
|
|
1034
1052
|
return this._next({ settings: func });
|
|
1035
1053
|
}
|
|
1036
1054
|
interceptors(func) {
|
|
1055
|
+
if (func instanceof VigorFetchInterceptors) {
|
|
1056
|
+
return this._next({ interceptors: func._getConfig() });
|
|
1057
|
+
}
|
|
1037
1058
|
if (typeof func === 'function') {
|
|
1038
1059
|
return this._next({ interceptors: func(new VigorFetchInterceptors(this._config.interceptors))._getConfig() });
|
|
1039
1060
|
}
|
|
1040
1061
|
return this._next({ interceptors: func });
|
|
1041
1062
|
}
|
|
1042
1063
|
retryConfig(func) {
|
|
1064
|
+
if (func instanceof VigorRetry) {
|
|
1065
|
+
return this._next({ retryConfig: func._getConfig() });
|
|
1066
|
+
}
|
|
1043
1067
|
if (typeof func === 'function') {
|
|
1044
1068
|
return this._next({ retryConfig: func(new VigorRetry(this._config.retryConfig))._getConfig() });
|
|
1045
1069
|
}
|
|
1046
1070
|
return this._next({ retryConfig: func });
|
|
1047
1071
|
}
|
|
1048
1072
|
parseConfig(func) {
|
|
1073
|
+
if (func instanceof VigorParse) {
|
|
1074
|
+
return this._next({ parseConfig: func._getConfig() });
|
|
1075
|
+
}
|
|
1049
1076
|
if (typeof func === 'function') {
|
|
1050
1077
|
return this._next({ parseConfig: func(new VigorParse(this._config.parseConfig))._getConfig() });
|
|
1051
1078
|
}
|
|
@@ -1435,12 +1462,18 @@ class VigorAll extends VigorStatus {
|
|
|
1435
1462
|
}
|
|
1436
1463
|
target(...funcs) { return this._next({ target: funcs.flat() }); }
|
|
1437
1464
|
settings(func) {
|
|
1465
|
+
if (func instanceof VigorAllSettings) {
|
|
1466
|
+
return this._next({ settings: func._getConfig() });
|
|
1467
|
+
}
|
|
1438
1468
|
if (typeof func === 'function') {
|
|
1439
1469
|
return this._next({ settings: func(new VigorAllSettings(this._config.settings))._getConfig() });
|
|
1440
1470
|
}
|
|
1441
1471
|
return this._next({ settings: func });
|
|
1442
1472
|
}
|
|
1443
1473
|
interceptors(func) {
|
|
1474
|
+
if (func instanceof VigorAllInterceptors) {
|
|
1475
|
+
return this._next({ interceptors: func._getConfig() });
|
|
1476
|
+
}
|
|
1444
1477
|
if (typeof func === 'function') {
|
|
1445
1478
|
return this._next({ interceptors: func(new VigorAllInterceptors(this._config.interceptors))._getConfig() });
|
|
1446
1479
|
}
|
|
@@ -1595,10 +1628,10 @@ class VigorAll extends VigorStatus {
|
|
|
1595
1628
|
};
|
|
1596
1629
|
for (const task of stats.target) {
|
|
1597
1630
|
let promise;
|
|
1598
|
-
promise = this.runTask(task, { stats, root: ctx }, { acquire, release })
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1631
|
+
promise = this.runTask(task, { stats, root: ctx }, { acquire, release })
|
|
1632
|
+
.then(res => ({ success: true, value: res }))
|
|
1633
|
+
.catch(err => ({ success: false, value: err }))
|
|
1634
|
+
.finally(() => ctx.queue.delete(promise));
|
|
1602
1635
|
ctx.queue.add(promise);
|
|
1603
1636
|
}
|
|
1604
1637
|
addTimeline("QUEUE_REQUEST_STARTED", {
|