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

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