@kubb/plugin-msw 3.0.0-alpha.14 → 3.0.0-alpha.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/chunk-5YD7CUAH.cjs +131 -0
  2. package/dist/chunk-5YD7CUAH.cjs.map +1 -0
  3. package/dist/chunk-6M2QU6UL.js +22 -0
  4. package/dist/chunk-6M2QU6UL.js.map +1 -0
  5. package/dist/chunk-GODA4G5K.cjs +25 -0
  6. package/dist/chunk-GODA4G5K.cjs.map +1 -0
  7. package/dist/chunk-XXDW7ZSY.js +122 -0
  8. package/dist/chunk-XXDW7ZSY.js.map +1 -0
  9. package/dist/components.cjs +5 -5
  10. package/dist/components.d.cts +7 -70
  11. package/dist/components.d.ts +7 -70
  12. package/dist/components.js +1 -1
  13. package/dist/generators.cjs +17 -0
  14. package/dist/generators.cjs.map +1 -0
  15. package/dist/generators.d.cts +10 -0
  16. package/dist/generators.d.ts +10 -0
  17. package/dist/generators.js +4 -0
  18. package/dist/generators.js.map +1 -0
  19. package/dist/index.cjs +9 -125
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +4 -86
  22. package/dist/index.d.ts +4 -86
  23. package/dist/index.js +2 -124
  24. package/dist/index.js.map +1 -1
  25. package/dist/types-cZ4a5aFe.d.cts +76 -0
  26. package/dist/types-cZ4a5aFe.d.ts +76 -0
  27. package/package.json +22 -14
  28. package/src/components/Handlers.tsx +19 -0
  29. package/src/components/Mock.tsx +8 -86
  30. package/src/components/index.ts +1 -1
  31. package/src/generators/__snapshots__/createPet.ts +9 -0
  32. package/src/generators/__snapshots__/deletePet.ts +9 -0
  33. package/src/generators/__snapshots__/getPets.ts +9 -0
  34. package/src/generators/__snapshots__/handlers.ts +3 -0
  35. package/src/generators/__snapshots__/showPetById.ts +9 -0
  36. package/src/generators/handlersGenerator.tsx +32 -0
  37. package/src/generators/index.ts +2 -0
  38. package/src/generators/mswGenerator.tsx +36 -0
  39. package/src/plugin.ts +5 -14
  40. package/src/types.ts +4 -12
  41. package/dist/chunk-3KHLTEUD.js +0 -98
  42. package/dist/chunk-3KHLTEUD.js.map +0 -1
  43. package/dist/chunk-BD7UJBXM.cjs +0 -101
  44. package/dist/chunk-BD7UJBXM.cjs.map +0 -1
  45. package/src/OperationGenerator.tsx +0 -66
  46. package/src/components/Operations.tsx +0 -94
  47. package/src/components/__snapshots__/Mock/Pets.ts +0 -7
  48. package/src/components/__snapshots__/Mock/showPetsById.ts +0 -7
