@kubb/plugin-react-query 3.0.0-alpha.2 → 3.0.0-alpha.21

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 (80) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-ESENIDWJ.js +608 -0
  3. package/dist/chunk-ESENIDWJ.js.map +1 -0
  4. package/dist/chunk-HAC4WPCC.js +608 -0
  5. package/dist/chunk-HAC4WPCC.js.map +1 -0
  6. package/dist/chunk-JQEH3UHY.cjs +618 -0
  7. package/dist/chunk-JQEH3UHY.cjs.map +1 -0
  8. package/dist/chunk-JYBGTT23.cjs +618 -0
  9. package/dist/chunk-JYBGTT23.cjs.map +1 -0
  10. package/dist/components.cjs +35 -14
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +143 -7
  13. package/dist/components.d.ts +143 -7
  14. package/dist/components.js +2 -14
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +25 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +14 -0
  19. package/dist/generators.d.ts +14 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +77 -154
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +1 -5
  25. package/dist/index.d.ts +1 -5
  26. package/dist/index.js +56 -140
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-DFHc63S9.d.cts +179 -0
  29. package/dist/types-DFHc63S9.d.ts +179 -0
  30. package/package.json +22 -17
  31. package/src/components/InfiniteQuery.tsx +129 -0
  32. package/src/components/InfiniteQueryOptions.tsx +121 -0
  33. package/src/components/Mutation.tsx +113 -321
  34. package/src/components/Query.tsx +91 -598
  35. package/src/components/QueryKey.tsx +51 -178
  36. package/src/components/QueryOptions.tsx +65 -468
  37. package/src/components/SuspenseQuery.tsx +129 -0
  38. package/src/components/index.ts +3 -1
  39. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +50 -0
  40. package/src/generators/__snapshots__/clientGetImportPath.ts +50 -0
  41. package/src/generators/__snapshots__/clientPostImportPath.ts +38 -0
  42. package/src/generators/__snapshots__/findByTags.ts +50 -0
  43. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +50 -0
  44. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +50 -0
  45. package/src/generators/__snapshots__/findByTagsWithZod.ts +50 -0
  46. package/src/generators/__snapshots__/findInfiniteByTags.ts +56 -0
  47. package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +56 -0
  48. package/src/generators/__snapshots__/getAsMutation.ts +31 -0
  49. package/src/generators/__snapshots__/postAsQuery.ts +48 -0
  50. package/src/generators/__snapshots__/updatePetById.ts +38 -0
  51. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +40 -0
  52. package/src/generators/index.ts +4 -0
  53. package/src/generators/infiniteQueryGenerator.tsx +125 -0
  54. package/src/generators/mutationGenerator.tsx +96 -0
  55. package/src/generators/queryGenerator.tsx +122 -0
  56. package/src/generators/suspenseQueryGenerator.tsx +121 -0
  57. package/src/plugin.ts +51 -73
  58. package/src/types.ts +43 -91
  59. package/dist/chunk-5IL6M74X.js +0 -1504
  60. package/dist/chunk-5IL6M74X.js.map +0 -1
  61. package/dist/chunk-JFX7DCS7.cjs +0 -1504
  62. package/dist/chunk-JFX7DCS7.cjs.map +0 -1
  63. package/dist/index-C9fwRDH7.d.cts +0 -579
  64. package/dist/index-C9fwRDH7.d.ts +0 -579
  65. package/src/OperationGenerator.tsx +0 -86
  66. package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -64
  67. package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -57
  68. package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -63
  69. package/src/__snapshots__/queryOptions/getPetById.ts +0 -37
  70. package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -47
  71. package/src/__snapshots__/upload/UploadFile.ts +0 -67
  72. package/src/__snapshots__/uploadMutation/UploadFile.ts +0 -44
  73. package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -21
  74. package/src/components/Operations.tsx +0 -74
  75. package/src/components/QueryImports.tsx +0 -167
  76. package/src/components/SchemaType.tsx +0 -55
  77. package/src/components/__snapshots__/gen/showPetById.ts +0 -57
  78. package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
  79. package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -47
  80. package/src/utils.ts +0 -96
