fetchium 0.2.1 → 0.2.3
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/CHANGELOG.md +14 -0
- package/dist/cjs/development/QueryAdapter-DUo338ga.js.map +1 -1
- package/dist/cjs/development/{QueryClient-vYETX2J2.js → QueryClient-Ce5Mnumb.js} +2 -2
- package/dist/cjs/development/QueryClient-Ce5Mnumb.js.map +1 -0
- package/dist/cjs/development/index.js +1 -1
- package/dist/cjs/{production/mutation-BnIsaYdm.js → development/mutation-GI_gTQEB.js} +2 -2
- package/dist/cjs/development/mutation-GI_gTQEB.js.map +1 -0
- package/dist/cjs/development/react/index.js +1 -1
- package/dist/cjs/development/rest/index.js +1 -1
- package/dist/cjs/development/topic/index.js +1 -1
- package/dist/cjs/development/topic/index.js.map +1 -1
- package/dist/cjs/production/QueryAdapter-DUo338ga.js.map +1 -1
- package/dist/cjs/production/{QueryClient-DJoA1ac6.js → QueryClient-BXGk-5PR.js} +2 -2
- package/dist/cjs/production/QueryClient-BXGk-5PR.js.map +1 -0
- package/dist/cjs/production/index.js +1 -1
- package/dist/cjs/{development/mutation-Beh3eks8.js → production/mutation-Bleah98u.js} +2 -2
- package/dist/cjs/production/mutation-Bleah98u.js.map +1 -0
- package/dist/cjs/production/react/index.js +1 -1
- package/dist/cjs/production/rest/index.js +1 -1
- package/dist/cjs/production/topic/index.js +1 -1
- package/dist/cjs/production/topic/index.js.map +1 -1
- package/dist/esm/QueryAdapter.d.ts +11 -0
- package/dist/esm/QueryAdapter.d.ts.map +1 -1
- package/dist/esm/QueryClient.d.ts +20 -6
- package/dist/esm/QueryClient.d.ts.map +1 -1
- package/dist/esm/QueryResult.d.ts.map +1 -1
- package/dist/esm/development/QueryAdapter-Bu5UJjE4.js.map +1 -1
- package/dist/esm/development/{QueryClient-zAD_O9xj.js → QueryClient-CmMSNSpt.js} +72 -48
- package/dist/esm/development/QueryClient-CmMSNSpt.js.map +1 -0
- package/dist/esm/development/index.js +2 -2
- package/dist/esm/development/{mutation-lw06SxbJ.js → mutation-BAM3eYqd.js} +2 -2
- package/dist/esm/development/mutation-BAM3eYqd.js.map +1 -0
- package/dist/esm/development/react/index.js +1 -1
- package/dist/esm/development/rest/index.js +2 -2
- package/dist/esm/development/topic/index.js +19 -18
- package/dist/esm/development/topic/index.js.map +1 -1
- package/dist/esm/mutation.d.ts +3 -3
- package/dist/esm/mutation.d.ts.map +1 -1
- package/dist/esm/production/QueryAdapter-Bu5UJjE4.js.map +1 -1
- package/dist/esm/production/{QueryClient-DSAzqTG6.js → QueryClient-3aWu_mJE.js} +62 -44
- package/dist/esm/production/QueryClient-3aWu_mJE.js.map +1 -0
- package/dist/esm/production/index.js +2 -2
- package/dist/esm/production/{mutation-Dmb9k9FG.js → mutation-YpiJLNWU.js} +2 -2
- package/dist/esm/production/mutation-YpiJLNWU.js.map +1 -0
- package/dist/esm/production/react/index.js +1 -1
- package/dist/esm/production/rest/index.js +2 -2
- package/dist/esm/production/topic/index.js +19 -18
- package/dist/esm/production/topic/index.js.map +1 -1
- package/dist/esm/query.d.ts +3 -3
- package/dist/esm/query.d.ts.map +1 -1
- package/dist/esm/topic/TopicQuery.d.ts +3 -2
- package/dist/esm/topic/TopicQuery.d.ts.map +1 -1
- package/package.json +1 -1
- package/plugin/docs/api/fetchium.md +2 -2
- package/plugin/docs/api/stores-async.md +9 -3
- package/plugin/docs/api/stores-sync.md +9 -3
- package/plugin/docs/core/entities.md +2 -2
- package/plugin/docs/core/queries.md +12 -19
- package/plugin/docs/core/streaming.md +7 -9
- package/plugin/docs/data/mutations.md +1 -1
- package/plugin/docs/guides/auth.md +65 -42
- package/plugin/docs/guides/error-handling.md +9 -5
- package/plugin/docs/guides/offline.md +11 -8
- package/plugin/docs/guides/testing.md +1 -1
- package/plugin/docs/quickstart.md +1 -1
- package/plugin/docs/reference/rest-queries.md +9 -9
- package/plugin/docs/setup/project-setup.md +5 -5
- package/dist/cjs/development/QueryClient-vYETX2J2.js.map +0 -1
- package/dist/cjs/development/mutation-Beh3eks8.js.map +0 -1
- package/dist/cjs/production/QueryClient-DJoA1ac6.js.map +0 -1
- package/dist/cjs/production/mutation-BnIsaYdm.js.map +0 -1
- package/dist/esm/development/QueryClient-zAD_O9xj.js.map +0 -1
- package/dist/esm/development/mutation-lw06SxbJ.js.map +0 -1
- package/dist/esm/production/QueryClient-DSAzqTG6.js.map +0 -1
- package/dist/esm/production/mutation-Dmb9k9FG.js.map +0 -1
|
@@ -202,7 +202,7 @@ function UserProfile({ userId }: { userId: number }) {
|
|
|
202
202
|
|
|
203
203
|
Sometimes you need to intercept errors _before_ they reach individual queries --- for instance, redirecting to a login page on a 401, refreshing an auth token, or logging all failures to a telemetry service.
|
|
204
204
|
|
|
205
|
-
The `
|
|
205
|
+
The `RESTQueryAdapter` accepts a `fetch` function, which is the standard place to add global error handling. You can wrap the native `fetch` with your own logic:
|
|
206
206
|
|
|
207
207
|
```ts
|
|
208
208
|
function createFetchWithErrorHandling(baseFetch: typeof fetch) {
|
|
@@ -227,15 +227,19 @@ Then pass it when constructing the client:
|
|
|
227
227
|
```tsx
|
|
228
228
|
import { QueryClient, QueryClientContext } from 'fetchium';
|
|
229
229
|
import { SyncQueryStore, MemoryPersistentStore } from 'fetchium/stores/sync';
|
|
230
|
+
import { RESTQueryAdapter } from 'fetchium/rest';
|
|
230
231
|
import { ContextProvider } from 'signalium/react';
|
|
231
232
|
|
|
232
233
|
const store = new SyncQueryStore(new MemoryPersistentStore());
|
|
233
234
|
const customFetch = createFetchWithErrorHandling(fetch);
|
|
234
|
-
const client = new QueryClient(
|
|
235
|
+
const client = new QueryClient({
|
|
236
|
+
store,
|
|
237
|
+
adapters: [new RESTQueryAdapter({ fetch: customFetch })],
|
|
238
|
+
});
|
|
235
239
|
|
|
236
240
|
function App() {
|
|
237
241
|
return (
|
|
238
|
-
<ContextProvider
|
|
242
|
+
<ContextProvider contexts={[[QueryClientContext, client]]}>
|
|
239
243
|
<YourApp />
|
|
240
244
|
</ContextProvider>
|
|
241
245
|
);
|
|
@@ -253,8 +257,8 @@ Non-fatal parse failures (optional fields falling back to `undefined`, array ite
|
|
|
253
257
|
Fetchium routes these warnings through `QueryContext.log.warn`. You can plug in a custom logger when creating the `QueryClient`:
|
|
254
258
|
|
|
255
259
|
```ts
|
|
256
|
-
const client = new QueryClient(
|
|
257
|
-
|
|
260
|
+
const client = new QueryClient({
|
|
261
|
+
store,
|
|
258
262
|
log: {
|
|
259
263
|
warn: (message: string, ...args: unknown[]) => {
|
|
260
264
|
console.warn(message, ...args);
|
|
@@ -29,7 +29,7 @@ import { SyncQueryStore, MemoryPersistentStore } from 'fetchium/stores/sync';
|
|
|
29
29
|
const store = new SyncQueryStore(new MemoryPersistentStore());
|
|
30
30
|
const networkManager = new NetworkManager();
|
|
31
31
|
|
|
32
|
-
const client = new QueryClient(store,
|
|
32
|
+
const client = new QueryClient({ store, networkManager });
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
If you do not provide a `NetworkManager`, the `QueryClient` creates one automatically.
|
|
@@ -124,7 +124,7 @@ The `SyncQueryStore` wraps a synchronous key-value store. It is the simplest opt
|
|
|
124
124
|
import { SyncQueryStore, MemoryPersistentStore } from 'fetchium/stores/sync';
|
|
125
125
|
|
|
126
126
|
const store = new SyncQueryStore(new MemoryPersistentStore());
|
|
127
|
-
const client = new QueryClient(
|
|
127
|
+
const client = new QueryClient({ store });
|
|
128
128
|
```
|
|
129
129
|
|
|
130
130
|
The `MemoryPersistentStore` keeps everything in memory --- data is lost when the page is refreshed. For persistence across sessions, implement the `SyncPersistentStore` interface with a durable backend like `localStorage`.
|
|
@@ -220,18 +220,21 @@ Here is a complete example that sets up a `QueryClient` with persistence and net
|
|
|
220
220
|
```tsx
|
|
221
221
|
import { QueryClient, NetworkManager } from 'fetchium';
|
|
222
222
|
import { SyncQueryStore } from 'fetchium/stores/sync';
|
|
223
|
+
import { RESTQueryAdapter } from 'fetchium/rest';
|
|
223
224
|
|
|
224
225
|
const store = new SyncQueryStore(new LocalStoragePersistentStore());
|
|
225
226
|
const networkManager = new NetworkManager();
|
|
226
227
|
|
|
227
|
-
const client = new QueryClient(
|
|
228
|
+
const client = new QueryClient({
|
|
228
229
|
store,
|
|
229
|
-
{
|
|
230
|
-
fetch: globalThis.fetch,
|
|
231
|
-
baseUrl: 'https://api.example.com',
|
|
232
|
-
},
|
|
233
230
|
networkManager,
|
|
234
|
-
|
|
231
|
+
adapters: [
|
|
232
|
+
new RESTQueryAdapter({
|
|
233
|
+
fetch: globalThis.fetch,
|
|
234
|
+
baseUrl: 'https://api.example.com',
|
|
235
|
+
}),
|
|
236
|
+
],
|
|
237
|
+
});
|
|
235
238
|
```
|
|
236
239
|
|
|
237
240
|
With this setup:
|
|
@@ -32,15 +32,15 @@ class GetUserPosts extends RESTQuery {
|
|
|
32
32
|
|
|
33
33
|
### Method reference
|
|
34
34
|
|
|
35
|
-
| Method | Returns
|
|
36
|
-
| --------------------- |
|
|
37
|
-
| `getPath()` | `string \| undefined`
|
|
38
|
-
| `getMethod()` | `string`
|
|
39
|
-
| `getSearchParams()` | `Record \| undefined`
|
|
40
|
-
| `getBody()` | `Record \| undefined`
|
|
41
|
-
| `
|
|
42
|
-
| `
|
|
43
|
-
| `getConfig()` | `
|
|
35
|
+
| Method | Returns | Description |
|
|
36
|
+
| --------------------- | ---------------------------------- | ---------------------------------- |
|
|
37
|
+
| `getPath()` | `string \| undefined` | Dynamic path override |
|
|
38
|
+
| `getMethod()` | `string` | Dynamic HTTP method |
|
|
39
|
+
| `getSearchParams()` | `Record \| undefined` | Dynamic search params |
|
|
40
|
+
| `getBody()` | `Record \| undefined` | Dynamic request body |
|
|
41
|
+
| `getRequestOptions()` | `QueryRequestOptions \| undefined` | Dynamic fetch options |
|
|
42
|
+
| `getFetchNext()` | `FetchNextConfig \| undefined` | Dynamic pagination config |
|
|
43
|
+
| `getConfig()` | `QueryConfigOptions \| undefined` | Dynamic cache/retry/network config |
|
|
44
44
|
|
|
45
45
|
---
|
|
46
46
|
|
|
@@ -67,10 +67,10 @@ Once you need a `baseUrl`, auth headers, persistent storage, or a custom fetch w
|
|
|
67
67
|
|
|
68
68
|
`RESTQueryAdapter` is the transport layer for all REST queries and mutations. It accepts:
|
|
69
69
|
|
|
70
|
-
| Option | Type
|
|
71
|
-
| --------- |
|
|
72
|
-
| `fetch` | `Function`
|
|
73
|
-
| `baseUrl` | `
|
|
70
|
+
| Option | Type | Default | Description |
|
|
71
|
+
| --------- | -------------- | ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
72
|
+
| `fetch` | `Function` | `globalThis.fetch` | The fetch function used for all network requests. Pass a custom wrapper for auth headers, logging, or testing. |
|
|
73
|
+
| `baseUrl` | `BaseUrlValue` | `undefined` | Prepended to every query path. Set this to your API root (`https://api.example.com`) so your query paths can be relative (`/users/42` instead of the full URL). Accepts a string, a Signalium `Signal<string>`, or a `() => string` function. |
|
|
74
74
|
|
|
75
75
|
`fetch` is the _single point of control_ for how Fetchium makes network requests. Every REST query and mutation flows through this function, which means you can add authentication, logging, retry logic, or any other cross-cutting concern in one place. We cover this in depth in the [Auth & Headers](/guides/auth) guide.
|
|
76
76
|
|
|
@@ -100,7 +100,7 @@ const client = new QueryClient({
|
|
|
100
100
|
|
|
101
101
|
function App() {
|
|
102
102
|
return (
|
|
103
|
-
<ContextProvider
|
|
103
|
+
<ContextProvider contexts={[[QueryClientContext, client]]}>
|
|
104
104
|
<YourApp />
|
|
105
105
|
</ContextProvider>
|
|
106
106
|
);
|