@kubb/plugin-msw 3.0.0-alpha.9 → 3.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -5
- package/dist/chunk-6F4YUN2R.cjs +138 -0
- package/dist/chunk-6F4YUN2R.cjs.map +1 -0
- package/dist/chunk-6M2QU6UL.js +22 -0
- package/dist/chunk-6M2QU6UL.js.map +1 -0
- package/dist/chunk-GODA4G5K.cjs +25 -0
- package/dist/chunk-GODA4G5K.cjs.map +1 -0
- package/dist/chunk-TW2VMA3H.js +129 -0
- package/dist/chunk-TW2VMA3H.js.map +1 -0
- package/dist/components.cjs +11 -4
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +7 -70
- package/dist/components.d.ts +7 -70
- package/dist/components.js +2 -8
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +9 -0
- package/dist/generators.d.ts +9 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +11 -128
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -86
- package/dist/index.d.ts +3 -86
- package/dist/index.js +3 -133
- package/dist/index.js.map +1 -1
- package/dist/types-B3_ksuJz.d.cts +46 -0
- package/dist/types-B3_ksuJz.d.ts +46 -0
- package/package.json +22 -17
- package/src/components/Handlers.tsx +19 -0
- package/src/components/Mock.tsx +8 -86
- package/src/components/index.ts +1 -1
- package/src/generators/__snapshots__/createPet.ts +9 -0
- package/src/generators/__snapshots__/deletePet.ts +9 -0
- package/src/generators/__snapshots__/getPets.ts +9 -0
- package/src/generators/__snapshots__/handlers.ts +3 -0
- package/src/generators/__snapshots__/showPetById.ts +9 -0
- package/src/generators/handlersGenerator.tsx +32 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/mswGenerator.tsx +38 -0
- package/src/plugin.ts +34 -37
- package/src/types.ts +15 -58
- package/dist/chunk-3KHLTEUD.js +0 -104
- package/dist/chunk-3KHLTEUD.js.map +0 -1
- package/dist/chunk-BD7UJBXM.cjs +0 -104
- package/dist/chunk-BD7UJBXM.cjs.map +0 -1
- package/src/OperationGenerator.tsx +0 -66
- package/src/components/Operations.tsx +0 -94
- package/src/components/__snapshots__/Mock/Pets.ts +0 -7
- package/src/components/__snapshots__/Mock/showPetsById.ts +0 -7
package/README.md
CHANGED
|
@@ -13,12 +13,8 @@
|
|
|
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
|
-
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/
|
|
17
|
+
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a>
|
|
22
18
|
<span> · </span>
|
|
23
19
|
<a href="https://kubb.dev/" target="_blank">Documentation</a>
|
|
24
20
|
<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,138 @@
|
|
|
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
|
+
return {
|
|
56
|
+
name: pluginMswName,
|
|
57
|
+
options: {
|
|
58
|
+
output
|
|
59
|
+
},
|
|
60
|
+
pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, pluginFaker.pluginFakerName],
|
|
61
|
+
resolvePath(baseName, pathMode, options2) {
|
|
62
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
63
|
+
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
64
|
+
if (options2?.tag && group?.type === "tag") {
|
|
65
|
+
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
66
|
+
return path__default.default.resolve(root, output.path, groupName({ group: transformers.camelCase(options2.tag) }), baseName);
|
|
67
|
+
}
|
|
68
|
+
if (mode === "single") {
|
|
69
|
+
return path__default.default.resolve(root, output.path);
|
|
70
|
+
}
|
|
71
|
+
return path__default.default.resolve(root, output.path, baseName);
|
|
72
|
+
},
|
|
73
|
+
resolveName(name, type) {
|
|
74
|
+
const resolvedName = transformers.camelCase(name, {
|
|
75
|
+
suffix: type ? "handler" : void 0,
|
|
76
|
+
isFile: type === "file"
|
|
77
|
+
});
|
|
78
|
+
if (type) {
|
|
79
|
+
return transformers$1?.name?.(resolvedName, type) || resolvedName;
|
|
80
|
+
}
|
|
81
|
+
return resolvedName;
|
|
82
|
+
},
|
|
83
|
+
async buildStart() {
|
|
84
|
+
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
85
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
86
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
87
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
88
|
+
const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
|
|
89
|
+
oas,
|
|
90
|
+
pluginManager: this.pluginManager,
|
|
91
|
+
plugin: this.plugin,
|
|
92
|
+
contentType: swaggerPlugin.context.contentType,
|
|
93
|
+
exclude,
|
|
94
|
+
include,
|
|
95
|
+
override,
|
|
96
|
+
mode
|
|
97
|
+
});
|
|
98
|
+
const files = await operationGenerator.build(...generators);
|
|
99
|
+
await this.addFile(...files);
|
|
100
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
101
|
+
type: output.barrelType ?? "named",
|
|
102
|
+
root,
|
|
103
|
+
output,
|
|
104
|
+
files: this.fileManager.files,
|
|
105
|
+
meta: {
|
|
106
|
+
pluginKey: this.plugin.key
|
|
107
|
+
},
|
|
108
|
+
logger: this.logger
|
|
109
|
+
});
|
|
110
|
+
await this.addFile(...barrelFiles);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
var handlersGenerator = pluginOas.createReactGenerator({
|
|
115
|
+
name: "plugin-msw",
|
|
116
|
+
Operations({ operations }) {
|
|
117
|
+
const { pluginManager, plugin } = react.useApp();
|
|
118
|
+
const { getName, getFile } = hooks.useOperationManager();
|
|
119
|
+
const file = pluginManager.getFile({ name: "handlers", extname: ".ts", pluginKey: [pluginMswName] });
|
|
120
|
+
const imports = operations.map((operation) => {
|
|
121
|
+
const operationFile = getFile(operation, { pluginKey: [pluginMswName] });
|
|
122
|
+
const operationName = getName(operation, { pluginKey: [pluginMswName], type: "function" });
|
|
123
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
|
|
124
|
+
});
|
|
125
|
+
const handlers = operations.map((operation) => getName(operation, { type: "function", pluginKey: [pluginMswName] }));
|
|
126
|
+
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: [
|
|
127
|
+
imports,
|
|
128
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkGODA4G5K_cjs.Handlers, { name: "handlers", handlers })
|
|
129
|
+
] });
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
exports.handlersGenerator = handlersGenerator;
|
|
134
|
+
exports.mswGenerator = mswGenerator;
|
|
135
|
+
exports.pluginMsw = pluginMsw;
|
|
136
|
+
exports.pluginMswName = pluginMswName;
|
|
137
|
+
//# sourceMappingURL=chunk-6F4YUN2R.cjs.map
|
|
138
|
+
//# sourceMappingURL=chunk-6F4YUN2R.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","PluginManager","OperationGenerator","jsxs","Handlers"],"mappings":";;;;;;;;;;;;;;;;;;AAQO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,K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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,CAAA;AAAA,KAClD,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-6F4YUN2R.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, type Group, 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\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 (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"]}
|
|
@@ -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,129 @@
|
|
|
1
|
+
import { Mock, Handlers } from './chunk-6M2QU6UL.js';
|
|
2
|
+
import { URLPath } 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
|
+
return {
|
|
50
|
+
name: pluginMswName,
|
|
51
|
+
options: {
|
|
52
|
+
output
|
|
53
|
+
},
|
|
54
|
+
pre: [pluginOasName, pluginTsName, pluginFakerName],
|
|
55
|
+
resolvePath(baseName, pathMode, options2) {
|
|
56
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
57
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
58
|
+
if (options2?.tag && group?.type === "tag") {
|
|
59
|
+
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
60
|
+
return path.resolve(root, output.path, groupName({ group: camelCase(options2.tag) }), baseName);
|
|
61
|
+
}
|
|
62
|
+
if (mode === "single") {
|
|
63
|
+
return path.resolve(root, output.path);
|
|
64
|
+
}
|
|
65
|
+
return path.resolve(root, output.path, baseName);
|
|
66
|
+
},
|
|
67
|
+
resolveName(name, type) {
|
|
68
|
+
const resolvedName = camelCase(name, {
|
|
69
|
+
suffix: type ? "handler" : void 0,
|
|
70
|
+
isFile: type === "file"
|
|
71
|
+
});
|
|
72
|
+
if (type) {
|
|
73
|
+
return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
74
|
+
}
|
|
75
|
+
return resolvedName;
|
|
76
|
+
},
|
|
77
|
+
async buildStart() {
|
|
78
|
+
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
79
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
80
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
81
|
+
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
82
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
83
|
+
oas,
|
|
84
|
+
pluginManager: this.pluginManager,
|
|
85
|
+
plugin: this.plugin,
|
|
86
|
+
contentType: swaggerPlugin.context.contentType,
|
|
87
|
+
exclude,
|
|
88
|
+
include,
|
|
89
|
+
override,
|
|
90
|
+
mode
|
|
91
|
+
});
|
|
92
|
+
const files = await operationGenerator.build(...generators);
|
|
93
|
+
await this.addFile(...files);
|
|
94
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
95
|
+
type: output.barrelType ?? "named",
|
|
96
|
+
root,
|
|
97
|
+
output,
|
|
98
|
+
files: this.fileManager.files,
|
|
99
|
+
meta: {
|
|
100
|
+
pluginKey: this.plugin.key
|
|
101
|
+
},
|
|
102
|
+
logger: this.logger
|
|
103
|
+
});
|
|
104
|
+
await this.addFile(...barrelFiles);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
var handlersGenerator = createReactGenerator({
|
|
109
|
+
name: "plugin-msw",
|
|
110
|
+
Operations({ operations }) {
|
|
111
|
+
const { pluginManager, plugin } = useApp();
|
|
112
|
+
const { getName, getFile } = useOperationManager();
|
|
113
|
+
const file = pluginManager.getFile({ name: "handlers", extname: ".ts", pluginKey: [pluginMswName] });
|
|
114
|
+
const imports = operations.map((operation) => {
|
|
115
|
+
const operationFile = getFile(operation, { pluginKey: [pluginMswName] });
|
|
116
|
+
const operationName = getName(operation, { pluginKey: [pluginMswName], type: "function" });
|
|
117
|
+
return /* @__PURE__ */ jsx(File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
|
|
118
|
+
});
|
|
119
|
+
const handlers = operations.map((operation) => getName(operation, { type: "function", pluginKey: [pluginMswName] }));
|
|
120
|
+
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.options.output?.banner, footer: plugin.options.output?.footer, children: [
|
|
121
|
+
imports,
|
|
122
|
+
/* @__PURE__ */ jsx(Handlers, { name: "handlers", handlers })
|
|
123
|
+
] });
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
export { handlersGenerator, mswGenerator, pluginMsw, pluginMswName };
|
|
128
|
+
//# sourceMappingURL=chunk-TW2VMA3H.js.map
|
|
129
|
+
//# sourceMappingURL=chunk-TW2VMA3H.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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,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-TW2VMA3H.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, type Group, 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\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 (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"]}
|
package/dist/components.cjs
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkGODA4G5K_cjs = require('./chunk-GODA4G5K.cjs');
|
|
3
4
|
|
|
4
|
-
var _chunkBD7UJBXMcjs = require('./chunk-BD7UJBXM.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
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
|
package/dist/components.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"components.cjs"}
|
package/dist/components.d.cts
CHANGED
|
@@ -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
|
|
4
|
+
type Props = {
|
|
7
5
|
/**
|
|
8
6
|
* Name of the function
|
|
9
7
|
*/
|
|
10
8
|
name: string;
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
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
|
|
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 {
|
|
24
|
+
export { Handlers, Mock };
|
package/dist/components.d.ts
CHANGED
|
@@ -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
|
|
4
|
+
type Props = {
|
|
7
5
|
/**
|
|
8
6
|
* Name of the function
|
|
9
7
|
*/
|
|
10
8
|
name: string;
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
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
|
|
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 {
|
|
24
|
+
export { Handlers, Mock };
|
package/dist/components.js
CHANGED
package/dist/components.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"components.js"}
|