@kubb/core 5.0.0-alpha.4 → 5.0.0-alpha.41

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 (71) hide show
  1. package/dist/PluginDriver-BQwm8hDd.cjs +1729 -0
  2. package/dist/PluginDriver-BQwm8hDd.cjs.map +1 -0
  3. package/dist/PluginDriver-CgXFtmNP.js +1617 -0
  4. package/dist/PluginDriver-CgXFtmNP.js.map +1 -0
  5. package/dist/index.cjs +915 -1901
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.ts +268 -264
  8. package/dist/index.js +894 -1863
  9. package/dist/index.js.map +1 -1
  10. package/dist/mocks.cjs +164 -0
  11. package/dist/mocks.cjs.map +1 -0
  12. package/dist/mocks.d.ts +74 -0
  13. package/dist/mocks.js +159 -0
  14. package/dist/mocks.js.map +1 -0
  15. package/dist/types-C6NCtNqM.d.ts +2151 -0
  16. package/package.json +11 -14
  17. package/src/FileManager.ts +131 -0
  18. package/src/FileProcessor.ts +84 -0
  19. package/src/Kubb.ts +174 -85
  20. package/src/PluginDriver.ts +941 -0
  21. package/src/constants.ts +33 -43
  22. package/src/createAdapter.ts +25 -0
  23. package/src/createKubb.ts +605 -0
  24. package/src/createPlugin.ts +31 -0
  25. package/src/createRenderer.ts +57 -0
  26. package/src/createStorage.ts +58 -0
  27. package/src/defineGenerator.ts +88 -100
  28. package/src/defineLogger.ts +13 -3
  29. package/src/defineParser.ts +45 -0
  30. package/src/definePlugin.ts +90 -7
  31. package/src/defineResolver.ts +453 -0
  32. package/src/devtools.ts +14 -14
  33. package/src/index.ts +12 -17
  34. package/src/mocks.ts +234 -0
  35. package/src/renderNode.ts +35 -0
  36. package/src/storages/fsStorage.ts +29 -9
  37. package/src/storages/memoryStorage.ts +2 -2
  38. package/src/types.ts +821 -152
  39. package/src/utils/TreeNode.ts +47 -9
  40. package/src/utils/diagnostics.ts +4 -1
  41. package/src/utils/executeStrategies.ts +16 -13
  42. package/src/utils/getBarrelFiles.ts +88 -15
  43. package/src/utils/isInputPath.ts +10 -0
  44. package/src/utils/packageJSON.ts +75 -0
  45. package/dist/chunk-ByKO4r7w.cjs +0 -38
  46. package/dist/hooks.cjs +0 -50
  47. package/dist/hooks.cjs.map +0 -1
  48. package/dist/hooks.d.ts +0 -49
  49. package/dist/hooks.js +0 -46
  50. package/dist/hooks.js.map +0 -1
  51. package/dist/types-Bbh1o0yW.d.ts +0 -1057
  52. package/src/BarrelManager.ts +0 -74
  53. package/src/PackageManager.ts +0 -180
  54. package/src/PluginManager.ts +0 -668
  55. package/src/PromiseManager.ts +0 -40
  56. package/src/build.ts +0 -420
  57. package/src/config.ts +0 -56
  58. package/src/defineAdapter.ts +0 -22
  59. package/src/defineStorage.ts +0 -56
  60. package/src/errors.ts +0 -1
  61. package/src/hooks/index.ts +0 -8
  62. package/src/hooks/useKubb.ts +0 -22
  63. package/src/hooks/useMode.ts +0 -11
  64. package/src/hooks/usePlugin.ts +0 -11
  65. package/src/hooks/usePluginManager.ts +0 -11
  66. package/src/utils/FunctionParams.ts +0 -155
  67. package/src/utils/formatters.ts +0 -56
  68. package/src/utils/getConfigs.ts +0 -30
  69. package/src/utils/getPlugins.ts +0 -23
  70. package/src/utils/linters.ts +0 -25
  71. package/src/utils/resolveOptions.ts +0 -93
package/src/types.ts CHANGED
@@ -1,41 +1,15 @@
1
1
  import type { AsyncEventEmitter, PossiblePromise } from '@internals/utils'
2
- import type { RootNode, SchemaNode } from '@kubb/ast/types'
3
- import type { KubbFile } from '@kubb/fabric-core/types'
4
- import type { Fabric } from '@kubb/react-fabric'
2
+ import type { FileNode, HttpMethod, ImportNode, InputNode, Node, OperationNode, SchemaNode, Visitor } from '@kubb/ast'
5
3
  import type { DEFAULT_STUDIO_URL, logLevel } from './constants.ts'
6
- import type { DefineStorage } from './defineStorage.ts'
7
- import type { KubbEvents } from './Kubb.ts'
8
- import type { PluginManager } from './PluginManager.ts'
4
+ import type { RendererFactory } from './createRenderer.ts'
5
+ import type { Storage } from './createStorage.ts'
6
+ import type { Generator } from './defineGenerator.ts'
7
+ import type { Parser } from './defineParser.ts'
8
+ import type { HookStylePlugin } from './definePlugin.ts'
9
+ import type { KubbHooks } from './Kubb.ts'
10
+ import type { PluginDriver } from './PluginDriver.ts'
9
11
 
10
- export type { Printer, PrinterFactoryOptions } from '@kubb/ast/types'
11
-
12
- declare global {
13
- namespace Kubb {
14
- interface PluginContext {}
15
- }
16
- }
17
-
18
- /**
19
- * Config used in `kubb.config.ts`
20
- *
21
- * @example
22
- * import { defineConfig } from '@kubb/core'
23
- * export default defineConfig({
24
- * ...
25
- * })
26
- */
27
- export type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins'> & {
28
- /**
29
- * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
30
- * @default process.cwd()
31
- */
32
- root?: string
33
- /**
34
- * 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.
35
- */
36
- // inject needs to be omitted because else we have a clash with the PluginManager instance
37
- plugins?: Array<Omit<UnknownUserPlugin, 'inject'>>
38
- }
12
+ export type { Renderer, RendererFactory } from './createRenderer.ts'
39
13
 
