@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,878 @@
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
+ function MutationKey({ name, typeSchemas, pathParamsType, operation, typeName, keysFn = (name2) => name2 }) {
162
+ const path = new utils.URLPath(operation.path);
163
+ const params = getParams2({ pathParamsType, typeSchemas });
164
+ const keys = [JSON.stringify({ url: path.path })].filter(Boolean);
165
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
166
+ /* @__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` }) }),
167
+ /* @__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}>` }) })
168
+ ] });
169
+ }
170
+ MutationKey.getParams = getParams2;
171
+ function getParams3({ dataReturnType, typeSchemas }) {
172
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
173
+ const mutationParams = react.FunctionParams.factory({
174
+ ...utils$1.getPathParams(typeSchemas.pathParams, { typed: true }),
175
+ data: typeSchemas.request?.name ? {
176
+ type: typeSchemas.request?.name,
177
+ optional: oas.isOptional(typeSchemas.request?.schema)
178
+ } : void 0,
179
+ params: typeSchemas.queryParams?.name ? {
180
+ type: typeSchemas.queryParams?.name,
181
+ optional: oas.isOptional(typeSchemas.queryParams?.schema)
182
+ } : void 0,
183
+ headers: typeSchemas.headerParams?.name ? {
184
+ type: typeSchemas.headerParams?.name,
185
+ optional: oas.isOptional(typeSchemas.headerParams?.schema)
186
+ } : void 0
187
+ });
188
+ const TRequest = mutationParams.toConstructor({ valueAsType: true });
189
+ const generics = [TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error", TRequest ? `{${TRequest}}` : void 0].filter(Boolean).join(", ");
190
+ return react.FunctionParams.factory({
191
+ options: {
192
+ type: `
193
+ {
194
+ mutation?: UseMutationOptions<${generics}>,
195
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"},
196
+ }
197
+ `,
198
+ default: "{}"
199
+ }
200
+ });
201
+ }
202
+ function Mutation({ name, clientName, paramsType, pathParamsType, dataReturnType, typeSchemas, operation, mutationKeyName }) {
203
+ const mutationKeyParams = MutationKey.getParams({
204
+ pathParamsType,
205
+ typeSchemas
206
+ });
207
+ const params = getParams3({
208
+ pathParamsType,
209
+ dataReturnType,
210
+ typeSchemas
211
+ });
212
+ const clientParams = Client.getParams({
213
+ paramsType,
214
+ typeSchemas,
215
+ pathParamsType
216
+ });
217
+ const mutationParams = react.FunctionParams.factory({
218
+ ...utils$1.getPathParams(typeSchemas.pathParams, { typed: true }),
219
+ data: typeSchemas.request?.name ? {
220
+ type: typeSchemas.request?.name,
221
+ optional: oas.isOptional(typeSchemas.request?.schema)
222
+ } : void 0,
223
+ params: typeSchemas.queryParams?.name ? {
224
+ type: typeSchemas.queryParams?.name,
225
+ optional: oas.isOptional(typeSchemas.queryParams?.schema)
226
+ } : void 0,
227
+ headers: typeSchemas.headerParams?.name ? {
228
+ type: typeSchemas.headerParams?.name,
229
+ optional: oas.isOptional(typeSchemas.headerParams?.schema)
230
+ } : void 0
231
+ });
232
+ const dataParams = react.FunctionParams.factory({
233
+ data: {
234
+ // No use of pathParams because useMutation can only take one argument in object form,
235
+ // see https://tanstack.com/query/latest/docs/framework/react/reference/useMutation#usemutation
236
+ mode: "object",
237
+ children: Object.entries(mutationParams.params).reduce((acc, [key, value]) => {
238
+ if (value) {
239
+ acc[key] = {
240
+ ...value,
241
+ type: void 0
242
+ };
243
+ }
244
+ return acc;
245
+ }, {})
246
+ }
247
+ });
248
+ const TRequest = mutationParams.toConstructor({ valueAsType: true });
249
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
250
+ const generics = [TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error", TRequest ? `{${TRequest}}` : void 0].filter(Boolean).join(", ");
251
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(
252
+ react.Function,
253
+ {
254
+ name,
255
+ export: true,
256
+ params: params.toConstructor(),
257
+ JSDoc: {
258
+ comments: utils$1.getComments(operation)
259
+ },
260
+ children: `
261
+ const { mutation: mutationOptions, client: config = {} } = options ?? {}
262
+ const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}(${mutationKeyParams.toCall()})
263
+
264
+ return useMutation<${generics}>({
265
+ mutationFn: async(${dataParams.toConstructor()}) => {
266
+ return ${clientName}(${clientParams.toCall()})
267
+ },
268
+ mutationKey,
269
+ ...mutationOptions
270
+ })
271
+ `
272
+ }
273
+ ) });
274
+ }
275
+ function getParams4({ pathParamsType, typeSchemas }) {
276
+ return react.FunctionParams.factory({
277
+ pathParams: {
278
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
279
+ children: utils$1.getPathParams(typeSchemas.pathParams, { typed: true })
280
+ },
281
+ data: typeSchemas.request?.name ? {
282
+ type: typeSchemas.request?.name,
283
+ optional: oas.isOptional(typeSchemas.request?.schema)
284
+ } : void 0,
285
+ params: typeSchemas.queryParams?.name ? {
286
+ type: typeSchemas.queryParams?.name,
287
+ optional: oas.isOptional(typeSchemas.queryParams?.schema)
288
+ } : void 0
289
+ });
290
+ }
291
+ function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, keysFn = (name2) => name2 }) {
292
+ const path = new utils.URLPath(operation.path);
293
+ const params = getParams4({ pathParamsType, typeSchemas });
294
+ const keys = [
295
+ path.toObject({
296
+ type: "path",
297
+ stringify: true
298
+ }),
299
+ typeSchemas.queryParams?.name ? "...(params ? [params] : [])" : void 0,
300
+ typeSchemas.request?.name ? "...(data ? [data] : [])" : void 0
301
+ ].filter(Boolean);
302
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
303
+ /* @__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` }) }),
304
+ /* @__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}>` }) })
305
+ ] });
306
+ }
307
+ QueryKey.getParams = getParams4;
308
+ function getParams5({ paramsType, pathParamsType, typeSchemas }) {
309
+ if (paramsType === "object") {
310
+ return react.FunctionParams.factory({
311
+ data: {
312
+ mode: "object",
313
+ children: {
314
+ ...utils$1.getPathParams(typeSchemas.pathParams, { typed: true }),
315
+ data: typeSchemas.request?.name ? {
316
+ type: typeSchemas.request?.name,
317
+ optional: oas.isOptional(typeSchemas.request?.schema)
318
+ } : void 0,
319
+ params: typeSchemas.queryParams?.name ? {
320
+ type: typeSchemas.queryParams?.name,
321
+ optional: oas.isOptional(typeSchemas.queryParams?.schema)
322
+ } : void 0,
323
+ headers: typeSchemas.headerParams?.name ? {
324
+ type: typeSchemas.headerParams?.name,
325
+ optional: oas.isOptional(typeSchemas.headerParams?.schema)
326
+ } : void 0
327
+ }
328
+ },
329
+ config: {
330
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>",
331
+ default: "{}"
332
+ }
333
+ });
334
+ }
335
+ return react.FunctionParams.factory({
336
+ pathParams: typeSchemas.pathParams?.name ? {
337
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
338
+ children: utils$1.getPathParams(typeSchemas.pathParams, { typed: true }),
339
+ type: typeSchemas.pathParams?.name,
340
+ optional: oas.isOptional(typeSchemas.pathParams?.schema)
341
+ } : void 0,
342
+ data: typeSchemas.request?.name ? {
343
+ type: typeSchemas.request?.name,
344
+ optional: oas.isOptional(typeSchemas.request?.schema)
345
+ } : void 0,
346
+ params: typeSchemas.queryParams?.name ? {
347
+ type: typeSchemas.queryParams?.name,
348
+ optional: oas.isOptional(typeSchemas.queryParams?.schema)
349
+ } : void 0,
350
+ headers: typeSchemas.headerParams?.name ? {
351
+ type: typeSchemas.headerParams?.name,
352
+ optional: oas.isOptional(typeSchemas.headerParams?.schema)
353
+ } : void 0,
354
+ config: {
355
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>",
356
+ default: "{}"
357
+ }
358
+ });
359
+ }
360
+ function QueryOptions({ name, clientName, typeSchemas, paramsType, pathParamsType, queryKeyName }) {
361
+ const params = getParams5({ paramsType, pathParamsType, typeSchemas });
362
+ const clientParams = Client.getParams({
363
+ typeSchemas,
364
+ paramsType,
365
+ pathParamsType
366
+ });
367
+ const queryKeyParams = QueryKey.getParams({
368
+ pathParamsType,
369
+ typeSchemas
370
+ });
371
+ const enabled = Object.entries(queryKeyParams.flatParams).map(([key, item]) => item && !item.optional ? key : void 0).filter(Boolean).join("&& ");
372
+ const enabledText = enabled ? `enabled: !!(${enabled})` : "";
373
+ 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: `
374
+ const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
375
+ return queryOptions({
376
+ ${enabledText}
377
+ queryKey,
378
+ queryFn: async ({ signal }) => {
379
+ config.signal = signal
380
+ return ${clientName}(${clientParams.toCall({})})
381
+ },
382
+ })
383
+ ` }) });
384
+ }
385
+ QueryOptions.getParams = getParams5;
386
+ function getParams6({ paramsType, pathParamsType, dataReturnType, typeSchemas }) {
387
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
388
+ if (paramsType === "object") {
389
+ return react.FunctionParams.factory({
390
+ data: {
391
+ mode: "object",
392
+ children: {
393
+ ...utils$1.getPathParams(typeSchemas.pathParams, { typed: true }),
394
+ data: typeSchemas.request?.name ? {
395
+ type: typeSchemas.request?.name,
396
+ optional: oas.isOptional(typeSchemas.request?.schema)
397
+ } : void 0,
398
+ params: typeSchemas.queryParams?.name ? {
399
+ type: typeSchemas.queryParams?.name,
400
+ optional: oas.isOptional(typeSchemas.queryParams?.schema)
401
+ } : void 0,
402
+ headers: typeSchemas.headerParams?.name ? {
403
+ type: typeSchemas.headerParams?.name,
404
+ optional: oas.isOptional(typeSchemas.headerParams?.schema)
405
+ } : void 0
406
+ }
407
+ },
408
+ options: {
409
+ type: `
410
+ {
411
+ query?: Partial<QueryObserverOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error", "TData", "TQueryData", "TQueryKey"].join(", ")}>>,
412
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"}
413
+ }
414
+ `,
415
+ default: "{}"
416
+ }
417
+ });
418
+ }
419
+ return react.FunctionParams.factory({
420
+ pathParams: typeSchemas.pathParams?.name ? {
421
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
422
+ children: utils$1.getPathParams(typeSchemas.pathParams, { typed: true }),
423
+ type: typeSchemas.pathParams?.name,
424
+ optional: oas.isOptional(typeSchemas.pathParams?.schema)
425
+ } : void 0,
426
+ data: typeSchemas.request?.name ? {
427
+ type: typeSchemas.request?.name,
428
+ optional: oas.isOptional(typeSchemas.request?.schema)
429
+ } : void 0,
430
+ params: typeSchemas.queryParams?.name ? {
431
+ type: typeSchemas.queryParams?.name,
432
+ optional: oas.isOptional(typeSchemas.queryParams?.schema)
433
+ } : void 0,
434
+ headers: typeSchemas.headerParams?.name ? {
435
+ type: typeSchemas.headerParams?.name,
436
+ optional: oas.isOptional(typeSchemas.headerParams?.schema)
437
+ } : void 0,
438
+ options: {
439
+ type: `
440
+ {
441
+ query?: Partial<QueryObserverOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error", "TData", "TQueryData", "TQueryKey"].join(", ")}>>,
442
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"}
443
+ }
444
+ `,
445
+ default: "{}"
446
+ }
447
+ });
448
+ }
449
+ function Query({
450
+ name,
451
+ queryKeyTypeName,
452
+ queryOptionsName,
453
+ queryKeyName,
454
+ paramsType,
455
+ pathParamsType,
456
+ dataReturnType,
457
+ typeSchemas,
458
+ operation
459
+ }) {
460
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
461
+ const returnType = `UseQueryResult<${["TData", typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"].join(", ")}> & { queryKey: TQueryKey }`;
462
+ const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
463
+ const queryKeyParams = QueryKey.getParams({
464
+ pathParamsType,
465
+ typeSchemas
466
+ });
467
+ const queryOptionsParams = QueryOptions.getParams({
468
+ paramsType,
469
+ pathParamsType,
470
+ typeSchemas
471
+ });
472
+ const params = getParams6({
473
+ paramsType,
474
+ pathParamsType,
475
+ dataReturnType,
476
+ typeSchemas
477
+ });
478
+ const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()}) as unknown as QueryObserverOptions`;
479
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(
480
+ react.Function,
481
+ {
482
+ name,
483
+ export: true,
484
+ generics: generics.join(", "),
485
+ params: params.toConstructor(),
486
+ JSDoc: {
487
+ comments: utils$1.getComments(operation)
488
+ },
489
+ children: `
490
+ const { query: queryOptions, client: config = {} } = options ?? {}
491
+ const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
492
+
493
+ const query = useQuery({
494
+ ...${queryOptions},
495
+ queryKey,
496
+ ...queryOptions as unknown as Omit<QueryObserverOptions, "queryKey">
497
+ }) as ${returnType}
498
+
499
+ query.queryKey = queryKey as TQueryKey
500
+
501
+ return query
502
+ `
503
+ }
504
+ ) });
505
+ }
506
+ Query.getParams = getParams6;
507
+ function getParams7({ paramsType, pathParamsType, typeSchemas }) {
508
+ if (paramsType === "object") {
509
+ return react.FunctionParams.factory({
510
+ data: {
511
+ mode: "object",
512
+ children: {
513
+ ...utils$1.getPathParams(typeSchemas.pathParams, { typed: true }),
514
+ data: typeSchemas.request?.name ? {
515
+ type: typeSchemas.request?.name,
516
+ optional: oas.isOptional(typeSchemas.request?.schema)
517
+ } : void 0,
518
+ params: typeSchemas.queryParams?.name ? {
519
+ type: typeSchemas.queryParams?.name,
520
+ optional: oas.isOptional(typeSchemas.queryParams?.schema)
521
+ } : void 0,
522
+ headers: typeSchemas.headerParams?.name ? {
523
+ type: typeSchemas.headerParams?.name,
524
+ optional: oas.isOptional(typeSchemas.headerParams?.schema)
525
+ } : void 0
526
+ }
527
+ },
528
+ config: {
529
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>",
530
+ default: "{}"
531
+ }
532
+ });
533
+ }
534
+ return react.FunctionParams.factory({
535
+ pathParams: typeSchemas.pathParams?.name ? {
536
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
537
+ children: utils$1.getPathParams(typeSchemas.pathParams, { typed: true }),
538
+ type: typeSchemas.pathParams?.name,
539
+ optional: oas.isOptional(typeSchemas.pathParams?.schema)
540
+ } : void 0,
541
+ data: typeSchemas.request?.name ? {
542
+ type: typeSchemas.request?.name,
543
+ optional: oas.isOptional(typeSchemas.request?.schema)
544
+ } : void 0,
545
+ params: typeSchemas.queryParams?.name ? {
546
+ type: typeSchemas.queryParams?.name,
547
+ optional: oas.isOptional(typeSchemas.queryParams?.schema)
548
+ } : void 0,
549
+ headers: typeSchemas.headerParams?.name ? {
550
+ type: typeSchemas.headerParams?.name,
551
+ optional: oas.isOptional(typeSchemas.headerParams?.schema)
552
+ } : void 0,
553
+ config: {
554
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>",
555
+ default: "{}"
556
+ }
557
+ });
558
+ }
559
+ function InfiniteQueryOptions({
560
+ name,
561
+ clientName,
562
+ initialPageParam,
563
+ cursorParam,
564
+ typeSchemas,
565
+ paramsType,
566
+ dataReturnType,
567
+ pathParamsType,
568
+ queryParam,
569
+ queryKeyName
570
+ }) {
571
+ const params = getParams7({ paramsType, pathParamsType, typeSchemas });
572
+ const clientParams = Client.getParams({
573
+ typeSchemas,
574
+ paramsType,
575
+ pathParamsType
576
+ });
577
+ const queryKeyParams = QueryKey.getParams({
578
+ pathParamsType,
579
+ typeSchemas
580
+ });
581
+ const queryOptions = [
582
+ `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
583
+ cursorParam ? `getNextPageParam: (lastPage) => lastPage['${cursorParam}']` : void 0,
584
+ cursorParam ? `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']` : void 0,
585
+ !cursorParam && dataReturnType === "full" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1" : void 0,
586
+ !cursorParam && dataReturnType === "data" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1" : void 0,
587
+ !cursorParam ? "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1" : void 0
588
+ ].filter(Boolean);
589
+ const infiniteOverrideParams = queryParam && typeSchemas.queryParams?.name ? `
590
+ if(params) {
591
+ params['${queryParam}'] = pageParam as unknown as ${typeSchemas.queryParams?.name}['${queryParam}']
592
+ }` : "";
593
+ const enabled = Object.entries(queryKeyParams.flatParams).map(([key, item]) => item && !item.optional ? key : void 0).filter(Boolean).join("&& ");
594
+ const enabledText = enabled ? `enabled: !!(${enabled})` : "";
595
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsxs(react.Function, { name, export: true, params: params.toConstructor(), children: [
596
+ infiniteOverrideParams && `
597
+ const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
598
+ return infiniteQueryOptions({
599
+ ${enabledText}
600
+ queryKey,
601
+ queryFn: async ({ signal, pageParam }) => {
602
+ config.signal = signal
603
+ ${infiniteOverrideParams}
604
+ return ${clientName}(${clientParams.toCall()})
605
+ },
606
+ ${queryOptions.join("\n")}
607
+ })
608
+ `,
609
+ !infiniteOverrideParams && `
610
+ const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
611
+ return infiniteQueryOptions({
612
+ ${enabledText}
613
+ queryKey,
614
+ queryFn: async ({ signal }) => {
615
+ config.signal = signal
616
+ return ${clientName}(${clientParams.toCall()})
617
+ },
618
+ ${queryOptions.join("\n")}
619
+ })
620
+ `
621
+ ] }) });
622
+ }
623
+ InfiniteQueryOptions.getParams = getParams7;
624
+ function getParams8({ paramsType, pathParamsType, dataReturnType, typeSchemas }) {
625
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
626
+ if (paramsType === "object") {
627
+ return react.FunctionParams.factory({
628
+ data: {
629
+ mode: "object",
630
+ children: {
631
+ ...utils$1.getPathParams(typeSchemas.pathParams, { typed: true }),
632
+ data: typeSchemas.request?.name ? {
633
+ type: typeSchemas.request?.name,
634
+ optional: oas.isOptional(typeSchemas.request?.schema)
635
+ } : void 0,
636
+ params: typeSchemas.queryParams?.name ? {
637
+ type: typeSchemas.queryParams?.name,
638
+ optional: oas.isOptional(typeSchemas.queryParams?.schema)
639
+ } : void 0,
640
+ headers: typeSchemas.headerParams?.name ? {
641
+ type: typeSchemas.headerParams?.name,
642
+ optional: oas.isOptional(typeSchemas.headerParams?.schema)
643
+ } : void 0
644
+ }
645
+ },
646
+ options: {
647
+ type: `
648
+ {
649
+ query?: Partial<InfiniteQueryObserverOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error", "TData", "TQueryData", "TQueryKey"].join(", ")}>>,
650
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"}
651
+ }
652
+ `,
653
+ default: "{}"
654
+ }
655
+ });
656
+ }
657
+ return react.FunctionParams.factory({
658
+ pathParams: typeSchemas.pathParams?.name ? {
659
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
660
+ children: utils$1.getPathParams(typeSchemas.pathParams, { typed: true }),
661
+ type: typeSchemas.pathParams?.name,
662
+ optional: oas.isOptional(typeSchemas.pathParams?.schema)
663
+ } : void 0,
664
+ data: typeSchemas.request?.name ? {
665
+ type: typeSchemas.request?.name,
666
+ optional: oas.isOptional(typeSchemas.request?.schema)
667
+ } : void 0,
668
+ params: typeSchemas.queryParams?.name ? {
669
+ type: typeSchemas.queryParams?.name,
670
+ optional: oas.isOptional(typeSchemas.queryParams?.schema)
671
+ } : void 0,
672
+ headers: typeSchemas.headerParams?.name ? {
673
+ type: typeSchemas.headerParams?.name,
674
+ optional: oas.isOptional(typeSchemas.headerParams?.schema)
675
+ } : void 0,
676
+ options: {
677
+ type: `
678
+ {
679
+ query?: Partial<InfiniteQueryObserverOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error", "TData", "TQueryData", "TQueryKey"].join(", ")}>>,
680
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"}
681
+ }
682
+ `,
683
+ default: "{}"
684
+ }
685
+ });
686
+ }
687
+ function InfiniteQuery({
688
+ name,
689
+ queryKeyTypeName,
690
+ queryOptionsName,
691
+ queryKeyName,
692
+ paramsType,
693
+ pathParamsType,
694
+ dataReturnType,
695
+ typeSchemas,
696
+ operation
697
+ }) {
698
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
699
+ const returnType = `UseInfiniteQueryResult<${["TData", typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"].join(", ")}> & { queryKey: TQueryKey }`;
700
+ const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
701
+ const queryKeyParams = QueryKey.getParams({
702
+ pathParamsType,
703
+ typeSchemas
704
+ });
705
+ const queryOptionsParams = QueryOptions.getParams({
706
+ paramsType,
707
+ pathParamsType,
708
+ typeSchemas
709
+ });
710
+ const params = getParams8({
711
+ paramsType,
712
+ pathParamsType,
713
+ dataReturnType,
714
+ typeSchemas
715
+ });
716
+ const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()}) as unknown as InfiniteQueryObserverOptions`;
717
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(
718
+ react.Function,
719
+ {
720
+ name,
721
+ export: true,
722
+ generics: generics.join(", "),
723
+ params: params.toConstructor(),
724
+ JSDoc: {
725
+ comments: utils$1.getComments(operation)
726
+ },
727
+ children: `
728
+ const { query: queryOptions, client: config = {} } = options ?? {}
729
+ const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
730
+
731
+ const query = useInfiniteQuery({
732
+ ...${queryOptions},
733
+ queryKey,
734
+ ...queryOptions as unknown as Omit<InfiniteQueryObserverOptions, "queryKey">
735
+ }) as ${returnType}
736
+
737
+ query.queryKey = queryKey as TQueryKey
738
+
739
+ return query
740
+ `
741
+ }
742
+ ) });
743
+ }
744
+ InfiniteQuery.getParams = getParams8;
745
+ function getParams9({ paramsType, pathParamsType, dataReturnType, typeSchemas }) {
746
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
747
+ if (paramsType === "object") {
748
+ return react.FunctionParams.factory({
749
+ data: {
750
+ mode: "object",
751
+ children: {
752
+ ...utils$1.getPathParams(typeSchemas.pathParams, { typed: true }),
753
+ data: typeSchemas.request?.name ? {
754
+ type: typeSchemas.request?.name,
755
+ optional: oas.isOptional(typeSchemas.request?.schema)
756
+ } : void 0,
757
+ params: typeSchemas.queryParams?.name ? {
758
+ type: typeSchemas.queryParams?.name,
759
+ optional: oas.isOptional(typeSchemas.queryParams?.schema)
760
+ } : void 0,
761
+ headers: typeSchemas.headerParams?.name ? {
762
+ type: typeSchemas.headerParams?.name,
763
+ optional: oas.isOptional(typeSchemas.headerParams?.schema)
764
+ } : void 0
765
+ }
766
+ },
767
+ options: {
768
+ type: `
769
+ {
770
+ query?: Partial<UseSuspenseQueryOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error", "TData", "TQueryKey"].join(", ")}>>,
771
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"}
772
+ }
773
+ `,
774
+ default: "{}"
775
+ }
776
+ });
777
+ }
778
+ return react.FunctionParams.factory({
779
+ pathParams: typeSchemas.pathParams?.name ? {
780
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
781
+ children: utils$1.getPathParams(typeSchemas.pathParams, { typed: true }),
782
+ type: typeSchemas.pathParams?.name,
783
+ optional: oas.isOptional(typeSchemas.pathParams?.schema)
784
+ } : void 0,
785
+ data: typeSchemas.request?.name ? {
786
+ type: typeSchemas.request?.name,
787
+ optional: oas.isOptional(typeSchemas.request?.schema)
788
+ } : void 0,
789
+ params: typeSchemas.queryParams?.name ? {
790
+ type: typeSchemas.queryParams?.name,
791
+ optional: oas.isOptional(typeSchemas.queryParams?.schema)
792
+ } : void 0,
793
+ headers: typeSchemas.headerParams?.name ? {
794
+ type: typeSchemas.headerParams?.name,
795
+ optional: oas.isOptional(typeSchemas.headerParams?.schema)
796
+ } : void 0,
797
+ options: {
798
+ type: `
799
+ {
800
+ query?: Partial<UseSuspenseQueryOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error", "TData", "TQueryKey"].join(", ")}>>,
801
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : "Partial<RequestConfig>"}
802
+ }
803
+ `,
804
+ default: "{}"
805
+ }
806
+ });
807
+ }
808
+ function SuspenseQuery({
809
+ name,
810
+ queryKeyTypeName,
811
+ queryOptionsName,
812
+ queryKeyName,
813
+ paramsType,
814
+ pathParamsType,
815
+ dataReturnType,
816
+ typeSchemas,
817
+ operation
818
+ }) {
819
+ const TData = dataReturnType === "data" ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`;
820
+ const returnType = `UseSuspenseQueryResult<${["TData", typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"].join(", ")}> & { queryKey: TQueryKey }`;
821
+ const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
822
+ const queryKeyParams = QueryKey.getParams({
823
+ pathParamsType,
824
+ typeSchemas
825
+ });
826
+ const queryOptionsParams = QueryOptions.getParams({
827
+ paramsType,
828
+ pathParamsType,
829
+ typeSchemas
830
+ });
831
+ const params = getParams9({
832
+ paramsType,
833
+ pathParamsType,
834
+ dataReturnType,
835
+ typeSchemas
836
+ });
837
+ const queryOptions = `${queryOptionsName}(${queryOptionsParams.toCall()}) as unknown as UseSuspenseQueryOptions`;
838
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(
839
+ react.Function,
840
+ {
841
+ name,
842
+ export: true,
843
+ generics: generics.join(", "),
844
+ params: params.toConstructor(),
845
+ JSDoc: {
846
+ comments: utils$1.getComments(operation)
847
+ },
848
+ children: `
849
+ const { query: queryOptions, client: config = {} } = options ?? {}
850
+ const queryKey = queryOptions?.queryKey ?? ${queryKeyName}(${queryKeyParams.toCall()})
851
+
852
+ const query = useSuspenseQuery({
853
+ ...${queryOptions},
854
+ queryKey,
855
+ ...queryOptions as unknown as Omit<UseSuspenseQueryOptions, "queryKey">
856
+ }) as ${returnType}
857
+
858
+ query.queryKey = queryKey as TQueryKey
859
+
860
+ return query
861
+ `
862
+ }
863
+ ) });
864
+ }
865
+ SuspenseQuery.getParams = getParams9;
866
+
867
+ exports.Client = Client;
868
+ exports.InfiniteQuery = InfiniteQuery;
869
+ exports.InfiniteQueryOptions = InfiniteQueryOptions;
870
+ exports.Mutation = Mutation;
871
+ exports.MutationKey = MutationKey;
872
+ exports.Operations = Operations;
873
+ exports.Query = Query;
874
+ exports.QueryKey = QueryKey;
875
+ exports.QueryOptions = QueryOptions;
876
+ exports.SuspenseQuery = SuspenseQuery;
877
+ //# sourceMappingURL=chunk-BML6BZ4F.cjs.map
878
+ //# sourceMappingURL=chunk-BML6BZ4F.cjs.map