@kubb/plugin-client 3.0.0-alpha.1 → 3.0.0-alpha.11
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.
- package/client.ts +1 -1
- package/dist/chunk-3NQF7BGA.cjs +58 -0
- package/dist/chunk-3NQF7BGA.cjs.map +1 -0
- package/dist/chunk-AZDWYBLW.cjs +4 -0
- package/dist/chunk-AZDWYBLW.cjs.map +1 -0
- package/dist/chunk-PO22ZUSH.cjs +125 -0
- package/dist/chunk-PO22ZUSH.cjs.map +1 -0
- package/dist/chunk-QBFKND4S.js +122 -0
- package/dist/chunk-QBFKND4S.js.map +1 -0
- package/dist/chunk-QLVGX3VO.js +56 -0
- package/dist/chunk-QLVGX3VO.js.map +1 -0
- package/dist/chunk-YJOVLRSC.js +3 -0
- package/dist/chunk-YJOVLRSC.js.map +1 -0
- package/dist/client.cjs +16 -7
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +5 -6
- package/dist/client.js.map +1 -1
- package/dist/components.cjs +12 -4
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +3 -5
- package/dist/components.d.ts +3 -5
- package/dist/components.js +3 -8
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +13 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +10 -0
- package/dist/generators.d.ts +10 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +51 -104
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -5
- package/dist/index.d.ts +3 -5
- package/dist/index.js +31 -91
- package/dist/index.js.map +1 -1
- package/dist/{types-xK4X9e5d.d.cts → types-DETYKDFZ.d.cts} +19 -108
- package/dist/{types-xK4X9e5d.d.ts → types-DETYKDFZ.d.ts} +19 -108
- package/package.json +22 -14
- package/src/components/Client.tsx +77 -198
- package/src/components/Operations.tsx +9 -75
- package/src/components/__snapshots__/Client/showPetById.ts +3 -6
- package/src/components/__snapshots__/Operations/showPetById.ts +5 -5
- package/src/generators/axiosGenerator.tsx +63 -0
- package/src/generators/index.ts +1 -0
- package/src/plugin.ts +21 -38
- package/src/types.ts +9 -3
- package/dist/chunk-W57BRY5O.js +0 -201
- package/dist/chunk-W57BRY5O.js.map +0 -1
- package/dist/chunk-W7F5CMU6.cjs +0 -201
- package/dist/chunk-W7F5CMU6.cjs.map +0 -1
- package/src/OperationGenerator.tsx +0 -65
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk3NQF7BGA_cjs = require('./chunk-3NQF7BGA.cjs');
|
|
4
|
+
require('./chunk-PO22ZUSH.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, "axiosGenerator", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunk3NQF7BGA_cjs.axiosGenerator; }
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=generators.cjs.map
|
|
13
|
+
//# sourceMappingURL=generators.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"generators.cjs"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _kubb_plugin_oas from '@kubb/plugin-oas';
|
|
2
|
+
import { P as PluginClient } from './types-DETYKDFZ.cjs';
|
|
3
|
+
import '@kubb/core';
|
|
4
|
+
import '@kubb/fs/types';
|
|
5
|
+
import '@kubb/oas';
|
|
6
|
+
import '@kubb/react/types';
|
|
7
|
+
|
|
8
|
+
declare const axiosGenerator: _kubb_plugin_oas.Generator<PluginClient>;
|
|
9
|
+
|
|
10
|
+
export { axiosGenerator };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _kubb_plugin_oas from '@kubb/plugin-oas';
|
|
2
|
+
import { P as PluginClient } from './types-DETYKDFZ.js';
|
|
3
|
+
import '@kubb/core';
|
|
4
|
+
import '@kubb/fs/types';
|
|
5
|
+
import '@kubb/oas';
|
|
6
|
+
import '@kubb/react/types';
|
|
7
|
+
|
|
8
|
+
declare const axiosGenerator: _kubb_plugin_oas.Generator<PluginClient>;
|
|
9
|
+
|
|
10
|
+
export { axiosGenerator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"generators.js"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,122 +1,81 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
+
require('./chunk-AZDWYBLW.cjs');
|
|
4
|
+
var chunk3NQF7BGA_cjs = require('./chunk-3NQF7BGA.cjs');
|
|
5
|
+
var chunkPO22ZUSH_cjs = require('./chunk-PO22ZUSH.cjs');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
var core = require('@kubb/core');
|
|
8
|
+
var transformers = require('@kubb/core/transformers');
|
|
9
|
+
var utils = require('@kubb/core/utils');
|
|
10
|
+
var pluginOas = require('@kubb/plugin-oas');
|
|
3
11
|
|
|
4
|
-
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
5
13
|
|
|
6
|
-
|
|
7
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
8
|
-
var _core = require('@kubb/core');
|
|
9
|
-
var _transformers = require('@kubb/core/transformers');
|
|
10
|
-
var _utils = require('@kubb/core/utils');
|
|
11
|
-
var _pluginoas = require('@kubb/plugin-oas');
|
|
12
|
-
var _utils3 = require('@kubb/plugin-oas/utils');
|
|
14
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
13
15
|
|
|
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
|
-
var pluginClient =
|
|
17
|
+
var pluginClient = core.createPlugin((options) => {
|
|
58
18
|
const {
|
|
59
19
|
output = { path: "clients" },
|
|
60
20
|
group,
|
|
61
21
|
exclude = [],
|
|
62
22
|
include,
|
|
63
23
|
override = [],
|
|
64
|
-
transformers = {},
|
|
24
|
+
transformers: transformers$1 = {},
|
|
65
25
|
dataReturnType = "data",
|
|
66
26
|
pathParamsType = "inline",
|
|
67
27
|
templates
|
|
68
28
|
} = options;
|
|
69
|
-
const template =
|
|
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:
|
|
82
|
-
client:
|
|
46
|
+
operations: chunkPO22ZUSH_cjs.Operations,
|
|
47
|
+
client: chunkPO22ZUSH_cjs.Client,
|
|
83
48
|
...templates
|
|
84
49
|
},
|
|
85
50
|
baseURL: void 0
|
|
86
51
|
},
|
|
87
|
-
pre: [
|
|
52
|
+
pre: [pluginOas.pluginOasName],
|
|
88
53
|
resolvePath(baseName, pathMode, options2) {
|
|
89
|
-
const root =
|
|
90
|
-
const mode =
|
|
54
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
55
|
+
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
91
56
|
if (mode === "single") {
|
|
92
|
-
return
|
|
57
|
+
return path__default.default.resolve(root, output.path);
|
|
93
58
|
}
|
|
94
|
-
if (
|
|
95
|
-
const tag =
|
|
96
|
-
return
|
|
59
|
+
if (options2?.tag && group?.type === "tag") {
|
|
60
|
+
const tag = transformers.camelCase(options2.tag);
|
|
61
|
+
return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
|
|
97
62
|
}
|
|
98
|
-
return
|
|
63
|
+
return path__default.default.resolve(root, output.path, baseName);
|
|
99
64
|
},
|
|
100
65
|
resolveName(name, type) {
|
|
101
|
-
const resolvedName =
|
|
66
|
+
const resolvedName = transformers.camelCase(name, { isFile: type === "file" });
|
|
102
67
|
if (type) {
|
|
103
|
-
return
|
|
68
|
+
return transformers$1?.name?.(resolvedName, type) || resolvedName;
|
|
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
|
-
const [swaggerPlugin] =
|
|
115
|
-
const oas = await swaggerPlugin.
|
|
116
|
-
const root =
|
|
117
|
-
const mode =
|
|
118
|
-
const baseURL = await swaggerPlugin.
|
|
119
|
-
const operationGenerator = new OperationGenerator(
|
|
73
|
+
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
74
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
75
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
76
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
77
|
+
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
78
|
+
const operationGenerator = new pluginOas.OperationGenerator(
|
|
120
79
|
{
|
|
121
80
|
...this.plugin.options,
|
|
122
81
|
baseURL
|
|
@@ -125,44 +84,32 @@ var pluginClient = _core.createPlugin.call(void 0, (options) => {
|
|
|
125
84
|
oas,
|
|
126
85
|
pluginManager: this.pluginManager,
|
|
127
86
|
plugin: this.plugin,
|
|
128
|
-
contentType: swaggerPlugin.
|
|
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(chunk3NQF7BGA_cjs.axiosGenerator);
|
|
136
95
|
await this.addFile(...files);
|
|
137
|
-
|
|
138
|
-
|
|
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(...
|
|
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
|
});
|
|
164
111
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
112
|
+
exports.pluginClient = pluginClient;
|
|
113
|
+
exports.pluginClientName = pluginClientName;
|
|
114
|
+
//# sourceMappingURL=index.cjs.map
|
|
168
115
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -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,EAA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AA;AAET,MAAA;AAC7B,QAAA;AACiB,UAAA;AACf,UAAA;AACF,QAAA;AACA,QAAA;AACE,UAAA;AACoB,UAAA;AACP,UAAA;AACkB,UAAA;AAC/B,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACF,QAAA;AACF,MAAA;AAE6C,MAAA;AAElB,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;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":["../src/plugin.ts"],"names":["createPlugin","transformers","Operations","Client","pluginOasName","options","path","FileManager","camelCase","renderTemplate","PluginManager","OperationGenerator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AO,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 } 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-
|
|
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/
|
|
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-
|
|
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/
|
|
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,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import './chunk-YJOVLRSC.js';
|
|
2
|
+
import { axiosGenerator } from './chunk-QLVGX3VO.js';
|
|
3
|
+
import { Operations, Client } from './chunk-QBFKND4S.js';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
6
|
+
import { camelCase } from '@kubb/core/transformers';
|
|
7
|
+
import { renderTemplate } from '@kubb/core/utils';
|
|
8
|
+
import { pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
|
|
5
9
|
|
|
6
|
-
// src/plugin.ts
|
|
7
|
-
import path from "path";
|
|
8
|
-
import { FileManager, PluginManager, createPlugin } from "@kubb/core";
|
|
9
|
-
import { camelCase } from "@kubb/core/transformers";
|
|
10
|
-
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
|
|
56
10
|
var pluginClientName = "plugin-client";
|
|
57
11
|
var pluginClient = createPlugin((options) => {
|
|
58
12
|
const {
|
|
@@ -69,17 +23,22 @@ var pluginClient = createPlugin((options) => {
|
|
|
69
23
|
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
70
24
|
return {
|
|
71
25
|
name: pluginClientName,
|
|
26
|
+
output: {
|
|
27
|
+
exportType: "barrelNamed",
|
|
28
|
+
...output
|
|
29
|
+
},
|
|
72
30
|
options: {
|
|
73
31
|
extName: output.extName,
|
|
74
32
|
dataReturnType,
|
|
75
33
|
client: {
|
|
76
34
|
importPath: "@kubb/plugin-client/client",
|
|
35
|
+
methods: ["get", "post", "delete", "put"],
|
|
77
36
|
...options.client
|
|
78
37
|
},
|
|
79
38
|
pathParamsType,
|
|
80
39
|
templates: {
|
|
81
|
-
operations: Operations
|
|
82
|
-
client: Client
|
|
40
|
+
operations: Operations,
|
|
41
|
+
client: Client,
|
|
83
42
|
...templates
|
|
84
43
|
},
|
|
85
44
|
baseURL: void 0
|
|
@@ -104,18 +63,12 @@ var pluginClient = createPlugin((options) => {
|
|
|
104
63
|
}
|
|
105
64
|
return resolvedName;
|
|
106
65
|
},
|
|
107
|
-
async writeFile(path2, source) {
|
|
108
|
-
if (!source) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
return this.fileManager.write(path2, source, { sanity: false });
|
|
112
|
-
},
|
|
113
66
|
async buildStart() {
|
|
114
67
|
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
115
|
-
const oas = await swaggerPlugin.
|
|
68
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
116
69
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
117
70
|
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
118
|
-
const baseURL = await swaggerPlugin.
|
|
71
|
+
const baseURL = await swaggerPlugin.context.getBaseURL();
|
|
119
72
|
const operationGenerator = new OperationGenerator(
|
|
120
73
|
{
|
|
121
74
|
...this.plugin.options,
|
|
@@ -125,44 +78,31 @@ var pluginClient = createPlugin((options) => {
|
|
|
125
78
|
oas,
|
|
126
79
|
pluginManager: this.pluginManager,
|
|
127
80
|
plugin: this.plugin,
|
|
128
|
-
contentType: swaggerPlugin.
|
|
81
|
+
contentType: swaggerPlugin.context.contentType,
|
|
129
82
|
exclude,
|
|
130
83
|
include,
|
|
131
84
|
override,
|
|
132
85
|
mode
|
|
133
86
|
}
|
|
134
87
|
);
|
|
135
|
-
const files = await operationGenerator.build();
|
|
88
|
+
const files = await operationGenerator.build(axiosGenerator);
|
|
136
89
|
await this.addFile(...files);
|
|
137
|
-
|
|
138
|
-
|
|
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",
|
|
90
|
+
if (this.config.output.exportType) {
|
|
91
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
150
92
|
root,
|
|
151
|
-
output
|
|
93
|
+
output,
|
|
94
|
+
files: this.fileManager.files,
|
|
95
|
+
meta: {
|
|
96
|
+
pluginKey: this.plugin.key
|
|
97
|
+
},
|
|
98
|
+
logger: this.logger
|
|
152
99
|
});
|
|
153
|
-
await this.addFile(...
|
|
100
|
+
await this.addFile(...barrelFiles);
|
|
154
101
|
}
|
|
155
|
-
await this.fileManager.addIndexes({
|
|
156
|
-
root,
|
|
157
|
-
output,
|
|
158
|
-
meta: { pluginKey: this.plugin.key },
|
|
159
|
-
logger: this.logger
|
|
160
|
-
});
|
|
161
102
|
}
|
|
162
103
|
};
|
|
163
104
|
});
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
};
|
|
105
|
+
|
|
106
|
+
export { pluginClient, pluginClientName };
|
|
107
|
+
//# sourceMappingURL=index.js.map
|
|
168
108
|
//# sourceMappingURL=index.js.map
|
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,WAA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,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 } 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"]}
|