@kubb/plugin-client 3.0.0-alpha.0 → 3.0.0-alpha.10

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 (51) hide show
  1. package/client.ts +1 -1
  2. package/dist/chunk-3NQF7BGA.cjs +61 -0
  3. package/dist/chunk-3NQF7BGA.cjs.map +1 -0
  4. package/dist/chunk-AZDWYBLW.cjs +1 -0
  5. package/dist/chunk-AZDWYBLW.cjs.map +1 -0
  6. package/dist/chunk-PO22ZUSH.cjs +128 -0
  7. package/dist/chunk-PO22ZUSH.cjs.map +1 -0
  8. package/dist/chunk-QBFKND4S.js +128 -0
  9. package/dist/chunk-QBFKND4S.js.map +1 -0
  10. package/dist/chunk-QLVGX3VO.js +61 -0
  11. package/dist/chunk-QLVGX3VO.js.map +1 -0
  12. package/dist/chunk-YJOVLRSC.js +1 -0
  13. package/dist/chunk-YJOVLRSC.js.map +1 -0
  14. package/dist/client.cjs.map +1 -1
  15. package/dist/client.d.cts +1 -1
  16. package/dist/client.d.ts +1 -1
  17. package/dist/client.js.map +1 -1
  18. package/dist/components.cjs +4 -3
  19. package/dist/components.cjs.map +1 -1
  20. package/dist/components.d.cts +3 -5
  21. package/dist/components.d.ts +3 -5
  22. package/dist/components.js +2 -1
  23. package/dist/generators.cjs +8 -0
  24. package/dist/generators.cjs.map +1 -0
  25. package/dist/generators.d.cts +10 -0
  26. package/dist/generators.d.ts +10 -0
  27. package/dist/generators.js +8 -0
  28. package/dist/generators.js.map +1 -0
  29. package/dist/index.cjs +27 -80
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.cts +3 -5
  32. package/dist/index.d.ts +3 -5
  33. package/dist/index.js +27 -80
  34. package/dist/index.js.map +1 -1
  35. package/dist/{types-DWYt1NR3.d.cts → types-DETYKDFZ.d.cts} +19 -113
  36. package/dist/{types-DWYt1NR3.d.ts → types-DETYKDFZ.d.ts} +19 -113
  37. package/package.json +22 -14
  38. package/src/components/Client.tsx +77 -198
  39. package/src/components/Operations.tsx +9 -75
  40. package/src/components/__snapshots__/Client/showPetById.ts +3 -6
  41. package/src/components/__snapshots__/Operations/showPetById.ts +5 -5
  42. package/src/generators/axiosGenerator.tsx +63 -0
  43. package/src/generators/index.ts +1 -0
  44. package/src/plugin.ts +21 -38
  45. package/src/types.ts +9 -9
  46. package/dist/chunk-W57BRY5O.js +0 -201
  47. package/dist/chunk-W57BRY5O.js.map +0 -1
  48. package/dist/chunk-W7F5CMU6.cjs +0 -201
  49. package/dist/chunk-W7F5CMU6.cjs.map +0 -1
  50. package/globals.d.ts +0 -24
  51. package/src/OperationGenerator.tsx +0 -65
package/dist/index.cjs CHANGED
@@ -1,7 +1,11 @@
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";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; }require('./chunk-AZDWYBLW.cjs');
2
2
 
3
3
 
4
- var _chunkW7F5CMU6cjs = require('./chunk-W7F5CMU6.cjs');
4
+ var _chunk3NQF7BGAcjs = require('./chunk-3NQF7BGA.cjs');
5
+
6
+
7
+
8
+ var _chunkPO22ZUSHcjs = require('./chunk-PO22ZUSH.cjs');
5
9
 
6
10
  // src/plugin.ts
7
11
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
@@ -9,50 +13,6 @@ var _core = require('@kubb/core');
9
13
  var _transformers = require('@kubb/core/transformers');
10
14
  var _utils = require('@kubb/core/utils');
11
15
  var _pluginoas = require('@kubb/plugin-oas');
