@kubb/plugin-msw 5.0.0-alpha.9 → 5.0.0-beta.3

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 (43) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +1 -3
  3. package/dist/components-CLQ77DVn.cjs +584 -0
  4. package/dist/components-CLQ77DVn.cjs.map +1 -0
  5. package/dist/components-vO0FIb2i.js +519 -0
  6. package/dist/components-vO0FIb2i.js.map +1 -0
  7. package/dist/components.cjs +1 -1
  8. package/dist/components.d.ts +17 -21
  9. package/dist/components.js +1 -1
  10. package/dist/generators-BPJCs1x1.js +176 -0
  11. package/dist/generators-BPJCs1x1.js.map +1 -0
  12. package/dist/generators-CrmMwWE4.cjs +186 -0
  13. package/dist/generators-CrmMwWE4.cjs.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +4 -500
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +54 -65
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +51 -65
  21. package/dist/index.js.map +1 -1
  22. package/dist/types-Dxu0KMQ4.d.ts +89 -0
  23. package/package.json +59 -57
  24. package/src/components/Handlers.tsx +3 -3
  25. package/src/components/Mock.tsx +36 -28
  26. package/src/components/MockWithFaker.tsx +36 -24
  27. package/src/components/Response.tsx +23 -17
  28. package/src/generators/handlersGenerator.tsx +18 -18
  29. package/src/generators/mswGenerator.tsx +49 -60
  30. package/src/index.ts +1 -1
  31. package/src/plugin.ts +48 -85
  32. package/src/resolvers/resolverMsw.ts +19 -0
  33. package/src/types.ts +45 -22
  34. package/src/utils.ts +109 -0
  35. package/dist/components-8XBwMbFa.cjs +0 -343
  36. package/dist/components-8XBwMbFa.cjs.map +0 -1
  37. package/dist/components-DgtTZkWX.js +0 -277
  38. package/dist/components-DgtTZkWX.js.map +0 -1
  39. package/dist/generators-CY1SNd5X.cjs +0 -171
  40. package/dist/generators-CY1SNd5X.cjs.map +0 -1
  41. package/dist/generators-CvyZTxOm.js +0 -161
  42. package/dist/generators-CvyZTxOm.js.map +0 -1
  43. package/dist/types-MdHRNpgi.d.ts +0 -68
