@kubb/plugin-vue-query 0.0.0-canary-20241104172400

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