@kubb/plugin-vue-query 3.0.0-beta.1 → 3.0.0-beta.10
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-FSQSBTBH.cjs → chunk-5MY3SE2R.cjs} +220 -18
- package/dist/chunk-5MY3SE2R.cjs.map +1 -0
- package/dist/{chunk-V6YETPDM.js → chunk-DWWRCRGY.js} +220 -18
- package/dist/chunk-DWWRCRGY.js.map +1 -0
- package/dist/{chunk-S7SEIU2L.cjs → chunk-PGNSMLGU.cjs} +31 -20
- package/dist/chunk-PGNSMLGU.cjs.map +1 -0
- package/dist/{chunk-VAPLKIAH.js → chunk-YQOJHRKU.js} +18 -7
- package/dist/chunk-YQOJHRKU.js.map +1 -0
- package/dist/components.cjs +8 -8
- package/dist/components.d.cts +19 -10
- package/dist/components.d.ts +19 -10
- package/dist/components.js +1 -1
- package/dist/generators.cjs +5 -5
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +2 -2
- package/dist/index.cjs +6 -5
- 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 +5 -4
- package/dist/index.js.map +1 -1
- package/dist/{types-FQruQAe4.d.cts → types-Dx6yZliF.d.cts} +30 -31
- package/dist/{types-FQruQAe4.d.ts → types-Dx6yZliF.d.ts} +30 -31
- package/package.json +14 -14
- package/src/components/InfiniteQuery.tsx +54 -1
- package/src/components/InfiniteQueryOptions.tsx +49 -2
- package/src/components/Mutation.tsx +7 -3
- package/src/components/Query.tsx +65 -2
- package/src/components/QueryOptions.tsx +50 -3
- package/src/generators/__snapshots__/findByTagsObject.ts +62 -0
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +1 -3
- package/src/generators/infiniteQueryGenerator.tsx +3 -1
- package/src/generators/mutationGenerator.tsx +2 -1
- package/src/generators/queryGenerator.tsx +3 -1
- package/src/plugin.ts +3 -2
- package/src/types.ts +14 -18
- package/dist/chunk-FSQSBTBH.cjs.map +0 -1
- package/dist/chunk-S7SEIU2L.cjs.map +0 -1
- package/dist/chunk-V6YETPDM.js.map +0 -1
- package/dist/chunk-VAPLKIAH.js.map +0 -1
|
@@ -26,7 +26,7 @@ type Options$1 = {
|
|
|
26
26
|
override?: Array<Override<ResolvedOptions$1>>;
|
|
27
27
|
/**
|
|
28
28
|
* Create `operations.ts` file with all operations grouped by methods.
|
|
29
|
-
* @default
|
|
29
|
+
* @default false
|
|
30
30
|
*/
|
|
31
31
|
operations?: boolean;
|
|
32
32
|
/**
|
|
@@ -38,27 +38,28 @@ type Options$1 = {
|
|
|
38
38
|
importPath?: string;
|
|
39
39
|
/**
|
|
40
40
|
* ReturnType that will be used when calling the client.
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* `Full` will return ResponseConfig.
|
|
45
|
-
* @default `'data'`
|
|
46
|
-
* @private
|
|
41
|
+
* - 'data' will return ResponseConfig[data].
|
|
42
|
+
* - 'full' will return ResponseConfig.
|
|
43
|
+
* @default 'data'
|
|
47
44
|
*/
|
|
48
45
|
dataReturnType?: 'data' | 'full';
|
|
46
|
+
/**
|
|
47
|
+
* How to pass your params
|
|
48
|
+
* - 'object' will return the params and pathParams as an object.
|
|
49
|
+
* - 'inline' will return the params as comma separated params.
|
|
50
|
+
* @default 'inline'
|
|
51
|
+
*/
|
|
52
|
+
paramsType?: 'object' | 'inline';
|
|
49
53
|
/**
|
|
50
54
|
* How to pass your pathParams.
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* `inline` will return the pathParams as comma separated params.
|
|
55
|
-
* @default `'inline'`
|
|
56
|
-
* @private
|
|
55
|
+
* - 'object' will return the pathParams as an object.
|
|
56
|
+
* - 'inline' will return the pathParams as comma separated params.
|
|
57
|
+
* @default 'inline'
|
|
57
58
|
*/
|
|
58
59
|
pathParamsType?: 'object' | 'inline';
|
|
59
60
|
/**
|
|
60
61
|
* Which parser can be used before returning the data
|
|
61
|
-
*
|
|
62
|
+
* - 'zod' will use `@kubb/plugin-zod` to parse the data.
|
|
62
63
|
* @default 'client'
|
|
63
64
|
*/
|
|
64
65
|
parser?: 'client' | 'zod';
|
|
@@ -81,6 +82,7 @@ type ResolvedOptions$1 = {
|
|
|
81
82
|
importPath: NonNullable<Options$1['importPath']>;
|
|
82
83
|
dataReturnType: NonNullable<Options$1['dataReturnType']>;
|
|
83
84
|
pathParamsType: NonNullable<Options$1['pathParamsType']>;
|
|
85
|
+
paramsType: NonNullable<Options$1['paramsType']>;
|
|
84
86
|
};
|
|
85
87
|
type PluginClient = PluginFactoryOptions<'plugin-client', Options$1, ResolvedOptions$1, never, ResolvePathOptions>;
|
|
86
88
|
|
|
@@ -140,7 +142,8 @@ type Infinite = {
|
|
|
140
142
|
};
|
|
141
143
|
type Options = {
|
|
142
144
|
/**
|
|
143
|
-
*
|
|
145
|
+
* Specify the export location for the files and define the behavior of the output
|
|
146
|
+
* @default { path: 'hooks', barrelType: 'named' }
|
|
144
147
|
*/
|
|
145
148
|
output?: Output;
|
|
146
149
|
/**
|
|
@@ -148,15 +151,6 @@ type Options = {
|
|
|
148
151
|
*/
|
|
149
152
|
group?: Group;
|
|
150
153
|
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath'>;
|
|
151
|
-
/**
|
|
152
|
-
* ReturnType that needs to be used when calling client().
|
|
153
|
-
*
|
|
154
|
-
* `Data` will return ResponseConfig[data].
|
|
155
|
-
*
|
|
156
|
-
* `Full` will return ResponseConfig.
|
|
157
|
-
* @default `'data'`
|
|
158
|
-
* @private
|
|
159
|
-
*/
|
|
160
154
|
/**
|
|
161
155
|
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
162
156
|
*/
|
|
@@ -169,14 +163,18 @@ type Options = {
|
|
|
169
163
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
170
164
|
*/
|
|
171
165
|
override?: Array<Override<ResolvedOptions>>;
|
|
166
|
+
/**
|
|
167
|
+
* How to pass your params
|
|
168
|
+
* - 'object' will return the params and pathParams as an object.
|
|
169
|
+
* - 'inline' will return the params as comma separated params.
|
|
170
|
+
* @default 'inline'
|
|
171
|
+
*/
|
|
172
|
+
paramsType?: 'object' | 'inline';
|
|
172
173
|
/**
|
|
173
174
|
* How to pass your pathParams.
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
* `inline` will return the pathParams as comma separated params.
|
|
178
|
-
* @default `'inline'`
|
|
179
|
-
* @private
|
|
175
|
+
* - 'object' will return the pathParams as an object.
|
|
176
|
+
* - 'inline' will return the pathParams as comma separated params.
|
|
177
|
+
* @default 'inline'
|
|
180
178
|
*/
|
|
181
179
|
pathParamsType?: PluginClient['options']['pathParamsType'];
|
|
182
180
|
/**
|
|
@@ -192,7 +190,7 @@ type Options = {
|
|
|
192
190
|
*/
|
|
193
191
|
mutation?: Mutation | false;
|
|
194
192
|
/**
|
|
195
|
-
* Which parser
|
|
193
|
+
* Which parser should be used before returning the data to `@tanstack/query`.
|
|
196
194
|
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
197
195
|
*/
|
|
198
196
|
parser?: PluginClient['options']['parser'];
|
|
@@ -212,6 +210,7 @@ type ResolvedOptions = {
|
|
|
212
210
|
baseURL: string | undefined;
|
|
213
211
|
client: Required<NonNullable<PluginVueQuery['options']['client']>>;
|
|
214
212
|
parser: Required<NonNullable<Options['parser']>>;
|
|
213
|
+
paramsType: NonNullable<Options['paramsType']>;
|
|
215
214
|
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
216
215
|
/**
|
|
217
216
|
* Only used of infinite
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-vue-query",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.10",
|
|
4
4
|
"description": "Generator vue-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.10",
|
|
66
|
+
"@kubb/fs": "3.0.0-beta.10",
|
|
67
|
+
"@kubb/oas": "3.0.0-beta.10",
|
|
68
|
+
"@kubb/plugin-oas": "3.0.0-beta.10",
|
|
69
|
+
"@kubb/plugin-ts": "3.0.0-beta.10",
|
|
70
|
+
"@kubb/plugin-zod": "3.0.0-beta.10",
|
|
71
|
+
"@kubb/react": "3.0.0-beta.10"
|
|
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.10",
|
|
79
|
+
"@kubb/config-tsup": "3.0.0-beta.10"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
|
-
"@kubb/react": "3.0.0-beta.
|
|
82
|
+
"@kubb/react": "3.0.0-beta.10"
|
|
83
83
|
},
|
|
84
84
|
"engines": {
|
|
85
85
|
"node": ">=20"
|
|
@@ -18,22 +18,72 @@ type Props = {
|
|
|
18
18
|
queryKeyTypeName: string
|
|
19
19
|
typeSchemas: OperationSchemas
|
|
20
20
|
operation: Operation
|
|
21
|
+
paramsType: PluginVueQuery['resolvedOptions']['paramsType']
|
|
21
22
|
pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
|
|
22
23
|
dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
type GetParamsProps = {
|
|
27
|
+
paramsType: PluginVueQuery['resolvedOptions']['paramsType']
|
|
26
28
|
pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
|
|
27
29
|
dataReturnType: PluginVueQuery['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, {
|
|
42
|
+
typed: true,
|
|
43
|
+
override(item) {
|
|
44
|
+
return {
|
|
45
|
+
...item,
|
|
46
|
+
type: `MaybeRef<${item.type}>`,
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
}),
|
|
50
|
+
data: typeSchemas.request?.name
|
|
51
|
+
? {
|
|
52
|
+
type: `MaybeRef<${typeSchemas.request?.name}>`,
|
|
53
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
54
|
+
}
|
|
55
|
+
: undefined,
|
|
56
|
+
params: typeSchemas.queryParams?.name
|
|
57
|
+
? {
|
|
58
|
+
type: `MaybeRef<${typeSchemas.queryParams?.name}>`,
|
|
59
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
60
|
+
}
|
|
61
|
+
: undefined,
|
|
62
|
+
headers: typeSchemas.headerParams?.name
|
|
63
|
+
? {
|
|
64
|
+
type: `MaybeRef<${typeSchemas.headerParams?.name}>`,
|
|
65
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
66
|
+
}
|
|
67
|
+
: undefined,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
options: {
|
|
71
|
+
type: `
|
|
72
|
+
{
|
|
73
|
+
query?: Partial<InfiniteQueryObserverOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', 'TData', 'TQueryData', 'TQueryKey'].join(', ')}>>,
|
|
74
|
+
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'}
|
|
75
|
+
}
|
|
76
|
+
`,
|
|
77
|
+
default: '{}',
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
34
82
|
return FunctionParams.factory({
|
|
35
83
|
pathParams: {
|
|
36
84
|
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
85
|
+
type: typeSchemas.pathParams?.name,
|
|
86
|
+
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
37
87
|
children: getPathParams(typeSchemas.pathParams, {
|
|
38
88
|
typed: true,
|
|
39
89
|
override(item) {
|
|
@@ -79,6 +129,7 @@ export function InfiniteQuery({
|
|
|
79
129
|
queryKeyTypeName,
|
|
80
130
|
queryOptionsName,
|
|
81
131
|
queryKeyName,
|
|
132
|
+
paramsType,
|
|
82
133
|
pathParamsType,
|
|
83
134
|
dataReturnType,
|
|
84
135
|
typeSchemas,
|
|
@@ -93,10 +144,12 @@ export function InfiniteQuery({
|
|
|
93
144
|
typeSchemas,
|
|
94
145
|
})
|
|
95
146
|
const queryOptionsParams = QueryOptions.getParams({
|
|
147
|
+
paramsType,
|
|
96
148
|
pathParamsType,
|
|
97
149
|
typeSchemas,
|
|
98
150
|
})
|
|
99
151
|
const params = getParams({
|
|
152
|
+
paramsType,
|
|
100
153
|
pathParamsType,
|
|
101
154
|
dataReturnType,
|
|
102
155
|
typeSchemas,
|
|
@@ -14,6 +14,7 @@ type Props = {
|
|
|
14
14
|
clientName: string
|
|
15
15
|
queryKeyName: string
|
|
16
16
|
typeSchemas: OperationSchemas
|
|
17
|
+
paramsType: PluginVueQuery['resolvedOptions']['paramsType']
|
|
17
18
|
pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
|
|
18
19
|
dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
|
|
19
20
|
initialPageParam: Infinite['initialPageParam']
|
|
@@ -22,14 +23,58 @@ type Props = {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
type GetParamsProps = {
|
|
26
|
+
paramsType: PluginVueQuery['resolvedOptions']['paramsType']
|
|
25
27
|
pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
|
|
26
28
|
typeSchemas: OperationSchemas
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
31
|
+
function getParams({ paramsType, pathParamsType, typeSchemas }: GetParamsProps) {
|
|
32
|
+
if (paramsType === 'object') {
|
|
33
|
+
return FunctionParams.factory({
|
|
34
|
+
data: {
|
|
35
|
+
mode: 'object',
|
|
36
|
+
children: {
|
|
37
|
+
...getPathParams(typeSchemas.pathParams, {
|
|
38
|
+
typed: true,
|
|
39
|
+
override(item) {
|
|
40
|
+
return {
|
|
41
|
+
...item,
|
|
42
|
+
type: `MaybeRef<${item.type}>`,
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
}),
|
|
46
|
+
data: typeSchemas.request?.name
|
|
47
|
+
? {
|
|
48
|
+
type: `MaybeRef<${typeSchemas.request?.name}>`,
|
|
49
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
50
|
+
}
|
|
51
|
+
: undefined,
|
|
52
|
+
params: typeSchemas.queryParams?.name
|
|
53
|
+
? {
|
|
54
|
+
type: `MaybeRef<${typeSchemas.queryParams?.name}>`,
|
|
55
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
56
|
+
}
|
|
57
|
+
: undefined,
|
|
58
|
+
headers: typeSchemas.headerParams?.name
|
|
59
|
+
? {
|
|
60
|
+
type: `MaybeRef<${typeSchemas.queryParams?.name}>`,
|
|
61
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
62
|
+
}
|
|
63
|
+
: undefined,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
config: {
|
|
67
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>',
|
|
68
|
+
default: '{}',
|
|
69
|
+
},
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
30
73
|
return FunctionParams.factory({
|
|
31
74
|
pathParams: {
|
|
32
75
|
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
76
|
+
type: typeSchemas.pathParams?.name,
|
|
77
|
+
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
33
78
|
children: getPathParams(typeSchemas.pathParams, {
|
|
34
79
|
typed: true,
|
|
35
80
|
override(item) {
|
|
@@ -71,13 +116,15 @@ export function InfiniteQueryOptions({
|
|
|
71
116
|
initialPageParam,
|
|
72
117
|
cursorParam,
|
|
73
118
|
typeSchemas,
|
|
119
|
+
paramsType,
|
|
74
120
|
dataReturnType,
|
|
75
121
|
pathParamsType,
|
|
76
122
|
queryParam,
|
|
77
123
|
queryKeyName,
|
|
78
124
|
}: Props): ReactNode {
|
|
79
|
-
const params = getParams({ pathParamsType, typeSchemas })
|
|
125
|
+
const params = getParams({ paramsType, pathParamsType, typeSchemas })
|
|
80
126
|
const clientParams = Client.getParams({
|
|
127
|
+
paramsType,
|
|
81
128
|
typeSchemas,
|
|
82
129
|
pathParamsType,
|
|
83
130
|
})
|
|
@@ -19,6 +19,7 @@ type Props = {
|
|
|
19
19
|
mutationKeyName: string
|
|
20
20
|
typeSchemas: OperationSchemas
|
|
21
21
|
operation: Operation
|
|
22
|
+
paramsType: PluginVueQuery['resolvedOptions']['paramsType']
|
|
22
23
|
dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
|
|
23
24
|
pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
|
|
24
25
|
}
|
|
@@ -66,7 +67,7 @@ function getParams({ dataReturnType, typeSchemas }: GetParamsProps) {
|
|
|
66
67
|
options: {
|
|
67
68
|
type: `
|
|
68
69
|
{
|
|
69
|
-
mutation?: MutationObserverOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', `{${TRequest}}`].join(', ')}>,
|
|
70
|
+
mutation?: MutationObserverOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', TRequest ? `{${TRequest}}` : undefined].filter(Boolean).join(', ')}>,
|
|
70
71
|
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'},
|
|
71
72
|
}
|
|
72
73
|
`,
|
|
@@ -75,7 +76,7 @@ function getParams({ dataReturnType, typeSchemas }: GetParamsProps) {
|
|
|
75
76
|
})
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
export function Mutation({ name, clientName, pathParamsType, dataReturnType, typeSchemas, operation, mutationKeyName }: Props): ReactNode {
|
|
79
|
+
export function Mutation({ name, clientName, paramsType, pathParamsType, dataReturnType, typeSchemas, operation, mutationKeyName }: Props): ReactNode {
|
|
79
80
|
const mutationKeyParams = MutationKey.getParams({
|
|
80
81
|
pathParamsType,
|
|
81
82
|
typeSchemas,
|
|
@@ -88,6 +89,7 @@ export function Mutation({ name, clientName, pathParamsType, dataReturnType, typ
|
|
|
88
89
|
})
|
|
89
90
|
|
|
90
91
|
const clientParams = Client.getParams({
|
|
92
|
+
paramsType,
|
|
91
93
|
typeSchemas,
|
|
92
94
|
pathParamsType,
|
|
93
95
|
})
|
|
@@ -133,7 +135,9 @@ export function Mutation({ name, clientName, pathParamsType, dataReturnType, typ
|
|
|
133
135
|
|
|
134
136
|
const TRequest = mutationParams.toConstructor({ valueAsType: true })
|
|
135
137
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
136
|
-
const generics = [TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', `{${TRequest}}`]
|
|
138
|
+
const generics = [TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', TRequest ? `{${TRequest}}` : undefined]
|
|
139
|
+
.filter(Boolean)
|
|
140
|
+
.join(', ')
|
|
137
141
|
|
|
138
142
|
return (
|
|
139
143
|
<File.Source name={name} isExportable isIndexable>
|
package/src/components/Query.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import { File, Function, FunctionParams } from '@kubb/react'
|
|
|
3
3
|
import { type Operation, isOptional } from '@kubb/oas'
|
|
4
4
|
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
5
5
|
import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
|
|
6
|
+
import type { PluginReactQuery } from '@kubb/plugin-react-query'
|
|
6
7
|
import type { ReactNode } from 'react'
|
|
7
8
|
import type { PluginVueQuery } from '../types.ts'
|
|
8
9
|
import { QueryKey } from './QueryKey.tsx'
|
|
@@ -18,22 +19,72 @@ type Props = {
|
|
|
18
19
|
queryKeyTypeName: string
|
|
19
20
|
typeSchemas: OperationSchemas
|
|
20
21
|
operation: Operation
|
|
22
|
+
paramsType: PluginVueQuery['resolvedOptions']['paramsType']
|
|
21
23
|
pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
|
|
22
24
|
dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
type GetParamsProps = {
|
|
28
|
+
paramsType: PluginVueQuery['resolvedOptions']['paramsType']
|
|
26
29
|
pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
|
|
27
30
|
dataReturnType: PluginVueQuery['resolvedOptions']['client']['dataReturnType']
|
|
28
31
|
typeSchemas: OperationSchemas
|
|
29
32
|
}
|
|
30
33
|
|
|
31
|
-
function getParams({ pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
|
|
34
|
+
function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas }: GetParamsProps) {
|
|
32
35
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
33
36
|
|
|
37
|
+
if (paramsType === 'object') {
|
|
38
|
+
return FunctionParams.factory({
|
|
39
|
+
data: {
|
|
40
|
+
mode: 'object',
|
|
41
|
+
children: {
|
|
42
|
+
...getPathParams(typeSchemas.pathParams, {
|
|
43
|
+
typed: true,
|
|
44
|
+
override(item) {
|
|
45
|
+
return {
|
|
46
|
+
...item,
|
|
47
|
+
type: `MaybeRef<${item.type}>`,
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
data: typeSchemas.request?.name
|
|
52
|
+
? {
|
|
53
|
+
type: `MaybeRef<${typeSchemas.request?.name}>`,
|
|
54
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
55
|
+
}
|
|
56
|
+
: undefined,
|
|
57
|
+
params: typeSchemas.queryParams?.name
|
|
58
|
+
? {
|
|
59
|
+
type: `MaybeRef<${typeSchemas.queryParams?.name}>`,
|
|
60
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
61
|
+
}
|
|
62
|
+
: undefined,
|
|
63
|
+
headers: typeSchemas.headerParams?.name
|
|
64
|
+
? {
|
|
65
|
+
type: `MaybeRef<${typeSchemas.headerParams?.name}>`,
|
|
66
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
67
|
+
}
|
|
68
|
+
: undefined,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
options: {
|
|
72
|
+
type: `
|
|
73
|
+
{
|
|
74
|
+
query?: Partial<QueryObserverOptions<${[TData, typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error', 'TData', 'TQueryData', 'TQueryKey'].join(', ')}>>,
|
|
75
|
+
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>'}
|
|
76
|
+
}
|
|
77
|
+
`,
|
|
78
|
+
default: '{}',
|
|
79
|
+
},
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
34
83
|
return FunctionParams.factory({
|
|
35
84
|
pathParams: {
|
|
36
85
|
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
86
|
+
type: typeSchemas.pathParams?.name,
|
|
87
|
+
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
37
88
|
children: getPathParams(typeSchemas.pathParams, {
|
|
38
89
|
typed: true,
|
|
39
90
|
override(item) {
|
|
@@ -74,7 +125,17 @@ function getParams({ pathParamsType, dataReturnType, typeSchemas }: GetParamsPro
|
|
|
74
125
|
})
|
|
75
126
|
}
|
|
76
127
|
|
|
77
|
-
export function Query({
|
|
128
|
+
export function Query({
|
|
129
|
+
name,
|
|
130
|
+
queryKeyTypeName,
|
|
131
|
+
queryOptionsName,
|
|
132
|
+
queryKeyName,
|
|
133
|
+
paramsType,
|
|
134
|
+
pathParamsType,
|
|
135
|
+
dataReturnType,
|
|
136
|
+
typeSchemas,
|
|
137
|
+
operation,
|
|
138
|
+
}: Props): ReactNode {
|
|
78
139
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
79
140
|
const returnType = `UseQueryReturnType<${['TData', typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'].join(', ')}> & { queryKey: TQueryKey }`
|
|
80
141
|
const generics = [`TData = ${TData}`, `TQueryData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`]
|
|
@@ -84,10 +145,12 @@ export function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
84
145
|
typeSchemas,
|
|
85
146
|
})
|
|
86
147
|
const queryOptionsParams = QueryOptions.getParams({
|
|
148
|
+
paramsType,
|
|
87
149
|
pathParamsType,
|
|
88
150
|
typeSchemas,
|
|
89
151
|
})
|
|
90
152
|
const params = getParams({
|
|
153
|
+
paramsType,
|
|
91
154
|
pathParamsType,
|
|
92
155
|
dataReturnType,
|
|
93
156
|
typeSchemas,
|
|
@@ -6,6 +6,7 @@ import type { ReactNode } from 'react'
|
|
|
6
6
|
import { isOptional } from '@kubb/oas'
|
|
7
7
|
import { Client } from '@kubb/plugin-client/components'
|
|
8
8
|
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
9
|
+
import type { PluginReactQuery } from '@kubb/plugin-react-query'
|
|
9
10
|
import type { PluginVueQuery } from '../types.ts'
|
|
10
11
|
import { QueryKey } from './QueryKey.tsx'
|
|
11
12
|
|
|
@@ -14,18 +15,63 @@ type Props = {
|
|
|
14
15
|
clientName: string
|
|
15
16
|
queryKeyName: string
|
|
16
17
|
typeSchemas: OperationSchemas
|
|
18
|
+
paramsType: PluginVueQuery['resolvedOptions']['paramsType']
|
|
17
19
|
pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
type GetParamsProps = {
|
|
23
|
+
paramsType: PluginVueQuery['resolvedOptions']['paramsType']
|
|
21
24
|
pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
|
|
22
25
|
typeSchemas: OperationSchemas
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
28
|
+
function getParams({ paramsType, pathParamsType, typeSchemas }: GetParamsProps) {
|
|
29
|
+
if (paramsType === 'object') {
|
|
30
|
+
return FunctionParams.factory({
|
|
31
|
+
data: {
|
|
32
|
+
mode: 'object',
|
|
33
|
+
children: {
|
|
34
|
+
...getPathParams(typeSchemas.pathParams, {
|
|
35
|
+
typed: true,
|
|
36
|
+
override(item) {
|
|
37
|
+
return {
|
|
38
|
+
...item,
|
|
39
|
+
type: `MaybeRef<${item.type}>`,
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
}),
|
|
43
|
+
data: typeSchemas.request?.name
|
|
44
|
+
? {
|
|
45
|
+
type: `MaybeRef<${typeSchemas.request?.name}>`,
|
|
46
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
47
|
+
}
|
|
48
|
+
: undefined,
|
|
49
|
+
params: typeSchemas.queryParams?.name
|
|
50
|
+
? {
|
|
51
|
+
type: `MaybeRef<${typeSchemas.queryParams?.name}>`,
|
|
52
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
53
|
+
}
|
|
54
|
+
: undefined,
|
|
55
|
+
headers: typeSchemas.headerParams?.name
|
|
56
|
+
? {
|
|
57
|
+
type: `MaybeRef<${typeSchemas.queryParams?.name}>`,
|
|
58
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
59
|
+
}
|
|
60
|
+
: undefined,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
config: {
|
|
64
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>',
|
|
65
|
+
default: '{}',
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
26
70
|
return FunctionParams.factory({
|
|
27
71
|
pathParams: {
|
|
28
72
|
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
73
|
+
type: typeSchemas.pathParams?.name,
|
|
74
|
+
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
29
75
|
children: getPathParams(typeSchemas.pathParams, {
|
|
30
76
|
typed: true,
|
|
31
77
|
override(item) {
|
|
@@ -61,9 +107,10 @@ function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
|
61
107
|
})
|
|
62
108
|
}
|
|
63
109
|
|
|
64
|
-
export function QueryOptions({ name, clientName, typeSchemas, pathParamsType, queryKeyName }: Props): ReactNode {
|
|
65
|
-
const params = getParams({ pathParamsType, typeSchemas })
|
|
110
|
+
export function QueryOptions({ name, clientName, typeSchemas, paramsType, pathParamsType, queryKeyName }: Props): ReactNode {
|
|
111
|
+
const params = getParams({ paramsType, pathParamsType, typeSchemas })
|
|
66
112
|
const clientParams = Client.getParams({
|
|
113
|
+
paramsType,
|
|
67
114
|
typeSchemas,
|
|
68
115
|
pathParamsType,
|
|
69
116
|
})
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import client from "@kubb/plugin-client/client";
|
|
2
|
+
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
|
+
import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "@tanstack/react-query";
|
|
4
|
+
import type { MaybeRef } from "vue";
|
|
5
|
+
import { useQuery, queryOptions } from "@tanstack/react-query";
|
|
6
|
+
import { unref } from "vue";
|
|
7
|
+
|
|
8
|
+
export const findPetsByTagsQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
9
|
+
|
|
10
|
+
export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
14
|
+
* @summary Finds Pets by tags
|
|
15
|
+
* @link /pet/findByTags
|
|
16
|
+
*/
|
|
17
|
+
async function findPetsByTags({ headers, params }: {
|
|
18
|
+
headers: FindPetsByTagsHeaderParams;
|
|
19
|
+
params?: FindPetsByTagsQueryParams;
|
|
20
|
+
}, config: Partial<RequestConfig> = {}) {
|
|
21
|
+
const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: "GET", url: `/pet/findByTags`, params, headers: { ...headers, ...config.headers }, ...config });
|
|
22
|
+
return findPetsByTagsQueryResponse.parse(res.data);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function findPetsByTagsQueryOptions({ headers, params }: {
|
|
26
|
+
headers: MaybeRef<FindPetsByTagsQueryParams>;
|
|
27
|
+
params?: MaybeRef<FindPetsByTagsQueryParams>;
|
|
28
|
+
}, config: Partial<RequestConfig> = {}) {
|
|
29
|
+
const queryKey = findPetsByTagsQueryKey(params);
|
|
30
|
+
return queryOptions({
|
|
31
|
+
queryKey,
|
|
32
|
+
queryFn: async ({ signal }) => {
|
|
33
|
+
config.signal = signal;
|
|
34
|
+
return findPetsByTags(unref({ headers: unref(headers), params: unref(params) }), unref(config));
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
41
|
+
* @summary Finds Pets by tags
|
|
42
|
+
* @link /pet/findByTags
|
|
43
|
+
*/
|
|
44
|
+
export function useFindPetsByTags<TData = FindPetsByTagsQueryResponse, TQueryData = FindPetsByTagsQueryResponse, TQueryKey extends QueryKey = FindPetsByTagsQueryKey>({ headers, params }: {
|
|
45
|
+
headers: MaybeRef<FindPetsByTagsHeaderParams>;
|
|
46
|
+
params?: MaybeRef<FindPetsByTagsQueryParams>;
|
|
47
|
+
}, options: {
|
|
48
|
+
query?: Partial<QueryObserverOptions<FindPetsByTagsQueryResponse, FindPetsByTags400, TData, TQueryData, TQueryKey>>;
|
|
49
|
+
client?: Partial<RequestConfig>;
|
|
50
|
+
} = {}) {
|
|
51
|
+
const { query: queryOptions, client: config = {} } = options ?? {};
|
|
52
|
+
const queryKey = queryOptions?.queryKey ?? findPetsByTagsQueryKey(params);
|
|
53
|
+
const query = useQuery({
|
|
54
|
+
...findPetsByTagsQueryOptions({ headers, params }, config) as unknown as QueryObserverOptions,
|
|
55
|
+
queryKey: queryKey as QueryKey,
|
|
56
|
+
...queryOptions as unknown as Omit<QueryObserverOptions, "queryKey">
|
|
57
|
+
}) as UseQueryReturnType<TData, FindPetsByTags400> & {
|
|
58
|
+
queryKey: TQueryKey;
|
|
59
|
+
};
|
|
60
|
+
query.queryKey = queryKey as TQueryKey;
|
|
61
|
+
return query;
|
|
62
|
+
}
|
|
@@ -12,9 +12,7 @@ import { useMutation } from "@tanstack/react-query";
|
|
|
12
12
|
* @summary Updates a pet in the store with form data
|
|
13
13
|
* @link /pet/:petId
|
|
14
14
|
*/
|
|
15
|
-
async function updatePetWithForm({ petId }: {
|
|
16
|
-
petId: UpdatePetWithFormPathParams["petId"];
|
|
17
|
-
}, data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> = {}) {
|
|
15
|
+
async function updatePetWithForm({ petId }: UpdatePetWithFormPathParams, data?: UpdatePetWithFormMutationRequest, params?: UpdatePetWithFormQueryParams, config: Partial<RequestConfig<UpdatePetWithFormMutationRequest>> = {}) {
|
|
18
16
|
const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, UpdatePetWithFormMutationRequest>({ method: "POST", url: `/pet/${petId}`, params, data, ...config });
|
|
19
17
|
return updatePetWithFormMutationResponse.parse(res.data);
|
|
20
18
|
}
|