vigor-fetch 4.0.8 → 4.0.10

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.cts CHANGED
@@ -15,6 +15,7 @@ declare const VigorDefault: symbol & {
15
15
  __brand: VigorBrand<"Core", "Symbol_Default">;
16
16
  };
17
17
  type VigorDefaultType = typeof VigorDefault;
18
+ type VigorExcludeDefault<T> = Exclude<T, VigorDefaultType>;
18
19
  declare const VigorEmpty: symbol & {
19
20
  __brand: VigorBrand<"Core", "Symbol_Empty">;
20
21
  };
@@ -133,6 +134,16 @@ declare class VigorAllPolicySettings<T extends VigorAllSchema<T> = typeof VigorA
133
134
  }
134
135
 
135
136
  type VigorAllTask = () => unknown | Promise<unknown>;
137
+ /** Extracts (and unwraps `Promise`/`Awaited`) the result type of a single task. */
138
+ type VigorAllTaskResult<F> = F extends () => infer R ? Awaited<R> : never;
139
+ /**
140
+ * Maps a tuple of tasks to a tuple of their (awaited) result types, in the
141
+ * same order and length as `N`. If `N` isn't a literal tuple (e.g. the
142
+ * default, unconfigured `target`), this degrades to a plain array type.
143
+ */
144
+ type VigorAllTasksTuple<N extends readonly VigorAllTask[]> = {
145
+ [K in keyof N]: VigorAllTaskResult<N[K]>;
146
+ };
136
147
  type VigorAllPolicySchema<T extends VigorAllSchema<T>> = {
137
148
  __brand: VigorBrand<"All", "Policy<Schema">;
138
149
  target: VigorAllTask[];
@@ -141,7 +152,7 @@ type VigorAllPolicySchema<T extends VigorAllSchema<T>> = {
141
152
  };
142
153
  declare const VigorAllPolicyBase: {
143
154
  readonly __brand: VigorBrand<"All", "Policy<Schema">;
144
- readonly target: VigorAllTask[];
155
+ readonly target: [];
145
156
  readonly settings: {
146
157
  readonly __brand: VigorBrand<"All", "Policy<Settings<Schema">;
147
158
  readonly concurrency: 5;
@@ -149,73 +160,239 @@ declare const VigorAllPolicyBase: {
149
160
  };
150
161
  readonly middlewares: {
151
162
  readonly __brand: VigorBrand<"All", "Policy<Middlewares<Schema">;
152
- readonly before: VigorAllEachMiddlewareFn[];
153
- readonly after: VigorAllEachMiddlewareFn[];
154
- readonly onError: VigorAllEachOnErrorFn[];
155
- };
156
- };
157
-
158
- type VigorAllContextSchema<T extends VigorAllSchema<T>> = {
159
- __brand: VigorBrand<"All", "Context<Schema">;
160
- result: unknown[] | VigorDefaultType;
161
- policy: T["policy"];
162
- record: Record<string, any>;
163
- };
164
- type VigorAllEachContextSchema<T extends VigorAllSchema<T>> = {
165
- __brand: VigorBrand<"All", "EachContext<Schema">;
166
- result: unknown | VigorDefaultType;
167
- error: unknown;
168
- flags: {
169
- overrided: boolean;
163
+ readonly before: [];
164
+ readonly after: [];
165
+ readonly onResult: [];
166
+ readonly beforeEach: [];
167
+ readonly afterEach: [];
168
+ readonly onErrorEach: [];
170
169
  };
171
- record: Record<string, any>;
172
170
  };
171
+ /**
172
+ * The naturally-inferred (pre-`.cast<T>()`) result type of `.request()`.
173
+ * When `onlySuccess` is left `false` (the default), every task's result
174
+ * lands at its own tuple slot — `.target(() => 1 as const, () => "a")`
175
+ * infers `[1, "a"]`, not `unknown[]`. `onlySuccess: true` filters the
176
+ * array at runtime to an arbitrary length, so it falls back to a plain
177
+ * array type instead of a tuple.
178
+ */
179
+ type VigorAllNaturalResult<T extends VigorAllSchema<T>> = T["policy"]["settings"]["onlySuccess"] extends true ? unknown[] : T["policy"]["target"] extends readonly VigorAllTask[] ? VigorAllTasksTuple<T["policy"]["target"]> : unknown[];
173
180
 
181
+ /** Per-task hook (`beforeEach` / `afterEach`) — observes/mutates a single task's context, no return value. */
174
182
  type VigorAllEachMiddlewareFn = (ctx: VigorAllEachContextSchema<any>) => void | Promise<void>;
183
+ /** Per-task failure hook (`onErrorEach`) — can override the task's outcome via `api.setResult`. */
175
184
  type VigorAllEachOnErrorFn = (ctx: VigorAllEachContextSchema<any>, api: {
176
185
  setResult: (r: unknown) => void;
177
186
  }) => void | Promise<void>;
178
187
  type VigorAllPolicyMiddlewaresSchema<T extends VigorAllSchema<T>> = {
179
188
  __brand: VigorBrand<"All", "Policy<Middlewares<Schema">;
180
- before: VigorAllEachMiddlewareFn[];
181
- after: VigorAllEachMiddlewareFn[];
182
- onError: VigorAllEachOnErrorFn[];
189
+ /** Batch-level: runs once before any task starts. */
190
+ before: (VigorAllPolicyMiddlewaresFluent<T>["before"] | VigorAllPolicyMiddlewaresIntercept<T>["before"])[];
191
+ /** Batch-level: runs once after every task has settled. */
192
+ after: (VigorAllPolicyMiddlewaresFluent<T>["after"] | VigorAllPolicyMiddlewaresIntercept<T>["after"])[];
193
+ /** Batch-level: transforms/validates the aggregate result. */
194
+ onResult: (VigorAllPolicyMiddlewaresFluent<T>["onResult"] | VigorAllPolicyMiddlewaresIntercept<T>["onResult"])[];
195
+ /** Per-task: runs before each individual task is invoked. */
196
+ beforeEach: VigorAllEachMiddlewareFn[];
197
+ /** Per-task: runs after each individual task settles successfully. */
198
+ afterEach: VigorAllEachMiddlewareFn[];
199
+ /** Per-task: runs when an individual task fails. */
200
+ onErrorEach: VigorAllEachOnErrorFn[];
183
201
  };
184
202
  declare const VigorAllPolicyMiddlewaresBase: {
185
203
  readonly __brand: VigorBrand<"All", "Policy<Middlewares<Schema">;
186
- readonly before: VigorAllEachMiddlewareFn[];
187
- readonly after: VigorAllEachMiddlewareFn[];
188
- readonly onError: VigorAllEachOnErrorFn[];
204
+ readonly before: [];
205
+ readonly after: [];
206
+ readonly onResult: [];
207
+ readonly beforeEach: [];
208
+ readonly afterEach: [];
209
+ readonly onErrorEach: [];
210
+ };
211
+ type VigorAllPolicyMiddlewaresFluent<T extends VigorAllSchema<T>> = {
212
+ __brand: VigorBrand<"All", "Policy<Middlewares<Fluent<Schema">;
213
+ before: {
214
+ _mode: "fluent";
215
+ func: (ctx: VigorAllBeforeContextSchema<T>) => void | Promise<void>;
216
+ };
217
+ after: {
218
+ _mode: "fluent";
219
+ func: (ctx: VigorAllAfterContextSchema<T>) => void | Promise<void>;
220
+ };
221
+ onResult: {
222
+ _mode: "fluent";
223
+ func: (res: VigorAllOnResultContextSchema<T> extends {
224
+ result: infer R;
225
+ } ? R : never) => VigorAllContextSchema<any>["result"] | Promise<VigorAllContextSchema<any>["result"]>;
226
+ };
227
+ };
228
+ type VigorAllPolicyMiddlewaresApi<T extends VigorAllSchema<T>> = {
229
+ setResult: (res: VigorAllContextSchema<any>["result"]) => void;
230
+ throwError: (err: unknown) => void;
231
+ };
232
+ type VigorAllPolicyMiddlewaresIntercept<T extends VigorAllSchema<T>> = {
233
+ __brand: VigorBrand<"All", "Policy<Middlewares<Intercept<Schema">;
234
+ before: {
235
+ _mode: "intercept";
236
+ func: (ctx: VigorAllBeforeContextSchema<T>, api: Pick<VigorAllPolicyMiddlewaresApi<T>, "throwError">) => VigorAllContextSchema<any> | Promise<VigorAllContextSchema<any>>;
237
+ };
238
+ after: {
239
+ _mode: "intercept";
240
+ func: (ctx: VigorAllAfterContextSchema<T>, api: Pick<VigorAllPolicyMiddlewaresApi<T>, "setResult" | "throwError">) => VigorAllContextSchema<any> | Promise<VigorAllContextSchema<any>>;
241
+ };
242
+ onResult: {
243
+ _mode: "intercept";
244
+ func: (ctx: VigorAllOnResultContextSchema<T>, api: Pick<VigorAllPolicyMiddlewaresApi<T>, "setResult" | "throwError">) => VigorAllContextSchema<any> | Promise<VigorAllContextSchema<any>>;
245
+ };
189
246
  };
190
- /** Immutable builder for an all-policy's per-task middleware pipeline (`before`, `after`, `onError`). */
247
+ /**
248
+ * Immutable builder for an all-policy's middleware pipeline. Batch-level
249
+ * stages (`before`, `after`, `onResult`) run once for the whole request and
250
+ * accept either "fluent" middleware (returns a plain value merged into the
251
+ * context) or "intercept" middleware (receives an explicit API to mutate
252
+ * control flow). Per-task stages (`beforeEach`, `afterEach`, `onErrorEach`)
253
+ * run once per task and are plain observer/mutator callbacks — there's no
254
+ * batch-level `onError`, since the batch runs its tasks `allSettled`-style
255
+ * and never fails because an individual task did.
256
+ */
191
257
  declare class VigorAllPolicyMiddlewares<T extends VigorAllSchema<T> = typeof VigorAllBase> extends VigorStatus<VigorAllSchema<any>, T, VigorAllPolicyMiddlewaresTypeLambda> {
192
258
  constructor(config?: T);
193
259
  protected _create<C>(config: C): VigorApply<VigorAllPolicyMiddlewaresTypeLambda, C>;
260
+ /** Registers a middleware that runs once before any task starts. */
261
+ before<const N extends VigorAllPolicyMiddlewaresFluent<T>["before"]["func"]>(type: "fluent", func: N): VigorApply<VigorAllPolicyMiddlewaresTypeLambda, VigorDeepMerge<T, {
262
+ policy: {
263
+ middlewares: {
264
+ before: [{
265
+ _mode: "fluent";
266
+ func: N;
267
+ }];
268
+ };
269
+ };
270
+ }>>;
271
+ before<const N extends VigorAllPolicyMiddlewaresIntercept<T>["before"]["func"]>(type: "intercept", func: N): VigorApply<VigorAllPolicyMiddlewaresTypeLambda, VigorDeepMerge<T, {
272
+ policy: {
273
+ middlewares: {
274
+ before: [{
275
+ _mode: "intercept";
276
+ func: N;
277
+ }];
278
+ };
279
+ };
280
+ }>>;
281
+ /** Registers a middleware that runs once after every task has settled. */
282
+ after<const N extends VigorAllPolicyMiddlewaresFluent<T>["after"]["func"]>(type: "fluent", func: N): VigorApply<VigorAllPolicyMiddlewaresTypeLambda, VigorDeepMerge<T, {
283
+ policy: {
284
+ middlewares: {
285
+ after: [{
286
+ _mode: "fluent";
287
+ func: N;
288
+ }];
289
+ };
290
+ };
291
+ }>>;
292
+ after<const N extends VigorAllPolicyMiddlewaresIntercept<T>["after"]["func"]>(type: "intercept", func: N): VigorApply<VigorAllPolicyMiddlewaresTypeLambda, VigorDeepMerge<T, {
293
+ policy: {
294
+ middlewares: {
295
+ after: [{
296
+ _mode: "intercept";
297
+ func: N;
298
+ }];
299
+ };
300
+ };
301
+ }>>;
302
+ /** Registers a middleware that transforms or validates the aggregate result. */
303
+ onResult<const N extends VigorAllPolicyMiddlewaresFluent<T>["onResult"]["func"]>(type: "fluent", func: N): VigorApply<VigorAllPolicyMiddlewaresTypeLambda, VigorDeepMerge<T, {
304
+ policy: {
305
+ middlewares: {
306
+ onResult: [{
307
+ _mode: "fluent";
308
+ func: N;
309
+ }];
310
+ };
311
+ };
312
+ }>>;
313
+ onResult<const N extends VigorAllPolicyMiddlewaresIntercept<T>["onResult"]["func"]>(type: "intercept", func: N): VigorApply<VigorAllPolicyMiddlewaresTypeLambda, VigorDeepMerge<T, {
314
+ policy: {
315
+ middlewares: {
316
+ onResult: [{
317
+ _mode: "intercept";
318
+ func: N;
319
+ }];
320
+ };
321
+ };
322
+ }>>;
194
323
  /** Registers a middleware that runs before each task is invoked. */
195
- before<const N extends VigorAllEachMiddlewareFn>(func: N): VigorAllPolicyMiddlewares<VigorAllIn<VigorDeepMerge<T, {
324
+ beforeEach<const N extends VigorAllEachMiddlewareFn>(func: N): VigorAllPolicyMiddlewares<VigorAllIn<VigorDeepMerge<T, {
196
325
  readonly policy: {
197
326
  readonly middlewares: {
198
- readonly before: readonly [N];
327
+ readonly beforeEach: readonly [N];
199
328
  };
200
329
  };
201
330
  }>>>;
202
331
  /** Registers a middleware that runs after each task settles successfully. */
203
- after<const N extends VigorAllEachMiddlewareFn>(func: N): VigorAllPolicyMiddlewares<VigorAllIn<VigorDeepMerge<T, {
332
+ afterEach<const N extends VigorAllEachMiddlewareFn>(func: N): VigorAllPolicyMiddlewares<VigorAllIn<VigorDeepMerge<T, {
204
333
  readonly policy: {
205
334
  readonly middlewares: {
206
- readonly after: readonly [N];
335
+ readonly afterEach: readonly [N];
207
336
  };
208
337
  };
209
338
  }>>>;
210
339
  /** Registers a middleware that runs when an individual task fails. */
211
- onError<const N extends VigorAllEachOnErrorFn>(func: N): VigorAllPolicyMiddlewares<VigorAllIn<VigorDeepMerge<T, {
340
+ onErrorEach<const N extends VigorAllEachOnErrorFn>(func: N): VigorAllPolicyMiddlewares<VigorAllIn<VigorDeepMerge<T, {
212
341
  readonly policy: {
213
342
  readonly middlewares: {
214
- readonly onError: readonly [N];
343
+ readonly onErrorEach: readonly [N];
215
344
  };
216
345
  };
217
346
  }>>>;
218
347
  }
348
+ type VigorAllPipeInitialContext<T extends VigorAllSchema<T>, R = VigorCastResult<T["cast"], VigorAllNaturalResult<T>>> = VigorDeepMerge<Omit<VigorAllContextSchema<T, unknown>, "result">, {
349
+ result: R;
350
+ }>;
351
+ type VigorAllPipeStepVoid<Ctx, Arr> = Arr extends [infer Head, ...infer Tail] ? Head extends {
352
+ _mode: "intercept";
353
+ func: (...args: any[]) => infer Ret;
354
+ } ? VigorAllPipeStepVoid<Ret, Tail> : VigorAllPipeStepVoid<Ctx, Tail> : Ctx;
355
+ type VigorAllPipeStepResult<Ctx, Arr> = Arr extends [infer Head, ...infer Tail] ? Head extends {
356
+ _mode: "intercept";
357
+ func: (...args: any[]) => infer Ret;
358
+ } ? VigorAllPipeStepResult<Ret, Tail> : Head extends {
359
+ _mode: "fluent";
360
+ func: (...args: any[]) => infer FR;
361
+ } ? VigorAllPipeStepResult<VigorDeepMerge<Ctx, {
362
+ result: FR;
363
+ }>, Tail> : VigorAllPipeStepResult<Ctx, Tail> : Ctx;
364
+ type VigorAllPolicyMiddlewaresPipe<T extends VigorAllSchema<T>> = VigorAllPipeStepResult<VigorAllPipeStepVoid<VigorAllPipeStepVoid<VigorAllPipeInitialContext<T>, T["policy"]["middlewares"]["before"]>, T["policy"]["middlewares"]["after"]>, T["policy"]["middlewares"]["onResult"]>;
365
+ type VigorAllPipeResult<T extends VigorAllSchema<T>> = VigorAllPolicyMiddlewaresPipe<T> extends {
366
+ result: infer R;
367
+ } ? R : never;
368
+
369
+ /**
370
+ * Base shape shared by every batch-level `all` context variant. `R` is the
371
+ * type of `result` at the point the context is observed — computed per
372
+ * pipeline stage instead of being fixed on the schema.
373
+ */
374
+ type VigorAllContextSchema<T extends VigorAllSchema<T>, R = VigorAllPipeResult<T> | VigorDefaultType> = {
375
+ __brand: VigorBrand<"All", "Context<Schema">;
376
+ result: R;
377
+ policy: T["policy"];
378
+ record: Record<string, any>;
379
+ };
380
+ /** Context shape seen by `before` middlewares — no task has run yet. */
381
+ type VigorAllBeforeContextSchema<T extends VigorAllSchema<T>> = VigorAllContextSchema<T, VigorDefaultType>;
382
+ /** Context shape seen by `after` middlewares — every task has settled, reflecting whatever `before` changed. */
383
+ type VigorAllAfterContextSchema<T extends VigorAllSchema<T>> = VigorAllPipeStepVoid<VigorAllPipeInitialContext<T>, T["policy"]["middlewares"]["before"]>;
384
+ /** Context shape seen by `onResult` middlewares — additionally threads any `onResult` middlewares already registered earlier in the same chain, so `ctx.result` reflects what the previous `onResult` returned. */
385
+ type VigorAllOnResultContextSchema<T extends VigorAllSchema<T>> = VigorAllPipeStepResult<VigorAllPipeStepVoid<VigorAllAfterContextSchema<T>, T["policy"]["middlewares"]["after"]>, T["policy"]["middlewares"]["onResult"]>;
386
+ /** Per-task context, seen by `beforeEach` / `afterEach` / `onErrorEach`. */
387
+ type VigorAllEachContextSchema<T extends VigorAllSchema<T>> = {
388
+ __brand: VigorBrand<"All", "EachContext<Schema">;
389
+ result: unknown | VigorDefaultType;
390
+ error: unknown;
391
+ flags: {
392
+ overrided: boolean;
393
+ };
394
+ record: Record<string, any>;
395
+ };
219
396
 
220
397
  type VigorAllSchema<T extends VigorAllSchema<T>> = {
221
398
  __brand: VigorBrand<"All", "Schema">;
@@ -227,7 +404,7 @@ declare const VigorAllBase: {
227
404
  readonly __brand: VigorBrand<"All", "Schema">;
228
405
  readonly policy: {
229
406
  readonly __brand: VigorBrand<"All", "Policy<Schema">;
230
- readonly target: VigorAllTask[];
407
+ readonly target: [];
231
408
  readonly settings: {
232
409
  readonly __brand: VigorBrand<"All", "Policy<Settings<Schema">;
233
410
  readonly concurrency: 5;
@@ -235,9 +412,12 @@ declare const VigorAllBase: {
235
412
  };
236
413
  readonly middlewares: {
237
414
  readonly __brand: VigorBrand<"All", "Policy<Middlewares<Schema">;
238
- readonly before: VigorAllEachMiddlewareFn[];
239
- readonly after: VigorAllEachMiddlewareFn[];
240
- readonly onError: VigorAllEachOnErrorFn[];
415
+ readonly before: [];
416
+ readonly after: [];
417
+ readonly onResult: [];
418
+ readonly beforeEach: [];
419
+ readonly afterEach: [];
420
+ readonly onErrorEach: [];
241
421
  };
242
422
  };
243
423
  readonly cast: symbol & {
@@ -259,18 +439,38 @@ declare class VigorAll<T extends VigorAllSchema<T> = typeof VigorAllBase> extend
259
439
  };
260
440
  }>>>;
261
441
  /** Configures the all-policy's general settings (concurrency, onlySuccess). */
262
- settings<const N extends VigorDeepPartial<VigorAllPolicySettingsSchema<T>>, R extends VigorAllSchema<any>>(input: N | ((s: VigorAllPolicySettings<T>) => VigorAllPolicySettings<R>) | VigorAllPolicySettings<R>): VigorAll<VigorAllIn<VigorDeepMerge<T, {
263
- readonly policy: {
264
- readonly settings: VigorAllPolicySettingsSchema<any>;
442
+ settings<const N extends VigorDeepPartial<VigorAllPolicySettingsSchema<T>>>(input: N): VigorApply<VigorAllTypeLambda, VigorDeepMerge<T, {
443
+ policy: {
444
+ settings: N;
265
445
  };
266
- }>>>;
446
+ }>>;
447
+ settings<const R extends VigorAllSchema<any>>(input: (s: VigorAllPolicySettings<T>) => VigorAllPolicySettings<R>): VigorApply<VigorAllTypeLambda, VigorDeepMerge<T, {
448
+ policy: {
449
+ settings: R["policy"]["settings"];
450
+ };
451
+ }>>;
452
+ settings<const R extends VigorAllSchema<any>>(input: VigorAllPolicySettings<R>): VigorApply<VigorAllTypeLambda, VigorDeepMerge<T, {
453
+ policy: {
454
+ settings: R["policy"]["settings"];
455
+ };
456
+ }>>;
267
457
  /** Configures the all-policy's per-task middleware pipeline. */
268
- middlewares<const N extends VigorDeepPartial<VigorAllPolicyMiddlewaresSchema<T>>, R extends VigorAllSchema<any>>(input: N | ((s: VigorAllPolicyMiddlewares<T>) => VigorAllPolicyMiddlewares<R>) | VigorAllPolicyMiddlewares<R>): VigorAll<VigorAllIn<VigorDeepMerge<T, {
269
- readonly policy: {
270
- readonly middlewares: VigorAllPolicyMiddlewaresSchema<any>;
458
+ middlewares<const N extends VigorDeepPartial<VigorAllPolicyMiddlewaresSchema<T>>>(input: N): VigorApply<VigorAllTypeLambda, VigorDeepMerge<T, {
459
+ policy: {
460
+ middlewares: N;
271
461
  };
272
- }>>>;
273
- /** Runs a single task through the before/after/onError middleware pipeline. */
462
+ }>>;
463
+ middlewares<const R extends VigorAllSchema<any>>(input: (s: VigorAllPolicyMiddlewares<T>) => VigorAllPolicyMiddlewares<R>): VigorApply<VigorAllTypeLambda, VigorDeepMerge<T, {
464
+ policy: {
465
+ middlewares: R["policy"]["middlewares"];
466
+ };
467
+ }>>;
468
+ middlewares<const R extends VigorAllSchema<any>>(input: VigorAllPolicyMiddlewares<R>): VigorApply<VigorAllTypeLambda, VigorDeepMerge<T, {
469
+ policy: {
470
+ middlewares: R["policy"]["middlewares"];
471
+ };
472
+ }>>;
473
+ /** Runs a single task through the beforeEach/afterEach/onErrorEach middleware pipeline. */
274
474
  private _runTask;
275
475
  /**
276
476
  * Overrides the resolved result type with `T`, taking priority over the
@@ -282,9 +482,9 @@ declare class VigorAll<T extends VigorAllSchema<T> = typeof VigorAllBase> extend
282
482
  cast: C;
283
483
  }>>>;
284
484
  /** Runs all tasks and returns the results array directly, throwing on final failure. */
285
- request<R = VigorCastResult<T["cast"], unknown[]>>(): Promise<R>;
485
+ request<R = VigorExcludeDefault<VigorAllContextSchema<T>["result"]>>(): Promise<R>;
286
486
  /** Runs all tasks and returns a result/error envelope instead of throwing. */
287
- requestVerbose<R = VigorCastResult<T["cast"], unknown[]>>(): Promise<{
487
+ requestVerbose<R = VigorExcludeDefault<VigorAllContextSchema<T>["result"]>>(): Promise<{
288
488
  success: false;
289
489
  data: null;
290
490
  error: unknown;
@@ -293,7 +493,7 @@ declare class VigorAll<T extends VigorAllSchema<T> = typeof VigorAllBase> extend
293
493
  data: R;
294
494
  error: null;
295
495
  }>;
296
- /** Internal execution loop implementing the bounded-concurrency worker pool. */
496
+ /** Internal execution loop implementing the bounded-concurrency worker pool and the batch-level before/after/onResult pipeline. */
297
497
  private requestRuntime;
298
498
  }
299
499
 
@@ -308,91 +508,6 @@ interface VigorAllPolicyMiddlewaresTypeLambda extends VigorTypeLambda {
308
508
  readonly Target: VigorAllPolicyMiddlewares<VigorAllIn<this["In"]>>;
309
509
  }
310
510
 
311
- type VigorFetchExtraOptions = Omit<RequestInit, "method" | "headers" | "body" | "signal">;
312
- type VigorFetchOptions = VigorFetchExtraOptions & {
313
- method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS" | "CONNECT" | "TRACE";
314
- headers: Record<string, string>;
315
- body?: BodyInit | null;
316
- signal?: AbortSignal;
317
- };
318
- /**
319
- * Base shape shared by every fetch context variant. `R` is the type of
320
- * `result` at the point the context is observed — computed per pipeline
321
- * stage instead of being fixed on the schema.
322
- */
323
- type VigorFetchContextSchema<T extends VigorFetchSchema<T>, R = VigorCastResult<T["cast"], unknown> | VigorDefaultType> = {
324
- __brand: VigorBrand<"Fetch", "Context<Schema">;
325
- href: string;
326
- response: Response | VigorDefaultType;
327
- result: R;
328
- error: unknown;
329
- options: VigorFetchOptions | VigorDefaultType;
330
- flags: {
331
- overrided: boolean;
332
- restarted: boolean;
333
- };
334
- record: Record<string, any>;
335
- policy: T["policy"];
336
- };
337
- /** Context shape seen by `before` middlewares — the request hasn't been sent yet. */
338
- type VigorFetchBeforeContextSchema<T extends VigorFetchSchema<T>> = VigorFetchContextSchema<T, VigorDefaultType>;
339
- /** Context shape seen by `after` / `onResult` middlewares — a response has been received/parsed. */
340
- type VigorFetchAfterContextSchema<T extends VigorFetchSchema<T>> = VigorFetchContextSchema<T, VigorCastResult<T["cast"], unknown>>;
341
-
342
- type VigorFetchPolicySettingsSchema<T extends VigorFetchSchema<T>> = {
343
- __brand: VigorBrand<"Fetch", "Policy<Settings<Schema">;
344
- retryHeaders: string[];
345
- unretryStatus: number[];
346
- maxRestarts: number;
347
- default: ((ctx: VigorFetchContextSchema<T>) => any | Promise<any>) | VigorEmptyType;
348
- };
349
- declare const VigorFetchPolicySettingsBase: {
350
- readonly __brand: VigorBrand<"Fetch", "Policy<Settings<Schema">;
351
- readonly retryHeaders: ["retry-after", "ratelimit-reset", "x-ratelimit-reset", "x-retry-after", "x-amz-retry-after", "chrome-proxy-next-link"];
352
- readonly unretryStatus: [400, 401, 403, 404, 405, 413, 422];
353
- readonly maxRestarts: 3;
354
- readonly default: symbol & {
355
- __brand: VigorBrand<"Core", "Symbol_Empty">;
356
- };
357
- };
358
- /** Immutable builder for a fetch policy's general settings. */
359
- declare class VigorFetchPolicySettings<T extends VigorFetchSchema<T> = typeof VigorFetchBase> extends VigorStatus<VigorFetchSchema<any>, T, VigorFetchPolicySettingsTypeLambda> {
360
- constructor(config?: T);
361
- protected _create<C>(config: C): VigorApply<VigorFetchPolicySettingsTypeLambda, C>;
362
- /** Sets response headers consulted to compute a server-suggested retry delay. */
363
- retryHeaders<const N extends VigorFetchSchema<any>["policy"]["settings"]["retryHeaders"]>(...strs: N): VigorFetchPolicySettings<VigorFetchIn<VigorDeepMerge<T, {
364
- readonly policy: {
365
- readonly settings: {
366
- readonly retryHeaders: N;
367
- };
368
- };
369
- }>>>;
370
- /** Sets HTTP status codes that should never be retried. */
371
- unretryStatus<const N extends VigorFetchSchema<any>["policy"]["settings"]["unretryStatus"]>(...nums: N): VigorFetchPolicySettings<VigorFetchIn<VigorDeepMerge<T, {
372
- readonly policy: {
373
- readonly settings: {
374
- readonly unretryStatus: N;
375
- };
376
- };
377
- }>>>;
378
- /** Sets the maximum number of full restarts allowed. */
379
- maxRestarts<const N extends VigorFetchSchema<any>["policy"]["settings"]["maxRestarts"]>(num: N): VigorFetchPolicySettings<VigorFetchIn<VigorDeepMerge<T, {
380
- readonly policy: {
381
- readonly settings: {
382
- readonly maxRestarts: N;
383
- };
384
- };
385
- }>>>;
386
- /** Sets the fallback value/factory used when the request ultimately fails. */
387
- default<const N extends VigorExcludeEmpty<VigorFetchSchema<any>["policy"]["settings"]["default"]>>(func: N): VigorFetchPolicySettings<VigorFetchIn<VigorDeepMerge<T, {
388
- readonly policy: {
389
- readonly settings: {
390
- readonly default: N;
391
- };
392
- };
393
- }>>>;
394
- }
395
-
396
511
  type VigorFetchPolicyMiddlewaresSchema<T extends VigorFetchSchema<T>> = {
397
512
  __brand: VigorBrand<"Fetch", "Policy<Middlewares<Schema">;
398
513
  before: (VigorFetchPolicyMiddlewaresFluent<T>["before"] | VigorFetchPolicyMiddlewaresIntercept<T>["before"])[];
@@ -411,19 +526,21 @@ type VigorFetchPolicyMiddlewaresFluent<T extends VigorFetchSchema<T>> = {
411
526
  __brand: VigorBrand<"Fetch", "Policy<Middlewares<Fluent<Schema">;
412
527
  before: {
413
528
  _mode: "fluent";
414
- func: (ctx: VigorFetchBeforeContextSchema<T>) => void;
529
+ func: (ctx: VigorFetchBeforeContextSchema<T>) => void | Promise<void>;
415
530
  };
416
531
  after: {
417
532
  _mode: "fluent";
418
- func: (ctx: VigorFetchAfterContextSchema<T>) => void;
533
+ func: (ctx: VigorFetchAfterContextSchema<T>) => void | Promise<void>;
419
534
  };
420
535
  onResult: {
421
536
  _mode: "fluent";
422
- func: (res: VigorFetchAfterContextSchema<T>["result"]) => VigorFetchContextSchema<any>["result"];
537
+ func: (res: VigorFetchOnResultContextSchema<T> extends {
538
+ result: infer R;
539
+ } ? R : never) => VigorFetchContextSchema<any>["result"] | Promise<VigorFetchContextSchema<any>["result"]>;
423
540
  };
424
541
  onError: {
425
542
  _mode: "fluent";
426
- func: (err: VigorFetchContextSchema<T>["error"]) => void;
543
+ func: (err: VigorFetchContextSchema<T>["error"]) => void | Promise<void>;
427
544
  };
428
545
  };
429
546
  type VigorFetchPolicyMiddlewaresApi<T extends VigorFetchSchema<T>> = {
@@ -447,7 +564,7 @@ type VigorFetchPolicyMiddlewaresIntercept<T extends VigorFetchSchema<T>> = {
447
564
  };
448
565
  onResult: {
449
566
  _mode: "intercept";
450
- func: (ctx: VigorFetchAfterContextSchema<T>, api: Pick<VigorFetchPolicyMiddlewaresApi<T>, "setResult" | "throwError">) => VigorFetchContextSchema<any> | Promise<VigorFetchContextSchema<any>>;
567
+ func: (ctx: VigorFetchOnResultContextSchema<T>, api: Pick<VigorFetchPolicyMiddlewaresApi<T>, "setResult" | "throwError">) => VigorFetchContextSchema<any> | Promise<VigorFetchContextSchema<any>>;
451
568
  };
452
569
  onError: {
453
570
  _mode: "intercept";
@@ -546,7 +663,114 @@ declare class VigorFetchPolicyMiddlewares<T extends VigorFetchSchema<T> = typeof
546
663
  }];
547
664
  };
548
665
  };
549
- }>>;
666
+ }>>;
667
+ }
668
+ type VigorFetchPipeInitialContext<T extends VigorFetchSchema<T>, R = VigorCastResult<T["cast"], unknown>> = VigorDeepMerge<Omit<VigorFetchContextSchema<T, unknown>, "result">, {
669
+ result: R;
670
+ }>;
671
+ type VigorFetchPipeStepVoid<Ctx, Arr> = Arr extends [infer Head, ...infer Tail] ? Head extends {
672
+ _mode: "intercept";
673
+ func: (...args: any[]) => infer Ret;
674
+ } ? VigorFetchPipeStepVoid<Ret, Tail> : VigorFetchPipeStepVoid<Ctx, Tail> : Ctx;
675
+ type VigorFetchPipeStepResult<Ctx, Arr> = Arr extends [infer Head, ...infer Tail] ? Head extends {
676
+ _mode: "intercept";
677
+ func: (...args: any[]) => infer Ret;
678
+ } ? VigorFetchPipeStepResult<Ret, Tail> : Head extends {
679
+ _mode: "fluent";
680
+ func: (...args: any[]) => infer FR;
681
+ } ? VigorFetchPipeStepResult<VigorDeepMerge<Ctx, {
682
+ result: FR;
683
+ }>, Tail> : VigorFetchPipeStepResult<Ctx, Tail> : Ctx;
684
+ type VigorFetchPolicyMiddlewaresPipe<T extends VigorFetchSchema<T>> = VigorFetchPipeStepVoid<VigorFetchPipeStepResult<VigorFetchPipeStepResult<VigorFetchPipeStepVoid<VigorFetchPipeInitialContext<T>, T["policy"]["middlewares"]["before"]>, T["policy"]["middlewares"]["after"]>, T["policy"]["middlewares"]["onResult"]>, T["policy"]["middlewares"]["onError"]>;
685
+ type VigorFetchPipeResult<T extends VigorFetchSchema<T>> = VigorFetchPolicyMiddlewaresPipe<T> extends {
686
+ result: infer R;
687
+ } ? R : never;
688
+
689
+ type VigorFetchExtraOptions = Omit<RequestInit, "method" | "headers" | "body" | "signal">;
690
+ type VigorFetchOptions = VigorFetchExtraOptions & {
691
+ method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS" | "CONNECT" | "TRACE";
692
+ headers: Record<string, string>;
693
+ body?: BodyInit | null;
694
+ signal?: AbortSignal;
695
+ };
696
+ /**
697
+ * Base shape shared by every fetch context variant. `R` is the type of
698
+ * `result` at the point the context is observed — computed per pipeline
699
+ * stage instead of being fixed on the schema.
700
+ */
701
+ type VigorFetchContextSchema<T extends VigorFetchSchema<T>, R = VigorFetchPipeResult<T> | VigorDefaultType> = {
702
+ __brand: VigorBrand<"Fetch", "Context<Schema">;
703
+ href: string;
704
+ response: Response | VigorDefaultType;
705
+ result: R;
706
+ error: unknown;
707
+ options: VigorFetchOptions | VigorDefaultType;
708
+ flags: {
709
+ overridden: boolean;
710
+ restarted: boolean;
711
+ };
712
+ record: Record<string, any>;
713
+ policy: T["policy"];
714
+ };
715
+ /** Context shape seen by `before` middlewares — the request hasn't been sent yet. */
716
+ type VigorFetchBeforeContextSchema<T extends VigorFetchSchema<T>> = VigorFetchContextSchema<T, VigorDefaultType>;
717
+ /** Context shape seen by `after` middlewares — reflects the result after `before` has run. */
718
+ type VigorFetchAfterContextSchema<T extends VigorFetchSchema<T>> = VigorFetchPipeStepResult<VigorFetchPipeStepVoid<VigorFetchPipeInitialContext<T>, T["policy"]["middlewares"]["before"]>, T["policy"]["middlewares"]["after"]>;
719
+ /** Context shape seen by `onResult` middlewares — additionally threads any `onResult` middlewares already registered earlier in the same chain, so `ctx.result` reflects what the previous `onResult` returned. */
720
+ type VigorFetchOnResultContextSchema<T extends VigorFetchSchema<T>> = VigorFetchPipeStepResult<VigorFetchAfterContextSchema<T>, T["policy"]["middlewares"]["onResult"]>;
721
+
722
+ type VigorFetchPolicySettingsSchema<T extends VigorFetchSchema<T>> = {
723
+ __brand: VigorBrand<"Fetch", "Policy<Settings<Schema">;
724
+ retryHeaders: string[];
725
+ unretryStatus: number[];
726
+ maxRestarts: number;
727
+ default: ((ctx: VigorFetchContextSchema<T>) => any | Promise<any>) | VigorEmptyType;
728
+ };
729
+ declare const VigorFetchPolicySettingsBase: {
730
+ readonly __brand: VigorBrand<"Fetch", "Policy<Settings<Schema">;
731
+ readonly retryHeaders: ["retry-after", "ratelimit-reset", "x-ratelimit-reset", "x-retry-after", "x-amz-retry-after", "chrome-proxy-next-link"];
732
+ readonly unretryStatus: [400, 401, 403, 404, 405, 413, 422];
733
+ readonly maxRestarts: 3;
734
+ readonly default: symbol & {
735
+ __brand: VigorBrand<"Core", "Symbol_Empty">;
736
+ };
737
+ };
738
+ /** Immutable builder for a fetch policy's general settings. */
739
+ declare class VigorFetchPolicySettings<T extends VigorFetchSchema<T> = typeof VigorFetchBase> extends VigorStatus<VigorFetchSchema<any>, T, VigorFetchPolicySettingsTypeLambda> {
740
+ constructor(config?: T);
741
+ protected _create<C>(config: C): VigorApply<VigorFetchPolicySettingsTypeLambda, C>;
742
+ /** Sets response headers consulted to compute a server-suggested retry delay. */
743
+ retryHeaders<const N extends VigorFetchSchema<any>["policy"]["settings"]["retryHeaders"]>(...strs: N): VigorFetchPolicySettings<VigorFetchIn<VigorDeepMerge<T, {
744
+ readonly policy: {
745
+ readonly settings: {
746
+ readonly retryHeaders: N;
747
+ };
748
+ };
749
+ }>>>;
750
+ /** Sets HTTP status codes that should never be retried. */
751
+ unretryStatus<const N extends VigorFetchSchema<any>["policy"]["settings"]["unretryStatus"]>(...nums: N): VigorFetchPolicySettings<VigorFetchIn<VigorDeepMerge<T, {
752
+ readonly policy: {
753
+ readonly settings: {
754
+ readonly unretryStatus: N;
755
+ };
756
+ };
757
+ }>>>;
758
+ /** Sets the maximum number of full restarts allowed. */
759
+ maxRestarts<const N extends VigorFetchSchema<any>["policy"]["settings"]["maxRestarts"]>(num: N): VigorFetchPolicySettings<VigorFetchIn<VigorDeepMerge<T, {
760
+ readonly policy: {
761
+ readonly settings: {
762
+ readonly maxRestarts: N;
763
+ };
764
+ };
765
+ }>>>;
766
+ /** Sets the fallback value/factory used when the request ultimately fails. */
767
+ default<const N extends VigorExcludeEmpty<VigorFetchSchema<any>["policy"]["settings"]["default"]>>(func: N): VigorFetchPolicySettings<VigorFetchIn<VigorDeepMerge<T, {
768
+ readonly policy: {
769
+ readonly settings: {
770
+ readonly default: N;
771
+ };
772
+ };
773
+ }>>>;
550
774
  }
551
775
 
552
776
  /** Returns a random offset in the range `[-jitter, +jitter]` to randomize a computed delay. */
@@ -819,27 +1043,29 @@ type VigorRetryPolicyMiddlewaresFluent<T extends VigorRetrySchema<T>> = {
819
1043
  __brand: VigorBrand<"Retry", "Policy<Middlewares<Fluent<Schema">;
820
1044
  before: {
821
1045
  _mode: "fluent";
822
- func: (ctx: VigorRetryBeforeContextSchema<T>) => void;
1046
+ func: (ctx: VigorRetryBeforeContextSchema<T>) => void | Promise<void>;
823
1047
  };
824
1048
  after: {
825
1049
  _mode: "fluent";
826
- func: (ctx: VigorRetryAfterContextSchema<T>) => void;
1050
+ func: (ctx: VigorRetryAfterContextSchema<T>) => void | Promise<void>;
827
1051
  };
828
1052
  onResult: {
829
1053
  _mode: "fluent";
830
- func: (res: VigorRetryAfterContextSchema<T>["result"]) => VigorRetryContextSchema<any>["result"];
1054
+ func: (res: VigorRetryOnResultContextSchema<T> extends {
1055
+ result: infer R;
1056
+ } ? R : never) => VigorRetryContextSchema<any>["result"] | Promise<VigorRetryContextSchema<any>["result"]>;
831
1057
  };
832
1058
  retryIf: {
833
1059
  _mode: "fluent";
834
- func: (err: VigorRetryContextSchema<T>["error"]) => VigorRetryContextSchema<any>["flags"]["doRetry"];
1060
+ func: (err: VigorRetryContextSchema<T>["error"]) => VigorRetryContextSchema<any>["flags"]["doRetry"] | Promise<VigorRetryContextSchema<any>["flags"]["doRetry"]>;
835
1061
  };
836
1062
  onRetry: {
837
1063
  _mode: "fluent";
838
- func: (err: VigorRetryContextSchema<T>["error"]) => void;
1064
+ func: (err: VigorRetryContextSchema<T>["error"]) => void | Promise<void>;
839
1065
  };
840
1066
  onError: {
841
1067
  _mode: "fluent";
842
- func: (err: VigorRetryContextSchema<T>["error"]) => void;
1068
+ func: (err: VigorRetryContextSchema<T>["error"]) => void | Promise<void>;
843
1069
  };
844
1070
  };
845
1071
  type VigorRetryPolicyMiddlewaresApi<T extends VigorRetrySchema<T>> = {
@@ -865,7 +1091,7 @@ type VigorRetryPolicyMiddlewaresIntercept<T extends VigorRetrySchema<T>> = {
865
1091
  };
866
1092
  onResult: {
867
1093
  _mode: "intercept";
868
- func: (ctx: VigorRetryAfterContextSchema<T>, api: Pick<VigorRetryPolicyMiddlewaresApi<T>, "setResult" | "throwError">) => VigorRetryContextSchema<any> | Promise<VigorRetryContextSchema<any>>;
1094
+ func: (ctx: VigorRetryOnResultContextSchema<T>, api: Pick<VigorRetryPolicyMiddlewaresApi<T>, "setResult" | "throwError">) => VigorRetryContextSchema<any> | Promise<VigorRetryContextSchema<any>>;
869
1095
  };
870
1096
  retryIf: {
871
1097
  _mode: "intercept";
@@ -1075,8 +1301,10 @@ type VigorRetryContextSchema<T extends VigorRetrySchema<T>, R = VigorRetryPipeRe
1075
1301
  };
1076
1302
  /** Context shape seen by `before` middlewares — the target hasn't run yet, so there's no result. */
1077
1303
  type VigorRetryBeforeContextSchema<T extends VigorRetrySchema<T>> = VigorRetryContextSchema<T, VigorDefaultType>;
1078
- /** Context shape seen by `after` / `onResult` middlewares — the target has settled. */
1079
- type VigorRetryAfterContextSchema<T extends VigorRetrySchema<T>> = VigorRetryContextSchema<T, VigorRetryPipeInitialContext<T>["result"]>;
1304
+ /** Context shape seen by `after` middlewares — reflects the result after `before` has run. */
1305
+ type VigorRetryAfterContextSchema<T extends VigorRetrySchema<T>> = VigorRetryPipeStepResult<VigorRetryPipeStepVoid<VigorRetryPipeInitialContext<T>, T["policy"]["middlewares"]["before"]>, T["policy"]["middlewares"]["after"]>;
1306
+ /** Context shape seen by `onResult` middlewares — additionally threads any `onResult` middlewares already registered earlier in the same chain, so `ctx.result` reflects what the previous `onResult` returned. */
1307
+ type VigorRetryOnResultContextSchema<T extends VigorRetrySchema<T>> = VigorRetryPipeStepResult<VigorRetryAfterContextSchema<T>, T["policy"]["middlewares"]["onResult"]>;
1080
1308
 
1081
1309
  type VigorRetryPolicySettingsSchema<T extends VigorRetrySchema<T>> = {
1082
1310
  __brand: VigorBrand<"Retry", "Policy<Settings<Schema">;
@@ -1268,23 +1496,48 @@ declare class VigorRetry<T extends VigorRetrySchema<T> = typeof VigorRetryBase>
1268
1496
  };
1269
1497
  }>>>;
1270
1498
  /** Configures the retry policy's general settings (max attempts, timeout, etc). */
1271
- settings<const N extends VigorDeepPartial<VigorRetryPolicySettingsSchema<T>>, R extends VigorRetrySchema<any>>(input: N | ((s: VigorRetryPolicySettings<T>) => VigorRetryPolicySettings<R>) | VigorRetryPolicySettings<R>): VigorRetry<VigorRetryIn<VigorDeepMerge<T, {
1272
- readonly policy: {
1273
- readonly settings: VigorRetryPolicySettingsSchema<any>;
1499
+ settings<const N extends VigorDeepPartial<VigorRetryPolicySettingsSchema<T>>>(input: N): VigorApply<VigorRetryTypeLambda, VigorDeepMerge<T, {
1500
+ policy: {
1501
+ settings: N;
1274
1502
  };
1275
- }>>>;
1503
+ }>>;
1504
+ settings<const R extends VigorRetrySchema<any>>(input: (s: VigorRetryPolicySettings<T>) => VigorRetryPolicySettings<R>): VigorApply<VigorRetryTypeLambda, VigorDeepMerge<T, {
1505
+ policy: {
1506
+ settings: R["policy"]["settings"];
1507
+ };
1508
+ }>>;
1509
+ settings<const R extends VigorRetrySchema<any>>(input: VigorRetryPolicySettings<R>): VigorApply<VigorRetryTypeLambda, VigorDeepMerge<T, {
1510
+ policy: {
1511
+ settings: R["policy"]["settings"];
1512
+ };
1513
+ }>>;
1276
1514
  /** Configures the retry policy's middleware pipeline. */
1277
- middlewares<const N extends VigorDeepPartial<VigorRetryPolicyMiddlewaresSchema<T>>, R extends VigorRetrySchema<any>>(input: N | ((s: VigorRetryPolicyMiddlewares<T>) => VigorRetryPolicyMiddlewares<R>) | VigorRetryPolicyMiddlewares<R>): VigorRetry<VigorRetryIn<VigorDeepMerge<T, {
1278
- readonly policy: {
1279
- readonly middlewares: VigorRetryPolicyMiddlewaresSchema<any>;
1515
+ middlewares<const N extends VigorDeepPartial<VigorRetryPolicyMiddlewaresSchema<T>>>(input: N): VigorApply<VigorRetryTypeLambda, VigorDeepMerge<T, {
1516
+ policy: {
1517
+ middlewares: N;
1280
1518
  };
1281
- }>>>;
1519
+ }>>;
1520
+ middlewares<const R extends VigorRetrySchema<any>>(input: (s: VigorRetryPolicyMiddlewares<T>) => VigorRetryPolicyMiddlewares<R>): VigorApply<VigorRetryTypeLambda, VigorDeepMerge<T, {
1521
+ policy: {
1522
+ middlewares: R["policy"]["middlewares"];
1523
+ };
1524
+ }>>;
1525
+ middlewares<const R extends VigorRetrySchema<any>>(input: VigorRetryPolicyMiddlewares<R>): VigorApply<VigorRetryTypeLambda, VigorDeepMerge<T, {
1526
+ policy: {
1527
+ middlewares: R["policy"]["middlewares"];
1528
+ };
1529
+ }>>;
1282
1530
  /** Configures the retry policy's delay algorithm. */
1283
- algorithms<const N extends VigorDeepPartial<VigorRetryPolicyAlgorithmsSchema<T>>, R extends VigorRetrySchema<any>>(input: N | ((a: VigorRetryPolicyAlgorithms<T>) => VigorRetryPolicyAlgorithms<R> | VigorRetryPolicyAlgorithmsConstant<any>)): VigorRetry<VigorRetryIn<VigorDeepMerge<T, {
1284
- readonly policy: {
1285
- readonly algorithms: any;
1531
+ algorithms<const N extends VigorDeepPartial<VigorRetryPolicyAlgorithmsSchema<T>>>(input: N): VigorApply<VigorRetryTypeLambda, VigorDeepMerge<T, {
1532
+ policy: {
1533
+ algorithms: N;
1286
1534
  };
1287
- }>>>;
1535
+ }>>;
1536
+ algorithms<const R extends VigorRetrySchema<any>>(input: (a: VigorRetryPolicyAlgorithms<T>) => VigorRetryPolicyAlgorithms<R>): VigorApply<VigorRetryTypeLambda, VigorDeepMerge<T, {
1537
+ policy: {
1538
+ algorithms: R["policy"]["algorithms"];
1539
+ };
1540
+ }>>;
1288
1541
  /**
1289
1542
  * Overrides the resolved result type with `T`, taking priority over the
1290
1543
  * type naturally inferred from `target()`. Can be called before or after
@@ -1295,9 +1548,9 @@ declare class VigorRetry<T extends VigorRetrySchema<T> = typeof VigorRetryBase>
1295
1548
  cast: C;
1296
1549
  }>>>;
1297
1550
  /** Runs the target and returns its result directly, throwing on final failure. */
1298
- request<R = VigorCastResult<T["cast"], VigorRetryContextSchema<T>["result"]>>(): Promise<R>;
1551
+ request<R = VigorExcludeDefault<VigorRetryContextSchema<T>["result"]>>(): Promise<R>;
1299
1552
  /** Runs the target and returns a result/error envelope instead of throwing. */
1300
- requestVerbose<R = VigorCastResult<T["cast"], VigorRetryContextSchema<T>["result"]>>(): Promise<{
1553
+ requestVerbose<R = VigorExcludeDefault<VigorRetryContextSchema<T>["result"]>>(): Promise<{
1301
1554
  success: false;
1302
1555
  data: null;
1303
1556
  error: unknown;
@@ -1409,72 +1662,6 @@ declare class VigorParsePolicyStrategies<T extends VigorParseSchema<T> = typeof
1409
1662
  }>>>;
1410
1663
  }
1411
1664
 
1412
- /**
1413
- * Base shape shared by every parse context variant. `R` is the type of
1414
- * `result` at the point the context is observed — computed per pipeline
1415
- * stage instead of being fixed on the schema.
1416
- */
1417
- type VigorParseContextSchema<T extends VigorParseSchema<T>, R = VigorCastResult<T["cast"], unknown> | VigorDefaultType> = {
1418
- __brand: VigorBrand<"Parse", "Context<Schema">;
1419
- result: R;
1420
- error: unknown;
1421
- response: VigorParsePolicySchema<T>["target"];
1422
- flags: {
1423
- overrided: boolean;
1424
- restarted: boolean;
1425
- };
1426
- record: Record<string, any>;
1427
- policy: T["policy"];
1428
- };
1429
- /** Context shape seen by `before` middlewares — parsing hasn't run yet. */
1430
- type VigorParseBeforeContextSchema<T extends VigorParseSchema<T>> = VigorParseContextSchema<T, VigorDefaultType>;
1431
- /** Context shape seen by `after` / `onResult` middlewares — a result has been produced. */
1432
- type VigorParseAfterContextSchema<T extends VigorParseSchema<T>> = VigorParseContextSchema<T, VigorCastResult<T["cast"], unknown>>;
1433
-
1434
- type VigorParsePolicySettingsSchema<T extends VigorParseSchema<T>> = {
1435
- __brand: VigorBrand<"Parse", "Policy<Settings<Schema">;
1436
- raw: boolean;
1437
- default: ((ctx: VigorParseContextSchema<T>) => any | Promise<any>) | VigorEmptyType;
1438
- maxRestarts: number;
1439
- };
1440
- declare const VigorParsePolicySettingsBase: {
1441
- readonly __brand: VigorBrand<"Parse", "Policy<Settings<Schema">;
1442
- readonly raw: false;
1443
- readonly default: symbol & {
1444
- __brand: VigorBrand<"Core", "Symbol_Empty">;
1445
- };
1446
- readonly maxRestarts: 3;
1447
- };
1448
- /** Immutable builder for a parse policy's general settings. */
1449
- declare class VigorParsePolicySettings<T extends VigorParseSchema<T> = typeof VigorParseBase> extends VigorStatus<VigorParseSchema<any>, T, VigorParsePolicySettingsTypeLambda> {
1450
- constructor(config?: T);
1451
- protected _create<C>(config: C): VigorApply<VigorParsePolicySettingsTypeLambda, C>;
1452
- /** When enabled, skips content-type based parsing and returns the raw response. */
1453
- raw<const N extends VigorParseSchema<any>["policy"]["settings"]["raw"]>(bool: N): VigorParsePolicySettings<VigorParseIn<VigorDeepMerge<T, {
1454
- readonly policy: {
1455
- readonly settings: {
1456
- readonly raw: N;
1457
- };
1458
- };
1459
- }>>>;
1460
- /** Sets the fallback value/factory used when parsing ultimately fails. */
1461
- default<const N extends VigorExcludeEmpty<VigorParseSchema<any>["policy"]["settings"]["default"]>>(func: N): VigorParsePolicySettings<VigorParseIn<VigorDeepMerge<T, {
1462
- readonly policy: {
1463
- readonly settings: {
1464
- readonly default: N;
1465
- };
1466
- };
1467
- }>>>;
1468
- /** Sets the maximum number of full restarts allowed. */
1469
- maxRestarts<const N extends VigorParseSchema<any>["policy"]["settings"]["maxRestarts"]>(num: N): VigorParsePolicySettings<VigorParseIn<VigorDeepMerge<T, {
1470
- readonly policy: {
1471
- readonly settings: {
1472
- readonly maxRestarts: N;
1473
- };
1474
- };
1475
- }>>>;
1476
- }
1477
-
1478
1665
  type VigorParsePolicyMiddlewaresSchema<T extends VigorParseSchema<T>> = {
1479
1666
  __brand: VigorBrand<"Parse", "Policy<Middlewares<Schema">;
1480
1667
  before: (VigorParsePolicyMiddlewaresFluent<T>["before"] | VigorParsePolicyMiddlewaresIntercept<T>["before"])[];
@@ -1493,19 +1680,21 @@ type VigorParsePolicyMiddlewaresFluent<T extends VigorParseSchema<T>> = {
1493
1680
  __brand: VigorBrand<"Parse", "Policy<Middlewares<Fluent<Schema">;
1494
1681
  before: {
1495
1682
  _mode: "fluent";
1496
- func: (ctx: VigorParseBeforeContextSchema<T>) => void;
1683
+ func: (ctx: VigorParseBeforeContextSchema<T>) => void | Promise<void>;
1497
1684
  };
1498
1685
  after: {
1499
1686
  _mode: "fluent";
1500
- func: (ctx: VigorParseAfterContextSchema<T>) => void;
1687
+ func: (ctx: VigorParseAfterContextSchema<T>) => void | Promise<void>;
1501
1688
  };
1502
1689
  onResult: {
1503
1690
  _mode: "fluent";
1504
- func: (res: VigorParseAfterContextSchema<T>["result"]) => VigorParseContextSchema<any>["result"];
1691
+ func: (res: VigorParseOnResultContextSchema<T> extends {
1692
+ result: infer R;
1693
+ } ? R : never) => VigorParseContextSchema<any>["result"] | Promise<VigorParseContextSchema<any>["result"]>;
1505
1694
  };
1506
1695
  onError: {
1507
1696
  _mode: "fluent";
1508
- func: (err: VigorParseContextSchema<T>["error"]) => void;
1697
+ func: (err: VigorParseContextSchema<T>["error"]) => void | Promise<void>;
1509
1698
  };
1510
1699
  };
1511
1700
  type VigorParsePolicyMiddlewaresApi<T extends VigorParseSchema<T>> = {
@@ -1526,7 +1715,7 @@ type VigorParsePolicyMiddlewaresIntercept<T extends VigorParseSchema<T>> = {
1526
1715
  };
1527
1716
  onResult: {
1528
1717
  _mode: "intercept";
1529
- func: (ctx: VigorParseAfterContextSchema<T>, api: Pick<VigorParsePolicyMiddlewaresApi<T>, "setResult" | "throwError">) => VigorParseContextSchema<any> | Promise<VigorParseContextSchema<any>>;
1718
+ func: (ctx: VigorParseOnResultContextSchema<T>, api: Pick<VigorParsePolicyMiddlewaresApi<T>, "setResult" | "throwError">) => VigorParseContextSchema<any> | Promise<VigorParseContextSchema<any>>;
1530
1719
  };
1531
1720
  onError: {
1532
1721
  _mode: "intercept";
@@ -1627,6 +1816,97 @@ declare class VigorParsePolicyMiddlewares<T extends VigorParseSchema<T> = typeof
1627
1816
  };
1628
1817
  }>>;
1629
1818
  }
1819
+ type VigorParsePipeInitialContext<T extends VigorParseSchema<T>, R = T["policy"]["settings"]["raw"] extends true ? VigorExcludeDefault<T["policy"]["target"]> : VigorCastResult<T["cast"], unknown>> = VigorDeepMerge<Omit<VigorParseContextSchema<T, unknown>, "result">, {
1820
+ result: R;
1821
+ }>;
1822
+ type VigorParsePipeStepVoid<Ctx, Arr> = Arr extends [infer Head, ...infer Tail] ? Head extends {
1823
+ _mode: "intercept";
1824
+ func: (...args: any[]) => infer Ret;
1825
+ } ? VigorParsePipeStepVoid<Ret, Tail> : VigorParsePipeStepVoid<Ctx, Tail> : Ctx;
1826
+ type VigorParsePipeStepResult<Ctx, Arr> = Arr extends [infer Head, ...infer Tail] ? Head extends {
1827
+ _mode: "intercept";
1828
+ func: (...args: any[]) => infer Ret;
1829
+ } ? VigorParsePipeStepResult<Ret, Tail> : Head extends {
1830
+ _mode: "fluent";
1831
+ func: (...args: any[]) => infer FR;
1832
+ } ? VigorParsePipeStepResult<VigorDeepMerge<Ctx, {
1833
+ result: FR;
1834
+ }>, Tail> : VigorParsePipeStepResult<Ctx, Tail> : Ctx;
1835
+ type VigorParsePolicyMiddlewaresPipe<T extends VigorParseSchema<T>> = VigorParsePipeStepVoid<VigorParsePipeStepResult<VigorParsePipeStepResult<VigorParsePipeStepVoid<VigorParsePipeInitialContext<T>, T["policy"]["middlewares"]["before"]>, T["policy"]["middlewares"]["after"]>, T["policy"]["middlewares"]["onResult"]>, T["policy"]["middlewares"]["onError"]>;
1836
+ type VigorParsePipeResult<T extends VigorParseSchema<T>> = VigorParsePolicyMiddlewaresPipe<T> extends {
1837
+ result: infer R;
1838
+ } ? R : never;
1839
+
1840
+ /**
1841
+ * Base shape shared by every parse context variant. `R` is the type of
1842
+ * `result` at the point the context is observed — computed per pipeline
1843
+ * stage instead of being fixed on the schema. Threads the configured
1844
+ * middleware pipeline (see `./middlewares`) so fluent `after`/`onResult`
1845
+ * middlewares narrow the resolved type, taking priority from `.cast<T>()`
1846
+ * when set.
1847
+ */
1848
+ type VigorParseContextSchema<T extends VigorParseSchema<T>, R = VigorParsePipeResult<T> | VigorDefaultType> = {
1849
+ __brand: VigorBrand<"Parse", "Context<Schema">;
1850
+ result: R;
1851
+ error: unknown;
1852
+ response: VigorParsePolicySchema<T>["target"];
1853
+ flags: {
1854
+ overrided: boolean;
1855
+ restarted: boolean;
1856
+ };
1857
+ record: Record<string, any>;
1858
+ policy: T["policy"];
1859
+ };
1860
+ /** Context shape seen by `before` middlewares — parsing hasn't run yet. */
1861
+ type VigorParseBeforeContextSchema<T extends VigorParseSchema<T>> = VigorParseContextSchema<T, VigorDefaultType>;
1862
+ /** Context shape seen by `after` middlewares — reflects the result after `before` has run. */
1863
+ type VigorParseAfterContextSchema<T extends VigorParseSchema<T>> = VigorParsePipeStepResult<VigorParsePipeStepVoid<VigorParsePipeInitialContext<T>, T["policy"]["middlewares"]["before"]>, T["policy"]["middlewares"]["after"]>;
1864
+ /** Context shape seen by `onResult` middlewares — additionally threads any `onResult` middlewares already registered earlier in the same chain, so `ctx.result` reflects what the previous `onResult` returned. */
1865
+ type VigorParseOnResultContextSchema<T extends VigorParseSchema<T>> = VigorParsePipeStepResult<VigorParseAfterContextSchema<T>, T["policy"]["middlewares"]["onResult"]>;
1866
+
1867
+ type VigorParsePolicySettingsSchema<T extends VigorParseSchema<T>> = {
1868
+ __brand: VigorBrand<"Parse", "Policy<Settings<Schema">;
1869
+ raw: boolean;
1870
+ default: ((ctx: VigorParseContextSchema<T>) => any | Promise<any>) | VigorEmptyType;
1871
+ maxRestarts: number;
1872
+ };
1873
+ declare const VigorParsePolicySettingsBase: {
1874
+ readonly __brand: VigorBrand<"Parse", "Policy<Settings<Schema">;
1875
+ readonly raw: false;
1876
+ readonly default: symbol & {
1877
+ __brand: VigorBrand<"Core", "Symbol_Empty">;
1878
+ };
1879
+ readonly maxRestarts: 3;
1880
+ };
1881
+ /** Immutable builder for a parse policy's general settings. */
1882
+ declare class VigorParsePolicySettings<T extends VigorParseSchema<T> = typeof VigorParseBase> extends VigorStatus<VigorParseSchema<any>, T, VigorParsePolicySettingsTypeLambda> {
1883
+ constructor(config?: T);
1884
+ protected _create<C>(config: C): VigorApply<VigorParsePolicySettingsTypeLambda, C>;
1885
+ /** When enabled, skips content-type based parsing and returns the raw response. */
1886
+ raw<const N extends VigorParseSchema<any>["policy"]["settings"]["raw"]>(bool: N): VigorParsePolicySettings<VigorParseIn<VigorDeepMerge<T, {
1887
+ readonly policy: {
1888
+ readonly settings: {
1889
+ readonly raw: N;
1890
+ };
1891
+ };
1892
+ }>>>;
1893
+ /** Sets the fallback value/factory used when parsing ultimately fails. */
1894
+ default<const N extends VigorExcludeEmpty<VigorParseSchema<any>["policy"]["settings"]["default"]>>(func: N): VigorParsePolicySettings<VigorParseIn<VigorDeepMerge<T, {
1895
+ readonly policy: {
1896
+ readonly settings: {
1897
+ readonly default: N;
1898
+ };
1899
+ };
1900
+ }>>>;
1901
+ /** Sets the maximum number of full restarts allowed. */
1902
+ maxRestarts<const N extends VigorParseSchema<any>["policy"]["settings"]["maxRestarts"]>(num: N): VigorParsePolicySettings<VigorParseIn<VigorDeepMerge<T, {
1903
+ readonly policy: {
1904
+ readonly settings: {
1905
+ readonly maxRestarts: N;
1906
+ };
1907
+ };
1908
+ }>>>;
1909
+ }
1630
1910
 
1631
1911
  type VigorParseIn<T> = T extends VigorParseSchema<any> ? T : never;
1632
1912
  interface VigorParseTypeLambda extends VigorTypeLambda {
@@ -1727,23 +2007,53 @@ declare class VigorParse<T extends VigorParseSchema<T> = typeof VigorParseBase>
1727
2007
  };
1728
2008
  }>>>;
1729
2009
  /** Configures the parse policy's general settings. */
1730
- settings<const N extends VigorDeepPartial<VigorParsePolicySettingsSchema<T>>, R extends VigorParseSchema<any>>(input: N | ((s: VigorParsePolicySettings<T>) => VigorParsePolicySettings<R>) | VigorParsePolicySettings<R>): VigorParse<VigorParseIn<VigorDeepMerge<T, {
1731
- readonly policy: {
1732
- readonly settings: VigorParsePolicySettingsSchema<any>;
2010
+ settings<const N extends VigorDeepPartial<VigorParsePolicySettingsSchema<T>>>(input: N): VigorApply<VigorParseTypeLambda, VigorDeepMerge<T, {
2011
+ policy: {
2012
+ settings: N;
1733
2013
  };
1734
- }>>>;
2014
+ }>>;
2015
+ settings<const R extends VigorParseSchema<any>>(input: (s: VigorParsePolicySettings<T>) => VigorParsePolicySettings<R>): VigorApply<VigorParseTypeLambda, VigorDeepMerge<T, {
2016
+ policy: {
2017
+ settings: R["policy"]["settings"];
2018
+ };
2019
+ }>>;
2020
+ settings<const R extends VigorParseSchema<any>>(input: VigorParsePolicySettings<R>): VigorApply<VigorParseTypeLambda, VigorDeepMerge<T, {
2021
+ policy: {
2022
+ settings: R["policy"]["settings"];
2023
+ };
2024
+ }>>;
1735
2025
  /** Configures the parse policy's middleware pipeline. */
1736
- middlewares<const N extends VigorDeepPartial<VigorParsePolicyMiddlewaresSchema<T>>, R extends VigorParseSchema<any>>(input: N | ((s: VigorParsePolicyMiddlewares<T>) => VigorParsePolicyMiddlewares<R>) | VigorParsePolicyMiddlewares<R>): VigorParse<VigorParseIn<VigorDeepMerge<T, {
1737
- readonly policy: {
1738
- readonly middlewares: VigorParsePolicyMiddlewaresSchema<any>;
2026
+ middlewares<const N extends VigorDeepPartial<VigorParsePolicyMiddlewaresSchema<T>>>(input: N): VigorApply<VigorParseTypeLambda, VigorDeepMerge<T, {
2027
+ policy: {
2028
+ middlewares: N;
1739
2029
  };
1740
- }>>>;
2030
+ }>>;
2031
+ middlewares<const R extends VigorParseSchema<any>>(input: (s: VigorParsePolicyMiddlewares<T>) => VigorParsePolicyMiddlewares<R>): VigorApply<VigorParseTypeLambda, VigorDeepMerge<T, {
2032
+ policy: {
2033
+ middlewares: R["policy"]["middlewares"];
2034
+ };
2035
+ }>>;
2036
+ middlewares<const R extends VigorParseSchema<any>>(input: VigorParsePolicyMiddlewares<R>): VigorApply<VigorParseTypeLambda, VigorDeepMerge<T, {
2037
+ policy: {
2038
+ middlewares: R["policy"]["middlewares"];
2039
+ };
2040
+ }>>;
1741
2041
  /** Configures the parse policy's fallback chain of parsing strategies. */
1742
- strategies<const N extends VigorDeepPartial<VigorParsePolicyStrategiesSchema<T>>, R extends VigorParseSchema<any>>(input: N | ((s: VigorParsePolicyStrategies<T>) => VigorParsePolicyStrategies<R>) | VigorParsePolicyStrategies<R>): VigorParse<VigorParseIn<VigorDeepMerge<T, {
1743
- readonly policy: {
1744
- readonly strategies: VigorParsePolicyStrategiesSchema<any>;
2042
+ strategies<const N extends VigorDeepPartial<VigorParsePolicyStrategiesSchema<T>>>(input: N): VigorApply<VigorParseTypeLambda, VigorDeepMerge<T, {
2043
+ policy: {
2044
+ strategies: N;
1745
2045
  };
1746
- }>>>;
2046
+ }>>;
2047
+ strategies<const R extends VigorParseSchema<any>>(input: (s: VigorParsePolicyStrategies<T>) => VigorParsePolicyStrategies<R>): VigorApply<VigorParseTypeLambda, VigorDeepMerge<T, {
2048
+ policy: {
2049
+ strategies: R["policy"]["strategies"];
2050
+ };
2051
+ }>>;
2052
+ strategies<const R extends VigorParseSchema<any>>(input: VigorParsePolicyStrategies<R>): VigorApply<VigorParseTypeLambda, VigorDeepMerge<T, {
2053
+ policy: {
2054
+ strategies: R["policy"]["strategies"];
2055
+ };
2056
+ }>>;
1747
2057
  /**
1748
2058
  * Overrides the resolved result type with `T`, taking priority over the
1749
2059
  * default `unknown` result. Can be called before or after `strategies()`
@@ -1754,9 +2064,9 @@ declare class VigorParse<T extends VigorParseSchema<T> = typeof VigorParseBase>
1754
2064
  cast: C;
1755
2065
  }>>>;
1756
2066
  /** Runs parsing and returns the result directly, throwing on final failure. */
1757
- request<R = VigorCastResult<T["cast"], VigorParseContextSchema<T>["result"]>>(): Promise<R>;
2067
+ request<R = VigorExcludeDefault<VigorParseContextSchema<T>["result"]>>(): Promise<R>;
1758
2068
  /** Runs parsing and returns a result/error envelope instead of throwing. */
1759
- requestVerbose<R = VigorCastResult<T["cast"], VigorParseContextSchema<T>["result"]>>(): Promise<{
2069
+ requestVerbose<R = VigorExcludeDefault<VigorParseContextSchema<T>["result"]>>(): Promise<{
1760
2070
  success: false;
1761
2071
  data: null;
1762
2072
  error: unknown;
@@ -2083,29 +2393,69 @@ declare class VigorFetch<T extends VigorFetchSchema<T> = typeof VigorFetchBase>
2083
2393
  };
2084
2394
  }>>>;
2085
2395
  /** Configures the fetch policy's general settings. */
2086
- settings<const N extends VigorDeepPartial<VigorFetchPolicySettingsSchema<T>>, R extends VigorFetchSchema<any>>(input: N | ((s: VigorFetchPolicySettings<T>) => VigorFetchPolicySettings<R>) | VigorFetchPolicySettings<R>): VigorFetch<VigorFetchIn<VigorDeepMerge<T, {
2087
- readonly policy: {
2088
- readonly settings: VigorFetchPolicySettingsSchema<any>;
2396
+ settings<const N extends VigorDeepPartial<VigorFetchPolicySettingsSchema<T>>>(input: N): VigorApply<VigorFetchTypeLambda, VigorDeepMerge<T, {
2397
+ policy: {
2398
+ settings: N;
2089
2399
  };
2090
- }>>>;
2400
+ }>>;
2401
+ settings<const R extends VigorFetchSchema<any>>(input: (s: VigorFetchPolicySettings<T>) => VigorFetchPolicySettings<R>): VigorApply<VigorFetchTypeLambda, VigorDeepMerge<T, {
2402
+ policy: {
2403
+ settings: R["policy"]["settings"];
2404
+ };
2405
+ }>>;
2406
+ settings<const R extends VigorFetchSchema<any>>(input: VigorFetchPolicySettings<R>): VigorApply<VigorFetchTypeLambda, VigorDeepMerge<T, {
2407
+ policy: {
2408
+ settings: R["policy"]["settings"];
2409
+ };
2410
+ }>>;
2091
2411
  /** Configures the fetch policy's middleware pipeline. */
2092
- middlewares<const N extends VigorDeepPartial<VigorFetchPolicyMiddlewaresSchema<T>>, R extends VigorFetchSchema<any>>(input: N | ((s: VigorFetchPolicyMiddlewares<T>) => VigorFetchPolicyMiddlewares<R>) | VigorFetchPolicyMiddlewares<R>): VigorFetch<VigorFetchIn<VigorDeepMerge<T, {
2093
- readonly policy: {
2094
- readonly middlewares: VigorFetchPolicyMiddlewaresSchema<any>;
2412
+ middlewares<const N extends VigorDeepPartial<VigorFetchPolicyMiddlewaresSchema<T>>>(input: N): VigorApply<VigorFetchTypeLambda, VigorDeepMerge<T, {
2413
+ policy: {
2414
+ middlewares: N;
2095
2415
  };
2096
- }>>>;
2416
+ }>>;
2417
+ middlewares<const R extends VigorFetchSchema<any>>(input: (s: VigorFetchPolicyMiddlewares<T>) => VigorFetchPolicyMiddlewares<R>): VigorApply<VigorFetchTypeLambda, VigorDeepMerge<T, {
2418
+ policy: {
2419
+ middlewares: R["policy"]["middlewares"];
2420
+ };
2421
+ }>>;
2422
+ middlewares<const R extends VigorFetchSchema<any>>(input: VigorFetchPolicyMiddlewares<R>): VigorApply<VigorFetchTypeLambda, VigorDeepMerge<T, {
2423
+ policy: {
2424
+ middlewares: R["policy"]["middlewares"];
2425
+ };
2426
+ }>>;
2097
2427
  /** Configures the retry engine used to send the underlying request. */
2098
- retry<const N extends VigorDeepPartial<VigorRetrySchema<any>>, R extends VigorRetrySchema<any>>(input: N | ((r: VigorRetry) => VigorRetry<R>) | VigorRetry<R>): VigorFetch<VigorFetchIn<VigorDeepMerge<T, {
2099
- readonly policy: {
2100
- readonly retry: R;
2428
+ retry<const N extends VigorDeepPartial<VigorRetrySchema<any>>>(input: N): VigorApply<VigorFetchTypeLambda, VigorDeepMerge<T, {
2429
+ policy: {
2430
+ retry: N;
2101
2431
  };
2102
- }>>>;
2432
+ }>>;
2433
+ retry<const R extends VigorRetrySchema<any>>(input: (r: VigorRetry) => VigorRetry<R>): VigorApply<VigorFetchTypeLambda, VigorDeepMerge<T, {
2434
+ policy: {
2435
+ retry: R;
2436
+ };
2437
+ }>>;
2438
+ retry<const R extends VigorRetrySchema<any>>(input: VigorRetry<R>): VigorApply<VigorFetchTypeLambda, VigorDeepMerge<T, {
2439
+ policy: {
2440
+ retry: R;
2441
+ };
2442
+ }>>;
2103
2443
  /** Configures the parse engine used to interpret the response. */
2104
- parse<const N extends VigorDeepPartial<VigorParseSchema<any>>, R extends VigorParseSchema<any>>(input: N | ((p: VigorParse) => VigorParse<R>) | VigorParse<R>): VigorFetch<VigorFetchIn<VigorDeepMerge<T, {
2105
- readonly policy: {
2106
- readonly parse: R;
2444
+ parse<const N extends VigorDeepPartial<VigorParseSchema<any>>>(input: N): VigorApply<VigorFetchTypeLambda, VigorDeepMerge<T, {
2445
+ policy: {
2446
+ parse: N;
2107
2447
  };
2108
- }>>>;
2448
+ }>>;
2449
+ parse<const R extends VigorParseSchema<any>>(input: (p: VigorParse) => VigorParse<R>): VigorApply<VigorFetchTypeLambda, VigorDeepMerge<T, {
2450
+ policy: {
2451
+ parse: R;
2452
+ };
2453
+ }>>;
2454
+ parse<const R extends VigorParseSchema<any>>(input: VigorParse<R>): VigorApply<VigorFetchTypeLambda, VigorDeepMerge<T, {
2455
+ policy: {
2456
+ parse: R;
2457
+ };
2458
+ }>>;
2109
2459
  /** Converts a list of stringable values into strings, dropping `null`/`undefined` entries. */
2110
2460
  protected _stringifyList(unkList: VigorStringable[]): string[];
2111
2461
  /**
@@ -2137,9 +2487,9 @@ declare class VigorFetch<T extends VigorFetchSchema<T> = typeof VigorFetchBase>
2137
2487
  cast: C;
2138
2488
  }>>>;
2139
2489
  /** Runs the request and returns its parsed result directly, throwing on final failure. */
2140
- request<R = VigorCastResult<T["cast"], VigorFetchContextSchema<T>["result"]>>(): Promise<R>;
2490
+ request<R = VigorExcludeDefault<VigorFetchContextSchema<T>["result"]>>(): Promise<R>;
2141
2491
  /** Runs the request and returns a result/error envelope instead of throwing. */
2142
- requestVerbose<R = VigorCastResult<T["cast"], VigorFetchContextSchema<T>["result"]>>(): Promise<{
2492
+ requestVerbose<R = VigorExcludeDefault<VigorFetchContextSchema<T>["result"]>>(): Promise<{
2143
2493
  success: false;
2144
2494
  data: null;
2145
2495
  error: unknown;
@@ -2343,7 +2693,7 @@ declare function fetchWithOrigin<const F extends Parameters<VigorFetch["origin"]
2343
2693
  }>>;
2344
2694
  declare function allWithTargets<const F extends VigorAllTask[]>(tasks: F): VigorAll<VigorAllIn<{
2345
2695
  policy: {
2346
- target: F extends VigorBuiltin ? F : F extends readonly any[] ? [...VigorAllTask[], ...F] : F;
2696
+ target: F extends VigorBuiltin ? F : F extends readonly any[] ? [...F] : F;
2347
2697
  __brand: VigorBrand<"All", "Policy<Schema">;
2348
2698
  settings: {
2349
2699
  readonly __brand: VigorBrand<"All", "Policy<Settings<Schema">;
@@ -2352,9 +2702,12 @@ declare function allWithTargets<const F extends VigorAllTask[]>(tasks: F): Vigor
2352
2702
  };
2353
2703
  middlewares: {
2354
2704
  readonly __brand: VigorBrand<"All", "Policy<Middlewares<Schema">;
2355
- readonly before: VigorAllEachMiddlewareFn[];
2356
- readonly after: VigorAllEachMiddlewareFn[];
2357
- readonly onError: VigorAllEachOnErrorFn[];
2705
+ readonly before: [];
2706
+ readonly after: [];
2707
+ readonly onResult: [];
2708
+ readonly beforeEach: [];
2709
+ readonly afterEach: [];
2710
+ readonly onErrorEach: [];
2358
2711
  };
2359
2712
  };
2360
2713
  __brand: VigorBrand<"All", "Schema">;
@@ -2866,7 +3219,7 @@ declare const vigorBase: {
2866
3219
  readonly __brand: VigorBrand<"All", "Schema">;
2867
3220
  readonly policy: {
2868
3221
  readonly __brand: VigorBrand<"All", "Policy<Schema">;
2869
- readonly target: VigorAllTask[];
3222
+ readonly target: [];
2870
3223
  readonly settings: {
2871
3224
  readonly __brand: VigorBrand<"All", "Policy<Settings<Schema">;
2872
3225
  readonly concurrency: 5;
@@ -2874,9 +3227,12 @@ declare const vigorBase: {
2874
3227
  };
2875
3228
  readonly middlewares: {
2876
3229
  readonly __brand: VigorBrand<"All", "Policy<Middlewares<Schema">;
2877
- readonly before: VigorAllEachMiddlewareFn[];
2878
- readonly after: VigorAllEachMiddlewareFn[];
2879
- readonly onError: VigorAllEachOnErrorFn[];
3230
+ readonly before: [];
3231
+ readonly after: [];
3232
+ readonly onResult: [];
3233
+ readonly beforeEach: [];
3234
+ readonly afterEach: [];
3235
+ readonly onErrorEach: [];
2880
3236
  };
2881
3237
  };
2882
3238
  readonly cast: symbol & {
@@ -2887,7 +3243,7 @@ declare const vigorBase: {
2887
3243
  readonly __brand: VigorBrand<"All", "Schema">;
2888
3244
  readonly policy: {
2889
3245
  readonly __brand: VigorBrand<"All", "Policy<Schema">;
2890
- readonly target: VigorAllTask[];
3246
+ readonly target: [];
2891
3247
  readonly settings: {
2892
3248
  readonly __brand: VigorBrand<"All", "Policy<Settings<Schema">;
2893
3249
  readonly concurrency: 5;
@@ -2895,9 +3251,12 @@ declare const vigorBase: {
2895
3251
  };
2896
3252
  readonly middlewares: {
2897
3253
  readonly __brand: VigorBrand<"All", "Policy<Middlewares<Schema">;
2898
- readonly before: VigorAllEachMiddlewareFn[];
2899
- readonly after: VigorAllEachMiddlewareFn[];
2900
- readonly onError: VigorAllEachOnErrorFn[];
3254
+ readonly before: [];
3255
+ readonly after: [];
3256
+ readonly onResult: [];
3257
+ readonly beforeEach: [];
3258
+ readonly afterEach: [];
3259
+ readonly onErrorEach: [];
2901
3260
  };
2902
3261
  };
2903
3262
  readonly cast: symbol & {
@@ -3059,4 +3418,4 @@ declare class VigorAllError<C extends VigorAllErrorCodes, T extends VigorAllSche
3059
3418
  constructor(code: C, options: VigorErrorOptions<VigorAllErrorDatas<C>, VigorAllContextSchema<T>>);
3060
3419
  }
3061
3420
 
3062
- export { VigorAll, VigorAllBase, type VigorAllEachMiddlewareFn, type VigorAllEachOnErrorFn, VigorAllError, type VigorAllErrorCodes, type VigorAllErrorDatas, VigorAllErrorMessageFuncs, VigorAllPolicyBase, VigorAllPolicyMiddlewares, VigorAllPolicyMiddlewaresBase, type VigorAllPolicyMiddlewaresSchema, type VigorAllPolicySchema, VigorAllPolicySettings, VigorAllPolicySettingsBase, type VigorAllPolicySettingsSchema, type VigorAllSchema, type VigorAllTask, type VigorBuiltin, type VigorCastResult, type VigorConcat, type VigorDeepMerge, type VigorDeepPartial, VigorError, type VigorErrorOptions, VigorFetch, VigorFetchBase, VigorFetchError, type VigorFetchErrorCodes, type VigorFetchErrorDatas, VigorFetchErrorMessageFuncs, VigorFetchPolicyBase, VigorFetchPolicyMiddlewares, type VigorFetchPolicyMiddlewaresApi, VigorFetchPolicyMiddlewaresBase, type VigorFetchPolicyMiddlewaresFluent, type VigorFetchPolicyMiddlewaresIntercept, type VigorFetchPolicyMiddlewaresSchema, type VigorFetchPolicySchema, VigorFetchPolicySettings, VigorFetchPolicySettingsBase, type VigorFetchPolicySettingsSchema, type VigorFetchSchema, type VigorInstance, VigorJitter, type VigorLastOf, type VigorMergeMode, type VigorMergeStrategy, VigorParse, VigorParseBase, VigorParseContentTypeStrategy, VigorParseError, type VigorParseErrorCodes, type VigorParseErrorDatas, VigorParseErrorMessageFuncs, VigorParsePolicyBase, VigorParsePolicyMiddlewares, type VigorParsePolicyMiddlewaresApi, VigorParsePolicyMiddlewaresBase, type VigorParsePolicyMiddlewaresFluent, type VigorParsePolicyMiddlewaresIntercept, type VigorParsePolicyMiddlewaresSchema, type VigorParsePolicySchema, VigorParsePolicySettings, VigorParsePolicySettingsBase, type VigorParsePolicySettingsSchema, VigorParsePolicyStrategies, VigorParsePolicyStrategiesBase, type VigorParsePolicyStrategiesSchema, type VigorParseSchema, VigorParseSniffStrategy, type VigorParseStrategyFunc, type VigorPlugin, type VigorPrimitive, type VigorReplaceType, VigorRetry, VigorRetryBase, VigorRetryError, type VigorRetryErrorCodes, type VigorRetryErrorDatas, VigorRetryErrorMessageFuncs, type VigorRetryPipeInitialContext, type VigorRetryPipeResult, type VigorRetryPipeStepResult, type VigorRetryPipeStepRetryIf, type VigorRetryPipeStepVoid, VigorRetryPolicyAlgorithms, VigorRetryPolicyAlgorithmsBackoff, VigorRetryPolicyAlgorithmsBackoffBase, type VigorRetryPolicyAlgorithmsBackoffSchema, VigorRetryPolicyAlgorithmsBase, VigorRetryPolicyAlgorithmsConstant, VigorRetryPolicyAlgorithmsConstantBase, type VigorRetryPolicyAlgorithmsConstantSchema, VigorRetryPolicyAlgorithmsCustom, VigorRetryPolicyAlgorithmsCustomBase, type VigorRetryPolicyAlgorithmsCustomSchema, VigorRetryPolicyAlgorithmsLinear, VigorRetryPolicyAlgorithmsLinearBase, type VigorRetryPolicyAlgorithmsLinearSchema, type VigorRetryPolicyAlgorithmsSchema, VigorRetryPolicyBase, VigorRetryPolicyMiddlewares, type VigorRetryPolicyMiddlewaresApi, VigorRetryPolicyMiddlewaresBase, type VigorRetryPolicyMiddlewaresFluent, type VigorRetryPolicyMiddlewaresIntercept, type VigorRetryPolicyMiddlewaresPipe, type VigorRetryPolicyMiddlewaresSchema, type VigorRetryPolicySchema, VigorRetryPolicySettings, VigorRetryPolicySettingsBase, type VigorRetryPolicySettingsSchema, type VigorRetrySchema, type VigorReturnType, type VigorSimplify, VigorStatus, type VigorStringable, vigor as default, vigor };
3421
+ export { VigorAll, VigorAllBase, type VigorAllEachMiddlewareFn, type VigorAllEachOnErrorFn, VigorAllError, type VigorAllErrorCodes, type VigorAllErrorDatas, VigorAllErrorMessageFuncs, type VigorAllNaturalResult, type VigorAllPipeInitialContext, type VigorAllPipeResult, type VigorAllPipeStepResult, type VigorAllPipeStepVoid, VigorAllPolicyBase, VigorAllPolicyMiddlewares, type VigorAllPolicyMiddlewaresApi, VigorAllPolicyMiddlewaresBase, type VigorAllPolicyMiddlewaresFluent, type VigorAllPolicyMiddlewaresIntercept, type VigorAllPolicyMiddlewaresPipe, type VigorAllPolicyMiddlewaresSchema, type VigorAllPolicySchema, VigorAllPolicySettings, VigorAllPolicySettingsBase, type VigorAllPolicySettingsSchema, type VigorAllSchema, type VigorAllTask, type VigorAllTaskResult, type VigorAllTasksTuple, type VigorBuiltin, type VigorCastResult, type VigorConcat, type VigorDeepMerge, type VigorDeepPartial, VigorError, type VigorErrorOptions, VigorFetch, VigorFetchBase, VigorFetchError, type VigorFetchErrorCodes, type VigorFetchErrorDatas, VigorFetchErrorMessageFuncs, type VigorFetchPipeInitialContext, type VigorFetchPipeResult, type VigorFetchPipeStepResult, type VigorFetchPipeStepVoid, VigorFetchPolicyBase, VigorFetchPolicyMiddlewares, type VigorFetchPolicyMiddlewaresApi, VigorFetchPolicyMiddlewaresBase, type VigorFetchPolicyMiddlewaresFluent, type VigorFetchPolicyMiddlewaresIntercept, type VigorFetchPolicyMiddlewaresPipe, type VigorFetchPolicyMiddlewaresSchema, type VigorFetchPolicySchema, VigorFetchPolicySettings, VigorFetchPolicySettingsBase, type VigorFetchPolicySettingsSchema, type VigorFetchSchema, type VigorInstance, VigorJitter, type VigorLastOf, type VigorMergeMode, type VigorMergeStrategy, VigorParse, VigorParseBase, VigorParseContentTypeStrategy, VigorParseError, type VigorParseErrorCodes, type VigorParseErrorDatas, VigorParseErrorMessageFuncs, type VigorParsePipeInitialContext, type VigorParsePipeResult, type VigorParsePipeStepResult, type VigorParsePipeStepVoid, VigorParsePolicyBase, VigorParsePolicyMiddlewares, type VigorParsePolicyMiddlewaresApi, VigorParsePolicyMiddlewaresBase, type VigorParsePolicyMiddlewaresFluent, type VigorParsePolicyMiddlewaresIntercept, type VigorParsePolicyMiddlewaresPipe, type VigorParsePolicyMiddlewaresSchema, type VigorParsePolicySchema, VigorParsePolicySettings, VigorParsePolicySettingsBase, type VigorParsePolicySettingsSchema, VigorParsePolicyStrategies, VigorParsePolicyStrategiesBase, type VigorParsePolicyStrategiesSchema, type VigorParseSchema, VigorParseSniffStrategy, type VigorParseStrategyFunc, type VigorPlugin, type VigorPrimitive, type VigorReplaceType, VigorRetry, VigorRetryBase, VigorRetryError, type VigorRetryErrorCodes, type VigorRetryErrorDatas, VigorRetryErrorMessageFuncs, type VigorRetryPipeInitialContext, type VigorRetryPipeResult, type VigorRetryPipeStepResult, type VigorRetryPipeStepRetryIf, type VigorRetryPipeStepVoid, VigorRetryPolicyAlgorithms, VigorRetryPolicyAlgorithmsBackoff, VigorRetryPolicyAlgorithmsBackoffBase, type VigorRetryPolicyAlgorithmsBackoffSchema, VigorRetryPolicyAlgorithmsBase, VigorRetryPolicyAlgorithmsConstant, VigorRetryPolicyAlgorithmsConstantBase, type VigorRetryPolicyAlgorithmsConstantSchema, VigorRetryPolicyAlgorithmsCustom, VigorRetryPolicyAlgorithmsCustomBase, type VigorRetryPolicyAlgorithmsCustomSchema, VigorRetryPolicyAlgorithmsLinear, VigorRetryPolicyAlgorithmsLinearBase, type VigorRetryPolicyAlgorithmsLinearSchema, type VigorRetryPolicyAlgorithmsSchema, VigorRetryPolicyBase, VigorRetryPolicyMiddlewares, type VigorRetryPolicyMiddlewaresApi, VigorRetryPolicyMiddlewaresBase, type VigorRetryPolicyMiddlewaresFluent, type VigorRetryPolicyMiddlewaresIntercept, type VigorRetryPolicyMiddlewaresPipe, type VigorRetryPolicyMiddlewaresSchema, type VigorRetryPolicySchema, VigorRetryPolicySettings, VigorRetryPolicySettingsBase, type VigorRetryPolicySettingsSchema, type VigorRetrySchema, type VigorReturnType, type VigorSimplify, VigorStatus, type VigorStringable, vigor as default, vigor };