vigor-fetch 4.0.8 → 4.0.9

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 CHANGED
@@ -12,8 +12,9 @@ Vigor gives you an immutable, chainable API for building robust network logic: r
12
12
  - 🔁 **Two-level retry** — per-attempt retry/backoff *and* whole-pipeline restart, each independently configurable
13
13
  - 🌐 **Smart fetch layer** — automatic `429 Retry-After` handling, configurable "never retry" status codes
14
14
  - 🔌 **Content-aware parsing** — auto-detects `Content-Type`, with a sniffing fallback and custom strategies
15
- - ⚡ **Bounded concurrency runner** — run many tasks with a concurrency cap and per-task hooks
15
+ - ⚡ **Bounded concurrency runner** — run many tasks with a concurrency cap, batch-level hooks, and per-task hooks
16
16
  - 🪝 **Two middleware modes** — `"fluent"` (return a value) or `"intercept"` (get an explicit control API)
17
+ - 🧬 **Type-level result override** — `.cast<T>()` on every module, when you know better than inference does
17
18
  - 🧠 **TypeScript-first** — config shape is inferred and carried through the whole chain
18
19
 
19
20
  ---
@@ -92,12 +93,40 @@ vigor.retry(task?) // -> VigorRetry, target pre-set if given
92
93
  vigor.parse(response?) // -> VigorParse, target pre-set if given
93
94
  vigor.all(...tasks) // -> VigorAll, target pre-set if any tasks given
94
95
  vigor.use(plugin, options?)
96
+ vigor.builders // direct access to each module's sub-builders
95
97
  ```
96
98
 
97
- Every module follows the same shape: an **immutable builder** with `.settings()`, `.middlewares()`, and a terminal `.request()` / `.requestVerbose()` pair.
99
+ Every module follows the same shape: an **immutable builder** with `.settings()`, `.middlewares()`, a terminal `.request()` / `.requestVerbose()` pair, and a `.cast<T>()` escape hatch for the result type.
98
100
 
99
101
  - `.request()` returns the result directly and **throws** on final failure.
100
102
  - `.requestVerbose()` never throws — it returns `{ success: true, data, error: null }` or `{ success: false, data: null, error }`.
103
+ - `.cast<T>()` overrides the inferred result type with `T`. It can be called before or after any other configuration method — whichever `.cast<T>()` call happens *last* in the chain wins, and it always takes priority over the naturally-inferred type.
104
+
105
+ ### `vigor.builders`
106
+
107
+ Every sub-builder used internally by `.settings()`/`.middlewares()`/etc. is also reachable directly, if you'd rather construct a reusable config object outside of a chain:
108
+
109
+ ```ts
110
+ vigor.builders.fetch.settings() // -> VigorFetchPolicySettings
111
+ vigor.builders.fetch.middlewares() // -> VigorFetchPolicyMiddlewares
112
+
113
+ vigor.builders.retry.settings() // -> VigorRetryPolicySettings
114
+ vigor.builders.retry.middlewares() // -> VigorRetryPolicyMiddlewares
115
+ vigor.builders.retry.algorithms() // -> VigorRetryPolicyAlgorithms
116
+ vigor.builders.retry.algorithm.constant()
117
+ vigor.builders.retry.algorithm.linear()
118
+ vigor.builders.retry.algorithm.backoff()
119
+ vigor.builders.retry.algorithm.custom()
120
+
121
+ vigor.builders.parse.settings() // -> VigorParsePolicySettings
122
+ vigor.builders.parse.middlewares() // -> VigorParsePolicyMiddlewares
123
+ vigor.builders.parse.strategies() // -> VigorParsePolicyStrategies
124
+
125
+ vigor.builders.all.settings() // -> VigorAllPolicySettings
126
+ vigor.builders.all.middlewares() // -> VigorAllPolicyMiddlewares
127
+ ```
128
+
129
+ This is equivalent to `new VigorFetchPolicySettings()` etc., just namespaced under `vigor` for discoverability.
101
130
 
102
131
  ---
103
132
 
@@ -119,6 +148,7 @@ Every module follows the same shape: an **immutable builder** with `.settings()`
119
148
  | `middlewares(fn \| config)` | Configures the fetch middleware pipeline (below) |
120
149
  | `retry(fn \| config \| VigorRetry)` | Configures the **internal retry engine** used to send the request |
121
150
  | `parse(fn \| config \| VigorParse)` | Configures the **internal parse engine** used to interpret the response |
151
+ | `cast<T>()` | Overrides the inferred result type with `T` |
122
152
  | `request()` | Executes and returns the parsed result, throwing on failure |
123
153
  | `requestVerbose()` | Executes and returns `{ success, data, error }` |
124
154
 
@@ -207,6 +237,19 @@ const data = await vigor
207
237
 
208
238
  Both accept a config object, a builder callback, or an already-built `VigorRetry`/`VigorParse` instance. The target function you'd normally set with `.target()` is ignored here — fetch always supplies its own target (the actual `fetch()` call) and its own `.target()` (`response.clone()` fed through your parse config).
209
239
 
240
+ ### cast
241
+
242
+ ```ts
243
+ const data = await vigor
244
+ .fetch("/api/users")
245
+ .parse(p => p.strategies(s => s.json()))
246
+ .cast<{ id: string; name: string }[]>()
247
+ .request();
248
+ // data: { id: string; name: string }[]
249
+ ```
250
+
251
+ Without `.cast()`, the result type falls back to whatever your `parse()` config naturally infers (`unknown` if unconfigured). `.cast()` overrides that regardless of where in the chain it's called.
252
+
210
253
  ---
211
254
 
212
255
  ## `vigor.retry`
@@ -220,6 +263,7 @@ Both accept a config object, a builder callback, or an already-built `VigorRetry
220
263
  | `settings(fn \| config)` | General retry settings (below) |
