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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-2D27Y6L5.js +618 -0
  3. package/dist/chunk-2D27Y6L5.js.map +1 -0
  4. package/dist/chunk-C2H3KPHM.cjs +658 -0
  5. package/dist/chunk-C2H3KPHM.cjs.map +1 -0
  6. package/dist/chunk-JW3GZUSC.cjs +627 -0
  7. package/dist/chunk-JW3GZUSC.cjs.map +1 -0
  8. package/dist/chunk-Y3DM2P6L.js +647 -0
  9. package/dist/chunk-Y3DM2P6L.js.map +1 -0
  10. package/dist/components.cjs +39 -14
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +161 -7
  13. package/dist/components.d.ts +161 -7
  14. package/dist/components.js +2 -14
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +25 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +14 -0
  19. package/dist/generators.d.ts +14 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +75 -154
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +1 -5
  25. package/dist/index.d.ts +1 -5
  26. package/dist/index.js +54 -140
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-rJasmoxy.d.cts +187 -0
  29. package/dist/types-rJasmoxy.d.ts +187 -0
  30. package/package.json +22 -17
  31. package/src/components/InfiniteQuery.tsx +129 -0
  32. package/src/components/InfiniteQueryOptions.tsx +130 -0
  33. package/src/components/Mutation.tsx +138 -322
  34. package/src/components/MutationKey.tsx +48 -0
  35. package/src/components/Query.tsx +91 -598
  36. package/src/components/QueryKey.tsx +51 -178
  37. package/src/components/QueryOptions.tsx +72 -466
  38. package/src/components/SuspenseQuery.tsx +129 -0
  39. package/src/components/index.ts +4 -1
  40. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +51 -0
  41. package/src/generators/__snapshots__/clientGetImportPath.ts +51 -0
  42. package/src/generators/__snapshots__/clientPostImportPath.ts +44 -0
  43. package/src/generators/__snapshots__/findByTags.ts +51 -0
  44. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +51 -0
  45. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +51 -0
  46. package/src/generators/__snapshots__/findByTagsWithZod.ts +51 -0
  47. package/src/generators/__snapshots__/findInfiniteByTags.ts +57 -0
  48. package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +57 -0
  49. package/src/generators/__snapshots__/getAsMutation.ts +31 -0
  50. package/src/generators/__snapshots__/postAsQuery.ts +50 -0
  51. package/src/generators/__snapshots__/updatePetById.ts +44 -0
  52. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +46 -0
  53. package/src/generators/index.ts +4 -0
  54. package/src/generators/infiniteQueryGenerator.tsx +124 -0
  55. package/src/generators/mutationGenerator.tsx +108 -0
  56. package/src/generators/queryGenerator.tsx +121 -0
  57. package/src/generators/suspenseQueryGenerator.tsx +120 -0
  58. package/src/plugin.ts +51 -75
  59. package/src/types.ts +49 -88
  60. package/dist/chunk-5IL6M74X.js +0 -1504
  61. package/dist/chunk-5IL6M74X.js.map +0 -1
  62. package/dist/chunk-JFX7DCS7.cjs +0 -1504
  63. package/dist/chunk-JFX7DCS7.cjs.map +0 -1
  64. package/dist/index-C9fwRDH7.d.cts +0 -579
  65. package/dist/index-C9fwRDH7.d.ts +0 -579
  66. package/src/OperationGenerator.tsx +0 -86
  67. package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -64
  68. package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -57
  69. package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -63
  70. package/src/__snapshots__/queryOptions/getPetById.ts +0 -37
  71. package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -47
  72. package/src/__snapshots__/upload/UploadFile.ts +0 -67
  73. package/src/__snapshots__/uploadMutation/UploadFile.ts +0 -44
  74. package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -21
  75. package/src/components/Operations.tsx +0 -74
  76. package/src/components/QueryImports.tsx +0 -167
  77. package/src/components/SchemaType.tsx +0 -55
  78. package/src/components/__snapshots__/gen/showPetById.ts +0 -57
  79. package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
  80. package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -47
  81. package/src/utils.ts +0 -96
package/dist/index.cjs CHANGED
@@ -1,112 +1,48 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
1
+ 'use strict';
2
2
 
