@tuyau/react-query 1.0.0-beta.4 → 1.1.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/build/index.d.ts CHANGED
@@ -1,62 +1,71 @@
1
- import { SchemaEndpoint, RawRequestArgs, BaseRequestOptions, TuyauRegistry, InferTree, AdonisEndpoint, InferRoutes } from '@tuyau/core/types';
1
+ import { SchemaEndpoint, ResponseOf, RawRequestArgs, ErrorOf, TuyauRegistry, InferTree, AdonisEndpoint, InferRoutes } from '@tuyau/core/types';
2
2
  import * as _tanstack_react_query from '@tanstack/react-query';
3
- import { SkipToken, DataTag, QueryFilters, WithRequired as WithRequired$1, UseMutationOptions, InfiniteData, UnusedSkipTokenInfiniteOptions, DefinedInitialDataInfiniteOptions, UndefinedInitialDataInfiniteOptions, DefinedInitialDataOptions, UndefinedInitialDataOptions, UnusedSkipTokenOptions } from '@tanstack/react-query';
3
+ import { SkipToken, DataTag, QueryFilters, UseMutationOptions, InfiniteData, UnusedSkipTokenInfiniteOptions, DefinedInitialDataInfiniteOptions, UndefinedInitialDataInfiniteOptions, DefinedInitialDataOptions, UndefinedInitialDataOptions, UnusedSkipTokenOptions } from '@tanstack/react-query';
4
+ import { TuyauQueryKey, WithRequired, DistributiveOmit, TuyauQueryBaseOptions, TuyauMutationKey, TuyauRequestOptions, DecorateRouterKeyable, CreateQueryFnOptions } from '@tuyau/query-core';
5
+ export { DecorateRouterKeyable, DistributiveOmit, QueryType, TuyauMutationKey, TuyauQueryBaseOptions, TuyauQueryKey, WithRequired } from '@tuyau/query-core';
4
6
  import { Tuyau } from '@tuyau/core/client';
5
7
 
6
- type Response$2<E extends SchemaEndpoint> = E['types']['response'];
7
8
  /**
8
9
  * Decorate query endpoints with Tanstack queries abilities
9
10
  */
10
11
  interface DecorateQueryFn<EDef extends SchemaEndpoint> {
11
12
  queryOptions: TuyauReactQueryOptions<EDef>;
12
- queryKey: (args?: RawRequestArgs<EDef>) => DataTag<TuyauQueryKey, Response$2<EDef>>;
13
- queryFilter: (args?: RawRequestArgs<EDef>, filters?: QueryFilters<DataTag<TuyauQueryKey, Response$2<EDef>>>) => WithRequired$1<QueryFilters<DataTag<TuyauQueryKey, Response$2<EDef>>>, 'queryKey'>;
13
+ queryKey: (args?: RawRequestArgs<EDef>) => DataTag<TuyauQueryKey, ResponseOf<EDef>>;
14
+ queryFilter: (args?: RawRequestArgs<EDef>, filters?: QueryFilters<DataTag<TuyauQueryKey, ResponseOf<EDef>>>) => WithRequired<QueryFilters<DataTag<TuyauQueryKey, ResponseOf<EDef>>>, 'queryKey'>;
14
15
  }
15
16
  /**
16
17
  * Type definition for query options with overloads for different scenarios
17
18
  */
