@kubb/plugin-msw 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.
@@ -1,4 +1,4 @@
1
- import { m as Operation } from "./index-BSYdDKeZ.cjs";
1
+ import { h as Operation } from "./index-CH9QiCej.cjs";
2
2
  import { KubbNode } from "@kubb/react-fabric/types";
3
3
 
4
4
  //#region src/components/Handlers.d.ts
@@ -1,4 +1,4 @@
1
- import { m as Operation } from "./index-B8yvSsLX.js";
1
+ import { h as Operation } from "./index-pe4_JZ3K.js";
2
2
  import { KubbNode } from "@kubb/react-fabric/types";
3
3
 
4
4
  //#region src/components/Handlers.d.ts
@@ -1,5 +1,5 @@
1
- import "./index-BSYdDKeZ.cjs";
2
- import { n as PluginMsw, r as ReactGenerator } from "./types-MDRyMp8X.cjs";
1
+ import "./index-CH9QiCej.cjs";
2
+ import { n as PluginMsw, r as ReactGenerator } from "./types-CZnA5aRm.cjs";
3
3
 
4
4
  //#region src/generators/handlersGenerator.d.ts
5
5
  declare const handlersGenerator: ReactGenerator<PluginMsw>;
@@ -1,5 +1,5 @@
1
- import "./index-B8yvSsLX.js";
2
- import { n as PluginMsw, r as ReactGenerator } from "./types-BUzgaOhd.js";
1
+ import "./index-pe4_JZ3K.js";
2
+ import { n as PluginMsw, r as ReactGenerator } from "./types-CSdstWCA.js";
3
3
 
4
4
  //#region src/generators/handlersGenerator.d.ts
5
5
  declare const handlersGenerator: ReactGenerator<PluginMsw>;
@@ -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
 
11
10
  //#region ../oas/src/types.d.ts
12
11
  type contentType = 'application/json' | (string & {});
@@ -57,75 +56,229 @@ declare abstract class BaseGenerator<TOptions = unknown, TContext = unknown> {
57
56
  abstract build(...params: unknown[]): unknown;
58
57
  }
59
58
  //#endregion
