@kubb/plugin-react-query 3.16.2 → 3.16.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.
Files changed (38) hide show
  1. package/dist/components-CuByb-hX.js +903 -0
  2. package/dist/components-CuByb-hX.js.map +1 -0
  3. package/dist/components-DHfUELJ3.cjs +979 -0
  4. package/dist/components-DHfUELJ3.cjs.map +1 -0
  5. package/dist/components.cjs +10 -40
  6. package/dist/components.d.cts +306 -146
  7. package/dist/components.d.ts +306 -146
  8. package/dist/components.js +3 -3
  9. package/dist/generators-CNHKYwqU.js +722 -0
  10. package/dist/generators-CNHKYwqU.js.map +1 -0
  11. package/dist/generators-kx0B_Nkc.cjs +745 -0
  12. package/dist/{chunk-2LUZUNTA.js.map → generators-kx0B_Nkc.cjs.map} +1 -1
  13. package/dist/generators.cjs +6 -24
  14. package/dist/generators.d.cts +14 -13
  15. package/dist/generators.d.ts +14 -13
  16. package/dist/generators.js +4 -4
  17. package/dist/index.cjs +120 -145
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +6 -8
  20. package/dist/index.d.ts +6 -8
  21. package/dist/index.js +120 -139
  22. package/dist/index.js.map +1 -1
  23. package/dist/types-5X0s8utE.d.cts +1391 -0
  24. package/dist/types-BTEmPwHJ.d.ts +1391 -0
  25. package/package.json +23 -28
  26. package/dist/chunk-2LUZUNTA.js +0 -588
  27. package/dist/chunk-7VVTPMRL.cjs +0 -788
  28. package/dist/chunk-7VVTPMRL.cjs.map +0 -1
  29. package/dist/chunk-LT467H44.js +0 -779
  30. package/dist/chunk-LT467H44.js.map +0 -1
  31. package/dist/chunk-PIAL3C5M.cjs +0 -593
  32. package/dist/chunk-PIAL3C5M.cjs.map +0 -1
  33. package/dist/components.cjs.map +0 -1
  34. package/dist/components.js.map +0 -1
  35. package/dist/generators.cjs.map +0 -1
  36. package/dist/generators.js.map +0 -1
  37. package/dist/types-BdjqYAq1.d.cts +0 -170
  38. package/dist/types-BdjqYAq1.d.ts +0 -170
