@beignet/react-query 0.0.22 → 0.0.24
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/README.md +53 -5
- package/package.json +1 -1
- package/skills/client/SKILL.md +11 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @beignet/react-query
|
|
2
2
|
|
|
3
|
+
## 0.0.24
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 91bc9b5: Harden framework security defaults for generated tenancy, auth secrets, CORS,
|
|
8
|
+
body limits, uploads, devtools, OpenAPI, rate-limit IP sources, public storage,
|
|
9
|
+
and Meilisearch query fields.
|
|
10
|
+
|
|
11
|
+
## 0.0.23
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- afa7179: Teach generated UI to colocate React Query options and invalidation helpers under feature client modules.
|
|
16
|
+
|
|
3
17
|
## 0.0.22
|
|
4
18
|
|
|
5
19
|
## 0.0.21
|
package/README.md
CHANGED
|
@@ -68,6 +68,54 @@ export function Providers({ children }: { children: ReactNode }) {
|
|
|
68
68
|
}
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
### 3. Add feature client helpers
|
|
72
|
+
|
|
73
|
+
Keep root `client/` for shared adapter setup, then put feature-specific query
|
|
74
|
+
options, mutation options, invalidation helpers, and hooks under
|
|
75
|
+
`features/<feature>/client/`:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
// features/todos/client/queries.ts
|
|
79
|
+
import type { QueryClient } from "@tanstack/react-query";
|
|
80
|
+
import { rq } from "@/client";
|
|
81
|
+
import { createTodo, listTodos } from "@/features/todos/contracts";
|
|
82
|
+
|
|
83
|
+
export function listTodosQueryOptions() {
|
|
84
|
+
return rq(listTodos).queryOptions({ query: {} });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function createTodoMutationOptions() {
|
|
88
|
+
return rq(createTodo).mutationOptions();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function invalidateTodos(queryClient: QueryClient) {
|
|
92
|
+
return rq(listTodos).invalidate(queryClient);
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Components can import those helpers and keep UI state separate from cache-key
|
|
97
|
+
construction:
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
101
|
+
import {
|
|
102
|
+
createTodoMutationOptions,
|
|
103
|
+
invalidateTodos,
|
|
104
|
+
listTodosQueryOptions,
|
|
105
|
+
} from "@/features/todos/client/queries";
|
|
106
|
+
|
|
107
|
+
function TodoList() {
|
|
108
|
+
const queryClient = useQueryClient();
|
|
109
|
+
const todosQuery = useQuery(listTodosQueryOptions());
|
|
110
|
+
const createTodoMutation = useMutation({
|
|
111
|
+
...createTodoMutationOptions(),
|
|
112
|
+
onSuccess: () => invalidateTodos(queryClient),
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
return <div>{/* ... */}</div>;
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
71
119
|
## Usage
|
|
72
120
|
|
|
73
121
|
### Options-first API (recommended)
|
|
@@ -235,19 +283,19 @@ const rq = createReactQuery(apiClient);
|
|
|
235
283
|
|
|
236
284
|
Headers are **excluded from generated query keys by default** because persisted
|
|
237
285
|
caches would otherwise store credentials such as `Authorization` tokens. When a
|
|
238
|
-
header changes response data
|
|
239
|
-
|
|
286
|
+
non-secret request-shaping header changes response data, opt that specific
|
|
287
|
+
header into keys with `keyHeaders`:
|
|
240
288
|
|
|
241
289
|
```ts
|
|
242
290
|
const rq = createReactQuery(apiClient, {
|
|
243
|
-
keyHeaders: ["X-
|
|
291
|
+
keyHeaders: ["X-Workspace-Preview"],
|
|
244
292
|
});
|
|
245
293
|
|
|
246
294
|
rq(listTodos).queryOptions({
|
|
247
|
-
headers: { "X-
|
|
295
|
+
headers: { "X-Workspace-Preview": "workspace-1", Authorization: "Bearer ..." },
|
|
248
296
|
});
|
|
249
297
|
// queryKey: ["beignet", "todos", "listTodos", "GET /todos",
|
|
250
|
-
// { headers: { "x-
|
|
298
|
+
// { headers: { "x-workspace-preview": "workspace-1" } }]
|
|
251
299
|
```
|
|
252
300
|
|
|
253
301
|
Only whitelisted header names are included. Names are matched
|
package/package.json
CHANGED
package/skills/client/SKILL.md
CHANGED
|
@@ -53,14 +53,21 @@ Follow the existing style unless intentionally migrating. Do not mix both
|
|
|
53
53
|
within one feature.
|
|
54
54
|
|
|
55
55
|
```ts
|
|
56
|
+
import type { QueryClient } from "@tanstack/react-query";
|
|
56
57
|
import { rq } from "@/client";
|
|
57
58
|
import { createTodo, listTodos } from "@/features/todos/contracts";
|
|
58
59
|
|
|
59
|
-
export
|
|
60
|
-
rq(listTodos).queryOptions({ query: { limit: 20 } });
|
|
60
|
+
export function listTodosQueryOptions() {
|
|
61
|
+
return rq(listTodos).queryOptions({ query: { limit: 20 } });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function createTodoMutationOptions() {
|
|
65
|
+
return rq(createTodo).mutationOptions();
|
|
66
|
+
}
|
|
61
67
|
|
|
62
|
-
export
|
|
63
|
-
rq(
|
|
68
|
+
export function invalidateTodos(queryClient: QueryClient) {
|
|
69
|
+
return rq(listTodos).invalidate(queryClient);
|
|
70
|
+
}
|
|
64
71
|
```
|
|
65
72
|
|
|
66
73
|
## Components
|