60
- //#region ../core/src/utils/EventEmitter.d.ts
61
- declare class EventEmitter<TEvents extends Record<string, any>> {
62
- #private;
63
- constructor();
64
- emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
65
- on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
66
- off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
67
- removeAll(): void;
68
- }
69
- //#endregion
70
- //#region ../core/src/logger.d.ts
59
+ //#region ../core/src/Kubb.d.ts
71
60
  type DebugEvent = {
72
61
  date: Date;
73
62
  logs: string[];
74
63
  fileName?: string;
64
+ };
65
+ type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
66
+ hookName: H;
67
+ plugins: Array<Plugin>;
68
+ };
69
+ type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
70
+ hookName: H;
71
+ };
72
+ type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
73
+ strategy: Strategy;
74
+ hookName: H;
75
+ plugin: Plugin;
76
+ parameters?: unknown[] | undefined;
77
+ output?: unknown;
78
+ };
79
+ type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
80
+ duration: number;
81
+ strategy: Strategy;
82
+ hookName: H;
83
+ plugin: Plugin;
84
+ parameters?: unknown[] | undefined;
85
+ output?: unknown;
86
+ };
87
+ /**
88
+ * Events emitted during the Kubb code generation lifecycle.
89
+ * These events can be listened to for logging, progress tracking, and custom integrations.
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * import type { AsyncEventEmitter } from '@kubb/core'
94
+ * import type { KubbEvents } from '@kubb/core'
95
+ *
96
+ * const events: AsyncEventEmitter<KubbEvents> = new AsyncEventEmitter()
97
+ *
98
+ * events.on('lifecycle:start', () => {
99
+ * console.log('Starting Kubb generation')
100
+ * })
101
+ *
102
+ * events.on('plugin:end', (plugin, duration) => {
103
+ * console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
104
+ * })
105
+ * ```
106
+ */
107
+ interface KubbEvents {
75
108
  /**
76
- * Category of the debug log, used for GitHub Actions grouping
77
- * - 'setup': Initial configuration and environment setup
78
- * - 'plugin': Plugin installation and execution
79
- * - 'hook': Plugin hook execution details
80
- * - 'schema': Schema parsing and generation
81
- * - 'file': File operations (read/write/generate)
82
- * - 'error': Error details and stack traces
83
- * - undefined: Generic logs (always inline)
109
+ * Emitted at the beginning of the Kubb lifecycle, before any code generation starts.
84
110
  */
85
- category?: 'setup' | 'plugin' | 'hook' | 'schema' | 'file' | 'error';
111
+ 'lifecycle:start': [version: string];
86
112
  /**
87
- * Plugin name for grouping plugin-specific logs together
113
+ * Emitted at the end of the Kubb lifecycle, after all code generation is complete.
88
114
  */
89
- pluginName?: string;
115
+ 'lifecycle:end': [];
90
116
  /**
91
- * Indicates if this is the start or end of a plugin's execution
92
- * - 'start': Start of plugin execution group
93
- * - 'end': End of plugin execution group
117
+ * Emitted when configuration loading starts.
94
118
  */
95
- pluginGroupMarker?: 'start' | 'end';
96
- };
97
- type Events$1 = {
98
- start: [message: string];
99
- success: [message: string];
100
- error: [message: string, error: Error];
101
- warning: [message: string];
102
- debug: [DebugEvent];
103
- verbose: [DebugEvent];
104
- info: [message: string];
105
- progress_start: [{
106
- id: string;
107
- size: number;
108
- message?: string;
109
- }];
110
- progressed: [{
111
- id: string;
112
- message?: string;
119
+ 'config:start': [];
120
+ /**
121
+ * Emitted when configuration loading is complete.
122
+ */
123
+ 'config:end': [configs: Array<Config>];
124
+ /**
125
+ * Emitted when code generation phase starts.
126
+ */
127
+ 'generation:start': [config: Config];
128
+ /**
129
+ * Emitted when code generation phase completes.
130
+ */
131
+ 'generation:end': [Config: Config];
132
+ /**
133
+ * Emitted with a summary of the generation results.
134
+ * Contains summary lines, title, and success status.
135
+ */
136
+ 'generation:summary': [Config: Config, {
137
+ failedPlugins: Set<{
138
+ plugin: Plugin;
139
+ error: Error;
140
+ }>;
141
+ status: 'success' | 'failed';
142
+ hrStart: [number, number];
143
+ filesCreated: number;
144
+ pluginTimings?: Map<string, number>;
113
145
  }];
114
- progress_stop: [{
115
- id: string;
146
+ /**
147
+ * Emitted when code formatting starts (e.g., running Biome or Prettier).
148
+ */
149
+ 'format:start': [];
150
+ /**
151
+ * Emitted when code formatting completes.
152
+ */
153
+ 'format:end': [];
154
+ /**
155
+ * Emitted when linting starts.
156
+ */
157
+ 'lint:start': [];
158
+ /**
159
+ * Emitted when linting completes.
160
+ */
161
+ 'lint:end': [];
162
+ /**
163
+ * Emitted when plugin hooks execution starts.
164
+ */
165
+ 'hooks:start': [];
166
+ /**
167
+ * Emitted when plugin hooks execution completes.
168
+ */
169
+ 'hooks:end': [];
170
+ /**
171
+ * Emitted when a single hook execution starts.
172
+ */
173
+ 'hook:start': [command: string];
174
+ /**
175
+ * Emitted to execute a hook command (e.g., format or lint).
176
+ * The callback should be invoked when the command completes.
177
+ */
178
+ 'hook:execute': [{
179
+ command: string | URL;
180
+ args?: readonly string[];
181
+ }, cb: () => void];
182
+ /**
183
+ * Emitted when a single hook execution completes.
184
+ */
185
+ 'hook:end': [command: string];
186
+ /**
187
+ * Emitted when a new version of Kubb is available.
188
+ */
189
+ 'version:new': [currentVersion: string, latestVersion: string];
190
+ /**
191
+ * Informational message event.
192
+ */
193
+ info: [message: string, info?: string];
194
+ /**
195
+ * Error event. Emitted when an error occurs during code generation.
196
+ */
197
+ error: [error: Error, meta?: Record<string, unknown>];
198
+ /**
199
+ * Success message event.
200
+ */
201
+ success: [message: string, info?: string];
202
+ /**
203
+ * Warning message event.
204
+ */
205
+ warn: [message: string, info?: string];
206
+ /**
207
+ * Debug event for detailed logging.
208
+ * Contains timestamp, log messages, and optional filename.
209
+ */
210
+ debug: [meta: DebugEvent];
211
+ /**
212
+ * Emitted when file processing starts.
213
+ * Contains the list of files to be processed.
214
+ */
215
+ 'files:processing:start': [files: Array<KubbFile.ResolvedFile>];
216
+ /**
217
+ * Emitted for each file being processed, providing progress updates.
218
+ * Contains processed count, total count, percentage, and file details.
219
+ */
220
+ 'file:processing:update': [{
221
+ /** Number of files processed so far */
222
+ processed: number;
223
+ /** Total number of files to process */
224
+ total: number;
225
+ /** Processing percentage (0-100) */
226
+ percentage: number;
227
+ /** Optional source identifier */
228
+ source?: string;
229
+ /** The file being processed */
230
+ file: KubbFile.ResolvedFile;
231
+ /**
232
+ * Kubb configuration (not present in Fabric).
233
+ * Provides access to the current config during file processing.
234
+ */
235
+ config: Config;
116
236
  }];
117
- };
118
- type Logger = {
119
237
  /**
120
- * Optional config name to show in CLI output
238
+ * Emitted when file processing completes.
239
+ * Contains the list of processed files.
121
240
  */
122
- name?: string;
123
- logLevel: LogLevel;
124
- consola?: ConsolaInstance;
125
- on: EventEmitter<Events$1>['on'];
126
- emit: EventEmitter<Events$1>['emit'];
127
- writeLogs: () => Promise<void>;
128
- };
241
+ 'files:processing:end': [files: KubbFile.ResolvedFile[]];
242
+ /**
243
+ * Emitted when a plugin starts executing.
244
+ */
245
+ 'plugin:start': [plugin: Plugin];
246
+ /**
247
+ * Emitted when a plugin completes execution.
248
+ */
249
+ 'plugin:end': [plugin: Plugin, duration: number];
250
+ /**
251
+ * Emitted when plugin hook progress tracking starts.
252
+ * Contains the hook name and list of plugins to execute.
253
+ */
254
+ 'plugins:hook:progress:start': [meta: ProgressStartMeta];
255
+ /**
256
+ * Emitted when plugin hook progress tracking ends.
257
+ * Contains the hook name that completed.
258
+ */
259
+ 'plugins:hook:progress:end': [meta: ProgressStopMeta];
260
+ /**
261
+ * Emitted when a plugin hook starts processing.
262
+ * Contains strategy, hook name, plugin, parameters, and output.
263
+ */
264
+ 'plugins:hook:processing:start': [meta: ExecutingMeta];
265
+ /**
266
+ * Emitted when a plugin hook completes processing.
267
+ * Contains duration, strategy, hook name, plugin, parameters, and output.
268
+ */
269
+ 'plugins:hook:processing:end': [meta: ExecutedMeta];
270
+ }
271
+ //#endregion
272
+ //#region ../core/src/utils/AsyncEventEmitter.d.ts
273
+ declare class AsyncEventEmitter<TEvents extends Record<string, any>> {
274
+ #private;
275
+ constructor(maxListener?: number);
276
+ emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
277
+ on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
278
+ onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArgs: TEvents[TEventName]) => void): void;
279
+ off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
280
+ removeAll(): void;
281
+ }
129
282
  //#endregion
130
283
  //#region ../core/src/utils/types.d.ts
131
284
  type PossiblePromise<T> = Promise<T> | T;
@@ -389,7 +542,7 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
389
542
  * merging multiple sources into the same output file
390
543
  */
391
544
  upsertFile: (...file: Array<KubbFile.File>) => Promise<void>;
392
- logger: Logger;
545
+ events: AsyncEventEmitter<KubbEvents>;
393
546
  mode: KubbFile.Mode;
394
547
  /**
395
548
  * Current plugin
@@ -435,35 +588,6 @@ type Group = {
435
588
  //#region ../core/src/PluginManager.d.ts
436
589
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
437
590
  type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
438
- type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
439
- strategy: Strategy;
440
- hookName: H;
441
- plugin: Plugin;
442
- parameters?: unknown[] | undefined;
443
- output?: unknown;
444
- };
445
- type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
446
- duration: number;
447
- strategy: Strategy;
448
- hookName: H;
449
- plugin: Plugin;
450
- parameters?: unknown[] | undefined;
451
- output?: unknown;
452
- };
453
- type ErrorMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
454
- hookName: H;
455
- duration: number;
456
- strategy: Strategy;
457
- parameters?: unknown[] | undefined;
458
- plugin: Plugin;
459
- };
460
- type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
461
- hookName: H;
462
- plugins: Array<Plugin>;
463
- };
464
- type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
465
- hookName: H;
466
- };
467
591
  type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
468
592
  type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
469
593
  result: Result;
@@ -471,19 +595,12 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
471
595
  };
472
596
  type Options = {
473
597
  fabric: Fabric;
474
- logger: Logger;
598
+ events: AsyncEventEmitter<KubbEvents>;
475
599
  /**
476
600
  * @default Number.POSITIVE_INFINITY
477
601
  */
478
602
  concurrency?: number;
479
603
  };
