unplugin-kubb 3.2.1 → 4.0.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.
Files changed (56) hide show
  1. package/dist/astro.cjs +1 -1
  2. package/dist/astro.d.cts +1 -1
  3. package/dist/astro.d.ts +1 -1
  4. package/dist/astro.js +1 -1
  5. package/dist/esbuild.cjs +1 -1
  6. package/dist/esbuild.d.cts +1 -1
  7. package/dist/esbuild.d.ts +1 -1
  8. package/dist/esbuild.js +1 -1
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.d.cts +3 -3
  11. package/dist/index.d.ts +3 -3
  12. package/dist/index.js +1 -1
  13. package/dist/nuxt.cjs +3 -3
  14. package/dist/nuxt.d.cts +1 -1
  15. package/dist/nuxt.d.ts +1 -1
  16. package/dist/nuxt.js +2 -3
  17. package/dist/nuxt.js.map +1 -1
  18. package/dist/rollup.cjs +1 -1
  19. package/dist/rollup.d.cts +1 -1
  20. package/dist/rollup.d.ts +1 -1
  21. package/dist/rollup.js +1 -1
  22. package/dist/rspack.cjs +1 -1
  23. package/dist/rspack.d.cts +1 -1
  24. package/dist/rspack.d.ts +1 -1
  25. package/dist/rspack.js +1 -1
  26. package/dist/src-7pFd4t48.cjs +145 -0
  27. package/dist/src-7pFd4t48.cjs.map +1 -0
  28. package/dist/src-y2za6sAo.js +94 -0
  29. package/dist/src-y2za6sAo.js.map +1 -0
  30. package/dist/{types-BNmRHGEx.d.cts → types-BWfxOttU.d.ts} +231 -80
  31. package/dist/{types-D54bCl1u.d.ts → types-BgPPdoLi.d.cts} +231 -80
  32. package/dist/types.d.cts +1 -1
  33. package/dist/types.d.ts +1 -1
  34. package/dist/{vite-CZqCD2RF.js → vite-DXcgbm9H.js} +2 -2
  35. package/dist/{vite-CZqCD2RF.js.map → vite-DXcgbm9H.js.map} +1 -1
  36. package/dist/{vite-DO7vdmOO.cjs → vite-HDFFF5rj.cjs} +2 -2
  37. package/dist/{vite-DO7vdmOO.cjs.map → vite-HDFFF5rj.cjs.map} +1 -1
  38. package/dist/vite.cjs +1 -2
  39. package/dist/vite.d.cts +1 -1
  40. package/dist/vite.d.ts +1 -1
  41. package/dist/vite.js +1 -2
  42. package/dist/{webpack-BPXrZfNl.js → webpack-BqG9Y2kv.js} +2 -2
  43. package/dist/{webpack-BPXrZfNl.js.map → webpack-BqG9Y2kv.js.map} +1 -1
  44. package/dist/{webpack-DwzhnPfl.cjs → webpack-D1dzppyE.cjs} +2 -2
  45. package/dist/{webpack-DwzhnPfl.cjs.map → webpack-D1dzppyE.cjs.map} +1 -1
  46. package/dist/webpack.cjs +1 -2
  47. package/dist/webpack.d.cts +1 -1
  48. package/dist/webpack.d.ts +1 -1
  49. package/dist/webpack.js +1 -2
  50. package/package.json +26 -26
  51. package/src/index.ts +117 -47
  52. package/dist/chunk-Bwj0kw0m.js +0 -32
  53. package/dist/src-6M-KdHiM.cjs +0 -67
  54. package/dist/src-6M-KdHiM.cjs.map +0 -1
  55. package/dist/src-CN9jIyH0.js +0 -50
  56. package/dist/src-CN9jIyH0.js.map +0 -1
@@ -1,54 +1,229 @@
1
1
  import { KubbFile } from "@kubb/fabric-core/types";
2
2
  import { Fabric } from "@kubb/react-fabric";
3
- import { ConsolaInstance, LogLevel } from "consola";
4
3
 
5
- //#region ../core/src/utils/EventEmitter.d.ts
6
- declare class EventEmitter<TEvents extends Record<string, any>> {
7
- #private;
8
- constructor();
9
- emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
10
- on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
11
- off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
12
- removeAll(): void;
13
- }
14
- //#endregion
15
- //#region ../core/src/logger.d.ts
4
+ //#region ../core/src/Kubb.d.ts
16
5
  type DebugEvent = {
17
6
  date: Date;
18
7
  logs: string[];
19
8
  fileName?: string;
20
9
  };
