@kubb/plugin-msw 3.0.0-alpha.3 → 3.0.0-alpha.30

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 (51) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-6M2QU6UL.js +22 -0
  3. package/dist/chunk-6M2QU6UL.js.map +1 -0
  4. package/dist/chunk-GODA4G5K.cjs +25 -0
  5. package/dist/chunk-GODA4G5K.cjs.map +1 -0
  6. package/dist/chunk-M3A3J5SW.cjs +139 -0
  7. package/dist/chunk-M3A3J5SW.cjs.map +1 -0
  8. package/dist/chunk-NDX2ITTW.js +130 -0
  9. package/dist/chunk-NDX2ITTW.js.map +1 -0
  10. package/dist/components.cjs +11 -4
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +7 -70
  13. package/dist/components.d.ts +7 -70
  14. package/dist/components.js +2 -8
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +17 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +9 -0
  19. package/dist/generators.d.ts +9 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +11 -137
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +3 -86
  25. package/dist/index.d.ts +3 -86
  26. package/dist/index.js +3 -142
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-C6GF3XKm.d.cts +64 -0
  29. package/dist/types-C6GF3XKm.d.ts +64 -0
  30. package/package.json +22 -17
  31. package/src/components/Handlers.tsx +19 -0
  32. package/src/components/Mock.tsx +9 -92
  33. package/src/components/index.ts +1 -1
  34. package/src/generators/__snapshots__/createPet.ts +9 -0
  35. package/src/generators/__snapshots__/deletePet.ts +9 -0
  36. package/src/generators/__snapshots__/getPets.ts +9 -0
  37. package/src/generators/__snapshots__/handlers.ts +3 -0
  38. package/src/generators/__snapshots__/showPetById.ts +9 -0
  39. package/src/generators/handlersGenerator.tsx +32 -0
  40. package/src/generators/index.ts +2 -0
  41. package/src/generators/mswGenerator.tsx +38 -0
  42. package/src/plugin.ts +24 -36
  43. package/src/types.ts +14 -39
  44. package/dist/chunk-S4P5XPFN.cjs +0 -105
  45. package/dist/chunk-S4P5XPFN.cjs.map +0 -1
  46. package/dist/chunk-WRIEMCYI.js +0 -105
  47. package/dist/chunk-WRIEMCYI.js.map +0 -1
  48. package/src/OperationGenerator.tsx +0 -66
  49. package/src/components/Operations.tsx +0 -96
  50. package/src/components/__snapshots__/Mock/Pets.ts +0 -7
  51. package/src/components/__snapshots__/Mock/showPetsById.ts +0 -7
package/README.md CHANGED
@@ -13,10 +13,6 @@
13
13
  [![Coverage][coverage-src]][coverage-href]
14
14
  [![License][license-src]][license-href]
15
15
 
16
- <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
17
- <!-- ALL-CONTRIBUTORS-BADGE:END -->
18
- </p>
19
-
20
16
  <h4>
21
17
  <a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/alpha/examples/typescript" target="_blank">View Demo</a>
22
18
  <span> · </span>
@@ -28,6 +24,19 @@
28
24
  </h4>
29
25
  </div>
30
26
 
27
+ ## Supporting Kubb
28
+
29
+ Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
30
+
31
+ - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
32
+
33
+ <p align="center">
34
+ <a href="https://github.com/sponsors/stijnvanhulle">
35
+ <img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
36
+ </a>
37
+ </p>
38
+
39
+
31
40
  <!-- Badges -->
32
41
 