480
- type Events = {
481
- progress_start: [meta: ProgressStartMeta];
482
- progress_stop: [meta: ProgressStopMeta];
483
- executing: [meta: ExecutingMeta];
484
- executed: [meta: ExecutedMeta];
485
- error: [error: Error, meta: ErrorMeta];
486
- };
487
604
  type GetFileProps<TOptions = object> = {
488
605
  name: string;
489
606
  mode?: KubbFile.Mode;
@@ -493,10 +610,10 @@ type GetFileProps<TOptions = object> = {
493
610
  };
494
611
  declare class PluginManager {
495
612
  #private;
496
- readonly events: EventEmitter<Events>;
497
613
  readonly config: Config;
498
614
  readonly options: Options;
499
615
  constructor(config: Config, options: Options);
616
+ get events(): AsyncEventEmitter<KubbEvents>;
500
617
  getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
501
618
  get plugins(): Array<Plugin>;
502
619
  getFile<TOptions = object>({
@@ -510,10 +627,6 @@ declare class PluginManager {
510
627
  }>;
511
628
  resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
512
629
  resolveName: (params: ResolveNameParams) => string;
513
- /**
514
- * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
515
- */
516
- on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
517
630
  /**
518
631
  * Run a specific hookName for plugin x.
519
632
  */
@@ -591,5 +704,5 @@ type FileMetaBase = {
591
704
  pluginKey?: Plugin['key'];
592
705
  };
593
706
  //#endregion
594
- export { Output as a, ResolveNameParams as c, BaseGenerator as d, Oas as f, contentType as g, SchemaObject$1 as h, Group as i, UserPluginWithLifeCycle as l, Operation$1 as m, PluginManager as n, Plugin as o, HttpMethod as p, Config as r, PluginFactoryOptions as s, FileMetaBase as t, Logger as u };
595
- //# sourceMappingURL=index-BSYdDKeZ.d.cts.map
707
+ export { contentType as _, Output as a, ResolveNameParams as c, KubbEvents as d, BaseGenerator as f, SchemaObject$1 as g, Operation$1 as h, Group as i, UserPluginWithLifeCycle as l, HttpMethod as m, PluginManager as n, Plugin as o, Oas as p, Config as r, PluginFactoryOptions as s, FileMetaBase as t, AsyncEventEmitter as u };
708
+ //# sourceMappingURL=index-CH9QiCej.d.cts.map
@@ -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
 
11
10
  //#region ../oas/src/types.d.ts
12
11
  type contentType = 'application/json' | (string & {});
@@ -57,75 +56,229 @@ declare abstract class BaseGenerator<TOptions = unknown, TContext = unknown> {
57
56
  abstract build(...params: unknown[]): unknown;
58
57
  }
59
58
  //#endregion
60
- //#region ../core/src/utils/EventEmitter.d.ts
61
- declare class EventEmitter<TEvents extends Record<string, any>> {
62
- #private;
63
- constructor();
64
- emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
65
- on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
66
- off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
67
- removeAll(): void;
68
- }
69
- //#endregion
70
- //#region ../core/src/logger.d.ts
59
+ //#region ../core/src/Kubb.d.ts
71
60
  type DebugEvent = {
72
61
  date: Date;
73
62
  logs: string[];
74
63
  fileName?: string;
64
+ };
65
+ type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
66
+ hookName: H;
67
+ plugins: Array<Plugin>;
68
+ };
69
+ type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
70
+ hookName: H;
71
+ };
72
+ type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
73
+ strategy: Strategy;
74
+ hookName: H;
75
+ plugin: Plugin;
76
+ parameters?: unknown[] | undefined;
77
+ output?: unknown;
78
+ };
79
+ type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
80
+ duration: number;
81
+ strategy: Strategy;
82
+ hookName: H;
83
+ plugin: Plugin;
84
+ parameters?: unknown[] | undefined;
85
+ output?: unknown;
86
+ };
87
+ /**
88
+ * Events emitted during the Kubb code generation lifecycle.
89
+ * These events can be listened to for logging, progress tracking, and custom integrations.
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * import type { AsyncEventEmitter } from '@kubb/core'
94
+ * import type { KubbEvents } from '@kubb/core'
95
+ *
96
+ * const events: AsyncEventEmitter<KubbEvents> = new AsyncEventEmitter()
97
+ *
98
+ * events.on('lifecycle:start', () => {
99
+ * console.log('Starting Kubb generation')
100
+ * })
101
+ *
102
+ * events.on('plugin:end', (plugin, duration) => {
103
+ * console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
104
+ * })
105
+ * ```
106
+ */
107
+ interface KubbEvents {
75
108
  /**
76
- * Category of the debug log, used for GitHub Actions grouping
77
- * - 'setup': Initial configuration and environment setup
78
- * - 'plugin': Plugin installation and execution
79
- * - 'hook': Plugin hook execution details
80
- * - 'schema': Schema parsing and generation
81
- * - 'file': File operations (read/write/generate)
82
- * - 'error': Error details and stack traces
83
- * - undefined: Generic logs (always inline)
109
+ * Emitted at the beginning of the Kubb lifecycle, before any code generation starts.
84
110
  */
85
- category?: 'setup' | 'plugin' | 'hook' | 'schema' | 'file' | 'error';
111
+ 'lifecycle:start': [version: string];
86
112
  /**
87
- * Plugin name for grouping plugin-specific logs together
113
+ * Emitted at the end of the Kubb lifecycle, after all code generation is complete.
88
114
  */
89
- pluginName?: string;
115
+ 'lifecycle:end': [];
90
116
  /**
91
- * Indicates if this is the start or end of a plugin's execution
92
- * - 'start': Start of plugin execution group
93
- * - 'end': End of plugin execution group
117
+ * Emitted when configuration loading starts.
94
118
  */
95
- pluginGroupMarker?: 'start' | 'end';
96
- };
97
- type Events$1 = {
98
- start: [message: string];
99
- success: [message: string];
100
- error: [message: string, error: Error];
101
- warning: [message: string];
102
- debug: [DebugEvent];
103
- verbose: [DebugEvent];
104
- info: [message: string];
105
- progress_start: [{
106
- id: string;
107
- size: number;
108
- message?: string;
109
- }];
110
- progressed: [{
111
- id: string;
112
- message?: string;
119
+ 'config:start': [];
120
+ /**
121
+ * Emitted when configuration loading is complete.
122
+ */
123
+ 'config:end': [configs: Array<Config>];
124
+ /**
125
+ * Emitted when code generation phase starts.
126
+ */
127
+ 'generation:start': [config: Config];
128
+ /**
129
+ * Emitted when code generation phase completes.
130
+ */
131
+ 'generation:end': [Config: Config];
132
+ /**
133
+ * Emitted with a summary of the generation results.
134
+ * Contains summary lines, title, and success status.
135
+ */
136
+ 'generation:summary': [Config: Config, {
137
+ failedPlugins: Set<{
138
+ plugin: Plugin;
139
+ error: Error;
140
+ }>;
141
+ status: 'success' | 'failed';
142
+ hrStart: [number, number];
143
+ filesCreated: number;
144
+ pluginTimings?: Map<string, number>;
113
145
  }];
114
- progress_stop: [{
115
- id: string;
146
+ /**
147
+ * Emitted when code formatting starts (e.g., running Biome or Prettier).
148
+ */
149
+ 'format:start': [];
150
+ /**
151
+ * Emitted when code formatting completes.
152
+ */
153
+ 'format:end': [];
154
+ /**
155
+ * Emitted when linting starts.
156
+ */
157
+ 'lint:start': [];
158
+ /**
159
+ * Emitted when linting completes.
160
+ */
161
+ 'lint:end': [];
162
+ /**
163
+ * Emitted when plugin hooks execution starts.
164
+ */
165
+ 'hooks:start': [];
166
+ /**
167
+ * Emitted when plugin hooks execution completes.
168
+ */
169
+ 'hooks:end': [];
170
+ /**
171
+ * Emitted when a single hook execution starts.
172
+ */
173
+ 'hook:start': [command: string];
174
+ /**
175
+ * Emitted to execute a hook command (e.g., format or lint).
176
+ * The callback should be invoked when the command completes.
177
+ */
178
+ 'hook:execute': [{
179
+ command: string | URL;
180
+ args?: readonly string[];
181
+ }, cb: () => void];
182
+ /**
183
+ * Emitted when a single hook execution completes.
184
+ */
185
+ 'hook:end': [command: string];
186
+ /**
187
+ * Emitted when a new version of Kubb is available.
188
+ */
189
+ 'version:new': [currentVersion: string, latestVersion: string];
190
+ /**
191
+ * Informational message event.
192
+ */
193
+ info: [message: string, info?: string];
194
+ /**
195
+ * Error event. Emitted when an error occurs during code generation.
196
+ */
197
+ error: [error: Error, meta?: Record<string, unknown>];
198
+ /**
199
+ * Success message event.
200
+ */
201
+ success: [message: string, info?: string];
202
+ /**
203
+ * Warning message event.
204
+ */
205
+ warn: [message: string, info?: string];
206
+ /**
207
+ * Debug event for detailed logging.
208
+ * Contains timestamp, log messages, and optional filename.
209
+ */
210
+ debug: [meta: DebugEvent];
211
+ /**
212
+ * Emitted when file processing starts.
213
+ * Contains the list of files to be processed.
214
+ */
215
+ 'files:processing:start': [files: Array<KubbFile.ResolvedFile>];
216
+ /**
217
+ * Emitted for each file being processed, providing progress updates.
218
+ * Contains processed count, total count, percentage, and file details.
219
+ */
220
+ 'file:processing:update': [{
221
+ /** Number of files processed so far */
222
+ processed: number;
223
+ /** Total number of files to process */
224
+ total: number;
225
+ /** Processing percentage (0-100) */
226
+ percentage: number;
227
+ /** Optional source identifier */
228
+ source?: string;
229
+ /** The file being processed */
230
+ file: KubbFile.ResolvedFile;
231
+ /**
232
+ * Kubb configuration (not present in Fabric).
233
+ * Provides access to the current config during file processing.
234
+ */
235
+ config: Config;
116
236
  }];
117
- };
118
- type Logger = {
119
237
  /**
120
- * Optional config name to show in CLI output
238
+ * Emitted when file processing completes.
239
+ * Contains the list of processed files.
121
240
  */
122
- name?: string;
123
- logLevel: LogLevel;
124
- consola?: ConsolaInstance;
125
- on: EventEmitter<Events$1>['on'];
126
- emit: EventEmitter<Events$1>['emit'];
127
- writeLogs: () => Promise<void>;
128
- };
241
+ 'files:processing:end': [files: KubbFile.ResolvedFile[]];
242
+ /**
243
+ * Emitted when a plugin starts executing.
244
+ */
245
+ 'plugin:start': [plugin: Plugin];
246
+ /**
247
+ * Emitted when a plugin completes execution.
248
+ */
249
+ 'plugin:end': [plugin: Plugin, duration: number];
250
+ /**
251
+ * Emitted when plugin hook progress tracking starts.
252
+ * Contains the hook name and list of plugins to execute.
253
+ */
254
+ 'plugins:hook:progress:start': [meta: ProgressStartMeta];
255
+ /**
256
+ * Emitted when plugin hook progress tracking ends.
257
+ * Contains the hook name that completed.
258
+ */
259
+ 'plugins:hook:progress:end': [meta: ProgressStopMeta];
260
+ /**
261
+ * Emitted when a plugin hook starts processing.
262
+ * Contains strategy, hook name, plugin, parameters, and output.
263
+ */
264
+ 'plugins:hook:processing:start': [meta: ExecutingMeta];
265
+ /**
266
+ * Emitted when a plugin hook completes processing.
267
+ * Contains duration, strategy, hook name, plugin, parameters, and output.
268
+ */
269
+ 'plugins:hook:processing:end': [meta: ExecutedMeta];
270
+ }
271
+ //#endregion
272
+ //#region ../core/src/utils/AsyncEventEmitter.d.ts
273
+ declare class AsyncEventEmitter<TEvents extends Record<string, any>> {
274
+ #private;
275
+ constructor(maxListener?: number);
276
+ emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
277
+ on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
278
+ onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArgs: TEvents[TEventName]) => void): void;
279
+ off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
280
+ removeAll(): void;
281
+ }
129
282
  //#endregion
130
283
  //#region ../core/src/utils/types.d.ts
131
284
  type PossiblePromise<T> = Promise<T> | T;
@@ -389,7 +542,7 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
389
542
  * merging multiple sources into the same output file
390
543
  */
391
544
  upsertFile: (...file: Array<KubbFile.File>) => Promise<void>;
392
- logger: Logger;
545
+ events: AsyncEventEmitter<KubbEvents>;
393
546
  mode: KubbFile.Mode;
394
547
  /**
395
548
  * Current plugin
@@ -435,35 +588,6 @@ type Group = {
435
588
  //#region ../core/src/PluginManager.d.ts
436
589
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
437
590
  type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
438
- type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
439
- strategy: Strategy;
440
- hookName: H;
441
- plugin: Plugin;
442
- parameters?: unknown[] | undefined;
443
- output?: unknown;
444
- };
445
- type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
446
- duration: number;
447
- strategy: Strategy;
448
- hookName: H;
449
- plugin: Plugin;
450
- parameters?: unknown[] | undefined;
451
- output?: unknown;
452
- };
453
- type ErrorMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
454
- hookName: H;
455
- duration: number;
456
- strategy: Strategy;
457
- parameters?: unknown[] | undefined;
458
- plugin: Plugin;
459
- };
460
- type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
461
- hookName: H;
462
- plugins: Array<Plugin>;
463
- };
464
- type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
465
- hookName: H;
466
- };
467
591
  type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
468
592
  type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
469
593
  result: Result;
@@ -471,19 +595,12 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
471
595
  };
472
596
  type Options = {
473
597
  fabric: Fabric;
474
- logger: Logger;
598
+ events: AsyncEventEmitter<KubbEvents>;
475
599
  /**
476
600
  * @default Number.POSITIVE_INFINITY
477
601
  */
478
602
  concurrency?: number;
479
603
  };
