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.
Files changed (75) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/development/QueryAdapter-DUo338ga.js.map +1 -1
  3. package/dist/cjs/development/{QueryClient-vYETX2J2.js → QueryClient-Ce5Mnumb.js} +2 -2
  4. package/dist/cjs/development/QueryClient-Ce5Mnumb.js.map +1 -0
  5. package/dist/cjs/development/index.js +1 -1
  6. package/dist/cjs/{production/mutation-BnIsaYdm.js → development/mutation-GI_gTQEB.js} +2 -2
  7. package/dist/cjs/development/mutation-GI_gTQEB.js.map +1 -0
  8. package/dist/cjs/development/react/index.js +1 -1
  9. package/dist/cjs/development/rest/index.js +1 -1
  10. package/dist/cjs/development/topic/index.js +1 -1
  11. package/dist/cjs/development/topic/index.js.map +1 -1
  12. package/dist/cjs/production/QueryAdapter-DUo338ga.js.map +1 -1
  13. package/dist/cjs/production/{QueryClient-DJoA1ac6.js → QueryClient-BXGk-5PR.js} +2 -2
  14. package/dist/cjs/production/QueryClient-BXGk-5PR.js.map +1 -0
  15. package/dist/cjs/production/index.js +1 -1
  16. package/dist/cjs/{development/mutation-Beh3eks8.js → production/mutation-Bleah98u.js} +2 -2
  17. package/dist/cjs/production/mutation-Bleah98u.js.map +1 -0
  18. package/dist/cjs/production/react/index.js +1 -1
  19. package/dist/cjs/production/rest/index.js +1 -1
  20. package/dist/cjs/production/topic/index.js +1 -1
  21. package/dist/cjs/production/topic/index.js.map +1 -1
  22. package/dist/esm/QueryAdapter.d.ts +11 -0
  23. package/dist/esm/QueryAdapter.d.ts.map +1 -1
  24. package/dist/esm/QueryClient.d.ts +20 -6
  25. package/dist/esm/QueryClient.d.ts.map +1 -1
  26. package/dist/esm/QueryResult.d.ts.map +1 -1
  27. package/dist/esm/development/QueryAdapter-Bu5UJjE4.js.map +1 -1
  28. package/dist/esm/development/{QueryClient-zAD_O9xj.js → QueryClient-CmMSNSpt.js} +72 -48
  29. package/dist/esm/development/QueryClient-CmMSNSpt.js.map +1 -0
  30. package/dist/esm/development/index.js +2 -2
  31. package/dist/esm/development/{mutation-lw06SxbJ.js → mutation-BAM3eYqd.js} +2 -2
  32. package/dist/esm/development/mutation-BAM3eYqd.js.map +1 -0
  33. package/dist/esm/development/react/index.js +1 -1
  34. package/dist/esm/development/rest/index.js +2 -2
  35. package/dist/esm/development/topic/index.js +19 -18
  36. package/dist/esm/development/topic/index.js.map +1 -1
  37. package/dist/esm/mutation.d.ts +3 -3
  38. package/dist/esm/mutation.d.ts.map +1 -1
  39. package/dist/esm/production/QueryAdapter-Bu5UJjE4.js.map +1 -1
  40. package/dist/esm/production/{QueryClient-DSAzqTG6.js → QueryClient-3aWu_mJE.js} +62 -44
  41. package/dist/esm/production/QueryClient-3aWu_mJE.js.map +1 -0
  42. package/dist/esm/production/index.js +2 -2
  43. package/dist/esm/production/{mutation-Dmb9k9FG.js → mutation-YpiJLNWU.js} +2 -2
  44. package/dist/esm/production/mutation-YpiJLNWU.js.map +1 -0
  45. package/dist/esm/production/react/index.js +1 -1
  46. package/dist/esm/production/rest/index.js +2 -2
  47. package/dist/esm/production/topic/index.js +19 -18
  48. package/dist/esm/production/topic/index.js.map +1 -1
  49. package/dist/esm/query.d.ts +3 -3
  50. package/dist/esm/query.d.ts.map +1 -1
  51. package/dist/esm/topic/TopicQuery.d.ts +3 -2
  52. package/dist/esm/topic/TopicQuery.d.ts.map +1 -1
  53. package/package.json +1 -1
  54. package/plugin/docs/api/fetchium.md +2 -2
  55. package/plugin/docs/api/stores-async.md +9 -3
  56. package/plugin/docs/api/stores-sync.md +9 -3
  57. package/plugin/docs/core/entities.md +2 -2
  58. package/plugin/docs/core/queries.md +12 -19
  59. package/plugin/docs/core/streaming.md +7 -9
  60. package/plugin/docs/data/mutations.md +1 -1
  61. package/plugin/docs/guides/auth.md +65 -42
  62. package/plugin/docs/guides/error-handling.md +9 -5
  63. package/plugin/docs/guides/offline.md +11 -8
  64. package/plugin/docs/guides/testing.md +1 -1
  65. package/plugin/docs/quickstart.md +1 -1
  66. package/plugin/docs/reference/rest-queries.md +9 -9
  67. package/plugin/docs/setup/project-setup.md +5 -5
  68. package/dist/cjs/development/QueryClient-vYETX2J2.js.map +0 -1
  69. package/dist/cjs/development/mutation-Beh3eks8.js.map +0 -1
  70. package/dist/cjs/production/QueryClient-DJoA1ac6.js.map +0 -1
  71. package/dist/cjs/production/mutation-BnIsaYdm.js.map +0 -1
  72. package/dist/esm/development/QueryClient-zAD_O9xj.js.map +0 -1
  73. package/dist/esm/development/mutation-lw06SxbJ.js.map +0 -1
  74. package/dist/esm/production/QueryClient-DSAzqTG6.js.map +0 -1
  75. 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 `QueryClient` accepts a `fetch` function, which is the standard place to add global error handling. You can wrap the native `fetch` with your own logic:
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(store, { fetch: customFetch });
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 value={client} context={QueryClientContext}>
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(store, {
257
- fetch,
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, { fetch }, networkManager);
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(store, { fetch });
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:
@@ -41,7 +41,7 @@ export function renderApp(
41
41
  { client }: { client: QueryClient },
42
42
  ) {
43
43
  return render(
44
- <ContextProvider value={client} context={QueryClientContext}>
44
+ <ContextProvider contexts={[[QueryClientContext, client]]}>
45
45
  {ui}
46
46
  </ContextProvider>,
47
47
  );
@@ -72,7 +72,7 @@ const client = new QueryClient();
72
72
 
73
73
  function App() {
74
74
  return (
75
- <ContextProvider value={client} context={QueryClientContext}>
75
+ <ContextProvider contexts={[[QueryClientContext, client]]}>
76
76
  <YourApp />
77
77
  </ContextProvider>
78
78
  );
@@ -32,15 +32,15 @@ class GetUserPosts extends RESTQuery {
32
32
 
33
33
  ### Method reference
34
34
 
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
- | `getHeaders()` | `HeadersInit \| undefined` | Dynamic request headers |
42
- | `getRequestOptions()` | `RequestOptions \| undefined` | Dynamic fetch options |
43
- | `getConfig()` | `ConfigOptions \| undefined` | Dynamic cache/retry/network config |
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 | 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` | `string` | `''` | 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). |
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 value={client} context={QueryClientContext}>
103
+ <ContextProvider contexts={[[QueryClientContext, client]]}>
104
104
  <YourApp />
105
105
  </ContextProvider>
106
106
  );