@kubb/plugin-vue-query 3.0.0-alpha.31 → 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.
Files changed (42) hide show
  1. package/README.md +1 -1
  2. package/dist/{chunk-FSQSBTBH.cjs → chunk-5MY3SE2R.cjs} +220 -18
  3. package/dist/chunk-5MY3SE2R.cjs.map +1 -0
  4. package/dist/{chunk-V6YETPDM.js → chunk-DWWRCRGY.js} +220 -18
  5. package/dist/chunk-DWWRCRGY.js.map +1 -0
  6. package/dist/{chunk-IAQL3OW6.cjs → chunk-PGNSMLGU.cjs} +31 -21
  7. package/dist/chunk-PGNSMLGU.cjs.map +1 -0
  8. package/dist/{chunk-CTBTK7UQ.js → chunk-YQOJHRKU.js} +18 -8
  9. package/dist/chunk-YQOJHRKU.js.map +1 -0
  10. package/dist/components.cjs +8 -8
  11. package/dist/components.d.cts +19 -10
  12. package/dist/components.d.ts +19 -10
  13. package/dist/components.js +1 -1
  14. package/dist/generators.cjs +5 -5
  15. package/dist/generators.d.cts +1 -1
  16. package/dist/generators.d.ts +1 -1
  17. package/dist/generators.js +2 -2
  18. package/dist/index.cjs +6 -5
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +1 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.js +5 -4
  23. package/dist/index.js.map +1 -1
  24. package/dist/{types-BGytoVFN.d.cts → types-Dx6yZliF.d.cts} +101 -40
  25. package/dist/{types-BGytoVFN.d.ts → types-Dx6yZliF.d.ts} +101 -40
  26. package/package.json +14 -14
  27. package/src/components/InfiniteQuery.tsx +54 -1
  28. package/src/components/InfiniteQueryOptions.tsx +49 -2
  29. package/src/components/Mutation.tsx +7 -3
  30. package/src/components/Query.tsx +65 -2
  31. package/src/components/QueryOptions.tsx +50 -3
  32. package/src/generators/__snapshots__/findByTagsObject.ts +62 -0
  33. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +1 -3
  34. package/src/generators/infiniteQueryGenerator.tsx +3 -1
  35. package/src/generators/mutationGenerator.tsx +2 -1
  36. package/src/generators/queryGenerator.tsx +3 -1
  37. package/src/plugin.ts +3 -2
  38. package/src/types.ts +18 -41
  39. package/dist/chunk-CTBTK7UQ.js.map +0 -1
  40. package/dist/chunk-FSQSBTBH.cjs.map +0 -1
  41. package/dist/chunk-IAQL3OW6.cjs.map +0 -1
  42. package/dist/chunk-V6YETPDM.js.map +0 -1
@@ -2,6 +2,90 @@ import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/co
2
2
  import { HttpMethod } from '@kubb/oas';
3
3
  import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
4
4
 
