@kubb/plugin-msw 5.1.1 → 5.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -140,11 +140,11 @@ function createGroupConfig(group) {
140
140
  //#region kubb-extension.json
141
141
  var compatibility = {
142
142
  "kubb": ">=5.8.3",
143
- "node": ">=22"
143
+ "node": ">=22.12"
144
144
  };
145
145
  //#endregion
146
146
  //#region package.json
147
- var version = "5.1.1";
147
+ var version = "5.1.3";
148
148
  //#endregion
149
149
  //#region src/generators/handlersGenerator.ts
150
150
  /**
@@ -0,0 +1,141 @@
1
+ import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
2
+ //#region src/types.d.ts
3
+ /**
4
+ * Resolver for MSW that provides naming methods for handler functions.
5
+ */
6
+ type ResolverMsw = Resolver & {
7
+ /**
8
+ * Naming for generated MSW handlers.
9
+ */
10
+ handler: {
11
+ /**
12
+ * Resolves the handler function name for an operation.
13
+ */
14
+ name(node: ast.OperationNode): string;
15
+ /**
16
+ * Resolves the exported handlers collection name.
17
+ */
18
+ listName(): string;
19
+ };
20
+ };
21
+ /**
22
+ * Where the generated MSW handlers are written and how they are exported, plus the optional
23
+ * `group` strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
24
+ *
25
+ * @default { path: 'handlers', barrel: { type: 'named' } }
26
+ */
27
+ type Options = OutputOptions & {
28
+ /**
29
+ * Base URL prepended to every handler's request URL. When omitted, handlers match the
30
+ * operation path only (for example `/pets/:petId`). The adapter's server URL is not used.
31
+ */
32
+ baseURL?: string;
33
+ /**
34
+ * Skip operations matching at least one entry in the list.
35
+ */
36
+ exclude?: Array<Exclude>;
37
+ /**
38
+ * Restrict generation to operations matching at least one entry in the list.
39
+ */
40
+ include?: Array<Include>;
41
+ /**
42
+ * Apply a different options object to operations matching a pattern.
43
+ */
44
+ override?: Array<Override<ResolvedOptions>>;
45
+ /**
46
+ * Override how handler names and file paths are built.
47
+ */
48
+ resolver?: ResolverPatch<ResolverMsw>;
49
+ /**
50
+ * Macros applied to operation nodes before printing.
51
+ */
52
+ macros?: Array<ast.Macro>;
53
+ /**
54
+ * Emit a `handlers.ts` file that re-exports every handler in operation order.
55
+ * Drop the file into `setupServer(...handlers)` or `setupWorker(...handlers)`.
56
+ *
57
+ * @default false
58
+ */
59
+ handlers?: boolean;
60
+ /**
61
+ * Source of the response body returned by each generated handler.
62
+ * - `'data'`: typed empty/example payload, ready for you to fill in from tests.
63
+ * - `'faker'`: value produced by `@kubb/plugin-faker`.
64
+ *
65
+ * @default 'data'
66
+ */
67
+ parser?: 'data' | 'faker';
68
+ };
69
+ type ResolvedOptions = {
70
+ output: Output;
71
+ group: Group | null;
72
+ exclude: NonNullable<Options['exclude']>;
73
+ include: Options['include'];
74
+ override: NonNullable<Options['override']>;
75
+ parser: NonNullable<Options['parser']>;
76
+ baseURL: Options['baseURL'] | undefined;
77
+ handlers: boolean;
78
+ };
79
+ type PluginMsw = PluginType<'plugin-msw', Options, ResolvedOptions, ResolverMsw>;
80
+ declare global {
81
+ namespace Kubb {
82
+ interface PluginRegistry {
83
+ 'plugin-msw': PluginMsw;
84
+ }
85
+ }
86
+ }
87
+ //#endregion
88
+ //#region src/plugin.d.ts
89
+ /**
90
+ * Canonical plugin name for `@kubb/plugin-msw`. Used for driver lookups and
91
+ * cross-plugin dependency references.
92
+ */
93
+ export declare const pluginMswName = "plugin-msw";
94
+ /**
95
+ * Generates MSW request handlers from an OpenAPI spec. Drop them into your
96
+ * test setup or service worker to mock the API end-to-end. Request path,
97
+ * method, status, and response body all stay in sync with the spec. Combine
98
+ * with `@kubb/plugin-faker` (via `parser: 'faker'`) to seed handlers with
99
+ * realistic data.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * import { defineConfig } from 'kubb/config'
104
+ * import { pluginTs } from '@kubb/plugin-ts'
105
+ * import { pluginMsw } from '@kubb/plugin-msw'
106
+ *
107
+ * export default defineConfig({
108
+ * input: './petStore.yaml',
109
+ * output: { path: './src/gen' },
110
+ * plugins: [
111
+ * pluginTs(),
112
+ * pluginMsw({
113
+ * output: { path: './handlers' },
114
+ * handlers: true,
115
+ * }),
116
+ * ],
117
+ * })
118
+ * ```
119
+ */
120
+ export declare const pluginMsw: import("kubb/kit").PluginFactory<PluginMsw>;
121
+ //#endregion
122
+ //#region src/resolvers/resolverMsw.d.ts
123
+ /**
124
+ * Default resolver used by `@kubb/plugin-msw`. Decides the names and file
125
+ * paths for every generated MSW handler. Function names get a `Handler`
126
+ * suffix; the aggregate export is always `handlers`.
127
+ *
128
+ * The top-level `name` applies the `handler` suffix, and `file` falls back to the built-in
129
+ * `toFilePath` casing. Operation-specific naming is grouped under the `handler` namespace.
130
+ *
131
+ * @example Resolve a handler name
132
+ * ```ts
133
+ * import { resolverMsw } from '@kubb/plugin-msw'
134
+ *
135
+ * resolverMsw.name('addPet') // 'addPetHandler'
136
+ * ```
137
+ */
138
+ export declare const resolverMsw: ResolverMsw;
139
+ //#endregion
140
+ export { type PluginMsw, type ResolverMsw, pluginMsw as default };
141
+ //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
1
  import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
3
2
  //#region src/types.d.ts
4
3
  /**
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import "./rolldown-runtime-C0LytTxp.js";
2
1
  import { Resolver, Url, addGenerator, assertPluginOption, ast, createResolver, defineExtension, defineGenerator, setMacros, setResolver } from "kubb/kit";
3
2
  import { pluginFakerName } from "@kubb/plugin-faker";
4
3
  import { enumTypeName, pluginTsName } from "@kubb/plugin-ts";
5
4
  import { File, Function, jsxRenderer } from "kubb/jsx";
6
5
  import { jsx, jsxs } from "kubb/jsx/jsx-runtime";
6
+ //#endregion
7
7
  //#region ../../internals/shared/src/operation.ts
8
8
  /**
9
9
  * Builds the `ResolverFileParams` every operation generator passes to
@@ -136,11 +136,11 @@ function createGroupConfig(group) {
136
136
  //#region kubb-extension.json
137
137
  var compatibility = {
138
138
  "kubb": ">=5.8.3",
139
- "node": ">=22"
139
+ "node": ">=22.12"
140
140
  };
141
141
  //#endregion
142
142
  //#region package.json
143
- var version = "5.1.1";
143
+ var version = "5.1.3";
144
144
  //#endregion
145
145
  //#region src/generators/handlersGenerator.ts
146
146
  /**
@@ -21,7 +21,7 @@
21
21
  "optionalDependencies": ["plugin-faker"],
22
22
  "compatibility": {
23
23
  "kubb": ">=5.8.3",
24
- "node": ">=22"
24
+ "node": ">=22.12"
25
25
  },
26
26
  "options": [
27
27
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-msw",
3
- "version": "5.1.1",
3
+ "version": "5.1.3",
4
4
  "description": "Generate Mock Service Worker (MSW) request handlers with Kubb. Intercept HTTP requests in the browser or Node.js for frontend development and testing.",
5
5
  "keywords": [
6
6
  "api-mocking",
@@ -68,9 +68,14 @@
68
68
  },
69
69
  "exports": {
70
70
  ".": {
71
- "types": "./dist/index.d.ts",
72
- "import": "./dist/index.js",
73
- "require": "./dist/index.cjs"
71
+ "import": {
72
+ "types": "./dist/index.d.ts",
73
+ "default": "./dist/index.js"
74
+ },
75
+ "require": {
76
+ "types": "./dist/index.d.cts",
77
+ "default": "./dist/index.cjs"
78
+ }
74
79
  },
75
80
  "./package.json": "./package.json",
76
81
  "./kubb-extension.json": "./kubb-extension.json"
@@ -80,17 +85,17 @@
80
85
  "registry": "https://registry.npmjs.org/"
81
86
  },
82
87
  "dependencies": {
83
- "@kubb/plugin-faker": "^5.1.7",
84
- "@kubb/plugin-ts": "^5.0.12"
88
+ "@kubb/plugin-faker": "^5.1.9",
89
+ "@kubb/plugin-ts": "^5.0.14"
85
90
  },
86
91
  "devDependencies": {
87
92
  "@internals/shared": "0.0.0",
88
93
  "@internals/utils": "0.0.0",
89
- "kubb": "^5.10.2",
94
+ "kubb": "^5.10.3",
90
95
  "msw": "^2.15.0"
91
96
  },
92
97
  "peerDependencies": {
93
- "kubb": "^5.10.2",
98
+ "kubb": "^5.10.3",
94
99
  "msw": "^2.0.0"
95
100
  },
96
101
  "peerDependenciesMeta": {
@@ -99,7 +104,7 @@
99
104
  }
100
105
  },
101
106
  "engines": {
102
- "node": ">=22"
107
+ "node": ">=22.12"
103
108
  },
104
109
  "scripts": {
105
110
  "build": "tsdown",
@@ -1,8 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __defProp = Object.defineProperty;
3
- var __name = (target, value) => __defProp(target, "name", {
4
- value,
5
- configurable: true
6
- });
7
- //#endregion
8
- export { __name as t };