18
19
  interface TuyauReactQueryOptions<EDef extends SchemaEndpoint> {
19
- <TData = Response$2<EDef>>(input: RawRequestArgs<EDef> | SkipToken, opts: DefinedTuyauQueryOptionsIn<Response$2<EDef>, TData, unknown>): DefinedTuyauQueryOptionsOut<Response$2<EDef>, TData, unknown>;
20
- <TData = Response$2<EDef>>(input: RawRequestArgs<EDef>, opts?: UnusedSkipTokenTuyauQueryOptionsIn<Response$2<EDef>, TData, unknown>): UnusedSkipTokenTuyauQueryOptionsOut<Response$2<EDef>, TData, unknown>;
21
- (): UnusedSkipTokenTuyauQueryOptionsOut<Response$2<EDef>, Response$2<EDef>, unknown>;
22
- (input: SkipToken): UndefinedTuyauQueryOptionsOut<Response$2<EDef>, Response$2<EDef>, unknown>;
23
- <TData = Response$2<EDef>>(input: RawRequestArgs<EDef> | SkipToken, opts?: UndefinedTuyauQueryOptionsIn<Response$2<EDef>, TData, unknown>): UndefinedTuyauQueryOptionsOut<Response$2<EDef>, TData, unknown>;
20
+ <TData = ResponseOf<EDef>>(input: RawRequestArgs<EDef> | SkipToken, opts: DefinedTuyauQueryOptionsIn<ResponseOf<EDef>, TData, ErrorOf<EDef>>): DefinedTuyauQueryOptionsOut<ResponseOf<EDef>, TData, ErrorOf<EDef>>;
21
+ <TData = ResponseOf<EDef>>(input: RawRequestArgs<EDef>, opts?: UnusedSkipTokenTuyauQueryOptionsIn<ResponseOf<EDef>, TData, ErrorOf<EDef>>): UnusedSkipTokenTuyauQueryOptionsOut<ResponseOf<EDef>, TData, ErrorOf<EDef>>;
22
+ (): UnusedSkipTokenTuyauQueryOptionsOut<ResponseOf<EDef>, ResponseOf<EDef>, ErrorOf<EDef>>;
23
+ (input: SkipToken): UndefinedTuyauQueryOptionsOut<ResponseOf<EDef>, ResponseOf<EDef>, ErrorOf<EDef>>;
24
+ <TData = ResponseOf<EDef>>(input: RawRequestArgs<EDef> | SkipToken, opts?: UndefinedTuyauQueryOptionsIn<ResponseOf<EDef>, TData, ErrorOf<EDef>>): UndefinedTuyauQueryOptionsOut<ResponseOf<EDef>, TData, ErrorOf<EDef>>;
24
25
  }
25
26
 
27
+ type ReservedOptions = 'mutationKey' | 'mutationFn';
26
28
  /**
27
- * Omits the key without removing a potential union
28
- */
29
- type DistributiveOmit<TObj, TKey extends keyof any> = TObj extends any ? Omit<TObj, TKey> : never;
30
- /**
31
- * Make certain keys required in a type
29
+ * User-facing mutation options input. Extends TanStack's mutation observer
30
+ * options but omits `mutationKey` and `mutationFn` which are auto-generated
32
31
  */
33
- type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;
34
-
35
- type ReservedOptions = 'mutationKey' | 'mutationFn';
36
- type Response$1<E extends SchemaEndpoint> = E['types']['response'];
37
32
  interface TuyauMutationOptionsIn<TInput, TError, TOutput, TContext> extends DistributiveOmit<UseMutationOptions<TOutput, TError, TInput, TContext>, ReservedOptions>, TuyauQueryBaseOptions {
38
33
  }
34
+ /**
35
+ * Fully resolved mutation options ready to be passed to `useMutation`.
36
+ * Includes the auto-generated `mutationKey` and `mutationFn`
37
+ */
39
38
  interface TuyauMutationOptionsOut<TInput, TError, TOutput, TContext> extends UseMutationOptions<TOutput, TError, TInput, TContext> {
40
39
  mutationKey: TuyauMutationKey;
41
40
  }
41
+ /**
42
+ * Callable interface exposed on mutation endpoints.
43
+ * Returns fully resolved mutation options from user-provided options
44
+ */
42
45
  interface TuyauReactMutationOptions<TDef extends SchemaEndpoint> {
43
- <TContext = unknown>(opts?: TuyauMutationOptionsIn<RawRequestArgs<TDef>, any, Response$1<TDef>, TContext>): TuyauMutationOptionsOut<RawRequestArgs<TDef>, any, Response$1<TDef>, TContext>;
46
+ <TContext = unknown>(opts?: TuyauMutationOptionsIn<RawRequestArgs<TDef>, ErrorOf<TDef>, ResponseOf<TDef>, TContext>): TuyauMutationOptionsOut<RawRequestArgs<TDef>, ErrorOf<TDef>, ResponseOf<TDef>, TContext>;
44
47
  }
45
- declare function getMutationKeyInternal(options: {
46
- segments: string[];
47
- }): TuyauMutationKey;
48
+ /**
49
+ * Decorates mutation endpoints with `mutationOptions` and `mutationKey` methods
50
+ */
48
51
  interface DecorateMutationFn<EDef extends SchemaEndpoint> {
49
52
  mutationOptions: TuyauReactMutationOptions<EDef>;
50
53
  mutationKey: () => TuyauMutationKey;
51
54
  }
