@navios/react-query 0.7.1 → 1.0.0-alpha.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.
Files changed (94) hide show
  1. package/CHANGELOG.md +161 -1
  2. package/README.md +152 -4
  3. package/dist/src/__tests__/errorSchema.spec.d.mts +2 -0
  4. package/dist/src/__tests__/errorSchema.spec.d.mts.map +1 -0
  5. package/dist/src/client/__type-tests__/from-endpoint.spec-d.d.mts +2 -0
  6. package/dist/src/client/__type-tests__/from-endpoint.spec-d.d.mts.map +1 -0
  7. package/dist/src/client/__type-tests__/infinite-query.spec-d.d.mts +2 -0
  8. package/dist/src/client/__type-tests__/infinite-query.spec-d.d.mts.map +1 -0
  9. package/dist/src/client/__type-tests__/multipart-mutation.spec-d.d.mts +2 -0
  10. package/dist/src/client/__type-tests__/multipart-mutation.spec-d.d.mts.map +1 -0
  11. package/dist/src/client/__type-tests__/mutation.spec-d.d.mts +2 -0
  12. package/dist/src/client/__type-tests__/mutation.spec-d.d.mts.map +1 -0
  13. package/dist/src/client/__type-tests__/query.spec-d.d.mts +2 -0
  14. package/dist/src/client/__type-tests__/query.spec-d.d.mts.map +1 -0
  15. package/dist/src/client/declare-client.d.mts +15 -8
  16. package/dist/src/client/declare-client.d.mts.map +1 -1
  17. package/dist/src/client/types/from-endpoint.d.mts +130 -0
  18. package/dist/src/client/types/from-endpoint.d.mts.map +1 -0
  19. package/dist/src/client/types/helpers.d.mts +74 -0
  20. package/dist/src/client/types/helpers.d.mts.map +1 -0
  21. package/dist/src/client/types/index.d.mts +21 -0
  22. package/dist/src/client/types/index.d.mts.map +1 -0
  23. package/dist/src/client/types/infinite-query.d.mts +61 -0
  24. package/dist/src/client/types/infinite-query.d.mts.map +1 -0
  25. package/dist/src/client/types/multipart-mutation.d.mts +98 -0
  26. package/dist/src/client/types/multipart-mutation.d.mts.map +1 -0
  27. package/dist/src/client/types/mutation.d.mts +75 -0
  28. package/dist/src/client/types/mutation.d.mts.map +1 -0
  29. package/dist/src/client/types/query.d.mts +65 -0
  30. package/dist/src/client/types/query.d.mts.map +1 -0
  31. package/dist/src/client/types.d.mts +1 -608
  32. package/dist/src/client/types.d.mts.map +1 -1
  33. package/dist/src/common/types.d.mts +30 -3
  34. package/dist/src/common/types.d.mts.map +1 -1
  35. package/dist/src/mutation/index.d.mts +1 -0
  36. package/dist/src/mutation/index.d.mts.map +1 -1
  37. package/dist/src/mutation/make-hook.d.mts +42 -16
  38. package/dist/src/mutation/make-hook.d.mts.map +1 -1
  39. package/dist/src/mutation/optimistic.d.mts +166 -0
  40. package/dist/src/mutation/optimistic.d.mts.map +1 -0
  41. package/dist/src/mutation/types.d.mts +51 -19
  42. package/dist/src/mutation/types.d.mts.map +1 -1
  43. package/dist/src/query/index.d.mts +1 -0
  44. package/dist/src/query/index.d.mts.map +1 -1
  45. package/dist/src/query/key-creator.d.mts.map +1 -1
  46. package/dist/src/query/make-infinite-options.d.mts +3 -2
  47. package/dist/src/query/make-infinite-options.d.mts.map +1 -1
  48. package/dist/src/query/make-options.d.mts +42 -12
  49. package/dist/src/query/make-options.d.mts.map +1 -1
  50. package/dist/src/query/prefetch.d.mts +245 -0
  51. package/dist/src/query/prefetch.d.mts.map +1 -0
  52. package/dist/src/query/types.d.mts +35 -17
  53. package/dist/src/query/types.d.mts.map +1 -1
  54. package/dist/tsconfig.tsbuildinfo +1 -1
  55. package/lib/index.cjs +445 -28
  56. package/lib/index.cjs.map +1 -1
  57. package/lib/index.d.cts +1022 -599
  58. package/lib/index.d.cts.map +1 -1
  59. package/lib/index.d.mts +1019 -596
  60. package/lib/index.d.mts.map +1 -1
  61. package/lib/index.mjs +441 -29
  62. package/lib/index.mjs.map +1 -1
  63. package/package.json +3 -3
  64. package/src/__tests__/declare-client.spec.mts +1 -2
  65. package/src/__tests__/errorSchema.spec.mts +391 -0
  66. package/src/__tests__/make-mutation.spec.mts +6 -5
  67. package/src/__tests__/makeDataTag.spec.mts +2 -1
  68. package/src/__tests__/makeQueryOptions.spec.mts +2 -1
  69. package/src/client/__type-tests__/from-endpoint.spec-d.mts +550 -0
  70. package/src/client/__type-tests__/infinite-query.spec-d.mts +648 -0
  71. package/src/client/__type-tests__/multipart-mutation.spec-d.mts +725 -0
  72. package/src/client/__type-tests__/mutation.spec-d.mts +757 -0
  73. package/src/client/__type-tests__/query.spec-d.mts +701 -0
  74. package/src/client/declare-client.mts +59 -34
  75. package/src/client/types/from-endpoint.mts +345 -0
  76. package/src/client/types/helpers.mts +140 -0
  77. package/src/client/types/index.mts +26 -0
  78. package/src/client/types/infinite-query.mts +133 -0
  79. package/src/client/types/multipart-mutation.mts +264 -0
  80. package/src/client/types/mutation.mts +176 -0
  81. package/src/client/types/query.mts +132 -0
  82. package/src/client/types.mts +1 -1935
  83. package/src/common/types.mts +48 -3
  84. package/src/mutation/index.mts +1 -0
  85. package/src/mutation/make-hook.mts +171 -63
  86. package/src/mutation/optimistic.mts +294 -0
  87. package/src/mutation/types.mts +102 -29
  88. package/src/query/index.mts +1 -0
  89. package/src/query/key-creator.mts +24 -13
  90. package/src/query/make-infinite-options.mts +53 -10
  91. package/src/query/make-options.mts +184 -43
  92. package/src/query/prefetch.mts +326 -0
  93. package/src/query/types.mts +76 -16
  94. package/src/client/__type-tests__/client-instance.spec-d.mts +0 -852