221
264
  | `middlewares(fn \| config)` | Middleware pipeline (below) |
222
265
  | `algorithms(fn)` | Selects and configures the delay algorithm (below) |
266
+ | `cast<T>()` | Overrides the inferred result type with `T` |
223
267
  | `request()` / `requestVerbose()` | Executes |
224
268
 
225
269
  ```ts
@@ -307,6 +351,7 @@ There are two independent resilience layers here:
307
351
  | `settings(fn \| config)` | General settings (below) |
308
352
  | `middlewares(fn \| config)` | Middleware pipeline (below) |
309
353
  | `strategies(fn \| config)` | Configures the ordered fallback chain of parsing strategies |
354
+ | `cast<T>()` | Overrides the inferred result type with `T` |
310
355
  | `request()` / `requestVerbose()` | Executes |
311
356
 
312
357
  ### settings
@@ -363,7 +408,7 @@ const data = await vigor
363
408
 
364
409
  ## `vigor.all`
365
410
 
366
- Runs a fixed list of zero-argument tasks with bounded concurrency.
411
+ Runs a fixed list of zero-argument tasks with bounded concurrency, `Promise.allSettled`-style — an individual task failing never makes the whole batch throw by itself.
367
412
 
368
413
  ### Methods
369
414
 
@@ -371,7 +416,8 @@ Runs a fixed list of zero-argument tasks with bounded concurrency.
371
416
  |---|---|
372
417
  | `target(...funcs)` | Sets the task list — each is `() => unknown \| Promise<unknown>` |
373
418
  | `settings(fn \| config)` | Concurrency settings (below) |
374
- | `middlewares(fn \| config)` | Per-task hooks (below) |
419
+ | `middlewares(fn \| config)` | Batch-level and per-task hooks (below) |
420
+ | `cast<T>()` | Overrides the inferred result type with `T` |
375
421
  | `request()` / `requestVerbose()` | Executes |
376
422
 
377
423
  ```ts
@@ -390,43 +436,71 @@ const results = await vigor
390
436
  | Method | Description | Default |
391
437
  |---|---|---|
392
438
  | `concurrency(num)` | Max number of tasks running at once | `5` |
393
- | `onlySuccess(bool)` | When `true`, filters the final array down to only tasks whose middleware chain resolved successfully | `false` |
439
+ | `onlySuccess(bool)` | When `true`, filters the final array down to only tasks whose result wasn't recovered as a failure | `false` |
394
440
 
