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