@kubb/plugin-vue-query 3.0.0-beta.9 → 3.0.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.
Files changed (56) hide show
  1. package/dist/{chunk-VEQJK4QZ.js → chunk-6PXSXFQR.js} +239 -25
  2. package/dist/chunk-6PXSXFQR.js.map +1 -0
  3. package/dist/{chunk-CJBEHJ3D.cjs → chunk-FG7T5YC2.cjs} +125 -100
  4. package/dist/chunk-FG7T5YC2.cjs.map +1 -0
  5. package/dist/{chunk-CYO3ZQ3K.js → chunk-L4RJORUB.js} +117 -92
  6. package/dist/chunk-L4RJORUB.js.map +1 -0
  7. package/dist/{chunk-QS4ZHURK.cjs → chunk-YSXKGUG5.cjs} +239 -25
  8. package/dist/chunk-YSXKGUG5.cjs.map +1 -0
  9. package/dist/components.cjs +8 -8
  10. package/dist/components.d.cts +25 -14
  11. package/dist/components.d.ts +25 -14
  12. package/dist/components.js +1 -1
  13. package/dist/generators.cjs +5 -5
  14. package/dist/generators.d.cts +1 -1
  15. package/dist/generators.d.ts +1 -1
  16. package/dist/generators.js +2 -2
  17. package/dist/index.cjs +24 -25
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.js +23 -24
  22. package/dist/index.js.map +1 -1
  23. package/dist/types-C8LfCZUP.d.cts +389 -0
  24. package/dist/types-C8LfCZUP.d.ts +389 -0
  25. package/package.json +13 -12
  26. package/src/components/InfiniteQuery.tsx +55 -2
  27. package/src/components/InfiniteQueryOptions.tsx +49 -2
  28. package/src/components/Mutation.tsx +3 -1
  29. package/src/components/MutationKey.tsx +11 -5
  30. package/src/components/Query.tsx +65 -2
  31. package/src/components/QueryKey.tsx +17 -7
  32. package/src/components/QueryOptions.tsx +50 -3
  33. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +1 -1
  34. package/src/generators/__snapshots__/clientGetImportPath.ts +1 -1
  35. package/src/generators/__snapshots__/clientPostImportPath.ts +2 -2
  36. package/src/generators/__snapshots__/findByTags.ts +1 -1
  37. package/src/generators/__snapshots__/findByTagsObject.ts +62 -0
  38. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +1 -1
  39. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +2 -2
  40. package/src/generators/__snapshots__/findByTagsWithZod.ts +1 -1
  41. package/src/generators/__snapshots__/findInfiniteByTags.ts +3 -3
  42. package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +3 -3
  43. package/src/generators/__snapshots__/postAsQuery.ts +1 -1
  44. package/src/generators/__snapshots__/updatePetById.ts +2 -2
  45. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +3 -5
  46. package/src/generators/infiniteQueryGenerator.tsx +46 -33
  47. package/src/generators/mutationGenerator.tsx +28 -18
  48. package/src/generators/queryGenerator.tsx +28 -18
  49. package/src/plugin.ts +29 -26
  50. package/src/types.ts +35 -14
  51. package/dist/chunk-CJBEHJ3D.cjs.map +0 -1
  52. package/dist/chunk-CYO3ZQ3K.js.map +0 -1
  53. package/dist/chunk-QS4ZHURK.cjs.map +0 -1
  54. package/dist/chunk-VEQJK4QZ.js.map +0 -1
  55. package/dist/types-BGseXQR_.d.cts +0 -208
  56. package/dist/types-BGseXQR_.d.ts +0 -208
@@ -3,6 +3,7 @@ import { File, Function, FunctionParams } from '@kubb/react'
3
3
  import { type Operation, isOptional } from '@kubb/oas'
4
4
  import type { OperationSchemas } from '@kubb/plugin-oas'
5
5
  import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
6
+ import type { PluginReactQuery } from '@kubb/plugin-react-query'
6
7
  import type { ReactNode } from 'react'
7
8
  import type { PluginVueQuery } from '../types.ts'
8
9
  import { QueryKey } from './QueryKey.tsx'