@@ -0,0 +1,131 @@
1
+ 'use strict';
2
+
3
+ var chunkGODA4G5K_cjs = require('./chunk-GODA4G5K.cjs');
4
+ var utils = require('@kubb/core/utils');
5
+ var pluginFaker = require('@kubb/plugin-faker');
6
+ var pluginOas = require('@kubb/plugin-oas');
7
+ var hooks = require('@kubb/plugin-oas/hooks');
8
+ var react = require('@kubb/react');
9
+ var jsxRuntime = require('@kubb/react/jsx-runtime');
10
+ var path = require('path');
11
+ var core = require('@kubb/core');
12
+ var transformers = require('@kubb/core/transformers');
13
+ var pluginTs = require('@kubb/plugin-ts');
14
+
15
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
16
+
17
+ var path__default = /*#__PURE__*/_interopDefault(path);
18
+
19
+ var mswGenerator = pluginOas.createReactGenerator({
20
+ name: "msw",
21
+ Operation({ operation }) {
22
+ const {
23
+ plugin: { output }
24
+ } = react.useApp();
25
+ const { getSchemaName, getName, getFile } = hooks.useOperationManager();
26
+ const mock = {
27
+ name: getName(operation, { type: "function" }),
28
+ file: getFile(operation)
29
+ };
30
+ const faker = {
31
+ name: getSchemaName(operation, "response", { pluginKey: [pluginFaker.pluginFakerName], type: "function" }),
32
+ file: getFile(operation, { pluginKey: [pluginFaker.pluginFakerName] })
33
+ };
34
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: mock.file.baseName, path: mock.file.path, meta: mock.file.meta, children: [
35
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["http"], path: "msw" }),
36
+ faker.file && faker.name && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { extName: output?.extName, name: [faker.name], root: mock.file.path, path: faker.file.path }),
37
+ /* @__PURE__ */ jsxRuntime.jsx(chunkGODA4G5K_cjs.Mock, { name: mock.name, fakerName: faker.name, method: operation.method, url: new utils.URLPath(operation.path).toURLPath() })
38
+ ] });
39
+ }
40
+ });
41
+ var pluginMswName = "plugin-msw";
42
+ var pluginMsw = core.createPlugin((options) => {
43
+ const { output = { path: "handlers" }, group, exclude = [], include, override = [], transformers: transformers$1 = {}, handlers = false } = options;
44
+ const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
45
+ return {
46
+ name: pluginMswName,
47
+ output: {
48
+ exportType: "barrelNamed",
49
+ ...output
50
+ },
51
+ options: {},
52
+ pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, pluginFaker.pluginFakerName],
53
+ resolvePath(baseName, pathMode, options2) {
54
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
55
+ const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
56
+ if (mode === "single") {
57
+ return path__default.default.resolve(root, output.path);
58
+ }
59
+ if (options2?.tag && group?.type === "tag") {
60
+ const tag = transformers.camelCase(options2.tag);
61
+ return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
62
+ }
63
+ return path__default.default.resolve(root, output.path, baseName);
64
+ },
65
+ resolveName(name, type) {
66
+ const resolvedName = transformers.camelCase(name, {
67
+ suffix: type ? "handler" : void 0,
68
+ isFile: type === "file"
69
+ });
70
+ if (type) {
71
+ return transformers$1?.name?.(resolvedName, type) || resolvedName;
72
+ }
73
+ return resolvedName;
74
+ },
75
+ async buildStart() {
76
+ const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
77
+ const oas = await swaggerPlugin.context.getOas();
78
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
79
+ const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
80
+ const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
81
+ oas,
82
+ pluginManager: this.pluginManager,
83
+ plugin: this.plugin,
84
+ contentType: swaggerPlugin.context.contentType,
85
+ exclude,
86
+ include,
87
+ override,
88
+ mode
89
+ });
90
+ const files = await operationGenerator.build(...[mswGenerator, handlers ? handlersGenerator : void 0].filter(Boolean));
91
+ await this.addFile(...files);
92
+ if (this.config.output.exportType) {
93
+ const barrelFiles = await this.fileManager.getBarrelFiles({
94
+ root,
95
+ output,
96
+ files: this.fileManager.files,
97
+ meta: {
98
+ pluginKey: this.plugin.key
99
+ },
100
+ logger: this.logger
101
+ });
102
+ await this.addFile(...barrelFiles);
103
+ }
104
+ }
105
+ };
106
+ });
107
+ var handlersGenerator = pluginOas.createReactGenerator({
108
+ name: "plugin-msw",
109
+ Operations({ operations }) {
110
+ const { pluginManager, plugin } = react.useApp();
111
+ const { getName, getFile } = hooks.useOperationManager();
112
+ const file = pluginManager.getFile({ name: "handlers", extName: ".ts", pluginKey: [pluginMswName] });
113
+ const imports = operations.map((operation) => {
114
+ const operationFile = getFile(operation, { pluginKey: [pluginMswName] });
115
+ const operationName = getName(operation, { pluginKey: [pluginMswName], type: "function" });
116
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { extName: plugin.output?.extName, name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
117
+ });
118
+ const handlers = operations.map((operation) => getName(operation, { type: "function", pluginKey: [pluginMswName] }));
119
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
120
+ imports,
121
+ /* @__PURE__ */ jsxRuntime.jsx(chunkGODA4G5K_cjs.Handlers, { name: "handlers", handlers })
122
+ ] });
123
+ }
124
+ });
125
+
126
+ exports.handlersGenerator = handlersGenerator;
127
+ exports.mswGenerator = mswGenerator;
128
+ exports.pluginMsw = pluginMsw;
129
+ exports.pluginMswName = pluginMswName;
130
+ //# sourceMappingURL=chunk-5YD7CUAH.cjs.map
131
+ //# sourceMappingURL=chunk-5YD7CUAH.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","jsxs","File","jsx","Mock","URLPath","createPlugin","transformers","pluginOasName","pluginTsName","options","path","FileManager","camelCase","renderTemplate","PluginManager","OperationGenerator","Handlers"],"mappings":";;;;;;;;;;;;;;;;;;AAQO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,MAAA,EAAQ,EAAE,MAAO,EAAA;AAAA,QACfC,YAAkB,EAAA,CAAA;AACtB,IAAA,MAAM,EAAE,aAAA,EAAe,OAAS,EAAA,OAAA,KAAYC,yBAAoB,EAAA,CAAA;AAEhE,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,aAAc,CAAA,SAAA,EAAW,UAAY,EAAA,EAAE,SAAW,EAAA,CAACC,2BAAe,CAAA,EAAG,IAAM,EAAA,UAAA,EAAY,CAAA;AAAA,MAC7F,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAACA,2BAAe,GAAG,CAAA;AAAA,KAC3D,CAAA;AAEA,IAAA,uBACGC,eAAA,CAAAC,UAAA,EAAA,EAAK,QAAU,EAAA,IAAA,CAAK,IAAK,CAAA,QAAA,EAAU,IAAM,EAAA,IAAA,CAAK,IAAK,CAAA,IAAA,EAAM,IAAM,EAAA,IAAA,CAAK,K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,EAAG,MAAM,IAAK,CAAA,IAAA,EAAM,MAAM,aAAc,CAAA,IAAA,EAAA,EAAhF,cAAc,IAAwE,CAAA,CAAA;AAAA,KACjJ,CAAA,CAAA;AAED,IAAA,MAAM,QAAW,GAAA,UAAA,CAAW,GAAI,CAAA,CAAC,cAAc,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,SAAW,EAAA,CAAC,aAAa,CAAA,EAAG,CAAC,CAAA,CAAA;AAEnH,IAAA,uBACED,eAAAA,CAACC,UAAA,EAAA,EAAK,QAAU,EAAA,IAAA,CAAK,QAAU,EAAA,IAAA,EAAM,IAAK,CAAA,IAAA,EAAM,IAAM,EAAA,IAAA,CAAK,IACxD,EAAA,QAAA,EAAA;AAAA,MAAA,OAAA;AAAA,sBACDC,cAAAA,CAACc,0BAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA,CAAA;AAAA,KAClD,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-5YD7CUAH.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 { File, useApp } from '@kubb/react'\nimport { Mock } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n plugin: { output },\n } = useApp<PluginMsw>()\n const { getSchemaName, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n name: getSchemaName(operation, 'response', { pluginKey: [pluginFakerName], type: 'function' }),\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta}>\n <File.Import name={['http']} path={'msw'} />\n {faker.file && faker.name && <File.Import extName={output?.extName} name={[faker.name]} root={mock.file.path} path={faker.file.path} />}\n\n <Mock name={mock.name} fakerName={faker.name} method={operation.method} url={new URLPath(operation.path).toURLPath()} />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { 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 { output = { path: 'handlers' }, group, exclude = [], include, override = [], transformers = {}, handlers = false } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginMswName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {},\n pre: [pluginOasName, pluginTsName, pluginFakerName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\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(...[mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean))\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n","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 extName={plugin.output?.extName} 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}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
@@ -0,0 +1,22 @@
1
+ import { File } from '@kubb/react';
2
+ import { jsx } from '@kubb/react/jsx-runtime';
3
+
4
+ // src/components/Mock.tsx
5
+ function Mock({ name, fakerName, url, method }) {
6
+ return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: `
7
+ export const ${name} = http.${method}('*${url}', function handler(info) {
8
+ return new Response(JSON.stringify(${fakerName}()), {
9
+ headers: {
10
+ 'Content-Type': 'application/json',
11
+ },
12
+ })
13
+ })
14
+ ` });
15
+ }
16
+ function Handlers({ name, handlers }) {
17
+ return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
18
+ }
19
+
20
+ export { Handlers, Mock };
21
+ //# sourceMappingURL=chunk-6M2QU6UL.js.map
22
+ //# sourceMappingURL=chunk-6M2QU6UL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx"],"names":["jsx","File"],"mappings":";;;;AAeO,SAAS,KAAK,EAAE,IAAA,EAAM,SAAW,EAAA,GAAA,EAAK,QAA4B,EAAA;AACvE,EACE,uBAAA,GAAA,CAAC,KAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,cAAY,IAC9C,EAAA,QAAA,EAAA,CAAA;AAAA,eAAA,EACU,IAAI,CAAA,QAAA,EAAW,MAAM,CAAA,GAAA,EAAM,GAAG,CAAA;AAAA,uCAAA,EACN,SAAS,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO9C,CAAA,EAAA,CAAA,CAAA;AAEJ,CAAA;ACjBO,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,CAAA;AAEJ","file":"chunk-6M2QU6UL.js","sourcesContent":["import { File } 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 fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function Mock({ name, fakerName, url, method }: Props): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`\n export const ${name} = http.${method}('*${url}', function handler(info) {\n return new Response(JSON.stringify(${fakerName}()), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })\n `}\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"]}
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ var react = require('@kubb/react');
4
+ var jsxRuntime = require('@kubb/react/jsx-runtime');
5
+
6
+ // src/components/Mock.tsx
7
+ function Mock({ name, fakerName, url, method }) {
8
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: `
9
+ export const ${name} = http.${method}('*${url}', function handler(info) {
10
+ return new Response(JSON.stringify(${fakerName}()), {
11
+ headers: {
12
+ 'Content-Type': 'application/json',
13
+ },
14
+ })
15
+ })
16
+ ` });
17
+ }
18
+ function Handlers({ name, handlers }) {
19
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
20
+ }
21
+
22
+ exports.Handlers = Handlers;
23
+ exports.Mock = Mock;
24
+ //# sourceMappingURL=chunk-GODA4G5K.cjs.map
25
+ //# sourceMappingURL=chunk-GODA4G5K.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx"],"names":["jsx","File"],"mappings":";;;;;;AAeO,SAAS,KAAK,EAAE,IAAA,EAAM,SAAW,EAAA,GAAA,EAAK,QAA4B,EAAA;AACvE,EACE,uBAAAA,cAAA,CAACC,WAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,cAAY,IAC9C,EAAA,QAAA,EAAA,CAAA;AAAA,eAAA,EACU,IAAI,CAAA,QAAA,EAAW,MAAM,CAAA,GAAA,EAAM,GAAG,CAAA;AAAA,uCAAA,EACN,SAAS,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO9C,CAAA,EAAA,CAAA,CAAA;AAEJ,CAAA;ACjBO,SAAS,QAAS,CAAA,EAAE,IAAM,EAAA,QAAA,EAAsC,EAAA;AACrE,EACE,uBAAAD,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,CAAA;AAEJ","file":"chunk-GODA4G5K.cjs","sourcesContent":["import { File } 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 fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function Mock({ name, fakerName, url, method }: Props): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`\n export const ${name} = http.${method}('*${url}', function handler(info) {\n return new Response(JSON.stringify(${fakerName}()), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })\n `}\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"]}
@@ -0,0 +1,122 @@
1
+ import { Mock, Handlers } from './chunk-6M2QU6UL.js';
2
+ import { URLPath, renderTemplate } from '@kubb/core/utils';
3
+ import { pluginFakerName } from '@kubb/plugin-faker';
4
+ import { createReactGenerator, pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
5
+ import { useOperationManager } from '@kubb/plugin-oas/hooks';
6
+ import { useApp, File } from '@kubb/react';
7
+ import { jsxs, jsx } from '@kubb/react/jsx-runtime';
8
+ import path from 'node:path';
9
+ import { createPlugin, FileManager, PluginManager } from '@kubb/core';
10
+ import { camelCase } from '@kubb/core/transformers';
11
+ import { pluginTsName } from '@kubb/plugin-ts';
12
+
13
+ var mswGenerator = createReactGenerator({
14
+ name: "msw",
15
+ Operation({ operation }) {
16
+ const {
17
+ plugin: { output }
18
+ } = useApp();
19
+ const { getSchemaName, getName, getFile } = useOperationManager();
20
+ const mock = {
21
+ name: getName(operation, { type: "function" }),
22
+ file: getFile(operation)
23
+ };
24
+ const faker = {
25
+ name: getSchemaName(operation, "response", { pluginKey: [pluginFakerName], type: "function" }),
26
+ file: getFile(operation, { pluginKey: [pluginFakerName] })
27
+ };
28
+ return /* @__PURE__ */ jsxs(File, { baseName: mock.file.baseName, path: mock.file.path, meta: mock.file.meta, children: [
29
+ /* @__PURE__ */ jsx(File.Import, { name: ["http"], path: "msw" }),
30
+ faker.file && faker.name && /* @__PURE__ */ jsx(File.Import, { extName: output?.extName, name: [faker.name], root: mock.file.path, path: faker.file.path }),
31
+ /* @__PURE__ */ jsx(Mock, { name: mock.name, fakerName: faker.name, method: operation.method, url: new URLPath(operation.path).toURLPath() })
32
+ ] });
33
+ }
34
+ });
35
+ var pluginMswName = "plugin-msw";
36
+ var pluginMsw = createPlugin((options) => {
37
+ const { output = { path: "handlers" }, group, exclude = [], include, override = [], transformers = {}, handlers = false } = options;
38
+ const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
39
+ return {
40
+ name: pluginMswName,
41
+ output: {
42
+ exportType: "barrelNamed",
43
+ ...output
44
+ },
45
+ options: {},
46
+ pre: [pluginOasName, pluginTsName, pluginFakerName],
47
+ resolvePath(baseName, pathMode, options2) {
48
+ const root = path.resolve(this.config.root, this.config.output.path);
49
+ const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
50
+ if (mode === "single") {
51
+ return path.resolve(root, output.path);
52
+ }
53
+ if (options2?.tag && group?.type === "tag") {
54
+ const tag = camelCase(options2.tag);
55
+ return path.resolve(root, renderTemplate(template, { tag }), baseName);
56
+ }
57
+ return path.resolve(root, output.path, baseName);
58
+ },
59
+ resolveName(name, type) {
60
+ const resolvedName = camelCase(name, {
61
+ suffix: type ? "handler" : void 0,
62
+ isFile: type === "file"
63
+ });
64
+ if (type) {
65
+ return transformers?.name?.(resolvedName, type) || resolvedName;
66
+ }
67
+ return resolvedName;
68
+ },
69
+ async buildStart() {
70
+ const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
71
+ const oas = await swaggerPlugin.context.getOas();
72
+ const root = path.resolve(this.config.root, this.config.output.path);
73
+ const mode = FileManager.getMode(path.resolve(root, output.path));
74
+ const operationGenerator = new OperationGenerator(this.plugin.options, {
75
+ oas,
76
+ pluginManager: this.pluginManager,
77
+ plugin: this.plugin,
78
+ contentType: swaggerPlugin.context.contentType,
79
+ exclude,
80
+ include,
81
+ override,
82
+ mode
83
+ });
84
+ const files = await operationGenerator.build(...[mswGenerator, handlers ? handlersGenerator : void 0].filter(Boolean));
85
+ await this.addFile(...files);
86
+ if (this.config.output.exportType) {
87
+ const barrelFiles = await this.fileManager.getBarrelFiles({
88
+ root,
89
+ output,
90
+ files: this.fileManager.files,
91
+ meta: {
92
+ pluginKey: this.plugin.key
93
+ },
94
+ logger: this.logger
95
+ });
96
+ await this.addFile(...barrelFiles);
97
+ }
98
+ }
99
+ };
100
+ });
101
+ var handlersGenerator = createReactGenerator({
102
+ name: "plugin-msw",
103
+ Operations({ operations }) {
104
+ const { pluginManager, plugin } = useApp();
105
+ const { getName, getFile } = useOperationManager();
106
+ const file = pluginManager.getFile({ name: "handlers", extName: ".ts", pluginKey: [pluginMswName] });
107
+ const imports = operations.map((operation) => {
108
+ const operationFile = getFile(operation, { pluginKey: [pluginMswName] });
109
+ const operationName = getName(operation, { pluginKey: [pluginMswName], type: "function" });
110
+ return /* @__PURE__ */ jsx(File.Import, { extName: plugin.output?.extName, name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
111
+ });
112
+ const handlers = operations.map((operation) => getName(operation, { type: "function", pluginKey: [pluginMswName] }));
113
+ return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
114
+ imports,
115
+ /* @__PURE__ */ jsx(Handlers, { name: "handlers", handlers })
116
+ ] });
117
+ }
118
+ });
119
+
120
+ export { handlersGenerator, mswGenerator, pluginMsw, pluginMswName };
121
+ //# sourceMappingURL=chunk-XXDW7ZSY.js.map
122
+ //# sourceMappingURL=chunk-XXDW7ZSY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/plugin.ts","../src/generators/handlersGenerator.tsx"],"names":["pluginFakerName","options","createReactGenerator","useApp","useOperationManager","jsx","File","jsxs"],"mappings":";;;;;;;;;;;;AAQO,IAAM,eAAe,oBAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,MAAA,EAAQ,EAAE,MAA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AA;AAAA,KAClD,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-XXDW7ZSY.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 { File, useApp } from '@kubb/react'\nimport { Mock } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n plugin: { output },\n } = useApp<PluginMsw>()\n const { getSchemaName, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n name: getSchemaName(operation, 'response', { pluginKey: [pluginFakerName], type: 'function' }),\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta}>\n <File.Import name={['http']} path={'msw'} />\n {faker.file && faker.name && <File.Import extName={output?.extName} name={[faker.name]} root={mock.file.path} path={faker.file.path} />}\n\n <Mock name={mock.name} fakerName={faker.name} method={operation.method} url={new URLPath(operation.path).toURLPath()} />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { 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 { output = { path: 'handlers' }, group, exclude = [], include, override = [], transformers = {}, handlers = false } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginMswName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {},\n pre: [pluginOasName, pluginTsName, pluginFakerName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\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(...[mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean))\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n","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 extName={plugin.output?.extName} 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}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
@@ -1,16 +1,16 @@
1
1
  'use strict';
