@kubb/plugin-react-query 3.0.0-alpha.25 → 3.0.0-alpha.28
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/{chunk-LVNFQQCW.js → chunk-BOVVCZJU.js} +42 -34
- package/dist/chunk-BOVVCZJU.js.map +1 -0
- package/dist/{chunk-JQG3RE3G.js → chunk-GTYG4K3C.js} +10 -10
- package/dist/chunk-GTYG4K3C.js.map +1 -0
- package/dist/{chunk-2V7DVJ3R.cjs → chunk-X4I3L6R3.cjs} +42 -34
- package/dist/chunk-X4I3L6R3.cjs.map +1 -0
- package/dist/{chunk-KGO62EU6.cjs → chunk-YRP4CXZA.cjs} +27 -27
- package/dist/chunk-YRP4CXZA.cjs.map +1 -0
- package/dist/components.cjs +9 -9
- package/dist/components.d.cts +2 -3
- package/dist/components.d.ts +2 -3
- package/dist/components.js +1 -1
- package/dist/generators.cjs +6 -6
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +2 -2
- package/dist/index.cjs +4 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/{types-7237pKeo.d.cts → types-rJasmoxy.d.cts} +5 -1
- package/dist/{types-7237pKeo.d.ts → types-rJasmoxy.d.ts} +5 -1
- package/package.json +12 -12
- package/src/components/InfiniteQuery.tsx +1 -1
- package/src/components/Mutation.tsx +46 -36
- package/src/components/Query.tsx +1 -1
- package/src/components/SuspenseQuery.tsx +1 -1
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +2 -2
- package/src/generators/__snapshots__/clientGetImportPath.ts +2 -2
- package/src/generators/__snapshots__/clientPostImportPath.ts +9 -12
- package/src/generators/__snapshots__/findByTags.ts +2 -2
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +2 -2
- package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +2 -2
- package/src/generators/__snapshots__/findByTagsWithZod.ts +2 -2
- package/src/generators/__snapshots__/findInfiniteByTags.ts +2 -2
- package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +2 -2
- package/src/generators/__snapshots__/postAsQuery.ts +2 -2
- package/src/generators/__snapshots__/updatePetById.ts +9 -12
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +9 -12
- package/src/generators/infiniteQueryGenerator.tsx +1 -1
- package/src/generators/mutationGenerator.tsx +1 -2
- package/src/generators/queryGenerator.tsx +1 -1
- package/src/generators/suspenseQueryGenerator.tsx +1 -1
- package/src/plugin.ts +2 -1
- package/src/types.ts +6 -1
- package/dist/chunk-2V7DVJ3R.cjs.map +0 -1
- package/dist/chunk-JQG3RE3G.js.map +0 -1
- package/dist/chunk-KGO62EU6.cjs.map +0 -1
- package/dist/chunk-LVNFQQCW.js.map +0 -1
|
@@ -4,6 +4,7 @@ import { type Operation, isOptional } from '@kubb/oas'
|
|
|
4
4
|
import { Client } from '@kubb/plugin-client/components'
|
|
5
5
|
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
6
6
|
import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
|
|
7
|
+
import type { Params } from '@kubb/react/types'
|
|
7
8
|
import type { ReactNode } from 'react'
|
|
8
9
|
import type { PluginReactQuery } from '../types.ts'
|
|
9
10
|
import { MutationKey } from './MutationKey.tsx'
|
|
@@ -16,7 +17,6 @@ type Props = {
|
|
|
16
17
|
typeName: string
|
|
17
18
|
clientName: string
|
|
18
19
|
mutationKeyName: string
|
|
19
|
-
mutationKeyTypeName: string
|
|
20
20
|
typeSchemas: OperationSchemas
|
|
21
21
|
operation: Operation
|
|
22
22
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
@@ -31,7 +31,7 @@ type GetParamsProps = {
|
|
|
31
31
|
|
|
32
32
|
function getParams({ dataReturnType, typeSchemas }: GetParamsProps) {
|
|
33
33
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
34
|
-
const
|
|
34
|
+
const mutationParams = FunctionParams.factory({
|
|
35
35
|
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
36
36
|
data: typeSchemas.request?.name
|
|
37
37
|
? {
|
|
@@ -52,13 +52,14 @@ function getParams({ dataReturnType, typeSchemas }: GetParamsProps) {
|
|
|
52
52
|
}
|
|
53
53
|
: undefined,
|
|
54
54
|
})
|
|
55
|
-
const TRequest =
|
|
55
|
+
const TRequest = mutationParams.toConstructor({ valueAsType: true })
|
|
56
|
+
const generics = [TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', `{${TRequest}}`].join(', ')
|
|
56
57
|
|
|
57
58
|
return FunctionParams.factory({
|
|
58
59
|
options: {
|
|
59
60
|
type: `
|
|
60
61
|
{
|
|
61
|
-
mutation?: UseMutationOptions<${
|
|
62
|
+
mutation?: UseMutationOptions<${generics}>,
|
|
62
63
|
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'},
|
|
63
64
|
}
|
|
64
65
|
`,
|
|
@@ -67,9 +68,7 @@ function getParams({ dataReturnType, typeSchemas }: GetParamsProps) {
|
|
|
67
68
|
})
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
export function Mutation({ name, clientName, pathParamsType, dataReturnType, typeSchemas, operation,
|
|
71
|
-
const returnType = 'ReturnType<typeof mutation> & { mutationKey: MutationKey }'
|
|
72
|
-
|
|
71
|
+
export function Mutation({ name, clientName, pathParamsType, dataReturnType, typeSchemas, operation, mutationKeyName }: Props): ReactNode {
|
|
73
72
|
const mutationKeyParams = MutationKey.getParams({
|
|
74
73
|
pathParamsType,
|
|
75
74
|
typeSchemas,
|
|
@@ -87,35 +86,49 @@ export function Mutation({ name, clientName, pathParamsType, dataReturnType, typ
|
|
|
87
86
|
})
|
|
88
87
|
|
|
89
88
|
const mutationParams = FunctionParams.factory({
|
|
89
|
+
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
90
|
+
data: typeSchemas.request?.name
|
|
91
|
+
? {
|
|
92
|
+
type: typeSchemas.request?.name,
|
|
93
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
94
|
+
}
|
|
95
|
+
: undefined,
|
|
96
|
+
params: typeSchemas.queryParams?.name
|
|
97
|
+
? {
|
|
98
|
+
type: typeSchemas.queryParams?.name,
|
|
99
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
100
|
+
}
|
|
101
|
+
: undefined,
|
|
102
|
+
headers: typeSchemas.headerParams?.name
|
|
103
|
+
? {
|
|
104
|
+
type: typeSchemas.headerParams?.name,
|
|
105
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
106
|
+
}
|
|
107
|
+
: undefined,
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
const dataParams = FunctionParams.factory({
|
|
90
111
|
data: {
|
|
91
112
|
// No use of pathParams because useMutation can only take one argument in object form,
|
|
92
113
|
// see https://tanstack.com/query/latest/docs/framework/react/reference/useMutation#usemutation
|
|
93
114
|
mode: 'object',
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
? {
|
|
105
|
-
type: typeSchemas.queryParams?.name,
|
|
106
|
-
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
107
|
-
}
|
|
108
|
-
: undefined,
|
|
109
|
-
headers: typeSchemas.headerParams?.name
|
|
110
|
-
? {
|
|
111
|
-
type: typeSchemas.headerParams?.name,
|
|
112
|
-
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
113
|
-
}
|
|
114
|
-
: undefined,
|
|
115
|
-
},
|
|
115
|
+
children: Object.entries(mutationParams.params).reduce((acc, [key, value]) => {
|
|
116
|
+
if (value) {
|
|
117
|
+
acc[key] = {
|
|
118
|
+
...value,
|
|
119
|
+
type: undefined,
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return acc
|
|
124
|
+
}, {} as Params),
|
|
116
125
|
},
|
|
117
126
|
})
|
|
118
127
|
|
|
128
|
+
const TRequest = mutationParams.toConstructor({ valueAsType: true })
|
|
129
|
+
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
130
|
+
const generics = [TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', `{${TRequest}}`].join(', ')
|
|
131
|
+
|
|
119
132
|
return (
|
|
120
133
|
<File.Source name={name} isExportable isIndexable>
|
|
121
134
|
<Function
|
|
@@ -130,16 +143,13 @@ export function Mutation({ name, clientName, pathParamsType, dataReturnType, typ
|
|
|
130
143
|
const { mutation: mutationOptions, client: config = {} } = options ?? {}
|
|
131
144
|
const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}(${mutationKeyParams.toCall()})
|
|
132
145
|
|
|
133
|
-
|
|
134
|
-
mutationFn: async(${
|
|
146
|
+
return useMutation<${generics}>({
|
|
147
|
+
mutationFn: async(${dataParams.toConstructor()}) => {
|
|
135
148
|
return ${clientName}(${clientParams.toCall()})
|
|
136
149
|
},
|
|
150
|
+
mutationKey,
|
|
137
151
|
...mutationOptions
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
mutation.mutationKey = mutationKey as MutationKey
|
|
141
|
-
|
|
142
|
-
return mutation
|
|
152
|
+
})
|
|
143
153
|
`}
|
|
144
154
|
</Function>
|
|
145
155
|
</File.Source>
|
package/src/components/Query.tsx
CHANGED
|
@@ -68,7 +68,7 @@ function getParams({ pathParamsType, dataReturnType, typeSchemas }: GetParamsPro
|
|
|
68
68
|
|
|
69
69
|
export function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, pathParamsType, dataReturnType, typeSchemas, operation }: Props): ReactNode {
|
|
70
70
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
71
|
-
const returnType = '
|
|
71
|
+
const returnType = `UseQueryResult<${['TData', typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'].join(', ')}> & { queryKey: TQueryKey }`
|
|
72
72
|
const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`]
|
|
73
73
|
|
|
74
74
|
const queryKeyParams = QueryKey.getParams({
|
|
@@ -77,7 +77,7 @@ export function SuspenseQuery({
|
|
|
77
77
|
operation,
|
|
78
78
|
}: Props): ReactNode {
|
|
79
79
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
80
|
-
const returnType = '
|
|
80
|
+
const returnType = `UseSuspenseQueryResult<${['TData', typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'].join(', ')}> & { queryKey: TQueryKey }`
|
|
81
81
|
const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`]
|
|
82
82
|
|
|
83
83
|
const queryKeyParams = QueryKey.getParams({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig, ResponseConfig } from "@kubb/plugin-client/client";
|
|
3
|
-
import type { QueryKey, QueryObserverOptions } from "@tanstack/react-query";
|
|
3
|
+
import type { QueryKey, QueryObserverOptions, UseQueryResult } from "@tanstack/react-query";
|
|
4
4
|
import { useQuery, queryOptions } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
@@ -42,7 +42,7 @@ export function useFindPetsByTags<TData = ResponseConfig<FindPetsByTagsQueryResp
|
|
|
42
42
|
...findPetsByTagsQueryOptions(headers, params, config) as unknown as QueryObserverOptions,
|
|
43
43
|
queryKey,
|
|
44
44
|
...queryOptions as unknown as Omit<QueryObserverOptions, "queryKey">
|
|
45
|
-
}) as
|
|
45
|
+
}) as UseQueryResult<TData, FindPetsByTags400> & {
|
|
46
46
|
queryKey: TQueryKey;
|
|
47
47
|
};
|
|
48
48
|
query.queryKey = queryKey as TQueryKey;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import client from "axios";
|
|
2
|
-
import type { QueryKey, QueryObserverOptions } from "@tanstack/react-query";
|
|
2
|
+
import type { QueryKey, QueryObserverOptions, UseQueryResult } from "@tanstack/react-query";
|
|
3
3
|
import type { RequestConfig } from "axios";
|
|
4
4
|
import { useQuery, queryOptions } from "@tanstack/react-query";
|
|
5
5
|
|
|
@@ -42,7 +42,7 @@ export function useFindPetsByTags<TData = FindPetsByTagsQueryResponse, TQueryDat
|
|
|
42
42
|
...findPetsByTagsQueryOptions(headers, params, config) as unknown as QueryObserverOptions,
|
|
43
43
|
queryKey,
|
|
44
44
|
...queryOptions as unknown as Omit<QueryObserverOptions, "queryKey">
|
|
45
|
-
}) as
|
|
45
|
+
}) as UseQueryResult<TData, FindPetsByTags400> & {
|
|
46
46
|
queryKey: TQueryKey;
|
|
47
47
|
};
|
|
48
48
|
query.queryKey = queryKey as TQueryKey;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import client from "axios";
|
|
2
|
-
import type { UseMutationOptions
|
|
2
|
+
import type { UseMutationOptions } from "@tanstack/react-query";
|
|
3
3
|
import type { RequestConfig } from "axios";
|
|
4
4
|
import { useMutation } from "@tanstack/react-query";
|
|
5
5
|
|
|
@@ -30,18 +30,15 @@ export function useUpdatePetWithForm(options: {
|
|
|
30
30
|
} = {}) {
|
|
31
31
|
const { mutation: mutationOptions, client: config = {} } = options ?? {};
|
|
32
32
|
const mutationKey = mutationOptions?.mutationKey ?? updatePetWithFormMutationKey();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}) => {
|
|
33
|
+
return useMutation<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, {
|
|
34
|
+
petId: UpdatePetWithFormPathParams["petId"];
|
|
35
|
+
data?: UpdatePetWithFormMutationRequest;
|
|
36
|
+
params?: UpdatePetWithFormQueryParams;
|
|
37
|
+
}>({
|
|
38
|
+
mutationFn: async ({ petId, data, params }) => {
|
|
39
39
|
return updatePetWithForm(petId, data, params, config);
|
|
40
40
|
},
|
|
41
|
+
mutationKey,
|
|
41
42
|
...mutationOptions
|
|
42
|
-
})
|
|
43
|
-
mutationKey: MutationKey;
|
|
44
|
-
};
|
|
45
|
-
mutation.mutationKey = mutationKey as MutationKey;
|
|
46
|
-
return mutation;
|
|
43
|
+
});
|
|
47
44
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
|
-
import type { QueryKey, QueryObserverOptions } from "@tanstack/react-query";
|
|
3
|
+
import type { QueryKey, QueryObserverOptions, UseQueryResult } from "@tanstack/react-query";
|
|
4
4
|
import { useQuery, queryOptions } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
@@ -42,7 +42,7 @@ export function useFindPetsByTags<TData = FindPetsByTagsQueryResponse, TQueryDat
|
|
|
42
42
|
...findPetsByTagsQueryOptions(headers, params, config) as unknown as QueryObserverOptions,
|
|
43
43
|
queryKey,
|
|
44
44
|
...queryOptions as unknown as Omit<QueryObserverOptions, "queryKey">
|
|
45
|
-
}) as
|
|
45
|
+
}) as UseQueryResult<TData, FindPetsByTags400> & {
|
|
46
46
|
queryKey: TQueryKey;
|
|
47
47
|
};
|
|
48
48
|
query.queryKey = queryKey as TQueryKey;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
|
-
import type { QueryKey, QueryObserverOptions } from "@tanstack/react-query";
|
|
3
|
+
import type { QueryKey, QueryObserverOptions, UseQueryResult } from "@tanstack/react-query";
|
|
4
4
|
import { useQuery, queryOptions } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
@@ -42,7 +42,7 @@ export function useFindPetsByTags<TData = FindPetsByTagsQueryResponse, TQueryDat
|
|
|
42
42
|
...findPetsByTagsQueryOptions(headers, params, config) as unknown as QueryObserverOptions,
|
|
43
43
|
queryKey,
|
|
44
44
|
...queryOptions as unknown as Omit<QueryObserverOptions, "queryKey">
|
|
45
|
-
}) as
|
|
45
|
+
}) as UseQueryResult<TData, FindPetsByTags400> & {
|
|
46
46
|
queryKey: TQueryKey;
|
|
47
47
|
};
|
|
48
48
|
query.queryKey = queryKey as TQueryKey;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
|
-
import type { QueryKey, QueryObserverOptions } from "@tanstack/react-query";
|
|
3
|
+
import type { QueryKey, QueryObserverOptions, UseQueryResult } from "@tanstack/react-query";
|
|
4
4
|
import { useQuery, queryOptions } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [test, { url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
@@ -42,7 +42,7 @@ export function useFindPetsByTags<TData = FindPetsByTagsQueryResponse, TQueryDat
|
|
|
42
42
|
...findPetsByTagsQueryOptions(headers, params, config) as unknown as QueryObserverOptions,
|
|
43
43
|
queryKey,
|
|
44
44
|
...queryOptions as unknown as Omit<QueryObserverOptions, "queryKey">
|
|
45
|
-
}) as
|
|
45
|
+
}) as UseQueryResult<TData, FindPetsByTags400> & {
|
|
46
46
|
queryKey: TQueryKey;
|
|
47
47
|
};
|
|
48
48
|
query.queryKey = queryKey as TQueryKey;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
|
-
import type { QueryKey, QueryObserverOptions } from "@tanstack/react-query";
|
|
3
|
+
import type { QueryKey, QueryObserverOptions, UseQueryResult } from "@tanstack/react-query";
|
|
4
4
|
import { useQuery, queryOptions } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
@@ -42,7 +42,7 @@ export function useFindPetsByTags<TData = FindPetsByTagsQueryResponse, TQueryDat
|
|
|
42
42
|
...findPetsByTagsQueryOptions(headers, params, config) as unknown as QueryObserverOptions,
|
|
43
43
|
queryKey,
|
|
44
44
|
...queryOptions as unknown as Omit<QueryObserverOptions, "queryKey">
|
|
45
|
-
}) as
|
|
45
|
+
}) as UseQueryResult<TData, FindPetsByTags400> & {
|
|
46
46
|
queryKey: TQueryKey;
|
|
47
47
|
};
|
|
48
48
|
query.queryKey = queryKey as TQueryKey;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
|
-
import type { QueryKey, InfiniteQueryObserverOptions } from "@tanstack/react-query";
|
|
3
|
+
import type { QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryResult } from "@tanstack/react-query";
|
|
4
4
|
import { useInfiniteQuery, infiniteQueryOptions } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsInfiniteQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
@@ -48,7 +48,7 @@ export function useFindPetsByTagsInfinite<TData = FindPetsByTagsQueryResponse, T
|
|
|
48
48
|
...findPetsByTagsInfiniteQueryOptions(headers, params, config) as unknown as InfiniteQueryObserverOptions,
|
|
49
49
|
queryKey,
|
|
50
50
|
...queryOptions as unknown as Omit<InfiniteQueryObserverOptions, "queryKey">
|
|
51
|
-
}) as
|
|
51
|
+
}) as UseInfiniteQueryResult<TData, FindPetsByTags400> & {
|
|
52
52
|
queryKey: TQueryKey;
|
|
53
53
|
};
|
|
54
54
|
query.queryKey = queryKey as TQueryKey;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
|
-
import type { QueryKey, InfiniteQueryObserverOptions } from "@tanstack/react-query";
|
|
3
|
+
import type { QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryResult } from "@tanstack/react-query";
|
|
4
4
|
import { useInfiniteQuery, infiniteQueryOptions } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsInfiniteQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
@@ -48,7 +48,7 @@ export function useFindPetsByTagsInfinite<TData = FindPetsByTagsQueryResponse, T
|
|
|
48
48
|
...findPetsByTagsInfiniteQueryOptions(headers, params, config) as unknown as InfiniteQueryObserverOptions,
|
|
49
49
|
queryKey,
|
|
50
50
|
...queryOptions as unknown as Omit<InfiniteQueryObserverOptions, "queryKey">
|
|
51
|
-
}) as
|
|
51
|
+
}) as UseInfiniteQueryResult<TData, FindPetsByTags400> & {
|
|
52
52
|
queryKey: TQueryKey;
|
|
53
53
|
};
|
|
54
54
|
query.queryKey = queryKey as TQueryKey;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
|
-
import type { QueryKey, QueryObserverOptions } from "custom-query";
|
|
3
|
+
import type { QueryKey, QueryObserverOptions, UseQueryResult } from "custom-query";
|
|
4
4
|
import { useQuery, queryOptions } from "custom-query";
|
|
5
5
|
|
|
6
6
|
export const updatePetWithFormQueryKey = (petId: UpdatePetWithFormPathParams["petId"], data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams) => [{ url: "/pet/:petId", params: { petId: petId } }, ...(params ? [params] : []), ...(data ? [data] : [])] as const;
|
|
@@ -40,7 +40,7 @@ export function useUpdatePetWithForm<TData = UpdatePetWithFormMutationResponse,
|
|
|
40
40
|
...updatePetWithFormQueryOptions(petId, data, params, config) as unknown as QueryObserverOptions,
|
|
41
41
|
queryKey,
|
|
42
42
|
...queryOptions as unknown as Omit<QueryObserverOptions, "queryKey">
|
|
43
|
-
}) as
|
|
43
|
+
}) as UseQueryResult<TData, UpdatePetWithForm405> & {
|
|
44
44
|
queryKey: TQueryKey;
|
|
45
45
|
};
|
|
46
46
|
query.queryKey = queryKey as TQueryKey;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
|
-
import type { UseMutationOptions
|
|
3
|
+
import type { UseMutationOptions } from "@tanstack/react-query";
|
|
4
4
|
import { useMutation } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
6
|
export const updatePetWithFormMutationKey = () => [{ "url": "/pet/{petId}" }] as const;
|
|
@@ -30,18 +30,15 @@ export function useUpdatePetWithForm(options: {
|
|
|
30
30
|
} = {}) {
|
|
31
31
|
const { mutation: mutationOptions, client: config = {} } = options ?? {};
|
|
32
32
|
const mutationKey = mutationOptions?.mutationKey ?? updatePetWithFormMutationKey();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}) => {
|
|
33
|
+
return useMutation<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, {
|
|
34
|
+
petId: UpdatePetWithFormPathParams["petId"];
|
|
35
|
+
data?: UpdatePetWithFormMutationRequest;
|
|
36
|
+
params?: UpdatePetWithFormQueryParams;
|
|
37
|
+
}>({
|
|
38
|
+
mutationFn: async ({ petId, data, params }) => {
|
|
39
39
|
return updatePetWithForm(petId, data, params, config);
|
|
40
40
|
},
|
|
41
|
+
mutationKey,
|
|
41
42
|
...mutationOptions
|
|
42
|
-
})
|
|
43
|
-
mutationKey: MutationKey;
|
|
44
|
-
};
|
|
45
|
-
mutation.mutationKey = mutationKey as MutationKey;
|
|
46
|
-
return mutation;
|
|
43
|
+
});
|
|
47
44
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
|
-
import type { UseMutationOptions
|
|
3
|
+
import type { UseMutationOptions } from "@tanstack/react-query";
|
|
4
4
|
import { useMutation } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
6
|
export const updatePetWithFormMutationKey = () => [{ "url": "/pet/{petId}" }] as const;
|
|
@@ -32,18 +32,15 @@ export function useUpdatePetWithForm(options: {
|
|
|
32
32
|
} = {}) {
|
|
33
33
|
const { mutation: mutationOptions, client: config = {} } = options ?? {};
|
|
34
34
|
const mutationKey = mutationOptions?.mutationKey ?? updatePetWithFormMutationKey();
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}) => {
|
|
35
|
+
return useMutation<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, {
|
|
36
|
+
petId: UpdatePetWithFormPathParams["petId"];
|
|
37
|
+
data?: UpdatePetWithFormMutationRequest;
|
|
38
|
+
params?: UpdatePetWithFormQueryParams;
|
|
39
|
+
}>({
|
|
40
|
+
mutationFn: async ({ petId, data, params }) => {
|
|
41
41
|
return updatePetWithForm({ petId }, data, params, config);
|
|
42
42
|
},
|
|
43
|
+
mutationKey,
|
|
43
44
|
...mutationOptions
|
|
44
|
-
})
|
|
45
|
-
mutationKey: MutationKey;
|
|
46
|
-
};
|
|
47
|
-
mutation.mutationKey = mutationKey as MutationKey;
|
|
48
|
-
return mutation;
|
|
45
|
+
});
|
|
49
46
|
}
|
|
@@ -59,7 +59,7 @@ export const infiniteQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
59
59
|
<File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
60
60
|
{options.parser === 'zod' && <File.Import extName={output?.extName} name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
|
|
61
61
|
<File.Import name={['useInfiniteQuery', 'infiniteQueryOptions']} path={options.query.importPath} />
|
|
62
|
-
<File.Import name={['QueryKey', 'WithRequired', 'InfiniteQueryObserverOptions']} path={options.query.importPath} isTypeOnly />
|
|
62
|
+
<File.Import name={['QueryKey', 'WithRequired', 'InfiniteQueryObserverOptions', 'UseInfiniteQueryResult']} path={options.query.importPath} isTypeOnly />
|
|
63
63
|
<File.Import name={'client'} path={options.client.importPath} />
|
|
64
64
|
<File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
|
|
65
65
|
{options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
|
|
@@ -58,7 +58,7 @@ export const mutationGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
58
58
|
<File.Import extName={output?.extName} name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />
|
|
59
59
|
)}
|
|
60
60
|
<File.Import name={['useMutation']} path={options.mutation.importPath} />
|
|
61
|
-
<File.Import name={['UseMutationOptions'
|
|
61
|
+
<File.Import name={['UseMutationOptions']} path={options.mutation.importPath} isTypeOnly />
|
|
62
62
|
<File.Import name={'client'} path={options.client.importPath} />
|
|
63
63
|
<File.Import name={['RequestConfig', 'ResponseConfig']} path={options.client.importPath} isTypeOnly />
|
|
64
64
|
<File.Import
|
|
@@ -104,7 +104,6 @@ export const mutationGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
104
104
|
dataReturnType={options.client.dataReturnType}
|
|
105
105
|
pathParamsType={options.pathParamsType}
|
|
106
106
|
mutationKeyName={mutationKey.name}
|
|
107
|
-
mutationKeyTypeName={mutationKey.typeName}
|
|
108
107
|
/>
|
|
109
108
|
</File>
|
|
110
109
|
)
|
|
@@ -60,7 +60,7 @@ export const queryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
60
60
|
<File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
61
61
|
{options.parser === 'zod' && <File.Import extName={output?.extName} name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
|
|
62
62
|
<File.Import name={['useQuery', 'queryOptions']} path={options.query.importPath} />
|
|
63
|
-
<File.Import name={['QueryKey', 'WithRequired', 'QueryObserverOptions']} path={options.query.importPath} isTypeOnly />
|
|
63
|
+
<File.Import name={['QueryKey', 'WithRequired', 'QueryObserverOptions', 'UseQueryResult']} path={options.query.importPath} isTypeOnly />
|
|
64
64
|
<File.Import name={'client'} path={options.client.importPath} />
|
|
65
65
|
<File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
|
|
66
66
|
{options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
|
|
@@ -59,7 +59,7 @@ export const suspenseQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
59
59
|
<File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
60
60
|
{options.parser === 'zod' && <File.Import extName={output?.extName} name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
|
|
61
61
|
<File.Import name={['useSuspenseQuery', 'queryOptions']} path={options.query.importPath} />
|
|
62
|
-
<File.Import name={['QueryKey', 'WithRequired', 'UseSuspenseQueryOptions']} path={options.query.importPath} isTypeOnly />
|
|
62
|
+
<File.Import name={['QueryKey', 'WithRequired', 'UseSuspenseQueryOptions', 'UseSuspenseQueryResult']} path={options.query.importPath} isTypeOnly />
|
|
63
63
|
<File.Import name={'client'} path={options.client.importPath} />
|
|
64
64
|
<File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
|
|
65
65
|
{options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
|
package/src/plugin.ts
CHANGED
|
@@ -27,6 +27,7 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
27
27
|
infinite,
|
|
28
28
|
transformers = {},
|
|
29
29
|
pathParamsType = 'inline',
|
|
30
|
+
generators = [queryGenerator, suspenseQueryGenerator, infiniteQueryGenerator, mutationGenerator].filter(Boolean),
|
|
30
31
|
mutation = {},
|
|
31
32
|
query = {},
|
|
32
33
|
} = options
|
|
@@ -134,7 +135,7 @@ export const pluginReactQuery = createPlugin<PluginReactQuery>((options) => {
|
|
|
134
135
|
},
|
|
135
136
|
)
|
|
136
137
|
|
|
137
|
-
const files = await operationGenerator.build(
|
|
138
|
+
const files = await operationGenerator.build(...generators)
|
|
138
139
|
await this.addFile(...files)
|
|
139
140
|
|
|
140
141
|
if (this.config.output.exportType) {
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
2
2
|
|
|
3
3
|
import type { HttpMethod } from '@kubb/oas'
|
|
4
|
-
import type {
|
|
4
|
+
import type { PluginClient } from '@kubb/plugin-client'
|
|
5
|
+
import type { Exclude, Generator, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
5
6
|
|
|
6
7
|
type Suspense = object
|
|
7
8
|
|
|
@@ -170,6 +171,10 @@ export type Options = {
|
|
|
170
171
|
*/
|
|
171
172
|
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
|
|
172
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Define some generators next to the react-query generators
|
|
176
|
+
*/
|
|
177
|
+
generators?: Array<Generator<PluginReactQuery>>
|
|
173
178
|
}
|
|
174
179
|
|
|
175
180
|
type ResolvedOptions = {
|