@kubb/plugin-vue-query 5.10.0 → 5.10.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 CHANGED
@@ -35,7 +35,7 @@ var compatibility = {
35
35
  "node": ">=22.22"
36
36
  };
37
37
  // package.json
38
- var version = "5.10.0";
38
+ var version = "5.10.1";
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.
@@ -469,5 +467,4 @@ export declare const pluginVueQuery: import("@kubb/kit").PluginFactory<PluginVue
469
467
  * ```
470
468
  */
471
469
  export declare const resolverVueQuery: ResolverVueQuery;
472
- export { type PageParamFn, type PluginVueQuery, type ResolverVueQuery, type Transformer, pluginVueQuery as default };
473
- //# sourceMappingURL=index.d.cts.map
470
+ export { type PageParamFn, type PluginVueQuery, type ResolverVueQuery, type Transformer, pluginVueQuery 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.
@@ -469,5 +467,4 @@ export declare const pluginVueQuery: import("@kubb/kit").PluginFactory<PluginVue
469
467
  * ```
470
468
  */
471
469
  export declare const resolverVueQuery: ResolverVueQuery;
472
- export { type PageParamFn, type PluginVueQuery, type ResolverVueQuery, type Transformer, pluginVueQuery as default };
473
- //# sourceMappingURL=index.d.ts.map
470
+ export { type PageParamFn, type PluginVueQuery, type ResolverVueQuery, type Transformer, pluginVueQuery 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.10.0";
12
+ var version = "5.10.1";
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
@@ -12,9 +12,11 @@ A query composable takes grouped request parameters as its first argument. Param
12
12
  ```typescript [usage.ts]
13
13
  import { useGetPetById } from './gen/hooks/useGetPetById'
14
14
 
15
- const { data, error, isLoading } = useGetPetById({ path: { petId: 1n } })
15
+ const { data, error, isLoading } = useGetPetById({ path: { petId: 1 } })
16
16
  ```
17
17
 
18
+ 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`.
19
+
18
20
  The second argument has two optional groups. `query` takes any TanStack Query option, and `query.client` sets the `QueryClient` to use. The top-level `client` takes request config for this call, such as `baseURL`:
19
21
 
20
22
  ```typescript
@@ -59,7 +61,7 @@ const { mutate } = useUpdatePetWithForm({
59
61
  mutation: { onSuccess: () => queryClient.invalidateQueries() },
60
62
  })
61
63
 
62
- mutate({ path: { petId: 1n }, query: { name: 'Fluffy' } })
64
+ mutate({ path: { petId: 1 }, query: { name: 'Fluffy' } })
63
65
  ```
64
66
 
65
67
  ## Errors and transport
@@ -101,17 +103,16 @@ pluginVueQuery({
101
103
  ```
102
104
 
103
105
  ```typescript [usage.ts]
104
- import { useInfiniteQuery } from '@tanstack/vue-query'
105
- import { findPetsByTagsInfiniteQueryOptions } from './gen/hooks/useFindPetsByTagsInfinite'
106
+ import { useFindPetsByTagsInfinite } from './gen/hooks/useFindPetsByTagsInfinite'
106
107
 
107
- const { data, fetchNextPage, hasNextPage } = useInfiniteQuery(
108
- findPetsByTagsInfiniteQueryOptions({ query: () => ({ tags: ['dog'] }) }),
109
- )
108
+ const { data, fetchNextPage, hasNextPage } = useFindPetsByTagsInfinite({
109
+ query: () => ({ tags: ['dog'] }),
110
+ })
110
111
  ```
111
112
 
112
113
  ::
113
114
 
114
- `nextParam` takes dot notation or an array of keys. Change it to match your API's response. Without `getNextPageParam`, `nextParam` or `cursorParam`, the generated options increment the page number until a page returns an empty array.
115
+ `nextParam` takes dot notation or an array of keys. Change it to match your API's response, and give `initialPageParam` the same type as the query parameter. Without `getNextPageParam`, `nextParam` or `cursorParam`, the generated options increment the page number until a page returns an empty array.
115
116
 
116
117
  ## Refetch when parameters change
117
118
 
package/docs/options.md CHANGED
@@ -44,7 +44,7 @@ Calls the operations generated by [`@kubb/plugin-axios`](https://kubb.dev/extens
44
44
  :::
45
45
 
46
46
  :::field{name="'client'"}
47
- 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.
47
+ 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.
48
48
  :::
49
49
 
50
50
  ::
@@ -62,7 +62,7 @@ Shape of the value the generated composables resolve to.
62
62
  ::field-group
63
63
 
64
64
  :::field{name="'full'"}
65
- Returns the client's whole `RequestResult` (`{ status, data, error, contentType, headers, request, response }`), so a composable can read the status and the response headers next to `data`. Infinite queries read the page cursor from `lastPage.data`. Needs a client plugin whose own `returnType` is `'full'` or `'plain'`; with a client `returnType: 'data'` generation stops with an error.
65
+ Returns the client's whole `RequestResult` (`{ status, data, error, contentType, headers, request, response }`), so a composable can read the status and the response headers next to `data`. Infinite queries read the page cursor from `lastPage.data`. Needs a client plugin whose own `returnType` is `'full'` or `'plain'`. With a client `returnType: 'data'`, generation stops with an error.
66
66
  :::
67
67
 
68
68
  :::field{name="'data'"}
@@ -80,6 +80,8 @@ const etag = result.value?.response.headers.get('ETag')
80
80
  const pet = result.value?.data
81
81
  ```
82
82
 
83
+ 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`.
84
+
83
85
  ### infinite
84
86
 
85
87
  Adds `infiniteQueryOptions` and `useInfiniteQuery` for operations that declare the query parameter named in `infinite.queryParam`. Needs [`hooks: true`](#hooks).
@@ -95,7 +97,7 @@ export function getPetsInfiniteQueryOptions(/* ... */) {
95
97
  return infiniteQueryOptions({ queryKey, queryFn, initialPageParam, getNextPageParam })
96
98
  }
97
99
 
98
- export function useGetPetsInfiniteQuery(/* ... */) {
100
+ export function useGetPetsInfinite(/* ... */) {
99
101
  return useInfiniteQuery(getPetsInfiniteQueryOptions(/* ... */))
100
102
  }
101
103
  ```
@@ -142,7 +144,7 @@ Path to the previous-page cursor on the response, in the same dot or array form.
142
144
 
143
145
  #### infinite.cursorParam
144
146
 
145
- Deprecated path to the cursor field, read for both `getNextPageParam` and `getPreviousPageParam` when set. Use `nextParam` and `previousParam` instead.
147
+ Deprecated name of a top-level response field that holds the cursor, read for both `getNextPageParam` and `getPreviousPageParam` when set. Dot paths are not supported. Use `nextParam` and `previousParam` instead.
146
148
 
147
149
  | | |
148
150
  | -------- | ---------------- |
@@ -152,25 +154,41 @@ Deprecated path to the cursor field, read for both `getNextPageParam` and `getPr
152
154
 
153
155
  #### infinite.getNextPageParam
154
156
 
155
- Source code for TanStack Query's `getNextPageParam`, copied into the generated code as written, such as `'(lastPage) => (lastPage.hasNext ? lastPage.number + 1 : undefined)'`. Use it when the next page must be computed instead of read from a field. Takes precedence over `nextParam` and `cursorParam`.
157
+ Source code for TanStack Query's `getNextPageParam`, copied into the generated code as written, such as `'(lastPage) => (lastPage.hasNext ? lastPage.number + 1 : undefined)'`. Pass a string or a function. Use it when the next page must be computed instead of read from a field. Takes precedence over `nextParam` and `cursorParam`.
156
158
 
157
- | | |
158
- | -------- | ---------------- |
159
- | Type | `string \| null` |
160
- | Required | `false` |
161
- | Default | `null` |
159
+ | | |
160
+ | -------- | ------------------------------- |
161
+ | Type | `string \| PageParamFn \| null` |
162
+ | Required | `false` |
163
+ | Default | `null` |
164
+
165
+ `definePageParam` types the page and the page parameter, and returns the function's source. A plain function works too. Only the source is copied, so the function cannot reference variables from the config file.
166
+
167
+ ```typescript [kubb.config.ts]
168
+ import { definePageParam, pluginVueQuery } from '@kubb/plugin-vue-query'
162
169
 
163
- Without `getNextPageParam`, `nextParam` or `cursorParam`, the composable counts pages up from `initialPageParam` until a page is an empty array. This works only for array responses, so generation warns when the response is an object.
170
+ type PetsPage = { hasNext: boolean; number: number }
171
+
172
+ pluginVueQuery({
173
+ hooks: true,
174
+ infinite: {
175
+ queryParam: 'page',
176
+ getNextPageParam: definePageParam<PetsPage, number>((lastPage) => (lastPage.hasNext ? lastPage.number + 1 : undefined)),
177
+ },
178
+ })
179
+ ```
180
+
181
+ Without `getNextPageParam`, `nextParam` or `cursorParam`, the composable counts pages up from `initialPageParam` until a page is an empty array. Counting works only for array responses, so generation warns for any other response.
164
182
 
165
183
  #### infinite.getPreviousPageParam
166
184
 
167
- Source code for TanStack Query's `getPreviousPageParam`, copied into the generated code as written. Takes precedence over `previousParam` and `cursorParam`.
185
+ Source code for TanStack Query's `getPreviousPageParam`, copied into the generated code as written. Takes a string or a function, like `getNextPageParam`. Takes precedence over `previousParam` and `cursorParam`.
168
186
 
169
- | | |
170
- | -------- | ---------------- |
171
- | Type | `string \| null` |
172
- | Required | `false` |
173
- | Default | `null` |
187
+ | | |
188
+ | -------- | ------------------------------- |
189
+ | Type | `string \| PageParamFn \| null` |
190
+ | Required | `false` |
191
+ | Default | `null` |
174
192
 
175
193
  ### query
176
194
 
@@ -221,7 +239,7 @@ queryKey: ({ node, variant }) => [JSON.stringify({ variant, operationId: node.op
221
239
  ```
222
240
 
223
241
  ```typescript [Generated output]
224
- export const getUserByNameQueryKey = () => [{ variant: 'query', operationId: 'getUserByName' }] as const
242
+ export const getUserByNameQueryKey = ({ path }: { path: MaybeRefOrGetter<Omit<GetUserByNameOptions, 'headers'>['path']> }) => [{"variant":"query","operationId":"getUserByName"}] as const
225
243
  ```
226
244
 
227
245
  ::
@@ -266,7 +284,7 @@ Module specifier for the generated `import { useMutation } from '...'`, emitted
266
284
 
267
285
  ### mutationKey
268
286
 
269
- Builds the `mutationKey` for each mutation composable, useful for batching invalidations. It takes the same props as `queryKey` with `variant: 'mutation'` and inlines strings the same way, so wrap literals in `JSON.stringify(...)`.
287
+ Builds the `mutationKey` for each mutation composable, useful for batching invalidations. The builder takes the same props as `queryKey` with `variant: 'mutation'` and inlines strings the same way, so wrap literals in `JSON.stringify(...)`.
270
288
 
271
289
  | | |
272
290
  | -------- | ------------------------------------------------------ |
package/docs/overview.md CHANGED
@@ -12,10 +12,10 @@ The plugin ships no HTTP client. Each helper calls a function generated by a cli
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.
15
+ - `client` picks `fetch`, `axios`, or `client` when more than one client plugin is registered. A single client plugin is detected automatically.
16
16
  - `hooks` adds the `use*` composables on top of the query option factories.
17
17
  - `infinite` adds `useInfiniteQuery` composables for pagination. It needs `hooks: true` and covers the operations that take the query parameter named in `infinite.queryParam`, which defaults to `'id'`.
18
- - `query` and `mutation` set which HTTP methods become queries (`GET`) and mutations (`POST`, `PUT`, `PATCH`, `DELETE`). They also set where the TanStack Query runtime is imported from. Set either to `false` to skip those helpers.
18
+ - `query` and `mutation` set which HTTP methods become queries (`GET`, `QUERY`) and mutations (`POST`, `PUT`, `PATCH`, `DELETE`). They also set where the TanStack Query runtime is imported from. Set either to `false` to skip those helpers.
19
19
 
20
20
  See [Options](https://kubb.dev/extensions/kubb-labs/plugin-vue-query/options) for every option and its default.
21
21
 
@@ -25,6 +25,7 @@ The config below generates `useQuery` and `useMutation` composables that call th
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 { pluginVueQuery } from '@kubb/plugin-vue-query'
@@ -32,6 +33,7 @@ import { pluginVueQuery } from '@kubb/plugin-vue-query'
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
  },
@@ -182,9 +185,9 @@
182
185
  "key": "queryMethods",
183
186
  "path": ["query", "methods"],
184
187
  "label": "Query Methods",
185
- "description": "Comma-separated HTTP methods treated as queries (default: GET)",
188
+ "description": "Comma-separated HTTP methods treated as queries (default: GET, QUERY)",
186
189
  "type": "list",
187
- "default": ["GET"],
190
+ "default": ["GET", "QUERY"],
188
191
  "itemCase": "upper"
189
192
  },
190
193
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-vue-query",
3
- "version": "5.10.0",
3
+ "version": "5.10.1",
4
4
  "description": "Generate type-safe TanStack Query (Vue Query) composables with Kubb. Covers useQuery, useMutation, useInfiniteQuery, and queryOptions with Vue 3 Composition API support.",
5
5
  "keywords": [
6
6
  "code-generation",
@@ -83,17 +83,17 @@
83
83
  "registry": "https://registry.npmjs.org/"
84
84
  },
85
85
  "dependencies": {
86
- "@kubb/kit": "^5.18.6",
87
- "@kubb/plugin-ts": "^5.5.0",
88
- "@kubb/renderer-jsx": "^5.18.6"
86
+ "@kubb/kit": "^5.18.8",
87
+ "@kubb/plugin-ts": "^5.5.1",
88
+ "@kubb/renderer-jsx": "^5.18.8"
89
89
  },
90
90
  "devDependencies": {
91
91
  "@internals/client": "0.0.0",
92
92
  "@internals/shared": "0.0.0",
93
93
  "@internals/tanstack-query": "0.0.0",
94
94
  "@internals/utils": "0.0.0",
95
- "@kubb/plugin-client": "6.0.0",
96
- "@tanstack/vue-query": "^5.106.1",
95
+ "@kubb/plugin-client": "6.0.1",
96
+ "@tanstack/vue-query": "^5.107.1",
97
97
  "vue": "^3.5.45"
98
98
  },
99
99
  "peerDependencies": {