@kubb/core 5.0.0-alpha.7 → 5.0.0-alpha.70

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 (69) hide show
  1. package/README.md +3 -2
  2. package/dist/PluginDriver-BXibeQk-.cjs +1036 -0
  3. package/dist/PluginDriver-BXibeQk-.cjs.map +1 -0
  4. package/dist/PluginDriver-DV3p2Hky.js +945 -0
  5. package/dist/PluginDriver-DV3p2Hky.js.map +1 -0
  6. package/dist/index.cjs +730 -1773
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts +289 -240
  9. package/dist/index.js +717 -1741
  10. package/dist/index.js.map +1 -1
  11. package/dist/mocks.cjs +139 -0
  12. package/dist/mocks.cjs.map +1 -0
  13. package/dist/mocks.d.ts +74 -0
  14. package/dist/mocks.js +134 -0
  15. package/dist/mocks.js.map +1 -0
  16. package/dist/types-DWtkW2RX.d.ts +1915 -0
  17. package/package.json +51 -57
  18. package/src/FileManager.ts +115 -0
  19. package/src/FileProcessor.ts +86 -0
  20. package/src/Kubb.ts +205 -130
  21. package/src/PluginDriver.ts +326 -565
  22. package/src/constants.ts +20 -47
  23. package/src/createAdapter.ts +25 -0
  24. package/src/createKubb.ts +546 -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/defineMiddleware.ts +64 -0
  30. package/src/defineParser.ts +45 -0
  31. package/src/definePlugin.ts +78 -7
  32. package/src/defineResolver.ts +521 -0
  33. package/src/devtools.ts +14 -14
  34. package/src/index.ts +13 -16
  35. package/src/mocks.ts +172 -0
  36. package/src/renderNode.ts +35 -0
  37. package/src/storages/fsStorage.ts +43 -13
  38. package/src/storages/memoryStorage.ts +6 -4
  39. package/src/types.ts +752 -226
  40. package/src/utils/diagnostics.ts +4 -1
  41. package/src/utils/isInputPath.ts +10 -0
  42. package/src/utils/packageJSON.ts +99 -0
  43. package/dist/PluginDriver-Dma9KhLK.d.ts +0 -1056
  44. package/dist/chunk-ByKO4r7w.cjs +0 -38
  45. package/dist/hooks.cjs +0 -102
  46. package/dist/hooks.cjs.map +0 -1
  47. package/dist/hooks.d.ts +0 -75
  48. package/dist/hooks.js +0 -97
  49. package/dist/hooks.js.map +0 -1
  50. package/src/PackageManager.ts +0 -180
  51. package/src/build.ts +0 -419
  52. package/src/config.ts +0 -56
  53. package/src/defineAdapter.ts +0 -22
  54. package/src/defineStorage.ts +0 -56
  55. package/src/errors.ts +0 -1
  56. package/src/hooks/index.ts +0 -4
  57. package/src/hooks/useKubb.ts +0 -138
  58. package/src/hooks/useMode.ts +0 -11
  59. package/src/hooks/usePlugin.ts +0 -11
  60. package/src/hooks/usePluginDriver.ts +0 -11
  61. package/src/utils/FunctionParams.ts +0 -155
  62. package/src/utils/TreeNode.ts +0 -215
  63. package/src/utils/executeStrategies.ts +0 -81
  64. package/src/utils/formatters.ts +0 -56
  65. package/src/utils/getBarrelFiles.ts +0 -141
  66. package/src/utils/getConfigs.ts +0 -30
  67. package/src/utils/getPlugins.ts +0 -23
  68. package/src/utils/linters.ts +0 -25
  69. package/src/utils/resolveOptions.ts +0 -93
package/src/types.ts CHANGED
@@ -1,40 +1,26 @@
1
1
  import type { AsyncEventEmitter, PossiblePromise } from '@internals/utils'
2
- import type { RootNode, SchemaNode } from '@kubb/ast/types'
3
- import type { Fabric as FabricType, KubbFile } from '@kubb/fabric-core/types'
2
+ import type { FileNode, HttpMethod, ImportNode, InputNode, Node, SchemaNode, UserFileNode, Visitor } from '@kubb/ast'
4
3
  import type { DEFAULT_STUDIO_URL, logLevel } from './constants.ts'
5
- import type { DefineStorage } from './defineStorage.ts'
6
- import type { KubbEvents } from './Kubb.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 { Middleware } from './defineMiddleware.ts'
8
+ import type { Parser } from './defineParser.ts'
9
+ import type { Plugin } from './definePlugin.ts'
10
+ import type { KubbHooks } from './Kubb.ts'
7
11
  import type { PluginDriver } from './PluginDriver.ts'
8
12
 
9
- export type { Printer, PrinterFactoryOptions } from '@kubb/ast/types'
10
-
11
- declare global {
12
- namespace Kubb {
13
- interface PluginContext {}
14
- }
15
- }
13
+ export type { Renderer, RendererFactory } from './createRenderer.ts'
16
14
 
17
15
  /**
18
- * Config used in `kubb.config.ts`
16
+ * Safely extracts the type of key `K` from `T`, returning `{}` when `K` is not a key of `T`.
17
+ * Used to implement optional interface augmentation for `Kubb.ConfigOptionsRegistry` and
18
+ * `Kubb.PluginOptionsRegistry` so that middleware and plugin packages can extend core types
19
+ * without requiring modifications to core.
19
20
  *
20
- * @example
21
- * import { defineConfig } from '@kubb/core'
22
- * export default defineConfig({
23
- * ...
24
- * })
21
+ * @internal
25
22
  */
26
- export type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins'> & {
27
- /**
28
- * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
29
- * @default process.cwd()
30
- */
31
- root?: string
32
- /**
33
- * 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.
34
- */
35
- // inject needs to be omitted because else we have a clash with the PluginDriver instance
36
- plugins?: Array<Omit<UnknownUserPlugin, 'inject'>>
37
- }
23
+ type ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {}
38
24
 
