src/read/client.ts is the only place the read, discuss and profile packages build a read request to a Seed site. src/read/superjson.ts decodes the {json, meta} envelope those endpoints answer with. Both are small and have no state.
Files
File | Role |
|---|---|
| |
| |
4 Bun tests |
client.ts
Export | What it does |
|---|---|
An | |
Builds | |
Fetches that URL and returns | |
|
The private getJson (L12-L25) sends Accept: application/json with exactTimeout: 15000 (the Exact fetch deadline, see The data module runtime). Network access is allowed by the net.fetch https: grant in app.ts, see Grants and capabilities.
Error messages
Condition | Message |
|---|---|
|
|
Status is not 2xx |
|
Body is not JSON, or the envelope fails to decode |
|
superjson.ts
The file's header explains why it exists: "Exact rejects superjson's is-what dependency (dynamic Function constructor)." The decoder is hand-written and fails closed: "Unknown types fail closed rather than silently changing the response's meaning" (L1-L3).
Returns body unchanged when it is not an object with a json key (plain JSON is still accepted).
Walks meta.values, a tree whose leaves are type annotations, and replaces the value at each path.
Applies meta.referentialEqualities (an object of source path to alias paths). An array form (cyclic root aliases) throws Unsupported API aliases.
Supported annotations (transform):
Annotation | Result |
|---|---|
|
|
|
|
|
|
| the number |
|
|
anything else | throws |
Tests
client.test.ts covers: decoding dates, bigint, undefined and bytes while still accepting plain JSON; an invalid annotation surfacing as The server sent something unreadable.; root values, escaped names and shared references; and the prototype guards.
Known limits
GET only. Writes go through a direct fetch in each package, see Publishing signed blobs.
No retry and no caching here. Caches live in load.ts and discuss/load.ts.
Me does not use this client: it has its own fetchJson with shorter timeouts.
Related
Seed site read API: every endpoint and parameter shape sent through api
Do you like what you are reading? Subscribe to receive updates.
Unsubscribe anytime