@kubb/plugin-react-query 5.0.0-beta.80 → 5.0.0-beta.84
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 +152 -275
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -174
- package/dist/index.js +25 -148
- package/dist/index.js.map +1 -1
- package/package.json +4 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,161 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
-
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ast } from "
|
|
3
|
-
//#region ../../internals/client/src/types.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Validator applied to request and response bodies using schemas from `@kubb/plugin-zod`.
|
|
6
|
-
* - `false`: no validation.
|
|
7
|
-
* - `'zod'`: validates the success (2xx) response body, and the error body when a non-2xx call does
|
|
8
|
-
* not throw (`throwOnError: false`).
|
|
9
|
-
* - `{ request?: 'zod'; response?: 'zod' }`: opt in per direction. `request` validates the request
|
|
10
|
-
* body and query parameters before the call; `response` validates the success response body and,
|
|
11
|
-
* on the non-throw path, the error body.
|
|
12
|
-
*/
|
|
13
|
-
type ValidatorOptions = false | 'zod' | {
|
|
14
|
-
request?: 'zod';
|
|
15
|
-
response?: 'zod';
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* How the class-based SDK groups operations.
|
|
19
|
-
* - `'tag'`: one class per tag, optionally composed into a root client.
|
|
20
|
-
* - `'flat'`: one class with every operation as a direct method.
|
|
21
|
-
*/
|
|
22
|
-
type Mode = 'tag' | 'flat';
|
|
23
|
-
/**
|
|
24
|
-
* The resolver shared by the client plugins. Functions and files use camelCase; URL helpers get
|
|
25
|
-
* a `get<Operation>Url` name.
|
|
26
|
-
*/
|
|
27
|
-
type ResolverClient = Resolver & {
|
|
28
|
-
/**
|
|
29
|
-
* Resolves the function name for a raw operation name.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* `resolver.resolveName('show pet by id') // -> 'showPetById'`
|
|
33
|
-
*/
|
|
34
|
-
resolveName(this: ResolverClient, name: string): string;
|
|
35
|
-
/**
|
|
36
|
-
* Resolves the output file name for a generated client module.
|
|
37
|
-
*/
|
|
38
|
-
resolvePathName(this: ResolverClient, name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
|
|
39
|
-
/**
|
|
40
|
-
* Resolves the generated class name for class-based clients.
|
|
41
|
-
*/
|
|
42
|
-
resolveClassName(this: ResolverClient, name: string): string;
|
|
43
|
-
/**
|
|
44
|
-
* Resolves the generated class name for a tag-based client group. The default appends a
|
|
45
|
-
* `Client` suffix (tag `pet` becomes `PetClient`) so the class never collides with the schema
|
|
46
|
-
* model of the same name in the barrel.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* `resolver.resolveGroupName('pet') // -> 'PetClient'`
|
|
50
|
-
*/
|
|
51
|
-
resolveGroupName(this: ResolverClient, name: string): string;
|
|
52
|
-
/**
|
|
53
|
-
* Resolves the property name a tag client is exposed under on the composed root SDK
|
|
54
|
-
* (`new PetStore(config).pet`).
|
|
55
|
-
*/
|
|
56
|
-
resolveClientPropertyName(this: ResolverClient, name: string): string;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* The shared options surface for the client plugins. Deliberately small: there is one
|
|
60
|
-
* response contract and one grouped options object. Each plugin extends this with its own
|
|
61
|
-
* `transport` field.
|
|
62
|
-
*/
|
|
63
|
-
type Options$1 = OutputOptions & {
|
|
64
|
-
/**
|
|
65
|
-
* Skip operations matching at least one entry in the list.
|
|
66
|
-
*/
|
|
67
|
-
exclude?: Array<Exclude>;
|
|
68
|
-
/**
|
|
69
|
-
* Restrict generation to operations matching at least one entry in the list.
|
|
70
|
-
*/
|
|
71
|
-
include?: Array<Include>;
|
|
72
|
-
/**
|
|
73
|
-
* Apply a different options object to operations matching a pattern.
|
|
74
|
-
*/
|
|
75
|
-
override?: Array<Override<ResolvedOptions$1>>;
|
|
76
|
-
/**
|
|
77
|
-
* Base URL prepended to every request. When omitted, falls back to the adapter's server URL.
|
|
78
|
-
*/
|
|
79
|
-
baseURL?: string;
|
|
80
|
-
/**
|
|
81
|
-
* Validate request and response bodies with schemas from `@kubb/plugin-zod`.
|
|
82
|
-
*
|
|
83
|
-
* @default false
|
|
84
|
-
*/
|
|
85
|
-
validator?: ValidatorOptions;
|
|
86
|
-
/**
|
|
87
|
-
* Generates a class-based SDK instead of the standalone functions. Each tag client is an instance
|
|
88
|
-
* class whose constructor takes a client config and builds its own client, so every environment is
|
|
89
|
-
* a separate instance. Leave `sdk` unset to keep the standalone per-operation functions (the
|
|
90
|
-
* default), which is also what query plugins consume.
|
|
91
|
-
*
|
|
92
|
-
* @example Instance class per tag
|
|
93
|
-
* ```ts
|
|
94
|
-
* pluginFetch({ sdk: {} })
|
|
95
|
-
* // const api = new PetClient({ baseURL: 'https://api.example.com' })
|
|
96
|
-
* // await api.getPetById({ path: { petId: 1 } })
|
|
97
|
-
* ```
|
|
98
|
-
* @example Composed root that instantiates every tag client from one config
|
|
99
|
-
* ```ts
|
|
100
|
-
* pluginFetch({ sdk: { name: 'petStore' } })
|
|
101
|
-
* // class PetStore {
|
|
102
|
-
* // readonly pet: PetClient
|
|
103
|
-
* // readonly store: StoreClient
|
|
104
|
-
* // constructor(config = {}) { ... }
|
|
105
|
-
* // }
|
|
106
|
-
* // const api = new PetStore({ baseURL })
|
|
107
|
-
* // await api.pet.getPetById({ path: { petId: 1 } })
|
|
108
|
-
* ```
|
|
109
|
-
* @example Flat class with every operation as a direct method
|
|
110
|
-
* ```ts
|
|
111
|
-
* pluginFetch({ sdk: { name: 'petStore', mode: 'flat' } })
|
|
112
|
-
* // const api = new PetStore({ baseURL })
|
|
113
|
-
* // await api.getPetById({ path: { petId: 1 } })
|
|
114
|
-
* ```
|
|
115
|
-
*/
|
|
116
|
-
sdk?: {
|
|
117
|
-
/**
|
|
118
|
-
* How the SDK groups operations.
|
|
119
|
-
* - `'tag'`: one class per tag. With `name`, a composed root instantiates every tag client.
|
|
120
|
-
* - `'flat'`: one class named by `name`, with every operation as a direct method.
|
|
121
|
-
*
|
|
122
|
-
* @default 'tag'
|
|
123
|
-
*/
|
|
124
|
-
mode?: Mode;
|
|
125
|
-
/**
|
|
126
|
-
* Name of the generated entry point, also the file name. With `mode: 'tag'` it emits a
|
|
127
|
-
* composed root class that instantiates every tag client from one shared config. With
|
|
128
|
-
* `mode: 'flat'` it names the single class.
|
|
129
|
-
*/
|
|
130
|
-
name?: string;
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* Override how names and file paths are built. Methods you omit fall back to the default resolver.
|
|
134
|
-
*/
|
|
135
|
-
resolver?: Partial<ResolverClient> & ThisType<ResolverClient>;
|
|
136
|
-
/**
|
|
137
|
-
* Macros applied to each operation node before code is printed.
|
|
138
|
-
*/
|
|
139
|
-
macros?: Array<ast.Macro>;
|
|
140
|
-
};
|
|
141
|
-
/**
|
|
142
|
-
* The resolved options after defaults are applied.
|
|
143
|
-
*/
|
|
144
|
-
type ResolvedOptions$1 = {
|
|
145
|
-
output: Output;
|
|
146
|
-
exclude: Array<Exclude>;
|
|
147
|
-
include: Array<Include> | undefined;
|
|
148
|
-
override: Array<Override<ResolvedOptions$1>>;
|
|
149
|
-
group: Group | null;
|
|
150
|
-
baseURL: Options$1['baseURL'];
|
|
151
|
-
validator: NonNullable<Options$1['validator']>;
|
|
152
|
-
sdk: {
|
|
153
|
-
mode: Mode;
|
|
154
|
-
name: string | undefined;
|
|
155
|
-
} | undefined;
|
|
156
|
-
resolver: ResolverClient;
|
|
157
|
-
};
|
|
158
|
-
//#endregion
|
|
2
|
+
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ast } from "kubb/kit";
|
|
159
3
|
//#region ../../internals/client/src/resolveClient.d.ts
|
|
160
4
|
/**
|
|
161
5
|
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
@@ -326,7 +170,7 @@ type Query = {
|
|
|
326
170
|
* HTTP methods treated as queries. Operations using these methods produce
|
|
327
171
|
* `useQuery`-style hooks.
|
|
328
172
|
*
|
|
329
|
-
* @default ['
|
|
173
|
+
* @default ['GET']
|
|
330
174
|
*/
|
|
331
175
|
methods?: Array<string>;
|
|
332
176
|
/**
|
|
@@ -343,7 +187,7 @@ type Mutation = {
|
|
|
343
187
|
* HTTP methods treated as mutations. Operations using these methods produce
|
|
344
188
|
* `useMutation`-style hooks.
|
|
345
189
|
*
|
|
346
|
-
* @default ['
|
|
190
|
+
* @default ['POST', 'PUT', 'PATCH', 'DELETE']
|
|
347
191
|
*/
|
|
348
192
|
methods?: Array<string>;
|
|
349
193
|
/**
|
|
@@ -387,8 +231,8 @@ type Infinite = {
|
|
|
387
231
|
};
|
|
388
232
|
type CustomOptions = {
|
|
389
233
|
/**
|
|
390
|
-
* Module specifier of your custom-options hook. Imported as
|
|
391
|
-
* `import ${name} from '${importPath}'`.
|
|
234
|
+
* Module specifier of your custom-options hook. Imported as a named import,
|
|
235
|
+
* `import { ${name} } from '${importPath}'`.
|
|
392
236
|
*/
|
|
393
237
|
importPath: string;
|
|
394
238
|
/**
|
|
@@ -430,7 +274,7 @@ type Options = OutputOptions & {
|
|
|
430
274
|
override?: Array<Override<ResolvedOptions>>;
|
|
431
275
|
/**
|
|
432
276
|
* Enables `useInfiniteQuery` hooks for cursor- or page-based pagination.
|
|
433
|
-
* Pass an object to configure how the cursor is read
|
|
277
|
+
* Pass an object to configure how the cursor is read, or pass `false` to skip.
|
|
434
278
|
*
|
|
435
279
|
* @default false
|
|
436
280
|
*/
|
|
@@ -465,12 +309,6 @@ type Options = OutputOptions & {
|
|
|
465
309
|
* `HookOptions` type so the wrapper stays in sync with generated hooks.
|
|
466
310
|
*/
|
|
467
311
|
customOptions?: CustomOptions;
|
|
468
|
-
/**
|
|
469
|
-
* Validator applied to response bodies before they reach the caller.
|
|
470
|
-
* - `'client'` — no validation. Trusts the API.
|
|
471
|
-
* - `'zod'` — pipes responses through schemas from `@kubb/plugin-zod`.
|
|
472
|
-
*/
|
|
473
|
-
validator?: Options$1['validator'];
|
|
474
312
|
/**
|
|
475
313
|
* Override how hook names and file paths are built. Methods you omit fall
|
|
476
314
|
* back to the default `resolverReactQuery`.
|
|
@@ -509,9 +347,8 @@ type ResolvedOptions = {
|
|
|
509
347
|
* The resolved contract client the generators import and call.
|
|
510
348
|
*/
|
|
511
349
|
client: ResolvedClient;
|
|
512
|
-
validator: NonNullable<Options['validator']>;
|
|
513
350
|
/**
|
|
514
|
-
*
|
|
351
|
+
* Resolved infinite query configuration, or `false` when infinite queries are disabled.
|
|
515
352
|
*/
|
|
516
353
|
infinite: NonNullable<Infinite> | false;
|
|
517
354
|
suspense: Suspense | false;
|
|
@@ -540,13 +377,13 @@ declare global {
|
|
|
540
377
|
declare const pluginReactQueryName = "plugin-react-query";
|
|
541
378
|
/**
|
|
542
379
|
* Generates one TanStack Query hook per OpenAPI operation for React. Queries
|
|
543
|
-
* become `
|
|
544
|
-
* become `
|
|
380
|
+
* become `useFoo`, with `useFooSuspense` and `useFooInfinite` variants.
|
|
381
|
+
* Mutations become `useFoo`. Each hook is fully typed: query keys, input
|
|
545
382
|
* variables, response data, and error shape all come from the spec.
|
|
546
383
|
*
|
|
547
384
|
* @example
|
|
548
385
|
* ```ts
|
|
549
|
-
* import { defineConfig } from 'kubb'
|
|
386
|
+
* import { defineConfig } from 'kubb/config'
|
|
550
387
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
551
388
|
* import { pluginReactQuery } from '@kubb/plugin-react-query'
|
|
552
389
|
*
|
|
@@ -563,7 +400,7 @@ declare const pluginReactQueryName = "plugin-react-query";
|
|
|
563
400
|
* })
|
|
564
401
|
* ```
|
|
565
402
|
*/
|
|
566
|
-
declare const pluginReactQuery: (options?: Options | undefined) => import("
|
|
403
|
+
declare const pluginReactQuery: (options?: Options | undefined) => import("kubb/kit").Plugin<PluginReactQuery>;
|
|
567
404
|
//#endregion
|
|
568
405
|
export { type PluginReactQuery, pluginReactQuery as default, pluginReactQuery, pluginReactQueryName };
|
|
569
406
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import "./rolldown-runtime-C0LytTxp.js";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { ast, defineGenerator, definePlugin, defineResolver } from "
|
|
3
|
+
import { ast, defineGenerator, definePlugin, defineResolver } from "kubb/kit";
|
|
4
4
|
import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
5
|
+
import { File, Function, Type, jsxRenderer } from "kubb/jsx";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
|
|
8
7
|
import fs from "node:fs";
|
|
9
|
-
import { getNestedAccessor } from "@kubb/ast/utils";
|
|
10
8
|
//#region ../../internals/utils/src/casing.ts
|
|
11
9
|
/**
|
|
12
10
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -530,16 +528,6 @@ function createGroupConfig(group) {
|
|
|
530
528
|
};
|
|
531
529
|
}
|
|
532
530
|
//#endregion
|
|
533
|
-
//#region ../../internals/client/src/builders/validatorOptions.ts
|
|
534
|
-
/**
|
|
535
|
-
* Returns `true` when any direction of the validator uses zod (used for dependency checks).
|
|
536
|
-
*/
|
|
537
|
-
function isValidatorEnabled(validator) {
|
|
538
|
-
if (!validator) return false;
|
|
539
|
-
if (validator === "zod") return true;
|
|
540
|
-
return Boolean(validator.request || validator.response);
|
|
541
|
-
}
|
|
542
|
-
//#endregion
|
|
543
531
|
//#region ../../internals/client/src/resolveClient.ts
|
|
544
532
|
/**
|
|
545
533
|
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
@@ -782,51 +770,6 @@ function resolveOperationOverrides(node, override) {
|
|
|
782
770
|
return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
|
|
783
771
|
}
|
|
784
772
|
/**
|
|
785
|
-
* Returns `'zod'` when response-direction parsing is enabled.
|
|
786
|
-
* The string shorthand `'zod'` also enables response parsing.
|
|
787
|
-
*/
|
|
788
|
-
function resolveResponseParser(parser) {
|
|
789
|
-
if (!parser) return null;
|
|
790
|
-
if (parser === "zod") return "zod";
|
|
791
|
-
return parser.response ?? null;
|
|
792
|
-
}
|
|
793
|
-
/**
|
|
794
|
-
* Returns `'zod'` when request body parsing is enabled.
|
|
795
|
-
* The string shorthand `'zod'` also enables request body parsing (existing behavior).
|
|
796
|
-
*/
|
|
797
|
-
function resolveRequestParser(parser) {
|
|
798
|
-
if (!parser) return null;
|
|
799
|
-
if (parser === "zod") return "zod";
|
|
800
|
-
return parser.request ?? null;
|
|
801
|
-
}
|
|
802
|
-
/**
|
|
803
|
-
* Returns `'zod'` when query-params parsing is enabled.
|
|
804
|
-
* Only the object form `{ request: 'zod' }` enables this. `parser: 'zod'` does not.
|
|
805
|
-
*/
|
|
806
|
-
function resolveQueryParamsParser(parser) {
|
|
807
|
-
if (!parser || parser === "zod") return null;
|
|
808
|
-
return parser.request ?? null;
|
|
809
|
-
}
|
|
810
|
-
/**
|
|
811
|
-
* Collects the Zod schema import names for an operation based on the active parser directions.
|
|
812
|
-
*
|
|
813
|
-
* - `parser: 'zod'`: response and request body names (backward-compatible behavior).
|
|
814
|
-
* - `parser: { request: 'zod' }`: request body and query params names.
|
|
815
|
-
* - `parser: { response: 'zod' }`: response name only.
|
|
816
|
-
* - `parser: { request: 'zod', response: 'zod' }`: all three.
|
|
817
|
-
*
|
|
818
|
-
* Returns an empty array when no resolver is provided or `parser` is falsy.
|
|
819
|
-
*/
|
|
820
|
-
function resolveZodSchemaNames(node, zodResolver, parser) {
|
|
821
|
-
if (!zodResolver || !parser) return [];
|
|
822
|
-
const { query: queryParams } = getOperationParameters(node, { paramsCasing: "original" });
|
|
823
|
-
return [
|
|
824
|
-
resolveResponseParser(parser) === "zod" ? zodResolver.resolveResponseName?.(node) : null,
|
|
825
|
-
resolveRequestParser(parser) === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null,
|
|
826
|
-
resolveQueryParamsParser(parser) === "zod" && queryParams.length > 0 ? zodResolver.resolveQueryParamsName?.(node, queryParams[0]) : null
|
|
827
|
-
].filter((n) => Boolean(n));
|
|
828
|
-
}
|
|
829
|
-
/**
|
|
830
773
|
* Build QueryKey params as the grouped `{ path, query, body }` object (NO headers, NO config),
|
|
831
774
|
* typed from the operation's `RequestConfig` minus `url`. The query key transformer reads the
|
|
832
775
|
* grouped `path`/`query`/`body` bindings.
|
|
@@ -1317,8 +1260,8 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
1317
1260
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
1318
1261
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
1319
1262
|
if (hasNewParams) {
|
|
1320
|
-
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
1321
|
-
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
1263
|
+
const nextAccessor = nextParam ? ast.getNestedAccessor(nextParam, "lastPage") : null;
|
|
1264
|
+
const prevAccessor = previousParam ? ast.getNestedAccessor(previousParam, "firstPage") : null;
|
|
1322
1265
|
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
1323
1266
|
}
|
|
1324
1267
|
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
@@ -1677,8 +1620,8 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1677
1620
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
1678
1621
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
1679
1622
|
if (hasNewParams) {
|
|
1680
|
-
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
1681
|
-
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
1623
|
+
const nextAccessor = nextParam ? ast.getNestedAccessor(nextParam, "lastPage") : null;
|
|
1624
|
+
const prevAccessor = previousParam ? ast.getNestedAccessor(previousParam, "firstPage") : null;
|
|
1682
1625
|
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
1683
1626
|
}
|
|
1684
1627
|
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
@@ -1816,7 +1759,7 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1816
1759
|
operation(node, ctx) {
|
|
1817
1760
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
1818
1761
|
const { config, driver, resolver, root } = ctx;
|
|
1819
|
-
const { output, query, mutation, infinite,
|
|
1762
|
+
const { output, query, mutation, infinite, client, group, customOptions, hooks } = ctx.options;
|
|
1820
1763
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1821
1764
|
if (!pluginTs) return null;
|
|
1822
1765
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -1866,14 +1809,6 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1866
1809
|
includeParams: false
|
|
1867
1810
|
})
|
|
1868
1811
|
].filter((name) => Boolean(name));
|
|
1869
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(pluginZodName) : null;
|
|
1870
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
1871
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1872
|
-
root,
|
|
1873
|
-
output: pluginZod?.options?.output ?? output,
|
|
1874
|
-
group: pluginZod?.options?.group ?? void 0
|
|
1875
|
-
}) : null;
|
|
1876
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
1877
1812
|
const calledClientName = contractOp.name;
|
|
1878
1813
|
return /* @__PURE__ */ jsxs(File, {
|
|
1879
1814
|
baseName: meta.file.baseName,
|
|
@@ -1896,11 +1831,6 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1896
1831
|
}
|
|
1897
1832
|
}),
|
|
1898
1833
|
children: [
|
|
1899
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
1900
|
-
name: zodSchemaNames,
|
|
1901
|
-
root: meta.file.path,
|
|
1902
|
-
path: fileZod.path
|
|
1903
|
-
}),
|
|
1904
1834
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1905
1835
|
name: [contractOp.name],
|
|
1906
1836
|
root: meta.file.path,
|
|
@@ -1994,7 +1924,7 @@ const mutationGenerator = defineGenerator({
|
|
|
1994
1924
|
operation(node, ctx) {
|
|
1995
1925
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
1996
1926
|
const { config, driver, resolver, root } = ctx;
|
|
1997
|
-
const { output, query, mutation,
|
|
1927
|
+
const { output, query, mutation, client, group, customOptions, hooks } = ctx.options;
|
|
1998
1928
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1999
1929
|
if (!pluginTs) return null;
|
|
2000
1930
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -2030,14 +1960,6 @@ const mutationGenerator = defineGenerator({
|
|
|
2030
1960
|
order: "body-response-first",
|
|
2031
1961
|
includeParams: false
|
|
2032
1962
|
})].filter((name) => Boolean(name));
|
|
2033
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(pluginZodName) : null;
|
|
2034
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
2035
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
2036
|
-
root,
|
|
2037
|
-
output: pluginZod?.options?.output ?? output,
|
|
2038
|
-
group: pluginZod?.options?.group ?? void 0
|
|
2039
|
-
}) : null;
|
|
2040
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
2041
1963
|
const calledClientName = contractOp.name;
|
|
2042
1964
|
return /* @__PURE__ */ jsxs(File, {
|
|
2043
1965
|
baseName: meta.file.baseName,
|
|
@@ -2060,11 +1982,6 @@ const mutationGenerator = defineGenerator({
|
|
|
2060
1982
|
}
|
|
2061
1983
|
}),
|
|
2062
1984
|
children: [
|
|
2063
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
2064
|
-
name: zodSchemaNames,
|
|
2065
|
-
root: meta.file.path,
|
|
2066
|
-
path: fileZod.path
|
|
2067
|
-
}),
|
|
2068
1985
|
/* @__PURE__ */ jsx(File.Import, {
|
|
2069
1986
|
name: [contractOp.name],
|
|
2070
1987
|
root: meta.file.path,
|
|
@@ -2143,7 +2060,7 @@ const queryGenerator = defineGenerator({
|
|
|
2143
2060
|
operation(node, ctx) {
|
|
2144
2061
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
2145
2062
|
const { config, driver, resolver, root } = ctx;
|
|
2146
|
-
const { output, query, mutation,
|
|
2063
|
+
const { output, query, mutation, client, group, customOptions, hooks } = ctx.options;
|
|
2147
2064
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
2148
2065
|
if (!pluginTs) return null;
|
|
2149
2066
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -2181,14 +2098,6 @@ const queryGenerator = defineGenerator({
|
|
|
2181
2098
|
order: "body-response-first",
|
|
2182
2099
|
includeParams: false
|
|
2183
2100
|
})].filter((name) => Boolean(name));
|
|
2184
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(pluginZodName) : null;
|
|
2185
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
2186
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
2187
|
-
root,
|
|
2188
|
-
output: pluginZod?.options?.output ?? output,
|
|
2189
|
-
group: pluginZod?.options?.group ?? void 0
|
|
2190
|
-
}) : null;
|
|
2191
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
2192
2101
|
const calledClientName = contractOp.name;
|
|
2193
2102
|
return /* @__PURE__ */ jsxs(File, {
|
|
2194
2103
|
baseName: meta.file.baseName,
|
|
@@ -2211,11 +2120,6 @@ const queryGenerator = defineGenerator({
|
|
|
2211
2120
|
}
|
|
2212
2121
|
}),
|
|
2213
2122
|
children: [
|
|
2214
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
2215
|
-
name: zodSchemaNames,
|
|
2216
|
-
root: meta.file.path,
|
|
2217
|
-
path: fileZod.path
|
|
2218
|
-
}),
|
|
2219
2123
|
/* @__PURE__ */ jsx(File.Import, {
|
|
2220
2124
|
name: [contractOp.name],
|
|
2221
2125
|
root: meta.file.path,
|
|
@@ -2289,7 +2193,7 @@ const queryGenerator = defineGenerator({
|
|
|
2289
2193
|
/**
|
|
2290
2194
|
* Built-in generator for `useSuspenseInfiniteQuery` hooks. Enabled when both
|
|
2291
2195
|
* `suspense` and `infinite` are configured. Combines suspense semantics with
|
|
2292
|
-
* cursor-based pagination
|
|
2196
|
+
* cursor-based pagination. Handlers throw promises while loading and pull
|
|
2293
2197
|
* additional pages on demand.
|
|
2294
2198
|
*/
|
|
2295
2199
|
const suspenseInfiniteQueryGenerator = defineGenerator({
|
|
@@ -2298,7 +2202,7 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
|
|
|
2298
2202
|
operation(node, ctx) {
|
|
2299
2203
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
2300
2204
|
const { config, driver, resolver, root } = ctx;
|
|
2301
|
-
const { output, query, mutation, infinite, suspense,
|
|
2205
|
+
const { output, query, mutation, infinite, suspense, client, group, customOptions, hooks } = ctx.options;
|
|
2302
2206
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
2303
2207
|
if (!pluginTs) return null;
|
|
2304
2208
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -2348,14 +2252,6 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
|
|
|
2348
2252
|
includeParams: false
|
|
2349
2253
|
})
|
|
2350
2254
|
].filter((name) => Boolean(name));
|
|
2351
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(pluginZodName) : null;
|
|
2352
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
2353
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
2354
|
-
root,
|
|
2355
|
-
output: pluginZod?.options?.output ?? output,
|
|
2356
|
-
group: pluginZod?.options?.group ?? void 0
|
|
2357
|
-
}) : null;
|
|
2358
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
2359
2255
|
const calledClientName = contractOp.name;
|
|
2360
2256
|
return /* @__PURE__ */ jsxs(File, {
|
|
2361
2257
|
baseName: meta.file.baseName,
|
|
@@ -2378,11 +2274,6 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
|
|
|
2378
2274
|
}
|
|
2379
2275
|
}),
|
|
2380
2276
|
children: [
|
|
2381
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
2382
|
-
name: zodSchemaNames,
|
|
2383
|
-
root: meta.file.path,
|
|
2384
|
-
path: fileZod.path
|
|
2385
|
-
}),
|
|
2386
2277
|
/* @__PURE__ */ jsx(File.Import, {
|
|
2387
2278
|
name: [contractOp.name],
|
|
2388
2279
|
root: meta.file.path,
|
|
@@ -2477,7 +2368,7 @@ const suspenseQueryGenerator = defineGenerator({
|
|
|
2477
2368
|
operation(node, ctx) {
|
|
2478
2369
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
2479
2370
|
const { config, driver, resolver, root } = ctx;
|
|
2480
|
-
const { output, query, mutation, suspense,
|
|
2371
|
+
const { output, query, mutation, suspense, client, group, customOptions, hooks } = ctx.options;
|
|
2481
2372
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
2482
2373
|
if (!pluginTs) return null;
|
|
2483
2374
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -2515,14 +2406,6 @@ const suspenseQueryGenerator = defineGenerator({
|
|
|
2515
2406
|
order: "body-response-first",
|
|
2516
2407
|
includeParams: false
|
|
2517
2408
|
})].filter((name) => Boolean(name));
|
|
2518
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(pluginZodName) : null;
|
|
2519
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
2520
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
2521
|
-
root,
|
|
2522
|
-
output: pluginZod?.options?.output ?? output,
|
|
2523
|
-
group: pluginZod?.options?.group ?? void 0
|
|
2524
|
-
}) : null;
|
|
2525
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
2526
2409
|
const calledClientName = contractOp.name;
|
|
2527
2410
|
return /* @__PURE__ */ jsxs(File, {
|
|
2528
2411
|
baseName: meta.file.baseName,
|
|
@@ -2545,11 +2428,6 @@ const suspenseQueryGenerator = defineGenerator({
|
|
|
2545
2428
|
}
|
|
2546
2429
|
}),
|
|
2547
2430
|
children: [
|
|
2548
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
2549
|
-
name: zodSchemaNames,
|
|
2550
|
-
root: meta.file.path,
|
|
2551
|
-
path: fileZod.path
|
|
2552
|
-
}),
|
|
2553
2431
|
/* @__PURE__ */ jsx(File.Import, {
|
|
2554
2432
|
name: [contractOp.name],
|
|
2555
2433
|
root: meta.file.path,
|
|
@@ -2625,8 +2503,8 @@ function capitalize(name) {
|
|
|
2625
2503
|
}
|
|
2626
2504
|
/**
|
|
2627
2505
|
* Default resolver used by `@kubb/plugin-react-query`. Decides the names and
|
|
2628
|
-
* file paths for every generated TanStack Query hook (`
|
|
2629
|
-
* `
|
|
2506
|
+
* file paths for every generated TanStack Query hook (`useFoo`,
|
|
2507
|
+
* `useFooSuspense`, `useFooInfinite`, ...) and its companion helpers
|
|
2630
2508
|
* (`fooQueryKey`, `fooQueryOptions`).
|
|
2631
2509
|
*
|
|
2632
2510
|
* Functions and files use camelCase; hooks get the `use` prefix; suspense and
|
|
@@ -2742,13 +2620,13 @@ const resolverReactQuery = defineResolver(() => ({
|
|
|
2742
2620
|
const pluginReactQueryName = "plugin-react-query";
|
|
2743
2621
|
/**
|
|
2744
2622
|
* Generates one TanStack Query hook per OpenAPI operation for React. Queries
|
|
2745
|
-
* become `
|
|
2746
|
-
* become `
|
|
2623
|
+
* become `useFoo`, with `useFooSuspense` and `useFooInfinite` variants.
|
|
2624
|
+
* Mutations become `useFoo`. Each hook is fully typed: query keys, input
|
|
2747
2625
|
* variables, response data, and error shape all come from the spec.
|
|
2748
2626
|
*
|
|
2749
2627
|
* @example
|
|
2750
2628
|
* ```ts
|
|
2751
|
-
* import { defineConfig } from 'kubb'
|
|
2629
|
+
* import { defineConfig } from 'kubb/config'
|
|
2752
2630
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
2753
2631
|
* import { pluginReactQuery } from '@kubb/plugin-react-query'
|
|
2754
2632
|
*
|
|
@@ -2769,7 +2647,7 @@ const pluginReactQuery = definePlugin((options) => {
|
|
|
2769
2647
|
const { output = {
|
|
2770
2648
|
path: "hooks",
|
|
2771
2649
|
barrel: { type: "named" }
|
|
2772
|
-
}, group, exclude = [], include, override = [],
|
|
2650
|
+
}, group, exclude = [], include, override = [], suspense = {}, infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, customOptions, hooks = false, client, resolver: userResolver, macros: userMacros } = options;
|
|
2773
2651
|
const selectedGenerators = [
|
|
2774
2652
|
queryGenerator,
|
|
2775
2653
|
suspenseQueryGenerator,
|
|
@@ -2783,7 +2661,7 @@ const pluginReactQuery = definePlugin((options) => {
|
|
|
2783
2661
|
return {
|
|
2784
2662
|
name: pluginReactQueryName,
|
|
2785
2663
|
options,
|
|
2786
|
-
dependencies: [pluginTsName
|
|
2664
|
+
dependencies: [pluginTsName],
|
|
2787
2665
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
2788
2666
|
const resolver = userResolver ? {
|
|
2789
2667
|
...resolverReactQuery,
|
|
@@ -2804,17 +2682,17 @@ const pluginReactQuery = definePlugin((options) => {
|
|
|
2804
2682
|
queryKey,
|
|
2805
2683
|
query: query === false ? false : {
|
|
2806
2684
|
importPath: "@tanstack/react-query",
|
|
2807
|
-
methods: ["
|
|
2685
|
+
methods: ["GET"],
|
|
2808
2686
|
...query
|
|
2809
2687
|
},
|
|
2810
2688
|
mutationKey,
|
|
2811
2689
|
mutation: mutation === false ? false : {
|
|
2812
2690
|
importPath: "@tanstack/react-query",
|
|
2813
2691
|
methods: [
|
|
2814
|
-
"
|
|
2815
|
-
"
|
|
2816
|
-
"
|
|
2817
|
-
"
|
|
2692
|
+
"POST",
|
|
2693
|
+
"PUT",
|
|
2694
|
+
"PATCH",
|
|
2695
|
+
"DELETE"
|
|
2818
2696
|
],
|
|
2819
2697
|
...mutation
|
|
2820
2698
|
},
|
|
@@ -2832,7 +2710,6 @@ const pluginReactQuery = definePlugin((options) => {
|
|
|
2832
2710
|
...customOptions
|
|
2833
2711
|
} : null,
|
|
2834
2712
|
hooks,
|
|
2835
|
-
validator,
|
|
2836
2713
|
group: groupConfig,
|
|
2837
2714
|
exclude,
|
|
2838
2715
|
include,
|