@kubb/plugin-msw 3.0.0-alpha.10 → 3.0.0-alpha.12

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.
@@ -1,9 +1,10 @@
1
+ import { URLPath } from '@kubb/core/utils';
2
+ import { useApp, File } from '@kubb/react';
3
+ import { pluginFakerName } from '@kubb/plugin-faker';
4
+ import { useOperationManager, useOperation, useOperations } from '@kubb/plugin-oas/hooks';
5
+ import { jsx, jsxs } from '@kubb/react/jsx-runtime';
6
+
1
7
  // src/components/Mock.tsx
2
- import { URLPath } from "@kubb/core/utils";
3
- import { File, useApp } from "@kubb/react";
4
- import { pluginFakerName } from "@kubb/plugin-faker";
5
- import { useOperation, useOperationManager } from "@kubb/plugin-oas/hooks";
6
- import { jsx, jsxs } from "@kubb/react/jsx-runtime";
7
8
  function Template({ name, method, path, responseName }) {
8
9
  return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: `
9
10
  export const ${name} = http.${method}('*${path.toURLPath()}', function handler(info) {
@@ -54,28 +55,23 @@ Mock.File = function({ templates = defaultTemplates }) {
54
55
  ] });
55
56
  };
56
57
  Mock.templates = defaultTemplates;
57
-
58
- // src/components/Operations.tsx
59
- import { useOperationManager as useOperationManager2, useOperations } from "@kubb/plugin-oas/hooks";
60
- import { File as File2, useApp as useApp2 } from "@kubb/react";
61
- import { jsx as jsx2, jsxs as jsxs2 } from "@kubb/react/jsx-runtime";
62
58
  function Template2({ name, handlers }) {
63
- return /* @__PURE__ */ jsx2(File2.Source, { name, isExportable: true, isIndexable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
59
+ return /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
64
60
  }
65
61
  function RootTemplate({ children }) {
66
62
  const {
67
63
  pluginManager,
68
64
  plugin: { key: pluginKey }
69
- } = useApp2();
70
- const { getName, getFile } = useOperationManager2();
65
+ } = useApp();
66
+ const { getName, getFile } = useOperationManager();
71
67
  const file = pluginManager.getFile({ name: "handlers", extName: ".ts", pluginKey });
72
68
  const operations = useOperations();
73
69
  const imports = operations.map((operation) => {
74
70
  const operationFile = getFile(operation, { pluginKey });
75
71
  const operationName = getName(operation, { pluginKey, type: "function" });
76
- return /* @__PURE__ */ jsx2(File2.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
72
+ return /* @__PURE__ */ jsx(File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
77
73
  }).filter(Boolean);
78
- return /* @__PURE__ */ jsxs2(File2, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
74
+ return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
79
75
  imports,
80
76
  children
81
77
  ] });
@@ -84,21 +80,19 @@ var defaultTemplates2 = { default: Template2, root: RootTemplate };
84
80
  function Operations({ Template: Template3 = defaultTemplates2.default }) {
85
81
  const {
86
82
  plugin: { key: pluginKey }
87
- } = useApp2();
83
+ } = useApp();
88
84
  const operations = useOperations();
89
- const { getName } = useOperationManager2();
90
- return /* @__PURE__ */ jsx2(Template3, { name: "handlers", handlers: operations.map((operation) => getName(operation, { type: "function", pluginKey })) });
85
+ const { getName } = useOperationManager();
86
+ return /* @__PURE__ */ jsx(Template3, { name: "handlers", handlers: operations.map((operation) => getName(operation, { type: "function", pluginKey })) });
91
87
  }
92
88
  Operations.File = function(props) {
93
89
  const templates = { ...defaultTemplates2, ...props.templates };
94
90
  const Template3 = templates.default;
95
91
  const RootTemplate2 = templates.root;
96
- return /* @__PURE__ */ jsx2(RootTemplate2, { children: /* @__PURE__ */ jsx2(Operations, { Template: Template3 }) });
92
+ return /* @__PURE__ */ jsx(RootTemplate2, { children: /* @__PURE__ */ jsx(Operations, { Template: Template3 }) });
97
93
  };
98
94
  Operations.templates = defaultTemplates2;
99
95
 
100
- export {
101
- Mock,
102
- Operations
103
- };
96
+ export { Mock, Operations };
97
+ //# sourceMappingURL=chunk-3KHLTEUD.js.map
104
98
  //# sourceMappingURL=chunk-3KHLTEUD.js.map
@@ -1 +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 isIndexable>\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 isIndexable>{`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,MAAC,aAAW,MAC9C;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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AAY,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"]}
1
+ {"version":3,"sources":["../src/components/Mock.tsx","../src/components/Operations.tsx"],"names":["Template","jsx","File","useApp","useOperationManager","jsxs","defaultTemplates","RootTemplate"],"mappings":";;;;;;;AA6BA,SAAS,SAAS,EAAE,IAAA,EAAM,MAAQ,EAAA,IAAA,EAAM,cAA0C,EAAA;AAChF,EACE,uBAAA,GAAA,CAAC,KAAK,MAAL,EAAA,EAAY,MAAY,YAAY,EAAA,IAAA,EAAC,aAAW,IAC9C,EAAA,QAAA,EAAA,CAAA;AAAA,eAAA,EACU,IAAI,CAAW,QAAA,EAAA,MAAM,CAAM,GAAA,EAAA,IAAA,CAAK,WAAW,CAAA;AAAA,uCAAA,EACnB,YAAY,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOjD,CAAA,EAAA,CAAA,CAAA;AAEJ,CAAA;AAEA,IAAM,gBAAA,GAAmB,EAAE,OAAA,EAAS,QAAS,EAAA,CAAA;AAStC,SAAS,KAAK,EAAE,QAAA,EAAAA,SAAW,GAAA,gBAAA,CAAiB,SAA6B,EAAA;AAC9E,EAAM,MAAA,EAAE,aAAc,EAAA,GAAI,MAAkB,EAAA,CAAA;AAC5C,EAAA,MAAM,EAAE,UAAA,EAAY,OAAQ,EAAA,GAAI,mBAAoB,EAAA,CAAA;AACpD,EAAA,MAAM,YAAY,YAAa,EAAA,CAAA;AAE/B,EAAM,MAAA,OAAA,GAAU,WAAW,SAAS,CAAA,CA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A;AACjC,EAAM,MAAA,EAAE,OAAQ,EAAA,GAAIC,mBAAoB,EAAA,CAAA;AAExC,EAAA,uBAAOH,GAACD,CAAAA,SAAAA,EAAA,EAAS,IAAK,EAAA,UAAA,EAAW,UAAU,UAAW,CAAA,GAAA,CAAI,CAAC,SAAc,KAAA,OAAA,CAAQ,WAAW,EAAE,IAAA,EAAM,YAAY,SAAU,EAAC,CAAC,CAAG,EAAA,CAAA,CAAA;AACjI,CAAA;AASA,UAAW,CAAA,IAAA,GAAO,SAAU,KAA4B,EAAA;AACtD,EAAA,MAAM,YAAY,EAAE,GAAGM,iBAAkB,EAAA,GAAG,MAAM,SAAU,EAAA,CAAA;AAE5D,EAAA,MAAMN,YAAW,SAAU,CAAA,OAAA,CAAA;AAC3B,EAAA,MAAMO,gBAAe,SAAU,CAAA,IAAA,CAAA;AAE/B,EACE,uBAAAN,IAACM,aAAA,EAAA,EACC,0BAAAN,GAAC,CAAA,UAAA,EAAA,EAAW,QAAUD,EAAAA,SAAAA,EAAU,CAClC,EAAA,CAAA,CAAA;AAEJ,CAAA,CAAA;AAEA,UAAA,CAAW,SAAYM,GAAAA,iBAAAA","file":"chunk-3KHLTEUD.js","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 isIndexable>\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 isIndexable>{`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,11 +1,14 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/components/Mock.tsx
2
- var _utils = require('@kubb/core/utils');
3
- var _react = require('@kubb/react');
4
- var _pluginfaker = require('@kubb/plugin-faker');
5
- var _hooks = require('@kubb/plugin-oas/hooks');
6
- var _jsxruntime = require('@kubb/react/jsx-runtime');
1
+ 'use strict';
2
+
3
+ var utils = require('@kubb/core/utils');
4
+ var react = require('@kubb/react');
5
+ var pluginFaker = require('@kubb/plugin-faker');
6
+ var hooks = require('@kubb/plugin-oas/hooks');
7
+ var jsxRuntime = require('@kubb/react/jsx-runtime');
8
+
9
+ // src/components/Mock.tsx
7
10
  function Template({ name, method, path, responseName }) {
8
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name, isExportable: true, isIndexable: true, children: `
11
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: `
9
12
  export const ${name} = http.${method}('*${path.toURLPath()}', function handler(info) {
10
13
  return new Response(JSON.stringify(${responseName}()), {
11
14
  headers: {
@@ -17,17 +20,17 @@ function Template({ name, method, path, responseName }) {
17
20
  }
18
21
  var defaultTemplates = { default: Template };
19
22
  function Mock({ Template: Template3 = defaultTemplates.default }) {
20
- const { pluginManager } = _react.useApp.call(void 0, );
21
- const { getSchemas, getName } = _hooks.useOperationManager.call(void 0, );
22
- const operation = _hooks.useOperation.call(void 0, );
23
+ const { pluginManager } = react.useApp();
24
+ const { getSchemas, getName } = hooks.useOperationManager();
25
+ const operation = hooks.useOperation();
23
26
  const schemas = getSchemas(operation);
24
27
  const name = getName(operation, { type: "function" });
25
28
  const responseName = pluginManager.resolveName({
26
- pluginKey: [_pluginfaker.pluginFakerName],
29
+ pluginKey: [pluginFaker.pluginFakerName],
27
30
  name: schemas.response.name,
28
31
  type: "type"
29
32
  });
30
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Template3, { name, responseName, method: operation.method, path: new (0, _utils.URLPath)(operation.path) });
33
+ return /* @__PURE__ */ jsxRuntime.jsx(Template3, { name, responseName, method: operation.method, path: new utils.URLPath(operation.path) });
31
34
  }
32
35
  Mock.File = function({ templates = defaultTemplates }) {
33
36
  const {
@@ -35,47 +38,42 @@ Mock.File = function({ templates = defaultTemplates }) {
35
38
  plugin: {
36
39
  options: { extName }
37
40
  }
38
- } = _react.useApp.call(void 0, );
39
- const { getSchemas, getFile } = _hooks.useOperationManager.call(void 0, );
40
- const operation = _hooks.useOperation.call(void 0, );
41
+ } = react.useApp();
42
+ const { getSchemas, getFile } = hooks.useOperationManager();
43
+ const operation = hooks.useOperation();
41
44
  const schemas = getSchemas(operation);
42
45
  const file = getFile(operation);
43
- const fileFaker = getFile(operation, { pluginKey: [_pluginfaker.pluginFakerName] });
46
+ const fileFaker = getFile(operation, { pluginKey: [pluginFaker.pluginFakerName] });
44
47
  const responseName = pluginManager.resolveName({
45
- pluginKey: [_pluginfaker.pluginFakerName],
48
+ pluginKey: [pluginFaker.pluginFakerName],
46
49
  name: schemas.response.name,
47
50
  type: "function"
48
51
  });
49
52
  const Template3 = templates.default;
50
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
51
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["http"], path: "msw" }),
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 })
53
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
54
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["http"], path: "msw" }),
55
+ fileFaker && responseName && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [responseName], root: file.path, path: fileFaker.path }),
56
+ /* @__PURE__ */ jsxRuntime.jsx(Mock, { Template: Template3 })
54
57
  ] });