40
14
  export type InputPath = {
41
15
  /**
@@ -51,7 +25,7 @@ export type InputData = {
51
25
  data: string | unknown
52
26
  }
53
27
 
54
- type Input = InputPath | InputData | Array<InputPath>
28
+ type Input = InputPath | InputData
55
29
 
56
30
  /**
57
31
  * The raw source passed to an adapter's `parse` function.
@@ -66,18 +40,25 @@ export type AdapterSource = { type: 'path'; path: string } | { type: 'data'; dat
66
40
  * - `TName` — unique string identifier (e.g. `'oas'`, `'asyncapi'`)
67
41
  * - `TOptions` — raw user-facing options passed to the adapter factory
68
42
  * - `TResolvedOptions` — defaults applied; what the adapter stores as `options`
43
+ * - `TDocument` — type of the raw source document exposed by the adapter after `parse()`
69
44
  */
70
- export type AdapterFactoryOptions<TName extends string = string, TOptions extends object = object, TResolvedOptions extends object = TOptions> = {
45
+ export type AdapterFactoryOptions<
46
+ TName extends string = string,
47
+ TOptions extends object = object,
48
+ TResolvedOptions extends object = TOptions,
49
+ TDocument = unknown,
50
+ > = {
71
51
  name: TName
72
52
  options: TOptions
73
53
  resolvedOptions: TResolvedOptions
54
+ document: TDocument
74
55
  }
75
56
 
76
57
  /**
77
- * An adapter converts a source file or data into a `@kubb/ast` `RootNode`.
58
+ * An adapter converts a source file or data into a `@kubb/ast` `InputNode`.
78
59
  *
79
60
  * Adapters are the single entry-point for different schema formats
80
- * (OpenAPI, AsyncAPI, Drizzle, …) and produce the universal `RootNode`
61
+ * (OpenAPI, AsyncAPI, Drizzle, …) and produce the universal `InputNode`
81
62
  * that all Kubb plugins consume.
82
63
  *
83
64
  * @example
@@ -92,22 +73,40 @@ export type AdapterFactoryOptions<TName extends string = string, TOptions extend
92
73
  * ```
93
74
  */
94
75
  export type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
95
- /** Human-readable identifier, e.g. `'oas'`, `'drizzle'`, `'asyncapi'`. */
76
+ /**
77
+ * Human-readable identifier, e.g. `'oas'`, `'drizzle'`, `'asyncapi'`.
78
+ */
96
79
  name: TOptions['name']
97
- /** Resolved options (after defaults have been applied). */
80
+ /**
81
+ * Resolved options (after defaults have been applied).
82
+ */
98
83
  options: TOptions['resolvedOptions']
99
- /** Convert the raw source into a universal `RootNode`. */
100
- parse: (source: AdapterSource) => PossiblePromise<RootNode>
101
84
  /**
102
- * Extracts `KubbFile.Import` entries needed by a `SchemaNode` tree.
85
+ * The raw source document produced after the first `parse()` call.
86
+ * `undefined` before parsing; typed by the adapter's `TDocument` generic.
87
+ */
88
+ document: TOptions['document'] | null
89
+ inputNode: InputNode | null
90
+ /**
91
+ * Convert the raw source into a universal `InputNode`.
92
+ */
93
+ parse: (source: AdapterSource) => PossiblePromise<InputNode>
94
+ /**
95
+ * Extracts `ImportNode` entries needed by a `SchemaNode` tree.
103
96
  * Populated after the first `parse()` call. Returns an empty array before that.
104
97
  *
105
98
  * The `resolve` callback receives the collision-corrected schema name and must
106
99
  * return the `{ name, path }` pair for the import, or `undefined` to skip it.
107
100
  */
108
- getImports: (node: SchemaNode, resolve: (schemaName: string) => { name: string; path: string }) => Array<KubbFile.Import>
101
+ getImports: (node: SchemaNode, resolve: (schemaName: string) => { name: string; path: string }) => Array<ImportNode>
109
102
  }
110
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
+ */
111
110
  export type BarrelType = 'all' | 'named' | 'propagate'
112
111
 
113
112
  export type DevtoolsOptions = {
@@ -133,31 +132,49 @@ export type Config<TInput = Input> = {
133
132
  */
134
133
  root: string
135
134
  /**
136
- * Adapter that converts the input file into a `@kubb/ast` `RootNode` — the universal
135
+ * An array of parsers used to convert generated files to strings.
136
+ * Each parser handles specific file extensions (e.g. `.ts`, `.tsx`).
137
+ *
138
+ * A catch-all fallback parser is always appended last for any unhandled extension.
139
+ *
140
+ * When omitted, `parserTs` from `@kubb/parser-ts` is used automatically as the
141
+ * default (requires `@kubb/parser-ts` to be installed as an optional dependency).
142
+ * @default [parserTs] — from `@kubb/parser-ts`
143
+ * @example
144
+ * ```ts
145
+ * import { parserTs, tsxParser } from '@kubb/parser-ts'
146
+ * export default defineConfig({
147
+ * parsers: [parserTs, tsxParser],
148
+ * })
149
+ * ```
150
+ */
151
+ parsers: Array<Parser>
152
+ /**
153
+ * Adapter that converts the input file into a `@kubb/ast` `InputNode` — the universal
137
154
  * intermediate representation consumed by all Kubb plugins.
138
155
  *
139
- * - Omit (or pass `undefined`) to use the built-in OpenAPI/Swagger adapter.
140
- * - Use `@kubb/adapter-oas` for explicit OpenAPI configuration (validate, contentType, …).
156
+ * - Use `@kubb/adapter-oas` for OpenAPI / Swagger.
141
157
  * - Use `@kubb/adapter-drizzle` or `@kubb/adapter-asyncapi` for other formats.
142
158
  *
143
159
  * @example
144
160
  * ```ts
145
- * import { drizzleAdapter } from '@kubb/adapter-drizzle'
161
+ * import { adapterOas } from '@kubb/adapter-oas'
146
162
  * export default defineConfig({
147
- * adapter: drizzleAdapter(),
148
- * input: { path: './src/schema.ts' },
163
+ * adapter: adapterOas(),
164
+ * input: { path: './petStore.yaml' },
149
165
  * })
150
166
  * ```
151
167
  */
152
- adapter?: Adapter
168
+ adapter: Adapter
153
169
  /**
154
- * 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.
155
172
  */
156
173
  input: TInput
157
174
  output: {
158
175
  /**
159
- * The path where all generated files receives exported.
160
- * 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`.
161
178
  */
162
179
  path: string
163
180
  /**
@@ -173,16 +190,16 @@ export type Config<TInput = Input> = {
173
190
  /**
174
191
  * Storage backend for generated files.
175
192
  * Defaults to `fsStorage()` — the built-in filesystem driver.
176
- * Accepts any object implementing the {@link DefineStorage} interface.
193
+ * Accepts any object implementing the {@link Storage} interface.
177
194
  * Keys are root-relative paths (e.g. `src/gen/api/getPets.ts`).
178
195
  * @default fsStorage()
179
196
  * @example
180
197
  * ```ts
181
- * import { defineStorage, fsStorage } from '@kubb/core'
182
- * storage: defineStorage(fsStorage())
198
+ * import { memoryStorage } from '@kubb/core'
199
+ * storage: memoryStorage()
183
200
  * ```
184
201
  */
185
- storage?: DefineStorage
202
+ storage?: Storage
186
203
  /**
187
204
  * Specifies the formatting tool to be used.
188
205
  * - 'auto' automatically detects and uses biome or prettier (in that order of preference).
@@ -207,12 +224,12 @@ export type Config<TInput = Input> = {
207
224
  * Overrides the extension for generated imports and exports. By default, each plugin adds an extension.
208
225
  * @default { '.ts': '.ts'}
209
226
  */
210
- extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>
227
+ extension?: Record<FileNode['extname'], FileNode['extname'] | ''>
211
228
  /**
212
229
  * Configures how `index.ts` files are created, including disabling barrel file generation. Each plugin has its own `barrelType` option; this setting controls the root barrel file (e.g., `src/gen/index.ts`).
213
230
  * @default 'named'
214
231
  */
215
- barrelType?: Exclude<BarrelType, 'propagate'> | false
232
+ barrelType?: 'all' | 'named' | false
216
233
  /**
217
234
  * Adds a default banner to the start of every generated file indicating it was generated by Kubb.
218
235
  * - 'simple' adds banner with link to Kubb.
@@ -230,11 +247,28 @@ export type Config<TInput = Input> = {
230
247
  override?: boolean
231
248
  }
232
249
  /**
233
- * An array of Kubb plugins that used in the generation.
234
- * Each plugin may include additional configurable options(defined in the plugin itself).
235
- * 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.
254
+ */
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
+ * ```
236
270
  */
237
- plugins?: Array<Plugin>
271
+ renderer?: RendererFactory
238
272
  /**
239
273
  * Devtools configuration for Kubb Studio integration.
240
274
  */
@@ -261,6 +295,58 @@ export type Config<TInput = Input> = {
261
295
 
262
296
  // plugin
263
297
 
298
+ /**
299
+ * A type/string-pattern filter used for `include`, `exclude`, and `override` matching.
300
+ */
301
+ type PatternFilter = {
302
+ type: string
303
+ pattern: string | RegExp
304
+ }
305
+
306
+ /**
307
+ * A pattern filter paired with partial option overrides to apply when the pattern matches.
308
+ */
309
+ type PatternOverride<TOptions> = PatternFilter & {
310
+ options: Omit<Partial<TOptions>, 'override'>
311
+ }
312
+
313
+ /**
314
+ * Context passed to `resolver.resolveOptions` to apply include/exclude/override filtering
315
+ * for a given operation or schema node.
316
+ */
317
+ export type ResolveOptionsContext<TOptions> = {
318
+ options: TOptions
319
+ exclude?: Array<PatternFilter>
320
+ include?: Array<PatternFilter>
321
+ override?: Array<PatternOverride<TOptions>>
322
+ }
323
+
324
+ /**
325
+ * Base constraint for all plugin resolver objects.
326
+ *
327
+ * `default`, `resolveOptions`, `resolvePath`, and `resolveFile` are injected automatically
328
+ * by `defineResolver` — plugin authors may override them but never need to implement them
329
+ * from scratch.
330
+ *
331
+ * @example
332
+ * ```ts
333
+ * type MyResolver = Resolver & {
334
+ * resolveName(node: SchemaNode): string
335
+ * resolveTypedName(node: SchemaNode): string
336
+ * }
337
+ * ```
338
+ */
339
+ export type Resolver = {
340
+ name: string
341
+ pluginName: Plugin['name']
342
+ default(name: ResolveNameParams['name'], type?: ResolveNameParams['type']): string
343
+ resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null
344
+ resolvePath(params: ResolverPathParams, context: ResolverContext): string
345
+ resolveFile(params: ResolverFileParams, context: ResolverContext): FileNode
346
+ resolveBanner(node: InputNode | null, context: ResolveBannerContext): string | undefined
347
+ resolveFooter(node: InputNode | null, context: ResolveBannerContext): string | undefined
348
+ }
349
+
264
350
  export type PluginFactoryOptions<
265
351
  /**
266
352
  * Name to be used for the plugin.
@@ -282,104 +368,334 @@ export type PluginFactoryOptions<
282
368
  * When calling `resolvePath` you can specify better types.
283
369
  */
284
370
  TResolvePathOptions extends object = object,
371
+ /**
372
+ * Resolver object that encapsulates the naming and path-resolution helpers used by this plugin.
373
+ * Use `defineResolver` to define the resolver object and export it alongside the plugin.
374
+ */
375
+ TResolver extends Resolver = Resolver,
285
376
  > = {
286
377
  name: TName
287
378
  options: TOptions
288
379
  resolvedOptions: TResolvedOptions
289
380
  context: TContext
290
381
  resolvePathOptions: TResolvePathOptions
382
+ resolver: TResolver
291
383
  }
292
384
 
293
- export type GetPluginFactoryOptions<TPlugin extends UserPlugin> = TPlugin extends UserPlugin<infer X> ? X : never
294
-
385
+ /**
386
+ * @deprecated
387
+ */
295
388
  export type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
296
389
  /**
297
- * Unique name used for the plugin
298
- * The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
299
- * @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'`
300
395
  */
301
396
  name: TOptions['name']
302
397
  /**
303
- * 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.
304
399
  */
305
- options: TOptions['resolvedOptions']
400
+ options: TOptions['resolvedOptions'] & {
401
+ output: Output
402
+ include?: Array<Include>
403
+ exclude: Array<Exclude>
404
+ override: Array<Override<TOptions['resolvedOptions']>>
405
+ }
306
406
  /**
307
- * 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.
308
- * Can be used to validate dependent plugins.
407
+ * The resolver for this plugin.
408
+ * Set via `setResolver()` in `kubb:plugin:setup` or passed as a user option.
309
409
  */
310
- pre?: Array<string>
410
+ resolver?: TOptions['resolver']
311
411
  /**
312
- * 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.
412
+ * The composed transformer for this plugin.
413
+ * Set via `setTransformer()` in `kubb:plugin:setup` or passed as a user option.
313
414
  */
314
- post?: Array<string>
315
- inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context']
415
+ transformer?: Visitor
416
+ /**
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.
438
+ */
439
+ generators?: Array<Generator>
440
+ /**
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.
443
+ */
444
+ dependencies?: Array<string>
445
+ /**
446
+ * When `apply` is defined, the plugin is only activated when `apply(config)` returns `true`.
447
+ * Inspired by Vite's `apply` option.
448
+ *
449
+ * @example
450
+ * ```ts
451
+ * apply: (config) => config.output.path !== 'disabled'
452
+ * ```
453
+ */
454
+ apply?: (config: Config) => boolean
455
+ /**
456
+ * Expose shared helpers or data to all other plugins via `PluginContext`.
457
+ * The object returned is merged into the context that every plugin receives.
458
+ * Use the `declare global { namespace Kubb { interface PluginContext { … } } }` pattern
459
+ * to make the injected properties type-safe.
460
+ *
461
+ * @example
462
+ * ```ts
463
+ * inject() {
464
+ * return { getOas: () => parseSpec(this.config) }
465
+ * }
466
+ * // Other plugins can then call `this.getOas()` inside buildStart()
467
+ * ```
468
+ */
469
+ inject?: (this: PluginContext<TOptions>) => TOptions['context']
316
470
  }
317
471
 
472
+ /**
473
+ * @deprecated
474
+ */
318
475
  export type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>
319
476
 
320
- export type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<any, any, any, any, any>>
477
+ /**
478
+ * Partial version of {@link Config} intended for user-facing config entry points.
479
+ *
480
+ * Fields that have sensible defaults (`root`, `plugins`, `parsers`, `adapter`) are optional.
481
+ */
482
+ export type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter'> & {
483
+ /**
484
+ * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
485
+ * @default process.cwd()
486
+ */
487
+ root?: string
488
+ /**
489
+ * An array of parsers used to convert generated files to strings.
490
+ * Each parser handles specific file extensions (e.g. `.ts`, `.tsx`).
491
+ *
492
+ * A catch-all fallback parser is always appended last for any unhandled extension.
493
+ */
494
+ parsers?: Array<Parser>
495
+ /**
496
+ * Adapter that converts the input file into a `@kubb/ast` `InputNode`.
497
+ */
498
+ adapter?: Adapter
499
+ /**
500
+ * User-facing plugins can be either legacy createPlugin instances or hook-style plugins.
501
+ */
502
+ plugins?: Array<Omit<UserPlugin, 'inject'> | HookStylePlugin>
503
+ }
504
+
505
+ /**
506
+ * Handler for a single schema node. Used by the `schema` hook on a plugin.
507
+ */
508
+ export type SchemaHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (
509
+ this: GeneratorContext<TOptions>,
510
+ node: SchemaNode,
511
+ options: TOptions['resolvedOptions'],
512
+ ) => PossiblePromise<unknown | Array<FileNode> | void>
321
513
 
514
+ /**
515
+ * Handler for a single operation node. Used by the `operation` hook on a plugin.
516
+ */
517
+ export type OperationHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (
518
+ this: GeneratorContext<TOptions>,
519
+ node: OperationNode,
520
+ options: TOptions['resolvedOptions'],
521
+ ) => PossiblePromise<unknown | Array<FileNode> | void>
522
+
523
+ /**
524
+ * Handler for all collected operation nodes. Used by the `operations` hook on a plugin.
525
+ */
526
+ export type OperationsHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (
527
+ this: GeneratorContext<TOptions>,
528
+ nodes: Array<OperationNode>,
529
+ options: TOptions['resolvedOptions'],
530
+ ) => PossiblePromise<unknown | Array<FileNode> | void>
531
+ /**
532
+ * @deprecated will be replaced with HookStylePlugin
533
+ */
322
534
  export type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
323
535
  /**
324
- * Unique name used for the plugin
325
- * @example @kubb/typescript
536
+ * Unique name used for the plugin.
537
+ *
538
+ * @example Plugin name
539
+ * `'@kubb/typescript'`
326
540
  */
327
541
  name: TOptions['name']
328
542
  /**
329
- * 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.
330
- * Can be used to validate dependent plugins.
543
+ * Specifies the plugins that the current plugin depends on. The current plugin is executed after all listed plugins.
544
+ * An error is returned if any required dependency plugin is missing.
331
545
  */
332
- pre?: Array<string>
546
+ dependencies?: Array<string>
333
547
  /**
334
- * 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.
548
+ * Options set for a specific plugin(see kubb.config.js), passthrough of options.
335
549
  */
336
- post?: Array<string>
550
+ options: TOptions['resolvedOptions'] & {
551
+ output: Output
552
+ include?: Array<Include>
553
+ exclude: Array<Exclude>
554
+ override: Array<Override<TOptions['resolvedOptions']>>
555
+ }
337
556
  /**
338
- * Options set for a specific plugin(see kubb.config.js), passthrough of options.
557
+ * The resolver for this plugin.
558
+ * Set via `setResolver()` in `kubb:plugin:setup` or passed as a user option.
339
559
  */
340
- options: TOptions['resolvedOptions']
560
+ resolver: TOptions['resolver']
561
+ /**
562
+ * The composed transformer for this plugin.
563
+ * Set via `setTransformer()` in `kubb:plugin:setup` or passed as a user option.
564
+ */
565
+ transformer?: Visitor
341
566
 
342
- install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>
343
567
  /**
344
- * Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
568
+ * When `apply` is defined, the plugin is only activated when `apply(config)` returns `true`.
569
+ * Inspired by Vite's `apply` option.
345
570
  */
346
- inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context']
347
- }
571
+ apply?: (config: Config) => boolean
572
+ /**
573
+ * Optional semver version string for this plugin, e.g. `"1.2.3"`.
574
+ * Used in diagnostic messages and version-conflict detection.
575
+ */
576
+ version?: string
577
+ /**
578
+ * Plugin-level renderer factory. All generators that do not declare their own `renderer`
579
+ * inherit this value. A generator can explicitly opt out by setting `renderer: null`.
580
+ */
581
+ renderer?: RendererFactory
582
+ /**
583
+ * Generators declared directly on the plugin. Each generator's `renderer` takes precedence
584
+ * over `plugin.renderer`; set `renderer: null` on a generator to opt out of rendering even
585
+ * when the plugin declares a renderer.
586
+ */
587
+ generators?: Array<Generator>
348
588
 
589
+ buildStart: (this: PluginContext<TOptions>) => PossiblePromise<void>
590
+ /**
591
+ * Called once per plugin after all files have been written to disk.
592
+ * Use this for post-processing, copying assets, or generating summary reports.
593
+ */
594
+ buildEnd: (this: PluginContext<TOptions>) => PossiblePromise<void>
595
+ /**
596
+ * Called for each schema node during the AST walk.
597
+ * Return a React element, an array of `FileNode`, or `void` for manual handling.
598
+ * Nodes matching `exclude`/`include` filters are skipped automatically.
599
+ *
600
+ * For multiple generators, use `composeGenerators` inside the plugin factory.
601
+ */
602
+ schema?: SchemaHook<TOptions>
603
+ /**
604
+ * Called for each operation node during the AST walk.
605
+ * Return a React element, an array of `FileNode`, or `void` for manual handling.
606
+ *
607
+ * For multiple generators, use `composeGenerators` inside the plugin factory.
608
+ */
609
+ operation?: OperationHook<TOptions>
610
+ /**
611
+ * Called once after all operations have been walked, with the full collected set.
612
+ *
613
+ * For multiple generators, use `composeGenerators` inside the plugin factory.
614
+ */
615
+ operations?: OperationsHook<TOptions>
616
+ /**
617
+ * Expose shared helpers or data to all other plugins via `PluginContext`.
618
+ * The returned object is merged into the context received by every plugin.
619
+ */
620
+ inject: (this: PluginContext<TOptions>) => TOptions['context']
621
+ }
622
+ /**
623
+ * @deprecated
624
+ */
349
625
  export type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>
