@kubb/plugin-react-query 4.14.1 → 4.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/{components-CO636qn3.cjs → components-7ul5AP_u.cjs} +17 -12
  2. package/dist/components-7ul5AP_u.cjs.map +1 -0
  3. package/dist/{components-DQHnoHX_.js → components-CX83mklO.js} +16 -11
  4. package/dist/components-CX83mklO.js.map +1 -0
  5. package/dist/components.cjs +1 -1
  6. package/dist/components.d.cts +15 -5
  7. package/dist/components.d.ts +15 -5
  8. package/dist/components.js +1 -1
  9. package/dist/{generators-BNtUetHy.cjs → generators-CNv1RI1y.cjs} +331 -6
  10. package/dist/generators-CNv1RI1y.cjs.map +1 -0
  11. package/dist/{generators-Cz0OG9Qu.js → generators-CVc1Qlnh.js} +320 -8
  12. package/dist/generators-CVc1Qlnh.js.map +1 -0
  13. package/dist/generators.cjs +3 -1
  14. package/dist/generators.d.cts +8 -2
  15. package/dist/generators.d.ts +8 -2
  16. package/dist/generators.js +2 -2
  17. package/dist/index.cjs +10 -4
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.js +10 -4
  22. package/dist/index.js.map +1 -1
  23. package/dist/{types-Cli5EJ4L.d.ts → types-B9xv5S0R.d.cts} +35 -2
  24. package/dist/{types-B2aUnqdY.d.cts → types-BAEc42Ae.d.ts} +35 -2
  25. package/package.json +7 -7
  26. package/src/components/InfiniteQuery.tsx +4 -1
  27. package/src/components/Mutation.tsx +4 -1
  28. package/src/components/Query.tsx +4 -1
  29. package/src/components/SuspenseInfiniteQuery.tsx +4 -1
  30. package/src/components/SuspenseQuery.tsx +4 -1
  31. package/src/generators/__snapshots__/findByTagsWithCustomOptions.ts +89 -0
  32. package/src/generators/__snapshots__/findInfiniteByTagsWithCustomOptions.ts +103 -0
  33. package/src/generators/__snapshots__/findSuspenseByTagsWithCustomOptions.ts +83 -0
  34. package/src/generators/__snapshots__/findSuspenseInfiniteByTagsWithCustomOptions.ts +103 -0
  35. package/src/generators/__snapshots__/updatePetByIdWithCustomOptions.ts +105 -0
  36. package/src/generators/customHookOptionsFileGenerator.tsx +98 -0
  37. package/src/generators/hookOptionsGenerator.tsx +196 -0
  38. package/src/generators/index.ts +2 -0
  39. package/src/generators/infiniteQueryGenerator.tsx +2 -0
  40. package/src/generators/mutationGenerator.tsx +2 -0
  41. package/src/generators/queryGenerator.tsx +2 -0
  42. package/src/generators/suspenseInfiniteQueryGenerator.tsx +2 -0
  43. package/src/generators/suspenseQueryGenerator.tsx +2 -0
  44. package/src/plugin.ts +20 -2
  45. package/src/types.ts +21 -0
  46. package/dist/components-CO636qn3.cjs.map +0 -1
  47. package/dist/components-DQHnoHX_.js.map +0 -1
  48. package/dist/generators-BNtUetHy.cjs.map +0 -1
  49. 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
+ }
@@ -0,0 +1,105 @@
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(config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof fetch } = {}) {
40
+ const mutationKey = updatePetWithFormMutationKey()
41
+ return mutationOptions<
42
+ UpdatePetWithFormMutationResponse,
43
+ ResponseErrorConfig<UpdatePetWithForm405>,
44
+ { petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams },
45
+ typeof mutationKey
46
+ >({
47
+ mutationKey,
48
+ mutationFn: async ({ petId, data, params }) => {
49
+ return updatePetWithForm(petId, data, params, config)
50
+ },
51
+ })
52
+ }
53
+
54
+ /**
55
+ * @summary Updates a pet in the store with form data
56
+ * {@link /pet/:pet_id}
57
+ */
58
+ export function useUpdatePetWithForm<TContext>(
59
+ options: {
60
+ mutation?: UseMutationOptions<
61
+ UpdatePetWithFormMutationResponse,
62
+ ResponseErrorConfig<UpdatePetWithForm405>,
63
+ { petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams },
64
+ TContext
65
+ > & { client?: QueryClient }
66
+ client?: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> & { client?: typeof fetch }
67
+ } = {},
68
+ ) {
69
+ const { mutation = {}, client: config = {} } = options ?? {}
70
+ const { client: queryClient, ...mutationOptions } = mutation
71
+ const mutationKey = mutationOptions.mutationKey ?? updatePetWithFormMutationKey()
72
+
73
+ const baseOptions = updatePetWithFormMutationOptions(config) as UseMutationOptions<
74
+ UpdatePetWithFormMutationResponse,
75
+ ResponseErrorConfig<UpdatePetWithForm405>,
76
+ { petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams },
77
+ TContext
78
+ >
79
+ const customOptions = useCustomHookOptions({ hookName: 'useUpdatePetWithForm', operationId: 'updatePetWithForm' }) as UseMutationOptions<
80
+ UpdatePetWithFormMutationResponse,
81
+ ResponseErrorConfig<UpdatePetWithForm405>,
82
+ { petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams },
83
+ TContext
84
+ >
85
+
86
+ return useMutation<
87
+ UpdatePetWithFormMutationResponse,
88
+ ResponseErrorConfig<UpdatePetWithForm405>,
89
+ { petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams },
90
+ TContext
91
+ >(
92
+ {
93
+ ...baseOptions,
94
+ ...customOptions,
95
+ mutationKey,
96
+ ...mutationOptions,
97
+ },
98
+ queryClient,
99
+ ) as UseMutationResult<
100
+ UpdatePetWithFormMutationResponse,
101
+ ResponseErrorConfig<UpdatePetWithForm405>,
102
+ { petId: UpdatePetWithFormPathParams['petId']; data?: UpdatePetWithFormMutationRequest; params?: UpdatePetWithFormQueryParams },
103
+ TContext
104
+ >
105
+ }
@@ -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
+ })