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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +3 -2
  2. package/dist/PluginDriver-Bc0HQM8V.js +948 -0
  3. package/dist/PluginDriver-Bc0HQM8V.js.map +1 -0
  4. package/dist/PluginDriver-Dyl2fwfQ.cjs +1039 -0
  5. package/dist/PluginDriver-Dyl2fwfQ.cjs.map +1 -0
  6. package/dist/index.cjs +691 -1798
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts +279 -265
  9. package/dist/index.js +678 -1765
  10. package/dist/index.js.map +1 -1
  11. package/dist/mocks.cjs +138 -0
  12. package/dist/mocks.cjs.map +1 -0
  13. package/dist/mocks.d.ts +74 -0
  14. package/dist/mocks.js +133 -0
  15. package/dist/mocks.js.map +1 -0
  16. package/dist/types-i0b4_23K.d.ts +1903 -0
  17. package/package.json +51 -57
  18. package/src/FileManager.ts +110 -0
  19. package/src/FileProcessor.ts +86 -0
  20. package/src/Kubb.ts +205 -130
  21. package/src/PluginDriver.ts +424 -0
  22. package/src/constants.ts +20 -47
  23. package/src/createAdapter.ts +25 -0
  24. package/src/createKubb.ts +527 -0
  25. package/src/createRenderer.ts +57 -0
  26. package/src/createStorage.ts +58 -0
  27. package/src/defineGenerator.ts +88 -100
  28. package/src/defineLogger.ts +13 -3
  29. package/src/defineMiddleware.ts +59 -0
  30. package/src/defineParser.ts +45 -0
  31. package/src/definePlugin.ts +78 -7
  32. package/src/defineResolver.ts +521 -0
  33. package/src/devtools.ts +14 -14
  34. package/src/index.ts +13 -17
  35. package/src/mocks.ts +171 -0
  36. package/src/renderNode.ts +35 -0
  37. package/src/storages/fsStorage.ts +40 -11
  38. package/src/storages/memoryStorage.ts +4 -3
  39. package/src/types.ts +738 -218
  40. package/src/utils/diagnostics.ts +4 -1
  41. package/src/utils/isInputPath.ts +10 -0
  42. package/src/utils/packageJSON.ts +99 -0
  43. package/dist/PluginManager-vZodFEMe.d.ts +0 -1056
  44. package/dist/chunk-ByKO4r7w.cjs +0 -38
  45. package/dist/hooks.cjs +0 -60
  46. package/dist/hooks.cjs.map +0 -1
  47. package/dist/hooks.d.ts +0 -64
  48. package/dist/hooks.js +0 -56
  49. package/dist/hooks.js.map +0 -1
  50. package/src/BarrelManager.ts +0 -74
  51. package/src/PackageManager.ts +0 -180
  52. package/src/PluginManager.ts +0 -667
  53. package/src/PromiseManager.ts +0 -40
  54. package/src/build.ts +0 -419
  55. package/src/config.ts +0 -56
  56. package/src/defineAdapter.ts +0 -22
  57. package/src/defineStorage.ts +0 -56
  58. package/src/errors.ts +0 -1
  59. package/src/hooks/index.ts +0 -4
  60. package/src/hooks/useKubb.ts +0 -55
  61. package/src/hooks/useMode.ts +0 -11
  62. package/src/hooks/usePlugin.ts +0 -11
  63. package/src/hooks/usePluginManager.ts +0 -11
  64. package/src/utils/FunctionParams.ts +0 -155
  65. package/src/utils/TreeNode.ts +0 -215
  66. package/src/utils/executeStrategies.ts +0 -81
  67. package/src/utils/formatters.ts +0 -56
  68. package/src/utils/getBarrelFiles.ts +0 -79
  69. package/src/utils/getConfigs.ts +0 -30
  70. package/src/utils/getPlugins.ts +0 -23
  71. package/src/utils/linters.ts +0 -25
  72. package/src/utils/resolveOptions.ts +0 -93