55
+ /**
56
+ * Internal options for building a mutation options object
57
+ */
52
58
  interface TuyauMutationOptionsOptions {
53
59
  opts?: TuyauMutationOptionsIn<any, any, any, any>;
54
60
  routeName: string;
55
61
  client: Tuyau<any>;
56
62
  }
57
- declare function tuyauMutationOptions(options: TuyauMutationOptionsOptions): _tanstack_react_query.WithRequired<UseMutationOptions<unknown, any, any, any>, "mutationKey">;
63
+ /**
64
+ * Builds a TanStack React Query `mutationOptions` object from Tuyau route information.
65
+ * Delegates mutationFn creation to the shared `createMutationFn` from `@tuyau/query-core`
66
+ */
67
+ declare function tuyauMutationOptions(options: TuyauMutationOptionsOptions): _tanstack_react_query.WithRequired<UseMutationOptions<any, any, any, any>, "mutationKey">;
58
68
 
59
- type Response<E extends SchemaEndpoint> = E['types']['response'];
60
69
  type ReservedInfiniteQueryOptions = 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash';
61
70
  /**
62
71
  * Base infinite query options with Tuyau-specific options
@@ -111,47 +120,29 @@ interface TuyauReactInfiniteQueryOptions<EDef extends SchemaEndpoint> {
111
120
  /**
112
121
  * Overload 1: When input is NOT SkipToken, return options compatible with useSuspenseInfiniteQuery
113
122
  */
114
- <TData = InfiniteData<Response<EDef>>>(input: RawRequestArgs<EDef>, opts: UnusedSkipTokenTuyauInfiniteQueryOptionsIn<Response<EDef>, unknown, TData>): UnusedSkipTokenTuyauInfiniteQueryOptionsOut<Response<EDef>, unknown, TData>;
123
+ <TData = InfiniteData<ResponseOf<EDef>>>(input: RawRequestArgs<EDef>, opts: UnusedSkipTokenTuyauInfiniteQueryOptionsIn<ResponseOf<EDef>, ErrorOf<EDef>, TData>): UnusedSkipTokenTuyauInfiniteQueryOptionsOut<ResponseOf<EDef>, ErrorOf<EDef>, TData>;
115
124
  /**
116
125
  * Overload 2: When initialData is defined
117
126
  */
118
- <TData = InfiniteData<Response<EDef>>>(input: RawRequestArgs<EDef> | SkipToken, opts: DefinedTuyauInfiniteQueryOptionsIn<Response<EDef>, unknown, TData>): DefinedTuyauInfiniteQueryOptionsOut<Response<EDef>, unknown, TData>;
127
+ <TData = InfiniteData<ResponseOf<EDef>>>(input: RawRequestArgs<EDef> | SkipToken, opts: DefinedTuyauInfiniteQueryOptionsIn<ResponseOf<EDef>, ErrorOf<EDef>, TData>): DefinedTuyauInfiniteQueryOptionsOut<ResponseOf<EDef>, ErrorOf<EDef>, TData>;
119
128
  /**
120
129
  * Overload 3: No arguments - no skipToken possible
121
130
  */
122
- (): UnusedSkipTokenTuyauInfiniteQueryOptionsOut<Response<EDef>, unknown, InfiniteData<Response<EDef>>>;
131
+ (): UnusedSkipTokenTuyauInfiniteQueryOptionsOut<ResponseOf<EDef>, ErrorOf<EDef>, InfiniteData<ResponseOf<EDef>>>;
123
132
  /**
124
133
  * Overload 4: With skipToken or conditional (request | skipToken) and options
125
134
  */
126
- <TData = InfiniteData<Response<EDef>>>(input: RawRequestArgs<EDef> | SkipToken, opts: UndefinedTuyauInfiniteQueryOptionsIn<Response<EDef>, unknown, TData>): UndefinedTuyauInfiniteQueryOptionsOut<Response<EDef>, unknown, TData>;
135
+ <TData = InfiniteData<ResponseOf<EDef>>>(input: RawRequestArgs<EDef> | SkipToken, opts: UndefinedTuyauInfiniteQueryOptionsIn<ResponseOf<EDef>, ErrorOf<EDef>, TData>): UndefinedTuyauInfiniteQueryOptionsOut<ResponseOf<EDef>, ErrorOf<EDef>, TData>;
127
136
  }
