@kubb/plugin-svelte-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-VO3QBBZG.cjs → chunk-CDRGJAED.cjs} +61 -54
- package/dist/chunk-CDRGJAED.cjs.map +1 -0
- package/dist/{chunk-NH7LXCFD.js → chunk-JGITTOE5.js} +55 -48
- package/dist/chunk-JGITTOE5.js.map +1 -0
- package/dist/{chunk-HUR476BL.cjs → chunk-KRGCKSGR.cjs} +22 -10
- package/dist/chunk-KRGCKSGR.cjs.map +1 -0
- package/dist/{chunk-LSV2AJSI.js → chunk-R6ZVBNG7.js} +22 -10
- package/dist/chunk-R6ZVBNG7.js.map +1 -0
- package/dist/components.cjs +6 -6
- package/dist/components.d.cts +7 -5
- package/dist/components.d.ts +7 -5
- 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 +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-Cg7Z4H-7.d.cts → types-B9W9aYra.d.cts} +187 -22
- package/dist/{types-Cg7Z4H-7.d.ts → types-B9W9aYra.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__/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__/postAsQuery.ts +1 -1
- package/src/generators/mutationGenerator.tsx +24 -16
- package/src/generators/queryGenerator.tsx +23 -17
- package/src/plugin.ts +19 -19
- package/src/types.ts +26 -13
- package/dist/chunk-HUR476BL.cjs.map +0 -1
- package/dist/chunk-LSV2AJSI.js.map +0 -1
- package/dist/chunk-NH7LXCFD.js.map +0 -1
- package/dist/chunk-VO3QBBZG.cjs.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 = {
|
|
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> | 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> | 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']
|
|
@@ -134,7 +294,7 @@ type Options = {
|
|
|
134
294
|
* Group the @tanstack/query hooks based on the provided name.
|
|
135
295
|
*/
|
|
136
296
|
group?: Group;
|
|
137
|
-
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath'>;
|
|
297
|
+
client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>;
|
|
138
298
|
/**
|
|
139
299
|
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
140
300
|
*/
|
|
@@ -161,10 +321,12 @@ type Options = {
|
|
|
161
321
|
* @default 'inline'
|
|
162
322
|
*/
|
|
163
323
|
pathParamsType?: PluginClient['options']['pathParamsType'];
|
|
324
|
+
queryKey?: QueryKey;
|
|
164
325
|
/**
|
|
165
326
|
* Override some useQuery behaviours.
|
|
166
327
|
*/
|
|
167
328
|
query?: Partial<Query> | false;
|
|
329
|
+
mutationKey?: MutationKey;
|
|
168
330
|
/**
|
|
169
331
|
* Override some useMutation behaviours.
|
|
170
332
|
*/
|
|
@@ -187,14 +349,17 @@ type Options = {
|
|
|
187
349
|
};
|
|
188
350
|
type ResolvedOptions = {
|
|
189
351
|
output: Output;
|
|
190
|
-
|
|
191
|
-
|
|
352
|
+
client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & {
|
|
353
|
+
baseURL?: string;
|
|
354
|
+
};
|
|
192
355
|
parser: Required<NonNullable<Options['parser']>>;
|
|
193
356
|
paramsType: NonNullable<Options['paramsType']>;
|
|
194
357
|
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
358
|
+
queryKey: QueryKey | undefined;
|
|
195
359
|
query: NonNullable<Required<Query>> | false;
|
|
360
|
+
mutationKey: MutationKey | undefined;
|
|
196
361
|
mutation: NonNullable<Required<Mutation>> | false;
|
|
197
362
|
};
|
|
198
363
|
type PluginSvelteQuery = PluginFactoryOptions<'plugin-svelte-query', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
199
364
|
|
|
200
|
-
export type { Options as O, PluginSvelteQuery as P };
|
|
365
|
+
export type { Options as O, PluginSvelteQuery as P, Transformer as T };
|
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.12",
|
|
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.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 { PluginSvelteQuery } from '../types'
|
|
7
|
+
import type { PluginSvelteQuery, 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: PluginSvelteQuery['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 { PluginSvelteQuery } from '../types'
|
|
8
|
+
import type { PluginSvelteQuery, 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: PluginSvelteQuery['resolvedOptions']['pathParamsType']
|
|
16
|
-
|
|
16
|
+
transformer: Transformer | undefined
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
type GetParamsProps = {
|
|
@@ -42,23 +42,32 @@ function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
|
42
42
|
})
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
const getTransformer: Transformer = ({ operation, schemas }) => {
|
|
46
46
|
const path = new URLPath(operation.path)
|
|
47
|
-
const params = getParams({ pathParamsType, typeSchemas })
|
|
48
47
|
const keys = [
|
|
49
48
|
path.toObject({
|
|
50
49
|
type: 'path',
|
|
51
50
|
stringify: true,
|
|
52
51
|
}),
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
schemas.queryParams?.name ? '...(params ? [params] : [])' : undefined,
|
|
53
|
+
schemas.request?.name ? '...(data ? [data] : [])' : undefined,
|
|
55
54
|
].filter(Boolean)
|
|
56
55
|
|
|
56
|
+
return keys
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
|
|
60
|
+
const params = getParams({ pathParamsType, typeSchemas })
|
|
61
|
+
const keys = transformer({
|
|
62
|
+
operation,
|
|
63
|
+
schemas: typeSchemas,
|
|
64
|
+
})
|
|
65
|
+
|
|
57
66
|
return (
|
|
58
67
|
<>
|
|
59
68
|
<File.Source name={name} isExportable isIndexable>
|
|
60
69
|
<Function.Arrow name={name} export params={params.toConstructor()} singleLine>
|
|
61
|
-
{`[${
|
|
70
|
+
{`[${keys.join(', ')}] as const`}
|
|
62
71
|
</Function.Arrow>
|
|
63
72
|
</File.Source>
|
|
64
73
|
<File.Source name={typeName} isExportable isIndexable isTypeOnly>
|
|
@@ -71,3 +80,4 @@ export function QueryKey({ name, typeSchemas, pathParamsType, operation, typeNam
|
|
|
71
80
|
}
|
|
72
81
|
|
|
73
82
|
QueryKey.getParams = getParams
|
|
83
|
+
QueryKey.getTransformer = getTransformer
|
|
@@ -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
|
|
|
@@ -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 "@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
|
|
|
@@ -21,6 +21,8 @@ export const mutationGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
21
21
|
const isQuery = typeof options.query === 'boolean' ? true : options.query?.methods.some((method) => operation.method === method)
|
|
22
22
|
const isMutation = !isQuery && options.mutation && options.mutation.methods.some((method) => operation.method === method)
|
|
23
23
|
|
|
24
|
+
const importPath = options.mutation ? options.mutation.importPath : '@tanstack/svelte-query'
|
|
25
|
+
|
|
24
26
|
const mutation = {
|
|
25
27
|
name: getName(operation, { type: 'function', prefix: 'create' }),
|
|
26
28
|
typeName: getName(operation, { type: 'type' }),
|
|
@@ -47,15 +49,14 @@ export const mutationGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
47
49
|
typeName: getName(operation, { type: 'type', suffix: 'MutationKey' }),
|
|
48
50
|
}
|
|
49
51
|
|
|
50
|
-
if (!isMutation
|
|
52
|
+
if (!isMutation) {
|
|
51
53
|
return null
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
return (
|
|
55
57
|
<File baseName={mutation.file.baseName} path={mutation.file.path} meta={mutation.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
56
58
|
{options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={mutation.file.path} path={zod.file.path} />}
|
|
57
|
-
|
|
58
|
-
<File.Import name={['CreateMutationOptions', 'CreateMutationResult']} path={options.mutation.importPath} isTypeOnly />
|
|
59
|
+
|
|
59
60
|
<File.Import name={'client'} path={options.client.importPath} />
|
|
60
61
|
<File.Import name={['RequestConfig', 'ResponseConfig']} path={options.client.importPath} isTypeOnly />
|
|
61
62
|
<File.Import
|
|
@@ -71,19 +72,20 @@ export const mutationGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
71
72
|
path={type.file.path}
|
|
72
73
|
isTypeOnly
|
|
73
74
|
/>
|
|
75
|
+
|
|
74
76
|
<MutationKey
|
|
75
77
|
name={mutationKey.name}
|
|
76
78
|
typeName={mutationKey.typeName}
|
|
77
79
|
operation={operation}
|
|
78
80
|
pathParamsType={options.pathParamsType}
|
|
79
81
|
typeSchemas={type.schemas}
|
|
80
|
-
|
|
82
|
+
transformer={options.mutationKey}
|
|
81
83
|
/>
|
|
82
84
|
<Client
|
|
83
85
|
name={client.name}
|
|
84
86
|
isExportable={false}
|
|
85
87
|
isIndexable={false}
|
|
86
|
-
baseURL={options.baseURL}
|
|
88
|
+
baseURL={options.client.baseURL}
|
|
87
89
|
operation={operation}
|
|
88
90
|
typeSchemas={type.schemas}
|
|
89
91
|
zodSchemas={zod.schemas}
|
|
@@ -92,17 +94,23 @@ export const mutationGenerator = createReactGenerator<PluginSvelteQuery>({
|
|
|
92
94
|
pathParamsType={options.pathParamsType}
|
|
93
95
|
parser={options.parser}
|
|
94
96
|
/>
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
+
)}
|
|
106
114
|
</File>
|
|
107
115
|
)
|
|
108
116
|
},
|