@kubb/plugin-swr 5.9.0-canary.20261109T201601 → 5.9.1
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 +561 -533
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.js +560 -532
- package/dist/index.js.map +1 -1
- package/docs/guides/calling-operations.md +8 -6
- package/docs/options.md +4 -2
- package/docs/overview.md +4 -2
- package/kubb-extension.json +9 -6
- package/package.json +9 -8
|
@@ -9,16 +9,18 @@ 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:
|
|
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
|
+
|
|
15
17
|
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
18
|
|
|
17
19
|
```typescript
|
|
18
20
|
import { useGetPetById } from './gen/hooks/useGetPetById'
|
|
19
21
|
|
|
20
22
|
useGetPetById(
|
|
21
|
-
{ path: { petId:
|
|
23
|
+
{ path: { petId: 1 } },
|
|
22
24
|
{
|
|
23
25
|
query: { refreshInterval: 30_000 },
|
|
24
26
|
client: { baseURL: 'https://api.example.com/v1' },
|
|
@@ -52,14 +54,14 @@ Each generated hook calls the client function with `throwOnError: true`. A faile
|
|
|
52
54
|
|
|
53
55
|
## Skip requests until ready
|
|
54
56
|
|
|
55
|
-
Set `shouldFetch: false` to give SWR a `null` key and skip the request.
|
|
57
|
+
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
58
|
|
|
57
59
|
```typescript [usage.ts]
|
|
58
60
|
import { useGetPetById } from './gen/hooks/useGetPetById'
|
|
59
61
|
|
|
60
|
-
export function useSelectedPet(petId:
|
|
62
|
+
export function useSelectedPet(petId: number | undefined) {
|
|
61
63
|
return useGetPetById(
|
|
62
|
-
{ path: { petId: petId ??
|
|
64
|
+
{ path: { petId: petId ?? 0 } },
|
|
63
65
|
{ shouldFetch: petId != null },
|
|
64
66
|
)
|
|
65
67
|
}
|
|
@@ -73,7 +75,7 @@ Set `immutable: true` on a query hook for data that stays unchanged. It sets `re
|
|
|
73
75
|
import { useGetPetById } from './gen/hooks/useGetPetById'
|
|
74
76
|
|
|
75
77
|
const { data, error } = useGetPetById(
|
|
76
|
-
{ path: { petId:
|
|
78
|
+
{ path: { petId: 1 } },
|
|
77
79
|
{ immutable: true },
|
|
78
80
|
)
|
|
79
81
|
```
|
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).
|
|
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, 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'
|
|
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 `
|
|
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(),
|
package/kubb-extension.json
CHANGED
|
@@ -17,10 +17,9 @@
|
|
|
17
17
|
"github": "stijnvanhulle"
|
|
18
18
|
}
|
|
19
19
|
],
|
|
20
|
-
"
|
|
21
|
-
"optionalDependencies": ["plugin-zod"],
|
|
20
|
+
"optionalDependencies": ["plugin-ts", "plugin-zod"],
|
|
22
21
|
"compatibility": {
|
|
23
|
-
"kubb": ">=5.
|
|
22
|
+
"kubb": ">=5.18.4",
|
|
24
23
|
"node": ">=22.22"
|
|
25
24
|
},
|
|
26
25
|
"role": "consumer",
|
|
@@ -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
|
|
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.
|
|
3
|
+
"version": "5.9.1",
|
|
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,15 +79,16 @@
|
|
|
79
79
|
"registry": "https://registry.npmjs.org/"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"@kubb/kit": "^5.
|
|
83
|
-
"@kubb/plugin-ts": "^5.5.
|
|
84
|
-
"@kubb/renderer-jsx": "^5.
|
|
82
|
+
"@kubb/kit": "^5.18.8",
|
|
83
|
+
"@kubb/plugin-ts": "^5.5.1",
|
|
84
|
+
"@kubb/renderer-jsx": "^5.18.8"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
-
"@internals/client": "0.
|
|
88
|
-
"@internals/shared": "0.
|
|
89
|
-
"@internals/tanstack-query": "0.
|
|
90
|
-
"@internals/utils": "0.
|
|
87
|
+
"@internals/client": "0.0.0",
|
|
88
|
+
"@internals/shared": "0.0.0",
|
|
89
|
+
"@internals/tanstack-query": "0.0.0",
|
|
90
|
+
"@internals/utils": "0.0.0",
|
|
91
|
+
"@kubb/plugin-client": "6.0.1",
|
|
91
92
|
"swr": "^2.5.1"
|
|
92
93
|
},
|
|
93
94
|
"peerDependencies": {
|