350
-
626
+ /**
627
+ * @deprecated
628
+ */
351
629
  export type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
352
630
  /**
353
- * Start of the lifecycle of a plugin.
354
- * @type hookParallel
631
+ * Called once per plugin at the start of its processing phase, before schema/operation/operations hooks run.
632
+ * Use this to set up shared state, fetch remote data, or perform any async initialization.
633
+ */
634
+ buildStart?: (this: PluginContext<TOptions>) => PossiblePromise<void>
635
+ /**
636
+ * Called once per plugin after all files have been written to disk.
637
+ * Use this for post-processing, copying assets, or generating summary reports.
638
+ */
639
+ buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>
640
+ /**
641
+ * Called for each schema node during the AST walk.
642
+ * Return a React element (`<File>...</File>`), an array of `FileNode` objects,
643
+ * or `void` to handle file writing manually via `this.upsertFile`.
644
+ * Nodes matching `exclude` / `include` filters are skipped automatically.
645
+ *
646
+ * For multiple generators, use `composeGenerators` inside the plugin factory.
647
+ */
648
+ schema?: SchemaHook<TOptions>
649
+ /**
650
+ * Called for each operation node during the AST walk.
651
+ * Return a React element (`<File>...</File>`), an array of `FileNode` objects,
652
+ * or `void` to handle file writing manually via `this.upsertFile`.
653
+ *
654
+ * For multiple generators, use `composeGenerators` inside the plugin factory.
655
+ */
656
+ operation?: OperationHook<TOptions>
657
+ /**
658
+ * Called once after all operation nodes have been walked, with the full collection.
659
+ * Useful for generating index/barrel files per group or aggregate operation handlers.
660
+ *
661
+ * For multiple generators, use `composeGenerators` inside the plugin factory.
355
662
  */
