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