@kubb/plugin-react-query 5.0.0-alpha.9 → 5.0.0-beta.100

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 (47) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +38 -93
  3. package/dist/index.cjs +2317 -149
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +494 -6
  6. package/dist/index.js +2283 -143
  7. package/dist/index.js.map +1 -1
  8. package/package.json +47 -75
  9. package/dist/components-BHQT9ZLc.cjs +0 -1634
  10. package/dist/components-BHQT9ZLc.cjs.map +0 -1
  11. package/dist/components-CpyHYGOw.js +0 -1520
  12. package/dist/components-CpyHYGOw.js.map +0 -1
  13. package/dist/components.cjs +0 -13
  14. package/dist/components.d.ts +0 -398
  15. package/dist/components.js +0 -2
  16. package/dist/generators-DP07m3rH.cjs +0 -1469
  17. package/dist/generators-DP07m3rH.cjs.map +0 -1
  18. package/dist/generators-DkQwKTc2.js +0 -1427
  19. package/dist/generators-DkQwKTc2.js.map +0 -1
  20. package/dist/generators.cjs +0 -9
  21. package/dist/generators.d.ts +0 -523
  22. package/dist/generators.js +0 -2
  23. package/dist/types-D5S7Ny9r.d.ts +0 -270
  24. package/src/components/InfiniteQuery.tsx +0 -220
  25. package/src/components/InfiniteQueryOptions.tsx +0 -289
  26. package/src/components/Mutation.tsx +0 -158
  27. package/src/components/MutationKey.tsx +0 -1
  28. package/src/components/MutationOptions.tsx +0 -122
  29. package/src/components/Query.tsx +0 -194
  30. package/src/components/QueryKey.tsx +0 -1
  31. package/src/components/QueryOptions.tsx +0 -181
  32. package/src/components/SuspenseInfiniteQuery.tsx +0 -220
  33. package/src/components/SuspenseInfiniteQueryOptions.tsx +0 -289
  34. package/src/components/SuspenseQuery.tsx +0 -204
  35. package/src/components/index.ts +0 -11
  36. package/src/generators/customHookOptionsFileGenerator.tsx +0 -98
  37. package/src/generators/hookOptionsGenerator.tsx +0 -196
  38. package/src/generators/index.ts +0 -7
  39. package/src/generators/infiniteQueryGenerator.tsx +0 -214
  40. package/src/generators/mutationGenerator.tsx +0 -195
  41. package/src/generators/queryGenerator.tsx +0 -194
  42. package/src/generators/suspenseInfiniteQueryGenerator.tsx +0 -202
  43. package/src/generators/suspenseQueryGenerator.tsx +0 -207
  44. package/src/index.ts +0 -2
  45. package/src/plugin.ts +0 -239
  46. package/src/types.ts +0 -205
  47. /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