39
25
  export type InputPath = {
40
26
  /**
@@ -50,7 +36,7 @@ export type InputData = {
50
36
  data: string | unknown
51
37
  }
52
38
 
53
- type Input = InputPath | InputData | Array<InputPath>
39
+ type Input = InputPath | InputData
54
40
 
55
41
  /**
56
42
  * The raw source passed to an adapter's `parse` function.
@@ -65,18 +51,25 @@ export type AdapterSource = { type: 'path'; path: string } | { type: 'data'; dat
65
51
  * - `TName` — unique string identifier (e.g. `'oas'`, `'asyncapi'`)
66
52
  * - `TOptions` — raw user-facing options passed to the adapter factory
67
53
  * - `TResolvedOptions` — defaults applied; what the adapter stores as `options`
54
+ * - `TDocument` — type of the raw source document exposed by the adapter after `parse()`
68
55
  */
69
- export type AdapterFactoryOptions<TName extends string = string, TOptions extends object = object, TResolvedOptions extends object = TOptions> = {
56
+ export type AdapterFactoryOptions<
57
+ TName extends string = string,
58
+ TOptions extends object = object,
59
+ TResolvedOptions extends object = TOptions,
60
+ TDocument = unknown,
61
+ > = {
70
62
  name: TName
71
63
  options: TOptions
72
64
  resolvedOptions: TResolvedOptions
65
+ document: TDocument
73
66
  }
74
67
 
75
68
  /**
76
- * An adapter converts a source file or data into a `@kubb/ast` `RootNode`.
69
+ * An adapter converts a source file or data into a `@kubb/ast` `InputNode`.
77
70
  *
78
71
  * Adapters are the single entry-point for different schema formats
79
- * (OpenAPI, AsyncAPI, Drizzle, …) and produce the universal `RootNode`
72
+ * (OpenAPI, AsyncAPI, Drizzle, …) and produce the universal `InputNode`
80
73
  * that all Kubb plugins consume.
81
74
  *
82
75
  * @example
@@ -91,24 +84,34 @@ export type AdapterFactoryOptions<TName extends string = string, TOptions extend
91
84
  * ```
92
85
  */
93
86
  export type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
94
- /** Human-readable identifier, e.g. `'oas'`, `'drizzle'`, `'asyncapi'`. */
87
+ /**
88
+ * Human-readable identifier, e.g. `'oas'`, `'drizzle'`, `'asyncapi'`.
89
+ */
95
90
  name: TOptions['name']
96
- /** Resolved options (after defaults have been applied). */
91
+ /**
92
+ * Resolved options (after defaults have been applied).
93
+ */
97
94
  options: TOptions['resolvedOptions']
98
- /** Convert the raw source into a universal `RootNode`. */
99
- parse: (source: AdapterSource) => PossiblePromise<RootNode>
100
95
  /**
101
- * Extracts `KubbFile.Import` entries needed by a `SchemaNode` tree.
96
+ * The raw source document produced after the first `parse()` call.
97
+ * `undefined` before parsing; typed by the adapter's `TDocument` generic.
98
+ */
99
+ document: TOptions['document'] | null
100
+ inputNode: InputNode | null
101
+ /**
102
+ * Convert the raw source into a universal `InputNode`.
103
+ */
104
+ parse: (source: AdapterSource) => PossiblePromise<InputNode>
105
+ /**
106
+ * Extracts `ImportNode` entries needed by a `SchemaNode` tree.
102
107
  * Populated after the first `parse()` call. Returns an empty array before that.
103
108
  *
104
109
  * The `resolve` callback receives the collision-corrected schema name and must
105
110
  * return the `{ name, path }` pair for the import, or `undefined` to skip it.
106
111
  */
107
- getImports: (node: SchemaNode, resolve: (schemaName: string) => { name: string; path: string }) => Array<KubbFile.Import>
112
+ getImports: (node: SchemaNode, resolve: (schemaName: string) => { name: string; path: string }) => Array<ImportNode>
108
113
  }
109
114
 
110
- export type BarrelType = 'all' | 'named' | 'propagate'
111
-
112
115
  export type DevtoolsOptions = {
113
116
  /**
114
117
  * Open the AST inspector view (`/ast`) in Kubb Studio.
@@ -132,31 +135,49 @@ export type Config<TInput = Input> = {
132
135
  */
133
136
  root: string
134
137
  /**
135
- * Adapter that converts the input file into a `@kubb/ast` `RootNode` — the universal
138
+ * An array of parsers used to convert generated files to strings.
139
+ * Each parser handles specific file extensions (e.g. `.ts`, `.tsx`).
140
+ *
141
+ * A catch-all fallback parser is always appended last for any unhandled extension.
142
+ *
143
+ * When omitted, `parserTs` from `@kubb/parser-ts` is used automatically as the
144
+ * default (requires `@kubb/parser-ts` to be installed as an optional dependency).
145
+ * @default [parserTs] — from `@kubb/parser-ts`
146
+ * @example
147
+ * ```ts
148
+ * import { parserTs, tsxParser } from '@kubb/parser-ts'
149
+ * export default defineConfig({
150
+ * parsers: [parserTs, tsxParser],
151
+ * })
152
+ * ```
153
+ */
154
+ parsers: Array<Parser>
155
+ /**
156
+ * Adapter that converts the input file into a `@kubb/ast` `InputNode` — the universal
136
157
  * intermediate representation consumed by all Kubb plugins.
137
158
  *
138
- * - Omit (or pass `undefined`) to use the built-in OpenAPI/Swagger adapter.
139
- * - Use `@kubb/adapter-oas` for explicit OpenAPI configuration (validate, contentType, …).
159
+ * - Use `@kubb/adapter-oas` for OpenAPI / Swagger.
140
160
  * - Use `@kubb/adapter-drizzle` or `@kubb/adapter-asyncapi` for other formats.
141
161
  *
142
162
  * @example
143
163
  * ```ts
144
- * import { drizzleAdapter } from '@kubb/adapter-drizzle'
164
+ * import { adapterOas } from '@kubb/adapter-oas'
145
165
  * export default defineConfig({
146
- * adapter: drizzleAdapter(),
147
- * input: { path: './src/schema.ts' },
166
+ * adapter: adapterOas(),
167
+ * input: { path: './petStore.yaml' },
148
168
  * })
149
169
  * ```
150
170
  */
151
- adapter?: Adapter
171
+ adapter: Adapter
152
172
  /**
153
- * You can use either `input.path` or `input.data`, depending on your specific needs.
173
+ * Source file or data to generate code from.
174
+ * Use `input.path` for a file on disk or `input.data` for an inline string or object.
154
175
  */
155
176
  input: TInput
156
177
  output: {
157
178
  /**
158
- * The path where all generated files receives exported.
159
- * This can be an absolute path or a path relative to the specified root option.
179
+ * Output directory for generated files.
180
+ * Accepts an absolute path or a path relative to `root`.
160
181
  */
161
182
  path: string
162
183
  /**
@@ -169,35 +190,22 @@ export type Config<TInput = Input> = {
169
190
  * @deprecated Use `storage` to control where files are written.
170
191
  */
171
192
  write?: boolean
172
- /**
173
- * Storage backend for generated files.
174
- * Defaults to `fsStorage()` — the built-in filesystem driver.
175
- * Accepts any object implementing the {@link DefineStorage} interface.
176
- * Keys are root-relative paths (e.g. `src/gen/api/getPets.ts`).
177
- * @default fsStorage()
178
- * @example
179
- * ```ts
180
- * import { defineStorage, fsStorage } from '@kubb/core'
181
- * storage: defineStorage(fsStorage())
182
- * ```
183
- */
184
- storage?: DefineStorage
185
193
  /**
186
194
  * Specifies the formatting tool to be used.
187
- * - 'auto' automatically detects and uses biome or prettier (in that order of preference).
195
+ * - 'auto' automatically detects and uses oxfmt, biome, or prettier (in that order of preference).
196
+ * - 'oxfmt' uses Oxfmt for code formatting.
188
197
  * - 'prettier' uses Prettier for code formatting.
189
198
  * - 'biome' uses Biome for code formatting.
190
- * - 'oxfmt' uses Oxfmt for code formatting.
191
199
  * - false disables code formatting.
192
200
  * @default 'prettier'
193
201
  */
194
202
  format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false
195
203
  /**
196
204
  * Specifies the linter that should be used to analyze the code.
197
- * - 'auto' automatically detects and uses biome, oxlint, or eslint (in that order of preference).
205
+ * - 'auto' automatically detects and uses oxlint, biome, or eslint (in that order of preference).
206
+ * - 'oxlint' uses Oxlint for linting.
198
207
  * - 'eslint' uses ESLint for linting.
199
208
  * - 'biome' uses Biome for linting.
200
- * - 'oxlint' uses Oxlint for linting.
201
209
  * - false disables linting.
202
210
  * @default 'auto'
203
211
  */
@@ -206,12 +214,7 @@ export type Config<TInput = Input> = {
206
214
  * Overrides the extension for generated imports and exports. By default, each plugin adds an extension.
207
215
  * @default { '.ts': '.ts'}
208
216
  */
209
- extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>
210
- /**
211
- * 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`).
212
- * @default 'named'
213
- */
214
- barrelType?: Exclude<BarrelType, 'propagate'> | false
217
+ extension?: Record<FileNode['extname'], FileNode['extname'] | ''>
215
218
  /**
216
219
  * Adds a default banner to the start of every generated file indicating it was generated by Kubb.
217
220
  * - 'simple' adds banner with link to Kubb.
@@ -227,13 +230,59 @@ export type Config<TInput = Input> = {
227
230
  * @default false
228
231
  */
229
232
  override?: boolean
230
- }
233
+ } & ExtractRegistryKey<Kubb.ConfigOptionsRegistry, 'output'>
231
234
  /**
232
- * An array of Kubb plugins that used in the generation.
233
- * Each plugin may include additional configurable options(defined in the plugin itself).
234
- * If a plugin depends on another plugin, an error is returned if the required dependency is missing. See pre for more details.
235
+ * Storage backend for generated files.
236
+ * Defaults to `fsStorage()` the built-in filesystem driver.
237
+ * Accepts any object implementing the {@link Storage} interface.
238
+ * Keys are root-relative paths (e.g. `src/gen/api/getPets.ts`).
239
+ * @default fsStorage()
240
+ * @example
241
+ * ```ts
242
+ * import { memoryStorage } from '@kubb/core'
243
+ * storage: memoryStorage()
244
+ * ```
235
245
  */
236
- plugins?: Array<Plugin>
246
+ storage?: Storage
247
+ /**
248
+ * An array of Kubb plugins used for code generation.
249
+ * Each plugin may declare additional configurable options.
250
+ * If a plugin depends on another, an error is thrown when the dependency is missing.
251
+ * Use `dependencies` on the plugin to declare execution order.
252
+ */
253
+ plugins: Array<Plugin>
254
+ /**
255
+ * Middleware instances that observe and post-process the build output.
256
+ * Each middleware receives the `hooks` emitter and attaches its own listeners.
257
+ * Middleware listeners are always registered after all plugin listeners,
258
+ * so middleware hooks fire last for any given event.
259
+ *
260
+ * @example
261
+ * ```ts
262
+ * import { middlewareBarrel } from '@kubb/middleware-barrel'
263
+ * export default defineConfig({
264
+ * middleware: [middlewareBarrel],
265
+ * plugins: [pluginTs(), pluginZod()],
266
+ * })
267
+ * ```
268
+ */
269
+ middleware?: Array<Middleware>
270
+ /**
271
+ * Project-wide renderer factory. All plugins and generators that do not declare their own
272
+ * `renderer` ultimately fall back to this value.
273
+ *
274
+ * The resolution chain is: `generator.renderer` → `plugin.renderer` → `config.renderer` → `undefined` (raw `FileNode[]` mode).
275
+ *
276
+ * @example
277
+ * ```ts
278
+ * import { jsxRenderer } from '@kubb/renderer-jsx'
279
+ * export default defineConfig({
280
+ * renderer: jsxRenderer,
281
+ * plugins: [pluginTs(), pluginZod()],
282
+ * })
283
+ * ```
284
+ */
285
+ renderer?: RendererFactory
237
286
  /**
238
287
  * Devtools configuration for Kubb Studio integration.
239
288
  */
@@ -260,6 +309,63 @@ export type Config<TInput = Input> = {
260
309
 
261
310
  // plugin
262
311
 
312
+ /**
313
+ * A type/string-pattern filter used for `include`, `exclude`, and `override` matching.
314
+ */
315
+ type PatternFilter = {
316
+ type: string
317
+ pattern: string | RegExp
318
+ }
319
+
320
+ /**
321
+ * A pattern filter paired with partial option overrides to apply when the pattern matches.
322
+ */
323
+ type PatternOverride<TOptions> = PatternFilter & {
324
+ options: Omit<Partial<TOptions>, 'override'>
325
+ }
326
+
327
+ /**
328
+ * Context passed to `resolver.resolveOptions` to apply include/exclude/override filtering
329
+ * for a given operation or schema node.
330
+ */
331
+ /**
332
+ * Resolves filtered options for a given operation or schema node.
333
+ *
334
+ * @internal
335
+ */
336
+ export type ResolveOptionsContext<TOptions> = {
337
+ options: TOptions
338
+ exclude?: Array<PatternFilter>
339
+ include?: Array<PatternFilter>
340
+ override?: Array<PatternOverride<TOptions>>
341
+ }
342
+
343
+ /**
344
+ * Base constraint for all plugin resolver objects.
345
+ *
346
+ * `default`, `resolveOptions`, `resolvePath`, and `resolveFile` are injected automatically
347
+ * by `defineResolver` — plugin authors may override them but never need to implement them
348
+ * from scratch.
349
+ *
350
+ * @example
351
+ * ```ts
352
+ * type MyResolver = Resolver & {
353
+ * resolveName(node: SchemaNode): string
354
+ * resolveTypedName(node: SchemaNode): string
355
+ * }
356
+ * ```
357
+ */
358
+ export type Resolver = {
359
+ name: string
360
+ pluginName: Plugin['name']
361
+ default(name: string, type?: 'file' | 'function' | 'type' | 'const'): string
362
+ resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null
363
+ resolvePath(params: ResolverPathParams, context: ResolverContext): string
364
+ resolveFile(params: ResolverFileParams, context: ResolverContext): FileNode
365
+ resolveBanner(node: InputNode | null, context: ResolveBannerContext): string | undefined
366
+ resolveFooter(node: InputNode | null, context: ResolveBannerContext): string | undefined
367
+ }
368
+
263
369
  export type PluginFactoryOptions<
264
370
  /**
265
371
  * Name to be used for the plugin.
@@ -274,239 +380,659 @@ export type PluginFactoryOptions<
274
380
  */
275
381
  TResolvedOptions extends object = TOptions,
276
382
  /**
277
- * Context that you want to expose to other plugins.
383
+ * Resolver object that encapsulates the naming and path-resolution helpers used by this plugin.
384
+ * Use `defineResolver` to define the resolver object and export it alongside the plugin.
278
385
  */
279
- TContext = unknown,
280
- /**
281
- * When calling `resolvePath` you can specify better types.
282
- */
283
- TResolvePathOptions extends object = object,
386
+ TResolver extends Resolver = Resolver,
284
387
  > = {
285
388
  name: TName
286
389
  options: TOptions
287
390
  resolvedOptions: TResolvedOptions
288
- context: TContext
289
- resolvePathOptions: TResolvePathOptions
391
+ resolver: TResolver
290
392
  }
291
393
 
292
- export type GetPluginFactoryOptions<TPlugin extends UserPlugin> = TPlugin extends UserPlugin<infer X> ? X : never
394
+ /**
395
+ * Internal representation of a plugin after normalization.
396
+ * Extends the user-facing `Plugin` with runtime fields populated during `kubb:plugin:setup`.
397
+ * Not part of the public API — use `Plugin` for external-facing interactions.
398
+ * @internal
399
+ */
400
+ export type NormalizedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & {
401
+ options: TOptions['resolvedOptions'] & {
402
+ output: Output
403
+ include?: Array<Include>
404
+ exclude: Array<Exclude>
405
+ override: Array<Override<TOptions['resolvedOptions']>>
406
+ }
407
+ resolver: TOptions['resolver']
408
+ transformer?: Visitor
409
+ renderer?: RendererFactory
410
+ generators?: Array<Generator>
411
+ apply?: (config: Config) => boolean
412
+ version?: string
413
+ }
293
414
 
294
- export type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
415
+ /**
416
+ * Partial version of {@link Config} intended for user-facing config entry points.
417
+ *
418
+ * Fields that have sensible defaults (`root`, `plugins`, `parsers`, `adapter`) are optional.
419
+ */
420
+ export type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter'> & {
295
421
  /**
296
- * Unique name used for the plugin
297
- * The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
298
- * @example @kubb/typescript
422
+ * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
423
+ * @default process.cwd()
299
424
  */
300
- name: TOptions['name']
425
+ root?: string
301
426
  /**
302
- * Options set for a specific plugin(see kubb.config.js), passthrough of options.
427
+ * An array of parsers used to convert generated files to strings.
428
+ * Each parser handles specific file extensions (e.g. `.ts`, `.tsx`).
429
+ *
430
+ * A catch-all fallback parser is always appended last for any unhandled extension.
303
431
  */
304
- options: TOptions['resolvedOptions']
432
+ parsers?: Array<Parser>
305
433
  /**
306
- * 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.
307
- * Can be used to validate dependent plugins.
434
+ * Adapter that converts the input file into a `@kubb/ast` `InputNode`.
308
435
  */
309
- pre?: Array<string>
436
+ adapter?: Adapter
310
437
  /**
311
- * 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.
438
+ * An array of Kubb plugins used for code generation.
439
+ * Each entry is a hook-style plugin created with `definePlugin`.
312
440
  */
313
- post?: Array<string>
314
- inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context']
441
+ plugins?: Array<Plugin>
315
442
  }
316
443
 
317
- export type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>
318
-
319
- export type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<any, any, any, any, any>>
320
-
321
- export type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
444
+ export type ResolveNameParams = {
445
+ name: string
446
+ pluginName?: string
322
447
  /**
323
- * Unique name used for the plugin
324
- * @example @kubb/typescript
448
+ * Specifies the type of entity being named.
449
+ * - `'file'` — customizes the name of the created file (camelCase).
450
+ * - `'function'` — customizes the exported function names (camelCase).
451
+ * - `'type'` — customizes TypeScript type names (PascalCase).
452
+ * - `'const'` — customizes variable names (camelCase).
325
453
  */
326
- name: TOptions['name']
454
+ type?: 'file' | 'function' | 'type' | 'const'
455
+ }
456
+ /**
457
+ * Context object passed as the second argument to generator `schema`, `operation`, and
458
+ * `operations` methods.
459
+ *
460
+ * Generators are only invoked from `runPluginAstHooks`, which already guards against a
461
+ * missing adapter. This type reflects that guarantee — `ctx.adapter` and `ctx.inputNode`
462
+ * are always defined, so no runtime checks or casts are needed inside generator bodies.
463
+ *
464
+ * `ctx.options` carries the per-node resolved options for `schema`/`operation` calls
465
+ * (after exclude/include/override filtering) and the plugin-level options for `operations`.
466
+ */
467
+ export type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
468
+ config: Config
327
469
  /**
328
- * 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.
329
- * Can be used to validate dependent plugins.
470
+ * Absolute path to the output directory for the current plugin.
471
+ * Shorthand for `path.resolve(config.root, config.output.path)`.
330
472
  */
331
- pre?: Array<string>
473
+ root: string
332
474
  /**
333
- * 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.
475
+ * Returns the output mode for the given output config.
476
+ * Returns `'single'` when `output.path` has a file extension, `'split'` otherwise.
334
477
  */
335
- post?: Array<string>
478
+ getMode: (output: { path: string }) => 'single' | 'split'
479
+ driver: PluginDriver
336
480
  /**
337
- * Options set for a specific plugin(see kubb.config.js), passthrough of options.
481
+ * Get a plugin by name. Returns the plugin typed via `Kubb.PluginRegistry` when
482
+ * the name is a registered key, otherwise returns the generic `Plugin`.
338
483
  */
339
- options: TOptions['resolvedOptions']
340
-
341
- install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>
484
+ getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined
485
+ getPlugin(name: string): Plugin | undefined
342
486
  /**
343
- * Define a context that can be used by other plugins, see `PluginDriver' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
487
+ * Like `getPlugin` but throws a descriptive error when the plugin is not found.
344
488
  */
345
- inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context']
346
- }
347
-
348
- export type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>
349
-
350
- export type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
489
+ requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>
490
+ requirePlugin(name: string): Plugin
351
491
  /**
352
- * Start of the lifecycle of a plugin.
353
- * @type hookParallel
492
+ * Get a resolver by plugin name. Returns the resolver typed via `Kubb.PluginRegistry` when
493
+ * the name is a registered key, otherwise returns the generic `Resolver`.
354
494
  */
355
- install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>
495
+ getResolver<TName extends keyof Kubb.PluginRegistry>(name: TName): Kubb.PluginRegistry[TName]['resolver']
496
+ getResolver(name: string): Resolver
356
497
  /**
357
- * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
358
- * Options can als be included.
359
- * @type hookFirst
360
- * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
498
+ * Add files only when they do not exist yet.
361
499
  */
362
- resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path
500
+ addFile: (...file: Array<FileNode>) => Promise<void>
363
501
  /**
364
- * Resolve to a name based on a string.
365
- * Useful when converting to PascalCase or camelCase.
366
- * @type hookFirst
367
- * @example ('pet') => 'Pet'
502
+ * Merge multiple sources into the same output file.
368
503
  */
369
- resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
504
+ upsertFile: (...file: Array<FileNode>) => Promise<void>
505
+ hooks: AsyncEventEmitter<KubbHooks>
506
+ /**
507
+ * The current plugin.
508
+ */
509
+ plugin: Plugin<TOptions>
510
+ /**
511
+ * Resolver for the current plugin.
512
+ */
513
+ resolver: TOptions['resolver']
514
+ /**
515
+ * Composed transformer for the current plugin.
516
+ */
517
+ transformer: Visitor | undefined
518
+ /**
519
+ * Emit a warning via the build event system.
520
+ */
521
+ warn: (message: string) => void
522
+ /**
523
+ * Emit an error via the build event system.
524
+ */
525
+ error: (error: string | Error) => void
526
+ /**
527
+ * Emit an info message via the build event system.
528
+ */
529
+ info: (message: string) => void
530
+ /**
531
+ * Opens the Kubb Studio URL for the current `inputNode` in the default browser.
532
+ */
533
+ openInStudio: (options?: DevtoolsOptions) => Promise<void>
534
+ /**
535
+ * The adapter from `@kubb/ast`.
536
+ */
537
+ adapter: Adapter
538
+ /**
539
+ * The universal `@kubb/ast` `InputNode` produced by the configured adapter.
540
+ */
541
+ inputNode: InputNode
542
+ /**
543
+ * Per-node resolved options (after exclude/include/override filtering).
544
+ */
545
+ options: TOptions['resolvedOptions']
370
546
  }