356
- install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>
663
+ operations?: OperationsHook<TOptions>
357
664
  /**
358
- * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
359
- * Options can als be included.
360
- * @type hookFirst
361
- * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
665
+ * Resolves a path from a baseName and directory.
666
+ * Options can also be included.
667
+ *
668
+ * @example
669
+ * `('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'`
670
+ *
671
+ * @deprecated Use resolvers instead.
362
672
  */
363
- resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path
673
+ resolvePath?: (this: PluginContext<TOptions>, baseName: FileNode['baseName'], mode?: 'single' | 'split', options?: TOptions['resolvePathOptions']) => string
364
674
  /**
365
- * Resolve to a name based on a string.
675
+ * Resolves a display name from a raw string.
366
676
  * Useful when converting to PascalCase or camelCase.
367
- * @type hookFirst
368
- * @example ('pet') => 'Pet'
677
+ *
678
+ * @example
679
+ * `('pet') => 'Pet'`
680
+ *
681
+ * @deprecated Use resolvers instead.
369
682
  */
370
683
  resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
371
684
  }
372
685
 
686
+ /**
687
+ * @deprecated
688
+ */
373
689
  export type PluginLifecycleHooks = keyof PluginLifecycle
374
690
 
375
691
  export type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>
376
692
 
377
693
  export type ResolvePathParams<TOptions = object> = {
378
694
  pluginName?: string
379
- baseName: KubbFile.BaseName
380
- mode?: KubbFile.Mode
695
+ baseName: FileNode['baseName']
696
+ mode?: 'single' | 'split'
381
697
  /**
382
- * Options to be passed to 'resolvePath' 3th parameter
698
+ * Options passed as the third argument to `resolvePath`.
383
699
  */
384
700
  options?: TOptions
385
701
  }
