@kubb/plugin-vue-query 3.0.0-beta.10 → 3.0.0-beta.12
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-PGNSMLGU.cjs → chunk-A7SD37VK.cjs} +103 -97
- package/dist/chunk-A7SD37VK.cjs.map +1 -0
- package/dist/{chunk-DWWRCRGY.js → chunk-DHJLKFYS.js} +22 -10
- package/dist/chunk-DHJLKFYS.js.map +1 -0
- package/dist/{chunk-5MY3SE2R.cjs → chunk-J4RZRRHQ.cjs} +22 -10
- package/dist/chunk-J4RZRRHQ.cjs.map +1 -0
- package/dist/{chunk-YQOJHRKU.js → chunk-O4EGNKUX.js} +95 -89
- package/dist/chunk-O4EGNKUX.js.map +1 -0
- package/dist/components.cjs +8 -8
- package/dist/components.d.cts +7 -5
- package/dist/components.d.ts +7 -5
- 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 +20 -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 +19 -21
- package/dist/index.js.map +1 -1
- package/dist/{types-Dx6yZliF.d.cts → types-C8LfCZUP.d.cts} +187 -22
- package/dist/{types-Dx6yZliF.d.ts → types-C8LfCZUP.d.ts} +187 -22
- package/package.json +11 -11
- package/src/components/MutationKey.tsx +11 -5
- package/src/components/QueryKey.tsx +17 -7
- package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +1 -1
- package/src/generators/__snapshots__/clientGetImportPath.ts +1 -1
- package/src/generators/__snapshots__/clientPostImportPath.ts +2 -2
- package/src/generators/__snapshots__/findByTags.ts +1 -1
- package/src/generators/__snapshots__/findByTagsObject.ts +1 -1
- 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__/findInfiniteByTags.ts +1 -1
- package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +1 -1
- package/src/generators/__snapshots__/postAsQuery.ts +1 -1
- package/src/generators/__snapshots__/updatePetById.ts +2 -2
- package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +2 -2
- package/src/generators/infiniteQueryGenerator.tsx +38 -33
- package/src/generators/mutationGenerator.tsx +22 -16
- package/src/generators/queryGenerator.tsx +22 -18
- package/src/plugin.ts +18 -19
- package/src/types.ts +26 -13
- package/dist/chunk-5MY3SE2R.cjs.map +0 -1
- package/dist/chunk-DWWRCRGY.js.map +0 -1
- package/dist/chunk-PGNSMLGU.cjs.map +0 -1
- package/dist/chunk-YQOJHRKU.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
|
|
2
|
-
import { HttpMethod } from '@kubb/oas';
|
|
3
|
-
import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
|
|
2
|
+
import { HttpMethod, Operation } from '@kubb/oas';
|
|
3
|
+
import { ResolvePathOptions, Exclude, Include, Override, Generator, OperationSchemas } from '@kubb/plugin-oas';
|
|
4
4
|
|
|
5
|
-
type Options$
|
|
5
|
+
type Options$2 = {
|
|
6
6
|
/**
|
|
7
7
|
* Specify the export location for the files and define the behavior of the output
|
|
8
8
|
* @default { path: 'clients', barrelType: 'named' }
|
|
@@ -23,7 +23,7 @@ type Options$1 = {
|
|
|
23
23
|
/**
|
|
24
24
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
25
25
|
*/
|
|
26
|
-
override?: Array<Override<ResolvedOptions$
|
|
26
|
+
override?: Array<Override<ResolvedOptions$2>>;
|
|
27
27
|
/**
|
|
28
28
|
* Create `operations.ts` file with all operations grouped by methods.
|
|
29
29
|
* @default false
|
|
@@ -36,6 +36,10 @@ type Options$1 = {
|
|
|
36
36
|
* @default '@kubb/plugin-client/client'
|
|
37
37
|
*/
|
|
38
38
|
importPath?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Allows you to set a custom base url for all generated calls.
|
|
41
|
+
*/
|
|
42
|
+
baseURL?: string;
|
|
39
43
|
/**
|
|
40
44
|
* ReturnType that will be used when calling the client.
|
|
41
45
|
* - 'data' will return ResponseConfig[data].
|
|
@@ -74,23 +78,183 @@ type Options$1 = {
|
|
|
74
78
|
*/
|
|
75
79
|
generators?: Array<Generator<PluginClient>>;
|
|
76
80
|
};
|
|
77
|
-
type ResolvedOptions$
|
|
81
|
+
type ResolvedOptions$2 = {
|
|
78
82
|
output: Output;
|
|
79
|
-
group?: Options$
|
|
83
|
+
group?: Options$2['group'];
|
|
80
84
|
baseURL: string | undefined;
|
|
81
|
-
parser: NonNullable<Options$
|
|
82
|
-
importPath: NonNullable<Options$
|
|
83
|
-
dataReturnType: NonNullable<Options$
|
|
85
|
+
parser: NonNullable<Options$2['parser']>;
|
|
86
|
+
importPath: NonNullable<Options$2['importPath']>;
|
|
87
|
+
dataReturnType: NonNullable<Options$2['dataReturnType']>;
|
|
88
|
+
pathParamsType: NonNullable<Options$2['pathParamsType']>;
|
|
89
|
+
paramsType: NonNullable<Options$2['paramsType']>;
|
|
90
|
+
};
|
|
91
|
+
type PluginClient = PluginFactoryOptions<'plugin-client', Options$2, ResolvedOptions$2, never, ResolvePathOptions>;
|
|
92
|
+
|
|
93
|
+
type TransformerProps$1 = {
|
|
94
|
+
operation: Operation;
|
|
95
|
+
schemas: OperationSchemas;
|
|
96
|
+
};
|
|
97
|
+
type Transformer$1 = (props: TransformerProps$1) => unknown[];
|
|
98
|
+
type Suspense = object;
|
|
99
|
+
/**
|
|
100
|
+
* Customize the queryKey
|
|
101
|
+
*/
|
|
102
|
+
type QueryKey$1 = Transformer$1;
|
|
103
|
+
/**
|
|
104
|
+
* Customize the mutationKey
|
|
105
|
+
*/
|
|
106
|
+
type MutationKey$1 = Transformer$1;
|
|
107
|
+
type Query$1 = {
|
|
108
|
+
/**
|
|
109
|
+
* Define which HttpMethods can be used for queries
|
|
110
|
+
* @default ['get']
|
|
111
|
+
*/
|
|
112
|
+
methods: Array<HttpMethod>;
|
|
113
|
+
/**
|
|
114
|
+
* Path to the useQuery that will be used to do the useQuery functionality.
|
|
115
|
+
* It will be used as `import { useQuery } from '${importPath}'`.
|
|
116
|
+
* It allows both relative and absolute path.
|
|
117
|
+
* the path will be applied as is, so relative path should be based on the file being generated.
|
|
118
|
+
* @default '@tanstack/react-query'
|
|
119
|
+
*/
|
|
120
|
+
importPath?: string;
|
|
121
|
+
};
|
|
122
|
+
type Mutation$1 = {
|
|
123
|
+
/**
|
|
124
|
+
* Define which HttpMethods can be used for mutations
|
|
125
|
+
* @default ['post', 'put', 'delete']
|
|
126
|
+
*/
|
|
127
|
+
methods: Array<HttpMethod>;
|
|
128
|
+
/**
|
|
129
|
+
* Path to the useQuery that will be used to do the useQuery functionality.
|
|
130
|
+
* It will be used as `import { useQuery } from '${importPath}'`.
|
|
131
|
+
* It allows both relative and absolute path.
|
|
132
|
+
* the path will be applied as is, so relative path should be based on the file being generated.
|
|
133
|
+
* @default '@tanstack/react-query'
|
|
134
|
+
*/
|
|
135
|
+
importPath?: string;
|
|
136
|
+
};
|
|
137
|
+
type Infinite$1 = {
|
|
138
|
+
/**
|
|
139
|
+
* Specify the params key used for `pageParam`.
|
|
140
|
+
* @default 'id'
|
|
141
|
+
*/
|
|
142
|
+
queryParam: string;
|
|
143
|
+
/**
|
|
144
|
+
* Which field of the data will be used, set it to undefined when no cursor is known.
|
|
145
|
+
*/
|
|
146
|
+
cursorParam?: string | undefined;
|
|
147
|
+
/**
|
|
148
|
+
* The initial value, the value of the first page.
|
|
149
|
+
* @default 0
|
|
150
|
+
*/
|
|
151
|
+
initialPageParam: unknown;
|
|
152
|
+
};
|
|
153
|
+
type Options$1 = {
|
|
154
|
+
/**
|
|
155
|
+
* Specify the export location for the files and define the behavior of the output
|
|
156
|
+
* @default { path: 'hooks', barrelType: 'named' }
|
|
157
|
+
*/
|
|
158
|
+
output?: Output;
|
|
159
|
+
/**
|
|
160
|
+
* Group the @tanstack/query hooks based on the provided name.
|
|
161
|
+
*/
|
|
162
|
+
group?: Group;
|
|
163
|
+
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>;
|
|
164
|
+
/**
|
|
165
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
166
|
+
*/
|
|
167
|
+
exclude?: Array<Exclude>;
|
|
168
|
+
/**
|
|
169
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
170
|
+
*/
|
|
171
|
+
include?: Array<Include>;
|
|
172
|
+
/**
|
|
173
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
174
|
+
*/
|
|
175
|
+
override?: Array<Override<ResolvedOptions$1>>;
|
|
176
|
+
/**
|
|
177
|
+
* How to pass your params
|
|
178
|
+
* - 'object' will return the params and pathParams as an object.
|
|
179
|
+
* - 'inline' will return the params as comma separated params.
|
|
180
|
+
* @default 'inline'
|
|
181
|
+
*/
|
|
182
|
+
paramsType?: 'object' | 'inline';
|
|
183
|
+
/**
|
|
184
|
+
* How to pass your pathParams.
|
|
185
|
+
* - 'object' will return the pathParams as an object.
|
|
186
|
+
* - 'inline' will return the pathParams as comma separated params.
|
|
187
|
+
* @default 'inline'
|
|
188
|
+
*/
|
|
189
|
+
pathParamsType?: PluginClient['options']['pathParamsType'];
|
|
190
|
+
/**
|
|
191
|
+
* When set, an infiniteQuery hooks will be added.
|
|
192
|
+
*/
|
|
193
|
+
infinite?: Partial<Infinite$1> | false;
|
|
194
|
+
/**
|
|
195
|
+
* When set, a suspenseQuery hooks will be added.
|
|
196
|
+
*/
|
|
197
|
+
suspense?: Partial<Suspense> | false;
|
|
198
|
+
queryKey?: QueryKey$1;
|
|
199
|
+
/**
|
|
200
|
+
* Override some useQuery behaviours.
|
|
201
|
+
*/
|
|
202
|
+
query?: Partial<Query$1> | false;
|
|
203
|
+
mutationKey?: MutationKey$1;
|
|
204
|
+
/**
|
|
205
|
+
* Override some useMutation behaviours.
|
|
206
|
+
*/
|
|
207
|
+
mutation?: Partial<Mutation$1> | false;
|
|
208
|
+
/**
|
|
209
|
+
* Which parser should be used before returning the data to `@tanstack/query`.
|
|
210
|
+
* `'zod'` will use `@kubb/plugin-zod` to parse the data.
|
|
211
|
+
*/
|
|
212
|
+
parser?: PluginClient['options']['parser'];
|
|
213
|
+
transformers?: {
|
|
214
|
+
/**
|
|
215
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
216
|
+
*/
|
|
217
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* Define some generators next to the react-query generators
|
|
221
|
+
*/
|
|
222
|
+
generators?: Array<Generator<PluginReactQuery>>;
|
|
223
|
+
};
|
|
224
|
+
type ResolvedOptions$1 = {
|
|
225
|
+
output: Output;
|
|
226
|
+
client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & {
|
|
227
|
+
baseURL?: string;
|
|
228
|
+
};
|
|
229
|
+
parser: Required<NonNullable<Options$1['parser']>>;
|
|
84
230
|
pathParamsType: NonNullable<Options$1['pathParamsType']>;
|
|
85
231
|
paramsType: NonNullable<Options$1['paramsType']>;
|
|
232
|
+
/**
|
|
233
|
+
* Only used of infinite
|
|
234
|
+
*/
|
|
235
|
+
infinite: NonNullable<Infinite$1> | false;
|
|
236
|
+
suspense: Suspense | false;
|
|
237
|
+
queryKey: QueryKey$1 | undefined;
|
|
238
|
+
query: NonNullable<Required<Query$1>> | false;
|
|
239
|
+
mutationKey: MutationKey$1 | undefined;
|
|
240
|
+
mutation: NonNullable<Required<Mutation$1>> | false;
|
|
86
241
|
};
|
|
87
|
-
type
|
|
242
|
+
type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options$1, ResolvedOptions$1, never, ResolvePathOptions>;
|
|
88
243
|
|
|
244
|
+
type TransformerProps = {
|
|
245
|
+
operation: Operation;
|
|
246
|
+
schemas: OperationSchemas;
|
|
247
|
+
};
|
|
248
|
+
type Transformer = (props: TransformerProps) => unknown[];
|
|
249
|
+
/**
|
|
250
|
+
* Customize the queryKey
|
|
251
|
+
*/
|
|
252
|
+
type QueryKey = Transformer;
|
|
253
|
+
/**
|
|
254
|
+
* Customize the mutationKey
|
|
255
|
+
*/
|
|
256
|
+
type MutationKey = Transformer;
|
|
89
257
|
type Query = {
|
|
90
|
-
/**
|
|
91
|
-
* Customize the queryKey, here you can specify a suffix.
|
|
92
|
-
*/
|
|
93
|
-
key: (key: unknown[]) => unknown[];
|
|
94
258
|
/**
|
|
95
259
|
* Define which HttpMethods can be used for queries
|
|
96
260
|
* @default ['get']
|
|
@@ -106,10 +270,6 @@ type Query = {
|
|
|
106
270
|
importPath?: string;
|
|
107
271
|
};
|
|
108
272
|
type Mutation = {
|
|
109
|
-
/**
|
|
110
|
-
* Customize the queryKey, here you can specify a suffix.
|
|
111
|
-
*/
|
|
112
|
-
key: (key: unknown[]) => unknown[];
|
|
113
273
|
/**
|
|
114
274
|
* Define which HttpMethods can be used for mutations
|
|
115
275
|
* @default ['post', 'put', 'delete']
|
|
@@ -150,7 +310,7 @@ type Options = {
|
|
|
150
310
|
* Group the @tanstack/query hooks based on the provided name.
|
|
151
311
|
*/
|
|
152
312
|
group?: Group;
|
|
153
|
-
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath'>;
|
|
313
|
+
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>;
|
|
154
314
|
/**
|
|
155
315
|
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
156
316
|
*/
|
|
@@ -181,10 +341,12 @@ type Options = {
|
|
|
181
341
|
* When set, an infiniteQuery hooks will be added.
|
|
182
342
|
*/
|
|
183
343
|
infinite?: Partial<Infinite> | false;
|
|
344
|
+
queryKey?: QueryKey;
|
|
184
345
|
/**
|
|
185
346
|
* Override some useQuery behaviours.
|
|
186
347
|
*/
|
|
187
348
|
query?: Partial<Query> | false;
|
|
349
|
+
mutationKey?: MutationKey;
|
|
188
350
|
/**
|
|
189
351
|
* Override some useMutation behaviours.
|
|
190
352
|
*/
|
|
@@ -207,8 +369,9 @@ type Options = {
|
|
|
207
369
|
};
|
|
208
370
|
type ResolvedOptions = {
|
|
209
371
|
output: Output;
|
|
210
|
-
|
|
211
|
-
|
|
372
|
+
client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & {
|
|
373
|
+
baseURL?: string;
|
|
374
|
+
};
|
|
212
375
|
parser: Required<NonNullable<Options['parser']>>;
|
|
213
376
|
paramsType: NonNullable<Options['paramsType']>;
|
|
214
377
|
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
@@ -216,9 +379,11 @@ type ResolvedOptions = {
|
|
|
216
379
|
* Only used of infinite
|
|
217
380
|
*/
|
|
218
381
|
infinite: NonNullable<Infinite> | false;
|
|
382
|
+
queryKey: QueryKey | undefined;
|
|
219
383
|
query: NonNullable<Required<Query>> | false;
|
|
384
|
+
mutationKey: MutationKey | undefined;
|
|
220
385
|
mutation: NonNullable<Required<Mutation>> | false;
|
|
221
386
|
};
|
|
222
387
|
type PluginVueQuery = PluginFactoryOptions<'plugin-vue-query', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
223
388
|
|
|
224
|
-
export type { Infinite as I, Options as O, PluginVueQuery as P };
|
|
389
|
+
export type { Infinite as I, Options as O, PluginVueQuery as P, Transformer as T };
|
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.12",
|
|
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.12",
|
|
66
|
+
"@kubb/fs": "3.0.0-beta.12",
|
|
67
|
+
"@kubb/oas": "3.0.0-beta.12",
|
|
68
|
+
"@kubb/plugin-oas": "3.0.0-beta.12",
|
|
69
|
+
"@kubb/plugin-ts": "3.0.0-beta.12",
|
|
70
|
+
"@kubb/plugin-zod": "3.0.0-beta.12",
|
|
71
|
+
"@kubb/react": "3.0.0-beta.12"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@types/react": "^18.3.12",
|
|
75
75
|
"react": "^18.3.1",
|
|
76
76
|
"tsup": "^8.3.5",
|
|
77
77
|
"typescript": "^5.6.3",
|
|
78
|
-
"@kubb/config-ts": "3.0.0-beta.
|
|
79
|
-
"@kubb/config-tsup": "3.0.0-beta.
|
|
78
|
+
"@kubb/config-ts": "3.0.0-beta.12",
|
|
79
|
+
"@kubb/config-tsup": "3.0.0-beta.12"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
|
-
"@kubb/react": "3.0.0-beta.
|
|
82
|
+
"@kubb/react": "3.0.0-beta.12"
|
|
83
83
|
},
|
|
84
84
|
"engines": {
|
|
85
85
|
"node": ">=20"
|
|
@@ -4,7 +4,7 @@ import { File, Function, FunctionParams, Type } from '@kubb/react'
|
|
|
4
4
|
import type { Operation } from '@kubb/oas'
|
|
5
5
|
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
6
6
|
import type { ReactNode } from 'react'
|
|
7
|
-
import type { PluginVueQuery } from '../types'
|
|
7
|
+
import type { PluginVueQuery, Transformer } from '../types'
|
|
8
8
|
|
|
9
9
|
type Props = {
|
|
10
10
|
name: string
|
|
@@ -12,7 +12,7 @@ type Props = {
|
|
|
12
12
|
typeSchemas: OperationSchemas
|
|
13
13
|
operation: Operation
|
|
14
14
|
pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
|
|
15
|
-
|
|
15
|
+
transformer: Transformer | undefined
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
type GetParamsProps = {
|
|
@@ -24,16 +24,21 @@ function getParams({}: GetParamsProps) {
|
|
|
24
24
|
return FunctionParams.factory({})
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
const getTransformer: Transformer = ({ operation }) => {
|
|
28
28
|
const path = new URLPath(operation.path)
|
|
29
|
+
|
|
30
|
+
return [JSON.stringify({ url: path.path })].filter(Boolean)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function MutationKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
|
|
29
34
|
const params = getParams({ pathParamsType, typeSchemas })
|
|
30
|
-
const keys =
|
|
35
|
+
const keys = transformer({ operation, schemas: typeSchemas })
|
|
31
36
|
|
|
32
37
|
return (
|
|
33
38
|
<>
|
|
34
39
|
<File.Source name={name} isExportable isIndexable>
|
|
35
40
|
<Function.Arrow name={name} export params={params.toConstructor()} singleLine>
|
|
36
|
-
{`[${
|
|
41
|
+
{`[${keys.join(', ')}] as const`}
|
|
37
42
|
</Function.Arrow>
|
|
38
43
|
</File.Source>
|
|
39
44
|
<File.Source name={typeName} isExportable isIndexable isTypeOnly>
|
|
@@ -46,3 +51,4 @@ export function MutationKey({ name, typeSchemas, pathParamsType, operation, type
|
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
MutationKey.getParams = getParams
|
|
54
|
+
MutationKey.getTransformer = getTransformer
|
|
@@ -5,7 +5,7 @@ import { File, Function, FunctionParams, Type } from '@kubb/react'
|
|
|
5
5
|
import { type Operation, isOptional } from '@kubb/oas'
|
|
6
6
|
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
7
7
|
import type { ReactNode } from 'react'
|
|
8
|
-
import type { PluginVueQuery } from '../types'
|
|
8
|
+
import type { PluginVueQuery, Transformer } from '../types'
|
|
9
9
|
|
|
10
10
|
type Props = {
|
|
11
11
|
name: string
|
|
@@ -13,7 +13,7 @@ type Props = {
|
|
|
13
13
|
typeSchemas: OperationSchemas
|
|
14
14
|
operation: Operation
|
|
15
15
|
pathParamsType: PluginVueQuery['resolvedOptions']['pathParamsType']
|
|
16
|
-
|
|
16
|
+
transformer: Transformer | undefined
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
type GetParamsProps = {
|
|
@@ -50,23 +50,32 @@ function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
|
50
50
|
})
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
const getTransformer: Transformer = ({ operation, schemas }) => {
|
|
54
54
|
const path = new URLPath(operation.path)
|
|
55
|
-
const params = getParams({ pathParamsType, typeSchemas })
|
|
56
55
|
const keys = [
|
|
57
56
|
path.toObject({
|
|
58
57
|
type: 'path',
|
|
59
58
|
stringify: true,
|
|
60
59
|
}),
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
schemas.queryParams?.name ? '...(params ? [params] : [])' : undefined,
|
|
61
|
+
schemas.request?.name ? '...(data ? [data] : [])' : undefined,
|
|
63
62
|
].filter(Boolean)
|
|
64
63
|
|
|
64
|
+
return keys
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
|
|
68
|
+
const params = getParams({ pathParamsType, typeSchemas })
|
|
69
|
+
const keys = transformer({
|
|
70
|
+
operation,
|
|
71
|
+
schemas: typeSchemas,
|
|
72
|
+
})
|
|
73
|
+
|
|
65
74
|
return (
|
|
66
75
|
<>
|
|
67
76
|
<File.Source name={name} isExportable isIndexable>
|
|
68
77
|
<Function.Arrow name={name} export params={params.toConstructor()} singleLine>
|
|
69
|
-
{`[${
|
|
78
|
+
{`[${keys.join(', ')}] as const`}
|
|
70
79
|
</Function.Arrow>
|
|
71
80
|
</File.Source>
|
|
72
81
|
<File.Source name={typeName} isExportable isIndexable isTypeOnly>
|
|
@@ -79,3 +88,4 @@ export function QueryKey({ name, typeSchemas, pathParamsType, operation, typeNam
|
|
|
79
88
|
}
|
|
80
89
|
|
|
81
90
|
QueryKey.getParams = getParams
|
|
91
|
+
QueryKey.getTransformer = getTransformer
|
|
@@ -2,7 +2,7 @@ import client from "@kubb/plugin-client/client";
|
|
|
2
2
|
import type { RequestConfig, ResponseConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "@tanstack/react-query";
|
|
4
4
|
import type { MaybeRef } from "vue";
|
|
5
|
-
import {
|
|
5
|
+
import { queryOptions, useQuery } from "@tanstack/react-query";
|
|
6
6
|
import { unref } from "vue";
|
|
7
7
|
|
|
8
8
|
export const findPetsByTagsQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
@@ -2,7 +2,7 @@ import client from "axios";
|
|
|
2
2
|
import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "@tanstack/react-query";
|
|
3
3
|
import type { RequestConfig } from "axios";
|
|
4
4
|
import type { MaybeRef } from "vue";
|
|
5
|
-
import {
|
|
5
|
+
import { queryOptions, useQuery } from "@tanstack/react-query";
|
|
6
6
|
import { unref } from "vue";
|
|
7
7
|
|
|
8
8
|
export const findPetsByTagsQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import client from "axios";
|
|
2
|
-
import type { MutationObserverOptions } from "@tanstack/
|
|
2
|
+
import type { MutationObserverOptions } from "@tanstack/vue-query";
|
|
3
3
|
import type { RequestConfig } from "axios";
|
|
4
4
|
import type { MaybeRef } from "vue";
|
|
5
|
-
import { useMutation } from "@tanstack/
|
|
5
|
+
import { useMutation } from "@tanstack/vue-query";
|
|
6
6
|
|
|
7
7
|
export const updatePetWithFormMutationKey = () => [{ "url": "/pet/{petId}" }] as const;
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@ import client from "@kubb/plugin-client/client";
|
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "@tanstack/react-query";
|
|
4
4
|
import type { MaybeRef } from "vue";
|
|
5
|
-
import {
|
|
5
|
+
import { queryOptions, useQuery } from "@tanstack/react-query";
|
|
6
6
|
import { unref } from "vue";
|
|
7
7
|
|
|
8
8
|
export const findPetsByTagsQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
@@ -2,7 +2,7 @@ import client from "@kubb/plugin-client/client";
|
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "@tanstack/react-query";
|
|
4
4
|
import type { MaybeRef } from "vue";
|
|
5
|
-
import {
|
|
5
|
+
import { queryOptions, useQuery } from "@tanstack/react-query";
|
|
6
6
|
import { unref } from "vue";
|
|
7
7
|
|
|
8
8
|
export const findPetsByTagsQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
@@ -2,7 +2,7 @@ import client from "@kubb/plugin-client/client";
|
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "@tanstack/react-query";
|
|
4
4
|
import type { MaybeRef } from "vue";
|
|
5
|
-
import {
|
|
5
|
+
import { queryOptions, useQuery } from "@tanstack/react-query";
|
|
6
6
|
import { unref } from "vue";
|
|
7
7
|
|
|
8
8
|
export const findPetsByTagsQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
@@ -2,10 +2,10 @@ import client from "@kubb/plugin-client/client";
|
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "@tanstack/react-query";
|
|
4
4
|
import type { MaybeRef } from "vue";
|
|
5
|
-
import {
|
|
5
|
+
import { queryOptions, useQuery } from "@tanstack/react-query";
|
|
6
6
|
import { unref } from "vue";
|
|
7
7
|
|
|
8
|
-
export const findPetsByTagsQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [test, { url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
8
|
+
export const findPetsByTagsQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => ["test", { url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
9
9
|
|
|
10
10
|
export type FindPetsByTagsQueryKey = ReturnType<typeof findPetsByTagsQueryKey>;
|
|
11
11
|
|
|
@@ -2,7 +2,7 @@ import client from "@kubb/plugin-client/client";
|
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "@tanstack/react-query";
|
|
4
4
|
import type { MaybeRef } from "vue";
|
|
5
|
-
import {
|
|
5
|
+
import { queryOptions, useQuery } from "@tanstack/react-query";
|
|
6
6
|
import { unref } from "vue";
|
|
7
7
|
|
|
8
8
|
export const findPetsByTagsQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
@@ -2,7 +2,7 @@ import client from "@kubb/plugin-client/client";
|
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryReturnType } from "@tanstack/react-query";
|
|
4
4
|
import type { MaybeRef } from "vue";
|
|
5
|
-
import {
|
|
5
|
+
import { infiniteQueryOptions, useInfiniteQuery } from "@tanstack/react-query";
|
|
6
6
|
|
|
7
7
|
export const findPetsByTagsInfiniteQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@ import client from "@kubb/plugin-client/client";
|
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, InfiniteQueryObserverOptions, UseInfiniteQueryReturnType } from "@tanstack/react-query";
|
|
4
4
|
import type { MaybeRef } from "vue";
|
|
5
|
-
import {
|
|
5
|
+
import { infiniteQueryOptions, useInfiniteQuery } from "@tanstack/react-query";
|
|
6
6
|
|
|
7
7
|
export const findPetsByTagsInfiniteQueryKey = (params?: MaybeRef<FindPetsByTagsQueryParams>) => [{ url: "/pet/findByTags" }, ...(params ? [params] : [])] as const;
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@ import client from "@kubb/plugin-client/client";
|
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
3
|
import type { QueryKey, QueryObserverOptions, UseQueryReturnType } from "custom-query";
|
|
4
4
|
import type { MaybeRef } from "vue";
|
|
5
|
-
import {
|
|
5
|
+
import { queryOptions, useQuery } from "custom-query";
|
|
6
6
|
import { unref } from "vue";
|
|
7
7
|
|
|
8
8
|
export const updatePetWithFormQueryKey = (petId: MaybeRef<UpdatePetWithFormPathParams["petId"]>, data?: MaybeRef<UpdatePetWithFormMutationRequest>, params?: MaybeRef<UpdatePetWithFormQueryParams>) => [{ url: "/pet/:petId", params: { petId: petId } }, ...(params ? [params] : []), ...(data ? [data] : [])] as const;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
|
-
import type { MutationObserverOptions } from "@tanstack/
|
|
3
|
+
import type { MutationObserverOptions } from "@tanstack/vue-query";
|
|
4
4
|
import type { MaybeRef } from "vue";
|
|
5
|
-
import { useMutation } from "@tanstack/
|
|
5
|
+
import { useMutation } from "@tanstack/vue-query";
|
|
6
6
|
|
|
7
7
|
export const updatePetWithFormMutationKey = () => [{ "url": "/pet/{petId}" }] as const;
|
|
8
8
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import client from "@kubb/plugin-client/client";
|
|
2
2
|
import type { RequestConfig } from "@kubb/plugin-client/client";
|
|
3
|
-
import type { MutationObserverOptions } from "@tanstack/
|
|
3
|
+
import type { MutationObserverOptions } from "@tanstack/vue-query";
|
|
4
4
|
import type { MaybeRef } from "vue";
|
|
5
|
-
import { useMutation } from "@tanstack/
|
|
5
|
+
import { useMutation } from "@tanstack/vue-query";
|
|
6
6
|
|
|
7
7
|
export const updatePetWithFormMutationKey = () => [{ "url": "/pet/{petId}" }] as const;
|
|
8
8
|
|