@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.
Files changed (49) hide show
  1. package/README.md +38 -91
  2. package/dist/{components-DTGLu4UV.js → components-DL0Cai7l.js} +570 -514
  3. package/dist/components-DL0Cai7l.js.map +1 -0
  4. package/dist/{components-dAKJEn9b.cjs → components-yMQOuFmI.cjs} +600 -514
  5. package/dist/components-yMQOuFmI.cjs.map +1 -0
  6. package/dist/components.cjs +1 -1
  7. package/dist/components.d.ts +5 -77
  8. package/dist/components.js +1 -1
  9. package/dist/{generators-C_fbcjpG.js → generators-BG-Vcvfg.js} +444 -597
  10. package/dist/generators-BG-Vcvfg.js.map +1 -0
  11. package/dist/{generators-CWEQsdO9.cjs → generators-zGKP8yII.cjs} +442 -595
  12. package/dist/generators-zGKP8yII.cjs.map +1 -0
  13. package/dist/generators.cjs +1 -1
  14. package/dist/generators.d.ts +49 -10
  15. package/dist/generators.js +1 -1
  16. package/dist/index.cjs +201 -28
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.ts +32 -4
  19. package/dist/index.js +203 -30
  20. package/dist/index.js.map +1 -1
  21. package/dist/types-X7D0NSvJ.d.ts +396 -0
  22. package/package.json +18 -27
  23. package/src/components/InfiniteQuery.tsx +27 -17
  24. package/src/components/InfiniteQueryOptions.tsx +60 -81
  25. package/src/components/Mutation.tsx +39 -20
  26. package/src/components/MutationOptions.tsx +15 -14
  27. package/src/components/Query.tsx +18 -15
  28. package/src/components/QueryOptions.tsx +20 -56
  29. package/src/components/SuspenseInfiniteQuery.tsx +22 -17
  30. package/src/components/SuspenseInfiniteQueryOptions.tsx +51 -76
  31. package/src/components/SuspenseQuery.tsx +13 -15
  32. package/src/generators/customHookOptionsFileGenerator.tsx +16 -12
  33. package/src/generators/hookOptionsGenerator.tsx +42 -49
  34. package/src/generators/infiniteQueryGenerator.tsx +55 -80
  35. package/src/generators/mutationGenerator.tsx +54 -66
  36. package/src/generators/queryGenerator.tsx +52 -65
  37. package/src/generators/suspenseInfiniteQueryGenerator.tsx +50 -67
  38. package/src/generators/suspenseQueryGenerator.tsx +54 -78
  39. package/src/plugin.ts +47 -33
  40. package/src/resolvers/resolverReactQuery.ts +104 -8
  41. package/src/types.ts +202 -68
  42. package/src/utils.ts +11 -33
  43. package/dist/components-DTGLu4UV.js.map +0 -1
  44. package/dist/components-dAKJEn9b.cjs.map +0 -1
  45. package/dist/generators-CWEQsdO9.cjs.map +0 -1
  46. package/dist/generators-C_fbcjpG.js.map +0 -1
  47. package/dist/types-DfaFRSBf.d.ts +0 -284
  48. package/extension.yaml +0 -938
  49. /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
