@kubb/core 5.0.0-beta.9 → 5.0.0-beta.91

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