@navios/react-query 0.7.1 → 1.0.0
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 +171 -1
- package/README.md +152 -4
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/client/declare-client.mts.html +1264 -0
- package/coverage/client/index.html +116 -0
- package/coverage/clover.xml +160 -0
- package/coverage/coverage-final.json +8 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +146 -0
- package/coverage/mutation/index.html +131 -0
- package/coverage/mutation/key-creator.mts.html +277 -0
- package/coverage/mutation/make-hook.mts.html +952 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/query/index.html +161 -0
- package/coverage/query/key-creator.mts.html +415 -0
- package/coverage/query/make-infinite-options.mts.html +601 -0
- package/coverage/query/make-options.mts.html +838 -0
- package/coverage/query/prefetch.mts.html +1063 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/dist/src/__tests__/errorSchema.spec.d.mts +2 -0
- package/dist/src/__tests__/errorSchema.spec.d.mts.map +1 -0
- package/dist/src/__tests__/prefetch.spec.d.mts +2 -0
- package/dist/src/__tests__/prefetch.spec.d.mts.map +1 -0
- package/dist/src/client/__type-tests__/from-endpoint.spec-d.d.mts +2 -0
- package/dist/src/client/__type-tests__/from-endpoint.spec-d.d.mts.map +1 -0
- package/dist/src/client/__type-tests__/infinite-query.spec-d.d.mts +2 -0
- package/dist/src/client/__type-tests__/infinite-query.spec-d.d.mts.map +1 -0
- package/dist/src/client/__type-tests__/multipart-mutation.spec-d.d.mts +2 -0
- package/dist/src/client/__type-tests__/multipart-mutation.spec-d.d.mts.map +1 -0
- package/dist/src/client/__type-tests__/mutation.spec-d.d.mts +2 -0
- package/dist/src/client/__type-tests__/mutation.spec-d.d.mts.map +1 -0
- package/dist/src/client/__type-tests__/query.spec-d.d.mts +2 -0
- package/dist/src/client/__type-tests__/query.spec-d.d.mts.map +1 -0
- package/dist/src/client/declare-client.d.mts +15 -8
- package/dist/src/client/declare-client.d.mts.map +1 -1
- package/dist/src/client/types/from-endpoint.d.mts +130 -0
- package/dist/src/client/types/from-endpoint.d.mts.map +1 -0
- package/dist/src/client/types/helpers.d.mts +74 -0
- package/dist/src/client/types/helpers.d.mts.map +1 -0
- package/dist/src/client/types/index.d.mts +21 -0
- package/dist/src/client/types/index.d.mts.map +1 -0
- package/dist/src/client/types/infinite-query.d.mts +61 -0
- package/dist/src/client/types/infinite-query.d.mts.map +1 -0
- package/dist/src/client/types/multipart-mutation.d.mts +98 -0
- package/dist/src/client/types/multipart-mutation.d.mts.map +1 -0
- package/dist/src/client/types/mutation.d.mts +75 -0
- package/dist/src/client/types/mutation.d.mts.map +1 -0
- package/dist/src/client/types/query.d.mts +65 -0
- package/dist/src/client/types/query.d.mts.map +1 -0
- package/dist/src/client/types.d.mts +1 -608
- package/dist/src/client/types.d.mts.map +1 -1
- package/dist/src/common/types.d.mts +40 -3
- package/dist/src/common/types.d.mts.map +1 -1
- package/dist/src/mutation/index.d.mts +1 -0
- package/dist/src/mutation/index.d.mts.map +1 -1
- package/dist/src/mutation/make-hook.d.mts +42 -16
- package/dist/src/mutation/make-hook.d.mts.map +1 -1
- package/dist/src/mutation/optimistic.d.mts +172 -0
- package/dist/src/mutation/optimistic.d.mts.map +1 -0
- package/dist/src/mutation/types.d.mts +41 -20
- package/dist/src/mutation/types.d.mts.map +1 -1
- package/dist/src/query/index.d.mts +1 -0
- package/dist/src/query/index.d.mts.map +1 -1
- package/dist/src/query/key-creator.d.mts.map +1 -1
- package/dist/src/query/make-infinite-options.d.mts +3 -2
- package/dist/src/query/make-infinite-options.d.mts.map +1 -1
- package/dist/src/query/make-options.d.mts +42 -12
- package/dist/src/query/make-options.d.mts.map +1 -1
- package/dist/src/query/prefetch.d.mts +245 -0
- package/dist/src/query/prefetch.d.mts.map +1 -0
- package/dist/src/query/types.d.mts +25 -18
- package/dist/src/query/types.d.mts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/index.cjs +451 -28
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +1019 -600
- package/lib/index.d.cts.map +1 -1
- package/lib/index.d.mts +1016 -597
- package/lib/index.d.mts.map +1 -1
- package/lib/index.mjs +447 -29
- package/lib/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/declare-client.spec.mts +229 -2
- package/src/__tests__/errorSchema.spec.mts +391 -0
- package/src/__tests__/make-mutation.spec.mts +6 -5
- package/src/__tests__/makeDataTag.spec.mts +2 -1
- package/src/__tests__/makeQueryOptions.spec.mts +2 -1
- package/src/__tests__/prefetch.spec.mts +310 -0
- package/src/client/__type-tests__/from-endpoint.spec-d.mts +550 -0
- package/src/client/__type-tests__/infinite-query.spec-d.mts +648 -0
- package/src/client/__type-tests__/multipart-mutation.spec-d.mts +725 -0
- package/src/client/__type-tests__/mutation.spec-d.mts +757 -0
- package/src/client/__type-tests__/query.spec-d.mts +701 -0
- package/src/client/declare-client.mts +59 -34
- package/src/client/types/from-endpoint.mts +344 -0
- package/src/client/types/helpers.mts +140 -0
- package/src/client/types/index.mts +26 -0
- package/src/client/types/infinite-query.mts +133 -0
- package/src/client/types/multipart-mutation.mts +264 -0
- package/src/client/types/mutation.mts +176 -0
- package/src/client/types/query.mts +132 -0
- package/src/client/types.mts +1 -1935
- package/src/common/types.mts +67 -3
- package/src/mutation/index.mts +1 -0
- package/src/mutation/make-hook.mts +171 -63
- package/src/mutation/optimistic.mts +300 -0
- package/src/mutation/types.mts +87 -30
- package/src/query/index.mts +1 -0
- package/src/query/key-creator.mts +24 -13
- package/src/query/make-infinite-options.mts +53 -10
- package/src/query/make-options.mts +184 -43
- package/src/query/prefetch.mts +326 -0
- package/src/query/types.mts +56 -17
- package/src/client/__type-tests__/client-instance.spec-d.mts +0 -852
package/src/common/types.mts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
BuilderInstance,
|
|
3
|
+
ErrorSchemaRecord,
|
|
4
|
+
InferErrorSchemaOutput,
|
|
5
|
+
} from '@navios/builder'
|
|
6
|
+
import type { z, ZodType } from 'zod/v4'
|
|
2
7
|
|
|
3
8
|
/**
|
|
4
9
|
* Splits a string by a delimiter into a tuple type.
|
|
@@ -19,13 +24,72 @@ export type ProcessResponseFunction<TData = unknown, TVariables = unknown> = (
|
|
|
19
24
|
variables: TVariables,
|
|
20
25
|
) => Promise<TData> | TData
|
|
21
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Compute the response input type based on discriminator and error schema.
|
|
29
|
+
* When UseDiscriminator=true and errorSchema is present, errors are included as a union.
|
|
30
|
+
* When UseDiscriminator=false, only the success type is returned (errors are thrown).
|
|
31
|
+
*
|
|
32
|
+
* @template UseDiscriminator - Whether to include error types in the response union
|
|
33
|
+
* @template ResponseSchema - The success response schema
|
|
34
|
+
* @template ErrorSchema - The error schema record (optional)
|
|
35
|
+
*/
|
|
36
|
+
export type ComputeResponseInput<
|
|
37
|
+
UseDiscriminator extends boolean,
|
|
38
|
+
ResponseSchema extends ZodType,
|
|
39
|
+
ErrorSchema extends ErrorSchemaRecord | undefined,
|
|
40
|
+
> = UseDiscriminator extends true
|
|
41
|
+
? ErrorSchema extends ErrorSchemaRecord
|
|
42
|
+
? z.output<ResponseSchema> | InferErrorSchemaOutput<ErrorSchema>
|
|
43
|
+
: z.output<ResponseSchema>
|
|
44
|
+
: z.output<ResponseSchema>
|
|
45
|
+
|
|
22
46
|
/**
|
|
23
47
|
* Options for creating a client instance.
|
|
48
|
+
*
|
|
49
|
+
* @template UseDiscriminator - When `true`, errors are returned as union types.
|
|
50
|
+
* When `false` (default), errors are thrown.
|
|
24
51
|
*/
|
|
25
|
-
export type ClientOptions = {
|
|
26
|
-
api: BuilderInstance
|
|
52
|
+
export type ClientOptions<UseDiscriminator extends boolean = false> = {
|
|
53
|
+
api: BuilderInstance<UseDiscriminator>
|
|
27
54
|
defaults?: {
|
|
28
55
|
keyPrefix?: string[]
|
|
29
56
|
keySuffix?: string[]
|
|
30
57
|
}
|
|
31
58
|
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Infers the full response type from an endpoint configuration.
|
|
62
|
+
* Returns `ResponseType | ErrorTypes` if errorSchema exists,
|
|
63
|
+
* otherwise just `ResponseType`.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* type Response = InferEndpointResponse<{
|
|
68
|
+
* responseSchema: z.ZodObject<{ data: z.ZodString }>,
|
|
69
|
+
* errorSchema: { 400: z.ZodObject<{ error: z.ZodString }> }
|
|
70
|
+
* }>
|
|
71
|
+
* // Result: { data: string } | { error: string }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export type InferEndpointResponse<
|
|
75
|
+
Config extends {
|
|
76
|
+
responseSchema: ZodType
|
|
77
|
+
errorSchema?: ErrorSchemaRecord
|
|
78
|
+
},
|
|
79
|
+
> = Config['errorSchema'] extends ErrorSchemaRecord
|
|
80
|
+
? z.output<Config['responseSchema']> | InferErrorSchemaOutput<Config['errorSchema']>
|
|
81
|
+
: z.output<Config['responseSchema']>
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Computes the Result type, applying processResponse transformation
|
|
85
|
+
* to the full response (including error union when present).
|
|
86
|
+
*/
|
|
87
|
+
export type ComputeResultType<
|
|
88
|
+
ResponseSchema extends ZodType,
|
|
89
|
+
ErrorSchema extends ErrorSchemaRecord | undefined,
|
|
90
|
+
ProcessedResult,
|
|
91
|
+
> = ProcessedResult extends undefined
|
|
92
|
+
? ErrorSchema extends ErrorSchemaRecord
|
|
93
|
+
? z.output<ResponseSchema> | InferErrorSchemaOutput<ErrorSchema>
|
|
94
|
+
: z.output<ResponseSchema>
|
|
95
|
+
: ProcessedResult
|
package/src/mutation/index.mts
CHANGED
|
@@ -1,22 +1,105 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
AbstractEndpoint,
|
|
3
2
|
AnyEndpointConfig,
|
|
4
|
-
|
|
3
|
+
BaseEndpointConfig,
|
|
4
|
+
ErrorSchemaRecord,
|
|
5
|
+
HttpMethod,
|
|
6
|
+
InferErrorSchemaOutput,
|
|
5
7
|
UrlHasParams,
|
|
6
8
|
UrlParams,
|
|
7
9
|
} from '@navios/builder'
|
|
8
10
|
import type {
|
|
9
11
|
MutationFunctionContext,
|
|
12
|
+
UseMutationOptions,
|
|
10
13
|
UseMutationResult,
|
|
11
14
|
} from '@tanstack/react-query'
|
|
12
|
-
import type { z } from 'zod/v4'
|
|
15
|
+
import type { z, ZodObject, ZodType } from 'zod/v4'
|
|
13
16
|
|
|
14
17
|
import { useIsMutating, useMutation } from '@tanstack/react-query'
|
|
15
18
|
|
|
16
|
-
import type {
|
|
19
|
+
import type { ProcessResponseFunction } from '../common/types.mjs'
|
|
20
|
+
import type { MutationHelpers } from './types.mjs'
|
|
17
21
|
|
|
18
22
|
import { createMutationKey } from './key-creator.mjs'
|
|
19
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Helper type for endpoint with config property
|
|
26
|
+
*/
|
|
27
|
+
type EndpointWithConfig<Config extends AnyEndpointConfig> = ((
|
|
28
|
+
params: any,
|
|
29
|
+
) => Promise<any>) & {
|
|
30
|
+
config: Config
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Helper type for response input when errorSchema is present
|
|
35
|
+
*/
|
|
36
|
+
type ResponseInput<
|
|
37
|
+
ResponseSchema extends ZodType,
|
|
38
|
+
ErrorSchema extends ErrorSchemaRecord | undefined,
|
|
39
|
+
> = ErrorSchema extends ErrorSchemaRecord
|
|
40
|
+
? z.output<ResponseSchema> | InferErrorSchemaOutput<ErrorSchema>
|
|
41
|
+
: z.output<ResponseSchema>
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Options type for makeMutation
|
|
45
|
+
*/
|
|
46
|
+
type MakeMutationParams<
|
|
47
|
+
Config extends AnyEndpointConfig,
|
|
48
|
+
ResponseSchema extends ZodType,
|
|
49
|
+
ErrorSchema extends ErrorSchemaRecord | undefined,
|
|
50
|
+
TData,
|
|
51
|
+
TVariables,
|
|
52
|
+
TOnMutateResult,
|
|
53
|
+
TContext,
|
|
54
|
+
UseKey extends boolean,
|
|
55
|
+
> = Omit<
|
|
56
|
+
UseMutationOptions<TData, Error, TVariables>,
|
|
57
|
+
| 'mutationKey'
|
|
58
|
+
| 'mutationFn'
|
|
59
|
+
| 'onMutate'
|
|
60
|
+
| 'onSuccess'
|
|
61
|
+
| 'onError'
|
|
62
|
+
| 'onSettled'
|
|
63
|
+
| 'scope'
|
|
64
|
+
> & {
|
|
65
|
+
processResponse?: ProcessResponseFunction<TData, ResponseInput<ResponseSchema, ErrorSchema>>
|
|
66
|
+
useContext?: () => TContext
|
|
67
|
+
onSuccess?: (
|
|
68
|
+
data: TData,
|
|
69
|
+
variables: TVariables,
|
|
70
|
+
context: TContext &
|
|
71
|
+
MutationFunctionContext & { onMutateResult: TOnMutateResult | undefined },
|
|
72
|
+
) => void | Promise<void>
|
|
73
|
+
onError?: (
|
|
74
|
+
err: unknown,
|
|
75
|
+
variables: TVariables,
|
|
76
|
+
context: TContext &
|
|
77
|
+
MutationFunctionContext & { onMutateResult: TOnMutateResult | undefined },
|
|
78
|
+
) => void | Promise<void>
|
|
79
|
+
onMutate?: (
|
|
80
|
+
variables: TVariables,
|
|
81
|
+
context: TContext & MutationFunctionContext,
|
|
82
|
+
) => TOnMutateResult | Promise<TOnMutateResult>
|
|
83
|
+
onSettled?: (
|
|
84
|
+
data: TData | undefined,
|
|
85
|
+
error: Error | null,
|
|
86
|
+
variables: TVariables,
|
|
87
|
+
context: TContext &
|
|
88
|
+
MutationFunctionContext & { onMutateResult: TOnMutateResult | undefined },
|
|
89
|
+
) => void | Promise<void>
|
|
90
|
+
useKey?: UseKey
|
|
91
|
+
keyPrefix?: UseKey extends true
|
|
92
|
+
? UrlHasParams<Config['url']> extends true
|
|
93
|
+
? string[]
|
|
94
|
+
: never
|
|
95
|
+
: never
|
|
96
|
+
keySuffix?: UseKey extends true
|
|
97
|
+
? UrlHasParams<Config['url']> extends true
|
|
98
|
+
? string[]
|
|
99
|
+
: never
|
|
100
|
+
: never
|
|
101
|
+
}
|
|
102
|
+
|
|
20
103
|
/**
|
|
21
104
|
* Creates a mutation hook for a given endpoint.
|
|
22
105
|
*
|
|
@@ -27,44 +110,87 @@ import { createMutationKey } from './key-creator.mjs'
|
|
|
27
110
|
* @param options - Mutation configuration including processResponse and callbacks
|
|
28
111
|
* @returns A hook function that returns mutation result with attached helpers
|
|
29
112
|
*/
|
|
113
|
+
// Overload: WITH errorSchema
|
|
30
114
|
export function makeMutation<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
115
|
+
Method extends HttpMethod,
|
|
116
|
+
Url extends string,
|
|
117
|
+
QuerySchema extends ZodObject | undefined,
|
|
118
|
+
ResponseSchema extends ZodType,
|
|
119
|
+
RequestSchema extends ZodType,
|
|
120
|
+
ErrorSchema extends ErrorSchemaRecord,
|
|
121
|
+
TData,
|
|
122
|
+
TOnMutateResult = unknown,
|
|
123
|
+
TContext = unknown,
|
|
124
|
+
UseKey extends boolean = false,
|
|
125
|
+
>(
|
|
126
|
+
endpoint: EndpointWithConfig<
|
|
127
|
+
BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema, ErrorSchema>
|
|
128
|
+
>,
|
|
129
|
+
options: MakeMutationParams<
|
|
130
|
+
BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema, ErrorSchema>,
|
|
131
|
+
ResponseSchema,
|
|
132
|
+
ErrorSchema,
|
|
133
|
+
TData,
|
|
134
|
+
any,
|
|
135
|
+
TOnMutateResult,
|
|
136
|
+
TContext,
|
|
137
|
+
UseKey
|
|
138
|
+
>,
|
|
139
|
+
): ((
|
|
140
|
+
keyParams: UseKey extends true
|
|
141
|
+
? UrlHasParams<Url> extends true
|
|
142
|
+
? { urlParams: UrlParams<Url> }
|
|
143
|
+
: never
|
|
144
|
+
: never,
|
|
145
|
+
) => UseMutationResult<TData, Error, any, TOnMutateResult>) &
|
|
146
|
+
MutationHelpers<Url, TData>
|
|
147
|
+
|
|
148
|
+
// Overload: WITHOUT errorSchema
|
|
149
|
+
export function makeMutation<
|
|
150
|
+
Method extends HttpMethod,
|
|
151
|
+
Url extends string,
|
|
152
|
+
QuerySchema extends ZodObject | undefined,
|
|
153
|
+
ResponseSchema extends ZodType,
|
|
154
|
+
RequestSchema extends ZodType | undefined,
|
|
155
|
+
TData,
|
|
35
156
|
TOnMutateResult = unknown,
|
|
36
157
|
TContext = unknown,
|
|
37
158
|
UseKey extends boolean = false,
|
|
38
159
|
>(
|
|
39
|
-
endpoint:
|
|
40
|
-
|
|
41
|
-
|
|
160
|
+
endpoint: EndpointWithConfig<
|
|
161
|
+
BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema, undefined>
|
|
162
|
+
>,
|
|
163
|
+
options: MakeMutationParams<
|
|
164
|
+
BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema, undefined>,
|
|
165
|
+
ResponseSchema,
|
|
166
|
+
undefined,
|
|
42
167
|
TData,
|
|
43
|
-
|
|
44
|
-
TResponse,
|
|
168
|
+
any,
|
|
45
169
|
TOnMutateResult,
|
|
46
170
|
TContext,
|
|
47
171
|
UseKey
|
|
48
172
|
>,
|
|
49
|
-
)
|
|
173
|
+
): ((
|
|
174
|
+
keyParams: UseKey extends true
|
|
175
|
+
? UrlHasParams<Url> extends true
|
|
176
|
+
? { urlParams: UrlParams<Url> }
|
|
177
|
+
: never
|
|
178
|
+
: never,
|
|
179
|
+
) => UseMutationResult<TData, Error, any, TOnMutateResult>) &
|
|
180
|
+
MutationHelpers<Url, TData>
|
|
181
|
+
|
|
182
|
+
// Implementation
|
|
183
|
+
export function makeMutation(
|
|
184
|
+
endpoint: EndpointWithConfig<AnyEndpointConfig>,
|
|
185
|
+
options: any,
|
|
186
|
+
): any {
|
|
50
187
|
const config = endpoint.config
|
|
51
188
|
|
|
52
189
|
const mutationKey = createMutationKey(config, {
|
|
53
190
|
...options,
|
|
54
|
-
processResponse: options.processResponse ?? ((data) => data),
|
|
191
|
+
processResponse: options.processResponse ?? ((data: any) => data),
|
|
55
192
|
})
|
|
56
|
-
const result = (
|
|
57
|
-
keyParams: UseKey extends true
|
|
58
|
-
? UrlHasParams<Config['url']> extends true
|
|
59
|
-
? { urlParams: UrlParams<Config['url']> }
|
|
60
|
-
: never
|
|
61
|
-
: never,
|
|
62
|
-
): UseMutationResult<
|
|
63
|
-
TData,
|
|
64
|
-
Error,
|
|
65
|
-
NaviosZodRequest<Config>,
|
|
66
|
-
TOnMutateResult
|
|
67
|
-
> => {
|
|
193
|
+
const result = (keyParams: any): any => {
|
|
68
194
|
const {
|
|
69
195
|
useKey,
|
|
70
196
|
useContext,
|
|
@@ -78,9 +204,8 @@ export function makeMutation<
|
|
|
78
204
|
...rest
|
|
79
205
|
} = options
|
|
80
206
|
|
|
81
|
-
const ownContext =
|
|
207
|
+
const ownContext = useContext?.() ?? {}
|
|
82
208
|
|
|
83
|
-
// @ts-expect-error The types match
|
|
84
209
|
return useMutation({
|
|
85
210
|
...rest,
|
|
86
211
|
mutationKey: useKey ? mutationKey(keyParams) : undefined,
|
|
@@ -89,89 +214,72 @@ export function makeMutation<
|
|
|
89
214
|
id: JSON.stringify(mutationKey(keyParams)),
|
|
90
215
|
}
|
|
91
216
|
: undefined,
|
|
92
|
-
async mutationFn(params:
|
|
217
|
+
async mutationFn(params: any) {
|
|
93
218
|
const response = await endpoint(params)
|
|
94
219
|
|
|
95
|
-
return
|
|
220
|
+
return processResponse ? processResponse(response) : response
|
|
96
221
|
},
|
|
97
222
|
onSuccess: onSuccess
|
|
98
223
|
? (
|
|
99
|
-
data:
|
|
100
|
-
variables:
|
|
101
|
-
onMutateResult:
|
|
224
|
+
data: any,
|
|
225
|
+
variables: any,
|
|
226
|
+
onMutateResult: any,
|
|
102
227
|
context: MutationFunctionContext,
|
|
103
228
|
) => {
|
|
104
229
|
return onSuccess?.(data, variables, {
|
|
105
230
|
...ownContext,
|
|
106
231
|
...context,
|
|
107
232
|
onMutateResult,
|
|
108
|
-
}
|
|
109
|
-
MutationFunctionContext & {
|
|
110
|
-
onMutateResult: TOnMutateResult | undefined
|
|
111
|
-
})
|
|
233
|
+
})
|
|
112
234
|
}
|
|
113
235
|
: undefined,
|
|
114
236
|
onError: onError
|
|
115
237
|
? (
|
|
116
238
|
err: Error,
|
|
117
|
-
variables:
|
|
118
|
-
onMutateResult:
|
|
239
|
+
variables: any,
|
|
240
|
+
onMutateResult: any,
|
|
119
241
|
context: MutationFunctionContext,
|
|
120
242
|
) => {
|
|
121
243
|
return onError?.(err, variables, {
|
|
122
244
|
onMutateResult,
|
|
123
245
|
...ownContext,
|
|
124
246
|
...context,
|
|
125
|
-
}
|
|
126
|
-
MutationFunctionContext & {
|
|
127
|
-
onMutateResult: TOnMutateResult | undefined
|
|
128
|
-
})
|
|
247
|
+
})
|
|
129
248
|
}
|
|
130
249
|
: undefined,
|
|
131
250
|
onMutate: onMutate
|
|
132
|
-
? (variables:
|
|
251
|
+
? (variables: any, context: MutationFunctionContext) => {
|
|
133
252
|
return onMutate(variables, {
|
|
134
253
|
...ownContext,
|
|
135
254
|
...context,
|
|
136
|
-
}
|
|
255
|
+
})
|
|
137
256
|
}
|
|
138
257
|
: undefined,
|
|
139
258
|
onSettled: onSettled
|
|
140
259
|
? (
|
|
141
|
-
data:
|
|
260
|
+
data: any,
|
|
142
261
|
error: Error | null,
|
|
143
|
-
variables:
|
|
144
|
-
onMutateResult:
|
|
262
|
+
variables: any,
|
|
263
|
+
onMutateResult: any,
|
|
145
264
|
context: MutationFunctionContext,
|
|
146
265
|
) => {
|
|
147
266
|
return onSettled(data, error, variables, {
|
|
148
267
|
...ownContext,
|
|
149
268
|
...context,
|
|
150
269
|
onMutateResult,
|
|
151
|
-
}
|
|
152
|
-
MutationFunctionContext & {
|
|
153
|
-
onMutateResult: TOnMutateResult | undefined
|
|
154
|
-
})
|
|
270
|
+
})
|
|
155
271
|
}
|
|
156
272
|
: undefined,
|
|
157
273
|
})
|
|
158
274
|
}
|
|
159
|
-
result.useIsMutating = (
|
|
160
|
-
keyParams: UseKey extends true
|
|
161
|
-
? UrlHasParams<Config['url']> extends true
|
|
162
|
-
? UrlParams<Config['url']>
|
|
163
|
-
: never
|
|
164
|
-
: never,
|
|
165
|
-
): boolean => {
|
|
275
|
+
result.useIsMutating = (keyParams: any): boolean => {
|
|
166
276
|
if (!options.useKey) {
|
|
167
277
|
throw new Error(
|
|
168
278
|
'useIsMutating can only be used when useKey is set to true',
|
|
169
279
|
)
|
|
170
280
|
}
|
|
171
281
|
const isMutating = useIsMutating({
|
|
172
|
-
mutationKey: mutationKey(
|
|
173
|
-
urlParams: keyParams,
|
|
174
|
-
}),
|
|
282
|
+
mutationKey: mutationKey(keyParams),
|
|
175
283
|
})
|
|
176
284
|
return isMutating > 0
|
|
177
285
|
}
|