@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/lib/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as _navios_builder0 from "@navios/builder";
|
|
2
|
-
import { AbstractEndpoint, AnyEndpointConfig, BaseEndpointConfig,
|
|
3
|
-
import * as _tanstack_react_query1 from "@tanstack/react-query";
|
|
4
|
-
import { DataTag, InfiniteData, MutationFunctionContext, QueryClient, UseInfiniteQueryOptions, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult, UseSuspenseInfiniteQueryOptions, UseSuspenseQueryOptions, UseSuspenseQueryResult } from "@tanstack/react-query";
|
|
2
|
+
import { AbstractEndpoint, AnyEndpointConfig, BaseEndpointConfig, BaseEndpointOptions, BuilderInstance, EndpointHandler, EndpointOptions, ErrorSchemaRecord, HttpMethod, InferEndpointParams, InferEndpointReturn, InferErrorSchemaOutput, RequestArgs, Simplify, StreamHandler, UrlHasParams, UrlParams } from "@navios/builder";
|
|
5
3
|
import { ZodObject, ZodType, z } from "zod/v4";
|
|
4
|
+
import * as _tanstack_react_query0 from "@tanstack/react-query";
|
|
5
|
+
import { DataTag, FetchQueryOptions, InfiniteData, MutationFunctionContext, QueryClient, QueryKey, UseInfiniteQueryOptions, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult, UseSuspenseInfiniteQueryOptions, UseSuspenseQueryOptions, UseSuspenseQueryResult } from "@tanstack/react-query";
|
|
6
6
|
|
|
7
7
|
//#region src/common/types.d.mts
|
|
8
8
|
/**
|
|
@@ -13,29 +13,66 @@ type Split<S extends string, D extends string> = string extends S ? string[] : S
|
|
|
13
13
|
/**
|
|
14
14
|
* Function type for processing API responses before returning to the caller.
|
|
15
15
|
*/
|
|
16
|
-
type ProcessResponseFunction<TData = unknown, TVariables = unknown> = (variables: TVariables) => Promise<TData> | TData;
|
|
16
|
+
type ProcessResponseFunction<TData$1 = unknown, TVariables = unknown> = (variables: TVariables) => Promise<TData$1> | TData$1;
|
|
17
|
+
/**
|
|
18
|
+
* Compute the response input type based on discriminator and error schema.
|
|
19
|
+
* When UseDiscriminator=true and errorSchema is present, errors are included as a union.
|
|
20
|
+
* When UseDiscriminator=false, only the success type is returned (errors are thrown).
|
|
21
|
+
*
|
|
22
|
+
* @template UseDiscriminator - Whether to include error types in the response union
|
|
23
|
+
* @template ResponseSchema - The success response schema
|
|
24
|
+
* @template ErrorSchema - The error schema record (optional)
|
|
25
|
+
*/
|
|
26
|
+
type ComputeResponseInput<UseDiscriminator extends boolean, ResponseSchema extends ZodType, ErrorSchema extends ErrorSchemaRecord | undefined> = UseDiscriminator extends true ? ErrorSchema extends ErrorSchemaRecord ? z.output<ResponseSchema> | InferErrorSchemaOutput<ErrorSchema> : z.output<ResponseSchema> : z.output<ResponseSchema>;
|
|
17
27
|
/**
|
|
18
28
|
* Options for creating a client instance.
|
|
29
|
+
*
|
|
30
|
+
* @template UseDiscriminator - When `true`, errors are returned as union types.
|
|
31
|
+
* When `false` (default), errors are thrown.
|
|
19
32
|
*/
|
|
20
|
-
type ClientOptions = {
|
|
21
|
-
api: BuilderInstance
|
|
33
|
+
type ClientOptions<UseDiscriminator extends boolean = false> = {
|
|
34
|
+
api: BuilderInstance<UseDiscriminator>;
|
|
22
35
|
defaults?: {
|
|
23
36
|
keyPrefix?: string[];
|
|
24
37
|
keySuffix?: string[];
|
|
25
38
|
};
|
|
26
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Infers the full response type from an endpoint configuration.
|
|
42
|
+
* Returns `ResponseType | ErrorTypes` if errorSchema exists,
|
|
43
|
+
* otherwise just `ResponseType`.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* type Response = InferEndpointResponse<{
|
|
48
|
+
* responseSchema: z.ZodObject<{ data: z.ZodString }>,
|
|
49
|
+
* errorSchema: { 400: z.ZodObject<{ error: z.ZodString }> }
|
|
50
|
+
* }>
|
|
51
|
+
* // Result: { data: string } | { error: string }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
type InferEndpointResponse<Config extends {
|
|
55
|
+
responseSchema: ZodType;
|
|
56
|
+
errorSchema?: ErrorSchemaRecord;
|
|
57
|
+
}> = Config['errorSchema'] extends ErrorSchemaRecord ? z.output<Config['responseSchema']> | InferErrorSchemaOutput<Config['errorSchema']> : z.output<Config['responseSchema']>;
|
|
58
|
+
/**
|
|
59
|
+
* Computes the Result type, applying processResponse transformation
|
|
60
|
+
* to the full response (including error union when present).
|
|
61
|
+
*/
|
|
62
|
+
type ComputeResultType<ResponseSchema extends ZodType, ErrorSchema extends ErrorSchemaRecord | undefined, ProcessedResult> = ProcessedResult extends undefined ? ErrorSchema extends ErrorSchemaRecord ? z.output<ResponseSchema> | InferErrorSchemaOutput<ErrorSchema> : z.output<ResponseSchema> : ProcessedResult;
|
|
27
63
|
//#endregion
|
|
28
64
|
//#region src/query/types.d.mts
|
|
65
|
+
/**
|
|
66
|
+
* Helper type to extract the result type from processResponse.
|
|
67
|
+
*/
|
|
68
|
+
type QueryResult<Options extends EndpointOptions, UseDiscriminator extends boolean = false> = Options extends {
|
|
69
|
+
processResponse: (data: any) => infer Result;
|
|
70
|
+
} ? Result : InferEndpointReturn<Options, UseDiscriminator>;
|
|
29
71
|
/**
|
|
30
72
|
* Arguments for query functions based on URL params and query schema.
|
|
73
|
+
* Uses RequestArgs from builder for consistency.
|
|
31
74
|
*/
|
|
32
|
-
type QueryArgs<Url extends string = string, QuerySchema =
|
|
33
|
-
urlParams: UrlParams<Url>;
|
|
34
|
-
} : {}) & (QuerySchema extends ZodObject ? {
|
|
35
|
-
params: z.input<QuerySchema>;
|
|
36
|
-
} : {}) & (RequestSchema extends ZodType ? {
|
|
37
|
-
data: z.input<RequestSchema>;
|
|
38
|
-
} : {});
|
|
75
|
+
type QueryArgs<Url extends string = string, QuerySchema extends ZodObject | undefined = undefined, RequestSchema extends ZodType | undefined = undefined> = RequestArgs<Url, QuerySchema, RequestSchema>;
|
|
39
76
|
/**
|
|
40
77
|
* Arguments containing only URL params (for invalidateAll operations).
|
|
41
78
|
*/
|
|
@@ -44,12 +81,15 @@ type QueryUrlParamsArgs<Url extends string = string> = UrlHasParams<Url> extends
|
|
|
44
81
|
} : {} | undefined;
|
|
45
82
|
/**
|
|
46
83
|
* Base parameters for query configuration.
|
|
84
|
+
*
|
|
85
|
+
* @template UseDiscriminator - When `true`, errors are returned as union types in processResponse.
|
|
86
|
+
* When `false` (default), errors are thrown and not included in the response type.
|
|
47
87
|
*/
|
|
48
|
-
type QueryParams<Config extends AnyEndpointConfig, Res = any> = {
|
|
88
|
+
type QueryParams<Config extends AnyEndpointConfig, Res = any, UseDiscriminator extends boolean = false> = {
|
|
49
89
|
keyPrefix?: string[];
|
|
50
90
|
keySuffix?: string[];
|
|
51
91
|
onFail?: (err: unknown) => void;
|
|
52
|
-
processResponse: (data:
|
|
92
|
+
processResponse: (data: ComputeResponseInput<UseDiscriminator, Config['responseSchema'], Config['errorSchema']>) => Res;
|
|
53
93
|
};
|
|
54
94
|
/**
|
|
55
95
|
* Result type from the query key creator function.
|
|
@@ -75,25 +115,28 @@ type QueryKeyCreatorResult<QuerySchema = undefined, Url extends string = string,
|
|
|
75
115
|
*/
|
|
76
116
|
type QueryHelpers<Url extends string, QuerySchema extends ZodObject | undefined = undefined, Result$1 = undefined, IsInfinite extends boolean = false, RequestSchema extends ZodType | undefined = undefined> = {
|
|
77
117
|
queryKey: QueryKeyCreatorResult<QuerySchema, Url, Result$1, IsInfinite>;
|
|
78
|
-
use: (params:
|
|
79
|
-
useSuspense: (params:
|
|
80
|
-
invalidate: (queryClient: QueryClient, params:
|
|
81
|
-
invalidateAll: (queryClient: QueryClient, params:
|
|
118
|
+
use: (params: Simplify<QueryArgs<Url, QuerySchema, RequestSchema>>) => UseQueryResult<Result$1, Error>;
|
|
119
|
+
useSuspense: (params: Simplify<QueryArgs<Url, QuerySchema, RequestSchema>>) => UseSuspenseQueryResult<Result$1, Error>;
|
|
120
|
+
invalidate: (queryClient: QueryClient, params: Simplify<QueryArgs<Url, QuerySchema, RequestSchema>>) => () => Promise<void>;
|
|
121
|
+
invalidateAll: (queryClient: QueryClient, params: Simplify<QueryUrlParamsArgs<Url>>) => () => Promise<void>;
|
|
82
122
|
};
|
|
83
123
|
/**
|
|
84
124
|
* Options for infinite query configuration.
|
|
125
|
+
*
|
|
126
|
+
* @template UseDiscriminator - When `true`, errors are returned as union types in processResponse.
|
|
127
|
+
* When `false` (default), errors are thrown and not included in the response type.
|
|
85
128
|
*/
|
|
86
|
-
type InfiniteQueryOptions<Config extends BaseEndpointConfig<HttpMethod, string, ZodObject>, Res = any> = {
|
|
129
|
+
type InfiniteQueryOptions<Config extends BaseEndpointConfig<HttpMethod, string, ZodObject>, Res = any, UseDiscriminator extends boolean = false> = {
|
|
87
130
|
keyPrefix?: string[];
|
|
88
131
|
keySuffix?: string[];
|
|
89
|
-
processResponse: (data:
|
|
132
|
+
processResponse: (data: ComputeResponseInput<UseDiscriminator, Config['responseSchema'], Config['errorSchema']>) => Res;
|
|
90
133
|
onFail?: (err: unknown) => void;
|
|
91
134
|
getNextPageParam: (lastPage: Res, allPages: Res[], lastPageParam: z.infer<Config['querySchema']> | undefined, allPageParams: z.infer<Config['querySchema']>[] | undefined) => z.input<Config['querySchema']> | z.infer<Config['querySchema']> | undefined;
|
|
92
135
|
getPreviousPageParam?: (firstPage: Res, allPages: Res[], lastPageParam: z.infer<Config['querySchema']> | undefined, allPageParams: z.infer<Config['querySchema']>[] | undefined) => z.input<Config['querySchema']>;
|
|
93
136
|
initialPageParam?: z.input<Config['querySchema']> | z.infer<Config['querySchema']>;
|
|
94
137
|
};
|
|
95
138
|
/** @deprecated Use QueryArgs instead */
|
|
96
|
-
type ClientQueryArgs<Url extends string = string, QuerySchema = ZodObject, RequestSchema = undefined> = QueryArgs<Url, QuerySchema, RequestSchema>;
|
|
139
|
+
type ClientQueryArgs<Url extends string = string, QuerySchema extends ZodObject = ZodObject, RequestSchema extends ZodType | undefined = undefined> = QueryArgs<Url, QuerySchema, RequestSchema>;
|
|
97
140
|
/** @deprecated Use QueryUrlParamsArgs instead */
|
|
98
141
|
type ClientQueryUrlParamsArgs<Url extends string = string> = QueryUrlParamsArgs<Url>;
|
|
99
142
|
/** @deprecated Use QueryParams instead */
|
|
@@ -122,25 +165,54 @@ declare function createQueryKey<Config extends AnyEndpointConfig, Options extend
|
|
|
122
165
|
declare const queryKeyCreator: typeof createQueryKey;
|
|
123
166
|
//#endregion
|
|
124
167
|
//#region src/query/make-options.d.mts
|
|
168
|
+
/**
|
|
169
|
+
* Options for makeQueryOptions.
|
|
170
|
+
*/
|
|
171
|
+
interface MakeQueryOptionsParams<Options extends EndpointOptions, UseDiscriminator extends boolean = false, Result$1 = QueryResult<Options, UseDiscriminator>> {
|
|
172
|
+
keyPrefix?: string[];
|
|
173
|
+
keySuffix?: string[];
|
|
174
|
+
onFail?: (err: unknown) => void;
|
|
175
|
+
processResponse: (data: InferEndpointReturn<Options, UseDiscriminator>) => Result$1;
|
|
176
|
+
}
|
|
125
177
|
/**
|
|
126
178
|
* Creates query options for a given endpoint.
|
|
127
179
|
*
|
|
128
180
|
* Returns a function that generates TanStack Query options when called with params.
|
|
129
181
|
* The returned function also has helper methods attached (use, useSuspense, invalidate, etc.)
|
|
130
182
|
*
|
|
131
|
-
*
|
|
183
|
+
* Uses const generics pattern to automatically infer types from the endpoint configuration.
|
|
184
|
+
*
|
|
185
|
+
* @param endpoint - The navios endpoint handler (from builder's declareEndpoint)
|
|
132
186
|
* @param options - Query configuration including processResponse
|
|
133
187
|
* @param baseQuery - Optional base query options to merge
|
|
134
188
|
* @returns A function that generates query options with attached helpers
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* const getUser = api.declareEndpoint({
|
|
193
|
+
* method: 'GET',
|
|
194
|
+
* url: '/users/$userId',
|
|
195
|
+
* responseSchema: userSchema,
|
|
196
|
+
* })
|
|
197
|
+
*
|
|
198
|
+
* const queryOptions = makeQueryOptions(getUser, {
|
|
199
|
+
* processResponse: (data) => data,
|
|
200
|
+
* })
|
|
201
|
+
*
|
|
202
|
+
* const { data } = queryOptions.useSuspense({ urlParams: { userId: '123' } })
|
|
203
|
+
* ```
|
|
135
204
|
*/
|
|
136
|
-
declare function makeQueryOptions<
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
205
|
+
declare function makeQueryOptions<const Options extends EndpointOptions, UseDiscriminator extends boolean = false, Result$1 = QueryResult<Options, UseDiscriminator>, BaseQuery extends Omit<UseQueryOptions<Result$1, Error, any>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam' | 'enabled' | 'throwOnError' | 'placeholderData'> = Omit<UseQueryOptions<Result$1, Error, any>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam' | 'enabled' | 'throwOnError' | 'placeholderData'>>(endpoint: EndpointHandler<Options, UseDiscriminator>, options: MakeQueryOptionsParams<Options, UseDiscriminator, Result$1>, baseQuery?: BaseQuery): ((params: Simplify<QueryArgs<Options['url'], Options extends {
|
|
206
|
+
querySchema: infer Q extends ZodObject;
|
|
207
|
+
} ? Q : undefined, Options extends {
|
|
208
|
+
requestSchema: infer R extends ZodType;
|
|
209
|
+
} ? R : undefined>>) => UseSuspenseQueryOptions<Result$1, Error, BaseQuery extends {
|
|
210
|
+
select: (...args: any[]) => infer T;
|
|
211
|
+
} ? T : Result$1, DataTag<Split<Options['url'], '/'>, Result$1, Error>>) & QueryHelpers<Options['url'], Options extends {
|
|
212
|
+
querySchema: infer Q extends ZodObject;
|
|
213
|
+
} ? Q : undefined, Result$1, false, Options extends {
|
|
214
|
+
requestSchema: infer R extends ZodType;
|
|
215
|
+
} ? R : undefined>;
|
|
144
216
|
//#endregion
|
|
145
217
|
//#region src/query/make-infinite-options.d.mts
|
|
146
218
|
/**
|
|
@@ -156,52 +228,317 @@ declare function makeQueryOptions<Config extends AnyEndpointConfig, Options exte
|
|
|
156
228
|
*/
|
|
157
229
|
declare function makeInfiniteQueryOptions<Config extends AnyEndpointConfig, Options extends InfiniteQueryOptions<Config>, BaseQuery extends Omit<UseInfiniteQueryOptions<ReturnType<Options['processResponse']>, Error, any>, 'queryKey' | 'queryFn' | 'getNextPageParam' | 'initialPageParam' | 'placeholderData' | 'throwOnError'>>(endpoint: AbstractEndpoint<Config>, options: Options, baseQuery?: BaseQuery): {
|
|
158
230
|
(params: QueryArgs<Config["url"], Config["querySchema"]>): Options["processResponse"] extends ((...args: any[]) => infer Result) ? UseSuspenseInfiniteQueryOptions<Result, Error, BaseQuery["select"] extends ((...args: any[]) => infer T) ? T : InfiniteData<Result>> : never;
|
|
231
|
+
/** The query key creator for this infinite query endpoint */
|
|
159
232
|
queryKey: QueryKeyCreatorResult<Config["querySchema"], Config["url"], Options["processResponse"] extends ((...args: any[]) => infer Result) ? Result : never, true, _navios_builder0.UrlHasParams<Config["url"]>>;
|
|
160
|
-
use(params: QueryArgs<Config["url"], Config["querySchema"]>):
|
|
161
|
-
useSuspense(params: QueryArgs<Config["url"], Config["querySchema"]>):
|
|
162
|
-
invalidate(queryClient: QueryClient, params: QueryArgs<Config["url"], Config["querySchema"]>): Promise<void>;
|
|
163
|
-
invalidateAll(queryClient: QueryClient, params: QueryArgs<Config["url"], Config["querySchema"]>): Promise<void>;
|
|
233
|
+
use(params: QueryArgs<Config["url"], Config["querySchema"]>): _tanstack_react_query0.UseInfiniteQueryResult<BaseQuery["select"] extends ((...args: any[]) => infer T) ? T : InfiniteData<unknown, unknown>, Error>;
|
|
234
|
+
useSuspense(params: QueryArgs<Config["url"], Config["querySchema"]>): _tanstack_react_query0.UseSuspenseInfiniteQueryResult<BaseQuery["select"] extends ((...args: any[]) => infer T) ? T : InfiniteData<unknown, unknown>, Error>;
|
|
235
|
+
invalidate(queryClient: QueryClient, params: QueryArgs<Config["url"], Config["querySchema"]>): () => Promise<void>;
|
|
236
|
+
invalidateAll(queryClient: QueryClient, params: QueryArgs<Config["url"], Config["querySchema"]>): () => Promise<void>;
|
|
164
237
|
};
|
|
165
238
|
//#endregion
|
|
239
|
+
//#region src/query/prefetch.d.mts
|
|
240
|
+
/**
|
|
241
|
+
* Type for a query options creator function that returns TanStack Query options.
|
|
242
|
+
*
|
|
243
|
+
* This matches the return type of `client.query()` from the navios react-query client.
|
|
244
|
+
*/
|
|
245
|
+
type QueryOptionsCreator<TParams$1, TData$1, TError$1 = Error> = (params: TParams$1) => FetchQueryOptions<TData$1, TError$1, TData$1, QueryKey>;
|
|
246
|
+
/**
|
|
247
|
+
* Helper utilities for prefetching queries.
|
|
248
|
+
*
|
|
249
|
+
* @template TParams - The query parameters type
|
|
250
|
+
* @template TData - The query data type
|
|
251
|
+
* @template TError - The error type (defaults to Error)
|
|
252
|
+
*/
|
|
253
|
+
interface PrefetchHelper<TParams$1, TData$1, TError$1 = Error> {
|
|
254
|
+
/**
|
|
255
|
+
* Prefetch query data on the server.
|
|
256
|
+
*
|
|
257
|
+
* Use this in server components or getServerSideProps to
|
|
258
|
+
* prefetch data before rendering.
|
|
259
|
+
*
|
|
260
|
+
* @param queryClient - The QueryClient instance
|
|
261
|
+
* @param params - Parameters for the query
|
|
262
|
+
* @returns Promise that resolves when prefetch is complete
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```tsx
|
|
266
|
+
* // In a Next.js Server Component
|
|
267
|
+
* const queryClient = new QueryClient()
|
|
268
|
+
* await prefetch.prefetch(queryClient, { urlParams: { userId: '1' } })
|
|
269
|
+
* return (
|
|
270
|
+
* <HydrationBoundary state={dehydrate(queryClient)}>
|
|
271
|
+
* <UserProfile userId="1" />
|
|
272
|
+
* </HydrationBoundary>
|
|
273
|
+
* )
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
prefetch: (queryClient: QueryClient, params: TParams$1) => Promise<void>;
|
|
277
|
+
/**
|
|
278
|
+
* Ensure query data exists in cache. Fetches only if not cached.
|
|
279
|
+
*
|
|
280
|
+
* Returns the cached or fetched data.
|
|
281
|
+
*
|
|
282
|
+
* @param queryClient - The QueryClient instance
|
|
283
|
+
* @param params - Parameters for the query
|
|
284
|
+
* @returns Promise that resolves to the query data
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```tsx
|
|
288
|
+
* // Ensure data exists before rendering
|
|
289
|
+
* const userData = await prefetch.ensureData(queryClient, {
|
|
290
|
+
* urlParams: { userId: '1' },
|
|
291
|
+
* })
|
|
292
|
+
* console.log('User:', userData.name)
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
ensureData: (queryClient: QueryClient, params: TParams$1) => Promise<TData$1>;
|
|
296
|
+
/**
|
|
297
|
+
* Get the query options for a given set of parameters.
|
|
298
|
+
*
|
|
299
|
+
* Useful for advanced use cases or when you need to
|
|
300
|
+
* customize the prefetch behavior.
|
|
301
|
+
*
|
|
302
|
+
* @param params - Parameters for the query
|
|
303
|
+
* @returns The query options object
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* ```tsx
|
|
307
|
+
* const options = prefetch.getQueryOptions({ urlParams: { userId: '1' } })
|
|
308
|
+
* await queryClient.prefetchQuery({
|
|
309
|
+
* ...options,
|
|
310
|
+
* staleTime: 60000, // Override stale time for prefetch
|
|
311
|
+
* })
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
getQueryOptions: (params: TParams$1) => FetchQueryOptions<TData$1, TError$1, TData$1, QueryKey>;
|
|
315
|
+
/**
|
|
316
|
+
* Prefetch multiple queries in parallel.
|
|
317
|
+
*
|
|
318
|
+
* @param queryClient - The QueryClient instance
|
|
319
|
+
* @param paramsList - Array of parameters for multiple queries
|
|
320
|
+
* @returns Promise that resolves when all prefetches complete
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```tsx
|
|
324
|
+
* // Prefetch multiple users in parallel
|
|
325
|
+
* await prefetch.prefetchMany(queryClient, [
|
|
326
|
+
* { urlParams: { userId: '1' } },
|
|
327
|
+
* { urlParams: { userId: '2' } },
|
|
328
|
+
* { urlParams: { userId: '3' } },
|
|
329
|
+
* ])
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
prefetchMany: (queryClient: QueryClient, paramsList: TParams$1[]) => Promise<void>;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Creates a type-safe prefetch helper for SSR/RSC.
|
|
336
|
+
*
|
|
337
|
+
* This utility wraps a query options creator to provide convenient
|
|
338
|
+
* methods for server-side data fetching and hydration.
|
|
339
|
+
*
|
|
340
|
+
* @param queryOptionsCreator - A function that creates query options (from client.query())
|
|
341
|
+
* @returns A prefetch helper object with prefetch, ensureData, and getQueryOptions methods
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```tsx
|
|
345
|
+
* // 1. Create your query
|
|
346
|
+
* const getUserQuery = client.query({
|
|
347
|
+
* method: 'GET',
|
|
348
|
+
* url: '/users/$userId',
|
|
349
|
+
* responseSchema: userSchema,
|
|
350
|
+
* })
|
|
351
|
+
*
|
|
352
|
+
* // 2. Create prefetch helper
|
|
353
|
+
* const userPrefetch = createPrefetchHelper(getUserQuery)
|
|
354
|
+
*
|
|
355
|
+
* // 3. Use in server component
|
|
356
|
+
* async function UserPage({ userId }: { userId: string }) {
|
|
357
|
+
* const queryClient = new QueryClient()
|
|
358
|
+
*
|
|
359
|
+
* await userPrefetch.prefetch(queryClient, {
|
|
360
|
+
* urlParams: { userId },
|
|
361
|
+
* })
|
|
362
|
+
*
|
|
363
|
+
* return (
|
|
364
|
+
* <HydrationBoundary state={dehydrate(queryClient)}>
|
|
365
|
+
* <UserProfile userId={userId} />
|
|
366
|
+
* </HydrationBoundary>
|
|
367
|
+
* )
|
|
368
|
+
* }
|
|
369
|
+
* ```
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* ```tsx
|
|
373
|
+
* // With Next.js App Router
|
|
374
|
+
* import { dehydrate, HydrationBoundary, QueryClient } from '@tanstack/react-query'
|
|
375
|
+
* import { createPrefetchHelper } from '@navios/react-query'
|
|
376
|
+
*
|
|
377
|
+
* // Define queries
|
|
378
|
+
* const getPostsQuery = client.query({
|
|
379
|
+
* method: 'GET',
|
|
380
|
+
* url: '/posts',
|
|
381
|
+
* querySchema: z.object({ page: z.number() }),
|
|
382
|
+
* responseSchema: postsSchema,
|
|
383
|
+
* })
|
|
384
|
+
*
|
|
385
|
+
* const postsPrefetch = createPrefetchHelper(getPostsQuery)
|
|
386
|
+
*
|
|
387
|
+
* // Server Component
|
|
388
|
+
* export default async function PostsPage() {
|
|
389
|
+
* const queryClient = new QueryClient()
|
|
390
|
+
*
|
|
391
|
+
* await postsPrefetch.prefetch(queryClient, {
|
|
392
|
+
* params: { page: 1 },
|
|
393
|
+
* })
|
|
394
|
+
*
|
|
395
|
+
* return (
|
|
396
|
+
* <HydrationBoundary state={dehydrate(queryClient)}>
|
|
397
|
+
* <PostsList />
|
|
398
|
+
* </HydrationBoundary>
|
|
399
|
+
* )
|
|
400
|
+
* }
|
|
401
|
+
* ```
|
|
402
|
+
*/
|
|
403
|
+
declare function createPrefetchHelper<TParams$1, TData$1, TError$1 = Error>(queryOptionsCreator: QueryOptionsCreator<TParams$1, TData$1, TError$1>): PrefetchHelper<TParams$1, TData$1, TError$1>;
|
|
404
|
+
/**
|
|
405
|
+
* Creates multiple prefetch helpers from a record of query options creators.
|
|
406
|
+
*
|
|
407
|
+
* Useful when you have multiple queries that need to be prefetched together.
|
|
408
|
+
*
|
|
409
|
+
* @param queries - Record of query options creator functions
|
|
410
|
+
* @returns Record of prefetch helpers with the same keys
|
|
411
|
+
*
|
|
412
|
+
* @example
|
|
413
|
+
* ```tsx
|
|
414
|
+
* // Define all your queries
|
|
415
|
+
* const queries = {
|
|
416
|
+
* user: client.query({
|
|
417
|
+
* method: 'GET',
|
|
418
|
+
* url: '/users/$userId',
|
|
419
|
+
* responseSchema: userSchema,
|
|
420
|
+
* }),
|
|
421
|
+
* posts: client.query({
|
|
422
|
+
* method: 'GET',
|
|
423
|
+
* url: '/users/$userId/posts',
|
|
424
|
+
* responseSchema: postsSchema,
|
|
425
|
+
* }),
|
|
426
|
+
* }
|
|
427
|
+
*
|
|
428
|
+
* // Create all prefetch helpers at once
|
|
429
|
+
* const prefetchers = createPrefetchHelpers(queries)
|
|
430
|
+
*
|
|
431
|
+
* // Use in server component
|
|
432
|
+
* async function UserPage({ userId }: { userId: string }) {
|
|
433
|
+
* const queryClient = new QueryClient()
|
|
434
|
+
*
|
|
435
|
+
* await Promise.all([
|
|
436
|
+
* prefetchers.user.prefetch(queryClient, { urlParams: { userId } }),
|
|
437
|
+
* prefetchers.posts.prefetch(queryClient, { urlParams: { userId } }),
|
|
438
|
+
* ])
|
|
439
|
+
*
|
|
440
|
+
* return (
|
|
441
|
+
* <HydrationBoundary state={dehydrate(queryClient)}>
|
|
442
|
+
* <UserProfileWithPosts userId={userId} />
|
|
443
|
+
* </HydrationBoundary>
|
|
444
|
+
* )
|
|
445
|
+
* }
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
declare function createPrefetchHelpers<T$1 extends Record<string, QueryOptionsCreator<any, any, any>>>(queries: T$1): { [K in keyof T$1]: T$1[K] extends QueryOptionsCreator<infer TParams, infer TData, infer TError> ? PrefetchHelper<TParams, TData, TError> : never };
|
|
449
|
+
/**
|
|
450
|
+
* Prefetch multiple queries from different query creators in parallel.
|
|
451
|
+
*
|
|
452
|
+
* @param queryClient - The QueryClient instance
|
|
453
|
+
* @param prefetches - Array of { helper, params } objects
|
|
454
|
+
* @returns Promise that resolves when all prefetches complete
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* ```tsx
|
|
458
|
+
* const userPrefetch = createPrefetchHelper(getUserQuery)
|
|
459
|
+
* const postsPrefetch = createPrefetchHelper(getPostsQuery)
|
|
460
|
+
*
|
|
461
|
+
* async function DashboardPage({ userId }: { userId: string }) {
|
|
462
|
+
* const queryClient = new QueryClient()
|
|
463
|
+
*
|
|
464
|
+
* await prefetchAll(queryClient, [
|
|
465
|
+
* { helper: userPrefetch, params: { urlParams: { userId } } },
|
|
466
|
+
* { helper: postsPrefetch, params: { urlParams: { userId }, params: { limit: 10 } } },
|
|
467
|
+
* ])
|
|
468
|
+
*
|
|
469
|
+
* return (
|
|
470
|
+
* <HydrationBoundary state={dehydrate(queryClient)}>
|
|
471
|
+
* <Dashboard userId={userId} />
|
|
472
|
+
* </HydrationBoundary>
|
|
473
|
+
* )
|
|
474
|
+
* }
|
|
475
|
+
* ```
|
|
476
|
+
*/
|
|
477
|
+
declare function prefetchAll(queryClient: QueryClient, prefetches: Array<{
|
|
478
|
+
helper: PrefetchHelper<any, any, any>;
|
|
479
|
+
params: unknown;
|
|
480
|
+
}>): Promise<void>;
|
|
481
|
+
//#endregion
|
|
166
482
|
//#region src/mutation/types.d.mts
|
|
167
483
|
/**
|
|
168
484
|
* Arguments for mutation functions based on URL params, request schema, and query schema.
|
|
485
|
+
* Uses RequestArgs from builder for consistency.
|
|
169
486
|
*/
|
|
170
|
-
type MutationArgs<Url extends string = string, RequestSchema =
|
|
171
|
-
urlParams: UrlParams<Url>;
|
|
172
|
-
} : {}) & (RequestSchema extends ZodObject ? {
|
|
173
|
-
data: z.input<RequestSchema>;
|
|
174
|
-
} : {}) & (QuerySchema extends ZodObject ? {
|
|
175
|
-
params: z.input<QuerySchema>;
|
|
176
|
-
} : {});
|
|
487
|
+
type MutationArgs<Url extends string = string, RequestSchema extends ZodType | undefined = undefined, QuerySchema extends ZodObject | undefined = undefined> = RequestArgs<Url, QuerySchema, RequestSchema>;
|
|
177
488
|
/**
|
|
178
489
|
* Helper methods attached to mutation hooks.
|
|
490
|
+
*
|
|
491
|
+
* @template Url - The URL template string
|
|
492
|
+
* @template Result - The mutation result type
|
|
179
493
|
*/
|
|
180
494
|
type MutationHelpers<Url extends string, Result$1 = unknown> = UrlHasParams<Url> extends true ? {
|
|
181
|
-
|
|
182
|
-
|
|
495
|
+
/**
|
|
496
|
+
* Generates a mutation key for the given URL parameters.
|
|
497
|
+
* Useful for tracking mutations or invalidating related queries.
|
|
498
|
+
*/
|
|
499
|
+
mutationKey: (params: {
|
|
500
|
+
urlParams: UrlParams<Url>;
|
|
501
|
+
}) => DataTag<[Url], Result$1, Error>;
|
|
502
|
+
/**
|
|
503
|
+
* Returns true if a mutation with the given URL parameters is currently in progress.
|
|
504
|
+
* Requires `useKey: true` to be set when creating the mutation.
|
|
505
|
+
*/
|
|
506
|
+
useIsMutating: (keyParams: {
|
|
507
|
+
urlParams: UrlParams<Url>;
|
|
508
|
+
}) => boolean;
|
|
183
509
|
} : {
|
|
510
|
+
/**
|
|
511
|
+
* Generates a mutation key.
|
|
512
|
+
* Useful for tracking mutations or invalidating related queries.
|
|
513
|
+
*/
|
|
184
514
|
mutationKey: () => DataTag<[Url], Result$1, Error>;
|
|
515
|
+
/**
|
|
516
|
+
* Returns true if a mutation is currently in progress.
|
|
517
|
+
* Requires `useKey: true` to be set when creating the mutation.
|
|
518
|
+
*/
|
|
185
519
|
useIsMutating: () => boolean;
|
|
186
520
|
};
|
|
187
521
|
/**
|
|
188
522
|
* Base parameters for mutation configuration.
|
|
523
|
+
*
|
|
524
|
+
* @template UseDiscriminator - When `true`, errors are returned as union types in processResponse.
|
|
525
|
+
* When `false` (default), errors are thrown and not included in TResponse.
|
|
189
526
|
*/
|
|
190
|
-
interface MutationParams<Config extends AnyEndpointConfig, TData = unknown, TVariables =
|
|
191
|
-
processResponse?: ProcessResponseFunction<TData,
|
|
527
|
+
interface MutationParams<Config extends AnyEndpointConfig, TData$1 = unknown, TVariables = RequestArgs<Config['url'], Config['querySchema'], Config['requestSchema'], Config['urlParamsSchema']>, _TResponse = ComputeResponseInput<false, Config['responseSchema'], Config['errorSchema']>, TOnMutateResult = unknown, TContext = unknown, UseKey extends boolean = false, UseDiscriminator extends boolean = false, TError$1 = (UseDiscriminator extends true ? Error : Config['errorSchema'] extends ErrorSchemaRecord ? InferErrorSchemaOutput<Config['errorSchema']> | Error : Error)> extends Omit<UseMutationOptions<TData$1, TError$1, TVariables>, 'mutationKey' | 'mutationFn' | 'onMutate' | 'onSuccess' | 'onError' | 'onSettled' | 'scope'> {
|
|
528
|
+
processResponse?: ProcessResponseFunction<TData$1, ComputeResponseInput<UseDiscriminator, Config['responseSchema'], Config['errorSchema']>>;
|
|
192
529
|
/**
|
|
193
530
|
* React hooks that will prepare the context for the mutation onSuccess and onError
|
|
194
531
|
* callbacks. This is useful for when you want to use the context in the callbacks
|
|
195
532
|
*/
|
|
196
533
|
useContext?: () => TContext;
|
|
197
|
-
onSuccess?: (data: TData, variables: TVariables, context: TContext & MutationFunctionContext & {
|
|
534
|
+
onSuccess?: (data: TData$1, variables: TVariables, context: TContext & MutationFunctionContext & {
|
|
198
535
|
onMutateResult: TOnMutateResult | undefined;
|
|
199
536
|
}) => void | Promise<void>;
|
|
200
|
-
onError?: (err:
|
|
537
|
+
onError?: (err: TError$1, variables: TVariables, context: TContext & MutationFunctionContext & {
|
|
201
538
|
onMutateResult: TOnMutateResult | undefined;
|
|
202
539
|
}) => void | Promise<void>;
|
|
203
540
|
onMutate?: (variables: TVariables, context: TContext & MutationFunctionContext) => TOnMutateResult | Promise<TOnMutateResult>;
|
|
204
|
-
onSettled?: (data: TData | undefined, error:
|
|
541
|
+
onSettled?: (data: TData$1 | undefined, error: TError$1 | null, variables: TVariables, context: TContext & MutationFunctionContext & {
|
|
205
542
|
onMutateResult: TOnMutateResult | undefined;
|
|
206
543
|
}) => void | Promise<void>;
|
|
207
544
|
/**
|
|
@@ -212,11 +549,11 @@ interface MutationParams<Config extends AnyEndpointConfig, TData = unknown, TVar
|
|
|
212
549
|
keySuffix?: UseKey extends true ? UrlHasParams<Config['url']> extends true ? string[] : never : never;
|
|
213
550
|
}
|
|
214
551
|
/** @deprecated Use MutationArgs instead */
|
|
215
|
-
type ClientMutationArgs<Url extends string = string, RequestSchema =
|
|
552
|
+
type ClientMutationArgs<Url extends string = string, RequestSchema extends ZodType | undefined = undefined, QuerySchema extends ZodObject | undefined = undefined> = MutationArgs<Url, RequestSchema, QuerySchema>;
|
|
216
553
|
/** @deprecated Use MutationParams instead */
|
|
217
|
-
type BaseMutationParams<Config extends AnyEndpointConfig, TData = unknown, TVariables =
|
|
218
|
-
/** @deprecated Use
|
|
219
|
-
type BaseMutationArgs<Config extends AnyEndpointConfig> =
|
|
554
|
+
type BaseMutationParams<Config extends AnyEndpointConfig, TData$1 = unknown, TVariables = RequestArgs<Config['url'], Config['querySchema'], Config['requestSchema'], Config['urlParamsSchema']>, TResponse = z.output<Config['responseSchema']>, TContext = unknown, UseKey extends boolean = false> = MutationParams<Config, TData$1, TVariables, TResponse, TContext, UseKey>;
|
|
555
|
+
/** @deprecated Use RequestArgs from @navios/builder instead */
|
|
556
|
+
type BaseMutationArgs<Config extends AnyEndpointConfig> = RequestArgs<Config['url'], Config['querySchema'], Config['requestSchema'], Config['urlParamsSchema']>;
|
|
220
557
|
//#endregion
|
|
221
558
|
//#region src/mutation/key-creator.d.mts
|
|
222
559
|
/**
|
|
@@ -253,6 +590,36 @@ declare function createMutationKey<Config extends AnyEndpointConfig, Options ext
|
|
|
253
590
|
declare const mutationKeyCreator: typeof createMutationKey;
|
|
254
591
|
//#endregion
|
|
255
592
|
//#region src/mutation/make-hook.d.mts
|
|
593
|
+
/**
|
|
594
|
+
* Helper type for endpoint with config property
|
|
595
|
+
*/
|
|
596
|
+
type EndpointWithConfig<Config extends AnyEndpointConfig> = ((params: any) => Promise<any>) & {
|
|
597
|
+
config: Config;
|
|
598
|
+
};
|
|
599
|
+
/**
|
|
600
|
+
* Helper type for response input when errorSchema is present
|
|
601
|
+
*/
|
|
602
|
+
type ResponseInput<ResponseSchema extends ZodType, ErrorSchema extends ErrorSchemaRecord | undefined> = ErrorSchema extends ErrorSchemaRecord ? z.output<ResponseSchema> | InferErrorSchemaOutput<ErrorSchema> : z.output<ResponseSchema>;
|
|
603
|
+
/**
|
|
604
|
+
* Options type for makeMutation
|
|
605
|
+
*/
|
|
606
|
+
type MakeMutationParams<Config extends AnyEndpointConfig, ResponseSchema extends ZodType, ErrorSchema extends ErrorSchemaRecord | undefined, TData$1, TVariables, TOnMutateResult, TContext, UseKey extends boolean> = Omit<UseMutationOptions<TData$1, Error, TVariables>, 'mutationKey' | 'mutationFn' | 'onMutate' | 'onSuccess' | 'onError' | 'onSettled' | 'scope'> & {
|
|
607
|
+
processResponse?: ProcessResponseFunction<TData$1, ResponseInput<ResponseSchema, ErrorSchema>>;
|
|
608
|
+
useContext?: () => TContext;
|
|
609
|
+
onSuccess?: (data: TData$1, variables: TVariables, context: TContext & MutationFunctionContext & {
|
|
610
|
+
onMutateResult: TOnMutateResult | undefined;
|
|
611
|
+
}) => void | Promise<void>;
|
|
612
|
+
onError?: (err: unknown, variables: TVariables, context: TContext & MutationFunctionContext & {
|
|
613
|
+
onMutateResult: TOnMutateResult | undefined;
|
|
614
|
+
}) => void | Promise<void>;
|
|
615
|
+
onMutate?: (variables: TVariables, context: TContext & MutationFunctionContext) => TOnMutateResult | Promise<TOnMutateResult>;
|
|
616
|
+
onSettled?: (data: TData$1 | undefined, error: Error | null, variables: TVariables, context: TContext & MutationFunctionContext & {
|
|
617
|
+
onMutateResult: TOnMutateResult | undefined;
|
|
618
|
+
}) => void | Promise<void>;
|
|
619
|
+
useKey?: UseKey;
|
|
620
|
+
keyPrefix?: UseKey extends true ? UrlHasParams<Config['url']> extends true ? string[] : never : never;
|
|
621
|
+
keySuffix?: UseKey extends true ? UrlHasParams<Config['url']> extends true ? string[] : never : never;
|
|
622
|
+
};
|
|
256
623
|
/**
|
|
257
624
|
* Creates a mutation hook for a given endpoint.
|
|
258
625
|
*
|
|
@@ -263,645 +630,693 @@ declare const mutationKeyCreator: typeof createMutationKey;
|
|
|
263
630
|
* @param options - Mutation configuration including processResponse and callbacks
|
|
264
631
|
* @returns A hook function that returns mutation result with attached helpers
|
|
265
632
|
*/
|
|
266
|
-
declare function makeMutation<
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
urlParams: UrlParams<Config["url"]>;
|
|
273
|
-
} : {} : never : never) => ProcessResponseFunction<TData, TResponse> | ((data: z.core.output<Config["responseSchema"]>) => z.core.output<Config["responseSchema"]>) extends ((...args: unknown[]) => infer Result) ? [Config["url"]] & {
|
|
274
|
-
[dataTagSymbol]: Result;
|
|
275
|
-
[dataTagErrorSymbol]: Error;
|
|
276
|
-
} : never;
|
|
277
|
-
};
|
|
633
|
+
declare function makeMutation<Method extends HttpMethod, Url extends string, QuerySchema extends ZodObject | undefined, ResponseSchema extends ZodType, RequestSchema extends ZodType, ErrorSchema extends ErrorSchemaRecord, TData$1, TOnMutateResult = unknown, TContext = unknown, UseKey extends boolean = false>(endpoint: EndpointWithConfig<BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema, ErrorSchema>>, options: MakeMutationParams<BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema, ErrorSchema>, ResponseSchema, ErrorSchema, TData$1, any, TOnMutateResult, TContext, UseKey>): ((keyParams: UseKey extends true ? UrlHasParams<Url> extends true ? {
|
|
634
|
+
urlParams: UrlParams<Url>;
|
|
635
|
+
} : never : never) => UseMutationResult<TData$1, Error, any, TOnMutateResult>) & MutationHelpers<Url, TData$1>;
|
|
636
|
+
declare function makeMutation<Method extends HttpMethod, Url extends string, QuerySchema extends ZodObject | undefined, ResponseSchema extends ZodType, RequestSchema extends ZodType | undefined, TData$1, TOnMutateResult = unknown, TContext = unknown, UseKey extends boolean = false>(endpoint: EndpointWithConfig<BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema, undefined>>, options: MakeMutationParams<BaseEndpointConfig<Method, Url, QuerySchema, ResponseSchema, RequestSchema, undefined>, ResponseSchema, undefined, TData$1, any, TOnMutateResult, TContext, UseKey>): ((keyParams: UseKey extends true ? UrlHasParams<Url> extends true ? {
|
|
637
|
+
urlParams: UrlParams<Url>;
|
|
638
|
+
} : never : never) => UseMutationResult<TData$1, Error, any, TOnMutateResult>) & MutationHelpers<Url, TData$1>;
|
|
278
639
|
//#endregion
|
|
279
|
-
//#region src/
|
|
640
|
+
//#region src/mutation/optimistic.d.mts
|
|
641
|
+
/**
|
|
642
|
+
* Configuration for creating optimistic update callbacks.
|
|
643
|
+
*
|
|
644
|
+
* @template TData - The mutation response data type
|
|
645
|
+
* @template TVariables - The mutation variables type
|
|
646
|
+
* @template TQueryData - The query cache data type
|
|
647
|
+
*/
|
|
648
|
+
interface OptimisticUpdateConfig<_TData, TVariables, TQueryData> {
|
|
649
|
+
/**
|
|
650
|
+
* The query key to optimistically update.
|
|
651
|
+
* This should match the query key used for the affected query.
|
|
652
|
+
*/
|
|
653
|
+
queryKey: readonly unknown[];
|
|
654
|
+
/**
|
|
655
|
+
* Function to compute the optimistic cache value.
|
|
656
|
+
* Receives the current cache data and mutation variables.
|
|
657
|
+
*
|
|
658
|
+
* @param oldData - Current data in the cache (may be undefined if not cached)
|
|
659
|
+
* @param variables - The mutation variables being submitted
|
|
660
|
+
* @returns The new optimistic cache value
|
|
661
|
+
*/
|
|
662
|
+
updateFn: (oldData: TQueryData | undefined, variables: TVariables) => TQueryData;
|
|
663
|
+
/**
|
|
664
|
+
* Whether to rollback on error.
|
|
665
|
+
* Defaults to true.
|
|
666
|
+
*/
|
|
667
|
+
rollbackOnError?: boolean;
|
|
668
|
+
/**
|
|
669
|
+
* Whether to invalidate the query on settlement.
|
|
670
|
+
* Defaults to true.
|
|
671
|
+
*/
|
|
672
|
+
invalidateOnSettled?: boolean;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Return type for optimistic update callbacks.
|
|
676
|
+
*/
|
|
677
|
+
interface OptimisticUpdateCallbacks<TData$1, TVariables, TQueryData> {
|
|
678
|
+
/**
|
|
679
|
+
* Called before the mutation starts. Cancels outgoing refetches,
|
|
680
|
+
* snapshots the current cache value, and applies the optimistic update.
|
|
681
|
+
*/
|
|
682
|
+
onMutate: (variables: TVariables, context: {
|
|
683
|
+
queryClient: QueryClient;
|
|
684
|
+
}) => Promise<{
|
|
685
|
+
previousData: TQueryData | undefined;
|
|
686
|
+
}>;
|
|
687
|
+
/**
|
|
688
|
+
* Called when the mutation fails. Rolls back the cache to the previous
|
|
689
|
+
* value if rollbackOnError is enabled.
|
|
690
|
+
*/
|
|
691
|
+
onError: (err: Error, variables: TVariables, context: {
|
|
692
|
+
previousData?: TQueryData;
|
|
693
|
+
queryClient: QueryClient;
|
|
694
|
+
}) => void;
|
|
695
|
+
/**
|
|
696
|
+
* Called when the mutation completes (success or error).
|
|
697
|
+
* Invalidates the query if invalidateOnSettled is enabled.
|
|
698
|
+
*/
|
|
699
|
+
onSettled: (data: TData$1 | undefined, error: Error | null, variables: TVariables, context: {
|
|
700
|
+
queryClient: QueryClient;
|
|
701
|
+
}) => void;
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Creates type-safe optimistic update callbacks for mutations.
|
|
705
|
+
*
|
|
706
|
+
* This helper generates the onMutate, onError, and onSettled callbacks
|
|
707
|
+
* that implement the standard optimistic update pattern:
|
|
708
|
+
*
|
|
709
|
+
* 1. onMutate: Cancel refetches, snapshot cache, apply optimistic update
|
|
710
|
+
* 2. onError: Rollback cache to previous value on failure
|
|
711
|
+
* 3. onSettled: Invalidate query to refetch fresh data
|
|
712
|
+
*
|
|
713
|
+
* @experimental This API is experimental and may change in future versions.
|
|
714
|
+
* Use with caution in production code.
|
|
715
|
+
*
|
|
716
|
+
* @param config - Configuration for the optimistic update
|
|
717
|
+
* @returns Object containing onMutate, onError, and onSettled callbacks
|
|
718
|
+
*
|
|
719
|
+
* @example
|
|
720
|
+
* ```ts
|
|
721
|
+
* // Create a mutation with optimistic updates
|
|
722
|
+
* const updateUser = client.mutation({
|
|
723
|
+
* method: 'PATCH',
|
|
724
|
+
* url: '/users/$userId',
|
|
725
|
+
* requestSchema: updateUserSchema,
|
|
726
|
+
* responseSchema: userSchema,
|
|
727
|
+
* processResponse: (data) => data,
|
|
728
|
+
* ...createOptimisticUpdate({
|
|
729
|
+
* queryKey: ['users', userId],
|
|
730
|
+
* updateFn: (oldData, variables) => ({
|
|
731
|
+
* ...oldData,
|
|
732
|
+
* ...variables.data,
|
|
733
|
+
* }),
|
|
734
|
+
* }),
|
|
735
|
+
* })
|
|
736
|
+
* ```
|
|
737
|
+
*
|
|
738
|
+
* @example
|
|
739
|
+
* ```ts
|
|
740
|
+
* // Optimistic update for adding an item to a list
|
|
741
|
+
* const addTodo = client.mutation({
|
|
742
|
+
* method: 'POST',
|
|
743
|
+
* url: '/todos',
|
|
744
|
+
* requestSchema: createTodoSchema,
|
|
745
|
+
* responseSchema: todoSchema,
|
|
746
|
+
* processResponse: (data) => data,
|
|
747
|
+
* ...createOptimisticUpdate({
|
|
748
|
+
* queryKey: ['todos'],
|
|
749
|
+
* updateFn: (oldData, variables) => [
|
|
750
|
+
* ...(oldData ?? []),
|
|
751
|
+
* { id: 'temp-id', ...variables.data, createdAt: new Date() },
|
|
752
|
+
* ],
|
|
753
|
+
* }),
|
|
754
|
+
* })
|
|
755
|
+
* ```
|
|
756
|
+
*
|
|
757
|
+
* @example
|
|
758
|
+
* ```ts
|
|
759
|
+
* // Optimistic delete
|
|
760
|
+
* const deleteTodo = client.mutation({
|
|
761
|
+
* method: 'DELETE',
|
|
762
|
+
* url: '/todos/$todoId',
|
|
763
|
+
* responseSchema: z.object({ success: z.boolean() }),
|
|
764
|
+
* processResponse: (data) => data,
|
|
765
|
+
* ...createOptimisticUpdate({
|
|
766
|
+
* queryKey: ['todos'],
|
|
767
|
+
* updateFn: (oldData, variables) =>
|
|
768
|
+
* (oldData ?? []).filter((t) => t.id !== variables.urlParams.todoId),
|
|
769
|
+
* }),
|
|
770
|
+
* })
|
|
771
|
+
* ```
|
|
772
|
+
*/
|
|
773
|
+
declare function createOptimisticUpdate<TData$1, TVariables, TQueryData>(config: OptimisticUpdateConfig<TData$1, TVariables, TQueryData>): OptimisticUpdateCallbacks<TData$1, TVariables, TQueryData>;
|
|
774
|
+
/**
|
|
775
|
+
* Creates optimistic update callbacks that work with multiple query keys.
|
|
776
|
+
*
|
|
777
|
+
* Useful when a mutation affects multiple cached queries.
|
|
778
|
+
*
|
|
779
|
+
* @experimental This API is experimental and may change in future versions.
|
|
780
|
+
* Use with caution in production code.
|
|
781
|
+
*
|
|
782
|
+
* @param configs - Array of optimistic update configurations
|
|
783
|
+
* @returns Combined callbacks that handle all specified queries
|
|
784
|
+
*
|
|
785
|
+
* @example
|
|
786
|
+
* ```ts
|
|
787
|
+
* // Updating a user affects both user detail and user list queries
|
|
788
|
+
* const updateUser = client.mutation({
|
|
789
|
+
* method: 'PATCH',
|
|
790
|
+
* url: '/users/$userId',
|
|
791
|
+
* requestSchema: updateUserSchema,
|
|
792
|
+
* responseSchema: userSchema,
|
|
793
|
+
* processResponse: (data) => data,
|
|
794
|
+
* ...createMultiOptimisticUpdate([
|
|
795
|
+
* {
|
|
796
|
+
* queryKey: ['users', userId],
|
|
797
|
+
* updateFn: (oldData, variables) => ({ ...oldData, ...variables.data }),
|
|
798
|
+
* },
|
|
799
|
+
* {
|
|
800
|
+
* queryKey: ['users'],
|
|
801
|
+
* updateFn: (oldList, variables) =>
|
|
802
|
+
* (oldList ?? []).map((u) =>
|
|
803
|
+
* u.id === userId ? { ...u, ...variables.data } : u
|
|
804
|
+
* ),
|
|
805
|
+
* },
|
|
806
|
+
* ]),
|
|
807
|
+
* })
|
|
808
|
+
* ```
|
|
809
|
+
*/
|
|
810
|
+
declare function createMultiOptimisticUpdate<TData$1, TVariables>(configs: Array<OptimisticUpdateConfig<TData$1, TVariables, unknown>>): OptimisticUpdateCallbacks<TData$1, TVariables, Map<string, unknown>>;
|
|
811
|
+
//#endregion
|
|
812
|
+
//#region src/client/types/helpers.d.mts
|
|
813
|
+
/**
|
|
814
|
+
* Compute the base result type based on discriminator and error schema.
|
|
815
|
+
* When UseDiscriminator=true and errorSchema is present, errors are included as a union.
|
|
816
|
+
* When UseDiscriminator=false, only the success type is returned (errors are thrown).
|
|
817
|
+
*/
|
|
818
|
+
type ComputeBaseResult<UseDiscriminator extends boolean, ResponseSchema extends ZodType, ErrorSchema extends ErrorSchemaRecord | undefined> = UseDiscriminator extends true ? ErrorSchema extends ErrorSchemaRecord ? z.output<ResponseSchema> | InferErrorSchemaOutput<ErrorSchema> : z.output<ResponseSchema> : z.output<ResponseSchema>;
|
|
819
|
+
/**
|
|
820
|
+
* Helper type to compute the response data type based on errorSchema presence and UseDiscriminator.
|
|
821
|
+
*
|
|
822
|
+
* When `UseDiscriminator` is `true` and `errorSchema` exists, returns `ResponseType | ErrorTypes`.
|
|
823
|
+
* When `UseDiscriminator` is `false`, returns only `ResponseType` (errors are thrown).
|
|
824
|
+
*
|
|
825
|
+
* @deprecated Use ComputeBaseResult instead (same logic, different parameter order)
|
|
826
|
+
*/
|
|
827
|
+
type ResponseDataType<Response extends ZodType, ErrorSchema extends ErrorSchemaRecord | undefined, UseDiscriminator extends boolean = false> = ComputeBaseResult<UseDiscriminator, Response, ErrorSchema>;
|
|
280
828
|
/**
|
|
281
829
|
* Helper type that attaches the endpoint to query/mutation results.
|
|
830
|
+
* Supports both new const generic pattern and legacy pattern with individual parameters.
|
|
831
|
+
*
|
|
832
|
+
* New pattern (2 args):
|
|
833
|
+
* @template Options - EndpointOptions from builder (new const generic pattern)
|
|
834
|
+
* @template UseDiscriminator - When true, errors are returned as union types
|
|
835
|
+
*
|
|
836
|
+
* Legacy pattern (4-5 args):
|
|
837
|
+
* @template Method - HTTP method
|
|
838
|
+
* @template Url - URL template
|
|
839
|
+
* @template RequestSchema - Request body schema
|
|
840
|
+
* @template ResponseSchema - Response schema
|
|
841
|
+
* @template QuerySchema - Query params schema (optional)
|
|
282
842
|
*/
|
|
283
|
-
type EndpointHelper<
|
|
284
|
-
endpoint:
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
843
|
+
type EndpointHelper<OptionsOrMethod extends EndpointOptions | HttpMethod = EndpointOptions, UseDiscriminatorOrUrl extends boolean | string = false, RequestSchema = undefined, ResponseSchema extends ZodType = ZodType, QuerySchema = undefined> = OptionsOrMethod extends EndpointOptions ? UseDiscriminatorOrUrl extends boolean ? {
|
|
844
|
+
endpoint: EndpointHandler<OptionsOrMethod, UseDiscriminatorOrUrl>;
|
|
845
|
+
} : never : OptionsOrMethod extends HttpMethod ? UseDiscriminatorOrUrl extends string ? {
|
|
846
|
+
endpoint: EndpointHandler<EndpointOptions & {
|
|
847
|
+
method: OptionsOrMethod;
|
|
848
|
+
url: UseDiscriminatorOrUrl;
|
|
849
|
+
requestSchema: RequestSchema;
|
|
850
|
+
responseSchema: ResponseSchema;
|
|
851
|
+
querySchema: QuerySchema;
|
|
852
|
+
}, false>;
|
|
853
|
+
} : never : never;
|
|
288
854
|
/** @deprecated Use EndpointHelper instead */
|
|
289
855
|
type ClientEndpointHelper<Method extends HttpMethod = HttpMethod, Url extends string = string, RequestSchema = unknown, ResponseSchema extends z.ZodType = z.ZodType, QuerySchema = unknown> = EndpointHelper<Method, Url, RequestSchema, ResponseSchema, QuerySchema>;
|
|
290
856
|
/**
|
|
291
857
|
* Helper type that attaches a stream endpoint to mutation results.
|
|
858
|
+
* Supports both new const generic pattern and legacy pattern with individual parameters.
|
|
859
|
+
*
|
|
860
|
+
* New pattern (2 args):
|
|
861
|
+
* @template Options - BaseEndpointOptions from builder (new const generic pattern)
|
|
862
|
+
* @template UseDiscriminator - When true, errors are returned as union types
|
|
863
|
+
*
|
|
864
|
+
* Legacy pattern (4-6 args):
|
|
865
|
+
* @template Method - HTTP method
|
|
866
|
+
* @template Url - URL template
|
|
867
|
+
* @template QuerySchema - Query params schema
|
|
868
|
+
* @template RequestSchema - Request body schema
|
|
869
|
+
* @template ErrorSchema - Error schema (optional)
|
|
870
|
+
* @template UrlParamsSchema - URL params schema (optional)
|
|
292
871
|
*/
|
|
293
|
-
type StreamHelper<
|
|
294
|
-
endpoint:
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
872
|
+
type StreamHelper<OptionsOrMethod extends BaseEndpointOptions | HttpMethod = BaseEndpointOptions, UseDiscriminatorOrUrl extends boolean | string = false, QuerySchema = undefined, RequestSchema = undefined, ErrorSchema = undefined, UrlParamsSchema = undefined> = OptionsOrMethod extends BaseEndpointOptions ? UseDiscriminatorOrUrl extends boolean ? {
|
|
873
|
+
endpoint: StreamHandler<OptionsOrMethod, UseDiscriminatorOrUrl>;
|
|
874
|
+
} : never : OptionsOrMethod extends HttpMethod ? UseDiscriminatorOrUrl extends string ? {
|
|
875
|
+
endpoint: StreamHandler<BaseEndpointOptions & {
|
|
876
|
+
method: OptionsOrMethod;
|
|
877
|
+
url: UseDiscriminatorOrUrl;
|
|
878
|
+
querySchema: QuerySchema;
|
|
879
|
+
requestSchema: RequestSchema;
|
|
880
|
+
errorSchema: ErrorSchema;
|
|
881
|
+
urlParamsSchema: UrlParamsSchema;
|
|
882
|
+
}, false>;
|
|
883
|
+
} : never : never;
|
|
884
|
+
//#endregion
|
|
885
|
+
//#region src/client/types/query.d.mts
|
|
298
886
|
/**
|
|
299
|
-
*
|
|
300
|
-
*
|
|
887
|
+
* Helper type to build endpoint options without including undefined properties.
|
|
888
|
+
* This ensures HasProperty correctly identifies missing properties.
|
|
301
889
|
*/
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
890
|
+
type BuildEndpointOptions<Method extends HttpMethod, Url extends string, QuerySchema extends ZodObject | undefined, RequestSchema extends ZodType | undefined, ResponseSchema extends ZodType, ErrorSchema extends ErrorSchemaRecord | undefined, UrlParamsSchema extends ZodObject | undefined> = {
|
|
891
|
+
method: Method;
|
|
892
|
+
url: Url;
|
|
893
|
+
responseSchema: ResponseSchema;
|
|
894
|
+
} & (QuerySchema extends undefined ? {} : {
|
|
895
|
+
querySchema: QuerySchema;
|
|
896
|
+
}) & (RequestSchema extends undefined ? {} : {
|
|
897
|
+
requestSchema: RequestSchema;
|
|
898
|
+
}) & (ErrorSchema extends undefined ? {} : {
|
|
899
|
+
errorSchema: ErrorSchema;
|
|
900
|
+
}) & (UrlParamsSchema extends undefined ? {} : {
|
|
901
|
+
urlParamsSchema: UrlParamsSchema;
|
|
902
|
+
});
|
|
903
|
+
/**
|
|
904
|
+
* Extended endpoint options interface for query that includes processResponse.
|
|
905
|
+
*/
|
|
906
|
+
interface QueryEndpointConfig<Method extends HttpMethod, Url extends string, QuerySchema extends ZodObject | undefined, RequestSchema extends ZodType | undefined, ResponseSchema extends ZodType, ErrorSchema extends ErrorSchemaRecord | undefined, UrlParamsSchema extends ZodObject | undefined, TBaseResult, Result$1> extends EndpointOptions {
|
|
907
|
+
method: Method;
|
|
908
|
+
url: Url;
|
|
909
|
+
querySchema?: QuerySchema;
|
|
910
|
+
requestSchema?: RequestSchema;
|
|
911
|
+
responseSchema: ResponseSchema;
|
|
912
|
+
errorSchema?: ErrorSchema;
|
|
913
|
+
urlParamsSchema?: UrlParamsSchema;
|
|
914
|
+
processResponse?: (data: TBaseResult) => Result$1;
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* Query method using decomposed generics pattern for proper processResponse typing.
|
|
918
|
+
*
|
|
919
|
+
* @template UseDiscriminator - When `true`, errors are returned as union types.
|
|
920
|
+
* When `false` (default), errors are thrown and not included in TData.
|
|
921
|
+
*/
|
|
922
|
+
interface ClientQueryMethods<UseDiscriminator extends boolean = false> {
|
|
923
|
+
/**
|
|
924
|
+
* Creates a type-safe query with automatic type inference.
|
|
925
|
+
*
|
|
926
|
+
* Uses decomposed generic pattern to infer types from the configuration object.
|
|
927
|
+
* All schema combinations are handled by a single method.
|
|
928
|
+
*
|
|
929
|
+
* @example
|
|
930
|
+
* ```ts
|
|
931
|
+
* const getUser = client.query({
|
|
932
|
+
* method: 'GET',
|
|
933
|
+
* url: '/users/$userId',
|
|
934
|
+
* responseSchema: userSchema,
|
|
935
|
+
* urlParamsSchema: z.object({ userId: z.string().uuid() }),
|
|
936
|
+
* })
|
|
937
|
+
*
|
|
938
|
+
* const { data } = getUser.useSuspense({ urlParams: { userId: '123' } })
|
|
939
|
+
* ```
|
|
940
|
+
*/
|
|
941
|
+
query<const Method extends HttpMethod = HttpMethod, const Url extends string = string, const QuerySchema extends ZodObject | undefined = undefined, const RequestSchema extends ZodType | undefined = undefined, const ResponseSchema extends ZodType = ZodType, const ErrorSchema extends ErrorSchemaRecord | undefined = undefined, const UrlParamsSchema extends ZodObject | undefined = undefined, const TBaseResult = ComputeBaseResult<UseDiscriminator, ResponseSchema, ErrorSchema>, const Result$1 = TBaseResult, const Options extends EndpointOptions = BuildEndpointOptions<Method, Url, QuerySchema, RequestSchema, ResponseSchema, ErrorSchema, UrlParamsSchema>>(config: QueryEndpointConfig<Method, Url, QuerySchema, RequestSchema, ResponseSchema, ErrorSchema, UrlParamsSchema, TBaseResult, Result$1>): ((params: Simplify<InferEndpointParams<Options>>) => UseSuspenseQueryOptions<Result$1, Error, Result$1, DataTag<Split<Url, '/'>, Result$1, Error>>) & QueryHelpers<Url, QuerySchema, Result$1, false, RequestSchema> & EndpointHelper<Options, UseDiscriminator>;
|
|
942
|
+
}
|
|
943
|
+
//#endregion
|
|
944
|
+
//#region src/client/types/infinite-query.d.mts
|
|
945
|
+
/**
|
|
946
|
+
* Extended endpoint options interface for infinite query that includes processResponse and pagination.
|
|
947
|
+
*/
|
|
948
|
+
interface InfiniteQueryEndpointConfig<_UseDiscriminator extends boolean, Method extends HttpMethod, Url extends string, QuerySchema extends ZodObject, RequestSchema extends ZodType | undefined, ResponseSchema extends ZodType, ErrorSchema extends ErrorSchemaRecord | undefined, UrlParamsSchema extends ZodObject | undefined, TBaseResult, PageResult> extends EndpointOptions {
|
|
949
|
+
method: Method;
|
|
950
|
+
url: Url;
|
|
951
|
+
querySchema: QuerySchema;
|
|
952
|
+
requestSchema?: RequestSchema;
|
|
953
|
+
responseSchema: ResponseSchema;
|
|
954
|
+
errorSchema?: ErrorSchema;
|
|
955
|
+
urlParamsSchema?: UrlParamsSchema;
|
|
956
|
+
processResponse?: (data: TBaseResult) => PageResult;
|
|
957
|
+
getNextPageParam: (lastPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<QuerySchema> | undefined, allPageParams: z.infer<QuerySchema>[] | undefined) => z.input<QuerySchema> | undefined;
|
|
958
|
+
getPreviousPageParam?: (firstPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<QuerySchema> | undefined, allPageParams: z.infer<QuerySchema>[] | undefined) => z.input<QuerySchema>;
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
* Infinite query method using decomposed generics pattern for proper processResponse typing.
|
|
962
|
+
*
|
|
963
|
+
* @template UseDiscriminator - When `true`, errors are returned as union types.
|
|
964
|
+
* When `false` (default), errors are thrown and not included in TData.
|
|
965
|
+
*/
|
|
966
|
+
interface ClientInfiniteQueryMethods<UseDiscriminator extends boolean = false> {
|
|
967
|
+
/**
|
|
968
|
+
* Creates a type-safe infinite query with automatic type inference.
|
|
969
|
+
*
|
|
970
|
+
* Uses decomposed generic pattern to infer types from the configuration object.
|
|
971
|
+
* All schema combinations are handled by a single method.
|
|
972
|
+
*
|
|
973
|
+
* @example
|
|
974
|
+
* ```ts
|
|
975
|
+
* const getUsers = client.infiniteQuery({
|
|
976
|
+
* method: 'GET',
|
|
977
|
+
* url: '/users',
|
|
978
|
+
* querySchema: z.object({ page: z.number() }),
|
|
979
|
+
* responseSchema: z.array(userSchema),
|
|
980
|
+
* getNextPageParam: (lastPage, allPages, lastPageParam) => {
|
|
981
|
+
* return lastPage.length > 0 ? { page: (lastPageParam?.page ?? 0) + 1 } : undefined
|
|
982
|
+
* },
|
|
983
|
+
* })
|
|
984
|
+
*
|
|
985
|
+
* const { data } = getUsers.useSuspense({ params: { page: 0 } })
|
|
986
|
+
* ```
|
|
987
|
+
*/
|
|
988
|
+
infiniteQuery<const Method extends HttpMethod = HttpMethod, const Url extends string = string, const QuerySchema extends ZodObject = ZodObject, const RequestSchema extends ZodType | undefined = undefined, const ResponseSchema extends ZodType = ZodType, const ErrorSchema extends ErrorSchemaRecord | undefined = undefined, const UrlParamsSchema extends ZodObject | undefined = undefined, const TBaseResult = ComputeBaseResult<UseDiscriminator, ResponseSchema, ErrorSchema>, const PageResult = TBaseResult, const Options extends EndpointOptions = {
|
|
310
989
|
method: Method;
|
|
311
990
|
url: Url;
|
|
312
991
|
querySchema: QuerySchema;
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
992
|
+
requestSchema: RequestSchema;
|
|
993
|
+
responseSchema: ResponseSchema;
|
|
994
|
+
errorSchema: ErrorSchema;
|
|
995
|
+
urlParamsSchema: UrlParamsSchema;
|
|
996
|
+
}>(config: InfiniteQueryEndpointConfig<UseDiscriminator, Method, Url, QuerySchema, RequestSchema, ResponseSchema, ErrorSchema, UrlParamsSchema, TBaseResult, PageResult>): ((params: Simplify<InferEndpointParams<Options>>) => UseSuspenseInfiniteQueryOptions<PageResult, Error, InfiniteData<PageResult>, DataTag<Split<Url, '/'>, PageResult, Error>, z.output<QuerySchema>>) & QueryHelpers<Url, QuerySchema, PageResult, true, RequestSchema> & EndpointHelper<Options, UseDiscriminator>;
|
|
997
|
+
}
|
|
998
|
+
//#endregion
|
|
999
|
+
//#region src/client/types/mutation.d.mts
|
|
1000
|
+
/**
|
|
1001
|
+
* Compute variables type from URL, schemas
|
|
1002
|
+
*/
|
|
1003
|
+
type ComputeVariables<Url extends string, QuerySchema extends ZodObject | undefined, RequestSchema extends ZodType | undefined, UrlParamsSchema extends ZodObject | undefined> = Simplify<RequestArgs<Url, QuerySchema, RequestSchema, UrlParamsSchema>>;
|
|
1004
|
+
/**
|
|
1005
|
+
* Extended endpoint options interface for mutation that includes processResponse and callbacks.
|
|
1006
|
+
*/
|
|
1007
|
+
interface MutationEndpointConfig<_UseDiscriminator extends boolean, Method extends HttpMethod, Url extends string, QuerySchema extends ZodObject | undefined, RequestSchema extends ZodType | undefined, ResponseSchema extends ZodType, ErrorSchema extends ErrorSchemaRecord | undefined, UrlParamsSchema extends ZodObject | undefined, UseKey extends boolean, TBaseResult, Result$1, OnMutateResult, Context, Variables> extends EndpointOptions {
|
|
1008
|
+
method: Method;
|
|
1009
|
+
url: Url;
|
|
1010
|
+
querySchema?: QuerySchema;
|
|
1011
|
+
requestSchema?: RequestSchema;
|
|
1012
|
+
responseSchema: ResponseSchema;
|
|
1013
|
+
errorSchema?: ErrorSchema;
|
|
1014
|
+
urlParamsSchema?: UrlParamsSchema;
|
|
1015
|
+
processResponse?: (data: TBaseResult) => Result$1 | Promise<Result$1>;
|
|
1016
|
+
useContext?: () => Context;
|
|
1017
|
+
useKey?: UseKey;
|
|
1018
|
+
onMutate?: (variables: Variables, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
1019
|
+
onSuccess?: (data: NoInfer<Result$1>, variables: Variables, context: Context & MutationFunctionContext & {
|
|
1020
|
+
onMutateResult: OnMutateResult | undefined;
|
|
1021
|
+
}) => void | Promise<void>;
|
|
1022
|
+
onError?: (error: Error, variables: Variables, context: Context & MutationFunctionContext & {
|
|
1023
|
+
onMutateResult: OnMutateResult | undefined;
|
|
1024
|
+
}) => void | Promise<void>;
|
|
1025
|
+
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Variables, context: Context & MutationFunctionContext & {
|
|
1026
|
+
onMutateResult: OnMutateResult | undefined;
|
|
1027
|
+
}) => void | Promise<void>;
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* Mutation method using decomposed generics pattern for proper processResponse typing.
|
|
1031
|
+
*
|
|
1032
|
+
* @template UseDiscriminator - When `true`, errors are returned as union types.
|
|
1033
|
+
* When `false` (default), errors are thrown and not included in TData.
|
|
1034
|
+
*/
|
|
1035
|
+
interface ClientMutationMethods<UseDiscriminator extends boolean = false> {
|
|
1036
|
+
/**
|
|
1037
|
+
* Creates a type-safe mutation with automatic type inference.
|
|
1038
|
+
*
|
|
1039
|
+
* Uses decomposed generic pattern to infer types from the configuration object.
|
|
1040
|
+
* All schema combinations are handled by a single method.
|
|
1041
|
+
*
|
|
1042
|
+
* @example
|
|
1043
|
+
* ```ts
|
|
1044
|
+
* const createUser = client.mutation({
|
|
1045
|
+
* method: 'POST',
|
|
1046
|
+
* url: '/users',
|
|
1047
|
+
* requestSchema: createUserSchema,
|
|
1048
|
+
* responseSchema: userSchema,
|
|
1049
|
+
* processResponse: (data) => data,
|
|
1050
|
+
* })
|
|
1051
|
+
*
|
|
1052
|
+
* const { mutate } = createUser()
|
|
1053
|
+
* mutate({ data: { name: 'John' } })
|
|
1054
|
+
* ```
|
|
1055
|
+
*/
|
|
1056
|
+
mutation<const Method extends HttpMethod = HttpMethod, const Url extends string = string, const QuerySchema extends ZodObject | undefined = undefined, const RequestSchema extends ZodType | undefined = undefined, const ResponseSchema extends ZodType = ZodType, const ErrorSchema extends ErrorSchemaRecord | undefined = undefined, const UrlParamsSchema extends ZodObject | undefined = undefined, const UseKey extends boolean = false, const TBaseResult = ComputeBaseResult<UseDiscriminator, ResponseSchema, ErrorSchema>, const Result$1 = TBaseResult, const OnMutateResult = unknown, const Context = unknown, const Variables = ComputeVariables<Url, QuerySchema, RequestSchema, UrlParamsSchema>, const Options extends EndpointOptions = {
|
|
317
1057
|
method: Method;
|
|
318
1058
|
url: Url;
|
|
1059
|
+
querySchema: QuerySchema;
|
|
319
1060
|
requestSchema: RequestSchema;
|
|
320
|
-
responseSchema:
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
getNextPageParam: (lastPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<QuerySchema> | undefined, allPageParams: z.infer<QuerySchema>[] | undefined) => z.input<QuerySchema> | undefined;
|
|
338
|
-
getPreviousPageParam?: (firstPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<QuerySchema> | undefined, allPageParams: z.infer<QuerySchema>[] | undefined) => z.input<QuerySchema>;
|
|
339
|
-
}): ((params: Util_FlatObject<QueryArgs<Url, QuerySchema>>) => UseSuspenseInfiniteQueryOptions<PageResult, Error, Result$1, DataTag<Split<Url, '/'>, PageResult, Error>, z.output<QuerySchema>>) & QueryHelpers<Url, QuerySchema, PageResult, true> & EndpointHelper<Method, Url, undefined, Response, QuerySchema>;
|
|
340
|
-
infiniteQuery<Method extends 'POST' = 'POST', Url extends string = string, QuerySchema extends ZodObject = ZodObject, RequestSchema extends ZodType = ZodType, Response extends ZodType = ZodType, PageResult = z.output<Response>, Result$1 = InfiniteData<PageResult>>(config: {
|
|
341
|
-
method: Method;
|
|
342
|
-
url: Url;
|
|
343
|
-
querySchema: QuerySchema;
|
|
344
|
-
requestSchema: RequestSchema;
|
|
345
|
-
responseSchema: Response;
|
|
346
|
-
processResponse?: (data: z.output<Response>) => PageResult;
|
|
347
|
-
getNextPageParam: (lastPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<QuerySchema> | undefined, allPageParams: z.infer<QuerySchema>[] | undefined) => z.input<QuerySchema> | undefined;
|
|
348
|
-
getPreviousPageParam?: (firstPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<QuerySchema> | undefined, allPageParams: z.infer<QuerySchema>[] | undefined) => z.input<QuerySchema>;
|
|
349
|
-
}): ((params: Util_FlatObject<QueryArgs<Url, QuerySchema, RequestSchema>>) => UseSuspenseInfiniteQueryOptions<PageResult, Error, Result$1, DataTag<Split<Url, '/'>, PageResult, Error>, z.output<QuerySchema>>) & QueryHelpers<Url, QuerySchema, PageResult, true, RequestSchema> & EndpointHelper<Method, Url, RequestSchema, Response, QuerySchema>;
|
|
350
|
-
mutation<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, QuerySchema extends ZodObject = ZodObject, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result$1 = unknown, OnMutateResult = unknown, Context = unknown, UseKey extends true = true>(config: {
|
|
1061
|
+
responseSchema: ResponseSchema;
|
|
1062
|
+
errorSchema: ErrorSchema;
|
|
1063
|
+
urlParamsSchema: UrlParamsSchema;
|
|
1064
|
+
}>(config: MutationEndpointConfig<UseDiscriminator, Method, Url, QuerySchema, RequestSchema, ResponseSchema, ErrorSchema, UrlParamsSchema, UseKey, TBaseResult, Result$1, OnMutateResult, Context, Variables>): ((...args: UseKey extends true ? UrlHasParams<Url> extends true ? [{
|
|
1065
|
+
urlParams: UrlParams<Url>;
|
|
1066
|
+
}] : [{}] : []) => UseMutationResult<Result$1, Error, Variables, OnMutateResult>) & (UseKey extends true ? MutationHelpers<Url, Result$1> : {}) & EndpointHelper<Options, UseDiscriminator>;
|
|
1067
|
+
}
|
|
1068
|
+
//#endregion
|
|
1069
|
+
//#region src/client/types/multipart-mutation.d.mts
|
|
1070
|
+
/**
|
|
1071
|
+
* Multipart mutation method overloads for ClientInstance.
|
|
1072
|
+
*
|
|
1073
|
+
* @template UseDiscriminator - When `true`, errors are returned as union types.
|
|
1074
|
+
* When `false` (default), errors are thrown and not included in TData.
|
|
1075
|
+
*/
|
|
1076
|
+
interface ClientMultipartMutationMethods<UseDiscriminator extends boolean = false> {
|
|
1077
|
+
multipartMutation<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, QuerySchema extends ZodObject = ZodObject, Response extends ZodType = ZodType, ErrorSchema extends ErrorSchemaRecord | undefined = undefined, TBaseResult = ComputeBaseResult<UseDiscriminator, Response, ErrorSchema>, Result$1 = unknown, OnMutateResult = unknown, Context = unknown, UseKey extends true = true>(config: {
|
|
351
1078
|
method: Method;
|
|
352
1079
|
url: Url;
|
|
353
1080
|
useKey: UseKey;
|
|
354
1081
|
requestSchema: RequestSchema;
|
|
355
1082
|
querySchema: QuerySchema;
|
|
356
1083
|
responseSchema: Response;
|
|
357
|
-
|
|
1084
|
+
errorSchema?: ErrorSchema;
|
|
1085
|
+
processResponse: (data: TBaseResult) => Result$1 | Promise<Result$1>;
|
|
358
1086
|
useContext?: () => Context;
|
|
359
|
-
onMutate?: (variables:
|
|
360
|
-
onSuccess?: (data: NoInfer<Result$1>, variables:
|
|
1087
|
+
onMutate?: (variables: Simplify<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
1088
|
+
onSuccess?: (data: NoInfer<Result$1>, variables: Simplify<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
361
1089
|
onMutateResult: OnMutateResult | undefined;
|
|
362
1090
|
}) => void | Promise<void>;
|
|
363
|
-
onError?: (error: Error, variables:
|
|
1091
|
+
onError?: (error: Error, variables: Simplify<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
364
1092
|
onMutateResult: OnMutateResult | undefined;
|
|
365
1093
|
}) => void | Promise<void>;
|
|
366
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables:
|
|
1094
|
+
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Simplify<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
367
1095
|
onMutateResult: OnMutateResult | undefined;
|
|
368
1096
|
}) => void | Promise<void>;
|
|
369
1097
|
}): ((params: UrlHasParams<Url> extends true ? {
|
|
370
1098
|
urlParams: UrlParams<Url>;
|
|
371
1099
|
} : {}) => UseMutationResult<Result$1, Error, MutationArgs<Url, RequestSchema, QuerySchema>, OnMutateResult>) & MutationHelpers<Url, Result$1> & EndpointHelper<Method, Url, RequestSchema, Response, QuerySchema>;
|
|
372
|
-
|
|
1100
|
+
multipartMutation<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, QuerySchema extends ZodObject = ZodObject, Response extends ZodType = ZodType, ErrorSchema extends ErrorSchemaRecord | undefined = undefined, TBaseResult = ComputeBaseResult<UseDiscriminator, Response, ErrorSchema>, Result$1 = unknown, OnMutateResult = unknown, Context = unknown>(config: {
|
|
373
1101
|
method: Method;
|
|
374
1102
|
url: Url;
|
|
375
1103
|
requestSchema: RequestSchema;
|
|
376
1104
|
querySchema: QuerySchema;
|
|
377
1105
|
responseSchema: Response;
|
|
378
|
-
|
|
1106
|
+
errorSchema?: ErrorSchema;
|
|
1107
|
+
processResponse: (data: TBaseResult) => Result$1 | Promise<Result$1>;
|
|
379
1108
|
useContext?: () => Context;
|
|
380
|
-
onMutate?: (variables:
|
|
381
|
-
onSuccess?: (data: NoInfer<Result$1>, variables:
|
|
1109
|
+
onMutate?: (variables: Simplify<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
1110
|
+
onSuccess?: (data: NoInfer<Result$1>, variables: Simplify<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
382
1111
|
onMutateResult: OnMutateResult | undefined;
|
|
383
1112
|
}) => void | Promise<void>;
|
|
384
|
-
onError?: (error: Error, variables:
|
|
1113
|
+
onError?: (error: Error, variables: Simplify<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
385
1114
|
onMutateResult: OnMutateResult | undefined;
|
|
386
1115
|
}) => void | Promise<void>;
|
|
387
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables:
|
|
1116
|
+
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Simplify<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
388
1117
|
onMutateResult: OnMutateResult | undefined;
|
|
389
1118
|
}) => void | Promise<void>;
|
|
390
1119
|
}): (() => UseMutationResult<Result$1, Error, MutationArgs<Url, RequestSchema, QuerySchema>, OnMutateResult>) & MutationHelpers<Url, Result$1> & EndpointHelper<Method, Url, RequestSchema, Response, QuerySchema>;
|
|
391
|
-
|
|
1120
|
+
multipartMutation<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, Response extends ZodType = ZodType, ErrorSchema extends ErrorSchemaRecord | undefined = undefined, TBaseResult = ComputeBaseResult<UseDiscriminator, Response, ErrorSchema>, Result$1 = unknown, OnMutateResult = unknown, Context = unknown>(config: {
|
|
392
1121
|
method: Method;
|
|
393
1122
|
url: Url;
|
|
394
1123
|
requestSchema: RequestSchema;
|
|
395
1124
|
responseSchema: Response;
|
|
396
|
-
|
|
1125
|
+
errorSchema?: ErrorSchema;
|
|
1126
|
+
processResponse: (data: TBaseResult) => Result$1 | Promise<Result$1>;
|
|
397
1127
|
useContext?: () => Context;
|
|
398
|
-
onMutate?: (variables:
|
|
399
|
-
onSuccess?: (data: NoInfer<Result$1>, variables:
|
|
1128
|
+
onMutate?: (variables: Simplify<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
1129
|
+
onSuccess?: (data: NoInfer<Result$1>, variables: Simplify<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
400
1130
|
onMutateResult: OnMutateResult | undefined;
|
|
401
1131
|
}) => void | Promise<void>;
|
|
402
|
-
onError?: (error: Error, variables:
|
|
1132
|
+
onError?: (error: Error, variables: Simplify<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
403
1133
|
onMutateResult: OnMutateResult | undefined;
|
|
404
1134
|
}) => void | Promise<void>;
|
|
405
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables:
|
|
1135
|
+
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Simplify<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
406
1136
|
onMutateResult: OnMutateResult | undefined;
|
|
407
1137
|
}) => void | Promise<void>;
|
|
408
1138
|
}): (() => UseMutationResult<Result$1, Error, MutationArgs<Url, RequestSchema, undefined>, OnMutateResult>) & MutationHelpers<Url, Result$1> & EndpointHelper<Method, Url, RequestSchema, Response>;
|
|
409
|
-
|
|
1139
|
+
multipartMutation<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, Response extends ZodType = ZodType, ErrorSchema extends ErrorSchemaRecord | undefined = undefined, TBaseResult = ComputeBaseResult<UseDiscriminator, Response, ErrorSchema>, Result$1 = unknown, OnMutateResult = unknown, Context = unknown, UseKey extends true = true>(config: {
|
|
410
1140
|
method: Method;
|
|
411
1141
|
url: Url;
|
|
412
1142
|
useKey: UseKey;
|
|
413
1143
|
requestSchema: RequestSchema;
|
|
414
1144
|
responseSchema: Response;
|
|
415
|
-
|
|
1145
|
+
errorSchema?: ErrorSchema;
|
|
1146
|
+
processResponse: (data: TBaseResult) => Result$1 | Promise<Result$1>;
|
|
416
1147
|
useContext?: () => Context;
|
|
417
|
-
onMutate?: (variables:
|
|
418
|
-
onSuccess?: (data: NoInfer<Result$1>, variables:
|
|
1148
|
+
onMutate?: (variables: Simplify<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
1149
|
+
onSuccess?: (data: NoInfer<Result$1>, variables: Simplify<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
419
1150
|
onMutateResult: OnMutateResult | undefined;
|
|
420
1151
|
}) => void | Promise<void>;
|
|
421
|
-
onError?: (error: Error, variables:
|
|
1152
|
+
onError?: (error: Error, variables: Simplify<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
422
1153
|
onMutateResult: OnMutateResult | undefined;
|
|
423
1154
|
}) => void | Promise<void>;
|
|
424
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables:
|
|
1155
|
+
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Simplify<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
425
1156
|
onMutateResult: OnMutateResult | undefined;
|
|
426
1157
|
}) => void | Promise<void>;
|
|
427
1158
|
}): ((params: UrlHasParams<Url> extends true ? {
|
|
428
1159
|
urlParams: UrlParams<Url>;
|
|
429
1160
|
} : {}) => UseMutationResult<Result$1, Error, MutationArgs<Url, RequestSchema, undefined>, OnMutateResult>) & MutationHelpers<Url, Result$1> & EndpointHelper<Method, Url, RequestSchema, Response>;
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
onMutateResult: OnMutateResult | undefined;
|
|
467
|
-
}) => void | Promise<void>;
|
|
468
|
-
}): (() => UseMutationResult<Result$1, Error, MutationArgs<Url, undefined, QuerySchema>, OnMutateResult>) & MutationHelpers<Url, Result$1> & EndpointHelper<Method, Url, undefined, Response, QuerySchema>;
|
|
469
|
-
mutation<Method extends 'DELETE' = 'DELETE', Url extends string = string, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result$1 = unknown, OnMutateResult = unknown, Context = unknown, UseKey extends true = true>(config: {
|
|
470
|
-
method: Method;
|
|
471
|
-
url: Url;
|
|
472
|
-
useKey: UseKey;
|
|
473
|
-
responseSchema: Response;
|
|
474
|
-
processResponse: ProcessResponseFunction<Result$1, ReqResult>;
|
|
475
|
-
useContext?: () => Context;
|
|
476
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
477
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext & {
|
|
478
|
-
onMutateResult: OnMutateResult | undefined;
|
|
479
|
-
}) => void | Promise<void>;
|
|
480
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext & {
|
|
481
|
-
onMutateResult: OnMutateResult | undefined;
|
|
482
|
-
}) => void | Promise<void>;
|
|
483
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext & {
|
|
484
|
-
onMutateResult: OnMutateResult | undefined;
|
|
485
|
-
}) => void | Promise<void>;
|
|
486
|
-
}): ((params: UrlHasParams<Url> extends true ? {
|
|
487
|
-
urlParams: UrlParams<Url>;
|
|
488
|
-
} : {}) => UseMutationResult<Result$1, Error, MutationArgs<Url, undefined, undefined>, OnMutateResult>) & MutationHelpers<Url, Result$1> & EndpointHelper<Method, Url, undefined, Response>;
|
|
489
|
-
mutation<Method extends 'DELETE' = 'DELETE', Url extends string = string, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result$1 = unknown, OnMutateResult = unknown, Context = unknown>(config: {
|
|
490
|
-
method: Method;
|
|
491
|
-
url: Url;
|
|
492
|
-
responseSchema: Response;
|
|
493
|
-
processResponse: ProcessResponseFunction<Result$1, ReqResult>;
|
|
494
|
-
useContext?: () => Context;
|
|
495
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
496
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext & {
|
|
497
|
-
onMutateResult: OnMutateResult | undefined;
|
|
498
|
-
}) => void | Promise<void>;
|
|
499
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext & {
|
|
500
|
-
onMutateResult: OnMutateResult | undefined;
|
|
501
|
-
}) => void | Promise<void>;
|
|
502
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext & {
|
|
503
|
-
onMutateResult: OnMutateResult | undefined;
|
|
504
|
-
}) => void | Promise<void>;
|
|
505
|
-
}): (() => UseMutationResult<Result$1, Error, MutationArgs<Url, undefined, undefined>, OnMutateResult>) & MutationHelpers<Url, Result$1> & EndpointHelper<Method, Url, undefined, Response>;
|
|
506
|
-
queryFromEndpoint<Method extends 'GET' | 'HEAD' | 'OPTIONS' = 'GET', Url extends string = string, QuerySchema extends ZodObject = ZodObject, Response extends ZodType = ZodType, Result$1 = z.output<Response>>(endpoint: {
|
|
507
|
-
config: BaseEndpointConfig<Method, Url, QuerySchema, Response>;
|
|
508
|
-
}, options?: {
|
|
509
|
-
processResponse?: (data: z.output<Response>) => Result$1;
|
|
510
|
-
}): (params: Util_FlatObject<QueryArgs<Url, QuerySchema>>) => UseSuspenseQueryOptions<Result$1, Error, Result$1, DataTag<Split<Url, '/'>, Result$1, Error>> & QueryHelpers<Url, QuerySchema, Result$1>;
|
|
511
|
-
queryFromEndpoint<Method extends 'GET' | 'HEAD' | 'OPTIONS' = 'GET', Url extends string = string, Response extends ZodType = ZodType, Result$1 = z.output<Response>>(endpoint: {
|
|
512
|
-
config: BaseEndpointConfig<Method, Url, undefined, Response>;
|
|
1161
|
+
}
|
|
1162
|
+
//#endregion
|
|
1163
|
+
//#region src/client/types/from-endpoint.d.mts
|
|
1164
|
+
/**
|
|
1165
|
+
* Helper type to extract useKey from mutation options
|
|
1166
|
+
*/
|
|
1167
|
+
type ExtractUseKey<Options> = Options extends {
|
|
1168
|
+
useKey: infer U;
|
|
1169
|
+
} ? U extends true ? true : false : false;
|
|
1170
|
+
/**
|
|
1171
|
+
* FromEndpoint methods using const generics pattern (simplified from multiple overloads).
|
|
1172
|
+
*
|
|
1173
|
+
* @template UseDiscriminator - When `true`, errors are returned as union types.
|
|
1174
|
+
* When `false` (default), errors are thrown and not included in TData.
|
|
1175
|
+
*/
|
|
1176
|
+
interface ClientFromEndpointMethods<UseDiscriminator extends boolean = false> {
|
|
1177
|
+
/**
|
|
1178
|
+
* Creates a type-safe query from an existing endpoint with automatic type inference.
|
|
1179
|
+
*
|
|
1180
|
+
* Uses const generic pattern to infer types from the endpoint configuration.
|
|
1181
|
+
*
|
|
1182
|
+
* @example
|
|
1183
|
+
* ```ts
|
|
1184
|
+
* const getUserEndpoint = api.declareEndpoint({
|
|
1185
|
+
* method: 'GET',
|
|
1186
|
+
* url: '/users/$userId',
|
|
1187
|
+
* responseSchema: userSchema,
|
|
1188
|
+
* })
|
|
1189
|
+
*
|
|
1190
|
+
* const getUser = client.queryFromEndpoint(getUserEndpoint, {
|
|
1191
|
+
* processResponse: (data) => data,
|
|
1192
|
+
* })
|
|
1193
|
+
* ```
|
|
1194
|
+
*/
|
|
1195
|
+
queryFromEndpoint<const Config extends EndpointOptions, TBaseResult = ComputeBaseResult<UseDiscriminator, Config['responseSchema'], Config['errorSchema']>, Result$1 = TBaseResult>(endpoint: {
|
|
1196
|
+
config: Config;
|
|
513
1197
|
}, options?: {
|
|
514
|
-
processResponse?: (data:
|
|
515
|
-
}): ((params:
|
|
516
|
-
|
|
517
|
-
|
|
1198
|
+
processResponse?: (data: TBaseResult) => Result$1;
|
|
1199
|
+
}): ((params: Simplify<InferEndpointParams<Config>>) => UseSuspenseQueryOptions<Result$1, Error, Result$1, DataTag<Split<Config['url'], '/'>, Result$1, Error>>) & QueryHelpers<Config['url'], Config['querySchema'] extends ZodObject ? Config['querySchema'] : undefined, Result$1, false, Config['requestSchema'] extends ZodType ? Config['requestSchema'] : undefined>;
|
|
1200
|
+
/**
|
|
1201
|
+
* Creates a type-safe infinite query from an existing endpoint with automatic type inference.
|
|
1202
|
+
*
|
|
1203
|
+
* Uses const generic pattern to infer types from the endpoint configuration.
|
|
1204
|
+
*
|
|
1205
|
+
* @example
|
|
1206
|
+
* ```ts
|
|
1207
|
+
* const getUsersEndpoint = api.declareEndpoint({
|
|
1208
|
+
* method: 'GET',
|
|
1209
|
+
* url: '/users',
|
|
1210
|
+
* querySchema: z.object({ page: z.number() }),
|
|
1211
|
+
* responseSchema: z.array(userSchema),
|
|
1212
|
+
* })
|
|
1213
|
+
*
|
|
1214
|
+
* const getUsers = client.infiniteQueryFromEndpoint(getUsersEndpoint, {
|
|
1215
|
+
* getNextPageParam: (lastPage, allPages, lastPageParam) => {
|
|
1216
|
+
* return lastPage.length > 0 ? { page: (lastPageParam?.page ?? 0) + 1 } : undefined
|
|
1217
|
+
* },
|
|
1218
|
+
* })
|
|
1219
|
+
* ```
|
|
1220
|
+
*/
|
|
1221
|
+
infiniteQueryFromEndpoint<const Config extends EndpointOptions & {
|
|
1222
|
+
querySchema: ZodObject;
|
|
1223
|
+
}, TBaseResult = ComputeBaseResult<UseDiscriminator, Config['responseSchema'], Config['errorSchema']>, PageResult = TBaseResult, Result$1 = InfiniteData<PageResult>>(endpoint: {
|
|
1224
|
+
config: Config;
|
|
518
1225
|
}, options: {
|
|
519
|
-
processResponse?: (data:
|
|
520
|
-
getNextPageParam: (lastPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<
|
|
521
|
-
getPreviousPageParam?: (firstPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<
|
|
522
|
-
}): ((params:
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
processResponse: ProcessResponseFunction<Result$1, ReqResult>;
|
|
546
|
-
useKey: UseKey;
|
|
547
|
-
useContext?: () => Context;
|
|
548
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
549
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
550
|
-
onMutateResult: OnMutateResult | undefined;
|
|
551
|
-
}) => void | Promise<void>;
|
|
552
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
553
|
-
onMutateResult: OnMutateResult | undefined;
|
|
554
|
-
}) => void | Promise<void>;
|
|
555
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
556
|
-
onMutateResult: OnMutateResult | undefined;
|
|
557
|
-
}) => void | Promise<void>;
|
|
558
|
-
}): ((params: UrlHasParams<Url> extends true ? {
|
|
559
|
-
urlParams: UrlParams<Url>;
|
|
560
|
-
} : {}) => UseMutationResult<Result$1, Error, MutationArgs<Url, RequestSchema, undefined>, OnMutateResult>) & MutationHelpers<Url, Result$1> & EndpointHelper<Method, Url, RequestSchema, Response, undefined>;
|
|
561
|
-
mutationFromEndpoint<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, QuerySchema extends ZodObject = ZodObject, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result$1 = unknown, OnMutateResult = unknown, Context = unknown>(endpoint: {
|
|
562
|
-
config: BaseEndpointConfig<Method, Url, QuerySchema, Response, RequestSchema>;
|
|
563
|
-
}, mutationOptions: {
|
|
564
|
-
processResponse: ProcessResponseFunction<Result$1, ReqResult>;
|
|
565
|
-
useContext?: () => Context;
|
|
566
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
567
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
568
|
-
onMutateResult: OnMutateResult | undefined;
|
|
569
|
-
}) => void | Promise<void>;
|
|
570
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
571
|
-
onMutateResult: OnMutateResult | undefined;
|
|
572
|
-
}) => void | Promise<void>;
|
|
573
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
574
|
-
onMutateResult: OnMutateResult | undefined;
|
|
575
|
-
}) => void | Promise<void>;
|
|
576
|
-
}): (() => UseMutationResult<Result$1, Error, MutationArgs<Url, RequestSchema, QuerySchema>, OnMutateResult>) & EndpointHelper<Method, Url, RequestSchema, Response, QuerySchema>;
|
|
577
|
-
mutationFromEndpoint<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result$1 = unknown, OnMutateResult = unknown, Context = unknown>(endpoint: {
|
|
578
|
-
config: BaseEndpointConfig<Method, Url, undefined, Response, RequestSchema>;
|
|
579
|
-
}, mutationOptions: {
|
|
580
|
-
processResponse: ProcessResponseFunction<Result$1, ReqResult>;
|
|
581
|
-
useContext?: () => Context;
|
|
582
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
583
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
584
|
-
onMutateResult: OnMutateResult | undefined;
|
|
585
|
-
}) => void | Promise<void>;
|
|
586
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
587
|
-
onMutateResult: OnMutateResult | undefined;
|
|
588
|
-
}) => void | Promise<void>;
|
|
589
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
590
|
-
onMutateResult: OnMutateResult | undefined;
|
|
591
|
-
}) => void | Promise<void>;
|
|
592
|
-
}): (() => UseMutationResult<Result$1, Error, MutationArgs<Url, RequestSchema, undefined>, OnMutateResult>) & EndpointHelper<Method, Url, RequestSchema, Response, undefined>;
|
|
593
|
-
mutationFromEndpoint<Method extends 'DELETE' = 'DELETE', Url extends string = string, QuerySchema extends ZodObject = ZodObject, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result$1 = unknown, OnMutateResult = unknown, Context = unknown, UseKey extends true = true>(endpoint: {
|
|
594
|
-
config: BaseEndpointConfig<Method, Url, QuerySchema, Response>;
|
|
595
|
-
}, mutationOptions: {
|
|
596
|
-
processResponse: ProcessResponseFunction<Result$1, ReqResult>;
|
|
597
|
-
useKey: UseKey;
|
|
598
|
-
useContext?: () => Context;
|
|
599
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
600
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
601
|
-
onMutateResult: OnMutateResult | undefined;
|
|
602
|
-
}) => void | Promise<void>;
|
|
603
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
604
|
-
onMutateResult: OnMutateResult | undefined;
|
|
605
|
-
}) => void | Promise<void>;
|
|
606
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
607
|
-
onMutateResult: OnMutateResult | undefined;
|
|
608
|
-
}) => void | Promise<void>;
|
|
609
|
-
}): (() => UseMutationResult<Result$1, Error, MutationArgs<Url, undefined, QuerySchema>, OnMutateResult>) & MutationHelpers<Url, Result$1> & EndpointHelper<Method, Url, undefined, Response, QuerySchema>;
|
|
610
|
-
mutationFromEndpoint<Method extends 'DELETE' = 'DELETE', Url extends string = string, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result$1 = unknown, OnMutateResult = unknown, Context = unknown, UseKey extends true = true>(endpoint: {
|
|
611
|
-
config: BaseEndpointConfig<Method, Url, undefined, Response>;
|
|
612
|
-
}, mutationOptions: {
|
|
613
|
-
processResponse: ProcessResponseFunction<Result$1, ReqResult>;
|
|
614
|
-
useKey: UseKey;
|
|
615
|
-
useContext?: () => Context;
|
|
616
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
617
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext & {
|
|
618
|
-
onMutateResult: OnMutateResult | undefined;
|
|
619
|
-
}) => void | Promise<void>;
|
|
620
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext & {
|
|
621
|
-
onMutateResult: OnMutateResult | undefined;
|
|
622
|
-
}) => void | Promise<void>;
|
|
623
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext & {
|
|
624
|
-
onMutateResult: OnMutateResult | undefined;
|
|
625
|
-
}) => void | Promise<void>;
|
|
626
|
-
}): ((params: UrlHasParams<Url> extends true ? {
|
|
627
|
-
urlParams: UrlParams<Url>;
|
|
628
|
-
} : {}) => UseMutationResult<Result$1, Error, MutationArgs<Url, undefined, undefined>, OnMutateResult>) & MutationHelpers<Url, Result$1> & EndpointHelper<Method, Url, undefined, Response, undefined>;
|
|
629
|
-
mutationFromEndpoint<Method extends 'DELETE' = 'DELETE', Url extends string = string, QuerySchema extends ZodObject = ZodObject, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result$1 = unknown, OnMutateResult = unknown, Context = unknown>(endpoint: {
|
|
630
|
-
config: BaseEndpointConfig<Method, Url, QuerySchema, Response>;
|
|
631
|
-
}, mutationOptions: {
|
|
632
|
-
processResponse: ProcessResponseFunction<Result$1, ReqResult>;
|
|
633
|
-
useContext?: () => Context;
|
|
634
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
635
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
636
|
-
onMutateResult: OnMutateResult | undefined;
|
|
637
|
-
}) => void | Promise<void>;
|
|
638
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
639
|
-
onMutateResult: OnMutateResult | undefined;
|
|
640
|
-
}) => void | Promise<void>;
|
|
641
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
642
|
-
onMutateResult: OnMutateResult | undefined;
|
|
643
|
-
}) => void | Promise<void>;
|
|
644
|
-
}): (() => UseMutationResult<Result$1, Error, MutationArgs<Url, undefined, QuerySchema>, OnMutateResult>) & EndpointHelper<Method, Url, undefined, Response, QuerySchema>;
|
|
645
|
-
mutationFromEndpoint<Method extends 'DELETE' = 'DELETE', Url extends string = string, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result$1 = unknown, OnMutateResult = unknown, Context = unknown>(endpoint: {
|
|
646
|
-
config: BaseEndpointConfig<Method, Url, undefined, Response>;
|
|
647
|
-
}, mutationOptions: {
|
|
648
|
-
processResponse: ProcessResponseFunction<Result$1, ReqResult>;
|
|
649
|
-
useContext?: () => Context;
|
|
650
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
651
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext & {
|
|
652
|
-
onMutateResult: OnMutateResult | undefined;
|
|
653
|
-
}) => void | Promise<void>;
|
|
654
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext & {
|
|
655
|
-
onMutateResult: OnMutateResult | undefined;
|
|
656
|
-
}) => void | Promise<void>;
|
|
657
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext & {
|
|
658
|
-
onMutateResult: OnMutateResult | undefined;
|
|
659
|
-
}) => void | Promise<void>;
|
|
660
|
-
}): (() => UseMutationResult<Result$1, Error, MutationArgs<Url, undefined, undefined>, OnMutateResult>) & EndpointHelper<Method, Url, undefined, Response, undefined>;
|
|
661
|
-
multipartMutation<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, QuerySchema extends ZodObject = ZodObject, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result$1 = unknown, OnMutateResult = unknown, Context = unknown, UseKey extends true = true>(config: {
|
|
662
|
-
method: Method;
|
|
663
|
-
url: Url;
|
|
664
|
-
useKey: UseKey;
|
|
665
|
-
requestSchema: RequestSchema;
|
|
666
|
-
querySchema: QuerySchema;
|
|
667
|
-
responseSchema: Response;
|
|
668
|
-
processResponse: ProcessResponseFunction<Result$1, ReqResult>;
|
|
669
|
-
useContext?: () => Context;
|
|
670
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
671
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
672
|
-
onMutateResult: OnMutateResult | undefined;
|
|
673
|
-
}) => void | Promise<void>;
|
|
674
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
675
|
-
onMutateResult: OnMutateResult | undefined;
|
|
676
|
-
}) => void | Promise<void>;
|
|
677
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
678
|
-
onMutateResult: OnMutateResult | undefined;
|
|
679
|
-
}) => void | Promise<void>;
|
|
680
|
-
}): ((params: UrlHasParams<Url> extends true ? {
|
|
681
|
-
urlParams: UrlParams<Url>;
|
|
682
|
-
} : {}) => UseMutationResult<Result$1, Error, MutationArgs<Url, RequestSchema, QuerySchema>, OnMutateResult>) & MutationHelpers<Url, Result$1> & EndpointHelper<Method, Url, RequestSchema, Response, QuerySchema>;
|
|
683
|
-
multipartMutation<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, QuerySchema extends ZodObject = ZodObject, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result$1 = unknown, OnMutateResult = unknown, Context = unknown>(config: {
|
|
684
|
-
method: Method;
|
|
685
|
-
url: Url;
|
|
686
|
-
requestSchema: RequestSchema;
|
|
687
|
-
querySchema: QuerySchema;
|
|
688
|
-
responseSchema: Response;
|
|
689
|
-
processResponse: ProcessResponseFunction<Result$1, ReqResult>;
|
|
690
|
-
useContext?: () => Context;
|
|
691
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
692
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
693
|
-
onMutateResult: OnMutateResult | undefined;
|
|
694
|
-
}) => void | Promise<void>;
|
|
695
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
696
|
-
onMutateResult: OnMutateResult | undefined;
|
|
697
|
-
}) => void | Promise<void>;
|
|
698
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
699
|
-
onMutateResult: OnMutateResult | undefined;
|
|
700
|
-
}) => void | Promise<void>;
|
|
701
|
-
}): (() => UseMutationResult<Result$1, Error, MutationArgs<Url, RequestSchema, QuerySchema>, OnMutateResult>) & MutationHelpers<Url, Result$1> & EndpointHelper<Method, Url, RequestSchema, Response, QuerySchema>;
|
|
702
|
-
multipartMutation<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result$1 = unknown, OnMutateResult = unknown, Context = unknown>(config: {
|
|
703
|
-
method: Method;
|
|
704
|
-
url: Url;
|
|
705
|
-
requestSchema: RequestSchema;
|
|
706
|
-
responseSchema: Response;
|
|
707
|
-
processResponse: ProcessResponseFunction<Result$1, ReqResult>;
|
|
708
|
-
useContext?: () => Context;
|
|
709
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
710
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
711
|
-
onMutateResult: OnMutateResult | undefined;
|
|
712
|
-
}) => void | Promise<void>;
|
|
713
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
714
|
-
onMutateResult: OnMutateResult | undefined;
|
|
715
|
-
}) => void | Promise<void>;
|
|
716
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
717
|
-
onMutateResult: OnMutateResult | undefined;
|
|
718
|
-
}) => void | Promise<void>;
|
|
719
|
-
}): (() => UseMutationResult<Result$1, Error, MutationArgs<Url, RequestSchema, undefined>, OnMutateResult>) & MutationHelpers<Url, Result$1> & EndpointHelper<Method, Url, RequestSchema, Response>;
|
|
720
|
-
multipartMutation<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, Response extends ZodType = ZodType, ReqResult = z.output<Response>, Result$1 = unknown, OnMutateResult = unknown, Context = unknown, UseKey extends true = true>(config: {
|
|
721
|
-
method: Method;
|
|
722
|
-
url: Url;
|
|
723
|
-
useKey: UseKey;
|
|
724
|
-
requestSchema: RequestSchema;
|
|
725
|
-
responseSchema: Response;
|
|
726
|
-
processResponse: ProcessResponseFunction<Result$1, ReqResult>;
|
|
727
|
-
useContext?: () => Context;
|
|
728
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
729
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
730
|
-
onMutateResult: OnMutateResult | undefined;
|
|
731
|
-
}) => void | Promise<void>;
|
|
732
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
733
|
-
onMutateResult: OnMutateResult | undefined;
|
|
734
|
-
}) => void | Promise<void>;
|
|
735
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
736
|
-
onMutateResult: OnMutateResult | undefined;
|
|
737
|
-
}) => void | Promise<void>;
|
|
738
|
-
}): ((params: UrlHasParams<Url> extends true ? {
|
|
739
|
-
urlParams: UrlParams<Url>;
|
|
740
|
-
} : {}) => UseMutationResult<Result$1, Error, MutationArgs<Url, RequestSchema, undefined>, OnMutateResult>) & MutationHelpers<Url, Result$1> & EndpointHelper<Method, Url, RequestSchema, Response>;
|
|
741
|
-
mutationFromEndpoint<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, QuerySchema extends ZodObject = ZodObject, Result$1 = Blob, OnMutateResult = unknown, Context = unknown, UseKey extends true = true>(endpoint: {
|
|
742
|
-
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
743
|
-
}, mutationOptions: {
|
|
744
|
-
processResponse?: ProcessResponseFunction<Result$1, Blob>;
|
|
745
|
-
useKey: UseKey;
|
|
746
|
-
useContext?: () => Context;
|
|
747
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
748
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
749
|
-
onMutateResult: OnMutateResult | undefined;
|
|
750
|
-
}) => void | Promise<void>;
|
|
751
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
752
|
-
onMutateResult: OnMutateResult | undefined;
|
|
753
|
-
}) => void | Promise<void>;
|
|
754
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
755
|
-
onMutateResult: OnMutateResult | undefined;
|
|
756
|
-
}) => void | Promise<void>;
|
|
757
|
-
}): ((params: UrlHasParams<Url> extends true ? {
|
|
758
|
-
urlParams: UrlParams<Url>;
|
|
759
|
-
} : {}) => UseMutationResult<Result$1, Error, MutationArgs<Url, RequestSchema, QuerySchema>, OnMutateResult>) & MutationHelpers<Url, Result$1> & StreamHelper<Method, Url, RequestSchema, QuerySchema>;
|
|
760
|
-
mutationFromEndpoint<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, QuerySchema extends ZodObject = ZodObject, Result$1 = Blob, OnMutateResult = unknown, Context = unknown>(endpoint: {
|
|
761
|
-
config: BaseStreamConfig<Method, Url, QuerySchema, RequestSchema>;
|
|
762
|
-
}, mutationOptions?: {
|
|
763
|
-
processResponse?: ProcessResponseFunction<Result$1, Blob>;
|
|
764
|
-
useContext?: () => Context;
|
|
765
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
766
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
767
|
-
onMutateResult: OnMutateResult | undefined;
|
|
768
|
-
}) => void | Promise<void>;
|
|
769
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
770
|
-
onMutateResult: OnMutateResult | undefined;
|
|
771
|
-
}) => void | Promise<void>;
|
|
772
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
773
|
-
onMutateResult: OnMutateResult | undefined;
|
|
774
|
-
}) => void | Promise<void>;
|
|
775
|
-
}): (() => UseMutationResult<Result$1, Error, MutationArgs<Url, RequestSchema, QuerySchema>, OnMutateResult>) & StreamHelper<Method, Url, RequestSchema, QuerySchema>;
|
|
776
|
-
mutationFromEndpoint<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, Result$1 = Blob, OnMutateResult = unknown, Context = unknown, UseKey extends true = true>(endpoint: {
|
|
777
|
-
config: BaseStreamConfig<Method, Url, undefined, RequestSchema>;
|
|
778
|
-
}, mutationOptions: {
|
|
779
|
-
processResponse?: ProcessResponseFunction<Result$1, Blob>;
|
|
780
|
-
useKey: UseKey;
|
|
781
|
-
useContext?: () => Context;
|
|
782
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
783
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
784
|
-
onMutateResult: OnMutateResult | undefined;
|
|
785
|
-
}) => void | Promise<void>;
|
|
786
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
787
|
-
onMutateResult: OnMutateResult | undefined;
|
|
788
|
-
}) => void | Promise<void>;
|
|
789
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
790
|
-
onMutateResult: OnMutateResult | undefined;
|
|
791
|
-
}) => void | Promise<void>;
|
|
792
|
-
}): ((params: UrlHasParams<Url> extends true ? {
|
|
793
|
-
urlParams: UrlParams<Url>;
|
|
794
|
-
} : {}) => UseMutationResult<Result$1, Error, MutationArgs<Url, RequestSchema, undefined>, OnMutateResult>) & MutationHelpers<Url, Result$1> & StreamHelper<Method, Url, RequestSchema, undefined>;
|
|
795
|
-
mutationFromEndpoint<Method extends 'POST' | 'PUT' | 'PATCH' = 'POST' | 'PUT' | 'PATCH', Url extends string = string, RequestSchema extends ZodType = ZodType, Result$1 = Blob, OnMutateResult = unknown, Context = unknown>(endpoint: {
|
|
796
|
-
config: BaseStreamConfig<Method, Url, undefined, RequestSchema>;
|
|
797
|
-
}, mutationOptions?: {
|
|
798
|
-
processResponse?: ProcessResponseFunction<Result$1, Blob>;
|
|
799
|
-
useContext?: () => Context;
|
|
800
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
801
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
802
|
-
onMutateResult: OnMutateResult | undefined;
|
|
803
|
-
}) => void | Promise<void>;
|
|
804
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
805
|
-
onMutateResult: OnMutateResult | undefined;
|
|
806
|
-
}) => void | Promise<void>;
|
|
807
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, RequestSchema, undefined>>, context: Context & MutationFunctionContext & {
|
|
808
|
-
onMutateResult: OnMutateResult | undefined;
|
|
809
|
-
}) => void | Promise<void>;
|
|
810
|
-
}): (() => UseMutationResult<Result$1, Error, MutationArgs<Url, RequestSchema, undefined>, OnMutateResult>) & StreamHelper<Method, Url, RequestSchema, undefined>;
|
|
811
|
-
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, QuerySchema extends ZodObject = ZodObject, Result$1 = Blob, OnMutateResult = unknown, Context = unknown, UseKey extends true = true>(endpoint: {
|
|
812
|
-
config: BaseStreamConfig<Method, Url, QuerySchema, undefined>;
|
|
813
|
-
}, mutationOptions: {
|
|
814
|
-
processResponse?: ProcessResponseFunction<Result$1, Blob>;
|
|
815
|
-
useKey: UseKey;
|
|
816
|
-
useContext?: () => Context;
|
|
817
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
818
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
819
|
-
onMutateResult: OnMutateResult | undefined;
|
|
820
|
-
}) => void | Promise<void>;
|
|
821
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
822
|
-
onMutateResult: OnMutateResult | undefined;
|
|
823
|
-
}) => void | Promise<void>;
|
|
824
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
825
|
-
onMutateResult: OnMutateResult | undefined;
|
|
826
|
-
}) => void | Promise<void>;
|
|
827
|
-
}): ((params: UrlHasParams<Url> extends true ? {
|
|
828
|
-
urlParams: UrlParams<Url>;
|
|
829
|
-
} : {}) => UseMutationResult<Result$1, Error, MutationArgs<Url, undefined, QuerySchema>, OnMutateResult>) & MutationHelpers<Url, Result$1> & StreamHelper<Method, Url, undefined, QuerySchema>;
|
|
830
|
-
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, QuerySchema extends ZodObject = ZodObject, Result$1 = Blob, OnMutateResult = unknown, Context = unknown>(endpoint: {
|
|
831
|
-
config: BaseStreamConfig<Method, Url, QuerySchema, undefined>;
|
|
832
|
-
}, mutationOptions?: {
|
|
833
|
-
processResponse?: ProcessResponseFunction<Result$1, Blob>;
|
|
834
|
-
useContext?: () => Context;
|
|
835
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
836
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
837
|
-
onMutateResult: OnMutateResult | undefined;
|
|
838
|
-
}) => void | Promise<void>;
|
|
839
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
840
|
-
onMutateResult: OnMutateResult | undefined;
|
|
841
|
-
}) => void | Promise<void>;
|
|
842
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, undefined, QuerySchema>>, context: Context & MutationFunctionContext & {
|
|
843
|
-
onMutateResult: OnMutateResult | undefined;
|
|
844
|
-
}) => void | Promise<void>;
|
|
845
|
-
}): (() => UseMutationResult<Result$1, Error, MutationArgs<Url, undefined, QuerySchema>, OnMutateResult>) & StreamHelper<Method, Url, undefined, QuerySchema>;
|
|
846
|
-
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, Result$1 = Blob, OnMutateResult = unknown, Context = unknown, UseKey extends true = true>(endpoint: {
|
|
847
|
-
config: BaseStreamConfig<Method, Url, undefined, undefined>;
|
|
848
|
-
}, mutationOptions: {
|
|
849
|
-
processResponse?: ProcessResponseFunction<Result$1, Blob>;
|
|
850
|
-
useKey: UseKey;
|
|
851
|
-
useContext?: () => Context;
|
|
852
|
-
onMutate?: (variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
853
|
-
onSuccess?: (data: NoInfer<Result$1>, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext & {
|
|
854
|
-
onMutateResult: OnMutateResult | undefined;
|
|
855
|
-
}) => void | Promise<void>;
|
|
856
|
-
onError?: (error: Error, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext & {
|
|
857
|
-
onMutateResult: OnMutateResult | undefined;
|
|
858
|
-
}) => void | Promise<void>;
|
|
859
|
-
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Util_FlatObject<MutationArgs<Url, undefined, undefined>>, context: Context & MutationFunctionContext & {
|
|
860
|
-
onMutateResult: OnMutateResult | undefined;
|
|
861
|
-
}) => void | Promise<void>;
|
|
862
|
-
}): ((params: UrlHasParams<Url> extends true ? {
|
|
863
|
-
urlParams: UrlParams<Url>;
|
|
864
|
-
} : {}) => UseMutationResult<Result$1, Error, MutationArgs<Url, undefined, undefined>, OnMutateResult>) & MutationHelpers<Url, Result$1> & StreamHelper<Method, Url, undefined, undefined>;
|
|
865
|
-
mutationFromEndpoint<Method extends 'GET' | 'DELETE' | 'OPTIONS' | 'HEAD' = 'GET', Url extends string = string, Result$1 = Blob, OnMutateResult = unknown, Context = unknown>(endpoint: {
|
|
866
|
-
config: BaseStreamConfig<Method, Url, undefined, undefined>;
|
|
1226
|
+
processResponse?: (data: TBaseResult) => PageResult;
|
|
1227
|
+
getNextPageParam: (lastPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<Config['querySchema']> | undefined, allPageParams: z.infer<Config['querySchema']>[] | undefined) => z.input<Config['querySchema']> | undefined;
|
|
1228
|
+
getPreviousPageParam?: (firstPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<Config['querySchema']> | undefined, allPageParams: z.infer<Config['querySchema']>[] | undefined) => z.input<Config['querySchema']>;
|
|
1229
|
+
}): ((params: Simplify<InferEndpointParams<Config>>) => UseSuspenseInfiniteQueryOptions<PageResult, Error, Result$1, DataTag<Split<Config['url'], '/'>, PageResult, Error>, z.output<Config['querySchema']>>) & QueryHelpers<Config['url'], Config['querySchema'], PageResult, true, Config['requestSchema'] extends ZodType ? Config['requestSchema'] : undefined>;
|
|
1230
|
+
/**
|
|
1231
|
+
* Creates a type-safe mutation from an existing endpoint with automatic type inference.
|
|
1232
|
+
*
|
|
1233
|
+
* Uses const generic pattern to infer types from the endpoint configuration.
|
|
1234
|
+
* Handles both regular endpoints and stream endpoints.
|
|
1235
|
+
*
|
|
1236
|
+
* @example
|
|
1237
|
+
* ```ts
|
|
1238
|
+
* const createUserEndpoint = api.declareEndpoint({
|
|
1239
|
+
* method: 'POST',
|
|
1240
|
+
* url: '/users',
|
|
1241
|
+
* requestSchema: createUserSchema,
|
|
1242
|
+
* responseSchema: userSchema,
|
|
1243
|
+
* })
|
|
1244
|
+
*
|
|
1245
|
+
* const createUser = client.mutationFromEndpoint(createUserEndpoint, {
|
|
1246
|
+
* processResponse: (data) => data,
|
|
1247
|
+
* })
|
|
1248
|
+
* ```
|
|
1249
|
+
*/
|
|
1250
|
+
mutationFromEndpoint<const Config extends EndpointOptions | BaseEndpointOptions, TBaseResult = (Config extends EndpointOptions ? ComputeBaseResult<UseDiscriminator, Config['responseSchema'], Config['errorSchema']> : Blob), Result$1 = (Config extends EndpointOptions ? ComputeBaseResult<UseDiscriminator, Config['responseSchema'], Config['errorSchema']> : Blob), OnMutateResult = unknown, Context = unknown>(endpoint: {
|
|
1251
|
+
config: Config;
|
|
867
1252
|
}, mutationOptions?: {
|
|
868
|
-
processResponse?:
|
|
1253
|
+
processResponse?: (data: TBaseResult) => Result$1 | Promise<Result$1>;
|
|
869
1254
|
useContext?: () => Context;
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
1255
|
+
useKey?: boolean;
|
|
1256
|
+
onMutate?: (variables: Simplify<RequestArgs<Config['url'], Config['querySchema'] extends ZodObject ? Config['querySchema'] : undefined, Config['requestSchema'] extends ZodType ? Config['requestSchema'] : undefined, Config['urlParamsSchema'] extends ZodObject ? Config['urlParamsSchema'] : undefined>>, context: Context & MutationFunctionContext) => OnMutateResult | Promise<OnMutateResult>;
|
|
1257
|
+
onSuccess?: (data: NoInfer<Result$1>, variables: Simplify<RequestArgs<Config['url'], Config['querySchema'] extends ZodObject ? Config['querySchema'] : undefined, Config['requestSchema'] extends ZodType ? Config['requestSchema'] : undefined, Config['urlParamsSchema'] extends ZodObject ? Config['urlParamsSchema'] : undefined>>, context: Context & MutationFunctionContext & {
|
|
1258
|
+
onMutateResult: OnMutateResult | undefined;
|
|
1259
|
+
}) => void | Promise<void>;
|
|
1260
|
+
onError?: (error: Error, variables: Simplify<RequestArgs<Config['url'], Config['querySchema'] extends ZodObject ? Config['querySchema'] : undefined, Config['requestSchema'] extends ZodType ? Config['requestSchema'] : undefined, Config['urlParamsSchema'] extends ZodObject ? Config['urlParamsSchema'] : undefined>>, context: Context & MutationFunctionContext & {
|
|
1261
|
+
onMutateResult: OnMutateResult | undefined;
|
|
1262
|
+
}) => void | Promise<void>;
|
|
1263
|
+
onSettled?: (data: NoInfer<Result$1> | undefined, error: Error | null, variables: Simplify<RequestArgs<Config['url'], Config['querySchema'] extends ZodObject ? Config['querySchema'] : undefined, Config['requestSchema'] extends ZodType ? Config['requestSchema'] : undefined, Config['urlParamsSchema'] extends ZodObject ? Config['urlParamsSchema'] : undefined>>, context: Context & MutationFunctionContext & {
|
|
1264
|
+
onMutateResult: OnMutateResult | undefined;
|
|
1265
|
+
}) => void | Promise<void>;
|
|
1266
|
+
}): ((...args: ExtractUseKey<typeof mutationOptions> extends true ? UrlHasParams<Config['url']> extends true ? [{
|
|
1267
|
+
urlParams: UrlParams<Config['url']>;
|
|
1268
|
+
}] : [] : []) => UseMutationResult<Result$1, Error, Simplify<RequestArgs<Config['url'], Config['querySchema'] extends ZodObject ? Config['querySchema'] : undefined, Config['requestSchema'] extends ZodType ? Config['requestSchema'] : undefined, Config['urlParamsSchema'] extends ZodObject ? Config['urlParamsSchema'] : undefined>>, OnMutateResult>) & (ExtractUseKey<typeof mutationOptions> extends true ? MutationHelpers<Config['url'], Result$1> : {}) & (Config extends EndpointOptions ? EndpointHelper<{
|
|
1269
|
+
method: Config['method'];
|
|
1270
|
+
url: Config['url'];
|
|
1271
|
+
responseSchema: Config['responseSchema'];
|
|
1272
|
+
querySchema: Config['querySchema'];
|
|
1273
|
+
requestSchema: Config['requestSchema'];
|
|
1274
|
+
errorSchema: Config['errorSchema'];
|
|
1275
|
+
urlParamsSchema: Config['urlParamsSchema'];
|
|
1276
|
+
}, UseDiscriminator> : StreamHelper<{
|
|
1277
|
+
method: Config['method'];
|
|
1278
|
+
url: Config['url'];
|
|
1279
|
+
querySchema: Config['querySchema'];
|
|
1280
|
+
requestSchema: Config['requestSchema'];
|
|
1281
|
+
errorSchema: Config['errorSchema'];
|
|
1282
|
+
urlParamsSchema: Config['urlParamsSchema'];
|
|
1283
|
+
}, UseDiscriminator>);
|
|
881
1284
|
}
|
|
882
1285
|
//#endregion
|
|
1286
|
+
//#region src/client/types/index.d.mts
|
|
1287
|
+
/**
|
|
1288
|
+
* The main client instance interface.
|
|
1289
|
+
* Provides methods for creating queries, infinite queries, and mutations.
|
|
1290
|
+
*
|
|
1291
|
+
* @template UseDiscriminator - When `true`, errors are returned as union types.
|
|
1292
|
+
* When `false` (default), errors are thrown and not included in TData.
|
|
1293
|
+
*/
|
|
1294
|
+
interface ClientInstance<UseDiscriminator extends boolean = false> extends ClientQueryMethods<UseDiscriminator>, ClientInfiniteQueryMethods<UseDiscriminator>, ClientMutationMethods<UseDiscriminator>, ClientMultipartMutationMethods<UseDiscriminator>, ClientFromEndpointMethods<UseDiscriminator> {}
|
|
1295
|
+
//#endregion
|
|
883
1296
|
//#region src/client/declare-client.d.mts
|
|
884
1297
|
/**
|
|
885
1298
|
* Configuration for declaring a query endpoint.
|
|
886
1299
|
*/
|
|
887
|
-
interface QueryConfig<Method = HttpMethod, Url = string, QuerySchema =
|
|
1300
|
+
interface QueryConfig<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema extends ZodObject | undefined = undefined, Response extends ZodType = ZodType, ErrorSchema extends ErrorSchemaRecord | undefined = undefined, Result$1 = ComputeBaseResult<true, Response, ErrorSchema>, RequestSchema extends ZodType | undefined = undefined> {
|
|
888
1301
|
method: Method;
|
|
889
1302
|
url: Url;
|
|
890
1303
|
querySchema?: QuerySchema;
|
|
891
1304
|
responseSchema: Response;
|
|
1305
|
+
errorSchema?: ErrorSchema;
|
|
892
1306
|
requestSchema?: RequestSchema;
|
|
893
|
-
processResponse?: (data:
|
|
1307
|
+
processResponse?: (data: ComputeBaseResult<true, Response, ErrorSchema>) => Result$1;
|
|
894
1308
|
}
|
|
895
1309
|
/**
|
|
896
1310
|
* Configuration for declaring an infinite query endpoint.
|
|
897
1311
|
*/
|
|
898
|
-
type InfiniteQueryConfig<Method = HttpMethod, Url = string, QuerySchema extends ZodObject = ZodObject, Response extends ZodType = ZodType, PageResult =
|
|
1312
|
+
type InfiniteQueryConfig<Method extends HttpMethod = HttpMethod, Url extends string = string, QuerySchema extends ZodObject = ZodObject, Response extends ZodType = ZodType, ErrorSchema extends ErrorSchemaRecord | undefined = undefined, PageResult = ComputeBaseResult<true, Response, ErrorSchema>, Result$1 = InfiniteData<PageResult>, RequestSchema extends ZodType | undefined = undefined> = {
|
|
899
1313
|
method: Method;
|
|
900
1314
|
url: Url;
|
|
901
1315
|
querySchema: QuerySchema;
|
|
902
1316
|
responseSchema: Response;
|
|
1317
|
+
errorSchema?: ErrorSchema;
|
|
903
1318
|
requestSchema?: RequestSchema;
|
|
904
|
-
processResponse?: (data:
|
|
1319
|
+
processResponse?: (data: ComputeBaseResult<true, Response, ErrorSchema>) => PageResult;
|
|
905
1320
|
select?: (data: InfiniteData<PageResult>) => Result$1;
|
|
906
1321
|
getNextPageParam: (lastPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<QuerySchema> | undefined, allPageParams: z.infer<QuerySchema>[] | undefined) => z.input<QuerySchema> | undefined;
|
|
907
1322
|
getPreviousPageParam?: (firstPage: PageResult, allPages: PageResult[], lastPageParam: z.infer<QuerySchema> | undefined, allPageParams: z.infer<QuerySchema>[] | undefined) => z.input<QuerySchema>;
|
|
@@ -910,11 +1325,12 @@ type InfiniteQueryConfig<Method = HttpMethod, Url = string, QuerySchema extends
|
|
|
910
1325
|
/**
|
|
911
1326
|
* Configuration for declaring a mutation endpoint.
|
|
912
1327
|
*/
|
|
913
|
-
interface MutationConfig<Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' = 'POST' | 'PUT' | 'PATCH' | 'DELETE', Url extends string = string, RequestSchema = (Method extends 'DELETE' ?
|
|
1328
|
+
interface MutationConfig<Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' = 'POST' | 'PUT' | 'PATCH' | 'DELETE', Url extends string = string, RequestSchema extends ZodType | undefined = (Method extends 'DELETE' ? undefined : ZodType), QuerySchema extends ZodObject | undefined = undefined, Response extends ZodType = ZodType, ErrorSchema extends ErrorSchemaRecord | undefined = undefined, ReqResult = ComputeBaseResult<true, Response, ErrorSchema>, Result$1 = unknown, TOnMutateResult = unknown, Context = unknown, UseKey extends boolean = false> {
|
|
914
1329
|
method: Method;
|
|
915
1330
|
url: Url;
|
|
916
1331
|
querySchema?: QuerySchema;
|
|
917
1332
|
responseSchema: Response;
|
|
1333
|
+
errorSchema?: ErrorSchema;
|
|
918
1334
|
requestSchema?: RequestSchema;
|
|
919
1335
|
processResponse: ProcessResponseFunction<Result$1, ReqResult>;
|
|
920
1336
|
useContext?: () => Context;
|
|
@@ -934,12 +1350,15 @@ interface MutationConfig<Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' = 'P
|
|
|
934
1350
|
/**
|
|
935
1351
|
* Creates a client instance for making type-safe queries and mutations.
|
|
936
1352
|
*
|
|
1353
|
+
* @template UseDiscriminator - When `true`, errors are returned as union types.
|
|
1354
|
+
* When `false` (default), errors are thrown and not included in TData.
|
|
1355
|
+
*
|
|
937
1356
|
* @param options - Client configuration including the API builder and defaults
|
|
938
1357
|
* @returns A client instance with query, infiniteQuery, and mutation methods
|
|
939
1358
|
*
|
|
940
1359
|
* @example
|
|
941
1360
|
* ```typescript
|
|
942
|
-
* const api =
|
|
1361
|
+
* const api = builder({});
|
|
943
1362
|
* const client = declareClient({ api });
|
|
944
1363
|
*
|
|
945
1364
|
* const getUser = client.query({
|
|
@@ -952,10 +1371,10 @@ interface MutationConfig<Method extends 'POST' | 'PUT' | 'PATCH' | 'DELETE' = 'P
|
|
|
952
1371
|
* const { data } = useSuspenseQuery(getUser({ urlParams: { id: '123' } }));
|
|
953
1372
|
* ```
|
|
954
1373
|
*/
|
|
955
|
-
declare function declareClient<
|
|
1374
|
+
declare function declareClient<UseDiscriminator extends boolean = false>({
|
|
956
1375
|
api,
|
|
957
1376
|
defaults
|
|
958
|
-
}:
|
|
1377
|
+
}: ClientOptions<UseDiscriminator>): ClientInstance<UseDiscriminator>;
|
|
959
1378
|
//#endregion
|
|
960
|
-
export { BaseMutationArgs, BaseMutationParams, BaseQueryArgs, BaseQueryParams, ClientEndpointHelper, ClientInstance, ClientMutationArgs, ClientOptions, ClientQueryArgs, ClientQueryUrlParamsArgs, EndpointHelper, InfiniteQueryConfig, InfiniteQueryOptions, MutationArgs, MutationConfig, MutationHelpers, MutationParams, ProcessResponseFunction, QueryArgs, QueryConfig, QueryHelpers, QueryKeyCreatorResult, QueryParams, QueryUrlParamsArgs, Split, StreamHelper, createMutationKey, createQueryKey, declareClient, makeInfiniteQueryOptions, makeMutation, makeQueryOptions, mutationKeyCreator, queryKeyCreator };
|
|
1379
|
+
export { BaseMutationArgs, BaseMutationParams, BaseQueryArgs, BaseQueryParams, ClientEndpointHelper, ClientFromEndpointMethods, ClientInfiniteQueryMethods, ClientInstance, ClientMultipartMutationMethods, ClientMutationArgs, ClientMutationMethods, ClientOptions, ClientQueryArgs, ClientQueryMethods, ClientQueryUrlParamsArgs, ComputeBaseResult, ComputeResponseInput, ComputeResultType, EndpointHelper, InferEndpointResponse, InfiniteQueryConfig, InfiniteQueryOptions, MakeQueryOptionsParams, MutationArgs, MutationConfig, MutationHelpers, MutationParams, OptimisticUpdateCallbacks, OptimisticUpdateConfig, PrefetchHelper, ProcessResponseFunction, QueryArgs, QueryConfig, QueryHelpers, QueryKeyCreatorResult, QueryOptionsCreator, QueryParams, QueryResult, QueryUrlParamsArgs, ResponseDataType, Split, StreamHelper, createMultiOptimisticUpdate, createMutationKey, createOptimisticUpdate, createPrefetchHelper, createPrefetchHelpers, createQueryKey, declareClient, makeInfiniteQueryOptions, makeMutation, makeQueryOptions, mutationKeyCreator, prefetchAll, queryKeyCreator };
|
|
961
1380
|
//# sourceMappingURL=index.d.cts.map
|