@kubb/plugin-react-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 +38 -91
- package/dist/{components-DTGLu4UV.js → components-DL0Cai7l.js} +570 -514
- package/dist/components-DL0Cai7l.js.map +1 -0
- package/dist/{components-dAKJEn9b.cjs → components-yMQOuFmI.cjs} +600 -514
- package/dist/components-yMQOuFmI.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +5 -77
- package/dist/components.js +1 -1
- package/dist/{generators-C_fbcjpG.js → generators-BG-Vcvfg.js} +444 -597
- package/dist/generators-BG-Vcvfg.js.map +1 -0
- package/dist/{generators-CWEQsdO9.cjs → generators-zGKP8yII.cjs} +442 -595
- package/dist/generators-zGKP8yII.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +49 -10
- package/dist/generators.js +1 -1
- package/dist/index.cjs +201 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +32 -4
- package/dist/index.js +203 -30
- package/dist/index.js.map +1 -1
- package/dist/types-X7D0NSvJ.d.ts +396 -0
- package/package.json +18 -27
- package/src/components/InfiniteQuery.tsx +27 -17
- package/src/components/InfiniteQueryOptions.tsx +60 -81
- package/src/components/Mutation.tsx +39 -20
- package/src/components/MutationOptions.tsx +15 -14
- package/src/components/Query.tsx +18 -15
- package/src/components/QueryOptions.tsx +20 -56
- package/src/components/SuspenseInfiniteQuery.tsx +22 -17
- package/src/components/SuspenseInfiniteQueryOptions.tsx +51 -76
- package/src/components/SuspenseQuery.tsx +13 -15
- package/src/generators/customHookOptionsFileGenerator.tsx +16 -12
- package/src/generators/hookOptionsGenerator.tsx +42 -49
- package/src/generators/infiniteQueryGenerator.tsx +55 -80
- package/src/generators/mutationGenerator.tsx +54 -66
- package/src/generators/queryGenerator.tsx +52 -65
- package/src/generators/suspenseInfiniteQueryGenerator.tsx +50 -67
- package/src/generators/suspenseQueryGenerator.tsx +54 -78
- package/src/plugin.ts +47 -33
- package/src/resolvers/resolverReactQuery.ts +104 -8
- package/src/types.ts +202 -68
- package/src/utils.ts +11 -33
- package/dist/components-DTGLu4UV.js.map +0 -1
- package/dist/components-dAKJEn9b.cjs.map +0 -1
- package/dist/generators-CWEQsdO9.cjs.map +0 -1
- package/dist/generators-C_fbcjpG.js.map +0 -1
- package/dist/types-DfaFRSBf.d.ts +0 -284
- package/extension.yaml +0 -938
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
|
@@ -1,22 +1,118 @@
|
|
|
1
|
-
import { camelCase } from '@internals/utils'
|
|
1
|
+
import { camelCase, toFilePath } from '@internals/utils'
|
|
2
2
|
import { defineResolver } from '@kubb/core'
|
|
3
3
|
import type { PluginReactQuery } from '../types.ts'
|
|
4
4
|
|
|
5
|
+
function capitalize(name: string): string {
|
|
6
|
+
return `${name.charAt(0).toUpperCase()}${name.slice(1)}`
|
|
7
|
+
}
|
|
8
|
+
|
|
5
9
|
/**
|
|
6
|
-
*
|
|
10
|
+
* Default resolver used by `@kubb/plugin-react-query`. Decides the names and
|
|
11
|
+
* file paths for every generated TanStack Query hook (`useFooQuery`,
|
|
12
|
+
* `useFooMutation`, `useFooInfiniteQuery`, ...) and its companion helpers
|
|
13
|
+
* (`fooQueryKey`, `fooQueryOptions`).
|
|
14
|
+
*
|
|
15
|
+
* Functions and files use camelCase; hooks get the `use` prefix; suspense and
|
|
16
|
+
* infinite variants are suffixed with `Suspense`/`Infinite`.
|
|
7
17
|
*
|
|
8
|
-
*
|
|
18
|
+
* @example Resolve hook and helper names
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { resolverReactQuery } from '@kubb/plugin-react-query'
|
|
9
21
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
22
|
+
* resolverReactQuery.resolveQueryName(operationNode) // 'useGetPetById'
|
|
23
|
+
* resolverReactQuery.resolveMutationName(operationNode) // 'useUpdatePet'
|
|
24
|
+
* resolverReactQuery.resolveQueryKeyName(operationNode) // 'getPetByIdQueryKey'
|
|
25
|
+
* resolverReactQuery.resolveQueryOptionsName(operationNode) // 'getPetByIdQueryOptions'
|
|
26
|
+
* ```
|
|
12
27
|
*/
|
|
13
|
-
export const resolverReactQuery = defineResolver<PluginReactQuery>((
|
|
28
|
+
export const resolverReactQuery = defineResolver<PluginReactQuery>(() => ({
|
|
14
29
|
name: 'default',
|
|
15
30
|
pluginName: 'plugin-react-query',
|
|
16
31
|
default(name, type) {
|
|
17
|
-
return
|
|
32
|
+
return type === 'file' ? toFilePath(name) : camelCase(name)
|
|
18
33
|
},
|
|
19
34
|
resolveName(name) {
|
|
20
|
-
return
|
|
35
|
+
return this.default(name, 'function')
|
|
36
|
+
},
|
|
37
|
+
resolvePathName(name, type) {
|
|
38
|
+
return this.default(name, type)
|
|
39
|
+
},
|
|
40
|
+
resolveQueryName(node) {
|
|
41
|
+
return `use${capitalize(this.resolveName(node.operationId))}`
|
|
42
|
+
},
|
|
43
|
+
resolveSuspenseQueryName(node) {
|
|
44
|
+
return `use${capitalize(this.resolveName(node.operationId))}Suspense`
|
|
45
|
+
},
|
|
46
|
+
resolveInfiniteQueryName(node) {
|
|
47
|
+
return `use${capitalize(this.resolveName(node.operationId))}Infinite`
|
|
48
|
+
},
|
|
49
|
+
resolveSuspenseInfiniteQueryName(node) {
|
|
50
|
+
return `use${capitalize(this.resolveName(node.operationId))}SuspenseInfinite`
|
|
51
|
+
},
|
|
52
|
+
resolveMutationName(node) {
|
|
53
|
+
return `use${capitalize(this.resolveName(node.operationId))}`
|
|
54
|
+
},
|
|
55
|
+
resolveQueryOptionsName(node) {
|
|
56
|
+
return `${this.resolveName(node.operationId)}QueryOptions`
|
|
57
|
+
},
|
|
58
|
+
resolveSuspenseQueryOptionsName(node) {
|
|
59
|
+
return `${this.resolveName(node.operationId)}SuspenseQueryOptions`
|
|
60
|
+
},
|
|
61
|
+
resolveInfiniteQueryOptionsName(node) {
|
|
62
|
+
return `${this.resolveName(node.operationId)}InfiniteQueryOptions`
|
|
63
|
+
},
|
|
64
|
+
resolveSuspenseInfiniteQueryOptionsName(node) {
|
|
65
|
+
return `${this.resolveName(node.operationId)}SuspenseInfiniteQueryOptions`
|
|
66
|
+
},
|
|
67
|
+
resolveMutationOptionsName(node) {
|
|
68
|
+
return `${this.resolveName(node.operationId)}MutationOptions`
|
|
69
|
+
},
|
|
70
|
+
resolveQueryKeyName(node) {
|
|
71
|
+
return `${this.resolveName(node.operationId)}QueryKey`
|
|
72
|
+
},
|
|
73
|
+
resolveSuspenseQueryKeyName(node) {
|
|
74
|
+
return `${this.resolveName(node.operationId)}SuspenseQueryKey`
|
|
75
|
+
},
|
|
76
|
+
resolveInfiniteQueryKeyName(node) {
|
|
77
|
+
return `${this.resolveName(node.operationId)}InfiniteQueryKey`
|
|
78
|
+
},
|
|
79
|
+
resolveSuspenseInfiniteQueryKeyName(node) {
|
|
80
|
+
return `${this.resolveName(node.operationId)}SuspenseInfiniteQueryKey`
|
|
81
|
+
},
|
|
82
|
+
resolveMutationKeyName(node) {
|
|
83
|
+
return `${this.resolveName(node.operationId)}MutationKey`
|
|
84
|
+
},
|
|
85
|
+
resolveQueryKeyTypeName(node) {
|
|
86
|
+
return `${capitalize(this.resolveName(node.operationId))}QueryKey`
|
|
87
|
+
},
|
|
88
|
+
resolveSuspenseQueryKeyTypeName(node) {
|
|
89
|
+
return `${capitalize(this.resolveName(node.operationId))}SuspenseQueryKey`
|
|
90
|
+
},
|
|
91
|
+
resolveInfiniteQueryKeyTypeName(node) {
|
|
92
|
+
return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`
|
|
93
|
+
},
|
|
94
|
+
resolveSuspenseInfiniteQueryKeyTypeName(node) {
|
|
95
|
+
return `${capitalize(this.resolveName(node.operationId))}SuspenseInfiniteQueryKey`
|
|
96
|
+
},
|
|
97
|
+
resolveMutationTypeName(node) {
|
|
98
|
+
return capitalize(this.resolveName(node.operationId))
|
|
99
|
+
},
|
|
100
|
+
resolveClientName(node) {
|
|
101
|
+
return this.resolveName(node.operationId)
|
|
102
|
+
},
|
|
103
|
+
resolveSuspenseClientName(node) {
|
|
104
|
+
return `${this.resolveName(node.operationId)}Suspense`
|
|
105
|
+
},
|
|
106
|
+
resolveInfiniteClientName(node) {
|
|
107
|
+
return `${this.resolveName(node.operationId)}Infinite`
|
|
108
|
+
},
|
|
109
|
+
resolveSuspenseInfiniteClientName(node) {
|
|
110
|
+
return `${this.resolveName(node.operationId)}SuspenseInfinite`
|
|
111
|
+
},
|
|
112
|
+
resolveHookOptionsName() {
|
|
113
|
+
return 'HookOptions'
|
|
114
|
+
},
|
|
115
|
+
resolveCustomHookOptionsName() {
|
|
116
|
+
return 'getCustomHookOptions'
|
|
21
117
|
},
|
|
22
118
|
}))
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Transformer } from '@internals/tanstack-query'
|
|
2
|
-
import type { ast, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver } from '@kubb/core'
|
|
2
|
+
import type { ast, Exclude, Generator, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver } from '@kubb/core'
|
|
3
3
|
import type { ClientImportPath, PluginClient } from '@kubb/plugin-client'
|
|
4
4
|
|
|
5
5
|
export type { Transformer } from '@internals/tanstack-query'
|
|
@@ -9,38 +9,153 @@ export type { Transformer } from '@internals/tanstack-query'
|
|
|
9
9
|
*/
|
|
10
10
|
export type ResolverReactQuery = Resolver & {
|
|
11
11
|
/**
|
|
12
|
-
* Resolves the
|
|
12
|
+
* Resolves the base function name for an operation.
|
|
13
13
|
*
|
|
14
|
-
* @example Resolving
|
|
14
|
+
* @example Resolving base operation names
|
|
15
15
|
* `resolver.resolveName('show pet by id') // -> 'showPetById'`
|
|
16
16
|
*/
|
|
17
17
|
resolveName(this: ResolverReactQuery, name: string): string
|
|
18
|
+
/**
|
|
19
|
+
* Resolves the output file name for a hook module.
|
|
20
|
+
*/
|
|
21
|
+
resolvePathName(this: ResolverReactQuery, name: string, type?: 'file' | 'function' | 'type' | 'const'): string
|
|
22
|
+
/**
|
|
23
|
+
* Resolves a query hook function name.
|
|
24
|
+
*/
|
|
25
|
+
resolveQueryName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
26
|
+
/**
|
|
27
|
+
* Resolves a suspense query hook function name.
|
|
28
|
+
*/
|
|
29
|
+
resolveSuspenseQueryName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
30
|
+
/**
|
|
31
|
+
* Resolves an infinite query hook function name.
|
|
32
|
+
*/
|
|
33
|
+
resolveInfiniteQueryName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
34
|
+
/**
|
|
35
|
+
* Resolves a suspense infinite query hook function name.
|
|
36
|
+
*/
|
|
37
|
+
resolveSuspenseInfiniteQueryName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
38
|
+
/**
|
|
39
|
+
* Resolves a mutation hook function name.
|
|
40
|
+
*/
|
|
41
|
+
resolveMutationName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
42
|
+
/**
|
|
43
|
+
* Resolves the query options helper name.
|
|
44
|
+
*/
|
|
45
|
+
resolveQueryOptionsName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
46
|
+
/**
|
|
47
|
+
* Resolves the suspense query options helper name.
|
|
48
|
+
*/
|
|
49
|
+
resolveSuspenseQueryOptionsName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
50
|
+
/**
|
|
51
|
+
* Resolves the infinite query options helper name.
|
|
52
|
+
*/
|
|
53
|
+
resolveInfiniteQueryOptionsName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
54
|
+
/**
|
|
55
|
+
* Resolves the suspense infinite query options helper name.
|
|
56
|
+
*/
|
|
57
|
+
resolveSuspenseInfiniteQueryOptionsName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
58
|
+
/**
|
|
59
|
+
* Resolves the mutation options helper name.
|
|
60
|
+
*/
|
|
61
|
+
resolveMutationOptionsName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
62
|
+
/**
|
|
63
|
+
* Resolves the query key helper name.
|
|
64
|
+
*/
|
|
65
|
+
resolveQueryKeyName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
66
|
+
/**
|
|
67
|
+
* Resolves the suspense query key helper name.
|
|
68
|
+
*/
|
|
69
|
+
resolveSuspenseQueryKeyName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
70
|
+
/**
|
|
71
|
+
* Resolves the infinite query key helper name.
|
|
72
|
+
*/
|
|
73
|
+
resolveInfiniteQueryKeyName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
74
|
+
/**
|
|
75
|
+
* Resolves the suspense infinite query key helper name.
|
|
76
|
+
*/
|
|
77
|
+
resolveSuspenseInfiniteQueryKeyName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
78
|
+
/**
|
|
79
|
+
* Resolves the mutation key helper name.
|
|
80
|
+
*/
|
|
81
|
+
resolveMutationKeyName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
82
|
+
/**
|
|
83
|
+
* Resolves the query key type name.
|
|
84
|
+
*/
|
|
85
|
+
resolveQueryKeyTypeName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
86
|
+
/**
|
|
87
|
+
* Resolves the suspense query key type name.
|
|
88
|
+
*/
|
|
89
|
+
resolveSuspenseQueryKeyTypeName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
90
|
+
/**
|
|
91
|
+
* Resolves the infinite query key type name.
|
|
92
|
+
*/
|
|
93
|
+
resolveInfiniteQueryKeyTypeName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
94
|
+
/**
|
|
95
|
+
* Resolves the suspense infinite query key type name.
|
|
96
|
+
*/
|
|
97
|
+
resolveSuspenseInfiniteQueryKeyTypeName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
98
|
+
/**
|
|
99
|
+
* Resolves the mutation type name.
|
|
100
|
+
*/
|
|
101
|
+
resolveMutationTypeName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
102
|
+
/**
|
|
103
|
+
* Resolves the client function name generated inline by query hooks.
|
|
104
|
+
*/
|
|
105
|
+
resolveClientName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
106
|
+
/**
|
|
107
|
+
* Resolves the client function name generated inline by suspense query hooks.
|
|
108
|
+
*/
|
|
109
|
+
resolveSuspenseClientName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
110
|
+
/**
|
|
111
|
+
* Resolves the client function name generated inline by infinite query hooks.
|
|
112
|
+
*/
|
|
113
|
+
resolveInfiniteClientName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
114
|
+
/**
|
|
115
|
+
* Resolves the client function name generated inline by suspense infinite query hooks.
|
|
116
|
+
*/
|
|
117
|
+
resolveSuspenseInfiniteClientName(this: ResolverReactQuery, node: ast.OperationNode): string
|
|
118
|
+
/**
|
|
119
|
+
* Resolves the generated custom hook options map type name.
|
|
120
|
+
*/
|
|
121
|
+
resolveHookOptionsName(this: ResolverReactQuery): string
|
|
122
|
+
/**
|
|
123
|
+
* Resolves the helper function name used inside the custom hook options file.
|
|
124
|
+
*/
|
|
125
|
+
resolveCustomHookOptionsName(this: ResolverReactQuery): string
|
|
18
126
|
}
|
|
19
127
|
|
|
20
128
|
type Suspense = object
|
|
21
129
|
|
|
22
130
|
/**
|
|
23
|
-
*
|
|
131
|
+
* Builds the `queryKey` used by each generated query hook.
|
|
132
|
+
*
|
|
133
|
+
* @note String values are inlined verbatim into generated code. Wrap literal
|
|
134
|
+
* strings in `JSON.stringify(...)`.
|
|
24
135
|
*/
|
|
25
136
|
type QueryKey = Transformer
|
|
26
137
|
|
|
27
138
|
/**
|
|
28
|
-
*
|
|
139
|
+
* Builds the `mutationKey` used by each generated mutation hook.
|
|
140
|
+
*
|
|
141
|
+
* @note String values are inlined verbatim into generated code. Wrap literal
|
|
142
|
+
* strings in `JSON.stringify(...)`.
|
|
29
143
|
*/
|
|
30
144
|
type MutationKey = Transformer
|
|
31
145
|
|
|
32
146
|
type Query = {
|
|
33
147
|
/**
|
|
34
|
-
* HTTP methods
|
|
148
|
+
* HTTP methods treated as queries. Operations using these methods produce
|
|
149
|
+
* `useQuery`-style hooks.
|
|
35
150
|
*
|
|
36
151
|
* @default ['get']
|
|
37
152
|
*/
|
|
38
153
|
methods?: Array<string>
|
|
39
154
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
155
|
+
* Module specifier used in the `import { useQuery } from '...'` statement at
|
|
156
|
+
* the top of every generated hook file. Useful for routing through a wrapper
|
|
157
|
+
* that injects a default `queryClient`.
|
|
158
|
+
*
|
|
44
159
|
* @default '@tanstack/react-query'
|
|
45
160
|
*/
|
|
46
161
|
importPath?: string
|
|
@@ -48,16 +163,16 @@ type Query = {
|
|
|
48
163
|
|
|
49
164
|
type Mutation = {
|
|
50
165
|
/**
|
|
51
|
-
* HTTP methods
|
|
166
|
+
* HTTP methods treated as mutations. Operations using these methods produce
|
|
167
|
+
* `useMutation`-style hooks.
|
|
52
168
|
*
|
|
53
169
|
* @default ['post', 'put', 'delete']
|
|
54
170
|
*/
|
|
55
171
|
methods?: Array<string>
|
|
56
172
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* Path is used as-is; relative paths are based on the generated file location.
|
|
173
|
+
* Module specifier used in the `import { useMutation } from '...'` statement
|
|
174
|
+
* at the top of every generated hook file.
|
|
175
|
+
*
|
|
61
176
|
* @default '@tanstack/react-query'
|
|
62
177
|
*/
|
|
63
178
|
importPath?: string
|
|
@@ -65,140 +180,160 @@ type Mutation = {
|
|
|
65
180
|
|
|
66
181
|
export type Infinite = {
|
|
67
182
|
/**
|
|
68
|
-
*
|
|
183
|
+
* Name of the query parameter that holds the page cursor.
|
|
184
|
+
*
|
|
69
185
|
* @default 'id'
|
|
70
186
|
*/
|
|
71
|
-
queryParam
|
|
187
|
+
queryParam?: string
|
|
72
188
|
/**
|
|
73
|
-
*
|
|
74
|
-
*
|
|
189
|
+
* Path to the cursor field on the response. Leave undefined when the cursor
|
|
190
|
+
* is not known.
|
|
191
|
+
*
|
|
192
|
+
* @deprecated Use `nextParam` and `previousParam` for richer pagination control.
|
|
75
193
|
*/
|
|
76
|
-
cursorParam?: string |
|
|
194
|
+
cursorParam?: string | null
|
|
77
195
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
196
|
+
* Path to the next-page cursor on the response. Supports dot notation
|
|
197
|
+
* (`'pagination.next.id'`) or array form (`['pagination', 'next', 'id']`).
|
|
80
198
|
*/
|
|
81
|
-
nextParam?: string | string
|
|
199
|
+
nextParam?: string | Array<string> | null
|
|
82
200
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
201
|
+
* Path to the previous-page cursor on the response. Supports dot notation
|
|
202
|
+
* or array form.
|
|
85
203
|
*/
|
|
86
|
-
previousParam?: string | string
|
|
204
|
+
previousParam?: string | Array<string> | null
|
|
87
205
|
/**
|
|
88
|
-
*
|
|
206
|
+
* Initial value for `pageParam` on the first fetch.
|
|
207
|
+
*
|
|
89
208
|
* @default 0
|
|
90
209
|
*/
|
|
91
|
-
initialPageParam
|
|
210
|
+
initialPageParam?: unknown
|
|
92
211
|
}
|
|
93
212
|
|
|
94
213
|
type CustomOptions = {
|
|
95
214
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* It allows both relative and absolute paths but be aware that we will not change the path.
|
|
215
|
+
* Module specifier of your custom-options hook. Imported as
|
|
216
|
+
* `import ${name} from '${importPath}'`.
|
|
99
217
|
*/
|
|
100
218
|
importPath: string
|
|
101
219
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
220
|
+
* Exported function name of your custom-options hook.
|
|
221
|
+
*
|
|
104
222
|
* @default 'useCustomHookOptions'
|
|
105
223
|
*/
|
|
106
224
|
name?: string
|
|
107
225
|
}
|
|
108
226
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Where the generated hooks are written and how they are exported, plus the optional `group`
|
|
229
|
+
* strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
|
|
230
|
+
*
|
|
231
|
+
* @default { path: 'hooks', barrel: { type: 'named' } }
|
|
232
|
+
*/
|
|
233
|
+
export type Options = OutputOptions & {
|
|
115
234
|
/**
|
|
116
|
-
*
|
|
235
|
+
* HTTP client used inside every generated hook. Mirrors a subset of
|
|
236
|
+
* `pluginClient` options.
|
|
117
237
|
*/
|
|
118
|
-
group?: Group
|
|
119
238
|
client?: ClientImportPath & Pick<PluginClient['options'], 'clientType' | 'dataReturnType' | 'baseURL' | 'bundle' | 'paramsCasing'>
|
|
120
239
|
/**
|
|
121
|
-
*
|
|
240
|
+
* Skip operations matching at least one entry in the list.
|
|
122
241
|
*/
|
|
123
242
|
exclude?: Array<Exclude>
|
|
124
243
|
/**
|
|
125
|
-
*
|
|
244
|
+
* Restrict generation to operations matching at least one entry in the list.
|
|
126
245
|
*/
|
|
127
246
|
include?: Array<Include>
|
|
128
247
|
/**
|
|
129
|
-
*
|
|
248
|
+
* Apply a different options object to operations matching a pattern.
|
|
130
249
|
*/
|
|
131
250
|
override?: Array<Override<ResolvedOptions>>
|
|
132
251
|
/**
|
|
133
|
-
*
|
|
252
|
+
* Rename parameter properties in the generated hooks.
|
|
253
|
+
*
|
|
254
|
+
* @note Must match the value of `paramsCasing` on `@kubb/plugin-ts`.
|
|
134
255
|
*/
|
|
135
256
|
paramsCasing?: 'camelcase'
|
|
136
257
|
/**
|
|
137
|
-
* How parameters
|
|
258
|
+
* How operation parameters appear in the generated hook signature.
|
|
259
|
+
* - `'inline'` — positional arguments.
|
|
260
|
+
* - `'object'` — single destructured object argument.
|
|
138
261
|
*
|
|
139
262
|
* @default 'inline'
|
|
140
263
|
*/
|
|
141
264
|
paramsType?: 'object' | 'inline'
|
|
142
265
|
/**
|
|
143
|
-
* How path parameters are
|
|
266
|
+
* How URL path parameters are arranged inside the inline argument list.
|
|
144
267
|
*
|
|
145
268
|
* @default 'inline'
|
|
146
269
|
*/
|
|
147
270
|
pathParamsType?: PluginClient['options']['pathParamsType']
|
|
148
271
|
/**
|
|
149
|
-
*
|
|
272
|
+
* Enables `useInfiniteQuery` hooks for cursor- or page-based pagination.
|
|
273
|
+
* Pass an object to configure how the cursor is read; pass `false` to skip.
|
|
274
|
+
*
|
|
275
|
+
* @default false
|
|
150
276
|
*/
|
|
151
277
|
infinite?: Partial<Infinite> | false
|
|
152
278
|
/**
|
|
153
|
-
*
|
|
279
|
+
* Adds `useSuspenseQuery` hooks alongside the regular `useQuery` ones.
|
|
280
|
+
* Pass an empty object (`{}`) to enable. TanStack Query v5+ only.
|
|
154
281
|
*/
|
|
155
282
|
suspense?: Partial<Suspense> | false
|
|
283
|
+
/**
|
|
284
|
+
* Custom `queryKey` builder. Use to add a version namespace, swap to
|
|
285
|
+
* operation IDs, or shape keys to match an existing invalidation strategy.
|
|
286
|
+
*/
|
|
156
287
|
queryKey?: QueryKey
|
|
157
288
|
/**
|
|
158
|
-
*
|
|
289
|
+
* Configures query hooks. Set to `false` to skip generating hooks entirely
|
|
290
|
+
* and emit only `queryOptions(...)` helpers.
|
|
159
291
|
*/
|
|
160
292
|
query?: Partial<Query> | false
|
|
293
|
+
/**
|
|
294
|
+
* Custom `mutationKey` builder. Useful when you batch invalidations or read
|
|
295
|
+
* mutation state via `useMutationState`.
|
|
296
|
+
*/
|
|
161
297
|
mutationKey?: MutationKey
|
|
162
298
|
/**
|
|
163
|
-
*
|
|
299
|
+
* Configures mutation hooks. Set to `false` to skip mutation generation.
|
|
164
300
|
*/
|
|
165
301
|
mutation?: Partial<Mutation> | false
|
|
166
302
|
/**
|
|
167
|
-
*
|
|
303
|
+
* Wires every generated hook through a user-supplied function that returns
|
|
304
|
+
* extra options (`onSuccess`, `onError`, `select`, ...). Also emits a
|
|
305
|
+
* `HookOptions` type so the wrapper stays in sync with generated hooks.
|
|
168
306
|
*/
|
|
169
307
|
customOptions?: CustomOptions
|
|
170
308
|
/**
|
|
171
|
-
*
|
|
309
|
+
* Validator applied to response bodies before they reach the caller.
|
|
310
|
+
* - `'client'` — no validation. Trusts the API.
|
|
311
|
+
* - `'zod'` — pipes responses through schemas from `@kubb/plugin-zod`.
|
|
172
312
|
*/
|
|
173
313
|
parser?: PluginClient['options']['parser']
|
|
174
|
-
transformers?: {
|
|
175
|
-
/**
|
|
176
|
-
* Override the default naming for hooks.
|
|
177
|
-
*/
|
|
178
|
-
name?: (name: string, type?: string) => string
|
|
179
|
-
}
|
|
180
314
|
/**
|
|
181
|
-
* Override
|
|
315
|
+
* Override how hook names and file paths are built. Methods you omit fall
|
|
316
|
+
* back to the default `resolverReactQuery`.
|
|
182
317
|
*/
|
|
183
318
|
resolver?: Partial<ResolverReactQuery> & ThisType<ResolverReactQuery>
|
|
184
319
|
/**
|
|
185
|
-
* AST visitor to
|
|
320
|
+
* AST visitor applied to each operation node before printing.
|
|
186
321
|
*/
|
|
187
322
|
transformer?: ast.Visitor
|
|
188
323
|
/**
|
|
189
|
-
*
|
|
324
|
+
* Custom generators that run alongside the built-in React Query generators.
|
|
190
325
|
*/
|
|
191
326
|
generators?: Array<Generator<PluginReactQuery>>
|
|
192
327
|
}
|
|
193
328
|
|
|
194
329
|
type ResolvedOptions = {
|
|
195
330
|
output: Output
|
|
196
|
-
group: Group |
|
|
331
|
+
group: Group | null
|
|
197
332
|
exclude: NonNullable<Options['exclude']>
|
|
198
333
|
include: Options['include']
|
|
199
334
|
override: NonNullable<Options['override']>
|
|
200
335
|
client: Pick<PluginClient['options'], 'client' | 'clientType' | 'dataReturnType' | 'importPath' | 'baseURL' | 'bundle' | 'paramsCasing'>
|
|
201
|
-
parser:
|
|
336
|
+
parser: NonNullable<Options['parser']>
|
|
202
337
|
pathParamsType: NonNullable<Options['pathParamsType']>
|
|
203
338
|
paramsCasing: Options['paramsCasing']
|
|
204
339
|
paramsType: NonNullable<Options['paramsType']>
|
|
@@ -207,13 +342,12 @@ type ResolvedOptions = {
|
|
|
207
342
|
*/
|
|
208
343
|
infinite: NonNullable<Infinite> | false
|
|
209
344
|
suspense: Suspense | false
|
|
210
|
-
queryKey: QueryKey |
|
|
345
|
+
queryKey: QueryKey | null
|
|
211
346
|
query: NonNullable<Required<Query>> | false
|
|
212
|
-
mutationKey: MutationKey |
|
|
347
|
+
mutationKey: MutationKey | null
|
|
213
348
|
mutation: NonNullable<Required<Mutation>> | false
|
|
214
|
-
customOptions: NonNullable<Required<CustomOptions>> |
|
|
349
|
+
customOptions: NonNullable<Required<CustomOptions>> | null
|
|
215
350
|
resolver: ResolverReactQuery
|
|
216
|
-
transformers: NonNullable<Options['transformers']>
|
|
217
351
|
}
|
|
218
352
|
|
|
219
353
|
export type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, ResolverReactQuery>
|
package/src/utils.ts
CHANGED
|
@@ -1,40 +1,18 @@
|
|
|
1
|
-
import type { ast } from '@kubb/core'
|
|
2
|
-
import type { PluginReactQuery } from './types.ts'
|
|
3
|
-
|
|
4
1
|
export {
|
|
5
2
|
buildGroupParam,
|
|
6
|
-
buildMutationArgParams,
|
|
7
3
|
buildQueryKeyParams,
|
|
8
|
-
getComments,
|
|
9
|
-
resolveErrorNames,
|
|
10
4
|
resolveHeaderGroupType,
|
|
5
|
+
resolveOperationOverrides,
|
|
11
6
|
resolvePathParamType,
|
|
12
7
|
resolveQueryGroupType,
|
|
13
|
-
|
|
8
|
+
resolveZodSchemaNames,
|
|
14
9
|
} from '@internals/tanstack-query'
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (type === 'tag') return node.tags.some((t) => matches(t))
|
|
25
|
-
if (type === 'path') return matches(node.path)
|
|
26
|
-
if (type === 'method') return matches(node.method)
|
|
27
|
-
return false
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Resolves per-operation overrides (first matching override wins), mirroring v4 OperationGenerator.getOptions().
|
|
32
|
-
*/
|
|
33
|
-
export function resolveOperationOverrides(
|
|
34
|
-
node: ast.OperationNode,
|
|
35
|
-
override?: PluginReactQuery['resolvedOptions']['override'],
|
|
36
|
-
): Partial<PluginReactQuery['resolvedOptions']> {
|
|
37
|
-
if (!override) return {}
|
|
38
|
-
const match = override.find((ov) => matchesPattern(node, ov as { type: string; pattern: string | RegExp }))
|
|
39
|
-
return (match as { options?: Partial<PluginReactQuery['resolvedOptions']> })?.options ?? {}
|
|
40
|
-
}
|
|
10
|
+
export {
|
|
11
|
+
buildOperationComments as getComments,
|
|
12
|
+
buildRequestConfigType,
|
|
13
|
+
buildStatusUnionType,
|
|
14
|
+
getContentTypeInfo,
|
|
15
|
+
resolveErrorNames,
|
|
16
|
+
resolveStatusCodeNames,
|
|
17
|
+
resolveSuccessNames,
|
|
18
|
+
} from '@internals/shared'
|