@kubb/plugin-react-query 3.0.0-alpha.9 → 3.0.0-beta.10

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