@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.
Files changed (51) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-6M2QU6UL.js +22 -0
  3. package/dist/chunk-6M2QU6UL.js.map +1 -0
  4. package/dist/chunk-73P6BBZZ.js +125 -0
  5. package/dist/chunk-73P6BBZZ.js.map +1 -0
  6. package/dist/chunk-GODA4G5K.cjs +25 -0
  7. package/dist/chunk-GODA4G5K.cjs.map +1 -0
  8. package/dist/chunk-UZ4ZUY3N.cjs +134 -0
  9. package/dist/chunk-UZ4ZUY3N.cjs.map +1 -0
  10. package/dist/components.cjs +11 -4
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +7 -70
  13. package/dist/components.d.ts +7 -70
  14. package/dist/components.js +2 -8
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +17 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +9 -0
  19. package/dist/generators.d.ts +9 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +11 -137
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +3 -86
  25. package/dist/index.d.ts +3 -86
  26. package/dist/index.js +3 -142
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-B2IuaP_7.d.cts +60 -0
  29. package/dist/types-B2IuaP_7.d.ts +60 -0
  30. package/package.json +22 -17
  31. package/src/components/Handlers.tsx +19 -0
  32. package/src/components/Mock.tsx +9 -92
  33. package/src/components/index.ts +1 -1
  34. package/src/generators/__snapshots__/createPet.ts +9 -0
  35. package/src/generators/__snapshots__/deletePet.ts +9 -0
  36. package/src/generators/__snapshots__/getPets.ts +9 -0
  37. package/src/generators/__snapshots__/handlers.ts +3 -0
  38. package/src/generators/__snapshots__/showPetById.ts +9 -0
  39. package/src/generators/handlersGenerator.tsx +32 -0
  40. package/src/generators/index.ts +2 -0
  41. package/src/generators/mswGenerator.tsx +38 -0
  42. package/src/plugin.ts +16 -34
  43. package/src/types.ts +9 -38
  44. package/dist/chunk-S4P5XPFN.cjs +0 -105
  45. package/dist/chunk-S4P5XPFN.cjs.map +0 -1
  46. package/dist/chunk-WRIEMCYI.js +0 -105
  47. package/dist/chunk-WRIEMCYI.js.map +0 -1
  48. package/src/OperationGenerator.tsx +0 -66
  49. package/src/components/Operations.tsx +0 -96
  50. package/src/components/__snapshots__/Mock/Pets.ts +0 -7
  51. package/src/components/__snapshots__/Mock/showPetsById.ts +0 -7
@@ -0,0 +1,60 @@
1
+ import { PluginFactoryOptions, Output, ResolveNameParams } from '@kubb/core';
2
+ import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
3
+
4
+ type Options = {
5
+ /**
6
+ * @default 'mocks'
7
+ */
8
+ output?: Output;
9
+ /**
10
+ * Group the MSW mocks based on the provided name.
11
+ */
12
+ group?: {
13
+ /**
14
+ * Tag will group based on the operation tag inside the Swagger file
15
+ */
16
+ type: 'tag';
17
+ /**
18
+ * Relative path to save the grouped MSW mocks.
19
+ *
20
+ * `{{tag}}` will be replaced by the current tagName.
21
+ * @example `${output}/{{tag}}Controller` => `mocks/PetController`
22
+ * @default `${output}/{{tag}}Controller`
23
+ */
24
+ output?: string;
25
+ /**
26
+ * Name to be used for the `export * as {{exportAs}} from './`
27
+ * @default `"{{tag}}Handlers"`
28
+ */
29
+ exportAs?: string;
30
+ };
31
+ /**
32
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
33
+ */
34
+ exclude?: Array<Exclude>;
35
+ /**
36
+ * Array containing include parameters to include tags/operations/methods/paths.
37
+ */
38
+ include?: Array<Include>;
39
+ /**
40
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
41
+ */
42
+ override?: Array<Override<ResolvedOptions>>;
43
+ transformers?: {
44
+ /**
45
+ * Customize the names based on the type that is provided by the plugin.
46
+ */
47
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
48
+ };
49
+ /**
50
+ * Create `handlers.ts` file with all handlers for all mocks.
51
+ * @default `false`
52
+ */
53
+ handlers?: boolean;
54
+ };
55
+ type ResolvedOptions = {
56
+ output: Output;
57
+ };
58
+ type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
59
+
60
+ export type { Options as O, PluginMsw as P };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-msw",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.0.0-alpha.21",
4
4
  "description": "Generator swagger",
