@kubb/plugin-react-query 5.0.0-beta.10 → 5.0.0-beta.100

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/README.md +22 -26
  2. package/dist/index.cjs +2288 -191
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.ts +494 -6
  5. package/dist/index.js +2258 -185
  6. package/dist/index.js.map +1 -1
  7. package/package.json +11 -34
  8. package/dist/components-Dow6tde8.js +0 -1459
  9. package/dist/components-Dow6tde8.js.map +0 -1
  10. package/dist/components-HwdCDefj.cjs +0 -1603
  11. package/dist/components-HwdCDefj.cjs.map +0 -1
  12. package/dist/components.cjs +0 -13
  13. package/dist/components.d.ts +0 -268
  14. package/dist/components.js +0 -2
  15. package/dist/generators-CcOmnTPa.cjs +0 -1454
  16. package/dist/generators-CcOmnTPa.cjs.map +0 -1
  17. package/dist/generators-yfZr_qfT.js +0 -1412
  18. package/dist/generators-yfZr_qfT.js.map +0 -1
  19. package/dist/generators.cjs +0 -9
  20. package/dist/generators.d.ts +0 -27
  21. package/dist/generators.js +0 -2
  22. package/dist/types-DG_OxOym.d.ts +0 -363
  23. package/extension.yaml +0 -911
  24. package/src/components/InfiniteQuery.tsx +0 -161
  25. package/src/components/InfiniteQueryOptions.tsx +0 -178
  26. package/src/components/Mutation.tsx +0 -121
  27. package/src/components/MutationKey.tsx +0 -1
  28. package/src/components/MutationOptions.tsx +0 -103
  29. package/src/components/Query.tsx +0 -118
  30. package/src/components/QueryKey.tsx +0 -1
  31. package/src/components/QueryOptions.tsx +0 -99
  32. package/src/components/SuspenseInfiniteQuery.tsx +0 -161
  33. package/src/components/SuspenseInfiniteQueryOptions.tsx +0 -178
  34. package/src/components/SuspenseQuery.tsx +0 -118
  35. package/src/components/index.ts +0 -11
  36. package/src/generators/customHookOptionsFileGenerator.tsx +0 -84
  37. package/src/generators/hookOptionsGenerator.tsx +0 -133
  38. package/src/generators/index.ts +0 -7
  39. package/src/generators/infiniteQueryGenerator.tsx +0 -194
  40. package/src/generators/mutationGenerator.tsx +0 -168
  41. package/src/generators/queryGenerator.tsx +0 -180
  42. package/src/generators/suspenseInfiniteQueryGenerator.tsx +0 -203
  43. package/src/generators/suspenseQueryGenerator.tsx +0 -181
  44. package/src/index.ts +0 -2
  45. package/src/plugin.ts +0 -186
  46. package/src/resolvers/resolverReactQuery.ts +0 -107
  47. package/src/types.ts +0 -328
  48. package/src/utils.ts +0 -10
  49. /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
