@kubb/plugin-react-query 3.0.0-alpha.9 → 3.0.0-beta.10
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/README.md +14 -5
- package/dist/chunk-24SL7I66.cjs +683 -0
- package/dist/chunk-24SL7I66.cjs.map +1 -0
- package/dist/chunk-BML6BZ4F.cjs +878 -0
- package/dist/chunk-BML6BZ4F.cjs.map +1 -0
- package/dist/chunk-JFIGHRBM.js +867 -0
- package/dist/chunk-JFIGHRBM.js.map +1 -0
- package/dist/chunk-LBVGJA4Q.js +674 -0
- package/dist/chunk-LBVGJA4Q.js.map +1 -0
- package/dist/components.cjs +39 -12
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +172 -6
- package/dist/components.d.ts +172 -6
- package/dist/components.js +2 -12
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +25 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +14 -0
- package/dist/generators.d.ts +14 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +80 -130
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -4
- package/dist/index.d.ts +1 -4
- package/dist/index.js +63 -120
- package/dist/index.js.map +1 -1
- package/dist/types-Dlwxp28D.d.cts +230 -0
- package/dist/types-Dlwxp28D.d.ts +230 -0
- package/package.json +22 -17
- package/src/components/InfiniteQuery.tsx +176 -0
- package/src/components/InfiniteQueryOptions.tsx +185 -0
- package/src/components/Mutation.tsx +142 -320
- package/src/components/MutationKey.tsx +48 -0
- package/src/components/Query.tsx +145 -592
- package/src/components/QueryKey.tsx +51 -182
- package/src/components/QueryOptions.tsx +110 -472
- package/src/components/SuspenseQuery.tsx +176 -0
- package/src/components/index.ts +4 -0
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +51 -0
- package/src/generators/__snapshots__/clientGetImportPath.ts +51 -0
- package/src/generators/__snapshots__/clientPostImportPath.ts +44 -0
- package/src/generators/__snapshots__/findByTags.ts +51 -0
- package/src/generators/__snapshots__/findByTagsObject.ts +60 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +51 -0
- package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +51 -0
- package/src/generators/__snapshots__/findByTagsWithZod.ts +51 -0
- package/src/generators/__snapshots__/findInfiniteByTags.ts +57 -0
- package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +57 -0
- package/src/generators/__snapshots__/getAsMutation.ts +31 -0
- package/src/generators/__snapshots__/postAsQuery.ts +50 -0
- package/src/generators/__snapshots__/updatePetById.ts +44 -0
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +44 -0
- package/src/generators/index.ts +4 -0
- package/src/generators/infiniteQueryGenerator.tsx +126 -0
- package/src/generators/mutationGenerator.tsx +109 -0
- package/src/generators/queryGenerator.tsx +123 -0
- package/src/generators/suspenseQueryGenerator.tsx +123 -0
- package/src/plugin.ts +62 -76
- package/src/types.ts +49 -126
- package/dist/chunk-7ZODZVKP.cjs +0 -1470
- package/dist/chunk-7ZODZVKP.cjs.map +0 -1
- package/dist/chunk-ZYTZV43V.js +0 -1470
- package/dist/chunk-ZYTZV43V.js.map +0 -1
- package/dist/index-5kpkk-7M.d.cts +0 -545
- package/dist/index-5kpkk-7M.d.ts +0 -545
- package/src/OperationGenerator.tsx +0 -57
- package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -69
- package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -62
- package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -68
- package/src/__snapshots__/queryOptions/getPetById.ts +0 -41
- package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -51
- package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -24
- package/src/components/QueryImports.tsx +0 -167
- package/src/components/SchemaType.tsx +0 -59
- package/src/components/__snapshots__/gen/showPetById.ts +0 -67
- package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
- package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -46
- package/src/utils.ts +0 -96
|
@@ -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 { useInfiniteQuery, infiniteQueryOptions } 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 { useQuery, queryOptions } 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,126 @@
|
|
|
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 query = {
|
|
24
|
+
name: getName(operation, { type: 'function', prefix: 'use', suffix: 'infinite' }),
|
|
25
|
+
typeName: getName(operation, { type: 'type' }),
|
|
26
|
+
file: getFile(operation, { prefix: 'use', suffix: 'infinite' }),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const client = {
|
|
30
|
+
name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const queryOptions = {
|
|
34
|
+
name: getName(operation, { type: 'function', suffix: 'InfiniteQueryOptions' }),
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const queryKey = {
|
|
38
|
+
name: getName(operation, { type: 'const', suffix: 'InfiniteQueryKey' }),
|
|
39
|
+
typeName: getName(operation, { type: 'type', suffix: 'InfiniteQueryKey' }),
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const type = {
|
|
43
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
44
|
+
//todo remove type?
|
|
45
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const zod = {
|
|
49
|
+
file: getFile(operation, { pluginKey: [pluginZodName] }),
|
|
50
|
+
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (!isQuery || !isInfinite || typeof options.query === 'boolean' || typeof options.infinite === 'boolean') {
|
|
54
|
+
return null
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
59
|
+
{options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
|
|
60
|
+
<File.Import name={['useInfiniteQuery', 'infiniteQueryOptions']} path={options.query.importPath} />
|
|
61
|
+
<File.Import name={['QueryKey', 'WithRequired', 'InfiniteQueryObserverOptions', 'UseInfiniteQueryResult']} path={options.query.importPath} isTypeOnly />
|
|
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
|
+
|
|
79
|
+
<QueryKey
|
|
80
|
+
name={queryKey.name}
|
|
81
|
+
typeName={queryKey.typeName}
|
|
82
|
+
operation={operation}
|
|
83
|
+
pathParamsType={options.pathParamsType}
|
|
84
|
+
typeSchemas={type.schemas}
|
|
85
|
+
keysFn={options.query.key}
|
|
86
|
+
/>
|
|
87
|
+
<Client
|
|
88
|
+
name={client.name}
|
|
89
|
+
isExportable={false}
|
|
90
|
+
isIndexable={false}
|
|
91
|
+
baseURL={options.baseURL}
|
|
92
|
+
operation={operation}
|
|
93
|
+
typeSchemas={type.schemas}
|
|
94
|
+
zodSchemas={zod.schemas}
|
|
95
|
+
dataReturnType={options.client.dataReturnType}
|
|
96
|
+
paramsType={options.paramsType}
|
|
97
|
+
pathParamsType={options.pathParamsType}
|
|
98
|
+
parser={options.parser}
|
|
99
|
+
/>
|
|
100
|
+
<InfiniteQueryOptions
|
|
101
|
+
name={queryOptions.name}
|
|
102
|
+
clientName={client.name}
|
|
103
|
+
queryKeyName={queryKey.name}
|
|
104
|
+
typeSchemas={type.schemas}
|
|
105
|
+
paramsType={options.paramsType}
|
|
106
|
+
pathParamsType={options.pathParamsType}
|
|
107
|
+
dataReturnType={options.client.dataReturnType}
|
|
108
|
+
cursorParam={options.infinite.cursorParam}
|
|
109
|
+
initialPageParam={options.infinite.initialPageParam}
|
|
110
|
+
queryParam={options.infinite.queryParam}
|
|
111
|
+
/>
|
|
112
|
+
<InfiniteQuery
|
|
113
|
+
name={query.name}
|
|
114
|
+
queryOptionsName={queryOptions.name}
|
|
115
|
+
typeSchemas={type.schemas}
|
|
116
|
+
paramsType={options.paramsType}
|
|
117
|
+
pathParamsType={options.pathParamsType}
|
|
118
|
+
operation={operation}
|
|
119
|
+
dataReturnType={options.client.dataReturnType}
|
|
120
|
+
queryKeyName={queryKey.name}
|
|
121
|
+
queryKeyTypeName={queryKey.typeName}
|
|
122
|
+
/>
|
|
123
|
+
</File>
|
|
124
|
+
)
|
|
125
|
+
},
|
|
126
|
+
})
|
|
@@ -0,0 +1,109 @@
|
|
|
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 mutation = {
|
|
25
|
+
name: getName(operation, { type: 'function', prefix: 'use' }),
|
|
26
|
+
typeName: getName(operation, { type: 'type' }),
|
|
27
|
+
file: getFile(operation, { prefix: 'use' }),
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const type = {
|
|
31
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
32
|
+
//todo remove type?
|
|
33
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const zod = {
|
|
37
|
+
file: getFile(operation, { pluginKey: [pluginZodName] }),
|
|
38
|
+
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const client = {
|
|
42
|
+
name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const mutationKey = {
|
|
46
|
+
name: getName(operation, { type: 'const', suffix: 'MutationKey' }),
|
|
47
|
+
typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!isMutation || typeof options.mutation === 'boolean') {
|
|
51
|
+
return null
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<File baseName={mutation.file.baseName} path={mutation.file.path} meta={mutation.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
56
|
+
{options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />}
|
|
57
|
+
<File.Import name={['useMutation']} path={options.mutation.importPath} />
|
|
58
|
+
<File.Import name={['UseMutationOptions']} path={options.mutation.importPath} isTypeOnly />
|
|
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
|
+
<MutationKey
|
|
75
|
+
name={mutationKey.name}
|
|
76
|
+
typeName={mutationKey.typeName}
|
|
77
|
+
operation={operation}
|
|
78
|
+
pathParamsType={options.pathParamsType}
|
|
79
|
+
typeSchemas={type.schemas}
|
|
80
|
+
keysFn={options.mutation.key}
|
|
81
|
+
/>
|
|
82
|
+
<Client
|
|
83
|
+
name={client.name}
|
|
84
|
+
isExportable={false}
|
|
85
|
+
isIndexable={false}
|
|
86
|
+
baseURL={options.baseURL}
|
|
87
|
+
operation={operation}
|
|
88
|
+
typeSchemas={type.schemas}
|
|
89
|
+
zodSchemas={zod.schemas}
|
|
90
|
+
dataReturnType={options.client.dataReturnType}
|
|
91
|
+
paramsType={options.paramsType}
|
|
92
|
+
pathParamsType={options.pathParamsType}
|
|
93
|
+
parser={options.parser}
|
|
94
|
+
/>
|
|
95
|
+
<Mutation
|
|
96
|
+
name={mutation.name}
|
|
97
|
+
clientName={client.name}
|
|
98
|
+
typeName={mutation.typeName}
|
|
99
|
+
typeSchemas={type.schemas}
|
|
100
|
+
operation={operation}
|
|
101
|
+
dataReturnType={options.client.dataReturnType}
|
|
102
|
+
paramsType={options.paramsType}
|
|
103
|
+
pathParamsType={options.pathParamsType}
|
|
104
|
+
mutationKeyName={mutationKey.name}
|
|
105
|
+
/>
|
|
106
|
+
</File>
|
|
107
|
+
)
|
|
108
|
+
},
|
|
109
|
+
})
|
|
@@ -0,0 +1,123 @@
|
|
|
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 { Query, QueryKey, QueryOptions } from '../components'
|
|
9
|
+
import type { PluginReactQuery } from '../types'
|
|
10
|
+
|
|
11
|
+
export const queryGenerator = 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 query = {
|
|
25
|
+
name: getName(operation, { type: 'function', prefix: 'use' }),
|
|
26
|
+
typeName: getName(operation, { type: 'type' }),
|
|
27
|
+
file: getFile(operation, { prefix: 'use' }),
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const client = {
|
|
31
|
+
name: getName(operation, { type: 'function', pluginKey: [pluginClientName] }),
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const queryOptions = {
|
|
35
|
+
name: getName(operation, { type: 'function', suffix: 'QueryOptions' }),
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const queryKey = {
|
|
39
|
+
name: getName(operation, { type: 'const', suffix: 'QueryKey' }),
|
|
40
|
+
typeName: getName(operation, { type: 'type', suffix: 'QueryKey' }),
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const type = {
|
|
44
|
+
file: getFile(operation, { pluginKey: [pluginTsName] }),
|
|
45
|
+
//todo remove type?
|
|
46
|
+
schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const zod = {
|
|
50
|
+
file: getFile(operation, { pluginKey: [pluginZodName] }),
|
|
51
|
+
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (!isQuery || typeof options.query === 'boolean') {
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
60
|
+
{options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
|
|
61
|
+
<File.Import name={['useQuery', 'queryOptions']} path={options.query.importPath} />
|
|
62
|
+
<File.Import name={['QueryKey', 'WithRequired', 'QueryObserverOptions', 'UseQueryResult']} path={options.query.importPath} isTypeOnly />
|
|
63
|
+
<File.Import name={'client'} path={options.client.importPath} />
|
|
64
|
+
<File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
|
|
65
|
+
{options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
|
|
66
|
+
<File.Import
|
|
67
|
+
name={[
|
|
68
|
+
type.schemas.request?.name,
|
|
69
|
+
type.schemas.response.name,
|
|
70
|
+
type.schemas.pathParams?.name,
|
|
71
|
+
type.schemas.queryParams?.name,
|
|
72
|
+
type.schemas.headerParams?.name,
|
|
73
|
+
...(type.schemas.statusCodes?.map((item) => item.name) || []),
|
|
74
|
+
].filter(Boolean)}
|
|
75
|
+
root={query.file.path}
|
|
76
|
+
path={type.file.path}
|
|
77
|
+
isTypeOnly
|
|
78
|
+
/>
|
|
79
|
+
|
|
80
|
+
<QueryKey
|
|
81
|
+
name={queryKey.name}
|
|
82
|
+
typeName={queryKey.typeName}
|
|
83
|
+
operation={operation}
|
|
84
|
+
pathParamsType={options.pathParamsType}
|
|
85
|
+
typeSchemas={type.schemas}
|
|
86
|
+
keysFn={options.query.key}
|
|
87
|
+
/>
|
|
88
|
+
<Client
|
|
89
|
+
name={client.name}
|
|
90
|
+
isExportable={false}
|
|
91
|
+
isIndexable={false}
|
|
92
|
+
baseURL={options.baseURL}
|
|
93
|
+
operation={operation}
|
|
94
|
+
typeSchemas={type.schemas}
|
|
95
|
+
zodSchemas={zod.schemas}
|
|
96
|
+
dataReturnType={options.client.dataReturnType}
|
|
97
|
+
paramsType={options.paramsType}
|
|
98
|
+
pathParamsType={options.pathParamsType}
|
|
99
|
+
parser={options.parser}
|
|
100
|
+
/>
|
|
101
|
+
<QueryOptions
|
|
102
|
+
name={queryOptions.name}
|
|
103
|
+
clientName={client.name}
|
|
104
|
+
queryKeyName={queryKey.name}
|
|
105
|
+
typeSchemas={type.schemas}
|
|
106
|
+
paramsType={options.paramsType}
|
|
107
|
+
pathParamsType={options.pathParamsType}
|
|
108
|
+
/>
|
|
109
|
+
<Query
|
|
110
|
+
name={query.name}
|
|
111
|
+
queryOptionsName={queryOptions.name}
|
|
112
|
+
typeSchemas={type.schemas}
|
|
113
|
+
paramsType={options.paramsType}
|
|
114
|
+
pathParamsType={options.pathParamsType}
|
|
115
|
+
operation={operation}
|
|
116
|
+
dataReturnType={options.client.dataReturnType}
|
|
117
|
+
queryKeyName={queryKey.name}
|
|
118
|
+
queryKeyTypeName={queryKey.typeName}
|
|
119
|
+
/>
|
|
120
|
+
</File>
|
|
121
|
+
)
|
|
122
|
+
},
|
|
123
|
+
})
|