33
42
  [npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-msw?flat&colorA=18181B&colorB=f58517
@@ -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,139 @@
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: {
24
+ options: { output }
25
+ }
26
+ } = react.useApp();
27
+ const { getSchemaName, getName, getFile } = hooks.useOperationManager();
28
+ const mock = {
29
+ name: getName(operation, { type: "function" }),
30
+ file: getFile(operation)
31
+ };
32
+ const faker = {
33
+ name: getSchemaName(operation, "response", { pluginKey: [pluginFaker.pluginFakerName], type: "function" }),
34
+ file: getFile(operation, { pluginKey: [pluginFaker.pluginFakerName] })
35
+ };
36
+ 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: [
37
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["http"], path: "msw" }),
38
+ faker.file && faker.name && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [faker.name], root: mock.file.path, path: faker.file.path }),
39
+ /* @__PURE__ */ jsxRuntime.jsx(chunkGODA4G5K_cjs.Mock, { name: mock.name, fakerName: faker.name, method: operation.method, url: new utils.URLPath(operation.path).toURLPath() })
40
+ ] });
41
+ }
42
+ });
43
+ var pluginMswName = "plugin-msw";
44
+ var pluginMsw = core.createPlugin((options) => {
45
+ const {
46
+ output = { path: "handlers", barrelType: "named" },
47
+ group,
48
+ exclude = [],
49
+ include,
50
+ override = [],
51
+ transformers: transformers$1 = {},
52
+ handlers = false,
53
+ generators = [mswGenerator, handlers ? handlersGenerator : void 0].filter(Boolean)
54
+ } = options;
55
+ const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
56
+ return {
57
+ name: pluginMswName,
58
+ options: {
59
+ output
60
+ },
61
+ pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, pluginFaker.pluginFakerName],
62
+ resolvePath(baseName, pathMode, options2) {
63
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
64
+ const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
65
+ if (mode === "single") {
66
+ return path__default.default.resolve(root, output.path);
67
+ }
68
+ if (options2?.tag && group?.type === "tag") {
69
+ const tag = transformers.camelCase(options2.tag);
70
+ return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
71
+ }
72
+ return path__default.default.resolve(root, output.path, baseName);
73
+ },
74
+ resolveName(name, type) {
75
+ const resolvedName = transformers.camelCase(name, {
76
+ suffix: type ? "handler" : void 0,
77
+ isFile: type === "file"
78
+ });
79
+ if (type) {
80
+ return transformers$1?.name?.(resolvedName, type) || resolvedName;
81
+ }
82
+ return resolvedName;
83
+ },
84
+ async buildStart() {
85
+ const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
86
+ const oas = await swaggerPlugin.context.getOas();
87
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
88
+ const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
89
+ const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
90
+ oas,
91
+ pluginManager: this.pluginManager,
92
+ plugin: this.plugin,
93
+ contentType: swaggerPlugin.context.contentType,
94
+ exclude,
95
+ include,
96
+ override,
97
+ mode
98
+ });
99
+ const files = await operationGenerator.build(...generators);
100
+ await this.addFile(...files);
101
+ const barrelFiles = await this.fileManager.getBarrelFiles({
102
+ type: output.barrelType ?? "named",
103
+ root,
104
+ output,
105
+ files: this.fileManager.files,
106
+ meta: {
107
+ pluginKey: this.plugin.key
108
+ },
109
+ logger: this.logger
110
+ });
111
+ await this.addFile(...barrelFiles);
112
+ }
113
+ };
114
+ });
115
+ var handlersGenerator = pluginOas.createReactGenerator({
116
+ name: "plugin-msw",
117
+ Operations({ operations }) {
118
+ const { pluginManager, plugin } = react.useApp();
119
+ const { getName, getFile } = hooks.useOperationManager();
120
+ const file = pluginManager.getFile({ name: "handlers", extname: ".ts", pluginKey: [pluginMswName] });
121
+ const imports = operations.map((operation) => {
122
+ const operationFile = getFile(operation, { pluginKey: [pluginMswName] });
123
+ const operationName = getName(operation, { pluginKey: [pluginMswName], type: "function" });
124
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
125
+ });
126
+ const handlers = operations.map((operation) => getName(operation, { type: "function", pluginKey: [pluginMswName] }));
127
+ 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: [
128
+ imports,
129
+ /* @__PURE__ */ jsxRuntime.jsx(chunkGODA4G5K_cjs.Handlers, { name: "handlers", handlers })
130
+ ] });
131
+ }
132
+ });
133
+
134
+ exports.handlersGenerator = handlersGenerator;
135
+ exports.mswGenerator = mswGenerator;
136
+ exports.pluginMsw = pluginMsw;
137
+ exports.pluginMswName = pluginMswName;
138
+ //# sourceMappingURL=chunk-M3A3J5SW.cjs.map
139
+ //# sourceMappingURL=chunk-M3A3J5SW.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","File","jsx","Mock","URLPath","createPlugin","transformers","pluginOasName","pluginTsName","options","path","FileManager","camelCase","renderTemplate","PluginManager","OperationGenerator","jsxs","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,MAAQ,EAAA;AAAA,QACN,OAAA,EAAS,EAAE,MAAO,EAAA;AAAA,OACpB;AAAA,QACEC,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,uCACGC,UAAK,EAAA,EAAA,QAAA,EAAU,KAAK,IAAK,CAAA,QAAA,EAAU,MAAM,IAAK,CAAA,IAAA,CAAK,MAAM,IAAM,EAAA,IAAA,CAAK,KAAK,IAAM,EAAA,MAAA,EAAQ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,CAAA,IAAA,EAAA,EAAhF,cAAc,IAAwE,CAAA,CAAA;AAAA,KAChH,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,IACE,uBAAAe,gBAACf,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,CAACe,0BAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA,CAAA;AAAA,KAClD,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-M3A3J5SW.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: {\n options: { output },\n },\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} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['http']} path={'msw'} />\n {faker.file && faker.name && <File.Import 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 {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginMswName,\n options: {\n output,\n },\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\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"]}
@@ -0,0 +1,130 @@
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: {
18
+ options: { output }
19
+ }
20
+ } = useApp();
21
+ const { getSchemaName, getName, getFile } = useOperationManager();
22
+ const mock = {
23
+ name: getName(operation, { type: "function" }),
24
+ file: getFile(operation)
25
+ };
26
+ const faker = {
27
+ name: getSchemaName(operation, "response", { pluginKey: [pluginFakerName], type: "function" }),
28
+ file: getFile(operation, { pluginKey: [pluginFakerName] })
29
+ };
30
+ return /* @__PURE__ */ jsxs(File, { baseName: mock.file.baseName, path: mock.file.path, meta: mock.file.meta, banner: output?.banner, footer: output?.footer, children: [
31
+ /* @__PURE__ */ jsx(File.Import, { name: ["http"], path: "msw" }),
32
+ faker.file && faker.name && /* @__PURE__ */ jsx(File.Import, { name: [faker.name], root: mock.file.path, path: faker.file.path }),
33
+ /* @__PURE__ */ jsx(Mock, { name: mock.name, fakerName: faker.name, method: operation.method, url: new URLPath(operation.path).toURLPath() })
34
+ ] });
35
+ }
36
+ });
37
+ var pluginMswName = "plugin-msw";
38
+ var pluginMsw = createPlugin((options) => {
39
+ const {
40
+ output = { path: "handlers", barrelType: "named" },
41
+ group,
42
+ exclude = [],
43
+ include,
44
+ override = [],
45
+ transformers = {},
46
+ handlers = false,
47
+ generators = [mswGenerator, handlers ? handlersGenerator : void 0].filter(Boolean)
48
+ } = options;
49
+ const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
50
+ return {
51
+ name: pluginMswName,
52
+ options: {
53
+ output
54
+ },
55
+ pre: [pluginOasName, pluginTsName, pluginFakerName],
56
+ resolvePath(baseName, pathMode, options2) {
57
+ const root = path.resolve(this.config.root, this.config.output.path);
58
+ const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
59
+ if (mode === "single") {
60
+ return path.resolve(root, output.path);
61
+ }
62
+ if (options2?.tag && group?.type === "tag") {
63
+ const tag = camelCase(options2.tag);
64
+ return path.resolve(root, renderTemplate(template, { tag }), baseName);
65
+ }
66
+ return path.resolve(root, output.path, baseName);
67
+ },
68
+ resolveName(name, type) {
69
+ const resolvedName = camelCase(name, {
70
+ suffix: type ? "handler" : void 0,
71
+ isFile: type === "file"
72
+ });
73
+ if (type) {
74
+ return transformers?.name?.(resolvedName, type) || resolvedName;
75
+ }
76
+ return resolvedName;
77
+ },
78
+ async buildStart() {
79
+ const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
80
+ const oas = await swaggerPlugin.context.getOas();
81
+ const root = path.resolve(this.config.root, this.config.output.path);
82
+ const mode = FileManager.getMode(path.resolve(root, output.path));
83
+ const operationGenerator = new OperationGenerator(this.plugin.options, {
84
+ oas,
85
+ pluginManager: this.pluginManager,
86
+ plugin: this.plugin,
87
+ contentType: swaggerPlugin.context.contentType,
88
+ exclude,
89
+ include,
90
+ override,
91
+ mode
92
+ });
93
+ const files = await operationGenerator.build(...generators);
94
+ await this.addFile(...files);
95
+ const barrelFiles = await this.fileManager.getBarrelFiles({
96
+ type: output.barrelType ?? "named",
97
+ root,
98
+ output,
99
+ files: this.fileManager.files,
100
+ meta: {
101
+ pluginKey: this.plugin.key
102
+ },
103
+ logger: this.logger
104
+ });
105
+ await this.addFile(...barrelFiles);
106
+ }
107
+ };
108
+ });
109
+ var handlersGenerator = createReactGenerator({
110
+ name: "plugin-msw",
111
+ Operations({ operations }) {
112
+ const { pluginManager, plugin } = useApp();
113
+ const { getName, getFile } = useOperationManager();
114
+ const file = pluginManager.getFile({ name: "handlers", extname: ".ts", pluginKey: [pluginMswName] });
115
+ const imports = operations.map((operation) => {
116
+ const operationFile = getFile(operation, { pluginKey: [pluginMswName] });
117
+ const operationName = getName(operation, { pluginKey: [pluginMswName], type: "function" });
118
+ return /* @__PURE__ */ jsx(File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
119
+ });
120
+ const handlers = operations.map((operation) => getName(operation, { type: "function", pluginKey: [pluginMswName] }));
121
+ return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.options.output?.banner, footer: plugin.options.output?.footer, children: [
122
+ imports,
123
+ /* @__PURE__ */ jsx(Handlers, { name: "handlers", handlers })
124
+ ] });
125
+ }
126
+ });
127
+
128
+ export { handlersGenerator, mswGenerator, pluginMsw, pluginMswName };
129
+ //# sourceMappingURL=chunk-NDX2ITTW.js.map
130
+ //# sourceMappingURL=chunk-NDX2ITTW.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,MAAQ,EAAA;AAAA,QACN,OAAA,EAAS,EAAE,MAAO,EAAA;AAAA,OACpB;AAAA,QACE,MAAkB,EAAA,CAAA;AACtB,IAAA,MAAM,EAAE,aAAA,EAAe,OAAS,EAAA,OAAA,KAAY,mBAAo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":"chunk-NDX2ITTW.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: {\n options: { output },\n },\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} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['http']} path={'msw'} />\n {faker.file && faker.name && <File.Import 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 {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginMswName,\n options: {\n output,\n },\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\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,9 +1,16 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
1
+ 'use strict';
2
2
 