21
- type Events$1 = {
22
- start: [message: string];
23
- success: [message: string];
24
- error: [message: string, cause: Error];
25
- warning: [message: string];
26
- debug: [DebugEvent];
27
- info: [message: string];
28
- progress_start: [{
29
- id: string;
30
- size: number;
31
- message?: string;
32
- }];
33
- progressed: [{
34
- id: string;
35
- message?: string;
10
+ type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
11
+ hookName: H;
12
+ plugins: Array<Plugin>;
13
+ };
14
+ type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
15
+ hookName: H;
16
+ };
17
+ type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
18
+ strategy: Strategy;
19
+ hookName: H;
20
+ plugin: Plugin;
21
+ parameters?: unknown[] | undefined;
22
+ output?: unknown;
23
+ };
24
+ type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
25
+ duration: number;
26
+ strategy: Strategy;
27
+ hookName: H;
28
+ plugin: Plugin;
29
+ parameters?: unknown[] | undefined;
30
+ output?: unknown;
31
+ };
32
+ /**
33
+ * Events emitted during the Kubb code generation lifecycle.
34
+ * These events can be listened to for logging, progress tracking, and custom integrations.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * import type { AsyncEventEmitter } from '@kubb/core'
39
+ * import type { KubbEvents } from '@kubb/core'
40
+ *
41
+ * const events: AsyncEventEmitter<KubbEvents> = new AsyncEventEmitter()
42
+ *
43
+ * events.on('lifecycle:start', () => {
44
+ * console.log('Starting Kubb generation')
45
+ * })
46
+ *
47
+ * events.on('plugin:end', (plugin, duration) => {
48
+ * console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
49
+ * })
50
+ * ```
51
+ */
52
+ interface KubbEvents {
53
+ /**
54
+ * Emitted at the beginning of the Kubb lifecycle, before any code generation starts.
55
+ */
56
+ 'lifecycle:start': [version: string];
57
+ /**
58
+ * Emitted at the end of the Kubb lifecycle, after all code generation is complete.
59
+ */
60
+ 'lifecycle:end': [];
61
+ /**
62
+ * Emitted when configuration loading starts.
63
+ */
64
+ 'config:start': [];
65
+ /**
66
+ * Emitted when configuration loading is complete.
67
+ */
68
+ 'config:end': [configs: Array<Config>];
69
+ /**
70
+ * Emitted when code generation phase starts.
71
+ */
72
+ 'generation:start': [config: Config];
73
+ /**
74
+ * Emitted when code generation phase completes.
75
+ */
76
+ 'generation:end': [Config: Config];
77
+ /**
78
+ * Emitted with a summary of the generation results.
79
+ * Contains summary lines, title, and success status.
80
+ */
81
+ 'generation:summary': [Config: Config, {
82
+ failedPlugins: Set<{
83
+ plugin: Plugin;
84
+ error: Error;
85
+ }>;
86
+ status: 'success' | 'failed';
87
+ hrStart: [number, number];
88
+ filesCreated: number;
89
+ pluginTimings?: Map<string, number>;
36
90
  }];
37
- progress_stop: [{
38
- id: string;
91
+ /**
92
+ * Emitted when code formatting starts (e.g., running Biome or Prettier).
93
+ */
94
+ 'format:start': [];
95
+ /**
96
+ * Emitted when code formatting completes.
97
+ */
98
+ 'format:end': [];
99
+ /**
100
+ * Emitted when linting starts.
101
+ */
102
+ 'lint:start': [];
103
+ /**
104
+ * Emitted when linting completes.
105
+ */
106
+ 'lint:end': [];
107
+ /**
108
+ * Emitted when plugin hooks execution starts.
109
+ */
110
+ 'hooks:start': [];
111
+ /**
112
+ * Emitted when plugin hooks execution completes.
113
+ */
114
+ 'hooks:end': [];
115
+ /**
116
+ * Emitted when a single hook execution starts.
117
+ */
118
+ 'hook:start': [command: string];
119
+ /**
120
+ * Emitted to execute a hook command (e.g., format or lint).
121
+ * The callback should be invoked when the command completes.
122
+ */
123
+ 'hook:execute': [{
124
+ command: string | URL;
125
+ args?: readonly string[];
126
+ }, cb: () => void];
127
+ /**
128
+ * Emitted when a single hook execution completes.
129
+ */
130
+ 'hook:end': [command: string];
131
+ /**
132
+ * Emitted when a new version of Kubb is available.
133
+ */
134
+ 'version:new': [currentVersion: string, latestVersion: string];
135
+ /**
136
+ * Informational message event.
137
+ */
138
+ info: [message: string, info?: string];
139
+ /**
140
+ * Error event. Emitted when an error occurs during code generation.
141
+ */
142
+ error: [error: Error, meta?: Record<string, unknown>];
143
+ /**
144
+ * Success message event.
145
+ */
146
+ success: [message: string, info?: string];
147
+ /**
148
+ * Warning message event.
149
+ */
150
+ warn: [message: string, info?: string];
151
+ /**
152
+ * Debug event for detailed logging.
153
+ * Contains timestamp, log messages, and optional filename.
154
+ */
155
+ debug: [meta: DebugEvent];
156
+ /**
157
+ * Emitted when file processing starts.
158
+ * Contains the list of files to be processed.
159
+ */
160
+ 'files:processing:start': [files: Array<KubbFile.ResolvedFile>];
161
+ /**
162
+ * Emitted for each file being processed, providing progress updates.
163
+ * Contains processed count, total count, percentage, and file details.
164
+ */
165
+ 'file:processing:update': [{
166
+ /** Number of files processed so far */
167
+ processed: number;
168
+ /** Total number of files to process */
169
+ total: number;
170
+ /** Processing percentage (0-100) */
171
+ percentage: number;
172
+ /** Optional source identifier */
173
+ source?: string;
174
+ /** The file being processed */
175
+ file: KubbFile.ResolvedFile;
176
+ /**
177
+ * Kubb configuration (not present in Fabric).
178
+ * Provides access to the current config during file processing.
179
+ */
180
+ config: Config;
39
181
  }];
40
- };
41
- type Logger = {
42
182
  /**
43
- * Optional config name to show in CLI output
183
+ * Emitted when file processing completes.
184
+ * Contains the list of processed files.
44
185
  */
45
- name?: string;
46
- logLevel: LogLevel;
47
- consola?: ConsolaInstance;
48
- on: EventEmitter<Events$1>['on'];
49
- emit: EventEmitter<Events$1>['emit'];
50
- writeLogs: () => Promise<string[]>;
51
- };
186
+ 'files:processing:end': [files: KubbFile.ResolvedFile[]];
187
+ /**
188
+ * Emitted when a plugin starts executing.
189
+ */
190
+ 'plugin:start': [plugin: Plugin];
191
+ /**
192
+ * Emitted when a plugin completes execution.
193
+ */
194
+ 'plugin:end': [plugin: Plugin, duration: number];
195
+ /**
196
+ * Emitted when plugin hook progress tracking starts.
197
+ * Contains the hook name and list of plugins to execute.
198
+ */
199
+ 'plugins:hook:progress:start': [meta: ProgressStartMeta];
200
+ /**
201
+ * Emitted when plugin hook progress tracking ends.
202
+ * Contains the hook name that completed.
203
+ */
204
+ 'plugins:hook:progress:end': [meta: ProgressStopMeta];
205
+ /**
206
+ * Emitted when a plugin hook starts processing.
207
+ * Contains strategy, hook name, plugin, parameters, and output.
208
+ */
209
+ 'plugins:hook:processing:start': [meta: ExecutingMeta];
210
+ /**
211
+ * Emitted when a plugin hook completes processing.
212
+ * Contains duration, strategy, hook name, plugin, parameters, and output.
213
+ */
214
+ 'plugins:hook:processing:end': [meta: ExecutedMeta];
215
+ }
216
+ //#endregion
217
+ //#region ../core/src/utils/AsyncEventEmitter.d.ts
218
+ declare class AsyncEventEmitter<TEvents extends Record<string, any>> {
219
+ #private;
220
+ constructor(maxListener?: number);
221
+ emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
222
+ on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
223
+ onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArgs: TEvents[TEventName]) => void): void;
224
+ off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
225
+ removeAll(): void;
226
+ }
52
227
  //#endregion