@@ -389,64 +705,127 @@ export type ResolveNameParams = {
389
705
  pluginName?: string
390
706
  /**
391
707
  * Specifies the type of entity being named.
392
- * - 'file' customizes the name of the created file (uses camelCase).
393
- * - 'function' customizes the exported function names (uses camelCase).
394
- * - 'type' customizes TypeScript types (uses PascalCase).
395
- * - 'const' customizes variable names (uses camelCase).
396
- * @default undefined
708
+ * - `'file'` customizes the name of the created file (camelCase).
709
+ * - `'function'` customizes the exported function names (camelCase).
710
+ * - `'type'` customizes TypeScript type names (PascalCase).
711
+ * - `'const'` customizes variable names (camelCase).
397
712
  */
398
713
  type?: 'file' | 'function' | 'type' | 'const'
399
714
  }
400
-
715
+ /**
716
+ * @deprecated
717
+ */
401
718
  export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
402
- fabric: Fabric
403
719
  config: Config
404
- pluginManager: PluginManager
405
720
  /**
406
- * Only add when the file does not exist yet
721
+ * Absolute path to the output directory for the current plugin.
722
+ * Shorthand for `path.resolve(config.root, config.output.path)`.
723
+ */
724
+ root: string
725
+ /**
726
+ * Returns the output mode for the given output config.
727
+ * Returns `'single'` when `output.path` has a file extension, `'split'` otherwise.
728
+ * Shorthand for `PluginDriver.getMode(path.resolve(this.root, output.path))`.
729
+ */
730
+ getMode: (output: { path: string }) => 'single' | 'split'
731
+ driver: PluginDriver
732
+ /**
733
+ * Get a plugin by name. Returns the plugin typed via `Kubb.PluginRegistry` when
734
+ * the name is a registered key, otherwise returns the generic `Plugin`.
735
+ */
736
+ getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined
737
+ getPlugin(name: string): Plugin | undefined
738
+ /**
739
+ * Like `getPlugin` but throws a descriptive error when the plugin is not found.
740
+ * Useful for enforcing dependencies inside `buildStart()`.
741
+ */
742
+ requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>
743
+ requirePlugin(name: string): Plugin
744
+ /**
745
+ * Add files only when they do not exist yet.
407
746
  */
