@kubb/core 5.0.0-alpha.6 → 5.0.0-alpha.60

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 (72) hide show
  1. package/README.md +3 -2
  2. package/dist/PluginDriver-Bc0HQM8V.js +948 -0
  3. package/dist/PluginDriver-Bc0HQM8V.js.map +1 -0
  4. package/dist/PluginDriver-Dyl2fwfQ.cjs +1039 -0
  5. package/dist/PluginDriver-Dyl2fwfQ.cjs.map +1 -0
  6. package/dist/index.cjs +691 -1798
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts +279 -265
  9. package/dist/index.js +678 -1765
  10. package/dist/index.js.map +1 -1
  11. package/dist/mocks.cjs +138 -0
  12. package/dist/mocks.cjs.map +1 -0
  13. package/dist/mocks.d.ts +74 -0
  14. package/dist/mocks.js +133 -0
  15. package/dist/mocks.js.map +1 -0
  16. package/dist/types-i0b4_23K.d.ts +1903 -0
  17. package/package.json +51 -57
  18. package/src/FileManager.ts +110 -0
  19. package/src/FileProcessor.ts +86 -0
  20. package/src/Kubb.ts +205 -130
  21. package/src/PluginDriver.ts +424 -0
  22. package/src/constants.ts +20 -47
  23. package/src/createAdapter.ts +25 -0
  24. package/src/createKubb.ts +527 -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 +59 -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 -17
  35. package/src/mocks.ts +171 -0
  36. package/src/renderNode.ts +35 -0
  37. package/src/storages/fsStorage.ts +40 -11
  38. package/src/storages/memoryStorage.ts +4 -3
  39. package/src/types.ts +738 -218
  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/PluginManager-vZodFEMe.d.ts +0 -1056
  44. package/dist/chunk-ByKO4r7w.cjs +0 -38
  45. package/dist/hooks.cjs +0 -60
  46. package/dist/hooks.cjs.map +0 -1
  47. package/dist/hooks.d.ts +0 -64
  48. package/dist/hooks.js +0 -56
  49. package/dist/hooks.js.map +0 -1
  50. package/src/BarrelManager.ts +0 -74
  51. package/src/PackageManager.ts +0 -180
  52. package/src/PluginManager.ts +0 -667
  53. package/src/PromiseManager.ts +0 -40
  54. package/src/build.ts +0 -419
  55. package/src/config.ts +0 -56
  56. package/src/defineAdapter.ts +0 -22
  57. package/src/defineStorage.ts +0 -56
  58. package/src/errors.ts +0 -1
  59. package/src/hooks/index.ts +0 -4
  60. package/src/hooks/useKubb.ts +0 -55
  61. package/src/hooks/useMode.ts +0 -11
  62. package/src/hooks/usePlugin.ts +0 -11
  63. package/src/hooks/usePluginManager.ts +0 -11
  64. package/src/utils/FunctionParams.ts +0 -155
  65. package/src/utils/TreeNode.ts +0 -215
  66. package/src/utils/executeStrategies.ts +0 -81
  67. package/src/utils/formatters.ts +0 -56
  68. package/src/utils/getBarrelFiles.ts +0 -79
  69. package/src/utils/getConfigs.ts +0 -30
  70. package/src/utils/getPlugins.ts +0 -23
  71. package/src/utils/linters.ts +0 -25
  72. 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, 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'
