@kubb/plugin-react-query 5.0.0-beta.42 → 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-DQAYLQW0.cjs → components-B0j2b6y8.cjs} +298 -416
- package/dist/components-B0j2b6y8.cjs.map +1 -0
- package/dist/{components-IArDg-DO.js → components-Ds-e_nnK.js} +294 -412
- 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-BqGaMUH6.cjs → generators-CU6zfet7.cjs} +149 -229
- package/dist/generators-CU6zfet7.cjs.map +1 -0
- package/dist/{generators-B86BJkmW.js → generators-nnZhtlrk.js} +151 -231
- package/dist/generators-nnZhtlrk.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +41 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +42 -19
- package/dist/index.js.map +1 -1
- package/dist/{types-Dh4HNR9K.d.ts → types-ANQXv7Gr.d.ts} +13 -17
- package/package.json +10 -18
- package/dist/components-DQAYLQW0.cjs.map +0 -1
- package/dist/components-IArDg-DO.js.map +0 -1
- package/dist/generators-B86BJkmW.js.map +0 -1
- package/dist/generators-BqGaMUH6.cjs.map +0 -1
- package/extension.yaml +0 -1484
- package/src/components/InfiniteQuery.tsx +0 -167
- package/src/components/InfiniteQueryOptions.tsx +0 -169
- package/src/components/Mutation.tsx +0 -123
- package/src/components/MutationKey.tsx +0 -1
- package/src/components/MutationOptions.tsx +0 -104
- package/src/components/Query.tsx +0 -125
- package/src/components/QueryKey.tsx +0 -1
- package/src/components/QueryOptions.tsx +0 -104
- package/src/components/SuspenseInfiniteQuery.tsx +0 -162
- package/src/components/SuspenseInfiniteQueryOptions.tsx +0 -163
- package/src/components/SuspenseQuery.tsx +0 -120
- 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 -200
- package/src/generators/mutationGenerator.tsx +0 -173
- package/src/generators/queryGenerator.tsx +0 -185
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +0 -209
- package/src/generators/suspenseQueryGenerator.tsx +0 -188
- package/src/index.ts +0 -2
- package/src/plugin.ts +0 -203
- package/src/resolvers/resolverReactQuery.ts +0 -118
- package/src/types.ts +0 -365
- package/src/utils.ts +0 -17
|
@@ -1,185 +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, pluginClientName } from '@kubb/plugin-client'
|
|
6
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
7
|
-
import { pluginZodName } from '@kubb/plugin-zod'
|
|
8
|
-
import { File, jsxRendererSync } 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: jsxRendererSync,
|
|
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 = parser === 'zod' ? 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)
|
|
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
|
-
{clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
|
|
102
|
-
</>
|
|
103
|
-
) : (
|
|
104
|
-
<>
|
|
105
|
-
{!shouldUseClientPlugin && <File.Import name={['client']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} />}
|
|
106
|
-
<File.Import
|
|
107
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
108
|
-
root={meta.file.path}
|
|
109
|
-
path={path.resolve(root, '.kubb/client.ts')}
|
|
110
|
-
isTypeOnly
|
|
111
|
-
/>
|
|
112
|
-
{clientOptions.dataReturnType === 'full' && (
|
|
113
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} isTypeOnly />
|
|
114
|
-
)}
|
|
115
|
-
</>
|
|
116
|
-
)}
|
|
117
|
-
{shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
|
|
118
|
-
{!shouldUseClientPlugin && <File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />}
|
|
119
|
-
{customOptions && <File.Import name={[customOptions.name]} path={customOptions.importPath} />}
|
|
120
|
-
{meta.fileTs && importedTypeNames.length > 0 && (
|
|
121
|
-
<File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
|
|
122
|
-
)}
|
|
123
|
-
|
|
124
|
-
<QueryKey
|
|
125
|
-
name={queryKeyName}
|
|
126
|
-
typeName={queryKeyTypeName}
|
|
127
|
-
node={node}
|
|
128
|
-
tsResolver={tsResolver}
|
|
129
|
-
pathParamsType={pathParamsType}
|
|
130
|
-
paramsCasing={paramsCasing}
|
|
131
|
-
transformer={ctx.options.queryKey}
|
|
132
|
-
/>
|
|
133
|
-
|
|
134
|
-
{!shouldUseClientPlugin && (
|
|
135
|
-
<Client
|
|
136
|
-
name={resolvedClientName}
|
|
137
|
-
baseURL={clientOptions.baseURL}
|
|
138
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
139
|
-
paramsCasing={clientOptions.paramsCasing || paramsCasing}
|
|
140
|
-
paramsType={paramsType}
|
|
141
|
-
pathParamsType={pathParamsType}
|
|
142
|
-
parser={parser}
|
|
143
|
-
node={node}
|
|
144
|
-
tsResolver={tsResolver}
|
|
145
|
-
zodResolver={zodResolver}
|
|
146
|
-
/>
|
|
147
|
-
)}
|
|
148
|
-
|
|
149
|
-
<File.Import name={['queryOptions']} path={importPath} />
|
|
150
|
-
|
|
151
|
-
<QueryOptions
|
|
152
|
-
name={queryOptionsName}
|
|
153
|
-
clientName={resolvedClientName}
|
|
154
|
-
queryKeyName={queryKeyName}
|
|
155
|
-
node={node}
|
|
156
|
-
tsResolver={tsResolver}
|
|
157
|
-
paramsCasing={paramsCasing}
|
|
158
|
-
paramsType={paramsType}
|
|
159
|
-
pathParamsType={pathParamsType}
|
|
160
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
161
|
-
/>
|
|
162
|
-
|
|
163
|
-
{query && (
|
|
164
|
-
<>
|
|
165
|
-
<File.Import name={['useQuery']} path={importPath} />
|
|
166
|
-
<File.Import name={['QueryKey', 'QueryClient', 'QueryObserverOptions', 'UseQueryResult']} path={importPath} isTypeOnly />
|
|
167
|
-
<Query
|
|
168
|
-
name={queryName}
|
|
169
|
-
queryOptionsName={queryOptionsName}
|
|
170
|
-
queryKeyName={queryKeyName}
|
|
171
|
-
queryKeyTypeName={queryKeyTypeName}
|
|
172
|
-
node={node}
|
|
173
|
-
tsResolver={tsResolver}
|
|
174
|
-
paramsCasing={paramsCasing}
|
|
175
|
-
paramsType={paramsType}
|
|
176
|
-
pathParamsType={pathParamsType}
|
|
177
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
178
|
-
customOptions={customOptions}
|
|
179
|
-
/>
|
|
180
|
-
</>
|
|
181
|
-
)}
|
|
182
|
-
</File>
|
|
183
|
-
)
|
|
184
|
-
},
|
|
185
|
-
})
|
|
@@ -1,209 +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, pluginClientName } from '@kubb/plugin-client'
|
|
6
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
7
|
-
import { pluginZodName } from '@kubb/plugin-zod'
|
|
8
|
-
import { File, jsxRendererSync } from '@kubb/renderer-jsx'
|
|
9
|
-
import { QueryKey, SuspenseInfiniteQuery, SuspenseInfiniteQueryOptions } from '../components'
|
|
10
|
-
import type { PluginReactQuery } from '../types'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Built-in generator for `useSuspenseInfiniteQuery` hooks. Enabled when both
|
|
14
|
-
* `suspense` and `infinite` are configured. Combines suspense semantics with
|
|
15
|
-
* cursor-based pagination — handlers throw promises while loading and pull
|
|
16
|
-
* additional pages on demand.
|
|
17
|
-
*/
|
|
18
|
-
export const suspenseInfiniteQueryGenerator = defineGenerator<PluginReactQuery>({
|
|
19
|
-
name: 'react-suspense-infinite-query',
|
|
20
|
-
renderer: jsxRendererSync,
|
|
21
|
-
operation(node, ctx) {
|
|
22
|
-
if (!ast.isHttpOperationNode(node)) return null
|
|
23
|
-
const { config, driver, resolver, root } = ctx
|
|
24
|
-
const {
|
|
25
|
-
output,
|
|
26
|
-
query,
|
|
27
|
-
mutation,
|
|
28
|
-
infinite,
|
|
29
|
-
suspense,
|
|
30
|
-
paramsCasing,
|
|
31
|
-
paramsType,
|
|
32
|
-
pathParamsType,
|
|
33
|
-
parser,
|
|
34
|
-
client: clientOptions,
|
|
35
|
-
group,
|
|
36
|
-
customOptions,
|
|
37
|
-
} = ctx.options
|
|
38
|
-
|
|
39
|
-
const pluginTs = driver.getPlugin(pluginTsName)
|
|
40
|
-
if (!pluginTs) return null
|
|
41
|
-
const tsResolver = driver.getResolver(pluginTsName)
|
|
42
|
-
|
|
43
|
-
const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
|
|
44
|
-
const queryMethods = new Set(query ? query.methods : [])
|
|
45
|
-
const isMutation =
|
|
46
|
-
mutation !== false &&
|
|
47
|
-
!isQuery &&
|
|
48
|
-
(mutation ? mutation.methods : []).some((method) => !queryMethods.has(method) && node.method.toLowerCase() === method.toLowerCase())
|
|
49
|
-
const isSuspense = !!suspense
|
|
50
|
-
const infiniteOptions = infinite && typeof infinite === 'object' ? infinite : null
|
|
51
|
-
|
|
52
|
-
if (!isQuery || isMutation || !isSuspense || !infiniteOptions) return null
|
|
53
|
-
|
|
54
|
-
// Validate queryParam exists in operation's query parameters
|
|
55
|
-
const normalizeKey = (key: string) => key.replace(/\?$/, '')
|
|
56
|
-
const queryParamKeys = getOperationParameters(node).query.map((p) => p.name)
|
|
57
|
-
const hasQueryParam = infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false
|
|
58
|
-
const hasCursorParam = !infiniteOptions.cursorParam || true
|
|
59
|
-
|
|
60
|
-
if (!hasQueryParam || !hasCursorParam) return null
|
|
61
|
-
|
|
62
|
-
const importPath = query ? query.importPath : '@tanstack/react-query'
|
|
63
|
-
|
|
64
|
-
const queryName = resolver.resolveSuspenseInfiniteQueryName(node)
|
|
65
|
-
const queryOptionsName = resolver.resolveSuspenseInfiniteQueryOptionsName(node)
|
|
66
|
-
const queryKeyName = resolver.resolveSuspenseInfiniteQueryKeyName(node)
|
|
67
|
-
const queryKeyTypeName = resolver.resolveSuspenseInfiniteQueryKeyTypeName(node)
|
|
68
|
-
const clientBaseName = resolver.resolveSuspenseInfiniteClientName(node)
|
|
69
|
-
|
|
70
|
-
const meta = {
|
|
71
|
-
file: resolver.resolveFile(operationFileEntry(node, queryName), { root, output, group: group ?? undefined }),
|
|
72
|
-
fileTs: tsResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
73
|
-
root,
|
|
74
|
-
output: pluginTs.options?.output ?? output,
|
|
75
|
-
group: pluginTs.options?.group ?? undefined,
|
|
76
|
-
}),
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, { paramsCasing, order: 'body-response-first' })
|
|
80
|
-
|
|
81
|
-
const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : null
|
|
82
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null
|
|
83
|
-
const fileZod = zodResolver
|
|
84
|
-
? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
85
|
-
root,
|
|
86
|
-
output: pluginZod?.options?.output ?? output,
|
|
87
|
-
group: pluginZod?.options?.group ?? undefined,
|
|
88
|
-
})
|
|
89
|
-
: null
|
|
90
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver)
|
|
91
|
-
|
|
92
|
-
const clientPlugin = driver.getPlugin(pluginClientName)
|
|
93
|
-
const hasClientPlugin = clientPlugin?.name === pluginClientName
|
|
94
|
-
const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
|
|
95
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null
|
|
96
|
-
|
|
97
|
-
const clientFile = shouldUseClientPlugin
|
|
98
|
-
? clientResolver?.resolveFile(operationFileEntry(node, node.operationId), {
|
|
99
|
-
root,
|
|
100
|
-
output: clientPlugin?.options?.output ?? output,
|
|
101
|
-
group: clientPlugin?.options?.group ?? undefined,
|
|
102
|
-
})
|
|
103
|
-
: null
|
|
104
|
-
|
|
105
|
-
const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientBaseName) : clientBaseName
|
|
106
|
-
|
|
107
|
-
return (
|
|
108
|
-
<File
|
|
109
|
-
baseName={meta.file.baseName}
|
|
110
|
-
path={meta.file.path}
|
|
111
|
-
meta={meta.file.meta}
|
|
112
|
-
banner={resolver.resolveBanner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
113
|
-
footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
114
|
-
>
|
|
115
|
-
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
116
|
-
{clientOptions.importPath ? (
|
|
117
|
-
<>
|
|
118
|
-
{!shouldUseClientPlugin && <File.Import name={'client'} path={clientOptions.importPath} />}
|
|
119
|
-
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
120
|
-
{clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
|
|
121
|
-
</>
|
|
122
|
-
) : (
|
|
123
|
-
<>
|
|
124
|
-
{!shouldUseClientPlugin && <File.Import name={['client']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} />}
|
|
125
|
-
<File.Import
|
|
126
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
127
|
-
root={meta.file.path}
|
|
128
|
-
path={path.resolve(root, '.kubb/client.ts')}
|
|
129
|
-
isTypeOnly
|
|
130
|
-
/>
|
|
131
|
-
{clientOptions.dataReturnType === 'full' && (
|
|
132
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} isTypeOnly />
|
|
133
|
-
)}
|
|
134
|
-
</>
|
|
135
|
-
)}
|
|
136
|
-
{shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
|
|
137
|
-
{!shouldUseClientPlugin && <File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />}
|
|
138
|
-
{customOptions && <File.Import name={[customOptions.name]} path={customOptions.importPath} />}
|
|
139
|
-
{meta.fileTs && importedTypeNames.length > 0 && (
|
|
140
|
-
<File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
|
|
141
|
-
)}
|
|
142
|
-
|
|
143
|
-
<QueryKey
|
|
144
|
-
name={queryKeyName}
|
|
145
|
-
typeName={queryKeyTypeName}
|
|
146
|
-
node={node}
|
|
147
|
-
tsResolver={tsResolver}
|
|
148
|
-
pathParamsType={pathParamsType}
|
|
149
|
-
paramsCasing={paramsCasing}
|
|
150
|
-
transformer={ctx.options.queryKey}
|
|
151
|
-
/>
|
|
152
|
-
|
|
153
|
-
{!shouldUseClientPlugin && (
|
|
154
|
-
<Client
|
|
155
|
-
name={resolvedClientName}
|
|
156
|
-
baseURL={clientOptions.baseURL}
|
|
157
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
158
|
-
paramsCasing={clientOptions.paramsCasing || paramsCasing}
|
|
159
|
-
paramsType={paramsType}
|
|
160
|
-
pathParamsType={pathParamsType}
|
|
161
|
-
parser={parser}
|
|
162
|
-
node={node}
|
|
163
|
-
tsResolver={tsResolver}
|
|
164
|
-
zodResolver={zodResolver}
|
|
165
|
-
/>
|
|
166
|
-
)}
|
|
167
|
-
|
|
168
|
-
<File.Import name={['InfiniteData']} isTypeOnly path={importPath} />
|
|
169
|
-
<File.Import name={['infiniteQueryOptions']} path={importPath} />
|
|
170
|
-
|
|
171
|
-
<SuspenseInfiniteQueryOptions
|
|
172
|
-
name={queryOptionsName}
|
|
173
|
-
clientName={resolvedClientName}
|
|
174
|
-
queryKeyName={queryKeyName}
|
|
175
|
-
node={node}
|
|
176
|
-
tsResolver={tsResolver}
|
|
177
|
-
paramsCasing={paramsCasing}
|
|
178
|
-
paramsType={paramsType}
|
|
179
|
-
pathParamsType={pathParamsType}
|
|
180
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
181
|
-
cursorParam={infiniteOptions.cursorParam}
|
|
182
|
-
nextParam={infiniteOptions.nextParam}
|
|
183
|
-
previousParam={infiniteOptions.previousParam}
|
|
184
|
-
initialPageParam={infiniteOptions.initialPageParam}
|
|
185
|
-
queryParam={infiniteOptions.queryParam}
|
|
186
|
-
/>
|
|
187
|
-
|
|
188
|
-
<File.Import name={['useSuspenseInfiniteQuery']} path={importPath} />
|
|
189
|
-
<File.Import name={['QueryKey', 'QueryClient', 'UseSuspenseInfiniteQueryOptions', 'UseSuspenseInfiniteQueryResult']} path={importPath} isTypeOnly />
|
|
190
|
-
|
|
191
|
-
<SuspenseInfiniteQuery
|
|
192
|
-
name={queryName}
|
|
193
|
-
queryOptionsName={queryOptionsName}
|
|
194
|
-
queryKeyName={queryKeyName}
|
|
195
|
-
queryKeyTypeName={queryKeyTypeName}
|
|
196
|
-
node={node}
|
|
197
|
-
tsResolver={tsResolver}
|
|
198
|
-
paramsCasing={paramsCasing}
|
|
199
|
-
paramsType={paramsType}
|
|
200
|
-
pathParamsType={pathParamsType}
|
|
201
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
202
|
-
initialPageParam={infiniteOptions.initialPageParam}
|
|
203
|
-
queryParam={infiniteOptions.queryParam}
|
|
204
|
-
customOptions={customOptions}
|
|
205
|
-
/>
|
|
206
|
-
</File>
|
|
207
|
-
)
|
|
208
|
-
},
|
|
209
|
-
})
|
|
@@ -1,188 +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, pluginClientName } from '@kubb/plugin-client'
|
|
6
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
7
|
-
import { pluginZodName } from '@kubb/plugin-zod'
|
|
8
|
-
import { File, jsxRendererSync } from '@kubb/renderer-jsx'
|
|
9
|
-
import { QueryKey, QueryOptions, SuspenseQuery } from '../components'
|
|
10
|
-
import type { PluginReactQuery } from '../types'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Built-in generator for `useSuspenseQuery` hooks. Enabled when
|
|
14
|
-
* `pluginReactQuery({ suspense: {} })`. Emits one `useFooSuspenseQuery` hook
|
|
15
|
-
* per query operation. Suspense queries throw promises while loading and
|
|
16
|
-
* require a `<Suspense>` boundary in the React tree. TanStack Query v5+ only.
|
|
17
|
-
*/
|
|
18
|
-
export const suspenseQueryGenerator = defineGenerator<PluginReactQuery>({
|
|
19
|
-
name: 'react-suspense-query',
|
|
20
|
-
renderer: jsxRendererSync,
|
|
21
|
-
operation(node, ctx) {
|
|
22
|
-
if (!ast.isHttpOperationNode(node)) return null
|
|
23
|
-
const { config, driver, resolver, root } = ctx
|
|
24
|
-
const { output, query, mutation, suspense, 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
|
-
// query: false means "this IS a query op" (suspense hooks still generate)
|
|
31
|
-
const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
|
|
32
|
-
const queryMethods = new Set(query ? query.methods : [])
|
|
33
|
-
const isMutation =
|
|
34
|
-
mutation !== false &&
|
|
35
|
-
!isQuery &&
|
|
36
|
-
(mutation ? mutation.methods : []).some((method) => !queryMethods.has(method) && node.method.toLowerCase() === method.toLowerCase())
|
|
37
|
-
const isSuspense = !!suspense
|
|
38
|
-
|
|
39
|
-
if (!isQuery || isMutation || !isSuspense) return null
|
|
40
|
-
|
|
41
|
-
const importPath = query ? query.importPath : '@tanstack/react-query'
|
|
42
|
-
|
|
43
|
-
const queryName = resolver.resolveSuspenseQueryName(node)
|
|
44
|
-
const queryOptionsName = resolver.resolveSuspenseQueryOptionsName(node)
|
|
45
|
-
const queryKeyName = resolver.resolveSuspenseQueryKeyName(node)
|
|
46
|
-
const queryKeyTypeName = resolver.resolveSuspenseQueryKeyTypeName(node)
|
|
47
|
-
const clientName = resolver.resolveSuspenseClientName(node)
|
|
48
|
-
|
|
49
|
-
const meta = {
|
|
50
|
-
file: resolver.resolveFile(operationFileEntry(node, queryName), { root, output, group: group ?? undefined }),
|
|
51
|
-
fileTs: tsResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
52
|
-
root,
|
|
53
|
-
output: pluginTs.options?.output ?? output,
|
|
54
|
-
group: pluginTs.options?.group ?? undefined,
|
|
55
|
-
}),
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, {
|
|
59
|
-
paramsCasing,
|
|
60
|
-
exclude: [queryKeyTypeName],
|
|
61
|
-
order: 'body-response-first',
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : null
|
|
65
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null
|
|
66
|
-
const fileZod = zodResolver
|
|
67
|
-
? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
68
|
-
root,
|
|
69
|
-
output: pluginZod?.options?.output ?? output,
|
|
70
|
-
group: pluginZod?.options?.group ?? undefined,
|
|
71
|
-
})
|
|
72
|
-
: null
|
|
73
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver)
|
|
74
|
-
|
|
75
|
-
const clientPlugin = driver.getPlugin(pluginClientName)
|
|
76
|
-
const hasClientPlugin = clientPlugin?.name === pluginClientName
|
|
77
|
-
const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
|
|
78
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null
|
|
79
|
-
|
|
80
|
-
const clientFile = shouldUseClientPlugin
|
|
81
|
-
? clientResolver?.resolveFile(operationFileEntry(node, node.operationId), {
|
|
82
|
-
root,
|
|
83
|
-
output: clientPlugin?.options?.output ?? output,
|
|
84
|
-
group: clientPlugin?.options?.group ?? undefined,
|
|
85
|
-
})
|
|
86
|
-
: null
|
|
87
|
-
|
|
88
|
-
const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientName) : clientName
|
|
89
|
-
|
|
90
|
-
return (
|
|
91
|
-
<File
|
|
92
|
-
baseName={meta.file.baseName}
|
|
93
|
-
path={meta.file.path}
|
|
94
|
-
meta={meta.file.meta}
|
|
95
|
-
banner={resolver.resolveBanner(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
96
|
-
footer={resolver.resolveFooter(ctx.meta, { output, config, file: { path: meta.file.path, baseName: meta.file.baseName } })}
|
|
97
|
-
>
|
|
98
|
-
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
99
|
-
{clientOptions.importPath ? (
|
|
100
|
-
<>
|
|
101
|
-
{!shouldUseClientPlugin && <File.Import name={'client'} path={clientOptions.importPath} />}
|
|
102
|
-
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
103
|
-
{clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
|
|
104
|
-
</>
|
|
105
|
-
) : (
|
|
106
|
-
<>
|
|
107
|
-
{!shouldUseClientPlugin && <File.Import name={['client']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} />}
|
|
108
|
-
<File.Import
|
|
109
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
110
|
-
root={meta.file.path}
|
|
111
|
-
path={path.resolve(root, '.kubb/client.ts')}
|
|
112
|
-
isTypeOnly
|
|
113
|
-
/>
|
|
114
|
-
{clientOptions.dataReturnType === 'full' && (
|
|
115
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} isTypeOnly />
|
|
116
|
-
)}
|
|
117
|
-
</>
|
|
118
|
-
)}
|
|
119
|
-
{shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
|
|
120
|
-
{!shouldUseClientPlugin && <File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />}
|
|
121
|
-
{customOptions && <File.Import name={[customOptions.name]} path={customOptions.importPath} />}
|
|
122
|
-
{meta.fileTs && importedTypeNames.length > 0 && (
|
|
123
|
-
<File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
|
|
124
|
-
)}
|
|
125
|
-
|
|
126
|
-
<QueryKey
|
|
127
|
-
name={queryKeyName}
|
|
128
|
-
typeName={queryKeyTypeName}
|
|
129
|
-
node={node}
|
|
130
|
-
tsResolver={tsResolver}
|
|
131
|
-
pathParamsType={pathParamsType}
|
|
132
|
-
paramsCasing={paramsCasing}
|
|
133
|
-
transformer={ctx.options.queryKey}
|
|
134
|
-
/>
|
|
135
|
-
|
|
136
|
-
{!shouldUseClientPlugin && (
|
|
137
|
-
<Client
|
|
138
|
-
name={resolvedClientName}
|
|
139
|
-
baseURL={clientOptions.baseURL}
|
|
140
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
141
|
-
paramsCasing={clientOptions.paramsCasing || paramsCasing}
|
|
142
|
-
paramsType={paramsType}
|
|
143
|
-
pathParamsType={pathParamsType}
|
|
144
|
-
parser={parser}
|
|
145
|
-
node={node}
|
|
146
|
-
tsResolver={tsResolver}
|
|
147
|
-
zodResolver={zodResolver}
|
|
148
|
-
/>
|
|
149
|
-
)}
|
|
150
|
-
|
|
151
|
-
<File.Import name={['queryOptions']} path={importPath} />
|
|
152
|
-
|
|
153
|
-
<QueryOptions
|
|
154
|
-
name={queryOptionsName}
|
|
155
|
-
clientName={resolvedClientName}
|
|
156
|
-
queryKeyName={queryKeyName}
|
|
157
|
-
node={node}
|
|
158
|
-
tsResolver={tsResolver}
|
|
159
|
-
paramsCasing={paramsCasing}
|
|
160
|
-
paramsType={paramsType}
|
|
161
|
-
pathParamsType={pathParamsType}
|
|
162
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
163
|
-
suspense
|
|
164
|
-
/>
|
|
165
|
-
|
|
166
|
-
{suspense && (
|
|
167
|
-
<>
|
|
168
|
-
<File.Import name={['useSuspenseQuery']} path={importPath} />
|
|
169
|
-
<File.Import name={['QueryKey', 'QueryClient', 'UseSuspenseQueryOptions', 'UseSuspenseQueryResult']} path={importPath} isTypeOnly />
|
|
170
|
-
<SuspenseQuery
|
|
171
|
-
name={queryName}
|
|
172
|
-
queryOptionsName={queryOptionsName}
|
|
173
|
-
queryKeyName={queryKeyName}
|
|
174
|
-
queryKeyTypeName={queryKeyTypeName}
|
|
175
|
-
node={node}
|
|
176
|
-
tsResolver={tsResolver}
|
|
177
|
-
paramsCasing={paramsCasing}
|
|
178
|
-
paramsType={paramsType}
|
|
179
|
-
pathParamsType={pathParamsType}
|
|
180
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
181
|
-
customOptions={customOptions}
|
|
182
|
-
/>
|
|
183
|
-
</>
|
|
184
|
-
)}
|
|
185
|
-
</File>
|
|
186
|
-
)
|
|
187
|
-
},
|
|
188
|
-
})
|
package/src/index.ts
DELETED