@kubb/plugin-msw 3.0.0-beta.9 → 3.0.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-IRCHRJU5.js → chunk-IUWTMC3G.js} +3 -3
- package/dist/chunk-IUWTMC3G.js.map +1 -0
- package/dist/{chunk-U4NEGWMP.cjs → chunk-QXK7PR6Z.cjs} +3 -3
- package/dist/chunk-QXK7PR6Z.cjs.map +1 -0
- package/dist/chunk-XLGN5MEF.cjs.map +1 -1
- package/dist/chunk-YG3WMS3Q.js.map +1 -1
- package/dist/generators.cjs +3 -3
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{types-DFygD4LB.d.cts → types-BaK4s79H.d.cts} +1 -1
- package/dist/{types-DFygD4LB.d.ts → types-BaK4s79H.d.ts} +1 -1
- package/package.json +12 -12
- package/src/generators/mswGenerator.tsx +3 -1
- package/src/types.ts +1 -1
- package/dist/chunk-IRCHRJU5.js.map +0 -1
- package/dist/chunk-U4NEGWMP.cjs.map +0 -1
|
@@ -34,7 +34,7 @@ var mswGenerator = createReactGenerator({
|
|
|
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
36
|
/* @__PURE__ */ jsx(File.Import, { name: [type.schemas.response.name], path: type.file.path, root: mock.file.path, isTypeOnly: true }),
|
|
37
|
-
faker.file && faker.schemas.response && /* @__PURE__ */ jsx(File.Import, { name: [faker.schemas.response.name], root: mock.file.path, path: faker.file.path }),
|
|
37
|
+
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
38
|
parser === "faker" && /* @__PURE__ */ jsx(
|
|
39
39
|
MockWithFaker,
|
|
40
40
|
{
|
|
@@ -151,5 +151,5 @@ var handlersGenerator = createReactGenerator({
|
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
export { handlersGenerator, mswGenerator, pluginMsw, pluginMswName };
|
|
154
|
-
//# sourceMappingURL=chunk-
|
|
155
|
-
//# sourceMappingURL=chunk-
|
|
154
|
+
//# sourceMappingURL=chunk-IUWTMC3G.js.map
|
|
155
|
+
//# sourceMappingURL=chunk-IUWTMC3G.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,CAA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KAAc,GAAG,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,SAAW,EAAA,CAAC,aAAa,CAAE,EAAC,CAAC,CAAI,EAAA,CAAA,CAAA;AAE1H,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-IUWTMC3G.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: [pluginMswName] })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: [pluginMswName] })\n const operationName = getName(operation, { pluginKey: [pluginMswName], 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: [pluginMswName] })}()`)\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"]}
|
|
@@ -40,7 +40,7 @@ var mswGenerator = pluginOas.createReactGenerator({
|
|
|
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
42
|
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [type.schemas.response.name], path: type.file.path, root: mock.file.path, isTypeOnly: true }),
|
|
43
|
-
faker.file && faker.schemas.response && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [faker.schemas.response.name], root: mock.file.path, path: faker.file.path }),
|
|
43
|
+
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
44
|
parser === "faker" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
45
45
|
chunkXLGN5MEF_cjs.MockWithFaker,
|
|
46
46
|
{
|
|
@@ -160,5 +160,5 @@ exports.handlersGenerator = handlersGenerator;
|
|
|
160
160
|
exports.mswGenerator = mswGenerator;
|
|
161
161
|
exports.pluginMsw = pluginMsw;
|
|
162
162
|
exports.pluginMswName = pluginMswName;
|
|
163
|
-
//# sourceMappingURL=chunk-
|
|
164
|
-
//# sourceMappingURL=chunk-
|
|
163
|
+
//# sourceMappingURL=chunk-QXK7PR6Z.cjs.map
|
|
164
|
+
//# sourceMappingURL=chunk-QXK7PR6Z.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,QAAQ,SAAS;AAAA,KACzB;AAEA,IAAA,MAAM,KAAQ,GAAA;AAAA,MACZ,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAACC,2BAAe,GAAG,CAAA;AAAA,MACzD,OAAA,EAAS,UAAW,CAAA,SAAA,EAAW,EAAE,SAAA,EAAW,CAACA,2BAAe,CAAA,EAAG,IAAM,EAAA,UAAA,EAAY;AAAA,KACnF;AAEA,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAACC,qBAAY,GAAG,CAAA;AAAA,MACtD,OAAA,EAAS,UAAW,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H,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-QXK7PR6Z.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: [pluginMswName] })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: [pluginMswName] })\n const operationName = getName(operation, { pluginKey: [pluginMswName], 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: [pluginMswName] })}()`)\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 +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,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
|
|
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 +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,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,QAAU,EAAA
|
|
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,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,IAAA,CAAA,EAOjC,CACF,EAAA,CAAA;AAEJ;ACzBO,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,IAAM,EAAA,QAAA;AAAA,MACN,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,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"]}
|
package/dist/generators.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkQXK7PR6Z_cjs = require('./chunk-QXK7PR6Z.cjs');
|
|
4
4
|
require('./chunk-XLGN5MEF.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 chunkQXK7PR6Z_cjs.handlersGenerator; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "mswGenerator", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkQXK7PR6Z_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
package/dist/index.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkQXK7PR6Z_cjs = require('./chunk-QXK7PR6Z.cjs');
|
|
4
4
|
require('./chunk-XLGN5MEF.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 chunkQXK7PR6Z_cjs.pluginMsw; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "pluginMswName", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkQXK7PR6Z_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
|
@@ -35,7 +35,7 @@ type Options = {
|
|
|
35
35
|
*/
|
|
36
36
|
handlers?: boolean;
|
|
37
37
|
/**
|
|
38
|
-
* Which parser
|
|
38
|
+
* Which parser should be used before returning the data to the `Response` of MSW.
|
|
39
39
|
* - `'faker'` will use `@kubb/plugin-faker` to generate the data for the response
|
|
40
40
|
* - `'data'` will use your custom data to generate the data for the response
|
|
41
41
|
* @default 'data'
|
|
@@ -35,7 +35,7 @@ type Options = {
|
|
|
35
35
|
*/
|
|
36
36
|
handlers?: boolean;
|
|
37
37
|
/**
|
|
38
|
-
* Which parser
|
|
38
|
+
* Which parser should be used before returning the data to the `Response` of MSW.
|
|
39
39
|
* - `'faker'` will use `@kubb/plugin-faker` to generate the data for the response
|
|
40
40
|
* - `'data'` will use your custom data to generate the data for the response
|
|
41
41
|
* @default 'data'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-msw",
|
|
3
|
-
"version": "3.0.0
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Generator swagger",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -74,24 +74,24 @@
|
|
|
74
74
|
"!/**/__tests__/**"
|
|
75
75
|
],
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@kubb/core": "3.0.0
|
|
78
|
-
"@kubb/fs": "3.0.0
|
|
79
|
-
"@kubb/oas": "3.0.0
|
|
80
|
-
"@kubb/plugin-faker": "3.0.0
|
|
81
|
-
"@kubb/plugin-oas": "3.0.0
|
|
82
|
-
"@kubb/plugin-ts": "3.0.0
|
|
83
|
-
"@kubb/react": "3.0.0
|
|
77
|
+
"@kubb/core": "3.0.0",
|
|
78
|
+
"@kubb/fs": "3.0.0",
|
|
79
|
+
"@kubb/oas": "3.0.0",
|
|
80
|
+
"@kubb/plugin-faker": "3.0.0",
|
|
81
|
+
"@kubb/plugin-oas": "3.0.0",
|
|
82
|
+
"@kubb/plugin-ts": "3.0.0",
|
|
83
|
+
"@kubb/react": "3.0.0"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@types/react": "^18.3.12",
|
|
87
87
|
"react": "^18.3.1",
|
|
88
|
-
"tsup": "^8.3.
|
|
88
|
+
"tsup": "^8.3.5",
|
|
89
89
|
"typescript": "^5.6.3",
|
|
90
|
-
"@kubb/config-ts": "3.0.0
|
|
91
|
-
"@kubb/config-tsup": "3.0.0
|
|
90
|
+
"@kubb/config-ts": "3.0.0",
|
|
91
|
+
"@kubb/config-tsup": "3.0.0"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
|
-
"@kubb/react": "3.0.0
|
|
94
|
+
"@kubb/react": "3.0.0"
|
|
95
95
|
},
|
|
96
96
|
"engines": {
|
|
97
97
|
"node": ">=20"
|
|
@@ -36,7 +36,9 @@ export const mswGenerator = createReactGenerator<PluginMsw>({
|
|
|
36
36
|
<File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
37
37
|
<File.Import name={['http']} path={'msw'} />
|
|
38
38
|
<File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />
|
|
39
|
-
{faker
|
|
39
|
+
{parser === 'faker' && faker.file && faker.schemas.response && (
|
|
40
|
+
<File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />
|
|
41
|
+
)}
|
|
40
42
|
|
|
41
43
|
{parser === 'faker' && (
|
|
42
44
|
<MockWithFaker
|
package/src/types.ts
CHANGED
|
@@ -36,7 +36,7 @@ export type Options = {
|
|
|
36
36
|
*/
|
|
37
37
|
handlers?: boolean
|
|
38
38
|
/**
|
|
39
|
-
* Which parser
|
|
39
|
+
* Which parser should be used before returning the data to the `Response` of MSW.
|
|
40
40
|
* - `'faker'` will use `@kubb/plugin-faker` to generate the data for the response
|
|
41
41
|
* - `'data'` will use your custom data to generate the data for the response
|
|
42
42
|
* @default 'data'
|
|
@@ -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,EAAA;AAAA,OAC5B;AAAA,QACE,MAAkB,EAAA,CAAA;AACtB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAY,mBAAoB,EAAA,CAAA;AAE7D,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS,CAAA;AAAA,KACzB,CAAA;AAEA,IAAA,MAAM,KAAQ,GAAA;AAAA,MACZ,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAAC,eAAe,GAAG,CAAA;AA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W,CAAC,aAAa,CAAA,EAAG,IAAM,EAAA,UAAA,EAAY,CAAA,CAAA;AAEzF,MAAA,uBAAOC,GAACC,CAAAA,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,CAAA;AAAA,KAChH,CAAA,CAAA;AAED,IAAA,MAAM,WAAW,UAAW,CAAA,GAAA,CAAI,CAAC,SAAA,KAAc,GAAG,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,SAAW,EAAA,CAAC,aAAa,CAAE,EAAC,CAAC,CAAI,EAAA,CAAA,CAAA,CAAA;AAE1H,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,CAAA;AAAA,KAClD,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-IRCHRJU5.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 {faker.file && faker.schemas.response && <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />}\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: [pluginMswName] })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: [pluginMswName] })\n const operationName = getName(operation, { pluginKey: [pluginMswName], 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: [pluginMswName] })}()`)\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,EAAA;AAAA,OAC5B;AAAA,QACEC,YAAkB,EAA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A,IAAA,EAAM,YAAY,QAAoB,EAAA,CAAA;AAAA,KAClD,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-U4NEGWMP.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 {faker.file && faker.schemas.response && <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />}\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: [pluginMswName] })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: [pluginMswName] })\n const operationName = getName(operation, { pluginKey: [pluginMswName], 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: [pluginMswName] })}()`)\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"]}
|