@kubb/plugin-react-query 5.0.0-beta.3 → 5.0.0-beta.31

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.
Files changed (48) hide show
  1. package/README.md +34 -83
  2. package/dist/{components-DTGLu4UV.js → components-BVmVgpLX.js} +379 -279
  3. package/dist/components-BVmVgpLX.js.map +1 -0
  4. package/dist/{components-dAKJEn9b.cjs → components-DLUeLMsz.cjs} +409 -279
  5. package/dist/components-DLUeLMsz.cjs.map +1 -0
  6. package/dist/components.cjs +1 -1
  7. package/dist/components.d.ts +4 -76
  8. package/dist/components.js +1 -1
  9. package/dist/{generators-CWEQsdO9.cjs → generators--AcF4Y4n.cjs} +332 -410
  10. package/dist/generators--AcF4Y4n.cjs.map +1 -0
  11. package/dist/{generators-C_fbcjpG.js → generators-BFn9CLBS.js} +333 -411
  12. package/dist/generators-BFn9CLBS.js.map +1 -0
  13. package/dist/generators.cjs +1 -1
  14. package/dist/generators.d.ts +41 -1
  15. package/dist/generators.js +1 -1
  16. package/dist/index.cjs +179 -26
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.ts +30 -1
  19. package/dist/index.js +179 -26
  20. package/dist/index.js.map +1 -1
  21. package/dist/types-DiZPLTXl.d.ts +400 -0
  22. package/extension.yaml +1507 -0
  23. package/package.json +16 -18
  24. package/src/components/InfiniteQuery.tsx +24 -13
  25. package/src/components/InfiniteQueryOptions.tsx +37 -55
  26. package/src/components/Mutation.tsx +35 -15
  27. package/src/components/MutationOptions.tsx +14 -13
  28. package/src/components/Query.tsx +14 -10
  29. package/src/components/QueryOptions.tsx +17 -34
  30. package/src/components/SuspenseInfiniteQuery.tsx +19 -13
  31. package/src/components/SuspenseInfiniteQueryOptions.tsx +28 -52
  32. package/src/components/SuspenseQuery.tsx +9 -10
  33. package/src/generators/customHookOptionsFileGenerator.tsx +18 -14
  34. package/src/generators/hookOptionsGenerator.tsx +42 -49
  35. package/src/generators/infiniteQueryGenerator.tsx +55 -76
  36. package/src/generators/mutationGenerator.tsx +51 -62
  37. package/src/generators/queryGenerator.tsx +52 -61
  38. package/src/generators/suspenseInfiniteQueryGenerator.tsx +50 -63
  39. package/src/generators/suspenseQueryGenerator.tsx +54 -74
  40. package/src/plugin.ts +45 -31
  41. package/src/resolvers/resolverReactQuery.ts +102 -6
  42. package/src/types.ts +199 -61
  43. package/src/utils.ts +10 -33
  44. package/dist/components-DTGLu4UV.js.map +0 -1
  45. package/dist/components-dAKJEn9b.cjs.map +0 -1
  46. package/dist/generators-CWEQsdO9.cjs.map +0 -1
  47. package/dist/generators-C_fbcjpG.js.map +0 -1
  48. package/dist/types-DfaFRSBf.d.ts +0 -284
package/src/types.ts CHANGED
@@ -9,38 +9,153 @@ export type { Transformer } from '@internals/tanstack-query'
9
9
  */
10
10
  export type ResolverReactQuery = Resolver & {
11
11
  /**
12
- * Resolves the hook function name for an operation.
12
+ * Resolves the base function name for an operation.
13
13
  *
14
- * @example Resolving hook names
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
- * Customize the queryKey.
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
- * Customize the mutationKey.
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 to use for queries.
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
- * Path to the useQuery hook for useQuery functionality.
41
- * Used as `import { useQuery } from '${importPath}'`.
42
- * Accepts relative and absolute paths.
43
- * Path is used as-is; relative paths are based on the generated file location.
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 to use for mutations.
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
- * Path to the useMutation hook for useMutation functionality.
58
- * Used as `import { useMutation } from '${importPath}'`.
59
- * Accepts relative and absolute paths.
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,42 +180,45 @@ type Mutation = {
65
180
 
66
181
  export type Infinite = {
67
182
  /**
68
- * Specify the params key used for `pageParam`.
183
+ * Name of the query parameter that holds the page cursor.
184
+ *
69
185
  * @default 'id'
70
186
  */
71
- queryParam: string
187
+ queryParam?: string
72
188
  /**
73
- * Which field of the data is used, set it to undefined when no cursor is known.
74
- * @deprecated Use `nextParam` and `previousParam` instead for more flexible pagination handling.
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 | undefined
194
+ cursorParam?: string | null
77
195
  /**
78
- * Which field of the data is used to get the cursor for the next page.
79
- * Supports dot notation (e.g. 'pagination.next.id') or array path (e.g. ['pagination', 'next', 'id']) to access nested fields.
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[] | undefined
199
+ nextParam?: string | Array<string> | null
82
200
  /**
83
- * Which field of the data is used to get the cursor for the previous page.
84
- * Supports dot notation (e.g. 'pagination.prev.id') or array path (e.g. ['pagination', 'prev', 'id']) to access nested fields.
201
+ * Path to the previous-page cursor on the response. Supports dot notation
202
+ * or array form.
85
203
  */
86
- previousParam?: string | string[] | undefined
204
+ previousParam?: string | Array<string> | null
87
205
  /**
88
- * The initial value, the value of the first page.
206
+ * Initial value for `pageParam` on the first fetch.
207
+ *
89
208
  * @default 0
90
209
  */
91
- initialPageParam: unknown
210
+ initialPageParam?: unknown
92
211
  }