7
- 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 { 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'
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 PluginManager 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
  /**
@@ -172,32 +193,32 @@ export type Config<TInput = Input> = {
172
193
  /**
173
194
  * Storage backend for generated files.
174
195
  * Defaults to `fsStorage()` — the built-in filesystem driver.
175
- * Accepts any object implementing the {@link DefineStorage} interface.
196
+ * Accepts any object implementing the {@link Storage} interface.
176
197
  * Keys are root-relative paths (e.g. `src/gen/api/getPets.ts`).
177
198
  * @default fsStorage()
178
199
  * @example
179
200
  * ```ts
180
- * import { defineStorage, fsStorage } from '@kubb/core'
181
- * storage: defineStorage(fsStorage())
201
+ * import { memoryStorage } from '@kubb/core'
202
+ * storage: memoryStorage()
182
203
  * ```
183
204
  */
184
- storage?: DefineStorage
205
+ storage?: Storage
185
206
  /**
186
207
  * Specifies the formatting tool to be used.
187
- * - 'auto' automatically detects and uses biome or prettier (in that order of preference).
208
+ * - 'auto' automatically detects and uses oxfmt, biome, or prettier (in that order of preference).
209
+ * - 'oxfmt' uses Oxfmt for code formatting.
188
210
  * - 'prettier' uses Prettier for code formatting.
189
211
  * - 'biome' uses Biome for code formatting.
190
- * - 'oxfmt' uses Oxfmt for code formatting.
191
212
  * - false disables code formatting.
192
213
  * @default 'prettier'
193
214
  */
194
215
  format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false
195
216
  /**
196
217
  * 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).
218
+ * - 'auto' automatically detects and uses oxlint, biome, or eslint (in that order of preference).
219
+ * - 'oxlint' uses Oxlint for linting.
198
220
  * - 'eslint' uses ESLint for linting.
199
221
  * - 'biome' uses Biome for linting.
200
- * - 'oxlint' uses Oxlint for linting.
201
222
  * - false disables linting.
202
223
  * @default 'auto'
203
224
  */
@@ -206,12 +227,7 @@ export type Config<TInput = Input> = {
206
227
  * Overrides the extension for generated imports and exports. By default, each plugin adds an extension.
207
228
  * @default { '.ts': '.ts'}
208
229
  */
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
230
+ extension?: Record<FileNode['extname'], FileNode['extname'] | ''>
215
231
  /**
216
232
  * Adds a default banner to the start of every generated file indicating it was generated by Kubb.
217
233
  * - 'simple' adds banner with link to Kubb.
@@ -227,13 +243,46 @@ export type Config<TInput = Input> = {
227
243
  * @default false
228
244
  */
229
245
  override?: boolean
230
- }
246
+ } & ExtractRegistryKey<Kubb.ConfigOptionsRegistry, 'output'>
231
247
  /**
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.
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.
235
252
  */
236
- plugins?: Array<Plugin>
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,653 @@ 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 `PluginManager' 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(
652
+ file: Pick<FileNode, 'baseName' | 'path'> & {
653
+ sources?: FileNode['sources']
654
+ },
655
+ ): void
656
+ /**
657
+ * Merge a partial config update into the current build configuration.
658
+ */
659
+ updateConfig(config: Partial<Config>): void
660
+ /**
661
+ * The resolved build configuration at the time of setup.
662
+ */
663
+ config: Config
664
+ /**
665
+ * The plugin's own options as passed by the user.
666
+ */
667
+ options: TFactory['options']
398
668
  }
399
669
 
400
- export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
401
- fabric: FabricType
670
+ /**
671
+ * Context passed to a hook-style plugin's `kubb:build:start` handler.
672
+ * Fires immediately before the plugin execution loop begins.
673
+ */
674
+ export type KubbBuildStartContext = {
402
675
  config: Config
403
- pluginManager: PluginManager
676
+ adapter: Adapter
677
+ inputNode: InputNode
404
678
  /**
405
- * Only add when the file does not exist yet
679
+ * Get a plugin by name. Returns the plugin typed via `Kubb.PluginRegistry` when
680
+ * the name is a registered key, otherwise returns the generic `Plugin`.
406
681
  */
407
- addFile: (...file: Array<KubbFile.File>) => Promise<void>
682
+ getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined
683
+ getPlugin(name: string): Plugin | undefined
408
684
  /**
409
- * merging multiple sources into the same output file
685
+ * Returns all files currently in the file manager.
686
+ * Call this lazily (e.g. inside a `kubb:plugin:end` listener) to see files added by plugins
687
+ * that have already run.
410
688
  */
411
- upsertFile: (...file: Array<KubbFile.File>) => Promise<void>
412
- events: AsyncEventEmitter<KubbEvents>
413
- mode: KubbFile.Mode
689
+ readonly files: ReadonlyArray<FileNode>
414
690
  /**
415
- * Current plugin
691
+ * Upsert one or more files into the file manager.
692
+ * Files with the same path are merged; new files are appended.
693
+ * Safe to call at any point during the plugin lifecycle, including inside `kubb:plugin:end`.
416
694
  */
417
- plugin: Plugin<TOptions>
695
+ upsertFile: (...files: Array<FileNode>) => void
696
+ }
418
697
 
698
+ /**
699
+ * Context passed to `kubb:plugins:end` handlers.
700
+ * Fires after all plugins have run and per-plugin barrels have been written,
701
+ * but BEFORE files are written to disk.
702
+ * Middleware that needs to inject final files (e.g. a root barrel) should use this event.
703
+ */
704
+ export type KubbPluginsEndContext = {
705
+ config: Config
419
706
  /**
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`.
707
+ * Returns all files currently in the file manager (lazy snapshot).
708
+ * Includes files added by plugins and per-plugin barrel middleware.
423
709
  */
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
710
+ readonly files: ReadonlyArray<FileNode>
711
+ /**
712
+ * Upsert one or more files into the file manager.
713
+ * Files added here will be included in the write pass that follows.
714
+ */
715
+ upsertFile: (...files: Array<FileNode>) => void
716
+ }
717
+
443
718
  /**
444
- * Specify the export location for the files and define the behavior of the output
719
+ * Context passed to a hook-style plugin's `kubb:build:end` handler.
720
+ * Fires after all files have been written to disk.
445
721
  */
