@kubb/core 5.0.0-alpha.34 → 5.0.0-alpha.35

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/src/types.ts CHANGED
@@ -1,92 +1,15 @@
1
1
  import type { AsyncEventEmitter, PossiblePromise } from '@internals/utils'
2
- import type { FileNode, ImportNode, InputNode, Node, OperationNode, Printer, SchemaNode, Visitor } from '@kubb/ast/types'
2
+ import type { FileNode, ImportNode, InputNode, Node, OperationNode, SchemaNode, Visitor } from '@kubb/ast'
3
3
  import type { HttpMethod } from '@kubb/oas'
4
- import type { KubbReactNode } from '@kubb/renderer-jsx/types'
5
4
  import type { DEFAULT_STUDIO_URL, logLevel } from './constants.ts'
5
+ import type { RendererFactory } from './createRenderer.ts'
6
6
  import type { Storage } from './createStorage.ts'
7
7
  import type { Generator } from './defineGenerator.ts'
8
8
  import type { Parser } from './defineParser.ts'
9
- import type { KubbEvents } from './Kubb.ts'
9
+ import type { KubbHooks } from './Kubb.ts'
10
10
  import type { PluginDriver } from './PluginDriver.ts'
11
11
 
12
- export type { Printer, PrinterFactoryOptions, PrinterPartial } from '@kubb/ast/types'
13
-
14
- declare global {
15
- namespace Kubb {
16
- interface PluginContext {}
17
- /**
18
- * Registry that maps plugin names to their `PluginFactoryOptions`.
19
- * Augment this interface in each plugin's `types.ts` to enable automatic
20
- * typing for `getPlugin` and `requirePlugin`.
21
- *
22
- * @example
23
- * ```ts
24
- * // packages/plugin-ts/src/types.ts
25
- * declare global {
26
- * namespace Kubb {
27
- * interface PluginRegistry {
28
- * 'plugin-ts': PluginTs
29
- * }
30
- * }
31
- * }
32
- * ```
33
- */
34
- interface PluginRegistry {}
35
- }
36
- }
37
-
38
- /**
39
- * Config used in `kubb.config.ts`
40
- *
41
- * @example
42
- * import { defineConfig } from '@kubb/core'
43
- * export default defineConfig({
44
- * ...
45
- * })
46
- */
47
- export type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter'> & {
48
- /**
49
- * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
50
- * @default process.cwd()
51
- */
52
- root?: string
53
- /**
54
- * An array of parsers used to convert generated files to strings.
55
- * Each parser handles specific file extensions (e.g. `.ts`, `.tsx`).
56
- *
57
- * A catch-all fallback parser is always appended last for any unhandled extension.
58
- *
59
- * When omitted, `parserTsx` from `@kubb/parser-ts` is used automatically as the
60
- * default (requires `@kubb/parser-ts` to be installed as an optional dependency).
61
- * @default [parserTsx] — from `@kubb/parser-ts`
62
- * @example
63
- * ```ts
64
- * import { parserTs, tsxParser } from '@kubb/parser-ts'
65
- * export default defineConfig({
66
- * parsers: [parserTs, tsxParser],
67
- * })
68
- * ```
69
- */
70
- parsers?: Array<Parser>
71
- /**
72
- * Adapter that converts the input file into a `@kubb/ast` `InputNode` — the universal
73
- * intermediate representation consumed by all Kubb plugins.
74
- *
75
- * When omitted, `adapterOas()` from `@kubb/adapter-oas` is used automatically as the
76
- * default (requires `@kubb/adapter-oas` to be installed as an optional dependency).
77
- *
78
- * - Use `@kubb/adapter-oas` for OpenAPI / Swagger (default).
79
- * - Use `@kubb/adapter-drizzle` or `@kubb/adapter-asyncapi` for other formats.
80
- *
81
- * @default adapterOas() — from `@kubb/adapter-oas`
82
- */
83
- adapter?: Adapter
84
- /**
85
- * An array of Kubb plugins used for generation. Each plugin may have additional configurable options (defined within the plugin itself). If a plugin relies on another plugin, an error will occur if the required dependency is missing. Refer to “pre” for more details.
86
- */
87
- // inject needs to be omitted because else we have a clash with the PluginDriver instance
88
- plugins?: Array<Omit<UnknownUserPlugin, 'inject'>>
89
- }
12
+ export type { Renderer, RendererFactory } from './createRenderer.ts'
90
13
 