408
- addFile: (...file: Array<KubbFile.File>) => Promise<void>
747
+ addFile: (...file: Array<FileNode>) => Promise<void>
409
748
  /**
410
- * merging multiple sources into the same output file
749
+ * Merge multiple sources into the same output file.
411
750
  */
412
- upsertFile: (...file: Array<KubbFile.File>) => Promise<void>
413
- events: AsyncEventEmitter<KubbEvents>
414
- mode: KubbFile.Mode
751
+ upsertFile: (...file: Array<FileNode>) => Promise<void>
752
+ hooks: AsyncEventEmitter<KubbHooks>
415
753
  /**
416
- * Current plugin
754
+ * The current plugin.
417
755
  */
418
756
  plugin: Plugin<TOptions>
757
+ /**
758
+ * Resolver for the current plugin. Shorthand for `plugin.resolver`.
759
+ */
760
+ resolver: TOptions['resolver']
761
+ /**
762
+ * Composed transformer for the current plugin. Shorthand for `plugin.transformer`.
763
+ * Apply with `transform(node, context.transformer)` to pre-process AST nodes before printing.
764
+ */
765
+ transformer: Visitor | undefined
419
766
 
420
767
  /**
421
- * Opens the Kubb Studio URL for the current `rootNode` in the default browser.
768
+ * Emit a warning via the build event system.
769
+ * Shorthand for `this.hooks.emit('kubb:warn', message)`.
770
+ */
771
+ warn: (message: string) => void
772
+ /**
773
+ * Emit an error via the build event system.
774
+ * Shorthand for `this.hooks.emit('kubb:error', error)`.
775
+ */
776
+ error: (error: string | Error) => void
777
+ /**
778
+ * Emit an info message via the build event system.
779
+ * Shorthand for `this.hooks.emit('kubb:info', message)`.
780
+ */
781
+ info: (message: string) => void
782
+ /**
783
+ * Opens the Kubb Studio URL for the current `inputNode` in the default browser.
422
784
  * Falls back to printing the URL if the browser cannot be launched.
423
- * No-ops silently when no adapter has set a `rootNode`.
785
+ * No-ops silently when no adapter has set an `inputNode`.
424
786
  */
425
787
  openInStudio: (options?: DevtoolsOptions) => Promise<void>
426
788
  } & (
427
789
  | {
428
790
  /**
429
- * Returns the universal `@kubb/ast` `RootNode` produced by the configured adapter.
791
+ * Returns the universal `@kubb/ast` `InputNode` produced by the configured adapter.
430
792
  * Returns `undefined` when no adapter was set (legacy OAS-only usage).
431
793
  */
432
- rootNode: RootNode
794
+ inputNode: InputNode
433
795
  /**
434
- * Return the adapter from `@kubb/ast`
796
+ * The adapter from `@kubb/ast`.
435
797
  */
436
798
  adapter: Adapter
437
799
  }
438
800
  | {
439
- rootNode?: never
801
+ inputNode?: never
440
802
  adapter?: never
441
803
  }
442
804
  ) &
443
805
  Kubb.PluginContext
806
+
444
807
  /**
445
- * Specify the export location for the files and define the behavior of the output
808
+ * Context object passed as the second argument to generator `schema`, `operation`, and
809
+ * `operations` methods.
810
+ *
811
+ * Generators are only invoked from `runPluginAstHooks`, which already guards against a
812
+ * missing adapter. This type reflects that guarantee — `ctx.adapter` and `ctx.inputNode`
813
+ * are always defined, so no runtime checks or casts are needed inside generator bodies.
814
+ *
815
+ * `ctx.options` carries the per-node resolved options for `schema`/`operation` calls
816
+ * (after exclude/include/override filtering) and the plugin-level options for `operations`.
446
817
  */
