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.cjs
CHANGED
|
@@ -86,6 +86,7 @@ var VigorDefault = /* @__PURE__ */ Symbol("VigorDefault");
|
|
|
86
86
|
var isVigorDefault = (v) => v === VigorDefault;
|
|
87
87
|
var VigorEmpty = /* @__PURE__ */ Symbol("VigorEmpty");
|
|
88
88
|
var isVigorEmpty = (v) => v === VigorEmpty;
|
|
89
|
+
var VigorCastPlaceholder = /* @__PURE__ */ Symbol("VigorCastPlaceholder");
|
|
89
90
|
|
|
90
91
|
// src/core/status.ts
|
|
91
92
|
var VigorStatus = class {
|
|
@@ -266,7 +267,7 @@ var VigorAllError = class extends VigorError {
|
|
|
266
267
|
var VigorAllBase = {
|
|
267
268
|
__brand: createBrand("All", "Schema"),
|
|
268
269
|
policy: VigorAllPolicyBase,
|
|
269
|
-
|
|
270
|
+
cast: VigorEmpty
|
|
270
271
|
};
|
|
271
272
|
var VigorAll = class _VigorAll extends VigorStatus {
|
|
272
273
|
constructor(config = VigorAllBase) {
|
|
@@ -318,6 +319,18 @@ var VigorAll = class _VigorAll extends VigorStatus {
|
|
|
318
319
|
return { success: false, value: error };
|
|
319
320
|
}
|
|
320
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Overrides the resolved result type with `T`, taking priority over the
|
|
324
|
+
* naturally-inferred `unknown[]`. Can be called before or after
|
|
325
|
+
* `target()` (or any other configuration method); whichever `.cast<T>()`
|
|
326
|
+
* call happens last wins.
|
|
327
|
+
*/
|
|
328
|
+
cast() {
|
|
329
|
+
return this._next(
|
|
330
|
+
{ cast: VigorCastPlaceholder },
|
|
331
|
+
{ cast: "replace" }
|
|
332
|
+
);
|
|
333
|
+
}
|
|
321
334
|
/** Runs all tasks and returns the results array directly, throwing on final failure. */
|
|
322
335
|
async request() {
|
|
323
336
|
const res = await this.requestVerbose();
|
|
@@ -790,7 +803,7 @@ var VigorRetryContextBase = {
|
|
|
790
803
|
var VigorRetryBase = {
|
|
791
804
|
__brand: createBrand("Retry", "Schema"),
|
|
792
805
|
policy: VigorRetryPolicyBase,
|
|
793
|
-
|
|
806
|
+
cast: VigorEmpty
|
|
794
807
|
};
|
|
795
808
|
var VigorRetry = class _VigorRetry extends VigorStatus {
|
|
796
809
|
constructor(config = VigorRetryBase) {
|
|
@@ -848,6 +861,18 @@ var VigorRetry = class _VigorRetry extends VigorStatus {
|
|
|
848
861
|
policy: { algorithms: input }
|
|
849
862
|
}, { policy: { algorithms: "replace" } });
|
|
850
863
|
}
|
|
864
|
+
/**
|
|
865
|
+
* Overrides the resolved result type with `T`, taking priority over the
|
|
866
|
+
* type naturally inferred from `target()`. Can be called before or after
|
|
867
|
+
* `target()` (or any other configuration method); whichever `.cast<T>()`
|
|
868
|
+
* call happens last wins.
|
|
869
|
+
*/
|
|
870
|
+
cast() {
|
|
871
|
+
return this._next(
|
|
872
|
+
{ cast: VigorCastPlaceholder },
|
|
873
|
+
{ cast: "replace" }
|
|
874
|
+
);
|
|
875
|
+
}
|
|
851
876
|
/** Runs the target and returns its result directly, throwing on final failure. */
|
|
852
877
|
async request() {
|
|
853
878
|
const res = await this.requestVerbose();
|
|
@@ -862,7 +887,7 @@ var VigorRetry = class _VigorRetry extends VigorStatus {
|
|
|
862
887
|
async requestRuntime(restartAttempt = 1) {
|
|
863
888
|
const config = this._merge(this.config, {});
|
|
864
889
|
let ctx = {
|
|
865
|
-
...
|
|
890
|
+
...VigorRetryContextBase,
|
|
866
891
|
policy: config.policy
|
|
867
892
|
};
|
|
868
893
|
if (isVigorEmpty(ctx.policy.target)) throw new VigorRetryError("VALUE_REQUIRED", {
|
|
@@ -1275,7 +1300,7 @@ var VigorParseContextBase = {
|
|
|
1275
1300
|
var VigorParseBase = {
|
|
1276
1301
|
__brand: createBrand("Parse", "Schema"),
|
|
1277
1302
|
policy: VigorParsePolicyBase,
|
|
1278
|
-
|
|
1303
|
+
cast: VigorEmpty
|
|
1279
1304
|
};
|
|
1280
1305
|
var VigorParse = class _VigorParse extends VigorStatus {
|
|
1281
1306
|
constructor(config = VigorParseBase) {
|
|
@@ -1318,6 +1343,18 @@ var VigorParse = class _VigorParse extends VigorStatus {
|
|
|
1318
1343
|
}
|
|
1319
1344
|
return this._next({ policy: { strategies: input } });
|
|
1320
1345
|
}
|
|
1346
|
+
/**
|
|
1347
|
+
* Overrides the resolved result type with `T`, taking priority over the
|
|
1348
|
+
* default `unknown` result. Can be called before or after `strategies()`
|
|
1349
|
+
* (or any other configuration method); whichever `.cast<T>()` call
|
|
1350
|
+
* happens last wins.
|
|
1351
|
+
*/
|
|
1352
|
+
cast() {
|
|
1353
|
+
return this._next(
|
|
1354
|
+
{ cast: VigorCastPlaceholder },
|
|
1355
|
+
{ cast: "replace" }
|
|
1356
|
+
);
|
|
1357
|
+
}
|
|
1321
1358
|
/** Runs parsing and returns the result directly, throwing on final failure. */
|
|
1322
1359
|
async request() {
|
|
1323
1360
|
const res = await this.requestVerbose();
|
|
@@ -1332,7 +1369,7 @@ var VigorParse = class _VigorParse extends VigorStatus {
|
|
|
1332
1369
|
async requestRuntime(restartAttempt = 1) {
|
|
1333
1370
|
const config = this._merge(this.config, {});
|
|
1334
1371
|
let ctx = {
|
|
1335
|
-
...
|
|
1372
|
+
...VigorParseContextBase,
|
|
1336
1373
|
policy: config.policy
|
|
1337
1374
|
};
|
|
1338
1375
|
if (isVigorDefault(ctx.policy.target)) throw new VigorParseError("VALUE_REQUIRED", {
|
|
@@ -1501,7 +1538,7 @@ var VigorFetchError = class extends VigorError {
|
|
|
1501
1538
|
var VigorFetchBase = {
|
|
1502
1539
|
__brand: createBrand("Fetch", "Schema"),
|
|
1503
1540
|
policy: VigorFetchPolicyBase,
|
|
1504
|
-
|
|
1541
|
+
cast: VigorEmpty
|
|
1505
1542
|
};
|
|
1506
1543
|
var VigorFetch = class _VigorFetch extends VigorStatus {
|
|
1507
1544
|
constructor(config = VigorFetchBase) {
|
|
@@ -1669,6 +1706,18 @@ var VigorFetch = class _VigorFetch extends VigorStatus {
|
|
|
1669
1706
|
data: { received: body }
|
|
1670
1707
|
});
|
|
1671
1708
|
}
|
|
1709
|
+
/**
|
|
1710
|
+
* Overrides the resolved result type with `T`, taking priority over the
|
|
1711
|
+
* default `unknown` result. Can be called before or after `parse()` (or
|
|
1712
|
+
* any other configuration method); whichever `.cast<T>()` call happens
|
|
1713
|
+
* last wins.
|
|
1714
|
+
*/
|
|
1715
|
+
cast() {
|
|
1716
|
+
return this._next(
|
|
1717
|
+
{ cast: VigorCastPlaceholder },
|
|
1718
|
+
{ cast: "replace" }
|
|
1719
|
+
);
|
|
1720
|
+
}
|
|
1672
1721
|
/** Runs the request and returns its parsed result directly, throwing on final failure. */
|
|
1673
1722
|
async request() {
|
|
1674
1723
|
const res = await this.requestVerbose();
|
|
@@ -1683,7 +1732,7 @@ var VigorFetch = class _VigorFetch extends VigorStatus {
|
|
|
1683
1732
|
async requestRuntime(restartAttempt = 1) {
|
|
1684
1733
|
const config = this._merge(this.config, {});
|
|
1685
1734
|
let ctx = {
|
|
1686
|
-
...
|
|
1735
|
+
...VigorFetchContextBase,
|
|
1687
1736
|
policy: config.policy
|
|
1688
1737
|
};
|
|
1689
1738
|
const throwError = (err) => {
|
|
@@ -1853,11 +1902,23 @@ var VigorFetch = class _VigorFetch extends VigorStatus {
|
|
|
1853
1902
|
};
|
|
1854
1903
|
|
|
1855
1904
|
// src/entry/main.ts
|
|
1905
|
+
function retryWithTarget(task) {
|
|
1906
|
+
return new VigorRetry().target(task);
|
|
1907
|
+
}
|
|
1908
|
+
function parseWithTarget(response) {
|
|
1909
|
+
return new VigorParse().target(response);
|
|
1910
|
+
}
|
|
1911
|
+
function fetchWithOrigin(origin) {
|
|
1912
|
+
return new VigorFetch().origin(origin);
|
|
1913
|
+
}
|
|
1914
|
+
function allWithTargets(tasks) {
|
|
1915
|
+
return new VigorAll().target(...tasks);
|
|
1916
|
+
}
|
|
1856
1917
|
var vigorBase = {
|
|
1857
|
-
retry: (
|
|
1858
|
-
parse: (
|
|
1859
|
-
fetch: (
|
|
1860
|
-
all: (...tasks) => tasks.length > 0 ?
|
|
1918
|
+
retry: ((task) => task !== void 0 ? retryWithTarget(task) : new VigorRetry()),
|
|
1919
|
+
parse: ((response) => response !== void 0 ? parseWithTarget(response) : new VigorParse()),
|
|
1920
|
+
fetch: ((origin) => origin !== void 0 ? fetchWithOrigin(origin) : new VigorFetch()),
|
|
1921
|
+
all: ((...tasks) => tasks.length > 0 ? allWithTargets(tasks) : new VigorAll()),
|
|
1861
1922
|
builders: {
|
|
1862
1923
|
fetch: {
|
|
1863
1924
|
settings: () => new VigorFetchPolicySettings(),
|