3
+ var chunkJW3GZUSC_cjs = require('./chunk-JW3GZUSC.cjs');
4
+ require('./chunk-C2H3KPHM.cjs');
5
+ var path = require('path');
6
+ var core = require('@kubb/core');
7
+ var transformers = require('@kubb/core/transformers');
8
+ var utils = require('@kubb/core/utils');
9
+ var pluginOas = require('@kubb/plugin-oas');
10
+ var pluginTs = require('@kubb/plugin-ts');
11
+ var pluginZod = require('@kubb/plugin-zod');
3
12
 
13
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
4
14
 
15
+ var path__default = /*#__PURE__*/_interopDefault(path);
5
16
 
6
-
7
-
8
- var _chunkJFX7DCS7cjs = require('./chunk-JFX7DCS7.cjs');
9
-
10
- // src/plugin.ts
11
- var _path = require('path'); var _path2 = _interopRequireDefault(_path);
12
- var _core = require('@kubb/core');
13
- var _transformers = require('@kubb/core/transformers');
14
- var _utils = require('@kubb/core/utils');
15
- var _pluginoas = require('@kubb/plugin-oas');
16
- var _utils3 = require('@kubb/plugin-oas/utils');
17
- var _plugints = require('@kubb/plugin-ts');
18
- var _pluginzod = require('@kubb/plugin-zod');
19
-
20
- // src/OperationGenerator.tsx
21
-
22
- var _components = require('@kubb/plugin-oas/components');
23
- var _react = require('@kubb/react');
24
- var _jsxruntime = require('@kubb/react/jsx-runtime');
25
- var OperationGenerator = class extends _pluginoas.OperationGenerator {
26
- async all(operations) {
27
- const { pluginManager, oas, plugin, mode } = this.context;
28
- const root = _react.createRoot.call(void 0, {
29
- logger: pluginManager.logger
30
- });
31
- const templates = {
32
- mutation: _chunkJFX7DCS7cjs.Mutation.templates,
33
- query: _chunkJFX7DCS7cjs.Query.templates,
34
- queryOptions: _chunkJFX7DCS7cjs.QueryOptions.templates,
35
- queryKey: _chunkJFX7DCS7cjs.QueryKey.templates,
36
- queryImports: _chunkJFX7DCS7cjs.QueryImports.templates,
37
- operations: _chunkJFX7DCS7cjs.Operations.templates,
38
- ...this.options.templates
39
- };
40
- root.render(
41
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations, generator: this, children: templates.operations && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkJFX7DCS7cjs.Operations.File, { templates: templates.operations }) }) })
42
- );
43
- return root.files;
44
- }
45
- async operation(operation, options) {
46
- const { oas, pluginManager, plugin, mode } = this.context;
47
- const root = _react.createRoot.call(void 0, {
48
- logger: pluginManager.logger
49
- });
50
- const templates = {
51
- mutation: _chunkJFX7DCS7cjs.Mutation.templates,
52
- query: _chunkJFX7DCS7cjs.Query.templates,
53
- queryOptions: _chunkJFX7DCS7cjs.QueryOptions.templates,
54
- queryKey: _chunkJFX7DCS7cjs.QueryKey.templates,
55
- queryImports: _chunkJFX7DCS7cjs.QueryImports.templates,
56
- ...options.templates
57
- };
58
- const isQuery = typeof options.query === "boolean" ? true : _optionalChain([options, 'access', _ => _.query, 'optionalAccess', _2 => _2.methods, 'access', _3 => _3.some, 'call', _4 => _4((method) => operation.method === method)]);
59
- const isMutate = !isQuery && options.mutate && options.mutate.methods.some((method) => operation.method === method);
60
- root.render(
61
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _components.Oas.Operation, { operation, children: [
62
- isMutate && _optionalChain([templates, 'optionalAccess', _5 => _5.mutation]) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkJFX7DCS7cjs.Mutation.File, { templates: templates.mutation }),
63
- isQuery && _optionalChain([templates, 'optionalAccess', _6 => _6.query]) && templates.queryKey && templates.queryOptions && templates.queryImports && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
64
- _chunkJFX7DCS7cjs.Query.File,
65
- {
66
- templates: {
67
- query: templates.query,
68
- queryKey: templates.queryKey,
69
- queryOptions: templates.queryOptions,
70
- queryImports: templates.queryImports
71
- }
72
- }
73
- )
74
- ] }) }) })
75
- );
76
- return root.files;
77
- }
78
- };
79
-
80
- // src/plugin.ts
81
17
  var pluginReactQueryName = "plugin-react-query";