91
14
  export type InputPath = {
92
15
  /**
@@ -178,6 +101,12 @@ export type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptio
178
101
  getImports: (node: SchemaNode, resolve: (schemaName: string) => { name: string; path: string }) => Array<ImportNode>
179
102
  }
180
103
 
104
+ /**
105
+ * Controls how `index.ts` barrel files are generated.
106
+ * - `'all'` — exports every generated symbol from every file.
107
+ * - `'named'` — exports only explicitly named exports.
108
+ * - `'propagate'` — propagates re-exports from nested barrel files upward.
109
+ */
181
110
  export type BarrelType = 'all' | 'named' | 'propagate'
182
111
 
183
112
  export type DevtoolsOptions = {
@@ -238,13 +167,14 @@ export type Config<TInput = Input> = {
238
167
  */
239
168
  adapter: Adapter
240
169
  /**
241
- * You can use either `input.path` or `input.data`, depending on your specific needs.
170
+ * Source file or data to generate code from.
171
+ * Use `input.path` for a file on disk or `input.data` for an inline string or object.
242
172
  */
243
173
  input: TInput
244
174
  output: {
245
175
  /**
246
- * The path where all generated files receives exported.
247
- * This can be an absolute path or a path relative to the specified root option.
176
+ * Output directory for generated files.
177
+ * Accepts an absolute path or a path relative to `root`.
248
178
  */
249
179
  path: string
250
180
  /**
@@ -317,11 +247,28 @@ export type Config<TInput = Input> = {
317
247
  override?: boolean
318
248
  }
319
249
  /**
320
- * An array of Kubb plugins that used in the generation.
321
- * Each plugin may include additional configurable options(defined in the plugin itself).
322
- * If a plugin depends on another plugin, an error is returned if the required dependency is missing. See pre for more details.
250
+ * An array of Kubb plugins used for code generation.
251
+ * Each plugin may declare additional configurable options.
252
+ * If a plugin depends on another, an error is thrown when the dependency is missing.
253
+ * Use `dependencies` on the plugin to declare execution order.
323
254
  */
324
255
  plugins: Array<Plugin>
256
+ /**
257
+ * Project-wide renderer factory. All plugins and generators that do not declare their own
258
+ * `renderer` ultimately fall back to this value.
259
+ *
260
+ * The resolution chain is: `generator.renderer` → `plugin.renderer` → `config.renderer` → `undefined` (raw `FileNode[]` mode).
261
+ *
262
+ * @example
263
+ * ```ts
264
+ * import { jsxRenderer } from '@kubb/renderer-jsx'
265
+ * export default defineConfig({
266
+ * renderer: jsxRenderer,
267
+ * plugins: [pluginTs(), pluginZod()],
268
+ * })
269
+ * ```
270
+ */
271
+ renderer?: RendererFactory
325
272
  /**
326
273
  * Devtools configuration for Kubb Studio integration.
327
274
  */
@@ -400,22 +347,6 @@ export type Resolver = {
400
347
  resolveFooter(node: InputNode | null, context: ResolveBannerContext): string | undefined
401
348
  }
402
349
 
403
- /**
404
- * The user-facing subset of a `Resolver` — everything except the four methods injected by
405
- * `defineResolver` (`default`, `resolveOptions`, `resolvePath`, and `resolveFile`).
406
- *
407
- * All four injected methods can still be overridden by providing them explicitly in the builder.
408
- *
409
- * @example
410
- * ```ts
411
- * export const resolver = defineResolver<PluginTs>(() => ({
412
- * name: 'default',
413
- * resolveName(node) { return this.default(node.name, 'function') },
414
- * }))
415
- * ```
416
- */
417
- export type UserResolver = Omit<Resolver, 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>
418
-
419
350
  export type PluginFactoryOptions<
420
351
  /**
421
352
  * Name to be used for the plugin.
@@ -451,15 +382,20 @@ export type PluginFactoryOptions<
451
382
  resolver: TResolver
452
383
  }
453
384
 
385
+ /**
386
+ * @deprecated
387
+ */
454
388
  export type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
455
389
  /**
456
- * Unique name used for the plugin
457
- * The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
458
- * @example @kubb/typescript
390
+ * Unique name used for the plugin.
391
+ * The name follows the format `scope:foo-bar` or `foo-bar` adding a scope avoids conflicts with other plugins.
392
+ *
393
+ * @example Plugin name
394
+ * `'@kubb/typescript'`
459
395
  */
460
396
  name: TOptions['name']
461
397
  /**
462
- * Options set for a specific plugin(see kubb.config.js), passthrough of options.
398
+ * Resolved options merged with output/include/exclude/override defaults for the current plugin.
463
399
  */
464
400
  options: TOptions['resolvedOptions'] & {
465
401
  output: Output
@@ -469,24 +405,43 @@ export type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOpti
469
405
  }
470
406
  /**
471
407
  * The resolver for this plugin.
472
- * Composed by `getPreset` from the preset resolver and the user's `resolver` partial override.
408
+ * Set via `setResolver()` in `kubb:plugin:setup` or passed as a user option.
473
409
  */
474
410
  resolver?: TOptions['resolver']
475
411
  /**
476
412
  * The composed transformer for this plugin.
477
- * Composed by `getPreset` from the preset's transformers and the user's `transformer` visitor.
478
- * When a visitor method returns `null`/`undefined`, the preset transformer's result is used instead.
413
+ * Set via `setTransformer()` in `kubb:plugin:setup` or passed as a user option.
479
414
  */
480
415
  transformer?: Visitor
481
416
  /**
482
- * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins.
483
- * Can be used to validate dependent plugins.
417
+ * Plugin-level renderer factory. All generators that do not declare their own `renderer`
418
+ * inherit this value. A generator can explicitly opt out by setting `renderer: null`.
419
+ *
420
+ * @example
421
+ * ```ts
422
+ * import { jsxRenderer } from '@kubb/renderer-jsx'
423
+ * createPlugin((options) => ({
424
+ * name: 'my-plugin',
425
+ * renderer: jsxRenderer,
426
+ * generators: [
427
+ * { name: 'types', schema(node) { return <File>...</File> } }, // inherits jsxRenderer
428
+ * { name: 'raw', renderer: null, schema(node) { return [...] } }, // explicit opt-out
429
+ * ],
430
+ * }))
431
+ * ```
432
+ */
433
+ renderer?: RendererFactory
434
+ /**
435
+ * Generators declared directly on the plugin. Each generator's `renderer` takes precedence
436
+ * over `plugin.renderer`; set `renderer: null` on a generator to opt out of rendering even
437
+ * when the plugin declares a renderer.
484
438
  */
485
- pre?: Array<string>
439
+ generators?: Array<Generator<any>>
486
440
  /**
487
- * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins.
441
+ * Specifies the plugins that the current plugin depends on. The current plugin is executed after all listed plugins.
442
+ * An error is returned if any required dependency plugin is missing.
488
443
  */
489
- post?: Array<string>
444
+ dependencies?: Array<string>
490
445
  /**
491
446
  * When `apply` is defined, the plugin is only activated when `apply(config)` returns `true`.
492
447
  * Inspired by Vite's `apply` option.
@@ -514,10 +469,11 @@ export type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOpti
514
469
  inject?: (this: PluginContext<TOptions>) => TOptions['context']
515
470
  }
516
471
 
472
+ /**
473
+ * @deprecated
474
+ */
517
475
  export type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>
518
476
 
519
- type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<string, object, object, unknown, object>>
520
-
521
477
  /**
522
478
  * Handler for a single schema node. Used by the `schema` hook on a plugin.
523
479
  */
@@ -525,7 +481,7 @@ export type SchemaHook<TOptions extends PluginFactoryOptions = PluginFactoryOpti
525
481
  this: GeneratorContext<TOptions>,
526
482
  node: SchemaNode,
527
483
  options: TOptions['resolvedOptions'],
528
- ) => PossiblePromise<KubbReactNode | Array<FileNode> | void>
484
+ ) => PossiblePromise<unknown | Array<FileNode> | void>
529
485
 
530
486
  /**
531
487
  * Handler for a single operation node. Used by the `operation` hook on a plugin.
@@ -534,7 +490,7 @@ export type OperationHook<TOptions extends PluginFactoryOptions = PluginFactoryO
534
490
  this: GeneratorContext<TOptions>,
535
491
  node: OperationNode,
536
492
  options: TOptions['resolvedOptions'],
537
- ) => PossiblePromise<KubbReactNode | Array<FileNode> | void>
493
+ ) => PossiblePromise<unknown | Array<FileNode> | void>
538
494
 
539
495
  /**
540
496
  * Handler for all collected operation nodes. Used by the `operations` hook on a plugin.
@@ -543,23 +499,23 @@ export type OperationsHook<TOptions extends PluginFactoryOptions = PluginFactory
543
499
  this: GeneratorContext<TOptions>,
544
500
  nodes: Array<OperationNode>,
545
501
  options: TOptions['resolvedOptions'],
546
- ) => PossiblePromise<KubbReactNode | Array<FileNode> | void>
547
-
502
+ ) => PossiblePromise<unknown | Array<FileNode> | void>
503
+ /**
504
+ * @deprecated will be replaced with HookStylePlugin
505
+ */
548
506
  export type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
549
507
  /**
550
- * Unique name used for the plugin
551
- * @example @kubb/typescript
508
+ * Unique name used for the plugin.
509
+ *
510
+ * @example Plugin name
511
+ * `'@kubb/typescript'`
552
512
  */
553
513
  name: TOptions['name']
554
514
  /**
555
- * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins.
556
- * Can be used to validate dependent plugins.
557
- */
558
- pre?: Array<string>
559
- /**
560
- * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins.
515
+ * Specifies the plugins that the current plugin depends on. The current plugin is executed after all listed plugins.
516
+ * An error is returned if any required dependency plugin is missing.
561
517
  */
562
- post?: Array<string>
518
+ dependencies?: Array<string>
563
519
  /**
564
520
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
565
521
  */
@@ -571,13 +527,12 @@ export type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
571
527
  }
572
528
  /**
573
529
  * The resolver for this plugin.
574
- * Composed by `getPreset` from the preset resolver and the user's `resolver` partial override.
530
+ * Set via `setResolver()` in `kubb:plugin:setup` or passed as a user option.
575
531
  */
576
532
  resolver: TOptions['resolver']
577
533
  /**
578
- * The composed transformer for this plugin. Accessible via `context.transformer`.
579
- * Composed by `getPreset` from the preset's transformers and the user's `transformer` visitor.
580
- * When a visitor method returns `null`/`undefined`, the preset transformer's result is used instead.
534
+ * The composed transformer for this plugin.
535
+ * Set via `setTransformer()` in `kubb:plugin:setup` or passed as a user option.
581
536
  */
582
537
  transformer?: Visitor
583
538
 
@@ -591,6 +546,17 @@ export type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
591
546
  * Used in diagnostic messages and version-conflict detection.
592
547
  */
593
548
  version?: string
549
+ /**
550
+ * Plugin-level renderer factory. All generators that do not declare their own `renderer`
551
+ * inherit this value. A generator can explicitly opt out by setting `renderer: null`.
552
+ */
553
+ renderer?: RendererFactory
554
+ /**
555
+ * Generators declared directly on the plugin. Each generator's `renderer` takes precedence
556
+ * over `plugin.renderer`; set `renderer: null` on a generator to opt out of rendering even
557
+ * when the plugin declares a renderer.
558
+ */
559
+ generators?: Array<Generator<any>>
594
560
 
595
561
  buildStart: (this: PluginContext<TOptions>) => PossiblePromise<void>
596
562
  /**
@@ -625,20 +591,22 @@ export type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
625
591
  */
626
592
  inject: (this: PluginContext<TOptions>) => TOptions['context']
627
593
  }