@@ -1,180 +0,0 @@
1
- import path from 'node:path'
2
- import { resolveOperationTypeNames } from '@internals/shared'
3
- import { resolveZodSchemaNames } from '@internals/tanstack-query'
4
- import { defineGenerator } from '@kubb/core'
5
- import { Client, pluginClientName } from '@kubb/plugin-client'
6
- import { pluginTsName } from '@kubb/plugin-ts'
7
- import { pluginZodName } from '@kubb/plugin-zod'
8
- import { File, jsxRenderer } from '@kubb/renderer-jsx'
9
- import { difference } from 'remeda'
10
- import { Query, QueryKey, QueryOptions } from '../components'
11
- import type { PluginReactQuery } from '../types'
12
-
13
- export const queryGenerator = defineGenerator<PluginReactQuery>({
14
- name: 'react-query',
15
- renderer: jsxRenderer,
16
- operation(node, ctx) {
17
- const { adapter, config, driver, resolver, root } = ctx
18
- const { output, query, mutation, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, customOptions } = ctx.options
19
-
20
- const pluginTs = driver.getPlugin(pluginTsName)
21
- if (!pluginTs) return null
22
- const tsResolver = driver.getResolver(pluginTsName)
23
-
24
- // query: false means "this IS a query op, but skip the useQuery hook"
25
- const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
26
- const isMutation =
27
- mutation !== false &&
28
- !isQuery &&
29
- difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase())
30
-
31
- if (!isQuery || isMutation) return null
32
-
33
- const importPath = query ? query.importPath : '@tanstack/react-query'
34
-
35
- const queryName = resolver.resolveQueryName(node)
36
- const queryOptionsName = resolver.resolveQueryOptionsName(node)
37
- const queryKeyName = resolver.resolveQueryKeyName(node)
38
- const queryKeyTypeName = resolver.resolveQueryKeyTypeName(node)
39
- const clientName = resolver.resolveClientName(node)
40
-
41
- const meta = {
42
- file: resolver.resolveFile({ name: queryName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path }, { root, output, group }),
43
- fileTs: tsResolver.resolveFile(
44
- { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
45
- { root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group },
46
- ),
47
- }
48
-
49
- const importedTypeNames = resolveOperationTypeNames(node, tsResolver, {
50
- paramsCasing,
51
- exclude: [queryKeyTypeName],
52
- order: 'body-response-first',
53
- })
54
-
55
- const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : undefined
56
- const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : undefined
57
- const fileZod = zodResolver
58
- ? zodResolver.resolveFile(
59
- { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
60
- { root, output: pluginZod?.options?.output ?? output, group: pluginZod?.options?.group },
61
- )
62
- : undefined
63
- const zodSchemaNames = resolveZodSchemaNames(node, zodResolver)
64
-
65
- const clientPlugin = driver.getPlugin(pluginClientName)
66
- const hasClientPlugin = clientPlugin?.name === pluginClientName
67
- const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
68
- const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : undefined
69
-
70
- const clientFile = shouldUseClientPlugin
71
- ? clientResolver?.resolveFile(
72
- { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
73
- {
74
- root,
75
- output: clientPlugin?.options?.output ?? output,
76
- group: clientPlugin?.options?.group,
77
- },
78
- )
79
- : undefined
80
-
81
- const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientName) : clientName
82
-
83
- return (
84
- <File
85
- baseName={meta.file.baseName}
86
- path={meta.file.path}
87
- meta={meta.file.meta}
88
- banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
89
- footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
90
- >
91
- {fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
92
- {clientOptions.importPath ? (
93
- <>
94
- {!shouldUseClientPlugin && <File.Import name={'fetch'} path={clientOptions.importPath} />}
95
- <File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
96
- {clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
97
- </>
98
- ) : (
99
- <>
100
- {!shouldUseClientPlugin && <File.Import name={['fetch']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} />}
101
- <File.Import
102
- name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
103
- root={meta.file.path}
104
- path={path.resolve(root, '.kubb/fetch.ts')}
105
- isTypeOnly
106
- />
107
- {clientOptions.dataReturnType === 'full' && (
108
- <File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} isTypeOnly />
109
- )}
110
- </>
111
- )}
112
- {shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
113
- {!shouldUseClientPlugin && <File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />}
114
- {customOptions && <File.Import name={[customOptions.name]} path={customOptions.importPath} />}
115
- {meta.fileTs && importedTypeNames.length > 0 && (
116
- <File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
117
- )}
118
-
119
- <QueryKey
120
- name={queryKeyName}
121
- typeName={queryKeyTypeName}
122
- node={node}
123
- tsResolver={tsResolver}
124
- pathParamsType={pathParamsType}
125
- paramsCasing={paramsCasing}
126
- transformer={ctx.options.queryKey}
127
- />
128
-
129
- {!shouldUseClientPlugin && (
130
- <Client
131
- name={resolvedClientName}
132
- baseURL={clientOptions.baseURL}
133
- dataReturnType={clientOptions.dataReturnType || 'data'}
134
- paramsCasing={clientOptions.paramsCasing || paramsCasing}
135
- paramsType={paramsType}
136
- pathParamsType={pathParamsType}
137
- parser={parser}
138
- node={node}
139
- tsResolver={tsResolver}
140
- zodResolver={zodResolver}
141
- />
142
- )}
143
-
144
- <File.Import name={['queryOptions']} path={importPath} />
145
-
146
- <QueryOptions
147
- name={queryOptionsName}
148
- clientName={resolvedClientName}
149
- queryKeyName={queryKeyName}
150
- node={node}
151
- tsResolver={tsResolver}
152
- paramsCasing={paramsCasing}
153
- paramsType={paramsType}
154
- pathParamsType={pathParamsType}
155
- dataReturnType={clientOptions.dataReturnType || 'data'}
156
- />
157
-
158
- {query && (
159
- <>
160
- <File.Import name={['useQuery']} path={importPath} />
161
- <File.Import name={['QueryKey', 'QueryClient', 'QueryObserverOptions', 'UseQueryResult']} path={importPath} isTypeOnly />
162
- <Query
163
- name={queryName}
164
- queryOptionsName={queryOptionsName}
165
- queryKeyName={queryKeyName}
166
- queryKeyTypeName={queryKeyTypeName}
167
- node={node}
168
- tsResolver={tsResolver}
169
- paramsCasing={paramsCasing}
170
- paramsType={paramsType}
171
- pathParamsType={pathParamsType}
172
- dataReturnType={clientOptions.dataReturnType || 'data'}
173
- customOptions={customOptions}
174
- />
175
- </>
176
- )}
177
- </File>
178
- )
179
- },
180
- })
@@ -1,203 +0,0 @@
1
- import path from 'node:path'
2
- import { getOperationParameters, resolveOperationTypeNames } from '@internals/shared'
3
- import { resolveZodSchemaNames } from '@internals/tanstack-query'
4
- import { defineGenerator } from '@kubb/core'
5
- import { Client, pluginClientName } from '@kubb/plugin-client'
6
- import { pluginTsName } from '@kubb/plugin-ts'
7
- import { pluginZodName } from '@kubb/plugin-zod'
8
- import { File, jsxRenderer } from '@kubb/renderer-jsx'
9
- import { difference } from 'remeda'
10
- import { QueryKey, SuspenseInfiniteQuery, SuspenseInfiniteQueryOptions } from '../components'
11
- import type { PluginReactQuery } from '../types'
12
-
13
- export const suspenseInfiniteQueryGenerator = defineGenerator<PluginReactQuery>({
14
- name: 'react-suspense-infinite-query',
15
- renderer: jsxRenderer,
16
- operation(node, ctx) {
17
- const { adapter, config, driver, resolver, root } = ctx
18
- const {
19
- output,
20
- query,
21
- mutation,
22
- infinite,
23
- suspense,
24
- paramsCasing,
25
- paramsType,
26
- pathParamsType,
27
- parser,
28
- client: clientOptions,
29
- group,
30
- customOptions,
31
- } = ctx.options
32
-
33
- const pluginTs = driver.getPlugin(pluginTsName)
34
- if (!pluginTs) return null
35
- const tsResolver = driver.getResolver(pluginTsName)
36
-
37
- const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
38
- const isMutation =
39
- mutation !== false &&
40
- !isQuery &&
41
- difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase())
42
- const isSuspense = !!suspense
43
- const infiniteOptions = infinite && typeof infinite === 'object' ? infinite : undefined
44
-
45
- if (!isQuery || isMutation || !isSuspense || !infiniteOptions) return null
46
-
47
- // Validate queryParam exists in operation's query parameters
48
- const normalizeKey = (key: string) => key.replace(/\?$/, '')
49
- const queryParamKeys = getOperationParameters(node).query.map((p) => p.name)
50
- const hasQueryParam = infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false
51
- const hasCursorParam = !infiniteOptions.cursorParam || true
52
-
53
- if (!hasQueryParam || !hasCursorParam) return null
54
-
55
- const importPath = query ? query.importPath : '@tanstack/react-query'
56
-
57
- const queryName = resolver.resolveSuspenseInfiniteQueryName(node)
58
- const queryOptionsName = resolver.resolveSuspenseInfiniteQueryOptionsName(node)
59
- const queryKeyName = resolver.resolveSuspenseInfiniteQueryKeyName(node)
60
- const queryKeyTypeName = resolver.resolveSuspenseInfiniteQueryKeyTypeName(node)
61
- const clientBaseName = resolver.resolveSuspenseInfiniteClientName(node)
62
-
63
- const meta = {
64
- file: resolver.resolveFile({ name: queryName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path }, { root, output, group }),
65
- fileTs: tsResolver.resolveFile(
66
- { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
67
- { root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group },
68
- ),
69
- }
70
-
71
- const importedTypeNames = resolveOperationTypeNames(node, tsResolver, { paramsCasing, order: 'body-response-first' })
72
-
73
- const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : undefined
74
- const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : undefined
75
- const fileZod = zodResolver
76
- ? zodResolver.resolveFile(
77
- { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
78
- { root, output: pluginZod?.options?.output ?? output, group: pluginZod?.options?.group },
79
- )
80
- : undefined
81
- const zodSchemaNames = resolveZodSchemaNames(node, zodResolver)
82
-
83
- const clientPlugin = driver.getPlugin(pluginClientName)
84
- const hasClientPlugin = clientPlugin?.name === pluginClientName
85
- const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
86
- const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : undefined
87
-
88
- const clientFile = shouldUseClientPlugin
89
- ? clientResolver?.resolveFile(
90
- { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
91
- {
92
- root,
93
- output: clientPlugin?.options?.output ?? output,
94
- group: clientPlugin?.options?.group,
95
- },
96
- )
97
- : undefined
98
-
99
- const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientBaseName) : clientBaseName
100
-
101
- return (
102
- <File
103
- baseName={meta.file.baseName}
104
- path={meta.file.path}
105
- meta={meta.file.meta}
106
- banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
107
- footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
108
- >
109
- {fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
110
- {clientOptions.importPath ? (
111
- <>
112
- {!shouldUseClientPlugin && <File.Import name={'fetch'} path={clientOptions.importPath} />}
113
- <File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
114
- {clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
115
- </>
116
- ) : (
117
- <>
118
- {!shouldUseClientPlugin && <File.Import name={['fetch']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} />}
119
- <File.Import
120
- name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
121
- root={meta.file.path}
122
- path={path.resolve(root, '.kubb/fetch.ts')}
123
- isTypeOnly
124
- />
125
- {clientOptions.dataReturnType === 'full' && (
126
- <File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} isTypeOnly />
127
- )}
128
- </>
129
- )}
130
- {shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
131
- {!shouldUseClientPlugin && <File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />}
132
- {customOptions && <File.Import name={[customOptions.name]} path={customOptions.importPath} />}
133
- {meta.fileTs && importedTypeNames.length > 0 && (
134
- <File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
135
- )}
136
-
137
- <QueryKey
138
- name={queryKeyName}
139
- typeName={queryKeyTypeName}
140
- node={node}
141
- tsResolver={tsResolver}
142
- pathParamsType={pathParamsType}
143
- paramsCasing={paramsCasing}
144
- transformer={ctx.options.queryKey}
145
- />
146
-
147
- {!shouldUseClientPlugin && (
148
- <Client
149
- name={resolvedClientName}
150
- baseURL={clientOptions.baseURL}
151
- dataReturnType={clientOptions.dataReturnType || 'data'}
152
- paramsCasing={clientOptions.paramsCasing || paramsCasing}
153
- paramsType={paramsType}
154
- pathParamsType={pathParamsType}
155
- parser={parser}
156
- node={node}
157
- tsResolver={tsResolver}
158
- zodResolver={zodResolver}
159
- />
160
- )}
161
-
162
- <File.Import name={['InfiniteData']} isTypeOnly path={importPath} />
163
- <File.Import name={['infiniteQueryOptions']} path={importPath} />
164
-
165
- <SuspenseInfiniteQueryOptions
166
- name={queryOptionsName}
167
- clientName={resolvedClientName}
168
- queryKeyName={queryKeyName}
169
- node={node}
170
- tsResolver={tsResolver}
171
- paramsCasing={paramsCasing}
172
- paramsType={paramsType}
173
- pathParamsType={pathParamsType}
174
- dataReturnType={clientOptions.dataReturnType || 'data'}
175
- cursorParam={infiniteOptions.cursorParam}
176
- nextParam={infiniteOptions.nextParam}
177
- previousParam={infiniteOptions.previousParam}
178
- initialPageParam={infiniteOptions.initialPageParam}
179
- queryParam={infiniteOptions.queryParam}
180
- />
181
-
182
- <File.Import name={['useSuspenseInfiniteQuery']} path={importPath} />
183
- <File.Import name={['QueryKey', 'QueryClient', 'UseSuspenseInfiniteQueryOptions', 'UseSuspenseInfiniteQueryResult']} path={importPath} isTypeOnly />
184
-
185
- <SuspenseInfiniteQuery
186
- name={queryName}
187
- queryOptionsName={queryOptionsName}
188
- queryKeyName={queryKeyName}
189
- queryKeyTypeName={queryKeyTypeName}
190
- node={node}
191
- tsResolver={tsResolver}
192
- paramsCasing={paramsCasing}
193
- paramsType={paramsType}
194
- pathParamsType={pathParamsType}
195
- dataReturnType={clientOptions.dataReturnType || 'data'}
196
- initialPageParam={infiniteOptions.initialPageParam}
197
- queryParam={infiniteOptions.queryParam}
198
- customOptions={customOptions}
199
- />
200
- </File>
201
- )
202
- },
203
- })
@@ -1,181 +0,0 @@
1
- import path from 'node:path'
2
- import { resolveOperationTypeNames } from '@internals/shared'
3
- import { resolveZodSchemaNames } from '@internals/tanstack-query'
4
- import { defineGenerator } from '@kubb/core'
5
- import { Client, pluginClientName } from '@kubb/plugin-client'
6
- import { pluginTsName } from '@kubb/plugin-ts'
7
- import { pluginZodName } from '@kubb/plugin-zod'
8
- import { File, jsxRenderer } from '@kubb/renderer-jsx'
9
- import { difference } from 'remeda'
10
- import { QueryKey, QueryOptions, SuspenseQuery } from '../components'
11
- import type { PluginReactQuery } from '../types'
12
-
13
- export const suspenseQueryGenerator = defineGenerator<PluginReactQuery>({
14
- name: 'react-suspense-query',
15
- renderer: jsxRenderer,
16
- operation(node, ctx) {
17
- const { adapter, config, driver, resolver, root } = ctx
18
- const { output, query, mutation, suspense, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, customOptions } = ctx.options
19
-
20
- const pluginTs = driver.getPlugin(pluginTsName)
21
- if (!pluginTs) return null
22
- const tsResolver = driver.getResolver(pluginTsName)
23
-
24
- // query: false means "this IS a query op" (suspense hooks still generate)
25
- const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
26
- const isMutation =
27
- mutation !== false &&
28
- !isQuery &&
29
- difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase())
30
- const isSuspense = !!suspense
31
-
32
- if (!isQuery || isMutation || !isSuspense) return null
33
-
34
- const importPath = query ? query.importPath : '@tanstack/react-query'
35
-
36
- const queryName = resolver.resolveSuspenseQueryName(node)
37
- const queryOptionsName = resolver.resolveSuspenseQueryOptionsName(node)
38
- const queryKeyName = resolver.resolveSuspenseQueryKeyName(node)
39
- const queryKeyTypeName = resolver.resolveSuspenseQueryKeyTypeName(node)
40
- const clientName = resolver.resolveSuspenseClientName(node)
41
-
42
- const meta = {
43
- file: resolver.resolveFile({ name: queryName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path }, { root, output, group }),
44
- fileTs: tsResolver.resolveFile(
45
- { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
46
- { root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group },
47
- ),
48
- }
49
-
50
- const importedTypeNames = resolveOperationTypeNames(node, tsResolver, {
51
- paramsCasing,
52
- exclude: [queryKeyTypeName],
53
- order: 'body-response-first',
54
- })
55
-
56
- const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : undefined
57
- const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : undefined
58
- const fileZod = zodResolver
59
- ? zodResolver.resolveFile(
60
- { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
61
- { root, output: pluginZod?.options?.output ?? output, group: pluginZod?.options?.group },
62
- )
63
- : undefined
64
- const zodSchemaNames = resolveZodSchemaNames(node, zodResolver)
65
-
66
- const clientPlugin = driver.getPlugin(pluginClientName)
67
- const hasClientPlugin = clientPlugin?.name === pluginClientName
68
- const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
69
- const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : undefined
70
-
71
- const clientFile = shouldUseClientPlugin
72
- ? clientResolver?.resolveFile(
73
- { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
74
- {
75
- root,
76
- output: clientPlugin?.options?.output ?? output,
77
- group: clientPlugin?.options?.group,
78
- },
79
- )
80
- : undefined
81
-
82
- const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientName) : clientName
83
-
84
- return (
85
- <File
86
- baseName={meta.file.baseName}
87
- path={meta.file.path}
88
- meta={meta.file.meta}
89
- banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
90
- footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
91
- >
92
- {fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
93
- {clientOptions.importPath ? (
94
- <>
95
- {!shouldUseClientPlugin && <File.Import name={'fetch'} path={clientOptions.importPath} />}
96
- <File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
97
- {clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
98
- </>
99
- ) : (
100
- <>
101
- {!shouldUseClientPlugin && <File.Import name={['fetch']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} />}
102
- <File.Import
103
- name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
104
- root={meta.file.path}
105
- path={path.resolve(root, '.kubb/fetch.ts')}
106
- isTypeOnly
107
- />
108
- {clientOptions.dataReturnType === 'full' && (
109
- <File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} isTypeOnly />
110
- )}
111
- </>
112
- )}
113
- {shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
114
- {!shouldUseClientPlugin && <File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />}
115
- {customOptions && <File.Import name={[customOptions.name]} path={customOptions.importPath} />}
116
- {meta.fileTs && importedTypeNames.length > 0 && (
117
- <File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
118
- )}
119
-
120
- <QueryKey
121
- name={queryKeyName}
122
- typeName={queryKeyTypeName}
123
- node={node}
124
- tsResolver={tsResolver}
125
- pathParamsType={pathParamsType}
126
- paramsCasing={paramsCasing}
127
- transformer={ctx.options.queryKey}
128
- />
129
-
130
- {!shouldUseClientPlugin && (
131
- <Client
132
- name={resolvedClientName}
133
- baseURL={clientOptions.baseURL}
134
- dataReturnType={clientOptions.dataReturnType || 'data'}
135
- paramsCasing={clientOptions.paramsCasing || paramsCasing}
136
- paramsType={paramsType}
137
- pathParamsType={pathParamsType}
138
- parser={parser}
139
- node={node}
140
- tsResolver={tsResolver}
141
- zodResolver={zodResolver}
142
- />
143
- )}
144
-
145
- <File.Import name={['queryOptions']} path={importPath} />
146
-
147
- <QueryOptions
148
- name={queryOptionsName}
149
- clientName={resolvedClientName}
150
- queryKeyName={queryKeyName}
151
- node={node}
152
- tsResolver={tsResolver}
153
- paramsCasing={paramsCasing}
154
- paramsType={paramsType}
155
- pathParamsType={pathParamsType}
156
- dataReturnType={clientOptions.dataReturnType || 'data'}
157
- />
158
-
159
- {suspense && (
160
- <>
161
- <File.Import name={['useSuspenseQuery']} path={importPath} />
162
- <File.Import name={['QueryKey', 'QueryClient', 'UseSuspenseQueryOptions', 'UseSuspenseQueryResult']} path={importPath} isTypeOnly />
163
- <SuspenseQuery
164
- name={queryName}
165
- queryOptionsName={queryOptionsName}
166
- queryKeyName={queryKeyName}
167
- queryKeyTypeName={queryKeyTypeName}
168
- node={node}
169
- tsResolver={tsResolver}
170
- paramsCasing={paramsCasing}
171
- paramsType={paramsType}
172
- pathParamsType={pathParamsType}
173
- dataReturnType={clientOptions.dataReturnType || 'data'}
174
- customOptions={customOptions}
175
- />
176
- </>
177
- )}
178
- </File>
179
- )
180
- },
181
- })
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export { default, pluginReactQuery, pluginReactQueryName } from './plugin.ts'
2
- export type { PluginReactQuery } from './types.ts'