@kubb/plugin-vue-query 5.0.0-beta.4 → 5.0.0-beta.56
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 +39 -22
- package/dist/{components-D1UhYFgY.js → components-B79Gljyl.js} +483 -565
- package/dist/components-B79Gljyl.js.map +1 -0
- package/dist/{components-qfOFRSoM.cjs → components-D3xIZ9FA.cjs} +513 -565
- package/dist/components-D3xIZ9FA.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +4 -68
- package/dist/components.js +1 -1
- package/dist/{generators-C4gs_P1i.cjs → generators-BTtcGtUY.cjs} +225 -314
- package/dist/generators-BTtcGtUY.cjs.map +1 -0
- package/dist/generators-D95ddIFV.js +620 -0
- package/dist/generators-D95ddIFV.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +21 -6
- package/dist/generators.js +1 -1
- package/dist/index.cjs +158 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +31 -4
- package/dist/index.js +160 -27
- package/dist/index.js.map +1 -1
- package/dist/types-CwabLiFK.d.ts +266 -0
- package/package.json +18 -27
- package/src/components/InfiniteQuery.tsx +18 -50
- package/src/components/InfiniteQueryOptions.tsx +64 -82
- package/src/components/Mutation.tsx +35 -44
- package/src/components/Query.tsx +18 -51
- package/src/components/QueryKey.tsx +9 -61
- package/src/components/QueryOptions.tsx +22 -99
- package/src/generators/infiniteQueryGenerator.tsx +55 -67
- package/src/generators/mutationGenerator.tsx +53 -65
- package/src/generators/queryGenerator.tsx +52 -65
- package/src/plugin.ts +48 -32
- package/src/resolvers/resolverVueQuery.ts +63 -6
- package/src/types.ts +132 -60
- package/src/utils.ts +45 -25
- package/dist/components-D1UhYFgY.js.map +0 -1
- package/dist/components-qfOFRSoM.cjs.map +0 -1
- package/dist/generators-C4gs_P1i.cjs.map +0 -1
- package/dist/generators-CbnIVBgY.js +0 -709
- package/dist/generators-CbnIVBgY.js.map +0 -1
- package/dist/types-nVDTfuS1.d.ts +0 -194
- package/extension.yaml +0 -793
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ast } from '@kubb/core'
|
|
1
|
+
import type { ast } from '@kubb/core'
|
|
3
2
|
import type { ResolverTs } from '@kubb/plugin-ts'
|
|
4
3
|
import { functionPrinter } from '@kubb/plugin-ts'
|
|
5
4
|
import { File, Function, Type } from '@kubb/renderer-jsx'
|
|
6
5
|
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
6
|
+
import { getEnabledParamNames, markParamsOptional, queryKeyTransformer } from '@internals/tanstack-query'
|
|
7
7
|
import type { Transformer } from '../types.ts'
|
|
8
|
-
import { buildQueryKeyParams } from '../utils.ts'
|
|
8
|
+
import { buildQueryKeyParams, wrapWithMaybeRefOrGetter } from '../utils.ts'
|
|
9
9
|
|
|
10
10
|
type Props = {
|
|
11
11
|
name: string
|
|
@@ -14,71 +14,23 @@ type Props = {
|
|
|
14
14
|
tsResolver: ResolverTs
|
|
15
15
|
paramsCasing: 'camelcase' | undefined
|
|
16
16
|
pathParamsType: 'object' | 'inline'
|
|
17
|
-
transformer: Transformer | undefined
|
|
17
|
+
transformer: Transformer | null | undefined
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const declarationPrinter = functionPrinter({ mode: 'declaration' })
|
|
21
|
-
const callPrinter = functionPrinter({ mode: 'call' })
|
|
22
21
|
|
|
23
|
-
function
|
|
24
|
-
const wrappedParams = paramsNode.params.map((param) => {
|
|
25
|
-
if ('kind' in param && (param as ast.ParameterGroupNode).kind === 'ParameterGroup') {
|
|
26
|
-
const group = param as ast.ParameterGroupNode
|
|
27
|
-
return {
|
|
28
|
-
...group,
|
|
29
|
-
properties: group.properties.map((p) => ({
|
|
30
|
-
...p,
|
|
31
|
-
type: p.type ? ast.createParamsType({ variant: 'reference', name: `MaybeRefOrGetter<${printType(p.type)}>` }) : p.type,
|
|
32
|
-
})),
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
const fp = param as ast.FunctionParameterNode
|
|
36
|
-
return {
|
|
37
|
-
...fp,
|
|
38
|
-
type: fp.type ? ast.createParamsType({ variant: 'reference', name: `MaybeRefOrGetter<${printType(fp.type)}>` }) : fp.type,
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
return ast.createFunctionParameters({ params: wrappedParams })
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function printType(typeNode: ast.ParamsTypeNode | undefined): string {
|
|
45
|
-
if (!typeNode) return 'unknown'
|
|
46
|
-
if (typeNode.variant === 'reference') return typeNode.name
|
|
47
|
-
if (typeNode.variant === 'member') return `${typeNode.base}['${typeNode.key}']`
|
|
48
|
-
if (typeNode.variant === 'struct') {
|
|
49
|
-
const parts = typeNode.properties.map((p) => {
|
|
50
|
-
const typeStr = printType(p.type)
|
|
51
|
-
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name)
|
|
52
|
-
return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`
|
|
53
|
-
})
|
|
54
|
-
return `{ ${parts.join('; ')} }`
|
|
55
|
-
}
|
|
56
|
-
return 'unknown'
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function getParams(
|
|
22
|
+
export function buildQueryKeyParamsNode(
|
|
60
23
|
node: ast.OperationNode,
|
|
61
24
|
options: { pathParamsType: 'object' | 'inline'; paramsCasing: 'camelcase' | undefined; resolver: ResolverTs },
|
|
62
25
|
): ast.FunctionParametersNode {
|
|
63
26
|
return wrapWithMaybeRefOrGetter(buildQueryKeyParams(node, options))
|
|
64
27
|
}
|
|
65
28
|
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const hasRequestBody = !!node.requestBody?.content?.[0]?.schema
|
|
70
|
-
|
|
71
|
-
return [
|
|
72
|
-
path.toObject({ type: 'path', stringify: true }),
|
|
73
|
-
hasQueryParams ? '...(params ? [params] : [])' : undefined,
|
|
74
|
-
hasRequestBody ? '...(data ? [data] : [])' : undefined,
|
|
75
|
-
].filter(Boolean) as string[]
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer = getTransformer }: Props): KubbReactNode {
|
|
79
|
-
const paramsNode = getParams(node, { pathParamsType, paramsCasing, resolver: tsResolver })
|
|
29
|
+
export function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer }: Props): KubbReactNode {
|
|
30
|
+
const baseParamsNode = buildQueryKeyParamsNode(node, { pathParamsType, paramsCasing, resolver: tsResolver })
|
|
31
|
+
const paramsNode = markParamsOptional(baseParamsNode, getEnabledParamNames(baseParamsNode))
|
|
80
32
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? ''
|
|
81
|
-
const keys = transformer({
|
|
33
|
+
const keys = (transformer ?? queryKeyTransformer)({
|
|
82
34
|
node,
|
|
83
35
|
casing: paramsCasing,
|
|
84
36
|
})
|
|
@@ -98,7 +50,3 @@ export function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType,
|
|
|
98
50
|
</>
|
|
99
51
|
)
|
|
100
52
|
}
|
|
101
|
-
|
|
102
|
-
QueryKey.getParams = getParams
|
|
103
|
-
QueryKey.getTransformer = getTransformer
|
|
104
|
-
QueryKey.callPrinter = callPrinter
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { ast } from '@kubb/core'
|
|
1
|
+
import type { ast } from '@kubb/core'
|
|
2
2
|
import type { ResolverTs } from '@kubb/plugin-ts'
|
|
3
3
|
import { functionPrinter } from '@kubb/plugin-ts'
|
|
4
4
|
import { File, Function } from '@kubb/renderer-jsx'
|
|
5
5
|
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
6
|
+
import { buildQueryOptionsParams, getEnabledParamNames, markParamsOptional } from '@internals/tanstack-query'
|
|
6
7
|
import type { PluginVueQuery } from '../types.ts'
|
|
7
|
-
import { resolveErrorNames } from '../utils.ts'
|
|
8
|
-
import {
|
|
8
|
+
import { buildStatusUnionType, resolveErrorNames, resolveSuccessNames, wrapWithMaybeRefOrGetter } from '../utils.ts'
|
|
9
|
+
import { buildQueryKeyParamsNode } from './QueryKey.tsx'
|
|
9
10
|
|
|
10
11
|
type Props = {
|
|
11
12
|
name: string
|
|
@@ -31,85 +32,7 @@ export function getQueryOptionsParams(
|
|
|
31
32
|
resolver: ResolverTs
|
|
32
33
|
},
|
|
33
34
|
): ast.FunctionParametersNode {
|
|
34
|
-
|
|
35
|
-
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : undefined
|
|
36
|
-
|
|
37
|
-
const baseParams = ast.createOperationParams(node, {
|
|
38
|
-
paramsType,
|
|
39
|
-
pathParamsType: paramsType === 'object' ? 'object' : pathParamsType === 'object' ? 'object' : 'inline',
|
|
40
|
-
paramsCasing,
|
|
41
|
-
resolver,
|
|
42
|
-
extraParams: [
|
|
43
|
-
ast.createFunctionParameter({
|
|
44
|
-
name: 'config',
|
|
45
|
-
type: ast.createParamsType({
|
|
46
|
-
variant: 'reference',
|
|
47
|
-
name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : 'Partial<RequestConfig> & { client?: Client }',
|
|
48
|
-
}),
|
|
49
|
-
default: '{}',
|
|
50
|
-
}),
|
|
51
|
-
],
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
return wrapOperationParamsWithMaybeRef(baseParams)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function wrapOperationParamsWithMaybeRef(paramsNode: ast.FunctionParametersNode): ast.FunctionParametersNode {
|
|
58
|
-
const wrappedParams = paramsNode.params.map((param) => {
|
|
59
|
-
if ('kind' in param && (param as ast.ParameterGroupNode).kind === 'ParameterGroup') {
|
|
60
|
-
const group = param as ast.ParameterGroupNode
|
|
61
|
-
return {
|
|
62
|
-
...group,
|
|
63
|
-
properties: group.properties.map((p) => ({
|
|
64
|
-
...p,
|
|
65
|
-
type: p.type ? ast.createParamsType({ variant: 'reference', name: `MaybeRefOrGetter<${printType(p.type)}>` }) : p.type,
|
|
66
|
-
})),
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
const fp = param as ast.FunctionParameterNode
|
|
70
|
-
// Don't wrap 'config' param — it's not reactive
|
|
71
|
-
if (fp.name === 'config') return fp
|
|
72
|
-
return {
|
|
73
|
-
...fp,
|
|
74
|
-
type: fp.type ? ast.createParamsType({ variant: 'reference', name: `MaybeRefOrGetter<${printType(fp.type)}>` }) : fp.type,
|
|
75
|
-
}
|
|
76
|
-
})
|
|
77
|
-
return ast.createFunctionParameters({ params: wrappedParams })
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function printType(typeNode: ast.ParamsTypeNode | undefined): string {
|
|
81
|
-
if (!typeNode) return 'unknown'
|
|
82
|
-
if (typeNode.variant === 'reference') return typeNode.name
|
|
83
|
-
if (typeNode.variant === 'member') return `${typeNode.base}['${typeNode.key}']`
|
|
84
|
-
if (typeNode.variant === 'struct') {
|
|
85
|
-
const parts = typeNode.properties.map((p) => {
|
|
86
|
-
const typeStr = printType(p.type)
|
|
87
|
-
const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name)
|
|
88
|
-
return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`
|
|
89
|
-
})
|
|
90
|
-
return `{ ${parts.join('; ')} }`
|
|
91
|
-
}
|
|
92
|
-
return 'unknown'
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function buildEnabledCheck(paramsNode: ast.FunctionParametersNode): string {
|
|
96
|
-
const required: string[] = []
|
|
97
|
-
for (const param of paramsNode.params) {
|
|
98
|
-
if ('kind' in param && (param as ast.ParameterGroupNode).kind === 'ParameterGroup') {
|
|
99
|
-
const group = param as ast.ParameterGroupNode
|
|
100
|
-
for (const child of group.properties) {
|
|
101
|
-
if (!child.optional && child.default === undefined) {
|
|
102
|
-
required.push(child.name)
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
} else {
|
|
106
|
-
const fp = param as ast.FunctionParameterNode
|
|
107
|
-
if (!fp.optional && fp.default === undefined) {
|
|
108
|
-
required.push(fp.name)
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return required.join(' && ')
|
|
35
|
+
return wrapWithMaybeRefOrGetter(buildQueryOptionsParams(node, options), (name) => name === 'config')
|
|
113
36
|
}
|
|
114
37
|
|
|
115
38
|
export function QueryOptions({
|
|
@@ -123,35 +46,35 @@ export function QueryOptions({
|
|
|
123
46
|
pathParamsType,
|
|
124
47
|
queryKeyName,
|
|
125
48
|
}: Props): KubbReactNode {
|
|
126
|
-
const
|
|
49
|
+
const successNames = resolveSuccessNames(node, tsResolver)
|
|
50
|
+
const responseName = successNames.length > 0 ? successNames.join(' | ') : tsResolver.resolveResponseName(node)
|
|
127
51
|
const errorNames = resolveErrorNames(node, tsResolver)
|
|
128
52
|
|
|
129
|
-
const TData = dataReturnType === 'data' ? responseName :
|
|
53
|
+
const TData = dataReturnType === 'data' ? responseName : buildStatusUnionType(node, tsResolver)
|
|
130
54
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(' | ') : 'Error'}>`
|
|
131
55
|
|
|
132
|
-
const
|
|
56
|
+
const queryKeyParamsNode = buildQueryKeyParamsNode(node, { pathParamsType, paramsCasing, resolver: tsResolver })
|
|
57
|
+
const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? ''
|
|
58
|
+
|
|
59
|
+
const enabledNames = getEnabledParamNames(queryKeyParamsNode)
|
|
60
|
+
const enabledText = enabledNames.length ? `enabled: () => ${enabledNames.map((n) => `!!toValue(${n})`).join(' && ')},` : ''
|
|
61
|
+
|
|
62
|
+
const paramsNode = markParamsOptional(getQueryOptionsParams(node, { paramsType, paramsCasing, pathParamsType, resolver: tsResolver }), enabledNames)
|
|
133
63
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? ''
|
|
134
64
|
const rawParamsCall = callPrinter.print(paramsNode) ?? ''
|
|
135
65
|
|
|
136
66
|
// Transform: wrap non-config params with toValue(), add signal to config
|
|
137
67
|
const clientCallStr = rawParamsCall.replace(/\bconfig\b(?=[^,]*$)/, '{ ...config, signal: config.signal ?? signal }')
|
|
138
68
|
|
|
139
|
-
const queryKeyParamsNode = QueryKey.getParams(node, { pathParamsType, paramsCasing, resolver: tsResolver })
|
|
140
|
-
const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? ''
|
|
141
|
-
|
|
142
|
-
const enabledSource = buildEnabledCheck(queryKeyParamsNode)
|
|
143
|
-
const enabledText = enabledSource ? `enabled: () => !!(${enabledSource}),` : ''
|
|
144
|
-
|
|
145
69
|
return (
|
|
146
70
|
<File.Source name={name} isExportable isIndexable>
|
|
147
71
|
<Function name={name} export params={paramsSignature}>
|
|
148
72
|
{`
|
|
149
73
|
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
150
|
-
return queryOptions<${TData}, ${TError}, ${TData}>({
|
|
151
|
-
${enabledText}
|
|
74
|
+
return queryOptions<${TData}, ${TError}, ${TData}>({${enabledText ? `\n ${enabledText}` : ''}
|
|
152
75
|
queryKey,
|
|
153
76
|
queryFn: async ({ signal }) => {
|
|
154
|
-
return ${clientName}(${addToValueCalls(clientCallStr)})
|
|
77
|
+
return ${clientName}(${addToValueCalls(clientCallStr, enabledNames)})
|
|
155
78
|
},
|
|
156
79
|
})
|
|
157
80
|
`}
|
|
@@ -167,8 +90,10 @@ export function QueryOptions({
|
|
|
167
90
|
* Handles both inline params (`petId, config`) and object shorthand
|
|
168
91
|
* params (`{ petId }, config`) by expanding to `{ petId: toValue(petId) }`.
|
|
169
92
|
*/
|
|
170
|
-
function addToValueCalls(callStr: string): string {
|
|
93
|
+
function addToValueCalls(callStr: string, enabledNames: ReadonlyArray<string> = []): string {
|
|
94
|
+
const optional = new Set(enabledNames)
|
|
171
95
|
// Step 1: Transform shorthand object params like { petId } → { petId: toValue(petId) }
|
|
96
|
+
// Params that drive the `enabled` guard are optional, so assert non-null: toValue(petId!)
|
|
172
97
|
let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner: string) => {
|
|
173
98
|
// Only transform simple shorthand (no colons, no spread)
|
|
174
99
|
if (inner.includes(':') || inner.includes('...')) return match
|
|
@@ -176,7 +101,7 @@ function addToValueCalls(callStr: string): string {
|
|
|
176
101
|
.split(',')
|
|
177
102
|
.map((k: string) => k.trim())
|
|
178
103
|
.filter(Boolean)
|
|
179
|
-
const wrapped = keys.map((k: string) => `${k}: toValue(${k})`).join(', ')
|
|
104
|
+
const wrapped = keys.map((k: string) => `${k}: toValue(${optional.has(k) ? `${k}!` : k})`).join(', ')
|
|
180
105
|
return `{ ${wrapped} }`
|
|
181
106
|
})
|
|
182
107
|
|
|
@@ -184,10 +109,8 @@ function addToValueCalls(callStr: string): string {
|
|
|
184
109
|
result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name: string) => {
|
|
185
110
|
if (name === 'config' || name === 'signal' || name === 'undefined') return match
|
|
186
111
|
if (match.includes('toValue(')) return match
|
|
187
|
-
return `toValue(${name})`
|
|
112
|
+
return `toValue(${optional.has(name) ? `${name}!` : name})`
|
|
188
113
|
})
|
|
189
114
|
|
|
190
115
|
return result
|
|
191
116
|
}
|
|
192
|
-
|
|
193
|
-
QueryOptions.getParams = getQueryOptionsParams
|
|
@@ -1,37 +1,45 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
+
import { getOperationParameters, operationFileEntry, resolveOperationTypeNames } from '@internals/shared'
|
|
3
|
+
import { resolveZodSchemaNames } from '@internals/tanstack-query'
|
|
2
4
|
import { ast, defineGenerator } from '@kubb/core'
|
|
3
|
-
import { Client, pluginClientName } from '@kubb/plugin-client'
|
|
5
|
+
import { Client, isParserEnabled, pluginClientName } from '@kubb/plugin-client'
|
|
4
6
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
5
7
|
import { pluginZodName } from '@kubb/plugin-zod'
|
|
6
8
|
import { File, jsxRenderer } from '@kubb/renderer-jsx'
|
|
7
|
-
import { difference } from 'remeda'
|
|
8
9
|
import { InfiniteQuery, InfiniteQueryOptions, QueryKey } from '../components'
|
|
9
10
|
import type { PluginVueQuery } from '../types'
|
|
10
|
-
import { transformName } from '../utils.ts'
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Built-in generator for `useInfiniteQuery` composables. Enabled when
|
|
14
|
+
* `pluginVueQuery({ infinite: { ... } })`. Emits one `useFooInfiniteQuery`
|
|
15
|
+
* composable per query operation, wiring the configured cursor path into
|
|
16
|
+
* TanStack Query's cursor-based pagination.
|
|
17
|
+
*/
|
|
12
18
|
export const infiniteQueryGenerator = defineGenerator<PluginVueQuery>({
|
|
13
19
|
name: 'vue-query-infinite',
|
|
14
20
|
renderer: jsxRenderer,
|
|
15
21
|
operation(node, ctx) {
|
|
16
|
-
|
|
17
|
-
const {
|
|
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 } = ctx.options
|
|
18
25
|
|
|
19
26
|
const pluginTs = driver.getPlugin(pluginTsName)
|
|
20
27
|
if (!pluginTs) return null
|
|
21
28
|
const tsResolver = driver.getResolver(pluginTsName)
|
|
22
29
|
|
|
23
30
|
const isQuery = query === false || (!!query && query.methods.some((method) => node.method.toLowerCase() === method.toLowerCase()))
|
|
31
|
+
const queryMethods = new Set(query ? query.methods : [])
|
|
24
32
|
const isMutation =
|
|
25
33
|
mutation !== false &&
|
|
26
34
|
!isQuery &&
|
|
27
|
-
|
|
28
|
-
const infiniteOptions = infinite && typeof infinite === 'object' ? infinite :
|
|
35
|
+
(mutation ? mutation.methods : []).some((method) => !queryMethods.has(method) && node.method.toLowerCase() === method.toLowerCase())
|
|
36
|
+
const infiniteOptions = infinite && typeof infinite === 'object' ? infinite : null
|
|
29
37
|
|
|
30
38
|
if (!isQuery || isMutation || !infiniteOptions) return null
|
|
31
39
|
|
|
32
40
|
// Validate queryParam exists in operation's query parameters
|
|
33
41
|
const normalizeKey = (key: string) => key.replace(/\?$/, '')
|
|
34
|
-
const queryParamKeys = node
|
|
42
|
+
const queryParamKeys = getOperationParameters(node).query.map((p) => p.name)
|
|
35
43
|
const hasQueryParam = infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false
|
|
36
44
|
// cursorParam validation against response schema keys is skipped in v5 (complex schema inspection)
|
|
37
45
|
const hasCursorParam = !infiniteOptions.cursorParam || true
|
|
@@ -40,64 +48,50 @@ export const infiniteQueryGenerator = defineGenerator<PluginVueQuery>({
|
|
|
40
48
|
|
|
41
49
|
const importPath = query ? query.importPath : '@tanstack/vue-query'
|
|
42
50
|
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const queryKeyTypeName = transformName(`${capitalize(baseName)}InfiniteQueryKey`, 'type', transformers)
|
|
49
|
-
const clientBaseName = transformName(`${baseName}Infinite`, 'function', transformers)
|
|
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)
|
|
50
56
|
|
|
51
57
|
const meta = {
|
|
52
|
-
file: resolver.resolveFile(
|
|
53
|
-
fileTs: tsResolver.resolveFile(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
+
}),
|
|
57
64
|
}
|
|
58
65
|
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
...pathParams.map((p) => tsResolver.resolvePathParamsName(node, p)),
|
|
68
|
-
...queryParams.map((p) => tsResolver.resolveQueryParamsName(node, p)),
|
|
69
|
-
...headerParams.map((p) => tsResolver.resolveHeaderParamsName(node, p)),
|
|
70
|
-
...node.responses.map((res) => tsResolver.resolveResponseStatusName(node, res.statusCode)),
|
|
71
|
-
].filter((name): name is string => !!name && name !== queryKeyTypeName)
|
|
72
|
-
|
|
73
|
-
const pluginZod = parser === 'zod' ? driver.getPlugin(pluginZodName) : undefined
|
|
74
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : undefined
|
|
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
|
|
75
74
|
const fileZod = zodResolver
|
|
76
|
-
? zodResolver.resolveFile(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
? [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : undefined].filter(Boolean)
|
|
84
|
-
: []
|
|
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)
|
|
85
82
|
|
|
86
83
|
const clientPlugin = driver.getPlugin(pluginClientName)
|
|
87
84
|
const hasClientPlugin = clientPlugin?.name === pluginClientName
|
|
88
85
|
const shouldUseClientPlugin = hasClientPlugin && clientOptions.clientType !== 'class'
|
|
89
|
-
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) :
|
|
86
|
+
const clientResolver = shouldUseClientPlugin ? driver.getResolver(pluginClientName) : null
|
|
90
87
|
|
|
91
88
|
const clientFile = shouldUseClientPlugin
|
|
92
|
-
? clientResolver?.resolveFile(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
},
|
|
99
|
-
)
|
|
100
|
-
: undefined
|
|
89
|
+
? clientResolver?.resolveFile(operationFileEntry(node, node.operationId), {
|
|
90
|
+
root,
|
|
91
|
+
output: clientPlugin?.options?.output ?? output,
|
|
92
|
+
group: clientPlugin?.options?.group ?? undefined,
|
|
93
|
+
})
|
|
94
|
+
: null
|
|
101
95
|
|
|
102
96
|
const resolvedClientName = shouldUseClientPlugin ? (clientResolver?.resolveName(node.operationId) ?? clientBaseName) : clientBaseName
|
|
103
97
|
|
|
@@ -106,30 +100,24 @@ export const infiniteQueryGenerator = defineGenerator<PluginVueQuery>({
|
|
|
106
100
|
baseName={meta.file.baseName}
|
|
107
101
|
path={meta.file.path}
|
|
108
102
|
meta={meta.file.meta}
|
|
109
|
-
banner={resolver.resolveBanner(
|
|
110
|
-
footer={resolver.resolveFooter(
|
|
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 } })}
|
|
111
105
|
>
|
|
112
|
-
{
|
|
113
|
-
<File.Import name={zodSchemaNames as string[]} root={meta.file.path} path={fileZod.path} />
|
|
114
|
-
)}
|
|
106
|
+
{fileZod && zodSchemaNames.length > 0 && <File.Import name={zodSchemaNames} root={meta.file.path} path={fileZod.path} />}
|
|
115
107
|
{clientOptions.importPath ? (
|
|
116
108
|
<>
|
|
117
|
-
{!shouldUseClientPlugin && <File.Import name={'
|
|
109
|
+
{!shouldUseClientPlugin && <File.Import name={'client'} path={clientOptions.importPath} />}
|
|
118
110
|
<File.Import name={['Client', 'RequestConfig', 'ResponseErrorConfig']} path={clientOptions.importPath} isTypeOnly />
|
|
119
|
-
{clientOptions.dataReturnType === 'full' && <File.Import name={['ResponseConfig']} path={clientOptions.importPath} isTypeOnly />}
|
|
120
111
|
</>
|
|
121
112
|
) : (
|
|
122
113
|
<>
|
|
123
|
-
{!shouldUseClientPlugin && <File.Import name={['
|
|
114
|
+
{!shouldUseClientPlugin && <File.Import name={['client']} root={meta.file.path} path={path.resolve(root, '.kubb/client.ts')} />}
|
|
124
115
|
<File.Import
|
|
125
116
|
name={['Client', 'RequestConfig', 'ResponseErrorConfig']}
|
|
126
117
|
root={meta.file.path}
|
|
127
|
-
path={path.resolve(root, '.kubb/
|
|
118
|
+
path={path.resolve(root, '.kubb/client.ts')}
|
|
128
119
|
isTypeOnly
|
|
129
120
|
/>
|
|
130
|
-
{clientOptions.dataReturnType === 'full' && (
|
|
131
|
-
<File.Import name={['ResponseConfig']} root={meta.file.path} path={path.resolve(root, '.kubb/fetch.ts')} isTypeOnly />
|
|
132
|
-
)}
|
|
133
121
|
</>
|
|
134
122
|
)}
|
|
135
123
|
<File.Import name={['toValue']} path="vue" />
|