55
58
  };
56
59
  Mock.templates = defaultTemplates;
57
-
58
- // src/components/Operations.tsx
59
-
60
-
61
-
62
60
  function Template2({ name, handlers }) {
63
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name, isExportable: true, isIndexable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
61
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
64
62
  }
65
63
  function RootTemplate({ children }) {
66
64
  const {
67
65
  pluginManager,
68
66
  plugin: { key: pluginKey }
69
- } = _react.useApp.call(void 0, );
70
- const { getName, getFile } = _hooks.useOperationManager.call(void 0, );
67
+ } = react.useApp();
68
+ const { getName, getFile } = hooks.useOperationManager();
71
69
  const file = pluginManager.getFile({ name: "handlers", extName: ".ts", pluginKey });
72
- const operations = _hooks.useOperations.call(void 0, );
70
+ const operations = hooks.useOperations();
73
71
  const imports = operations.map((operation) => {
74
72
  const operationFile = getFile(operation, { pluginKey });
75
73
  const operationName = getName(operation, { pluginKey, type: "function" });
76
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
74
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
77
75
  }).filter(Boolean);
78
- return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
76
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
79
77
  imports,
80
78
  children
81
79
  ] });
@@ -84,21 +82,20 @@ var defaultTemplates2 = { default: Template2, root: RootTemplate };
84
82
  function Operations({ Template: Template3 = defaultTemplates2.default }) {
85
83
  const {
86
84
  plugin: { key: pluginKey }
87
- } = _react.useApp.call(void 0, );
88
- const operations = _hooks.useOperations.call(void 0, );
89
- const { getName } = _hooks.useOperationManager.call(void 0, );
90
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Template3, { name: "handlers", handlers: operations.map((operation) => getName(operation, { type: "function", pluginKey })) });
85
+ } = react.useApp();
86
+ const operations = hooks.useOperations();
87
+ const { getName } = hooks.useOperationManager();
88
+ return /* @__PURE__ */ jsxRuntime.jsx(Template3, { name: "handlers", handlers: operations.map((operation) => getName(operation, { type: "function", pluginKey })) });
91
89
  }