447
- export type Output<TOptions> = {
818
+ export type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Omit<PluginContext<TOptions>, 'adapter' | 'inputNode'> & {
819
+ adapter: Adapter
820
+ inputNode: InputNode
821
+ options: TOptions['resolvedOptions']
822
+ }
823
+ /**
824
+ * Configure generated file output location and behavior.
825
+ */
826
+ export type Output<_TOptions = unknown> = {
448
827
  /**
449
- * Path to the output folder or file that will contain the generated code
828
+ * Path to the output folder or file that will contain generated code.
450
829
  */
451
830
  path: string
452
831
  /**
@@ -455,13 +834,15 @@ export type Output<TOptions> = {
455
834
  */
456
835
  barrelType?: BarrelType | false
457
836
  /**
458
- * Add a banner text in the beginning of every file
837
+ * Text or function appended at the start of every generated file.
838
+ * When a function, receives the current `InputNode` and must return a string.
459
839
  */
460
- banner?: string | ((options: TOptions) => string)
840
+ banner?: string | ((node?: InputNode) => string)
461
841
  /**
462
- * Add a footer text in the beginning of every file
842
+ * Text or function appended at the end of every generated file.
843
+ * When a function, receives the current `InputNode` and must return a string.
463
844
  */
464
- footer?: string | ((options: TOptions) => string)
845
+ footer?: string | ((node?: InputNode) => string)
465
846
  /**
466
847
  * Whether to override existing external files if they already exist.
467
848
  * @default false
@@ -469,22 +850,31 @@ export type Output<TOptions> = {
469
850
  override?: boolean
470
851
  }
471
852
 
472
- type GroupContext = {
473
- group: string
853
+ export type UserGroup = {
854
+ /**
855
+ * Determines how files are grouped into subdirectories.
856
+ * - `'tag'` groups files by OpenAPI tags.
857
+ * - `'path'` groups files by OpenAPI paths.
858
+ */
859
+ type: 'tag' | 'path'
860
+ /**
861
+ * Returns the subdirectory name for a given group value.
862
+ * Defaults to `${camelCase(group)}Controller` for tags and the first path segment for paths.
863
+ */
864
+ name?: (context: { group: string }) => string
474
865
  }
475
866
 
476
867
  export type Group = {
477
868
  /**
478
- * Defines the type where to group the files.
479
- * - 'tag' groups files by OpenAPI tags.
480
- * - 'path' groups files by OpenAPI paths.
481
- * @default undefined
869
+ * Determines how files are grouped into subdirectories.
870
+ * - `'tag'` groups files by OpenAPI tags.
871
+ * - `'path'` groups files by OpenAPI paths.
482
872
  */
483
873
  type: 'tag' | 'path'
484
874
  /**
485
- * Return the name of a group based on the group name, this used for the file and name generation
875
+ * Returns the subdirectory name for a given group value.
486
876
  */
487
- name?: (context: GroupContext) => string
877
+ name: (context: { group: string }) => string
488
878
  }
489
879
 
490
880
  export type LoggerOptions = {
@@ -495,19 +885,298 @@ export type LoggerOptions = {
495
885
  }
496
886
 
497
887
  /**
498
- * Shared context passed to all plugins, parsers, and Fabric internals.
888
+ * Shared context passed to all plugins, parsers, and other internals.
499
889
  */
500
- export interface LoggerContext extends AsyncEventEmitter<KubbEvents> {}
501
-
502
- type Install<TOptions = unknown> = (context: LoggerContext, options?: TOptions) => void | Promise<void>
890
+ export type LoggerContext = AsyncEventEmitter<KubbHooks>
503
891
 
504
892
  export type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
505
893
  name: string
506
- install: Install<TOptions>
894
+ install: (context: LoggerContext, options?: TOptions) => void | Promise<void>
895
+ }
896
+
897
+ export type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Logger<TOptions>
898
+
899
+ /**
900
+ * Compatibility preset for code generation tools.
901
+ * - `'default'` – no compatibility adjustments (default behavior).
902
+ * - `'kubbV4'` – align generated names and structures with Kubb v4 output.
903
+ */
904
+ export type CompatibilityPreset = 'default' | 'kubbV4'
905
+
906
+ export type { Storage } from './createStorage.ts'
907
+ export type { Generator } from './defineGenerator.ts'
908
+ export type { HookStylePlugin, PluginHooks } from './definePlugin.ts'
909
+ export type { Kubb, KubbHooks } from './Kubb.ts'
910
+
911
+ /**
912
+ * Context passed to a hook-style plugin's `kubb:plugin:setup` handler.
913
+ * Provides methods to register generators, configure the resolver, transformer,
914
+ * and renderer, as well as access to the current build configuration.
915
+ */
916
+ export type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
917
+ /**
918
+ * Register a generator on this plugin. Generators are invoked during the AST walk
919
+ * (schema/operation/operations) exactly like generators declared statically on `createPlugin`.
920
+ */
921
+ addGenerator<TElement = unknown>(generator: Generator<TFactory, TElement>): void
922
+ /**
923
+ * Set or partially override the resolver for this plugin.
924
+ * The resolver controls file naming and path resolution for generated files.
925
+ *
926
+ * When `TFactory` is a concrete `PluginFactoryOptions` (e.g. `PluginClient`),
927
+ * the resolver parameter is typed to the plugin's own resolver type (e.g. `ResolverClient`).
928
+ */
929
+ setResolver(resolver: Partial<TFactory['resolver']>): void
930
+ /**
931
+ * Set the AST transformer (visitor) for this plugin.
932
+ * The transformer pre-processes nodes before they reach the generators.
933
+ */
934
+ setTransformer(visitor: Visitor): void
935
+ /**
936
+ * Set the renderer factory for this plugin.
937
+ * Used to process JSX elements returned by generators.
938
+ */
939
+ setRenderer(renderer: RendererFactory): void
940
+ /**
941
+ * Set the resolved options for the build loop. These options are merged into the
942
+ * normalized plugin's `options` object (which includes `output`, `exclude`, `override`).
943
+ *
944
+ * Call this in `kubb:plugin:setup` to provide the resolved options that generators
945
+ * and the build loop need (e.g., `enumType`, `optionalType`, `group`).
946
+ */
947
+ setOptions(options: TFactory['resolvedOptions']): void
948
+ /**
949
+ * Inject a raw file into the build output, bypassing the normal generation pipeline.
950
+ */
951
+ injectFile(file: Pick<FileNode, 'baseName' | 'path'> & { sources?: FileNode['sources'] }): void
952
+ /**
953
+ * Merge a partial config update into the current build configuration.
954
+ */
955
+ updateConfig(config: Partial<Config>): void
956
+ /**
957
+ * The resolved build configuration at the time of setup.
958
+ */
959
+ config: Config
960
+ /**
961
+ * The plugin's own options as passed by the user.
962
+ */
963
+ options: TFactory['options']
964
+ }
965
+
966
+ /**
967
+ * Context passed to a hook-style plugin's `kubb:build:start` handler.
968
+ * Fires immediately before the plugin execution loop begins.
969
+ */
970
+ export type KubbBuildStartContext = {
971
+ config: Config
972
+ adapter: Adapter
973
+ inputNode: InputNode
974
+ getPlugin(name: string): Plugin | undefined
975
+ }
976
+
977
+ /**
978
+ * Context passed to a hook-style plugin's `kubb:build:end` handler.
979
+ * Fires after all files have been written to disk.
980
+ */
981
+ export type KubbBuildEndContext = {
982
+ files: Array<FileNode>
983
+ config: Config
984
+ outputDir: string
985
+ }
986
+
987
+ type ByTag = {
988
+ type: 'tag'
989
+ pattern: string | RegExp
507
990
  }
508
991
 
