@kubb/plugin-react-query 3.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +114 -0
  3. package/dist/chunk-5IL6M74X.js +1504 -0
  4. package/dist/chunk-5IL6M74X.js.map +1 -0
  5. package/dist/chunk-JFX7DCS7.cjs +1504 -0
  6. package/dist/chunk-JFX7DCS7.cjs.map +1 -0
  7. package/dist/components.cjs +15 -0
  8. package/dist/components.cjs.map +1 -0
  9. package/dist/components.d.cts +8 -0
  10. package/dist/components.d.ts +8 -0
  11. package/dist/components.js +15 -0
  12. package/dist/components.js.map +1 -0
  13. package/dist/index-yXskx3Td.d.cts +584 -0
  14. package/dist/index-yXskx3Td.d.ts +584 -0
  15. package/dist/index.cjs +223 -0
  16. package/dist/index.cjs.map +1 -0
  17. package/dist/index.d.cts +13 -0
  18. package/dist/index.d.ts +13 -0
  19. package/dist/index.js +223 -0
  20. package/dist/index.js.map +1 -0
  21. package/package.json +97 -0
  22. package/src/OperationGenerator.tsx +86 -0
  23. package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +64 -0
  24. package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +57 -0
  25. package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +63 -0
  26. package/src/__snapshots__/queryOptions/getPetById.ts +37 -0
  27. package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +47 -0
  28. package/src/__snapshots__/upload/UploadFile.ts +67 -0
  29. package/src/__snapshots__/uploadMutation/UploadFile.ts +44 -0
  30. package/src/__snapshots__/variablesTypeMutate/deletePet.ts +21 -0
  31. package/src/components/Mutation.tsx +341 -0
  32. package/src/components/Operations.tsx +74 -0
  33. package/src/components/Query.tsx +627 -0
  34. package/src/components/QueryImports.tsx +167 -0
  35. package/src/components/QueryKey.tsx +200 -0
  36. package/src/components/QueryOptions.tsx +487 -0
  37. package/src/components/SchemaType.tsx +55 -0
  38. package/src/components/__snapshots__/gen/showPetById.ts +57 -0
  39. package/src/components/__snapshots__/gen/useCreatePets.ts +46 -0
  40. package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +47 -0
  41. package/src/components/index.ts +5 -0
  42. package/src/index.ts +2 -0
  43. package/src/plugin.ts +183 -0
  44. package/src/types.ts +240 -0
  45. package/src/utils.ts +96 -0
@@ -0,0 +1,86 @@
1
+ import { OperationGenerator as Generator } from '@kubb/plugin-oas'
2
+ import { Oas } from '@kubb/plugin-oas/components'
3
+ import { App, createRoot } from '@kubb/react'
4
+
5
+ import { Mutation } from './components/Mutation.tsx'
6
+ import { Operations } from './components/Operations.tsx'
7
+ import { Query } from './components/Query.tsx'
8
+ import { QueryKey } from './components/QueryKey.tsx'
9
+ import { QueryOptions } from './components/QueryOptions.tsx'
10
+
11
+ import type { Operation } from '@kubb/oas'
12
+ import type { OperationMethodResult } from '@kubb/plugin-oas'
13
+ import { QueryImports } from './components/QueryImports.tsx'
14
+ import type { FileMeta, PluginReactQuery } from './types.ts'
15
+
16
+ export class OperationGenerator extends Generator<PluginReactQuery['resolvedOptions'], PluginReactQuery, FileMeta> {
17
+ async all(operations: Operation[]): OperationMethodResult<FileMeta> {
18
+ const { pluginManager, oas, plugin, mode } = this.context
19
+
20
+ const root = createRoot({
21
+ logger: pluginManager.logger,
22
+ })
23
+
24
+ const templates = {
25
+ mutation: Mutation.templates,
26
+ query: Query.templates,
27
+ queryOptions: QueryOptions.templates,
28
+ queryKey: QueryKey.templates,
29
+ queryImports: QueryImports.templates,
30
+ operations: Operations.templates,
31
+ ...this.options.templates,
32
+ }
33
+
34
+ root.render(
35
+ <App pluginManager={pluginManager} plugin={plugin} mode={mode}>
36
+ <Oas oas={oas} operations={operations} generator={this}>
37
+ {templates.operations && <Operations.File templates={templates.operations} />}
38
+ </Oas>
39
+ </App>,
40
+ )
41
+
42
+ return root.files
43
+ }
44
+
45
+ async operation(operation: Operation, options: PluginReactQuery['resolvedOptions']): OperationMethodResult<FileMeta> {
46
+ const { oas, pluginManager, plugin, mode } = this.context
47
+
48
+ const root = createRoot({
49
+ logger: pluginManager.logger,
50
+ })
51
+
52
+ const templates = {
53
+ mutation: Mutation.templates,
54
+ query: Query.templates,
55
+ queryOptions: QueryOptions.templates,
56
+ queryKey: QueryKey.templates,
57
+ queryImports: QueryImports.templates,
58
+ ...options.templates,
59
+ }
60
+
61
+ const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
62
+ const isMutate = !isQuery && options.mutate && options.mutate.methods.some((method) => operation.method === method)
63
+
64
+ root.render(
65
+ <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>
66
+ <Oas oas={oas} operations={[operation]} generator={this}>
67
+ <Oas.Operation operation={operation}>
68
+ {isMutate && templates?.mutation && <Mutation.File templates={templates.mutation} />}
69
+ {isQuery && templates?.query && templates.queryKey && templates.queryOptions && templates.queryImports && (
70
+ <Query.File
71
+ templates={{
72
+ query: templates.query,
73
+ queryKey: templates.queryKey,
74
+ queryOptions: templates.queryOptions,
75
+ queryImports: templates.queryImports,
76
+ }}
77
+ />
78
+ )}
79
+ </Oas.Operation>
80
+ </Oas>
81
+ </App>,
82
+ )
83
+
84
+ return root.files
85
+ }
86
+ }
@@ -0,0 +1,64 @@
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
+ }
@@ -0,0 +1,57 @@
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
+ }
@@ -0,0 +1,63 @@
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
+ }
@@ -0,0 +1,37 @@
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
+ }
@@ -0,0 +1,47 @@
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
+ }
@@ -0,0 +1,67 @@
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
+ }
@@ -0,0 +1,44 @@
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
+ }
@@ -0,0 +1,21 @@
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>;