92
90
  Operations.File = function(props) {
93
91
  const templates = { ...defaultTemplates2, ...props.templates };
94
92
  const Template3 = templates.default;
95
93
  const RootTemplate2 = templates.root;
96
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, RootTemplate2, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Operations, { Template: Template3 }) });
94
+ return /* @__PURE__ */ jsxRuntime.jsx(RootTemplate2, { children: /* @__PURE__ */ jsxRuntime.jsx(Operations, { Template: Template3 }) });
97
95
  };
98
96
  Operations.templates = defaultTemplates2;
99
97
 
100
-
101
-
102
-
103
- exports.Mock = Mock; exports.Operations = Operations;
98
+ exports.Mock = Mock;
99
+ exports.Operations = Operations;
100
+ //# sourceMappingURL=chunk-BD7UJBXM.cjs.map
104
101
  //# sourceMappingURL=chunk-BD7UJBXM.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-msw/dist/chunk-BD7UJBXM.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,EAAC,WAAA,EAAW,IAAA,EAC9C,QAAA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AAE/B,EAAA,uBACEN,6BAAAA,aAACM,EAAA,EACC,QAAA,kBAAAN,6BAAAA,UAAC,EAAA,EAAW,QAAA,EAAUD,UAAAA,CAAU,EAAA,CAClC,CAAA;AAEJ,CAAA;AAEA,UAAA,CAAW,UAAA,EAAYM,iBAAAA;AFKvB;AACA;AACE;AACA;AACF,qDAAC","file":"/home/runner/work/kubb/kubb/packages/plugin-msw/dist/chunk-BD7UJBXM.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 isIndexable>\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 isIndexable>{`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