53
228
  //#region ../core/src/utils/types.d.ts
54
229
  type PossiblePromise<T> = Promise<T> | T;
@@ -314,8 +489,15 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
314
489
  fabric: Fabric;
315
490
  config: Config;
316
491
  pluginManager: PluginManager;
492
+ /**
493
+ * Only add when the file does not exist yet
494
+ */
317
495
  addFile: (...file: Array<KubbFile.File>) => Promise<void>;
318
- logger: Logger;
496
+ /**
497
+ * merging multiple sources into the same output file
498
+ */
499
+ upsertFile: (...file: Array<KubbFile.File>) => Promise<void>;
500
+ events: AsyncEventEmitter<KubbEvents>;
319
501
  mode: KubbFile.Mode;
320
502
  /**
321
503
  * Current plugin
@@ -326,14 +508,6 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
326
508
  //#region ../core/src/PluginManager.d.ts
327
509
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
328
510
  type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
329
- type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
330
- message: string;
331
- strategy: Strategy;
332
- hookName: H;
333
- plugin: Plugin;
334
- parameters?: unknown[] | undefined;
335
- output?: unknown;
336
- };
337
511
  type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
338
512
  type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
339
513
  result: Result;
@@ -341,17 +515,12 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
341
515
  };
342
516
  type Options$1 = {
343
517
  fabric: Fabric;
344
- logger: Logger;
518
+ events: AsyncEventEmitter<KubbEvents>;
345
519
  /**
346
520
  * @default Number.POSITIVE_INFINITY
347
521
  */
