@kubb/plugin-msw 3.0.0-alpha.2 → 3.0.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -4
- package/dist/chunk-6M2QU6UL.js +22 -0
- package/dist/chunk-6M2QU6UL.js.map +1 -0
- package/dist/chunk-73P6BBZZ.js +125 -0
- package/dist/chunk-73P6BBZZ.js.map +1 -0
- package/dist/chunk-GODA4G5K.cjs +25 -0
- package/dist/chunk-GODA4G5K.cjs.map +1 -0
- package/dist/chunk-UZ4ZUY3N.cjs +134 -0
- package/dist/chunk-UZ4ZUY3N.cjs.map +1 -0
- package/dist/components.cjs +11 -4
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +7 -70
- package/dist/components.d.ts +7 -70
- package/dist/components.js +2 -8
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +9 -0
- package/dist/generators.d.ts +9 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +11 -137
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -86
- package/dist/index.d.ts +3 -86
- package/dist/index.js +3 -142
- package/dist/index.js.map +1 -1
- package/dist/types-B2IuaP_7.d.cts +60 -0
- package/dist/types-B2IuaP_7.d.ts +60 -0
- package/package.json +22 -17
- package/src/components/Handlers.tsx +19 -0
- package/src/components/Mock.tsx +9 -92
- package/src/components/index.ts +1 -1
- package/src/generators/__snapshots__/createPet.ts +9 -0
- package/src/generators/__snapshots__/deletePet.ts +9 -0
- package/src/generators/__snapshots__/getPets.ts +9 -0
- package/src/generators/__snapshots__/handlers.ts +3 -0
- package/src/generators/__snapshots__/showPetById.ts +9 -0
- package/src/generators/handlersGenerator.tsx +32 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/mswGenerator.tsx +38 -0
- package/src/plugin.ts +16 -34
- package/src/types.ts +9 -38
- package/dist/chunk-S4P5XPFN.cjs +0 -105
- package/dist/chunk-S4P5XPFN.cjs.map +0 -1
- package/dist/chunk-WRIEMCYI.js +0 -105
- package/dist/chunk-WRIEMCYI.js.map +0 -1
- package/src/OperationGenerator.tsx +0 -66
- package/src/components/Operations.tsx +0 -96
- package/src/components/__snapshots__/Mock/Pets.ts +0 -7
- package/src/components/__snapshots__/Mock/showPetsById.ts +0 -7
|
@@ -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","RootTemplate"],"mappings":"AAAA;ACAA,sBAA+B;AAC/B,yCAAwB;AACxB,oCAAqC;AACrC,iDAAgC;AAChC,+CAAkD;AA4B9C,qDAAA;AAFJ,SAAS,QAAA,CAAS,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,aAAa,CAAA,EAA6B;AAChF,EAAA,uBACE,6BAAA,oBAAA,EAAA,EACG,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,CAAA;AAEJ;AAEA,IAAM,iBAAA,EAAmB,EAAE,OAAA,EAAS,SAAS,CAAA;AAStC,SAAS,IAAA,CAAK,EAAE,QAAA,EAAAA,UAAAA,EAAW,gBAAA,CAAiB,QAAQ,CAAA,EAAqB;AAC9E,EAAA,MAAM,EAAE,cAAc,EAAA,EAAI,2BAAA,CAAkB;AAC5C,EAAA,MAAM,EAAE,UAAA,EAAY,QAAQ,EAAA,EAAI,wCAAA,CAAoB;AACpD,EAAA,MAAM,UAAA,EAAY,iCAAA,CAAa;A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'@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"]}
|
package/dist/chunk-WRIEMCYI.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
// src/components/Mock.tsx
|
|
2
|
-
import "@kubb/core";
|
|
3
|
-
import { URLPath } from "@kubb/core/utils";
|
|
4
|
-
import { Parser, File, useApp } from "@kubb/react";
|
|
5
|
-
import { pluginFakerName } from "@kubb/plugin-faker";
|
|
6
|
-
import { useOperation, useOperationManager } from "@kubb/plugin-oas/hooks";
|
|
7
|
-
import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
8
|
-
function Template({ name, method, path, responseName }) {
|
|
9
|
-
return /* @__PURE__ */ jsx(Fragment, { children: `
|
|
10
|
-
export const ${name} = http.${method}('*${path.toURLPath()}', function handler(info) {
|
|
11
|
-
return new Response(JSON.stringify(${responseName}()), {
|
|
12
|
-
headers: {
|
|
13
|
-
'Content-Type': 'application/json',
|
|
14
|
-
},
|
|
15
|
-
})
|
|
16
|
-
})
|
|
17
|
-
` });
|
|
18
|
-
}
|
|
19
|
-
var defaultTemplates = { default: Template };
|
|
20
|
-
function Mock({ Template: Template3 = defaultTemplates.default }) {
|
|
21
|
-
const { pluginManager } = useApp();
|
|
22
|
-
const { getSchemas, getName } = useOperationManager();
|
|
23
|
-
const operation = useOperation();
|
|
24
|
-
const schemas = getSchemas(operation);
|
|
25
|
-
const name = getName(operation, { type: "function" });
|
|
26
|
-
const responseName = pluginManager.resolveName({
|
|
27
|
-
pluginKey: [pluginFakerName],
|
|
28
|
-
name: schemas.response.name,
|
|
29
|
-
type: "type"
|
|
30
|
-
});
|
|
31
|
-
return /* @__PURE__ */ jsx(Template3, { name, responseName, method: operation.method, path: new URLPath(operation.path) });
|
|
32
|
-
}
|
|
33
|
-
Mock.File = function({ templates = defaultTemplates }) {
|
|
34
|
-
const {
|
|
35
|
-
pluginManager,
|
|
36
|
-
plugin: {
|
|
37
|
-
options: { extName }
|
|
38
|
-
}
|
|
39
|
-
} = useApp();
|
|
40
|
-
const { getSchemas, getFile } = useOperationManager();
|
|
41
|
-
const operation = useOperation();
|
|
42
|
-
const schemas = getSchemas(operation);
|
|
43
|
-
const file = getFile(operation);
|
|
44
|
-
const fileFaker = getFile(operation, { pluginKey: [pluginFakerName] });
|
|
45
|
-
const responseName = pluginManager.resolveName({
|
|
46
|
-
pluginKey: [pluginFakerName],
|
|
47
|
-
name: schemas.response.name,
|
|
48
|
-
type: "function"
|
|
49
|
-
});
|
|
50
|
-
const Template3 = templates.default;
|
|
51
|
-
return /* @__PURE__ */ jsx(Parser, { language: "typescript", children: /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
52
|
-
/* @__PURE__ */ jsx(File.Import, { name: ["http"], path: "msw" }),
|
|
53
|
-
fileFaker && responseName && /* @__PURE__ */ jsx(File.Import, { extName, name: [responseName], root: file.path, path: fileFaker.path }),
|
|
54
|
-
/* @__PURE__ */ jsx(File.Source, { children: /* @__PURE__ */ jsx(Mock, { Template: Template3 }) })
|
|
55
|
-
] }) });
|
|
56
|
-
};
|
|
57
|
-
Mock.templates = defaultTemplates;
|
|
58
|
-
|
|
59
|
-
// src/components/Operations.tsx
|
|
60
|
-
import { Parser as Parser2, File as File2, useApp as useApp2 } from "@kubb/react";
|
|
61
|
-
import { useOperationManager as useOperationManager2, useOperations } from "@kubb/plugin-oas/hooks";
|
|
62
|
-
import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "@kubb/react/jsx-runtime";
|
|
63
|
-
function Template2({ name, handlers }) {
|
|
64
|
-
return /* @__PURE__ */ jsx2(Fragment2, { children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
|
|
65
|
-
}
|
|
66
|
-
function RootTemplate({ children }) {
|
|
67
|
-
const {
|
|
68
|
-
pluginManager,
|
|
69
|
-
plugin: { key: pluginKey }
|
|
70
|
-
} = useApp2();
|
|
71
|
-
const { getName, getFile } = useOperationManager2();
|
|
72
|
-
const file = pluginManager.getFile({ name: "handlers", extName: ".ts", pluginKey });
|
|
73
|
-
const operations = useOperations();
|
|
74
|
-
const imports = operations.map((operation) => {
|
|
75
|
-
const operationFile = getFile(operation, { pluginKey });
|
|
76
|
-
const operationName = getName(operation, { pluginKey, type: "function" });
|
|
77
|
-
return /* @__PURE__ */ jsx2(File2.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
|
|
78
|
-
}).filter(Boolean);
|
|
79
|
-
return /* @__PURE__ */ jsx2(Parser2, { language: "typescript", children: /* @__PURE__ */ jsxs2(File2, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
80
|
-
imports,
|
|
81
|
-
/* @__PURE__ */ jsx2(File2.Source, { children })
|
|
82
|
-
] }) });
|
|
83
|
-
}
|
|
84
|
-
var defaultTemplates2 = { default: Template2, root: RootTemplate };
|
|
85
|
-
function Operations({ Template: Template3 = defaultTemplates2.default }) {
|
|
86
|
-
const {
|
|
87
|
-
plugin: { key: pluginKey }
|
|
88
|
-
} = useApp2();
|
|
89
|
-
const operations = useOperations();
|
|
90
|
-
const { getName } = useOperationManager2();
|
|
91
|
-
return /* @__PURE__ */ jsx2(Template3, { name: "handlers", handlers: operations.map((operation) => getName(operation, { type: "function", pluginKey })) });
|
|
92
|
-
}
|
|
93
|
-
Operations.File = function(props) {
|
|
94
|
-
const templates = { ...defaultTemplates2, ...props.templates };
|
|
95
|
-
const Template3 = templates.default;
|
|
96
|
-
const RootTemplate2 = templates.root;
|
|
97
|
-
return /* @__PURE__ */ jsx2(RootTemplate2, { children: /* @__PURE__ */ jsx2(Operations, { Template: Template3 }) });
|
|
98
|
-
};
|
|
99
|
-
Operations.templates = defaultTemplates2;
|
|
100
|
-
|
|
101
|
-
export {
|
|
102
|
-
Mock,
|
|
103
|
-
Operations
|
|
104
|
-
};
|
|
105
|
-
//# sourceMappingURL=chunk-WRIEMCYI.js.map
|
|
@@ -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,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,KAACJ,MAAK,QAAL,EAAa,UAAS;AAAA,KACzB,GACF;AAEJ;AAEA,IAAMO,oBAAmB,EAAE,SAASD,WAAU,MAAM,aAAa;AAW1D,SAAS,WAAW,EAAE,UAAAA,YAAWC,kBAAiB,QAAQ,GAAqB;AACpF,QAAM;AAAA,IACJ,QAAQ,EAAE,KAAK,UAAU;AAAA,EAC3B,IAAIN,QAAkB;AAEtB,QAAM,aAAa,cAAc;AACjC,QAAM,EAAE,QAAQ,IAAIC,qBAAoB;AAExC,SAAO,gBAAAE,KAACE,WAAA,EAAS,MAAK,YAAW,UAAU,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","Parser","File","useApp","useOperationManager","Fragment","jsx","jsxs","Template","defaultTemplates","RootTemplate"]}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { OperationGenerator as Generator } from '@kubb/plugin-oas'
|
|
2
|
-
import { Oas } from '@kubb/plugin-oas/components'
|
|
3
|
-
import { App, createRoot } from '@kubb/react'
|
|
4
|
-
|
|
5
|
-
import { Mock } from './components/Mock.tsx'
|
|
6
|
-
import { Operations } from './components/Operations.tsx'
|
|
7
|
-
|
|
8
|
-
import type { Operation } from '@kubb/oas'
|
|
9
|
-
import type { OperationMethodResult, OperationsByMethod } from '@kubb/plugin-oas'
|
|
10
|
-
import type { FileMeta, PluginMsw } from './types.ts'
|
|
11
|
-
|
|
12
|
-
export class OperationGenerator extends Generator<PluginMsw['resolvedOptions'], PluginMsw> {
|
|
13
|
-
async all(operations: Operation[], operationsByMethod: OperationsByMethod): OperationMethodResult<FileMeta> {
|
|
14
|
-
const { oas, pluginManager, plugin, mode } = this.context
|
|
15
|
-
|
|
16
|
-
const root = createRoot({
|
|
17
|
-
logger: pluginManager.logger,
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
const templates = {
|
|
21
|
-
operations: Operations.templates,
|
|
22
|
-
mock: Mock.templates,
|
|
23
|
-
...this.options.templates,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
root.render(
|
|
27
|
-
<App pluginManager={pluginManager} plugin={plugin} mode={mode}>
|
|
28
|
-
<Oas oas={oas} operations={operations} generator={this}>
|
|
29
|
-
{templates?.operations && <Operations.File templates={templates.operations} />}
|
|
30
|
-
</Oas>
|
|
31
|
-
</App>,
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
return root.files
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async operation(operation: Operation, options: PluginMsw['resolvedOptions']): OperationMethodResult<FileMeta> {
|
|
38
|
-
const { oas, pluginManager, plugin, mode } = this.context
|
|
39
|
-
|
|
40
|
-
const root = createRoot({
|
|
41
|
-
logger: pluginManager.logger,
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
const templates = {
|
|
45
|
-
handlers: Operations.templates,
|
|
46
|
-
mock: Mock.templates,
|
|
47
|
-
...options.templates,
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (!templates?.mock) {
|
|
51
|
-
return []
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
root.render(
|
|
55
|
-
<App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>
|
|
56
|
-
<Oas oas={oas} operations={[operation]} generator={this}>
|
|
57
|
-
<Oas.Operation operation={operation}>
|
|
58
|
-
<Mock.File templates={templates.mock} />
|
|
59
|
-
</Oas.Operation>
|
|
60
|
-
</Oas>
|
|
61
|
-
</App>,
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
return root.files
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { Parser, File, useApp } from '@kubb/react'
|
|
2
|
-
import { useOperationManager, useOperations } from '@kubb/plugin-oas/hooks'
|
|
3
|
-
|
|
4
|
-
import type { KubbNode } from '@kubb/react'
|
|
5
|
-
import type { ReactNode } from 'react'
|
|
6
|
-
import type { FileMeta, PluginMsw } from '../types.ts'
|
|
7
|
-
|
|
8
|
-
type TemplateProps = {
|
|
9
|
-
/**
|
|
10
|
-
* Name of the function
|
|
11
|
-
*/
|
|
12
|
-
name: string
|
|
13
|
-
handlers: string[]
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function Template({ name, handlers }: TemplateProps): ReactNode {
|
|
17
|
-
return <>{`export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, '')} as const`}</>
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type ParserTemplateProps = {
|
|
21
|
-
children?: React.ReactNode
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function RootTemplate({ children }: ParserTemplateProps) {
|
|
25
|
-
const {
|
|
26
|
-
pluginManager,
|
|
27
|
-
plugin: { key: pluginKey },
|
|
28
|
-
} = useApp<PluginMsw>()
|
|
29
|
-
|
|
30
|
-
const { getName, getFile } = useOperationManager()
|
|
31
|
-
|
|
32
|
-
const file = pluginManager.getFile({ name: 'handlers', extName: '.ts', pluginKey })
|
|
33
|
-
const operations = useOperations()
|
|
34
|
-
|
|
35
|
-
const imports = operations
|
|
36
|
-
.map((operation) => {
|
|
37
|
-
const operationFile = getFile(operation, { pluginKey })
|
|
38
|
-
const operationName = getName(operation, { pluginKey, type: 'function' })
|
|
39
|
-
|
|
40
|
-
return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />
|
|
41
|
-
})
|
|
42
|
-
.filter(Boolean)
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<Parser language="typescript">
|
|
46
|
-
<File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
47
|
-
{imports}
|
|
48
|
-
<File.Source>{children}</File.Source>
|
|
49
|
-
</File>
|
|
50
|
-
</Parser>
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const defaultTemplates = { default: Template, root: RootTemplate } as const
|
|
55
|
-
|
|
56
|
-
type Templates = Partial<typeof defaultTemplates>
|
|
57
|
-
|
|
58
|
-
type Props = {
|
|
59
|
-
/**
|
|
60
|
-
* This will make it possible to override the default behaviour.
|
|
61
|
-
*/
|
|
62
|
-
Template?: React.ComponentType<React.ComponentProps<typeof Template>>
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function Operations({ Template = defaultTemplates.default }: Props): ReactNode {
|
|
66
|
-
const {
|
|
67
|
-
plugin: { key: pluginKey },
|
|
68
|
-
} = useApp<PluginMsw>()
|
|
69
|
-
|
|
70
|
-
const operations = useOperations()
|
|
71
|
-
const { getName } = useOperationManager()
|
|
72
|
-
|
|
73
|
-
return <Template name="handlers" handlers={operations.map((operation) => getName(operation, { type: 'function', pluginKey }))} />
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
type FileProps = {
|
|
77
|
-
/**
|
|
78
|
-
* This will make it possible to override the default behaviour.
|
|
79
|
-
*/
|
|
80
|
-
templates?: Templates
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
Operations.File = function (props: FileProps): KubbNode {
|
|
84
|
-
const templates = { ...defaultTemplates, ...props.templates }
|
|
85
|
-
|
|
86
|
-
const Template = templates.default
|
|
87
|
-
const RootTemplate = templates.root
|
|
88
|
-
|
|
89
|
-
return (
|
|
90
|
-
<RootTemplate>
|
|
91
|
-
<Operations Template={Template} />
|
|
92
|
-
</RootTemplate>
|
|
93
|
-
)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
Operations.templates = defaultTemplates
|