128
137
  /**
129
138
  * Decorate query endpoints with infinite query capabilities
130
139
  */
131
140
  interface DecorateInfiniteQueryFn<EDef extends SchemaEndpoint> {
132
141
  infiniteQueryOptions: TuyauReactInfiniteQueryOptions<EDef>;
133
- infiniteQueryKey: (args?: RawRequestArgs<EDef>) => DataTag<TuyauQueryKey, InfiniteData<Response<EDef>>>;
134
- infiniteQueryFilter: (args?: RawRequestArgs<EDef>, filters?: QueryFilters<DataTag<TuyauQueryKey, InfiniteData<Response<EDef>>>>) => WithRequired$1<QueryFilters<DataTag<TuyauQueryKey, InfiniteData<Response<EDef>>>>, 'queryKey'>;
142
+ infiniteQueryKey: (args?: RawRequestArgs<EDef>) => DataTag<TuyauQueryKey, InfiniteData<ResponseOf<EDef>>>;
143
+ infiniteQueryFilter: (args?: RawRequestArgs<EDef>, filters?: QueryFilters<DataTag<TuyauQueryKey, InfiniteData<ResponseOf<EDef>>>>) => WithRequired<QueryFilters<DataTag<TuyauQueryKey, InfiniteData<ResponseOf<EDef>>>>, 'queryKey'>;
135
144
  }
136
145
 
137
- /**
138
- * Query type identifier
139
- */
140
- type QueryType = 'any' | 'infinite' | 'query';
141
- /**
142
- * Tuyau-specific query key structure
143
- */
144
- type TuyauQueryKey = [
145
- readonly string[],
146
- {
147
- request?: RawRequestArgs<any>;
148
- type?: Exclude<QueryType, 'any'>;
149
- }?
150
- ];
151
- /**
152
- * Tuyau-specific mutation key structure
153
- */
154
- type TuyauMutationKey = [readonly string[]];
155
146
  /**
156
147
  * Query options with defined initial data
157
148
  */
@@ -186,30 +177,9 @@ interface UnusedSkipTokenTuyauQueryOptionsOut<TQueryFnData, TData, TError> exten
186
177
  queryKey: DataTag<TuyauQueryKey, TData, TError>;
187
178
  }
188
179
  /**
189
- * Tuyau-specific request options for React Query integration
190
- */
191
- interface TuyauReactRequestOptions extends BaseRequestOptions {
192
- /**
193
- * Opt out or into aborting request on unmount
194
- */
195
- abortOnUnmount?: boolean;
196
- }
197
- /**
198
- * Base options for Tuyau queries and mutations
199
- */
200
- interface TuyauQueryBaseOptions {
201
- /**
202
- * Tuyau-specific options including Ky request options (timeout, retry, headers, etc.)
203
- */
204
- tuyau?: TuyauReactRequestOptions;
205
- }
206
- interface DecorateRouterKeyable {
207
- pathKey: () => TuyauQueryKey;
208
- pathFilter: (filters?: QueryFilters<TuyauQueryKey>) => WithRequired<QueryFilters<TuyauQueryKey>, 'queryKey'>;
209
- }
210
- /**
211
- * Keys that identify an endpoint-like structure
180
+ * Alias for backward compatibility with existing consumers
212
181
  */
182
+ type TuyauReactRequestOptions = TuyauRequestOptions;
213
183
  type EndpointKeys = 'methods' | 'pattern' | 'types';
214
184
  /**
215
185
  * Determines if endpoint is a query (GET/HEAD) or mutation
@@ -230,19 +200,27 @@ type TransformToReactQuery<T> = {
230
200
  } & DecorateRouterKeyable;
231
201
  type TuyauReactQuery<R extends Record<string, SchemaEndpoint>> = TransformToReactQuery<R>;
232
202
 
203
+ /**
204
+ * Creates a type-safe TanStack React Query client from a Tuyau client instance.
205
+ * Returns a Proxy-based object that mirrors the API route tree and exposes
206
+ * `queryOptions`, `mutationOptions`, `infiniteQueryOptions`, and key/filter
207
+ * helpers on each endpoint node
208
+ */
233
209
  declare function createTuyauReactQueryClient<Reg extends TuyauRegistry, Tree = InferTree<Reg>, Routes extends Record<string, AdonisEndpoint> = InferRoutes<Reg>>(options: {
234
210
  client: Tuyau<Reg, Routes>;
235
211
  globalOptions?: TuyauReactRequestOptions;
236
212
  }): TransformToReactQuery<Tree>;
