@kubb/plugin-msw 5.0.11 → 5.0.13

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
@@ -158,7 +158,7 @@ var compatibility = {
158
158
  };
159
159
  //#endregion
160
160
  //#region package.json
161
- var version = "5.0.11";
161
+ var version = "5.0.13";
162
162
  //#endregion
163
163
  //#region src/generators/handlersGenerator.ts
164
164
  /**
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
- import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ResolverPatch, ast } from "kubb/kit";
2
+ import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
3
3
  //#region src/types.d.ts
4
4
  /**
5
5
  * Resolver for MSW that provides naming methods for handler functions.
@@ -78,7 +78,7 @@ type ResolvedOptions = {
78
78
  handlers: boolean;
79
79
  resolver: ResolverMsw;
80
80
  };
81
- type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, ResolverMsw>;
81
+ type PluginMsw = PluginType<'plugin-msw', Options, ResolvedOptions, ResolverMsw>;
82
82
  declare global {
83
83
  namespace Kubb {
84
84
  interface PluginRegistry {
package/dist/index.js CHANGED
@@ -154,7 +154,7 @@ var compatibility = {
154
154
  };
155
155
  //#endregion
156
156
  //#region package.json
157
- var version = "5.0.11";
157
+ var version = "5.0.13";
158
158
  //#endregion
159
159
  //#region src/generators/handlersGenerator.ts
160
160
  /**
package/docs/options.md CHANGED
@@ -62,7 +62,7 @@ Default value. Returns the data you pass to the handler, typed with the `@kubb/p
62
62
  :::
63
63
 
64
64
  :::field{name="'faker'"}
65
- Falls back to a value generated by `@kubb/plugin-faker` when `data` is missing or falsy, such as `0`, `false`, or `''`. Register `pluginFaker()` alongside this plugin.
65
+ Falls back to a value generated by `@kubb/plugin-faker` when `data` is `undefined` or `null`. Other falsy values, such as `0`, `false`, or `''`, are sent as the response body. Register `pluginFaker()` alongside this plugin.
66
66
  :::
67
67
 
68
68
  ::
@@ -72,7 +72,7 @@ export function getPetHandler(data?: GetPetQueryResponse | ((info: Parameters<Pa
72
72
  return http.get('/pet/:petId', function handler(info) {
73
73
  if (typeof data === 'function') return data(info)
74
74
 
75
- return new Response(JSON.stringify(data || createGetPetQueryResponse(data)), {
75
+ return new Response(JSON.stringify(data ?? createGetPetQueryResponse(data)), {
76
76
  status: 200,
77
77
  headers: { 'Content-Type': 'application/json' },
78
78
  })
package/docs/overview.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # MSW
2
2
 
3
- Generates typed MSW request handlers from your OpenAPI spec, one per operation. Use them to mock the API in tests and during local development.
3
+ The MSW plugin generates a typed MSW request handler for each operation in your OpenAPI spec.
4
4
 
5
- Each handler returns the data you pass to it. With `parser: 'faker'`, it falls back to mock data from `@kubb/plugin-faker` when you pass none.
5
+ Each handler returns the data you pass to it. With `parser: 'faker'`, a handler called without data returns mock data from `@kubb/plugin-faker`. Only operations with a success response schema get mock data.
6
6
 
7
7
  ## Setup
8
8
 
9
- - Add `@kubb/plugin-ts`.
10
- - Add `@kubb/plugin-faker` when you set `parser: 'faker'`. The default `data` parser does not need it.
11
- - Install MSW v2 or higher in the app that uses the generated code.
9
+ - Add `@kubb/plugin-ts` for the request and response types.
10
+ - Add `@kubb/plugin-faker` when you set `parser: 'faker'`, and install `@faker-js/faker` v10. The default `data` parser does not need it.
11
+ - Install `msw` v2 in the app that uses the generated code.
12
12
 
13
13
  ## Options worth knowing
14
14
 
@@ -16,8 +16,12 @@ Each handler returns the data you pass to it. With `parser: 'faker'`, it falls b
16
16
  - `handlers` writes a `handlers.ts` file that exports every handler, ready to spread into `setupServer` or `setupWorker`.
17
17
  - `baseURL` is prepended to the path each handler matches.
18
18
 
19
+ See [Options](https://kubb.dev/extensions/kubb-labs/plugin-msw/options) for every option and its default.
20
+
19
21
  ## Example
20
22
 
23
+ The config below generates one handler per operation and a `handlers.ts` file that exports them all.
24
+
21
25
  ```typescript [kubb.config.ts]
22
26
  import { defineConfig } from 'kubb/config'
23
27
  import { pluginTs } from '@kubb/plugin-ts'
@@ -32,9 +36,3 @@ export default defineConfig({
32
36
  ],
33
37
  })
34
38
  ```
35
-
36
- ## See also
37
-
38
- - [MSW](https://mswjs.io/)
39
- - [@kubb/plugin-ts](https://kubb.dev/extensions/kubb-labs/plugin-ts)
40
- - [@kubb/plugin-faker](https://kubb.dev/extensions/kubb-labs/plugin-faker)
@@ -17,7 +17,8 @@
17
17
  "github": "stijnvanhulle"
18
18
  }
19
19
  ],
20
- "dependencies": ["plugin-ts", "plugin-faker"],
20
+ "dependencies": ["plugin-ts"],
21
+ "optionalDependencies": ["plugin-faker"],
21
22
  "compatibility": {
22
23
  "kubb": ">=5.8.3",
23
24
  "node": ">=22"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-msw",
3
- "version": "5.0.11",
3
+ "version": "5.0.13",
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",
@@ -80,17 +80,17 @@
80
80
  "registry": "https://registry.npmjs.org/"
81
81
  },
82
82
  "dependencies": {
83
- "@kubb/plugin-faker": "^5.1.4",
84
- "@kubb/plugin-ts": "^5.0.9"
83
+ "@kubb/plugin-faker": "^5.1.6",
84
+ "@kubb/plugin-ts": "^5.0.11"
85
85
  },
86
86
  "devDependencies": {
87
87
  "@internals/shared": "0.0.0",
88
88
  "@internals/utils": "0.0.0",
89
- "kubb": "^5.8.3",
89
+ "kubb": "^5.9.2",
90
90
  "msw": "^2.15.0"
91
91
  },
92
92
  "peerDependencies": {
93
- "kubb": "^5.8.3",
93
+ "kubb": "^5.9.2",
94
94
  "msw": "^2.0.0"
95
95
  },
96
96
  "peerDependenciesMeta": {