12
- var _utils3 = require('@kubb/plugin-oas/utils');
13
-
14
- // src/OperationGenerator.tsx
15
-
16
- var _components = require('@kubb/plugin-oas/components');
17
- var _react = require('@kubb/react');
18
- var _jsxruntime = require('@kubb/react/jsx-runtime');
19
- var OperationGenerator = class extends _pluginoas.OperationGenerator {
20
- async all(operations, _operationsByMethod) {
21
- const { pluginManager, oas, plugin, mode } = this.context;
22
- const root = _react.createRoot.call(void 0, {
23
- logger: pluginManager.logger
24
- });
25
- const templates = {
26
- operations: _chunkW7F5CMU6cjs.Operations.templates,
27
- client: _chunkW7F5CMU6cjs.Client.templates,
28
- ...this.options.templates
29
- };
30
- root.render(
31
- /* @__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, _chunkW7F5CMU6cjs.Operations.File, { baseURL: this.options.baseURL, templates: templates.operations }) }) })
32
- );
33
- return root.files;
34
- }
35
- async operation(operation, options) {
36
- const { oas, pluginManager, plugin, mode } = this.context;
37
- const root = _react.createRoot.call(void 0, {
38
- logger: pluginManager.logger
39
- });
40
- const templates = {
41
- operations: _chunkW7F5CMU6cjs.Operations.templates,
42
- client: _chunkW7F5CMU6cjs.Client.templates,
43
- ...options.templates
44
- };
45
- if (!templates.client) {
46
- return [];
47
- }
48
- root.render(
49
- /* @__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.jsx.call(void 0, _components.Oas.Operation, { operation, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkW7F5CMU6cjs.Client.File, { baseURL: this.options.baseURL, templates: templates.client }) }) }) })
50
- );
51
- return root.files;
52
- }
53
- };
54
-
55
- // src/plugin.ts
56
16
  var pluginClientName = "plugin-client";
57
17
  var pluginClient = _core.createPlugin.call(void 0, (options) => {
58
18
  const {
@@ -69,17 +29,22 @@ var pluginClient = _core.createPlugin.call(void 0, (options) => {
69
29
  const template = _optionalChain([group, 'optionalAccess', _ => _.output]) ? group.output : `${output.path}/{{tag}}Controller`;
70
30
  return {
71
31
  name: pluginClientName,
32
+ output: {
33
+ exportType: "barrelNamed",
34
+ ...output
35
+ },
72
36
  options: {
73
37
  extName: output.extName,
74
38
  dataReturnType,
75
39
  client: {
76
40
  importPath: "@kubb/plugin-client/client",
41
+ methods: ["get", "post", "delete", "put"],
77
42
  ...options.client
78
43
  },
79
44
  pathParamsType,
80
45
  templates: {
81
- operations: _chunkW7F5CMU6cjs.Operations.templates,
82
- client: _chunkW7F5CMU6cjs.Client.templates,
46
+ operations: _chunkPO22ZUSHcjs.Operations,
47
+ client: _chunkPO22ZUSHcjs.Client,
83
48
  ...templates
84
49
  },
85
50
  baseURL: void 0
@@ -104,19 +69,13 @@ var pluginClient = _core.createPlugin.call(void 0, (options) => {
104
69
  }
105
70
  return resolvedName;
106
71
  },
107
- async writeFile(path2, source) {
108
- if (!source) {
109
- return;
110
- }
111
- return this.fileManager.write(path2, source, { sanity: false });
112
- },
113
72
  async buildStart() {
114
73
  const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
115
- const oas = await swaggerPlugin.api.getOas();
74
+ const oas = await swaggerPlugin.context.getOas();
116
75
  const root = _path2.default.resolve(this.config.root, this.config.output.path);
117
76
  const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
118
- const baseURL = await swaggerPlugin.api.getBaseURL();
119
- const operationGenerator = new OperationGenerator(
77
+ const baseURL = await swaggerPlugin.context.getBaseURL();
78
+ const operationGenerator = new (0, _pluginoas.OperationGenerator)(
120
79
  {
121
80
  ...this.plugin.options,
122
81
  baseURL
@@ -125,39 +84,27 @@ var pluginClient = _core.createPlugin.call(void 0, (options) => {
125
84
  oas,
126
85
  pluginManager: this.pluginManager,
127
86
  plugin: this.plugin,
128
- contentType: swaggerPlugin.api.contentType,
87
+ contentType: swaggerPlugin.context.contentType,
129
88
  exclude,
130
89
  include,
131
90
  override,
132
91
  mode
133
92
  }
134
93
  );
135
- const files = await operationGenerator.build();
94
+ const files = await operationGenerator.build(_chunk3NQF7BGAcjs.axiosGenerator);
136
95
  await this.addFile(...files);
137
- },
138
- async buildEnd() {
139
- if (this.config.output.write === false) {
140
- return;
141
- }
142
- const root = _path2.default.resolve(this.config.root, this.config.output.path);
143
- if (_optionalChain([group, 'optionalAccess', _6 => _6.type]) === "tag") {
144
- const rootFiles = await _utils3.getGroupedByTagFiles.call(void 0, {
145
- logger: this.logger,
146
- files: this.fileManager.files,
147
- plugin: this.plugin,
148
- template,
149
- exportAs: group.exportAs || "{{tag}}Service",
96
+ if (this.config.output.exportType) {
97
+ const barrelFiles = await this.fileManager.getBarrelFiles({
150
98
  root,
151
- output
99
+ output,
100
+ files: this.fileManager.files,
101
+ meta: {
102
+ pluginKey: this.plugin.key
103
+ },
104
+ logger: this.logger
152
105
  });
153
- await this.addFile(...rootFiles);
106
+ await this.addFile(...barrelFiles);
154
107
  }
155
- await this.fileManager.addIndexes({
156
- root,
157
- output,
158
- meta: { pluginKey: this.plugin.key },
159
- logger: this.logger
160
- });
161
108
  }
162
109
  };
163
110
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-client/dist/index.cjs","../src/plugin.ts","../src/OperationGenerator.tsx"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACLA,wEAAiB;AAEjB,kCAAyD;AACzD,uDAA0B;AAC1B,yCAA+B;AAC/B,6CAA8B;AAC9B,gDAAqC;ADMrC;AACA;AEbA;AACA,yDAAoB;AACpB,oCAAgC;AAyBG,qDAAA;AAjB5B,IAAM,mBAAA,EAAN,MAAA,QAAiC,8BAAyD;AAAA,EAC/F,MAAM,GAAA,CAAI,UAAA,EAAyB,mBAAA,EAA0E;AAC3G,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,UAAA,EAAY,4BAAA,CAAW,SAAA;AAAA,MACvB,MAAA,EAAQ,wBAAA,CAAO,SAAA;AAAA,MACf,GAAG,IAAA,CAAK,OAAA,CAAQ;AAAA,IAClB,CAAA;AAEA,IAAA,IAAA,CAAK,MAAA;AAAA,sBACH,6BAAA,UAAC,EAAA,EAAI,aAAA,EAA8B,MAAA,EAAgB,IAAA,EACjD,QAAA,kBAAA,6BAAA,eAAC,EAAA,EAAI,GAAA,EAAU,UAAA,EAAwB,SAAA,EAAW,IAAA,EAC/C,QAAA,EAAA,SAAA,CAAU,WAAA,mBAAc,6BAAA,4BAAC,CAAW,IAAA,EAAX,EAAgB,OAAA,EAAS,IAAA,CAAK,OAAA,CAAQ,OAAA,EAAS,SAAA,EAAW,SAAA,CAAU,WAAA,CAAY,EAAA,CAC5G,EAAA,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;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;ADmBkD;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/plugin-client/dist/index.cjs","sourcesContent":[null,"import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { pluginOasName } from '@kubb/plugin-oas'\nimport { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'\n\nimport { OperationGenerator } from './OperationGenerator.tsx'\nimport { Client, Operations } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport type { PluginClient } from './types.ts'\n\nexport const pluginClientName = 'plugin-client' satisfies PluginClient['name']\n\nexport const pluginClient = createPlugin<PluginClient>((options) => {\n const {\n output = { path: 'clients' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dataReturnType = 'data',\n pathParamsType = 'inline',\n templates,\n } = options\n\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginClientName,\n options: {\n extName: output.extName,\n dataReturnType,\n client: {\n importPath: '@kubb/plugin-client/client',\n ...options.client,\n },\n pathParamsType,\n templates: {\n operations: Operations.templates,\n client: Client.templates,\n ...templates,\n },\n baseURL: undefined,\n },\n pre: [pluginOasName],\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 const resolvedName = camelCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async writeFile(path, source) {\n if (!source) {\n return\n }\n\n return this.fileManager.write(path, source, { sanity: false })\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.api.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.api.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.api.contentType,\n exclude,\n include,\n override,\n mode,\n },\n )\n\n const files = await operationGenerator.build()\n\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}}Service',\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 { Client, Operations } from './components/index.ts'\n\nimport type { Operation } from '@kubb/oas'\nimport type { OperationMethodResult, OperationsByMethod } from '@kubb/plugin-oas'\nimport type { FileMeta, PluginClient } from './types.ts'\n\nexport class OperationGenerator extends Generator<PluginClient['resolvedOptions'], PluginClient> {\n async all(operations: Operation[], _operationsByMethod: OperationsByMethod): 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 operations: Operations.templates,\n client: Client.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 baseURL={this.options.baseURL} templates={templates.operations} />}\n </Oas>\n </App>,\n )\n\n return root.files\n }\n\n async operation(operation: Operation, options: PluginClient['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 operations: Operations.templates,\n client: Client.templates,\n ...options.templates,\n }\n\n if (!templates.client) {\n return []\n }\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 <Client.File baseURL={this.options.baseURL} templates={templates.client} />\n </Oas.Operation>\n </Oas>\n </App>,\n )\n\n return root.files\n }\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-client/dist/index.cjs","../src/plugin.ts"],"names":[],"mappings":"AAAA,izBAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACTA,wEAAiB;AAEjB,kCAAyD;AACzD,uDAA0B;AAC1B,yCAA+B;AAC/B,6CAAkD;AAS3C,IAAM,iBAAA,EAAmB,eAAA;AAEzB,IAAM,aAAA,EAAe,gCAAA,CAA4B,OAAA,EAAA,GAAY;A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B,UAAA;AAClB,UAAA;AACmB,YAAA;AACzB,UAAA;AACa,UAAA;AACd,QAAA;AAEgC,QAAA;AACnC,MAAA;AACF,IAAA;AACF,EAAA;AACD;ADjBkD;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/plugin-client/dist/index.cjs","sourcesContent":[null,"import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { Client, Operations } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { axiosGenerator } from './generators/axiosGenerator.tsx'\nimport type { PluginClient } from './types.ts'\n\nexport const pluginClientName = 'plugin-client' satisfies PluginClient['name']\n\nexport const pluginClient = createPlugin<PluginClient>((options) => {\n const {\n output = { path: 'clients' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dataReturnType = 'data',\n pathParamsType = 'inline',\n templates,\n } = options\n\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginClientName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {\n extName: output.extName,\n dataReturnType,\n client: {\n importPath: '@kubb/plugin-client/client',\n methods: ['get', 'post', 'delete', 'put'],\n ...options.client,\n },\n pathParamsType,\n templates: {\n operations: Operations,\n client: Client,\n ...templates,\n },\n baseURL: undefined,\n },\n pre: [pluginOasName],\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 const resolvedName = camelCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(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(axiosGenerator)\n\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,11 +1,9 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginClient } from './types-DWYt1NR3.cjs';
2
+ import { O as Options, P as PluginClient } from './types-DETYKDFZ.cjs';
3
3
  import '@kubb/fs/types';
4
- import '@kubb/plugin-oas';
5
- import '@kubb/core/utils';
6
4
  import '@kubb/oas';
7
- import '@kubb/react';
8
- import 'react';
5
+ import '@kubb/plugin-oas';
6
+ import '@kubb/react/types';
9
7
 
10
8
  declare const pluginClientName = "plugin-client";
11
9
  declare const pluginClient: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginClient>;
package/dist/index.d.ts CHANGED
@@ -1,11 +1,9 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginClient } from './types-DWYt1NR3.js';
2
+ import { O as Options, P as PluginClient } from './types-DETYKDFZ.js';
3
3
  import '@kubb/fs/types';
4
- import '@kubb/plugin-oas';
5
- import '@kubb/core/utils';
6
4
  import '@kubb/oas';
7
- import '@kubb/react';
8
- import 'react';
5
+ import '@kubb/plugin-oas';
6
+ import '@kubb/react/types';
9
7
 
10
8
  declare const pluginClientName = "plugin-client";
11
9
  declare const pluginClient: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginClient>;
package/dist/index.js CHANGED
@@ -1,58 +1,18 @@
1
+ import "./chunk-YJOVLRSC.js";
2
+ import {
3
+ axiosGenerator
4
+ } from "./chunk-QLVGX3VO.js";
1
5
  import {
2
6
  Client,
3
7
  Operations
4
- } from "./chunk-W57BRY5O.js";
8
+ } from "./chunk-QBFKND4S.js";
5
9
 
6
10
  // src/plugin.ts
7
- import path from "path";
11
+ import path from "node:path";
8
12
  import { FileManager, PluginManager, createPlugin } from "@kubb/core";
9
13
  import { camelCase } from "@kubb/core/transformers";
10
14
  import { renderTemplate } from "@kubb/core/utils";
11
- import { pluginOasName } from "@kubb/plugin-oas";
12
- import { getGroupedByTagFiles } from "@kubb/plugin-oas/utils";
13
-
14
- // src/OperationGenerator.tsx
15
- import { OperationGenerator as Generator } from "@kubb/plugin-oas";
16
- import { Oas } from "@kubb/plugin-oas/components";
17
- import { App, createRoot } from "@kubb/react";
18
- import { jsx } from "@kubb/react/jsx-runtime";
19
- var OperationGenerator = class extends Generator {
20
- async all(operations, _operationsByMethod) {
21
- const { pluginManager, oas, plugin, mode } = this.context;
22
- const root = createRoot({
23
- logger: pluginManager.logger
24
- });
25
- const templates = {
26
- operations: Operations.templates,
27
- client: Client.templates,
28
- ...this.options.templates
29
- };
30
- root.render(
31
- /* @__PURE__ */ jsx(App, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsx(Oas, { oas, operations, generator: this, children: templates.operations && /* @__PURE__ */ jsx(Operations.File, { baseURL: this.options.baseURL, templates: templates.operations }) }) })
32
- );
33
- return root.files;
34
- }
35
- async operation(operation, options) {
36
- const { oas, pluginManager, plugin, mode } = this.context;
37
- const root = createRoot({
38
- logger: pluginManager.logger
39
- });
40
- const templates = {
41
- operations: Operations.templates,
42
- client: Client.templates,
43
- ...options.templates
44
- };
45
- if (!templates.client) {
46
- return [];
47
- }
48
- root.render(
49
- /* @__PURE__ */ jsx(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx(Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsx(Oas.Operation, { operation, children: /* @__PURE__ */ jsx(Client.File, { baseURL: this.options.baseURL, templates: templates.client }) }) }) })
50
- );
51
- return root.files;
52
- }
53
- };
54
-
55
- // src/plugin.ts
15
+ import { OperationGenerator, pluginOasName } from "@kubb/plugin-oas";
56
16
  var pluginClientName = "plugin-client";