+ {"version":3,"sources":["../src/components/Mock.tsx","../src/components/Operations.tsx"],"names":["jsx","File","Template","useApp","useOperationManager","useOperation","pluginFakerName","URLPath","jsxs","useOperations","defaultTemplates","RootTemplate"],"mappings":";;;;;;;;;AA6BA,SAAS,SAAS,EAAE,IAAA,EAAM,MAAQ,EAAA,IAAA,EAAM,cAA0C,EAAA;AAChF,EACE,uBAAAA,cAAA,CAACC,WAAK,MAAL,EAAA,EAAY,MAAY,YAAY,EAAA,IAAA,EAAC,aAAW,IAC9C,EAAA,QAAA,EAAA,CAAA;AAAA,eAAA,EACU,IAAI,CAAW,QAAA,EAAA,MAAM,CAAM,GAAA,EAAA,IAAA,CAAK,WAAW,CAAA;AAAA,uCAAA,EACnB,YAAY,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOjD,CAAA,EAAA,CAAA,CAAA;AAEJ,CAAA;AAEA,IAAM,gBAAA,GAA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AAA;AAAA,IACA,QAAA;AAAA,GACH,EAAA,CAAA,CAAA;AAEJ,CAAA;AAEA,IAAMS,iBAAmB,GAAA,EAAE,OAASR,EAAAA,SAAAA,EAAU,MAAM,YAAa,EAAA,CAAA;AAW1D,SAAS,WAAW,EAAE,QAAA,EAAAA,SAAWQ,GAAAA,iBAAAA,CAAiB,SAA6B,EAAA;AACpF,EAAM,MAAA;AAAA,IACJ,MAAA,EAAQ,EAAE,GAAA,EAAK,SAAU,EAAA;AAAA,MACvBP,YAAkB,EAAA,CAAA;AAEtB,EAAA,MAAM,aAAaM,mBAAc,EAAA,CAAA;AACjC,EAAM,MAAA,EAAE,OAAQ,EAAA,GAAIL,yBAAoB,EAAA,CAAA;AAExC,EAAA,uBAAOJ,cAACE,CAAAA,SAAAA,EAAA,EAAS,IAAK,EAAA,UAAA,EAAW,UAAU,UAAW,CAAA,GAAA,CAAI,CAAC,SAAc,KAAA,OAAA,CAAQ,WAAW,EAAE,IAAA,EAAM,YAAY,SAAU,EAAC,CAAC,CAAG,EAAA,CAAA,CAAA;AACjI,CAAA;AASA,UAAW,CAAA,IAAA,GAAO,SAAU,KAA4B,EAAA;AACtD,EAAA,MAAM,YAAY,EAAE,GAAGQ,iBAAkB,EAAA,GAAG,MAAM,SAAU,EAAA,CAAA;AAE5D,EAAA,MAAMR,YAAW,SAAU,CAAA,OAAA,CAAA;AAC3B,EAAA,MAAMS,gBAAe,SAAU,CAAA,IAAA,CAAA;AAE/B,EACE,uBAAAX,eAACW,aAAA,EAAA,EACC,0BAAAX,cAAC,CAAA,UAAA,EAAA,EAAW,QAAUE,EAAAA,SAAAA,EAAU,CAClC,EAAA,CAAA,CAAA;AAEJ,CAAA,CAAA;AAEA,UAAA,CAAW,SAAYQ,GAAAA,iBAAAA","file":"chunk-BD7UJBXM.cjs","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 isIndexable>\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 isIndexable>{`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,9 +1,16 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
1
+ 'use strict';
2
2
 
3
+ var chunkBD7UJBXM_cjs = require('./chunk-BD7UJBXM.cjs');
3
4
 
4
- var _chunkBD7UJBXMcjs = require('./chunk-BD7UJBXM.cjs');
5
5
 
6
6
 
7
-
8
- exports.Mock = _chunkBD7UJBXMcjs.Mock; exports.Operations = _chunkBD7UJBXMcjs.Operations;
7
+ Object.defineProperty(exports, "Mock", {
8
+ enumerable: true,
9
+ get: function () { return chunkBD7UJBXM_cjs.Mock; }
10
+ });
11
+ Object.defineProperty(exports, "Operations", {
12
+ enumerable: true,
13
+ get: function () { return chunkBD7UJBXM_cjs.Operations; }
14
+ });
15
+ //# sourceMappingURL=components.cjs.map
9
16
  //# sourceMappingURL=components.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-msw/dist/components.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,yFAAC","file":"/home/runner/work/kubb/kubb/packages/plugin-msw/dist/components.cjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"components.cjs"}
@@ -1,9 +1,3 @@
1
- import {
2
- Mock,
3
- Operations
4
- } from "./chunk-3KHLTEUD.js";
5
- export {
6
- Mock,
7
- Operations
8
- };
1
+ export { Mock, Operations } from './chunk-3KHLTEUD.js';
2
+ //# sourceMappingURL=components.js.map
9
3
  //# sourceMappingURL=components.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"components.js"}
package/dist/index.cjs CHANGED
@@ -1,53 +1,52 @@
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; }
1
+ 'use strict';
2
2
 
