@raf-query/react 0.1.3 → 0.1.4

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 CHANGED
@@ -1,10 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.4](https://github.com/KATT/raf-query/compare/0.1.3...0.1.4) (2026-10-12)
4
+
5
+ ### Features
6
+
7
+ * **core:** add per-query meta ([#26](https://github.com/KATT/raf-query/issues/26)) ([863c915](https://github.com/KATT/raf-query/commit/863c915d884bdfa3bcb3053da348d51aa0e697cf))
8
+
3
9
  ## [0.1.3](https://github.com/KATT/raf-query/compare/0.1.2...0.1.3) (2026-10-12)
4
10
 
5
11
  ### Features
6
12
 
7
- * **core:** cancel requests nobody reads anymore ([#27](https://github.com/KATT/raf-query/issues/27)) ([c3c1e4b](https://github.com/KATT/raf-query/commit/c3c1e4bb9250164b6df17d7d4b7bd4043f908961))
13
+ - **core:** cancel requests nobody reads anymore ([#27](https://github.com/KATT/raf-query/issues/27)) ([c3c1e4b](https://github.com/KATT/raf-query/commit/c3c1e4bb9250164b6df17d7d4b7bd4043f908961))
8
14
 
9
15
  ## [0.1.2](https://github.com/KATT/raf-query/compare/0.1.1...0.1.2) (2026-10-12)
10
16
 
package/README.md CHANGED
@@ -66,10 +66,46 @@ export function commentsQuery(input: { slug: string }) {
66
66
 
67
67
  Factories must take at most one argument; the type rejects two or more. The single argument is the query's **input** and must be serializable, because it is what a handle carries.
68
68
 
69
- A `queryFn` returns a value, a promise, or an [Effect](#effect). It receives `queryKey` and an abort `signal`; paged ones also get `pageParam` and `direction`. TypeScript infers the page type from `queryFn`, so if `getNextPageParam` comes first in the object literal (sorted keys), pass the types instead: `infiniteQueryOptions<CommentPage, number>({ ... })`.
69
+ A `queryFn` returns a value, a promise, or an [Effect](#effect). It receives `queryKey`, the query's [`meta`](#query-meta) and an abort `signal`; paged ones also get `pageParam` and `direction`. TypeScript infers the page type from `queryFn`, so if `getNextPageParam` comes first in the object literal (sorted keys), pass the types instead: `infiniteQueryOptions<CommentPage, number>({ ... })`.
70
70
 
71
71
  The factory is the only place a query is declared paged. Every other API — `prefetch`, `ensure`, `fetch`, `useQuery`, `useWaterfall`, `invalidate`, `setData` — takes either kind and infers the rest from the factory's type.
72
72
 
73
+ ### Query meta
74
+
75
+ `meta` attaches anything you want to know about a query elsewhere. It reaches the `queryFn` context, `Query.metaUnsafe(query)` (from the latest factory call) and the devtools. A common use is a per-query message for one global error handler:
76
+
77
+ ```ts
78
+ import { Query, QueryClient, queryOptions } from "@raf-query/react";
79
+
80
+ export function issuesQuery() {
81
+ return queryOptions({
82
+ queryKey: ["issues"],
83
+ queryFn: () => listIssues(),
84
+ meta: { errorMessage: "Couldn't load issues" },
85
+ });
86
+ }
87
+
88
+ const queryClient = new QueryClient({
89
+ onError: (error, query) => {
90
+ toast.error(
91
+ Query.metaUnsafe(query)?.errorMessage ?? "Something went wrong",
92
+ );
93
+ },
94
+ });
95
+ ```
96
+
97
+ `meta` is `Record<string, unknown>` by default. Type it for the whole app by augmenting `Register` in the package you import from (`@raf-query/react` re-exports it from `@raf-query/core`, so either works):
98
+
99
+ ```ts
100
+ declare module "@raf-query/react" {
101
+ interface Register {
102
+ queryMeta: { errorMessage?: string };
103
+ }
104
+ }
105
+ ```
106
+
107
+ `config.defaults` takes `meta` too, for queries that set none; a query's own `meta` replaces the default as a whole. `meta` is sent with dehydrated state, so keep it serializable: a hydrated entry reports the sender's `meta` until the receiving side calls its factory.
108
+
73
109
  ## Starting queries
74
110
 
75
111
  All three verbs live on the query client and accept a factory plus its input.
@@ -593,7 +629,7 @@ A button in the corner opens a panel docked to the edge of the viewport. The pan
593
629
  | `fresh` | Read, and within `staleTime` |
594
630
  | `inactive` | Nothing reads it; it's removed at `gcTime` |
595
631
 
596
- Select an entry to see its key, input, data, error, and last update, and to **Refetch**, **Invalidate**, **Reset** (drop its data, so readers suspend and refetch) or **Remove** it. The header filters entries by key, sorts them, and has **Invalidate all** and **Clear cache**. The panel keeps its open state and size in `localStorage`.
632
+ Select an entry to see its key, input, meta, data, error, and last update, and to **Refetch**, **Invalidate**, **Reset** (drop its data, so readers suspend and refetch) or **Remove** it. The header filters entries by key, sorts them, and has **Invalidate all** and **Clear cache**. The panel keeps its open state and size in `localStorage`.
597
633
 
598
634
  `QueryDevtools` props, all optional:
599
635
 
@@ -639,6 +675,7 @@ Query options, accepted by `queryOptions`, `infiniteQueryOptions` and `config.de
639
675
  | `retryDelay` (ms, or a function of the failure count) | Doubling from 1 s, at most 30 s |
640
676
  | `refetchOnWindowFocus`, `refetchOnReconnect` | `true` (only read, stale queries refetch) |
641
677
  | `structuralSharing` (keep deeply equal parts of data) | `true` |
678
+ | [`meta`](#query-meta) | None |
642
679
 
643
680
  `infiniteQueryOptions` also takes `getPreviousPageParam` and `maxPages`.
644
681
 
@@ -648,22 +685,23 @@ When the last reader of a query unsubscribes during a background refetch, a `que
648
685
 
649
686
  `@raf-query/core`:
650
687
 
651
- | Export | Use |
652
- | ------------------------------------------------------------ | -------------------------------------------------------------------------- |
653
- | `QueryCache` | The cache service (`qc.effect`): `make`, `layer`, and the verbs as Effects |
654
- | `Query` | Cache entries: `Query.fetch`, `Query.changes`, `Query.getUnsafe`, … |
655
- | `Platform` | The page the cache watches (focus, network); swap it in tests |
656
- | `queryOptions(options)` | Typed options for a query factory |
657
- | `infiniteQueryOptions(options)` | Typed options for a paged query factory |
658
- | `hashKey(key)`, `matchesKey(key, prefix)` | Key helpers |
659
- | `QueryObserver` | One reader's view of a query, with tracked results; for bindings |
660
- | `Query.CancelledError` | Failure of a request whose entry was removed or cleared before it settled |
661
- | `RedactedError` | What a streamed pending query rejects with when its server request failed |
662
- | `QueryHandle<TFactory>` | Handle type for props |
663
- | `EnsuredQueryHandle<TFactory>` | Handle type for props fed by `ensure` |
664
- | `Thenable<T>` | Promise with `status` / `value` / `reason`, read by `use()` |
665
- | `DataOf<TFactory>`, `InputOf<TFactory>`, `ErrorOf<TFactory>` | A factory's data, input and error types |
666
- | `ServicesOf<TFactory>` | The services a factory's `queryFn` Effect needs; `never` for promises |
688
+ | Export | Use |
689
+ | ------------------------------------------------------------ | --------------------------------------------------------------------------------------- |
690
+ | `QueryCache` | The cache service (`qc.effect`): `make`, `layer`, and the verbs as Effects |
691
+ | `Query` | Cache entries: `Query.fetch`, `Query.changes`, `Query.getUnsafe`, `Query.metaUnsafe`, … |
692
+ | `Platform` | The page the cache watches (focus, network); swap it in tests |
693
+ | `queryOptions(options)` | Typed options for a query factory |
694
+ | `infiniteQueryOptions(options)` | Typed options for a paged query factory |
695
+ | `hashKey(key)`, `matchesKey(key, prefix)` | Key helpers |
696
+ | `QueryObserver` | One reader's view of a query, with tracked results; for bindings |
697
+ | `Query.CancelledError` | Failure of a request whose entry was removed or cleared before it settled |
698
+ | `RedactedError` | What a streamed pending query rejects with when its server request failed |
699
+ | `QueryHandle<TFactory>` | Handle type for props |
700
+ | `EnsuredQueryHandle<TFactory>` | Handle type for props fed by `ensure` |
701
+ | `Thenable<T>` | Promise with `status` / `value` / `reason`, read by `use()` |
702
+ | `DataOf<TFactory>`, `InputOf<TFactory>`, `ErrorOf<TFactory>` | A factory's data, input and error types |
703
+ | `ServicesOf<TFactory>` | The services a factory's `queryFn` Effect needs; `never` for promises |
704
+ | `Register`, `QueryMeta` | Augment `Register` with `queryMeta` to type [`meta`](#query-meta) |
667
705
 
668
706
  `@raf-query/react` (plus all of the above):
669
707
 
@@ -273,6 +273,7 @@ function QueryDetails(props) {
273
273
  const query = props.row.query;
274
274
  const state = props.row.state;
275
275
  const options = query.options;
276
+ const meta = Query.metaUnsafe(query);
276
277
  const section = { padding: 8 };
277
278
  return /* @__PURE__ */ jsxs("section", {
278
279
  "aria-label": "Query details",
@@ -431,7 +432,21 @@ function QueryDetails(props) {
431
432
  palette,
432
433
  value: query.handle.input
433
434
  })
434
- })
435
+ }),
436
+ meta === void 0 ? null : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Heading, {
437
+ palette,
438
+ title: "Meta"
439
+ }), /* @__PURE__ */ jsx("div", {
440
+ style: {
441
+ ...section,
442
+ fontFamily: monoFamily
443
+ },
444
+ children: /* @__PURE__ */ jsx(Explorer, {
445
+ depth: 0,
446
+ palette,
447
+ value: meta
448
+ })
449
+ })] })
435
450
  ]
436
451
  });
437
452
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raf-query/react",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "React bindings for raf-query, a render-as-you-fetch query library",
5
5
  "keywords": [
6
6
  "query",
@@ -40,7 +40,7 @@
40
40
  "./tanstack-router": "./dist/tanstack-router.mjs"
41
41
  },
42
42
  "dependencies": {
43
- "@raf-query/core": "0.1.3",
43
+ "@raf-query/core": "0.1.4",
44
44
  "effect": "^4.0.1"
45
45
  },
46
46
  "peerDependencies": {