5
5
  "keywords": [
6
6
  "typescript",
@@ -40,6 +40,11 @@
40
40
  "require": "./dist/components.cjs",
41
41
  "default": "./dist/components.cjs"
42
42
  },
43
+ "./generators": {
44
+ "import": "./dist/generators.js",
45
+ "require": "./dist/generators.cjs",
46
+ "default": "./dist/generators.cjs"
47
+ },
43
48
  "./package.json": "./package.json",
44
49
  "./*": "./*"
45
50
  },
@@ -56,6 +61,9 @@
56
61
  ],
57
62
  "components": [
58
63
  "./dist/components.d.ts"
64
+ ],
65
+ "generators": [
66
+ "./dist/generators.d.ts"
59
67
  ]
60
68
  }
61
69
  },
@@ -66,27 +74,24 @@
66
74
  "!/**/__tests__/**"
67
75
  ],
68
76
  "dependencies": {
69
- "@kubb/core": "3.0.0-alpha.2",
70
- "@kubb/fs": "3.0.0-alpha.2",
71
- "@kubb/oas": "3.0.0-alpha.2",
72
- "@kubb/parser-ts": "3.0.0-alpha.2",
73
- "@kubb/plugin-faker": "3.0.0-alpha.2",
74
- "@kubb/plugin-oas": "3.0.0-alpha.2",
75
- "@kubb/plugin-ts": "3.0.0-alpha.2",
76
- "@kubb/react": "3.0.0-alpha.2"
77
+ "@kubb/core": "3.0.0-alpha.21",
78
+ "@kubb/fs": "3.0.0-alpha.21",
79
+ "@kubb/oas": "3.0.0-alpha.21",
80
+ "@kubb/plugin-faker": "3.0.0-alpha.21",
81
+ "@kubb/plugin-oas": "3.0.0-alpha.21",
82
+ "@kubb/plugin-ts": "3.0.0-alpha.21",
83
+ "@kubb/react": "3.0.0-alpha.21"
77
84
  },
78
85
  "devDependencies": {
79
- "@types/react": "^18.3.4",
80
- "@types/react-dom": "^18.3.0",
86
+ "@types/react": "^18.3.8",
81
87
  "react": "^18.3.1",
82
- "tsup": "^8.2.4",
83
- "typescript": "^5.5.4",
84
- "@kubb/config-biome": "3.0.0-alpha.2",
85
- "@kubb/config-ts": "3.0.0-alpha.2",
86
- "@kubb/config-tsup": "3.0.0-alpha.2"
88
+ "tsup": "^8.3.0",
89
+ "typescript": "^5.6.2",
90
+ "@kubb/config-ts": "3.0.0-alpha.21",
91
+ "@kubb/config-tsup": "3.0.0-alpha.21"
87
92
  },
88
93
  "peerDependencies": {
89
- "@kubb/react": "3.0.0-alpha.2"
94
+ "@kubb/react": "3.0.0-alpha.21"
90
95
  },