@@ -0,0 +1,396 @@
1
+ import { t as __name } from "./chunk-C0LytTxp.js";
2
+ import { Exclude, Generator, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
3
+ import { ClientImportPath, PluginClient } from "@kubb/plugin-client";
4
+ import { PluginTs, ResolverTs } from "@kubb/plugin-ts";
5
+ import { KubbReactNode } from "@kubb/renderer-jsx/types";
6
+
7
+ //#region ../../internals/tanstack-query/src/types.d.ts
8
+ type ParamsCasing = 'camelcase' | undefined;
9
+ type Transformer = (props: {
10
+ node: ast.OperationNode;
11
+ casing: ParamsCasing;
12
+ }) => unknown[];
13
+ //#endregion
14
+ //#region ../../internals/tanstack-query/src/components/MutationKey.d.ts
15
+ type Props$1 = {
16
+ name: string;
17
+ node: ast.OperationNode;
18
+ paramsCasing: 'camelcase' | undefined;
19
+ pathParamsType: 'object' | 'inline';
20
+ transformer: Transformer | null | undefined;
21
+ };
22
+ declare function MutationKey$1({
23
+ name,
24
+ paramsCasing,
25
+ node,
26
+ transformer
27
+ }: Props$1): KubbReactNode;
28
+ //#endregion
29
+ //#region ../../internals/tanstack-query/src/components/QueryKey.d.ts
30
+ type Props = {
31
+ name: string;
32
+ typeName: string;
33
+ node: ast.OperationNode;
34
+ tsResolver: PluginTs['resolver'];
35
+ paramsCasing: 'camelcase' | undefined;
36
+ pathParamsType: 'object' | 'inline';
37
+ transformer: Transformer | null | undefined;
38
+ };
39
+ declare function QueryKey$1({
40
+ name,
41
+ node,
42
+ tsResolver,
43
+ paramsCasing,
44
+ pathParamsType,
45
+ typeName,
46
+ transformer
47
+ }: Props): KubbReactNode;
48
+ //#endregion
49
+ //#region src/types.d.ts
50
+ /**
51
+ * Resolver for React Query that provides naming methods for hook functions.
52
+ */
53
+ type ResolverReactQuery = Resolver & {
54
+ /**
55
+ * Resolves the base function name for an operation.
56
+ *
57
+ * @example Resolving base operation names
58
+ * `resolver.resolveName('show pet by id') // -> 'showPetById'`
59
+ */
60
+ resolveName(this: ResolverReactQuery, name: string): string;
61
+ /**
62
+ * Resolves the output file name for a hook module.
63
+ */
64
+ resolvePathName(this: ResolverReactQuery, name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
65
+ /**
66
+ * Resolves a query hook function name.
67
+ */
68
+ resolveQueryName(this: ResolverReactQuery, node: ast.OperationNode): string;
69
+ /**
70
+ * Resolves a suspense query hook function name.
71
+ */
72
+ resolveSuspenseQueryName(this: ResolverReactQuery, node: ast.OperationNode): string;
73
+ /**
74
+ * Resolves an infinite query hook function name.
75
+ */
76
+ resolveInfiniteQueryName(this: ResolverReactQuery, node: ast.OperationNode): string;
77
+ /**
78
+ * Resolves a suspense infinite query hook function name.
79
+ */
80
+ resolveSuspenseInfiniteQueryName(this: ResolverReactQuery, node: ast.OperationNode): string;
81
+ /**
82
+ * Resolves a mutation hook function name.
83
+ */
84
+ resolveMutationName(this: ResolverReactQuery, node: ast.OperationNode): string;
85
+ /**
86
+ * Resolves the query options helper name.
87
+ */
88
+ resolveQueryOptionsName(this: ResolverReactQuery, node: ast.OperationNode): string;
89
+ /**
90
+ * Resolves the suspense query options helper name.
91
+ */
92
+ resolveSuspenseQueryOptionsName(this: ResolverReactQuery, node: ast.OperationNode): string;
93
+ /**
94
+ * Resolves the infinite query options helper name.
95
+ */
96
+ resolveInfiniteQueryOptionsName(this: ResolverReactQuery, node: ast.OperationNode): string;
97
+ /**
98
+ * Resolves the suspense infinite query options helper name.
99
+ */
100
+ resolveSuspenseInfiniteQueryOptionsName(this: ResolverReactQuery, node: ast.OperationNode): string;
101
+ /**
102
+ * Resolves the mutation options helper name.
103
+ */
104
+ resolveMutationOptionsName(this: ResolverReactQuery, node: ast.OperationNode): string;
105
+ /**
106
+ * Resolves the query key helper name.
107
+ */
108
+ resolveQueryKeyName(this: ResolverReactQuery, node: ast.OperationNode): string;
109
+ /**
110
+ * Resolves the suspense query key helper name.
111
+ */
112
+ resolveSuspenseQueryKeyName(this: ResolverReactQuery, node: ast.OperationNode): string;
113
+ /**
114
+ * Resolves the infinite query key helper name.
115
+ */
116
+ resolveInfiniteQueryKeyName(this: ResolverReactQuery, node: ast.OperationNode): string;
117
+ /**
118
+ * Resolves the suspense infinite query key helper name.
119
+ */
120
+ resolveSuspenseInfiniteQueryKeyName(this: ResolverReactQuery, node: ast.OperationNode): string;
121
+ /**
122
+ * Resolves the mutation key helper name.
123
+ */
124
+ resolveMutationKeyName(this: ResolverReactQuery, node: ast.OperationNode): string;
125
+ /**
126
+ * Resolves the query key type name.
127
+ */
128
+ resolveQueryKeyTypeName(this: ResolverReactQuery, node: ast.OperationNode): string;
129
+ /**
130
+ * Resolves the suspense query key type name.
131
+ */
132
+ resolveSuspenseQueryKeyTypeName(this: ResolverReactQuery, node: ast.OperationNode): string;
133
+ /**
134
+ * Resolves the infinite query key type name.
135
+ */
136
+ resolveInfiniteQueryKeyTypeName(this: ResolverReactQuery, node: ast.OperationNode): string;
137
+ /**
138
+ * Resolves the suspense infinite query key type name.
139
+ */
140
+ resolveSuspenseInfiniteQueryKeyTypeName(this: ResolverReactQuery, node: ast.OperationNode): string;
141
+ /**
142
+ * Resolves the mutation type name.
143
+ */
144
+ resolveMutationTypeName(this: ResolverReactQuery, node: ast.OperationNode): string;
145
+ /**
146
+ * Resolves the client function name generated inline by query hooks.
147
+ */
148
+ resolveClientName(this: ResolverReactQuery, node: ast.OperationNode): string;
149
+ /**
150
+ * Resolves the client function name generated inline by suspense query hooks.
151
+ */
152
+ resolveSuspenseClientName(this: ResolverReactQuery, node: ast.OperationNode): string;
153
+ /**
154
+ * Resolves the client function name generated inline by infinite query hooks.
155
+ */
156
+ resolveInfiniteClientName(this: ResolverReactQuery, node: ast.OperationNode): string;
157
+ /**
158
+ * Resolves the client function name generated inline by suspense infinite query hooks.
159
+ */
160
+ resolveSuspenseInfiniteClientName(this: ResolverReactQuery, node: ast.OperationNode): string;
161
+ /**
162
+ * Resolves the generated custom hook options map type name.
163
+ */
164
+ resolveHookOptionsName(this: ResolverReactQuery): string;
165
+ /**
166
+ * Resolves the helper function name used inside the custom hook options file.
167
+ */
168
+ resolveCustomHookOptionsName(this: ResolverReactQuery): string;
169
+ };
170
+ type Suspense = object;
171
+ /**
172
+ * Builds the `queryKey` used by each generated query hook.
173
+ *
174
+ * @note String values are inlined verbatim into generated code. Wrap literal
175
+ * strings in `JSON.stringify(...)`.
176
+ */
177
+ type QueryKey = Transformer;
178
+ /**
179
+ * Builds the `mutationKey` used by each generated mutation hook.
180
+ *
181
+ * @note String values are inlined verbatim into generated code. Wrap literal
182
+ * strings in `JSON.stringify(...)`.
183
+ */
184
+ type MutationKey = Transformer;
185
+ type Query = {
186
+ /**
187
+ * HTTP methods treated as queries. Operations using these methods produce
188
+ * `useQuery`-style hooks.
189
+ *
190
+ * @default ['get']
191
+ */
192
+ methods?: Array<string>;
193
+ /**
194
+ * Module specifier used in the `import { useQuery } from '...'` statement at
195
+ * the top of every generated hook file. Useful for routing through a wrapper
196
+ * that injects a default `queryClient`.
197
+ *
198
+ * @default '@tanstack/react-query'
199
+ */
200
+ importPath?: string;
201
+ };
202
+ type Mutation = {
203
+ /**
204
+ * HTTP methods treated as mutations. Operations using these methods produce
205
+ * `useMutation`-style hooks.
206
+ *
207
+ * @default ['post', 'put', 'delete']
208
+ */
209
+ methods?: Array<string>;
210
+ /**
211
+ * Module specifier used in the `import { useMutation } from '...'` statement
212
+ * at the top of every generated hook file.
213
+ *
214
+ * @default '@tanstack/react-query'
215
+ */
216
+ importPath?: string;
217
+ };
218
+ type Infinite = {
219
+ /**
220
+ * Name of the query parameter that holds the page cursor.
221
+ *
222
+ * @default 'id'
223
+ */
224
+ queryParam?: string;
225
+ /**
226
+ * Path to the cursor field on the response. Leave undefined when the cursor
227
+ * is not known.
228
+ *
229
+ * @deprecated Use `nextParam` and `previousParam` for richer pagination control.
230
+ */
231
+ cursorParam?: string | null;
232
+ /**
233
+ * Path to the next-page cursor on the response. Supports dot notation
234
+ * (`'pagination.next.id'`) or array form (`['pagination', 'next', 'id']`).
235
+ */
236
+ nextParam?: string | Array<string> | null;
237
+ /**
238
+ * Path to the previous-page cursor on the response. Supports dot notation
239
+ * or array form.
240
+ */
241
+ previousParam?: string | Array<string> | null;
242
+ /**
243
+ * Initial value for `pageParam` on the first fetch.
244
+ *
245
+ * @default 0
246
+ */
247
+ initialPageParam?: unknown;
248
+ };
249
+ type CustomOptions = {
250
+ /**
251
+ * Module specifier of your custom-options hook. Imported as
252
+ * `import ${name} from '${importPath}'`.
253
+ */
254
+ importPath: string;
255
+ /**
256
+ * Exported function name of your custom-options hook.
257
+ *
258
+ * @default 'useCustomHookOptions'
259
+ */
260
+ name?: string;
261
+ };
262
+ /**
263
+ * Where the generated hooks are written and how they are exported, plus the optional `group`
264
+ * strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
265
+ *
266
+ * @default { path: 'hooks', barrel: { type: 'named' } }
267
+ */
268
+ type Options = OutputOptions & {
269
+ /**
270
+ * HTTP client used inside every generated hook. Mirrors a subset of
271
+ * `pluginClient` options.
272
+ */
273
+ client?: ClientImportPath & Pick<PluginClient['options'], 'clientType' | 'dataReturnType' | 'baseURL' | 'bundle' | 'paramsCasing'>;
274
+ /**
275
+ * Skip operations matching at least one entry in the list.
276
+ */
277
+ exclude?: Array<Exclude>;
278
+ /**
279
+ * Restrict generation to operations matching at least one entry in the list.
280
+ */
281
+ include?: Array<Include>;
282
+ /**
283
+ * Apply a different options object to operations matching a pattern.
284
+ */
285
+ override?: Array<Override<ResolvedOptions>>;
286
+ /**
287
+ * Rename parameter properties in the generated hooks.
288
+ *
289
+ * @note Must match the value of `paramsCasing` on `@kubb/plugin-ts`.
290
+ */
291
+ paramsCasing?: 'camelcase';
292
+ /**
293
+ * How operation parameters appear in the generated hook signature.
294
+ * - `'inline'` — positional arguments.
295
+ * - `'object'` — single destructured object argument.
296
+ *
297
+ * @default 'inline'
298
+ */
299
+ paramsType?: 'object' | 'inline';
300
+ /**
301
+ * How URL path parameters are arranged inside the inline argument list.
302
+ *
303
+ * @default 'inline'
304
+ */
305
+ pathParamsType?: PluginClient['options']['pathParamsType'];
306
+ /**
307
+ * Enables `useInfiniteQuery` hooks for cursor- or page-based pagination.
308
+ * Pass an object to configure how the cursor is read; pass `false` to skip.
309
+ *
310
+ * @default false
311
+ */
312
+ infinite?: Partial<Infinite> | false;
313
+ /**
314
+ * Adds `useSuspenseQuery` hooks alongside the regular `useQuery` ones.
315
+ * Pass an empty object (`{}`) to enable. TanStack Query v5+ only.
316
+ */
317
+ suspense?: Partial<Suspense> | false;
318
+ /**
319
+ * Custom `queryKey` builder. Use to add a version namespace, swap to
320
+ * operation IDs, or shape keys to match an existing invalidation strategy.
321
+ */
322
+ queryKey?: QueryKey;
323
+ /**
324
+ * Configures query hooks. Set to `false` to skip generating hooks entirely
325
+ * and emit only `queryOptions(...)` helpers.
326
+ */
327
+ query?: Partial<Query> | false;
328
+ /**
329
+ * Custom `mutationKey` builder. Useful when you batch invalidations or read
330
+ * mutation state via `useMutationState`.
331
+ */
332
+ mutationKey?: MutationKey;
333
+ /**
334
+ * Configures mutation hooks. Set to `false` to skip mutation generation.
335
+ */
336
+ mutation?: Partial<Mutation> | false;
337
+ /**
338
+ * Wires every generated hook through a user-supplied function that returns
339
+ * extra options (`onSuccess`, `onError`, `select`, ...). Also emits a
340
+ * `HookOptions` type so the wrapper stays in sync with generated hooks.
341
+ */
342
+ customOptions?: CustomOptions;
343
+ /**
344
+ * Validator applied to response bodies before they reach the caller.
345
+ * - `'client'` — no validation. Trusts the API.
346
+ * - `'zod'` — pipes responses through schemas from `@kubb/plugin-zod`.
347
+ */
348
+ parser?: PluginClient['options']['parser'];
349
+ /**
350
+ * Override how hook names and file paths are built. Methods you omit fall
351
+ * back to the default `resolverReactQuery`.
352
+ */
353
+ resolver?: Partial<ResolverReactQuery> & ThisType<ResolverReactQuery>;
354
+ /**
355
+ * AST visitor applied to each operation node before printing.
356
+ */
357
+ transformer?: ast.Visitor;
358
+ /**
359
+ * Custom generators that run alongside the built-in React Query generators.
360
+ */
361
+ generators?: Array<Generator<PluginReactQuery>>;
362
+ };
363
+ type ResolvedOptions = {
364
+ output: Output;
365
+ group: Group | null;
366
+ exclude: NonNullable<Options['exclude']>;
367
+ include: Options['include'];
368
+ override: NonNullable<Options['override']>;
369
+ client: Pick<PluginClient['options'], 'client' | 'clientType' | 'dataReturnType' | 'importPath' | 'baseURL' | 'bundle' | 'paramsCasing'>;
370
+ parser: NonNullable<Options['parser']>;
371
+ pathParamsType: NonNullable<Options['pathParamsType']>;
372
+ paramsCasing: Options['paramsCasing'];
373
+ paramsType: NonNullable<Options['paramsType']>;
374
+ /**
375
+ * Only used for infinite
376
+ */
377
+ infinite: NonNullable<Infinite> | false;
378
+ suspense: Suspense | false;
379
+ queryKey: QueryKey | null;
380
+ query: NonNullable<Required<Query>> | false;
381
+ mutationKey: MutationKey | null;
382
+ mutation: NonNullable<Required<Mutation>> | false;
383
+ customOptions: NonNullable<Required<CustomOptions>> | null;
384
+ resolver: ResolverReactQuery;
385
+ };
386
+ type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, ResolverReactQuery>;
387
+ declare global {
388
+ namespace Kubb {
389
+ interface PluginRegistry {
390
+ 'plugin-react-query': PluginReactQuery;
391
+ }
392
+ }
393
+ }
394
+ //#endregion
395
+ export { MutationKey$1 as a, QueryKey$1 as i, Options as n, PluginReactQuery as r, Infinite as t };
396
+ //# sourceMappingURL=types-X7D0NSvJ.d.ts.map
package/package.json CHANGED
@@ -1,25 +1,22 @@
1
1
  {
2
2
  "name": "@kubb/plugin-react-query",
3
- "version": "5.0.0-beta.4",
4
- "description": "React Query hooks generator plugin for Kubb, creating type-safe API client hooks from OpenAPI specifications for React applications.",
3
+ "version": "5.0.0-beta.56",
4
+ "description": "Generate type-safe TanStack Query (React Query) hooks from your OpenAPI specification. Covers useQuery, useMutation, useInfiniteQuery, and queryOptions with full TypeScript support.",
5
5
  "keywords": [
6
- "api-client",
7
- "code-generator",
6
+ "code-generation",
8
7
  "codegen",
9
8
  "data-fetching",
10
9
  "hooks",
11
10
  "kubb",
12
- "oas",
13
11
  "openapi",
14
- "plugins",
15
12
  "react",
16
- "react-hooks",
17
13
  "react-query",
18
- "sdk-generator",
19
14
  "swagger",
15
+ "tanstack",
20
16
  "tanstack-query",
21
- "type-safe",
22
- "typescript"
17
+ "typescript",
18
+ "use-mutation",
19
+ "use-query"
23
20
  ],
24
21
  "license": "MIT",
25
22
  "author": "stijnvanhulle",
@@ -31,7 +28,6 @@
31
28
  "files": [
32
29
  "src",
33
30
  "dist",
34
- "extension.yaml",
35
31
  "!/**/**.test.**",
36
32
  "!/**/__tests__/**",
37
33
  "!/**/__snapshots__/**"
@@ -71,37 +67,32 @@
71
67
  "registry": "https://registry.npmjs.org/"
72
68
  },
73
69
  "dependencies": {
74
- "@kubb/core": "5.0.0-beta.4",
75
- "@kubb/renderer-jsx": "5.0.0-beta.4",
76
- "remeda": "^2.34.0",
77
- "@kubb/plugin-client": "5.0.0-beta.4",
78
- "@kubb/plugin-ts": "5.0.0-beta.4",
79
- "@kubb/plugin-zod": "5.0.0-beta.4"
70
+ "@kubb/ast": "5.0.0-beta.55",
71
+ "@kubb/core": "5.0.0-beta.55",
72
+ "@kubb/renderer-jsx": "5.0.0-beta.55",
73
+ "@kubb/plugin-client": "5.0.0-beta.56",
74
+ "@kubb/plugin-ts": "5.0.0-beta.56",
75
+ "@kubb/plugin-zod": "5.0.0-beta.56"
80
76
  },
81
77
  "devDependencies": {
78
+ "@internals/shared": "0.0.0",
82
79
  "@internals/tanstack-query": "0.0.0",
83
80
  "@internals/utils": "0.0.0"
84
81
  },
85
82
  "peerDependencies": {
86
- "@kubb/renderer-jsx": "5.0.0-beta.4"
83
+ "@kubb/renderer-jsx": "5.0.0-beta.55"
87
84
  },
88
- "size-limit": [
89
- {
90
- "path": "./dist/*.js",
91
- "limit": "510 KiB",
92
- "gzip": true
93
- }
94
- ],
95
85
  "engines": {
96
86
  "node": ">=22"
97
87
  },
98
88
  "scripts": {
99
- "build": "tsdown && size-limit",
100
- "clean": "npx rimraf ./dist",
89
+ "build": "tsdown",
90
+ "clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
101
91
  "lint": "oxlint .",
102
92
  "lint:fix": "oxlint --fix .",
103
93
  "release": "pnpm publish --no-git-check",
104
94
  "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
95
+ "release:stage": "pnpm stage publish --no-git-check",
105
96
  "start": "tsdown --watch",
106
97
  "test": "vitest --passWithNoTests",
107
98
  "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
@@ -1,11 +1,12 @@
1
+ import { getOperationParameters } from '@internals/shared'
1
2
  import { ast } from '@kubb/core'
2
3
  import type { ResolverTs } from '@kubb/plugin-ts'
3
4
  import { functionPrinter } from '@kubb/plugin-ts'
4
5
  import { File, Function } from '@kubb/renderer-jsx'
5
6
  import type { KubbReactNode } from '@kubb/renderer-jsx/types'
6
7
  import type { Infinite, PluginReactQuery } from '../types.ts'
7
- import { getComments, resolveErrorNames } from '../utils.ts'
8
- import { QueryKey } from './QueryKey.tsx'
8
+ import { getEnabledParamNames, markParamsOptional } from '@internals/tanstack-query'
9
+ import { buildQueryKeyParams, buildStatusUnionType, getComments, resolveErrorNames, resolveSuccessNames } from '../utils.ts'
9
10
  import { getQueryOptionsParams } from './QueryOptions.tsx'
10
11
 
11
12
  type Props = {
@@ -27,7 +28,7 @@ type Props = {
27
28
  const declarationPrinter = functionPrinter({ mode: 'declaration' })
28
29
  const callPrinter = functionPrinter({ mode: 'call' })
29
30
 
30
- function getParams(
31
+ function buildInfiniteQueryParamsNode(
31
32
  node: ast.OperationNode,
32
33
  options: {
33
34
  paramsType: PluginReactQuery['resolvedOptions']['paramsType']
@@ -39,7 +40,7 @@ function getParams(
39
40
  },
40
41
  ): ast.FunctionParametersNode {
41
42
  const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options
42
- const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : undefined
43
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null
43
44
 
44
45
  const optionsParam = ast.createFunctionParameter({
45
46
  name: 'options',
@@ -77,10 +78,11 @@ export function InfiniteQuery({
77
78
  queryParam,
78
79
  customOptions,
79
80
  }: Props): KubbReactNode {
80
- const responseName = tsResolver.resolveResponseName(node)
81
+ const successNames = resolveSuccessNames(node, tsResolver)
82
+ const responseName = successNames.length > 0 ? successNames.join(' | ') : tsResolver.resolveResponseName(node)
81
83
  const errorNames = resolveErrorNames(node, tsResolver)
82
84
 
83
- const responseType = dataReturnType === 'data' ? responseName : `ResponseConfig<${responseName}>`
85
+ const responseType = dataReturnType === 'data' ? responseName : buildStatusUnionType(node, tsResolver)
84
86
  const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(' | ') : 'Error'}>`
85
87
 
86
88
  const isInitialPageParamDefined = initialPageParam !== undefined && initialPageParam !== null
@@ -98,17 +100,17 @@ export function InfiniteQuery({
98
100
  ? 'boolean'
99
101
  : 'unknown'
100
102
 
101
- const rawQueryParams = node.parameters.filter((p) => p.in === 'query')
103
+ const rawQueryParams = getOperationParameters(node).query
102
104
  const queryParamsTypeName =
103
105
  rawQueryParams.length > 0
104
106
  ? (() => {
105
107
  const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]!)
106
108
  const individualName = tsResolver.resolveParamName(node, rawQueryParams[0]!)
107
- return groupName !== individualName ? groupName : undefined
109
+ return groupName !== individualName ? groupName : null
108
110
  })()
109
- : undefined
111
+ : null
110
112
 
111
- const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : undefined
113
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null
112
114
  const pageParamType = queryParamType ? (isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType) : fallbackPageParamType
113
115
 
114
116
  const returnType = 'UseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }'
@@ -120,13 +122,24 @@ export function InfiniteQuery({
120
122
  `TPageParam = ${pageParamType}`,
121
123
  ]
122
124
 
123
- const queryKeyParamsNode = QueryKey.getParams(node, { pathParamsType, paramsCasing, resolver: tsResolver })
125
+ const queryKeyParamsNode = buildQueryKeyParams(node, { pathParamsType, paramsCasing, resolver: tsResolver })
124
126
  const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? ''
127
+ const enabledNames = getEnabledParamNames(queryKeyParamsNode)
125
128
 
126
129
  const queryOptionsParamsNode = getQueryOptionsParams(node, { paramsType, paramsCasing, pathParamsType, resolver: tsResolver })
127
130
  const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? ''
128
131
 
129
- const paramsNode = getParams(node, { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver: tsResolver, pageParamGeneric: 'TPageParam' })
132
+ const paramsNode = markParamsOptional(
133
+ buildInfiniteQueryParamsNode(node, {
134
+ paramsType,
135
+ paramsCasing,
136
+ pathParamsType,
137
+ dataReturnType,
138
+ resolver: tsResolver,
139
+ pageParamGeneric: 'TPageParam',
140
+ }),
141
+ enabledNames,
142
+ )
130
143
  const paramsSignature = declarationPrinter.print(paramsNode) ?? ''
131
144
 
132
145
  return (
@@ -135,11 +148,10 @@ export function InfiniteQuery({
135
148
  {`
136
149
  const { query: queryConfig = {}, client: config = {} } = options ?? {}
137
150
  const { client: queryClient, ...resolvedOptions } = queryConfig
138
- const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
139
- ${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ''}
151
+ const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ''}
140
152
 
141
153
  const query = useInfiniteQuery({
142
- ...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? '\n...customOptions,' : ''}
154
+ ...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? '\n ...customOptions,' : ''}
143
155
  ...resolvedOptions,
144
156
  queryKey,
145
157
  } as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
@@ -152,5 +164,3 @@ export function InfiniteQuery({
152
164
  </File.Source>
153
165
  )
154
166
  }
155
-
156
- InfiniteQuery.getParams = getParams