@kubb/plugin-react-query 3.0.0-alpha.14 → 3.0.0-alpha.16

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 (73) hide show
  1. package/dist/chunk-ESENIDWJ.js +608 -0
  2. package/dist/chunk-ESENIDWJ.js.map +1 -0
  3. package/dist/chunk-JQEH3UHY.cjs +618 -0
  4. package/dist/chunk-JQEH3UHY.cjs.map +1 -0
  5. package/dist/chunk-KRG2LWHM.cjs +606 -0
  6. package/dist/chunk-KRG2LWHM.cjs.map +1 -0
  7. package/dist/chunk-ME7ZFS5H.js +596 -0
  8. package/dist/chunk-ME7ZFS5H.js.map +1 -0
  9. package/dist/components.cjs +17 -5
  10. package/dist/components.d.cts +143 -5
  11. package/dist/components.d.ts +143 -5
  12. package/dist/components.js +1 -1
  13. package/dist/generators.cjs +25 -0
  14. package/dist/generators.cjs.map +1 -0
  15. package/dist/generators.d.cts +15 -0
  16. package/dist/generators.d.ts +15 -0
  17. package/dist/generators.js +4 -0
  18. package/dist/generators.js.map +1 -0
  19. package/dist/index.cjs +33 -76
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +2 -4
  22. package/dist/index.d.ts +2 -4
  23. package/dist/index.js +34 -77
  24. package/dist/index.js.map +1 -1
  25. package/dist/types-DJxL-JeY.d.cts +195 -0
  26. package/dist/types-DJxL-JeY.d.ts +195 -0
  27. package/package.json +23 -15
  28. package/src/components/InfiniteQuery.tsx +129 -0
  29. package/src/components/InfiniteQueryOptions.tsx +121 -0
  30. package/src/components/Mutation.tsx +112 -304
  31. package/src/components/Query.tsx +91 -593
  32. package/src/components/QueryKey.tsx +51 -182
  33. package/src/components/QueryOptions.tsx +64 -465
  34. package/src/components/SuspenseQuery.tsx +129 -0
  35. package/src/components/index.ts +3 -0
  36. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +64 -0
  37. package/src/generators/__snapshots__/clientGetImportPath.ts +64 -0
  38. package/src/generators/__snapshots__/clientPostImportPath.ts +59 -0
  39. package/src/generators/__snapshots__/findByTags.ts +64 -0
  40. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +64 -0
  41. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +64 -0
  42. package/src/generators/__snapshots__/findByTagsWithZod.ts +64 -0
  43. package/src/generators/__snapshots__/findInfiniteByTags.ts +74 -0
  44. package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +74 -0
  45. package/src/generators/__snapshots__/getAsMutation.ts +31 -0
  46. package/src/generators/__snapshots__/postAsQuery.ts +77 -0
  47. package/src/generators/__snapshots__/updatePetById.ts +59 -0
  48. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +63 -0
  49. package/src/generators/index.ts +4 -0
  50. package/src/generators/infiniteQueryGenerator.tsx +124 -0
  51. package/src/generators/mutationGenerator.tsx +94 -0
  52. package/src/generators/queryGenerator.tsx +121 -0
  53. package/src/generators/suspenseQueryGenerator.tsx +120 -0
  54. package/src/plugin.ts +38 -49
  55. package/src/types.ts +35 -59
  56. package/dist/chunk-AGLJPONA.cjs +0 -1423
  57. package/dist/chunk-AGLJPONA.cjs.map +0 -1
  58. package/dist/chunk-I7X4HNDR.js +0 -1413
  59. package/dist/chunk-I7X4HNDR.js.map +0 -1
  60. package/dist/index-BzoLlZve.d.cts +0 -537
  61. package/dist/index-BzoLlZve.d.ts +0 -537
  62. package/src/OperationGenerator.tsx +0 -57
  63. package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -69
  64. package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -62
  65. package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -68
  66. package/src/__snapshots__/queryOptions/getPetById.ts +0 -41
  67. package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -51
  68. package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -24
  69. package/src/components/QueryImports.tsx +0 -167
  70. package/src/components/SchemaType.tsx +0 -74
  71. package/src/components/__snapshots__/gen/showPetById.ts +0 -67
  72. package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
  73. package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -46
package/dist/index.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkAGLJPONA_cjs = require('./chunk-AGLJPONA.cjs');
3
+ var chunkKRG2LWHM_cjs = require('./chunk-KRG2LWHM.cjs');
4
+ require('./chunk-JQEH3UHY.cjs');
4
5
  var path = require('path');
5
6
  var core = require('@kubb/core');
