@kubb/plugin-react-query 5.0.0-alpha.8 → 5.0.0-beta.3
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/LICENSE +17 -10
- package/README.md +1 -3
- package/dist/components-DTGLu4UV.js +1451 -0
- package/dist/components-DTGLu4UV.js.map +1 -0
- package/dist/components-dAKJEn9b.cjs +1571 -0
- package/dist/components-dAKJEn9b.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +105 -161
- package/dist/components.js +1 -1
- package/dist/generators-CWEQsdO9.cjs +1502 -0
- package/dist/generators-CWEQsdO9.cjs.map +1 -0
- package/dist/generators-C_fbcjpG.js +1460 -0
- package/dist/generators-C_fbcjpG.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +9 -476
- package/dist/generators.js +1 -1
- package/dist/index.cjs +114 -126
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +110 -126
- package/dist/index.js.map +1 -1
- package/dist/{types-D5S7Ny9r.d.ts → types-DfaFRSBf.d.ts} +100 -86
- package/package.json +59 -62
- package/src/components/InfiniteQuery.tsx +75 -139
- package/src/components/InfiniteQueryOptions.tsx +62 -164
- package/src/components/Mutation.tsx +58 -113
- package/src/components/MutationOptions.tsx +61 -80
- package/src/components/Query.tsx +67 -140
- package/src/components/QueryOptions.tsx +75 -135
- package/src/components/SuspenseInfiniteQuery.tsx +75 -139
- package/src/components/SuspenseInfiniteQueryOptions.tsx +62 -164
- package/src/components/SuspenseQuery.tsx +67 -150
- package/src/generators/customHookOptionsFileGenerator.tsx +33 -45
- package/src/generators/hookOptionsGenerator.tsx +115 -175
- package/src/generators/infiniteQueryGenerator.tsx +183 -176
- package/src/generators/mutationGenerator.tsx +127 -138
- package/src/generators/queryGenerator.tsx +141 -141
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +175 -155
- package/src/generators/suspenseQueryGenerator.tsx +149 -148
- package/src/index.ts +1 -1
- package/src/plugin.ts +133 -183
- package/src/resolvers/resolverReactQuery.ts +22 -0
- package/src/types.ts +67 -45
- package/src/utils.ts +40 -0
- package/dist/components-BHQT9ZLc.cjs +0 -1634
- package/dist/components-BHQT9ZLc.cjs.map +0 -1
- package/dist/components-CpyHYGOw.js +0 -1520
- package/dist/components-CpyHYGOw.js.map +0 -1
- package/dist/generators-DP07m3rH.cjs +0 -1469
- package/dist/generators-DP07m3rH.cjs.map +0 -1
- package/dist/generators-DkQwKTc2.js +0 -1427
- package/dist/generators-DkQwKTc2.js.map +0 -1
|
@@ -1,175 +1,115 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import type { FabricReactNode } from '@kubb/react-fabric/types'
|
|
1
|
+
import { ast } from '@kubb/core'
|
|
2
|
+
import type { ResolverTs } from '@kubb/plugin-ts'
|
|
3
|
+
import { functionPrinter } from '@kubb/plugin-ts'
|
|
4
|
+
import { File, Function } from '@kubb/renderer-jsx'
|
|
5
|
+
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
7
6
|
import type { PluginReactQuery } from '../types.ts'
|
|
7
|
+
import { resolveErrorNames } from '../utils.ts'
|
|
8
8
|
import { QueryKey } from './QueryKey.tsx'
|
|
9
9
|
|
|
10
10
|
type Props = {
|
|
11
11
|
name: string
|
|
12
12
|
clientName: string
|
|
13
13
|
queryKeyName: string
|
|
14
|
-
|
|
14
|
+
node: ast.OperationNode
|
|
15
|
+
tsResolver: ResolverTs
|
|
15
16
|
paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
|
|
16
17
|
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
17
18
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
18
19
|
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
24
|
-
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
25
|
-
typeSchemas: OperationSchemas
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {
|
|
29
|
-
if (paramsType === 'object') {
|
|
30
|
-
const pathParams = getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing })
|
|
31
|
-
|
|
32
|
-
const children = {
|
|
33
|
-
...pathParams,
|
|
34
|
-
data: typeSchemas.request?.name
|
|
35
|
-
? {
|
|
36
|
-
type: typeSchemas.request?.name,
|
|
37
|
-
optional: isOptional(typeSchemas.request?.schema),
|
|
38
|
-
}
|
|
39
|
-
: undefined,
|
|
40
|
-
params: typeSchemas.queryParams?.name
|
|
41
|
-
? {
|
|
42
|
-
type: typeSchemas.queryParams?.name,
|
|
43
|
-
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
44
|
-
}
|
|
45
|
-
: undefined,
|
|
46
|
-
headers: typeSchemas.headerParams?.name
|
|
47
|
-
? {
|
|
48
|
-
type: typeSchemas.headerParams?.name,
|
|
49
|
-
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
50
|
-
}
|
|
51
|
-
: undefined,
|
|
52
|
-
}
|
|
22
|
+
const declarationPrinter = functionPrinter({ mode: 'declaration' })
|
|
23
|
+
const callPrinter = functionPrinter({ mode: 'call' })
|
|
53
24
|
|
|
54
|
-
|
|
55
|
-
|
|
25
|
+
export function getQueryOptionsParams(
|
|
26
|
+
node: ast.OperationNode,
|
|
27
|
+
options: {
|
|
28
|
+
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
29
|
+
paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
|
|
30
|
+
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
31
|
+
resolver: ResolverTs
|
|
32
|
+
},
|
|
33
|
+
): ast.FunctionParametersNode {
|
|
34
|
+
const { paramsType, paramsCasing, pathParamsType, resolver } = options
|
|
35
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : undefined
|
|
56
36
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
: '
|
|
37
|
+
return 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
|
+
}),
|
|
67
49
|
default: '{}',
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
}
|
|
50
|
+
}),
|
|
51
|
+
],
|
|
52
|
+
})
|
|
53
|
+
}
|
|
71
54
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
default: isAllOptional(typeSchemas.pathParams?.schema) ? '{}' : undefined,
|
|
81
|
-
}
|
|
82
|
-
: undefined,
|
|
83
|
-
data: typeSchemas.request?.name
|
|
84
|
-
? {
|
|
85
|
-
type: typeSchemas.request?.name,
|
|
86
|
-
optional: isOptional(typeSchemas.request?.schema),
|
|
87
|
-
}
|
|
88
|
-
: undefined,
|
|
89
|
-
params: typeSchemas.queryParams?.name
|
|
90
|
-
? {
|
|
91
|
-
type: typeSchemas.queryParams?.name,
|
|
92
|
-
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
55
|
+
export function buildEnabledCheck(paramsNode: ast.FunctionParametersNode): string {
|
|
56
|
+
const required: string[] = []
|
|
57
|
+
for (const param of paramsNode.params) {
|
|
58
|
+
if ('kind' in param && (param as ast.ParameterGroupNode).kind === 'ParameterGroup') {
|
|
59
|
+
const group = param as ast.ParameterGroupNode
|
|
60
|
+
for (const child of group.properties) {
|
|
61
|
+
if (!child.optional && child.default === undefined) {
|
|
62
|
+
required.push(child.name)
|
|
93
63
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }`
|
|
104
|
-
: 'Partial<RequestConfig> & { client?: Client }',
|
|
105
|
-
default: '{}',
|
|
106
|
-
},
|
|
107
|
-
})
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
const fp = param as ast.FunctionParameterNode
|
|
67
|
+
if (!fp.optional && fp.default === undefined) {
|
|
68
|
+
required.push(fp.name)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return required.join(' && ')
|
|
108
73
|
}
|
|
109
74
|
|
|
110
75
|
export function QueryOptions({
|
|
111
76
|
name,
|
|
112
77
|
clientName,
|
|
113
78
|
dataReturnType,
|
|
114
|
-
|
|
79
|
+
node,
|
|
80
|
+
tsResolver,
|
|
115
81
|
paramsCasing,
|
|
116
82
|
paramsType,
|
|
117
83
|
pathParamsType,
|
|
118
84
|
queryKeyName,
|
|
119
|
-
}: Props):
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
paramsCasing,
|
|
123
|
-
pathParamsType,
|
|
124
|
-
typeSchemas,
|
|
125
|
-
})
|
|
126
|
-
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
127
|
-
const TError = typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'
|
|
85
|
+
}: Props): KubbReactNode {
|
|
86
|
+
const responseName = tsResolver.resolveResponseName(node)
|
|
87
|
+
const errorNames = resolveErrorNames(node, tsResolver)
|
|
128
88
|
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
})
|
|
136
|
-
const queryKeyParams = QueryKey.getParams({
|
|
137
|
-
pathParamsType,
|
|
138
|
-
typeSchemas,
|
|
139
|
-
paramsCasing,
|
|
140
|
-
})
|
|
89
|
+
const TData = dataReturnType === 'data' ? responseName : `ResponseConfig<${responseName}>`
|
|
90
|
+
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(' | ') : 'Error'}>`
|
|
91
|
+
|
|
92
|
+
const paramsNode = getQueryOptionsParams(node, { paramsType, paramsCasing, pathParamsType, resolver: tsResolver })
|
|
93
|
+
const paramsSignature = declarationPrinter.print(paramsNode) ?? ''
|
|
94
|
+
const rawParamsCall = callPrinter.print(paramsNode) ?? ''
|
|
95
|
+
const clientCallStr = rawParamsCall.replace(/\bconfig\b(?=[^,]*$)/, '{ ...config, signal: config.signal ?? signal }')
|
|
141
96
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const enabled = Object.entries(queryKeyParams.flatParams)
|
|
145
|
-
.map(([key, item]) => {
|
|
146
|
-
// Only include if the parameter exists and is NOT optional
|
|
147
|
-
// This ensures we only check required parameters
|
|
148
|
-
return item && !item.optional && !item.default ? key : undefined
|
|
149
|
-
})
|
|
150
|
-
.filter(Boolean)
|
|
151
|
-
.join('&& ')
|
|
97
|
+
const queryKeyParamsNode = QueryKey.getParams(node, { pathParamsType, paramsCasing, resolver: tsResolver })
|
|
98
|
+
const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? ''
|
|
152
99
|
|
|
153
|
-
const
|
|
100
|
+
const enabledSource = buildEnabledCheck(queryKeyParamsNode)
|
|
101
|
+
const enabledText = enabledSource ? `enabled: !!(${enabledSource}),` : ''
|
|
154
102
|
|
|
155
103
|
return (
|
|
156
104
|
<File.Source name={name} isExportable isIndexable>
|
|
157
|
-
<Function name={name} export params={
|
|
105
|
+
<Function name={name} export params={paramsSignature}>
|
|
158
106
|
{`
|
|
159
|
-
const queryKey = ${queryKeyName}(${
|
|
160
|
-
return queryOptions<${TData},
|
|
107
|
+
const queryKey = ${queryKeyName}(${queryKeyParamsCall})
|
|
108
|
+
return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
|
|
161
109
|
${enabledText}
|
|
162
110
|
queryKey,
|
|
163
111
|
queryFn: async ({ signal }) => {
|
|
164
|
-
return ${clientName}(${
|
|
165
|
-
transformName(name) {
|
|
166
|
-
if (name === 'config') {
|
|
167
|
-
return '{ ...config, signal: config.signal ?? signal }'
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return name
|
|
171
|
-
},
|
|
172
|
-
})})
|
|
112
|
+
return ${clientName}(${clientCallStr})
|
|
173
113
|
},
|
|
174
114
|
})
|
|
175
115
|
`}
|
|
@@ -178,4 +118,4 @@ export function QueryOptions({
|
|
|
178
118
|
)
|
|
179
119
|
}
|
|
180
120
|
|
|
181
|
-
QueryOptions.getParams =
|
|
121
|
+
QueryOptions.getParams = getQueryOptionsParams
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
4
|
-
import { File, Function
|
|
5
|
-
import type {
|
|
1
|
+
import { ast } from '@kubb/core'
|
|
2
|
+
import type { ResolverTs } from '@kubb/plugin-ts'
|
|
3
|
+
import { functionPrinter } from '@kubb/plugin-ts'
|
|
4
|
+
import { File, Function } from '@kubb/renderer-jsx'
|
|
5
|
+
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
6
6
|
import type { Infinite, PluginReactQuery } from '../types.ts'
|
|
7
|
+
import { getComments, resolveErrorNames } from '../utils.ts'
|
|
7
8
|
import { QueryKey } from './QueryKey.tsx'
|
|
8
|
-
import {
|
|
9
|
+
import { getQueryOptionsParams } from './QueryOptions.tsx'
|
|
9
10
|
|
|
10
11
|
type Props = {
|
|
11
|
-
/**
|
|
12
|
-
* Name of the function
|
|
13
|
-
*/
|
|
14
12
|
name: string
|
|
15
13
|
queryOptionsName: string
|
|
16
14
|
queryKeyName: string
|
|
17
15
|
queryKeyTypeName: string
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
node: ast.OperationNode
|
|
17
|
+
tsResolver: ResolverTs
|
|
20
18
|
paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
|
|
21
19
|
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
22
20
|
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
@@ -26,99 +24,41 @@ type Props = {
|
|
|
26
24
|
queryParam?: Infinite['queryParam']
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
|
|
32
|
-
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
33
|
-
typeSchemas: OperationSchemas
|
|
34
|
-
pageParamGeneric: string
|
|
35
|
-
}
|
|
27
|
+
const declarationPrinter = functionPrinter({ mode: 'declaration' })
|
|
28
|
+
const callPrinter = functionPrinter({ mode: 'call' })
|
|
36
29
|
|
|
37
|
-
function getParams(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
? {
|
|
57
|
-
type: typeSchemas.headerParams?.name,
|
|
58
|
-
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
59
|
-
}
|
|
60
|
-
: undefined,
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Check if all children are optional or undefined
|
|
64
|
-
const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional)
|
|
65
|
-
|
|
66
|
-
return FunctionParams.factory({
|
|
67
|
-
data: {
|
|
68
|
-
mode: 'object',
|
|
69
|
-
children,
|
|
70
|
-
default: allChildrenAreOptional ? '{}' : undefined,
|
|
71
|
-
},
|
|
72
|
-
options: {
|
|
73
|
-
type: `
|
|
74
|
-
{
|
|
75
|
-
query?: Partial<UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
|
|
76
|
-
client?: ${typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : 'Partial<RequestConfig> & { client?: Client }'}
|
|
77
|
-
}
|
|
78
|
-
`,
|
|
79
|
-
default: '{}',
|
|
80
|
-
},
|
|
81
|
-
})
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return FunctionParams.factory({
|
|
85
|
-
pathParams: typeSchemas.pathParams?.name
|
|
86
|
-
? {
|
|
87
|
-
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
88
|
-
children: getPathParams(typeSchemas.pathParams, {
|
|
89
|
-
typed: true,
|
|
90
|
-
casing: paramsCasing,
|
|
91
|
-
}),
|
|
92
|
-
default: isAllOptional(typeSchemas.pathParams?.schema) ? '{}' : undefined,
|
|
93
|
-
}
|
|
94
|
-
: undefined,
|
|
95
|
-
data: typeSchemas.request?.name
|
|
96
|
-
? {
|
|
97
|
-
type: typeSchemas.request?.name,
|
|
98
|
-
optional: isOptional(typeSchemas.request?.schema),
|
|
99
|
-
}
|
|
100
|
-
: undefined,
|
|
101
|
-
params: typeSchemas.queryParams?.name
|
|
102
|
-
? {
|
|
103
|
-
type: typeSchemas.queryParams?.name,
|
|
104
|
-
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
105
|
-
}
|
|
106
|
-
: undefined,
|
|
107
|
-
headers: typeSchemas.headerParams?.name
|
|
108
|
-
? {
|
|
109
|
-
type: typeSchemas.headerParams?.name,
|
|
110
|
-
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
111
|
-
}
|
|
112
|
-
: undefined,
|
|
113
|
-
options: {
|
|
114
|
-
type: `
|
|
115
|
-
{
|
|
30
|
+
function getParams(
|
|
31
|
+
node: ast.OperationNode,
|
|
32
|
+
options: {
|
|
33
|
+
paramsType: PluginReactQuery['resolvedOptions']['paramsType']
|
|
34
|
+
paramsCasing: PluginReactQuery['resolvedOptions']['paramsCasing']
|
|
35
|
+
pathParamsType: PluginReactQuery['resolvedOptions']['pathParamsType']
|
|
36
|
+
dataReturnType: PluginReactQuery['resolvedOptions']['client']['dataReturnType']
|
|
37
|
+
resolver: ResolverTs
|
|
38
|
+
pageParamGeneric: string
|
|
39
|
+
},
|
|
40
|
+
): ast.FunctionParametersNode {
|
|
41
|
+
const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options
|
|
42
|
+
const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : undefined
|
|
43
|
+
|
|
44
|
+
const optionsParam = ast.createFunctionParameter({
|
|
45
|
+
name: 'options',
|
|
46
|
+
type: ast.createParamsType({
|
|
47
|
+
variant: 'reference',
|
|
48
|
+
name: `{
|
|
116
49
|
query?: Partial<UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
|
|
117
|
-
client?: ${
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
50
|
+
client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : 'Partial<RequestConfig> & { client?: Client }'}
|
|
51
|
+
}`,
|
|
52
|
+
}),
|
|
53
|
+
default: '{}',
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
return ast.createOperationParams(node, {
|
|
57
|
+
paramsType,
|
|
58
|
+
pathParamsType: paramsType === 'object' ? 'object' : pathParamsType === 'object' ? 'object' : 'inline',
|
|
59
|
+
paramsCasing,
|
|
60
|
+
resolver,
|
|
61
|
+
extraParams: [optionsParam],
|
|
122
62
|
})
|
|
123
63
|
}
|
|
124
64
|
|
|
@@ -131,14 +71,18 @@ export function SuspenseInfiniteQuery({
|
|
|
131
71
|
paramsCasing,
|
|
132
72
|
pathParamsType,
|
|
133
73
|
dataReturnType,
|
|
134
|
-
|
|
135
|
-
|
|
74
|
+
node,
|
|
75
|
+
tsResolver,
|
|
136
76
|
customOptions,
|
|
137
77
|
initialPageParam,
|
|
138
78
|
queryParam,
|
|
139
|
-
}: Props):
|
|
140
|
-
const
|
|
141
|
-
const
|
|
79
|
+
}: Props): KubbReactNode {
|
|
80
|
+
const responseName = tsResolver.resolveResponseName(node)
|
|
81
|
+
const errorNames = resolveErrorNames(node, tsResolver)
|
|
82
|
+
|
|
83
|
+
const responseType = dataReturnType === 'data' ? responseName : `ResponseConfig<${responseName}>`
|
|
84
|
+
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(' | ') : 'Error'}>`
|
|
85
|
+
|
|
142
86
|
const isInitialPageParamDefined = initialPageParam !== undefined && initialPageParam !== null
|
|
143
87
|
const fallbackPageParamType =
|
|
144
88
|
typeof initialPageParam === 'number'
|
|
@@ -153,8 +97,20 @@ export function SuspenseInfiniteQuery({
|
|
|
153
97
|
: typeof initialPageParam === 'boolean'
|
|
154
98
|
? 'boolean'
|
|
155
99
|
: 'unknown'
|
|
156
|
-
|
|
100
|
+
|
|
101
|
+
const rawQueryParams = node.parameters.filter((p) => p.in === 'query')
|
|
102
|
+
const queryParamsTypeName =
|
|
103
|
+
rawQueryParams.length > 0
|
|
104
|
+
? (() => {
|
|
105
|
+
const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]!)
|
|
106
|
+
const individualName = tsResolver.resolveParamName(node, rawQueryParams[0]!)
|
|
107
|
+
return groupName !== individualName ? groupName : undefined
|
|
108
|
+
})()
|
|
109
|
+
: undefined
|
|
110
|
+
|
|
111
|
+
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : undefined
|
|
157
112
|
const pageParamType = queryParamType ? (isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType) : fallbackPageParamType
|
|
113
|
+
|
|
158
114
|
const returnType = 'UseSuspenseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }'
|
|
159
115
|
const generics = [
|
|
160
116
|
`TQueryFnData = ${responseType}`,
|
|
@@ -164,46 +120,26 @@ export function SuspenseInfiniteQuery({
|
|
|
164
120
|
`TPageParam = ${pageParamType}`,
|
|
165
121
|
]
|
|
166
122
|
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const queryOptionsParams = QueryOptions.getParams({
|
|
173
|
-
paramsType,
|
|
174
|
-
pathParamsType,
|
|
175
|
-
typeSchemas,
|
|
176
|
-
paramsCasing,
|
|
177
|
-
})
|
|
178
|
-
const params = getParams({
|
|
179
|
-
paramsCasing,
|
|
180
|
-
paramsType,
|
|
181
|
-
pathParamsType,
|
|
182
|
-
typeSchemas,
|
|
183
|
-
pageParamGeneric: 'TPageParam',
|
|
184
|
-
})
|
|
123
|
+
const queryKeyParamsNode = QueryKey.getParams(node, { pathParamsType, paramsCasing, resolver: tsResolver })
|
|
124
|
+
const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? ''
|
|
125
|
+
|
|
126
|
+
const queryOptionsParamsNode = getQueryOptionsParams(node, { paramsType, paramsCasing, pathParamsType, resolver: tsResolver })
|
|
127
|
+
const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? ''
|
|
185
128
|
|
|
186
|
-
const
|
|
129
|
+
const paramsNode = getParams(node, { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver: tsResolver, pageParamGeneric: 'TPageParam' })
|
|
130
|
+
const paramsSignature = declarationPrinter.print(paramsNode) ?? ''
|
|
187
131
|
|
|
188
132
|
return (
|
|
189
133
|
<File.Source name={name} isExportable isIndexable>
|
|
190
|
-
<Function
|
|
191
|
-
name={name}
|
|
192
|
-
export
|
|
193
|
-
generics={generics.join(', ')}
|
|
194
|
-
params={params.toConstructor()}
|
|
195
|
-
JSDoc={{
|
|
196
|
-
comments: getComments(operation),
|
|
197
|
-
}}
|
|
198
|
-
>
|
|
134
|
+
<Function name={name} export generics={generics.join(', ')} params={paramsSignature} returnType={undefined} JSDoc={{ comments: getComments(node) }}>
|
|
199
135
|
{`
|
|
200
136
|
const { query: queryConfig = {}, client: config = {} } = options ?? {}
|
|
201
137
|
const { client: queryClient, ...resolvedOptions } = queryConfig
|
|
202
|
-
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${
|
|
203
|
-
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${
|
|
138
|
+
const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
|
|
139
|
+
${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ''}
|
|
204
140
|
|
|
205
141
|
const query = useSuspenseInfiniteQuery({
|
|
206
|
-
...${
|
|
142
|
+
...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? '\n...customOptions,' : ''}
|
|
207
143
|
...resolvedOptions,
|
|
208
144
|
queryKey,
|
|
209
145
|
} as unknown as UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
|