vigor-fetch 4.0.5 → 4.0.7
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.cjs +72 -11
- package/dist/index.d.cts +1405 -2551
- package/dist/index.d.ts +1405 -2551
- package/dist/index.js +72 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ var VigorDefault = /* @__PURE__ */ Symbol("VigorDefault");
|
|
|
6
6
|
var isVigorDefault = (v) => v === VigorDefault;
|
|
7
7
|
var VigorEmpty = /* @__PURE__ */ Symbol("VigorEmpty");
|
|
8
8
|
var isVigorEmpty = (v) => v === VigorEmpty;
|
|
9
|
+
var VigorCastPlaceholder = /* @__PURE__ */ Symbol("VigorCastPlaceholder");
|
|
9
10
|
|
|
10
11
|
// src/core/status.ts
|
|
11
12
|
var VigorStatus = class {
|
|
@@ -186,7 +187,7 @@ var VigorAllError = class extends VigorError {
|
|
|
186
187
|
var VigorAllBase = {
|
|
187
188
|
__brand: createBrand("All", "Schema"),
|
|
188
189
|
policy: VigorAllPolicyBase,
|
|
189
|
-
|
|
190
|
+
cast: VigorEmpty
|
|
190
191
|
};
|
|
191
192
|
var VigorAll = class _VigorAll extends VigorStatus {
|
|
192
193
|
constructor(config = VigorAllBase) {
|
|
@@ -238,6 +239,18 @@ var VigorAll = class _VigorAll extends VigorStatus {
|
|
|
238
239
|
return { success: false, value: error };
|
|
239
240
|
}
|
|
240
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Overrides the resolved result type with `T`, taking priority over the
|
|
244
|
+
* naturally-inferred `unknown[]`. Can be called before or after
|
|
245
|
+
* `target()` (or any other configuration method); whichever `.cast<T>()`
|
|
246
|
+
* call happens last wins.
|
|
247
|
+
*/
|
|
248
|
+
cast() {
|
|
249
|
+
return this._next(
|
|
250
|
+
{ cast: VigorCastPlaceholder },
|
|
251
|
+
{ cast: "replace" }
|
|
252
|
+
);
|
|
253
|
+
}
|
|
241
254
|
/** Runs all tasks and returns the results array directly, throwing on final failure. */
|
|
242
255
|
async request() {
|
|
243
256
|
const res = await this.requestVerbose();
|
|
@@ -710,7 +723,7 @@ var VigorRetryContextBase = {
|
|
|
710
723
|
var VigorRetryBase = {
|
|
711
724
|
__brand: createBrand("Retry", "Schema"),
|
|
712
725
|
policy: VigorRetryPolicyBase,
|
|
713
|
-
|
|
726
|
+
cast: VigorEmpty
|
|
714
727
|
};
|
|
715
728
|
var VigorRetry = class _VigorRetry extends VigorStatus {
|
|
716
729
|
constructor(config = VigorRetryBase) {
|
|
@@ -768,6 +781,18 @@ var VigorRetry = class _VigorRetry extends VigorStatus {
|
|
|
768
781
|
policy: { algorithms: input }
|
|
769
782
|
}, { policy: { algorithms: "replace" } });
|
|
770
783
|
}
|
|
784
|
+
/**
|
|
785
|
+
* Overrides the resolved result type with `T`, taking priority over the
|
|
786
|
+
* type naturally inferred from `target()`. Can be called before or after
|
|
787
|
+
* `target()` (or any other configuration method); whichever `.cast<T>()`
|
|
788
|
+
* call happens last wins.
|
|
789
|
+
*/
|
|
790
|
+
cast() {
|
|
791
|
+
return this._next(
|
|
792
|
+
{ cast: VigorCastPlaceholder },
|
|
793
|
+
{ cast: "replace" }
|
|
794
|
+
);
|
|
795
|
+
}
|
|
771
796
|
/** Runs the target and returns its result directly, throwing on final failure. */
|
|
772
797
|
async request() {
|
|
773
798
|
const res = await this.requestVerbose();
|
|
@@ -782,7 +807,7 @@ var VigorRetry = class _VigorRetry extends VigorStatus {
|
|
|
782
807
|
async requestRuntime(restartAttempt = 1) {
|
|
783
808
|
const config = this._merge(this.config, {});
|
|
784
809
|
let ctx = {
|
|
785
|
-
...
|
|
810
|
+
...VigorRetryContextBase,
|
|
786
811
|
policy: config.policy
|
|
787
812
|
};
|
|
788
813
|
if (isVigorEmpty(ctx.policy.target)) throw new VigorRetryError("VALUE_REQUIRED", {
|
|
@@ -1195,7 +1220,7 @@ var VigorParseContextBase = {
|
|
|
1195
1220
|
var VigorParseBase = {
|
|
1196
1221
|
__brand: createBrand("Parse", "Schema"),
|
|
1197
1222
|
policy: VigorParsePolicyBase,
|
|
1198
|
-
|
|
1223
|
+
cast: VigorEmpty
|
|
1199
1224
|
};
|
|
1200
1225
|
var VigorParse = class _VigorParse extends VigorStatus {
|
|
1201
1226
|
constructor(config = VigorParseBase) {
|
|
@@ -1238,6 +1263,18 @@ var VigorParse = class _VigorParse extends VigorStatus {
|
|
|
1238
1263
|
}
|
|
1239
1264
|
return this._next({ policy: { strategies: input } });
|
|
1240
1265
|
}
|
|
1266
|
+
/**
|
|
1267
|
+
* Overrides the resolved result type with `T`, taking priority over the
|
|
1268
|
+
* default `unknown` result. Can be called before or after `strategies()`
|
|
1269
|
+
* (or any other configuration method); whichever `.cast<T>()` call
|
|
1270
|
+
* happens last wins.
|
|
1271
|
+
*/
|
|
1272
|
+
cast() {
|
|
1273
|
+
return this._next(
|
|
1274
|
+
{ cast: VigorCastPlaceholder },
|
|
1275
|
+
{ cast: "replace" }
|
|
1276
|
+
);
|
|
1277
|
+
}
|
|
1241
1278
|
/** Runs parsing and returns the result directly, throwing on final failure. */
|
|
1242
1279
|
async request() {
|
|
1243
1280
|
const res = await this.requestVerbose();
|
|
@@ -1252,7 +1289,7 @@ var VigorParse = class _VigorParse extends VigorStatus {
|
|
|
1252
1289
|
async requestRuntime(restartAttempt = 1) {
|
|
1253
1290
|
const config = this._merge(this.config, {});
|
|
1254
1291
|
let ctx = {
|
|
1255
|
-
...
|
|
1292
|
+
...VigorParseContextBase,
|
|
1256
1293
|
policy: config.policy
|
|
1257
1294
|
};
|
|
1258
1295
|
if (isVigorDefault(ctx.policy.target)) throw new VigorParseError("VALUE_REQUIRED", {
|
|
@@ -1421,7 +1458,7 @@ var VigorFetchError = class extends VigorError {
|
|
|
1421
1458
|
var VigorFetchBase = {
|
|
1422
1459
|
__brand: createBrand("Fetch", "Schema"),
|
|
1423
1460
|
policy: VigorFetchPolicyBase,
|
|
1424
|
-
|
|
1461
|
+
cast: VigorEmpty
|
|
1425
1462
|
};
|
|
1426
1463
|
var VigorFetch = class _VigorFetch extends VigorStatus {
|
|
1427
1464
|
constructor(config = VigorFetchBase) {
|
|
@@ -1589,6 +1626,18 @@ var VigorFetch = class _VigorFetch extends VigorStatus {
|
|
|
1589
1626
|
data: { received: body }
|
|
1590
1627
|
});
|
|
1591
1628
|
}
|
|
1629
|
+
/**
|
|
1630
|
+
* Overrides the resolved result type with `T`, taking priority over the
|
|
1631
|
+
* default `unknown` result. Can be called before or after `parse()` (or
|
|
1632
|
+
* any other configuration method); whichever `.cast<T>()` call happens
|
|
1633
|
+
* last wins.
|
|
1634
|
+
*/
|
|
1635
|
+
cast() {
|
|
1636
|
+
return this._next(
|
|
1637
|
+
{ cast: VigorCastPlaceholder },
|
|
1638
|
+
{ cast: "replace" }
|
|
1639
|
+
);
|
|
1640
|
+
}
|
|
1592
1641
|
/** Runs the request and returns its parsed result directly, throwing on final failure. */
|
|
1593
1642
|
async request() {
|
|
1594
1643
|
const res = await this.requestVerbose();
|
|
@@ -1603,7 +1652,7 @@ var VigorFetch = class _VigorFetch extends VigorStatus {
|
|
|
1603
1652
|
async requestRuntime(restartAttempt = 1) {
|
|
1604
1653
|
const config = this._merge(this.config, {});
|
|
1605
1654
|
let ctx = {
|
|
1606
|
-
...
|
|
1655
|
+
...VigorFetchContextBase,
|
|
1607
1656
|
policy: config.policy
|
|
1608
1657
|
};
|
|
1609
1658
|
const throwError = (err) => {
|
|
@@ -1773,11 +1822,23 @@ var VigorFetch = class _VigorFetch extends VigorStatus {
|
|
|
1773
1822
|
};
|
|
1774
1823
|
|
|
1775
1824
|
// src/entry/main.ts
|
|
1825
|
+
function retryWithTarget(task) {
|
|
1826
|
+
return new VigorRetry().target(task);
|
|
1827
|
+
}
|
|
1828
|
+
function parseWithTarget(response) {
|
|
1829
|
+
return new VigorParse().target(response);
|
|
1830
|
+
}
|
|
1831
|
+
function fetchWithOrigin(origin) {
|
|
1832
|
+
return new VigorFetch().origin(origin);
|
|
1833
|
+
}
|
|
1834
|
+
function allWithTargets(tasks) {
|
|
1835
|
+
return new VigorAll().target(...tasks);
|
|
1836
|
+
}
|
|
1776
1837
|
var vigorBase = {
|
|
1777
|
-
retry: (
|
|
1778
|
-
parse: (
|
|
1779
|
-
fetch: (
|
|
1780
|
-
all: (...tasks) => tasks.length > 0 ?
|
|
1838
|
+
retry: ((task) => task !== void 0 ? retryWithTarget(task) : new VigorRetry()),
|
|
1839
|
+
parse: ((response) => response !== void 0 ? parseWithTarget(response) : new VigorParse()),
|
|
1840
|
+
fetch: ((origin) => origin !== void 0 ? fetchWithOrigin(origin) : new VigorFetch()),
|
|
1841
|
+
all: ((...tasks) => tasks.length > 0 ? allWithTargets(tasks) : new VigorAll()),
|
|
1781
1842
|
builders: {
|
|
1782
1843
|
fetch: {
|
|
1783
1844
|
settings: () => new VigorFetchPolicySettings(),
|