@tuyau/react-query 1.0.0-beta.2 → 1.0.0-beta.4
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 +61 -12
- 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'];
|
|
@@ -18,7 +18,9 @@ interface DecorateQueryFn<EDef extends SchemaEndpoint> {
|
|
|
18
18
|
interface TuyauReactQueryOptions<EDef extends SchemaEndpoint> {
|
|
19
19
|
<TData = Response$2<EDef>>(input: RawRequestArgs<EDef> | SkipToken, opts: DefinedTuyauQueryOptionsIn<Response$2<EDef>, TData, unknown>): DefinedTuyauQueryOptionsOut<Response$2<EDef>, TData, unknown>;
|
|
20
20
|
<TData = Response$2<EDef>>(input: RawRequestArgs<EDef>, opts?: UnusedSkipTokenTuyauQueryOptionsIn<Response$2<EDef>, TData, unknown>): UnusedSkipTokenTuyauQueryOptionsOut<Response$2<EDef>, TData, unknown>;
|
|
21
|
-
|
|
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>;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
/**
|
|
@@ -55,10 +57,11 @@ interface TuyauMutationOptionsOptions {
|
|
|
55
57
|
declare function tuyauMutationOptions(options: TuyauMutationOptionsOptions): _tanstack_react_query.WithRequired<UseMutationOptions<unknown, any, any, any>, "mutationKey">;
|
|
56
58
|
|
|
57
59
|
type Response<E extends SchemaEndpoint> = E['types']['response'];
|
|
60
|
+
type ReservedInfiniteQueryOptions = 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash';
|
|
58
61
|
/**
|
|
59
|
-
*
|
|
62
|
+
* Base infinite query options with Tuyau-specific options
|
|
60
63
|
*/
|
|
61
|
-
interface
|
|
64
|
+
interface TuyauInfiniteQueryBaseOptionsIn {
|
|
62
65
|
/**
|
|
63
66
|
* The key that will be used for the page parameter in the request.
|
|
64
67
|
* For example, if your API expects ?page=1, set this to 'page'.
|
|
@@ -67,17 +70,60 @@ interface TuyauInfiniteQueryOptionsIn<TQueryFnData, TError, TData> extends Distr
|
|
|
67
70
|
pageParamKey?: string;
|
|
68
71
|
}
|
|
69
72
|
/**
|
|
70
|
-
* Infinite query options
|
|
73
|
+
* Infinite query options when initialData is undefined (default case)
|
|
71
74
|
*/
|
|
72
|
-
interface
|
|
75
|
+
interface UndefinedTuyauInfiniteQueryOptionsIn<TQueryFnData, TError, TData> extends DistributiveOmit<UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TuyauQueryKey, unknown>, ReservedInfiniteQueryOptions>, TuyauQueryBaseOptions, TuyauInfiniteQueryBaseOptionsIn {
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Output type when initialData is undefined - queryFn can be SkipToken
|
|
79
|
+
*/
|
|
80
|
+
interface UndefinedTuyauInfiniteQueryOptionsOut<TQueryFnData, TError, TData> extends DistributiveOmit<UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TuyauQueryKey, unknown>, 'queryKey'> {
|
|
81
|
+
queryKey: DataTag<TuyauQueryKey, TData>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Infinite query options when initialData is defined
|
|
85
|
+
*/
|
|
86
|
+
interface DefinedTuyauInfiniteQueryOptionsIn<TQueryFnData, TError, TData> extends DistributiveOmit<DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TuyauQueryKey, unknown>, ReservedInfiniteQueryOptions>, TuyauQueryBaseOptions, TuyauInfiniteQueryBaseOptionsIn {
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Output type when initialData is defined - queryFn can be SkipToken
|
|
90
|
+
*/
|
|
91
|
+
interface DefinedTuyauInfiniteQueryOptionsOut<TQueryFnData, TError, TData> extends DistributiveOmit<DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TuyauQueryKey, unknown>, 'queryKey'> {
|
|
73
92
|
queryKey: DataTag<TuyauQueryKey, TData>;
|
|
74
93
|
}
|
|
75
94
|
/**
|
|
76
|
-
*
|
|
95
|
+
* Infinite query options when SkipToken is NOT used as input.
|
|
96
|
+
* This makes the result compatible with useSuspenseInfiniteQuery.
|
|
97
|
+
*/
|
|
98
|
+
interface UnusedSkipTokenTuyauInfiniteQueryOptionsIn<TQueryFnData, TError, TData> extends DistributiveOmit<UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TuyauQueryKey, unknown>, ReservedInfiniteQueryOptions>, TuyauQueryBaseOptions, TuyauInfiniteQueryBaseOptionsIn {
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Output type when SkipToken is NOT used - queryFn excludes SkipToken.
|
|
102
|
+
* This makes it compatible with useSuspenseInfiniteQuery.
|
|
103
|
+
*/
|
|
104
|
+
interface UnusedSkipTokenTuyauInfiniteQueryOptionsOut<TQueryFnData, TError, TData> extends DistributiveOmit<UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TuyauQueryKey, unknown>, 'queryKey'> {
|
|
105
|
+
queryKey: DataTag<TuyauQueryKey, TData>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Type definition for infinite query options with proper overloads.
|
|
77
109
|
*/
|
|
78
110
|
interface TuyauReactInfiniteQueryOptions<EDef extends SchemaEndpoint> {
|
|
79
|
-
|
|
80
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Overload 1: When input is NOT SkipToken, return options compatible with useSuspenseInfiniteQuery
|
|
113
|
+
*/
|
|
114
|
+
<TData = InfiniteData<Response<EDef>>>(input: RawRequestArgs<EDef>, opts: UnusedSkipTokenTuyauInfiniteQueryOptionsIn<Response<EDef>, unknown, TData>): UnusedSkipTokenTuyauInfiniteQueryOptionsOut<Response<EDef>, unknown, TData>;
|
|
115
|
+
/**
|
|
116
|
+
* Overload 2: When initialData is defined
|
|
117
|
+
*/
|
|
118
|
+
<TData = InfiniteData<Response<EDef>>>(input: RawRequestArgs<EDef> | SkipToken, opts: DefinedTuyauInfiniteQueryOptionsIn<Response<EDef>, unknown, TData>): DefinedTuyauInfiniteQueryOptionsOut<Response<EDef>, unknown, TData>;
|
|
119
|
+
/**
|
|
120
|
+
* Overload 3: No arguments - no skipToken possible
|
|
121
|
+
*/
|
|
122
|
+
(): UnusedSkipTokenTuyauInfiniteQueryOptionsOut<Response<EDef>, unknown, InfiniteData<Response<EDef>>>;
|
|
123
|
+
/**
|
|
124
|
+
* Overload 4: With skipToken or conditional (request | skipToken) and options
|
|
125
|
+
*/
|
|
126
|
+
<TData = InfiniteData<Response<EDef>>>(input: RawRequestArgs<EDef> | SkipToken, opts: UndefinedTuyauInfiniteQueryOptionsIn<Response<EDef>, unknown, TData>): UndefinedTuyauInfiniteQueryOptionsOut<Response<EDef>, unknown, TData>;
|
|
81
127
|
}
|
|
82
128
|
/**
|
|
83
129
|
* Decorate query endpoints with infinite query capabilities
|
|
@@ -142,16 +188,19 @@ interface UnusedSkipTokenTuyauQueryOptionsOut<TQueryFnData, TData, TError> exten
|
|
|
142
188
|
/**
|
|
143
189
|
* Tuyau-specific request options for React Query integration
|
|
144
190
|
*/
|
|
145
|
-
interface TuyauReactRequestOptions {
|
|
191
|
+
interface TuyauReactRequestOptions extends BaseRequestOptions {
|
|
146
192
|
/**
|
|
147
193
|
* Opt out or into aborting request on unmount
|
|
148
194
|
*/
|
|
149
195
|
abortOnUnmount?: boolean;
|
|
150
196
|
}
|
|
151
197
|
/**
|
|
152
|
-
* Base options for Tuyau queries
|
|
198
|
+
* Base options for Tuyau queries and mutations
|
|
153
199
|
*/
|
|
154
200
|
interface TuyauQueryBaseOptions {
|
|
201
|
+
/**
|
|
202
|
+
* Tuyau-specific options including Ky request options (timeout, retry, headers, etc.)
|
|
203
|
+
*/
|
|
155
204
|
tuyau?: TuyauReactRequestOptions;
|
|
156
205
|
}
|
|
157
206
|
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.4",
|
|
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.10"
|
|
33
49
|
},
|
|
34
50
|
"tsup": {
|
|
35
51
|
"entry": [
|