@@ -18,22 +19,72 @@ type Props = {
18
19
  queryKeyTypeName: string
19
20
  typeSchemas: OperationSchemas
20
21
  operation: Operation
22
+ paramsType: PluginVueQuery['resolvedOptions']['paramsType']
21
23
  pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
22
24
  dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
23
25
  }
24
26
 
25
27
  type GetParamsProps = {
28
+ paramsType: PluginVueQuery['resolvedOptions']['paramsType']
26
29
  pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
27
30
  dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
28
31
  typeSchemas: OperationSchemas
29
32
  }
30
33
 
31
- function getParams({ pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
34
+ function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
32
35
  const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
33
36
 
37
+ if (paramsType === 'object') {
38
+ return FunctionParams.factory({
39
+ data: {
40
+ mode: 'object',
41
+ children: {
42
+ ...getPathParams(typeSchemas.pathParams, {
43
+ typed: true,
44
+ override(item) {
45
+ return {
46
+ ...item,
47
+ type: `MaybeRef<${item.type}>`,
48
+ }
49
+ },
50
+ }),
51
+ data: typeSchemas.request?.name
52
+ ? {
53
+ type: `MaybeRef<${typeSchemas.request?.name}>`,
54
+ optional: isOptional(typeSchemas.request?.schema),
55
+ }
56
+ : undefined,
57
+ params: typeSchemas.queryParams?.name
58
+ ? {
59
+ type: `MaybeRef<${typeSchemas.queryParams?.name}>`,
60
+ optional: isOptional(typeSchemas.queryParams?.schema),
61
+ }
62
+ : undefined,
63
+ headers: typeSchemas.headerParams?.name
64
+ ? {
65
+ type: `MaybeRef<${typeSchemas.headerParams?.name}>`,
66
+ optional: isOptional(typeSchemas.headerParams?.schema),
67
+ }
68
+ : undefined,
69
+ },
70
+ },
71
+ options: {
72
+ type: `
73
+ {
74
+ query?: Partial<QueryObserverOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', 'TData', 'TQueryData', 'TQueryKey'].join(', ')}>>,
75
+ client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'}
76
+ }
77
+ `,
78
+ default: '{}',
79
+ },
80
+ })
81
+ }
82
+
34
83
  return FunctionParams.factory({
35
84
  pathParams: {
36
85
  mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
86
+ type: typeSchemas.pathParams?.name,
87
+ optional: isOptional(typeSchemas.pathParams?.schema),
37
88
  children: getPathParams(typeSchemas.pathParams, {
38
89
  typed: true,
39
90
  override(item) {
@@ -74,7 +125,17 @@ function getParams({ pathParamsType, dataReturnType, typeSchemas }: GetParamsPro
74
125
  })
75
126
  }
76
127
 
77
- export function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, pathParamsType, dataReturnType, typeSchemas, operation }: Props): ReactNode {
128
+ export function Query({
129
+ name,
130
+ queryKeyTypeName,
131
+ queryOptionsName,
132
+ queryKeyName,
133
+ paramsType,
134
+ pathParamsType,
135
+ dataReturnType,
136
+ typeSchemas,
137
+ operation,
138
+ }: Props): ReactNode {
78
139
  const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
79
140
  const returnType = `UseQueryReturnType<${['TData', typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'].join(', ')}> & { queryKey: TQueryKey }`
80
141
  const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`]
@@ -84,10 +145,12 @@ export function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
84
145
  typeSchemas,
85
146
  })
86
147
  const queryOptionsParams = QueryOptions.getParams({
148
+ paramsType,
87
149
  pathParamsType,
88
150
  typeSchemas,
89
151
  })
90
152
  const params = getParams({
153
+ paramsType,
91
154
  pathParamsType,
92
155
  dataReturnType,
93
156
  typeSchemas,
@@ -5,7 +5,7 @@ import { File, Function, FunctionParams, Type } from '@kubb/react'
5
5
  import { type Operation, isOptional } from '@kubb/oas'
6
6
  import type { OperationSchemas } from '@kubb/plugin-oas'
7
7
  import type { ReactNode } from 'react'
8
- import type { PluginVueQuery } from '../types'
8
+ import type { PluginVueQuery, Transformer } from '../types'
9
9
 
10
10
  type Props = {
11
11
  name: string
@@ -13,7 +13,7 @@ type Props = {
13
13
  typeSchemas: OperationSchemas
14
14
  operation: Operation
15
15
  pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
16
- keysFn: ((keys: unknown[]) => unknown[]) | undefined
16
+ transformer: Transformer | undefined
17
17
  }
18
18
 
19
19
  type GetParamsProps = {
@@ -50,23 +50,32 @@ function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
50
50
  })
51
51
  }
52
52
 
53
- export function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, keysFn = (name) => name }: Props): ReactNode {
53
+ const getTransformer: Transformer = ({ operation, schemas }) => {
54
54
  const path = new URLPath(operation.path)
55
- const params = getParams({ pathParamsType, typeSchemas })
56
55
  const keys = [
57
56
  path.toObject({
58
57
  type: 'path',
59
58
  stringify: true,
60
59
  }),
61
- typeSchemas.queryParams?.name ? '...(params ? [params] : [])' : undefined,
62
- typeSchemas.request?.name ? '...(data ? [data] : [])' : undefined,
60
+ schemas.queryParams?.name ? '...(params ? [params] : [])' : undefined,
61
+ schemas.request?.name ? '...(data ? [data] : [])' : undefined,
63
62
  ].filter(Boolean)
64
63
 
64
+ return keys
65
+ }
66
+
67
+ export function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
68
+ const params = getParams({ pathParamsType, typeSchemas })
69
+ const keys = transformer({
70
+ operation,
71
+ schemas: typeSchemas,
72
+ })
73
+
65
74
  return (
66
75
  <>
67
76
  <File.Source name={name} isExportable isIndexable>
68
77
  <Function.Arrow name={name} export params={params.toConstructor()} singleLine>
69
- {`[${keysFn(keys).join(', ')}] as const`}
78
+ {`[${keys.join(', ')}] as const`}
70
79
  </Function.Arrow>
71
80
  </File.Source>
72
81
  <File.Source name={typeName} isExportable isIndexable isTypeOnly>
@@ -79,3 +88,4 @@ export function QueryKey({ name, typeSchemas, pathParamsType, operation, typeNam
79
88
  }
80
89
 
81
90
  QueryKey.getParams = getParams
91
+ QueryKey.getTransformer = getTransformer
@@ -6,6 +6,7 @@ import type { ReactNode } from 'react'
6
6
  import { isOptional } from '@kubb/oas'
7
7
  import { Client } from '@kubb/plugin-client/components'
8
8
  import type { OperationSchemas } from '@kubb/plugin-oas'
9
+ import type { PluginReactQuery } from '@kubb/plugin-react-query'
9
10
  import type { PluginVueQuery } from '../types.ts'
10
11
  import { QueryKey } from './QueryKey.tsx'
11
12
 
@@ -14,18 +15,63 @@ type Props = {
14
15
  clientName: string
15
16
  queryKeyName: string
16
17
  typeSchemas: OperationSchemas
18
+ paramsType: PluginVueQuery['resolvedOptions']['paramsType']
17
19
  pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
18
20
  }
19
21
 
20
22
  type GetParamsProps = {
23
+ paramsType: PluginVueQuery['resolvedOptions']['paramsType']
21
24
  pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
22
25
  typeSchemas: OperationSchemas
23
26
  }
24
27
 
25
- function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
28
+ function getParams({ paramsType, pathParamsType, typeSchemas }: GetParamsProps) {
29
+ if (paramsType === 'object') {
30
+ return FunctionParams.factory({
31
+ data: {
32
+ mode: 'object',
33
+ children: {
34
+ ...getPathParams(typeSchemas.pathParams, {
35
+ typed: true,
36
+ override(item) {
37
+ return {
38
+ ...item,
39
+ type: `MaybeRef<${item.type}>`,
40
+ }
41
+ },
42
+ }),
43
+ data: typeSchemas.request?.name
44
+ ? {
45
+ type: `MaybeRef<${typeSchemas.request?.name}>`,
46
+ optional: isOptional(typeSchemas.request?.schema),
47
+ }
48
+ : undefined,
49
+ params: typeSchemas.queryParams?.name
50
+ ? {
51
+ type: `MaybeRef<${typeSchemas.queryParams?.name}>`,
52
+ optional: isOptional(typeSchemas.queryParams?.schema),
53
+ }
54
+ : undefined,
55
+ headers: typeSchemas.headerParams?.name
56
+ ? {
57
+ type: `MaybeRef<${typeSchemas.queryParams?.name}>`,
58
+ optional: isOptional(typeSchemas.headerParams?.schema),
59
+ }
60
+ : undefined,
61
+ },
62
+ },
63
+ config: {
64
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>',
65
+ default: '{}',
66
+ },
67
+ })
68
+ }
69
+
26
70
  return FunctionParams.factory({
27
71
  pathParams: {
28
72
  mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
73
+ type: typeSchemas.pathParams?.name,
74
+ optional: isOptional(typeSchemas.pathParams?.schema),
29
75
  children: getPathParams(typeSchemas.pathParams, {
30
76
  typed: true,
31
77
  override(item) {
@@ -61,9 +107,10 @@ function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
61
107
  })
62
108
  }
63
109
 
64
- export function QueryOptions({ name, clientName, typeSchemas, pathParamsType, queryKeyName }: Props): ReactNode {
65
- const params = getParams({ pathParamsType, typeSchemas })
110
+ export function QueryOptions({ name, clientName, typeSchemas, paramsType, pathParamsType, queryKeyName }: Props): ReactNode {
111
+ const params = getParams({ paramsType, pathParamsType, typeSchemas })
66
112
  const clientParams = Client.getParams({
113
+ paramsType,
67
114
  typeSchemas,
68
115
  pathParamsType,
69
116
  })
@@ -2,7 +2,7 @@ import client from "@kubb/plugin-client/client";
2
2
  import type { RequestConfig, ResponseConfig } from "@kubb/plugin-client/client";
3
3
  import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "@tanstack/react-query";
4
4
  import type { MaybeRef } from "vue";
5
- import { useQuery, queryOptions } from "@tanstack/react-query";
5
+ import { queryOptions, useQuery } from "@tanstack/react-query";
6
6
  import { unref } from "vue";
7
7
 
8
8
  export const findPetsByTagsQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
@@ -2,7 +2,7 @@ import client from "axios";
2
2
  import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "@tanstack/react-query";
3
3
  import type { RequestConfig } from "axios";
4
4
  import type { MaybeRef } from "vue";
5
- import { useQuery, queryOptions } from "@tanstack/react-query";
5
+ import { queryOptions, useQuery } from "@tanstack/react-query";
6
6
  import { unref } from "vue";
7
7
 
8
8
  export const findPetsByTagsQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
@@ -1,8 +1,8 @@
1
1
  import client from "axios";
2
- import type { MutationObserverOptions } from "@tanstack/react-query";
2
+ import type { MutationObserverOptions } from "@tanstack/vue-query";
3
3
  import type { RequestConfig } from "axios";
4
4
  import type { MaybeRef } from "vue";
5
- import { useMutation } from "@tanstack/react-query";
5
+ import { useMutation } from "@tanstack/vue-query";
6
6
 
7
7
  export const updatePetWithFormMutationKey = () => [{ "url": "/pet/{petId}" }] as const;
8
8
 
@@ -2,7 +2,7 @@ import client from "@kubb/plugin-client/client";
2
2
  import type { RequestConfig } from "@kubb/plugin-client/client";
3
3
  import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "@tanstack/react-query";
4
4
  import type { MaybeRef } from "vue";
5
- import { useQuery, queryOptions } from "@tanstack/react-query";
5
+ import { queryOptions, useQuery } from "@tanstack/react-query";
6
6
  import { unref } from "vue";
7
7
 
8
8
  export const findPetsByTagsQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
@@ -0,0 +1,62 @@
1
+ import client from "@kubb/plugin-client/client";
2
+ import type { RequestConfig } from "@kubb/plugin-client/client";
3
+ import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "@tanstack/react-query";
4
+ import type { MaybeRef } from "vue";
5
+ import { queryOptions, useQuery } from "@tanstack/react-query";
6
+ import { unref } from "vue";
7
+
8
+ export const findPetsByTagsQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
9
+
10
+ export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
11
+
12
+ /**
13
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
14
+ * @summary Finds Pets by tags
15
+ * @link /pet/findByTags
16
+ */
17
+ async function findPetsByTags({ headers, params }: {
18
+ headers: FindPetsByTagsHeaderParams;
19
+ params?: FindPetsByTagsQueryParams;
20
+ }, config: Partial<RequestConfig> = {}) {
21
+ const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "GET", url: `/pet/findByTags`, params, headers: { ...headers, ...config.headers }, ...config });
22
+ return findPetsByTagsQueryResponse.parse(res.data);
23
+ }
24
+
25
+ export function findPetsByTagsQueryOptions({ headers, params }: {
26
+ headers: MaybeRef<FindPetsByTagsQueryParams>;
27
+ params?: MaybeRef<FindPetsByTagsQueryParams>;
28
+ }, config: Partial<RequestConfig> = {}) {
29
+ const queryKey = findPetsByTagsQueryKey(params);
30
+ return queryOptions({
31
+ queryKey,
32
+ queryFn: async ({ signal }) => {
33
+ config.signal = signal;
34
+ return findPetsByTags(unref({ headers: unref(headers), params: unref(params) }), unref(config));
35
+ },
36
+ });
37
+ }
38
+
39
+ /**
40
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
41
+ * @summary Finds Pets by tags
42
+ * @link /pet/findByTags
43
+ */
44
+ export function useFindPetsByTags<TData = FindPetsByTagsQueryResponse, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsQueryKey>({ headers, params }: {
45
+ headers: MaybeRef<FindPetsByTagsHeaderParams>;
46
+ params?: MaybeRef<FindPetsByTagsQueryParams>;
47
+ }, options: {
48
+ query?: Partial<QueryObserverOptions<FindPetsByTagsQueryResponse, FindPetsByTags400, TData, TQueryData, TQueryKey>>;
49
+ client?: Partial<RequestConfig>;
50
+ } = {}) {
51
+ const { query: queryOptions, client: config = {} } = options ?? {};
52
+ const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params);
53
+ const query = useQuery({
54
+ ...findPetsByTagsQueryOptions({ headers, params }, config) as unknown as QueryObserverOptions,
55
+ queryKey: queryKey as QueryKey,
56
+ ...queryOptions as unknown as Omit<QueryObserverOptions, "queryKey">
57
+ }) as UseQueryReturnType<TData, FindPetsByTags400> & {
58
+ queryKey: TQueryKey;
59
+ };
60
+ query.queryKey = queryKey as TQueryKey;
61
+ return query;
62
+ }
@@ -2,7 +2,7 @@ import client from "@kubb/plugin-client/client";
2
2
  import type { RequestConfig } from "@kubb/plugin-client/client";
3
3
  import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "@tanstack/react-query";
4
4
  import type { MaybeRef } from "vue";
5
- import { useQuery, queryOptions } from "@tanstack/react-query";
5
+ import { queryOptions, useQuery } from "@tanstack/react-query";
6
6
  import { unref } from "vue";
7
7
 
8
8
  export const findPetsByTagsQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
@@ -2,10 +2,10 @@ import client from "@kubb/plugin-client/client";
2
2
  import type { RequestConfig } from "@kubb/plugin-client/client";
3
3
  import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "@tanstack/react-query";
4
4
  import type { MaybeRef } from "vue";
5
- import { useQuery, queryOptions } from "@tanstack/react-query";
5
+ import { queryOptions, useQuery } from "@tanstack/react-query";
6
6
  import { unref } from "vue";
7
7
 
8
- export const findPetsByTagsQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [test, { url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
8
+ export const findPetsByTagsQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => ["test", { url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
9
9
 
10
10
  export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
11
11
 
@@ -2,7 +2,7 @@ import client from "@kubb/plugin-client/client";
2
2
  import type { RequestConfig } from "@kubb/plugin-client/client";
3
3
  import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "@tanstack/react-query";
4
4
  import type { MaybeRef } from "vue";
5
- import { useQuery, queryOptions } from "@tanstack/react-query";
5
+ import { queryOptions, useQuery } from "@tanstack/react-query";
6
6
  import { unref } from "vue";
7
7
 
8
8
  export const findPetsByTagsQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
@@ -1,8 +1,8 @@
1
1
  import client from "@kubb/plugin-client/client";
2
2
  import type { RequestConfig } from "@kubb/plugin-client/client";
3
- import type { QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryReturnType } from "@tanstack/react-query";
3
+ import type { InfiniteData, QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryReturnType } from "@tanstack/react-query";
4
4
  import type { MaybeRef } from "vue";
5
- import { useInfiniteQuery, infiniteQueryOptions } from "@tanstack/react-query";
5
+ import { infiniteQueryOptions, useInfiniteQuery } from "@tanstack/react-query";
6
6
 
7
7
  export const findPetsByTagsInfiniteQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
8
8
 
@@ -40,7 +40,7 @@ async function findPetsByTags(headers: FindPetsByTagsHeaderParams, params?: Find
40
40
  * @summary Finds Pets by tags
41
41
  * @link /pet/findByTags
42
42
  */
43
- export function useFindPetsByTagsInfinite<TData = FindPetsByTagsQueryResponse, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsInfiniteQueryKey>(headers: MaybeRef<FindPetsByTagsHeaderParams>, params?: MaybeRef<FindPetsByTagsQueryParams>, options: {
43
+ export function useFindPetsByTagsInfinite<TData = InfiniteData<FindPetsByTagsQueryResponse>, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsInfiniteQueryKey>(headers: MaybeRef<FindPetsByTagsHeaderParams>, params?: MaybeRef<FindPetsByTagsQueryParams>, options: {
44
44
  query?: Partial<InfiniteQueryObserverOptions<FindPetsByTagsQueryResponse, FindPetsByTags400, TData, TQueryData, TQueryKey>>;
45
45
  client?: Partial<RequestConfig>;
46
46
  } = {}) {
@@ -1,8 +1,8 @@
1
1
  import client from "@kubb/plugin-client/client";
2
2
  import type { RequestConfig } from "@kubb/plugin-client/client";
3
- import type { QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryReturnType } from "@tanstack/react-query";
3
+ import type { InfiniteData, QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryReturnType } from "@tanstack/react-query";
4
4
  import type { MaybeRef } from "vue";
5
- import { useInfiniteQuery, infiniteQueryOptions } from "@tanstack/react-query";
5
+ import { infiniteQueryOptions, useInfiniteQuery } from "@tanstack/react-query";
6
6
 
7
7
  export const findPetsByTagsInfiniteQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
8
8
 
@@ -40,7 +40,7 @@ async function findPetsByTags(headers: FindPetsByTagsHeaderParams, params?: Find
40
40
  * @summary Finds Pets by tags
41
41
  * @link /pet/findByTags
42
42
  */
43
- export function useFindPetsByTagsInfinite<TData = FindPetsByTagsQueryResponse, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsInfiniteQueryKey>(headers: MaybeRef<FindPetsByTagsHeaderParams>, params?: MaybeRef<FindPetsByTagsQueryParams>, options: {
43
+ export function useFindPetsByTagsInfinite<TData = InfiniteData<FindPetsByTagsQueryResponse>, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsInfiniteQueryKey>(headers: MaybeRef<FindPetsByTagsHeaderParams>, params?: MaybeRef<FindPetsByTagsQueryParams>, options: {
44
44
  query?: Partial<InfiniteQueryObserverOptions<FindPetsByTagsQueryResponse, FindPetsByTags400, TData, TQueryData, TQueryKey>>;
45
45
  client?: Partial<RequestConfig>;
46
46
  } = {}) {
@@ -2,7 +2,7 @@ import client from "@kubb/plugin-client/client";
2
2
  import type { RequestConfig } from "@kubb/plugin-client/client";
3
3
  import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "custom-query";
4
4
  import type { MaybeRef } from "vue";
5
- import { useQuery, queryOptions } from "custom-query";
5
+ import { queryOptions, useQuery } from "custom-query";
6
6
  import { unref } from "vue";
7
7
 
8
8
  export const updatePetWithFormQueryKey = (petId: MaybeRef<UpdatePetWithFormPathParams["petId"]>, data?: MaybeRef<UpdatePetWithFormMutationRequest>, params?: MaybeRef<UpdatePetWithFormQueryParams>) => [{ url: "/pet/:petId", params: { petId: petId } }, ...(params ? [params] : []), ...(data ? [data] : [])] as const;
@@ -1,8 +1,8 @@
1
1
  import client from "@kubb/plugin-client/client";
2
2
  import type { RequestConfig } from "@kubb/plugin-client/client";
3
- import type { MutationObserverOptions } from "@tanstack/react-query";
3
+ import type { MutationObserverOptions } from "@tanstack/vue-query";
4
4
  import type { MaybeRef } from "vue";
5
- import { useMutation } from "@tanstack/react-query";
5
+ import { useMutation } from "@tanstack/vue-query";
6
6
 
7
7
  export const updatePetWithFormMutationKey = () => [{ "url": "/pet/{petId}" }] as const;
8
8
 
@@ -1,8 +1,8 @@
1
1
  import client from "@kubb/plugin-client/client";
2
2
  import type { RequestConfig } from "@kubb/plugin-client/client";
3
- import type { MutationObserverOptions } from "@tanstack/react-query";
3
+ import type { MutationObserverOptions } from "@tanstack/vue-query";
4
4
  import type { MaybeRef } from "vue";
5
- import { useMutation } from "@tanstack/react-query";
5
+ import { useMutation } from "@tanstack/vue-query";
6
6
 
7
7
  export const updatePetWithFormMutationKey = () => [{ "url": "/pet/{petId}" }] as const;
8
8
 
@@ -12,9 +12,7 @@ import { useMutation } from "@tanstack/react-query";
12
12
  * @summary Updates a pet in the store with form data
13
13
  * @link /pet/:petId
14
14
  */
15
- async function updatePetWithForm({ petId }: {
16
- petId: UpdatePetWithFormPathParams["petId"];
17
- }, data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> = {}) {
15
+ async function updatePetWithForm({ petId }: UpdatePetWithFormPathParams, data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> = {}) {
18
16
  const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationRequest>({ method: "POST", url: `/pet/${petId}`, params, data, ...config });
19
17
  return updatePetWithFormMutationResponse.parse(res.data);
20
18
  }
@@ -1,4 +1,3 @@
1
- import transformers from '@kubb/core/transformers'
2
1
  import { pluginClientName } from '@kubb/plugin-client'
3
2
  import { Client } from '@kubb/plugin-client/components'
4
3
  import { createReactGenerator } from '@kubb/plugin-oas'
@@ -6,6 +5,7 @@ import { useOperationManager } from '@kubb/plugin-oas/hooks'
6
5
  import { pluginTsName } from '@kubb/plugin-ts'
7
6
  import { pluginZodName } from '@kubb/plugin-zod'
8
7
  import { File, useApp } from '@kubb/react'
8
+ import { difference } from 'remeda'
9
9
  import { InfiniteQuery, InfiniteQueryOptions, QueryKey } from '../components'
10
10
  import type { PluginVueQuery } from '../types'
11
11
 
@@ -18,8 +18,13 @@ export const infiniteQueryGenerator = createReactGenerator<PluginVueQuery>({
18
18
  },
19
19
  } = useApp<PluginVueQuery>()
20
20
  const { getSchemas, getName, getFile } = useOperationManager()
21
- const isQuery = typeof options.query === 'boolean' ? options.query : !!options.query.methods?.some((method) => operation.method === method)
21
+
22
+ const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
23
+ const isMutation = difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some(
24
+ (method) => operation.method === method,
25
+ )
22
26
  const isInfinite = isQuery && !!options.infinite
27
+ const importPath = options.query ? options.query.importPath : '@tanstack/vue-query'
23
28
 
24
29
  const query = {
25
30
  name: getName(operation, { type: 'function', prefix: 'use', suffix: 'infinite' }),
@@ -51,19 +56,13 @@ export const infiniteQueryGenerator = createReactGenerator<PluginVueQuery>({
51
56
  schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
52
57
  }
53
58
 
54
- if (!isQuery || !isInfinite || typeof options.query === 'boolean' || typeof options.infinite === 'boolean') {
59
+ if (!isQuery || isMutation || !isInfinite) {
55
60
  return null
56
61
  }
57
62
 
58
63
  return (
59
64
  <File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
60
65
  {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
61
- <File.Import name={['useInfiniteQuery', 'infiniteQueryOptions']} path={options.query.importPath} />
62
- <File.Import
63
- name={['QueryKey', 'WithRequired', 'InfiniteQueryObserverOptions', 'UseInfiniteQueryReturnType']}
64
- path={options.query.importPath}
65
- isTypeOnly
66
- />
67
66
  <File.Import name={['unref']} path="vue" />
68
67
  <File.Import name={['MaybeRef']} path="vue" isTypeOnly />
69
68
  <File.Import name={'client'} path={options.client.importPath} />
@@ -82,48 +81,62 @@ export const infiniteQueryGenerator = createReactGenerator<PluginVueQuery>({
82
81
  path={type.file.path}
83
82
  isTypeOnly
84
83
  />
85
-
86
84
  <QueryKey
87
85
  name={queryKey.name}
88
86
  typeName={queryKey.typeName}
89
87
  operation={operation}
90
88
  pathParamsType={options.pathParamsType}
91
89
  typeSchemas={type.schemas}
92
- keysFn={options.query.key}
90
+ transformer={options.queryKey}
93
91
  />
94
92
  <Client
95
93
  name={client.name}
96
94
  isExportable={false}
97
95
  isIndexable={false}
98
- baseURL={options.baseURL}
96
+ baseURL={options.client.baseURL}
99
97
  operation={operation}
100
98
  typeSchemas={type.schemas}
101
99
  zodSchemas={zod.schemas}
102
100
  dataReturnType={options.client.dataReturnType}
101
+ paramsType={options.paramsType}
103
102
  pathParamsType={options.pathParamsType}
104
103
  parser={options.parser}
105
104
  />
106
- <InfiniteQueryOptions
107
- name={queryOptions.name}
108
- clientName={client.name}
109
- queryKeyName={queryKey.name}
110
- typeSchemas={type.schemas}
111
- pathParamsType={options.pathParamsType}
112
- dataReturnType={options.client.dataReturnType}
113
- cursorParam={options.infinite.cursorParam}
114
- initialPageParam={options.infinite.initialPageParam}
115
- queryParam={options.infinite.queryParam}
116
- />
117
- <InfiniteQuery
118
- name={query.name}
119
- queryOptionsName={queryOptions.name}
120
- typeSchemas={type.schemas}
121
- pathParamsType={options.pathParamsType}
122
- operation={operation}
123
- dataReturnType={options.client.dataReturnType}
124
- queryKeyName={queryKey.name}
125
- queryKeyTypeName={queryKey.typeName}
126
- />
105
+ {options.infinite && (
106
+ <>
107
+ <File.Import name={['InfiniteData']} isTypeOnly path={importPath} />
108
+ <File.Import name={['infiniteQueryOptions']} path={importPath} />
109
+ <InfiniteQueryOptions
110
+ name={queryOptions.name}
111
+ clientName={client.name}
112
+ queryKeyName={queryKey.name}
113
+ typeSchemas={type.schemas}
114
+ paramsType={options.paramsType}
115
+ pathParamsType={options.pathParamsType}
116
+ dataReturnType={options.client.dataReturnType}
117
+ cursorParam={options.infinite.cursorParam}
118
+ initialPageParam={options.infinite.initialPageParam}
119
+ queryParam={options.infinite.queryParam}
120
+ />
121
+ </>
122
+ )}
123
+ {options.infinite && (
124
+ <>
125
+ <File.Import name={['useInfiniteQuery']} path={importPath} />
126
+ <File.Import name={['QueryKey', 'InfiniteQueryObserverOptions', 'UseInfiniteQueryReturnType']} path={importPath} isTypeOnly />
127
+ <InfiniteQuery
128
+ name={query.name}
129
+ queryOptionsName={queryOptions.name}
130
+ typeSchemas={type.schemas}
131
+ paramsType={options.paramsType}
132
+ pathParamsType={options.pathParamsType}
133
+ operation={operation}
134
+ dataReturnType={options.client.dataReturnType}
135
+ queryKeyName={queryKey.name}
136
+ queryKeyTypeName={queryKey.typeName}
137
+ />
138
+ </>
139
+ )}
127
140
  </File>
128
141
  )
129
142
  },