@@ -49,6 +49,37 @@ export const listPets = (
49
49
export const getListPetsQueryKey = ( params ?: ListPetsParams , version = 1 ) =>
50
50
[ `/v${ version } /pets` , ...( params ? [ params ] : [ ] ) ] as const ;
51
51
52
+ export const getListPetsInfiniteQueryOptions = <
53
+ TData = Awaited < ReturnType < typeof listPets > > ,
54
+ TError = ErrorType < Error > ,
55
+ > (
56
+ params ?: ListPetsParams ,
57
+ version = 1 ,
58
+ options ?: {
59
+ query ?: UseInfiniteQueryOptions <
60
+ Awaited < ReturnType < typeof listPets > > ,
61
+ TError ,
62
+ TData
63
+ > ;
64
+ } ,
65
+ ) : UseInfiniteQueryOptions <
66
+ Awaited < ReturnType < typeof listPets > > ,
67
+ TError ,
68
+ TData
69
+ > & { queryKey : QueryKey } => {
70
+ const { query : queryOptions } = options ?? { } ;
71
+
72
+ const queryKey =
73
+ queryOptions ?. queryKey ?? getListPetsQueryKey ( params , version ) ;
74
+
75
+ const queryFn : QueryFunction < Awaited < ReturnType < typeof listPets > > > = ( {
76
+ signal,
77
+ pageParam,
78
+ } ) => listPets ( { limit : pageParam , ...params } , version , signal ) ;
79
+
80
+ return { queryKey, queryFn, enabled : ! ! version , ...queryOptions } ;
81
+ } ;
82
+
52
83
export type ListPetsInfiniteQueryResult = NonNullable <
53
84
Awaited < ReturnType < typeof listPets > >
54
85
> ;
@@ -68,30 +99,49 @@ export const useListPetsInfinite = <
68
99
> ;
69
100
} ,
70
101
) : UseInfiniteQueryResult < TData , TError > & { queryKey : QueryKey } => {
102
+ const listPetsInfiniteQueryOptions = getListPetsInfiniteQueryOptions (
103
+ params ,
104
+ version ,
105
+ options ,
106
+ ) ;
107
+
108
+ const query = useInfiniteQuery (
109
+ listPetsInfiniteQueryOptions ,
110
+ ) as UseInfiniteQueryResult < TData , TError > & {
111
+ queryKey : QueryKey ;
112
+ } ;
113
+
114
+ query . queryKey = listPetsInfiniteQueryOptions . queryKey ;
115
+
116
+ return query ;
117
+ } ;
118
+
119
+ export const getListPetsQueryOptions = <
120
+ TData = Awaited < ReturnType < typeof listPets > > ,
121
+ TError = ErrorType < Error > ,
122
+ > (
123
+ params ?: ListPetsParams ,
124
+ version = 1 ,
125
+ options ?: {
126
+ query ?: UseQueryOptions <
127
+ Awaited < ReturnType < typeof listPets > > ,
128
+ TError ,
129
+ TData
130
+ > ;
131
+ } ,
132
+ ) : UseQueryOptions < Awaited < ReturnType < typeof listPets > > , TError , TData > & {
133
+ queryKey : QueryKey ;
134
+ } => {
71
135
const { query : queryOptions } = options ?? { } ;
72
136
73
137
const queryKey =
74
138
queryOptions ?. queryKey ?? getListPetsQueryKey ( params , version ) ;
75
139
76
140
const queryFn : QueryFunction < Awaited < ReturnType < typeof listPets > > > = ( {
77
141
signal,
78
- pageParam,
79
- } ) => listPets ( { limit : pageParam , ...params } , version , signal ) ;
80
-
81
- const query = useInfiniteQuery <
82
- Awaited < ReturnType < typeof listPets > > ,
83
- TError ,
84
- TData
85
- > ( {
86
- queryKey,
87
- queryFn,
88
- enabled : ! ! version ,
89
- ...queryOptions ,
90
- } ) as UseInfiniteQueryResult < TData , TError > & { queryKey : QueryKey } ;
91
-
92
- query . queryKey = queryKey ;
142
+ } ) => listPets ( params , version , signal ) ;
93
143
94
- return query ;
144
+ return { queryKey , queryFn , enabled : ! ! version , ... queryOptions } ;
95
145
} ;
96
146
97
147
export type ListPetsQueryResult = NonNullable <
@@ -113,23 +163,18 @@ export const useListPets = <
113
163
> ;
114
164
} ,
115
165
) : UseQueryResult < TData , TError > & { queryKey : QueryKey } => {
116
- const { query : queryOptions } = options ?? { } ;
117
-
118
- const queryKey =
119
- queryOptions ?. queryKey ?? getListPetsQueryKey ( params , version ) ;
120
-
121
- const queryFn : QueryFunction < Awaited < ReturnType < typeof listPets > > > = ( {
122
- signal,
123
- } ) => listPets ( params , version , signal ) ;
166
+ const listPetsQueryOptions = getListPetsQueryOptions (
167
+ params ,
168
+ version ,
169
+ options ,
170
+ ) ;
124
171
125
- const query = useQuery < Awaited < ReturnType < typeof listPets > > , TError , TData > ( {
126
- queryKey,
127
- queryFn,
128
- enabled : ! ! version ,
129
- ...queryOptions ,
130
- } ) as UseQueryResult < TData , TError > & { queryKey : QueryKey } ;
172
+ const query = useQuery ( listPetsQueryOptions ) as UseQueryResult <
173
+ TData ,
174
+ TError
175
+ > & { queryKey : QueryKey } ;
131
176
132
- query . queryKey = queryKey ;
177
+ query . queryKey = listPetsQueryOptions . queryKey ;
133
178
134
179
return query ;
135
180
} ;
@@ -146,40 +191,68 @@ export const createPets = (createPetsBody: CreatePetsBody, version = 1) => {
146
191
} ) ;
147
192
} ;
148
193
149
- export type CreatePetsMutationResult = NonNullable <
150
- Awaited < ReturnType < typeof createPets > >
151
- > ;
152
- export type CreatePetsMutationBody = CreatePetsBody ;
153
- export type CreatePetsMutationError = ErrorType < Error > ;
154
-
155
- export const useCreatePets = <
194
+ export const getCreatePetsMutationOptions = <
156
195
TError = ErrorType < Error > ,
157
196
TContext = unknown ,
158
197
> ( options ?: {
159
198
mutation ?: UseMutationOptions <
160
199
Awaited < ReturnType < typeof createPets > > ,
161
200
TError ,
162
- { data : CreatePetsBody ; version ?: number } ,
201
+ {
202
+ data : CreatePetsBody ;
203
+ version ?: number ;
204
+ } ,
163
205
TContext
164
206
> ;
165
- } ) => {
207
+ } ) : UseMutationOptions <
208
+ Awaited < ReturnType < typeof createPets > > ,
209
+ TError ,
210
+ {
211
+ data : CreatePetsBody ;
212
+ version ?: number ;
213
+ } ,
214
+ TContext
215
+ > => {
166
216
const { mutation : mutationOptions } = options ?? { } ;
167
217
168
218
const mutationFn : MutationFunction <
169
219
Awaited < ReturnType < typeof createPets > > ,
170
- { data : CreatePetsBody ; version ?: number }
220
+ {
221
+ data : CreatePetsBody ;
222
+ version ?: number ;
223
+ }
171
224
> = ( props ) => {
172
225
const { data, version } = props ?? { } ;
173
226
174
227
return createPets ( data , version ) ;
175
228
} ;
176
229
177
- return useMutation <
230
+ return { mutationFn, ...mutationOptions } ;
231
+ } ;
232
+
233
+ export type CreatePetsMutationResult = NonNullable <
234
+ Awaited < ReturnType < typeof createPets > >
235
+ > ;
236
+ export type CreatePetsMutationBody = CreatePetsBody ;
237
+ export type CreatePetsMutationError = ErrorType < Error > ;
238
+
239
+ export const useCreatePets = <
240
+ TError = ErrorType < Error > ,
241
+ TContext = unknown ,
242
+ > ( options ?: {
243
+ mutation ?: UseMutationOptions <
178
244
Awaited < ReturnType < typeof createPets > > ,
179
245
TError ,
180
- { data : CreatePetsBody ; version ?: number } ,
246
+ {
247
+ data : CreatePetsBody ;
248
+ version ?: number ;
249
+ } ,
181
250
TContext
182
- > ( mutationFn , mutationOptions ) ;
251
+ > ;
252
+ } ) => {
253
+ const createPetsMutationOptions = getCreatePetsMutationOptions ( options ) ;
254
+
255
+ return useMutation ( createPetsMutationOptions ) ;
183
256
} ;
184
257
185
258
/**
@@ -248,6 +321,36 @@ export const showPetById = (
248
321
export const getShowPetByIdQueryKey = ( petId : string , version = 1 ) =>
249
322
[ `/v${ version } /pets/${ petId } ` ] as const ;
250
323
324
+ export const getShowPetByIdInfiniteQueryOptions = <
325
+ TData = Awaited < ReturnType < typeof showPetById > > ,
326
+ TError = ErrorType < Error > ,
327
+ > (
328
+ petId : string ,
329
+ version = 1 ,
330
+ options ?: {
331
+ query ?: UseInfiniteQueryOptions <
332
+ Awaited < ReturnType < typeof showPetById > > ,
333
+ TError ,
334
+ TData
335
+ > ;
336
+ } ,
337
+ ) : UseInfiniteQueryOptions <
338
+ Awaited < ReturnType < typeof showPetById > > ,
339
+ TError ,
340
+ TData
341
+ > & { queryKey : QueryKey } => {
342
+ const { query : queryOptions } = options ?? { } ;
343
+
344
+ const queryKey =
345
+ queryOptions ?. queryKey ?? getShowPetByIdQueryKey ( petId , version ) ;
346
+
347
+ const queryFn : QueryFunction < Awaited < ReturnType < typeof showPetById > > > = ( {
348
+ signal,
349
+ } ) => showPetById ( petId , version , signal ) ;
350
+
351
+ return { queryKey, queryFn, enabled : ! ! ( version && petId ) , ...queryOptions } ;
352
+ } ;
353
+
251
354
export type ShowPetByIdInfiniteQueryResult = NonNullable <
252
355
Awaited < ReturnType < typeof showPetById > >
253
356
> ;
@@ -267,6 +370,39 @@ export const useShowPetByIdInfinite = <
267
370
> ;
268
371
} ,
269
372
) : UseInfiniteQueryResult < TData , TError > & { queryKey : QueryKey } => {
373
+ const showPetByIdInfiniteQueryOptions = getShowPetByIdInfiniteQueryOptions (
374
+ petId ,
375
+ version ,
376
+ options ,
377
+ ) ;
378
+
379
+ const query = useInfiniteQuery (
380
+ showPetByIdInfiniteQueryOptions ,
381
+ ) as UseInfiniteQueryResult < TData , TError > & {
382
+ queryKey : QueryKey ;
383
+ } ;
384
+
385
+ query . queryKey = showPetByIdInfiniteQueryOptions . queryKey ;
386
+
387
+ return query ;
388
+ } ;
389
+
390
+ export const getShowPetByIdQueryOptions = <
391
+ TData = Awaited < ReturnType < typeof showPetById > > ,
392
+ TError = ErrorType < Error > ,
393
+ > (
394
+ petId : string ,
395
+ version = 1 ,
396
+ options ?: {
397
+ query ?: UseQueryOptions <
398
+ Awaited < ReturnType < typeof showPetById > > ,
399
+ TError ,
400
+ TData
401
+ > ;
402
+ } ,
403
+ ) : UseQueryOptions < Awaited < ReturnType < typeof showPetById > > , TError , TData > & {
404
+ queryKey : QueryKey ;
405
+ } => {
270
406
const { query : queryOptions } = options ?? { } ;
271
407
272
408
const queryKey =
@@ -276,20 +412,7 @@ export const useShowPetByIdInfinite = <
276
412
signal,
277
413
} ) => showPetById ( petId , version , signal ) ;
278
414
279
- const query = useInfiniteQuery <
280
- Awaited < ReturnType < typeof showPetById > > ,
281
- TError ,
282
- TData
283
- > ( {
284
- queryKey,
285
- queryFn,
286
- enabled : ! ! ( version && petId ) ,
287
- ...queryOptions ,
288
- } ) as UseInfiniteQueryResult < TData , TError > & { queryKey : QueryKey } ;
289
-
290
- query . queryKey = queryKey ;
291
-
292
- return query ;
415
+ return { queryKey, queryFn, enabled : ! ! ( version && petId ) , ...queryOptions } ;
293
416
} ;
294
417
295
418
export type ShowPetByIdQueryResult = NonNullable <
@@ -311,27 +434,18 @@ export const useShowPetById = <
311
434
> ;
312
435
} ,
313
436
) : UseQueryResult < TData , TError > & { queryKey : QueryKey } => {
314
- const { query : queryOptions } = options ?? { } ;
315
-
316
- const queryKey =
317
- queryOptions ?. queryKey ?? getShowPetByIdQueryKey ( petId , version ) ;
318
-
319
- const queryFn : QueryFunction < Awaited < ReturnType < typeof showPetById > > > = ( {
320
- signal,
321
- } ) => showPetById ( petId , version , signal ) ;
322
-
323
- const query = useQuery <
324
- Awaited < ReturnType < typeof showPetById > > ,
325
- TError ,
326
- TData
327
- > ( {
328
- queryKey,
329
- queryFn,
330
- enabled : ! ! ( version && petId ) ,
331
- ...queryOptions ,
332
- } ) as UseQueryResult < TData , TError > & { queryKey : QueryKey } ;
333
-
334
- query . queryKey = queryKey ;
437
+ const showPetByIdQueryOptions = getShowPetByIdQueryOptions (
438
+ petId ,
439
+ version ,
440
+ options ,
441
+ ) ;
442
+
443
+ const query = useQuery ( showPetByIdQueryOptions ) as UseQueryResult <
444
+ TData ,
445
+ TError
446
+ > & { queryKey : QueryKey } ;
447
+
448
+ query . queryKey = showPetByIdQueryOptions . queryKey ;
335
449
336
450
return query ;
337
451
} ;
1 commit comments
vercel[bot] commentedon Apr 11, 2023
Successfully deployed to the following URLs:
orval – ./
orval-git-master-anymaniax.vercel.app
orval-anymaniax.vercel.app
orval.vercel.app
orval.dev
www.orval.dev