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