@kubb/core 5.0.0-beta.1 → 5.0.0-beta.10

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.
@@ -98,7 +98,7 @@ type PossiblePromise<T> = Promise<T> | T;
98
98
  /**
99
99
  * Base URL for the Kubb Studio web app.
100
100
  */
101
- declare const DEFAULT_STUDIO_URL: "https://studio.kubb.dev";
101
+ declare const DEFAULT_STUDIO_URL: "https://kubb.studio";
102
102
  /**
103
103
  * Numeric log-level thresholds used internally to compare verbosity.
104
104
  *
@@ -113,6 +113,116 @@ declare const logLevel: {
113
113
  readonly debug: 5;
114
114
  };
115
115
  //#endregion
116
+ //#region src/createAdapter.d.ts
117
+ /**
118
+ * Source data passed to an adapter's `parse` function.
119
+ * Mirrors the config input shape with paths resolved to absolute.
120
+ */
121
+ type AdapterSource = {
122
+ type: 'path';
123
+ path: string;
124
+ } | {
125
+ type: 'data';
126
+ data: string | unknown;
127
+ } | {
128
+ type: 'paths';
129
+ paths: Array<string>;
130
+ };
131
+ /**
132
+ * Generic type parameters for an adapter definition.
133
+ *
134
+ * - `TName` — unique identifier (e.g. `'oas'`, `'asyncapi'`)
135
+ * - `TOptions` — user-facing options passed to the adapter factory
136
+ * - `TResolvedOptions` — options after defaults applied
137
+ * - `TDocument` — type of the parsed source document
138
+ */
139
+ type AdapterFactoryOptions<TName extends string = string, TOptions extends object = object, TResolvedOptions extends object = TOptions, TDocument = unknown> = {
140
+ name: TName;
141
+ options: TOptions;
142
+ resolvedOptions: TResolvedOptions;
143
+ document: TDocument;
144
+ };
145
+ /**
146
+ * Adapter that converts input files or data into an `InputNode`.
147
+ *
148
+ * Adapters parse different schema formats (OpenAPI, AsyncAPI, Drizzle, etc.) into Kubb's
149
+ * universal intermediate representation that all plugins consume.
150
+ *
151
+ * @example
152
+ * ```ts
153
+ * import { adapterOas } from '@kubb/adapter-oas'
154
+ *
155
+ * export default defineConfig({
156
+ * adapter: adapterOas(),
157
+ * input: { path: './openapi.yaml' },
158
+ * plugins: [pluginTs(), pluginZod()],
159
+ * })
160
+ * ```
161
+ */
162
+ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
163
+ /**
164
+ * Human-readable adapter identifier (e.g. `'oas'`, `'asyncapi'`).
165
+ */
166
+ name: TOptions['name'];
167
+ /**
168
+ * Resolved adapter options after defaults have been applied.
169
+ */
170
+ options: TOptions['resolvedOptions'];
171
+ /**
172
+ * Parsed source document after the first `parse()` call. `null` before parsing.
173
+ */
174
+ document: TOptions['document'] | null;
175
+ inputNode: InputNode | null;
176
+ /**
177
+ * Parse the source into a universal `InputNode`.
178
+ */
179
+ parse: (source: AdapterSource) => PossiblePromise<InputNode>;
180
+ /**
181
+ * Extract `ImportNode` entries for a schema tree.
182
+ * Returns an empty array before the first `parse()` call.
183
+ *
184
+ * The `resolve` callback receives the collision-corrected schema name and must
185
+ * return `{ name, path }` for the import, or `undefined` to skip it.
186
+ */
187
+ getImports: (node: SchemaNode, resolve: (schemaName: string) => {
188
+ name: string;
189
+ path: string;
190
+ }) => Array<ImportNode>;
191
+ /**
192
+ * Validate the document at the given path or URL.
193
+ */
194
+ validate: (input: string, options?: {
195
+ throwOnError?: boolean;
196
+ }) => Promise<void>;
197
+ };
198
+ type AdapterBuilder<T extends AdapterFactoryOptions> = (options: T['options']) => Adapter<T>;
199
+ /**
200
+ * Factory for implementing custom adapters that translate non-OpenAPI specs into Kubb's AST.
201
+ *
202
+ * Use this to support GraphQL schemas, gRPC definitions, AsyncAPI, or custom domain-specific languages.
203
+ * Built-in adapters include `@kubb/adapter-oas` for OpenAPI and Swagger documents.
204
+ *
205
+ * @note Adapters must parse their input format to Kubb's `InputNode` structure.
206
+ *
207
+ * @example
208
+ * ```ts
209
+ * export const myAdapter = createAdapter<MyAdapter>((options) => {
210
+ * return {
211
+ * name: 'my-adapter',
212
+ * options,
213
+ * async parse(source) {
214
+ * // Transform source format to InputNode
215
+ * return { ... }
216
+ * },
217
+ * }
218
+ * })
219
+ *
220
+ * // Instantiate:
221
+ * const adapter = myAdapter({ validate: true })
222
+ * ```
223
+ */
224
+ declare function createAdapter<T extends AdapterFactoryOptions = AdapterFactoryOptions>(build: AdapterBuilder<T>): (options?: T['options']) => Adapter<T>;
225
+ //#endregion
116
226
  //#region src/createRenderer.d.ts
117
227
  /**
118
228
  * Minimal interface any Kubb renderer must satisfy.
@@ -235,825 +345,1079 @@ type Storage = {
235
345
  */
236
346
  declare function createStorage<TOptions = Record<string, never>>(build: (options: TOptions) => Storage): (options?: TOptions) => Storage;
237
347
  //#endregion
238
- //#region src/defineGenerator.d.ts
348
+ //#region src/devtools.d.ts
349
+ type DevtoolsOptions = {
350
+ /**
351
+ * Open the AST inspector in Kubb Studio (`/ast`). Defaults to the main Studio page.
352
+ * @default false
353
+ */
354
+ ast?: boolean;
355
+ };
356
+ //#endregion
357
+ //#region src/defineLogger.d.ts
358
+ type LoggerOptions = {
359
+ /**
360
+ * Log level for output verbosity.
361
+ * @default 3
362
+ */
363
+ logLevel: (typeof logLevel)[keyof typeof logLevel];
364
+ };
239
365
  /**
240
- * Declares a named generator unit that walks the AST and emits files.
241
- *
242
- * Each method (`schema`, `operation`, `operations`) is called for the matching node type.
243
- * Each method returns `TElement | Array<FileNode> | void`. JSX-based generators require a `renderer` factory.
244
- * Return `Array<FileNode>` directly or call `ctx.upsertFile()` manually and return `void` to bypass rendering.
366
+ * Shared context passed to plugins, parsers, and other internals.
367
+ */
368
+ type LoggerContext = AsyncEventEmitter<KubbHooks>;
369
+ type Logger<TOptions extends LoggerOptions = LoggerOptions, TInstallReturn = void> = {
370
+ name: string;
371
+ install: (context: LoggerContext, options?: TOptions) => TInstallReturn | Promise<TInstallReturn>;
372
+ };
373
+ type UserLogger<TOptions extends LoggerOptions = LoggerOptions, TInstallReturn = void> = Logger<TOptions, TInstallReturn>;
374
+ /**
375
+ * Wraps a logger definition into a typed {@link Logger}.
245
376
  *
246
- * @note Generators are consumed by plugins and registered via `ctx.addGenerator()` in `kubb:plugin:setup`.
377
+ * The optional second type parameter `TInstallReturn` allows loggers to return
378
+ * a value from `install` — for example, a sink factory that the caller can
379
+ * forward to hook execution.
247
380
  *
248
- * @example
381
+ * @example Basic logger
249
382
  * ```ts
250
- * import { defineGenerator } from '@kubb/core'
251
- * import { jsxRenderer } from '@kubb/renderer-jsx'
383
+ * export const myLogger = defineLogger({
384
+ * name: 'my-logger',
385
+ * install(context, options) {
386
+ * context.on('kubb:info', (message) => console.log('ℹ', message))
387
+ * context.on('kubb:error', (error) => console.error('✗', error.message))
388
+ * },
389
+ * })
390
+ * ```
252
391
  *
253
- * export const typeGenerator = defineGenerator({
254
- * name: 'typescript',
255
- * renderer: jsxRenderer,
256
- * schema(node, ctx) {
257
- * const { adapter, resolver, root, options } = ctx
258
- * return <File ...><Type node={node} resolver={resolver} /></File>
392
+ * @example Logger that returns a hook sink factory
393
+ * ```ts
394
+ * export const myLogger = defineLogger<LoggerOptions, HookSinkFactory>({
395
+ * name: 'my-logger',
396
+ * install(context, options) {
397
+ * // register event handlers
398
+ * return (commandWithArgs) => ({ onStdout: console.log })
259
399
  * },
260
400
  * })
261
401
  * ```
262
402
  */