93
212
 
94
213
  type CustomOptions = {
95
214
  /**
96
- * Path to the hook that is used to customize the hook options.
97
- * It used as `import ${customOptions.name} from '${customOptions.importPath}'`.
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
- * Name of the exported hook that is used to customize the hook options.
103
- * It used as `import ${customOptions.name} from '${customOptions.importPath}'`.
220
+ * Exported function name of your custom-options hook.
221
+ *
104
222
  * @default 'useCustomHookOptions'
105
223
  */
106
224
  name?: string
@@ -108,92 +226,113 @@ type CustomOptions = {
108
226
 
109
227
  export type Options = {
110
228
  /**
111
- * Specify the export location for the files and define the behavior of the output
112
- * @default { path: 'hooks', barrelType: 'named' }
229
+ * Where the generated hooks are written and how they are exported.
230
+ *
231
+ * @default { path: 'hooks', barrel: { type: 'named' } }
113
232
  */
114
233
  output?: Output
115
234
  /**
116
- * Group the @tanstack/query hooks based on the provided name.
235
+ * Split generated files into subfolders based on the operation's tag.
117
236
  */
118
237
  group?: Group
238
+ /**
239
+ * HTTP client used inside every generated hook. Mirrors a subset of
240
+ * `pluginClient` options.
241
+ */
119
242
  client?: ClientImportPath & Pick<PluginClient['options'], 'clientType' | 'dataReturnType' | 'baseURL' | 'bundle' | 'paramsCasing'>
120
243
  /**
121
- * Tags, operations, or paths to exclude from generation.
244
+ * Skip operations matching at least one entry in the list.
122
245
  */
123
246
  exclude?: Array<Exclude>
124
247
  /**
125
- * Tags, operations, or paths to include in generation.
248
+ * Restrict generation to operations matching at least one entry in the list.
126
249
  */
127
250
  include?: Array<Include>
128
251
  /**
129
- * Override options for specific tags, operations, or paths.
252
+ * Apply a different options object to operations matching a pattern.
130
253
  */
131
254
  override?: Array<Override<ResolvedOptions>>
132
255
  /**
133
- * Apply casing to parameter names.
256
+ * Rename parameter properties in the generated hooks.
257
+ *
258
+ * @note Must match the value of `paramsCasing` on `@kubb/plugin-ts`.
134
259
  */
135
260
  paramsCasing?: 'camelcase'
136
261
  /**
137
- * How parameters are passed: grouped in an object or spread inline.
262
+ * How operation parameters appear in the generated hook signature.
263
+ * - `'inline'` — positional arguments.
264
+ * - `'object'` — single destructured object argument.
138
265
  *
139
266
  * @default 'inline'
140
267
  */
141
268
  paramsType?: 'object' | 'inline'
142
269
  /**
143
- * How path parameters are passed: grouped in an object or spread inline.
270
+ * How URL path parameters are arranged inside the inline argument list.
144
271
  *
145
272
  * @default 'inline'
146
273
  */
147
274
  pathParamsType?: PluginClient['options']['pathParamsType']
148
275
  /**
149
- * Add infinite query hooks.
276
+ * Enables `useInfiniteQuery` hooks for cursor- or page-based pagination.
277
+ * Pass an object to configure how the cursor is read; pass `false` to skip.
278
+ *
279
+ * @default false
150
280
  */
151
281
  infinite?: Partial<Infinite> | false
152
282
  /**
153
- * Add suspense query hooks.
283
+ * Adds `useSuspenseQuery` hooks alongside the regular `useQuery` ones.
284
+ * Pass an empty object (`{}`) to enable. TanStack Query v5+ only.
154
285
  */
155
286
  suspense?: Partial<Suspense> | false
287
+ /**
288
+ * Custom `queryKey` builder. Use to add a version namespace, swap to
289
+ * operation IDs, or shape keys to match an existing invalidation strategy.
290
+ */
156
291
  queryKey?: QueryKey
157
292
  /**
158
- * Configure useQuery behavior.
293
+ * Configures query hooks. Set to `false` to skip generating hooks entirely
294
+ * and emit only `queryOptions(...)` helpers.
159
295
  */
160
296
  query?: Partial<Query> | false
297
+ /**
298
+ * Custom `mutationKey` builder. Useful when you batch invalidations or read
299
+ * mutation state via `useMutationState`.
300
+ */
161
301
  mutationKey?: MutationKey
162
302
  /**
163
- * Configure useMutation behavior.
303
+ * Configures mutation hooks. Set to `false` to skip mutation generation.
164
304
  */
165
305
  mutation?: Partial<Mutation> | false
166
306
  /**
167
- * Use a custom hook to customize hook options and generate a HookOptions type.
307
+ * Wires every generated hook through a user-supplied function that returns
308
+ * extra options (`onSuccess`, `onError`, `select`, ...). Also emits a
309
+ * `HookOptions` type so the wrapper stays in sync with generated hooks.
168
310
  */
169
311
  customOptions?: CustomOptions
170
312
  /**
171
- * Parser to use for validating response data.
313
+ * Validator applied to response bodies before they reach the caller.
314
+ * - `'client'` — no validation. Trusts the API.
315
+ * - `'zod'` — pipes responses through schemas from `@kubb/plugin-zod`.
172
316
  */
173
317
  parser?: PluginClient['options']['parser']
174
- transformers?: {
175
- /**
176
- * Override the default naming for hooks.
177
- */
178
- name?: (name: string, type?: string) => string
179
- }
180
318
  /**
181
- * Override naming conventions for function names and types.
319
+ * Override how hook names and file paths are built. Methods you omit fall
320
+ * back to the default `resolverReactQuery`.
182
321
  */
183
322
  resolver?: Partial<ResolverReactQuery> & ThisType<ResolverReactQuery>
184
323
  /**
185
- * AST visitor to transform generated nodes.
324
+ * AST visitor applied to each operation node before printing.
186
325
  */
187
326
  transformer?: ast.Visitor
188
327
  /**
189
- * Additional generators alongside the default generators.
328
+ * Custom generators that run alongside the built-in React Query generators.
190
329
  */
191
330
  generators?: Array<Generator<PluginReactQuery>>
192
331
  }
193
332
 
194
333
  type ResolvedOptions = {
195
334
  output: Output
196
- group: Group | undefined
335
+ group: Group | null
197
336
  exclude: NonNullable<Options['exclude']>
198
337
  include: Options['include']
199
338
  override: NonNullable<Options['override']>
@@ -207,13 +346,12 @@ type ResolvedOptions = {
207
346
  */
208
347
  infinite: NonNullable<Infinite> | false
209
348
  suspense: Suspense | false
210
- queryKey: QueryKey | undefined
349
+ queryKey: QueryKey | null
211
350
  query: NonNullable<Required<Query>> | false
212
- mutationKey: MutationKey | undefined
351
+ mutationKey: MutationKey | null
213
352
  mutation: NonNullable<Required<Mutation>> | false
214
- customOptions: NonNullable<Required<CustomOptions>> | undefined
353
+ customOptions: NonNullable<Required<CustomOptions>> | null
215
354
  resolver: ResolverReactQuery
216
- transformers: NonNullable<Options['transformers']>
217
355
  }
218
356
 
219
357
  export type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, ResolverReactQuery>
package/src/utils.ts CHANGED
@@ -1,40 +1,17 @@
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
- resolveStatusCodeNames,
8
+ resolveZodSchemaNames,
14
9
  } from '@internals/tanstack-query'
15
-
16
- export function transformName(name: string, type: string, transformers?: PluginReactQuery['resolvedOptions']['transformers']): string {
17
- return transformers?.name?.(name, type) || name
18
- }
19
-
20
- function matchesPattern(node: ast.OperationNode, ov: { type: string; pattern: string | RegExp }): boolean {
21
- const { type, pattern } = ov
22
- const matches = (value: string) => (typeof pattern === 'string' ? value === pattern : pattern.test(value))
23
- if (type === 'operationId') return matches(node.operationId)
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
+ getContentTypeInfo,
14
+ resolveErrorNames,
15
+ resolveStatusCodeNames,
16
+ resolveSuccessNames,
17
+ } from '@internals/shared'