@kubb/plugin-react-query 3.0.0-alpha.9 → 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 (79) hide show
  1. package/README.md +14 -5
  2. package/dist/chunk-24SL7I66.cjs +683 -0
  3. package/dist/chunk-24SL7I66.cjs.map +1 -0
  4. package/dist/chunk-BML6BZ4F.cjs +878 -0
  5. package/dist/chunk-BML6BZ4F.cjs.map +1 -0
  6. package/dist/chunk-JFIGHRBM.js +867 -0
  7. package/dist/chunk-JFIGHRBM.js.map +1 -0
  8. package/dist/chunk-LBVGJA4Q.js +674 -0
  9. package/dist/chunk-LBVGJA4Q.js.map +1 -0
  10. package/dist/components.cjs +39 -12
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +172 -6
  13. package/dist/components.d.ts +172 -6
  14. package/dist/components.js +2 -12
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +25 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +14 -0
  19. package/dist/generators.d.ts +14 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +80 -130
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +1 -4
  25. package/dist/index.d.ts +1 -4
  26. package/dist/index.js +63 -120
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-Dlwxp28D.d.cts +230 -0
  29. package/dist/types-Dlwxp28D.d.ts +230 -0
  30. package/package.json +22 -17
  31. package/src/components/InfiniteQuery.tsx +176 -0
  32. package/src/components/InfiniteQueryOptions.tsx +185 -0
  33. package/src/components/Mutation.tsx +142 -320
  34. package/src/components/MutationKey.tsx +48 -0
  35. package/src/components/Query.tsx +145 -592
  36. package/src/components/QueryKey.tsx +51 -182
  37. package/src/components/QueryOptions.tsx +110 -472
  38. package/src/components/SuspenseQuery.tsx +176 -0
  39. package/src/components/index.ts +4 -0
  40. package/src/generators/__snapshots__/clientDataReturnTypeFull.ts +51 -0
  41. package/src/generators/__snapshots__/clientGetImportPath.ts +51 -0
  42. package/src/generators/__snapshots__/clientPostImportPath.ts +44 -0
  43. package/src/generators/__snapshots__/findByTags.ts +51 -0
  44. package/src/generators/__snapshots__/findByTagsObject.ts +60 -0
  45. package/src/generators/__snapshots__/findByTagsPathParamsObject.ts +51 -0
  46. package/src/generators/__snapshots__/findByTagsWithCustomQueryKey.ts +51 -0
  47. package/src/generators/__snapshots__/findByTagsWithZod.ts +51 -0
  48. package/src/generators/__snapshots__/findInfiniteByTags.ts +57 -0
  49. package/src/generators/__snapshots__/findInfiniteByTagsCursor.ts +57 -0
  50. package/src/generators/__snapshots__/getAsMutation.ts +31 -0
  51. package/src/generators/__snapshots__/postAsQuery.ts +50 -0
  52. package/src/generators/__snapshots__/updatePetById.ts +44 -0
  53. package/src/generators/__snapshots__/updatePetByIdPathParamsObject.ts +44 -0
  54. package/src/generators/index.ts +4 -0
  55. package/src/generators/infiniteQueryGenerator.tsx +126 -0
  56. package/src/generators/mutationGenerator.tsx +109 -0
  57. package/src/generators/queryGenerator.tsx +123 -0
  58. package/src/generators/suspenseQueryGenerator.tsx +123 -0
  59. package/src/plugin.ts +62 -76
  60. package/src/types.ts +49 -126
  61. package/dist/chunk-7ZODZVKP.cjs +0 -1470
  62. package/dist/chunk-7ZODZVKP.cjs.map +0 -1
  63. package/dist/chunk-ZYTZV43V.js +0 -1470
  64. package/dist/chunk-ZYTZV43V.js.map +0 -1
  65. package/dist/index-5kpkk-7M.d.cts +0 -545
  66. package/dist/index-5kpkk-7M.d.ts +0 -545
  67. package/src/OperationGenerator.tsx +0 -57
  68. package/src/__snapshots__/mutateAsQuery/updatePetWithForm.ts +0 -69
  69. package/src/__snapshots__/pathParamsTypeInline/getPetById.ts +0 -62
  70. package/src/__snapshots__/pathParamsTypeObject/getPetById.ts +0 -68
  71. package/src/__snapshots__/queryOptions/getPetById.ts +0 -41
  72. package/src/__snapshots__/queryWithoutQueryOptions/getPetById.ts +0 -51
  73. package/src/__snapshots__/variablesTypeMutate/deletePet.ts +0 -24
  74. package/src/components/QueryImports.tsx +0 -167
  75. package/src/components/SchemaType.tsx +0 -59
  76. package/src/components/__snapshots__/gen/showPetById.ts +0 -67
  77. package/src/components/__snapshots__/gen/useCreatePets.ts +0 -46
  78. package/src/components/__snapshots__/gen/useCreatePetsMutate.ts +0 -46
  79. package/src/utils.ts +0 -96
