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