@kubb/core 5.0.0-beta.6 → 5.0.0-beta.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 (56) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +25 -158
  3. package/dist/diagnostics-B-UZnFqP.d.ts +2906 -0
  4. package/dist/index.cjs +2497 -1071
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.ts +80 -273
  7. package/dist/index.js +2487 -1067
  8. package/dist/index.js.map +1 -1
  9. package/dist/memoryStorage-CUj1hrxa.cjs +823 -0
  10. package/dist/memoryStorage-CUj1hrxa.cjs.map +1 -0
  11. package/dist/memoryStorage-CWFzAz4o.js +714 -0
  12. package/dist/memoryStorage-CWFzAz4o.js.map +1 -0
  13. package/dist/mocks.cjs +79 -19
  14. package/dist/mocks.cjs.map +1 -1
  15. package/dist/mocks.d.ts +35 -9
  16. package/dist/mocks.js +80 -22
  17. package/dist/mocks.js.map +1 -1
  18. package/package.json +8 -28
  19. package/src/FileManager.ts +86 -64
  20. package/src/FileProcessor.ts +170 -44
  21. package/src/KubbDriver.ts +908 -0
  22. package/src/Transform.ts +75 -0
  23. package/src/constants.ts +111 -20
  24. package/src/createAdapter.ts +112 -17
  25. package/src/createKubb.ts +140 -517
  26. package/src/createRenderer.ts +43 -28
  27. package/src/createReporter.ts +134 -0
  28. package/src/createStorage.ts +36 -23
  29. package/src/defineGenerator.ts +147 -17
  30. package/src/defineParser.ts +30 -12
  31. package/src/definePlugin.ts +370 -21
  32. package/src/defineResolver.ts +402 -212
  33. package/src/diagnostics.ts +662 -0
  34. package/src/index.ts +8 -8
  35. package/src/mocks.ts +91 -20
  36. package/src/reporters/cliReporter.ts +89 -0
  37. package/src/reporters/fileReporter.ts +103 -0
  38. package/src/reporters/jsonReporter.ts +20 -0
  39. package/src/reporters/report.ts +85 -0
  40. package/src/storages/fsStorage.ts +23 -55
  41. package/src/types.ts +411 -887
  42. package/dist/PluginDriver-BkTRD2H2.js +0 -946
  43. package/dist/PluginDriver-BkTRD2H2.js.map +0 -1
  44. package/dist/PluginDriver-Cadu4ORh.cjs +0 -1037
  45. package/dist/PluginDriver-Cadu4ORh.cjs.map +0 -1
  46. package/dist/types-DVPKmzw_.d.ts +0 -2159
  47. package/src/Kubb.ts +0 -300
  48. package/src/PluginDriver.ts +0 -426
  49. package/src/defineLogger.ts +0 -19
  50. package/src/defineMiddleware.ts +0 -62
  51. package/src/devtools.ts +0 -59
  52. package/src/renderNode.ts +0 -35
  53. package/src/utils/diagnostics.ts +0 -18
  54. package/src/utils/isInputPath.ts +0 -10
  55. package/src/utils/packageJSON.ts +0 -99
  56. /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
