@kubb/plugin-react-query 3.0.0-alpha.9 → 3.0.0-beta.2

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