2
2
 
3
- var chunkBD7UJBXM_cjs = require('./chunk-BD7UJBXM.cjs');
3
+ var chunkGODA4G5K_cjs = require('./chunk-GODA4G5K.cjs');
4
4
 
5
5
 
6
6
 
7
- Object.defineProperty(exports, "Mock", {
7
+ Object.defineProperty(exports, "Handlers", {
8
8
  enumerable: true,
9
- get: function () { return chunkBD7UJBXM_cjs.Mock; }
9
+ get: function () { return chunkGODA4G5K_cjs.Handlers; }
10
10
  });
11
- Object.defineProperty(exports, "Operations", {
11
+ Object.defineProperty(exports, "Mock", {
12
12
  enumerable: true,
13
- get: function () { return chunkBD7UJBXM_cjs.Operations; }
13
+ get: function () { return chunkGODA4G5K_cjs.Mock; }
14
14
  });
15
15
  //# sourceMappingURL=components.cjs.map
16
16
  //# sourceMappingURL=components.cjs.map
@@ -1,87 +1,24 @@
1
- import { URLPath } from '@kubb/core/utils';
2
1
  import { HttpMethod } from '@kubb/oas';
3
2
  import { ReactNode } from 'react';
4
- import { KubbNode } from '@kubb/react/types';
5
3
 
6
- type TemplateProps$1 = {
4
+ type Props = {
7
5
  /**
8
6
  * Name of the function
9
7
  */
10
8
  name: string;
11
- /**
12
- * Method of the current operation, see useOperation.
13
- */
9
+ fakerName: string;
10
+ url: string;
14
11
  method: HttpMethod;
15
- /**
16
- * Path of the mock
17
- */
18
- path: URLPath;
19
- /**
20
- * Name of the import for the mock(this is a function).
21
- * @example createPet
22
- */
23
- responseName: string;
24
- };
25
- declare function Template$1({ name, method, path, responseName }: TemplateProps$1): ReactNode;
26
- declare const defaultTemplates$1: {
27
- readonly default: typeof Template$1;
28
- };
29
- type Props$1 = {
30
- /**
31
- * This will make it possible to override the default behaviour.
32
- */
33
- Template?: React.ComponentType<React.ComponentProps<typeof Template$1>>;
34
- };
35
- declare function Mock({ Template }: Props$1): ReactNode;
36
- declare namespace Mock {
37
- var File: ({ templates }: FileProps$1) => ReactNode;
38
- var templates: {
39
- readonly default: typeof Template$1;
40
- };
41
- }
42
- type FileProps$1 = {
43
- /**
44
- * This will make it possible to override the default behaviour.
45
- */
46
- templates?: typeof defaultTemplates$1;
47
12
  };
13
+ declare function Mock({ name, fakerName, url, method }: Props): ReactNode;
48
14
 
49
- type TemplateProps = {
15
+ type HandlersProps = {
50
16
  /**
51
17
  * Name of the function
52
18
  */
53
19
  name: string;
54
20
  handlers: string[];
55
21
  };
56
- declare function Template({ name, handlers }: TemplateProps): ReactNode;
57
- type ParserTemplateProps = {
58
- children?: React.ReactNode;
59
- };
60
- declare function RootTemplate({ children }: ParserTemplateProps): JSX.Element;
61
- declare const defaultTemplates: {
62
- readonly default: typeof Template;
63
- readonly root: typeof RootTemplate;
64
- };
65
- type Templates = Partial<typeof defaultTemplates>;
66
- type Props = {
67
- /**
68
- * This will make it possible to override the default behaviour.
69
- */
70
- Template?: React.ComponentType<React.ComponentProps<typeof Template>>;
71
- };
72
- declare function Operations({ Template }: Props): ReactNode;
73
- declare namespace Operations {
74
- var File: (props: FileProps) => KubbNode;
75
- var templates: {
76
- readonly default: typeof Template;
77
- readonly root: typeof RootTemplate;
78
- };
79
- }
80
- type FileProps = {
81
- /**
82
- * This will make it possible to override the default behaviour.
83
- */
84
- templates?: Templates;
85
- };
22
+ declare function Handlers({ name, handlers }: HandlersProps): ReactNode;
86
23
 
87
- export { Mock, Operations };
24
+ export { Handlers, Mock };
@@ -1,87 +1,24 @@
1
- import { URLPath } from '@kubb/core/utils';
2
1
  import { HttpMethod } from '@kubb/oas';
3
2
  import { ReactNode } from 'react';
4
- import { KubbNode } from '@kubb/react/types';
5
3
 
6
- type TemplateProps$1 = {
4
+ type Props = {
7
5
  /**
8
6
  * Name of the function
9
7
  */
10
8
  name: string;
11
- /**
12
- * Method of the current operation, see useOperation.
13
- */
9
+ fakerName: string;
10
+ url: string;
14
11
  method: HttpMethod;
15
- /**
16
- * Path of the mock
17
- */
18
- path: URLPath;
19
- /**
20
- * Name of the import for the mock(this is a function).
21
- * @example createPet
22
- */
23
- responseName: string;
24
- };
25
- declare function Template$1({ name, method, path, responseName }: TemplateProps$1): ReactNode;
26
- declare const defaultTemplates$1: {
27
- readonly default: typeof Template$1;
28
- };
29
- type Props$1 = {
30
- /**
31
- * This will make it possible to override the default behaviour.
32
- */
33
- Template?: React.ComponentType<React.ComponentProps<typeof Template$1>>;
34
- };
35
- declare function Mock({ Template }: Props$1): ReactNode;
36
- declare namespace Mock {
37
- var File: ({ templates }: FileProps$1) => ReactNode;
38
- var templates: {
39
- readonly default: typeof Template$1;
40
- };
41
- }
42
- type FileProps$1 = {
43
- /**
44
- * This will make it possible to override the default behaviour.
45
- */
46
- templates?: typeof defaultTemplates$1;
47
12
  };
13
+ declare function Mock({ name, fakerName, url, method }: Props): ReactNode;
48
14
 
49
- type TemplateProps = {
15
+ type HandlersProps = {
50
16
  /**
51
17
  * Name of the function
52
18
  */
53
19
  name: string;
54
20
  handlers: string[];
55
21
  };
56
- declare function Template({ name, handlers }: TemplateProps): ReactNode;
57
- type ParserTemplateProps = {
58
- children?: React.ReactNode;
59
- };
60
- declare function RootTemplate({ children }: ParserTemplateProps): JSX.Element;
61
- declare const defaultTemplates: {
62
- readonly default: typeof Template;
63
- readonly root: typeof RootTemplate;
64
- };
65
- type Templates = Partial<typeof defaultTemplates>;
66
- type Props = {
67
- /**
68
- * This will make it possible to override the default behaviour.
69
- */
70
- Template?: React.ComponentType<React.ComponentProps<typeof Template>>;
71
- };
72
- declare function Operations({ Template }: Props): ReactNode;
73
- declare namespace Operations {
74
- var File: (props: FileProps) => KubbNode;
75
- var templates: {
76
- readonly default: typeof Template;
77
- readonly root: typeof RootTemplate;
78
- };
79
- }
80
- type FileProps = {
81
- /**
82
- * This will make it possible to override the default behaviour.
83
- */
84
- templates?: Templates;
85
- };
22
+ declare function Handlers({ name, handlers }: HandlersProps): ReactNode;
86
23
 
87
- export { Mock, Operations };
24
+ export { Handlers, Mock };
@@ -1,3 +1,3 @@
1
- export { Mock, Operations } from './chunk-3KHLTEUD.js';
1
+ export { Handlers, Mock } from './chunk-6M2QU6UL.js';
2
2
  //# sourceMappingURL=components.js.map
3
3
  //# sourceMappingURL=components.js.map
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ var chunk5YD7CUAH_cjs = require('./chunk-5YD7CUAH.cjs');
4
+ require('./chunk-GODA4G5K.cjs');
5
+
6
+
7
+
8
+ Object.defineProperty(exports, "handlersGenerator", {
9
+ enumerable: true,
10
+ get: function () { return chunk5YD7CUAH_cjs.handlersGenerator; }
11
+ });
12
+ Object.defineProperty(exports, "mswGenerator", {
13
+ enumerable: true,
14
+ get: function () { return chunk5YD7CUAH_cjs.mswGenerator; }
15
+ });
16
+ //# sourceMappingURL=generators.cjs.map
17
+ //# sourceMappingURL=generators.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"generators.cjs"}
@@ -0,0 +1,10 @@
1
+ import * as _kubb_plugin_oas from '@kubb/plugin-oas';
2
+ import { P as PluginMsw } from './types-cZ4a5aFe.cjs';
3
+ import '@kubb/core';
4
+ import '@kubb/fs/types';
5
+
6
+ declare const mswGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
7
+
8
+ declare const handlersGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
9
+
10
+ export { handlersGenerator, mswGenerator };
@@ -0,0 +1,10 @@
1
+ import * as _kubb_plugin_oas from '@kubb/plugin-oas';
2
+ import { P as PluginMsw } from './types-cZ4a5aFe.js';
3
+ import '@kubb/core';
4
+ import '@kubb/fs/types';
5
+
6
+ declare const mswGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
7
+
8
+ declare const handlersGenerator: _kubb_plugin_oas.Generator<PluginMsw>;
9
+
10
+ export { handlersGenerator, mswGenerator };
@@ -0,0 +1,4 @@
1
+ export { handlersGenerator, mswGenerator } from './chunk-XXDW7ZSY.js';
2
+ import './chunk-6M2QU6UL.js';
3
+ //# sourceMappingURL=generators.js.map
4
+ //# sourceMappingURL=generators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"generators.js"}