5
+ type Options$1 = {
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$1>>;
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
+ * ReturnType that will be used when calling the client.
41
+ * - 'data' will return ResponseConfig[data].
42
+ * - 'full' will return ResponseConfig.
43
+ * @default 'data'
44
+ */
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';
53
+ /**
54
+ * How to pass your pathParams.
55
+ * - 'object' will return the pathParams as an object.
56
+ * - 'inline' will return the pathParams as comma separated params.
57
+ * @default 'inline'
58
+ */
59
+ pathParamsType?: 'object' | 'inline';
60
+ /**
61
+ * Which parser can be used before returning the data
62
+ * - 'zod' will use `@kubb/plugin-zod` to parse the data.
63
+ * @default 'client'
64
+ */
65
+ parser?: 'client' | 'zod';
66
+ transformers?: {
67
+ /**
68
+ * Customize the names based on the type that is provided by the plugin.
69
+ */
70
+ name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
71
+ };
72
+ /**
73
+ * Define some generators next to the client generators
74
+ */
75
+ generators?: Array<Generator<PluginClient>>;
76
+ };
77
+ type ResolvedOptions$1 = {
78
+ output: Output;
79
+ group?: Options$1['group'];
80
+ baseURL: string | undefined;
81
+ parser: NonNullable<Options$1['parser']>;
82
+ importPath: NonNullable<Options$1['importPath']>;
83
+ dataReturnType: NonNullable<Options$1['dataReturnType']>;
84
+ pathParamsType: NonNullable<Options$1['pathParamsType']>;
85
+ paramsType: NonNullable<Options$1['paramsType']>;
86
+ };
87
+ type PluginClient = PluginFactoryOptions<'plugin-client', Options$1, ResolvedOptions$1, never, ResolvePathOptions>;
88
+
5
89
  type Query = {
6
90
  /**
7
91
  * Customize the queryKey, here you can specify a suffix.
@@ -43,7 +127,6 @@ type Mutation = {
43
127
  type Infinite = {
44
128
  /**
45
129
  * Specify the params key used for `pageParam`.
46
- * Used inside `useInfiniteQuery`, `createInfiniteQueries`, `createInfiniteQuery`
47
130
  * @default `'id'`
48
131
  */
49
132
  queryParam: string;
@@ -59,42 +142,15 @@ type Infinite = {
59
142
  };
60
143
  type Options = {
61
144
  /**
62
- * @default 'hooks'
145
+ * Specify the export location for the files and define the behavior of the output
146
+ * @default { path: 'hooks', barrelType: 'named' }
63
147
  */
64
148
  output?: Output;
65
149
  /**
66
150
  * Group the @tanstack/query hooks based on the provided name.
67
151
  */
68
152
  group?: Group;
69
- client?: {
70
- /**
71
- * Path to the client that will be used to do the API calls.
72
- * It will be used as `import client from '${client.importPath}'`.
73
- * It allows both relative and absolute path.
74
- * the path will be applied as is, so relative path should be based on the file being generated.
75
- * @default '@kubb/plugin-client/client'
76
- */
77
- importPath?: string;
78
- /**
79
- * ReturnType that needs to be used when calling client().
80
- *
81
- * `Data` will return ResponseConfig[data].
82
- *
83
- * `Full` will return ResponseConfig.
84
- * @default `'data'`
85
- * @private
86
- */
87
- dataReturnType?: 'data' | 'full';
88
- };
89
- /**
90
- * ReturnType that needs to be used when calling client().
91
- *
92
- * `Data` will return ResponseConfig[data].
93
- *
94
- * `Full` will return ResponseConfig.
95
- * @default `'data'`
96
- * @private
97
- */
153
+ client?: Pick<PluginClient['options'], 'dataReturnType' | 'importPath'>;
98
154
  /**
99
155
  * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
100
156
  */
@@ -107,16 +163,20 @@ type Options = {
107
163
  * Array containing override parameters to override `options` based on tags/operations/methods/paths.
108
164
  */
109
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';
110
173
  /**
111
174
  * How to pass your pathParams.
112
- *
113
- * `object` will return the pathParams as an object.
114
- *
115
- * `inline` will return the pathParams as comma separated params.
116
- * @default `'inline'`
117
- * @private
175
+ * - 'object' will return the pathParams as an object.
176
+ * - 'inline' will return the pathParams as comma separated params.
177
+ * @default 'inline'
118
178
  */
119
- pathParamsType?: 'object' | 'inline';
179
+ pathParamsType?: PluginClient['options']['pathParamsType'];
120
180
  /**
121
181
  * When set, an infiniteQuery hooks will be added.
122
182
  */
@@ -130,10 +190,10 @@ type Options = {
130
190
  */
131
191
  mutation?: Mutation | false;
132
192
  /**
133
- * Which parser can be used before returning the data to `@tanstack/query`.
193
+ * Which parser should be used before returning the data to `@tanstack/query`.
134
194
  * `'zod'` will use `@kubb/plugin-zod` to parse the data.
135
195
  */
136
- parser?: 'client' | 'zod';
196
+ parser?: PluginClient['options']['parser'];
137
197
  transformers?: {
138
198
  /**
139
199
  * Customize the names based on the type that is provided by the plugin.
@@ -150,6 +210,7 @@ type ResolvedOptions = {
150
210
  baseURL: string | undefined;
151
211
  client: Required<NonNullable<PluginVueQuery['options']['client']>>;
152
212
  parser: Required<NonNullable<Options['parser']>>;
213
+ paramsType: NonNullable<Options['paramsType']>;
153
214
  pathParamsType: NonNullable<Options['pathParamsType']>;
154
215
  /**
155
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-alpha.31",
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-alpha.31",
66
- "@kubb/fs": "3.0.0-alpha.31",
67
- "@kubb/oas": "3.0.0-alpha.31",
68
- "@kubb/plugin-oas": "3.0.0-alpha.31",
69
- "@kubb/plugin-ts": "3.0.0-alpha.31",
70
- "@kubb/plugin-zod": "3.0.0-alpha.31",
71
- "@kubb/react": "3.0.0-alpha.31"
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.10",
74
+ "@types/react": "^18.3.12",
75
75
  "react": "^18.3.1",
76
- "tsup": "^8.3.0",
77
- "typescript": "^5.6.2",
78
- "@kubb/config-ts": "3.0.0-alpha.31",
79
- "@kubb/config-tsup": "3.0.0-alpha.31"
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-alpha.31"
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}}`].join(', ')
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>
@@ -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({ name, queryKeyTypeName, queryOptionsName, queryKeyName, pathParamsType, dataReturnType, typeSchemas, operation }: Props): ReactNode {
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
  })