@kubb/plugin-msw 4.12.2 → 4.12.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{components-ATPc-lQH.cjs → components-N4uAuUW1.cjs} +16 -16
- package/dist/{components-ATPc-lQH.cjs.map → components-N4uAuUW1.cjs.map} +1 -1
- package/dist/components.cjs +1 -1
- package/dist/{generators-Cz0z5DBg.cjs → generators-CTtbmbWc.cjs} +37 -37
- package/dist/{generators-Cz0z5DBg.cjs.map → generators-CTtbmbWc.cjs.map} +1 -1
- package/dist/generators.cjs +1 -1
- package/dist/index.cjs +16 -16
- package/dist/index.cjs.map +1 -1
- package/package.json +7 -7
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
const require_index = require('./index.cjs');
|
|
2
|
-
let
|
|
3
|
-
let
|
|
4
|
-
let
|
|
2
|
+
let _kubb_react_fabric = require("@kubb/react-fabric");
|
|
3
|
+
let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
|
|
4
|
+
let _kubb_core_utils = require("@kubb/core/utils");
|
|
5
5
|
|
|
6
6
|
//#region src/components/Handlers.tsx
|
|
7
7
|
function Handlers({ name, handlers }) {
|
|
8
|
-
return /* @__PURE__ */ (0,
|
|
8
|
+
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
9
9
|
name,
|
|
10
10
|
isIndexable: true,
|
|
11
11
|
isExportable: true,
|
|
@@ -21,20 +21,20 @@ function Mock({ baseURL = "", name, typeName, operation }) {
|
|
|
21
21
|
const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200;
|
|
22
22
|
const responseObject = operation.getResponseByStatusCode(statusCode);
|
|
23
23
|
const contentType = Object.keys(responseObject.content || {})?.[0];
|
|
24
|
-
const url = new
|
|
24
|
+
const url = new _kubb_core_utils.URLPath(operation.path).toURLPath().replace(/([^/]):/g, "$1\\\\:");
|
|
25
25
|
const headers = [contentType ? `'Content-Type': '${contentType}'` : void 0].filter(Boolean);
|
|
26
26
|
const dataType = contentType && responseObject?.content?.[contentType]?.schema !== void 0 ? typeName : "string | number | boolean | null | object";
|
|
27
|
-
const params =
|
|
27
|
+
const params = _kubb_react_fabric.FunctionParams.factory({ data: {
|
|
28
28
|
type: `${dataType} | ((
|
|
29
29
|
info: Parameters<Parameters<typeof http.${method}>[1]>[0],
|
|
30
30
|
) => Response | Promise<Response>)`,
|
|
31
31
|
optional: true
|
|
32
32
|
} });
|
|
33
|
-
return /* @__PURE__ */ (0,
|
|
33
|
+
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
34
34
|
name,
|
|
35
35
|
isIndexable: true,
|
|
36
36
|
isExportable: true,
|
|
37
|
-
children: /* @__PURE__ */ (0,
|
|
37
|
+
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
|
|
38
38
|
name,
|
|
39
39
|
export: true,
|
|
40
40
|
params: params.toConstructor(),
|
|
@@ -60,19 +60,19 @@ function MockWithFaker({ baseURL = "", name, fakerName, typeName, operation }) {
|
|
|
60
60
|
const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200;
|
|
61
61
|
const responseObject = operation.getResponseByStatusCode(statusCode);
|
|
62
62
|
const contentType = Object.keys(responseObject.content || {})?.[0];
|
|
63
|
-
const url = new
|
|
63
|
+
const url = new _kubb_core_utils.URLPath(operation.path).toURLPath().replace(/([^/]):/g, "$1\\\\:");
|
|
64
64
|
const headers = [contentType ? `'Content-Type': '${contentType}'` : void 0].filter(Boolean);
|
|
65
|
-
const params =
|
|
65
|
+
const params = _kubb_react_fabric.FunctionParams.factory({ data: {
|
|
66
66
|
type: `${typeName} | ((
|
|
67
67
|
info: Parameters<Parameters<typeof http.${method}>[1]>[0],
|
|
68
68
|
) => Response | Promise<Response>)`,
|
|
69
69
|
optional: true
|
|
70
70
|
} });
|
|
71
|
-
return /* @__PURE__ */ (0,
|
|
71
|
+
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
72
72
|
name,
|
|
73
73
|
isIndexable: true,
|
|
74
74
|
isExportable: true,
|
|
75
|
-
children: /* @__PURE__ */ (0,
|
|
75
|
+
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
|
|
76
76
|
name,
|
|
77
77
|
export: true,
|
|
78
78
|
params: params.toConstructor(),
|
|
@@ -97,16 +97,16 @@ function Response({ name, typeName, operation, statusCode }) {
|
|
|
97
97
|
const contentType = Object.keys(responseObject.content || {})?.[0];
|
|
98
98
|
const headers = [contentType ? `'Content-Type': '${contentType}'` : void 0].filter(Boolean);
|
|
99
99
|
const hasResponseSchema = contentType && responseObject?.content?.[contentType]?.schema !== void 0;
|
|
100
|
-
const params =
|
|
100
|
+
const params = _kubb_react_fabric.FunctionParams.factory({ data: {
|
|
101
101
|
type: `${typeName}`,
|
|
102
102
|
optional: !hasResponseSchema
|
|
103
103
|
} });
|
|
104
104
|
const responseName = `${name}Response${statusCode}`;
|
|
105
|
-
return /* @__PURE__ */ (0,
|
|
105
|
+
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
106
106
|
name: responseName,
|
|
107
107
|
isIndexable: true,
|
|
108
108
|
isExportable: true,
|
|
109
|
-
children: /* @__PURE__ */ (0,
|
|
109
|
+
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
|
|
110
110
|
name: responseName,
|
|
111
111
|
export: true,
|
|
112
112
|
params: params.toConstructor(),
|
|
@@ -146,4 +146,4 @@ Object.defineProperty(exports, 'Response', {
|
|
|
146
146
|
return Response;
|
|
147
147
|
}
|
|
148
148
|
});
|
|
149
|
-
//# sourceMappingURL=components-
|
|
149
|
+
//# sourceMappingURL=components-N4uAuUW1.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components-
|
|
1
|
+
{"version":3,"file":"components-N4uAuUW1.cjs","names":["File","URLPath","FunctionParams","File","Function","URLPath","FunctionParams","File","Function","FunctionParams","File","Function"],"sources":["../src/components/Handlers.tsx","../src/components/Mock.tsx","../src/components/MockWithFaker.tsx","../src/components/Response.tsx"],"sourcesContent":["import { File } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\n\ntype HandlersProps = {\n /**\n * Name of the function\n */\n name: string\n // custom\n handlers: string[]\n}\n\nexport function Handlers({ name, handlers }: HandlersProps): KubbNode {\n return (\n <File.Source name={name} isIndexable isExportable>\n {`export const ${name} = ${JSON.stringify(handlers).replaceAll(`\"`, '')} as const`}\n </File.Source>\n )\n}\n","import { URLPath } from '@kubb/core/utils'\nimport type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n baseURL: string | undefined\n operation: Operation\n}\n\nexport function Mock({ baseURL = '', name, typeName, operation }: Props): KubbNode {\n const method = operation.method\n const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))\n const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200\n\n const responseObject = operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject\n const contentType = Object.keys(responseObject.content || {})?.[0]\n const url = new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\\\\\:')\n\n const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)\n\n const hasResponseSchema = contentType && responseObject?.content?.[contentType]?.schema !== undefined\n\n // If no response schema, uses any type but function to avoid overriding callback\n const dataType = hasResponseSchema ? typeName : 'string | number | boolean | null | object'\n\n const params = FunctionParams.factory({\n data: {\n type: `${dataType} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response | Promise<Response>)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}(\\`${baseURL}${url.replace(/([^/]):/g, '$1\\\\\\\\:')}\\`, function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data), {\n status: ${statusCode},\n ${\n headers.length\n ? ` headers: {\n ${headers.join(', \\n')}\n },`\n : ''\n }\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n","import { URLPath } from '@kubb/core/utils'\n\nimport type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeName: string\n fakerName: string\n baseURL: string | undefined\n operation: Operation\n}\n\nexport function MockWithFaker({ baseURL = '', name, fakerName, typeName, operation }: Props): KubbNode {\n const method = operation.method\n const successStatusCodes = operation.getResponseStatusCodes().filter((code) => code.startsWith('2'))\n const statusCode = successStatusCodes.length > 0 ? Number(successStatusCodes[0]) : 200\n\n const responseObject = operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject\n const contentType = Object.keys(responseObject.content || {})?.[0]\n const url = new URLPath(operation.path).toURLPath().replace(/([^/]):/g, '$1\\\\\\\\:')\n\n const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)\n\n const params = FunctionParams.factory({\n data: {\n type: `${typeName} | ((\n info: Parameters<Parameters<typeof http.${method}>[1]>[0],\n ) => Response | Promise<Response>)`,\n optional: true,\n },\n })\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()}>\n {`return http.${method}('${baseURL}${url.replace(/([^/]):/g, '$1\\\\\\\\:')}', function handler(info) {\n if(typeof data === 'function') return data(info)\n\n return new Response(JSON.stringify(data || ${fakerName}(data)), {\n status: ${statusCode},\n ${\n headers.length\n ? ` headers: {\n ${headers.join(', \\n')}\n },`\n : ''\n }\n })\n })`}\n </Function>\n </File.Source>\n )\n}\n","import type { OasTypes, Operation } from '@kubb/oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\n\ntype Props = {\n typeName: string\n operation: Operation\n name: string\n statusCode: number\n}\n\nexport function Response({ name, typeName, operation, statusCode }: Props): KubbNode {\n const responseObject = operation.getResponseByStatusCode(statusCode) as OasTypes.ResponseObject\n const contentType = Object.keys(responseObject.content || {})?.[0]\n\n const headers = [contentType ? `'Content-Type': '${contentType}'` : undefined].filter(Boolean)\n\n const hasResponseSchema = contentType && responseObject?.content?.[contentType]?.schema !== undefined\n\n const params = FunctionParams.factory({\n data: {\n type: `${typeName}`,\n optional: !hasResponseSchema,\n },\n })\n\n const responseName = `${name}Response${statusCode}`\n\n return (\n <File.Source name={responseName} isIndexable isExportable>\n <Function name={responseName} export params={params.toConstructor()}>\n {`\n return new Response(JSON.stringify(data), {\n status: ${statusCode},\n ${\n headers.length\n ? ` headers: {\n ${headers.join(', \\n')}\n },`\n : ''\n }\n })`}\n </Function>\n </File.Source>\n )\n}\n"],"mappings":";;;;;;AAYA,SAAgB,SAAS,EAAE,MAAM,YAAqC;AACpE,QACE,wDAACA,wBAAK;EAAa;EAAM;EAAY;YAClC,gBAAgB,KAAK,KAAK,KAAK,UAAU,SAAS,CAAC,WAAW,KAAK,GAAG,CAAC;GAC5D;;;;;ACAlB,SAAgB,KAAK,EAAE,UAAU,IAAI,MAAM,UAAU,aAA8B;CACjF,MAAM,SAAS,UAAU;CACzB,MAAM,qBAAqB,UAAU,wBAAwB,CAAC,QAAQ,SAAS,KAAK,WAAW,IAAI,CAAC;CACpG,MAAM,aAAa,mBAAmB,SAAS,IAAI,OAAO,mBAAmB,GAAG,GAAG;CAEnF,MAAM,iBAAiB,UAAU,wBAAwB,WAAW;CACpE,MAAM,cAAc,OAA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,CAAC;AAEF,QACE,wDAACC,wBAAK;EAAa;EAAM;EAAY;YACnC,wDAACC;GAAe;GAAM;GAAO,QAAQ,OAAO,eAAe;aACxD,eAAe,OAAO,IAAI,UAAU,IAAI,QAAQ,YAAY,UAAU,CAAC;;;iDAG/B,UAAU;gBAC3C,WAAW;QAEnB,QAAQ,SACJ;UACF,QAAQ,KAAK,OAAO,CAAC;YAEnB,GACL;;;IAGU;GACC;;;;;AC5ClB,SAAgB,SAAS,EAAE,MAAM,UAAU,WAAW,cAA+B;CACnF,MAAM,iBAAiB,UAAU,wBAAwB,WAAW;CACpE,MAAM,cAAc,OAAO,KAAK,eAAe,WAAW,EAAE,CAAC,GAAG;CAEhE,MAAM,UAAU,CAAC,cAAc,oBAAoB,YAAY,KAAK,OAAU,CAAC,OAAO,QAAQ;CAE9F,MAAM,oBAAoB,eAAe,gBAAgB,UAAU,cAAc,WAAW;CAE5F,MAAM,SAASC,kCAAe,QAAQ,EACpC,MAAM;EACJ,MAAM,GAAG;EACT,UAAU,CAAC;EACZ,EACF,CAAC;CAEF,MAAM,eAAe,GAAG,KAAK,UAAU;AAEvC,QACE,wDAACC,wBAAK;EAAO,MAAM;EAAc;EAAY;YAC3C,wDAACC;GAAS,MAAM;GAAc;GAAO,QAAQ,OAAO,eAAe;aAChE;;gBAEO,WAAW;QAEnB,QAAQ,SACJ;UACF,QAAQ,KAAK,OAAO,CAAC;YAEnB,GACL;;IAEU;GACC"}
|
package/dist/components.cjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
const require_components = require('./components-
|
|
1
|
+
const require_components = require('./components-N4uAuUW1.cjs');
|
|
2
2
|
const require_index = require('./index.cjs');
|
|
3
|
-
let
|
|
4
|
-
let
|
|
5
|
-
let
|
|
6
|
-
let
|
|
7
|
-
let
|
|
8
|
-
let
|
|
9
|
-
let
|
|
10
|
-
let
|
|
3
|
+
let _kubb_plugin_faker = require("@kubb/plugin-faker");
|
|
4
|
+
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
5
|
+
let _kubb_core_hooks = require("@kubb/core/hooks");
|
|
6
|
+
let _kubb_plugin_oas_generators = require("@kubb/plugin-oas/generators");
|
|
7
|
+
let _kubb_plugin_oas_hooks = require("@kubb/plugin-oas/hooks");
|
|
8
|
+
let _kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils");
|
|
9
|
+
let _kubb_react_fabric = require("@kubb/react-fabric");
|
|
10
|
+
let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
|
|
11
11
|
|
|
12
12
|
//#region src/generators/handlersGenerator.tsx
|
|
13
|
-
const handlersGenerator = (0,
|
|
13
|
+
const handlersGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
14
14
|
name: "plugin-msw",
|
|
15
15
|
Operations({ operations, generator, plugin }) {
|
|
16
|
-
const pluginManager = (0,
|
|
17
|
-
const oas = (0,
|
|
18
|
-
const { getName, getFile } = (0,
|
|
16
|
+
const pluginManager = (0, _kubb_core_hooks.usePluginManager)();
|
|
17
|
+
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
|
|
18
|
+
const { getName, getFile } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
|
|
19
19
|
const file = pluginManager.getFile({
|
|
20
20
|
name: "handlers",
|
|
21
21
|
extname: ".ts",
|
|
@@ -27,7 +27,7 @@ const handlersGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)
|
|
|
27
27
|
pluginKey: plugin.key,
|
|
28
28
|
type: "function"
|
|
29
29
|
});
|
|
30
|
-
return /* @__PURE__ */ (0,
|
|
30
|
+
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
31
31
|
name: [operationName],
|
|
32
32
|
root: file.path,
|
|
33
33
|
path: operationFile.path
|
|
@@ -37,20 +37,20 @@ const handlersGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)
|
|
|
37
37
|
type: "function",
|
|
38
38
|
pluginKey: plugin.key
|
|
39
39
|
})}()`);
|
|
40
|
-
return /* @__PURE__ */ (0,
|
|
40
|
+
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
|
|
41
41
|
baseName: file.baseName,
|
|
42
42
|
path: file.path,
|
|
43
43
|
meta: file.meta,
|
|
44
|
-
banner: (0,
|
|
44
|
+
banner: (0, _kubb_plugin_oas_utils.getBanner)({
|
|
45
45
|
oas,
|
|
46
46
|
output: plugin.options.output,
|
|
47
47
|
config: pluginManager.config
|
|
48
48
|
}),
|
|
49
|
-
footer: (0,
|
|
49
|
+
footer: (0, _kubb_plugin_oas_utils.getFooter)({
|
|
50
50
|
oas,
|
|
51
51
|
output: plugin.options.output
|
|
52
52
|
}),
|
|
53
|
-
children: [imports, /* @__PURE__ */ (0,
|
|
53
|
+
children: [imports, /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.Handlers, {
|
|
54
54
|
name: "handlers",
|
|
55
55
|
handlers
|
|
56
56
|
})]
|
|
@@ -60,28 +60,28 @@ const handlersGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)
|
|
|
60
60
|
|
|
61
61
|
//#endregion
|
|
62
62
|
//#region src/generators/mswGenerator.tsx
|
|
63
|
-
const mswGenerator = (0,
|
|
63
|
+
const mswGenerator = (0, _kubb_plugin_oas_generators.createReactGenerator)({
|
|
64
64
|
name: "msw",
|
|
65
65
|
Operation({ operation, generator, plugin }) {
|
|
66
66
|
const { options: { output, parser, baseURL } } = plugin;
|
|
67
|
-
const pluginManager = (0,
|
|
68
|
-
const oas = (0,
|
|
69
|
-
const { getSchemas, getName, getFile } = (0,
|
|
67
|
+
const pluginManager = (0, _kubb_core_hooks.usePluginManager)();
|
|
68
|
+
const oas = (0, _kubb_plugin_oas_hooks.useOas)();
|
|
69
|
+
const { getSchemas, getName, getFile } = (0, _kubb_plugin_oas_hooks.useOperationManager)(generator);
|
|
70
70
|
const mock = {
|
|
71
71
|
name: getName(operation, { type: "function" }),
|
|
72
72
|
file: getFile(operation)
|
|
73
73
|
};
|
|
74
74
|
const faker = {
|
|
75
|
-
file: getFile(operation, { pluginKey: [
|
|
75
|
+
file: getFile(operation, { pluginKey: [_kubb_plugin_faker.pluginFakerName] }),
|
|
76
76
|
schemas: getSchemas(operation, {
|
|
77
|
-
pluginKey: [
|
|
77
|
+
pluginKey: [_kubb_plugin_faker.pluginFakerName],
|
|
78
78
|
type: "function"
|
|
79
79
|
})
|
|
80
80
|
};
|
|
81
81
|
const type = {
|
|
82
|
-
file: getFile(operation, { pluginKey: [
|
|
82
|
+
file: getFile(operation, { pluginKey: [_kubb_plugin_ts.pluginTsName] }),
|
|
83
83
|
schemas: getSchemas(operation, {
|
|
84
|
-
pluginKey: [
|
|
84
|
+
pluginKey: [_kubb_plugin_ts.pluginTsName],
|
|
85
85
|
type: "type"
|
|
86
86
|
})
|
|
87
87
|
};
|
|
@@ -99,54 +99,54 @@ const mswGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)({
|
|
|
99
99
|
const codeType = type.schemas.errors?.find((err) => err.statusCode === Number(code));
|
|
100
100
|
if (codeType) types.push([Number(code), codeType.name]);
|
|
101
101
|
}
|
|
102
|
-
return /* @__PURE__ */ (0,
|
|
102
|
+
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
|
|
103
103
|
baseName: mock.file.baseName,
|
|
104
104
|
path: mock.file.path,
|
|
105
105
|
meta: mock.file.meta,
|
|
106
|
-
banner: (0,
|
|
106
|
+
banner: (0, _kubb_plugin_oas_utils.getBanner)({
|
|
107
107
|
oas,
|
|
108
108
|
output,
|
|
109
109
|
config: pluginManager.config
|
|
110
110
|
}),
|
|
111
|
-
footer: (0,
|
|
111
|
+
footer: (0, _kubb_plugin_oas_utils.getFooter)({
|
|
112
112
|
oas,
|
|
113
113
|
output
|
|
114
114
|
}),
|
|
115
115
|
children: [
|
|
116
|
-
/* @__PURE__ */ (0,
|
|
116
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
117
117
|
name: ["http"],
|
|
118
118
|
path: "msw"
|
|
119
119
|
}),
|
|
120
|
-
/* @__PURE__ */ (0,
|
|
120
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
121
121
|
name: ["ResponseResolver"],
|
|
122
122
|
isTypeOnly: true,
|
|
123
123
|
path: "msw"
|
|
124
124
|
}),
|
|
125
|
-
/* @__PURE__ */ (0,
|
|
125
|
+
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
126
126
|
name: Array.from(new Set([type.schemas.response.name, ...types.map((t) => t[1])])),
|
|
127
127
|
path: type.file.path,
|
|
128
128
|
root: mock.file.path,
|
|
129
129
|
isTypeOnly: true
|
|
130
130
|
}),
|
|
131
|
-
parser === "faker" && faker.file && faker.schemas.response && /* @__PURE__ */ (0,
|
|
131
|
+
parser === "faker" && faker.file && faker.schemas.response && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
|
|
132
132
|
name: [faker.schemas.response.name],
|
|
133
133
|
root: mock.file.path,
|
|
134
134
|
path: faker.file.path
|
|
135
135
|
}),
|
|
136
|
-
types.filter(([code]) => code !== "default").map(([code, typeName]) => /* @__PURE__ */ (0,
|
|
136
|
+
types.filter(([code]) => code !== "default").map(([code, typeName]) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.Response, {
|
|
137
137
|
typeName,
|
|
138
138
|
operation,
|
|
139
139
|
name: mock.name,
|
|
140
140
|
statusCode: code
|
|
141
141
|
})),
|
|
142
|
-
parser === "faker" && /* @__PURE__ */ (0,
|
|
142
|
+
parser === "faker" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.MockWithFaker, {
|
|
143
143
|
name: mock.name,
|
|
144
144
|
typeName: type.schemas.response.name,
|
|
145
145
|
fakerName: faker.schemas.response.name,
|
|
146
146
|
operation,
|
|
147
147
|
baseURL
|
|
148
148
|
}),
|
|
149
|
-
parser === "data" && /* @__PURE__ */ (0,
|
|
149
|
+
parser === "data" && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(require_components.Mock, {
|
|
150
150
|
name: mock.name,
|
|
151
151
|
typeName: type.schemas.response.name,
|
|
152
152
|
fakerName: faker.schemas.response.name,
|
|
@@ -171,4 +171,4 @@ Object.defineProperty(exports, 'mswGenerator', {
|
|
|
171
171
|
return mswGenerator;
|
|
172
172
|
}
|
|
173
173
|
});
|
|
174
|
-
//# sourceMappingURL=generators-
|
|
174
|
+
//# sourceMappingURL=generators-CTtbmbWc.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generators-
|
|
1
|
+
{"version":3,"file":"generators-CTtbmbWc.cjs","names":["File","Handlers","pluginFakerName","pluginTsName","types: [statusCode: number | 'default', typeName: string][]","File","Response","MockWithFaker","Mock"],"sources":["../src/generators/handlersGenerator.tsx","../src/generators/mswGenerator.tsx"],"sourcesContent":["import { usePluginManager } 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 pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getName, getFile } = useOperationManager(generator)\n\n const file = pluginManager.getFile({ name: 'handlers', extname: '.ts', pluginKey: plugin.key })\n\n const imports = operations.map((operation) => {\n const operationFile = getFile(operation, { pluginKey: plugin.key })\n const operationName = getName(operation, { pluginKey: plugin.key, 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', pluginKey: plugin.key })}()`)\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: pluginManager.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 { usePluginManager } 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 pluginManager = usePluginManager()\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, { pluginKey: [pluginFakerName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginFakerName], type: 'function' }),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [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: pluginManager.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,0EAAoD;CAC/D,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,wDAAkC;EAExC,MAAM,0CAAc;EACpB,MAAM,EAAE,SAAS,4DAAgC,UAAU;EAE3D,MAAM,OAAO,cAAc,QAAQ;GAAE,MAAM;GAAY,SAAS;GAAO,WAAW,OAAO;GAAK,CAAC;EAE/F,MAAM,UAAU,WAAW,KAAK,cAAc;GAC5C,MAAM,gBAAgB,QAAQ,WAAW,EAAE,WAAW,OAAO,KAAK,CAAC;GACnE,MAAM,gBAAgB,QAAQ,WAAW;IAAE,WAAW,OAAO;IAAK,MAAM;IAAY,CAAC;AAErF,UAAO,wDAACA,wBAAK;IAAgC,MAAM,CAAC,cAAc;IAAE,MAAM,KAAK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MACT;IAEH,WAAW,UACV,wDAACC;KAAK,MAAM,KAAK;KAAM,UAAU,KAAK,QAAQ,SAAS;KAAM,WAAW,MAAM,QAAQ,SAAS;KAAiB;KAAoB;MAAW;;IAE5I;;CAGZ,CAAC"}
|
package/dist/generators.cjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -25,18 +25,18 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
}) : target, mod));
|
|
26
26
|
|
|
27
27
|
//#endregion
|
|
28
|
-
const require_generators = require('./generators-
|
|
28
|
+
const require_generators = require('./generators-CTtbmbWc.cjs');
|
|
29
29
|
let node_path = require("node:path");
|
|
30
30
|
node_path = __toESM(node_path);
|
|
31
|
-
let
|
|
32
|
-
let
|
|
33
|
-
let
|
|
34
|
-
let
|
|
35
|
-
let
|
|
31
|
+
let _kubb_core = require("@kubb/core");
|
|
32
|
+
let _kubb_core_transformers = require("@kubb/core/transformers");
|
|
33
|
+
let _kubb_plugin_faker = require("@kubb/plugin-faker");
|
|
34
|
+
let _kubb_plugin_oas = require("@kubb/plugin-oas");
|
|
35
|
+
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
36
36
|
|
|
37
37
|
//#region src/plugin.ts
|
|
38
38
|
const pluginMswName = "plugin-msw";
|
|
39
|
-
const pluginMsw = (0,
|
|
39
|
+
const pluginMsw = (0, _kubb_core.definePlugin)((options) => {
|
|
40
40
|
const { output = {
|
|
41
41
|
path: "handlers",
|
|
42
42
|
barrelType: "named"
|
|
@@ -50,13 +50,13 @@ const pluginMsw = (0, __kubb_core.definePlugin)((options) => {
|
|
|
50
50
|
baseURL
|
|
51
51
|
},
|
|
52
52
|
pre: [
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
parser === "faker" ?
|
|
53
|
+
_kubb_plugin_oas.pluginOasName,
|
|
54
|
+
_kubb_plugin_ts.pluginTsName,
|
|
55
|
+
parser === "faker" ? _kubb_plugin_faker.pluginFakerName : void 0
|
|
56
56
|
].filter(Boolean),
|
|
57
57
|
resolvePath(baseName, pathMode, options$1) {
|
|
58
58
|
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
59
|
-
if ((pathMode ?? (0,
|
|
59
|
+
if ((pathMode ?? (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path))) === "single")
|
|
60
60
|
/**
|
|
61
61
|
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
62
62
|
* Other plugins then need to call addOrAppend instead of just add from the fileManager class
|
|
@@ -65,14 +65,14 @@ const pluginMsw = (0, __kubb_core.definePlugin)((options) => {
|
|
|
65
65
|
if (group && (options$1?.group?.path || options$1?.group?.tag)) {
|
|
66
66
|
const groupName = group?.name ? group.name : (ctx) => {
|
|
67
67
|
if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
68
|
-
return `${(0,
|
|
68
|
+
return `${(0, _kubb_core_transformers.camelCase)(ctx.group)}Controller`;
|
|
69
69
|
};
|
|
70
70
|
return node_path.default.resolve(root, output.path, groupName({ group: group.type === "path" ? options$1.group.path : options$1.group.tag }), baseName);
|
|
71
71
|
}
|
|
72
72
|
return node_path.default.resolve(root, output.path, baseName);
|
|
73
73
|
},
|
|
74
74
|
resolveName(name, type) {
|
|
75
|
-
const resolvedName = (0,
|
|
75
|
+
const resolvedName = (0, _kubb_core_transformers.camelCase)(name, {
|
|
76
76
|
suffix: type ? "handler" : void 0,
|
|
77
77
|
isFile: type === "file"
|
|
78
78
|
});
|
|
@@ -81,9 +81,9 @@ const pluginMsw = (0, __kubb_core.definePlugin)((options) => {
|
|
|
81
81
|
},
|
|
82
82
|
async install() {
|
|
83
83
|
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
84
|
-
const mode = (0,
|
|
84
|
+
const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path));
|
|
85
85
|
const oas = await this.getOas();
|
|
86
|
-
const files = await new
|
|
86
|
+
const files = await new _kubb_plugin_oas.OperationGenerator(this.plugin.options, {
|
|
87
87
|
fabric: this.fabric,
|
|
88
88
|
oas,
|
|
89
89
|
pluginManager: this.pluginManager,
|
|
@@ -96,7 +96,7 @@ const pluginMsw = (0, __kubb_core.definePlugin)((options) => {
|
|
|
96
96
|
mode
|
|
97
97
|
}).build(...generators);
|
|
98
98
|
await this.upsertFile(...files);
|
|
99
|
-
const barrelFiles = await (0,
|
|
99
|
+
const barrelFiles = await (0, _kubb_core.getBarrelFiles)(this.fabric.files, {
|
|
100
100
|
type: output.barrelType ?? "named",
|
|
101
101
|
root,
|
|
102
102
|
output,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["mswGenerator","handlersGenerator","pluginOasName","pluginTsName","pluginFakerName","path","options","groupName: Group['name']","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = definePlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n parser = 'data',\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n contentType,\n baseURL,\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n group,\n baseURL,\n },\n pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? 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 (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\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\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAa,gBAAgB;AAE7B,MAAa,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["mswGenerator","handlersGenerator","pluginOasName","pluginTsName","pluginFakerName","path","options","groupName: Group['name']","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = definePlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n parser = 'data',\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n contentType,\n baseURL,\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n group,\n baseURL,\n },\n pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? 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 (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\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\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAa,gBAAgB;AAE7B,MAAa,0CAAqC,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAY,YAAY;EAAS,EAClD,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,WAAW,OACX,SAAS,QACT,aAAa,CAACA,iCAAc,WAAWC,uCAAoB,OAAU,CAAC,OAAO,QAAQ,EACrF,aACA,YACE;AAEJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GACA;GACD;EACD,KAAK;GAACC;GAAeC;GAAc,WAAW,UAAUC,qCAAkB;GAAU,CAAC,OAAO,QAAQ;EACpG,YAAY,UAAU,UAAU,WAAS;GACvC,MAAM,OAAOC,kBAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;AAGpE,QAFa,oCAAoBA,kBAAK,QAAQ,MAAM,OAAO,KAAK,CAAC,MAEpD;;;;;AAKX,UAAOA,kBAAK,QAAQ,MAAM,OAAO,KAAK;AAGxC,OAAI,UAAUC,WAAS,OAAO,QAAQA,WAAS,OAAO,MAAM;IAC1D,MAAMC,YAA2B,OAAO,OACpC,MAAM,QACL,QAAQ;AACP,SAAI,OAAO,SAAS,OAClB,QAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;AAEjC,YAAO,0CAAa,IAAI,MAAM,CAAC;;AAGrC,WAAOF,kBAAK,QACV,MACA,OAAO,MACP,UAAU,EACR,OAAO,MAAM,SAAS,SAASC,UAAQ,MAAM,OAAQA,UAAQ,MAAM,KACpE,CAAC,EACF,SACD;;AAGH,UAAOD,kBAAK,QAAQ,MAAM,OAAO,MAAM,SAAS;;EAElD,YAAY,MAAM,MAAM;GACtB,MAAM,sDAAyB,MAAM;IACnC,QAAQ,OAAO,YAAY;IAC3B,QAAQ,SAAS;IAClB,CAAC;AAEF,OAAI,KACF,QAAO,cAAc,OAAO,cAAc,KAAK,IAAI;AAGrD,UAAO;;EAET,MAAM,UAAU;GACd,MAAM,OAAOA,kBAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,+BAAeA,kBAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACrD,MAAM,MAAM,MAAM,KAAK,QAAQ;GAe/B,MAAM,QAAQ,MAba,IAAIG,oCAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,MAAM,cAAc,qCAAqB,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-msw",
|
|
3
|
-
"version": "4.12.
|
|
3
|
+
"version": "4.12.4",
|
|
4
4
|
"description": "Mock Service Worker (MSW) handlers generator plugin for Kubb, creating API mocks from OpenAPI specifications for frontend development and testing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"msw",
|
|
@@ -73,12 +73,12 @@
|
|
|
73
73
|
}
|
|
74
74
|
],
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@kubb/react-fabric": "0.7.
|
|
77
|
-
"@kubb/core": "4.12.
|
|
78
|
-
"@kubb/oas": "4.12.
|
|
79
|
-
"@kubb/plugin-faker": "4.12.
|
|
80
|
-
"@kubb/plugin-oas": "4.12.
|
|
81
|
-
"@kubb/plugin-ts": "4.12.
|
|
76
|
+
"@kubb/react-fabric": "0.7.1",
|
|
77
|
+
"@kubb/core": "4.12.4",
|
|
78
|
+
"@kubb/oas": "4.12.4",
|
|
79
|
+
"@kubb/plugin-faker": "4.12.4",
|
|
80
|
+
"@kubb/plugin-oas": "4.12.4",
|
|
81
|
+
"@kubb/plugin-ts": "4.12.4"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {},
|
|
84
84
|
"engines": {
|