@@ -0,0 +1,1903 @@
1
+ import { t as __name } from "./chunk--u3MIqq1.js";
2
+ import { FileNode, HttpMethod, ImportNode, InputNode, Node, OperationNode, SchemaNode, Visitor } from "@kubb/ast";
3
+
4
+ //#region ../../internals/utils/src/asyncEventEmitter.d.ts
5
+ /**
6
+ * A function that can be registered as an event listener, synchronous or async.
7
+ */
8
+ type AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>;
9
+ /**
10
+ * Typed `EventEmitter` that awaits all async listeners before resolving.
11
+ * Wraps Node's `EventEmitter` with full TypeScript event-map inference.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const emitter = new AsyncEventEmitter<{ build: [name: string] }>()
16
+ * emitter.on('build', async (name) => { console.log(name) })
17
+ * await emitter.emit('build', 'petstore') // all listeners awaited
18
+ * ```
19
+ */
20
+ declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {
21
+ #private;
22
+ /**
23
+ * Maximum number of listeners per event before Node emits a memory-leak warning.
24
+ * @default 10
25
+ */
26
+ constructor(maxListener?: number);
27
+ /**
28
+ * Emits `eventName` and awaits all registered listeners sequentially.
29
+ * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * await emitter.emit('build', 'petstore')
34
+ * ```
35
+ */
36
+ emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
37
+ /**
38
+ * Registers a persistent listener for `eventName`.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * emitter.on('build', async (name) => { console.log(name) })
43
+ * ```
44
+ */
45
+ on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
46
+ /**
47
+ * Registers a one-shot listener that removes itself after the first invocation.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * emitter.onOnce('build', async (name) => { console.log(name) })
52
+ * ```
53
+ */
54
+ onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
55
+ /**
56
+ * Removes a previously registered listener.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * emitter.off('build', handler)
61
+ * ```
62
+ */
63
+ off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
64
+ /**
65
+ * Returns the number of listeners registered for `eventName`.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * emitter.on('build', handler)
70
+ * emitter.listenerCount('build') // 1
71
+ * ```
72
+ */
73
+ listenerCount<TEventName extends keyof TEvents & string>(eventName: TEventName): number;
74
+ /**
75
+ * Removes all listeners from every event channel.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * emitter.removeAll()
80
+ * ```
81
+ */
82
+ removeAll(): void;
83
+ }
84
+ //#endregion
85
+ //#region ../../internals/utils/src/promise.d.ts
86
+ /** A value that may already be resolved or still pending.
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * function load(id: string): PossiblePromise<string> {
91
+ * return cache.get(id) ?? fetchRemote(id)
92
+ * }
93
+ * ```
94
+ */
95
+ type PossiblePromise<T> = Promise<T> | T;
96
+ //#endregion
97
+ //#region src/constants.d.ts
98
+ /**
99
+ * Base URL for the Kubb Studio web app.
100
+ */
101
+ declare const DEFAULT_STUDIO_URL: "https://studio.kubb.dev";
102
+ /**
103
+ * Numeric log-level thresholds used internally to compare verbosity.
104
+ *
105
+ * Higher numbers are more verbose.
106
+ */
107
+ declare const logLevel: {
108
+ readonly silent: number;
109
+ readonly error: 0;
110
+ readonly warn: 1;
111
+ readonly info: 3;
112
+ readonly verbose: 4;
113
+ readonly debug: 5;
114
+ };
115
+ //#endregion
116
+ //#region src/createRenderer.d.ts
117
+ /**
118
+ * Minimal interface any Kubb renderer must satisfy.
119
+ *
120
+ * The generic `TElement` is the type of the element the renderer accepts —
121
+ * e.g. `KubbReactElement` for `@kubb/renderer-jsx`, or a custom type for
122
+ * your own renderer. Defaults to `unknown` so that generators which do not
123
+ * care about the element type continue to work without specifying it.
124
+ *
125
+ * This allows core to drive rendering without a hard dependency on
126
+ * `@kubb/renderer-jsx` or any specific renderer implementation.
127
+ */
128
+ type Renderer<TElement = unknown> = {
129
+ render(element: TElement): Promise<void>;
130
+ unmount(error?: Error | number | null): void;
131
+ readonly files: Array<FileNode>;
132
+ };
133
+ /**
134
+ * A factory function that produces a fresh {@link Renderer} per render.
135
+ *
136
+ * Generators use this to declare which renderer handles their output.
137
+ */
138
+ type RendererFactory<TElement = unknown> = () => Renderer<TElement>;
139
+ /**
140
+ * Creates a renderer factory for use in generator definitions.
141
+ *
142
+ * Wrap your renderer factory function with this helper to register it as the
143
+ * renderer for a generator. Core will call this factory once per render cycle
144
+ * to obtain a fresh renderer instance.
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * // packages/renderer-jsx/src/index.ts
149
+ * export const jsxRenderer = createRenderer(() => {
150
+ * const runtime = new Runtime()
151
+ * return {
152
+ * async render(element) { await runtime.render(element) },
153
+ * get files() { return runtime.nodes },
154
+ * unmount(error) { runtime.unmount(error) },
155
+ * }
156
+ * })
157
+ *
158
+ * // packages/plugin-zod/src/generators/zodGenerator.tsx
159
+ * import { jsxRenderer } from '@kubb/renderer-jsx'
160
+ * export const zodGenerator = defineGenerator<PluginZod>({
161
+ * name: 'zod',
162
+ * renderer: jsxRenderer,
163
+ * schema(node, options) { return <File ...>...</File> },
164
+ * })
165
+ * ```
166
+ */
167
+ declare function createRenderer<TElement = unknown>(factory: RendererFactory<TElement>): RendererFactory<TElement>;
168
+ //#endregion
169
+ //#region src/createStorage.d.ts
170
+ type Storage = {
171
+ /**
172
+ * Identifier used for logging and debugging (e.g. `'fs'`, `'s3'`).
173
+ */
174
+ readonly name: string;
175
+ /**
176
+ * Returns `true` when an entry for `key` exists in storage.
177
+ */
178
+ hasItem(key: string): Promise<boolean>;
179
+ /**
180
+ * Returns the stored string value, or `null` when `key` does not exist.
181
+ */
182
+ getItem(key: string): Promise<string | null>;
183
+ /**
184
+ * Persists `value` under `key`, creating any required structure.
185
+ */
186
+ setItem(key: string, value: string): Promise<void>;
187
+ /**
188
+ * Removes the entry for `key`. No-ops when the key does not exist.
189
+ */
190
+ removeItem(key: string): Promise<void>;
191
+ /**
192
+ * Returns all keys, optionally filtered to those starting with `base`.
193
+ */
194
+ getKeys(base?: string): Promise<Array<string>>;
195
+ /**
196
+ * Removes all entries, optionally scoped to those starting with `base`.
197
+ */
198
+ clear(base?: string): Promise<void>;
199
+ /**
200
+ * Optional teardown hook called after the build completes.
201
+ */
202
+ dispose?(): Promise<void>;
203
+ };
204
+ /**
205
+ * Creates a storage factory. Call the returned function with optional options to get the storage instance.
206
+ *
207
+ * @example
208
+ * export const memoryStorage = createStorage(() => {
209
+ * const store = new Map<string, string>()
210
+ * return {
211
+ * name: 'memory',
212
+ * async hasItem(key) { return store.has(key) },
213
+ * async getItem(key) { return store.get(key) ?? null },
214
+ * async setItem(key, value) { store.set(key, value) },
215
+ * async removeItem(key) { store.delete(key) },
216
+ * async getKeys(base) {
217
+ * const keys = [...store.keys()]
218
+ * return base ? keys.filter((k) => k.startsWith(base)) : keys
219
+ * },
220
+ * async clear(base) { if (!base) store.clear() },
221
+ * }
222
+ * })
223
+ */
224
+ declare function createStorage<TOptions = Record<string, never>>(build: (options: TOptions) => Storage): (options?: TOptions) => Storage;
225
+ //#endregion
226
+ //#region src/defineGenerator.d.ts
227
+ /**
228
+ * A generator is a named object with optional `schema`, `operation`, and `operations`
229
+ * methods. Each method receives the AST node as the first argument and a typed
230
+ * `ctx` object as the second, giving access to `ctx.config`, `ctx.resolver`,
231
+ * `ctx.adapter`, `ctx.options`, `ctx.upsertFile`, etc.
232
+ *
233
+ * Generators that return renderer elements (e.g. JSX) must declare a `renderer`
234
+ * factory so that core knows how to process the output without coupling core
235
+ * to any specific renderer package.
236
+ *
237
+ * Return a renderer element, an array of `FileNode`, or `void` to handle file
238
+ * writing manually via `ctx.upsertFile`.
239
+ *
240
+ * @example
241
+ * ```ts
242
+ * import { jsxRenderer } from '@kubb/renderer-jsx'
243
+ *
244
+ * export const typeGenerator = defineGenerator<PluginTs>({
245
+ * name: 'typescript',
246
+ * renderer: jsxRenderer,
247
+ * schema(node, ctx) {
248
+ * const { adapter, resolver, root, options } = ctx
249
+ * return <File ...><Type node={node} resolver={resolver} /></File>
250
+ * },
251
+ * operation(node, ctx) {
252
+ * const { options } = ctx
253
+ * return <File ...><OperationType node={node} /></File>
254
+ * },
255
+ * })
256
+ * ```
257
+ */
258
+ type Generator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown> = {
259
+ /**
260
+ * Used in diagnostic messages and debug output.
261
+ */
262
+ name: string;
263
+ /**
264
+ * Optional renderer factory that produces a {@link Renderer} for each render cycle.
265
+ *
266
+ * Generators that return renderer elements (e.g. JSX via `@kubb/renderer-jsx`) must set this
267
+ * to the matching renderer factory (e.g. `jsxRenderer` from `@kubb/renderer-jsx`).
268
+ *
269
+ * Generators that only return `Array<FileNode>` or `void` do not need to set this.
270
+ *
271
+ * Set `renderer: null` to explicitly opt out of rendering even when the parent plugin
272
+ * declares a `renderer` (overrides the plugin-level fallback).
273
+ *
274
+ * @example
275
+ * ```ts
276
+ * import { jsxRenderer } from '@kubb/renderer-jsx'
277
+ * export const myGenerator = defineGenerator<PluginTs>({
278
+ * renderer: jsxRenderer,
279
+ * schema(node, ctx) { return <File ...>...</File> },
280
+ * })
281
+ * ```
282
+ */
283
+ renderer?: RendererFactory<TElement> | null;
284
+ /**
285
+ * Called for each schema node in the AST walk.
286
+ * `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
287
+ * plus `ctx.options` with the per-node resolved options (after exclude/include/override).
288
+ */
289
+ schema?: (node: SchemaNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
290
+ /**
291
+ * Called for each operation node in the AST walk.
292
+ * `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
293
+ * plus `ctx.options` with the per-node resolved options (after exclude/include/override).
294
+ */
295
+ operation?: (node: OperationNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
296
+ /**
297
+ * Called once after all operations have been walked.
298
+ * `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
299
+ * plus `ctx.options` with the plugin-level options for the batch call.
300
+ */
301
+ operations?: (nodes: Array<OperationNode>, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
302
+ };
303
+ /**
304
+ * Defines a generator. Returns the object as-is with correct `this` typings.
305
+ * `applyHookResult` handles renderer elements and `File[]` uniformly using
306
+ * the generator's declared `renderer` factory.
307
+ */
308
+ declare function defineGenerator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown>(generator: Generator<TOptions, TElement>): Generator<TOptions, TElement>;
309
+ //#endregion
310
+ //#region src/definePlugin.d.ts
311
+ /**
312
+ * A plugin object produced by `definePlugin`.
313
+ * Instead of flat lifecycle methods, it groups all handlers under a `hooks:` property
314
+ * (matching Astro's integration naming convention).
315
+ *
316
+ * @template TFactory - The plugin's `PluginFactoryOptions` type.
317
+ */
318
+ type Plugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
319
+ /**
320
+ * Unique name for the plugin, following the same naming convention as `createPlugin`.
321
+ */
322
+ name: string;
323
+ /**
324
+ * Plugins that must be registered before this plugin executes.
325
+ * An error is thrown at startup when any listed dependency is missing.
326
+ */
327
+ dependencies?: Array<string>;
328
+ /**
329
+ * Controls the execution order of this plugin relative to others.
330
+ *
331
+ * - `'pre'` — runs before all normal plugins.
332
+ * - `'post'` — runs after all normal plugins.
333
+ * - `undefined` (default) — runs in declaration order among normal plugins.
334
+ *
335
+ * Dependency constraints always take precedence over `enforce`.
336
+ */
337
+ enforce?: 'pre' | 'post';
338
+ /**
339
+ * The options passed by the user when calling the plugin factory.
340
+ */
341
+ options?: TFactory['options'];
342
+ /**
343
+ * Lifecycle event handlers for this plugin.
344
+ * Any event from the global `KubbHooks` map can be subscribed to here.
345
+ */
346
+ hooks: { [K in Exclude<keyof KubbHooks, 'kubb:plugin:setup'>]?: (...args: KubbHooks[K]) => void | Promise<void> } & {
347
+ 'kubb:plugin:setup'?(ctx: KubbPluginSetupContext<TFactory>): void | Promise<void>;
348
+ };
349
+ };
350
+ /**
351
+ * Creates a plugin factory using the hook-style (`hooks:`) API.
352
+ *
353
+ * The returned factory is called with optional options and produces a `Plugin`
354
+ * that coexists with plugins created via the legacy `createPlugin` API in the same
355
+ * `kubb.config.ts`.
356
+ *
357
+ * Lifecycle handlers are registered on the `PluginDriver`'s `AsyncEventEmitter`, enabling
358
+ * both the plugin's own handlers and external tooling (CLI, devtools) to observe every event.
359
+ *
360
+ * @example
361
+ * ```ts
362
+ * // With PluginFactoryOptions (recommended for real plugins)
363
+ * export const pluginTs = definePlugin<PluginTs>((options) => ({
364
+ * name: 'plugin-ts',
365
+ * hooks: {
366
+ * 'kubb:plugin:setup'(ctx) {
367
+ * ctx.setResolver(resolverTs) // typed as Partial<ResolverTs>
368
+ * },
369
+ * },
370
+ * }))
371
+ * ```
372
+ */
373
+ declare function definePlugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(factory: (options: TFactory['options']) => Plugin<TFactory>): (options?: TFactory['options']) => Plugin<TFactory>;
374
+ //#endregion
375
+ //#region src/FileManager.d.ts
376
+ /**
377
+ * In-memory file store for generated files.
378
+ *
379
+ * Files with the same `path` are merged — sources, imports, and exports are concatenated.
380
+ * The `files` getter returns all stored files sorted by path length (shortest first).
381
+ *
382
+ * @example
383
+ * ```ts
384
+ * import { FileManager } from '@kubb/core'
385
+ *
386
+ * const manager = new FileManager()
387
+ * manager.upsert(myFile)
388
+ * console.log(manager.files) // all stored files
389
+ * ```
390
+ */
391
+ declare class FileManager {
392
+ #private;
393
+ /**
394
+ * Adds one or more files. Incoming files with the same path are merged
395
+ * (sources/imports/exports concatenated), but existing cache entries are
396
+ * replaced — use {@link upsert} when you want to merge into the cache too.
397
+ */
398
+ add(...files: Array<FileNode>): Array<FileNode>;
399
+ /**
400
+ * Adds or merges one or more files.
401
+ * If a file with the same path already exists in the cache, its
402
+ * sources/imports/exports are merged into the incoming file.
403
+ */
404
+ upsert(...files: Array<FileNode>): Array<FileNode>;
405
+ getByPath(path: string): FileNode | null;
406
+ deleteByPath(path: string): void;
407
+ clear(): void;
408
+ /**
409
+ * All stored files, sorted by path length (shorter paths first).
410
+ */
411
+ get files(): Array<FileNode>;
412
+ }
413
+ //#endregion
414
+ //#region src/PluginDriver.d.ts
415
+ type Options = {
416
+ hooks: AsyncEventEmitter<KubbHooks>;
417
+ };
418
+ declare class PluginDriver {
419
+ #private;
420
+ readonly config: Config;
421
+ readonly options: Options;
422
+ /**
423
+ * Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.
424
+ *
425
+ * @example
426
+ * ```ts
427
+ * PluginDriver.getMode('src/gen/types.ts') // 'single'
428
+ * PluginDriver.getMode('src/gen/types') // 'split'
429
+ * ```
430
+ */
431
+ static getMode(fileOrFolder: string | undefined | null): 'single' | 'split';
432
+ /**
433
+ * The universal `@kubb/ast` `InputNode` produced by the adapter, set by
434
+ * the build pipeline after the adapter's `parse()` resolves.
435
+ */
436
+ inputNode: InputNode | undefined;
437
+ adapter: Adapter | undefined;
438
+ /**
439
+ * Central file store for all generated files.
440
+ * Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to
441
+ * add files; this property gives direct read/write access when needed.
442
+ */
443
+ readonly fileManager: FileManager;
444
+ readonly plugins: Map<string, NormalizedPlugin>;
445
+ constructor(config: Config, options: Options);
446
+ get hooks(): AsyncEventEmitter<KubbHooks>;
447
+ /**
448
+ * Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.
449
+ *
450
+ * For `kubb:plugin:setup`, the registered listener wraps the globally emitted context with a
451
+ * plugin-specific one so that `addGenerator`, `setResolver`, `setTransformer`, and
452
+ * `setRenderer` all target the correct `normalizedPlugin` entry in the plugins map.
453
+ *
454
+ * All other hooks are iterated and registered directly as pass-through listeners.
455
+ * Any event key present in the global `KubbHooks` interface can be subscribed to.
456
+ *
457
+ * External tooling can subscribe to any of these events via `hooks.on(...)` to observe
458
+ * the plugin lifecycle without modifying plugin behavior.
459
+ *
460
+ * @internal
461
+ */
462
+ registerPluginHooks(hookPlugin: Plugin, normalizedPlugin: NormalizedPlugin): void;
463
+ /**
464
+ * Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners
465
+ * can configure generators, resolvers, transformers and renderers before `buildStart` runs.
466
+ *
467
+ * Call this once from `safeBuild` before the plugin execution loop begins.
468
+ */
469
+ emitSetupHooks(): Promise<void>;
470
+ /**
471
+ * Registers a generator for the given plugin on the shared event emitter.
472
+ *
473
+ * The generator's `schema`, `operation`, and `operations` methods are registered as
474
+ * listeners on `kubb:generate:schema`, `kubb:generate:operation`, and `kubb:generate:operations`
475
+ * respectively. Each listener is scoped to the owning plugin via a `ctx.plugin.name` check
476
+ * so that generators from different plugins do not cross-fire.
477
+ *
478
+ * The renderer resolution chain is: `generator.renderer → plugin.renderer → config.renderer`.
479
+ * Set `generator.renderer = null` to explicitly opt out of rendering even when the plugin
480
+ * declares a renderer.
481
+ *
482
+ * Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.
483
+ */
484
+ registerGenerator(pluginName: string, gen: Generator): void;
485
+ /**
486
+ * Returns `true` when at least one generator was registered for the given plugin
487
+ * via `addGenerator()` in `kubb:plugin:setup` (event-based path).
488
+ *
489
+ * Used by the build loop to decide whether to walk the AST and emit generator events
490
+ * for a plugin that has no static `plugin.generators`.
491
+ */
492
+ hasRegisteredGenerators(pluginName: string): boolean;
493
+ /**
494
+ * Unregisters all plugin lifecycle listeners from the shared event emitter.
495
+ * Called at the end of a build to prevent listener leaks across repeated builds.
496
+ *
497
+ * @internal
498
+ */
499
+ dispose(): void;
500
+ /**
501
+ * Merges `partial` with the plugin's default resolver and stores the result.
502
+ * Also mirrors it onto `plugin.resolver` so callers using `getPlugin(name).resolver`
503
+ * get the up-to-date resolver without going through `getResolver()`.
504
+ */
505
+ setPluginResolver(pluginName: string, partial: Partial<Resolver>): void;
506
+ /**
507
+ * Returns the resolver for the given plugin.
508
+ *
509
+ * Resolution order: dynamic resolver set via `setPluginResolver` → static resolver on the
510
+ * plugin → lazily created default resolver (identity name, no path transforms).
511
+ */
512
+ getResolver<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Kubb.PluginRegistry[TName]['resolver'];
513
+ getResolver<TResolver extends Resolver = Resolver>(pluginName: string): TResolver;
514
+ getContext<TOptions extends PluginFactoryOptions>(plugin: NormalizedPlugin<TOptions>): GeneratorContext<TOptions> & Record<string, unknown>;
515
+ getPlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
516
+ getPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions> | undefined;
517
+ /**
518
+ * Like `getPlugin` but throws a descriptive error when the plugin is not found.
519
+ */
520
+ requirePlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]>;
521
+ requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>;
522
+ }
523
+ //#endregion
524
+ //#region src/createKubb.d.ts
525
+ /**
526
+ * Full output produced by a successful or failed build.
527
+ */
528
+ type BuildOutput = {
529
+ /**
530
+ * Plugins that threw during installation, paired with the caught error.
531
+ */
532
+ failedPlugins: Set<{
533
+ plugin: Plugin;
534
+ error: Error;
535
+ }>;
536
+ files: Array<FileNode>;
537
+ driver: PluginDriver;
538
+ /**
539
+ * Elapsed time in milliseconds for each plugin, keyed by plugin name.
540
+ */
541
+ pluginTimings: Map<string, number>;
542
+ error?: Error;
543
+ /**
544
+ * Raw generated source, keyed by absolute file path.
545
+ */
546
+ sources: Map<string, string>;
547
+ };
548
+ type CreateKubbOptions = {
549
+ hooks?: AsyncEventEmitter<KubbHooks>;
550
+ };
551
+ /**
552
+ * Creates a Kubb instance bound to a single config entry.
553
+ *
554
+ * Accepts a user-facing config shape and resolves it to a full {@link Config} during
555
+ * `setup()`. The instance then holds shared state (`hooks`, `sources`, `driver`, `config`)
556
+ * across the `setup → build` lifecycle. Attach event listeners to `kubb.hooks` before
557
+ * calling `setup()` or `build()`.
558
+ *
559
+ * @example
560
+ * ```ts
561
+ * const kubb = createKubb(userConfig)
562
+ *
563
+ * kubb.hooks.on('kubb:plugin:end', ({ plugin, duration }) => {
564
+ * console.log(`${plugin.name} completed in ${duration}ms`)
565
+ * })
566
+ *
567
+ * const { files, failedPlugins } = await kubb.safeBuild()
568
+ * ```
569
+ */
570
+ declare function createKubb(userConfig: UserConfig, options?: CreateKubbOptions): Kubb$1;
571
+ //#endregion
572
+ //#region src/Kubb.d.ts
573
+ /**
574
+ * The instance returned by {@link createKubb}.
575
+ */
576
+ type Kubb$1 = {
577
+ /**
578
+ * The shared event emitter. Attach listeners here before calling `setup()` or `build()`.
579
+ */
580
+ readonly hooks: AsyncEventEmitter<KubbHooks>;
581
+ /**
582
+ * Raw generated source, keyed by absolute file path.
583
+ * Populated after a successful `build()` or `safeBuild()` call.
584
+ */
585
+ readonly sources: Map<string, string>;
586
+ /**
587
+ * The plugin driver. Available after `setup()` has been called.
588
+ */
589
+ readonly driver: PluginDriver | undefined;
590
+ /**
591
+ * The resolved config with applied defaults. Available after `setup()` has been called.
592
+ */
593
+ readonly config: Config | undefined;
594
+ /**
595
+ * Initializes all Kubb infrastructure: validates input, applies config defaults,
596
+ * runs the adapter, and creates the PluginDriver.
597
+ *
598
+ * Calling `build()` or `safeBuild()` without calling `setup()` first will
599
+ * automatically invoke `setup()` before proceeding.
600
+ */
601
+ setup(): Promise<void>;
602
+ /**
603
+ * Runs a full Kubb build and throws on any error or plugin failure.
604
+ * Automatically calls `setup()` if it has not been called yet.
605
+ */
606
+ build(): Promise<BuildOutput>;
607
+ /**
608
+ * Runs a full Kubb build and captures errors instead of throwing.
609
+ * Automatically calls `setup()` if it has not been called yet.
610
+ */
611
+ safeBuild(): Promise<BuildOutput>;
612
+ };
613
+ /**
614
+ * Events emitted during the Kubb code generation lifecycle.
615
+ * These events can be listened to for logging, progress tracking, and custom integrations.
616
+ *
617
+ * @example
618
+ * ```typescript
619
+ * import type { AsyncEventEmitter } from '@internals/utils'
620
+ * import type { KubbHooks } from '@kubb/core'
621
+ *
622
+ * const hooks: AsyncEventEmitter<KubbHooks> = new AsyncEventEmitter()
623
+ *
624
+ * hooks.on('kubb:lifecycle:start', () => {
625
+ * console.log('Starting Kubb generation')
626
+ * })
627
+ *
628
+ * hooks.on('kubb:plugin:end', ({ plugin, duration }) => {
629
+ * console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
630
+ * })
631
+ * ```
632
+ */
633
+ interface KubbHooks {
634
+ /**
635
+ * Emitted at the beginning of the Kubb lifecycle, before any code generation starts.
636
+ */
637
+ 'kubb:lifecycle:start': [ctx: KubbLifecycleStartContext];
638
+ /**
639
+ * Emitted at the end of the Kubb lifecycle, after all code generation is complete.
640
+ */
641
+ 'kubb:lifecycle:end': [];
642
+ /**
643
+ * Emitted when configuration loading starts.
644
+ */
645
+ 'kubb:config:start': [];
646
+ /**
647
+ * Emitted when configuration loading is complete.
648
+ */
649
+ 'kubb:config:end': [ctx: KubbConfigEndContext];
650
+ /**
651
+ * Emitted when code generation phase starts.
652
+ */
653
+ 'kubb:generation:start': [ctx: KubbGenerationStartContext];
654
+ /**
655
+ * Emitted when code generation phase completes.
656
+ */
657
+ 'kubb:generation:end': [ctx: KubbGenerationEndContext];
658
+ /**
659
+ * Emitted with a summary of the generation results.
660
+ * Contains summary lines, title, and success status.
661
+ */
662
+ 'kubb:generation:summary': [ctx: KubbGenerationSummaryContext];
663
+ /**
664
+ * Emitted when code formatting starts (e.g., running Biome or Prettier).
665
+ */
666
+ 'kubb:format:start': [];
667
+ /**
668
+ * Emitted when code formatting completes.
669
+ */
670
+ 'kubb:format:end': [];
671
+ /**
672
+ * Emitted when linting starts.
673
+ */
674
+ 'kubb:lint:start': [];
675
+ /**
676
+ * Emitted when linting completes.
677
+ */
678
+ 'kubb:lint:end': [];
679
+ /**
680
+ * Emitted when plugin hooks execution starts.
681
+ */
682
+ 'kubb:hooks:start': [];
683
+ /**
684
+ * Emitted when plugin hooks execution completes.
685
+ */
686
+ 'kubb:hooks:end': [];
687
+ /**
688
+ * Emitted when a single hook execution starts (e.g., format or lint).
689
+ * The callback should be invoked when the command completes.
690
+ */
691
+ 'kubb:hook:start': [ctx: KubbHookStartContext];
692
+ /**
693
+ * Emitted when a single hook execution completes.
694
+ */
695
+ 'kubb:hook:end': [ctx: KubbHookEndContext];
696
+ /**
697
+ * Emitted when a new version of Kubb is available.
698
+ */
699
+ 'kubb:version:new': [ctx: KubbVersionNewContext];
700
+ /**
701
+ * Informational message event.
702
+ */
703
+ 'kubb:info': [ctx: KubbInfoContext];
704
+ /**
705
+ * Error event. Emitted when an error occurs during code generation.
706
+ */
707
+ 'kubb:error': [ctx: KubbErrorContext];
708
+ /**
709
+ * Success message event.
710
+ */
711
+ 'kubb:success': [ctx: KubbSuccessContext];
712
+ /**
713
+ * Warning message event.
714
+ */
715
+ 'kubb:warn': [ctx: KubbWarnContext];
716
+ /**
717
+ * Debug event for detailed logging.
718
+ * Contains timestamp, log messages, and optional filename.
719
+ */
720
+ 'kubb:debug': [ctx: KubbDebugContext];
721
+ /**
722
+ * Emitted when file processing starts.
723
+ * Contains the list of files to be processed.
724
+ */
725
+ 'kubb:files:processing:start': [ctx: KubbFilesProcessingStartContext];
726
+ /**
727
+ * Emitted for each file being processed, providing progress updates.
728
+ * Contains processed count, total count, percentage, and file details.
729
+ */
730
+ 'kubb:file:processing:update': [ctx: KubbFileProcessingUpdateContext];
731
+ /**
732
+ * Emitted when file processing completes.
733
+ * Contains the list of processed files.
734
+ */
735
+ 'kubb:files:processing:end': [ctx: KubbFilesProcessingEndContext];
736
+ /**
737
+ * Emitted when a plugin starts executing.
738
+ */
739
+ 'kubb:plugin:start': [ctx: KubbPluginStartContext];
740
+ /**
741
+ * Emitted when a plugin completes execution.
742
+ * Duration in ms.
743
+ */
744
+ 'kubb:plugin:end': [ctx: KubbPluginEndContext];
745
+ /**
746
+ * Fired once — before any plugin's `buildStart` runs — so that hook-style plugins
747
+ * can register generators, configure resolvers/transformers/renderers, or inject
748
+ * extra files. All `kubb:plugin:setup` handlers registered via `definePlugin` receive
749
+ * a plugin-specific context (with the correct `addGenerator` closure).
750
+ * External tooling can observe this event via `hooks.on('kubb:plugin:setup', …)`.
751
+ */
752
+ 'kubb:plugin:setup': [ctx: KubbPluginSetupContext];
753
+ /**
754
+ * Fired immediately before the plugin execution loop begins.
755
+ * The adapter has already parsed the source and `inputNode` is available.
756
+ */
757
+ 'kubb:build:start': [ctx: KubbBuildStartContext];
758
+ /**
759
+ * Fired after all plugins have run and all per-plugin barrels have been generated,
760
+ * but BEFORE files are written to disk.
761
+ * Use this event to inject final files (e.g. a root barrel) that must be persisted
762
+ * in the same write pass as the plugin output.
763
+ */
764
+ 'kubb:plugins:end': [ctx: KubbPluginsEndContext];
765
+ /**
766
+ * Fired after all files have been written to disk.
767
+ */
768
+ 'kubb:build:end': [ctx: KubbBuildEndContext];
769
+ /**
770
+ * Emitted for each schema node during the AST walk.
771
+ * Generator listeners registered via `addGenerator()` in `kubb:plugin:setup` respond to this event.
772
+ * The `ctx.plugin.name` identifies which plugin is driving the current walk.
773
+ * `ctx.options` carries the per-node resolved options (after exclude/include/override).
774
+ */
775
+ 'kubb:generate:schema': [node: SchemaNode, ctx: GeneratorContext];
776
+ /**
777
+ * Emitted for each operation node during the AST walk.
778
+ * Generator listeners registered via `addGenerator()` in `kubb:plugin:setup` respond to this event.
779
+ * The `ctx.plugin.name` identifies which plugin is driving the current walk.
780
+ * `ctx.options` carries the per-node resolved options (after exclude/include/override).
781
+ */
782
+ 'kubb:generate:operation': [node: OperationNode, ctx: GeneratorContext];
783
+ /**
784
+ * Emitted once after all operations have been walked, with the full collected array.
785
+ * Generator listeners with an `operations()` method respond to this event.
786
+ * The `ctx.plugin.name` identifies which plugin is driving the current walk.
787
+ * `ctx.options` carries the plugin-level resolved options for the batch call.
788
+ */
789
+ 'kubb:generate:operations': [nodes: Array<OperationNode>, ctx: GeneratorContext];
790
+ }
791
+ declare global {
792
+ namespace Kubb {
793
+ /**
794
+ * Registry that maps plugin names to their `PluginFactoryOptions`.
795
+ * Augment this interface in each plugin's `types.ts` to enable automatic
796
+ * typing for `getPlugin` and `requirePlugin`.
797
+ *
798
+ * @example
799
+ * ```ts
800
+ * // packages/plugin-ts/src/types.ts
801
+ * declare global {
802
+ * namespace Kubb {
803
+ * interface PluginRegistry {
804
+ * 'plugin-ts': PluginTs
805
+ * }
806
+ * }
807
+ * }
808
+ * ```
809
+ */
810
+ interface PluginRegistry {}
811
+ /**
812
+ * Extension point for root `Config['output']` options.
813
+ * Augment the `output` key in middleware or plugin packages to add extra fields
814
+ * to the global output configuration without touching core types.
815
+ *
816
+ * @example
817
+ * ```ts
818
+ * // packages/middleware-barrel/src/types.ts
819
+ * declare global {
820
+ * namespace Kubb {
821
+ * interface ConfigOptionsRegistry {
822
+ * output: {
823
+ * barrelType?: import('./types.ts').BarrelType | false
824
+ * }
825
+ * }
826
+ * }
827
+ * }
828
+ * ```
829
+ */
830
+ interface ConfigOptionsRegistry {}
831
+ /**
832
+ * Extension point for per-plugin `Output` options.
833
+ * Augment the `output` key in middleware or plugin packages to add extra fields
834
+ * to the per-plugin output configuration without touching core types.
835
+ *
836
+ * @example
837
+ * ```ts
838
+ * // packages/middleware-barrel/src/types.ts
839
+ * declare global {
840
+ * namespace Kubb {
841
+ * interface PluginOptionsRegistry {
842
+ * output: {
843
+ * barrelType?: import('./types.ts').BarrelType | false
844
+ * }
845
+ * }
846
+ * }
847
+ * }
848
+ * ```
849
+ */
850
+ interface PluginOptionsRegistry {}
851
+ }
852
+ }
853
+ //#endregion
854
+ //#region src/defineMiddleware.d.ts
855
+ /**
856
+ * A middleware observes and post-processes the build output produced by plugins.
857
+ * It attaches listeners to the shared `hooks` emitter before the plugin execution loop
858
+ * begins and reacts to lifecycle events (e.g. `kubb:plugin:end`, `kubb:build:end`) to
859
+ * inject barrel files or perform other cross-cutting concerns.
860
+ *
861
+ * Middleware listeners are always registered **after** all plugin listeners, because
862
+ * `createKubb` installs middleware only after the `PluginDriver` has registered every
863
+ * plugin's hooks. This means middleware hooks for any event always fire last.
864
+ *
865
+ * @example
866
+ * ```ts
867
+ * import { defineMiddleware } from '@kubb/core'
868
+ *
869
+ * export const myMiddleware = defineMiddleware({
870
+ * name: 'my-middleware',
871
+ * install(hooks) {
872
+ * hooks.on('kubb:build:end', ({ files }) => {
873
+ * console.log(`Build complete with ${files.length} files`)
874
+ * })
875
+ * },
876
+ * })
877
+ * ```
878
+ */
879
+ type Middleware = {
880
+ /**
881
+ * Unique identifier for this middleware.
882
+ */
883
+ name: string;
884
+ /**
885
+ * Called during `createKubb` after `setup()` but before the plugin
886
+ * execution loop starts. Attach listeners to `hooks` here.
887
+ */
888
+ install(hooks: AsyncEventEmitter<KubbHooks>): void;
889
+ };
890
+ /**
891
+ * Identity factory for middleware.
892
+ * Returns the middleware object unchanged but provides a typed entry-point
893
+ * to define middleware with proper inference.
894
+ *
895
+ * @example
896
+ * ```ts
897
+ * export const myMiddleware = defineMiddleware({
898
+ * name: 'my-middleware',
899
+ * install(hooks) {
900
+ * hooks.on('kubb:build:end', ({ files }) => {
901
+ * console.log(`Build complete with ${files.length} files`)
902
+ * })
903
+ * },
904
+ * })
905
+ * ```
906
+ */
907
+ declare function defineMiddleware(middleware: Middleware): Middleware;
908
+ //#endregion
909
+ //#region src/defineParser.d.ts
910
+ type PrintOptions = {
911
+ extname?: FileNode['extname'];
912
+ };
913
+ type Parser<TMeta extends object = any> = {
914
+ name: string;
915
+ /**
916
+ * File extensions this parser handles.
917
+ * Use `undefined` to create a catch-all fallback parser.
918
+ *
919
+ * @example Handled extensions
920
+ * `['.ts', '.js']`
921
+ */
922
+ extNames: Array<FileNode['extname']> | undefined;
923
+ /**
924
+ * Convert a resolved file to a string.
925
+ */
926
+ parse(file: FileNode<TMeta>, options?: PrintOptions): Promise<string> | string;
927
+ };
928
+ /**
929
+ * Defines a parser with type safety.
930
+ *
931
+ * Use this function to create parsers that transform generated files to strings
932
+ * based on their extension.
933
+ *
934
+ * @example
935
+ * ```ts
936
+ * import { defineParser } from '@kubb/core'
937
+ *
938
+ * export const jsonParser = defineParser({
939
+ * name: 'json',
940
+ * extNames: ['.json'],
941
+ * parse(file) {
942
+ * const { extractStringsFromNodes } = await import('@kubb/ast')
943
+ * return file.sources.map((s) => extractStringsFromNodes(s.nodes ?? [])).join('\n')
944
+ * },
945
+ * })
946
+ * ```
947
+ */
948
+ declare function defineParser<TMeta extends object = any>(parser: Parser<TMeta>): Parser<TMeta>;
949
+ //#endregion
950
+ //#region src/types.d.ts
951
+ /**
952
+ * Safely extracts the type of key `K` from `T`, returning `{}` when `K` is not a key of `T`.
953
+ * Used to implement optional interface augmentation for `Kubb.ConfigOptionsRegistry` and
954
+ * `Kubb.PluginOptionsRegistry` so that middleware and plugin packages can extend core types
955
+ * without requiring modifications to core.
956
+ *
957
+ * @internal
958
+ */
959
+ type ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {};
960
+ type InputPath = {
961
+ /**
962
+ * Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
963
+ */
964
+ path: string;
965
+ };
966
+ type InputData = {
967
+ /**
968
+ * A `string` or `object` that contains your Swagger/OpenAPI data.
969
+ */
970
+ data: string | unknown;
971
+ };
972
+ type Input = InputPath | InputData;
973
+ /**
974
+ * The raw source passed to an adapter's `parse` function.
975
+ * Mirrors the shape of `Config['input']` with paths already resolved to absolute.
976
+ */
977
+ type AdapterSource = {
978
+ type: 'path';
979
+ path: string;
980
+ } | {
981
+ type: 'data';
982
+ data: string | unknown;
983
+ } | {
984
+ type: 'paths';
985
+ paths: Array<string>;
986
+ };
987
+ /**
988
+ * Type parameters for an adapter definition.
989
+ *
990
+ * Mirrors `PluginFactoryOptions` but scoped to the adapter lifecycle:
991
+ * - `TName` — unique string identifier (e.g. `'oas'`, `'asyncapi'`)
992
+ * - `TOptions` — raw user-facing options passed to the adapter factory
993
+ * - `TResolvedOptions` — defaults applied; what the adapter stores as `options`
994
+ * - `TDocument` — type of the raw source document exposed by the adapter after `parse()`
995
+ */
996
+ type AdapterFactoryOptions<TName extends string = string, TOptions extends object = object, TResolvedOptions extends object = TOptions, TDocument = unknown> = {
997
+ name: TName;
998
+ options: TOptions;
999
+ resolvedOptions: TResolvedOptions;
1000
+ document: TDocument;
1001
+ };
1002
+ /**
1003
+ * An adapter converts a source file or data into a `@kubb/ast` `InputNode`.
1004
+ *
1005
+ * Adapters are the single entry-point for different schema formats
1006
+ * (OpenAPI, AsyncAPI, Drizzle, …) and produce the universal `InputNode`
1007
+ * that all Kubb plugins consume.
1008
+ *
1009
+ * @example
1010
+ * ```ts
1011
+ * import { oasAdapter } from '@kubb/adapter-oas'
1012
+ *
1013
+ * export default defineConfig({
1014
+ * adapter: adapterOas(), // default — OpenAPI / Swagger
1015
+ * input: { path: './openapi.yaml' },
1016
+ * plugins: [pluginTs(), pluginZod()],
1017
+ * })
1018
+ * ```
1019
+ */
1020
+ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
1021
+ /**
1022
+ * Human-readable identifier, e.g. `'oas'`, `'drizzle'`, `'asyncapi'`.
1023
+ */
1024
+ name: TOptions['name'];
1025
+ /**
1026
+ * Resolved options (after defaults have been applied).
1027
+ */
1028
+ options: TOptions['resolvedOptions'];
1029
+ /**
1030
+ * The raw source document produced after the first `parse()` call.
1031
+ * `undefined` before parsing; typed by the adapter's `TDocument` generic.
1032
+ */
1033
+ document: TOptions['document'] | null;
1034
+ inputNode: InputNode | null;
1035
+ /**
1036
+ * Convert the raw source into a universal `InputNode`.
1037
+ */
1038
+ parse: (source: AdapterSource) => PossiblePromise<InputNode>;
1039
+ /**
1040
+ * Extracts `ImportNode` entries needed by a `SchemaNode` tree.
1041
+ * Populated after the first `parse()` call. Returns an empty array before that.
1042
+ *
1043
+ * The `resolve` callback receives the collision-corrected schema name and must
1044
+ * return the `{ name, path }` pair for the import, or `undefined` to skip it.
1045
+ */
1046
+ getImports: (node: SchemaNode, resolve: (schemaName: string) => {
1047
+ name: string;
1048
+ path: string;
1049
+ }) => Array<ImportNode>;
1050
+ };
1051
+ type DevtoolsOptions = {
1052
+ /**
1053
+ * Open the AST inspector view (`/ast`) in Kubb Studio.
1054
+ * When `false`, opens the main Studio page instead.
1055
+ * @default false
1056
+ */
1057
+ ast?: boolean;
1058
+ };
1059
+ /**
1060
+ * @private
1061
+ */
1062
+ type Config<TInput = Input> = {
1063
+ /**
1064
+ * The name to display in the CLI output.
1065
+ */
1066
+ name?: string;
1067
+ /**
1068
+ * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
1069
+ * @default process.cwd()
1070
+ */
1071
+ root: string;
1072
+ /**
1073
+ * An array of parsers used to convert generated files to strings.
1074
+ * Each parser handles specific file extensions (e.g. `.ts`, `.tsx`).
1075
+ *
1076
+ * A catch-all fallback parser is always appended last for any unhandled extension.
1077
+ *
1078
+ * When omitted, `parserTs` from `@kubb/parser-ts` is used automatically as the
1079
+ * default (requires `@kubb/parser-ts` to be installed as an optional dependency).
1080
+ * @default [parserTs] — from `@kubb/parser-ts`
1081
+ * @example
1082
+ * ```ts
1083
+ * import { parserTs, tsxParser } from '@kubb/parser-ts'
1084
+ * export default defineConfig({
1085
+ * parsers: [parserTs, tsxParser],
1086
+ * })
1087
+ * ```
1088
+ */
1089
+ parsers: Array<Parser>;
1090
+ /**
1091
+ * Adapter that converts the input file into a `@kubb/ast` `InputNode` — the universal
1092
+ * intermediate representation consumed by all Kubb plugins.
1093
+ *
1094
+ * - Use `@kubb/adapter-oas` for OpenAPI / Swagger.
1095
+ * - Use `@kubb/adapter-drizzle` or `@kubb/adapter-asyncapi` for other formats.
1096
+ *
1097
+ * @example
1098
+ * ```ts
1099
+ * import { adapterOas } from '@kubb/adapter-oas'
1100
+ * export default defineConfig({
1101
+ * adapter: adapterOas(),
1102
+ * input: { path: './petStore.yaml' },
1103
+ * })
1104
+ * ```
1105
+ */
1106
+ adapter: Adapter;
1107
+ /**
1108
+ * Source file or data to generate code from.
1109
+ * Use `input.path` for a file on disk or `input.data` for an inline string or object.
1110
+ */
1111
+ input: TInput;
1112
+ output: {
1113
+ /**
1114
+ * Output directory for generated files.
1115
+ * Accepts an absolute path or a path relative to `root`.
1116
+ */
1117
+ path: string;
1118
+ /**
1119
+ * Clean the output directory before each build.
1120
+ */
1121
+ clean?: boolean;
1122
+ /**
1123
+ * Save files to the file system.
1124
+ * @default true
1125
+ * @deprecated Use `storage` to control where files are written.
1126
+ */
1127
+ write?: boolean;
1128
+ /**
1129
+ * Storage backend for generated files.
1130
+ * Defaults to `fsStorage()` — the built-in filesystem driver.
1131
+ * Accepts any object implementing the {@link Storage} interface.
1132
+ * Keys are root-relative paths (e.g. `src/gen/api/getPets.ts`).
1133
+ * @default fsStorage()
1134
+ * @example
1135
+ * ```ts
1136
+ * import { memoryStorage } from '@kubb/core'
1137
+ * storage: memoryStorage()
1138
+ * ```
1139
+ */
1140
+ storage?: Storage;
1141
+ /**
1142
+ * Specifies the formatting tool to be used.
1143
+ * - 'auto' automatically detects and uses oxfmt, biome, or prettier (in that order of preference).
1144
+ * - 'oxfmt' uses Oxfmt for code formatting.
1145
+ * - 'prettier' uses Prettier for code formatting.
1146
+ * - 'biome' uses Biome for code formatting.
1147
+ * - false disables code formatting.
1148
+ * @default 'prettier'
1149
+ */
1150
+ format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false;
1151
+ /**
1152
+ * Specifies the linter that should be used to analyze the code.
1153
+ * - 'auto' automatically detects and uses oxlint, biome, or eslint (in that order of preference).
1154
+ * - 'oxlint' uses Oxlint for linting.
1155
+ * - 'eslint' uses ESLint for linting.
1156
+ * - 'biome' uses Biome for linting.
1157
+ * - false disables linting.
1158
+ * @default 'auto'
1159
+ */
1160
+ lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false;
1161
+ /**
1162
+ * Overrides the extension for generated imports and exports. By default, each plugin adds an extension.
1163
+ * @default { '.ts': '.ts'}
1164
+ */
1165
+ extension?: Record<FileNode['extname'], FileNode['extname'] | ''>;
1166
+ /**
1167
+ * Adds a default banner to the start of every generated file indicating it was generated by Kubb.
1168
+ * - 'simple' adds banner with link to Kubb.
1169
+ * - 'full' adds source, title, description, and OpenAPI version.
1170
+ * - false disables banner generation.
1171
+ * @default 'simple'
1172
+ */
1173
+ defaultBanner?: 'simple' | 'full' | false;
1174
+ /**
1175
+ * Whether to override existing external files if they already exist.
1176
+ * When setting the option in the global configuration, all plugins inherit the same behavior by default.
1177
+ * However, all plugins also have an `output.override` option, which can be used to override the behavior for a specific plugin.
1178
+ * @default false
1179
+ */
1180
+ override?: boolean;
1181
+ } & ExtractRegistryKey<Kubb.ConfigOptionsRegistry, 'output'>;
1182
+ /**
1183
+ * An array of Kubb plugins used for code generation.
1184
+ * Each plugin may declare additional configurable options.
1185
+ * If a plugin depends on another, an error is thrown when the dependency is missing.
1186
+ * Use `dependencies` on the plugin to declare execution order.
1187
+ */
1188
+ plugins: Array<Plugin>;
1189
+ /**
1190
+ * Middleware instances that observe and post-process the build output.
1191
+ * Each middleware receives the `hooks` emitter and attaches its own listeners.
1192
+ * Middleware listeners are always registered after all plugin listeners,
1193
+ * so middleware hooks fire last for any given event.
1194
+ *
1195
+ * @example
1196
+ * ```ts
1197
+ * import { middlewareBarrel } from '@kubb/middleware-barrel'
1198
+ * export default defineConfig({
1199
+ * middleware: [middlewareBarrel],
1200
+ * plugins: [pluginTs(), pluginZod()],
1201
+ * })
1202
+ * ```
1203
+ */
1204
+ middleware?: Array<Middleware>;
1205
+ /**
1206
+ * Project-wide renderer factory. All plugins and generators that do not declare their own
1207
+ * `renderer` ultimately fall back to this value.
1208
+ *
1209
+ * The resolution chain is: `generator.renderer` → `plugin.renderer` → `config.renderer` → `undefined` (raw `FileNode[]` mode).
1210
+ *
1211
+ * @example
1212
+ * ```ts
1213
+ * import { jsxRenderer } from '@kubb/renderer-jsx'
1214
+ * export default defineConfig({
1215
+ * renderer: jsxRenderer,
1216
+ * plugins: [pluginTs(), pluginZod()],
1217
+ * })
1218
+ * ```
1219
+ */
1220
+ renderer?: RendererFactory;
1221
+ /**
1222
+ * Devtools configuration for Kubb Studio integration.
1223
+ */
1224
+ devtools?: true | {
1225
+ /**
1226
+ * Override the Kubb Studio base URL.
1227
+ * @default 'https://studio.kubb.dev'
1228
+ */
1229
+ studioUrl?: typeof DEFAULT_STUDIO_URL | (string & {});
1230
+ };
1231
+ /**
1232
+ * Hooks triggered when a specific action occurs in Kubb.
1233
+ */
1234
+ hooks?: {
1235
+ /**
1236
+ * Hook that triggers at the end of all executions.
1237
+ * Useful for running Prettier or ESLint to format/lint your code.
1238
+ */
1239
+ done?: string | Array<string>;
1240
+ };
1241
+ };
1242
+ /**
1243
+ * A type/string-pattern filter used for `include`, `exclude`, and `override` matching.
1244
+ */
1245
+ type PatternFilter = {
1246
+ type: string;
1247
+ pattern: string | RegExp;
1248
+ };
1249
+ /**
1250
+ * A pattern filter paired with partial option overrides to apply when the pattern matches.
1251
+ */
1252
+ type PatternOverride<TOptions> = PatternFilter & {
1253
+ options: Omit<Partial<TOptions>, 'override'>;
1254
+ };
1255
+ /**
1256
+ * Context passed to `resolver.resolveOptions` to apply include/exclude/override filtering
1257
+ * for a given operation or schema node.
1258
+ */
1259
+ /**
1260
+ * Resolves filtered options for a given operation or schema node.
1261
+ *
1262
+ * @internal
1263
+ */
1264
+ type ResolveOptionsContext<TOptions> = {
1265
+ options: TOptions;
1266
+ exclude?: Array<PatternFilter>;
1267
+ include?: Array<PatternFilter>;
1268
+ override?: Array<PatternOverride<TOptions>>;
1269
+ };
1270
+ /**
1271
+ * Base constraint for all plugin resolver objects.
1272
+ *
1273
+ * `default`, `resolveOptions`, `resolvePath`, and `resolveFile` are injected automatically
1274
+ * by `defineResolver` — plugin authors may override them but never need to implement them
1275
+ * from scratch.
1276
+ *
1277
+ * @example
1278
+ * ```ts
1279
+ * type MyResolver = Resolver & {
1280
+ * resolveName(node: SchemaNode): string
1281
+ * resolveTypedName(node: SchemaNode): string
1282
+ * }
1283
+ * ```
1284
+ */
1285
+ type Resolver = {
1286
+ name: string;
1287
+ pluginName: Plugin['name'];
1288
+ default(name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
1289
+ resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null;
1290
+ resolvePath(params: ResolverPathParams, context: ResolverContext): string;
1291
+ resolveFile(params: ResolverFileParams, context: ResolverContext): FileNode;
1292
+ resolveBanner(node: InputNode | null, context: ResolveBannerContext): string | undefined;
1293
+ resolveFooter(node: InputNode | null, context: ResolveBannerContext): string | undefined;
1294
+ };
1295
+ type PluginFactoryOptions<
1296
+ /**
1297
+ * Name to be used for the plugin.
1298
+ */
1299
+ TName extends string = string,
1300
+ /**
1301
+ * Options of the plugin.
1302
+ */
1303
+ TOptions extends object = object,
1304
+ /**
1305
+ * Options of the plugin that can be used later on, see `options` inside your plugin config.
1306
+ */
1307
+ TResolvedOptions extends object = TOptions,
1308
+ /**
1309
+ * Resolver object that encapsulates the naming and path-resolution helpers used by this plugin.
1310
+ * Use `defineResolver` to define the resolver object and export it alongside the plugin.
1311
+ */
1312
+ TResolver extends Resolver = Resolver> = {
1313
+ name: TName;
1314
+ options: TOptions;
1315
+ resolvedOptions: TResolvedOptions;
1316
+ resolver: TResolver;
1317
+ };
1318
+ /**
1319
+ * Internal representation of a plugin after normalization.
1320
+ * Extends the user-facing `Plugin` with runtime fields populated during `kubb:plugin:setup`.
1321
+ * Not part of the public API — use `Plugin` for external-facing interactions.
1322
+ * @internal
1323
+ */
1324
+ type NormalizedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & {
1325
+ options: TOptions['resolvedOptions'] & {
1326
+ output: Output;
1327
+ include?: Array<Include>;
1328
+ exclude: Array<Exclude$1>;
1329
+ override: Array<Override<TOptions['resolvedOptions']>>;
1330
+ };
1331
+ resolver: TOptions['resolver'];
1332
+ transformer?: Visitor;
1333
+ renderer?: RendererFactory;
1334
+ generators?: Array<Generator>;
1335
+ apply?: (config: Config) => boolean;
1336
+ version?: string;
1337
+ };
1338
+ /**
1339
+ * Partial version of {@link Config} intended for user-facing config entry points.
1340
+ *
1341
+ * Fields that have sensible defaults (`root`, `plugins`, `parsers`, `adapter`) are optional.
1342
+ */
1343
+ type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter'> & {
1344
+ /**
1345
+ * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
1346
+ * @default process.cwd()
1347
+ */
1348
+ root?: string;
1349
+ /**
1350
+ * An array of parsers used to convert generated files to strings.
1351
+ * Each parser handles specific file extensions (e.g. `.ts`, `.tsx`).
1352
+ *
1353
+ * A catch-all fallback parser is always appended last for any unhandled extension.
1354
+ */
1355
+ parsers?: Array<Parser>;
1356
+ /**
1357
+ * Adapter that converts the input file into a `@kubb/ast` `InputNode`.
1358
+ */
1359
+ adapter?: Adapter;
1360
+ /**
1361
+ * An array of Kubb plugins used for code generation.
1362
+ * Each entry is a hook-style plugin created with `definePlugin`.
1363
+ */
1364
+ plugins?: Array<Plugin>;
1365
+ };
1366
+ type ResolveNameParams = {
1367
+ name: string;
1368
+ pluginName?: string;
1369
+ /**
1370
+ * Specifies the type of entity being named.
1371
+ * - `'file'` — customizes the name of the created file (camelCase).
1372
+ * - `'function'` — customizes the exported function names (camelCase).
1373
+ * - `'type'` — customizes TypeScript type names (PascalCase).
1374
+ * - `'const'` — customizes variable names (camelCase).
1375
+ */
1376
+ type?: 'file' | 'function' | 'type' | 'const';
1377
+ };
1378
+ /**
1379
+ * Context object passed as the second argument to generator `schema`, `operation`, and
1380
+ * `operations` methods.
1381
+ *
1382
+ * Generators are only invoked from `runPluginAstHooks`, which already guards against a
1383
+ * missing adapter. This type reflects that guarantee — `ctx.adapter` and `ctx.inputNode`
1384
+ * are always defined, so no runtime checks or casts are needed inside generator bodies.
1385
+ *
1386
+ * `ctx.options` carries the per-node resolved options for `schema`/`operation` calls
1387
+ * (after exclude/include/override filtering) and the plugin-level options for `operations`.
1388
+ */
1389
+ type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
1390
+ config: Config;
1391
+ /**
1392
+ * Absolute path to the output directory for the current plugin.
1393
+ * Shorthand for `path.resolve(config.root, config.output.path)`.
1394
+ */
1395
+ root: string;
1396
+ /**
1397
+ * Returns the output mode for the given output config.
1398
+ * Returns `'single'` when `output.path` has a file extension, `'split'` otherwise.
1399
+ */
1400
+ getMode: (output: {
1401
+ path: string;
1402
+ }) => 'single' | 'split';
1403
+ driver: PluginDriver;
1404
+ /**
1405
+ * Get a plugin by name. Returns the plugin typed via `Kubb.PluginRegistry` when
1406
+ * the name is a registered key, otherwise returns the generic `Plugin`.
1407
+ */
1408
+ getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
1409
+ getPlugin(name: string): Plugin | undefined;
1410
+ /**
1411
+ * Like `getPlugin` but throws a descriptive error when the plugin is not found.
1412
+ */
1413
+ requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>;
1414
+ requirePlugin(name: string): Plugin;
1415
+ /**
1416
+ * Get a resolver by plugin name. Returns the resolver typed via `Kubb.PluginRegistry` when
1417
+ * the name is a registered key, otherwise returns the generic `Resolver`.
1418
+ */
1419
+ getResolver<TName extends keyof Kubb.PluginRegistry>(name: TName): Kubb.PluginRegistry[TName]['resolver'];
1420
+ getResolver(name: string): Resolver;
1421
+ /**
1422
+ * Add files only when they do not exist yet.
1423
+ */
1424
+ addFile: (...file: Array<FileNode>) => Promise<void>;
1425
+ /**
1426
+ * Merge multiple sources into the same output file.
1427
+ */
1428
+ upsertFile: (...file: Array<FileNode>) => Promise<void>;
1429
+ hooks: AsyncEventEmitter<KubbHooks>;
1430
+ /**
1431
+ * The current plugin.
1432
+ */
1433
+ plugin: Plugin<TOptions>;
1434
+ /**
1435
+ * Resolver for the current plugin.
1436
+ */
1437
+ resolver: TOptions['resolver'];
1438
+ /**
1439
+ * Composed transformer for the current plugin.
1440
+ */
1441
+ transformer: Visitor | undefined;
1442
+ /**
1443
+ * Emit a warning via the build event system.
1444
+ */
1445
+ warn: (message: string) => void;
1446
+ /**
1447
+ * Emit an error via the build event system.
1448
+ */
1449
+ error: (error: string | Error) => void;
1450
+ /**
1451
+ * Emit an info message via the build event system.
1452
+ */
1453
+ info: (message: string) => void;
1454
+ /**
1455
+ * Opens the Kubb Studio URL for the current `inputNode` in the default browser.
1456
+ */
1457
+ openInStudio: (options?: DevtoolsOptions) => Promise<void>;
1458
+ /**
1459
+ * The adapter from `@kubb/ast`.
1460
+ */
1461
+ adapter: Adapter;
1462
+ /**
1463
+ * The universal `@kubb/ast` `InputNode` produced by the configured adapter.
1464
+ */
1465
+ inputNode: InputNode;
1466
+ /**
1467
+ * Per-node resolved options (after exclude/include/override filtering).
1468
+ */
1469
+ options: TOptions['resolvedOptions'];
1470
+ };
1471
+ /**
1472
+ * Configure generated file output location and behavior.
1473
+ */
1474
+ type Output<_TOptions = unknown> = {
1475
+ /**
1476
+ * Path to the output folder or file that will contain generated code.
1477
+ */
1478
+ path: string;
1479
+ /**
1480
+ * Text or function appended at the start of every generated file.
1481
+ * When a function, receives the current `InputNode` and must return a string.
1482
+ */
1483
+ banner?: string | ((node?: InputNode) => string);
1484
+ /**
1485
+ * Text or function appended at the end of every generated file.
1486
+ * When a function, receives the current `InputNode` and must return a string.
1487
+ */
1488
+ footer?: string | ((node?: InputNode) => string);
1489
+ /**
1490
+ * Whether to override existing external files if they already exist.
1491
+ * @default false
1492
+ */
1493
+ override?: boolean;
1494
+ } & ExtractRegistryKey<Kubb.PluginOptionsRegistry, 'output'>;
1495
+ type Group = {
1496
+ /**
1497
+ * Determines how files are grouped into subdirectories.
1498
+ * - `'tag'` groups files by OpenAPI tags.
1499
+ * - `'path'` groups files by OpenAPI paths.
1500
+ */
1501
+ type: 'tag' | 'path';
1502
+ /**
1503
+ * Returns the subdirectory name for a given group value.
1504
+ * Defaults to `${camelCase(group)}Controller` for tags and the first path segment for paths.
1505
+ */
1506
+ name?: (context: {
1507
+ group: string;
1508
+ }) => string;
1509
+ };
1510
+ type LoggerOptions = {
1511
+ /**
1512
+ * @default 3
1513
+ */
1514
+ logLevel: (typeof logLevel)[keyof typeof logLevel];
1515
+ };
1516
+ /**
1517
+ * Shared context passed to all plugins, parsers, and other internals.
1518
+ */
1519
+ type LoggerContext = AsyncEventEmitter<KubbHooks>;
1520
+ type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
1521
+ name: string;
1522
+ install: (context: LoggerContext, options?: TOptions) => void | Promise<void>;
1523
+ };
1524
+ type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Logger<TOptions>;
1525
+ /**
1526
+ * Context passed to a hook-style plugin's `kubb:plugin:setup` handler.
1527
+ * Provides methods to register generators, configure the resolver, transformer,
1528
+ * and renderer, as well as access to the current build configuration.
1529
+ */
1530
+ type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
1531
+ /**
1532
+ * Register a generator on this plugin. Generators are invoked during the AST walk
1533
+ * (schema/operation/operations) exactly like generators declared statically on `createPlugin`.
1534
+ */
1535
+ addGenerator<TElement = unknown>(generator: Generator<TFactory, TElement>): void;
1536
+ /**
1537
+ * Set or partially override the resolver for this plugin.
1538
+ * The resolver controls file naming and path resolution for generated files.
1539
+ *
1540
+ * When `TFactory` is a concrete `PluginFactoryOptions` (e.g. `PluginClient`),
1541
+ * the resolver parameter is typed to the plugin's own resolver type (e.g. `ResolverClient`).
1542
+ */
1543
+ setResolver(resolver: Partial<TFactory['resolver']>): void;
1544
+ /**
1545
+ * Set the AST transformer (visitor) for this plugin.
1546
+ * The transformer pre-processes nodes before they reach the generators.
1547
+ */
1548
+ setTransformer(visitor: Visitor): void;
1549
+ /**
1550
+ * Set the renderer factory for this plugin.
1551
+ * Used to process JSX elements returned by generators.
1552
+ */
1553
+ setRenderer(renderer: RendererFactory): void;
1554
+ /**
1555
+ * Set the resolved options for the build loop. These options are merged into the
1556
+ * normalized plugin's `options` object (which includes `output`, `exclude`, `override`).
1557
+ *
1558
+ * Call this in `kubb:plugin:setup` to provide the resolved options that generators
1559
+ * and the build loop need (e.g., `enumType`, `optionalType`, `group`).
1560
+ */
1561
+ setOptions(options: TFactory['resolvedOptions']): void;
1562
+ /**
1563
+ * Inject a raw file into the build output, bypassing the normal generation pipeline.
1564
+ */
1565
+ injectFile(file: Pick<FileNode, 'baseName' | 'path'> & {
1566
+ sources?: FileNode['sources'];
1567
+ }): void;
1568
+ /**
1569
+ * Merge a partial config update into the current build configuration.
1570
+ */
1571
+ updateConfig(config: Partial<Config>): void;
1572
+ /**
1573
+ * The resolved build configuration at the time of setup.
1574
+ */
1575
+ config: Config;
1576
+ /**
1577
+ * The plugin's own options as passed by the user.
1578
+ */
1579
+ options: TFactory['options'];
1580
+ };
1581
+ /**
1582
+ * Context passed to a hook-style plugin's `kubb:build:start` handler.
1583
+ * Fires immediately before the plugin execution loop begins.
1584
+ */
1585
+ type KubbBuildStartContext = {
1586
+ config: Config;
1587
+ adapter: Adapter;
1588
+ inputNode: InputNode;
1589
+ /**
1590
+ * Get a plugin by name. Returns the plugin typed via `Kubb.PluginRegistry` when
1591
+ * the name is a registered key, otherwise returns the generic `Plugin`.
1592
+ */
1593
+ getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
1594
+ getPlugin(name: string): Plugin | undefined;
1595
+ /**
1596
+ * Returns all files currently in the file manager.
1597
+ * Call this lazily (e.g. inside a `kubb:plugin:end` listener) to see files added by plugins
1598
+ * that have already run.
1599
+ */
1600
+ readonly files: ReadonlyArray<FileNode>;
1601
+ /**
1602
+ * Upsert one or more files into the file manager.
1603
+ * Files with the same path are merged; new files are appended.
1604
+ * Safe to call at any point during the plugin lifecycle, including inside `kubb:plugin:end`.
1605
+ */
1606
+ upsertFile: (...files: Array<FileNode>) => void;
1607
+ };
1608
+ /**
1609
+ * Context passed to `kubb:plugins:end` handlers.
1610
+ * Fires after all plugins have run and per-plugin barrels have been written,
1611
+ * but BEFORE files are written to disk.
1612
+ * Middleware that needs to inject final files (e.g. a root barrel) should use this event.
1613
+ */
1614
+ type KubbPluginsEndContext = {
1615
+ config: Config;
1616
+ /**
1617
+ * Returns all files currently in the file manager (lazy snapshot).
1618
+ * Includes files added by plugins and per-plugin barrel middleware.
1619
+ */
1620
+ readonly files: ReadonlyArray<FileNode>;
1621
+ /**
1622
+ * Upsert one or more files into the file manager.
1623
+ * Files added here will be included in the write pass that follows.
1624
+ */
1625
+ upsertFile: (...files: Array<FileNode>) => void;
1626
+ };
1627
+ /**
1628
+ * Context passed to a hook-style plugin's `kubb:build:end` handler.
1629
+ * Fires after all files have been written to disk.
1630
+ */
1631
+ type KubbBuildEndContext = {
1632
+ files: Array<FileNode>;
1633
+ config: Config;
1634
+ outputDir: string;
1635
+ };
1636
+ type KubbLifecycleStartContext = {
1637
+ version: string;
1638
+ };
1639
+ type KubbConfigEndContext = {
1640
+ configs: Array<Config>;
1641
+ };
1642
+ type KubbGenerationStartContext = {
1643
+ config: Config;
1644
+ };
1645
+ type KubbGenerationEndContext = {
1646
+ config: Config;
1647
+ files: Array<FileNode>;
1648
+ sources: Map<string, string>;
1649
+ };
1650
+ type KubbGenerationSummaryContext = {
1651
+ config: Config;
1652
+ failedPlugins: Set<{
1653
+ plugin: Plugin;
1654
+ error: Error;
1655
+ }>;
1656
+ status: 'success' | 'failed';
1657
+ hrStart: [number, number];
1658
+ filesCreated: number;
1659
+ pluginTimings?: Map<Plugin['name'], number>;
1660
+ };
1661
+ type KubbVersionNewContext = {
1662
+ currentVersion: string;
1663
+ latestVersion: string;
1664
+ };
1665
+ type KubbInfoContext = {
1666
+ message: string;
1667
+ info?: string;
1668
+ };
1669
+ type KubbErrorContext = {
1670
+ error: Error;
1671
+ meta?: Record<string, unknown>;
1672
+ };
1673
+ type KubbSuccessContext = {
1674
+ message: string;
1675
+ info?: string;
1676
+ };
1677
+ type KubbWarnContext = {
1678
+ message: string;
1679
+ info?: string;
1680
+ };
1681
+ type KubbDebugContext = {
1682
+ date: Date;
1683
+ logs: Array<string>;
1684
+ fileName?: string;
1685
+ };
1686
+ type KubbFilesProcessingStartContext = {
1687
+ files: Array<FileNode>;
1688
+ };
1689
+ type KubbFileProcessingUpdateContext = {
1690
+ /**
1691
+ * Number of files processed so far.
1692
+ */
1693
+ processed: number;
1694
+ /**
1695
+ * Total number of files to process.
1696
+ */
1697
+ total: number;
1698
+ /**
1699
+ * Processing percentage (0–100).
1700
+ */
1701
+ percentage: number;
1702
+ /**
1703
+ * Optional source identifier.
1704
+ */
1705
+ source?: string;
1706
+ /**
1707
+ * The file being processed.
1708
+ */
1709
+ file: FileNode;
1710
+ /**
1711
+ * Kubb configuration.
1712
+ * Provides access to the current config during file processing.
1713
+ */
1714
+ config: Config;
1715
+ };
1716
+ type KubbFilesProcessingEndContext = {
1717
+ files: Array<FileNode>;
1718
+ };
1719
+ type KubbPluginStartContext = {
1720
+ plugin: Plugin;
1721
+ };
1722
+ type KubbPluginEndContext = {
1723
+ plugin: Plugin;
1724
+ duration: number;
1725
+ success: boolean;
1726
+ error?: Error;
1727
+ };
1728
+ type KubbHookStartContext = {
1729
+ id?: string;
1730
+ command: string;
1731
+ args?: readonly string[];
1732
+ };
1733
+ type KubbHookEndContext = {
1734
+ id?: string;
1735
+ command: string;
1736
+ args?: readonly string[];
1737
+ success: boolean;
1738
+ error: Error | null;
1739
+ };
1740
+ type ByTag = {
1741
+ type: 'tag';
1742
+ pattern: string | RegExp;
1743
+ };
1744
+ type ByOperationId = {
1745
+ type: 'operationId';
1746
+ pattern: string | RegExp;
1747
+ };
1748
+ type ByPath = {
1749
+ type: 'path';
1750
+ pattern: string | RegExp;
1751
+ };
1752
+ type ByMethod = {
1753
+ type: 'method';
1754
+ pattern: HttpMethod | RegExp;
1755
+ };
1756
+ type BySchemaName = {
1757
+ type: 'schemaName';
1758
+ pattern: string | RegExp;
1759
+ };
1760
+ type ByContentType = {
1761
+ type: 'contentType';
1762
+ pattern: string | RegExp;
1763
+ };
1764
+ /**
1765
+ * A pattern filter that prevents matching nodes from being generated.
1766
+ * Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
1767
+ */
1768
+ type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
1769
+ /**
1770
+ * A pattern filter that restricts generation to only matching nodes.
1771
+ * Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
1772
+ */
1773
+ type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
1774
+ /**
1775
+ * A pattern filter paired with partial option overrides applied when the pattern matches.
1776
+ * Match by `tag`, `operationId`, `path`, `method`, `schemaName`, or `contentType`.
1777
+ */
1778
+ type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
1779
+ options: Partial<TOptions>;
1780
+ };
1781
+ /**
1782
+ * File-specific parameters for `Resolver.resolvePath`.
1783
+ *
1784
+ * Pass alongside a `ResolverContext` to identify which file to resolve.
1785
+ * Provide `tag` for tag-based grouping or `path` for path-based grouping.
1786
+ *
1787
+ * @example
1788
+ * ```ts
1789
+ * resolver.resolvePath(
1790
+ * { baseName: 'petTypes.ts', tag: 'pets' },
1791
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
1792
+ * )
1793
+ * // → '/src/types/petsController/petTypes.ts'
1794
+ * ```
1795
+ */
1796
+ type ResolverPathParams = {
1797
+ baseName: FileNode['baseName'];
1798
+ pathMode?: 'single' | 'split';
1799
+ /**
1800
+ * Tag value used when `group.type === 'tag'`.
1801
+ */
1802
+ tag?: string;
1803
+ /**
1804
+ * Path value used when `group.type === 'path'`.
1805
+ */
1806
+ path?: string;
1807
+ };
1808
+ /**
1809
+ * Shared context passed as the second argument to `Resolver.resolvePath` and `Resolver.resolveFile`.
1810
+ *
1811
+ * Describes where on disk output is rooted, which output config is active, and the optional
1812
+ * grouping strategy that controls subdirectory layout.
1813
+ *
1814
+ * @example
1815
+ * ```ts
1816
+ * const context: ResolverContext = {
1817
+ * root: config.root,
1818
+ * output,
1819
+ * group,
1820
+ * }
1821
+ * ```
1822
+ */
1823
+ type ResolverContext = {
1824
+ root: string;
1825
+ output: Output;
1826
+ group?: Group;
1827
+ /**
1828
+ * Plugin name used to populate `meta.pluginName` on the resolved file.
1829
+ */
1830
+ pluginName?: string;
1831
+ };
1832
+ /**
1833
+ * File-specific parameters for `Resolver.resolveFile`.
1834
+ *
1835
+ * Pass alongside a `ResolverContext` to fully describe the file to resolve.
1836
+ * `tag` and `path` are used only when a matching `group` is present in the context.
1837
+ *
1838
+ * @example
1839
+ * ```ts
1840
+ * resolver.resolveFile(
1841
+ * { name: 'listPets', extname: '.ts', tag: 'pets' },
1842
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
1843
+ * )
1844
+ * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
1845
+ * ```
1846
+ */
1847
+ type ResolverFileParams = {
1848
+ name: string;
1849
+ extname: FileNode['extname'];
1850
+ /**
1851
+ * Tag value used when `group.type === 'tag'`.
1852
+ */
1853
+ tag?: string;
1854
+ /**
1855
+ * Path value used when `group.type === 'path'`.
1856
+ */
1857
+ path?: string;
1858
+ };
1859
+ /**
1860
+ * Context passed to `Resolver.resolveBanner` and `Resolver.resolveFooter`.
1861
+ *
1862
+ * `output` is optional — not every plugin configures a banner/footer.
1863
+ * `config` carries the global Kubb config, used to derive the default Kubb banner.
1864
+ *
1865
+ * @example
1866
+ * ```ts
1867
+ * resolver.resolveBanner(inputNode, { output: { banner: '// generated' }, config })
1868
+ * // → '// generated'
1869
+ * ```
1870
+ */
1871
+ type ResolveBannerContext = {
1872
+ output?: Pick<Output, 'banner' | 'footer'>;
1873
+ config: Config;
1874
+ };
1875
+ /**
1876
+ * CLI options derived from command-line flags.
1877
+ */
1878
+ type CLIOptions = {
1879
+ /**
1880
+ * Path to `kubb.config.js`.
1881
+ */
1882
+ config?: string;
1883
+ /**
1884
+ * Enable watch mode for input files.
1885
+ */
1886
+ watch?: boolean;
1887
+ /**
1888
+ * Logging verbosity for CLI usage.
1889
+ * @default 'silent'
1890
+ */
1891
+ logLevel?: 'silent' | 'info' | 'debug';
1892
+ };
1893
+ /**
1894
+ * All accepted forms of a Kubb configuration.
1895
+ *
1896
+ * Config is always `@kubb/core` {@link Config}.
1897
+ * - `PossibleConfig` accepts `Config`/`Config[]`/promise or a no-arg config factory.
1898
+ * - `PossibleConfig<TCliOptions>` accepts the same config forms or a config factory receiving `TCliOptions`.
1899
+ */
1900
+ type PossibleConfig<TCliOptions = undefined> = PossiblePromise<Config | Config[]> | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Config[]>);
1901
+ //#endregion
1902
+ 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 };
1903
+ //# sourceMappingURL=types-i0b4_23K.d.ts.map