547
+ /**
548
+ * Configure generated file output location and behavior.
549
+ */
550
+ export type Output<_TOptions = unknown> = {
551
+ /**
552
+ * Path to the output folder or file that will contain generated code.
553
+ */
554
+ path: string
555
+ /**
556
+ * Text or function appended at the start of every generated file.
557
+ * When a function, receives the current `InputNode` and must return a string.
558
+ */
559
+ banner?: string | ((node?: InputNode) => string)
560
+ /**
561
+ * Text or function appended at the end of every generated file.
562
+ * When a function, receives the current `InputNode` and must return a string.
563
+ */
564
+ footer?: string | ((node?: InputNode) => string)
565
+ /**
566
+ * Whether to override existing external files if they already exist.
567
+ * @default false
568
+ */
569
+ override?: boolean
570
+ } & ExtractRegistryKey<Kubb.PluginOptionsRegistry, 'output'>
371
571
 
372
- export type PluginLifecycleHooks = keyof PluginLifecycle
373
-
374
- export type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>
572
+ export type Group = {
573
+ /**
574
+ * Determines how files are grouped into subdirectories.
575
+ * - `'tag'` groups files by OpenAPI tags.
576
+ * - `'path'` groups files by OpenAPI paths.
577
+ */
578
+ type: 'tag' | 'path'
579
+ /**
580
+ * Returns the subdirectory name for a given group value.
581
+ * Defaults to `${camelCase(group)}Controller` for tags and the first path segment for paths.
582
+ */
583
+ name?: (context: { group: string }) => string
584
+ }
375
585
 
