@kubb/plugin-react-query 3.0.0-alpha.3 → 3.0.0-alpha.31

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 (81) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-C2H3KPHM.cjs +658 -0
  3. package/dist/chunk-C2H3KPHM.cjs.map +1 -0
  4. package/dist/chunk-J7NSRJSY.js +661 -0
  5. package/dist/chunk-J7NSRJSY.js.map +1 -0
  6. package/dist/chunk-M5RJDPKE.cjs +670 -0
  7. package/dist/chunk-M5RJDPKE.cjs.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 -14
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +161 -7
  13. package/dist/components.d.ts +161 -7
  14. package/dist/components.js +2 -14
  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 +75 -155
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +1 -5
  25. package/dist/index.d.ts +1 -5
  26. package/dist/index.js +58 -145
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-oaGq_oPb.d.cts +169 -0
  29. package/dist/types-oaGq_oPb.d.ts +169 -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 +138 -322
  34. package/src/components/MutationKey.tsx +48 -0
  35. package/src/components/Query.tsx +91 -598
  36. package/src/components/QueryKey.tsx +51 -178
  37. package/src/components/QueryOptions.tsx +72 -466
  38. package/src/components/SuspenseQuery.tsx +129 -0
  39. package/src/components/index.ts +4 -1
  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 +58 -83
  59. package/src/types.ts +50 -107
  60. package/dist/chunk-5IL6M74X.js +0 -1504
  61. package/dist/chunk-5IL6M74X.js.map +0 -1
  62. package/dist/chunk-JFX7DCS7.cjs +0 -1504
  63. package/dist/chunk-JFX7DCS7.cjs.map +0 -1
  64. package/dist/index-C9fwRDH7.d.cts +0 -579
  65. package/dist/index-C9fwRDH7.d.ts +0 -579
  66. package/src/OperationGenerator.tsx +0 -86
  67. package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -64
  68. package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -57
  69. package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -63
  70. package/src/__snapshots__/queryOptions/getPetById.ts +0 -37
  71. package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -47
  72. package/src/__snapshots__/upload/UploadFile.ts +0 -67
  73. package/src/__snapshots__/uploadMutation/UploadFile.ts +0 -44
  74. package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -21
  75. package/src/components/Operations.tsx +0 -74
  76. package/src/components/QueryImports.tsx +0 -167
  77. package/src/components/SchemaType.tsx +0 -55
  78. package/src/components/__snapshots__/gen/showPetById.ts +0 -57
  79. package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
  80. package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -47
  81. package/src/utils.ts +0 -96
