@kubb/plugin-svelte-query 3.0.0-beta.8 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/{chunk-IYE4XII3.cjs → chunk-CDRGJAED.cjs} +71 -56
  2. package/dist/chunk-CDRGJAED.cjs.map +1 -0
  3. package/dist/{chunk-STYJ2DL3.js → chunk-JGITTOE5.js} +65 -50
  4. package/dist/chunk-JGITTOE5.js.map +1 -0
  5. package/dist/{chunk-WAAKXO6O.cjs → chunk-KRGCKSGR.cjs} +145 -29
  6. package/dist/chunk-KRGCKSGR.cjs.map +1 -0
  7. package/dist/{chunk-B7GVNGYU.js → chunk-R6ZVBNG7.js} +145 -29
  8. package/dist/chunk-R6ZVBNG7.js.map +1 -0
  9. package/dist/components.cjs +6 -6
  10. package/dist/components.d.cts +17 -10
  11. package/dist/components.d.ts +17 -10
  12. package/dist/components.js +1 -1
  13. package/dist/generators.cjs +4 -4
  14. package/dist/generators.d.cts +1 -1
  15. package/dist/generators.d.ts +1 -1
  16. package/dist/generators.js +2 -2
  17. package/dist/index.cjs +23 -24
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.js +22 -23
  22. package/dist/index.js.map +1 -1
  23. package/dist/types-B9W9aYra.d.cts +365 -0
  24. package/dist/types-B9W9aYra.d.ts +365 -0
  25. package/package.json +13 -13
  26. package/src/components/Mutation.tsx +7 -3
  27. package/src/components/MutationKey.tsx +11 -5
  28. package/src/components/Query.tsx +62 -6
  29. package/src/components/QueryKey.tsx +17 -7
  30. package/src/components/QueryOptions.tsx +47 -7
  31. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +1 -1
  32. package/src/generators/__snapshots__/clientGetImportPath.ts +1 -1
  33. package/src/generators/__snapshots__/findByTags.ts +1 -1
  34. package/src/generators/__snapshots__/findByTagsObject.ts +60 -0
  35. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +1 -1
  36. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +2 -2
  37. package/src/generators/__snapshots__/findByTagsWithZod.ts +1 -1
  38. package/src/generators/__snapshots__/postAsQuery.ts +1 -1
  39. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +1 -3
  40. package/src/generators/mutationGenerator.tsx +25 -16
  41. package/src/generators/queryGenerator.tsx +25 -17
  42. package/src/plugin.ts +22 -21
  43. package/src/types.ts +35 -14
  44. package/dist/chunk-B7GVNGYU.js.map +0 -1
  45. package/dist/chunk-IYE4XII3.cjs.map +0 -1
  46. package/dist/chunk-STYJ2DL3.js.map +0 -1
  47. package/dist/chunk-WAAKXO6O.cjs.map +0 -1
  48. package/dist/types-CvXX_phR.d.cts +0 -184
  49. package/dist/types-CvXX_phR.d.ts +0 -184
