@kubb/plugin-swr 5.9.0 → 5.9.2

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
@@ -35,7 +35,7 @@ var compatibility = {
35
35
  "node": ">=22.22"
36
36
  };
37
37
  // package.json
38
- var version = "5.9.0";
38
+ var version = "5.9.2";
39
39
  // ../../internals/client/src/resolveClient.ts
40
40
  /**
41
41
  * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
package/dist/index.d.cts CHANGED
@@ -1,7 +1,5 @@
1
1
  import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "@kubb/kit";
2
2
  import { ResolverTs } from "@kubb/plugin-ts";
3
- import "@kubb/renderer-jsx";
4
- import "@kubb/adapter-oas";
5
3
  /**
6
4
  * The client selector accepted by a consumer's `client` option. Each calls a registered contract
7
5
  * client plugin.
@@ -367,5 +365,4 @@ export declare const pluginSwr: import("@kubb/kit").PluginFactory<PluginSwr>;
367
365
  * ```
368
366
  */
369
367
  export declare const resolverSwr: ResolverSwr;
370
- export { type PluginSwr, type ResolverSwr, type Transformer, pluginSwr as default };
371
- //# sourceMappingURL=index.d.cts.map
368
+ export { type PluginSwr, type ResolverSwr, type Transformer, pluginSwr as default };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "@kubb/kit";
2
2
  import { ResolverTs } from "@kubb/plugin-ts";
3
- import "@kubb/renderer-jsx";
4
- import "@kubb/adapter-oas";
5
3
  /**
6
4
  * The client selector accepted by a consumer's `client` option. Each calls a registered contract
7
5
  * client plugin.
@@ -367,5 +365,4 @@ export declare const pluginSwr: import("@kubb/kit").PluginFactory<PluginSwr>;
367
365
  * ```
368
366
  */
369
367
  export declare const resolverSwr: ResolverSwr;
370
- export { type PluginSwr, type ResolverSwr, type Transformer, pluginSwr as default };
371
- //# sourceMappingURL=index.d.ts.map
368
+ export { type PluginSwr, type ResolverSwr, type Transformer, pluginSwr as default };
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ var compatibility = {
9
9
  "node": ">=22.22"
10
10
  };
11
11
  // package.json
12
- var version = "5.9.0";
12
+ var version = "5.9.2";
13
13
  // ../../internals/client/src/resolveClient.ts