263
- type Generator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown> = {
264
- /**
265
- * Used in diagnostic messages and debug output.
266
- */
267
- name: string;
268
- /**
269
- * Optional renderer factory that produces a {@link Renderer} for each render cycle.
270
- *
271
- * Generators that return renderer elements (e.g. JSX via `@kubb/renderer-jsx`) must set this
272
- * to the matching renderer factory (e.g. `jsxRenderer` from `@kubb/renderer-jsx`).
273
- *
274
- * Generators that only return `Array<FileNode>` or `void` do not need to set this.
275
- *
276
- * Set `renderer: null` to explicitly opt out of rendering even when the parent plugin
277
- * declares a `renderer` (overrides the plugin-level fallback).
278
- *
279
- * @example
280
- * ```ts
281
- * import { jsxRenderer } from '@kubb/renderer-jsx'
282
- * export const myGenerator = defineGenerator<PluginTs>({
283
- * renderer: jsxRenderer,
284
- * schema(node, ctx) { return <File ...>...</File> },
285
- * })
286
- * ```
287
- */
288
- renderer?: RendererFactory<TElement> | null;
289
- /**
290
- * Called for each schema node in the AST walk.
291
- * `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
292
- * plus `ctx.options` with the per-node resolved options (after exclude/include/override).
293
- */
294
- schema?: (node: SchemaNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
295
- /**
296
- * Called for each operation node in the AST walk.
297
- * `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
298
- * plus `ctx.options` with the per-node resolved options (after exclude/include/override).
299
- */
300
- operation?: (node: OperationNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
301
- /**
302
- * Called once after all operations have been walked.
303
- * `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
304
- * plus `ctx.options` with the plugin-level options for the batch call.
305
- */
306
- operations?: (nodes: Array<OperationNode>, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
307
- };
308
- /**
309
- * Defines a generator. Returns the object as-is with correct `this` typings.
310
- * `applyHookResult` handles renderer elements and `File[]` uniformly using
311
- * the generator's declared `renderer` factory.
312
- */
313
- declare function defineGenerator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown>(generator: Generator<TOptions, TElement>): Generator<TOptions, TElement>;
403
+ declare function defineLogger<Options extends LoggerOptions = LoggerOptions, TInstallReturn = void>(logger: UserLogger<Options, TInstallReturn>): Logger<Options, TInstallReturn>;
314
404
  //#endregion
315
- //#region src/definePlugin.d.ts
405
+ //#region src/defineMiddleware.d.ts
316
406
  /**
317
- * A plugin object produced by `definePlugin`.
318
- * Instead of flat lifecycle methods, it groups all handlers under a `hooks:` property
319
- * (matching Astro's integration naming convention).
320
- *
321
- * @template TFactory - The plugin's `PluginFactoryOptions` type.
407
+ * A middleware instance produced by calling a factory created with `defineMiddleware`.
408
+ * It declares event handlers under a `hooks` object which are registered on the
409
+ * shared emitter after all plugin hooks, so middleware handlers for any event
410
+ * always fire last.
322
411
  */
323
- type Plugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
412
+ type Middleware = {
324
413
  /**
325
- * Unique name for the plugin, following the same naming convention as `createPlugin`.
414
+ * Unique identifier for this middleware.
326
415
  */
327
416
  name: string;
328
417
  /**
329
- * Plugins that must be registered before this plugin executes.
330
- * An error is thrown at startup when any listed dependency is missing.
331
- */
332
- dependencies?: Array<string>;
333
- /**
334
- * Controls the execution order of this plugin relative to others.
335
- *
336
- * - `'pre'` — runs before all normal plugins.
337
- * - `'post'` — runs after all normal plugins.
338
- * - `undefined` (default) — runs in declaration order among normal plugins.
339
- *
340
- * Dependency constraints always take precedence over `enforce`.
341
- */
342
- enforce?: 'pre' | 'post';
343
- /**
344
- * The options passed by the user when calling the plugin factory.
345
- */
346
- options?: TFactory['options'];
347
- /**
348
- * Lifecycle event handlers for this plugin.
418
+ * Lifecycle event handlers for this middleware.
349
419
  * Any event from the global `KubbHooks` map can be subscribed to here.
420
+ * Handlers are registered after all plugin handlers, so they always fire last.
350
421
  */
351
- hooks: { [K in Exclude<keyof KubbHooks, 'kubb:plugin:setup'>]?: (...args: KubbHooks[K]) => void | Promise<void> } & {
352
- 'kubb:plugin:setup'?(ctx: KubbPluginSetupContext<TFactory>): void | Promise<void>;
353
- };
422
+ hooks: { [K in keyof KubbHooks]?: (...args: KubbHooks[K]) => void | Promise<void> };
354
423
  };
355
424
  /**
356
- * Wraps a factory function and returns a typed `Plugin` with lifecycle handlers grouped under `hooks`.
425
+ * Creates a middleware factory using the hook-style `hooks` API.
357
426
  *
358
- * Handlers live in a single `hooks` object (inspired by Astro integrations).
359
- * All lifecycle events from `KubbHooks` are available for subscription.
427
+ * Middleware handlers fire after all plugin handlers for any given event, making them ideal for post-processing, logging, and auditing.
428
+ * Per-build state (such as accumulators) belongs inside the factory closure so each `createKubb` invocation gets its own isolated instance.
360
429
  *
361
- * @note For real plugins, use a `PluginFactoryOptions` type parameter to get type-safe context in `kubb:plugin:setup`.
362
- * Plugin names should follow the convention `plugin-<feature>` (e.g., `plugin-react-query`, `plugin-zod`).
430
+ * @note The factory can accept typed options. See examples for using options and per-build state patterns.
363
431
  *
364
432
  * @example
365
433
  * ```ts
366
- * import { definePlugin } from '@kubb/core'
434
+ * import { defineMiddleware } from '@kubb/core'
367
435
  *
368
- * export const pluginTs = definePlugin((options: { prefix?: string } = {}) => ({
369
- * name: 'plugin-ts',
436
+ * // Stateless middleware
437
+ * export const logMiddleware = defineMiddleware(() => ({
438
+ * name: 'log-middleware',
370
439
  * hooks: {
371
- * 'kubb:plugin:setup'(ctx) {
372
- * ctx.setResolver(resolverTs)
440
+ * 'kubb:build:end'({ files }) {
441
+ * console.log(`Build complete with ${files.length} files`)
373
442
  * },
374
443
  * },
375
444
  * }))
376
- * ```
377
- */
378
- declare function definePlugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(factory: (options: TFactory['options']) => Plugin<TFactory>): (options?: TFactory['options']) => Plugin<TFactory>;
379
- //#endregion
380
- //#region src/FileManager.d.ts
381
- /**
382
- * In-memory file store for generated files.
383
- *
384
- * Files with the same `path` are merged — sources, imports, and exports are concatenated.
385
- * The `files` getter returns all stored files sorted by path length (shortest first).
386
445
  *
387
- * @example
388
- * ```ts
389
- * import { FileManager } from '@kubb/core'
390
- *
391
- * const manager = new FileManager()
392
- * manager.upsert(myFile)
393
- * console.log(manager.files) // all stored files
446
+ * // Middleware with options and per-build state
447
+ * export const prefixMiddleware = defineMiddleware((options: { prefix: string } = { prefix: '' }) => {
448
+ * const seen = new Set<string>()
449
+ * return {
450
+ * name: 'prefix-middleware',
451
+ * hooks: {
452
+ * 'kubb:plugin:end'({ plugin }) {
453
+ * seen.add(`${options.prefix}${plugin.name}`)
454
+ * },
455
+ * },
456
+ * }
457
+ * })
394
458
  * ```
395
459
  */
396
- declare class FileManager {
397
- #private;
398
- /**
399
- * Adds one or more files. Incoming files with the same path are merged
400
- * (sources/imports/exports concatenated), but existing cache entries are
401
- * replaced — use {@link upsert} when you want to merge into the cache too.
402
- */
403
- add(...files: Array<FileNode>): Array<FileNode>;
460
+ declare function defineMiddleware<TOptions extends object = object>(factory: (options: TOptions) => Middleware): (options?: TOptions) => Middleware;
461
+ //#endregion
462
+ //#region src/defineParser.d.ts
463
+ type PrintOptions = {
464
+ extname?: FileNode['extname'];
465
+ };
466
+ type Parser<TMeta extends object = any> = {
467
+ name: string;
404
468
  /**
405
- * Adds or merges one or more files.
406
- * If a file with the same path already exists in the cache, its
407
- * sources/imports/exports are merged into the incoming file.
469
+ * File extensions this parser handles.
470
+ * Use `undefined` to create a catch-all fallback parser.
471
+ *
472
+ * @example Handled extensions
473
+ * `['.ts', '.js']`
408
474
  */
409
- upsert(...files: Array<FileNode>): Array<FileNode>;
410
- getByPath(path: string): FileNode | null;
411
- deleteByPath(path: string): void;
412
- clear(): void;
475
+ extNames: Array<FileNode['extname']> | undefined;
413
476
  /**
414
- * All stored files, sorted by path length (shorter paths first).
477
+ * Convert a resolved file to a string.
415
478
  */
416
- get files(): Array<FileNode>;
417
- }
479
+ parse(file: FileNode<TMeta>, options?: PrintOptions): Promise<string> | string;
480
+ };
481
+ /**
482
+ * Defines a parser with type safety. Creates parsers that transform generated files to strings based on their extension.
483
+ *
484
+ * @note Call the returned factory with optional options to instantiate the parser.
485
+ *
486
+ * @example
487
+ * ```ts
488
+ * import { defineParser } from '@kubb/core'
489
+ *
490
+ * export const jsonParser = defineParser({
491
+ * name: 'json',
492
+ * extNames: ['.json'],
493
+ * parse(file) {
494
+ * const { extractStringsFromNodes } = await import('@kubb/ast')
495
+ * return file.sources.map((s) => extractStringsFromNodes(s.nodes ?? [])).join('\n')
496
+ * },
497
+ * })
498
+ * ```
499
+ */
500
+ declare function defineParser<TMeta extends object = any>(parser: Parser<TMeta>): Parser<TMeta>;
418
501
  //#endregion
419
- //#region src/PluginDriver.d.ts
420
- type Options = {
421
- hooks: AsyncEventEmitter<KubbHooks>;
502
+ //#region src/defineResolver.d.ts
503
+ /**
504
+ * Type/string pattern filter for include/exclude/override matching.
505
+ */
506
+ type PatternFilter = {
507
+ type: string;
508
+ pattern: string | RegExp;
422
509
  };
423
- declare class PluginDriver {
424
- #private;
425
- readonly config: Config;
426
- readonly options: Options;
510
+ /**
511
+ * Pattern filter with partial option overrides applied when the pattern matches.
512
+ */
513
+ type PatternOverride<TOptions> = PatternFilter & {
514
+ options: Omit<Partial<TOptions>, 'override'>;
515
+ };
516
+ /**
517
+ * Context for resolving filtered options for a given operation or schema node.
518
+ *
519
+ * @internal
520
+ */
521
+ type ResolveOptionsContext<TOptions> = {
522
+ options: TOptions;
523
+ exclude?: Array<PatternFilter>;
524
+ include?: Array<PatternFilter>;
525
+ override?: Array<PatternOverride<TOptions>>;
526
+ };
527
+ /**
528
+ * Base constraint for all plugin resolver objects.
529
+ *
530
+ * `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`
531
+ * are injected automatically by `defineResolver` — extend this type to add custom resolution methods.
532
+ *
533
+ * @example
534
+ * ```ts
535
+ * type MyResolver = Resolver & {
536
+ * resolveName(node: SchemaNode): string
537
+ * resolveTypedName(node: SchemaNode): string
538
+ * }
539
+ * ```
540
+ */
541
+ type Resolver = {
542
+ name: string;
543
+ pluginName: string;
544
+ default(name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
545
+ resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null;
546
+ resolvePath(params: ResolverPathParams, context: ResolverContext): string;
547
+ resolveFile(params: ResolverFileParams, context: ResolverContext): FileNode;
548
+ resolveBanner(node: InputNode | null, context: ResolveBannerContext): string | undefined;
549
+ resolveFooter(node: InputNode | null, context: ResolveBannerContext): string | undefined;
550
+ };
551
+ /**
552
+ * File-specific parameters for `Resolver.resolvePath`.
553
+ *
554
+ * Pass alongside a `ResolverContext` to identify which file to resolve.
555
+ * Provide `tag` for tag-based grouping or `path` for path-based grouping.
556
+ *
557
+ * @example
558
+ * ```ts
559
+ * resolver.resolvePath(
560
+ * { baseName: 'petTypes.ts', tag: 'pets' },
561
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
562
+ * )
563
+ * // → '/src/types/petsController/petTypes.ts'
564
+ * ```
565
+ */
566
+ type ResolverPathParams = {
567
+ baseName: FileNode['baseName'];
568
+ pathMode?: 'single' | 'split';
427
569
  /**
428
- * Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.
429
- *
430
- * @example
431
- * ```ts
432
- * PluginDriver.getMode('src/gen/types.ts') // 'single'
433
- * PluginDriver.getMode('src/gen/types') // 'split'
434
- * ```
570
+ * Tag value used when `group.type === 'tag'`.
435
571
  */
436
- static getMode(fileOrFolder: string | undefined | null): 'single' | 'split';
572
+ tag?: string;
437
573
  /**
438
- * The universal `@kubb/ast` `InputNode` produced by the adapter, set by
439
- * the build pipeline after the adapter's `parse()` resolves.
574
+ * Path value used when `group.type === 'path'`.
440
575
  */
441
- inputNode: InputNode | undefined;
442
- adapter: Adapter | undefined;
576
+ path?: string;
577
+ };
578
+ /**
579
+ * Shared context passed as the second argument to `Resolver.resolvePath` and `Resolver.resolveFile`.
580
+ *
581
+ * Describes where on disk output is rooted, which output config is active, and the optional
582
+ * grouping strategy that controls subdirectory layout.
583
+ *
584
+ * @example
585
+ * ```ts
586
+ * const context: ResolverContext = {
587
+ * root: config.root,
588
+ * output,
589
+ * group,
590
+ * }
591
+ * ```
592
+ */
593
+ type ResolverContext = {
594
+ root: string;
595
+ output: Output;
596
+ group?: Group;
443
597
  /**
444
- * Central file store for all generated files.
445
- * Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to
446
- * add files; this property gives direct read/write access when needed.
598
+ * Plugin name used to populate `meta.pluginName` on the resolved file.
447
599
  */
448
- readonly fileManager: FileManager;
449
- readonly plugins: Map<string, NormalizedPlugin>;
450
- constructor(config: Config, options: Options);
451
- get hooks(): AsyncEventEmitter<KubbHooks>;
600
+ pluginName?: string;
601
+ };
602
+ /**
603
+ * File-specific parameters for `Resolver.resolveFile`.
604
+ *
605
+ * Pass alongside a `ResolverContext` to fully describe the file to resolve.
606
+ * `tag` and `path` are used only when a matching `group` is present in the context.
607
+ *
608
+ * @example
609
+ * ```ts
610
+ * resolver.resolveFile(
611
+ * { name: 'listPets', extname: '.ts', tag: 'pets' },
612
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
613
+ * )
614
+ * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
615
+ * ```
616
+ */
617
+ type ResolverFileParams = {
618
+ name: string;
619
+ extname: FileNode['extname'];
452
620
  /**
453
- * Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.
454
- *
455
- * For `kubb:plugin:setup`, the registered listener wraps the globally emitted context with a
456
- * plugin-specific one so that `addGenerator`, `setResolver`, `setTransformer`, and
457
- * `setRenderer` all target the correct `normalizedPlugin` entry in the plugins map.
458
- *
459
- * All other hooks are iterated and registered directly as pass-through listeners.
460
- * Any event key present in the global `KubbHooks` interface can be subscribed to.
461
- *
462
- * External tooling can subscribe to any of these events via `hooks.on(...)` to observe
463
- * the plugin lifecycle without modifying plugin behavior.
464
- *
465
- * @internal
621
+ * Tag value used when `group.type === 'tag'`.
466
622
  */
467
- registerPluginHooks(hookPlugin: Plugin, normalizedPlugin: NormalizedPlugin): void;
623
+ tag?: string;
468
624
  /**
469
- * Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners
470
- * can configure generators, resolvers, transformers and renderers before `buildStart` runs.
471
- *
472
- * Call this once from `safeBuild` before the plugin execution loop begins.
625
+ * Path value used when `group.type === 'path'`.
473
626
  */
474
- emitSetupHooks(): Promise<void>;
627
+ path?: string;
628
+ };
629
+ /**
630
+ * Context passed to `Resolver.resolveBanner` and `Resolver.resolveFooter`.
631
+ *
632
+ * `output` is optional — not every plugin configures a banner/footer.
633
+ * `config` carries the global Kubb config, used to derive the default Kubb banner.
634
+ *
635
+ * @example
636
+ * ```ts
637
+ * resolver.resolveBanner(inputNode, { output: { banner: '// generated' }, config })
638
+ * // → '// generated'
639
+ * ```
640
+ */
641
+ type ResolveBannerContext = {
642
+ output?: Pick<Output, 'banner' | 'footer'>;
643
+ config: Config;
644
+ };
645
+ /**
646
+ * Builder type for the plugin-specific resolver fields.
647
+ *
648
+ * `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`
649
+ * are optional — built-in fallbacks are injected when omitted.
650
+ *
651
+ * Methods in the returned object can call sibling resolver methods via `this`.
652
+ */
653
+ type ResolverBuilder<T extends PluginFactoryOptions> = () => Omit<T['resolver'], 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter' | 'name' | 'pluginName'> & Partial<Pick<T['resolver'], 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>> & {
654
+ name: string;
655
+ pluginName: T['name'];
656
+ } & ThisType<T['resolver']>;
657
+ /**
658
+ * Default option resolver — applies include/exclude filters and merges matching override options.
659
+ *
660
+ * Returns `null` when the node is filtered out by an `exclude` rule or not matched by any `include` rule.
661
+ *
662
+ * @example Include/exclude filtering
663
+ * ```ts
664
+ * const options = defaultResolveOptions(operationNode, {
665
+ * options: { output: 'types' },
666
+ * exclude: [{ type: 'tag', pattern: 'internal' }],
667
+ * })
668
+ * // → null when node has tag 'internal'
669
+ * ```
670
+ *
671
+ * @example Override merging
672
+ * ```ts
673
+ * const options = defaultResolveOptions(operationNode, {
674
+ * options: { enumType: 'asConst' },
675
+ * override: [{ type: 'operationId', pattern: 'listPets', options: { enumType: 'enum' } }],
676
+ * })
677
+ * // → { enumType: 'enum' } when operationId matches
678
+ * ```
679
+ */
680
+ /**
681
+ * Defines a resolver for a plugin, injecting built-in defaults for name casing,
682
+ * include/exclude/override filtering, path resolution, and file construction.
683
+ *
684
+ * All four defaults can be overridden by providing them in the builder function:
685
+ * - `default` — name casing strategy (camelCase / PascalCase)
686
+ * - `resolveOptions` — include/exclude/override filtering
687
+ * - `resolvePath` — output path computation
688
+ * - `resolveFile` — full `FileNode` construction
689
+ *
690
+ * Methods in the returned object can call sibling resolver methods via `this`.
691
+ *
692
+ * @example Basic resolver with naming helpers
693
+ * ```ts
694
+ * export const resolver = defineResolver<PluginTs>(() => ({
695
+ * name: 'default',
696
+ * resolveName(node) {
697
+ * return this.default(node.name, 'function')
698
+ * },
699
+ * resolveTypedName(node) {
700
+ * return this.default(node.name, 'type')
701
+ * },
702
+ * }))
703
+ * ```
704
+ *
705
+ * @example Override resolvePath for a custom output structure
706
+ * ```ts
707
+ * export const resolver = defineResolver<PluginTs>(() => ({
708
+ * name: 'custom',
709
+ * resolvePath({ baseName }, { root, output }) {
710
+ * return path.resolve(root, output.path, 'generated', baseName)
711
+ * },
712
+ * }))
713
+ * ```
714
+ *
715
+ * @example Use this.default inside a helper
716
+ * ```ts
717
+ * export const resolver = defineResolver<PluginTs>(() => ({
718
+ * name: 'default',
719
+ * resolveParamName(node, param) {
720
+ * return this.default(`${node.operationId} ${param.in} ${param.name}`, 'type')
721
+ * },
722
+ * }))
723
+ * ```
724
+ */
725
+ declare function defineResolver<T extends PluginFactoryOptions>(build: ResolverBuilder<T>): T['resolver'];
726
+ //#endregion
727
+ //#region src/definePlugin.d.ts
728
+ /**
729
+ * Safely extracts a type from a registry, returning `{}` if the key doesn't exist.
730
+ * Enables optional interface augmentation for `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry`
731
+ * without requiring changes to core.
732
+ *
733
+ * @internal
734
+ */
735
+ type ExtractRegistryKey$1<T, K extends PropertyKey> = K extends keyof T ? T[K] : {};
736
+ /**
737
+ * Output configuration for generated files.
738
+ */
739
+ type Output<_TOptions = unknown> = {
475
740
  /**
476
- * Registers a generator for the given plugin on the shared event emitter.
477
- *
478
- * The generator's `schema`, `operation`, and `operations` methods are registered as
479
- * listeners on `kubb:generate:schema`, `kubb:generate:operation`, and `kubb:generate:operations`
480
- * respectively. Each listener is scoped to the owning plugin via a `ctx.plugin.name` check
481
- * so that generators from different plugins do not cross-fire.
482
- *
483
- * The renderer resolution chain is: `generator.renderer → plugin.renderer → config.renderer`.
484
- * Set `generator.renderer = null` to explicitly opt out of rendering even when the plugin
485
- * declares a renderer.
486
- *
487
- * Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.
741
+ * Output folder or file path for generated code.
488
742
  */
489
- registerGenerator(pluginName: string, gen: Generator): void;
743
+ path: string;
490
744
  /**
491
- * Returns `true` when at least one generator was registered for the given plugin
492
- * via `addGenerator()` in `kubb:plugin:setup` (event-based path).
493
- *
494
- * Used by the build loop to decide whether to walk the AST and emit generator events
495
- * for a plugin that has no static `plugin.generators`.
745
+ * Text or function prepended to every generated file.
746
+ * When a function, receives the current `InputNode` and returns a string.
496
747
  */
497
- hasRegisteredGenerators(pluginName: string): boolean;
748
+ banner?: string | ((node?: InputNode) => string);
498
749
  /**
499
- * Unregisters all plugin lifecycle listeners from the shared event emitter.
500
- * Called at the end of a build to prevent listener leaks across repeated builds.
501
- *
502
- * @internal
750
+ * Text or function appended to every generated file.
751
+ * When a function, receives the current `InputNode` and returns a string.
503
752
  */
504
- dispose(): void;
753
+ footer?: string | ((node?: InputNode) => string);
505
754
  /**
506
- * Merges `partial` with the plugin's default resolver and stores the result.
507
- * Also mirrors it onto `plugin.resolver` so callers using `getPlugin(name).resolver`
508
- * get the up-to-date resolver without going through `getResolver()`.
755
+ * Whether to override existing external files if they already exist.
756
+ * @default false
509
757
  */
510
- setPluginResolver(pluginName: string, partial: Partial<Resolver>): void;
758
+ override?: boolean;
759
+ } & ExtractRegistryKey$1<Kubb.PluginOptionsRegistry, 'output'>;
760
+ type Group = {
511
761
  /**
512
- * Returns the resolver for the given plugin.
513
- *
514
- * Resolution order: dynamic resolver set via `setPluginResolver` static resolver on the
515
- * plugin → lazily created default resolver (identity name, no path transforms).
762
+ * How to group files into subdirectories.
763
+ * - `'tag'` — group by OpenAPI tags
764
+ * - `'path'` group by OpenAPI paths
516
765
  */
517
- getResolver<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Kubb.PluginRegistry[TName]['resolver'];
518
- getResolver<TResolver extends Resolver = Resolver>(pluginName: string): TResolver;
519
- getContext<TOptions extends PluginFactoryOptions>(plugin: NormalizedPlugin<TOptions>): GeneratorContext<TOptions> & Record<string, unknown>;
520
- getPlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
521
- getPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions> | undefined;
766
+ type: 'tag' | 'path';
522
767
  /**
523
- * Like `getPlugin` but throws a descriptive error when the plugin is not found.
768
+ * Function that returns the subdirectory name for a group value.
769
+ * Defaults to `${camelCase(group)}Controller` for tags, first path segment for paths.
524
770
  */
525
- requirePlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]>;
526
- requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>;
527
- }
528
- //#endregion
529
- //#region src/createKubb.d.ts
530
- /**
531
- * Full output produced by a successful or failed build.
532
- */
533
- type BuildOutput = {
771
+ name?: (context: {
772
+ group: string;
773
+ }) => string;
774
+ };
775
+ type ByTag = {
534
776
  /**
535
- * Plugins that threw during installation, paired with the caught error.
777
+ * Filter by OpenAPI `tags` field. Matches one or more tags assigned to operations.
536
778
  */
537
- failedPlugins: Set<{
538
- plugin: Plugin;
539
- error: Error;
540
- }>;
541
- files: Array<FileNode>;
542
- driver: PluginDriver;
779
+ type: 'tag';
543
780
  /**
544
- * Elapsed time in milliseconds for each plugin, keyed by plugin name.
781
+ * Tag name to match (case-sensitive). Can be a literal string or regex pattern.
782
+ */
783
+ pattern: string | RegExp;
784
+ };
785
+ type ByOperationId = {
786
+ /**
787
+ * Filter by OpenAPI `operationId` field. Each operation (GET, POST, etc.) has a unique identifier.
545
788
  */
546
- pluginTimings: Map<string, number>;
547
- error?: Error;
789
+ type: 'operationId';
548
790
  /**
549
- * Raw generated source, keyed by absolute file path.
791
+ * Operation ID to match (case-sensitive). Can be a literal string or regex pattern.
550
792
  */
551
- sources: Map<string, string>;
552
- };
553
- type CreateKubbOptions = {
554
- hooks?: AsyncEventEmitter<KubbHooks>;
793
+ pattern: string | RegExp;
555
794
  };
556
- /**
557
- * Creates a Kubb instance bound to a single config entry.
558
- *
559
- * Accepts a user-facing config shape and resolves it to a full {@link Config} during
560
- * `setup()`. The instance then holds shared state (`hooks`, `sources`, `driver`, `config`)
561
- * across the `setup → build` lifecycle. Attach event listeners to `kubb.hooks` before
562
- * calling `setup()` or `build()`.
563
- *
564
- * @example
565
- * ```ts
566
- * const kubb = createKubb(userConfig)
567
- *
568
- * kubb.hooks.on('kubb:plugin:end', ({ plugin, duration }) => {
569
- * console.log(`${plugin.name} completed in ${duration}ms`)
570
- * })
571
- *
572
- * const { files, failedPlugins } = await kubb.safeBuild()
573
- * ```
574
- */
575
- declare function createKubb(userConfig: UserConfig, options?: CreateKubbOptions): Kubb$1;
576
- //#endregion
577
- //#region src/Kubb.d.ts
578
- /**
579
- * Kubb code generation instance returned by {@link createKubb}.
580
- *
581
- * Use this when orchestrating multiple builds, inspecting plugin timings, or integrating Kubb into a larger toolchain.
582
- * For a single one-off build, chain directly: `await createKubb(config).build()`.
583
- */
584
- type Kubb$1 = {
795
+ type ByPath = {
585
796
  /**
586
- * Shared event emitter for lifecycle and status events. Attach listeners before calling `setup()` or `build()`.
797
+ * Filter by OpenAPI `path` (URL endpoint). Useful to group or filter by service segments like `/pets`, `/users`, etc.
587
798
  */
588
- readonly hooks: AsyncEventEmitter<KubbHooks>;
799
+ type: 'path';
589
800
  /**
590
- * Generated source code keyed by absolute file path. Available after `build()` or `safeBuild()` completes.
801
+ * URL path to match (case-sensitive). Can be a literal string or regex pattern. Matches against the full path.
591
802
  */
592
- readonly sources: Map<string, string>;
803
+ pattern: string | RegExp;
804
+ };
805
+ type ByMethod = {
593
806
  /**
594
- * Plugin driver managing all plugins. Available after `setup()` completes.
807
+ * Filter by HTTP method: `'get'`, `'post'`, `'put'`, `'delete'`, `'patch'`, `'head'`, `'options'`.
595
808
  */
596
- readonly driver: PluginDriver | undefined;
809
+ type: 'method';
597
810
  /**
598
- * Resolved configuration with defaults applied. Available after `setup()` completes.
811
+ * HTTP method to match (case-insensitive when using string, or regex for dynamic matching).
599
812
  */
600
- readonly config: Config | undefined;
813
+ pattern: HttpMethod | RegExp;
814
+ };
815
+ type BySchemaName = {
601
816
  /**
602
- * Resolves config and initializes the driver. `build()` calls this automatically.
817
+ * Filter by schema component name (TypeScript or JSON schema). Matches schemas in `#/components/schemas`.
603
818
  */
604
- setup(): Promise<void>;
819
+ type: 'schemaName';
605
820
  /**
606
- * Runs the full pipeline and throws on any plugin error. Automatically calls `setup()` if needed.
821
+ * Schema name to match (case-sensitive). Can be a literal string or regex pattern.
607
822
  */
608
- build(): Promise<BuildOutput>;
823
+ pattern: string | RegExp;
824
+ };
825
+ type ByContentType = {
609
826
  /**
610
- * Runs the full pipeline and captures errors in `BuildOutput` instead of throwing. Automatically calls `setup()` if needed.
827
+ * Filter by response or request content type: `'application/json'`, `'application/xml'`, etc.
611
828
  */
612
- safeBuild(): Promise<BuildOutput>;
829
+ type: 'contentType';
830
+ /**
831
+ * Content type to match (case-sensitive). Can be a literal string or regex pattern.
832
+ */
833
+ pattern: string | RegExp;
613
834
  };
614
835
  /**
615
- * Lifecycle events emitted during Kubb code generation.
616
- * Use these for logging, progress tracking, and custom integrations.
836
+ * A pattern filter that prevents matching nodes from being generated.
837
+ *
838
+ * Use to skip code generation for specific operations or schemas. For example, exclude deprecated endpoints
839
+ * or internal-only schemas. Can filter by tag, operationId, path, HTTP method, content type, or schema name.
617
840
  *
618
841
  * @example
619
- * ```typescript
620
- * import type { AsyncEventEmitter } from '@internals/utils'
621
- * import type { KubbHooks } from '@kubb/core'
842
+ * ```ts
843
+ * exclude: [
844
+ * { type: 'tag', pattern: 'internal' }, // skip "internal" tag
845
+ * { type: 'path', pattern: /^\/admin/ }, // skip all /admin endpoints
846
+ * { type: 'operationId', pattern: 'deprecated_*' } // skip operationIds matching pattern
847
+ * ]
848
+ * ```
849
+ */
850
+ type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
851
+ /**
852
+ * A pattern filter that restricts generation to only matching nodes.
622
853
  *
623
- * const hooks: AsyncEventEmitter<KubbHooks> = new AsyncEventEmitter()
854
+ * Use to generate code for a subset of operations or schemas. For example, only generate for a specific service
855
+ * tag or only for "production" endpoints. Can filter by tag, operationId, path, HTTP method, content type, or schema name.
624
856
  *
625
- * hooks.on('kubb:lifecycle:start', () => {
626
- * console.log('Starting Kubb generation')
627
- * })
857
+ * @example
858
+ * ```ts
859
+ * include: [
860
+ * { type: 'tag', pattern: 'public' }, // generate only "public" tag
861
+ * { type: 'path', pattern: /^\/api\/v1/ }, // generate only v1 endpoints
862
+ * ]
863
+ * ```
864
+ */
865
+ type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
866
+ /**
867
+ * A pattern filter paired with partial option overrides applied when the pattern matches.
628
868
  *
629
- * hooks.on('kubb:plugin:end', ({ plugin, duration }) => {
630
- * console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
631
- * })
869
+ * Use to customize generation for specific operations or schemas. For example, apply different output paths
870
+ * for different tags, or use custom resolver functions per operation. Can filter by tag, operationId, path,
871
+ * HTTP method, schema name, or content type.
872
+ *
873
+ * @example
874
+ * ```ts
875
+ * override: [
876
+ * {
877
+ * type: 'tag',
878
+ * pattern: 'admin',
879
+ * options: { output: { path: './src/gen/admin' } } // admin APIs go to separate folder
880
+ * },
881
+ * {
882
+ * type: 'operationId',
883
+ * pattern: 'listPets',
884
+ * options: { exclude: true } // skip this specific operation
885
+ * }
886
+ * ]
632
887
  * ```
633
888
  */
634
- interface KubbHooks {
635
- /**
636
- * Fires at the start of the Kubb lifecycle, before code generation begins.
637
- */
638
- 'kubb:lifecycle:start': [ctx: KubbLifecycleStartContext];
639
- /**
640
- * Fires at the end of the Kubb lifecycle, after all code generation completes.
641
- */
642
- 'kubb:lifecycle:end': [];
643
- /**
644
- * Fires when configuration loading starts.
645
- */
646
- 'kubb:config:start': [];
889
+ type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
890
+ options: Partial<TOptions>;
891
+ };
892
+ type PluginFactoryOptions<
893
+ /**
894
+ * Unique plugin name.
895
+ */
896
+ TName extends string = string,
897
+ /**
898
+ * User-facing plugin options.
899
+ */
900
+ TOptions extends object = object,
901
+ /**
902
+ * Plugin options after defaults are applied.
903
+ */
904
+ TResolvedOptions extends object = TOptions,
905
+ /**
906
+ * Resolver that encapsulates naming and path-resolution helpers.
907
+ * Define with `defineResolver` and export alongside the plugin.
908
+ */
909
+ TResolver extends Resolver = Resolver> = {
910
+ name: TName;
911
+ options: TOptions;
912
+ resolvedOptions: TResolvedOptions;
913
+ resolver: TResolver;
914
+ };
915
+ /**
916
+ * Context for hook-style plugin `kubb:plugin:setup` handler.
917
+ * Provides methods to register generators, configure resolvers, transformers, and renderers.
918
+ */
919
+ type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
647
920
  /**
648
- * Fires when configuration loading completes.
921
+ * Register a generator dynamically. Generators fire during the AST walk (schema/operation/operations)
922
+ * just like generators declared statically on `createPlugin`.
649
923
  */
650
- 'kubb:config:end': [ctx: KubbConfigEndContext];
924
+ addGenerator<TElement = unknown>(generator: Generator<TFactory, TElement>): void;
651
925
  /**
652
- * Fires when code generation starts.
926
+ * Set or override the resolver for this plugin.
927
+ * The resolver controls file naming and path resolution.
653
928
  */
654
- 'kubb:generation:start': [ctx: KubbGenerationStartContext];
929
+ setResolver(resolver: Partial<TFactory['resolver']>): void;
655
930
  /**
656
- * Fires when code generation completes.
931
+ * Set the AST transformer to pre-process nodes before they reach generators.
657
932
  */
658
- 'kubb:generation:end': [ctx: KubbGenerationEndContext];
933
+ setTransformer(visitor: Visitor): void;
659
934
  /**
660
- * Fires with a generation summary including summary lines, title, and success status.
935
+ * Set the renderer factory to process JSX elements from generators.
661
936
  */
662
- 'kubb:generation:summary': [ctx: KubbGenerationSummaryContext];
937
+ setRenderer(renderer: RendererFactory): void;
663
938
  /**
664
- * Fires when code formatting starts (e.g., Biome or Prettier).
939
+ * Set resolved options merged into the normalized plugin's `options`.
940
+ * Call this in `kubb:plugin:setup` to provide options generators need.
665
941
  */
666
- 'kubb:format:start': [];
942
+ setOptions(options: TFactory['resolvedOptions']): void;
667
943
  /**
668
- * Fires when code formatting completes.
944
+ * Inject a raw file into the build output, bypassing the generation pipeline.
669
945
  */
670
- 'kubb:format:end': [];
946
+ injectFile(userFileNode: UserFileNode): void;
671
947
  /**
672
- * Fires when linting starts.
948
+ * Merge a partial config update into the current build configuration.
673
949
  */
674
- 'kubb:lint:start': [];
950
+ updateConfig(config: Partial<Config>): void;
675
951
  /**
676
- * Fires when linting completes.
952
+ * The resolved build configuration at setup time.
677
953
  */
678
- 'kubb:lint:end': [];
954
+ config: Config;
679
955
  /**
680
- * Fires when plugin hooks execution starts.
956
+ * The plugin's user-provided options.
681
957
  */
682
- 'kubb:hooks:start': [];
958
+ options: TFactory['options'];
959
+ };
960
+ /**
961
+ * A plugin object produced by `definePlugin`.
962
+ * Instead of flat lifecycle methods, it groups all handlers under a `hooks:` property
963
+ * (matching Astro's integration naming convention).
964
+ *
965
+ * @template TFactory - The plugin's `PluginFactoryOptions` type.
966
+ */
967
+ type Plugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
683
968
  /**
684
- * Fires when plugin hooks execution completes.
969
+ * Unique name for the plugin, following the same naming convention as `createPlugin`.
685
970
  */
686
- 'kubb:hooks:end': [];
971
+ name: string;
687
972
  /**
688
- * Fires when a single hook executes (e.g., format or lint). The callback is invoked when the command finishes.
973
+ * Plugins that must be registered before this plugin executes.
974
+ * An error is thrown at startup when any listed dependency is missing.
689
975
  */
690
- 'kubb:hook:start': [ctx: KubbHookStartContext];
976
+ dependencies?: Array<string>;
691
977
  /**
692
- * Fires when a single hook execution completes.
978
+ * Controls the execution order of this plugin relative to others.
979
+ *
980
+ * - `'pre'` — runs before all normal plugins.
981
+ * - `'post'` — runs after all normal plugins.
982
+ * - `undefined` (default) — runs in declaration order among normal plugins.
983
+ *
984
+ * Dependency constraints always take precedence over `enforce`.
693
985
  */
694
- 'kubb:hook:end': [ctx: KubbHookEndContext];
986
+ enforce?: 'pre' | 'post';
695
987
  /**
696
- * Fires when a new Kubb version is available.
988
+ * The options passed by the user when calling the plugin factory.
697
989
  */
698
- 'kubb:version:new': [ctx: KubbVersionNewContext];
990
+ options?: TFactory['options'];
699
991
  /**
700
- * Informational message event.
992
+ * Lifecycle event handlers for this plugin.
993
+ * Any event from the global `KubbHooks` map can be subscribed to here.
701
994
  */
702
- 'kubb:info': [ctx: KubbInfoContext];
995
+ hooks: { [K in keyof KubbHooks as K extends 'kubb:plugin:setup' ? never : K]?: (...args: KubbHooks[K]) => void | Promise<void> } & {
996
+ 'kubb:plugin:setup'?(ctx: KubbPluginSetupContext<TFactory>): void | Promise<void>;
997
+ };
998
+ };
999
+ /**
1000
+ * Normalized plugin after setup, with runtime fields populated.
1001
+ * For internal use only — plugins use the public `Plugin` type externally.
1002
+ *
1003
+ * @internal
1004
+ */
1005
+ type NormalizedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & {
1006
+ options: TOptions['resolvedOptions'] & {
1007
+ output: Output;
1008
+ include?: Array<Include>;
1009
+ exclude: Array<Exclude>;
1010
+ override: Array<Override<TOptions['resolvedOptions']>>;
1011
+ };
1012
+ resolver: TOptions['resolver'];
1013
+ transformer?: Visitor;
1014
+ renderer?: RendererFactory;
1015
+ generators?: Array<Generator>;
1016
+ apply?: (config: Config) => boolean;
1017
+ version?: string;
1018
+ };
1019
+ type KubbPluginStartContext = {
1020
+ plugin: NormalizedPlugin;
1021
+ };
1022
+ type KubbPluginEndContext = {
1023
+ plugin: NormalizedPlugin;
1024
+ duration: number;
1025
+ success: boolean;
1026
+ error?: Error;
1027
+ config: Config;
703
1028
  /**
704
- * Error event, fired when an error occurs during generation.
1029
+ * Returns all files currently in the file manager (lazy snapshot).
1030
+ * Includes files added by plugins that have already run.
705
1031
  */
706
- 'kubb:error': [ctx: KubbErrorContext];
1032
+ readonly files: ReadonlyArray<FileNode>;
707
1033
  /**
708
- * Success message event.
1034
+ * Upsert one or more files into the file manager.
709
1035
  */
710
- 'kubb:success': [ctx: KubbSuccessContext];
1036
+ upsertFile: (...files: Array<FileNode>) => void;
1037
+ };
1038
+ /**
1039
+ * Wraps a factory function and returns a typed `Plugin` with lifecycle handlers grouped under `hooks`.
1040
+ *
1041
+ * Handlers live in a single `hooks` object (inspired by Astro integrations).
1042
+ * All lifecycle events from `KubbHooks` are available for subscription.
1043
+ *
1044
+ * @note For real plugins, use a `PluginFactoryOptions` type parameter to get type-safe context in `kubb:plugin:setup`.
1045
+ * Plugin names should follow the convention `plugin-<feature>` (e.g., `plugin-react-query`, `plugin-zod`).
1046
+ *
1047
+ * @example
1048
+ * ```ts
1049
+ * import { definePlugin } from '@kubb/core'
1050
+ *
1051
+ * export const pluginTs = definePlugin((options: { prefix?: string } = {}) => ({
1052
+ * name: 'plugin-ts',
1053
+ * hooks: {
1054
+ * 'kubb:plugin:setup'(ctx) {
1055
+ * ctx.setResolver(resolverTs)
1056
+ * },
1057
+ * },
1058
+ * }))
1059
+ * ```
1060
+ */
1061
+ declare function definePlugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(factory: (options: TFactory['options']) => Plugin<TFactory>): (options?: TFactory['options']) => Plugin<TFactory>;
1062
+ //#endregion
1063
+ //#region src/FileManager.d.ts
1064
+ /**
1065
+ * In-memory file store for generated files.
1066
+ *
1067
+ * Files with the same `path` are merged — sources, imports, and exports are concatenated.
1068
+ * The `files` getter returns all stored files sorted by path length (shortest first).
1069
+ *
1070
+ * @example
1071
+ * ```ts
1072
+ * import { FileManager } from '@kubb/core'
1073
+ *
1074
+ * const manager = new FileManager()
1075
+ * manager.upsert(myFile)
1076
+ * console.log(manager.files) // all stored files
1077
+ * ```
1078
+ */
1079
+ declare class FileManager {
1080
+ #private;
711
1081
  /**
712
- * Warning message event.
1082
+ * Adds one or more files. Incoming files with the same path are merged
1083
+ * (sources/imports/exports concatenated), but existing cache entries are
1084
+ * replaced — use {@link upsert} when you want to merge into the cache too.
713
1085
  */
714
- 'kubb:warn': [ctx: KubbWarnContext];
1086
+ add(...files: Array<FileNode>): Array<FileNode>;
715
1087
  /**
716
- * Debug event for detailed logging with timestamp and optional filename.
1088
+ * Adds or merges one or more files.
1089
+ * If a file with the same path already exists in the cache, its
1090
+ * sources/imports/exports are merged into the incoming file.
717
1091
  */
718
- 'kubb:debug': [ctx: KubbDebugContext];
1092
+ upsert(...files: Array<FileNode>): Array<FileNode>;
1093
+ getByPath(path: string): FileNode | null;
1094
+ deleteByPath(path: string): void;
1095
+ clear(): void;
719
1096
  /**
720
- * Fires when file processing starts with the list of files to process.
1097
+ * All stored files, sorted by path length (shorter paths first).
721
1098
  */
722
- 'kubb:files:processing:start': [ctx: KubbFilesProcessingStartContext];
1099
+ get files(): Array<FileNode>;
1100
+ }
1101
+ //#endregion
1102
+ //#region src/PluginDriver.d.ts
1103
+ type Options = {
1104
+ hooks: AsyncEventEmitter<KubbHooks>;
1105
+ };
1106
+ declare class PluginDriver {
1107
+ #private;
1108
+ readonly config: Config;
1109
+ readonly options: Options;
723
1110
  /**
724
- * Fires for each file with progress updates: processed count, total, percentage, and file details.
1111
+ * Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.
1112
+ *
1113
+ * @example
1114
+ * ```ts
1115
+ * PluginDriver.getMode('src/gen/types.ts') // 'single'
1116
+ * PluginDriver.getMode('src/gen/types') // 'split'
1117
+ * ```
725
1118
  */
726
- 'kubb:file:processing:update': [ctx: KubbFileProcessingUpdateContext];
1119
+ static getMode(fileOrFolder: string | undefined | null): 'single' | 'split';
727
1120
  /**
728
- * Fires when file processing completes with the list of processed files.
1121
+ * The universal `@kubb/ast` `InputNode` produced by the adapter, set by
1122
+ * the build pipeline after the adapter's `parse()` resolves.
729
1123
  */
730
- 'kubb:files:processing:end': [ctx: KubbFilesProcessingEndContext];
1124
+ inputNode: InputNode | undefined;
1125
+ adapter: Adapter | undefined;
731
1126
  /**
732
- * Fires when a plugin starts execution.
1127
+ * Central file store for all generated files.
1128
+ * Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to
1129
+ * add files; this property gives direct read/write access when needed.
733
1130
  */
734
- 'kubb:plugin:start': [ctx: KubbPluginStartContext];
1131
+ readonly fileManager: FileManager;
1132
+ readonly plugins: Map<string, NormalizedPlugin>;
1133
+ constructor(config: Config, options: Options);
1134
+ get hooks(): AsyncEventEmitter<KubbHooks>;
735
1135
  /**
736
- * Fires when a plugin completes execution. Duration measured in milliseconds.
1136
+ * Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.
1137
+ *
1138
+ * For `kubb:plugin:setup`, the registered listener wraps the globally emitted context with a
1139
+ * plugin-specific one so that `addGenerator`, `setResolver`, `setTransformer`, and
1140
+ * `setRenderer` all target the correct `normalizedPlugin` entry in the plugins map.
1141
+ *
1142
+ * All other hooks are iterated and registered directly as pass-through listeners.
1143
+ * Any event key present in the global `KubbHooks` interface can be subscribed to.
1144
+ *
1145
+ * External tooling can subscribe to any of these events via `hooks.on(...)` to observe
1146
+ * the plugin lifecycle without modifying plugin behavior.
1147
+ *
1148
+ * @internal
737
1149
  */
738
- 'kubb:plugin:end': [ctx: KubbPluginEndContext];
1150
+ registerPluginHooks(hookPlugin: Plugin, normalizedPlugin: NormalizedPlugin): void;
739
1151
  /**
740
- * Fires once before plugins execute allowing plugins to register generators, configure resolvers/transformers/renderers, or inject files.
1152
+ * Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners
1153
+ * can configure generators, resolvers, transformers and renderers before `buildStart` runs.
1154
+ *
1155
+ * Call this once from `safeBuild` before the plugin execution loop begins.
741
1156
  */
742
- 'kubb:plugin:setup': [ctx: KubbPluginSetupContext];
1157
+ emitSetupHooks(): Promise<void>;
743
1158
  /**
744
- * Fires before the plugin execution loop begins. The adapter has already parsed the source and `inputNode` is available.
1159
+ * Registers a generator for the given plugin on the shared event emitter.
1160
+ *
1161
+ * The generator's `schema`, `operation`, and `operations` methods are registered as
1162
+ * listeners on `kubb:generate:schema`, `kubb:generate:operation`, and `kubb:generate:operations`
1163
+ * respectively. Each listener is scoped to the owning plugin via a `ctx.plugin.name` check
1164
+ * so that generators from different plugins do not cross-fire.
1165
+ *
1166
+ * The renderer resolution chain is: `generator.renderer → plugin.renderer → config.renderer`.
1167
+ * Set `generator.renderer = null` to explicitly opt out of rendering even when the plugin
1168
+ * declares a renderer.
1169
+ *
1170
+ * Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.
745
1171
  */
746
- 'kubb:build:start': [ctx: KubbBuildStartContext];
1172
+ registerGenerator(pluginName: string, gen: Generator): void;
747
1173
  /**
748
- * Fires after all plugins run and per-plugin barrels generate, but before files write to disk.
749
- * Use this to inject final files that must persist in the same write pass as plugin output.
1174
+ * Returns `true` when at least one generator was registered for the given plugin
1175
+ * via `addGenerator()` in `kubb:plugin:setup` (event-based path).
1176
+ *
1177
+ * Used by the build loop to decide whether to walk the AST and emit generator events
1178
+ * for a plugin that has no static `plugin.generators`.
750
1179
  */
751
- 'kubb:plugins:end': [ctx: KubbPluginsEndContext];
1180
+ hasRegisteredGenerators(pluginName: string): boolean;
752
1181
  /**
753
- * Fires after all files write to disk.
1182
+ * Unregisters all plugin lifecycle listeners from the shared event emitter.
1183
+ * Called at the end of a build to prevent listener leaks across repeated builds.
1184
+ *
1185
+ * @internal
754
1186
  */
755
- 'kubb:build:end': [ctx: KubbBuildEndContext];
1187
+ dispose(): void;
756
1188
  /**
757
- * Fires for each schema node during AST traversal. Generator listeners respond to this.
1189
+ * Merges `partial` with the plugin's default resolver and stores the result.
1190
+ * Also mirrors it onto `plugin.resolver` so callers using `getPlugin(name).resolver`
1191
+ * get the up-to-date resolver without going through `getResolver()`.
758
1192
  */
759
- 'kubb:generate:schema': [node: SchemaNode, ctx: GeneratorContext];
1193
+ setPluginResolver(pluginName: string, partial: Partial<Resolver>): void;
760
1194
  /**
761
- * Fires for each operation node during AST traversal. Generator listeners respond to this.
1195
+ * Returns the resolver for the given plugin.
1196
+ *
1197
+ * Resolution order: dynamic resolver set via `setPluginResolver` → static resolver on the
1198
+ * plugin → lazily created default resolver (identity name, no path transforms).
762
1199
  */
763
- 'kubb:generate:operation': [node: OperationNode, ctx: GeneratorContext];
1200
+ getResolver<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Kubb.PluginRegistry[TName]['resolver'];
1201
+ getResolver<TResolver extends Resolver = Resolver>(pluginName: string): TResolver;
1202
+ getContext<TOptions extends PluginFactoryOptions>(plugin: NormalizedPlugin<TOptions>): GeneratorContext<TOptions> & Record<string, unknown>;
1203
+ getPlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
1204
+ getPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions> | undefined;
764
1205
  /**
765
- * Fires once after all operations traverse with the full collected array. Batch generator listeners respond to this.
1206
+ * Like `getPlugin` but throws a descriptive error when the plugin is not found.
766
1207
  */
767
- 'kubb:generate:operations': [nodes: Array<OperationNode>, ctx: GeneratorContext];
768
- }
769
- declare global {
770
- namespace Kubb {
771
- /**
772
- * Registry that maps plugin names to their `PluginFactoryOptions`.
773
- * Augment this interface in each plugin's `types.ts` to enable automatic
774
- * typing for `getPlugin` and `requirePlugin`.
775
- *
776
- * @example
777
- * ```ts
778
- * // packages/plugin-ts/src/types.ts
779
- * declare global {
780
- * namespace Kubb {
781
- * interface PluginRegistry {
782
- * 'plugin-ts': PluginTs
783
- * }
784
- * }
785
- * }
786
- * ```
787
- */
788
- interface PluginRegistry {}
789
- /**
790
- * Extension point for root `Config['output']` options.
791
- * Augment the `output` key in middleware or plugin packages to add extra fields
792
- * to the global output configuration without touching core types.
793
- *
794
- * @example
795
- * ```ts
796
- * // packages/middleware-barrel/src/types.ts
797
- * declare global {
798
- * namespace Kubb {
799
- * interface ConfigOptionsRegistry {
800
- * output: {
801
- * barrelType?: import('./types.ts').BarrelType | false
802
- * }
803
- * }
804
- * }
805
- * }
806
- * ```
807
- */
808
- interface ConfigOptionsRegistry {}
809
- /**
810
- * Extension point for per-plugin `Output` options.
811
- * Augment the `output` key in middleware or plugin packages to add extra fields
812
- * to the per-plugin output configuration without touching core types.
813
- *
814
- * @example
815
- * ```ts
816
- * // packages/middleware-barrel/src/types.ts
817
- * declare global {
818
- * namespace Kubb {
819
- * interface PluginOptionsRegistry {
820
- * output: {
821
- * barrelType?: import('./types.ts').BarrelType | false
822
- * }
823
- * }
824
- * }
825
- * }
826
- * ```
827
- */
828
- interface PluginOptionsRegistry {}
829
- }
1208
+ requirePlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]>;
1209
+ requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>;
830
1210
  }
831
1211
  //#endregion
832
- //#region src/defineMiddleware.d.ts
1212
+ //#region src/defineGenerator.d.ts
833
1213
  /**
834
- * A middleware instance produced by calling a factory created with `defineMiddleware`.
835
- * It declares event handlers under a `hooks` object which are registered on the
836
- * shared emitter after all plugin hooks, so middleware handlers for any event
837
- * always fire last.
1214
+ * Context object passed to generator `schema`, `operation`, and `operations` methods.
1215
+ *
1216
+ * The adapter is always defined (guaranteed by `runPluginAstHooks`) so no runtime checks
1217
+ * are needed. `ctx.options` carries resolved per-node options after exclude/include/override
1218
+ * filtering for individual schema/operation calls, or plugin-level options for operations.
838
1219
  */
839
- type Middleware = {
1220
+ type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
1221
+ config: Config;
1222
+ /**
1223
+ * Absolute path to the current plugin's output directory.
1224
+ */
1225
+ root: string;
840
1226
  /**
841
- * Unique identifier for this middleware.
1227
+ * Determine output mode based on the output config.
1228
+ * Returns `'single'` when `output.path` is a file, `'split'` for a directory.
842
1229
  */
843
- name: string;
1230
+ getMode: (output: {
1231
+ path: string;
1232
+ }) => 'single' | 'split';
1233
+ driver: PluginDriver;
844
1234
  /**
845
- * Lifecycle event handlers for this middleware.
846
- * Any event from the global `KubbHooks` map can be subscribed to here.
847
- * Handlers are registered after all plugin handlers, so they always fire last.
1235
+ * Get a plugin by name, typed via `Kubb.PluginRegistry` when registered.
848
1236
  */
849
- hooks: { [K in keyof KubbHooks]?: (...args: KubbHooks[K]) => void | Promise<void> };
850
- };
851
- /**
852
- * Creates a middleware factory using the hook-style `hooks` API.
853
- *
854
- * Middleware handlers fire after all plugin handlers for any given event, making them ideal for post-processing, logging, and auditing.
855
- * Per-build state (such as accumulators) belongs inside the factory closure so each `createKubb` invocation gets its own isolated instance.
856
- *
857
- * @note The factory can accept typed options. See examples for using options and per-build state patterns.
858
- *
859
- * @example
860
- * ```ts
861
- * import { defineMiddleware } from '@kubb/core'
862
- *
863
- * // Stateless middleware
864
- * export const logMiddleware = defineMiddleware(() => ({
865
- * name: 'log-middleware',
866
- * hooks: {
867
- * 'kubb:build:end'({ files }) {
868
- * console.log(`Build complete with ${files.length} files`)
869
- * },
870
- * },
871
- * }))
872
- *
873
- * // Middleware with options and per-build state
874
- * export const prefixMiddleware = defineMiddleware((options: { prefix: string } = { prefix: '' }) => {
875
- * const seen = new Set<string>()
876
- * return {
877
- * name: 'prefix-middleware',
878
- * hooks: {
879
- * 'kubb:plugin:end'({ plugin }) {
880
- * seen.add(`${options.prefix}${plugin.name}`)
881
- * },
882
- * },
883
- * }
884
- * })
885
- * ```
886
- */
887
- declare function defineMiddleware<TOptions extends object = object>(factory: (options: TOptions) => Middleware): (options?: TOptions) => Middleware;
888
- //#endregion
889
- //#region src/defineParser.d.ts
890
- type PrintOptions = {
891
- extname?: FileNode['extname'];
892
- };
893
- type Parser<TMeta extends object = any> = {
894
- name: string;
1237
+ getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
1238
+ getPlugin(name: string): Plugin | undefined;
895
1239
  /**
896
- * File extensions this parser handles.
897
- * Use `undefined` to create a catch-all fallback parser.
898
- *
899
- * @example Handled extensions
900
- * `['.ts', '.js']`
1240
+ * Get a plugin by name, throws an error if not found.
901
1241
  */
902
- extNames: Array<FileNode['extname']> | undefined;
1242
+ requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>;
1243
+ requirePlugin(name: string): Plugin;
903
1244
  /**
904
- * Convert a resolved file to a string.
1245
+ * Get a resolver by plugin name, typed via `Kubb.PluginRegistry` when registered.
905
1246
  */
906
- parse(file: FileNode<TMeta>, options?: PrintOptions): Promise<string> | string;
1247
+ getResolver<TName extends keyof Kubb.PluginRegistry>(name: TName): Kubb.PluginRegistry[TName]['resolver'];
1248
+ getResolver(name: string): Resolver;
1249
+ /**
1250
+ * Add files only if they don't exist.
1251
+ */
1252
+ addFile: (...file: Array<FileNode>) => Promise<void>;
1253
+ /**
1254
+ * Merge sources into the same output file.
1255
+ */
1256
+ upsertFile: (...file: Array<FileNode>) => Promise<void>;
1257
+ hooks: AsyncEventEmitter<KubbHooks>;
1258
+ /**
1259
+ * The current plugin instance.
1260
+ */
1261
+ plugin: Plugin<TOptions>;
1262
+ /**
1263
+ * The current plugin's resolver.
1264
+ */
1265
+ resolver: TOptions['resolver'];
1266
+ /**
1267
+ * The current plugin's transformer.
1268
+ */
1269
+ transformer: Visitor | undefined;
1270
+ /**
1271
+ * Emit a warning.
1272
+ */
1273
+ warn: (message: string) => void;
1274
+ /**
1275
+ * Emit an error.
1276
+ */
1277
+ error: (error: string | Error) => void;
1278
+ /**
1279
+ * Emit an info message.
1280
+ */
1281
+ info: (message: string) => void;
1282
+ /**
1283
+ * Open the current input node in Kubb Studio.
1284
+ */
1285
+ openInStudio: (options?: DevtoolsOptions) => Promise<void>;
1286
+ /**
1287
+ * The configured adapter instance.
1288
+ */
1289
+ adapter: Adapter;
1290
+ /**
1291
+ * The universal `InputNode` produced by the adapter.
1292
+ */
1293
+ inputNode: InputNode;
1294
+ /**
1295
+ * Resolved options after exclude/include/override filtering.
1296
+ */
1297
+ options: TOptions['resolvedOptions'];
907
1298
  };
908
1299
  /**
909
- * Defines a parser with type safety. Creates parsers that transform generated files to strings based on their extension.
1300
+ * Declares a named generator unit that walks the AST and emits files.
910
1301
  *
911
- * @note Call the returned factory with optional options to instantiate the parser.
1302
+ * Each method (`schema`, `operation`, `operations`) is called for the matching node type.
1303
+ * Each method returns `TElement | Array<FileNode> | void`. JSX-based generators require a `renderer` factory.
1304
+ * Return `Array<FileNode>` directly or call `ctx.upsertFile()` manually and return `void` to bypass rendering.
1305
+ *
1306
+ * @note Generators are consumed by plugins and registered via `ctx.addGenerator()` in `kubb:plugin:setup`.
912
1307
  *
913
1308
  * @example
914
1309
  * ```ts
915
- * import { defineParser } from '@kubb/core'
1310
+ * import { defineGenerator } from '@kubb/core'
1311
+ * import { jsxRenderer } from '@kubb/renderer-jsx'
916
1312
  *
917
- * export const jsonParser = defineParser({
918
- * name: 'json',
919
- * extNames: ['.json'],
920
- * parse(file) {
921
- * const { extractStringsFromNodes } = await import('@kubb/ast')
922
- * return file.sources.map((s) => extractStringsFromNodes(s.nodes ?? [])).join('\n')
1313
+ * export const typeGenerator = defineGenerator({
1314
+ * name: 'typescript',
1315
+ * renderer: jsxRenderer,
1316
+ * schema(node, ctx) {
1317
+ * const { adapter, resolver, root, options } = ctx
1318
+ * return <File ...><Type node={node} resolver={resolver} /></File>
923
1319
  * },
924
1320
  * })
925
1321
  * ```
926
1322
  */
927
- declare function defineParser<TMeta extends object = any>(parser: Parser<TMeta>): Parser<TMeta>;
928
- //#endregion
929
- //#region src/types.d.ts
930
- /**
931
- * Safely extracts a type from a registry, returning `{}` if the key doesn't exist.
932
- * Enables optional interface augmentation for `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry`
933
- * without requiring changes to core.
934
- *
935
- * @internal
936
- */
937
- type ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {};
938
- /**
939
- * Reference to an input file to generate code from.
940
- *
941
- * Specify an absolute path or a path relative to the config file location.
942
- * The adapter will parse this file (e.g., OpenAPI YAML or JSON) into the universal AST.
943
- */
944
- type InputPath = {
1323
+ type Generator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown> = {
945
1324
  /**
946
- * Path to your Swagger/OpenAPI file, absolute or relative to the config file location.
947
- *
948
- * @example
949
- * ```ts
950
- * { path: './petstore.yaml' }
951
- * { path: '/absolute/path/to/openapi.json' }
952
- * ```
1325
+ * Used in diagnostic messages and debug output.
953
1326
  */
954
- path: string;
955
- };
956
- /**
957
- * Inline input data to generate code from.
958
- *
959
- * Useful when you want to pass the specification directly instead of from a file.
960
- * Can be a string (YAML/JSON) or a parsed object.
961
- */
962
- type InputData = {
1327
+ name: string;
963
1328
  /**
964
- * Swagger/OpenAPI data as a string (YAML/JSON) or a parsed object.
1329
+ * Optional renderer factory that produces a {@link Renderer} for each render cycle.
1330
+ *
1331
+ * Generators that return renderer elements (e.g. JSX via `@kubb/renderer-jsx`) must set this
1332
+ * to the matching renderer factory (e.g. `jsxRenderer` from `@kubb/renderer-jsx`).
1333
+ *
1334
+ * Generators that only return `Array<FileNode>` or `void` do not need to set this.
1335
+ *
1336
+ * Set `renderer: null` to explicitly opt out of rendering even when the parent plugin
1337
+ * declares a `renderer` (overrides the plugin-level fallback).
965
1338
  *
966
1339
  * @example
967
1340
  * ```ts
968
- * { data: fs.readFileSync('./openapi.yaml', 'utf8') }
969
- * { data: { openapi: '3.1.0', info: { ... } } }
1341
+ * import { jsxRenderer } from '@kubb/renderer-jsx'
1342
+ * export const myGenerator = defineGenerator<PluginTs>({
1343
+ * renderer: jsxRenderer,
1344
+ * schema(node, ctx) { return <File ...>...</File> },
1345
+ * })
970
1346
  * ```
971
1347
  */
972
- data: string | unknown;
973
- };
974
- type Input = InputPath | InputData;
975
- /**
976
- * Source data passed to an adapter's `parse` function.
977
- * Mirrors the config input shape with paths resolved to absolute.
978
- */
979
- type AdapterSource = {
980
- type: 'path';
981
- path: string;
982
- } | {
983
- type: 'data';
984
- data: string | unknown;
985
- } | {
986
- type: 'paths';
987
- paths: Array<string>;
988
- };
989
- /**
990
- * Generic type parameters for an adapter definition.
991
- *
992
- * - `TName` — unique identifier (e.g. `'oas'`, `'asyncapi'`)
993
- * - `TOptions` — user-facing options passed to the adapter factory
994
- * - `TResolvedOptions` — options after defaults applied
995
- * - `TDocument` — type of the parsed source document
996
- */
997
- type AdapterFactoryOptions<TName extends string = string, TOptions extends object = object, TResolvedOptions extends object = TOptions, TDocument = unknown> = {
998
- name: TName;
999
- options: TOptions;
1000
- resolvedOptions: TResolvedOptions;
1001
- document: TDocument;
1002
- };
1003
- /**
1004
- * Adapter that converts input files or data into an `InputNode`.
1005
- *
1006
- * Adapters parse different schema formats (OpenAPI, AsyncAPI, Drizzle, etc.) into Kubb's
1007
- * universal intermediate representation that all plugins consume.
1008
- *
1009
- * @example
1010
- * ```ts
1011
- * import { adapterOas } from '@kubb/adapter-oas'
1012
- *
1013
- * export default defineConfig({
1014
- * adapter: adapterOas(),
1015
- * input: { path: './openapi.yaml' },
1016
- * plugins: [pluginTs(), pluginZod()],
1017
- * })
1018
- * ```
1019
- */
1020
- type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
1021
- /**
1022
- * Human-readable adapter identifier (e.g. `'oas'`, `'asyncapi'`).
1023
- */
1024
- name: TOptions['name'];
1348
+ renderer?: RendererFactory<TElement> | null;
1025
1349
  /**
1026
- * Resolved adapter options after defaults have been applied.
1350
+ * Called for each schema node in the AST walk.
1351
+ * `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
1352
+ * plus `ctx.options` with the per-node resolved options (after exclude/include/override).
1027
1353
  */
1028
- options: TOptions['resolvedOptions'];
1354
+ schema?: (node: SchemaNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
1029
1355
  /**
1030
- * Parsed source document after the first `parse()` call. `null` before parsing.
1356
+ * Called for each operation node in the AST walk.
1357
+ * `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
1358
+ * plus `ctx.options` with the per-node resolved options (after exclude/include/override).
1031
1359
  */
1032
- document: TOptions['document'] | null;
1033
- inputNode: InputNode | null;
1360
+ operation?: (node: OperationNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
1034
1361
  /**
1035
- * Parse the source into a universal `InputNode`.
1362
+ * Called once after all operations have been walked.
1363
+ * `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
1364
+ * plus `ctx.options` with the plugin-level options for the batch call.
1036
1365
  */
1037
- parse: (source: AdapterSource) => PossiblePromise<InputNode>;
1366
+ operations?: (nodes: Array<OperationNode>, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
1367
+ };
1368
+ /**
1369
+ * Defines a generator. Returns the object as-is with correct `this` typings.
1370
+ * `applyHookResult` handles renderer elements and `File[]` uniformly using
1371
+ * the generator's declared `renderer` factory.
1372
+ */
1373
+ declare function defineGenerator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown>(generator: Generator<TOptions, TElement>): Generator<TOptions, TElement>;
1374
+ //#endregion
1375
+ //#region src/createKubb.d.ts
1376
+ /**
1377
+ * Safely extracts a type from a registry, returning `{}` if the key doesn't exist.
1378
+ * Enables optional interface augmentation for `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry`
1379
+ * without requiring changes to core.
1380
+ *
1381
+ * @internal
1382
+ */
1383
+ type ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {};
1384
+ /**
1385
+ * Reference to an input file to generate code from.
1386
+ *
1387
+ * Specify an absolute path or a path relative to the config file location.
1388
+ * The adapter will parse this file (e.g., OpenAPI YAML or JSON) into the universal AST.
1389
+ */
1390
+ type InputPath = {
1038
1391
  /**
1039
- * Extract `ImportNode` entries for a schema tree.
1040
- * Returns an empty array before the first `parse()` call.
1392
+ * Path to your Swagger/OpenAPI file, absolute or relative to the config file location.
1041
1393
  *
1042
- * The `resolve` callback receives the collision-corrected schema name and must
1043
- * return `{ name, path }` for the import, or `undefined` to skip it.
1394
+ * @example
1395
+ * ```ts
1396
+ * { path: './petstore.yaml' }
1397
+ * { path: '/absolute/path/to/openapi.json' }
1398
+ * ```
1044
1399
  */
1045
- getImports: (node: SchemaNode, resolve: (schemaName: string) => {
1046
- name: string;
1047
- path: string;
1048
- }) => Array<ImportNode>;
1400
+ path: string;
1049
1401
  };
1050
- type DevtoolsOptions = {
1402
+ /**
1403
+ * Inline input data to generate code from.
1404
+ *
1405
+ * Useful when you want to pass the specification directly instead of from a file.
1406
+ * Can be a string (YAML/JSON) or a parsed object.
1407
+ */
1408
+ type InputData = {
1051
1409
  /**
1052
- * Open the AST inspector in Kubb Studio (`/ast`). Defaults to the main Studio page.
1053
- * @default false
1410
+ * Swagger/OpenAPI data as a string (YAML/JSON) or a parsed object.
1411
+ *
1412
+ * @example
1413
+ * ```ts
1414
+ * { data: fs.readFileSync('./openapi.yaml', 'utf8') }
1415
+ * { data: { openapi: '3.1.0', info: { ... } } }
1416
+ * ```
1054
1417
  */
1055
- ast?: boolean;
1418
+ data: string | unknown;
1056
1419
  };
1420
+ type Input = InputPath | InputData;
1057
1421
  /**
1058
1422
  * Build configuration for Kubb code generation.
1059
1423
  *
@@ -1069,725 +1433,465 @@ type DevtoolsOptions = {
1069
1433
  */
1070
1434
  type Config<TInput = Input> = {
1071
1435
  /**
1072
- * Display name for this configuration in CLI output and logs.
1073
- * Useful when running multiple builds with `defineConfig` arrays.
1074
- *
1075
- * @example
1076
- * ```ts
1077
- * name: 'api-client'
1078
- * ```
1079
- */
1080
- name?: string;
1081
- /**
1082
- * Project root directory, absolute or relative to the config file.
1083
- * @default process.cwd()
1084
- */
1085
- root: string;
1086
- /**
1087
- * Parsers that convert generated files to strings.
1088
- * Each parser handles specific extensions (e.g. `.ts`, `.tsx`).
1089
- * A fallback parser is appended for unhandled extensions.
1090
- * When omitted, defaults to `parserTs` from `@kubb/parser-ts`.
1091
- *
1092
- * @default [parserTs] from `@kubb/parser-ts`
1093
- * @example
1094
- * ```ts
1095
- * import { parserTs, tsxParser } from '@kubb/parser-ts'
1096
- * export default defineConfig({
1097
- * parsers: [parserTs, tsxParser],
1098
- * })
1099
- * ```
1100
- */
1101
- parsers: Array<Parser>;
1102
- /**
1103
- * Adapter that parses input files into the universal `InputNode` representation.
1104
- * Use `@kubb/adapter-oas` for OpenAPI/Swagger or `@kubb/adapter-asyncapi` for other formats.
1105
- *
1106
- * @example
1107
- * ```ts
1108
- * import { adapterOas } from '@kubb/adapter-oas'
1109
- * export default defineConfig({
1110
- * adapter: adapterOas(),
1111
- * input: { path: './petstore.yaml' },
1112
- * })
1113
- * ```
1114
- */
1115
- adapter: Adapter;
1116
- /**
1117
- * Source file or data to generate code from.
1118
- * Use `input.path` for a file path or `input.data` for inline data.
1119
- */
1120
- input: TInput;
1121
- output: {
1122
- /**
1123
- * Output directory for generated files, absolute or relative to `root`.
1124
- *
1125
- * All generated files will be written under this directory. Subdirectories can be created
1126
- * by plugins based on grouping strategy (by tag, path, etc.).
1127
- *
1128
- * @example
1129
- * ```ts
1130
- * output: {
1131
- * path: './src/gen', // generates ./src/gen/api.ts, ./src/gen/types.ts, etc.
1132
- * }
1133
- * ```
1134
- */
1135
- path: string;
1136
- /**
1137
- * Remove all files from the output directory before starting the build.
1138
- *
1139
- * Useful to ensure old generated files aren't mixed with new ones.
1140
- * Set to `true` for fresh builds, `false` to preserve manual edits in output dir.
1141
- *
1142
- * @default false
1143
- * @example
1144
- * ```ts
1145
- * clean: true // wipes ./src/gen/* before generating
1146
- * ```
1147
- */
1148
- clean?: boolean;
1149
- /**
1150
- * Persists generated files to the file system.
1151
- *
1152
- * @default true
1153
- * @deprecated Use `storage` option to control where files are written instead.
1154
- */
1155
- write?: boolean;
1156
- /**
1157
- * Auto-format generated files after code generation completes.
1158
- *
1159
- * Applies a code formatter to all generated files. Use `'auto'` to detect which formatter
1160
- * is available on your system. Pass `false` to skip formatting (useful for CI or specific workflows).
1161
- *
1162
- * @default false
1163
- * @example
1164
- * ```ts
1165
- * format: 'auto' // auto-detect prettier, biome, or oxfmt
1166
- * format: 'prettier' // force prettier
1167
- * format: false // skip formatting
1168
- * ```
1169
- */
1170
- format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false;
1171
- /**
1172
- * Auto-lint generated files after code generation completes.
1173
- *
1174
- * Analyzes all generated files for style/correctness issues. Use `'auto'` to detect which linter
1175
- * is available on your system. Pass `false` to skip linting.
1176
- *
1177
- * @default false
1178
- * @example
1179
- * ```ts
1180
- * lint: 'auto' // auto-detect oxlint, biome, or eslint
1181
- * lint: 'eslint' // force eslint
1182
- * lint: false // skip linting
1183
- * ```
1184
- */
1185
- lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false;
1186
- /**
1187
- * Map file extensions to different output extensions.
1188
- *
1189
- * Useful when you want generated `.ts` imports to reference `.js` files or vice versa (e.g., for ESM dual packages).
1190
- * Keys are the original extension, values are the output extension. Use empty string `''` to omit extension.
1191
- *
1192
- * @default { '.ts': '.ts' }
1193
- * @example
1194
- * ```ts
1195
- * extension: { '.ts': '.js' } // generates import './api.js' instead of './api.ts'
1196
- * extension: { '.ts': '', '.tsx': '.jsx' }
1197
- * ```
1198
- */
1199
- extension?: Record<FileNode['extname'], FileNode['extname'] | ''>;
1200
- /**
1201
- * Banner text prepended to every generated file.
1202
- *
1203
- * Useful for auto-generation notices or license headers. Choose a preset or write custom text.
1204
- * Use `'simple'` for a basic Kubb banner, `'full'` for detailed metadata, or `false` to omit.
1205
- *
1206
- * @default 'simple'
1207
- * @example
1208
- * ```ts
1209
- * defaultBanner: 'simple' // "This file was autogenerated by Kubb"
1210
- * defaultBanner: 'full' // adds source, title, description, API version
1211
- * defaultBanner: false // no banner
1212
- * ```
1213
- */
1214
- defaultBanner?: 'simple' | 'full' | false;
1215
- /**
1216
- * When `true`, overwrites existing files. When `false`, skips generated files that already exist.
1217
- *
1218
- * Individual plugins can override this setting. This is useful for preventing accidental data loss
1219
- * when re-generating while you have local edits in the output folder.
1220
- *
1221
- * @default false
1222
- * @example
1223
- * ```ts
1224
- * override: true // regenerate everything, even existing files
1225
- * override: false // skip files that already exist
1226
- * ```
1227
- */
1228
- override?: boolean;
1229
- } & ExtractRegistryKey<Kubb.ConfigOptionsRegistry, 'output'>;
1230
- /**
1231
- * Storage backend that controls where and how generated files are persisted.
1232
- *
1233
- * Defaults to `fsStorage()` which writes to the file system. Pass `memoryStorage()` to keep files in RAM,
1234
- * or implement a custom `Storage` interface to write to cloud storage, databases, or other backends.
1235
- *
1236
- * @default fsStorage()
1237
- * @example
1238
- * ```ts
1239
- * import { memoryStorage } from '@kubb/core'
1240
- *
1241
- * // Keep generated files in memory (useful for testing, CI pipelines)
1242
- * storage: memoryStorage()
1243
- *
1244
- * // Use custom S3 storage
1245
- * storage: myS3Storage()
1246
- * ```
1247
- *
1248
- * @see {@link Storage} interface for implementing custom backends.
1249
- */
1250
- storage?: Storage;
1251
- /**
1252
- * Plugins that execute during the build to generate code and transform the AST.
1253
- *
1254
- * Each plugin processes the AST produced by the adapter and can emit files for different
1255
- * programming languages or formats (TypeScript, Zod schemas, Faker data, etc.).
1256
- * Dependencies are enforced — an error is thrown if a plugin requires another plugin that isn't registered.
1257
- *
1258
- * Plugins can declare their own options via `PluginFactoryOptions`. See plugin documentation for details.
1436
+ * Display name for this configuration in CLI output and logs.
1437
+ * Useful when running multiple builds with `defineConfig` arrays.
1259
1438
  *
1260
1439
  * @example
1261
1440
  * ```ts
1262
- * import { pluginTs } from '@kubb/plugin-ts'
1263
- * import { pluginZod } from '@kubb/plugin-zod'
1264
- *
1265
- * plugins: [
1266
- * pluginTs({ output: { path: './src/gen' } }),
1267
- * pluginZod({ output: { path: './src/gen' } }),
1268
- * ]
1441
+ * name: 'api-client'
1269
1442
  * ```
1270
1443
  */
1271
- plugins: Array<Plugin>;
1444
+ name?: string;
1272
1445
  /**
1273
- * Middleware instances that observe build events and post-process generated code.
1274
- *
1275
- * Middleware fires AFTER all plugins for each event. Perfect for tasks like:
1276
- * - Auditing what was generated
1277
- * - Adding barrel/index files
1278
- * - Validating output
1279
- * - Running custom transformations
1280
- *
1281
- * @example
1282
- * ```ts
1283
- * import { middlewareBarrel } from '@kubb/middleware-barrel'
1284
- *
1285
- * middleware: [middlewareBarrel()]
1286
- * ```
1287
- *
1288
- * @see {@link defineMiddleware} to create custom middleware.
1446
+ * Project root directory, absolute or relative to the config file.
1447
+ * @default process.cwd()
1289
1448
  */
1290
- middleware?: Array<Middleware>;
1449
+ root: string;
1291
1450
  /**
1292
- * Default renderer factory used by all plugins and generators.
1293
- * Resolution chain: `generator.renderer` `plugin.renderer` → `config.renderer` `undefined` (raw FileNode[] mode).
1451
+ * Parsers that convert generated files to strings.
1452
+ * Each parser handles specific extensions (e.g. `.ts`, `.tsx`).
1453
+ * A fallback parser is appended for unhandled extensions.
1454
+ * When omitted, defaults to `parserTs` from `@kubb/parser-ts`.
1294
1455
  *
1456
+ * @default [parserTs] from `@kubb/parser-ts`
1295
1457
  * @example
1296
1458
  * ```ts
1297
- * import { jsxRenderer } from '@kubb/renderer-jsx'
1459
+ * import { parserTs, tsxParser } from '@kubb/parser-ts'
1298
1460
  * export default defineConfig({
1299
- * renderer: jsxRenderer,
1300
- * plugins: [pluginTs(), pluginZod()],
1461
+ * parsers: [parserTs, tsxParser],
1301
1462
  * })
1302
1463
  * ```
1303
1464
  */
1465
+ parsers: Array<Parser>;
1304
1466
  /**
1305
- * Renderer that converts generated AST nodes to code strings.
1467
+ * Adapter that parses input files into the universal `InputNode` representation.
1468
+ * Use `@kubb/adapter-oas` for OpenAPI/Swagger or `@kubb/adapter-asyncapi` for other formats.
1306
1469
  *
1307
- * By default, Kubb uses the JSX renderer (`rendererJsx`). Pass a custom renderer to support
1308
- * different output formats (template engines, code generation DSLs, etc.).
1470
+ * When omitted, Kubb runs in plugin-only mode: `kubb:plugin:setup` fires and files
1471
+ * injected via `injectFile` are written, but no AST walk occurs and generator hooks
1472
+ * (`kubb:generate:schema`, `kubb:generate:operation`) are never emitted.
1309
1473
  *
1310
- * @default rendererJsx() // from @kubb/renderer-jsx
1311
1474
  * @example
1312
1475
  * ```ts
1313
- * import { rendererJsx } from '@kubb/renderer-jsx'
1314
- * renderer: rendererJsx()
1476
+ * import { adapterOas } from '@kubb/adapter-oas'
1477
+ * export default defineConfig({
1478
+ * adapter: adapterOas(),
1479
+ * input: { path: './petstore.yaml' },
1480
+ * })
1315
1481
  * ```
1316
- *
1317
- * @see {@link Renderer} to implement a custom renderer.
1318
1482
  */
1319
- renderer?: RendererFactory;
1483
+ adapter?: Adapter;
1320
1484
  /**
1321
- * Kubb Studio cloud integration settings.
1322
- *
1323
- * Kubb Studio (https://studio.kubb.dev) is a web-based IDE for managing API specs and generated code.
1324
- * Set to `true` to enable with default settings, or pass an object to customize the Studio URL.
1325
- *
1326
- * @default false // disabled by default
1327
- * @example
1328
- * ```ts
1329
- * devtools: true // use default Kubb Studio
1330
- * devtools: { studioUrl: 'https://my-studio.dev' } // custom Studio instance
1331
- * ```
1485
+ * Source file or data to generate code from.
1486
+ * Use `input.path` for a file path or `input.data` for inline data.
1487
+ * Required when an adapter is configured; omit when running in plugin-only mode.
1332
1488
  */
1333
- devtools?: true | {
1489
+ input?: TInput;
1490
+ output: {
1334
1491
  /**
1335
- * Override the Kubb Studio base URL.
1336
- * @default 'https://studio.kubb.dev'
1492
+ * Output directory for generated files, absolute or relative to `root`.
1493
+ *
1494
+ * All generated files will be written under this directory. Subdirectories can be created
1495
+ * by plugins based on grouping strategy (by tag, path, etc.).
1496
+ *
1497
+ * @example
1498
+ * ```ts
1499
+ * output: {
1500
+ * path: './src/gen', // generates ./src/gen/api.ts, ./src/gen/types.ts, etc.
1501
+ * }
1502
+ * ```
1337
1503
  */
1338
- studioUrl?: typeof DEFAULT_STUDIO_URL | (string & {});
1339
- };
1340
- /**
1341
- * Lifecycle hooks that execute during or after the build process.
1342
- *
1343
- * Hooks allow you to run external tools (prettier, eslint, custom scripts) based on build events.
1344
- * Currently supports the `done` hook which fires after all plugins and middleware complete.
1345
- *
1346
- * @example
1347
- * ```ts
1348
- * hooks: {
1349
- * done: 'prettier --write "./src/gen"', // auto-format generated files
1350
- * // or multiple commands:
1351
- * done: ['prettier --write "./src/gen"', 'eslint --fix "./src/gen"']
1352
- * }
1353
- * ```
1354
- */
1355
- hooks?: {
1504
+ path: string;
1356
1505
  /**
1357
- * Command(s) to run after all plugins and middleware complete generation.
1506
+ * Remove all files from the output directory before starting the build.
1358
1507
  *
1359
- * Useful for post-processing: formatting, linting, copying files, or custom validation.
1360
- * Pass a single command string or array of command strings to run sequentially.
1361
- * Commands are executed relative to the `root` directory.
1508
+ * Useful to ensure old generated files aren't mixed with new ones.
1509
+ * Set to `true` for fresh builds, `false` to preserve manual edits in output dir.
1362
1510
  *
1511
+ * @default false
1363
1512
  * @example
1364
1513
  * ```ts
1365
- * done: 'prettier --write "./src/gen"'
1366
- * done: ['prettier --write "./src/gen"', 'eslint --fix "./src/gen"']
1514
+ * clean: true // wipes ./src/gen/* before generating
1367
1515
  * ```
1368
1516
  */
1369
- done?: string | Array<string>;
1370
- };
1371
- };
1372
- /**
1373
- * Type/string pattern filter for include/exclude/override matching.
1374
- */
1375
- type PatternFilter = {
1376
- type: string;
1377
- pattern: string | RegExp;
1378
- };
1379
- /**
1380
- * Pattern filter with partial option overrides applied when the pattern matches.
1381
- */
1382
- type PatternOverride<TOptions> = PatternFilter & {
1383
- options: Omit<Partial<TOptions>, 'override'>;
1384
- };
1385
- /**
1386
- * Context for resolving filtered options for a given operation or schema node.
1387
- *
1388
- * @internal
1389
- */
1390
- type ResolveOptionsContext<TOptions> = {
1391
- options: TOptions;
1392
- exclude?: Array<PatternFilter>;
1393
- include?: Array<PatternFilter>;
1394
- override?: Array<PatternOverride<TOptions>>;
1395
- };
1396
- /**
1397
- * Base constraint for all plugin resolver objects.
1398
- *
1399
- * `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`
1400
- * are injected automatically by `defineResolver` — extend this type to add custom resolution methods.
1401
- *
1402
- * @example
1403
- * ```ts
1404
- * type MyResolver = Resolver & {
1405
- * resolveName(node: SchemaNode): string
1406
- * resolveTypedName(node: SchemaNode): string
1407
- * }
1408
- * ```
1409
- */
1410
- type Resolver = {
1411
- name: string;
1412
- pluginName: Plugin['name'];
1413
- default(name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
1414
- resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null;
1415
- resolvePath(params: ResolverPathParams, context: ResolverContext): string;
1416
- resolveFile(params: ResolverFileParams, context: ResolverContext): FileNode;
1417
- resolveBanner(node: InputNode | null, context: ResolveBannerContext): string | undefined;
1418
- resolveFooter(node: InputNode | null, context: ResolveBannerContext): string | undefined;
1419
- };
1420
- type PluginFactoryOptions<
1421
- /**
1422
- * Unique plugin name.
1423
- */
1424
- TName extends string = string,
1425
- /**
1426
- * User-facing plugin options.
1427
- */
1428
- TOptions extends object = object,
1429
- /**
1430
- * Plugin options after defaults are applied.
1431
- */
1432
- TResolvedOptions extends object = TOptions,
1433
- /**
1434
- * Resolver that encapsulates naming and path-resolution helpers.
1435
- * Define with `defineResolver` and export alongside the plugin.
1436
- */
1437
- TResolver extends Resolver = Resolver> = {
1438
- name: TName;
1439
- options: TOptions;
1440
- resolvedOptions: TResolvedOptions;
1441
- resolver: TResolver;
1442
- };
1443
- /**
1444
- * Normalized plugin after setup, with runtime fields populated.
1445
- * For internal use only — plugins use the public `Plugin` type externally.
1446
- *
1447
- * @internal
1448
- */
1449
- type NormalizedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & {
1450
- options: TOptions['resolvedOptions'] & {
1451
- output: Output;
1452
- include?: Array<Include>;
1453
- exclude: Array<Exclude$1>;
1454
- override: Array<Override<TOptions['resolvedOptions']>>;
1455
- };
1456
- resolver: TOptions['resolver'];
1457
- transformer?: Visitor;
1458
- renderer?: RendererFactory;
1459
- generators?: Array<Generator>;
1460
- apply?: (config: Config) => boolean;
1461
- version?: string;
1462
- };
1463
- /**
1464
- * Partial `Config` for user-facing entry points with sensible defaults.
1465
- *
1466
- * `UserConfig` is what you pass to `defineConfig()`. It has optional `root`, `plugins`, `parsers`, and `adapter`
1467
- * fields (which fall back to sensible defaults). All other Config options are available, including `output`, `input`,
1468
- * `storage`, `middleware`, `renderer`, `devtools`, and `hooks`.
1469
- *
1470
- * @example
1471
- * ```ts
1472
- * export default defineConfig({
1473
- * input: { path: './petstore.yaml' },
1474
- * output: { path: './src/gen' },
1475
- * plugins: [pluginTs(), pluginZod()],
1476
- * })
1477
- * ```
1478
- */
1479
- type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter'> & {
1517
+ clean?: boolean;
1518
+ /**
1519
+ * Auto-format generated files after code generation completes.
1520
+ *
1521
+ * Applies a code formatter to all generated files. Use `'auto'` to detect which formatter
1522
+ * is available on your system. Pass `false` to skip formatting (useful for CI or specific workflows).
1523
+ *
1524
+ * @default false
1525
+ * @example
1526
+ * ```ts
1527
+ * format: 'auto' // auto-detect prettier, biome, or oxfmt
1528
+ * format: 'prettier' // force prettier
1529
+ * format: false // skip formatting
1530
+ * ```
1531
+ */
1532
+ format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false;
1533
+ /**
1534
+ * Auto-lint generated files after code generation completes.
1535
+ *
1536
+ * Analyzes all generated files for style/correctness issues. Use `'auto'` to detect which linter
1537
+ * is available on your system. Pass `false` to skip linting.
1538
+ *
1539
+ * @default false
1540
+ * @example
1541
+ * ```ts
1542
+ * lint: 'auto' // auto-detect oxlint, biome, or eslint
1543
+ * lint: 'eslint' // force eslint
1544
+ * lint: false // skip linting
1545
+ * ```
1546
+ */
1547
+ lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false;
1548
+ /**
1549
+ * Map file extensions to different output extensions.
1550
+ *
1551
+ * Useful when you want generated `.ts` imports to reference `.js` files or vice versa (e.g., for ESM dual packages).
1552
+ * Keys are the original extension, values are the output extension. Use empty string `''` to omit extension.
1553
+ *
1554
+ * @default { '.ts': '.ts' }
1555
+ * @example
1556
+ * ```ts
1557
+ * extension: { '.ts': '.js' } // generates import './api.js' instead of './api.ts'
1558
+ * extension: { '.ts': '', '.tsx': '.jsx' }
1559
+ * ```
1560
+ */
1561
+ extension?: Record<FileNode['extname'], FileNode['extname'] | ''>;
1562
+ /**
1563
+ * Banner text prepended to every generated file.
1564
+ *
1565
+ * Useful for auto-generation notices or license headers. Choose a preset or write custom text.
1566
+ * Use `'simple'` for a basic Kubb banner, `'full'` for detailed metadata, or `false` to omit.
1567
+ *
1568
+ * @default 'simple'
1569
+ * @example
1570
+ * ```ts
1571
+ * defaultBanner: 'simple' // "This file was autogenerated by Kubb"
1572
+ * defaultBanner: 'full' // adds source, title, description, API version
1573
+ * defaultBanner: false // no banner
1574
+ * ```
1575
+ */
1576
+ defaultBanner?: 'simple' | 'full' | false;
1577
+ /**
1578
+ * When `true`, overwrites existing files. When `false`, skips generated files that already exist.
1579
+ *
1580
+ * Individual plugins can override this setting. This is useful for preventing accidental data loss
1581
+ * when re-generating while you have local edits in the output folder.
1582
+ *
1583
+ * @default false
1584
+ * @example
1585
+ * ```ts
1586
+ * override: true // regenerate everything, even existing files
1587
+ * override: false // skip files that already exist
1588
+ * ```
1589
+ */
1590
+ override?: boolean;
1591
+ } & ExtractRegistryKey<Kubb$1.ConfigOptionsRegistry, 'output'>;
1480
1592
  /**
1481
- * Project root directory, absolute or relative to the config file location.
1593
+ * Storage backend that controls where and how generated files are persisted.
1482
1594
  *
1483
- * Used as the base path for `root`-relative paths (e.g., `output.path`, file paths in hooks).
1595
+ * Defaults to `fsStorage()` which writes to the file system. Pass `memoryStorage()` to keep files in RAM,
1596
+ * or implement a custom `Storage` interface to write to cloud storage, databases, or other backends.
1484
1597
  *
1485
- * @default process.cwd()
1598
+ * @default fsStorage()
1486
1599
  * @example
1487
1600
  * ```ts
1488
- * root: '/home/user/my-project'
1489
- * root: './my-project' // relative to config file
1601
+ * import { memoryStorage } from '@kubb/core'
1602
+ *
1603
+ * // Keep generated files in memory (useful for testing, CI pipelines)
1604
+ * storage: memoryStorage()
1605
+ *
1606
+ * // Use custom S3 storage
1607
+ * storage: myS3Storage()
1490
1608
  * ```
1609
+ *
1610
+ * @see {@link Storage} interface for implementing custom backends.
1491
1611
  */
1492
- root?: string;
1612
+ storage: Storage;
1493
1613
  /**
1494
- * Custom parsers that convert generated AST nodes to strings (TypeScript, JSON, markdown, etc.).
1614
+ * Plugins that execute during the build to generate code and transform the AST.
1615
+ *
1616
+ * Each plugin processes the AST produced by the adapter and can emit files for different
1617
+ * programming languages or formats (TypeScript, Zod schemas, Faker data, etc.).
1618
+ * Dependencies are enforced — an error is thrown if a plugin requires another plugin that isn't registered.
1495
1619
  *
1496
- * Each parser handles a specific file type. By default, Kubb uses `parserTs` from `@kubb/parser-ts` for TypeScript files.
1497
- * Pass custom parsers to support additional languages or custom formats.
1620
+ * Plugins can declare their own options via `PluginFactoryOptions`. See plugin documentation for details.
1498
1621
  *
1499
- * @default [parserTs] // from @kubb/parser-ts
1500
1622
  * @example
1501
1623
  * ```ts
1502
- * import { parserTs } from '@kubb/parser-ts'
1503
- * import { parserJsonSchema } from '@kubb/parser-json-schema'
1624
+ * import { pluginTs } from '@kubb/plugin-ts'
1625
+ * import { pluginZod } from '@kubb/plugin-zod'
1504
1626
  *
1505
- * parsers: [parserTs(), parserJsonSchema()]
1627
+ * plugins: [
1628
+ * pluginTs({ output: { path: './src/gen' } }),
1629
+ * pluginZod({ output: { path: './src/gen' } }),
1630
+ * ]
1506
1631
  * ```
1507
- *
1508
- * @see {@link Parser} to implement a custom parser.
1509
1632
  */
1510
- parsers?: Array<Parser>;
1633
+ plugins: Array<Plugin>;
1511
1634
  /**
1512
- * Adapter that parses your API specification (OpenAPI, GraphQL, AsyncAPI, etc.) into Kubb's universal AST.
1635
+ * Middleware instances that observe build events and post-process generated code.
1513
1636
  *
1514
- * The adapter bridge between your input format and Kubb's internal representation. By default, uses the OAS adapter.
1515
- * Pass an alternative adapter (or multiple configs with different adapters) to support different spec formats.
1637
+ * Middleware fires AFTER all plugins for each event. Perfect for tasks like:
1638
+ * - Auditing what was generated
1639
+ * - Adding barrel/index files
1640
+ * - Validating output
1641
+ * - Running custom transformations
1516
1642
  *
1517
- * @default new OasAdapter() // from @kubb/adapter-oas
1518
1643
  * @example
1519
1644
  * ```ts
1520
- * import { Oas } from '@kubb/adapter-oas'
1645
+ * import { middlewareBarrel } from '@kubb/middleware-barrel'
1521
1646
  *
1522
- * adapter: new Oas({ apiVersion: '3.0.0' })
1647
+ * middleware: [middlewareBarrel()]
1523
1648
  * ```
1524
1649
  *
1525
- * @see {@link Adapter} to implement a custom adapter for GraphQL or other formats.
1650
+ * @see {@link defineMiddleware} to create custom middleware.
1526
1651
  */
1527
- adapter?: Adapter;
1652
+ middleware?: Array<Middleware>;
1528
1653
  /**
1529
- * Plugins that execute during the build to generate code and transform the AST.
1654
+ * Renderer that converts generated AST nodes to code strings.
1530
1655
  *
1531
- * Each plugin processes the AST produced by the adapter and can emit files for different
1532
- * programming languages or formats (TypeScript, Zod schemas, Faker data, etc.).
1656
+ * By default, Kubb uses the JSX renderer (`rendererJsx`). Pass a custom renderer to support
1657
+ * different output formats (template engines, code generation DSLs, etc.).
1533
1658
  *
1534
- * @default [] // no plugins (useful for setup/testing)
1659
+ * @default rendererJsx() // from @kubb/renderer-jsx
1535
1660
  * @example
1536
1661
  * ```ts
1537
- * plugins: [
1538
- * pluginTs({ output: { path: './src/gen' } }),
1539
- * pluginZod({ output: { path: './src/gen' } }),
1540
- * ]
1662
+ * import { rendererJsx } from '@kubb/renderer-jsx'
1663
+ * renderer: rendererJsx()
1541
1664
  * ```
1542
- *
1543
- * @see {@link definePlugin} to create a custom plugin.
1544
- */
1545
- plugins?: Array<Plugin>;
1546
- };
1547
- type ResolveNameParams = {
1548
- name: string;
1549
- pluginName?: string;
1550
- /**
1551
- * Entity type being named.
1552
- * - `'file'` — file name (camelCase)
1553
- * - `'function'` — exported function name (camelCase)
1554
- * - `'type'` — TypeScript type name (PascalCase)
1555
- * - `'const'` — variable name (camelCase)
1556
- */
1557
- type?: 'file' | 'function' | 'type' | 'const';
1558
- };
1559
- /**
1560
- * Context object passed to generator `schema`, `operation`, and `operations` methods.
1561
- *
1562
- * The adapter is always defined (guaranteed by `runPluginAstHooks`) so no runtime checks
1563
- * are needed. `ctx.options` carries resolved per-node options after exclude/include/override
1564
- * filtering for individual schema/operation calls, or plugin-level options for operations.
1565
- */
1566
- type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
1567
- config: Config;
1568
- /**
1569
- * Absolute path to the current plugin's output directory.
1570
- */
1571
- root: string;
1572
- /**
1573
- * Determine output mode based on the output config.
1574
- * Returns `'single'` when `output.path` is a file, `'split'` for a directory.
1575
- */
1576
- getMode: (output: {
1577
- path: string;
1578
- }) => 'single' | 'split';
1579
- driver: PluginDriver;
1580
- /**
1581
- * Get a plugin by name, typed via `Kubb.PluginRegistry` when registered.
1582
- */
1583
- getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
1584
- getPlugin(name: string): Plugin | undefined;
1585
- /**
1586
- * Get a plugin by name, throws an error if not found.
1587
- */
1588
- requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>;
1589
- requirePlugin(name: string): Plugin;
1590
- /**
1591
- * Get a resolver by plugin name, typed via `Kubb.PluginRegistry` when registered.
1592
- */
1593
- getResolver<TName extends keyof Kubb.PluginRegistry>(name: TName): Kubb.PluginRegistry[TName]['resolver'];
1594
- getResolver(name: string): Resolver;
1595
- /**
1596
- * Add files only if they don't exist.
1597
- */
1598
- addFile: (...file: Array<FileNode>) => Promise<void>;
1599
- /**
1600
- * Merge sources into the same output file.
1601
- */
1602
- upsertFile: (...file: Array<FileNode>) => Promise<void>;
1603
- hooks: AsyncEventEmitter<KubbHooks>;
1604
- /**
1605
- * The current plugin instance.
1606
- */
1607
- plugin: Plugin<TOptions>;
1608
- /**
1609
- * The current plugin's resolver.
1610
- */
1611
- resolver: TOptions['resolver'];
1612
- /**
1613
- * The current plugin's transformer.
1614
- */
1615
- transformer: Visitor | undefined;
1616
- /**
1617
- * Emit a warning.
1618
- */
1619
- warn: (message: string) => void;
1620
- /**
1621
- * Emit an error.
1622
- */
1623
- error: (error: string | Error) => void;
1624
- /**
1625
- * Emit an info message.
1626
- */
1627
- info: (message: string) => void;
1628
- /**
1629
- * Open the current input node in Kubb Studio.
1630
- */
1631
- openInStudio: (options?: DevtoolsOptions) => Promise<void>;
1632
- /**
1633
- * The configured adapter instance.
1634
- */
1635
- adapter: Adapter;
1636
- /**
1637
- * The universal `InputNode` produced by the adapter.
1638
- */
1639
- inputNode: InputNode;
1640
- /**
1641
- * Resolved options after exclude/include/override filtering.
1642
- */
1643
- options: TOptions['resolvedOptions'];
1644
- };
1645
- /**
1646
- * Output configuration for generated files.
1647
- */
1648
- type Output<_TOptions = unknown> = {
1649
- /**
1650
- * Output folder or file path for generated code.
1651
- */
1652
- path: string;
1653
- /**
1654
- * Text or function prepended to every generated file.
1655
- * When a function, receives the current `InputNode` and returns a string.
1656
- */
1657
- banner?: string | ((node?: InputNode) => string);
1658
- /**
1659
- * Text or function appended to every generated file.
1660
- * When a function, receives the current `InputNode` and returns a string.
1661
- */
1662
- footer?: string | ((node?: InputNode) => string);
1663
- /**
1664
- * Whether to override existing external files if they already exist.
1665
- * @default false
1666
- */
1667
- override?: boolean;
1668
- } & ExtractRegistryKey<Kubb.PluginOptionsRegistry, 'output'>;
1669
- type Group = {
1670
- /**
1671
- * How to group files into subdirectories.
1672
- * - `'tag'` — group by OpenAPI tags
1673
- * - `'path'` — group by OpenAPI paths
1674
- */
1675
- type: 'tag' | 'path';
1676
- /**
1677
- * Function that returns the subdirectory name for a group value.
1678
- * Defaults to `${camelCase(group)}Controller` for tags, first path segment for paths.
1679
- */
1680
- name?: (context: {
1681
- group: string;
1682
- }) => string;
1683
- };
1684
- type LoggerOptions = {
1685
- /**
1686
- * Log level for output verbosity.
1687
- * @default 3
1688
- */
1689
- logLevel: (typeof logLevel)[keyof typeof logLevel];
1690
- };
1691
- /**
1692
- * Shared context passed to plugins, parsers, and other internals.
1693
- */
1694
- type LoggerContext = AsyncEventEmitter<KubbHooks>;
1695
- type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
1696
- name: string;
1697
- install: (context: LoggerContext, options?: TOptions) => void | Promise<void>;
1698
- };
1699
- type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Logger<TOptions>;
1700
- /**
1701
- * Context for hook-style plugin `kubb:plugin:setup` handler.
1702
- * Provides methods to register generators, configure resolvers, transformers, and renderers.
1703
- */
1704
- type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
1705
- /**
1706
- * Register a generator dynamically. Generators fire during the AST walk (schema/operation/operations)
1707
- * just like generators declared statically on `createPlugin`.
1708
- */
1709
- addGenerator<TElement = unknown>(generator: Generator<TFactory, TElement>): void;
1710
- /**
1711
- * Set or override the resolver for this plugin.
1712
- * The resolver controls file naming and path resolution.
1665
+ *
1666
+ * @see {@link Renderer} to implement a custom renderer.
1713
1667
  */
1714
- setResolver(resolver: Partial<TFactory['resolver']>): void;
1668
+ renderer?: RendererFactory;
1715
1669
  /**
1716
- * Set the AST transformer to pre-process nodes before they reach generators.
1670
+ * Kubb Studio cloud integration settings.
1671
+ *
1672
+ * Kubb Studio (https://kubb.studio) is a web-based IDE for managing API specs and generated code.
1673
+ * Set to `true` to enable with default settings, or pass an object to customize the Studio URL.
1674
+ *
1675
+ * @default false // disabled by default
1676
+ * @example
1677
+ * ```ts
1678
+ * devtools: true // use default Kubb Studio
1679
+ * devtools: { studioUrl: 'https://my-studio.dev' } // custom Studio instance
1680
+ * ```
1717
1681
  */
1718
- setTransformer(visitor: Visitor): void;
1682
+ devtools?: true | {
1683
+ /**
1684
+ * Override the Kubb Studio base URL.
1685
+ * @default 'https://kubb.studio'
1686
+ */
1687
+ studioUrl?: typeof DEFAULT_STUDIO_URL | (string & {});
1688
+ };
1719
1689
  /**
1720
- * Set the renderer factory to process JSX elements from generators.
1690
+ * Lifecycle hooks that execute during or after the build process.
1691
+ *
1692
+ * Hooks allow you to run external tools (prettier, eslint, custom scripts) based on build events.
1693
+ * Currently supports the `done` hook which fires after all plugins and middleware complete.
1694
+ *
1695
+ * @example
1696
+ * ```ts
1697
+ * hooks: {
1698
+ * done: 'prettier --write "./src/gen"', // auto-format generated files
1699
+ * // or multiple commands:
1700
+ * done: ['prettier --write "./src/gen"', 'eslint --fix "./src/gen"']
1701
+ * }
1702
+ * ```
1721
1703
  */
1722
- setRenderer(renderer: RendererFactory): void;
1704
+ hooks?: {
1705
+ /**
1706
+ * Command(s) to run after all plugins and middleware complete generation.
1707
+ *
1708
+ * Useful for post-processing: formatting, linting, copying files, or custom validation.
1709
+ * Pass a single command string or array of command strings to run sequentially.
1710
+ * Commands are executed relative to the `root` directory.
1711
+ *
1712
+ * @example
1713
+ * ```ts
1714
+ * done: 'prettier --write "./src/gen"'
1715
+ * done: ['prettier --write "./src/gen"', 'eslint --fix "./src/gen"']
1716
+ * ```
1717
+ */
1718
+ done?: string | Array<string>;
1719
+ };
1720
+ };
1721
+ /**
1722
+ * Partial `Config` for user-facing entry points with sensible defaults.
1723
+ *
1724
+ * `UserConfig` is what you pass to `defineConfig()`. It has optional `root`, `plugins`, `parsers`, and `adapter`
1725
+ * fields (which fall back to sensible defaults). All other Config options are available, including `output`, `input`,
1726
+ * `storage`, `middleware`, `renderer`, `devtools`, and `hooks`.
1727
+ *
1728
+ * @example
1729
+ * ```ts
1730
+ * export default defineConfig({
1731
+ * input: { path: './petstore.yaml' },
1732
+ * output: { path: './src/gen' },
1733
+ * plugins: [pluginTs(), pluginZod()],
1734
+ * })
1735
+ * ```
1736
+ */
1737
+ type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter' | 'storage'> & {
1723
1738
  /**
1724
- * Set resolved options merged into the normalized plugin's `options`.
1725
- * Call this in `kubb:plugin:setup` to provide options generators need.
1739
+ * Project root directory, absolute or relative to the config file location.
1740
+ * @default process.cwd()
1726
1741
  */
1727
- setOptions(options: TFactory['resolvedOptions']): void;
1742
+ root?: string;
1728
1743
  /**
1729
- * Inject a raw file into the build output, bypassing the generation pipeline.
1744
+ * Custom parsers that convert generated AST nodes to strings (TypeScript, JSON, markdown, etc.).
1745
+ * @default [parserTs] // from `@kubb/parser-ts`
1730
1746
  */
1731
- injectFile(userFileNode: UserFileNode): void;
1747
+ parsers?: Array<Parser>;
1732
1748
  /**
1733
- * Merge a partial config update into the current build configuration.
1749
+ * Adapter that parses your API specification into Kubb's universal AST.
1750
+ * When omitted, Kubb runs in plugin-only mode.
1734
1751
  */
1735
- updateConfig(config: Partial<Config>): void;
1752
+ adapter?: Adapter;
1736
1753
  /**
1737
- * The resolved build configuration at setup time.
1754
+ * Plugins that execute during the build to generate code and transform the AST.
1755
+ * @default []
1738
1756
  */
1739
- config: Config;
1757
+ plugins?: Array<Plugin>;
1740
1758
  /**
1741
- * The plugin's user-provided options.
1759
+ * Storage backend that controls where and how generated files are persisted.
1760
+ * @default fsStorage()
1742
1761
  */
1743
- options: TFactory['options'];
1762
+ storage?: Storage;
1744
1763
  };
1764
+ declare global {
1765
+ namespace Kubb {
1766
+ /**
1767
+ * Registry that maps plugin names to their `PluginFactoryOptions`.
1768
+ * Augment this interface in each plugin's `types.ts` to enable automatic
1769
+ * typing for `getPlugin` and `requirePlugin`.
1770
+ *
1771
+ * @example
1772
+ * ```ts
1773
+ * // packages/plugin-ts/src/types.ts
1774
+ * declare global {
1775
+ * namespace Kubb {
1776
+ * interface PluginRegistry {
1777
+ * 'plugin-ts': PluginTs
1778
+ * }
1779
+ * }
1780
+ * }
1781
+ * ```
1782
+ */
1783
+ interface PluginRegistry {}
1784
+ /**
1785
+ * Extension point for root `Config['output']` options.
1786
+ * Augment the `output` key in middleware or plugin packages to add extra fields
1787
+ * to the global output configuration without touching core types.
1788
+ *
1789
+ * @example
1790
+ * ```ts
1791
+ * // packages/middleware-barrel/src/types.ts
1792
+ * declare global {
1793
+ * namespace Kubb {
1794
+ * interface ConfigOptionsRegistry {
1795
+ * output: {
1796
+ * barrel?: import('./types.ts').BarrelConfig | false
1797
+ * }
1798
+ * }
1799
+ * }
1800
+ * }
1801
+ * ```
1802
+ */
1803
+ interface ConfigOptionsRegistry {}
1804
+ /**
1805
+ * Extension point for per-plugin `Output` options.
1806
+ * Augment the `output` key in middleware or plugin packages to add extra fields
1807
+ * to the per-plugin output configuration without touching core types.
1808
+ *
1809
+ * @example
1810
+ * ```ts
1811
+ * // packages/middleware-barrel/src/types.ts
1812
+ * declare global {
1813
+ * namespace Kubb {
1814
+ * interface PluginOptionsRegistry {
1815
+ * output: {
1816
+ * barrel?: import('./types.ts').PluginBarrelConfig | false
1817
+ * }
1818
+ * }
1819
+ * }
1820
+ * }
1821
+ * ```
1822
+ */
1823
+ interface PluginOptionsRegistry {}
1824
+ }
1825
+ }
1745
1826
  /**
1746
- * Context for hook-style plugin `kubb:build:start` handler.
1747
- * Fires immediately before the plugin execution loop begins.
1827
+ * Lifecycle events emitted during Kubb code generation.
1828
+ * Use these for logging, progress tracking, and custom integrations.
1829
+ *
1830
+ * @example
1831
+ * ```typescript
1832
+ * import type { AsyncEventEmitter } from '@internals/utils'
1833
+ * import type { KubbHooks } from '@kubb/core'
1834
+ *
1835
+ * const hooks: AsyncEventEmitter<KubbHooks> = new AsyncEventEmitter()
1836
+ *
1837
+ * hooks.on('kubb:lifecycle:start', () => {
1838
+ * console.log('Starting Kubb generation')
1839
+ * })
1840
+ *
1841
+ * hooks.on('kubb:plugin:end', ({ plugin, duration }) => {
1842
+ * console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
1843
+ * })
1844
+ * ```
1748
1845
  */
1846
+ interface KubbHooks {
1847
+ 'kubb:lifecycle:start': [ctx: KubbLifecycleStartContext];
1848
+ 'kubb:lifecycle:end': [];
1849
+ 'kubb:config:start': [];
1850
+ 'kubb:config:end': [ctx: KubbConfigEndContext];
1851
+ 'kubb:generation:start': [ctx: KubbGenerationStartContext];
1852
+ 'kubb:generation:end': [ctx: KubbGenerationEndContext];
1853
+ 'kubb:generation:summary': [ctx: KubbGenerationSummaryContext];
1854
+ 'kubb:format:start': [];
1855
+ 'kubb:format:end': [];
1856
+ 'kubb:lint:start': [];
1857
+ 'kubb:lint:end': [];
1858
+ 'kubb:hooks:start': [];
1859
+ 'kubb:hooks:end': [];
1860
+ 'kubb:hook:start': [ctx: KubbHookStartContext];
1861
+ 'kubb:hook:end': [ctx: KubbHookEndContext];
1862
+ 'kubb:version:new': [ctx: KubbVersionNewContext];
1863
+ 'kubb:info': [ctx: KubbInfoContext];
1864
+ 'kubb:error': [ctx: KubbErrorContext];
1865
+ 'kubb:success': [ctx: KubbSuccessContext];
1866
+ 'kubb:warn': [ctx: KubbWarnContext];
1867
+ 'kubb:debug': [ctx: KubbDebugContext];
1868
+ 'kubb:files:processing:start': [ctx: KubbFilesProcessingStartContext];
1869
+ 'kubb:file:processing:update': [ctx: KubbFileProcessingUpdateContext];
1870
+ 'kubb:files:processing:end': [ctx: KubbFilesProcessingEndContext];
1871
+ 'kubb:plugin:start': [ctx: KubbPluginStartContext];
1872
+ 'kubb:plugin:end': [ctx: KubbPluginEndContext];
1873
+ 'kubb:plugin:setup': [ctx: KubbPluginSetupContext];
1874
+ 'kubb:build:start': [ctx: KubbBuildStartContext];
1875
+ 'kubb:plugins:end': [ctx: KubbPluginsEndContext];
1876
+ 'kubb:build:end': [ctx: KubbBuildEndContext];
1877
+ 'kubb:generate:schema': [node: SchemaNode, ctx: GeneratorContext];
1878
+ 'kubb:generate:operation': [node: OperationNode, ctx: GeneratorContext];
1879
+ 'kubb:generate:operations': [nodes: Array<OperationNode>, ctx: GeneratorContext];
1880
+ }
1749
1881
  type KubbBuildStartContext = {
1750
1882
  config: Config;
1751
1883
  adapter: Adapter;
1752
1884
  inputNode: InputNode;
1753
- /**
1754
- * Get a plugin by name, typed via `Kubb.PluginRegistry` when registered.
1755
- */
1756
- getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
1885
+ getPlugin<TName extends keyof Kubb$1.PluginRegistry>(name: TName): Plugin<Kubb$1.PluginRegistry[TName]> | undefined;
1757
1886
  getPlugin(name: string): Plugin | undefined;
1758
- /**
1759
- * Get all files currently in the file manager.
1760
- * Call this lazily (e.g. in `kubb:plugin:end`) to see files added by prior plugins.
1761
- */
1762
1887
  readonly files: ReadonlyArray<FileNode>;
1763
- /**
1764
- * Upsert one or more files into the file manager.
1765
- * Files with the same path are merged; new files are appended.
1766
- * Safe to call at any point during the plugin lifecycle, including inside `kubb:plugin:end`.
1767
- */
1768
1888
  upsertFile: (...files: Array<FileNode>) => void;
1769
1889
  };
1770
- /**
1771
- * Context for `kubb:plugins:end` handlers.
1772
- * Fires after plugins run and per-plugin barrels are written, before final write to disk.
1773
- * Middleware that needs final files (e.g. root barrel) use this event.
1774
- */
1775
1890
  type KubbPluginsEndContext = {
1776
1891
  config: Config;
1777
- /**
1778
- * All files currently in the file manager (lazy snapshot).
1779
- */
1780
1892
  readonly files: ReadonlyArray<FileNode>;
1781
- /**
1782
- * Upsert files into the file manager.
1783
- * Files added here are included in the write pass.
1784
- */
1785
1893
  upsertFile: (...files: Array<FileNode>) => void;
1786
1894
  };
1787
- /**
1788
- * Context for hook-style plugin `kubb:build:end` handler.
1789
- * Fires after all files have been written to disk.
1790
- */
1791
1895
  type KubbBuildEndContext = {
1792
1896
  files: Array<FileNode>;
1793
1897
  config: Config;
@@ -1847,52 +1951,15 @@ type KubbFilesProcessingStartContext = {
1847
1951
  files: Array<FileNode>;
1848
1952
  };
1849
1953
  type KubbFileProcessingUpdateContext = {
1850
- /**
1851
- * Number of files processed.
1852
- */
1853
1954
  processed: number;
1854
- /**
1855
- * Total files to process.
1856
- */
1857
1955
  total: number;
1858
- /**
1859
- * Processing percentage (0–100).
1860
- */
1861
1956
  percentage: number;
1862
- /**
1863
- * Optional source identifier.
1864
- */
1865
1957
  source?: string;
1866
- /**
1867
- * The file being processed.
1868
- */
1869
1958
  file: FileNode;
1870
- /**
1871
- * The current build configuration.
1872
- */
1873
- config: Config;
1874
- };
1875
- type KubbFilesProcessingEndContext = {
1876
- files: Array<FileNode>;
1877
- };
1878
- type KubbPluginStartContext = {
1879
- plugin: NormalizedPlugin;
1880
- };
1881
- type KubbPluginEndContext = {
1882
- plugin: NormalizedPlugin;
1883
- duration: number;
1884
- success: boolean;
1885
- error?: Error;
1886
1959
  config: Config;
1887
- /**
1888
- * Returns all files currently in the file manager (lazy snapshot).
1889
- * Includes files added by plugins that have already run.
1890
- */
1891
- readonly files: ReadonlyArray<FileNode>;
1892
- /**
1893
- * Upsert one or more files into the file manager.
1894
- */
1895
- upsertFile: (...files: Array<FileNode>) => void;
1960
+ };
1961
+ type KubbFilesProcessingEndContext = {
1962
+ files: Array<FileNode>;
1896
1963
  };
1897
1964
  type KubbHookStartContext = {
1898
1965
  id?: string;
@@ -1906,243 +1973,110 @@ type KubbHookEndContext = {
1906
1973
  success: boolean;
1907
1974
  error: Error | null;
1908
1975
  };
1909
- type ByTag = {
1910
- /**
1911
- * Filter by OpenAPI `tags` field. Matches one or more tags assigned to operations.
1912
- */
1913
- type: 'tag';
1914
- /**
1915
- * Tag name to match (case-sensitive). Can be a literal string or regex pattern.
1916
- */
1917
- pattern: string | RegExp;
1976
+ /**
1977
+ * CLI options derived from command-line flags.
1978
+ */
1979
+ type CLIOptions = {
1980
+ config?: string;
1981
+ watch?: boolean; /** @default 'silent' */
1982
+ logLevel?: 'silent' | 'info' | 'debug';
1918
1983
  };
1919
- type ByOperationId = {
1984
+ /**
1985
+ * All accepted forms of a Kubb configuration.
1986
+ * Accepts `Config`/`Config[]`/promise or a factory (optionally receiving `TCliOptions`).
1987
+ */
1988
+ type PossibleConfig<TCliOptions = undefined> = PossiblePromise<Config | Config[]> | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Config[]>);
1989
+ /**
1990
+ * Full output produced by a successful or failed build.
1991
+ */
1992
+ type BuildOutput = {
1920
1993
  /**
1921
- * Filter by OpenAPI `operationId` field. Each operation (GET, POST, etc.) has a unique identifier.
1994
+ * Plugins that threw during installation, paired with the caught error.
1922
1995
  */
1923
- type: 'operationId';
1996
+ failedPlugins: Set<{
1997
+ plugin: Plugin;
1998
+ error: Error;
1999
+ }>;
2000
+ files: Array<FileNode>;
2001
+ driver: PluginDriver;
1924
2002
  /**
1925
- * Operation ID to match (case-sensitive). Can be a literal string or regex pattern.
2003
+ * Elapsed time in milliseconds for each plugin, keyed by plugin name.
1926
2004
  */
1927
- pattern: string | RegExp;
1928
- };
1929
- type ByPath = {
2005
+ pluginTimings: Map<string, number>;
2006
+ error?: Error;
1930
2007
  /**
1931
- * Filter by OpenAPI `path` (URL endpoint). Useful to group or filter by service segments like `/pets`, `/users`, etc.
2008
+ * Raw generated source, keyed by absolute file path.
1932
2009
  */
1933
- type: 'path';
2010
+ sources: Map<string, string>;
2011
+ };
2012
+ /**
2013
+ * Kubb code generation instance returned by {@link createKubb}.
2014
+ *
2015
+ * Use this when orchestrating multiple builds, inspecting plugin timings, or integrating Kubb into a larger toolchain.
2016
+ * For a single one-off build, chain directly: `await createKubb(config).build()`.
2017
+ */
2018
+ type Kubb$1 = {
1934
2019
  /**
1935
- * URL path to match (case-sensitive). Can be a literal string or regex pattern. Matches against the full path.
2020
+ * Shared event emitter for lifecycle and status events. Attach listeners before calling `setup()` or `build()`.
1936
2021
  */
1937
- pattern: string | RegExp;
1938
- };
1939
- type ByMethod = {
2022
+ readonly hooks: AsyncEventEmitter<KubbHooks>;
1940
2023
  /**
1941
- * Filter by HTTP method: `'get'`, `'post'`, `'put'`, `'delete'`, `'patch'`, `'head'`, `'options'`.
2024
+ * Generated source code keyed by absolute file path. Available after `build()` or `safeBuild()` completes.
1942
2025
  */
1943
- type: 'method';
2026
+ readonly sources: Map<string, string>;
1944
2027
  /**
1945
- * HTTP method to match (case-insensitive when using string, or regex for dynamic matching).
2028
+ * Plugin driver managing all plugins. Available after `setup()` completes.
1946
2029
  */
1947
- pattern: HttpMethod | RegExp;
1948
- };
1949
- type BySchemaName = {
2030
+ readonly driver: PluginDriver | undefined;
1950
2031
  /**
1951
- * Filter by schema component name (TypeScript or JSON schema). Matches schemas in `#/components/schemas`.
2032
+ * Resolved configuration with defaults applied. Available after `setup()` completes.
1952
2033
  */
1953
- type: 'schemaName';
2034
+ readonly config: Config | undefined;
1954
2035
  /**
1955
- * Schema name to match (case-sensitive). Can be a literal string or regex pattern.
2036
+ * Resolves config and initializes the driver. `build()` calls this automatically.
1956
2037
  */
1957
- pattern: string | RegExp;
1958
- };
1959
- type ByContentType = {
2038
+ setup(): Promise<void>;
1960
2039
  /**
1961
- * Filter by response or request content type: `'application/json'`, `'application/xml'`, etc.
2040
+ * Runs the full pipeline and throws on any plugin error. Automatically calls `setup()` if needed.
1962
2041
  */
1963
- type: 'contentType';
2042
+ build(): Promise<BuildOutput>;
1964
2043
  /**
1965
- * Content type to match (case-sensitive). Can be a literal string or regex pattern.
2044
+ * Runs the full pipeline and captures errors in `BuildOutput` instead of throwing. Automatically calls `setup()` if needed.
1966
2045
  */
1967
- pattern: string | RegExp;
2046
+ safeBuild(): Promise<BuildOutput>;
1968
2047
  };
1969
2048
  /**
1970
- * A pattern filter that prevents matching nodes from being generated.
1971
- *
1972
- * Use to skip code generation for specific operations or schemas. For example, exclude deprecated endpoints
1973
- * or internal-only schemas. Can filter by tag, operationId, path, HTTP method, content type, or schema name.
1974
- *
1975
- * @example
1976
- * ```ts
1977
- * exclude: [
1978
- * { type: 'tag', pattern: 'internal' }, // skip "internal" tag
1979
- * { type: 'path', pattern: /^\/admin/ }, // skip all /admin endpoints
1980
- * { type: 'operationId', pattern: 'deprecated_*' } // skip operationIds matching pattern
1981
- * ]
1982
- * ```
1983
- */
1984
- type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
1985
- /**
1986
- * A pattern filter that restricts generation to only matching nodes.
1987
- *
1988
- * Use to generate code for a subset of operations or schemas. For example, only generate for a specific service
1989
- * tag or only for "production" endpoints. Can filter by tag, operationId, path, HTTP method, content type, or schema name.
1990
- *
1991
- * @example
1992
- * ```ts
1993
- * include: [
1994
- * { type: 'tag', pattern: 'public' }, // generate only "public" tag
1995
- * { type: 'path', pattern: /^\/api\/v1/ }, // generate only v1 endpoints
1996
- * ]
1997
- * ```
1998
- */
1999
- type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
2000
- /**
2001
- * A pattern filter paired with partial option overrides applied when the pattern matches.
2002
- *
2003
- * Use to customize generation for specific operations or schemas. For example, apply different output paths
2004
- * for different tags, or use custom resolver functions per operation. Can filter by tag, operationId, path,
2005
- * HTTP method, schema name, or content type.
2006
- *
2007
- * @example
2008
- * ```ts
2009
- * override: [
2010
- * {
2011
- * type: 'tag',
2012
- * pattern: 'admin',
2013
- * options: { output: { path: './src/gen/admin' } } // admin APIs go to separate folder
2014
- * },
2015
- * {
2016
- * type: 'operationId',
2017
- * pattern: 'listPets',
2018
- * options: { exclude: true } // skip this specific operation
2019
- * }
2020
- * ]
2021
- * ```
2049
+ * Type guard to check if a given config has an `input.path`.
2022
2050
  */
2023
- type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
2024
- options: Partial<TOptions>;
2051
+ declare function isInputPath(config: UserConfig | undefined): config is UserConfig<InputPath> & {
2052
+ input: InputPath;
2025
2053
  };
2026
- /**
2027
- * File-specific parameters for `Resolver.resolvePath`.
2028
- *
2029
- * Pass alongside a `ResolverContext` to identify which file to resolve.
2030
- * Provide `tag` for tag-based grouping or `path` for path-based grouping.
2031
- *
2032
- * @example
2033
- * ```ts
2034
- * resolver.resolvePath(
2035
- * { baseName: 'petTypes.ts', tag: 'pets' },
2036
- * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
2037
- * )
2038
- * // → '/src/types/petsController/petTypes.ts'
2039
- * ```
2040
- */
2041
- type ResolverPathParams = {
2042
- baseName: FileNode['baseName'];
2043
- pathMode?: 'single' | 'split';
2044
- /**
2045
- * Tag value used when `group.type === 'tag'`.
2046
- */
2047
- tag?: string;
2048
- /**
2049
- * Path value used when `group.type === 'path'`.
2050
- */
2051
- path?: string;
2054
+ declare function isInputPath(config: Config | undefined): config is Config<InputPath> & {
2055
+ input: InputPath;
2052
2056
  };
2053
- /**
2054
- * Shared context passed as the second argument to `Resolver.resolvePath` and `Resolver.resolveFile`.
2055
- *
2056
- * Describes where on disk output is rooted, which output config is active, and the optional
2057
- * grouping strategy that controls subdirectory layout.
2058
- *
2059
- * @example
2060
- * ```ts
2061
- * const context: ResolverContext = {
2062
- * root: config.root,
2063
- * output,
2064
- * group,
2065
- * }
2066
- * ```
2067
- */
2068
- type ResolverContext = {
2069
- root: string;
2070
- output: Output;
2071
- group?: Group;
2072
- /**
2073
- * Plugin name used to populate `meta.pluginName` on the resolved file.
2074
- */
2075
- pluginName?: string;
2057
+ type CreateKubbOptions = {
2058
+ hooks?: AsyncEventEmitter<KubbHooks>;
2076
2059
  };
2077
2060
  /**
2078
- * File-specific parameters for `Resolver.resolveFile`.
2061
+ * Creates a Kubb instance bound to a single config entry.
2079
2062
  *
2080
- * Pass alongside a `ResolverContext` to fully describe the file to resolve.
2081
- * `tag` and `path` are used only when a matching `group` is present in the context.
2063
+ * Accepts a user-facing config shape and resolves it to a full {@link Config} during
2064
+ * `setup()`. The instance then holds shared state (`hooks`, `sources`, `driver`, `config`)
2065
+ * across the `setup → build` lifecycle. Attach event listeners to `kubb.hooks` before
2066
+ * calling `setup()` or `build()`.
2082
2067
  *
2083
2068
  * @example
2084
2069
  * ```ts
2085
- * resolver.resolveFile(
2086
- * { name: 'listPets', extname: '.ts', tag: 'pets' },
2087
- * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
2088
- * )
2089
- * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
2090
- * ```
2091
- */
2092
- type ResolverFileParams = {
2093
- name: string;
2094
- extname: FileNode['extname'];
2095
- /**
2096
- * Tag value used when `group.type === 'tag'`.
2097
- */
2098
- tag?: string;
2099
- /**
2100
- * Path value used when `group.type === 'path'`.
2101
- */
2102
- path?: string;
2103
- };
2104
- /**
2105
- * Context passed to `Resolver.resolveBanner` and `Resolver.resolveFooter`.
2070
+ * const kubb = createKubb(userConfig)
2106
2071
  *
2107
- * `output` is optional not every plugin configures a banner/footer.
2108
- * `config` carries the global Kubb config, used to derive the default Kubb banner.
2072
+ * kubb.hooks.on('kubb:plugin:end', ({ plugin, duration }) => {
2073
+ * console.log(`${plugin.name} completed in ${duration}ms`)
2074
+ * })
2109
2075
  *
2110
- * @example
2111
- * ```ts
2112
- * resolver.resolveBanner(inputNode, { output: { banner: '// generated' }, config })
2113
- * // → '// generated'
2076
+ * const { files, failedPlugins } = await kubb.safeBuild()
2114
2077
  * ```
2115
2078
  */
2116
- type ResolveBannerContext = {
2117
- output?: Pick<Output, 'banner' | 'footer'>;
2118
- config: Config;
2119
- };
2120
- /**
2121
- * CLI options derived from command-line flags.
2122
- */
2123
- type CLIOptions = {
2124
- /**
2125
- * Path to `kubb.config.js`.
2126
- */
2127
- config?: string;
2128
- /**
2129
- * Enable watch mode for input files.
2130
- */
2131
- watch?: boolean;
2132
- /**
2133
- * Logging verbosity for CLI usage.
2134
- * @default 'silent'
2135
- */
2136
- logLevel?: 'silent' | 'info' | 'debug';
2137
- };
2138
- /**
2139
- * All accepted forms of a Kubb configuration.
2140
- *
2141
- * Config is always `@kubb/core` {@link Config}.
2142
- * - `PossibleConfig` accepts `Config`/`Config[]`/promise or a no-arg config factory.
2143
- * - `PossibleConfig<TCliOptions>` accepts the same config forms or a config factory receiving `TCliOptions`.
2144
- */
2145
- type PossibleConfig<TCliOptions = undefined> = PossiblePromise<Config | Config[]> | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Config[]>);
2079
+ declare function createKubb(userConfig: UserConfig, options?: CreateKubbOptions): Kubb$1;
2146
2080
  //#endregion
2147
- export { defineParser as $, KubbPluginStartContext as A, Override as B, KubbGenerationSummaryContext as C, KubbLifecycleStartContext as D, KubbInfoContext as E, Logger as F, ResolveOptionsContext as G, PossibleConfig as H, LoggerContext as I, ResolverFileParams as J, Resolver as K, LoggerOptions as L, KubbSuccessContext as M, KubbVersionNewContext as N, KubbPluginEndContext as O, KubbWarnContext as P, Parser as Q, NormalizedPlugin as R, KubbGenerationStartContext as S, KubbHookStartContext as T, ResolveBannerContext as U, PluginFactoryOptions as V, ResolveNameParams as W, UserConfig as X, ResolverPathParams as Y, UserLogger as Z, KubbErrorContext as _, logLevel as _t, Config as a, createKubb as at, KubbFilesProcessingStartContext as b, GeneratorContext as c, Plugin as ct, InputData as d, defineGenerator as dt, Middleware as et, InputPath as f, Storage as ft, KubbDebugContext as g, createRenderer as gt, KubbConfigEndContext as h, RendererFactory as ht, CLIOptions as i, BuildOutput as it, KubbPluginsEndContext as j, KubbPluginSetupContext as k, Group as l, definePlugin as lt, KubbBuildStartContext as m, Renderer as mt, AdapterFactoryOptions as n, Kubb$1 as nt, DevtoolsOptions as o, PluginDriver as ot, KubbBuildEndContext as p, createStorage as pt, ResolverContext as q, AdapterSource as r, KubbHooks as rt, Exclude$1 as s, FileManager as st, Adapter as t, defineMiddleware as tt, Include as u, Generator as ut, KubbFileProcessingUpdateContext as v, AsyncEventEmitter as vt, KubbHookEndContext as w, KubbGenerationEndContext as x, KubbFilesProcessingEndContext as y, Output as z };
2148
- //# sourceMappingURL=types-CuNocrbJ.d.ts.map
2081
+ export { ResolverPathParams as $, isInputPath as A, KubbPluginSetupContext as B, KubbPluginsEndContext as C, PossibleConfig as D, KubbWarnContext as E, FileManager as F, Plugin as G, NormalizedPlugin as H, Exclude as I, ResolveBannerContext as J, PluginFactoryOptions as K, Group as L, GeneratorContext as M, defineGenerator as N, UserConfig as O, PluginDriver as P, ResolverFileParams as Q, Include as R, KubbLifecycleStartContext as S, KubbVersionNewContext as T, Output as U, KubbPluginStartContext as V, Override as W, Resolver as X, ResolveOptionsContext as Y, ResolverContext as Z, KubbGenerationSummaryContext as _, AdapterFactoryOptions as _t, InputPath as a, Logger as at, KubbHooks as b, logLevel as bt, KubbBuildStartContext as c, UserLogger as ct, KubbErrorContext as d, Storage as dt, defineResolver as et, KubbFileProcessingUpdateContext as f, createStorage as ft, KubbGenerationStartContext as g, Adapter as gt, KubbGenerationEndContext as h, createRenderer as ht, InputData as i, defineMiddleware as it, Generator as j, createKubb as k, KubbConfigEndContext as l, defineLogger as lt, KubbFilesProcessingStartContext as m, RendererFactory as mt, CLIOptions as n, defineParser as nt, Kubb$1 as o, LoggerContext as ot, KubbFilesProcessingEndContext as p, Renderer as pt, definePlugin as q, Config as r, Middleware as rt, KubbBuildEndContext as s, LoggerOptions as st, BuildOutput as t, Parser as tt, KubbDebugContext as u, DevtoolsOptions as ut, KubbHookEndContext as v, AdapterSource as vt, KubbSuccessContext as w, KubbInfoContext as x, AsyncEventEmitter as xt, KubbHookStartContext as y, createAdapter as yt, KubbPluginEndContext as z };
2082
+ //# sourceMappingURL=createKubb-ALdb8lmq.d.ts.map