@kubb/plugin-client 5.0.0-beta.3 → 5.0.0-beta.30
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/README.md +24 -4
- package/dist/clients/axios.cjs +25 -3
- package/dist/clients/axios.cjs.map +1 -1
- package/dist/clients/axios.d.ts +9 -2
- package/dist/clients/axios.js +25 -3
- package/dist/clients/axios.js.map +1 -1
- package/dist/clients/fetch.cjs +20 -2
- package/dist/clients/fetch.cjs.map +1 -1
- package/dist/clients/fetch.d.ts +9 -2
- package/dist/clients/fetch.js +20 -2
- package/dist/clients/fetch.js.map +1 -1
- package/dist/index.cjs +524 -301
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +150 -84
- package/dist/index.js +525 -302
- package/dist/index.js.map +1 -1
- package/dist/templates/clients/axios.source.cjs +1 -1
- package/dist/templates/clients/axios.source.js +1 -1
- package/dist/templates/clients/fetch.source.cjs +1 -1
- package/dist/templates/clients/fetch.source.js +1 -1
- package/extension.yaml +1293 -0
- package/package.json +11 -17
- package/src/clients/axios.ts +41 -7
- package/src/clients/fetch.ts +30 -3
- package/src/components/ClassClient.tsx +17 -19
- package/src/components/Client.tsx +68 -51
- package/src/components/StaticClassClient.tsx +17 -19
- package/src/components/Url.tsx +7 -9
- package/src/components/WrapperClient.tsx +9 -5
- package/src/functionParams.ts +8 -8
- package/src/generators/classClientGenerator.tsx +40 -38
- package/src/generators/clientGenerator.tsx +32 -35
- package/src/generators/groupedClientGenerator.tsx +14 -8
- package/src/generators/operationsGenerator.tsx +12 -6
- package/src/generators/staticClassClientGenerator.tsx +34 -32
- package/src/plugin.ts +24 -11
- package/src/resolvers/resolverClient.ts +31 -8
- package/src/types.ts +90 -53
- package/src/utils.ts +30 -53
- package/templates/clients/axios.ts +0 -73
- package/templates/clients/fetch.ts +0 -96
- package/templates/config.ts +0 -43
package/dist/index.d.ts
CHANGED
|
@@ -13,10 +13,34 @@ import { KubbReactNode } from "@kubb/renderer-jsx/types";
|
|
|
13
13
|
type ResolverClient = Resolver & {
|
|
14
14
|
/**
|
|
15
15
|
* Resolves the function name for a given raw operation name.
|
|
16
|
+
*
|
|
16
17
|
* @example Resolving operation names
|
|
17
18
|
* `resolver.resolveName('show pet by id') // -> 'showPetById'`
|
|
18
19
|
*/
|
|
19
20
|
resolveName(this: ResolverClient, name: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Resolves the output file name for a client module.
|
|
23
|
+
*/
|
|
24
|
+
resolvePathName(this: ResolverClient, name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
|
|
25
|
+
/**
|
|
26
|
+
* Resolves the generated class name for class-based clients.
|
|
27
|
+
*/
|
|
28
|
+
resolveClassName(this: ResolverClient, name: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Resolves the generated class name for tag-based client groups.
|
|
31
|
+
*/
|
|
32
|
+
resolveGroupName(this: ResolverClient, name: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Resolves the generated SDK facade property name for a client class.
|
|
35
|
+
*/
|
|
36
|
+
resolveClientPropertyName(this: ResolverClient, name: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Resolves the URL helper function name for an operation.
|
|
39
|
+
*
|
|
40
|
+
* @example Resolving URL helper names
|
|
41
|
+
* `resolver.resolveUrlName(node) // -> 'getShowPetByIdUrl'`
|
|
42
|
+
*/
|
|
43
|
+
resolveUrlName(this: ResolverClient, node: ast.OperationNode): string;
|
|
20
44
|
};
|
|
21
45
|
/**
|
|
22
46
|
* Use either a preset `client` type OR a custom `importPath`, not both.
|
|
@@ -26,9 +50,10 @@ type ResolverClient = Resolver & {
|
|
|
26
50
|
*/
|
|
27
51
|
type ClientImportPath = {
|
|
28
52
|
/**
|
|
29
|
-
*
|
|
30
|
-
* - 'axios'
|
|
31
|
-
* - 'fetch'
|
|
53
|
+
* HTTP client used by the generated code.
|
|
54
|
+
* - `'axios'` — imports from `@kubb/plugin-client/clients/axios`. Requires `axios` at runtime.
|
|
55
|
+
* - `'fetch'` — imports from `@kubb/plugin-client/clients/fetch`. Uses the global `fetch`.
|
|
56
|
+
*
|
|
32
57
|
* @default 'axios'
|
|
33
58
|
*/
|
|
34
59
|
client?: 'axios' | 'fetch';
|
|
@@ -36,9 +61,12 @@ type ClientImportPath = {
|
|
|
36
61
|
} | {
|
|
37
62
|
client?: never;
|
|
38
63
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
64
|
+
* Path to a custom client module. Generated files import their HTTP runtime from here
|
|
65
|
+
* instead of `@kubb/plugin-client/clients/{client}`. Accepts both relative paths and
|
|
66
|
+
* bare module specifiers; the value is used as-is.
|
|
67
|
+
*
|
|
68
|
+
* @note When combined with a query plugin, the module must export `Client`,
|
|
69
|
+
* `RequestConfig`, and `ResponseErrorConfig` types.
|
|
42
70
|
*/
|
|
43
71
|
importPath: string;
|
|
44
72
|
/**
|
|
@@ -58,115 +86,123 @@ type ClientImportPath = {
|
|
|
58
86
|
*/
|
|
59
87
|
type ParamsTypeOptions = {
|
|
60
88
|
/**
|
|
61
|
-
*
|
|
89
|
+
* Every operation parameter (path, query, headers, body) is wrapped in a single
|
|
62
90
|
* destructured object argument.
|
|
63
|
-
* - 'object' returns the params and pathParams as an object.
|
|
64
|
-
* @default 'inline'
|
|
65
91
|
*/
|
|
66
92
|
paramsType: 'object';
|
|
67
93
|
/**
|
|
68
94
|
* `pathParamsType` has no effect when `paramsType` is `'object'`.
|
|
69
|
-
* Path params
|
|
95
|
+
* Path params already live inside the single destructured object.
|
|
70
96
|
*/
|
|
71
97
|
pathParamsType?: never;
|
|
72
98
|
} | {
|
|
73
99
|
/**
|
|
74
|
-
* Each parameter group is emitted as a separate function argument.
|
|
75
|
-
*
|
|
100
|
+
* Each parameter group is emitted as a separate positional function argument.
|
|
101
|
+
*
|
|
76
102
|
* @default 'inline'
|
|
77
103
|
*/
|
|
78
104
|
paramsType?: 'inline';
|
|
79
105
|
/**
|
|
80
|
-
*
|
|
81
|
-
* - 'object' groups
|
|
82
|
-
* - 'inline' emits each path param as its own argument: `petId: string`.
|
|
106
|
+
* How URL path parameters are arranged inside the inline argument list.
|
|
107
|
+
* - `'object'` groups them into one destructured object: `{ petId }: PathParams`.
|
|
108
|
+
* - `'inline'` emits each path param as its own argument: `petId: string`.
|
|
109
|
+
*
|
|
83
110
|
* @default 'inline'
|
|
84
111
|
*/
|
|
85
112
|
pathParamsType?: 'object' | 'inline';
|
|
86
113
|
};
|
|
87
114
|
type Options = {
|
|
88
115
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
116
|
+
* Where the generated client files are written and how they are exported.
|
|
117
|
+
*
|
|
118
|
+
* @default { path: 'clients', barrel: { type: 'named' } }
|
|
91
119
|
*/
|
|
92
120
|
output?: Output;
|
|
93
121
|
/**
|
|
94
|
-
*
|
|
122
|
+
* Split generated files into subfolders based on the operation's tag.
|
|
95
123
|
*/
|
|
96
124
|
group?: Group;
|
|
97
125
|
/**
|
|
98
|
-
*
|
|
126
|
+
* Skip operations matching at least one entry in the list.
|
|
99
127
|
*/
|
|
100
128
|
exclude?: Array<Exclude>;
|
|
101
129
|
/**
|
|
102
|
-
*
|
|
130
|
+
* Restrict generation to operations matching at least one entry in the list.
|
|
103
131
|
*/
|
|
104
132
|
include?: Array<Include>;
|
|
105
133
|
/**
|
|
106
|
-
*
|
|
134
|
+
* Apply a different options object to operations matching a pattern.
|
|
107
135
|
*/
|
|
108
136
|
override?: Array<Override<ResolvedOptions>>;
|
|
109
137
|
/**
|
|
110
|
-
*
|
|
138
|
+
* Emit an `operations.ts` file that re-exports every generated function grouped by HTTP method.
|
|
139
|
+
*
|
|
111
140
|
* @default false
|
|
112
141
|
*/
|
|
113
142
|
operations?: boolean;
|
|
114
143
|
/**
|
|
115
|
-
*
|
|
116
|
-
* - 'export'
|
|
117
|
-
* - false
|
|
144
|
+
* Whether to also export the URL builder helpers (`get<Operation>Url`).
|
|
145
|
+
* - `'export'` exposes them via the barrel.
|
|
146
|
+
* - `false` keeps them private.
|
|
147
|
+
*
|
|
118
148
|
* @default false
|
|
119
|
-
* @example getGetPetByIdUrl
|
|
120
149
|
*/
|
|
121
150
|
urlType?: 'export' | false;
|
|
122
151
|
/**
|
|
123
|
-
*
|
|
152
|
+
* Base URL prepended to every request. When omitted, falls back to the adapter's
|
|
153
|
+
* server URL (typically `servers[0].url`).
|
|
124
154
|
*/
|
|
125
155
|
baseURL?: string;
|
|
126
156
|
/**
|
|
127
|
-
*
|
|
128
|
-
* - 'data'
|
|
129
|
-
* - 'full'
|
|
157
|
+
* Shape of the value returned by each generated client function.
|
|
158
|
+
* - `'data'` — only the response body.
|
|
159
|
+
* - `'full'` — the full response config (body, status, headers, request).
|
|
160
|
+
*
|
|
130
161
|
* @default 'data'
|
|
131
162
|
*/
|
|
132
163
|
dataReturnType?: 'data' | 'full';
|
|
133
164
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
165
|
+
* Rename parameter properties in the generated client (path, query, headers).
|
|
166
|
+
* The HTTP request still uses the original spec names; Kubb writes the mapping for you.
|
|
167
|
+
*
|
|
168
|
+
* @note Use the same value on `@kubb/plugin-ts` so types stay compatible.
|
|
137
169
|
*/
|
|
138
170
|
paramsCasing?: 'camelcase';
|
|
139
171
|
/**
|
|
140
|
-
*
|
|
141
|
-
* - 'client'
|
|
142
|
-
* - 'zod'
|
|
172
|
+
* Validator applied to response bodies before they are returned to the caller.
|
|
173
|
+
* - `'client'` — no validation. Trusts the API.
|
|
174
|
+
* - `'zod'` — pipes responses through schemas from `@kubb/plugin-zod`.
|
|
175
|
+
*
|
|
143
176
|
* @default 'client'
|
|
144
177
|
*/
|
|
145
178
|
parser?: 'client' | 'zod';
|
|
146
179
|
/**
|
|
147
|
-
*
|
|
148
|
-
* - 'function'
|
|
149
|
-
* - 'class'
|
|
150
|
-
* - 'staticClass'
|
|
180
|
+
* Shape of the generated client.
|
|
181
|
+
* - `'function'` — one standalone async function per operation.
|
|
182
|
+
* - `'class'` — one class per tag with instance methods.
|
|
183
|
+
* - `'staticClass'` — one class per tag with static methods.
|
|
184
|
+
*
|
|
151
185
|
* @default 'function'
|
|
186
|
+
* @note Only `'function'` is compatible with query plugins.
|
|
152
187
|
*/
|
|
153
188
|
clientType?: 'function' | 'class' | 'staticClass';
|
|
154
189
|
/**
|
|
155
|
-
*
|
|
156
|
-
* When
|
|
190
|
+
* Copy the HTTP client runtime into the generated output so consumers do not need
|
|
191
|
+
* `@kubb/plugin-client` at runtime. When `false`, generated files import from
|
|
192
|
+
* `@kubb/plugin-client/clients/{client}`.
|
|
193
|
+
*
|
|
157
194
|
* @default false
|
|
158
|
-
* In version 5 of Kubb this is by default true
|
|
159
195
|
*/
|
|
160
196
|
bundle?: boolean;
|
|
161
197
|
/**
|
|
162
|
-
* Generate
|
|
163
|
-
*
|
|
198
|
+
* Generate a single SDK class composing every tag-based client into one entry point.
|
|
199
|
+
* Automatically enables `clientType: 'class'`.
|
|
200
|
+
*
|
|
164
201
|
* @example
|
|
165
202
|
* ```ts
|
|
166
203
|
* pluginClient({
|
|
167
204
|
* sdk: { className: 'PetStoreSDK' },
|
|
168
205
|
* })
|
|
169
|
-
* // Generates a class with a shared constructor config and one property per tag:
|
|
170
206
|
* // class PetStoreSDK {
|
|
171
207
|
* // readonly petController: petController
|
|
172
208
|
* // readonly storeController: storeController
|
|
@@ -176,22 +212,23 @@ type Options = {
|
|
|
176
212
|
*/
|
|
177
213
|
sdk?: {
|
|
178
214
|
/**
|
|
179
|
-
* Name of the generated SDK facade class.
|
|
215
|
+
* Name of the generated SDK facade class. Also the file name.
|
|
180
216
|
*/
|
|
181
217
|
className: string;
|
|
182
218
|
};
|
|
183
219
|
/**
|
|
184
|
-
* Override
|
|
185
|
-
*
|
|
220
|
+
* Override how names and file paths are built for the generated client.
|
|
221
|
+
* Methods you omit fall back to the default resolver. `this` is bound to the
|
|
222
|
+
* full resolver, so `this.default(name)` delegates to the built-in implementation.
|
|
186
223
|
*/
|
|
187
224
|
resolver?: Partial<ResolverClient> & ThisType<ResolverClient>;
|
|
188
225
|
/**
|
|
189
|
-
*
|
|
190
|
-
* Return `null` or `undefined`
|
|
226
|
+
* AST visitor applied to each operation node before code is printed.
|
|
227
|
+
* Return `null` or `undefined` to leave the node unchanged.
|
|
191
228
|
*/
|
|
192
229
|
transformer?: ast.Visitor;
|
|
193
230
|
/**
|
|
194
|
-
*
|
|
231
|
+
* Custom generators that run alongside the built-in client generators.
|
|
195
232
|
*/
|
|
196
233
|
generators?: Array<Generator<PluginClient>>;
|
|
197
234
|
} & ClientImportPath & ParamsTypeOptions;
|
|
@@ -200,7 +237,7 @@ type ResolvedOptions = {
|
|
|
200
237
|
exclude: Array<Exclude>;
|
|
201
238
|
include: Array<Include> | undefined;
|
|
202
239
|
override: Array<Override<ResolvedOptions>>;
|
|
203
|
-
group: Group |
|
|
240
|
+
group: Group | null;
|
|
204
241
|
client: Options['client'];
|
|
205
242
|
clientType: NonNullable<Options['clientType']>;
|
|
206
243
|
bundle: NonNullable<Options['bundle']>;
|
|
@@ -232,7 +269,7 @@ type Props = {
|
|
|
232
269
|
isIndexable?: boolean;
|
|
233
270
|
isConfigurable?: boolean;
|
|
234
271
|
returnType?: string;
|
|
235
|
-
baseURL: string | undefined;
|
|
272
|
+
baseURL: string | null | undefined;
|
|
236
273
|
dataReturnType: PluginClient['resolvedOptions']['dataReturnType'];
|
|
237
274
|
paramsCasing: PluginClient['resolvedOptions']['paramsCasing'];
|
|
238
275
|
paramsType: PluginClient['resolvedOptions']['pathParamsType'];
|
|
@@ -240,17 +277,9 @@ type Props = {
|
|
|
240
277
|
parser: PluginClient['resolvedOptions']['parser'] | undefined;
|
|
241
278
|
node: ast.OperationNode;
|
|
242
279
|
tsResolver: ResolverTs;
|
|
243
|
-
zodResolver?: ResolverZod;
|
|
280
|
+
zodResolver?: ResolverZod | null;
|
|
244
281
|
children?: KubbReactNode;
|
|
245
282
|
};
|
|
246
|
-
type GetParamsProps = {
|
|
247
|
-
paramsCasing: PluginClient['resolvedOptions']['paramsCasing'];
|
|
248
|
-
paramsType: PluginClient['resolvedOptions']['paramsType'];
|
|
249
|
-
pathParamsType: PluginClient['resolvedOptions']['pathParamsType'];
|
|
250
|
-
node: ast.OperationNode;
|
|
251
|
-
tsResolver: ResolverTs;
|
|
252
|
-
isConfigurable: boolean;
|
|
253
|
-
};
|
|
254
283
|
declare function Client({
|
|
255
284
|
name,
|
|
256
285
|
isExportable,
|
|
@@ -269,47 +298,78 @@ declare function Client({
|
|
|
269
298
|
children,
|
|
270
299
|
isConfigurable
|
|
271
300
|
}: Props): KubbReactNode;
|
|
272
|
-
declare namespace Client {
|
|
273
|
-
var getParams: ({
|
|
274
|
-
paramsType,
|
|
275
|
-
paramsCasing,
|
|
276
|
-
pathParamsType,
|
|
277
|
-
node,
|
|
278
|
-
tsResolver,
|
|
279
|
-
isConfigurable
|
|
280
|
-
}: GetParamsProps) => ast.FunctionParametersNode;
|
|
281
|
-
}
|
|
282
301
|
//#endregion
|
|
283
302
|
//#region src/generators/classClientGenerator.d.ts
|
|
303
|
+
/**
|
|
304
|
+
* Built-in `operations` generator for `@kubb/plugin-client` when
|
|
305
|
+
* `clientType: 'class'`. Emits one class per tag, with one instance method
|
|
306
|
+
* per operation and a shared constructor for request configuration.
|
|
307
|
+
*/
|
|
284
308
|
declare const classClientGenerator: _$_kubb_core0.Generator<PluginClient, unknown>;
|
|
285
309
|
//#endregion
|
|
286
310
|
//#region src/generators/clientGenerator.d.ts
|
|
311
|
+
/**
|
|
312
|
+
* Built-in operation generator for `@kubb/plugin-client`. Emits one async
|
|
313
|
+
* function per OpenAPI operation, plus the matching URL helper. Used when
|
|
314
|
+
* `clientType: 'function'` (the default).
|
|
315
|
+
*/
|
|
287
316
|
declare const clientGenerator: _$_kubb_core0.Generator<PluginClient, unknown>;
|
|
288
317
|
//#endregion
|
|
289
318
|
//#region src/generators/groupedClientGenerator.d.ts
|
|
319
|
+
/**
|
|
320
|
+
* Emits one aggregate file per tag/group when `group` is configured. Each
|
|
321
|
+
* file re-exports every client function for that group, so callers can
|
|
322
|
+
* `import { petController } from './gen/clients'` instead of importing
|
|
323
|
+
* each operation individually.
|
|
324
|
+
*/
|
|
290
325
|
declare const groupedClientGenerator: _$_kubb_core0.Generator<PluginClient, unknown>;
|
|
291
326
|
//#endregion
|
|
292
327
|
//#region src/generators/operationsGenerator.d.ts
|
|
328
|
+
/**
|
|
329
|
+
* Generates an `operations.ts` file that re-exports every operation grouped
|
|
330
|
+
* by HTTP method. Enabled when `pluginClient({ operations: true })`. Useful
|
|
331
|
+
* for building meta-tooling on top of the generated client (route
|
|
332
|
+
* registries, API explorers).
|
|
333
|
+
*/
|
|
293
334
|
declare const operationsGenerator: _$_kubb_core0.Generator<PluginClient, unknown>;
|
|
294
335
|
//#endregion
|
|
295
336
|
//#region src/generators/staticClassClientGenerator.d.ts
|
|
337
|
+
/**
|
|
338
|
+
* Built-in `operations` generator for `@kubb/plugin-client` when
|
|
339
|
+
* `clientType: 'staticClass'`. Emits one class per tag, with a static method
|
|
340
|
+
* per operation so callers can use `Pet.getPetById(...)` without
|
|
341
|
+
* instantiating the class.
|
|
342
|
+
*/
|
|
296
343
|
declare const staticClassClientGenerator: _$_kubb_core0.Generator<PluginClient, unknown>;
|
|
297
344
|
//#endregion
|
|
298
345
|
//#region src/plugin.d.ts
|
|
299
346
|
/**
|
|
300
|
-
* Canonical plugin name for `@kubb/plugin-client
|
|
347
|
+
* Canonical plugin name for `@kubb/plugin-client`. Used for driver lookups and
|
|
348
|
+
* cross-plugin dependency references.
|
|
301
349
|
*/
|
|
302
350
|
declare const pluginClientName = "plugin-client";
|
|
303
351
|
/**
|
|
304
|
-
* Generates
|
|
305
|
-
*
|
|
306
|
-
*
|
|
352
|
+
* Generates one HTTP client function per OpenAPI operation. Each function has
|
|
353
|
+
* typed path params, query params, body, and response, so callers use the API
|
|
354
|
+
* like any other typed function. Ships with `axios` and `fetch` runtimes; bring
|
|
355
|
+
* your own by setting `importPath`.
|
|
307
356
|
*
|
|
308
|
-
* @example
|
|
357
|
+
* @example
|
|
309
358
|
* ```ts
|
|
310
|
-
* import
|
|
359
|
+
* import { defineConfig } from 'kubb'
|
|
360
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
361
|
+
* import { pluginClient } from '@kubb/plugin-client'
|
|
362
|
+
*
|
|
311
363
|
* export default defineConfig({
|
|
312
|
-
*
|
|
364
|
+
* input: { path: './petStore.yaml' },
|
|
365
|
+
* output: { path: './src/gen' },
|
|
366
|
+
* plugins: [
|
|
367
|
+
* pluginTs(),
|
|
368
|
+
* pluginClient({
|
|
369
|
+
* output: { path: './clients' },
|
|
370
|
+
* client: 'fetch',
|
|
371
|
+
* }),
|
|
372
|
+
* ],
|
|
313
373
|
* })
|
|
314
374
|
* ```
|
|
315
375
|
*/
|
|
@@ -317,12 +377,18 @@ declare const pluginClient: (options?: Options | undefined) => _$_kubb_core0.Plu
|
|
|
317
377
|
//#endregion
|
|
318
378
|
//#region src/resolvers/resolverClient.d.ts
|
|
319
379
|
/**
|
|
320
|
-
*
|
|
380
|
+
* Default resolver used by `@kubb/plugin-client`. Decides the names and file
|
|
381
|
+
* paths for every generated client function or class. Functions and files use
|
|
382
|
+
* camelCase; classes and tag groups use PascalCase.
|
|
321
383
|
*
|
|
322
|
-
*
|
|
384
|
+
* @example Resolve client function and class names
|
|
385
|
+
* ```ts
|
|
386
|
+
* import { resolverClient } from '@kubb/plugin-client'
|
|
323
387
|
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
388
|
+
* resolverClient.default('list pets', 'function') // 'listPets'
|
|
389
|
+
* resolverClient.resolveClassName('pet') // 'Pet'
|
|
390
|
+
* resolverClient.resolveUrlName(operationNode) // 'getShowPetByIdUrl'
|
|
391
|
+
* ```
|
|
326
392
|
*/
|
|
327
393
|
declare const resolverClient: ResolverClient;
|
|
328
394
|
//#endregion
|