@kubb/plugin-react-query 3.0.0-alpha.1 → 3.0.0-alpha.11
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/dist/chunk-7ZODZVKP.cjs +1427 -0
- package/dist/chunk-7ZODZVKP.cjs.map +1 -0
- package/dist/{chunk-5IL6M74X.js → chunk-ZYTZV43V.js} +295 -382
- package/dist/chunk-ZYTZV43V.js.map +1 -0
- package/dist/components.cjs +23 -14
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +1 -2
- package/dist/components.d.ts +1 -2
- package/dist/components.js +2 -14
- package/dist/components.js.map +1 -1
- package/dist/{index-C9fwRDH7.d.cts → index-5kpkk-7M.d.cts} +7 -41
- package/dist/{index-C9fwRDH7.d.ts → index-5kpkk-7M.d.ts} +7 -41
- package/dist/index.cjs +67 -107
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +30 -77
- package/dist/index.js.map +1 -1
- package/package.json +15 -15
- package/src/OperationGenerator.tsx +0 -29
- package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +14 -9
- package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +14 -9
- package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +14 -9
- package/src/__snapshots__/queryOptions/getPetById.ts +9 -5
- package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +11 -7
- package/src/__snapshots__/variablesTypeMutate/deletePet.ts +6 -3
- package/src/components/Mutation.tsx +30 -30
- package/src/components/Query.tsx +74 -78
- package/src/components/QueryKey.tsx +13 -9
- package/src/components/QueryOptions.tsx +21 -13
- package/src/components/SchemaType.tsx +9 -5
- package/src/components/__snapshots__/gen/showPetById.ts +58 -48
- package/src/components/__snapshots__/gen/useCreatePets.ts +36 -36
- package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +36 -37
- package/src/components/index.ts +0 -1
- package/src/plugin.ts +16 -34
- package/src/types.ts +0 -3
- package/dist/chunk-5IL6M74X.js.map +0 -1
- package/dist/chunk-JFX7DCS7.cjs +0 -1504
- package/dist/chunk-JFX7DCS7.cjs.map +0 -1
- package/src/__snapshots__/upload/UploadFile.ts +0 -67
- package/src/__snapshots__/uploadMutation/UploadFile.ts +0 -44
- package/src/components/Operations.tsx +0 -74
|
@@ -3,7 +3,6 @@ import { Oas } from '@kubb/plugin-oas/components'
|
|
|
3
3
|
import { App, createRoot } from '@kubb/react'
|
|
4
4
|
|
|
5
5
|
import { Mutation } from './components/Mutation.tsx'
|
|
6
|
-
import { Operations } from './components/Operations.tsx'
|
|
7
6
|
import { Query } from './components/Query.tsx'
|
|
8
7
|
import { QueryKey } from './components/QueryKey.tsx'
|
|
9
8
|
import { QueryOptions } from './components/QueryOptions.tsx'
|
|
@@ -14,34 +13,6 @@ import { QueryImports } from './components/QueryImports.tsx'
|
|
|
14
13
|
import type { FileMeta, PluginReactQuery } from './types.ts'
|
|
15
14
|
|
|
16
15
|
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
16
|
async operation(operation: Operation, options: PluginReactQuery['resolvedOptions']): OperationMethodResult<FileMeta> {
|
|
46
17
|
const { oas, pluginManager, plugin, mode } = this.context
|
|
47
18
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
|
3
2
|
import type { UseBaseQueryOptions, UseQueryResult, QueryKey, WithRequired } from "@tanstack/react-query";
|
|
3
|
+
import { useQuery } from "@tanstack/react-query";
|
|
4
4
|
|
|
5
5
|
type UpdatePetWithFormClient = typeof client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationRequest>;
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
type UpdatePetWithForm = {
|
|
7
8
|
data: UpdatePetWithFormMutationResponse;
|
|
8
9
|
error: UpdatePetWithForm405;
|
|
9
10
|
request: UpdatePetWithFormMutationRequest;
|
|
@@ -16,14 +17,17 @@ type UpdatePetWithForm = {
|
|
|
16
17
|
return: Awaited<ReturnType<UpdatePetWithFormClient>>;
|
|
17
18
|
};
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
+
|
|
21
|
+
export const updatePetWithFormQueryKey = ({ petId }: {
|
|
20
22
|
petId: UpdatePetWithFormPathParams["petId"];
|
|
21
23
|
}, params?: UpdatePetWithForm["queryParams"], data?: UpdatePetWithForm["request"]) => [{ url: "/pet/:petId", params: { petId: petId } }, ...(params ? [params] : []), ...(data ? [data] : [])] as const;
|
|
22
|
-
|
|
23
|
-
export
|
|
24
|
+
|
|
25
|
+
export type UpdatePetWithFormQueryKey = ReturnType<typeof updatePetWithFormQueryKey>;
|
|
26
|
+
|
|
27
|
+
export function updatePetWithFormQueryOptions<TData = UpdatePetWithForm["response"], TQueryData = UpdatePetWithForm["response"]>({ petId }: {
|
|
24
28
|
petId: UpdatePetWithFormPathParams["petId"];
|
|
25
29
|
}, params?: UpdatePetWithForm["queryParams"], data?: UpdatePetWithForm["request"], options: UpdatePetWithForm["client"]["parameters"] = {}): WithRequired<UseBaseQueryOptions<UpdatePetWithForm["response"], UpdatePetWithForm["error"], TData, TQueryData>, "queryKey"> {
|
|
26
|
-
const queryKey =
|
|
30
|
+
const queryKey = updatePetWithFormQueryKey({ petId }, params, data);
|
|
27
31
|
return {
|
|
28
32
|
queryKey,
|
|
29
33
|
queryFn: async () => {
|
|
@@ -38,7 +42,8 @@ export function UpdatePetWithFormQueryOptions<TData = UpdatePetWithForm["respons
|
|
|
38
42
|
},
|
|
39
43
|
};
|
|
40
44
|
}
|
|
41
|
-
|
|
45
|
+
|
|
46
|
+
/**
|
|
42
47
|
* @summary Updates a pet in the store with form data
|
|
43
48
|
* @link /pet/:petId
|
|
44
49
|
*/
|
|
@@ -51,9 +56,9 @@ export function updatePetWithForm<TData = UpdatePetWithForm["response"], TQueryD
|
|
|
51
56
|
queryKey: TQueryKey;
|
|
52
57
|
} {
|
|
53
58
|
const { query: queryOptions, client: clientOptions = {} } = options ?? {};
|
|
54
|
-
const queryKey = queryOptions?.queryKey ??
|
|
59
|
+
const queryKey = queryOptions?.queryKey ?? updatePetWithFormQueryKey({ petId }, params, data);
|
|
55
60
|
const query = useQuery<UpdatePetWithForm["data"], UpdatePetWithForm["error"], TData, any>({
|
|
56
|
-
...
|
|
61
|
+
...updatePetWithFormQueryOptions<TData, TQueryData>({ petId }, params, data, clientOptions),
|
|
57
62
|
queryKey,
|
|
58
63
|
...queryOptions
|
|
59
64
|
}) as UseQueryResult<TData, UpdatePetWithForm["error"]> & {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
|
3
2
|
import type { UseBaseQueryOptions, UseQueryResult, QueryKey, WithRequired } from "@tanstack/react-query";
|
|
3
|
+
import { useQuery } from "@tanstack/react-query";
|
|
4
4
|
|
|
5
5
|
type GetPetByIdClient = typeof client<GetPetByIdQueryResponse, GetPetById400 | GetPetById404, never>;
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
type GetPetById = {
|
|
7
8
|
data: GetPetByIdQueryResponse;
|
|
8
9
|
error: GetPetById400 | GetPetById404;
|
|
9
10
|
request: never;
|
|
@@ -16,10 +17,13 @@ type GetPetById = {
|
|
|
16
17
|
return: Awaited<ReturnType<GetPetByIdClient>>;
|
|
17
18
|
};
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
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);
|
|
23
27
|
return {
|
|
24
28
|
queryKey,
|
|
25
29
|
queryFn: async () => {
|
|
@@ -32,7 +36,8 @@ export function GetPetByIdQueryOptions<TData = GetPetById["response"], TQueryDat
|
|
|
32
36
|
},
|
|
33
37
|
};
|
|
34
38
|
}
|
|
35
|
-
|
|
39
|
+
|
|
40
|
+
/**
|
|
36
41
|
* @description Returns a single pet
|
|
37
42
|
* @summary Find pet by ID
|
|
38
43
|
* @link /pet/:petId
|
|
@@ -44,9 +49,9 @@ export function getPetById<TData = GetPetById["response"], TQueryData = GetPetBy
|
|
|
44
49
|
queryKey: TQueryKey;
|
|
45
50
|
} {
|
|
46
51
|
const { query: queryOptions, client: clientOptions = {} } = options ?? {};
|
|
47
|
-
const queryKey = queryOptions?.queryKey ??
|
|
52
|
+
const queryKey = queryOptions?.queryKey ?? getPetByIdQueryKey(petId);
|
|
48
53
|
const query = useQuery<GetPetById["data"], GetPetById["error"], TData, any>({
|
|
49
|
-
...
|
|
54
|
+
...getPetByIdQueryOptions<TData, TQueryData>(petId, clientOptions),
|
|
50
55
|
queryKey,
|
|
51
56
|
...queryOptions
|
|
52
57
|
}) as UseQueryResult<TData, GetPetById["error"]> & {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
|
3
2
|
import type { UseBaseQueryOptions, UseQueryResult, QueryKey, WithRequired } from "@tanstack/react-query";
|
|
3
|
+
import { useQuery } from "@tanstack/react-query";
|
|
4
4
|
|
|
5
5
|
type GetPetByIdClient = typeof client<GetPetByIdQueryResponse, GetPetById400 | GetPetById404, never>;
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
type GetPetById = {
|
|
7
8
|
data: GetPetByIdQueryResponse;
|
|
8
9
|
error: GetPetById400 | GetPetById404;
|
|
9
10
|
request: never;
|
|
@@ -16,14 +17,17 @@ type GetPetById = {
|
|
|
16
17
|
return: Awaited<ReturnType<GetPetByIdClient>>;
|
|
17
18
|
};
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
+
|
|
21
|
+
export const getPetByIdQueryKey = ({ petId }: {
|
|
20
22
|
petId: GetPetByIdPathParams["petId"];
|
|
21
23
|
}) => [{ url: "/pet/:petId", params: { petId: petId } }] as const;
|
|
22
|
-
|
|
23
|
-
export
|
|
24
|
+
|
|
25
|
+
export type GetPetByIdQueryKey = ReturnType<typeof getPetByIdQueryKey>;
|
|
26
|
+
|
|
27
|
+
export function getPetByIdQueryOptions<TData = GetPetById["response"], TQueryData = GetPetById["response"]>({ petId }: {
|
|
24
28
|
petId: GetPetByIdPathParams["petId"];
|
|
25
29
|
}, options: GetPetById["client"]["parameters"] = {}): WithRequired<UseBaseQueryOptions<GetPetById["response"], GetPetById["error"], TData, TQueryData>, "queryKey"> {
|
|
26
|
-
const queryKey =
|
|
30
|
+
const queryKey = getPetByIdQueryKey({ petId });
|
|
27
31
|
return {
|
|
28
32
|
queryKey,
|
|
29
33
|
queryFn: async () => {
|
|
@@ -36,7 +40,8 @@ export function GetPetByIdQueryOptions<TData = GetPetById["response"], TQueryDat
|
|
|
36
40
|
},
|
|
37
41
|
};
|
|
38
42
|
}
|
|
39
|
-
|
|
43
|
+
|
|
44
|
+
/**
|
|
40
45
|
* @description Returns a single pet
|
|
41
46
|
* @summary Find pet by ID
|
|
42
47
|
* @link /pet/:petId
|
|
@@ -50,9 +55,9 @@ export function getPetById<TData = GetPetById["response"], TQueryData = GetPetBy
|
|
|
50
55
|
queryKey: TQueryKey;
|
|
51
56
|
} {
|
|
52
57
|
const { query: queryOptions, client: clientOptions = {} } = options ?? {};
|
|
53
|
-
const queryKey = queryOptions?.queryKey ??
|
|
58
|
+
const queryKey = queryOptions?.queryKey ?? getPetByIdQueryKey({ petId });
|
|
54
59
|
const query = useQuery<GetPetById["data"], GetPetById["error"], TData, any>({
|
|
55
|
-
...
|
|
60
|
+
...getPetByIdQueryOptions<TData, TQueryData>({ petId }, clientOptions),
|
|
56
61
|
queryKey,
|
|
57
62
|
...queryOptions
|
|
58
63
|
}) as UseQueryResult<TData, GetPetById["error"]> & {
|
|
@@ -2,7 +2,8 @@ import client from "@kubb/plugin-client/client";
|
|
|
2
2
|
import type { UseBaseQueryOptions, QueryKey, WithRequired } from "@tanstack/react-query";
|
|
3
3
|
|
|
4
4
|
type GetPetByIdClient = typeof client<GetPetByIdQueryResponse, GetPetById400 | GetPetById404, never>;
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
type GetPetById = {
|
|
6
7
|
data: GetPetByIdQueryResponse;
|
|
7
8
|
error: GetPetById400 | GetPetById404;
|
|
8
9
|
request: never;
|
|
@@ -15,14 +16,17 @@ type GetPetById = {
|
|
|
15
16
|
return: Awaited<ReturnType<GetPetByIdClient>>;
|
|
16
17
|
};
|
|
17
18
|
};
|
|
18
|
-
|
|
19
|
+
|
|
20
|
+
export const getPetByIdQueryKey = ({ petId }: {
|
|
19
21
|
petId: GetPetByIdPathParams["petId"];
|
|
20
22
|
}) => [{ url: "/pet/:petId", params: { petId: petId } }] as const;
|
|
21
|
-
|
|
22
|
-
export
|
|
23
|
+
|
|
24
|
+
export type GetPetByIdQueryKey = ReturnType<typeof getPetByIdQueryKey>;
|
|
25
|
+
|
|
26
|
+
export function getPetByIdQueryOptions<TData = GetPetById["response"], TQueryData = GetPetById["response"]>({ petId }: {
|
|
23
27
|
petId: GetPetByIdPathParams["petId"];
|
|
24
28
|
}, options: GetPetById["client"]["parameters"] = {}): WithRequired<UseBaseQueryOptions<GetPetById["response"], GetPetById["error"], TData, TQueryData>, "queryKey"> {
|
|
25
|
-
const queryKey =
|
|
29
|
+
const queryKey = getPetByIdQueryKey({ petId });
|
|
26
30
|
return {
|
|
27
31
|
queryKey,
|
|
28
32
|
queryFn: async () => {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
|
3
2
|
import type { UseBaseQueryOptions, UseQueryResult, QueryKey } from "@tanstack/react-query";
|
|
3
|
+
import { useQuery } from "@tanstack/react-query";
|
|
4
4
|
|
|
5
5
|
type GetPetByIdClient = typeof client<GetPetByIdQueryResponse, GetPetById400 | GetPetById404, never>;
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
type GetPetById = {
|
|
7
8
|
data: GetPetByIdQueryResponse;
|
|
8
9
|
error: GetPetById400 | GetPetById404;
|
|
9
10
|
request: never;
|
|
@@ -16,11 +17,14 @@ type GetPetById = {
|
|
|
16
17
|
return: Awaited<ReturnType<GetPetByIdClient>>;
|
|
17
18
|
};
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
+
|
|
21
|
+
export const getPetByIdQueryKey = ({ petId }: {
|
|
20
22
|
petId: GetPetByIdPathParams["petId"];
|
|
21
23
|
}) => [{ url: "/pet/:petId", params: { petId: petId } }] as const;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
|
|
25
|
+
export type GetPetByIdQueryKey = ReturnType<typeof getPetByIdQueryKey>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
24
28
|
* @description Returns a single pet
|
|
25
29
|
* @summary Find pet by ID
|
|
26
30
|
* @link /pet/:petId
|
|
@@ -34,9 +38,9 @@ export function getPetById<TData = GetPetById["response"], TQueryData = GetPetBy
|
|
|
34
38
|
queryKey: TQueryKey;
|
|
35
39
|
} {
|
|
36
40
|
const { query: queryOptions, client: clientOptions = {} } = options ?? {};
|
|
37
|
-
const queryKey = queryOptions?.queryKey ??
|
|
41
|
+
const queryKey = queryOptions?.queryKey ?? getPetByIdQueryKey({ petId });
|
|
38
42
|
const query = useQuery<GetPetById["data"], GetPetById["error"], TData, any>({
|
|
39
|
-
...
|
|
43
|
+
...getPetByIdQueryOptions<TData, TQueryData>({ petId }, clientOptions),
|
|
40
44
|
queryKey,
|
|
41
45
|
...queryOptions
|
|
42
46
|
}) as UseQueryResult<TData, GetPetById["error"]> & {
|
|
@@ -2,7 +2,8 @@ import client from "@kubb/plugin-client/client";
|
|
|
2
2
|
import type { QueryKey } from "@tanstack/react-query";
|
|
3
3
|
|
|
4
4
|
type DeletePetClient = typeof client<DeletePetMutationResponse, DeletePet400, never>;
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
type DeletePet = {
|
|
6
7
|
data: DeletePetMutationResponse;
|
|
7
8
|
error: DeletePet400;
|
|
8
9
|
request: never;
|
|
@@ -15,7 +16,9 @@ type DeletePet = {
|
|
|
15
16
|
return: Awaited<ReturnType<DeletePetClient>>;
|
|
16
17
|
};
|
|
17
18
|
};
|
|
18
|
-
|
|
19
|
+
|
|
20
|
+
export const deletePetQueryKey = ({ petId }: {
|
|
19
21
|
petId: DeletePetPathParams["petId"];
|
|
20
22
|
}) => [{ url: "/pet/:petId", params: { petId: petId } }] as const;
|
|
21
|
-
|
|
23
|
+
|
|
24
|
+
export type DeletePetQueryKey = ReturnType<typeof deletePetQueryKey>;
|
|
@@ -2,7 +2,7 @@ import transformers from '@kubb/core/transformers'
|
|
|
2
2
|
import { FunctionParams, URLPath } from '@kubb/core/utils'
|
|
3
3
|
import { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
4
4
|
import { getASTParams, getComments } from '@kubb/plugin-oas/utils'
|
|
5
|
-
import { File, Function,
|
|
5
|
+
import { File, Function, useApp } from '@kubb/react'
|
|
6
6
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
7
7
|
|
|
8
8
|
import { SchemaType } from './SchemaType.tsx'
|
|
@@ -82,8 +82,9 @@ function Template({ name, params, mutateParams, JSDoc, client, hook, dataReturnT
|
|
|
82
82
|
: undefined
|
|
83
83
|
|
|
84
84
|
return (
|
|
85
|
-
<
|
|
86
|
-
{
|
|
85
|
+
<File.Source name={name} isExportable isIndexable>
|
|
86
|
+
<Function export name={name} params={params} JSDoc={JSDoc}>
|
|
87
|
+
{`
|
|
87
88
|
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}
|
|
88
89
|
|
|
89
90
|
return ${hook.name}({
|
|
@@ -98,7 +99,8 @@ function Template({ name, params, mutateParams, JSDoc, client, hook, dataReturnT
|
|
|
98
99
|
},
|
|
99
100
|
...mutationOptions
|
|
100
101
|
})`}
|
|
101
|
-
|
|
102
|
+
</Function>
|
|
103
|
+
</File.Source>
|
|
102
104
|
)
|
|
103
105
|
}
|
|
104
106
|
|
|
@@ -124,32 +126,30 @@ function RootTemplate({ children }: RootTemplateProps) {
|
|
|
124
126
|
const fileType = getFile(operation, { pluginKey: [pluginTsName] })
|
|
125
127
|
|
|
126
128
|
return (
|
|
127
|
-
<
|
|
128
|
-
<File
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
name
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
</File>
|
|
152
|
-
</Parser>
|
|
129
|
+
<File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
130
|
+
<File.Import name={'client'} path={importPath} />
|
|
131
|
+
<File.Import name={['ResponseConfig']} path={importPath} isTypeOnly />
|
|
132
|
+
<File.Import
|
|
133
|
+
name={[
|
|
134
|
+
schemas.request?.name,
|
|
135
|
+
schemas.response.name,
|
|
136
|
+
schemas.pathParams?.name,
|
|
137
|
+
schemas.queryParams?.name,
|
|
138
|
+
schemas.headerParams?.name,
|
|
139
|
+
...(schemas.errors?.map((error) => error.name) || []),
|
|
140
|
+
].filter(Boolean)}
|
|
141
|
+
root={file.path}
|
|
142
|
+
path={fileType.path}
|
|
143
|
+
isTypeOnly
|
|
144
|
+
/>
|
|
145
|
+
<File.Import
|
|
146
|
+
name={['UseMutationOptions', 'UseMutationResult']}
|
|
147
|
+
path={typeof mutate !== 'boolean' && mutate.importPath ? mutate.importPath : '@tanstack/react-query'}
|
|
148
|
+
isTypeOnly
|
|
149
|
+
/>
|
|
150
|
+
<File.Import name={['useMutation']} path={typeof mutate !== 'boolean' && mutate.importPath ? mutate.importPath : '@tanstack/react-query'} />
|
|
151
|
+
{children}
|
|
152
|
+
</File>
|
|
153
153
|
)
|
|
154
154
|
}
|
|
155
155
|
|
package/src/components/Query.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PackageManager } from '@kubb/core'
|
|
2
2
|
import transformers from '@kubb/core/transformers'
|
|
3
3
|
import { FunctionParams, URLPath } from '@kubb/core/utils'
|
|
4
|
-
import {
|
|
4
|
+
import { File, Function, useApp } from '@kubb/react'
|
|
5
5
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
6
6
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
7
7
|
import { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
@@ -56,7 +56,7 @@ function Template({ name, generics, returnType, params, JSDoc, hook, infinite }:
|
|
|
56
56
|
|
|
57
57
|
if (isV5) {
|
|
58
58
|
return (
|
|
59
|
-
|
|
59
|
+
<File.Source name={name} isExportable isIndexable>
|
|
60
60
|
<Function name={name} export generics={generics} returnType={resolvedReturnType} params={params} JSDoc={JSDoc}>
|
|
61
61
|
{`
|
|
62
62
|
const { query: queryOptions, client: clientOptions = {} } = options ?? {}
|
|
@@ -74,12 +74,12 @@ function Template({ name, generics, returnType, params, JSDoc, hook, infinite }:
|
|
|
74
74
|
|
|
75
75
|
`}
|
|
76
76
|
</Function>
|
|
77
|
-
|
|
77
|
+
</File.Source>
|
|
78
78
|
)
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
return (
|
|
82
|
-
|
|
82
|
+
<File.Source name={name} isExportable isIndexable>
|
|
83
83
|
<Function name={name} export generics={generics} returnType={resolvedReturnType} params={params} JSDoc={JSDoc}>
|
|
84
84
|
{`
|
|
85
85
|
const { query: queryOptions, client: clientOptions = {} } = options ?? {}
|
|
@@ -97,7 +97,7 @@ function Template({ name, generics, returnType, params, JSDoc, hook, infinite }:
|
|
|
97
97
|
|
|
98
98
|
`}
|
|
99
99
|
</Function>
|
|
100
|
-
|
|
100
|
+
</File.Source>
|
|
101
101
|
)
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -547,80 +547,76 @@ Query.File = function ({ templates }: FileProps): ReactNode {
|
|
|
547
547
|
}
|
|
548
548
|
|
|
549
549
|
return (
|
|
550
|
-
<
|
|
551
|
-
<File
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
name
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
/>
|
|
550
|
+
<File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
551
|
+
{parser === 'zod' && <File.Import name={[zodSchemas.response?.name]} root={file.path} path={fileZodSchemas.path} />}
|
|
552
|
+
<File.Import name={'client'} path={importPath} />
|
|
553
|
+
<File.Import name={['ResponseConfig']} path={importPath} isTypeOnly />
|
|
554
|
+
<File.Import
|
|
555
|
+
name={[
|
|
556
|
+
schemas.request?.name,
|
|
557
|
+
schemas.response.name,
|
|
558
|
+
schemas.pathParams?.name,
|
|
559
|
+
schemas.queryParams?.name,
|
|
560
|
+
schemas.headerParams?.name,
|
|
561
|
+
...(schemas.errors?.map((error) => error.name) || []),
|
|
562
|
+
].filter(Boolean)}
|
|
563
|
+
root={file.path}
|
|
564
|
+
path={fileType.path}
|
|
565
|
+
isTypeOnly
|
|
566
|
+
/>
|
|
568
567
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
</File.Source>
|
|
622
|
-
</File>
|
|
623
|
-
</Parser>
|
|
568
|
+
<QueryImports hookPath={typeof query !== 'boolean' ? query.importPath : undefined} Template={Import} isInfinite={false} isSuspense={false} />
|
|
569
|
+
{!!infinite && (
|
|
570
|
+
<QueryImports hookPath={typeof query !== 'boolean' ? query.importPath : undefined} Template={Import} isInfinite={true} isSuspense={false} />
|
|
571
|
+
)}
|
|
572
|
+
{!!suspense && isV5 && (
|
|
573
|
+
<QueryImports hookPath={typeof query !== 'boolean' ? query.importPath : undefined} Template={Import} isInfinite={false} isSuspense={true} />
|
|
574
|
+
)}
|
|
575
|
+
<SchemaType />
|
|
576
|
+
<Query
|
|
577
|
+
factory={factory}
|
|
578
|
+
Template={Template}
|
|
579
|
+
QueryKeyTemplate={QueryKeyTemplate}
|
|
580
|
+
QueryOptionsTemplate={QueryOptionsTemplate}
|
|
581
|
+
infinite={false}
|
|
582
|
+
suspense={false}
|
|
583
|
+
query={query}
|
|
584
|
+
queryOptions={queryOptions}
|
|
585
|
+
hookName={importNames.query['react'].hookName}
|
|
586
|
+
resultType={importNames.query['react'].resultType}
|
|
587
|
+
optionsType={importNames.query['react'].optionsType}
|
|
588
|
+
/>
|
|
589
|
+
{!!infinite && (
|
|
590
|
+
<Query
|
|
591
|
+
factory={factory}
|
|
592
|
+
Template={Template}
|
|
593
|
+
QueryKeyTemplate={QueryKeyTemplate}
|
|
594
|
+
QueryOptionsTemplate={QueryOptionsTemplate}
|
|
595
|
+
infinite={infinite}
|
|
596
|
+
suspense={false}
|
|
597
|
+
query={query}
|
|
598
|
+
queryOptions={queryOptions}
|
|
599
|
+
hookName={importNames.queryInfinite['react'].hookName}
|
|
600
|
+
resultType={importNames.queryInfinite['react'].resultType}
|
|
601
|
+
optionsType={importNames.queryInfinite['react'].optionsType}
|
|
602
|
+
/>
|
|
603
|
+
)}
|
|
604
|
+
{!!suspense && isV5 && (
|
|
605
|
+
<Query
|
|
606
|
+
factory={factory}
|
|
607
|
+
Template={Template}
|
|
608
|
+
QueryKeyTemplate={QueryKeyTemplate}
|
|
609
|
+
QueryOptionsTemplate={QueryOptionsTemplate}
|
|
610
|
+
infinite={false}
|
|
611
|
+
suspense={suspense}
|
|
612
|
+
query={query}
|
|
613
|
+
queryOptions={queryOptions}
|
|
614
|
+
hookName={importNames.querySuspense['react'].hookName}
|
|
615
|
+
resultType={importNames.querySuspense['react'].resultType}
|
|
616
|
+
optionsType={importNames.querySuspense['react'].optionsType}
|
|
617
|
+
/>
|
|
618
|
+
)}
|
|
619
|
+
</File>
|
|
624
620
|
)
|
|
625
621
|
}
|
|
626
622
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { FunctionParams, URLPath } from '@kubb/core/utils'
|
|
2
|
-
import { Function, Type, useApp } from '@kubb/react'
|
|
3
2
|
import { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
4
3
|
import { getASTParams } from '@kubb/plugin-oas/utils'
|
|
4
|
+
import { File, Function, Type, useApp } from '@kubb/react'
|
|
5
5
|
|
|
6
6
|
import { isRequired } from '@kubb/oas'
|
|
7
|
+
import { pluginTsName } from '@kubb/plugin-ts'
|
|
7
8
|
import type { ReactNode } from 'react'
|
|
8
9
|
import type { PluginReactQuery } from '../types'
|
|
9
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
10
10
|
|
|
11
11
|
type TemplateProps = {
|
|
12
12
|
/**
|
|
@@ -41,13 +41,17 @@ type TemplateProps = {
|
|
|
41
41
|
function Template({ name, typeName, params, generics, returnType, JSDoc, keys }: TemplateProps): ReactNode {
|
|
42
42
|
return (
|
|
43
43
|
<>
|
|
44
|
-
<
|
|
45
|
-
{
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
<File.Source name={name} isExportable isIndexable>
|
|
45
|
+
<Function.Arrow name={name} export generics={generics} params={params} returnType={returnType} singleLine JSDoc={JSDoc}>
|
|
46
|
+
{`[${keys}] as const`}
|
|
47
|
+
</Function.Arrow>
|
|
48
|
+
</File.Source>
|
|
49
|
+
|
|
50
|
+
<File.Source name={typeName} isExportable isIndexable isTypeOnly>
|
|
51
|
+
<Type name={typeName} export>
|
|
52
|
+
{`ReturnType<typeof ${name}>`}
|
|
53
|
+
</Type>
|
|
54
|
+
</File.Source>
|
|
51
55
|
</>
|
|
52
56
|
)
|
|
53
57
|
}
|