@kubb/plugin-vue-query 5.0.0-beta.80 → 5.0.0-beta.81
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 +99 -195
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -168
- package/dist/index.js +99 -195
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,161 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
2
|
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
|
|
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
|
|
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
|
|
@@ -179,6 +23,10 @@ type ResolvedOptions$1 = {
|
|
|
179
23
|
type ClientSelector = 'fetch' | 'axios';
|
|
180
24
|
//#endregion
|
|
181
25
|
//#region src/types.d.ts
|
|
26
|
+
/**
|
|
27
|
+
* Builds the parts of a query or mutation key for one operation. Receives the operation node and
|
|
28
|
+
* the resolved `paramsCasing` setting and returns the key elements in order.
|
|
29
|
+
*/
|
|
182
30
|
type Transformer = (props: {
|
|
183
31
|
node: ast.OperationNode;
|
|
184
32
|
casing: 'camelcase' | undefined;
|
|
@@ -281,7 +129,7 @@ type Mutation = {
|
|
|
281
129
|
/**
|
|
282
130
|
* HTTP methods treated as mutations.
|
|
283
131
|
*
|
|
284
|
-
* @default ['post', 'put', 'delete']
|
|
132
|
+
* @default ['post', 'put', 'patch', 'delete']
|
|
285
133
|
*/
|
|
286
134
|
methods?: Array<string>;
|
|
287
135
|
/**
|
|
@@ -355,7 +203,7 @@ type Options = OutputOptions & {
|
|
|
355
203
|
override?: Array<Override<ResolvedOptions>>;
|
|
356
204
|
/**
|
|
357
205
|
* Enables `useInfiniteQuery` composables for cursor- or page-based pagination.
|
|
358
|
-
* Pass an object to configure how the cursor is read
|
|
206
|
+
* Pass an object to configure how the cursor is read, or pass `false` to skip.
|
|
359
207
|
*
|
|
360
208
|
* @default false
|
|
361
209
|
*/
|
|
@@ -377,19 +225,13 @@ type Options = OutputOptions & {
|
|
|
377
225
|
* Configures mutation composables. Set to `false` to skip mutation generation.
|
|
378
226
|
*/
|
|
379
227
|
mutation?: Partial<Mutation> | false;
|
|
380
|
-
/**
|
|
381
|
-
* Validator applied to response bodies before they reach the caller.
|
|
382
|
-
* - `'client'` — no validation.
|
|
383
|
-
* - `'zod'` — pipes responses through schemas from `@kubb/plugin-zod`.
|
|
384
|
-
*/
|
|
385
|
-
validator?: Options$1['validator'];
|
|
386
228
|
/**
|
|
387
229
|
* Override how composable names and file paths are built.
|
|
388
230
|
*/
|
|
389
231
|
resolver?: Partial<ResolverVueQuery> & ThisType<ResolverVueQuery>;
|
|
390
232
|
/**
|
|
391
233
|
* Set to `false` to skip generating `use*` composable functions. `queryOptions`,
|
|
392
|
-
* `
|
|
234
|
+
* `queryKey`, and `mutationKey` helpers are still emitted.
|
|
393
235
|
*
|
|
394
236
|
* @default false
|
|
395
237
|
*/
|
|
@@ -417,9 +259,8 @@ type ResolvedOptions = {
|
|
|
417
259
|
* The resolved contract client the generators import and call.
|
|
418
260
|
*/
|
|
419
261
|
client: ResolvedClient;
|
|
420
|
-
validator: NonNullable<Options['validator']>;
|
|
421
262
|
/**
|
|
422
|
-
*
|
|
263
|
+
* Resolved infinite query configuration, or `false` when infinite queries are disabled.
|
|
423
264
|
*/
|
|
424
265
|
infinite: NonNullable<Infinite> | false;
|
|
425
266
|
queryKey: QueryKey | null;
|
|
@@ -447,7 +288,7 @@ declare const pluginVueQueryName = "plugin-vue-query";
|
|
|
447
288
|
/**
|
|
448
289
|
* Generates one TanStack Query composable per OpenAPI operation for Vue's
|
|
449
290
|
* Composition API. Queries become `useFooQuery` (and optionally
|
|
450
|
-
* `useFooInfiniteQuery`)
|
|
291
|
+
* `useFooInfiniteQuery`). Mutations become `useFooMutation`. Each composable
|
|
451
292
|
* is fully typed end to end.
|
|
452
293
|
*
|
|
453
294
|
* @example
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import "./rolldown-runtime-C0LytTxp.js";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { ast, defineGenerator, definePlugin, defineResolver } from "@kubb/core";
|
|
4
4
|
import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
5
|
-
import { pluginZodName } from "@kubb/plugin-zod";
|
|
6
5
|
import { File, Function, Type, jsxRenderer } from "@kubb/renderer-jsx";
|
|
7
6
|
import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
|
|
8
7
|
import { getNestedAccessor } from "@kubb/ast/utils";
|
|
@@ -529,109 +528,6 @@ function createGroupConfig(group) {
|
|
|
529
528
|
};
|
|
530
529
|
}
|
|
531
530
|
//#endregion
|
|
532
|
-
//#region ../../internals/client/src/builders/validatorOptions.ts
|
|
533
|
-
/**
|
|
534
|
-
* Returns `true` when any direction of the validator uses zod (used for dependency checks).
|
|
535
|
-
*/
|
|
536
|
-
function isValidatorEnabled(validator) {
|
|
537
|
-
if (!validator) return false;
|
|
538
|
-
if (validator === "zod") return true;
|
|
539
|
-
return Boolean(validator.request || validator.response);
|
|
540
|
-
}
|
|
541
|
-
//#endregion
|
|
542
|
-
//#region ../../internals/client/src/resolveClient.ts
|
|
543
|
-
/**
|
|
544
|
-
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
545
|
-
* operation, shared so the selection rules and diagnostics stay in one place.
|
|
546
|
-
*
|
|
547
|
-
* Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered
|
|
548
|
-
* contract client plugin (plugin-fetch or plugin-axios) and never emits its own inline client:
|
|
549
|
-
*
|
|
550
|
-
* - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
|
|
551
|
-
* imports and calls them.
|
|
552
|
-
* - `error` — no client plugin is registered, several are registered without a selector, or the
|
|
553
|
-
* requested one is missing.
|
|
554
|
-
*
|
|
555
|
-
* The `client` string selects explicitly (`'fetch'` / `'axios'`); when it is unset a lone registered
|
|
556
|
-
* contract client plugin is picked up automatically.
|
|
557
|
-
*/
|
|
558
|
-
const pluginFetchName = "plugin-fetch";
|
|
559
|
-
const pluginAxiosName = "plugin-axios";
|
|
560
|
-
const selectorToPlugin = {
|
|
561
|
-
fetch: pluginFetchName,
|
|
562
|
-
axios: pluginAxiosName
|
|
563
|
-
};
|
|
564
|
-
const contractPlugins = [pluginFetchName, pluginAxiosName];
|
|
565
|
-
/**
|
|
566
|
-
* Applies the `client` resolution rules. See the module comment for the strategy shape.
|
|
567
|
-
*
|
|
568
|
-
* @example
|
|
569
|
-
* ```ts
|
|
570
|
-
* resolveClient({ client: 'fetch', pluginNames: ['plugin-ts', 'plugin-fetch'] })
|
|
571
|
-
* // { kind: 'contract', pluginName: 'plugin-fetch' }
|
|
572
|
-
* ```
|
|
573
|
-
*
|
|
574
|
-
* @example
|
|
575
|
-
* ```ts
|
|
576
|
-
* resolveClient({ client: undefined, pluginNames: ['plugin-ts'] })
|
|
577
|
-
* // { kind: 'error', message: 'No client plugin is registered…' }
|
|
578
|
-
* ```
|
|
579
|
-
*/
|
|
580
|
-
function resolveClient(options) {
|
|
581
|
-
const { client, pluginNames } = options;
|
|
582
|
-
const has = (name) => pluginNames.includes(name);
|
|
583
|
-
if (client === "fetch" || client === "axios") {
|
|
584
|
-
const pluginName = selectorToPlugin[client];
|
|
585
|
-
if (!has(pluginName)) return {
|
|
586
|
-
kind: "error",
|
|
587
|
-
message: `\`client: '${client}'\` is set but \`@kubb/plugin-${client}\` is not registered in \`plugins\`. Add it, or drop \`client\` to use a different client plugin.`
|
|
588
|
-
};
|
|
589
|
-
return {
|
|
590
|
-
kind: "contract",
|
|
591
|
-
pluginName
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
const registered = contractPlugins.filter(has);
|
|
595
|
-
if (registered.length === 1) return {
|
|
596
|
-
kind: "contract",
|
|
597
|
-
pluginName: registered[0]
|
|
598
|
-
};
|
|
599
|
-
if (registered.length > 1) return {
|
|
600
|
-
kind: "error",
|
|
601
|
-
message: `Multiple client plugins are registered (${registered.map((name) => `\`@kubb/${name}\``).join(", ")}). Set \`client: 'fetch' | 'axios'\` to choose which client the hooks call, or register a single client plugin.`
|
|
602
|
-
};
|
|
603
|
-
return {
|
|
604
|
-
kind: "error",
|
|
605
|
-
message: "No client plugin is registered. Add `@kubb/plugin-axios` or `@kubb/plugin-fetch` to `plugins` so the generated code has an HTTP client to call."
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
//#endregion
|
|
609
|
-
//#region ../../internals/client/src/resolveClientOperation.ts
|
|
610
|
-
/**
|
|
611
|
-
* Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up
|
|
612
|
-
* the registered contract client plugin's resolver and output. Works for any contract client plugin
|
|
613
|
-
* (plugin-fetch or plugin-axios). Returns `null` when no contract plugin is in play (the inline
|
|
614
|
-
* path). The plugin injects `.kubb/client.ts` at the global output root, the same path consumers
|
|
615
|
-
* read `RequestConfig` / `ResponseErrorConfig` from.
|
|
616
|
-
*/
|
|
617
|
-
function resolveClientOperation(options) {
|
|
618
|
-
const { clientPlugin, driver, node, root, output } = options;
|
|
619
|
-
if (!clientPlugin) return null;
|
|
620
|
-
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
621
|
-
if (!resolver) return null;
|
|
622
|
-
const plugin = driver.getPlugin(clientPlugin.pluginName);
|
|
623
|
-
const file = resolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
624
|
-
root,
|
|
625
|
-
output: plugin?.options?.output ?? output,
|
|
626
|
-
group: plugin?.options?.group ?? void 0
|
|
627
|
-
});
|
|
628
|
-
return {
|
|
629
|
-
name: resolver.resolveName(node.operationId),
|
|
630
|
-
path: file.path,
|
|
631
|
-
clientPath: path.resolve(root, ".kubb/client.ts")
|
|
632
|
-
};
|
|
633
|
-
}
|
|
634
|
-
//#endregion
|
|
635
531
|
//#region ../../internals/tanstack-query/src/components/MutationKey.tsx
|
|
636
532
|
const declarationPrinter$7 = functionPrinter({ mode: "declaration" });
|
|
637
533
|
const mutationKeyTransformer = ({ node }) => {
|
|
@@ -746,51 +642,6 @@ function buildQueryOptionsParams(node, options) {
|
|
|
746
642
|
default: "{}"
|
|
747
643
|
})].filter((param) => param !== null) });
|
|
748
644
|
}
|
|
749
|
-
/**
|
|
750
|
-
* Returns `'zod'` when response-direction parsing is enabled.
|
|
751
|
-
* The string shorthand `'zod'` also enables response parsing.
|
|
752
|
-
*/
|
|
753
|
-
function resolveResponseParser(parser) {
|
|
754
|
-
if (!parser) return null;
|
|
755
|
-
if (parser === "zod") return "zod";
|
|
756
|
-
return parser.response ?? null;
|
|
757
|
-
}
|
|
758
|
-
/**
|
|
759
|
-
* Returns `'zod'` when request body parsing is enabled.
|
|
760
|
-
* The string shorthand `'zod'` also enables request body parsing (existing behavior).
|
|
761
|
-
*/
|
|
762
|
-
function resolveRequestParser(parser) {
|
|
763
|
-
if (!parser) return null;
|
|
764
|
-
if (parser === "zod") return "zod";
|
|
765
|
-
return parser.request ?? null;
|
|
766
|
-
}
|
|
767
|
-
/**
|
|
768
|
-
* Returns `'zod'` when query-params parsing is enabled.
|
|
769
|
-
* Only the object form `{ request: 'zod' }` enables this. `parser: 'zod'` does not.
|
|
770
|
-
*/
|
|
771
|
-
function resolveQueryParamsParser(parser) {
|
|
772
|
-
if (!parser || parser === "zod") return null;
|
|
773
|
-
return parser.request ?? null;
|
|
774
|
-
}
|
|
775
|
-
/**
|
|
776
|
-
* Collects the Zod schema import names for an operation based on the active parser directions.
|
|
777
|
-
*
|
|
778
|
-
* - `parser: 'zod'`: response and request body names (backward-compatible behavior).
|
|
779
|
-
* - `parser: { request: 'zod' }`: request body and query params names.
|
|
780
|
-
* - `parser: { response: 'zod' }`: response name only.
|
|
781
|
-
* - `parser: { request: 'zod', response: 'zod' }`: all three.
|
|
782
|
-
*
|
|
783
|
-
* Returns an empty array when no resolver is provided or `parser` is falsy.
|
|
784
|
-
*/
|
|
785
|
-
function resolveZodSchemaNames(node, zodResolver, parser) {
|
|
786
|
-
if (!zodResolver || !parser) return [];
|
|
787
|
-
const { query: queryParams } = getOperationParameters(node, { paramsCasing: "original" });
|
|
788
|
-
return [
|
|
789
|
-
resolveResponseParser(parser) === "zod" ? zodResolver.resolveResponseName?.(node) : null,
|
|
790
|
-
resolveRequestParser(parser) === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null,
|
|
791
|
-
resolveQueryParamsParser(parser) === "zod" && queryParams.length > 0 ? zodResolver.resolveQueryParamsName?.(node, queryParams[0]) : null
|
|
792
|
-
].filter((n) => Boolean(n));
|
|
793
|
-
}
|
|
794
645
|
functionPrinter({ mode: "declaration" });
|
|
795
646
|
const queryKeyTransformer = ({ node }) => {
|
|
796
647
|
if (!node.path) return [];
|
|
@@ -804,6 +655,99 @@ const queryKeyTransformer = ({ node }) => {
|
|
|
804
655
|
].filter(Boolean);
|
|
805
656
|
};
|
|
806
657
|
//#endregion
|
|
658
|
+
//#region ../../internals/client/src/resolveClient.ts
|
|
659
|
+
/**
|
|
660
|
+
* Resolves which client plugin a consumer (react-query, vue-query, swr, mcp) should call for an
|
|
661
|
+
* operation, shared so the selection rules and diagnostics stay in one place.
|
|
662
|
+
*
|
|
663
|
+
* Every client runtime lives in a dedicated client plugin, so a consumer always calls a registered
|
|
664
|
+
* contract client plugin (plugin-fetch or plugin-axios) and never emits its own inline client:
|
|
665
|
+
*
|
|
666
|
+
* - `contract` — a registered contract client plugin owns the `<op>` functions and the consumer
|
|
667
|
+
* imports and calls them.
|
|
668
|
+
* - `error` — no client plugin is registered, several are registered without a selector, or the
|
|
669
|
+
* requested one is missing.
|
|
670
|
+
*
|
|
671
|
+
* The `client` string selects explicitly (`'fetch'` / `'axios'`); when it is unset a lone registered
|
|
672
|
+
* contract client plugin is picked up automatically.
|
|
673
|
+
*/
|
|
674
|
+
const pluginFetchName = "plugin-fetch";
|
|
675
|
+
const pluginAxiosName = "plugin-axios";
|
|
676
|
+
const selectorToPlugin = {
|
|
677
|
+
fetch: pluginFetchName,
|
|
678
|
+
axios: pluginAxiosName
|
|
679
|
+
};
|
|
680
|
+
const contractPlugins = [pluginFetchName, pluginAxiosName];
|
|
681
|
+
/**
|
|
682
|
+
* Applies the `client` resolution rules. See the module comment for the strategy shape.
|
|
683
|
+
*
|
|
684
|
+
* @example
|
|
685
|
+
* ```ts
|
|
686
|
+
* resolveClient({ client: 'fetch', pluginNames: ['plugin-ts', 'plugin-fetch'] })
|
|
687
|
+
* // { kind: 'contract', pluginName: 'plugin-fetch' }
|
|
688
|
+
* ```
|
|
689
|
+
*
|
|
690
|
+
* @example
|
|
691
|
+
* ```ts
|
|
692
|
+
* resolveClient({ client: undefined, pluginNames: ['plugin-ts'] })
|
|
693
|
+
* // { kind: 'error', message: 'No client plugin is registered…' }
|
|
694
|
+
* ```
|
|
695
|
+
*/
|
|
696
|
+
function resolveClient(options) {
|
|
697
|
+
const { client, pluginNames } = options;
|
|
698
|
+
const has = (name) => pluginNames.includes(name);
|
|
699
|
+
if (client === "fetch" || client === "axios") {
|
|
700
|
+
const pluginName = selectorToPlugin[client];
|
|
701
|
+
if (!has(pluginName)) return {
|
|
702
|
+
kind: "error",
|
|
703
|
+
message: `\`client: '${client}'\` is set but \`@kubb/plugin-${client}\` is not registered in \`plugins\`. Add it, or drop \`client\` to use a different client plugin.`
|
|
704
|
+
};
|
|
705
|
+
return {
|
|
706
|
+
kind: "contract",
|
|
707
|
+
pluginName
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
const registered = contractPlugins.filter(has);
|
|
711
|
+
if (registered.length === 1) return {
|
|
712
|
+
kind: "contract",
|
|
713
|
+
pluginName: registered[0]
|
|
714
|
+
};
|
|
715
|
+
if (registered.length > 1) return {
|
|
716
|
+
kind: "error",
|
|
717
|
+
message: `Multiple client plugins are registered (${registered.map((name) => `\`@kubb/${name}\``).join(", ")}). Set \`client: 'fetch' | 'axios'\` to choose which client the hooks call, or register a single client plugin.`
|
|
718
|
+
};
|
|
719
|
+
return {
|
|
720
|
+
kind: "error",
|
|
721
|
+
message: "No client plugin is registered. Add `@kubb/plugin-axios` or `@kubb/plugin-fetch` to `plugins` so the generated code has an HTTP client to call."
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
//#endregion
|
|
725
|
+
//#region ../../internals/client/src/resolveClientOperation.ts
|
|
726
|
+
/**
|
|
727
|
+
* Resolves the contract client `<op>` a consumer (query hook, MCP handler) imports, by looking up
|
|
728
|
+
* the registered contract client plugin's resolver and output. Works for any contract client plugin
|
|
729
|
+
* (plugin-fetch or plugin-axios). Returns `null` when no contract plugin is in play (the inline
|
|
730
|
+
* path). The plugin injects `.kubb/client.ts` at the global output root, the same path consumers
|
|
731
|
+
* read `RequestConfig` / `ResponseErrorConfig` from.
|
|
732
|
+
*/
|
|
733
|
+
function resolveClientOperation(options) {
|
|
734
|
+
const { clientPlugin, driver, node, root, output } = options;
|
|
735
|
+
if (!clientPlugin) return null;
|
|
736
|
+
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
737
|
+
if (!resolver) return null;
|
|
738
|
+
const plugin = driver.getPlugin(clientPlugin.pluginName);
|
|
739
|
+
const file = resolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
740
|
+
root,
|
|
741
|
+
output: plugin?.options?.output ?? output,
|
|
742
|
+
group: plugin?.options?.group ?? void 0
|
|
743
|
+
});
|
|
744
|
+
return {
|
|
745
|
+
name: resolver.resolveName(node.operationId),
|
|
746
|
+
path: file.path,
|
|
747
|
+
clientPath: path.resolve(root, ".kubb/client.ts")
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
//#endregion
|
|
807
751
|
//#region src/utils.ts
|
|
808
752
|
const requestGroupOrder = [
|
|
809
753
|
"path",
|
|
@@ -1248,7 +1192,7 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1248
1192
|
operation(node, ctx) {
|
|
1249
1193
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
1250
1194
|
const { config, driver, resolver, root } = ctx;
|
|
1251
|
-
const { output, query, mutation, infinite,
|
|
1195
|
+
const { output, query, mutation, infinite, client, group, hooks } = ctx.options;
|
|
1252
1196
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1253
1197
|
if (!pluginTs) return null;
|
|
1254
1198
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -1298,14 +1242,6 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1298
1242
|
includeParams: false
|
|
1299
1243
|
})
|
|
1300
1244
|
].filter((name) => Boolean(name));
|
|
1301
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(pluginZodName) : null;
|
|
1302
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
1303
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1304
|
-
root,
|
|
1305
|
-
output: pluginZod?.options?.output ?? output,
|
|
1306
|
-
group: pluginZod?.options?.group ?? void 0
|
|
1307
|
-
}) : null;
|
|
1308
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
1309
1245
|
const calledClientName = contractOp.name;
|
|
1310
1246
|
return /* @__PURE__ */ jsxs(File, {
|
|
1311
1247
|
baseName: meta.file.baseName,
|
|
@@ -1328,11 +1264,6 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1328
1264
|
}
|
|
1329
1265
|
}),
|
|
1330
1266
|
children: [
|
|
1331
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
1332
|
-
name: zodSchemaNames,
|
|
1333
|
-
root: meta.file.path,
|
|
1334
|
-
path: fileZod.path
|
|
1335
|
-
}),
|
|
1336
1267
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1337
1268
|
name: [contractOp.name],
|
|
1338
1269
|
root: meta.file.path,
|
|
@@ -1430,7 +1361,7 @@ const mutationGenerator = defineGenerator({
|
|
|
1430
1361
|
operation(node, ctx) {
|
|
1431
1362
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
1432
1363
|
const { config, driver, resolver, root } = ctx;
|
|
1433
|
-
const { output, query, mutation,
|
|
1364
|
+
const { output, query, mutation, client, group, hooks } = ctx.options;
|
|
1434
1365
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1435
1366
|
if (!pluginTs) return null;
|
|
1436
1367
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -1465,14 +1396,6 @@ const mutationGenerator = defineGenerator({
|
|
|
1465
1396
|
order: "body-response-first",
|
|
1466
1397
|
includeParams: false
|
|
1467
1398
|
})].filter((name) => Boolean(name));
|
|
1468
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(pluginZodName) : null;
|
|
1469
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
1470
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1471
|
-
root,
|
|
1472
|
-
output: pluginZod?.options?.output ?? output,
|
|
1473
|
-
group: pluginZod?.options?.group ?? void 0
|
|
1474
|
-
}) : null;
|
|
1475
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
1476
1399
|
const calledClientName = contractOp.name;
|
|
1477
1400
|
const groups = getRequestGroups(node);
|
|
1478
1401
|
const hasRequestGroups = groups.path || groups.query || groups.body || groups.headers;
|
|
@@ -1497,11 +1420,6 @@ const mutationGenerator = defineGenerator({
|
|
|
1497
1420
|
}
|
|
1498
1421
|
}),
|
|
1499
1422
|
children: [
|
|
1500
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
1501
|
-
name: zodSchemaNames,
|
|
1502
|
-
root: meta.file.path,
|
|
1503
|
-
path: fileZod.path
|
|
1504
|
-
}),
|
|
1505
1423
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1506
1424
|
name: [contractOp.name],
|
|
1507
1425
|
root: meta.file.path,
|
|
@@ -1569,7 +1487,7 @@ const queryGenerator = defineGenerator({
|
|
|
1569
1487
|
operation(node, ctx) {
|
|
1570
1488
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
1571
1489
|
const { config, driver, resolver, root } = ctx;
|
|
1572
|
-
const { output, query, mutation,
|
|
1490
|
+
const { output, query, mutation, client, group, hooks } = ctx.options;
|
|
1573
1491
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1574
1492
|
if (!pluginTs) return null;
|
|
1575
1493
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
@@ -1607,14 +1525,6 @@ const queryGenerator = defineGenerator({
|
|
|
1607
1525
|
order: "body-response-first",
|
|
1608
1526
|
includeParams: false
|
|
1609
1527
|
})].filter((name) => Boolean(name));
|
|
1610
|
-
const pluginZod = isValidatorEnabled(validator) ? driver.getPlugin(pluginZodName) : null;
|
|
1611
|
-
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
1612
|
-
const fileZod = zodResolver ? zodResolver.resolveFile(operationFileEntry(node, node.operationId), {
|
|
1613
|
-
root,
|
|
1614
|
-
output: pluginZod?.options?.output ?? output,
|
|
1615
|
-
group: pluginZod?.options?.group ?? void 0
|
|
1616
|
-
}) : null;
|
|
1617
|
-
const zodSchemaNames = resolveZodSchemaNames(node, zodResolver, validator);
|
|
1618
1528
|
const calledClientName = contractOp.name;
|
|
1619
1529
|
return /* @__PURE__ */ jsxs(File, {
|
|
1620
1530
|
baseName: meta.file.baseName,
|
|
@@ -1637,11 +1547,6 @@ const queryGenerator = defineGenerator({
|
|
|
1637
1547
|
}
|
|
1638
1548
|
}),
|
|
1639
1549
|
children: [
|
|
1640
|
-
fileZod && zodSchemaNames.length > 0 && /* @__PURE__ */ jsx(File.Import, {
|
|
1641
|
-
name: zodSchemaNames,
|
|
1642
|
-
root: meta.file.path,
|
|
1643
|
-
path: fileZod.path
|
|
1644
|
-
}),
|
|
1645
1550
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1646
1551
|
name: [contractOp.name],
|
|
1647
1552
|
root: meta.file.path,
|
|
@@ -1797,7 +1702,7 @@ const pluginVueQueryName = "plugin-vue-query";
|
|
|
1797
1702
|
/**
|
|
1798
1703
|
* Generates one TanStack Query composable per OpenAPI operation for Vue's
|
|
1799
1704
|
* Composition API. Queries become `useFooQuery` (and optionally
|
|
1800
|
-
* `useFooInfiniteQuery`)
|
|
1705
|
+
* `useFooInfiniteQuery`). Mutations become `useFooMutation`. Each composable
|
|
1801
1706
|
* is fully typed end to end.
|
|
1802
1707
|
*
|
|
1803
1708
|
* @example
|
|
@@ -1822,7 +1727,7 @@ const pluginVueQuery = definePlugin((options) => {
|
|
|
1822
1727
|
const { output = {
|
|
1823
1728
|
path: "hooks",
|
|
1824
1729
|
barrel: { type: "named" }
|
|
1825
|
-
}, group, exclude = [], include, override = [],
|
|
1730
|
+
}, group, exclude = [], include, override = [], infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, hooks = false, client, resolver: userResolver, macros: userMacros } = options;
|
|
1826
1731
|
const selectedGenerators = [
|
|
1827
1732
|
queryGenerator,
|
|
1828
1733
|
infiniteQueryGenerator,
|
|
@@ -1832,7 +1737,7 @@ const pluginVueQuery = definePlugin((options) => {
|
|
|
1832
1737
|
return {
|
|
1833
1738
|
name: pluginVueQueryName,
|
|
1834
1739
|
options,
|
|
1835
|
-
dependencies: [pluginTsName
|
|
1740
|
+
dependencies: [pluginTsName],
|
|
1836
1741
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
1837
1742
|
const resolver = userResolver ? {
|
|
1838
1743
|
...resolverVueQuery,
|
|
@@ -1876,7 +1781,6 @@ const pluginVueQuery = definePlugin((options) => {
|
|
|
1876
1781
|
...infinite
|
|
1877
1782
|
} : false,
|
|
1878
1783
|
hooks,
|
|
1879
|
-
validator,
|
|
1880
1784
|
group: groupConfig,
|
|
1881
1785
|
exclude,
|
|
1882
1786
|
include,
|