vigor-fetch 5.0.0 → 5.1.0
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 +7 -0
- package/dist/index.d.cts +298 -316
- package/dist/index.d.ts +298 -316
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -358,6 +358,13 @@ Every stage takes a mode as the first argument: `"fluent"` (return a plain value
|
|
|
358
358
|
)
|
|
359
359
|
```
|
|
360
360
|
|
|
361
|
+
**The returned context replaces `ctx`** — at runtime and in the types. Return values are only checked for being context-shaped; what you change is what carries on:
|
|
362
|
+
|
|
363
|
+
- Returning `ctx` (sync or `async`) changes nothing, so the types stay those of the finished builder — a middleware registered before `.cast()`, `.apiMap()` or `.target()` doesn't freeze the result at that point.
|
|
364
|
+
- Every key you change is overwritten from then on: `({ ...ctx, record: { traceId } })` in `before` types `ctx.record` in every later stage, and `({ ...ctx, result: x })` in `after`/`onResult` makes `x` the result (and what the next `onResult` receives). A fluent `onResult`'s return value — awaited — overwrites `result` the same way.
|
|
365
|
+
- Keys the runtime sets itself are reset where it sets them: `result` (and fetch's `response`) at the start of `after`, so changing `result` in `before` has no effect. A `result` changed in `onError` joins the result type as what a recovered request (`setResult`) resolves to.
|
|
366
|
+
- Each stage's context is its own: `retryIf`/`onRetry`/`onError` see what their stage's earlier middlewares changed, not `before`'s/`after`'s, since those may not have run.
|
|
367
|
+
|
|
361
368
|
| Stage | Runs | Intercept API |
|
|
362
369
|
|---|---|---|
|
|
363
370
|
| `before` | Before the request is sent | `throwError`, `setOptions`, `setHeaders`, `setBody` |
|