@kubb/plugin-msw 5.0.0-beta.56 → 5.0.0-beta.73
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/index.cjs +640 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +92 -2
- package/dist/index.js +635 -8
- package/dist/index.js.map +1 -1
- package/package.json +9 -18
- package/dist/components-Bi7cN-ws.js +0 -431
- package/dist/components-Bi7cN-ws.js.map +0 -1
- package/dist/components-Bp69JYOt.cjs +0 -484
- package/dist/components-Bp69JYOt.cjs.map +0 -1
- package/dist/components.cjs +0 -5
- package/dist/components.d.ts +0 -53
- package/dist/components.js +0 -2
- package/dist/generators-BnEvTy3q.js +0 -208
- package/dist/generators-BnEvTy3q.js.map +0 -1
- package/dist/generators-d22_s2UN.cjs +0 -218
- package/dist/generators-d22_s2UN.cjs.map +0 -1
- package/dist/generators.cjs +0 -4
- package/dist/generators.d.ts +0 -23
- package/dist/generators.js +0 -2
- package/dist/types-B1yTWOfj.d.ts +0 -99
- package/src/components/Mock.tsx +0 -71
- package/src/components/MockWithFaker.tsx +0 -70
- package/src/components/Response.tsx +0 -52
- package/src/components/index.ts +0 -3
- package/src/generators/handlersGenerator.ts +0 -49
- package/src/generators/index.ts +0 -2
- package/src/generators/mswGenerator.tsx +0 -96
- package/src/index.ts +0 -2
- package/src/plugin.ts +0 -94
- package/src/resolvers/resolverMsw.ts +0 -35
- package/src/types.ts +0 -98
- package/src/utils.ts +0 -74
- /package/dist/{chunk-C0LytTxp.js → rolldown-runtime-C0LytTxp.js} +0 -0
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import "./chunk-C0LytTxp.js";
|
|
2
|
-
import { a as getOperationSuccessResponses, i as resolveFakerMeta, n as MockWithFaker, o as resolveResponseTypes, r as Mock, t as Response } from "./components-Bi7cN-ws.js";
|
|
3
|
-
import { ast, defineGenerator } from "@kubb/core";
|
|
4
|
-
import { pluginFakerName } from "@kubb/plugin-faker";
|
|
5
|
-
import { pluginTsName } from "@kubb/plugin-ts";
|
|
6
|
-
import { File, jsxRenderer } from "@kubb/renderer-jsx";
|
|
7
|
-
import { jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
8
|
-
//#region src/generators/handlersGenerator.ts
|
|
9
|
-
/**
|
|
10
|
-
* Aggregate generator enabled by `pluginMsw({ handlers: true })`. Emits a
|
|
11
|
-
* `handlers.ts` file that re-exports every generated handler grouped by HTTP
|
|
12
|
-
* method, ready to spread into `setupServer(...handlers)` or
|
|
13
|
-
* `setupWorker(...handlers)`.
|
|
14
|
-
*/
|
|
15
|
-
const handlersGenerator = defineGenerator({
|
|
16
|
-
name: "plugin-msw",
|
|
17
|
-
operations(nodes, ctx) {
|
|
18
|
-
const { resolver, config, root } = ctx;
|
|
19
|
-
const { output, group } = ctx.options;
|
|
20
|
-
const handlersName = resolver.resolveHandlersName();
|
|
21
|
-
const file = resolver.resolveFile({
|
|
22
|
-
name: resolver.resolvePathName(handlersName, "file"),
|
|
23
|
-
extname: ".ts"
|
|
24
|
-
}, {
|
|
25
|
-
root,
|
|
26
|
-
output,
|
|
27
|
-
group: group ?? void 0
|
|
28
|
-
});
|
|
29
|
-
const imports = nodes.map((node) => {
|
|
30
|
-
const operationName = resolver.resolveHandlerName(node);
|
|
31
|
-
const operationFile = resolver.resolveFile({
|
|
32
|
-
name: resolver.resolveName(node.operationId),
|
|
33
|
-
extname: ".ts",
|
|
34
|
-
tag: node.tags[0] ?? "default",
|
|
35
|
-
path: node.path
|
|
36
|
-
}, {
|
|
37
|
-
root,
|
|
38
|
-
output,
|
|
39
|
-
group: group ?? void 0
|
|
40
|
-
});
|
|
41
|
-
return ast.createImport({
|
|
42
|
-
name: [operationName],
|
|
43
|
-
root: file.path,
|
|
44
|
-
path: operationFile.path
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
const handlers = nodes.map((node) => `${resolver.resolveHandlerName(node)}()`);
|
|
48
|
-
return [ast.createFile({
|
|
49
|
-
baseName: file.baseName,
|
|
50
|
-
path: file.path,
|
|
51
|
-
meta: file.meta,
|
|
52
|
-
banner: resolver.resolveBanner(ctx.meta, {
|
|
53
|
-
output,
|
|
54
|
-
config,
|
|
55
|
-
file: {
|
|
56
|
-
path: file.path,
|
|
57
|
-
baseName: file.baseName
|
|
58
|
-
}
|
|
59
|
-
}),
|
|
60
|
-
footer: resolver.resolveFooter(ctx.meta, {
|
|
61
|
-
output,
|
|
62
|
-
config,
|
|
63
|
-
file: {
|
|
64
|
-
path: file.path,
|
|
65
|
-
baseName: file.baseName
|
|
66
|
-
}
|
|
67
|
-
}),
|
|
68
|
-
imports,
|
|
69
|
-
sources: [ast.createSource({
|
|
70
|
-
name: handlersName,
|
|
71
|
-
isIndexable: true,
|
|
72
|
-
isExportable: true,
|
|
73
|
-
nodes: [ast.createText(`export const ${handlersName} = ${JSON.stringify(handlers).replaceAll("\"", "")} as const`)]
|
|
74
|
-
})]
|
|
75
|
-
})];
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/generators/mswGenerator.tsx
|
|
80
|
-
/**
|
|
81
|
-
* Built-in operation generator for `@kubb/plugin-msw`. Emits one MSW handler
|
|
82
|
-
* per OpenAPI operation. With `parser: 'faker'` the handler returns a value
|
|
83
|
-
* from `@kubb/plugin-faker`; with `parser: 'data'` it returns a typed empty
|
|
84
|
-
* payload for tests to fill in.
|
|
85
|
-
*/
|
|
86
|
-
const mswGenerator = defineGenerator({
|
|
87
|
-
name: "msw",
|
|
88
|
-
renderer: jsxRenderer,
|
|
89
|
-
operation(node, ctx) {
|
|
90
|
-
if (!ast.isHttpOperationNode(node)) return null;
|
|
91
|
-
const { driver, resolver, config, root } = ctx;
|
|
92
|
-
const { output, parser, baseURL, group } = ctx.options;
|
|
93
|
-
const fileName = resolver.resolveName(node.operationId);
|
|
94
|
-
const mock = {
|
|
95
|
-
name: resolver.resolveHandlerName(node),
|
|
96
|
-
file: resolver.resolveFile({
|
|
97
|
-
name: fileName,
|
|
98
|
-
extname: ".ts",
|
|
99
|
-
tag: node.tags[0] ?? "default",
|
|
100
|
-
path: node.path
|
|
101
|
-
}, {
|
|
102
|
-
root,
|
|
103
|
-
output,
|
|
104
|
-
group: group ?? void 0
|
|
105
|
-
})
|
|
106
|
-
};
|
|
107
|
-
const fakerPlugin = parser === "faker" ? driver.getPlugin(pluginFakerName) : null;
|
|
108
|
-
const faker = parser === "faker" && fakerPlugin ? resolveFakerMeta(node, {
|
|
109
|
-
root,
|
|
110
|
-
fakerResolver: driver.getResolver(pluginFakerName),
|
|
111
|
-
fakerOutput: fakerPlugin.options?.output ?? output,
|
|
112
|
-
fakerGroup: fakerPlugin.options?.group ?? null
|
|
113
|
-
}) : null;
|
|
114
|
-
const pluginTs = driver.getPlugin(pluginTsName);
|
|
115
|
-
if (!pluginTs) return null;
|
|
116
|
-
const tsResolver = driver.getResolver(pluginTsName);
|
|
117
|
-
const type = {
|
|
118
|
-
file: tsResolver.resolveFile({
|
|
119
|
-
name: node.operationId,
|
|
120
|
-
extname: ".ts",
|
|
121
|
-
tag: node.tags[0] ?? "default",
|
|
122
|
-
path: node.path
|
|
123
|
-
}, {
|
|
124
|
-
root,
|
|
125
|
-
output: pluginTs.options?.output ?? output,
|
|
126
|
-
group: pluginTs.options?.group ?? void 0
|
|
127
|
-
}),
|
|
128
|
-
responseName: tsResolver.resolveResponseName(node)
|
|
129
|
-
};
|
|
130
|
-
const types = resolveResponseTypes(node, tsResolver);
|
|
131
|
-
const hasSuccessSchema = getOperationSuccessResponses(node).some((response) => !!response.content?.[0]?.schema);
|
|
132
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : null;
|
|
133
|
-
return /* @__PURE__ */ jsxs(File, {
|
|
134
|
-
baseName: mock.file.baseName,
|
|
135
|
-
path: mock.file.path,
|
|
136
|
-
meta: mock.file.meta,
|
|
137
|
-
banner: resolver.resolveBanner(ctx.meta, {
|
|
138
|
-
output,
|
|
139
|
-
config,
|
|
140
|
-
file: {
|
|
141
|
-
path: mock.file.path,
|
|
142
|
-
baseName: mock.file.baseName
|
|
143
|
-
}
|
|
144
|
-
}),
|
|
145
|
-
footer: resolver.resolveFooter(ctx.meta, {
|
|
146
|
-
output,
|
|
147
|
-
config,
|
|
148
|
-
file: {
|
|
149
|
-
path: mock.file.path,
|
|
150
|
-
baseName: mock.file.baseName
|
|
151
|
-
}
|
|
152
|
-
}),
|
|
153
|
-
children: [
|
|
154
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
155
|
-
name: ["http"],
|
|
156
|
-
path: "msw"
|
|
157
|
-
}),
|
|
158
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
159
|
-
name: ["HttpResponseResolver"],
|
|
160
|
-
isTypeOnly: true,
|
|
161
|
-
path: "msw"
|
|
162
|
-
}),
|
|
163
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
164
|
-
name: Array.from(new Set([
|
|
165
|
-
type.responseName,
|
|
166
|
-
...types.map((t) => t[1]),
|
|
167
|
-
...requestName ? [requestName] : []
|
|
168
|
-
])),
|
|
169
|
-
path: type.file.path,
|
|
170
|
-
root: mock.file.path,
|
|
171
|
-
isTypeOnly: true
|
|
172
|
-
}),
|
|
173
|
-
parser === "faker" && faker && /* @__PURE__ */ jsx(File.Import, {
|
|
174
|
-
name: [faker.name],
|
|
175
|
-
root: mock.file.path,
|
|
176
|
-
path: faker.file.path
|
|
177
|
-
}),
|
|
178
|
-
types.filter(([code]) => code !== "default").map(([code, typeName]) => {
|
|
179
|
-
const response = node.responses.find((item) => item.statusCode === String(code));
|
|
180
|
-
if (!response) return null;
|
|
181
|
-
return /* @__PURE__ */ jsx(Response, {
|
|
182
|
-
typeName,
|
|
183
|
-
response,
|
|
184
|
-
name: mock.name
|
|
185
|
-
}, typeName);
|
|
186
|
-
}),
|
|
187
|
-
parser === "faker" && faker && hasSuccessSchema ? /* @__PURE__ */ jsx(MockWithFaker, {
|
|
188
|
-
name: mock.name,
|
|
189
|
-
typeName: type.responseName,
|
|
190
|
-
requestTypeName: requestName,
|
|
191
|
-
fakerName: faker.name,
|
|
192
|
-
node,
|
|
193
|
-
baseURL
|
|
194
|
-
}) : /* @__PURE__ */ jsx(Mock, {
|
|
195
|
-
name: mock.name,
|
|
196
|
-
typeName: type.responseName,
|
|
197
|
-
requestTypeName: requestName,
|
|
198
|
-
node,
|
|
199
|
-
baseURL
|
|
200
|
-
})
|
|
201
|
-
]
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
//#endregion
|
|
206
|
-
export { handlersGenerator as n, mswGenerator as t };
|
|
207
|
-
|
|
208
|
-
//# sourceMappingURL=generators-BnEvTy3q.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-BnEvTy3q.js","names":[],"sources":["../src/generators/handlersGenerator.ts","../src/generators/mswGenerator.tsx"],"sourcesContent":["import { ast, defineGenerator } from '@kubb/core'\nimport type { PluginMsw } from '../types'\n\n/**\n * Aggregate generator enabled by `pluginMsw({ handlers: true })`. Emits a\n * `handlers.ts` file that re-exports every generated handler grouped by HTTP\n * method, ready to spread into `setupServer(...handlers)` or\n * `setupWorker(...handlers)`.\n */\nexport const handlersGenerator = defineGenerator<PluginMsw>({\n name: 'plugin-msw',\n operations(nodes, ctx) {\n const { resolver, config, root } = ctx\n const { output, group } = ctx.options\n\n const handlersName = resolver.resolveHandlersName()\n const file = resolver.resolveFile({ name: resolver.resolvePathName(handlersName, 'file'), extname: '.ts' }, { root, output, group: group ?? undefined })\n\n const imports = nodes.map((node) => {\n const operationName = resolver.resolveHandlerName(node)\n const operationFile = resolver.resolveFile(\n { name: resolver.resolveName(node.operationId), extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },\n { root, output, group: group ?? undefined },\n )\n return ast.createImport({ name: [operationName], root: file.path, path: operationFile.path })\n })\n\n const handlers = nodes.map((node) => `${resolver.resolveHandlerName(node)}()`)\n\n return [\n ast.createFile({\n baseName: file.baseName,\n path: file.path,\n meta: file.meta,\n banner: resolver.resolveBanner(ctx.meta, { output, config, file: { path: file.path, baseName: file.baseName } }),\n footer: resolver.resolveFooter(ctx.meta, { output, config, file: { path: file.path, baseName: file.baseName } }),\n imports,\n sources: [\n ast.createSource({\n name: handlersName,\n isIndexable: true,\n isExportable: true,\n nodes: [ast.createText(`export const ${handlersName} = ${JSON.stringify(handlers).replaceAll('\"', '')} as const`)],\n }),\n ],\n }),\n ]\n },\n})\n","import { getOperationSuccessResponses, resolveResponseTypes } from '@internals/shared'\nimport { ast, defineGenerator } from '@kubb/core'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, jsxRenderer } from '@kubb/renderer-jsx'\nimport { Mock, MockWithFaker, Response } from '../components'\nimport type { PluginMsw } from '../types'\nimport { resolveFakerMeta } from '../utils.ts'\n\n/**\n * Built-in operation generator for `@kubb/plugin-msw`. Emits one MSW handler\n * per OpenAPI operation. With `parser: 'faker'` the handler returns a value\n * from `@kubb/plugin-faker`; with `parser: 'data'` it returns a typed empty\n * payload for tests to fill in.\n */\nexport const mswGenerator = defineGenerator<PluginMsw>({\n name: 'msw',\n renderer: jsxRenderer,\n operation(node, ctx) {\n if (!ast.isHttpOperationNode(node)) return null\n const { driver, resolver, config, root } = ctx\n const { output, parser, baseURL, group } = ctx.options\n\n const fileName = resolver.resolveName(node.operationId)\n const mock = {\n name: resolver.resolveHandlerName(node),\n file: resolver.resolveFile(\n { name: fileName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },\n { root, output, group: group ?? undefined },\n ),\n }\n\n const fakerPlugin = parser === 'faker' ? driver.getPlugin(pluginFakerName) : null\n const faker =\n parser === 'faker' && fakerPlugin\n ? resolveFakerMeta(node, {\n root,\n fakerResolver: driver.getResolver(pluginFakerName),\n fakerOutput: fakerPlugin.options?.output ?? output,\n fakerGroup: fakerPlugin.options?.group ?? null,\n })\n : null\n\n const pluginTs = driver.getPlugin(pluginTsName)\n if (!pluginTs) return null\n const tsResolver = driver.getResolver(pluginTsName)\n\n const type = {\n file: tsResolver.resolveFile(\n { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },\n { root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group ?? undefined },\n ),\n responseName: tsResolver.resolveResponseName(node),\n }\n\n const types = resolveResponseTypes(node, tsResolver)\n const successResponses = getOperationSuccessResponses(node)\n const hasSuccessSchema = successResponses.some((response) => !!response.content?.[0]?.schema)\n\n const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : null\n\n return (\n <File\n baseName={mock.file.baseName}\n path={mock.file.path}\n meta={mock.file.meta}\n banner={resolver.resolveBanner(ctx.meta, { output, config, file: { path: mock.file.path, baseName: mock.file.baseName } })}\n footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: mock.file.path, baseName: mock.file.baseName } })}\n >\n <File.Import name={['http']} path=\"msw\" />\n <File.Import name={['HttpResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import\n name={Array.from(new Set([type.responseName, ...types.map((t) => t[1]), ...(requestName ? [requestName] : [])]))}\n path={type.file.path}\n root={mock.file.path}\n isTypeOnly\n />\n {parser === 'faker' && faker && <File.Import name={[faker.name]} root={mock.file.path} path={faker.file.path} />}\n\n {types\n .filter(([code]) => code !== 'default')\n .map(([code, typeName]) => {\n const response = node.responses.find((item) => item.statusCode === String(code))\n if (!response) return null\n return <Response key={typeName} typeName={typeName} response={response} name={mock.name} />\n })}\n\n {parser === 'faker' && faker && hasSuccessSchema ? (\n <MockWithFaker name={mock.name} typeName={type.responseName} requestTypeName={requestName} fakerName={faker.name} node={node} baseURL={baseURL} />\n ) : (\n <Mock name={mock.name} typeName={type.responseName} requestTypeName={requestName} node={node} baseURL={baseURL} />\n )}\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;;AASA,MAAa,oBAAoB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MAAmC;MAAoB;MAAU,MAAM,KAAK;KAAO,GAApE,QAAoE;IAC5F,CAAC;IAEF,WAAW,WAAW,SAAS,mBAC9B,oBAAC,eAAD;KAAe,MAAM,KAAK;KAAM,UAAU,KAAK;KAAc,iBAAiB;KAAa,WAAW,MAAM;KAAY;KAAe;IAAU,CAAA,IAEjJ,oBAAC,MAAD;KAAM,MAAM,KAAK;KAAM,UAAU,KAAK;KAAc,iBAAiB;KAAmB;KAAe;IAAU,CAAA;GAE/G;;CAEV;AACF,CAAC"}
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
const require_components = require("./components-Bp69JYOt.cjs");
|
|
2
|
-
let _kubb_core = require("@kubb/core");
|
|
3
|
-
let _kubb_plugin_faker = require("@kubb/plugin-faker");
|
|
4
|
-
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
5
|
-
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
6
|
-
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
7
|
-
//#region src/generators/handlersGenerator.ts
|
|
8
|
-
/**
|
|
9
|
-
* Aggregate generator enabled by `pluginMsw({ handlers: true })`. Emits a
|
|
10
|
-
* `handlers.ts` file that re-exports every generated handler grouped by HTTP
|
|
11
|
-
* method, ready to spread into `setupServer(...handlers)` or
|
|
12
|
-
* `setupWorker(...handlers)`.
|
|
13
|
-
*/
|
|
14
|
-
const handlersGenerator = (0, _kubb_core.defineGenerator)({
|
|
15
|
-
name: "plugin-msw",
|
|
16
|
-
operations(nodes, ctx) {
|
|
17
|
-
const { resolver, config, root } = ctx;
|
|
18
|
-
const { output, group } = ctx.options;
|
|
19
|
-
const handlersName = resolver.resolveHandlersName();
|
|
20
|
-
const file = resolver.resolveFile({
|
|
21
|
-
name: resolver.resolvePathName(handlersName, "file"),
|
|
22
|
-
extname: ".ts"
|
|
23
|
-
}, {
|
|
24
|
-
root,
|
|
25
|
-
output,
|
|
26
|
-
group: group ?? void 0
|
|
27
|
-
});
|
|
28
|
-
const imports = nodes.map((node) => {
|
|
29
|
-
const operationName = resolver.resolveHandlerName(node);
|
|
30
|
-
const operationFile = resolver.resolveFile({
|
|
31
|
-
name: resolver.resolveName(node.operationId),
|
|
32
|
-
extname: ".ts",
|
|
33
|
-
tag: node.tags[0] ?? "default",
|
|
34
|
-
path: node.path
|
|
35
|
-
}, {
|
|
36
|
-
root,
|
|
37
|
-
output,
|
|
38
|
-
group: group ?? void 0
|
|
39
|
-
});
|
|
40
|
-
return _kubb_core.ast.createImport({
|
|
41
|
-
name: [operationName],
|
|
42
|
-
root: file.path,
|
|
43
|
-
path: operationFile.path
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
const handlers = nodes.map((node) => `${resolver.resolveHandlerName(node)}()`);
|
|
47
|
-
return [_kubb_core.ast.createFile({
|
|
48
|
-
baseName: file.baseName,
|
|
49
|
-
path: file.path,
|
|
50
|
-
meta: file.meta,
|
|
51
|
-
banner: resolver.resolveBanner(ctx.meta, {
|
|
52
|
-
output,
|
|
53
|
-
config,
|
|
54
|
-
file: {
|
|
55
|
-
path: file.path,
|
|
56
|
-
baseName: file.baseName
|
|
57
|
-
}
|
|
58
|
-
}),
|
|
59
|
-
footer: resolver.resolveFooter(ctx.meta, {
|
|
60
|
-
output,
|
|
61
|
-
config,
|
|
62
|
-
file: {
|
|
63
|
-
path: file.path,
|
|
64
|
-
baseName: file.baseName
|
|
65
|
-
}
|
|
66
|
-
}),
|
|
67
|
-
imports,
|
|
68
|
-
sources: [_kubb_core.ast.createSource({
|
|
69
|
-
name: handlersName,
|
|
70
|
-
isIndexable: true,
|
|
71
|
-
isExportable: true,
|
|
72
|
-
nodes: [_kubb_core.ast.createText(`export const ${handlersName} = ${JSON.stringify(handlers).replaceAll("\"", "")} as const`)]
|
|
73
|
-
})]
|
|
74
|
-
})];
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
//#endregion
|
|
78
|
-
//#region src/generators/mswGenerator.tsx
|
|
79
|
-
/**
|
|
80
|
-
* Built-in operation generator for `@kubb/plugin-msw`. Emits one MSW handler
|
|
81
|
-
* per OpenAPI operation. With `parser: 'faker'` the handler returns a value
|
|
82
|
-
* from `@kubb/plugin-faker`; with `parser: 'data'` it returns a typed empty
|
|
83
|
-
* payload for tests to fill in.
|
|
84
|
-
*/
|
|
85
|
-
const mswGenerator = (0, _kubb_core.defineGenerator)({
|
|
86
|
-
name: "msw",
|
|
87
|
-
renderer: _kubb_renderer_jsx.jsxRenderer,
|
|
88
|
-
operation(node, ctx) {
|
|
89
|
-
if (!_kubb_core.ast.isHttpOperationNode(node)) return null;
|
|
90
|
-
const { driver, resolver, config, root } = ctx;
|
|
91
|
-
const { output, parser, baseURL, group } = ctx.options;
|
|
92
|
-
const fileName = resolver.resolveName(node.operationId);
|
|
93
|
-
const mock = {
|
|
94
|
-
name: resolver.resolveHandlerName(node),
|
|
95
|
-
file: resolver.resolveFile({
|
|
96
|
-
name: fileName,
|
|
97
|
-
extname: ".ts",
|
|
98
|
-
tag: node.tags[0] ?? "default",
|
|
99
|
-
path: node.path
|
|
100
|
-
}, {
|
|
101
|
-
root,
|
|
102
|
-
output,
|
|
103
|
-
group: group ?? void 0
|
|
104
|
-
})
|
|
105
|
-
};
|
|
106
|
-
const fakerPlugin = parser === "faker" ? driver.getPlugin(_kubb_plugin_faker.pluginFakerName) : null;
|
|
107
|
-
const faker = parser === "faker" && fakerPlugin ? require_components.resolveFakerMeta(node, {
|
|
108
|
-
root,
|
|
109
|
-
fakerResolver: driver.getResolver(_kubb_plugin_faker.pluginFakerName),
|
|
110
|
-
fakerOutput: fakerPlugin.options?.output ?? output,
|
|
111
|
-
fakerGroup: fakerPlugin.options?.group ?? null
|
|
112
|
-
}) : null;
|
|
113
|
-
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
114
|
-
if (!pluginTs) return null;
|
|
115
|
-
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
116
|
-
const type = {
|
|
117
|
-
file: tsResolver.resolveFile({
|
|
118
|
-
name: node.operationId,
|
|
119
|
-
extname: ".ts",
|
|
120
|
-
tag: node.tags[0] ?? "default",
|
|
121
|
-
path: node.path
|
|
122
|
-
}, {
|
|
123
|
-
root,
|
|
124
|
-
output: pluginTs.options?.output ?? output,
|
|
125
|
-
group: pluginTs.options?.group ?? void 0
|
|
126
|
-
}),
|
|
127
|
-
responseName: tsResolver.resolveResponseName(node)
|
|
128
|
-
};
|
|
129
|
-
const types = require_components.resolveResponseTypes(node, tsResolver);
|
|
130
|
-
const hasSuccessSchema = require_components.getOperationSuccessResponses(node).some((response) => !!response.content?.[0]?.schema);
|
|
131
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : null;
|
|
132
|
-
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
133
|
-
baseName: mock.file.baseName,
|
|
134
|
-
path: mock.file.path,
|
|
135
|
-
meta: mock.file.meta,
|
|
136
|
-
banner: resolver.resolveBanner(ctx.meta, {
|
|
137
|
-
output,
|
|
138
|
-
config,
|
|
139
|
-
file: {
|
|
140
|
-
path: mock.file.path,
|
|
141
|
-
baseName: mock.file.baseName
|
|
142
|
-
}
|
|
143
|
-
}),
|
|
144
|
-
footer: resolver.resolveFooter(ctx.meta, {
|
|
145
|
-
output,
|
|
146
|
-
config,
|
|
147
|
-
file: {
|
|
148
|
-
path: mock.file.path,
|
|
149
|
-
baseName: mock.file.baseName
|
|
150
|
-
}
|
|
151
|
-
}),
|
|
152
|
-
children: [
|
|
153
|
-
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
154
|
-
name: ["http"],
|
|
155
|
-
path: "msw"
|
|
156
|
-
}),
|
|
157
|
-
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
158
|
-
name: ["HttpResponseResolver"],
|
|
159
|
-
isTypeOnly: true,
|
|
160
|
-
path: "msw"
|
|
161
|
-
}),
|
|
162
|
-
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
163
|
-
name: Array.from(new Set([
|
|
164
|
-
type.responseName,
|
|
165
|
-
...types.map((t) => t[1]),
|
|
166
|
-
...requestName ? [requestName] : []
|
|
167
|
-
])),
|
|
168
|
-
path: type.file.path,
|
|
169
|
-
root: mock.file.path,
|
|
170
|
-
isTypeOnly: true
|
|
171
|
-
}),
|
|
172
|
-
parser === "faker" && faker && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
173
|
-
name: [faker.name],
|
|
174
|
-
root: mock.file.path,
|
|
175
|
-
path: faker.file.path
|
|
176
|
-
}),
|
|
177
|
-
types.filter(([code]) => code !== "default").map(([code, typeName]) => {
|
|
178
|
-
const response = node.responses.find((item) => item.statusCode === String(code));
|
|
179
|
-
if (!response) return null;
|
|
180
|
-
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(require_components.Response, {
|
|
181
|
-
typeName,
|
|
182
|
-
response,
|
|
183
|
-
name: mock.name
|
|
184
|
-
}, typeName);
|
|
185
|
-
}),
|
|
186
|
-
parser === "faker" && faker && hasSuccessSchema ? /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(require_components.MockWithFaker, {
|
|
187
|
-
name: mock.name,
|
|
188
|
-
typeName: type.responseName,
|
|
189
|
-
requestTypeName: requestName,
|
|
190
|
-
fakerName: faker.name,
|
|
191
|
-
node,
|
|
192
|
-
baseURL
|
|
193
|
-
}) : /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(require_components.Mock, {
|
|
194
|
-
name: mock.name,
|
|
195
|
-
typeName: type.responseName,
|
|
196
|
-
requestTypeName: requestName,
|
|
197
|
-
node,
|
|
198
|
-
baseURL
|
|
199
|
-
})
|
|
200
|
-
]
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
//#endregion
|
|
205
|
-
Object.defineProperty(exports, "handlersGenerator", {
|
|
206
|
-
enumerable: true,
|
|
207
|
-
get: function() {
|
|
208
|
-
return handlersGenerator;
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
Object.defineProperty(exports, "mswGenerator", {
|
|
212
|
-
enumerable: true,
|
|
213
|
-
get: function() {
|
|
214
|
-
return mswGenerator;
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
//# sourceMappingURL=generators-d22_s2UN.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-d22_s2UN.cjs","names":["ast","jsxRenderer","ast","pluginFakerName","resolveFakerMeta","pluginTsName","resolveResponseTypes","getOperationSuccessResponses","File","Response","MockWithFaker","Mock"],"sources":["../src/generators/handlersGenerator.ts","../src/generators/mswGenerator.tsx"],"sourcesContent":["import { ast, defineGenerator } from '@kubb/core'\nimport type { PluginMsw } from '../types'\n\n/**\n * Aggregate generator enabled by `pluginMsw({ handlers: true })`. Emits a\n * `handlers.ts` file that re-exports every generated handler grouped by HTTP\n * method, ready to spread into `setupServer(...handlers)` or\n * `setupWorker(...handlers)`.\n */\nexport const handlersGenerator = defineGenerator<PluginMsw>({\n name: 'plugin-msw',\n operations(nodes, ctx) {\n const { resolver, config, root } = ctx\n const { output, group } = ctx.options\n\n const handlersName = resolver.resolveHandlersName()\n const file = resolver.resolveFile({ name: resolver.resolvePathName(handlersName, 'file'), extname: '.ts' }, { root, output, group: group ?? undefined })\n\n const imports = nodes.map((node) => {\n const operationName = resolver.resolveHandlerName(node)\n const operationFile = resolver.resolveFile(\n { name: resolver.resolveName(node.operationId), extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },\n { root, output, group: group ?? undefined },\n )\n return ast.createImport({ name: [operationName], root: file.path, path: operationFile.path })\n })\n\n const handlers = nodes.map((node) => `${resolver.resolveHandlerName(node)}()`)\n\n return [\n ast.createFile({\n baseName: file.baseName,\n path: file.path,\n meta: file.meta,\n banner: resolver.resolveBanner(ctx.meta, { output, config, file: { path: file.path, baseName: file.baseName } }),\n footer: resolver.resolveFooter(ctx.meta, { output, config, file: { path: file.path, baseName: file.baseName } }),\n imports,\n sources: [\n ast.createSource({\n name: handlersName,\n isIndexable: true,\n isExportable: true,\n nodes: [ast.createText(`export const ${handlersName} = ${JSON.stringify(handlers).replaceAll('\"', '')} as const`)],\n }),\n ],\n }),\n ]\n },\n})\n","import { getOperationSuccessResponses, resolveResponseTypes } from '@internals/shared'\nimport { ast, defineGenerator } from '@kubb/core'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, jsxRenderer } from '@kubb/renderer-jsx'\nimport { Mock, MockWithFaker, Response } from '../components'\nimport type { PluginMsw } from '../types'\nimport { resolveFakerMeta } from '../utils.ts'\n\n/**\n * Built-in operation generator for `@kubb/plugin-msw`. Emits one MSW handler\n * per OpenAPI operation. With `parser: 'faker'` the handler returns a value\n * from `@kubb/plugin-faker`; with `parser: 'data'` it returns a typed empty\n * payload for tests to fill in.\n */\nexport const mswGenerator = defineGenerator<PluginMsw>({\n name: 'msw',\n renderer: jsxRenderer,\n operation(node, ctx) {\n if (!ast.isHttpOperationNode(node)) return null\n const { driver, resolver, config, root } = ctx\n const { output, parser, baseURL, group } = ctx.options\n\n const fileName = resolver.resolveName(node.operationId)\n const mock = {\n name: resolver.resolveHandlerName(node),\n file: resolver.resolveFile(\n { name: fileName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },\n { root, output, group: group ?? undefined },\n ),\n }\n\n const fakerPlugin = parser === 'faker' ? driver.getPlugin(pluginFakerName) : null\n const faker =\n parser === 'faker' && fakerPlugin\n ? resolveFakerMeta(node, {\n root,\n fakerResolver: driver.getResolver(pluginFakerName),\n fakerOutput: fakerPlugin.options?.output ?? output,\n fakerGroup: fakerPlugin.options?.group ?? null,\n })\n : null\n\n const pluginTs = driver.getPlugin(pluginTsName)\n if (!pluginTs) return null\n const tsResolver = driver.getResolver(pluginTsName)\n\n const type = {\n file: tsResolver.resolveFile(\n { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },\n { root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group ?? undefined },\n ),\n responseName: tsResolver.resolveResponseName(node),\n }\n\n const types = resolveResponseTypes(node, tsResolver)\n const successResponses = getOperationSuccessResponses(node)\n const hasSuccessSchema = successResponses.some((response) => !!response.content?.[0]?.schema)\n\n const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : null\n\n return (\n <File\n baseName={mock.file.baseName}\n path={mock.file.path}\n meta={mock.file.meta}\n banner={resolver.resolveBanner(ctx.meta, { output, config, file: { path: mock.file.path, baseName: mock.file.baseName } })}\n footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: mock.file.path, baseName: mock.file.baseName } })}\n >\n <File.Import name={['http']} path=\"msw\" />\n <File.Import name={['HttpResponseResolver']} isTypeOnly path=\"msw\" />\n <File.Import\n name={Array.from(new Set([type.responseName, ...types.map((t) => t[1]), ...(requestName ? [requestName] : [])]))}\n path={type.file.path}\n root={mock.file.path}\n isTypeOnly\n />\n {parser === 'faker' && faker && <File.Import name={[faker.name]} root={mock.file.path} path={faker.file.path} />}\n\n {types\n .filter(([code]) => code !== 'default')\n .map(([code, typeName]) => {\n const response = node.responses.find((item) => item.statusCode === String(code))\n if (!response) return null\n return <Response key={typeName} typeName={typeName} response={response} name={mock.name} />\n })}\n\n {parser === 'faker' && faker && hasSuccessSchema ? (\n <MockWithFaker name={mock.name} typeName={type.responseName} requestTypeName={requestName} fakerName={faker.name} node={node} baseURL={baseURL} />\n ) : (\n <Mock name={mock.name} typeName={type.responseName} requestTypeName={requestName} node={node} baseURL={baseURL} />\n )}\n </File>\n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ACA,WAAW,WAAW,SAAS,iBAAA,GAAA,+BAAA,IAAA,CAACA,mBAAAA,KAAK,QAAN;KAAa,MAAM,CAAC,MAAM,IAAI;KAAG,MAAM,KAAK,KAAK;KAAM,MAAM,MAAM,KAAK;IAAO,CAAA;IAE9G,MACE,QAAQ,CAAC,UAAU,SAAS,SAAS,CAAC,CACtC,KAAK,CAAC,MAAM,cAAc;KACzB,MAAM,WAAW,KAAK,UAAU,MAAM,SAAS,KAAK,eAAe,OAAO,IAAI,CAAC;KAC/E,IAAI,CAAC,UAAU,OAAO;KACtB,OAAO,iBAAA,GAAA,+BAAA,IAAA,CAACC,mBAAAA,UAAD;MAAmC;MAAoB;MAAU,MAAM,KAAK;KAAO,GAApE,QAAoE;IAC5F,CAAC;IAEF,WAAW,WAAW,SAAS,mBAC9B,iBAAA,GAAA,+BAAA,IAAA,CAACC,mBAAAA,eAAD;KAAe,MAAM,KAAK;KAAM,UAAU,KAAK;KAAc,iBAAiB;KAAa,WAAW,MAAM;KAAY;KAAe;IAAU,CAAA,IAEjJ,iBAAA,GAAA,+BAAA,IAAA,CAACC,mBAAAA,MAAD;KAAM,MAAM,KAAK;KAAM,UAAU,KAAK;KAAc,iBAAiB;KAAmB;KAAe;IAAU,CAAA;GAE/G;;CAEV;AACF,CAAC"}
|
package/dist/generators.cjs
DELETED
package/dist/generators.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { t as __name } from "./chunk-C0LytTxp.js";
|
|
2
|
-
import { n as PluginMsw } from "./types-B1yTWOfj.js";
|
|
3
|
-
|
|
4
|
-
//#region src/generators/handlersGenerator.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Aggregate generator enabled by `pluginMsw({ handlers: true })`. Emits a
|
|
7
|
-
* `handlers.ts` file that re-exports every generated handler grouped by HTTP
|
|
8
|
-
* method, ready to spread into `setupServer(...handlers)` or
|
|
9
|
-
* `setupWorker(...handlers)`.
|
|
10
|
-
*/
|
|
11
|
-
declare const handlersGenerator: import("@kubb/core").Generator<PluginMsw, unknown>;
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/generators/mswGenerator.d.ts
|
|
14
|
-
/**
|
|
15
|
-
* Built-in operation generator for `@kubb/plugin-msw`. Emits one MSW handler
|
|
16
|
-
* per OpenAPI operation. With `parser: 'faker'` the handler returns a value
|
|
17
|
-
* from `@kubb/plugin-faker`; with `parser: 'data'` it returns a typed empty
|
|
18
|
-
* payload for tests to fill in.
|
|
19
|
-
*/
|
|
20
|
-
declare const mswGenerator: import("@kubb/core").Generator<PluginMsw, unknown>;
|
|
21
|
-
//#endregion
|
|
22
|
-
export { handlersGenerator, mswGenerator };
|
|
23
|
-
//# sourceMappingURL=generators.d.ts.map
|
package/dist/generators.js
DELETED
package/dist/types-B1yTWOfj.d.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { t as __name } from "./chunk-C0LytTxp.js";
|
|
2
|
-
import { Exclude, Generator, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
|
|
3
|
-
|
|
4
|
-
//#region src/types.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Resolver for MSW that provides naming methods for handler functions.
|
|
7
|
-
*/
|
|
8
|
-
type ResolverMsw = Resolver & {
|
|
9
|
-
/**
|
|
10
|
-
* Resolves the base handler function name for an operation.
|
|
11
|
-
*/
|
|
12
|
-
resolveName(this: ResolverMsw, name: string): string;
|
|
13
|
-
/**
|
|
14
|
-
* Resolves the output file name for an MSW handler module.
|
|
15
|
-
*/
|
|
16
|
-
resolvePathName(this: ResolverMsw, name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
|
|
17
|
-
/**
|
|
18
|
-
* Resolves the handler function name for an operation.
|
|
19
|
-
*/
|
|
20
|
-
resolveHandlerName(this: ResolverMsw, node: ast.OperationNode): string;
|
|
21
|
-
/**
|
|
22
|
-
* Resolves the exported handlers collection name.
|
|
23
|
-
*/
|
|
24
|
-
resolveHandlersName(this: ResolverMsw): string;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Where the generated MSW handlers are written and how they are exported, plus the optional
|
|
28
|
-
* `group` strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
|
|
29
|
-
*
|
|
30
|
-
* @default { path: 'handlers', barrel: { type: 'named' } }
|
|
31
|
-
*/
|
|
32
|
-
type Options = OutputOptions & {
|
|
33
|
-
/**
|
|
34
|
-
* Base URL prepended to every handler's request URL. When omitted, falls back
|
|
35
|
-
* to the adapter's server URL (typically `servers[0].url`).
|
|
36
|
-
*/
|
|
37
|
-
baseURL?: string;
|
|
38
|
-
/**
|
|
39
|
-
* Skip operations matching at least one entry in the list.
|
|
40
|
-
*/
|
|
41
|
-
exclude?: Array<Exclude>;
|
|
42
|
-
/**
|
|
43
|
-
* Restrict generation to operations matching at least one entry in the list.
|
|
44
|
-
*/
|
|
45
|
-
include?: Array<Include>;
|
|
46
|
-
/**
|
|
47
|
-
* Apply a different options object to operations matching a pattern.
|
|
48
|
-
*/
|
|
49
|
-
override?: Array<Override<ResolvedOptions>>;
|
|
50
|
-
/**
|
|
51
|
-
* Override how handler names and file paths are built.
|
|
52
|
-
*/
|
|
53
|
-
resolver?: Partial<ResolverMsw> & ThisType<ResolverMsw>;
|
|
54
|
-
/**
|
|
55
|
-
* AST visitor applied to operation nodes before printing.
|
|
56
|
-
*/
|
|
57
|
-
transformer?: ast.Visitor;
|
|
58
|
-
/**
|
|
59
|
-
* Emit a `handlers.ts` file that re-exports every handler grouped by HTTP method.
|
|
60
|
-
* Drop the file into `setupServer(...handlers)` or `setupWorker(...handlers)`.
|
|
61
|
-
*
|
|
62
|
-
* @default false
|
|
63
|
-
*/
|
|
64
|
-
handlers?: boolean;
|
|
65
|
-
/**
|
|
66
|
-
* Source of the response body returned by each generated handler.
|
|
67
|
-
* - `'data'` — typed empty/example payload, ready for you to fill in from tests.
|
|
68
|
-
* - `'faker'` — value produced by `@kubb/plugin-faker`.
|
|
69
|
-
*
|
|
70
|
-
* @default 'data'
|
|
71
|
-
*/
|
|
72
|
-
parser?: 'data' | 'faker';
|
|
73
|
-
/**
|
|
74
|
-
* Custom generators that run alongside the built-in MSW generators.
|
|
75
|
-
*/
|
|
76
|
-
generators?: Array<Generator<PluginMsw>>;
|
|
77
|
-
};
|
|
78
|
-
type ResolvedOptions = {
|
|
79
|
-
output: Output;
|
|
80
|
-
group: Group | null;
|
|
81
|
-
exclude: NonNullable<Options['exclude']>;
|
|
82
|
-
include: Options['include'];
|
|
83
|
-
override: NonNullable<Options['override']>;
|
|
84
|
-
parser: NonNullable<Options['parser']>;
|
|
85
|
-
baseURL: Options['baseURL'] | undefined;
|
|
86
|
-
handlers: boolean;
|
|
87
|
-
resolver: ResolverMsw;
|
|
88
|
-
};
|
|
89
|
-
type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, ResolverMsw>;
|
|
90
|
-
declare global {
|
|
91
|
-
namespace Kubb {
|
|
92
|
-
interface PluginRegistry {
|
|
93
|
-
'plugin-msw': PluginMsw;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
//#endregion
|
|
98
|
-
export { PluginMsw as n, Options as t };
|
|
99
|
-
//# sourceMappingURL=types-B1yTWOfj.d.ts.map
|
package/src/components/Mock.tsx
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { getPrimarySuccessResponse } from '@internals/shared'
|
|
2
|
-
import { Url } from '@internals/utils'
|
|
3
|
-
import { ast } from '@kubb/core'
|
|
4
|
-
import { functionPrinter } from '@kubb/plugin-ts'
|
|
5
|
-
import { File, Function } from '@kubb/renderer-jsx'
|
|
6
|
-
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
7
|
-
import { getContentType, getMswMethod, getMswUrl, hasResponseSchema } from '../utils.ts'
|
|
8
|
-
|
|
9
|
-
type Props = {
|
|
10
|
-
name: string
|
|
11
|
-
typeName: string
|
|
12
|
-
requestTypeName?: string | null
|
|
13
|
-
baseURL: string | null | undefined
|
|
14
|
-
node: ast.OperationNode
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const declarationPrinter = functionPrinter({ mode: 'declaration' })
|
|
18
|
-
|
|
19
|
-
export function Mock({ baseURL = '', name, typeName, requestTypeName, node }: Props): KubbReactNode {
|
|
20
|
-
const method = getMswMethod(node)
|
|
21
|
-
const successResponse = getPrimarySuccessResponse(node)
|
|
22
|
-
const statusCode = successResponse ? Number(successResponse.statusCode) : 200
|
|
23
|
-
const contentType = getContentType(successResponse)
|
|
24
|
-
const url = Url.toPath(getMswUrl(node))
|
|
25
|
-
|
|
26
|
-
const headers = [contentType ? `'Content-Type': '${contentType}'` : null].filter(Boolean)
|
|
27
|
-
const responseHasSchema = hasResponseSchema(successResponse)
|
|
28
|
-
const dataType = responseHasSchema ? typeName : 'string | number | boolean | null | object'
|
|
29
|
-
|
|
30
|
-
const callbackType = requestTypeName
|
|
31
|
-
? `HttpResponseResolver<Record<string, string>, ${requestTypeName}, any>`
|
|
32
|
-
: `((info: Parameters<Parameters<typeof http.${method}>[1]>[0]) => Response | Promise<Response>)`
|
|
33
|
-
|
|
34
|
-
const params = declarationPrinter.print(
|
|
35
|
-
ast.createFunctionParameters({
|
|
36
|
-
params: [
|
|
37
|
-
ast.createFunctionParameter({
|
|
38
|
-
name: 'data',
|
|
39
|
-
type: ast.createParamsType({
|
|
40
|
-
variant: 'reference',
|
|
41
|
-
name: `${dataType} | ${callbackType}`,
|
|
42
|
-
}),
|
|
43
|
-
optional: true,
|
|
44
|
-
}),
|
|
45
|
-
],
|
|
46
|
-
}),
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
const httpCall = requestTypeName ? `http.${method}<Record<string, string>, ${requestTypeName}, any>` : `http.${method}`
|
|
50
|
-
|
|
51
|
-
return (
|
|
52
|
-
<File.Source name={name} isIndexable isExportable>
|
|
53
|
-
<Function name={name} export params={params ?? ''}>
|
|
54
|
-
{`return ${httpCall}(\`${baseURL}${url.replace(/([^/]):/g, '$1\\\\:')}\`, function handler(info) {
|
|
55
|
-
if(typeof data === 'function') return data(info)
|
|
56
|
-
|
|
57
|
-
return new Response(JSON.stringify(data), {
|
|
58
|
-
status: ${statusCode},
|
|
59
|
-
${
|
|
60
|
-
headers.length
|
|
61
|
-
? ` headers: {
|
|
62
|
-
${headers.join(', \n')}
|
|
63
|
-
},`
|
|
64
|
-
: ''
|
|
65
|
-
}
|
|
66
|
-
})
|
|
67
|
-
})`}
|
|
68
|
-
</Function>
|
|
69
|
-
</File.Source>
|
|
70
|
-
)
|
|
71
|
-
}
|