@kubb/plugin-react-query 0.0.0-canary-20241104172400

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