@kubb/plugin-svelte-query 3.0.0-beta.8 → 3.0.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.
- package/dist/{chunk-IYE4XII3.cjs → chunk-CDRGJAED.cjs} +71 -56
- package/dist/chunk-CDRGJAED.cjs.map +1 -0
- package/dist/{chunk-STYJ2DL3.js → chunk-JGITTOE5.js} +65 -50
- package/dist/chunk-JGITTOE5.js.map +1 -0
- package/dist/{chunk-WAAKXO6O.cjs → chunk-KRGCKSGR.cjs} +145 -29
- package/dist/chunk-KRGCKSGR.cjs.map +1 -0
- package/dist/{chunk-B7GVNGYU.js → chunk-R6ZVBNG7.js} +145 -29
- package/dist/chunk-R6ZVBNG7.js.map +1 -0
- package/dist/components.cjs +6 -6
- package/dist/components.d.cts +17 -10
- package/dist/components.d.ts +17 -10
- package/dist/components.js +1 -1
- package/dist/generators.cjs +4 -4
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +2 -2
- package/dist/index.cjs +23 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +22 -23
- package/dist/index.js.map +1 -1
- package/dist/types-B9W9aYra.d.cts +365 -0
- package/dist/types-B9W9aYra.d.ts +365 -0
- package/package.json +13 -13
- package/src/components/Mutation.tsx +7 -3
- package/src/components/MutationKey.tsx +11 -5
- package/src/components/Query.tsx +62 -6
- package/src/components/QueryKey.tsx +17 -7
- package/src/components/QueryOptions.tsx +47 -7
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +1 -1
- package/src/generators/__snapshots__/clientGetImportPath.ts +1 -1
- package/src/generators/__snapshots__/findByTags.ts +1 -1
- package/src/generators/__snapshots__/findByTagsObject.ts +60 -0
- package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +1 -1
- package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +2 -2
- package/src/generators/__snapshots__/findByTagsWithZod.ts +1 -1
- package/src/generators/__snapshots__/postAsQuery.ts +1 -1
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +1 -3
- package/src/generators/mutationGenerator.tsx +25 -16
- package/src/generators/queryGenerator.tsx +25 -17
- package/src/plugin.ts +22 -21
- package/src/types.ts +35 -14
- package/dist/chunk-B7GVNGYU.js.map +0 -1
- package/dist/chunk-IYE4XII3.cjs.map +0 -1
- package/dist/chunk-STYJ2DL3.js.map +0 -1
- package/dist/chunk-WAAKXO6O.cjs.map +0 -1
- package/dist/types-CvXX_phR.d.cts +0 -184
- package/dist/types-CvXX_phR.d.ts +0 -184
|
@@ -14,20 +14,59 @@ type Props = {
|
|
|
14
14
|
clientName: string
|
|
15
15
|
queryKeyName: string
|
|
16
16
|
typeSchemas: OperationSchemas
|
|
17
|
+
paramsType: PluginSvelteQuery['resolvedOptions']['paramsType']
|
|
17
18
|
pathParamsType: PluginSvelteQuery['resolvedOptions']['pathParamsType']
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
type GetParamsProps = {
|
|
22
|
+
paramsType: PluginSvelteQuery['resolvedOptions']['paramsType']
|
|
21
23
|
pathParamsType: PluginSvelteQuery['resolvedOptions']['pathParamsType']
|
|
22
24
|
typeSchemas: OperationSchemas
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
27
|
+
function getParams({ paramsType, pathParamsType, typeSchemas }: GetParamsProps) {
|
|
28
|
+
if (paramsType === 'object') {
|
|
29
|
+
return FunctionParams.factory({
|
|
30
|
+
data: {
|
|
31
|
+
mode: 'object',
|
|
32
|
+
children: {
|
|
33
|
+
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
34
|
+
data: typeSchemas.request?.name
|
|
35
|
+
? {
|
|
36
|
+
type: typeSchemas.request?.name,
|
|
37
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
38
|
+
}
|
|
39
|
+
: undefined,
|
|
40
|
+
params: typeSchemas.queryParams?.name
|
|
41
|
+
? {
|
|
42
|
+
type: typeSchemas.queryParams?.name,
|
|
43
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
44
|
+
}
|
|
45
|
+
: undefined,
|
|
46
|
+
headers: typeSchemas.headerParams?.name
|
|
47
|
+
? {
|
|
48
|
+
type: typeSchemas.headerParams?.name,
|
|
49
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
50
|
+
}
|
|
51
|
+
: undefined,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
config: {
|
|
55
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>',
|
|
56
|
+
default: '{}',
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
26
61
|
return FunctionParams.factory({
|
|
27
|
-
pathParams:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
62
|
+
pathParams: typeSchemas.pathParams?.name
|
|
63
|
+
? {
|
|
64
|
+
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
65
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
66
|
+
type: typeSchemas.pathParams?.name,
|
|
67
|
+
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
68
|
+
}
|
|
69
|
+
: undefined,
|
|
31
70
|
data: typeSchemas.request?.name
|
|
32
71
|
? {
|
|
33
72
|
type: typeSchemas.request?.name,
|
|
@@ -53,9 +92,10 @@ function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
|
53
92
|
})
|
|
54
93
|
}
|
|
55
94
|
|
|
56
|
-
export function QueryOptions({ name, clientName, typeSchemas, pathParamsType, queryKeyName }: Props): ReactNode {
|
|
57
|
-
const params = getParams({ pathParamsType, typeSchemas })
|
|
95
|
+
export function QueryOptions({ name, clientName, typeSchemas, paramsType, pathParamsType, queryKeyName }: Props): ReactNode {
|
|
96
|
+
const params = getParams({ paramsType, pathParamsType, typeSchemas })
|
|
58
97
|
const clientParams = Client.getParams({
|
|
98
|
+
paramsType,
|
|
59
99
|
typeSchemas,
|
|
60
100
|
pathParamsType,
|
|
61
101
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig, ResponseConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "@tanstack/svelte-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, createQuery } from "@tanstack/svelte-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import client from "axios";
|
|
2
2
|
import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "@tanstack/svelte-query";
|
|
3
3
|
import type { RequestConfig } from "axios";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, createQuery } from "@tanstack/svelte-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "@tanstack/svelte-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, createQuery } from "@tanstack/svelte-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
7
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import client from "@kubb/plugin-client/client";
|
|
2
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
|
+
import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "@tanstack/svelte-query";
|
|
4
|
+
import { queryOptions, createQuery } from "@tanstack/svelte-query";
|
|
5
|
+
|
|
6
|
+
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
|
+
|
|
8
|
+
export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
12
|
+
* @summary Finds Pets by tags
|
|
13
|
+
* @link /pet/findByTags
|
|
14
|
+
*/
|
|
15
|
+
async function findPetsByTags({ headers, params }: {
|
|
16
|
+
headers: FindPetsByTagsHeaderParams;
|
|
17
|
+
params?: FindPetsByTagsQueryParams;
|
|
18
|
+
}, config: Partial<RequestConfig> = {}) {
|
|
19
|
+
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "GET", url: `/pet/findByTags`, params, headers: { ...headers, ...config.headers }, ...config });
|
|
20
|
+
return findPetsByTagsQueryResponse.parse(res.data);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function findPetsByTagsQueryOptions({ headers, params }: {
|
|
24
|
+
headers: FindPetsByTagsHeaderParams;
|
|
25
|
+
params?: FindPetsByTagsQueryParams;
|
|
26
|
+
}, config: Partial<RequestConfig> = {}) {
|
|
27
|
+
const queryKey = findPetsByTagsQueryKey(params);
|
|
28
|
+
return queryOptions({
|
|
29
|
+
queryKey,
|
|
30
|
+
queryFn: async ({ signal }) => {
|
|
31
|
+
config.signal = signal;
|
|
32
|
+
return findPetsByTags({ headers, params }, config);
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
39
|
+
* @summary Finds Pets by tags
|
|
40
|
+
* @link /pet/findByTags
|
|
41
|
+
*/
|
|
42
|
+
export function createFindPetsByTags<TData = FindPetsByTagsQueryResponse, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsQueryKey>({ headers, params }: {
|
|
43
|
+
headers: FindPetsByTagsHeaderParams;
|
|
44
|
+
params?: FindPetsByTagsQueryParams;
|
|
45
|
+
}, options: {
|
|
46
|
+
query?: Partial<CreateBaseQueryOptions<FindPetsByTagsQueryResponse, FindPetsByTags400, TData, TQueryData, TQueryKey>>;
|
|
47
|
+
client?: Partial<RequestConfig>;
|
|
48
|
+
} = {}) {
|
|
49
|
+
const { query: queryOptions, client: config = {} } = options ?? {};
|
|
50
|
+
const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params);
|
|
51
|
+
const query = createQuery({
|
|
52
|
+
...findPetsByTagsQueryOptions({ headers, params }, config) as unknown as CreateBaseQueryOptions,
|
|
53
|
+
queryKey,
|
|
54
|
+
...queryOptions as unknown as Omit<CreateBaseQueryOptions, "queryKey">
|
|
55
|
+
}) as CreateQueryResult<TData, FindPetsByTags400> & {
|
|
56
|
+
queryKey: TQueryKey;
|
|
57
|
+
};
|
|
58
|
+
query.queryKey = queryKey as TQueryKey;
|
|
59
|
+
return query;
|
|
60
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "@tanstack/svelte-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, createQuery } from "@tanstack/svelte-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
7
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "@tanstack/react-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, createQuery } from "@tanstack/react-query";
|
|
5
5
|
|
|
6
|
-
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [test, { url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
6
|
+
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => ["test", { url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
7
|
|
|
8
8
|
export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
|
|
9
9
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "@tanstack/svelte-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, createQuery } from "@tanstack/svelte-query";
|
|
5
5
|
|
|
6
6
|
export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, CreateBaseQueryOptions, CreateQueryResult } from "custom-query";
|
|
4
|
-
import {
|
|
4
|
+
import { queryOptions, createQuery } from "custom-query";
|
|
5
5
|
|
|
6
6
|
export const updatePetWithFormQueryKey = (petId: UpdatePetWithFormPathParams["petId"], data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams) => [{ url: "/pet/:petId", params: { petId: petId } }, ...(params ? [params] : []), ...(data ? [data] : [])] as const;
|
|
7
7
|
|
|
@@ -11,9 +11,7 @@ import { createMutation } from "@tanstack/svelte-query";
|
|
|
11
11
|
* @summary Updates a pet in the store with form data
|
|
12
12
|
* @link /pet/:petId
|
|
13
13
|
*/
|
|
14
|
-
async function updatePetWithForm({ petId }: {
|
|
15
|
-
petId: UpdatePetWithFormPathParams["petId"];
|
|
16
|
-
}, data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> = {}) {
|
|
14
|
+
async function updatePetWithForm({ petId }: UpdatePetWithFormPathParams, data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> = {}) {
|
|
17
15
|
const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationRequest>({ method: "POST", url: `/pet/${petId}`, params, data, ...config });
|
|
18
16
|
return updatePetWithFormMutationResponse.parse(res.data);
|
|
19
17
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import transformers from '@kubb/core/transformers'
|
|
2
1
|
import { pluginClientName } from '@kubb/plugin-client'
|
|
3
2
|
import { Client } from '@kubb/plugin-client/components'
|
|
4
3
|
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
@@ -22,6 +21,8 @@ export const mutationGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
22
21
|
const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
|
|
23
22
|
const isMutation = !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method)
|
|
24
23
|
|
|
24
|
+
const importPath = options.mutation ? options.mutation.importPath : '@tanstack/svelte-query'
|
|
25
|
+
|
|
25
26
|
const mutation = {
|
|
26
27
|
name: getName(operation, { type: 'function', prefix: 'create' }),
|
|
27
28
|
typeName: getName(operation, { type: 'type' }),
|
|
@@ -48,15 +49,14 @@ export const mutationGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
48
49
|
typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
if (!isMutation
|
|
52
|
+
if (!isMutation) {
|
|
52
53
|
return null
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
return (
|
|
56
57
|
<File baseName={mutation.file.baseName} path={mutation.file.path} meta={mutation.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
57
58
|
{options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />}
|
|
58
|
-
|
|
59
|
-
<File.Import name={['CreateMutationOptions', 'CreateMutationResult']} path={options.mutation.importPath} isTypeOnly />
|
|
59
|
+
|
|
60
60
|
<File.Import name={'client'} path={options.client.importPath} />
|
|
61
61
|
<File.Import name={['RequestConfig', 'ResponseConfig']} path={options.client.importPath} isTypeOnly />
|
|
62
62
|
<File.Import
|
|
@@ -72,36 +72,45 @@ export const mutationGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
72
72
|
path={type.file.path}
|
|
73
73
|
isTypeOnly
|
|
74
74
|
/>
|
|
75
|
+
|
|
75
76
|
<MutationKey
|
|
76
77
|
name={mutationKey.name}
|
|
77
78
|
typeName={mutationKey.typeName}
|
|
78
79
|
operation={operation}
|
|
79
80
|
pathParamsType={options.pathParamsType}
|
|
80
81
|
typeSchemas={type.schemas}
|
|
81
|
-
|
|
82
|
+
transformer={options.mutationKey}
|
|
82
83
|
/>
|
|
83
84
|
<Client
|
|
84
85
|
name={client.name}
|
|
85
86
|
isExportable={false}
|
|
86
87
|
isIndexable={false}
|
|
87
|
-
baseURL={options.baseURL}
|
|
88
|
+
baseURL={options.client.baseURL}
|
|
88
89
|
operation={operation}
|
|
89
90
|
typeSchemas={type.schemas}
|
|
90
91
|
zodSchemas={zod.schemas}
|
|
91
92
|
dataReturnType={options.client.dataReturnType}
|
|
93
|
+
paramsType={options.paramsType}
|
|
92
94
|
pathParamsType={options.pathParamsType}
|
|
93
95
|
parser={options.parser}
|
|
94
96
|
/>
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
97
|
+
{options.mutation && (
|
|
98
|
+
<>
|
|
99
|
+
<File.Import name={['createMutation']} path={importPath} />
|
|
100
|
+
<File.Import name={['CreateMutationOptions', 'CreateMutationResult']} path={importPath} isTypeOnly />
|
|
101
|
+
<Mutation
|
|
102
|
+
name={mutation.name}
|
|
103
|
+
clientName={client.name}
|
|
104
|
+
typeName={mutation.typeName}
|
|
105
|
+
typeSchemas={type.schemas}
|
|
106
|
+
operation={operation}
|
|
107
|
+
dataReturnType={options.client.dataReturnType}
|
|
108
|
+
paramsType={options.paramsType}
|
|
109
|
+
pathParamsType={options.pathParamsType}
|
|
110
|
+
mutationKeyName={mutationKey.name}
|
|
111
|
+
/>
|
|
112
|
+
</>
|
|
113
|
+
)}
|
|
105
114
|
</File>
|
|
106
115
|
)
|
|
107
116
|
},
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import transformers from '@kubb/core/transformers'
|
|
2
1
|
import { pluginClientName } from '@kubb/plugin-client'
|
|
3
2
|
import { Client } from '@kubb/plugin-client/components'
|
|
4
3
|
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
@@ -20,7 +19,7 @@ export const queryGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
20
19
|
const { getSchemas, getName, getFile } = useOperationManager()
|
|
21
20
|
|
|
22
21
|
const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
|
|
23
|
-
const
|
|
22
|
+
const importPath = options.query ? options.query.importPath : '@tanstack/svelte-query'
|
|
24
23
|
|
|
25
24
|
const query = {
|
|
26
25
|
name: getName(operation, { type: 'function', prefix: 'create' }),
|
|
@@ -52,15 +51,13 @@ export const queryGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
52
51
|
schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
|
|
53
52
|
}
|
|
54
53
|
|
|
55
|
-
if (!isQuery
|
|
54
|
+
if (!isQuery) {
|
|
56
55
|
return null
|
|
57
56
|
}
|
|
58
57
|
|
|
59
58
|
return (
|
|
60
59
|
<File baseName={query.file.baseName} path={query.file.path} meta={query.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
61
60
|
{options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={query.file.path} path={zod.file.path} />}
|
|
62
|
-
<File.Import name={['createQuery', 'queryOptions']} path={options.query.importPath} />
|
|
63
|
-
<File.Import name={['QueryKey', 'WithRequired', 'CreateBaseQueryOptions', 'CreateQueryResult']} path={options.query.importPath} isTypeOnly />
|
|
64
61
|
<File.Import name={'client'} path={options.client.importPath} />
|
|
65
62
|
<File.Import name={['RequestConfig']} path={options.client.importPath} isTypeOnly />
|
|
66
63
|
{options.client.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />}
|
|
@@ -84,37 +81,48 @@ export const queryGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
84
81
|
operation={operation}
|
|
85
82
|
pathParamsType={options.pathParamsType}
|
|
86
83
|
typeSchemas={type.schemas}
|
|
87
|
-
|
|
84
|
+
transformer={options.queryKey}
|
|
88
85
|
/>
|
|
86
|
+
|
|
89
87
|
<Client
|
|
90
88
|
name={client.name}
|
|
91
89
|
isExportable={false}
|
|
92
90
|
isIndexable={false}
|
|
93
|
-
baseURL={options.baseURL}
|
|
91
|
+
baseURL={options.client.baseURL}
|
|
94
92
|
operation={operation}
|
|
95
93
|
typeSchemas={type.schemas}
|
|
96
94
|
zodSchemas={zod.schemas}
|
|
97
95
|
dataReturnType={options.client.dataReturnType}
|
|
96
|
+
paramsType={options.paramsType}
|
|
98
97
|
pathParamsType={options.pathParamsType}
|
|
99
98
|
parser={options.parser}
|
|
100
99
|
/>
|
|
100
|
+
<File.Import name={['queryOptions']} path={importPath} />
|
|
101
101
|
<QueryOptions
|
|
102
102
|
name={queryOptions.name}
|
|
103
103
|
clientName={client.name}
|
|
104
104
|
queryKeyName={queryKey.name}
|
|
105
105
|
typeSchemas={type.schemas}
|
|
106
|
+
paramsType={options.paramsType}
|
|
106
107
|
pathParamsType={options.pathParamsType}
|
|
107
108
|
/>
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
109
|
+
{options.query && (
|
|
110
|
+
<>
|
|
111
|
+
<File.Import name={['createQuery']} path={importPath} />
|
|
112
|
+
<File.Import name={['QueryKey', 'CreateBaseQueryOptions', 'CreateQueryResult']} path={importPath} isTypeOnly />
|
|
113
|
+
<Query
|
|
114
|
+
name={query.name}
|
|
115
|
+
queryOptionsName={queryOptions.name}
|
|
116
|
+
typeSchemas={type.schemas}
|
|
117
|
+
pathParamsType={options.pathParamsType}
|
|
118
|
+
operation={operation}
|
|
119
|
+
paramsType={options.paramsType}
|
|
120
|
+
dataReturnType={options.client.dataReturnType}
|
|
121
|
+
queryKeyName={queryKey.name}
|
|
122
|
+
queryKeyTypeName={queryKey.typeName}
|
|
123
|
+
/>
|
|
124
|
+
</>
|
|
125
|
+
)}
|
|
118
126
|
</File>
|
|
119
127
|
)
|
|
120
128
|
},
|
package/src/plugin.ts
CHANGED
|
@@ -2,7 +2,6 @@ import path from 'node:path'
|
|
|
2
2
|
|
|
3
3
|
import { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'
|
|
4
4
|
import { camelCase, pascalCase } from '@kubb/core/transformers'
|
|
5
|
-
import { renderTemplate } from '@kubb/core/utils'
|
|
6
5
|
import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
|
|
7
6
|
|
|
8
7
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
@@ -10,6 +9,7 @@ import { pluginZodName } from '@kubb/plugin-zod'
|
|
|
10
9
|
|
|
11
10
|
import type { Plugin } from '@kubb/core'
|
|
12
11
|
import type { PluginOas } from '@kubb/plugin-oas'
|
|
12
|
+
import { MutationKey, QueryKey } from './components'
|
|
13
13
|
import { mutationGenerator, queryGenerator } from './generators'
|
|
14
14
|
import type { PluginSvelteQuery } from './types.ts'
|
|
15
15
|
|
|
@@ -24,9 +24,12 @@ export const pluginSvelteQuery = createPlugin<PluginSvelteQuery>((options) => {
|
|
|
24
24
|
override = [],
|
|
25
25
|
parser = 'client',
|
|
26
26
|
transformers = {},
|
|
27
|
+
paramsType = 'inline',
|
|
27
28
|
pathParamsType = 'inline',
|
|
28
29
|
mutation = {},
|
|
29
30
|
query = {},
|
|
31
|
+
mutationKey = MutationKey.getTransformer,
|
|
32
|
+
queryKey = QueryKey.getTransformer,
|
|
30
33
|
generators = [queryGenerator, mutationGenerator].filter(Boolean),
|
|
31
34
|
} = options
|
|
32
35
|
|
|
@@ -34,26 +37,26 @@ export const pluginSvelteQuery = createPlugin<PluginSvelteQuery>((options) => {
|
|
|
34
37
|
name: pluginSvelteQueryName,
|
|
35
38
|
options: {
|
|
36
39
|
output,
|
|
37
|
-
baseURL: undefined,
|
|
38
40
|
client: {
|
|
39
41
|
importPath: '@kubb/plugin-client/client',
|
|
40
42
|
dataReturnType: 'data',
|
|
41
43
|
pathParamsType: 'inline',
|
|
42
44
|
...options.client,
|
|
43
45
|
},
|
|
46
|
+
queryKey,
|
|
44
47
|
query: {
|
|
45
|
-
key: (key: unknown[]) => key,
|
|
46
48
|
methods: ['get'],
|
|
47
49
|
importPath: '@tanstack/svelte-query',
|
|
48
50
|
...query,
|
|
49
51
|
},
|
|
52
|
+
mutationKey,
|
|
50
53
|
mutation: {
|
|
51
|
-
key: (key: unknown[]) => key,
|
|
52
54
|
methods: ['post', 'put', 'patch', 'delete'],
|
|
53
55
|
importPath: '@tanstack/svelte-query',
|
|
54
56
|
...mutation,
|
|
55
57
|
},
|
|
56
|
-
|
|
58
|
+
paramsType,
|
|
59
|
+
pathParamsType: paramsType === 'object' ? 'object' : pathParamsType,
|
|
57
60
|
parser,
|
|
58
61
|
},
|
|
59
62
|
pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
|
|
@@ -103,22 +106,20 @@ export const pluginSvelteQuery = createPlugin<PluginSvelteQuery>((options) => {
|
|
|
103
106
|
const mode = FileManager.getMode(path.resolve(root, output.path))
|
|
104
107
|
const baseURL = await swaggerPlugin.context.getBaseURL()
|
|
105
108
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
},
|
|
121
|
-
)
|
|
109
|
+
if (baseURL) {
|
|
110
|
+
this.plugin.options.client.baseURL = baseURL
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
114
|
+
oas,
|
|
115
|
+
pluginManager: this.pluginManager,
|
|
116
|
+
plugin: this.plugin,
|
|
117
|
+
contentType: swaggerPlugin.context.contentType,
|
|
118
|
+
exclude,
|
|
119
|
+
include,
|
|
120
|
+
override,
|
|
121
|
+
mode,
|
|
122
|
+
})
|
|
122
123
|
|
|
123
124
|
const files = await operationGenerator.build(...generators)
|
|
124
125
|
await this.addFile(...files)
|
package/src/types.ts
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
2
2
|
|
|
3
|
-
import type { HttpMethod } from '@kubb/oas'
|
|
3
|
+
import type { HttpMethod, Operation } from '@kubb/oas'
|
|
4
4
|
import type { PluginClient } from '@kubb/plugin-client'
|
|
5
|
-
import type { Exclude, Generator, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
5
|
+
import type { Exclude, Generator, Include, OperationSchemas, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
6
|
+
import type { PluginReactQuery } from '@kubb/plugin-react-query'
|
|
7
|
+
|
|
8
|
+
type TransformerProps = {
|
|
9
|
+
operation: Operation
|
|
10
|
+
schemas: OperationSchemas
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type Transformer = (props: TransformerProps) => unknown[]
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Customize the queryKey
|
|
17
|
+
*/
|
|
18
|
+
type QueryKey = Transformer
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Customize the mutationKey
|
|
22
|
+
*/
|
|
23
|
+
type MutationKey = Transformer
|
|
6
24
|
|
|
7
25
|
type Query = {
|
|
8
|
-
/**
|
|
9
|
-
* Customize the queryKey, here you can specify a suffix.
|
|
10
|
-
*/
|
|
11
|
-
key: (key: unknown[]) => unknown[]
|
|
12
26
|
/**
|
|
13
27
|
* Define which HttpMethods can be used for queries
|
|
14
28
|
* @default ['get']
|
|
@@ -25,10 +39,6 @@ type Query = {
|
|
|
25
39
|
}
|
|
26
40
|
|
|
27
41
|
type Mutation = {
|
|
28
|
-
/**
|
|
29
|
-
* Customize the queryKey, here you can specify a suffix.
|
|
30
|
-
*/
|
|
31
|
-
key: (key: unknown[]) => unknown[]
|
|
32
42
|
/**
|
|
33
43
|
* Define which HttpMethods can be used for mutations
|
|
34
44
|
* @default ['post', 'put', 'delete']
|
|
@@ -55,7 +65,7 @@ export type Options = {
|
|
|
55
65
|
*/
|
|
56
66
|
group?: Group
|
|
57
67
|
|
|
58
|
-
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath'>
|
|
68
|
+
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>
|
|
59
69
|
|
|
60
70
|
/**
|
|
61
71
|
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
@@ -69,6 +79,13 @@ export type Options = {
|
|
|
69
79
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
70
80
|
*/
|
|
71
81
|
override?: Array<Override<ResolvedOptions>>
|
|
82
|
+
/**
|
|
83
|
+
* How to pass your params
|
|
84
|
+
* - 'object' will return the params and pathParams as an object.
|
|
85
|
+
* - 'inline' will return the params as comma separated params.
|
|
86
|
+
* @default 'inline'
|
|
87
|
+
*/
|
|
88
|
+
paramsType?: 'object' | 'inline'
|
|
72
89
|
/**
|
|
73
90
|
* How to pass your pathParams.
|
|
74
91
|
* - 'object' will return the pathParams as an object.
|
|
@@ -76,16 +93,18 @@ export type Options = {
|
|
|
76
93
|
* @default 'inline'
|
|
77
94
|
*/
|
|
78
95
|
pathParamsType?: PluginClient['options']['pathParamsType']
|
|
96
|
+
queryKey?: QueryKey
|
|
79
97
|
/**
|
|
80
98
|
* Override some useQuery behaviours.
|
|
81
99
|
*/
|
|
82
100
|
query?: Partial<Query> | false
|
|
101
|
+
mutationKey?: MutationKey
|
|
83
102
|
/**
|
|
84
103
|
* Override some useMutation behaviours.
|
|
85
104
|
*/
|
|
86
105
|
mutation?: Mutation | false
|
|
87
106
|
/**
|
|
88
|
-
* Which parser
|
|
107
|
+
* Which parser should be used before returning the data to `@tanstack/query`.
|
|
89
108
|
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
90
109
|
*/
|
|
91
110
|
parser?: PluginClient['options']['parser']
|
|
@@ -103,11 +122,13 @@ export type Options = {
|
|
|
103
122
|
|
|
104
123
|
type ResolvedOptions = {
|
|
105
124
|
output: Output
|
|
106
|
-
|
|
107
|
-
client: Required<NonNullable<PluginSvelteQuery['options']['client']>>
|
|
125
|
+
client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & { baseURL?: string }
|
|
108
126
|
parser: Required<NonNullable<Options['parser']>>
|
|
127
|
+
paramsType: NonNullable<Options['paramsType']>
|
|
109
128
|
pathParamsType: NonNullable<Options['pathParamsType']>
|
|
129
|
+
queryKey: QueryKey | undefined
|
|
110
130
|
query: NonNullable<Required<Query>> | false
|
|
131
|
+
mutationKey: MutationKey | undefined
|
|
111
132
|
mutation: NonNullable<Required<Mutation>> | false
|
|
112
133
|
}
|
|
113
134
|
|