@kubb/plugin-msw 5.0.0-alpha.5 → 5.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{generators-DFhPHY4V.cjs → generators-CY1SNd5X.cjs} +6 -6
- package/dist/generators-CY1SNd5X.cjs.map +1 -0
- package/dist/{generators-Cs46KGm7.js → generators-CvyZTxOm.js} +7 -7
- package/dist/generators-CvyZTxOm.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +3 -3
- package/dist/generators.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/generators/handlersGenerator.tsx +4 -4
- package/src/generators/mswGenerator.tsx +3 -3
- package/src/plugin.ts +1 -1
- package/dist/generators-Cs46KGm7.js.map +0 -1
- package/dist/generators-DFhPHY4V.cjs.map +0 -1
|
@@ -11,10 +11,10 @@ let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
|
|
|
11
11
|
const handlersGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
12
12
|
name: "plugin-msw",
|
|
13
13
|
Operations({ operations, generator, plugin }) {
|
|
14
|
-
const
|
|
14
|
+
const driver = (0, _kubb_core_hooks.usePluginDriver)();
|
|
15
15
|
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
|
|
16
16
|
const { getName, getFile } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
|
|
17
|
-
const file =
|
|
17
|
+
const file = driver.getFile({
|
|
18
18
|
name: "handlers",
|
|
19
19
|
extname: ".ts",
|
|
20
20
|
pluginName: plugin.name
|
|
@@ -42,7 +42,7 @@ const handlersGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)(
|
|
|
42
42
|
banner: (0, _kubb_plugin_oas_utils.getBanner)({
|
|
43
43
|
oas,
|
|
44
44
|
output: plugin.options.output,
|
|
45
|
-
config:
|
|
45
|
+
config: driver.config
|
|
46
46
|
}),
|
|
47
47
|
footer: (0, _kubb_plugin_oas_utils.getFooter)({
|
|
48
48
|
oas,
|
|
@@ -61,7 +61,7 @@ const mswGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
61
61
|
name: "msw",
|
|
62
62
|
Operation({ operation, generator, plugin }) {
|
|
63
63
|
const { options: { output, parser, baseURL } } = plugin;
|
|
64
|
-
const
|
|
64
|
+
const driver = (0, _kubb_core_hooks.usePluginDriver)();
|
|
65
65
|
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
|
|
66
66
|
const { getSchemas, getName, getFile } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
|
|
67
67
|
const mock = {
|
|
@@ -103,7 +103,7 @@ const mswGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
103
103
|
banner: (0, _kubb_plugin_oas_utils.getBanner)({
|
|
104
104
|
oas,
|
|
105
105
|
output,
|
|
106
|
-
config:
|
|
106
|
+
config: driver.config
|
|
107
107
|
}),
|
|
108
108
|
footer: (0, _kubb_plugin_oas_utils.getFooter)({
|
|
109
109
|
oas,
|
|
@@ -168,4 +168,4 @@ Object.defineProperty(exports, "mswGenerator", {
|
|
|
168
168
|
}
|
|
169
169
|
});
|
|
170
170
|
|
|
171
|
-
//# sourceMappingURL=generators-
|
|
171
|
+
//# sourceMappingURL=generators-CY1SNd5X.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-CY1SNd5X.cjs","names":["File","Handlers","pluginFakerName","pluginTsName","File","Response","MockWithFaker","Mock"],"sources":["../src/generators/handlersGenerator.tsx","../src/generators/mswGenerator.tsx"],"sourcesContent":["import { usePluginDriver } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { Handlers } from '../components/Handlers.tsx'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations, generator, plugin }) {\n const driver = usePluginDriver()\n\n const oas = useOas()\n const { getName, getFile } = useOperationManager(generator)\n\n const file = driver.getFile({ name: 'handlers', extname: '.ts', pluginName: plugin.name })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginName: plugin.name })\n const operationName = getName(operation, { pluginName: plugin.name, 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', pluginName: plugin.name })}()`)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: driver.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n","import { usePluginDriver } from '@kubb/core/hooks'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport { Mock, MockWithFaker, Response } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation, generator, plugin }) {\n const {\n options: { output, parser, baseURL },\n } = plugin\n const driver = usePluginDriver()\n\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager(generator)\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginName: pluginFakerName }),\n schemas: getSchemas(operation, { pluginName: pluginFakerName, type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginName: pluginTsName }),\n schemas: getSchemas(operation, { pluginName: pluginTsName, type: 'type' }),\n }\n\n const responseStatusCodes = operation.getResponseStatusCodes()\n\n const types: [statusCode: number | 'default', typeName: string][] = []\n\n for (const code of responseStatusCodes) {\n if (code === 'default') {\n types.push(['default', type.schemas.response.name])\n continue\n }\n\n if (code.startsWith('2')) {\n types.push([Number(code), type.schemas.response.name])\n continue\n }\n\n const codeType = type.schemas.errors?.find((err) => err.statusCode === Number(code))\n if (codeType) types.push([Number(code), codeType.name])\n }\n\n return (\n <File\n baseName={mock.file.baseName}\n path={mock.file.path}\n meta={mock.file.meta}\n banner={getBanner({ oas, output, config: driver.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['http']} path=\"msw\" />\n <File.Import name={['ResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import\n name={Array.from(new Set([type.schemas.response.name, ...types.map((t) => t[1])]))}\n path={type.file.path}\n root={mock.file.path}\n isTypeOnly\n />\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 {types\n .filter(([code]) => code !== 'default')\n .map(([code, typeName]) => (\n <Response typeName={typeName} operation={operation} name={mock.name} statusCode={code as number} />\n ))}\n {parser === 'faker' && (\n <MockWithFaker\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n operation={operation}\n baseURL={baseURL}\n />\n )}\n {parser === 'data' && (\n <Mock name={mock.name} typeName={type.schemas.response.name} fakerName={faker.schemas.response.name} operation={operation} baseURL={baseURL} />\n )}\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;AAQA,MAAa,qBAAA,GAAA,4BAAA,sBAAoD;CAC/D,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,UAAA,GAAA,iBAAA,kBAA0B;EAEhC,MAAM,OAAA,GAAA,uBAAA,SAAc;EACpB,MAAM,EA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
3
|
import { pluginFakerName } from "@kubb/plugin-faker";
|
|
4
4
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
5
|
-
import {
|
|
5
|
+
import { usePluginDriver } from "@kubb/core/hooks";
|
|
6
6
|
import { createReactGenerator } from "@kubb/plugin-oas/generators";
|
|
7
7
|
import { useOas, useOperationManager } from "@kubb/plugin-oas/hooks";
|
|
8
8
|
import { getBanner, getFooter } from "@kubb/plugin-oas/utils";
|
|
@@ -12,10 +12,10 @@ import { jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
|
|
|
12
12
|
const handlersGenerator = createReactGenerator({
|
|
13
13
|
name: "plugin-msw",
|
|
14
14
|
Operations({ operations, generator, plugin }) {
|
|
15
|
-
const
|
|
15
|
+
const driver = usePluginDriver();
|
|
16
16
|
const oas = useOas();
|
|
17
17
|
const { getName, getFile } = useOperationManager(generator);
|
|
18
|
-
const file =
|
|
18
|
+
const file = driver.getFile({
|
|
19
19
|
name: "handlers",
|
|
20
20
|
extname: ".ts",
|
|
21
21
|
pluginName: plugin.name
|
|
@@ -43,7 +43,7 @@ const handlersGenerator = createReactGenerator({
|
|
|
43
43
|
banner: getBanner({
|
|
44
44
|
oas,
|
|
45
45
|
output: plugin.options.output,
|
|
46
|
-
config:
|
|
46
|
+
config: driver.config
|
|
47
47
|
}),
|
|
48
48
|
footer: getFooter({
|
|
49
49
|
oas,
|
|
@@ -62,7 +62,7 @@ const mswGenerator = createReactGenerator({
|
|
|
62
62
|
name: "msw",
|
|
63
63
|
Operation({ operation, generator, plugin }) {
|
|
64
64
|
const { options: { output, parser, baseURL } } = plugin;
|
|
65
|
-
const
|
|
65
|
+
const driver = usePluginDriver();
|
|
66
66
|
const oas = useOas();
|
|
67
67
|
const { getSchemas, getName, getFile } = useOperationManager(generator);
|
|
68
68
|
const mock = {
|
|
@@ -104,7 +104,7 @@ const mswGenerator = createReactGenerator({
|
|
|
104
104
|
banner: getBanner({
|
|
105
105
|
oas,
|
|
106
106
|
output,
|
|
107
|
-
config:
|
|
107
|
+
config: driver.config
|
|
108
108
|
}),
|
|
109
109
|
footer: getFooter({
|
|
110
110
|
oas,
|
|
@@ -158,4 +158,4 @@ const mswGenerator = createReactGenerator({
|
|
|
158
158
|
//#endregion
|
|
159
159
|
export { handlersGenerator as n, mswGenerator as t };
|
|
160
160
|
|
|
161
|
-
//# sourceMappingURL=generators-
|
|
161
|
+
//# sourceMappingURL=generators-CvyZTxOm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-CvyZTxOm.js","names":[],"sources":["../src/generators/handlersGenerator.tsx","../src/generators/mswGenerator.tsx"],"sourcesContent":["import { usePluginDriver } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { Handlers } from '../components/Handlers.tsx'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations, generator, plugin }) {\n const driver = usePluginDriver()\n\n const oas = useOas()\n const { getName, getFile } = useOperationManager(generator)\n\n const file = driver.getFile({ name: 'handlers', extname: '.ts', pluginName: plugin.name })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginName: plugin.name })\n const operationName = getName(operation, { pluginName: plugin.name, 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', pluginName: plugin.name })}()`)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: driver.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n","import { usePluginDriver } from '@kubb/core/hooks'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport { Mock, MockWithFaker, Response } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation, generator, plugin }) {\n const {\n options: { output, parser, baseURL },\n } = plugin\n const driver = usePluginDriver()\n\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager(generator)\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginName: pluginFakerName }),\n schemas: getSchemas(operation, { pluginName: pluginFakerName, type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginName: pluginTsName }),\n schemas: getSchemas(operation, { pluginName: pluginTsName, type: 'type' }),\n }\n\n const responseStatusCodes = operation.getResponseStatusCodes()\n\n const types: [statusCode: number | 'default', typeName: string][] = []\n\n for (const code of responseStatusCodes) {\n if (code === 'default') {\n types.push(['default', type.schemas.response.name])\n continue\n }\n\n if (code.startsWith('2')) {\n types.push([Number(code), type.schemas.response.name])\n continue\n }\n\n const codeType = type.schemas.errors?.find((err) => err.statusCode === Number(code))\n if (codeType) types.push([Number(code), codeType.name])\n }\n\n return (\n <File\n baseName={mock.file.baseName}\n path={mock.file.path}\n meta={mock.file.meta}\n banner={getBanner({ oas, output, config: driver.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['http']} path=\"msw\" />\n <File.Import name={['ResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import\n name={Array.from(new Set([type.schemas.response.name, ...types.map((t) => t[1])]))}\n path={type.file.path}\n root={mock.file.path}\n isTypeOnly\n />\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 {types\n .filter(([code]) => code !== 'default')\n .map(([code, typeName]) => (\n <Response typeName={typeName} operation={operation} name={mock.name} statusCode={code as number} />\n ))}\n {parser === 'faker' && (\n <MockWithFaker\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n operation={operation}\n baseURL={baseURL}\n />\n )}\n {parser === 'data' && (\n <Mock name={mock.name} typeName={type.schemas.response.name} fakerName={faker.schemas.response.name} operation={operation} baseURL={baseURL} />\n )}\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;AAQA,MAAa,oBAAoB,qBAAgC;CAC/D,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,SAAS,iBAAiB;EAEhC,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,SAAS,YAAY,oBAAoB,UAAU;EAE3D,MAAM,OAAO,OAAO,QAAQ;GAAE,MAAM;GAAY,SAAS;GAAO,YAAY,OAAO;GAAM,CAAC;EAE1F,MAAM,UAAU,WAAW,KAAK,cAAc;GAC5C,MAAM,gBAAgB,QAAQ,WAAW,EAAE,YAAY,OAAO,MAAM,CAAC;GACrE,MAAM,gBAAgB,QAAQ,WAAW;IAAE,YAAY,OAAO;IAAM,MAAM;IAAY,CAAC;AAEvF,UAAO,oBAAC,KAAK,QAAN;IAAsC,MAAM,CAAC,cAAc;IAAE,MAAM,KAAK;IAAM,MAAM,cAAc;IAAQ,EAAxF,cAAc,KAA0E;IACjH;EAEF,MAAM,WAAW,WAAW,KAAK,cAAc,GAAG,QAAQ,WAAW;GAAE,MAAM;GAAY,YAAY,OAAO;GAAM,CAAC,CAAC,IAAI;AAExH,SACE,qBAAC,MAAD;GACE,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,QAAQ,UAAU;IAAE;IAAK,QAAQ,OAAO,QAAQ;IAAQ,QAAQ,OAAO;IAAQ,CAAC;GAChF,QAAQ,UAAU;IAAE;I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(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_generators = require("./generators-
|
|
2
|
+
const require_generators = require("./generators-CY1SNd5X.cjs");
|
|
3
3
|
exports.handlersGenerator = require_generators.handlersGenerator;
|
|
4
4
|
exports.mswGenerator = require_generators.mswGenerator;
|
package/dist/generators.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import { n as PluginMsw } from "./types-MdHRNpgi.js";
|
|
3
|
-
import { AsyncEventEmitter, Config, FileMetaBase, Generator, Group, KubbEvents, Output, Plugin,
|
|
3
|
+
import { AsyncEventEmitter, Config, FileMetaBase, Generator, Group, KubbEvents, Output, Plugin, PluginDriver, PluginFactoryOptions, ResolveNameParams } from "@kubb/core";
|
|
4
4
|
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
5
5
|
import { HttpMethod, Oas, Operation, SchemaObject, contentType } from "@kubb/oas";
|
|
6
6
|
import { Fabric, KubbFile } from "@kubb/fabric-core/types";
|
|
@@ -105,7 +105,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
105
105
|
include: Array<Include> | undefined;
|
|
106
106
|
override: Array<Override<TOptions>> | undefined;
|
|
107
107
|
contentType: contentType | undefined;
|
|
108
|
-
|
|
108
|
+
driver: PluginDriver;
|
|
109
109
|
events?: AsyncEventEmitter<KubbEvents>;
|
|
110
110
|
/**
|
|
111
111
|
* Current plugin
|
|
@@ -359,7 +359,7 @@ type Schema = {
|
|
|
359
359
|
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
360
360
|
fabric: Fabric;
|
|
361
361
|
oas: Oas;
|
|
362
|
-
|
|
362
|
+
driver: PluginDriver;
|
|
363
363
|
events?: AsyncEventEmitter<KubbEvents>;
|
|
364
364
|
/**
|
|
365
365
|
* Current plugin
|
package/dist/generators.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as handlersGenerator, t as mswGenerator } from "./generators-
|
|
1
|
+
import { n as handlersGenerator, t as mswGenerator } from "./generators-CvyZTxOm.js";
|
|
2
2
|
export { handlersGenerator, mswGenerator };
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_components = require("./components-8XBwMbFa.cjs");
|
|
3
|
-
const require_generators = require("./generators-
|
|
3
|
+
const require_generators = require("./generators-CY1SNd5X.cjs");
|
|
4
4
|
let node_path = require("node:path");
|
|
5
5
|
node_path = require_components.__toESM(node_path);
|
|
6
6
|
let _kubb_core = require("@kubb/core");
|
|
@@ -59,7 +59,7 @@ const pluginMsw = (0, _kubb_core.definePlugin)((options) => {
|
|
|
59
59
|
const files = await new _kubb_plugin_oas.OperationGenerator(this.plugin.options, {
|
|
60
60
|
fabric: this.fabric,
|
|
61
61
|
oas,
|
|
62
|
-
|
|
62
|
+
driver: this.driver,
|
|
63
63
|
events: this.events,
|
|
64
64
|
plugin: this.plugin,
|
|
65
65
|
contentType,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["mswGenerator","handlersGenerator","pluginOasName","pluginTsName","pluginFakerName","path","camelCase","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = definePlugin<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 contentType,\n baseURL,\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n group,\n baseURL,\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 ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\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 install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["mswGenerator","handlersGenerator","pluginOasName","pluginTsName","pluginFakerName","path","camelCase","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = definePlugin<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 contentType,\n baseURL,\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n group,\n baseURL,\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 ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\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 install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n driver: this.driver,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginName: this.plugin.name,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;AASA,MAAa,gBAAgB;AAE7B,MAAa,aAAA,GAAA,WAAA,eAAqC,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAY,YAAY;EAAS,EAClD,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,WAAW,OACX,SAAS,QACT,aAAa,CAACA,mBAAAA,cAAc,WAAWC,mBAAAA,oBAAoB,KAAA,EAAU,CAAC,OAAO,QAAQ,EACrF,aACA,YACE;AAEJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GACA;GACD;EACD,KAAK;GAACC,iBAAAA;GAAeC,gBAAAA;GAAc,WAAW,UAAUC,mBAAAA,kBAAkB,KAAA;GAAU,CAAC,OAAO,QAAQ;EACpG,YAAY,UAAU,UAAU,SAAS;GACvC,MAAM,OAAOC,UAAAA,QAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;AAGpE,QAFa,aAAA,GAAA,WAAA,SAAoBA,UAAAA,QAAK,QAAQ,MAAM,OAAO,KAAK,CAAC,MAEpD;;;;;AAKX,UAAOA,UAAAA,QAAK,QAAQ,MAAM,OAAO,KAAK;AAGxC,OAAI,UAAU,SAAS,OAAO,QAAQ,SAAS,OAAO,MAAM;IAC1D,MAAM,YAA2B,OAAO,OACpC,MAAM,QACL,QAAQ;AACP,SAAI,OAAO,SAAS,OAClB,QAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;AAEjC,YAAO,GAAGC,mBAAAA,UAAU,IAAI,MAAM,CAAC;;AAGrC,WAAOD,UAAAA,QAAK,QACV,MACA,OAAO,MACP,UAAU,EACR,OAAO,MAAM,SAAS,SAAS,QAAQ,MAAM,OAAQ,QAAQ,MAAM,KACpE,CAAC,EACF,SACD;;AAGH,UAAOA,UAAAA,QAAK,QAAQ,MAAM,OAAO,MAAM,SAAS;;EAElD,YAAY,MAAM,MAAM;GACtB,MAAM,eAAeC,mBAAAA,UAAU,MAAM;IACnC,QAAQ,OAAO,YAAY,KAAA;IAC3B,QAAQ,SAAS;IAClB,CAAC;AAEF,OAAI,KACF,QAAO,cAAc,OAAO,cAAc,KAAK,IAAI;AAGrD,UAAO;;EAET,MAAM,UAAU;GACd,MAAM,OAAOD,UAAAA,QAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,QAAA,GAAA,WAAA,SAAeA,UAAAA,QAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACrD,MAAM,MAAM,MAAM,KAAK,QAAQ;GAe/B,MAAM,QAAQ,MAba,IAAIE,iBAAAA,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,MAAM,cAAc,OAAA,GAAA,WAAA,gBAAqB,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,YAAY,KAAK,OAAO,MACzB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
2
|
import { a as camelCase } from "./components-DgtTZkWX.js";
|
|
3
|
-
import { n as handlersGenerator, t as mswGenerator } from "./generators-
|
|
3
|
+
import { n as handlersGenerator, t as mswGenerator } from "./generators-CvyZTxOm.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { definePlugin, getBarrelFiles, getMode } from "@kubb/core";
|
|
6
6
|
import { pluginFakerName } from "@kubb/plugin-faker";
|
|
@@ -58,7 +58,7 @@ const pluginMsw = definePlugin((options) => {
|
|
|
58
58
|
const files = await new OperationGenerator(this.plugin.options, {
|
|
59
59
|
fabric: this.fabric,
|
|
60
60
|
oas,
|
|
61
|
-
|
|
61
|
+
driver: this.driver,
|
|
62
62
|
events: this.events,
|
|
63
63
|
plugin: this.plugin,
|
|
64
64
|
contentType,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = definePlugin<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 contentType,\n baseURL,\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n group,\n baseURL,\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 ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\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 install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = definePlugin<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 contentType,\n baseURL,\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n group,\n baseURL,\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 ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\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 install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n driver: this.driver,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginName: this.plugin.name,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;AASA,MAAa,gBAAgB;AAE7B,MAAa,YAAY,cAAyB,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAY,YAAY;EAAS,EAClD,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,WAAW,OACX,SAAS,QACT,aAAa,CAAC,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,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,YAAY,KAAK,OAAO,MACzB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-msw",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.7",
|
|
4
4
|
"description": "Mock Service Worker (MSW) handlers generator plugin for Kubb, creating API mocks from OpenAPI specifications for frontend development and testing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"msw",
|
|
@@ -77,11 +77,11 @@
|
|
|
77
77
|
],
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"@kubb/react-fabric": "0.14.0",
|
|
80
|
-
"@kubb/core": "5.0.0-alpha.
|
|
81
|
-
"@kubb/oas": "5.0.0-alpha.
|
|
82
|
-
"@kubb/plugin-faker": "5.0.0-alpha.
|
|
83
|
-
"@kubb/plugin-oas": "5.0.0-alpha.
|
|
84
|
-
"@kubb/plugin-ts": "5.0.0-alpha.
|
|
80
|
+
"@kubb/core": "5.0.0-alpha.7",
|
|
81
|
+
"@kubb/oas": "5.0.0-alpha.7",
|
|
82
|
+
"@kubb/plugin-faker": "5.0.0-alpha.7",
|
|
83
|
+
"@kubb/plugin-oas": "5.0.0-alpha.7",
|
|
84
|
+
"@kubb/plugin-ts": "5.0.0-alpha.7"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@internals/utils": "0.0.0"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { usePluginDriver } from '@kubb/core/hooks'
|
|
2
2
|
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
3
3
|
import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
4
4
|
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
|
|
@@ -9,12 +9,12 @@ import type { PluginMsw } from '../types'
|
|
|
9
9
|
export const handlersGenerator = createReactGenerator<PluginMsw>({
|
|
10
10
|
name: 'plugin-msw',
|
|
11
11
|
Operations({ operations, generator, plugin }) {
|
|
12
|
-
const
|
|
12
|
+
const driver = usePluginDriver()
|
|
13
13
|
|
|
14
14
|
const oas = useOas()
|
|
15
15
|
const { getName, getFile } = useOperationManager(generator)
|
|
16
16
|
|
|
17
|
-
const file =
|
|
17
|
+
const file = driver.getFile({ name: 'handlers', extname: '.ts', pluginName: plugin.name })
|
|
18
18
|
|
|
19
19
|
const imports = operations.map((operation) => {
|
|
20
20
|
const operationFile = getFile(operation, { pluginName: plugin.name })
|
|
@@ -30,7 +30,7 @@ export const handlersGenerator = createReactGenerator<PluginMsw>({
|
|
|
30
30
|
baseName={file.baseName}
|
|
31
31
|
path={file.path}
|
|
32
32
|
meta={file.meta}
|
|
33
|
-
banner={getBanner({ oas, output: plugin.options.output, config:
|
|
33
|
+
banner={getBanner({ oas, output: plugin.options.output, config: driver.config })}
|
|
34
34
|
footer={getFooter({ oas, output: plugin.options.output })}
|
|
35
35
|
>
|
|
36
36
|
{imports}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { usePluginDriver } from '@kubb/core/hooks'
|
|
2
2
|
import { pluginFakerName } from '@kubb/plugin-faker'
|
|
3
3
|
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
4
4
|
import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
@@ -14,7 +14,7 @@ export const mswGenerator = createReactGenerator<PluginMsw>({
|
|
|
14
14
|
const {
|
|
15
15
|
options: { output, parser, baseURL },
|
|
16
16
|
} = plugin
|
|
17
|
-
const
|
|
17
|
+
const driver = usePluginDriver()
|
|
18
18
|
|
|
19
19
|
const oas = useOas()
|
|
20
20
|
const { getSchemas, getName, getFile } = useOperationManager(generator)
|
|
@@ -58,7 +58,7 @@ export const mswGenerator = createReactGenerator<PluginMsw>({
|
|
|
58
58
|
baseName={mock.file.baseName}
|
|
59
59
|
path={mock.file.path}
|
|
60
60
|
meta={mock.file.meta}
|
|
61
|
-
banner={getBanner({ oas, output, config:
|
|
61
|
+
banner={getBanner({ oas, output, config: driver.config })}
|
|
62
62
|
footer={getFooter({ oas, output })}
|
|
63
63
|
>
|
|
64
64
|
<File.Import name={['http']} path="msw" />
|
package/src/plugin.ts
CHANGED
|
@@ -87,7 +87,7 @@ export const pluginMsw = definePlugin<PluginMsw>((options) => {
|
|
|
87
87
|
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
88
88
|
fabric: this.fabric,
|
|
89
89
|
oas,
|
|
90
|
-
|
|
90
|
+
driver: this.driver,
|
|
91
91
|
events: this.events,
|
|
92
92
|
plugin: this.plugin,
|
|
93
93
|
contentType,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-Cs46KGm7.js","names":[],"sources":["../src/generators/handlersGenerator.tsx","../src/generators/mswGenerator.tsx"],"sourcesContent":["import { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { Handlers } from '../components/Handlers.tsx'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations, generator, plugin }) {\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getName, getFile } = useOperationManager(generator)\n\n const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginName: plugin.name })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginName: plugin.name })\n const operationName = getName(operation, { pluginName: plugin.name, 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', pluginName: plugin.name })}()`)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n","import { usePluginManager } from '@kubb/core/hooks'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport { Mock, MockWithFaker, Response } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation, generator, plugin }) {\n const {\n options: { output, parser, baseURL },\n } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager(generator)\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginName: pluginFakerName }),\n schemas: getSchemas(operation, { pluginName: pluginFakerName, type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginName: pluginTsName }),\n schemas: getSchemas(operation, { pluginName: pluginTsName, type: 'type' }),\n }\n\n const responseStatusCodes = operation.getResponseStatusCodes()\n\n const types: [statusCode: number | 'default', typeName: string][] = []\n\n for (const code of responseStatusCodes) {\n if (code === 'default') {\n types.push(['default', type.schemas.response.name])\n continue\n }\n\n if (code.startsWith('2')) {\n types.push([Number(code), type.schemas.response.name])\n continue\n }\n\n const codeType = type.schemas.errors?.find((err) => err.statusCode === Number(code))\n if (codeType) types.push([Number(code), codeType.name])\n }\n\n return (\n <File\n baseName={mock.file.baseName}\n path={mock.file.path}\n meta={mock.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['http']} path=\"msw\" />\n <File.Import name={['ResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import\n name={Array.from(new Set([type.schemas.response.name, ...types.map((t) => t[1])]))}\n path={type.file.path}\n root={mock.file.path}\n isTypeOnly\n />\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 {types\n .filter(([code]) => code !== 'default')\n .map(([code, typeName]) => (\n <Response typeName={typeName} operation={operation} name={mock.name} statusCode={code as number} />\n ))}\n {parser === 'faker' && (\n <MockWithFaker\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n operation={operation}\n baseURL={baseURL}\n />\n )}\n {parser === 'data' && (\n <Mock name={mock.name} typeName={type.schemas.response.name} fakerName={faker.schemas.response.name} operation={operation} baseURL={baseURL} />\n )}\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;AAQA,MAAa,oBAAoB,qBAAgC;CAC/D,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,gBAAgB,kBAAkB;EAExC,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,SAAS,YAAY,oBAAoB,UAAU;EAE3D,MAAM,OAAO,cAAc,QAAQ;GAAE,MAAM;GAAY,SAAS;GAAO,YAAY,OAAO;GAAM,CAAC;EAEjG,MAAM,UAAU,WAAW,KAAK,cAAc;GAC5C,MAAM,gBAAgB,QAAQ,WAAW,EAAE,YAAY,OAAO,MAAM,CAAC;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,QAAQ,CAAC,UAAU,SAAS,UAAU,CACtC,KAAK,CAAC,MAAM,cACX,oBAAC,UAAD;KAAoB;KAAqB;KAAW,MAAM,KAAK;KAAM,YAAY;KAAkB,CAAA,CACnG;IACH,WAAW,WACV,oBAAC,eAAD;KACE,MAAM,KAAK;KACX,UAAU,KAAK,QAAQ,SAAS;KAChC,WAAW,MAAM,QAAQ,SAAS;KACvB;KACF;KACT,CAAA;IAEH,WAAW,UACV,oBAAC,MAAD;KAAM,MAAM,KAAK;KAAM,UAAU,KAAK,QAAQ,SAAS;KAAM,WAAW,MAAM,QAAQ,SAAS;KAAiB;KAAoB;KAAW,CAAA;IAE5I;;;CAGZ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-DFhPHY4V.cjs","names":["File","Handlers","pluginFakerName","pluginTsName","File","Response","MockWithFaker","Mock"],"sources":["../src/generators/handlersGenerator.tsx","../src/generators/mswGenerator.tsx"],"sourcesContent":["import { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { Handlers } from '../components/Handlers.tsx'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations, generator, plugin }) {\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getName, getFile } = useOperationManager(generator)\n\n const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginName: plugin.name })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginName: plugin.name })\n const operationName = getName(operation, { pluginName: plugin.name, 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', pluginName: plugin.name })}()`)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n","import { usePluginManager } from '@kubb/core/hooks'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport { Mock, MockWithFaker, Response } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation, generator, plugin }) {\n const {\n options: { output, parser, baseURL },\n } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager(generator)\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginName: pluginFakerName }),\n schemas: getSchemas(operation, { pluginName: pluginFakerName, type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginName: pluginTsName }),\n schemas: getSchemas(operation, { pluginName: pluginTsName, type: 'type' }),\n }\n\n const responseStatusCodes = operation.getResponseStatusCodes()\n\n const types: [statusCode: number | 'default', typeName: string][] = []\n\n for (const code of responseStatusCodes) {\n if (code === 'default') {\n types.push(['default', type.schemas.response.name])\n continue\n }\n\n if (code.startsWith('2')) {\n types.push([Number(code), type.schemas.response.name])\n continue\n }\n\n const codeType = type.schemas.errors?.find((err) => err.statusCode === Number(code))\n if (codeType) types.push([Number(code), codeType.name])\n }\n\n return (\n <File\n baseName={mock.file.baseName}\n path={mock.file.path}\n meta={mock.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['http']} path=\"msw\" />\n <File.Import name={['ResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import\n name={Array.from(new Set([type.schemas.response.name, ...types.map((t) => t[1])]))}\n path={type.file.path}\n root={mock.file.path}\n isTypeOnly\n />\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 {types\n .filter(([code]) => code !== 'default')\n .map(([code, typeName]) => (\n <Response typeName={typeName} operation={operation} name={mock.name} statusCode={code as number} />\n ))}\n {parser === 'faker' && (\n <MockWithFaker\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n operation={operation}\n baseURL={baseURL}\n />\n )}\n {parser === 'data' && (\n <Mock name={mock.name} typeName={type.schemas.response.name} fakerName={faker.schemas.response.name} operation={operation} baseURL={baseURL} />\n )}\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;AAQA,MAAa,qBAAA,GAAA,4BAAA,sBAAoD;CAC/D,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,iBAAA,GAAA,iBAAA,mBAAkC;EAExC,MAAM,OAAA,GAAA,uBAAA,SAAc;EACpB,MAAM,EAAE,SAAS,aAAA,GAAA,uBAAA,qBAAgC,UAAU;EAE3D,MAAM,OAAO,cAAc,QAAQ;GAAE,MAAM;GAAY,SAAS;GAAO,YAAY,OAAO;GAAM,CAAC;EAEjG,MAAM,UAAU,WAAW,KAAK,cAAc;GAC5C,MAAM,gBAAgB,QAAQ,WAAW,EAAE,YAAY,OAAO,MAAM,CAAC;GACrE,MAAM,gBAAgB,QAAQ,WAAW;IAAE,YAAY,OAAO;IAAM,MAAM;IAAY,CAAC;AAEvF,UAAO,iBAAA,GAAA,+BAAA,KAACA,mBAAAA,KAAK,QAAN;IAAsC,MAAM,CAAC,cAAc;IAAE,MAAM,KAAK;IAAM,MAAM,cAAc;IAAQ,EAAxF,cAAc,KAA0E;IACjH;EA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