@kubb/plugin-swr 5.4.3 → 5.4.4
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 +23 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +22 -2
- package/dist/index.js.map +1 -1
- package/docs/options.md +20 -4
- package/package.json +3 -3
package/docs/options.md
CHANGED
|
@@ -10,9 +10,9 @@ Pass these options to `pluginSwr()`, all of them optional. Shared options link t
|
|
|
10
10
|
| [`group`](https://kubb.dev/docs/5.x/reference/plugin-options#group) | Split output by tag or path: `type`, `name`. | None |
|
|
11
11
|
| [`client`](#client) | Which registered client plugin the hooks call. | Auto-detected |
|
|
12
12
|
| [`query`](#query) | Configure the `useSWR` hooks, or turn them off. | `{ methods: ['GET', 'QUERY'], importPath: 'swr' }` |
|
|
13
|
-
| [`queryKey`](#querykey) | Build the SWR key for each query hook. |
|
|
13
|
+
| [`queryKey`](#querykey) | Build the SWR key for each query hook. | Exported `queryKeyTransformer` |
|
|
14
14
|
| [`mutation`](#mutation) | Configure the `useSWRMutation` hooks, or turn them off. | `{ methods: ['POST', 'PUT', 'PATCH', 'DELETE'], importPath: 'swr/mutation' }` |
|
|
15
|
-
| [`mutationKey`](#mutationkey) | Build the SWR key for each mutation hook. |
|
|
15
|
+
| [`mutationKey`](#mutationkey) | Build the SWR key for each mutation hook. | Exported `mutationKeyTransformer` |
|
|
16
16
|
| [`include`](https://kubb.dev/docs/5.x/reference/plugin-options#include) | Keep only operations that match. | None |
|
|
17
17
|
| [`exclude`](https://kubb.dev/docs/5.x/reference/plugin-options#exclude) | Skip operations that match. | `[]` |
|
|
18
18
|
| [`override`](https://kubb.dev/docs/5.x/reference/plugin-options#override) | Apply different options per pattern. | `[]` |
|
|
@@ -86,12 +86,20 @@ Builds the SWR key for each query hook. The callback receives the operation `nod
|
|
|
86
86
|
| -------- | ------------------------------------------------------ |
|
|
87
87
|
| Type | `(props: { node, casing, variant }) => Array<unknown>` |
|
|
88
88
|
| Required | `false` |
|
|
89
|
-
| Default |
|
|
89
|
+
| Default | Exported `queryKeyTransformer` |
|
|
90
90
|
|
|
91
91
|
```typescript
|
|
92
92
|
queryKey: ({ node, variant }) => [JSON.stringify({ variant, operationId: node.operationId })]
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
+
To extend the default key instead of replacing it, import `queryKeyTransformer` and spread its result. The default segments can change between releases, so spread them instead of reading single entries.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
import { queryKeyTransformer } from '@kubb/plugin-swr'
|
|
99
|
+
|
|
100
|
+
queryKey: (props) => [JSON.stringify(props.node.operationId), ...queryKeyTransformer(props)]
|
|
101
|
+
```
|
|
102
|
+
|
|
95
103
|
### mutation
|
|
96
104
|
|
|
97
105
|
Configures the generated `useSWRMutation` hooks. Pass an object to change the HTTP methods or import path, or `false` to skip mutation hook generation.
|
|
@@ -130,7 +138,15 @@ Builds the SWR key for each mutation hook. Like `queryKey`, the callback receive
|
|
|
130
138
|
| -------- | ------------------------------------------------------ |
|
|
131
139
|
| Type | `(props: { node, casing, variant }) => Array<unknown>` |
|
|
132
140
|
| Required | `false` |
|
|
133
|
-
| Default |
|
|
141
|
+
| Default | Exported `mutationKeyTransformer` |
|
|
142
|
+
|
|
143
|
+
Extend the default the same way with `mutationKeyTransformer`:
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { mutationKeyTransformer } from '@kubb/plugin-swr'
|
|
147
|
+
|
|
148
|
+
mutationKey: (props) => [JSON.stringify(props.node.operationId), ...mutationKeyTransformer(props)]
|
|
149
|
+
```
|
|
134
150
|
|
|
135
151
|
### resolver
|
|
136
152
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-swr",
|
|
3
|
-
"version": "5.4.
|
|
3
|
+
"version": "5.4.4",
|
|
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",
|
|
@@ -86,11 +86,11 @@
|
|
|
86
86
|
"@internals/shared": "0.0.0",
|
|
87
87
|
"@internals/tanstack-query": "0.0.0",
|
|
88
88
|
"@internals/utils": "0.0.0",
|
|
89
|
-
"kubb": "^5.
|
|
89
|
+
"kubb": "^5.11.1",
|
|
90
90
|
"swr": "^2.5.1"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
93
|
-
"kubb": "^5.
|
|
93
|
+
"kubb": "^5.11.1",
|
|
94
94
|
"swr": "^2.2.0"
|
|
95
95
|
},
|
|
96
96
|
"peerDependenciesMeta": {
|