@kubb/plugin-react-query 5.0.0-beta.56 → 5.0.0-beta.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{components-yMQOuFmI.cjs → components-B0j2b6y8.cjs} +99 -173
- package/dist/components-B0j2b6y8.cjs.map +1 -0
- package/dist/{components-DL0Cai7l.js → components-Ds-e_nnK.js} +99 -173
- package/dist/components-Ds-e_nnK.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/{generators-zGKP8yII.cjs → generators-CU6zfet7.cjs} +2 -2
- package/dist/{generators-zGKP8yII.cjs.map → generators-CU6zfet7.cjs.map} +1 -1
- package/dist/{generators-BG-Vcvfg.js → generators-nnZhtlrk.js} +2 -2
- package/dist/{generators-BG-Vcvfg.js.map → generators-nnZhtlrk.js.map} +1 -1
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +8 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/{types-X7D0NSvJ.d.ts → types-ANQXv7Gr.d.ts} +3 -3
- package/package.json +8 -9
- package/dist/components-DL0Cai7l.js.map +0 -1
- package/dist/components-yMQOuFmI.cjs.map +0 -1
- package/src/components/InfiniteQuery.tsx +0 -166
- package/src/components/InfiniteQueryOptions.tsx +0 -166
- package/src/components/Mutation.tsx +0 -122
- package/src/components/MutationKey.tsx +0 -1
- package/src/components/MutationOptions.tsx +0 -104
- package/src/components/Query.tsx +0 -124
- package/src/components/QueryKey.tsx +0 -1
- package/src/components/QueryOptions.tsx +0 -85
- package/src/components/SuspenseInfiniteQuery.tsx +0 -161
- package/src/components/SuspenseInfiniteQueryOptions.tsx +0 -162
- package/src/components/SuspenseQuery.tsx +0 -119
- package/src/components/index.ts +0 -11
- package/src/generators/customHookOptionsFileGenerator.tsx +0 -90
- package/src/generators/hookOptionsGenerator.tsx +0 -129
- package/src/generators/index.ts +0 -7
- package/src/generators/infiniteQueryGenerator.tsx +0 -196
- package/src/generators/mutationGenerator.tsx +0 -172
- package/src/generators/queryGenerator.tsx +0 -181
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +0 -205
- package/src/generators/suspenseQueryGenerator.tsx +0 -184
- package/src/index.ts +0 -2
- package/src/plugin.ts +0 -203
- package/src/resolvers/resolverReactQuery.ts +0 -118
- package/src/types.ts +0 -361
- package/src/utils.ts +0 -18
package/src/generators/index.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { customHookOptionsFileGenerator } from './customHookOptionsFileGenerator.tsx'
|
|
2
|
-
export { hookOptionsGenerator } from './hookOptionsGenerator.tsx'
|
|
3
|
-
export { infiniteQueryGenerator } from './infiniteQueryGenerator.tsx'
|
|
4
|
-
export { mutationGenerator } from './mutationGenerator.tsx'
|
|
5
|
-
export { queryGenerator } from './queryGenerator.tsx'
|
|
6
|
-
export { suspenseInfiniteQueryGenerator } from './suspenseInfiniteQueryGenerator.tsx'
|
|
7
|
-
export { suspenseQueryGenerator } from './suspenseQueryGenerator.tsx'
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { getOperationParameters, operationFileEntry, resolveOperationTypeNames } from '@internals/shared'
|
|
3
|
-
import { resolveZodSchemaNames } from '@internals/tanstack-query'
|
|
4
|
-
import { ast, defineGenerator } from '@kubb/core'
|
|
5
|
-
import { Client, isParserEnabled, 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 { InfiniteQuery, InfiniteQueryOptions, QueryKey } from '../components'
|
|
10
|
-
import type { PluginReactQuery } from '../types'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Built-in generator for `useInfiniteQuery` hooks. Enabled when
|
|
14
|
-
* `pluginReactQuery({ infinite: { ... } })`. Emits one `useFooInfiniteQuery`
|
|
15
|
-
* hook per query operation, wiring the configured `nextParam` /
|
|
16
|
-
* `previousParam` paths into TanStack Query's cursor-based pagination.
|
|
17
|
-
*/
|
|
18
|
-
export const infiniteQueryGenerator = defineGenerator<PluginReactQuery>({
|
|
19
|
-
name: 'react-infinite-query',
|
|
20
|
-
renderer: jsxRenderer,
|
|
21
|
-
operation(node, ctx) {
|
|
22
|
-
if (!ast.isHttpOperationNode(node)) return null
|
|
23
|
-
const { config, driver, resolver, root } = ctx
|
|
24
|
-
const { output, query, mutation, infinite, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, customOptions } = ctx.options
|
|
25
|
-
|
|
26
|
-
const pluginTs = driver.getPlugin(pluginTsName)
|
|
27
|
-
if (!pluginTs) return null
|
|
28
|
-
const tsResolver = driver.getResolver(pluginTsName)
|
|
29
|
-
|
|
30
|
-
const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
|
|
31
|
-
const queryMethods = new Set(query ? query.methods : [])
|
|
32
|
-
const isMutation =
|
|
33
|
-
mutation !== false &&
|
|
34
|
-
!isQuery &&
|
|
35
|
-
(mutation ? mutation.methods : []).some((method) => !queryMethods.has(method) && node.method.toLowerCase() === method.toLowerCase())
|
|
36
|
-
const infiniteOptions = infinite && typeof infinite === 'object' ? infinite : null
|
|
37
|
-
|
|
38
|
-
if (!isQuery || isMutation || !infiniteOptions) return null
|
|
39
|
-
|
|
40
|
-
// Validate queryParam exists in operation's query parameters
|
|
41
|
-
const normalizeKey = (key: string) => key.replace(/\?$/, '')
|
|
42
|
-
const queryParamKeys = getOperationParameters(node).query.map((p) => p.name)
|
|
43
|
-
const hasQueryParam = infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false
|
|
44
|
-
// cursorParam validation against response schema keys is skipped in v5 (complex schema inspection)
|
|
45
|
-
const hasCursorParam = !infiniteOptions.cursorParam || true
|
|
46
|
-
|
|
47
|
-
if (!hasQueryParam || !hasCursorParam) return null
|
|
48
|
-
|
|
49
|
-
const importPath = query ? query.importPath : '@tanstack/react-query'
|
|
50
|
-
|
|
51
|
-
const queryName = resolver.resolveInfiniteQueryName(node)
|
|
52
|
-
const queryOptionsName = resolver.resolveInfiniteQueryOptionsName(node)
|
|
53
|
-
const queryKeyName = resolver.resolveInfiniteQueryKeyName(node)
|
|
54
|
-
const queryKeyTypeName = resolver.resolveInfiniteQueryKeyTypeName(node)
|
|
55
|
-
const clientBaseName = resolver.resolveInfiniteClientName(node)
|
|
56
|
-
|
|
57
|
-
const meta = {
|
|
58
|
-
file: resolver.resolveFile(operationFileEntry(node, queryName), { root, output, group: group ?? undefined }),
|
|
59
|
-
fileTs: tsResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
60
|
-
root,
|
|
61
|
-
output: pluginTs.options?.output ?? output,
|
|
62
|
-
group: pluginTs.options?.group ?? undefined,
|
|
63
|
-
}),
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, {
|
|
67
|
-
paramsCasing,
|
|
68
|
-
exclude: [queryKeyTypeName],
|
|
69
|
-
order: 'body-response-first',
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
const pluginZod = isParserEnabled(parser) ? driver.getPlugin(pluginZodName) : null
|
|
73
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null
|
|
74
|
-
const fileZod = zodResolver
|
|
75
|
-
? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
76
|
-
root,
|
|
77
|
-
output: pluginZod?.options?.output ?? output,
|
|
78
|
-
group: pluginZod?.options?.group ?? undefined,
|
|
79
|
-
})
|
|
80
|
-
: null
|
|
81
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, parser)
|
|
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) : null
|
|
87
|
-
|
|
88
|
-
const clientFile = shouldUseClientPlugin
|
|
89
|
-
? clientResolver?.resolveFile(operationFileEntry(node, node.operationId), {
|
|
90
|
-
root,
|
|
91
|
-
output: clientPlugin?.options?.output ?? output,
|
|
92
|
-
group: clientPlugin?.options?.group ?? undefined,
|
|
93
|
-
})
|
|
94
|
-
: null
|
|
95
|
-
|
|
96
|
-
const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientBaseName) : clientBaseName
|
|
97
|
-
|
|
98
|
-
return (
|
|
99
|
-
<File
|
|
100
|
-
baseName={meta.file.baseName}
|
|
101
|
-
path={meta.file.path}
|
|
102
|
-
meta={meta.file.meta}
|
|
103
|
-
banner={resolver.resolveBanner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
104
|
-
footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
105
|
-
>
|
|
106
|
-
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
107
|
-
{clientOptions.importPath ? (
|
|
108
|
-
<>
|
|
109
|
-
{!shouldUseClientPlugin && <File.Import name={'client'} path={clientOptions.importPath} />}
|
|
110
|
-
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
111
|
-
</>
|
|
112
|
-
) : (
|
|
113
|
-
<>
|
|
114
|
-
{!shouldUseClientPlugin && <File.Import name={['client']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} />}
|
|
115
|
-
<File.Import
|
|
116
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
117
|
-
root={meta.file.path}
|
|
118
|
-
path={path.resolve(root, '.kubb/client.ts')}
|
|
119
|
-
isTypeOnly
|
|
120
|
-
/>
|
|
121
|
-
</>
|
|
122
|
-
)}
|
|
123
|
-
{shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
|
|
124
|
-
{!shouldUseClientPlugin && <File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />}
|
|
125
|
-
{customOptions && <File.Import name={[customOptions.name]} path={customOptions.importPath} />}
|
|
126
|
-
{meta.fileTs && importedTypeNames.length > 0 && (
|
|
127
|
-
<File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
|
|
128
|
-
)}
|
|
129
|
-
|
|
130
|
-
<QueryKey
|
|
131
|
-
name={queryKeyName}
|
|
132
|
-
typeName={queryKeyTypeName}
|
|
133
|
-
node={node}
|
|
134
|
-
tsResolver={tsResolver}
|
|
135
|
-
pathParamsType={pathParamsType}
|
|
136
|
-
paramsCasing={paramsCasing}
|
|
137
|
-
transformer={ctx.options.queryKey}
|
|
138
|
-
/>
|
|
139
|
-
|
|
140
|
-
{!shouldUseClientPlugin && (
|
|
141
|
-
<Client
|
|
142
|
-
name={resolvedClientName}
|
|
143
|
-
baseURL={clientOptions.baseURL}
|
|
144
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
145
|
-
paramsCasing={clientOptions.paramsCasing || paramsCasing}
|
|
146
|
-
paramsType={paramsType}
|
|
147
|
-
pathParamsType={pathParamsType}
|
|
148
|
-
parser={parser}
|
|
149
|
-
node={node}
|
|
150
|
-
tsResolver={tsResolver}
|
|
151
|
-
zodResolver={zodResolver}
|
|
152
|
-
/>
|
|
153
|
-
)}
|
|
154
|
-
|
|
155
|
-
<File.Import name={['InfiniteData']} isTypeOnly path={importPath} />
|
|
156
|
-
<File.Import name={['infiniteQueryOptions']} path={importPath} />
|
|
157
|
-
|
|
158
|
-
<InfiniteQueryOptions
|
|
159
|
-
name={queryOptionsName}
|
|
160
|
-
clientName={resolvedClientName}
|
|
161
|
-
queryKeyName={queryKeyName}
|
|
162
|
-
node={node}
|
|
163
|
-
tsResolver={tsResolver}
|
|
164
|
-
paramsCasing={paramsCasing}
|
|
165
|
-
paramsType={paramsType}
|
|
166
|
-
pathParamsType={pathParamsType}
|
|
167
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
168
|
-
cursorParam={infiniteOptions.cursorParam}
|
|
169
|
-
nextParam={infiniteOptions.nextParam}
|
|
170
|
-
previousParam={infiniteOptions.previousParam}
|
|
171
|
-
initialPageParam={infiniteOptions.initialPageParam}
|
|
172
|
-
queryParam={infiniteOptions.queryParam}
|
|
173
|
-
/>
|
|
174
|
-
|
|
175
|
-
<File.Import name={['useInfiniteQuery']} path={importPath} />
|
|
176
|
-
<File.Import name={['QueryKey', 'QueryClient', 'InfiniteQueryObserverOptions', 'UseInfiniteQueryResult']} path={importPath} isTypeOnly />
|
|
177
|
-
|
|
178
|
-
<InfiniteQuery
|
|
179
|
-
name={queryName}
|
|
180
|
-
queryOptionsName={queryOptionsName}
|
|
181
|
-
queryKeyName={queryKeyName}
|
|
182
|
-
queryKeyTypeName={queryKeyTypeName}
|
|
183
|
-
node={node}
|
|
184
|
-
tsResolver={tsResolver}
|
|
185
|
-
paramsCasing={paramsCasing}
|
|
186
|
-
paramsType={paramsType}
|
|
187
|
-
pathParamsType={pathParamsType}
|
|
188
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
189
|
-
initialPageParam={infiniteOptions.initialPageParam}
|
|
190
|
-
queryParam={infiniteOptions.queryParam}
|
|
191
|
-
customOptions={customOptions}
|
|
192
|
-
/>
|
|
193
|
-
</File>
|
|
194
|
-
)
|
|
195
|
-
},
|
|
196
|
-
})
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { operationFileEntry, resolveOperationTypeNames } from '@internals/shared'
|
|
3
|
-
import { resolveZodSchemaNames } from '@internals/tanstack-query'
|
|
4
|
-
import { ast, defineGenerator } from '@kubb/core'
|
|
5
|
-
import { Client, isParserEnabled, 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 { Mutation, MutationKey, MutationOptions } from '../components'
|
|
10
|
-
import type { PluginReactQuery } from '../types'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Built-in generator for `useMutation` hooks. Emits one `useFooMutation` hook
|
|
14
|
-
* per POST/PUT/DELETE operation (configurable via `mutation.methods`) plus
|
|
15
|
-
* the matching `fooMutationKey` / `fooMutationOptions` helpers.
|
|
16
|
-
*/
|
|
17
|
-
export const mutationGenerator = defineGenerator<PluginReactQuery>({
|
|
18
|
-
name: 'react-query-mutation',
|
|
19
|
-
renderer: jsxRenderer,
|
|
20
|
-
operation(node, ctx) {
|
|
21
|
-
if (!ast.isHttpOperationNode(node)) return null
|
|
22
|
-
const { config, driver, resolver, root } = ctx
|
|
23
|
-
const { output, query, mutation, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, customOptions } = ctx.options
|
|
24
|
-
|
|
25
|
-
const pluginTs = driver.getPlugin(pluginTsName)
|
|
26
|
-
if (!pluginTs) return null
|
|
27
|
-
const tsResolver = driver.getResolver(pluginTsName)
|
|
28
|
-
|
|
29
|
-
const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
|
|
30
|
-
const queryMethods = new Set(query ? query.methods : [])
|
|
31
|
-
const isMutation =
|
|
32
|
-
mutation !== false &&
|
|
33
|
-
!isQuery &&
|
|
34
|
-
(mutation ? mutation.methods : []).some((method) => !queryMethods.has(method) && node.method.toLowerCase() === method.toLowerCase())
|
|
35
|
-
|
|
36
|
-
if (!isMutation) return null
|
|
37
|
-
|
|
38
|
-
const importPath = mutation ? mutation.importPath : '@tanstack/react-query'
|
|
39
|
-
|
|
40
|
-
const mutationHookName = resolver.resolveMutationName(node)
|
|
41
|
-
const mutationTypeName = resolver.resolveMutationTypeName(node)
|
|
42
|
-
const mutationOptionsName = resolver.resolveMutationOptionsName(node)
|
|
43
|
-
const mutationKeyName = resolver.resolveMutationKeyName(node)
|
|
44
|
-
const clientName = resolver.resolveClientName(node)
|
|
45
|
-
|
|
46
|
-
const meta = {
|
|
47
|
-
file: resolver.resolveFile(operationFileEntry(node, mutationHookName), { root, output, group: group ?? undefined }),
|
|
48
|
-
fileTs: tsResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
49
|
-
root,
|
|
50
|
-
output: pluginTs.options?.output ?? output,
|
|
51
|
-
group: pluginTs.options?.group ?? undefined,
|
|
52
|
-
}),
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, { paramsCasing, order: 'body-response-first' })
|
|
56
|
-
|
|
57
|
-
const pluginZod = isParserEnabled(parser) ? driver.getPlugin(pluginZodName) : null
|
|
58
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null
|
|
59
|
-
const fileZod = zodResolver
|
|
60
|
-
? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
61
|
-
root,
|
|
62
|
-
output: pluginZod?.options?.output ?? output,
|
|
63
|
-
group: pluginZod?.options?.group ?? undefined,
|
|
64
|
-
})
|
|
65
|
-
: null
|
|
66
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, parser)
|
|
67
|
-
|
|
68
|
-
const clientPlugin = driver.getPlugin(pluginClientName)
|
|
69
|
-
const hasClientPlugin = clientPlugin?.name === pluginClientName
|
|
70
|
-
const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
|
|
71
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null
|
|
72
|
-
|
|
73
|
-
const clientFile = shouldUseClientPlugin
|
|
74
|
-
? clientResolver?.resolveFile(operationFileEntry(node, node.operationId), {
|
|
75
|
-
root,
|
|
76
|
-
output: clientPlugin?.options?.output ?? output,
|
|
77
|
-
group: clientPlugin?.options?.group ?? undefined,
|
|
78
|
-
})
|
|
79
|
-
: null
|
|
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(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
89
|
-
footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
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={'client'} path={clientOptions.importPath} />}
|
|
95
|
-
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
96
|
-
</>
|
|
97
|
-
) : (
|
|
98
|
-
<>
|
|
99
|
-
{!shouldUseClientPlugin && <File.Import name={['client']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} />}
|
|
100
|
-
<File.Import
|
|
101
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
102
|
-
root={meta.file.path}
|
|
103
|
-
path={path.resolve(root, '.kubb/client.ts')}
|
|
104
|
-
isTypeOnly
|
|
105
|
-
/>
|
|
106
|
-
</>
|
|
107
|
-
)}
|
|
108
|
-
{shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
|
|
109
|
-
{!shouldUseClientPlugin && node.requestBody?.content?.some((e) => e.contentType === 'multipart/form-data') && (
|
|
110
|
-
<File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />
|
|
111
|
-
)}
|
|
112
|
-
{!shouldUseClientPlugin && parser === 'zod' && zodResolver && node.requestBody?.content?.[0]?.schema && (
|
|
113
|
-
<File.Import name={['z']} path="zod" isTypeOnly />
|
|
114
|
-
)}
|
|
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
|
-
<MutationKey name={mutationKeyName} node={node} pathParamsType={pathParamsType} paramsCasing={paramsCasing} transformer={ctx.options.mutationKey} />
|
|
121
|
-
|
|
122
|
-
{!shouldUseClientPlugin && (
|
|
123
|
-
<Client
|
|
124
|
-
name={resolvedClientName}
|
|
125
|
-
baseURL={clientOptions.baseURL}
|
|
126
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
127
|
-
paramsCasing={clientOptions.paramsCasing || paramsCasing}
|
|
128
|
-
paramsType={paramsType}
|
|
129
|
-
pathParamsType={pathParamsType}
|
|
130
|
-
parser={parser}
|
|
131
|
-
node={node}
|
|
132
|
-
tsResolver={tsResolver}
|
|
133
|
-
zodResolver={zodResolver}
|
|
134
|
-
/>
|
|
135
|
-
)}
|
|
136
|
-
|
|
137
|
-
<File.Import name={['mutationOptions']} path={importPath} />
|
|
138
|
-
|
|
139
|
-
<MutationOptions
|
|
140
|
-
name={mutationOptionsName}
|
|
141
|
-
clientName={resolvedClientName}
|
|
142
|
-
mutationKeyName={mutationKeyName}
|
|
143
|
-
node={node}
|
|
144
|
-
tsResolver={tsResolver}
|
|
145
|
-
paramsCasing={paramsCasing}
|
|
146
|
-
paramsType={paramsType}
|
|
147
|
-
pathParamsType={pathParamsType}
|
|
148
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
149
|
-
/>
|
|
150
|
-
|
|
151
|
-
{mutation && (
|
|
152
|
-
<>
|
|
153
|
-
<File.Import name={['useMutation']} path={importPath} />
|
|
154
|
-
<File.Import name={['UseMutationOptions', 'UseMutationResult', 'QueryClient']} path={importPath} isTypeOnly />
|
|
155
|
-
<Mutation
|
|
156
|
-
name={mutationHookName}
|
|
157
|
-
typeName={mutationTypeName}
|
|
158
|
-
mutationOptionsName={mutationOptionsName}
|
|
159
|
-
mutationKeyName={mutationKeyName}
|
|
160
|
-
node={node}
|
|
161
|
-
tsResolver={tsResolver}
|
|
162
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
163
|
-
paramsCasing={paramsCasing}
|
|
164
|
-
pathParamsType={pathParamsType}
|
|
165
|
-
customOptions={customOptions}
|
|
166
|
-
/>
|
|
167
|
-
</>
|
|
168
|
-
)}
|
|
169
|
-
</File>
|
|
170
|
-
)
|
|
171
|
-
},
|
|
172
|
-
})
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { operationFileEntry, resolveOperationTypeNames } from '@internals/shared'
|
|
3
|
-
import { resolveZodSchemaNames } from '@internals/tanstack-query'
|
|
4
|
-
import { ast, defineGenerator } from '@kubb/core'
|
|
5
|
-
import { Client, isParserEnabled, 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 { Query, QueryKey, QueryOptions } from '../components'
|
|
10
|
-
import type { PluginReactQuery } from '../types'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Built-in generator for `useQuery` hooks. Emits one `useFooQuery` hook per
|
|
14
|
-
* GET operation (configurable via `query.methods`) plus the matching
|
|
15
|
-
* `fooQueryKey` / `fooQueryOptions` helpers.
|
|
16
|
-
*/
|
|
17
|
-
export const queryGenerator = defineGenerator<PluginReactQuery>({
|
|
18
|
-
name: 'react-query',
|
|
19
|
-
renderer: jsxRenderer,
|
|
20
|
-
operation(node, ctx) {
|
|
21
|
-
if (!ast.isHttpOperationNode(node)) return null
|
|
22
|
-
const { config, driver, resolver, root } = ctx
|
|
23
|
-
const { output, query, mutation, paramsCasing, paramsType, pathParamsType, parser, client: clientOptions, group, customOptions } = ctx.options
|
|
24
|
-
|
|
25
|
-
const pluginTs = driver.getPlugin(pluginTsName)
|
|
26
|
-
if (!pluginTs) return null
|
|
27
|
-
const tsResolver = driver.getResolver(pluginTsName)
|
|
28
|
-
|
|
29
|
-
// query: false means "this IS a query op, but skip the useQuery hook"
|
|
30
|
-
const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
|
|
31
|
-
const queryMethods = new Set(query ? query.methods : [])
|
|
32
|
-
const isMutation =
|
|
33
|
-
mutation !== false &&
|
|
34
|
-
!isQuery &&
|
|
35
|
-
(mutation ? mutation.methods : []).some((method) => !queryMethods.has(method) && node.method.toLowerCase() === method.toLowerCase())
|
|
36
|
-
|
|
37
|
-
if (!isQuery || isMutation) return null
|
|
38
|
-
|
|
39
|
-
const importPath = query ? query.importPath : '@tanstack/react-query'
|
|
40
|
-
|
|
41
|
-
const queryName = resolver.resolveQueryName(node)
|
|
42
|
-
const queryOptionsName = resolver.resolveQueryOptionsName(node)
|
|
43
|
-
const queryKeyName = resolver.resolveQueryKeyName(node)
|
|
44
|
-
const queryKeyTypeName = resolver.resolveQueryKeyTypeName(node)
|
|
45
|
-
const clientName = resolver.resolveClientName(node)
|
|
46
|
-
|
|
47
|
-
const meta = {
|
|
48
|
-
file: resolver.resolveFile(operationFileEntry(node, queryName), { root, output, group: group ?? undefined }),
|
|
49
|
-
fileTs: tsResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
50
|
-
root,
|
|
51
|
-
output: pluginTs.options?.output ?? output,
|
|
52
|
-
group: pluginTs.options?.group ?? undefined,
|
|
53
|
-
}),
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, {
|
|
57
|
-
paramsCasing,
|
|
58
|
-
exclude: [queryKeyTypeName],
|
|
59
|
-
order: 'body-response-first',
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
const pluginZod = isParserEnabled(parser) ? driver.getPlugin(pluginZodName) : null
|
|
63
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null
|
|
64
|
-
const fileZod = zodResolver
|
|
65
|
-
? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
66
|
-
root,
|
|
67
|
-
output: pluginZod?.options?.output ?? output,
|
|
68
|
-
group: pluginZod?.options?.group ?? undefined,
|
|
69
|
-
})
|
|
70
|
-
: null
|
|
71
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, parser)
|
|
72
|
-
|
|
73
|
-
const clientPlugin = driver.getPlugin(pluginClientName)
|
|
74
|
-
const hasClientPlugin = clientPlugin?.name === pluginClientName
|
|
75
|
-
const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
|
|
76
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null
|
|
77
|
-
|
|
78
|
-
const clientFile = shouldUseClientPlugin
|
|
79
|
-
? clientResolver?.resolveFile(operationFileEntry(node, node.operationId), {
|
|
80
|
-
root,
|
|
81
|
-
output: clientPlugin?.options?.output ?? output,
|
|
82
|
-
group: clientPlugin?.options?.group ?? undefined,
|
|
83
|
-
})
|
|
84
|
-
: null
|
|
85
|
-
|
|
86
|
-
const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientName) : clientName
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
<File
|
|
90
|
-
baseName={meta.file.baseName}
|
|
91
|
-
path={meta.file.path}
|
|
92
|
-
meta={meta.file.meta}
|
|
93
|
-
banner={resolver.resolveBanner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
94
|
-
footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
95
|
-
>
|
|
96
|
-
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
97
|
-
{clientOptions.importPath ? (
|
|
98
|
-
<>
|
|
99
|
-
{!shouldUseClientPlugin && <File.Import name={'client'} path={clientOptions.importPath} />}
|
|
100
|
-
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
101
|
-
</>
|
|
102
|
-
) : (
|
|
103
|
-
<>
|
|
104
|
-
{!shouldUseClientPlugin && <File.Import name={['client']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} />}
|
|
105
|
-
<File.Import
|
|
106
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
107
|
-
root={meta.file.path}
|
|
108
|
-
path={path.resolve(root, '.kubb/client.ts')}
|
|
109
|
-
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
|
-
{query && (
|
|
160
|
-
<>
|
|
161
|
-
<File.Import name={['useQuery']} path={importPath} />
|
|
162
|
-
<File.Import name={['QueryKey', 'QueryClient', 'QueryObserverOptions', 'UseQueryResult']} path={importPath} isTypeOnly />
|
|
163
|
-
<Query
|
|
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
|
-
})
|