@tuyau/react-query 0.0.1-next.0 → 0.0.1-next.2
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/build/index.d.ts +69 -27
- package/build/index.js +58 -34
- package/package.json +7 -7
package/build/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ interface TuyauReactQueryOptions<EDef extends EndpointDef, TParams = Record<stri
|
|
|
21
21
|
} | SkipToken, opts?: UndefinedTuyauQueryOptionsIn<UnionFromSuccessStatuses<EDef['response']>, TData, any>): UndefinedTuyauQueryOptionsOut<UnionFromSuccessStatuses<EDef['response']>, TData, any>;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
* Interface for query function decorators
|
|
24
|
+
* Interface for query function decorators
|
|
25
25
|
*/
|
|
26
26
|
interface DecorateQueryFn<EDef extends EndpointDef, TParams = Record<string, string | number>> extends TypeHelper<EDef> {
|
|
27
27
|
queryOptions: TuyauReactQueryOptions<EDef, TParams>;
|
|
@@ -45,14 +45,17 @@ interface DecorateMutationFn<EDef extends EndpointDef, TParams = Record<string,
|
|
|
45
45
|
/**
|
|
46
46
|
* Output type for mutation options
|
|
47
47
|
*/
|
|
48
|
-
interface TuyauMutationOptionsOut<TInput, TError, TOutput, TContext, TParams = Record<string, string | number>> extends UseMutationOptions<TOutput, TError, {
|
|
48
|
+
interface TuyauMutationOptionsOut<TInput, TError, TOutput, TContext, TParams = Record<string, string | number>> extends UseMutationOptions<TOutput, TError, TInput extends undefined | {} | Record<string, never> | unknown ? {
|
|
49
|
+
payload?: TInput;
|
|
50
|
+
params?: TParams;
|
|
51
|
+
} : {
|
|
49
52
|
payload: TInput;
|
|
50
53
|
params?: TParams;
|
|
51
54
|
}, TContext> {
|
|
52
55
|
mutationKey: TuyauMutationKey;
|
|
53
56
|
}
|
|
54
57
|
/**
|
|
55
|
-
* Type definition for mutation options
|
|
58
|
+
* Type definition for mutation options
|
|
56
59
|
*/
|
|
57
60
|
interface TuyauReactMutationOptions<TDef extends EndpointDef, TParams = Record<string, string | number>> {
|
|
58
61
|
<TContext = unknown>(opts?: TuyauMutationOptionsIn<TDef['request'], any, UnionFromSuccessStatuses<TDef['response']>, TContext, TParams>): TuyauMutationOptionsOut<TDef['request'], any, UnionFromSuccessStatuses<TDef['response']>, TContext, TParams>;
|
|
@@ -95,38 +98,38 @@ type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
|
95
98
|
/**
|
|
96
99
|
* Query options with defined initial data
|
|
97
100
|
*/
|
|
98
|
-
interface DefinedTuyauQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<DefinedInitialDataOptions<TQueryFnData, TError, TData, TuyauQueryKey>, 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash'
|
|
101
|
+
interface DefinedTuyauQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<DefinedInitialDataOptions<TQueryFnData, TError, TData, TuyauQueryKey>, 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash'>, TuyauQueryBaseOptions {
|
|
99
102
|
}
|
|
100
103
|
/**
|
|
101
104
|
* Query options with undefined initial data
|
|
102
105
|
*/
|
|
103
|
-
interface UndefinedTuyauQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<UndefinedInitialDataOptions<TQueryFnData, TError, TData, TuyauQueryKey>, 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash'
|
|
106
|
+
interface UndefinedTuyauQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<UndefinedInitialDataOptions<TQueryFnData, TError, TData, TuyauQueryKey>, 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash'>, TuyauQueryBaseOptions {
|
|
104
107
|
}
|
|
105
108
|
/**
|
|
106
109
|
* Query options with unused skip token
|
|
107
110
|
*/
|
|
108
|
-
interface UnusedSkipTokenTuyauQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<UnusedSkipTokenOptions<TQueryFnData, TError, TData, TuyauQueryKey>, 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash'
|
|
111
|
+
interface UnusedSkipTokenTuyauQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<UnusedSkipTokenOptions<TQueryFnData, TError, TData, TuyauQueryKey>, 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash'>, TuyauQueryBaseOptions {
|
|
109
112
|
}
|
|
110
113
|
/**
|
|
111
114
|
* Output type for query options with defined initial data
|
|
112
115
|
*/
|
|
113
|
-
interface DefinedTuyauQueryOptionsOut<TQueryFnData, TData, TError> extends DefinedInitialDataOptions<TQueryFnData, TError, TData, TuyauQueryKey
|
|
116
|
+
interface DefinedTuyauQueryOptionsOut<TQueryFnData, TData, TError> extends DefinedInitialDataOptions<TQueryFnData, TError, TData, TuyauQueryKey>, TuyauQueryOptionsResult {
|
|
114
117
|
queryKey: DataTag<TuyauQueryKey, TData, TError>;
|
|
115
118
|
}
|
|
116
119
|
/**
|
|
117
120
|
* Output type for query options with undefined initial data
|
|
118
121
|
*/
|
|
119
|
-
interface UndefinedTuyauQueryOptionsOut<TQueryFnData, TData, TError> extends UndefinedInitialDataOptions<TQueryFnData, TError, TData, TuyauQueryKey
|
|
122
|
+
interface UndefinedTuyauQueryOptionsOut<TQueryFnData, TData, TError> extends UndefinedInitialDataOptions<TQueryFnData, TError, TData, TuyauQueryKey>, TuyauQueryOptionsResult {
|
|
120
123
|
queryKey: DataTag<TuyauQueryKey, TData, TError>;
|
|
121
124
|
}
|
|
122
125
|
/**
|
|
123
126
|
* Output type for query options with unused skip token
|
|
124
127
|
*/
|
|
125
|
-
interface UnusedSkipTokenTuyauQueryOptionsOut<TQueryFnData, TData, TError> extends UnusedSkipTokenOptions<TQueryFnData, TError, TData, TuyauQueryKey
|
|
128
|
+
interface UnusedSkipTokenTuyauQueryOptionsOut<TQueryFnData, TData, TError> extends UnusedSkipTokenOptions<TQueryFnData, TError, TData, TuyauQueryKey>, TuyauQueryOptionsResult {
|
|
126
129
|
queryKey: DataTag<TuyauQueryKey, TData, TError>;
|
|
127
130
|
}
|
|
128
131
|
/**
|
|
129
|
-
* Input type for mutation options
|
|
132
|
+
* Input type for mutation options
|
|
130
133
|
*/
|
|
131
134
|
interface TuyauMutationOptionsIn<TInput, TError, TOutput, TContext, TParams = Record<string, string | number>> extends DistributiveOmit<UseMutationOptions<TOutput, TError, {
|
|
132
135
|
payload: TInput;
|
|
@@ -160,7 +163,34 @@ type InferRequestType<Endpoint extends DecorateQueryFn<any> | DecorateMutationFn
|
|
|
160
163
|
/**
|
|
161
164
|
* Infer response type from an endpoint
|
|
162
165
|
*/
|
|
163
|
-
type InferResponseType<Endpoint extends DecorateQueryFn<any> | DecorateMutationFn<any>> = Endpoint['~types']['response'];
|
|
166
|
+
type InferResponseType<Endpoint extends DecorateQueryFn<any> | DecorateMutationFn<any>> = Endpoint['~types']['response']['200'];
|
|
167
|
+
/**
|
|
168
|
+
* Tuyau-specific request options for React Query integration
|
|
169
|
+
*/
|
|
170
|
+
interface TuyauReactRequestOptions {
|
|
171
|
+
/**
|
|
172
|
+
* Opt out or into aborting request on unmount
|
|
173
|
+
*/
|
|
174
|
+
abortOnUnmount?: boolean;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Base options for Tuyau queries
|
|
178
|
+
*/
|
|
179
|
+
interface TuyauQueryBaseOptions {
|
|
180
|
+
/**
|
|
181
|
+
* Tuyau-related options
|
|
182
|
+
*/
|
|
183
|
+
tuyau?: TuyauReactRequestOptions;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Result interface for Tuyau query options
|
|
187
|
+
*/
|
|
188
|
+
interface TuyauQueryOptionsResult {
|
|
189
|
+
tuyau: {
|
|
190
|
+
path: string[];
|
|
191
|
+
type: 'query';
|
|
192
|
+
};
|
|
193
|
+
}
|
|
164
194
|
|
|
165
195
|
/**
|
|
166
196
|
* Reserved infinite query options that should not be overridden
|
|
@@ -176,17 +206,21 @@ type TuyauInfiniteData<TData> = {
|
|
|
176
206
|
/**
|
|
177
207
|
* Infinite query options with undefined initial data
|
|
178
208
|
*/
|
|
179
|
-
interface UndefinedTuyauInfiniteQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TuyauInfiniteData<TData>, TuyauQueryKey,
|
|
209
|
+
interface UndefinedTuyauInfiniteQueryOptionsIn<TQueryFnData, TData, TError, TRequest, TPageParamKey extends keyof TRequest> extends DistributiveOmit<UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TuyauInfiniteData<TData>, TuyauQueryKey, ExtractPageParamType<TRequest, TPageParamKey> | null>, InfiniteQueryReservedOptions>, TuyauQueryBaseOptions {
|
|
210
|
+
pageParamKey: TPageParamKey;
|
|
180
211
|
}
|
|
181
212
|
/**
|
|
182
213
|
* Infinite query options with defined initial data
|
|
183
214
|
*/
|
|
184
|
-
interface DefinedTuyauInfiniteQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TuyauInfiniteData<TData>, TuyauQueryKey,
|
|
215
|
+
interface DefinedTuyauInfiniteQueryOptionsIn<TQueryFnData, TData, TError, TRequest, TPageParamKey extends keyof TRequest> extends DistributiveOmit<DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TuyauInfiniteData<TData>, TuyauQueryKey, ExtractPageParamType<TRequest, TPageParamKey> | null>, InfiniteQueryReservedOptions>, TuyauQueryBaseOptions {
|
|
216
|
+
pageParamKey: TPageParamKey;
|
|
185
217
|
}
|
|
218
|
+
type ExtractPageParamType<TRequest, TPageParamKey extends keyof TRequest> = TRequest[TPageParamKey];
|
|
186
219
|
/**
|
|
187
220
|
* Infinite query options with unused skip token
|
|
188
221
|
*/
|
|
189
|
-
interface UnusedSkipTokenTuyauInfiniteQueryOptionsIn<TQueryFnData, TData, TError> extends DistributiveOmit<UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TuyauInfiniteData<TData>, TuyauQueryKey,
|
|
222
|
+
interface UnusedSkipTokenTuyauInfiniteQueryOptionsIn<TQueryFnData, TData, TError, TRequest, TPageParamKey extends keyof TRequest> extends DistributiveOmit<UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TuyauInfiniteData<TData>, TuyauQueryKey, ExtractPageParamType<TRequest, TPageParamKey>>, InfiniteQueryReservedOptions>, TuyauQueryBaseOptions {
|
|
223
|
+
pageParamKey: TPageParamKey;
|
|
190
224
|
}
|
|
191
225
|
/**
|
|
192
226
|
* Output type for infinite query options with undefined initial data
|
|
@@ -222,18 +256,18 @@ interface UnusedSkipTokenTuyauInfiniteQueryOptionsOut<TQueryFnData, TData, TErro
|
|
|
222
256
|
* Type definition for infinite query options with overloads for different scenarios
|
|
223
257
|
*/
|
|
224
258
|
interface TuyauReactInfiniteQueryOptions<EDef extends EndpointDef, TParams = Record<string, string | number>> {
|
|
225
|
-
<TData = UnionFromSuccessStatuses<EDef['response']
|
|
226
|
-
payload?: EDef['request']
|
|
259
|
+
<TData = UnionFromSuccessStatuses<EDef['response']>, TPageParamKey extends keyof EDef['request'] = string>(input: {
|
|
260
|
+
payload?: Omit<EDef['request'], TPageParamKey>;
|
|
227
261
|
params?: TParams;
|
|
228
|
-
} | SkipToken, opts: DefinedTuyauInfiniteQueryOptionsIn<UnionFromSuccessStatuses<EDef['response']>, TData, any>): DefinedTuyauInfiniteQueryOptionsOut<UnionFromSuccessStatuses<EDef['response']>, TData, any>;
|
|
229
|
-
<TData = UnionFromSuccessStatuses<EDef['response']
|
|
230
|
-
payload?: EDef['request']
|
|
262
|
+
} | SkipToken, opts: DefinedTuyauInfiniteQueryOptionsIn<UnionFromSuccessStatuses<EDef['response']>, TData, any, EDef['request'], TPageParamKey>): DefinedTuyauInfiniteQueryOptionsOut<UnionFromSuccessStatuses<EDef['response']>, TData, any>;
|
|
263
|
+
<TData = UnionFromSuccessStatuses<EDef['response']>, TPageParamKey extends keyof EDef['request'] = string>(input: {
|
|
264
|
+
payload?: Omit<EDef['request'], TPageParamKey>;
|
|
231
265
|
params?: TParams;
|
|
232
|
-
}, opts: UnusedSkipTokenTuyauInfiniteQueryOptionsIn<UnionFromSuccessStatuses<EDef['response']>, TData, any>): UnusedSkipTokenTuyauInfiniteQueryOptionsOut<UnionFromSuccessStatuses<EDef['response']>, TData, any>;
|
|
233
|
-
<TData = UnionFromSuccessStatuses<EDef['response']
|
|
234
|
-
payload?: EDef['request']
|
|
266
|
+
}, opts: UnusedSkipTokenTuyauInfiniteQueryOptionsIn<UnionFromSuccessStatuses<EDef['response']>, TData, any, EDef['request'], TPageParamKey>): UnusedSkipTokenTuyauInfiniteQueryOptionsOut<UnionFromSuccessStatuses<EDef['response']>, TData, any>;
|
|
267
|
+
<TData = UnionFromSuccessStatuses<EDef['response']>, TPageParamKey extends keyof EDef['request'] = string>(input?: {
|
|
268
|
+
payload?: Omit<EDef['request'], TPageParamKey>;
|
|
235
269
|
params?: TParams;
|
|
236
|
-
} | SkipToken, opts?: UndefinedTuyauInfiniteQueryOptionsIn<UnionFromSuccessStatuses<EDef['response']>, TData, any>): UndefinedTuyauInfiniteQueryOptionsOut<UnionFromSuccessStatuses<EDef['response']>, TData, any>;
|
|
270
|
+
} | SkipToken, opts?: UndefinedTuyauInfiniteQueryOptionsIn<UnionFromSuccessStatuses<EDef['response']>, TData, any, EDef['request'], TPageParamKey>): UndefinedTuyauInfiniteQueryOptionsOut<UnionFromSuccessStatuses<EDef['response']>, TData, any>;
|
|
237
271
|
}
|
|
238
272
|
/**
|
|
239
273
|
* Interface for infinite query function decorators
|
|
@@ -251,12 +285,20 @@ interface DecorateInfiniteQueryFn<EDef extends EndpointDef, TParams = Record<str
|
|
|
251
285
|
}
|
|
252
286
|
|
|
253
287
|
/**
|
|
254
|
-
*
|
|
288
|
+
* Options for configuring the Tuyau React Query client
|
|
255
289
|
*/
|
|
256
|
-
|
|
290
|
+
interface TuyauReactQueryClientOptions<D extends Record<string, any>, R extends GeneratedRoutes> {
|
|
257
291
|
client: TuyauClient<D, R>;
|
|
258
292
|
queryClient: QueryClient | (() => QueryClient);
|
|
259
|
-
|
|
293
|
+
/**
|
|
294
|
+
* Global Tuyau-specific request options
|
|
295
|
+
*/
|
|
296
|
+
globalOptions?: TuyauReactRequestOptions;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Create the Tuyau React Query client
|
|
300
|
+
*/
|
|
301
|
+
declare function createTuyauReactQueryClient<D extends Record<string, any>, R extends GeneratedRoutes>(options: TuyauReactQueryClientOptions<D, R>): TuyauReactQuery<D> & DecorateRouterKeyable;
|
|
260
302
|
/**
|
|
261
303
|
* Main type for the Tuyau React Query client
|
|
262
304
|
* Maps route definitions to appropriate query or mutation decorators
|
|
@@ -288,7 +330,7 @@ type CreateParamFunction<Route extends Record<string, any>, Path extends string,
|
|
|
288
330
|
* Create the parameter property mappings
|
|
289
331
|
*/
|
|
290
332
|
type CreateParamProperties<Route extends Record<string, any>, Path extends string, NotProvidedParams> = {
|
|
291
|
-
[K in keyof Route as K extends `:${string}` ? K : never]: TuyauReactQuery<Route[K], NotProvidedParams & PathParamToObject<Path
|
|
333
|
+
[K in keyof Route as K extends `:${string}` ? K : never]: TuyauReactQuery<Route[K], NotProvidedParams & PathParamToObject<Path>> & DecorateRouterKeyable;
|
|
292
334
|
};
|
|
293
335
|
/**
|
|
294
336
|
* Type for handling route parameters
|
package/build/index.js
CHANGED
|
@@ -69,11 +69,20 @@ function getQueryKeyInternal(path, input, type) {
|
|
|
69
69
|
];
|
|
70
70
|
}
|
|
71
71
|
function tuyauQueryOptions(options) {
|
|
72
|
-
const { input, opts, queryKey, path, client } = options;
|
|
72
|
+
const { input, opts, queryKey, path, client, globalOptions } = options;
|
|
73
73
|
const inputIsSkipToken = input === skipToken;
|
|
74
|
-
const queryFn = inputIsSkipToken ? skipToken : async () => {
|
|
74
|
+
const queryFn = inputIsSkipToken ? skipToken : async (queryFnContext) => {
|
|
75
75
|
const { payload, requestPath } = extractInputAndPath(input, path);
|
|
76
|
-
|
|
76
|
+
const effectiveAbortOnUnmount = opts?.tuyau?.abortOnUnmount ?? globalOptions?.abortOnUnmount ?? false;
|
|
77
|
+
const actualOpts = {
|
|
78
|
+
...opts,
|
|
79
|
+
tuyau: {
|
|
80
|
+
...globalOptions,
|
|
81
|
+
...opts?.tuyau,
|
|
82
|
+
...effectiveAbortOnUnmount ? { signal: queryFnContext.signal } : { signal: null }
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
return await client.$fetch({ paths: requestPath, input: payload, queryOptions: actualOpts });
|
|
77
86
|
};
|
|
78
87
|
return Object.assign(queryOptions({ ...opts, queryKey, queryFn }), {
|
|
79
88
|
tuyau: { path, type: "query" }
|
|
@@ -93,21 +102,40 @@ import {
|
|
|
93
102
|
infiniteQueryOptions,
|
|
94
103
|
skipToken as skipToken2
|
|
95
104
|
} from "@tanstack/react-query";
|
|
96
|
-
function extractInfiniteInputAndPath(input, path) {
|
|
105
|
+
function extractInfiniteInputAndPath(input, path, pageParamKey, pageParam) {
|
|
97
106
|
if (typeof input !== "object" || input === null || !("payload" in input) && !("params" in input)) {
|
|
98
107
|
const payload2 = typeof input === "object" && input !== null ? input : {};
|
|
99
|
-
|
|
108
|
+
const enhancedPayload2 = { ...payload2, [pageParamKey]: pageParam };
|
|
109
|
+
return { payload: enhancedPayload2, requestPath: path };
|
|
100
110
|
}
|
|
101
111
|
const { payload, params } = input;
|
|
102
112
|
const requestPath = buildRequestPath(path, params);
|
|
103
|
-
|
|
113
|
+
const enhancedPayload = { ...payload, [pageParamKey]: pageParam };
|
|
114
|
+
return { payload: enhancedPayload, requestPath };
|
|
104
115
|
}
|
|
105
116
|
function tuyauInfiniteQueryOptions(options) {
|
|
106
|
-
const { input, opts, queryKey, path, client } = options;
|
|
117
|
+
const { input, opts, queryKey, path, client, globalOptions } = options;
|
|
107
118
|
const inputIsSkipToken = input === skipToken2;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
119
|
+
if (!opts?.pageParamKey) {
|
|
120
|
+
throw new Error("pageParamKey is required for infinite queries");
|
|
121
|
+
}
|
|
122
|
+
const queryFn = inputIsSkipToken ? skipToken2 : async (queryFnContext) => {
|
|
123
|
+
const { payload, requestPath } = extractInfiniteInputAndPath(
|
|
124
|
+
input,
|
|
125
|
+
path,
|
|
126
|
+
opts.pageParamKey,
|
|
127
|
+
queryFnContext.pageParam
|
|
128
|
+
);
|
|
129
|
+
const effectiveAbortOnUnmount = opts?.tuyau?.abortOnUnmount ?? globalOptions?.abortOnUnmount ?? false;
|
|
130
|
+
const actualOpts = {
|
|
131
|
+
...opts,
|
|
132
|
+
tuyau: {
|
|
133
|
+
...globalOptions,
|
|
134
|
+
...opts?.tuyau,
|
|
135
|
+
...effectiveAbortOnUnmount ? { signal: queryFnContext.signal } : { signal: null }
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
return await client.$fetch({ paths: requestPath, input: payload, queryOptions: actualOpts });
|
|
111
139
|
};
|
|
112
140
|
return Object.assign(
|
|
113
141
|
infiniteQueryOptions({
|
|
@@ -121,16 +149,13 @@ function tuyauInfiniteQueryOptions(options) {
|
|
|
121
149
|
}
|
|
122
150
|
|
|
123
151
|
// src/mutation.ts
|
|
152
|
+
import {
|
|
153
|
+
mutationOptions
|
|
154
|
+
} from "@tanstack/react-query";
|
|
124
155
|
function getMutationKeyInternal(path) {
|
|
125
156
|
const splitPath = path.flatMap((part) => part.toString().split("."));
|
|
126
157
|
return splitPath.length ? [splitPath] : [];
|
|
127
158
|
}
|
|
128
|
-
function createTuyauOptionsResult(opts) {
|
|
129
|
-
return {
|
|
130
|
-
path: opts.path,
|
|
131
|
-
type: "mutation"
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
159
|
function tuyauMutationOptions(args) {
|
|
135
160
|
const { opts, path, client, overrides } = args;
|
|
136
161
|
const queryClient = unwrapLazyArg(args.queryClient);
|
|
@@ -143,23 +168,20 @@ function tuyauMutationOptions(args) {
|
|
|
143
168
|
const requestPath = buildRequestPath(path, input.params);
|
|
144
169
|
return await client.$fetch({ paths: requestPath, input: input.payload });
|
|
145
170
|
};
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
originalFn,
|
|
157
|
-
queryClient,
|
|
158
|
-
meta: opts?.meta ?? defaultOpts?.meta ?? {}
|
|
159
|
-
});
|
|
160
|
-
},
|
|
161
|
-
tuyau: createTuyauOptionsResult({ path })
|
|
171
|
+
const onSuccess = (data, variables, context) => {
|
|
172
|
+
const originalFn = () => {
|
|
173
|
+
if (opts?.onSuccess) return opts.onSuccess(data, variables, context);
|
|
174
|
+
if (defaultOpts?.onSuccess) return defaultOpts.onSuccess(data, variables, context);
|
|
175
|
+
};
|
|
176
|
+
return mutationSuccessOverride({
|
|
177
|
+
originalFn,
|
|
178
|
+
queryClient,
|
|
179
|
+
meta: opts?.meta ?? defaultOpts?.meta ?? {}
|
|
180
|
+
});
|
|
162
181
|
};
|
|
182
|
+
return Object.assign(mutationOptions({ ...opts, mutationKey, mutationFn, onSuccess }), {
|
|
183
|
+
tuyau: { path, type: "mutation" }
|
|
184
|
+
});
|
|
163
185
|
}
|
|
164
186
|
|
|
165
187
|
// src/main.ts
|
|
@@ -176,7 +198,8 @@ function createTuyauReactQueryClient(options) {
|
|
|
176
198
|
queryKey: getQueryKeyInternal(patternPath, arg1, "query"),
|
|
177
199
|
queryClient: unwrapLazyArg(options.queryClient),
|
|
178
200
|
client: options.client,
|
|
179
|
-
path
|
|
201
|
+
path,
|
|
202
|
+
globalOptions: options.globalOptions
|
|
180
203
|
});
|
|
181
204
|
}
|
|
182
205
|
if (fnName === "infiniteQueryOptions") {
|
|
@@ -186,7 +209,8 @@ function createTuyauReactQueryClient(options) {
|
|
|
186
209
|
queryKey: getQueryKeyInternal(patternPath, arg1, "infinite"),
|
|
187
210
|
queryClient: unwrapLazyArg(options.queryClient),
|
|
188
211
|
client: options.client,
|
|
189
|
-
path
|
|
212
|
+
path,
|
|
213
|
+
globalOptions: options.globalOptions
|
|
190
214
|
});
|
|
191
215
|
}
|
|
192
216
|
if (fnName === "queryKey") return getQueryKeyInternal(patternPath, arg1, "query");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuyau/react-query",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.1-next.
|
|
4
|
+
"version": "0.0.1-next.2",
|
|
5
5
|
"description": "React Query plugin for Tuyau",
|
|
6
6
|
"author": "Julien Ripouteau <julien@ripouteau.com>",
|
|
7
7
|
"license": "ISC",
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
"@tuyau/utils": "0.0.9"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@adonisjs/core": "^6.
|
|
25
|
-
"@happy-dom/global-registrator": "^17.
|
|
26
|
-
"@tanstack/react-query": "^5.
|
|
24
|
+
"@adonisjs/core": "^6.19.0",
|
|
25
|
+
"@happy-dom/global-registrator": "^17.6.3",
|
|
26
|
+
"@tanstack/react-query": "^5.83.0",
|
|
27
27
|
"@testing-library/react": "^16.3.0",
|
|
28
|
-
"@types/react": "^19.1.
|
|
28
|
+
"@types/react": "^19.1.8",
|
|
29
29
|
"@vinejs/vine": "^3.0.1",
|
|
30
|
-
"nock": "^14.0.
|
|
30
|
+
"nock": "^14.0.6",
|
|
31
31
|
"react": "^19.1.0",
|
|
32
|
-
"@tuyau/client": "0.2.11-next.
|
|
32
|
+
"@tuyau/client": "0.2.11-next.2"
|
|
33
33
|
},
|
|
34
34
|
"tsup": {
|
|
35
35
|
"entry": [
|