57
17
  var pluginClient = createPlugin((options) => {
58
18
  const {
@@ -69,17 +29,22 @@ var pluginClient = createPlugin((options) => {
69
29
  const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
70
30
  return {
71
31
  name: pluginClientName,
32
+ output: {
33
+ exportType: "barrelNamed",
34
+ ...output
35
+ },
72
36
  options: {
73
37
  extName: output.extName,
74
38
  dataReturnType,
75
39
  client: {
76
40
  importPath: "@kubb/plugin-client/client",
41
+ methods: ["get", "post", "delete", "put"],
77
42
  ...options.client
78
43
  },
79
44
  pathParamsType,
80
45
  templates: {
81
- operations: Operations.templates,
82
- client: Client.templates,
46
+ operations: Operations,
47
+ client: Client,
83
48
  ...templates
84
49
  },
85
50
  baseURL: void 0
@@ -104,18 +69,12 @@ var pluginClient = createPlugin((options) => {
104
69
  }
105
70
  return resolvedName;
106
71
  },
107
- async writeFile(path2, source) {
108
- if (!source) {
109
- return;
110
- }
111
- return this.fileManager.write(path2, source, { sanity: false });
112
- },
113
72
  async buildStart() {
114
73
  const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
115
- const oas = await swaggerPlugin.api.getOas();
74
+ const oas = await swaggerPlugin.context.getOas();
116
75
  const root = path.resolve(this.config.root, this.config.output.path);
117
76
  const mode = FileManager.getMode(path.resolve(root, output.path));
118
- const baseURL = await swaggerPlugin.api.getBaseURL();
77
+ const baseURL = await swaggerPlugin.context.getBaseURL();
119
78
  const operationGenerator = new OperationGenerator(
120
79
  {
121
80
  ...this.plugin.options,
@@ -125,39 +84,27 @@ var pluginClient = createPlugin((options) => {
125
84
  oas,
126
85
  pluginManager: this.pluginManager,
127
86
  plugin: this.plugin,
128
- contentType: swaggerPlugin.api.contentType,
87
+ contentType: swaggerPlugin.context.contentType,
129
88
  exclude,
130
89
  include,
131
90
  override,
132
91
  mode
133
92
  }
134
93
  );
135
- const files = await operationGenerator.build();
94
+ const files = await operationGenerator.build(axiosGenerator);
136
95
  await this.addFile(...files);
137
- },
138
- async buildEnd() {
139
- if (this.config.output.write === false) {
140
- return;
141
- }
142
- const root = path.resolve(this.config.root, this.config.output.path);
143
- if (group?.type === "tag") {
144
- const rootFiles = await getGroupedByTagFiles({
145
- logger: this.logger,
146
- files: this.fileManager.files,
147
- plugin: this.plugin,
148
- template,
149
- exportAs: group.exportAs || "{{tag}}Service",
96
+ if (this.config.output.exportType) {
97
+ const barrelFiles = await this.fileManager.getBarrelFiles({
150
98
  root,
151
- output
99
+ output,
100
+ files: this.fileManager.files,
101
+ meta: {
102
+ pluginKey: this.plugin.key
103
+ },
104
+ logger: this.logger
152
105
  });
153
- await this.addFile(...rootFiles);
106
+ await this.addFile(...barrelFiles);
154
107
  }
155
- await this.fileManager.addIndexes({
156
- root,
157
- output,
158
- meta: { pluginKey: this.plugin.key },
159
- logger: this.logger
160
- });
161
108
  }
162
109
  };
163
110
  });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin.ts","../src/OperationGenerator.tsx"],"sourcesContent":["import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { pluginOasName } from '@kubb/plugin-oas'\nimport { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'\n\nimport { OperationGenerator } from './OperationGenerator.tsx'\nimport { Client, Operations } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport type { PluginClient } from './types.ts'\n\nexport const pluginClientName = 'plugin-client' satisfies PluginClient['name']\n\nexport const pluginClient = createPlugin<PluginClient>((options) => {\n const {\n output = { path: 'clients' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dataReturnType = 'data',\n pathParamsType = 'inline',\n templates,\n } = options\n\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginClientName,\n options: {\n extName: output.extName,\n dataReturnType,\n client: {\n importPath: '@kubb/plugin-client/client',\n ...options.client,\n },\n pathParamsType,\n templates: {\n operations: Operations.templates,\n client: Client.templates,\n ...templates,\n },\n baseURL: undefined,\n },\n pre: [pluginOasName],\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 const resolvedName = camelCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async writeFile(path, source) {\n if (!source) {\n return\n }\n\n return this.fileManager.write(path, source, { sanity: false })\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.api.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.api.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.api.contentType,\n exclude,\n include,\n override,\n mode,\n },\n )\n\n const files = await operationGenerator.build()\n\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}}Service',\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 { Client, Operations } from './components/index.ts'\n\nimport type { Operation } from '@kubb/oas'\nimport type { OperationMethodResult, OperationsByMethod } from '@kubb/plugin-oas'\nimport type { FileMeta, PluginClient } from './types.ts'\n\nexport class OperationGenerator extends Generator<PluginClient['resolvedOptions'], PluginClient> {\n async all(operations: Operation[], _operationsByMethod: OperationsByMethod): 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 operations: Operations.templates,\n client: Client.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 baseURL={this.options.baseURL} templates={templates.operations} />}\n </Oas>\n </App>,\n )\n\n return root.files\n }\n\n async operation(operation: Operation, options: PluginClient['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 operations: Operations.templates,\n client: Client.templates,\n ...options.templates,\n }\n\n if (!templates.client) {\n return []\n }\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 <Client.File baseURL={this.options.baseURL} templates={templates.client} />\n </Oas.Operation>\n </Oas>\n </App>,\n )\n\n return root.files\n }\n}\n"],"mappings":";;;;;;AAAA,OAAO,UAAU;AAEjB,SAAS,aAAa,eAAe,oBAAoB;AACzD,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAC9B,SAAS,4BAA4B;;;ACNrC,SAAS,sBAAsB,iBAAiB;AAChD,SAAS,WAAW;AACpB,SAAS,KAAK,kBAAkB;AAyBG;AAjB5B,IAAM,qBAAN,cAAiC,UAAyD;AAAA,EAC/F,MAAM,IAAI,YAAyB,qBAA0E;AAC3G,UAAM,EAAE,eAAe,KAAK,QAAQ,KAAK,IAAI,KAAK;AAElD,UAAM,OAAO,WAAW;AAAA,MACtB,QAAQ,cAAc;AAAA,IACxB,CAAC;AAED,UAAM,YAAY;AAAA,MAChB,YAAY,WAAW;AAAA,MACvB,QAAQ,OAAO;AAAA,MACf,GAAG,KAAK,QAAQ;AAAA,IAClB;AAEA,SAAK;AAAA,MACH,oBAAC,OAAI,eAA8B,QAAgB,MACjD,8BAAC,OAAI,KAAU,YAAwB,WAAW,MAC/C,oBAAU,cAAc,oBAAC,WAAW,MAAX,EAAgB,SAAS,KAAK,QAAQ,SAAS,WAAW,UAAU,YAAY,GAC5G,GACF;AAAA,IACF;AAEA,WA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AI,WAAW;AAEnD,YAAM,qBAAqB,IAAI;AAAA,QAC7B;AAAA,UACE,GAAG,KAAK,OAAO;AAAA,UACf;AAAA,QACF;AAAA,QACA;AAAA,UACE;AAAA,UACA,eAAe,KAAK;AAAA,UACpB,QAAQ,KAAK;AAAA,UACb,aAAa,cAAc,IAAI;AAAA,UAC/B;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAEA,YAAM,QAAQ,MAAM,mBAAmB,MAAM;AAE7C,YAAM,KAAK,QAAQ,GAAG,KAAK;AAAA,IAC7B;AAAA,IACA,MAAM,WAAW;AACf,UAAI,KAAK,OAAO,OAAO,UAAU,OAAO;AACtC;AAAA,MACF;AAEA,YAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,IAAI;AAEnE,UAAI,OAAO,SAAS,OAAO;AACzB,cAAM,YAAY,MAAM,qBAAqB;AAAA,UAC3C,QAAQ,KAAK;AAAA,UACb,OAAO,KAAK,YAAY;AAAA,UACxB,QAAQ,KAAK;AAAA,UACb;AAAA,UACA,UAAU,MAAM,YAAY;AAAA,UAC5B;AAAA,UACA;AAAA,QACF,CAAC;AAED,cAAM,KAAK,QAAQ,GAAG,SAAS;AAAA,MACjC;AAEA,YAAM,KAAK,YAAY,WAAW;AAAA,QAChC;AAAA,QACA;AAAA,QACA,MAAM,EAAE,WAAW,KAAK,OAAO,IAAI;AAAA,QACnC,QAAQ,KAAK;AAAA,MACf,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":["options","path"]}
1
+ {"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { Client, Operations } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { axiosGenerator } from './generators/axiosGenerator.tsx'\nimport type { PluginClient } from './types.ts'\n\nexport const pluginClientName = 'plugin-client' satisfies PluginClient['name']\n\nexport const pluginClient = createPlugin<PluginClient>((options) => {\n const {\n output = { path: 'clients' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dataReturnType = 'data',\n pathParamsType = 'inline',\n templates,\n } = options\n\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginClientName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {\n extName: output.extName,\n dataReturnType,\n client: {\n importPath: '@kubb/plugin-client/client',\n methods: ['get', 'post', 'delete', 'put'],\n ...options.client,\n },\n pathParamsType,\n templates: {\n operations: Operations,\n client: Client,\n ...templates,\n },\n baseURL: undefined,\n },\n pre: [pluginOasName],\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 const resolvedName = camelCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(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(axiosGenerator)\n\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"],"mappings":";;;;;;;;;;AAAA,OAAO,UAAU;AAEjB,SAAS,aAAa,eAAe,oBAAoB;AACzD,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB,qBAAqB;AAS3C,IAAM,mBAAmB;AAEzB,IAAM,eAAe,aAA2B,CAAC,YAAY;AAClE,QAAM;AAAA,IACJ,SAAS,EAAE,MAAM,UAAU;AAAA,IAC3B;AAAA,IACA,UAAU,CAAC;AAAA,IACX;AAAA,IACA,WAAW,CAAC;AAAA,IACZ,eAAe,CAAC;AAAA,IAChB,iBAAiB;AAAA,IACjB,iBAAiB;AAAA,IACjB;AAAA,EACF,IAAI;AAEJ,QAAM,WAAW,OAAO,SAAS,MAAM,SAAS,GAAG,OAAO,IAAI;AAE9D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ;AAAA,MACN,YAAY;AAAA,MACZ,GAAG;AAAA,IACL;AAAA,IACA,SAAS;AAAA,MACP,SAAS,OAAO;AAAA,MAChB;AAAA,MACA,QAAQ;AAAA,QACN,YAAY;AAAA,QACZ,SAAS,CAAC,OAAO,QAAQ,UAAU,KAAK;AAAA,QACxC,GAAG,QAAQ;AAAA,MACb;AAAA,MACA;AAAA,MACA,WAAW;AAAA,QACT,YAAY;AAAA,QACZ,QAAQ;AAAA,QACR,GAAG;AAAA,MACL;AAAA,MACA,SAAS;AAAA,IACX;AAAA,IACA,KAAK,CAA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UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAEA,YAAM,QAAQ,MAAM,mBAAmB,MAAM,cAAc;AAE3D,YAAM,KAAK,QAAQ,GAAG,KAAK;AAE3B,UAAI,KAAK,OAAO,OAAO,YAAY;AACjC,cAAM,cAAc,MAAM,KAAK,YAAY,eAAe;AAAA,UACxD;AAAA,UACA;AAAA,UACA,OAAO,KAAK,YAAY;AAAA,UACxB,MAAM;AAAA,YACJ,WAAW,KAAK,OAAO;AAAA,UACzB;AAAA,UACA,QAAQ,KAAK;AAAA,QACf,CAAC;AAED,cAAM,KAAK,QAAQ,GAAG,WAAW;AAAA,MACnC;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":["options"]}
@@ -1,123 +1,29 @@
1
1
  import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
2
2
  import * as KubbFile from '@kubb/fs/types';
3
- import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
4
- import { URLPath } from '@kubb/core/utils';
5
- import { HttpMethod, Operation } from '@kubb/oas';
6
- import { KubbNode, Params } from '@kubb/react';
7
- import { ComponentType, ComponentProps } from 'react';
3
+ import { Operation, HttpMethod } from '@kubb/oas';
4
+ import { OperationSchemas, ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
5
+ import { KubbNode } from '@kubb/react/types';
8
6
 
9
- type TemplateProps$1 = {
7
+ type Props = {
10
8
  /**
11
9
  * Name of the function
12
10
  */
13
11
  name: string;
14
- /**
15
- * Parameters/options/props that need to be used
16
- */
17
- params: Params;
18
- /**
19
- * Generics that needs to be added for TypeScript
20
- */
21
- generics?: string;
22
- /**
23
- * ReturnType(see async for adding Promise type)
24
- */
25
- returnType?: string;
26
- /**
27
- * Options for JSdocs
28
- */
29
- JSDoc?: {
30
- comments: string[];
31
- };
32
- client: {
33
- baseURL: string | undefined;
34
- generics: string | string[];
35
- method: HttpMethod;
36
- path: URLPath;
37
- dataReturnType: PluginClient['options']['dataReturnType'];
38
- withQueryParams: boolean;
39
- withData: boolean;
40
- withHeaders: boolean;
41
- contentType: string;
42
- };
43
- };
44
- declare function Template$1({ name, generics, returnType, params, JSDoc, client }: TemplateProps$1): KubbNode;
45
- type RootTemplateProps$1 = {
46
- children?: React.ReactNode;
47
- };
48
- declare function RootTemplate$1({ children }: RootTemplateProps$1): JSX.Element;
49
- declare const defaultTemplates$1: {
50
- readonly default: typeof Template$1;
51
- readonly root: typeof RootTemplate$1;
52
- };
53
- type Templates$2 = Partial<typeof defaultTemplates$1>;
54
- type ClientProps = {
55
- baseURL: string | undefined;
56
- /**
57
- * This will make it possible to override the default behaviour.
58
- */
59
- Template?: ComponentType<ComponentProps<typeof Template$1>>;
60
- };
61
- declare function Client({ baseURL, Template }: ClientProps): KubbNode;
62
- declare namespace Client {
63
- var File: ({ baseURL, ...props }: FileProps$1) => KubbNode;
64
- var templates: {
65
- readonly default: typeof Template$1;
66
- readonly root: typeof RootTemplate$1;
67
- };
68
- }
69
- type FileProps$1 = {
70
- baseURL: string | undefined;
71
- /**
72
- * This will make it possible to override the default behaviour.
73
- */
74
- templates?: Templates$2;
12
+ options: PluginClient['resolvedOptions'];
13
+ typedSchemas: OperationSchemas;
14
+ operation: Operation;
75
15
  };
16
+ declare function Client({ name, options, typedSchemas, operation }: Props): KubbNode;
76
17
 
77
- type TemplateProps = {
78
- /**
79
- * Name of the function
80
- */
18
+ type OperationsProps = {
81
19
  name: string;
82
- operations: Operation[];
83
- baseURL: string | undefined;
84
- };
85
- declare function Template({ name, operations }: TemplateProps): KubbNode;
86
- type RootTemplateProps = {
87
- children?: React.ReactNode;
88
- };
89
- declare function RootTemplate({ children }: RootTemplateProps): JSX.Element;
90
- declare const defaultTemplates: {
91
- readonly default: typeof Template;
92
- readonly root: typeof RootTemplate;
93
- };
94
- type Templates$1 = Partial<typeof defaultTemplates>;
95
- type Props = {
96
- baseURL: string | undefined;
97
- /**
98
- * This will make it possible to override the default behaviour.
99
- */
100
- Template?: ComponentType<ComponentProps<typeof Template>>;
101
- };
102
- declare function Operations({ baseURL, Template }: Props): KubbNode;
103
- declare namespace Operations {
104
- var File: ({ baseURL, ...props }: FileProps) => KubbNode;
105
- var templates: {
106
- readonly default: typeof Template;
107
- readonly root: typeof RootTemplate;
108
- };
109
- }
110
- type FileProps = {
111
- baseURL: string | undefined;
112
- /**
113
- * This will make it possible to override the default behaviour.
114
- */
115
- templates?: Templates$1;
20
+ operations: Array<Operation>;
116
21
  };
22
+ declare function Operations({ name, operations }: OperationsProps): JSX.Element;
117
23
 
118
24
  type Templates = {
119
- operations?: typeof Operations.templates | false;
120
- client?: typeof Client.templates | false;
25
+ operations?: typeof Operations | false;
26
+ client?: typeof Client | false;
121
27
  };
122
28
  type Options = {
123
29
  output?: {
@@ -136,7 +42,7 @@ type Options = {
136
42
  extName?: KubbFile.Extname;
137
43
  /**
138
44
  * Define what needs to exported, here you can also disable the export of barrel files
139
- * @default `'barrel'`
45
+ * @default `'barrelNamed'`
140
46
  */
141
47
  exportType?: 'barrel' | 'barrelNamed' | false;
142
48
  };
@@ -183,6 +89,11 @@ type Options = {
183
89
  * @default '@kubb/plugin-client/client'
184
90
  */
185
91
  importPath?: string;
92
+ /**
93
+ * Define which HttpMethods can be used for queries
94
+ * @default ['get', 'post', 'put', 'delete']
95
+ */
96
+ methods?: Array<HttpMethod>;
186
97
  };
187
98
  /**
188
99
  * ReturnType that needs to be used when calling client().
@@ -224,10 +135,5 @@ type ResolvedOptions = {
224
135
  templates: NonNullable<Templates>;
225
136
  };
226
137
  type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, never, ResolvePathOptions>;
227
- declare module '@kubb/core' {
228
- interface _Register {
229
- ['@kubb/plugin-client']: PluginClient;
230
- }
231
- }
232
138
 
233
139
  export { Client as C, type Options as O, type PluginClient as P, Operations as a };