@kubb/plugin-vue-query 0.0.0-canary-20250724082832 → 0.0.0-canary-20250816141041

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