@kubb/plugin-svelte-query 3.0.0-beta.1 → 3.0.0-beta.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-IYE4XII3.cjs → chunk-C3XFYLKR.cjs} +32 -23
- package/dist/chunk-C3XFYLKR.cjs.map +1 -0
- package/dist/{chunk-WAAKXO6O.cjs → chunk-HUR476BL.cjs} +125 -21
- package/dist/chunk-HUR476BL.cjs.map +1 -0
- package/dist/{chunk-B7GVNGYU.js → chunk-LSV2AJSI.js} +125 -21
- package/dist/chunk-LSV2AJSI.js.map +1 -0
- package/dist/{chunk-STYJ2DL3.js → chunk-PCNLFEZJ.js} +23 -14
- package/dist/chunk-PCNLFEZJ.js.map +1 -0
- package/dist/components.cjs +6 -6
- package/dist/components.d.cts +11 -6
- package/dist/components.d.ts +11 -6
- 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 +19 -22
- 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 +18 -21
- package/dist/index.js.map +1 -1
- package/dist/types-Co8a9Sr5.d.cts +347 -0
- package/dist/types-Co8a9Sr5.d.ts +347 -0
- package/package.json +14 -14
- package/src/components/Mutation.tsx +7 -3
- package/src/components/Query.tsx +62 -6
- package/src/components/QueryOptions.tsx +47 -7
- package/src/generators/__snapshots__/findByTagsObject.ts +60 -0
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +1 -3
- package/src/generators/mutationGenerator.tsx +3 -2
- package/src/generators/queryGenerator.tsx +4 -2
- package/src/plugin.ts +17 -19
- package/src/types.ts +17 -21
- 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-DJAXpPpT.d.cts +0 -201
- package/dist/types-DJAXpPpT.d.ts +0 -201
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-svelte-query",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.11",
|
|
4
4
|
"description": "Generator svelte-query hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"faker",
|
|
@@ -62,24 +62,24 @@
|
|
|
62
62
|
"!/**/__tests__/**"
|
|
63
63
|
],
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@kubb/core": "3.0.0-beta.
|
|
66
|
-
"@kubb/fs": "3.0.0-beta.
|
|
67
|
-
"@kubb/oas": "3.0.0-beta.
|
|
68
|
-
"@kubb/plugin-oas": "3.0.0-beta.
|
|
69
|
-
"@kubb/plugin-ts": "3.0.0-beta.
|
|
70
|
-
"@kubb/plugin-zod": "3.0.0-beta.
|
|
71
|
-
"@kubb/react": "3.0.0-beta.
|
|
65
|
+
"@kubb/core": "3.0.0-beta.11",
|
|
66
|
+
"@kubb/fs": "3.0.0-beta.11",
|
|
67
|
+
"@kubb/oas": "3.0.0-beta.11",
|
|
68
|
+
"@kubb/plugin-oas": "3.0.0-beta.11",
|
|
69
|
+
"@kubb/plugin-ts": "3.0.0-beta.11",
|
|
70
|
+
"@kubb/plugin-zod": "3.0.0-beta.11",
|
|
71
|
+
"@kubb/react": "3.0.0-beta.11"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@types/react": "^18.3.
|
|
74
|
+
"@types/react": "^18.3.12",
|
|
75
75
|
"react": "^18.3.1",
|
|
76
|
-
"tsup": "^8.3.
|
|
77
|
-
"typescript": "^5.6.
|
|
78
|
-
"@kubb/config-ts": "3.0.0-beta.
|
|
79
|
-
"@kubb/config-tsup": "3.0.0-beta.
|
|
76
|
+
"tsup": "^8.3.5",
|
|
77
|
+
"typescript": "^5.6.3",
|
|
78
|
+
"@kubb/config-ts": "3.0.0-beta.11",
|
|
79
|
+
"@kubb/config-tsup": "3.0.0-beta.11"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
|
-
"@kubb/react": "3.0.0-beta.
|
|
82
|
+
"@kubb/react": "3.0.0-beta.11"
|
|
83
83
|
},
|
|
84
84
|
"engines": {
|
|
85
85
|
"node": ">=20"
|
|
@@ -19,6 +19,7 @@ type Props = {
|
|
|
19
19
|
mutationKeyName: string
|
|
20
20
|
typeSchemas: OperationSchemas
|
|
21
21
|
operation: Operation
|
|
22
|
+
paramsType: PluginSvelteQuery['resolvedOptions']['paramsType']
|
|
22
23
|
dataReturnType: PluginSvelteQuery['resolvedOptions']['client']['dataReturnType']
|
|
23
24
|
pathParamsType: PluginSvelteQuery['resolvedOptions']['pathParamsType']
|
|
24
25
|
}
|
|
@@ -58,7 +59,7 @@ function getParams({ dataReturnType, typeSchemas }: GetParamsProps) {
|
|
|
58
59
|
options: {
|
|
59
60
|
type: `
|
|
60
61
|
{
|
|
61
|
-
mutation?: CreateMutationOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', `{${TRequest}}`].join(', ')}>,
|
|
62
|
+
mutation?: CreateMutationOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', TRequest ? `{${TRequest}}` : undefined].filter(Boolean).join(', ')}>,
|
|
62
63
|
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'},
|
|
63
64
|
}
|
|
64
65
|
`,
|
|
@@ -67,7 +68,7 @@ function getParams({ dataReturnType, typeSchemas }: GetParamsProps) {
|
|
|
67
68
|
})
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
export function Mutation({ name, clientName, pathParamsType, dataReturnType, typeSchemas, operation, mutationKeyName }: Props): ReactNode {
|
|
71
|
+
export function Mutation({ name, clientName, paramsType, pathParamsType, dataReturnType, typeSchemas, operation, mutationKeyName }: Props): ReactNode {
|
|
71
72
|
const mutationKeyParams = MutationKey.getParams({
|
|
72
73
|
pathParamsType,
|
|
73
74
|
typeSchemas,
|
|
@@ -80,6 +81,7 @@ export function Mutation({ name, clientName, pathParamsType, dataReturnType, typ
|
|
|
80
81
|
})
|
|
81
82
|
|
|
82
83
|
const clientParams = Client.getParams({
|
|
84
|
+
paramsType,
|
|
83
85
|
typeSchemas,
|
|
84
86
|
pathParamsType,
|
|
85
87
|
})
|
|
@@ -124,7 +126,9 @@ export function Mutation({ name, clientName, pathParamsType, dataReturnType, typ
|
|
|
124
126
|
|
|
125
127
|
const TRequest = mutationParams.toConstructor({ valueAsType: true })
|
|
126
128
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
127
|
-
const generics = [TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', `{${TRequest}}`]
|
|
129
|
+
const generics = [TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', TRequest ? `{${TRequest}}` : undefined]
|
|
130
|
+
.filter(Boolean)
|
|
131
|
+
.join(', ')
|
|
128
132
|
|
|
129
133
|
return (
|
|
130
134
|
<File.Source name={name} isExportable isIndexable>
|
package/src/components/Query.tsx
CHANGED
|
@@ -18,24 +18,68 @@ type Props = {
|
|
|
18
18
|
queryKeyTypeName: string
|
|
19
19
|
typeSchemas: OperationSchemas
|
|
20
20
|
operation: Operation
|
|
21
|
+
paramsType: PluginSvelteQuery['resolvedOptions']['paramsType']
|
|
21
22
|
pathParamsType: PluginSvelteQuery['resolvedOptions']['pathParamsType']
|
|
22
23
|
dataReturnType: PluginSvelteQuery['resolvedOptions']['client']['dataReturnType']
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
type GetParamsProps = {
|
|
27
|
+
paramsType: PluginSvelteQuery['resolvedOptions']['paramsType']
|
|
26
28
|
pathParamsType: PluginSvelteQuery['resolvedOptions']['pathParamsType']
|
|
27
29
|
dataReturnType: PluginSvelteQuery['resolvedOptions']['client']['dataReturnType']
|
|
28
30
|
typeSchemas: OperationSchemas
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
function getParams({ pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
|
|
33
|
+
function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
|
|
32
34
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
33
35
|
|
|
36
|
+
if (paramsType === 'object') {
|
|
37
|
+
return FunctionParams.factory({
|
|
38
|
+
data: {
|
|
39
|
+
mode: 'object',
|
|
40
|
+
children: {
|
|
41
|
+
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
42
|
+
data: typeSchemas.request?.name
|
|
43
|
+
? {
|
|
44
|
+
type: typeSchemas.request?.name,
|
|
45
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
46
|
+
}
|
|
47
|
+
: undefined,
|
|
48
|
+
params: typeSchemas.queryParams?.name
|
|
49
|
+
? {
|
|
50
|
+
type: typeSchemas.queryParams?.name,
|
|
51
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
52
|
+
}
|
|
53
|
+
: undefined,
|
|
54
|
+
headers: typeSchemas.headerParams?.name
|
|
55
|
+
? {
|
|
56
|
+
type: typeSchemas.headerParams?.name,
|
|
57
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
58
|
+
}
|
|
59
|
+
: undefined,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
options: {
|
|
63
|
+
type: `
|
|
64
|
+
{
|
|
65
|
+
query?: Partial<CreateBaseQueryOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', 'TData', 'TQueryData', 'TQueryKey'].join(', ')}>>,
|
|
66
|
+
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'}
|
|
67
|
+
}
|
|
68
|
+
`,
|
|
69
|
+
default: '{}',
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
34
74
|
return FunctionParams.factory({
|
|
35
|
-
pathParams:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
75
|
+
pathParams: typeSchemas.pathParams?.name
|
|
76
|
+
? {
|
|
77
|
+
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
78
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
79
|
+
type: typeSchemas.pathParams?.name,
|
|
80
|
+
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
81
|
+
}
|
|
82
|
+
: undefined,
|
|
39
83
|
data: typeSchemas.request?.name
|
|
40
84
|
? {
|
|
41
85
|
type: typeSchemas.request?.name,
|
|
@@ -66,7 +110,17 @@ function getParams({ pathParamsType, dataReturnType, typeSchemas }: GetParamsPro
|
|
|
66
110
|
})
|
|
67
111
|
}
|
|
68
112
|
|
|
69
|
-
export function Query({
|
|
113
|
+
export function Query({
|
|
114
|
+
name,
|
|
115
|
+
queryKeyTypeName,
|
|
116
|
+
queryOptionsName,
|
|
117
|
+
queryKeyName,
|
|
118
|
+
paramsType,
|
|
119
|
+
pathParamsType,
|
|
120
|
+
dataReturnType,
|
|
121
|
+
typeSchemas,
|
|
122
|
+
operation,
|
|
123
|
+
}: Props): ReactNode {
|
|
70
124
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
71
125
|
const returnType = `CreateQueryResult<${['TData', typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'].join(', ')}> & { queryKey: TQueryKey }`
|
|
72
126
|
const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`]
|
|
@@ -76,10 +130,12 @@ export function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
76
130
|
typeSchemas,
|
|
77
131
|
})
|
|
78
132
|
const queryOptionsParams = QueryOptions.getParams({
|
|
133
|
+
paramsType,
|
|
79
134
|
pathParamsType,
|
|
80
135
|
typeSchemas,
|
|
81
136
|
})
|
|
82
137
|
const params = getParams({
|
|
138
|
+
paramsType,
|
|
83
139
|
pathParamsType,
|
|
84
140
|
dataReturnType,
|
|
85
141
|
typeSchemas,
|
|
@@ -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
|
})
|
|
@@ -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 { createQuery, queryOptions } 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
|
+
}
|
|
@@ -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'
|
|
@@ -84,11 +83,12 @@ export const mutationGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
84
83
|
name={client.name}
|
|
85
84
|
isExportable={false}
|
|
86
85
|
isIndexable={false}
|
|
87
|
-
baseURL={options.baseURL}
|
|
86
|
+
baseURL={options.client.baseURL}
|
|
88
87
|
operation={operation}
|
|
89
88
|
typeSchemas={type.schemas}
|
|
90
89
|
zodSchemas={zod.schemas}
|
|
91
90
|
dataReturnType={options.client.dataReturnType}
|
|
91
|
+
paramsType={options.paramsType}
|
|
92
92
|
pathParamsType={options.pathParamsType}
|
|
93
93
|
parser={options.parser}
|
|
94
94
|
/>
|
|
@@ -99,6 +99,7 @@ export const mutationGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
99
99
|
typeSchemas={type.schemas}
|
|
100
100
|
operation={operation}
|
|
101
101
|
dataReturnType={options.client.dataReturnType}
|
|
102
|
+
paramsType={options.paramsType}
|
|
102
103
|
pathParamsType={options.pathParamsType}
|
|
103
104
|
mutationKeyName={mutationKey.name}
|
|
104
105
|
/>
|
|
@@ -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'
|
|
@@ -90,11 +89,12 @@ export const queryGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
90
89
|
name={client.name}
|
|
91
90
|
isExportable={false}
|
|
92
91
|
isIndexable={false}
|
|
93
|
-
baseURL={options.baseURL}
|
|
92
|
+
baseURL={options.client.baseURL}
|
|
94
93
|
operation={operation}
|
|
95
94
|
typeSchemas={type.schemas}
|
|
96
95
|
zodSchemas={zod.schemas}
|
|
97
96
|
dataReturnType={options.client.dataReturnType}
|
|
97
|
+
paramsType={options.paramsType}
|
|
98
98
|
pathParamsType={options.pathParamsType}
|
|
99
99
|
parser={options.parser}
|
|
100
100
|
/>
|
|
@@ -103,6 +103,7 @@ export const queryGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
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
|
<Query
|
|
@@ -111,6 +112,7 @@ export const queryGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
111
112
|
typeSchemas={type.schemas}
|
|
112
113
|
pathParamsType={options.pathParamsType}
|
|
113
114
|
operation={operation}
|
|
115
|
+
paramsType={options.paramsType}
|
|
114
116
|
dataReturnType={options.client.dataReturnType}
|
|
115
117
|
queryKeyName={queryKey.name}
|
|
116
118
|
queryKeyTypeName={queryKey.typeName}
|
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'
|
|
@@ -24,6 +23,7 @@ export const pluginSvelteQuery = createPlugin<PluginSvelteQuery>((options) => {
|
|
|
24
23
|
override = [],
|
|
25
24
|
parser = 'client',
|
|
26
25
|
transformers = {},
|
|
26
|
+
paramsType = 'inline',
|
|
27
27
|
pathParamsType = 'inline',
|
|
28
28
|
mutation = {},
|
|
29
29
|
query = {},
|
|
@@ -34,7 +34,6 @@ export const pluginSvelteQuery = createPlugin<PluginSvelteQuery>((options) => {
|
|
|
34
34
|
name: pluginSvelteQueryName,
|
|
35
35
|
options: {
|
|
36
36
|
output,
|
|
37
|
-
baseURL: undefined,
|
|
38
37
|
client: {
|
|
39
38
|
importPath: '@kubb/plugin-client/client',
|
|
40
39
|
dataReturnType: 'data',
|
|
@@ -53,7 +52,8 @@ export const pluginSvelteQuery = createPlugin<PluginSvelteQuery>((options) => {
|
|
|
53
52
|
importPath: '@tanstack/svelte-query',
|
|
54
53
|
...mutation,
|
|
55
54
|
},
|
|
56
|
-
|
|
55
|
+
paramsType,
|
|
56
|
+
pathParamsType: paramsType === 'object' ? 'object' : pathParamsType,
|
|
57
57
|
parser,
|
|
58
58
|
},
|
|
59
59
|
pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
|
|
@@ -103,22 +103,20 @@ export const pluginSvelteQuery = createPlugin<PluginSvelteQuery>((options) => {
|
|
|
103
103
|
const mode = FileManager.getMode(path.resolve(root, output.path))
|
|
104
104
|
const baseURL = await swaggerPlugin.context.getBaseURL()
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
},
|
|
121
|
-
)
|
|
106
|
+
if (baseURL) {
|
|
107
|
+
this.plugin.options.client.baseURL = baseURL
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
111
|
+
oas,
|
|
112
|
+
pluginManager: this.pluginManager,
|
|
113
|
+
plugin: this.plugin,
|
|
114
|
+
contentType: swaggerPlugin.context.contentType,
|
|
115
|
+
exclude,
|
|
116
|
+
include,
|
|
117
|
+
override,
|
|
118
|
+
mode,
|
|
119
|
+
})
|
|
122
120
|
|
|
123
121
|
const files = await operationGenerator.build(...generators)
|
|
124
122
|
await this.addFile(...files)
|
package/src/types.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@ku
|
|
|
3
3
|
import type { HttpMethod } from '@kubb/oas'
|
|
4
4
|
import type { PluginClient } from '@kubb/plugin-client'
|
|
5
5
|
import type { Exclude, Generator, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
6
|
+
import type { PluginReactQuery } from '@kubb/plugin-react-query'
|
|
6
7
|
|
|
7
8
|
type Query = {
|
|
8
9
|
/**
|
|
@@ -46,7 +47,8 @@ type Mutation = {
|
|
|
46
47
|
|
|
47
48
|
export type Options = {
|
|
48
49
|
/**
|
|
49
|
-
*
|
|
50
|
+
* Specify the export location for the files and define the behavior of the output
|
|
51
|
+
* @default { path: 'hooks', barrelType: 'named' }
|
|
50
52
|
*/
|
|
51
53
|
output?: Output
|
|
52
54
|
/**
|
|
@@ -54,17 +56,7 @@ export type Options = {
|
|
|
54
56
|
*/
|
|
55
57
|
group?: Group
|
|
56
58
|
|
|
57
|
-
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath'>
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* ReturnType that needs to be used when calling client().
|
|
61
|
-
*
|
|
62
|
-
* `Data` will return ResponseConfig[data].
|
|
63
|
-
*
|
|
64
|
-
* `Full` will return ResponseConfig.
|
|
65
|
-
* @default `'data'`
|
|
66
|
-
* @private
|
|
67
|
-
*/
|
|
59
|
+
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>
|
|
68
60
|
|
|
69
61
|
/**
|
|
70
62
|
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
@@ -78,14 +70,18 @@ export type Options = {
|
|
|
78
70
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
79
71
|
*/
|
|
80
72
|
override?: Array<Override<ResolvedOptions>>
|
|
73
|
+
/**
|
|
74
|
+
* How to pass your params
|
|
75
|
+
* - 'object' will return the params and pathParams as an object.
|
|
76
|
+
* - 'inline' will return the params as comma separated params.
|
|
77
|
+
* @default 'inline'
|
|
78
|
+
*/
|
|
79
|
+
paramsType?: 'object' | 'inline'
|
|
81
80
|
/**
|
|
82
81
|
* How to pass your pathParams.
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* `inline` will return the pathParams as comma separated params.
|
|
87
|
-
* @default `'inline'`
|
|
88
|
-
* @private
|
|
82
|
+
* - 'object' will return the pathParams as an object.
|
|
83
|
+
* - 'inline' will return the pathParams as comma separated params.
|
|
84
|
+
* @default 'inline'
|
|
89
85
|
*/
|
|
90
86
|
pathParamsType?: PluginClient['options']['pathParamsType']
|
|
91
87
|
/**
|
|
@@ -97,7 +93,7 @@ export type Options = {
|
|
|
97
93
|
*/
|
|
98
94
|
mutation?: Mutation | false
|
|
99
95
|
/**
|
|
100
|
-
* Which parser
|
|
96
|
+
* Which parser should be used before returning the data to `@tanstack/query`.
|
|
101
97
|
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
102
98
|
*/
|
|
103
99
|
parser?: PluginClient['options']['parser']
|
|
@@ -115,9 +111,9 @@ export type Options = {
|
|
|
115
111
|
|
|
116
112
|
type ResolvedOptions = {
|
|
117
113
|
output: Output
|
|
118
|
-
|
|
119
|
-
client: Required<NonNullable<PluginSvelteQuery['options']['client']>>
|
|
114
|
+
client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & { baseURL?: string }
|
|
120
115
|
parser: Required<NonNullable<Options['parser']>>
|
|
116
|
+
paramsType: NonNullable<Options['paramsType']>
|
|
121
117
|
pathParamsType: NonNullable<Options['pathParamsType']>
|
|
122
118
|
query: NonNullable<Required<Query>> | false
|
|
123
119
|
mutation: NonNullable<Required<Mutation>> | false
|