@@ -0,0 +1,365 @@
1
+ import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
2
+ import { HttpMethod, Operation } from '@kubb/oas';
3
+ import { ResolvePathOptions, Exclude, Include, Override, Generator, OperationSchemas } from '@kubb/plugin-oas';
4
+
5
+ type Options$2 = {
6
+ /**
7
+ * Specify the export location for the files and define the behavior of the output
8
+ * @default { path: 'clients', barrelType: 'named' }
9
+ */
10
+ output?: Output;
11
+ /**
12
+ * Group the clients based on the provided name.
13
+ */
14
+ group?: Group;
15
+ /**
16
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
17
+ */
18
+ exclude?: Array<Exclude>;
19
+ /**
20
+ * Array containing include parameters to include tags/operations/methods/paths.
21
+ */
22
+ include?: Array<Include>;
23
+ /**
24
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
25
+ */
26
+ override?: Array<Override<ResolvedOptions$2>>;
27
+ /**
28
+ * Create `operations.ts` file with all operations grouped by methods.
29
+ * @default false
30
+ */
31
+ operations?: boolean;
32
+ /**
33
+ * Path to the client import path that will be used to do the API calls.
34
+ * It will be used as `import client from '${client.importPath}'`.
35
+ * It allows both relative and absolute path but be aware that we will not change the path.
36
+ * @default '@kubb/plugin-client/client'
37
+ */
38
+ importPath?: string;
39
+ /**
40
+ * Allows you to set a custom base url for all generated calls.
41
+ */
42
+ baseURL?: string;
43
+ /**
44
+ * ReturnType that will be used when calling the client.
45
+ * - 'data' will return ResponseConfig[data].
46
+ * - 'full' will return ResponseConfig.
47
+ * @default 'data'
48
+ */
49
+ dataReturnType?: 'data' | 'full';
50
+ /**
51
+ * How to pass your params
52
+ * - 'object' will return the params and pathParams as an object.
53
+ * - 'inline' will return the params as comma separated params.
54
+ * @default 'inline'
55
+ */
56
+ paramsType?: 'object' | 'inline';
57
+ /**
58
+ * How to pass your pathParams.
59
+ * - 'object' will return the pathParams as an object.
60
+ * - 'inline' will return the pathParams as comma separated params.
61
+ * @default 'inline'
62
+ */
63
+ pathParamsType?: 'object' | 'inline';
64
+ /**
65
+ * Which parser can be used before returning the data
66
+ * - 'zod' will use `@kubb/plugin-zod` to parse the data.
67
+ * @default 'client'
68
+ */
69
+ parser?: 'client' | 'zod';
70
+ transformers?: {
71
+ /**
72
+ * Customize the names based on the type that is provided by the plugin.
73
+ */
74
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
75
+ };
76
+ /**
77
+ * Define some generators next to the client generators
78
+ */
79
+ generators?: Array<Generator<PluginClient>>;
80
+ };
81
+ type ResolvedOptions$2 = {
82
+ output: Output;
83
+ group?: Options$2['group'];
84
+ baseURL: string | undefined;
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']>>;
230
+ pathParamsType: NonNullable<Options$1['pathParamsType']>;
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;
241
+ };
242
+ type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options$1, ResolvedOptions$1, never, ResolvePathOptions>;
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;
257
+ type Query = {
258
+ /**
259
+ * Define which HttpMethods can be used for queries
260
+ * @default ['get']
261
+ */
262
+ methods: Array<HttpMethod>;
263
+ /**
264
+ * Path to the useQuery that will be used to do the useQuery functionality.
265
+ * It will be used as `import { useQuery } from '${importPath}'`.
266
+ * It allows both relative and absolute path.
267
+ * the path will be applied as is, so relative path should be based on the file being generated.
268
+ * @default '@tanstack/svelte-query'
269
+ */
270
+ importPath?: string;
271
+ };
272
+ type Mutation = {
273
+ /**
274
+ * Define which HttpMethods can be used for mutations
275
+ * @default ['post', 'put', 'delete']
276
+ */
277
+ methods: Array<HttpMethod>;
278
+ /**
279
+ * Path to the useQuery that will be used to do the useQuery functionality.
280
+ * It will be used as `import { useQuery } from '${importPath}'`.
281
+ * It allows both relative and absolute path.
282
+ * the path will be applied as is, so relative path should be based on the file being generated.
283
+ * @default '@tanstack/svelte-query'
284
+ */
285
+ importPath?: string;
286
+ };
287
+ type Options = {
288
+ /**
289
+ * Specify the export location for the files and define the behavior of the output
290
+ * @default { path: 'hooks', barrelType: 'named' }
291
+ */
292
+ output?: Output;
293
+ /**
294
+ * Group the @tanstack/query hooks based on the provided name.
295
+ */
296
+ group?: Group;
297
+ client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath' | 'baseURL'>;
298
+ /**
299
+ * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
300
+ */
301
+ exclude?: Array<Exclude>;
302
+ /**
303
+ * Array containing include parameters to include tags/operations/methods/paths.
304
+ */
305
+ include?: Array<Include>;
306
+ /**
307
+ * Array containing override parameters to override `options` based on tags/operations/methods/paths.
308
+ */
309
+ override?: Array<Override<ResolvedOptions>>;
310
+ /**
311
+ * How to pass your params
312
+ * - 'object' will return the params and pathParams as an object.
313
+ * - 'inline' will return the params as comma separated params.
314
+ * @default 'inline'
315
+ */
316
+ paramsType?: 'object' | 'inline';
317
+ /**
318
+ * How to pass your pathParams.
319
+ * - 'object' will return the pathParams as an object.
320
+ * - 'inline' will return the pathParams as comma separated params.
321
+ * @default 'inline'
322
+ */
323
+ pathParamsType?: PluginClient['options']['pathParamsType'];
324
+ queryKey?: QueryKey;
325
+ /**
326
+ * Override some useQuery behaviours.
327
+ */
328
+ query?: Partial<Query> | false;
329
+ mutationKey?: MutationKey;
330
+ /**
331
+ * Override some useMutation behaviours.
332
+ */
333
+ mutation?: Mutation | false;
334
+ /**
335
+ * Which parser should be used before returning the data to `@tanstack/query`.
336
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
337
+ */
338
+ parser?: PluginClient['options']['parser'];
339
+ transformers?: {
340
+ /**
341
+ * Customize the names based on the type that is provided by the plugin.
342
+ */
343
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
344
+ };
345
+ /**
346
+ * Define some generators next to the svelte-query generators
347
+ */
348
+ generators?: Array<Generator<PluginSvelteQuery>>;
349
+ };
350
+ type ResolvedOptions = {
351
+ output: Output;
352
+ client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & {
353
+ baseURL?: string;
354
+ };
355
+ parser: Required<NonNullable<Options['parser']>>;
356
+ paramsType: NonNullable<Options['paramsType']>;
357
+ pathParamsType: NonNullable<Options['pathParamsType']>;
358
+ queryKey: QueryKey | undefined;
359
+ query: NonNullable<Required<Query>> | false;
360
+ mutationKey: MutationKey | undefined;
361
+ mutation: NonNullable<Required<Mutation>> | false;
362
+ };
363
+ type PluginSvelteQuery = PluginFactoryOptions<'plugin-svelte-query', Options, ResolvedOptions, never, ResolvePathOptions>;
364
+
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.8",
3
+ "version": "3.0.0",
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.8",
66
- "@kubb/fs": "3.0.0-beta.8",
67
- "@kubb/oas": "3.0.0-beta.8",
68
- "@kubb/plugin-oas": "3.0.0-beta.8",
69
- "@kubb/plugin-ts": "3.0.0-beta.8",
70
- "@kubb/plugin-zod": "3.0.0-beta.8",
71
- "@kubb/react": "3.0.0-beta.8"
65
+ "@kubb/core": "3.0.0",
66
+ "@kubb/fs": "3.0.0",
67
+ "@kubb/oas": "3.0.0",
68
+ "@kubb/plugin-oas": "3.0.0",
69
+ "@kubb/plugin-ts": "3.0.0",
70
+ "@kubb/plugin-zod": "3.0.0",
71
+ "@kubb/react": "3.0.0"
72
72
  },