package/dist/index.d.ts CHANGED
@@ -1,10 +1,498 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { n as Options, r as PluginReactQuery } from "./types-D5S7Ny9r.js";
3
- import * as _kubb_core0 from "@kubb/core";
4
-
1
+ import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
+ import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ResolverPatch, ast } from "kubb/kit";
3
+ import "@kubb/plugin-ts";
4
+ import "kubb/jsx";
5
+ import "@kubb/plugin-zod";
6
+ //#region ../../internals/client/src/resolveClient.d.ts
7
+ /**
8
+ * Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
9
+ * operation, shared so the selection rules and diagnostics stay in one place.
10
+ *
11
+ * Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered
12
+ * contract client plugin (plugin-fetch or plugin-axios) and never emits its own inline client:
13
+ *
14
+ * - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
15
+ * imports and calls them.
16
+ * - `error` — no client plugin is registered, several are registered without a selector, or the
17
+ * requested one is missing.
18
+ *
19
+ * The `client` string selects explicitly (`'fetch'` / `'axios'`); when it is unset a lone registered
20
+ * contract client plugin is picked up automatically.
21
+ */
22
+ /**
23
+ * The client selector accepted by a consumer's `client` option. Both call a registered contract
24
+ * client plugin.
25
+ */
26
+ type ClientSelector = 'fetch' | 'axios';
27
+ /**
28
+ * The resolved client strategy stored in a consumer plugin's options: the generated code always
29
+ * imports and calls a registered contract client plugin's `<op>`. The client runtime lives in
30
+ * plugin-axios / plugin-fetch, so nothing is bundled by the consumer.
31
+ */
32
+ type ResolvedContractClient = {
33
+ kind: 'contract';
34
+ pluginName: string;
35
+ };
36
+ //#endregion
37
+ //#region ../../internals/tanstack-query/src/types.d.ts
38
+ type ParamsCasing = 'camelcase' | undefined;
39
+ type Transformer = (props: {
40
+ node: ast.OperationNode;
41
+ casing: ParamsCasing;
42
+ }) => Array<unknown>;
43
+ /**
44
+ * Configures the query side of a TanStack-family plugin: which HTTP methods produce query
45
+ * hooks and where the query runtime is imported from.
46
+ */
47
+ type Query = {
48
+ /**
49
+ * HTTP methods treated as queries. Operations using these methods produce
50
+ * `useQuery`-style hooks.
51
+ *
52
+ * @default ['GET']
53
+ */
54
+ methods?: Array<string>;
55
+ /**
56
+ * Module specifier used in the `import { useQuery } from '...'` statement at
57
+ * the top of every generated file. Each plugin defaults this to its own runtime
58
+ * package. Useful for routing through a wrapper that injects a default
59
+ * `queryClient`.
60
+ */
61
+ importPath?: string;
62
+ };
63
+ /**
64
+ * Configures the mutation side of a TanStack-family plugin: which HTTP methods produce
65
+ * mutation hooks and where the mutation runtime is imported from.
66
+ */
67
+ type Mutation = {
68
+ /**
69
+ * HTTP methods treated as mutations. Operations using these methods produce
70
+ * `useMutation`-style hooks.
71
+ *
72
+ * @default ['POST', 'PUT', 'PATCH', 'DELETE']
73
+ */
74
+ methods?: Array<string>;
75
+ /**
76
+ * Module specifier used in the `import { useMutation } from '...'` statement
77
+ * at the top of every generated file. Each plugin defaults this to its own
78
+ * runtime package.
79
+ */
80
+ importPath?: string;
81
+ };
82
+ type Infinite = {
83
+ /**
84
+ * Name of the query parameter that holds the page cursor.
85
+ *
86
+ * @default 'id'
87
+ */
88
+ queryParam?: string;
89
+ /**
90
+ * Path to the cursor field on the response. Leave undefined when the cursor
91
+ * is not known.
92
+ *
93
+ * @deprecated Use `nextParam` and `previousParam` for richer pagination control.
94
+ */
95
+ cursorParam?: string | null;
96
+ /**
97
+ * Path to the next-page cursor on the response. Supports dot notation
98
+ * (`'pagination.next.id'`) or array form (`['pagination', 'next', 'id']`).
99
+ */
100
+ nextParam?: string | Array<string> | null;
101
+ /**
102
+ * Path to the previous-page cursor on the response. Supports dot notation
103
+ * or array form.
104
+ */
105
+ previousParam?: string | Array<string> | null;
106
+ /**
107
+ * Initial value for `pageParam` on the first fetch.
108
+ *
109
+ * @default 0
110
+ */
111
+ initialPageParam?: unknown;
112
+ };
113
+ //#endregion
114
+ //#region src/types.d.ts
115
+ /**
116
+ * The concrete resolver type for `@kubb/plugin-react-query`.
117
+ * Extends the base `Resolver` (which provides `default` naming and option helpers, the top-level
118
+ * `name` casing, and the `file` builder) with plugin-specific naming namespaces for the generated
119
+ * `useQuery`, `useSuspenseQuery`, `useInfiniteQuery`, `useSuspenseInfiniteQuery`, and `useMutation`
120
+ * hooks and their companion helpers.
121
+ */
122
+ type ResolverReactQuery = Resolver & {
123
+ /**
124
+ * Naming for the generated `useQuery` hook and its companion helpers.
125
+ */
126
+ query: {
127
+ /**
128
+ * Resolves a query hook function name.
129
+ *
130
+ * @example Query hook names
131
+ * `resolver.query.name(node) // → 'useGetPetById'`
132
+ */
133
+ name(node: ast.OperationNode): string;
134
+ /**
135
+ * Resolves the query options helper name.
136
+ *
137
+ * @example Query options helper names
138
+ * `resolver.query.optionsName(node) // → 'getPetByIdQueryOptions'`
139
+ */
140
+ optionsName(node: ast.OperationNode): string;
141
+ /**
142
+ * Resolves the query key helper name.
143
+ *
144
+ * @example Query key helper names
145
+ * `resolver.query.keyName(node) // → 'getPetByIdQueryKey'`
146
+ */
147
+ keyName(node: ast.OperationNode): string;
148
+ /**
149
+ * Resolves the query key type name.
150
+ *
151
+ * @example Query key type names
152
+ * `resolver.query.keyTypeName(node) // → 'GetPetByIdQueryKey'`
153
+ */
154
+ keyTypeName(node: ast.OperationNode): string;
155
+ /**
156
+ * Resolves the client function name generated inline by query hooks.
157
+ *
158
+ * @example Client function names
159
+ * `resolver.query.clientName(node) // → 'getPetById'`
160
+ */
161
+ clientName(node: ast.OperationNode): string;
162
+ };
163
+ /**
164
+ * Naming for the generated `useSuspenseQuery` hook and its companion helpers.
165
+ */
166
+ suspenseQuery: {
167
+ /**
168
+ * Resolves a suspense query hook function name.
169
+ *
170
+ * @example Suspense query hook names
171
+ * `resolver.suspenseQuery.name(node) // → 'useGetPetByIdSuspense'`
172
+ */
173
+ name(node: ast.OperationNode): string;
174
+ /**
175
+ * Resolves the suspense query options helper name.
176
+ */
177
+ optionsName(node: ast.OperationNode): string;
178
+ /**
179
+ * Resolves the suspense query key helper name.
180
+ */
181
+ keyName(node: ast.OperationNode): string;
182
+ /**
183
+ * Resolves the suspense query key type name.
184
+ */
185
+ keyTypeName(node: ast.OperationNode): string;
186
+ /**
187
+ * Resolves the client function name generated inline by suspense query hooks.
188
+ */
189
+ clientName(node: ast.OperationNode): string;
190
+ };
191
+ /**
192
+ * Naming for the generated `useInfiniteQuery` hook and its companion helpers.
193
+ */
194
+ infiniteQuery: {
195
+ /**
196
+ * Resolves an infinite query hook function name.
197
+ *
198
+ * @example Infinite query hook names
199
+ * `resolver.infiniteQuery.name(node) // → 'useGetPetByIdInfinite'`
200
+ */
201
+ name(node: ast.OperationNode): string;
202
+ /**
203
+ * Resolves the infinite query options helper name.
204
+ */
205
+ optionsName(node: ast.OperationNode): string;
206
+ /**
207
+ * Resolves the infinite query key helper name.
208
+ */
209
+ keyName(node: ast.OperationNode): string;
210
+ /**
211
+ * Resolves the infinite query key type name.
212
+ */
213
+ keyTypeName(node: ast.OperationNode): string;
214
+ /**
215
+ * Resolves the client function name generated inline by infinite query hooks.
216
+ */
217
+ clientName(node: ast.OperationNode): string;
218
+ };
219
+ /**
220
+ * Naming for the generated `useSuspenseInfiniteQuery` hook and its companion helpers.
221
+ */
222
+ suspenseInfiniteQuery: {
223
+ /**
224
+ * Resolves a suspense infinite query hook function name.
225
+ *
226
+ * @example Suspense infinite query hook names
227
+ * `resolver.suspenseInfiniteQuery.name(node) // → 'useGetPetByIdSuspenseInfinite'`
228
+ */
229
+ name(node: ast.OperationNode): string;
230
+ /**
231
+ * Resolves the suspense infinite query options helper name.
232
+ */
233
+ optionsName(node: ast.OperationNode): string;
234
+ /**
235
+ * Resolves the suspense infinite query key helper name.
236
+ */
237
+ keyName(node: ast.OperationNode): string;
238
+ /**
239
+ * Resolves the suspense infinite query key type name.
240
+ */
241
+ keyTypeName(node: ast.OperationNode): string;
242
+ /**
243
+ * Resolves the client function name generated inline by suspense infinite query hooks.
244
+ */
245
+ clientName(node: ast.OperationNode): string;
246
+ };
247
+ /**
248
+ * Naming for the generated `useMutation` hook and its companion helpers.
249
+ */
250
+ mutation: {
251
+ /**
252
+ * Resolves a mutation hook function name.
253
+ *
254
+ * @example Mutation hook names
255
+ * `resolver.mutation.name(node) // → 'useUpdatePet'`
256
+ */
257
+ name(node: ast.OperationNode): string;
258
+ /**
259
+ * Resolves the mutation options helper name.
260
+ */
261
+ optionsName(node: ast.OperationNode): string;
262
+ /**
263
+ * Resolves the mutation key helper name.
264
+ */
265
+ keyName(node: ast.OperationNode): string;
266
+ /**
267
+ * Resolves the mutation type name.
268
+ *
269
+ * @example Mutation type names
270
+ * `resolver.mutation.typeName(node) // → 'UpdatePet'`
271
+ */
272
+ typeName(node: ast.OperationNode): string;
273
+ };
274
+ /**
275
+ * Naming for the generated custom hook options file.
276
+ */
277
+ hook: {
278
+ /**
279
+ * Resolves the generated custom hook options map type name.
280
+ */
281
+ optionsName(): string;
282
+ /**
283
+ * Resolves the helper function name used inside the custom hook options file.
284
+ */
285
+ customOptionsName(): string;
286
+ };
287
+ };
288
+ type Suspense = object;
289
+ /**
290
+ * Builds the `queryKey` used by each generated query hook.
291
+ *
292
+ * @note String values are inlined verbatim into generated code. Wrap literal
293
+ * strings in `JSON.stringify(...)`.
294
+ */
295
+ type QueryKey = Transformer;
296
+ /**
297
+ * Builds the `mutationKey` used by each generated mutation hook.
298
+ *
299
+ * @note String values are inlined verbatim into generated code. Wrap literal
300
+ * strings in `JSON.stringify(...)`.
301
+ */
302
+ type MutationKey = Transformer;
303
+ type CustomOptions = {
304
+ /**
305
+ * Module specifier of your custom-options hook. Imported as a named import,
306
+ * `import { ${name} } from '${importPath}'`.
307
+ */
308
+ importPath: string;
309
+ /**
310
+ * Exported function name of your custom-options hook.
311
+ *
312
+ * @default 'useCustomHookOptions'
313
+ */
314
+ name?: string;
315
+ };
316
+ /**
317
+ * Where the generated hooks are written and how they are exported, plus the optional `group`
318
+ * strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
319
+ *
320
+ * @default { path: 'hooks', barrel: { type: 'named' } }
321
+ */
322
+ type Options = OutputOptions & {
323
+ /**
324
+ * Selects the HTTP client the generated hooks call. Every client plugin speaks the `RequestResult`
325
+ * contract, so the hooks call a contract `<op>` that takes one grouped `options` object.
326
+ *
327
+ * `'fetch'` / `'axios'` calls the `@kubb/plugin-fetch` / `@kubb/plugin-axios` functions. When a
328
+ * single client plugin (plugin-fetch or plugin-axios) is registered it is
329
+ * auto-detected, so the string is only needed to disambiguate several client plugins.
330
+ *
331
+ * A client plugin must be registered. The hooks always call its `<op>`.
332
+ */
333
+ client?: ClientSelector;
334
+ /**
335
+ * Skip operations matching at least one entry in the list.
336
+ */
337
+ exclude?: Array<Exclude>;
338
+ /**
339
+ * Restrict generation to operations matching at least one entry in the list.
340
+ */
341
+ include?: Array<Include>;
342
+ /**
343
+ * Apply a different options object to operations matching a pattern.
344
+ */
345
+ override?: Array<Override<ResolvedOptions>>;
346
+ /**
347
+ * Enables `useInfiniteQuery` hooks for cursor- or page-based pagination.
348
+ * Pass an object to configure how the cursor is read, or pass `false` to skip.
349
+ *
350
+ * @default false
351
+ */
352
+ infinite?: Partial<Infinite> | false;
353
+ /**
354
+ * Adds `useSuspenseQuery` hooks alongside the regular `useQuery` ones.
355
+ * Pass an empty object (`{}`) to enable. TanStack Query v5+ only.
356
+ *
357
+ * @default false
358
+ */
359
+ suspense?: Partial<Suspense> | false;
360
+ /**
361
+ * Custom `queryKey` builder. Use to add a version namespace, swap to
362
+ * operation IDs, or shape keys to match an existing invalidation strategy.
363
+ */
364
+ queryKey?: QueryKey;
365
+ /**
366
+ * Configures query hooks. Set to `false` to skip generating hooks entirely
367
+ * and emit only `queryOptions(...)` helpers.
368
+ */
369
+ query?: Partial<Query> | false;
370
+ /**
371
+ * Custom `mutationKey` builder. Useful when you batch invalidations or read
372
+ * mutation state via `useMutationState`.
373
+ */
374
+ mutationKey?: MutationKey;
375
+ /**
376
+ * Configures mutation hooks. Set to `false` to skip mutation generation.
377
+ */
378
+ mutation?: Partial<Mutation> | false;
379
+ /**
380
+ * Wires every generated hook through a user-supplied function that returns
381
+ * extra options (`onSuccess`, `onError`, `select`, ...). Also emits a
382
+ * `HookOptions` type so the wrapper stays in sync with generated hooks.
383
+ */
384
+ customOptions?: CustomOptions;
385
+ /**
386
+ * Override how hook names and file paths are built. Methods you omit fall
387
+ * back to the default `resolverReactQuery`.
388
+ */
389
+ resolver?: ResolverPatch<ResolverReactQuery>;
390
+ /**
391
+ * Set to `false` to skip generating `use*` hook functions. `queryOptions`,
392
+ * `mutationOptions`, `queryKey`, and `mutationKey` helpers are still emitted.
393
+ * The resulting output uses only `@tanstack/react-query` factory imports
394
+ * (`queryOptions`, `infiniteQueryOptions`, `mutationOptions`) that are
395
+ * adapter-portable across React, Vue, Solid, and Svelte.
396
+ *
397
+ * @default false
398
+ */
399
+ hooks?: boolean;
400
+ /**
401
+ * Macros applied to each operation node before printing.
402
+ */
403
+ macros?: Array<ast.Macro>;
404
+ };
405
+ /**
406
+ * The resolved client strategy for the generated hooks, computed once during setup. The hooks always
407
+ * import and call a registered contract client plugin's `<op>`.
408
+ */
409
+ type ResolvedClient = ResolvedContractClient;
410
+ type ResolvedOptions = {
411
+ output: Output;
412
+ group: Group | null;
413
+ exclude: NonNullable<Options['exclude']>;
414
+ include: Options['include'];
415
+ override: NonNullable<Options['override']>;
416
+ /**
417
+ * The resolved contract client the generators import and call.
418
+ */
419
+ client: ResolvedClient;
420
+ /**
421
+ * Resolved infinite query configuration, or `false` when infinite queries are disabled.
422
+ */
423
+ infinite: NonNullable<Infinite> | false;
424
+ suspense: Suspense | false;
425
+ queryKey: QueryKey | null;
426
+ query: NonNullable<Required<Query>> | false;
427
+ mutationKey: MutationKey | null;
428
+ mutation: NonNullable<Required<Mutation>> | false;
429
+ customOptions: NonNullable<Required<CustomOptions>> | null;
430
+ hooks: boolean;
431
+ resolver: ResolverReactQuery;
432
+ };
433
+ type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options, ResolvedOptions, ResolverReactQuery>;
434
+ declare global {
435
+ namespace Kubb {
436
+ interface PluginRegistry {
437
+ 'plugin-react-query': PluginReactQuery;
438
+ }
439
+ }
440
+ }
441
+ //#endregion
5
442
  //#region src/plugin.d.ts
