@navios/react-query 0.5.2 → 0.6.1
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 +51 -10
- package/README.md +405 -273
- package/dist/src/client/declare-client.d.mts +13 -4
- package/dist/src/client/declare-client.d.mts.map +1 -1
- package/dist/src/client/types.d.mts +337 -113
- package/dist/src/client/types.d.mts.map +1 -1
- package/dist/src/mutation/make-hook.d.mts +2 -2
- package/dist/src/mutation/make-hook.d.mts.map +1 -1
- package/dist/src/mutation/types.d.mts +12 -4
- package/dist/src/mutation/types.d.mts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/_tsup-dts-rollup.d.mts +362 -120
- package/lib/_tsup-dts-rollup.d.ts +362 -120
- package/lib/index.js +51 -27
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +52 -28
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/declare-client.spec.mts +24 -5
- package/src/__tests__/make-mutation.spec.mts +150 -8
- package/src/client/__type-tests__/client-instance.spec-d.mts +2 -2
- package/src/client/declare-client.mts +33 -8
- package/src/client/types.mts +617 -141
- package/src/mutation/make-hook.mts +96 -42
- package/src/mutation/types.mts +28 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,31 +1,72 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [0.
|
|
3
|
+
## [0.6.0] - Dec 13, 2025
|
|
4
|
+
|
|
5
|
+
### Breaking Changes
|
|
6
|
+
|
|
7
|
+
- **Mutation callback signatures changed** - The `onSuccess`, `onError`, `onMutate`, and `onSettled` callbacks now use a unified context-based signature instead of receiving `queryClient` as the first parameter:
|
|
8
|
+
|
|
9
|
+
**Before (0.5.x):**
|
|
10
|
+
```typescript
|
|
11
|
+
const mutation = client.mutation({
|
|
12
|
+
onSuccess: (queryClient, data, variables) => {
|
|
13
|
+
queryClient.invalidateQueries({ queryKey: ['users'] })
|
|
14
|
+
},
|
|
15
|
+
onError: (queryClient, error, variables) => {
|
|
16
|
+
console.error(error)
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
**After (0.6.0):**
|
|
22
|
+
```typescript
|
|
23
|
+
const mutation = client.mutation({
|
|
24
|
+
onSuccess: (data, variables, context) => {
|
|
25
|
+
// Access queryClient via useContext if needed
|
|
26
|
+
context.queryClient.invalidateQueries({ queryKey: ['users'] })
|
|
27
|
+
},
|
|
28
|
+
onError: (error, variables, context) => {
|
|
29
|
+
console.error(error)
|
|
30
|
+
},
|
|
31
|
+
onMutate: (variables, context) => {
|
|
32
|
+
// Return value is available in other callbacks as context.onMutateResult
|
|
33
|
+
return { previousData: context.queryClient.getQueryData(['users']) }
|
|
34
|
+
},
|
|
35
|
+
onSettled: (data, error, variables, context) => {
|
|
36
|
+
// Called on both success and error
|
|
37
|
+
// context.onMutateResult contains the return value from onMutate
|
|
38
|
+
},
|
|
39
|
+
useContext: () => {
|
|
40
|
+
const queryClient = useQueryClient()
|
|
41
|
+
return { queryClient }
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- **New `TOnMutateResult` type parameter** - `MutationParams` now includes a `TOnMutateResult` generic for typing the return value of `onMutate`, which is passed to other callbacks via `context.onMutateResult`.
|
|
4
47
|
|
|
5
48
|
### Added
|
|
6
49
|
|
|
50
|
+
- **`onMutate` callback** - Called before the mutation executes. The return value is available in `onSuccess`, `onError`, and `onSettled` callbacks via `context.onMutateResult`. This enables optimistic updates pattern.
|
|
51
|
+
|
|
52
|
+
- **`onSettled` callback** - Called after the mutation completes (success or failure). Receives `data` (undefined on error), `error` (null on success), `variables`, and `context`.
|
|
53
|
+
|
|
54
|
+
- **`MutationFunctionContext` integration** - All callbacks now receive TanStack Query's `MutationFunctionContext` merged with your custom context, providing access to `mutationId` and `meta`.
|
|
55
|
+
|
|
7
56
|
- **Stream mutation support** - `mutationFromEndpoint` now supports stream endpoints created with `api.declareStream()`. This enables file downloads and other blob responses in mutations.
|
|
8
57
|
|
|
9
58
|
```typescript
|
|
10
|
-
// Create a stream endpoint
|
|
11
59
|
const downloadFile = api.declareStream({
|
|
12
60
|
method: 'GET',
|
|
13
61
|
url: '/files/$id/download',
|
|
14
62
|
})
|
|
15
63
|
|
|
16
|
-
// Use it with mutationFromEndpoint - processResponse is optional
|
|
17
64
|
const useDownloadFile = client.mutationFromEndpoint(downloadFile, {
|
|
18
|
-
onSuccess: (
|
|
19
|
-
// blob is typed as Blob
|
|
65
|
+
onSuccess: (blob, variables, context) => {
|
|
20
66
|
const url = URL.createObjectURL(blob)
|
|
21
67
|
window.open(url)
|
|
22
68
|
},
|
|
23
69
|
})
|
|
24
|
-
|
|
25
|
-
// Or transform the response
|
|
26
|
-
const useDownloadFile2 = client.mutationFromEndpoint(downloadFile, {
|
|
27
|
-
processResponse: (blob) => URL.createObjectURL(blob),
|
|
28
|
-
})
|
|
29
70
|
```
|
|
30
71
|
|
|
31
72
|
- **New `StreamHelper` type** - Helper type that attaches stream endpoint to mutation results, similar to `EndpointHelper` for regular endpoints.
|