@kubb/plugin-zod 4.11.3 → 4.12.0

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.
@@ -6,7 +6,6 @@ import { OpenAPIV3 } from "openapi-types";
6
6
  import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
7
7
  import BaseOas from "oas";
8
8
  import { KubbFile } from "@kubb/fabric-core/types";
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/utils/EventEmitter.d.ts
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
- * Category of the debug log, used for GitHub Actions grouping
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
- category?: 'setup' | 'plugin' | 'hook' | 'schema' | 'file' | 'error';
112
+ 'lifecycle:start': [version: string];
87
113
  /**
88
- * Plugin name for grouping plugin-specific logs together
114
+ * Emitted at the end of the Kubb lifecycle, after all code generation is complete.
89
115
  */
90
- pluginName?: string;
116
+ 'lifecycle:end': [];
91
117
  /**
92
- * Indicates if this is the start or end of a plugin's execution
93
- * - 'start': Start of plugin execution group
94
- * - 'end': End of plugin execution group
118
+ * Emitted when configuration loading starts.
95
119
  */
96
- pluginGroupMarker?: 'start' | 'end';
97
- };
98
- type Events$1 = {
99
- start: [message: string];
100
- success: [message: string];
101
- error: [message: string, error: Error];
102
- warning: [message: string];
103
- debug: [DebugEvent];
104
- verbose: [DebugEvent];
105
- info: [message: string];
106
- progress_start: [{
107
- id: string;
108
- size: number;
109
- message?: string;
110
- }];
111
- progressed: [{
112
- id: string;
113
- message?: string;
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
- progress_stop: [{
116
- id: string;
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
- * Optional config name to show in CLI output
239
+ * Emitted when file processing completes.
240
+ * Contains the list of processed files.
122
241
  */
123
- name?: string;
124
- logLevel: LogLevel;
125
- consola?: ConsolaInstance;
126
- on: EventEmitter<Events$1>['on'];
127
- emit: EventEmitter<Events$1>['emit'];
128
- writeLogs: () => Promise<void>;
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
- logger: Logger;
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
- logger: Logger;
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
  */
@@ -911,7 +1024,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
911
1024
  fabric: Fabric;
912
1025
  oas: Oas;
913
1026
  pluginManager: PluginManager;
914
- logger?: Logger;
1027
+ events?: AsyncEventEmitter<KubbEvents>;
915
1028
  /**
916
1029
  * Current plugin
917
1030
  */
@@ -1016,7 +1129,7 @@ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
1016
1129
  override: Array<Override<TOptions>> | undefined;
1017
1130
  contentType: contentType | undefined;
1018
1131
  pluginManager: PluginManager;
1019
- logger?: Logger;
1132
+ events?: AsyncEventEmitter<KubbEvents>;
1020
1133
  /**
1021
1134
  * Current plugin
1022
1135
  */
@@ -1173,4 +1286,4 @@ type ResolvedOptions = {
1173
1286
  type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions>;
1174
1287
  //#endregion
1175
1288
  export { UserPluginWithLifeCycle as a, Schema as i, PluginZod as n, Operation$1 as o, ReactGenerator as r, SchemaObject$1 as s, Options as t };
1176
- //# sourceMappingURL=types-BIZhZG2K.d.ts.map
1289
+ //# sourceMappingURL=types-B3gAGpsj.d.ts.map