628
-
594
+ /**
595
+ * @deprecated
596
+ */
629
597
  export type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>
630
-
598
+ /**
599
+ * @deprecated
600
+ */
631
601
  export type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
632
602
  /**
633
603
  * Called once per plugin at the start of its processing phase, before schema/operation/operations hooks run.
634
604
  * Use this to set up shared state, fetch remote data, or perform any async initialization.
635
- * @type hookParallel
636
605
  */
637
606
  buildStart?: (this: PluginContext<TOptions>) => PossiblePromise<void>
638
607
  /**
639
608
  * Called once per plugin after all files have been written to disk.
640
609
  * Use this for post-processing, copying assets, or generating summary reports.
641
- * @type hookParallel
642
610
  */
643
611
  buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>
644
612
  /**
@@ -666,23 +634,30 @@ export type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactor
666
634
  */
667
635
  operations?: OperationsHook<TOptions>
668
636
  /**
669
- * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
670
- * Options can als be included.
671
- * @type hookFirst
672
- * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
673
- * @deprecated this will be replaced by resolvers
637
+ * Resolves a path from a baseName and directory.
638
+ * Options can also be included.
639
+ *
640
+ * @example
641
+ * `('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'`
642
+ *
643
+ * @deprecated Use resolvers instead.
674
644
  */
