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

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