509
- export type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Omit<Logger<TOptions>, 'logLevel'>
992
+ type ByOperationId = {
993
+ type: 'operationId'
994
+ pattern: string | RegExp
995
+ }
996
+
997
+ type ByPath = {
998
+ type: 'path'
999
+ pattern: string | RegExp
1000
+ }
1001
+
1002
+ type ByMethod = {
1003
+ type: 'method'
1004
+ pattern: HttpMethod | RegExp
1005
+ }
1006
+ // TODO implement as alternative for ByMethod
1007
+ // type ByMethods = {
1008
+ // type: 'methods'
1009
+ // pattern: Array<HttpMethod>
1010
+ // }
1011
+
1012
+ type BySchemaName = {
1013
+ type: 'schemaName'
1014
+ pattern: string | RegExp
1015
+ }
1016
+
1017
+ type ByContentType = {
1018
+ type: 'contentType'
1019
+ pattern: string | RegExp
1020
+ }
1021
+
1022
+ /**
1023
+ * A pattern filter that prevents matching nodes from being generated.
1024
+ * Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
1025
+ */
1026
+ export type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
1027
+
1028
+ /**
1029
+ * A pattern filter that restricts generation to only matching nodes.
1030
+ * Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
1031
+ */
1032
+ export type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
1033
+
1034
+ /**
1035
+ * A pattern filter paired with partial option overrides applied when the pattern matches.
1036
+ * Match by `tag`, `operationId`, `path`, `method`, `schemaName`, or `contentType`.
1037
+ */
1038
+ export type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
1039
+ //TODO should be options: Omit<Partial<TOptions>, 'override'>
1040
+ options: Partial<TOptions>
1041
+ }
1042
+
1043
+ export type ResolvePathOptions = {
1044
+ pluginName?: string
1045
+ group?: {
1046
+ tag?: string
1047
+ path?: string
1048
+ }
1049
+ type?: ResolveNameParams['type']
1050
+ }
1051
+
1052
+ /**
1053
+ * File-specific parameters for `Resolver.resolvePath`.
1054
+ *
1055
+ * Pass alongside a `ResolverContext` to identify which file to resolve.
1056
+ * Provide `tag` for tag-based grouping or `path` for path-based grouping.
1057
+ *
1058
+ * @example
1059
+ * ```ts
1060
+ * resolver.resolvePath(
1061
+ * { baseName: 'petTypes.ts', tag: 'pets' },
1062
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
1063
+ * )
1064
+ * // → '/src/types/petsController/petTypes.ts'
1065
+ * ```
1066
+ */
1067
+ export type ResolverPathParams = {
1068
+ baseName: FileNode['baseName']
1069
+ pathMode?: 'single' | 'split'
1070
+ /**
1071
+ * Tag value used when `group.type === 'tag'`.
1072
+ */
1073
+ tag?: string
1074
+ /**
1075
+ * Path value used when `group.type === 'path'`.
1076
+ */
1077
+ path?: string
1078
+ }
1079
+
1080
+ /**
1081
+ * Shared context passed as the second argument to `Resolver.resolvePath` and `Resolver.resolveFile`.
1082
+ *
1083
+ * Describes where on disk output is rooted, which output config is active, and the optional
1084
+ * grouping strategy that controls subdirectory layout.
1085
+ *
1086
+ * @example
1087
+ * ```ts
1088
+ * const context: ResolverContext = {
1089
+ * root: config.root,
1090
+ * output,
1091
+ * group,
1092
+ * }
1093
+ * ```
1094
+ */
1095
+ export type ResolverContext = {
1096
+ root: string
1097
+ output: Output
1098
+ group?: Group
1099
+ /**
1100
+ * Plugin name used to populate `meta.pluginName` on the resolved file.
1101
+ */
1102
+ pluginName?: string
1103
+ }
1104
+
1105
+ /**
1106
+ * File-specific parameters for `Resolver.resolveFile`.
1107
+ *
1108
+ * Pass alongside a `ResolverContext` to fully describe the file to resolve.
1109
+ * `tag` and `path` are used only when a matching `group` is present in the context.
1110
+ *
1111
+ * @example
1112
+ * ```ts
1113
+ * resolver.resolveFile(
1114
+ * { name: 'listPets', extname: '.ts', tag: 'pets' },
1115
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
1116
+ * )
1117
+ * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
1118
+ * ```
1119
+ */
1120
+ export type ResolverFileParams = {
1121
+ name: string
1122
+ extname: FileNode['extname']
1123
+ /**
1124
+ * Tag value used when `group.type === 'tag'`.
1125
+ */
1126
+ tag?: string
1127
+ /**
1128
+ * Path value used when `group.type === 'path'`.
1129
+ */
1130
+ path?: string
1131
+ }
1132
+
1133
+ /**
1134
+ * Context passed to `Resolver.resolveBanner` and `Resolver.resolveFooter`.
1135
+ *
1136
+ * `output` is optional — not every plugin configures a banner/footer.
1137
+ * `config` carries the global Kubb config, used to derive the default Kubb banner.
1138
+ *
1139
+ * @example
1140
+ * ```ts
1141
+ * resolver.resolveBanner(inputNode, { output: { banner: '// generated' }, config })
1142
+ * // → '// generated'
1143
+ * ```
1144
+ */
1145
+ export type ResolveBannerContext = {
1146
+ output?: Pick<Output, 'banner' | 'footer'>
1147
+ config: Config
1148
+ }
1149
+
1150
+ /**
1151
+ * CLI options derived from command-line flags.
1152
+ */
1153
+ export type CLIOptions = {
1154
+ /**
1155
+ * Path to `kubb.config.js`.
1156
+ */
1157
+ config?: string
1158
+ /**
1159
+ * Enable watch mode for input files.
1160
+ */
1161
+ watch?: boolean
1162
+ /**
1163
+ * Logging verbosity for CLI usage.
1164
+ * @default 'silent'
1165
+ */
1166
+ logLevel?: 'silent' | 'info' | 'debug'
1167
+ }
1168
+
1169
+ /**
1170
+ * All accepted forms of a Kubb configuration.
1171
+ *
1172
+ * Config is always `@kubb/core` {@link Config}.
1173
+ * - `PossibleConfig` accepts `Config`/`Config[]`/promise or a no-arg config factory.
1174
+ * - `PossibleConfig<TCliOptions>` accepts the same config forms or a config factory receiving `TCliOptions`.
1175
+ */
1176
+ export type PossibleConfig<TCliOptions = undefined> =
1177
+ | PossiblePromise<Config | Config[]>
1178
+ | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Config[]>)
510
1179
 
511
- export type { CoreGeneratorV2, Generator, ReactGeneratorV2 } from './defineGenerator.ts'
512
- export type { DefineStorage } from './defineStorage.ts'
513
- export type { KubbEvents } from './Kubb.ts'
1180
+ export type { BuildOutput } from './createKubb.ts'
1181
+ export type { Parser } from './defineParser.ts'
1182
+ export type { FileMetaBase } from './utils/getBarrelFiles.ts'