@kubb/plugin-msw 3.0.14 → 3.1.0
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/dist/{chunk-WQ5AMENV.cjs → chunk-23GXMYX6.cjs} +18 -11
- package/dist/chunk-23GXMYX6.cjs.map +1 -0
- package/dist/{chunk-YG3WMS3Q.js → chunk-LOYUDIPB.js} +14 -6
- package/dist/chunk-LOYUDIPB.js.map +1 -0
- package/dist/{chunk-CV3WD6X6.js → chunk-NS6CAQJT.js} +15 -8
- package/dist/chunk-NS6CAQJT.js.map +1 -0
- package/dist/{chunk-XLGN5MEF.cjs → chunk-YYEGKAGZ.cjs} +14 -6
- package/dist/chunk-YYEGKAGZ.cjs.map +1 -0
- package/dist/components.cjs +4 -4
- package/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/generators.cjs +4 -4
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +2 -2
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/{types-BaK4s79H.d.cts → types-DGHcSmpE.d.cts} +1 -0
- package/dist/{types-BaK4s79H.d.ts → types-DGHcSmpE.d.ts} +1 -0
- package/package.json +11 -11
- package/src/components/Mock.tsx +6 -2
- package/src/components/MockWithFaker.tsx +6 -2
- package/src/generators/__snapshots__/createPet.ts +3 -1
- package/src/generators/__snapshots__/deletePet.ts +3 -1
- package/src/generators/__snapshots__/getPets.ts +3 -1
- package/src/generators/__snapshots__/getPetsFaker.ts +4 -2
- package/src/generators/__snapshots__/showPetById.ts +3 -1
- package/src/generators/mswGenerator.tsx +2 -1
- package/src/plugin.ts +14 -6
- package/src/types.ts +1 -0
- package/dist/chunk-CV3WD6X6.js.map +0 -1
- package/dist/chunk-WQ5AMENV.cjs.map +0 -1
- package/dist/chunk-XLGN5MEF.cjs.map +0 -1
- package/dist/chunk-YG3WMS3Q.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkYYEGKAGZ_cjs = require('./chunk-YYEGKAGZ.cjs');
|
|
4
4
|
var utils = require('@kubb/core/utils');
|
|
5
5
|
var pluginFaker = require('@kubb/plugin-faker');
|
|
6
6
|
var pluginOas = require('@kubb/plugin-oas');
|
|
@@ -39,10 +39,11 @@ var mswGenerator = pluginOas.createReactGenerator({
|
|
|
39
39
|
};
|
|
40
40
|
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: mock.file.baseName, path: mock.file.path, meta: mock.file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
41
41
|
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["http"], path: "msw" }),
|
|
42
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["ResponseResolver"], isTypeOnly: true, path: "msw" }),
|
|
42
43
|
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [type.schemas.response.name], path: type.file.path, root: mock.file.path, isTypeOnly: true }),
|
|
43
44
|
parser === "faker" && faker.file && faker.schemas.response && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [faker.schemas.response.name], root: mock.file.path, path: faker.file.path }),
|
|
44
45
|
parser === "faker" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
45
|
-
|
|
46
|
+
chunkYYEGKAGZ_cjs.MockWithFaker,
|
|
46
47
|
{
|
|
47
48
|
name: mock.name,
|
|
48
49
|
typeName: type.schemas.response.name,
|
|
@@ -52,7 +53,7 @@ var mswGenerator = pluginOas.createReactGenerator({
|
|
|
52
53
|
}
|
|
53
54
|
),
|
|
54
55
|
parser === "data" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
55
|
-
|
|
56
|
+
chunkYYEGKAGZ_cjs.Mock,
|
|
56
57
|
{
|
|
57
58
|
name: mock.name,
|
|
58
59
|
typeName: type.schemas.response.name,
|
|
@@ -81,19 +82,25 @@ var pluginMsw = core.createPlugin((options) => {
|
|
|
81
82
|
name: pluginMswName,
|
|
82
83
|
options: {
|
|
83
84
|
output,
|
|
84
|
-
parser
|
|
85
|
+
parser,
|
|
86
|
+
group
|
|
85
87
|
},
|
|
86
88
|
pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, parser === "faker" ? pluginFaker.pluginFakerName : void 0].filter(Boolean),
|
|
87
89
|
resolvePath(baseName, pathMode, options2) {
|
|
88
90
|
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
89
91
|
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
90
|
-
if (options2?.tag && group?.type === "tag") {
|
|
91
|
-
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
92
|
-
return path__default.default.resolve(root, output.path, groupName({ group: transformers.camelCase(options2.tag) }), baseName);
|
|
93
|
-
}
|
|
94
92
|
if (mode === "single") {
|
|
95
93
|
return path__default.default.resolve(root, output.path);
|
|
96
94
|
}
|
|
95
|
+
if (options2?.group && group) {
|
|
96
|
+
const groupName = group?.name ? group.name : (ctx) => {
|
|
97
|
+
if (group?.type === "path") {
|
|
98
|
+
return `${ctx.group.split("/")[1]}`;
|
|
99
|
+
}
|
|
100
|
+
return `${transformers.camelCase(ctx.group)}Controller`;
|
|
101
|
+
};
|
|
102
|
+
return path__default.default.resolve(root, output.path, groupName({ group: options2.group }), baseName);
|
|
103
|
+
}
|
|
97
104
|
return path__default.default.resolve(root, output.path, baseName);
|
|
98
105
|
},
|
|
99
106
|
resolveName(name, type) {
|
|
@@ -151,7 +158,7 @@ var handlersGenerator = pluginOas.createReactGenerator({
|
|
|
151
158
|
const handlers = operations.map((operation) => `${getName(operation, { type: "function", pluginKey: plugin.key })}()`);
|
|
152
159
|
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.options.output?.banner, footer: plugin.options.output?.footer, children: [
|
|
153
160
|
imports,
|
|
154
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
161
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkYYEGKAGZ_cjs.Handlers, { name: "handlers", handlers })
|
|
155
162
|
] });
|
|
156
163
|
}
|
|
157
164
|
});
|
|
@@ -160,5 +167,5 @@ exports.handlersGenerator = handlersGenerator;
|
|
|
160
167
|
exports.mswGenerator = mswGenerator;
|
|
161
168
|
exports.pluginMsw = pluginMsw;
|
|
162
169
|
exports.pluginMswName = pluginMswName;
|
|
163
|
-
//# sourceMappingURL=chunk-
|
|
164
|
-
//# sourceMappingURL=chunk-
|
|
170
|
+
//# sourceMappingURL=chunk-23GXMYX6.cjs.map
|
|
171
|
+
//# sourceMappingURL=chunk-23GXMYX6.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/plugin.ts","../src/generators/handlersGenerator.tsx"],"names":["createReactGenerator","useApp","useOperationManager","pluginFakerName","pluginTsName","File","jsx","MockWithFaker","URLPath","Mock","createPlugin","transformers","pluginOasName","options","path","FileManager","camelCase","PluginManager","OperationGenerator","jsxs","Handlers"],"mappings":";;;;;;;;;;;;;;;;;;AASO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,MAAQ,EAAA;AAAA,QACN,OAAA,EAAS,EAAE,MAAA,EAAQ,MAAO;AAAA;AAC5B,QACEC,YAAkB,EAAA;AACtB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAYC,yBAAoB,EAAA;AAE7D,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,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port { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Mock, MockWithFaker } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n plugin: {\n options: { output, parser },\n },\n } = useApp<PluginMsw>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['http']} path=\"msw\" />\n <File.Import name={['ResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />\n {parser === 'faker' && faker.file && faker.schemas.response && (\n <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />\n )}\n\n {parser === 'faker' && (\n <MockWithFaker\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n url={new URLPath(operation.path).toURLPath()}\n />\n )}\n {parser === 'data' && (\n <Mock\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n url={new URLPath(operation.path).toURLPath()}\n />\n )}\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n parser = 'data',\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n group,\n },\n pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.group && group) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(root, output.path, groupName({ group: options.group }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<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\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\nimport { pluginMswName } from '../plugin.ts'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: plugin.key })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: plugin.key })\n const operationName = getName(operation, { pluginKey: plugin.key, type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => `${getName(operation, { type: 'function', pluginKey: plugin.key })}()`)\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -2,14 +2,18 @@ import { FunctionParams, File, Function } from '@kubb/react';
|
|
|
2
2
|
import { jsx } from '@kubb/react/jsx-runtime';
|
|
3
3
|
|
|
4
4
|
// src/components/Mock.tsx
|
|
5
|
-
function Mock({ name,
|
|
5
|
+
function Mock({ name, typeName, url, method }) {
|
|
6
6
|
const params = FunctionParams.factory({
|
|
7
7
|
data: {
|
|
8
|
-
type: typeName
|
|
8
|
+
type: `${typeName} | ((
|
|
9
|
+
info: Parameters<Parameters<typeof http.${method}>[1]>[0],
|
|
10
|
+
) => Response)`,
|
|
9
11
|
optional: true
|
|
10
12
|
}
|
|
11
13
|
});
|
|
12
14
|
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsx(Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('*${url}', function handler(info) {
|
|
15
|
+
if(typeof data === 'function') return data(info)
|
|
16
|
+
|
|
13
17
|
return new Response(JSON.stringify(data), {
|
|
14
18
|
headers: {
|
|
15
19
|
'Content-Type': 'application/json',
|
|
@@ -23,12 +27,16 @@ function Handlers({ name, handlers }) {
|
|
|
23
27
|
function MockWithFaker({ name, fakerName, typeName, url, method }) {
|
|
24
28
|
const params = FunctionParams.factory({
|
|
25
29
|
data: {
|
|
26
|
-
type: typeName
|
|
30
|
+
type: `${typeName} | ((
|
|
31
|
+
info: Parameters<Parameters<typeof http.${method}>[1]>[0],
|
|
32
|
+
) => Response)`,
|
|
27
33
|
optional: true
|
|
28
34
|
}
|
|
29
35
|
});
|
|
30
36
|
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsx(Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('*${url}', function handler(info) {
|
|
31
|
-
return
|
|
37
|
+
if(typeof data === 'function') return data(info)
|
|
38
|
+
|
|
39
|
+
return new Response(JSON.stringify(data || ${fakerName}(data)), {
|
|
32
40
|
headers: {
|
|
33
41
|
'Content-Type': 'application/json',
|
|
34
42
|
},
|
|
@@ -37,5 +45,5 @@ function MockWithFaker({ name, fakerName, typeName, url, method }) {
|
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
export { Handlers, Mock, MockWithFaker };
|
|
40
|
-
//# sourceMappingURL=chunk-
|
|
41
|
-
//# sourceMappingURL=chunk-
|
|
48
|
+
//# sourceMappingURL=chunk-LOYUDIPB.js.map
|
|
49
|
+
//# sourceMappingURL=chunk-LOYUDIPB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx","../src/components/MockWithFaker.tsx"],"names":["jsx","File","FunctionParams","Function"],"mappings":";;;;AAgBO,SAAS,KAAK,EAAE,IAAA,EAAM,QAAU,EAAA,GAAA,EAAK,QAA4B,EAAA;AACtE,EAAM,MAAA,MAAA,GAAS,eAAe,OAAQ,CAAA;AAAA,IACpC,IAAM,EAAA;AAAA,MACJ,IAAA,EAAM,GAAG,QAAQ,CAAA;AAAA,gDAAA,EAC2B,MAAM,CAAA;AAAA,oBAAA,CAAA;AAAA,MAElD,QAAU,EAAA;AAAA;AACZ,GACD,CAAA;AAED,EACE,uBAAA,GAAA,CAAC,KAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,cAAY,IAC/C,EAAA,QAAA,kBAAA,GAAA,CAAC,YAAS,IAAY,EAAA,MAAA,EAAM,MAAC,MAAQ,EAAA,MAAA,CAAO,eACzC,EAAA,QAAA,EAAA,CAAA,YAAA,EAAe,MAAM,CAAA,GAAA,EAAM,GAAG,CAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EASjC,CACF,EAAA,CAAA;AAEJ;AC7BO,SAAS,QAAS,CAAA,EAAE,IAAM,EAAA,QAAA,EAAsC,EAAA;AACrE,EACE,uBAAAA,IAACC,IAAK,CAAA,MAAA,EAAL,EAAY,IAAY,EAAA,WAAA,EAAW,MAAC,YAAY,EAAA,IAAA,EAC9C,0BAAgB,IAAI,CAAA,GAAA,EAAM,KAAK,SAAU,CAAA,QAAQ,EAAE,UAAW,CAAA,CAAA,CAAA,CAAA,EAAK,EAAE,CAAC,CACzE,SAAA,CAAA,EAAA,CAAA;AAEJ;ACFO,SAAS,cAAc,EAAE,IAAA,EAAM,WAAW,QAAU,EAAA,GAAA,EAAK,QAA4B,EAAA;AAC1F,EAAM,MAAA,MAAA,GAASC,eAAe,OAAQ,CAAA;AAAA,IACpC,IAAM,EAAA;AAAA,MACJ,IAAA,EAAM,GAAG,QAAQ,CAAA;AAAA,gDAAA,EAC2B,MAAM,CAAA;AAAA,oBAAA,CAAA;AAAA,MAElD,QAAU,EAAA;AAAA;AACZ,GACD,CAAA;AAED,EACE,uBAAAF,GAACC,CAAAA,IAAAA,CAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,YAAY,EAAA,IAAA,EAC/C,QAAAD,kBAAAA,GAAAA,CAACG,UAAA,EAAS,IAAA,EAAY,MAAM,EAAA,IAAA,EAAC,MAAQ,EAAA,MAAA,CAAO,eACzC,EAAA,QAAA,EAAA,CAAA,YAAA,EAAe,MAAM,CAAA,GAAA,EAAM,GAAG,CAAA;AAAA;;AAAA,+CAAA,EAGU,SAAS,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAMpD,CACF,EAAA,CAAA;AAEJ","file":"chunk-LOYUDIPB.js","sourcesContent":["import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function Mock({ name, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: `${typeName} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n","import { File } from '@kubb/react'\nimport type { ReactNode } from 'react'\n\ntype HandlersProps = {\n /**\n * Name of the function\n */\n name: string\n // custom\n handlers: string[]\n}\n\nexport function Handlers({ name, handlers }: HandlersProps): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}\n </File.Source>\n )\n}\n","import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: `${typeName} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data || ${fakerName}(data)), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MockWithFaker, Mock, Handlers } from './chunk-
|
|
1
|
+
import { MockWithFaker, Mock, Handlers } from './chunk-LOYUDIPB.js';
|
|
2
2
|
import { URLPath } from '@kubb/core/utils';
|
|
3
3
|
import { pluginFakerName } from '@kubb/plugin-faker';
|
|
4
4
|
import { createReactGenerator, pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
|
|
@@ -33,6 +33,7 @@ var mswGenerator = createReactGenerator({
|
|
|
33
33
|
};
|
|
34
34
|
return /* @__PURE__ */ jsxs(File, { baseName: mock.file.baseName, path: mock.file.path, meta: mock.file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
35
35
|
/* @__PURE__ */ jsx(File.Import, { name: ["http"], path: "msw" }),
|
|
36
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["ResponseResolver"], isTypeOnly: true, path: "msw" }),
|
|
36
37
|
/* @__PURE__ */ jsx(File.Import, { name: [type.schemas.response.name], path: type.file.path, root: mock.file.path, isTypeOnly: true }),
|
|
37
38
|
parser === "faker" && faker.file && faker.schemas.response && /* @__PURE__ */ jsx(File.Import, { name: [faker.schemas.response.name], root: mock.file.path, path: faker.file.path }),
|
|
38
39
|
parser === "faker" && /* @__PURE__ */ jsx(
|
|
@@ -75,19 +76,25 @@ var pluginMsw = createPlugin((options) => {
|
|
|
75
76
|
name: pluginMswName,
|
|
76
77
|
options: {
|
|
77
78
|
output,
|
|
78
|
-
parser
|
|
79
|
+
parser,
|
|
80
|
+
group
|
|
79
81
|
},
|
|
80
82
|
pre: [pluginOasName, pluginTsName, parser === "faker" ? pluginFakerName : void 0].filter(Boolean),
|
|
81
83
|
resolvePath(baseName, pathMode, options2) {
|
|
82
84
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
83
85
|
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
84
|
-
if (options2?.tag && group?.type === "tag") {
|
|
85
|
-
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
86
|
-
return path.resolve(root, output.path, groupName({ group: camelCase(options2.tag) }), baseName);
|
|
87
|
-
}
|
|
88
86
|
if (mode === "single") {
|
|
89
87
|
return path.resolve(root, output.path);
|
|
90
88
|
}
|
|
89
|
+
if (options2?.group && group) {
|
|
90
|
+
const groupName = group?.name ? group.name : (ctx) => {
|
|
91
|
+
if (group?.type === "path") {
|
|
92
|
+
return `${ctx.group.split("/")[1]}`;
|
|
93
|
+
}
|
|
94
|
+
return `${camelCase(ctx.group)}Controller`;
|
|
95
|
+
};
|
|
96
|
+
return path.resolve(root, output.path, groupName({ group: options2.group }), baseName);
|
|
97
|
+
}
|
|
91
98
|
return path.resolve(root, output.path, baseName);
|
|
92
99
|
},
|
|
93
100
|
resolveName(name, type) {
|
|
@@ -151,5 +158,5 @@ var handlersGenerator = createReactGenerator({
|
|
|
151
158
|
});
|
|
152
159
|
|
|
153
160
|
export { handlersGenerator, mswGenerator, pluginMsw, pluginMswName };
|
|
154
|
-
//# sourceMappingURL=chunk-
|
|
155
|
-
//# sourceMappingURL=chunk-
|
|
161
|
+
//# sourceMappingURL=chunk-NS6CAQJT.js.map
|
|
162
|
+
//# sourceMappingURL=chunk-NS6CAQJT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/plugin.ts","../src/generators/handlersGenerator.tsx"],"names":["pluginTsName","pluginFakerName","options","createReactGenerator","useApp","useOperationManager","jsx","File","jsxs"],"mappings":";;;;;;;;;;;;AASO,IAAM,eAAe,oBAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,MAAQ,EAAA;AAAA,QACN,OAAA,EAAS,EAAE,MAAA,EAAQ,MAAO;AAAA;AAC5B,QACE,MAAkB,EAAA;AACtB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAY,mBAAoB,EAAA;AAE7D,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS;AAAA,KACzB;AAEA,IAAA,MAAM,KAAQ,GAAA;AAAA,MACZ,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAAC,eAAe,GAAG,CAAA;AAAA,MACzD,OAAA,EAAS,UAAW,CAAA,SAAA,EAAW,EAAE,SAAA,EAAW,CAAC,eAAe,CAAA,EAAG,IAAM,EAAA,UAAA,EAAY;AAAA,KACnF;AAEA,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,IAAA,EAA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AAAA,IAAAA,CAAK,MAAL,EAAA,EAAqC,MAAM,CAAC,aAAa,CAAG,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,IAAA,EAAM,aAAc,CAAA,IAAA,EAAA,EAAhF,cAAc,IAAwE,CAAA;AAAA,KAChH,CAAA;AAED,IAAA,MAAM,WAAW,UAAW,CAAA,GAAA,CAAI,CAAC,SAAA,KAAc,GAAG,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,SAAW,EAAA,MAAA,CAAO,GAAI,EAAC,CAAC,CAAI,EAAA,CAAA,CAAA;AAErH,IACE,uBAAAC,KAACD,IAAA,EAAA,EAAK,UAAU,IAAK,CAAA,QAAA,EAAU,IAAM,EAAA,IAAA,CAAK,IAAM,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,MAAA,EAAQ,OAAO,OAAQ,CAAA,MAAA,EAAQ,QAAQ,MAAQ,EAAA,MAAA,CAAO,OAAQ,CAAA,MAAA,EAAQ,MACpI,EAAA,QAAA,EAAA;AAAA,MAAA,OAAA;AAAA,sBACDD,GAAAA,CAAC,QAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA;AAAA,KAClD,EAAA,CAAA;AAAA;AAGN,CAAC","file":"chunk-NS6CAQJT.js","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Mock, MockWithFaker } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n plugin: {\n options: { output, parser },\n },\n } = useApp<PluginMsw>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['http']} path=\"msw\" />\n <File.Import name={['ResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />\n {parser === 'faker' && faker.file && faker.schemas.response && (\n <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />\n )}\n\n {parser === 'faker' && (\n <MockWithFaker\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n url={new URLPath(operation.path).toURLPath()}\n />\n )}\n {parser === 'data' && (\n <Mock\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n url={new URLPath(operation.path).toURLPath()}\n />\n )}\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n parser = 'data',\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n group,\n },\n pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.group && group) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(root, output.path, groupName({ group: options.group }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<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\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\nimport { pluginMswName } from '../plugin.ts'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: plugin.key })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: plugin.key })\n const operationName = getName(operation, { pluginKey: plugin.key, type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => `${getName(operation, { type: 'function', pluginKey: plugin.key })}()`)\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -4,14 +4,18 @@ var react = require('@kubb/react');
|
|
|
4
4
|
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
5
5
|
|
|
6
6
|
// src/components/Mock.tsx
|
|
7
|
-
function Mock({ name,
|
|
7
|
+
function Mock({ name, typeName, url, method }) {
|
|
8
8
|
const params = react.FunctionParams.factory({
|
|
9
9
|
data: {
|
|
10
|
-
type: typeName
|
|
10
|
+
type: `${typeName} | ((
|
|
11
|
+
info: Parameters<Parameters<typeof http.${method}>[1]>[0],
|
|
12
|
+
) => Response)`,
|
|
11
13
|
optional: true
|
|
12
14
|
}
|
|
13
15
|
});
|
|
14
16
|
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('*${url}', function handler(info) {
|
|
17
|
+
if(typeof data === 'function') return data(info)
|
|
18
|
+
|
|
15
19
|
return new Response(JSON.stringify(data), {
|
|
16
20
|
headers: {
|
|
17
21
|
'Content-Type': 'application/json',
|
|
@@ -25,12 +29,16 @@ function Handlers({ name, handlers }) {
|
|
|
25
29
|
function MockWithFaker({ name, fakerName, typeName, url, method }) {
|
|
26
30
|
const params = react.FunctionParams.factory({
|
|
27
31
|
data: {
|
|
28
|
-
type: typeName
|
|
32
|
+
type: `${typeName} | ((
|
|
33
|
+
info: Parameters<Parameters<typeof http.${method}>[1]>[0],
|
|
34
|
+
) => Response)`,
|
|
29
35
|
optional: true
|
|
30
36
|
}
|
|
31
37
|
});
|
|
32
38
|
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('*${url}', function handler(info) {
|
|
33
|
-
return
|
|
39
|
+
if(typeof data === 'function') return data(info)
|
|
40
|
+
|
|
41
|
+
return new Response(JSON.stringify(data || ${fakerName}(data)), {
|
|
34
42
|
headers: {
|
|
35
43
|
'Content-Type': 'application/json',
|
|
36
44
|
},
|
|
@@ -41,5 +49,5 @@ function MockWithFaker({ name, fakerName, typeName, url, method }) {
|
|
|
41
49
|
exports.Handlers = Handlers;
|
|
42
50
|
exports.Mock = Mock;
|
|
43
51
|
exports.MockWithFaker = MockWithFaker;
|
|
44
|
-
//# sourceMappingURL=chunk-
|
|
45
|
-
//# sourceMappingURL=chunk-
|
|
52
|
+
//# sourceMappingURL=chunk-YYEGKAGZ.cjs.map
|
|
53
|
+
//# sourceMappingURL=chunk-YYEGKAGZ.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx","../src/components/MockWithFaker.tsx"],"names":["FunctionParams","jsx","File","Function"],"mappings":";;;;;;AAgBO,SAAS,KAAK,EAAE,IA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,CAAA;AAED,EACE,uBAAAC,cAACC,CAAAA,UAAAA,CAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,YAAY,EAAA,IAAA,EAC/C,QAAAD,kBAAAA,cAAAA,CAACE,gBAAA,EAAS,IAAA,EAAY,MAAM,EAAA,IAAA,EAAC,MAAQ,EAAA,MAAA,CAAO,eACzC,EAAA,QAAA,EAAA,CAAA,YAAA,EAAe,MAAM,CAAA,GAAA,EAAM,GAAG,CAAA;AAAA;;AAAA,+CAAA,EAGU,SAAS,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAMpD,CACF,EAAA,CAAA;AAEJ","file":"chunk-YYEGKAGZ.cjs","sourcesContent":["import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function Mock({ name, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: `${typeName} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n","import { File } from '@kubb/react'\nimport type { ReactNode } from 'react'\n\ntype HandlersProps = {\n /**\n * Name of the function\n */\n name: string\n // custom\n handlers: string[]\n}\n\nexport function Handlers({ name, handlers }: HandlersProps): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}\n </File.Source>\n )\n}\n","import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: `${typeName} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data || ${fakerName}(data)), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n"]}
|
package/dist/components.cjs
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkYYEGKAGZ_cjs = require('./chunk-YYEGKAGZ.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "Handlers", {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
9
|
+
get: function () { return chunkYYEGKAGZ_cjs.Handlers; }
|
|
10
10
|
});
|
|
11
11
|
Object.defineProperty(exports, "Mock", {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkYYEGKAGZ_cjs.Mock; }
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(exports, "MockWithFaker", {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
17
|
+
get: function () { return chunkYYEGKAGZ_cjs.MockWithFaker; }
|
|
18
18
|
});
|
|
19
19
|
//# sourceMappingURL=components.cjs.map
|
|
20
20
|
//# sourceMappingURL=components.cjs.map
|
package/dist/components.d.cts
CHANGED
|
@@ -11,7 +11,7 @@ type Props$1 = {
|
|
|
11
11
|
url: string;
|
|
12
12
|
method: HttpMethod;
|
|
13
13
|
};
|
|
14
|
-
declare function Mock({ name,
|
|
14
|
+
declare function Mock({ name, typeName, url, method }: Props$1): ReactNode;
|
|
15
15
|
|
|
16
16
|
type HandlersProps = {
|
|
17
17
|
/**
|
package/dist/components.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ type Props$1 = {
|
|
|
11
11
|
url: string;
|
|
12
12
|
method: HttpMethod;
|
|
13
13
|
};
|
|
14
|
-
declare function Mock({ name,
|
|
14
|
+
declare function Mock({ name, typeName, url, method }: Props$1): ReactNode;
|
|
15
15
|
|
|
16
16
|
type HandlersProps = {
|
|
17
17
|
/**
|
package/dist/components.js
CHANGED
package/dist/generators.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var chunk23GXMYX6_cjs = require('./chunk-23GXMYX6.cjs');
|
|
4
|
+
require('./chunk-YYEGKAGZ.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "handlersGenerator", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunk23GXMYX6_cjs.handlersGenerator; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "mswGenerator", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunk23GXMYX6_cjs.mswGenerator; }
|
|
15
15
|
});
|
|
16
16
|
//# sourceMappingURL=generators.cjs.map
|
|
17
17
|
//# sourceMappingURL=generators.cjs.map
|
package/dist/generators.d.cts
CHANGED
package/dist/generators.d.ts
CHANGED
package/dist/generators.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { handlersGenerator, mswGenerator } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
export { handlersGenerator, mswGenerator } from './chunk-NS6CAQJT.js';
|
|
2
|
+
import './chunk-LOYUDIPB.js';
|
|
3
3
|
//# sourceMappingURL=generators.js.map
|
|
4
4
|
//# sourceMappingURL=generators.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var chunk23GXMYX6_cjs = require('./chunk-23GXMYX6.cjs');
|
|
4
|
+
require('./chunk-YYEGKAGZ.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "pluginMsw", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunk23GXMYX6_cjs.pluginMsw; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "pluginMswName", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunk23GXMYX6_cjs.pluginMswName; }
|
|
15
15
|
});
|
|
16
16
|
//# sourceMappingURL=index.cjs.map
|
|
17
17
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-msw",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Generator swagger",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -74,21 +74,21 @@
|
|
|
74
74
|
"!/**/__tests__/**"
|
|
75
75
|
],
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@kubb/core": "3.0
|
|
78
|
-
"@kubb/fs": "3.0
|
|
79
|
-
"@kubb/oas": "3.0
|
|
80
|
-
"@kubb/plugin-faker": "3.0
|
|
81
|
-
"@kubb/plugin-oas": "3.0
|
|
82
|
-
"@kubb/plugin-ts": "3.0
|
|
83
|
-
"@kubb/react": "3.0
|
|
77
|
+
"@kubb/core": "3.1.0",
|
|
78
|
+
"@kubb/fs": "3.1.0",
|
|
79
|
+
"@kubb/oas": "3.1.0",
|
|
80
|
+
"@kubb/plugin-faker": "3.1.0",
|
|
81
|
+
"@kubb/plugin-oas": "3.1.0",
|
|
82
|
+
"@kubb/plugin-ts": "3.1.0",
|
|
83
|
+
"@kubb/react": "3.1.0"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@types/react": "^18.3.
|
|
86
|
+
"@types/react": "^18.3.13",
|
|
87
87
|
"react": "^18.3.1",
|
|
88
88
|
"tsup": "^8.3.5",
|
|
89
89
|
"typescript": "^5.7.2",
|
|
90
|
-
"@kubb/config-ts": "3.0
|
|
91
|
-
"@kubb/config-tsup": "3.0
|
|
90
|
+
"@kubb/config-ts": "3.1.0",
|
|
91
|
+
"@kubb/config-tsup": "3.1.0"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
94
|
"@kubb/react": "^3.0.0"
|
package/src/components/Mock.tsx
CHANGED
|
@@ -14,10 +14,12 @@ type Props = {
|
|
|
14
14
|
method: HttpMethod
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export function Mock({ name,
|
|
17
|
+
export function Mock({ name, typeName, url, method }: Props): ReactNode {
|
|
18
18
|
const params = FunctionParams.factory({
|
|
19
19
|
data: {
|
|
20
|
-
type: typeName
|
|
20
|
+
type: `${typeName} | ((
|
|
21
|
+
info: Parameters<Parameters<typeof http.${method}>[1]>[0],
|
|
22
|
+
) => Response)`,
|
|
21
23
|
optional: true,
|
|
22
24
|
},
|
|
23
25
|
})
|
|
@@ -26,6 +28,8 @@ export function Mock({ name, fakerName, typeName, url, method }: Props): ReactNo
|
|
|
26
28
|
<File.Source name={name} isIndexable isExportable>
|
|
27
29
|
<Function name={name} export params={params.toConstructor()}>
|
|
28
30
|
{`return http.${method}('*${url}', function handler(info) {
|
|
31
|
+
if(typeof data === 'function') return data(info)
|
|
32
|
+
|
|
29
33
|
return new Response(JSON.stringify(data), {
|
|
30
34
|
headers: {
|
|
31
35
|
'Content-Type': 'application/json',
|
|
@@ -17,7 +17,9 @@ type Props = {
|
|
|
17
17
|
export function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode {
|
|
18
18
|
const params = FunctionParams.factory({
|
|
19
19
|
data: {
|
|
20
|
-
type: typeName
|
|
20
|
+
type: `${typeName} | ((
|
|
21
|
+
info: Parameters<Parameters<typeof http.${method}>[1]>[0],
|
|
22
|
+
) => Response)`,
|
|
21
23
|
optional: true,
|
|
22
24
|
},
|
|
23
25
|
})
|
|
@@ -26,7 +28,9 @@ export function MockWithFaker({ name, fakerName, typeName, url, method }: Props)
|
|
|
26
28
|
<File.Source name={name} isIndexable isExportable>
|
|
27
29
|
<Function name={name} export params={params.toConstructor()}>
|
|
28
30
|
{`return http.${method}('*${url}', function handler(info) {
|
|
29
|
-
return
|
|
31
|
+
if(typeof data === 'function') return data(info)
|
|
32
|
+
|
|
33
|
+
return new Response(JSON.stringify(data || ${fakerName}(data)), {
|
|
30
34
|
headers: {
|
|
31
35
|
'Content-Type': 'application/json',
|
|
32
36
|
},
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { http } from "msw";
|
|
2
2
|
|
|
3
|
-
export function createPets(data?: CreatePetsMutationResponse) {
|
|
3
|
+
export function createPets(data?: CreatePetsMutationResponse | ((info: Parameters<Parameters<typeof http.post>[1]>[0]) => Response)) {
|
|
4
4
|
return http.post("*/pets", function handler(info) {
|
|
5
|
+
if (typeof data === "function")
|
|
6
|
+
return data(info);
|
|
5
7
|
return new Response(JSON.stringify(data), {
|
|
6
8
|
headers: {
|
|
7
9
|
"Content-Type": "application/json",
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { http } from "msw";
|
|
2
2
|
|
|
3
|
-
export function deletePetsPetid(data?: DeletePetsPetidMutationResponse) {
|
|
3
|
+
export function deletePetsPetid(data?: DeletePetsPetidMutationResponse | ((info: Parameters<Parameters<typeof http.delete>[1]>[0]) => Response)) {
|
|
4
4
|
return http.delete("*/pets/:petId", function handler(info) {
|
|
5
|
+
if (typeof data === "function")
|
|
6
|
+
return data(info);
|
|
5
7
|
return new Response(JSON.stringify(data), {
|
|
6
8
|
headers: {
|
|
7
9
|
"Content-Type": "application/json",
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { http } from "msw";
|
|
2
2
|
|
|
3
|
-
export function listPets(data?: ListPetsQueryResponse) {
|
|
3
|
+
export function listPets(data?: ListPetsQueryResponse | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Response)) {
|
|
4
4
|
return http.get("*/pets", function handler(info) {
|
|
5
|
+
if (typeof data === "function")
|
|
6
|
+
return data(info);
|
|
5
7
|
return new Response(JSON.stringify(data), {
|
|
6
8
|
headers: {
|
|
7
9
|
"Content-Type": "application/json",
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { http } from "msw";
|
|
2
2
|
|
|
3
|
-
export function listPets(data?: ListPetsQueryResponse) {
|
|
3
|
+
export function listPets(data?: ListPetsQueryResponse | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Response)) {
|
|
4
4
|
return http.get("*/pets", function handler(info) {
|
|
5
|
-
|
|
5
|
+
if (typeof data === "function")
|
|
6
|
+
return data(info);
|
|
7
|
+
return new Response(JSON.stringify(data || listPetsQueryResponse(data)), {
|
|
6
8
|
headers: {
|
|
7
9
|
"Content-Type": "application/json",
|
|
8
10
|
},
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { http } from "msw";
|
|
2
2
|
|
|
3
|
-
export function showPetById(data?: ShowPetByIdQueryResponse) {
|
|
3
|
+
export function showPetById(data?: ShowPetByIdQueryResponse | ((info: Parameters<Parameters<typeof http.get>[1]>[0]) => Response)) {
|
|
4
4
|
return http.get("*/pets/:petId", function handler(info) {
|
|
5
|
+
if (typeof data === "function")
|
|
6
|
+
return data(info);
|
|
5
7
|
return new Response(JSON.stringify(data), {
|
|
6
8
|
headers: {
|
|
7
9
|
"Content-Type": "application/json",
|
|
@@ -34,7 +34,8 @@ export const mswGenerator = createReactGenerator<PluginMsw>({
|
|
|
34
34
|
|
|
35
35
|
return (
|
|
36
36
|
<File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
37
|
-
<File.Import name={['http']} path=
|
|
37
|
+
<File.Import name={['http']} path="msw" />
|
|
38
|
+
<File.Import name={['ResponseResolver']} isTypeOnly path="msw" />
|
|
38
39
|
<File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />
|
|
39
40
|
{parser === 'faker' && faker.file && faker.schemas.response && (
|
|
40
41
|
<File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />
|
package/src/plugin.ts
CHANGED
|
@@ -32,18 +32,13 @@ export const pluginMsw = createPlugin<PluginMsw>((options) => {
|
|
|
32
32
|
options: {
|
|
33
33
|
output,
|
|
34
34
|
parser,
|
|
35
|
+
group,
|
|
35
36
|
},
|
|
36
37
|
pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),
|
|
37
38
|
resolvePath(baseName, pathMode, options) {
|
|
38
39
|
const root = path.resolve(this.config.root, this.config.output.path)
|
|
39
40
|
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
|
|
40
41
|
|
|
41
|
-
if (options?.tag && group?.type === 'tag') {
|
|
42
|
-
const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`
|
|
43
|
-
|
|
44
|
-
return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
42
|
if (mode === 'single') {
|
|
48
43
|
/**
|
|
49
44
|
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
@@ -52,6 +47,19 @@ export const pluginMsw = createPlugin<PluginMsw>((options) => {
|
|
|
52
47
|
return path.resolve(root, output.path)
|
|
53
48
|
}
|
|
54
49
|
|
|
50
|
+
if (options?.group && group) {
|
|
51
|
+
const groupName: Group['name'] = group?.name
|
|
52
|
+
? group.name
|
|
53
|
+
: (ctx) => {
|
|
54
|
+
if (group?.type === 'path') {
|
|
55
|
+
return `${ctx.group.split('/')[1]}`
|
|
56
|
+
}
|
|
57
|
+
return `${camelCase(ctx.group)}Controller`
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return path.resolve(root, output.path, groupName({ group: options.group }), baseName)
|
|
61
|
+
}
|
|
62
|
+
|
|
55
63
|
return path.resolve(root, output.path, baseName)
|
|
56
64
|
},
|
|
57
65
|
resolveName(name, type) {
|
package/src/types.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/plugin.ts","../src/generators/handlersGenerator.tsx"],"names":["pluginTsName","pluginFakerName","options","createReactGenerator","useApp","useOperationManager","jsx","File","jsxs"],"mappings":";;;;;;;;;;;;AASO,IAAM,eAAe,oBAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,MAAQ,EAAA;AAAA,QACN,OAAA,EAAS,EAAE,MAAA,EAAQ,MAAO;AAAA;AAC5B,QACE,MAAkB,EAAA;AACtB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAY,mBAAoB,EAAA;AAE7D,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS;AAAA,KACzB;AAEA,IAAA,MAAM,KAAQ,GAAA;AAAA,MACZ,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAAC,eAAe,GAAG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,CAAA;AAAA,KAChH,CAAA;AAED,IAAA,MAAM,WAAW,UAAW,CAAA,GAAA,CAAI,CAAC,SAAA,KAAc,GAAG,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,SAAW,EAAA,MAAA,CAAO,GAAI,EAAC,CAAC,CAAI,EAAA,CAAA,CAAA;AAErH,IACE,uBAAAC,KAACD,IAAA,EAAA,EAAK,UAAU,IAAK,CAAA,QAAA,EAAU,IAAM,EAAA,IAAA,CAAK,IAAM,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,MAAA,EAAQ,OAAO,OAAQ,CAAA,MAAA,EAAQ,QAAQ,MAAQ,EAAA,MAAA,CAAO,OAAQ,CAAA,MAAA,EAAQ,MACpI,EAAA,QAAA,EAAA;AAAA,MAAA,OAAA;AAAA,sBACDD,GAAAA,CAAC,QAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA;AAAA,KAClD,EAAA,CAAA;AAAA;AAGN,CAAC","file":"chunk-CV3WD6X6.js","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Mock, MockWithFaker } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n plugin: {\n options: { output, parser },\n },\n } = useApp<PluginMsw>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['http']} path={'msw'} />\n <File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />\n {parser === 'faker' && faker.file && faker.schemas.response && (\n <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />\n )}\n\n {parser === 'faker' && (\n <MockWithFaker\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n url={new URLPath(operation.path).toURLPath()}\n />\n )}\n {parser === 'data' && (\n <Mock\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n url={new URLPath(operation.path).toURLPath()}\n />\n )}\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n parser = 'data',\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n },\n pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\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 return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<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\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\nimport { pluginMswName } from '../plugin.ts'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: plugin.key })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: plugin.key })\n const operationName = getName(operation, { pluginKey: plugin.key, type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => `${getName(operation, { type: 'function', pluginKey: plugin.key })}()`)\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/plugin.ts","../src/generators/handlersGenerator.tsx"],"names":["createReactGenerator","useApp","useOperationManager","pluginFakerName","pluginTsName","File","jsx","MockWithFaker","URLPath","Mock","createPlugin","transformers","pluginOasName","options","path","FileManager","camelCase","PluginManager","OperationGenerator","jsxs","Handlers"],"mappings":";;;;;;;;;;;;;;;;;;AASO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,MAAQ,EAAA;AAAA,QACN,OAAA,EAAS,EAAE,MAAA,EAAQ,MAAO;AAAA;AAC5B,QACEC,YAAkB,EAAA;AACtB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAYC,yBAAoB,EAAA;AAE7D,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS;AAAA,KACzB;AAEA,IAAA,MAAM,KAAQ,GAAA;AAAA,MACZ,IAAA,EAAM,QA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a,CAAG,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,IAAA,EAAM,aAAc,CAAA,IAAA,EAAA,EAAhF,cAAc,IAAwE,CAAA;AAAA,KAChH,CAAA;AAED,IAAA,MAAM,WAAW,UAAW,CAAA,GAAA,CAAI,CAAC,SAAA,KAAc,GAAG,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,SAAW,EAAA,MAAA,CAAO,GAAI,EAAC,CAAC,CAAI,EAAA,CAAA,CAAA;AAErH,IACE,uBAAAc,gBAACd,UAAA,EAAA,EAAK,UAAU,IAAK,CAAA,QAAA,EAAU,IAAM,EAAA,IAAA,CAAK,IAAM,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,MAAA,EAAQ,OAAO,OAAQ,CAAA,MAAA,EAAQ,QAAQ,MAAQ,EAAA,MAAA,CAAO,OAAQ,CAAA,MAAA,EAAQ,MACpI,EAAA,QAAA,EAAA;AAAA,MAAA,OAAA;AAAA,sBACDC,cAAAA,CAACc,0BAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA;AAAA,KAClD,EAAA,CAAA;AAAA;AAGN,CAAC","file":"chunk-WQ5AMENV.cjs","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Mock, MockWithFaker } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n plugin: {\n options: { output, parser },\n },\n } = useApp<PluginMsw>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['http']} path={'msw'} />\n <File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />\n {parser === 'faker' && faker.file && faker.schemas.response && (\n <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />\n )}\n\n {parser === 'faker' && (\n <MockWithFaker\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n url={new URLPath(operation.path).toURLPath()}\n />\n )}\n {parser === 'data' && (\n <Mock\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n url={new URLPath(operation.path).toURLPath()}\n />\n )}\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n parser = 'data',\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n },\n pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\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 return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<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\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\nimport { pluginMswName } from '../plugin.ts'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: plugin.key })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: plugin.key })\n const operationName = getName(operation, { pluginKey: plugin.key, type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => `${getName(operation, { type: 'function', pluginKey: plugin.key })}()`)\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx","../src/components/MockWithFaker.tsx"],"names":["FunctionParams","jsx","File","Function"],"mappings":";;;;;;AAgBO,SAAS,KAAK,EAAE,IAAA,EAAM,WAAW,QAAU,EAAA,GAAA,EAAK,QAA4B,EAAA;AACjF,EAAM,MAAA,MAAA,GAASA,qBAAe,OAAQ,CAAA;AAAA,IACpC,IAAM,EAAA;AAAA,MACJ,IAAM,EAAA,QAAA;AAAA,MACN,QAAU,EAAA;AAAA;AACZ,GACD,CAAA;AAED,EACE,uBAAAC,cAAA,CAACC,WAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,cAAY,IAC/C,EAAA,QAAA,kBAAAD,cAAA,CAACE,kBAAS,IAAY,EAAA,MAAA,EAAM,MAAC,MAAQ,EAAA,MAAA,CAAO,eACzC,EAAA,QAAA,EAAA,CAAA,YAAA,EAAe,MAAM,CAAA,GAAA,EAAM,GAAG,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAOjC,CACF,EAAA,CAAA;AAEJ;ACzBO,SAAS,QAAS,CAAA,EAAE,IAAM,EAAA,QAAA,EAAsC,EAAA;AACrE,EACE,uBAAAF,eAACC,UAAK,CAAA,MAAA,EAAL,EAAY,IAAY,EAAA,WAAA,EAAW,MAAC,YAAY,EAAA,IAAA,EAC9C,0BAAgB,IAAI,CAAA,GAAA,EAAM,KAAK,SAAU,CAAA,QAAQ,EAAE,UAAW,CAAA,CAAA,CAAA,CAAA,EAAK,EAAE,CAAC,CACzE,SAAA,CAAA,EAAA,CAAA;AAEJ;ACFO,SAAS,cAAc,EAAE,IAAA,EAAM,WAAW,QAAU,EAAA,GAAA,EAAK,QAA4B,EAAA;AAC1F,EAAM,MAAA,MAAA,GAASF,qBAAe,OAAQ,CAAA;AAAA,IACpC,IAAM,EAAA;AAAA,MACJ,IAAM,EAAA,QAAA;AAAA,MACN,QAAU,EAAA;AAAA;AACZ,GACD,CAAA;AAED,EACE,uBAAAC,cAACC,CAAAA,UAAAA,CAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,YAAY,EAAA,IAAA,EAC/C,QAAAD,kBAAAA,cAAAA,CAACE,gBAAA,EAAS,IAAA,EAAY,MAAM,EAAA,IAAA,EAAC,MAAQ,EAAA,MAAA,CAAO,eACzC,EAAA,QAAA,EAAA,CAAA,YAAA,EAAe,MAAM,CAAA,GAAA,EAAM,GAAG,CAAA;AAAA,uCAAA,EACE,SAAS,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAM5C,CACF,EAAA,CAAA;AAEJ","file":"chunk-XLGN5MEF.cjs","sourcesContent":["import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function Mock({ name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: typeName,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n return new Response(JSON.stringify(data), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n","import { File } from '@kubb/react'\nimport type { ReactNode } from 'react'\n\ntype HandlersProps = {\n /**\n * Name of the function\n */\n name: string\n // custom\n handlers: string[]\n}\n\nexport function Handlers({ name, handlers }: HandlersProps): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}\n </File.Source>\n )\n}\n","import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: typeName,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n return new Response(JSON.stringify(${fakerName}(data)), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx","../src/components/MockWithFaker.tsx"],"names":["jsx","File","FunctionParams","Function"],"mappings":";;;;AAgBO,SAAS,KAAK,EAAE,IAAA,EAAM,WAAW,QAAU,EAAA,GAAA,EAAK,QAA4B,EAAA;AACjF,EAAM,MAAA,MAAA,GAAS,eAAe,OAAQ,CAAA;AAAA,IACpC,IAAM,EAAA;AAAA,MACJ,IAAM,EAAA,QAAA;AAAA,MACN,QA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AA,uCAAA,EACE,SAAS,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAM5C,CACF,EAAA,CAAA;AAEJ","file":"chunk-YG3WMS3Q.js","sourcesContent":["import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function Mock({ name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: typeName,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n return new Response(JSON.stringify(data), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n","import { File } from '@kubb/react'\nimport type { ReactNode } from 'react'\n\ntype HandlersProps = {\n /**\n * Name of the function\n */\n name: string\n // custom\n handlers: string[]\n}\n\nexport function Handlers({ name, handlers }: HandlersProps): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}\n </File.Source>\n )\n}\n","import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: typeName,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n return new Response(JSON.stringify(${fakerName}(data)), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n"]}
|