376
- export type ResolvePathParams<TOptions = object> = {
377
- pluginName?: string
378
- baseName: KubbFile.BaseName
379
- mode?: KubbFile.Mode
586
+ export type LoggerOptions = {
380
587
  /**
381
- * Options to be passed to 'resolvePath' 3th parameter
588
+ * @default 3
382
589
  */
383
- options?: TOptions
590
+ logLevel: (typeof logLevel)[keyof typeof logLevel]
384
591
  }
385
592
 
386
- export type ResolveNameParams = {
593
+ /**
594
+ * Shared context passed to all plugins, parsers, and other internals.
595
+ */
596
+ export type LoggerContext = AsyncEventEmitter<KubbHooks>
597
+
598
+ export type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
387
599
  name: string
388
- pluginName?: string
600
+ install: (context: LoggerContext, options?: TOptions) => void | Promise<void>
601
+ }
602
+
603
+ export type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Logger<TOptions>
604
+
605
+ export type { Storage } from './createStorage.ts'
606
+ export type { Generator } from './defineGenerator.ts'
607
+ export type { Middleware } from './defineMiddleware.ts'
608
+ export type { Plugin } from './definePlugin.ts'
609
+ export type { Kubb, KubbHooks } from './Kubb.ts'
610
+
611
+ /**
612
+ * Context passed to a hook-style plugin's `kubb:plugin:setup` handler.
613
+ * Provides methods to register generators, configure the resolver, transformer,
614
+ * and renderer, as well as access to the current build configuration.
615
+ */
616
+ export type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
389
617
  /**
390
- * Specifies the type of entity being named.
391
- * - 'file' customizes the name of the created file (uses camelCase).
392
- * - 'function' customizes the exported function names (uses camelCase).
393
- * - 'type' customizes TypeScript types (uses PascalCase).
394
- * - 'const' customizes variable names (uses camelCase).
395
- * @default undefined
618
+ * Register a generator on this plugin. Generators are invoked during the AST walk
619
+ * (schema/operation/operations) exactly like generators declared statically on `createPlugin`.
396
620
  */
397
- type?: 'file' | 'function' | 'type' | 'const'
621
+ addGenerator<TElement = unknown>(generator: Generator<TFactory, TElement>): void
622
+ /**
623
+ * Set or partially override the resolver for this plugin.
624
+ * The resolver controls file naming and path resolution for generated files.
625
+ *
626
+ * When `TFactory` is a concrete `PluginFactoryOptions` (e.g. `PluginClient`),
627
+ * the resolver parameter is typed to the plugin's own resolver type (e.g. `ResolverClient`).
628
+ */
629
+ setResolver(resolver: Partial<TFactory['resolver']>): void
630
+ /**
631
+ * Set the AST transformer (visitor) for this plugin.
632
+ * The transformer pre-processes nodes before they reach the generators.
633
+ */
634
+ setTransformer(visitor: Visitor): void
635
+ /**
636
+ * Set the renderer factory for this plugin.
637
+ * Used to process JSX elements returned by generators.
638
+ */
639
+ setRenderer(renderer: RendererFactory): void
640
+ /**
641
+ * Set the resolved options for the build loop. These options are merged into the
642
+ * normalized plugin's `options` object (which includes `output`, `exclude`, `override`).
643
+ *
644
+ * Call this in `kubb:plugin:setup` to provide the resolved options that generators
645
+ * and the build loop need (e.g., `enumType`, `optionalType`, `group`).
646
+ */
647
+ setOptions(options: TFactory['resolvedOptions']): void
648
+ /**
649
+ * Inject a raw file into the build output, bypassing the normal generation pipeline.
650
+ */
651
+ injectFile(userFileNode: UserFileNode): void
652
+ /**
653
+ * Merge a partial config update into the current build configuration.
654
+ */
655
+ updateConfig(config: Partial<Config>): void
656
+ /**
657
+ * The resolved build configuration at the time of setup.
658
+ */
659
+ config: Config
660
+ /**
661
+ * The plugin's own options as passed by the user.
662
+ */
663
+ options: TFactory['options']
398
664
  }