@@ -0,0 +1,2906 @@
1
+ import { t as __name } from "./chunk-C0LytTxp.js";
2
+ import { FileNode, HttpMethod, ImportNode, InputMeta, InputNode, Node, OperationNode, SchemaNode, UserFileNode, 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 Array<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]: Array<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> | 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
+ * Raises or lowers the per-event listener ceiling before Node warns about a memory leak.
76
+ * Set this above the expected listener count when many listeners attach by design.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * emitter.setMaxListeners(40)
81
+ * ```
82
+ */
83
+ setMaxListeners(max: number): void;
84
+ /**
85
+ * Returns the current per-event listener ceiling.
86
+ */
87
+ getMaxListeners(): number;
88
+ /**
89
+ * Removes all listeners from every event channel.
90
+ *
91
+ * @example
92
+ * ```ts
93
+ * emitter.removeAll()
94
+ * ```
95
+ */
96
+ removeAll(): void;
97
+ }
98
+ //#endregion
99
+ //#region ../../internals/utils/src/promise.d.ts
100
+ /** A value that may already be resolved or still pending.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * function load(id: string): PossiblePromise<string> {
105
+ * return cache.get(id) ?? fetchRemote(id)
106
+ * }
107
+ * ```
108
+ */
109
+ type PossiblePromise<T> = Promise<T> | T;
110
+ //#endregion
111
+ //#region src/createAdapter.d.ts
112
+ /**
113
+ * Source data handed to an adapter's `parse` function. Mirrors the config
114
+ * input shape with paths resolved to absolute.
115
+ *
116
+ * - `{ type: 'path' }`: single file on disk.
117
+ * - `{ type: 'paths' }`: multiple files (e.g. split spec).
118
+ * - `{ type: 'data' }`: raw string or parsed object provided inline.
119
+ */
120
+ type AdapterSource = {
121
+ type: 'path';
122
+ path: string;
123
+ } | {
124
+ type: 'data';
125
+ data: string | unknown;
126
+ } | {
127
+ type: 'paths';
128
+ paths: Array<string>;
129
+ };
130
+ /**
131
+ * Generic parameters used by `createAdapter` and the resulting `Adapter` type.
132
+ *
133
+ * - `TName`: unique adapter identifier (`'oas'`, `'asyncapi'`, ...).
134
+ * - `TOptions`: user-facing options accepted by the adapter factory.
135
+ * - `TResolvedOptions`: options after defaults are applied.
136
+ * - `TDocument`: type of the parsed source document.
137
+ */
138
+ type AdapterFactoryOptions<TName extends string = string, TOptions extends object = object, TResolvedOptions extends object = TOptions, TDocument = unknown> = {
139
+ name: TName;
140
+ options: TOptions;
141
+ resolvedOptions: TResolvedOptions;
142
+ document: TDocument;
143
+ };
144
+ /**
145
+ * Converts input files or inline data into Kubb's universal AST `InputNode`.
146
+ *
147
+ * Adapters live between the spec format and the plugins. The built-in
148
+ * `@kubb/adapter-oas` handles OpenAPI 2.0, 3.0, and 3.1. A custom adapter can
149
+ * support GraphQL, gRPC, or another schema language.
150
+ *
151
+ * @example
152
+ * ```ts
153
+ * import { defineConfig } from 'kubb'
154
+ * import { adapterOas } from '@kubb/adapter-oas'
155
+ * import { pluginTs } from '@kubb/plugin-ts'
156
+ *
157
+ * export default defineConfig({
158
+ * input: { path: './petStore.yaml' },
159
+ * output: { path: './src/gen' },
160
+ * adapter: adapterOas(),
161
+ * plugins: [pluginTs()],
162
+ * })
163
+ * ```
164
+ */
165
+ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
166
+ /**
167
+ * Human-readable adapter identifier (e.g. `'oas'`, `'asyncapi'`).
168
+ */
169
+ name: TOptions['name'];
170
+ /**
171
+ * Resolved adapter options after defaults have been applied.
172
+ */
173
+ options: TOptions['resolvedOptions'];
174
+ /**
175
+ * Parsed source document after the first `parse()` call. `null` before parsing.
176
+ */
177
+ document: TOptions['document'] | null;
178
+ /**
179
+ * Parse the source into a universal `InputNode`.
180
+ */
181
+ parse: (source: AdapterSource) => PossiblePromise<InputNode>;
182
+ /**
183
+ * Extract `ImportNode` entries for a schema tree.
184
+ * Returns an empty array before the first `parse()` call.
185
+ *
186
+ * The `resolve` callback receives the collision-corrected schema name and must
187
+ * return `{ name, path }` for the import, or `undefined` to skip it.
188
+ */
189
+ getImports: (node: SchemaNode, resolve: (schemaName: string) => {
190
+ name: string;
191
+ path: string;
192
+ }) => Array<ImportNode>;
193
+ /**
194
+ * Validate the document at the given path or URL.
195
+ */
196
+ validate: (input: string, options?: {
197
+ throwOnError?: boolean;
198
+ }) => Promise<void>;
199
+ /**
200
+ * Memory-efficient streaming variant of `parse()`.
201
+ *
202
+ * Returns an `InputNode<true>` whose `schemas` and `operations` are `AsyncIterable`.
203
+ * Each `for await` loop creates a fresh parse pass over the cached in-memory document.
204
+ * No pre-built arrays are held in memory.
205
+ */
206
+ stream?: (source: AdapterSource) => Promise<InputNode<true>>;
207
+ };
208
+ type AdapterBuilder<T extends AdapterFactoryOptions> = (options: T['options']) => Adapter<T>;
209
+ /**
210
+ * Defines a custom adapter that translates a spec format into Kubb's universal
211
+ * AST, for example GraphQL, gRPC, or AsyncAPI. The built-in `@kubb/adapter-oas`
212
+ * handles OpenAPI/Swagger documents.
213
+ *
214
+ * Adapters must return an `InputNode` from `parse`. That node is what every
215
+ * plugin in the build consumes.
216
+ *
217
+ * @example
218
+ * ```ts
219
+ * import { createAdapter, ast, type AdapterFactoryOptions } from '@kubb/core'
220
+ *
221
+ * type MyAdapter = AdapterFactoryOptions<'my-adapter', { validate?: boolean }>
222
+ *
223
+ * export const myAdapter = createAdapter<MyAdapter>((options) => ({
224
+ * name: 'my-adapter',
225
+ * options,
226
+ * document: null,
227
+ * async parse(_source) {
228
+ * // Convert `source` (path or inline data) into an InputNode.
229
+ * return ast.factory.createInput()
230
+ * },
231
+ * getImports: () => [],
232
+ * async validate() {
233
+ * // Throw or call ctx.error here when the spec is invalid.
234
+ * },
235
+ * }))
236
+ * ```
237
+ */
238
+ declare function createAdapter<T extends AdapterFactoryOptions = AdapterFactoryOptions>(build: AdapterBuilder<T>): (options?: T['options']) => Adapter<T>;
239
+ //#endregion
240
+ //#region src/constants.d.ts
241
+ /**
242
+ * Stable codes Kubb attaches to a `Diagnostic`. Each maps to a known failure mode
243
+ * and stays stable so it can be referenced in tooling and (later) docs. Reference
244
+ * these instead of inlining the string at a throw site.
245
+ */
246
+ declare const diagnosticCode: {
247
+ /**
248
+ * Fallback for an unstructured error with no specific code.
249
+ */
250
+ readonly unknown: "KUBB_UNKNOWN";
251
+ /**
252
+ * The `input.path` file or URL could not be read.
253
+ */
254
+ readonly inputNotFound: "KUBB_INPUT_NOT_FOUND";
255
+ /**
256
+ * An adapter was configured without an `input`.
257
+ */
258
+ readonly inputRequired: "KUBB_INPUT_REQUIRED";
259
+ /**
260
+ * A `$ref` (or equivalent reference) could not be resolved in the source document.
261
+ */
262
+ readonly refNotFound: "KUBB_REF_NOT_FOUND";
263
+ /**
264
+ * A server variable value is not allowed by its `enum`.
265
+ */
266
+ readonly invalidServerVariable: "KUBB_INVALID_SERVER_VARIABLE";
267
+ /**
268
+ * A required plugin is missing from the config.
269
+ */
270
+ readonly pluginNotFound: "KUBB_PLUGIN_NOT_FOUND";
271
+ /**
272
+ * A plugin threw while generating.
273
+ */
274
+ readonly pluginFailed: "KUBB_PLUGIN_FAILED";
275
+ /**
276
+ * A plugin reported a non-fatal warning through `ctx.warn`.
277
+ */
278
+ readonly pluginWarning: "KUBB_PLUGIN_WARNING";
279
+ /**
280
+ * A plugin reported an informational message through `ctx.info`.
281
+ */
282
+ readonly pluginInfo: "KUBB_PLUGIN_INFO";
283
+ /**
284
+ * A schema uses a `format` Kubb does not map to a specific type. Reserved for
285
+ * adapters to emit as a `warning`.
286
+ */
287
+ readonly unsupportedFormat: "KUBB_UNSUPPORTED_FORMAT";
288
+ /**
289
+ * A referenced schema or operation is marked `deprecated`. Reserved for adapters
290
+ * to emit as an `info`.
291
+ */
292
+ readonly deprecated: "KUBB_DEPRECATED";
293
+ /**
294
+ * An adapter is required but the config has none. The build cannot read the input
295
+ * without one.
296
+ */
297
+ readonly adapterRequired: "KUBB_ADAPTER_REQUIRED";
298
+ /**
299
+ * A resolved output path escapes the output directory, which can stem from a path
300
+ * traversal in the spec or a misconfigured `group.name`.
301
+ */
302
+ readonly pathTraversal: "KUBB_PATH_TRAVERSAL";
303
+ /**
304
+ * A plugin's options are invalid, for example `output.mode: 'file'` paired with a `group` option.
305
+ */
306
+ readonly invalidPluginOptions: "KUBB_INVALID_PLUGIN_OPTIONS";
307
+ /**
308
+ * A post-generate shell hook (`hooks.done`) exited with a failure.
309
+ */
310
+ readonly hookFailed: "KUBB_HOOK_FAILED";
311
+ /**
312
+ * The formatter pass over the generated files failed.
313
+ */
314
+ readonly formatFailed: "KUBB_FORMAT_FAILED";
315
+ /**
316
+ * The linter pass over the generated files failed.
317
+ */
318
+ readonly lintFailed: "KUBB_LINT_FAILED";
319
+ /**
320
+ * Not a failure. Carries a plugin's elapsed time, summed into the run total.
321
+ */
322
+ readonly performance: "KUBB_PERFORMANCE";
323
+ /**
324
+ * Not a failure. A newer Kubb version is available on npm.
325
+ */
326
+ readonly updateAvailable: "KUBB_UPDATE_AVAILABLE";
327
+ };
328
+ /**
329
+ * Union of the stable {@link diagnosticCode} values.
330
+ */
331
+ type DiagnosticCode = (typeof diagnosticCode)[keyof typeof diagnosticCode];
332
+ //#endregion
333
+ //#region src/createReporter.d.ts
334
+ /**
335
+ * Numeric log-level thresholds used internally to compare verbosity.
336
+ *
337
+ * Higher numbers are more verbose.
338
+ */
339
+ declare const logLevel: {
340
+ readonly silent: number;
341
+ readonly error: 0;
342
+ readonly warn: 1;
343
+ readonly info: 3;
344
+ readonly verbose: 4;
345
+ };
346
+ /**
347
+ * A built-in reporter that renders a run's output, independent of the live logger view.
348
+ *
349
+ * - `cli` renders the per-config summary to the terminal (the default).
350
+ * - `json` writes a machine-readable report to stdout, for CI.
351
+ * - `file` writes a config's diagnostics to `.kubb/kubb-<name>-<timestamp>.log`.
352
+ */
353
+ type ReporterName = 'cli' | 'json' | 'file';
354
+ /**
355
+ * One config's outcome within a run, as handed to a {@link Reporter}.
356
+ */
357
+ type GenerationResult = {
358
+ config: Config;
359
+ /**
360
+ * Diagnostics collected while generating this config.
361
+ */
362
+ diagnostics: Array<Diagnostic>;
363
+ /**
364
+ * Number of files written for this config.
365
+ */
366
+ filesCreated: number;
367
+ status: 'success' | 'failed';
368
+ /**
369
+ * `process.hrtime()` snapshot taken when this config started generating.
370
+ */
371
+ hrStart: [number, number];
372
+ };
373
+ /**
374
+ * Render context passed alongside the {@link GenerationResult}, carrying knobs a reporter needs
375
+ * but that are not part of the run data (e.g. verbosity).
376
+ */
377
+ type ReporterContext = {
378
+ /**
379
+ * Output verbosity. Use the `logLevel` constants exported from `@kubb/core`
380
+ * (`silent`, `error`, `warn`, `info`, `verbose`, `debug`).
381
+ */
382
+ logLevel: (typeof logLevel)[keyof typeof logLevel];
383
+ };
384
+ /**
385
+ * Host-facing reporter, as installed onto a run. Unlike a Logger (the live TUI view), a reporter
386
+ * never sees the event emitter. `report` runs once per config. `drain`, when present, runs once
387
+ * after the last config.
388
+ */
389
+ type Reporter = {
390
+ /**
391
+ * Display name, matching a {@link ReporterName} for the built-ins.
392
+ */
393
+ name: string;
394
+ /**
395
+ * Called once per config with that config's result and the render context.
396
+ */
397
+ report: (result: GenerationResult, context: ReporterContext) => void | Promise<void>;
398
+ /**
399
+ * Optional finalizer called once after the run's last config. The host wires it to
400
+ * `kubb:lifecycle:end`. {@link createReporter} closes it over the reports `report` returned.
401
+ */
402
+ drain?: (context: ReporterContext) => void | Promise<void>;
403
+ };
404
+ /**
405
+ * Reporter definition passed to {@link createReporter}. `report` returns the value to collect for
406
+ * this config (e.g. a built report), and the optional `drain` receives the collected reports to
407
+ * emit as one document. `T` is inferred from `report`'s return type.
408
+ */
409
+ type UserReporter<T = void> = {
410
+ name: string;
411
+ report: (result: GenerationResult, context: ReporterContext) => T | Promise<T>;
412
+ drain?: (context: ReporterContext, reports: Array<T>) => void | Promise<void>;
413
+ };
414
+ /**
415
+ * Defines a reporter. When the definition has a `drain`, the returned reporter buffers each value
416
+ * `report` returns and hands the array to `drain` once, then clears it. Without a `drain`, nothing
417
+ * is buffered. Wiring the reporter onto the run's events is the host's job, so the reporter only
418
+ * ever deals with a {@link GenerationResult}.
419
+ *
420
+ * @example
421
+ * ```ts
422
+ * import { createReporter, Diagnostics } from '@kubb/core'
423
+ *
424
+ * export const jsonReporter = createReporter({
425
+ * name: 'json',
426
+ * report(result) {
427
+ * return { status: Diagnostics.hasError(result.diagnostics) ? 'failed' : 'success', diagnostics: result.diagnostics }
428
+ * },
429
+ * drain(context, reports) {
430
+ * process.stdout.write(`${JSON.stringify(reports, null, 2)}\n`)
431
+ * },
432
+ * })
433
+ * ```
434
+ */
435
+ declare function createReporter<T = void>(reporter: UserReporter<T>): Reporter;
436
+ //#endregion
437
+ //#region src/createStorage.d.ts
438
+ /**
439
+ * Backend that persists generated files. Kubb ships with `fsStorage` (writes
440
+ * to disk) and `memoryStorage` (keeps everything in RAM). Implement this
441
+ * interface to write somewhere else, such as S3 or a database.
442
+ */
443
+ type Storage = {
444
+ /**
445
+ * Identifier used in logs and diagnostics (`'fs'`, `'memory'`, `'s3'`).
446
+ */
447
+ readonly name: string;
448
+ /**
449
+ * Returns `true` when an entry for `key` exists.
450
+ */
451
+ hasItem(key: string): Promise<boolean>;
452
+ /**
453
+ * Reads the stored string. Returns `null` when the key is missing.
454
+ */
455
+ getItem(key: string): Promise<string | null>;
456
+ /**
457
+ * Stores `value` under `key`, creating any required structure (directories,
458
+ * buckets, ...).
459
+ */
460
+ setItem(key: string, value: string): Promise<void>;
461
+ /**
462
+ * Deletes the entry for `key`. No-op when the key does not exist.
463
+ */
464
+ removeItem(key: string): Promise<void>;
465
+ /**
466
+ * Returns every key. Pass `base` to filter to keys starting with that prefix.
467
+ */
468
+ getKeys(base?: string): Promise<Array<string>>;
469
+ /**
470
+ * Removes every entry. Pass `base` to scope the wipe to a key prefix.
471
+ */
472
+ clear(base?: string): Promise<void>;
473
+ /**
474
+ * Optional teardown hook called after the build completes. Use to flush
475
+ * buffers, close connections, or release file locks.
476
+ */
477
+ dispose?(): Promise<void>;
478
+ };
479
+ /**
480
+ * Defines a custom storage backend. The builder receives user options and
481
+ * returns a `Storage` implementation. Kubb ships with filesystem and in-memory
482
+ * storages. A custom backend writes generated files elsewhere, such as cloud
483
+ * storage or a database.
484
+ *
485
+ * @example In-memory storage (the built-in implementation)
486
+ * ```ts
487
+ * import { createStorage } from '@kubb/core'
488
+ *
489
+ * export const memoryStorage = createStorage(() => {
490
+ * const store = new Map<string, string>()
491
+ *
492
+ * return {
493
+ * name: 'memory',
494
+ * async hasItem(key) {
495
+ * return store.has(key)
496
+ * },
497
+ * async getItem(key) {
498
+ * return store.get(key) ?? null
499
+ * },
500
+ * async setItem(key, value) {
501
+ * store.set(key, value)
502
+ * },
503
+ * async removeItem(key) {
504
+ * store.delete(key)
505
+ * },
506
+ * async getKeys(base) {
507
+ * const keys = [...store.keys()]
508
+ * return base ? keys.filter((k) => k.startsWith(base)) : keys
509
+ * },
510
+ * async clear(base) {
511
+ * if (!base) store.clear()
512
+ * },
513
+ * }
514
+ * })
515
+ * ```
516
+ */
517
+ declare function createStorage<TOptions = Record<string, never>>(build: (options: TOptions) => Storage): (options?: TOptions) => Storage;
518
+ //#endregion
519
+ //#region src/createRenderer.d.ts
520
+ /**
521
+ * Minimal interface any Kubb renderer must satisfy.
522
+ *
523
+ * `TElement` is the type the renderer accepts, for example `KubbReactElement`
524
+ * for `@kubb/renderer-jsx` or a custom type for your own renderer. Defaults to
525
+ * `unknown` so generators that don't care about the element type work without
526
+ * specifying it.
527
+ */
528
+ type Renderer<TElement = unknown> = {
529
+ /**
530
+ * Renders `element` and populates {@link files} with the resulting {@link FileNode} objects.
531
+ * Called once per render cycle. Must resolve before {@link files} is read.
532
+ */
533
+ render(element: TElement): Promise<void>;
534
+ /**
535
+ * Accumulated {@link FileNode} results produced by the last {@link render} call.
536
+ * Not populated when {@link stream} is implemented.
537
+ */
538
+ readonly files: Array<FileNode>;
539
+ /**
540
+ * When present, core calls this instead of {@link render} and {@link files},
541
+ * forwarding each file to `FileManager` as soon as it is ready.
542
+ */
543
+ stream?(element: TElement): Iterable<FileNode>;
544
+ /**
545
+ * Disposer hook so renderers participate in `using` blocks: `using r = rendererFactory()`
546
+ * runs cleanup on every exit path, including thrown errors.
547
+ */
548
+ [Symbol.dispose](): void;
549
+ };
550
+ /**
551
+ * A factory function that produces a fresh {@link Renderer} per render cycle.
552
+ *
553
+ * Generators use this to declare which renderer handles their output.
554
+ */
555
+ type RendererFactory<TElement = unknown> = () => Renderer<TElement>;
556
+ /**
557
+ * Defines a renderer factory. Renderers turn the generator's return value
558
+ * (JSX, a template string, a tree of any shape) into `FileNode`s that get
559
+ * written to disk.
560
+ *
561
+ * A renderer can target output formats beyond JSX, for instance a Handlebars
562
+ * renderer or one that writes binary files. Plugins and generators pick the
563
+ * renderer to use via the `renderer` field on `defineGenerator`.
564
+ *
565
+ * @example A minimal renderer that wraps a custom runtime
566
+ * ```ts
567
+ * import { createRenderer } from '@kubb/core'
568
+ *
569
+ * export const myRenderer = createRenderer(() => {
570
+ * const runtime = new MyRuntime()
571
+ * return {
572
+ * async render(element) {
573
+ * await runtime.render(element)
574
+ * },
575
+ * get files() {
576
+ * return runtime.files
577
+ * },
578
+ * [Symbol.dispose]() {
579
+ * runtime.dispose()
580
+ * },
581
+ * }
582
+ * })
583
+ * ```
584
+ */
585
+ declare function createRenderer<TElement = unknown>(factory: RendererFactory<TElement>): RendererFactory<TElement>;
586
+ //#endregion
587
+ //#region src/defineResolver.d.ts
588
+ /**
589
+ * Type/string pattern filter for include/exclude/override matching.
590
+ */
591
+ type PatternFilter = {
592
+ type: string;
593
+ pattern: string | RegExp;
594
+ };
595
+ /**
596
+ * Pattern filter with partial option overrides applied when the pattern matches.
597
+ */
598
+ type PatternOverride<TOptions> = PatternFilter & {
599
+ options: Omit<Partial<TOptions>, 'override'>;
600
+ };
601
+ /**
602
+ * Context for resolving filtered options for a given operation or schema node.
603
+ *
604
+ * @internal
605
+ */
606
+ type ResolveOptionsContext<TOptions> = {
607
+ options: TOptions;
608
+ exclude?: Array<PatternFilter>;
609
+ include?: Array<PatternFilter>;
610
+ override?: Array<PatternOverride<TOptions>>;
611
+ };
612
+ /**
613
+ * Base constraint for all plugin resolver objects.
614
+ *
615
+ * `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`
616
+ * are injected automatically by `defineResolver`. Extend this type to add custom resolution methods.
617
+ *
618
+ * @example
619
+ * ```ts
620
+ * type MyResolver = Resolver & {
621
+ * resolveName(node: SchemaNode): string
622
+ * resolveTypedName(node: SchemaNode): string
623
+ * }
624
+ * ```
625
+ */
626
+ type Resolver = {
627
+ name: string;
628
+ pluginName: string;
629
+ default(name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
630
+ resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null;
631
+ resolvePath(params: ResolverPathParams, context: ResolverContext): string;
632
+ resolveFile(params: ResolverFileParams, context: ResolverContext): FileNode;
633
+ resolveBanner(meta: InputMeta | undefined, context: ResolveBannerContext): string | null;
634
+ resolveFooter(meta: InputMeta | undefined, context: ResolveBannerContext): string | null;
635
+ };
636
+ /**
637
+ * File-specific parameters for `Resolver.resolvePath`.
638
+ *
639
+ * Pass alongside a `ResolverContext` to identify which file to resolve.
640
+ * Provide `tag` for tag-based grouping or `path` for path-based grouping.
641
+ *
642
+ * @example
643
+ * ```ts
644
+ * resolver.resolvePath(
645
+ * { baseName: 'petTypes.ts', tag: 'pets' },
646
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
647
+ * )
648
+ * // → '/src/types/pets/petTypes.ts'
649
+ * ```
650
+ */
651
+ type ResolverPathParams = {
652
+ baseName: FileNode['baseName'];
653
+ /**
654
+ * Tag value used when `group.type === 'tag'`.
655
+ */
656
+ tag?: string;
657
+ /**
658
+ * Path value used when `group.type === 'path'`.
659
+ */
660
+ path?: string;
661
+ };
662
+ /**
663
+ * Shared context passed as the second argument to `Resolver.resolvePath` and `Resolver.resolveFile`.
664
+ *
665
+ * Describes where on disk output is rooted, which output config is active, and the optional
666
+ * grouping strategy that controls subdirectory layout.
667
+ *
668
+ * @example
669
+ * ```ts
670
+ * const context: ResolverContext = {
671
+ * root: config.root,
672
+ * output,
673
+ * group,
674
+ * }
675
+ * ```
676
+ */
677
+ type ResolverContext = {
678
+ root: string;
679
+ output: Output;
680
+ group?: Group;
681
+ /**
682
+ * Plugin name used to populate `meta.pluginName` on the resolved file.
683
+ */
684
+ pluginName?: string;
685
+ };
686
+ /**
687
+ * File-specific parameters for `Resolver.resolveFile`.
688
+ *
689
+ * Pass alongside a `ResolverContext` to fully describe the file to resolve.
690
+ * `tag` and `path` are used only when a matching `group` is present in the context.
691
+ *
692
+ * @example
693
+ * ```ts
694
+ * resolver.resolveFile(
695
+ * { name: 'listPets', extname: '.ts', tag: 'pets' },
696
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
697
+ * )
698
+ * // → { baseName: 'listPets.ts', path: '/src/types/pets/listPets.ts', ... }
699
+ * ```
700
+ */
701
+ type ResolverFileParams = {
702
+ name: string;
703
+ extname: FileNode['extname'];
704
+ /**
705
+ * Tag value used when `group.type === 'tag'`.
706
+ */
707
+ tag?: string;
708
+ /**
709
+ * Path value used when `group.type === 'path'`.
710
+ */
711
+ path?: string;
712
+ };
713
+ /**
714
+ * Per-file context describing the file a banner/footer is being resolved for.
715
+ *
716
+ * Supplied by the generator (or the barrel plugin) at resolve-time and merged
717
+ * into `BannerMeta` so a `banner`/`footer` function can branch on the file kind,
718
+ * e.g. omit a `'use server'` directive on re-export files.
719
+ */
720
+ type ResolveBannerFile = {
721
+ /**
722
+ * Full output path of the file being generated.
723
+ */
724
+ path: string;
725
+ /**
726
+ * File name only, e.g. `'stocks.ts'`.
727
+ */
728
+ baseName: string;
729
+ /**
730
+ * `true` for `index.ts` re-export barrels.
731
+ */
732
+ isBarrel?: boolean;
733
+ /**
734
+ * `true` for group `[dir]/[dir].ts` aggregation files.
735
+ */
736
+ isAggregation?: boolean;
737
+ };
738
+ /**
739
+ * Document metadata extended with per-file context, passed to a `banner`/`footer` function.
740
+ *
741
+ * Carries everything in {@link InputMeta} plus the file the banner is rendered into, so a
742
+ * single function can decide per file (e.g. skip a directive on barrel/aggregation files).
743
+ *
744
+ * @example Skip a directive on re-export files
745
+ * `banner: (meta) => (meta.isBarrel || meta.isAggregation) ? '' : "'use server'"`
746
+ */
747
+ type BannerMeta = InputMeta & {
748
+ /**
749
+ * Full output path of the file being generated.
750
+ */
751
+ filePath: string;
752
+ /**
753
+ * File name only, e.g. `'stocks.ts'`.
754
+ */
755
+ baseName: string;
756
+ /**
757
+ * `true` for `index.ts` re-export barrels.
758
+ */
759
+ isBarrel: boolean;
760
+ /**
761
+ * `true` for group `[dir]/[dir].ts` aggregation files.
762
+ */
763
+ isAggregation: boolean;
764
+ };
765
+ /**
766
+ * Context passed to `Resolver.resolveBanner` and `Resolver.resolveFooter`.
767
+ *
768
+ * `output` is optional, since not every plugin configures a banner/footer.
769
+ * `config` carries the global Kubb config, used to derive the default Kubb banner.
770
+ * `file` carries per-file context forwarded to a `banner`/`footer` function.
771
+ *
772
+ * @example
773
+ * ```ts
774
+ * resolver.resolveBanner(meta, { output: { banner: '// generated' }, config })
775
+ * // → '// generated'
776
+ * ```
777
+ */
778
+ type ResolveBannerContext = {
779
+ output?: Pick<Output, 'banner' | 'footer'>;
780
+ config: Config;
781
+ file?: ResolveBannerFile;
782
+ };
783
+ /**
784
+ * Builder type for the plugin-specific resolver fields.
785
+ *
786
+ * `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`
787
+ * are optional, with built-in fallbacks injected when omitted.
788
+ *
789
+ * Methods in the returned object can call sibling resolver methods via `this`.
790
+ */
791
+ 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'>> & {
792
+ name: string;
793
+ pluginName: T['name'];
794
+ } & ThisType<T['resolver']>;
795
+ /**
796
+ * Default path resolver used by `defineResolver`.
797
+ *
798
+ * - `mode: 'file'` resolves directly to `output.path` (the full file path, extension included).
799
+ * - `mode: 'directory'` (default) resolves to `output.path/{baseName}`, or into a
800
+ * subdirectory when `group` and a `tag`/`path` value are provided.
801
+ *
802
+ * A custom `group.name` function overrides the default subdirectory naming.
803
+ * For `tag` groups the default is the camelCased tag.
804
+ * For `path` groups the default is the first path segment after `/`.
805
+ *
806
+ * @example Flat output
807
+ * ```ts
808
+ * defaultResolvePath({ baseName: 'petTypes.ts' }, { root: '/src', output: { path: 'types' } })
809
+ * // → '/src/types/petTypes.ts'
810
+ * ```
811
+ *
812
+ * @example Tag-based grouping
813
+ * ```ts
814
+ * defaultResolvePath(
815
+ * { baseName: 'petTypes.ts', tag: 'pets' },
816
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
817
+ * )
818
+ * // → '/src/types/pets/petTypes.ts'
819
+ * ```
820
+ *
821
+ * @example Path-based grouping
822
+ * ```ts
823
+ * defaultResolvePath(
824
+ * { baseName: 'petTypes.ts', path: '/pets/list' },
825
+ * { root: '/src', output: { path: 'types' }, group: { type: 'path' } },
826
+ * )
827
+ * // → '/src/types/pets/petTypes.ts'
828
+ * ```
829
+ *
830
+ * @example Single file (`mode: 'file'`)
831
+ * ```ts
832
+ * defaultResolvePath(
833
+ * { baseName: 'petTypes.ts' },
834
+ * { root: '/src', output: { path: 'types.ts', mode: 'file' } },
835
+ * )
836
+ * // → '/src/types.ts'
837
+ * ```
838
+ */
839
+ /**
840
+ * Defines a plugin resolver. The resolver is the object that decides what
841
+ * every generated symbol and file path is called. Built-in defaults handle
842
+ * name casing, include/exclude/override filtering, output path computation,
843
+ * and file construction. Supply your own to override any of them:
844
+ *
845
+ * - `default` sets the name casing strategy (camelCase or PascalCase).
846
+ * - `resolveOptions` does include/exclude/override filtering.
847
+ * - `resolvePath` computes the output path.
848
+ * - `resolveFile` builds the full `FileNode`.
849
+ * - `resolveBanner` and `resolveFooter` produce the top and bottom of file text.
850
+ *
851
+ * Methods in the returned object can call sibling resolver methods via `this`.
852
+ * A custom rule can delegate to a default, for example `this.default(name, 'type')`.
853
+ *
854
+ * @example Basic resolver with naming helpers
855
+ * ```ts
856
+ * export const resolverTs = defineResolver<PluginTs>(() => ({
857
+ * name: 'default',
858
+ * resolveName(name) {
859
+ * return this.default(name, 'function')
860
+ * },
861
+ * resolveTypeName(name) {
862
+ * return this.default(name, 'type')
863
+ * },
864
+ * }))
865
+ * ```
866
+ *
867
+ * @example Custom output path
868
+ * ```ts
869
+ * import path from 'node:path'
870
+ *
871
+ * export const resolverTs = defineResolver<PluginTs>(() => ({
872
+ * name: 'custom',
873
+ * resolvePath({ baseName }, { root, output }) {
874
+ * return path.resolve(root, output.path, 'generated', baseName)
875
+ * },
876
+ * }))
877
+ * ```
878
+ */
879
+ declare function defineResolver<T extends PluginFactoryOptions>(build: ResolverBuilder<T>): T['resolver'];
880
+ //#endregion
881
+ //#region src/definePlugin.d.ts
882
+ /**
883
+ * Reads a type from a registry, falling back to `{}` when the key is absent. Lets
884
+ * `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry` be augmented without
885
+ * touching core.
886
+ *
887
+ * @internal
888
+ */
889
+ type ExtractRegistryKey$1<T, K extends PropertyKey> = K extends keyof T ? T[K] : {};
890
+ /**
891
+ * How a plugin consolidates its generated code into files.
892
+ * - `'directory'` writes one file per operation or schema under `path`.
893
+ * - `'file'` writes everything into a single file.
894
+ */
895
+ type OutputMode = 'directory' | 'file';
896
+ /**
897
+ * Output configuration shared by every plugin. Each plugin extends this with
898
+ * its own keys via the `Kubb.PluginOptionsRegistry.output` interface merge.
899
+ */
900
+ type Output<_TOptions = unknown> = {
901
+ /**
902
+ * Directory where the plugin writes its generated code, resolved against the global
903
+ * `output.path` set on `defineConfig`. With `mode: 'file'`, this is the full output file
904
+ * path and must include the extension (e.g. `'types.ts'`, `'models.py'`).
905
+ */
906
+ path: string;
907
+ /**
908
+ * How generated code is consolidated into files.
909
+ * - `'directory'` writes one file per operation or schema under `path`.
910
+ * - `'file'` writes everything into a single file. The `path` must include the file extension.
911
+ *
912
+ * @default 'directory'
913
+ */
914
+ mode?: OutputMode;
915
+ /**
916
+ * Text prepended to every generated file. Useful for license headers,
917
+ * lint disables, or `@ts-nocheck` directives.
918
+ *
919
+ * A string is applied to every file (including barrel and aggregation re-export files).
920
+ * Pass a function to compute the banner from the file's `BannerMeta` document metadata
921
+ * plus per-file context (`isBarrel`, `isAggregation`, `filePath`, `baseName`), so you can
922
+ * skip the banner on specific files.
923
+ *
924
+ * @example Add a directive to source files but not re-export files
925
+ * `banner: (meta) => (meta.isBarrel || meta.isAggregation) ? '' : "'use server'"`
926
+ */
927
+ banner?: string | ((meta: BannerMeta) => string);
928
+ /**
929
+ * Text appended at the end of every generated file. Mirror of `banner`.
930
+ * Pass a function to compute the footer from the file's `BannerMeta`.
931
+ */
932
+ footer?: string | ((meta: BannerMeta) => string);
933
+ /**
934
+ * Allows the plugin to overwrite hand-written files at the same path.
935
+ * Defaults to `false` to protect manual edits.
936
+ *
937
+ * @default false
938
+ */
939
+ override?: boolean;
940
+ } & ExtractRegistryKey$1<Kubb.PluginOptionsRegistry, 'output'>;
941
+ /**
942
+ * Groups generated files into subdirectories based on an OpenAPI tag or path
943
+ * segment.
944
+ */
945
+ type Group = {
946
+ /**
947
+ * Property used to assign each operation to a group.
948
+ * - `'tag'` uses the first tag (`operation.getTags().at(0)?.name`).
949
+ * - `'path'` uses the first segment of the operation's URL.
950
+ */
951
+ type: 'tag' | 'path';
952
+ /**
953
+ * Returns the subdirectory name from the group key. Defaults to the
954
+ * camelCased tag for `tag` groups, or the first path segment for `path` groups.
955
+ */
956
+ name?: (context: {
957
+ group: string;
958
+ }) => string;
959
+ };
960
+ /**
961
+ * Couples `output.mode` with the plugin's `group` option at the type level.
962
+ * - `mode: 'file'` forbids `group` (a single file has nothing to group).
963
+ * - `mode: 'directory'` (or no mode) allows an optional `group` to organize
964
+ * files into per-group subdirectories.
965
+ *
966
+ * Intersect into a plugin's `Options` type instead of declaring `output` and
967
+ * `group` directly, since `mode` lives inside `output` while `group` is its sibling.
968
+ * The generic keeps a plugin's extended `Output` shape intact.
969
+ *
970
+ * @example
971
+ * ```ts
972
+ * export type Options = OutputOptions & {
973
+ * exclude?: Array<Exclude>
974
+ * }
975
+ * ```
976
+ */
977
+ type OutputOptions<TOutput extends Output = Output> = {
978
+ output?: TOutput & {
979
+ mode?: 'directory';
980
+ };
981
+ group?: Group;
982
+ } | {
983
+ output: TOutput & {
984
+ mode: 'file';
985
+ };
986
+ group?: never;
987
+ };
988
+ type ByTag = {
989
+ /**
990
+ * Filter by OpenAPI `tags` field. Matches one or more tags assigned to operations.
991
+ */
992
+ type: 'tag';
993
+ /**
994
+ * Tag name to match (case-sensitive). Can be a literal string or regex pattern.
995
+ */
996
+ pattern: string | RegExp;
997
+ };
998
+ type ByOperationId = {
999
+ /**
1000
+ * Filter by OpenAPI `operationId` field. Each operation (GET, POST, etc.) has a unique identifier.
1001
+ */
1002
+ type: 'operationId';
1003
+ /**
1004
+ * Operation ID to match (case-sensitive). Can be a literal string or regex pattern.
1005
+ */
1006
+ pattern: string | RegExp;
1007
+ };
1008
+ type ByPath = {
1009
+ /**
1010
+ * Filter by OpenAPI `path` (URL endpoint). Useful to group or filter by service segments like `/pets`, `/users`, etc.
1011
+ */
1012
+ type: 'path';
1013
+ /**
1014
+ * URL path to match (case-sensitive). Can be a literal string or regex pattern. Matches against the full path.
1015
+ */
1016
+ pattern: string | RegExp;
1017
+ };
1018
+ type ByMethod = {
1019
+ /**
1020
+ * Filter by HTTP method: `'get'`, `'post'`, `'put'`, `'delete'`, `'patch'`, `'head'`, `'options'`.
1021
+ */
1022
+ type: 'method';
1023
+ /**
1024
+ * HTTP method to match (case-insensitive when using string, or regex for dynamic matching).
1025
+ */
1026
+ pattern: HttpMethod | RegExp;
1027
+ };
1028
+ type BySchemaName = {
1029
+ /**
1030
+ * Filter by schema component name (TypeScript or JSON schema). Matches schemas in `#/components/schemas`.
1031
+ */
1032
+ type: 'schemaName';
1033
+ /**
1034
+ * Schema name to match (case-sensitive). Can be a literal string or regex pattern.
1035
+ */
1036
+ pattern: string | RegExp;
1037
+ };
1038
+ type ByContentType = {
1039
+ /**
1040
+ * Filter by response or request content type: `'application/json'`, `'application/xml'`, etc.
1041
+ */
1042
+ type: 'contentType';
1043
+ /**
1044
+ * Content type to match (case-sensitive). Can be a literal string or regex pattern.
1045
+ */
1046
+ pattern: string | RegExp;
1047
+ };
1048
+ /**
1049
+ * Filter that skips matching operations or schemas during generation, for example
1050
+ * deprecated endpoints or internal-only schemas.
1051
+ *
1052
+ * @example
1053
+ * ```ts
1054
+ * exclude: [
1055
+ * { type: 'tag', pattern: 'internal' },
1056
+ * { type: 'path', pattern: /^\/admin/ },
1057
+ * { type: 'operationId', pattern: /^deprecated_/ },
1058
+ * ]
1059
+ * ```
1060
+ */
1061
+ type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
1062
+ /**
1063
+ * Filter that restricts generation to operations or schemas matching at least
1064
+ * one entry. Useful for partial builds (one tag, one API version).
1065
+ *
1066
+ * @example
1067
+ * ```ts
1068
+ * include: [
1069
+ * { type: 'tag', pattern: 'public' },
1070
+ * { type: 'path', pattern: /^\/api\/v1/ },
1071
+ * ]
1072
+ * ```
1073
+ */
1074
+ type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
1075
+ /**
1076
+ * Filter paired with a partial options object. When the filter matches, the
1077
+ * options are merged on top of the plugin defaults for that operation only.
1078
+ * Useful for "this one tag goes to a different folder" rules.
1079
+ *
1080
+ * Entries are evaluated top to bottom. The first matching entry wins.
1081
+ *
1082
+ * @example
1083
+ * ```ts
1084
+ * override: [
1085
+ * {
1086
+ * type: 'tag',
1087
+ * pattern: 'admin',
1088
+ * options: { output: { path: './src/gen/admin' } },
1089
+ * },
1090
+ * {
1091
+ * type: 'operationId',
1092
+ * pattern: 'listPets',
1093
+ * options: { enumType: 'literal' },
1094
+ * },
1095
+ * ]
1096
+ * ```
1097
+ */
1098
+ type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
1099
+ options: Omit<Partial<TOptions>, 'override'>;
1100
+ };
1101
+ type PluginFactoryOptions<
1102
+ /**
1103
+ * Unique plugin name.
1104
+ */
1105
+ TName extends string = string,
1106
+ /**
1107
+ * User-facing plugin options.
1108
+ */
1109
+ TOptions extends object = object,
1110
+ /**
1111
+ * Plugin options after defaults are applied.
1112
+ */
1113
+ TResolvedOptions extends object = TOptions,
1114
+ /**
1115
+ * Resolver that encapsulates naming and path-resolution helpers.
1116
+ * Define with `defineResolver` and export alongside the plugin.
1117
+ */
1118
+ TResolver extends Resolver = Resolver> = {
1119
+ name: TName;
1120
+ options: TOptions;
1121
+ resolvedOptions: TResolvedOptions;
1122
+ resolver: TResolver;
1123
+ };
1124
+ /**
1125
+ * Context passed to a plugin's `kubb:plugin:setup` handler, where it registers generators and
1126
+ * sets its resolver, transformer, and options.
1127
+ */
1128
+ type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
1129
+ /**
1130
+ * Register a generator dynamically. Generators fire during the AST walk (schema/operation/operations)
1131
+ * just like generators declared statically on `createPlugin`.
1132
+ */
1133
+ addGenerator<TElement = unknown>(generator: Generator$1<TFactory, TElement>): void;
1134
+ /**
1135
+ * Set or override the resolver for this plugin.
1136
+ * The resolver controls file naming and path resolution.
1137
+ */
1138
+ setResolver(resolver: Partial<TFactory['resolver']>): void;
1139
+ /**
1140
+ * Set the AST transformer to pre-process nodes before they reach generators.
1141
+ */
1142
+ setTransformer(visitor: Visitor): void;
1143
+ /**
1144
+ * Set resolved options merged into the normalized plugin's `options`.
1145
+ * Call this in `kubb:plugin:setup` to provide options generators need.
1146
+ */
1147
+ setOptions(options: TFactory['resolvedOptions']): void;
1148
+ /**
1149
+ * Inject a raw file into the build output, bypassing the generation pipeline.
1150
+ */
1151
+ injectFile(userFileNode: UserFileNode): void;
1152
+ /**
1153
+ * Merge a partial config update into the current build configuration.
1154
+ */
1155
+ updateConfig(config: Partial<Config>): void;
1156
+ /**
1157
+ * The resolved build configuration at setup time.
1158
+ */
1159
+ config: Config;
1160
+ /**
1161
+ * The plugin's user-provided options.
1162
+ */
1163
+ options: TFactory['options'];
1164
+ };
1165
+ /**
1166
+ * A plugin object produced by `definePlugin`. Its lifecycle handlers live under a single
1167
+ * `hooks` property rather than flat methods.
1168
+ */
1169
+ type Plugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
1170
+ /**
1171
+ * Unique name for the plugin, following the same naming convention as `createPlugin`.
1172
+ */
1173
+ name: string;
1174
+ /**
1175
+ * Plugins that must be registered before this plugin executes.
1176
+ * An error is thrown at startup when any listed dependency is missing.
1177
+ */
1178
+ dependencies?: Array<string>;
1179
+ /**
1180
+ * Controls the execution order of this plugin relative to others.
1181
+ *
1182
+ * - `'pre'` runs before all normal plugins.
1183
+ * - `'post'` runs after all normal plugins.
1184
+ * - `undefined` (default), runs in declaration order among normal plugins.
1185
+ *
1186
+ * Dependency constraints always take precedence over `enforce`.
1187
+ */
1188
+ enforce?: 'pre' | 'post';
1189
+ /**
1190
+ * The options passed by the user when calling the plugin factory.
1191
+ */
1192
+ options?: TFactory['options'];
1193
+ /**
1194
+ * Lifecycle event handlers for this plugin.
1195
+ * Any event from the global `KubbHooks` map can be subscribed to here.
1196
+ */
1197
+ hooks: { [K in keyof KubbHooks as K extends 'kubb:plugin:setup' ? never : K]?: (...args: KubbHooks[K]) => void | Promise<void> } & {
1198
+ 'kubb:plugin:setup'?(ctx: KubbPluginSetupContext<TFactory>): void | Promise<void>;
1199
+ };
1200
+ };
1201
+ /**
1202
+ * Normalized plugin after setup, with runtime fields populated. Internal only. Plugins use the
1203
+ * public `Plugin` type.
1204
+ *
1205
+ * @internal
1206
+ */
1207
+ type NormalizedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & {
1208
+ options: TOptions['resolvedOptions'] & {
1209
+ output: Output;
1210
+ include?: Array<Include>;
1211
+ exclude: Array<Exclude$1>;
1212
+ override: Array<Override<TOptions['resolvedOptions']>>;
1213
+ };
1214
+ resolver: TOptions['resolver'];
1215
+ transformer?: Visitor;
1216
+ generators?: Array<Generator$1>;
1217
+ apply?: (config: Config) => boolean;
1218
+ version?: string;
1219
+ };
1220
+ type KubbPluginStartContext = {
1221
+ plugin: NormalizedPlugin;
1222
+ };
1223
+ type KubbPluginEndContext = {
1224
+ plugin: NormalizedPlugin;
1225
+ duration: number;
1226
+ success: boolean;
1227
+ error?: Error;
1228
+ config: Config;
1229
+ /**
1230
+ * Returns all files currently in the file manager (lazy snapshot).
1231
+ * Includes files added by plugins that have already run.
1232
+ */
1233
+ readonly files: ReadonlyArray<FileNode>;
1234
+ /**
1235
+ * Upsert one or more files into the file manager.
1236
+ */
1237
+ upsertFile: (...files: Array<FileNode>) => void;
1238
+ };
1239
+ /**
1240
+ * Wraps a plugin factory and returns a function that accepts user options and
1241
+ * yields a typed `Plugin`. Lifecycle handlers go inside a single `hooks` object.
1242
+ *
1243
+ * Pass a `PluginFactoryOptions` type parameter to get a typed `ctx` inside
1244
+ * `kubb:plugin:setup`. Plugin names should follow the `plugin-<feature>`
1245
+ * convention (`plugin-react-query`, `plugin-zod`, ...).
1246
+ *
1247
+ * @example
1248
+ * ```ts
1249
+ * import { definePlugin } from '@kubb/core'
1250
+ *
1251
+ * export const pluginTs = definePlugin((options: { prefix?: string } = {}) => ({
1252
+ * name: 'plugin-ts',
1253
+ * hooks: {
1254
+ * 'kubb:plugin:setup'(ctx) {
1255
+ * ctx.setResolver(resolverTs)
1256
+ * },
1257
+ * },
1258
+ * }))
1259
+ * ```
1260
+ */
1261
+ declare function definePlugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(factory: (options: TFactory['options']) => Plugin<TFactory>): (options?: TFactory['options']) => Plugin<TFactory>;
1262
+ //#endregion
1263
+ //#region src/FileManager.d.ts
1264
+ /**
1265
+ * Hooks fired by a `FileManager`.
1266
+ *
1267
+ * - `upsert` fires once per resolved file added through `add` or `upsert`.
1268
+ */
1269
+ type FileManagerHooks = {
1270
+ upsert: [file: FileNode];
1271
+ };
1272
+ /**
1273
+ * In-memory file store for generated files. Files sharing a `path` are merged
1274
+ * (sources/imports/exports concatenated). The `files` getter is sorted by
1275
+ * path length (barrel `index.ts` last within a bucket).
1276
+ *
1277
+ * @example
1278
+ * ```ts
1279
+ * const manager = new FileManager()
1280
+ * manager.upsert(myFile)
1281
+ * manager.files // sorted view
1282
+ * ```
1283
+ */
1284
+ declare class FileManager {
1285
+ #private;
1286
+ /**
1287
+ * Subscribe to file-store changes. Listeners on `upsert` see each resolved file as it lands
1288
+ * through `add` or `upsert`.
1289
+ */
1290
+ readonly hooks: AsyncEventEmitter<FileManagerHooks>;
1291
+ add(...files: Array<FileNode>): Array<FileNode>;
1292
+ upsert(...files: Array<FileNode>): Array<FileNode>;
1293
+ getByPath(path: string): FileNode | null;
1294
+ deleteByPath(path: string): void;
1295
+ clear(): void;
1296
+ /**
1297
+ * Releases all stored files and clears every `hooks` listener. Called by the core after
1298
+ * `kubb:build:end`.
1299
+ */
1300
+ dispose(): void;
1301
+ [Symbol.dispose](): void;
1302
+ /**
1303
+ * All stored files in stable sort order (shortest path first, barrel files
1304
+ * last within a length bucket). Returns a cached view, do not mutate.
1305
+ */
1306
+ get files(): Array<FileNode>;
1307
+ }
1308
+ //#endregion
1309
+ //#region src/KubbDriver.d.ts
1310
+ type Options = {
1311
+ hooks: AsyncEventEmitter<KubbHooks>;
1312
+ };
1313
+ type RequirePluginContext = {
1314
+ /**
1315
+ * Name of the plugin that declared the dependency, included in the error so users can
1316
+ * trace which plugin needs the missing one.
1317
+ */
1318
+ requiredBy?: string;
1319
+ };
1320
+ declare class KubbDriver {
1321
+ #private;
1322
+ readonly config: Config;
1323
+ readonly options: Options;
1324
+ /**
1325
+ * The streaming `InputNode<true>` produced by the adapter. Set after adapter setup.
1326
+ * Parse-only adapters are wrapped automatically.
1327
+ */
1328
+ inputNode: InputNode<true> | null;
1329
+ adapter: Adapter | null;
1330
+ /**
1331
+ * Central file store for all generated files.
1332
+ * Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to
1333
+ * add files. This property gives direct read/write access when needed.
1334
+ */
1335
+ readonly fileManager: FileManager;
1336
+ readonly plugins: Map<string, NormalizedPlugin>;
1337
+ constructor(config: Config, options: Options);
1338
+ setup(): Promise<void>;
1339
+ get hooks(): AsyncEventEmitter<KubbHooks>;
1340
+ /**
1341
+ * Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners
1342
+ * can configure generators, resolvers, transformers and renderers before `buildStart` runs.
1343
+ *
1344
+ * Call this once from `safeBuild` before the plugin execution loop begins.
1345
+ */
1346
+ emitSetupHooks(): Promise<void>;
1347
+ /**
1348
+ * Registers a generator for the given plugin on the shared event emitter.
1349
+ *
1350
+ * The generator's `schema`, `operation`, and `operations` methods are registered as
1351
+ * listeners on `kubb:generate:schema`, `kubb:generate:operation`, and `kubb:generate:operations`
1352
+ * respectively. Each listener is scoped to the owning plugin via a `ctx.plugin.name` check
1353
+ * so that generators from different plugins do not cross-fire.
1354
+ *
1355
+ * The renderer comes from `generator.renderer`. Set `generator.renderer = null` (or leave it
1356
+ * unset) to opt out of rendering.
1357
+ *
1358
+ * Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.
1359
+ */
1360
+ registerGenerator(pluginName: string, generator: Generator$1): void;
1361
+ /**
1362
+ * Returns `true` when at least one generator was registered for the given plugin
1363
+ * via `addGenerator()` in `kubb:plugin:setup` (event-based path).
1364
+ *
1365
+ * Used by the build loop to decide whether to walk the AST and emit generator events
1366
+ * for a plugin that has no static `plugin.generators`.
1367
+ */
1368
+ hasEventGenerators(pluginName: string): boolean;
1369
+ /**
1370
+ * Runs the full plugin pipeline. Returns the diagnostics collected so far even
1371
+ * when an outer hook throws, since the orchestrator preserves partial state by capturing
1372
+ * the failure as a {@link Diagnostic} instead of propagating. Each plugin also
1373
+ * contributes a `timing` diagnostic for the run summary.
1374
+ */
1375
+ run({
1376
+ storage
1377
+ }: {
1378
+ storage: Storage;
1379
+ }): Promise<{
1380
+ diagnostics: Array<Diagnostic>;
1381
+ }>;
1382
+ /**
1383
+ * Stores whatever a generator method or `kubb:generate:*` hook returned.
1384
+ *
1385
+ * - An `Array<FileNode>` goes straight into `fileManager` via `upsert`.
1386
+ * - A renderer element runs through `renderer` (the renderer factory, e.g. JSX) and the
1387
+ * produced files go to `fileManager.upsert`.
1388
+ * - A falsy result is treated as a no-op. The generator wrote files itself via
1389
+ * `ctx.upsertFile`.
1390
+ *
1391
+ * Pass `renderer` when the result may be a renderer element. Generators that only return
1392
+ * `Array<FileNode>` do not need one.
1393
+ */
1394
+ dispatch<TElement = unknown>({
1395
+ result,
1396
+ renderer
1397
+ }: {
1398
+ result: TElement | Array<FileNode> | undefined | null;
1399
+ renderer?: RendererFactory<TElement> | null;
1400
+ }): Promise<void>;
1401
+ /**
1402
+ * Removes every listener the driver added. Listeners attached directly to `hooks` from outside
1403
+ * the driver survive. Called at the end of a build to prevent leaks across repeated builds.
1404
+ *
1405
+ * @internal
1406
+ */
1407
+ dispose(): void;
1408
+ [Symbol.dispose](): void;
1409
+ /**
1410
+ * Merges `partial` with the plugin's default resolver and stores the result.
1411
+ * Also mirrors it onto `plugin.resolver` so callers using `getPlugin(name).resolver`
1412
+ * get the up-to-date resolver without going through `getResolver()`.
1413
+ */
1414
+ setPluginResolver(pluginName: string, partial: Partial<Resolver>): void;
1415
+ /**
1416
+ * Returns the resolver for the given plugin.
1417
+ *
1418
+ * Resolution order: dynamic resolver set via `setPluginResolver` → static resolver on the
1419
+ * plugin → lazily created default resolver (identity name, no path transforms).
1420
+ */
1421
+ getResolver<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Kubb.PluginRegistry[TName]['resolver'];
1422
+ getResolver<TResolver extends Resolver = Resolver>(pluginName: string): TResolver;
1423
+ getContext<TOptions extends PluginFactoryOptions>(plugin: NormalizedPlugin<TOptions>): Omit<GeneratorContext<TOptions>, 'options'>;
1424
+ getPlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
1425
+ getPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions> | undefined;
1426
+ /**
1427
+ * Like `getPlugin` but throws a descriptive error when the plugin is not found.
1428
+ */
1429
+ requirePlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName, context?: RequirePluginContext): Plugin<Kubb.PluginRegistry[TName]>;
1430
+ requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string, context?: RequirePluginContext): Plugin<TOptions>;
1431
+ }
1432
+ //#endregion
1433
+ //#region src/defineGenerator.d.ts
1434
+ /**
1435
+ * Context object passed to generator `schema`, `operation`, and `operations` methods.
1436
+ *
1437
+ * The adapter is always defined (guaranteed by `runPluginAstHooks`) so no runtime checks
1438
+ * are needed. `ctx.options` carries resolved per-node options after exclude/include/override
1439
+ * filtering for individual schema/operation calls, or plugin-level options for operations.
1440
+ */
1441
+ type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
1442
+ /**
1443
+ * The resolved Kubb config for this build, including `root`, `input`, `output`, and the
1444
+ * full plugin list.
1445
+ */
1446
+ config: Config;
1447
+ /**
1448
+ * Absolute path to the current plugin's output directory.
1449
+ */
1450
+ root: string;
1451
+ /**
1452
+ * The driver running this build. Most generators never need it. Prefer the scoped helpers
1453
+ * on this context (`getPlugin`, `getResolver`, `upsertFile`) over reaching into the driver.
1454
+ */
1455
+ driver: KubbDriver;
1456
+ /**
1457
+ * Get a plugin by name, typed via `Kubb.PluginRegistry` when registered.
1458
+ */
1459
+ getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
1460
+ getPlugin(name: string): Plugin | undefined;
1461
+ /**
1462
+ * Get a plugin by name, throws an error if not found.
1463
+ */
1464
+ requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>;
1465
+ requirePlugin(name: string): Plugin;
1466
+ /**
1467
+ * Get a resolver by plugin name, typed via `Kubb.PluginRegistry` when registered.
1468
+ */
1469
+ getResolver<TName extends keyof Kubb.PluginRegistry>(name: TName): Kubb.PluginRegistry[TName]['resolver'];
1470
+ getResolver(name: string): Resolver;
1471
+ /**
1472
+ * Add files only if they don't exist.
1473
+ */
1474
+ addFile: (...file: Array<FileNode>) => Promise<void>;
1475
+ /**
1476
+ * Merge sources into the same output file.
1477
+ */
1478
+ upsertFile: (...file: Array<FileNode>) => Promise<void>;
1479
+ /**
1480
+ * The build's event bus. Emit or listen to any `KubbHooks` event, for example to react to
1481
+ * `kubb:build:end` from inside a generator.
1482
+ */
1483
+ hooks: AsyncEventEmitter<KubbHooks>;
1484
+ /**
1485
+ * The current plugin instance.
1486
+ */
1487
+ plugin: Plugin<TOptions>;
1488
+ /**
1489
+ * The current plugin's resolver. It decides what every generated symbol and file path is
1490
+ * called. Kubb picks a `setResolver` registration first, then the plugin's static
1491
+ * `resolver`, then the built-in default.
1492
+ *
1493
+ * @example Resolve a type name
1494
+ * `ctx.resolver.default('pet', 'type') // 'Pet'`
1495
+ *
1496
+ * @example Resolve an output file
1497
+ * `ctx.resolver.resolveFile({ name: 'pet', extname: '.ts' }, { root, output })`
1498
+ */
1499
+ resolver: TOptions['resolver'];
1500
+ /**
1501
+ * The AST visitor this plugin registered through `setTransformer` during
1502
+ * `kubb:plugin:setup`, or `undefined` when it never registered one. The driver already
1503
+ * applies the visitor to every schema and operation node before a generator sees it, so
1504
+ * read it here only to inspect or re-run the transformation.
1505
+ */
1506
+ transformer: Visitor | undefined;
1507
+ /**
1508
+ * Report a warning. Collected as a `warning` diagnostic attributed to the current
1509
+ * plugin. It surfaces in the run summary but does not fail the build. For a structured
1510
+ * diagnostic with a code and source location, use `Diagnostics.report` or throw a
1511
+ * `Diagnostics.Error` directly.
1512
+ */
1513
+ warn: (message: string) => void;
1514
+ /**
1515
+ * Report an error. Collected as an `error` diagnostic attributed to the current
1516
+ * plugin, which fails the build.
1517
+ */
1518
+ error: (error: string | Error) => void;
1519
+ /**
1520
+ * Report an informational message. Collected as an `info` diagnostic attributed to
1521
+ * the current plugin.
1522
+ */
1523
+ info: (message: string) => void;
1524
+ /**
1525
+ * The configured adapter instance.
1526
+ */
1527
+ adapter: Adapter;
1528
+ /**
1529
+ * Document metadata from the adapter: title, version, base URL, and pre-computed
1530
+ * schema index fields (`circularNames`, `enumNames`).
1531
+ */
1532
+ meta: InputMeta;
1533
+ /**
1534
+ * Resolved options after exclude/include/override filtering.
1535
+ */
1536
+ options: TOptions['resolvedOptions'];
1537
+ };
1538
+ /**
1539
+ * Declares a named generator unit that walks the AST and emits files.
1540
+ *
1541
+ * Each method (`schema`, `operation`, `operations`) is called for the matching node type.
1542
+ * JSX-based generators require a `renderer` factory. Return `Array<FileNode>` directly, or call
1543
+ * `ctx.upsertFile()` manually and return `null` to bypass rendering.
1544
+ *
1545
+ * @note Generators are consumed by plugins and registered via `ctx.addGenerator()` in `kubb:plugin:setup`.
1546
+ *
1547
+ * @example
1548
+ * ```ts
1549
+ * import { defineGenerator } from '@kubb/core'
1550
+ * import { jsxRenderer } from '@kubb/renderer-jsx'
1551
+ *
1552
+ * export const typeGenerator = defineGenerator({
1553
+ * name: 'typescript',
1554
+ * renderer: jsxRenderer,
1555
+ * schema(node, ctx) {
1556
+ * const { adapter, resolver, root, options } = ctx
1557
+ * return <File ...><Type node={node} resolver={resolver} /></File>
1558
+ * },
1559
+ * })
1560
+ * ```
1561
+ */
1562
+ type Generator$1<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown> = {
1563
+ /**
1564
+ * Used in diagnostic messages and debug output.
1565
+ */
1566
+ name: string;
1567
+ /**
1568
+ * Optional renderer factory that produces a {@link Renderer} for each render cycle.
1569
+ *
1570
+ * Generators that return renderer elements (e.g. JSX via `@kubb/renderer-jsx`) must set this
1571
+ * to the matching renderer factory (e.g. `jsxRenderer` from `@kubb/renderer-jsx`).
1572
+ *
1573
+ * Generators that only return `Array<FileNode>` or `void` do not need to set this.
1574
+ *
1575
+ * Leave it unset or set `renderer: null` to opt out of rendering.
1576
+ *
1577
+ * @example
1578
+ * ```ts
1579
+ * import { jsxRenderer } from '@kubb/renderer-jsx'
1580
+ * export const myGenerator = defineGenerator<PluginTs>({
1581
+ * renderer: jsxRenderer,
1582
+ * schema(node, ctx) { return <File ...>...</File> },
1583
+ * })
1584
+ * ```
1585
+ */
1586
+ renderer?: RendererFactory<TElement> | null;
1587
+ /**
1588
+ * Called for each schema node in the AST walk.
1589
+ * `ctx` carries the plugin context with `adapter` and `meta` (document metadata),
1590
+ * plus `ctx.options` with the per-node resolved options (after exclude/include/override).
1591
+ */
1592
+ schema?: (node: SchemaNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | undefined | null>;
1593
+ /**
1594
+ * Called for each operation node in the AST walk.
1595
+ * `ctx` carries the plugin context with `adapter` and `meta` (document metadata),
1596
+ * plus `ctx.options` with the per-node resolved options (after exclude/include/override).
1597
+ */
1598
+ operation?: (node: OperationNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | undefined | null>;
1599
+ /**
1600
+ * Called once after all operations have been walked.
1601
+ * `ctx` carries the plugin context with `adapter` and `meta` (document metadata),
1602
+ * plus `ctx.options` with the plugin-level options for the batch call.
1603
+ */
1604
+ operations?: (nodes: Array<OperationNode>, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | undefined | null>;
1605
+ };
1606
+ /**
1607
+ * Defines a generator: a unit of work that runs during the plugin's AST walk
1608
+ * and produces files. Plugins register generators via `ctx.addGenerator()`
1609
+ * inside `kubb:plugin:setup`.
1610
+ *
1611
+ * The returned object is the input as-is, but with `this` types preserved so
1612
+ * `schema`/`operation`/`operations` methods are correctly typed against the
1613
+ * plugin's `PluginFactoryOptions`. Renderer elements and `FileNode[]` returns
1614
+ * are both handled by the runtime, so pick whichever style fits.
1615
+ *
1616
+ * @example JSX-based schema generator
1617
+ * ```tsx
1618
+ * import { defineGenerator } from '@kubb/core'
1619
+ * import { jsxRenderer } from '@kubb/renderer-jsx'
1620
+ *
1621
+ * export const typeGenerator = defineGenerator({
1622
+ * name: 'typescript',
1623
+ * renderer: jsxRenderer,
1624
+ * schema(node, ctx) {
1625
+ * return (
1626
+ * <File path={`${ctx.root}/${node.name}.ts`}>
1627
+ * <Type node={node} resolver={ctx.resolver} />
1628
+ * </File>
1629
+ * )
1630
+ * },
1631
+ * })
1632
+ * ```
1633
+ */
1634
+ declare function defineGenerator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown>(generator: Generator$1<TOptions, TElement>): Generator$1<TOptions, TElement>;
1635
+ //#endregion
1636
+ //#region src/defineParser.d.ts
1637
+ type PrintOptions = {
1638
+ extname?: FileNode['extname'];
1639
+ };
1640
+ /**
1641
+ * Converts a resolved {@link FileNode} into the final source string that gets
1642
+ * written to disk. Kubb ships with TypeScript and TSX parsers. Add your own
1643
+ * for new file types (JSON, Markdown, ...).
1644
+ */
1645
+ type Parser<TMeta extends object = object, TNode = unknown> = {
1646
+ /**
1647
+ * Display name used in diagnostics and the parser registry.
1648
+ */
1649
+ name: string;
1650
+ /**
1651
+ * File extensions this parser handles. Set to `undefined` to define a
1652
+ * catch-all fallback used when no other parser claims the extension.
1653
+ *
1654
+ * @example
1655
+ * `['.ts', '.js']`
1656
+ */
1657
+ extNames: Array<FileNode['extname']> | undefined;
1658
+ /**
1659
+ * Serialize the file's AST into source code.
1660
+ */
1661
+ parse(file: FileNode<TMeta>, options?: PrintOptions): string;
1662
+ /**
1663
+ * Render compiler AST nodes for this parser's language into source text.
1664
+ * Plugins call this to format the nodes they assemble before handing them
1665
+ * back to the parser as `FileNode.sources`.
1666
+ */
1667
+ print(...nodes: Array<TNode>): string;
1668
+ };
1669
+ /**
1670
+ * Defines a parser with type-safe `this`. Used to register handlers for new
1671
+ * file extensions or to plug a non-TypeScript output into the build.
1672
+ *
1673
+ * @example
1674
+ * ```ts
1675
+ * import { defineParser } from '@kubb/core'
1676
+ * import { extractStringsFromNodes } from '@kubb/ast/utils'
1677
+ *
1678
+ * export const jsonParser = defineParser({
1679
+ * name: 'json',
1680
+ * extNames: ['.json'],
1681
+ * parse(file) {
1682
+ * return file.sources
1683
+ * .map((source) => extractStringsFromNodes(source.nodes ?? []))
1684
+ * .join('\n')
1685
+ * },
1686
+ * print(...nodes) {
1687
+ * return nodes.map(String).join('\n')
1688
+ * },
1689
+ * })
1690
+ * ```
1691
+ */
1692
+ declare function defineParser<T extends Parser>(parser: T): T;
1693
+ //#endregion
1694
+ //#region src/createKubb.d.ts
1695
+ type CreateKubbOptions = {
1696
+ hooks?: AsyncEventEmitter<KubbHooks>;
1697
+ };
1698
+ /**
1699
+ * Kubb code-generation instance bound to a single config entry. Resolves the user
1700
+ * config in the constructor, so `config` is available right away, and shares `hooks`,
1701
+ * `storage`, and `driver` across the `setup → build` lifecycle.
1702
+ *
1703
+ * `createKubb` takes a plain, serializable config object (the shape `defineConfig`
1704
+ * produces), not a fluent builder. Config stays plain data so it can be cache
1705
+ * fingerprinted and validated against the shipped JSON schema.
1706
+ *
1707
+ * Attach event listeners to `.hooks` before calling `setup()` or `build()`.
1708
+ *
1709
+ * @example
1710
+ * ```ts
1711
+ * const kubb = createKubb(userConfig)
1712
+ * kubb.hooks.on('kubb:plugin:end', ({ plugin, duration }) => console.log(plugin.name, duration))
1713
+ * const { files, diagnostics } = await kubb.safeBuild()
1714
+ * ```
1715
+ */
1716
+ declare class Kubb$1 {
1717
+ #private;
1718
+ readonly hooks: AsyncEventEmitter<KubbHooks>;
1719
+ readonly config: Config;
1720
+ constructor(userConfig: UserConfig, options?: CreateKubbOptions);
1721
+ get storage(): Storage;
1722
+ get driver(): KubbDriver;
1723
+ /**
1724
+ * Initializes the driver and storage. `build()` calls this automatically.
1725
+ */
1726
+ setup(): Promise<void>;
1727
+ /**
1728
+ * Runs the full pipeline and throws on any plugin error.
1729
+ * Automatically calls `setup()` if needed.
1730
+ */
1731
+ build(): Promise<BuildOutput>;
1732
+ /**
1733
+ * Runs the full pipeline and captures errors in `BuildOutput` instead of throwing.
1734
+ * Automatically calls `setup()` if needed. This is the canonical call: it never throws on
1735
+ * plugin errors, so callers stay in control of how failures surface.
1736
+ */
1737
+ safeBuild(): Promise<BuildOutput>;
1738
+ dispose(): void;
1739
+ [Symbol.dispose](): void;
1740
+ }
1741
+ /**
1742
+ * Constructs a {@link Kubb} build orchestrator from a user config. Equivalent
1743
+ * to `new Kubb(userConfig, options)` and the canonical public entry point.
1744
+ *
1745
+ * @example
1746
+ * ```ts
1747
+ * import { createKubb } from '@kubb/core'
1748
+ * import { adapterOas } from '@kubb/adapter-oas'
1749
+ * import { pluginTs } from '@kubb/plugin-ts'
1750
+ *
1751
+ * const kubb = createKubb({
1752
+ * input: { path: './petStore.yaml' },
1753
+ * output: { path: './src/gen' },
1754
+ * adapter: adapterOas(),
1755
+ * plugins: [pluginTs()],
1756
+ * })
1757
+ *
1758
+ * await kubb.build()
1759
+ * ```
1760
+ */
1761
+ declare function createKubb(userConfig: UserConfig, options?: CreateKubbOptions): Kubb$1;
1762
+ //#endregion
1763
+ //#region src/FileProcessor.d.ts
1764
+ /**
1765
+ * Hooks fired by a `FileProcessor`.
1766
+ *
1767
+ * - `start` opens a batch, from `run` or a queue flush.
1768
+ * - `update` fires once per file as it is converted.
1769
+ * - `end` closes a batch.
1770
+ * - `enqueue` fires for every `enqueue` call.
1771
+ * - `drain` fires when `drain()` empties the queue with no in-flight batch left.
1772
+ */
1773
+ type FileProcessorHooks = {
1774
+ start: [files: Array<FileNode>];
1775
+ update: [params: {
1776
+ file: FileNode;
1777
+ source?: string;
1778
+ processed: number;
1779
+ total: number;
1780
+ percentage: number;
1781
+ }];
1782
+ end: [files: Array<FileNode>];
1783
+ enqueue: [file: FileNode];
1784
+ drain: [];
1785
+ };
1786
+ /**
1787
+ * Per-file progress record yielded by `stream` and surfaced through the `update` event.
1788
+ */
1789
+ type ParsedFile = {
1790
+ file: FileNode;
1791
+ source: string;
1792
+ processed: number;
1793
+ total: number;
1794
+ percentage: number;
1795
+ };
1796
+ //#endregion
1797
+ //#region src/types.d.ts
1798
+ /**
1799
+ * Extracts a type from a registry, falling back to `{}` when the key doesn't exist.
1800
+ * Lets plugins augment `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry`
1801
+ * without changing core.
1802
+ *
1803
+ * @internal
1804
+ */
1805
+ type ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {};
1806
+ /**
1807
+ * Path to an input file to generate from, absolute or relative to the config file. The adapter
1808
+ * parses it (e.g. an OpenAPI YAML or JSON spec) into the universal AST.
1809
+ */
1810
+ type InputPath = {
1811
+ /**
1812
+ * Path to your Swagger/OpenAPI file, absolute or relative to the config file location.
1813
+ *
1814
+ * @example
1815
+ * ```ts
1816
+ * { path: './petstore.yaml' }
1817
+ * { path: '/absolute/path/to/openapi.json' }
1818
+ * ```
1819
+ */
1820
+ path: string;
1821
+ };
1822
+ /**
1823
+ * Inline spec to generate from, passed directly instead of read from a file. A string
1824
+ * (YAML/JSON) or a parsed object.
1825
+ */
1826
+ type InputData = {
1827
+ /**
1828
+ * Swagger/OpenAPI data as a string (YAML/JSON) or a parsed object.
1829
+ *
1830
+ * @example
1831
+ * ```ts
1832
+ * { data: fs.readFileSync('./openapi.yaml', 'utf8') }
1833
+ * { data: { openapi: '3.1.0', info: { ... } } }
1834
+ * ```
1835
+ */
1836
+ data: string | unknown;
1837
+ };
1838
+ type Input = InputPath | InputData;
1839
+ /**
1840
+ * Resolved build configuration for a Kubb run: what to generate from (adapter, input), where to
1841
+ * write it (output), how (plugins), and the runtime pieces (parsers, storage). See
1842
+ * `UserConfig` for the relaxed form with defaults applied.
1843
+ *
1844
+ * @private
1845
+ */
1846
+ type Config<TInput = Input> = {
1847
+ /**
1848
+ * Display name for this configuration in CLI output and logs.
1849
+ * Useful when running multiple builds with `defineConfig` arrays.
1850
+ *
1851
+ * @example
1852
+ * ```ts
1853
+ * name: 'api-client'
1854
+ * ```
1855
+ */
1856
+ name?: string;
1857
+ /**
1858
+ * Project root directory, absolute or relative to the config file. Already
1859
+ * resolved on the `Config` instance (see `UserConfig` for the optional
1860
+ * form that defaults to `process.cwd()`).
1861
+ */
1862
+ root: string;
1863
+ /**
1864
+ * Parsers that convert generated files into strings. Each parser handles a
1865
+ * set of file extensions, and a fallback parser handles anything else.
1866
+ *
1867
+ * Already resolved on the `Config` instance (see `UserConfig` for the
1868
+ * optional form that defaults to `[parserTs, parserTsx, parserMd]`).
1869
+ *
1870
+ * @example
1871
+ * ```ts
1872
+ * import { defineConfig } from 'kubb'
1873
+ * import { parserTs, parserTsx } from '@kubb/parser-ts'
1874
+ *
1875
+ * export default defineConfig({
1876
+ * parsers: [parserTs, parserTsx],
1877
+ * })
1878
+ * ```
1879
+ */
1880
+ parsers: Array<Parser>;
1881
+ /**
1882
+ * Adapter that parses input files into the universal AST representation.
1883
+ * Use `@kubb/adapter-oas` for OpenAPI/Swagger or `@kubb/adapter-asyncapi` for other formats.
1884
+ *
1885
+ * When omitted, Kubb runs in plugin-only mode: `kubb:plugin:setup` fires and files
1886
+ * injected via `injectFile` are written, but no AST walk occurs and generator hooks
1887
+ * (`kubb:generate:schema`, `kubb:generate:operation`) are never emitted.
1888
+ *
1889
+ * @example
1890
+ * ```ts
1891
+ * import { adapterOas } from '@kubb/adapter-oas'
1892
+ * export default defineConfig({
1893
+ * adapter: adapterOas(),
1894
+ * input: { path: './petstore.yaml' },
1895
+ * })
1896
+ * ```
1897
+ */
1898
+ adapter?: Adapter;
1899
+ /**
1900
+ * Source file or data to generate code from.
1901
+ * Use `input.path` for a file path or `input.data` for inline data.
1902
+ * Required when an adapter is configured. Omit it when running in plugin-only mode.
1903
+ */
1904
+ input?: TInput;
1905
+ output: {
1906
+ /**
1907
+ * Output directory for generated files, absolute or relative to `root`. Plugins can nest
1908
+ * subdirectories under it by grouping strategy (tag, path).
1909
+ *
1910
+ * @example
1911
+ * ```ts
1912
+ * output: {
1913
+ * path: './src/gen', // generates ./src/gen/api.ts, ./src/gen/types.ts, etc.
1914
+ * }
1915
+ * ```
1916
+ */
1917
+ path: string;
1918
+ /**
1919
+ * Remove every file in the output directory before the build, so stale output isn't mixed
1920
+ * with new files. Leave `false` to preserve manual edits in the output directory.
1921
+ *
1922
+ * @example
1923
+ * ```ts
1924
+ * clean: true // wipes ./src/gen/* before generating
1925
+ * ```
1926
+ */
1927
+ clean?: boolean;
1928
+ /**
1929
+ * Format the generated files after generation. `'auto'` runs the first formatter it finds
1930
+ * (oxfmt, biome, or prettier), a named tool forces that one, and `false` skips formatting.
1931
+ *
1932
+ * @example
1933
+ * ```ts
1934
+ * format: 'auto' // auto-detect prettier, biome, or oxfmt
1935
+ * format: 'prettier' // force prettier
1936
+ * format: false // skip formatting
1937
+ * ```
1938
+ */
1939
+ format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false;
1940
+ /**
1941
+ * Lint the generated files after generation. `'auto'` runs the first linter it finds
1942
+ * (oxlint, biome, or eslint), a named tool forces that one, and `false` skips linting.
1943
+ *
1944
+ * @example
1945
+ * ```ts
1946
+ * lint: 'auto' // auto-detect oxlint, biome, or eslint
1947
+ * lint: 'eslint' // force eslint
1948
+ * lint: false // skip linting
1949
+ * ```
1950
+ */
1951
+ lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false;
1952
+ /**
1953
+ * Rewrite import extensions in generated files, e.g. emit `.js` imports from `.ts` sources for
1954
+ * ESM dual packages. Keys are the source extension, values the output, and `''` drops it.
1955
+ *
1956
+ * @default { '.ts': '.ts' }
1957
+ * @example
1958
+ * ```ts
1959
+ * extension: { '.ts': '.js' } // generates import './api.js' instead of './api.ts'
1960
+ * extension: { '.ts': '', '.tsx': '.jsx' }
1961
+ * ```
1962
+ */
1963
+ extension?: Record<FileNode['extname'], FileNode['extname'] | ''>;
1964
+ /**
1965
+ * Banner prepended to every generated file. `'simple'` is the basic Kubb notice, `'full'` adds
1966
+ * source, title, description, and API version, and `false` omits it.
1967
+ *
1968
+ * @default 'simple'
1969
+ * @example
1970
+ * ```ts
1971
+ * defaultBanner: 'simple' // "This file was autogenerated by Kubb"
1972
+ * defaultBanner: 'full' // adds source, title, description, API version
1973
+ * defaultBanner: false // no banner
1974
+ * ```
1975
+ */
1976
+ defaultBanner?: 'simple' | 'full' | false;
1977
+ /**
1978
+ * Overwrite existing files when `true`, skip files that already exist when `false`. Individual
1979
+ * plugins can override it. Keep `false` to avoid clobbering local edits in the output folder.
1980
+ *
1981
+ * @example
1982
+ * ```ts
1983
+ * override: true // regenerate everything, even existing files
1984
+ * override: false // skip files that already exist
1985
+ * ```
1986
+ */
1987
+ override?: boolean;
1988
+ } & ExtractRegistryKey<Kubb.ConfigOptionsRegistry, 'output'>;
1989
+ /**
1990
+ * Where generated files are persisted. Defaults to `fsStorage()` (disk). Pass `memoryStorage()`
1991
+ * to keep files in RAM, or implement `Storage` for a custom backend such as cloud or a database.
1992
+ *
1993
+ * @default fsStorage()
1994
+ * @example
1995
+ * ```ts
1996
+ * import { memoryStorage } from '@kubb/core'
1997
+ *
1998
+ * // Keep generated files in memory (useful for testing, CI pipelines)
1999
+ * storage: memoryStorage()
2000
+ *
2001
+ * // Use custom S3 storage
2002
+ * storage: myS3Storage()
2003
+ * ```
2004
+ *
2005
+ * @see {@link Storage} interface for implementing custom backends.
2006
+ */
2007
+ storage: Storage;
2008
+ /**
2009
+ * Plugins that run during the build to generate code and transform the AST. Each one processes
2010
+ * the adapter's AST and can emit files for a different target (TypeScript, Zod, Faker). A plugin
2011
+ * that depends on another throws when that plugin isn't registered.
2012
+ *
2013
+ * @example
2014
+ * ```ts
2015
+ * import { pluginTs } from '@kubb/plugin-ts'
2016
+ * import { pluginZod } from '@kubb/plugin-zod'
2017
+ *
2018
+ * plugins: [
2019
+ * pluginTs({ output: { path: './src/gen' } }),
2020
+ * pluginZod({ output: { path: './src/gen' } }),
2021
+ * ]
2022
+ * ```
2023
+ */
2024
+ plugins: Array<Plugin>;
2025
+ /**
2026
+ * Lifecycle hooks that run external tools (prettier, eslint, a custom script) on build events.
2027
+ *
2028
+ * Currently supports the `done` hook, which fires after all plugins complete.
2029
+ *
2030
+ * @example
2031
+ * ```ts
2032
+ * hooks: {
2033
+ * done: 'prettier --write "./src/gen"', // auto-format generated files
2034
+ * // or multiple commands:
2035
+ * done: ['prettier --write "./src/gen"', 'eslint --fix "./src/gen"']
2036
+ * }
2037
+ * ```
2038
+ */
2039
+ hooks?: {
2040
+ /**
2041
+ * Command(s) to run after all plugins finish generating, for post-processing the output.
2042
+ *
2043
+ * Pass a single command string, or an array to run them in sequence.
2044
+ * Commands run relative to the `root` directory.
2045
+ *
2046
+ * @example
2047
+ * ```ts
2048
+ * done: 'prettier --write "./src/gen"'
2049
+ * done: ['prettier --write "./src/gen"', 'eslint --fix "./src/gen"']
2050
+ * ```
2051
+ */
2052
+ done?: string | Array<string>;
2053
+ };
2054
+ /**
2055
+ * The reporters available to the run, registered as instances. The host
2056
+ * (the CLI via `--reporter`) selects which ones to trigger by `name` with {@link selectReporters}.
2057
+ * `defineConfig` from the `kubb` package registers the built-in `cli`, `json`, and `file`
2058
+ * reporters by default.
2059
+ *
2060
+ * - `cli` writes the end-of-run summary to the terminal.
2061
+ * - `json` writes a machine-readable report to stdout, for CI.
2062
+ * - `file` writes a debug log to `.kubb/<name>-<timestamp>.log`.
2063
+ *
2064
+ * @example
2065
+ * ```ts
2066
+ * import { cliReporter, jsonReporter } from '@kubb/core'
2067
+ *
2068
+ * reporters: [cliReporter, jsonReporter, myReporter]
2069
+ * ```
2070
+ */
2071
+ reporters: Array<Reporter>;
2072
+ };
2073
+ /**
2074
+ * Partial `Config` for user-facing entry points with sensible defaults.
2075
+ *
2076
+ * `UserConfig` is what you pass to `defineConfig()`. It has optional `root`, `plugins`, `parsers`, and `adapter`
2077
+ * fields (which fall back to sensible defaults). All other Config options are available, including `output`, `input`,
2078
+ * `storage`, and `hooks`.
2079
+ *
2080
+ * @example
2081
+ * ```ts
2082
+ * export default defineConfig({
2083
+ * input: { path: './petstore.yaml' },
2084
+ * output: { path: './src/gen' },
2085
+ * plugins: [pluginTs(), pluginZod()],
2086
+ * })
2087
+ * ```
2088
+ */
2089
+ type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter' | 'storage' | 'reporters'> & {
2090
+ /**
2091
+ * Project root directory, absolute or relative to the config file location.
2092
+ * @default process.cwd()
2093
+ */
2094
+ root?: string;
2095
+ /**
2096
+ * Custom parsers that convert generated AST nodes to strings (TypeScript, JSON, markdown, etc.).
2097
+ * @default [parserTs, parserTsx, parserMd] // applied by `defineConfig` from the `kubb` package
2098
+ */
2099
+ parsers?: Array<Parser>;
2100
+ /**
2101
+ * Adapter that parses your API specification into Kubb's universal AST.
2102
+ * When omitted, Kubb runs in plugin-only mode.
2103
+ */
2104
+ adapter?: Adapter;
2105
+ /**
2106
+ * Plugins that execute during the build to generate code and transform the AST.
2107
+ * @default []
2108
+ */
2109
+ plugins?: Array<Plugin>;
2110
+ /**
2111
+ * Storage backend that controls where and how generated files are persisted.
2112
+ * @default fsStorage()
2113
+ */
2114
+ storage?: Storage;
2115
+ /**
2116
+ * Reporters available to the run. `defineConfig` registers the built-in `cli`, `json`, and
2117
+ * `file` reporters when omitted.
2118
+ * @default [cliReporter, jsonReporter, fileReporter] // applied by `defineConfig` from the `kubb` package
2119
+ */
2120
+ reporters?: Array<Reporter>;
2121
+ };
2122
+ declare global {
2123
+ namespace Kubb {
2124
+ /**
2125
+ * Registry that maps plugin names to their `PluginFactoryOptions`.
2126
+ * Augment this interface in each plugin's `types.ts` to enable automatic
2127
+ * typing for `getPlugin` and `requirePlugin`.
2128
+ *
2129
+ * @example
2130
+ * ```ts
2131
+ * // packages/plugin-ts/src/types.ts
2132
+ * declare global {
2133
+ * namespace Kubb {
2134
+ * interface PluginRegistry {
2135
+ * 'plugin-ts': PluginTs
2136
+ * }
2137
+ * }
2138
+ * }
2139
+ * ```
2140
+ */
2141
+ interface PluginRegistry {}
2142
+ /**
2143
+ * Extension point for root `Config['output']` options.
2144
+ * Augment the `output` key in plugin packages to add extra fields
2145
+ * to the global output configuration without touching core types.
2146
+ *
2147
+ * @example
2148
+ * ```ts
2149
+ * // packages/plugin-barrel/src/plugin.ts
2150
+ * declare global {
2151
+ * namespace Kubb {
2152
+ * interface ConfigOptionsRegistry {
2153
+ * output: {
2154
+ * barrel?: import('./types.ts').BarrelConfig | false
2155
+ * }
2156
+ * }
2157
+ * }
2158
+ * }
2159
+ * ```
2160
+ */
2161
+ interface ConfigOptionsRegistry {}
2162
+ /**
2163
+ * Extension point for per-plugin `Output` options.
2164
+ * Augment the `output` key in plugin packages to add extra fields
2165
+ * to the per-plugin output configuration without touching core types.
2166
+ *
2167
+ * @example
2168
+ * ```ts
2169
+ * // packages/plugin-barrel/src/plugin.ts
2170
+ * declare global {
2171
+ * namespace Kubb {
2172
+ * interface PluginOptionsRegistry {
2173
+ * output: {
2174
+ * barrel?: import('./types.ts').PluginBarrelConfig | false
2175
+ * }
2176
+ * }
2177
+ * }
2178
+ * }
2179
+ * ```
2180
+ */
2181
+ interface PluginOptionsRegistry {}
2182
+ }
2183
+ }
2184
+ /**
2185
+ * Lifecycle events emitted during Kubb code generation.
2186
+ * Attach listeners before calling `setup()` or `build()` to observe and react to build progress.
2187
+ *
2188
+ * @example
2189
+ * ```ts
2190
+ * kubb.hooks.on('kubb:lifecycle:start', () => {
2191
+ * console.log('Starting Kubb generation')
2192
+ * })
2193
+ *
2194
+ * kubb.hooks.on('kubb:plugin:end', ({ plugin, duration }) => {
2195
+ * console.log(`${plugin.name} completed in ${duration}ms`)
2196
+ * })
2197
+ * ```
2198
+ */
2199
+ interface KubbHooks {
2200
+ 'kubb:lifecycle:start': [ctx: KubbLifecycleStartContext];
2201
+ 'kubb:lifecycle:end': [];
2202
+ 'kubb:generation:start': [ctx: KubbGenerationStartContext];
2203
+ 'kubb:generation:end': [ctx: KubbGenerationEndContext];
2204
+ 'kubb:format:start': [];
2205
+ 'kubb:format:end': [];
2206
+ 'kubb:lint:start': [];
2207
+ 'kubb:lint:end': [];
2208
+ 'kubb:hooks:start': [];
2209
+ 'kubb:hooks:end': [];
2210
+ 'kubb:hook:start': [ctx: KubbHookStartContext];
2211
+ 'kubb:hook:line': [ctx: KubbHookLineContext];
2212
+ 'kubb:hook:end': [ctx: KubbHookEndContext];
2213
+ 'kubb:info': [ctx: KubbInfoContext];
2214
+ 'kubb:error': [ctx: KubbErrorContext];
2215
+ 'kubb:success': [ctx: KubbSuccessContext];
2216
+ 'kubb:warn': [ctx: KubbWarnContext];
2217
+ 'kubb:diagnostic': [ctx: KubbDiagnosticContext];
2218
+ 'kubb:files:processing:start': [ctx: KubbFilesProcessingStartContext];
2219
+ 'kubb:files:processing:update': [ctx: KubbFilesProcessingUpdateContext];
2220
+ 'kubb:files:processing:end': [ctx: KubbFilesProcessingEndContext];
2221
+ 'kubb:plugin:start': [ctx: KubbPluginStartContext];
2222
+ 'kubb:plugin:end': [ctx: KubbPluginEndContext];
2223
+ 'kubb:plugin:setup': [ctx: KubbPluginSetupContext];
2224
+ 'kubb:build:start': [ctx: KubbBuildStartContext];
2225
+ 'kubb:plugins:end': [ctx: KubbPluginsEndContext];
2226
+ 'kubb:build:end': [ctx: KubbBuildEndContext];
2227
+ 'kubb:generate:schema': [node: SchemaNode, ctx: GeneratorContext];
2228
+ 'kubb:generate:operation': [node: OperationNode, ctx: GeneratorContext];
2229
+ 'kubb:generate:operations': [nodes: Array<OperationNode>, ctx: GeneratorContext];
2230
+ }
2231
+ type KubbBuildStartContext = {
2232
+ /**
2233
+ * Resolved configuration for this build.
2234
+ */
2235
+ config: Config;
2236
+ /**
2237
+ * Adapter that parsed the input into the universal AST.
2238
+ */
2239
+ adapter: Adapter;
2240
+ /**
2241
+ * Metadata about the parsed document (title, version, base URL, circular schema names, enum names).
2242
+ * To observe individual schemas and operations use the `kubb:generate:schema` / `kubb:generate:operation` hooks.
2243
+ */
2244
+ meta: InputMeta | undefined;
2245
+ /**
2246
+ * Looks up a registered plugin by name, typed by the plugin registry.
2247
+ */
2248
+ getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
2249
+ getPlugin(name: string): Plugin | undefined;
2250
+ /**
2251
+ * Snapshot of all files accumulated so far.
2252
+ */
2253
+ readonly files: ReadonlyArray<FileNode>;
2254
+ /**
2255
+ * Adds or merges one or more files into the file manager.
2256
+ */
2257
+ upsertFile: (...files: Array<FileNode>) => void;
2258
+ };
2259
+ type KubbPluginsEndContext = {
2260
+ /**
2261
+ * Resolved configuration for this build.
2262
+ */
2263
+ config: Config;
2264
+ /**
2265
+ * Snapshot of all files accumulated across all plugins.
2266
+ */
2267
+ readonly files: ReadonlyArray<FileNode>;
2268
+ /**
2269
+ * Adds or merges one or more files into the file manager.
2270
+ */
2271
+ upsertFile: (...files: Array<FileNode>) => void;
2272
+ };
2273
+ type KubbBuildEndContext = {
2274
+ /**
2275
+ * All files generated during this build.
2276
+ */
2277
+ files: Array<FileNode>;
2278
+ /**
2279
+ * Resolved configuration for this build.
2280
+ */
2281
+ config: Config;
2282
+ /**
2283
+ * Absolute path to the output directory.
2284
+ */
2285
+ outputDir: string;
2286
+ };
2287
+ type KubbLifecycleStartContext = {
2288
+ /**
2289
+ * Current Kubb version string.
2290
+ */
2291
+ version: string;
2292
+ };
2293
+ type KubbGenerationStartContext = {
2294
+ /**
2295
+ * Resolved configuration for this generation run.
2296
+ */
2297
+ config: Config;
2298
+ };
2299
+ type KubbGenerationEndContext = {
2300
+ /**
2301
+ * Resolved configuration for this generation run.
2302
+ */
2303
+ config: Config;
2304
+ /**
2305
+ * Read-only view of the files written during this build.
2306
+ * Reads go directly to `config.storage`, nothing extra is held in memory.
2307
+ *
2308
+ * @example Read a generated file
2309
+ * `const code = await storage.getItem('/src/gen/pet.ts')`
2310
+ *
2311
+ * @example Walk every generated file
2312
+ * ```ts
2313
+ * for (const path of await storage.getKeys()) {
2314
+ * const code = await storage.getItem(path)
2315
+ * }
2316
+ * ```
2317
+ */
2318
+ storage: Storage;
2319
+ /**
2320
+ * Diagnostics collected during the build: error/warning/info problems plus a
2321
+ * `performance` diagnostic per plugin. The end-of-run summary derives its failure counts
2322
+ * and per-plugin timings from these. Set by the CLI runner, omitted by other callers.
2323
+ */
2324
+ diagnostics?: Array<Diagnostic>;
2325
+ /**
2326
+ * `'success'` when all plugins completed without errors, `'failed'` otherwise.
2327
+ */
2328
+ status?: 'success' | 'failed';
2329
+ /**
2330
+ * High-resolution start time from `process.hrtime()`, used to compute the elapsed time.
2331
+ */
2332
+ hrStart?: [number, number];
2333
+ /**
2334
+ * Total number of files created during this run.
2335
+ */
2336
+ filesCreated?: number;
2337
+ };
2338
+ type KubbInfoContext = {
2339
+ /**
2340
+ * Human-readable info message.
2341
+ */
2342
+ message: string;
2343
+ /**
2344
+ * Optional supplementary detail.
2345
+ */
2346
+ info?: string;
2347
+ };
2348
+ type KubbErrorContext = {
2349
+ /**
2350
+ * The caught error.
2351
+ */
2352
+ error: Error;
2353
+ /**
2354
+ * Optional structured metadata for additional context.
2355
+ */
2356
+ meta?: Record<string, unknown>;
2357
+ };
2358
+ type KubbSuccessContext = {
2359
+ /**
2360
+ * Human-readable success message.
2361
+ */
2362
+ message: string;
2363
+ /**
2364
+ * Optional supplementary detail.
2365
+ */
2366
+ info?: string;
2367
+ };
2368
+ type KubbWarnContext = {
2369
+ /**
2370
+ * Human-readable warning message.
2371
+ */
2372
+ message: string;
2373
+ /**
2374
+ * Optional supplementary detail.
2375
+ */
2376
+ info?: string;
2377
+ };
2378
+ type KubbDiagnosticContext = {
2379
+ /**
2380
+ * The structured diagnostic to render: a build problem or a version-update notice.
2381
+ */
2382
+ diagnostic: ProblemDiagnostic | UpdateDiagnostic;
2383
+ };
2384
+ type KubbFilesProcessingStartContext = {
2385
+ /**
2386
+ * Files about to be serialized and written.
2387
+ */
2388
+ files: Array<FileNode>;
2389
+ };
2390
+ type KubbFileProcessingUpdate = {
2391
+ /**
2392
+ * Number of files processed so far in this batch.
2393
+ */
2394
+ processed: number;
2395
+ /**
2396
+ * Total number of files in this batch.
2397
+ */
2398
+ total: number;
2399
+ /**
2400
+ * Completion percentage, `0` to `100`.
2401
+ */
2402
+ percentage: number;
2403
+ /**
2404
+ * Serialized file content, or `undefined` when the file produced no output.
2405
+ */
2406
+ source?: string;
2407
+ /**
2408
+ * The file that was just processed.
2409
+ */
2410
+ file: FileNode;
2411
+ /**
2412
+ * Resolved configuration for this build.
2413
+ */
2414
+ config: Config;
2415
+ };
2416
+ type KubbFilesProcessingUpdateContext = {
2417
+ /**
2418
+ * All files processed in this flush chunk.
2419
+ */
2420
+ files: Array<KubbFileProcessingUpdate>;
2421
+ };
2422
+ type KubbFilesProcessingEndContext = {
2423
+ /**
2424
+ * All files that were serialized in this batch.
2425
+ */
2426
+ files: Array<FileNode>;
2427
+ };
2428
+ type KubbHookStartContext = {
2429
+ /**
2430
+ * Optional identifier for correlating start/end events.
2431
+ */
2432
+ id?: string;
2433
+ /**
2434
+ * The shell command that is about to run.
2435
+ */
2436
+ command: string;
2437
+ /**
2438
+ * Parsed argument list, when available.
2439
+ */
2440
+ args?: ReadonlyArray<string>;
2441
+ };
2442
+ /**
2443
+ * Emitted for each line streamed from a hook's stdout while it runs.
2444
+ * A logger correlates the line to its active UI element via `id`.
2445
+ */
2446
+ type KubbHookLineContext = {
2447
+ /**
2448
+ * Identifier matching the corresponding `kubb:hook:start` event.
2449
+ */
2450
+ id: string;
2451
+ /**
2452
+ * A single streamed stdout line, without its trailing newline.
2453
+ */
2454
+ line: string;
2455
+ };
2456
+ type KubbHookEndContext = {
2457
+ /**
2458
+ * Optional identifier matching the corresponding `kubb:hook:start` event.
2459
+ */
2460
+ id?: string;
2461
+ /**
2462
+ * The shell command that ran.
2463
+ */
2464
+ command: string;
2465
+ /**
2466
+ * Parsed argument list, when available.
2467
+ */
2468
+ args?: ReadonlyArray<string>;
2469
+ /**
2470
+ * `true` when the command exited with code `0`.
2471
+ */
2472
+ success: boolean;
2473
+ /**
2474
+ * Error thrown by the command, or `null` on success.
2475
+ */
2476
+ error: Error | null;
2477
+ /**
2478
+ * Captured stdout from the process, populated when it exits non-zero.
2479
+ */
2480
+ stdout?: string;
2481
+ /**
2482
+ * Captured stderr from the process, populated when it exits non-zero.
2483
+ */
2484
+ stderr?: string;
2485
+ };
2486
+ /**
2487
+ * CLI options derived from command-line flags.
2488
+ */
2489
+ type CLIOptions = {
2490
+ /**
2491
+ * Path to the Kubb config file.
2492
+ */
2493
+ config?: string;
2494
+ /**
2495
+ * OpenAPI input path passed as the positional argument to `kubb generate`.
2496
+ * Overrides `config.input.path` when set.
2497
+ */
2498
+ input?: string;
2499
+ /**
2500
+ * Re-run generation whenever input files change.
2501
+ */
2502
+ watch?: boolean;
2503
+ /**
2504
+ * Controls how much output the CLI prints.
2505
+ *
2506
+ * @default 'info'
2507
+ */
2508
+ logLevel?: 'silent' | 'info' | 'verbose';
2509
+ /**
2510
+ * Reporters selected on the CLI via `--reporter`, overriding `config.reporters`.
2511
+ */
2512
+ reporters?: Array<ReporterName>;
2513
+ };
2514
+ /**
2515
+ * All accepted forms of a Kubb configuration.
2516
+ * Accepts `Config`/`Config[]`/promise or a factory (optionally receiving `TCliOptions`).
2517
+ */
2518
+ type PossibleConfig<TCliOptions = undefined> = PossiblePromise<Config | Array<Config>> | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Array<Config>>);
2519
+ /**
2520
+ * Full output produced by a successful or failed build.
2521
+ */
2522
+ type BuildOutput = {
2523
+ /**
2524
+ * Structured diagnostics collected during the build: error/warning/info problems
2525
+ * (each with a code, severity, and where known a JSON-pointer location) plus a
2526
+ * `performance` diagnostic per plugin. Includes a top-level diagnostic when the build
2527
+ * threw before completing. Use {@link Diagnostics.hasError} to test for failure.
2528
+ */
2529
+ diagnostics: Array<Diagnostic>;
2530
+ /**
2531
+ * All files generated during this build.
2532
+ */
2533
+ files: Array<FileNode>;
2534
+ /**
2535
+ * The plugin driver that orchestrated this build.
2536
+ */
2537
+ driver: KubbDriver;
2538
+ /**
2539
+ * Read-only view of every file written during this build.
2540
+ * Reads go straight to `config.storage`, nothing extra is held in memory.
2541
+ *
2542
+ * @example Read a generated file
2543
+ * `const code = await buildOutput.storage.getItem('/src/gen/pet.ts')`
2544
+ *
2545
+ * @example List all generated file paths
2546
+ * `const paths = await buildOutput.storage.getKeys()`
2547
+ */
2548
+ storage: Storage;
2549
+ };
2550
+ //#endregion
2551
+ //#region src/diagnostics.d.ts
2552
+ /**
2553
+ * How serious a diagnostic is. `error` fails the build, `warning` and `info`
2554
+ * are reported but do not.
2555
+ */
2556
+ type DiagnosticSeverity = 'error' | 'warning' | 'info';
2557
+ /**
2558
+ * A human-readable explanation of a diagnostic code: a short title, what triggers it, and how
2559
+ * to resolve it. This is the source of truth the kubb.dev `/diagnostics/<slug>` pages mirror, so
2560
+ * every code stays documented in one place. Adding a code without documenting it fails the build.
2561
+ */
2562
+ type DiagnosticDoc = {
2563
+ /**
2564
+ * Short title shown as the docs heading.
2565
+ */
2566
+ title: string;
2567
+ /**
2568
+ * What triggers the diagnostic.
2569
+ */
2570
+ cause: string;
2571
+ /**
2572
+ * The action that resolves it.
2573
+ */
2574
+ fix: string;
2575
+ };
2576
+ /**
2577
+ * Points a diagnostic back into the source document. Inputs are parsed into an
2578
+ * object model with no line/column, so locations carry a JSON pointer the adapter
2579
+ * builds (the OAS adapter emits `#/components/schemas/Pet`). A `config` diagnostic
2580
+ * points at the Kubb config itself and so has no pointer.
2581
+ */
2582
+ type DiagnosticLocation = {
2583
+ kind: 'schema';
2584
+ /**
2585
+ * RFC 6901 JSON pointer into the source document.
2586
+ */
2587
+ pointer: string;
2588
+ /**
2589
+ * The original reference when the diagnostic stems from an unresolved one.
2590
+ */
2591
+ ref?: string;
2592
+ } | {
2593
+ kind: 'operation' | 'document';
2594
+ /**
2595
+ * RFC 6901 JSON pointer into the source document.
2596
+ */
2597
+ pointer: string;
2598
+ } | {
2599
+ kind: 'config';
2600
+ };
2601
+ /**
2602
+ * What a diagnostic carries.
2603
+ * - `problem` is a build issue shown to the user, and the only kind rendered as a problem.
2604
+ * - `performance` records a plugin's elapsed time.
2605
+ * - `update` is a version notice.
2606
+ */
2607
+ type DiagnosticKind = 'problem' | 'performance' | 'update';
2608
+ /**
2609
+ * Codes that describe a build problem: every {@link DiagnosticCode} except the
2610
+ * `performance` and `updateAvailable` codes, which ride on their own variants.
2611
+ */
2612
+ type ProblemCode = Exclude<DiagnosticCode, typeof diagnosticCode.performance | typeof diagnosticCode.updateAvailable>;
2613
+ /**
2614
+ * A build problem collected during a run, gathered into the result instead of
2615
+ * aborting on the first failure.
2616
+ */
2617
+ type ProblemDiagnostic = {
2618
+ /**
2619
+ * @default 'problem'
2620
+ */
2621
+ kind?: 'problem';
2622
+ /**
2623
+ * Stable identifier for the problem, from the {@link diagnosticCode} catalog.
2624
+ */
2625
+ code: ProblemCode;
2626
+ severity: DiagnosticSeverity;
2627
+ message: string;
2628
+ location?: DiagnosticLocation;
2629
+ /**
2630
+ * A suggested fix, phrased as an action the user can take.
2631
+ */
2632
+ help?: string;
2633
+ /**
2634
+ * Name of the plugin or subsystem that produced the diagnostic.
2635
+ */
2636
+ plugin?: string;
2637
+ /**
2638
+ * The underlying error, when the diagnostic wraps a thrown one.
2639
+ */
2640
+ cause?: Error;
2641
+ };
2642
+ /**
2643
+ * A per-plugin performance record, built with {@link Diagnostics.performance}. The `performance`
2644
+ * kind keeps it out of the problem list. It feeds the per-plugin timing bars, and reporters sum
2645
+ * these into the run total.
2646
+ */
2647
+ type PerformanceDiagnostic = {
2648
+ kind: 'performance';
2649
+ code: typeof diagnosticCode.performance;
2650
+ severity: 'info';
2651
+ message: string;
2652
+ /**
2653
+ * The plugin this measurement belongs to.
2654
+ */
2655
+ plugin: string;
2656
+ /**
2657
+ * Elapsed milliseconds.
2658
+ */
2659
+ duration: number;
2660
+ };
2661
+ /**
2662
+ * A notice that a newer Kubb version is available on npm, built with {@link Diagnostics.update}.
2663
+ * It renders like any info diagnostic.
2664
+ */
2665
+ type UpdateDiagnostic = {
2666
+ kind: 'update';
2667
+ code: typeof diagnosticCode.updateAvailable;
2668
+ severity: 'info';
2669
+ message: string;
2670
+ /**
2671
+ * The running Kubb version.
2672
+ */
2673
+ currentVersion: string;
2674
+ /**
2675
+ * The newest version published on npm.
2676
+ */
2677
+ latestVersion: string;
2678
+ };
2679
+ /**
2680
+ * A structured record collected during a build, discriminated on `kind`: a
2681
+ * {@link ProblemDiagnostic} for an issue, a {@link PerformanceDiagnostic} for a per-plugin
2682
+ * timing, or an {@link UpdateDiagnostic} for a version notice.
2683
+ */
2684
+ type Diagnostic = ProblemDiagnostic | PerformanceDiagnostic | UpdateDiagnostic;
2685
+ /**
2686
+ * Maps each {@link DiagnosticCode} to the variant it selects, for {@link narrow}.
2687
+ * Every {@link ProblemCode} selects a {@link ProblemDiagnostic}, and the two bookkeeping codes
2688
+ * select their own variant.
2689
+ */
2690
+ type DiagnosticByCode = Record<ProblemCode, ProblemDiagnostic> & Record<typeof diagnosticCode.performance, PerformanceDiagnostic> & Record<typeof diagnosticCode.updateAvailable, UpdateDiagnostic>;
2691
+ /**
2692
+ * Narrows a {@link Diagnostic} to the variant for `code`, or `null` when it does not match.
2693
+ *
2694
+ * @example
2695
+ * ```ts
2696
+ * const update = narrow(diagnostic, diagnosticCode.updateAvailable)
2697
+ * if (update) {
2698
+ * console.log(update.latestVersion)
2699
+ * }
2700
+ * ```
2701
+ */
2702
+ declare function narrow<C extends DiagnosticCode>(diagnostic: Diagnostic, code: C): DiagnosticByCode[C] | null;
2703
+ /**
2704
+ * A {@link Diagnostic} reduced to its JSON-safe fields plus a `docsUrl`, for
2705
+ * machine-readable output (the `--reporter json` report, the MCP tools). Drops the
2706
+ * non-serializable `cause` and the `timing`/`duration` bookkeeping.
2707
+ */
2708
+ type SerializedDiagnostic = {
2709
+ code: DiagnosticCode;
2710
+ severity: DiagnosticSeverity;
2711
+ message: string;
2712
+ location?: DiagnosticLocation;
2713
+ help?: string;
2714
+ plugin?: string;
2715
+ /**
2716
+ * The kubb.dev docs link for the code, omitted for the unknown fallback.
2717
+ */
2718
+ docsUrl?: string;
2719
+ };
2720
+ /**
2721
+ * Static helpers for working with {@link Diagnostic}s, plus the run-scoped sink
2722
+ * that lets deep code report a diagnostic without threading a callback.
2723
+ *
2724
+ * The sink lives in a single `AsyncLocalStorage` in the `@kubb/core` bundle.
2725
+ * `Diagnostics.scope` activates it for a run, so anything inside that run (the
2726
+ * adapter parse, a lazily consumed stream, a generator) reports through
2727
+ * `Diagnostics.report` and lands in the same run.
2728
+ */
2729
+ declare class Diagnostics {
2730
+ #private;
2731
+ /**
2732
+ * The diagnostic code catalog, exposed as `Diagnostics.code` (e.g. `Diagnostics.code.refNotFound`).
2733
+ */
2734
+ static code: {
2735
+ readonly unknown: "KUBB_UNKNOWN";
2736
+ readonly inputNotFound: "KUBB_INPUT_NOT_FOUND";
2737
+ readonly inputRequired: "KUBB_INPUT_REQUIRED";
2738
+ readonly refNotFound: "KUBB_REF_NOT_FOUND";
2739
+ readonly invalidServerVariable: "KUBB_INVALID_SERVER_VARIABLE";
2740
+ readonly pluginNotFound: "KUBB_PLUGIN_NOT_FOUND";
2741
+ readonly pluginFailed: "KUBB_PLUGIN_FAILED";
2742
+ readonly pluginWarning: "KUBB_PLUGIN_WARNING";
2743
+ readonly pluginInfo: "KUBB_PLUGIN_INFO";
2744
+ readonly unsupportedFormat: "KUBB_UNSUPPORTED_FORMAT";
2745
+ readonly deprecated: "KUBB_DEPRECATED";
2746
+ readonly adapterRequired: "KUBB_ADAPTER_REQUIRED";
2747
+ readonly pathTraversal: "KUBB_PATH_TRAVERSAL";
2748
+ readonly invalidPluginOptions: "KUBB_INVALID_PLUGIN_OPTIONS";
2749
+ readonly hookFailed: "KUBB_HOOK_FAILED";
2750
+ readonly formatFailed: "KUBB_FORMAT_FAILED";
2751
+ readonly lintFailed: "KUBB_LINT_FAILED";
2752
+ readonly performance: "KUBB_PERFORMANCE";
2753
+ readonly updateAvailable: "KUBB_UPDATE_AVAILABLE";
2754
+ };
2755
+ /**
2756
+ * Type guard for a build {@link ProblemDiagnostic}.
2757
+ */
2758
+ static isProblem: (diagnostic: Diagnostic) => diagnostic is ProblemDiagnostic;
2759
+ /**
2760
+ * Type guard for a version-update {@link UpdateDiagnostic}.
2761
+ */
2762
+ static isUpdate: (diagnostic: Diagnostic) => diagnostic is UpdateDiagnostic;
2763
+ /**
2764
+ * Type guard for a per-plugin {@link PerformanceDiagnostic}.
2765
+ */
2766
+ static isPerformance: (diagnostic: Diagnostic) => diagnostic is PerformanceDiagnostic;
2767
+ /**
2768
+ * Narrows a {@link Diagnostic} to the variant for `code`, or `null` when it does not match.
2769
+ */
2770
+ static narrow: typeof narrow;
2771
+ /**
2772
+ * An `Error` that carries a {@link Diagnostic}, so structured problems can flow
2773
+ * through the existing throw/catch paths while keeping their code and location.
2774
+ *
2775
+ * @example
2776
+ * ```ts
2777
+ * throw new Diagnostics.Error({ code: diagnosticCode.refNotFound, severity: 'error', message: `Could not find ${ref}`, location: { kind: 'schema', pointer: ref, ref } })
2778
+ * ```
2779
+ */
2780
+ static Error: {
2781
+ new (diagnostic: ProblemDiagnostic): {
2782
+ diagnostic: ProblemDiagnostic;
2783
+ name: string;
2784
+ message: string;
2785
+ stack?: string;
2786
+ cause?: unknown;
2787
+ };
2788
+ isError(error: unknown): error is Error;
2789
+ isError(value: unknown): value is Error;
2790
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
2791
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
2792
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
2793
+ stackTraceLimit: number;
2794
+ };
2795
+ /**
2796
+ * Structural check for a {@link Diagnostics.Error}, including one thrown from a duplicated
2797
+ * `@kubb/core` copy where `instanceof` fails. Matches on the `name` and a `diagnostic`
2798
+ * that carries a `code`.
2799
+ */
2800
+ static isError(error: unknown): error is InstanceType<typeof Diagnostics.Error>;
2801
+ /**
2802
+ * Runs `fn` with `sink` as the active diagnostic sink for the whole async
2803
+ * subtree, so {@link Diagnostics.report} reaches it from anywhere inside.
2804
+ */
2805
+ static scope<T>(sink: (diagnostic: Diagnostic) => void, fn: () => T): T;
2806
+ /**
2807
+ * Collects a diagnostic into the active build via the run-scoped sink, without throwing.
2808
+ * Returns `true` when a run consumed it, `false` when called outside a {@link Diagnostics.scope}
2809
+ * (so callers can fall back to throwing). Use a `warning`/`info` severity for non-fatal issues.
2810
+ * For rendering a diagnostic live on the hook bus, use {@link Diagnostics.emit} instead.
2811
+ */
2812
+ static report(diagnostic: Diagnostic): boolean;
2813
+ /**
2814
+ * Emits a diagnostic on the run's `kubb:diagnostic` event so the loggers render it live.
2815
+ * Use it instead of calling `hooks.emit('kubb:diagnostic', ...)` directly. To collect a
2816
+ * diagnostic into the build result from deep in a run, use {@link Diagnostics.report} instead.
2817
+ */
2818
+ static emit(hooks: AsyncEventEmitter<KubbHooks>, diagnostic: ProblemDiagnostic | UpdateDiagnostic): Promise<void>;
2819
+ /**
2820
+ * Coerces any thrown value into a {@link ProblemDiagnostic}. A {@link Diagnostics.Error}
2821
+ * keeps its structured data, and anything else becomes a `KUBB_UNKNOWN` error.
2822
+ */
2823
+ static from(error: unknown): ProblemDiagnostic;
2824
+ /**
2825
+ * Builds a per-plugin performance record. Reporters sum these into the run total.
2826
+ */
2827
+ static performance({
2828
+ plugin,
2829
+ duration
2830
+ }: {
2831
+ plugin: string;
2832
+ duration: number;
2833
+ }): PerformanceDiagnostic;
2834
+ /**
2835
+ * Builds the version-update notice shown when a newer Kubb is published on npm.
2836
+ */
2837
+ static update({
2838
+ currentVersion,
2839
+ latestVersion
2840
+ }: {
2841
+ currentVersion: string;
2842
+ latestVersion: string;
2843
+ }): UpdateDiagnostic;
2844
+ /**
2845
+ * True when any diagnostic is an error, the severity that fails a build. Non-error
2846
+ * diagnostics are ignored.
2847
+ */
2848
+ static hasError(diagnostics: ReadonlyArray<Diagnostic>): boolean;
2849
+ /**
2850
+ * Names of the plugins that failed, deduped, derived from the error diagnostics
2851
+ * that carry a `plugin`.
2852
+ */
2853
+ static failedPlugins(diagnostics: ReadonlyArray<Diagnostic>): Array<string>;
2854
+ /**
2855
+ * Counts `problem` diagnostics by severity for the run summary. `timing`
2856
+ * diagnostics are ignored.
2857
+ */
2858
+ static count(diagnostics: ReadonlyArray<Diagnostic>): {
2859
+ errors: number;
2860
+ warnings: number;
2861
+ infos: number;
2862
+ };
2863
+ /**
2864
+ * Drops duplicate `problem` diagnostics that share a code, location pointer, and
2865
+ * plugin, so the same issue reported across several passes is shown once. Non-problem
2866
+ * diagnostics are always kept.
2867
+ */
2868
+ static dedupe(diagnostics: ReadonlyArray<Diagnostic>): Array<Diagnostic>;
2869
+ /**
2870
+ * Builds the kubb.dev docs URL for a diagnostic code, e.g.
2871
+ * `KUBB_REF_NOT_FOUND` → `https://kubb.dev/docs/5.x/reference/diagnostics/kubb-ref-not-found`.
2872
+ */
2873
+ static docsUrl(code: string): string;
2874
+ /**
2875
+ * The catalog entry for a code: its title, cause, and fix. Mirrors the kubb.dev
2876
+ * `/diagnostics/<slug>` page.
2877
+ */
2878
+ static explain(code: DiagnosticCode): DiagnosticDoc;
2879
+ /**
2880
+ * Reduces a diagnostic to its JSON-safe fields plus a `docsUrl`, for machine-readable
2881
+ * consumers. The `cause`, `kind`, and `duration` are dropped, and absent optional
2882
+ * fields are omitted rather than set to `undefined`.
2883
+ */
2884
+ static serialize(diagnostic: Diagnostic): SerializedDiagnostic;
2885
+ /**
2886
+ * Renders a {@link Diagnostic} for terminal output as its parts: the colored severity `symbol`
2887
+ * (the gutter glyph), the `plugin(CODE): message` `headline`, and the `details` lines (optional
2888
+ * `at <pointer>`, `help:`, and `docs:`).
2889
+ *
2890
+ * Hosts compose these to fit their gutter: a clack logger passes `symbol` as its own gutter and
2891
+ * `[headline, ...details]` as the message, while plain text outputs use {@link Diagnostics.formatLines}.
2892
+ */
2893
+ static format(diagnostic: Diagnostic): {
2894
+ symbol: string;
2895
+ headline: string;
2896
+ details: Array<string>;
2897
+ };
2898
+ /**
2899
+ * The self-contained block form of {@link Diagnostics.format}: `${symbol} ${headline}` followed by
2900
+ * the detail lines. Used where there is no gutter to own the symbol (plain and file output).
2901
+ */
2902
+ static formatLines(diagnostic: Diagnostic): Array<string>;
2903
+ }
2904
+ //#endregion
2905
+ export { KubbPluginSetupContext as $, KubbHookStartContext as A, Adapter as At, ParsedFile as B, KubbFilesProcessingEndContext as C, GenerationResult as Ct, KubbGenerationStartContext as D, UserReporter as Dt, KubbGenerationEndContext as E, ReporterName as Et, KubbSuccessContext as F, Generator$1 as G, createKubb as H, KubbWarnContext as I, KubbDriver as J, GeneratorContext as K, PossibleConfig as L, KubbInfoContext as M, AdapterSource as Mt, KubbLifecycleStartContext as N, createAdapter as Nt, KubbHookEndContext as O, createReporter as Ot, KubbPluginsEndContext as P, AsyncEventEmitter as Pt, KubbPluginEndContext as Q, UserConfig as R, KubbFileProcessingUpdate as S, createStorage as St, KubbFilesProcessingUpdateContext as T, ReporterContext as Tt, Parser as U, Kubb$1 as V, defineParser as W, Group as X, Exclude$1 as Y, Include as Z, InputPath as _, defineResolver as _t, DiagnosticLocation as a, Override as at, KubbDiagnosticContext as b, createRenderer as bt, PerformanceDiagnostic as c, definePlugin as ct, SerializedDiagnostic as d, ResolveBannerFile as dt, KubbPluginStartContext as et, UpdateDiagnostic as f, ResolveOptionsContext as ft, InputData as g, ResolverPathParams as gt, Config as h, ResolverFileParams as ht, DiagnosticKind as i, OutputOptions as it, KubbHooks as j, AdapterFactoryOptions as jt, KubbHookLineContext as k, logLevel as kt, ProblemCode as l, BannerMeta as lt, CLIOptions as m, ResolverContext as mt, DiagnosticByCode as n, Output as nt, DiagnosticSeverity as o, Plugin as ot, BuildOutput as p, Resolver as pt, defineGenerator as q, DiagnosticDoc as r, OutputMode as rt, Diagnostics as s, PluginFactoryOptions as st, Diagnostic as t, NormalizedPlugin as tt, ProblemDiagnostic as u, ResolveBannerContext as ut, KubbBuildEndContext as v, Renderer as vt, KubbFilesProcessingStartContext as w, Reporter as wt, KubbErrorContext as x, Storage as xt, KubbBuildStartContext as y, RendererFactory as yt, FileProcessorHooks as z };
2906
+ //# sourceMappingURL=diagnostics-B-UZnFqP.d.ts.map