@@ -0,0 +1,140 @@
1
+ import type {
2
+ BaseEndpointOptions,
3
+ EndpointHandler,
4
+ EndpointOptions,
5
+ ErrorSchemaRecord,
6
+ HttpMethod,
7
+ InferErrorSchemaOutput,
8
+ StreamHandler,
9
+ } from '@navios/builder'
10
+ import type { z, ZodType } from 'zod/v4'
11
+
12
+ /**
13
+ * Compute the base result type based on discriminator and error schema.
14
+ * When UseDiscriminator=true and errorSchema is present, errors are included as a union.
15
+ * When UseDiscriminator=false, only the success type is returned (errors are thrown).
16
+ */
17
+ export type ComputeBaseResult<
18
+ UseDiscriminator extends boolean,
19
+ ResponseSchema extends ZodType,
20
+ ErrorSchema extends ErrorSchemaRecord | undefined,
21
+ > = UseDiscriminator extends true
22
+ ? ErrorSchema extends ErrorSchemaRecord
23
+ ? z.output<ResponseSchema> | InferErrorSchemaOutput<ErrorSchema>
24
+ : z.output<ResponseSchema>
25
+ : z.output<ResponseSchema>
26
+
27
+ /**
28
+ * Helper type to compute the response data type based on errorSchema presence and UseDiscriminator.
29
+ *
30
+ * When `UseDiscriminator` is `true` and `errorSchema` exists, returns `ResponseType | ErrorTypes`.
31
+ * When `UseDiscriminator` is `false`, returns only `ResponseType` (errors are thrown).
32
+ *
33
+ * @deprecated Use ComputeBaseResult instead (same logic, different parameter order)
34
+ */
35
+ export type ResponseDataType<
36
+ Response extends ZodType,
37
+ ErrorSchema extends ErrorSchemaRecord | undefined,
38
+ UseDiscriminator extends boolean = false,
39
+ > = ComputeBaseResult<UseDiscriminator, Response, ErrorSchema>
40
+
41
+ /**
42
+ * Helper type that attaches the endpoint to query/mutation results.
43
+ * Supports both new const generic pattern and legacy pattern with individual parameters.
44
+ *
45
+ * New pattern (2 args):
46
+ * @template Options - EndpointOptions from builder (new const generic pattern)
47
+ * @template UseDiscriminator - When true, errors are returned as union types
48
+ *
49
+ * Legacy pattern (4-5 args):
50
+ * @template Method - HTTP method
51
+ * @template Url - URL template
52
+ * @template RequestSchema - Request body schema
53
+ * @template ResponseSchema - Response schema
54
+ * @template QuerySchema - Query params schema (optional)
55
+ */
56
+ export type EndpointHelper<
57
+ OptionsOrMethod extends EndpointOptions | HttpMethod = EndpointOptions,
58
+ UseDiscriminatorOrUrl extends boolean | string = false,
59
+ RequestSchema = undefined,
60
+ ResponseSchema extends ZodType = ZodType,
61
+ QuerySchema = undefined,
62
+ > = OptionsOrMethod extends EndpointOptions
63
+ ? UseDiscriminatorOrUrl extends boolean
64
+ ? {
65
+ endpoint: EndpointHandler<OptionsOrMethod, UseDiscriminatorOrUrl>
66
+ }
67
+ : never
68
+ : OptionsOrMethod extends HttpMethod
69
+ ? UseDiscriminatorOrUrl extends string
70
+ ? {
71
+ endpoint: EndpointHandler<
72
+ EndpointOptions & {
73
+ method: OptionsOrMethod
74
+ url: UseDiscriminatorOrUrl
75
+ requestSchema: RequestSchema
76
+ responseSchema: ResponseSchema
77
+ querySchema: QuerySchema
78
+ },
79
+ false
80
+ >
81
+ }
82
+ : never
83
+ : never
84
+
85
+ // Legacy export for backwards compatibility
86
+ /** @deprecated Use EndpointHelper instead */
87
+ export type ClientEndpointHelper<
88
+ Method extends HttpMethod = HttpMethod,
89
+ Url extends string = string,
90
+ RequestSchema = unknown,
91
+ ResponseSchema extends z.ZodType = z.ZodType,
92
+ QuerySchema = unknown,
93
+ > = EndpointHelper<Method, Url, RequestSchema, ResponseSchema, QuerySchema>
94
+
95
+ /**
96
+ * Helper type that attaches a stream endpoint to mutation results.
97
+ * Supports both new const generic pattern and legacy pattern with individual parameters.
98
+ *
99
+ * New pattern (2 args):
100
+ * @template Options - BaseEndpointOptions from builder (new const generic pattern)
101
+ * @template UseDiscriminator - When true, errors are returned as union types
102
+ *
103
+ * Legacy pattern (4-6 args):
104
+ * @template Method - HTTP method
105
+ * @template Url - URL template
106
+ * @template QuerySchema - Query params schema
107
+ * @template RequestSchema - Request body schema
108
+ * @template ErrorSchema - Error schema (optional)
109
+ * @template UrlParamsSchema - URL params schema (optional)
110
+ */
111
+ export type StreamHelper<
112
+ OptionsOrMethod extends BaseEndpointOptions | HttpMethod = BaseEndpointOptions,
113
+ UseDiscriminatorOrUrl extends boolean | string = false,
114
+ QuerySchema = undefined,
115
+ RequestSchema = undefined,
116
+ ErrorSchema = undefined,
117
+ UrlParamsSchema = undefined,
118
+ > = OptionsOrMethod extends BaseEndpointOptions
119
+ ? UseDiscriminatorOrUrl extends boolean
120
+ ? {
121
+ endpoint: StreamHandler<OptionsOrMethod, UseDiscriminatorOrUrl>
122
+ }
123
+ : never
124
+ : OptionsOrMethod extends HttpMethod
125
+ ? UseDiscriminatorOrUrl extends string
126
+ ? {
127
+ endpoint: StreamHandler<
128
+ BaseEndpointOptions & {
129
+ method: OptionsOrMethod
130
+ url: UseDiscriminatorOrUrl
131
+ querySchema: QuerySchema
132
+ requestSchema: RequestSchema
133
+ errorSchema: ErrorSchema
134
+ urlParamsSchema: UrlParamsSchema
135
+ },
136
+ false
137
+ >
138
+ }
139
+ : never
140
+ : never
@@ -0,0 +1,26 @@
1
+ export * from './helpers.mjs'
2
+ export * from './query.mjs'
3
+ export * from './infinite-query.mjs'
4
+ export * from './mutation.mjs'
5
+ export * from './multipart-mutation.mjs'
6
+ export * from './from-endpoint.mjs'
7
+
8
+ import type { ClientFromEndpointMethods } from './from-endpoint.mjs'
9
+ import type { ClientInfiniteQueryMethods } from './infinite-query.mjs'
10
+ import type { ClientMultipartMutationMethods } from './multipart-mutation.mjs'
11
+ import type { ClientMutationMethods } from './mutation.mjs'
12
+ import type { ClientQueryMethods } from './query.mjs'
13
+
14
+ /**
15
+ * The main client instance interface.
16
+ * Provides methods for creating queries, infinite queries, and mutations.
17
+ *
18
+ * @template UseDiscriminator - When `true`, errors are returned as union types.
19
+ * When `false` (default), errors are thrown and not included in TData.
20
+ */
21
+ export interface ClientInstance<UseDiscriminator extends boolean = false>
22
+ extends ClientQueryMethods<UseDiscriminator>,
23
+ ClientInfiniteQueryMethods<UseDiscriminator>,
24
+ ClientMutationMethods<UseDiscriminator>,
25
+ ClientMultipartMutationMethods<UseDiscriminator>,
26
+ ClientFromEndpointMethods<UseDiscriminator> {}
@@ -0,0 +1,133 @@
1
+ import type {
2
+ EndpointOptions,
3
+ ErrorSchemaRecord,
4
+ HttpMethod,
5
+ InferEndpointParams,
6
+ Simplify,
7
+ } from '@navios/builder'
8
+ import type {
9
+ DataTag,
10
+ InfiniteData,
11
+ UseSuspenseInfiniteQueryOptions,
12
+ } from '@tanstack/react-query'
13
+ import type { z, ZodObject, ZodType } from 'zod/v4'
14
+
15
+ import type { Split } from '../../common/types.mjs'
16
+ import type { QueryHelpers } from '../../query/types.mjs'
17
+ import type { ComputeBaseResult, EndpointHelper } from './helpers.mjs'
18
+
19
+ /**
20
+ * Extended endpoint options interface for infinite query that includes processResponse and pagination.
21
+ */
22
+ interface InfiniteQueryEndpointConfig<
23
+ _UseDiscriminator extends boolean,
24
+ Method extends HttpMethod,
25
+ Url extends string,
26
+ QuerySchema extends ZodObject,
27
+ RequestSchema extends ZodType | undefined,
28
+ ResponseSchema extends ZodType,
29
+ ErrorSchema extends ErrorSchemaRecord | undefined,
30
+ UrlParamsSchema extends ZodObject | undefined,
31
+ TBaseResult,
32
+ PageResult,
33
+ > extends EndpointOptions {
34
+ method: Method
35
+ url: Url
36
+ querySchema: QuerySchema
37
+ requestSchema?: RequestSchema
38
+ responseSchema: ResponseSchema
39
+ errorSchema?: ErrorSchema
40
+ urlParamsSchema?: UrlParamsSchema
41
+ processResponse?: (data: TBaseResult) => PageResult
42
+ getNextPageParam: (
43
+ lastPage: PageResult,
44
+ allPages: PageResult[],
45
+ lastPageParam: z.infer<QuerySchema> | undefined,
46
+ allPageParams: z.infer<QuerySchema>[] | undefined,
47
+ ) => z.input<QuerySchema> | undefined
48
+ getPreviousPageParam?: (
49
+ firstPage: PageResult,
50
+ allPages: PageResult[],
51
+ lastPageParam: z.infer<QuerySchema> | undefined,
52
+ allPageParams: z.infer<QuerySchema>[] | undefined,
53
+ ) => z.input<QuerySchema>
54
+ }
55
+
56
+ /**
57
+ * Infinite query method using decomposed generics pattern for proper processResponse typing.
58
+ *
59
+ * @template UseDiscriminator - When `true`, errors are returned as union types.
60
+ * When `false` (default), errors are thrown and not included in TData.
61
+ */
62
+ export interface ClientInfiniteQueryMethods<
63
+ UseDiscriminator extends boolean = false,
64
+ > {
65
+ /**
66
+ * Creates a type-safe infinite query with automatic type inference.
67
+ *
68
+ * Uses decomposed generic pattern to infer types from the configuration object.
69
+ * All schema combinations are handled by a single method.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * const getUsers = client.infiniteQuery({
74
+ * method: 'GET',
75
+ * url: '/users',
76
+ * querySchema: z.object({ page: z.number() }),
77
+ * responseSchema: z.array(userSchema),
78
+ * getNextPageParam: (lastPage, allPages, lastPageParam) => {
79
+ * return lastPage.length > 0 ? { page: (lastPageParam?.page ?? 0) + 1 } : undefined
80
+ * },
81
+ * })
82
+ *
83
+ * const { data } = getUsers.useSuspense({ params: { page: 0 } })
84
+ * ```
85
+ */
86
+ infiniteQuery<
87
+ const Method extends HttpMethod = HttpMethod,
88
+ const Url extends string = string,
89
+ const QuerySchema extends ZodObject = ZodObject,
90
+ const RequestSchema extends ZodType | undefined = undefined,
91
+ const ResponseSchema extends ZodType = ZodType,
92
+ const ErrorSchema extends ErrorSchemaRecord | undefined = undefined,
93
+ const UrlParamsSchema extends ZodObject | undefined = undefined,
94
+ const TBaseResult = ComputeBaseResult<
95
+ UseDiscriminator,
96
+ ResponseSchema,
97
+ ErrorSchema
98
+ >,
99
+ const PageResult = TBaseResult,
100
+ const Options extends EndpointOptions = {
101
+ method: Method
102
+ url: Url
103
+ querySchema: QuerySchema
104
+ requestSchema: RequestSchema
105
+ responseSchema: ResponseSchema
106
+ errorSchema: ErrorSchema
107
+ urlParamsSchema: UrlParamsSchema
108
+ },
109
+ >(
110
+ config: InfiniteQueryEndpointConfig<
111
+ UseDiscriminator,
112
+ Method,
113
+ Url,
114
+ QuerySchema,
115
+ RequestSchema,
116
+ ResponseSchema,
117
+ ErrorSchema,
118
+ UrlParamsSchema,
119
+ TBaseResult,
120
+ PageResult
121
+ >,
122
+ ): ((
123
+ params: Simplify<InferEndpointParams<Options>>,
124
+ ) => UseSuspenseInfiniteQueryOptions<
125
+ PageResult,
126
+ Error,
127
+ InfiniteData<PageResult>,
128
+ DataTag<Split<Url, '/'>, PageResult, Error>,
129
+ z.output<QuerySchema>
130
+ >) &
131
+ QueryHelpers<Url, QuerySchema, PageResult, true, RequestSchema> &
132
+ EndpointHelper<Options, UseDiscriminator>
133
+ }
@@ -0,0 +1,264 @@
1
+ import type {
2
+ ErrorSchemaRecord,
3
+ Simplify,
4
+ UrlHasParams,
5
+ UrlParams,
6
+ } from '@navios/builder'
7
+ import type {
8
+ MutationFunctionContext,
9
+ UseMutationResult,
10
+ } from '@tanstack/react-query'
11
+ import type { ZodObject, ZodType } from 'zod/v4'
12
+
13
+ import type { MutationArgs, MutationHelpers } from '../../mutation/types.mjs'
14
+ import type { ComputeBaseResult, EndpointHelper } from './helpers.mjs'
15
+
16
+ /**
17
+ * Multipart mutation method overloads for ClientInstance.
18
+ *
19
+ * @template UseDiscriminator - When `true`, errors are returned as union types.
20
+ * When `false` (default), errors are thrown and not included in TData.
21
+ */
22
+ export interface ClientMultipartMutationMethods<
23
+ UseDiscriminator extends boolean = false,
24
+ > {
25
+ // ============================================================================
26
+ // MULTIPART MUTATION METHODS
27
+ // ============================================================================
28
+
29
+ multipartMutation<
30
+ Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH',
31
+ Url extends string = string,
32
+ RequestSchema extends ZodType = ZodType,
33
+ QuerySchema extends ZodObject = ZodObject,
34
+ Response extends ZodType = ZodType,
35
+ ErrorSchema extends ErrorSchemaRecord | undefined = undefined,
36
+ TBaseResult = ComputeBaseResult<UseDiscriminator, Response, ErrorSchema>,
37
+ Result = unknown,
38
+ OnMutateResult = unknown,
39
+ Context = unknown,
40
+ UseKey extends true = true,
41
+ >(config: {
42
+ method: Method
43
+ url: Url
44
+ useKey: UseKey
45
+ requestSchema: RequestSchema
46
+ querySchema: QuerySchema
47
+ responseSchema: Response
48
+ errorSchema?: ErrorSchema
49
+ processResponse: (data: TBaseResult) => Result | Promise<Result>
50
+ useContext?: () => Context
51
+ onMutate?: (
52
+ variables: Simplify<MutationArgs<Url, RequestSchema, QuerySchema>>,
53
+ context: Context & MutationFunctionContext,
54
+ ) => OnMutateResult | Promise<OnMutateResult>
55
+ onSuccess?: (
56
+ data: NoInfer<Result>,
57
+ variables: Simplify<MutationArgs<Url, RequestSchema, QuerySchema>>,
58
+ context: Context &
59
+ MutationFunctionContext & {
60
+ onMutateResult: OnMutateResult | undefined
61
+ },
62
+ ) => void | Promise<void>
63
+ onError?: (
64
+ error: Error,
65
+ variables: Simplify<MutationArgs<Url, RequestSchema, QuerySchema>>,
66
+ context: Context &
67
+ MutationFunctionContext & {
68
+ onMutateResult: OnMutateResult | undefined
69
+ },
70
+ ) => void | Promise<void>
71
+ onSettled?: (
72
+ data: NoInfer<Result> | undefined,
73
+ error: Error | null,
74
+ variables: Simplify<MutationArgs<Url, RequestSchema, QuerySchema>>,
75
+ context: Context &
76
+ MutationFunctionContext & {
77
+ onMutateResult: OnMutateResult | undefined
78
+ },
79
+ ) => void | Promise<void>
80
+ }): ((
81
+ params: UrlHasParams<Url> extends true ? { urlParams: UrlParams<Url> } : {},
82
+ ) => UseMutationResult<
83
+ Result,
84
+ Error,
85
+ MutationArgs<Url, RequestSchema, QuerySchema>,
86
+ OnMutateResult
87
+ >) &
88
+ MutationHelpers<Url, Result> &
89
+ EndpointHelper<Method, Url, RequestSchema, Response, QuerySchema>
90
+
91
+ multipartMutation<
92
+ Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH',
93
+ Url extends string = string,
94
+ RequestSchema extends ZodType = ZodType,
95
+ QuerySchema extends ZodObject = ZodObject,
96
+ Response extends ZodType = ZodType,
97
+ ErrorSchema extends ErrorSchemaRecord | undefined = undefined,
98
+ TBaseResult = ComputeBaseResult<UseDiscriminator, Response, ErrorSchema>,
99
+ Result = unknown,
100
+ OnMutateResult = unknown,
101
+ Context = unknown,
102
+ >(config: {
103
+ method: Method
104
+ url: Url
105
+ requestSchema: RequestSchema
106
+ querySchema: QuerySchema
107
+ responseSchema: Response
108
+ errorSchema?: ErrorSchema
109
+ processResponse: (data: TBaseResult) => Result | Promise<Result>
110
+ useContext?: () => Context
111
+ onMutate?: (
112
+ variables: Simplify<MutationArgs<Url, RequestSchema, QuerySchema>>,
113
+ context: Context & MutationFunctionContext,
114
+ ) => OnMutateResult | Promise<OnMutateResult>
115
+ onSuccess?: (
116
+ data: NoInfer<Result>,
117
+ variables: Simplify<MutationArgs<Url, RequestSchema, QuerySchema>>,
118
+ context: Context &
119
+ MutationFunctionContext & {
120
+ onMutateResult: OnMutateResult | undefined
121
+ },
122
+ ) => void | Promise<void>
123
+ onError?: (
124
+ error: Error,
125
+ variables: Simplify<MutationArgs<Url, RequestSchema, QuerySchema>>,
126
+ context: Context &
127
+ MutationFunctionContext & {
128
+ onMutateResult: OnMutateResult | undefined
129
+ },
130
+ ) => void | Promise<void>
131
+ onSettled?: (
132
+ data: NoInfer<Result> | undefined,
133
+ error: Error | null,
134
+ variables: Simplify<MutationArgs<Url, RequestSchema, QuerySchema>>,
135
+ context: Context &
136
+ MutationFunctionContext & {
137
+ onMutateResult: OnMutateResult | undefined
138
+ },
139
+ ) => void | Promise<void>
140
+ }): (() => UseMutationResult<
141
+ Result,
142
+ Error,
143
+ MutationArgs<Url, RequestSchema, QuerySchema>,
144
+ OnMutateResult
145
+ >) &
146
+ MutationHelpers<Url, Result> &
147
+ EndpointHelper<Method, Url, RequestSchema, Response, QuerySchema>
148
+
149
+ multipartMutation<
150
+ Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH',
151
+ Url extends string = string,
152
+ RequestSchema extends ZodType = ZodType,
153
+ Response extends ZodType = ZodType,
154
+ ErrorSchema extends ErrorSchemaRecord | undefined = undefined,
155
+ TBaseResult = ComputeBaseResult<UseDiscriminator, Response, ErrorSchema>,
156
+ Result = unknown,
157
+ OnMutateResult = unknown,
158
+ Context = unknown,
159
+ >(config: {
160
+ method: Method
161
+ url: Url
162
+ requestSchema: RequestSchema
163
+ responseSchema: Response
164
+ errorSchema?: ErrorSchema
165
+ processResponse: (data: TBaseResult) => Result | Promise<Result>
166
+ useContext?: () => Context
167
+ onMutate?: (
168
+ variables: Simplify<MutationArgs<Url, RequestSchema, undefined>>,
169
+ context: Context & MutationFunctionContext,
170
+ ) => OnMutateResult | Promise<OnMutateResult>
171
+ onSuccess?: (
172
+ data: NoInfer<Result>,
173
+ variables: Simplify<MutationArgs<Url, RequestSchema, undefined>>,
174
+ context: Context &
175
+ MutationFunctionContext & {
176
+ onMutateResult: OnMutateResult | undefined
177
+ },
178
+ ) => void | Promise<void>
179
+ onError?: (
180
+ error: Error,
181
+ variables: Simplify<MutationArgs<Url, RequestSchema, undefined>>,
182
+ context: Context &
183
+ MutationFunctionContext & {
184
+ onMutateResult: OnMutateResult | undefined
185
+ },
186
+ ) => void | Promise<void>
187
+ onSettled?: (
188
+ data: NoInfer<Result> | undefined,
189
+ error: Error | null,
190
+ variables: Simplify<MutationArgs<Url, RequestSchema, undefined>>,
191
+ context: Context &
192
+ MutationFunctionContext & {
193
+ onMutateResult: OnMutateResult | undefined
194
+ },
195
+ ) => void | Promise<void>
196
+ }): (() => UseMutationResult<
197
+ Result,
198
+ Error,
199
+ MutationArgs<Url, RequestSchema, undefined>,
200
+ OnMutateResult
201
+ >) &
202
+ MutationHelpers<Url, Result> &
203
+ EndpointHelper<Method, Url, RequestSchema, Response>
204
+
205
+ multipartMutation<
206
+ Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH',
207
+ Url extends string = string,
208
+ RequestSchema extends ZodType = ZodType,
209
+ Response extends ZodType = ZodType,
210
+ ErrorSchema extends ErrorSchemaRecord | undefined = undefined,
211
+ TBaseResult = ComputeBaseResult<UseDiscriminator, Response, ErrorSchema>,
212
+ Result = unknown,
213
+ OnMutateResult = unknown,
214
+ Context = unknown,
215
+ UseKey extends true = true,
216
+ >(config: {
217
+ method: Method
218
+ url: Url
219
+ useKey: UseKey
220
+ requestSchema: RequestSchema
221
+ responseSchema: Response
222
+ errorSchema?: ErrorSchema
223
+ processResponse: (data: TBaseResult) => Result | Promise<Result>
224
+ useContext?: () => Context
225
+ onMutate?: (
226
+ variables: Simplify<MutationArgs<Url, RequestSchema, undefined>>,
227
+ context: Context & MutationFunctionContext,
228
+ ) => OnMutateResult | Promise<OnMutateResult>
229
+ onSuccess?: (
230
+ data: NoInfer<Result>,
231
+ variables: Simplify<MutationArgs<Url, RequestSchema, undefined>>,
232
+ context: Context &
233
+ MutationFunctionContext & {
234
+ onMutateResult: OnMutateResult | undefined
235
+ },
236
+ ) => void | Promise<void>
237
+ onError?: (
238
+ error: Error,
239
+ variables: Simplify<MutationArgs<Url, RequestSchema, undefined>>,
240
+ context: Context &
241
+ MutationFunctionContext & {
242
+ onMutateResult: OnMutateResult | undefined
243
+ },
244
+ ) => void | Promise<void>
245
+ onSettled?: (
246
+ data: NoInfer<Result> | undefined,
247
+ error: Error | null,
248
+ variables: Simplify<MutationArgs<Url, RequestSchema, undefined>>,
249
+ context: Context &
250
+ MutationFunctionContext & {
251
+ onMutateResult: OnMutateResult | undefined
252
+ },
253
+ ) => void | Promise<void>
254
+ }): ((
255
+ params: UrlHasParams<Url> extends true ? { urlParams: UrlParams<Url> } : {},
256
+ ) => UseMutationResult<
257
+ Result,
258
+ Error,
259
+ MutationArgs<Url, RequestSchema, undefined>,
260
+ OnMutateResult
261
+ >) &
262
+ MutationHelpers<Url, Result> &
263
+ EndpointHelper<Method, Url, RequestSchema, Response>
264
+ }