399
665
 
400
- export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
401
- fabric: FabricType
666
+ /**
667
+ * Context passed to a hook-style plugin's `kubb:build:start` handler.
668
+ * Fires immediately before the plugin execution loop begins.
669
+ */
670
+ export type KubbBuildStartContext = {
402
671
  config: Config
403
- driver: PluginDriver
672
+ adapter: Adapter
673
+ inputNode: InputNode
404
674
  /**
405
- * Only add when the file does not exist yet
675
+ * Get a plugin by name. Returns the plugin typed via `Kubb.PluginRegistry` when
676
+ * the name is a registered key, otherwise returns the generic `Plugin`.
406
677
  */
407
- addFile: (...file: Array<KubbFile.File>) => Promise<void>
678
+ getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined
679
+ getPlugin(name: string): Plugin | undefined
408
680
  /**
409
- * merging multiple sources into the same output file
681
+ * Returns all files currently in the file manager.
682
+ * Call this lazily (e.g. inside a `kubb:plugin:end` listener) to see files added by plugins
683
+ * that have already run.
410
684
  */
411
- upsertFile: (...file: Array<KubbFile.File>) => Promise<void>
412
- events: AsyncEventEmitter<KubbEvents>
413
- mode: KubbFile.Mode
685
+ readonly files: ReadonlyArray<FileNode>
414
686
  /**
415
- * Current plugin
687
+ * Upsert one or more files into the file manager.
688
+ * Files with the same path are merged; new files are appended.
689
+ * Safe to call at any point during the plugin lifecycle, including inside `kubb:plugin:end`.
416
690
  */
417
- plugin: Plugin<TOptions>
691
+ upsertFile: (...files: Array<FileNode>) => void
692
+ }
418
693
 