@@ -1,779 +0,0 @@
1
- import { File, Function, Type, FunctionParams } from '@kubb/react';
2
- import { isOptional } from '@kubb/oas';
3
- import { Client } from '@kubb/plugin-client/components';
4
- import { getPathParams, getComments } from '@kubb/plugin-oas/utils';
5
- import { URLPath } from '@kubb/core/utils';
6
- import { jsxs, Fragment, jsx } from '@kubb/react/jsx-runtime';
7
-
8
- // src/components/Mutation.tsx
9
- function getParams({}) {
10
- return FunctionParams.factory({});
11
- }
12
- var getTransformer = ({ operation, casing }) => {
13
- const path = new URLPath(operation.path, { casing });
14
- return [JSON.stringify({ url: path.path })].filter(Boolean);
15
- };
16
- function MutationKey({ name, typeSchemas, pathParamsType, paramsCasing, operation, typeName, transformer = getTransformer }) {
17
- const params = getParams({ });
18
- const keys = transformer({ operation, schemas: typeSchemas, casing: paramsCasing });
19
- return /* @__PURE__ */ jsxs(Fragment, { children: [
20
- /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Function.Arrow, { name, export: true, params: params.toConstructor(), singleLine: true, children: `[${keys.join(", ")}] as const` }) }),
21
- /* @__PURE__ */ jsx(File.Source, { name: typeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsx(Type, { name: typeName, export: true, children: `ReturnType<typeof ${name}>` }) })
22
- ] });
23
- }
24
- MutationKey.getParams = getParams;
25
- MutationKey.getTransformer = getTransformer;
26
- function getParams2({ paramsCasing, dataReturnType, typeSchemas }) {
27
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
28
- const mutationParams = FunctionParams.factory({
29
- ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
30
- data: typeSchemas.request?.name ? {
31
- type: typeSchemas.request?.name,
32
- optional: isOptional(typeSchemas.request?.schema)
33
- } : void 0,
34
- params: typeSchemas.queryParams?.name ? {
35
- type: typeSchemas.queryParams?.name,
36
- optional: isOptional(typeSchemas.queryParams?.schema)
37
- } : void 0,
38
- headers: typeSchemas.headerParams?.name ? {
39
- type: typeSchemas.headerParams?.name,
40
- optional: isOptional(typeSchemas.headerParams?.schema)
41
- } : void 0
42
- });
43
- const TRequest = mutationParams.toConstructor();
44
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
45
- const generics = [TData, TError, TRequest ? `{${TRequest}}` : "void", "TContext"].join(", ");
46
- return FunctionParams.factory({
47
- options: {
48
- type: `
49
- {
50
- mutation?: UseMutationOptions<${generics}> & { client?: QueryClient },
51
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"},
52
- }
53
- `,
54
- default: "{}"
55
- }
56
- });
57
- }
58
- function Mutation({
59
- name,
60
- clientName,
61
- paramsCasing,
62
- paramsType,
63
- pathParamsType,
64
- dataReturnType,
65
- typeSchemas,
66
- operation,
67
- mutationKeyName
68
- }) {
69
- const mutationKeyParams = MutationKey.getParams({
70
- pathParamsType,
71
- typeSchemas
72
- });
73
- const params = getParams2({
74
- paramsCasing,
75
- dataReturnType,
76
- typeSchemas
77
- });
78
- const clientParams = Client.getParams({
79
- paramsCasing,
80
- paramsType,
81
- typeSchemas,
82
- pathParamsType,
83
- isConfigurable: true
84
- });
85
- const mutationParams = FunctionParams.factory({
86
- ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
87
- data: typeSchemas.request?.name ? {
88
- type: typeSchemas.request?.name,
89
- optional: isOptional(typeSchemas.request?.schema)
90
- } : void 0,
91
- params: typeSchemas.queryParams?.name ? {
92
- type: typeSchemas.queryParams?.name,
93
- optional: isOptional(typeSchemas.queryParams?.schema)
94
- } : void 0,
95
- headers: typeSchemas.headerParams?.name ? {
96
- type: typeSchemas.headerParams?.name,
97
- optional: isOptional(typeSchemas.headerParams?.schema)
98
- } : void 0
99
- });
100
- const dataParams = FunctionParams.factory({
101
- data: {
102
- // No use of pathParams because useMutation can only take one argument in object form,
103
- // see https://tanstack.com/query/latest/docs/framework/react/reference/useMutation#usemutation
104
- mode: "object",
105
- children: Object.entries(mutationParams.params).reduce((acc, [key, value]) => {
106
- if (value) {
107
- acc[key] = {
108
- ...value,
109
- type: void 0
110
- };
111
- }
112
- return acc;
113
- }, {})
114
- }
115
- });
116
- const TRequest = mutationParams.toConstructor();
117
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
118
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
119
- const generics = [TData, TError, TRequest ? `{${TRequest}}` : "void", "TContext"].join(", ");
120
- return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(
121
- Function,
122
- {
123
- name,
124
- export: true,
125
- params: params.toConstructor(),
126
- JSDoc: {
127
- comments: getComments(operation)
128
- },
129
- generics: ["TContext"],
130
- children: `
131
- const { mutation = {}, client: config = {} } = options ?? {}
132
- const { client: queryClient, ...mutationOptions } = mutation;
133
- const mutationKey = mutationOptions.mutationKey ?? ${mutationKeyName}(${mutationKeyParams.toCall()})
134
-
135
- return useMutation<${generics}>({
136
- mutationFn: async(${dataParams.toConstructor()}) => {
137
- return ${clientName}(${clientParams.toCall()})
138
- },
139
- mutationKey,
140
- ...mutationOptions
141
- }, queryClient)
142
- `
143
- }
144
- ) });
145
- }
146
- function getParams3({ pathParamsType, paramsCasing, typeSchemas }) {
147
- return FunctionParams.factory({
148
- pathParams: {
149
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
150
- children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing })
151
- },
152
- data: typeSchemas.request?.name ? {
153
- type: typeSchemas.request?.name,
154
- optional: isOptional(typeSchemas.request?.schema)
155
- } : void 0,
156
- params: typeSchemas.queryParams?.name ? {
157
- type: typeSchemas.queryParams?.name,
158
- optional: isOptional(typeSchemas.queryParams?.schema)
159
- } : void 0
160
- });
161
- }
162
- var getTransformer2 = ({ operation, schemas, casing }) => {
163
- const path = new URLPath(operation.path, { casing });
164
- const keys = [
165
- path.toObject({
166
- type: "path",
167
- stringify: true
168
- }),
169
- schemas.queryParams?.name ? "...(params ? [params] : [])" : void 0,
170
- schemas.request?.name ? "...(data ? [data] : [])" : void 0
171
- ].filter(Boolean);
172
- return keys;
173
- };
174
- function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer2 }) {
175
- const params = getParams3({ pathParamsType, typeSchemas, paramsCasing });
176
- const keys = transformer({
177
- operation,
178
- schemas: typeSchemas,
179
- casing: paramsCasing
180
- });
181
- return /* @__PURE__ */ jsxs(Fragment, { children: [
182
- /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Function.Arrow, { name, export: true, params: params.toConstructor(), singleLine: true, children: `[${keys.join(", ")}] as const` }) }),
183
- /* @__PURE__ */ jsx(File.Source, { name: typeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsx(Type, { name: typeName, export: true, children: `ReturnType<typeof ${name}>` }) })
184
- ] });
185
- }
186
- QueryKey.getParams = getParams3;
187
- QueryKey.getTransformer = getTransformer2;
188
- function getParams4({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
189
- if (paramsType === "object") {
190
- return FunctionParams.factory({
191
- data: {
192
- mode: "object",
193
- children: {
194
- ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
195
- data: typeSchemas.request?.name ? {
196
- type: typeSchemas.request?.name,
197
- optional: isOptional(typeSchemas.request?.schema)
198
- } : void 0,
199
- params: typeSchemas.queryParams?.name ? {
200
- type: typeSchemas.queryParams?.name,
201
- optional: isOptional(typeSchemas.queryParams?.schema)
202
- } : void 0,
203
- headers: typeSchemas.headerParams?.name ? {
204
- type: typeSchemas.headerParams?.name,
205
- optional: isOptional(typeSchemas.headerParams?.schema)
206
- } : void 0
207
- }
208
- },
209
- config: {
210
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }",
211
- default: "{}"
212
- }
213
- });
214
- }
215
- return FunctionParams.factory({
216
- pathParams: typeSchemas.pathParams?.name ? {
217
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
218
- children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
219
- optional: isOptional(typeSchemas.pathParams?.schema)
220
- } : void 0,
221
- data: typeSchemas.request?.name ? {
222
- type: typeSchemas.request?.name,
223
- optional: isOptional(typeSchemas.request?.schema)
224
- } : void 0,
225
- params: typeSchemas.queryParams?.name ? {
226
- type: typeSchemas.queryParams?.name,
227
- optional: isOptional(typeSchemas.queryParams?.schema)
228
- } : void 0,
229
- headers: typeSchemas.headerParams?.name ? {
230
- type: typeSchemas.headerParams?.name,
231
- optional: isOptional(typeSchemas.headerParams?.schema)
232
- } : void 0,
233
- config: {
234
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }",
235
- default: "{}"
236
- }
237
- });
238
- }
239
- function QueryOptions({ name, clientName, dataReturnType, typeSchemas, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
240
- const params = getParams4({ paramsType, paramsCasing, pathParamsType, typeSchemas });
241
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
242
- const TError = typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error";
243
- const clientParams = Client.getParams({
244
- typeSchemas,
245
- paramsCasing,
246
- paramsType,
247
- pathParamsType,
248
- isConfigurable: true
249
- });
250
- const queryKeyParams = QueryKey.getParams({
251
- pathParamsType,
252
- typeSchemas,
253
- paramsCasing
254
- });
255
- const enabled = Object.entries(queryKeyParams.flatParams).map(([key, item]) => item && !item.optional ? key : void 0).filter(Boolean).join("&& ");
256
- const enabledText = enabled ? `enabled: !!(${enabled}),` : "";
257
- return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Function, { name, export: true, params: params.toConstructor(), children: `
258
- const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
259
- return queryOptions<${TData}, ResponseErrorConfig<${TError}>, ${TData}, typeof queryKey>({
260
- ${enabledText}
261
- queryKey,
262
- queryFn: async ({ signal }) => {
263
- config.signal = signal
264
- return ${clientName}(${clientParams.toCall({})})
265
- },
266
- })
267
- ` }) });
268
- }
269
- QueryOptions.getParams = getParams4;
270
- function getParams5({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }) {
271
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
272
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
273
- if (paramsType === "object") {
274
- return FunctionParams.factory({
275
- data: {
276
- mode: "object",
277
- children: {
278
- ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
279
- data: typeSchemas.request?.name ? {
280
- type: typeSchemas.request?.name,
281
- optional: isOptional(typeSchemas.request?.schema)
282
- } : void 0,
283
- params: typeSchemas.queryParams?.name ? {
284
- type: typeSchemas.queryParams?.name,
285
- optional: isOptional(typeSchemas.queryParams?.schema)
286
- } : void 0,
287
- headers: typeSchemas.headerParams?.name ? {
288
- type: typeSchemas.headerParams?.name,
289
- optional: isOptional(typeSchemas.headerParams?.schema)
290
- } : void 0
291
- }
292
- },
293
- options: {
294
- type: `
295
- {
296
- query?: Partial<QueryObserverOptions<${[TData, TError, "TData", "TQueryData", "TQueryKey"].join(", ")}>> & { client?: QueryClient },
297
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"}
298
- }
299
- `,
300
- default: "{}"
301
- }
302
- });
303
- }
304
- return FunctionParams.factory({
305
- pathParams: typeSchemas.pathParams?.name ? {
306
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
307
- children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
308
- optional: isOptional(typeSchemas.pathParams?.schema)
309
- } : void 0,
310
- data: typeSchemas.request?.name ? {
311
- type: typeSchemas.request?.name,
312
- optional: isOptional(typeSchemas.request?.schema)
313
- } : void 0,
314
- params: typeSchemas.queryParams?.name ? {
315
- type: typeSchemas.queryParams?.name,
316
- optional: isOptional(typeSchemas.queryParams?.schema)
317
- } : void 0,
318
- headers: typeSchemas.headerParams?.name ? {
319
- type: typeSchemas.headerParams?.name,
320
- optional: isOptional(typeSchemas.headerParams?.schema)
321
- } : void 0,
322
- options: {
323
- type: `
324
- {
325
- query?: Partial<QueryObserverOptions<${[TData, TError, "TData", "TQueryData", "TQueryKey"].join(", ")}>> & { client?: QueryClient },
326
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"}
327
- }
328
- `,
329
- default: "{}"
330
- }
331
- });
332
- }
333
- function Query({
334
- name,
335
- queryKeyTypeName,
336
- queryOptionsName,
337
- queryKeyName,
338
- paramsType,
339
- paramsCasing,
340
- pathParamsType,
341
- dataReturnType,
342
- typeSchemas,
343
- operation
344
- }) {
345
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
346
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
347
- const returnType = `UseQueryResult<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
348
- const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
349
- const queryKeyParams = QueryKey.getParams({
350
- pathParamsType,
351
- typeSchemas,
352
- paramsCasing
353
- });
354
- const queryOptionsParams = QueryOptions.getParams({
355
- paramsType,
356
- pathParamsType,
357
- typeSchemas,
358
- paramsCasing
359
- });
360
- const params = getParams5({
361
- paramsCasing,
362
- paramsType,
363
- pathParamsType,
364
- dataReturnType,
365
- typeSchemas
366
- });
367
- const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()})`;
368
- return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(
369
- Function,
370
- {
371
- name,
372
- export: true,
373
- generics: generics.join(", "),
374
- params: params.toConstructor(),
375
- JSDoc: {
376
- comments: getComments(operation)
377
- },
378
- children: `
379
- const { query: { client: queryClient, ...queryOptions } = {}, client: config = {} } = options ?? {}
380
- const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
381
-
382
- const query = useQuery({
383
- ...${queryOptions},
384
- queryKey,
385
- ...queryOptions
386
- } as unknown as QueryObserverOptions, queryClient) as ${returnType}
387
-
388
- query.queryKey = queryKey as TQueryKey
389
-
390
- return query
391
- `
392
- }
393
- ) });
394
- }
395
- Query.getParams = getParams5;
396
- function getParams6({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
397
- if (paramsType === "object") {
398
- return FunctionParams.factory({
399
- data: {
400
- mode: "object",
401
- children: {
402
- ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
403
- data: typeSchemas.request?.name ? {
404
- type: typeSchemas.request?.name,
405
- optional: isOptional(typeSchemas.request?.schema)
406
- } : void 0,
407
- params: typeSchemas.queryParams?.name ? {
408
- type: typeSchemas.queryParams?.name,
409
- optional: isOptional(typeSchemas.queryParams?.schema)
410
- } : void 0,
411
- headers: typeSchemas.headerParams?.name ? {
412
- type: typeSchemas.headerParams?.name,
413
- optional: isOptional(typeSchemas.headerParams?.schema)
414
- } : void 0
415
- }
416
- },
417
- config: {
418
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }",
419
- default: "{}"
420
- }
421
- });
422
- }
423
- return FunctionParams.factory({
424
- pathParams: typeSchemas.pathParams?.name ? {
425
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
426
- children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
427
- optional: isOptional(typeSchemas.pathParams?.schema)
428
- } : void 0,
429
- data: typeSchemas.request?.name ? {
430
- type: typeSchemas.request?.name,
431
- optional: isOptional(typeSchemas.request?.schema)
432
- } : void 0,
433
- params: typeSchemas.queryParams?.name ? {
434
- type: typeSchemas.queryParams?.name,
435
- optional: isOptional(typeSchemas.queryParams?.schema)
436
- } : void 0,
437
- headers: typeSchemas.headerParams?.name ? {
438
- type: typeSchemas.headerParams?.name,
439
- optional: isOptional(typeSchemas.headerParams?.schema)
440
- } : void 0,
441
- config: {
442
- type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }",
443
- default: "{}"
444
- }
445
- });
446
- }
447
- function InfiniteQueryOptions({
448
- name,
449
- clientName,
450
- initialPageParam,
451
- cursorParam,
452
- typeSchemas,
453
- paramsCasing,
454
- paramsType,
455
- dataReturnType,
456
- pathParamsType,
457
- queryParam,
458
- queryKeyName
459
- }) {
460
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
461
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
462
- const params = getParams6({ paramsType, paramsCasing, pathParamsType, typeSchemas });
463
- const clientParams = Client.getParams({
464
- paramsCasing,
465
- typeSchemas,
466
- paramsType,
467
- pathParamsType,
468
- isConfigurable: true
469
- });
470
- const queryKeyParams = QueryKey.getParams({
471
- pathParamsType,
472
- typeSchemas,
473
- paramsCasing
474
- });
475
- const queryOptions = [
476
- `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
477
- cursorParam ? `getNextPageParam: (lastPage) => lastPage['${cursorParam}']` : void 0,
478
- cursorParam ? `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']` : void 0,
479
- !cursorParam && dataReturnType === "full" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1" : void 0,
480
- !cursorParam && dataReturnType === "data" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1" : void 0,
481
- !cursorParam ? "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1" : void 0
482
- ].filter(Boolean);
483
- const infiniteOverrideParams = queryParam && typeSchemas.queryParams?.name ? `
484
- if(params) {
485
- params['${queryParam}'] = pageParam as unknown as ${typeSchemas.queryParams?.name}['${queryParam}']
486
- }` : "";
487
- const enabled = Object.entries(queryKeyParams.flatParams).map(([key, item]) => item && !item.optional ? key : void 0).filter(Boolean).join("&& ");
488
- const enabledText = enabled ? `enabled: !!(${enabled}),` : "";
489
- if (infiniteOverrideParams) {
490
- return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Function, { name, export: true, params: params.toConstructor(), children: `
491
- const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
492
- return infiniteQueryOptions<${TData}, ${TError}, ${TData}, typeof queryKey, number>({
493
- ${enabledText}
494
- queryKey,
495
- queryFn: async ({ signal, pageParam }) => {
496
- config.signal = signal
497
- ${infiniteOverrideParams}
498
- return ${clientName}(${clientParams.toCall()})
499
- },
500
- ${queryOptions.join(",\n")}
501
- })
502
- ` }) });
503
- }
504
- return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Function, { name, export: true, params: params.toConstructor(), children: `
505
- const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
506
- return infiniteQueryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
507
- ${enabledText}
508
- queryKey,
509
- queryFn: async ({ signal }) => {
510
- config.signal = signal
511
- return ${clientName}(${clientParams.toCall()})
512
- },
513
- ${queryOptions.join(",\n")}
514
- })
515
- ` }) });
516
- }
517
- InfiniteQueryOptions.getParams = getParams6;
518
- function getParams7({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }) {
519
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
520
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
521
- if (paramsType === "object") {
522
- return FunctionParams.factory({
523
- data: {
524
- mode: "object",
525
- children: {
526
- ...getPathParams(typeSchemas.pathParams, {
527
- typed: true,
528
- casing: paramsCasing
529
- }),
530
- data: typeSchemas.request?.name ? {
531
- type: typeSchemas.request?.name,
532
- optional: isOptional(typeSchemas.request?.schema)
533
- } : void 0,
534
- params: typeSchemas.queryParams?.name ? {
535
- type: typeSchemas.queryParams?.name,
536
- optional: isOptional(typeSchemas.queryParams?.schema)
537
- } : void 0,
538
- headers: typeSchemas.headerParams?.name ? {
539
- type: typeSchemas.headerParams?.name,
540
- optional: isOptional(typeSchemas.headerParams?.schema)
541
- } : void 0
542
- }
543
- },
544
- options: {
545
- type: `
546
- {
547
- query?: Partial<InfiniteQueryObserverOptions<${[TData, TError, "TData", "TQueryKey"].join(", ")}>> & { client?: QueryClient },
548
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"}
549
- }
550
- `,
551
- default: "{}"
552
- }
553
- });
554
- }
555
- return FunctionParams.factory({
556
- pathParams: typeSchemas.pathParams?.name ? {
557
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
558
- children: getPathParams(typeSchemas.pathParams, {
559
- typed: true,
560
- casing: paramsCasing
561
- }),
562
- optional: isOptional(typeSchemas.pathParams?.schema)
563
- } : void 0,
564
- data: typeSchemas.request?.name ? {
565
- type: typeSchemas.request?.name,
566
- optional: isOptional(typeSchemas.request?.schema)
567
- } : void 0,
568
- params: typeSchemas.queryParams?.name ? {
569
- type: typeSchemas.queryParams?.name,
570
- optional: isOptional(typeSchemas.queryParams?.schema)
571
- } : void 0,
572
- headers: typeSchemas.headerParams?.name ? {
573
- type: typeSchemas.headerParams?.name,
574
- optional: isOptional(typeSchemas.headerParams?.schema)
575
- } : void 0,
576
- options: {
577
- type: `
578
- {
579
- query?: Partial<InfiniteQueryObserverOptions<${[TData, TError, "TData", "TQueryKey"].join(", ")}>> & { client?: QueryClient },
580
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"}
581
- }
582
- `,
583
- default: "{}"
584
- }
585
- });
586
- }
587
- function InfiniteQuery({
588
- name,
589
- queryKeyTypeName,
590
- queryOptionsName,
591
- queryKeyName,
592
- paramsType,
593
- paramsCasing,
594
- pathParamsType,
595
- dataReturnType,
596
- typeSchemas,
597
- operation
598
- }) {
599
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
600
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
601
- const returnType = `UseInfiniteQueryResult<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
602
- const generics = [`TData = InfiniteData<${TData}>`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
603
- const queryKeyParams = QueryKey.getParams({
604
- pathParamsType,
605
- typeSchemas,
606
- paramsCasing
607
- });
608
- const queryOptionsParams = QueryOptions.getParams({
609
- paramsType,
610
- pathParamsType,
611
- typeSchemas,
612
- paramsCasing
613
- });
614
- const params = getParams7({
615
- paramsCasing,
616
- paramsType,
617
- pathParamsType,
618
- dataReturnType,
619
- typeSchemas
620
- });
621
- const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()})`;
622
- return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(
623
- Function,
624
- {
625
- name,
626
- export: true,
627
- generics: generics.join(", "),
628
- params: params.toConstructor(),
629
- JSDoc: {
630
- comments: getComments(operation)
631
- },
632
- children: `
633
- const { query: { client: queryClient, ...queryOptions } = {}, client: config = {} } = options ?? {}
634
- const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
635
-
636
- const query = useInfiniteQuery({
637
- ...${queryOptions},
638
- queryKey,
639
- ...queryOptions
640
- } as unknown as InfiniteQueryObserverOptions, queryClient) as ${returnType}
641
-
642
- query.queryKey = queryKey as TQueryKey
643
-
644
- return query
645
- `
646
- }
647
- ) });
648
- }
649
- InfiniteQuery.getParams = getParams7;
650
- function getParams8({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas }) {
651
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
652
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
653
- if (paramsType === "object") {
654
- return FunctionParams.factory({
655
- data: {
656
- mode: "object",
657
- children: {
658
- ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
659
- data: typeSchemas.request?.name ? {
660
- type: typeSchemas.request?.name,
661
- optional: isOptional(typeSchemas.request?.schema)
662
- } : void 0,
663
- params: typeSchemas.queryParams?.name ? {
664
- type: typeSchemas.queryParams?.name,
665
- optional: isOptional(typeSchemas.queryParams?.schema)
666
- } : void 0,
667
- headers: typeSchemas.headerParams?.name ? {
668
- type: typeSchemas.headerParams?.name,
669
- optional: isOptional(typeSchemas.headerParams?.schema)
670
- } : void 0
671
- }
672
- },
673
- options: {
674
- type: `
675
- {
676
- query?: Partial<UseSuspenseQueryOptions<${[TData, TError, "TData", "TQueryKey"].join(", ")}>> & { client?: QueryClient },
677
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"}
678
- }
679
- `,
680
- default: "{}"
681
- }
682
- });
683
- }
684
- return FunctionParams.factory({
685
- pathParams: typeSchemas.pathParams?.name ? {
686
- mode: pathParamsType === "object" ? "object" : "inlineSpread",
687
- children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
688
- optional: isOptional(typeSchemas.pathParams?.schema)
689
- } : void 0,
690
- data: typeSchemas.request?.name ? {
691
- type: typeSchemas.request?.name,
692
- optional: isOptional(typeSchemas.request?.schema)
693
- } : void 0,
694
- params: typeSchemas.queryParams?.name ? {
695
- type: typeSchemas.queryParams?.name,
696
- optional: isOptional(typeSchemas.queryParams?.schema)
697
- } : void 0,
698
- headers: typeSchemas.headerParams?.name ? {
699
- type: typeSchemas.headerParams?.name,
700
- optional: isOptional(typeSchemas.headerParams?.schema)
701
- } : void 0,
702
- options: {
703
- type: `
704
- {
705
- query?: Partial<UseSuspenseQueryOptions<${[TData, TError, "TData", "TQueryKey"].join(", ")}>> & { client?: QueryClient },
706
- client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }` : "Partial<RequestConfig> & { client?: typeof fetch }"}
707
- }
708
- `,
709
- default: "{}"
710
- }
711
- });
712
- }
713
- function SuspenseQuery({
714
- name,
715
- queryKeyTypeName,
716
- queryOptionsName,
717
- queryKeyName,
718
- paramsType,
719
- paramsCasing,
720
- pathParamsType,
721
- dataReturnType,
722
- typeSchemas,
723
- operation
724
- }) {
725
- const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
726
- const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
727
- const returnType = `UseSuspenseQueryResult<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
728
- const generics = [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
729
- const queryKeyParams = QueryKey.getParams({
730
- pathParamsType,
731
- typeSchemas,
732
- paramsCasing
733
- });
734
- const queryOptionsParams = QueryOptions.getParams({
735
- paramsCasing,
736
- paramsType,
737
- pathParamsType,
738
- typeSchemas
739
- });
740
- const params = getParams8({
741
- paramsCasing,
742
- paramsType,
743
- pathParamsType,
744
- dataReturnType,
745
- typeSchemas
746
- });
747
- const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()})`;
748
- return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(
749
- Function,
750
- {
751
- name,
752
- export: true,
753
- generics: generics.join(", "),
754
- params: params.toConstructor(),
755
- JSDoc: {
756
- comments: getComments(operation)
757
- },
758
- children: `
759
- const { query: { client: queryClient, ...queryOptions } = {}, client: config = {} } = options ?? {}
760
- const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
761
-
762
- const query = useSuspenseQuery({
763
- ...${queryOptions},
764
- queryKey,
765
- ...queryOptions
766
- } as unknown as UseSuspenseQueryOptions, queryClient) as ${returnType}
767
-
768
- query.queryKey = queryKey as TQueryKey
769
-
770
- return query
771
- `
772
- }
773
- ) });
774
- }
775
- SuspenseQuery.getParams = getParams8;
776
-
777
- export { InfiniteQuery, InfiniteQueryOptions, Mutation, MutationKey, Query, QueryKey, QueryOptions, SuspenseQuery };
778
- //# sourceMappingURL=chunk-LT467H44.js.map
779
- //# sourceMappingURL=chunk-LT467H44.js.map