@@ -0,0 +1,661 @@
1
+ import { Client, Operations, QueryKey, QueryOptions, Query, MutationKey, Mutation, InfiniteQueryOptions, InfiniteQuery, SuspenseQuery } from './chunk-Y3DM2P6L.js';
2
+ import { camelCase } from '@kubb/core/transformers';
3
+ import path from 'node:path';
4
+ import { createPlugin, FileManager, PluginManager } from '@kubb/core';
5
+ import '@kubb/core/utils';
6
+ import { createReactGenerator, pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
7
+ import { pluginZodName } from '@kubb/plugin-zod';
8
+ import { useOperationManager } from '@kubb/plugin-oas/hooks';
9
+ import { pluginTsName } from '@kubb/plugin-ts';
10
+ import { useApp, File, Function } from '@kubb/react';
11
+ import { jsxs, jsx } from '@kubb/react/jsx-runtime';
12
+
13
+ var clientGenerator = createReactGenerator({
14
+ name: "client",
15
+ Operation({ options, operation }) {
16
+ const {
17
+ plugin: {
18
+ options: { output }
19
+ }
20
+ } = useApp();
21
+ const { getSchemas, getName, getFile } = useOperationManager();
22
+ const client = {
23
+ name: getName(operation, { type: "function" }),
24
+ file: getFile(operation)
25
+ };
26
+ const type = {
27
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
28
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
29
+ };
30
+ const zod = {
31
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
32
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: "function" })
33
+ };
34
+ return /* @__PURE__ */ jsxs(File, { baseName: client.file.baseName, path: client.file.path, meta: client.file.meta, banner: output?.banner, footer: output?.footer, children: [
35
+ /* @__PURE__ */ jsx(File.Import, { name: "client", path: options.importPath }),
36
+ /* @__PURE__ */ jsx(File.Import, { name: ["RequestConfig"], path: options.importPath, isTypeOnly: true }),
37
+ options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, { name: [zod.schemas.response.name], root: client.file.path, path: zod.file.path }),
38
+ /* @__PURE__ */ jsx(
39
+ File.Import,
40
+ {
41
+ name: [
42
+ type.schemas.request?.name,
43
+ type.schemas.response.name,
44
+ type.schemas.pathParams?.name,
45
+ type.schemas.queryParams?.name,
46
+ type.schemas.headerParams?.name,
47
+ ...type.schemas.statusCodes?.map((item) => item.name) || []
48
+ ].filter(Boolean),
49
+ root: client.file.path,
50
+ path: type.file.path,
51
+ isTypeOnly: true
52
+ }
53
+ ),
54
+ /* @__PURE__ */ jsx(
55
+ Client,
56
+ {
57
+ name: client.name,
58
+ baseURL: options.baseURL,
59
+ dataReturnType: options.dataReturnType,
60
+ pathParamsType: options.pathParamsType,
61
+ typeSchemas: type.schemas,
62
+ operation,
63
+ parser: options.parser,
64
+ zodSchemas: zod.schemas
65
+ }
66
+ )
67
+ ] });
68
+ }
69
+ });
70
+ var operationsGenerator = createReactGenerator({
71
+ name: "client",
72
+ Operations({ operations }) {
73
+ const {
74
+ pluginManager,
75
+ plugin: {
76
+ options: { output }
77
+ }
78
+ } = useApp();
79
+ const name = "operations";
80
+ const file = pluginManager.getFile({ name, extname: ".ts", pluginKey: [pluginClientName] });
81
+ return /* @__PURE__ */ jsx(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: output?.banner, footer: output?.footer, children: /* @__PURE__ */ jsx(Operations, { name, operations }) });
82
+ }
83
+ });
84
+ var groupedClientGenerator = createReactGenerator({
85
+ name: "groupedClient",
86
+ Operations({ operations }) {
87
+ const {
88
+ pluginManager,
89
+ plugin: { options }
90
+ } = useApp();
91
+ const { getName, getFile } = useOperationManager();
92
+ const controllers = operations.reduce(
93
+ (acc, operation) => {
94
+ if (options.group?.type === "tag") {
95
+ const tag = operation.getTags().at(0)?.name;
96
+ const name = tag ? options.group?.name?.({ group: camelCase(tag) }) : void 0;
97
+ if (!tag || !name) {
98
+ return acc;
99
+ }
100
+ const file = pluginManager.getFile({
101
+ name,
102
+ extname: ".ts",
103
+ pluginKey: [pluginClientName],
104
+ options: { tag }
105
+ });
106
+ const client = {
107
+ name: getName(operation, { type: "function" }),
108
+ file: getFile(operation)
109
+ };
110
+ const previousFile = acc.find((item) => item.file.path === file.path);
111
+ if (previousFile) {
112
+ previousFile.clients.push(client);
113
+ } else {
114
+ acc.push({ name, file, clients: [client] });
115
+ }
116
+ }
117
+ return acc;
118
+ },
119
+ []
120
+ );
121
+ return controllers.map(({ name, file, clients }) => {
122
+ return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: options.output?.banner, footer: options.output?.footer, children: [
123
+ clients.map((client) => /* @__PURE__ */ jsx(File.Import, { name: [client.name], root: file.path, path: client.file.path }, client.name)),
124
+ /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Function, { export: true, name, children: `return { ${clients.map((client) => client.name).join(", ")} }` }) })
125
+ ] }, file.path);
126
+ });
127
+ }
128
+ });
129
+
130
+ // ../plugin-client/src/plugin.ts
131
+ var pluginClientName = "plugin-client";
132
+ createPlugin((options) => {
133
+ const {
134
+ output = { path: "clients", barrelType: "named" },
135
+ group,
136
+ exclude = [],
137
+ include,
138
+ override = [],
139
+ transformers: transformers5 = {},
140
+ dataReturnType = "data",
141
+ pathParamsType = "inline",
142
+ operations = false,
143
+ generators = [clientGenerator, group ? groupedClientGenerator : void 0, operations ? operationsGenerator : void 0].filter(Boolean),
144
+ importPath = "@kubb/plugin-client/client",
145
+ parser = "client"
146
+ } = options;
147
+ return {
148
+ name: pluginClientName,
149
+ options: {
150
+ output,
151
+ group,
152
+ parser,
153
+ dataReturnType,
154
+ importPath,
155
+ pathParamsType,
156
+ baseURL: void 0
157
+ },
158
+ pre: [pluginOasName, parser === "zod" ? pluginZodName : void 0].filter(Boolean),
159
+ resolvePath(baseName, pathMode, options2) {
160
+ const root = path.resolve(this.config.root, this.config.output.path);
161
+ const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
162
+ if (options2?.tag && group?.type === "tag") {
163
+ const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
164
+ return path.resolve(root, output.path, groupName({ group: camelCase(options2.tag) }), baseName);
165
+ }
166
+ if (mode === "single") {
167
+ return path.resolve(root, output.path);
168
+ }
169
+ return path.resolve(root, output.path, baseName);
170
+ },
171
+ resolveName(name, type) {
172
+ const resolvedName = camelCase(name, { isFile: type === "file" });
173
+ if (type) {
174
+ return transformers5?.name?.(resolvedName, type) || resolvedName;
175
+ }
176
+ return resolvedName;
177
+ },
178
+ async buildStart() {
179
+ const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
180
+ const oas = await swaggerPlugin.context.getOas();
181
+ const root = path.resolve(this.config.root, this.config.output.path);
182
+ const mode = FileManager.getMode(path.resolve(root, output.path));
183
+ const baseURL = await swaggerPlugin.context.getBaseURL();
184
+ const operationGenerator = new OperationGenerator(
185
+ {
186
+ ...this.plugin.options,
187
+ baseURL
188
+ },
189
+ {
190
+ oas,
191
+ pluginManager: this.pluginManager,
192
+ plugin: this.plugin,
193
+ contentType: swaggerPlugin.context.contentType,
194
+ exclude,
195
+ include,
196
+ override,
197
+ mode
198
+ }
199
+ );
200
+ const files = await operationGenerator.build(...generators);
201
+ await this.addFile(...files);
202
+ const barrelFiles = await this.fileManager.getBarrelFiles({
203
+ type: output.barrelType ?? "named",
204
+ root,
205
+ output,
206
+ files: this.fileManager.files,
207
+ meta: {
208
+ pluginKey: this.plugin.key
209
+ },
210
+ logger: this.logger
211
+ });
212
+ await this.addFile(...barrelFiles);
213
+ }
214
+ };
215
+ });
216
+ var queryGenerator = createReactGenerator({
217
+ name: "react-query",
218
+ Operation({ options, operation }) {
219
+ const {
220
+ plugin: {
221
+ options: { output }
222
+ }
223
+ } = useApp();
224
+ const { getSchemas, getName, getFile } = useOperationManager();
225
+ const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
226
+ !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method);
227
+ const query = {
228
+ name: getName(operation, { type: "function", prefix: "use" }),
229
+ typeName: getName(operation, { type: "type" }),
230
+ file: getFile(operation, { prefix: "use" })
231
+ };
232
+ const client = {
233
+ name: getName(operation, { type: "function", pluginKey: [pluginClientName] })
234
+ };
235
+ const queryOptions = {
236
+ name: getName(operation, { type: "function", suffix: "QueryOptions" })
237
+ };
238
+ const queryKey = {
239
+ name: getName(operation, { type: "const", suffix: "QueryKey" }),
240
+ typeName: getName(operation, { type: "type", suffix: "QueryKey" })
241
+ };
242
+ const type = {
243
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
244
+ //todo remove type?
245
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
246
+ };
247
+ const zod = {
248
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
249
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: "function" })
250
+ };
251
+ if (!isQuery || typeof options.query === "boolean") {
252
+ return null;
253
+ }
254
+ return /* @__PURE__ */ jsxs(File, { baseName: query.file.baseName, path: query.file.path, meta: query.file.meta, banner: output?.banner, footer: output?.footer, children: [
255
+ options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, { name: [zod.schemas.response.name], root: query.file.path, path: zod.file.path }),
256
+ /* @__PURE__ */ jsx(File.Import, { name: ["useQuery", "queryOptions"], path: options.query.importPath }),
257
+ /* @__PURE__ */ jsx(File.Import, { name: ["QueryKey", "WithRequired", "QueryObserverOptions", "UseQueryResult"], path: options.query.importPath, isTypeOnly: true }),
258
+ /* @__PURE__ */ jsx(File.Import, { name: "client", path: options.client.importPath }),
259
+ /* @__PURE__ */ jsx(File.Import, { name: ["RequestConfig"], path: options.client.importPath, isTypeOnly: true }),
260
+ options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, { name: ["ResponseConfig"], path: options.client.importPath, isTypeOnly: true }),
261
+ /* @__PURE__ */ jsx(
262
+ File.Import,
263
+ {
264
+ name: [
265
+ type.schemas.request?.name,
266
+ type.schemas.response.name,
267
+ type.schemas.pathParams?.name,
268
+ type.schemas.queryParams?.name,
269
+ type.schemas.headerParams?.name,
270
+ ...type.schemas.statusCodes?.map((item) => item.name) || []
271
+ ].filter(Boolean),
272
+ root: query.file.path,
273
+ path: type.file.path,
274
+ isTypeOnly: true
275
+ }
276
+ ),
277
+ /* @__PURE__ */ jsx(
278
+ QueryKey,
279
+ {
280
+ name: queryKey.name,
281
+ typeName: queryKey.typeName,
282
+ operation,
283
+ pathParamsType: options.pathParamsType,
284
+ typeSchemas: type.schemas,
285
+ keysFn: options.query.key
286
+ }
287
+ ),
288
+ /* @__PURE__ */ jsx(
289
+ Client,
290
+ {
291
+ name: client.name,
292
+ isExportable: false,
293
+ isIndexable: false,
294
+ baseURL: options.baseURL,
295
+ operation,
296
+ typeSchemas: type.schemas,
297
+ zodSchemas: zod.schemas,
298
+ dataReturnType: options.client.dataReturnType,
299
+ pathParamsType: options.pathParamsType,
300
+ parser: options.parser
301
+ }
302
+ ),
303
+ /* @__PURE__ */ jsx(
304
+ QueryOptions,
305
+ {
306
+ name: queryOptions.name,
307
+ clientName: client.name,
308
+ queryKeyName: queryKey.name,
309
+ typeSchemas: type.schemas,
310
+ pathParamsType: options.pathParamsType
311
+ }
312
+ ),
313
+ /* @__PURE__ */ jsx(
314
+ Query,
315
+ {
316
+ name: query.name,
317
+ queryOptionsName: queryOptions.name,
318
+ typeSchemas: type.schemas,
319
+ pathParamsType: options.pathParamsType,
320
+ operation,
321
+ dataReturnType: options.client.dataReturnType,
322
+ queryKeyName: queryKey.name,
323
+ queryKeyTypeName: queryKey.typeName
324
+ }
325
+ )
326
+ ] });
327
+ }
328
+ });
329
+ var mutationGenerator = createReactGenerator({
330
+ name: "react-query",
331
+ Operation({ options, operation }) {
332
+ const {
333
+ plugin: {
334
+ options: { output }
335
+ }
336
+ } = useApp();
337
+ const { getSchemas, getName, getFile } = useOperationManager();
338
+ const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
339
+ const isMutation = !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method);
340
+ const mutation = {
341
+ name: getName(operation, { type: "function", prefix: "use" }),
342
+ typeName: getName(operation, { type: "type" }),
343
+ file: getFile(operation, { prefix: "use" })
344
+ };
345
+ const type = {
346
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
347
+ //todo remove type?
348
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
349
+ };
350
+ const zod = {
351
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
352
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: "function" })
353
+ };
354
+ const client = {
355
+ name: getName(operation, { type: "function", pluginKey: [pluginClientName] })
356
+ };
357
+ const mutationKey = {
358
+ name: getName(operation, { type: "const", suffix: "MutationKey" }),
359
+ typeName: getName(operation, { type: "type", suffix: "MutationKey" })
360
+ };
361
+ if (!isMutation || typeof options.mutation === "boolean") {
362
+ return null;
363
+ }
364
+ return /* @__PURE__ */ jsxs(File, { baseName: mutation.file.baseName, path: mutation.file.path, meta: mutation.file.meta, banner: output?.banner, footer: output?.footer, children: [
365
+ options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, { name: [zod.schemas.response.name], root: mutation.file.path, path: zod.file.path }),
366
+ /* @__PURE__ */ jsx(File.Import, { name: ["useMutation"], path: options.mutation.importPath }),
367
+ /* @__PURE__ */ jsx(File.Import, { name: ["UseMutationOptions"], path: options.mutation.importPath, isTypeOnly: true }),
368
+ /* @__PURE__ */ jsx(File.Import, { name: "client", path: options.client.importPath }),
369
+ /* @__PURE__ */ jsx(File.Import, { name: ["RequestConfig", "ResponseConfig"], path: options.client.importPath, isTypeOnly: true }),
370
+ /* @__PURE__ */ jsx(
371
+ File.Import,
372
+ {
373
+ name: [
374
+ type.schemas.request?.name,
375
+ type.schemas.response.name,
376
+ type.schemas.pathParams?.name,
377
+ type.schemas.queryParams?.name,
378
+ type.schemas.headerParams?.name,
379
+ ...type.schemas.statusCodes?.map((item) => item.name) || []
380
+ ].filter(Boolean),
381
+ root: mutation.file.path,
382
+ path: type.file.path,
383
+ isTypeOnly: true
384
+ }
385
+ ),
386
+ /* @__PURE__ */ jsx(
387
+ MutationKey,
388
+ {
389
+ name: mutationKey.name,
390
+ typeName: mutationKey.typeName,
391
+ operation,
392
+ pathParamsType: options.pathParamsType,
393
+ typeSchemas: type.schemas,
394
+ keysFn: options.mutation.key
395
+ }
396
+ ),
397
+ /* @__PURE__ */ jsx(
398
+ Client,
399
+ {
400
+ name: client.name,
401
+ isExportable: false,
402
+ isIndexable: false,
403
+ baseURL: options.baseURL,
404
+ operation,
405
+ typeSchemas: type.schemas,
406
+ zodSchemas: zod.schemas,
407
+ dataReturnType: options.client.dataReturnType,
408
+ pathParamsType: options.pathParamsType,
409
+ parser: options.parser
410
+ }
411
+ ),
412
+ /* @__PURE__ */ jsx(
413
+ Mutation,
414
+ {
415
+ name: mutation.name,
416
+ clientName: client.name,
417
+ typeName: mutation.typeName,
418
+ typeSchemas: type.schemas,
419
+ operation,
420
+ dataReturnType: options.client.dataReturnType,
421
+ pathParamsType: options.pathParamsType,
422
+ mutationKeyName: mutationKey.name
423
+ }
424
+ )
425
+ ] });
426
+ }
427
+ });
428
+ var infiniteQueryGenerator = createReactGenerator({
429
+ name: "react-infinite-query",
430
+ Operation({ options, operation }) {
431
+ const {
432
+ plugin: {
433
+ options: { output }
434
+ }
435
+ } = useApp();
436
+ const { getSchemas, getName, getFile } = useOperationManager();
437
+ const isQuery = typeof options.query === "boolean" ? options.query : !!options.query.methods?.some((method) => operation.method === method);
438
+ const isInfinite = isQuery && !!options.infinite;
439
+ const query = {
440
+ name: getName(operation, { type: "function", prefix: "use", suffix: "infinite" }),
441
+ typeName: getName(operation, { type: "type" }),
442
+ file: getFile(operation, { prefix: "use", suffix: "infinite" })
443
+ };
444
+ const client = {
445
+ name: getName(operation, { type: "function", pluginKey: [pluginClientName] })
446
+ };
447
+ const queryOptions = {
448
+ name: getName(operation, { type: "function", suffix: "InfiniteQueryOptions" })
449
+ };
450
+ const queryKey = {
451
+ name: getName(operation, { type: "const", suffix: "InfiniteQueryKey" }),
452
+ typeName: getName(operation, { type: "type", suffix: "InfiniteQueryKey" })
453
+ };
454
+ const type = {
455
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
456
+ //todo remove type?
457
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
458
+ };
459
+ const zod = {
460
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
461
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: "function" })
462
+ };
463
+ if (!isQuery || !isInfinite || typeof options.query === "boolean" || typeof options.infinite === "boolean") {
464
+ return null;
465
+ }
466
+ return /* @__PURE__ */ jsxs(File, { baseName: query.file.baseName, path: query.file.path, meta: query.file.meta, banner: output?.banner, footer: output?.footer, children: [
467
+ options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, { name: [zod.schemas.response.name], root: query.file.path, path: zod.file.path }),
468
+ /* @__PURE__ */ jsx(File.Import, { name: ["useInfiniteQuery", "infiniteQueryOptions"], path: options.query.importPath }),
469
+ /* @__PURE__ */ jsx(File.Import, { name: ["QueryKey", "WithRequired", "InfiniteQueryObserverOptions", "UseInfiniteQueryResult"], path: options.query.importPath, isTypeOnly: true }),
470
+ /* @__PURE__ */ jsx(File.Import, { name: "client", path: options.client.importPath }),
471
+ /* @__PURE__ */ jsx(File.Import, { name: ["RequestConfig"], path: options.client.importPath, isTypeOnly: true }),
472
+ options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, { name: ["ResponseConfig"], path: options.client.importPath, isTypeOnly: true }),
473
+ /* @__PURE__ */ jsx(
474
+ File.Import,
475
+ {
476
+ name: [
477
+ type.schemas.request?.name,
478
+ type.schemas.response.name,
479
+ type.schemas.pathParams?.name,
480
+ type.schemas.queryParams?.name,
481
+ type.schemas.headerParams?.name,
482
+ ...type.schemas.statusCodes?.map((item) => item.name) || []
483
+ ].filter(Boolean),
484
+ root: query.file.path,
485
+ path: type.file.path,
486
+ isTypeOnly: true
487
+ }
488
+ ),
489
+ /* @__PURE__ */ jsx(
490
+ QueryKey,
491
+ {
492
+ name: queryKey.name,
493
+ typeName: queryKey.typeName,
494
+ operation,
495
+ pathParamsType: options.pathParamsType,
496
+ typeSchemas: type.schemas,
497
+ keysFn: options.query.key
498
+ }
499
+ ),
500
+ /* @__PURE__ */ jsx(
501
+ Client,
502
+ {
503
+ name: client.name,
504
+ isExportable: false,
505
+ isIndexable: false,
506
+ baseURL: options.baseURL,
507
+ operation,
508
+ typeSchemas: type.schemas,
509
+ zodSchemas: zod.schemas,
510
+ dataReturnType: options.client.dataReturnType,
511
+ pathParamsType: options.pathParamsType,
512
+ parser: options.parser
513
+ }
514
+ ),
515
+ /* @__PURE__ */ jsx(
516
+ InfiniteQueryOptions,
517
+ {
518
+ name: queryOptions.name,
519
+ clientName: client.name,
520
+ queryKeyName: queryKey.name,
521
+ typeSchemas: type.schemas,
522
+ pathParamsType: options.pathParamsType,
523
+ dataReturnType: options.client.dataReturnType,
524
+ cursorParam: options.infinite.cursorParam,
525
+ initialPageParam: options.infinite.initialPageParam,
526
+ queryParam: options.infinite.queryParam
527
+ }
528
+ ),
529
+ /* @__PURE__ */ jsx(
530
+ InfiniteQuery,
531
+ {
532
+ name: query.name,
533
+ queryOptionsName: queryOptions.name,
534
+ typeSchemas: type.schemas,
535
+ pathParamsType: options.pathParamsType,
536
+ operation,
537
+ dataReturnType: options.client.dataReturnType,
538
+ queryKeyName: queryKey.name,
539
+ queryKeyTypeName: queryKey.typeName
540
+ }
541
+ )
542
+ ] });
543
+ }
544
+ });
545
+ var suspenseQueryGenerator = createReactGenerator({
546
+ name: "react-suspense-query",
547
+ Operation({ options, operation }) {
548
+ const {
549
+ plugin: {
550
+ options: { output }
551
+ }
552
+ } = useApp();
553
+ const { getSchemas, getName, getFile } = useOperationManager();
554
+ const isQuery = typeof options.query === "boolean" ? options.query : !!options.query.methods?.some((method) => operation.method === method);
555
+ const isSuspense = isQuery && !!options.suspense;
556
+ const query = {
557
+ name: getName(operation, { type: "function", prefix: "use", suffix: "suspense" }),
558
+ typeName: getName(operation, { type: "type" }),
559
+ file: getFile(operation, { prefix: "use", suffix: "suspense" })
560
+ };
561
+ const client = {
562
+ name: getName(operation, { type: "function", pluginKey: [pluginClientName] })
563
+ };
564
+ const queryOptions = {
565
+ name: getName(operation, { type: "function", suffix: "SuspenseQueryOptions" })
566
+ };
567
+ const queryKey = {
568
+ name: getName(operation, { type: "const", suffix: "SuspenseQueryKey" }),
569
+ typeName: getName(operation, { type: "type", suffix: "SuspenseQueryKey" })
570
+ };
571
+ const type = {
572
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
573
+ //todo remove type?
574
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
575
+ };
576
+ const zod = {
577
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
578
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: "function" })
579
+ };
580
+ if (!isQuery || !isSuspense || typeof options.query === "boolean") {
581
+ return null;
582
+ }
583
+ return /* @__PURE__ */ jsxs(File, { baseName: query.file.baseName, path: query.file.path, meta: query.file.meta, banner: output?.banner, footer: output?.footer, children: [
584
+ options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, { name: [zod.schemas.response.name], root: query.file.path, path: zod.file.path }),
585
+ /* @__PURE__ */ jsx(File.Import, { name: ["useSuspenseQuery", "queryOptions"], path: options.query.importPath }),
586
+ /* @__PURE__ */ jsx(File.Import, { name: ["QueryKey", "WithRequired", "UseSuspenseQueryOptions", "UseSuspenseQueryResult"], path: options.query.importPath, isTypeOnly: true }),
587
+ /* @__PURE__ */ jsx(File.Import, { name: "client", path: options.client.importPath }),
588
+ /* @__PURE__ */ jsx(File.Import, { name: ["RequestConfig"], path: options.client.importPath, isTypeOnly: true }),
589
+ options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, { name: ["ResponseConfig"], path: options.client.importPath, isTypeOnly: true }),
590
+ /* @__PURE__ */ jsx(
591
+ File.Import,
592
+ {
593
+ name: [
594
+ type.schemas.request?.name,
595
+ type.schemas.response.name,
596
+ type.schemas.pathParams?.name,
597
+ type.schemas.queryParams?.name,
598
+ type.schemas.headerParams?.name,
599
+ ...type.schemas.statusCodes?.map((item) => item.name) || []
600
+ ].filter(Boolean),
601
+ root: query.file.path,
602
+ path: type.file.path,
603
+ isTypeOnly: true
604
+ }
605
+ ),
606
+ /* @__PURE__ */ jsx(
607
+ QueryKey,
608
+ {
609
+ name: queryKey.name,
610
+ typeName: queryKey.typeName,
611
+ operation,
612
+ pathParamsType: options.pathParamsType,
613
+ typeSchemas: type.schemas,
614
+ keysFn: options.query.key
615
+ }
616
+ ),
617
+ /* @__PURE__ */ jsx(
618
+ Client,
619
+ {
620
+ name: client.name,
621
+ isExportable: false,
622
+ isIndexable: false,
623
+ baseURL: options.baseURL,
624
+ operation,
625
+ typeSchemas: type.schemas,
626
+ zodSchemas: zod.schemas,
627
+ dataReturnType: options.client.dataReturnType,
628
+ pathParamsType: options.pathParamsType,
629
+ parser: options.parser
630
+ }
631
+ ),
632
+ /* @__PURE__ */ jsx(
633
+ QueryOptions,
634
+ {
635
+ name: queryOptions.name,
636
+ clientName: client.name,
637
+ queryKeyName: queryKey.name,
638
+ typeSchemas: type.schemas,
639
+ pathParamsType: options.pathParamsType
640
+ }
641
+ ),
642
+ /* @__PURE__ */ jsx(
643
+ SuspenseQuery,
644
+ {
645
+ name: query.name,
646
+ queryOptionsName: queryOptions.name,
647
+ typeSchemas: type.schemas,
648
+ pathParamsType: options.pathParamsType,
649
+ operation,
650
+ dataReturnType: options.client.dataReturnType,
651
+ queryKeyName: queryKey.name,
652
+ queryKeyTypeName: queryKey.typeName
653
+ }
654
+ )
655
+ ] });
656
+ }
657
+ });
658
+
659
+ export { infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseQueryGenerator };
660
+ //# sourceMappingURL=chunk-J7NSRJSY.js.map
661
+ //# sourceMappingURL=chunk-J7NSRJSY.js.map