443
+ /**
444
+ * Canonical plugin name for `@kubb/plugin-react-query`. Used for driver lookups
445
+ * and cross-plugin dependency references.
446
+ */
6
447
  declare const pluginReactQueryName = "plugin-react-query";
7
- declare const pluginReactQuery: (options?: Options | undefined) => _kubb_core0.UserPluginWithLifeCycle<PluginReactQuery>;
448
+ /**
449
+ * Generates one TanStack Query hook per OpenAPI operation for React. Queries
450
+ * become `useFoo`, with `useFooSuspense` and `useFooInfinite` variants.
451
+ * Mutations become `useFoo`. Each hook is fully typed: query keys, input
452
+ * variables, response data, and error shape all come from the spec.
453
+ *
454
+ * @example
455
+ * ```ts
456
+ * import { defineConfig } from 'kubb/config'
457
+ * import { pluginTs } from '@kubb/plugin-ts'
458
+ * import { pluginReactQuery } from '@kubb/plugin-react-query'
459
+ *
460
+ * export default defineConfig({
461
+ * input: './petStore.yaml',
462
+ * output: { path: './src/gen' },
463
+ * plugins: [
464
+ * pluginTs(),
465
+ * pluginReactQuery({
466
+ * output: { path: './hooks' },
467
+ * suspense: {},
468
+ * }),
469
+ * ],
470
+ * })
471
+ * ```
472
+ */
473
+ declare const pluginReactQuery: (options?: Options | undefined) => import("kubb/kit").Plugin<PluginReactQuery>;
474
+ //#endregion
475
+ //#region src/resolvers/resolverReactQuery.d.ts
476
+ /**
477
+ * Default resolver used by `@kubb/plugin-react-query`. Decides the names and
478
+ * file paths for every generated TanStack Query hook (`useFoo`,
479
+ * `useFooSuspense`, `useFooInfinite`, ...) and its companion helpers
480
+ * (`fooQueryKey`, `fooQueryOptions`).
481
+ *
482
+ * Functions and files use the built-in camelCase casing; hooks get the `use`
483
+ * prefix; suspense and infinite variants are suffixed with `Suspense`/`Infinite`.
484
+ *
485
+ * @example Resolve hook and helper names
486
+ * ```ts
487
+ * import { resolverReactQuery } from '@kubb/plugin-react-query'
488
+ *
489
+ * resolverReactQuery.query.name(operationNode) // 'useGetPetById'
490
+ * resolverReactQuery.mutation.name(operationNode) // 'useUpdatePet'
491
+ * resolverReactQuery.query.keyName(operationNode) // 'getPetByIdQueryKey'
492
+ * resolverReactQuery.query.optionsName(operationNode) // 'getPetByIdQueryOptions'
493
+ * ```
494
+ */
495
+ declare const resolverReactQuery: ResolverReactQuery;
8
496
  //#endregion
9
- export { type PluginReactQuery, pluginReactQuery, pluginReactQueryName };
497
+ export { type PluginReactQuery, type ResolverReactQuery, pluginReactQuery as default, pluginReactQuery, pluginReactQueryName, resolverReactQuery };
10
498
  //# sourceMappingURL=index.d.ts.map