694
+ /**
695
+ * Context passed to `kubb:plugins:end` handlers.
696
+ * Fires after all plugins have run and per-plugin barrels have been written,
697
+ * but BEFORE files are written to disk.
698
+ * Middleware that needs to inject final files (e.g. a root barrel) should use this event.
699
+ */
700
+ export type KubbPluginsEndContext = {
701
+ config: Config
419
702
  /**
420
- * Opens the Kubb Studio URL for the current `rootNode` in the default browser.
421
- * Falls back to printing the URL if the browser cannot be launched.
422
- * No-ops silently when no adapter has set a `rootNode`.
703
+ * Returns all files currently in the file manager (lazy snapshot).
704
+ * Includes files added by plugins and per-plugin barrel middleware.
423
705
  */
424
- openInStudio: (options?: DevtoolsOptions) => Promise<void>
425
- } & (
426
- | {
427
- /**
428
- * Returns the universal `@kubb/ast` `RootNode` produced by the configured adapter.
429
- * Returns `undefined` when no adapter was set (legacy OAS-only usage).
430
- */
431
- rootNode: RootNode
432
- /**
433
- * Return the adapter from `@kubb/ast`
434
- */
435
- adapter: Adapter
436
- }
437
- | {
438
- rootNode?: never
439
- adapter?: never
440
- }
441
- ) &
442
- Kubb.PluginContext
706
+ readonly files: ReadonlyArray<FileNode>
707
+ /**
708
+ * Upsert one or more files into the file manager.
709
+ * Files added here will be included in the write pass that follows.
710
+ */
711
+ upsertFile: (...files: Array<FileNode>) => void
712
+ }
713
+
443
714
  /**
444
- * Specify the export location for the files and define the behavior of the output
715
+ * Context passed to a hook-style plugin's `kubb:build:end` handler.
716
+ * Fires after all files have been written to disk.
445
717
  */
