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