446
- export type Output<TOptions> = {
722
+ export type KubbBuildEndContext = {
723
+ files: Array<FileNode>
724
+ config: Config
725
+ outputDir: string
726
+ }
727
+
728
+ export type KubbLifecycleStartContext = {
729
+ version: string
730
+ }
731
+
732
+ export type KubbConfigEndContext = {
733
+ configs: Array<Config>
734
+ }
735
+
736
+ export type KubbGenerationStartContext = {
737
+ config: Config
738
+ }
739
+
740
+ export type KubbGenerationEndContext = {
741
+ config: Config
742
+ files: Array<FileNode>
743
+ sources: Map<string, string>
744
+ }
745
+
746
+ export type KubbGenerationSummaryContext = {
747
+ config: Config
748
+ failedPlugins: Set<{ plugin: Plugin; error: Error }>
749
+ status: 'success' | 'failed'
750
+ hrStart: [number, number]
751
+ filesCreated: number
752
+ pluginTimings?: Map<Plugin['name'], number>
753
+ }
754
+
755
+ export type KubbVersionNewContext = {
756
+ currentVersion: string
757
+ latestVersion: string
758
+ }
759
+
760
+ export type KubbInfoContext = {
761
+ message: string
762
+ info?: string
763
+ }
764
+
765
+ export type KubbErrorContext = {
766
+ error: Error
767
+ meta?: Record<string, unknown>
768
+ }
769
+
770
+ export type KubbSuccessContext = {
771
+ message: string
772
+ info?: string
773
+ }
774
+
775
+ export type KubbWarnContext = {
776
+ message: string
777
+ info?: string
778
+ }
779
+
780
+ export type KubbDebugContext = {
781
+ date: Date
782
+ logs: Array<string>
783
+ fileName?: string
784
+ }
785
+
786
+ export type KubbFilesProcessingStartContext = {
787
+ files: Array<FileNode>
788
+ }
789
+
790
+ export type KubbFileProcessingUpdateContext = {
447
791
  /**
448
- * Path to the output folder or file that will contain the generated code
792
+ * Number of files processed so far.
449
793
  */
450
- path: string
794
+ processed: number
451
795
  /**
452
- * Define what needs to be exported, here you can also disable the export of barrel files
453
- * @default 'named'
796
+ * Total number of files to process.
454
797
  */
455
- barrelType?: BarrelType | false
798
+ total: number
456
799
  /**
457
- * Add a banner text in the beginning of every file
800
+ * Processing percentage (0–100).
458
801
  */
459
- banner?: string | ((options: TOptions) => string)
802
+ percentage: number
460
803
  /**
461
- * Add a footer text in the beginning of every file
804
+ * Optional source identifier.
462
805
  */
463
- footer?: string | ((options: TOptions) => string)
806
+ source?: string
464
807
  /**
465
- * Whether to override existing external files if they already exist.
466
- * @default false
808
+ * The file being processed.
467
809
  */
468
- override?: boolean
810
+ file: FileNode
811
+ /**
812
+ * Kubb configuration.
813
+ * Provides access to the current config during file processing.
814
+ */
815
+ config: Config
469
816
  }
470
817
 
471
- type GroupContext = {
472
- group: string
818
+ export type KubbFilesProcessingEndContext = {
819
+ files: Array<FileNode>
473
820
  }
474
821
 
475
- export type Group = {
822
+ export type KubbPluginStartContext = {
823
+ plugin: Plugin
824
+ }
825
+
826
+ export type KubbPluginEndContext = {
827
+ plugin: Plugin
828
+ duration: number
829
+ success: boolean
830
+ error?: Error
831
+ }
832
+
833
+ export type KubbHookStartContext = {
834
+ id?: string
835
+ command: string
836
+ args?: readonly string[]
837
+ }
838
+
839
+ export type KubbHookEndContext = {
840
+ id?: string
841
+ command: string
842
+ args?: readonly string[]
843
+ success: boolean
844
+ error: Error | null
845
+ }
846
+
847
+ type ByTag = {
848
+ type: 'tag'
849
+ pattern: string | RegExp
850
+ }
851
+
852
+ type ByOperationId = {
853
+ type: 'operationId'
854
+ pattern: string | RegExp
855
+ }
856
+
857
+ type ByPath = {
858
+ type: 'path'
859
+ pattern: string | RegExp
860
+ }
861
+
862
+ type ByMethod = {
863
+ type: 'method'
864
+ pattern: HttpMethod | RegExp
865
+ }
866
+ // TODO implement as alternative for ByMethod
867
+ // type ByMethods = {
868
+ // type: 'methods'
869
+ // pattern: Array<HttpMethod>
870
+ // }
871
+
872
+ type BySchemaName = {
873
+ type: 'schemaName'
874
+ pattern: string | RegExp
875
+ }
876
+
877
+ type ByContentType = {
878
+ type: 'contentType'
879
+ pattern: string | RegExp
880
+ }
881
+
882
+ /**
883
+ * A pattern filter that prevents matching nodes from being generated.
884
+ * Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
885
+ */
886
+ export type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
887
+
888
+ /**
889
+ * A pattern filter that restricts generation to only matching nodes.
890
+ * Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
891
+ */
892
+ export type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
893
+
894
+ /**
895
+ * A pattern filter paired with partial option overrides applied when the pattern matches.
896
+ * Match by `tag`, `operationId`, `path`, `method`, `schemaName`, or `contentType`.
897
+ */
898
+ export type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
899
+ //TODO should be options: Omit<Partial<TOptions>, 'override'>
900
+ options: Partial<TOptions>
901
+ }
902
+
903
+ /**
904
+ * File-specific parameters for `Resolver.resolvePath`.
905
+ *
906
+ * Pass alongside a `ResolverContext` to identify which file to resolve.
907
+ * Provide `tag` for tag-based grouping or `path` for path-based grouping.
908
+ *
909
+ * @example
910
+ * ```ts
911
+ * resolver.resolvePath(
912
+ * { baseName: 'petTypes.ts', tag: 'pets' },
913
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
914
+ * )
915
+ * // → '/src/types/petsController/petTypes.ts'
916
+ * ```
917
+ */
918
+ export type ResolverPathParams = {
919
+ baseName: FileNode['baseName']
920
+ pathMode?: 'single' | 'split'
476
921
  /**
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
922
+ * Tag value used when `group.type === 'tag'`.
481
923
  */
482
- type: 'tag' | 'path'
924
+ tag?: string
483
925
  /**
484
- * Return the name of a group based on the group name, this used for the file and name generation
926
+ * Path value used when `group.type === 'path'`.
485
927
  */
486
- name?: (context: GroupContext) => string
928
+ path?: string
487
929
  }
488
930
 
489
- export type LoggerOptions = {
931
+ /**
932
+ * Shared context passed as the second argument to `Resolver.resolvePath` and `Resolver.resolveFile`.
933
+ *
934
+ * Describes where on disk output is rooted, which output config is active, and the optional
935
+ * grouping strategy that controls subdirectory layout.
936
+ *
937
+ * @example
938
+ * ```ts
939
+ * const context: ResolverContext = {
940
+ * root: config.root,
941
+ * output,
942
+ * group,
943
+ * }
944
+ * ```
945
+ */
946
+ export type ResolverContext = {
947
+ root: string
948
+ output: Output
949
+ group?: Group
490
950
  /**
491
- * @default 3
951
+ * Plugin name used to populate `meta.pluginName` on the resolved file.
492
952
  */
493
- logLevel: (typeof logLevel)[keyof typeof logLevel]
953
+ pluginName?: string
494
954
  }
495
955
 
496
956
  /**
497
- * Shared context passed to all plugins, parsers, and Fabric internals.
957
+ * File-specific parameters for `Resolver.resolveFile`.
958
+ *
959
+ * Pass alongside a `ResolverContext` to fully describe the file to resolve.
960
+ * `tag` and `path` are used only when a matching `group` is present in the context.
961
+ *
962
+ * @example
963
+ * ```ts
964
+ * resolver.resolveFile(
965
+ * { name: 'listPets', extname: '.ts', tag: 'pets' },
966
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
967
+ * )
968
+ * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
969
+ * ```
498
970
  */
499
- export interface LoggerContext extends AsyncEventEmitter<KubbEvents> {}
971
+ export type ResolverFileParams = {
972
+ name: string
973
+ extname: FileNode['extname']
974
+ /**
975
+ * Tag value used when `group.type === 'tag'`.
976
+ */
977
+ tag?: string
978
+ /**
979
+ * Path value used when `group.type === 'path'`.
980
+ */
981
+ path?: string
982
+ }
500
983
 
501
- type Install<TOptions = unknown> = (context: LoggerContext, options?: TOptions) => void | Promise<void>
984
+ /**
985
+ * Context passed to `Resolver.resolveBanner` and `Resolver.resolveFooter`.
986
+ *
987
+ * `output` is optional — not every plugin configures a banner/footer.
988
+ * `config` carries the global Kubb config, used to derive the default Kubb banner.
989
+ *
990
+ * @example
991
+ * ```ts
992
+ * resolver.resolveBanner(inputNode, { output: { banner: '// generated' }, config })
993
+ * // → '// generated'
994
+ * ```
995
+ */
996
+ export type ResolveBannerContext = {
997
+ output?: Pick<Output, 'banner' | 'footer'>
998
+ config: Config
999
+ }
502
1000
 
503
- export type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
504
- name: string
505
- install: Install<TOptions>
1001
+ /**
1002
+ * CLI options derived from command-line flags.
1003
+ */
1004
+ export type CLIOptions = {
1005
+ /**
1006
+ * Path to `kubb.config.js`.
1007
+ */
1008
+ config?: string
1009
+ /**
1010
+ * Enable watch mode for input files.
1011
+ */
1012
+ watch?: boolean
1013
+ /**
1014
+ * Logging verbosity for CLI usage.
1015
+ * @default 'silent'
1016
+ */
1017
+ logLevel?: 'silent' | 'info' | 'debug'
506
1018
  }
507
1019
 
508
- export type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Omit<Logger<TOptions>, 'logLevel'>
1020
+ /**
1021
+ * All accepted forms of a Kubb configuration.
1022
+ *
1023
+ * Config is always `@kubb/core` {@link Config}.
1024
+ * - `PossibleConfig` accepts `Config`/`Config[]`/promise or a no-arg config factory.
1025
+ * - `PossibleConfig<TCliOptions>` accepts the same config forms or a config factory receiving `TCliOptions`.
1026
+ */
1027
+ export type PossibleConfig<TCliOptions = undefined> =
1028
+ | PossiblePromise<Config | Config[]>
1029
+ | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Config[]>)
509
1030
 
510
- export type { CoreGeneratorV2, Generator, ReactGeneratorV2 } from './defineGenerator.ts'
511
- export type { DefineStorage } from './defineStorage.ts'
512
- export type { KubbEvents } from './Kubb.ts'
1031
+ export type { BuildOutput } from './createKubb.ts'
1032
+ export type { Parser } from './defineParser.ts'