@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.
- package/README.md +22 -26
- package/dist/index.cjs +2288 -191
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +494 -6
- package/dist/index.js +2258 -185
- package/dist/index.js.map +1 -1
- package/package.json +11 -34
- package/dist/components-Dow6tde8.js +0 -1459
- package/dist/components-Dow6tde8.js.map +0 -1
- package/dist/components-HwdCDefj.cjs +0 -1603
- package/dist/components-HwdCDefj.cjs.map +0 -1
- package/dist/components.cjs +0 -13
- package/dist/components.d.ts +0 -268
- package/dist/components.js +0 -2
- package/dist/generators-CcOmnTPa.cjs +0 -1454
- package/dist/generators-CcOmnTPa.cjs.map +0 -1
- package/dist/generators-yfZr_qfT.js +0 -1412
- package/dist/generators-yfZr_qfT.js.map +0 -1
- package/dist/generators.cjs +0 -9
- package/dist/generators.d.ts +0 -27
- package/dist/generators.js +0 -2
- package/dist/types-DG_OxOym.d.ts +0 -363
- package/extension.yaml +0 -911
- package/src/components/InfiniteQuery.tsx +0 -161
- package/src/components/InfiniteQueryOptions.tsx +0 -178
- package/src/components/Mutation.tsx +0 -121
- package/src/components/MutationKey.tsx +0 -1
- package/src/components/MutationOptions.tsx +0 -103
- package/src/components/Query.tsx +0 -118
- package/src/components/QueryKey.tsx +0 -1
- package/src/components/QueryOptions.tsx +0 -99
- package/src/components/SuspenseInfiniteQuery.tsx +0 -161
- package/src/components/SuspenseInfiniteQueryOptions.tsx +0 -178
- package/src/components/SuspenseQuery.tsx +0 -118
- package/src/components/index.ts +0 -11
- package/src/generators/customHookOptionsFileGenerator.tsx +0 -84
- package/src/generators/hookOptionsGenerator.tsx +0 -133
- package/src/generators/index.ts +0 -7
- package/src/generators/infiniteQueryGenerator.tsx +0 -194
- package/src/generators/mutationGenerator.tsx +0 -168
- package/src/generators/queryGenerator.tsx +0 -180
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +0 -203
- package/src/generators/suspenseQueryGenerator.tsx +0 -181
- package/src/index.ts +0 -2
- package/src/plugin.ts +0 -186
- package/src/resolvers/resolverReactQuery.ts +0 -107
- package/src/types.ts +0 -328
- package/src/utils.ts +0 -10
- /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { getOperationParameters } from '@internals/shared'
|
|
2
|
-
import { defineGenerator } from '@kubb/core'
|
|
3
|
-
import { File, jsxRenderer, Type } from '@kubb/renderer-jsx'
|
|
4
|
-
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
5
|
-
import { difference } from 'remeda'
|
|
6
|
-
import type { PluginReactQuery } from '../types'
|
|
7
|
-
import { resolveOperationOverrides } from '../utils.ts'
|
|
8
|
-
|
|
9
|
-
type QueryOption = PluginReactQuery['resolvedOptions']['query']
|
|
10
|
-
type MutationOption = PluginReactQuery['resolvedOptions']['mutation']
|
|
11
|
-
|
|
12
|
-
export const hookOptionsGenerator = defineGenerator<PluginReactQuery>({
|
|
13
|
-
name: 'react-query-hook-options',
|
|
14
|
-
renderer: jsxRenderer,
|
|
15
|
-
operations(nodes, ctx) {
|
|
16
|
-
const { resolver, config, root, adapter } = ctx
|
|
17
|
-
const { output, customOptions, query, mutation, suspense, infinite, group, override } = ctx.options
|
|
18
|
-
|
|
19
|
-
if (!customOptions) return null
|
|
20
|
-
|
|
21
|
-
const name = resolver.resolveHookOptionsName()
|
|
22
|
-
const resolvedFile = resolver.resolveFile({ name, extname: '.ts' }, { root, output, group })
|
|
23
|
-
const hookOptionsFile = {
|
|
24
|
-
...resolvedFile,
|
|
25
|
-
baseName: `${name}.ts` as const,
|
|
26
|
-
path: resolvedFile.path.replace(/[^/\\]+\.ts$/, `${name}.ts`),
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const imports: KubbReactNode[] = []
|
|
30
|
-
const hookOptions: Record<string, string> = {}
|
|
31
|
-
|
|
32
|
-
for (const node of nodes) {
|
|
33
|
-
const opOverrides = resolveOperationOverrides(node, override)
|
|
34
|
-
const nodeQuery: QueryOption = 'query' in opOverrides ? (opOverrides.query as QueryOption) : query
|
|
35
|
-
const nodeMutation: MutationOption = 'mutation' in opOverrides ? (opOverrides.mutation as MutationOption) : mutation
|
|
36
|
-
const nodeInfinite = 'infinite' in opOverrides ? opOverrides.infinite : infinite
|
|
37
|
-
const nodeInfiniteOptions = nodeInfinite && typeof nodeInfinite === 'object' ? nodeInfinite : undefined
|
|
38
|
-
|
|
39
|
-
// query: false means "still a query but skip the useQuery hook"
|
|
40
|
-
const isQueryOp =
|
|
41
|
-
nodeQuery === false
|
|
42
|
-
? !!query && query.methods.some((m) => node.method.toLowerCase() === m.toLowerCase())
|
|
43
|
-
: !!nodeQuery && nodeQuery.methods.some((m) => node.method.toLowerCase() === m.toLowerCase())
|
|
44
|
-
const isMutationOp =
|
|
45
|
-
nodeMutation !== false &&
|
|
46
|
-
!isQueryOp &&
|
|
47
|
-
difference(nodeMutation ? nodeMutation.methods : [], nodeQuery ? nodeQuery.methods : []).some((m) => node.method.toLowerCase() === m.toLowerCase())
|
|
48
|
-
const isSuspenseOp = !!suspense
|
|
49
|
-
const isInfiniteOp = !!nodeInfiniteOptions
|
|
50
|
-
|
|
51
|
-
if (isQueryOp) {
|
|
52
|
-
const queryOptionsName = resolver.resolveQueryOptionsName(node)
|
|
53
|
-
const queryHookName = resolver.resolveQueryName(node)
|
|
54
|
-
const queryHookFile = resolver.resolveFile(
|
|
55
|
-
{ name: queryHookName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
56
|
-
{ root, output, group },
|
|
57
|
-
)
|
|
58
|
-
imports.push(<File.Import name={[queryOptionsName]} root={hookOptionsFile.path} path={queryHookFile.path} />)
|
|
59
|
-
hookOptions[queryHookName] = `Partial<ReturnType<typeof ${queryOptionsName}>>`
|
|
60
|
-
|
|
61
|
-
if (isSuspenseOp) {
|
|
62
|
-
const suspenseOptionsName = resolver.resolveSuspenseQueryOptionsName(node)
|
|
63
|
-
const suspenseHookName = resolver.resolveSuspenseQueryName(node)
|
|
64
|
-
const suspenseHookFile = resolver.resolveFile(
|
|
65
|
-
{ name: suspenseHookName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
66
|
-
{ root, output, group },
|
|
67
|
-
)
|
|
68
|
-
imports.push(<File.Import name={[suspenseOptionsName]} root={hookOptionsFile.path} path={suspenseHookFile.path} />)
|
|
69
|
-
hookOptions[suspenseHookName] = `Partial<ReturnType<typeof ${suspenseOptionsName}>>`
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (isInfiniteOp) {
|
|
73
|
-
// Validate queryParam
|
|
74
|
-
const normalizeKey = (key: string) => key.replace(/\?$/, '')
|
|
75
|
-
const queryParamKeys = getOperationParameters(node).query.map((p) => p.name)
|
|
76
|
-
const hasQueryParam = nodeInfiniteOptions!.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === nodeInfiniteOptions!.queryParam) : false
|
|
77
|
-
|
|
78
|
-
if (hasQueryParam) {
|
|
79
|
-
const infiniteOptionsName = resolver.resolveInfiniteQueryOptionsName(node)
|
|
80
|
-
const infiniteHookName = resolver.resolveInfiniteQueryName(node)
|
|
81
|
-
const infiniteHookFile = resolver.resolveFile(
|
|
82
|
-
{ name: infiniteHookName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
83
|
-
{ root, output, group },
|
|
84
|
-
)
|
|
85
|
-
imports.push(<File.Import name={[infiniteOptionsName]} root={hookOptionsFile.path} path={infiniteHookFile.path} />)
|
|
86
|
-
hookOptions[infiniteHookName] = `Partial<ReturnType<typeof ${infiniteOptionsName}>>`
|
|
87
|
-
|
|
88
|
-
if (isSuspenseOp) {
|
|
89
|
-
const suspenseInfiniteOptionsName = resolver.resolveSuspenseInfiniteQueryOptionsName(node)
|
|
90
|
-
const suspenseInfiniteHookName = resolver.resolveSuspenseInfiniteQueryName(node)
|
|
91
|
-
const suspenseInfiniteHookFile = resolver.resolveFile(
|
|
92
|
-
{ name: suspenseInfiniteHookName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
93
|
-
{ root, output, group },
|
|
94
|
-
)
|
|
95
|
-
imports.push(<File.Import name={[suspenseInfiniteOptionsName]} root={hookOptionsFile.path} path={suspenseInfiniteHookFile.path} />)
|
|
96
|
-
hookOptions[suspenseInfiniteHookName] = `Partial<ReturnType<typeof ${suspenseInfiniteOptionsName}>>`
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (isMutationOp) {
|
|
103
|
-
const mutationOptionsName = resolver.resolveMutationOptionsName(node)
|
|
104
|
-
const mutationHookName = resolver.resolveMutationName(node)
|
|
105
|
-
const mutationHookFile = resolver.resolveFile(
|
|
106
|
-
{ name: mutationHookName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
107
|
-
{ root, output, group },
|
|
108
|
-
)
|
|
109
|
-
imports.push(<File.Import name={[mutationOptionsName]} root={hookOptionsFile.path} path={mutationHookFile.path} />)
|
|
110
|
-
hookOptions[mutationHookName] = `Partial<ReturnType<typeof ${mutationOptionsName}>>`
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return (
|
|
115
|
-
<File
|
|
116
|
-
baseName={hookOptionsFile.baseName}
|
|
117
|
-
path={hookOptionsFile.path}
|
|
118
|
-
meta={hookOptionsFile.meta}
|
|
119
|
-
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
120
|
-
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
121
|
-
>
|
|
122
|
-
{imports}
|
|
123
|
-
<File.Source name={name} isExportable isIndexable isTypeOnly>
|
|
124
|
-
<Type export name={name}>
|
|
125
|
-
{`{ ${Object.keys(hookOptions)
|
|
126
|
-
.map((key) => `${JSON.stringify(key)}: ${hookOptions[key]}`)
|
|
127
|
-
.join(', ')} }`}
|
|
128
|
-
</Type>
|
|
129
|
-
</File.Source>
|
|
130
|
-
</File>
|
|
131
|
-
)
|
|
132
|
-
},
|
|
133
|
-
})
|
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,194 +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 { InfiniteQuery, InfiniteQueryOptions, QueryKey } from '../components'
|
|
11
|
-
import type { PluginReactQuery } from '../types'
|
|
12
|
-
|
|
13
|
-
export const infiniteQueryGenerator = defineGenerator<PluginReactQuery>({
|
|
14
|
-
name: 'react-infinite-query',
|
|
15
|
-
renderer: jsxRenderer,
|
|
16
|
-
operation(node, ctx) {
|
|
17
|
-
const { adapter, config, driver, resolver, root } = ctx
|
|
18
|
-
const { output, query, mutation, infinite, 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
|
-
const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
|
|
25
|
-
const isMutation =
|
|
26
|
-
mutation !== false &&
|
|
27
|
-
!isQuery &&
|
|
28
|
-
difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase())
|
|
29
|
-
const infiniteOptions = infinite && typeof infinite === 'object' ? infinite : undefined
|
|
30
|
-
|
|
31
|
-
if (!isQuery || isMutation || !infiniteOptions) return null
|
|
32
|
-
|
|
33
|
-
// Validate queryParam exists in operation's query parameters
|
|
34
|
-
const normalizeKey = (key: string) => key.replace(/\?$/, '')
|
|
35
|
-
const queryParamKeys = getOperationParameters(node).query.map((p) => p.name)
|
|
36
|
-
const hasQueryParam = infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false
|
|
37
|
-
// cursorParam validation against response schema keys is skipped in v5 (complex schema inspection)
|
|
38
|
-
const hasCursorParam = !infiniteOptions.cursorParam || true
|
|
39
|
-
|
|
40
|
-
if (!hasQueryParam || !hasCursorParam) return null
|
|
41
|
-
|
|
42
|
-
const importPath = query ? query.importPath : '@tanstack/react-query'
|
|
43
|
-
|
|
44
|
-
const queryName = resolver.resolveInfiniteQueryName(node)
|
|
45
|
-
const queryOptionsName = resolver.resolveInfiniteQueryOptionsName(node)
|
|
46
|
-
const queryKeyName = resolver.resolveInfiniteQueryKeyName(node)
|
|
47
|
-
const queryKeyTypeName = resolver.resolveInfiniteQueryKeyTypeName(node)
|
|
48
|
-
const clientBaseName = resolver.resolveInfiniteClientName(node)
|
|
49
|
-
|
|
50
|
-
const meta = {
|
|
51
|
-
file: resolver.resolveFile({ name: queryName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path }, { root, output, group }),
|
|
52
|
-
fileTs: tsResolver.resolveFile(
|
|
53
|
-
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
54
|
-
{ root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group },
|
|
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) : undefined
|
|
65
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : undefined
|
|
66
|
-
const fileZod = zodResolver
|
|
67
|
-
? zodResolver.resolveFile(
|
|
68
|
-
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
69
|
-
{ root, output: pluginZod?.options?.output ?? output, group: pluginZod?.options?.group },
|
|
70
|
-
)
|
|
71
|
-
: undefined
|
|
72
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver)
|
|
73
|
-
|
|
74
|
-
const clientPlugin = driver.getPlugin(pluginClientName)
|
|
75
|
-
const hasClientPlugin = clientPlugin?.name === pluginClientName
|
|
76
|
-
const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
|
|
77
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : undefined
|
|
78
|
-
|
|
79
|
-
const clientFile = shouldUseClientPlugin
|
|
80
|
-
? clientResolver?.resolveFile(
|
|
81
|
-
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
82
|
-
{
|
|
83
|
-
root,
|
|
84
|
-
output: clientPlugin?.options?.output ?? output,
|
|
85
|
-
group: clientPlugin?.options?.group,
|
|
86
|
-
},
|
|
87
|
-
)
|
|
88
|
-
: undefined
|
|
89
|
-
|
|
90
|
-
const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientBaseName) : clientBaseName
|
|
91
|
-
|
|
92
|
-
return (
|
|
93
|
-
<File
|
|
94
|
-
baseName={meta.file.baseName}
|
|
95
|
-
path={meta.file.path}
|
|
96
|
-
meta={meta.file.meta}
|
|
97
|
-
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
98
|
-
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
99
|
-
>
|
|
100
|
-
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
101
|
-
{clientOptions.importPath ? (
|
|
102
|
-
<>
|
|
103
|
-
{!shouldUseClientPlugin && <File.Import name={'fetch'} path={clientOptions.importPath} />}
|
|
104
|
-
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
105
|
-
{clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
|
|
106
|
-
</>
|
|
107
|
-
) : (
|
|
108
|
-
<>
|
|
109
|
-
{!shouldUseClientPlugin && <File.Import name={['fetch']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} />}
|
|
110
|
-
<File.Import
|
|
111
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
112
|
-
root={meta.file.path}
|
|
113
|
-
path={path.resolve(root, '.kubb/fetch.ts')}
|
|
114
|
-
isTypeOnly
|
|
115
|
-
/>
|
|
116
|
-
{clientOptions.dataReturnType === 'full' && (
|
|
117
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} isTypeOnly />
|
|
118
|
-
)}
|
|
119
|
-
</>
|
|
120
|
-
)}
|
|
121
|
-
{shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
|
|
122
|
-
{!shouldUseClientPlugin && <File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />}
|
|
123
|
-
{customOptions && <File.Import name={[customOptions.name]} path={customOptions.importPath} />}
|
|
124
|
-
{meta.fileTs && importedTypeNames.length > 0 && (
|
|
125
|
-
<File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
|
|
126
|
-
)}
|
|
127
|
-
|
|
128
|
-
<QueryKey
|
|
129
|
-
name={queryKeyName}
|
|
130
|
-
typeName={queryKeyTypeName}
|
|
131
|
-
node={node}
|
|
132
|
-
tsResolver={tsResolver}
|
|
133
|
-
pathParamsType={pathParamsType}
|
|
134
|
-
paramsCasing={paramsCasing}
|
|
135
|
-
transformer={ctx.options.queryKey}
|
|
136
|
-
/>
|
|
137
|
-
|
|
138
|
-
{!shouldUseClientPlugin && (
|
|
139
|
-
<Client
|
|
140
|
-
name={resolvedClientName}
|
|
141
|
-
baseURL={clientOptions.baseURL}
|
|
142
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
143
|
-
paramsCasing={clientOptions.paramsCasing || paramsCasing}
|
|
144
|
-
paramsType={paramsType}
|
|
145
|
-
pathParamsType={pathParamsType}
|
|
146
|
-
parser={parser}
|
|
147
|
-
node={node}
|
|
148
|
-
tsResolver={tsResolver}
|
|
149
|
-
zodResolver={zodResolver}
|
|
150
|
-
/>
|
|
151
|
-
)}
|
|
152
|
-
|
|
153
|
-
<File.Import name={['InfiniteData']} isTypeOnly path={importPath} />
|
|
154
|
-
<File.Import name={['infiniteQueryOptions']} path={importPath} />
|
|
155
|
-
|
|
156
|
-
<InfiniteQueryOptions
|
|
157
|
-
name={queryOptionsName}
|
|
158
|
-
clientName={resolvedClientName}
|
|
159
|
-
queryKeyName={queryKeyName}
|
|
160
|
-
node={node}
|
|
161
|
-
tsResolver={tsResolver}
|
|
162
|
-
paramsCasing={paramsCasing}
|
|
163
|
-
paramsType={paramsType}
|
|
164
|
-
pathParamsType={pathParamsType}
|
|
165
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
166
|
-
cursorParam={infiniteOptions.cursorParam}
|
|
167
|
-
nextParam={infiniteOptions.nextParam}
|
|
168
|
-
previousParam={infiniteOptions.previousParam}
|
|
169
|
-
initialPageParam={infiniteOptions.initialPageParam}
|
|
170
|
-
queryParam={infiniteOptions.queryParam}
|
|
171
|
-
/>
|
|
172
|
-
|
|
173
|
-
<File.Import name={['useInfiniteQuery']} path={importPath} />
|
|
174
|
-
<File.Import name={['QueryKey', 'QueryClient', 'InfiniteQueryObserverOptions', 'UseInfiniteQueryResult']} path={importPath} isTypeOnly />
|
|
175
|
-
|
|
176
|
-
<InfiniteQuery
|
|
177
|
-
name={queryName}
|
|
178
|
-
queryOptionsName={queryOptionsName}
|
|
179
|
-
queryKeyName={queryKeyName}
|
|
180
|
-
queryKeyTypeName={queryKeyTypeName}
|
|
181
|
-
node={node}
|
|
182
|
-
tsResolver={tsResolver}
|
|
183
|
-
paramsCasing={paramsCasing}
|
|
184
|
-
paramsType={paramsType}
|
|
185
|
-
pathParamsType={pathParamsType}
|
|
186
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
187
|
-
initialPageParam={infiniteOptions.initialPageParam}
|
|
188
|
-
queryParam={infiniteOptions.queryParam}
|
|
189
|
-
customOptions={customOptions}
|
|
190
|
-
/>
|
|
191
|
-
</File>
|
|
192
|
-
)
|
|
193
|
-
},
|
|
194
|
-
})
|
|
@@ -1,168 +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 { Mutation, MutationKey, MutationOptions } from '../components'
|
|
11
|
-
import type { PluginReactQuery } from '../types'
|
|
12
|
-
|
|
13
|
-
export const mutationGenerator = defineGenerator<PluginReactQuery>({
|
|
14
|
-
name: 'react-query-mutation',
|
|
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
|
-
const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
|
|
25
|
-
const isMutation =
|
|
26
|
-
mutation !== false &&
|
|
27
|
-
!isQuery &&
|
|
28
|
-
difference(mutation ? mutation.methods : [], query ? query.methods : []).some((method) => node.method.toLowerCase() === method.toLowerCase())
|
|
29
|
-
|
|
30
|
-
if (!isMutation) return null
|
|
31
|
-
|
|
32
|
-
const importPath = mutation ? mutation.importPath : '@tanstack/react-query'
|
|
33
|
-
|
|
34
|
-
const mutationHookName = resolver.resolveMutationName(node)
|
|
35
|
-
const mutationTypeName = resolver.resolveMutationTypeName(node)
|
|
36
|
-
const mutationOptionsName = resolver.resolveMutationOptionsName(node)
|
|
37
|
-
const mutationKeyName = resolver.resolveMutationKeyName(node)
|
|
38
|
-
const clientName = resolver.resolveClientName(node)
|
|
39
|
-
|
|
40
|
-
const meta = {
|
|
41
|
-
file: resolver.resolveFile({ name: mutationHookName, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path }, { root, output, group }),
|
|
42
|
-
fileTs: tsResolver.resolveFile(
|
|
43
|
-
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
44
|
-
{ root, output: pluginTs.options?.output ?? output, group: pluginTs.options?.group },
|
|
45
|
-
),
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const importedTypeNames = resolveOperationTypeNames(node, tsResolver, { paramsCasing, order: 'body-response-first' })
|
|
49
|
-
|
|
50
|
-
const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : undefined
|
|
51
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : undefined
|
|
52
|
-
const fileZod = zodResolver
|
|
53
|
-
? zodResolver.resolveFile(
|
|
54
|
-
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
55
|
-
{ root, output: pluginZod?.options?.output ?? output, group: pluginZod?.options?.group },
|
|
56
|
-
)
|
|
57
|
-
: undefined
|
|
58
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver)
|
|
59
|
-
|
|
60
|
-
const clientPlugin = driver.getPlugin(pluginClientName)
|
|
61
|
-
const hasClientPlugin = clientPlugin?.name === pluginClientName
|
|
62
|
-
const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
|
|
63
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : undefined
|
|
64
|
-
|
|
65
|
-
const clientFile = shouldUseClientPlugin
|
|
66
|
-
? clientResolver?.resolveFile(
|
|
67
|
-
{ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
|
|
68
|
-
{
|
|
69
|
-
root,
|
|
70
|
-
output: clientPlugin?.options?.output ?? output,
|
|
71
|
-
group: clientPlugin?.options?.group,
|
|
72
|
-
},
|
|
73
|
-
)
|
|
74
|
-
: undefined
|
|
75
|
-
|
|
76
|
-
const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientName) : clientName
|
|
77
|
-
|
|
78
|
-
return (
|
|
79
|
-
<File
|
|
80
|
-
baseName={meta.file.baseName}
|
|
81
|
-
path={meta.file.path}
|
|
82
|
-
meta={meta.file.meta}
|
|
83
|
-
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
84
|
-
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
85
|
-
>
|
|
86
|
-
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
87
|
-
{clientOptions.importPath ? (
|
|
88
|
-
<>
|
|
89
|
-
{!shouldUseClientPlugin && <File.Import name={'fetch'} path={clientOptions.importPath} />}
|
|
90
|
-
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
91
|
-
{clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
|
|
92
|
-
</>
|
|
93
|
-
) : (
|
|
94
|
-
<>
|
|
95
|
-
{!shouldUseClientPlugin && <File.Import name={['fetch']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} />}
|
|
96
|
-
<File.Import
|
|
97
|
-
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
98
|
-
root={meta.file.path}
|
|
99
|
-
path={path.resolve(root, '.kubb/fetch.ts')}
|
|
100
|
-
isTypeOnly
|
|
101
|
-
/>
|
|
102
|
-
{clientOptions.dataReturnType === 'full' && (
|
|
103
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} isTypeOnly />
|
|
104
|
-
)}
|
|
105
|
-
</>
|
|
106
|
-
)}
|
|
107
|
-
{shouldUseClientPlugin && clientFile && <File.Import name={[resolvedClientName]} root={meta.file.path} path={clientFile.path} />}
|
|
108
|
-
{!shouldUseClientPlugin && node.requestBody?.content?.some((e) => e.contentType === 'multipart/form-data') && (
|
|
109
|
-
<File.Import name={['buildFormData']} root={meta.file.path} path={path.resolve(root, '.kubb/config.ts')} />
|
|
110
|
-
)}
|
|
111
|
-
{customOptions && <File.Import name={[customOptions.name]} path={customOptions.importPath} />}
|
|
112
|
-
{meta.fileTs && importedTypeNames.length > 0 && (
|
|
113
|
-
<File.Import name={Array.from(new Set(importedTypeNames))} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />
|
|
114
|
-
)}
|
|
115
|
-
|
|
116
|
-
<MutationKey name={mutationKeyName} node={node} pathParamsType={pathParamsType} paramsCasing={paramsCasing} transformer={ctx.options.mutationKey} />
|
|
117
|
-
|
|
118
|
-
{!shouldUseClientPlugin && (
|
|
119
|
-
<Client
|
|
120
|
-
name={resolvedClientName}
|
|
121
|
-
baseURL={clientOptions.baseURL}
|
|
122
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
123
|
-
paramsCasing={clientOptions.paramsCasing || paramsCasing}
|
|
124
|
-
paramsType={paramsType}
|
|
125
|
-
pathParamsType={pathParamsType}
|
|
126
|
-
parser={parser}
|
|
127
|
-
node={node}
|
|
128
|
-
tsResolver={tsResolver}
|
|
129
|
-
zodResolver={zodResolver}
|
|
130
|
-
/>
|
|
131
|
-
)}
|
|
132
|
-
|
|
133
|
-
<File.Import name={['mutationOptions']} path={importPath} />
|
|
134
|
-
|
|
135
|
-
<MutationOptions
|
|
136
|
-
name={mutationOptionsName}
|
|
137
|
-
clientName={resolvedClientName}
|
|
138
|
-
mutationKeyName={mutationKeyName}
|
|
139
|
-
node={node}
|
|
140
|
-
tsResolver={tsResolver}
|
|
141
|
-
paramsCasing={paramsCasing}
|
|
142
|
-
paramsType={paramsType}
|
|
143
|
-
pathParamsType={pathParamsType}
|
|
144
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
145
|
-
/>
|
|
146
|
-
|
|
147
|
-
{mutation && (
|
|
148
|
-
<>
|
|
149
|
-
<File.Import name={['useMutation']} path={importPath} />
|
|
150
|
-
<File.Import name={['UseMutationOptions', 'UseMutationResult', 'QueryClient']} path={importPath} isTypeOnly />
|
|
151
|
-
<Mutation
|
|
152
|
-
name={mutationHookName}
|
|
153
|
-
typeName={mutationTypeName}
|
|
154
|
-
mutationOptionsName={mutationOptionsName}
|
|
155
|
-
mutationKeyName={mutationKeyName}
|
|
156
|
-
node={node}
|
|
157
|
-
tsResolver={tsResolver}
|
|
158
|
-
dataReturnType={clientOptions.dataReturnType || 'data'}
|
|
159
|
-
paramsCasing={paramsCasing}
|
|
160
|
-
pathParamsType={pathParamsType}
|
|
161
|
-
customOptions={customOptions}
|
|
162
|
-
/>
|
|
163
|
-
</>
|
|
164
|
-
)}
|
|
165
|
-
</File>
|
|
166
|
-
)
|
|
167
|
-
},
|
|
168
|
-
})
|