6
7
  var transformers = require('@kubb/core/transformers');
@@ -8,51 +9,11 @@ var utils = require('@kubb/core/utils');
8
9
  var pluginOas = require('@kubb/plugin-oas');
9
10
  var pluginTs = require('@kubb/plugin-ts');
10
11
  var pluginZod = require('@kubb/plugin-zod');
11
- var components = require('@kubb/plugin-oas/components');
12
- var react = require('@kubb/react');
13
- var jsxRuntime = require('@kubb/react/jsx-runtime');
14
12
 
15
13
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
16
14
 
17
15
  var path__default = /*#__PURE__*/_interopDefault(path);
18
16
 
19
- var OperationGenerator = class extends pluginOas.OperationGenerator {
20
- async operation(operation, options) {
21
- const { oas, pluginManager, plugin, mode } = this.context;
22
- const root = react.createRoot({
23
- logger: pluginManager.logger
24
- });
25
- const templates = {
26
- mutation: chunkAGLJPONA_cjs.Mutation.templates,
27
- query: chunkAGLJPONA_cjs.Query.templates,
28
- queryOptions: chunkAGLJPONA_cjs.QueryOptions.templates,
29
- queryKey: chunkAGLJPONA_cjs.QueryKey.templates,
30
- queryImports: chunkAGLJPONA_cjs.QueryImports.templates,
31
- ...options.templates
32
- };
33
- const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
34
- const isMutate = !isQuery && options.mutate && options.mutate.methods.some((method) => operation.method === method);
35
- root.render(
36
- /* @__PURE__ */ jsxRuntime.jsx(react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsxRuntime.jsxs(components.Oas.Operation, { operation, children: [
37
- isMutate && templates?.mutation && /* @__PURE__ */ jsxRuntime.jsx(chunkAGLJPONA_cjs.Mutation.File, { templates: templates.mutation }),
38
- isQuery && templates?.query && templates.queryKey && templates.queryOptions && templates.queryImports && /* @__PURE__ */ jsxRuntime.jsx(
39
- chunkAGLJPONA_cjs.Query.File,
40
- {
41
- templates: {
42
- query: templates.query,
43
- queryKey: templates.queryKey,
44
- queryOptions: templates.queryOptions,
45
- queryImports: templates.queryImports
46
- }
47
- }
48
- )
49
- ] }) }) })
50
- );
51
- return root.files;
52
- }
53
- };
54
-
55
- // src/plugin.ts
56
17
  var pluginReactQueryName = "plugin-react-query";