73
73
  "devDependencies": {
74
- "@types/react": "^18.3.11",
74
+ "@types/react": "^18.3.12",
75
75
  "react": "^18.3.1",
76
- "tsup": "^8.3.0",
76
+ "tsup": "^8.3.5",
77
77
  "typescript": "^5.6.3",
78
- "@kubb/config-ts": "3.0.0-beta.8",
79
- "@kubb/config-tsup": "3.0.0-beta.8"
78
+ "@kubb/config-ts": "3.0.0",
79
+ "@kubb/config-tsup": "3.0.0"
80
80
  },
81
81
  "peerDependencies": {
82
- "@kubb/react": "3.0.0-beta.8"
82
+ "@kubb/react": "3.0.0"
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}}`].join(', ')
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>
@@ -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
- keysFn: ((keys: unknown[]) => unknown[]) | undefined
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
- export function MutationKey({ name, typeSchemas, pathParamsType, operation, typeName, keysFn = (name) => name }: Props): ReactNode {
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 = [JSON.stringify({ url: path.path })].filter(Boolean)
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
- {`[${keysFn(keys).join(', ')}] as const`}
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
@@ -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
- mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
37
- children: getPathParams(typeSchemas.pathParams, { typed: true }),
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({ name, queryKeyTypeName, queryOptionsName, queryKeyName, pathParamsType, dataReturnType, typeSchemas, operation }: Props): ReactNode {
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,
@@ -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
- keysFn: ((keys: unknown[]) => unknown[]) | undefined
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
- export function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, keysFn = (name) => name }: Props): ReactNode {
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
- typeSchemas.queryParams?.name ? '...(params ? [params] : [])' : undefined,
54
- typeSchemas.request?.name ? '...(data ? [data] : [])' : undefined,
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
- {`[${keysFn(keys).join(', ')}] as const`}
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