675
645
  resolvePath?: (this: PluginContext<TOptions>, baseName: FileNode['baseName'], mode?: 'single' | 'split', options?: TOptions['resolvePathOptions']) => string
676
646
  /**
677
- * Resolve to a name based on a string.
647
+ * Resolves a display name from a raw string.
678
648
  * Useful when converting to PascalCase or camelCase.
679
- * @type hookFirst
680
- * @example ('pet') => 'Pet'
681
- * @deprecated this will be replaced by resolvers
649
+ *
650
+ * @example
651
+ * `('pet') => 'Pet'`
652
+ *
653
+ * @deprecated Use resolvers instead.
682
654
  */
683
655
  resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
684
656
  }
685
657
 
658
+ /**
659
+ * @deprecated
660
+ */
686
661
  export type PluginLifecycleHooks = keyof PluginLifecycle
687
662
 
688
663
  export type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>
@@ -692,7 +667,7 @@ export type ResolvePathParams<TOptions = object> = {
692
667
  baseName: FileNode['baseName']
693
668
  mode?: 'single' | 'split'
694
669
  /**
695
- * Options to be passed to 'resolvePath' 3th parameter
670
+ * Options passed as the third argument to `resolvePath`.
696
671
  */
697
672
  options?: TOptions
698
673
  }
