@kubb/plugin-msw 3.0.0-alpha.8 → 3.0.0-beta.1
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/README.md +14 -5
- package/dist/chunk-6F4YUN2R.cjs +138 -0
- package/dist/chunk-6F4YUN2R.cjs.map +1 -0
- package/dist/chunk-6M2QU6UL.js +22 -0
- package/dist/chunk-6M2QU6UL.js.map +1 -0
- package/dist/chunk-GODA4G5K.cjs +25 -0
- package/dist/chunk-GODA4G5K.cjs.map +1 -0
- package/dist/chunk-TW2VMA3H.js +129 -0
- package/dist/chunk-TW2VMA3H.js.map +1 -0
- package/dist/components.cjs +11 -4
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +7 -70
- package/dist/components.d.ts +7 -70
- package/dist/components.js +2 -8
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +9 -0
- package/dist/generators.d.ts +9 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +11 -128
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -86
- package/dist/index.d.ts +3 -86
- package/dist/index.js +3 -133
- package/dist/index.js.map +1 -1
- package/dist/types-B3_ksuJz.d.cts +46 -0
- package/dist/types-B3_ksuJz.d.ts +46 -0
- package/package.json +22 -17
- package/src/components/Handlers.tsx +19 -0
- package/src/components/Mock.tsx +8 -86
- package/src/components/index.ts +1 -1
- package/src/generators/__snapshots__/createPet.ts +9 -0
- package/src/generators/__snapshots__/deletePet.ts +9 -0
- package/src/generators/__snapshots__/getPets.ts +9 -0
- package/src/generators/__snapshots__/handlers.ts +3 -0
- package/src/generators/__snapshots__/showPetById.ts +9 -0
- package/src/generators/handlersGenerator.tsx +32 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/mswGenerator.tsx +38 -0
- package/src/plugin.ts +34 -37
- package/src/types.ts +15 -58
- package/dist/chunk-3KHLTEUD.js +0 -104
- package/dist/chunk-3KHLTEUD.js.map +0 -1
- package/dist/chunk-BD7UJBXM.cjs +0 -104
- package/dist/chunk-BD7UJBXM.cjs.map +0 -1
- package/src/OperationGenerator.tsx +0 -66
- package/src/components/Operations.tsx +0 -94
- package/src/components/__snapshots__/Mock/Pets.ts +0 -7
- package/src/components/__snapshots__/Mock/showPetsById.ts +0 -7
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk6F4YUN2R_cjs = require('./chunk-6F4YUN2R.cjs');
|
|
4
|
+
require('./chunk-GODA4G5K.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, "handlersGenerator", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunk6F4YUN2R_cjs.handlersGenerator; }
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "mswGenerator", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunk6F4YUN2R_cjs.mswGenerator; }
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=generators.cjs.map
|
|
17
|
+
//# sourceMappingURL=generators.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"generators.cjs"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as _kubb_plugin_oas from '@kubb/plugin-oas';
|
|
2
|
+
import { P as PluginMsw } from './types-B3_ksuJz.cjs';
|
|
3
|
+
import '@kubb/core';
|
|
4
|
+
|
|
5
|
+
declare const mswGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
|
|
6
|
+
|
|
7
|
+
declare const handlersGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
|
|
8
|
+
|
|
9
|
+
export { handlersGenerator, mswGenerator };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as _kubb_plugin_oas from '@kubb/plugin-oas';
|
|
2
|
+
import { P as PluginMsw } from './types-B3_ksuJz.js';
|
|
3
|
+
import '@kubb/core';
|
|
4
|
+
|
|
5
|
+
declare const mswGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
|
|
6
|
+
|
|
7
|
+
declare const handlersGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
|
|
8
|
+
|
|
9
|
+
export { handlersGenerator, mswGenerator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"generators.js"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,134 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunk6F4YUN2R_cjs = require('./chunk-6F4YUN2R.cjs');
|
|
4
|
+
require('./chunk-GODA4G5K.cjs');
|
|
3
5
|
|
|
4
|
-
var _chunkBD7UJBXMcjs = require('./chunk-BD7UJBXM.cjs');
|
|
5
6
|
|
|
6
|
-
// src/plugin.ts
|
|
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 _pluginfaker = require('@kubb/plugin-faker');
|
|
13
|
-
var _plugints = require('@kubb/plugin-ts');
|
|
14
7
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var _react = require('@kubb/react');
|
|
19
|
-
var _jsxruntime = require('@kubb/react/jsx-runtime');
|
|
20
|
-
var OperationGenerator = class extends _pluginoas.OperationGenerator {
|
|
21
|
-
async all(operations, operationsByMethod) {
|
|
22
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
23
|
-
const root = _react.createRoot.call(void 0, {
|
|
24
|
-
logger: pluginManager.logger
|
|
25
|
-
});
|
|
26
|
-
const templates = {
|
|
27
|
-
operations: _chunkBD7UJBXMcjs.Operations.templates,
|
|
28
|
-
mock: _chunkBD7UJBXMcjs.Mock.templates,
|
|
29
|
-
...this.options.templates
|
|
30
|
-
};
|
|
31
|
-
root.render(
|
|
32
|
-
/* @__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: _optionalChain([templates, 'optionalAccess', _ => _.operations]) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkBD7UJBXMcjs.Operations.File, { templates: templates.operations }) }) })
|
|
33
|
-
);
|
|
34
|
-
return root.files;
|
|
35
|
-
}
|
|
36
|
-
async operation(operation, options) {
|
|
37
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
38
|
-
const root = _react.createRoot.call(void 0, {
|
|
39
|
-
logger: pluginManager.logger
|
|
40
|
-
});
|
|
41
|
-
const templates = {
|
|
42
|
-
handlers: _chunkBD7UJBXMcjs.Operations.templates,
|
|
43
|
-
mock: _chunkBD7UJBXMcjs.Mock.templates,
|
|
44
|
-
...options.templates
|
|
45
|
-
};
|
|
46
|
-
if (!_optionalChain([templates, 'optionalAccess', _2 => _2.mock])) {
|
|
47
|
-
return [];
|
|
48
|
-
}
|
|
49
|
-
root.render(
|
|
50
|
-
/* @__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, _chunkBD7UJBXMcjs.Mock.File, { templates: templates.mock }) }) }) })
|
|
51
|
-
);
|
|
52
|
-
return root.files;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// src/plugin.ts
|
|
57
|
-
var pluginMswName = "plugin-msw";
|
|
58
|
-
var pluginMsw = _core.createPlugin.call(void 0, (options) => {
|
|
59
|
-
const { output = { path: "handlers" }, group, exclude = [], include, override = [], transformers = {}, templates } = options;
|
|
60
|
-
const template = _optionalChain([group, 'optionalAccess', _3 => _3.output]) ? group.output : `${output.path}/{{tag}}Controller`;
|
|
61
|
-
return {
|
|
62
|
-
name: pluginMswName,
|
|
63
|
-
output: {
|
|
64
|
-
exportType: "barrelNamed",
|
|
65
|
-
...output
|
|
66
|
-
},
|
|
67
|
-
options: {
|
|
68
|
-
extName: output.extName,
|
|
69
|
-
templates: {
|
|
70
|
-
operations: _chunkBD7UJBXMcjs.Operations.templates,
|
|
71
|
-
mock: _chunkBD7UJBXMcjs.Mock.templates,
|
|
72
|
-
...templates
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
pre: [_pluginoas.pluginOasName, _plugints.pluginTsName, _pluginfaker.pluginFakerName],
|
|
76
|
-
resolvePath(baseName, pathMode, options2) {
|
|
77
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
78
|
-
const mode = _nullishCoalesce(pathMode, () => ( _core.FileManager.getMode(_path2.default.resolve(root, output.path))));
|
|
79
|
-
if (mode === "single") {
|
|
80
|
-
return _path2.default.resolve(root, output.path);
|
|
81
|
-
}
|
|
82
|
-
if (_optionalChain([options2, 'optionalAccess', _4 => _4.tag]) && _optionalChain([group, 'optionalAccess', _5 => _5.type]) === "tag") {
|
|
83
|
-
const tag = _transformers.camelCase.call(void 0, options2.tag);
|
|
84
|
-
return _path2.default.resolve(root, _utils.renderTemplate.call(void 0, template, { tag }), baseName);
|
|
85
|
-
}
|
|
86
|
-
return _path2.default.resolve(root, output.path, baseName);
|
|
87
|
-
},
|
|
88
|
-
resolveName(name, type) {
|
|
89
|
-
const resolvedName = _transformers.camelCase.call(void 0, name, {
|
|
90
|
-
suffix: type ? "handler" : void 0,
|
|
91
|
-
isFile: type === "file"
|
|
92
|
-
});
|
|
93
|
-
if (type) {
|
|
94
|
-
return _optionalChain([transformers, 'optionalAccess', _6 => _6.name, 'optionalCall', _7 => _7(resolvedName, type)]) || resolvedName;
|
|
95
|
-
}
|
|
96
|
-
return resolvedName;
|
|
97
|
-
},
|
|
98
|
-
async buildStart() {
|
|
99
|
-
const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
|
|
100
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
101
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
102
|
-
const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
|
|
103
|
-
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
104
|
-
oas,
|
|
105
|
-
pluginManager: this.pluginManager,
|
|
106
|
-
plugin: this.plugin,
|
|
107
|
-
contentType: swaggerPlugin.context.contentType,
|
|
108
|
-
exclude,
|
|
109
|
-
include,
|
|
110
|
-
override,
|
|
111
|
-
mode
|
|
112
|
-
});
|
|
113
|
-
const files = await operationGenerator.build();
|
|
114
|
-
await this.addFile(...files);
|
|
115
|
-
if (this.config.output.exportType) {
|
|
116
|
-
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
117
|
-
root,
|
|
118
|
-
output,
|
|
119
|
-
files: this.fileManager.files,
|
|
120
|
-
meta: {
|
|
121
|
-
pluginKey: this.plugin.key
|
|
122
|
-
},
|
|
123
|
-
logger: this.logger
|
|
124
|
-
});
|
|
125
|
-
await this.addFile(...barrelFiles);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
};
|
|
8
|
+
Object.defineProperty(exports, "pluginMsw", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunk6F4YUN2R_cjs.pluginMsw; }
|
|
129
11
|
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
12
|
+
Object.defineProperty(exports, "pluginMswName", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunk6F4YUN2R_cjs.pluginMswName; }
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=index.cjs.map
|
|
134
17
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,91 +1,8 @@
|
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
|
|
5
|
-
import { Operations, Mock } from './components.cjs';
|
|
6
|
-
import '@kubb/core/utils';
|
|
7
|
-
import '@kubb/oas';
|
|
8
|
-
import 'react';
|
|
9
|
-
import '@kubb/react/types';
|
|
10
|
-
|
|
11
|
-
type Templates = {
|
|
12
|
-
operations?: typeof Operations.templates | false;
|
|
13
|
-
mock?: typeof Mock.templates | false;
|
|
14
|
-
};
|
|
15
|
-
type Options = {
|
|
16
|
-
output?: {
|
|
17
|
-
/**
|
|
18
|
-
* Relative path to save the MSW mocks.
|
|
19
|
-
* When output is a file it will save all models inside that file else it will create a file per schema item.
|
|
20
|
-
* @default 'mocks'
|
|
21
|
-
*/
|
|
22
|
-
path: string;
|
|
23
|
-
/**
|
|
24
|
-
* Name to be used for the `export * as {{exportAs}} from './'`
|
|
25
|
-
*/
|
|
26
|
-
exportAs?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
29
|
-
*/
|
|
30
|
-
extName?: KubbFile.Extname;
|
|
31
|
-
/**
|
|
32
|
-
* Define what needs to exported, here you can also disable the export of barrel files
|
|
33
|
-
* @default `'barrel'`
|
|
34
|
-
*/
|
|
35
|
-
exportType?: 'barrel' | 'barrelNamed' | false;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Group the MSW mocks based on the provided name.
|
|
39
|
-
*/
|
|
40
|
-
group?: {
|
|
41
|
-
/**
|
|
42
|
-
* Tag will group based on the operation tag inside the Swagger file
|
|
43
|
-
*/
|
|
44
|
-
type: 'tag';
|
|
45
|
-
/**
|
|
46
|
-
* Relative path to save the grouped MSW mocks.
|
|
47
|
-
*
|
|
48
|
-
* `{{tag}}` will be replaced by the current tagName.
|
|
49
|
-
* @example `${output}/{{tag}}Controller` => `mocks/PetController`
|
|
50
|
-
* @default `${output}/{{tag}}Controller`
|
|
51
|
-
*/
|
|
52
|
-
output?: string;
|
|
53
|
-
/**
|
|
54
|
-
* Name to be used for the `export * as {{exportAs}} from './`
|
|
55
|
-
* @default `"{{tag}}Handlers"`
|
|
56
|
-
*/
|
|
57
|
-
exportAs?: string;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
61
|
-
*/
|
|
62
|
-
exclude?: Array<Exclude>;
|
|
63
|
-
/**
|
|
64
|
-
* Array containing include parameters to include tags/operations/methods/paths.
|
|
65
|
-
*/
|
|
66
|
-
include?: Array<Include>;
|
|
67
|
-
/**
|
|
68
|
-
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
69
|
-
*/
|
|
70
|
-
override?: Array<Override<ResolvedOptions>>;
|
|
71
|
-
transformers?: {
|
|
72
|
-
/**
|
|
73
|
-
* Customize the names based on the type that is provided by the plugin.
|
|
74
|
-
*/
|
|
75
|
-
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* Make it possible to override one of the templates
|
|
79
|
-
*/
|
|
80
|
-
templates?: Partial<Templates>;
|
|
81
|
-
};
|
|
82
|
-
type ResolvedOptions = {
|
|
83
|
-
extName: KubbFile.Extname | undefined;
|
|
84
|
-
templates: NonNullable<Templates>;
|
|
85
|
-
};
|
|
86
|
-
type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
2
|
+
import { O as Options, P as PluginMsw } from './types-B3_ksuJz.cjs';
|
|
3
|
+
import '@kubb/plugin-oas';
|
|
87
4
|
|
|
88
5
|
declare const pluginMswName = "plugin-msw";
|
|
89
6
|
declare const pluginMsw: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginMsw>;
|
|
90
7
|
|
|
91
|
-
export {
|
|
8
|
+
export { PluginMsw, pluginMsw, pluginMswName };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,91 +1,8 @@
|
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
|
|
5
|
-
import { Operations, Mock } from './components.js';
|
|
6
|
-
import '@kubb/core/utils';
|
|
7
|
-
import '@kubb/oas';
|
|
8
|
-
import 'react';
|
|
9
|
-
import '@kubb/react/types';
|
|
10
|
-
|
|
11
|
-
type Templates = {
|
|
12
|
-
operations?: typeof Operations.templates | false;
|
|
13
|
-
mock?: typeof Mock.templates | false;
|
|
14
|
-
};
|
|
15
|
-
type Options = {
|
|
16
|
-
output?: {
|
|
17
|
-
/**
|
|
18
|
-
* Relative path to save the MSW mocks.
|
|
19
|
-
* When output is a file it will save all models inside that file else it will create a file per schema item.
|
|
20
|
-
* @default 'mocks'
|
|
21
|
-
*/
|
|
22
|
-
path: string;
|
|
23
|
-
/**
|
|
24
|
-
* Name to be used for the `export * as {{exportAs}} from './'`
|
|
25
|
-
*/
|
|
26
|
-
exportAs?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
29
|
-
*/
|
|
30
|
-
extName?: KubbFile.Extname;
|
|
31
|
-
/**
|
|
32
|
-
* Define what needs to exported, here you can also disable the export of barrel files
|
|
33
|
-
* @default `'barrel'`
|
|
34
|
-
*/
|
|
35
|
-
exportType?: 'barrel' | 'barrelNamed' | false;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Group the MSW mocks based on the provided name.
|
|
39
|
-
*/
|
|
40
|
-
group?: {
|
|
41
|
-
/**
|
|
42
|
-
* Tag will group based on the operation tag inside the Swagger file
|
|
43
|
-
*/
|
|
44
|
-
type: 'tag';
|
|
45
|
-
/**
|
|
46
|
-
* Relative path to save the grouped MSW mocks.
|
|
47
|
-
*
|
|
48
|
-
* `{{tag}}` will be replaced by the current tagName.
|
|
49
|
-
* @example `${output}/{{tag}}Controller` => `mocks/PetController`
|
|
50
|
-
* @default `${output}/{{tag}}Controller`
|
|
51
|
-
*/
|
|
52
|
-
output?: string;
|
|
53
|
-
/**
|
|
54
|
-
* Name to be used for the `export * as {{exportAs}} from './`
|
|
55
|
-
* @default `"{{tag}}Handlers"`
|
|
56
|
-
*/
|
|
57
|
-
exportAs?: string;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
61
|
-
*/
|
|
62
|
-
exclude?: Array<Exclude>;
|
|
63
|
-
/**
|
|
64
|
-
* Array containing include parameters to include tags/operations/methods/paths.
|
|
65
|
-
*/
|
|
66
|
-
include?: Array<Include>;
|
|
67
|
-
/**
|
|
68
|
-
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
69
|
-
*/
|
|
70
|
-
override?: Array<Override<ResolvedOptions>>;
|
|
71
|
-
transformers?: {
|
|
72
|
-
/**
|
|
73
|
-
* Customize the names based on the type that is provided by the plugin.
|
|
74
|
-
*/
|
|
75
|
-
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* Make it possible to override one of the templates
|
|
79
|
-
*/
|
|
80
|
-
templates?: Partial<Templates>;
|
|
81
|
-
};
|
|
82
|
-
type ResolvedOptions = {
|
|
83
|
-
extName: KubbFile.Extname | undefined;
|
|
84
|
-
templates: NonNullable<Templates>;
|
|
85
|
-
};
|
|
86
|
-
type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
2
|
+
import { O as Options, P as PluginMsw } from './types-B3_ksuJz.js';
|
|
3
|
+
import '@kubb/plugin-oas';
|
|
87
4
|
|
|
88
5
|
declare const pluginMswName = "plugin-msw";
|
|
89
6
|
declare const pluginMsw: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginMsw>;
|
|
90
7
|
|
|
91
|
-
export {
|
|
8
|
+
export { PluginMsw, pluginMsw, pluginMswName };
|
package/dist/index.js
CHANGED
|
@@ -1,134 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./chunk-3KHLTEUD.js";
|
|
5
|
-
|
|
6
|
-
// src/plugin.ts
|
|
7
|
-
import path from "node: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 { pluginFakerName } from "@kubb/plugin-faker";
|
|
13
|
-
import { pluginTsName } from "@kubb/plugin-ts";
|
|
14
|
-
|
|
15
|
-
// src/OperationGenerator.tsx
|
|
16
|
-
import { OperationGenerator as Generator } from "@kubb/plugin-oas";
|
|
17
|
-
import { Oas } from "@kubb/plugin-oas/components";
|
|
18
|
-
import { App, createRoot } from "@kubb/react";
|
|
19
|
-
import { jsx } from "@kubb/react/jsx-runtime";
|
|
20
|
-
var OperationGenerator = class extends Generator {
|
|
21
|
-
async all(operations, operationsByMethod) {
|
|
22
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
23
|
-
const root = createRoot({
|
|
24
|
-
logger: pluginManager.logger
|
|
25
|
-
});
|
|
26
|
-
const templates = {
|
|
27
|
-
operations: Operations.templates,
|
|
28
|
-
mock: Mock.templates,
|
|
29
|
-
...this.options.templates
|
|
30
|
-
};
|
|
31
|
-
root.render(
|
|
32
|
-
/* @__PURE__ */ jsx(App, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsx(Oas, { oas, operations, generator: this, children: templates?.operations && /* @__PURE__ */ jsx(Operations.File, { templates: templates.operations }) }) })
|
|
33
|
-
);
|
|
34
|
-
return root.files;
|
|
35
|
-
}
|
|
36
|
-
async operation(operation, options) {
|
|
37
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
38
|
-
const root = createRoot({
|
|
39
|
-
logger: pluginManager.logger
|
|
40
|
-
});
|
|
41
|
-
const templates = {
|
|
42
|
-
handlers: Operations.templates,
|
|
43
|
-
mock: Mock.templates,
|
|
44
|
-
...options.templates
|
|
45
|
-
};
|
|
46
|
-
if (!templates?.mock) {
|
|
47
|
-
return [];
|
|
48
|
-
}
|
|
49
|
-
root.render(
|
|
50
|
-
/* @__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(Mock.File, { templates: templates.mock }) }) }) })
|
|
51
|
-
);
|
|
52
|
-
return root.files;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// src/plugin.ts
|
|
57
|
-
var pluginMswName = "plugin-msw";
|
|
58
|
-
var pluginMsw = createPlugin((options) => {
|
|
59
|
-
const { output = { path: "handlers" }, group, exclude = [], include, override = [], transformers = {}, templates } = options;
|
|
60
|
-
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
61
|
-
return {
|
|
62
|
-
name: pluginMswName,
|
|
63
|
-
output: {
|
|
64
|
-
exportType: "barrelNamed",
|
|
65
|
-
...output
|
|
66
|
-
},
|
|
67
|
-
options: {
|
|
68
|
-
extName: output.extName,
|
|
69
|
-
templates: {
|
|
70
|
-
operations: Operations.templates,
|
|
71
|
-
mock: Mock.templates,
|
|
72
|
-
...templates
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
pre: [pluginOasName, pluginTsName, pluginFakerName],
|
|
76
|
-
resolvePath(baseName, pathMode, options2) {
|
|
77
|
-
const root = path.resolve(this.config.root, this.config.output.path);
|
|
78
|
-
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
79
|
-
if (mode === "single") {
|
|
80
|
-
return path.resolve(root, output.path);
|
|
81
|
-
}
|
|
82
|
-
if (options2?.tag && group?.type === "tag") {
|
|
83
|
-
const tag = camelCase(options2.tag);
|
|
84
|
-
return path.resolve(root, renderTemplate(template, { tag }), baseName);
|
|
85
|
-
}
|
|
86
|
-
return path.resolve(root, output.path, baseName);
|
|
87
|
-
},
|
|
88
|
-
resolveName(name, type) {
|
|
89
|
-
const resolvedName = camelCase(name, {
|
|
90
|
-
suffix: type ? "handler" : void 0,
|
|
91
|
-
isFile: type === "file"
|
|
92
|
-
});
|
|
93
|
-
if (type) {
|
|
94
|
-
return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
95
|
-
}
|
|
96
|
-
return resolvedName;
|
|
97
|
-
},
|
|
98
|
-
async buildStart() {
|
|
99
|
-
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
100
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
101
|
-
const root = path.resolve(this.config.root, this.config.output.path);
|
|
102
|
-
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
103
|
-
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
104
|
-
oas,
|
|
105
|
-
pluginManager: this.pluginManager,
|
|
106
|
-
plugin: this.plugin,
|
|
107
|
-
contentType: swaggerPlugin.context.contentType,
|
|
108
|
-
exclude,
|
|
109
|
-
include,
|
|
110
|
-
override,
|
|
111
|
-
mode
|
|
112
|
-
});
|
|
113
|
-
const files = await operationGenerator.build();
|
|
114
|
-
await this.addFile(...files);
|
|
115
|
-
if (this.config.output.exportType) {
|
|
116
|
-
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
117
|
-
root,
|
|
118
|
-
output,
|
|
119
|
-
files: this.fileManager.files,
|
|
120
|
-
meta: {
|
|
121
|
-
pluginKey: this.plugin.key
|
|
122
|
-
},
|
|
123
|
-
logger: this.logger
|
|
124
|
-
});
|
|
125
|
-
await this.addFile(...barrelFiles);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
});
|
|
130
|
-
export {
|
|
131
|
-
pluginMsw,
|
|
132
|
-
pluginMswName
|
|
133
|
-
};
|
|
1
|
+
export { pluginMsw, pluginMswName } from './chunk-TW2VMA3H.js';
|
|
2
|
+
import './chunk-6M2QU6UL.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
134
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
|
|
2
|
+
import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
|
|
3
|
+
|
|
4
|
+
type Options = {
|
|
5
|
+
/**
|
|
6
|
+
* @default 'mocks'
|
|
7
|
+
*/
|
|
8
|
+
output?: Output;
|
|
9
|
+
/**
|
|
10
|
+
* Group the MSW mocks based on the provided name.
|
|
11
|
+
*/
|
|
12
|
+
group?: Group;
|
|
13
|
+
/**
|
|
14
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
15
|
+
*/
|
|
16
|
+
exclude?: Array<Exclude>;
|
|
17
|
+
/**
|
|
18
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
19
|
+
*/
|
|
20
|
+
include?: Array<Include>;
|
|
21
|
+
/**
|
|
22
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
23
|
+
*/
|
|
24
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
25
|
+
transformers?: {
|
|
26
|
+
/**
|
|
27
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
28
|
+
*/
|
|
29
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Create `handlers.ts` file with all handlers grouped by methods.
|
|
33
|
+
* @default `false`
|
|
34
|
+
*/
|
|
35
|
+
handlers?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Define some generators next to the msw generators
|
|
38
|
+
*/
|
|
39
|
+
generators?: Array<Generator<PluginMsw>>;
|
|
40
|
+
};
|
|
41
|
+
type ResolvedOptions = {
|
|
42
|
+
output: Output;
|
|
43
|
+
};
|
|
44
|
+
type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
45
|
+
|
|
46
|
+
export type { Options as O, PluginMsw as P };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
|
|
2
|
+
import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
|
|
3
|
+
|
|
4
|
+
type Options = {
|
|
5
|
+
/**
|
|
6
|
+
* @default 'mocks'
|
|
7
|
+
*/
|
|
8
|
+
output?: Output;
|
|
9
|
+
/**
|
|
10
|
+
* Group the MSW mocks based on the provided name.
|
|
11
|
+
*/
|
|
12
|
+
group?: Group;
|
|
13
|
+
/**
|
|
14
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
15
|
+
*/
|
|
16
|
+
exclude?: Array<Exclude>;
|
|
17
|
+
/**
|
|
18
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
19
|
+
*/
|
|
20
|
+
include?: Array<Include>;
|
|
21
|
+
/**
|
|
22
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
23
|
+
*/
|
|
24
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
25
|
+
transformers?: {
|
|
26
|
+
/**
|
|
27
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
28
|
+
*/
|
|
29
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Create `handlers.ts` file with all handlers grouped by methods.
|
|
33
|
+
* @default `false`
|
|
34
|
+
*/
|
|
35
|
+
handlers?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Define some generators next to the msw generators
|
|
38
|
+
*/
|
|
39
|
+
generators?: Array<Generator<PluginMsw>>;
|
|
40
|
+
};
|
|
41
|
+
type ResolvedOptions = {
|
|
42
|
+
output: Output;
|
|
43
|
+
};
|
|
44
|
+
type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
45
|
+
|
|
46
|
+
export type { Options as O, PluginMsw as P };
|