480
- type Events = {
481
- progress_start: [meta: ProgressStartMeta];
482
- progress_stop: [meta: ProgressStopMeta];
483
- executing: [meta: ExecutingMeta];
484
- executed: [meta: ExecutedMeta];
485
- error: [error: Error, meta: ErrorMeta];
486
- };
487
604
  type GetFileProps<TOptions = object> = {
488
605
  name: string;
489
606
  mode?: KubbFile.Mode;
@@ -493,10 +610,10 @@ type GetFileProps<TOptions = object> = {
493
610
  };
494
611
  declare class PluginManager {
495
612
  #private;
496
- readonly events: EventEmitter<Events>;
497
613
  readonly config: Config;
498
614
  readonly options: Options;
499
615
  constructor(config: Config, options: Options);
616
+ get events(): AsyncEventEmitter<KubbEvents>;
500
617
  getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
501
618
  get plugins(): Array<Plugin>;
502
619
  getFile<TOptions = object>({
@@ -510,10 +627,6 @@ declare class PluginManager {
510
627
  }>;
511
628
  resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
512
629
  resolveName: (params: ResolveNameParams) => string;
513
- /**
514
- * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
515
- */
516
- on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
517
630
  /**
518
631
  * Run a specific hookName for plugin x.
519
632
  */
@@ -591,5 +704,5 @@ type FileMetaBase = {
591
704
  pluginKey?: Plugin['key'];
592
705
  };
593
706
  //#endregion
594
- export { Output as a, ResolveNameParams as c, BaseGenerator as d, Oas as f, contentType as g, SchemaObject$1 as h, Group as i, UserPluginWithLifeCycle as l, Operation$1 as m, PluginManager as n, Plugin as o, HttpMethod as p, Config as r, PluginFactoryOptions as s, FileMetaBase as t, Logger as u };
595
- //# sourceMappingURL=index-B8yvSsLX.d.ts.map
707
+ export { contentType as _, Output as a, ResolveNameParams as c, KubbEvents as d, BaseGenerator as f, SchemaObject$1 as g, Operation$1 as h, Group as i, UserPluginWithLifeCycle as l, HttpMethod as m, PluginManager as n, Plugin as o, Oas as p, Config as r, PluginFactoryOptions as s, FileMetaBase as t, AsyncEventEmitter as u };
708
+ //# sourceMappingURL=index-pe4_JZ3K.d.ts.map
package/dist/index.cjs CHANGED
@@ -87,7 +87,7 @@ const pluginMsw = (0, __kubb_core.definePlugin)((options) => {
87
87
  fabric: this.fabric,
88
88
  oas,
89
89
  pluginManager: this.pluginManager,
90
- logger: this.logger,
90
+ events: this.events,
91
91
  plugin: this.plugin,
92
92
  contentType,
93
93
  exclude,
@@ -100,8 +100,7 @@ const pluginMsw = (0, __kubb_core.definePlugin)((options) => {
100
100
  type: output.barrelType ?? "named",
101
101
  root,
102
102
  output,
103
- meta: { pluginKey: this.plugin.key },
104
- logger: this.logger
103
+ meta: { pluginKey: this.plugin.key }
105
104
  });
106
105
  await this.upsertFile(...barrelFiles);
107
106
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["mswGenerator","handlersGenerator","pluginOasName","pluginTsName","pluginFakerName","path","options","groupName: Group['name']","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = definePlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n parser = 'data',\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n contentType,\n baseURL,\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n group,\n baseURL,\n },\n pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n logger: this.logger,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAa,gBAAgB;AAE7B,MAAa,2CAAqC,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAY,YAAY;EAAS,EAClD,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,WAAW,OACX,SAAS,QACT,aAAa,CAACA,iCAAc,WAAWC,uCAAoB,OAAU,CAAC,OAAO,QAAQ,EACrF,aACA,YACE;AAEJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GACA;GACD;EACD,KAAK;GAACC;GAAeC;GAAc,WAAW,UAAUC,sCAAkB;GAAU,CAAC,OAAO,QAAQ;EACpG,YAAY,UAAU,UAAU,WAAS;GACvC,MAAM,OAAOC,kBAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;AAGpE,QAFa,qCAAoBA,kBAAK,QAAQ,MAAM,OAAO,KAAK,CAAC,MAEpD;;;;;AAKX,UAAOA,kBAAK,QAAQ,MAAM,OAAO,KAAK;AAGxC,OAAI,UAAUC,WAAS,OAAO,QAAQA,WAAS,OAAO,MAAM;IAC1D,MAAMC,YAA2B,OAAO,OACpC,MAAM,QACL,QAAQ;AACP,SAAI,OAAO,SAAS,OAClB,QAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;AAEjC,YAAO,2CAAa,IAAI,MAAM,CAAC;;AAGrC,WAAOF,kBAAK,QACV,MACA,OAAO,MACP,UAAU,EACR,OAAO,MAAM,SAAS,SAASC,UAAQ,MAAM,OAAQA,UAAQ,MAAM,KACpE,CAAC,EACF,SACD;;AAGH,UAAOD,kBAAK,QAAQ,MAAM,OAAO,MAAM,SAAS;;EAElD,YAAY,MAAM,MAAM;GACtB,MAAM,uDAAyB,MAAM;IACnC,QAAQ,OAAO,YAAY;IAC3B,QAAQ,SAAS;IAClB,CAAC;AAEF,OAAI,KACF,QAAO,cAAc,OAAO,cAAc,KAAK,IAAI;AAGrD,UAAO;;EAET,MAAM,UAAU;GACd,MAAM,OAAOA,kBAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,gCAAeA,kBAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACrD,MAAM,MAAM,MAAM,KAAK,QAAQ;GAe/B,MAAM,QAAQ,MAba,IAAIG,qCAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,MAAM,cAAc,sCAAqB,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACD,QAAQ,KAAK;IACd,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
1
+ {"version":3,"file":"index.cjs","names":["mswGenerator","handlersGenerator","pluginOasName","pluginTsName","pluginFakerName","path","options","groupName: Group['name']","OperationGenerator"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = definePlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n parser = 'data',\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n contentType,\n baseURL,\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n group,\n baseURL,\n },\n pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAa,gBAAgB;AAE7B,MAAa,2CAAqC,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAY,YAAY;EAAS,EAClD,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,WAAW,OACX,SAAS,QACT,aAAa,CAACA,iCAAc,WAAWC,uCAAoB,OAAU,CAAC,OAAO,QAAQ,EACrF,aACA,YACE;AAEJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GACA;GACD;EACD,KAAK;GAACC;GAAeC;GAAc,WAAW,UAAUC,sCAAkB;GAAU,CAAC,OAAO,QAAQ;EACpG,YAAY,UAAU,UAAU,WAAS;GACvC,MAAM,OAAOC,kBAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;AAGpE,QAFa,qCAAoBA,kBAAK,QAAQ,MAAM,OAAO,KAAK,CAAC,MAEpD;;;;;AAKX,UAAOA,kBAAK,QAAQ,MAAM,OAAO,KAAK;AAGxC,OAAI,UAAUC,WAAS,OAAO,QAAQA,WAAS,OAAO,MAAM;IAC1D,MAAMC,YAA2B,OAAO,OACpC,MAAM,QACL,QAAQ;AACP,SAAI,OAAO,SAAS,OAClB,QAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;AAEjC,YAAO,2CAAa,IAAI,MAAM,CAAC;;AAGrC,WAAOF,kBAAK,QACV,MACA,OAAO,MACP,UAAU,EACR,OAAO,MAAM,SAAS,SAASC,UAAQ,MAAM,OAAQA,UAAQ,MAAM,KACpE,CAAC,EACF,SACD;;AAGH,UAAOD,kBAAK,QAAQ,MAAM,OAAO,MAAM,SAAS;;EAElD,YAAY,MAAM,MAAM;GACtB,MAAM,uDAAyB,MAAM;IACnC,QAAQ,OAAO,YAAY;IAC3B,QAAQ,SAAS;IAClB,CAAC;AAEF,OAAI,KACF,QAAO,cAAc,OAAO,cAAc,KAAK,IAAI;AAGrD,UAAO;;EAET,MAAM,UAAU;GACd,MAAM,OAAOA,kBAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,gCAAeA,kBAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACrD,MAAM,MAAM,MAAM,KAAK,QAAQ;GAe/B,MAAM,QAAQ,MAba,IAAIG,qCAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,MAAM,cAAc,sCAAqB,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { l as UserPluginWithLifeCycle } from "./index-BSYdDKeZ.cjs";
2
- import { n as PluginMsw, t as Options } from "./types-MDRyMp8X.cjs";
1
+ import { l as UserPluginWithLifeCycle } from "./index-CH9QiCej.cjs";
2
+ import { n as PluginMsw, t as Options } from "./types-CZnA5aRm.cjs";
3
3
 
4
4
  //#region src/plugin.d.ts
5
5
  declare const pluginMswName = "plugin-msw";
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { l as UserPluginWithLifeCycle } from "./index-B8yvSsLX.js";
2
- import { n as PluginMsw, t as Options } from "./types-BUzgaOhd.js";
1
+ import { l as UserPluginWithLifeCycle } from "./index-pe4_JZ3K.js";
2
+ import { n as PluginMsw, t as Options } from "./types-CSdstWCA.js";
3
3
 
4
4
  //#region src/plugin.d.ts
5
5
  declare const pluginMswName = "plugin-msw";
package/dist/index.js CHANGED
@@ -59,7 +59,7 @@ const pluginMsw = definePlugin((options) => {
59
59
  fabric: this.fabric,
60
60
  oas,
61
61
  pluginManager: this.pluginManager,
62
- logger: this.logger,
62
+ events: this.events,
63
63
  plugin: this.plugin,
64
64
  contentType,
65
65
  exclude,
@@ -72,8 +72,7 @@ const pluginMsw = definePlugin((options) => {
72
72
  type: output.barrelType ?? "named",
73
73
  root,
74
74
  output,
75
- meta: { pluginKey: this.plugin.key },
76
- logger: this.logger
75
+ meta: { pluginKey: this.plugin.key }
77
76
  });
78
77
  await this.upsertFile(...barrelFiles);
79
78
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["options","groupName: Group['name']"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = definePlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n parser = 'data',\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n contentType,\n baseURL,\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n group,\n baseURL,\n },\n pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n logger: this.logger,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;AAUA,MAAa,gBAAgB;AAE7B,MAAa,YAAY,cAAyB,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAY,YAAY;EAAS,EAClD,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,WAAW,OACX,SAAS,QACT,aAAa,CAAC,cAAc,WAAW,oBAAoB,OAAU,CAAC,OAAO,QAAQ,EACrF,aACA,YACE;AAEJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GACA;GACD;EACD,KAAK;GAAC;GAAe;GAAc,WAAW,UAAU,kBAAkB;GAAU,CAAC,OAAO,QAAQ;EACpG,YAAY,UAAU,UAAU,WAAS;GACvC,MAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;AAGpE,QAFa,YAAY,QAAQ,KAAK,QAAQ,MAAM,OAAO,KAAK,CAAC,MAEpD;;;;;AAKX,UAAO,KAAK,QAAQ,MAAM,OAAO,KAAK;AAGxC,OAAI,UAAUA,WAAS,OAAO,QAAQA,WAAS,OAAO,MAAM;IAC1D,MAAMC,YAA2B,OAAO,OACpC,MAAM,QACL,QAAQ;AACP,SAAI,OAAO,SAAS,OAClB,QAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;AAEjC,YAAO,GAAG,UAAU,IAAI,MAAM,CAAC;;AAGrC,WAAO,KAAK,QACV,MACA,OAAO,MACP,UAAU,EACR,OAAO,MAAM,SAAS,SAASD,UAAQ,MAAM,OAAQA,UAAQ,MAAM,KACpE,CAAC,EACF,SACD;;AAGH,UAAO,KAAK,QAAQ,MAAM,OAAO,MAAM,SAAS;;EAElD,YAAY,MAAM,MAAM;GACtB,MAAM,eAAe,UAAU,MAAM;IACnC,QAAQ,OAAO,YAAY;IAC3B,QAAQ,SAAS;IAClB,CAAC;AAEF,OAAI,KACF,QAAO,cAAc,OAAO,cAAc,KAAK,IAAI;AAGrD,UAAO;;EAET,MAAM,UAAU;GACd,MAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,OAAO,QAAQ,KAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACrD,MAAM,MAAM,MAAM,KAAK,QAAQ;GAe/B,MAAM,QAAQ,MAba,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACD,QAAQ,KAAK;IACd,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
1
+ {"version":3,"file":"index.js","names":["options","groupName: Group['name']"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { definePlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\n\nimport { pluginFakerName } from '@kubb/plugin-faker'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { handlersGenerator, mswGenerator } from './generators'\nimport type { PluginMsw } from './types.ts'\n\nexport const pluginMswName = 'plugin-msw' satisfies PluginMsw['name']\n\nexport const pluginMsw = definePlugin<PluginMsw>((options) => {\n const {\n output = { path: 'handlers', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n handlers = false,\n parser = 'data',\n generators = [mswGenerator, handlers ? handlersGenerator : undefined].filter(Boolean),\n contentType,\n baseURL,\n } = options\n\n return {\n name: pluginMswName,\n options: {\n output,\n parser,\n group,\n baseURL,\n },\n pre: [pluginOasName, pluginTsName, parser === 'faker' ? pluginFakerName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, {\n suffix: type ? 'handler' : undefined,\n isFile: type === 'file',\n })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async install() {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n const oas = await this.getOas()\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n fabric: this.fabric,\n oas,\n pluginManager: this.pluginManager,\n events: this.events,\n plugin: this.plugin,\n contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const files = await operationGenerator.build(...generators)\n await this.upsertFile(...files)\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginKey: this.plugin.key,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;;;AAUA,MAAa,gBAAgB;AAE7B,MAAa,YAAY,cAAyB,YAAY;CAC5D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAY,YAAY;EAAS,EAClD,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,eAAe,EAAE,EACjB,WAAW,OACX,SAAS,QACT,aAAa,CAAC,cAAc,WAAW,oBAAoB,OAAU,CAAC,OAAO,QAAQ,EACrF,aACA,YACE;AAEJ,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GACA;GACD;EACD,KAAK;GAAC;GAAe;GAAc,WAAW,UAAU,kBAAkB;GAAU,CAAC,OAAO,QAAQ;EACpG,YAAY,UAAU,UAAU,WAAS;GACvC,MAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;AAGpE,QAFa,YAAY,QAAQ,KAAK,QAAQ,MAAM,OAAO,KAAK,CAAC,MAEpD;;;;;AAKX,UAAO,KAAK,QAAQ,MAAM,OAAO,KAAK;AAGxC,OAAI,UAAUA,WAAS,OAAO,QAAQA,WAAS,OAAO,MAAM;IAC1D,MAAMC,YAA2B,OAAO,OACpC,MAAM,QACL,QAAQ;AACP,SAAI,OAAO,SAAS,OAClB,QAAO,GAAG,IAAI,MAAM,MAAM,IAAI,CAAC;AAEjC,YAAO,GAAG,UAAU,IAAI,MAAM,CAAC;;AAGrC,WAAO,KAAK,QACV,MACA,OAAO,MACP,UAAU,EACR,OAAO,MAAM,SAAS,SAASD,UAAQ,MAAM,OAAQA,UAAQ,MAAM,KACpE,CAAC,EACF,SACD;;AAGH,UAAO,KAAK,QAAQ,MAAM,OAAO,MAAM,SAAS;;EAElD,YAAY,MAAM,MAAM;GACtB,MAAM,eAAe,UAAU,MAAM;IACnC,QAAQ,OAAO,YAAY;IAC3B,QAAQ,SAAS;IAClB,CAAC;AAEF,OAAI,KACF,QAAO,cAAc,OAAO,cAAc,KAAK,IAAI;AAGrD,UAAO;;EAET,MAAM,UAAU;GACd,MAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,KAAK;GACpE,MAAM,OAAO,QAAQ,KAAK,QAAQ,MAAM,OAAO,KAAK,CAAC;GACrD,MAAM,MAAM,MAAM,KAAK,QAAQ;GAe/B,MAAM,QAAQ,MAba,IAAI,mBAAmB,KAAK,OAAO,SAAS;IACrE,QAAQ,KAAK;IACb;IACA,eAAe,KAAK;IACpB,QAAQ,KAAK;IACb,QAAQ,KAAK;IACb;IACA;IACA;IACA;IACA;IACD,CAAC,CAEqC,MAAM,GAAG,WAAW;AAC3D,SAAM,KAAK,WAAW,GAAG,MAAM;GAE/B,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,WAAW,KAAK,OAAO,KACxB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
@@ -1,4 +1,4 @@
1
- import { a as Output, c as ResolveNameParams, d as BaseGenerator, f as Oas, g as contentType, h as SchemaObject, i as Group, m as Operation, n as PluginManager, o as Plugin, p as HttpMethod, r as Config, s as PluginFactoryOptions, t as FileMetaBase, u as Logger } from "./index-B8yvSsLX.js";
1
+ import { _ as contentType, a as Output, c as ResolveNameParams, d as KubbEvents, f as BaseGenerator, g as SchemaObject, h as Operation, i as Group, m as HttpMethod, n as PluginManager, o as Plugin, p as Oas, r as Config, s as PluginFactoryOptions, t as FileMetaBase, u as AsyncEventEmitter } from "./index-pe4_JZ3K.js";
2
2
  import { Fabric } from "@kubb/react-fabric";
3
3
  import { KubbNode } from "@kubb/react-fabric/types";
4
4
  import { KubbFile } from "@kubb/fabric-core/types";
@@ -109,7 +109,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
109
109
  override: Array<Override<TOptions>> | undefined;
110
110
  contentType: contentType | undefined;
111
111
  pluginManager: PluginManager;
112
- logger?: Logger;
112
+ events?: AsyncEventEmitter<KubbEvents>;
113
113
  /**
114
114
  * Current plugin
115
115
  */
@@ -353,7 +353,7 @@ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
353
353
  fabric: Fabric;
354
354
  oas: Oas;
355
355
  pluginManager: PluginManager;
356
- logger?: Logger;
356
+ events?: AsyncEventEmitter<KubbEvents>;
357
357
  /**
358
358
  * Current plugin
359
359
  */
@@ -510,4 +510,4 @@ type ResolvedOptions = {
510
510
  type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
511
511
  //#endregion
512
512
  export { PluginMsw as n, ReactGenerator as r, Options as t };
513
- //# sourceMappingURL=types-BUzgaOhd.d.ts.map
513
+ //# sourceMappingURL=types-CSdstWCA.d.ts.map
@@ -1,4 +1,4 @@
1
- import { a as Output, c as ResolveNameParams, d as BaseGenerator, f as Oas, g as contentType, h as SchemaObject, i as Group, m as Operation, n as PluginManager, o as Plugin, p as HttpMethod, r as Config, s as PluginFactoryOptions, t as FileMetaBase, u as Logger } from "./index-BSYdDKeZ.cjs";
1
+ import { _ as contentType, a as Output, c as ResolveNameParams, d as KubbEvents, f as BaseGenerator, g as SchemaObject, h as Operation, i as Group, m as HttpMethod, n as PluginManager, o as Plugin, p as Oas, r as Config, s as PluginFactoryOptions, t as FileMetaBase, u as AsyncEventEmitter } from "./index-CH9QiCej.cjs";
2
2
  import { KubbNode } from "@kubb/react-fabric/types";
3
3
  import { KubbFile } from "@kubb/fabric-core/types";
4
4
  import { Fabric } from "@kubb/react-fabric";
@@ -109,7 +109,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
109
109
  override: Array<Override<TOptions>> | undefined;
110
110
  contentType: contentType | undefined;
111
111
  pluginManager: PluginManager;
112
- logger?: Logger;
112
+ events?: AsyncEventEmitter<KubbEvents>;
113
113
  /**
114
114
  * Current plugin
115
115
  */
@@ -353,7 +353,7 @@ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
353
353
  fabric: Fabric;
354
354
  oas: Oas;
355
355
  pluginManager: PluginManager;
356
- logger?: Logger;
356
+ events?: AsyncEventEmitter<KubbEvents>;
357
357
  /**
358
358
  * Current plugin
359
359
  */
@@ -510,4 +510,4 @@ type ResolvedOptions = {
510
510
  type PluginMsw = PluginFactoryOptions<'plugin-msw', Options, ResolvedOptions, never, ResolvePathOptions>;
511
511
  //#endregion
512
512
  export { PluginMsw as n, ReactGenerator as r, Options as t };
513
- //# sourceMappingURL=types-MDRyMp8X.d.cts.map
513
+ //# sourceMappingURL=types-CZnA5aRm.d.cts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-msw",
3
- "version": "4.11.3",
3
+ "version": "4.12.0",
4
4
  "description": "Mock Service Worker (MSW) handlers generator plugin for Kubb, creating API mocks from OpenAPI specifications for frontend development and testing.",
5
5
  "keywords": [
6
6
  "msw",
@@ -73,12 +73,12 @@
73
73
  }
74
74
  ],
75
75
  "dependencies": {
76
- "@kubb/react-fabric": "0.5.4",
77
- "@kubb/core": "4.11.3",
78
- "@kubb/oas": "4.11.3",
79
- "@kubb/plugin-faker": "4.11.3",
80
- "@kubb/plugin-oas": "4.11.3",
81
- "@kubb/plugin-ts": "4.11.3"
76
+ "@kubb/react-fabric": "0.7.0",
77
+ "@kubb/core": "4.12.0",
78
+ "@kubb/oas": "4.12.0",
79
+ "@kubb/plugin-faker": "4.12.0",
80
+ "@kubb/plugin-oas": "4.12.0",
81
+ "@kubb/plugin-ts": "4.12.0"
82
82
  },
83
83
  "devDependencies": {},
84
84
  "engines": {
package/src/plugin.ts CHANGED
@@ -89,7 +89,7 @@ export const pluginMsw = definePlugin<PluginMsw>((options) => {
89
89
  fabric: this.fabric,
90
90
  oas,
91
91
  pluginManager: this.pluginManager,
92
- logger: this.logger,
92
+ events: this.events,
93
93
  plugin: this.plugin,
94
94
  contentType,
95
95
  exclude,
@@ -108,7 +108,6 @@ export const pluginMsw = definePlugin<PluginMsw>((options) => {
108
108
  meta: {
109
109
  pluginKey: this.plugin.key,
110
110
  },
111
- logger: this.logger,
112
111
  })
113
112
 
114
113
  await this.upsertFile(...barrelFiles)