@@ -702,15 +677,16 @@ export type ResolveNameParams = {
702
677
  pluginName?: string
703
678
  /**
704
679
  * Specifies the type of entity being named.
705
- * - 'file' customizes the name of the created file (uses camelCase).
706
- * - 'function' customizes the exported function names (uses camelCase).
707
- * - 'type' customizes TypeScript types (uses PascalCase).
708
- * - 'const' customizes variable names (uses camelCase).
709
- * @default undefined
680
+ * - `'file'` customizes the name of the created file (camelCase).
681
+ * - `'function'` customizes the exported function names (camelCase).
682
+ * - `'type'` customizes TypeScript type names (PascalCase).
683
+ * - `'const'` customizes variable names (camelCase).
710
684
  */
711
685
  type?: 'file' | 'function' | 'type' | 'const'
712
686
  }
713
-
687
+ /**
688
+ * @deprecated
689
+ */
714
690
  export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
715
691
  config: Config
716
692
  /**
@@ -738,19 +714,16 @@ export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryO
738
714
  requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>
739
715
  requirePlugin(name: string): Plugin
740
716
  /**
741
- * Only add when the file does not exist yet
717
+ * Add files only when they do not exist yet.
742
718
  */
743
719
  addFile: (...file: Array<FileNode>) => Promise<void>
744
720
  /**
745
- * merging multiple sources into the same output file
721
+ * Merge multiple sources into the same output file.
746
722
  */
747
723
  upsertFile: (...file: Array<FileNode>) => Promise<void>
724
+ hooks: AsyncEventEmitter<KubbHooks>
748
725
  /**
749
- * @deprecated use this.warn, this.error, this.info instead
750
- */
751
- events: AsyncEventEmitter<KubbEvents>
752
- /**
753
- * Current plugin
726
+ * The current plugin.
754
727
  */
755
728
  plugin: Plugin<TOptions>
756
729
  /**
@@ -765,17 +738,17 @@ export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryO
765
738
 
766
739
  /**
767
740
  * Emit a warning via the build event system.
768
- * Shorthand for `this.events.emit('warn', message)`.
741
+ * Shorthand for `this.hooks.emit('kubb:warn', message)`.
769
742
  */
770
743
  warn: (message: string) => void
771
744
  /**
772
745
  * Emit an error via the build event system.
773
- * Shorthand for `this.events.emit('error', error)`.
746
+ * Shorthand for `this.hooks.emit('kubb:error', error)`.
774
747
  */
775
748
  error: (error: string | Error) => void
