@kubb/plugin-react-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.
- package/dist/{chunk-U35NELYJ.js → chunk-ARL3PQR3.js} +259 -41
- package/dist/chunk-ARL3PQR3.js.map +1 -0
- package/dist/{chunk-D5PFCZWQ.cjs → chunk-FYBD7BZP.cjs} +259 -41
- package/dist/chunk-FYBD7BZP.cjs.map +1 -0
- package/dist/{chunk-JKG4EZID.cjs → chunk-WMQRQT7P.cjs} +158 -116
- package/dist/chunk-WMQRQT7P.cjs.map +1 -0
- package/dist/{chunk-3OOSVEDM.js → chunk-WYNK6OE2.js} +147 -105
- package/dist/chunk-WYNK6OE2.js.map +1 -0
- package/dist/components.cjs +9 -9
- package/dist/components.d.cts +29 -16
- package/dist/components.d.ts +29 -16
- 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 +25 -25
- 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 +24 -24
- package/dist/index.js.map +1 -1
- package/dist/{types-LhwfnVo7.d.cts → types-IuxCCG1K.d.cts} +46 -16
- package/dist/{types-LhwfnVo7.d.ts → types-IuxCCG1K.d.ts} +46 -16
- package/package.json +13 -12
- package/src/components/InfiniteQuery.tsx +53 -6
- package/src/components/InfiniteQueryOptions.tsx +47 -6
- package/src/components/Mutation.tsx +3 -1
- package/src/components/MutationKey.tsx +11 -5
- package/src/components/Query.tsx +62 -6
- package/src/components/QueryKey.tsx +17 -7
- package/src/components/QueryOptions.tsx +47 -7
- package/src/components/SuspenseQuery.tsx +52 -5
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +1 -1
- package/src/generators/__snapshots__/clientGetImportPath.ts +1 -1
- package/src/generators/__snapshots__/findByTags.ts +1 -1
- package/src/generators/__snapshots__/findByTagsObject.ts +60 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +1 -1
- package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +2 -2
- package/src/generators/__snapshots__/findByTagsWithZod.ts +1 -1
- package/src/generators/__snapshots__/findInfiniteByTags.ts +3 -3
- package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +3 -3
- package/src/generators/__snapshots__/postAsQuery.ts +1 -1
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +1 -3
- package/src/generators/infiniteQueryGenerator.tsx +48 -30
- package/src/generators/mutationGenerator.tsx +30 -18
- package/src/generators/queryGenerator.tsx +29 -17
- package/src/generators/suspenseQueryGenerator.tsx +34 -19
- package/src/plugin.ts +31 -25
- package/src/types.ts +35 -15
- package/dist/chunk-3OOSVEDM.js.map +0 -1
- package/dist/chunk-D5PFCZWQ.cjs.map +0 -1
- package/dist/chunk-JKG4EZID.cjs.map +0 -1
- package/dist/chunk-U35NELYJ.js.map +0 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import client from "@kubb/plugin-client/client";
|
|
2
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
|
+
import type { QueryKey, QueryObserverOptions, UseQueryResult } from "@tanstack/react-query";
|
|
4
|
+
import { queryOptions, useQuery } from "@tanstack/react-query";
|
|
5
|
+
|
|
6
|
+
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
|
+
|
|
8
|
+
export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
12
|
+
* @summary Finds Pets by tags
|
|
13
|
+
* @link /pet/findByTags
|
|
14
|
+
*/
|
|
15
|
+
async function findPetsByTags({ headers, params }: {
|
|
16
|
+
headers: FindPetsByTagsHeaderParams;
|
|
17
|
+
params?: FindPetsByTagsQueryParams;
|
|
18
|
+
}, config: Partial<RequestConfig> = {}) {
|
|
19
|
+
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "GET", url: `/pet/findByTags`, params, headers: { ...headers, ...config.headers }, ...config });
|
|
20
|
+
return findPetsByTagsQueryResponse.parse(res.data);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function findPetsByTagsQueryOptions({ headers, params }: {
|
|
24
|
+
headers: FindPetsByTagsHeaderParams;
|
|
25
|
+
params?: FindPetsByTagsQueryParams;
|
|
26
|
+
}, config: Partial<RequestConfig> = {}) {
|
|
27
|
+
const queryKey = findPetsByTagsQueryKey(params);
|
|
28
|
+
return queryOptions({
|
|
29
|
+
queryKey,
|
|
30
|
+
queryFn: async ({ signal }) => {
|
|
31
|
+
config.signal = signal;
|
|
32
|
+
return findPetsByTags({ headers, params }, config);
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
39
|
+
* @summary Finds Pets by tags
|
|
40
|
+
* @link /pet/findByTags
|
|
41
|
+
*/
|
|
42
|
+
export function useFindPetsByTags<TData = FindPetsByTagsQueryResponse, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsQueryKey>({ headers, params }: {
|
|
43
|
+
headers: FindPetsByTagsHeaderParams;
|
|
44
|
+
params?: FindPetsByTagsQueryParams;
|
|
45
|
+
}, options: {
|
|
46
|
+
query?: Partial<QueryObserverOptions<FindPetsByTagsQueryResponse, FindPetsByTags400, TData, TQueryData, TQueryKey>>;
|
|
47
|
+
client?: Partial<RequestConfig>;
|
|
48
|
+
} = {}) {
|
|
49
|
+
const { query: queryOptions, client: config = {} } = options ?? {};
|
|
50
|
+
const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params);
|
|
51
|
+
const query = useQuery({
|
|
52
|
+
...findPetsByTagsQueryOptions({ headers, params }, config) as unknown as QueryObserverOptions,
|
|
53
|
+
queryKey,
|
|
54
|
+
...queryOptions as unknown as Omit<QueryObserverOptions, "queryKey">
|
|
55
|
+
}) as UseQueryResult<TData, FindPetsByTags400> & {
|
|
56
|
+
queryKey: TQueryKey;
|
|
57
|
+
};
|
|
58
|
+
query.queryKey = queryKey as TQueryKey;
|
|
59
|
+
return query;
|
|
60
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, QueryObserverOptions, UseQueryResult } from "@tanstack/react-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, useQuery } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
7
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, QueryObserverOptions, UseQueryResult } from "@tanstack/react-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, useQuery } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
|
-
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [test, { url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
6
|
+
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => ["test", { url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
7
|
|
|
8
8
|
export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
|
|
9
9
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, QueryObserverOptions, UseQueryResult } from "@tanstack/react-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, useQuery } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
|
-
import type { QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryResult } from "@tanstack/react-query";
|
|
4
|
-
import {
|
|
3
|
+
import type { InfiniteData, QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryResult } from "@tanstack/react-query";
|
|
4
|
+
import { infiniteQueryOptions, useInfiniteQuery } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsInfiniteQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
7
|
|
|
@@ -39,7 +39,7 @@ async function findPetsByTags(headers: FindPetsByTagsHeaderParams, params?: Find
|
|
|
39
39
|
* @summary Finds Pets by tags
|
|
40
40
|
* @link /pet/findByTags
|
|
41
41
|
*/
|
|
42
|
-
export function useFindPetsByTagsInfinite<TData = FindPetsByTagsQueryResponse
|
|
42
|
+
export function useFindPetsByTagsInfinite<TData = InfiniteData<FindPetsByTagsQueryResponse>, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsInfiniteQueryKey>(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, options: {
|
|
43
43
|
query?: Partial<InfiniteQueryObserverOptions<FindPetsByTagsQueryResponse, FindPetsByTags400, TData, TQueryData, TQueryKey>>;
|
|
44
44
|
client?: Partial<RequestConfig>;
|
|
45
45
|
} = {}) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
|
-
import type { QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryResult } from "@tanstack/react-query";
|
|
4
|
-
import {
|
|
3
|
+
import type { InfiniteData, QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryResult } from "@tanstack/react-query";
|
|
4
|
+
import { infiniteQueryOptions, useInfiniteQuery } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsInfiniteQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
7
|
|
|
@@ -39,7 +39,7 @@ async function findPetsByTags(headers: FindPetsByTagsHeaderParams, params?: Find
|
|
|
39
39
|
* @summary Finds Pets by tags
|
|
40
40
|
* @link /pet/findByTags
|
|
41
41
|
*/
|
|
42
|
-
export function useFindPetsByTagsInfinite<TData = FindPetsByTagsQueryResponse
|
|
42
|
+
export function useFindPetsByTagsInfinite<TData = InfiniteData<FindPetsByTagsQueryResponse>, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsInfiniteQueryKey>(headers: FindPetsByTagsHeaderParams, params?: FindPetsByTagsQueryParams, options: {
|
|
43
43
|
query?: Partial<InfiniteQueryObserverOptions<FindPetsByTagsQueryResponse, FindPetsByTags400, TData, TQueryData, TQueryKey>>;
|
|
44
44
|
client?: Partial<RequestConfig>;
|
|
45
45
|
} = {}) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, QueryObserverOptions, UseQueryResult } from "custom-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, useQuery } 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;
|
|
7
7
|
|
|
@@ -11,9 +11,7 @@ import { useMutation } from "@tanstack/react-query";
|
|
|
11
11
|
* @summary Updates a pet in the store with form data
|
|
12
12
|
* @link /pet/:petId
|
|
13
13
|
*/
|
|
14
|
-
async function updatePetWithForm({ petId }: {
|
|
15
|
-
petId: UpdatePetWithFormPathParams["petId"];
|
|
16
|
-
}, data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> = {}) {
|
|
14
|
+
async function updatePetWithForm({ petId }: UpdatePetWithFormPathParams, data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> = {}) {
|
|
17
15
|
const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationRequest>({ method: "POST", url: `/pet/${petId}`, params, data, ...config });
|
|
18
16
|
return updatePetWithFormMutationResponse.parse(res.data);
|
|
19
17
|
}
|
|
@@ -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 { PluginReactQuery } from '../types'
|
|
11
11
|
|
|
@@ -18,8 +18,14 @@ export const infiniteQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
18
18
|
},
|
|
19
19
|
} = useApp<PluginReactQuery>()
|
|
20
20
|
const { getSchemas, getName, getFile } = useOperationManager()
|
|
21
|
-
|
|
22
|
-
const
|
|
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
|
+
)
|
|
26
|
+
const isInfinite = !!options.infinite
|
|
27
|
+
|
|
28
|
+
const importPath = options.query ? options.query.importPath : '@tanstack/react-query'
|
|
23
29
|
|
|
24
30
|
const query = {
|
|
25
31
|
name: getName(operation, { type: 'function', prefix: 'use', suffix: 'infinite' }),
|
|
@@ -51,15 +57,13 @@ export const infiniteQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
51
57
|
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
|
|
52
58
|
}
|
|
53
59
|
|
|
54
|
-
if (!isQuery ||
|
|
60
|
+
if (!isQuery || isMutation || !isInfinite) {
|
|
55
61
|
return null
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
return (
|
|
59
65
|
<File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
60
66
|
{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 name={['QueryKey', 'WithRequired', 'InfiniteQueryObserverOptions', 'UseInfiniteQueryResult']} path={options.query.importPath} isTypeOnly />
|
|
63
67
|
<File.Import name={'client'} path={options.client.importPath} />
|
|
64
68
|
<File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
|
|
65
69
|
{options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
|
|
@@ -76,48 +80,62 @@ export const infiniteQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
76
80
|
path={type.file.path}
|
|
77
81
|
isTypeOnly
|
|
78
82
|
/>
|
|
79
|
-
|
|
80
83
|
<QueryKey
|
|
81
84
|
name={queryKey.name}
|
|
82
85
|
typeName={queryKey.typeName}
|
|
83
86
|
operation={operation}
|
|
84
87
|
pathParamsType={options.pathParamsType}
|
|
85
88
|
typeSchemas={type.schemas}
|
|
86
|
-
|
|
89
|
+
transformer={options.queryKey}
|
|
87
90
|
/>
|
|
88
91
|
<Client
|
|
89
92
|
name={client.name}
|
|
90
93
|
isExportable={false}
|
|
91
94
|
isIndexable={false}
|
|
92
|
-
baseURL={options.baseURL}
|
|
95
|
+
baseURL={options.client.baseURL}
|
|
93
96
|
operation={operation}
|
|
94
97
|
typeSchemas={type.schemas}
|
|
95
98
|
zodSchemas={zod.schemas}
|
|
96
99
|
dataReturnType={options.client.dataReturnType}
|
|
100
|
+
paramsType={options.paramsType}
|
|
97
101
|
pathParamsType={options.pathParamsType}
|
|
98
102
|
parser={options.parser}
|
|
99
103
|
/>
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
104
|
+
{options.infinite && (
|
|
105
|
+
<>
|
|
106
|
+
<File.Import name={['InfiniteData']} isTypeOnly path={importPath} />
|
|
107
|
+
<File.Import name={['infiniteQueryOptions']} path={importPath} />
|
|
108
|
+
<InfiniteQueryOptions
|
|
109
|
+
name={queryOptions.name}
|
|
110
|
+
clientName={client.name}
|
|
111
|
+
queryKeyName={queryKey.name}
|
|
112
|
+
typeSchemas={type.schemas}
|
|
113
|
+
paramsType={options.paramsType}
|
|
114
|
+
pathParamsType={options.pathParamsType}
|
|
115
|
+
dataReturnType={options.client.dataReturnType}
|
|
116
|
+
cursorParam={options.infinite.cursorParam}
|
|
117
|
+
initialPageParam={options.infinite.initialPageParam}
|
|
118
|
+
queryParam={options.infinite.queryParam}
|
|
119
|
+
/>
|
|
120
|
+
</>
|
|
121
|
+
)}
|
|
122
|
+
{options.infinite && (
|
|
123
|
+
<>
|
|
124
|
+
<File.Import name={['useInfiniteQuery']} path={importPath} />
|
|
125
|
+
<File.Import name={['QueryKey', 'InfiniteQueryObserverOptions', 'UseInfiniteQueryResult']} path={importPath} isTypeOnly />
|
|
126
|
+
<InfiniteQuery
|
|
127
|
+
name={query.name}
|
|
128
|
+
queryOptionsName={queryOptions.name}
|
|
129
|
+
typeSchemas={type.schemas}
|
|
130
|
+
paramsType={options.paramsType}
|
|
131
|
+
pathParamsType={options.pathParamsType}
|
|
132
|
+
operation={operation}
|
|
133
|
+
dataReturnType={options.client.dataReturnType}
|
|
134
|
+
queryKeyName={queryKey.name}
|
|
135
|
+
queryKeyTypeName={queryKey.typeName}
|
|
136
|
+
/>
|
|
137
|
+
</>
|
|
138
|
+
)}
|
|
121
139
|
</File>
|
|
122
140
|
)
|
|
123
141
|
},
|
|
@@ -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 { Mutation, MutationKey } from '../components'
|
|
10
10
|
import type { PluginReactQuery } from '../types'
|
|
11
11
|
|
|
@@ -19,8 +19,12 @@ export const mutationGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
19
19
|
} = useApp<PluginReactQuery>()
|
|
20
20
|
const { getSchemas, getName, getFile } = useOperationManager()
|
|
21
21
|
|
|
22
|
-
const isQuery =
|
|
23
|
-
const isMutation =
|
|
22
|
+
const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method)
|
|
23
|
+
const isMutation =
|
|
24
|
+
!isQuery &&
|
|
25
|
+
difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method)
|
|
26
|
+
|
|
27
|
+
const importPath = options.mutation ? options.mutation.importPath : '@tanstack/react-query'
|
|
24
28
|
|
|
25
29
|
const mutation = {
|
|
26
30
|
name: getName(operation, { type: 'function', prefix: 'use' }),
|
|
@@ -48,15 +52,13 @@ export const mutationGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
48
52
|
typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
if (!isMutation
|
|
55
|
+
if (!isMutation) {
|
|
52
56
|
return null
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
return (
|
|
56
60
|
<File baseName={mutation.file.baseName} path={mutation.file.path} meta={mutation.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
57
61
|
{options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />}
|
|
58
|
-
<File.Import name={['useMutation']} path={options.mutation.importPath} />
|
|
59
|
-
<File.Import name={['UseMutationOptions']} path={options.mutation.importPath} isTypeOnly />
|
|
60
62
|
<File.Import name={'client'} path={options.client.importPath} />
|
|
61
63
|
<File.Import name={['RequestConfig', 'ResponseConfig']} path={options.client.importPath} isTypeOnly />
|
|
62
64
|
<File.Import
|
|
@@ -72,36 +74,46 @@ export const mutationGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
72
74
|
path={type.file.path}
|
|
73
75
|
isTypeOnly
|
|
74
76
|
/>
|
|
77
|
+
|
|
75
78
|
<MutationKey
|
|
76
79
|
name={mutationKey.name}
|
|
77
80
|
typeName={mutationKey.typeName}
|
|
78
81
|
operation={operation}
|
|
79
82
|
pathParamsType={options.pathParamsType}
|
|
80
83
|
typeSchemas={type.schemas}
|
|
81
|
-
|
|
84
|
+
transformer={options.mutationKey}
|
|
82
85
|
/>
|
|
86
|
+
|
|
83
87
|
<Client
|
|
84
88
|
name={client.name}
|
|
85
89
|
isExportable={false}
|
|
86
90
|
isIndexable={false}
|
|
87
|
-
baseURL={options.baseURL}
|
|
91
|
+
baseURL={options.client.baseURL}
|
|
88
92
|
operation={operation}
|
|
89
93
|
typeSchemas={type.schemas}
|
|
90
94
|
zodSchemas={zod.schemas}
|
|
91
95
|
dataReturnType={options.client.dataReturnType}
|
|
96
|
+
paramsType={options.paramsType}
|
|
92
97
|
pathParamsType={options.pathParamsType}
|
|
93
98
|
parser={options.parser}
|
|
94
99
|
/>
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
{options.mutation && (
|
|
101
|
+
<>
|
|
102
|
+
<File.Import name={['useMutation']} path={importPath} />
|
|
103
|
+
<File.Import name={['UseMutationOptions']} path={importPath} isTypeOnly />
|
|
104
|
+
<Mutation
|
|
105
|
+
name={mutation.name}
|
|
106
|
+
clientName={client.name}
|
|
107
|
+
typeName={mutation.typeName}
|
|
108
|
+
typeSchemas={type.schemas}
|
|
109
|
+
operation={operation}
|
|
110
|
+
dataReturnType={options.client.dataReturnType}
|
|
111
|
+
paramsType={options.paramsType}
|
|
112
|
+
pathParamsType={options.pathParamsType}
|
|
113
|
+
mutationKeyName={mutationKey.name}
|
|
114
|
+
/>
|
|
115
|
+
</>
|
|
116
|
+
)}
|
|
105
117
|
</File>
|
|
106
118
|
)
|
|
107
119
|
},
|
|
@@ -5,6 +5,7 @@ import { useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
|
5
5
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
6
6
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
7
7
|
import { File, useApp } from '@kubb/react'
|
|
8
|
+
import { difference } from 'remeda'
|
|
8
9
|
import { Query, QueryKey, QueryOptions } from '../components'
|
|
9
10
|
import type { PluginReactQuery } from '../types'
|
|
10
11
|
|
|
@@ -19,7 +20,11 @@ export const queryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
19
20
|
const { getSchemas, getName, getFile } = useOperationManager()
|
|
20
21
|
|
|
21
22
|
const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
|
|
22
|
-
const isMutation =
|
|
23
|
+
const isMutation = difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some(
|
|
24
|
+
(method) => operation.method === method,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
const importPath = options.query ? options.query.importPath : '@tanstack/react-query'
|
|
23
28
|
|
|
24
29
|
const query = {
|
|
25
30
|
name: getName(operation, { type: 'function', prefix: 'use' }),
|
|
@@ -51,15 +56,13 @@ export const queryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
51
56
|
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
|
|
52
57
|
}
|
|
53
58
|
|
|
54
|
-
if (!isQuery ||
|
|
59
|
+
if (!isQuery || isMutation) {
|
|
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={['useQuery', 'queryOptions']} path={options.query.importPath} />
|
|
62
|
-
<File.Import name={['QueryKey', 'WithRequired', 'QueryObserverOptions', 'UseQueryResult']} path={options.query.importPath} isTypeOnly />
|
|
63
66
|
<File.Import name={'client'} path={options.client.importPath} />
|
|
64
67
|
<File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
|
|
65
68
|
{options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
|
|
@@ -76,44 +79,53 @@ export const queryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
76
79
|
path={type.file.path}
|
|
77
80
|
isTypeOnly
|
|
78
81
|
/>
|
|
79
|
-
|
|
80
82
|
<QueryKey
|
|
81
83
|
name={queryKey.name}
|
|
82
84
|
typeName={queryKey.typeName}
|
|
83
85
|
operation={operation}
|
|
84
86
|
pathParamsType={options.pathParamsType}
|
|
85
87
|
typeSchemas={type.schemas}
|
|
86
|
-
|
|
88
|
+
transformer={options.queryKey}
|
|
87
89
|
/>
|
|
88
90
|
<Client
|
|
89
91
|
name={client.name}
|
|
90
92
|
isExportable={false}
|
|
91
93
|
isIndexable={false}
|
|
92
|
-
baseURL={options.baseURL}
|
|
94
|
+
baseURL={options.client.baseURL}
|
|
93
95
|
operation={operation}
|
|
94
96
|
typeSchemas={type.schemas}
|
|
95
97
|
zodSchemas={zod.schemas}
|
|
96
98
|
dataReturnType={options.client.dataReturnType}
|
|
99
|
+
paramsType={options.paramsType}
|
|
97
100
|
pathParamsType={options.pathParamsType}
|
|
98
101
|
parser={options.parser}
|
|
99
102
|
/>
|
|
103
|
+
<File.Import name={['queryOptions']} path={importPath} />
|
|
100
104
|
<QueryOptions
|
|
101
105
|
name={queryOptions.name}
|
|
102
106
|
clientName={client.name}
|
|
103
107
|
queryKeyName={queryKey.name}
|
|
104
108
|
typeSchemas={type.schemas}
|
|
109
|
+
paramsType={options.paramsType}
|
|
105
110
|
pathParamsType={options.pathParamsType}
|
|
106
111
|
/>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
112
|
+
{options.query && (
|
|
113
|
+
<>
|
|
114
|
+
<File.Import name={['useQuery']} path={importPath} />
|
|
115
|
+
<File.Import name={['QueryKey', 'QueryObserverOptions', 'UseQueryResult']} path={importPath} isTypeOnly />
|
|
116
|
+
<Query
|
|
117
|
+
name={query.name}
|
|
118
|
+
queryOptionsName={queryOptions.name}
|
|
119
|
+
typeSchemas={type.schemas}
|
|
120
|
+
paramsType={options.paramsType}
|
|
121
|
+
pathParamsType={options.pathParamsType}
|
|
122
|
+
operation={operation}
|
|
123
|
+
dataReturnType={options.client.dataReturnType}
|
|
124
|
+
queryKeyName={queryKey.name}
|
|
125
|
+
queryKeyTypeName={queryKey.typeName}
|
|
126
|
+
/>
|
|
127
|
+
</>
|
|
128
|
+
)}
|
|
117
129
|
</File>
|
|
118
130
|
)
|
|
119
131
|
},
|
|
@@ -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 { QueryKey, QueryOptions, SuspenseQuery } from '../components'
|
|
10
10
|
import type { PluginReactQuery } from '../types'
|
|
11
11
|
|
|
@@ -18,8 +18,15 @@ export const suspenseQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
18
18
|
},
|
|
19
19
|
} = useApp<PluginReactQuery>()
|
|
20
20
|
const { getSchemas, getName, getFile } = useOperationManager()
|
|
21
|
-
|
|
22
|
-
const
|
|
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
|
+
)
|
|
26
|
+
|
|
27
|
+
const isSuspense = !!options.suspense
|
|
28
|
+
|
|
29
|
+
const importPath = options.query ? options.query.importPath : '@tanstack/react-query'
|
|
23
30
|
|
|
24
31
|
const query = {
|
|
25
32
|
name: getName(operation, { type: 'function', prefix: 'use', suffix: 'suspense' }),
|
|
@@ -51,15 +58,13 @@ export const suspenseQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
51
58
|
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
|
|
52
59
|
}
|
|
53
60
|
|
|
54
|
-
if (!isQuery ||
|
|
61
|
+
if (!isQuery || isMutation || !isSuspense) {
|
|
55
62
|
return null
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
return (
|
|
59
66
|
<File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
60
67
|
{options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
|
|
61
|
-
<File.Import name={['useSuspenseQuery', 'queryOptions']} path={options.query.importPath} />
|
|
62
|
-
<File.Import name={['QueryKey', 'WithRequired', 'UseSuspenseQueryOptions', 'UseSuspenseQueryResult']} path={options.query.importPath} isTypeOnly />
|
|
63
68
|
<File.Import name={'client'} path={options.client.importPath} />
|
|
64
69
|
<File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
|
|
65
70
|
{options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
|
|
@@ -76,44 +81,54 @@ export const suspenseQueryGenerator = createReactGenerator<PluginReactQuery>({
|
|
|
76
81
|
path={type.file.path}
|
|
77
82
|
isTypeOnly
|
|
78
83
|
/>
|
|
79
|
-
|
|
80
84
|
<QueryKey
|
|
81
85
|
name={queryKey.name}
|
|
82
86
|
typeName={queryKey.typeName}
|
|
83
87
|
operation={operation}
|
|
84
88
|
pathParamsType={options.pathParamsType}
|
|
85
89
|
typeSchemas={type.schemas}
|
|
86
|
-
|
|
90
|
+
transformer={options.queryKey}
|
|
87
91
|
/>
|
|
92
|
+
|
|
88
93
|
<Client
|
|
89
94
|
name={client.name}
|
|
90
95
|
isExportable={false}
|
|
91
96
|
isIndexable={false}
|
|
92
|
-
baseURL={options.baseURL}
|
|
97
|
+
baseURL={options.client.baseURL}
|
|
93
98
|
operation={operation}
|
|
94
99
|
typeSchemas={type.schemas}
|
|
95
100
|
zodSchemas={zod.schemas}
|
|
96
101
|
dataReturnType={options.client.dataReturnType}
|
|
102
|
+
paramsType={options.paramsType}
|
|
97
103
|
pathParamsType={options.pathParamsType}
|
|
98
104
|
parser={options.parser}
|
|
99
105
|
/>
|
|
106
|
+
<File.Import name={['queryOptions']} path={importPath} />
|
|
100
107
|
<QueryOptions
|
|
101
108
|
name={queryOptions.name}
|
|
102
109
|
clientName={client.name}
|
|
103
110
|
queryKeyName={queryKey.name}
|
|
104
111
|
typeSchemas={type.schemas}
|
|
112
|
+
paramsType={options.paramsType}
|
|
105
113
|
pathParamsType={options.pathParamsType}
|
|
106
114
|
/>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
{options.suspense && (
|
|
116
|
+
<>
|
|
117
|
+
<File.Import name={['useSuspenseQuery']} path={importPath} />
|
|
118
|
+
<File.Import name={['QueryKey', 'UseSuspenseQueryOptions', 'UseSuspenseQueryResult']} path={importPath} isTypeOnly />
|
|
119
|
+
<SuspenseQuery
|
|
120
|
+
name={query.name}
|
|
121
|
+
queryOptionsName={queryOptions.name}
|
|
122
|
+
typeSchemas={type.schemas}
|
|
123
|
+
paramsType={options.paramsType}
|
|
124
|
+
pathParamsType={options.pathParamsType}
|
|
125
|
+
operation={operation}
|
|
126
|
+
dataReturnType={options.client.dataReturnType}
|
|
127
|
+
queryKeyName={queryKey.name}
|
|
128
|
+
queryKeyTypeName={queryKey.typeName}
|
|
129
|
+
/>
|
|
130
|
+
</>
|
|
131
|
+
)}
|
|
117
132
|
</File>
|
|
118
133
|
)
|
|
119
134
|
},
|