91
96
  "engines": {
92
97
  "node": ">=20"
@@ -0,0 +1,19 @@
1
+ import { File } from '@kubb/react'
2
+ import type { ReactNode } from 'react'
3
+
4
+ type HandlersProps = {
5
+ /**
6
+ * Name of the function
7
+ */
8
+ name: string
9
+ // custom
10
+ handlers: string[]
11
+ }
12
+
13
+ export function Handlers({ name, handlers }: HandlersProps): ReactNode {
14
+ return (
15
+ <File.Source name={name} isIndexable isExportable>
16
+ {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, '')} as const`}
17
+ </File.Source>
18
+ )
19
+ }
@@ -1,113 +1,30 @@
1
- import { PackageManager } from '@kubb/core'
2
- import { URLPath } from '@kubb/core/utils'
3
- import { Parser, File, useApp } from '@kubb/react'
4
- import { pluginFakerName } from '@kubb/plugin-faker'
5
- import { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
1
+ import { File } from '@kubb/react'
6
2
 
7
3
  import type { HttpMethod } from '@kubb/oas'
8
4
  import type { ReactNode } from 'react'
9
- import type { FileMeta, PluginMsw } from '../types.ts'
10
5
 
11
- type TemplateProps = {
6
+ type Props = {
12
7
  /**
13
8
  * Name of the function
14
9
  */
15
10
  name: string
16
- /**
17
- * Method of the current operation, see useOperation.
18
- */
11
+ fakerName: string
12
+ url: string
19
13
  method: HttpMethod
20
- /**
21
- * Path of the mock
22
- */
23
- path: URLPath
24
- /**
25
- * Name of the import for the mock(this is a function).
26
- * @example createPet
27
- */
28
- responseName: string
29
14
  }
30
15
 
31
- function Template({ name, method, path, responseName }: TemplateProps): ReactNode {
16
+ export function Mock({ name, fakerName, url, method }: Props): ReactNode {
32
17
  return (
33
- <>
18
+ <File.Source name={name} isIndexable isExportable>
34
19
  {`
35
- export const ${name} = http.${method}('*${path.toURLPath()}', function handler(info) {
36
- return new Response(JSON.stringify(${responseName}()), {
20
+ export const ${name} = http.${method}('*${url}', function handler(info) {
21
+ return new Response(JSON.stringify(${fakerName}()), {
37
22
  headers: {
38
23
  'Content-Type': 'application/json',
39
24
  },
40
25
  })
41
26
  })
42
27
  `}
43
- </>
28
+ </File.Source>
44
29
  )
45
30
  }
46
-
47
- const defaultTemplates = { default: Template } as const
48
-
49
- type Props = {
50
- /**
51
- * This will make it possible to override the default behaviour.
52
- */
53
- Template?: React.ComponentType<React.ComponentProps<typeof Template>>
54
- }
55
-
56
- export function Mock({ Template = defaultTemplates.default }: Props): ReactNode {
57
- const { pluginManager } = useApp<PluginMsw>()
58
- const { getSchemas, getName } = useOperationManager()
59
- const operation = useOperation()
60
-
61
- const schemas = getSchemas(operation)
62
- const name = getName(operation, { type: 'function' })
63
- const responseName = pluginManager.resolveName({
64
- pluginKey: [pluginFakerName],
65
- name: schemas.response.name,
66
- type: 'type',
67
- })
68
-
69
- return <Template name={name} responseName={responseName} method={operation.method} path={new URLPath(operation.path)} />
70
- }
71
-
72
- type FileProps = {
73
- /**
74
- * This will make it possible to override the default behaviour.
75
- */
76
- templates?: typeof defaultTemplates
77
- }
78
-
79
- Mock.File = function ({ templates = defaultTemplates }: FileProps): ReactNode {
80
- const {
81
- pluginManager,
82
- plugin: {
83
- options: { extName },
84
- },
85
- } = useApp<PluginMsw>()
86
- const { getSchemas, getFile } = useOperationManager()
87
- const operation = useOperation()
88
-
89
- const schemas = getSchemas(operation)
90
- const file = getFile(operation)
91
- const fileFaker = getFile(operation, { pluginKey: [pluginFakerName] })
92
- const responseName = pluginManager.resolveName({
93
- pluginKey: [pluginFakerName],
94
- name: schemas.response.name,
95
- type: 'function',
96
- })
97
-
98
- const Template = templates.default
99
-
100
- return (
101
- <Parser language="typescript">
102
- <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
103
- <File.Import name={['http']} path={'msw'} />
104
- {fileFaker && responseName && <File.Import extName={extName} name={[responseName]} root={file.path} path={fileFaker.path} />}
105
- <File.Source>
106
- <Mock Template={Template} />
107
- </File.Source>
108
- </File>
109
- </Parser>
110
- )
111
- }
112
-
113
- Mock.templates = defaultTemplates
@@ -1,2 +1,2 @@
1
1
  export { Mock } from './Mock.tsx'
2
- export { Operations } from './Operations.tsx'
2
+ export { Handlers } from './Handlers.tsx'
@@ -0,0 +1,9 @@
1
+ import { http } from "msw";
2
+
3
+ export const createPets = http.post("*/pets", function handler(info) {
4
+ return new Response(JSON.stringify(createPetsMutationResponse()), {
5
+ headers: {
6
+ "Content-Type": "application/json",
7
+ },
8
+ });
9
+ });
@@ -0,0 +1,9 @@
1
+ import { http } from "msw";
2
+
3
+ export const deletePetsPetid = http.delete("*/pets/:petId", function handler(info) {
4
+ return new Response(JSON.stringify(deletePetsPetidMutationResponse()), {
5
+ headers: {
6
+ "Content-Type": "application/json",
7
+ },
8
+ });
9
+ });
@@ -0,0 +1,9 @@
1
+ import { http } from "msw";
2
+
3
+ export const listPets = http.get("*/pets", function handler(info) {
4
+ return new Response(JSON.stringify(listPetsQueryResponse()), {
5
+ headers: {
6
+ "Content-Type": "application/json",
7
+ },
8
+ });
9
+ });
@@ -0,0 +1,3 @@
1
+ import { listPets, createPets, showPetById } from "./findByTags.ts";
2
+
3
+ export const handlers = [listPets, createPets, showPetById] as const;
@@ -0,0 +1,9 @@
1
+ import { http } from "msw";
2
+
3
+ export const showPetById = http.get("*/pets/:petId", function handler(info) {
4
+ return new Response(JSON.stringify(showPetByIdQueryResponse()), {
5
+ headers: {
6
+ "Content-Type": "application/json",
7
+ },
8
+ });
9
+ });
@@ -0,0 +1,32 @@
1
+ import { createReactGenerator } from '@kubb/plugin-oas'
2
+ import { useOperationManager } from '@kubb/plugin-oas/hooks'
3
+ import { File, useApp } from '@kubb/react'
4
+ import { Handlers } from '../components/Handlers.tsx'
5
+ import { pluginMswName } from '../plugin.ts'
6
+ import type { PluginMsw } from '../types'
7
+
8
+ export const handlersGenerator = createReactGenerator<PluginMsw>({
9
+ name: 'plugin-msw',
10
+ Operations({ operations }) {
11
+ const { pluginManager, plugin } = useApp<PluginMsw>()
12
+ const { getName, getFile } = useOperationManager()
13
+
14
+ const file = pluginManager.getFile({ name: 'handlers', extName: '.ts', pluginKey: [pluginMswName] })
15
+
16
+ const imports = operations.map((operation) => {
17
+ const operationFile = getFile(operation, { pluginKey: [pluginMswName] })
18
+ const operationName = getName(operation, { pluginKey: [pluginMswName], type: 'function' })
19
+
20
+ return <File.Import extName={plugin.options.output?.extName} key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />
21
+ })
22
+
23
+ const handlers = operations.map((operation) => getName(operation, { type: 'function', pluginKey: [pluginMswName] }))
24
+
25
+ return (
26
+ <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>
27
+ {imports}
28
+ <Handlers name={'handlers'} handlers={handlers} />
29
+ </File>
30
+ )
31
+ },
32
+ })
@@ -0,0 +1,2 @@
1
+ export { mswGenerator } from './mswGenerator.tsx'
2
+ export { handlersGenerator } from './handlersGenerator.tsx'
@@ -0,0 +1,38 @@
1
+ import { URLPath } from '@kubb/core/utils'
2
+ import { pluginFakerName } from '@kubb/plugin-faker'
3
+ import { createReactGenerator } from '@kubb/plugin-oas'
4
+ import { useOperationManager } from '@kubb/plugin-oas/hooks'
5
+ import { File, useApp } from '@kubb/react'
6
+ import { Mock } from '../components'
7
+ import type { PluginMsw } from '../types'
8
+
9
+ export const mswGenerator = createReactGenerator<PluginMsw>({
10
+ name: 'msw',
11
+ Operation({ operation }) {
12
+ const {
13
+ plugin: {
14
+ options: { output },
15
+ },
16
+ } = useApp<PluginMsw>()
17
+ const { getSchemaName, getName, getFile } = useOperationManager()
18
+
19
+ const mock = {
20
+ name: getName(operation, { type: 'function' }),
21
+ file: getFile(operation),
22
+ }
23
+
24
+ const faker = {
25
+ name: getSchemaName(operation, 'response', { pluginKey: [pluginFakerName], type: 'function' }),
26
+ file: getFile(operation, { pluginKey: [pluginFakerName] }),
27
+ }
28
+
29
+ return (
30
+ <File baseName={mock.file.baseName} path={mock.file.path} meta={mock.file.meta} banner={output?.banner} footer={output?.footer}>
31
+ <File.Import name={['http']} path={'msw'} />
32
+ {faker.file && faker.name && <File.Import extName={output?.extName} name={[faker.name]} root={mock.file.path} path={faker.file.path} />}
33
+
34
+ <Mock name={mock.name} fakerName={faker.name} method={operation.method} url={new URLPath(operation.path).toURLPath()} />
35
+ </File>
36
+ )
37
+ },
38
+ })
package/src/plugin.ts CHANGED
@@ -3,32 +3,28 @@ import path from 'node:path'
3
3
  import { FileManager, PluginManager, createPlugin } from '@kubb/core'
4
4
  import { camelCase } from '@kubb/core/transformers'
5
5
  import { renderTemplate } from '@kubb/core/utils'
6
- import { pluginOasName } from '@kubb/plugin-oas'
7
- import { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'
6
+ import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
7
+
8
8
  import { pluginFakerName } from '@kubb/plugin-faker'
9
9
  import { pluginTsName } from '@kubb/plugin-ts'
10
10
 
11
- import { OperationGenerator } from './OperationGenerator.tsx'
12
- import { Mock, Operations } from './components/index.ts'
13
-
14
11
  import type { Plugin } from '@kubb/core'
15
12
  import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
13
+ import { handlersGenerator, mswGenerator } from './generators'
16
14
  import type { PluginMsw } from './types.ts'
17
15
 
18
16
  export const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']
19
17
 
20
18
  export const pluginMsw = createPlugin<PluginMsw>((options) => {
21
- const { output = { path: 'handlers' }, group, exclude = [], include, override = [], transformers = {}, templates } = options
19
+ const { output = { path: 'handlers' }, group, exclude = [], include, override = [], transformers = {}, handlers = false } = options
22
20
  const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`
23
21
 
24
22
  return {
25
23
  name: pluginMswName,
26
24
  options: {
27
- extName: output.extName,
28
- templates: {
29
- operations: Operations.templates,
30
- mock: Mock.templates,
31
- ...templates,
25
+ output: {
26
+ exportType: 'barrelNamed',
27
+ ...output,
32
28
  },
33
29
  },
34
30
  pre: [pluginOasName, pluginTsName, pluginFakerName],
@@ -81,36 +77,22 @@ export const pluginMsw = createPlugin<PluginMsw>((options) => {
81
77
  mode,
82
78
  })
83
79
 
84
- const files = await operationGenerator.build()
80
+ const files = await operationGenerator.build(...[mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean))
85
81
  await this.addFile(...files)
86
- },
87
- async buildEnd() {
88
- if (this.config.output.write === false) {
89
- return
90
- }
91
-
92
- const root = path.resolve(this.config.root, this.config.output.path)
93
82
 
94
- if (group?.type === 'tag') {
95
- const rootFiles = await getGroupedByTagFiles({
96
- logger: this.logger,
97
- files: this.fileManager.files,
98
- plugin: this.plugin,
99
- template,
100
- exportAs: group.exportAs || '{{tag}}Handlers',
83
+ if (this.config.output.exportType) {
84
+ const barrelFiles = await this.fileManager.getBarrelFiles({
101
85
  root,
102
86
  output,
87
+ files: this.fileManager.files,
88
+ meta: {
89
+ pluginKey: this.plugin.key,
90
+ },
91
+ logger: this.logger,
103
92
  })
104
93
 
105
- await this.addFile(...rootFiles)
94
+ await this.addFile(...barrelFiles)
106
95
  }
107
-
108
- await this.fileManager.addIndexes({
109
- root,
110
- output,
111
- meta: { pluginKey: this.plugin.key },
112
- logger: this.logger,
113
- })
114
96
  },
115
97
  }
116
98
  })
package/src/types.ts CHANGED
@@ -1,36 +1,12 @@
1
- import type { Plugin, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
2
- import type * as KubbFile from '@kubb/fs/types'
1
+ import type { Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
3
2
 
4
3
  import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
5
- import type { Mock, Operations } from './components/index.ts'
6
-
7
- type Templates = {
8
- operations?: typeof Operations.templates | false
9
- mock?: typeof Mock.templates | false
10
- }
11
4
 
12
5
  export type Options = {
13
- output?: {
14
- /**
15
- * Relative path to save the MSW mocks.
16
- * When output is a file it will save all models inside that file else it will create a file per schema item.
17
- * @default 'mocks'
18
- */
19
- path: string
20
- /**
21
- * Name to be used for the `export * as {{exportAs}} from './'`
22
- */
23
- exportAs?: string
24
- /**
25
- * Add an extension to the generated imports and exports, default it will not use an extension
26
- */
27
- extName?: KubbFile.Extname
28
- /**
29
- * Define what needs to exported, here you can also disable the export of barrel files
30
- * @default `'barrel'`
31
- */
32
- exportType?: 'barrel' | 'barrelNamed' | false
33
- }
6
+ /**
7
+ * @default 'mocks'
8
+ */
9
+ output?: Output
34
10
  /**
35
11
  * Group the MSW mocks based on the provided name.
36
12
  */
@@ -72,18 +48,13 @@ export type Options = {
72
48
  name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
73
49
  }
74
50
  /**
75
- * Make it possible to override one of the templates
51
+ * Create `handlers.ts` file with all handlers for all mocks.
52
+ * @default `false`
76
53
  */
77
- templates?: Partial<Templates>
54
+ handlers?: boolean
78
55
  }
79
56
  type ResolvedOptions = {
80
- extName: KubbFile.Extname | undefined
81
- templates: NonNullable<Templates>
82
- }
83
-
84
- export type FileMeta = {
85
- pluginKey?: Plugin['key']
86
- tag?: string
57
+ output: Output
87
58
  }
88
59
 
89
60
  export type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>
@@ -1,105 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/components/Mock.tsx
2
- require('@kubb/core');
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
- function Template({ name, method, path, responseName }) {
9
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.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 } = _react.useApp.call(void 0, );
22
- const { getSchemas, getName } = _hooks.useOperationManager.call(void 0, );
23
- const operation = _hooks.useOperation.call(void 0, );
24
- const schemas = getSchemas(operation);
25
- const name = getName(operation, { type: "function" });
26
- const responseName = pluginManager.resolveName({
27
- pluginKey: [_pluginfaker.pluginFakerName],
28
- name: schemas.response.name,
29
- type: "type"
30
- });
31
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Template3, { name, responseName, method: operation.method, path: new (0, _utils.URLPath)(operation.path) });
32
- }
33
- Mock.File = function({ templates = defaultTemplates }) {
34
- const {
35
- pluginManager,
36
- plugin: {
37
- options: { extName }
38
- }
39
- } = _react.useApp.call(void 0, );
40
- const { getSchemas, getFile } = _hooks.useOperationManager.call(void 0, );
41
- const operation = _hooks.useOperation.call(void 0, );
42
- const schemas = getSchemas(operation);
43
- const file = getFile(operation);
44
- const fileFaker = getFile(operation, { pluginKey: [_pluginfaker.pluginFakerName] });
45
- const responseName = pluginManager.resolveName({
46
- pluginKey: [_pluginfaker.pluginFakerName],
47
- name: schemas.response.name,
48
- type: "function"
49
- });
50
- const Template3 = templates.default;
51
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Parser, { language: "typescript", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
52
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["http"], path: "msw" }),
53
- fileFaker && responseName && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { extName, name: [responseName], root: file.path, path: fileFaker.path }),
54
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Mock, { Template: Template3 }) })
55
- ] }) });
56
- };
57
- Mock.templates = defaultTemplates;
58
-
59
- // src/components/Operations.tsx
60
-
61
-
62
-
63
- function Template2({ name, handlers }) {
64
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: `export const ${name} = ${JSON.stringify(handlers).replaceAll(`"`, "")} as const` });
65
- }
66
- function RootTemplate({ children }) {
67
- const {
68
- pluginManager,
69
- plugin: { key: pluginKey }
70
- } = _react.useApp.call(void 0, );
71
- const { getName, getFile } = _hooks.useOperationManager.call(void 0, );
72
- const file = pluginManager.getFile({ name: "handlers", extName: ".ts", pluginKey });
73
- const operations = _hooks.useOperations.call(void 0, );
74
- const imports = operations.map((operation) => {
75
- const operationFile = getFile(operation, { pluginKey });
76
- const operationName = getName(operation, { pluginKey, type: "function" });
77
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: [operationName], root: file.path, path: operationFile.path }, operationFile.path);
78
- }).filter(Boolean);
79
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Parser, { language: "typescript", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
80
- imports,
81
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.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
- } = _react.useApp.call(void 0, );
89
- const operations = _hooks.useOperations.call(void 0, );
90
- const { getName } = _hooks.useOperationManager.call(void 0, );
91
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 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__ */ _jsxruntime.jsx.call(void 0, RootTemplate2, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Operations, { Template: Template3 }) });
98
- };
99
- Operations.templates = defaultTemplates2;
100
-
101
-
102
-
103
-
104
- exports.Mock = Mock; exports.Operations = Operations;
105
- //# sourceMappingURL=chunk-S4P5XPFN.cjs.map