@kubb/plugin-client 5.0.0-alpha.8 → 5.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +17 -10
- package/README.md +4 -4
- package/dist/clients/axios.cjs +2 -2
- package/dist/clients/axios.cjs.map +1 -1
- package/dist/clients/axios.d.ts +4 -4
- package/dist/clients/axios.js +1 -1
- package/dist/clients/axios.js.map +1 -1
- package/dist/clients/fetch.cjs +1 -1
- package/dist/clients/fetch.cjs.map +1 -1
- package/dist/clients/fetch.d.ts +2 -2
- package/dist/clients/fetch.js +1 -1
- package/dist/clients/fetch.js.map +1 -1
- package/dist/index.cjs +1739 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +324 -4
- package/dist/index.js +1725 -95
- 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/package.json +67 -84
- package/src/clients/axios.ts +5 -1
- package/src/clients/fetch.ts +5 -1
- package/src/components/ClassClient.tsx +45 -142
- package/src/components/Client.tsx +90 -129
- package/src/components/Operations.tsx +10 -10
- package/src/components/StaticClassClient.tsx +44 -138
- package/src/components/Url.tsx +38 -48
- package/src/components/WrapperClient.tsx +3 -3
- package/src/functionParams.ts +118 -0
- package/src/generators/classClientGenerator.tsx +148 -171
- package/src/generators/clientGenerator.tsx +95 -82
- package/src/generators/groupedClientGenerator.tsx +50 -52
- package/src/generators/operationsGenerator.tsx +11 -18
- package/src/generators/staticClassClientGenerator.tsx +178 -183
- package/src/index.ts +9 -2
- package/src/plugin.ts +115 -145
- package/src/resolvers/resolverClient.ts +22 -0
- package/src/types.ts +104 -44
- package/src/utils.ts +180 -0
- package/templates/clients/axios.ts +5 -2
- package/templates/clients/fetch.ts +5 -2
- package/dist/StaticClassClient-By-aMAe4.cjs +0 -677
- package/dist/StaticClassClient-By-aMAe4.cjs.map +0 -1
- package/dist/StaticClassClient-CCn9g9eF.js +0 -636
- package/dist/StaticClassClient-CCn9g9eF.js.map +0 -1
- package/dist/components.cjs +0 -7
- package/dist/components.d.ts +0 -216
- package/dist/components.js +0 -2
- package/dist/generators-BYUJaeZP.js +0 -723
- package/dist/generators-BYUJaeZP.js.map +0 -1
- package/dist/generators-DTxD9FDY.cjs +0 -753
- package/dist/generators-DTxD9FDY.cjs.map +0 -1
- package/dist/generators.cjs +0 -7
- package/dist/generators.d.ts +0 -488
- package/dist/generators.js +0 -2
- package/dist/types-DBQdg-BV.d.ts +0 -169
- package/src/components/index.ts +0 -5
- package/src/generators/index.ts +0 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,330 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import * as _$_kubb_core0 from "@kubb/core";
|
|
3
|
+
import { Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
|
|
4
|
+
import { ResolverTs } from "@kubb/plugin-ts";
|
|
5
|
+
import { ResolverZod } from "@kubb/plugin-zod";
|
|
6
|
+
import { KubbReactNode } from "@kubb/renderer-jsx/types";
|
|
4
7
|
|
|
8
|
+
//#region src/types.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* The concrete resolver type for `@kubb/plugin-client`.
|
|
11
|
+
* Extends the base `Resolver` with a `resolveName` helper for client function names.
|
|
12
|
+
*/
|
|
13
|
+
type ResolverClient = Resolver & {
|
|
14
|
+
/**
|
|
15
|
+
* Resolves the function name for a given raw operation name.
|
|
16
|
+
* @example Resolving operation names
|
|
17
|
+
* `resolver.resolveName('show pet by id') // -> 'showPetById'`
|
|
18
|
+
*/
|
|
19
|
+
resolveName(this: ResolverClient, name: string): string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Use either a preset `client` type OR a custom `importPath`, not both.
|
|
23
|
+
* `importPath` will override the default `client` preset when both are provided.
|
|
24
|
+
* These options are mutually exclusive. `bundle` and `importPath` are also
|
|
25
|
+
* mutually exclusive since `bundle` only has effect when `importPath` is not set.
|
|
26
|
+
*/
|
|
27
|
+
type ClientImportPath = {
|
|
28
|
+
/**
|
|
29
|
+
* Which client should be used to do the HTTP calls.
|
|
30
|
+
* - 'axios' uses axios client for HTTP requests.
|
|
31
|
+
* - 'fetch' uses native fetch API for HTTP requests.
|
|
32
|
+
* @default 'axios'
|
|
33
|
+
*/
|
|
34
|
+
client?: 'axios' | 'fetch';
|
|
35
|
+
importPath?: never;
|
|
36
|
+
} | {
|
|
37
|
+
client?: never;
|
|
38
|
+
/**
|
|
39
|
+
* Client import path for API calls.
|
|
40
|
+
* Used as `import client from '${importPath}'`.
|
|
41
|
+
* Accepts relative and absolute paths; path changes are not performed.
|
|
42
|
+
*/
|
|
43
|
+
importPath: string;
|
|
44
|
+
/**
|
|
45
|
+
* `bundle` has no effect when `importPath` is set.
|
|
46
|
+
* Use either `bundle` (with `client`) or `importPath`, not both.
|
|
47
|
+
*/
|
|
48
|
+
bundle?: never;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Discriminated union that ties `pathParamsType` to the `paramsType` values where it is meaningful.
|
|
52
|
+
*
|
|
53
|
+
* - `paramsType: 'object'` — all parameters (including path params) are merged into a single
|
|
54
|
+
* destructured object. `pathParamsType` is never reached in this code path and has no effect.
|
|
55
|
+
* - `paramsType?: 'inline'` (or omitted) — each parameter group is a separate function argument.
|
|
56
|
+
* `pathParamsType` controls whether the path-param group itself is destructured (`'object'`)
|
|
57
|
+
* or spread as individual arguments (`'inline'`).
|
|
58
|
+
*/
|
|
59
|
+
type ParamsTypeOptions = {
|
|
60
|
+
/**
|
|
61
|
+
* All parameters — path, query, headers, and body — are merged into a single
|
|
62
|
+
* destructured object argument.
|
|
63
|
+
* - 'object' returns the params and pathParams as an object.
|
|
64
|
+
* @default 'inline'
|
|
65
|
+
*/
|
|
66
|
+
paramsType: 'object';
|
|
67
|
+
/**
|
|
68
|
+
* `pathParamsType` has no effect when `paramsType` is `'object'`.
|
|
69
|
+
* Path params are already inside the single destructured object.
|
|
70
|
+
*/
|
|
71
|
+
pathParamsType?: never;
|
|
72
|
+
} | {
|
|
73
|
+
/**
|
|
74
|
+
* Each parameter group is emitted as a separate function argument.
|
|
75
|
+
* - 'inline' returns the params as comma separated params.
|
|
76
|
+
* @default 'inline'
|
|
77
|
+
*/
|
|
78
|
+
paramsType?: 'inline';
|
|
79
|
+
/**
|
|
80
|
+
* Controls how path parameters are arranged within the inline argument list.
|
|
81
|
+
* - 'object' groups path params into a destructured object: `{ petId }: PathParams`.
|
|
82
|
+
* - 'inline' emits each path param as its own argument: `petId: string`.
|
|
83
|
+
* @default 'inline'
|
|
84
|
+
*/
|
|
85
|
+
pathParamsType?: 'object' | 'inline';
|
|
86
|
+
};
|
|
87
|
+
type Options = {
|
|
88
|
+
/**
|
|
89
|
+
* Specify the export location for the files and define the behavior of the output.
|
|
90
|
+
* @default { path: 'clients', barrelType: 'named' }
|
|
91
|
+
*/
|
|
92
|
+
output?: Output;
|
|
93
|
+
/**
|
|
94
|
+
* Group the clients based on the provided name.
|
|
95
|
+
*/
|
|
96
|
+
group?: Group;
|
|
97
|
+
/**
|
|
98
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
99
|
+
*/
|
|
100
|
+
exclude?: Array<Exclude>;
|
|
101
|
+
/**
|
|
102
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
103
|
+
*/
|
|
104
|
+
include?: Array<Include>;
|
|
105
|
+
/**
|
|
106
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
107
|
+
*/
|
|
108
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
109
|
+
/**
|
|
110
|
+
* Create `operations.ts` file with all operations grouped by methods.
|
|
111
|
+
* @default false
|
|
112
|
+
*/
|
|
113
|
+
operations?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Export urls that are used by operation x.
|
|
116
|
+
* - 'export' makes them part of your barrel file.
|
|
117
|
+
* - false does not make them exportable.
|
|
118
|
+
* @default false
|
|
119
|
+
* @example getGetPetByIdUrl
|
|
120
|
+
*/
|
|
121
|
+
urlType?: 'export' | false;
|
|
122
|
+
/**
|
|
123
|
+
* Allows you to set a custom base url for all generated calls.
|
|
124
|
+
*/
|
|
125
|
+
baseURL?: string;
|
|
126
|
+
/**
|
|
127
|
+
* ReturnType that is used when calling the client.
|
|
128
|
+
* - 'data' returns ResponseConfig[data].
|
|
129
|
+
* - 'full' returns ResponseConfig.
|
|
130
|
+
* @default 'data'
|
|
131
|
+
*/
|
|
132
|
+
dataReturnType?: 'data' | 'full';
|
|
133
|
+
/**
|
|
134
|
+
* How to style your params, by default no casing is applied.
|
|
135
|
+
* - 'camelcase' uses camelCase for pathParams, queryParams and headerParams names
|
|
136
|
+
* @note response types (data/body) are not affected by this option
|
|
137
|
+
*/
|
|
138
|
+
paramsCasing?: 'camelcase';
|
|
139
|
+
/**
|
|
140
|
+
* Which parser can be used before returning the data.
|
|
141
|
+
* - 'client' returns the data as-is from the client.
|
|
142
|
+
* - 'zod' uses @kubb/plugin-zod to parse the data.
|
|
143
|
+
* @default 'client'
|
|
144
|
+
*/
|
|
145
|
+
parser?: 'client' | 'zod';
|
|
146
|
+
/**
|
|
147
|
+
* How to generate the client code.
|
|
148
|
+
* - 'function' generates standalone functions for each operation.
|
|
149
|
+
* - 'class' generates a class with methods for each operation.
|
|
150
|
+
* - 'staticClass' generates a class with static methods for each operation.
|
|
151
|
+
* @default 'function'
|
|
152
|
+
*/
|
|
153
|
+
clientType?: 'function' | 'class' | 'staticClass';
|
|
154
|
+
/**
|
|
155
|
+
* Bundle the selected client into the generated `.kubb` directory.
|
|
156
|
+
* When disabled the generated clients will import the shared runtime from `@kubb/plugin-client/clients/*`.
|
|
157
|
+
* @default false
|
|
158
|
+
* In version 5 of Kubb this is by default true
|
|
159
|
+
*/
|
|
160
|
+
bundle?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Generate an SDK facade class that composes all tag-based client classes into a single entry point.
|
|
163
|
+
* Setting this option automatically enables `clientType: 'class'`.
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* pluginClient({
|
|
167
|
+
* sdk: { className: 'PetStoreSDK' },
|
|
168
|
+
* })
|
|
169
|
+
* // Generates a class with a shared constructor config and one property per tag:
|
|
170
|
+
* // class PetStoreSDK {
|
|
171
|
+
* // readonly petController: petController
|
|
172
|
+
* // readonly storeController: storeController
|
|
173
|
+
* // constructor(config = {}) { ... }
|
|
174
|
+
* // }
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
sdk?: {
|
|
178
|
+
/**
|
|
179
|
+
* Name of the generated SDK facade class.
|
|
180
|
+
*/
|
|
181
|
+
className: string;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Override individual resolver methods. Any method you omit falls back to the
|
|
185
|
+
* preset resolver's implementation. Use `this.default(...)` to call it.
|
|
186
|
+
*/
|
|
187
|
+
resolver?: Partial<ResolverClient> & ThisType<ResolverClient>;
|
|
188
|
+
/**
|
|
189
|
+
* Single AST visitor applied to each node before printing.
|
|
190
|
+
* Return `null` or `undefined` from a method to leave the node unchanged.
|
|
191
|
+
*/
|
|
192
|
+
transformer?: ast.Visitor;
|
|
193
|
+
/**
|
|
194
|
+
* Define some generators next to the client generators.
|
|
195
|
+
*/
|
|
196
|
+
generators?: Array<Generator<PluginClient>>;
|
|
197
|
+
} & ClientImportPath & ParamsTypeOptions;
|
|
198
|
+
type ResolvedOptions = {
|
|
199
|
+
output: Output;
|
|
200
|
+
exclude: Array<Exclude>;
|
|
201
|
+
include: Array<Include> | undefined;
|
|
202
|
+
override: Array<Override<ResolvedOptions>>;
|
|
203
|
+
group: Group | undefined;
|
|
204
|
+
client: Options['client'];
|
|
205
|
+
clientType: NonNullable<Options['clientType']>;
|
|
206
|
+
bundle: NonNullable<Options['bundle']>;
|
|
207
|
+
parser: NonNullable<Options['parser']>;
|
|
208
|
+
urlType: NonNullable<Options['urlType']>;
|
|
209
|
+
importPath: Options['importPath'];
|
|
210
|
+
baseURL: Options['baseURL'];
|
|
211
|
+
dataReturnType: NonNullable<Options['dataReturnType']>;
|
|
212
|
+
pathParamsType: NonNullable<NonNullable<Options['pathParamsType']>>;
|
|
213
|
+
paramsType: NonNullable<Options['paramsType']>;
|
|
214
|
+
paramsCasing: Options['paramsCasing'];
|
|
215
|
+
sdk: Options['sdk'];
|
|
216
|
+
resolver: ResolverClient;
|
|
217
|
+
};
|
|
218
|
+
type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, ResolverClient>;
|
|
219
|
+
declare global {
|
|
220
|
+
namespace Kubb {
|
|
221
|
+
interface PluginRegistry {
|
|
222
|
+
'plugin-client': PluginClient;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
//#endregion
|
|
227
|
+
//#region src/components/Client.d.ts
|
|
228
|
+
type Props = {
|
|
229
|
+
name: string;
|
|
230
|
+
urlName?: string;
|
|
231
|
+
isExportable?: boolean;
|
|
232
|
+
isIndexable?: boolean;
|
|
233
|
+
isConfigurable?: boolean;
|
|
234
|
+
returnType?: string;
|
|
235
|
+
baseURL: string | undefined;
|
|
236
|
+
dataReturnType: PluginClient['resolvedOptions']['dataReturnType'];
|
|
237
|
+
paramsCasing: PluginClient['resolvedOptions']['paramsCasing'];
|
|
238
|
+
paramsType: PluginClient['resolvedOptions']['pathParamsType'];
|
|
239
|
+
pathParamsType: PluginClient['resolvedOptions']['pathParamsType'];
|
|
240
|
+
parser: PluginClient['resolvedOptions']['parser'] | undefined;
|
|
241
|
+
node: ast.OperationNode;
|
|
242
|
+
tsResolver: ResolverTs;
|
|
243
|
+
zodResolver?: ResolverZod;
|
|
244
|
+
children?: KubbReactNode;
|
|
245
|
+
};
|
|
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
|
+
declare function Client({
|
|
255
|
+
name,
|
|
256
|
+
isExportable,
|
|
257
|
+
isIndexable,
|
|
258
|
+
returnType,
|
|
259
|
+
baseURL,
|
|
260
|
+
dataReturnType,
|
|
261
|
+
parser,
|
|
262
|
+
paramsType,
|
|
263
|
+
paramsCasing,
|
|
264
|
+
pathParamsType,
|
|
265
|
+
node,
|
|
266
|
+
tsResolver,
|
|
267
|
+
zodResolver,
|
|
268
|
+
urlName,
|
|
269
|
+
children,
|
|
270
|
+
isConfigurable
|
|
271
|
+
}: 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
|
+
//#endregion
|
|
283
|
+
//#region src/generators/classClientGenerator.d.ts
|
|
284
|
+
declare const classClientGenerator: _$_kubb_core0.Generator<PluginClient, unknown>;
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/generators/clientGenerator.d.ts
|
|
287
|
+
declare const clientGenerator: _$_kubb_core0.Generator<PluginClient, unknown>;
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/generators/groupedClientGenerator.d.ts
|
|
290
|
+
declare const groupedClientGenerator: _$_kubb_core0.Generator<PluginClient, unknown>;
|
|
291
|
+
//#endregion
|
|
292
|
+
//#region src/generators/operationsGenerator.d.ts
|
|
293
|
+
declare const operationsGenerator: _$_kubb_core0.Generator<PluginClient, unknown>;
|
|
294
|
+
//#endregion
|
|
295
|
+
//#region src/generators/staticClassClientGenerator.d.ts
|
|
296
|
+
declare const staticClassClientGenerator: _$_kubb_core0.Generator<PluginClient, unknown>;
|
|
297
|
+
//#endregion
|
|
5
298
|
//#region src/plugin.d.ts
|
|
299
|
+
/**
|
|
300
|
+
* Canonical plugin name for `@kubb/plugin-client`, used in driver lookups and warnings.
|
|
301
|
+
*/
|
|
6
302
|
declare const pluginClientName = "plugin-client";
|
|
7
|
-
|
|
303
|
+
/**
|
|
304
|
+
* Generates type-safe HTTP client functions or classes from an OpenAPI specification.
|
|
305
|
+
* Creates client APIs by walking operations and delegating to generators.
|
|
306
|
+
* Writes barrel files based on the configured `barrelType`.
|
|
307
|
+
*
|
|
308
|
+
* @example Client generator
|
|
309
|
+
* ```ts
|
|
310
|
+
* import pluginClient from '@kubb/plugin-client'
|
|
311
|
+
* export default defineConfig({
|
|
312
|
+
* plugins: [pluginClient({ output: { path: 'clients' } })]
|
|
313
|
+
* })
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
declare const pluginClient: (options?: Options | undefined) => _$_kubb_core0.Plugin<PluginClient>;
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/resolvers/resolverClient.d.ts
|
|
319
|
+
/**
|
|
320
|
+
* Naming convention resolver for client plugin.
|
|
321
|
+
*
|
|
322
|
+
* Provides default naming helpers using camelCase for functions and file paths.
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* `resolverClient.default('list pets', 'function') // → 'listPets'`
|
|
326
|
+
*/
|
|
327
|
+
declare const resolverClient: ResolverClient;
|
|
8
328
|
//#endregion
|
|
9
|
-
export { type ClientImportPath, type PluginClient, pluginClient, pluginClientName };
|
|
329
|
+
export { Client, type ClientImportPath, type PluginClient, type ResolverClient, classClientGenerator, clientGenerator, pluginClient as default, pluginClient, groupedClientGenerator, operationsGenerator, pluginClientName, resolverClient, staticClassClientGenerator };
|
|
10
330
|
//# sourceMappingURL=index.d.ts.map
|