237
213
 
238
- interface TuyauQueryOptionsOptions {
239
- request: RawRequestArgs<any> | SkipToken;
240
- opts?: TuyauQueryBaseOptions;
214
+ /**
215
+ * Internal options for building a TanStack Query options object
216
+ */
217
+ type TuyauQueryOptionsOptions = CreateQueryFnOptions & {
241
218
  queryKey: TuyauQueryKey;
242
- routeName: string;
243
- client: Tuyau<any>;
244
- globalOptions?: TuyauReactRequestOptions;
245
- }
219
+ };
220
+ /**
221
+ * Builds a TanStack React Query `queryOptions` object from Tuyau route information.
222
+ * Delegates queryFn creation to the shared `createQueryFn` from `@tuyau/query-core`
223
+ */
246
224
  declare function tuyauQueryOptions(options: TuyauQueryOptionsOptions): _tanstack_react_query.UseQueryOptions<any, Error, any, readonly unknown[]> & {
247
225
  initialData?: any;
248
226
  } & {
@@ -252,4 +230,4 @@ declare function tuyauQueryOptions(options: TuyauQueryOptionsOptions): _tanstack
252
230
  };
253
231
  };
254
232
 
255
- export { type DecorateMutationFn, type DecorateRouterKeyable, type DefinedTuyauQueryOptionsIn, type DefinedTuyauQueryOptionsOut, type EndpointNode, type QueryType, type TransformToReactQuery, type TuyauMutationKey, type TuyauMutationOptionsIn, type TuyauMutationOptionsOptions, type TuyauMutationOptionsOut, type TuyauQueryBaseOptions, type TuyauQueryKey, type TuyauQueryOptionsOptions, type TuyauReactMutationOptions, type TuyauReactQuery, type TuyauReactRequestOptions, type UndefinedTuyauQueryOptionsIn, type UndefinedTuyauQueryOptionsOut, type UnusedSkipTokenTuyauQueryOptionsIn, type UnusedSkipTokenTuyauQueryOptionsOut, createTuyauReactQueryClient, getMutationKeyInternal, tuyauMutationOptions, tuyauQueryOptions };
233
+ export { type DecorateMutationFn, type DefinedTuyauQueryOptionsIn, type DefinedTuyauQueryOptionsOut, type EndpointNode, type TransformToReactQuery, type TuyauMutationOptionsIn, type TuyauMutationOptionsOptions, type TuyauMutationOptionsOut, type TuyauQueryOptionsOptions, type TuyauReactMutationOptions, type TuyauReactQuery, type TuyauReactRequestOptions, type UndefinedTuyauQueryOptionsIn, type UndefinedTuyauQueryOptionsOut, type UnusedSkipTokenTuyauQueryOptionsIn, type UnusedSkipTokenTuyauQueryOptionsOut, createTuyauReactQueryClient, tuyauMutationOptions, tuyauQueryOptions };
package/build/index.js CHANGED
@@ -1,101 +1,21 @@
1
- // src/utils.ts
2
- import { skipToken } from "@tanstack/react-query";
3
- function isObject(value) {
4
- return typeof value === "object" && value !== null && !Array.isArray(value);
5
- }
6
- function invoke(fn) {
7
- return fn?.();
8
- }
9
- function buildKey(opts) {
10
- const { segments, request, type } = opts;
11
- const splitPath = segments.flatMap((part) => part.split("."));
12
- if (!request && type === "any") {
13
- return splitPath.length ? [splitPath] : [];
14
- }
15
- if (type === "infinite" && isObject(request)) {
16
- const query = request.query;
17
- const body = request.body;
18
- const hasCursorInQuery = isObject(query) && ("direction" in query || "cursor" in query);
19
- const hasCursorInBody = isObject(body) && ("direction" in body || "cursor" in body);
20
- if (hasCursorInQuery || hasCursorInBody) {
21
- const cleanedRequest = { ...request };
22
- if (hasCursorInQuery && isObject(query)) {
23
- const { cursor: _, direction: __, ...cleanQuery } = query;
24
- cleanedRequest.query = cleanQuery;
25
- }
26
- if (hasCursorInBody && isObject(body)) {
27
- const { cursor: _, direction: __, ...cleanBody } = body;
28
- cleanedRequest.body = cleanBody;
29
- }
30
- return [splitPath, { request: cleanedRequest, type: "infinite" }];
31
- }
32
- }
33
- return [
34
- splitPath,
35
- {
36
- ...typeof request !== "undefined" && request !== skipToken && { request },
37
- ...type && type !== "any" && { type }
38
- }
39
- ];
40
- }
41
- function extractKyOptions(tuyauOpts) {
42
- if (!tuyauOpts) return {};
43
- const { abortOnUnmount, ...kyOptions } = tuyauOpts;
44
- return kyOptions;
45
- }
1
+ // src/main.ts
2
+ import { buildKey, segmentsToRouteName, getMutationKeyInternal as getMutationKeyInternal2 } from "@tuyau/query-core";
46
3
 