3
+ var chunkBD7UJBXM_cjs = require('./chunk-BD7UJBXM.cjs');
4
+ var path = require('path');
5
+ var core = require('@kubb/core');
6
+ var transformers = require('@kubb/core/transformers');
7
+ var utils = require('@kubb/core/utils');
8
+ var pluginOas = require('@kubb/plugin-oas');
9
+ var pluginFaker = require('@kubb/plugin-faker');
10
+ var pluginTs = require('@kubb/plugin-ts');
11
+ var components = require('@kubb/plugin-oas/components');
12
+ var react = require('@kubb/react');
13
+ var jsxRuntime = require('@kubb/react/jsx-runtime');
3
14
 
4
- var _chunkBD7UJBXMcjs = require('./chunk-BD7UJBXM.cjs');
15
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
5
16
 
6
- // src/plugin.ts
7
- var _path = require('path'); var _path2 = _interopRequireDefault(_path);
8
- var _core = require('@kubb/core');
9
- var _transformers = require('@kubb/core/transformers');
10
- var _utils = require('@kubb/core/utils');
11
- var _pluginoas = require('@kubb/plugin-oas');
12
- var _pluginfaker = require('@kubb/plugin-faker');
13
- var _plugints = require('@kubb/plugin-ts');
14
-
15
- // src/OperationGenerator.tsx
17
+ var path__default = /*#__PURE__*/_interopDefault(path);
16
18
 
17
- var _components = require('@kubb/plugin-oas/components');
18
- var _react = require('@kubb/react');
19
- var _jsxruntime = require('@kubb/react/jsx-runtime');
20
- var OperationGenerator = class extends _pluginoas.OperationGenerator {
19
+ var OperationGenerator = class extends pluginOas.OperationGenerator {
21
20
  async all(operations, operationsByMethod) {
22
21
  const { oas, pluginManager, plugin, mode } = this.context;
23
- const root = _react.createRoot.call(void 0, {
22
+ const root = react.createRoot({
24
23
  logger: pluginManager.logger
25
24
  });
26
25
  const templates = {
27
- operations: _chunkBD7UJBXMcjs.Operations.templates,
28
- mock: _chunkBD7UJBXMcjs.Mock.templates,
26
+ operations: chunkBD7UJBXM_cjs.Operations.templates,
27
+ mock: chunkBD7UJBXM_cjs.Mock.templates,
29
28
  ...this.options.templates
30
29
  };
31
30
  root.render(
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, _chunkBD7UJBXMcjs.Operations.File, { templates: templates.operations }) }) })
31
+ /* @__PURE__ */ jsxRuntime.jsx(react.App, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas, { oas, operations, generator: this, children: templates?.operations && /* @__PURE__ */ jsxRuntime.jsx(chunkBD7UJBXM_cjs.Operations.File, { templates: templates.operations }) }) })
33
32
  );
34
33
  return root.files;
35
34
  }
36
35
  async operation(operation, options) {
37
36
  const { oas, pluginManager, plugin, mode } = this.context;
38
- const root = _react.createRoot.call(void 0, {
37
+ const root = react.createRoot({
39
38
  logger: pluginManager.logger
40
39
  });
41
40
  const templates = {
42
- handlers: _chunkBD7UJBXMcjs.Operations.templates,
43
- mock: _chunkBD7UJBXMcjs.Mock.templates,
41
+ handlers: chunkBD7UJBXM_cjs.Operations.templates,
42
+ mock: chunkBD7UJBXM_cjs.Mock.templates,
44
43
  ...options.templates
45
44
  };
46
- if (!_optionalChain([templates, 'optionalAccess', _2 => _2.mock])) {
45
+ if (!templates?.mock) {
47
46
  return [];
48
47
  }
49
48
  root.render(
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, _chunkBD7UJBXMcjs.Mock.File, { templates: templates.mock }) }) }) })
49
+ /* @__PURE__ */ jsxRuntime.jsx(react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas.Operation, { operation, children: /* @__PURE__ */ jsxRuntime.jsx(chunkBD7UJBXM_cjs.Mock.File, { templates: templates.mock }) }) }) })
51
50
  );
