@kubb/plugin-react-query 0.0.0-canary-20241104172400

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