package/README.md CHANGED
@@ -13,10 +13,6 @@
13
13
  [![Coverage][coverage-src]][coverage-href]
14
14
  [![License][license-src]][license-href]
15
15
 
16
- <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
17
- <!-- ALL-CONTRIBUTORS-BADGE:END -->
18
- </p>
19
-
20
16
  <h4>
21
17
  <a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/alpha/examples/typescript" target="_blank">View Demo</a>
22
18
  <span> · </span>
@@ -28,6 +24,19 @@
28
24
  </h4>
29
25
  </div>
30
26
 
27
+ ## Supporting Kubb
28
+
29
+ Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
30
+
31
+ - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
32
+
33
+ <p align="center">
34
+ <a href="https://github.com/sponsors/stijnvanhulle">
35
+ <img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
36
+ </a>
37
+ </p>
38
+
39
+
31
40
  <!-- Badges -->
32
41
 
33
42
  [npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-tanstack-query?flat&colorA=18181B&colorB=f58517
@@ -0,0 +1,608 @@
1
+ import { FunctionParams, File, Function, Const, Type } from '@kubb/react';
2
+ import { isOptional } from '@kubb/oas';
3
+ import { URLPath } from '@kubb/core/utils';
4
+ import { getComments, getPathParams } from '@kubb/plugin-oas/utils';
5
+ import { jsx, jsxs, Fragment } from '@kubb/react/jsx-runtime';
6
+
7
+ // src/components/Mutation.tsx
8
+ function getParams({ pathParamsType, typeSchemas }) {
9
+ return FunctionParams.factory({
10
+ pathParams: {
11
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
12
+ children: getPathParams(typeSchemas.pathParams, { typed: true })
13
+ },
14
+ data: typeSchemas.request?.name ? {
15
+ type: typeSchemas.request?.name,
16
+ optional: isOptional(typeSchemas.request?.schema)
17
+ } : void 0,
18
+ params: typeSchemas.queryParams?.name ? {
19
+ type: typeSchemas.queryParams?.name,
20
+ optional: isOptional(typeSchemas.queryParams?.schema)
21
+ } : void 0,
22
+ headers: typeSchemas.headerParams?.name ? {
23
+ type: typeSchemas.headerParams?.name,
24
+ optional: isOptional(typeSchemas.headerParams?.schema)
25
+ } : void 0,
26
+ config: {
27
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>",
28
+ default: "{}"
29
+ }
30
+ });
31
+ }
32
+ function Client({
33
+ name,
34
+ isExportable = true,
35
+ isIndexable = true,
36
+ typeSchemas,
37
+ baseURL,
38
+ dataReturnType,
39
+ parser,
40
+ zodSchemas,
41
+ pathParamsType,
42
+ operation
43
+ }) {
44
+ const path = new URLPath(operation.path);
45
+ const contentType = operation.getContentType();
46
+ const isFormData = contentType === "multipart/form-data";
47
+ const headers = [
48
+ contentType !== "application/json" ? `'Content-Type': '${contentType}'` : void 0,
49
+ typeSchemas.headerParams?.name ? "...headers" : void 0
50
+ ].filter(Boolean);
51
+ const generics = [
52
+ typeSchemas.response.name,
53
+ typeSchemas.errors?.map((item) => item.name).join(" | ") || "unknown",
54
+ typeSchemas.request?.name || "unknown"
55
+ ].filter(Boolean);
56
+ const params = getParams({ pathParamsType, typeSchemas });
57
+ const clientParams = FunctionParams.factory({
58
+ config: {
59
+ mode: "object",
60
+ children: {
61
+ method: {
62
+ value: JSON.stringify(operation.method)
63
+ },
64
+ url: {
65
+ value: path.template
66
+ },
67
+ baseURL: baseURL ? {
68
+ value: JSON.stringify(baseURL)
69
+ } : void 0,
70
+ params: typeSchemas.queryParams?.name ? {} : void 0,
71
+ data: typeSchemas.request?.name ? {
72
+ value: isFormData ? "formData" : void 0
73
+ } : void 0,
74
+ headers: headers.length ? {
75
+ value: headers.length ? `{ ${headers.join(", ")}, ...config.headers }` : void 0
76
+ } : void 0,
77
+ config: {
78
+ mode: "inlineSpread"
79
+ }
80
+ }
81
+ }
82
+ });
83
+ const formData = isFormData ? `
84
+ const formData = new FormData()
85
+ if(data) {
86
+ Object.keys(data).forEach((key) => {
87
+ const value = data[key];
88
+ if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
89
+ formData.append(key, value);
90
+ }
91
+ })
92
+ }
93
+ ` : "";
94
+ return /* @__PURE__ */ jsx(File.Source, { name, isExportable, isIndexable, children: /* @__PURE__ */ jsxs(
95
+ Function,
96
+ {
97
+ name,
98
+ async: true,
99
+ export: isExportable,
100
+ params: params.toConstructor(),
101
+ JSDoc: {
102
+ comments: getComments(operation)
103
+ },
104
+ children: [
105
+ formData,
106
+ `const res = await client<${generics.join(", ")}>(${clientParams.toCall()})`,
107
+ /* @__PURE__ */ jsx("br", {}),
108
+ dataReturnType === "full" && parser === "zod" && zodSchemas && `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`,
109
+ dataReturnType === "data" && parser === "zod" && zodSchemas && `return ${zodSchemas.response.name}.parse(res.data)`,
110
+ dataReturnType === "full" && parser === "client" && "return res",
111
+ dataReturnType === "data" && parser === "client" && "return res.data"
112
+ ]
113
+ }
114
+ ) });
115
+ }
116
+ Client.getParams = getParams;
117
+ function Operations({ name, operations }) {
118
+ const operationsObject = {};
119
+ operations.forEach((operation) => {
120
+ operationsObject[operation.getOperationId()] = {
121
+ path: new URLPath(operation.path).URL,
122
+ method: operation.method
123
+ };
124
+ });
125
+ return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Const, { name, export: true, asConst: true, children: JSON.stringify(operationsObject, void 0, 2) }) });
126
+ }
127
+ function getParams2({ dataReturnType, typeSchemas }) {
128
+ const mutateParams = FunctionParams.factory({
129
+ ...getPathParams(typeSchemas.pathParams, { typed: true }),
130
+ data: typeSchemas.request?.name ? {
131
+ type: typeSchemas.request?.name,
132
+ optional: isOptional(typeSchemas.request?.schema)
133
+ } : void 0,
134
+ params: typeSchemas.queryParams?.name ? {
135
+ type: typeSchemas.queryParams?.name,
136
+ optional: isOptional(typeSchemas.queryParams?.schema)
137
+ } : void 0,
138
+ headers: typeSchemas.headerParams?.name ? {
139
+ type: typeSchemas.headerParams?.name,
140
+ optional: isOptional(typeSchemas.headerParams?.schema)
141
+ } : void 0
142
+ });
143
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
144
+ const TRequest = mutateParams.toConstructor({ valueAsType: true });
145
+ return FunctionParams.factory({
146
+ options: {
147
+ type: `
148
+ {
149
+ mutation?: UseMutationOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "unknown", `{${TRequest}`].join(", ")}>,
150
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"},
151
+ }
152
+ `,
153
+ default: "{}"
154
+ }
155
+ });
156
+ }
157
+ function Mutation({ name, clientName, pathParamsType, dataReturnType, typeSchemas, operation }) {
158
+ const params = getParams2({
159
+ pathParamsType,
160
+ dataReturnType,
161
+ typeSchemas
162
+ });
163
+ const clientParams = Client.getParams({
164
+ typeSchemas,
165
+ pathParamsType
166
+ });
167
+ const mutationParams = FunctionParams.factory({
168
+ data: {
169
+ // No use of pathParams because useMutation can only take one argument in object form,
170
+ // see https://tanstack.com/query/latest/docs/framework/react/reference/useMutation#usemutation
171
+ mode: "object",
172
+ //TODO rename with value
173
+ children: {
174
+ ...getPathParams(typeSchemas.pathParams, { typed: true }),
175
+ data: typeSchemas.request?.name ? {
176
+ type: typeSchemas.request?.name,
177
+ optional: isOptional(typeSchemas.request?.schema)
178
+ } : void 0,
179
+ params: typeSchemas.queryParams?.name ? {
180
+ type: typeSchemas.queryParams?.name,
181
+ optional: isOptional(typeSchemas.queryParams?.schema)
182
+ } : void 0,
183
+ headers: typeSchemas.headerParams?.name ? {
184
+ type: typeSchemas.headerParams?.name,
185
+ optional: isOptional(typeSchemas.headerParams?.schema)
186
+ } : void 0
187
+ }
188
+ }
189
+ });
190
+ return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(
191
+ Function,
192
+ {
193
+ name,
194
+ export: true,
195
+ params: params.toConstructor(),
196
+ JSDoc: {
197
+ comments: getComments(operation)
198
+ },
199
+ children: `
200
+ const { mutation: mutationOptions, client: config = {} } = options ?? {}
201
+
202
+ return useMutation({
203
+ mutationFn: async(${mutationParams.toConstructor()}) => {
204
+ return ${clientName}(${clientParams.toCall()})
205
+ },
206
+ ...mutationOptions
207
+ })
208
+ `
209
+ }
210
+ ) });
211
+ }
212
+ function getParams3({ pathParamsType, typeSchemas }) {
213
+ return FunctionParams.factory({
214
+ pathParams: {
215
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
216
+ children: getPathParams(typeSchemas.pathParams, { typed: true })
217
+ },
218
+ data: typeSchemas.request?.name ? {
219
+ type: typeSchemas.request?.name,
220
+ optional: isOptional(typeSchemas.request?.schema)
221
+ } : void 0,
222
+ params: typeSchemas.queryParams?.name ? {
223
+ type: typeSchemas.queryParams?.name,
224
+ optional: isOptional(typeSchemas.queryParams?.schema)
225
+ } : void 0
226
+ });
227
+ }
228
+ function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, keysFn = (name2) => name2 }) {
229
+ const path = new URLPath(operation.path);
230
+ const params = getParams3({ pathParamsType, typeSchemas });
231
+ const keys = [
232
+ path.toObject({
233
+ type: "path",
234
+ stringify: true
235
+ }),
236
+ typeSchemas.queryParams?.name ? "...(params ? [params] : [])" : void 0,
237
+ typeSchemas.request?.name ? "...(data ? [data] : [])" : void 0
238
+ ].filter(Boolean);
239
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
240
+ /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Function.Arrow, { name, export: true, params: params.toConstructor(), singleLine: true, children: `[${keysFn(keys).join(", ")}] as const` }) }),
241
+ /* @__PURE__ */ jsx(File.Source, { name: typeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsx(Type, { name: typeName, export: true, children: `ReturnType<typeof ${name}>` }) })
242
+ ] });
243
+ }
244
+ QueryKey.getParams = getParams3;
245
+ function getParams4({ pathParamsType, typeSchemas }) {
246
+ return FunctionParams.factory({
247
+ pathParams: {
248
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
249
+ children: getPathParams(typeSchemas.pathParams, { typed: true })
250
+ },
251
+ data: typeSchemas.request?.name ? {
252
+ type: typeSchemas.request?.name,
253
+ optional: isOptional(typeSchemas.request?.schema)
254
+ } : void 0,
255
+ params: typeSchemas.queryParams?.name ? {
256
+ type: typeSchemas.queryParams?.name,
257
+ optional: isOptional(typeSchemas.queryParams?.schema)
258
+ } : void 0,
259
+ headers: typeSchemas.headerParams?.name ? {
260
+ type: typeSchemas.headerParams?.name,
261
+ optional: isOptional(typeSchemas.headerParams?.schema)
262
+ } : void 0,
263
+ config: {
264
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>",
265
+ default: "{}"
266
+ }
267
+ });
268
+ }
269
+ function QueryOptions({ name, clientName, typeSchemas, pathParamsType, queryKeyName }) {
270
+ const params = getParams4({ pathParamsType, typeSchemas });
271
+ const clientParams = Client.getParams({
272
+ typeSchemas,
273
+ pathParamsType
274
+ });
275
+ const queryKeyParams = QueryKey.getParams({
276
+ pathParamsType,
277
+ typeSchemas
278
+ });
279
+ return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Function, { name, export: true, params: params.toConstructor(), children: `
280
+ const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
281
+ return queryOptions({
282
+ queryKey,
283
+ queryFn: async () => {
284
+ return ${clientName}(${clientParams.toCall()})
285
+ },
286
+ })
287
+ ` }) });
288
+ }
289
+ QueryOptions.getParams = getParams4;
290
+ function getParams5({ pathParamsType, dataReturnType, typeSchemas }) {
291
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
292
+ return FunctionParams.factory({
293
+ pathParams: {
294
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
295
+ children: getPathParams(typeSchemas.pathParams, { typed: true })
296
+ },
297
+ data: typeSchemas.request?.name ? {
298
+ type: typeSchemas.request?.name,
299
+ optional: isOptional(typeSchemas.request?.schema)
300
+ } : void 0,
301
+ params: typeSchemas.queryParams?.name ? {
302
+ type: typeSchemas.queryParams?.name,
303
+ optional: isOptional(typeSchemas.queryParams?.schema)
304
+ } : void 0,
305
+ headers: typeSchemas.headerParams?.name ? {
306
+ type: typeSchemas.headerParams?.name,
307
+ optional: isOptional(typeSchemas.headerParams?.schema)
308
+ } : void 0,
309
+ options: {
310
+ type: `
311
+ {
312
+ query?: Partial<QueryObserverOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "unknown", "TData", "TQueryData", "TQueryKey"].join(", ")}>>,
313
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"}
314
+ }
315
+ `,
316
+ default: "{}"
317
+ }
318
+ });
319
+ }
320
+ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, pathParamsType, dataReturnType, typeSchemas, operation }) {
321
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
322
+ const returnType = `UseQueryResult<${["TData", typeSchemas.errors?.map((item) => item.name).join(" | ") || "unknown"].join(", ")}> & { queryKey: TQueryKey }`;
323
+ const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
324
+ const queryKeyParams = QueryKey.getParams({
325
+ pathParamsType,
326
+ typeSchemas
327
+ });
328
+ const queryOptionsParams = QueryOptions.getParams({
329
+ pathParamsType,
330
+ typeSchemas
331
+ });
332
+ const params = getParams5({
333
+ pathParamsType,
334
+ dataReturnType,
335
+ typeSchemas
336
+ });
337
+ const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()}) as unknown as QueryObserverOptions`;
338
+ return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(
339
+ Function,
340
+ {
341
+ name,
342
+ export: true,
343
+ generics: generics.join(", "),
344
+ params: params.toConstructor(),
345
+ JSDoc: {
346
+ comments: getComments(operation)
347
+ },
348
+ children: `
349
+ const { query: queryOptions, client: config = {} } = options ?? {}
350
+ const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
351
+
352
+ const query = useQuery({
353
+ ...${queryOptions},
354
+ queryKey,
355
+ ...queryOptions as unknown as Omit<QueryObserverOptions, "queryKey">
356
+ }) as ${returnType}
357
+
358
+ query.queryKey = queryKey as TQueryKey
359
+
360
+ return query
361
+ `
362
+ }
363
+ ) });
364
+ }
365
+ Query.getParams = getParams5;
366
+ function getParams6({ pathParamsType, typeSchemas }) {
367
+ return FunctionParams.factory({
368
+ pathParams: {
369
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
370
+ children: getPathParams(typeSchemas.pathParams, { typed: true })
371
+ },
372
+ data: typeSchemas.request?.name ? {
373
+ type: typeSchemas.request?.name,
374
+ optional: isOptional(typeSchemas.request?.schema)
375
+ } : void 0,
376
+ params: typeSchemas.queryParams?.name ? {
377
+ type: typeSchemas.queryParams?.name,
378
+ optional: isOptional(typeSchemas.queryParams?.schema)
379
+ } : void 0,
380
+ headers: typeSchemas.headerParams?.name ? {
381
+ type: typeSchemas.headerParams?.name,
382
+ optional: isOptional(typeSchemas.headerParams?.schema)
383
+ } : void 0,
384
+ config: {
385
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>",
386
+ default: "{}"
387
+ }
388
+ });
389
+ }
390
+ function InfiniteQueryOptions({
391
+ name,
392
+ clientName,
393
+ initialPageParam,
394
+ cursorParam,
395
+ typeSchemas,
396
+ dataReturnType,
397
+ pathParamsType,
398
+ queryParam,
399
+ queryKeyName
400
+ }) {
401
+ const params = getParams6({ pathParamsType, typeSchemas });
402
+ const clientParams = Client.getParams({
403
+ typeSchemas,
404
+ pathParamsType
405
+ });
406
+ const queryKeyParams = QueryKey.getParams({
407
+ pathParamsType,
408
+ typeSchemas
409
+ });
410
+ const queryOptions = [
411
+ `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
412
+ cursorParam ? `getNextPageParam: (lastPage) => lastPage['${cursorParam}']` : void 0,
413
+ cursorParam ? `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']` : void 0,
414
+ !cursorParam && dataReturnType === "full" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1" : void 0,
415
+ !cursorParam && dataReturnType === "data" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1" : void 0,
416
+ !cursorParam ? "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1" : void 0
417
+ ].filter(Boolean);
418
+ const infiniteOverrideParams = queryParam && typeSchemas.queryParams?.name ? `
419
+ if(params) {
420
+ params['${queryParam}'] = pageParam as unknown as ${typeSchemas.queryParams?.name}['${queryParam}']
421
+ }` : "";
422
+ return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Function, { name, export: true, params: params.toConstructor(), children: `
423
+ const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
424
+ return infiniteQueryOptions({
425
+ queryKey,
426
+ queryFn: async ({ pageParam }) => {
427
+ ${infiniteOverrideParams}
428
+ return ${clientName}(${clientParams.toCall()})
429
+ },
430
+ ${queryOptions.join("\n")}
431
+ })
432
+ ` }) });
433
+ }
434
+ InfiniteQueryOptions.getParams = getParams6;
435
+ function getParams7({ pathParamsType, dataReturnType, typeSchemas }) {
436
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
437
+ return FunctionParams.factory({
438
+ pathParams: {
439
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
440
+ children: getPathParams(typeSchemas.pathParams, { typed: true })
441
+ },
442
+ data: typeSchemas.request?.name ? {
443
+ type: typeSchemas.request?.name,
444
+ optional: isOptional(typeSchemas.request?.schema)
445
+ } : void 0,
446
+ params: typeSchemas.queryParams?.name ? {
447
+ type: typeSchemas.queryParams?.name,
448
+ optional: isOptional(typeSchemas.queryParams?.schema)
449
+ } : void 0,
450
+ headers: typeSchemas.headerParams?.name ? {
451
+ type: typeSchemas.headerParams?.name,
452
+ optional: isOptional(typeSchemas.headerParams?.schema)
453
+ } : void 0,
454
+ options: {
455
+ type: `
456
+ {
457
+ query?: Partial<InfiniteQueryObserverOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "unknown", "TData", "TQueryData", "TQueryKey"].join(", ")}>>,
458
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"}
459
+ }
460
+ `,
461
+ default: "{}"
462
+ }
463
+ });
464
+ }
465
+ function InfiniteQuery({
466
+ name,
467
+ queryKeyTypeName,
468
+ queryOptionsName,
469
+ queryKeyName,
470
+ pathParamsType,
471
+ dataReturnType,
472
+ typeSchemas,
473
+ operation
474
+ }) {
475
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
476
+ const returnType = `UseInfiniteQueryResult<${["TData", typeSchemas.errors?.map((item) => item.name).join(" | ") || "unknown"].join(", ")}> & { queryKey: TQueryKey }`;
477
+ const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
478
+ const queryKeyParams = QueryKey.getParams({
479
+ pathParamsType,
480
+ typeSchemas
481
+ });
482
+ const queryOptionsParams = QueryOptions.getParams({
483
+ pathParamsType,
484
+ typeSchemas
485
+ });
486
+ const params = getParams7({
487
+ pathParamsType,
488
+ dataReturnType,
489
+ typeSchemas
490
+ });
491
+ const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()}) as unknown as InfiniteQueryObserverOptions`;
492
+ return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(
493
+ Function,
494
+ {
495
+ name,
496
+ export: true,
497
+ generics: generics.join(", "),
498
+ params: params.toConstructor(),
499
+ JSDoc: {
500
+ comments: getComments(operation)
501
+ },
502
+ children: `
503
+ const { query: queryOptions, client: config = {} } = options ?? {}
504
+ const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
505
+
506
+ const query = useInfiniteQuery({
507
+ ...${queryOptions},
508
+ queryKey,
509
+ ...queryOptions as unknown as Omit<InfiniteQueryObserverOptions, "queryKey">
510
+ }) as ${returnType}
511
+
512
+ query.queryKey = queryKey as TQueryKey
513
+
514
+ return query
515
+ `
516
+ }
517
+ ) });
518
+ }
519
+ InfiniteQuery.getParams = getParams7;
520
+ function getParams8({ pathParamsType, dataReturnType, typeSchemas }) {
521
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
522
+ return FunctionParams.factory({
523
+ pathParams: {
524
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
525
+ children: getPathParams(typeSchemas.pathParams, { typed: true })
526
+ },
527
+ data: typeSchemas.request?.name ? {
528
+ type: typeSchemas.request?.name,
529
+ optional: isOptional(typeSchemas.request?.schema)
530
+ } : void 0,
531
+ params: typeSchemas.queryParams?.name ? {
532
+ type: typeSchemas.queryParams?.name,
533
+ optional: isOptional(typeSchemas.queryParams?.schema)
534
+ } : void 0,
535
+ headers: typeSchemas.headerParams?.name ? {
536
+ type: typeSchemas.headerParams?.name,
537
+ optional: isOptional(typeSchemas.headerParams?.schema)
538
+ } : void 0,
539
+ options: {
540
+ type: `
541
+ {
542
+ query?: Partial<UseSuspenseQueryOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "unknown", "TData", "TQueryKey"].join(", ")}>>,
543
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"}
544
+ }
545
+ `,
546
+ default: "{}"
547
+ }
548
+ });
549
+ }
550
+ function SuspenseQuery({
551
+ name,
552
+ queryKeyTypeName,
553
+ queryOptionsName,
554
+ queryKeyName,
555
+ pathParamsType,
556
+ dataReturnType,
557
+ typeSchemas,
558
+ operation
559
+ }) {
560
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
561
+ const returnType = `UseSuspenseQueryResult<${["TData", typeSchemas.errors?.map((item) => item.name).join(" | ") || "unknown"].join(", ")}> & { queryKey: TQueryKey }`;
562
+ const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
563
+ const queryKeyParams = QueryKey.getParams({
564
+ pathParamsType,
565
+ typeSchemas
566
+ });
567
+ const queryOptionsParams = QueryOptions.getParams({
568
+ pathParamsType,
569
+ typeSchemas
570
+ });
571
+ const params = getParams8({
572
+ pathParamsType,
573
+ dataReturnType,
574
+ typeSchemas
575
+ });
576
+ const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()}) as unknown as UseSuspenseQueryOptions`;
577
+ return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(
578
+ Function,
579
+ {
580
+ name,
581
+ export: true,
582
+ generics: generics.join(", "),
583
+ params: params.toConstructor(),
584
+ JSDoc: {
585
+ comments: getComments(operation)
586
+ },
587
+ children: `
588
+ const { query: queryOptions, client: config = {} } = options ?? {}
589
+ const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
590
+
591
+ const query = useSuspenseQuery({
592
+ ...${queryOptions},
593
+ queryKey,
594
+ ...queryOptions as unknown as Omit<UseSuspenseQueryOptions, "queryKey">
595
+ }) as ${returnType}
596
+
597
+ query.queryKey = queryKey as TQueryKey
598
+
599
+ return query
600
+ `
601
+ }
602
+ ) });
603
+ }
604
+ SuspenseQuery.getParams = getParams8;
605
+
606
+ export { Client, InfiniteQuery, InfiniteQueryOptions, Mutation, Operations, Query, QueryKey, QueryOptions, SuspenseQuery };
607
+ //# sourceMappingURL=chunk-ESENIDWJ.js.map
608
+ //# sourceMappingURL=chunk-ESENIDWJ.js.map