@kubb/plugin-client 4.11.3 → 4.12.1
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/{Operations-BVIrtQ0H.cjs → Operations-DWWtAt0R.cjs} +2 -2
- package/dist/Operations-DWWtAt0R.cjs.map +1 -0
- package/dist/{Operations-B6I1tCOx.js → Operations-hfmOLxuh.js} +2 -2
- package/dist/Operations-hfmOLxuh.js.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/components.js +1 -1
- package/dist/{generators-CsFgdAtO.js → generators-1GIwjncx.js} +2 -2
- package/dist/{generators-CsFgdAtO.js.map → generators-1GIwjncx.js.map} +1 -1
- package/dist/{generators-dDr1GP7q.cjs → generators-iy-47eUM.cjs} +2 -2
- package/dist/{generators-dDr1GP7q.cjs.map → generators-iy-47eUM.cjs.map} +1 -1
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +3 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/{types-HFFrUUbA.d.ts → types-RDkxaTi2.d.ts} +215 -102
- package/dist/{types-CvjnC2Dp.d.cts → types-g75-RjQa.d.cts} +215 -102
- package/package.json +8 -8
- package/src/components/Client.tsx +1 -1
- package/src/generators/__snapshots__/findByTagsWithTemplateString.ts +29 -0
- package/src/plugin.ts +1 -2
- package/dist/Operations-B6I1tCOx.js.map +0 -1
- package/dist/Operations-BVIrtQ0H.cjs.map +0 -1
|
@@ -6,7 +6,6 @@ import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
|
|
|
6
6
|
import BaseOas from "oas";
|
|
7
7
|
import { KubbFile } from "@kubb/fabric-core/types";
|
|
8
8
|
import { Fabric } from "@kubb/react-fabric";
|
|
9
|
-
import { ConsolaInstance, LogLevel } from "consola";
|
|
10
9
|
import { KubbNode } from "@kubb/react-fabric/types";
|
|
11
10
|
|
|
12
11
|
//#region ../oas/src/types.d.ts
|
|
@@ -58,75 +57,229 @@ declare abstract class BaseGenerator<TOptions = unknown, TContext = unknown> {
|
|
|
58
57
|
abstract build(...params: unknown[]): unknown;
|
|
59
58
|
}
|
|
60
59
|
//#endregion
|
|
61
|
-
//#region ../core/src/
|
|
62
|
-
declare class EventEmitter<TEvents extends Record<string, any>> {
|
|
63
|
-
#private;
|
|
64
|
-
constructor();
|
|
65
|
-
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
|
|
66
|
-
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
67
|
-
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
68
|
-
removeAll(): void;
|
|
69
|
-
}
|
|
70
|
-
//#endregion
|
|
71
|
-
//#region ../core/src/logger.d.ts
|
|
60
|
+
//#region ../core/src/Kubb.d.ts
|
|
72
61
|
type DebugEvent = {
|
|
73
62
|
date: Date;
|
|
74
63
|
logs: string[];
|
|
75
64
|
fileName?: string;
|
|
65
|
+
};
|
|
66
|
+
type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
67
|
+
hookName: H;
|
|
68
|
+
plugins: Array<Plugin>;
|
|
69
|
+
};
|
|
70
|
+
type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
71
|
+
hookName: H;
|
|
72
|
+
};
|
|
73
|
+
type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
74
|
+
strategy: Strategy;
|
|
75
|
+
hookName: H;
|
|
76
|
+
plugin: Plugin;
|
|
77
|
+
parameters?: unknown[] | undefined;
|
|
78
|
+
output?: unknown;
|
|
79
|
+
};
|
|
80
|
+
type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
81
|
+
duration: number;
|
|
82
|
+
strategy: Strategy;
|
|
83
|
+
hookName: H;
|
|
84
|
+
plugin: Plugin;
|
|
85
|
+
parameters?: unknown[] | undefined;
|
|
86
|
+
output?: unknown;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Events emitted during the Kubb code generation lifecycle.
|
|
90
|
+
* These events can be listened to for logging, progress tracking, and custom integrations.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* import type { AsyncEventEmitter } from '@kubb/core'
|
|
95
|
+
* import type { KubbEvents } from '@kubb/core'
|
|
96
|
+
*
|
|
97
|
+
* const events: AsyncEventEmitter<KubbEvents> = new AsyncEventEmitter()
|
|
98
|
+
*
|
|
99
|
+
* events.on('lifecycle:start', () => {
|
|
100
|
+
* console.log('Starting Kubb generation')
|
|
101
|
+
* })
|
|
102
|
+
*
|
|
103
|
+
* events.on('plugin:end', (plugin, duration) => {
|
|
104
|
+
* console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
|
|
105
|
+
* })
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
interface KubbEvents {
|
|
76
109
|
/**
|
|
77
|
-
*
|
|
78
|
-
* - 'setup': Initial configuration and environment setup
|
|
79
|
-
* - 'plugin': Plugin installation and execution
|
|
80
|
-
* - 'hook': Plugin hook execution details
|
|
81
|
-
* - 'schema': Schema parsing and generation
|
|
82
|
-
* - 'file': File operations (read/write/generate)
|
|
83
|
-
* - 'error': Error details and stack traces
|
|
84
|
-
* - undefined: Generic logs (always inline)
|
|
110
|
+
* Emitted at the beginning of the Kubb lifecycle, before any code generation starts.
|
|
85
111
|
*/
|
|
86
|
-
|
|
112
|
+
'lifecycle:start': [version: string];
|
|
87
113
|
/**
|
|
88
|
-
*
|
|
114
|
+
* Emitted at the end of the Kubb lifecycle, after all code generation is complete.
|
|
89
115
|
*/
|
|
90
|
-
|
|
116
|
+
'lifecycle:end': [];
|
|
91
117
|
/**
|
|
92
|
-
*
|
|
93
|
-
* - 'start': Start of plugin execution group
|
|
94
|
-
* - 'end': End of plugin execution group
|
|
118
|
+
* Emitted when configuration loading starts.
|
|
95
119
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
120
|
+
'config:start': [];
|
|
121
|
+
/**
|
|
122
|
+
* Emitted when configuration loading is complete.
|
|
123
|
+
*/
|
|
124
|
+
'config:end': [configs: Array<Config>];
|
|
125
|
+
/**
|
|
126
|
+
* Emitted when code generation phase starts.
|
|
127
|
+
*/
|
|
128
|
+
'generation:start': [config: Config];
|
|
129
|
+
/**
|
|
130
|
+
* Emitted when code generation phase completes.
|
|
131
|
+
*/
|
|
132
|
+
'generation:end': [Config: Config];
|
|
133
|
+
/**
|
|
134
|
+
* Emitted with a summary of the generation results.
|
|
135
|
+
* Contains summary lines, title, and success status.
|
|
136
|
+
*/
|
|
137
|
+
'generation:summary': [Config: Config, {
|
|
138
|
+
failedPlugins: Set<{
|
|
139
|
+
plugin: Plugin;
|
|
140
|
+
error: Error;
|
|
141
|
+
}>;
|
|
142
|
+
status: 'success' | 'failed';
|
|
143
|
+
hrStart: [number, number];
|
|
144
|
+
filesCreated: number;
|
|
145
|
+
pluginTimings?: Map<string, number>;
|
|
114
146
|
}];
|
|
115
|
-
|
|
116
|
-
|
|
147
|
+
/**
|
|
148
|
+
* Emitted when code formatting starts (e.g., running Biome or Prettier).
|
|
149
|
+
*/
|
|
150
|
+
'format:start': [];
|
|
151
|
+
/**
|
|
152
|
+
* Emitted when code formatting completes.
|
|
153
|
+
*/
|
|
154
|
+
'format:end': [];
|
|
155
|
+
/**
|
|
156
|
+
* Emitted when linting starts.
|
|
157
|
+
*/
|
|
158
|
+
'lint:start': [];
|
|
159
|
+
/**
|
|
160
|
+
* Emitted when linting completes.
|
|
161
|
+
*/
|
|
162
|
+
'lint:end': [];
|
|
163
|
+
/**
|
|
164
|
+
* Emitted when plugin hooks execution starts.
|
|
165
|
+
*/
|
|
166
|
+
'hooks:start': [];
|
|
167
|
+
/**
|
|
168
|
+
* Emitted when plugin hooks execution completes.
|
|
169
|
+
*/
|
|
170
|
+
'hooks:end': [];
|
|
171
|
+
/**
|
|
172
|
+
* Emitted when a single hook execution starts.
|
|
173
|
+
*/
|
|
174
|
+
'hook:start': [command: string];
|
|
175
|
+
/**
|
|
176
|
+
* Emitted to execute a hook command (e.g., format or lint).
|
|
177
|
+
* The callback should be invoked when the command completes.
|
|
178
|
+
*/
|
|
179
|
+
'hook:execute': [{
|
|
180
|
+
command: string | URL;
|
|
181
|
+
args?: readonly string[];
|
|
182
|
+
}, cb: () => void];
|
|
183
|
+
/**
|
|
184
|
+
* Emitted when a single hook execution completes.
|
|
185
|
+
*/
|
|
186
|
+
'hook:end': [command: string];
|
|
187
|
+
/**
|
|
188
|
+
* Emitted when a new version of Kubb is available.
|
|
189
|
+
*/
|
|
190
|
+
'version:new': [currentVersion: string, latestVersion: string];
|
|
191
|
+
/**
|
|
192
|
+
* Informational message event.
|
|
193
|
+
*/
|
|
194
|
+
info: [message: string, info?: string];
|
|
195
|
+
/**
|
|
196
|
+
* Error event. Emitted when an error occurs during code generation.
|
|
197
|
+
*/
|
|
198
|
+
error: [error: Error, meta?: Record<string, unknown>];
|
|
199
|
+
/**
|
|
200
|
+
* Success message event.
|
|
201
|
+
*/
|
|
202
|
+
success: [message: string, info?: string];
|
|
203
|
+
/**
|
|
204
|
+
* Warning message event.
|
|
205
|
+
*/
|
|
206
|
+
warn: [message: string, info?: string];
|
|
207
|
+
/**
|
|
208
|
+
* Debug event for detailed logging.
|
|
209
|
+
* Contains timestamp, log messages, and optional filename.
|
|
210
|
+
*/
|
|
211
|
+
debug: [meta: DebugEvent];
|
|
212
|
+
/**
|
|
213
|
+
* Emitted when file processing starts.
|
|
214
|
+
* Contains the list of files to be processed.
|
|
215
|
+
*/
|
|
216
|
+
'files:processing:start': [files: Array<KubbFile.ResolvedFile>];
|
|
217
|
+
/**
|
|
218
|
+
* Emitted for each file being processed, providing progress updates.
|
|
219
|
+
* Contains processed count, total count, percentage, and file details.
|
|
220
|
+
*/
|
|
221
|
+
'file:processing:update': [{
|
|
222
|
+
/** Number of files processed so far */
|
|
223
|
+
processed: number;
|
|
224
|
+
/** Total number of files to process */
|
|
225
|
+
total: number;
|
|
226
|
+
/** Processing percentage (0-100) */
|
|
227
|
+
percentage: number;
|
|
228
|
+
/** Optional source identifier */
|
|
229
|
+
source?: string;
|
|
230
|
+
/** The file being processed */
|
|
231
|
+
file: KubbFile.ResolvedFile;
|
|
232
|
+
/**
|
|
233
|
+
* Kubb configuration (not present in Fabric).
|
|
234
|
+
* Provides access to the current config during file processing.
|
|
235
|
+
*/
|
|
236
|
+
config: Config;
|
|
117
237
|
}];
|
|
118
|
-
};
|
|
119
|
-
type Logger = {
|
|
120
238
|
/**
|
|
121
|
-
*
|
|
239
|
+
* Emitted when file processing completes.
|
|
240
|
+
* Contains the list of processed files.
|
|
122
241
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
242
|
+
'files:processing:end': [files: KubbFile.ResolvedFile[]];
|
|
243
|
+
/**
|
|
244
|
+
* Emitted when a plugin starts executing.
|
|
245
|
+
*/
|
|
246
|
+
'plugin:start': [plugin: Plugin];
|
|
247
|
+
/**
|
|
248
|
+
* Emitted when a plugin completes execution.
|
|
249
|
+
*/
|
|
250
|
+
'plugin:end': [plugin: Plugin, duration: number];
|
|
251
|
+
/**
|
|
252
|
+
* Emitted when plugin hook progress tracking starts.
|
|
253
|
+
* Contains the hook name and list of plugins to execute.
|
|
254
|
+
*/
|
|
255
|
+
'plugins:hook:progress:start': [meta: ProgressStartMeta];
|
|
256
|
+
/**
|
|
257
|
+
* Emitted when plugin hook progress tracking ends.
|
|
258
|
+
* Contains the hook name that completed.
|
|
259
|
+
*/
|
|
260
|
+
'plugins:hook:progress:end': [meta: ProgressStopMeta];
|
|
261
|
+
/**
|
|
262
|
+
* Emitted when a plugin hook starts processing.
|
|
263
|
+
* Contains strategy, hook name, plugin, parameters, and output.
|
|
264
|
+
*/
|
|
265
|
+
'plugins:hook:processing:start': [meta: ExecutingMeta];
|
|
266
|
+
/**
|
|
267
|
+
* Emitted when a plugin hook completes processing.
|
|
268
|
+
* Contains duration, strategy, hook name, plugin, parameters, and output.
|
|
269
|
+
*/
|
|
270
|
+
'plugins:hook:processing:end': [meta: ExecutedMeta];
|
|
271
|
+
}
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region ../core/src/utils/AsyncEventEmitter.d.ts
|
|
274
|
+
declare class AsyncEventEmitter<TEvents extends Record<string, any>> {
|
|
275
|
+
#private;
|
|
276
|
+
constructor(maxListener?: number);
|
|
277
|
+
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
|
|
278
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
279
|
+
onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArgs: TEvents[TEventName]) => void): void;
|
|
280
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
281
|
+
removeAll(): void;
|
|
282
|
+
}
|
|
130
283
|
//#endregion
|
|
131
284
|
//#region ../core/src/utils/types.d.ts
|
|
132
285
|
type PossiblePromise<T> = Promise<T> | T;
|
|
@@ -390,7 +543,7 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
390
543
|
* merging multiple sources into the same output file
|
|
391
544
|
*/
|
|
392
545
|
upsertFile: (...file: Array<KubbFile.File>) => Promise<void>;
|
|
393
|
-
|
|
546
|
+
events: AsyncEventEmitter<KubbEvents>;
|
|
394
547
|
mode: KubbFile.Mode;
|
|
395
548
|
/**
|
|
396
549
|
* Current plugin
|
|
@@ -436,35 +589,6 @@ type Group = {
|
|
|
436
589
|
//#region ../core/src/PluginManager.d.ts
|
|
437
590
|
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
438
591
|
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
|
|
439
|
-
type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
440
|
-
strategy: Strategy;
|
|
441
|
-
hookName: H;
|
|
442
|
-
plugin: Plugin;
|
|
443
|
-
parameters?: unknown[] | undefined;
|
|
444
|
-
output?: unknown;
|
|
445
|
-
};
|
|
446
|
-
type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
447
|
-
duration: number;
|
|
448
|
-
strategy: Strategy;
|
|
449
|
-
hookName: H;
|
|
450
|
-
plugin: Plugin;
|
|
451
|
-
parameters?: unknown[] | undefined;
|
|
452
|
-
output?: unknown;
|
|
453
|
-
};
|
|
454
|
-
type ErrorMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
455
|
-
hookName: H;
|
|
456
|
-
duration: number;
|
|
457
|
-
strategy: Strategy;
|
|
458
|
-
parameters?: unknown[] | undefined;
|
|
459
|
-
plugin: Plugin;
|
|
460
|
-
};
|
|
461
|
-
type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
462
|
-
hookName: H;
|
|
463
|
-
plugins: Array<Plugin>;
|
|
464
|
-
};
|
|
465
|
-
type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
466
|
-
hookName: H;
|
|
467
|
-
};
|
|
468
592
|
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
469
593
|
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
470
594
|
result: Result;
|
|
@@ -472,19 +596,12 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
|
|
|
472
596
|
};
|
|
473
597
|
type Options$1 = {
|
|
474
598
|
fabric: Fabric;
|
|
475
|
-
|
|
599
|
+
events: AsyncEventEmitter<KubbEvents>;
|
|
476
600
|
/**
|
|
477
601
|
* @default Number.POSITIVE_INFINITY
|
|
478
602
|
*/
|
|
479
603
|
concurrency?: number;
|
|
480
604
|
};
|
|
481
|
-
type Events = {
|
|
482
|
-
progress_start: [meta: ProgressStartMeta];
|
|
483
|
-
progress_stop: [meta: ProgressStopMeta];
|
|
484
|
-
executing: [meta: ExecutingMeta];
|
|
485
|
-
executed: [meta: ExecutedMeta];
|
|
486
|
-
error: [error: Error, meta: ErrorMeta];
|
|
487
|
-
};
|
|
488
605
|
type GetFileProps<TOptions = object> = {
|
|
489
606
|
name: string;
|
|
490
607
|
mode?: KubbFile.Mode;
|
|
@@ -494,10 +611,10 @@ type GetFileProps<TOptions = object> = {
|
|
|
494
611
|
};
|
|
495
612
|
declare class PluginManager {
|
|
496
613
|
#private;
|
|
497
|
-
readonly events: EventEmitter<Events>;
|
|
498
614
|
readonly config: Config;
|
|
499
615
|
readonly options: Options$1;
|
|
500
616
|
constructor(config: Config, options: Options$1);
|
|
617
|
+
get events(): AsyncEventEmitter<KubbEvents>;
|
|
501
618
|
getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
|
|
502
619
|
get plugins(): Array<Plugin>;
|
|
503
620
|
getFile<TOptions = object>({
|
|
@@ -511,10 +628,6 @@ declare class PluginManager {
|
|
|
511
628
|
}>;
|
|
512
629
|
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
|
|
513
630
|
resolveName: (params: ResolveNameParams) => string;
|
|
514
|
-
/**
|
|
515
|
-
* Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
|
|
516
|
-
*/
|
|
517
|
-
on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
|
|
518
631
|
/**
|
|
519
632
|
* Run a specific hookName for plugin x.
|
|
520
633
|
*/
|
|
@@ -698,7 +811,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
698
811
|
override: Array<Override<TOptions>> | undefined;
|
|
699
812
|
contentType: contentType | undefined;
|
|
700
813
|
pluginManager: PluginManager;
|
|
701
|
-
|
|
814
|
+
events?: AsyncEventEmitter<KubbEvents>;
|
|
702
815
|
/**
|
|
703
816
|
* Current plugin
|
|
704
817
|
*/
|
|
@@ -942,7 +1055,7 @@ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
942
1055
|
fabric: Fabric;
|
|
943
1056
|
oas: Oas;
|
|
944
1057
|
pluginManager: PluginManager;
|
|
945
|
-
|
|
1058
|
+
events?: AsyncEventEmitter<KubbEvents>;
|
|
946
1059
|
/**
|
|
947
1060
|
* Current plugin
|
|
948
1061
|
*/
|
|
@@ -1170,4 +1283,4 @@ type ResolvedOptions = {
|
|
|
1170
1283
|
type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
1171
1284
|
//#endregion
|
|
1172
1285
|
export { UserPluginWithLifeCycle as a, OperationSchemas as i, PluginClient as n, Operation$1 as o, ReactGenerator as r, Options as t };
|
|
1173
|
-
//# sourceMappingURL=types-
|
|
1286
|
+
//# sourceMappingURL=types-g75-RjQa.d.cts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-client",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.12.1",
|
|
4
4
|
"description": "API client generator plugin for Kubb, creating type-safe HTTP clients (Axios, Fetch) from OpenAPI specifications for making API requests.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-client",
|
|
@@ -86,19 +86,19 @@
|
|
|
86
86
|
}
|
|
87
87
|
],
|
|
88
88
|
"dependencies": {
|
|
89
|
-
"@kubb/react-fabric": "0.
|
|
89
|
+
"@kubb/react-fabric": "0.7.0",
|
|
90
90
|
"jiti": "^2.6.1",
|
|
91
|
-
"@kubb/core": "4.
|
|
92
|
-
"@kubb/oas": "4.
|
|
93
|
-
"@kubb/plugin-oas": "4.
|
|
94
|
-
"@kubb/plugin-ts": "4.
|
|
95
|
-
"@kubb/plugin-zod": "4.
|
|
91
|
+
"@kubb/core": "4.12.1",
|
|
92
|
+
"@kubb/oas": "4.12.1",
|
|
93
|
+
"@kubb/plugin-oas": "4.12.1",
|
|
94
|
+
"@kubb/plugin-ts": "4.12.1",
|
|
95
|
+
"@kubb/plugin-zod": "4.12.1"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
98
|
"axios": "^1.13.2"
|
|
99
99
|
},
|
|
100
100
|
"peerDependencies": {
|
|
101
|
-
"@kubb/react-fabric": "0.
|
|
101
|
+
"@kubb/react-fabric": "0.7.0",
|
|
102
102
|
"axios": "^1.7.2"
|
|
103
103
|
},
|
|
104
104
|
"peerDependenciesMeta": {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint-disable no-alert, no-console */
|
|
2
|
+
/**
|
|
3
|
+
* Generated by Kubb (https://kubb.dev/).
|
|
4
|
+
* Do not edit manually.
|
|
5
|
+
*/
|
|
6
|
+
import type { RequestConfig, ResponseErrorConfig } from './test/.kubb/fetch'
|
|
7
|
+
import { fetch } from './test/.kubb/fetch'
|
|
8
|
+
|
|
9
|
+
export function getFindPetsByTagsUrl() {
|
|
10
|
+
const res = { method: 'GET', url: `${123456}/pet/findByTags` as const }
|
|
11
|
+
return res
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
|
16
|
+
* @summary Finds Pets by tags
|
|
17
|
+
* {@link /pet/findByTags}
|
|
18
|
+
*/
|
|
19
|
+
export async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {
|
|
20
|
+
const { client: request = fetch, ...requestConfig } = config
|
|
21
|
+
|
|
22
|
+
const res = await request<FindPetsByTagsQueryResponse, ResponseErrorConfig<FindPetsByTags400>, unknown>({
|
|
23
|
+
method: 'GET',
|
|
24
|
+
url: getFindPetsByTagsUrl().url.toString(),
|
|
25
|
+
params,
|
|
26
|
+
...requestConfig,
|
|
27
|
+
})
|
|
28
|
+
return res.data
|
|
29
|
+
}
|
package/src/plugin.ts
CHANGED
|
@@ -152,7 +152,7 @@ export const pluginClient = definePlugin<PluginClient>((options) => {
|
|
|
152
152
|
fabric: this.fabric,
|
|
153
153
|
oas,
|
|
154
154
|
pluginManager: this.pluginManager,
|
|
155
|
-
|
|
155
|
+
events: this.events,
|
|
156
156
|
plugin: this.plugin,
|
|
157
157
|
contentType,
|
|
158
158
|
exclude,
|
|
@@ -173,7 +173,6 @@ export const pluginClient = definePlugin<PluginClient>((options) => {
|
|
|
173
173
|
meta: {
|
|
174
174
|
pluginKey: this.plugin.key,
|
|
175
175
|
},
|
|
176
|
-
logger: this.logger,
|
|
177
176
|
})
|
|
178
177
|
|
|
179
178
|
await this.upsertFile(...barrelFiles)
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Operations-B6I1tCOx.js","names":["getParams","operationsObject: Record<string, { path: string; method: HttpMethod }>"],"sources":["../src/components/Url.tsx","../src/components/Client.tsx","../src/components/ClassClient.tsx","../src/components/Operations.tsx"],"sourcesContent":["import { URLPath } from '@kubb/core/utils'\n\nimport { isOptional, type Operation } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getPathParams } from '@kubb/plugin-oas/utils'\nimport { Const, File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\nimport type { PluginClient } from '../types.ts'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n isExportable?: boolean\n isIndexable?: boolean\n\n baseURL: string | undefined\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['pathParamsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n operation: Operation\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['paramsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {\n if (paramsType === 'object') {\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n },\n },\n })\n }\n\n return FunctionParams.factory({\n pathParams: typeSchemas.pathParams?.name\n ? {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n optional: isOptional(typeSchemas.pathParams?.schema),\n }\n : undefined,\n })\n}\n\nexport function Url({\n name,\n isExportable = true,\n isIndexable = true,\n typeSchemas,\n baseURL,\n paramsType,\n paramsCasing,\n pathParamsType,\n operation,\n}: Props): KubbNode {\n const path = new URLPath(operation.path, { casing: paramsCasing })\n const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })\n\n return (\n <File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>\n <Function name={name} export={isExportable} params={params.toConstructor()}>\n <Const name={'res'}>{`{ method: '${operation.method.toUpperCase()}', url: ${path.toTemplateString({ prefix: baseURL })} as const }`}</Const>\n <br />\n return res\n </Function>\n </File.Source>\n )\n}\n\nUrl.getParams = getParams\n","import { URLPath } from '@kubb/core/utils'\n\nimport { isOptional, type Operation } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getComments, getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\nimport type { PluginClient } from '../types.ts'\nimport { Url } from './Url.tsx'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n urlName?: string\n isExportable?: boolean\n isIndexable?: boolean\n isConfigurable?: boolean\n returnType?: string\n\n baseURL: string | undefined\n dataReturnType: PluginClient['resolvedOptions']['dataReturnType']\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['pathParamsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n typeSchemas: OperationSchemas\n zodSchemas: OperationSchemas | undefined\n operation: Operation\n children?: KubbNode\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['paramsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n isConfigurable: boolean\n}\n\nfunction getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable }: GetParamsProps) {\n if (paramsType === 'object') {\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n },\n },\n config: isConfigurable\n ? {\n type: typeSchemas.request?.name\n ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }`\n : 'Partial<RequestConfig> & { client?: typeof fetch }',\n default: '{}',\n }\n : undefined,\n })\n }\n\n return FunctionParams.factory({\n pathParams: typeSchemas.pathParams?.name\n ? {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n optional: isOptional(typeSchemas.pathParams?.schema),\n }\n : undefined,\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n config: isConfigurable\n ? {\n type: typeSchemas.request?.name\n ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }`\n : 'Partial<RequestConfig> & { client?: typeof fetch }',\n default: '{}',\n }\n : undefined,\n })\n}\n\nexport function Client({\n name,\n isExportable = true,\n isIndexable = true,\n returnType,\n typeSchemas,\n baseURL,\n dataReturnType,\n parser,\n zodSchemas,\n paramsType,\n paramsCasing,\n pathParamsType,\n operation,\n urlName,\n children,\n isConfigurable = true,\n}: Props): KubbNode {\n const path = new URLPath(operation.path, { casing: paramsCasing })\n const contentType = operation.getContentType()\n const isFormData = contentType === 'multipart/form-data'\n const headers = [\n contentType !== 'application/json' && contentType !== 'multipart/form-data' ? `'Content-Type': '${contentType}'` : undefined,\n typeSchemas.headerParams?.name ? '...headers' : undefined,\n ].filter(Boolean)\n\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n\n const generics = [typeSchemas.response.name, TError, typeSchemas.request?.name || 'unknown'].filter(Boolean)\n const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable })\n const urlParams = Url.getParams({\n paramsType,\n paramsCasing,\n pathParamsType,\n typeSchemas,\n })\n const clientParams = FunctionParams.factory({\n config: {\n mode: 'object',\n children: {\n method: {\n value: JSON.stringify(operation.method.toUpperCase()),\n },\n url: {\n value: urlName ? `${urlName}(${urlParams.toCall()}).url.toString()` : path.template,\n },\n baseURL:\n baseURL && !urlName\n ? {\n value: JSON.stringify(baseURL),\n }\n : undefined,\n params: typeSchemas.queryParams?.name ? {} : undefined,\n data: typeSchemas.request?.name\n ? {\n value: isFormData ? 'formData as FormData' : 'requestData',\n }\n : undefined,\n requestConfig: isConfigurable\n ? {\n mode: 'inlineSpread',\n }\n : undefined,\n headers: headers.length\n ? {\n value: isConfigurable ? `{ ${headers.join(', ')}, ...requestConfig.headers }` : `{ ${headers.join(', ')} }`,\n }\n : undefined,\n },\n },\n })\n\n const childrenElement = children ? (\n children\n ) : (\n <>\n {dataReturnType === 'full' && parser === 'zod' && zodSchemas && `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`}\n {dataReturnType === 'data' && parser === 'zod' && zodSchemas && `return ${zodSchemas.response.name}.parse(res.data)`}\n {dataReturnType === 'full' && parser === 'client' && 'return res'}\n {dataReturnType === 'data' && parser === 'client' && 'return res.data'}\n </>\n )\n\n return (\n <File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>\n <Function\n name={name}\n async\n export={isExportable}\n params={params.toConstructor()}\n JSDoc={{\n comments: getComments(operation),\n }}\n returnType={returnType}\n >\n {isConfigurable ? 'const { client: request = fetch, ...requestConfig } = config' : ''}\n <br />\n <br />\n {parser === 'zod' && zodSchemas?.request?.name\n ? `const requestData = ${zodSchemas.request.name}.parse(data)`\n : typeSchemas?.request?.name && 'const requestData = data'}\n <br />\n {isFormData && typeSchemas?.request?.name && 'const formData = buildFormData(requestData)'}\n <br />\n {isConfigurable\n ? `const res = await request<${generics.join(', ')}>(${clientParams.toCall()})`\n : `const res = await fetch<${generics.join(', ')}>(${clientParams.toCall()})`}\n <br />\n {childrenElement}\n </Function>\n </File.Source>\n )\n}\n\nClient.getParams = getParams\n","import { buildJSDoc, URLPath } from '@kubb/core/utils'\nimport type { Operation } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getComments } from '@kubb/plugin-oas/utils'\nimport { File, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\nimport type { PluginClient } from '../types.ts'\n\nimport { Client } from './Client.tsx'\n\ntype Props = {\n /**\n * Name of the class\n */\n name: string\n isExportable?: boolean\n isIndexable?: boolean\n operations: Array<{\n operation: Operation\n name: string\n typeSchemas: OperationSchemas\n zodSchemas: OperationSchemas | undefined\n }>\n baseURL: string | undefined\n dataReturnType: PluginClient['resolvedOptions']['dataReturnType']\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['pathParamsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n children?: KubbNode\n}\n\ntype GenerateMethodProps = {\n operation: Operation\n name: string\n typeSchemas: OperationSchemas\n zodSchemas: OperationSchemas | undefined\n baseURL: string | undefined\n dataReturnType: PluginClient['resolvedOptions']['dataReturnType']\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n paramsType: PluginClient['resolvedOptions']['paramsType']\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n}\n\nfunction buildHeaders(contentType: string, hasHeaderParams: boolean): Array<string> {\n return [\n contentType !== 'application/json' && contentType !== 'multipart/form-data' ? `'Content-Type': '${contentType}'` : undefined,\n hasHeaderParams ? '...headers' : undefined,\n ].filter(Boolean) as Array<string>\n}\n\nfunction buildGenerics(typeSchemas: OperationSchemas): Array<string> {\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n return [typeSchemas.response.name, TError, typeSchemas.request?.name || 'unknown'].filter(Boolean)\n}\n\nfunction buildClientParams({\n operation,\n path,\n baseURL,\n typeSchemas,\n isFormData,\n headers,\n}: {\n operation: Operation\n path: URLPath\n baseURL: string | undefined\n typeSchemas: OperationSchemas\n isFormData: boolean\n headers: Array<string>\n}) {\n return FunctionParams.factory({\n config: {\n mode: 'object',\n children: {\n method: {\n value: JSON.stringify(operation.method.toUpperCase()),\n },\n url: {\n value: path.template,\n },\n baseURL: baseURL\n ? {\n value: JSON.stringify(baseURL),\n }\n : undefined,\n params: typeSchemas.queryParams?.name ? {} : undefined,\n data: typeSchemas.request?.name\n ? {\n value: isFormData ? 'formData as FormData' : 'requestData',\n }\n : undefined,\n requestConfig: {\n mode: 'inlineSpread',\n },\n headers: headers.length\n ? {\n value: `{ ${headers.join(', ')}, ...requestConfig.headers }`,\n }\n : undefined,\n },\n },\n })\n}\n\nfunction buildRequestDataLine({\n parser,\n zodSchemas,\n typeSchemas,\n}: {\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n zodSchemas: OperationSchemas | undefined\n typeSchemas: OperationSchemas\n}): string {\n if (parser === 'zod' && zodSchemas?.request?.name) {\n return `const requestData = ${zodSchemas.request.name}.parse(data)`\n }\n if (typeSchemas?.request?.name) {\n return 'const requestData = data'\n }\n return ''\n}\n\nfunction buildFormDataLine(isFormData: boolean, hasRequest: boolean): string {\n return isFormData && hasRequest ? 'const formData = buildFormData(requestData)' : ''\n}\n\nfunction buildReturnStatement({\n dataReturnType,\n parser,\n zodSchemas,\n}: {\n dataReturnType: PluginClient['resolvedOptions']['dataReturnType']\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n zodSchemas: OperationSchemas | undefined\n}): string {\n if (dataReturnType === 'full' && parser === 'zod' && zodSchemas) {\n return `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`\n }\n if (dataReturnType === 'data' && parser === 'zod' && zodSchemas) {\n return `return ${zodSchemas.response.name}.parse(res.data)`\n }\n if (dataReturnType === 'full' && parser === 'client') {\n return 'return res'\n }\n return 'return res.data'\n}\n\nfunction generateMethod({\n operation,\n name,\n typeSchemas,\n zodSchemas,\n baseURL,\n dataReturnType,\n parser,\n paramsType,\n paramsCasing,\n pathParamsType,\n}: GenerateMethodProps): string {\n const path = new URLPath(operation.path, { casing: paramsCasing })\n const contentType = operation.getContentType()\n const isFormData = contentType === 'multipart/form-data'\n const headers = buildHeaders(contentType, !!typeSchemas.headerParams?.name)\n const generics = buildGenerics(typeSchemas)\n const params = ClassClient.getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable: true })\n const clientParams = buildClientParams({ operation, path, baseURL, typeSchemas, isFormData, headers })\n const jsdoc = buildJSDoc(getComments(operation))\n\n const requestDataLine = buildRequestDataLine({ parser, zodSchemas, typeSchemas })\n const formDataLine = buildFormDataLine(isFormData, !!typeSchemas?.request?.name)\n const returnStatement = buildReturnStatement({ dataReturnType, parser, zodSchemas })\n\n const methodBody = [\n 'const { client: request = this.#client, ...requestConfig } = config',\n '',\n requestDataLine,\n formDataLine,\n `const res = await request<${generics.join(', ')}>(${clientParams.toCall()})`,\n returnStatement,\n ]\n .filter(Boolean)\n .map((line) => ` ${line}`)\n .join('\\n')\n\n return `${jsdoc}async ${name}(${params.toConstructor()}) {\\n${methodBody}\\n }`\n}\n\nexport function ClassClient({\n name,\n isExportable = true,\n isIndexable = true,\n operations,\n baseURL,\n dataReturnType,\n parser,\n paramsType,\n paramsCasing,\n pathParamsType,\n children,\n}: Props): KubbNode {\n const methods = operations.map(({ operation, name: methodName, typeSchemas, zodSchemas }) =>\n generateMethod({\n operation,\n name: methodName,\n typeSchemas,\n zodSchemas,\n baseURL,\n dataReturnType,\n parser,\n paramsType,\n paramsCasing,\n pathParamsType,\n }),\n )\n\n const classCode = `export class ${name} {\n #client: typeof fetch\n\n constructor(config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {\n this.#client = config.client || fetch\n }\n\n${methods.join('\\n\\n')}\n}`\n\n return (\n <File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>\n {classCode}\n {children}\n </File.Source>\n )\n}\nClassClient.getParams = Client.getParams\n","import { URLPath } from '@kubb/core/utils'\nimport type { HttpMethod, Operation } from '@kubb/oas'\nimport { Const, File } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\n\ntype OperationsProps = {\n name: string\n operations: Array<Operation>\n}\n\nexport function Operations({ name, operations }: OperationsProps): KubbNode {\n const operationsObject: Record<string, { path: string; method: HttpMethod }> = {}\n\n operations.forEach((operation) => {\n operationsObject[operation.getOperationId()] = {\n path: new URLPath(operation.path).URL,\n method: operation.method,\n }\n })\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Const name={name} export>\n {JSON.stringify(operationsObject, undefined, 2)}\n </Const>\n </File.Source>\n )\n}\n"],"mappings":";;;;;;;AAgCA,SAASA,YAAU,EAAE,YAAY,cAAc,gBAAgB,eAA+B;AAC5F,KAAI,eAAe,SACjB,QAAO,eAAe,QAAQ,EAC5B,MAAM;EACJ,MAAM;EACN,UAAU,EACR,GAAG,cAAc,YAAY,YAAY;GAAE,OAAO;GAAM,QAAQ;GAAc,CAAC,EAChF;EACF,EACF,CAAC;AAGJ,QAAO,eAAe,QAAQ,EAC5B,YAAY,YAAY,YAAY,OAChC;EACE,MAAM,mBAAmB,WAAW,WAAW;EAC/C,UAAU,cAAc,YAAY,YAAY;GAAE,OAAO;GAAM,QAAQ;GAAc,CAAC;EACtF,UAAU,WAAW,YAAY,YAAY,OAAO;EACrD,GACD,QACL,CAAC;;AAGJ,SAAgB,IAAI,EAClB,MACA,eAAe,MACf,cAAc,MACd,aACA,SACA,YACA,cACA,gBACA,aACkB;CAClB,MAAM,OAAO,IAAI,QAAQ,UAAU,MAAM,EAAE,QAAQ,cAAc,CAAC;CAClE,MAAM,SAASA,YAAU;EAAE;EAAY;EAAc;EAAgB;EAAa,CAAC;AAEnF,QACE,oBA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EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC,CACH,CASO,KAAK,OAAO,CAAC;;AAGrB,QACE,qBAAC,KAAK;EAAa;EAAoB;EAA2B;aAC/D,WACA;GACW;;AAGlB,YAAY,YAAY,OAAO;;;;AChO/B,SAAgB,WAAW,EAAE,MAAM,cAAyC;CAC1E,MAAMC,mBAAyE,EAAE;AAEjF,YAAW,SAAS,cAAc;AAChC,mBAAiB,UAAU,gBAAgB,IAAI;GAC7C,MAAM,IAAI,QAAQ,UAAU,KAAK,CAAC;GAClC,QAAQ,UAAU;GACnB;GACD;AAEF,QACE,oBAAC,KAAK;EAAa;EAAM;EAAa;YACpC,oBAAC;GAAY;GAAM;aAChB,KAAK,UAAU,kBAAkB,QAAW,EAAE;IACzC;GACI"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Operations-BVIrtQ0H.cjs","names":["getParams","FunctionParams","URLPath","File","Function","Const","FunctionParams","URLPath","File","Function","FunctionParams","URLPath","File","operationsObject: Record<string, { path: string; method: HttpMethod }>","URLPath","File","Const"],"sources":["../src/components/Url.tsx","../src/components/Client.tsx","../src/components/ClassClient.tsx","../src/components/Operations.tsx"],"sourcesContent":["import { URLPath } from '@kubb/core/utils'\n\nimport { isOptional, type Operation } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getPathParams } from '@kubb/plugin-oas/utils'\nimport { Const, File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\nimport type { PluginClient } from '../types.ts'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n isExportable?: boolean\n isIndexable?: boolean\n\n baseURL: string | undefined\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['pathParamsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n operation: Operation\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['paramsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n}\n\nfunction getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {\n if (paramsType === 'object') {\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n },\n },\n })\n }\n\n return FunctionParams.factory({\n pathParams: typeSchemas.pathParams?.name\n ? {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n optional: isOptional(typeSchemas.pathParams?.schema),\n }\n : undefined,\n })\n}\n\nexport function Url({\n name,\n isExportable = true,\n isIndexable = true,\n typeSchemas,\n baseURL,\n paramsType,\n paramsCasing,\n pathParamsType,\n operation,\n}: Props): KubbNode {\n const path = new URLPath(operation.path, { casing: paramsCasing })\n const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })\n\n return (\n <File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>\n <Function name={name} export={isExportable} params={params.toConstructor()}>\n <Const name={'res'}>{`{ method: '${operation.method.toUpperCase()}', url: ${path.toTemplateString({ prefix: baseURL })} as const }`}</Const>\n <br />\n return res\n </Function>\n </File.Source>\n )\n}\n\nUrl.getParams = getParams\n","import { URLPath } from '@kubb/core/utils'\n\nimport { isOptional, type Operation } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getComments, getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\nimport type { PluginClient } from '../types.ts'\nimport { Url } from './Url.tsx'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n urlName?: string\n isExportable?: boolean\n isIndexable?: boolean\n isConfigurable?: boolean\n returnType?: string\n\n baseURL: string | undefined\n dataReturnType: PluginClient['resolvedOptions']['dataReturnType']\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['pathParamsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n typeSchemas: OperationSchemas\n zodSchemas: OperationSchemas | undefined\n operation: Operation\n children?: KubbNode\n}\n\ntype GetParamsProps = {\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['paramsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n typeSchemas: OperationSchemas\n isConfigurable: boolean\n}\n\nfunction getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable }: GetParamsProps) {\n if (paramsType === 'object') {\n return FunctionParams.factory({\n data: {\n mode: 'object',\n children: {\n ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n },\n },\n config: isConfigurable\n ? {\n type: typeSchemas.request?.name\n ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }`\n : 'Partial<RequestConfig> & { client?: typeof fetch }',\n default: '{}',\n }\n : undefined,\n })\n }\n\n return FunctionParams.factory({\n pathParams: typeSchemas.pathParams?.name\n ? {\n mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),\n optional: isOptional(typeSchemas.pathParams?.schema),\n }\n : undefined,\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n params: typeSchemas.queryParams?.name\n ? {\n type: typeSchemas.queryParams?.name,\n optional: isOptional(typeSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typeSchemas.headerParams?.name\n ? {\n type: typeSchemas.headerParams?.name,\n optional: isOptional(typeSchemas.headerParams?.schema),\n }\n : undefined,\n config: isConfigurable\n ? {\n type: typeSchemas.request?.name\n ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: typeof fetch }`\n : 'Partial<RequestConfig> & { client?: typeof fetch }',\n default: '{}',\n }\n : undefined,\n })\n}\n\nexport function Client({\n name,\n isExportable = true,\n isIndexable = true,\n returnType,\n typeSchemas,\n baseURL,\n dataReturnType,\n parser,\n zodSchemas,\n paramsType,\n paramsCasing,\n pathParamsType,\n operation,\n urlName,\n children,\n isConfigurable = true,\n}: Props): KubbNode {\n const path = new URLPath(operation.path, { casing: paramsCasing })\n const contentType = operation.getContentType()\n const isFormData = contentType === 'multipart/form-data'\n const headers = [\n contentType !== 'application/json' && contentType !== 'multipart/form-data' ? `'Content-Type': '${contentType}'` : undefined,\n typeSchemas.headerParams?.name ? '...headers' : undefined,\n ].filter(Boolean)\n\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n\n const generics = [typeSchemas.response.name, TError, typeSchemas.request?.name || 'unknown'].filter(Boolean)\n const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable })\n const urlParams = Url.getParams({\n paramsType,\n paramsCasing,\n pathParamsType,\n typeSchemas,\n })\n const clientParams = FunctionParams.factory({\n config: {\n mode: 'object',\n children: {\n method: {\n value: JSON.stringify(operation.method.toUpperCase()),\n },\n url: {\n value: urlName ? `${urlName}(${urlParams.toCall()}).url.toString()` : path.template,\n },\n baseURL:\n baseURL && !urlName\n ? {\n value: JSON.stringify(baseURL),\n }\n : undefined,\n params: typeSchemas.queryParams?.name ? {} : undefined,\n data: typeSchemas.request?.name\n ? {\n value: isFormData ? 'formData as FormData' : 'requestData',\n }\n : undefined,\n requestConfig: isConfigurable\n ? {\n mode: 'inlineSpread',\n }\n : undefined,\n headers: headers.length\n ? {\n value: isConfigurable ? `{ ${headers.join(', ')}, ...requestConfig.headers }` : `{ ${headers.join(', ')} }`,\n }\n : undefined,\n },\n },\n })\n\n const childrenElement = children ? (\n children\n ) : (\n <>\n {dataReturnType === 'full' && parser === 'zod' && zodSchemas && `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`}\n {dataReturnType === 'data' && parser === 'zod' && zodSchemas && `return ${zodSchemas.response.name}.parse(res.data)`}\n {dataReturnType === 'full' && parser === 'client' && 'return res'}\n {dataReturnType === 'data' && parser === 'client' && 'return res.data'}\n </>\n )\n\n return (\n <File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>\n <Function\n name={name}\n async\n export={isExportable}\n params={params.toConstructor()}\n JSDoc={{\n comments: getComments(operation),\n }}\n returnType={returnType}\n >\n {isConfigurable ? 'const { client: request = fetch, ...requestConfig } = config' : ''}\n <br />\n <br />\n {parser === 'zod' && zodSchemas?.request?.name\n ? `const requestData = ${zodSchemas.request.name}.parse(data)`\n : typeSchemas?.request?.name && 'const requestData = data'}\n <br />\n {isFormData && typeSchemas?.request?.name && 'const formData = buildFormData(requestData)'}\n <br />\n {isConfigurable\n ? `const res = await request<${generics.join(', ')}>(${clientParams.toCall()})`\n : `const res = await fetch<${generics.join(', ')}>(${clientParams.toCall()})`}\n <br />\n {childrenElement}\n </Function>\n </File.Source>\n )\n}\n\nClient.getParams = getParams\n","import { buildJSDoc, URLPath } from '@kubb/core/utils'\nimport type { Operation } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getComments } from '@kubb/plugin-oas/utils'\nimport { File, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\nimport type { PluginClient } from '../types.ts'\n\nimport { Client } from './Client.tsx'\n\ntype Props = {\n /**\n * Name of the class\n */\n name: string\n isExportable?: boolean\n isIndexable?: boolean\n operations: Array<{\n operation: Operation\n name: string\n typeSchemas: OperationSchemas\n zodSchemas: OperationSchemas | undefined\n }>\n baseURL: string | undefined\n dataReturnType: PluginClient['resolvedOptions']['dataReturnType']\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n paramsType: PluginClient['resolvedOptions']['pathParamsType']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n children?: KubbNode\n}\n\ntype GenerateMethodProps = {\n operation: Operation\n name: string\n typeSchemas: OperationSchemas\n zodSchemas: OperationSchemas | undefined\n baseURL: string | undefined\n dataReturnType: PluginClient['resolvedOptions']['dataReturnType']\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n paramsType: PluginClient['resolvedOptions']['paramsType']\n paramsCasing: PluginClient['resolvedOptions']['paramsCasing']\n pathParamsType: PluginClient['resolvedOptions']['pathParamsType']\n}\n\nfunction buildHeaders(contentType: string, hasHeaderParams: boolean): Array<string> {\n return [\n contentType !== 'application/json' && contentType !== 'multipart/form-data' ? `'Content-Type': '${contentType}'` : undefined,\n hasHeaderParams ? '...headers' : undefined,\n ].filter(Boolean) as Array<string>\n}\n\nfunction buildGenerics(typeSchemas: OperationSchemas): Array<string> {\n const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(' | ') || 'Error'}>`\n return [typeSchemas.response.name, TError, typeSchemas.request?.name || 'unknown'].filter(Boolean)\n}\n\nfunction buildClientParams({\n operation,\n path,\n baseURL,\n typeSchemas,\n isFormData,\n headers,\n}: {\n operation: Operation\n path: URLPath\n baseURL: string | undefined\n typeSchemas: OperationSchemas\n isFormData: boolean\n headers: Array<string>\n}) {\n return FunctionParams.factory({\n config: {\n mode: 'object',\n children: {\n method: {\n value: JSON.stringify(operation.method.toUpperCase()),\n },\n url: {\n value: path.template,\n },\n baseURL: baseURL\n ? {\n value: JSON.stringify(baseURL),\n }\n : undefined,\n params: typeSchemas.queryParams?.name ? {} : undefined,\n data: typeSchemas.request?.name\n ? {\n value: isFormData ? 'formData as FormData' : 'requestData',\n }\n : undefined,\n requestConfig: {\n mode: 'inlineSpread',\n },\n headers: headers.length\n ? {\n value: `{ ${headers.join(', ')}, ...requestConfig.headers }`,\n }\n : undefined,\n },\n },\n })\n}\n\nfunction buildRequestDataLine({\n parser,\n zodSchemas,\n typeSchemas,\n}: {\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n zodSchemas: OperationSchemas | undefined\n typeSchemas: OperationSchemas\n}): string {\n if (parser === 'zod' && zodSchemas?.request?.name) {\n return `const requestData = ${zodSchemas.request.name}.parse(data)`\n }\n if (typeSchemas?.request?.name) {\n return 'const requestData = data'\n }\n return ''\n}\n\nfunction buildFormDataLine(isFormData: boolean, hasRequest: boolean): string {\n return isFormData && hasRequest ? 'const formData = buildFormData(requestData)' : ''\n}\n\nfunction buildReturnStatement({\n dataReturnType,\n parser,\n zodSchemas,\n}: {\n dataReturnType: PluginClient['resolvedOptions']['dataReturnType']\n parser: PluginClient['resolvedOptions']['parser'] | undefined\n zodSchemas: OperationSchemas | undefined\n}): string {\n if (dataReturnType === 'full' && parser === 'zod' && zodSchemas) {\n return `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`\n }\n if (dataReturnType === 'data' && parser === 'zod' && zodSchemas) {\n return `return ${zodSchemas.response.name}.parse(res.data)`\n }\n if (dataReturnType === 'full' && parser === 'client') {\n return 'return res'\n }\n return 'return res.data'\n}\n\nfunction generateMethod({\n operation,\n name,\n typeSchemas,\n zodSchemas,\n baseURL,\n dataReturnType,\n parser,\n paramsType,\n paramsCasing,\n pathParamsType,\n}: GenerateMethodProps): string {\n const path = new URLPath(operation.path, { casing: paramsCasing })\n const contentType = operation.getContentType()\n const isFormData = contentType === 'multipart/form-data'\n const headers = buildHeaders(contentType, !!typeSchemas.headerParams?.name)\n const generics = buildGenerics(typeSchemas)\n const params = ClassClient.getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable: true })\n const clientParams = buildClientParams({ operation, path, baseURL, typeSchemas, isFormData, headers })\n const jsdoc = buildJSDoc(getComments(operation))\n\n const requestDataLine = buildRequestDataLine({ parser, zodSchemas, typeSchemas })\n const formDataLine = buildFormDataLine(isFormData, !!typeSchemas?.request?.name)\n const returnStatement = buildReturnStatement({ dataReturnType, parser, zodSchemas })\n\n const methodBody = [\n 'const { client: request = this.#client, ...requestConfig } = config',\n '',\n requestDataLine,\n formDataLine,\n `const res = await request<${generics.join(', ')}>(${clientParams.toCall()})`,\n returnStatement,\n ]\n .filter(Boolean)\n .map((line) => ` ${line}`)\n .join('\\n')\n\n return `${jsdoc}async ${name}(${params.toConstructor()}) {\\n${methodBody}\\n }`\n}\n\nexport function ClassClient({\n name,\n isExportable = true,\n isIndexable = true,\n operations,\n baseURL,\n dataReturnType,\n parser,\n paramsType,\n paramsCasing,\n pathParamsType,\n children,\n}: Props): KubbNode {\n const methods = operations.map(({ operation, name: methodName, typeSchemas, zodSchemas }) =>\n generateMethod({\n operation,\n name: methodName,\n typeSchemas,\n zodSchemas,\n baseURL,\n dataReturnType,\n parser,\n paramsType,\n paramsCasing,\n pathParamsType,\n }),\n )\n\n const classCode = `export class ${name} {\n #client: typeof fetch\n\n constructor(config: Partial<RequestConfig> & { client?: typeof fetch } = {}) {\n this.#client = config.client || fetch\n }\n\n${methods.join('\\n\\n')}\n}`\n\n return (\n <File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>\n {classCode}\n {children}\n </File.Source>\n )\n}\nClassClient.getParams = Client.getParams\n","import { URLPath } from '@kubb/core/utils'\nimport type { HttpMethod, Operation } from '@kubb/oas'\nimport { Const, File } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\n\ntype OperationsProps = {\n name: string\n operations: Array<Operation>\n}\n\nexport function Operations({ name, operations }: OperationsProps): KubbNode {\n const operationsObject: Record<string, { path: string; method: HttpMethod }> = {}\n\n operations.forEach((operation) => {\n operationsObject[operation.getOperationId()] = {\n path: new URLPath(operation.path).URL,\n method: operation.method,\n }\n })\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Const name={name} export>\n {JSON.stringify(operationsObject, undefined, 2)}\n </Const>\n </File.Source>\n )\n}\n"],"mappings":";;;;;;;;AAgCA,SAASA,YAAU,EAAE,YAAY,cAAc,gBAAgB,eAA+B;AAC5F,KAAI,eAAe,SACjB,QAAOC,mCAAe,QAAQ,EAC5B,MAAM;EACJ,MAAM;EACN,UAAU,EACR,8CAAiB,YAAY,YAAY;GAAE,OAAO;GAAM,QAAQ;GAAc,CAAC,EAChF;EACF,EACF,CAAC;AAGJ,QAAOA,mCAAe,QAAQ,EAC5B,YAAY,YAAY,YAAY,OAChC;EACE,MAAM,mBAAmB,WAAW,WAAW;EAC/C,qDAAwB,YAAY,YAAY;GAAE,OAAO;GAAM,QAAQ;GAAc,CAAC;EACtF,qCAAqB,YAAY,YAAY,OAAO;EACrD,GACD,QACL,CAAC;;AAGJ,SAAgB,IAAI,EAClB,MACA,eAAe,MACf,cAAc,MACd,aACA,SACA,YACA,cACA,gBACA,aACkB;CAClB,MAAM,OAAO,IAAIC,0BAAQ,UAAU,MAAM,EAAE,QAAQ,cAAc,CAAC;CAClE,MAAM,SAASF,YAAU;EAAE;EAAY;EAAc;EAAgB;EAAa,CAAC;AAEnF,QACE,yDAACG,yBAAK;EAAa;EAAoB;EAA2B;YAChE,0DAACC;GAAe;GAAM,QAAQ;GAAc,QAAQ,OAAO,eAAe;;IACxE,yDAACC;KAAM,MAAM;eAAQ,cAAc,UAAU,OAAO,aAAa,CAAC,UAAU,KAAK,iBAAiB,EAAE,QAAQ,SAAS,CAAC,CAAC;MAAqB;IAC5I,yDAAC,SAAK;;;IAEG;GACC;;AAIlB,IAAI,YAAYL;;;;ACvChB,SAAS,UAAU,EAAE,YAAY,cAAc,gBAAgB,aAAa,kBAAkC;AAC5G,KAAI,eAAe,SACjB,QAAOM,mCAAe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