@kubb/plugin-react-query 4.14.1 → 4.15.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/{components-CO636qn3.cjs → components-6nRaAppd.cjs} +19 -13
- package/dist/components-6nRaAppd.cjs.map +1 -0
- package/dist/{components-DQHnoHX_.js → components-B6lqcqgn.js} +18 -12
- package/dist/components-B6lqcqgn.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.cts +15 -5
- package/dist/components.d.ts +15 -5
- package/dist/components.js +1 -1
- package/dist/{generators-BNtUetHy.cjs → generators-CYoqgYAV.cjs} +331 -6
- package/dist/generators-CYoqgYAV.cjs.map +1 -0
- package/dist/{generators-Cz0OG9Qu.js → generators-cZao868O.js} +320 -8
- package/dist/generators-cZao868O.js.map +1 -0
- package/dist/generators.cjs +3 -1
- package/dist/generators.d.cts +8 -2
- package/dist/generators.d.ts +8 -2
- package/dist/generators.js +2 -2
- package/dist/index.cjs +10 -4
- 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 +10 -4
- package/dist/index.js.map +1 -1
- package/dist/{types-Cli5EJ4L.d.ts → types-B9xv5S0R.d.cts} +35 -2
- package/dist/{types-B2aUnqdY.d.cts → types-BAEc42Ae.d.ts} +35 -2
- package/package.json +7 -7
- package/src/components/InfiniteQuery.tsx +4 -1
- package/src/components/Mutation.tsx +4 -1
- package/src/components/MutationOptions.tsx +2 -2
- package/src/components/Query.tsx +4 -1
- package/src/components/SuspenseInfiniteQuery.tsx +4 -1
- package/src/components/SuspenseQuery.tsx +4 -1
- package/src/generators/__snapshots__/clientPostImportPath.ts +4 -2
- package/src/generators/__snapshots__/findByTagsWithCustomOptions.ts +89 -0
- package/src/generators/__snapshots__/findInfiniteByTagsWithCustomOptions.ts +103 -0
- package/src/generators/__snapshots__/findSuspenseByTagsWithCustomOptions.ts +83 -0
- package/src/generators/__snapshots__/findSuspenseInfiniteByTagsWithCustomOptions.ts +103 -0
- package/src/generators/__snapshots__/updatePetById.ts +4 -2
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +4 -2
- package/src/generators/__snapshots__/updatePetByIdWithCustomOptions.ts +107 -0
- package/src/generators/customHookOptionsFileGenerator.tsx +98 -0
- package/src/generators/hookOptionsGenerator.tsx +196 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/infiniteQueryGenerator.tsx +2 -0
- package/src/generators/mutationGenerator.tsx +2 -0
- package/src/generators/queryGenerator.tsx +2 -0
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +2 -0
- package/src/generators/suspenseQueryGenerator.tsx +2 -0
- package/src/plugin.ts +20 -2
- package/src/types.ts +21 -0
- package/dist/components-CO636qn3.cjs.map +0 -1
- package/dist/components-DQHnoHX_.js.map +0 -1
- package/dist/generators-BNtUetHy.cjs.map +0 -1
- package/dist/generators-Cz0OG9Qu.js.map +0 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by Kubb (https://kubb.dev/).
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { RequestConfig, ResponseErrorConfig } from './test/.kubb/fetch'
|
|
6
|
+
import type { QueryKey, QueryClient, QueryObserverOptions, UseQueryResult } from '@tanstack/react-query'
|
|
7
|
+
import { fetch } from './test/.kubb/fetch'
|
|
8
|
+
import { queryOptions, useQuery } from '@tanstack/react-query'
|
|
9
|
+
import { useCustomHookOptions } from 'useCustomHookOptions.ts'
|
|
10
|
+
|
|
11
|
+
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
|
|
12
|
+
|
|
13
|
+
export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
17
|
+
* @summary Finds Pets by tags
|
|
18
|
+
* {@link /pet/findByTags}
|
|
19
|
+
*/
|
|
20
|
+
export async function findPetsByTags(
|
|
21
|
+
headers: FindPetsByTagsHeaderParams,
|
|
22
|
+
params?: FindPetsByTagsQueryParams,
|
|
23
|
+
config: Partial<RequestConfig> & { client?: typeof fetch } = {},
|
|
24
|
+
) {
|
|
25
|
+
const { client: request = fetch, ...requestConfig } = config
|
|
26
|
+
|
|
27
|
+
const res = await request<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>, unknown>({
|
|
28
|
+
method: 'GET',
|
|
29
|
+
url: `/pet/findByTags`,
|
|
30
|
+
params,
|
|
31
|
+
...requestConfig,
|
|
32
|
+
headers: { ...headers, ...requestConfig.headers },
|
|
33
|
+
})
|
|
34
|
+
return findPetsByTagsQueryResponse.parse(res.data)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function findPetsByTagsQueryOptions(
|
|
38
|
+
headers: FindPetsByTagsHeaderParams,
|
|
39
|
+
params?: FindPetsByTagsQueryParams,
|
|
40
|
+
config: Partial<RequestConfig> & { client?: typeof fetch } = {},
|
|
41
|
+
) {
|
|
42
|
+
const queryKey = findPetsByTagsQueryKey(params)
|
|
43
|
+
return queryOptions<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>, FindPetsByTagsQueryResponse, typeof queryKey>({
|
|
44
|
+
queryKey,
|
|
45
|
+
queryFn: async ({ signal }) => {
|
|
46
|
+
config.signal = signal
|
|
47
|
+
return findPetsByTags(headers, params, config)
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
54
|
+
* @summary Finds Pets by tags
|
|
55
|
+
* {@link /pet/findByTags}
|
|
56
|
+
*/
|
|
57
|
+
export function useFindPetsByTags<
|
|
58
|
+
TData = FindPetsByTagsQueryResponse,
|
|
59
|
+
TQueryData = FindPetsByTagsQueryResponse,
|
|
60
|
+
TQueryKey extends QueryKey = FindPetsByTagsQueryKey,
|
|
61
|
+
>(
|
|
62
|
+
headers: FindPetsByTagsHeaderParams,
|
|
63
|
+
params?: FindPetsByTagsQueryParams,
|
|
64
|
+
options: {
|
|
65
|
+
query?: Partial<QueryObserverOptions<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>, TData, TQueryData, TQueryKey>> & {
|
|
66
|
+
client?: QueryClient
|
|
67
|
+
}
|
|
68
|
+
client?: Partial<RequestConfig> & { client?: typeof fetch }
|
|
69
|
+
} = {},
|
|
70
|
+
) {
|
|
71
|
+
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
72
|
+
const { client: queryClient, ...queryOptions } = queryConfig
|
|
73
|
+
const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params)
|
|
74
|
+
const customOptions = useCustomHookOptions({ hookName: 'useFindPetsByTags', operationId: 'findPetsByTags' })
|
|
75
|
+
|
|
76
|
+
const query = useQuery(
|
|
77
|
+
{
|
|
78
|
+
...findPetsByTagsQueryOptions(headers, params, config),
|
|
79
|
+
...customOptions,
|
|
80
|
+
queryKey,
|
|
81
|
+
...queryOptions,
|
|
82
|
+
} as unknown as QueryObserverOptions,
|
|
83
|
+
queryClient,
|
|
84
|
+
) as UseQueryResult<TData, ResponseErrorConfig<FindPetsByTags400>> & { queryKey: TQueryKey }
|
|
85
|
+
|
|
86
|
+
query.queryKey = queryKey as TQueryKey
|
|
87
|
+
|
|
88
|
+
return query
|
|
89
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by Kubb (https://kubb.dev/).
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { RequestConfig, ResponseErrorConfig } from './test/.kubb/fetch'
|
|
6
|
+
import type { InfiniteData, QueryKey, QueryClient, InfiniteQueryObserverOptions, UseInfiniteQueryResult } from '@tanstack/react-query'
|
|
7
|
+
import { fetch } from './test/.kubb/fetch'
|
|
8
|
+
import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query'
|
|
9
|
+
import { useCustomHookOptions } from 'useCustomHookOptions.ts'
|
|
10
|
+
|
|
11
|
+
export const findPetsByTagsInfiniteQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
|
|
12
|
+
|
|
13
|
+
export type FindPetsByTagsInfiniteQueryKey = ReturnType<typeof findPetsByTagsInfiniteQueryKey>
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
17
|
+
* @summary Finds Pets by tags
|
|
18
|
+
* {@link /pet/findByTags}
|
|
19
|
+
*/
|
|
20
|
+
export async function findPetsByTagsInfinite(
|
|
21
|
+
headers: FindPetsByTagsHeaderParams,
|
|
22
|
+
params?: FindPetsByTagsQueryParams,
|
|
23
|
+
config: Partial<RequestConfig> & { client?: typeof fetch } = {},
|
|
24
|
+
) {
|
|
25
|
+
const { client: request = fetch, ...requestConfig } = config
|
|
26
|
+
|
|
27
|
+
const res = await request<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>, unknown>({
|
|
28
|
+
method: 'GET',
|
|
29
|
+
url: `/pet/findByTags`,
|
|
30
|
+
params,
|
|
31
|
+
...requestConfig,
|
|
32
|
+
headers: { ...headers, ...requestConfig.headers },
|
|
33
|
+
})
|
|
34
|
+
return findPetsByTagsQueryResponse.parse(res.data)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function findPetsByTagsInfiniteQueryOptions(
|
|
38
|
+
headers: FindPetsByTagsHeaderParams,
|
|
39
|
+
params?: FindPetsByTagsQueryParams,
|
|
40
|
+
config: Partial<RequestConfig> & { client?: typeof fetch } = {},
|
|
41
|
+
) {
|
|
42
|
+
const queryKey = findPetsByTagsInfiniteQueryKey(params)
|
|
43
|
+
return infiniteQueryOptions<
|
|
44
|
+
FindPetsByTagsQueryResponse,
|
|
45
|
+
ResponseErrorConfig<FindPetsByTags400>,
|
|
46
|
+
InfiniteData<FindPetsByTagsQueryResponse>,
|
|
47
|
+
typeof queryKey,
|
|
48
|
+
NonNullable<FindPetsByTagsQueryParams['pageSize']>
|
|
49
|
+
>({
|
|
50
|
+
queryKey,
|
|
51
|
+
queryFn: async ({ signal, pageParam }) => {
|
|
52
|
+
config.signal = signal
|
|
53
|
+
|
|
54
|
+
params = {
|
|
55
|
+
...(params ?? {}),
|
|
56
|
+
['pageSize']: pageParam as unknown as FindPetsByTagsQueryParams['pageSize'],
|
|
57
|
+
} as FindPetsByTagsQueryParams
|
|
58
|
+
return findPetsByTagsInfinite(headers, params, config)
|
|
59
|
+
},
|
|
60
|
+
initialPageParam: 0,
|
|
61
|
+
getNextPageParam: (lastPage, _allPages, lastPageParam) => (Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1),
|
|
62
|
+
getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => (firstPageParam <= 1 ? undefined : firstPageParam - 1),
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
68
|
+
* @summary Finds Pets by tags
|
|
69
|
+
* {@link /pet/findByTags}
|
|
70
|
+
*/
|
|
71
|
+
export function useFindPetsByTagsInfinite<
|
|
72
|
+
TQueryFnData = FindPetsByTagsQueryResponse,
|
|
73
|
+
TError = ResponseErrorConfig<FindPetsByTags400>,
|
|
74
|
+
TData = InfiniteData<TQueryFnData>,
|
|
75
|
+
TQueryKey extends QueryKey = FindPetsByTagsInfiniteQueryKey,
|
|
76
|
+
TPageParam = NonNullable<FindPetsByTagsQueryParams['pageSize']>,
|
|
77
|
+
>(
|
|
78
|
+
headers: FindPetsByTagsHeaderParams,
|
|
79
|
+
params?: FindPetsByTagsQueryParams,
|
|
80
|
+
options: {
|
|
81
|
+
query?: Partial<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>> & { client?: QueryClient }
|
|
82
|
+
client?: Partial<RequestConfig> & { client?: typeof fetch }
|
|
83
|
+
} = {},
|
|
84
|
+
) {
|
|
85
|
+
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
86
|
+
const { client: queryClient, ...queryOptions } = queryConfig
|
|
87
|
+
const queryKey = queryOptions?.queryKey ?? findPetsByTagsInfiniteQueryKey(params)
|
|
88
|
+
const customOptions = useCustomHookOptions({ hookName: 'useFindPetsByTagsInfinite', operationId: 'findPetsByTags' })
|
|
89
|
+
|
|
90
|
+
const query = useInfiniteQuery(
|
|
91
|
+
{
|
|
92
|
+
...findPetsByTagsInfiniteQueryOptions(headers, params, config),
|
|
93
|
+
...customOptions,
|
|
94
|
+
queryKey,
|
|
95
|
+
...queryOptions,
|
|
96
|
+
} as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,
|
|
97
|
+
queryClient,
|
|
98
|
+
) as UseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }
|
|
99
|
+
|
|
100
|
+
query.queryKey = queryKey as TQueryKey
|
|
101
|
+
|
|
102
|
+
return query
|
|
103
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by Kubb (https://kubb.dev/).
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { RequestConfig, ResponseErrorConfig } from './test/.kubb/fetch'
|
|
6
|
+
import type { QueryKey, QueryClient, UseSuspenseQueryOptions, UseSuspenseQueryResult } from '@tanstack/react-query'
|
|
7
|
+
import { fetch } from './test/.kubb/fetch'
|
|
8
|
+
import { queryOptions, useSuspenseQuery } from '@tanstack/react-query'
|
|
9
|
+
import { useCustomHookOptions } from 'useCustomHookOptions.ts'
|
|
10
|
+
|
|
11
|
+
export const findPetsByTagsSuspenseQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
|
|
12
|
+
|
|
13
|
+
export type FindPetsByTagsSuspenseQueryKey = ReturnType<typeof findPetsByTagsSuspenseQueryKey>
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
17
|
+
* @summary Finds Pets by tags
|
|
18
|
+
* {@link /pet/findByTags}
|
|
19
|
+
*/
|
|
20
|
+
export async function findPetsByTagsSuspense(
|
|
21
|
+
headers: FindPetsByTagsHeaderParams,
|
|
22
|
+
params?: FindPetsByTagsQueryParams,
|
|
23
|
+
config: Partial<RequestConfig> & { client?: typeof fetch } = {},
|
|
24
|
+
) {
|
|
25
|
+
const { client: request = fetch, ...requestConfig } = config
|
|
26
|
+
|
|
27
|
+
const res = await request<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>, unknown>({
|
|
28
|
+
method: 'GET',
|
|
29
|
+
url: `/pet/findByTags`,
|
|
30
|
+
params,
|
|
31
|
+
...requestConfig,
|
|
32
|
+
headers: { ...headers, ...requestConfig.headers },
|
|
33
|
+
})
|
|
34
|
+
return findPetsByTagsQueryResponse.parse(res.data)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function findPetsByTagsSuspenseQueryOptions(
|
|
38
|
+
headers: FindPetsByTagsHeaderParams,
|
|
39
|
+
params?: FindPetsByTagsQueryParams,
|
|
40
|
+
config: Partial<RequestConfig> & { client?: typeof fetch } = {},
|
|
41
|
+
) {
|
|
42
|
+
const queryKey = findPetsByTagsSuspenseQueryKey(params)
|
|
43
|
+
return queryOptions<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>, FindPetsByTagsQueryResponse, typeof queryKey>({
|
|
44
|
+
queryKey,
|
|
45
|
+
queryFn: async ({ signal }) => {
|
|
46
|
+
config.signal = signal
|
|
47
|
+
return findPetsByTagsSuspense(headers, params, config)
|
|
48
|
+
},
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
54
|
+
* @summary Finds Pets by tags
|
|
55
|
+
* {@link /pet/findByTags}
|
|
56
|
+
*/
|
|
57
|
+
export function useFindPetsByTagsSuspense<TData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsSuspenseQueryKey>(
|
|
58
|
+
headers: FindPetsByTagsHeaderParams,
|
|
59
|
+
params?: FindPetsByTagsQueryParams,
|
|
60
|
+
options: {
|
|
61
|
+
query?: Partial<UseSuspenseQueryOptions<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>, TData, TQueryKey>> & { client?: QueryClient }
|
|
62
|
+
client?: Partial<RequestConfig> & { client?: typeof fetch }
|
|
63
|
+
} = {},
|
|
64
|
+
) {
|
|
65
|
+
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
66
|
+
const { client: queryClient, ...queryOptions } = queryConfig
|
|
67
|
+
const queryKey = queryOptions?.queryKey ?? findPetsByTagsSuspenseQueryKey(params)
|
|
68
|
+
const customOptions = useCustomHookOptions({ hookName: 'useFindPetsByTagsSuspense', operationId: 'findPetsByTags' })
|
|
69
|
+
|
|
70
|
+
const query = useSuspenseQuery(
|
|
71
|
+
{
|
|
72
|
+
...findPetsByTagsSuspenseQueryOptions(headers, params, config),
|
|
73
|
+
...customOptions,
|
|
74
|
+
queryKey,
|
|
75
|
+
...queryOptions,
|
|
76
|
+
} as unknown as UseSuspenseQueryOptions,
|
|
77
|
+
queryClient,
|
|
78
|
+
) as UseSuspenseQueryResult<TData, ResponseErrorConfig<FindPetsByTags400>> & { queryKey: TQueryKey }
|
|
79
|
+
|
|
80
|
+
query.queryKey = queryKey as TQueryKey
|
|
81
|
+
|
|
82
|
+
return query
|
|
83
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by Kubb (https://kubb.dev/).
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { RequestConfig, ResponseErrorConfig } from './test/.kubb/fetch'
|
|
6
|
+
import type { InfiniteData, QueryKey, QueryClient, UseSuspenseInfiniteQueryOptions, UseSuspenseInfiniteQueryResult } from '@tanstack/react-query'
|
|
7
|
+
import { fetch } from './test/.kubb/fetch'
|
|
8
|
+
import { infiniteQueryOptions, useSuspenseInfiniteQuery } from '@tanstack/react-query'
|
|
9
|
+
import { useCustomHookOptions } from 'useCustomHookOptions.ts'
|
|
10
|
+
|
|
11
|
+
export const findPetsByTagsSuspenseInfiniteQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
|
|
12
|
+
|
|
13
|
+
export type FindPetsByTagsSuspenseInfiniteQueryKey = ReturnType<typeof findPetsByTagsSuspenseInfiniteQueryKey>
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
17
|
+
* @summary Finds Pets by tags
|
|
18
|
+
* {@link /pet/findByTags}
|
|
19
|
+
*/
|
|
20
|
+
export async function findPetsByTagsSuspenseInfinite(
|
|
21
|
+
headers: FindPetsByTagsHeaderParams,
|
|
22
|
+
params?: FindPetsByTagsQueryParams,
|
|
23
|
+
config: Partial<RequestConfig> & { client?: typeof fetch } = {},
|
|
24
|
+
) {
|
|
25
|
+
const { client: request = fetch, ...requestConfig } = config
|
|
26
|
+
|
|
27
|
+
const res = await request<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>, unknown>({
|
|
28
|
+
method: 'GET',
|
|
29
|
+
url: `/pet/findByTags`,
|
|
30
|
+
params,
|
|
31
|
+
...requestConfig,
|
|
32
|
+
headers: { ...headers, ...requestConfig.headers },
|
|
33
|
+
})
|
|
34
|
+
return findPetsByTagsQueryResponse.parse(res.data)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function findPetsByTagsSuspenseInfiniteQueryOptions(
|
|
38
|
+
headers: FindPetsByTagsHeaderParams,
|
|
39
|
+
params?: FindPetsByTagsQueryParams,
|
|
40
|
+
config: Partial<RequestConfig> & { client?: typeof fetch } = {},
|
|
41
|
+
) {
|
|
42
|
+
const queryKey = findPetsByTagsSuspenseInfiniteQueryKey(params)
|
|
43
|
+
return infiniteQueryOptions<
|
|
44
|
+
FindPetsByTagsQueryResponse,
|
|
45
|
+
ResponseErrorConfig<FindPetsByTags400>,
|
|
46
|
+
InfiniteData<FindPetsByTagsQueryResponse>,
|
|
47
|
+
typeof queryKey,
|
|
48
|
+
NonNullable<FindPetsByTagsQueryParams['pageSize']>
|
|
49
|
+
>({
|
|
50
|
+
queryKey,
|
|
51
|
+
queryFn: async ({ signal, pageParam }) => {
|
|
52
|
+
config.signal = signal
|
|
53
|
+
|
|
54
|
+
params = {
|
|
55
|
+
...(params ?? {}),
|
|
56
|
+
['pageSize']: pageParam as unknown as FindPetsByTagsQueryParams['pageSize'],
|
|
57
|
+
} as FindPetsByTagsQueryParams
|
|
58
|
+
return findPetsByTagsSuspenseInfinite(headers, params, config)
|
|
59
|
+
},
|
|
60
|
+
initialPageParam: 0,
|
|
61
|
+
getNextPageParam: (lastPage, _allPages, lastPageParam) => (Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1),
|
|
62
|
+
getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => (firstPageParam <= 1 ? undefined : firstPageParam - 1),
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
68
|
+
* @summary Finds Pets by tags
|
|
69
|
+
* {@link /pet/findByTags}
|
|
70
|
+
*/
|
|
71
|
+
export function useFindPetsByTagsSuspenseInfinite<
|
|
72
|
+
TQueryFnData = FindPetsByTagsQueryResponse,
|
|
73
|
+
TError = ResponseErrorConfig<FindPetsByTags400>,
|
|
74
|
+
TData = InfiniteData<TQueryFnData>,
|
|
75
|
+
TQueryKey extends QueryKey = FindPetsByTagsSuspenseInfiniteQueryKey,
|
|
76
|
+
TPageParam = NonNullable<FindPetsByTagsQueryParams['pageSize']>,
|
|
77
|
+
>(
|
|
78
|
+
headers: FindPetsByTagsHeaderParams,
|
|
79
|
+
params?: FindPetsByTagsQueryParams,
|
|
80
|
+
options: {
|
|
81
|
+
query?: Partial<UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>> & { client?: QueryClient }
|
|
82
|
+
client?: Partial<RequestConfig> & { client?: typeof fetch }
|
|
83
|
+
} = {},
|
|
84
|
+
) {
|
|
85
|
+
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
86
|
+
const { client: queryClient, ...queryOptions } = queryConfig
|
|
87
|
+
const queryKey = queryOptions?.queryKey ?? findPetsByTagsSuspenseInfiniteQueryKey(params)
|
|
88
|
+
const customOptions = useCustomHookOptions({ hookName: 'useFindPetsByTagsSuspenseInfinite', operationId: 'findPetsByTags' })
|
|
89
|
+
|
|
90
|
+
const query = useSuspenseInfiniteQuery(
|
|
91
|
+
{
|
|
92
|
+
...findPetsByTagsSuspenseInfiniteQueryOptions(headers, params, config),
|
|
93
|
+
...customOptions,
|
|
94
|
+
queryKey,
|
|
95
|
+
...queryOptions,
|
|
96
|
+
} as unknown as UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,
|
|
97
|
+
queryClient,
|
|
98
|
+
) as UseSuspenseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }
|
|
99
|
+
|
|
100
|
+
query.queryKey = queryKey as TQueryKey
|
|
101
|
+
|
|
102
|
+
return query
|
|
103
|
+
}
|
|
@@ -35,13 +35,15 @@ export async function updatePetWithForm(
|
|
|
35
35
|
return updatePetWithFormMutationResponse.parse(res.data)
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export function updatePetWithFormMutationOptions
|
|
38
|
+
export function updatePetWithFormMutationOptions<TContext = unknown>(
|
|
39
|
+
config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof fetch } = {},
|
|
40
|
+
) {
|
|
39
41
|
const mutationKey = updatePetWithFormMutationKey()
|
|
40
42
|
return mutationOptions<
|
|
41
43
|
UpdatePetWithFormMutationResponse,
|
|
42
44
|
ResponseErrorConfig<UpdatePetWithForm405>,
|
|
43
45
|
{ petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams },
|
|
44
|
-
|
|
46
|
+
TContext
|
|
45
47
|
>({
|
|
46
48
|
mutationKey,
|
|
47
49
|
mutationFn: async ({ petId, data, params }) => {
|
|
@@ -35,13 +35,15 @@ export async function updatePetWithForm(
|
|
|
35
35
|
return updatePetWithFormMutationResponse.parse(res.data)
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export function updatePetWithFormMutationOptions
|
|
38
|
+
export function updatePetWithFormMutationOptions<TContext = unknown>(
|
|
39
|
+
config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof fetch } = {},
|
|
40
|
+
) {
|
|
39
41
|
const mutationKey = updatePetWithFormMutationKey()
|
|
40
42
|
return mutationOptions<
|
|
41
43
|
UpdatePetWithFormMutationResponse,
|
|
42
44
|
ResponseErrorConfig<UpdatePetWithForm405>,
|
|
43
45
|
{ petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams },
|
|
44
|
-
|
|
46
|
+
TContext
|
|
45
47
|
>({
|
|
46
48
|
mutationKey,
|
|
47
49
|
mutationFn: async ({ petId, data, params }) => {
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by Kubb (https://kubb.dev/).
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { RequestConfig, ResponseErrorConfig } from './test/.kubb/fetch'
|
|
6
|
+
import type { UseMutationOptions, UseMutationResult, QueryClient } from '@tanstack/react-query'
|
|
7
|
+
import { fetch } from './test/.kubb/fetch'
|
|
8
|
+
import { mutationOptions, useMutation } from '@tanstack/react-query'
|
|
9
|
+
import { useCustomHookOptions } from 'useCustomHookOptions.ts'
|
|
10
|
+
|
|
11
|
+
export const updatePetWithFormMutationKey = () => [{ url: '/pet/:pet_id' }] as const
|
|
12
|
+
|
|
13
|
+
export type UpdatePetWithFormMutationKey = ReturnType<typeof updatePetWithFormMutationKey>
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @summary Updates a pet in the store with form data
|
|
17
|
+
* {@link /pet/:pet_id}
|
|
18
|
+
*/
|
|
19
|
+
export async function updatePetWithForm(
|
|
20
|
+
petId: UpdatePetWithFormPathParams['petId'],
|
|
21
|
+
data?: UpdatePetWithFormMutationRequest,
|
|
22
|
+
params?: UpdatePetWithFormQueryParams,
|
|
23
|
+
config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof fetch } = {},
|
|
24
|
+
) {
|
|
25
|
+
const { client: request = fetch, ...requestConfig } = config
|
|
26
|
+
|
|
27
|
+
const requestData = updatePetWithFormMutationRequest.parse(data)
|
|
28
|
+
|
|
29
|
+
const res = await request<UpdatePetWithFormMutationResponse, ResponseErrorConfig<UpdatePetWithForm405>, UpdatePetWithFormMutationRequest>({
|
|
30
|
+
method: 'POST',
|
|
31
|
+
url: `/pet/${pet_id}`,
|
|
32
|
+
params,
|
|
33
|
+
data: requestData,
|
|
34
|
+
...requestConfig,
|
|
35
|
+
})
|
|
36
|
+
return updatePetWithFormMutationResponse.parse(res.data)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function updatePetWithFormMutationOptions<TContext = unknown>(
|
|
40
|
+
config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof fetch } = {},
|
|
41
|
+
) {
|
|
42
|
+
const mutationKey = updatePetWithFormMutationKey()
|
|
43
|
+
return mutationOptions<
|
|
44
|
+
UpdatePetWithFormMutationResponse,
|
|
45
|
+
ResponseErrorConfig<UpdatePetWithForm405>,
|
|
46
|
+
{ petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams },
|
|
47
|
+
TContext
|
|
48
|
+
>({
|
|
49
|
+
mutationKey,
|
|
50
|
+
mutationFn: async ({ petId, data, params }) => {
|
|
51
|
+
return updatePetWithForm(petId, data, params, config)
|
|
52
|
+
},
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @summary Updates a pet in the store with form data
|
|
58
|
+
* {@link /pet/:pet_id}
|
|
59
|
+
*/
|
|
60
|
+
export function useUpdatePetWithForm<TContext>(
|
|
61
|
+
options: {
|
|
62
|
+
mutation?: UseMutationOptions<
|
|
63
|
+
UpdatePetWithFormMutationResponse,
|
|
64
|
+
ResponseErrorConfig<UpdatePetWithForm405>,
|
|
65
|
+
{ petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams },
|
|
66
|
+
TContext
|
|
67
|
+
> & { client?: QueryClient }
|
|
68
|
+
client?: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof fetch }
|
|
69
|
+
} = {},
|
|
70
|
+
) {
|
|
71
|
+
const { mutation = {}, client: config = {} } = options ?? {}
|
|
72
|
+
const { client: queryClient, ...mutationOptions } = mutation
|
|
73
|
+
const mutationKey = mutationOptions.mutationKey ?? updatePetWithFormMutationKey()
|
|
74
|
+
|
|
75
|
+
const baseOptions = updatePetWithFormMutationOptions(config) as UseMutationOptions<
|
|
76
|
+
UpdatePetWithFormMutationResponse,
|
|
77
|
+
ResponseErrorConfig<UpdatePetWithForm405>,
|
|
78
|
+
{ petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams },
|
|
79
|
+
TContext
|
|
80
|
+
>
|
|
81
|
+
const customOptions = useCustomHookOptions({ hookName: 'useUpdatePetWithForm', operationId: 'updatePetWithForm' }) as UseMutationOptions<
|
|
82
|
+
UpdatePetWithFormMutationResponse,
|
|
83
|
+
ResponseErrorConfig<UpdatePetWithForm405>,
|
|
84
|
+
{ petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams },
|
|
85
|
+
TContext
|
|
86
|
+
>
|
|
87
|
+
|
|
88
|
+
return useMutation<
|
|
89
|
+
UpdatePetWithFormMutationResponse,
|
|
90
|
+
ResponseErrorConfig<UpdatePetWithForm405>,
|
|
91
|
+
{ petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams },
|
|
92
|
+
TContext
|
|
93
|
+
>(
|
|
94
|
+
{
|
|
95
|
+
...baseOptions,
|
|
96
|
+
...customOptions,
|
|
97
|
+
mutationKey,
|
|
98
|
+
...mutationOptions,
|
|
99
|
+
},
|
|
100
|
+
queryClient,
|
|
101
|
+
) as UseMutationResult<
|
|
102
|
+
UpdatePetWithFormMutationResponse,
|
|
103
|
+
ResponseErrorConfig<UpdatePetWithForm405>,
|
|
104
|
+
{ petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams },
|
|
105
|
+
TContext
|
|
106
|
+
>
|
|
107
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { usePluginManager } from '@kubb/core/hooks'
|
|
4
|
+
import type { Operation } from '@kubb/oas'
|
|
5
|
+
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
6
|
+
import { useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
7
|
+
import { File, Function } from '@kubb/react-fabric'
|
|
8
|
+
import type { PluginReactQuery } from '../types'
|
|
9
|
+
|
|
10
|
+
export const customHookOptionsFileGenerator = createReactGenerator<PluginReactQuery>({
|
|
11
|
+
name: 'react-query-custom-hook-options-file',
|
|
12
|
+
Operations({ operations, generator, plugin, config }) {
|
|
13
|
+
const {
|
|
14
|
+
options,
|
|
15
|
+
options: { output },
|
|
16
|
+
key: pluginKey,
|
|
17
|
+
} = plugin
|
|
18
|
+
const pluginManager = usePluginManager()
|
|
19
|
+
|
|
20
|
+
const { getFile } = useOperationManager(generator)
|
|
21
|
+
|
|
22
|
+
if (!options.customOptions) {
|
|
23
|
+
return null
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const override = output.override ?? config.output.override ?? false
|
|
27
|
+
const { importPath, name } = options.customOptions
|
|
28
|
+
|
|
29
|
+
const root = path.resolve(config.root, config.output.path)
|
|
30
|
+
|
|
31
|
+
const reactQueryImportPath = options.query ? options.query.importPath : '@tanstack/react-query'
|
|
32
|
+
|
|
33
|
+
const getHookFilePath = (operations: Operation[]) => {
|
|
34
|
+
const firstOperation = operations[0]
|
|
35
|
+
if (firstOperation != null) {
|
|
36
|
+
// Get the file of the first generated hook
|
|
37
|
+
return getFile(firstOperation, { prefix: 'use' }).path
|
|
38
|
+
}
|
|
39
|
+
// Get the index file of the hooks directory
|
|
40
|
+
return pluginManager.getFile({ name: 'index', extname: '.ts', pluginKey }).path
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const ensureExtension = (filePath: string, extname: string) => {
|
|
44
|
+
if (path.extname(filePath) === '') {
|
|
45
|
+
return filePath + extname
|
|
46
|
+
}
|
|
47
|
+
return filePath
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const getExternalFile = (filePath: string, rootPath: string) => {
|
|
51
|
+
const actualFilePath = ensureExtension(filePath, '.ts')
|
|
52
|
+
return {
|
|
53
|
+
baseName: path.basename(actualFilePath) as `${string}.${string}`,
|
|
54
|
+
name: path.basename(actualFilePath, path.extname(actualFilePath)),
|
|
55
|
+
path: path.resolve(rootPath, actualFilePath),
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const basePath = path.dirname(getHookFilePath(operations))
|
|
60
|
+
const file = getExternalFile(importPath, basePath)
|
|
61
|
+
|
|
62
|
+
if (fs.existsSync(file.path) && !override) {
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<File baseName={file.baseName} path={file.path}>
|
|
68
|
+
<File.Import name={['QueryClient']} path={reactQueryImportPath} isTypeOnly />
|
|
69
|
+
<File.Import name={['useQueryClient']} path={reactQueryImportPath} />
|
|
70
|
+
<File.Import name={['HookOptions']} root={file.path} path={path.resolve(root, './index.ts')} />
|
|
71
|
+
<File.Source name={file.name} isExportable isIndexable>
|
|
72
|
+
<Function name="getCustomHookOptions" params="{ queryClient }: { queryClient: QueryClient }" returnType="Partial<HookOptions>">
|
|
73
|
+
{`return {
|
|
74
|
+
// TODO: Define custom hook options here
|
|
75
|
+
// Example:
|
|
76
|
+
// useUpdatePetHook: {
|
|
77
|
+
// onSuccess: () => {
|
|
78
|
+
// void queryClient.invalidateQueries({ queryKey: ['pet'] })
|
|
79
|
+
// }
|
|
80
|
+
// }
|
|
81
|
+
}`}
|
|
82
|
+
</Function>
|
|
83
|
+
<Function
|
|
84
|
+
name={name}
|
|
85
|
+
generics="T extends keyof HookOptions"
|
|
86
|
+
params="{ hookName, operationId }: { hookName: T, operationId: string }"
|
|
87
|
+
returnType="HookOptions[T]"
|
|
88
|
+
export
|
|
89
|
+
>
|
|
90
|
+
{`const queryClient = useQueryClient()
|
|
91
|
+
const customOptions = getCustomHookOptions({ queryClient })
|
|
92
|
+
return customOptions[hookName] ?? {}`}
|
|
93
|
+
</Function>
|
|
94
|
+
</File.Source>
|
|
95
|
+
</File>
|
|
96
|
+
)
|
|
97
|
+
},
|
|
98
|
+
})
|