@kubb/plugin-react-query 3.0.0-alpha.2 → 3.0.0-alpha.21
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 +13 -4
- package/dist/chunk-ESENIDWJ.js +608 -0
- package/dist/chunk-ESENIDWJ.js.map +1 -0
- package/dist/chunk-HAC4WPCC.js +608 -0
- package/dist/chunk-HAC4WPCC.js.map +1 -0
- package/dist/chunk-JQEH3UHY.cjs +618 -0
- package/dist/chunk-JQEH3UHY.cjs.map +1 -0
- package/dist/chunk-JYBGTT23.cjs +618 -0
- package/dist/chunk-JYBGTT23.cjs.map +1 -0
- package/dist/components.cjs +35 -14
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +143 -7
- package/dist/components.d.ts +143 -7
- package/dist/components.js +2 -14
- 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 +77 -154
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -5
- package/dist/index.d.ts +1 -5
- package/dist/index.js +56 -140
- package/dist/index.js.map +1 -1
- package/dist/types-DFHc63S9.d.cts +179 -0
- package/dist/types-DFHc63S9.d.ts +179 -0
- package/package.json +22 -17
- package/src/components/InfiniteQuery.tsx +129 -0
- package/src/components/InfiniteQueryOptions.tsx +121 -0
- package/src/components/Mutation.tsx +113 -321
- package/src/components/Query.tsx +91 -598
- package/src/components/QueryKey.tsx +51 -178
- package/src/components/QueryOptions.tsx +65 -468
- package/src/components/SuspenseQuery.tsx +129 -0
- package/src/components/index.ts +3 -1
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +50 -0
- package/src/generators/__snapshots__/clientGetImportPath.ts +50 -0
- package/src/generators/__snapshots__/clientPostImportPath.ts +38 -0
- package/src/generators/__snapshots__/findByTags.ts +50 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +50 -0
- package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +50 -0
- package/src/generators/__snapshots__/findByTagsWithZod.ts +50 -0
- package/src/generators/__snapshots__/findInfiniteByTags.ts +56 -0
- package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +56 -0
- package/src/generators/__snapshots__/getAsMutation.ts +31 -0
- package/src/generators/__snapshots__/postAsQuery.ts +48 -0
- package/src/generators/__snapshots__/updatePetById.ts +38 -0
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +40 -0
- package/src/generators/index.ts +4 -0
- package/src/generators/infiniteQueryGenerator.tsx +125 -0
- package/src/generators/mutationGenerator.tsx +96 -0
- package/src/generators/queryGenerator.tsx +122 -0
- package/src/generators/suspenseQueryGenerator.tsx +121 -0
- package/src/plugin.ts +51 -73
- package/src/types.ts +43 -91
- package/dist/chunk-5IL6M74X.js +0 -1504
- package/dist/chunk-5IL6M74X.js.map +0 -1
- package/dist/chunk-JFX7DCS7.cjs +0 -1504
- package/dist/chunk-JFX7DCS7.cjs.map +0 -1
- package/dist/index-C9fwRDH7.d.cts +0 -579
- package/dist/index-C9fwRDH7.d.ts +0 -579
- package/src/OperationGenerator.tsx +0 -86
- package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -64
- package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -57
- package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -63
- package/src/__snapshots__/queryOptions/getPetById.ts +0 -37
- package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -47
- package/src/__snapshots__/upload/UploadFile.ts +0 -67
- package/src/__snapshots__/uploadMutation/UploadFile.ts +0 -44
- package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -21
- package/src/components/Operations.tsx +0 -74
- package/src/components/QueryImports.tsx +0 -167
- package/src/components/SchemaType.tsx +0 -55
- package/src/components/__snapshots__/gen/showPetById.ts +0 -57
- package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
- package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -47
- package/src/utils.ts +0 -96
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import client from "@kubb/plugin-client/client";
|
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
|
3
|
-
import type { UseBaseQueryOptions, UseQueryResult, QueryKey, WithRequired } from "@tanstack/react-query";
|
|
4
|
-
|
|
5
|
-
type UpdatePetWithFormClient = typeof client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationRequest>;
|
|
6
|
-
type UpdatePetWithForm = {
|
|
7
|
-
data: UpdatePetWithFormMutationResponse;
|
|
8
|
-
error: UpdatePetWithForm405;
|
|
9
|
-
request: UpdatePetWithFormMutationRequest;
|
|
10
|
-
pathParams: UpdatePetWithFormPathParams;
|
|
11
|
-
queryParams: UpdatePetWithFormQueryParams;
|
|
12
|
-
headerParams: never;
|
|
13
|
-
response: UpdatePetWithFormMutationResponse;
|
|
14
|
-
client: {
|
|
15
|
-
parameters: Partial<Parameters<UpdatePetWithFormClient>[0]>;
|
|
16
|
-
return: Awaited<ReturnType<UpdatePetWithFormClient>>;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export const UpdatePetWithFormQueryKey = ({ petId }: {
|
|
20
|
-
petId: UpdatePetWithFormPathParams["petId"];
|
|
21
|
-
}, params?: UpdatePetWithForm["queryParams"], data?: UpdatePetWithForm["request"]) => [{ url: "/pet/:petId", params: { petId: petId } }, ...(params ? [params] : []), ...(data ? [data] : [])] as const;
|
|
22
|
-
export type UpdatePetWithFormQueryKey = ReturnType<typeof UpdatePetWithFormQueryKey>;
|
|
23
|
-
export function UpdatePetWithFormQueryOptions<TData = UpdatePetWithForm["response"], TQueryData = UpdatePetWithForm["response"]>({ petId }: {
|
|
24
|
-
petId: UpdatePetWithFormPathParams["petId"];
|
|
25
|
-
}, params?: UpdatePetWithForm["queryParams"], data?: UpdatePetWithForm["request"], options: UpdatePetWithForm["client"]["parameters"] = {}): WithRequired<UseBaseQueryOptions<UpdatePetWithForm["response"], UpdatePetWithForm["error"], TData, TQueryData>, "queryKey"> {
|
|
26
|
-
const queryKey = UpdatePetWithFormQueryKey({ petId }, params, data);
|
|
27
|
-
return {
|
|
28
|
-
queryKey,
|
|
29
|
-
queryFn: async () => {
|
|
30
|
-
const res = await client<UpdatePetWithForm["data"], UpdatePetWithForm["error"]>({
|
|
31
|
-
method: "post",
|
|
32
|
-
url: `/pet/${petId}`,
|
|
33
|
-
params,
|
|
34
|
-
data,
|
|
35
|
-
...options
|
|
36
|
-
});
|
|
37
|
-
return res.data;
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* @summary Updates a pet in the store with form data
|
|
43
|
-
* @link /pet/:petId
|
|
44
|
-
*/
|
|
45
|
-
export function updatePetWithForm<TData = UpdatePetWithForm["response"], TQueryData = UpdatePetWithForm["response"], TQueryKey extends QueryKey = UpdatePetWithFormQueryKey>({ petId }: {
|
|
46
|
-
petId: UpdatePetWithFormPathParams["petId"];
|
|
47
|
-
}, params?: UpdatePetWithForm["queryParams"], data?: UpdatePetWithForm["request"], options: {
|
|
48
|
-
query?: Partial<UseBaseQueryOptions<UpdatePetWithForm["response"], UpdatePetWithForm["error"], TData, TQueryData, TQueryKey>>;
|
|
49
|
-
client?: UpdatePetWithForm["client"]["parameters"];
|
|
50
|
-
} = {}): UseQueryResult<TData, UpdatePetWithForm["error"]> & {
|
|
51
|
-
queryKey: TQueryKey;
|
|
52
|
-
} {
|
|
53
|
-
const { query: queryOptions, client: clientOptions = {} } = options ?? {};
|
|
54
|
-
const queryKey = queryOptions?.queryKey ?? UpdatePetWithFormQueryKey({ petId }, params, data);
|
|
55
|
-
const query = useQuery<UpdatePetWithForm["data"], UpdatePetWithForm["error"], TData, any>({
|
|
56
|
-
...UpdatePetWithFormQueryOptions<TData, TQueryData>({ petId }, params, data, clientOptions),
|
|
57
|
-
queryKey,
|
|
58
|
-
...queryOptions
|
|
59
|
-
}) as UseQueryResult<TData, UpdatePetWithForm["error"]> & {
|
|
60
|
-
queryKey: TQueryKey;
|
|
61
|
-
};
|
|
62
|
-
query.queryKey = queryKey as TQueryKey;
|
|
63
|
-
return query;
|
|
64
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import client from "@kubb/plugin-client/client";
|
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
|
3
|
-
import type { UseBaseQueryOptions, UseQueryResult, QueryKey, WithRequired } from "@tanstack/react-query";
|
|
4
|
-
|
|
5
|
-
type GetPetByIdClient = typeof client<GetPetByIdQueryResponse, GetPetById400 | GetPetById404, never>;
|
|
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
|
-
export const GetPetByIdQueryKey = (petId: GetPetByIdPathParams["petId"]) => [{ url: "/pet/:petId", params: { petId: petId } }] as const;
|
|
20
|
-
export type GetPetByIdQueryKey = ReturnType<typeof GetPetByIdQueryKey>;
|
|
21
|
-
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"> {
|
|
22
|
-
const queryKey = GetPetByIdQueryKey(petId);
|
|
23
|
-
return {
|
|
24
|
-
queryKey,
|
|
25
|
-
queryFn: async () => {
|
|
26
|
-
const res = await client<GetPetById["data"], GetPetById["error"]>({
|
|
27
|
-
method: "get",
|
|
28
|
-
url: `/pet/${petId}`,
|
|
29
|
-
...options
|
|
30
|
-
});
|
|
31
|
-
return res.data;
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* @description Returns a single pet
|
|
37
|
-
* @summary Find pet by ID
|
|
38
|
-
* @link /pet/:petId
|
|
39
|
-
*/
|
|
40
|
-
export function getPetById<TData = GetPetById["response"], TQueryData = GetPetById["response"], TQueryKey extends QueryKey = GetPetByIdQueryKey>(petId: GetPetByIdPathParams["petId"], options: {
|
|
41
|
-
query?: Partial<UseBaseQueryOptions<GetPetById["response"], GetPetById["error"], TData, TQueryData, TQueryKey>>;
|
|
42
|
-
client?: GetPetById["client"]["parameters"];
|
|
43
|
-
} = {}): UseQueryResult<TData, GetPetById["error"]> & {
|
|
44
|
-
queryKey: TQueryKey;
|
|
45
|
-
} {
|
|
46
|
-
const { query: queryOptions, client: clientOptions = {} } = options ?? {};
|
|
47
|
-
const queryKey = queryOptions?.queryKey ?? GetPetByIdQueryKey(petId);
|
|
48
|
-
const query = useQuery<GetPetById["data"], GetPetById["error"], TData, any>({
|
|
49
|
-
...GetPetByIdQueryOptions<TData, TQueryData>(petId, clientOptions),
|
|
50
|
-
queryKey,
|
|
51
|
-
...queryOptions
|
|
52
|
-
}) as UseQueryResult<TData, GetPetById["error"]> & {
|
|
53
|
-
queryKey: TQueryKey;
|
|
54
|
-
};
|
|
55
|
-
query.queryKey = queryKey as TQueryKey;
|
|
56
|
-
return query;
|
|
57
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import client from "@kubb/plugin-client/client";
|
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
|
3
|
-
import type { UseBaseQueryOptions, UseQueryResult, QueryKey, WithRequired } from "@tanstack/react-query";
|
|
4
|
-
|
|
5
|
-
type GetPetByIdClient = typeof client<GetPetByIdQueryResponse, GetPetById400 | GetPetById404, never>;
|
|
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
|
-
export const GetPetByIdQueryKey = ({ petId }: {
|
|
20
|
-
petId: GetPetByIdPathParams["petId"];
|
|
21
|
-
}) => [{ url: "/pet/:petId", params: { petId: petId } }] as const;
|
|
22
|
-
export type GetPetByIdQueryKey = ReturnType<typeof GetPetByIdQueryKey>;
|
|
23
|
-
export function GetPetByIdQueryOptions<TData = GetPetById["response"], TQueryData = GetPetById["response"]>({ petId }: {
|
|
24
|
-
petId: GetPetByIdPathParams["petId"];
|
|
25
|
-
}, 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
|
-
* @description Returns a single pet
|
|
41
|
-
* @summary Find pet by ID
|
|
42
|
-
* @link /pet/:petId
|
|
43
|
-
*/
|
|
44
|
-
export function getPetById<TData = GetPetById["response"], TQueryData = GetPetById["response"], TQueryKey extends QueryKey = GetPetByIdQueryKey>({ petId }: {
|
|
45
|
-
petId: GetPetByIdPathParams["petId"];
|
|
46
|
-
}, options: {
|
|
47
|
-
query?: Partial<UseBaseQueryOptions<GetPetById["response"], GetPetById["error"], TData, TQueryData, TQueryKey>>;
|
|
48
|
-
client?: GetPetById["client"]["parameters"];
|
|
49
|
-
} = {}): UseQueryResult<TData, GetPetById["error"]> & {
|
|
50
|
-
queryKey: TQueryKey;
|
|
51
|
-
} {
|
|
52
|
-
const { query: queryOptions, client: clientOptions = {} } = options ?? {};
|
|
53
|
-
const queryKey = queryOptions?.queryKey ?? GetPetByIdQueryKey({ petId });
|
|
54
|
-
const query = useQuery<GetPetById["data"], GetPetById["error"], TData, any>({
|
|
55
|
-
...GetPetByIdQueryOptions<TData, TQueryData>({ petId }, clientOptions),
|
|
56
|
-
queryKey,
|
|
57
|
-
...queryOptions
|
|
58
|
-
}) as UseQueryResult<TData, GetPetById["error"]> & {
|
|
59
|
-
queryKey: TQueryKey;
|
|
60
|
-
};
|
|
61
|
-
query.queryKey = queryKey as TQueryKey;
|
|
62
|
-
return query;
|
|
63
|
-
}
|
|
@@ -1,37 +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
|
-
type GetPetById = {
|
|
6
|
-
data: GetPetByIdQueryResponse;
|
|
7
|
-
error: GetPetById400 | GetPetById404;
|
|
8
|
-
request: never;
|
|
9
|
-
pathParams: GetPetByIdPathParams;
|
|
10
|
-
queryParams: never;
|
|
11
|
-
headerParams: never;
|
|
12
|
-
response: GetPetByIdQueryResponse;
|
|
13
|
-
client: {
|
|
14
|
-
parameters: Partial<Parameters<GetPetByIdClient>[0]>;
|
|
15
|
-
return: Awaited<ReturnType<GetPetByIdClient>>;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export const GetPetByIdQueryKey = ({ petId }: {
|
|
19
|
-
petId: GetPetByIdPathParams["petId"];
|
|
20
|
-
}) => [{ url: "/pet/:petId", params: { petId: petId } }] as const;
|
|
21
|
-
export type GetPetByIdQueryKey = ReturnType<typeof GetPetByIdQueryKey>;
|
|
22
|
-
export function GetPetByIdQueryOptions<TData = GetPetById["response"], TQueryData = GetPetById["response"]>({ petId }: {
|
|
23
|
-
petId: GetPetByIdPathParams["petId"];
|
|
24
|
-
}, options: GetPetById["client"]["parameters"] = {}): WithRequired<UseBaseQueryOptions<GetPetById["response"], GetPetById["error"], TData, TQueryData>, "queryKey"> {
|
|
25
|
-
const queryKey = GetPetByIdQueryKey({ petId });
|
|
26
|
-
return {
|
|
27
|
-
queryKey,
|
|
28
|
-
queryFn: async () => {
|
|
29
|
-
const res = await client<GetPetById["data"], GetPetById["error"]>({
|
|
30
|
-
method: "get",
|
|
31
|
-
url: `/pet/${petId}`,
|
|
32
|
-
...options
|
|
33
|
-
});
|
|
34
|
-
return res.data;
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import client from "@kubb/plugin-client/client";
|
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
|
3
|
-
import type { UseBaseQueryOptions, UseQueryResult, QueryKey } from "@tanstack/react-query";
|
|
4
|
-
|
|
5
|
-
type GetPetByIdClient = typeof client<GetPetByIdQueryResponse, GetPetById400 | GetPetById404, never>;
|
|
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
|
-
export const GetPetByIdQueryKey = ({ petId }: {
|
|
20
|
-
petId: GetPetByIdPathParams["petId"];
|
|
21
|
-
}) => [{ url: "/pet/:petId", params: { petId: petId } }] as const;
|
|
22
|
-
export type GetPetByIdQueryKey = ReturnType<typeof GetPetByIdQueryKey>;
|
|
23
|
-
/**
|
|
24
|
-
* @description Returns a single pet
|
|
25
|
-
* @summary Find pet by ID
|
|
26
|
-
* @link /pet/:petId
|
|
27
|
-
*/
|
|
28
|
-
export function getPetById<TData = GetPetById["response"], TQueryData = GetPetById["response"], TQueryKey extends QueryKey = GetPetByIdQueryKey>({ petId }: {
|
|
29
|
-
petId: GetPetByIdPathParams["petId"];
|
|
30
|
-
}, options: {
|
|
31
|
-
query?: Partial<UseBaseQueryOptions<GetPetById["response"], GetPetById["error"], TData, TQueryData, TQueryKey>>;
|
|
32
|
-
client?: GetPetById["client"]["parameters"];
|
|
33
|
-
} = {}): UseQueryResult<TData, GetPetById["error"]> & {
|
|
34
|
-
queryKey: TQueryKey;
|
|
35
|
-
} {
|
|
36
|
-
const { query: queryOptions, client: clientOptions = {} } = options ?? {};
|
|
37
|
-
const queryKey = queryOptions?.queryKey ?? GetPetByIdQueryKey({ petId });
|
|
38
|
-
const query = useQuery<GetPetById["data"], GetPetById["error"], TData, any>({
|
|
39
|
-
...GetPetByIdQueryOptions<TData, TQueryData>({ petId }, clientOptions),
|
|
40
|
-
queryKey,
|
|
41
|
-
...queryOptions
|
|
42
|
-
}) as UseQueryResult<TData, GetPetById["error"]> & {
|
|
43
|
-
queryKey: TQueryKey;
|
|
44
|
-
};
|
|
45
|
-
query.queryKey = queryKey as TQueryKey;
|
|
46
|
-
return query;
|
|
47
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import client from "@kubb/plugin-client/client";
|
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
|
3
|
-
import type { UseBaseQueryOptions, UseQueryResult, QueryKey, WithRequired } from "@tanstack/react-query";
|
|
4
|
-
|
|
5
|
-
type UploadFileClient = typeof client<UploadFileMutationResponse, UploadFile400, FormData>;
|
|
6
|
-
type UploadFile = {
|
|
7
|
-
data: UploadFileMutationResponse;
|
|
8
|
-
error: UploadFile400;
|
|
9
|
-
request: FormData;
|
|
10
|
-
pathParams: never;
|
|
11
|
-
queryParams: never;
|
|
12
|
-
headerParams: never;
|
|
13
|
-
response: UploadFileMutationResponse;
|
|
14
|
-
client: {
|
|
15
|
-
parameters: Partial<Parameters<UploadFileClient>[0]>;
|
|
16
|
-
return: Awaited<ReturnType<UploadFileClient>>;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export const UploadFileQueryKey = (data: UploadFile["request"]) => [{ url: "/upload" }, ...(data ? [data] : [])] as const;
|
|
20
|
-
export type UploadFileQueryKey = ReturnType<typeof UploadFileQueryKey>;
|
|
21
|
-
export function UploadFileQueryOptions<TData = UploadFile["response"], TQueryData = UploadFile["response"]>(data: UploadFile["request"], options: UploadFile["client"]["parameters"] = {}): WithRequired<UseBaseQueryOptions<UploadFile["response"], UploadFile["error"], TData, TQueryData>, "queryKey"> {
|
|
22
|
-
const queryKey = UploadFileQueryKey(data);
|
|
23
|
-
return {
|
|
24
|
-
queryKey,
|
|
25
|
-
queryFn: async () => {
|
|
26
|
-
const formData = new FormData();
|
|
27
|
-
if (data) {
|
|
28
|
-
Object.keys(data).forEach((key) => {
|
|
29
|
-
const value = data[key];
|
|
30
|
-
if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
|
|
31
|
-
formData.append(key, value);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
const res = await client<UploadFile["data"], UploadFile["error"]>({
|
|
36
|
-
method: "post",
|
|
37
|
-
url: `/upload`,
|
|
38
|
-
data: formData,
|
|
39
|
-
headers: { "Content-Type": "multipart/form-data", ...options.headers },
|
|
40
|
-
...options
|
|
41
|
-
});
|
|
42
|
-
return res.data;
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* @description Upload file
|
|
48
|
-
* @link /upload
|
|
49
|
-
*/
|
|
50
|
-
export function UploadFile<TData = UploadFile["response"], TQueryData = UploadFile["response"], TQueryKey extends QueryKey = UploadFileQueryKey>(data: UploadFile["request"], options: {
|
|
51
|
-
query?: Partial<UseBaseQueryOptions<UploadFile["response"], UploadFile["error"], TData, TQueryData, TQueryKey>>;
|
|
52
|
-
client?: UploadFile["client"]["parameters"];
|
|
53
|
-
} = {}): UseQueryResult<TData, UploadFile["error"]> & {
|
|
54
|
-
queryKey: TQueryKey;
|
|
55
|
-
} {
|
|
56
|
-
const { query: queryOptions, client: clientOptions = {} } = options ?? {};
|
|
57
|
-
const queryKey = queryOptions?.queryKey ?? UploadFileQueryKey(data);
|
|
58
|
-
const query = useQuery<UploadFile["data"], UploadFile["error"], TData, any>({
|
|
59
|
-
...UploadFileQueryOptions<TData, TQueryData>(data, clientOptions),
|
|
60
|
-
queryKey,
|
|
61
|
-
...queryOptions
|
|
62
|
-
}) as UseQueryResult<TData, UploadFile["error"]> & {
|
|
63
|
-
queryKey: TQueryKey;
|
|
64
|
-
};
|
|
65
|
-
query.queryKey = queryKey as TQueryKey;
|
|
66
|
-
return query;
|
|
67
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import client from "@kubb/plugin-client/client";
|
|
2
|
-
import type { UseBaseQueryOptions, QueryKey, WithRequired } from "@tanstack/react-query";
|
|
3
|
-
|
|
4
|
-
type UploadFileClient = typeof client<UploadFileMutationResponse, UploadFile400, FormData>;
|
|
5
|
-
type UploadFile = {
|
|
6
|
-
data: UploadFileMutationResponse;
|
|
7
|
-
error: UploadFile400;
|
|
8
|
-
request: FormData;
|
|
9
|
-
pathParams: never;
|
|
10
|
-
queryParams: never;
|
|
11
|
-
headerParams: never;
|
|
12
|
-
response: UploadFileMutationResponse;
|
|
13
|
-
client: {
|
|
14
|
-
parameters: Partial<Parameters<UploadFileClient>[0]>;
|
|
15
|
-
return: Awaited<ReturnType<UploadFileClient>>;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export const UploadFileQueryKey = (data: UploadFile["request"]) => [{ url: "/upload" }, ...(data ? [data] : [])] as const;
|
|
19
|
-
export type UploadFileQueryKey = ReturnType<typeof UploadFileQueryKey>;
|
|
20
|
-
export function UploadFileQueryOptions<TData = UploadFile["response"], TQueryData = UploadFile["response"]>(data: UploadFile["request"], options: UploadFile["client"]["parameters"] = {}): WithRequired<UseBaseQueryOptions<UploadFile["response"], UploadFile["error"], TData, TQueryData>, "queryKey"> {
|
|
21
|
-
const queryKey = UploadFileQueryKey(data);
|
|
22
|
-
return {
|
|
23
|
-
queryKey,
|
|
24
|
-
queryFn: async () => {
|
|
25
|
-
const formData = new FormData();
|
|
26
|
-
if (data) {
|
|
27
|
-
Object.keys(data).forEach((key) => {
|
|
28
|
-
const value = data[key];
|
|
29
|
-
if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
|
|
30
|
-
formData.append(key, value);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
const res = await client<UploadFile["data"], UploadFile["error"]>({
|
|
35
|
-
method: "post",
|
|
36
|
-
url: `/upload`,
|
|
37
|
-
data: formData,
|
|
38
|
-
headers: { "Content-Type": "multipart/form-data", ...options.headers },
|
|
39
|
-
...options
|
|
40
|
-
});
|
|
41
|
-
return res.data;
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|
|
@@ -1,21 +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
|
-
type DeletePet = {
|
|
6
|
-
data: DeletePetMutationResponse;
|
|
7
|
-
error: DeletePet400;
|
|
8
|
-
request: never;
|
|
9
|
-
pathParams: DeletePetPathParams;
|
|
10
|
-
queryParams: never;
|
|
11
|
-
headerParams: DeletePetHeaderParams;
|
|
12
|
-
response: DeletePetMutationResponse;
|
|
13
|
-
client: {
|
|
14
|
-
parameters: Partial<Parameters<DeletePetClient>[0]>;
|
|
15
|
-
return: Awaited<ReturnType<DeletePetClient>>;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export const DeletePetQueryKey = ({ petId }: {
|
|
19
|
-
petId: DeletePetPathParams["petId"];
|
|
20
|
-
}) => [{ url: "/pet/:petId", params: { petId: petId } }] as const;
|
|
21
|
-
export type DeletePetQueryKey = ReturnType<typeof DeletePetQueryKey>;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { Parser, File, useApp } from '@kubb/react'
|
|
2
|
-
|
|
3
|
-
import type { KubbNode } from '@kubb/react'
|
|
4
|
-
import type { ComponentProps, ComponentType } from 'react'
|
|
5
|
-
import type { FileMeta, PluginReactQuery } from '../types.ts'
|
|
6
|
-
|
|
7
|
-
type TemplateProps = {}
|
|
8
|
-
|
|
9
|
-
function Template({}: TemplateProps): KubbNode {
|
|
10
|
-
return null
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type RootTemplateProps = {
|
|
14
|
-
children?: React.ReactNode
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function RootTemplate({ children }: RootTemplateProps) {
|
|
18
|
-
const {
|
|
19
|
-
pluginManager,
|
|
20
|
-
plugin: { key: pluginKey },
|
|
21
|
-
} = useApp<PluginReactQuery>()
|
|
22
|
-
|
|
23
|
-
const file = pluginManager.getFile({
|
|
24
|
-
name: 'operations',
|
|
25
|
-
mode: 'split',
|
|
26
|
-
extName: '.ts',
|
|
27
|
-
pluginKey,
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<Parser language="typescript">
|
|
32
|
-
<File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
33
|
-
<File.Source>{children}</File.Source>
|
|
34
|
-
</File>
|
|
35
|
-
</Parser>
|
|
36
|
-
)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const defaultTemplates = { default: Template, root: RootTemplate } as const
|
|
40
|
-
|
|
41
|
-
type Templates = Partial<typeof defaultTemplates>
|
|
42
|
-
|
|
43
|
-
type Props = {
|
|
44
|
-
/**
|
|
45
|
-
* This will make it possible to override the default behaviour.
|
|
46
|
-
*/
|
|
47
|
-
Template?: ComponentType<ComponentProps<typeof Template>>
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function Operations({ Template = defaultTemplates.default }: Props): KubbNode {
|
|
51
|
-
return <Template />
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
type FileProps = {
|
|
55
|
-
/**
|
|
56
|
-
* This will make it possible to override the default behaviour.
|
|
57
|
-
*/
|
|
58
|
-
templates?: Templates
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
Operations.File = function (props: FileProps): KubbNode {
|
|
62
|
-
const templates = { ...defaultTemplates, ...props.templates }
|
|
63
|
-
|
|
64
|
-
const Template = templates.default
|
|
65
|
-
const RootTemplate = templates.root
|
|
66
|
-
|
|
67
|
-
return (
|
|
68
|
-
<RootTemplate>
|
|
69
|
-
<Operations Template={Template} />
|
|
70
|
-
</RootTemplate>
|
|
71
|
-
)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
Operations.templates = defaultTemplates
|
|
@@ -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
|