776
749
  /**
777
750
  * Emit an info message via the build event system.
778
- * Shorthand for `this.events.emit('info', message)`.
751
+ * Shorthand for `this.hooks.emit('kubb:info', message)`.
779
752
  */
780
753
  info: (message: string) => void
781
754
  /**
@@ -792,7 +765,7 @@ export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryO
792
765
  */
793
766
  inputNode: InputNode
794
767
  /**
795
- * Return the adapter from `@kubb/ast`
768
+ * The adapter from `@kubb/ast`.
796
769
  */
797
770
  adapter: Adapter
798
771
  }
@@ -804,23 +777,27 @@ export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryO
804
777
  Kubb.PluginContext
805
778
 
806
779
  /**
807
- * Narrowed `PluginContext` used as the `this` type inside generator and plugin AST hook methods.
780
+ * Context object passed as the second argument to generator `schema`, `operation`, and
781
+ * `operations` methods.
808
782
  *
809
- * Generators and the `schema`/`operation`/`operations` plugin hooks are only invoked from
810
- * `runPluginAstHooks`, which already guards against a missing adapter. This type reflects
811
- * that guarantee — `this.adapter` and `this.inputNode` are always defined, so no runtime
812
- * checks or casts are needed inside the method bodies.
783
+ * Generators are only invoked from `runPluginAstHooks`, which already guards against a
784
+ * missing adapter. This type reflects that guarantee — `ctx.adapter` and `ctx.inputNode`
785
+ * are always defined, so no runtime checks or casts are needed inside generator bodies.
786
+ *
787
+ * `ctx.options` carries the per-node resolved options for `schema`/`operation` calls
788
+ * (after exclude/include/override filtering) and the plugin-level options for `operations`.
813
789
  */
814
790
  export type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Omit<PluginContext<TOptions>, 'adapter' | 'inputNode'> & {
815
791
  adapter: Adapter
816
792
  inputNode: InputNode
793
+ options: TOptions['resolvedOptions']
817
794
  }
818
795
  /**
819
- * Specify the export location for the files and define the behavior of the output
796
+ * Configure generated file output location and behavior.
820
797
  */
821
798
  export type Output<_TOptions = unknown> = {
822
799
  /**
823
- * Path to the output folder or file that will contain the generated code
800
+ * Path to the output folder or file that will contain generated code.
824
801
  */
825
802
  path: string
826
803
  /**
@@ -829,11 +806,13 @@ export type Output<_TOptions = unknown> = {
829
806
  */
830
807
  barrelType?: BarrelType | false
831
808
  /**
832
- * Add a banner text in the beginning of every file
809
+ * Text or function appended at the start of every generated file.
810
+ * When a function, receives the current `InputNode` and must return a string.
833
811
  */
834
812
  banner?: string | ((node?: InputNode) => string)
835
813
  /**
836
- * Add a footer text in the beginning of every file
814
+ * Text or function appended at the end of every generated file.
815
+ * When a function, receives the current `InputNode` and must return a string.
837
816
  */
838
817
  footer?: string | ((node?: InputNode) => string)
839
818
  /**
@@ -845,28 +824,27 @@ export type Output<_TOptions = unknown> = {
845
824
 
846
825
  export type UserGroup = {
847
826
  /**
848
- * Defines the type where to group the files.
849
- * - 'tag' groups files by OpenAPI tags.
850
- * - 'path' groups files by OpenAPI paths.
851
- * @default undefined
827
+ * Determines how files are grouped into subdirectories.
828
+ * - `'tag'` groups files by OpenAPI tags.
829
+ * - `'path'` groups files by OpenAPI paths.
852
830
  */
853
831
  type: 'tag' | 'path'
854
832
  /**
855
- * Return the name of a group based on the group name, this is used for the file and name generation.
833
+ * Returns the subdirectory name for a given group value.
834
+ * Defaults to `${camelCase(group)}Controller` for tags and the first path segment for paths.
856
835
  */
857
836
  name?: (context: { group: string }) => string
858
837
  }
859
838
 
