@kubb/plugin-react-query 3.0.0-alpha.9 → 3.0.0-beta.2
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-37VO6QXJ.cjs +669 -0
- package/dist/chunk-37VO6QXJ.cjs.map +1 -0
- package/dist/chunk-C2H3KPHM.cjs +658 -0
- package/dist/chunk-C2H3KPHM.cjs.map +1 -0
- package/dist/chunk-IRW2Y3EC.js +660 -0
- package/dist/chunk-IRW2Y3EC.js.map +1 -0
- package/dist/chunk-Y3DM2P6L.js +647 -0
- package/dist/chunk-Y3DM2P6L.js.map +1 -0
- package/dist/components.cjs +39 -12
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +161 -6
- package/dist/components.d.ts +161 -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 +78 -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 +61 -120
- package/dist/index.js.map +1 -1
- package/dist/types-5pnOmDmM.d.cts +231 -0
- package/dist/types-5pnOmDmM.d.ts +231 -0
- package/package.json +22 -17
- package/src/components/InfiniteQuery.tsx +129 -0
- package/src/components/InfiniteQueryOptions.tsx +130 -0
- package/src/components/Mutation.tsx +137 -321
- package/src/components/MutationKey.tsx +48 -0
- package/src/components/Query.tsx +91 -594
- package/src/components/QueryKey.tsx +51 -182
- package/src/components/QueryOptions.tsx +71 -473
- package/src/components/SuspenseQuery.tsx +129 -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__/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 +46 -0
- package/src/generators/index.ts +4 -0
- package/src/generators/infiniteQueryGenerator.tsx +124 -0
- package/src/generators/mutationGenerator.tsx +108 -0
- package/src/generators/queryGenerator.tsx +121 -0
- package/src/generators/suspenseQueryGenerator.tsx +120 -0
- package/src/plugin.ts +60 -76
- package/src/types.ts +42 -115
- 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
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import client from "@kubb/plugin-client/client";
|
|
2
|
-
import type { UseBaseQueryOptions, UseQueryResult, QueryKey, WithRequired } from "@tanstack/react-query";
|
|
3
|
-
import { useQuery } from "@tanstack/react-query";
|
|
4
|
-
|
|
5
|
-
type GetPetByIdClient = typeof client<GetPetByIdQueryResponse, GetPetById400 | GetPetById404, never>;
|
|
6
|
-
|
|
7
|
-
type GetPetById = {
|
|
8
|
-
data: GetPetByIdQueryResponse;
|
|
9
|
-
error: GetPetById400 | GetPetById404;
|
|
10
|
-
request: never;
|
|
11
|
-
pathParams: GetPetByIdPathParams;
|
|
12
|
-
queryParams: never;
|
|
13
|
-
headerParams: never;
|
|
14
|
-
response: GetPetByIdQueryResponse;
|
|
15
|
-
client: {
|
|
16
|
-
parameters: Partial<Parameters<GetPetByIdClient>[0]>;
|
|
17
|
-
return: Awaited<ReturnType<GetPetByIdClient>>;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const getPetByIdQueryKey = (petId: GetPetByIdPathParams["petId"]) => [{ url: "/pet/:petId", params: { petId: petId } }] as const;
|
|
22
|
-
|
|
23
|
-
export type GetPetByIdQueryKey = ReturnType<typeof getPetByIdQueryKey>;
|
|
24
|
-
|
|
25
|
-
export function getPetByIdQueryOptions<TData = GetPetById["response"], TQueryData = GetPetById["response"]>(petId: GetPetByIdPathParams["petId"], options: GetPetById["client"]["parameters"] = {}): WithRequired<UseBaseQueryOptions<GetPetById["response"], GetPetById["error"], TData, TQueryData>, "queryKey"> {
|
|
26
|
-
const queryKey = getPetByIdQueryKey(petId);
|
|
27
|
-
return {
|
|
28
|
-
queryKey,
|
|
29
|
-
queryFn: async () => {
|
|
30
|
-
const res = await client<GetPetById["data"], GetPetById["error"]>({
|
|
31
|
-
method: "get",
|
|
32
|
-
url: `/pet/${petId}`,
|
|
33
|
-
...options
|
|
34
|
-
});
|
|
35
|
-
return res.data;
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @description Returns a single pet
|
|
42
|
-
* @summary Find pet by ID
|
|
43
|
-
* @link /pet/:petId
|
|
44
|
-
*/
|
|
45
|
-
export function getPetById<TData = GetPetById["response"], TQueryData = GetPetById["response"], TQueryKey extends QueryKey = GetPetByIdQueryKey>(petId: GetPetByIdPathParams["petId"], options: {
|
|
46
|
-
query?: Partial<UseBaseQueryOptions<GetPetById["response"], GetPetById["error"], TData, TQueryData, TQueryKey>>;
|
|
47
|
-
client?: GetPetById["client"]["parameters"];
|
|
48
|
-
} = {}): UseQueryResult<TData, GetPetById["error"]> & {
|
|
49
|
-
queryKey: TQueryKey;
|
|
50
|
-
} {
|
|
51
|
-
const { query: queryOptions, client: clientOptions = {} } = options ?? {};
|
|
52
|
-
const queryKey = queryOptions?.queryKey ?? getPetByIdQueryKey(petId);
|
|
53
|
-
const query = useQuery<GetPetById["data"], GetPetById["error"], TData, any>({
|
|
54
|
-
...getPetByIdQueryOptions<TData, TQueryData>(petId, clientOptions),
|
|
55
|
-
queryKey,
|
|
56
|
-
...queryOptions
|
|
57
|
-
}) as UseQueryResult<TData, GetPetById["error"]> & {
|
|
58
|
-
queryKey: TQueryKey;
|
|
59
|
-
};
|
|
60
|
-
query.queryKey = queryKey as TQueryKey;
|
|
61
|
-
return query;
|
|
62
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import client from "@kubb/plugin-client/client";
|
|
2
|
-
import type { UseBaseQueryOptions, UseQueryResult, QueryKey, WithRequired } from "@tanstack/react-query";
|
|
3
|
-
import { useQuery } from "@tanstack/react-query";
|
|
4
|
-
|
|
5
|
-
type GetPetByIdClient = typeof client<GetPetByIdQueryResponse, GetPetById400 | GetPetById404, never>;
|
|
6
|
-
|
|
7
|
-
type GetPetById = {
|
|
8
|
-
data: GetPetByIdQueryResponse;
|
|
9
|
-
error: GetPetById400 | GetPetById404;
|
|
10
|
-
request: never;
|
|
11
|
-
pathParams: GetPetByIdPathParams;
|
|
12
|
-
queryParams: never;
|
|
13
|
-
headerParams: never;
|
|
14
|
-
response: GetPetByIdQueryResponse;
|
|
15
|
-
client: {
|
|
16
|
-
parameters: Partial<Parameters<GetPetByIdClient>[0]>;
|
|
17
|
-
return: Awaited<ReturnType<GetPetByIdClient>>;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const getPetByIdQueryKey = ({ petId }: {
|
|
22
|
-
petId: GetPetByIdPathParams["petId"];
|
|
23
|
-
}) => [{ url: "/pet/:petId", params: { petId: petId } }] as const;
|
|
24
|
-
|
|
25
|
-
export type GetPetByIdQueryKey = ReturnType<typeof getPetByIdQueryKey>;
|
|
26
|
-
|
|
27
|
-
export function getPetByIdQueryOptions<TData = GetPetById["response"], TQueryData = GetPetById["response"]>({ petId }: {
|
|
28
|
-
petId: GetPetByIdPathParams["petId"];
|
|
29
|
-
}, options: GetPetById["client"]["parameters"] = {}): WithRequired<UseBaseQueryOptions<GetPetById["response"], GetPetById["error"], TData, TQueryData>, "queryKey"> {
|
|
30
|
-
const queryKey = getPetByIdQueryKey({ petId });
|
|
31
|
-
return {
|
|
32
|
-
queryKey,
|
|
33
|
-
queryFn: async () => {
|
|
34
|
-
const res = await client<GetPetById["data"], GetPetById["error"]>({
|
|
35
|
-
method: "get",
|
|
36
|
-
url: `/pet/${petId}`,
|
|
37
|
-
...options
|
|
38
|
-
});
|
|
39
|
-
return res.data;
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @description Returns a single pet
|
|
46
|
-
* @summary Find pet by ID
|
|
47
|
-
* @link /pet/:petId
|
|
48
|
-
*/
|
|
49
|
-
export function getPetById<TData = GetPetById["response"], TQueryData = GetPetById["response"], TQueryKey extends QueryKey = GetPetByIdQueryKey>({ petId }: {
|
|
50
|
-
petId: GetPetByIdPathParams["petId"];
|
|
51
|
-
}, options: {
|
|
52
|
-
query?: Partial<UseBaseQueryOptions<GetPetById["response"], GetPetById["error"], TData, TQueryData, TQueryKey>>;
|
|
53
|
-
client?: GetPetById["client"]["parameters"];
|
|
54
|
-
} = {}): UseQueryResult<TData, GetPetById["error"]> & {
|
|
55
|
-
queryKey: TQueryKey;
|
|
56
|
-
} {
|
|
57
|
-
const { query: queryOptions, client: clientOptions = {} } = options ?? {};
|
|
58
|
-
const queryKey = queryOptions?.queryKey ?? getPetByIdQueryKey({ petId });
|
|
59
|
-
const query = useQuery<GetPetById["data"], GetPetById["error"], TData, any>({
|
|
60
|
-
...getPetByIdQueryOptions<TData, TQueryData>({ petId }, clientOptions),
|
|
61
|
-
queryKey,
|
|
62
|
-
...queryOptions
|
|
63
|
-
}) as UseQueryResult<TData, GetPetById["error"]> & {
|
|
64
|
-
queryKey: TQueryKey;
|
|
65
|
-
};
|
|
66
|
-
query.queryKey = queryKey as TQueryKey;
|
|
67
|
-
return query;
|
|
68
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import client from "@kubb/plugin-client/client";
|
|
2
|
-
import type { UseBaseQueryOptions, QueryKey, WithRequired } from "@tanstack/react-query";
|
|
3
|
-
|
|
4
|
-
type GetPetByIdClient = typeof client<GetPetByIdQueryResponse, GetPetById400 | GetPetById404, never>;
|
|
5
|
-
|
|
6
|
-
type GetPetById = {
|
|
7
|
-
data: GetPetByIdQueryResponse;
|
|
8
|
-
error: GetPetById400 | GetPetById404;
|
|
9
|
-
request: never;
|
|
10
|
-
pathParams: GetPetByIdPathParams;
|
|
11
|
-
queryParams: never;
|
|
12
|
-
headerParams: never;
|
|
13
|
-
response: GetPetByIdQueryResponse;
|
|
14
|
-
client: {
|
|
15
|
-
parameters: Partial<Parameters<GetPetByIdClient>[0]>;
|
|
16
|
-
return: Awaited<ReturnType<GetPetByIdClient>>;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const getPetByIdQueryKey = ({ petId }: {
|
|
21
|
-
petId: GetPetByIdPathParams["petId"];
|
|
22
|
-
}) => [{ url: "/pet/:petId", params: { petId: petId } }] as const;
|
|
23
|
-
|
|
24
|
-
export type GetPetByIdQueryKey = ReturnType<typeof getPetByIdQueryKey>;
|
|
25
|
-
|
|
26
|
-
export function getPetByIdQueryOptions<TData = GetPetById["response"], TQueryData = GetPetById["response"]>({ petId }: {
|
|
27
|
-
petId: GetPetByIdPathParams["petId"];
|
|
28
|
-
}, options: GetPetById["client"]["parameters"] = {}): WithRequired<UseBaseQueryOptions<GetPetById["response"], GetPetById["error"], TData, TQueryData>, "queryKey"> {
|
|
29
|
-
const queryKey = getPetByIdQueryKey({ petId });
|
|
30
|
-
return {
|
|
31
|
-
queryKey,
|
|
32
|
-
queryFn: async () => {
|
|
33
|
-
const res = await client<GetPetById["data"], GetPetById["error"]>({
|
|
34
|
-
method: "get",
|
|
35
|
-
url: `/pet/${petId}`,
|
|
36
|
-
...options
|
|
37
|
-
});
|
|
38
|
-
return res.data;
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import client from "@kubb/plugin-client/client";
|
|
2
|
-
import type { UseBaseQueryOptions, UseQueryResult, QueryKey } from "@tanstack/react-query";
|
|
3
|
-
import { useQuery } from "@tanstack/react-query";
|
|
4
|
-
|
|
5
|
-
type GetPetByIdClient = typeof client<GetPetByIdQueryResponse, GetPetById400 | GetPetById404, never>;
|
|
6
|
-
|
|
7
|
-
type GetPetById = {
|
|
8
|
-
data: GetPetByIdQueryResponse;
|
|
9
|
-
error: GetPetById400 | GetPetById404;
|
|
10
|
-
request: never;
|
|
11
|
-
pathParams: GetPetByIdPathParams;
|
|
12
|
-
queryParams: never;
|
|
13
|
-
headerParams: never;
|
|
14
|
-
response: GetPetByIdQueryResponse;
|
|
15
|
-
client: {
|
|
16
|
-
parameters: Partial<Parameters<GetPetByIdClient>[0]>;
|
|
17
|
-
return: Awaited<ReturnType<GetPetByIdClient>>;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const getPetByIdQueryKey = ({ petId }: {
|
|
22
|
-
petId: GetPetByIdPathParams["petId"];
|
|
23
|
-
}) => [{ url: "/pet/:petId", params: { petId: petId } }] as const;
|
|
24
|
-
|
|
25
|
-
export type GetPetByIdQueryKey = ReturnType<typeof getPetByIdQueryKey>;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @description Returns a single pet
|
|
29
|
-
* @summary Find pet by ID
|
|
30
|
-
* @link /pet/:petId
|
|
31
|
-
*/
|
|
32
|
-
export function getPetById<TData = GetPetById["response"], TQueryData = GetPetById["response"], TQueryKey extends QueryKey = GetPetByIdQueryKey>({ petId }: {
|
|
33
|
-
petId: GetPetByIdPathParams["petId"];
|
|
34
|
-
}, options: {
|
|
35
|
-
query?: Partial<UseBaseQueryOptions<GetPetById["response"], GetPetById["error"], TData, TQueryData, TQueryKey>>;
|
|
36
|
-
client?: GetPetById["client"]["parameters"];
|
|
37
|
-
} = {}): UseQueryResult<TData, GetPetById["error"]> & {
|
|
38
|
-
queryKey: TQueryKey;
|
|
39
|
-
} {
|
|
40
|
-
const { query: queryOptions, client: clientOptions = {} } = options ?? {};
|
|
41
|
-
const queryKey = queryOptions?.queryKey ?? getPetByIdQueryKey({ petId });
|
|
42
|
-
const query = useQuery<GetPetById["data"], GetPetById["error"], TData, any>({
|
|
43
|
-
...getPetByIdQueryOptions<TData, TQueryData>({ petId }, clientOptions),
|
|
44
|
-
queryKey,
|
|
45
|
-
...queryOptions
|
|
46
|
-
}) as UseQueryResult<TData, GetPetById["error"]> & {
|
|
47
|
-
queryKey: TQueryKey;
|
|
48
|
-
};
|
|
49
|
-
query.queryKey = queryKey as TQueryKey;
|
|
50
|
-
return query;
|
|
51
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import client from "@kubb/plugin-client/client";
|
|
2
|
-
import type { QueryKey } from "@tanstack/react-query";
|
|
3
|
-
|
|
4
|
-
type DeletePetClient = typeof client<DeletePetMutationResponse, DeletePet400, never>;
|
|
5
|
-
|
|
6
|
-
type DeletePet = {
|
|
7
|
-
data: DeletePetMutationResponse;
|
|
8
|
-
error: DeletePet400;
|
|
9
|
-
request: never;
|
|
10
|
-
pathParams: DeletePetPathParams;
|
|
11
|
-
queryParams: never;
|
|
12
|
-
headerParams: DeletePetHeaderParams;
|
|
13
|
-
response: DeletePetMutationResponse;
|
|
14
|
-
client: {
|
|
15
|
-
parameters: Partial<Parameters<DeletePetClient>[0]>;
|
|
16
|
-
return: Awaited<ReturnType<DeletePetClient>>;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const deletePetQueryKey = ({ petId }: {
|
|
21
|
-
petId: DeletePetPathParams["petId"];
|
|
22
|
-
}) => [{ url: "/pet/:petId", params: { petId: petId } }] as const;
|
|
23
|
-
|
|
24
|
-
export type DeletePetQueryKey = ReturnType<typeof deletePetQueryKey>;
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { PackageManager } from '@kubb/core'
|
|
2
|
-
import { File } from '@kubb/react'
|
|
3
|
-
|
|
4
|
-
import { getImportNames, reactQueryDepRegex } from '../utils.ts'
|
|
5
|
-
|
|
6
|
-
import type { ReactNode } from 'react'
|
|
7
|
-
|
|
8
|
-
type TemplateProps = {
|
|
9
|
-
/**
|
|
10
|
-
* Path to @tanstack-query
|
|
11
|
-
*/
|
|
12
|
-
path: string
|
|
13
|
-
/**
|
|
14
|
-
* Override the path of 'useQuery'
|
|
15
|
-
* @default 'path'
|
|
16
|
-
*/
|
|
17
|
-
hookPath: string | undefined
|
|
18
|
-
optionsType: string
|
|
19
|
-
queryOptions: string | undefined
|
|
20
|
-
resultType: string
|
|
21
|
-
hookName: string
|
|
22
|
-
isInfinite: boolean
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function Template({ path, hookPath = path, isInfinite, hookName, queryOptions, optionsType, resultType }: TemplateProps): ReactNode {
|
|
26
|
-
return (
|
|
27
|
-
<>
|
|
28
|
-
<File.Import name={[optionsType, resultType]} path={path} isTypeOnly />
|
|
29
|
-
<File.Import name={[hookName]} path={hookPath} />
|
|
30
|
-
|
|
31
|
-
{queryOptions && <File.Import name={[queryOptions].filter(Boolean)} path={path} />}
|
|
32
|
-
<File.Import name={['QueryKey', 'WithRequired', isInfinite ? 'InfiniteData' : undefined].filter(Boolean)} path={path} isTypeOnly />
|
|
33
|
-
</>
|
|
34
|
-
)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
type FrameworkProps = Partial<TemplateProps> & {
|
|
38
|
-
context: {
|
|
39
|
-
isInfinite: boolean
|
|
40
|
-
isSuspense: boolean
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const defaultTemplates = {
|
|
45
|
-
get react() {
|
|
46
|
-
return function ({ context, hookPath, ...rest }: FrameworkProps): ReactNode {
|
|
47
|
-
const importNames = getImportNames()
|
|
48
|
-
const isV5 = new PackageManager().isValidSync(reactQueryDepRegex, '>=5')
|
|
49
|
-
const { isInfinite, isSuspense } = context
|
|
50
|
-
|
|
51
|
-
return (
|
|
52
|
-
<Template
|
|
53
|
-
isInfinite={isInfinite}
|
|
54
|
-
{...(isSuspense ? importNames.querySuspense.react : isInfinite ? importNames.queryInfinite.react : importNames.query.react)}
|
|
55
|
-
queryOptions={isV5 ? (isInfinite ? 'infiniteQueryOptions' : 'queryOptions') : undefined}
|
|
56
|
-
hookPath={hookPath}
|
|
57
|
-
{...rest}
|
|
58
|
-
/>
|
|
59
|
-
)
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
get solid() {
|
|
63
|
-
return function ({ context, hookPath, ...rest }: FrameworkProps): ReactNode {
|
|
64
|
-
const importNames = getImportNames()
|
|
65
|
-
const isV5 = new PackageManager().isValidSync(reactQueryDepRegex, '>=5')
|
|
66
|
-
const { isInfinite } = context
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<Template
|
|
70
|
-
isInfinite={isInfinite}
|
|
71
|
-
{...(isInfinite ? importNames.queryInfinite.solid : importNames.query.solid)}
|
|
72
|
-
queryOptions={isV5 ? (isInfinite ? 'infiniteQueryOptions' : 'queryOptions') : undefined}
|
|
73
|
-
hookPath={hookPath}
|
|
74
|
-
{...rest}
|
|
75
|
-
/>
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
get svelte() {
|
|
80
|
-
return function ({ context, hookPath, ...rest }: FrameworkProps): ReactNode {
|
|
81
|
-
const importNames = getImportNames()
|
|
82
|
-
const isV5 = new PackageManager().isValidSync(reactQueryDepRegex, '>=5')
|
|
83
|
-
const { isInfinite } = context
|
|
84
|
-
|
|
85
|
-
return (
|
|
86
|
-
<Template
|
|
87
|
-
isInfinite={isInfinite}
|
|
88
|
-
{...(isInfinite ? importNames.queryInfinite.svelte : importNames.query.svelte)}
|
|
89
|
-
queryOptions={isV5 ? (isInfinite ? 'infiniteQueryOptions' : 'queryOptions') : undefined}
|
|
90
|
-
hookPath={hookPath}
|
|
91
|
-
{...rest}
|
|
92
|
-
/>
|
|
93
|
-
)
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
get vue() {
|
|
97
|
-
return function ({ context, hookPath, ...rest }: FrameworkProps): ReactNode {
|
|
98
|
-
const importNames = getImportNames()
|
|
99
|
-
const isV5 = new PackageManager().isValidSync(reactQueryDepRegex, '>=5')
|
|
100
|
-
const { isInfinite } = context
|
|
101
|
-
const path = '@tanstack/vue-query'
|
|
102
|
-
|
|
103
|
-
return (
|
|
104
|
-
<>
|
|
105
|
-
{isV5 && (
|
|
106
|
-
<>
|
|
107
|
-
<Template
|
|
108
|
-
isInfinite={isInfinite}
|
|
109
|
-
{...(isInfinite ? importNames.queryInfinite.vue : importNames.query.vue)}
|
|
110
|
-
queryOptions={isInfinite ? 'infiniteQueryOptions' : 'queryOptions'}
|
|
111
|
-
hookPath={hookPath}
|
|
112
|
-
{...rest}
|
|
113
|
-
/>
|
|
114
|
-
<File.Import name={['QueryObserverOptions']} path={path} isTypeOnly />
|
|
115
|
-
</>
|
|
116
|
-
)}
|
|
117
|
-
|
|
118
|
-
{!isV5 && isInfinite && (
|
|
119
|
-
<>
|
|
120
|
-
<File.Import name={[importNames.queryInfinite.vue.resultType]} path={path} isTypeOnly />
|
|
121
|
-
<File.Import name={[importNames.queryInfinite.vue.optionsType]} path={'@tanstack/vue-query/build/lib/types'} isTypeOnly />
|
|
122
|
-
<File.Import name={[importNames.queryInfinite.vue.hookName]} path={path} />
|
|
123
|
-
</>
|
|
124
|
-
)}
|
|
125
|
-
|
|
126
|
-
{!isV5 && !isInfinite && (
|
|
127
|
-
<>
|
|
128
|
-
<File.Import name={[importNames.query.vue.resultType]} path={path} isTypeOnly />
|
|
129
|
-
<File.Import name={[importNames.query.vue.optionsType]} path={'@tanstack/vue-query/build/lib/types'} isTypeOnly />
|
|
130
|
-
<File.Import name={[importNames.query.vue.hookName]} path={path} />
|
|
131
|
-
</>
|
|
132
|
-
)}
|
|
133
|
-
<File.Import name={['unref']} path={'vue'} />
|
|
134
|
-
<File.Import name={['MaybeRef']} path={'vue'} isTypeOnly />
|
|
135
|
-
<File.Import name={['QueryKey', 'WithRequired']} path={path} isTypeOnly />
|
|
136
|
-
</>
|
|
137
|
-
)
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
} as const
|
|
141
|
-
|
|
142
|
-
type Props = {
|
|
143
|
-
hookPath: string | undefined
|
|
144
|
-
isInfinite: boolean
|
|
145
|
-
/**
|
|
146
|
-
* Only for React and v5
|
|
147
|
-
*/
|
|
148
|
-
isSuspense: boolean
|
|
149
|
-
/**
|
|
150
|
-
* This will make it possible to override the default behaviour.
|
|
151
|
-
*/
|
|
152
|
-
Template?: React.ComponentType<FrameworkProps>
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export function QueryImports({ hookPath, isInfinite, isSuspense, Template = defaultTemplates.react }: Props): ReactNode {
|
|
156
|
-
return (
|
|
157
|
-
<Template
|
|
158
|
-
hookPath={hookPath}
|
|
159
|
-
context={{
|
|
160
|
-
isInfinite,
|
|
161
|
-
isSuspense,
|
|
162
|
-
}}
|
|
163
|
-
/>
|
|
164
|
-
)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
QueryImports.templates = defaultTemplates
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
2
|
-
import { File, Type, useApp } from '@kubb/react'
|
|
3
|
-
|
|
4
|
-
import type { ReactNode } from 'react'
|
|
5
|
-
import type { PluginReactQuery } from '../types.ts'
|
|
6
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
7
|
-
|
|
8
|
-
export function SchemaType(): ReactNode {
|
|
9
|
-
const {
|
|
10
|
-
plugin: {
|
|
11
|
-
options: { dataReturnType },
|
|
12
|
-
},
|
|
13
|
-
} = useApp<PluginReactQuery>()
|
|
14
|
-
const { getSchemas, getName } = useOperationManager()
|
|
15
|
-
const operation = useOperation()
|
|
16
|
-
|
|
17
|
-
const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
|
|
18
|
-
|
|
19
|
-
const [TData, TError, TRequest, TPathParams, TQueryParams, THeaderParams, TResponse] = [
|
|
20
|
-
schemas.response.name,
|
|
21
|
-
schemas.errors?.map((item) => item.name).join(' | ') || 'never',
|
|
22
|
-
schemas.request?.name || 'never',
|
|
23
|
-
schemas.pathParams?.name || 'never',
|
|
24
|
-
schemas.queryParams?.name || 'never',
|
|
25
|
-
schemas.headerParams?.name || 'never',
|
|
26
|
-
schemas.response.name,
|
|
27
|
-
]
|
|
28
|
-
const factoryName = getName(operation, { type: 'type' })
|
|
29
|
-
|
|
30
|
-
const clientType = `${factoryName}Client`
|
|
31
|
-
const isFormData = operation.getContentType() === 'multipart/form-data'
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<>
|
|
35
|
-
<File.Source name={clientType} isTypeOnly>
|
|
36
|
-
<Type name={clientType}>{`typeof client<${TResponse}, ${TError}, ${isFormData ? 'FormData' : TRequest}>`}</Type>
|
|
37
|
-
</File.Source>
|
|
38
|
-
<File.Source name={factoryName} isTypeOnly>
|
|
39
|
-
<Type name={factoryName}>
|
|
40
|
-
{`
|
|
41
|
-
{
|
|
42
|
-
data: ${TData}
|
|
43
|
-
error: ${TError}
|
|
44
|
-
request: ${isFormData ? 'FormData' : TRequest}
|
|
45
|
-
pathParams: ${TPathParams}
|
|
46
|
-
queryParams: ${TQueryParams}
|
|
47
|
-
headerParams: ${THeaderParams}
|
|
48
|
-
response: ${dataReturnType === 'data' ? TData : `Awaited<ReturnType<${clientType}>>`}
|
|
49
|
-
client: {
|
|
50
|
-
parameters: Partial<Parameters<${clientType}>[0]>
|
|
51
|
-
return: Awaited<ReturnType<${clientType}>>
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
`}
|
|
55
|
-
</Type>
|
|
56
|
-
</File.Source>
|
|
57
|
-
</>
|
|
58
|
-
)
|
|
59
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
type GetPetsUuidClient = typeof client<GetPetsUuidQueryResponse, never, never>
|
|
2
|
-
|
|
3
|
-
type GetPetsUuid =
|
|
4
|
-
{
|
|
5
|
-
data: GetPetsUuidQueryResponse
|
|
6
|
-
error: never
|
|
7
|
-
request: never
|
|
8
|
-
pathParams: never
|
|
9
|
-
queryParams: never
|
|
10
|
-
headerParams: never
|
|
11
|
-
response: GetPetsUuidQueryResponse
|
|
12
|
-
client: {
|
|
13
|
-
parameters: Partial<Parameters<GetPetsUuidClient>[0]>
|
|
14
|
-
return: Awaited<ReturnType<GetPetsUuidClient>>
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const GetPetsUuidQueryKey = () => [{ url: '/pets/:uuid', params: {uuid:uuid} }] as const
|
|
19
|
-
|
|
20
|
-
export type GetPetsUuidQueryKey = ReturnType<typeof GetPetsUuidQueryKey>
|
|
21
|
-
|
|
22
|
-
export function GetPetsUuidQueryOptions<TData = GetPetsUuid["response"], TQueryData = GetPetsUuid["response"]>(options: GetPetsUuid['client']['parameters'] = {}): WithRequired<UseBaseQueryOptions<GetPetsUuid['response'], GetPetsUuid["error"], TData, TQueryData>, 'queryKey'> {
|
|
23
|
-
|
|
24
|
-
const queryKey = GetPetsUuidQueryKey()
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
queryKey,
|
|
28
|
-
queryFn: async () => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const res = await client<GetPetsUuid['data'],GetPetsUuid['error']>({
|
|
32
|
-
method: "get",
|
|
33
|
-
url: `/pets/${uuid}`,
|
|
34
|
-
...options
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
return res.data
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @link /pets/:uuid
|
|
47
|
-
*/
|
|
48
|
-
export function useGetPetsUuid<TData = GetPetsUuid["response"], TQueryData = GetPetsUuid["response"], TQueryKey extends QueryKey = GetPetsUuidQueryKey>(options: {
|
|
49
|
-
query?: Partial<UseBaseQueryOptions<GetPetsUuid['response'], GetPetsUuid['error'], TData, TQueryData, TQueryKey>>,
|
|
50
|
-
client?: GetPetsUuid['client']['parameters']
|
|
51
|
-
} = {}): UseQueryResult<TData, GetPetsUuid['error']> & { queryKey: TQueryKey } {
|
|
52
|
-
|
|
53
|
-
const { query: queryOptions, client: clientOptions = {} } = options ?? {}
|
|
54
|
-
const queryKey = queryOptions?.queryKey ?? GetPetsUuidQueryKey()
|
|
55
|
-
|
|
56
|
-
const query = useQuery<GetPetsUuid['data'], GetPetsUuid['error'], TData, any>({
|
|
57
|
-
...GetPetsUuidQueryOptions<TData, TQueryData>(clientOptions),
|
|
58
|
-
queryKey,
|
|
59
|
-
...queryOptions
|
|
60
|
-
}) as UseQueryResult<TData, GetPetsUuid['error']> & { queryKey: TQueryKey }
|
|
61
|
-
|
|
62
|
-
query.queryKey = queryKey as TQueryKey
|
|
63
|
-
|
|
64
|
-
return query
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
type CreatePetsClient = typeof client<CreatePetsMutationResponse, never, CreatePetsMutationRequest>
|
|
2
|
-
|
|
3
|
-
type CreatePets =
|
|
4
|
-
{
|
|
5
|
-
data: CreatePetsMutationResponse
|
|
6
|
-
error: never
|
|
7
|
-
request: CreatePetsMutationRequest
|
|
8
|
-
pathParams: CreatePetsPathParams
|
|
9
|
-
queryParams: CreatePetsQueryParams
|
|
10
|
-
headerParams: CreatePetsHeaderParams
|
|
11
|
-
response: CreatePetsMutationResponse
|
|
12
|
-
client: {
|
|
13
|
-
parameters: Partial<Parameters<CreatePetsClient>[0]>
|
|
14
|
-
return: Awaited<ReturnType<CreatePetsClient>>
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @summary Create a pet
|
|
20
|
-
* @link /pets/:uuid
|
|
21
|
-
*/
|
|
22
|
-
export function useCreatePets(uuid: CreatePetsPathParams["uuid"], headers: CreatePets['headerParams'], params?: CreatePets['queryParams'], options: {
|
|
23
|
-
mutation?: UseMutationOptions<CreatePets["response"], CreatePets["error"], CreatePets["request"]>,
|
|
24
|
-
client?: CreatePets['client']['parameters']
|
|
25
|
-
} = {}) {
|
|
26
|
-
|
|
27
|
-
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
|
|
28
|
-
|
|
29
|
-
return useMutation({
|
|
30
|
-
mutationFn: async(data) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const res = await client<CreatePets["data"], CreatePets["error"], CreatePets["request"]>({
|
|
34
|
-
method: "post",
|
|
35
|
-
url: `/pets/${uuid}`,
|
|
36
|
-
params,
|
|
37
|
-
data,
|
|
38
|
-
headers: { ...headers, ...clientOptions.headers },
|
|
39
|
-
...clientOptions
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
return res.data
|
|
43
|
-
},
|
|
44
|
-
...mutationOptions
|
|
45
|
-
})
|
|
46
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
type CreatePetsClient = typeof client<CreatePetsMutationResponse, never, CreatePetsMutationRequest>
|
|
2
|
-
|
|
3
|
-
type CreatePets =
|
|
4
|
-
{
|
|
5
|
-
data: CreatePetsMutationResponse
|
|
6
|
-
error: never
|
|
7
|
-
request: CreatePetsMutationRequest
|
|
8
|
-
pathParams: CreatePetsPathParams
|
|
9
|
-
queryParams: CreatePetsQueryParams
|
|
10
|
-
headerParams: CreatePetsHeaderParams
|
|
11
|
-
response: CreatePetsMutationResponse
|
|
12
|
-
client: {
|
|
13
|
-
parameters: Partial<Parameters<CreatePetsClient>[0]>
|
|
14
|
-
return: Awaited<ReturnType<CreatePetsClient>>
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @summary Create a pet
|
|
20
|
-
* @link /pets/:uuid
|
|
21
|
-
*/
|
|
22
|
-
export function useCreatePets(options: {
|
|
23
|
-
mutation?: UseMutationOptions<CreatePets["response"], CreatePets["error"], { uuid: CreatePetsPathParams["uuid"]; params?: CreatePets['queryParams']; headers: CreatePets['headerParams']; data: CreatePets['request'] }>,
|
|
24
|
-
client?: CreatePets['client']['parameters']
|
|
25
|
-
} = {}) {
|
|
26
|
-
|
|
27
|
-
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
|
|
28
|
-
|
|
29
|
-
return useMutation({
|
|
30
|
-
mutationFn: async({ uuid, headers, data, params }) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const res = await client<CreatePets["data"], CreatePets["error"], CreatePets["request"]>({
|
|
34
|
-
method: "post",
|
|
35
|
-
url: `/pets/${uuid}`,
|
|
36
|
-
params,
|
|
37
|
-
data,
|
|
38
|
-
headers: { ...headers, ...clientOptions.headers },
|
|
39
|
-
...clientOptions
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
return res.data
|
|
43
|
-
},
|
|
44
|
-
...mutationOptions
|
|
45
|
-
})
|
|
46
|
-
}
|