52
51
  return root.files;
53
52
  }
@@ -55,9 +54,9 @@ var OperationGenerator = class extends _pluginoas.OperationGenerator {
55
54
 
56
55
  // src/plugin.ts
57
56
  var pluginMswName = "plugin-msw";
58
- var pluginMsw = _core.createPlugin.call(void 0, (options) => {
59
- const { output = { path: "handlers" }, group, exclude = [], include, override = [], transformers = {}, templates } = options;
60
- const template = _optionalChain([group, 'optionalAccess', _3 => _3.output]) ? group.output : `${output.path}/{{tag}}Controller`;
57
+ var pluginMsw = core.createPlugin((options) => {
58
+ const { output = { path: "handlers" }, group, exclude = [], include, override = [], transformers: transformers$1 = {}, templates } = options;
59
+ const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
61
60
  return {
62
61
  name: pluginMswName,
63
62
  output: {
@@ -67,39 +66,39 @@ var pluginMsw = _core.createPlugin.call(void 0, (options) => {
67
66
  options: {
68
67
  extName: output.extName,
69
68
  templates: {
70
- operations: _chunkBD7UJBXMcjs.Operations.templates,
71
- mock: _chunkBD7UJBXMcjs.Mock.templates,
69
+ operations: chunkBD7UJBXM_cjs.Operations.templates,
70
+ mock: chunkBD7UJBXM_cjs.Mock.templates,
72
71
  ...templates
73
72
  }
74
73
  },
75
- pre: [_pluginoas.pluginOasName, _plugints.pluginTsName, _pluginfaker.pluginFakerName],
74
+ pre: [pluginOas.pluginOasName, pluginTs.pluginTsName, pluginFaker.pluginFakerName],
76
75
  resolvePath(baseName, pathMode, options2) {
77
- const root = _path2.default.resolve(this.config.root, this.config.output.path);
78
- const mode = _nullishCoalesce(pathMode, () => ( _core.FileManager.getMode(_path2.default.resolve(root, output.path))));
76
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
77
+ const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
79
78
  if (mode === "single") {
80
- return _path2.default.resolve(root, output.path);
79
+ return path__default.default.resolve(root, output.path);
81
80
  }
82
- if (_optionalChain([options2, 'optionalAccess', _4 => _4.tag]) && _optionalChain([group, 'optionalAccess', _5 => _5.type]) === "tag") {
83
- const tag = _transformers.camelCase.call(void 0, options2.tag);
84
- return _path2.default.resolve(root, _utils.renderTemplate.call(void 0, template, { tag }), baseName);
81
+ if (options2?.tag && group?.type === "tag") {
82
+ const tag = transformers.camelCase(options2.tag);
83
+ return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
85
84
  }
86
- return _path2.default.resolve(root, output.path, baseName);
85
+ return path__default.default.resolve(root, output.path, baseName);
87
86
  },
88
87
  resolveName(name, type) {
89
- const resolvedName = _transformers.camelCase.call(void 0, name, {
88
+ const resolvedName = transformers.camelCase(name, {
90
89
  suffix: type ? "handler" : void 0,
91
90
  isFile: type === "file"
92
91
  });
93
92
  if (type) {
94
- return _optionalChain([transformers, 'optionalAccess', _6 => _6.name, 'optionalCall', _7 => _7(resolvedName, type)]) || resolvedName;
93
+ return transformers$1?.name?.(resolvedName, type) || resolvedName;
95
94
  }
96
95
  return resolvedName;
97
96
  },
98
97
  async buildStart() {
99
- const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
98
+ const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
100
99
  const oas = await swaggerPlugin.context.getOas();
101
- const root = _path2.default.resolve(this.config.root, this.config.output.path);
102
- const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
100
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
101
+ const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
103
102
  const operationGenerator = new OperationGenerator(this.plugin.options, {
104
103
  oas,
105
104
  pluginManager: this.pluginManager,
@@ -128,7 +127,7 @@ var pluginMsw = _core.createPlugin.call(void 0, (options) => {
128
127
  };
129
128
  });
130
129
 
131
-
132
-
133
- exports.pluginMsw = pluginMsw; exports.pluginMswName = pluginMswName;
130
+ exports.pluginMsw = pluginMsw;
131
+ exports.pluginMswName = pluginMswName;
132
+ //# sourceMappingURL=index.cjs.map
134
133
  //# sourceMappingURL=index.cjs.map
@@ -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;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,C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QAAA;AACV,QAAA;AAClB,MAAA;AACS,MAAA;AACkC,QAAA;AAC5C,MAAA;AAEO,MAAA;AACT,IAAA;AACmB,IAAA;AACqD,MAAA;AAE9B,MAAA;AACI,MAAA;AACN,MAAA;AAEP,MAAA;AAC7B,QAAA;AACoB,QAAA;AACP,QAAA;AACsB,QAAA;AACnC,QAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACD,MAAA;AAE4C,MAAA;AAClB,MAAA;AAEQ,MAAA;AACU,QAAA;AACzC,UAAA;AACA,UAAA;AACwB,UAAA;AAClB,UAAA;AACmB,YAAA;AACzB,UAAA;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"]}
1
+ {"version":3,"sources":["../src/OperationGenerator.tsx","../src/plugin.ts"],"names":["Generator","createRoot","Operations","Mock","jsx","App","Oas","createPlugin","transformers","pluginOasName","pluginTsName","pluginFakerName","options","path","FileManager","camelCase","renderTemplate","PluginManager"],"mappings":";;;;;;;;;;;;;;;;;;AAWO,IAAM,kBAAA,GAAN,cAAiCA,4BAAmD,CAAA;AAAA,EACzF,MAAM,GAAI,CAAA,UAAA,EAAyB,kBAAyE,EAAA;AAC1G,IAAA,MAAM,EAAE,GAAK,EAAA,aAAA,EAAe,MAAQ,EAAA,IAAA,KAAS,IAAK,CAAA,OAAA,CAAA;AAElD,IAAA,MAAM,OAAOC,gBAAW,CAAA;AAAA,MACtB,QAAQ,aAAc,CAAA,MAAA;AAA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A,MAAA;AAAA,SACd,CAAA,CAAA;AAED,QAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA,CAAA;AAAA,OACnC;AAAA,KACF;AAAA,GACF,CAAA;AACF,CAAC","file":"index.cjs","sourcesContent":["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","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"]}
package/dist/index.js CHANGED
@@ -1,23 +1,16 @@
1
- import {
2
- Mock,
3
- Operations
4
- } from "./chunk-3KHLTEUD.js";
1
+ import { Operations, Mock } from './chunk-3KHLTEUD.js';
2
+ import path from 'node:path';
3
+ import { createPlugin, FileManager, PluginManager } from '@kubb/core';
4
+ import { camelCase } from '@kubb/core/transformers';
5
+ import { renderTemplate } from '@kubb/core/utils';
6
+ import { pluginOasName, OperationGenerator as OperationGenerator$1 } from '@kubb/plugin-oas';
7
+ import { pluginFakerName } from '@kubb/plugin-faker';
8
+ import { pluginTsName } from '@kubb/plugin-ts';
9
+ import { Oas } from '@kubb/plugin-oas/components';
10
+ import { createRoot, App } from '@kubb/react';
11
+ import { jsx } from '@kubb/react/jsx-runtime';
5
12
 
6
- // src/plugin.ts
7
- import path from "node:path";
8
- import { FileManager, PluginManager, createPlugin } from "@kubb/core";
9
- import { camelCase } from "@kubb/core/transformers";
10
- import { renderTemplate } from "@kubb/core/utils";
11
- import { pluginOasName } from "@kubb/plugin-oas";
12
- import { pluginFakerName } from "@kubb/plugin-faker";
13
- import { pluginTsName } from "@kubb/plugin-ts";
14
-
15
- // src/OperationGenerator.tsx
16
- import { OperationGenerator as Generator } from "@kubb/plugin-oas";
17
- import { Oas } from "@kubb/plugin-oas/components";
18
- import { App, createRoot } from "@kubb/react";
19
- import { jsx } from "@kubb/react/jsx-runtime";
20
- var OperationGenerator = class extends Generator {
13
+ var OperationGenerator = class extends OperationGenerator$1 {
21
14
  async all(operations, operationsByMethod) {
22
15
  const { oas, pluginManager, plugin, mode } = this.context;
23
16
  const root = createRoot({
@@ -127,8 +120,7 @@ var pluginMsw = createPlugin((options) => {
127
120
  }
128
121
  };
129
122
  });
130
- export {
131
- pluginMsw,
132
- pluginMswName
133
- };
123
+
124
+ export { pluginMsw, pluginMswName };
125
+ //# sourceMappingURL=index.js.map
134
126
  //# sourceMappingURL=index.js.map
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'\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,MAC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QAAQ;AAAA,QACnC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAED,YAAM,QAAQ,MAAM,mBAAmB,MAAM;AAC7C,YAAM,KAAK,QAAQ,GAAG,KAAK;AAE3B,UAAI,KAAK,OAAO,OAAO,YAAY;AACjC,cAAM,cAAc,MAAM,KAAK,YAAY,eAAe;AAAA,UACxD;AAAA,UACA;AAAA,UACA,OAAO,KAAK,YAAY;AAAA,UACxB,MAAM;AAAA,YACJ,WAAW,KAAK,OAAO;AAAA,UACzB;AAAA,UACA,QAAQ,KAAK;AAAA,QACf,CAAC;AAED,cAAM,KAAK,QAAQ,GAAG,WAAW;AAAA,MACnC;AAAA,IACF;AAAA,EACF;AACF,CAAC;","names":["options"]}
1
+ {"version":3,"sources":["../src/OperationGenerator.tsx","../src/plugin.ts"],"names":["Generator","options"],"mappings":";;;;;;;;;;;;AAWO,IAAM,kBAAA,GAAN,cAAiCA,oBAAmD,CAAA;AAAA,EACzF,MAAM,GAAI,CAAA,UAAA,EAAyB,kBAAyE,EAAA;AAC1G,IAAA,MAAM,EAAE,GAAK,EAAA,aAAA,EAAe,MAAQ,EAAA,IAAA,KAAS,IAAK,CAAA,OAAA,CAAA;AAElD,IAAA,MAAM,OAAO,UAAW,CAAA;AAAA,MACtB,QAAQ,aAAc,CAAA,MAAA;AAAA,KACvB,CAAA,CAAA;AAED,IAAA,MAAM,SAAY,GAAA;AAAA,MAChB,YAAY,UAAW,CAAA,SAAA;AAAA,MACvB,MAAM,IAAK,CAAA,SAAA;AAAA,MACX,GAAG,KAAK,OAAQ,CAAA,SAAA;AAAA,KAClB,CAAA;AAEA,IAAK,IAAA,CAAA,MAAA;AAAA,sBACH,GAAA,CAAC,OAAI,aAA8B,EAAA,MAAA,EAAgB,MACjD,QAAC,kBAAA,GAAA,CAAA,GAAA,EAAA,EAAI,KAAU,UAAwB,EAAA,SAAA,EAAW,MAC/C,QAAW,EAAA,SAAA,EAAA,UAAA,wBAAe,UAAW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B,GAAA,IAAI,kBAAmB,CAAA,IAAA,CAAK,OAAO,OAAS,EAAA;AAAA,QACrE,GAAA;AAAA,QACA,eAAe,IAAK,CAAA,aAAA;AAAA,QACpB,QAAQ,IAAK,CAAA,MAAA;AAAA,QACb,WAAA,EAAa,cAAc,OAAQ,CAAA,WAAA;AAAA,QACnC,OAAA;AAAA,QACA,OAAA;AAAA,QACA,QAAA;AAAA,QACA,IAAA;AAAA,OACD,CAAA,CAAA;AAED,MAAM,MAAA,KAAA,GAAQ,MAAM,kBAAA,CAAmB,KAAM,EAAA,CAAA;AAC7C,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,CAAA,CAAA;AAE3B,MAAI,IAAA,IAAA,CAAK,MAAO,CAAA,MAAA,CAAO,UAAY,EAAA;AACjC,QAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,UACxD,IAAA;AAAA,UACA,MAAA;AAAA,UACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,UACxB,IAAM,EAAA;AAAA,YACJ,SAAA,EAAW,KAAK,MAAO,CAAA,GAAA;AAAA,WACzB;AAAA,UACA,QAAQ,IAAK,CAAA,MAAA;AAAA,SACd,CAAA,CAAA;AAED,QAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA,CAAA;AAAA,OACnC;AAAA,KACF;AAAA,GACF,CAAA;AACF,CAAC","file":"index.js","sourcesContent":["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","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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-msw",
3
- "version": "3.0.0-alpha.10",
3
+ "version": "3.0.0-alpha.12",
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.10",
70
- "@kubb/fs": "3.0.0-alpha.10",
71
- "@kubb/oas": "3.0.0-alpha.10",
72
- "@kubb/parser-ts": "3.0.0-alpha.10",
73
- "@kubb/plugin-faker": "3.0.0-alpha.10",
74
- "@kubb/plugin-oas": "3.0.0-alpha.10",
75
- "@kubb/plugin-ts": "3.0.0-alpha.10",
76
- "@kubb/react": "3.0.0-alpha.10"
69
+ "@kubb/core": "3.0.0-alpha.12",
70
+ "@kubb/fs": "3.0.0-alpha.12",
71
+ "@kubb/oas": "3.0.0-alpha.12",
72
+ "@kubb/parser-ts": "3.0.0-alpha.12",
73
+ "@kubb/plugin-faker": "3.0.0-alpha.12",
74
+ "@kubb/plugin-oas": "3.0.0-alpha.12",
75
+ "@kubb/plugin-ts": "3.0.0-alpha.12",
76
+ "@kubb/react": "3.0.0-alpha.12"
77
77
  },
78
78
  "devDependencies": {
79
79
  "@types/react": "^18.3.5",
@@ -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.10",
85
- "@kubb/config-ts": "3.0.0-alpha.10",
86
- "@kubb/config-tsup": "3.0.0-alpha.10"
84
+ "@kubb/config-biome": "3.0.0-alpha.12",
85
+ "@kubb/config-ts": "3.0.0-alpha.12",
86
+ "@kubb/config-tsup": "3.0.0-alpha.12"
87
87
  },
88
88
  "peerDependencies": {
89
- "@kubb/react": "3.0.0-alpha.10"
89
+ "@kubb/react": "3.0.0-alpha.12"
90
90
  },
91
91
  "engines": {
92
92
  "node": ">=20"