860
839
  export type Group = {
861
840
  /**
862
- * Defines the type where to group the files.
863
- * - 'tag' groups files by OpenAPI tags.
864
- * - 'path' groups files by OpenAPI paths.
865
- * @default undefined
841
+ * Determines how files are grouped into subdirectories.
842
+ * - `'tag'` groups files by OpenAPI tags.
843
+ * - `'path'` groups files by OpenAPI paths.
866
844
  */
867
845
  type: 'tag' | 'path'
868
846
  /**
869
- * Return the name of a group based on the group name, this is used for the file and name generation.
847
+ * Returns the subdirectory name for a given group value.
870
848
  */
871
849
  name: (context: { group: string }) => string
872
850
  }
@@ -881,7 +859,7 @@ export type LoggerOptions = {
881
859
  /**
882
860
  * Shared context passed to all plugins, parsers, and other internals.
883
861
  */
884
- export type LoggerContext = AsyncEventEmitter<KubbEvents>
862
+ export type LoggerContext = AsyncEventEmitter<KubbHooks>
885
863
 
886
864
  export type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
887
865
  name: string
@@ -899,46 +877,84 @@ export type CompatibilityPreset = 'default' | 'kubbV4'
899
877
 
900
878
  export type { Storage } from './createStorage.ts'
901
879
  export type { Generator } from './defineGenerator.ts'
902
- export type { KubbEvents } from './Kubb.ts'
880
+ export type { HookStylePlugin, PluginHooks } from './definePlugin.ts'
881
+ export type { Kubb, KubbHooks } from './Kubb.ts'
903
882
 
904
883
  /**
905
- * A preset bundles a name, a resolver, optional AST transformers,
906
- * and optional generators into a single reusable configuration object.
907
- *
908
- * @template TResolver - The concrete resolver type for this preset.
884
+ * Context passed to a hook-style plugin's `kubb:plugin:setup` handler.
885
+ * Provides methods to register generators, configure the resolver, transformer,
886
+ * and renderer, as well as access to the current build configuration.
909
887
  */
910
- export type Preset<TResolver extends Resolver = Resolver> = {
888
+ export type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
911
889
  /**
912
- * Unique identifier for this preset.
890
+ * Register a generator on this plugin. Generators are invoked during the AST walk
891
+ * (schema/operation/operations) exactly like generators declared statically on `createPlugin`.
913
892
  */
914
- name: string
893
+ addGenerator<TElement = unknown>(generator: Generator<TFactory, TElement>): void
915
894
  /**
916
- * The resolver used by this preset.
895
+ * Set or partially override the resolver for this plugin.
896
+ * The resolver controls file naming and path resolution for generated files.
897
+ *
898
+ * When `TFactory` is a concrete `PluginFactoryOptions` (e.g. `PluginClient`),
899
+ * the resolver parameter is typed to the plugin's own resolver type (e.g. `ResolverClient`).
917
900
  */
918
- resolver: TResolver
901
+ setResolver(resolver: Partial<TFactory['resolver']>): void
919
902
  /**
920
- * Optional AST visitors / transformers applied after resolving.
903
+ * Set the AST transformer (visitor) for this plugin.
904
+ * The transformer pre-processes nodes before they reach the generators.
921
905
  */
922
- transformers?: Array<Visitor>
906
+ setTransformer(visitor: Visitor): void
923
907
  /**
924
- * Optional generators used by this preset. Plugin implementations cast this
925
- * to their concrete generator type.
908
+ * Set the renderer factory for this plugin.
909
+ * Used to process JSX elements returned by generators.
926
910
  */
927
- generators?: Array<Generator<any>>
911
+ setRenderer(renderer: RendererFactory): void
912
+ /**
913
+ * Set the resolved options for the build loop. These options are merged into the
914
+ * normalized plugin's `options` object (which includes `output`, `exclude`, `override`).
915
+ *
916
+ * Call this in `kubb:plugin:setup` to provide the resolved options that generators
917
+ * and the build loop need (e.g., `enumType`, `optionalType`, `group`).
918
+ */
919
+ setOptions(options: TFactory['resolvedOptions']): void
920
+ /**
921
+ * Inject a raw file into the build output, bypassing the normal generation pipeline.
922
+ */
923
+ injectFile(file: Pick<FileNode, 'baseName' | 'path'> & { sources?: FileNode['sources'] }): void
928
924
  /**
929
- * Optional printer factory used by this preset.
930
- * The generator calls this function at render-time to produce a configured printer instance.
925
+ * Merge a partial config update into the current build configuration.
931
926
  */
932
- printer?: (options: any) => Printer
927
+ updateConfig(config: Partial<Config>): void
928
+ /**
929
+ * The resolved build configuration at the time of setup.
930
+ */
931
+ config: Config
932
+ /**
933
+ * The plugin's own options as passed by the user.
934
+ */
935
+ options: TFactory['options']
933
936
  }
934
937
 
935
938
  /**
936
- * A named registry of presets, keyed by preset name.
937
- *
938
- * @template TResolver - The concrete resolver type shared by all presets in this registry.
939
- * @template TName - The union of valid preset name keys.
939
+ * Context passed to a hook-style plugin's `kubb:build:start` handler.
940
+ * Fires immediately before the plugin execution loop begins.
941
+ */
942
+ export type KubbBuildStartContext = {
943
+ config: Config
944
+ adapter: Adapter
945
+ inputNode: InputNode
946
+ getPlugin(name: string): Plugin | undefined
947
+ }
948
+
949
+ /**
950
+ * Context passed to a hook-style plugin's `kubb:build:end` handler.
951
+ * Fires after all files have been written to disk.
940
952
  */
941
- export type Presets<TResolver extends Resolver = Resolver> = Record<CompatibilityPreset, Preset<TResolver>>
953
+ export type KubbBuildEndContext = {
954
+ files: Array<FileNode>
955
+ config: Config
956
+ outputDir: string
957
+ }
942
958
 
943
959
  type ByTag = {
944
960
  type: 'tag'
@@ -975,9 +991,22 @@ type ByContentType = {
975
991
  pattern: string | RegExp
976
992
  }
977
993
 
994
+ /**
995
+ * A pattern filter that prevents matching nodes from being generated.
996
+ * Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
997
+ */
978
998
  export type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
999
+
1000
+ /**
1001
+ * A pattern filter that restricts generation to only matching nodes.
1002
+ * Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
1003
+ */
979
1004
  export type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
980
1005
 
1006
+ /**
1007
+ * A pattern filter paired with partial option overrides applied when the pattern matches.
1008
+ * Match by `tag`, `operationId`, `path`, `method`, `schemaName`, or `contentType`.
1009
+ */
981
1010
  export type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
982
1011
  //TODO should be options: Omit<Partial<TOptions>, 'override'>
983
1012
  options: Partial<TOptions>
@@ -1090,7 +1119,44 @@ export type ResolveBannerContext = {
1090
1119
  config: Config
1091
1120
  }
1092
1121
 
1093
- export type { CLIOptions, ConfigInput } from './defineConfig.ts'
1122
+ /**
1123
+ * CLI options derived from command-line flags.
1124
+ */
1125
+ export type CLIOptions = {
1126
+ /**
1127
+ * Path to `kubb.config.js`.
1128
+ */
1129
+ config?: string
1130
+ /**
1131
+ * Enable watch mode for input files.
1132
+ */
1133
+ watch?: boolean
1134
+ /**
1135
+ * Logging verbosity for CLI usage.
1136
+ * @default 'silent'
1137
+ */
1138
+ logLevel?: 'silent' | 'info' | 'debug'
1139
+ }
1140
+
1141
+ /**
1142
+ * All accepted forms of a Kubb configuration.
1143
+ *
1144
+ * Config is always `@kubb/core` {@link Config}.
1145
+ * - `PossibleConfig` accepts `Config`/`Config[]`/promise or a no-arg config factory.
1146
+ * - `PossibleConfig<TCliOptions>` accepts the same config forms or a config factory receiving `TCliOptions`.
1147
+ */
1148
+ export type PossibleConfig<TCliOptions = undefined> =
1149
+ | PossiblePromise<Config | Config[]>
1150
+ | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Config[]>)
1151
+
1152
+ /**
1153
+ * All accepted forms of a Kubb configuration.
1154
+ * @deprecated
1155
+ * Kept for backward compatibility. Prefer `PossibleConfig<CLIOptions>` in new code.
1156
+ */
1157
+ export type ConfigInput = PossibleConfig<CLIOptions>
1158
+
1159
+ export type { BuildOutput } from './createKubb.ts'
1094
1160
  export type { Parser } from './defineParser.ts'
1095
1161
  export type { FunctionParamsAST } from './utils/FunctionParams.ts'
1096
1162
  export type { FileMetaBase } from './utils/getBarrelFiles.ts'