446
- export type Output<TOptions> = {
718
+ export type KubbBuildEndContext = {
719
+ files: Array<FileNode>
720
+ config: Config
721
+ outputDir: string
722
+ }
723
+
724
+ export type KubbLifecycleStartContext = {
725
+ version: string
726
+ }
727
+
728
+ export type KubbConfigEndContext = {
729
+ configs: Array<Config>
730
+ }
731
+
732
+ export type KubbGenerationStartContext = {
733
+ config: Config
734
+ }
735
+
736
+ export type KubbGenerationEndContext = {
737
+ config: Config
738
+ files: Array<FileNode>
739
+ sources: Map<string, string>
740
+ }
741
+
742
+ export type KubbGenerationSummaryContext = {
743
+ config: Config
744
+ failedPlugins: Set<{ plugin: Plugin; error: Error }>
745
+ status: 'success' | 'failed'
746
+ hrStart: [number, number]
747
+ filesCreated: number
748
+ pluginTimings?: Map<Plugin['name'], number>
749
+ }
750
+
751
+ export type KubbVersionNewContext = {
752
+ currentVersion: string
753
+ latestVersion: string
754
+ }
755
+
756
+ export type KubbInfoContext = {
757
+ message: string
758
+ info?: string
759
+ }
760
+
761
+ export type KubbErrorContext = {
762
+ error: Error
763
+ meta?: Record<string, unknown>
764
+ }
765
+
766
+ export type KubbSuccessContext = {
767
+ message: string
768
+ info?: string
769
+ }
770
+
771
+ export type KubbWarnContext = {
772
+ message: string
773
+ info?: string
774
+ }
775
+
776
+ export type KubbDebugContext = {
777
+ date: Date
778
+ logs: Array<string>
779
+ fileName?: string
780
+ }
781
+
782
+ export type KubbFilesProcessingStartContext = {
783
+ files: Array<FileNode>
784
+ }
785
+
786
+ export type KubbFileProcessingUpdateContext = {
447
787
  /**
448
- * Path to the output folder or file that will contain the generated code
788
+ * Number of files processed so far.
449
789
  */
450
- path: string
790
+ processed: number
451
791
  /**
452
- * Define what needs to be exported, here you can also disable the export of barrel files
453
- * @default 'named'
792
+ * Total number of files to process.
454
793
  */
455
- barrelType?: BarrelType | false
794
+ total: number
456
795
  /**
457
- * Add a banner text in the beginning of every file
796
+ * Processing percentage (0–100).
458
797
  */
459
- banner?: string | ((options: TOptions) => string)
798
+ percentage: number
460
799
  /**
461
- * Add a footer text in the beginning of every file
800
+ * Optional source identifier.
462
801
  */
463
- footer?: string | ((options: TOptions) => string)
802
+ source?: string
464
803
  /**
465
- * Whether to override existing external files if they already exist.
466
- * @default false
804
+ * The file being processed.
467
805
  */
468
- override?: boolean
806
+ file: FileNode
807
+ /**
808
+ * Kubb configuration.
809
+ * Provides access to the current config during file processing.
810
+ */
811
+ config: Config
469
812
  }
470
813
 
471
- type GroupContext = {
472
- group: string
814
+ export type KubbFilesProcessingEndContext = {
815
+ files: Array<FileNode>
473
816
  }
474
817
 
475
- export type Group = {
818
+ export type KubbPluginStartContext = {
819
+ plugin: NormalizedPlugin
820
+ }
821
+
822
+ export type KubbPluginEndContext = {
823
+ plugin: NormalizedPlugin
824
+ duration: number
825
+ success: boolean
826
+ error?: Error
827
+ config: Config
476
828
  /**
477
- * Defines the type where to group the files.
478
- * - 'tag' groups files by OpenAPI tags.
479
- * - 'path' groups files by OpenAPI paths.
480
- * @default undefined
829
+ * Returns all files currently in the file manager (lazy snapshot).
830
+ * Includes files added by plugins that have already run.
481
831
  */
482
- type: 'tag' | 'path'
832
+ readonly files: ReadonlyArray<FileNode>
483
833
  /**
484
- * Return the name of a group based on the group name, this used for the file and name generation
834
+ * Upsert one or more files into the file manager.
485
835
  */
486
- name?: (context: GroupContext) => string
836
+ upsertFile: (...files: Array<FileNode>) => void
487
837
  }
488
838
 
489
- export type LoggerOptions = {
839
+ export type KubbHookStartContext = {
840
+ id?: string
841
+ command: string
842
+ args?: readonly string[]
843
+ }
844
+
845
+ export type KubbHookEndContext = {
846
+ id?: string
847
+ command: string
848
+ args?: readonly string[]
849
+ success: boolean
850
+ error: Error | null
851
+ }
852
+
853
+ type ByTag = {
854
+ type: 'tag'
855
+ pattern: string | RegExp
856
+ }
857
+
858
+ type ByOperationId = {
859
+ type: 'operationId'
860
+ pattern: string | RegExp
861
+ }
862
+
863
+ type ByPath = {
864
+ type: 'path'
865
+ pattern: string | RegExp
866
+ }
867
+
868
+ type ByMethod = {
869
+ type: 'method'
870
+ pattern: HttpMethod | RegExp
871
+ }
872
+ // TODO implement as alternative for ByMethod
873
+ // type ByMethods = {
874
+ // type: 'methods'
875
+ // pattern: Array<HttpMethod>
876
+ // }
877
+
878
+ type BySchemaName = {
879
+ type: 'schemaName'
880
+ pattern: string | RegExp
881
+ }
882
+
883
+ type ByContentType = {
884
+ type: 'contentType'
885
+ pattern: string | RegExp
886
+ }
887
+
888
+ /**
889
+ * A pattern filter that prevents matching nodes from being generated.
890
+ * Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
891
+ */
892
+ export type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
893
+
894
+ /**
895
+ * A pattern filter that restricts generation to only matching nodes.
896
+ * Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
897
+ */
898
+ export type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
899
+
900
+ /**
901
+ * A pattern filter paired with partial option overrides applied when the pattern matches.
902
+ * Match by `tag`, `operationId`, `path`, `method`, `schemaName`, or `contentType`.
903
+ */
904
+ export type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
905
+ //TODO should be options: Omit<Partial<TOptions>, 'override'>
906
+ options: Partial<TOptions>
907
+ }
908
+
909
+ /**
910
+ * File-specific parameters for `Resolver.resolvePath`.
911
+ *
912
+ * Pass alongside a `ResolverContext` to identify which file to resolve.
913
+ * Provide `tag` for tag-based grouping or `path` for path-based grouping.
914
+ *
915
+ * @example
916
+ * ```ts
917
+ * resolver.resolvePath(
918
+ * { baseName: 'petTypes.ts', tag: 'pets' },
919
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
920
+ * )
921
+ * // → '/src/types/petsController/petTypes.ts'
922
+ * ```
923
+ */
924
+ export type ResolverPathParams = {
925
+ baseName: FileNode['baseName']
926
+ pathMode?: 'single' | 'split'
490
927
  /**
491
- * @default 3
928
+ * Tag value used when `group.type === 'tag'`.
492
929
  */
493
- logLevel: (typeof logLevel)[keyof typeof logLevel]
930
+ tag?: string
931
+ /**
932
+ * Path value used when `group.type === 'path'`.
933
+ */
934
+ path?: string
935
+ }
936
+
937
+ /**
938
+ * Shared context passed as the second argument to `Resolver.resolvePath` and `Resolver.resolveFile`.
939
+ *
940
+ * Describes where on disk output is rooted, which output config is active, and the optional
941
+ * grouping strategy that controls subdirectory layout.
942
+ *
943
+ * @example
944
+ * ```ts
945
+ * const context: ResolverContext = {
946
+ * root: config.root,
947
+ * output,
948
+ * group,
949
+ * }
950
+ * ```
951
+ */
952
+ export type ResolverContext = {
953
+ root: string
954
+ output: Output
955
+ group?: Group
956
+ /**
957
+ * Plugin name used to populate `meta.pluginName` on the resolved file.
958
+ */
959
+ pluginName?: string
494
960
  }
495
961
 
496
962
  /**
497
- * Shared context passed to all plugins, parsers, and Fabric internals.
963
+ * File-specific parameters for `Resolver.resolveFile`.
964
+ *
965
+ * Pass alongside a `ResolverContext` to fully describe the file to resolve.
966
+ * `tag` and `path` are used only when a matching `group` is present in the context.
967
+ *
968
+ * @example
969
+ * ```ts
970
+ * resolver.resolveFile(
971
+ * { name: 'listPets', extname: '.ts', tag: 'pets' },
972
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
973
+ * )
974
+ * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
975
+ * ```
498
976
  */
499
- export interface LoggerContext extends AsyncEventEmitter<KubbEvents> {}
977
+ export type ResolverFileParams = {
978
+ name: string
979
+ extname: FileNode['extname']
980
+ /**
981
+ * Tag value used when `group.type === 'tag'`.
982
+ */
983
+ tag?: string
984
+ /**
985
+ * Path value used when `group.type === 'path'`.
986
+ */
987
+ path?: string
988
+ }
500
989
 
501
- type Install<TOptions = unknown> = (context: LoggerContext, options?: TOptions) => void | Promise<void>
990
+ /**
991
+ * Context passed to `Resolver.resolveBanner` and `Resolver.resolveFooter`.
992
+ *
993
+ * `output` is optional — not every plugin configures a banner/footer.
994
+ * `config` carries the global Kubb config, used to derive the default Kubb banner.
995
+ *
996
+ * @example
997
+ * ```ts
998
+ * resolver.resolveBanner(inputNode, { output: { banner: '// generated' }, config })
999
+ * // → '// generated'
1000
+ * ```
1001
+ */
1002
+ export type ResolveBannerContext = {
1003
+ output?: Pick<Output, 'banner' | 'footer'>
1004
+ config: Config
1005
+ }
502
1006
 
503
- export type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
504
- name: string
505
- install: Install<TOptions>
1007
+ /**
1008
+ * CLI options derived from command-line flags.
1009
+ */
1010
+ export type CLIOptions = {
1011
+ /**
1012
+ * Path to `kubb.config.js`.
1013
+ */
1014
+ config?: string
1015
+ /**
1016
+ * Enable watch mode for input files.
1017
+ */
1018
+ watch?: boolean
1019
+ /**
1020
+ * Logging verbosity for CLI usage.
1021
+ * @default 'silent'
1022
+ */
1023
+ logLevel?: 'silent' | 'info' | 'debug'
506
1024
  }
507
1025
 
508
- export type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Omit<Logger<TOptions>, 'logLevel'>
1026
+ /**
1027
+ * All accepted forms of a Kubb configuration.
1028
+ *
1029
+ * Config is always `@kubb/core` {@link Config}.
1030
+ * - `PossibleConfig` accepts `Config`/`Config[]`/promise or a no-arg config factory.
1031
+ * - `PossibleConfig<TCliOptions>` accepts the same config forms or a config factory receiving `TCliOptions`.
1032
+ */
1033
+ export type PossibleConfig<TCliOptions = undefined> =
1034
+ | PossiblePromise<Config | Config[]>
1035
+ | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Config[]>)
509
1036
 
510
- export type { CoreGeneratorV2, Generator, ReactGeneratorV2 } from './defineGenerator.ts'
511
- export type { DefineStorage } from './defineStorage.ts'
512
- export type { KubbEvents } from './Kubb.ts'
1037
+ export type { BuildOutput } from './createKubb.ts'
1038
+ export type { Parser } from './defineParser.ts'