@kubb/plugin-vue-query 3.16.2 → 3.16.3

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