@tuyau/react-query 1.0.0-beta.2 → 1.0.0-beta.3
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/README.md +11 -0
- package/build/index.d.ts +59 -11
- package/build/index.js +11 -1
- package/package.json +27 -11
package/README.md
ADDED
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SchemaEndpoint, RawRequestArgs, TuyauRegistry, InferTree, AdonisEndpoint, InferRoutes } from '@tuyau/core/types';
|
|
1
|
+
import { SchemaEndpoint, RawRequestArgs, BaseRequestOptions, 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,
|
|
3
|
+
import { SkipToken, DataTag, QueryFilters, WithRequired as WithRequired$1, UseMutationOptions, InfiniteData, UnusedSkipTokenInfiniteOptions, DefinedInitialDataInfiniteOptions, UndefinedInitialDataInfiniteOptions, DefinedInitialDataOptions, UndefinedInitialDataOptions, UnusedSkipTokenOptions } from '@tanstack/react-query';
|
|
4
4
|
import { Tuyau } from '@tuyau/core/client';
|
|
5
5
|
|
|
6
6
|
type Response$2<E extends SchemaEndpoint> = E['types']['response'];
|
|
@@ -55,10 +55,11 @@ interface TuyauMutationOptionsOptions {
|
|
|
55
55
|
declare function tuyauMutationOptions(options: TuyauMutationOptionsOptions): _tanstack_react_query.WithRequired<UseMutationOptions<unknown, any, any, any>, "mutationKey">;
|
|
56
56
|
|
|
57
57
|
type Response<E extends SchemaEndpoint> = E['types']['response'];
|
|
58
|
+
type ReservedInfiniteQueryOptions = 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash';
|
|
58
59
|
/**
|
|
59
|
-
*
|
|
60
|
+
* Base infinite query options with Tuyau-specific options
|
|
60
61
|
*/
|
|
61
|
-
interface
|
|
62
|
+
interface TuyauInfiniteQueryBaseOptionsIn {
|
|
62
63
|
/**
|
|
63
64
|
* The key that will be used for the page parameter in the request.
|
|
64
65
|
* For example, if your API expects ?page=1, set this to 'page'.
|
|
@@ -67,17 +68,61 @@ interface TuyauInfiniteQueryOptionsIn<TQueryFnData, TError, TData> extends Distr
|
|
|
67
68
|
pageParamKey?: string;
|
|
68
69
|
}
|
|
69
70
|
/**
|
|
70
|
-
* Infinite query options
|
|
71
|
+
* Infinite query options when initialData is undefined (default case)
|
|
71
72
|
*/
|
|
72
|
-
interface
|
|
73
|
+
interface UndefinedTuyauInfiniteQueryOptionsIn<TQueryFnData, TError, TData> extends DistributiveOmit<UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TuyauQueryKey, unknown>, ReservedInfiniteQueryOptions>, TuyauQueryBaseOptions, TuyauInfiniteQueryBaseOptionsIn {
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Output type when initialData is undefined - queryFn can be SkipToken
|
|
77
|
+
*/
|
|
78
|
+
interface UndefinedTuyauInfiniteQueryOptionsOut<TQueryFnData, TError, TData> extends DistributiveOmit<UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TuyauQueryKey, unknown>, 'queryKey'> {
|
|
73
79
|
queryKey: DataTag<TuyauQueryKey, TData>;
|
|
74
80
|
}
|
|
75
81
|
/**
|
|
76
|
-
*
|
|
82
|
+
* Infinite query options when initialData is defined
|
|
83
|
+
*/
|
|
84
|
+
interface DefinedTuyauInfiniteQueryOptionsIn<TQueryFnData, TError, TData> extends DistributiveOmit<DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TuyauQueryKey, unknown>, ReservedInfiniteQueryOptions>, TuyauQueryBaseOptions, TuyauInfiniteQueryBaseOptionsIn {
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Output type when initialData is defined - queryFn can be SkipToken
|
|
88
|
+
*/
|
|
89
|
+
interface DefinedTuyauInfiniteQueryOptionsOut<TQueryFnData, TError, TData> extends DistributiveOmit<DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TuyauQueryKey, unknown>, 'queryKey'> {
|
|
90
|
+
queryKey: DataTag<TuyauQueryKey, TData>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Infinite query options when SkipToken is NOT used as input.
|
|
94
|
+
* This makes the result compatible with useSuspenseInfiniteQuery.
|
|
95
|
+
*/
|
|
96
|
+
interface UnusedSkipTokenTuyauInfiniteQueryOptionsIn<TQueryFnData, TError, TData> extends DistributiveOmit<UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TuyauQueryKey, unknown>, ReservedInfiniteQueryOptions>, TuyauQueryBaseOptions, TuyauInfiniteQueryBaseOptionsIn {
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Output type when SkipToken is NOT used - queryFn excludes SkipToken.
|
|
100
|
+
* This makes it compatible with useSuspenseInfiniteQuery.
|
|
101
|
+
*/
|
|
102
|
+
interface UnusedSkipTokenTuyauInfiniteQueryOptionsOut<TQueryFnData, TError, TData> extends DistributiveOmit<UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TuyauQueryKey, unknown>, 'queryKey'> {
|
|
103
|
+
queryKey: DataTag<TuyauQueryKey, TData>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Type definition for infinite query options with proper overloads.
|
|
107
|
+
*
|
|
108
|
+
* Three overloads handle different cases:
|
|
109
|
+
* 1. Input without SkipToken => Returns type compatible with useSuspenseInfiniteQuery
|
|
110
|
+
* 2. Input with SkipToken + defined initialData => Returns type with SkipToken possible
|
|
111
|
+
* 3. Input with SkipToken (default) => Returns type with SkipToken possible
|
|
77
112
|
*/
|
|
78
113
|
interface TuyauReactInfiniteQueryOptions<EDef extends SchemaEndpoint> {
|
|
79
|
-
|
|
80
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Overload 1: When input is NOT SkipToken, return options compatible with useSuspenseInfiniteQuery
|
|
116
|
+
*/
|
|
117
|
+
<TData = InfiniteData<Response<EDef>>>(input: RawRequestArgs<EDef>, opts: UnusedSkipTokenTuyauInfiniteQueryOptionsIn<Response<EDef>, unknown, TData>): UnusedSkipTokenTuyauInfiniteQueryOptionsOut<Response<EDef>, unknown, TData>;
|
|
118
|
+
/**
|
|
119
|
+
* Overload 2: When initialData is defined
|
|
120
|
+
*/
|
|
121
|
+
<TData = InfiniteData<Response<EDef>>>(input: RawRequestArgs<EDef> | SkipToken, opts: DefinedTuyauInfiniteQueryOptionsIn<Response<EDef>, unknown, TData>): DefinedTuyauInfiniteQueryOptionsOut<Response<EDef>, unknown, TData>;
|
|
122
|
+
/**
|
|
123
|
+
* Overload 3: Default case - input may be SkipToken, initialData undefined
|
|
124
|
+
*/
|
|
125
|
+
<TData = InfiniteData<Response<EDef>>>(input?: RawRequestArgs<EDef> | SkipToken, opts?: UndefinedTuyauInfiniteQueryOptionsIn<Response<EDef>, unknown, TData>): UndefinedTuyauInfiniteQueryOptionsOut<Response<EDef>, unknown, TData>;
|
|
81
126
|
}
|
|
82
127
|
/**
|
|
83
128
|
* Decorate query endpoints with infinite query capabilities
|
|
@@ -142,16 +187,19 @@ interface UnusedSkipTokenTuyauQueryOptionsOut<TQueryFnData, TData, TError> exten
|
|
|
142
187
|
/**
|
|
143
188
|
* Tuyau-specific request options for React Query integration
|
|
144
189
|
*/
|
|
145
|
-
interface TuyauReactRequestOptions {
|
|
190
|
+
interface TuyauReactRequestOptions extends BaseRequestOptions {
|
|
146
191
|
/**
|
|
147
192
|
* Opt out or into aborting request on unmount
|
|
148
193
|
*/
|
|
149
194
|
abortOnUnmount?: boolean;
|
|
150
195
|
}
|
|
151
196
|
/**
|
|
152
|
-
* Base options for Tuyau queries
|
|
197
|
+
* Base options for Tuyau queries and mutations
|
|
153
198
|
*/
|
|
154
199
|
interface TuyauQueryBaseOptions {
|
|
200
|
+
/**
|
|
201
|
+
* Tuyau-specific options including Ky request options (timeout, retry, headers, etc.)
|
|
202
|
+
*/
|
|
155
203
|
tuyau?: TuyauReactRequestOptions;
|
|
156
204
|
}
|
|
157
205
|
interface DecorateRouterKeyable {
|
package/build/index.js
CHANGED
|
@@ -38,6 +38,11 @@ function buildKey(opts) {
|
|
|
38
38
|
}
|
|
39
39
|
];
|
|
40
40
|
}
|
|
41
|
+
function extractKyOptions(tuyauOpts) {
|
|
42
|
+
if (!tuyauOpts) return {};
|
|
43
|
+
const { abortOnUnmount, ...kyOptions } = tuyauOpts;
|
|
44
|
+
return kyOptions;
|
|
45
|
+
}
|
|
41
46
|
|
|
42
47
|
// src/query.ts
|
|
43
48
|
import { queryOptions, skipToken as skipToken2 } from "@tanstack/react-query";
|
|
@@ -47,8 +52,10 @@ function tuyauQueryOptions(options) {
|
|
|
47
52
|
if (request === skipToken2) return skipToken2;
|
|
48
53
|
return async (queryFnContext) => {
|
|
49
54
|
const effectiveAbortOnUnmount = opts?.tuyau?.abortOnUnmount ?? globalOptions?.abortOnUnmount ?? false;
|
|
55
|
+
const kyOptions = extractKyOptions(opts?.tuyau);
|
|
50
56
|
return await client.request(routeName, {
|
|
51
57
|
...request,
|
|
58
|
+
...kyOptions,
|
|
52
59
|
retry: 0,
|
|
53
60
|
...effectiveAbortOnUnmount ? { signal: queryFnContext.signal } : {}
|
|
54
61
|
});
|
|
@@ -66,6 +73,7 @@ function tuyauInfiniteQueryOptions(options) {
|
|
|
66
73
|
return async (queryFnContext) => {
|
|
67
74
|
const { pageParam } = queryFnContext;
|
|
68
75
|
const effectiveAbortOnUnmount = opts?.tuyau?.abortOnUnmount ?? globalOptions?.abortOnUnmount ?? false;
|
|
76
|
+
const kyOptions = extractKyOptions(opts?.tuyau);
|
|
69
77
|
const pageParamKey = opts?.pageParamKey || "page";
|
|
70
78
|
let requestArgs;
|
|
71
79
|
if (typeof request === "object" && request !== null) {
|
|
@@ -82,6 +90,7 @@ function tuyauInfiniteQueryOptions(options) {
|
|
|
82
90
|
}
|
|
83
91
|
return await client.request(routeName, {
|
|
84
92
|
...requestArgs,
|
|
93
|
+
...kyOptions,
|
|
85
94
|
retry: 0,
|
|
86
95
|
...effectiveAbortOnUnmount ? { signal: queryFnContext.signal } : {}
|
|
87
96
|
});
|
|
@@ -106,9 +115,10 @@ function getMutationKeyInternal(options) {
|
|
|
106
115
|
function tuyauMutationOptions(options) {
|
|
107
116
|
const { opts, routeName, client } = options;
|
|
108
117
|
const mutationKey = getMutationKeyInternal({ segments: routeName.split(".") });
|
|
118
|
+
const kyOptions = extractKyOptions(opts?.tuyau);
|
|
109
119
|
const mutationFn = async (request) => {
|
|
110
120
|
const requestArgs = request || {};
|
|
111
|
-
return await client.request(routeName, { ...requestArgs, retry: 0 });
|
|
121
|
+
return await client.request(routeName, { ...requestArgs, ...kyOptions, retry: 0 });
|
|
112
122
|
};
|
|
113
123
|
return mutationOptions({ ...opts, mutationKey, mutationFn });
|
|
114
124
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuyau/react-query",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
5
|
-
"description": "
|
|
4
|
+
"version": "1.0.0-beta.3",
|
|
5
|
+
"description": "Tanstack Query integration for Tuyau",
|
|
6
6
|
"author": "Julien Ripouteau <julien@ripouteau.com>",
|
|
7
|
-
"license": "
|
|
8
|
-
"
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"homepage": "https://github.com/Julien-R44/tuyau#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/Julien-R44/tuyau.git",
|
|
12
|
+
"directory": "packages/react-query"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/Julien-R44/tuyau/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"adonisjs",
|
|
19
|
+
"typescript",
|
|
20
|
+
"typesafe",
|
|
21
|
+
"react-query",
|
|
22
|
+
"tanstack-query",
|
|
23
|
+
"tuyau"
|
|
24
|
+
],
|
|
9
25
|
"exports": {
|
|
10
26
|
".": "./build/index.js"
|
|
11
27
|
},
|
|
@@ -18,18 +34,18 @@
|
|
|
18
34
|
},
|
|
19
35
|
"peerDependencies": {
|
|
20
36
|
"@tanstack/react-query": "^5.74.7",
|
|
21
|
-
"@tuyau/core": "1.0.0-beta.
|
|
37
|
+
"@tuyau/core": "^1.0.0-beta.9"
|
|
22
38
|
},
|
|
23
39
|
"devDependencies": {
|
|
24
|
-
"@adonisjs/core": "^7.0.0-next.
|
|
40
|
+
"@adonisjs/core": "^7.0.0-next.16",
|
|
25
41
|
"@faker-js/faker": "^10.1.0",
|
|
26
42
|
"@happy-dom/global-registrator": "^20.0.11",
|
|
27
|
-
"@tanstack/react-query": "^5.90.
|
|
28
|
-
"@testing-library/react": "^16.3.
|
|
43
|
+
"@tanstack/react-query": "^5.90.14",
|
|
44
|
+
"@testing-library/react": "^16.3.1",
|
|
29
45
|
"@types/react": "^19.2.7",
|
|
30
|
-
"@vinejs/vine": "^4.
|
|
31
|
-
"react": "^19.2.
|
|
32
|
-
"@tuyau/core": "1.0.0-beta.
|
|
46
|
+
"@vinejs/vine": "^4.2.0",
|
|
47
|
+
"react": "^19.2.3",
|
|
48
|
+
"@tuyau/core": "1.0.0-beta.9"
|
|
33
49
|
},
|
|
34
50
|
"tsup": {
|
|
35
51
|
"entry": [
|