47
4
  // src/query.ts
48
- import { queryOptions, skipToken as skipToken2 } from "@tanstack/react-query";
5
+ import { queryOptions } from "@tanstack/react-query";
6
+ import { createQueryFn } from "@tuyau/query-core";
49
7
  function tuyauQueryOptions(options) {
50
- const { request, routeName, opts, queryKey, client, globalOptions } = options;
51
- const queryFn = invoke(() => {
52
- if (request === skipToken2) return skipToken2;
53
- return async (queryFnContext) => {
54
- const effectiveAbortOnUnmount = opts?.tuyau?.abortOnUnmount ?? globalOptions?.abortOnUnmount ?? false;
55
- const kyOptions = extractKyOptions(opts?.tuyau);
56
- return await client.request(routeName, {
57
- ...request,
58
- ...kyOptions,
59
- retry: 0,
60
- ...effectiveAbortOnUnmount ? { signal: queryFnContext.signal } : {}
61
- });
62
- };
63
- });
64
- return queryOptions({ ...opts, queryKey, queryFn });
8
+ const { queryKey, ...fnOptions } = options;
9
+ const queryFn = createQueryFn(fnOptions);
10
+ return queryOptions({ ...options.opts, queryKey, queryFn });
65
11
  }
66
12
 
67
13
  // src/infinite_query.ts
