@kubb/plugin-msw 0.0.0-canary-20241104172400
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/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/chunk-IUWTMC3G.js +155 -0
- package/dist/chunk-IUWTMC3G.js.map +1 -0
- package/dist/chunk-QXK7PR6Z.cjs +164 -0
- package/dist/chunk-QXK7PR6Z.cjs.map +1 -0
- package/dist/chunk-XLGN5MEF.cjs +45 -0
- package/dist/chunk-XLGN5MEF.cjs.map +1 -0
- package/dist/chunk-YG3WMS3Q.js +41 -0
- package/dist/chunk-YG3WMS3Q.js.map +1 -0
- package/dist/components.cjs +20 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +37 -0
- package/dist/components.d.ts +37 -0
- package/dist/components.js +3 -0
- package/dist/components.js.map +1 -0
- 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 +17 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/types-BaK4s79H.d.cts +55 -0
- package/dist/types-BaK4s79H.d.ts +55 -0
- package/package.json +114 -0
- package/src/components/Handlers.tsx +19 -0
- package/src/components/Mock.tsx +38 -0
- package/src/components/MockWithFaker.tsx +38 -0
- package/src/components/index.ts +3 -0
- package/src/generators/__snapshots__/createPet.ts +11 -0
- package/src/generators/__snapshots__/deletePet.ts +11 -0
- package/src/generators/__snapshots__/getPets.ts +11 -0
- package/src/generators/__snapshots__/getPetsFaker.ts +11 -0
- package/src/generators/__snapshots__/handlers.ts +3 -0
- package/src/generators/__snapshots__/showPetById.ts +11 -0
- package/src/generators/handlersGenerator.tsx +32 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/mswGenerator.tsx +64 -0
- package/src/index.ts +2 -0
- package/src/plugin.ts +104 -0
- package/src/types.ts +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Stijn Van Hulle
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<!-- <img src="assets/logo.png" alt="logo" width="200" height="auto" /> -->
|
|
4
|
+
<h1>@kubb/plugin-msw</h1>
|
|
5
|
+
|
|
6
|
+
<p>
|
|
7
|
+
Swagger integration to create mock data based on MSW
|
|
8
|
+
</p>
|
|
9
|
+
<img src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/banner.png" alt="logo" height="auto" />
|
|
10
|
+
|
|
11
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
12
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
13
|
+
[![Coverage][coverage-src]][coverage-href]
|
|
14
|
+
[![License][license-src]][license-href]
|
|
15
|
+
|
|
16
|
+
<h4>
|
|
17
|
+
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a>
|
|
18
|
+
<span> · </span>
|
|
19
|
+
<a href="https://kubb.dev/" target="_blank">Documentation</a>
|
|
20
|
+
<span> · </span>
|
|
21
|
+
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
|
|
22
|
+
<span> · </span>
|
|
23
|
+
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Request Feature</a>
|
|
24
|
+
</h4>
|
|
25
|
+
</div>
|
|
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
|
+
|
|
40
|
+
<!-- Badges -->
|
|
41
|
+
|
|
42
|
+
[npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-msw?flat&colorA=18181B&colorB=f58517
|
|
43
|
+
[npm-version-href]: https://npmjs.com/package/@kubb/plugin-msw
|
|
44
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/plugin-msw?flat&colorA=18181B&colorB=f58517
|
|
45
|
+
[npm-downloads-href]: https://npmjs.com/package/@kubb/plugin-msw
|
|
46
|
+
[license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517
|
|
47
|
+
[license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
|
|
48
|
+
[build-src]: https://img.shields.io/github/actions/workflow/status/kubb-labs/kubb/ci.yaml?style=flat&colorA=18181B&colorB=f58517
|
|
49
|
+
[build-href]: https://www.npmjs.com/package/@kubb/plugin-msw
|
|
50
|
+
[minified-src]: https://img.shields.io/bundlephobia/min/@kubb/plugin-msw?style=flat&colorA=18181B&colorB=f58517
|
|
51
|
+
[minified-href]: https://www.npmjs.com/package/@kubb/plugin-msw
|
|
52
|
+
[coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
|
|
53
|
+
[coverage-href]: https://www.npmjs.com/package/@kubb/plugin-msw
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { MockWithFaker, Mock, Handlers } from './chunk-YG3WMS3Q.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 { pluginTsName } from '@kubb/plugin-ts';
|
|
7
|
+
import { useApp, File } from '@kubb/react';
|
|
8
|
+
import { jsxs, jsx } from '@kubb/react/jsx-runtime';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
11
|
+
import { camelCase } from '@kubb/core/transformers';
|
|
12
|
+
|
|
13
|
+
var mswGenerator = createReactGenerator({
|
|
14
|
+
name: "msw",
|
|
15
|
+
Operation({ operation }) {
|
|
16
|
+
const {
|
|
17
|
+
plugin: {
|
|
18
|
+
options: { output, parser }
|
|
19
|
+
}
|
|
20
|
+
} = useApp();
|
|
21
|
+
const { getSchemas, getName, getFile } = useOperationManager();
|
|
22
|
+
const mock = {
|
|
23
|
+
name: getName(operation, { type: "function" }),
|
|
24
|
+
file: getFile(operation)
|
|
25
|
+
};
|
|
26
|
+
const faker = {
|
|
27
|
+
file: getFile(operation, { pluginKey: [pluginFakerName] }),
|
|
28
|
+
schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: "function" })
|
|
29
|
+
};
|
|
30
|
+
const type = {
|
|
31
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
32
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
|
|
33
|
+
};
|
|
34
|
+
return /* @__PURE__ */ jsxs(File, { baseName: mock.file.baseName, path: mock.file.path, meta: mock.file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
35
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["http"], path: "msw" }),
|
|
36
|
+
/* @__PURE__ */ jsx(File.Import, { name: [type.schemas.response.name], path: type.file.path, root: mock.file.path, isTypeOnly: true }),
|
|
37
|
+
parser === "faker" && faker.file && faker.schemas.response && /* @__PURE__ */ jsx(File.Import, { name: [faker.schemas.response.name], root: mock.file.path, path: faker.file.path }),
|
|
38
|
+
parser === "faker" && /* @__PURE__ */ jsx(
|
|
39
|
+
MockWithFaker,
|
|
40
|
+
{
|
|
41
|
+
name: mock.name,
|
|
42
|
+
typeName: type.schemas.response.name,
|
|
43
|
+
fakerName: faker.schemas.response.name,
|
|
44
|
+
method: operation.method,
|
|
45
|
+
url: new URLPath(operation.path).toURLPath()
|
|
46
|
+
}
|
|
47
|
+
),
|
|
48
|
+
parser === "data" && /* @__PURE__ */ jsx(
|
|
49
|
+
Mock,
|
|
50
|
+
{
|
|
51
|
+
name: mock.name,
|
|
52
|
+
typeName: type.schemas.response.name,
|
|
53
|
+
fakerName: faker.schemas.response.name,
|
|
54
|
+
method: operation.method,
|
|
55
|
+
url: new URLPath(operation.path).toURLPath()
|
|
56
|
+
}
|
|
57
|
+
)
|
|
58
|
+
] });
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
var pluginMswName = "plugin-msw";
|
|
62
|
+
var pluginMsw = createPlugin((options) => {
|
|
63
|
+
const {
|
|
64
|
+
output = { path: "handlers", barrelType: "named" },
|
|
65
|
+
group,
|
|
66
|
+
exclude = [],
|
|
67
|
+
include,
|
|
68
|
+
override = [],
|
|
69
|
+
transformers = {},
|
|
70
|
+
handlers = false,
|
|
71
|
+
parser = "data",
|
|
72
|
+
generators = [mswGenerator, handlers ? handlersGenerator : void 0].filter(Boolean)
|
|
73
|
+
} = options;
|
|
74
|
+
return {
|
|
75
|
+
name: pluginMswName,
|
|
76
|
+
options: {
|
|
77
|
+
output,
|
|
78
|
+
parser
|
|
79
|
+
},
|
|
80
|
+
pre: [pluginOasName, pluginTsName, parser === "faker" ? pluginFakerName : void 0].filter(Boolean),
|
|
81
|
+
resolvePath(baseName, pathMode, options2) {
|
|
82
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
83
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
84
|
+
if (options2?.tag && group?.type === "tag") {
|
|
85
|
+
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
86
|
+
return path.resolve(root, output.path, groupName({ group: camelCase(options2.tag) }), baseName);
|
|
87
|
+
}
|
|
88
|
+
if (mode === "single") {
|
|
89
|
+
return path.resolve(root, output.path);
|
|
90
|
+
}
|
|
91
|
+
return path.resolve(root, output.path, baseName);
|
|
92
|
+
},
|
|
93
|
+
resolveName(name, type) {
|
|
94
|
+
const resolvedName = camelCase(name, {
|
|
95
|
+
suffix: type ? "handler" : void 0,
|
|
96
|
+
isFile: type === "file"
|
|
97
|
+
});
|
|
98
|
+
if (type) {
|
|
99
|
+
return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
100
|
+
}
|
|
101
|
+
return resolvedName;
|
|
102
|
+
},
|
|
103
|
+
async buildStart() {
|
|
104
|
+
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
105
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
106
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
107
|
+
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
108
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
109
|
+
oas,
|
|
110
|
+
pluginManager: this.pluginManager,
|
|
111
|
+
plugin: this.plugin,
|
|
112
|
+
contentType: swaggerPlugin.context.contentType,
|
|
113
|
+
exclude,
|
|
114
|
+
include,
|
|
115
|
+
override,
|
|
116
|
+
mode
|
|
117
|
+
});
|
|
118
|
+
const files = await operationGenerator.build(...generators);
|
|
119
|
+
await this.addFile(...files);
|
|
120
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
121
|
+
type: output.barrelType ?? "named",
|
|
122
|
+
root,
|
|
123
|
+
output,
|
|
124
|
+
files: this.fileManager.files,
|
|
125
|
+
meta: {
|
|
126
|
+
pluginKey: this.plugin.key
|
|
127
|
+
},
|
|
128
|
+
logger: this.logger
|
|
129
|
+
});
|
|
130
|
+
await this.addFile(...barrelFiles);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
var handlersGenerator = createReactGenerator({
|
|
135
|
+
name: "plugin-msw",
|
|
136
|
+
Operations({ operations }) {
|
|
137
|
+
const { pluginManager, plugin } = useApp();
|
|
138
|
+
const { getName, getFile } = useOperationManager();
|
|
139
|
+
const file = pluginManager.getFile({ name: "handlers", extname: ".ts", pluginKey: [pluginMswName] });
|
|
140
|
+
const imports = operations.map((operation) => {
|
|
141
|
+
const operationFile = getFile(operation, { pluginKey: [pluginMswName] });
|
|
142
|
+
const operationName = getName(operation, { pluginKey: [pluginMswName], type: "function" });
|
|
143
|
+
return /* @__PURE__ */ jsx(File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
|
|
144
|
+
});
|
|
145
|
+
const handlers = operations.map((operation) => `${getName(operation, { type: "function", pluginKey: [pluginMswName] })}()`);
|
|
146
|
+
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.options.output?.banner, footer: plugin.options.output?.footer, children: [
|
|
147
|
+
imports,
|
|
148
|
+
/* @__PURE__ */ jsx(Handlers, { name: "handlers", handlers })
|
|
149
|
+
] });
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
export { handlersGenerator, mswGenerator, pluginMsw, pluginMswName };
|
|
154
|
+
//# sourceMappingURL=chunk-IUWTMC3G.js.map
|
|
155
|
+
//# sourceMappingURL=chunk-IUWTMC3G.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/plugin.ts","../src/generators/handlersGenerator.tsx"],"names":["pluginTsName","pluginFakerName","options","createReactGenerator","useApp","useOperationManager","jsx","File","jsxs"],"mappings":";;;;;;;;;;;;AASO,IAAM,eAAe,oBAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,MACJ,MAAQ,EAAA;AAAA,QACN,OAAA,EAAS,EAAE,MAAA,EAAQ,MAAO;AAAA;AAC5B,QACE,MAAkB,EAAA;AACtB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAY,mBAAoB,EAAA;AAE7D,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS;AAAA,KACzB;AAEA,IAAA,MAAM,KAAQ,GAAA;AAAA,MACZ,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAAC,eAAe,GAA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IAAwE,CAAA;AAAA,KAChH,CAAA;AAED,IAAA,MAAM,WAAW,UAAW,CAAA,GAAA,CAAI,CAAC,SAAA,KAAc,GAAG,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,SAAW,EAAA,CAAC,aAAa,CAAE,EAAC,CAAC,CAAI,EAAA,CAAA,CAAA;AAE1H,IACE,uBAAAC,KAACD,IAAA,EAAA,EAAK,UAAU,IAAK,CAAA,QAAA,EAAU,IAAM,EAAA,IAAA,CAAK,IAAM,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,MAAA,EAAQ,OAAO,OAAQ,CAAA,MAAA,EAAQ,QAAQ,MAAQ,EAAA,MAAA,CAAO,OAAQ,CAAA,MAAA,EAAQ,MACpI,EAAA,QAAA,EAAA;AAAA,MAAA,OAAA;AAAA,sBACDD,GAAAA,CAAC,QAAS,EAAA,EAAA,IAAA,EAAM,YAAY,QAAoB,EAAA;AAAA,KAClD,EAAA,CAAA;AAAA;AAGN,CAAC","file":"chunk-IUWTMC3G.js","sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Mock, MockWithFaker } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n plugin: {\n options: { output, parser },\n },\n } = useApp<PluginMsw>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['http']} path={'msw'} />\n <File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />\n {parser === 'faker' && faker.file && faker.schemas.response && (\n <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />\n )}\n\n {parser === 'faker' && (\n <MockWithFaker\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n url={new URLPath(operation.path).toURLPath()}\n />\n )}\n {parser === 'data' && (\n <Mock\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n url={new URLPath(operation.path).toURLPath()}\n />\n )}\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n parser = 'data',\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n },\n pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\nimport { pluginMswName } from '../plugin.ts'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: [pluginMswName] })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: [pluginMswName] })\n const operationName = getName(operation, { pluginKey: [pluginMswName], type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => `${getName(operation, { type: 'function', pluginKey: [pluginMswName] })}()`)\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkXLGN5MEF_cjs = require('./chunk-XLGN5MEF.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 pluginTs = require('@kubb/plugin-ts');
|
|
9
|
+
var react = require('@kubb/react');
|
|
10
|
+
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
11
|
+
var path = require('path');
|
|
12
|
+
var core = require('@kubb/core');
|
|
13
|
+
var transformers = require('@kubb/core/transformers');
|
|
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, parser }
|
|
25
|
+
}
|
|
26
|
+
} = react.useApp();
|
|
27
|
+
const { getSchemas, getName, getFile } = hooks.useOperationManager();
|
|
28
|
+
const mock = {
|
|
29
|
+
name: getName(operation, { type: "function" }),
|
|
30
|
+
file: getFile(operation)
|
|
31
|
+
};
|
|
32
|
+
const faker = {
|
|
33
|
+
file: getFile(operation, { pluginKey: [pluginFaker.pluginFakerName] }),
|
|
34
|
+
schemas: getSchemas(operation, { pluginKey: [pluginFaker.pluginFakerName], type: "function" })
|
|
35
|
+
};
|
|
36
|
+
const type = {
|
|
37
|
+
file: getFile(operation, { pluginKey: [pluginTs.pluginTsName] }),
|
|
38
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" })
|
|
39
|
+
};
|
|
40
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: mock.file.baseName, path: mock.file.path, meta: mock.file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
41
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["http"], path: "msw" }),
|
|
42
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [type.schemas.response.name], path: type.file.path, root: mock.file.path, isTypeOnly: true }),
|
|
43
|
+
parser === "faker" && faker.file && faker.schemas.response && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [faker.schemas.response.name], root: mock.file.path, path: faker.file.path }),
|
|
44
|
+
parser === "faker" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
45
|
+
chunkXLGN5MEF_cjs.MockWithFaker,
|
|
46
|
+
{
|
|
47
|
+
name: mock.name,
|
|
48
|
+
typeName: type.schemas.response.name,
|
|
49
|
+
fakerName: faker.schemas.response.name,
|
|
50
|
+
method: operation.method,
|
|
51
|
+
url: new utils.URLPath(operation.path).toURLPath()
|
|
52
|
+
}
|
|
53
|
+
),
|
|
54
|
+
parser === "data" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
55
|
+
chunkXLGN5MEF_cjs.Mock,
|
|
56
|
+
{
|
|
57
|
+
name: mock.name,
|
|
58
|
+
typeName: type.schemas.response.name,
|
|
59
|
+
fakerName: faker.schemas.response.name,
|
|
60
|
+
method: operation.method,
|
|
61
|
+
url: new utils.URLPath(operation.path).toURLPath()
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
] });
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
var pluginMswName = "plugin-msw";
|
|
68
|
+
var pluginMsw = core.createPlugin((options) => {
|
|
69
|
+
const {
|
|
70
|
+
output = { path: "handlers", barrelType: "named" },
|
|
71
|
+
group,
|
|
72
|
+
exclude = [],
|
|
73
|
+
include,
|
|
74
|
+
override = [],
|
|
75
|
+
transformers: transformers$1 = {},
|
|
76
|
+
handlers = false,
|
|
77
|
+
parser = "data",
|
|
78
|
+
generators = [mswGenerator, handlers ? handlersGenerator : void 0].filter(Boolean)
|
|
79
|
+
} = options;
|
|
80
|
+
return {
|
|
81
|
+
name: pluginMswName,
|
|
82
|
+
options: {
|
|
83
|
+
output,
|
|
84
|
+
parser
|
|
85
|
+
},
|
|
86
|
+
pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, parser === "faker" ? pluginFaker.pluginFakerName : void 0].filter(Boolean),
|
|
87
|
+
resolvePath(baseName, pathMode, options2) {
|
|
88
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
89
|
+
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
90
|
+
if (options2?.tag && group?.type === "tag") {
|
|
91
|
+
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
92
|
+
return path__default.default.resolve(root, output.path, groupName({ group: transformers.camelCase(options2.tag) }), baseName);
|
|
93
|
+
}
|
|
94
|
+
if (mode === "single") {
|
|
95
|
+
return path__default.default.resolve(root, output.path);
|
|
96
|
+
}
|
|
97
|
+
return path__default.default.resolve(root, output.path, baseName);
|
|
98
|
+
},
|
|
99
|
+
resolveName(name, type) {
|
|
100
|
+
const resolvedName = transformers.camelCase(name, {
|
|
101
|
+
suffix: type ? "handler" : void 0,
|
|
102
|
+
isFile: type === "file"
|
|
103
|
+
});
|
|
104
|
+
if (type) {
|
|
105
|
+
return transformers$1?.name?.(resolvedName, type) || resolvedName;
|
|
106
|
+
}
|
|
107
|
+
return resolvedName;
|
|
108
|
+
},
|
|
109
|
+
async buildStart() {
|
|
110
|
+
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
111
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
112
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
113
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
114
|
+
const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
|
|
115
|
+
oas,
|
|
116
|
+
pluginManager: this.pluginManager,
|
|
117
|
+
plugin: this.plugin,
|
|
118
|
+
contentType: swaggerPlugin.context.contentType,
|
|
119
|
+
exclude,
|
|
120
|
+
include,
|
|
121
|
+
override,
|
|
122
|
+
mode
|
|
123
|
+
});
|
|
124
|
+
const files = await operationGenerator.build(...generators);
|
|
125
|
+
await this.addFile(...files);
|
|
126
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
127
|
+
type: output.barrelType ?? "named",
|
|
128
|
+
root,
|
|
129
|
+
output,
|
|
130
|
+
files: this.fileManager.files,
|
|
131
|
+
meta: {
|
|
132
|
+
pluginKey: this.plugin.key
|
|
133
|
+
},
|
|
134
|
+
logger: this.logger
|
|
135
|
+
});
|
|
136
|
+
await this.addFile(...barrelFiles);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
var handlersGenerator = pluginOas.createReactGenerator({
|
|
141
|
+
name: "plugin-msw",
|
|
142
|
+
Operations({ operations }) {
|
|
143
|
+
const { pluginManager, plugin } = react.useApp();
|
|
144
|
+
const { getName, getFile } = hooks.useOperationManager();
|
|
145
|
+
const file = pluginManager.getFile({ name: "handlers", extname: ".ts", pluginKey: [pluginMswName] });
|
|
146
|
+
const imports = operations.map((operation) => {
|
|
147
|
+
const operationFile = getFile(operation, { pluginKey: [pluginMswName] });
|
|
148
|
+
const operationName = getName(operation, { pluginKey: [pluginMswName], type: "function" });
|
|
149
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
|
|
150
|
+
});
|
|
151
|
+
const handlers = operations.map((operation) => `${getName(operation, { type: "function", pluginKey: [pluginMswName] })}()`);
|
|
152
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.options.output?.banner, footer: plugin.options.output?.footer, children: [
|
|
153
|
+
imports,
|
|
154
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkXLGN5MEF_cjs.Handlers, { name: "handlers", handlers })
|
|
155
|
+
] });
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
exports.handlersGenerator = handlersGenerator;
|
|
160
|
+
exports.mswGenerator = mswGenerator;
|
|
161
|
+
exports.pluginMsw = pluginMsw;
|
|
162
|
+
exports.pluginMswName = pluginMswName;
|
|
163
|
+
//# sourceMappingURL=chunk-QXK7PR6Z.cjs.map
|
|
164
|
+
//# sourceMappingURL=chunk-QXK7PR6Z.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/mswGenerator.tsx","../src/plugin.ts","../src/generators/handlersGenerator.tsx"],"names":["createReactGenerator","useApp","useOperationManager","pluginFakerName","pluginTsName","File","jsx","MockWithFaker","URLPath","Mock","createPlugin","transformers","pluginOasName","options","path","FileManager","camelCase","PluginManager","OperationGenerator","jsxs","Handlers"],"mappings":";;;;;;;;;;;;;;;;;;AASO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAA,CAAU,EAAE,SAAA,EAAa,EAAA;AACvB,IAAM,MAAA;AAAA,M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'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Mock, MockWithFaker } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation }) {\n const {\n plugin: {\n options: { output, parser },\n },\n } = useApp<PluginMsw>()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginKey: [pluginFakerName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n return (\n <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['http']} path={'msw'} />\n <File.Import name={[type.schemas.response.name]} path={type.file.path} root={mock.file.path} isTypeOnly />\n {parser === 'faker' && faker.file && faker.schemas.response && (\n <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />\n )}\n\n {parser === 'faker' && (\n <MockWithFaker\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n url={new URLPath(operation.path).toURLPath()}\n />\n )}\n {parser === 'data' && (\n <Mock\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n method={operation.method}\n url={new URLPath(operation.path).toURLPath()}\n />\n )}\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n parser = 'data',\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n },\n pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Handlers } from '../components/Handlers.tsx'\nimport { pluginMswName } from '../plugin.ts'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations }) {\n const { pluginManager, plugin } = useApp<PluginMsw>()\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: [pluginMswName] })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: [pluginMswName] })\n const operationName = getName(operation, { pluginKey: [pluginMswName], type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => `${getName(operation, { type: 'function', pluginKey: [pluginMswName] })}()`)\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
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, typeName, url, method }) {
|
|
8
|
+
const params = react.FunctionParams.factory({
|
|
9
|
+
data: {
|
|
10
|
+
type: typeName,
|
|
11
|
+
optional: true
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('*${url}', function handler(info) {
|
|
15
|
+
return new Response(JSON.stringify(data), {
|
|
16
|
+
headers: {
|
|
17
|
+
'Content-Type': 'application/json',
|
|
18
|
+
},
|
|
19
|
+
})
|
|
20
|
+
})` }) });
|
|
21
|
+
}
|
|
22
|
+
function Handlers({ name, handlers }) {
|
|
23
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
|
|
24
|
+
}
|
|
25
|
+
function MockWithFaker({ name, fakerName, typeName, url, method }) {
|
|
26
|
+
const params = react.FunctionParams.factory({
|
|
27
|
+
data: {
|
|
28
|
+
type: typeName,
|
|
29
|
+
optional: true
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('*${url}', function handler(info) {
|
|
33
|
+
return new Response(JSON.stringify(${fakerName}(data)), {
|
|
34
|
+
headers: {
|
|
35
|
+
'Content-Type': 'application/json',
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
})` }) });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.Handlers = Handlers;
|
|
42
|
+
exports.Mock = Mock;
|
|
43
|
+
exports.MockWithFaker = MockWithFaker;
|
|
44
|
+
//# sourceMappingURL=chunk-XLGN5MEF.cjs.map
|
|
45
|
+
//# sourceMappingURL=chunk-XLGN5MEF.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/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BAAAC,cAACC,CAAAA,UAAAA,CAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,YAAY,EAAA,IAAA,EAC/C,QAAAD,kBAAAA,cAAAA,CAACE,gBAAA,EAAS,IAAA,EAAY,MAAM,EAAA,IAAA,EAAC,MAAQ,EAAA,MAAA,CAAO,eACzC,EAAA,QAAA,EAAA,CAAA,YAAA,EAAe,MAAM,CAAA,GAAA,EAAM,GAAG,CAAA;AAAA,uCAAA,EACE,SAAS,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAM5C,CACF,EAAA,CAAA;AAEJ","file":"chunk-XLGN5MEF.cjs","sourcesContent":["import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function Mock({ name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: typeName,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n return new Response(JSON.stringify(data), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n","import { File } from '@kubb/react'\nimport type { ReactNode } from 'react'\n\ntype HandlersProps = {\n /**\n * Name of the function\n */\n name: string\n // custom\n handlers: string[]\n}\n\nexport function Handlers({ name, handlers }: HandlersProps): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}\n </File.Source>\n )\n}\n","import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: typeName,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n return new Response(JSON.stringify(${fakerName}(data)), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { FunctionParams, File, Function } from '@kubb/react';
|
|
2
|
+
import { jsx } from '@kubb/react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
// src/components/Mock.tsx
|
|
5
|
+
function Mock({ name, fakerName, typeName, url, method }) {
|
|
6
|
+
const params = FunctionParams.factory({
|
|
7
|
+
data: {
|
|
8
|
+
type: typeName,
|
|
9
|
+
optional: true
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsx(Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('*${url}', function handler(info) {
|
|
13
|
+
return new Response(JSON.stringify(data), {
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': 'application/json',
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
})` }) });
|
|
19
|
+
}
|
|
20
|
+
function Handlers({ name, handlers }) {
|
|
21
|
+
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
|
|
22
|
+
}
|
|
23
|
+
function MockWithFaker({ name, fakerName, typeName, url, method }) {
|
|
24
|
+
const params = FunctionParams.factory({
|
|
25
|
+
data: {
|
|
26
|
+
type: typeName,
|
|
27
|
+
optional: true
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return /* @__PURE__ */ jsx(File.Source, { name, isIndexable: true, isExportable: true, children: /* @__PURE__ */ jsx(Function, { name, export: true, params: params.toConstructor(), children: `return http.${method}('*${url}', function handler(info) {
|
|
31
|
+
return new Response(JSON.stringify(${fakerName}(data)), {
|
|
32
|
+
headers: {
|
|
33
|
+
'Content-Type': 'application/json',
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
})` }) });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { Handlers, Mock, MockWithFaker };
|
|
40
|
+
//# sourceMappingURL=chunk-YG3WMS3Q.js.map
|
|
41
|
+
//# sourceMappingURL=chunk-YG3WMS3Q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Mock.tsx","../src/components/Handlers.tsx","../src/components/MockWithFaker.tsx"],"names":["jsx","File","FunctionParams","Function"],"mappings":";;;;AAgBO,SAAS,KAAK,EAAE,IAAA,EAAM,WAAW,QAAU,EAAA,GAAA,EAAK,QAA4B,EAAA;AACjF,EAAM,MAAA,MAAA,GAAS,eAAe,OAAQ,CAAA;AAAA,IACpC,IAAM,EAAA;AAAA,MACJ,IAAM,EAAA,QAAA;AAAA,MACN,QAAU,EAAA;AAAA;AACZ,GACD,CAAA;AAED,EACE,uBAAA,GAAA,CAAC,KAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,cAAY,IAC/C,EAAA,QAAA,kBAAA,GAAA,CAAC,YAAS,IAAY,EAAA,MAAA,EAAM,MAAC,MAAQ,EAAA,MAAA,CAAO,eACzC,EAAA,QAAA,EAAA,CAAA,YAAA,EAAe,MAAM,CAAA,GAAA,EAAM,GAAG,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAOjC,CACF,EAAA,CAAA;AAEJ;ACzBO,SAAS,QAAS,CAAA,EAAE,IAAM,EAAA,QAAA,EAAsC,EAAA;AACrE,EACE,uBAAAA,IAACC,IAAK,CAAA,MAAA,EAAL,EAAY,IAAY,EAAA,WAAA,EAAW,MAAC,YAAY,EAAA,IAAA,EAC9C,0BAAgB,IAAI,CAAA,GAAA,EAAM,KAAK,SAAU,CAAA,QAAQ,EAAE,UAAW,CAAA,CAAA,CAAA,CAAA,EAAK,EAAE,CAAC,CACzE,SAAA,CAAA,EAAA,CAAA;AAEJ;ACFO,SAAS,cAAc,EAAE,IAAA,EAAM,WAAW,QAAU,EAAA,GAAA,EAAK,QAA4B,EAAA;AAC1F,EAAM,MAAA,MAAA,GAASC,eAAe,OAAQ,CAAA;AAAA,IACpC,IAAM,EAAA;AAAA,MACJ,IAAM,EAAA,QAAA;AAAA,MACN,QAAU,EAAA;AAAA;AACZ,GACD,CAAA;AAED,EACE,uBAAAF,GAACC,CAAAA,IAAAA,CAAK,MAAL,EAAA,EAAY,MAAY,WAAW,EAAA,IAAA,EAAC,YAAY,EAAA,IAAA,EAC/C,QAAAD,kBAAAA,GAAAA,CAACG,UAAA,EAAS,IAAA,EAAY,MAAM,EAAA,IAAA,EAAC,MAAQ,EAAA,MAAA,CAAO,eACzC,EAAA,QAAA,EAAA,CAAA,YAAA,EAAe,MAAM,CAAA,GAAA,EAAM,GAAG,CAAA;AAAA,uCAAA,EACE,SAAS,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,CAAA,EAM5C,CACF,EAAA,CAAA;AAEJ","file":"chunk-YG3WMS3Q.js","sourcesContent":["import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function Mock({ name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: typeName,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n return new Response(JSON.stringify(data), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n","import { File } from '@kubb/react'\nimport type { ReactNode } from 'react'\n\ntype HandlersProps = {\n /**\n * Name of the function\n */\n name: string\n // custom\n handlers: string[]\n}\n\nexport function Handlers({ name, handlers }: HandlersProps): ReactNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}\n </File.Source>\n )\n}\n","import { File, Function, FunctionParams } from '@kubb/react'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n url: string\n method: HttpMethod\n}\n\nexport function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode {\n const params = FunctionParams.factory({\n data: {\n type: typeName,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('*${url}', function handler(info) {\n return new Response(JSON.stringify(${fakerName}(data)), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkXLGN5MEF_cjs = require('./chunk-XLGN5MEF.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "Handlers", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunkXLGN5MEF_cjs.Handlers; }
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "Mock", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return chunkXLGN5MEF_cjs.Mock; }
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "MockWithFaker", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return chunkXLGN5MEF_cjs.MockWithFaker; }
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=components.cjs.map
|
|
20
|
+
//# sourceMappingURL=components.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"components.cjs"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { HttpMethod } from '@kubb/oas';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
type Props$1 = {
|
|
5
|
+
/**
|
|
6
|
+
* Name of the function
|
|
7
|
+
*/
|
|
8
|
+
name: string;
|
|
9
|
+
typeName: string;
|
|
10
|
+
fakerName: string;
|
|
11
|
+
url: string;
|
|
12
|
+
method: HttpMethod;
|
|
13
|
+
};
|
|
14
|
+
declare function Mock({ name, fakerName, typeName, url, method }: Props$1): ReactNode;
|
|
15
|
+
|
|
16
|
+
type HandlersProps = {
|
|
17
|
+
/**
|
|
18
|
+
* Name of the function
|
|
19
|
+
*/
|
|
20
|
+
name: string;
|
|
21
|
+
handlers: string[];
|
|
22
|
+
};
|
|
23
|
+
declare function Handlers({ name, handlers }: HandlersProps): ReactNode;
|
|
24
|
+
|
|
25
|
+
type Props = {
|
|
26
|
+
/**
|
|
27
|
+
* Name of the function
|
|
28
|
+
*/
|
|
29
|
+
name: string;
|
|
30
|
+
typeName: string;
|
|
31
|
+
fakerName: string;
|
|
32
|
+
url: string;
|
|
33
|
+
method: HttpMethod;
|
|
34
|
+
};
|
|
35
|
+
declare function MockWithFaker({ name, fakerName, typeName, url, method }: Props): ReactNode;
|
|
36
|
+
|
|
37
|
+
export { Handlers, Mock, MockWithFaker };
|