@@ -1,161 +0,0 @@
1
- import "./chunk--u3MIqq1.js";
2
- import { i as Handlers, n as MockWithFaker, r as Mock, t as Response } from "./components-DgtTZkWX.js";
3
- import { pluginFakerName } from "@kubb/plugin-faker";
4
- import { pluginTsName } from "@kubb/plugin-ts";
5
- import { usePluginDriver } from "@kubb/core/hooks";
6
- import { createReactGenerator } from "@kubb/plugin-oas/generators";
7
- import { useOas, useOperationManager } from "@kubb/plugin-oas/hooks";
8
- import { getBanner, getFooter } from "@kubb/plugin-oas/utils";
9
- import { File } from "@kubb/react-fabric";
10
- import { jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
11
- //#region src/generators/handlersGenerator.tsx
12
- const handlersGenerator = createReactGenerator({
13
- name: "plugin-msw",
14
- Operations({ operations, generator, plugin }) {
15
- const driver = usePluginDriver();
16
- const oas = useOas();
17
- const { getName, getFile } = useOperationManager(generator);
18
- const file = driver.getFile({
19
- name: "handlers",
20
- extname: ".ts",
21
- pluginName: plugin.name
22
- });
23
- const imports = operations.map((operation) => {
24
- const operationFile = getFile(operation, { pluginName: plugin.name });
25
- const operationName = getName(operation, {
26
- pluginName: plugin.name,
27
- type: "function"
28
- });
29
- return /* @__PURE__ */ jsx(File.Import, {
30
- name: [operationName],
31
- root: file.path,
32
- path: operationFile.path
33
- }, operationFile.path);
34
- });
35
- const handlers = operations.map((operation) => `${getName(operation, {
36
- type: "function",
37
- pluginName: plugin.name
38
- })}()`);
39
- return /* @__PURE__ */ jsxs(File, {
40
- baseName: file.baseName,
41
- path: file.path,
42
- meta: file.meta,
43
- banner: getBanner({
44
- oas,
45
- output: plugin.options.output,
46
- config: driver.config
47
- }),
48
- footer: getFooter({
49
- oas,
50
- output: plugin.options.output
51
- }),
52
- children: [imports, /* @__PURE__ */ jsx(Handlers, {
53
- name: "handlers",
54
- handlers
55
- })]
56
- });
57
- }
58
- });
59
- //#endregion
60
- //#region src/generators/mswGenerator.tsx
61
- const mswGenerator = createReactGenerator({
62
- name: "msw",
63
- Operation({ operation, generator, plugin }) {
64
- const { options: { output, parser, baseURL } } = plugin;
65
- const driver = usePluginDriver();
66
- const oas = useOas();
67
- const { getSchemas, getName, getFile } = useOperationManager(generator);
68
- const mock = {
69
- name: getName(operation, { type: "function" }),
70
- file: getFile(operation)
71
- };
72
- const faker = {
73
- file: getFile(operation, { pluginName: pluginFakerName }),
74
- schemas: getSchemas(operation, {
75
- pluginName: pluginFakerName,
76
- type: "function"
77
- })
78
- };
79
- const type = {
80
- file: getFile(operation, { pluginName: pluginTsName }),
81
- schemas: getSchemas(operation, {
82
- pluginName: pluginTsName,
83
- type: "type"
84
- })
85
- };
86
- const responseStatusCodes = operation.getResponseStatusCodes();
87
- const types = [];
88
- for (const code of responseStatusCodes) {
89
- if (code === "default") {
90
- types.push(["default", type.schemas.response.name]);
91
- continue;
92
- }
93
- if (code.startsWith("2")) {
94
- types.push([Number(code), type.schemas.response.name]);
95
- continue;
96
- }
97
- const codeType = type.schemas.errors?.find((err) => err.statusCode === Number(code));
98
- if (codeType) types.push([Number(code), codeType.name]);
99
- }
100
- return /* @__PURE__ */ jsxs(File, {
101
- baseName: mock.file.baseName,
102
- path: mock.file.path,
103
- meta: mock.file.meta,
104
- banner: getBanner({
105
- oas,
106
- output,
107
- config: driver.config
108
- }),
109
- footer: getFooter({
110
- oas,
111
- output
112
- }),
113
- children: [
114
- /* @__PURE__ */ jsx(File.Import, {
115
- name: ["http"],
116
- path: "msw"
117
- }),
118
- /* @__PURE__ */ jsx(File.Import, {
119
- name: ["ResponseResolver"],
120
- isTypeOnly: true,
121
- path: "msw"
122
- }),
123
- /* @__PURE__ */ jsx(File.Import, {
124
- name: Array.from(new Set([type.schemas.response.name, ...types.map((t) => t[1])])),
125
- path: type.file.path,
126
- root: mock.file.path,
127
- isTypeOnly: true
128
- }),
129
- parser === "faker" && faker.file && faker.schemas.response && /* @__PURE__ */ jsx(File.Import, {
130
- name: [faker.schemas.response.name],
131
- root: mock.file.path,
132
- path: faker.file.path
133
- }),
134
- types.filter(([code]) => code !== "default").map(([code, typeName]) => /* @__PURE__ */ jsx(Response, {
135
- typeName,
136
- operation,
137
- name: mock.name,
138
- statusCode: code
139
- })),
140
- parser === "faker" && /* @__PURE__ */ jsx(MockWithFaker, {
141
- name: mock.name,
142
- typeName: type.schemas.response.name,
143
- fakerName: faker.schemas.response.name,
144
- operation,
145
- baseURL
146
- }),
147
- parser === "data" && /* @__PURE__ */ jsx(Mock, {
148
- name: mock.name,
149
- typeName: type.schemas.response.name,
150
- fakerName: faker.schemas.response.name,
151
- operation,
152
- baseURL
153
- })
154
- ]
155
- });
156
- }
157
- });
158
- //#endregion
159
- export { handlersGenerator as n, mswGenerator as t };
160
-
161
- //# sourceMappingURL=generators-CvyZTxOm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generators-CvyZTxOm.js","names":[],"sources":["../src/generators/handlersGenerator.tsx","../src/generators/mswGenerator.tsx"],"sourcesContent":["import { usePluginDriver } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { Handlers } from '../components/Handlers.tsx'\nimport type { PluginMsw } from '../types'\n\nexport const handlersGenerator = createReactGenerator<PluginMsw>({\n name: 'plugin-msw',\n Operations({ operations, generator, plugin }) {\n const driver = usePluginDriver()\n\n const oas = useOas()\n const { getName, getFile } = useOperationManager(generator)\n\n const file = driver.getFile({ name: 'handlers', extname: '.ts', pluginName: plugin.name })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginName: plugin.name })\n const operationName = getName(operation, { pluginName: plugin.name, type: 'function' })\n\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = operations.map((operation) => `${getName(operation, { type: 'function', pluginName: plugin.name })}()`)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: driver.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n {imports}\n <Handlers name={'handlers'} handlers={handlers} />\n </File>\n )\n },\n})\n","import { usePluginDriver } from '@kubb/core/hooks'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport { Mock, MockWithFaker, Response } from '../components'\nimport type { PluginMsw } from '../types'\n\nexport const mswGenerator = createReactGenerator<PluginMsw>({\n name: 'msw',\n Operation({ operation, generator, plugin }) {\n const {\n options: { output, parser, baseURL },\n } = plugin\n const driver = usePluginDriver()\n\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager(generator)\n\n const mock = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const faker = {\n file: getFile(operation, { pluginName: pluginFakerName }),\n schemas: getSchemas(operation, { pluginName: pluginFakerName, type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginName: pluginTsName }),\n schemas: getSchemas(operation, { pluginName: pluginTsName, type: 'type' }),\n }\n\n const responseStatusCodes = operation.getResponseStatusCodes()\n\n const types: [statusCode: number | 'default', typeName: string][] = []\n\n for (const code of responseStatusCodes) {\n if (code === 'default') {\n types.push(['default', type.schemas.response.name])\n continue\n }\n\n if (code.startsWith('2')) {\n types.push([Number(code), type.schemas.response.name])\n continue\n }\n\n const codeType = type.schemas.errors?.find((err) => err.statusCode === Number(code))\n if (codeType) types.push([Number(code), codeType.name])\n }\n\n return (\n <File\n baseName={mock.file.baseName}\n path={mock.file.path}\n meta={mock.file.meta}\n banner={getBanner({ oas, output, config: driver.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['http']} path=\"msw\" />\n <File.Import name={['ResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import\n name={Array.from(new Set([type.schemas.response.name, ...types.map((t) => t[1])]))}\n path={type.file.path}\n root={mock.file.path}\n isTypeOnly\n />\n {parser === 'faker' && faker.file && faker.schemas.response && (\n <File.Import name={[faker.schemas.response.name]} root={mock.file.path} path={faker.file.path} />\n )}\n\n {types\n .filter(([code]) => code !== 'default')\n .map(([code, typeName]) => (\n <Response typeName={typeName} operation={operation} name={mock.name} statusCode={code as number} />\n ))}\n {parser === 'faker' && (\n <MockWithFaker\n name={mock.name}\n typeName={type.schemas.response.name}\n fakerName={faker.schemas.response.name}\n operation={operation}\n baseURL={baseURL}\n />\n )}\n {parser === 'data' && (\n <Mock name={mock.name} typeName={type.schemas.response.name} fakerName={faker.schemas.response.name} operation={operation} baseURL={baseURL} />\n )}\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;AAQA,MAAa,oBAAoB,qBAAgC;CAC/D,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,SAAS,iBAAiB;EAEhC,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,SAAS,YAAY,oBAAoB,UAAU;EAE3D,MAAM,OAAO,OAAO,QAAQ;GAAE,MAAM;GAAY,SAAS;GAAO,YAAY,OAAO;GAAM,CAAC;EAE1F,MAAM,UAAU,WAAW,KAAK,cAAc;GAC5C,MAAM,gBAAgB,QAAQ,WAAW,EAAE,YAAY,OAAO,MAAM,CAAC;GACrE,MAAM,gBAAgB,QAAQ,WAAW;IAAE,YAAY,OAAO;IAAM,MAAM;IAAY,CAAC;AAEvF,UAAO,oBAAC,KAAK,QAAN;IAAsC,MAAM,CAAC,cAAc;IAAE,MAAM,KAAK;IAAM,MAAM,cAAc;IAAQ,EAAxF,cAAc,KAA0E;I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,QAAQ,SAAS;KAChC,WAAW,MAAM,QAAQ,SAAS;KACvB;KACF;KACT,CAAA;IAEH,WAAW,UACV,oBAAC,MAAD;KAAM,MAAM,KAAK;KAAM,UAAU,KAAK,QAAQ,SAAS;KAAM,WAAW,MAAM,QAAQ,SAAS;KAAiB;KAAoB;KAAW,CAAA;IAE5I;;;CAGZ,CAAC"}
@@ -1,68 +0,0 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { Group, Output, PluginFactoryOptions, ResolveNameParams } from "@kubb/core";
3
- import { Exclude, Include, Override, ResolvePathOptions } from "@kubb/plugin-oas";
4
- import { Generator as Generator$1 } from "@kubb/plugin-oas/generators";
5
- import { Oas, contentType } from "@kubb/oas";
6
-
7
- //#region src/types.d.ts
8
- type Options = {
9
- /**
10
- * Specify the export location for the files and define the behavior of the output
11
- * @default { path: 'mocks', barrelType: 'named' }
12
- */
13
- output?: Output<Oas>;
14
- /**
15
- * Define which contentType should be used.
16
- * By default, the first JSON valid mediaType is used
17
- */
18
- contentType?: contentType;
19
- baseURL?: string;
20
- /**
21
- * Group the MSW mocks based on the provided name.
22
- */
23
- group?: Group;
24
- /**
25
- * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
26
- */
27
- exclude?: Array<Exclude>;
28
- /**
29
- * Array containing include parameters to include tags/operations/methods/paths.
30
- */
31
- include?: Array<Include>;
32
- /**
33
- * Array containing override parameters to override `options` based on tags/operations/methods/paths.
34
- */
35
- override?: Array<Override<ResolvedOptions>>;
36
- transformers?: {
37
- /**
38
- * Customize the names based on the type that is provided by the plugin.
39
- */
40
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
41
- };
42
- /**
43
- * Create `handlers.ts` file with all handlers grouped by methods.
44
- * @default false
45
- */
46
- handlers?: boolean;
47
- /**
48
- * Which parser should be used before returning the data to the Response of MSW.
49
- * - 'data' uses your custom data to generate the data for the response.
50
- * - 'faker' uses @kubb/plugin-faker to generate the data for the response.
51
- * @default 'data'
52
- */
53
- parser?: 'data' | 'faker';
54
- /**
55
- * Define some generators next to the msw generators
56
- */
57
- generators?: Array<Generator$1<PluginMsw>>;
58
- };
59
- type ResolvedOptions = {
60
- output: Output<Oas>;
61
- group: Options['group'];
62
- parser: NonNullable<Options['parser']>;
63
- baseURL: Options['baseURL'] | undefined;
64
- };
65
- type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
66
- //#endregion
67
- export { PluginMsw as n, Options as t };
68
- //# sourceMappingURL=types-MdHRNpgi.d.ts.map