82
- var pluginReactQuery = _core.createPlugin.call(void 0, (options) => {
18
+ var pluginReactQuery = core.createPlugin((options) => {
83
19
  const {
84
- output = { path: "hooks" },
20
+ output = { path: "hooks", barrelType: "named" },
85
21
  group,
86
22
  exclude = [],
87
23
  include,
88
24
  override = [],
89
- parser,
25
+ parser = "client",
90
26
  suspense = {},
91
27
  infinite,
92
- transformers = {},
93
- dataReturnType = "data",
28
+ transformers: transformers$1 = {},
94
29
  pathParamsType = "inline",
95
- mutate = {},
96
- query = {},
97
- queryOptions = {},
98
- templates
30
+ generators = [chunkJW3GZUSC_cjs.queryGenerator, chunkJW3GZUSC_cjs.suspenseQueryGenerator, chunkJW3GZUSC_cjs.infiniteQueryGenerator, chunkJW3GZUSC_cjs.mutationGenerator].filter(Boolean),
31
+ mutation = {},
32
+ query = {}
99
33
  } = options;
100
- const template = _optionalChain([group, 'optionalAccess', _7 => _7.output]) ? group.output : `${output.path}/{{tag}}Controller`;
34
+ const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
101
35
  return {
102
36
  name: pluginReactQueryName,
103
37
  options: {
38
+ output,
39
+ baseURL: void 0,
104
40
  client: {
105
41
  importPath: "@kubb/plugin-client/client",
42
+ dataReturnType: "data",
43
+ pathParamsType: "inline",
106
44
  ...options.client
107
45
  },
108
- dataReturnType,
109
- pathParamsType,
110
46
  infinite: infinite ? {
111
47
  queryParam: "id",
112
48
  initialPageParam: 0,
@@ -114,104 +50,89 @@ var pluginReactQuery = _core.createPlugin.call(void 0, (options) => {
114
50
  ...infinite
115
51
  } : false,
116
52
  suspense,
117
- query: query ? {
118
- queryKey: (key) => key,
53
+ query: {
54
+ key: (key) => key,
119
55
  methods: ["get"],
120
56
  importPath: "@tanstack/react-query",
121
57
  ...query
122
- } : false,
123
- queryOptions,
124
- mutate: mutate ? {
125
- variablesType: "hook",
58
+ },
59
+ mutation: {
60
+ key: (key) => key,
126
61
  methods: ["post", "put", "patch", "delete"],
127
- ...mutate
128
- } : false,
129
- templates: {
130
- mutation: _chunkJFX7DCS7cjs.Mutation.templates,
131
- query: _chunkJFX7DCS7cjs.Query.templates,
132
- queryOptions: _chunkJFX7DCS7cjs.QueryOptions.templates,
133
- queryKey: _chunkJFX7DCS7cjs.QueryKey.templates,
134
- queryImports: _chunkJFX7DCS7cjs.QueryImports.templates,
135
- operations: _chunkJFX7DCS7cjs.Operations.templates,
136
- ...templates
62
+ importPath: "@tanstack/react-query",
63
+ ...mutation
137
64
  },
65
+ pathParamsType,
138
66
  parser
139
67
  },
140
- pre: [_pluginoas.pluginOasName, _plugints.pluginTsName, parser === "zod" ? _pluginzod.pluginZodName : void 0].filter(Boolean),
68
+ pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, parser === "zod" ? pluginZod.pluginZodName : void 0].filter(Boolean),
141
69
  resolvePath(baseName, pathMode, options2) {
142
- const root = _path2.default.resolve(this.config.root, this.config.output.path);
143
- const mode = _nullishCoalesce(pathMode, () => ( _core.FileManager.getMode(_path2.default.resolve(root, output.path))));
70
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
71
+ const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
144
72
  if (mode === "single") {
145
- return _path2.default.resolve(root, output.path);
73
+ return path__default.default.resolve(root, output.path);
146
74
  }
147
- if (_optionalChain([options2, 'optionalAccess', _8 => _8.tag]) && _optionalChain([group, 'optionalAccess', _9 => _9.type]) === "tag") {
148
- const tag = _transformers.camelCase.call(void 0, options2.tag);
149
- return _path2.default.resolve(root, _utils.renderTemplate.call(void 0, template, { tag }), baseName);
75
+ if (options2?.tag && group?.type === "tag") {
76
+ const tag = transformers.camelCase(options2.tag);
77
+ return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
150
78
  }
151
- return _path2.default.resolve(root, output.path, baseName);
79
+ return path__default.default.resolve(root, output.path, baseName);
152
80
  },
153
81
  resolveName(name, type) {
154
- let resolvedName = _transformers.camelCase.call(void 0, name);
82
+ let resolvedName = transformers.camelCase(name);
155
83
  if (type === "file" || type === "function") {
156
- resolvedName = _transformers.camelCase.call(void 0, name, {
157
- prefix: "use",
84
+ resolvedName = transformers.camelCase(name, {
158
85
  isFile: type === "file"
159
86
  });
160
87
  }
161
88
  if (type === "type") {
162
- resolvedName = _transformers.pascalCase.call(void 0, name);
89
+ resolvedName = transformers.pascalCase(name);
163
90
  }
164
91
  if (type) {
165
- return _optionalChain([transformers, 'optionalAccess', _10 => _10.name, 'optionalCall', _11 => _11(resolvedName, type)]) || resolvedName;
92
+ return transformers$1?.name?.(resolvedName, type) || resolvedName;
166
93
  }
167
94
  return resolvedName;
168
95
  },
169
96
  async buildStart() {
170
- const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
97
+ const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
171
98
  const oas = await swaggerPlugin.context.getOas();
172
- const root = _path2.default.resolve(this.config.root, this.config.output.path);
173
- const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
174
- const operationGenerator = new OperationGenerator(this.plugin.options, {
175
- oas,
176
- pluginManager: this.pluginManager,
177
- plugin: this.plugin,
178
- contentType: swaggerPlugin.context.contentType,
179
- exclude,
180
- include,
181
- override,
182
- mode
183
- });
184
- const files = await operationGenerator.build();
185
- await this.addFile(...files);
186
- },
187
- async buildEnd() {
188
- if (this.config.output.write === false) {
189
- return;
190
- }
191
- const root = _path2.default.resolve(this.config.root, this.config.output.path);
192
- if (_optionalChain([group, 'optionalAccess', _12 => _12.type]) === "tag") {
193
- const rootFiles = await _utils3.getGroupedByTagFiles.call(void 0, {
194
- logger: this.logger,
195
- files: this.fileManager.files,
99
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
100
+ const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
101
+ const baseURL = await swaggerPlugin.context.getBaseURL();
102
+ const operationGenerator = new pluginOas.OperationGenerator(
103
+ {
104
+ ...this.plugin.options,
105
+ baseURL
106
+ },
107
+ {
108
+ oas,
109
+ pluginManager: this.pluginManager,
196
110
  plugin: this.plugin,
197
- template,
198
- exportAs: group.exportAs || "{{tag}}Hooks",
199
- root,
200
- output
201
- });
202
- await this.addFile(...rootFiles);
203
- }
204
- await this.fileManager.addIndexes({
111
+ contentType: swaggerPlugin.context.contentType,
112
+ exclude,
113
+ include,
114
+ override,
115
+ mode
116
+ }
117
+ );
118
+ const files = await operationGenerator.build(...generators);
119
+ await this.addFile(...files);
120
+ const barrelFiles = await this.fileManager.getBarrelFiles({
121
+ type: output.barrelType ?? "named",
205
122
  root,
206
123
  output,
207
- meta: { pluginKey: this.plugin.key },
124
+ files: this.fileManager.files,
125
+ meta: {
126
+ pluginKey: this.plugin.key
127
+ },
208
128
  logger: this.logger
209
129
  });
130
+ await this.addFile(...barrelFiles);
210
131
  }
211
132
  };
212
133
  });
213
134
 
214
-
215
-
216
- exports.pluginReactQuery = pluginReactQuery; exports.pluginReactQueryName = pluginReactQueryName;
135
+ exports.pluginReactQuery = pluginReactQuery;
136
+ exports.pluginReactQueryName = pluginReactQueryName;
137
+ //# sourceMappingURL=index.cjs.map
217
138
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-react-query/dist/index.cjs","../src/plugin.ts","../src/OperationGenerator.tsx"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACTA,wEAAiB;AAEjB,kCAAyD;AACzD,uDAAsC;AACtC,yCAA+B;AAC/B,6CAA8B;AAC9B,gDAAqC;AACrC,2CAA6B;AAC7B,6CAA8B;ADU9B;AACA;AEnBA;AACA,yDAAoB;AACpB,oCAAgC;AAkCG,qDAAA;AArB5B,IAAM,mBAAA,EAAN,MAAA,QAAiC,8BAA2E;AAAA,EACjH,MAAM,GAAA,CAAI,UAAA,EAA0D;AAClE,IAAA,MAAM,EAAE,aAAA,EAAe,GAAA,EAAK,MAAA,EAAQ,KAAK,EAAA,EAAI,IAAA,CAAK,OAAA;AAElD,IAAA,MAAM,KAAA,EAAO,+BAAA;AAAW,MACtB,MAAA,EAAQ,aAAA,CAAc;AAAA,IACxB,CAAC,CAAA;AAED,IAAA,MAAM,UAAA,EAAY;AAAA,MAChB,QAAA,EAAU,0BAAA,CAAS,SAAA;AAAA,MACnB,KAAA,EAAO,uBAAA,CAAM,SA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AC8C,IAAA;AACL,IAAA;AACK,MAAA;AACC,MAAA;AAEtB,MAAA;AAKgB,QAAA;AACvC,MAAA;AAE2C,MAAA;AACR,QAAA;AAEQ,QAAA;AAC3C,MAAA;AAEuC,MAAA;AACzC,IAAA;AACwB,IAAA;AACW,MAAA;AAEW,MAAA;AACX,QAAA;AACrB,UAAA;AACS,UAAA;AAClB,QAAA;AACH,MAAA;AACqB,MAAA;AACW,QAAA;AAChC,MAAA;AAEU,MAAA;AACkC,QAAA;AAC5C,MAAA;AAEO,MAAA;AACT,IAAA;AACmB,IAAA;AAC0C,MAAA;AAEnB,MAAA;AACI,MAAA;AACN,MAAA;AAEP,MAAA;AAC7B,QAAA;AACoB,QAAA;AACP,QAAA;AACsB,QAAA;AACnC,QAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACD,MAAA;AAE4C,MAAA;AAClB,MAAA;AAC7B,IAAA;AACiB,IAAA;AACyB,MAAA;AACtC,QAAA;AACF,MAAA;AAE4C,MAAA;AAEjB,MAAA;AACD,QAAA;AACT,UAAA;AACW,UAAA;AACX,UAAA;AACb,UAAA;AAC4B,UAAA;AAC5B,UAAA;AACA,UAAA;AACD,QAAA;AAE8B,QAAA;AACjC,MAAA;AAEkC,MAAA;AAChC,QAAA;AACA,QAAA;AACmC,QAAA;AACtB,QAAA;AACd,MAAA;AACH,IAAA;AACF,EAAA;AACD;ADqCkD;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/plugin-react-query/dist/index.cjs","sourcesContent":[null,"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'\nimport { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport { OperationGenerator } from './OperationGenerator.tsx'\nimport { Mutation, Operations, 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 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 operations: Operations.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 async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n const root = path.resolve(this.config.root, this.config.output.path)\n\n if (group?.type === 'tag') {\n const rootFiles = await getGroupedByTagFiles({\n logger: this.logger,\n files: this.fileManager.files,\n plugin: this.plugin,\n template,\n exportAs: group.exportAs || '{{tag}}Hooks',\n root,\n output,\n })\n\n await this.addFile(...rootFiles)\n }\n\n await this.fileManager.addIndexes({\n root,\n output,\n meta: { pluginKey: this.plugin.key },\n logger: this.logger,\n })\n },\n }\n})\n","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 { Operations } from './components/Operations.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 all(operations: Operation[]): OperationMethodResult<FileMeta> {\n const { pluginManager, oas, 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 operations: Operations.templates,\n ...this.options.templates,\n }\n\n root.render(\n <App pluginManager={pluginManager} plugin={plugin} mode={mode}>\n <Oas oas={oas} operations={operations} generator={this}>\n {templates.operations && <Operations.File templates={templates.operations} />}\n </Oas>\n </App>,\n )\n\n return root.files\n }\n\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"]}
1
+ {"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","queryGenerator","suspenseQueryGenerator","infiniteQueryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","options","path","FileManager","camelCase","renderTemplate","pascalCase","PluginManager","OperationGenerator"],"mappings":";;;;;;;;;;;;;;;;AAeO,IAAM,oBAAuB,GAAA,qBAAA;AAEvB,IAAA,gBAAA,GAAmBA,iBAA+B,CAAA,CAAC,OAAY,KAAA;AAC1E,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,OAAA,EAAS,YAAY,OAAQ,EAAA;AAAA,IAC9C,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,IACZ,MAAS,GAAA,QAAA;AAAA,IACT,WAAW,EAAC;AAAA,IACZ,QAAA;AAAA,kBACAC,iBAAe,EAAC;AAAA,IAChB,cAAiB,GAAA,QAAA;AAAA,IACjB,UAAA,GAAa,CAACC,gCAAgB,EAAAC,wCAAA,EAAwBC,0CAAwBC,mCAAiB,CAAA,CAAE,OAAO,OAAO,CAAA;AAAA,IAC/G,WAAW,EAAC;AAAA,IACZ,QAAQ,EAAC;AAAA,GACP,GAAA,OAAA,CAAA;AACJ,EAAA,MAAM,WAAW,KAAO,EAAA,MAAA,GAAS,MAAM,MAAS,GAAA,CAAA,EAAG,OAAO,IAAI,CAAA,kBAAA,CAAA,CAAA;AAE9D,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,oBAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP,MAAA;AAAA,MACA,OAAS,EAAA,KAAA,CAAA;AAAA,MACT,MAAQ,EAAA;AAAA,QACN,UAAY,EAAA,4BAAA;AAAA,QACZ,cAAgB,EAAA,MAAA;AAAA,QAChB,cAAgB,EAAA,QAAA;AAAA,QAChB,GAAG,OAAQ,CAAA,MAAA;AAAA,OACb;AAAA,MACA,UAAU,QACN,GAAA;AAAA,QACE,UAAY,EAAA,IAAA;AAAA,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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', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n suspense = {},\n infinite,\n transformers = {},\n pathParamsType = 'inline',\n generators = [queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator].filter(Boolean),\n mutation = {},\n query = {},\n } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginReactQueryName,\n options: {\n output,\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 key: (key: unknown[]) => key,\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(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\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"]}
package/dist/index.d.cts CHANGED
@@ -1,11 +1,7 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginReactQuery } from './index-C9fwRDH7.cjs';
3
- import '@kubb/core/utils';
2
+ import { O as Options, P as PluginReactQuery } from './types-rJasmoxy.cjs';
4
3
  import '@kubb/oas';
5
- import 'react';
6
- import '@kubb/fs/types';
7
4
  import '@kubb/plugin-oas';
8
- import '@kubb/react';
9
5
 
10
6
  declare const pluginReactQueryName = "plugin-react-query";
11
7
  declare const pluginReactQuery: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginReactQuery>;
package/dist/index.d.ts CHANGED
@@ -1,11 +1,7 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginReactQuery } from './index-C9fwRDH7.js';
3
- import '@kubb/core/utils';
2
+ import { O as Options, P as PluginReactQuery } from './types-rJasmoxy.js';
4
3
  import '@kubb/oas';
5
- import 'react';
6
- import '@kubb/fs/types';
7
4
  import '@kubb/plugin-oas';
8
- import '@kubb/react';
9
5
 
10
6
  declare const pluginReactQueryName = "plugin-react-query";
11
7
  declare const pluginReactQuery: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginReactQuery>;
package/dist/index.js CHANGED
@@ -1,112 +1,42 @@
1
- import {
2
- Mutation,
3
- Operations,
4
- Query,
5
- QueryImports,
6
- QueryKey,
7
- QueryOptions
8
- } from "./chunk-5IL6M74X.js";
1
+ import { queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator } from './chunk-2D27Y6L5.js';
2
+ import './chunk-Y3DM2P6L.js';
3
+ import path from 'node:path';
4
+ import { createPlugin, FileManager, PluginManager } from '@kubb/core';
5
+ import { camelCase, pascalCase } from '@kubb/core/transformers';
6
+ import { renderTemplate } from '@kubb/core/utils';
7
+ import { pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
8
+ import { pluginTsName } from '@kubb/plugin-ts';
9
+ import { pluginZodName } from '@kubb/plugin-zod';
9
10
 
10
- // src/plugin.ts
11
- import path from "path";
12
- import { FileManager, PluginManager, createPlugin } from "@kubb/core";
13
- import { camelCase, pascalCase } from "@kubb/core/transformers";
14
- import { renderTemplate } from "@kubb/core/utils";
15
- import { pluginOasName } from "@kubb/plugin-oas";
16
- import { getGroupedByTagFiles } from "@kubb/plugin-oas/utils";
17
- import { pluginTsName } from "@kubb/plugin-ts";
18
- import { pluginZodName } from "@kubb/plugin-zod";
19
-
20
- // src/OperationGenerator.tsx
21
- import { OperationGenerator as Generator } from "@kubb/plugin-oas";
22
- import { Oas } from "@kubb/plugin-oas/components";
23
- import { App, createRoot } from "@kubb/react";
24
- import { jsx, jsxs } from "@kubb/react/jsx-runtime";
25
- var OperationGenerator = class extends Generator {
26
- async all(operations) {
27
- const { pluginManager, oas, plugin, mode } = this.context;
28
- const root = createRoot({
29
- logger: pluginManager.logger
30
- });
31
- const templates = {
32
- mutation: Mutation.templates,
33
- query: Query.templates,
34
- queryOptions: QueryOptions.templates,
35
- queryKey: QueryKey.templates,
36
- queryImports: QueryImports.templates,
37
- operations: Operations.templates,
38
- ...this.options.templates
39
- };
40
- root.render(
41
- /* @__PURE__ */ jsx(App, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsx(Oas, { oas, operations, generator: this, children: templates.operations && /* @__PURE__ */ jsx(Operations.File, { templates: templates.operations }) }) })
42
- );
43
- return root.files;
44
- }
45
- async operation(operation, options) {
46
- const { oas, pluginManager, plugin, mode } = this.context;
47
- const root = createRoot({
48
- logger: pluginManager.logger
49
- });
50
- const templates = {
51
- mutation: Mutation.templates,
52
- query: Query.templates,
53
- queryOptions: QueryOptions.templates,
54
- queryKey: QueryKey.templates,
55
- queryImports: QueryImports.templates,
56
- ...options.templates
57
- };
58
- const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
59
- const isMutate = !isQuery && options.mutate && options.mutate.methods.some((method) => operation.method === method);
60
- root.render(
61
- /* @__PURE__ */ jsx(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx(Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsxs(Oas.Operation, { operation, children: [
62
- isMutate && templates?.mutation && /* @__PURE__ */ jsx(Mutation.File, { templates: templates.mutation }),
63
- isQuery && templates?.query && templates.queryKey && templates.queryOptions && templates.queryImports && /* @__PURE__ */ jsx(
64
- Query.File,
65
- {
66
- templates: {
67
- query: templates.query,
68
- queryKey: templates.queryKey,
69
- queryOptions: templates.queryOptions,
70
- queryImports: templates.queryImports
71
- }
72
- }
73
- )
74
- ] }) }) })
75
- );
76
- return root.files;
77
- }
78
- };
79
-
80
- // src/plugin.ts
81
11
  var pluginReactQueryName = "plugin-react-query";
82
12
  var pluginReactQuery = createPlugin((options) => {
83
13
  const {
84
- output = { path: "hooks" },
14
+ output = { path: "hooks", barrelType: "named" },
85
15
  group,
86
16
  exclude = [],
87
17
  include,
88
18
  override = [],
89
- parser,
19
+ parser = "client",
90
20
  suspense = {},
91
21
  infinite,
92
22
  transformers = {},
93
- dataReturnType = "data",
94
23
  pathParamsType = "inline",
95
- mutate = {},
96
- query = {},
97
- queryOptions = {},
98
- templates
24
+ generators = [queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator].filter(Boolean),
25
+ mutation = {},
26
+ query = {}
99
27
  } = options;
100
28
  const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
101
29
  return {
102
30
  name: pluginReactQueryName,
103
31
  options: {
32
+ output,
33
+ baseURL: void 0,
104
34
  client: {
105
35
  importPath: "@kubb/plugin-client/client",
36
+ dataReturnType: "data",
37
+ pathParamsType: "inline",
106
38
  ...options.client
107
39
  },
108
- dataReturnType,
109
- pathParamsType,
110
40
  infinite: infinite ? {
111
41
  queryParam: "id",
112
42
  initialPageParam: 0,
@@ -114,27 +44,19 @@ var pluginReactQuery = createPlugin((options) => {
114
44
  ...infinite
115
45
  } : false,
116
46
  suspense,
117
- query: query ? {
118
- queryKey: (key) => key,
47
+ query: {
48
+ key: (key) => key,
119
49
  methods: ["get"],
120
50
  importPath: "@tanstack/react-query",
121
51
  ...query
122
- } : false,
123
- queryOptions,
124
- mutate: mutate ? {
125
- variablesType: "hook",
52
+ },
53
+ mutation: {
54
+ key: (key) => key,
126
55
  methods: ["post", "put", "patch", "delete"],
127
- ...mutate
128
- } : false,
129
- templates: {
130
- mutation: Mutation.templates,
131
- query: Query.templates,
132
- queryOptions: QueryOptions.templates,
133
- queryKey: QueryKey.templates,
134
- queryImports: QueryImports.templates,
135
- operations: Operations.templates,
136
- ...templates
56
+ importPath: "@tanstack/react-query",
57
+ ...mutation
137
58
  },
59
+ pathParamsType,
138
60
  parser
139
61
  },
140
62
  pre: [pluginOasName, pluginTsName, parser === "zod" ? pluginZodName : void 0].filter(Boolean),
@@ -154,7 +76,6 @@ var pluginReactQuery = createPlugin((options) => {
154
76
  let resolvedName = camelCase(name);
155
77
  if (type === "file" || type === "function") {
156
78
  resolvedName = camelCase(name, {
157
- prefix: "use",
158
79
  isFile: type === "file"
159
80
  });
160
81
  }
@@ -171,47 +92,40 @@ var pluginReactQuery = createPlugin((options) => {
171
92
  const oas = await swaggerPlugin.context.getOas();
172
93
  const root = path.resolve(this.config.root, this.config.output.path);
173
94
  const mode = FileManager.getMode(path.resolve(root, output.path));
174
- const operationGenerator = new OperationGenerator(this.plugin.options, {
175
- oas,
176
- pluginManager: this.pluginManager,
177
- plugin: this.plugin,
178
- contentType: swaggerPlugin.context.contentType,
179
- exclude,
180
- include,
181
- override,
182
- mode
183
- });
184
- const files = await operationGenerator.build();
185
- await this.addFile(...files);
186
- },
187
- async buildEnd() {
188
- if (this.config.output.write === false) {
189
- return;
190
- }
191
- const root = path.resolve(this.config.root, this.config.output.path);
192
- if (group?.type === "tag") {
193
- const rootFiles = await getGroupedByTagFiles({
194
- logger: this.logger,
195
- files: this.fileManager.files,
95
+ const baseURL = await swaggerPlugin.context.getBaseURL();
96
+ const operationGenerator = new OperationGenerator(
97
+ {
98
+ ...this.plugin.options,
99
+ baseURL
100
+ },
101
+ {
102
+ oas,
103
+ pluginManager: this.pluginManager,
196
104
  plugin: this.plugin,
197
- template,
198
- exportAs: group.exportAs || "{{tag}}Hooks",
199
- root,
200
- output
201
- });
202
- await this.addFile(...rootFiles);
203
- }
204
- await this.fileManager.addIndexes({
105
+ contentType: swaggerPlugin.context.contentType,
106
+ exclude,
107
+ include,
108
+ override,
109
+ mode
110
+ }
111
+ );
112
+ const files = await operationGenerator.build(...generators);
113
+ await this.addFile(...files);
114
+ const barrelFiles = await this.fileManager.getBarrelFiles({
115
+ type: output.barrelType ?? "named",
205
116
  root,
206
117
  output,
207
- meta: { pluginKey: this.plugin.key },
118
+ files: this.fileManager.files,
119
+ meta: {
120
+ pluginKey: this.plugin.key
121
+ },
208
122
  logger: this.logger
209
123
  });
124
+ await this.addFile(...barrelFiles);
210
125
  }
211
126
  };
212
127
  });
213
- export {
214
- pluginReactQuery,
215
- pluginReactQueryName
216
- };
128
+
129
+ export { pluginReactQuery, pluginReactQueryName };
130
+ //# sourceMappingURL=index.js.map
217
131
  //# sourceMappingURL=index.js.map