@kubb/core 5.0.0-beta.37 → 5.0.0-beta.39

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.
@@ -108,115 +108,6 @@ declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[
108
108
  */
109
109
  type PossiblePromise<T> = Promise<T> | T;
110
110
  //#endregion
111
- //#region src/constants.d.ts
112
- /**
113
- * Base URL for the Kubb Studio web app.
114
- */
115
- declare const DEFAULT_STUDIO_URL: "https://kubb.studio";
116
- /**
117
- * Numeric log-level thresholds used internally to compare verbosity.
118
- *
119
- * Higher numbers are more verbose.
120
- */
121
- declare const logLevel: {
122
- readonly silent: number;
123
- readonly error: 0;
124
- readonly warn: 1;
125
- readonly info: 3;
126
- readonly verbose: 4;
127
- };
128
- /**
129
- * Stable codes Kubb attaches to a `Diagnostic`. Each maps to a known failure mode
130
- * and stays stable so it can be referenced in tooling and (later) docs. Reference
131
- * these instead of inlining the string at a throw site.
132
- */
133
- declare const diagnosticCode: {
134
- /**
135
- * Fallback for an unstructured error with no specific code.
136
- */
137
- readonly unknown: "KUBB_UNKNOWN";
138
- /**
139
- * The `input.path` file or URL could not be read.
140
- */
141
- readonly inputNotFound: "KUBB_INPUT_NOT_FOUND";
142
- /**
143
- * An adapter was configured without an `input`.
144
- */
145
- readonly inputRequired: "KUBB_INPUT_REQUIRED";
146
- /**
147
- * A `$ref` (or equivalent reference) could not be resolved in the source document.
148
- */
149
- readonly refNotFound: "KUBB_REF_NOT_FOUND";
150
- /**
151
- * A server variable value is not allowed by its `enum`.
152
- */
153
- readonly invalidServerVariable: "KUBB_INVALID_SERVER_VARIABLE";
154
- /**
155
- * A required plugin is missing from the config.
156
- */
157
- readonly pluginNotFound: "KUBB_PLUGIN_NOT_FOUND";
158
- /**
159
- * A plugin threw while generating.
160
- */
161
- readonly pluginFailed: "KUBB_PLUGIN_FAILED";
162
- /**
163
- * A plugin reported a non-fatal warning through `ctx.warn`.
164
- */
165
- readonly pluginWarning: "KUBB_PLUGIN_WARNING";
166
- /**
167
- * A plugin reported an informational message through `ctx.info`.
168
- */
169
- readonly pluginInfo: "KUBB_PLUGIN_INFO";
170
- /**
171
- * A schema uses a `format` Kubb does not map to a specific type. Reserved for
172
- * adapters to emit as a `warning`.
173
- */
174
- readonly unsupportedFormat: "KUBB_UNSUPPORTED_FORMAT";
175
- /**
176
- * A referenced schema or operation is marked `deprecated`. Reserved for adapters
177
- * to emit as an `info`.
178
- */
179
- readonly deprecated: "KUBB_DEPRECATED";
180
- /**
181
- * An adapter is required but the config has none. The build cannot read the input
182
- * without one.
183
- */
184
- readonly adapterRequired: "KUBB_ADAPTER_REQUIRED";
185
- /**
186
- * The `devtools` config is set to something other than an object.
187
- */
188
- readonly devtoolsInvalid: "KUBB_DEVTOOLS_INVALID";
189
- /**
190
- * A resolved output path escapes the output directory, which can stem from a path
191
- * traversal in the spec or a misconfigured `group.name`.
192
- */
193
- readonly pathTraversal: "KUBB_PATH_TRAVERSAL";
194
- /**
195
- * A post-generate shell hook (`hooks.done`) exited with a failure.
196
- */
197
- readonly hookFailed: "KUBB_HOOK_FAILED";
198
- /**
199
- * The formatter pass over the generated files failed.
200
- */
201
- readonly formatFailed: "KUBB_FORMAT_FAILED";
202
- /**
203
- * The linter pass over the generated files failed.
204
- */
205
- readonly lintFailed: "KUBB_LINT_FAILED";
206
- /**
207
- * Not a failure. Carries a plugin's elapsed time, summed into the run total.
208
- */
209
- readonly performance: "KUBB_PERFORMANCE";
210
- /**
211
- * Not a failure. A newer Kubb version is available on npm.
212
- */
213
- readonly updateAvailable: "KUBB_UPDATE_AVAILABLE";
214
- };
215
- /**
216
- * Union of the stable {@link diagnosticCode} values.
217
- */
218
- type DiagnosticCode = (typeof diagnosticCode)[keyof typeof diagnosticCode];
219
- //#endregion
220
111
  //#region src/createAdapter.d.ts
221
112
  /**
222
113
  * Source data handed to an adapter's `parse` function. Mirrors the config
@@ -347,6 +238,95 @@ type AdapterBuilder<T extends AdapterFactoryOptions> = (options: T['options']) =
347
238
  */
348
239
  declare function createAdapter<T extends AdapterFactoryOptions = AdapterFactoryOptions>(build: AdapterBuilder<T>): (options?: T['options']) => Adapter<T>;
349
240
  //#endregion
241
+ //#region src/constants.d.ts
242
+ /**
243
+ * Stable codes Kubb attaches to a `Diagnostic`. Each maps to a known failure mode
244
+ * and stays stable so it can be referenced in tooling and (later) docs. Reference
245
+ * these instead of inlining the string at a throw site.
246
+ */
247
+ declare const diagnosticCode: {
248
+ /**
249
+ * Fallback for an unstructured error with no specific code.
250
+ */
251
+ readonly unknown: "KUBB_UNKNOWN";
252
+ /**
253
+ * The `input.path` file or URL could not be read.
254
+ */
255
+ readonly inputNotFound: "KUBB_INPUT_NOT_FOUND";
256
+ /**
257
+ * An adapter was configured without an `input`.
258
+ */
259
+ readonly inputRequired: "KUBB_INPUT_REQUIRED";
260
+ /**
261
+ * A `$ref` (or equivalent reference) could not be resolved in the source document.
262
+ */
263
+ readonly refNotFound: "KUBB_REF_NOT_FOUND";
264
+ /**
265
+ * A server variable value is not allowed by its `enum`.
266
+ */
267
+ readonly invalidServerVariable: "KUBB_INVALID_SERVER_VARIABLE";
268
+ /**
269
+ * A required plugin is missing from the config.
270
+ */
271
+ readonly pluginNotFound: "KUBB_PLUGIN_NOT_FOUND";
272
+ /**
273
+ * A plugin threw while generating.
274
+ */
275
+ readonly pluginFailed: "KUBB_PLUGIN_FAILED";
276
+ /**
277
+ * A plugin reported a non-fatal warning through `ctx.warn`.
278
+ */
279
+ readonly pluginWarning: "KUBB_PLUGIN_WARNING";
280
+ /**
281
+ * A plugin reported an informational message through `ctx.info`.
282
+ */
283
+ readonly pluginInfo: "KUBB_PLUGIN_INFO";
284
+ /**
285
+ * A schema uses a `format` Kubb does not map to a specific type. Reserved for
286
+ * adapters to emit as a `warning`.
287
+ */
288
+ readonly unsupportedFormat: "KUBB_UNSUPPORTED_FORMAT";
289
+ /**
290
+ * A referenced schema or operation is marked `deprecated`. Reserved for adapters
291
+ * to emit as an `info`.
292
+ */
293
+ readonly deprecated: "KUBB_DEPRECATED";
294
+ /**
295
+ * An adapter is required but the config has none. The build cannot read the input
296
+ * without one.
297
+ */
298
+ readonly adapterRequired: "KUBB_ADAPTER_REQUIRED";
299
+ /**
300
+ * A resolved output path escapes the output directory, which can stem from a path
301
+ * traversal in the spec or a misconfigured `group.name`.
302
+ */
303
+ readonly pathTraversal: "KUBB_PATH_TRAVERSAL";
304
+ /**
305
+ * A post-generate shell hook (`hooks.done`) exited with a failure.
306
+ */
307
+ readonly hookFailed: "KUBB_HOOK_FAILED";
308
+ /**
309
+ * The formatter pass over the generated files failed.
310
+ */
311
+ readonly formatFailed: "KUBB_FORMAT_FAILED";
312
+ /**
313
+ * The linter pass over the generated files failed.
314
+ */
315
+ readonly lintFailed: "KUBB_LINT_FAILED";
316
+ /**
317
+ * Not a failure. Carries a plugin's elapsed time, summed into the run total.
318
+ */
319
+ readonly performance: "KUBB_PERFORMANCE";
320
+ /**
321
+ * Not a failure. A newer Kubb version is available on npm.
322
+ */
323
+ readonly updateAvailable: "KUBB_UPDATE_AVAILABLE";
324
+ };
325
+ /**
326
+ * Union of the stable {@link diagnosticCode} values.
327
+ */
328
+ type DiagnosticCode = (typeof diagnosticCode)[keyof typeof diagnosticCode];
329
+ //#endregion
350
330
  //#region src/createStorage.d.ts
351
331
  /**
352
332
  * Backend that persists generated files. Kubb ships with `fsStorage` (writes
@@ -513,14 +493,85 @@ type RendererFactory<TElement = unknown> = () => Renderer<TElement>;
513
493
  */
514
494
  declare function createRenderer<TElement = unknown>(factory: RendererFactory<TElement>): RendererFactory<TElement>;
515
495
  //#endregion
516
- //#region src/devtools.d.ts
517
- type DevtoolsOptions = {
496
+ //#region src/defineLogger.d.ts
497
+ /**
498
+ * Numeric log-level thresholds used internally to compare verbosity.
499
+ *
500
+ * Higher numbers are more verbose.
501
+ */
502
+ declare const logLevel: {
503
+ readonly silent: number;
504
+ readonly error: 0;
505
+ readonly warn: 1;
506
+ readonly info: 3;
507
+ readonly verbose: 4;
508
+ };
509
+ /**
510
+ * Options accepted by a logger's `install` callback.
511
+ */
512
+ type LoggerOptions = {
518
513
  /**
519
- * Open the AST inspector in Kubb Studio (`/ast`). Defaults to the main Studio page.
520
- * @default false
514
+ * Output verbosity. Use the `logLevel` constants exported from `@kubb/core`
515
+ * (`silent`, `error`, `warn`, `info`, `verbose`, `debug`).
516
+ */
517
+ logLevel: (typeof logLevel)[keyof typeof logLevel];
518
+ };
519
+ /**
520
+ * Event emitter handed to `Logger.install`. Use `.on('kubb:info', ...)` and
521
+ * friends to subscribe to build events.
522
+ */
523
+ type LoggerContext = AsyncEventEmitter<KubbHooks>;
524
+ /**
525
+ * Logger contract. A logger receives the build's event emitter and subscribes
526
+ * to whichever lifecycle events it wants to forward to its destination
527
+ * (console, file, remote sink).
528
+ */
529
+ type Logger<TOptions extends LoggerOptions = LoggerOptions, TInstallReturn = void> = {
530
+ /**
531
+ * Display name used in diagnostics.
521
532
  */
522
- ast?: boolean;
533
+ name: string;
534
+ /**
535
+ * Called once per build with the shared event emitter. Subscribe to events
536
+ * here. The return value (if any) is forwarded to whoever installed the
537
+ * logger, which is handy for sink factories.
538
+ */
539
+ install: (context: LoggerContext, options?: TOptions) => TInstallReturn | Promise<TInstallReturn>;
523
540
  };
541
+ type UserLogger<TOptions extends LoggerOptions = LoggerOptions, TInstallReturn = void> = Logger<TOptions, TInstallReturn>;
542
+ /**
543
+ * Defines a typed logger. Use the second type parameter to declare a return
544
+ * value from `install`, which is handy when the logger exposes a sink factory
545
+ * or cleanup callback to the caller.
546
+ *
547
+ * @example Basic logger
548
+ * ```ts
549
+ * import { defineLogger } from '@kubb/core'
550
+ *
551
+ * export const myLogger = defineLogger({
552
+ * name: 'my-logger',
553
+ * install(context) {
554
+ * context.on('kubb:info', ({ message }) => console.log('ℹ', message))
555
+ * context.on('kubb:error', ({ error }) => console.error('✗', error.message))
556
+ * },
557
+ * })
558
+ * ```
559
+ *
560
+ * @example Logger that returns a hook sink factory
561
+ * ```ts
562
+ * import { defineLogger, type LoggerOptions } from '@kubb/core'
563
+ * import type { HookSinkFactory } from './sinks'
564
+ *
565
+ * export const myLogger = defineLogger<LoggerOptions, HookSinkFactory>({
566
+ * name: 'my-logger',
567
+ * install(context) {
568
+ * // … register event handlers …
569
+ * return () => ({ onStdout: console.log })
570
+ * },
571
+ * })
572
+ * ```
573
+ */
574
+ declare function defineLogger<Options extends LoggerOptions = LoggerOptions, TInstallReturn = void>(logger: UserLogger<Options, TInstallReturn>): Logger<Options, TInstallReturn>;
524
575
  //#endregion
525
576
  //#region src/createReporter.d.ts
526
577
  /**
@@ -562,9 +613,9 @@ type ReporterContext = {
562
613
  logLevel: (typeof logLevel)[keyof typeof logLevel];
563
614
  };
564
615
  /**
565
- * Reporter contract. Unlike a Logger (the live TUI view), a reporter never sees the event
566
- * emitter. `report` is called once per config with its {@link GenerationResult} and produces
567
- * output (a terminal summary, a JSON report, a log file).
616
+ * Host-facing reporter, as installed onto a run. Unlike a Logger (the live TUI view), a reporter
617
+ * never sees the event emitter. `report` runs once per config; `drain`, when present, runs once
618
+ * after the last config.
568
619
  */
569
620
  type Reporter = {
570
621
  /**
@@ -575,12 +626,27 @@ type Reporter = {
575
626
  * Called once per config with that config's result and the render context.
576
627
  */
577
628
  report: (result: GenerationResult, context: ReporterContext) => void | Promise<void>;
629
+ /**
630
+ * Optional finalizer called once after the run's last config. The host wires it to
631
+ * `kubb:lifecycle:end`. {@link createReporter} closes it over the reports `report` returned.
632
+ */
633
+ drain?: (context: ReporterContext) => void | Promise<void>;
634
+ };
635
+ /**
636
+ * Reporter definition passed to {@link createReporter}. `report` returns the value to collect for
637
+ * this config (e.g. a built report), and the optional `drain` receives the collected reports to
638
+ * emit as one document. `T` is inferred from `report`'s return type.
639
+ */
640
+ type UserReporter<T = void> = {
641
+ name: string;
642
+ report: (result: GenerationResult, context: ReporterContext) => T | Promise<T>;
643
+ drain?: (context: ReporterContext, reports: Array<T>) => void | Promise<void>;
578
644
  };
579
- type UserReporter = Reporter;
580
645
  /**
581
- * Defines a reporter. Returns the reporter unchanged at runtime. It exists for type inference and
582
- * to mark the value as a reporter, mirroring {@link defineLogger}. Wiring the reporter onto the
583
- * run's events is the host's job, so the reporter only ever deals with a {@link GenerationResult}.
646
+ * Defines a reporter. When the definition has a `drain`, the returned reporter buffers each value
647
+ * `report` returns and hands the array to `drain` once, then clears it. Without a `drain`, nothing
648
+ * is buffered. Wiring the reporter onto the run's events is the host's job, so the reporter only
649
+ * ever deals with a {@link GenerationResult}.
584
650
  *
585
651
  * @example
586
652
  * ```ts
@@ -589,13 +655,22 @@ type UserReporter = Reporter;
589
655
  * export const jsonReporter = createReporter({
590
656
  * name: 'json',
591
657
  * report(result) {
592
- * const status = Diagnostics.hasError(result.diagnostics) ? 'failed' : 'success'
593
- * process.stdout.write(`${JSON.stringify({ status, diagnostics: result.diagnostics }, null, 2)}\n`)
658
+ * return { status: Diagnostics.hasError(result.diagnostics) ? 'failed' : 'success', diagnostics: result.diagnostics }
659
+ * },
660
+ * drain(context, reports) {
661
+ * process.stdout.write(`${JSON.stringify(reports, null, 2)}\n`)
594
662
  * },
595
663
  * })
596
664
  * ```
597
665
  */
598
- declare function createReporter(reporter: UserReporter): Reporter;
666
+ declare function createReporter<T = void>(reporter: UserReporter<T>): Reporter;
667
+ /**
668
+ * Picks the reporters whose `name` matches one of `names`, in the order the names are given.
669
+ * The config carries every available reporter, and the host selects which to activate by name
670
+ * (the CLI maps `--reporter` to this). Duplicate names and names without a matching reporter are
671
+ * skipped.
672
+ */
673
+ declare function selectReporters(reporters: ReadonlyArray<Reporter>, names: ReadonlyArray<string>): Array<Reporter>;
599
674
  //#endregion
600
675
  //#region src/defineParser.d.ts
601
676
  type PrintOptions = {
@@ -687,135 +762,6 @@ type ParsedFile = {
687
762
  total: number;
688
763
  percentage: number;
689
764
  };
690
- type FileProcessorOptions = {
691
- /**
692
- * Storage destination for queued writes.
693
- */
694
- storage: Storage;
695
- /**
696
- * Parsers indexed by file extension.
697
- */
698
- parsers?: Map<FileNode['extname'], Parser>;
699
- /**
700
- * Output extname per source extname, applied during conversion.
701
- */
702
- extension?: Record<FileNode['extname'], FileNode['extname'] | ''>;
703
- };
704
- /**
705
- * Turns `FileNode`s into source strings and writes them to storage.
706
- *
707
- * Two modes share the same instance. Stateless mode (`parse`, `stream`, `run`) just runs the
708
- * conversion. Queue mode (`enqueue`, `flush`, `drain`) buffers files deduped by path and
709
- * writes each batch through storage with up to `STREAM_FLUSH_EVERY` requests in flight.
710
- *
711
- * `flush` does not wait for its batch to finish, so dispatch can overlap with IO. The next
712
- * `flush` or `drain` picks the in-flight batch up. `drain` blocks until everything has been
713
- * written and is meant for the end of a build.
714
- *
715
- * To surface build-level hook signals (`kubb:files:processing:*` and friends) subscribe to
716
- * `hooks` and re-emit on the kubb bus.
717
- */
718
- declare class FileProcessor {
719
- #private;
720
- readonly hooks: AsyncEventEmitter<FileProcessorHooks>;
721
- constructor(options: FileProcessorOptions);
722
- /**
723
- * Files waiting in the queue.
724
- */
725
- get size(): number;
726
- parse(file: FileNode): string;
727
- stream(files: ReadonlyArray<FileNode>): Generator<ParsedFile>;
728
- run(files: Array<FileNode>): Promise<Array<FileNode>>;
729
- /**
730
- * Adds a file to the next flush. A later `enqueue` for the same path replaces the previous
731
- * entry, matching `FileManager.upsert`. Fires the `enqueue` event.
732
- */
733
- enqueue(file: FileNode): void;
734
- /**
735
- * Starts processing the queued files. Waits for any previous flush to finish (so two
736
- * batches never run together) and then returns without waiting for the new one. The next
737
- * `flush` or `drain` picks up the in-flight task.
738
- */
739
- flush(): Promise<void>;
740
- /**
741
- * Waits for the in-flight flush and writes any files still queued. Fires the `drain` event
742
- * when both are done.
743
- */
744
- drain(): Promise<void>;
745
- /**
746
- * Clears every listener and the pending queue.
747
- */
748
- dispose(): void;
749
- [Symbol.dispose](): void;
750
- }
751
- //#endregion
752
- //#region src/defineLogger.d.ts
753
- /**
754
- * Options accepted by a logger's `install` callback.
755
- */
756
- type LoggerOptions = {
757
- /**
758
- * Output verbosity. Use the `logLevel` constants exported from `@kubb/core`
759
- * (`silent`, `error`, `warn`, `info`, `verbose`, `debug`).
760
- */
761
- logLevel: (typeof logLevel)[keyof typeof logLevel];
762
- };
763
- /**
764
- * Event emitter handed to `Logger.install`. Use `.on('kubb:info', ...)` and
765
- * friends to subscribe to build events.
766
- */
767
- type LoggerContext = AsyncEventEmitter<KubbHooks>;
768
- /**
769
- * Logger contract. A logger receives the build's event emitter and subscribes
770
- * to whichever lifecycle events it wants to forward to its destination
771
- * (console, file, remote sink).
772
- */
773
- type Logger<TOptions extends LoggerOptions = LoggerOptions, TInstallReturn = void> = {
774
- /**
775
- * Display name used in diagnostics.
776
- */
777
- name: string;
778
- /**
779
- * Called once per build with the shared event emitter. Subscribe to events
780
- * here. The return value (if any) is forwarded to whoever installed the
781
- * logger, which is handy for sink factories.
782
- */
783
- install: (context: LoggerContext, options?: TOptions) => TInstallReturn | Promise<TInstallReturn>;
784
- };
785
- type UserLogger<TOptions extends LoggerOptions = LoggerOptions, TInstallReturn = void> = Logger<TOptions, TInstallReturn>;
786
- /**
787
- * Defines a typed logger. Use the second type parameter to declare a return
788
- * value from `install`, which is handy when the logger exposes a sink factory
789
- * or cleanup callback to the caller.
790
- *
791
- * @example Basic logger
792
- * ```ts
793
- * import { defineLogger } from '@kubb/core'
794
- *
795
- * export const myLogger = defineLogger({
796
- * name: 'my-logger',
797
- * install(context) {
798
- * context.on('kubb:info', ({ message }) => console.log('ℹ', message))
799
- * context.on('kubb:error', ({ error }) => console.error('✗', error.message))
800
- * },
801
- * })
802
- * ```
803
- *
804
- * @example Logger that returns a hook sink factory
805
- * ```ts
806
- * import { defineLogger, type LoggerOptions } from '@kubb/core'
807
- * import type { HookSinkFactory } from './sinks'
808
- *
809
- * export const myLogger = defineLogger<LoggerOptions, HookSinkFactory>({
810
- * name: 'my-logger',
811
- * install(context) {
812
- * // … register event handlers …
813
- * return () => ({ onStdout: console.log })
814
- * },
815
- * })
816
- * ```
817
- */
818
- declare function defineLogger<Options extends LoggerOptions = LoggerOptions, TInstallReturn = void>(logger: UserLogger<Options, TInstallReturn>): Logger<Options, TInstallReturn>;
819
765
  //#endregion
820
766
  //#region src/defineMiddleware.d.ts
821
767
  /**
@@ -1706,7 +1652,7 @@ type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptio
1706
1652
  * Report a warning. Collected as a `warning` diagnostic attributed to the current
1707
1653
  * plugin. It surfaces in the run summary but does not fail the build. For a structured
1708
1654
  * diagnostic with a code and source location, use `Diagnostics.report` or throw a
1709
- * `DiagnosticError` directly.
1655
+ * `Diagnostics.Error` directly.
1710
1656
  */
1711
1657
  warn: (message: string) => void;
1712
1658
  /**
@@ -1719,10 +1665,6 @@ type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptio
1719
1665
  * the current plugin.
1720
1666
  */
1721
1667
  info: (message: string) => void;
1722
- /**
1723
- * Open the current input node in Kubb Studio.
1724
- */
1725
- openInStudio: (options?: DevtoolsOptions) => Promise<void>;
1726
1668
  /**
1727
1669
  * The configured adapter instance.
1728
1670
  */
@@ -2086,26 +2028,6 @@ type Config<TInput = Input> = {
2086
2028
  * @see {@link defineMiddleware} to create custom middleware.
2087
2029
  */
2088
2030
  middleware?: Array<Middleware>;
2089
- /**
2090
- * Kubb Studio cloud integration settings.
2091
- *
2092
- * Kubb Studio (https://kubb.studio) is a web-based IDE for managing API specs and generated code.
2093
- * Set to `true` to enable with default settings, or pass an object to customize the Studio URL.
2094
- *
2095
- * @default false // disabled by default
2096
- * @example
2097
- * ```ts
2098
- * devtools: true // use default Kubb Studio
2099
- * devtools: { studioUrl: 'https://my-studio.dev' } // custom Studio instance
2100
- * ```
2101
- */
2102
- devtools?: true | {
2103
- /**
2104
- * Override the Kubb Studio base URL.
2105
- * @default 'https://kubb.studio'
2106
- */
2107
- studioUrl?: typeof DEFAULT_STUDIO_URL | (string & {});
2108
- };
2109
2031
  /**
2110
2032
  * Lifecycle hooks that execute during or after the build process.
2111
2033
  *
@@ -2138,28 +2060,30 @@ type Config<TInput = Input> = {
2138
2060
  done?: string | Array<string>;
2139
2061
  };
2140
2062
  /**
2141
- * Reporters that render the run's output, like Vitest. List one or more by name;
2142
- * the CLI `--reporter` flag overrides this when set.
2063
+ * The reporters available to the run, registered as instances. The host
2064
+ * (the CLI via `--reporter`) selects which ones to trigger by `name` with {@link selectReporters}.
2065
+ * `defineConfig` from the `kubb` package registers the built-in `cli`, `json`, and `file`
2066
+ * reporters by default.
2143
2067
  *
2144
2068
  * - `cli` writes the end-of-run summary to the terminal.
2145
2069
  * - `json` writes a machine-readable report to stdout, for CI.
2146
2070
  * - `file` writes a debug log to `.kubb/<name>-<timestamp>.log`.
2147
2071
  *
2148
- * @default ['cli']
2149
- *
2150
2072
  * @example
2151
2073
  * ```ts
2152
- * reporters: ['cli', 'file']
2074
+ * import { cliReporter, jsonReporter } from '@kubb/core'
2075
+ *
2076
+ * reporters: [cliReporter, jsonReporter, myReporter]
2153
2077
  * ```
2154
2078
  */
2155
- reporters?: Array<ReporterName>;
2079
+ reporters: Array<Reporter>;
2156
2080
  };
2157
2081
  /**
2158
2082
  * Partial `Config` for user-facing entry points with sensible defaults.
2159
2083
  *
2160
2084
  * `UserConfig` is what you pass to `defineConfig()`. It has optional `root`, `plugins`, `parsers`, and `adapter`
2161
2085
  * fields (which fall back to sensible defaults). All other Config options are available, including `output`, `input`,
2162
- * `storage`, `middleware`, `devtools`, and `hooks`.
2086
+ * `storage`, `middleware`, and `hooks`.
2163
2087
  *
2164
2088
  * @example
2165
2089
  * ```ts
@@ -2170,7 +2094,7 @@ type Config<TInput = Input> = {
2170
2094
  * })
2171
2095
  * ```
2172
2096
  */
2173
- type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter' | 'storage'> & {
2097
+ type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter' | 'storage' | 'reporters'> & {
2174
2098
  /**
2175
2099
  * Project root directory, absolute or relative to the config file location.
2176
2100
  * @default process.cwd()
@@ -2196,6 +2120,12 @@ type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'par
2196
2120
  * @default fsStorage()
2197
2121
  */
2198
2122
  storage?: Storage;
2123
+ /**
2124
+ * Reporters available to the run. `defineConfig` registers the built-in `cli`, `json`, and
2125
+ * `file` reporters when omitted.
2126
+ * @default [cliReporter, jsonReporter, fileReporter] // applied by `defineConfig` from the `kubb` package
2127
+ */
2128
+ reporters?: Array<Reporter>;
2199
2129
  };
2200
2130
  declare global {
2201
2131
  namespace Kubb {
@@ -2610,15 +2540,6 @@ type BuildOutput = {
2610
2540
  */
2611
2541
  storage: Storage;
2612
2542
  };
2613
- /**
2614
- * Type guard to check if a given config has an `input.path`.
2615
- */
2616
- declare function isInputPath(config: UserConfig | undefined): config is UserConfig<InputPath> & {
2617
- input: InputPath;
2618
- };
2619
- declare function isInputPath(config: Config | undefined): config is Config<InputPath> & {
2620
- input: InputPath;
2621
- };
2622
2543
  type CreateKubbOptions = {
2623
2544
  hooks?: AsyncEventEmitter<KubbHooks>;
2624
2545
  };
@@ -2820,7 +2741,7 @@ type UpdateDiagnostic = {
2820
2741
  */
2821
2742
  type Diagnostic = ProblemDiagnostic | PerformanceDiagnostic | UpdateDiagnostic;
2822
2743
  /**
2823
- * Maps each {@link DiagnosticCode} to the variant it selects, for {@link narrowDiagnostic}.
2744
+ * Maps each {@link DiagnosticCode} to the variant it selects, for {@link narrow}.
2824
2745
  * Every {@link ProblemCode} selects a {@link ProblemDiagnostic}, and the two bookkeeping codes
2825
2746
  * select their own variant.
2826
2747
  */
@@ -2830,44 +2751,13 @@ type DiagnosticByCode = Record<ProblemCode, ProblemDiagnostic> & Record<typeof d
2830
2751
  *
2831
2752
  * @example
2832
2753
  * ```ts
2833
- * const update = narrowDiagnostic(diagnostic, diagnosticCode.updateAvailable)
2754
+ * const update = narrow(diagnostic, diagnosticCode.updateAvailable)
2834
2755
  * if (update) {
2835
2756
  * console.log(update.latestVersion)
2836
2757
  * }
2837
2758
  * ```
2838
2759
  */
2839
- declare function narrowDiagnostic<C extends DiagnosticCode>(diagnostic: Diagnostic, code: C): DiagnosticByCode[C] | null;
2840
- /**
2841
- * Returns `true` when the diagnostic is a build {@link ProblemDiagnostic}.
2842
- *
2843
- * @example
2844
- * ```ts
2845
- * if (isProblemDiagnostic(diagnostic)) {
2846
- * console.log(diagnostic.location)
2847
- * }
2848
- * ```
2849
- */
2850
- declare const isProblemDiagnostic: (diagnostic: Diagnostic) => diagnostic is ProblemDiagnostic;
2851
- /**
2852
- * Returns `true` when the diagnostic is a per-plugin {@link PerformanceDiagnostic}.
2853
- *
2854
- * @example
2855
- * ```ts
2856
- * const timings = diagnostics.filter(isPerformanceDiagnostic)
2857
- * ```
2858
- */
2859
- declare const isPerformanceDiagnostic: (diagnostic: Diagnostic) => diagnostic is PerformanceDiagnostic;
2860
- /**
2861
- * Returns `true` when the diagnostic is a version-update {@link UpdateDiagnostic}.
2862
- *
2863
- * @example
2864
- * ```ts
2865
- * if (isUpdateDiagnostic(diagnostic)) {
2866
- * console.log(diagnostic.latestVersion)
2867
- * }
2868
- * ```
2869
- */
2870
- declare const isUpdateDiagnostic: (diagnostic: Diagnostic) => diagnostic is UpdateDiagnostic;
2760
+ declare function narrow<C extends DiagnosticCode>(diagnostic: Diagnostic, code: C): DiagnosticByCode[C] | null;
2871
2761
  /**
2872
2762
  * A {@link Diagnostic} reduced to its JSON-safe fields plus a `docsUrl`, for
2873
2763
  * machine-readable output (the `--reporter json` report, the MCP tools). Drops the
@@ -2885,24 +2775,6 @@ type SerializedDiagnostic = {
2885
2775
  */
2886
2776
  docsUrl?: string;
2887
2777
  };
2888
- /**
2889
- * An `Error` that carries a {@link Diagnostic}, so structured problems can flow
2890
- * through the existing throw/catch paths while keeping their code and location.
2891
- *
2892
- * @example
2893
- * ```ts
2894
- * throw new DiagnosticError({ code: diagnosticCode.refNotFound, severity: 'error', message: `Could not find ${ref}`, location: { kind: 'schema', pointer: ref, ref } })
2895
- * ```
2896
- */
2897
- declare class DiagnosticError extends Error {
2898
- diagnostic: ProblemDiagnostic;
2899
- constructor(diagnostic: ProblemDiagnostic);
2900
- }
2901
- /**
2902
- * Explanation for every {@link diagnosticCode}. Use {@link Diagnostics.explain} to look one up
2903
- * and `Diagnostics.docsUrl` for the matching kubb.dev page.
2904
- */
2905
- declare const diagnosticCatalog: Record<DiagnosticCode, DiagnosticDoc>;
2906
2778
  /**
2907
2779
  * Static helpers for working with {@link Diagnostic}s, plus the run-scoped sink
2908
2780
  * that lets deep code report a diagnostic without threading a callback.
@@ -2914,6 +2786,75 @@ declare const diagnosticCatalog: Record<DiagnosticCode, DiagnosticDoc>;
2914
2786
  */
2915
2787
  declare class Diagnostics {
2916
2788
  #private;
2789
+ /**
2790
+ * The diagnostic code catalog, exposed as `Diagnostics.code` (e.g. `Diagnostics.code.refNotFound`).
2791
+ */
2792
+ static code: {
2793
+ readonly unknown: "KUBB_UNKNOWN";
2794
+ readonly inputNotFound: "KUBB_INPUT_NOT_FOUND";
2795
+ readonly inputRequired: "KUBB_INPUT_REQUIRED";
2796
+ readonly refNotFound: "KUBB_REF_NOT_FOUND";
2797
+ readonly invalidServerVariable: "KUBB_INVALID_SERVER_VARIABLE";
2798
+ readonly pluginNotFound: "KUBB_PLUGIN_NOT_FOUND";
2799
+ readonly pluginFailed: "KUBB_PLUGIN_FAILED";
2800
+ readonly pluginWarning: "KUBB_PLUGIN_WARNING";
2801
+ readonly pluginInfo: "KUBB_PLUGIN_INFO";
2802
+ readonly unsupportedFormat: "KUBB_UNSUPPORTED_FORMAT";
2803
+ readonly deprecated: "KUBB_DEPRECATED";
2804
+ readonly adapterRequired: "KUBB_ADAPTER_REQUIRED";
2805
+ readonly pathTraversal: "KUBB_PATH_TRAVERSAL";
2806
+ readonly hookFailed: "KUBB_HOOK_FAILED";
2807
+ readonly formatFailed: "KUBB_FORMAT_FAILED";
2808
+ readonly lintFailed: "KUBB_LINT_FAILED";
2809
+ readonly performance: "KUBB_PERFORMANCE";
2810
+ readonly updateAvailable: "KUBB_UPDATE_AVAILABLE";
2811
+ };
2812
+ /**
2813
+ * Type guard for a build {@link ProblemDiagnostic}.
2814
+ */
2815
+ static isProblem: (diagnostic: Diagnostic) => diagnostic is ProblemDiagnostic;
2816
+ /**
2817
+ * Type guard for a version-update {@link UpdateDiagnostic}.
2818
+ */
2819
+ static isUpdate: (diagnostic: Diagnostic) => diagnostic is UpdateDiagnostic;
2820
+ /**
2821
+ * Type guard for a per-plugin {@link PerformanceDiagnostic}.
2822
+ */
2823
+ static isPerformance: (diagnostic: Diagnostic) => diagnostic is PerformanceDiagnostic;
2824
+ /**
2825
+ * Narrows a {@link Diagnostic} to the variant for `code`, or `null` when it does not match.
2826
+ */
2827
+ static narrow: typeof narrow;
2828
+ /**
2829
+ * An `Error` that carries a {@link Diagnostic}, so structured problems can flow
2830
+ * through the existing throw/catch paths while keeping their code and location.
2831
+ *
2832
+ * @example
2833
+ * ```ts
2834
+ * throw new Diagnostics.Error({ code: diagnosticCode.refNotFound, severity: 'error', message: `Could not find ${ref}`, location: { kind: 'schema', pointer: ref, ref } })
2835
+ * ```
2836
+ */
2837
+ static Error: {
2838
+ new (diagnostic: ProblemDiagnostic): {
2839
+ diagnostic: ProblemDiagnostic;
2840
+ name: string;
2841
+ message: string;
2842
+ stack?: string;
2843
+ cause?: unknown;
2844
+ };
2845
+ isError(error: unknown): error is Error;
2846
+ isError(value: unknown): value is Error;
2847
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
2848
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
2849
+ prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
2850
+ stackTraceLimit: number;
2851
+ };
2852
+ /**
2853
+ * Structural check for a {@link Diagnostics.Error}, including one thrown from a duplicated
2854
+ * `@kubb/core` copy where `instanceof` fails. Matches on the `name` and a `diagnostic`
2855
+ * that carries a `code`.
2856
+ */
2857
+ static isError(error: unknown): error is InstanceType<typeof Diagnostics.Error>;
2917
2858
  /**
2918
2859
  * Runs `fn` with `sink` as the active diagnostic sink for the whole async
2919
2860
  * subtree, so {@link Diagnostics.report} reaches it from anywhere inside.
@@ -2933,7 +2874,7 @@ declare class Diagnostics {
2933
2874
  */
2934
2875
  static emit(hooks: AsyncEventEmitter<KubbHooks>, diagnostic: ProblemDiagnostic | UpdateDiagnostic): Promise<void>;
2935
2876
  /**
2936
- * Coerces any thrown value into a {@link ProblemDiagnostic}. A {@link DiagnosticError}
2877
+ * Coerces any thrown value into a {@link ProblemDiagnostic}. A {@link Diagnostics.Error}
2937
2878
  * keeps its structured data, and anything else becomes a `KUBB_UNKNOWN` error.
2938
2879
  */
2939
2880
  static from(error: unknown): ProblemDiagnostic;
@@ -2998,7 +2939,25 @@ declare class Diagnostics {
2998
2939
  * fields are omitted rather than set to `undefined`.
2999
2940
  */
3000
2941
  static serialize(diagnostic: Diagnostic): SerializedDiagnostic;
2942
+ /**
2943
+ * Renders a {@link Diagnostic} for terminal output as its parts: the colored severity `symbol`
2944
+ * (the gutter glyph), the `plugin(CODE): message` `headline`, and the `details` lines (optional
2945
+ * `at <pointer>`, `help:`, and `docs:`).
2946
+ *
2947
+ * Hosts compose these to fit their gutter: a clack logger passes `symbol` as its own gutter and
2948
+ * `[headline, ...details]` as the message, while plain text outputs use {@link Diagnostics.formatLines}.
2949
+ */
2950
+ static format(diagnostic: Diagnostic): {
2951
+ symbol: string;
2952
+ headline: string;
2953
+ details: Array<string>;
2954
+ };
2955
+ /**
2956
+ * The self-contained block form of {@link Diagnostics.format}: `${symbol} ${headline}` followed by
2957
+ * the detail lines. Used where there is no gutter to own the symbol (plain and file output).
2958
+ */
2959
+ static formatLines(diagnostic: Diagnostic): Array<string>;
3001
2960
  }
3002
2961
  //#endregion
3003
- export { Exclude$1 as $, KubbFileProcessingUpdate as A, Parser as At, KubbLifecycleStartContext as B, RendererFactory as Bt, InputPath as C, LoggerContext as Ct, KubbConfigEndContext as D, FileProcessor as Dt, KubbBuildStartContext as E, defineLogger as Et, KubbGenerationStartContext as F, ReporterName as Ft, UserConfig as G, AdapterFactoryOptions as Gt, KubbSuccessContext as H, Storage as Ht, KubbHookEndContext as I, UserReporter as It, Generator$1 as J, diagnosticCode as Jt, createKubb as K, AdapterSource as Kt, KubbHookStartContext as L, createReporter as Lt, KubbFilesProcessingStartContext as M, GenerationResult as Mt, KubbFilesProcessingUpdateContext as N, Reporter as Nt, KubbDiagnosticContext as O, FileProcessorHooks as Ot, KubbGenerationEndContext as P, ReporterContext as Pt, FileManager as Q, KubbHooks as R, DevtoolsOptions as Rt, InputData as S, Logger as St, KubbBuildEndContext as T, UserLogger as Tt, KubbWarnContext as U, createStorage as Ut, KubbPluginsEndContext as V, createRenderer as Vt, PossibleConfig as W, Adapter as Wt, defineGenerator as X, AsyncEventEmitter as Xt, GeneratorContext as Y, logLevel as Yt, KubbDriver as Z, isUpdateDiagnostic as _, ResolverFileParams as _t, DiagnosticKind as a, NormalizedPlugin as at, CLIOptions as b, Middleware as bt, Diagnostics as c, Plugin as ct, ProblemDiagnostic as d, BannerMeta as dt, Group as et, SerializedDiagnostic as f, ResolveBannerContext as ft, isProblemDiagnostic as g, ResolverContext as gt, isPerformanceDiagnostic as h, Resolver as ht, DiagnosticError as i, KubbPluginStartContext as it, KubbFilesProcessingEndContext as j, defineParser as jt, KubbErrorContext as k, ParsedFile as kt, PerformanceDiagnostic as l, PluginFactoryOptions as lt, diagnosticCatalog as m, ResolveOptionsContext as mt, DiagnosticByCode as n, KubbPluginEndContext as nt, DiagnosticLocation as o, Output as ot, UpdateDiagnostic as p, ResolveBannerFile as pt, isInputPath as q, createAdapter as qt, DiagnosticDoc as r, KubbPluginSetupContext as rt, DiagnosticSeverity as s, Override as st, Diagnostic as t, Include as tt, ProblemCode as u, definePlugin as ut, narrowDiagnostic as v, ResolverPathParams as vt, Kubb$1 as w, LoggerOptions as wt, Config as x, defineMiddleware as xt, BuildOutput as y, defineResolver as yt, KubbInfoContext as z, Renderer as zt };
3004
- //# sourceMappingURL=diagnostics-B0ONXReg.d.ts.map
2962
+ export { Override as $, KubbHookEndContext as A, logLevel as At, createKubb as B, AsyncEventEmitter as Bt, KubbErrorContext as C, createReporter as Ct, KubbFilesProcessingUpdateContext as D, LoggerOptions as Dt, KubbFilesProcessingStartContext as E, LoggerContext as Et, KubbPluginsEndContext as F, createStorage as Ft, Exclude$1 as G, GeneratorContext as H, KubbSuccessContext as I, Adapter as It, KubbPluginEndContext as J, Group as K, KubbWarnContext as L, AdapterFactoryOptions as Lt, KubbHooks as M, RendererFactory as Mt, KubbInfoContext as N, createRenderer as Nt, KubbGenerationEndContext as O, UserLogger as Ot, KubbLifecycleStartContext as P, Storage as Pt, Output as Q, PossibleConfig as R, AdapterSource as Rt, KubbDiagnosticContext as S, UserReporter as St, KubbFilesProcessingEndContext as T, Logger as Tt, defineGenerator as U, Generator$1 as V, KubbDriver as W, KubbPluginStartContext as X, KubbPluginSetupContext as Y, NormalizedPlugin as Z, InputPath as _, defineParser as _t, DiagnosticLocation as a, ResolveBannerFile as at, KubbBuildStartContext as b, ReporterContext as bt, PerformanceDiagnostic as c, ResolverContext as ct, SerializedDiagnostic as d, defineResolver as dt, Plugin as et, UpdateDiagnostic as f, Middleware as ft, InputData as g, Parser as gt, Config as h, ParsedFile as ht, DiagnosticKind as i, ResolveBannerContext as it, KubbHookStartContext as j, Renderer as jt, KubbGenerationStartContext as k, defineLogger as kt, ProblemCode as l, ResolverFileParams as lt, CLIOptions as m, FileProcessorHooks as mt, DiagnosticByCode as n, definePlugin as nt, DiagnosticSeverity as o, ResolveOptionsContext as ot, BuildOutput as p, defineMiddleware as pt, Include as q, DiagnosticDoc as r, BannerMeta as rt, Diagnostics as s, Resolver as st, Diagnostic as t, PluginFactoryOptions as tt, ProblemDiagnostic as u, ResolverPathParams as ut, Kubb$1 as v, GenerationResult as vt, KubbFileProcessingUpdate as w, selectReporters as wt, KubbConfigEndContext as x, ReporterName as xt, KubbBuildEndContext as y, Reporter as yt, UserConfig as z, createAdapter as zt };
2963
+ //# sourceMappingURL=diagnostics-DhfW8YpT.d.ts.map