@softistx/riva 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +168 -2
- package/dist/batch.d.ts +5 -0
- package/dist/batch.d.ts.map +1 -0
- package/dist/chunks/index-2g2s3y31.js +58 -0
- package/dist/chunks/index-2g2s3y31.js.map +10 -0
- package/dist/chunks/index-46sbdyt0.js +84 -0
- package/dist/chunks/index-46sbdyt0.js.map +12 -0
- package/dist/chunks/index-5xnfwj57.js +21 -0
- package/dist/chunks/index-5xnfwj57.js.map +10 -0
- package/dist/chunks/index-asz1gnp1.js +50 -0
- package/dist/chunks/index-asz1gnp1.js.map +10 -0
- package/dist/chunks/index-e4vzsfy1.js +253 -0
- package/dist/chunks/index-e4vzsfy1.js.map +11 -0
- package/dist/chunks/index-tn8ankny.js +137 -0
- package/dist/chunks/index-tn8ankny.js.map +10 -0
- package/dist/chunks/index-vz93xwnj.js +35 -0
- package/dist/chunks/index-vz93xwnj.js.map +10 -0
- package/dist/chunks/index-y6bzw104.js +53 -0
- package/dist/chunks/index-y6bzw104.js.map +11 -0
- package/dist/client.d.ts +48 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/computed.d.ts +21 -0
- package/dist/computed.d.ts.map +1 -0
- package/dist/data/index.d.ts +19 -0
- package/dist/data/index.d.ts.map +1 -0
- package/dist/data/index.js +60 -0
- package/dist/data/index.js.map +10 -0
- package/dist/data/types.d.ts +12 -0
- package/dist/data/types.d.ts.map +1 -0
- package/dist/duration.d.ts +5 -0
- package/dist/duration.d.ts.map +1 -0
- package/dist/effect.d.ts +5 -0
- package/dist/effect.d.ts.map +1 -0
- package/dist/entities/api.d.ts +18 -0
- package/dist/entities/api.d.ts.map +1 -0
- package/dist/entities/denormalize.d.ts +13 -0
- package/dist/entities/denormalize.d.ts.map +1 -0
- package/dist/entities/identity.d.ts +11 -0
- package/dist/entities/identity.d.ts.map +1 -0
- package/dist/entities/index.d.ts +6 -0
- package/dist/entities/index.d.ts.map +1 -0
- package/dist/entities/index.js +414 -0
- package/dist/entities/index.js.map +16 -0
- package/dist/entities/json.d.ts +15 -0
- package/dist/entities/json.d.ts.map +1 -0
- package/dist/entities/normalize.d.ts +11 -0
- package/dist/entities/normalize.d.ts.map +1 -0
- package/dist/entities/policy.d.ts +41 -0
- package/dist/entities/policy.d.ts.map +1 -0
- package/dist/entities/store.d.ts +47 -0
- package/dist/entities/store.d.ts.map +1 -0
- package/dist/env.d.ts +15 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/errors.d.ts +38 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/flush.d.ts +11 -0
- package/dist/flush.d.ts.map +1 -0
- package/dist/graph.d.ts +47 -0
- package/dist/graph.d.ts.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +502 -0
- package/dist/index.js.map +18 -0
- package/dist/infinite/index.d.ts +3 -0
- package/dist/infinite/index.d.ts.map +1 -0
- package/dist/infinite/index.js +207 -0
- package/dist/infinite/index.js.map +13 -0
- package/dist/infinite/infinite.d.ts +8 -0
- package/dist/infinite/infinite.d.ts.map +1 -0
- package/dist/infinite/more.d.ts +19 -0
- package/dist/infinite/more.d.ts.map +1 -0
- package/dist/infinite/refetch.d.ts +16 -0
- package/dist/infinite/refetch.d.ts.map +1 -0
- package/dist/infinite/slots.d.ts +22 -0
- package/dist/infinite/slots.d.ts.map +1 -0
- package/dist/infinite/types.d.ts +68 -0
- package/dist/infinite/types.d.ts.map +1 -0
- package/dist/key.d.ts +3 -0
- package/dist/key.d.ts.map +1 -0
- package/dist/mutation-run.d.ts +5 -0
- package/dist/mutation-run.d.ts.map +1 -0
- package/dist/mutation.d.ts +53 -0
- package/dist/mutation.d.ts.map +1 -0
- package/dist/query-cache.d.ts +33 -0
- package/dist/query-cache.d.ts.map +1 -0
- package/dist/query-entry.d.ts +85 -0
- package/dist/query-entry.d.ts.map +1 -0
- package/dist/query-observe.d.ts +9 -0
- package/dist/query-observe.d.ts.map +1 -0
- package/dist/query-run.d.ts +12 -0
- package/dist/query-run.d.ts.map +1 -0
- package/dist/query.d.ts +100 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/retry.d.ts +18 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/scope.d.ts +16 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/signal.d.ts +22 -0
- package/dist/signal.d.ts.map +1 -0
- package/dist/ssr/codec.d.ts +10 -0
- package/dist/ssr/codec.d.ts.map +1 -0
- package/dist/ssr/dehydrate.d.ts +37 -0
- package/dist/ssr/dehydrate.d.ts.map +1 -0
- package/dist/ssr/hydrate.d.ts +20 -0
- package/dist/ssr/hydrate.d.ts.map +1 -0
- package/dist/ssr/index.d.ts +5 -0
- package/dist/ssr/index.d.ts.map +1 -0
- package/dist/ssr/index.js +136 -0
- package/dist/ssr/index.js.map +11 -0
- package/dist/store/def.d.ts +31 -0
- package/dist/store/def.d.ts.map +1 -0
- package/dist/store/index.d.ts +3 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +215 -0
- package/dist/store/index.js.map +14 -0
- package/dist/store/instance.d.ts +14 -0
- package/dist/store/instance.d.ts.map +1 -0
- package/dist/store/run.d.ts +12 -0
- package/dist/store/run.d.ts.map +1 -0
- package/dist/store/store.d.ts +10 -0
- package/dist/store/store.d.ts.map +1 -0
- package/dist/store/types.d.ts +70 -0
- package/dist/store/types.d.ts.map +1 -0
- package/dist/store/view.d.ts +10 -0
- package/dist/store/view.d.ts.map +1 -0
- package/docs/README.md +19 -0
- package/docs/guide/data.md +36 -0
- package/docs/guide/entities.md +90 -0
- package/docs/guide/errors.md +31 -0
- package/docs/guide/infinite.md +62 -0
- package/docs/guide/mutations.md +73 -0
- package/docs/guide/queries.md +93 -0
- package/docs/guide/signals.md +72 -0
- package/docs/guide/ssr.md +65 -0
- package/docs/guide/store.md +88 -0
- package/docs/troubleshooting.md +343 -0
- package/package.json +84 -5
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
# Troubleshooting
|
|
2
|
+
|
|
3
|
+
Each entry is headed by the message you will see.
|
|
4
|
+
|
|
5
|
+
## No RivaClient in scope
|
|
6
|
+
|
|
7
|
+
Code: `RIVA_SCOPE` (`RivaScopeError`).
|
|
8
|
+
|
|
9
|
+
**When:** `signal.get()`, `.set()`, `.subscribe()` or `computed.get()` ran outside any client, on the server or in a browser with no default client.
|
|
10
|
+
|
|
11
|
+
**Why:** definitions are stateless and hold no value; values live in a `RivaClient`. A module-level client on the server would leak between requests, so none is assumed.
|
|
12
|
+
|
|
13
|
+
**Fix:** read through the client, or run the code inside it.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
const client = createRivaClient(); // one per request on the server
|
|
17
|
+
client.get(count);
|
|
18
|
+
client.run(() => count.get());
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## setDefaultClient is browser-only
|
|
22
|
+
|
|
23
|
+
Code: `RIVA_SCOPE` (`RivaScopeError`).
|
|
24
|
+
|
|
25
|
+
**When:** `setDefaultClient(client)` ran where there is no `document`, that is on the server.
|
|
26
|
+
|
|
27
|
+
**Why:** a default client is module-level state; shared between requests it would mix one user's values into another's.
|
|
28
|
+
|
|
29
|
+
**Fix:** call it only in browser code. On the server, use the per-request client with `client.run(() => …)`. `setDefaultClient(undefined)` clears the default in a browser.
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
if (typeof document !== 'undefined') setDefaultClient(createRivaClient());
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Cycle detected
|
|
36
|
+
|
|
37
|
+
Code: `RIVA_CYCLE`.
|
|
38
|
+
|
|
39
|
+
**When:** a computed reads itself, directly or through other computeds.
|
|
40
|
+
|
|
41
|
+
**Why:** its value would depend on itself and can never settle.
|
|
42
|
+
|
|
43
|
+
**Fix:** break the loop: derive from signals, or move one side to a signal you set explicitly. Name computeds (`computed(fn, { name })`) so the message names the culprit.
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
const total = computed((get) => get(price) * get(quantity)); // not get(total)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Loop detected
|
|
50
|
+
|
|
51
|
+
Code: `RIVA_LOOP`.
|
|
52
|
+
|
|
53
|
+
**When:** a node re-ran more than 100 times in one flush, typically an effect or subscriber that writes a source it reads.
|
|
54
|
+
|
|
55
|
+
**Why:** each write re-triggers the node, so the flush never ends. The loop is cut and the error is thrown after the other notifications ran.
|
|
56
|
+
|
|
57
|
+
**Fix:** make the write converge (guard it with a condition), write to a different signal, or read the source with `untracked`. Name the node with `{ name }` to find it.
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
client.effect(() => {
|
|
61
|
+
const n = client.get(count);
|
|
62
|
+
if (n < 5) client.set(count, n + 1); // converges
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## RIVA_STORE
|
|
67
|
+
|
|
68
|
+
Code: `RIVA_STORE`. Thrown by `@softistx/riva/store` and `useStore`. Every message starts with `Store "<name>": `, then the key and the refusal.
|
|
69
|
+
|
|
70
|
+
### Store "<name>": "<key>" is written outside an action. Write it in an action of the store.
|
|
71
|
+
|
|
72
|
+
A state key was written with `Store.key.set(…)` or `client.set(Store.key, …)`, in a component, a listener or a test. Only an action writes. Write it in an action of the store (`s.key = …`), and call the action.
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
const Counter = store({
|
|
76
|
+
name: 'counter',
|
|
77
|
+
state: { n: 0 },
|
|
78
|
+
actions: { inc(s) { s.n += 1; } },
|
|
79
|
+
});
|
|
80
|
+
Counter.inc(); // not Counter.n.set(1)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Store "<name>": "<key>" is written after its action settled.
|
|
84
|
+
|
|
85
|
+
An action kept `s` (in a timer or a callback) and wrote after the action's promise settled. Write only while the action runs: `await` what the write depends on, or start another action.
|
|
86
|
+
|
|
87
|
+
### Store "<name>": "<key>" is not a state key, so it cannot be written.
|
|
88
|
+
|
|
89
|
+
`s.total = …` where `total` is a computed, or a key the store does not have. Only state is writable.
|
|
90
|
+
|
|
91
|
+
### Store "<name>": a computed cannot write "<key>".
|
|
92
|
+
|
|
93
|
+
A computed assigned on its `s`. A computed only reads; move the write to an action.
|
|
94
|
+
|
|
95
|
+
### Store "<name>": "<key>" is read-only here; write it in an action.
|
|
96
|
+
|
|
97
|
+
A write on the view `useStore(Store)` or `Store.bind(client)[0]` returns. Write through the actions (`a.add(…)`), never on `s`.
|
|
98
|
+
|
|
99
|
+
### Store "<name>": the key "<key>" is taken (a state, computed or action key, or one of kind, name, reset, bind, then).
|
|
100
|
+
|
|
101
|
+
A state, computed or action key repeats, or is one of `kind`, `name`, `reset`, `bind`, `then`. Rename it. The reserved keys are also a type error.
|
|
102
|
+
|
|
103
|
+
### Store "<name>": two stores are named "<name>" on this client: give each store a unique name.
|
|
104
|
+
|
|
105
|
+
Two store definitions with one name were used on one client, on the server. Give each a unique `name`. In a browser the newer definition takes over instead (a hot-reloaded module), so this error does not happen there.
|
|
106
|
+
|
|
107
|
+
### A nested mutation throws a `TypeError` in development
|
|
108
|
+
|
|
109
|
+
Stored values (initial, written or hydrated) are deep-frozen outside production, so `s.items.push(b)` or `s.items[0].title = …` throws. Replace the value: `s.items = [...s.items, b]`.
|
|
110
|
+
|
|
111
|
+
### The context lands in an optional argument, or `a.inc()` does not type
|
|
112
|
+
|
|
113
|
+
The context goes right after the arguments the caller passes or the function declares, whichever is longer. A default value before it (`(s, page = 1, ctx)`) shortens the function's declared length and moves it, and an action whose last parameter is optional or defaulted with no context after it receives the context in that parameter. That shape is a type error (`Add "ctx?: StoreContext" as the last parameter…`): declare the context last.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
inc(s, by?: number, ctx?: StoreContext) { s.n += by ?? 1; }
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Reads after an `await` fail with `RIVA_SCOPE`
|
|
120
|
+
|
|
121
|
+
`BookStore.total.get()` inside an async action, after the first `await`, has no ambient client. Read `s.total` instead: `s` stays bound to the action's client.
|
|
122
|
+
|
|
123
|
+
## Invalid duration
|
|
124
|
+
|
|
125
|
+
Code: `RIVA_DURATION` (`RivaError`).
|
|
126
|
+
|
|
127
|
+
**When:** an option such as `staleTime`, `gcTime` or `refetchEvery` got a value it cannot read, at the `query({...})` call.
|
|
128
|
+
|
|
129
|
+
**Why:** a duration is a non-negative number of milliseconds (or `Infinity`), or a string of a number (decimals allowed, e.g. `"1.5s"`) and exactly one unit: `ms`, `s`, `m`, `h`.
|
|
130
|
+
|
|
131
|
+
**Fix:**
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
query({ id: 'user', staleTime: '30s', gcTime: '5m', fetch }); // not "30" or "5 min"
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Cannot derive a cache key
|
|
138
|
+
|
|
139
|
+
Code: `RIVA_KEY` (`RivaError`).
|
|
140
|
+
|
|
141
|
+
**When:** the variables of a query hold a function, a symbol, a bigint, a non-finite number, an invalid `Date` or a circular reference.
|
|
142
|
+
|
|
143
|
+
**Why:** the key is the definition id plus the stable-serialized variables, so they must be JSON-like.
|
|
144
|
+
|
|
145
|
+
**Fix:** pass plain data; convert before the call (`id.toString()` for a bigint, an ISO string for an odd date), and keep callbacks out of the variables.
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
user.ensure(client, { id: String(id) });
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Two definitions share the id "<id>": define each query once (a module-level const) and import it, or pass a distinct id.
|
|
152
|
+
|
|
153
|
+
Code: `RIVA_KEY` (`RivaError`).
|
|
154
|
+
|
|
155
|
+
**When:** two `query` definitions with the same `id` are read on one client on the server. In a browser a hot reload takes over: the newest definition replaces the old one under that id and nothing is thrown. A replaced definition that comes back (the old one read again after the new one) throws.
|
|
156
|
+
|
|
157
|
+
**Why:** the cache key is the definition id plus the variables, so two definitions with one id would share one entry and the second would silently run the first's `fetch`.
|
|
158
|
+
|
|
159
|
+
**Fix:** define each query once, as a module-level const, and import it where it is read. Pass a distinct `id` only when two definitions are genuinely different.
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
// queries.ts
|
|
163
|
+
export const user = query({ id: 'user', fetch });
|
|
164
|
+
|
|
165
|
+
// elsewhere
|
|
166
|
+
import { user } from './queries';
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
const admin = query({ id: 'admin', fetch }); // an escape hatch: not 'user' again
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## `Cannot cache the data: it holds <what>. Use JSON-like values (a Date is allowed).`
|
|
174
|
+
|
|
175
|
+
Code: `RIVA_CACHE` (`RivaError`).
|
|
176
|
+
|
|
177
|
+
**When:** a query with `cache: entities()` (or `writeEntity`) receives data holding a function, a symbol, a bigint, a non-finite number, a class instance other than `Date`, a `Map`/`Set` or a circular reference. A fetch rejects with it (the entry shows the error and keeps its previous data). `setData` throws it and leaves the entry untouched. A mutation with `cache: entities()` hits it too: data returned by `optimistic` makes `run` reject before anything is shown, and a server result refused at commit rolls the layers back; in both cases `updates` and `invalidates` do not run and `run` rejects with the error.
|
|
178
|
+
|
|
179
|
+
**Why:** the entity store merges and compares plain JSON data field by field, so it cannot hold anything else. Nothing is written when it throws.
|
|
180
|
+
|
|
181
|
+
**Fix:** return plain data from `fetch` (convert class instances with `toJSON()` or a mapper), or keep that query on the default keyed cache.
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
fetch: async () => (await res.json()) as Plain, // not a Map, not a model instance
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## This client already uses other entity identity rules
|
|
188
|
+
|
|
189
|
+
Code: `RIVA_CACHE` (`RivaError`).
|
|
190
|
+
|
|
191
|
+
**When:** two `entities()` policies with different `keys` or `identify` (compared by reference) meet on one client, or a policy with such rules is first used after `readEntity` or `writeEntity` filled the client's store.
|
|
192
|
+
|
|
193
|
+
**Why:** a client has one entity store with one identity rule, so the same object cannot be two entities.
|
|
194
|
+
|
|
195
|
+
**Fix:** share one policy, or the same options objects, between the client's queries; create it before any `readEntity`/`writeEntity`.
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
const cache = entities({ keys }); // one, module level
|
|
199
|
+
query({ id: 'a', cache, fetch });
|
|
200
|
+
query({ id: 'b', cache, fetch });
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## `The cache cannot read the query's data after a fetch.`
|
|
204
|
+
|
|
205
|
+
Code: `RIVA_CACHE` (`RivaError`).
|
|
206
|
+
|
|
207
|
+
**When:** a fetch succeeded but the query's cache policy cannot read the data it just stored back (`read` returns `undefined`): the entry shows the error status and `ensure` rejects with it. Only a cache that reads selectively can do it, such as the GraphQL `normalized()` one.
|
|
208
|
+
|
|
209
|
+
**Why:** the answer lacks something the cache needs (a selected field the server left out, an entity it did not identify), so the data would be served half-empty. A second fetch would give the same answer, so none is started. Separately, an observed query whose stored data stops reading later (an entity evicted) is refetched; the error clears once the data reads again.
|
|
210
|
+
|
|
211
|
+
**Fix:** have the source return everything the cache reads (a nullable GraphQL field must come back as `null`, not be left out), or stop reading the missing part. See the GraphQL cause in the [riva-graphql page](../../riva-graphql/docs/troubleshooting.md).
|
|
212
|
+
|
|
213
|
+
## `Cannot dehydrate <what> at <path>: snapshots hold JSON values and Dates. Convert it in the fetch, or keep it out of the cache.`
|
|
214
|
+
|
|
215
|
+
Code: `RIVA_SSR` (`RivaError`).
|
|
216
|
+
|
|
217
|
+
**When:** `dehydrate` meets a bigint, a function, a symbol, a `Map`, a `Set`, a class instance (other than `Date`), an invalid `Date` or a circular reference in a query entry's data or a named signal's value. `<path>` names the entry (or the signal) and the field, e.g. `invoices:{"year":2026}.data.items[0].total`.
|
|
218
|
+
|
|
219
|
+
**Why:** a snapshot travels as JSON, so it can hold only what JSON holds, plus Dates, `NaN` and the infinities, which riva tags and restores.
|
|
220
|
+
|
|
221
|
+
**Fix:** return plain data from `fetch` (a string or a number for a bigint, an array for a `Set`), or keep that query or signal out of the snapshot (leave `ssr: true` off the signal).
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
fetch: async () => (await res.json()).items.map((i) => ({ ...i, total: Number(i.total) })),
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## `Cannot dehydrate: two signals are named "<name>". Give each SSR signal a unique name, or set ssr: false.`
|
|
228
|
+
|
|
229
|
+
Code: `RIVA_SSR` (`RivaError`).
|
|
230
|
+
|
|
231
|
+
**When:** `dehydrate` finds two signals with the same `name` that the client has used.
|
|
232
|
+
|
|
233
|
+
**Why:** signals travel by name, so a snapshot could not tell which one a value belongs to.
|
|
234
|
+
|
|
235
|
+
**Fix:** rename one, or drop `ssr: true` from the one that stays local.
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
const a = signal('', { name: 'draft', ssr: true });
|
|
239
|
+
const b = signal('', { name: 'draft', ssr: true }); // collides with a
|
|
240
|
+
|
|
241
|
+
// fix: rename b, or drop ssr: true from the one that stays local
|
|
242
|
+
const local = signal('', { name: 'draft' });
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## `Cannot hydrate: this is not a snapshot dehydrate() made (version <v>).`
|
|
246
|
+
|
|
247
|
+
Code: `RIVA_SSR` (`RivaError`).
|
|
248
|
+
|
|
249
|
+
**When:** `hydrate` receives something that is not a snapshot of this format: `undefined` (the server sent nothing), an object of another shape, or another version.
|
|
250
|
+
|
|
251
|
+
**Why:** the snapshot's `v` is 1 and it holds `q` and `a`. A different value usually means the page carried something else, or the server and the browser run different versions of riva.
|
|
252
|
+
|
|
253
|
+
**Fix:** pass what `dehydrate` returned, unchanged, and keep both sides on one version of `@softistx/riva`.
|
|
254
|
+
|
|
255
|
+
```ts
|
|
256
|
+
import type { Snapshot } from '@softistx/riva/ssr';
|
|
257
|
+
|
|
258
|
+
hydrate(client, JSON.parse(payload) as Snapshot);
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Data refetches right after hydration
|
|
262
|
+
|
|
263
|
+
**When:** the page renders with the server's data, then the same requests go out again as soon as a component subscribes.
|
|
264
|
+
|
|
265
|
+
**Why:** hydrated entries keep their age. A query's `staleTime` defaults to 0, so data of any age is already stale and a subscription fetches it.
|
|
266
|
+
|
|
267
|
+
**Fix:** give the query a `staleTime` that covers the render, e.g. `staleTime: '30s'`. Fresh hydrated data is never fetched again.
|
|
268
|
+
|
|
269
|
+
```ts
|
|
270
|
+
const invoices = query({ id: 'invoices', staleTime: '30s', fetch });
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## The request was aborted
|
|
274
|
+
|
|
275
|
+
Code: `RIVA_ABORT` (`RivaAbortError`).
|
|
276
|
+
|
|
277
|
+
**When:** `ensure` rejects with it after the `signal` you passed aborted, or after `cancel` aborted the fetch you were waiting on. A mutation's `run(client, vars, { signal })` rejects with it too, and rolls back its optimistic layers, including while it waits for an earlier mutation to settle (it never commits afterwards).
|
|
278
|
+
|
|
279
|
+
**Why:** abort is a decision, not a failure: it is never retried and never stored as the query's error; the entry returns to its previous state.
|
|
280
|
+
|
|
281
|
+
**Fix:** catch it where you abort.
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
try {
|
|
285
|
+
await user.ensure(client, { id }, { signal });
|
|
286
|
+
} catch (e) {
|
|
287
|
+
if (!(e instanceof RivaAbortError)) throw e;
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## HTTP <status>
|
|
292
|
+
|
|
293
|
+
Code: `HTTP_<status>` (`RivaHttpError`, a `RivaRequestError`).
|
|
294
|
+
|
|
295
|
+
**When:** a fetcher threw `new RivaHttpError(status)` without a message, so the message is `HTTP 503`, `HTTP 404`...
|
|
296
|
+
|
|
297
|
+
**Why:** the server answered with an error status. It is retried for 5xx, 408 and 429 (per `retry`) and never for other statuses.
|
|
298
|
+
|
|
299
|
+
**Fix:** read `error.status` and `error.cause`; fix the request for a 4xx, or raise `retry` / wait for the server for a 5xx. Pass your own message as the second argument for a clearer text.
|
|
300
|
+
|
|
301
|
+
## Network error
|
|
302
|
+
|
|
303
|
+
Code: `RIVA_NETWORK` (`RivaNetworkError`, a `RivaRequestError`).
|
|
304
|
+
|
|
305
|
+
**When:** a fetcher threw `new RivaNetworkError()` without a message: the request never got a response (offline, DNS, CORS, connection reset).
|
|
306
|
+
|
|
307
|
+
**Why:** it is always retryable, so the engine retries it per `retry` before settling the error state.
|
|
308
|
+
|
|
309
|
+
**Fix:** check connectivity and the URL; look at `error.cause` for the underlying failure. On the server `retry` defaults to 0, so set it to retry there.
|
|
310
|
+
|
|
311
|
+
## `The data route answered <status> with a body that is not JSON.`
|
|
312
|
+
|
|
313
|
+
Code: `RIVA_INVALID_RESPONSE` (`RivaRequestError`, not retryable). Also `The data route answered without a "data" field.`
|
|
314
|
+
|
|
315
|
+
**When:** a call made through `postData` (`@softistx/riva/data`, so any `bffTransport`) got an answer that is not the `/_data` route's JSON: an HTML error page from a proxy, a login redirect, a route that is not a `dataRoute`.
|
|
316
|
+
|
|
317
|
+
**Why:** the transport expects `{ data }` or `{ error: { code, message, status } }`, and retrying cannot change what the URL serves.
|
|
318
|
+
|
|
319
|
+
**Fix:** check the URL (`url` option, default `/_data`) and that the route mounts `dataRoute`'s `action`. Look at the status the message names and at what sits in front of the route (a proxy, an auth redirect).
|
|
320
|
+
|
|
321
|
+
## `RIVA_UNKNOWN` on a hydrated error
|
|
322
|
+
|
|
323
|
+
Code: `RIVA_UNKNOWN`, on the `error` of a hydrated query entry.
|
|
324
|
+
|
|
325
|
+
**When:** a query failed on the server with something that was not a `RivaError` (a `TypeError` in a fetcher, a thrown string), and the browser reads the entry after `hydrate`.
|
|
326
|
+
|
|
327
|
+
**Why:** a snapshot carries codes only, never a message, a stack or a cause, so a server detail cannot leak. An error that is not a `RivaError` has no code to carry.
|
|
328
|
+
|
|
329
|
+
**Fix:** throw riva's errors from fetchers (`RivaHttpError`, `RivaRequestError`...), or map the failure in the fetcher. Log the original error on the server.
|
|
330
|
+
|
|
331
|
+
## `Several listeners or computeds threw.`
|
|
332
|
+
|
|
333
|
+
An `AggregateError`, thrown when a write flushes its listeners and more than one of them (an `effect`, a `computed`, a subscriber) throws. With a single failure that error is rethrown as is.
|
|
334
|
+
|
|
335
|
+
**Fix:** read `error.errors`: it lists every failure, in the order they ran. Fix each listener; one that throws never stops the others from running.
|
|
336
|
+
|
|
337
|
+
## `The data route answered without a "data" field.`
|
|
338
|
+
|
|
339
|
+
Code: `RIVA_INVALID_RESPONSE` (`RivaRequestError`, not retryable).
|
|
340
|
+
|
|
341
|
+
**When:** the data route answered 2xx with JSON that is not `{ data }`, for example a proxy's or a login page's body.
|
|
342
|
+
|
|
343
|
+
**Fix:** check that the URL given to `postData` (or `bffTransport`) reaches the `dataRoute` action and not another handler; look at the response in the network tab.
|
package/package.json
CHANGED
|
@@ -1,6 +1,85 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@softistx/riva",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Core: signals, RivaClient, query and mutation engine, normalized and keyed cache, pagination, optimistic layer, dehydrate and hydrate. Pure TypeScript, no DOM, no React.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"docs",
|
|
13
|
+
"README.md",
|
|
14
|
+
"package.json",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"default": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./entities": {
|
|
24
|
+
"types": "./dist/entities/index.d.ts",
|
|
25
|
+
"import": "./dist/entities/index.js",
|
|
26
|
+
"default": "./dist/entities/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./infinite": {
|
|
29
|
+
"types": "./dist/infinite/index.d.ts",
|
|
30
|
+
"import": "./dist/infinite/index.js",
|
|
31
|
+
"default": "./dist/infinite/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./ssr": {
|
|
34
|
+
"types": "./dist/ssr/index.d.ts",
|
|
35
|
+
"import": "./dist/ssr/index.js",
|
|
36
|
+
"default": "./dist/ssr/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./store": {
|
|
39
|
+
"types": "./dist/store/index.d.ts",
|
|
40
|
+
"import": "./dist/store/index.js",
|
|
41
|
+
"default": "./dist/store/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./data": {
|
|
44
|
+
"types": "./dist/data/index.d.ts",
|
|
45
|
+
"import": "./dist/data/index.js",
|
|
46
|
+
"default": "./dist/data/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./package.json": "./package.json"
|
|
49
|
+
},
|
|
50
|
+
"keywords": [
|
|
51
|
+
"state",
|
|
52
|
+
"signals",
|
|
53
|
+
"cache",
|
|
54
|
+
"graphql",
|
|
55
|
+
"rest",
|
|
56
|
+
"ssr"
|
|
57
|
+
],
|
|
58
|
+
"repository": {
|
|
59
|
+
"type": "git",
|
|
60
|
+
"url": "git+https://github.com/softistx/riva.git",
|
|
61
|
+
"directory": "packages/riva"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"registry": "https://registry.npmjs.org/",
|
|
65
|
+
"access": "public"
|
|
66
|
+
},
|
|
67
|
+
"scripts": {
|
|
68
|
+
"build": "bun run ../../build.ts",
|
|
69
|
+
"test": "bun test src",
|
|
70
|
+
"typecheck": "bun check"
|
|
71
|
+
},
|
|
72
|
+
"devDependencies": {
|
|
73
|
+
"@types/bun": "^1.4.5"
|
|
74
|
+
},
|
|
75
|
+
"nxgt": {
|
|
76
|
+
"entrypoints": [
|
|
77
|
+
"src/index.ts",
|
|
78
|
+
"src/entities/index.ts",
|
|
79
|
+
"src/infinite/index.ts",
|
|
80
|
+
"src/ssr/index.ts",
|
|
81
|
+
"src/data/index.ts",
|
|
82
|
+
"src/store/index.ts"
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
}
|