14
14
  /**
15
15
  * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
@@ -9,16 +9,20 @@ A query hook takes the operation's grouped request config (`path`, `query`, `hea
9
9
  ```typescript
10
10
  import { useGetPetById } from './gen/hooks/useGetPetById'
11
11
 
12
- const { data, error, isLoading } = useGetPetById({ path: { petId: 1n } })
12
+ const { data, error, isLoading } = useGetPetById({ path: { petId: 1 } })
13
13
  ```
14
14
 
15
+ The examples set [`integerType: 'number'`](https://kubb.dev/extensions/kubb-labs/adapter-oas/options#integertype) on the adapter, so an `int64` id such as `petId` is a `number`. With the default it is a `bigint` and the call takes `1n`.
16
+
17
+ Path keys keep the names from the spec, so a `{pet-id}` placeholder is passed as `path: { 'pet-id': 1 }`. Set [`pathParamsCasing: 'camelcase'`](https://kubb.dev/extensions/kubb-labs/adapter-oas/options#pathparamscasing) on the adapter (`@kubb/adapter-oas` 5.20.0 or later) to pass `path: { petId: 1 }` instead, the name MSW handlers and query keys already use. The HTTP request stays the same.
18
+
15
19
  The second argument takes `query` (any `SWRConfiguration`), `client` (request config for this call, such as `baseURL`), and the Kubb options `shouldFetch` and `immutable`, covered in [Skip requests until ready](#skip-requests-until-ready) and [Fetch immutable data](#fetch-immutable-data):
16
20
 
17
21
  ```typescript
18
22
  import { useGetPetById } from './gen/hooks/useGetPetById'
19
23
 
20
24
  useGetPetById(
21
- { path: { petId: 1n } },
25
+ { path: { petId: 1 } },
22
26
  {
23
27
  query: { refreshInterval: 30_000 },
24
28
  client: { baseURL: 'https://api.example.com/v1' },
@@ -52,14 +56,14 @@ Each generated hook calls the client function with `throwOnError: true`. A faile
52
56
 
53
57
  ## Skip requests until ready
54
58
 
55
- Set `shouldFetch: false` to give SWR a `null` key and skip the request. Enable it once the required parameters are available. Mutation hooks accept the same switch, and a `null` key stops `trigger` from firing.
59
+ Set `shouldFetch: false` to give SWR a `null` key and skip the request. Pass `true` once the required parameters are available. Mutation hooks accept the same option. With a `null` key, calling `trigger` throws a missing-key error.
56
60
 
57
61
  ```typescript [usage.ts]
58
62
  import { useGetPetById } from './gen/hooks/useGetPetById'
59
63
 
60
- export function useSelectedPet(petId: bigint | undefined) {
64
+ export function useSelectedPet(petId: number | undefined) {
61
65
  return useGetPetById(
62
- { path: { petId: petId ?? 0n } },
66
+ { path: { petId: petId ?? 0 } },
63
67
  { shouldFetch: petId != null },
64
68
  )
65
69
  }
@@ -73,7 +77,7 @@ Set `immutable: true` on a query hook for data that stays unchanged. It sets `re
73
77
  import { useGetPetById } from './gen/hooks/useGetPetById'
74
78
 
75
79
  const { data, error } = useGetPetById(
76
- { path: { petId: 1n } },
80
+ { path: { petId: 1 } },
77
81
  { immutable: true },
78
82
  )
79
83
  ```
package/docs/options.md CHANGED
@@ -42,7 +42,7 @@ Calls the operations generated by [`@kubb/plugin-axios`](https://kubb.dev/extens
42
42
  :::
43
43
 
44
44
  :::field{name="'client'"}
45
- Calls the operations generated by [`@kubb/plugin-client`](https://kubb.dev/extensions/kubb-labs/plugin-client). Your client module must also export the `RequestConfig` and `ResponseErrorConfig` types.
45
+ Calls the operations generated by [`@kubb/plugin-client`](https://kubb.dev/extensions/kubb-labs/plugin-client). The client module must also export the `RequestConfig` and `ResponseErrorConfig` types.
46
46
  :::
47
47
 
48
48
  ::
@@ -60,7 +60,7 @@ Shape of the value the generated hooks resolve to.
60
60
  ::field-group
61
61
 
62
62
  :::field{name="'full'"}
63
- Returns the client's whole `RequestResult` (`{ status, data, error, contentType, headers, request, response }`), so a hook can read the status and the response headers next to `data`. Needs a client plugin whose own `returnType` is `'full'` or `'plain'`; with a client `returnType: 'data'` generation stops with an error.
63
+ Returns the client's whole `RequestResult` (`{ status, data, error, contentType, headers, request, response }`), so a hook can read the status and the response headers next to `data`. Needs a client plugin whose own `returnType` is `'full'` or `'plain'`. With a client `returnType: 'data'`, generation stops with an error.
64
64
  :::
65
65
 
66
66
  :::field{name="'data'"}
@@ -78,6 +78,8 @@ const etag = result?.response.headers.get('ETag')
78
78
  const pet = result?.data
79
79
  ```
80
80
 
81
+ The examples set [`integerType: 'number'`](https://kubb.dev/extensions/kubb-labs/adapter-oas/options#integertype) on the adapter, so an `int64` id such as `petId` is a `number`. With the default it is a `bigint` and the call takes `1n`.
82
+
81
83
  ### query
82
84
 
83
85
  Configures the generated `useSWR` hooks. Pass an object to change the HTTP methods or import path, or `false` to skip query hook generation.
package/docs/overview.md CHANGED
@@ -12,8 +12,8 @@ The plugin ships no HTTP client. Each hook calls a function generated by a clien
12
12
 
13
13
  ## Options worth knowing
14
14
 
15
- - `client` picks `fetch` or `axios` when both client plugins are registered. A single client is detected automatically.
16
- - `query` and `mutation` set which HTTP methods become queries (`GET`) and mutations (`POST`, `PUT`, `PATCH`, `DELETE`). They also set where SWR is imported from (`swr` and `swr/mutation`). Set either to `false` to skip those hooks.
15
+ - `client` picks `fetch`, `axios`, or `client` when more than one client plugin is registered. A single client plugin is detected automatically.
16
+ - `query` and `mutation` set which HTTP methods become queries (`GET`, `QUERY`) and mutations (`POST`, `PUT`, `PATCH`, `DELETE`). They also set where SWR is imported from (`swr` and `swr/mutation`). Set either to `false` to skip those hooks.
17
17
 
18
18
  The plugin does not generate `useSWRInfinite` hooks.
19
19
 
@@ -25,6 +25,7 @@ The config below generates `useSWR` and `useSWRMutation` hooks that call the Fet
25
25
 
26
26
  ```typescript [kubb.config.ts]
27
27
  import { defineConfig } from 'kubb/config'
28
+ import { adapterOas } from '@kubb/adapter-oas'
28
29
  import { pluginTs } from '@kubb/plugin-ts'
29
30
  import { pluginFetch } from '@kubb/plugin-fetch'
30
31
  import { pluginSwr } from '@kubb/plugin-swr'
@@ -32,6 +33,7 @@ import { pluginSwr } from '@kubb/plugin-swr'
32
33
  export default defineConfig({
33
34
  input: './petStore.yaml',
34
35
  output: { path: './src/gen' },
36
+ adapter: adapterOas({ integerType: 'number' }),
35
37
  plugins: [
36
38
  pluginTs(),
37
39
  pluginFetch(),
@@ -17,8 +17,7 @@
17
17
  "github": "stijnvanhulle"
18
18
  }
19
19
  ],
20
- "dependencies": ["plugin-ts"],
21
- "optionalDependencies": ["plugin-zod"],
20
+ "optionalDependencies": ["plugin-ts", "plugin-zod"],
22
21
  "compatibility": {
23
22
  "kubb": ">=5.18.4",
24
23
  "node": ">=22.22"
@@ -97,7 +96,7 @@
97
96
  "key": "client",
98
97
  "path": ["client"],
99
98
  "label": "Client",
100
- "description": "HTTP client the generated hooks call. Only needed to disambiguate when both plugin-fetch and plugin-axios are enabled",
99
+ "description": "HTTP client the generated hooks call. Only needed to disambiguate when more than one of plugin-fetch, plugin-axios and plugin-client is enabled",
101
100
  "type": "select",
102
101
  "default": null,
103
102
  "choices": [
@@ -112,6 +111,10 @@
112
111
  {
113
112
  "label": "axios",
114
113
  "value": "axios"
114
+ },
115
+ {
116
+ "label": "client",
117
+ "value": "client"
115
118
  }
116
119
  ]
117
120
  },
@@ -167,9 +170,9 @@
167
170
  "key": "queryMethods",
168
171
  "path": ["query", "methods"],
169
172
  "label": "Query Methods",
170
- "description": "Comma-separated HTTP methods treated as queries (default: GET)",
173
+ "description": "Comma-separated HTTP methods treated as queries (default: GET, QUERY)",
171
174
  "type": "list",
172
- "default": ["GET"],
175
+ "default": ["GET", "QUERY"],
173
176
  "itemCase": "upper"
174
177
  },
175
178
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-swr",
3
- "version": "5.9.0",
3
+ "version": "5.9.2",
4
4
  "description": "Generate type-safe SWR hooks with Kubb. Covers useSWR and useSWRMutation with full TypeScript support.",
5
5
  "keywords": [
6
6
  "code-generation",
@@ -79,16 +79,16 @@
79
79
  "registry": "https://registry.npmjs.org/"
80
80
  },
81
81
  "dependencies": {
82
- "@kubb/kit": "^5.18.6",
83
- "@kubb/plugin-ts": "^5.5.0",
84
- "@kubb/renderer-jsx": "^5.18.6"
82
+ "@kubb/kit": "^5.19.0",
83
+ "@kubb/plugin-ts": "^5.5.2",
84
+ "@kubb/renderer-jsx": "^5.19.0"
85
85
  },
86
86
  "devDependencies": {
87
87
  "@internals/client": "0.0.0",
88
88
  "@internals/shared": "0.0.0",
89
89
  "@internals/tanstack-query": "0.0.0",
90
90
  "@internals/utils": "0.0.0",
91
- "@kubb/plugin-client": "6.0.0",
91
+ "@kubb/plugin-client": "6.0.2",
92
92
  "swr": "^2.5.1"
93
93
  },
94
94
  "peerDependencies": {