395
- > Unlike `vigor.retry`/`vigor.fetch`/`vigor.parse`, `vigor.all` has no `default`/fallback setting, and per-task failures don't throw the whole call by themselves — a task that fails (and whose `onError` middleware doesn't call `setResult`) simply contributes its error value into the results array (or is dropped, if `onlySuccess` is on). The only thing that makes `.request()` throw is an **empty** task list.
441
+ > Unlike `vigor.retry`/`vigor.fetch`/`vigor.parse`, `vigor.all` has no `default`/fallback setting and no batch-level `onError` — the only thing that makes `.request()` throw is an **empty** task list (`EMPTY_TARGET`). Per-task failures are handled by `onErrorEach` (below) instead.
442
+
443
+ **Result typing:** when `onlySuccess` is `false` (the default) and `target(...)` is given as literal task functions, the result is inferred as a **tuple** matching each task's own return type — `.target(() => 1 as const, () => "a")` infers `[1, "a"]`, not `unknown[]`. Setting `onlySuccess(true)` filters the array at runtime to an arbitrary length, so the type falls back to a plain array. `.cast<T>()` overrides either case.
396
444
 
397
445
  ### hooks (`middlewares`)
398
446
 
399
- Unlike the other modules, `all`'s per-task hooks are plain functions — there's no `"fluent"`/`"intercept"` mode split.
447
+ `all` has **two tiers** of hooks: batch-level stages (run once for the whole call, support `"fluent"`/`"intercept"` modes like the other modules) and per-task stages (run once per task, plain callbacks with no mode argument).
400
448
 
401
- | Stage | Signature | Runs |
402
- |---|---|---|
403
- | `before(fn)` | `(ctx) => void \| Promise<void>` | Before each task is invoked |
404
- | `after(fn)` | `(ctx) => void \| Promise<void>` | After a task settles successfully |
405
- | `onError(fn)` | `(ctx, { setResult }) => void \| Promise<void>` | When an individual task throws |
449
+ | Stage | Level | Runs | API |
450
+ |---|---|---|---|
451
+ | `before(type, fn)` | Batch | Once, before any task starts | `throwError` (intercept mode) |
452
+ | `after(type, fn)` | Batch | Once, after every task has settled | `setResult`, `throwError` (intercept mode) |
453
+ | `onResult(type, fn)` | Batch | Once, right before returning the final result | `setResult`, `throwError` (intercept mode) |
454
+ | `beforeEach(fn)` | Per-task | Before each individual task is invoked | — |
455
+ | `afterEach(fn)` | Per-task | After a task settles successfully | — |
456
+ | `onErrorEach(fn)` | Per-task | When an individual task throws | `setResult` |
406
457
 
407
458
  ```ts
408
459
  .middlewares(m => m
409
- .onError(async (ctx, api) => {
460
+ .before("fluent", (ctx) => { console.log("starting batch"); })
461
+ .onResult("intercept", async (ctx, api) => {
462
+ if (ctx.result.length === 0) api.throwError(new Error("nothing succeeded"));
463
+ return ctx;
464
+ })
465
+ .onErrorEach(async (ctx, api) => {
410
466
  console.error(ctx.error);
411
467
  api.setResult(null); // recover instead of letting this task register as failed
412
468
  })
413
469
  )
414
470
  ```
415
471
 
472
+ Batch-level fluent signatures: `before`/`after` take `(ctx) => void`, `onResult` takes `(res) => newRes`. Per-task hooks (`beforeEach`, `afterEach`, `onErrorEach`) are always plain functions — there's no fluent/intercept split for these, since they observe/mutate a single task's context rather than the pipeline's control flow.
473
+
416
474
  ---
417
475
 
418
476
  ## Plugins
419
477
 
420
478
  ```ts
421
- export type VigorPlugin<O> = {
422
- options: O // type-only anchor for inferring O — not used at runtime
423
- func: (v: typeof vigor, options: O) => void
479
+ export type VigorPlugin<
480
+ O extends Record<string, any> = {},
481
+ Ext extends Record<string, any> = Record<string, any>
482
+ > = {
483
+ options: O
484
+ func: (v: VigorInstance, options: O) => Ext
424
485
  }
425
486
 
426
487
  vigor.use(plugin, options?)
427
488
  ```
428
489
 