@@ -1,495 +1,133 @@
1
- import { PackageManager } from '@kubb/core'
2
- import transformers from '@kubb/core/transformers'
3
- import { FunctionParams, URLPath } from '@kubb/core/utils'
4
- import { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
5
- import { getASTParams } from '@kubb/plugin-oas/utils'
6
- import { Function, useApp, File } from '@kubb/react'
7
- import { pluginZodName } from '@kubb/plugin-zod'
1
+ import { getPathParams } from '@kubb/plugin-oas/utils'
2
+ import { File, Function, FunctionParams } from '@kubb/react'
8
3
 
9
- import { isRequired } from '@kubb/oas'
10
- import type { HttpMethod } from '@kubb/oas'
11
4
  import type { ReactNode } from 'react'
12
- import type { Infinite, PluginReactQuery, Suspense } from '../types.ts'
13
- import { pluginTsName } from '@kubb/plugin-ts'
14
- import { reactQueryDepRegex } from '../utils.ts'
15
5
 
16
- type TemplateProps = {
17
- /**
18
- * Name of the function
19
- */
6
+ import { isOptional } from '@kubb/oas'
7
+ import { Client } from '@kubb/plugin-client/components'
8
+ import type { OperationSchemas } from '@kubb/plugin-oas'
9
+ import type { PluginReactQuery } from '../types.ts'
10
+ import { QueryKey } from './QueryKey.tsx'
11
+
12
+ type Props = {
20
13
  name: string
21
- /**
22
- * Parameters/options/props that need to be used
23
- */
24
- params: string
25
- /**
26
- * Generics that needs to be added for TypeScript
27
- */
28
- generics?: string
29
- /**
30
- * ReturnType(see async for adding Promise type)
31
- */
32
- returnType?: string
33
- /**
34
- * Options for JSdocs
35
- */
36
- JSDoc?: {
37
- comments: string[]
38
- }
39
- hook: {
40
- queryKey: string
41
- children?: string
42
- }
43
- client: {
44
- generics: string
45
- method: HttpMethod
46
- path: URLPath
47
- withQueryParams: boolean
48
- withPathParams: boolean
49
- withData: boolean
50
- withHeaders: boolean
51
- contentType: string
52
- }
53
- infinite: Infinite | false
54
- dataReturnType: NonNullable<PluginReactQuery['options']['dataReturnType']>
55
- parser: string | undefined
14
+ clientName: string
15
+ queryKeyName: string
16
+ typeSchemas: OperationSchemas
17
+ paramsType: PluginReactQuery['resolvedOptions']['paramsType']
18
+ pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
56
19
  }
57
20
 
58
- function Template({ name, params, generics, returnType, JSDoc, hook, client, infinite, dataReturnType, parser }: TemplateProps): ReactNode {
59
- const isV5 = new PackageManager().isValidSync(reactQueryDepRegex, '>=5')
60
- const isFormData = client.contentType === 'multipart/form-data'
61
- const headers = [
62
- client.contentType !== 'application/json' ? `'Content-Type': '${client.contentType}'` : undefined,
63
- client.withHeaders ? '...headers' : undefined,
64
- ]
65
- .filter(Boolean)
66
- .join(', ')
21
+ type GetParamsProps = {
22
+ paramsType: PluginReactQuery['resolvedOptions']['paramsType']
23
+ pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
24
+ typeSchemas: OperationSchemas
25
+ }
67
26
 
68
- const clientOptions = [
69
- `method: "${client.method}"`,
70
- `url: ${client.path.template}`,
71
- client.withQueryParams && !infinite ? 'params' : undefined,
72
- client.withData && !isFormData ? 'data' : undefined,
73
- client.withData && isFormData ? 'data: formData' : undefined,
74
- headers.length ? `headers: { ${headers}, ...options.headers }` : undefined,
75
- '...options',
76
- client.withQueryParams && !!infinite
77
- ? `params: {
78
- ...params,
79
- ['${infinite.queryParam}']: pageParam,
80
- ...(options.params || {}),
81
- }`
82
- : undefined,
83
- ].filter(Boolean)
27
+ function getParams({ paramsType, pathParamsType, typeSchemas }: GetParamsProps) {
28
+ if (paramsType === 'object') {
29
+ return FunctionParams.factory({
30
+ data: {
31
+ mode: 'object',
32
+ children: {
33
+ ...getPathParams(typeSchemas.pathParams, { typed: true }),
34
+ data: typeSchemas.request?.name
35
+ ? {
36
+ type: typeSchemas.request?.name,
37
+ optional: isOptional(typeSchemas.request?.schema),
38
+ }
39
+ : undefined,
40
+ params: typeSchemas.queryParams?.name
41
+ ? {
42
+ type: typeSchemas.queryParams?.name,
43
+ optional: isOptional(typeSchemas.queryParams?.schema),
44
+ }
45
+ : undefined,
46
+ headers: typeSchemas.headerParams?.name
47
+ ? {
48
+ type: typeSchemas.headerParams?.name,
49
+ optional: isOptional(typeSchemas.headerParams?.schema),
50
+ }
51
+ : undefined,
52
+ },
53
+ },
54
+ config: {
55
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>',
56
+ default: '{}',
57
+ },
58
+ })
59
+ }
84
60
 
85
- const queryOptions = [
86
- isV5 && !!infinite ? `initialPageParam: ${infinite.initialPageParam}` : undefined,
87
- isV5 && !!infinite && !!infinite.cursorParam ? `getNextPageParam: (lastPage) => lastPage['${infinite.cursorParam}']` : undefined,
88
- isV5 && !!infinite && !!infinite.cursorParam ? `getPreviousPageParam: (firstPage) => firstPage['${infinite.cursorParam}']` : undefined,
89
- isV5 && !!infinite && !infinite.cursorParam && dataReturnType === 'full'
90
- ? 'getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1'
61
+ return FunctionParams.factory({
62
+ pathParams: typeSchemas.pathParams?.name
63
+ ? {
64
+ mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
65
+ children: getPathParams(typeSchemas.pathParams, { typed: true }),
66
+ type: typeSchemas.pathParams?.name,
67
+ optional: isOptional(typeSchemas.pathParams?.schema),
68
+ }
91
69
  : undefined,
92
- isV5 && !!infinite && !infinite.cursorParam && dataReturnType === 'data'
93
- ? 'getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1'
70
+ data: typeSchemas.request?.name
71
+ ? {
72
+ type: typeSchemas.request?.name,
73
+ optional: isOptional(typeSchemas.request?.schema),
74
+ }
94
75
  : undefined,
95
- isV5 && !!infinite && !infinite.cursorParam
96
- ? 'getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1'
76
+ params: typeSchemas.queryParams?.name
77
+ ? {
78
+ type: typeSchemas.queryParams?.name,
79
+ optional: isOptional(typeSchemas.queryParams?.schema),
80
+ }
97
81
  : undefined,
98
- ].filter(Boolean)
99
-
100
- const resolvedClientOptions = `${transformers.createIndent(4)}${clientOptions.join(`,\n${transformers.createIndent(4)}`)}`
101
- const resolvedQueryOptions = `${transformers.createIndent(4)}${queryOptions.join(`,\n${transformers.createIndent(4)}`)}`
102
-
103
- let returnRes = parser ? `return ${parser}(res.data)` : 'return res.data'
104
-
105
- if (dataReturnType === 'full') {
106
- returnRes = parser ? `return {...res, data: ${parser}(res.data)}` : 'return res'
107
- }
108
-
109
- const formData = isFormData
110
- ? `
111
- const formData = new FormData()
112
- if(data) {
113
- Object.keys(data).forEach((key) => {
114
- const value = data[key];
115
- if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
116
- formData.append(key, value);
117
- }
118
- })
119
- }
120
- `
121
- : undefined
122
-
123
- if (infinite) {
124
- if (isV5) {
125
- return (
126
- <File.Source name={name} isExportable isIndexable>
127
- <Function name={name} export params={params} JSDoc={JSDoc}>
128
- {`
129
- const queryKey = ${hook.queryKey}
130
-
131
- return infiniteQueryOptions({
132
- queryKey,
133
- queryFn: async ({ pageParam }) => {
134
- ${hook.children || ''}
135
- ${formData || ''}
136
- const res = await client<${client.generics}>({
137
- ${resolvedClientOptions}
138
- })
139
-
140
- ${returnRes}
141
- },
142
- ${resolvedQueryOptions}
143
- })
144
-
145
- `}
146
- </Function>
147
- </File.Source>
148
- )
149
- }
150
-
151
- return (
152
- <File.Source name={name} isExportable isIndexable>
153
- <Function name={name} export generics={generics} returnType={returnType} params={params} JSDoc={JSDoc}>
154
- {`
155
- const queryKey = ${hook.queryKey}
156
-
157
- return {
158
- queryKey,
159
- queryFn: async ({ pageParam }) => {
160
- ${hook.children || ''}
161
- ${formData || ''}
162
- const res = await client<${client.generics}>({
163
- ${resolvedClientOptions}
164
- })
165
-
166
- ${returnRes}
167
- },
168
- ${resolvedQueryOptions}
169
- }
170
-
171
- `}
172
- </Function>
173
- </File.Source>
174
- )
175
- }
82
+ headers: typeSchemas.headerParams?.name
83
+ ? {
84
+ type: typeSchemas.headerParams?.name,
85
+ optional: isOptional(typeSchemas.headerParams?.schema),
86
+ }
87
+ : undefined,
88
+ config: {
89
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>',
90
+ default: '{}',
91
+ },
92
+ })
93
+ }
176
94
 
177
- if (isV5) {
178
- return (
179
- <File.Source name={name} isExportable isIndexable>
180
- <Function name={name} export params={params} JSDoc={JSDoc}>
181
- {`
182
- const queryKey = ${hook.queryKey}
95
+ export function QueryOptions({ name, clientName, typeSchemas, paramsType, pathParamsType, queryKeyName }: Props): ReactNode {
96
+ const params = getParams({ paramsType, pathParamsType, typeSchemas })
97
+ const clientParams = Client.getParams({
98
+ typeSchemas,
99
+ paramsType,
100
+ pathParamsType,
101
+ })
102
+ const queryKeyParams = QueryKey.getParams({
103
+ pathParamsType,
104
+ typeSchemas,
105
+ })
183
106
 
184
- return queryOptions({
185
- queryKey,
186
- queryFn: async () => {
187
- ${hook.children || ''}
188
- ${formData || ''}
189
- const res = await client<${client.generics}>({
190
- ${resolvedClientOptions}
191
- })
107
+ const enabled = Object.entries(queryKeyParams.flatParams)
108
+ .map(([key, item]) => (item && !item.optional ? key : undefined))
109
+ .filter(Boolean)
110
+ .join('&& ')
192
111
 
193
- ${returnRes}
194
- },
195
- ${resolvedQueryOptions}
196
- })
197
-
198
- `}
199
- </Function>
200
- </File.Source>
201
- )
202
- }
112
+ const enabledText = enabled ? `enabled: !!(${enabled})` : ''
203
113
 
204
114
  return (
205
115
  <File.Source name={name} isExportable isIndexable>
206
- <Function name={name} export generics={generics} returnType={returnType} params={params} JSDoc={JSDoc}>
116
+ <Function name={name} export params={params.toConstructor()}>
207
117
  {`
208
- const queryKey = ${hook.queryKey}
209
-
210
- return {
211
- queryKey,
212
- queryFn: async () => {
213
- ${hook.children || ''}
214
- ${formData || ''}
215
- const res = await client<${client.generics}>({
216
- ${resolvedClientOptions}
217
- })
218
-
219
- ${returnRes}
220
- },
221
- ${resolvedQueryOptions}
222
- }
223
-
224
- `}
118
+ const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
119
+ return queryOptions({
120
+ ${enabledText}
121
+ queryKey,
122
+ queryFn: async ({ signal }) => {
123
+ config.signal = signal
124
+ return ${clientName}(${clientParams.toCall({})})
125
+ },
126
+ })
127
+ `}
225
128
  </Function>
226
129
  </File.Source>
227
130
  )
228
131
  }
229
132
 
230
- type FrameworkProps = TemplateProps & {
231
- context: {
232
- factory: {
233
- name: string
234
- }
235
- queryKey: string
236
- }
237
- }
238
-
239
- const defaultTemplates = {
240
- get react() {
241
- return function (props: FrameworkProps): ReactNode {
242
- return <Template {...props} />
243
- }
244
- },
245
- get solid() {
246
- return function (props: FrameworkProps): ReactNode {
247
- return <Template {...props} />
248
- }
249
- },
250
- get svelte() {
251
- return function (props: FrameworkProps): ReactNode {
252
- return <Template {...props} />
253
- }
254
- },
255
- get vue() {
256
- return function ({ client, context, ...rest }: FrameworkProps): ReactNode {
257
- const { factory, queryKey } = context
258
-
259
- const {
260
- plugin: {
261
- options: { pathParamsType },
262
- },
263
- } = useApp<PluginReactQuery>()
264
-
265
- const { getSchemas } = useOperationManager()
266
- const operation = useOperation()
267
-
268
- const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
269
- const params = new FunctionParams()
270
- const queryKeyParams = new FunctionParams()
271
-
272
- params.add([
273
- ...(pathParamsType === 'object'
274
- ? [
275
- getASTParams(schemas.pathParams, {
276
- typed: true,
277
- override: (item) => ({
278
- ...item,
279
- name: item.name ? `ref${transformers.pascalCase(item.name)}` : undefined,
280
- type: `MaybeRef<${item.type}>`,
281
- }),
282
- }),
283
- ]
284
- : getASTParams(schemas.pathParams, {
285
- typed: true,
286
- override: (item) => ({
287
- ...item,
288
- name: item.name ? `ref${transformers.pascalCase(item.name)}` : undefined,
289
- type: `MaybeRef<${item.type}>`,
290
- }),
291
- })),
292
- {
293
- name: 'refParams',
294
- type: `MaybeRef<${schemas.queryParams?.name}>`,
295
- enabled: client.withQueryParams,
296
- required: isRequired(schemas.queryParams?.schema),
297
- },
298
- {
299
- name: 'refHeaders',
300
- type: `MaybeRef<${schemas.headerParams?.name}>`,
301
- enabled: client.withHeaders,
302
- required: isRequired(schemas.headerParams?.schema),
303
- },
304
- {
305
- name: 'refData',
306
- type: `MaybeRef<${schemas.request?.name}>`,
307
- enabled: client.withData,
308
- required: isRequired(schemas.request?.schema),
309
- },
310
- {
311
- name: 'options',
312
- type: `${factory.name}['client']['parameters']`,
313
- default: '{}',
314
- },
315
- ])
316
-
317
- queryKeyParams.add([
318
- ...(pathParamsType === 'object'
319
- ? [
320
- getASTParams(schemas.pathParams, {
321
- override: (item) => ({
322
- ...item,
323
- name: item.name ? `ref${transformers.pascalCase(item.name)}` : undefined,
324
- }),
325
- }),
326
- ]
327
- : getASTParams(schemas.pathParams, {
328
- override: (item) => ({
329
- ...item,
330
- name: item.name ? `ref${transformers.pascalCase(item.name)}` : undefined,
331
- }),
332
- })),
333
- {
334
- name: 'refParams',
335
- enabled: client.withQueryParams,
336
- required: isRequired(schemas.queryParams?.schema),
337
- },
338
- {
339
- name: 'refData',
340
- enabled: client.withData,
341
- required: isRequired(schemas.request?.schema),
342
- },
343
- ])
344
-
345
- const unrefs = params.items
346
- .filter((item) => item.enabled)
347
- .map((item) => {
348
- return item.name ? `const ${transformers.camelCase(item.name.replace('ref', ''))} = unref(${item.name})` : undefined
349
- })
350
- .join('\n')
351
-
352
- const hook = {
353
- queryKey: `${queryKey}(${queryKeyParams.toString()})`,
354
- children: unrefs,
355
- }
356
-
357
- return <Template {...rest} params={params.toString()} hook={hook} client={client} />
358
- }
359
- },
360
- } as const
361
-
362
- type Props = {
363
- infinite: Infinite | false
364
- suspense: Suspense | false
365
- factory: {
366
- name: string
367
- }
368
- resultType: string
369
- /**
370
- * This will make it possible to override the default behaviour.
371
- */
372
- Template?: React.ComponentType<FrameworkProps>
373
- dataReturnType: NonNullable<PluginReactQuery['options']['dataReturnType']>
374
- }
375
-
376
- export function QueryOptions({ factory, infinite, suspense, resultType, dataReturnType, Template = defaultTemplates.react }: Props): ReactNode {
377
- const {
378
- pluginManager,
379
- plugin: {
380
- key: pluginKey,
381
- options: { parser, pathParamsType, queryOptions },
382
- },
383
- } = useApp<PluginReactQuery>()
384
-
385
- const { getSchemas } = useOperationManager()
386
- const operation = useOperation()
387
-
388
- const contentType = operation.getContentType()
389
- const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
390
- const zodSchemas = getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' })
391
-
392
- const queryKey = pluginManager.resolveName({
393
- name: [factory.name, infinite ? 'Infinite' : undefined, suspense ? 'Suspense' : undefined, 'QueryKey'].filter(Boolean).join(''),
394
- pluginKey,
395
- })
396
- const queryOptionsName = pluginManager.resolveName({
397
- name: [factory.name, infinite ? 'Infinite' : undefined, suspense ? 'Suspense' : undefined, 'QueryOptions'].filter(Boolean).join(''),
398
- pluginKey,
399
- })
400
-
401
- const generics = new FunctionParams()
402
- const params = new FunctionParams()
403
- const queryKeyParams = new FunctionParams()
404
-
405
- const clientGenerics = [`${factory.name}['data']`, `${factory.name}['error']`]
406
- // suspense is having 4 generics instead of 5, TQueryData is not needed because data will always be defined
407
- const resultGenerics = suspense
408
- ? [`${factory.name}['response']`, `${factory.name}["error"]`, 'TData']
409
- : [`${factory.name}['response']`, `${factory.name}["error"]`, 'TData', 'TQueryData']
410
-
411
- const client = {
412
- withQueryParams: !!schemas.queryParams?.name,
413
- withData: !!schemas.request?.name,
414
- withPathParams: !!schemas.pathParams?.name,
415
- withHeaders: !!schemas.headerParams?.name,
416
- method: operation.method,
417
- path: new URLPath(operation.path),
418
- generics: clientGenerics.toString(),
419
- contentType,
420
- }
421
-
422
- generics.add([
423
- { type: 'TData', default: `${factory.name}["response"]` },
424
- suspense ? undefined : { type: 'TQueryData', default: `${factory.name}["response"]` },
425
- ])
426
-
427
- params.add([
428
- ...(pathParamsType === 'object' ? [getASTParams(schemas.pathParams, { typed: true })] : getASTParams(schemas.pathParams, { typed: true })),
429
- {
430
- name: 'params',
431
- type: `${factory.name}['queryParams']`,
432
- enabled: client.withQueryParams,
433
- required: isRequired(schemas.queryParams?.schema),
434
- },
435
- {
436
- name: 'headers',
437
- type: `${factory.name}['headerParams']`,
438
- enabled: client.withHeaders,
439
- required: isRequired(schemas.headerParams?.schema),
440
- },
441
- {
442
- name: 'data',
443
- type: `${factory.name}['request']`,
444
- enabled: client.withData,
445
- required: isRequired(schemas.request?.schema),
446
- },
447
- {
448
- name: 'options',
449
- type: `${factory.name}['client']['parameters']`,
450
- default: '{}',
451
- },
452
- ])
453
-
454
- queryKeyParams.add([
455
- ...(pathParamsType === 'object' ? [getASTParams(schemas.pathParams)] : getASTParams(schemas.pathParams)),
456
- {
457
- name: 'params',
458
- enabled: client.withQueryParams,
459
- required: isRequired(schemas.queryParams?.schema),
460
- },
461
- {
462
- name: 'data',
463
- enabled: client.withData,
464
- required: isRequired(schemas.request?.schema),
465
- },
466
- ])
467
-
468
- const hook = {
469
- queryKey: `${queryKey}(${queryKeyParams.toString()})`,
470
- }
471
-
472
- if (!queryOptions) {
473
- return null
474
- }
475
-
476
- return (
477
- <Template
478
- name={queryOptionsName}
479
- params={params.toString()}
480
- generics={generics.toString()}
481
- returnType={`WithRequired<${resultType}<${resultGenerics.join(', ')}>, 'queryKey'>`}
482
- client={client}
483
- hook={hook}
484
- infinite={infinite}
485
- dataReturnType={dataReturnType}
486
- parser={parser === 'zod' ? `${zodSchemas.response.name}.parse` : undefined}
487
- context={{
488
- factory,
489
- queryKey,
490
- }}
491
- />
492
- )
493
- }
494
-
495
- QueryOptions.templates = defaultTemplates
133
+ QueryOptions.getParams = getParams