@tuyau/react-query 0.0.1-next.1 → 1.0.0-beta.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 +116 -268
- package/build/index.js +136 -247
- package/package.json +12 -16
package/build/index.d.ts
CHANGED
|
@@ -1,100 +1,108 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { AdonisEndpoint, RawRequestArgs, Method, UnionToIntersection, StrKeys, Split } from '@tuyau/core/types';
|
|
2
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
3
|
+
import { SkipToken, DataTag, QueryFilters, WithRequired as WithRequired$1, UseMutationOptions, InfiniteData, InfiniteQueryObserverOptions, DefinedInitialDataOptions, UndefinedInitialDataOptions, UnusedSkipTokenOptions, QueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { Tuyau } from '@tuyau/core/client';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Decorate query endpoints with Tanstack queries abilities
|
|
8
8
|
*/
|
|
9
|
-
interface
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} | SkipToken, opts: DefinedTuyauQueryOptionsIn<UnionFromSuccessStatuses<EDef['response']>, TData, any>): DefinedTuyauQueryOptionsOut<UnionFromSuccessStatuses<EDef['response']>, TData, any>;
|
|
14
|
-
<TData = UnionFromSuccessStatuses<EDef['response']>>(input: {
|
|
15
|
-
payload?: EDef['request'];
|
|
16
|
-
params?: TParams;
|
|
17
|
-
}, opts?: UnusedSkipTokenTuyauQueryOptionsIn<UnionFromSuccessStatuses<EDef['response']>, TData, any>): UnusedSkipTokenTuyauQueryOptionsOut<UnionFromSuccessStatuses<EDef['response']>, TData, any>;
|
|
18
|
-
<TData = UnionFromSuccessStatuses<EDef['response']>>(input?: {
|
|
19
|
-
payload?: EDef['request'];
|
|
20
|
-
params?: TParams;
|
|
21
|
-
} | SkipToken, opts?: UndefinedTuyauQueryOptionsIn<UnionFromSuccessStatuses<EDef['response']>, TData, any>): UndefinedTuyauQueryOptionsOut<UnionFromSuccessStatuses<EDef['response']>, TData, any>;
|
|
9
|
+
interface DecorateQueryFn<EDef extends AdonisEndpoint> extends TypeHelper<EDef> {
|
|
10
|
+
queryOptions: TuyauReactQueryOptions<EDef>;
|
|
11
|
+
queryKey: (args?: RawRequestArgs<EDef>) => DataTag<TuyauQueryKey, EDef['types']['response']>;
|
|
12
|
+
queryFilter: (args?: RawRequestArgs<EDef>, filters?: QueryFilters<DataTag<TuyauQueryKey, EDef['types']['response']>>) => WithRequired$1<QueryFilters<DataTag<TuyauQueryKey, EDef['types']['response']>>, 'queryKey'>;
|
|
22
13
|
}
|
|
23
14
|
/**
|
|
24
|
-
*
|
|
15
|
+
* Type definition for query options with overloads for different scenarios
|
|
25
16
|
*/
|
|
26
|
-
interface
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
params?: TParams;
|
|
31
|
-
}) => DataTag<TuyauQueryKey, UnionFromSuccessStatuses<EDef['response']>, any>;
|
|
32
|
-
queryFilter: (input?: {
|
|
33
|
-
payload?: Partial<EDef['request']>;
|
|
34
|
-
params?: TParams;
|
|
35
|
-
}, filters?: QueryFilters<DataTag<TuyauQueryKey, UnionFromSuccessStatuses<EDef['response']>, any>>) => WithRequired<QueryFilters<DataTag<TuyauQueryKey, UnionFromSuccessStatuses<EDef['response']>, any>>, 'queryKey'>;
|
|
17
|
+
interface TuyauReactQueryOptions<EDef extends AdonisEndpoint> {
|
|
18
|
+
<TData = EDef['types']['response']>(input: RawRequestArgs<EDef> | SkipToken, opts: DefinedTuyauQueryOptionsIn<EDef['types']['response'], TData, unknown>): DefinedTuyauQueryOptionsOut<EDef['types']['response'], TData, unknown>;
|
|
19
|
+
<TData = EDef['types']['response']>(input: RawRequestArgs<EDef>, opts?: UnusedSkipTokenTuyauQueryOptionsIn<EDef['types']['response'], TData, unknown>): UnusedSkipTokenTuyauQueryOptionsOut<EDef['types']['response'], TData, unknown>;
|
|
20
|
+
<TData = EDef['types']['response']>(input?: RawRequestArgs<EDef> | SkipToken, opts?: UndefinedTuyauQueryOptionsIn<EDef['types']['response'], TData, unknown>): UndefinedTuyauQueryOptionsOut<EDef['types']['response'], TData, unknown>;
|
|
36
21
|
}
|
|
37
22
|
|
|
38
23
|
/**
|
|
39
|
-
*
|
|
24
|
+
* Omits the key without removing a potential union
|
|
25
|
+
*/
|
|
26
|
+
type DistributiveOmit<TObj, TKey extends keyof any> = TObj extends any ? Omit<TObj, TKey> : never;
|
|
27
|
+
/**
|
|
28
|
+
* Make certain keys required in a type
|
|
40
29
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
31
|
+
|
|
32
|
+
type ReservedOptions = 'mutationKey' | 'mutationFn';
|
|
33
|
+
interface TuyauMutationOptionsIn<TInput, TError, TOutput, TContext> extends DistributiveOmit<UseMutationOptions<TOutput, TError, TInput, TContext>, ReservedOptions>, TuyauQueryBaseOptions {
|
|
34
|
+
}
|
|
35
|
+
interface TuyauMutationOptionsOut<TInput, TError, TOutput, TContext> extends UseMutationOptions<TOutput, TError, TInput, TContext> {
|
|
36
|
+
mutationKey: TuyauMutationKey;
|
|
37
|
+
}
|
|
38
|
+
interface TuyauReactMutationOptions<TDef extends AdonisEndpoint> {
|
|
39
|
+
<TContext = unknown>(opts?: TuyauMutationOptionsIn<RawRequestArgs<TDef>, any, TDef['types']['response'], TContext>): TuyauMutationOptionsOut<RawRequestArgs<TDef>, any, TDef['types']['response'], TContext>;
|
|
40
|
+
}
|
|
41
|
+
declare function getMutationKeyInternal(options: {
|
|
42
|
+
segments: string[];
|
|
43
|
+
}): TuyauMutationKey;
|
|
44
|
+
interface DecorateMutationFn<EDef extends AdonisEndpoint> extends TypeHelper<EDef> {
|
|
45
|
+
mutationOptions: TuyauReactMutationOptions<EDef>;
|
|
43
46
|
mutationKey: () => TuyauMutationKey;
|
|
44
47
|
}
|
|
48
|
+
interface TuyauMutationOptionsOptions {
|
|
49
|
+
opts?: TuyauMutationOptionsIn<any, any, any, any>;
|
|
50
|
+
routeName: string;
|
|
51
|
+
client: Tuyau<any>;
|
|
52
|
+
}
|
|
53
|
+
declare function tuyauMutationOptions(options: TuyauMutationOptionsOptions): _tanstack_react_query.WithRequired<UseMutationOptions<unknown, any, any, any>, "mutationKey">;
|
|
54
|
+
|
|
45
55
|
/**
|
|
46
|
-
*
|
|
56
|
+
* Infinite query options input type
|
|
47
57
|
*/
|
|
48
|
-
interface
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
mutationKey: TuyauMutationKey;
|
|
58
|
+
interface TuyauInfiniteQueryOptionsIn<TQueryFnData, TError, TData> extends DistributiveOmit<InfiniteQueryObserverOptions<TQueryFnData, TError, TData>, 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash'>, TuyauQueryBaseOptions {
|
|
59
|
+
/**
|
|
60
|
+
* The key that will be used for the page parameter in the request.
|
|
61
|
+
* For example, if your API expects ?page=1, set this to 'page'.
|
|
62
|
+
* If your API expects ?cursor=abc, set this to 'cursor'.
|
|
63
|
+
*/
|
|
64
|
+
pageParamKey?: string;
|
|
56
65
|
}
|
|
57
66
|
/**
|
|
58
|
-
*
|
|
67
|
+
* Infinite query options output type
|
|
59
68
|
*/
|
|
60
|
-
interface
|
|
61
|
-
|
|
69
|
+
interface TuyauInfiniteQueryOptionsOut<TQueryFnData, TError, TData> extends Omit<InfiniteQueryObserverOptions<TQueryFnData, TError, TData>, 'queryKey'> {
|
|
70
|
+
queryKey: DataTag<TuyauQueryKey, TData>;
|
|
62
71
|
}
|
|
63
|
-
|
|
64
72
|
/**
|
|
65
|
-
*
|
|
73
|
+
* Type definition for infinite query options
|
|
66
74
|
*/
|
|
67
|
-
|
|
75
|
+
interface TuyauReactInfiniteQueryOptions<EDef extends AdonisEndpoint> {
|
|
76
|
+
<TData = InfiniteData<EDef['types']['response']>>(input: RawRequestArgs<EDef> | SkipToken, opts: TuyauInfiniteQueryOptionsIn<EDef['types']['response'], unknown, TData>): TuyauInfiniteQueryOptionsOut<EDef['types']['response'], unknown, TData>;
|
|
77
|
+
<TData = InfiniteData<EDef['types']['response']>>(input?: RawRequestArgs<EDef> | SkipToken, opts?: TuyauInfiniteQueryOptionsIn<EDef['types']['response'], unknown, TData>): TuyauInfiniteQueryOptionsOut<EDef['types']['response'], unknown, TData>;
|
|
78
|
+
}
|
|
68
79
|
/**
|
|
69
|
-
*
|
|
80
|
+
* Decorate query endpoints with infinite query capabilities
|
|
70
81
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
interface DecorateInfiniteQueryFn<EDef extends AdonisEndpoint> extends TypeHelper<EDef> {
|
|
83
|
+
infiniteQueryOptions: TuyauReactInfiniteQueryOptions<EDef>;
|
|
84
|
+
infiniteQueryKey: (args?: RawRequestArgs<EDef>) => DataTag<TuyauQueryKey, InfiniteData<EDef['types']['response']>>;
|
|
85
|
+
infiniteQueryFilter: (args?: RawRequestArgs<EDef>, filters?: QueryFilters<DataTag<TuyauQueryKey, InfiniteData<EDef['types']['response']>>>) => WithRequired$1<QueryFilters<DataTag<TuyauQueryKey, InfiniteData<EDef['types']['response']>>>, 'queryKey'>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Query type identifier
|
|
90
|
+
*/
|
|
91
|
+
type QueryType = 'any' | 'infinite' | 'query';
|
|
75
92
|
/**
|
|
76
93
|
* Tuyau-specific query key structure
|
|
77
94
|
*/
|
|
78
95
|
type TuyauQueryKey = [
|
|
79
96
|
readonly string[],
|
|
80
97
|
{
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
type?: 'infinite' | 'query';
|
|
98
|
+
request?: RawRequestArgs<any>;
|
|
99
|
+
type?: Exclude<QueryType, 'any'>;
|
|
84
100
|
}?
|
|
85
101
|
];
|
|
86
102
|
/**
|
|
87
103
|
* Tuyau-specific mutation key structure
|
|
88
104
|
*/
|
|
89
105
|
type TuyauMutationKey = [readonly string[]];
|
|
90
|
-
/**
|
|
91
|
-
* Omits the key without removing a potential union
|
|
92
|
-
*/
|
|
93
|
-
type DistributiveOmit<TObj, TKey extends keyof any> = TObj extends any ? Omit<TObj, TKey> : never;
|
|
94
|
-
/**
|
|
95
|
-
* Make certain keys required in a type
|
|
96
|
-
*/
|
|
97
|
-
type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;
|
|
98
106
|
/**
|
|
99
107
|
* Query options with defined initial data
|
|
100
108
|
*/
|
|
@@ -113,57 +121,21 @@ interface UnusedSkipTokenTuyauQueryOptionsIn<TQueryFnData, TData, TError> extend
|
|
|
113
121
|
/**
|
|
114
122
|
* Output type for query options with defined initial data
|
|
115
123
|
*/
|
|
116
|
-
interface DefinedTuyauQueryOptionsOut<TQueryFnData, TData, TError> extends DefinedInitialDataOptions<TQueryFnData, TError, TData, TuyauQueryKey
|
|
124
|
+
interface DefinedTuyauQueryOptionsOut<TQueryFnData, TData, TError> extends DefinedInitialDataOptions<TQueryFnData, TError, TData, TuyauQueryKey> {
|
|
117
125
|
queryKey: DataTag<TuyauQueryKey, TData, TError>;
|
|
118
126
|
}
|
|
119
127
|
/**
|
|
120
128
|
* Output type for query options with undefined initial data
|
|
121
129
|
*/
|
|
122
|
-
interface UndefinedTuyauQueryOptionsOut<TQueryFnData, TData, TError> extends UndefinedInitialDataOptions<TQueryFnData, TError, TData, TuyauQueryKey
|
|
130
|
+
interface UndefinedTuyauQueryOptionsOut<TQueryFnData, TData, TError> extends UndefinedInitialDataOptions<TQueryFnData, TError, TData, TuyauQueryKey> {
|
|
123
131
|
queryKey: DataTag<TuyauQueryKey, TData, TError>;
|
|
124
132
|
}
|
|
125
133
|
/**
|
|
126
134
|
* Output type for query options with unused skip token
|
|
127
135
|
*/
|
|
128
|
-
interface UnusedSkipTokenTuyauQueryOptionsOut<TQueryFnData, TData, TError> extends UnusedSkipTokenOptions<TQueryFnData, TError, TData, TuyauQueryKey
|
|
136
|
+
interface UnusedSkipTokenTuyauQueryOptionsOut<TQueryFnData, TData, TError> extends UnusedSkipTokenOptions<TQueryFnData, TError, TData, TuyauQueryKey> {
|
|
129
137
|
queryKey: DataTag<TuyauQueryKey, TData, TError>;
|
|
130
138
|
}
|
|
131
|
-
/**
|
|
132
|
-
* Input type for mutation options
|
|
133
|
-
*/
|
|
134
|
-
interface TuyauMutationOptionsIn<TInput, TError, TOutput, TContext, TParams = Record<string, string | number>> extends DistributiveOmit<UseMutationOptions<TOutput, TError, {
|
|
135
|
-
payload: TInput;
|
|
136
|
-
params?: TParams;
|
|
137
|
-
}, TContext>, 'mutationKey' | 'mutationFn'> {
|
|
138
|
-
/**
|
|
139
|
-
* Route parameters to be passed to the mutation
|
|
140
|
-
*/
|
|
141
|
-
params?: TParams;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Interface for router keyable decorators (pathKey, pathFilter)
|
|
145
|
-
*/
|
|
146
|
-
interface DecorateRouterKeyable {
|
|
147
|
-
pathKey: () => TuyauQueryKey;
|
|
148
|
-
pathFilter: (filters?: QueryFilters<TuyauQueryKey>) => WithRequired<QueryFilters<TuyauQueryKey>, 'queryKey'>;
|
|
149
|
-
}
|
|
150
|
-
interface TypeHelper<EDef extends EndpointDef> {
|
|
151
|
-
/**
|
|
152
|
-
* @internal
|
|
153
|
-
*/
|
|
154
|
-
'~types': {
|
|
155
|
-
request: EDef['request'];
|
|
156
|
-
response: EDef['response'];
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Infer request type from an endpoint
|
|
161
|
-
*/
|
|
162
|
-
type InferRequestType<Endpoint extends DecorateQueryFn<any> | DecorateMutationFn<any>> = Endpoint['~types']['request'];
|
|
163
|
-
/**
|
|
164
|
-
* Infer response type from an endpoint
|
|
165
|
-
*/
|
|
166
|
-
type InferResponseType<Endpoint extends DecorateQueryFn<any> | DecorateMutationFn<any>> = Endpoint['~types']['response'];
|
|
167
139
|
/**
|
|
168
140
|
* Tuyau-specific request options for React Query integration
|
|
169
141
|
*/
|
|
@@ -177,180 +149,56 @@ interface TuyauReactRequestOptions {
|
|
|
177
149
|
* Base options for Tuyau queries
|
|
178
150
|
*/
|
|
179
151
|
interface TuyauQueryBaseOptions {
|
|
180
|
-
/**
|
|
181
|
-
* Tuyau-related options
|
|
182
|
-
*/
|
|
183
152
|
tuyau?: TuyauReactRequestOptions;
|
|
184
153
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
interface TuyauQueryOptionsResult {
|
|
189
|
-
tuyau: {
|
|
190
|
-
path: string[];
|
|
191
|
-
type: 'query';
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Reserved infinite query options that should not be overridden
|
|
197
|
-
*/
|
|
198
|
-
type InfiniteQueryReservedOptions = 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash';
|
|
199
|
-
/**
|
|
200
|
-
* Tuyau infinite data structure
|
|
201
|
-
*/
|
|
202
|
-
type TuyauInfiniteData<TData> = {
|
|
203
|
-
pages: TData[];
|
|
204
|
-
pageParams: unknown[];
|
|
205
|
-
};
|
|
206
|
-
/**
|
|
207
|
-
* Infinite query options with undefined initial data
|
|
208
|
-
*/
|
|
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;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Infinite query options with defined initial data
|
|
214
|
-
*/
|
|
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;
|
|
217
|
-
}
|
|
218
|
-
type ExtractPageParamType<TRequest, TPageParamKey extends keyof TRequest> = TRequest[TPageParamKey];
|
|
219
|
-
/**
|
|
220
|
-
* Infinite query options with unused skip token
|
|
221
|
-
*/
|
|
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;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Output type for infinite query options with undefined initial data
|
|
227
|
-
*/
|
|
228
|
-
interface UndefinedTuyauInfiniteQueryOptionsOut<TQueryFnData, TData, TError> extends UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TuyauInfiniteData<TData>, TuyauQueryKey, unknown> {
|
|
229
|
-
queryKey: DataTag<TuyauQueryKey, TuyauInfiniteData<TData>, TError>;
|
|
230
|
-
tuyau: {
|
|
231
|
-
path: string[];
|
|
232
|
-
type: 'infinite';
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Output type for infinite query options with defined initial data
|
|
237
|
-
*/
|
|
238
|
-
interface DefinedTuyauInfiniteQueryOptionsOut<TQueryFnData, TData, TError> extends DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TuyauInfiniteData<TData>, TuyauQueryKey, unknown> {
|
|
239
|
-
queryKey: DataTag<TuyauQueryKey, TuyauInfiniteData<TData>, TError>;
|
|
240
|
-
tuyau: {
|
|
241
|
-
path: string[];
|
|
242
|
-
type: 'infinite';
|
|
243
|
-
};
|
|
154
|
+
interface DecorateRouterKeyable {
|
|
155
|
+
pathKey: () => TuyauQueryKey;
|
|
156
|
+
pathFilter: (filters?: QueryFilters<TuyauQueryKey>) => WithRequired<QueryFilters<TuyauQueryKey>, 'queryKey'>;
|
|
244
157
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
interface
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
158
|
+
type EndpointNode<E extends AdonisEndpoint> = E extends {
|
|
159
|
+
methods: readonly (infer M extends Method)[];
|
|
160
|
+
} ? M extends 'GET' | 'HEAD' ? DecorateQueryFn<E> & DecorateInfiniteQueryFn<E> & DecorateRouterKeyable : DecorateMutationFn<E> & DecorateRouterKeyable : DecorateRouterKeyable;
|
|
161
|
+
interface TypeHelper<EDef extends AdonisEndpoint> {
|
|
162
|
+
/**
|
|
163
|
+
* @internal
|
|
164
|
+
*/
|
|
165
|
+
'~types': {
|
|
166
|
+
request: EDef['types']['body'];
|
|
167
|
+
response: EDef['types']['response'];
|
|
253
168
|
};
|
|
254
169
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
params?: TParams;
|
|
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>;
|
|
269
|
-
params?: TParams;
|
|
270
|
-
} | SkipToken, opts?: UndefinedTuyauInfiniteQueryOptionsIn<UnionFromSuccessStatuses<EDef['response']>, TData, any, EDef['request'], TPageParamKey>): UndefinedTuyauInfiniteQueryOptionsOut<UnionFromSuccessStatuses<EDef['response']>, TData, any>;
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Interface for infinite query function decorators
|
|
274
|
-
*/
|
|
275
|
-
interface DecorateInfiniteQueryFn<EDef extends EndpointDef, TParams = Record<string, string | number>> {
|
|
276
|
-
infiniteQueryOptions: TuyauReactInfiniteQueryOptions<EDef, TParams>;
|
|
277
|
-
infiniteQueryKey: (input?: {
|
|
278
|
-
payload?: Partial<EDef['request']>;
|
|
279
|
-
params?: TParams;
|
|
280
|
-
}) => DataTag<TuyauQueryKey, TuyauInfiniteData<UnionFromSuccessStatuses<EDef['response']>>, any>;
|
|
281
|
-
infiniteQueryFilter: (input?: {
|
|
282
|
-
payload?: Partial<EDef['request']>;
|
|
283
|
-
params?: TParams;
|
|
284
|
-
}, filters?: QueryFilters<DataTag<TuyauQueryKey, TuyauInfiniteData<UnionFromSuccessStatuses<EDef['response']>>, any>>) => WithRequired<QueryFilters<DataTag<TuyauQueryKey, TuyauInfiniteData<UnionFromSuccessStatuses<EDef['response']>>, any>>, 'queryKey'>;
|
|
285
|
-
}
|
|
170
|
+
type SetAtPathWithKeyable<Path extends string[], V> = Path extends [
|
|
171
|
+
infer H extends string,
|
|
172
|
+
...infer T extends string[]
|
|
173
|
+
] ? {
|
|
174
|
+
[K in H]: T['length'] extends 0 ? V : SetAtPathWithKeyable<T, V> & DecorateRouterKeyable;
|
|
175
|
+
} : {};
|
|
176
|
+
type BuildNamespaces<R extends Record<string, AdonisEndpoint>> = UnionToIntersection<{
|
|
177
|
+
[K in StrKeys<R>]: SetAtPathWithKeyable<Split<K>, EndpointNode<R[K]>>;
|
|
178
|
+
}[StrKeys<R>]> & DecorateRouterKeyable;
|
|
179
|
+
type TuyauReactQuery<R extends Record<string, AdonisEndpoint>> = BuildNamespaces<R>;
|
|
286
180
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
*/
|
|
290
|
-
interface TuyauReactQueryClientOptions<D extends Record<string, any>, R extends GeneratedRoutes> {
|
|
291
|
-
client: TuyauClient<D, R>;
|
|
181
|
+
declare function createTuyauReactQueryClient<D extends Record<string, AdonisEndpoint>>(options: {
|
|
182
|
+
client: Tuyau<D>;
|
|
292
183
|
queryClient: QueryClient | (() => QueryClient);
|
|
293
|
-
/**
|
|
294
|
-
* Global Tuyau-specific request options
|
|
295
|
-
*/
|
|
296
184
|
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;
|
|
302
|
-
/**
|
|
303
|
-
* Main type for the Tuyau React Query client
|
|
304
|
-
* Maps route definitions to appropriate query or mutation decorators
|
|
305
|
-
*/
|
|
306
|
-
type TuyauReactQuery<in out Route extends Record<string, any>, NotProvidedParams = {}> = {
|
|
307
|
-
[K in keyof Route as K extends `:${string}` ? never : K]: Route[K] extends {
|
|
308
|
-
response: infer _Res extends Record<number, unknown>;
|
|
309
|
-
request: infer _Request;
|
|
310
|
-
} ? K extends '$get' | '$head' ? DecorateQueryFn<Route[K], NotProvidedParams> & DecorateInfiniteQueryFn<Route[K], NotProvidedParams> & DecorateRouterKeyable : // POST, PUT, PATCH, DELETE methods become mutations
|
|
311
|
-
DecorateMutationFn<Route[K], NotProvidedParams> & DecorateRouterKeyable : K extends '$url' ? (options?: {
|
|
312
|
-
query?: QueryParameters;
|
|
313
|
-
}) => string : CreateParams<Route[K], NotProvidedParams> & DecorateRouterKeyable;
|
|
314
|
-
};
|
|
315
|
-
/**
|
|
316
|
-
* Extract path parameters from route keys
|
|
317
|
-
*/
|
|
318
|
-
type ExtractPathParams<Route> = Extract<keyof Route, `:${string}`>;
|
|
319
|
-
/**
|
|
320
|
-
* Convert path parameter to object type
|
|
321
|
-
*/
|
|
322
|
-
type PathParamToObject<Path extends string> = Path extends `:${infer Param}` ? {
|
|
323
|
-
[K in Param]: string | number;
|
|
324
|
-
} : never;
|
|
325
|
-
/**
|
|
326
|
-
* Create the route parameter function signature
|
|
327
|
-
*/
|
|
328
|
-
type CreateParamFunction<Route extends Record<string, any>, Path extends string, NotProvidedParams> = (params: PathParamToObject<Path>) => TuyauReactQuery<Route[Path], NotProvidedParams> & CreateParams<Route[Path], NotProvidedParams & PathParamToObject<Path>>;
|
|
329
|
-
/**
|
|
330
|
-
* Create the parameter property mappings
|
|
331
|
-
*/
|
|
332
|
-
type CreateParamProperties<Route extends Record<string, any>, Path extends string, NotProvidedParams> = {
|
|
333
|
-
[K in keyof Route as K extends `:${string}` ? K : never]: TuyauReactQuery<Route[K], NotProvidedParams & PathParamToObject<Path>> & DecorateRouterKeyable;
|
|
334
|
-
};
|
|
335
|
-
/**
|
|
336
|
-
* Type for handling route parameters
|
|
337
|
-
*/
|
|
338
|
-
type CreateParams<Route extends Record<string, any>, NotProvidedParams = {}> = ExtractPathParams<Route> extends infer Path extends string ? IsNever<Path> extends true ? TuyauReactQuery<Route, NotProvidedParams> & DecorateRouterKeyable : CreateParamFunction<Route, Path, NotProvidedParams> & TuyauReactQuery<Route, NotProvidedParams> & CreateParamProperties<Route, Path, NotProvidedParams> & DecorateRouterKeyable : never;
|
|
185
|
+
}): TuyauReactQuery<D> & DecorateRouterKeyable;
|
|
339
186
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
}>;
|
|
348
|
-
useTuyau: () => InferTuyauReactQuery<API>;
|
|
349
|
-
useTuyauClient: () => InferTuyauClient<API>;
|
|
187
|
+
interface TuyauQueryOptionsOptions {
|
|
188
|
+
request: RawRequestArgs<any> | SkipToken;
|
|
189
|
+
opts?: TuyauQueryBaseOptions;
|
|
190
|
+
queryKey: TuyauQueryKey;
|
|
191
|
+
routeName: string;
|
|
192
|
+
client: Tuyau<any>;
|
|
193
|
+
globalOptions?: TuyauReactRequestOptions;
|
|
350
194
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
195
|
+
declare function tuyauQueryOptions(options: TuyauQueryOptionsOptions): _tanstack_react_query.UseQueryOptions<any, Error, any, readonly unknown[]> & {
|
|
196
|
+
initialData?: any;
|
|
197
|
+
} & {
|
|
198
|
+
queryKey: readonly unknown[] & {
|
|
199
|
+
[dataTagSymbol]: any;
|
|
200
|
+
[dataTagErrorSymbol]: Error;
|
|
201
|
+
};
|
|
202
|
+
};
|
|
355
203
|
|
|
356
|
-
export { type
|
|
204
|
+
export { type DecorateMutationFn, type DecorateRouterKeyable, type DefinedTuyauQueryOptionsIn, type DefinedTuyauQueryOptionsOut, type EndpointNode, type QueryType, type TuyauMutationKey, type TuyauMutationOptionsIn, type TuyauMutationOptionsOptions, type TuyauMutationOptionsOut, type TuyauQueryBaseOptions, type TuyauQueryKey, type TuyauQueryOptionsOptions, type TuyauReactMutationOptions, type TuyauReactQuery, type TuyauReactRequestOptions, type TypeHelper, type UndefinedTuyauQueryOptionsIn, type UndefinedTuyauQueryOptionsOut, type UnusedSkipTokenTuyauQueryOptionsIn, type UnusedSkipTokenTuyauQueryOptionsOut, createTuyauReactQueryClient, getMutationKeyInternal, tuyauMutationOptions, tuyauQueryOptions };
|
package/build/index.js
CHANGED
|
@@ -1,287 +1,176 @@
|
|
|
1
|
-
// src/main.ts
|
|
2
|
-
import {
|
|
3
|
-
createTuyauRecursiveProxy
|
|
4
|
-
} from "@tuyau/client";
|
|
5
|
-
|
|
6
1
|
// src/utils.ts
|
|
7
|
-
|
|
8
|
-
return typeof arg === "function" ? arg() : arg;
|
|
9
|
-
}
|
|
2
|
+
import { skipToken } from "@tanstack/react-query";
|
|
10
3
|
function isObject(value) {
|
|
11
4
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
5
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
const result = [];
|
|
16
|
-
for (const segment of path) {
|
|
17
|
-
const segmentStr = String(segment);
|
|
18
|
-
if (segmentStr.includes("/")) {
|
|
19
|
-
const parts = segmentStr.split("/");
|
|
20
|
-
for (const part of parts) {
|
|
21
|
-
if (part.startsWith(":")) {
|
|
22
|
-
const paramName = part.slice(1);
|
|
23
|
-
result.push(params[paramName]?.toString() || part);
|
|
24
|
-
} else {
|
|
25
|
-
result.push(part);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
} else if (segmentStr.startsWith(":")) {
|
|
29
|
-
const paramName = segmentStr.slice(1);
|
|
30
|
-
result.push(params[paramName]?.toString() || segmentStr);
|
|
31
|
-
} else {
|
|
32
|
-
result.push(segmentStr);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return result;
|
|
6
|
+
function invoke(fn) {
|
|
7
|
+
return fn?.();
|
|
36
8
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
skipToken
|
|
42
|
-
} from "@tanstack/react-query";
|
|
43
|
-
function getQueryKeyInternal(path, input, type) {
|
|
44
|
-
let params;
|
|
45
|
-
let payload;
|
|
46
|
-
if (isObject(input)) {
|
|
47
|
-
if ("params" in input && input.params && typeof input.params === "object") {
|
|
48
|
-
params = input.params;
|
|
49
|
-
}
|
|
50
|
-
if ("payload" in input) {
|
|
51
|
-
payload = input.payload;
|
|
52
|
-
} else if (!("params" in input)) {
|
|
53
|
-
payload = input;
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
payload = input;
|
|
57
|
-
}
|
|
58
|
-
const splitPath = path.flatMap((part) => part.toString().split("/"));
|
|
59
|
-
if (!input && (!type || type === "any")) {
|
|
9
|
+
function buildKey(opts) {
|
|
10
|
+
const { segments, request, type } = opts;
|
|
11
|
+
const splitPath = segments.flatMap((part) => part.split("."));
|
|
12
|
+
if (!request && type === "any") {
|
|
60
13
|
return splitPath.length ? [splitPath] : [];
|
|
61
14
|
}
|
|
15
|
+
if (type === "infinite" && isObject(request) && ("direction" in request || "cursor" in request)) {
|
|
16
|
+
const { cursor: _, direction: __, ...inputWithoutCursorAndDirection } = request;
|
|
17
|
+
return [splitPath, { request: inputWithoutCursorAndDirection, type: "infinite" }];
|
|
18
|
+
}
|
|
62
19
|
return [
|
|
63
20
|
splitPath,
|
|
64
21
|
{
|
|
65
|
-
...typeof
|
|
66
|
-
...typeof params !== "undefined" && { params },
|
|
22
|
+
...typeof request !== "undefined" && request !== skipToken && { request },
|
|
67
23
|
...type && type !== "any" && { type }
|
|
68
24
|
}
|
|
69
25
|
];
|
|
70
26
|
}
|
|
27
|
+
|
|
28
|
+
// src/query.ts
|
|
29
|
+
import { queryOptions, skipToken as skipToken2 } from "@tanstack/react-query";
|
|
71
30
|
function tuyauQueryOptions(options) {
|
|
72
|
-
const {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
...opts?.tuyau,
|
|
82
|
-
...effectiveAbortOnUnmount ? { signal: queryFnContext.signal } : { signal: null }
|
|
83
|
-
}
|
|
31
|
+
const { request, routeName, opts, queryKey, client, globalOptions } = options;
|
|
32
|
+
const queryFn = invoke(() => {
|
|
33
|
+
if (request === skipToken2) return skipToken2;
|
|
34
|
+
return async (queryFnContext) => {
|
|
35
|
+
const effectiveAbortOnUnmount = opts?.tuyau?.abortOnUnmount ?? globalOptions?.abortOnUnmount ?? false;
|
|
36
|
+
return await client.request(routeName, {
|
|
37
|
+
...request,
|
|
38
|
+
...effectiveAbortOnUnmount ? { signal: queryFnContext.signal } : {}
|
|
39
|
+
});
|
|
84
40
|
};
|
|
85
|
-
return await client.$fetch({
|
|
86
|
-
paths: requestPath,
|
|
87
|
-
input: payload,
|
|
88
|
-
queryOptions: actualOpts
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
return Object.assign(queryOptions({ ...opts, queryKey, queryFn }), {
|
|
92
|
-
tuyau: { path, type: "query" }
|
|
93
41
|
});
|
|
94
|
-
}
|
|
95
|
-
function extractInputAndPath(input, path) {
|
|
96
|
-
if (typeof input !== "object" || input === null || !("payload" in input) && !("params" in input)) {
|
|
97
|
-
return { payload: input, requestPath: path };
|
|
98
|
-
}
|
|
99
|
-
const { payload, params } = input;
|
|
100
|
-
const requestPath = buildRequestPath(path, params);
|
|
101
|
-
return { payload, requestPath };
|
|
42
|
+
return queryOptions({ ...opts, queryKey, queryFn });
|
|
102
43
|
}
|
|
103
44
|
|
|
104
45
|
// src/infinite_query.ts
|
|
105
46
|
import {
|
|
106
47
|
infiniteQueryOptions,
|
|
107
|
-
skipToken as
|
|
48
|
+
skipToken as skipToken3
|
|
108
49
|
} from "@tanstack/react-query";
|
|
109
|
-
function extractInfiniteInputAndPath(input, path, pageParamKey, pageParam) {
|
|
110
|
-
if (typeof input !== "object" || input === null || !("payload" in input) && !("params" in input)) {
|
|
111
|
-
const payload2 = typeof input === "object" && input !== null ? input : {};
|
|
112
|
-
const enhancedPayload2 = { ...payload2, [pageParamKey]: pageParam };
|
|
113
|
-
return { payload: enhancedPayload2, requestPath: path };
|
|
114
|
-
}
|
|
115
|
-
const { payload, params } = input;
|
|
116
|
-
const requestPath = buildRequestPath(path, params);
|
|
117
|
-
const enhancedPayload = { ...payload, [pageParamKey]: pageParam };
|
|
118
|
-
return { payload: enhancedPayload, requestPath };
|
|
119
|
-
}
|
|
120
50
|
function tuyauInfiniteQueryOptions(options) {
|
|
121
|
-
const {
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
51
|
+
const { request, routeName, opts, queryKey, client, globalOptions } = options;
|
|
52
|
+
const queryFn = invoke(() => {
|
|
53
|
+
if (request === skipToken3) return skipToken3;
|
|
54
|
+
return async (queryFnContext) => {
|
|
55
|
+
const { pageParam } = queryFnContext;
|
|
56
|
+
const effectiveAbortOnUnmount = opts?.tuyau?.abortOnUnmount ?? globalOptions?.abortOnUnmount ?? false;
|
|
57
|
+
const pageParamKey = opts?.pageParamKey || "page";
|
|
58
|
+
let requestArgs;
|
|
59
|
+
if (typeof request === "object" && request !== null) {
|
|
60
|
+
if (pageParam !== void 0) {
|
|
61
|
+
requestArgs = {
|
|
62
|
+
...request,
|
|
63
|
+
query: { ...request.query, [pageParamKey]: pageParam }
|
|
64
|
+
};
|
|
65
|
+
} else {
|
|
66
|
+
requestArgs = request;
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
requestArgs = { query: pageParam !== void 0 ? { [pageParamKey]: pageParam } : {} };
|
|
140
70
|
}
|
|
71
|
+
return await client.request(routeName, {
|
|
72
|
+
...requestArgs,
|
|
73
|
+
...effectiveAbortOnUnmount ? { signal: queryFnContext.signal } : {}
|
|
74
|
+
});
|
|
141
75
|
};
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
queryKey,
|
|
152
|
-
queryFn,
|
|
153
|
-
initialPageParam: opts?.initialPageParam ?? null
|
|
154
|
-
}),
|
|
155
|
-
{ tuyau: { path, type: "infinite" } }
|
|
156
|
-
);
|
|
76
|
+
});
|
|
77
|
+
return infiniteQueryOptions({
|
|
78
|
+
...opts,
|
|
79
|
+
queryKey,
|
|
80
|
+
queryFn,
|
|
81
|
+
initialPageParam: opts?.initialPageParam ?? 1,
|
|
82
|
+
getNextPageParam: opts?.getNextPageParam ?? (() => null),
|
|
83
|
+
getPreviousPageParam: opts?.getPreviousPageParam
|
|
84
|
+
});
|
|
157
85
|
}
|
|
158
86
|
|
|
159
87
|
// src/mutation.ts
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
88
|
+
import { mutationOptions } from "@tanstack/react-query";
|
|
89
|
+
function getMutationKeyInternal(options) {
|
|
90
|
+
const key = [options.segments.flatMap((part) => part.split("."))];
|
|
91
|
+
return key;
|
|
163
92
|
}
|
|
164
|
-
function
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
function tuyauMutationOptions(args) {
|
|
171
|
-
const { opts, path, client, overrides } = args;
|
|
172
|
-
const queryClient = unwrapLazyArg(args.queryClient);
|
|
173
|
-
const mutationKey = getMutationKeyInternal(path);
|
|
174
|
-
const defaultOpts = queryClient.defaultMutationOptions(
|
|
175
|
-
queryClient.getMutationDefaults(mutationKey)
|
|
176
|
-
);
|
|
177
|
-
const mutationSuccessOverride = overrides?.onSuccess ?? ((options) => options.originalFn());
|
|
178
|
-
const mutationFn = async (input) => {
|
|
179
|
-
const requestPath = buildRequestPath(path, input.params);
|
|
180
|
-
return await client.$fetch({ paths: requestPath, input: input.payload });
|
|
181
|
-
};
|
|
182
|
-
return {
|
|
183
|
-
...opts,
|
|
184
|
-
mutationKey,
|
|
185
|
-
mutationFn,
|
|
186
|
-
onSuccess(data, variables, context) {
|
|
187
|
-
const originalFn = () => {
|
|
188
|
-
if (opts?.onSuccess) return opts.onSuccess(data, variables, context);
|
|
189
|
-
if (defaultOpts?.onSuccess) return defaultOpts.onSuccess(data, variables, context);
|
|
190
|
-
};
|
|
191
|
-
return mutationSuccessOverride({
|
|
192
|
-
originalFn,
|
|
193
|
-
queryClient,
|
|
194
|
-
meta: opts?.meta ?? defaultOpts?.meta ?? {}
|
|
195
|
-
});
|
|
196
|
-
},
|
|
197
|
-
tuyau: createTuyauOptionsResult({ path })
|
|
93
|
+
function tuyauMutationOptions(options) {
|
|
94
|
+
const { opts, routeName, client } = options;
|
|
95
|
+
const mutationKey = getMutationKeyInternal({ segments: routeName.split(".") });
|
|
96
|
+
const mutationFn = async (request) => {
|
|
97
|
+
const requestArgs = request || {};
|
|
98
|
+
return await client.request(routeName, requestArgs);
|
|
198
99
|
};
|
|
100
|
+
return mutationOptions({ ...opts, mutationKey, mutationFn });
|
|
199
101
|
}
|
|
200
102
|
|
|
201
103
|
// src/main.ts
|
|
202
|
-
function
|
|
203
|
-
return
|
|
204
|
-
const fnName = paths.at(-1);
|
|
205
|
-
const path = paths.slice(0, -1);
|
|
206
|
-
const patternPath = patternPaths ? patternPaths.slice(0, -1) : path;
|
|
207
|
-
const [arg1, arg2] = args;
|
|
208
|
-
if (fnName === "queryOptions") {
|
|
209
|
-
return tuyauQueryOptions({
|
|
210
|
-
input: arg1,
|
|
211
|
-
opts: arg2 || {},
|
|
212
|
-
queryKey: getQueryKeyInternal(patternPath, arg1, "query"),
|
|
213
|
-
queryClient: unwrapLazyArg(options.queryClient),
|
|
214
|
-
client: options.client,
|
|
215
|
-
path,
|
|
216
|
-
globalOptions: options.globalOptions
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
if (fnName === "infiniteQueryOptions") {
|
|
220
|
-
return tuyauInfiniteQueryOptions({
|
|
221
|
-
input: arg1,
|
|
222
|
-
opts: arg2 || {},
|
|
223
|
-
queryKey: getQueryKeyInternal(patternPath, arg1, "infinite"),
|
|
224
|
-
queryClient: unwrapLazyArg(options.queryClient),
|
|
225
|
-
client: options.client,
|
|
226
|
-
path,
|
|
227
|
-
globalOptions: options.globalOptions
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
if (fnName === "queryKey") return getQueryKeyInternal(patternPath, arg1, "query");
|
|
231
|
-
if (fnName === "infiniteQueryKey") return getQueryKeyInternal(patternPath, arg1, "infinite");
|
|
232
|
-
if (fnName === "pathKey") return getQueryKeyInternal(patternPath);
|
|
233
|
-
if (fnName === "queryFilter") {
|
|
234
|
-
return { ...arg2, queryKey: getQueryKeyInternal(patternPath, arg1, "query") };
|
|
235
|
-
}
|
|
236
|
-
if (fnName === "infiniteQueryFilter") {
|
|
237
|
-
return { ...arg2, queryKey: getQueryKeyInternal(patternPath, arg1, "infinite") };
|
|
238
|
-
}
|
|
239
|
-
if (fnName === "pathFilter") {
|
|
240
|
-
return { ...arg1, queryKey: getQueryKeyInternal(patternPath) };
|
|
241
|
-
}
|
|
242
|
-
if (fnName === "mutationOptions") {
|
|
243
|
-
return tuyauMutationOptions({
|
|
244
|
-
path,
|
|
245
|
-
opts: arg1,
|
|
246
|
-
queryClient: unwrapLazyArg(options.queryClient),
|
|
247
|
-
client: options.client
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
if (fnName === "mutationKey") return getMutationKeyInternal(path);
|
|
251
|
-
const newProxy = executeIfRouteParamCall({ fnName, body: args[0] });
|
|
252
|
-
if (newProxy) return newProxy;
|
|
253
|
-
throw new Error(`Method ${fnName} not found on Tuyau client`);
|
|
254
|
-
});
|
|
104
|
+
function segmentsToRouteName(segments) {
|
|
105
|
+
return segments.join(".");
|
|
255
106
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
() =>
|
|
265
|
-
|
|
266
|
-
|
|
107
|
+
function createTuyauReactQueryClient(options) {
|
|
108
|
+
const { client, globalOptions } = options;
|
|
109
|
+
function makeReactQueryNamed(segments) {
|
|
110
|
+
const routeName = segmentsToRouteName(segments);
|
|
111
|
+
const decoratedEndpoint = {
|
|
112
|
+
/**
|
|
113
|
+
* Queries
|
|
114
|
+
*/
|
|
115
|
+
queryOptions: (request, opts) => {
|
|
116
|
+
return tuyauQueryOptions({
|
|
117
|
+
opts,
|
|
118
|
+
client,
|
|
119
|
+
request,
|
|
120
|
+
routeName,
|
|
121
|
+
globalOptions,
|
|
122
|
+
queryKey: buildKey({ segments, request, type: "query" })
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
queryKey: (request) => buildKey({ segments, request, type: "query" }),
|
|
126
|
+
queryFilter: (request, filters) => ({
|
|
127
|
+
queryKey: buildKey({ segments, request, type: "query" }),
|
|
128
|
+
...filters
|
|
267
129
|
}),
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
130
|
+
/**
|
|
131
|
+
* Infinite Queries
|
|
132
|
+
*/
|
|
133
|
+
infiniteQueryOptions: (request, opts) => {
|
|
134
|
+
return tuyauInfiniteQueryOptions({
|
|
135
|
+
opts,
|
|
136
|
+
client,
|
|
137
|
+
request,
|
|
138
|
+
routeName,
|
|
139
|
+
globalOptions,
|
|
140
|
+
queryKey: buildKey({ segments, request, type: "infinite" })
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
infiniteQueryKey: (request) => buildKey({ segments, request, type: "infinite" }),
|
|
144
|
+
infiniteQueryFilter: (request, filters) => ({
|
|
145
|
+
queryKey: buildKey({ segments, request, type: "infinite" }),
|
|
146
|
+
...filters
|
|
147
|
+
}),
|
|
148
|
+
/**
|
|
149
|
+
* Mutations
|
|
150
|
+
*/
|
|
151
|
+
mutationOptions: (opts) => tuyauMutationOptions({ opts, client, routeName }),
|
|
152
|
+
mutationKey: () => getMutationKeyInternal({ segments }),
|
|
153
|
+
/**
|
|
154
|
+
* Paths
|
|
155
|
+
*/
|
|
156
|
+
pathKey: () => buildKey({ segments, type: "any" }),
|
|
157
|
+
pathFilter: (filters) => ({
|
|
158
|
+
queryKey: buildKey({ segments, type: "any" }),
|
|
159
|
+
...filters
|
|
160
|
+
})
|
|
161
|
+
};
|
|
162
|
+
return new Proxy(decoratedEndpoint, {
|
|
163
|
+
get: (target, prop) => {
|
|
164
|
+
if (prop in target) return target[prop];
|
|
165
|
+
return makeReactQueryNamed([...segments, String(prop)]);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
281
168
|
}
|
|
282
|
-
return
|
|
169
|
+
return makeReactQueryNamed([]);
|
|
283
170
|
}
|
|
284
171
|
export {
|
|
285
|
-
|
|
286
|
-
|
|
172
|
+
createTuyauReactQueryClient,
|
|
173
|
+
getMutationKeyInternal,
|
|
174
|
+
tuyauMutationOptions,
|
|
175
|
+
tuyauQueryOptions
|
|
287
176
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuyau/react-query",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "1.0.0-beta.0",
|
|
5
5
|
"description": "React Query plugin for Tuyau",
|
|
6
6
|
"author": "Julien Ripouteau <julien@ripouteau.com>",
|
|
7
7
|
"license": "ISC",
|
|
@@ -15,21 +15,17 @@
|
|
|
15
15
|
],
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"@tanstack/react-query": "^5.74.7",
|
|
18
|
-
"@tuyau/
|
|
19
|
-
},
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"@tuyau/utils": "0.0.9"
|
|
18
|
+
"@tuyau/core": "1.0.0-beta.2"
|
|
22
19
|
},
|
|
23
20
|
"devDependencies": {
|
|
24
|
-
"@adonisjs/core": "^
|
|
25
|
-
"@happy-dom/global-registrator": "^
|
|
26
|
-
"@tanstack/react-query": "^5.
|
|
21
|
+
"@adonisjs/core": "^7.0.0-next.10",
|
|
22
|
+
"@happy-dom/global-registrator": "^20.0.10",
|
|
23
|
+
"@tanstack/react-query": "^5.90.7",
|
|
27
24
|
"@testing-library/react": "^16.3.0",
|
|
28
|
-
"@types/react": "^19.
|
|
29
|
-
"@vinejs/vine": "^
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"@tuyau/client": "0.2.11-next.2"
|
|
25
|
+
"@types/react": "^19.2.2",
|
|
26
|
+
"@vinejs/vine": "^4.1.0",
|
|
27
|
+
"react": "^19.2.0",
|
|
28
|
+
"@tuyau/core": "1.0.0-beta.2"
|
|
33
29
|
},
|
|
34
30
|
"tsup": {
|
|
35
31
|
"entry": [
|
|
@@ -43,14 +39,14 @@
|
|
|
43
39
|
},
|
|
44
40
|
"publishConfig": {
|
|
45
41
|
"access": "public",
|
|
46
|
-
"tag": "
|
|
42
|
+
"tag": "beta"
|
|
47
43
|
},
|
|
48
44
|
"scripts": {
|
|
49
45
|
"lint": "eslint .",
|
|
50
46
|
"typecheck": "tsc --noEmit",
|
|
51
47
|
"build": "tsup-node",
|
|
52
|
-
"test": "
|
|
53
|
-
"quick:test": "node --enable-source-maps
|
|
48
|
+
"test": "pnpm quick:test",
|
|
49
|
+
"quick:test": "node --import=@poppinss/ts-exec --enable-source-maps bin/test.ts --force-exit",
|
|
54
50
|
"checks": "pnpm lint && pnpm typecheck"
|
|
55
51
|
}
|
|
56
52
|
}
|