429
- `vigor.use(plugin, options)` simply invokes `plugin.func(vigor, options)` — a lightweight hook for setup-time side effects (e.g. registering shared config, wiring up logging) rather than a full plugin/extension system.
490
+ `plugin.func` receives the current `vigor` instance (read-only — plugins never mutate it, e.g. they might read it to wrap an existing method) and returns `Ext`, a set of properties to merge in. `vigor.use()` shallow-clones `vigor` (including its nested `builders` groups) and merges `Ext` on top, returning a **new** instance — `VigorInstance & Ext` — leaving the original `vigor` untouched.
491
+
492
+ ```ts
493
+ const loggingPlugin: VigorPlugin<{ prefix?: string }> = {
494
+ options: {},
495
+ func: (v, options) => ({
496
+ fetch: (origin?: string) => v.fetch(origin).middlewares(m => m
497
+ .before("fluent", (ctx) => console.log(options.prefix ?? "[vigor]", ctx.href))
498
+ ),
499
+ }),
500
+ };
501
+
502
+ const myVigor = vigor.use(loggingPlugin, { prefix: "[api]" });
503
+ ```
430
504
 
431
505
  ---
432
506
 
@@ -468,4 +542,5 @@ if (!res.success) {
468
542
 
469
543
  - Every builder is **immutable** — `.settings(...)`, `.path(...)`, etc. all return a *new* instance with the change merged in; the original is untouched.
470
544
  - Array-valued config (`path`, `query`, parse `strategies`, etc.) **concatenates** across calls by default; object-valued config deep-merges. A handful of methods (`hash`, `headers("overwrite", ...)`, `body("overwrite", ...)`, `options("overwrite", ...)`, `retry(...)`, `parse(...)`, `algorithms(...)`) force a full **replace** instead, since merging wouldn't make sense there.
471
- - Config shape is tracked through the whole chain via TypeScript generics, so `.settings()`/`.middlewares()` callbacks and `.request()`'s inferred return type stay accurate as you chain.
545
+ - Config shape is tracked through the whole chain via TypeScript generics, so `.settings()`/`.middlewares()` callbacks and `.request()`'s inferred return type stay accurate as you chain.
546
+ - `.cast<T>()` is available on every module (`fetch`, `retry`, `parse`, `all`) and always wins over the naturally-inferred type, regardless of where in the chain it's called.
package/dist/index.cjs CHANGED
@@ -176,7 +176,10 @@ var VigorAllPolicyMiddlewaresBase = {
176
176
  __brand: createBrand("All", "Policy<Middlewares<Schema"),
177
177
  before: [],
178
178
  after: [],
179
- onError: []
179
+ onResult: [],
180
+ beforeEach: [],
181
+ afterEach: [],
182
+ onErrorEach: []
180
183
  };
181
184
  var VigorAllPolicyMiddlewares = class _VigorAllPolicyMiddlewares extends VigorStatus {
182
185
  constructor(config = VigorAllBase) {
@@ -185,17 +188,26 @@ var VigorAllPolicyMiddlewares = class _VigorAllPolicyMiddlewares extends VigorSt
185
188
  _create(config) {
186
189
  return new _VigorAllPolicyMiddlewares(config);
187
190
  }
191
+ before(type, func) {
192
+ return this._next({ policy: { middlewares: { before: [{ _mode: type, func }] } } });
193
+ }
194
+ after(type, func) {
195
+ return this._next({ policy: { middlewares: { after: [{ _mode: type, func }] } } });
196
+ }
197
+ onResult(type, func) {
198
+ return this._next({ policy: { middlewares: { onResult: [{ _mode: type, func }] } } });
199
+ }
188
200
  /** Registers a middleware that runs before each task is invoked. */
189
- before(func) {
190
- return this._next({ policy: { middlewares: { before: [func] } } });
201
+ beforeEach(func) {
202
+ return this._next({ policy: { middlewares: { beforeEach: [func] } } });
191
203
  }
192
204
  /** Registers a middleware that runs after each task settles successfully. */
193
- after(func) {
194
- return this._next({ policy: { middlewares: { after: [func] } } });
205
+ afterEach(func) {
206
+ return this._next({ policy: { middlewares: { afterEach: [func] } } });
195
207
  }
196
208
  /** Registers a middleware that runs when an individual task fails. */
197
- onError(func) {
198
- return this._next({ policy: { middlewares: { onError: [func] } } });
209
+ onErrorEach(func) {
210
+ return this._next({ policy: { middlewares: { onErrorEach: [func] } } });
199
211
  }
200
212
  };
201
213
 
@@ -280,7 +292,6 @@ var VigorAll = class _VigorAll extends VigorStatus {
280
292
  target(...funcs) {
281
293
  return this._next({ policy: { target: funcs } });
282
294
  }
283
- /** Configures the all-policy's general settings (concurrency, onlySuccess). */
284
295
  settings(input) {
285
296
  if (typeof input === "function" || input instanceof VigorAllPolicySettings) {
286
297
  const result = typeof input === "function" ? input(new VigorAllPolicySettings()) : input;
@@ -290,7 +301,6 @@ var VigorAll = class _VigorAll extends VigorStatus {
290
301
  }
291
302
  return this._next({ policy: { settings: input } });
292
303
  }
293
- /** Configures the all-policy's per-task middleware pipeline. */
294
304
  middlewares(input) {
295
305
  if (typeof input === "function" || input instanceof VigorAllPolicyMiddlewares) {
296
306
  const result = typeof input === "function" ? input(new VigorAllPolicyMiddlewares()) : input;
@@ -300,13 +310,13 @@ var VigorAll = class _VigorAll extends VigorStatus {
300
310
  }
301
311
  return this._next({ policy: { middlewares: input } });
302
312
  }
303
- /** Runs a single task through the before/after/onError middleware pipeline. */
313
+ /** Runs a single task through the beforeEach/afterEach/onErrorEach middleware pipeline. */
304
314
  async _runTask(task, policy) {
305
315
  let ctx = { ...VigorAllEachContextBase };
306
316
  try {
307
- for (const before of policy.middlewares.before) await before(ctx);
317
+ for (const beforeEach of policy.middlewares.beforeEach) await beforeEach(ctx);
308
318
  ctx.result = await task();
309
- for (const after of policy.middlewares.after) await after(ctx);
319
+ for (const afterEach of policy.middlewares.afterEach) await afterEach(ctx);
310
320
  return { success: true, value: ctx.result };
311
321
  } catch (error) {
312
322
  ctx.error = error;
@@ -314,7 +324,7 @@ var VigorAll = class _VigorAll extends VigorStatus {
314
324
  ctx.flags.overrided = true;
315
325
  ctx.result = r;
316
326
  };
317
- for (const onError of policy.middlewares.onError) await onError(ctx, { setResult });
327
+ for (const onErrorEach of policy.middlewares.onErrorEach) await onErrorEach(ctx, { setResult });
318
328
  if (ctx.flags.overrided) return { success: true, value: ctx.result };
319
329
  return { success: false, value: error };
320
330
  }
@@ -341,15 +351,29 @@ var VigorAll = class _VigorAll extends VigorStatus {
341
351
  async requestVerbose() {
342
352
  return await this.requestRuntime();
343
353
  }
344
- /** Internal execution loop implementing the bounded-concurrency worker pool. */
354
+ /** Internal execution loop implementing the bounded-concurrency worker pool and the batch-level before/after/onResult pipeline. */
345
355
  async requestRuntime(restartAttempt = 1) {
346
356
  const config = this._merge(this.config, {});
347
357
  const policy = config.policy;
358
+ let ctx = { ...VigorAllContextBase, policy };
359
+ const setResult = (r) => {
360
+ ctx = { ...ctx, result: r };
361
+ };
362
+ const throwError = (err) => {
363
+ throw err;
364
+ };
348
365
  try {
349
366
  if (policy.target.length === 0) throw new VigorAllError("EMPTY_TARGET", {
350
367
  method: "request",
351
368
  data: {}
352
369
  });
370
+ for (const mw of policy.middlewares.before) {
371
+ if (mw._mode === "fluent") {
372
+ await mw.func(ctx);
373
+ } else {
374
+ ctx = await mw.func(ctx, { throwError });
375
+ }
376
+ }
353
377
  const concurrency = Math.max(1, policy.settings.concurrency);
354
378
  const results = new Array(policy.target.length);
355
379
  let cursor = 0;
@@ -363,10 +387,24 @@ var VigorAll = class _VigorAll extends VigorStatus {
363
387
  await Promise.all(
364
388
  Array.from({ length: Math.min(concurrency, policy.target.length) }, () => worker())
365
389
  );
366
- const result = policy.settings.onlySuccess ? results.filter((r) => r.success).map((r) => r.value) : results.map((r) => r.value);
390
+ ctx.result = policy.settings.onlySuccess ? results.filter((r) => r.success).map((r) => r.value) : results.map((r) => r.value);
391
+ for (const mw of policy.middlewares.after) {
392
+ if (mw._mode === "fluent") {
393
+ await mw.func(ctx);
394
+ } else {
395
+ ctx = await mw.func(ctx, { setResult, throwError });
396
+ }
397
+ }
398
+ for (const mw of policy.middlewares.onResult) {
399
+ if (mw._mode === "fluent") {
400
+ ctx.result = await mw.func(ctx.result);
401
+ } else {
402
+ ctx = await mw.func(ctx, { setResult, throwError });
403
+ }
404
+ }
367
405
  return {
368
406
  success: true,
369
- data: result,
407
+ data: ctx.result,
370
408
  error: null
371
409
  };
372
410
  } catch (error) {
@@ -824,7 +862,6 @@ var VigorRetry = class _VigorRetry extends VigorStatus {
824
862
  policy: { abortSignals: sig }
825
863
  });
826
864
  }
827
- /** Configures the retry policy's general settings (max attempts, timeout, etc). */
828
865
  settings(input) {
829
866
  if (typeof input === "function" || input instanceof VigorRetryPolicySettings) {
830
867
  const result = typeof input === "function" ? input(new VigorRetryPolicySettings()) : input;
@@ -836,7 +873,6 @@ var VigorRetry = class _VigorRetry extends VigorStatus {
836
873
  policy: { settings: input }
837
874
  });
838
875
  }
839
- /** Configures the retry policy's middleware pipeline. */
840
876
  middlewares(input) {
841
877
  if (typeof input === "function" || input instanceof VigorRetryPolicyMiddlewares) {
842
878
  const result = typeof input === "function" ? input(new VigorRetryPolicyMiddlewares()) : input;
@@ -848,7 +884,6 @@ var VigorRetry = class _VigorRetry extends VigorStatus {
848
884
  policy: { middlewares: input }
849
885
  });
850
886
  }
851
- /** Configures the retry policy's delay algorithm. */
852
887
  algorithms(input) {
853
888
  if (typeof input === "function") {
854
889
  const result = input(new VigorRetryPolicyAlgorithms());
@@ -1313,7 +1348,6 @@ var VigorParse = class _VigorParse extends VigorStatus {
1313
1348
  target(response) {
1314
1349
  return this._next({ policy: { target: response } });
1315
1350
  }
1316
- /** Configures the parse policy's general settings. */
1317
1351
  settings(input) {
1318
1352
  if (typeof input === "function" || input instanceof VigorParsePolicySettings) {
1319
1353
  const result = typeof input === "function" ? input(new VigorParsePolicySettings()) : input;
@@ -1323,7 +1357,6 @@ var VigorParse = class _VigorParse extends VigorStatus {
1323
1357
  }
1324
1358
  return this._next({ policy: { settings: input } });
1325
1359
  }
1326
- /** Configures the parse policy's middleware pipeline. */
1327
1360
  middlewares(input) {
1328
1361
  if (typeof input === "function" || input instanceof VigorParsePolicyMiddlewares) {
1329
1362
  const result = typeof input === "function" ? input(new VigorParsePolicyMiddlewares()) : input;
@@ -1333,7 +1366,6 @@ var VigorParse = class _VigorParse extends VigorStatus {
1333
1366
  }
1334
1367
  return this._next({ policy: { middlewares: input } });
1335
1368
  }
1336
- /** Configures the parse policy's fallback chain of parsing strategies. */
1337
1369
  strategies(input) {
1338
1370
  if (typeof input === "function" || input instanceof VigorParsePolicyStrategies) {
1339
1371
  const result = typeof input === "function" ? input(new VigorParsePolicyStrategies()) : input;
@@ -1389,10 +1421,10 @@ var VigorParse = class _VigorParse extends VigorStatus {
1389
1421
  ctx = await middleware.func(ctx, { throwError });
1390
1422
  }
1391
1423
  }
1392
- const response = ctx.response;
1393
1424
  if (ctx.policy.settings.raw) {
1394
- ctx.result = response;
1425
+ ctx.result = ctx.response;
1395
1426
  } else {
1427
+ const response = ctx.response;
1396
1428
  const funcs = ctx.policy.strategies.funcs.length > 0 ? ctx.policy.strategies.funcs : [VigorParseContentTypeStrategy];
1397
1429
  let parsed = false;
1398
1430
  for (const [i, func] of funcs.entries()) {
@@ -1508,7 +1540,7 @@ var VigorFetchContextBase = {
1508
1540
  error: VigorDefault,
1509
1541
  options: VigorDefault,
1510
1542
  flags: {
1511
- overrided: false,
1543
+ overridden: false,
1512
1544
  restarted: false
1513
1545
  },
1514
1546
  record: {},
@@ -1605,7 +1637,6 @@ var VigorFetch = class _VigorFetch extends VigorStatus {
1605
1637
  if (mode === "overwrite") return this._next({ policy: { extra: obj } }, { policy: { extra: "replace" } });
1606
1638
  return this._next({ policy: { extra: obj } });
1607
1639
  }
1608
- /** Configures the fetch policy's general settings. */
1609
1640
  settings(input) {
1610
1641
  if (typeof input === "function" || input instanceof VigorFetchPolicySettings) {
1611
1642
  const result = typeof input === "function" ? input(new VigorFetchPolicySettings()) : input;
@@ -1615,7 +1646,6 @@ var VigorFetch = class _VigorFetch extends VigorStatus {
1615
1646
  }
1616
1647
  return this._next({ policy: { settings: input } });
1617
1648
  }
1618
- /** Configures the fetch policy's middleware pipeline. */
1619
1649
  middlewares(input) {
1620
1650
  if (typeof input === "function" || input instanceof VigorFetchPolicyMiddlewares) {
1621
1651
  const result = typeof input === "function" ? input(new VigorFetchPolicyMiddlewares()) : input;
@@ -1625,7 +1655,6 @@ var VigorFetch = class _VigorFetch extends VigorStatus {
1625
1655
  }
1626
1656
  return this._next({ policy: { middlewares: input } });
1627
1657
  }
1628
- /** Configures the retry engine used to send the underlying request. */
1629
1658
  retry(input) {
1630
1659
  if (typeof input === "function" || input instanceof VigorRetry) {
1631
1660
  const result = typeof input === "function" ? input(new VigorRetry()) : input;
@@ -1633,7 +1662,6 @@ var VigorFetch = class _VigorFetch extends VigorStatus {
1633
1662
  }
1634
1663
  return this._next({ policy: { retry: input } }, { policy: { retry: "replace" } });
1635
1664
  }
1636
- /** Configures the parse engine used to interpret the response. */
1637
1665
  parse(input) {
1638
1666
  if (typeof input === "function" || input instanceof VigorParse) {
1639
1667
  const result = typeof input === "function" ? input(new VigorParse()) : input;
@@ -1853,10 +1881,10 @@ var VigorFetch = class _VigorFetch extends VigorStatus {
1853
1881
  };
1854
1882
  } catch (error) {
1855
1883
  ctx.error = error;
1856
- ctx.flags.overrided = false;
1884
+ ctx.flags.overridden = false;
1857
1885
  ctx.flags.restarted = false;
1858
1886
  const setResult = (r) => {
1859
- ctx.flags.overrided = true;
1887
+ ctx.flags.overridden = true;
1860
1888
  ctx.result = r;
1861
1889
  };
1862
1890
  const proceedRestart = () => ctx.flags.restarted = true;
@@ -1879,7 +1907,7 @@ var VigorFetch = class _VigorFetch extends VigorStatus {
1879
1907
  });
1880
1908
  return await this.requestRuntime(restartAttempt + 1);
1881
1909
  }
1882
- if (ctx.flags.overrided) return {
1910
+ if (ctx.flags.overridden) return {
1883
1911
  success: true,
1884
1912
  data: ctx.result,
1885
1913
  error: null