1# Chapter 19½: inside jev-worker/src — one file, two adapters 2 3Everything is in [lib.rs](lib.rs), top to bottom in the order you would 4read it. 5 6## lib.rs, in reading order 7 81. **The doc comment**: what the crate is and why it has no ledger. 92. **`MAX_BODY`**: 8 MiB, the most of a response body it accepts, the same 10 cap `jev-http` uses. A bigger body is `TooLarge`, which the client never 11 retries (the answer was already produced and billed). 123. **`FetchTransport`**: holds one URL. `FetchTransport::api()` is 13 `jev_protocol::ENDPOINT`; `FetchTransport::new(url)` is anything else. 144. **`request(url, sent)`**: turns `jev-client`'s `HttpRequest` into a 15 workers-rs `Request`: a `POST` with every header copied and the body as a 16 `Uint8Array`. A header that is not valid text, or a request workers-rs 17 will not build, is a `Config` error. 185. **`header_map(headers)`**: turns the response's `Headers` back into an 19 `http::HeaderMap`, skipping any pair `http` will not accept. 206. **`impl Transport for FetchTransport`**: `send` runs `Fetch::Request(..) 21 .send()`. A failed fetch is `Connect`; a failure reading the body is 22 `Interrupted`; an oversized body is `TooLarge`. `distrust_connection` is 23 empty, because `fetch` owns the connections. 247. **`WorkerRuntime`** and **`impl Runtime`**: `now` is 25 `jev_client::Instant::now()` (web-time's `performance.now()` clock), 26 `wall_clock` is `Date.now()`, `sleep` is a workers-rs `Delay`, `timeout` 27 races the future against a `Delay` with `futures_util::future::select`, 28 and `jitter` is `Math.random()`. 29 30| `fetch` outcome | `TransportErrorKind` | What the client does | 31| --- | --- | --- | 32| the request cannot be built | `Config` | fails at once | 33| `fetch` itself fails | `Connect` | retries with backoff | 34| reading the body fails | `Interrupted` | retries with backoff | 35| body over 8 MiB | `TooLarge` | fails at once | 36 37## Try it 38 39``` 40cargo build -p jev-worker --target wasm32-unknown-unknown 41``` 42 43## For the people who maintain it 44 45### In this folder 46 47| File | What | 48| --- | --- | 49| [lib.rs](lib.rs) | `FetchTransport`, `WorkerRuntime`, `MAX_BODY`. | 50| [CLAUDE.md](CLAUDE.md) | Invariants for agents. | 51 52← Previous: [Chapter 19: jev-worker](../) · Up: [jev-worker](../) · Next: [Chapter 20: jev-http](../../jev-http/) →