@kubb/plugin-vue-query 3.16.2 → 3.16.4

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