@kubb/plugin-msw 3.0.0-alpha.5 → 3.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/{chunk-S4P5XPFN.cjs → chunk-FNHHPVHL.cjs} +10 -11
- package/dist/chunk-FNHHPVHL.cjs.map +1 -0
- package/dist/{chunk-WRIEMCYI.js → chunk-LXZF3YE3.js} +14 -15
- package/dist/chunk-LXZF3YE3.js.map +1 -0
- package/dist/components.cjs +2 -2
- package/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/index.cjs +22 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +15 -28
- package/dist/index.js.map +1 -1
- package/package.json +13 -13
- package/src/components/Mock.tsx +8 -13
- package/src/components/Operations.tsx +7 -9
- package/src/components/__snapshots__/Mock/Pets.ts +6 -6
- package/src/components/__snapshots__/Mock/showPetsById.ts +6 -6
- package/src/plugin.ts +13 -27
- package/dist/chunk-S4P5XPFN.cjs.map +0 -1
- package/dist/chunk-WRIEMCYI.js.map +0 -1
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/components/Mock.tsx
|
|
2
|
-
require('@kubb/core');
|
|
3
2
|
var _utils = require('@kubb/core/utils');
|
|
4
3
|
var _react = require('@kubb/react');
|
|
5
4
|
var _pluginfaker = require('@kubb/plugin-faker');
|
|
6
5
|
var _hooks = require('@kubb/plugin-oas/hooks');
|
|
7
6
|
var _jsxruntime = require('@kubb/react/jsx-runtime');
|
|
8
7
|
function Template({ name, method, path, responseName }) {
|
|
9
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
8
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name, isExportable: true, children: `
|
|
10
9
|
export const ${name} = http.${method}('*${path.toURLPath()}', function handler(info) {
|
|
11
10
|
return new Response(JSON.stringify(${responseName}()), {
|
|
12
11
|
headers: {
|
|
@@ -48,11 +47,11 @@ Mock.File = function({ templates = defaultTemplates }) {
|
|
|
48
47
|
type: "function"
|
|
49
48
|
});
|
|
50
49
|
const Template3 = templates.default;
|
|
51
|
-
return /* @__PURE__ */ _jsxruntime.
|
|
50
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
52
51
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["http"], path: "msw" }),
|
|
53
|
-
fileFaker && responseName && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, {
|
|
54
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
55
|
-
] })
|
|
52
|
+
fileFaker && responseName && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: [responseName], root: file.path, path: fileFaker.path }),
|
|
53
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, Mock, { Template: Template3 })
|
|
54
|
+
] });
|
|
56
55
|
};
|
|
57
56
|
Mock.templates = defaultTemplates;
|
|
58
57
|
|
|
@@ -61,7 +60,7 @@ Mock.templates = defaultTemplates;
|
|
|
61
60
|
|
|
62
61
|
|
|
63
62
|
function Template2({ name, handlers }) {
|
|
64
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
63
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name, isExportable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
|
|
65
64
|
}
|
|
66
65
|
function RootTemplate({ children }) {
|
|
67
66
|
const {
|
|
@@ -76,10 +75,10 @@ function RootTemplate({ children }) {
|
|
|
76
75
|
const operationName = getName(operation, { pluginKey, type: "function" });
|
|
77
76
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
|
|
78
77
|
}).filter(Boolean);
|
|
79
|
-
return /* @__PURE__ */ _jsxruntime.
|
|
78
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
80
79
|
imports,
|
|
81
|
-
|
|
82
|
-
] })
|
|
80
|
+
children
|
|
81
|
+
] });
|
|
83
82
|
}
|
|
84
83
|
var defaultTemplates2 = { default: Template2, root: RootTemplate };
|
|
85
84
|
function Operations({ Template: Template3 = defaultTemplates2.default }) {
|
|
@@ -102,4 +101,4 @@ Operations.templates = defaultTemplates2;
|
|
|
102
101
|
|
|
103
102
|
|
|
104
103
|
exports.Mock = Mock; exports.Operations = Operations;
|
|
105
|
-
//# sourceMappingURL=chunk-
|
|
104
|
+
//# sourceMappingURL=chunk-FNHHPVHL.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-msw/dist/chunk-FNHHPVHL.cjs","../src/components/Mock.tsx","../src/components/Operations.tsx"],"names":["Template","jsx","File","useApp","useOperationManager","jsxs","defaultTemplates","RootTemplate"],"mappings":"AAAA;ACAA,yCAAwB;AACxB,oCAA6B;AAC7B,iDAAgC;AAChC,+CAAkD;AA4B9C,qDAAA;AAFJ,SAAS,QAAA,CAAS,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,aAAa,CAAA,EAA6B;AAChF,EAAA,uBACE,6BAAA,WAAC,CAAK,MAAA,EAAL,EAAY,IAAA,EAAY,YAAA,EAAY,IAAA,EAClC,QAAA,EAAA,CAAA;AAAA,eAAA,EACU,IAAI,CAAA,QAAA,EAAW,MAAM,CAAA,GAAA,EAAM,IAAA,CAAK,SAAA,CAAU,CAAC,CAAA;AAAA,uCAAA,EACnB,YAAY,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAAA,EAAA,CAOjD,C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/work/kubb/kubb/packages/plugin-msw/dist/chunk-FNHHPVHL.cjs","sourcesContent":[null,"import { URLPath } from '@kubb/core/utils'\nimport { File, useApp } from '@kubb/react'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\nimport type { FileMeta, PluginMsw } from '../types.ts'\n\ntype TemplateProps = {\n /**\n * Name of the function\n */\n name: string\n /**\n * Method of the current operation, see useOperation.\n */\n method: HttpMethod\n /**\n * Path of the mock\n */\n path: URLPath\n /**\n * Name of the import for the mock(this is a function).\n * @example createPet\n */\n responseName: string\n}\n\nfunction Template({ name, method, path, responseName }: TemplateProps): ReactNode {\n return (\n <File.Source name={name} isExportable>\n {`\n export const ${name} = http.${method}('*${path.toURLPath()}', function handler(info) {\n return new Response(JSON.stringify(${responseName}()), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })\n `}\n </File.Source>\n )\n}\n\nconst defaultTemplates = { default: Template } as const\n\ntype Props = {\n /**\n * This will make it possible to override the default behaviour.\n */\n Template?: React.ComponentType<React.ComponentProps<typeof Template>>\n}\n\nexport function Mock({ Template = defaultTemplates.default }: Props): ReactNode {\n const { pluginManager } = useApp<PluginMsw>()\n const { getSchemas, getName } = useOperationManager()\n const operation = useOperation()\n\n const schemas = getSchemas(operation)\n const name = getName(operation, { type: 'function' })\n const responseName = pluginManager.resolveName({\n pluginKey: [pluginFakerName],\n name: schemas.response.name,\n type: 'type',\n })\n\n return <Template name={name} responseName={responseName} method={operation.method} path={new URLPath(operation.path)} />\n}\n\ntype FileProps = {\n /**\n * This will make it possible to override the default behaviour.\n */\n templates?: typeof defaultTemplates\n}\n\nMock.File = function ({ templates = defaultTemplates }: FileProps): ReactNode {\n const {\n pluginManager,\n plugin: {\n options: { extName },\n },\n } = useApp<PluginMsw>()\n const { getSchemas, getFile } = useOperationManager()\n const operation = useOperation()\n\n const schemas = getSchemas(operation)\n const file = getFile(operation)\n const fileFaker = getFile(operation, { pluginKey: [pluginFakerName] })\n const responseName = pluginManager.resolveName({\n pluginKey: [pluginFakerName],\n name: schemas.response.name,\n type: 'function',\n })\n\n const Template = templates.default\n\n return (\n <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>\n <File.Import name={['http']} path={'msw'} />\n {fileFaker && responseName && <File.Import name={[responseName]} root={file.path} path={fileFaker.path} />}\n <Mock Template={Template} />\n </File>\n )\n}\n\nMock.templates = defaultTemplates\n","import { useOperationManager, useOperations } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\n\nimport type { KubbNode } from '@kubb/react/types'\nimport type { ReactNode } from 'react'\nimport type { FileMeta, PluginMsw } from '../types.ts'\n\ntype TemplateProps = {\n /**\n * Name of the function\n */\n name: string\n handlers: string[]\n}\n\nfunction Template({ name, handlers }: TemplateProps): ReactNode {\n return <File.Source name={name} isExportable>{`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}</File.Source>\n}\n\ntype ParserTemplateProps = {\n children?: React.ReactNode\n}\n\nfunction RootTemplate({ children }: ParserTemplateProps) {\n const {\n pluginManager,\n plugin: { key: pluginKey },\n } = useApp<PluginMsw>()\n\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extName: '.ts', pluginKey })\n const operations = useOperations()\n\n const imports = operations\n .map((operation) => {\n const operationFile = getFile(operation, { pluginKey })\n const operationName = getName(operation, { pluginKey, type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n .filter(Boolean)\n\n return (\n <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>\n {imports}\n {children}\n </File>\n )\n}\n\nconst defaultTemplates = { default: Template, root: RootTemplate } as const\n\ntype Templates = Partial<typeof defaultTemplates>\n\ntype Props = {\n /**\n * This will make it possible to override the default behaviour.\n */\n Template?: React.ComponentType<React.ComponentProps<typeof Template>>\n}\n\nexport function Operations({ Template = defaultTemplates.default }: Props): ReactNode {\n const {\n plugin: { key: pluginKey },\n } = useApp<PluginMsw>()\n\n const operations = useOperations()\n const { getName } = useOperationManager()\n\n return <Template name=\"handlers\" handlers={operations.map((operation) => getName(operation, { type: 'function', pluginKey }))} />\n}\n\ntype FileProps = {\n /**\n * This will make it possible to override the default behaviour.\n */\n templates?: Templates\n}\n\nOperations.File = function (props: FileProps): KubbNode {\n const templates = { ...defaultTemplates, ...props.templates }\n\n const Template = templates.default\n const RootTemplate = templates.root\n\n return (\n <RootTemplate>\n <Operations Template={Template} />\n </RootTemplate>\n )\n}\n\nOperations.templates = defaultTemplates\n"]}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
// src/components/Mock.tsx
|
|
2
|
-
import "@kubb/core";
|
|
3
2
|
import { URLPath } from "@kubb/core/utils";
|
|
4
|
-
import {
|
|
3
|
+
import { File, useApp } from "@kubb/react";
|
|
5
4
|
import { pluginFakerName } from "@kubb/plugin-faker";
|
|
6
5
|
import { useOperation, useOperationManager } from "@kubb/plugin-oas/hooks";
|
|
7
|
-
import {
|
|
6
|
+
import { jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
8
7
|
function Template({ name, method, path, responseName }) {
|
|
9
|
-
return /* @__PURE__ */ jsx(
|
|
8
|
+
return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, children: `
|
|
10
9
|
export const ${name} = http.${method}('*${path.toURLPath()}', function handler(info) {
|
|
11
10
|
return new Response(JSON.stringify(${responseName}()), {
|
|
12
11
|
headers: {
|
|
@@ -48,20 +47,20 @@ Mock.File = function({ templates = defaultTemplates }) {
|
|
|
48
47
|
type: "function"
|
|
49
48
|
});
|
|
50
49
|
const Template3 = templates.default;
|
|
51
|
-
return /* @__PURE__ */
|
|
50
|
+
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
52
51
|
/* @__PURE__ */ jsx(File.Import, { name: ["http"], path: "msw" }),
|
|
53
|
-
fileFaker && responseName && /* @__PURE__ */ jsx(File.Import, {
|
|
54
|
-
/* @__PURE__ */ jsx(
|
|
55
|
-
] })
|
|
52
|
+
fileFaker && responseName && /* @__PURE__ */ jsx(File.Import, { name: [responseName], root: file.path, path: fileFaker.path }),
|
|
53
|
+
/* @__PURE__ */ jsx(Mock, { Template: Template3 })
|
|
54
|
+
] });
|
|
56
55
|
};
|
|
57
56
|
Mock.templates = defaultTemplates;
|
|
58
57
|
|
|
59
58
|
// src/components/Operations.tsx
|
|
60
|
-
import { Parser as Parser2, File as File2, useApp as useApp2 } from "@kubb/react";
|
|
61
59
|
import { useOperationManager as useOperationManager2, useOperations } from "@kubb/plugin-oas/hooks";
|
|
62
|
-
import {
|
|
60
|
+
import { File as File2, useApp as useApp2 } from "@kubb/react";
|
|
61
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "@kubb/react/jsx-runtime";
|
|
63
62
|
function Template2({ name, handlers }) {
|
|
64
|
-
return /* @__PURE__ */ jsx2(
|
|
63
|
+
return /* @__PURE__ */ jsx2(File2.Source, { name, isExportable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
|
|
65
64
|
}
|
|
66
65
|
function RootTemplate({ children }) {
|
|
67
66
|
const {
|
|
@@ -76,10 +75,10 @@ function RootTemplate({ children }) {
|
|
|
76
75
|
const operationName = getName(operation, { pluginKey, type: "function" });
|
|
77
76
|
return /* @__PURE__ */ jsx2(File2.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
|
|
78
77
|
}).filter(Boolean);
|
|
79
|
-
return /* @__PURE__ */
|
|
78
|
+
return /* @__PURE__ */ jsxs2(File2, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
80
79
|
imports,
|
|
81
|
-
|
|
82
|
-
] })
|
|
80
|
+
children
|
|
81
|
+
] });
|
|
83
82
|
}
|
|
84
83
|
var defaultTemplates2 = { default: Template2, root: RootTemplate };
|
|
85
84
|
function Operations({ Template: Template3 = defaultTemplates2.default }) {
|
|
@@ -102,4 +101,4 @@ export {
|
|
|
102
101
|
Mock,
|
|
103
102
|
Operations
|
|
104
103
|
};
|
|
105
|
-
//# sourceMappingURL=chunk-
|
|
104
|
+
//# sourceMappingURL=chunk-LXZF3YE3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Mock.tsx","../src/components/Operations.tsx"],"sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { File, useApp } from '@kubb/react'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\nimport type { FileMeta, PluginMsw } from '../types.ts'\n\ntype TemplateProps = {\n /**\n * Name of the function\n */\n name: string\n /**\n * Method of the current operation, see useOperation.\n */\n method: HttpMethod\n /**\n * Path of the mock\n */\n path: URLPath\n /**\n * Name of the import for the mock(this is a function).\n * @example createPet\n */\n responseName: string\n}\n\nfunction Template({ name, method, path, responseName }: TemplateProps): ReactNode {\n return (\n <File.Source name={name} isExportable>\n {`\n export const ${name} = http.${method}('*${path.toURLPath()}', function handler(info) {\n return new Response(JSON.stringify(${responseName}()), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })\n `}\n </File.Source>\n )\n}\n\nconst defaultTemplates = { default: Template } as const\n\ntype Props = {\n /**\n * This will make it possible to override the default behaviour.\n */\n Template?: React.ComponentType<React.ComponentProps<typeof Template>>\n}\n\nexport function Mock({ Template = defaultTemplates.default }: Props): ReactNode {\n const { pluginManager } = useApp<PluginMsw>()\n const { getSchemas, getName } = useOperationManager()\n const operation = useOperation()\n\n const schemas = getSchemas(operation)\n const name = getName(operation, { type: 'function' })\n const responseName = pluginManager.resolveName({\n pluginKey: [pluginFakerName],\n name: schemas.response.name,\n type: 'type',\n })\n\n return <Template name={name} responseName={responseName} method={operation.method} path={new URLPath(operation.path)} />\n}\n\ntype FileProps = {\n /**\n * This will make it possible to override the default behaviour.\n */\n templates?: typeof defaultTemplates\n}\n\nMock.File = function ({ templates = defaultTemplates }: FileProps): ReactNode {\n const {\n pluginManager,\n plugin: {\n options: { extName },\n },\n } = useApp<PluginMsw>()\n const { getSchemas, getFile } = useOperationManager()\n const operation = useOperation()\n\n const schemas = getSchemas(operation)\n const file = getFile(operation)\n const fileFaker = getFile(operation, { pluginKey: [pluginFakerName] })\n const responseName = pluginManager.resolveName({\n pluginKey: [pluginFakerName],\n name: schemas.response.name,\n type: 'function',\n })\n\n const Template = templates.default\n\n return (\n <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>\n <File.Import name={['http']} path={'msw'} />\n {fileFaker && responseName && <File.Import name={[responseName]} root={file.path} path={fileFaker.path} />}\n <Mock Template={Template} />\n </File>\n )\n}\n\nMock.templates = defaultTemplates\n","import { useOperationManager, useOperations } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\n\nimport type { KubbNode } from '@kubb/react/types'\nimport type { ReactNode } from 'react'\nimport type { FileMeta, PluginMsw } from '../types.ts'\n\ntype TemplateProps = {\n /**\n * Name of the function\n */\n name: string\n handlers: string[]\n}\n\nfunction Template({ name, handlers }: TemplateProps): ReactNode {\n return <File.Source name={name} isExportable>{`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}</File.Source>\n}\n\ntype ParserTemplateProps = {\n children?: React.ReactNode\n}\n\nfunction RootTemplate({ children }: ParserTemplateProps) {\n const {\n pluginManager,\n plugin: { key: pluginKey },\n } = useApp<PluginMsw>()\n\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extName: '.ts', pluginKey })\n const operations = useOperations()\n\n const imports = operations\n .map((operation) => {\n const operationFile = getFile(operation, { pluginKey })\n const operationName = getName(operation, { pluginKey, type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n .filter(Boolean)\n\n return (\n <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>\n {imports}\n {children}\n </File>\n )\n}\n\nconst defaultTemplates = { default: Template, root: RootTemplate } as const\n\ntype Templates = Partial<typeof defaultTemplates>\n\ntype Props = {\n /**\n * This will make it possible to override the default behaviour.\n */\n Template?: React.ComponentType<React.ComponentProps<typeof Template>>\n}\n\nexport function Operations({ Template = defaultTemplates.default }: Props): ReactNode {\n const {\n plugin: { key: pluginKey },\n } = useApp<PluginMsw>()\n\n const operations = useOperations()\n const { getName } = useOperationManager()\n\n return <Template name=\"handlers\" handlers={operations.map((operation) => getName(operation, { type: 'function', pluginKey }))} />\n}\n\ntype FileProps = {\n /**\n * This will make it possible to override the default behaviour.\n */\n templates?: Templates\n}\n\nOperations.File = function (props: FileProps): KubbNode {\n const templates = { ...defaultTemplates, ...props.templates }\n\n const Template = templates.default\n const RootTemplate = templates.root\n\n return (\n <RootTemplate>\n <Operations Template={Template} />\n </RootTemplate>\n )\n}\n\nOperations.templates = defaultTemplates\n"],"mappings":";AAAA,SAAS,eAAe;AACxB,SAAS,MAAM,cAAc;AAC7B,SAAS,uBAAuB;AAChC,SAAS,cAAc,2BAA2B;AA4B9C,cAoEA,YApEA;AAFJ,SAAS,SAAS,EAAE,MAAM,QAAQ,MAAM,aAAa,GAA6B;AAChF,SACE,oBAAC,KAAK,QAAL,EAAY,MAAY,cAAY,MAClC;AAAA,iBACU,IAAI,WAAW,MAAM,MAAM,KAAK,UAAU,CAAC;AAAA,yCACnB,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAOjD;AAEJ;AAEA,IAAM,mBAAmB,EAAE,SAAS,SAAS;AAStC,SAAS,KAAK,EAAE,UAAAA,YAAW,iBAAiB,QAAQ,GAAqB;AAC9E,QAAM,EAAE,cAAc,IAAI,OAAkB;AAC5C,QAAM,EAAE,YAAY,QAAQ,IAAI,oBAAoB;AACpD,QAAM,YAAY,aAAa;AAE/B,QAAM,UAAU,WAAW,SAAS;AACp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AAU,WAAW,IAAI,CAAC,cAAc,QAAQ,WAAW,EAAE,MAAM,YAAY,UAAU,CAAC,CAAC,GAAG;AACjI;AASA,WAAW,OAAO,SAAU,OAA4B;AACtD,QAAM,YAAY,EAAE,GAAGC,mBAAkB,GAAG,MAAM,UAAU;AAE5D,QAAMD,YAAW,UAAU;AAC3B,QAAME,gBAAe,UAAU;AAE/B,SACE,gBAAAJ,KAACI,eAAA,EACC,0BAAAJ,KAAC,cAAW,UAAUE,WAAU,GAClC;AAEJ;AAEA,WAAW,YAAYC;","names":["Template","useOperationManager","File","useApp","jsx","jsxs","Template","defaultTemplates","RootTemplate"]}
|
package/dist/components.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkFNHHPVHLcjs = require('./chunk-FNHHPVHL.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
exports.Mock =
|
|
8
|
+
exports.Mock = _chunkFNHHPVHLcjs.Mock; exports.Operations = _chunkFNHHPVHLcjs.Operations;
|
|
9
9
|
//# sourceMappingURL=components.cjs.map
|
package/dist/components.d.cts
CHANGED
package/dist/components.d.ts
CHANGED
package/dist/components.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkFNHHPVHLcjs = require('./chunk-FNHHPVHL.cjs');
|
|
5
5
|
|
|
6
6
|
// src/plugin.ts
|
|
7
7
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
@@ -9,7 +9,6 @@ var _core = require('@kubb/core');
|
|
|
9
9
|
var _transformers = require('@kubb/core/transformers');
|
|
10
10
|
var _utils = require('@kubb/core/utils');
|
|
11
11
|
var _pluginoas = require('@kubb/plugin-oas');
|
|
12
|
-
var _utils3 = require('@kubb/plugin-oas/utils');
|
|
13
12
|
var _pluginfaker = require('@kubb/plugin-faker');
|
|
14
13
|
var _plugints = require('@kubb/plugin-ts');
|
|
15
14
|
|
|
@@ -25,12 +24,12 @@ var OperationGenerator = class extends _pluginoas.OperationGenerator {
|
|
|
25
24
|
logger: pluginManager.logger
|
|
26
25
|
});
|
|
27
26
|
const templates = {
|
|
28
|
-
operations:
|
|
29
|
-
mock:
|
|
27
|
+
operations: _chunkFNHHPVHLcjs.Operations.templates,
|
|
28
|
+
mock: _chunkFNHHPVHLcjs.Mock.templates,
|
|
30
29
|
...this.options.templates
|
|
31
30
|
};
|
|
32
31
|
root.render(
|
|
33
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations, generator: this, children: _optionalChain([templates, 'optionalAccess', _ => _.operations]) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
32
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations, generator: this, children: _optionalChain([templates, 'optionalAccess', _ => _.operations]) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkFNHHPVHLcjs.Operations.File, { templates: templates.operations }) }) })
|
|
34
33
|
);
|
|
35
34
|
return root.files;
|
|
36
35
|
}
|
|
@@ -40,15 +39,15 @@ var OperationGenerator = class extends _pluginoas.OperationGenerator {
|
|
|
40
39
|
logger: pluginManager.logger
|
|
41
40
|
});
|
|
42
41
|
const templates = {
|
|
43
|
-
handlers:
|
|
44
|
-
mock:
|
|
42
|
+
handlers: _chunkFNHHPVHLcjs.Operations.templates,
|
|
43
|
+
mock: _chunkFNHHPVHLcjs.Mock.templates,
|
|
45
44
|
...options.templates
|
|
46
45
|
};
|
|
47
46
|
if (!_optionalChain([templates, 'optionalAccess', _2 => _2.mock])) {
|
|
48
47
|
return [];
|
|
49
48
|
}
|
|
50
49
|
root.render(
|
|
51
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Operation, { operation, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
50
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Operation, { operation, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkFNHHPVHLcjs.Mock.File, { templates: templates.mock }) }) }) })
|
|
52
51
|
);
|
|
53
52
|
return root.files;
|
|
54
53
|
}
|
|
@@ -61,11 +60,15 @@ var pluginMsw = _core.createPlugin.call(void 0, (options) => {
|
|
|
61
60
|
const template = _optionalChain([group, 'optionalAccess', _3 => _3.output]) ? group.output : `${output.path}/{{tag}}Controller`;
|
|
62
61
|
return {
|
|
63
62
|
name: pluginMswName,
|
|
63
|
+
output: {
|
|
64
|
+
exportType: "barrelNamed",
|
|
65
|
+
...output
|
|
66
|
+
},
|
|
64
67
|
options: {
|
|
65
68
|
extName: output.extName,
|
|
66
69
|
templates: {
|
|
67
|
-
operations:
|
|
68
|
-
mock:
|
|
70
|
+
operations: _chunkFNHHPVHLcjs.Operations.templates,
|
|
71
|
+
mock: _chunkFNHHPVHLcjs.Mock.templates,
|
|
69
72
|
...templates
|
|
70
73
|
}
|
|
71
74
|
},
|
|
@@ -109,34 +112,18 @@ var pluginMsw = _core.createPlugin.call(void 0, (options) => {
|
|
|
109
112
|
});
|
|
110
113
|
const files = await operationGenerator.build();
|
|
111
114
|
await this.addFile(...files);
|
|
112
|
-
if (this.config.output.
|
|
113
|
-
const
|
|
114
|
-
logger: this.logger,
|
|
115
|
-
files: this.fileManager.files,
|
|
116
|
-
plugin: this.plugin,
|
|
117
|
-
template,
|
|
118
|
-
exportAs: group.exportAs || "{{tag}}Handlers",
|
|
115
|
+
if (this.config.output.exportType) {
|
|
116
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
119
117
|
root,
|
|
120
|
-
output
|
|
118
|
+
output,
|
|
119
|
+
files: this.fileManager.files,
|
|
120
|
+
meta: {
|
|
121
|
+
pluginKey: this.plugin.key
|
|
122
|
+
},
|
|
123
|
+
logger: this.logger
|
|
121
124
|
});
|
|
122
|
-
await this.addFile(...
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
async buildEnd() {
|
|
126
|
-
if (this.config.output.write === false) {
|
|
127
|
-
return;
|
|
125
|
+
await this.addFile(...barrelFiles);
|
|
128
126
|
}
|
|
129
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
130
|
-
const files = await this.fileManager.getIndexFiles({
|
|
131
|
-
root,
|
|
132
|
-
output,
|
|
133
|
-
plugin: this.plugin,
|
|
134
|
-
logger: this.logger
|
|
135
|
-
});
|
|
136
|
-
await this.fileManager.processFiles({
|
|
137
|
-
logger: this.logger,
|
|
138
|
-
files
|
|
139
|
-
});
|
|
140
127
|
}
|
|
141
128
|
};
|
|
142
129
|
});
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-msw/dist/index.cjs","../src/plugin.ts","../src/OperationGenerator.tsx"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACLA,wEAAiB;AAEjB,kCAAyD;AACzD,uDAA0B;AAC1B,yCAA+B;AAC/B,6CAA8B;
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-msw/dist/index.cjs","../src/plugin.ts","../src/OperationGenerator.tsx"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACLA,wEAAiB;AAEjB,kCAAyD;AACzD,uDAA0B;AAC1B,yCAA+B;AAC/B,6CAA8B;AAE9B,iDAAgC;AAChC,2CAA6B;ADK7B;AACA;AEdA;AACA,yDAAoB;AACpB,oCAAgC;AA0BI,qDAAA;AAjB7B,IAAM,mBAAA,EAAN,MAAA,QAAiC,8BAAmD;AAAA,EACzF,MAAM,GAAA,CAAI,UAAA,EAAyB,kBAAA,EAAyE;AAC1G,IAAA,MAAM,EAAE,GAAA,EAAK,aAAA,EAAe,MAAA,EAAQ,KAAK,EAAA,EAAI,IAAA,CAAK,OAAA;AAElD,IAAA,MAAM,KAAA,EAAO,+BAAA;AAAW,MACtB,MAAA,EAAQ,aAAA,CAAc;AAAA,IACxB,CAAC,CAAA;AAED,IAAA,MAAM,UAAA,EAAY;AAAA,MAChB,UAAA,EAAY,4BAAA,CAAW,SAAA;AAAA,MACvB,IAAA,EAAM,sBAAA,CAAK,SAAA;AAAA,MACX,GAAG,IAAA,CAAK,OAAA,CAAQ;AAAA,IAClB,CAAA;AAEA,IAAA,IAAA,CAAK,MAAA;AAAA,sBACH,6BAAA,UAAC,EAAA,EAAI,aAAA,EAA8B,MAAA,EAAgB,IA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;AACa,UAAA;AACd,QAAA;AAEgC,QAAA;AACnC,MAAA;AACF,IAAA;AACF,EAAA;AACD;ADwBkD;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/plugin-msw/dist/index.cjs","sourcesContent":[null,"import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport { OperationGenerator } from './OperationGenerator.tsx'\nimport { Mock, Operations } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const { output = { path: 'handlers' }, group, exclude = [], include, override = [], transformers = {}, templates } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginMswName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {\n extName: output.extName,\n templates: {\n operations: Operations.templates,\n mock: Mock.templates,\n ...templates,\n },\n },\n pre: [pluginOasName, pluginTsName, pluginFakerName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n 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()\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n","import { OperationGenerator as Generator } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { App, createRoot } from '@kubb/react'\n\nimport { Mock } from './components/Mock.tsx'\nimport { Operations } from './components/Operations.tsx'\n\nimport type { Operation } from '@kubb/oas'\nimport type { OperationMethodResult, OperationsByMethod } from '@kubb/plugin-oas'\nimport type { FileMeta, PluginMsw } from './types.ts'\n\nexport class OperationGenerator extends Generator<PluginMsw['resolvedOptions'], PluginMsw> {\n async all(operations: Operation[], operationsByMethod: OperationsByMethod): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const templates = {\n operations: Operations.templates,\n mock: Mock.templates,\n ...this.options.templates,\n }\n\n root.render(\n <App pluginManager={pluginManager} plugin={plugin} mode={mode}>\n <Oas oas={oas} operations={operations} generator={this}>\n {templates?.operations && <Operations.File templates={templates.operations} />}\n </Oas>\n </App>,\n )\n\n return root.files\n }\n\n async operation(operation: Operation, options: PluginMsw['resolvedOptions']): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const templates = {\n handlers: Operations.templates,\n mock: Mock.templates,\n ...options.templates,\n }\n\n if (!templates?.mock) {\n return []\n }\n\n root.render(\n <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>\n <Oas oas={oas} operations={[operation]} generator={this}>\n <Oas.Operation operation={operation}>\n <Mock.File templates={templates.mock} />\n </Oas.Operation>\n </Oas>\n </App>,\n )\n\n return root.files\n }\n}\n"]}
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Mock,
|
|
3
3
|
Operations
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-LXZF3YE3.js";
|
|
5
5
|
|
|
6
6
|
// src/plugin.ts
|
|
7
|
-
import path from "path";
|
|
7
|
+
import path from "node:path";
|
|
8
8
|
import { FileManager, PluginManager, createPlugin } from "@kubb/core";
|
|
9
9
|
import { camelCase } from "@kubb/core/transformers";
|
|
10
10
|
import { renderTemplate } from "@kubb/core/utils";
|
|
11
11
|
import { pluginOasName } from "@kubb/plugin-oas";
|
|
12
|
-
import { getGroupedByTagFiles } from "@kubb/plugin-oas/utils";
|
|
13
12
|
import { pluginFakerName } from "@kubb/plugin-faker";
|
|
14
13
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
15
14
|
|
|
@@ -61,6 +60,10 @@ var pluginMsw = createPlugin((options) => {
|
|
|
61
60
|
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
62
61
|
return {
|
|
63
62
|
name: pluginMswName,
|
|
63
|
+
output: {
|
|
64
|
+
exportType: "barrelNamed",
|
|
65
|
+
...output
|
|
66
|
+
},
|
|
64
67
|
options: {
|
|
65
68
|
extName: output.extName,
|
|
66
69
|
templates: {
|
|
@@ -109,34 +112,18 @@ var pluginMsw = createPlugin((options) => {
|
|
|
109
112
|
});
|
|
110
113
|
const files = await operationGenerator.build();
|
|
111
114
|
await this.addFile(...files);
|
|
112
|
-
if (this.config.output.
|
|
113
|
-
const
|
|
114
|
-
logger: this.logger,
|
|
115
|
-
files: this.fileManager.files,
|
|
116
|
-
plugin: this.plugin,
|
|
117
|
-
template,
|
|
118
|
-
exportAs: group.exportAs || "{{tag}}Handlers",
|
|
115
|
+
if (this.config.output.exportType) {
|
|
116
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
119
117
|
root,
|
|
120
|
-
output
|
|
118
|
+
output,
|
|
119
|
+
files: this.fileManager.files,
|
|
120
|
+
meta: {
|
|
121
|
+
pluginKey: this.plugin.key
|
|
122
|
+
},
|
|
123
|
+
logger: this.logger
|
|
121
124
|
});
|
|
122
|
-
await this.addFile(...
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
async buildEnd() {
|
|
126
|
-
if (this.config.output.write === false) {
|
|
127
|
-
return;
|
|
125
|
+
await this.addFile(...barrelFiles);
|
|
128
126
|
}
|
|
129
|
-
const root = path.resolve(this.config.root, this.config.output.path);
|
|
130
|
-
const files = await this.fileManager.getIndexFiles({
|
|
131
|
-
root,
|
|
132
|
-
output,
|
|
133
|
-
plugin: this.plugin,
|
|
134
|
-
logger: this.logger
|
|
135
|
-
});
|
|
136
|
-
await this.fileManager.processFiles({
|
|
137
|
-
logger: this.logger,
|
|
138
|
-
files
|
|
139
|
-
});
|
|
140
127
|
}
|
|
141
128
|
};
|
|
142
129
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts","../src/OperationGenerator.tsx"],"sourcesContent":["import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { pluginOasName } from '@kubb/plugin-oas'\
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts","../src/OperationGenerator.tsx"],"sourcesContent":["import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport { OperationGenerator } from './OperationGenerator.tsx'\nimport { Mock, Operations } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = createPlugin<PluginMsw>((options) => {\n const { output = { path: 'handlers' }, group, exclude = [], include, override = [], transformers = {}, templates } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginMswName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {\n extName: output.extName,\n templates: {\n operations: Operations.templates,\n mock: Mock.templates,\n ...templates,\n },\n },\n pre: [pluginOasName, pluginTsName, pluginFakerName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n 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()\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n","import { OperationGenerator as Generator } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { App, createRoot } from '@kubb/react'\n\nimport { Mock } from './components/Mock.tsx'\nimport { Operations } from './components/Operations.tsx'\n\nimport type { Operation } from '@kubb/oas'\nimport type { OperationMethodResult, OperationsByMethod } from '@kubb/plugin-oas'\nimport type { FileMeta, PluginMsw } from './types.ts'\n\nexport class OperationGenerator extends Generator<PluginMsw['resolvedOptions'], PluginMsw> {\n async all(operations: Operation[], operationsByMethod: OperationsByMethod): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const templates = {\n operations: Operations.templates,\n mock: Mock.templates,\n ...this.options.templates,\n }\n\n root.render(\n <App pluginManager={pluginManager} plugin={plugin} mode={mode}>\n <Oas oas={oas} operations={operations} generator={this}>\n {templates?.operations && <Operations.File templates={templates.operations} />}\n </Oas>\n </App>,\n )\n\n return root.files\n }\n\n async operation(operation: Operation, options: PluginMsw['resolvedOptions']): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const templates = {\n handlers: Operations.templates,\n mock: Mock.templates,\n ...options.templates,\n }\n\n if (!templates?.mock) {\n return []\n }\n\n root.render(\n <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>\n <Oas oas={oas} operations={[operation]} generator={this}>\n <Oas.Operation operation={operation}>\n <Mock.File templates={templates.mock} />\n </Oas.Operation>\n </Oas>\n </App>,\n )\n\n return root.files\n }\n}\n"],"mappings":";;;;;;AAAA,OAAO,UAAU;AAEjB,SAAS,aAAa,eAAe,oBAAoB;AACzD,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAE9B,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;;;ACR7B,SAAS,sBAAsB,iBAAiB;AAChD,SAAS,WAAW;AACpB,SAAS,KAAK,kBAAkB;AA0BI;AAjB7B,IAAM,qBAAN,cAAiC,UAAmD;AAAA,EACzF,MAAM,IAAI,YAAyB,oBAAyE;AAC1G,UAAM,EAAE,KAAK,eAAe,QAAQ,KAAK,IAAI,KAAK;AAElD,UAAM,OAAO,WAAW;AAAA,MACtB,QAAQ,cAAc;AAAA,IACxB,CAAC;AAED,UAAM,YAAY;AAAA,MAChB,YAAY,WAAW;AAAA,MACvB,MAAM,KAAK;AAAA,MACX,GAAG,KAAK,QAAQ;AAAA,IAClB;AAEA,SAAK;AAAA,MACH,oBAAC,OAAI,eAA8B,QAAgB,MACjD,8BAAC,OAAI,KAAU,YAAwB,WAAW,MAC/C,qBAAW,cAAc,oBAAC,WAAW,MAAX,EAAgB,WAAW,UAAU,YAAY,GAC9E,GACF;AAAA,IACF;AAEA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAM,UAAU,WAAsB,SAAwE;AAC5G,UAAM,EAAE,KAAK,eAAe,QAAQ,KAAK,IAAI,KAAK;AAElD,UAAM,OAAO,WAAW;AAAA,MACtB,QAAQ,cAAc;AAAA,IACxB,CAAC;A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AAQ,KAAK;AAAA,QACf,CAAC;AAED,cAAM,KAAK,QAAQ,GAAG,WAAW;AAAA,MACnC;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":["options"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-msw",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.7",
|
|
4
4
|
"description": "Generator swagger",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -66,14 +66,14 @@
|
|
|
66
66
|
"!/**/__tests__/**"
|
|
67
67
|
],
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@kubb/core": "3.0.0-alpha.
|
|
70
|
-
"@kubb/fs": "3.0.0-alpha.
|
|
71
|
-
"@kubb/oas": "3.0.0-alpha.
|
|
72
|
-
"@kubb/parser-ts": "3.0.0-alpha.
|
|
73
|
-
"@kubb/plugin-faker": "3.0.0-alpha.
|
|
74
|
-
"@kubb/plugin-oas": "3.0.0-alpha.
|
|
75
|
-
"@kubb/plugin-ts": "3.0.0-alpha.
|
|
76
|
-
"@kubb/react": "3.0.0-alpha.
|
|
69
|
+
"@kubb/core": "3.0.0-alpha.7",
|
|
70
|
+
"@kubb/fs": "3.0.0-alpha.7",
|
|
71
|
+
"@kubb/oas": "3.0.0-alpha.7",
|
|
72
|
+
"@kubb/parser-ts": "3.0.0-alpha.7",
|
|
73
|
+
"@kubb/plugin-faker": "3.0.0-alpha.7",
|
|
74
|
+
"@kubb/plugin-oas": "3.0.0-alpha.7",
|
|
75
|
+
"@kubb/plugin-ts": "3.0.0-alpha.7",
|
|
76
|
+
"@kubb/react": "3.0.0-alpha.7"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@types/react": "^18.3.4",
|
|
@@ -81,12 +81,12 @@
|
|
|
81
81
|
"react": "^18.3.1",
|
|
82
82
|
"tsup": "^8.2.4",
|
|
83
83
|
"typescript": "^5.5.4",
|
|
84
|
-
"@kubb/config-biome": "3.0.0-alpha.
|
|
85
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
86
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
84
|
+
"@kubb/config-biome": "3.0.0-alpha.7",
|
|
85
|
+
"@kubb/config-ts": "3.0.0-alpha.7",
|
|
86
|
+
"@kubb/config-tsup": "3.0.0-alpha.7"
|
|
87
87
|
},
|
|
88
88
|
"peerDependencies": {
|
|
89
|
-
"@kubb/react": "3.0.0-alpha.
|
|
89
|
+
"@kubb/react": "3.0.0-alpha.7"
|
|
90
90
|
},
|
|
91
91
|
"engines": {
|
|
92
92
|
"node": ">=20"
|
package/src/components/Mock.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { PackageManager } from '@kubb/core'
|
|
2
1
|
import { URLPath } from '@kubb/core/utils'
|
|
3
|
-
import {
|
|
2
|
+
import { File, useApp } from '@kubb/react'
|
|
4
3
|
import { pluginFakerName } from '@kubb/plugin-faker'
|
|
5
4
|
import { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
6
5
|
|
|
@@ -30,7 +29,7 @@ type TemplateProps = {
|
|
|
30
29
|
|
|
31
30
|
function Template({ name, method, path, responseName }: TemplateProps): ReactNode {
|
|
32
31
|
return (
|
|
33
|
-
|
|
32
|
+
<File.Source name={name} isExportable>
|
|
34
33
|
{`
|
|
35
34
|
export const ${name} = http.${method}('*${path.toURLPath()}', function handler(info) {
|
|
36
35
|
return new Response(JSON.stringify(${responseName}()), {
|
|
@@ -40,7 +39,7 @@ function Template({ name, method, path, responseName }: TemplateProps): ReactNod
|
|
|
40
39
|
})
|
|
41
40
|
})
|
|
42
41
|
`}
|
|
43
|
-
|
|
42
|
+
</File.Source>
|
|
44
43
|
)
|
|
45
44
|
}
|
|
46
45
|
|
|
@@ -98,15 +97,11 @@ Mock.File = function ({ templates = defaultTemplates }: FileProps): ReactNode {
|
|
|
98
97
|
const Template = templates.default
|
|
99
98
|
|
|
100
99
|
return (
|
|
101
|
-
<
|
|
102
|
-
<File
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
<Mock Template={Template} />
|
|
107
|
-
</File.Source>
|
|
108
|
-
</File>
|
|
109
|
-
</Parser>
|
|
100
|
+
<File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
101
|
+
<File.Import name={['http']} path={'msw'} />
|
|
102
|
+
{fileFaker && responseName && <File.Import name={[responseName]} root={file.path} path={fileFaker.path} />}
|
|
103
|
+
<Mock Template={Template} />
|
|
104
|
+
</File>
|
|
110
105
|
)
|
|
111
106
|
}
|
|
112
107
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Parser, File, useApp } from '@kubb/react'
|
|
2
1
|
import { useOperationManager, useOperations } from '@kubb/plugin-oas/hooks'
|
|
2
|
+
import { File, useApp } from '@kubb/react'
|
|
3
3
|
|
|
4
|
-
import type { KubbNode } from '@kubb/react'
|
|
4
|
+
import type { KubbNode } from '@kubb/react/types'
|
|
5
5
|
import type { ReactNode } from 'react'
|
|
6
6
|
import type { FileMeta, PluginMsw } from '../types.ts'
|
|
7
7
|
|
|
@@ -14,7 +14,7 @@ type TemplateProps = {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
function Template({ name, handlers }: TemplateProps): ReactNode {
|
|
17
|
-
return
|
|
17
|
+
return <File.Source name={name} isExportable>{`export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, '')} as const`}</File.Source>
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
type ParserTemplateProps = {
|
|
@@ -42,12 +42,10 @@ function RootTemplate({ children }: ParserTemplateProps) {
|
|
|
42
42
|
.filter(Boolean)
|
|
43
43
|
|
|
44
44
|
return (
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
</File>
|
|
50
|
-
</Parser>
|
|
45
|
+
<File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
46
|
+
{imports}
|
|
47
|
+
{children}
|
|
48
|
+
</File>
|
|
51
49
|
)
|
|
52
50
|
}
|
|
53
51
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const createPets = http.post('*/pets', function handler(info) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
})
|
|
2
|
+
return new Response(JSON.stringify(CreatePetsMutationResponse()), {
|
|
3
|
+
headers: {
|
|
4
|
+
'Content-Type': 'application/json',
|
|
5
|
+
},
|
|
6
|
+
})
|
|
7
|
+
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const showPetById = http.get('*/pets/:petId', function handler(info) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
})
|
|
2
|
+
return new Response(JSON.stringify(ShowPetByIdQueryResponse()), {
|
|
3
|
+
headers: {
|
|
4
|
+
'Content-Type': 'application/json',
|
|
5
|
+
},
|
|
6
|
+
})
|
|
7
|
+
})
|
package/src/plugin.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { FileManager, PluginManager, createPlugin } from '@kubb/core'
|
|
|
4
4
|
import { camelCase } from '@kubb/core/transformers'
|
|
5
5
|
import { renderTemplate } from '@kubb/core/utils'
|
|
6
6
|
import { pluginOasName } from '@kubb/plugin-oas'
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
import { pluginFakerName } from '@kubb/plugin-faker'
|
|
9
9
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
10
10
|
|
|
@@ -23,6 +23,10 @@ export const pluginMsw = createPlugin<PluginMsw>((options) => {
|
|
|
23
23
|
|
|
24
24
|
return {
|
|
25
25
|
name: pluginMswName,
|
|
26
|
+
output: {
|
|
27
|
+
exportType: 'barrelNamed',
|
|
28
|
+
...output,
|
|
29
|
+
},
|
|
26
30
|
options: {
|
|
27
31
|
extName: output.extName,
|
|
28
32
|
templates: {
|
|
@@ -84,37 +88,19 @@ export const pluginMsw = createPlugin<PluginMsw>((options) => {
|
|
|
84
88
|
const files = await operationGenerator.build()
|
|
85
89
|
await this.addFile(...files)
|
|
86
90
|
|
|
87
|
-
if (this.config.output.
|
|
88
|
-
const
|
|
89
|
-
logger: this.logger,
|
|
90
|
-
files: this.fileManager.files,
|
|
91
|
-
plugin: this.plugin,
|
|
92
|
-
template,
|
|
93
|
-
exportAs: group.exportAs || '{{tag}}Handlers',
|
|
91
|
+
if (this.config.output.exportType) {
|
|
92
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
94
93
|
root,
|
|
95
94
|
output,
|
|
95
|
+
files: this.fileManager.files,
|
|
96
|
+
meta: {
|
|
97
|
+
pluginKey: this.plugin.key,
|
|
98
|
+
},
|
|
99
|
+
logger: this.logger,
|
|
96
100
|
})
|
|
97
101
|
|
|
98
|
-
await this.addFile(...
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
async buildEnd() {
|
|
102
|
-
if (this.config.output.write === false) {
|
|
103
|
-
return
|
|
102
|
+
await this.addFile(...barrelFiles)
|
|
104
103
|
}
|
|
105
|
-
|
|
106
|
-
const root = path.resolve(this.config.root, this.config.output.path)
|
|
107
|
-
const files = await this.fileManager.getIndexFiles({
|
|
108
|
-
root,
|
|
109
|
-
output,
|
|
110
|
-
plugin: this.plugin,
|
|
111
|
-
logger: this.logger,
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
await this.fileManager.processFiles({
|
|
115
|
-
logger: this.logger,
|
|
116
|
-
files,
|
|
117
|
-
})
|
|
118
104
|
},
|
|
119
105
|
}
|
|
120
106
|
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-msw/dist/chunk-S4P5XPFN.cjs","../src/components/Mock.tsx","../src/components/Operations.tsx"],"names":["Template","jsx","Fragment","useApp","useOperationManager","File","Parser","jsxs","defaultTemplates","Root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6BAAAA,SAACD,EAAA,EAAS,IAAA,EAAK,UAAA,EAAW,QAAA,EAAU,UAAA,CAAW,GAAA,CAAI,CAAC,SAAA,EAAA,GAAc,OAAA,CAAQ,SAAA,EAAW,EAAE,IAAA,EAAM,UAAA,EAAY,UAAU,CAAC,CAAC,EAAA,CAAG,CAAA;AACjI;AASA,UAAA,CAAW,KAAA,EAAO,QAAA,CAAU,KAAA,EAA4B;AACtD,EAAA,MAAM,UAAA,EAAY,EAAE,GAAGQ,iBAAAA,EAAkB,GAAG,KAAA,CAAM,UAAU,CAAA;AAE5D,EAAA,MAAMR,UAAAA,EAAW,SAAA,CAAU,OAAA;AAC3B,EAAA,MAAMS,cAAAA,EAAe,SAAA,CAAU,IAAA;AAE/B,EAAA,uBACER,6BAAAA,aAACQ,EAAA,EACC,QAAA,kBAAAR,6BAAAA,UAAC,EAAA,EAAW,QAAA,EAAUD,UAAAA,CAAU,EAAA,CAClC,CAAA;AAEJ,CAAA;AAEA,UAAA,CAAW,UAAA,EAAYQ,iBAAAA;AFIvB;AACA;AACE;AACA;AACF,qDAAC","file":"/home/runner/work/kubb/kubb/packages/plugin-msw/dist/chunk-S4P5XPFN.cjs","sourcesContent":[null,"import { PackageManager } from '@kubb/core'\nimport { URLPath } from '@kubb/core/utils'\nimport { Parser, File, useApp } from '@kubb/react'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\nimport type { FileMeta, PluginMsw } from '../types.ts'\n\ntype TemplateProps = {\n /**\n * Name of the function\n */\n name: string\n /**\n * Method of the current operation, see useOperation.\n */\n method: HttpMethod\n /**\n * Path of the mock\n */\n path: URLPath\n /**\n * Name of the import for the mock(this is a function).\n * @example createPet\n */\n responseName: string\n}\n\nfunction Template({ name, method, path, responseName }: TemplateProps): ReactNode {\n return (\n <>\n {`\n export const ${name} = http.${method}('*${path.toURLPath()}', function handler(info) {\n return new Response(JSON.stringify(${responseName}()), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })\n `}\n </>\n )\n}\n\nconst defaultTemplates = { default: Template } as const\n\ntype Props = {\n /**\n * This will make it possible to override the default behaviour.\n */\n Template?: React.ComponentType<React.ComponentProps<typeof Template>>\n}\n\nexport function Mock({ Template = defaultTemplates.default }: Props): ReactNode {\n const { pluginManager } = useApp<PluginMsw>()\n const { getSchemas, getName } = useOperationManager()\n const operation = useOperation()\n\n const schemas = getSchemas(operation)\n const name = getName(operation, { type: 'function' })\n const responseName = pluginManager.resolveName({\n pluginKey: [pluginFakerName],\n name: schemas.response.name,\n type: 'type',\n })\n\n return <Template name={name} responseName={responseName} method={operation.method} path={new URLPath(operation.path)} />\n}\n\ntype FileProps = {\n /**\n * This will make it possible to override the default behaviour.\n */\n templates?: typeof defaultTemplates\n}\n\nMock.File = function ({ templates = defaultTemplates }: FileProps): ReactNode {\n const {\n pluginManager,\n plugin: {\n options: { extName },\n },\n } = useApp<PluginMsw>()\n const { getSchemas, getFile } = useOperationManager()\n const operation = useOperation()\n\n const schemas = getSchemas(operation)\n const file = getFile(operation)\n const fileFaker = getFile(operation, { pluginKey: [pluginFakerName] })\n const responseName = pluginManager.resolveName({\n pluginKey: [pluginFakerName],\n name: schemas.response.name,\n type: 'function',\n })\n\n const Template = templates.default\n\n return (\n <Parser language=\"typescript\">\n <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>\n <File.Import name={['http']} path={'msw'} />\n {fileFaker && responseName && <File.Import extName={extName} name={[responseName]} root={file.path} path={fileFaker.path} />}\n <File.Source>\n <Mock Template={Template} />\n </File.Source>\n </File>\n </Parser>\n )\n}\n\nMock.templates = defaultTemplates\n","import { Parser, File, useApp } from '@kubb/react'\nimport { useOperationManager, useOperations } from '@kubb/plugin-oas/hooks'\n\nimport type { KubbNode } from '@kubb/react'\nimport type { ReactNode } from 'react'\nimport type { FileMeta, PluginMsw } from '../types.ts'\n\ntype TemplateProps = {\n /**\n * Name of the function\n */\n name: string\n handlers: string[]\n}\n\nfunction Template({ name, handlers }: TemplateProps): ReactNode {\n return <>{`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}</>\n}\n\ntype ParserTemplateProps = {\n children?: React.ReactNode\n}\n\nfunction RootTemplate({ children }: ParserTemplateProps) {\n const {\n pluginManager,\n plugin: { key: pluginKey },\n } = useApp<PluginMsw>()\n\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extName: '.ts', pluginKey })\n const operations = useOperations()\n\n const imports = operations\n .map((operation) => {\n const operationFile = getFile(operation, { pluginKey })\n const operationName = getName(operation, { pluginKey, type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n .filter(Boolean)\n\n return (\n <Parser language=\"typescript\">\n <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>\n {imports}\n <File.Source>{children}</File.Source>\n </File>\n </Parser>\n )\n}\n\nconst defaultTemplates = { default: Template, root: RootTemplate } as const\n\ntype Templates = Partial<typeof defaultTemplates>\n\ntype Props = {\n /**\n * This will make it possible to override the default behaviour.\n */\n Template?: React.ComponentType<React.ComponentProps<typeof Template>>\n}\n\nexport function Operations({ Template = defaultTemplates.default }: Props): ReactNode {\n const {\n plugin: { key: pluginKey },\n } = useApp<PluginMsw>()\n\n const operations = useOperations()\n const { getName } = useOperationManager()\n\n return <Template name=\"handlers\" handlers={operations.map((operation) => getName(operation, { type: 'function', pluginKey }))} />\n}\n\ntype FileProps = {\n /**\n * This will make it possible to override the default behaviour.\n */\n templates?: Templates\n}\n\nOperations.File = function (props: FileProps): KubbNode {\n const templates = { ...defaultTemplates, ...props.templates }\n\n const Template = templates.default\n const RootTemplate = templates.root\n\n return (\n <RootTemplate>\n <Operations Template={Template} />\n </RootTemplate>\n )\n}\n\nOperations.templates = defaultTemplates\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/Mock.tsx","../src/components/Operations.tsx"],"sourcesContent":["import { PackageManager } from '@kubb/core'\nimport { URLPath } from '@kubb/core/utils'\nimport { Parser, File, useApp } from '@kubb/react'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'\n\nimport type { HttpMethod } from '@kubb/oas'\nimport type { ReactNode } from 'react'\nimport type { FileMeta, PluginMsw } from '../types.ts'\n\ntype TemplateProps = {\n /**\n * Name of the function\n */\n name: string\n /**\n * Method of the current operation, see useOperation.\n */\n method: HttpMethod\n /**\n * Path of the mock\n */\n path: URLPath\n /**\n * Name of the import for the mock(this is a function).\n * @example createPet\n */\n responseName: string\n}\n\nfunction Template({ name, method, path, responseName }: TemplateProps): ReactNode {\n return (\n <>\n {`\n export const ${name} = http.${method}('*${path.toURLPath()}', function handler(info) {\n return new Response(JSON.stringify(${responseName}()), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n })\n `}\n </>\n )\n}\n\nconst defaultTemplates = { default: Template } as const\n\ntype Props = {\n /**\n * This will make it possible to override the default behaviour.\n */\n Template?: React.ComponentType<React.ComponentProps<typeof Template>>\n}\n\nexport function Mock({ Template = defaultTemplates.default }: Props): ReactNode {\n const { pluginManager } = useApp<PluginMsw>()\n const { getSchemas, getName } = useOperationManager()\n const operation = useOperation()\n\n const schemas = getSchemas(operation)\n const name = getName(operation, { type: 'function' })\n const responseName = pluginManager.resolveName({\n pluginKey: [pluginFakerName],\n name: schemas.response.name,\n type: 'type',\n })\n\n return <Template name={name} responseName={responseName} method={operation.method} path={new URLPath(operation.path)} />\n}\n\ntype FileProps = {\n /**\n * This will make it possible to override the default behaviour.\n */\n templates?: typeof defaultTemplates\n}\n\nMock.File = function ({ templates = defaultTemplates }: FileProps): ReactNode {\n const {\n pluginManager,\n plugin: {\n options: { extName },\n },\n } = useApp<PluginMsw>()\n const { getSchemas, getFile } = useOperationManager()\n const operation = useOperation()\n\n const schemas = getSchemas(operation)\n const file = getFile(operation)\n const fileFaker = getFile(operation, { pluginKey: [pluginFakerName] })\n const responseName = pluginManager.resolveName({\n pluginKey: [pluginFakerName],\n name: schemas.response.name,\n type: 'function',\n })\n\n const Template = templates.default\n\n return (\n <Parser language=\"typescript\">\n <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>\n <File.Import name={['http']} path={'msw'} />\n {fileFaker && responseName && <File.Import extName={extName} name={[responseName]} root={file.path} path={fileFaker.path} />}\n <File.Source>\n <Mock Template={Template} />\n </File.Source>\n </File>\n </Parser>\n )\n}\n\nMock.templates = defaultTemplates\n","import { Parser, File, useApp } from '@kubb/react'\nimport { useOperationManager, useOperations } from '@kubb/plugin-oas/hooks'\n\nimport type { KubbNode } from '@kubb/react'\nimport type { ReactNode } from 'react'\nimport type { FileMeta, PluginMsw } from '../types.ts'\n\ntype TemplateProps = {\n /**\n * Name of the function\n */\n name: string\n handlers: string[]\n}\n\nfunction Template({ name, handlers }: TemplateProps): ReactNode {\n return <>{`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}</>\n}\n\ntype ParserTemplateProps = {\n children?: React.ReactNode\n}\n\nfunction RootTemplate({ children }: ParserTemplateProps) {\n const {\n pluginManager,\n plugin: { key: pluginKey },\n } = useApp<PluginMsw>()\n\n const { getName, getFile } = useOperationManager()\n\n const file = pluginManager.getFile({ name: 'handlers', extName: '.ts', pluginKey })\n const operations = useOperations()\n\n const imports = operations\n .map((operation) => {\n const operationFile = getFile(operation, { pluginKey })\n const operationName = getName(operation, { pluginKey, type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n .filter(Boolean)\n\n return (\n <Parser language=\"typescript\">\n <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>\n {imports}\n <File.Source>{children}</File.Source>\n </File>\n </Parser>\n )\n}\n\nconst defaultTemplates = { default: Template, root: RootTemplate } as const\n\ntype Templates = Partial<typeof defaultTemplates>\n\ntype Props = {\n /**\n * This will make it possible to override the default behaviour.\n */\n Template?: React.ComponentType<React.ComponentProps<typeof Template>>\n}\n\nexport function Operations({ Template = defaultTemplates.default }: Props): ReactNode {\n const {\n plugin: { key: pluginKey },\n } = useApp<PluginMsw>()\n\n const operations = useOperations()\n const { getName } = useOperationManager()\n\n return <Template name=\"handlers\" handlers={operations.map((operation) => getName(operation, { type: 'function', pluginKey }))} />\n}\n\ntype FileProps = {\n /**\n * This will make it possible to override the default behaviour.\n */\n templates?: Templates\n}\n\nOperations.File = function (props: FileProps): KubbNode {\n const templates = { ...defaultTemplates, ...props.templates }\n\n const Template = templates.default\n const RootTemplate = templates.root\n\n return (\n <RootTemplate>\n <Operations Template={Template} />\n </RootTemplate>\n )\n}\n\nOperations.templates = defaultTemplates\n"],"mappings":";AAAA,OAA+B;AAC/B,SAAS,eAAe;AACxB,SAAS,QAAQ,MAAM,cAAc;AACrC,SAAS,uBAAuB;AAChC,SAAS,cAAc,2BAA2B;AA4B9C,wBAqEE,YArEF;AAFJ,SAAS,SAAS,EAAE,MAAM,QAAQ,MAAM,aAAa,GAA6B;AAChF,SACE,gCACG;AAAA,iBACU,IAAI,WAAW,MAAM,MAAM,KAAK,UAAU,CAAC;AAAA,yCACnB,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KAOjD;AAEJ;AAEA,IAAM,mBAAmB,EAAE,SAAS,SAAS;AAStC,SAAS,KAAK,EAAE,UAAAA,YAAW,iBAAiB,QAAQ,GAAqB;AAC9E,QAAM,EAAE,cAAc,IAAI,OAAkB;AAC5C,QAAM,EAAE,YAAY,QAAQ,IAAI,oBAAoB;AACpD,QAAM,YAAY,aAAa;AAE/B,QAAM,UAAU,WAAW,SAAS;AACpC,QAAM,OAAO,QAAQ,WAAW,EAAE,MAAM,WAAW,CAAC;AACpD,QAAM,eAAe,cAAc,YAAY;AAAA,IAC7C,WAAW,CAAC,eAAe;AAAA,IAC3B,MAAM,QAAQ,SAAS;AAAA,IAC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