@kubb/plugin-react-query 5.5.1 → 5.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +538 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +3 -3
- package/kubb-extension.json +1 -1
- package/package.json +13 -8
- package/dist/rolldown-runtime-C0LytTxp.js +0 -8
package/dist/index.cjs
CHANGED
|
@@ -343,11 +343,11 @@ function createGroupConfig(group) {
|
|
|
343
343
|
//#region kubb-extension.json
|
|
344
344
|
var compatibility = {
|
|
345
345
|
"kubb": ">=5.8.3",
|
|
346
|
-
"node": ">=22"
|
|
346
|
+
"node": ">=22.12"
|
|
347
347
|
};
|
|
348
348
|
//#endregion
|
|
349
349
|
//#region package.json
|
|
350
|
-
var version = "5.5.
|
|
350
|
+
var version = "5.5.3";
|
|
351
351
|
//#endregion
|
|
352
352
|
//#region ../../internals/client/src/resolveClient.ts
|
|
353
353
|
/**
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
2
|
+
import "@kubb/plugin-zod";
|
|
3
|
+
import "@kubb/plugin-ts";
|
|
4
|
+
import "kubb/jsx";
|
|
5
|
+
//#region ../../internals/client/src/resolveClient.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* The client selector accepted by a consumer's `client` option. Each calls a registered contract
|
|
8
|
+
* client plugin.
|
|
9
|
+
*/
|
|
10
|
+
type ClientSelector = 'fetch' | 'axios' | 'client';
|
|
11
|
+
/**
|
|
12
|
+
* The resolved client strategy stored in a consumer plugin's options: the generated code always
|
|
13
|
+
* imports and calls a registered contract client plugin's `<op>`. The client runtime lives in
|
|
14
|
+
* plugin-axios / plugin-fetch, so nothing is bundled by the consumer.
|
|
15
|
+
*/
|
|
16
|
+
type ResolvedContractClient = {
|
|
17
|
+
kind: 'contract';
|
|
18
|
+
pluginName: string;
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region ../../internals/tanstack-query/src/types.d.ts
|
|
22
|
+
type ParamsCasing = 'camelcase' | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* The hook a key is built for. Plain and suspense queries can share a key, but an infinite query
|
|
25
|
+
* caches `InfiniteData` and must never share one with a plain query.
|
|
26
|
+
*/
|
|
27
|
+
type KeyVariant = 'query' | 'suspenseQuery' | 'infiniteQuery' | 'suspenseInfiniteQuery' | 'mutation';
|
|
28
|
+
/**
|
|
29
|
+
* Builds query or mutation key segments for an operation node.
|
|
30
|
+
* Receives `variant` indicating which hook or composable the key is built for.
|
|
31
|
+
*/
|
|
32
|
+
type Transformer = (props: {
|
|
33
|
+
node: ast.OperationNode;
|
|
34
|
+
casing: ParamsCasing;
|
|
35
|
+
variant: KeyVariant;
|
|
36
|
+
}) => Array<unknown>;
|
|
37
|
+
/**
|
|
38
|
+
* Configures the query side of a TanStack-family plugin: which HTTP methods produce query
|
|
39
|
+
* hooks and where the query runtime is imported from.
|
|
40
|
+
*/
|
|
41
|
+
type Query = {
|
|
42
|
+
/**
|
|
43
|
+
* HTTP methods treated as queries. Operations using these methods produce
|
|
44
|
+
* `useQuery`-style hooks.
|
|
45
|
+
*
|
|
46
|
+
* @default ['GET', 'QUERY']
|
|
47
|
+
*/
|
|
48
|
+
methods?: Array<string>;
|
|
49
|
+
/**
|
|
50
|
+
* Module specifier used in the `import { useQuery } from '...'` statement at
|
|
51
|
+
* the top of every generated file. Each plugin defaults this to its own runtime
|
|
52
|
+
* package. Useful for routing through a wrapper that injects a default
|
|
53
|
+
* `queryClient`.
|
|
54
|
+
*/
|
|
55
|
+
importPath?: string;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Configures the mutation side of a TanStack-family plugin: which HTTP methods produce
|
|
59
|
+
* mutation hooks and where the mutation runtime is imported from.
|
|
60
|
+
*/
|
|
61
|
+
type Mutation = {
|
|
62
|
+
/**
|
|
63
|
+
* HTTP methods treated as mutations. Operations using these methods produce
|
|
64
|
+
* `useMutation`-style hooks.
|
|
65
|
+
*
|
|
66
|
+
* @default ['POST', 'PUT', 'PATCH', 'DELETE']
|
|
67
|
+
*/
|
|
68
|
+
methods?: Array<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Module specifier used in the `import { useMutation } from '...'` statement
|
|
71
|
+
* at the top of every generated file. Each plugin defaults this to its own
|
|
72
|
+
* runtime package.
|
|
73
|
+
*/
|
|
74
|
+
importPath?: string;
|
|
75
|
+
};
|
|
76
|
+
type Infinite = {
|
|
77
|
+
/**
|
|
78
|
+
* Name of the query parameter that holds the page cursor.
|
|
79
|
+
*
|
|
80
|
+
* @default 'id'
|
|
81
|
+
*/
|
|
82
|
+
queryParam?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Path to the cursor field on the response. Leave undefined when the cursor
|
|
85
|
+
* is not known.
|
|
86
|
+
*
|
|
87
|
+
* @deprecated Use `nextParam` and `previousParam` for richer pagination control.
|
|
88
|
+
*/
|
|
89
|
+
cursorParam?: string | null;
|
|
90
|
+
/**
|
|
91
|
+
* Path to the next-page cursor on the response. Supports dot notation
|
|
92
|
+
* (`'pagination.next.id'`) or array form (`['pagination', 'next', 'id']`).
|
|
93
|
+
*/
|
|
94
|
+
nextParam?: string | Array<string> | null;
|
|
95
|
+
/**
|
|
96
|
+
* Path to the previous-page cursor on the response. Supports dot notation
|
|
97
|
+
* or array form.
|
|
98
|
+
*/
|
|
99
|
+
previousParam?: string | Array<string> | null;
|
|
100
|
+
/**
|
|
101
|
+
* Initial value for `pageParam` on the first fetch.
|
|
102
|
+
*
|
|
103
|
+
* @default 0
|
|
104
|
+
*/
|
|
105
|
+
initialPageParam?: unknown;
|
|
106
|
+
/**
|
|
107
|
+
* Whether `initialPageParam` was explicitly configured rather than defaulted.
|
|
108
|
+
* When omitted or false, the default previous page threshold remains 1 (legacy 1-based default).
|
|
109
|
+
*/
|
|
110
|
+
hasExplicitInitialPageParam?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Source of TanStack Query's `getNextPageParam`, inlined verbatim as a function expression. Use it
|
|
113
|
+
* when the next page has to be computed rather than read from a field. Takes precedence over
|
|
114
|
+
* `nextParam` and `cursorParam`.
|
|
115
|
+
*
|
|
116
|
+
* Note: Because functions are inlined verbatim into generated code via `.toString()`, they cannot
|
|
117
|
+
* reference local closures or external variables from the config file.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* `'(lastPage) => (lastPage.hasNext ? lastPage.number + 1 : undefined)'`
|
|
121
|
+
* // or with definePageParam:
|
|
122
|
+
* `definePageParam<MyResponse, number>((lastPage) => (lastPage.hasNext ? lastPage.number + 1 : undefined))`
|
|
123
|
+
*/
|
|
124
|
+
getNextPageParam?: string | PageParamFn | null;
|
|
125
|
+
/**
|
|
126
|
+
* Source of TanStack Query's `getPreviousPageParam`, inlined verbatim as a function expression.
|
|
127
|
+
* Takes precedence over `previousParam` and `cursorParam`.
|
|
128
|
+
*
|
|
129
|
+
* Note: Because functions are inlined verbatim into generated code via `.toString()`, they cannot
|
|
130
|
+
* reference local closures or external variables from the config file.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* `'(firstPage) => (firstPage.number > 0 ? firstPage.number - 1 : undefined)'`
|
|
134
|
+
* // or with definePageParam:
|
|
135
|
+
* `definePageParam<MyResponse, number>((firstPage) => (firstPage.number > 0 ? firstPage.number - 1 : undefined))`
|
|
136
|
+
*/
|
|
137
|
+
getPreviousPageParam?: string | PageParamFn | null;
|
|
138
|
+
};
|
|
139
|
+
type PageParamFn<TPage = any, TParam = any> = (page: TPage, allPages: Array<TPage>, pageParam: TParam, allPageParams: Array<TParam>) => TParam | undefined | null;
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region ../../internals/tanstack-query/src/utils.d.ts
|
|
142
|
+
/**
|
|
143
|
+
* Helper to define a typed page param function for `infinite.getNextPageParam` or
|
|
144
|
+
* `infinite.getPreviousPageParam`. Serializes the function to a string for inlining in generated code.
|
|
145
|
+
*
|
|
146
|
+
* Note: Because the function is inlined verbatim into the generated file via `.toString()`,
|
|
147
|
+
* it must be self-contained and cannot reference local closures or external variables from
|
|
148
|
+
* the config file.
|
|
149
|
+
*/
|
|
150
|
+
export declare function definePageParam<TPage = any, TParam = any>(fn: PageParamFn<TPage, TParam>): string;
|
|
151
|
+
//#endregion
|
|
152
|
+
//#region src/types.d.ts
|
|
153
|
+
/**
|
|
154
|
+
* The concrete resolver type for `@kubb/plugin-react-query`.
|
|
155
|
+
* Extends the base `Resolver` (which provides `default` naming and option helpers, the top-level
|
|
156
|
+
* `name` casing, and the `file` builder) with plugin-specific naming namespaces for the generated
|
|
157
|
+
* `useQuery`, `useSuspenseQuery`, `useInfiniteQuery`, `useSuspenseInfiniteQuery`, and `useMutation`
|
|
158
|
+
* hooks and their companion helpers.
|
|
159
|
+
*/
|
|
160
|
+
type ResolverReactQuery = Resolver & {
|
|
161
|
+
/**
|
|
162
|
+
* Naming for the generated `useQuery` hook and its companion helpers.
|
|
163
|
+
*/
|
|
164
|
+
query: {
|
|
165
|
+
/**
|
|
166
|
+
* Resolves a query hook function name.
|
|
167
|
+
*
|
|
168
|
+
* @example Query hook names
|
|
169
|
+
* `resolver.query.name(node) // → 'useGetPetById'`
|
|
170
|
+
*/
|
|
171
|
+
name(node: ast.OperationNode): string;
|
|
172
|
+
/**
|
|
173
|
+
* Resolves the query options helper name.
|
|
174
|
+
*
|
|
175
|
+
* @example Query options helper names
|
|
176
|
+
* `resolver.query.optionsName(node) // → 'getPetByIdQueryOptions'`
|
|
177
|
+
*/
|
|
178
|
+
optionsName(node: ast.OperationNode): string;
|
|
179
|
+
/**
|
|
180
|
+
* Resolves the query key helper name.
|
|
181
|
+
*
|
|
182
|
+
* @example Query key helper names
|
|
183
|
+
* `resolver.query.keyName(node) // → 'getPetByIdQueryKey'`
|
|
184
|
+
*/
|
|
185
|
+
keyName(node: ast.OperationNode): string;
|
|
186
|
+
/**
|
|
187
|
+
* Resolves the query key type name.
|
|
188
|
+
*
|
|
189
|
+
* @example Query key type names
|
|
190
|
+
* `resolver.query.keyTypeName(node) // → 'GetPetByIdQueryKey'`
|
|
191
|
+
*/
|
|
192
|
+
keyTypeName(node: ast.OperationNode): string;
|
|
193
|
+
/**
|
|
194
|
+
* Resolves the client function name generated inline by query hooks.
|
|
195
|
+
*
|
|
196
|
+
* @example Client function names
|
|
197
|
+
* `resolver.query.clientName(node) // → 'getPetById'`
|
|
198
|
+
*/
|
|
199
|
+
clientName(node: ast.OperationNode): string;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* Naming for the generated `useSuspenseQuery` hook and its companion helpers.
|
|
203
|
+
*/
|
|
204
|
+
suspenseQuery: {
|
|
205
|
+
/**
|
|
206
|
+
* Resolves a suspense query hook function name.
|
|
207
|
+
*
|
|
208
|
+
* @example Suspense query hook names
|
|
209
|
+
* `resolver.suspenseQuery.name(node) // → 'useGetPetByIdSuspense'`
|
|
210
|
+
*/
|
|
211
|
+
name(node: ast.OperationNode): string;
|
|
212
|
+
/**
|
|
213
|
+
* Resolves the suspense query options helper name.
|
|
214
|
+
*/
|
|
215
|
+
optionsName(node: ast.OperationNode): string;
|
|
216
|
+
/**
|
|
217
|
+
* Resolves the suspense query key helper name.
|
|
218
|
+
*/
|
|
219
|
+
keyName(node: ast.OperationNode): string;
|
|
220
|
+
/**
|
|
221
|
+
* Resolves the suspense query key type name.
|
|
222
|
+
*/
|
|
223
|
+
keyTypeName(node: ast.OperationNode): string;
|
|
224
|
+
/**
|
|
225
|
+
* Resolves the client function name generated inline by suspense query hooks.
|
|
226
|
+
*/
|
|
227
|
+
clientName(node: ast.OperationNode): string;
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* Naming for the generated `useInfiniteQuery` hook and its companion helpers.
|
|
231
|
+
*/
|
|
232
|
+
infiniteQuery: {
|
|
233
|
+
/**
|
|
234
|
+
* Resolves an infinite query hook function name.
|
|
235
|
+
*
|
|
236
|
+
* @example Infinite query hook names
|
|
237
|
+
* `resolver.infiniteQuery.name(node) // → 'useGetPetByIdInfinite'`
|
|
238
|
+
*/
|
|
239
|
+
name(node: ast.OperationNode): string;
|
|
240
|
+
/**
|
|
241
|
+
* Resolves the infinite query options helper name.
|
|
242
|
+
*/
|
|
243
|
+
optionsName(node: ast.OperationNode): string;
|
|
244
|
+
/**
|
|
245
|
+
* Resolves the infinite query key helper name.
|
|
246
|
+
*/
|
|
247
|
+
keyName(node: ast.OperationNode): string;
|
|
248
|
+
/**
|
|
249
|
+
* Resolves the infinite query key type name.
|
|
250
|
+
*/
|
|
251
|
+
keyTypeName(node: ast.OperationNode): string;
|
|
252
|
+
/**
|
|
253
|
+
* Resolves the client function name generated inline by infinite query hooks.
|
|
254
|
+
*/
|
|
255
|
+
clientName(node: ast.OperationNode): string;
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Naming for the generated `useSuspenseInfiniteQuery` hook and its companion helpers.
|
|
259
|
+
*/
|
|
260
|
+
suspenseInfiniteQuery: {
|
|
261
|
+
/**
|
|
262
|
+
* Resolves a suspense infinite query hook function name.
|
|
263
|
+
*
|
|
264
|
+
* @example Suspense infinite query hook names
|
|
265
|
+
* `resolver.suspenseInfiniteQuery.name(node) // → 'useGetPetByIdSuspenseInfinite'`
|
|
266
|
+
*/
|
|
267
|
+
name(node: ast.OperationNode): string;
|
|
268
|
+
/**
|
|
269
|
+
* Resolves the suspense infinite query options helper name.
|
|
270
|
+
*/
|
|
271
|
+
optionsName(node: ast.OperationNode): string;
|
|
272
|
+
/**
|
|
273
|
+
* Resolves the suspense infinite query key helper name.
|
|
274
|
+
*/
|
|
275
|
+
keyName(node: ast.OperationNode): string;
|
|
276
|
+
/**
|
|
277
|
+
* Resolves the suspense infinite query key type name.
|
|
278
|
+
*/
|
|
279
|
+
keyTypeName(node: ast.OperationNode): string;
|
|
280
|
+
/**
|
|
281
|
+
* Resolves the client function name generated inline by suspense infinite query hooks.
|
|
282
|
+
*/
|
|
283
|
+
clientName(node: ast.OperationNode): string;
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* Naming for the generated `useMutation` hook and its companion helpers.
|
|
287
|
+
*/
|
|
288
|
+
mutation: {
|
|
289
|
+
/**
|
|
290
|
+
* Resolves a mutation hook function name.
|
|
291
|
+
*
|
|
292
|
+
* @example Mutation hook names
|
|
293
|
+
* `resolver.mutation.name(node) // → 'useUpdatePet'`
|
|
294
|
+
*/
|
|
295
|
+
name(node: ast.OperationNode): string;
|
|
296
|
+
/**
|
|
297
|
+
* Resolves the mutation options helper name.
|
|
298
|
+
*/
|
|
299
|
+
optionsName(node: ast.OperationNode): string;
|
|
300
|
+
/**
|
|
301
|
+
* Resolves the mutation key helper name.
|
|
302
|
+
*/
|
|
303
|
+
keyName(node: ast.OperationNode): string;
|
|
304
|
+
/**
|
|
305
|
+
* Resolves the mutation type name.
|
|
306
|
+
*
|
|
307
|
+
* @example Mutation type names
|
|
308
|
+
* `resolver.mutation.typeName(node) // → 'UpdatePet'`
|
|
309
|
+
*/
|
|
310
|
+
typeName(node: ast.OperationNode): string;
|
|
311
|
+
};
|
|
312
|
+
/**
|
|
313
|
+
* Naming for the generated custom hook options file.
|
|
314
|
+
*/
|
|
315
|
+
hook: {
|
|
316
|
+
/**
|
|
317
|
+
* Resolves the generated custom hook options map type name.
|
|
318
|
+
*/
|
|
319
|
+
optionsName(): string;
|
|
320
|
+
/**
|
|
321
|
+
* Resolves the helper function name used inside the custom hook options file.
|
|
322
|
+
*/
|
|
323
|
+
customOptionsName(): string;
|
|
324
|
+
};
|
|
325
|
+
};
|
|
326
|
+
type Suspense = object;
|
|
327
|
+
/**
|
|
328
|
+
* Builds the `queryKey` used by each generated query hook. `variant` tells which hook the key is for,
|
|
329
|
+
* so infinite keys can stay apart from plain ones.
|
|
330
|
+
*
|
|
331
|
+
* @note String values are inlined verbatim into generated code. Wrap literal
|
|
332
|
+
* strings in `JSON.stringify(...)`.
|
|
333
|
+
*/
|
|
334
|
+
type QueryKey = Transformer;
|
|
335
|
+
/**
|
|
336
|
+
* Builds the `mutationKey` used by each generated mutation hook.
|
|
337
|
+
*
|
|
338
|
+
* @note String values are inlined verbatim into generated code. Wrap literal
|
|
339
|
+
* strings in `JSON.stringify(...)`.
|
|
340
|
+
*/
|
|
341
|
+
type MutationKey = Transformer;
|
|
342
|
+
type CustomOptions = {
|
|
343
|
+
/**
|
|
344
|
+
* Module specifier of your custom-options hook. Imported as a named import,
|
|
345
|
+
* `import { ${name} } from '${importPath}'`.
|
|
346
|
+
*/
|
|
347
|
+
importPath: string;
|
|
348
|
+
/**
|
|
349
|
+
* Exported function name of your custom-options hook.
|
|
350
|
+
*
|
|
351
|
+
* @default 'useCustomHookOptions'
|
|
352
|
+
*/
|
|
353
|
+
name?: string;
|
|
354
|
+
};
|
|
355
|
+
/**
|
|
356
|
+
* Where the generated hooks are written and how they are exported, plus the optional `group`
|
|
357
|
+
* strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
|
|
358
|
+
*
|
|
359
|
+
* @default { path: 'hooks', barrel: { type: 'named' } }
|
|
360
|
+
*/
|
|
361
|
+
type Options = OutputOptions & {
|
|
362
|
+
/**
|
|
363
|
+
* Selects the HTTP client the generated hooks call. Every client plugin speaks the `RequestResult`
|
|
364
|
+
* contract, so the hooks call a contract `<op>` that takes one grouped `options` object.
|
|
365
|
+
*
|
|
366
|
+
* `'fetch'` / `'axios'` / `'client'` calls the `@kubb/plugin-fetch` / `@kubb/plugin-axios` /
|
|
367
|
+
* `@kubb/plugin-client` functions. When a single client plugin is registered it is
|
|
368
|
+
* auto-detected, so the string is only needed to disambiguate several client plugins.
|
|
369
|
+
*
|
|
370
|
+
* A client plugin must be registered. The hooks always call its `<op>`.
|
|
371
|
+
*/
|
|
372
|
+
client?: ClientSelector;
|
|
373
|
+
/**
|
|
374
|
+
* Skip operations matching at least one entry in the list.
|
|
375
|
+
*/
|
|
376
|
+
exclude?: Array<Exclude>;
|
|
377
|
+
/**
|
|
378
|
+
* Restrict generation to operations matching at least one entry in the list.
|
|
379
|
+
*/
|
|
380
|
+
include?: Array<Include>;
|
|
381
|
+
/**
|
|
382
|
+
* Apply a different options object to operations matching a pattern.
|
|
383
|
+
*/
|
|
384
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
385
|
+
/**
|
|
386
|
+
* Enables `useInfiniteQuery` hooks for cursor- or page-based pagination.
|
|
387
|
+
* Pass an object to configure how the cursor is read, or pass `false` to skip.
|
|
388
|
+
*
|
|
389
|
+
* @default false
|
|
390
|
+
*/
|
|
391
|
+
infinite?: Partial<Infinite> | false;
|
|
392
|
+
/**
|
|
393
|
+
* Adds `useSuspenseQuery` hooks alongside the regular `useQuery` ones.
|
|
394
|
+
* Pass an empty object (`{}`) to enable. TanStack Query v5+ only.
|
|
395
|
+
*
|
|
396
|
+
* @default false
|
|
397
|
+
*/
|
|
398
|
+
suspense?: Partial<Suspense> | false;
|
|
399
|
+
/**
|
|
400
|
+
* Custom `queryKey` builder. Use to add a version namespace, swap to
|
|
401
|
+
* operation IDs, or shape keys to match an existing invalidation strategy.
|
|
402
|
+
*/
|
|
403
|
+
queryKey?: QueryKey;
|
|
404
|
+
/**
|
|
405
|
+
* Configures query hooks. Set to `false` to skip generating hooks entirely
|
|
406
|
+
* and emit only `queryOptions(...)` helpers.
|
|
407
|
+
*/
|
|
408
|
+
query?: Partial<Query> | false;
|
|
409
|
+
/**
|
|
410
|
+
* Custom `mutationKey` builder. Useful when you batch invalidations or read
|
|
411
|
+
* mutation state via `useMutationState`.
|
|
412
|
+
*/
|
|
413
|
+
mutationKey?: MutationKey;
|
|
414
|
+
/**
|
|
415
|
+
* Configures mutation hooks. Set to `false` to skip mutation generation.
|
|
416
|
+
*/
|
|
417
|
+
mutation?: Partial<Mutation> | false;
|
|
418
|
+
/**
|
|
419
|
+
* Wires every generated hook through a user-supplied function that returns
|
|
420
|
+
* extra options (`onSuccess`, `onError`, `select`, ...). Also emits a
|
|
421
|
+
* `HookOptions` type so the wrapper stays in sync with generated hooks.
|
|
422
|
+
*/
|
|
423
|
+
customOptions?: CustomOptions;
|
|
424
|
+
/**
|
|
425
|
+
* Override how hook names and file paths are built. Methods you omit fall
|
|
426
|
+
* back to the default `resolverReactQuery`.
|
|
427
|
+
*/
|
|
428
|
+
resolver?: ResolverPatch<ResolverReactQuery>;
|
|
429
|
+
/**
|
|
430
|
+
* Set to `true` to also generate `use*` hook functions. By default only the
|
|
431
|
+
* `queryOptions`, `mutationOptions`, `queryKey`, and `mutationKey` helpers are
|
|
432
|
+
* emitted, using `@tanstack/react-query` factory imports (`queryOptions`,
|
|
433
|
+
* `infiniteQueryOptions`, `mutationOptions`) that are adapter-portable across
|
|
434
|
+
* React, Vue, Solid, and Svelte. Infinite, suspense, and `customOptions` output
|
|
435
|
+
* needs `hooks: true` too.
|
|
436
|
+
*
|
|
437
|
+
* @default false
|
|
438
|
+
*/
|
|
439
|
+
hooks?: boolean;
|
|
440
|
+
/**
|
|
441
|
+
* Macros applied to each operation node before printing.
|
|
442
|
+
*/
|
|
443
|
+
macros?: Array<ast.Macro>;
|
|
444
|
+
};
|
|
445
|
+
/**
|
|
446
|
+
* The resolved client strategy for the generated hooks, computed once during setup. The hooks always
|
|
447
|
+
* import and call a registered contract client plugin's `<op>`.
|
|
448
|
+
*/
|
|
449
|
+
type ResolvedClient = ResolvedContractClient;
|
|
450
|
+
type ResolvedOptions = {
|
|
451
|
+
output: Output;
|
|
452
|
+
group: Group | null;
|
|
453
|
+
exclude: NonNullable<Options['exclude']>;
|
|
454
|
+
include: Options['include'];
|
|
455
|
+
override: NonNullable<Options['override']>;
|
|
456
|
+
/**
|
|
457
|
+
* The resolved contract client the generators import and call.
|
|
458
|
+
*/
|
|
459
|
+
client: ResolvedClient;
|
|
460
|
+
/**
|
|
461
|
+
* Resolved infinite query configuration, or `false` when infinite queries are disabled.
|
|
462
|
+
*/
|
|
463
|
+
infinite: NonNullable<Infinite> | false;
|
|
464
|
+
suspense: Suspense | false;
|
|
465
|
+
queryKey: QueryKey | null;
|
|
466
|
+
query: NonNullable<Required<Query>> | false;
|
|
467
|
+
mutationKey: MutationKey | null;
|
|
468
|
+
mutation: NonNullable<Required<Mutation>> | false;
|
|
469
|
+
customOptions: NonNullable<Required<CustomOptions>> | null;
|
|
470
|
+
hooks: boolean;
|
|
471
|
+
resolver: ResolverReactQuery;
|
|
472
|
+
};
|
|
473
|
+
type PluginReactQuery = PluginType<'plugin-react-query', Options, ResolvedOptions, ResolverReactQuery>;
|
|
474
|
+
declare global {
|
|
475
|
+
namespace Kubb {
|
|
476
|
+
interface PluginRegistry {
|
|
477
|
+
'plugin-react-query': PluginReactQuery;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
//#endregion
|
|
482
|
+
//#region src/plugin.d.ts
|
|
483
|
+
/**
|
|
484
|
+
* Canonical plugin name for `@kubb/plugin-react-query`. Used for driver lookups
|
|
485
|
+
* and cross-plugin dependency references.
|
|
486
|
+
*/
|
|
487
|
+
export declare const pluginReactQueryName = "plugin-react-query";
|
|
488
|
+
/**
|
|
489
|
+
* Generates one TanStack Query hook per OpenAPI operation for React. Queries
|
|
490
|
+
* become `useFoo`, with `useFooSuspense` and `useFooInfinite` variants.
|
|
491
|
+
* Mutations become `useFoo`. Each hook is fully typed: query keys, input
|
|
492
|
+
* variables, response data, and error shape all come from the spec.
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* ```ts
|
|
496
|
+
* import { defineConfig } from 'kubb/config'
|
|
497
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
498
|
+
* import { pluginReactQuery } from '@kubb/plugin-react-query'
|
|
499
|
+
*
|
|
500
|
+
* export default defineConfig({
|
|
501
|
+
* input: './petStore.yaml',
|
|
502
|
+
* output: { path: './src/gen' },
|
|
503
|
+
* plugins: [
|
|
504
|
+
* pluginTs(),
|
|
505
|
+
* pluginReactQuery({
|
|
506
|
+
* output: { path: './hooks' },
|
|
507
|
+
* suspense: {},
|
|
508
|
+
* }),
|
|
509
|
+
* ],
|
|
510
|
+
* })
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
513
|
+
export declare const pluginReactQuery: import("kubb/kit").PluginFactory<PluginReactQuery>;
|
|
514
|
+
//#endregion
|
|
515
|
+
//#region src/resolvers/resolverReactQuery.d.ts
|
|
516
|
+
/**
|
|
517
|
+
* Default resolver used by `@kubb/plugin-react-query`. Decides the names and
|
|
518
|
+
* file paths for every generated TanStack Query hook (`useFoo`,
|
|
519
|
+
* `useFooSuspense`, `useFooInfinite`, ...) and its companion helpers
|
|
520
|
+
* (`fooQueryKey`, `fooQueryOptions`).
|
|
521
|
+
*
|
|
522
|
+
* Functions and files use the built-in camelCase casing; hooks get the `use`
|
|
523
|
+
* prefix; suspense and infinite variants are suffixed with `Suspense`/`Infinite`.
|
|
524
|
+
*
|
|
525
|
+
* @example Resolve hook and helper names
|
|
526
|
+
* ```ts
|
|
527
|
+
* import { resolverReactQuery } from '@kubb/plugin-react-query'
|
|
528
|
+
*
|
|
529
|
+
* resolverReactQuery.query.name(operationNode) // 'useGetPetById'
|
|
530
|
+
* resolverReactQuery.mutation.name(operationNode) // 'useUpdatePet'
|
|
531
|
+
* resolverReactQuery.query.keyName(operationNode) // 'getPetByIdQueryKey'
|
|
532
|
+
* resolverReactQuery.query.optionsName(operationNode) // 'getPetByIdQueryOptions'
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
export declare const resolverReactQuery: ResolverReactQuery;
|
|
536
|
+
//#endregion
|
|
537
|
+
export { type PageParamFn, type PluginReactQuery, type ResolverReactQuery, pluginReactQuery as default };
|
|
538
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Diagnostics, Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
1
|
+
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
3
2
|
import "@kubb/plugin-zod";
|
|
4
|
-
import "kubb/jsx";
|
|
5
3
|
import "@kubb/plugin-ts";
|
|
4
|
+
import "kubb/jsx";
|
|
6
5
|
//#region ../../internals/client/src/resolveClient.d.ts
|
|
7
6
|
/**
|
|
8
7
|
* The client selector accepted by a consumer's `client` option. Each calls a registered contract
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import "./rolldown-runtime-C0LytTxp.js";
|
|
2
1
|
import { Diagnostics, Resolver, Url, addGenerator, ast, createResolver, defineExtension, defineGenerator, setMacros, setResolver, useConfig } from "kubb/kit";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
import { File, Function, Type, jsxRenderer } from "kubb/jsx";
|
|
5
4
|
import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
6
5
|
import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
|
|
7
6
|
import fs from "node:fs";
|
|
7
|
+
//#endregion
|
|
8
8
|
//#region ../../internals/shared/src/operation.ts
|
|
9
9
|
/**
|
|
10
10
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
@@ -316,11 +316,11 @@ function createGroupConfig(group) {
|
|
|
316
316
|
//#region kubb-extension.json
|
|
317
317
|
var compatibility = {
|
|
318
318
|
"kubb": ">=5.8.3",
|
|
319
|
-
"node": ">=22"
|
|
319
|
+
"node": ">=22.12"
|
|
320
320
|
};
|
|
321
321
|
//#endregion
|
|
322
322
|
//#region package.json
|
|
323
|
-
var version = "5.5.
|
|
323
|
+
var version = "5.5.3";
|
|
324
324
|
//#endregion
|
|
325
325
|
//#region ../../internals/client/src/resolveClient.ts
|
|
326
326
|
/**
|
package/kubb-extension.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-react-query",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.3",
|
|
4
4
|
"description": "Generate type-safe TanStack Query (React Query) hooks with Kubb. Covers useQuery, useMutation, useInfiniteQuery, and queryOptions with full TypeScript support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"code-generation",
|
|
@@ -64,9 +64,14 @@
|
|
|
64
64
|
},
|
|
65
65
|
"exports": {
|
|
66
66
|
".": {
|
|
67
|
-
"
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
"import": {
|
|
68
|
+
"types": "./dist/index.d.ts",
|
|
69
|
+
"default": "./dist/index.js"
|
|
70
|
+
},
|
|
71
|
+
"require": {
|
|
72
|
+
"types": "./dist/index.d.cts",
|
|
73
|
+
"default": "./dist/index.cjs"
|
|
74
|
+
}
|
|
70
75
|
},
|
|
71
76
|
"./package.json": "./package.json",
|
|
72
77
|
"./kubb-extension.json": "./kubb-extension.json"
|
|
@@ -76,7 +81,7 @@
|
|
|
76
81
|
"registry": "https://registry.npmjs.org/"
|
|
77
82
|
},
|
|
78
83
|
"dependencies": {
|
|
79
|
-
"@kubb/plugin-ts": "^5.0.
|
|
84
|
+
"@kubb/plugin-ts": "^5.0.14"
|
|
80
85
|
},
|
|
81
86
|
"devDependencies": {
|
|
82
87
|
"@internals/client": "0.0.0",
|
|
@@ -84,11 +89,11 @@
|
|
|
84
89
|
"@internals/tanstack-query": "0.0.0",
|
|
85
90
|
"@internals/utils": "0.0.0",
|
|
86
91
|
"@tanstack/react-query": "^5.104.2",
|
|
87
|
-
"kubb": "^5.10.
|
|
92
|
+
"kubb": "^5.10.3"
|
|
88
93
|
},
|
|
89
94
|
"peerDependencies": {
|
|
90
95
|
"@tanstack/react-query": "^5.82.0",
|
|
91
|
-
"kubb": "^5.10.
|
|
96
|
+
"kubb": "^5.10.3"
|
|
92
97
|
},
|
|
93
98
|
"peerDependenciesMeta": {
|
|
94
99
|
"@tanstack/react-query": {
|
|
@@ -96,7 +101,7 @@
|
|
|
96
101
|
}
|
|
97
102
|
},
|
|
98
103
|
"engines": {
|
|
99
|
-
"node": ">=22"
|
|
104
|
+
"node": ">=22.12"
|
|
100
105
|
},
|
|
101
106
|
"scripts": {
|
|
102
107
|
"build": "tsdown",
|