3
+ var chunkGODA4G5K_cjs = require('./chunk-GODA4G5K.cjs');
3
4
 
4
- var _chunkS4P5XPFNcjs = require('./chunk-S4P5XPFN.cjs');
5
5
 
6
6
 
7
-
8
- exports.Mock = _chunkS4P5XPFNcjs.Mock; exports.Operations = _chunkS4P5XPFNcjs.Operations;
7
+ Object.defineProperty(exports, "Handlers", {
8
+ enumerable: true,
9
+ get: function () { return chunkGODA4G5K_cjs.Handlers; }
10
+ });
11
+ Object.defineProperty(exports, "Mock", {
12
+ enumerable: true,
13
+ get: function () { return chunkGODA4G5K_cjs.Mock; }
14
+ });
15
+ //# sourceMappingURL=components.cjs.map
9
16
  //# sourceMappingURL=components.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-msw/dist/components.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,yFAAC","file":"/home/runner/work/kubb/kubb/packages/plugin-msw/dist/components.cjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"components.cjs"}
@@ -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';
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';
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,9 +1,3 @@
1
- import {
2
- Mock,
3
- Operations
4
- } from "./chunk-WRIEMCYI.js";
5
- export {
6
- Mock,
7
- Operations
8
- };
1
+ export { Handlers, Mock } from './chunk-6M2QU6UL.js';
2
+ //# sourceMappingURL=components.js.map
9
3
  //# sourceMappingURL=components.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"components.js"}