57
18
  var pluginReactQuery = core.createPlugin((options) => {
58
19
  const {
@@ -61,16 +22,13 @@ var pluginReactQuery = core.createPlugin((options) => {
61
22
  exclude = [],
62
23
  include,
63
24
  override = [],
64
- parser,
25
+ parser = "client",
65
26
  suspense = {},
66
27
  infinite,
67
28
  transformers: transformers$1 = {},
68
- dataReturnType = "data",
69
29
  pathParamsType = "inline",
70
- mutate = {},
71
- query = {},
72
- queryOptions = {},
73
- templates
30
+ mutation = {},
31
+ query = {}
74
32
  } = options;
75
33
  const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
76
34
  return {
@@ -80,12 +38,13 @@ var pluginReactQuery = core.createPlugin((options) => {
80
38
  ...output
81
39
  },
82
40
  options: {
41
+ baseURL: void 0,
83
42
  client: {
84
43
  importPath: "@kubb/plugin-client/client",
44
+ dataReturnType: "data",
45
+ pathParamsType: "inline",
85
46
  ...options.client
86
47
  },
87
- dataReturnType,
88
- pathParamsType,
89
48
  infinite: infinite ? {
90
49
  queryParam: "id",
91
50
  initialPageParam: 0,
@@ -93,26 +52,18 @@ var pluginReactQuery = core.createPlugin((options) => {
93
52
  ...infinite
94
53
  } : false,
95
54
  suspense,
96
- query: query ? {
97
- queryKey: (key) => key,
55
+ query: {
56
+ key: (key) => key,
98
57
  methods: ["get"],
99
58
  importPath: "@tanstack/react-query",
100
59
  ...query
101
- } : false,
102
- queryOptions,
103
- mutate: mutate ? {
104
- variablesType: "hook",
60
+ },
61
+ mutation: {
105
62
  methods: ["post", "put", "patch", "delete"],
106
- ...mutate
107
- } : false,
108
- templates: {
109
- mutation: chunkAGLJPONA_cjs.Mutation.templates,
110
- query: chunkAGLJPONA_cjs.Query.templates,
111
- queryOptions: chunkAGLJPONA_cjs.QueryOptions.templates,
112
- queryKey: chunkAGLJPONA_cjs.QueryKey.templates,
113
- queryImports: chunkAGLJPONA_cjs.QueryImports.templates,
114
- ...templates
63
+ importPath: "@tanstack/react-query",
64
+ ...mutation
115
65
  },
66
+ pathParamsType,
116
67
  parser
117
68
  },
118
69
  pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, parser === "zod" ? pluginZod.pluginZodName : void 0].filter(Boolean),
@@ -132,7 +83,6 @@ var pluginReactQuery = core.createPlugin((options) => {
132
83
  let resolvedName = transformers.camelCase(name);
133
84
  if (type === "file" || type === "function") {
134
85
  resolvedName = transformers.camelCase(name, {
135
- prefix: "use",
136
86
  isFile: type === "file"
137
87
  });
138
88
  }
@@ -149,17 +99,24 @@ var pluginReactQuery = core.createPlugin((options) => {
149
99
  const oas = await swaggerPlugin.context.getOas();
150
100
  const root = path__default.default.resolve(this.config.root, this.config.output.path);
151
101
  const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
152
- const operationGenerator = new OperationGenerator(this.plugin.options, {
153
- oas,
154
- pluginManager: this.pluginManager,
155
- plugin: this.plugin,
156
- contentType: swaggerPlugin.context.contentType,
157
- exclude,
158
- include,
159
- override,
160
- mode
161
- });
162
- const files = await operationGenerator.build();
102
+ const baseURL = await swaggerPlugin.context.getBaseURL();
103
+ const operationGenerator = new pluginOas.OperationGenerator(
104
+ {
105
+ ...this.plugin.options,
106
+ baseURL
107
+ },
108
+ {
109
+ oas,
110
+ pluginManager: this.pluginManager,
111
+ plugin: this.plugin,
112
+ contentType: swaggerPlugin.context.contentType,
113
+ exclude,
114
+ include,
115
+ override,
116
+ mode
117
+ }
118
+ );
119
+ const files = await operationGenerator.build(chunkKRG2LWHM_cjs.queryGenerator, chunkKRG2LWHM_cjs.suspenseQueryGenerator, chunkKRG2LWHM_cjs.infiniteQueryGenerator, chunkKRG2LWHM_cjs.mutationGenerator);
163
120
  await this.addFile(...files);
164
121
  if (this.config.output.exportType) {
165
122
  const barrelFiles = await this.fileManager.getBarrelFiles({
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/OperationGenerator.tsx","../src/plugin.ts"],"names":["Generator","createRoot","Mutation","Query","QueryOptions","QueryKey","QueryImports","jsx","App","Oas","jsxs","createPlugin","transformers","pluginOasName","pluginTsName","pluginZodName","options","path","FileManager","camelCase","renderTemplate","pascalCase","PluginManager"],"mappings":";;;;;;;;;;;;;;;;;;AAcO,IAAM,kBAAA,GAAN,cAAiCA,4BAA2E,CAAA;AAAA,EACjH,MAAM,SAAU,CAAA,SAAA,EAAsB,OAA+E,EAAA;AACnH,IAAA,MAAM,EAAE,GAAK,EAAA,aAAA,EAAe,MAAQ,EAAA,IAAA,KAAS,IAAK,CAAA,OAAA,CAAA;AAElD,IAAA,MAAM,OAAOC,gBAAW,CAAA;AAAA,MACtB,QAAQ,aAAc,CAAA,MAAA;AAAA,KACvB,CAAA,CAAA;AAED,IAAA,MAAM,SAAY,GAAA;AAAA,MAChB,UAAUC,0BAAS,CAAA,SAAA;AAAA,MACnB,OAAOC,uBAAM,CAAA,SAAA;AAAA,MACb,cAAcC,8BAAa,CAAA,SAAA;AAAA,MAC3B,UAAUC,0BAAS,CAAA,SAAA;AAAA,MACnB,cAAcC,8BAAa,CAAA,SAAA;AAAA,MAC3B,GAAG,OAAQ,CAAA,SAAA;AAAA,KACb,CAAA;AAEA,IAAA,MAAM,OAAU,GAAA,OAAO,OAAQ,CAAA,KAAA,KAAU,YAAY,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IAAA,CAAK,MAAO,CAAA,MAAA,CAAO,IAAI,CAAA,CAAA;AACnE,MAAM,MAAA,IAAA,GAAOC,iBAAY,OAAQ,CAAAD,qBAAA,CAAK,QAAQ,IAAM,EAAA,MAAA,CAAO,IAAI,CAAC,CAAA,CAAA;AAEhE,MAAA,MAAM,kBAAqB,GAAA,IAAI,kBAAmB,CAAA,IAAA,CAAK,OAAO,OAAS,EAAA;AAAA,QACrE,GAAA;AAAA,QACA,eAAe,IAAK,CAAA,aAAA;AAAA,QACpB,QAAQ,IAAK,CAAA,MAAA;AAAA,QACb,WAAA,EAAa,cAAc,OAAQ,CAAA,WAAA;AAAA,QACnC,OAAA;AAAA,QACA,OAAA;AAAA,QACA,QAAA;AAAA,QACA,IAAA;AAAA,OACD,CAAA,CAAA;AAED,MAAM,MAAA,KAAA,GAAQ,MAAM,kBAAA,CAAmB,KAAM,EAAA,CAAA;AAC7C,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,CAAA,CAAA;AAE3B,MAAI,IAAA,IAAA,CAAK,MAAO,CAAA,MAAA,CAAO,UAAY,EAAA;AACjC,QAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,UACxD,IAAA;AAAA,UACA,MAAA;AAAA,UACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,UACxB,IAAM,EAAA;AAAA,YACJ,SAAA,EAAW,KAAK,MAAO,CAAA,GAAA;AAAA,WACzB;AAAA,UACA,QAAQ,IAAK,CAAA,MAAA;AAAA,SACd,CAAA,CAAA;AAED,QAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA,CAAA;AAAA,OACnC;AAAA,KACF;AAAA,GACF,CAAA;AACF,CAAC","file":"index.cjs","sourcesContent":["import { OperationGenerator as Generator } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { App, createRoot } from '@kubb/react'\n\nimport { Mutation } from './components/Mutation.tsx'\nimport { Query } from './components/Query.tsx'\nimport { QueryKey } from './components/QueryKey.tsx'\nimport { QueryOptions } from './components/QueryOptions.tsx'\n\nimport type { Operation } from '@kubb/oas'\nimport type { OperationMethodResult } from '@kubb/plugin-oas'\nimport { QueryImports } from './components/QueryImports.tsx'\nimport type { FileMeta, PluginReactQuery } from './types.ts'\n\nexport class OperationGenerator extends Generator<PluginReactQuery['resolvedOptions'], PluginReactQuery, FileMeta> {\n async operation(operation: Operation, options: PluginReactQuery['resolvedOptions']): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const templates = {\n mutation: Mutation.templates,\n query: Query.templates,\n queryOptions: QueryOptions.templates,\n queryKey: QueryKey.templates,\n queryImports: QueryImports.templates,\n ...options.templates,\n }\n\n const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)\n const isMutate = !isQuery && options.mutate && options.mutate.methods.some((method) => operation.method === method)\n\n root.render(\n <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>\n <Oas oas={oas} operations={[operation]} generator={this}>\n <Oas.Operation operation={operation}>\n {isMutate && templates?.mutation && <Mutation.File templates={templates.mutation} />}\n {isQuery && templates?.query && templates.queryKey && templates.queryOptions && templates.queryImports && (\n <Query.File\n templates={{\n query: templates.query,\n queryKey: templates.queryKey,\n queryOptions: templates.queryOptions,\n queryImports: templates.queryImports,\n }}\n />\n )}\n </Oas.Operation>\n </Oas>\n </App>,\n )\n\n return root.files\n }\n}\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport { OperationGenerator } from './OperationGenerator.tsx'\nimport { Mutation, Query, QueryKey, QueryOptions } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { QueryImports } from './components/QueryImports.tsx'\nimport type { PluginReactQuery } from './types.ts'\n\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\nexport const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks' },\n group,\n exclude = [],\n include,\n override = [],\n parser,\n suspense = {},\n infinite,\n transformers = {},\n dataReturnType = 'data',\n pathParamsType = 'inline',\n mutate = {},\n query = {},\n queryOptions = {},\n templates,\n } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginReactQueryName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {\n client: {\n importPath: '@kubb/plugin-client/client',\n ...options.client,\n },\n dataReturnType,\n pathParamsType,\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: undefined,\n ...infinite,\n }\n : false,\n suspense,\n query: query\n ? {\n queryKey: (key: unknown[]) => key,\n methods: ['get'],\n importPath: '@tanstack/react-query',\n ...query,\n }\n : false,\n queryOptions,\n mutate: mutate\n ? {\n variablesType: 'hook',\n methods: ['post', 'put', 'patch', 'delete'],\n ...mutate,\n }\n : false,\n templates: {\n mutation: Mutation.templates,\n query: Query.templates,\n queryOptions: QueryOptions.templates,\n queryKey: QueryKey.templates,\n queryImports: QueryImports.templates,\n ...templates,\n },\n parser,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n prefix: 'use',\n isFile: type === 'file',\n })\n }\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build()\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n"]}
1
+ {"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","pluginOasName","pluginTsName","pluginZodName","options","path","FileManager","camelCase","renderTemplate","pascalCase","PluginManager","OperationGenerator","queryGenerator","suspenseQueryGenerator","infiniteQueryGenerator","mutationGenerator"],"mappings":";;;;;;;;;;;;;;;;AAeO,IAAM,oBAAuB,GAAA,qBAAA;AAEvB,IAAA,gBAAA,GAAmBA,iBAA+B,CAAA,CAAC,OAAY,KAAA;AAC1E,EAAM,MAAA;AAAA,IACJ,MAAA,GAAS,EAAE,IAAA,EAAM,OAAQ,EAAA;AAAA,IACzB,KAAA;AAAA,IACA,UAAU,EAAC;AA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AA,UACnC,OAAA;AAAA,UACA,OAAA;AAAA,UACA,QAAA;AAAA,UACA,IAAA;AAAA,SACF;AAAA,OACF,CAAA;AAEA,MAAA,MAAM,QAAQ,MAAM,kBAAA,CAAmB,MAAMC,gCAAgB,EAAAC,wCAAA,EAAwBC,0CAAwBC,mCAAiB,CAAA,CAAA;AAC9H,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,CAAA,CAAA;AAE3B,MAAI,IAAA,IAAA,CAAK,MAAO,CAAA,MAAA,CAAO,UAAY,EAAA;AACjC,QAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,UACxD,IAAA;AAAA,UACA,MAAA;AAAA,UACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,UACxB,IAAM,EAAA;AAAA,YACJ,SAAA,EAAW,KAAK,MAAO,CAAA,GAAA;AAAA,WACzB;AAAA,UACA,QAAQ,IAAK,CAAA,MAAA;AAAA,SACd,CAAA,CAAA;AAED,QAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA,CAAA;AAAA,OACnC;AAAA,KACF;AAAA,GACF,CAAA;AACF,CAAC","file":"index.cjs","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseQueryGenerator } from './generators'\nimport type { PluginReactQuery } from './types.ts'\n\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\nexport const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite,\n transformers = {},\n pathParamsType = 'inline',\n mutation = {},\n query = {},\n } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginReactQueryName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {\n baseURL: undefined,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\n pathParamsType: 'inline',\n ...options.client,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: undefined,\n ...infinite,\n }\n : false,\n suspense,\n query: {\n key: (key: unknown[]) => key,\n methods: ['get'],\n importPath: '@tanstack/react-query',\n ...query,\n },\n mutation: {\n methods: ['post', 'put', 'patch', 'delete'],\n importPath: '@tanstack/react-query',\n ...mutation,\n },\n pathParamsType,\n parser,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n const baseURL = await swaggerPlugin.context.getBaseURL()\n\n const operationGenerator = new OperationGenerator(\n {\n ...this.plugin.options,\n baseURL,\n },\n {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n },\n )\n\n const files = await operationGenerator.build(queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator)\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n"]}
package/dist/index.d.cts CHANGED
@@ -1,9 +1,7 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginReactQuery } from './index-BzoLlZve.cjs';
3
- import '@kubb/core/utils';
4
- import '@kubb/oas';
5
- import 'react';
2
+ import { O as Options, P as PluginReactQuery } from './types-DJxL-JeY.cjs';
6
3
  import '@kubb/fs/types';
4
+ import '@kubb/oas';
7
5
  import '@kubb/plugin-oas';
8
6
 
9
7
  declare const pluginReactQueryName = "plugin-react-query";
package/dist/index.d.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginReactQuery } from './index-BzoLlZve.js';
3
- import '@kubb/core/utils';
4
- import '@kubb/oas';
5
- import 'react';
2
+ import { O as Options, P as PluginReactQuery } from './types-DJxL-JeY.js';
6
3
  import '@kubb/fs/types';
4
+ import '@kubb/oas';
7
5
  import '@kubb/plugin-oas';
8
6
 
9
7
  declare const pluginReactQueryName = "plugin-react-query";
package/dist/index.js CHANGED
@@ -1,52 +1,13 @@
1
- import { Mutation, Query, QueryOptions, QueryKey, QueryImports } from './chunk-I7X4HNDR.js';
1
+ import { queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator } from './chunk-ME7ZFS5H.js';
2
+ import './chunk-ESENIDWJ.js';
2
3
  import path from 'node:path';
3
4
  import { createPlugin, FileManager, PluginManager } from '@kubb/core';
4
5
  import { camelCase, pascalCase } from '@kubb/core/transformers';
5
6
  import { renderTemplate } from '@kubb/core/utils';
6
- import { pluginOasName, OperationGenerator as OperationGenerator$1 } from '@kubb/plugin-oas';
7
+ import { pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
7
8
  import { pluginTsName } from '@kubb/plugin-ts';
8
9
  import { pluginZodName } from '@kubb/plugin-zod';
9
- import { Oas } from '@kubb/plugin-oas/components';
10
- import { createRoot, App } from '@kubb/react';
11
- import { jsx, jsxs } from '@kubb/react/jsx-runtime';
12
10
 
13
- var OperationGenerator = class extends OperationGenerator$1 {
14
- async operation(operation, options) {
15
- const { oas, pluginManager, plugin, mode } = this.context;
16
- const root = createRoot({
17
- logger: pluginManager.logger
18
- });
19
- const templates = {
20
- mutation: Mutation.templates,
21
- query: Query.templates,
22
- queryOptions: QueryOptions.templates,
23
- queryKey: QueryKey.templates,
24
- queryImports: QueryImports.templates,
25
- ...options.templates
26
- };
27
- const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
28
- const isMutate = !isQuery && options.mutate && options.mutate.methods.some((method) => operation.method === method);
29
- root.render(
30
- /* @__PURE__ */ jsx(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx(Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsxs(Oas.Operation, { operation, children: [
31
- isMutate && templates?.mutation && /* @__PURE__ */ jsx(Mutation.File, { templates: templates.mutation }),
32
- isQuery && templates?.query && templates.queryKey && templates.queryOptions && templates.queryImports && /* @__PURE__ */ jsx(
33
- Query.File,
34
- {
35
- templates: {
36
- query: templates.query,
37
- queryKey: templates.queryKey,
38
- queryOptions: templates.queryOptions,
39
- queryImports: templates.queryImports
40
- }
41
- }
42
- )
43
- ] }) }) })
44
- );
45
- return root.files;
46
- }
47
- };
48
-
49
- // src/plugin.ts
50
11
  var pluginReactQueryName = "plugin-react-query";
51
12
  var pluginReactQuery = createPlugin((options) => {
52
13
  const {
@@ -55,16 +16,13 @@ var pluginReactQuery = createPlugin((options) => {
55
16
  exclude = [],
56
17
  include,
57
18
  override = [],
58
- parser,
19
+ parser = "client",
59
20
  suspense = {},
60
21
  infinite,
61
22
  transformers = {},
62
- dataReturnType = "data",
63
23
  pathParamsType = "inline",
64
- mutate = {},
65
- query = {},
66
- queryOptions = {},
67
- templates
24
+ mutation = {},
25
+ query = {}
68
26
  } = options;
69
27
  const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
70
28
  return {
@@ -74,12 +32,13 @@ var pluginReactQuery = createPlugin((options) => {
74
32
  ...output
75
33
  },
76
34
  options: {
35
+ baseURL: void 0,
77
36
  client: {
78
37
  importPath: "@kubb/plugin-client/client",
38
+ dataReturnType: "data",
39
+ pathParamsType: "inline",
79
40
  ...options.client
80
41
  },
81
- dataReturnType,
82
- pathParamsType,
83
42
  infinite: infinite ? {
84
43
  queryParam: "id",
85
44
  initialPageParam: 0,
@@ -87,26 +46,18 @@ var pluginReactQuery = createPlugin((options) => {
87
46
  ...infinite
88
47
  } : false,
89
48
  suspense,
90
- query: query ? {
91
- queryKey: (key) => key,
49
+ query: {
50
+ key: (key) => key,
92
51
  methods: ["get"],
93
52
  importPath: "@tanstack/react-query",
94
53
  ...query
95
- } : false,
96
- queryOptions,
97
- mutate: mutate ? {
98
- variablesType: "hook",
54
+ },
55
+ mutation: {
99
56
  methods: ["post", "put", "patch", "delete"],
100
- ...mutate
101
- } : false,
102
- templates: {
103
- mutation: Mutation.templates,
104
- query: Query.templates,
105
- queryOptions: QueryOptions.templates,
106
- queryKey: QueryKey.templates,
107
- queryImports: QueryImports.templates,
108
- ...templates
57
+ importPath: "@tanstack/react-query",
58
+ ...mutation
109
59
  },
60
+ pathParamsType,
110
61
  parser
111
62
  },
112
63
  pre: [pluginOasName, pluginTsName, parser === "zod" ? pluginZodName : void 0].filter(Boolean),
@@ -126,7 +77,6 @@ var pluginReactQuery = createPlugin((options) => {
126
77
  let resolvedName = camelCase(name);
127
78
  if (type === "file" || type === "function") {
128
79
  resolvedName = camelCase(name, {
129
- prefix: "use",
130
80
  isFile: type === "file"
131
81
  });
132
82
  }
@@ -143,17 +93,24 @@ var pluginReactQuery = createPlugin((options) => {
143
93
  const oas = await swaggerPlugin.context.getOas();
144
94
  const root = path.resolve(this.config.root, this.config.output.path);
145
95
  const mode = FileManager.getMode(path.resolve(root, output.path));
146
- const operationGenerator = new OperationGenerator(this.plugin.options, {
147
- oas,
148
- pluginManager: this.pluginManager,
149
- plugin: this.plugin,
150
- contentType: swaggerPlugin.context.contentType,
151
- exclude,
152
- include,
153
- override,
154
- mode
155
- });
156
- const files = await operationGenerator.build();
96
+ const baseURL = await swaggerPlugin.context.getBaseURL();
97
+ const operationGenerator = new OperationGenerator(
98
+ {
99
+ ...this.plugin.options,
100
+ baseURL
101
+ },
102
+ {
103
+ oas,
104
+ pluginManager: this.pluginManager,
105
+ plugin: this.plugin,
106
+ contentType: swaggerPlugin.context.contentType,
107
+ exclude,
108
+ include,
109
+ override,
110
+ mode
111
+ }
112
+ );
113
+ const files = await operationGenerator.build(queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator);
157
114
  await this.addFile(...files);
158
115
  if (this.config.output.exportType) {
159
116
  const barrelFiles = await this.fileManager.getBarrelFiles({
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/OperationGenerator.tsx","../src/plugin.ts"],"names":["Generator","options"],"mappings":";;;;;;;;;;;;AAcO,IAAM,kBAAA,GAAN,cAAiCA,oBAA2E,CAAA;AAAA,EACjH,MAAM,SAAU,CAAA,SAAA,EAAsB,OAA+E,EAAA;AACnH,IAAA,MAAM,EAAE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AAAA,UACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,UACxB,IAAM,EAAA;AAAA,YACJ,SAAA,EAAW,KAAK,MAAO,CAAA,GAAA;AAAA,WACzB;AAAA,UACA,QAAQ,IAAK,CAAA,MAAA;AAAA,SACd,CAAA,CAAA;AAED,QAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA,CAAA;AAAA,OACnC;AAAA,KACF;AAAA,GACF,CAAA;AACF,CAAC","file":"index.js","sourcesContent":["import { OperationGenerator as Generator } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { App, createRoot } from '@kubb/react'\n\nimport { Mutation } from './components/Mutation.tsx'\nimport { Query } from './components/Query.tsx'\nimport { QueryKey } from './components/QueryKey.tsx'\nimport { QueryOptions } from './components/QueryOptions.tsx'\n\nimport type { Operation } from '@kubb/oas'\nimport type { OperationMethodResult } from '@kubb/plugin-oas'\nimport { QueryImports } from './components/QueryImports.tsx'\nimport type { FileMeta, PluginReactQuery } from './types.ts'\n\nexport class OperationGenerator extends Generator<PluginReactQuery['resolvedOptions'], PluginReactQuery, FileMeta> {\n async operation(operation: Operation, options: PluginReactQuery['resolvedOptions']): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const templates = {\n mutation: Mutation.templates,\n query: Query.templates,\n queryOptions: QueryOptions.templates,\n queryKey: QueryKey.templates,\n queryImports: QueryImports.templates,\n ...options.templates,\n }\n\n const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)\n const isMutate = !isQuery && options.mutate && options.mutate.methods.some((method) => operation.method === method)\n\n root.render(\n <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>\n <Oas oas={oas} operations={[operation]} generator={this}>\n <Oas.Operation operation={operation}>\n {isMutate && templates?.mutation && <Mutation.File templates={templates.mutation} />}\n {isQuery && templates?.query && templates.queryKey && templates.queryOptions && templates.queryImports && (\n <Query.File\n templates={{\n query: templates.query,\n queryKey: templates.queryKey,\n queryOptions: templates.queryOptions,\n queryImports: templates.queryImports,\n }}\n />\n )}\n </Oas.Operation>\n </Oas>\n </App>,\n )\n\n return root.files\n }\n}\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport { OperationGenerator } from './OperationGenerator.tsx'\nimport { Mutation, Query, QueryKey, QueryOptions } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { QueryImports } from './components/QueryImports.tsx'\nimport type { PluginReactQuery } from './types.ts'\n\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\nexport const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks' },\n group,\n exclude = [],\n include,\n override = [],\n parser,\n suspense = {},\n infinite,\n transformers = {},\n dataReturnType = 'data',\n pathParamsType = 'inline',\n mutate = {},\n query = {},\n queryOptions = {},\n templates,\n } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginReactQueryName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {\n client: {\n importPath: '@kubb/plugin-client/client',\n ...options.client,\n },\n dataReturnType,\n pathParamsType,\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: undefined,\n ...infinite,\n }\n : false,\n suspense,\n query: query\n ? {\n queryKey: (key: unknown[]) => key,\n methods: ['get'],\n importPath: '@tanstack/react-query',\n ...query,\n }\n : false,\n queryOptions,\n mutate: mutate\n ? {\n variablesType: 'hook',\n methods: ['post', 'put', 'patch', 'delete'],\n ...mutate,\n }\n : false,\n templates: {\n mutation: Mutation.templates,\n query: Query.templates,\n queryOptions: QueryOptions.templates,\n queryKey: QueryKey.templates,\n queryImports: QueryImports.templates,\n ...templates,\n },\n parser,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n prefix: 'use',\n isFile: type === 'file',\n })\n }\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build()\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n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I,kBAAA;AAAA,QAC7B;AAAA,UACE,GAAG,KAAK,MAAO,CAAA,OAAA;AAAA,UACf,OAAA;AAAA,SACF;AAAA,QACA;AAAA,UACE,GAAA;AAAA,UACA,eAAe,IAAK,CAAA,aAAA;AAAA,UACpB,QAAQ,IAAK,CAAA,MAAA;AAAA,UACb,WAAA,EAAa,cAAc,OAAQ,CAAA,WAAA;AAAA,UACnC,OAAA;AAAA,UACA,OAAA;AAAA,UACA,QAAA;AAAA,UACA,IAAA;AAAA,SACF;AAAA,OACF,CAAA;AAEA,MAAA,MAAM,QAAQ,MAAM,kBAAA,CAAmB,MAAM,cAAgB,EAAA,sBAAA,EAAwB,wBAAwB,iBAAiB,CAAA,CAAA;AAC9H,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,CAAA,CAAA;AAE3B,MAAI,IAAA,IAAA,CAAK,MAAO,CAAA,MAAA,CAAO,UAAY,EAAA;AACjC,QAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,UACxD,IAAA;AAAA,UACA,MAAA;AAAA,UACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,UACxB,IAAM,EAAA;AAAA,YACJ,SAAA,EAAW,KAAK,MAAO,CAAA,GAAA;AAAA,WACzB;AAAA,UACA,QAAQ,IAAK,CAAA,MAAA;AAAA,SACd,CAAA,CAAA;AAED,QAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA,CAAA;AAAA,OACnC;AAAA,KACF;AAAA,GACF,CAAA;AACF,CAAC","file":"index.js","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas } from '@kubb/plugin-oas'\nimport { infiniteQueryGenerator, mutationGenerator, queryGenerator, suspenseQueryGenerator } from './generators'\nimport type { PluginReactQuery } from './types.ts'\n\nexport const pluginReactQueryName = 'plugin-react-query' satisfies PluginReactQuery['name']\n\nexport const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {\n const {\n output = { path: 'hooks' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite,\n transformers = {},\n pathParamsType = 'inline',\n mutation = {},\n query = {},\n } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginReactQueryName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {\n baseURL: undefined,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\n pathParamsType: 'inline',\n ...options.client,\n },\n infinite: infinite\n ? {\n queryParam: 'id',\n initialPageParam: 0,\n cursorParam: undefined,\n ...infinite,\n }\n : false,\n suspense,\n query: {\n key: (key: unknown[]) => key,\n methods: ['get'],\n importPath: '@tanstack/react-query',\n ...query,\n },\n mutation: {\n methods: ['post', 'put', 'patch', 'delete'],\n importPath: '@tanstack/react-query',\n ...mutation,\n },\n pathParamsType,\n parser,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<PluginOas>] = PluginManager.getDependedPlugins<PluginOas>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n const baseURL = await swaggerPlugin.context.getBaseURL()\n\n const operationGenerator = new OperationGenerator(\n {\n ...this.plugin.options,\n baseURL,\n },\n {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n },\n )\n\n const files = await operationGenerator.build(queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator)\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n"]}