@kubb/core 5.10.1 → 5.10.2

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.
@@ -84,647 +84,295 @@ type ParserFactory<TOptions extends object = object, TMeta extends object = obje
84
84
  */
85
85
  declare function defineParser<TOptions extends object = object, TMeta extends object = object, TNode = unknown>(definition: ParserDefinition<TOptions, TMeta, TNode>): ParserFactory<TOptions, TMeta, TNode>;
86
86
  //#endregion
87
- //#region src/createRenderer.d.ts
88
- /**
89
- * Minimal interface any Kubb renderer must satisfy.
90
- *
91
- * `TElement` is the type the renderer accepts, for example `KubbReactElement`
92
- * for `@kubb/renderer-jsx` or a custom type for your own renderer. Defaults to
93
- * `unknown` so generators that don't care about the element type work without
94
- * specifying it.
95
- */
96
- type Renderer<TElement = unknown> = {
97
- /**
98
- * Renders `element` and populates {@link files} with the resulting {@link FileNode} objects.
99
- * Called once per render cycle. Must resolve before {@link files} is read.
100
- */
101
- render(element: TElement): Promise<void>;
102
- /**
103
- * Accumulated {@link FileNode} results produced by the last {@link render} call.
104
- */
105
- readonly files: Array<FileNode>;
106
- /**
107
- * Disposer hook so renderers participate in `using` blocks: `using r = rendererFactory()`
108
- * runs cleanup on every exit path, including thrown errors.
109
- */
110
- [Symbol.dispose](): void;
111
- };
112
- /**
113
- * A factory function that produces a fresh {@link Renderer} per render cycle.
114
- *
115
- * Generators use this to declare which renderer handles their output.
116
- */
117
- type RendererFactory<TElement = unknown> = () => Renderer<TElement>;
118
- /**
119
- * Defines a renderer factory. Renderers turn the generator's return value
120
- * (JSX, a template string, a tree of any shape) into `FileNode`s that get
121
- * written to disk.
122
- *
123
- * A renderer can target output formats beyond JSX, for instance a Handlebars
124
- * renderer or one that writes binary files. Plugins and generators pick the
125
- * renderer to use via the `renderer` field on `defineGenerator`.
126
- *
127
- * @example A minimal renderer that wraps a custom runtime
128
- * ```ts
129
- * import { createRenderer } from '@kubb/core'
130
- *
131
- * export const myRenderer = createRenderer(() => {
132
- * const runtime = new MyRuntime()
133
- * return {
134
- * async render(element) {
135
- * await runtime.render(element)
136
- * },
137
- * get files() {
138
- * return runtime.files
139
- * },
140
- * [Symbol.dispose]() {
141
- * runtime.dispose()
142
- * },
143
- * }
144
- * })
145
- * ```
146
- */
147
- declare function createRenderer<TElement = unknown>(factory: RendererFactory<TElement>): RendererFactory<TElement>;
148
- //#endregion
149
- //#region src/constants.d.ts
150
- /**
151
- * Stable codes Kubb attaches to a `Diagnostic`. Each maps to a known failure mode
152
- * and stays stable so it can be referenced in tooling and (later) docs. Reference
153
- * these instead of inlining the string at a throw site.
154
- */
155
- declare const diagnosticCode: {
156
- /**
157
- * Fallback for an unstructured error with no specific code.
158
- */
159
- readonly unknown: "KUBB_UNKNOWN";
160
- /**
161
- * The file or URL set as `input` could not be read.
162
- */
163
- readonly inputNotFound: "KUBB_INPUT_NOT_FOUND";
164
- /**
165
- * A URL set as `input` (or referenced by a `$ref`) answered with a 4xx or 5xx status
166
- * instead of the document.
167
- */
168
- readonly inputRequestFailed: "KUBB_INPUT_REQUEST_FAILED";
169
- /**
170
- * A URL set as `input` (or referenced by a `$ref`) never answered, so the request failed
171
- * before a status was returned.
172
- */
173
- readonly inputUnreachable: "KUBB_INPUT_UNREACHABLE";
174
- /**
175
- * An adapter was configured without an `input`.
176
- */
177
- readonly inputRequired: "KUBB_INPUT_REQUIRED";
178
- /**
179
- * `input` uses the v4 `{ path }` / `{ data }` wrapper, which v5 reads as a parsed
180
- * document instead of a pointer to one.
181
- */
182
- readonly legacyInput: "KUBB_LEGACY_INPUT";
183
- /**
184
- * The parsed `input` carries no `openapi` or `swagger` version, so it is not a
185
- * document the adapter can read.
186
- */
187
- readonly invalidDocument: "KUBB_INVALID_DOCUMENT";
188
- /** The document fails OpenAPI schema validation. Reported as a warning. */
189
- readonly invalidSpec: "KUBB_INVALID_SPEC";
190
- /**
191
- * A `$ref` (or equivalent reference) could not be resolved in the source document.
192
- */
193
- readonly refNotFound: "KUBB_REF_NOT_FOUND";
194
- /**
195
- * A server variable value is not allowed by its `enum`.
196
- */
197
- readonly invalidServerVariable: "KUBB_INVALID_SERVER_VARIABLE";
198
- /**
199
- * A required plugin is missing from the config.
200
- */
201
- readonly pluginNotFound: "KUBB_PLUGIN_NOT_FOUND";
202
- /**
203
- * The running Kubb or Node.js version is outside a plugin's `meta.compatibility`.
204
- */
205
- readonly incompatibleExtension: "KUBB_INCOMPATIBLE_EXTENSION";
206
- /**
207
- * A required entry in a plugin's `dependencies` record is missing from the config.
208
- */
209
- readonly missingDependency: "KUBB_MISSING_DEPENDENCY";
210
- /**
211
- * A dependency's `meta.version` is outside the range a plugin's `dependencies` record declares.
212
- */
213
- readonly incompatibleDependency: "KUBB_INCOMPATIBLE_DEPENDENCY";
214
- /**
215
- * A plugin threw while generating.
216
- */
217
- readonly pluginFailed: "KUBB_PLUGIN_FAILED";
218
- /** An adapter threw while parsing the input. */
219
- readonly adapterFailed: "KUBB_ADAPTER_FAILED";
220
- /** A parser threw while printing a generated file. */
221
- readonly parserFailed: "KUBB_PARSER_FAILED";
222
- /**
223
- * A plugin reported a non-fatal warning through `ctx.warn`.
224
- */
225
- readonly pluginWarning: "KUBB_PLUGIN_WARNING";
226
- /**
227
- * A plugin reported an informational message through `ctx.info`.
228
- */
229
- readonly pluginInfo: "KUBB_PLUGIN_INFO";
230
- /**
231
- * A `kubb/kit` composable was called outside a plugin's `setup` and `kubb:plugin:setup`.
232
- */
233
- readonly noContext: "KUBB_NO_CONTEXT";
234
- /**
235
- * A schema uses a `format` Kubb does not map to a specific type. Reserved for
236
- * adapters to emit as a `warning`.
237
- */
238
- readonly unsupportedFormat: "KUBB_UNSUPPORTED_FORMAT";
239
- /**
240
- * A referenced schema or operation is marked `deprecated`. Reserved for adapters
241
- * to emit as an `info`.
242
- */
243
- readonly deprecated: "KUBB_DEPRECATED";
244
- /**
245
- * An adapter is required but the config has none. The build cannot read the input
246
- * without one.
247
- */
248
- readonly adapterRequired: "KUBB_ADAPTER_REQUIRED";
249
- /**
250
- * A resolved output path escapes the output directory, which can stem from a path
251
- * traversal in the spec or a misconfigured `group.name`.
252
- */
253
- readonly pathTraversal: "KUBB_PATH_TRAVERSAL";
254
- /**
255
- * `output.clean` is enabled but `output.path` resolves to the project root or a parent of it,
256
- * so cleaning would delete kubb.config and every source file.
257
- */
258
- readonly cleanRoot: "KUBB_CLEAN_ROOT";
259
- /**
260
- * A plugin's options are invalid, for example `output.mode: 'file'` paired with a `group` option.
261
- */
262
- readonly invalidPluginOptions: "KUBB_INVALID_PLUGIN_OPTIONS";
263
- /**
264
- * A post-generate command (`output.postGenerate`) exited with a failure.
265
- */
266
- readonly postGenerateFailed: "KUBB_POST_GENERATE_FAILED";
267
- /**
268
- * The formatter pass over the generated files failed.
269
- */
270
- readonly formatFailed: "KUBB_FORMAT_FAILED";
271
- /**
272
- * The linter pass over the generated files failed.
273
- */
274
- readonly lintFailed: "KUBB_LINT_FAILED";
275
- /**
276
- * A barrel tries to re-export the same name from more than one module.
277
- */
278
- readonly barrelDuplicateExport: "KUBB_BARREL_DUPLICATE_EXPORT";
279
- /**
280
- * Not a failure. Carries a plugin's elapsed time, summed into the run total.
281
- */
282
- readonly performance: "KUBB_PERFORMANCE";
283
- /**
284
- * Not a failure. A newer Kubb version is available on npm.
285
- */
286
- readonly updateAvailable: "KUBB_UPDATE_AVAILABLE";
287
- };
288
- /**
289
- * Union of the stable {@link diagnosticCode} values.
290
- */
291
- type DiagnosticCode = (typeof diagnosticCode)[keyof typeof diagnosticCode];
292
- //#endregion
293
- //#region src/Hookable.d.ts
294
- /**
295
- * A function that can be registered as a hook listener, synchronous or async. Any return value is
296
- * allowed and ignored, so handlers that return a result for their own callers still register.
297
- */
298
- type AsyncListener<TArgs extends Array<unknown>> = (...args: TArgs) => unknown;
299
- /**
300
- * Typed hook emitter that awaits all async listeners before resolving.
301
- *
302
- * @example
303
- * ```ts
304
- * const hooks = new Hookable<{ build: [name: string] }>()
305
- * hooks.hook('build', async (name) => { console.log(name) })
306
- * await hooks.callHook('build', 'petstore') // all listeners awaited
307
- * ```
308
- */
309
- declare class Hookable<THooks extends { [K in keyof THooks]: Array<unknown>; }> {
310
- #private;
311
- /**
312
- * Calls `hookName` and awaits all registered listeners sequentially.
313
- * Throws if any listener rejects, wrapping the cause in an error that names the hook.
314
- *
315
- * @example
316
- * ```ts
317
- * await hooks.callHook('build', 'petstore')
318
- * ```
319
- */
320
- callHook<THookName extends keyof THooks & string>(hookName: THookName, ...hookArgs: THooks[THookName]): Promise<void> | void;
321
- /**
322
- * Registers a persistent listener for `hookName` and returns a function that removes it.
323
- *
324
- * @example
325
- * ```ts
326
- * const unhook = hooks.hook('build', async (name) => { console.log(name) })
327
- * unhook() // removes it
328
- * ```
329
- */
330
- hook<THookName extends keyof THooks & string>(hookName: THookName, handler: AsyncListener<THooks[THookName]>): () => void;
331
- /**
332
- * Registers every handler in `configHooks` at once and returns a function that removes them
333
- * all. Undefined entries are skipped, so a partial hook object registers only its present keys.
334
- *
335
- * @example
336
- * ```ts
337
- * const unhook = hooks.addHooks({ build: onBuild, done: onDone })
338
- * unhook() // removes both
339
- * ```
340
- */
341
- addHooks(configHooks: Partial<{ [K in keyof THooks & string]: AsyncListener<THooks[K]>; }>): () => void;
342
- /**
343
- * Removes a previously registered listener.
344
- *
345
- * @example
346
- * ```ts
347
- * hooks.removeHook('build', handler)
348
- * ```
349
- */
350
- removeHook<THookName extends keyof THooks & string>(hookName: THookName, handler: AsyncListener<THooks[THookName]>): void;
351
- /**
352
- * Returns the number of listeners registered for `hookName`.
353
- *
354
- * @example
355
- * ```ts
356
- * hooks.hook('build', handler)
357
- * hooks.listenerCount('build') // 1
358
- * ```
359
- */
360
- listenerCount<THookName extends keyof THooks & string>(hookName: THookName): number;
361
- /**
362
- * No-op kept for callers written against the `EventEmitter`-backed version. Listeners are unbounded.
363
- *
364
- * @deprecated There is no listener ceiling anymore.
365
- */
366
- setMaxListeners(_max: number): void;
367
- /**
368
- * Removes all listeners from every hook channel.
369
- *
370
- * @example
371
- * ```ts
372
- * hooks.removeAllHooks()
373
- * ```
374
- */
375
- removeAllHooks(): void;
376
- }
377
- //#endregion
378
- //#region src/Diagnostics.d.ts
379
- /**
380
- * How serious a diagnostic is. `error` fails the build, `warning` and `info`
381
- * are reported but do not.
382
- */
383
- type DiagnosticSeverity = 'error' | 'warning' | 'info';
384
- /**
385
- * A human-readable explanation of a diagnostic code: a short title, what triggers it, and how
386
- * to resolve it. This is the source of truth the kubb.dev `/reference/diagnostics#<slug>` sections mirror, so
387
- * every code stays documented in one place. Adding a code without documenting it fails the build.
388
- */
389
- type DiagnosticDoc = {
390
- /**
391
- * Short title shown as the docs heading.
392
- */
393
- title: string;
394
- /**
395
- * What triggers the diagnostic.
396
- */
397
- cause: string;
398
- /**
399
- * The action that resolves it.
400
- */
401
- fix: string;
402
- };
403
- /**
404
- * Points a diagnostic back into the source document. Inputs are parsed into an
405
- * object model with no line/column, so locations carry a JSON pointer the adapter
406
- * builds (the OAS adapter emits `#/components/schemas/Pet`). A `config` diagnostic
407
- * points at the Kubb config itself and so has no pointer.
408
- */
409
- type DiagnosticLocation = {
410
- kind: 'schema';
411
- /**
412
- * RFC 6901 JSON pointer into the source document.
413
- */
414
- pointer: string;
415
- /**
416
- * The original reference when the diagnostic stems from an unresolved one.
417
- */
418
- ref?: string;
419
- } | {
420
- kind: 'operation' | 'document';
421
- /**
422
- * RFC 6901 JSON pointer into the source document.
423
- */
424
- pointer: string;
425
- } | {
426
- kind: 'config';
427
- };
428
- /**
429
- * What a diagnostic carries.
430
- * - `problem` is a build issue shown to the user, and the only kind rendered as a problem.
431
- * - `performance` records a plugin's elapsed time.
432
- * - `update` is a version notice.
433
- */
434
- type DiagnosticKind = 'problem' | 'performance' | 'update';
435
- /**
436
- * Codes that describe a build problem: every {@link DiagnosticCode} except the
437
- * `performance` and `updateAvailable` codes, which ride on their own variants.
438
- */
439
- type ProblemCode = Exclude<DiagnosticCode, typeof diagnosticCode.performance | typeof diagnosticCode.updateAvailable>;
440
- /**
441
- * A build problem collected during a run, gathered into the result instead of
442
- * aborting on the first failure.
443
- */
444
- type ProblemDiagnostic = {
445
- /**
446
- * @default 'problem'
447
- */
448
- kind?: 'problem';
449
- /**
450
- * Stable identifier for the problem, from the {@link diagnosticCode} catalog.
451
- */
452
- code: ProblemCode;
453
- severity: DiagnosticSeverity;
454
- message: string;
455
- location?: DiagnosticLocation;
456
- /**
457
- * A suggested fix, phrased as an action the user can take.
458
- */
459
- help?: string;
460
- /**
461
- * Name of the plugin or subsystem that produced the diagnostic.
462
- */
463
- plugin?: string;
464
- /** Issue tracker URL of the extension that crashed, from its `meta.issues`. */
465
- issues?: string;
466
- /**
467
- * The underlying error, when the diagnostic wraps a thrown one.
468
- */
469
- cause?: Error;
470
- };
471
- /**
472
- * A per-plugin performance record, built with {@link Diagnostics.performance}. The `performance`
473
- * kind keeps it out of the problem list. It feeds the per-plugin timing bars, and reporters sum
474
- * these into the run total.
475
- */
476
- type PerformanceDiagnostic = {
477
- kind: 'performance';
478
- code: typeof diagnosticCode.performance;
479
- severity: 'info';
480
- message: string;
481
- /**
482
- * The plugin this measurement belongs to.
483
- */
484
- plugin: string;
485
- /**
486
- * Elapsed milliseconds.
487
- */
488
- duration: number;
489
- };
490
- /**
491
- * A notice that a newer Kubb version is available on npm, built with {@link Diagnostics.update}.
492
- * It renders like any info diagnostic.
493
- */
494
- type UpdateDiagnostic = {
495
- kind: 'update';
496
- code: typeof diagnosticCode.updateAvailable;
497
- severity: 'info';
498
- message: string;
499
- /**
500
- * The running Kubb version.
501
- */
502
- currentVersion: string;
503
- /**
504
- * The newest version published on npm.
505
- */
506
- latestVersion: string;
507
- };
508
- /**
509
- * A structured record collected during a build, discriminated on `kind`: a
510
- * {@link ProblemDiagnostic} for an issue, a {@link PerformanceDiagnostic} for a per-plugin
511
- * timing, or an {@link UpdateDiagnostic} for a version notice.
512
- */
513
- type Diagnostic = ProblemDiagnostic | PerformanceDiagnostic | UpdateDiagnostic;
514
- /**
515
- * A {@link Diagnostic} reduced to its JSON-safe fields plus a `docsUrl`, for
516
- * machine-readable output (the `--reporter json` report, the MCP tools). Drops the
517
- * non-serializable `cause` and the `kind`/`duration` bookkeeping.
518
- */
519
- type SerializedDiagnostic = {
520
- code: DiagnosticCode;
521
- severity: DiagnosticSeverity;
522
- message: string;
523
- location?: DiagnosticLocation;
524
- help?: string;
525
- plugin?: string;
526
- issues?: string;
527
- /**
528
- * The kubb.dev docs link for the code, omitted for the unknown fallback.
529
- */
530
- docsUrl?: string;
531
- };
532
- /**
533
- * Static helpers for working with {@link Diagnostic}s, plus the run-scoped sink
534
- * that lets deep code report a diagnostic without threading a callback.
535
- *
536
- * The sink lives in a single `AsyncLocalStorage` in the `@kubb/core` bundle.
537
- * `Diagnostics.scope` activates it for a run, so anything inside that run (the
538
- * adapter parse, a generator) reports through `Diagnostics.report` and lands
539
- * in the same run.
540
- */
541
- declare class Diagnostics {
542
- #private;
543
- /**
544
- * The diagnostic code catalog, exposed as `Diagnostics.code` (e.g. `Diagnostics.code.refNotFound`).
545
- */
546
- static code: {
547
- readonly unknown: "KUBB_UNKNOWN";
548
- readonly inputNotFound: "KUBB_INPUT_NOT_FOUND";
549
- readonly inputRequestFailed: "KUBB_INPUT_REQUEST_FAILED";
550
- readonly inputUnreachable: "KUBB_INPUT_UNREACHABLE";
551
- readonly inputRequired: "KUBB_INPUT_REQUIRED";
552
- readonly legacyInput: "KUBB_LEGACY_INPUT";
553
- readonly invalidDocument: "KUBB_INVALID_DOCUMENT";
554
- readonly invalidSpec: "KUBB_INVALID_SPEC";
555
- readonly refNotFound: "KUBB_REF_NOT_FOUND";
556
- readonly invalidServerVariable: "KUBB_INVALID_SERVER_VARIABLE";
557
- readonly pluginNotFound: "KUBB_PLUGIN_NOT_FOUND";
558
- readonly incompatibleExtension: "KUBB_INCOMPATIBLE_EXTENSION";
559
- readonly missingDependency: "KUBB_MISSING_DEPENDENCY";
560
- readonly incompatibleDependency: "KUBB_INCOMPATIBLE_DEPENDENCY";
561
- readonly pluginFailed: "KUBB_PLUGIN_FAILED";
562
- readonly adapterFailed: "KUBB_ADAPTER_FAILED";
563
- readonly parserFailed: "KUBB_PARSER_FAILED";
564
- readonly pluginWarning: "KUBB_PLUGIN_WARNING";
565
- readonly pluginInfo: "KUBB_PLUGIN_INFO";
566
- readonly noContext: "KUBB_NO_CONTEXT";
567
- readonly unsupportedFormat: "KUBB_UNSUPPORTED_FORMAT";
568
- readonly deprecated: "KUBB_DEPRECATED";
569
- readonly adapterRequired: "KUBB_ADAPTER_REQUIRED";
570
- readonly pathTraversal: "KUBB_PATH_TRAVERSAL";
571
- readonly cleanRoot: "KUBB_CLEAN_ROOT";
572
- readonly invalidPluginOptions: "KUBB_INVALID_PLUGIN_OPTIONS";
573
- readonly postGenerateFailed: "KUBB_POST_GENERATE_FAILED";
574
- readonly formatFailed: "KUBB_FORMAT_FAILED";
575
- readonly lintFailed: "KUBB_LINT_FAILED";
576
- readonly barrelDuplicateExport: "KUBB_BARREL_DUPLICATE_EXPORT";
577
- readonly performance: "KUBB_PERFORMANCE";
578
- readonly updateAvailable: "KUBB_UPDATE_AVAILABLE";
87
+ //#region src/diagnosticCatalog.d.ts
88
+ /**
89
+ * Every diagnostic code with its docs entry: a short title, what triggers it, and how to resolve
90
+ * it. The source of truth for {@link diagnosticCode}, and the kubb.dev `/reference/diagnostics`
91
+ * sections mirror it.
92
+ */
93
+ declare const diagnosticCatalog: {
94
+ readonly unknown: {
95
+ readonly code: "KUBB_UNKNOWN";
96
+ readonly title: "Unknown error";
97
+ readonly cause: "An error was thrown without a stable Kubb code, so it is reported as-is.";
98
+ readonly fix: "Read the underlying message and stack. If it comes from a plugin or adapter, check its configuration; otherwise report it as a possible Kubb bug.";
579
99
  };
580
- /**
581
- * Type guard for a build {@link ProblemDiagnostic}.
582
- */
583
- static isProblem: (diagnostic: Diagnostic) => diagnostic is ProblemDiagnostic;
584
- /**
585
- * Type guard for a version-update {@link UpdateDiagnostic}.
586
- */
587
- static isUpdate: (diagnostic: Diagnostic) => diagnostic is UpdateDiagnostic;
588
- /**
589
- * Type guard for a per-plugin {@link PerformanceDiagnostic}.
590
- */
591
- static isPerformance: (diagnostic: Diagnostic) => diagnostic is PerformanceDiagnostic;
592
- /**
593
- * An `Error` that carries a {@link Diagnostic}, so structured problems can flow
594
- * through the existing throw/catch paths while keeping their code and location.
595
- *
596
- * @example
597
- * ```ts
598
- * throw new Diagnostics.Error({ code: diagnosticCode.refNotFound, severity: 'error', message: `Could not find ${ref}`, location: { kind: 'schema', pointer: ref, ref } })
599
- * ```
600
- */
601
- static Error: {
602
- new (diagnostic: ProblemDiagnostic): {
603
- diagnostic: ProblemDiagnostic;
604
- name: string;
605
- message: string;
606
- stack?: string;
607
- cause?: unknown;
608
- };
609
- isError(error: unknown): error is Error;
610
- isError(value: unknown): value is Error;
611
- captureStackTrace(targetObject: object, constructorOpt?: Function): void;
612
- captureStackTrace(targetObject: object, constructorOpt?: Function): void;
613
- prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
614
- stackTraceLimit: number;
100
+ readonly inputNotFound: {
101
+ readonly code: "KUBB_INPUT_NOT_FOUND";
102
+ readonly title: "Input not found";
103
+ readonly cause: "The file set as `input` (or passed as `kubb generate PATH`) could not be read. A URL reports `KUBB_INPUT_REQUEST_FAILED` or `KUBB_INPUT_UNREACHABLE` instead.";
104
+ readonly fix: "Check that the path exists and is readable, then set it as `input` or pass it on the CLI.";
105
+ };
106
+ readonly inputRequestFailed: {
107
+ readonly code: "KUBB_INPUT_REQUEST_FAILED";
108
+ readonly title: "Input request failed";
109
+ readonly cause: "A URL set as `input` (or reached through a `$ref`) answered with a 4xx or 5xx status instead of the document.";
110
+ readonly fix: "Open the URL to see what the server returns. A 401 or 403 needs credentials Kubb does not send, so download the document and point `input` at the local file. A 404 means the path is wrong, and a 5xx means the server itself failed.";
111
+ };
112
+ readonly inputUnreachable: {
113
+ readonly code: "KUBB_INPUT_UNREACHABLE";
114
+ readonly title: "Input unreachable";
115
+ readonly cause: "A URL set as `input` (or reached through a `$ref`) never answered, so the request failed before a status came back. A refused connection, an unknown host, an expired certificate, and a timeout all land here.";
116
+ readonly fix: "Check that the host is running and reachable from this machine. For a local server, start it and confirm the port matches the one in `input`.";
117
+ };
118
+ readonly inputRequired: {
119
+ readonly code: "KUBB_INPUT_REQUIRED";
120
+ readonly title: "Input required";
121
+ readonly cause: "An adapter is configured but no `input` was provided.";
122
+ readonly fix: "Set `input` to a file path, a URL, an inline spec (JSON/YAML string), or a parsed object in your Kubb config.";
123
+ };
124
+ readonly legacyInput: {
125
+ readonly code: "KUBB_LEGACY_INPUT";
126
+ readonly title: "Legacy input shape";
127
+ readonly cause: "`input` is a `{ path }` or `{ data }` wrapper, which v4 used to point at a document and v5 reads as the document itself.";
128
+ readonly fix: "Unwrap it: `input: { path: \"./petStore.yaml\" }` becomes `input: \"./petStore.yaml\"`, and `input: { data: spec }` becomes `input: spec`.";
129
+ };
130
+ readonly invalidDocument: {
131
+ readonly code: "KUBB_INVALID_DOCUMENT";
132
+ readonly title: "Invalid document";
133
+ readonly cause: "The `input` cannot be read as an OpenAPI or Swagger document: its JSON or YAML has a syntax error, it declares no `openapi` or `swagger` version field, or its version cannot be upgraded to OpenAPI 3.1.";
134
+ readonly fix: "Fix the syntax at the reported line, and check that `input` points at the spec and not an HTML page. Point `input` at a Swagger 2.0, OpenAPI 3.0, or OpenAPI 3.1 document, and check that a passed object is the spec itself rather than a wrapper around it.";
135
+ };
136
+ readonly invalidSpec: {
137
+ readonly code: "KUBB_INVALID_SPEC";
138
+ readonly title: "Invalid spec";
139
+ readonly cause: "The document does not pass OpenAPI schema validation. Kubb still generates from it, but the output can be incomplete or wrong.";
140
+ readonly fix: "Fix the reported problem in the spec. Run `kubb validate` to list every error, or set `validate: false` on the adapter to skip the check.";
141
+ };
142
+ readonly refNotFound: {
143
+ readonly code: "KUBB_REF_NOT_FOUND";
144
+ readonly title: "Reference not found";
145
+ readonly cause: "A `$ref` could not be resolved in the source document.";
146
+ readonly fix: "Add the missing definition (for example under `components.schemas`) or fix the `$ref`. Run `kubb validate` to check the spec.";
147
+ };
148
+ readonly invalidServerVariable: {
149
+ readonly code: "KUBB_INVALID_SERVER_VARIABLE";
150
+ readonly title: "Invalid server variable";
151
+ readonly cause: "A server variable value is not allowed by its `enum`.";
152
+ readonly fix: "Use one of the values listed in the server variable `enum`, or update the spec.";
153
+ };
154
+ readonly pluginNotFound: {
155
+ readonly code: "KUBB_PLUGIN_NOT_FOUND";
156
+ readonly title: "Plugin not found";
157
+ readonly cause: "A plugin that another plugin depends on is missing from the config.";
158
+ readonly fix: "Add the required plugin to the `plugins` array in kubb.config.ts, or remove the dependency on it.";
159
+ };
160
+ readonly incompatibleExtension: {
161
+ readonly code: "KUBB_INCOMPATIBLE_EXTENSION";
162
+ readonly title: "Incompatible extension";
163
+ readonly cause: "A plugin sets `meta.compatibility.kubb` or `meta.compatibility.node` to a range the running Kubb or Node.js version does not satisfy.";
164
+ readonly fix: "Upgrade Kubb or Node.js to a version in the range, or install a version of the plugin that supports your current Kubb and Node.js.";
165
+ };
166
+ readonly missingDependency: {
167
+ readonly code: "KUBB_MISSING_DEPENDENCY";
168
+ readonly title: "Missing dependency";
169
+ readonly cause: "A plugin lists another plugin in its `dependencies` record without `optional: true`, and the config does not include it.";
170
+ readonly fix: "Add the missing plugin to the `plugins` array in kubb.config.ts.";
171
+ };
172
+ readonly incompatibleDependency: {
173
+ readonly code: "KUBB_INCOMPATIBLE_DEPENDENCY";
174
+ readonly title: "Incompatible dependency";
175
+ readonly cause: "A plugin's `dependencies` record sets a `version` range, and the configured plugin's `meta.version` falls outside it.";
176
+ readonly fix: "Install a version of the dependency inside the range, or a version of the dependent plugin that supports the installed dependency.";
177
+ };
178
+ readonly pluginFailed: {
179
+ readonly code: "KUBB_PLUGIN_FAILED";
180
+ readonly title: "Plugin failed";
181
+ readonly cause: "A plugin threw while generating, or reported an error through `ctx.error`.";
182
+ readonly fix: "Check the plugin options and the node at `at:`. If it is a bug, report it with the stack at `report:`.";
183
+ };
184
+ readonly adapterFailed: {
185
+ readonly code: "KUBB_ADAPTER_FAILED";
186
+ readonly title: "Adapter failed";
187
+ readonly cause: "The adapter threw an unexpected error while parsing the input.";
188
+ readonly fix: "Check the input and the adapter options. If it is a bug, report it with the stack at `report:`.";
189
+ };
190
+ readonly parserFailed: {
191
+ readonly code: "KUBB_PARSER_FAILED";
192
+ readonly title: "Parser failed";
193
+ readonly cause: "A parser threw an unexpected error while printing a generated file.";
194
+ readonly fix: "Check the parser options. If it is a bug, report it with the stack at `report:`.";
195
+ };
196
+ readonly pluginWarning: {
197
+ readonly code: "KUBB_PLUGIN_WARNING";
198
+ readonly title: "Plugin warning";
199
+ readonly cause: "A plugin reported a non-fatal warning through `ctx.warn`.";
200
+ readonly fix: "Review the message. It does not fail the build; adjust the plugin options or input if the warning is unwanted.";
201
+ };
202
+ readonly pluginInfo: {
203
+ readonly code: "KUBB_PLUGIN_INFO";
204
+ readonly title: "Plugin info";
205
+ readonly cause: "A plugin reported an informational message through `ctx.info`.";
206
+ readonly fix: "Informational only. No action is required.";
207
+ };
208
+ readonly noContext: {
209
+ readonly code: "KUBB_NO_CONTEXT";
210
+ readonly title: "No plugin context";
211
+ readonly cause: "A `kubb/kit` composable such as `useKubb()` or `addGenerator()` ran outside the `setup` and `kubb:plugin:setup` of a plugin, so there is no plugin to apply it to.";
212
+ readonly fix: "Call the composable inside `setup` or `kubb:plugin:setup`, including in code that setup awaits.";
213
+ };
214
+ readonly unsupportedFormat: {
215
+ readonly code: "KUBB_UNSUPPORTED_FORMAT";
216
+ readonly title: "Unsupported format";
217
+ readonly cause: "A schema uses a `format` Kubb does not map to a specific type, so it falls back to the base type.";
218
+ readonly fix: "Use a format Kubb supports, or handle the custom format with a parser or plugin.";
219
+ };
220
+ readonly deprecated: {
221
+ readonly code: "KUBB_DEPRECATED";
222
+ readonly title: "Deprecated";
223
+ readonly cause: "A referenced schema or operation is marked `deprecated`.";
224
+ readonly fix: "Migrate off the deprecated definition if the warning is unwanted.";
225
+ };
226
+ readonly adapterRequired: {
227
+ readonly code: "KUBB_ADAPTER_REQUIRED";
228
+ readonly title: "Adapter required";
229
+ readonly cause: "An action needs an adapter but none is configured.";
230
+ readonly fix: "Set `adapter` in kubb.config.ts, for example `adapterOas()`.";
231
+ };
232
+ readonly pathTraversal: {
233
+ readonly code: "KUBB_PATH_TRAVERSAL";
234
+ readonly title: "Path traversal";
235
+ readonly cause: "A resolved output path escaped the output directory, which can stem from a path traversal in the spec or a misconfigured `group.name`.";
236
+ readonly fix: "Keep generated paths within the output directory. Review the `group.name` function and the names coming from the spec.";
237
+ };
238
+ readonly cleanRoot: {
239
+ readonly code: "KUBB_CLEAN_ROOT";
240
+ readonly title: "Clean targets the project root";
241
+ readonly cause: "`output.clean` is enabled and `output.path` resolves to the project root or a parent of it, so cleaning would delete `kubb.config` and every source file.";
242
+ readonly fix: "Point `output.path` at a subdirectory such as `./src/gen` so clean only removes generated code, or disable `output.clean`.";
243
+ };
244
+ readonly invalidPluginOptions: {
245
+ readonly code: "KUBB_INVALID_PLUGIN_OPTIONS";
246
+ readonly title: "Invalid plugin options";
247
+ readonly cause: "A plugin was configured with options that cannot be honored, for example `output.mode: 'file'` paired with a `group` option.";
248
+ readonly fix: "Fix the plugin options. A single-file output has nothing to group, so remove the `group` option or use `output.mode: 'directory'`.";
249
+ };
250
+ readonly postGenerateFailed: {
251
+ readonly code: "KUBB_POST_GENERATE_FAILED";
252
+ readonly title: "Post-generate command failed";
253
+ readonly cause: "A post-generate command (`output.postGenerate`) exited with a non-zero status.";
254
+ readonly fix: "Check the command is installed and correct, and run it manually to see the error.";
255
+ };
256
+ readonly formatFailed: {
257
+ readonly code: "KUBB_FORMAT_FAILED";
258
+ readonly title: "Format failed";
259
+ readonly cause: "The formatter pass over the generated files failed.";
260
+ readonly fix: "Check the formatter (oxfmt, biome, or prettier) is installed and its config is valid, then run it manually on the output.";
261
+ };
262
+ readonly lintFailed: {
263
+ readonly code: "KUBB_LINT_FAILED";
264
+ readonly title: "Lint failed";
265
+ readonly cause: "The linter pass over the generated files failed.";
266
+ readonly fix: "Check the linter (oxlint, biome, or eslint) is installed and its config is valid, then run it manually on the output.";
615
267
  };
268
+ readonly barrelDuplicateExport: {
269
+ readonly code: "KUBB_BARREL_DUPLICATE_EXPORT";
270
+ readonly title: "Duplicate barrel export";
271
+ readonly cause: "Two generated modules export the same name, so the barrel cannot re-export both.";
272
+ readonly fix: "Rename one of the colliding declarations, or configure the plugin resolver to produce distinct names.";
273
+ };
274
+ readonly internalError: {
275
+ readonly code: "KUBB_INTERNAL_ERROR";
276
+ readonly title: "Internal error";
277
+ readonly cause: "Kubb hit a state it does not expect. This is a bug in Kubb, not in your config.";
278
+ readonly fix: "Rerun with `--reporter json` or `--verbose` to get the stack. Then report it at https://github.com/kubb-labs/kubb/issues with the spec and config that trigger it.";
279
+ };
280
+ readonly performance: {
281
+ readonly code: "KUBB_PERFORMANCE";
282
+ readonly title: "Performance";
283
+ readonly cause: "Not a failure. Records a plugin’s elapsed time, summed into the run total.";
284
+ readonly fix: "No action. This is an informational metric.";
285
+ };
286
+ readonly updateAvailable: {
287
+ readonly code: "KUBB_UPDATE_AVAILABLE";
288
+ readonly title: "Update available";
289
+ readonly cause: "A newer Kubb version is published on npm than the one running.";
290
+ readonly fix: "Update the `@kubb/*` packages, for example `npm install -g @kubb/cli`, to get the latest fixes.";
291
+ };
292
+ };
293
+ /**
294
+ * Stable codes Kubb attaches to a `Diagnostic`, derived from {@link diagnosticCatalog}. Reference
295
+ * these instead of inlining the string at a throw site.
296
+ */
297
+ declare const diagnosticCode: { readonly [K in keyof typeof diagnosticCatalog]: (typeof diagnosticCatalog)[K]["code"]; };
298
+ /**
299
+ * Union of the stable {@link diagnosticCode} values.
300
+ */
301
+ type DiagnosticCode = (typeof diagnosticCode)[keyof typeof diagnosticCode];
302
+ //#endregion
303
+ //#region src/formatDiagnostic.d.ts
304
+ /**
305
+ * How {@link format} renders a diagnostic.
306
+ */
307
+ type DiagnosticFormatOptions = {
616
308
  /**
617
- * Structural check for a {@link Diagnostics.Error}, including one thrown from a duplicated
618
- * `@kubb/core` copy where `instanceof` fails. Matches on the `name` and a `diagnostic`
619
- * that carries a `code`.
620
- */
621
- static isError(error: unknown): error is InstanceType<typeof Diagnostics.Error>;
622
- /**
623
- * Runs `fn` with `sink` as the active diagnostic sink for the whole async
624
- * subtree, so {@link Diagnostics.report} reaches it from anywhere inside.
625
- */
626
- static scope<T>(sink: (diagnostic: Diagnostic) => void, fn: () => T): T;
627
- /**
628
- * Collects a diagnostic into the active build via the run-scoped sink, without throwing.
629
- * Returns `true` when a run consumed it, `false` when called outside a {@link Diagnostics.scope}
630
- * (so callers can fall back to throwing). Use a `warning`/`info` severity for non-fatal issues.
631
- * For rendering a diagnostic live on the hook bus, use {@link Diagnostics.emit} instead.
632
- */
633
- static report(diagnostic: Diagnostic): boolean;
634
- /**
635
- * Emits a diagnostic on the run's `kubb:diagnostic` hook so the loggers render it live.
636
- * Use it instead of calling `hooks.callHook('kubb:diagnostic', ...)` directly. To collect a
637
- * diagnostic into the build result from deep in a run, use {@link Diagnostics.report} instead.
638
- */
639
- static emit(hooks: Hookable<KubbHooks>, diagnostic: ProblemDiagnostic | UpdateDiagnostic): Promise<void>;
640
- /**
641
- * Coerces any thrown value into a {@link ProblemDiagnostic}. A {@link Diagnostics.Error}
642
- * keeps its structured data, and anything else becomes a `KUBB_UNKNOWN` error.
643
- */
644
- static from(error: unknown): ProblemDiagnostic;
645
- /**
646
- * Coerces an error thrown by a plugin, adapter, or parser into a diagnostic attributed to it.
647
- * A structured {@link Diagnostics.Error} keeps its code. Any other error is a crash: it gets the
648
- * kind's `*_FAILED` code and the extension's `meta.issues` link, so the user reports it to the
649
- * extension's maintainers instead of to Kubb.
650
- */
651
- static fromExtension(error: unknown, { kind, extension }: {
652
- kind: ExtensionKind;
653
- extension: ExtensionNamed;
654
- }): ProblemDiagnostic;
655
- /**
656
- * Builds a per-plugin performance record. Reporters sum these into the run total.
657
- */
658
- static performance({ plugin, duration }: {
659
- plugin: string;
660
- duration: number;
661
- }): PerformanceDiagnostic;
662
- /**
663
- * Builds the version-update notice shown when a newer Kubb is published on npm.
664
- */
665
- static update({ currentVersion, latestVersion }: {
666
- currentVersion: string;
667
- latestVersion: string;
668
- }): UpdateDiagnostic;
669
- /**
670
- * True when any diagnostic is an error, the severity that fails a build. Non-error
671
- * diagnostics are ignored.
309
+ * Who reads the output.
310
+ * - `'agent'` spells out every detail on labeled rows
311
+ * - `'human'` keeps it short and links to the docs
312
+ * @default 'agent'
672
313
  */
673
- static hasError(diagnostics: ReadonlyArray<Diagnostic>): boolean;
314
+ audience?: 'agent' | 'human';
674
315
  /**
675
- * Names of the plugins that failed, deduped, derived from the error diagnostics
676
- * that carry a `plugin`.
316
+ * Show the root cause's full stack.
677
317
  */
678
- static failedPlugins(diagnostics: ReadonlyArray<Diagnostic>): Array<string>;
318
+ verbose?: boolean;
679
319
  /**
680
- * Counts `problem` diagnostics by severity for the run summary. `performance` and
681
- * `update` diagnostics are ignored.
320
+ * Columns the `human` headline fills, so the code lines up at the right edge.
321
+ * @default 0
682
322
  */
683
- static count(diagnostics: ReadonlyArray<Diagnostic>): {
684
- errors: number;
685
- warnings: number;
686
- infos: number;
687
- };
323
+ width?: number;
324
+ };
325
+ /**
326
+ * A {@link Diagnostic} reduced to its JSON-safe fields plus a `docsUrl`, for
327
+ * machine-readable output (the `--reporter json` report, the MCP tools). Replaces the
328
+ * non-serializable `cause` with its message chain and drops the `kind`/`duration` bookkeeping.
329
+ */
330
+ type SerializedDiagnostic = {
331
+ code: DiagnosticCode;
332
+ severity: DiagnosticSeverity;
333
+ message: string;
688
334
  /**
689
- * Drops duplicate `problem` diagnostics that share a code, location pointer, and
690
- * plugin, so the same issue reported across several passes is shown once. Non-problem
691
- * diagnostics are always kept.
335
+ * Catalog title.
692
336
  */
693
- static dedupe(diagnostics: ReadonlyArray<Diagnostic>): Array<Diagnostic>;
337
+ title?: string;
694
338
  /**
695
- * Builds the kubb.dev docs URL for a diagnostic code, e.g.
696
- * `KUBB_REF_NOT_FOUND` → `https://kubb.dev/docs/5.x/reference/diagnostics#kubb-ref-not-found`.
339
+ * Catalog cause.
697
340
  */
698
- static docsUrl(code: string): string;
341
+ cause?: string;
342
+ location?: DiagnosticLocation;
699
343
  /**
700
- * The catalog entry for a code: its title, cause, and fix. Mirrors the kubb.dev
701
- * `/reference/diagnostics#<slug>` section.
344
+ * The diagnostic's `help`, or the catalog fix.
702
345
  */
703
- static explain(code: DiagnosticCode): DiagnosticDoc;
346
+ help?: string;
347
+ plugin?: string;
348
+ issues?: string;
704
349
  /**
705
- * Reduces a diagnostic to its JSON-safe fields plus a `docsUrl`, for machine-readable
706
- * consumers. The `cause`, `kind`, and `duration` are dropped, and absent optional
707
- * fields are omitted rather than set to `undefined`.
350
+ * Messages of the underlying errors, outermost first.
708
351
  */
709
- static serialize(diagnostic: Diagnostic): SerializedDiagnostic;
352
+ causes?: Array<string>;
710
353
  /**
711
- * Renders a {@link Diagnostic} for terminal output as its parts: the `headline`
712
- * (`[CODE] plugin: message`, with the code in the severity color) and the indented `details`
713
- * rows (`at:` pointer, `fix:` help, `see:` docs link, `report:` issue tracker).
714
- *
715
- * Hosts compose these to fit their gutter: a clack logger passes `[headline, ...details]` as the
716
- * message with no gutter symbol, while plain text outputs use {@link Diagnostics.formatLines}.
354
+ * Root cause's stack, for `KUBB_UNKNOWN`, `KUBB_INTERNAL_ERROR`, and `*_FAILED` codes.
717
355
  */
718
- static format(diagnostic: Diagnostic): {
719
- headline: string;
720
- details: Array<string>;
721
- };
356
+ stack?: string;
722
357
  /**
723
- * The self-contained block form of {@link Diagnostics.format}: the `headline` followed by the
724
- * indented detail rows. Used where there is no gutter (plain and file output).
358
+ * The kubb.dev docs link for the code, omitted for the unknown fallback.
725
359
  */
726
- static formatLines(diagnostic: Diagnostic): Array<string>;
727
- }
360
+ docsUrl?: string;
361
+ };
362
+ /**
363
+ * Reduces a diagnostic to its JSON-safe fields plus a `docsUrl`, for machine-readable
364
+ * consumers, with the catalog `title`, `cause`, and fix, and the `cause` error as `causes` and
365
+ * `stack`. Absent optional fields are omitted.
366
+ */
367
+ declare function serialize(diagnostic: Diagnostic): SerializedDiagnostic;
368
+ /**
369
+ * Renders a {@link Diagnostic} as lines: a headline, then indented detail rows. `agent` (the default)
370
+ * prints uncolored labeled rows (`at:`, `why:`, `fix:`, `caused by:`, `stack:` for a crash,
371
+ * `docs:`, `report:`). `human` prints an icon, the bold message, and the code aligned to `width`,
372
+ * with `at`, `fix`, the first cause, and `Learn more` for an error, and one row for a warning.
373
+ * `verbose` adds the full stack.
374
+ */
375
+ declare function format(diagnostic: Diagnostic, { audience, verbose, width }?: DiagnosticFormatOptions): Array<string>;
728
376
  //#endregion
729
377
  //#region src/createReporter.d.ts
730
378
  /**
@@ -934,6 +582,68 @@ type Storage = {
934
582
  */
935
583
  declare const createStorage: <TOptions = Record<string, never>>(build: (options: TOptions) => Storage) => (options?: TOptions) => Storage;
936
584
  //#endregion
585
+ //#region src/createRenderer.d.ts
586
+ /**
587
+ * Minimal interface any Kubb renderer must satisfy.
588
+ *
589
+ * `TElement` is the type the renderer accepts, for example `KubbReactElement`
590
+ * for `@kubb/renderer-jsx` or a custom type for your own renderer. Defaults to
591
+ * `unknown` so generators that don't care about the element type work without
592
+ * specifying it.
593
+ */
594
+ type Renderer<TElement = unknown> = {
595
+ /**
596
+ * Renders `element` and populates {@link files} with the resulting {@link FileNode} objects.
597
+ * Called once per render cycle. Must resolve before {@link files} is read.
598
+ */
599
+ render(element: TElement): Promise<void>;
600
+ /**
601
+ * Accumulated {@link FileNode} results produced by the last {@link render} call.
602
+ */
603
+ readonly files: Array<FileNode>;
604
+ /**
605
+ * Disposer hook so renderers participate in `using` blocks: `using r = rendererFactory()`
606
+ * runs cleanup on every exit path, including thrown errors.
607
+ */
608
+ [Symbol.dispose](): void;
609
+ };
610
+ /**
611
+ * A factory function that produces a fresh {@link Renderer} per render cycle.
612
+ *
613
+ * Generators use this to declare which renderer handles their output.
614
+ */
615
+ type RendererFactory<TElement = unknown> = () => Renderer<TElement>;
616
+ /**
617
+ * Defines a renderer factory. Renderers turn the generator's return value
618
+ * (JSX, a template string, a tree of any shape) into `FileNode`s that get
619
+ * written to disk.
620
+ *
621
+ * A renderer can target output formats beyond JSX, for instance a Handlebars
622
+ * renderer or one that writes binary files. Plugins and generators pick the
623
+ * renderer to use via the `renderer` field on `defineGenerator`.
624
+ *
625
+ * @example A minimal renderer that wraps a custom runtime
626
+ * ```ts
627
+ * import { createRenderer } from '@kubb/core'
628
+ *
629
+ * export const myRenderer = createRenderer(() => {
630
+ * const runtime = new MyRuntime()
631
+ * return {
632
+ * async render(element) {
633
+ * await runtime.render(element)
634
+ * },
635
+ * get files() {
636
+ * return runtime.files
637
+ * },
638
+ * [Symbol.dispose]() {
639
+ * runtime.dispose()
640
+ * },
641
+ * }
642
+ * })
643
+ * ```
644
+ */
645
+ declare function createRenderer<TElement = unknown>(factory: RendererFactory<TElement>): RendererFactory<TElement>;
646
+ //#endregion
937
647
  //#region src/outputManifest.d.ts
938
648
  /**
939
649
  * Remembers what the output passes did to each generated file, so the next run can tell "the
@@ -967,6 +677,91 @@ type OutputManifest = {
967
677
  commit(): Promise<void>;
968
678
  };
969
679
  //#endregion
680
+ //#region src/Hookable.d.ts
681
+ /**
682
+ * A function that can be registered as a hook listener, synchronous or async. Any return value is
683
+ * allowed and ignored, so handlers that return a result for their own callers still register.
684
+ */
685
+ type AsyncListener<TArgs extends Array<unknown>> = (...args: TArgs) => unknown;
686
+ /**
687
+ * Typed hook emitter that awaits all async listeners before resolving.
688
+ *
689
+ * @example
690
+ * ```ts
691
+ * const hooks = new Hookable<{ build: [name: string] }>()
692
+ * hooks.hook('build', async (name) => { console.log(name) })
693
+ * await hooks.callHook('build', 'petstore') // all listeners awaited
694
+ * ```
695
+ */
696
+ declare class Hookable<THooks extends { [K in keyof THooks]: Array<unknown>; }> {
697
+ #private;
698
+ /**
699
+ * Calls `hookName` and awaits all registered listeners sequentially.
700
+ * Throws if any listener rejects, wrapping the cause in an error that names the hook.
701
+ *
702
+ * @example
703
+ * ```ts
704
+ * await hooks.callHook('build', 'petstore')
705
+ * ```
706
+ */
707
+ callHook<THookName extends keyof THooks & string>(hookName: THookName, ...hookArgs: THooks[THookName]): Promise<void> | void;
708
+ /**
709
+ * Registers a persistent listener for `hookName` and returns a function that removes it.
710
+ *
711
+ * @example
712
+ * ```ts
713
+ * const unhook = hooks.hook('build', async (name) => { console.log(name) })
714
+ * unhook() // removes it
715
+ * ```
716
+ */
717
+ hook<THookName extends keyof THooks & string>(hookName: THookName, handler: AsyncListener<THooks[THookName]>): () => void;
718
+ /**
719
+ * Registers every handler in `configHooks` at once and returns a function that removes them
720
+ * all. Undefined entries are skipped, so a partial hook object registers only its present keys.
721
+ *
722
+ * @example
723
+ * ```ts
724
+ * const unhook = hooks.addHooks({ build: onBuild, done: onDone })
725
+ * unhook() // removes both
726
+ * ```
727
+ */
728
+ addHooks(configHooks: Partial<{ [K in keyof THooks & string]: AsyncListener<THooks[K]>; }>): () => void;
729
+ /**
730
+ * Removes a previously registered listener.
731
+ *
732
+ * @example
733
+ * ```ts
734
+ * hooks.removeHook('build', handler)
735
+ * ```
736
+ */
737
+ removeHook<THookName extends keyof THooks & string>(hookName: THookName, handler: AsyncListener<THooks[THookName]>): void;
738
+ /**
739
+ * Returns the number of listeners registered for `hookName`.
740
+ *
741
+ * @example
742
+ * ```ts
743
+ * hooks.hook('build', handler)
744
+ * hooks.listenerCount('build') // 1
745
+ * ```
746
+ */
747
+ listenerCount<THookName extends keyof THooks & string>(hookName: THookName): number;
748
+ /**
749
+ * No-op kept for callers written against the `EventEmitter`-backed version. Listeners are unbounded.
750
+ *
751
+ * @deprecated There is no listener ceiling anymore.
752
+ */
753
+ setMaxListeners(_max: number): void;
754
+ /**
755
+ * Removes all listeners from every hook channel.
756
+ *
757
+ * @example
758
+ * ```ts
759
+ * hooks.removeAllHooks()
760
+ * ```
761
+ */
762
+ removeAllHooks(): void;
763
+ }
764
+ //#endregion
970
765
  //#region src/FileManager.d.ts
971
766
  type ParseOptions = {
972
767
  parsers?: Map<FileNode['extname'], Parser>;
@@ -1672,155 +1467,477 @@ type KubbErrorContext = {
1672
1467
  /**
1673
1468
  * Optional structured metadata for additional context.
1674
1469
  */
1675
- meta?: Record<string, unknown>;
1676
- };
1677
- type KubbDiagnosticContext = {
1470
+ meta?: Record<string, unknown>;
1471
+ };
1472
+ type KubbDiagnosticContext = {
1473
+ /**
1474
+ * The structured diagnostic to render: a build problem or a version-update notice.
1475
+ */
1476
+ diagnostic: ProblemDiagnostic | UpdateDiagnostic;
1477
+ };
1478
+ type KubbGenerationSummaryContext = {
1479
+ duration: number;
1480
+ fileCount: number;
1481
+ failedPlugins: number;
1482
+ status: 'success' | 'failed';
1483
+ };
1484
+ type KubbFilesProcessingStartContext = {
1485
+ /**
1486
+ * Files about to be serialized and written.
1487
+ */
1488
+ files: Array<FileNode>;
1489
+ };
1490
+ type KubbFileProcessingUpdate = {
1491
+ /**
1492
+ * Number of files processed so far in this batch.
1493
+ */
1494
+ processed: number;
1495
+ /**
1496
+ * Total number of files in this batch.
1497
+ */
1498
+ total: number;
1499
+ /**
1500
+ * Completion percentage, `0` to `100`.
1501
+ */
1502
+ percentage: number;
1503
+ /**
1504
+ * The file that was just processed.
1505
+ */
1506
+ file: FileNode;
1507
+ /**
1508
+ * Resolved configuration for this build.
1509
+ */
1510
+ config: Config;
1511
+ };
1512
+ type KubbFilesProcessingUpdateContext = {
1513
+ /**
1514
+ * All files processed in this flush chunk.
1515
+ */
1516
+ files: Array<KubbFileProcessingUpdate>;
1517
+ };
1518
+ type KubbFilesProcessingEndContext = {
1519
+ /**
1520
+ * All files that were serialized in this batch.
1521
+ */
1522
+ files: Array<FileNode>;
1523
+ };
1524
+ type KubbHookStartContext = {
1525
+ /**
1526
+ * Optional identifier for correlating start/end hooks.
1527
+ */
1528
+ id?: string;
1529
+ /**
1530
+ * The shell command that is about to run.
1531
+ */
1532
+ command: string;
1533
+ /**
1534
+ * Optional label for the command, shown in the CLI output when set.
1535
+ */
1536
+ name?: string;
1537
+ /**
1538
+ * Parsed argument list, when available.
1539
+ */
1540
+ args?: ReadonlyArray<string>;
1541
+ };
1542
+ /**
1543
+ * Emitted for each line streamed from a hook's stdout while it runs.
1544
+ * A logger correlates the line to its active UI element via `id`.
1545
+ */
1546
+ type KubbHookLineContext = {
1547
+ /**
1548
+ * Identifier matching the corresponding `kubb:hook:start` hook.
1549
+ */
1550
+ id: string;
1551
+ /**
1552
+ * A single streamed stdout line, without its trailing newline.
1553
+ */
1554
+ line: string;
1555
+ };
1556
+ /** Emitted when a hook subprocess ends: its `kubb:hook:start` context plus the outcome. */
1557
+ type KubbHookEndContext = KubbHookStartContext & HookResult;
1558
+ /**
1559
+ * CLI options derived from command-line flags.
1560
+ */
1561
+ type CLIOptions = {
1562
+ /**
1563
+ * Path to the Kubb config file.
1564
+ */
1565
+ config?: string;
1566
+ /**
1567
+ * OpenAPI input path or URL passed as the positional argument to `kubb generate`.
1568
+ * Overrides `config.input` when set.
1569
+ */
1570
+ input?: string;
1571
+ /**
1572
+ * Re-run generation whenever input files change.
1573
+ */
1574
+ watch?: boolean;
1575
+ /**
1576
+ * Controls how much output the CLI prints.
1577
+ *
1578
+ * @default 'info'
1579
+ */
1580
+ logLevel?: 'silent' | 'info' | 'verbose';
1581
+ /**
1582
+ * Reporters selected on the CLI via `--reporter`, overriding `config.reporters`.
1583
+ */
1584
+ reporters?: Array<ReporterName>;
1585
+ };
1586
+ /**
1587
+ * All accepted forms of a Kubb configuration.
1588
+ * Accepts `Config`/`Config[]`/promise or a factory (optionally receiving `TCliOptions`).
1589
+ */
1590
+ type PossibleConfig<TCliOptions = undefined> = PossiblePromise<Config | Array<Config>> | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Array<Config>>);
1591
+ /**
1592
+ * Full output produced by a successful or failed build.
1593
+ */
1594
+ type BuildOutput = {
1595
+ /**
1596
+ * Structured diagnostics collected during the build: error/warning/info problems
1597
+ * (each with a code, severity, and where known a JSON-pointer location) plus a
1598
+ * `performance` diagnostic per plugin. Includes a top-level diagnostic when the build
1599
+ * threw before completing. Use {@link Diagnostics.hasError} to test for failure.
1600
+ */
1601
+ diagnostics: Array<Diagnostic>;
1602
+ /**
1603
+ * All files generated during this build.
1604
+ */
1605
+ files: Array<FileNode>;
1606
+ /**
1607
+ * The plugin driver that orchestrated this build.
1608
+ */
1609
+ driver: KubbDriver;
1610
+ /**
1611
+ * The configured `Storage` backend, for reading back a generated file's final content.
1612
+ * Use `files` to list what this build produced.
1613
+ *
1614
+ * @example Read a generated file
1615
+ * `const code = await buildOutput.storage.readItem('/src/gen/pet.ts')`
1616
+ */
1617
+ storage: Storage;
1618
+ };
1619
+ //#endregion
1620
+ //#region src/Diagnostics.d.ts
1621
+ /**
1622
+ * How serious a diagnostic is. `error` fails the build, `warning` and `info`
1623
+ * are reported but do not.
1624
+ */
1625
+ type DiagnosticSeverity = 'error' | 'warning' | 'info';
1626
+ /**
1627
+ * A human-readable explanation of a diagnostic code: a short title, what triggers it, and how
1628
+ * to resolve it. This is the source of truth the kubb.dev `/reference/diagnostics#<slug>` sections mirror, so
1629
+ * every code stays documented in one place. Adding a code without documenting it fails the build.
1630
+ */
1631
+ type DiagnosticDoc = {
1632
+ /**
1633
+ * Short title shown as the docs heading.
1634
+ */
1635
+ title: string;
1636
+ /**
1637
+ * What triggers the diagnostic.
1638
+ */
1639
+ cause: string;
1640
+ /**
1641
+ * The action that resolves it.
1642
+ */
1643
+ fix: string;
1644
+ };
1645
+ /**
1646
+ * Points a diagnostic back into the source document. Inputs are parsed into an
1647
+ * object model with no line/column, so locations carry a JSON pointer the adapter
1648
+ * builds (the OAS adapter emits `#/components/schemas/Pet`). A `config` diagnostic
1649
+ * points at the Kubb config itself and so has no pointer.
1650
+ */
1651
+ type DiagnosticLocation = {
1652
+ kind: 'schema';
1653
+ /**
1654
+ * RFC 6901 JSON pointer into the source document.
1655
+ */
1656
+ pointer: string;
1657
+ /**
1658
+ * The original reference when the diagnostic stems from an unresolved one.
1659
+ */
1660
+ ref?: string;
1661
+ } | {
1662
+ kind: 'operation' | 'document';
1663
+ /**
1664
+ * RFC 6901 JSON pointer into the source document.
1665
+ */
1666
+ pointer: string;
1667
+ } | {
1668
+ kind: 'config';
1669
+ };
1670
+ /**
1671
+ * What a diagnostic carries.
1672
+ * - `problem` is a build issue shown to the user, and the only kind rendered as a problem.
1673
+ * - `performance` records a plugin's elapsed time.
1674
+ * - `update` is a version notice.
1675
+ */
1676
+ type DiagnosticKind = 'problem' | 'performance' | 'update';
1677
+ /**
1678
+ * Codes that describe a build problem: every {@link DiagnosticCode} except the
1679
+ * `performance` and `updateAvailable` codes, which ride on their own variants.
1680
+ */
1681
+ type ProblemCode = Exclude<DiagnosticCode, typeof diagnosticCode.performance | typeof diagnosticCode.updateAvailable>;
1682
+ /**
1683
+ * A build problem collected during a run, gathered into the result instead of
1684
+ * aborting on the first failure.
1685
+ */
1686
+ type ProblemDiagnostic = {
1687
+ /**
1688
+ * @default 'problem'
1689
+ */
1690
+ kind?: 'problem';
1691
+ /**
1692
+ * Stable identifier for the problem, from the {@link diagnosticCode} catalog.
1693
+ */
1694
+ code: ProblemCode;
1695
+ severity: DiagnosticSeverity;
1696
+ message: string;
1697
+ location?: DiagnosticLocation;
1698
+ /**
1699
+ * A suggested fix, phrased as an action the user can take.
1700
+ */
1701
+ help?: string;
1702
+ /**
1703
+ * Name of the plugin or subsystem that produced the diagnostic.
1704
+ */
1705
+ plugin?: string;
1706
+ /** Issue tracker URL of the extension that crashed, from its `meta.issues`. */
1707
+ issues?: string;
1708
+ /**
1709
+ * The underlying error, when the diagnostic wraps a thrown one.
1710
+ */
1711
+ cause?: Error;
1712
+ };
1713
+ /**
1714
+ * A per-plugin performance record, built with {@link Diagnostics.performance}. The `performance`
1715
+ * kind keeps it out of the problem list. It feeds the per-plugin timing bars, and reporters sum
1716
+ * these into the run total.
1717
+ */
1718
+ type PerformanceDiagnostic = {
1719
+ kind: 'performance';
1720
+ code: typeof diagnosticCode.performance;
1721
+ severity: 'info';
1722
+ message: string;
1723
+ /**
1724
+ * The plugin this measurement belongs to.
1725
+ */
1726
+ plugin: string;
1678
1727
  /**
1679
- * The structured diagnostic to render: a build problem or a version-update notice.
1728
+ * Elapsed milliseconds.
1680
1729
  */
1681
- diagnostic: ProblemDiagnostic | UpdateDiagnostic;
1682
- };
1683
- type KubbGenerationSummaryContext = {
1684
1730
  duration: number;
1685
- fileCount: number;
1686
- failedPlugins: number;
1687
- status: 'success' | 'failed';
1688
1731
  };
1689
- type KubbFilesProcessingStartContext = {
1732
+ /**
1733
+ * A notice that a newer Kubb version is available on npm, built with {@link Diagnostics.update}.
1734
+ * It renders like any info diagnostic.
1735
+ */
1736
+ type UpdateDiagnostic = {
1737
+ kind: 'update';
1738
+ code: typeof diagnosticCode.updateAvailable;
1739
+ severity: 'info';
1740
+ message: string;
1690
1741
  /**
1691
- * Files about to be serialized and written.
1742
+ * The running Kubb version.
1692
1743
  */
1693
- files: Array<FileNode>;
1694
- };
1695
- type KubbFileProcessingUpdate = {
1744
+ currentVersion: string;
1696
1745
  /**
1697
- * Number of files processed so far in this batch.
1746
+ * The newest version published on npm.
1698
1747
  */
1699
- processed: number;
1748
+ latestVersion: string;
1749
+ };
1750
+ /**
1751
+ * A structured record collected during a build, discriminated on `kind`: a
1752
+ * {@link ProblemDiagnostic} for an issue, a {@link PerformanceDiagnostic} for a per-plugin
1753
+ * timing, or an {@link UpdateDiagnostic} for a version notice.
1754
+ */
1755
+ type Diagnostic = ProblemDiagnostic | PerformanceDiagnostic | UpdateDiagnostic;
1756
+ /**
1757
+ * Static helpers for working with {@link Diagnostic}s, plus the run-scoped sink
1758
+ * that lets deep code report a diagnostic without threading a callback.
1759
+ *
1760
+ * The sink lives in a single `AsyncLocalStorage` in the `@kubb/core` bundle.
1761
+ * `Diagnostics.scope` activates it for a run, so anything inside that run (the
1762
+ * adapter parse, a generator) reports through `Diagnostics.report` and lands
1763
+ * in the same run.
1764
+ */
1765
+ declare class Diagnostics {
1766
+ #private;
1700
1767
  /**
1701
- * Total number of files in this batch.
1768
+ * The diagnostic code catalog, exposed as `Diagnostics.code` (e.g. `Diagnostics.code.refNotFound`).
1702
1769
  */
1703
- total: number;
1770
+ static code: {
1771
+ readonly unknown: "KUBB_UNKNOWN";
1772
+ readonly inputNotFound: "KUBB_INPUT_NOT_FOUND";
1773
+ readonly inputRequestFailed: "KUBB_INPUT_REQUEST_FAILED";
1774
+ readonly inputUnreachable: "KUBB_INPUT_UNREACHABLE";
1775
+ readonly inputRequired: "KUBB_INPUT_REQUIRED";
1776
+ readonly legacyInput: "KUBB_LEGACY_INPUT";
1777
+ readonly invalidDocument: "KUBB_INVALID_DOCUMENT";
1778
+ readonly invalidSpec: "KUBB_INVALID_SPEC";
1779
+ readonly refNotFound: "KUBB_REF_NOT_FOUND";
1780
+ readonly invalidServerVariable: "KUBB_INVALID_SERVER_VARIABLE";
1781
+ readonly pluginNotFound: "KUBB_PLUGIN_NOT_FOUND";
1782
+ readonly incompatibleExtension: "KUBB_INCOMPATIBLE_EXTENSION";
1783
+ readonly missingDependency: "KUBB_MISSING_DEPENDENCY";
1784
+ readonly incompatibleDependency: "KUBB_INCOMPATIBLE_DEPENDENCY";
1785
+ readonly pluginFailed: "KUBB_PLUGIN_FAILED";
1786
+ readonly adapterFailed: "KUBB_ADAPTER_FAILED";
1787
+ readonly parserFailed: "KUBB_PARSER_FAILED";
1788
+ readonly pluginWarning: "KUBB_PLUGIN_WARNING";
1789
+ readonly pluginInfo: "KUBB_PLUGIN_INFO";
1790
+ readonly noContext: "KUBB_NO_CONTEXT";
1791
+ readonly unsupportedFormat: "KUBB_UNSUPPORTED_FORMAT";
1792
+ readonly deprecated: "KUBB_DEPRECATED";
1793
+ readonly adapterRequired: "KUBB_ADAPTER_REQUIRED";
1794
+ readonly pathTraversal: "KUBB_PATH_TRAVERSAL";
1795
+ readonly cleanRoot: "KUBB_CLEAN_ROOT";
1796
+ readonly invalidPluginOptions: "KUBB_INVALID_PLUGIN_OPTIONS";
1797
+ readonly postGenerateFailed: "KUBB_POST_GENERATE_FAILED";
1798
+ readonly formatFailed: "KUBB_FORMAT_FAILED";
1799
+ readonly lintFailed: "KUBB_LINT_FAILED";
1800
+ readonly barrelDuplicateExport: "KUBB_BARREL_DUPLICATE_EXPORT";
1801
+ readonly internalError: "KUBB_INTERNAL_ERROR";
1802
+ readonly performance: "KUBB_PERFORMANCE";
1803
+ readonly updateAvailable: "KUBB_UPDATE_AVAILABLE";
1804
+ };
1704
1805
  /**
1705
- * Completion percentage, `0` to `100`.
1806
+ * Type guard for a build {@link ProblemDiagnostic}.
1706
1807
  */
1707
- percentage: number;
1808
+ static isProblem: (diagnostic: Diagnostic) => diagnostic is ProblemDiagnostic;
1708
1809
  /**
1709
- * The file that was just processed.
1810
+ * Type guard for a version-update {@link UpdateDiagnostic}.
1710
1811
  */
1711
- file: FileNode;
1812
+ static isUpdate: (diagnostic: Diagnostic) => diagnostic is UpdateDiagnostic;
1712
1813
  /**
1713
- * Resolved configuration for this build.
1814
+ * Type guard for a per-plugin {@link PerformanceDiagnostic}.
1714
1815
  */
1715
- config: Config;
1716
- };
1717
- type KubbFilesProcessingUpdateContext = {
1816
+ static isPerformance: (diagnostic: Diagnostic) => diagnostic is PerformanceDiagnostic;
1718
1817
  /**
1719
- * All files processed in this flush chunk.
1818
+ * An `Error` that carries a {@link Diagnostic}, so structured problems can flow
1819
+ * through the existing throw/catch paths while keeping their code and location.
1820
+ *
1821
+ * @example
1822
+ * ```ts
1823
+ * throw new Diagnostics.Error({ code: diagnosticCode.refNotFound, severity: 'error', message: `Could not find ${ref}`, location: { kind: 'schema', pointer: ref, ref } })
1824
+ * ```
1720
1825
  */
1721
- files: Array<KubbFileProcessingUpdate>;
1722
- };
1723
- type KubbFilesProcessingEndContext = {
1826
+ static Error: {
1827
+ new (diagnostic: ProblemDiagnostic): {
1828
+ diagnostic: ProblemDiagnostic;
1829
+ name: string;
1830
+ message: string;
1831
+ stack?: string;
1832
+ cause?: unknown;
1833
+ };
1834
+ isError(error: unknown): error is Error;
1835
+ isError(value: unknown): value is Error;
1836
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
1837
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
1838
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
1839
+ stackTraceLimit: number;
1840
+ };
1724
1841
  /**
1725
- * All files that were serialized in this batch.
1842
+ * Structural check for a {@link Diagnostics.Error}, including one thrown from a duplicated
1843
+ * `@kubb/core` copy where `instanceof` fails. Matches on the `name` and a `diagnostic`
1844
+ * that carries a `code`.
1726
1845
  */
1727
- files: Array<FileNode>;
1728
- };
1729
- type KubbHookStartContext = {
1846
+ static isError(error: unknown): error is InstanceType<typeof Diagnostics.Error>;
1730
1847
  /**
1731
- * Optional identifier for correlating start/end hooks.
1848
+ * Runs `fn` with `sink` as the active diagnostic sink for the whole async
1849
+ * subtree, so {@link Diagnostics.report} reaches it from anywhere inside.
1732
1850
  */
1733
- id?: string;
1851
+ static scope<T>(sink: (diagnostic: Diagnostic) => void, fn: () => T): T;
1734
1852
  /**
1735
- * The shell command that is about to run.
1853
+ * Collects a diagnostic into the active build via the run-scoped sink, without throwing.
1854
+ * Returns `true` when a run consumed it, `false` when called outside a {@link Diagnostics.scope}
1855
+ * (so callers can fall back to throwing). Use a `warning`/`info` severity for non-fatal issues.
1856
+ * For rendering a diagnostic live on the hook bus, use {@link Diagnostics.emit} instead.
1736
1857
  */
1737
- command: string;
1858
+ static report(diagnostic: Diagnostic): boolean;
1738
1859
  /**
1739
- * Optional label for the command, shown in the CLI output when set.
1860
+ * Emits a diagnostic, or any thrown value, on the run's hooks so the loggers render it live.
1861
+ * A coded problem or an update goes to `kubb:diagnostic`. An uncoded one goes to `kubb:error`
1862
+ * whole, so every wrapper's message, its help, and the stack survive. To collect a diagnostic into
1863
+ * the build result from deep in a run, use {@link Diagnostics.report} instead.
1740
1864
  */
1741
- name?: string;
1865
+ static emit(hooks: Hookable<KubbHooks>, value: ProblemDiagnostic | UpdateDiagnostic | unknown): Promise<void>;
1742
1866
  /**
1743
- * Parsed argument list, when available.
1867
+ * Coerces any thrown value into a {@link ProblemDiagnostic}. A {@link Diagnostics.Error}
1868
+ * keeps its structured data, and anything else becomes a `KUBB_UNKNOWN` error.
1744
1869
  */
1745
- args?: ReadonlyArray<string>;
1746
- };
1747
- /**
1748
- * Emitted for each line streamed from a hook's stdout while it runs.
1749
- * A logger correlates the line to its active UI element via `id`.
1750
- */
1751
- type KubbHookLineContext = {
1870
+ static from(error: unknown): ProblemDiagnostic;
1752
1871
  /**
1753
- * Identifier matching the corresponding `kubb:hook:start` hook.
1872
+ * Coerces an error thrown by a plugin, adapter, or parser into a diagnostic attributed to it.
1873
+ * A structured {@link Diagnostics.Error} keeps its code. Any other error is a crash: it gets the
1874
+ * kind's `*_FAILED` code and the extension's `meta.issues` link, so the user reports it to the
1875
+ * extension's maintainers instead of to Kubb.
1754
1876
  */
1755
- id: string;
1877
+ static fromExtension(error: unknown, { kind, extension }: {
1878
+ kind: ExtensionKind;
1879
+ extension: ExtensionNamed;
1880
+ }): ProblemDiagnostic;
1756
1881
  /**
1757
- * A single streamed stdout line, without its trailing newline.
1882
+ * Builds a per-plugin performance record. Reporters sum these into the run total.
1758
1883
  */
1759
- line: string;
1760
- };
1761
- /** Emitted when a hook subprocess ends: its `kubb:hook:start` context plus the outcome. */
1762
- type KubbHookEndContext = KubbHookStartContext & HookResult;
1763
- /**
1764
- * CLI options derived from command-line flags.
1765
- */
1766
- type CLIOptions = {
1884
+ static performance({ plugin, duration }: {
1885
+ plugin: string;
1886
+ duration: number;
1887
+ }): PerformanceDiagnostic;
1767
1888
  /**
1768
- * Path to the Kubb config file.
1889
+ * Builds the version-update notice shown when a newer Kubb is published on npm.
1769
1890
  */
1770
- config?: string;
1891
+ static update({ currentVersion, latestVersion }: {
1892
+ currentVersion: string;
1893
+ latestVersion: string;
1894
+ }): UpdateDiagnostic;
1771
1895
  /**
1772
- * OpenAPI input path or URL passed as the positional argument to `kubb generate`.
1773
- * Overrides `config.input` when set.
1896
+ * True when any diagnostic is an error, the severity that fails a build. Non-error
1897
+ * diagnostics are ignored.
1774
1898
  */
1775
- input?: string;
1899
+ static hasError(diagnostics: ReadonlyArray<Diagnostic>): boolean;
1776
1900
  /**
1777
- * Re-run generation whenever input files change.
1901
+ * Names of the plugins that failed, deduped, derived from the error diagnostics
1902
+ * that carry a `plugin`.
1778
1903
  */
1779
- watch?: boolean;
1904
+ static failedPlugins(diagnostics: ReadonlyArray<Diagnostic>): Array<string>;
1780
1905
  /**
1781
- * Controls how much output the CLI prints.
1782
- *
1783
- * @default 'info'
1906
+ * Counts `problem` diagnostics by severity for the run summary. `performance` and
1907
+ * `update` diagnostics are ignored.
1784
1908
  */
1785
- logLevel?: 'silent' | 'info' | 'verbose';
1909
+ static count(diagnostics: ReadonlyArray<Diagnostic>): {
1910
+ errors: number;
1911
+ warnings: number;
1912
+ infos: number;
1913
+ };
1786
1914
  /**
1787
- * Reporters selected on the CLI via `--reporter`, overriding `config.reporters`.
1915
+ * Drops duplicate `problem` diagnostics that share a code, location pointer, and
1916
+ * plugin, so the same issue reported across several passes is shown once. Non-problem
1917
+ * diagnostics are always kept.
1788
1918
  */
1789
- reporters?: Array<ReporterName>;
1790
- };
1791
- /**
1792
- * All accepted forms of a Kubb configuration.
1793
- * Accepts `Config`/`Config[]`/promise or a factory (optionally receiving `TCliOptions`).
1794
- */
1795
- type PossibleConfig<TCliOptions = undefined> = PossiblePromise<Config | Array<Config>> | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Array<Config>>);
1796
- /**
1797
- * Full output produced by a successful or failed build.
1798
- */
1799
- type BuildOutput = {
1919
+ static dedupe(diagnostics: ReadonlyArray<Diagnostic>): Array<Diagnostic>;
1800
1920
  /**
1801
- * Structured diagnostics collected during the build: error/warning/info problems
1802
- * (each with a code, severity, and where known a JSON-pointer location) plus a
1803
- * `performance` diagnostic per plugin. Includes a top-level diagnostic when the build
1804
- * threw before completing. Use {@link Diagnostics.hasError} to test for failure.
1921
+ * Builds the kubb.dev docs URL for a diagnostic code, e.g.
1922
+ * `KUBB_REF_NOT_FOUND` → `https://kubb.dev/docs/5.x/reference/diagnostics#kubb-ref-not-found`.
1805
1923
  */
1806
- diagnostics: Array<Diagnostic>;
1924
+ static docsUrl(code: string): string;
1807
1925
  /**
1808
- * All files generated during this build.
1926
+ * The catalog entry for a code: its title, cause, and fix. Mirrors the kubb.dev
1927
+ * `/reference/diagnostics#<slug>` section.
1809
1928
  */
1810
- files: Array<FileNode>;
1929
+ static explain(code: DiagnosticCode): DiagnosticDoc;
1811
1930
  /**
1812
- * The plugin driver that orchestrated this build.
1931
+ * Reduces a diagnostic to its JSON-safe fields plus a `docsUrl`, for machine-readable
1932
+ * consumers, with the catalog `title`, `cause`, and fix, and the `cause` error as `causes` and
1933
+ * `stack`. Absent optional fields are omitted.
1813
1934
  */
1814
- driver: KubbDriver;
1935
+ static serialize: typeof serialize;
1815
1936
  /**
1816
- * The configured `Storage` backend, for reading back a generated file's final content.
1817
- * Use `files` to list what this build produced.
1818
- *
1819
- * @example Read a generated file
1820
- * `const code = await buildOutput.storage.readItem('/src/gen/pet.ts')`
1937
+ * Renders a diagnostic as lines for an `agent` (the default) or a `human`. See {@link format}.
1821
1938
  */
1822
- storage: Storage;
1823
- };
1939
+ static format: typeof format;
1940
+ }
1824
1941
  //#endregion
1825
1942
  //#region src/nodeCache.d.ts
1826
1943
  /**
@@ -1927,21 +2044,24 @@ type GeneratorContext<TOptions extends PluginType = PluginType> = {
1927
2044
  resolver: TOptions['resolver'];
1928
2045
  /**
1929
2046
  * Report a warning. Collected as a `warning` diagnostic attributed to the current
1930
- * plugin. It surfaces in the run summary but does not fail the build. For a structured
1931
- * diagnostic with a code and source location, use `Diagnostics.report` or throw a
1932
- * `Diagnostics.Error` directly.
2047
+ * plugin. It surfaces in the run summary but does not fail the build. Pass `options` to set
2048
+ * the `code`, the `help` text, or the source `location`.
2049
+ *
2050
+ * @example
2051
+ * `ctx.warn('Enum has no values', { help: 'Add values to the enum.', location: { kind: 'schema', pointer: '#/components/schemas/Status' } })`
1933
2052
  */
1934
- warn: (message: string) => void;
2053
+ warn: (message: string, options?: Partial<Pick<ProblemDiagnostic, 'code' | 'help' | 'location'>>) => void;
1935
2054
  /**
1936
2055
  * Report an error. Collected as an `error` diagnostic attributed to the current
1937
- * plugin, which fails the build.
2056
+ * plugin, which fails the build. A `Diagnostics.Error` keeps its own code, help, and location.
2057
+ * Pass `options` to set them for a plain message or error.
1938
2058
  */
1939
- error: (error: string | Error) => void;
2059
+ error: (error: string | Error, options?: Partial<Pick<ProblemDiagnostic, 'code' | 'help' | 'location'>>) => void;
1940
2060
  /**
1941
2061
  * Report an informational message. Collected as an `info` diagnostic attributed to
1942
- * the current plugin.
2062
+ * the current plugin. Pass `options` to set the `code`, the `help` text, or the source `location`.
1943
2063
  */
1944
- info: (message: string) => void;
2064
+ info: (message: string, options?: Partial<Pick<ProblemDiagnostic, 'code' | 'help' | 'location'>>) => void;
1945
2065
  /**
1946
2066
  * The configured adapter instance.
1947
2067
  */
@@ -2846,7 +2966,7 @@ type ExtensionNamed = {
2846
2966
  /**
2847
2967
  * Returns `meta`, or `{ name }` for an extension that only sets the deprecated `name`. Throws `KUBB_INVALID_PLUGIN_OPTIONS` when it has neither.
2848
2968
  */
2849
- declare function resolveMeta({ name, meta }: ExtensionNamed): ExtensionMeta;
2969
+ declare function resolveMeta(extension: ExtensionNamed): ExtensionMeta;
2850
2970
  /**
2851
2971
  * Sets how Kubb checks one entry in a `dependencies` record.
2852
2972
  */
@@ -3024,5 +3144,5 @@ type AdapterFactory<T extends AdapterFactoryOptions = AdapterFactoryOptions> = E
3024
3144
  */
3025
3145
  declare function createAdapter<T extends AdapterFactoryOptions = AdapterFactoryOptions>(definition: AdapterDefinition<T>): AdapterFactory<T>;
3026
3146
  //#endregion
3027
- export { NodeCache as $, UpdateDiagnostic as $t, PluginFactory as A, RunHookOptions as At, ResolveImportsOptions as B, UserReporter as Bt, NormalizedPlugin as C, KubbPluginsEndContext as Ct, Override as D, PostGenerateCommand as Dt, OutputOptions as E, PossibleConfig as Et, definePlugin as F, GenerationResult as Ft, ResolverFile as G, DiagnosticKind as Gt, ResolvePathOptions as H, logLevel as Ht, BannerMeta as I, Reporter as It, ResolverPatch as J, Diagnostics as Jt, ResolverFileParams as K, DiagnosticLocation as Kt, ResolveBannerContext as L, ReporterContext as Lt, PluginType as M, KubbDriver as Mt, ResolvePluginOptions as N, Storage as Nt, Plugin as O, UserConfig as Ot, assertPluginOption as P, createStorage as Pt, defineGenerator as Q, SerializedDiagnostic as Qt, ResolveBannerFile as R, ReporterName as Rt, KubbPluginStartContext as S, KubbMessageContext as St, OutputMode as T, KubbWarnContext as Tt, Resolver as U, Diagnostic as Ut, ResolveOptionsContext as V, createReporter as Vt, ResolverDefault as W, DiagnosticDoc as Wt, Generator as X, ProblemCode as Xt, ResolverPathParams as Y, PerformanceDiagnostic as Yt, GeneratorContext as Z, ProblemDiagnostic as Zt, Filter as _, KubbHookLineContext as _t, AdapterSource as a, ParserDefinition as an, KubbBuildEndContext as at, KubbPluginEndContext as b, KubbInfoContext as bt, ExtensionDependency as c, KubbErrorContext as ct, ExtensionKind as d, KubbFilesProcessingStartContext as dt, Hookable as en, BuildOutput as et, ExtensionMeta as f, KubbFilesProcessingUpdateContext as ft, Exclude$1 as g, KubbHookEndContext as gt, resolveMeta as h, KubbGenerationSummaryContext as ht, AdapterFactoryOptions as i, Parser as in, Input as it, PluginName as j, runHook as jt, PluginDefinition as k, HookResult as kt, ExtensionDependencyRecord as l, KubbFileProcessingUpdate as lt, defineExtension as m, KubbGenerationStartContext as mt, AdapterDefinition as n, RendererFactory as nn, Config as nt, createAdapter as o, ParserFactory as on, KubbBuildStartContext as ot, checkCompatibility as p, KubbGenerationEndContext as pt, ResolverFilePathParams as q, DiagnosticSeverity as qt, AdapterFactory as r, createRenderer as rn, FilesContext as rt, ExtensionDependencies as s, defineParser as sn, KubbDiagnosticContext as st, Adapter as t, Renderer as tn, CLIOptions as tt, ExtensionFactory as u, KubbFilesProcessingEndContext as ut, Group as v, KubbHookStartContext as vt, Output as w, KubbSuccessContext as wt, KubbPluginSetupContext as x, KubbLifecycleStartContext as xt, Include as y, KubbHooks as yt, ResolveFileOptions as z, ReporterPluginFiles as zt };
3028
- //# sourceMappingURL=createAdapter-D55JE9lX.d.ts.map
3147
+ export { NodeCache as $, ReporterPluginFiles as $t, PluginFactory as A, KubbInfoContext as At, ResolveImportsOptions as B, RunHookOptions as Bt, NormalizedPlugin as C, KubbGenerationEndContext as Ct, Override as D, KubbHookLineContext as Dt, OutputOptions as E, KubbHookEndContext as Et, definePlugin as F, KubbWarnContext as Ft, ResolverFile as G, RendererFactory as Gt, ResolvePathOptions as H, KubbDriver as Ht, BannerMeta as I, PossibleConfig as It, ResolverPatch as J, createStorage as Jt, ResolverFileParams as K, createRenderer as Kt, ResolveBannerContext as L, PostGenerateCommand as Lt, PluginType as M, KubbMessageContext as Mt, ResolvePluginOptions as N, KubbPluginsEndContext as Nt, Plugin as O, KubbHookStartContext as Ot, assertPluginOption as P, KubbSuccessContext as Pt, defineGenerator as Q, ReporterName as Qt, ResolveBannerFile as R, UserConfig as Rt, KubbPluginStartContext as S, KubbFilesProcessingUpdateContext as St, OutputMode as T, KubbGenerationSummaryContext as Tt, Resolver as U, Hookable as Ut, ResolveOptionsContext as V, runHook as Vt, ResolverDefault as W, Renderer as Wt, Generator as X, Reporter as Xt, ResolverPathParams as Y, GenerationResult as Yt, GeneratorContext as Z, ReporterContext as Zt, Filter as _, KubbDiagnosticContext as _t, AdapterSource as a, Parser as an, Diagnostics as at, KubbPluginEndContext as b, KubbFilesProcessingEndContext as bt, ExtensionDependency as c, defineParser as cn, ProblemDiagnostic as ct, ExtensionKind as d, CLIOptions as dt, UserReporter as en, Diagnostic as et, ExtensionMeta as f, Config as ft, Exclude$1 as g, KubbBuildStartContext as gt, resolveMeta as h, KubbBuildEndContext as ht, AdapterFactoryOptions as i, SerializedDiagnostic as in, DiagnosticSeverity as it, PluginName as j, KubbLifecycleStartContext as jt, PluginDefinition as k, KubbHooks as kt, ExtensionDependencyRecord as l, UpdateDiagnostic as lt, defineExtension as m, Input as mt, AdapterDefinition as n, logLevel as nn, DiagnosticKind as nt, createAdapter as o, ParserDefinition as on, PerformanceDiagnostic as ot, checkCompatibility as p, FilesContext as pt, ResolverFilePathParams as q, Storage as qt, AdapterFactory as r, DiagnosticFormatOptions as rn, DiagnosticLocation as rt, ExtensionDependencies as s, ParserFactory as sn, ProblemCode as st, Adapter as t, createReporter as tn, DiagnosticDoc as tt, ExtensionFactory as u, BuildOutput as ut, Group as v, KubbErrorContext as vt, Output as w, KubbGenerationStartContext as wt, KubbPluginSetupContext as x, KubbFilesProcessingStartContext as xt, Include as y, KubbFileProcessingUpdate as yt, ResolveFileOptions as z, HookResult as zt };
3148
+ //# sourceMappingURL=createAdapter-CMnLz31B.d.ts.map