348
522
  concurrency?: number;
349
523
  };
350
- type Events = {
351
- executing: [executer: Executer];
352
- executed: [executer: Executer];
353
- error: [error: Error];
354
- };
355
524
  type GetFileProps<TOptions = object> = {
356
525
  name: string;
357
526
  mode?: KubbFile.Mode;
@@ -361,12 +530,10 @@ type GetFileProps<TOptions = object> = {
361
530
  };
362
531
  declare class PluginManager {
363
532
  #private;
364
- readonly events: EventEmitter<Events>;
365
533
  readonly config: Config;
366
- readonly executed: Array<Executer>;
367
- readonly logger: Logger;
368
534
  readonly options: Options$1;
369
535
  constructor(config: Config, options: Options$1);
536
+ get events(): AsyncEventEmitter<KubbEvents>;
370
537
  getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
371
538
  get plugins(): Array<Plugin>;
372
539
  getFile<TOptions = object>({
@@ -380,23 +547,17 @@ declare class PluginManager {
380
547
  }>;
381
548
  resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
382
549
  resolveName: (params: ResolveNameParams) => string;
383
- /**
384
- * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
385
- */
386
- on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
387
550
  /**
388
551
  * Run a specific hookName for plugin x.
389
552
  */
390
553
  hookForPlugin<H extends PluginLifecycleHooks>({
391
554
  pluginKey,
392
555
  hookName,
393
- parameters,
394
- message
556
+ parameters
395
557
  }: {
396
558
  pluginKey: Plugin['key'];
397
559
  hookName: H;
398
560
  parameters: PluginParameter<H>;
399
- message: string;
400
561
  }): Promise<Array<ReturnType<ParseResult<H>> | null>>;
401
562
  /**
402
563
  * Run a specific hookName for plugin x.
@@ -404,13 +565,11 @@ declare class PluginManager {
404
565
  hookForPluginSync<H extends PluginLifecycleHooks>({
405
566
  pluginKey,
406
567
  hookName,
407
- parameters,
408
- message
568
+ parameters
409
569
  }: {
410
570
  pluginKey: Plugin['key'];
411
571
  hookName: H;
412
572
  parameters: PluginParameter<H>;
413
- message: string;
414
573
  }): Array<ReturnType<ParseResult<H>>> | null;
415
574
  /**
416
575
  * First non-null result stops and will return it's value.
@@ -418,13 +577,11 @@ declare class PluginManager {
418
577
  hookFirst<H extends PluginLifecycleHooks>({
419
578
  hookName,
420
579
  parameters,
421
- skipped,
422
- message
580
+ skipped
423
581
  }: {
424
582
  hookName: H;
425
583
  parameters: PluginParameter<H>;
426
584
  skipped?: ReadonlySet<Plugin> | null;
427
- message: string;
428
585
  }): Promise<SafeParseResult<H>>;
429
586
  /**
430
587
  * First non-null result stops and will return it's value.
@@ -432,37 +589,31 @@ declare class PluginManager {
432
589
  hookFirstSync<H extends PluginLifecycleHooks>({
433
590
  hookName,
434
591
  parameters,
435
- skipped,
436
- message
592
+ skipped
437
593
  }: {
438
594
  hookName: H;
439
595
  parameters: PluginParameter<H>;
440
596
  skipped?: ReadonlySet<Plugin> | null;
441
- message: string;
442
597
  }): SafeParseResult<H>;
443
598
  /**
444
599
  * Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
445
600
  */
446
601
  hookParallel<H extends PluginLifecycleHooks, TOuput = void>({
447
602
  hookName,
448
- parameters,
449
- message
603
+ parameters
450
604
  }: {
451
605
  hookName: H;
452
606
  parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
453
- message: string;
454
607
  }): Promise<Awaited<TOuput>[]>;
455
608
  /**
456
609
  * Chains plugins
457
610
  */
458
611
  hookSeq<H extends PluginLifecycleHooks>({
459
612
  hookName,
460
- parameters,
461
- message
613
+ parameters
462
614
  }: {
463
615
  hookName: H;
464
616
  parameters?: PluginParameter<H>;
465
- message: string;
466
617
  }): Promise<void>;
467
618
  getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
468
619
  getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
@@ -477,4 +628,4 @@ type Options = {
477
628
  };
478
629
  //#endregion
479
630
  export { Options as t };
480
- //# sourceMappingURL=types-BNmRHGEx.d.cts.map
631
+ //# sourceMappingURL=types-BWfxOttU.d.ts.map