@kubb/core 5.0.0-beta.89 → 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.
- package/dist/index.cjs +98 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +52 -4
- package/dist/index.js +97 -48
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.js +1 -1
- package/dist/{Diagnostics-CM0-Ae30.d.ts → types-aNebW3Ui.d.ts} +692 -731
- package/dist/{usingCtx-Cnrm3TcM.js → usingCtx-BriKju-v.js} +5 -9
- package/dist/{usingCtx-Cnrm3TcM.js.map → usingCtx-BriKju-v.js.map} +1 -1
- package/dist/{usingCtx-BN2OKJRx.cjs → usingCtx-eyNeehd2.cjs} +5 -9
- package/dist/{usingCtx-BN2OKJRx.cjs.map → usingCtx-eyNeehd2.cjs.map} +1 -1
- package/package.json +2 -2
|
@@ -56,7 +56,7 @@ type AdapterFactoryOptions<TName extends string = string, TOptions extends objec
|
|
|
56
56
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
57
57
|
*
|
|
58
58
|
* export default defineConfig({
|
|
59
|
-
* input:
|
|
59
|
+
* input: './petStore.yaml',
|
|
60
60
|
* output: { path: './src/gen' },
|
|
61
61
|
* adapter: adapterOas(),
|
|
62
62
|
* plugins: [pluginTs()],
|
|
@@ -143,7 +143,7 @@ declare const diagnosticCode: {
|
|
|
143
143
|
*/
|
|
144
144
|
readonly unknown: "KUBB_UNKNOWN";
|
|
145
145
|
/**
|
|
146
|
-
* The
|
|
146
|
+
* The file or URL set as `input` could not be read.
|
|
147
147
|
*/
|
|
148
148
|
readonly inputNotFound: "KUBB_INPUT_NOT_FOUND";
|
|
149
149
|
/**
|
|
@@ -224,6 +224,454 @@ declare const diagnosticCode: {
|
|
|
224
224
|
*/
|
|
225
225
|
type DiagnosticCode = (typeof diagnosticCode)[keyof typeof diagnosticCode];
|
|
226
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
|
|
227
675
|
//#region src/createReporter.d.ts
|
|
228
676
|
/**
|
|
229
677
|
* Numeric log-level thresholds used internally to compare verbosity.
|
|
@@ -365,11 +813,6 @@ type Storage = {
|
|
|
365
813
|
* Removes every entry. Pass `base` to scope the wipe to a key prefix.
|
|
366
814
|
*/
|
|
367
815
|
clear(base?: string): Promise<void>;
|
|
368
|
-
/**
|
|
369
|
-
* Optional teardown hook for a backend to flush buffers, close connections,
|
|
370
|
-
* or release file locks.
|
|
371
|
-
*/
|
|
372
|
-
dispose?(): Promise<void>;
|
|
373
816
|
};
|
|
374
817
|
/**
|
|
375
818
|
* Defines a custom storage backend. The builder receives user options and
|
|
@@ -1031,10 +1474,6 @@ type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactor
|
|
|
1031
1474
|
* generated folder verbatim, instead of building its content from `sources`.
|
|
1032
1475
|
*/
|
|
1033
1476
|
injectFile(userFileNode: UserFileNode): void;
|
|
1034
|
-
/**
|
|
1035
|
-
* Merge a partial config update into the current build configuration.
|
|
1036
|
-
*/
|
|
1037
|
-
updateConfig(config: Partial<Config>): void;
|
|
1038
1477
|
/**
|
|
1039
1478
|
* The resolved build configuration at setup time.
|
|
1040
1479
|
*/
|
|
@@ -1148,9 +1587,6 @@ type KubbPluginEndContext = {
|
|
|
1148
1587
|
declare function definePlugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(factory: (options: TFactory['options']) => Plugin<TFactory>): (options?: TFactory['options']) => Plugin<TFactory>;
|
|
1149
1588
|
//#endregion
|
|
1150
1589
|
//#region src/defineParser.d.ts
|
|
1151
|
-
type PrintOptions = {
|
|
1152
|
-
extname?: FileNode['extname'];
|
|
1153
|
-
};
|
|
1154
1590
|
/**
|
|
1155
1591
|
* Converts a resolved {@link FileNode} into the final source string that gets
|
|
1156
1592
|
* written to disk. Kubb ships with TypeScript and TSX parsers. Add your own
|
|
@@ -1173,7 +1609,7 @@ type Parser<TMeta extends object = object, TNode = unknown> = {
|
|
|
1173
1609
|
/**
|
|
1174
1610
|
* Serialize the file's AST into source code.
|
|
1175
1611
|
*/
|
|
1176
|
-
parse(file: FileNode<TMeta
|
|
1612
|
+
parse(file: FileNode<TMeta>): string;
|
|
1177
1613
|
/**
|
|
1178
1614
|
* Render compiler AST nodes for this parser's language into source text.
|
|
1179
1615
|
* Plugins call this to format the nodes they assemble before handing them
|
|
@@ -1182,124 +1618,33 @@ type Parser<TMeta extends object = object, TNode = unknown> = {
|
|
|
1182
1618
|
print(...nodes: Array<TNode>): string;
|
|
1183
1619
|
};
|
|
1184
1620
|
/**
|
|
1185
|
-
*
|
|
1186
|
-
*
|
|
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' } })`).
|
|
1187
1628
|
*
|
|
1188
1629
|
* @example
|
|
1189
1630
|
* ```ts
|
|
1190
1631
|
* import { defineParser } from '@kubb/core'
|
|
1191
1632
|
* import { extractStringsFromNodes } from '@kubb/ast'
|
|
1192
1633
|
*
|
|
1193
|
-
* export const
|
|
1634
|
+
* export const parserJson = defineParser((options: { pretty?: boolean } = {}) => ({
|
|
1194
1635
|
* name: 'json',
|
|
1195
1636
|
* extNames: ['.json'],
|
|
1196
1637
|
* parse(file) {
|
|
1197
|
-
*
|
|
1198
|
-
*
|
|
1199
|
-
* .join('\n')
|
|
1638
|
+
* const source = file.sources.map((source) => extractStringsFromNodes(source.nodes ?? [])).join('\n')
|
|
1639
|
+
* return options.pretty ? JSON.stringify(JSON.parse(source), null, 2) : source
|
|
1200
1640
|
* },
|
|
1201
1641
|
* print(...nodes) {
|
|
1202
1642
|
* return nodes.map(String).join('\n')
|
|
1203
1643
|
* },
|
|
1204
|
-
* })
|
|
1205
|
-
* ```
|
|
1206
|
-
*/
|
|
1207
|
-
declare function defineParser<T extends Parser>(parser: T): T;
|
|
1208
|
-
//#endregion
|
|
1209
|
-
//#region src/Hookable.d.ts
|
|
1210
|
-
/**
|
|
1211
|
-
* A function that can be registered as a hook listener, synchronous or async. Any return value is
|
|
1212
|
-
* allowed and ignored, so handlers that return a result for their own callers still register.
|
|
1213
|
-
*/
|
|
1214
|
-
type AsyncListener<TArgs extends Array<unknown>> = (...args: TArgs) => unknown;
|
|
1215
|
-
/**
|
|
1216
|
-
* Typed hook emitter that awaits all async listeners before resolving.
|
|
1217
|
-
* Wraps Node's `EventEmitter` with full TypeScript hook-map inference.
|
|
1218
|
-
*
|
|
1219
|
-
* @example
|
|
1220
|
-
* ```ts
|
|
1221
|
-
* const hooks = new Hookable<{ build: [name: string] }>()
|
|
1222
|
-
* hooks.hook('build', async (name) => { console.log(name) })
|
|
1223
|
-
* await hooks.callHook('build', 'petstore') // all listeners awaited
|
|
1644
|
+
* }))
|
|
1224
1645
|
* ```
|
|
1225
1646
|
*/
|
|
1226
|
-
declare
|
|
1227
|
-
#private;
|
|
1228
|
-
/**
|
|
1229
|
-
* Maximum number of listeners per hook before Node emits a memory-leak warning.
|
|
1230
|
-
* @default 10
|
|
1231
|
-
*/
|
|
1232
|
-
constructor(maxListener?: number);
|
|
1233
|
-
/**
|
|
1234
|
-
* Calls `hookName` and awaits all registered listeners sequentially.
|
|
1235
|
-
* Throws if any listener rejects, wrapping the cause with the hook name and serialized arguments.
|
|
1236
|
-
*
|
|
1237
|
-
* @example
|
|
1238
|
-
* ```ts
|
|
1239
|
-
* await hooks.callHook('build', 'petstore')
|
|
1240
|
-
* ```
|
|
1241
|
-
*/
|
|
1242
|
-
callHook<THookName extends keyof THooks & string>(hookName: THookName, ...hookArgs: THooks[THookName]): Promise<void> | void;
|
|
1243
|
-
/**
|
|
1244
|
-
* Registers a persistent listener for `hookName` and returns a function that removes it.
|
|
1245
|
-
*
|
|
1246
|
-
* @example
|
|
1247
|
-
* ```ts
|
|
1248
|
-
* const unhook = hooks.hook('build', async (name) => { console.log(name) })
|
|
1249
|
-
* unhook() // removes it
|
|
1250
|
-
* ```
|
|
1251
|
-
*/
|
|
1252
|
-
hook<THookName extends keyof THooks & string>(hookName: THookName, handler: AsyncListener<THooks[THookName]>): () => void;
|
|
1253
|
-
/**
|
|
1254
|
-
* Registers every handler in `configHooks` at once and returns a function that removes them
|
|
1255
|
-
* all. Undefined entries are skipped, so a partial hook object registers only its present keys.
|
|
1256
|
-
*
|
|
1257
|
-
* @example
|
|
1258
|
-
* ```ts
|
|
1259
|
-
* const unhook = hooks.addHooks({ build: onBuild, done: onDone })
|
|
1260
|
-
* unhook() // removes both
|
|
1261
|
-
* ```
|
|
1262
|
-
*/
|
|
1263
|
-
addHooks(configHooks: Partial<{ [K in keyof THooks & string]: AsyncListener<THooks[K]> }>): () => void;
|
|
1264
|
-
/**
|
|
1265
|
-
* Removes a previously registered listener.
|
|
1266
|
-
*
|
|
1267
|
-
* @example
|
|
1268
|
-
* ```ts
|
|
1269
|
-
* hooks.removeHook('build', handler)
|
|
1270
|
-
* ```
|
|
1271
|
-
*/
|
|
1272
|
-
removeHook<THookName extends keyof THooks & string>(hookName: THookName, handler: AsyncListener<THooks[THookName]>): void;
|
|
1273
|
-
/**
|
|
1274
|
-
* Returns the number of listeners registered for `hookName`.
|
|
1275
|
-
*
|
|
1276
|
-
* @example
|
|
1277
|
-
* ```ts
|
|
1278
|
-
* hooks.hook('build', handler)
|
|
1279
|
-
* hooks.listenerCount('build') // 1
|
|
1280
|
-
* ```
|
|
1281
|
-
*/
|
|
1282
|
-
listenerCount<THookName extends keyof THooks & string>(hookName: THookName): number;
|
|
1283
|
-
/**
|
|
1284
|
-
* Raises or lowers the per-hook listener ceiling before Node warns about a memory leak.
|
|
1285
|
-
* Set this above the expected listener count when many listeners attach by design.
|
|
1286
|
-
*
|
|
1287
|
-
* @example
|
|
1288
|
-
* ```ts
|
|
1289
|
-
* hooks.setMaxListeners(40)
|
|
1290
|
-
* ```
|
|
1291
|
-
*/
|
|
1292
|
-
setMaxListeners(max: number): void;
|
|
1293
|
-
/**
|
|
1294
|
-
* Removes all listeners from every hook channel.
|
|
1295
|
-
*
|
|
1296
|
-
* @example
|
|
1297
|
-
* ```ts
|
|
1298
|
-
* hooks.removeAllHooks()
|
|
1299
|
-
* ```
|
|
1300
|
-
*/
|
|
1301
|
-
removeAllHooks(): void;
|
|
1302
|
-
}
|
|
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>;
|
|
1303
1648
|
//#endregion
|
|
1304
1649
|
//#region src/FileManager.d.ts
|
|
1305
1650
|
/**
|
|
@@ -1318,7 +1663,6 @@ type FileManagerHooks = {
|
|
|
1318
1663
|
};
|
|
1319
1664
|
type ParseOptions = {
|
|
1320
1665
|
parsers?: Map<FileNode['extname'], Parser>;
|
|
1321
|
-
extension?: Record<FileNode['extname'], FileNode['extname'] | ''>;
|
|
1322
1666
|
};
|
|
1323
1667
|
type WriteOptions = ParseOptions & {
|
|
1324
1668
|
storage: Storage;
|
|
@@ -1357,8 +1701,7 @@ declare class FileManager {
|
|
|
1357
1701
|
* Converts a file's AST sources (or its `copy` source) into the final on-disk string.
|
|
1358
1702
|
*/
|
|
1359
1703
|
parse(file: FileNode, {
|
|
1360
|
-
parsers
|
|
1361
|
-
extension
|
|
1704
|
+
parsers
|
|
1362
1705
|
}?: ParseOptions): Promise<string>;
|
|
1363
1706
|
/**
|
|
1364
1707
|
* Converts and writes every file at once, letting `storage.setItem` decide how much of
|
|
@@ -1366,8 +1709,7 @@ declare class FileManager {
|
|
|
1366
1709
|
*/
|
|
1367
1710
|
write(files: Array<FileNode>, {
|
|
1368
1711
|
storage,
|
|
1369
|
-
parsers
|
|
1370
|
-
extension
|
|
1712
|
+
parsers
|
|
1371
1713
|
}: WriteOptions): Promise<void>;
|
|
1372
1714
|
}
|
|
1373
1715
|
//#endregion
|
|
@@ -1750,7 +2092,7 @@ declare class Kubb$1 {
|
|
|
1750
2092
|
* import { pluginTs } from '@kubb/plugin-ts'
|
|
1751
2093
|
*
|
|
1752
2094
|
* const kubb = createKubb({
|
|
1753
|
-
* input:
|
|
2095
|
+
* input: './petStore.yaml',
|
|
1754
2096
|
* output: { path: './src/gen' },
|
|
1755
2097
|
* adapter: adapterOas(),
|
|
1756
2098
|
* plugins: [pluginTs()],
|
|
@@ -1767,38 +2109,22 @@ declare function createKubb(userConfig: UserConfig, options?: CreateKubbOptions)
|
|
|
1767
2109
|
*/
|
|
1768
2110
|
type ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {};
|
|
1769
2111
|
/**
|
|
1770
|
-
*
|
|
1771
|
-
*
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
};
|
|
1785
|
-
/**
|
|
1786
|
-
* Inline spec to generate from, passed directly instead of read from a file. A string
|
|
1787
|
-
* (YAML/JSON) or a parsed object.
|
|
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
|
+
* ```
|
|
1788
2126
|
*/
|
|
1789
|
-
type
|
|
1790
|
-
/**
|
|
1791
|
-
* Swagger/OpenAPI data as a string (YAML/JSON) or a parsed object.
|
|
1792
|
-
*
|
|
1793
|
-
* @example
|
|
1794
|
-
* ```ts
|
|
1795
|
-
* { data: fs.readFileSync('./openapi.yaml', 'utf8') }
|
|
1796
|
-
* { data: { openapi: '3.1.0', info: { ... } } }
|
|
1797
|
-
* ```
|
|
1798
|
-
*/
|
|
1799
|
-
data: string | unknown;
|
|
1800
|
-
};
|
|
1801
|
-
type Input = InputPath | InputData;
|
|
2127
|
+
type Input = string | Record<string, unknown>;
|
|
1802
2128
|
/**
|
|
1803
2129
|
* Resolved build configuration for a Kubb run: what to generate from (adapter, input), where to
|
|
1804
2130
|
* write it (output), how (plugins), and the runtime pieces (parsers, storage). See
|
|
@@ -1828,7 +2154,7 @@ type Config<TInput = Input> = {
|
|
|
1828
2154
|
* set of file extensions, and a fallback parser handles anything else.
|
|
1829
2155
|
*
|
|
1830
2156
|
* Already resolved on the `Config` instance (see `UserConfig` for the
|
|
1831
|
-
* optional form that defaults to `[parserTs, parserTsx, parserMd]`).
|
|
2157
|
+
* optional form that defaults to `[parserTs(), parserTsx(), parserMd()]`).
|
|
1832
2158
|
*
|
|
1833
2159
|
* @example
|
|
1834
2160
|
* ```ts
|
|
@@ -1836,7 +2162,7 @@ type Config<TInput = Input> = {
|
|
|
1836
2162
|
* import { parserTs, parserTsx } from '@kubb/parser-ts'
|
|
1837
2163
|
*
|
|
1838
2164
|
* export default defineConfig({
|
|
1839
|
-
* parsers: [parserTs, parserTsx],
|
|
2165
|
+
* parsers: [parserTs(), parserTsx()],
|
|
1840
2166
|
* })
|
|
1841
2167
|
* ```
|
|
1842
2168
|
*/
|
|
@@ -1854,14 +2180,14 @@ type Config<TInput = Input> = {
|
|
|
1854
2180
|
* import { adapterOas } from '@kubb/adapter-oas'
|
|
1855
2181
|
* export default defineConfig({
|
|
1856
2182
|
* adapter: adapterOas(),
|
|
1857
|
-
* input:
|
|
2183
|
+
* input: './petstore.yaml',
|
|
1858
2184
|
* })
|
|
1859
2185
|
* ```
|
|
1860
2186
|
*/
|
|
1861
2187
|
adapter?: Adapter;
|
|
1862
2188
|
/**
|
|
1863
|
-
* Source file
|
|
1864
|
-
*
|
|
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.
|
|
1865
2191
|
* Required when an adapter is configured. Omit it when running in plugin-only mode.
|
|
1866
2192
|
*/
|
|
1867
2193
|
input?: TInput;
|
|
@@ -1912,18 +2238,6 @@ type Config<TInput = Input> = {
|
|
|
1912
2238
|
* ```
|
|
1913
2239
|
*/
|
|
1914
2240
|
lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false;
|
|
1915
|
-
/**
|
|
1916
|
-
* Rewrite import extensions in generated files, e.g. emit `.js` imports from `.ts` sources for
|
|
1917
|
-
* ESM dual packages. Keys are the source extension, values the output, and `''` drops it.
|
|
1918
|
-
*
|
|
1919
|
-
* @default { '.ts': '.ts' }
|
|
1920
|
-
* @example
|
|
1921
|
-
* ```ts
|
|
1922
|
-
* extension: { '.ts': '.js' } // generates import './api.js' instead of './api.ts'
|
|
1923
|
-
* extension: { '.ts': '', '.tsx': '.jsx' }
|
|
1924
|
-
* ```
|
|
1925
|
-
*/
|
|
1926
|
-
extension?: Record<FileNode['extname'], FileNode['extname'] | ''>;
|
|
1927
2241
|
/**
|
|
1928
2242
|
* Banner prepended to every generated file. `'simple'` is the basic Kubb notice, `'full'` adds
|
|
1929
2243
|
* source, title, description, and API version, and `false` omits it.
|
|
@@ -2032,7 +2346,7 @@ type Config<TInput = Input> = {
|
|
|
2032
2346
|
* @example
|
|
2033
2347
|
* ```ts
|
|
2034
2348
|
* export default defineConfig({
|
|
2035
|
-
* input:
|
|
2349
|
+
* input: './petstore.yaml',
|
|
2036
2350
|
* output: { path: './src/gen' },
|
|
2037
2351
|
* plugins: [pluginTs(), pluginZod()],
|
|
2038
2352
|
* })
|
|
@@ -2046,7 +2360,7 @@ type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'par
|
|
|
2046
2360
|
root?: string;
|
|
2047
2361
|
/**
|
|
2048
2362
|
* Custom parsers that convert generated AST nodes to strings (TypeScript, JSON, markdown, etc.).
|
|
2049
|
-
* @default [parserTs, parserTsx, parserMd] // applied by `defineConfig` from the `kubb` package
|
|
2363
|
+
* @default [parserTs(), parserTsx(), parserMd()] // applied by `defineConfig` from the `kubb` package
|
|
2050
2364
|
*/
|
|
2051
2365
|
parsers?: Array<Parser>;
|
|
2052
2366
|
/**
|
|
@@ -2190,665 +2504,312 @@ type KubbBuildStartContext = {
|
|
|
2190
2504
|
*/
|
|
2191
2505
|
adapter: Adapter;
|
|
2192
2506
|
/**
|
|
2193
|
-
* Metadata about the parsed document (title, version, base URL, circular schema names, enum names).
|
|
2194
|
-
* To observe individual schemas and operations use the `kubb:generate:schema` / `kubb:generate:operation` hooks.
|
|
2195
|
-
*/
|
|
2196
|
-
meta: InputMeta | undefined;
|
|
2197
|
-
/**
|
|
2198
|
-
* Looks up a registered plugin by name, typed by the plugin registry.
|
|
2199
|
-
*/
|
|
2200
|
-
getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
|
|
2201
|
-
getPlugin(name: string): Plugin | undefined;
|
|
2202
|
-
/**
|
|
2203
|
-
* Snapshot of all files accumulated so far.
|
|
2204
|
-
*/
|
|
2205
|
-
readonly files: ReadonlyArray<FileNode>;
|
|
2206
|
-
/**
|
|
2207
|
-
* Adds or merges one or more files into the file manager.
|
|
2208
|
-
*/
|
|
2209
|
-
upsertFile: (...files: Array<FileNode>) => void;
|
|
2210
|
-
};
|
|
2211
|
-
type KubbPluginsEndContext = {
|
|
2212
|
-
/**
|
|
2213
|
-
* Resolved configuration for this build.
|
|
2214
|
-
*/
|
|
2215
|
-
config: Config;
|
|
2216
|
-
/**
|
|
2217
|
-
* Snapshot of all files accumulated across all plugins.
|
|
2218
|
-
*/
|
|
2219
|
-
readonly files: ReadonlyArray<FileNode>;
|
|
2220
|
-
/**
|
|
2221
|
-
* Adds or merges one or more files into the file manager.
|
|
2222
|
-
*/
|
|
2223
|
-
upsertFile: (...files: Array<FileNode>) => void;
|
|
2224
|
-
};
|
|
2225
|
-
type KubbBuildEndContext = {
|
|
2226
|
-
/**
|
|
2227
|
-
* All files generated during this build.
|
|
2228
|
-
*/
|
|
2229
|
-
files: Array<FileNode>;
|
|
2230
|
-
/**
|
|
2231
|
-
* Resolved configuration for this build.
|
|
2232
|
-
*/
|
|
2233
|
-
config: Config;
|
|
2234
|
-
/**
|
|
2235
|
-
* Absolute path to the output directory.
|
|
2236
|
-
*/
|
|
2237
|
-
outputDir: string;
|
|
2238
|
-
};
|
|
2239
|
-
type KubbLifecycleStartContext = {
|
|
2240
|
-
/**
|
|
2241
|
-
* Current Kubb version string.
|
|
2242
|
-
*/
|
|
2243
|
-
version: string;
|
|
2244
|
-
};
|
|
2245
|
-
type KubbGenerationStartContext = {
|
|
2246
|
-
/**
|
|
2247
|
-
* Resolved configuration for this generation run.
|
|
2248
|
-
*/
|
|
2249
|
-
config: Config;
|
|
2250
|
-
};
|
|
2251
|
-
type KubbGenerationEndContext = {
|
|
2252
|
-
/**
|
|
2253
|
-
* Resolved configuration for this generation run.
|
|
2254
|
-
*/
|
|
2255
|
-
config: Config;
|
|
2256
|
-
/**
|
|
2257
|
-
* Read-only view of the files written during this build.
|
|
2258
|
-
* Reads go directly to `config.storage`, nothing extra is held in memory.
|
|
2259
|
-
*
|
|
2260
|
-
* @example Read a generated file
|
|
2261
|
-
* `const code = await storage.getItem('/src/gen/pet.ts')`
|
|
2262
|
-
*
|
|
2263
|
-
* @example Walk every generated file
|
|
2264
|
-
* ```ts
|
|
2265
|
-
* for (const path of await storage.getKeys()) {
|
|
2266
|
-
* const code = await storage.getItem(path)
|
|
2267
|
-
* }
|
|
2268
|
-
* ```
|
|
2269
|
-
*/
|
|
2270
|
-
storage: Storage;
|
|
2271
|
-
/**
|
|
2272
|
-
* Diagnostics collected during the build: error/warning/info problems plus a
|
|
2273
|
-
* `performance` diagnostic per plugin. The end-of-run summary derives its failure counts
|
|
2274
|
-
* and per-plugin timings from these. Set by the CLI runner, omitted by other callers.
|
|
2275
|
-
*/
|
|
2276
|
-
diagnostics?: Array<Diagnostic>;
|
|
2277
|
-
/**
|
|
2278
|
-
* `'success'` when all plugins completed without errors, `'failed'` otherwise.
|
|
2279
|
-
*/
|
|
2280
|
-
status?: 'success' | 'failed';
|
|
2281
|
-
/**
|
|
2282
|
-
* High-resolution start time from `process.hrtime()`, used to compute the elapsed time.
|
|
2283
|
-
*/
|
|
2284
|
-
hrStart?: [number, number];
|
|
2285
|
-
/**
|
|
2286
|
-
* Total number of files created during this run.
|
|
2287
|
-
*/
|
|
2288
|
-
filesCreated?: number;
|
|
2289
|
-
};
|
|
2290
|
-
type KubbInfoContext = {
|
|
2291
|
-
/**
|
|
2292
|
-
* Human-readable info message.
|
|
2293
|
-
*/
|
|
2294
|
-
message: string;
|
|
2295
|
-
/**
|
|
2296
|
-
* Optional supplementary detail.
|
|
2297
|
-
*/
|
|
2298
|
-
info?: string;
|
|
2299
|
-
};
|
|
2300
|
-
type KubbErrorContext = {
|
|
2301
|
-
/**
|
|
2302
|
-
* The caught error.
|
|
2303
|
-
*/
|
|
2304
|
-
error: Error;
|
|
2305
|
-
/**
|
|
2306
|
-
* Optional structured metadata for additional context.
|
|
2307
|
-
*/
|
|
2308
|
-
meta?: Record<string, unknown>;
|
|
2309
|
-
};
|
|
2310
|
-
type KubbSuccessContext = {
|
|
2311
|
-
/**
|
|
2312
|
-
* Human-readable success message.
|
|
2313
|
-
*/
|
|
2314
|
-
message: string;
|
|
2315
|
-
/**
|
|
2316
|
-
* Optional supplementary detail.
|
|
2317
|
-
*/
|
|
2318
|
-
info?: string;
|
|
2319
|
-
};
|
|
2320
|
-
type KubbWarnContext = {
|
|
2321
|
-
/**
|
|
2322
|
-
* Human-readable warning message.
|
|
2323
|
-
*/
|
|
2324
|
-
message: string;
|
|
2325
|
-
/**
|
|
2326
|
-
* Optional supplementary detail.
|
|
2327
|
-
*/
|
|
2328
|
-
info?: string;
|
|
2329
|
-
};
|
|
2330
|
-
type KubbDiagnosticContext = {
|
|
2331
|
-
/**
|
|
2332
|
-
* The structured diagnostic to render: a build problem or a version-update notice.
|
|
2333
|
-
*/
|
|
2334
|
-
diagnostic: ProblemDiagnostic | UpdateDiagnostic;
|
|
2335
|
-
};
|
|
2336
|
-
type KubbFilesProcessingStartContext = {
|
|
2337
|
-
/**
|
|
2338
|
-
* Files about to be serialized and written.
|
|
2339
|
-
*/
|
|
2340
|
-
files: Array<FileNode>;
|
|
2341
|
-
};
|
|
2342
|
-
type KubbFileProcessingUpdate = {
|
|
2343
|
-
/**
|
|
2344
|
-
* Number of files processed so far in this batch.
|
|
2345
|
-
*/
|
|
2346
|
-
processed: number;
|
|
2347
|
-
/**
|
|
2348
|
-
* Total number of files in this batch.
|
|
2349
|
-
*/
|
|
2350
|
-
total: number;
|
|
2351
|
-
/**
|
|
2352
|
-
* Completion percentage, `0` to `100`.
|
|
2353
|
-
*/
|
|
2354
|
-
percentage: number;
|
|
2355
|
-
/**
|
|
2356
|
-
* Serialized file content, or `undefined` when the file produced no output.
|
|
2357
|
-
*/
|
|
2358
|
-
source?: string;
|
|
2359
|
-
/**
|
|
2360
|
-
* The file that was just processed.
|
|
2361
|
-
*/
|
|
2362
|
-
file: FileNode;
|
|
2363
|
-
/**
|
|
2364
|
-
* Resolved configuration for this build.
|
|
2365
|
-
*/
|
|
2366
|
-
config: Config;
|
|
2367
|
-
};
|
|
2368
|
-
type KubbFilesProcessingUpdateContext = {
|
|
2369
|
-
/**
|
|
2370
|
-
* All files processed in this flush chunk.
|
|
2371
|
-
*/
|
|
2372
|
-
files: Array<KubbFileProcessingUpdate>;
|
|
2373
|
-
};
|
|
2374
|
-
type KubbFilesProcessingEndContext = {
|
|
2375
|
-
/**
|
|
2376
|
-
* All files that were serialized in this batch.
|
|
2377
|
-
*/
|
|
2378
|
-
files: Array<FileNode>;
|
|
2379
|
-
};
|
|
2380
|
-
type KubbHookStartContext = {
|
|
2381
|
-
/**
|
|
2382
|
-
* Optional identifier for correlating start/end hooks.
|
|
2383
|
-
*/
|
|
2384
|
-
id?: string;
|
|
2385
|
-
/**
|
|
2386
|
-
* The shell command that is about to run.
|
|
2387
|
-
*/
|
|
2388
|
-
command: string;
|
|
2389
|
-
/**
|
|
2390
|
-
* Parsed argument list, when available.
|
|
2391
|
-
*/
|
|
2392
|
-
args?: ReadonlyArray<string>;
|
|
2393
|
-
};
|
|
2394
|
-
/**
|
|
2395
|
-
* Emitted for each line streamed from a hook's stdout while it runs.
|
|
2396
|
-
* A logger correlates the line to its active UI element via `id`.
|
|
2397
|
-
*/
|
|
2398
|
-
type KubbHookLineContext = {
|
|
2399
|
-
/**
|
|
2400
|
-
* Identifier matching the corresponding `kubb:hook:start` hook.
|
|
2401
|
-
*/
|
|
2402
|
-
id: string;
|
|
2403
|
-
/**
|
|
2404
|
-
* A single streamed stdout line, without its trailing newline.
|
|
2405
|
-
*/
|
|
2406
|
-
line: string;
|
|
2407
|
-
};
|
|
2408
|
-
type KubbHookEndContext = {
|
|
2409
|
-
/**
|
|
2410
|
-
* Optional identifier matching the corresponding `kubb:hook:start` hook.
|
|
2411
|
-
*/
|
|
2412
|
-
id?: string;
|
|
2413
|
-
/**
|
|
2414
|
-
* The shell command that ran.
|
|
2415
|
-
*/
|
|
2416
|
-
command: string;
|
|
2417
|
-
/**
|
|
2418
|
-
* Parsed argument list, when available.
|
|
2419
|
-
*/
|
|
2420
|
-
args?: ReadonlyArray<string>;
|
|
2421
|
-
/**
|
|
2422
|
-
* `true` when the command exited with code `0`.
|
|
2423
|
-
*/
|
|
2424
|
-
success: boolean;
|
|
2425
|
-
/**
|
|
2426
|
-
* Error thrown by the command, or `null` on success.
|
|
2427
|
-
*/
|
|
2428
|
-
error: Error | null;
|
|
2429
|
-
/**
|
|
2430
|
-
* Captured stdout from the process, populated when it exits non-zero.
|
|
2431
|
-
*/
|
|
2432
|
-
stdout?: string;
|
|
2433
|
-
/**
|
|
2434
|
-
* Captured stderr from the process, populated when it exits non-zero.
|
|
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.
|
|
2435
2509
|
*/
|
|
2436
|
-
|
|
2437
|
-
};
|
|
2438
|
-
/**
|
|
2439
|
-
* CLI options derived from command-line flags.
|
|
2440
|
-
*/
|
|
2441
|
-
type CLIOptions = {
|
|
2510
|
+
meta: InputMeta | undefined;
|
|
2442
2511
|
/**
|
|
2443
|
-
*
|
|
2512
|
+
* Looks up a registered plugin by name, typed by the plugin registry.
|
|
2444
2513
|
*/
|
|
2445
|
-
|
|
2514
|
+
getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
|
|
2515
|
+
getPlugin(name: string): Plugin | undefined;
|
|
2446
2516
|
/**
|
|
2447
|
-
*
|
|
2448
|
-
* Overrides `config.input.path` when set.
|
|
2517
|
+
* Snapshot of all files accumulated so far.
|
|
2449
2518
|
*/
|
|
2450
|
-
|
|
2519
|
+
readonly files: ReadonlyArray<FileNode>;
|
|
2451
2520
|
/**
|
|
2452
|
-
*
|
|
2521
|
+
* Adds or merges one or more files into the file manager.
|
|
2453
2522
|
*/
|
|
2454
|
-
|
|
2523
|
+
upsertFile: (...files: Array<FileNode>) => void;
|
|
2524
|
+
};
|
|
2525
|
+
type KubbPluginsEndContext = {
|
|
2455
2526
|
/**
|
|
2456
|
-
*
|
|
2457
|
-
*
|
|
2458
|
-
* @default 'info'
|
|
2527
|
+
* Resolved configuration for this build.
|
|
2459
2528
|
*/
|
|
2460
|
-
|
|
2529
|
+
config: Config;
|
|
2461
2530
|
/**
|
|
2462
|
-
*
|
|
2531
|
+
* Snapshot of all files accumulated across all plugins.
|
|
2463
2532
|
*/
|
|
2464
|
-
|
|
2465
|
-
};
|
|
2466
|
-
/**
|
|
2467
|
-
* All accepted forms of a Kubb configuration.
|
|
2468
|
-
* Accepts `Config`/`Config[]`/promise or a factory (optionally receiving `TCliOptions`).
|
|
2469
|
-
*/
|
|
2470
|
-
type PossibleConfig<TCliOptions = undefined> = PossiblePromise<Config | Array<Config>> | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Array<Config>>);
|
|
2471
|
-
/**
|
|
2472
|
-
* Full output produced by a successful or failed build.
|
|
2473
|
-
*/
|
|
2474
|
-
type BuildOutput = {
|
|
2533
|
+
readonly files: ReadonlyArray<FileNode>;
|
|
2475
2534
|
/**
|
|
2476
|
-
*
|
|
2477
|
-
* (each with a code, severity, and where known a JSON-pointer location) plus a
|
|
2478
|
-
* `performance` diagnostic per plugin. Includes a top-level diagnostic when the build
|
|
2479
|
-
* threw before completing. Use {@link Diagnostics.hasError} to test for failure.
|
|
2535
|
+
* Adds or merges one or more files into the file manager.
|
|
2480
2536
|
*/
|
|
2481
|
-
|
|
2537
|
+
upsertFile: (...files: Array<FileNode>) => void;
|
|
2538
|
+
};
|
|
2539
|
+
type KubbBuildEndContext = {
|
|
2482
2540
|
/**
|
|
2483
2541
|
* All files generated during this build.
|
|
2484
2542
|
*/
|
|
2485
2543
|
files: Array<FileNode>;
|
|
2486
2544
|
/**
|
|
2487
|
-
*
|
|
2545
|
+
* Resolved configuration for this build.
|
|
2488
2546
|
*/
|
|
2489
|
-
|
|
2547
|
+
config: Config;
|
|
2490
2548
|
/**
|
|
2491
|
-
*
|
|
2492
|
-
* Use `files` to list what this build produced.
|
|
2493
|
-
*
|
|
2494
|
-
* @example Read a generated file
|
|
2495
|
-
* `const code = await buildOutput.storage.getItem('/src/gen/pet.ts')`
|
|
2549
|
+
* Absolute path to the output directory.
|
|
2496
2550
|
*/
|
|
2497
|
-
|
|
2551
|
+
outputDir: string;
|
|
2498
2552
|
};
|
|
2499
|
-
|
|
2500
|
-
//#region src/Diagnostics.d.ts
|
|
2501
|
-
/**
|
|
2502
|
-
* How serious a diagnostic is. `error` fails the build, `warning` and `info`
|
|
2503
|
-
* are reported but do not.
|
|
2504
|
-
*/
|
|
2505
|
-
type DiagnosticSeverity = 'error' | 'warning' | 'info';
|
|
2506
|
-
/**
|
|
2507
|
-
* A human-readable explanation of a diagnostic code: a short title, what triggers it, and how
|
|
2508
|
-
* to resolve it. This is the source of truth the kubb.dev `/diagnostics/<slug>` pages mirror, so
|
|
2509
|
-
* every code stays documented in one place. Adding a code without documenting it fails the build.
|
|
2510
|
-
*/
|
|
2511
|
-
type DiagnosticDoc = {
|
|
2553
|
+
type KubbLifecycleStartContext = {
|
|
2512
2554
|
/**
|
|
2513
|
-
*
|
|
2555
|
+
* Current Kubb version string.
|
|
2514
2556
|
*/
|
|
2515
|
-
|
|
2557
|
+
version: string;
|
|
2558
|
+
};
|
|
2559
|
+
type KubbGenerationStartContext = {
|
|
2516
2560
|
/**
|
|
2517
|
-
*
|
|
2561
|
+
* Resolved configuration for this generation run.
|
|
2518
2562
|
*/
|
|
2519
|
-
|
|
2563
|
+
config: Config;
|
|
2564
|
+
};
|
|
2565
|
+
type KubbGenerationEndContext = {
|
|
2520
2566
|
/**
|
|
2521
|
-
*
|
|
2567
|
+
* Resolved configuration for this generation run.
|
|
2522
2568
|
*/
|
|
2523
|
-
|
|
2524
|
-
};
|
|
2525
|
-
/**
|
|
2526
|
-
* Points a diagnostic back into the source document. Inputs are parsed into an
|
|
2527
|
-
* object model with no line/column, so locations carry a JSON pointer the adapter
|
|
2528
|
-
* builds (the OAS adapter emits `#/components/schemas/Pet`). A `config` diagnostic
|
|
2529
|
-
* points at the Kubb config itself and so has no pointer.
|
|
2530
|
-
*/
|
|
2531
|
-
type DiagnosticLocation = {
|
|
2532
|
-
kind: 'schema';
|
|
2569
|
+
config: Config;
|
|
2533
2570
|
/**
|
|
2534
|
-
*
|
|
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
|
+
* ```
|
|
2535
2583
|
*/
|
|
2536
|
-
|
|
2584
|
+
storage: Storage;
|
|
2537
2585
|
/**
|
|
2538
|
-
*
|
|
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.
|
|
2539
2589
|
*/
|
|
2540
|
-
|
|
2541
|
-
} | {
|
|
2542
|
-
kind: 'operation' | 'document';
|
|
2590
|
+
diagnostics?: Array<Diagnostic>;
|
|
2543
2591
|
/**
|
|
2544
|
-
*
|
|
2592
|
+
* `'success'` when all plugins completed without errors, `'failed'` otherwise.
|
|
2545
2593
|
*/
|
|
2546
|
-
|
|
2547
|
-
} | {
|
|
2548
|
-
kind: 'config';
|
|
2549
|
-
};
|
|
2550
|
-
/**
|
|
2551
|
-
* What a diagnostic carries.
|
|
2552
|
-
* - `problem` is a build issue shown to the user, and the only kind rendered as a problem.
|
|
2553
|
-
* - `performance` records a plugin's elapsed time.
|
|
2554
|
-
* - `update` is a version notice.
|
|
2555
|
-
*/
|
|
2556
|
-
type DiagnosticKind = 'problem' | 'performance' | 'update';
|
|
2557
|
-
/**
|
|
2558
|
-
* Codes that describe a build problem: every {@link DiagnosticCode} except the
|
|
2559
|
-
* `performance` and `updateAvailable` codes, which ride on their own variants.
|
|
2560
|
-
*/
|
|
2561
|
-
type ProblemCode = Exclude<DiagnosticCode, typeof diagnosticCode.performance | typeof diagnosticCode.updateAvailable>;
|
|
2562
|
-
/**
|
|
2563
|
-
* A build problem collected during a run, gathered into the result instead of
|
|
2564
|
-
* aborting on the first failure.
|
|
2565
|
-
*/
|
|
2566
|
-
type ProblemDiagnostic = {
|
|
2594
|
+
status?: 'success' | 'failed';
|
|
2567
2595
|
/**
|
|
2568
|
-
*
|
|
2596
|
+
* High-resolution start time from `process.hrtime()`, used to compute the elapsed time.
|
|
2569
2597
|
*/
|
|
2570
|
-
|
|
2598
|
+
hrStart?: [number, number];
|
|
2571
2599
|
/**
|
|
2572
|
-
*
|
|
2600
|
+
* Total number of files created during this run.
|
|
2601
|
+
*/
|
|
2602
|
+
filesCreated?: number;
|
|
2603
|
+
};
|
|
2604
|
+
type KubbInfoContext = {
|
|
2605
|
+
/**
|
|
2606
|
+
* Human-readable info message.
|
|
2573
2607
|
*/
|
|
2574
|
-
code: ProblemCode;
|
|
2575
|
-
severity: DiagnosticSeverity;
|
|
2576
2608
|
message: string;
|
|
2577
|
-
location?: DiagnosticLocation;
|
|
2578
2609
|
/**
|
|
2579
|
-
*
|
|
2610
|
+
* Optional supplementary detail.
|
|
2580
2611
|
*/
|
|
2581
|
-
|
|
2612
|
+
info?: string;
|
|
2613
|
+
};
|
|
2614
|
+
type KubbErrorContext = {
|
|
2582
2615
|
/**
|
|
2583
|
-
*
|
|
2616
|
+
* The caught error.
|
|
2584
2617
|
*/
|
|
2585
|
-
|
|
2618
|
+
error: Error;
|
|
2586
2619
|
/**
|
|
2587
|
-
*
|
|
2620
|
+
* Optional structured metadata for additional context.
|
|
2588
2621
|
*/
|
|
2589
|
-
|
|
2622
|
+
meta?: Record<string, unknown>;
|
|
2590
2623
|
};
|
|
2591
|
-
|
|
2592
|
-
* A per-plugin performance record, built with {@link Diagnostics.performance}. The `performance`
|
|
2593
|
-
* kind keeps it out of the problem list. It feeds the per-plugin timing bars, and reporters sum
|
|
2594
|
-
* these into the run total.
|
|
2595
|
-
*/
|
|
2596
|
-
type PerformanceDiagnostic = {
|
|
2597
|
-
kind: 'performance';
|
|
2598
|
-
code: typeof diagnosticCode.performance;
|
|
2599
|
-
severity: 'info';
|
|
2600
|
-
message: string;
|
|
2624
|
+
type KubbSuccessContext = {
|
|
2601
2625
|
/**
|
|
2602
|
-
*
|
|
2626
|
+
* Human-readable success message.
|
|
2603
2627
|
*/
|
|
2604
|
-
|
|
2628
|
+
message: string;
|
|
2605
2629
|
/**
|
|
2606
|
-
*
|
|
2630
|
+
* Optional supplementary detail.
|
|
2607
2631
|
*/
|
|
2608
|
-
|
|
2632
|
+
info?: string;
|
|
2609
2633
|
};
|
|
2610
|
-
|
|
2611
|
-
* A notice that a newer Kubb version is available on npm, built with {@link Diagnostics.update}.
|
|
2612
|
-
* It renders like any info diagnostic.
|
|
2613
|
-
*/
|
|
2614
|
-
type UpdateDiagnostic = {
|
|
2615
|
-
kind: 'update';
|
|
2616
|
-
code: typeof diagnosticCode.updateAvailable;
|
|
2617
|
-
severity: 'info';
|
|
2618
|
-
message: string;
|
|
2634
|
+
type KubbWarnContext = {
|
|
2619
2635
|
/**
|
|
2620
|
-
*
|
|
2636
|
+
* Human-readable warning message.
|
|
2621
2637
|
*/
|
|
2622
|
-
|
|
2638
|
+
message: string;
|
|
2623
2639
|
/**
|
|
2624
|
-
*
|
|
2640
|
+
* Optional supplementary detail.
|
|
2625
2641
|
*/
|
|
2626
|
-
|
|
2642
|
+
info?: string;
|
|
2627
2643
|
};
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
* Maps each {@link DiagnosticCode} to the variant it selects, for {@link narrow}.
|
|
2636
|
-
* Every {@link ProblemCode} selects a {@link ProblemDiagnostic}, and the two bookkeeping codes
|
|
2637
|
-
* select their own variant.
|
|
2638
|
-
*/
|
|
2639
|
-
type DiagnosticByCode = Record<ProblemCode, ProblemDiagnostic> & Record<typeof diagnosticCode.performance, PerformanceDiagnostic> & Record<typeof diagnosticCode.updateAvailable, UpdateDiagnostic>;
|
|
2640
|
-
/**
|
|
2641
|
-
* Narrows a {@link Diagnostic} to the variant for `code`, or `null` when it does not match.
|
|
2642
|
-
*
|
|
2643
|
-
* @example
|
|
2644
|
-
* ```ts
|
|
2645
|
-
* const update = narrow(diagnostic, diagnosticCode.updateAvailable)
|
|
2646
|
-
* if (update) {
|
|
2647
|
-
* console.log(update.latestVersion)
|
|
2648
|
-
* }
|
|
2649
|
-
* ```
|
|
2650
|
-
*/
|
|
2651
|
-
declare function narrow<C extends DiagnosticCode>(diagnostic: Diagnostic, code: C): DiagnosticByCode[C] | null;
|
|
2652
|
-
/**
|
|
2653
|
-
* A {@link Diagnostic} reduced to its JSON-safe fields plus a `docsUrl`, for
|
|
2654
|
-
* machine-readable output (the `--reporter json` report, the MCP tools). Drops the
|
|
2655
|
-
* non-serializable `cause` and the `kind`/`duration` bookkeeping.
|
|
2656
|
-
*/
|
|
2657
|
-
type SerializedDiagnostic = {
|
|
2658
|
-
code: DiagnosticCode;
|
|
2659
|
-
severity: DiagnosticSeverity;
|
|
2660
|
-
message: string;
|
|
2661
|
-
location?: DiagnosticLocation;
|
|
2662
|
-
help?: string;
|
|
2663
|
-
plugin?: string;
|
|
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 = {
|
|
2664
2651
|
/**
|
|
2665
|
-
*
|
|
2652
|
+
* Files about to be serialized and written.
|
|
2666
2653
|
*/
|
|
2667
|
-
|
|
2654
|
+
files: Array<FileNode>;
|
|
2668
2655
|
};
|
|
2669
|
-
|
|
2670
|
-
* Static helpers for working with {@link Diagnostic}s, plus the run-scoped sink
|
|
2671
|
-
* that lets deep code report a diagnostic without threading a callback.
|
|
2672
|
-
*
|
|
2673
|
-
* The sink lives in a single `AsyncLocalStorage` in the `@kubb/core` bundle.
|
|
2674
|
-
* `Diagnostics.scope` activates it for a run, so anything inside that run (the
|
|
2675
|
-
* adapter parse, a generator) reports through `Diagnostics.report` and lands
|
|
2676
|
-
* in the same run.
|
|
2677
|
-
*/
|
|
2678
|
-
declare class Diagnostics {
|
|
2679
|
-
#private;
|
|
2656
|
+
type KubbFileProcessingUpdate = {
|
|
2680
2657
|
/**
|
|
2681
|
-
*
|
|
2658
|
+
* Number of files processed so far in this batch.
|
|
2682
2659
|
*/
|
|
2683
|
-
|
|
2684
|
-
readonly unknown: "KUBB_UNKNOWN";
|
|
2685
|
-
readonly inputNotFound: "KUBB_INPUT_NOT_FOUND";
|
|
2686
|
-
readonly inputRequired: "KUBB_INPUT_REQUIRED";
|
|
2687
|
-
readonly refNotFound: "KUBB_REF_NOT_FOUND";
|
|
2688
|
-
readonly invalidServerVariable: "KUBB_INVALID_SERVER_VARIABLE";
|
|
2689
|
-
readonly pluginNotFound: "KUBB_PLUGIN_NOT_FOUND";
|
|
2690
|
-
readonly pluginFailed: "KUBB_PLUGIN_FAILED";
|
|
2691
|
-
readonly pluginWarning: "KUBB_PLUGIN_WARNING";
|
|
2692
|
-
readonly pluginInfo: "KUBB_PLUGIN_INFO";
|
|
2693
|
-
readonly unsupportedFormat: "KUBB_UNSUPPORTED_FORMAT";
|
|
2694
|
-
readonly deprecated: "KUBB_DEPRECATED";
|
|
2695
|
-
readonly adapterRequired: "KUBB_ADAPTER_REQUIRED";
|
|
2696
|
-
readonly pathTraversal: "KUBB_PATH_TRAVERSAL";
|
|
2697
|
-
readonly invalidPluginOptions: "KUBB_INVALID_PLUGIN_OPTIONS";
|
|
2698
|
-
readonly hookFailed: "KUBB_HOOK_FAILED";
|
|
2699
|
-
readonly formatFailed: "KUBB_FORMAT_FAILED";
|
|
2700
|
-
readonly lintFailed: "KUBB_LINT_FAILED";
|
|
2701
|
-
readonly performance: "KUBB_PERFORMANCE";
|
|
2702
|
-
readonly updateAvailable: "KUBB_UPDATE_AVAILABLE";
|
|
2703
|
-
};
|
|
2660
|
+
processed: number;
|
|
2704
2661
|
/**
|
|
2705
|
-
*
|
|
2662
|
+
* Total number of files in this batch.
|
|
2706
2663
|
*/
|
|
2707
|
-
|
|
2664
|
+
total: number;
|
|
2708
2665
|
/**
|
|
2709
|
-
*
|
|
2666
|
+
* Completion percentage, `0` to `100`.
|
|
2710
2667
|
*/
|
|
2711
|
-
|
|
2668
|
+
percentage: number;
|
|
2712
2669
|
/**
|
|
2713
|
-
*
|
|
2670
|
+
* Serialized file content, or `undefined` when the file produced no output.
|
|
2714
2671
|
*/
|
|
2715
|
-
|
|
2672
|
+
source?: string;
|
|
2716
2673
|
/**
|
|
2717
|
-
*
|
|
2674
|
+
* The file that was just processed.
|
|
2718
2675
|
*/
|
|
2719
|
-
|
|
2676
|
+
file: FileNode;
|
|
2720
2677
|
/**
|
|
2721
|
-
*
|
|
2722
|
-
* through the existing throw/catch paths while keeping their code and location.
|
|
2723
|
-
*
|
|
2724
|
-
* @example
|
|
2725
|
-
* ```ts
|
|
2726
|
-
* throw new Diagnostics.Error({ code: diagnosticCode.refNotFound, severity: 'error', message: `Could not find ${ref}`, location: { kind: 'schema', pointer: ref, ref } })
|
|
2727
|
-
* ```
|
|
2678
|
+
* Resolved configuration for this build.
|
|
2728
2679
|
*/
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
name: string;
|
|
2733
|
-
message: string;
|
|
2734
|
-
stack?: string;
|
|
2735
|
-
cause?: unknown;
|
|
2736
|
-
};
|
|
2737
|
-
isError(error: unknown): error is Error;
|
|
2738
|
-
isError(value: unknown): value is Error;
|
|
2739
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
2740
|
-
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
2741
|
-
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
2742
|
-
stackTraceLimit: number;
|
|
2743
|
-
};
|
|
2680
|
+
config: Config;
|
|
2681
|
+
};
|
|
2682
|
+
type KubbFilesProcessingUpdateContext = {
|
|
2744
2683
|
/**
|
|
2745
|
-
*
|
|
2746
|
-
* `@kubb/core` copy where `instanceof` fails. Matches on the `name` and a `diagnostic`
|
|
2747
|
-
* that carries a `code`.
|
|
2684
|
+
* All files processed in this flush chunk.
|
|
2748
2685
|
*/
|
|
2749
|
-
|
|
2686
|
+
files: Array<KubbFileProcessingUpdate>;
|
|
2687
|
+
};
|
|
2688
|
+
type KubbFilesProcessingEndContext = {
|
|
2750
2689
|
/**
|
|
2751
|
-
*
|
|
2752
|
-
* subtree, so {@link Diagnostics.report} reaches it from anywhere inside.
|
|
2690
|
+
* All files that were serialized in this batch.
|
|
2753
2691
|
*/
|
|
2754
|
-
|
|
2692
|
+
files: Array<FileNode>;
|
|
2693
|
+
};
|
|
2694
|
+
type KubbHookStartContext = {
|
|
2755
2695
|
/**
|
|
2756
|
-
*
|
|
2757
|
-
* Returns `true` when a run consumed it, `false` when called outside a {@link Diagnostics.scope}
|
|
2758
|
-
* (so callers can fall back to throwing). Use a `warning`/`info` severity for non-fatal issues.
|
|
2759
|
-
* For rendering a diagnostic live on the hook bus, use {@link Diagnostics.emit} instead.
|
|
2696
|
+
* Optional identifier for correlating start/end hooks.
|
|
2760
2697
|
*/
|
|
2761
|
-
|
|
2698
|
+
id?: string;
|
|
2762
2699
|
/**
|
|
2763
|
-
*
|
|
2764
|
-
* Use it instead of calling `hooks.callHook('kubb:diagnostic', ...)` directly. To collect a
|
|
2765
|
-
* diagnostic into the build result from deep in a run, use {@link Diagnostics.report} instead.
|
|
2700
|
+
* The shell command that is about to run.
|
|
2766
2701
|
*/
|
|
2767
|
-
|
|
2702
|
+
command: string;
|
|
2768
2703
|
/**
|
|
2769
|
-
*
|
|
2770
|
-
* keeps its structured data, and anything else becomes a `KUBB_UNKNOWN` error.
|
|
2704
|
+
* Parsed argument list, when available.
|
|
2771
2705
|
*/
|
|
2772
|
-
|
|
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 = {
|
|
2773
2713
|
/**
|
|
2774
|
-
*
|
|
2714
|
+
* Identifier matching the corresponding `kubb:hook:start` hook.
|
|
2775
2715
|
*/
|
|
2776
|
-
|
|
2777
|
-
plugin,
|
|
2778
|
-
duration
|
|
2779
|
-
}: {
|
|
2780
|
-
plugin: string;
|
|
2781
|
-
duration: number;
|
|
2782
|
-
}): PerformanceDiagnostic;
|
|
2716
|
+
id: string;
|
|
2783
2717
|
/**
|
|
2784
|
-
*
|
|
2718
|
+
* A single streamed stdout line, without its trailing newline.
|
|
2785
2719
|
*/
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
}: {
|
|
2790
|
-
currentVersion: string;
|
|
2791
|
-
latestVersion: string;
|
|
2792
|
-
}): UpdateDiagnostic;
|
|
2720
|
+
line: string;
|
|
2721
|
+
};
|
|
2722
|
+
type KubbHookEndContext = {
|
|
2793
2723
|
/**
|
|
2794
|
-
*
|
|
2795
|
-
* diagnostics are ignored.
|
|
2724
|
+
* Optional identifier matching the corresponding `kubb:hook:start` hook.
|
|
2796
2725
|
*/
|
|
2797
|
-
|
|
2726
|
+
id?: string;
|
|
2798
2727
|
/**
|
|
2799
|
-
*
|
|
2800
|
-
* that carry a `plugin`.
|
|
2728
|
+
* The shell command that ran.
|
|
2801
2729
|
*/
|
|
2802
|
-
|
|
2730
|
+
command: string;
|
|
2803
2731
|
/**
|
|
2804
|
-
*
|
|
2805
|
-
* `update` diagnostics are ignored.
|
|
2732
|
+
* Parsed argument list, when available.
|
|
2806
2733
|
*/
|
|
2807
|
-
|
|
2808
|
-
errors: number;
|
|
2809
|
-
warnings: number;
|
|
2810
|
-
infos: number;
|
|
2811
|
-
};
|
|
2734
|
+
args?: ReadonlyArray<string>;
|
|
2812
2735
|
/**
|
|
2813
|
-
*
|
|
2814
|
-
* plugin, so the same issue reported across several passes is shown once. Non-problem
|
|
2815
|
-
* diagnostics are always kept.
|
|
2736
|
+
* `true` when the command exited with code `0`.
|
|
2816
2737
|
*/
|
|
2817
|
-
|
|
2738
|
+
success: boolean;
|
|
2818
2739
|
/**
|
|
2819
|
-
*
|
|
2820
|
-
* `KUBB_REF_NOT_FOUND` → `https://kubb.dev/docs/5.x/reference/diagnostics/kubb-ref-not-found`.
|
|
2740
|
+
* Error thrown by the command, or `null` on success.
|
|
2821
2741
|
*/
|
|
2822
|
-
|
|
2742
|
+
error: Error | null;
|
|
2823
2743
|
/**
|
|
2824
|
-
*
|
|
2825
|
-
* `/diagnostics/<slug>` page.
|
|
2744
|
+
* Captured stdout from the process, populated when it exits non-zero.
|
|
2826
2745
|
*/
|
|
2827
|
-
|
|
2746
|
+
stdout?: string;
|
|
2828
2747
|
/**
|
|
2829
|
-
*
|
|
2830
|
-
* consumers. The `cause`, `kind`, and `duration` are dropped, and absent optional
|
|
2831
|
-
* fields are omitted rather than set to `undefined`.
|
|
2748
|
+
* Captured stderr from the process, populated when it exits non-zero.
|
|
2832
2749
|
*/
|
|
2833
|
-
|
|
2750
|
+
stderr?: string;
|
|
2751
|
+
};
|
|
2752
|
+
/**
|
|
2753
|
+
* CLI options derived from command-line flags.
|
|
2754
|
+
*/
|
|
2755
|
+
type CLIOptions = {
|
|
2834
2756
|
/**
|
|
2835
|
-
*
|
|
2836
|
-
|
|
2837
|
-
|
|
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.
|
|
2838
2771
|
*
|
|
2839
|
-
*
|
|
2840
|
-
* message with no gutter symbol, while plain text outputs use {@link Diagnostics.formatLines}.
|
|
2772
|
+
* @default 'info'
|
|
2841
2773
|
*/
|
|
2842
|
-
|
|
2843
|
-
headline: string;
|
|
2844
|
-
details: Array<string>;
|
|
2845
|
-
};
|
|
2774
|
+
logLevel?: 'silent' | 'info' | 'verbose';
|
|
2846
2775
|
/**
|
|
2847
|
-
*
|
|
2848
|
-
* indented detail rows. Used where there is no gutter (plain and file output).
|
|
2776
|
+
* Reporters selected on the CLI via `--reporter`, overriding `config.reporters`.
|
|
2849
2777
|
*/
|
|
2850
|
-
|
|
2851
|
-
}
|
|
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
|
+
};
|
|
2852
2813
|
//#endregion
|
|
2853
|
-
export {
|
|
2854
|
-
//# sourceMappingURL=
|
|
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
|