@kubb/plugin-react-query 3.16.1 → 3.16.3

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