@kubb/plugin-client 5.5.12 → 5.5.15
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 +8 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +251 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +9 -7
- package/dist/index.js.map +1 -1
- package/kubb-extension.json +1 -1
- package/package.json +14 -9
- package/dist/rolldown-runtime-C0LytTxp.js +0 -8
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
2
|
+
import "@kubb/plugin-zod";
|
|
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 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
|
+
* Shape of the value a generated operation function resolves to.
|
|
25
|
+
* - `'full'`: the complete `{ status, data, error, contentType, request, response }` result.
|
|
26
|
+
* - `'data'`: the bare success body when `throwOnError` is true, or the full result when it is false
|
|
27
|
+
* so callers can inspect `error`.
|
|
28
|
+
* - `'plain'`: the client's own promise typed as `RequestResult`, with no `withUnwrap` / `unwrapResult`
|
|
29
|
+
* helper. Backs `@kubb/plugin-client`.
|
|
30
|
+
*/
|
|
31
|
+
type ReturnTypeOption = 'full' | 'data' | 'plain';
|
|
32
|
+
/**
|
|
33
|
+
* The resolver shared by the client plugins. Inherits the built-in camelCase `name` and `file`;
|
|
34
|
+
* classes and tag groups use PascalCase (with a `Client` suffix for groups).
|
|
35
|
+
*/
|
|
36
|
+
type ResolverClient = Resolver & {
|
|
37
|
+
/**
|
|
38
|
+
* Resolves the generated class name for class-based clients.
|
|
39
|
+
*/
|
|
40
|
+
className(this: ResolverClient, name: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Resolves the generated class name for a tag-based client group. The default appends a
|
|
43
|
+
* `Client` suffix (tag `pet` becomes `PetClient`) so the class never collides with the schema
|
|
44
|
+
* model of the same name in the barrel.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* `resolver.groupName('pet') // -> 'PetClient'`
|
|
48
|
+
*/
|
|
49
|
+
groupName(this: ResolverClient, name: string): string;
|
|
50
|
+
/**
|
|
51
|
+
* Resolves the property name a tag client is exposed under on the composed root SDK
|
|
52
|
+
* (`new PetStore(config).pet`).
|
|
53
|
+
*/
|
|
54
|
+
propertyName(this: ResolverClient, name: string): string;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* The shared options surface for the client plugins. Deliberately small: there is one
|
|
58
|
+
* response contract and one grouped options object. Each plugin extends this with its own
|
|
59
|
+
* `transport` field.
|
|
60
|
+
*/
|
|
61
|
+
type Options$1 = OutputOptions & {
|
|
62
|
+
/**
|
|
63
|
+
* Skip operations matching at least one entry in the list.
|
|
64
|
+
*/
|
|
65
|
+
exclude?: Array<Exclude>;
|
|
66
|
+
/**
|
|
67
|
+
* Restrict generation to operations matching at least one entry in the list.
|
|
68
|
+
*/
|
|
69
|
+
include?: Array<Include>;
|
|
70
|
+
/**
|
|
71
|
+
* Apply a different options object to operations matching a pattern.
|
|
72
|
+
*/
|
|
73
|
+
override?: Array<Override<Omit<ResolvedOptions$1, 'throwOnErrorDefault'>>>;
|
|
74
|
+
/**
|
|
75
|
+
* Base URL prepended to every request. When omitted, the generated client sets no base URL, so
|
|
76
|
+
* set one at runtime with `client.setConfig({ baseURL })`. The adapter's server URL is not used.
|
|
77
|
+
* Values containing a `${...}` interpolation are emitted as template literals in the generated
|
|
78
|
+
* client config, which keeps runtime environment reads dynamic.
|
|
79
|
+
*/
|
|
80
|
+
baseURL?: string;
|
|
81
|
+
/**
|
|
82
|
+
* Default error behavior for generated operations and their client. Per-call `throwOnError`
|
|
83
|
+
* takes precedence.
|
|
84
|
+
*
|
|
85
|
+
* @default true
|
|
86
|
+
*/
|
|
87
|
+
throwOnErrorDefault?: boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Validate request and response bodies with schemas from `@kubb/plugin-zod`.
|
|
90
|
+
*
|
|
91
|
+
* @default false
|
|
92
|
+
*/
|
|
93
|
+
validator?: ValidatorOptions;
|
|
94
|
+
/**
|
|
95
|
+
* Shape of the value a generated operation function resolves to. Applies to the standalone
|
|
96
|
+
* functions and the class-based SDK; not to the query-hook plugins (`@kubb/plugin-react-query`,
|
|
97
|
+
* `@kubb/plugin-vue-query`, `@kubb/plugin-swr`), which keep calling the client directly and
|
|
98
|
+
* expect the full result.
|
|
99
|
+
*
|
|
100
|
+
* @default 'full'
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* pluginAxios({ returnType: 'data' })
|
|
104
|
+
* // const pet = await getPetById({ path: { petId: 1 } }) // Pet, not { status, data, ... }
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
returnType?: ReturnTypeOption;
|
|
108
|
+
/**
|
|
109
|
+
* Generates a class-based SDK instead of the standalone functions. Each tag client is an instance
|
|
110
|
+
* class whose constructor takes a client config and builds its own client, so every environment is
|
|
111
|
+
* a separate instance. Leave `sdk` unset to keep the standalone per-operation functions (the
|
|
112
|
+
* default), which is also what query plugins consume.
|
|
113
|
+
*
|
|
114
|
+
* @example Instance class per tag
|
|
115
|
+
* ```ts
|
|
116
|
+
* pluginFetch({ sdk: {} })
|
|
117
|
+
* // const api = new PetClient({ baseURL: 'https://api.example.com' })
|
|
118
|
+
* // await api.getPetById({ path: { petId: 1 } })
|
|
119
|
+
* ```
|
|
120
|
+
* @example Composed root that instantiates every tag client from one config
|
|
121
|
+
* ```ts
|
|
122
|
+
* pluginFetch({ sdk: { name: 'petStore' } })
|
|
123
|
+
* // class PetStore {
|
|
124
|
+
* // readonly pet: PetClient
|
|
125
|
+
* // readonly store: StoreClient
|
|
126
|
+
* // constructor(config = {}) { ... }
|
|
127
|
+
* // }
|
|
128
|
+
* // const api = new PetStore({ baseURL })
|
|
129
|
+
* // await api.pet.getPetById({ path: { petId: 1 } })
|
|
130
|
+
* ```
|
|
131
|
+
* @example Flat class with every operation as a direct method
|
|
132
|
+
* ```ts
|
|
133
|
+
* pluginFetch({ sdk: { name: 'petStore', mode: 'flat' } })
|
|
134
|
+
* // const api = new PetStore({ baseURL })
|
|
135
|
+
* // await api.getPetById({ path: { petId: 1 } })
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
sdk?: {
|
|
139
|
+
/**
|
|
140
|
+
* How the SDK groups operations.
|
|
141
|
+
* - `'tag'`: one class per tag. With `name`, a composed root instantiates every tag client.
|
|
142
|
+
* - `'flat'`: one class named by `name`, with every operation as a direct method.
|
|
143
|
+
*
|
|
144
|
+
* @default 'tag'
|
|
145
|
+
*/
|
|
146
|
+
mode?: Mode;
|
|
147
|
+
/**
|
|
148
|
+
* Name of the generated entry point, also the file name. With `mode: 'tag'` it emits a
|
|
149
|
+
* composed root class that instantiates every tag client from one shared config. With
|
|
150
|
+
* `mode: 'flat'` it names the single class.
|
|
151
|
+
*/
|
|
152
|
+
name?: string;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Override how names and file paths are built. Methods you omit fall back to the default resolver.
|
|
156
|
+
*/
|
|
157
|
+
resolver?: ResolverPatch<ResolverClient>;
|
|
158
|
+
/**
|
|
159
|
+
* Macros applied to each operation node before code is printed.
|
|
160
|
+
*/
|
|
161
|
+
macros?: Array<ast.Macro>;
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* The resolved options after defaults are applied.
|
|
165
|
+
*/
|
|
166
|
+
type ResolvedOptions$1 = {
|
|
167
|
+
output: Output;
|
|
168
|
+
exclude: Array<Exclude>;
|
|
169
|
+
include: Array<Include> | undefined;
|
|
170
|
+
override: Array<Override<Omit<ResolvedOptions$1, 'throwOnErrorDefault'>>>;
|
|
171
|
+
group: Group | null;
|
|
172
|
+
baseURL: Options$1['baseURL'];
|
|
173
|
+
throwOnErrorDefault: boolean;
|
|
174
|
+
validator: NonNullable<Options$1['validator']>;
|
|
175
|
+
returnType: ReturnTypeOption;
|
|
176
|
+
sdk: {
|
|
177
|
+
mode: Mode;
|
|
178
|
+
name: string | undefined;
|
|
179
|
+
} | undefined;
|
|
180
|
+
resolver: ResolverClient;
|
|
181
|
+
};
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/types.d.ts
|
|
184
|
+
/**
|
|
185
|
+
* Omits keys from every member of a union, where the built-in `Omit` would collapse the union into one shape.
|
|
186
|
+
*/
|
|
187
|
+
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
188
|
+
/**
|
|
189
|
+
* Options for `pluginClient`. It takes the shared client options, without the ones this plugin does not use,
|
|
190
|
+
* plus the required `importPath`.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* pluginClient({ importPath: '../../../client' })
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
type Options = DistributiveOmit<Options$1, 'sdk' | 'returnType' | 'baseURL' | 'override'> & {
|
|
198
|
+
/**
|
|
199
|
+
* Applies different options to operations that match a pattern.
|
|
200
|
+
* `sdk`, `returnType`, and `baseURL` are not available, because this plugin generates standalone operations and your client module owns the base URL.
|
|
201
|
+
*/
|
|
202
|
+
override?: Array<Override<Omit<ResolvedOptions, 'throwOnErrorDefault' | 'sdk' | 'returnType' | 'baseURL'>>>;
|
|
203
|
+
/**
|
|
204
|
+
* Import specifier of your own client module, written into every generated import exactly as given.
|
|
205
|
+
* It must resolve from the generated file, so use a relative path, a package name, or an alias.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* pluginClient({ importPath: '../../../client' }) // relative to src/gen/clients/<tag>/
|
|
210
|
+
* pluginClient({ importPath: '@my-org/api-client' }) // a package
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
importPath: string;
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Options after `pluginClient` applies its defaults.
|
|
217
|
+
*/
|
|
218
|
+
type ResolvedOptions = ResolvedOptions$1 & {
|
|
219
|
+
importPath: string;
|
|
220
|
+
};
|
|
221
|
+
/**
|
|
222
|
+
* Plugin type of `@kubb/plugin-client`, registered in the Kubb plugin registry.
|
|
223
|
+
*/
|
|
224
|
+
type PluginClient = PluginType<'plugin-client', Options, ResolvedOptions, ResolverClient>;
|
|
225
|
+
declare global {
|
|
226
|
+
namespace Kubb {
|
|
227
|
+
interface PluginRegistry {
|
|
228
|
+
'plugin-client': PluginClient;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
//#endregion
|
|
233
|
+
//#region src/plugin.d.ts
|
|
234
|
+
/**
|
|
235
|
+
* Canonical plugin name for `@kubb/plugin-client`.
|
|
236
|
+
*/
|
|
237
|
+
export declare const pluginClientName = "plugin-client";
|
|
238
|
+
/**
|
|
239
|
+
* Generates typed operations that call a client module owned by your application.
|
|
240
|
+
* The module at `importPath` must export the runtime helpers and types used by generated operations.
|
|
241
|
+
* Kubb does not copy or inject a transport implementation.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```ts
|
|
245
|
+
* pluginClient({ importPath: '../api/client' })
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
export declare const pluginClient: import("kubb/kit").PluginFactory<PluginClient>;
|
|
249
|
+
//#endregion
|
|
250
|
+
export { type Options, type PluginClient, type ResolvedOptions, type ResolverClient, pluginClient as default };
|
|
251
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
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
3
|
//#region ../../internals/client/src/types.d.ts
|
|
5
4
|
/**
|
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, macroSimplifyUnion, setMacros, setResolver } from "kubb/kit";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
import { createFunctionParameter, createFunctionParameters, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
5
4
|
import { pluginZodName } from "@kubb/plugin-zod";
|
|
6
5
|
import { File, Function, jsxRenderer } from "kubb/jsx";
|
|
7
6
|
import { jsx, jsxs } from "kubb/jsx/jsx-runtime";
|
|
7
|
+
//#endregion
|
|
8
8
|
//#region ../../internals/shared/src/operation.ts
|
|
9
9
|
/**
|
|
10
10
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
@@ -413,11 +413,11 @@ function createGroupConfig(group) {
|
|
|
413
413
|
//#region kubb-extension.json
|
|
414
414
|
var compatibility = {
|
|
415
415
|
"kubb": ">=5.8.3",
|
|
416
|
-
"node": ">=22"
|
|
416
|
+
"node": ">=22.12"
|
|
417
417
|
};
|
|
418
418
|
//#endregion
|
|
419
419
|
//#region package.json
|
|
420
|
-
var version = "5.5.
|
|
420
|
+
var version = "5.5.15";
|
|
421
421
|
//#endregion
|
|
422
422
|
//#region ../../internals/client/src/builders/validatorOptions.ts
|
|
423
423
|
/**
|
|
@@ -679,21 +679,23 @@ function toKey(name, location) {
|
|
|
679
679
|
return isValidVarName(key) ? key : JSON.stringify(key);
|
|
680
680
|
}
|
|
681
681
|
/**
|
|
682
|
-
* Serializes one parameter's metadata into a `{ style, explode }` literal, or `null`
|
|
683
|
-
* parameter carries
|
|
684
|
-
* fixed style (`simple` and `form`), so only `explode` is emitted for them.
|
|
682
|
+
* Serializes one parameter's metadata into a `{ style, explode, allowReserved }` literal, or `null`
|
|
683
|
+
* when the parameter carries none. Path and query carry the serialization `style`; header and cookie
|
|
684
|
+
* use a fixed style (`simple` and `form`), so only `explode` is emitted for them. `allowReserved`
|
|
685
|
+
* only applies to query parameters.
|
|
685
686
|
*/
|
|
686
687
|
function serializeParameter(parameter) {
|
|
687
688
|
const parts = [];
|
|
688
689
|
if ((parameter.in === "path" || parameter.in === "query") && parameter.style) parts.push(`style: '${parameter.style}'`);
|
|
689
690
|
if (parameter.explode !== void 0) parts.push(`explode: ${parameter.explode}`);
|
|
691
|
+
if (parameter.in === "query" && parameter.allowReserved !== void 0) parts.push(`allowReserved: ${parameter.allowReserved}`);
|
|
690
692
|
return parts.length > 0 ? `{ ${parts.join(", ")} }` : null;
|
|
691
693
|
}
|
|
692
694
|
/**
|
|
693
695
|
* Builds the per-operation `styles` literal from the operation's parameters, grouped by location.
|
|
694
696
|
* Path entries are keyed by the camelCased name to match the URL template placeholders; query,
|
|
695
697
|
* header, and cookie entries keep the spec name to match the keys the runtime serializes.
|
|
696
|
-
* Only parameters whose source defines `style` or `
|
|
698
|
+
* Only parameters whose source defines `style`, `explode`, or `allowReserved` are emitted, so calls without
|
|
697
699
|
* serialization metadata keep the runtime defaults and existing output is unchanged. Returns `null`
|
|
698
700
|
* when no parameter carries metadata.
|
|
699
701
|
*
|