@kubb/plugin-msw 5.0.0-beta.22 → 5.0.0-beta.27
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-BQv-JnBv.js → components-D8UgWjR8.js} +14 -14
- package/dist/components-D8UgWjR8.js.map +1 -0
- package/dist/{components-DxxXQcZO.cjs → components-DXKC32x5.cjs} +14 -14
- package/dist/components-DXKC32x5.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +3 -3
- package/dist/components.js +1 -1
- package/dist/{generators-JuFqhHYm.js → generators-CTUQF3uN.js} +22 -10
- package/dist/generators-CTUQF3uN.js.map +1 -0
- package/dist/{generators-BiUgbvwT.cjs → generators-Cm9ZuAL1.cjs} +22 -10
- package/dist/generators-Cm9ZuAL1.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +13 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +43 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +31 -1
- package/dist/index.js +43 -6
- package/dist/index.js.map +1 -1
- package/dist/{types-ItsHsMvC.d.ts → types-CLAiv8qc.d.ts} +22 -13
- package/extension.yaml +504 -74
- package/package.json +8 -8
- package/src/components/Handlers.tsx +1 -1
- package/src/components/Mock.tsx +2 -2
- package/src/components/MockWithFaker.tsx +2 -2
- package/src/components/Response.tsx +1 -1
- package/src/generators/handlersGenerator.tsx +8 -2
- package/src/generators/mswGenerator.tsx +15 -6
- package/src/plugin.ts +32 -2
- package/src/resolvers/resolverMsw.ts +9 -2
- package/src/types.ts +21 -12
- package/src/utils.ts +9 -6
- package/dist/components-BQv-JnBv.js.map +0 -1
- package/dist/components-DxxXQcZO.cjs.map +0 -1
- package/dist/generators-BiUgbvwT.cjs.map +0 -1
- package/dist/generators-JuFqhHYm.js.map +0 -1
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
const require_components = require("./components-
|
|
1
|
+
const require_components = require("./components-DXKC32x5.cjs");
|
|
2
2
|
let _kubb_core = require("@kubb/core");
|
|
3
3
|
let _kubb_plugin_faker = require("@kubb/plugin-faker");
|
|
4
4
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
5
5
|
let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
|
|
6
6
|
let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
|
|
7
7
|
//#region src/generators/handlersGenerator.tsx
|
|
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
|
+
*/
|
|
8
14
|
const handlersGenerator = (0, _kubb_core.defineGenerator)({
|
|
9
15
|
name: "plugin-msw",
|
|
10
16
|
renderer: _kubb_renderer_jsx.jsxRendererSync,
|
|
@@ -18,7 +24,7 @@ const handlersGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
18
24
|
}, {
|
|
19
25
|
root,
|
|
20
26
|
output,
|
|
21
|
-
group
|
|
27
|
+
group: group ?? void 0
|
|
22
28
|
});
|
|
23
29
|
const imports = nodes.map((node) => {
|
|
24
30
|
const operationName = resolver.resolveHandlerName(node);
|
|
@@ -30,7 +36,7 @@ const handlersGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
30
36
|
}, {
|
|
31
37
|
root,
|
|
32
38
|
output,
|
|
33
|
-
group
|
|
39
|
+
group: group ?? void 0
|
|
34
40
|
});
|
|
35
41
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
36
42
|
name: [operationName],
|
|
@@ -60,6 +66,12 @@ const handlersGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
60
66
|
});
|
|
61
67
|
//#endregion
|
|
62
68
|
//#region src/generators/mswGenerator.tsx
|
|
69
|
+
/**
|
|
70
|
+
* Built-in operation generator for `@kubb/plugin-msw`. Emits one MSW handler
|
|
71
|
+
* per OpenAPI operation. With `parser: 'faker'` the handler returns a value
|
|
72
|
+
* from `@kubb/plugin-faker`; with `parser: 'data'` it returns a typed empty
|
|
73
|
+
* payload for tests to fill in.
|
|
74
|
+
*/
|
|
63
75
|
const mswGenerator = (0, _kubb_core.defineGenerator)({
|
|
64
76
|
name: "msw",
|
|
65
77
|
renderer: _kubb_renderer_jsx.jsxRendererSync,
|
|
@@ -77,16 +89,16 @@ const mswGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
77
89
|
}, {
|
|
78
90
|
root,
|
|
79
91
|
output,
|
|
80
|
-
group
|
|
92
|
+
group: group ?? void 0
|
|
81
93
|
})
|
|
82
94
|
};
|
|
83
|
-
const fakerPlugin = parser === "faker" ? driver.getPlugin(_kubb_plugin_faker.pluginFakerName) :
|
|
95
|
+
const fakerPlugin = parser === "faker" ? driver.getPlugin(_kubb_plugin_faker.pluginFakerName) : null;
|
|
84
96
|
const faker = parser === "faker" && fakerPlugin ? require_components.resolveFakerMeta(node, {
|
|
85
97
|
root,
|
|
86
98
|
fakerResolver: driver.getResolver(_kubb_plugin_faker.pluginFakerName),
|
|
87
99
|
fakerOutput: fakerPlugin.options?.output ?? output,
|
|
88
|
-
fakerGroup: fakerPlugin.options?.group
|
|
89
|
-
}) :
|
|
100
|
+
fakerGroup: fakerPlugin.options?.group ?? null
|
|
101
|
+
}) : null;
|
|
90
102
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
91
103
|
if (!pluginTs) return null;
|
|
92
104
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
@@ -99,13 +111,13 @@ const mswGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
99
111
|
}, {
|
|
100
112
|
root,
|
|
101
113
|
output: pluginTs.options?.output ?? output,
|
|
102
|
-
group: pluginTs.options?.group
|
|
114
|
+
group: pluginTs.options?.group ?? void 0
|
|
103
115
|
}),
|
|
104
116
|
responseName: tsResolver.resolveResponseName(node)
|
|
105
117
|
};
|
|
106
118
|
const types = require_components.resolveResponseTypes(node, tsResolver);
|
|
107
119
|
const hasSuccessSchema = require_components.getOperationSuccessResponses(node).some((response) => !!response.schema);
|
|
108
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) :
|
|
120
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : null;
|
|
109
121
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
110
122
|
baseName: mock.file.baseName,
|
|
111
123
|
path: mock.file.path,
|
|
@@ -184,4 +196,4 @@ Object.defineProperty(exports, "mswGenerator", {
|
|
|
184
196
|
}
|
|
185
197
|
});
|
|
186
198
|
|
|
187
|
-
//# sourceMappingURL=generators-
|
|
199
|
+
//# sourceMappingURL=generators-Cm9ZuAL1.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-Cm9ZuAL1.cjs","names":["jsxRendererSync","File","Handlers","jsxRendererSync","pluginFakerName","resolveFakerMeta","pluginTsName","resolveResponseTypes","getOperationSuccessResponses","File","Response","MockWithFaker","Mock"],"sources":["../src/generators/handlersGenerator.tsx","../src/generators/mswGenerator.tsx"],"sourcesContent":["import { defineGenerator } from '@kubb/core'\nimport { File, jsxRendererSync } from '@kubb/renderer-jsx'\nimport { Handlers } from '../components/Handlers.tsx'\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 renderer: jsxRendererSync,\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\n return <File.Import key={operationFile.path} name={[operationName]} root={file.path} path={operationFile.path} />\n })\n\n const handlers = nodes.map((node) => `${resolver.resolveHandlerName(node)}()`)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={resolver.resolveBanner(ctx.meta, { output, config })}\n footer={resolver.resolveFooter(ctx.meta, { output, config })}\n >\n {imports}\n <Handlers name={handlersName} handlers={handlers} />\n </File>\n )\n },\n})\n","import { getOperationSuccessResponses, resolveResponseTypes } from '@internals/shared'\nimport { defineGenerator } from '@kubb/core'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, jsxRendererSync } 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: jsxRendererSync,\n operation(node, ctx) {\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.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 })}\n footer={resolver.resolveFooter(ctx.meta, { output, config })}\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.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C,mBAAAA,UAAD;MAAmC;MAAoB;MAAU,MAAM,KAAK;MAAQ,EAArE,SAAqE;MAC3F;IAEH,WAAW,WAAW,SAAS,mBAC9B,iBAAA,GAAA,+BAAA,KAACC,mBAAAA,eAAD;KAAe,MAAM,KAAK;KAAM,UAAU,KAAK;KAAc,iBAAiB;KAAa,WAAW,MAAM;KAAY;KAAe;KAAW,CAAA,GAElJ,iBAAA,GAAA,+BAAA,KAACC,mBAAAA,MAAD;KAAM,MAAM,KAAK;KAAM,UAAU,KAAK;KAAc,iBAAiB;KAAmB;KAAe;KAAW,CAAA;IAE/G;;;CAGZ,CAAC"}
|
package/dist/generators.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_generators = require("./generators-
|
|
2
|
+
const require_generators = require("./generators-Cm9ZuAL1.cjs");
|
|
3
3
|
exports.handlersGenerator = require_generators.handlersGenerator;
|
|
4
4
|
exports.mswGenerator = require_generators.mswGenerator;
|
package/dist/generators.d.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { n as PluginMsw } from "./types-
|
|
2
|
+
import { n as PluginMsw } from "./types-CLAiv8qc.js";
|
|
3
3
|
import * as _$_kubb_core0 from "@kubb/core";
|
|
4
4
|
|
|
5
5
|
//#region src/generators/handlersGenerator.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Aggregate generator enabled by `pluginMsw({ handlers: true })`. Emits a
|
|
8
|
+
* `handlers.ts` file that re-exports every generated handler grouped by HTTP
|
|
9
|
+
* method, ready to spread into `setupServer(...handlers)` or
|
|
10
|
+
* `setupWorker(...handlers)`.
|
|
11
|
+
*/
|
|
6
12
|
declare const handlersGenerator: _$_kubb_core0.Generator<PluginMsw, unknown>;
|
|
7
13
|
//#endregion
|
|
8
14
|
//#region src/generators/mswGenerator.d.ts
|
|
15
|
+
/**
|
|
16
|
+
* Built-in operation generator for `@kubb/plugin-msw`. Emits one MSW handler
|
|
17
|
+
* per OpenAPI operation. With `parser: 'faker'` the handler returns a value
|
|
18
|
+
* from `@kubb/plugin-faker`; with `parser: 'data'` it returns a typed empty
|
|
19
|
+
* payload for tests to fill in.
|
|
20
|
+
*/
|
|
9
21
|
declare const mswGenerator: _$_kubb_core0.Generator<PluginMsw, unknown>;
|
|
10
22
|
//#endregion
|
|
11
23
|
export { handlersGenerator, mswGenerator };
|
package/dist/generators.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as handlersGenerator, t as mswGenerator } from "./generators-
|
|
1
|
+
import { n as handlersGenerator, t as mswGenerator } from "./generators-CTUQF3uN.js";
|
|
2
2
|
export { handlersGenerator, mswGenerator };
|
package/dist/index.cjs
CHANGED
|
@@ -2,16 +2,23 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_components = require("./components-
|
|
6
|
-
const require_generators = require("./generators-
|
|
5
|
+
const require_components = require("./components-DXKC32x5.cjs");
|
|
6
|
+
const require_generators = require("./generators-Cm9ZuAL1.cjs");
|
|
7
7
|
let _kubb_core = require("@kubb/core");
|
|
8
8
|
let _kubb_plugin_faker = require("@kubb/plugin-faker");
|
|
9
9
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
10
10
|
//#region src/resolvers/resolverMsw.ts
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Default resolver used by `@kubb/plugin-msw`. Decides the names and file
|
|
13
|
+
* paths for every generated MSW handler. Function names get a `Handler`
|
|
14
|
+
* suffix; the aggregate export is always `handlers`.
|
|
13
15
|
*
|
|
14
|
-
*
|
|
16
|
+
* @example Resolve a handler name
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { resolverMsw } from '@kubb/plugin-msw'
|
|
19
|
+
*
|
|
20
|
+
* resolverMsw.resolveName('addPet') // 'addPetHandler'
|
|
21
|
+
* ```
|
|
15
22
|
*/
|
|
16
23
|
const resolverMsw = (0, _kubb_core.defineResolver)(() => ({
|
|
17
24
|
name: "default",
|
|
@@ -34,7 +41,37 @@ const resolverMsw = (0, _kubb_core.defineResolver)(() => ({
|
|
|
34
41
|
}));
|
|
35
42
|
//#endregion
|
|
36
43
|
//#region src/plugin.ts
|
|
44
|
+
/**
|
|
45
|
+
* Canonical plugin name for `@kubb/plugin-msw`. Used for driver lookups and
|
|
46
|
+
* cross-plugin dependency references.
|
|
47
|
+
*/
|
|
37
48
|
const pluginMswName = "plugin-msw";
|
|
49
|
+
/**
|
|
50
|
+
* Generates MSW request handlers from an OpenAPI spec. Drop them into your
|
|
51
|
+
* test setup or service worker to mock the API end-to-end. Request path,
|
|
52
|
+
* method, status, and response body all stay in sync with the spec. Combine
|
|
53
|
+
* with `@kubb/plugin-faker` (via `parser: 'faker'`) to seed handlers with
|
|
54
|
+
* realistic data.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { defineConfig } from 'kubb'
|
|
59
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
60
|
+
* import { pluginMsw } from '@kubb/plugin-msw'
|
|
61
|
+
*
|
|
62
|
+
* export default defineConfig({
|
|
63
|
+
* input: { path: './petStore.yaml' },
|
|
64
|
+
* output: { path: './src/gen' },
|
|
65
|
+
* plugins: [
|
|
66
|
+
* pluginTs(),
|
|
67
|
+
* pluginMsw({
|
|
68
|
+
* output: { path: './handlers' },
|
|
69
|
+
* handlers: true,
|
|
70
|
+
* }),
|
|
71
|
+
* ],
|
|
72
|
+
* })
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
38
75
|
const pluginMsw = (0, _kubb_core.definePlugin)((options) => {
|
|
39
76
|
const { output = {
|
|
40
77
|
path: "handlers",
|
|
@@ -46,11 +83,11 @@ const pluginMsw = (0, _kubb_core.definePlugin)((options) => {
|
|
|
46
83
|
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
47
84
|
return `${require_components.camelCase(ctx.group)}Controller`;
|
|
48
85
|
}
|
|
49
|
-
} :
|
|
86
|
+
} : null;
|
|
50
87
|
return {
|
|
51
88
|
name: pluginMswName,
|
|
52
89
|
options,
|
|
53
|
-
dependencies: [_kubb_plugin_ts.pluginTsName, parser === "faker" ? _kubb_plugin_faker.pluginFakerName :
|
|
90
|
+
dependencies: [_kubb_plugin_ts.pluginTsName, parser === "faker" ? _kubb_plugin_faker.pluginFakerName : null].filter((dependency) => Boolean(dependency)),
|
|
54
91
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
55
92
|
const resolver = userResolver ? {
|
|
56
93
|
...resolverMsw,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["camelCase","camelCase","pluginTsName","pluginFakerName","mswGenerator","handlersGenerator"],"sources":["../src/resolvers/resolverMsw.ts","../src/plugin.ts"],"sourcesContent":["import { camelCase } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginMsw } from '../types.ts'\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["camelCase","camelCase","pluginTsName","pluginFakerName","mswGenerator","handlersGenerator"],"sources":["../src/resolvers/resolverMsw.ts","../src/plugin.ts"],"sourcesContent":["import { camelCase } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginMsw } from '../types.ts'\n\n/**\n * Default resolver used by `@kubb/plugin-msw`. Decides the names and file\n * paths for every generated MSW handler. Function names get a `Handler`\n * suffix; the aggregate export is always `handlers`.\n *\n * @example Resolve a handler name\n * ```ts\n * import { resolverMsw } from '@kubb/plugin-msw'\n *\n * resolverMsw.resolveName('addPet') // 'addPetHandler'\n * ```\n */\nexport const resolverMsw = defineResolver<PluginMsw>(() => ({\n name: 'default',\n pluginName: 'plugin-msw',\n default(name, type) {\n return camelCase(name, { isFile: type === 'file' })\n },\n resolveName(name) {\n return camelCase(name, { suffix: 'handler' })\n },\n resolvePathName(name, type) {\n return this.default(name, type)\n },\n resolveHandlerName(node) {\n return this.resolveName(node.operationId)\n },\n resolveHandlersName() {\n return 'handlers'\n },\n}))\n","import { camelCase } from '@internals/utils'\nimport { definePlugin, type Group } from '@kubb/core'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport { resolverMsw } from './resolvers/resolverMsw.ts'\nimport type { PluginMsw } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-msw`. Used for driver lookups and\n * cross-plugin dependency references.\n */\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\n/**\n * Generates MSW request handlers from an OpenAPI spec. Drop them into your\n * test setup or service worker to mock the API end-to-end. Request path,\n * method, status, and response body all stay in sync with the spec. Combine\n * with `@kubb/plugin-faker` (via `parser: 'faker'`) to seed handlers with\n * realistic data.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginMsw } from '@kubb/plugin-msw'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginTs(),\n * pluginMsw({\n * output: { path: './handlers' },\n * handlers: true,\n * }),\n * ],\n * })\n * ```\n */\nexport const pluginMsw = definePlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n handlers = false,\n parser = 'data',\n baseURL,\n resolver: userResolver,\n transformer: userTransformer,\n generators: userGenerators = [],\n } = options\n\n const groupConfig = group\n ? ({\n ...group,\n name: group.name\n ? group.name\n : (ctx: { group: string }) => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n },\n } satisfies Group)\n : null\n\n return {\n name: pluginMswName,\n options,\n dependencies: [pluginTsName, parser === 'faker' ? pluginFakerName : null].filter((dependency): dependency is string => Boolean(dependency)),\n hooks: {\n 'kubb:plugin:setup'(ctx) {\n const resolver = userResolver ? { ...resolverMsw, ...userResolver } : resolverMsw\n\n ctx.setOptions({\n output,\n parser,\n baseURL,\n group: groupConfig,\n exclude,\n include,\n override,\n handlers,\n resolver,\n })\n ctx.setResolver(resolver)\n if (userTransformer) {\n ctx.setTransformer(userTransformer)\n }\n\n ctx.addGenerator(mswGenerator)\n if (handlers) {\n ctx.addGenerator(handlersGenerator)\n }\n for (const gen of userGenerators) {\n ctx.addGenerator(gen)\n }\n },\n },\n }\n})\n\nexport default pluginMsw\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAa,eAAA,GAAA,WAAA,uBAA+C;CAC1D,MAAM;CACN,YAAY;CACZ,QAAQ,MAAM,MAAM;EAClB,OAAOA,mBAAAA,UAAU,MAAM,EAAE,QAAQ,SAAS,QAAQ,CAAC;;CAErD,YAAY,MAAM;EAChB,OAAOA,mBAAAA,UAAU,MAAM,EAAE,QAAQ,WAAW,CAAC;;CAE/C,gBAAgB,MAAM,MAAM;EAC1B,OAAO,KAAK,QAAQ,MAAM,KAAK;;CAEjC,mBAAmB,MAAM;EACvB,OAAO,KAAK,YAAY,KAAK,YAAY;;CAE3C,sBAAsB;EACpB,OAAO;;CAEV,EAAE;;;;;;;ACtBH,MAAa,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4B7B,MAAa,aAAA,GAAA,WAAA,eAAqC,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAY,YAAY;EAAS,EAClD,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,WAAW,OACX,SAAS,QACT,SACA,UAAU,cACV,aAAa,iBACb,YAAY,iBAAiB,EAAE,KAC7B;CAEJ,MAAM,cAAc,QACf;EACC,GAAG;EACH,MAAM,MAAM,OACR,MAAM,QACL,QAA2B;GAC1B,IAAI,MAAM,SAAS,QACjB,OAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;GAEjC,OAAO,GAAGC,mBAAAA,UAAU,IAAI,MAAM,CAAC;;EAEtC,GACD;CAEJ,OAAO;EACL,MAAM;EACN;EACA,cAAc,CAACC,gBAAAA,cAAc,WAAW,UAAUC,mBAAAA,kBAAkB,KAAK,CAAC,QAAQ,eAAqC,QAAQ,WAAW,CAAC;EAC3I,OAAO,EACL,oBAAoB,KAAK;GACvB,MAAM,WAAW,eAAe;IAAE,GAAG;IAAa,GAAG;IAAc,GAAG;GAEtE,IAAI,WAAW;IACb;IACA;IACA;IACA,OAAO;IACP;IACA;IACA;IACA;IACA;IACD,CAAC;GACF,IAAI,YAAY,SAAS;GACzB,IAAI,iBACF,IAAI,eAAe,gBAAgB;GAGrC,IAAI,aAAaC,mBAAAA,aAAa;GAC9B,IAAI,UACF,IAAI,aAAaC,mBAAAA,kBAAkB;GAErC,KAAK,MAAM,OAAO,gBAChB,IAAI,aAAa,IAAI;KAG1B;EACF;EACD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,39 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { n as PluginMsw, t as Options } from "./types-
|
|
2
|
+
import { n as PluginMsw, t as Options } from "./types-CLAiv8qc.js";
|
|
3
3
|
import * as _$_kubb_core0 from "@kubb/core";
|
|
4
4
|
|
|
5
5
|
//#region src/plugin.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Canonical plugin name for `@kubb/plugin-msw`. Used for driver lookups and
|
|
8
|
+
* cross-plugin dependency references.
|
|
9
|
+
*/
|
|
6
10
|
declare const pluginMswName = "plugin-msw";
|
|
11
|
+
/**
|
|
12
|
+
* Generates MSW request handlers from an OpenAPI spec. Drop them into your
|
|
13
|
+
* test setup or service worker to mock the API end-to-end. Request path,
|
|
14
|
+
* method, status, and response body all stay in sync with the spec. Combine
|
|
15
|
+
* with `@kubb/plugin-faker` (via `parser: 'faker'`) to seed handlers with
|
|
16
|
+
* realistic data.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { defineConfig } from 'kubb'
|
|
21
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
22
|
+
* import { pluginMsw } from '@kubb/plugin-msw'
|
|
23
|
+
*
|
|
24
|
+
* export default defineConfig({
|
|
25
|
+
* input: { path: './petStore.yaml' },
|
|
26
|
+
* output: { path: './src/gen' },
|
|
27
|
+
* plugins: [
|
|
28
|
+
* pluginTs(),
|
|
29
|
+
* pluginMsw({
|
|
30
|
+
* output: { path: './handlers' },
|
|
31
|
+
* handlers: true,
|
|
32
|
+
* }),
|
|
33
|
+
* ],
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
7
37
|
declare const pluginMsw: (options?: Options | undefined) => _$_kubb_core0.Plugin<PluginMsw>;
|
|
8
38
|
//#endregion
|
|
9
39
|
export { type PluginMsw, pluginMsw as default, pluginMsw, pluginMswName };
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { c as camelCase } from "./components-
|
|
3
|
-
import { n as handlersGenerator, t as mswGenerator } from "./generators-
|
|
2
|
+
import { c as camelCase } from "./components-D8UgWjR8.js";
|
|
3
|
+
import { n as handlersGenerator, t as mswGenerator } from "./generators-CTUQF3uN.js";
|
|
4
4
|
import { definePlugin, defineResolver } from "@kubb/core";
|
|
5
5
|
import { pluginFakerName } from "@kubb/plugin-faker";
|
|
6
6
|
import { pluginTsName } from "@kubb/plugin-ts";
|
|
7
7
|
//#region src/resolvers/resolverMsw.ts
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Default resolver used by `@kubb/plugin-msw`. Decides the names and file
|
|
10
|
+
* paths for every generated MSW handler. Function names get a `Handler`
|
|
11
|
+
* suffix; the aggregate export is always `handlers`.
|
|
10
12
|
*
|
|
11
|
-
*
|
|
13
|
+
* @example Resolve a handler name
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { resolverMsw } from '@kubb/plugin-msw'
|
|
16
|
+
*
|
|
17
|
+
* resolverMsw.resolveName('addPet') // 'addPetHandler'
|
|
18
|
+
* ```
|
|
12
19
|
*/
|
|
13
20
|
const resolverMsw = defineResolver(() => ({
|
|
14
21
|
name: "default",
|
|
@@ -31,7 +38,37 @@ const resolverMsw = defineResolver(() => ({
|
|
|
31
38
|
}));
|
|
32
39
|
//#endregion
|
|
33
40
|
//#region src/plugin.ts
|
|
41
|
+
/**
|
|
42
|
+
* Canonical plugin name for `@kubb/plugin-msw`. Used for driver lookups and
|
|
43
|
+
* cross-plugin dependency references.
|
|
44
|
+
*/
|
|
34
45
|
const pluginMswName = "plugin-msw";
|
|
46
|
+
/**
|
|
47
|
+
* Generates MSW request handlers from an OpenAPI spec. Drop them into your
|
|
48
|
+
* test setup or service worker to mock the API end-to-end. Request path,
|
|
49
|
+
* method, status, and response body all stay in sync with the spec. Combine
|
|
50
|
+
* with `@kubb/plugin-faker` (via `parser: 'faker'`) to seed handlers with
|
|
51
|
+
* realistic data.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { defineConfig } from 'kubb'
|
|
56
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
57
|
+
* import { pluginMsw } from '@kubb/plugin-msw'
|
|
58
|
+
*
|
|
59
|
+
* export default defineConfig({
|
|
60
|
+
* input: { path: './petStore.yaml' },
|
|
61
|
+
* output: { path: './src/gen' },
|
|
62
|
+
* plugins: [
|
|
63
|
+
* pluginTs(),
|
|
64
|
+
* pluginMsw({
|
|
65
|
+
* output: { path: './handlers' },
|
|
66
|
+
* handlers: true,
|
|
67
|
+
* }),
|
|
68
|
+
* ],
|
|
69
|
+
* })
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
35
72
|
const pluginMsw = definePlugin((options) => {
|
|
36
73
|
const { output = {
|
|
37
74
|
path: "handlers",
|
|
@@ -43,11 +80,11 @@ const pluginMsw = definePlugin((options) => {
|
|
|
43
80
|
if (group.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
44
81
|
return `${camelCase(ctx.group)}Controller`;
|
|
45
82
|
}
|
|
46
|
-
} :
|
|
83
|
+
} : null;
|
|
47
84
|
return {
|
|
48
85
|
name: pluginMswName,
|
|
49
86
|
options,
|
|
50
|
-
dependencies: [pluginTsName, parser === "faker" ? pluginFakerName :
|
|
87
|
+
dependencies: [pluginTsName, parser === "faker" ? pluginFakerName : null].filter((dependency) => Boolean(dependency)),
|
|
51
88
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
52
89
|
const resolver = userResolver ? {
|
|
53
90
|
...resolverMsw,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/resolvers/resolverMsw.ts","../src/plugin.ts"],"sourcesContent":["import { camelCase } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginMsw } from '../types.ts'\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/resolvers/resolverMsw.ts","../src/plugin.ts"],"sourcesContent":["import { camelCase } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginMsw } from '../types.ts'\n\n/**\n * Default resolver used by `@kubb/plugin-msw`. Decides the names and file\n * paths for every generated MSW handler. Function names get a `Handler`\n * suffix; the aggregate export is always `handlers`.\n *\n * @example Resolve a handler name\n * ```ts\n * import { resolverMsw } from '@kubb/plugin-msw'\n *\n * resolverMsw.resolveName('addPet') // 'addPetHandler'\n * ```\n */\nexport const resolverMsw = defineResolver<PluginMsw>(() => ({\n name: 'default',\n pluginName: 'plugin-msw',\n default(name, type) {\n return camelCase(name, { isFile: type === 'file' })\n },\n resolveName(name) {\n return camelCase(name, { suffix: 'handler' })\n },\n resolvePathName(name, type) {\n return this.default(name, type)\n },\n resolveHandlerName(node) {\n return this.resolveName(node.operationId)\n },\n resolveHandlersName() {\n return 'handlers'\n },\n}))\n","import { camelCase } from '@internals/utils'\nimport { definePlugin, type Group } from '@kubb/core'\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport { resolverMsw } from './resolvers/resolverMsw.ts'\nimport type { PluginMsw } from './types.ts'\n\n/**\n * Canonical plugin name for `@kubb/plugin-msw`. Used for driver lookups and\n * cross-plugin dependency references.\n */\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\n/**\n * Generates MSW request handlers from an OpenAPI spec. Drop them into your\n * test setup or service worker to mock the API end-to-end. Request path,\n * method, status, and response body all stay in sync with the spec. Combine\n * with `@kubb/plugin-faker` (via `parser: 'faker'`) to seed handlers with\n * realistic data.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n * import { pluginMsw } from '@kubb/plugin-msw'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [\n * pluginTs(),\n * pluginMsw({\n * output: { path: './handlers' },\n * handlers: true,\n * }),\n * ],\n * })\n * ```\n */\nexport const pluginMsw = definePlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n handlers = false,\n parser = 'data',\n baseURL,\n resolver: userResolver,\n transformer: userTransformer,\n generators: userGenerators = [],\n } = options\n\n const groupConfig = group\n ? ({\n ...group,\n name: group.name\n ? group.name\n : (ctx: { group: string }) => {\n if (group.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n },\n } satisfies Group)\n : null\n\n return {\n name: pluginMswName,\n options,\n dependencies: [pluginTsName, parser === 'faker' ? pluginFakerName : null].filter((dependency): dependency is string => Boolean(dependency)),\n hooks: {\n 'kubb:plugin:setup'(ctx) {\n const resolver = userResolver ? { ...resolverMsw, ...userResolver } : resolverMsw\n\n ctx.setOptions({\n output,\n parser,\n baseURL,\n group: groupConfig,\n exclude,\n include,\n override,\n handlers,\n resolver,\n })\n ctx.setResolver(resolver)\n if (userTransformer) {\n ctx.setTransformer(userTransformer)\n }\n\n ctx.addGenerator(mswGenerator)\n if (handlers) {\n ctx.addGenerator(handlersGenerator)\n }\n for (const gen of userGenerators) {\n ctx.addGenerator(gen)\n }\n },\n },\n }\n})\n\nexport default pluginMsw\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAgBA,MAAa,cAAc,sBAAiC;CAC1D,MAAM;CACN,YAAY;CACZ,QAAQ,MAAM,MAAM;EAClB,OAAO,UAAU,MAAM,EAAE,QAAQ,SAAS,QAAQ,CAAC;;CAErD,YAAY,MAAM;EAChB,OAAO,UAAU,MAAM,EAAE,QAAQ,WAAW,CAAC;;CAE/C,gBAAgB,MAAM,MAAM;EAC1B,OAAO,KAAK,QAAQ,MAAM,KAAK;;CAEjC,mBAAmB,MAAM;EACvB,OAAO,KAAK,YAAY,KAAK,YAAY;;CAE3C,sBAAsB;EACpB,OAAO;;CAEV,EAAE;;;;;;;ACtBH,MAAa,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4B7B,MAAa,YAAY,cAAyB,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAY,YAAY;EAAS,EAClD,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,WAAW,OACX,SAAS,QACT,SACA,UAAU,cACV,aAAa,iBACb,YAAY,iBAAiB,EAAE,KAC7B;CAEJ,MAAM,cAAc,QACf;EACC,GAAG;EACH,MAAM,MAAM,OACR,MAAM,QACL,QAA2B;GAC1B,IAAI,MAAM,SAAS,QACjB,OAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;GAEjC,OAAO,GAAG,UAAU,IAAI,MAAM,CAAC;;EAEtC,GACD;CAEJ,OAAO;EACL,MAAM;EACN;EACA,cAAc,CAAC,cAAc,WAAW,UAAU,kBAAkB,KAAK,CAAC,QAAQ,eAAqC,QAAQ,WAAW,CAAC;EAC3I,OAAO,EACL,oBAAoB,KAAK;GACvB,MAAM,WAAW,eAAe;IAAE,GAAG;IAAa,GAAG;IAAc,GAAG;GAEtE,IAAI,WAAW;IACb;IACA;IACA;IACA,OAAO;IACP;IACA;IACA;IACA;IACA;IACD,CAAC;GACF,IAAI,YAAY,SAAS;GACzB,IAAI,iBACF,IAAI,eAAe,gBAAgB;GAGrC,IAAI,aAAa,aAAa;GAC9B,IAAI,UACF,IAAI,aAAa,kBAAkB;GAErC,KAAK,MAAM,OAAO,gBAChB,IAAI,aAAa,IAAI;KAG1B;EACF;EACD"}
|
|
@@ -25,54 +25,63 @@ type ResolverMsw = Resolver & {
|
|
|
25
25
|
};
|
|
26
26
|
type Options = {
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
28
|
+
* Where the generated MSW handlers are written and how they are exported.
|
|
29
|
+
*
|
|
30
|
+
* @default { path: 'handlers', barrel: { type: 'named' } }
|
|
30
31
|
*/
|
|
31
32
|
output?: Output;
|
|
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
|
+
*/
|
|
32
37
|
baseURL?: string;
|
|
33
38
|
/**
|
|
34
|
-
*
|
|
39
|
+
* Split generated files into subfolders based on the operation's tag.
|
|
35
40
|
*/
|
|
36
41
|
group?: Group;
|
|
37
42
|
/**
|
|
38
|
-
*
|
|
43
|
+
* Skip operations matching at least one entry in the list.
|
|
39
44
|
*/
|
|
40
45
|
exclude?: Array<Exclude>;
|
|
41
46
|
/**
|
|
42
|
-
*
|
|
47
|
+
* Restrict generation to operations matching at least one entry in the list.
|
|
43
48
|
*/
|
|
44
49
|
include?: Array<Include>;
|
|
45
50
|
/**
|
|
46
|
-
*
|
|
51
|
+
* Apply a different options object to operations matching a pattern.
|
|
47
52
|
*/
|
|
48
53
|
override?: Array<Override<ResolvedOptions>>;
|
|
49
54
|
/**
|
|
50
|
-
* Override
|
|
55
|
+
* Override how handler names and file paths are built.
|
|
51
56
|
*/
|
|
52
57
|
resolver?: Partial<ResolverMsw> & ThisType<ResolverMsw>;
|
|
53
58
|
/**
|
|
54
|
-
* AST visitor to
|
|
59
|
+
* AST visitor applied to operation nodes before printing.
|
|
55
60
|
*/
|
|
56
61
|
transformer?: ast.Visitor;
|
|
57
62
|
/**
|
|
58
|
-
*
|
|
63
|
+
* Emit a `handlers.ts` file that re-exports every handler grouped by HTTP method.
|
|
64
|
+
* Drop the file into `setupServer(...handlers)` or `setupWorker(...handlers)`.
|
|
65
|
+
*
|
|
59
66
|
* @default false
|
|
60
67
|
*/
|
|
61
68
|
handlers?: boolean;
|
|
62
69
|
/**
|
|
63
|
-
*
|
|
70
|
+
* Source of the response body returned by each generated handler.
|
|
71
|
+
* - `'data'` — typed empty/example payload, ready for you to fill in from tests.
|
|
72
|
+
* - `'faker'` — value produced by `@kubb/plugin-faker`.
|
|
64
73
|
*
|
|
65
74
|
* @default 'data'
|
|
66
75
|
*/
|
|
67
76
|
parser?: 'data' | 'faker';
|
|
68
77
|
/**
|
|
69
|
-
*
|
|
78
|
+
* Custom generators that run alongside the built-in MSW generators.
|
|
70
79
|
*/
|
|
71
80
|
generators?: Array<Generator<PluginMsw>>;
|
|
72
81
|
};
|
|
73
82
|
type ResolvedOptions = {
|
|
74
83
|
output: Output;
|
|
75
|
-
group: Group |
|
|
84
|
+
group: Group | null;
|
|
76
85
|
exclude: NonNullable<Options['exclude']>;
|
|
77
86
|
include: Options['include'];
|
|
78
87
|
override: NonNullable<Options['override']>;
|
|
@@ -91,4 +100,4 @@ declare global {
|
|
|
91
100
|
}
|
|
92
101
|
//#endregion
|
|
93
102
|
export { PluginMsw as n, Options as t };
|
|
94
|
-
//# sourceMappingURL=types-
|
|
103
|
+
//# sourceMappingURL=types-CLAiv8qc.d.ts.map
|