68
- import { infiniteQueryOptions, skipToken as skipToken3 } from "@tanstack/react-query";
14
+ import { infiniteQueryOptions } from "@tanstack/react-query";
15
+ import { createInfiniteQueryFn } from "@tuyau/query-core";
69
16
  function tuyauInfiniteQueryOptions(options) {
70
17
  const { request, routeName, opts, queryKey, client, globalOptions } = options;
71
- const queryFn = invoke(() => {
72
- if (request === skipToken3) return skipToken3;
73
- return async (queryFnContext) => {
74
- const { pageParam } = queryFnContext;
75
- const effectiveAbortOnUnmount = opts?.tuyau?.abortOnUnmount ?? globalOptions?.abortOnUnmount ?? false;
76
- const kyOptions = extractKyOptions(opts?.tuyau);
77
- const pageParamKey = opts?.pageParamKey || "page";
78
- let requestArgs;
79
- if (typeof request === "object" && request !== null) {
80
- if (pageParam !== void 0) {
81
- requestArgs = {
82
- ...request,
83
- query: { ...request.query, [pageParamKey]: pageParam }
84
- };
85
- } else {
86
- requestArgs = request;
87
- }
88
- } else {
89
- requestArgs = { query: pageParam !== void 0 ? { [pageParamKey]: pageParam } : {} };
90
- }
91
- return await client.request(routeName, {
92
- ...requestArgs,
93
- ...kyOptions,
94
- retry: 0,
95
- ...effectiveAbortOnUnmount ? { signal: queryFnContext.signal } : {}
96
- });
97
- };
98
- });
18
+ const queryFn = createInfiniteQueryFn({ request, routeName, opts, client, globalOptions });
99
19
  return infiniteQueryOptions({
100
20
  ...opts,
101
21
  queryKey,
@@ -108,28 +28,15 @@ function tuyauInfiniteQueryOptions(options) {
108
28
 
109
29
  // src/mutation.ts
110
30
  import { mutationOptions } from "@tanstack/react-query";
111
- function getMutationKeyInternal(options) {
112
- const key = [options.segments.flatMap((part) => part.split("."))];
113
- return key;
114
- }
31
+ import { getMutationKeyInternal, createMutationFn } from "@tuyau/query-core";
115
32
  function tuyauMutationOptions(options) {
116
33
  const { opts, routeName, client } = options;
117
34
  const mutationKey = getMutationKeyInternal({ segments: routeName.split(".") });
118
- const kyOptions = extractKyOptions(opts?.tuyau);
119
- const mutationFn = async (request) => {
120
- const requestArgs = request || {};
121
- return await client.request(routeName, { ...requestArgs, ...kyOptions, retry: 0 });
122
- };
35
+ const mutationFn = createMutationFn({ opts, routeName, client });
123
36
  return mutationOptions({ ...opts, mutationKey, mutationFn });
124
37
  }
125
38
 
126
39
  // src/main.ts
127
- function toSnakeCase(str) {
128
- return str.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
129
- }
130
- function segmentsToRouteName(segments) {
131
- return segments.map(toSnakeCase).join(".");
132
- }
133
40
  function createTuyauReactQueryClient(options) {
134
41
  const { client, globalOptions } = options;
135
42
  function makeReactQueryNamed(segments) {
@@ -175,7 +82,7 @@ function createTuyauReactQueryClient(options) {
175
82
  * Mutations
176
83
  */
177
84
  mutationOptions: (opts) => tuyauMutationOptions({ opts, client, routeName }),
178
- mutationKey: () => getMutationKeyInternal({ segments }),
85
+ mutationKey: () => getMutationKeyInternal2({ segments }),
179
86
  /**
180
87
  * Paths
181
88
  */
@@ -187,6 +94,7 @@ function createTuyauReactQueryClient(options) {
187
94
  };
188
95
  return new Proxy(decoratedEndpoint, {
189
96
  get: (target, prop) => {
97
+ if (typeof prop === "symbol") return void 0;
190
98
  if (prop in target) return target[prop];
191
99
  return makeReactQueryNamed([...segments, String(prop)]);
192
100
  }
@@ -196,7 +104,6 @@ function createTuyauReactQueryClient(options) {
196
104
  }
197
105
  export {
198
106
  createTuyauReactQueryClient,
199
- getMutationKeyInternal,
200
107
  tuyauMutationOptions,
201
108
  tuyauQueryOptions
202
109
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tuyau/react-query",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.4",
4
+ "version": "1.1.0",
5
5
  "description": "Tanstack Query integration for Tuyau",
6
6
  "author": "Julien Ripouteau <julien@ripouteau.com>",
7
7
  "license": "MIT",
@@ -32,20 +32,24 @@
32
32
  "engines": {
33
33
  "node": ">=24.0.0"
34
34
  },
35
+ "dependencies": {
36
+ "@tuyau/query-core": "1.1.0"
37
+ },
35
38
  "peerDependencies": {
36
39
  "@tanstack/react-query": "^5.74.7",
37
40
  "@tuyau/core": "^1.0.0-beta.9"
38
41
  },
39
42
  "devDependencies": {
40
- "@adonisjs/core": "^7.0.0-next.16",
41
- "@faker-js/faker": "^10.1.0",
42
- "@happy-dom/global-registrator": "^20.0.11",
43
- "@tanstack/react-query": "^5.90.14",
44
- "@testing-library/react": "^16.3.1",
45
- "@types/react": "^19.2.7",
46
- "@vinejs/vine": "^4.2.0",
47
- "react": "^19.2.3",
48
- "@tuyau/core": "1.0.0-beta.10"
43
+ "@adonisjs/core": "^7.0.1",
44
+ "@faker-js/faker": "^10.3.0",
45
+ "@happy-dom/global-registrator": "^20.8.3",
46
+ "@tanstack/react-query": "^5.90.21",
47
+ "@testing-library/react": "^16.3.2",
48
+ "@types/react": "^19.2.14",
49
+ "@vinejs/vine": "^4.3.0",
50
+ "nock": "^14.0.11",
51
+ "react": "^19.2.4",
52
+ "@tuyau/core": "1.2.1"
49
53
  },
50
54
  "tsup": {
51
55
  "entry": [
@@ -59,10 +63,10 @@
59
63
  },
60
64
  "publishConfig": {
61
65
  "access": "public",
62
- "tag": "beta"
66
+ "tag": "latest"
63
67
  },
64
68
  "scripts": {
65
- "lint": "eslint .",
69
+ "lint": "oxlint .",
66
70
  "typecheck": "tsc --noEmit",
67
71
  "build": "tsup-node",
68
72
  "test": "pnpm quick:test",