@kubb/core 5.0.0-beta.84 → 5.0.0-beta.85
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/{diagnostics-DuaXn2bT.d.ts → Diagnostics-PnPLU3kj.d.ts} +314 -402
- package/dist/index.cjs +729 -973
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -93
- package/dist/index.js +690 -934
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +7 -14
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.js +3 -10
- package/dist/mocks.js.map +1 -1
- package/dist/{memoryStorage-BjUIqpYE.js → usingCtx-BABTfo1g.js} +160 -480
- package/dist/usingCtx-BABTfo1g.js.map +1 -0
- package/dist/{memoryStorage-DQ6qXJ8o.cjs → usingCtx-fxRpJw0P.cjs} +159 -521
- package/dist/usingCtx-fxRpJw0P.cjs.map +1 -0
- package/package.json +2 -2
- package/dist/memoryStorage-BjUIqpYE.js.map +0 -1
- package/dist/memoryStorage-DQ6qXJ8o.cjs.map +0 -1
|
@@ -1,88 +1,6 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
2
|
import { Enforce, FileNode, HttpMethod, ImportNode, InputMeta, InputNode, Macro, Node, OperationNode, SchemaNode, UserFileNode } from "@kubb/ast";
|
|
3
3
|
|
|
4
|
-
//#region ../../internals/utils/src/asyncEventEmitter.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* A function that can be registered as an event listener, synchronous or async.
|
|
7
|
-
*/
|
|
8
|
-
type AsyncListener<TArgs extends Array<unknown>> = (...args: TArgs) => void | Promise<void>;
|
|
9
|
-
/**
|
|
10
|
-
* Typed `EventEmitter` that awaits all async listeners before resolving.
|
|
11
|
-
* Wraps Node's `EventEmitter` with full TypeScript event-map inference.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* const emitter = new AsyncEventEmitter<{ build: [name: string] }>()
|
|
16
|
-
* emitter.on('build', async (name) => { console.log(name) })
|
|
17
|
-
* await emitter.emit('build', 'petstore') // all listeners awaited
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: Array<unknown> }> {
|
|
21
|
-
#private;
|
|
22
|
-
/**
|
|
23
|
-
* Maximum number of listeners per event before Node emits a memory-leak warning.
|
|
24
|
-
* @default 10
|
|
25
|
-
*/
|
|
26
|
-
constructor(maxListener?: number);
|
|
27
|
-
/**
|
|
28
|
-
* Emits `eventName` and awaits all registered listeners sequentially.
|
|
29
|
-
* Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* await emitter.emit('build', 'petstore')
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> | void;
|
|
37
|
-
/**
|
|
38
|
-
* Registers a persistent listener for `eventName`.
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```ts
|
|
42
|
-
* emitter.on('build', async (name) => { console.log(name) })
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
46
|
-
/**
|
|
47
|
-
* Removes a previously registered listener.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* ```ts
|
|
51
|
-
* emitter.off('build', handler)
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
55
|
-
/**
|
|
56
|
-
* Returns the number of listeners registered for `eventName`.
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```ts
|
|
60
|
-
* emitter.on('build', handler)
|
|
61
|
-
* emitter.listenerCount('build') // 1
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
listenerCount<TEventName extends keyof TEvents & string>(eventName: TEventName): number;
|
|
65
|
-
/**
|
|
66
|
-
* Raises or lowers the per-event listener ceiling before Node warns about a memory leak.
|
|
67
|
-
* Set this above the expected listener count when many listeners attach by design.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```ts
|
|
71
|
-
* emitter.setMaxListeners(40)
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
setMaxListeners(max: number): void;
|
|
75
|
-
/**
|
|
76
|
-
* Removes all listeners from every event channel.
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```ts
|
|
80
|
-
* emitter.removeAll()
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
removeAll(): void;
|
|
84
|
-
}
|
|
85
|
-
//#endregion
|
|
86
4
|
//#region ../../internals/utils/src/promise.d.ts
|
|
87
5
|
/** A value that may already be resolved or still pending.
|
|
88
6
|
*
|
|
@@ -179,14 +97,6 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
|
179
97
|
validate: (input: string, options?: {
|
|
180
98
|
throwOnError?: boolean;
|
|
181
99
|
}) => Promise<void>;
|
|
182
|
-
/**
|
|
183
|
-
* Memory-efficient streaming variant of `parse()`.
|
|
184
|
-
*
|
|
185
|
-
* Returns an `InputNode<true>` whose `schemas` and `operations` are `AsyncIterable`.
|
|
186
|
-
* Each `for await` loop creates a fresh parse pass over the cached in-memory document.
|
|
187
|
-
* No pre-built arrays are held in memory.
|
|
188
|
-
*/
|
|
189
|
-
stream?: (source: AdapterSource) => Promise<InputNode<true>>;
|
|
190
100
|
};
|
|
191
101
|
type AdapterBuilder<T extends AdapterFactoryOptions> = (options: T['options']) => Adapter<T>;
|
|
192
102
|
/**
|
|
@@ -383,7 +293,8 @@ type Reporter = {
|
|
|
383
293
|
* Optional finalizer called once after the run's last config. The host wires it to
|
|
384
294
|
* `kubb:lifecycle:end`. {@link createReporter} closes it over the values that `report` returned.
|
|
385
295
|
*/
|
|
386
|
-
drain
|
|
296
|
+
drain: (context: ReporterContext) => void | Promise<void>;
|
|
297
|
+
[Symbol.dispose](): void;
|
|
387
298
|
};
|
|
388
299
|
/**
|
|
389
300
|
* Reporter definition passed to {@link createReporter}. `report` returns the value to collect for
|
|
@@ -517,14 +428,8 @@ type Renderer<TElement = unknown> = {
|
|
|
517
428
|
render(element: TElement): Promise<void>;
|
|
518
429
|
/**
|
|
519
430
|
* Accumulated {@link FileNode} results produced by the last {@link render} call.
|
|
520
|
-
* Not populated when {@link stream} is implemented.
|
|
521
431
|
*/
|
|
522
432
|
readonly files: Array<FileNode>;
|
|
523
|
-
/**
|
|
524
|
-
* When present, core calls this instead of {@link render} and {@link files},
|
|
525
|
-
* forwarding each file to `FileManager` as soon as it is ready.
|
|
526
|
-
*/
|
|
527
|
-
stream?(element: TElement): Iterable<FileNode>;
|
|
528
433
|
/**
|
|
529
434
|
* Disposer hook so renderers participate in `using` blocks: `using r = rendererFactory()`
|
|
530
435
|
* runs cleanup on every exit path, including thrown errors.
|
|
@@ -568,20 +473,7 @@ type RendererFactory<TElement = unknown> = () => Renderer<TElement>;
|
|
|
568
473
|
*/
|
|
569
474
|
declare function createRenderer<TElement = unknown>(factory: RendererFactory<TElement>): RendererFactory<TElement>;
|
|
570
475
|
//#endregion
|
|
571
|
-
//#region src/
|
|
572
|
-
/**
|
|
573
|
-
* Type/string pattern filter for include/exclude/override matching.
|
|
574
|
-
*/
|
|
575
|
-
type PatternFilter = {
|
|
576
|
-
type: string;
|
|
577
|
-
pattern: string | RegExp;
|
|
578
|
-
};
|
|
579
|
-
/**
|
|
580
|
-
* Pattern filter with partial option overrides applied when the pattern matches.
|
|
581
|
-
*/
|
|
582
|
-
type PatternOverride<TOptions> = PatternFilter & {
|
|
583
|
-
options: Omit<Partial<TOptions>, 'override'>;
|
|
584
|
-
};
|
|
476
|
+
//#region src/createResolver.d.ts
|
|
585
477
|
/**
|
|
586
478
|
* Context for resolving filtered options for a given operation or schema node.
|
|
587
479
|
*
|
|
@@ -589,43 +481,33 @@ type PatternOverride<TOptions> = PatternFilter & {
|
|
|
589
481
|
*/
|
|
590
482
|
type ResolveOptionsContext<TOptions> = {
|
|
591
483
|
options: TOptions;
|
|
592
|
-
exclude?: Array<
|
|
593
|
-
include?: Array<
|
|
594
|
-
override?: Array<
|
|
484
|
+
exclude?: Array<Filter>;
|
|
485
|
+
include?: Array<Filter>;
|
|
486
|
+
override?: Array<Override<TOptions>>;
|
|
595
487
|
};
|
|
596
488
|
/**
|
|
597
|
-
*
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
* are injected automatically by `defineResolver`. Extend this type to add custom resolution methods.
|
|
601
|
-
*
|
|
602
|
-
* @example
|
|
603
|
-
* ```ts
|
|
604
|
-
* type MyResolver = Resolver & {
|
|
605
|
-
* resolveName(node: SchemaNode): string
|
|
606
|
-
* resolveTypedName(node: SchemaNode): string
|
|
607
|
-
* }
|
|
608
|
-
* ```
|
|
489
|
+
* The built-in resolution machinery exposed on every resolver as `resolver.default`.
|
|
490
|
+
* Plugins delegate to it via `this.default.*` and set their own conventions through
|
|
491
|
+
* the top-level `name` and `file` entries.
|
|
609
492
|
*/
|
|
610
|
-
type
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
493
|
+
type ResolverDefault = {
|
|
494
|
+
/**
|
|
495
|
+
* Built-in camelCase casing for a generated identifier.
|
|
496
|
+
*/
|
|
497
|
+
name(name: string): string;
|
|
498
|
+
options<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null;
|
|
499
|
+
path(params: ResolverPathParams, context: ResolverContext): string;
|
|
500
|
+
file(params: ResolverFileParams, context: ResolverContext): FileNode;
|
|
501
|
+
banner(meta: InputMeta | undefined, context: ResolveBannerContext): string | null;
|
|
502
|
+
footer(meta: InputMeta | undefined, context: ResolveBannerContext): string | null;
|
|
619
503
|
};
|
|
620
504
|
/**
|
|
621
|
-
* File-specific parameters for `
|
|
622
|
-
*
|
|
623
|
-
* Pass alongside a `ResolverContext` to identify which file to resolve.
|
|
505
|
+
* File-specific parameters for `resolver.default.path`.
|
|
624
506
|
* Provide `tag` for tag-based grouping or `path` for path-based grouping.
|
|
625
507
|
*
|
|
626
508
|
* @example
|
|
627
509
|
* ```ts
|
|
628
|
-
* resolver.
|
|
510
|
+
* resolver.default.path(
|
|
629
511
|
* { baseName: 'petTypes.ts', tag: 'pets' },
|
|
630
512
|
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
631
513
|
* )
|
|
@@ -644,38 +526,22 @@ type ResolverPathParams = {
|
|
|
644
526
|
path?: string;
|
|
645
527
|
};
|
|
646
528
|
/**
|
|
647
|
-
* Shared context passed as the second argument to `
|
|
648
|
-
*
|
|
649
|
-
*
|
|
650
|
-
* grouping strategy that controls subdirectory layout.
|
|
651
|
-
*
|
|
652
|
-
* @example
|
|
653
|
-
* ```ts
|
|
654
|
-
* const context: ResolverContext = {
|
|
655
|
-
* root: config.root,
|
|
656
|
-
* output,
|
|
657
|
-
* group,
|
|
658
|
-
* }
|
|
659
|
-
* ```
|
|
529
|
+
* Shared context passed as the second argument to `resolver.default.path` and
|
|
530
|
+
* `resolver.default.file`: where output is rooted, which output config is active,
|
|
531
|
+
* and the optional grouping strategy.
|
|
660
532
|
*/
|
|
661
533
|
type ResolverContext = {
|
|
662
534
|
root: string;
|
|
663
535
|
output: Output;
|
|
664
536
|
group?: Group;
|
|
665
|
-
/**
|
|
666
|
-
* Plugin name used to populate `meta.pluginName` on the resolved file.
|
|
667
|
-
*/
|
|
668
|
-
pluginName?: string;
|
|
669
537
|
};
|
|
670
538
|
/**
|
|
671
|
-
* File-specific parameters for `
|
|
672
|
-
*
|
|
673
|
-
* Pass alongside a `ResolverContext` to fully describe the file to resolve.
|
|
539
|
+
* File-specific parameters for `resolver.default.file`.
|
|
674
540
|
* `tag` and `path` are used only when a matching `group` is present in the context.
|
|
675
541
|
*
|
|
676
542
|
* @example
|
|
677
543
|
* ```ts
|
|
678
|
-
* resolver.
|
|
544
|
+
* resolver.default.file(
|
|
679
545
|
* { name: 'listPets', extname: '.ts', tag: 'pets' },
|
|
680
546
|
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
681
547
|
* )
|
|
@@ -693,13 +559,18 @@ type ResolverFileParams = {
|
|
|
693
559
|
* Path value used when `group.type === 'path'`.
|
|
694
560
|
*/
|
|
695
561
|
path?: string;
|
|
562
|
+
/**
|
|
563
|
+
* Casing applied to `name` to build the file base name. A plugin's `file` override
|
|
564
|
+
* threads its own caser here to change file naming without reimplementing the builder.
|
|
565
|
+
*
|
|
566
|
+
* @default toFilePath
|
|
567
|
+
*/
|
|
568
|
+
resolveName?: (name: string) => string;
|
|
696
569
|
};
|
|
697
570
|
/**
|
|
698
|
-
* Per-file context describing the file a banner/footer is being resolved for
|
|
699
|
-
*
|
|
700
|
-
*
|
|
701
|
-
* into `BannerMeta` so a `banner`/`footer` function can branch on the file kind,
|
|
702
|
-
* e.g. omit a `'use server'` directive on re-export files.
|
|
571
|
+
* Per-file context describing the file a banner/footer is being resolved for, so a
|
|
572
|
+
* `banner`/`footer` function can branch on the file kind (e.g. skip a `'use server'`
|
|
573
|
+
* directive on re-export files).
|
|
703
574
|
*/
|
|
704
575
|
type ResolveBannerFile = {
|
|
705
576
|
/**
|
|
@@ -722,9 +593,6 @@ type ResolveBannerFile = {
|
|
|
722
593
|
/**
|
|
723
594
|
* Document metadata extended with per-file context, passed to a `banner`/`footer` function.
|
|
724
595
|
*
|
|
725
|
-
* Carries everything in {@link InputMeta} plus the file the banner is rendered into, so a
|
|
726
|
-
* single function can decide per file (e.g. skip a directive on barrel/aggregation files).
|
|
727
|
-
*
|
|
728
596
|
* @example Skip a directive on re-export files
|
|
729
597
|
* `banner: (meta) => (meta.isBarrel || meta.isAggregation) ? '' : "'use server'"`
|
|
730
598
|
*/
|
|
@@ -747,17 +615,9 @@ type BannerMeta = InputMeta & {
|
|
|
747
615
|
isAggregation: boolean;
|
|
748
616
|
};
|
|
749
617
|
/**
|
|
750
|
-
* Context passed to `
|
|
751
|
-
*
|
|
752
|
-
*
|
|
753
|
-
* `config` carries the global Kubb config, used to derive the default Kubb banner.
|
|
754
|
-
* `file` carries per-file context forwarded to a `banner`/`footer` function.
|
|
755
|
-
*
|
|
756
|
-
* @example
|
|
757
|
-
* ```ts
|
|
758
|
-
* resolver.resolveBanner(meta, { output: { banner: '// generated' }, config })
|
|
759
|
-
* // → '// generated'
|
|
760
|
-
* ```
|
|
618
|
+
* Context passed to `resolver.default.banner` and `resolver.default.footer`.
|
|
619
|
+
* `output` is optional since not every plugin configures a banner/footer, and `config`
|
|
620
|
+
* carries the global Kubb config used to derive the default Kubb banner.
|
|
761
621
|
*/
|
|
762
622
|
type ResolveBannerContext = {
|
|
763
623
|
output?: Pick<Output, 'banner' | 'footer'>;
|
|
@@ -765,111 +625,93 @@ type ResolveBannerContext = {
|
|
|
765
625
|
file?: ResolveBannerFile;
|
|
766
626
|
};
|
|
767
627
|
/**
|
|
768
|
-
*
|
|
769
|
-
*
|
|
770
|
-
* `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`
|
|
771
|
-
* are optional, with built-in fallbacks injected when omitted.
|
|
772
|
-
*
|
|
773
|
-
* Methods in the returned object can call sibling resolver methods via `this`.
|
|
628
|
+
* Raw resolver fields passed to `createResolver` or patched through `Resolver.merge`.
|
|
629
|
+
* `default` is the built-in machinery and is not user-settable.
|
|
774
630
|
*/
|
|
775
|
-
type
|
|
776
|
-
|
|
631
|
+
type ResolverBuildOptions = {
|
|
632
|
+
pluginName: string;
|
|
633
|
+
name?: (name: string) => string;
|
|
634
|
+
file?: (params: ResolverFileParams, context: ResolverContext) => FileNode;
|
|
635
|
+
[key: string]: unknown;
|
|
636
|
+
};
|
|
637
|
+
/**
|
|
638
|
+
* Partial resolver fields accepted by `Resolver.merge` and `setResolver`.
|
|
639
|
+
*/
|
|
640
|
+
type ResolverOverride = Omit<ResolverBuildOptions, 'pluginName'>;
|
|
641
|
+
/**
|
|
642
|
+
* The plugin-specific resolver fields handed to `createResolver`. `name` and `file` fall
|
|
643
|
+
* back to the built-ins when omitted. Every method reaches sibling helpers through `this`,
|
|
644
|
+
* which `ThisType` types as the full resolver.
|
|
645
|
+
*/
|
|
646
|
+
type ResolverOptions<T extends PluginFactoryOptions> = Omit<T['resolver'], keyof Resolver> & {
|
|
777
647
|
pluginName: T['name'];
|
|
648
|
+
name?: T['resolver']['name'];
|
|
649
|
+
file?: T['resolver']['file'];
|
|
778
650
|
} & ThisType<T['resolver']>;
|
|
779
651
|
/**
|
|
780
|
-
*
|
|
781
|
-
*
|
|
782
|
-
* - `mode: 'file'` resolves directly to `output.path` (the full file path, extension included).
|
|
783
|
-
* - `mode: 'directory'` (default) resolves to `output.path/{baseName}`, or into a
|
|
784
|
-
* subdirectory when `group` and a `tag`/`path` value are provided.
|
|
785
|
-
*
|
|
786
|
-
* A custom `group.name` function overrides the default subdirectory naming.
|
|
787
|
-
* For `tag` groups the default is the camelCased tag.
|
|
788
|
-
* For `path` groups the default is the first path segment after `/`.
|
|
789
|
-
*
|
|
790
|
-
* @example Flat output
|
|
791
|
-
* ```ts
|
|
792
|
-
* defaultResolvePath({ baseName: 'petTypes.ts' }, { root: '/src', output: { path: 'types' } })
|
|
793
|
-
* // → '/src/types/petTypes.ts'
|
|
794
|
-
* ```
|
|
652
|
+
* Base constraint for all plugin resolver objects.
|
|
795
653
|
*
|
|
796
|
-
*
|
|
797
|
-
*
|
|
798
|
-
*
|
|
799
|
-
* { baseName: 'petTypes.ts', tag: 'pets' },
|
|
800
|
-
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
801
|
-
* )
|
|
802
|
-
* // → '/src/types/pets/petTypes.ts'
|
|
803
|
-
* ```
|
|
654
|
+
* The built-in machinery lives under `default`. Generators call the top-level `name` and
|
|
655
|
+
* `file`, and a plugin overrides them to set its conventions. Extend with top-level helpers
|
|
656
|
+
* (`typeName`, …) and/or grouped namespaces (`query`, `schema`, …).
|
|
804
657
|
*
|
|
805
|
-
* @example
|
|
658
|
+
* @example Top-level helper
|
|
806
659
|
* ```ts
|
|
807
|
-
*
|
|
808
|
-
*
|
|
809
|
-
*
|
|
810
|
-
* )
|
|
811
|
-
* // → '/src/types/pets/petTypes.ts'
|
|
660
|
+
* type MyResolver = Resolver & {
|
|
661
|
+
* typeName(name: string): string
|
|
662
|
+
* }
|
|
812
663
|
* ```
|
|
813
664
|
*
|
|
814
|
-
* @example
|
|
665
|
+
* @example Grouped namespace
|
|
815
666
|
* ```ts
|
|
816
|
-
*
|
|
817
|
-
*
|
|
818
|
-
*
|
|
819
|
-
* )
|
|
820
|
-
*
|
|
667
|
+
* type MyResolver = Resolver & {
|
|
668
|
+
* query: {
|
|
669
|
+
* name(node: OperationNode): string
|
|
670
|
+
* keyName(node: OperationNode): string
|
|
671
|
+
* }
|
|
672
|
+
* }
|
|
821
673
|
* ```
|
|
822
674
|
*/
|
|
675
|
+
declare class Resolver {
|
|
676
|
+
#private;
|
|
677
|
+
readonly pluginName: string;
|
|
678
|
+
constructor(options: ResolverBuildOptions);
|
|
679
|
+
/**
|
|
680
|
+
* The built-in resolution machinery. Always reaches the untouched defaults, even when a
|
|
681
|
+
* plugin overrides the top-level `name` or `file`.
|
|
682
|
+
*/
|
|
683
|
+
get default(): ResolverDefault;
|
|
684
|
+
name(name: string): string;
|
|
685
|
+
file(params: ResolverFileParams, context: ResolverContext): FileNode;
|
|
686
|
+
/**
|
|
687
|
+
* Merges `override` over `base` and returns a new resolver with helpers re-bound.
|
|
688
|
+
* Each key is replaced wholesale. Used when applying `setResolver` partial overrides.
|
|
689
|
+
*/
|
|
690
|
+
static merge<T extends Resolver>(base: T, override: ResolverOverride | Resolver): T;
|
|
691
|
+
}
|
|
823
692
|
/**
|
|
824
|
-
* Defines a plugin resolver
|
|
825
|
-
*
|
|
826
|
-
*
|
|
827
|
-
*
|
|
693
|
+
* Defines a plugin resolver, the object that decides what every generated symbol and file
|
|
694
|
+
* path is called. Override the top-level `name` and `file` to set the plugin's conventions,
|
|
695
|
+
* and add your own naming helpers, top-level (`typeName`, …) or grouped in namespaces
|
|
696
|
+
* (`query`, `schema`, …). Every method reaches sibling helpers and the built-in machinery
|
|
697
|
+
* through `this.name`, `this.file`, and `this.default`.
|
|
828
698
|
*
|
|
829
|
-
*
|
|
830
|
-
* - `resolveOptions` does include/exclude/override filtering.
|
|
831
|
-
* - `resolvePath` computes the output path.
|
|
832
|
-
* - `resolveFile` builds the full `FileNode`.
|
|
833
|
-
* - `resolveBanner` and `resolveFooter` produce the top and bottom of file text.
|
|
834
|
-
*
|
|
835
|
-
* Methods in the returned object can call sibling resolver methods via `this`.
|
|
836
|
-
* A custom rule can delegate to a default, for example `this.default(name, 'type')`.
|
|
837
|
-
*
|
|
838
|
-
* @example Basic resolver with naming helpers
|
|
699
|
+
* @example Custom identifier and file casing
|
|
839
700
|
* ```ts
|
|
840
|
-
* export const resolverTs =
|
|
841
|
-
*
|
|
842
|
-
*
|
|
843
|
-
* return
|
|
701
|
+
* export const resolverTs = createResolver<PluginTs>({
|
|
702
|
+
* pluginName: 'plugin-ts',
|
|
703
|
+
* name(name) {
|
|
704
|
+
* return ensureValidVarName(pascalCase(name))
|
|
844
705
|
* },
|
|
845
|
-
*
|
|
846
|
-
* return this.default(name,
|
|
706
|
+
* file(params, context) {
|
|
707
|
+
* return this.default.file({ ...params, resolveName: (name) => toFilePath(name, pascalCase) }, context)
|
|
847
708
|
* },
|
|
848
|
-
* })
|
|
849
|
-
* ```
|
|
850
|
-
*
|
|
851
|
-
* @example Custom output path
|
|
852
|
-
* ```ts
|
|
853
|
-
* import path from 'node:path'
|
|
854
|
-
*
|
|
855
|
-
* export const resolverTs = defineResolver<PluginTs>(() => ({
|
|
856
|
-
* name: 'custom',
|
|
857
|
-
* resolvePath({ baseName }, { root, output }) {
|
|
858
|
-
* return path.resolve(root, output.path, 'generated', baseName)
|
|
859
|
-
* },
|
|
860
|
-
* }))
|
|
709
|
+
* })
|
|
861
710
|
* ```
|
|
862
711
|
*/
|
|
863
|
-
declare function
|
|
712
|
+
declare function createResolver<T extends PluginFactoryOptions>(options: ResolverOptions<T>): T['resolver'];
|
|
864
713
|
//#endregion
|
|
865
714
|
//#region src/definePlugin.d.ts
|
|
866
|
-
/**
|
|
867
|
-
* Reads a type from a registry, falling back to `{}` when the key is absent. Lets
|
|
868
|
-
* `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry` be augmented without
|
|
869
|
-
* touching core.
|
|
870
|
-
*
|
|
871
|
-
* @internal
|
|
872
|
-
*/
|
|
873
715
|
type ExtractRegistryKey$1<T, K extends PropertyKey> = K extends keyof T ? T[K] : {};
|
|
874
716
|
/**
|
|
875
717
|
* How a plugin consolidates its generated code into files.
|
|
@@ -881,7 +723,7 @@ type OutputMode = 'directory' | 'file';
|
|
|
881
723
|
* Output configuration shared by every plugin. Each plugin extends this with
|
|
882
724
|
* its own keys via the `Kubb.PluginOptionsRegistry.output` interface merge.
|
|
883
725
|
*/
|
|
884
|
-
type Output
|
|
726
|
+
type Output = {
|
|
885
727
|
/**
|
|
886
728
|
* Directory where the plugin writes its generated code, resolved against the global
|
|
887
729
|
* `output.path` set on `defineConfig`. With `mode: 'file'`, this is the full output file
|
|
@@ -1023,6 +865,11 @@ type ByContentType = {
|
|
|
1023
865
|
*/
|
|
1024
866
|
pattern: string | RegExp;
|
|
1025
867
|
};
|
|
868
|
+
/**
|
|
869
|
+
* Pattern filter for include, exclude, and override rules. Matches operations or schemas
|
|
870
|
+
* by tag, operationId, path, method, content type, or schema name.
|
|
871
|
+
*/
|
|
872
|
+
type Filter = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
|
|
1026
873
|
/**
|
|
1027
874
|
* Filter that skips matching operations or schemas during generation, for example
|
|
1028
875
|
* deprecated endpoints or internal-only schemas.
|
|
@@ -1036,7 +883,7 @@ type ByContentType = {
|
|
|
1036
883
|
* ]
|
|
1037
884
|
* ```
|
|
1038
885
|
*/
|
|
1039
|
-
type Exclude$1 =
|
|
886
|
+
type Exclude$1 = Filter;
|
|
1040
887
|
/**
|
|
1041
888
|
* Filter that restricts generation to operations or schemas matching at least
|
|
1042
889
|
* one entry. Useful for partial builds (one tag, one API version).
|
|
@@ -1049,7 +896,7 @@ type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | ByS
|
|
|
1049
896
|
* ]
|
|
1050
897
|
* ```
|
|
1051
898
|
*/
|
|
1052
|
-
type Include =
|
|
899
|
+
type Include = Filter;
|
|
1053
900
|
/**
|
|
1054
901
|
* Filter paired with a partial options object. When the filter matches, the
|
|
1055
902
|
* options are merged on top of the plugin defaults for that operation only.
|
|
@@ -1073,7 +920,7 @@ type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySch
|
|
|
1073
920
|
* ]
|
|
1074
921
|
* ```
|
|
1075
922
|
*/
|
|
1076
|
-
type Override<TOptions> =
|
|
923
|
+
type Override<TOptions> = Filter & {
|
|
1077
924
|
options: Omit<Partial<TOptions>, 'override'>;
|
|
1078
925
|
};
|
|
1079
926
|
type PluginFactoryOptions<
|
|
@@ -1091,7 +938,7 @@ TOptions extends object = object,
|
|
|
1091
938
|
TResolvedOptions extends object = TOptions,
|
|
1092
939
|
/**
|
|
1093
940
|
* Resolver that encapsulates naming and path-resolution helpers.
|
|
1094
|
-
* Define with `
|
|
941
|
+
* Define with `createResolver` and export alongside the plugin.
|
|
1095
942
|
*/
|
|
1096
943
|
TResolver extends Resolver = Resolver> = {
|
|
1097
944
|
name: TName;
|
|
@@ -1120,9 +967,10 @@ type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactor
|
|
|
1120
967
|
addGenerator<TElement = unknown>(...generators: Array<Generator<TFactory, TElement>>): void;
|
|
1121
968
|
/**
|
|
1122
969
|
* Set or override the resolver for this plugin.
|
|
1123
|
-
* The resolver controls file naming and path resolution.
|
|
970
|
+
* The resolver controls file naming and path resolution. Overrides merge over the built-in
|
|
971
|
+
* defaults, so a partial `core` or a single namespace method replaces only what it names.
|
|
1124
972
|
*/
|
|
1125
|
-
setResolver(resolver:
|
|
973
|
+
setResolver(resolver: ResolverOverride): void;
|
|
1126
974
|
/**
|
|
1127
975
|
* Add a macro that rewrites AST nodes before they reach generators. Macros run in the order they
|
|
1128
976
|
* are added, after any macros from earlier `addMacro` calls.
|
|
@@ -1255,50 +1103,215 @@ type KubbPluginEndContext = {
|
|
|
1255
1103
|
*/
|
|
1256
1104
|
declare function definePlugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(factory: (options: TFactory['options']) => Plugin<TFactory>): (options?: TFactory['options']) => Plugin<TFactory>;
|
|
1257
1105
|
//#endregion
|
|
1258
|
-
//#region src/
|
|
1106
|
+
//#region src/defineParser.d.ts
|
|
1107
|
+
type PrintOptions = {
|
|
1108
|
+
extname?: FileNode['extname'];
|
|
1109
|
+
};
|
|
1110
|
+
/**
|
|
1111
|
+
* Converts a resolved {@link FileNode} into the final source string that gets
|
|
1112
|
+
* written to disk. Kubb ships with TypeScript and TSX parsers. Add your own
|
|
1113
|
+
* for new file types (JSON, Markdown, ...).
|
|
1114
|
+
*/
|
|
1115
|
+
type Parser<TMeta extends object = object, TNode = unknown> = {
|
|
1116
|
+
/**
|
|
1117
|
+
* Display name used in diagnostics and the parser registry.
|
|
1118
|
+
*/
|
|
1119
|
+
name: string;
|
|
1120
|
+
/**
|
|
1121
|
+
* File extensions this parser handles. The driver registers the parser for each
|
|
1122
|
+
* extension in this list. A parser with `undefined` here is not registered, so
|
|
1123
|
+
* files of an unclaimed extension fall back to joining their sources verbatim.
|
|
1124
|
+
*
|
|
1125
|
+
* @example
|
|
1126
|
+
* `['.ts', '.js']`
|
|
1127
|
+
*/
|
|
1128
|
+
extNames: Array<FileNode['extname']> | undefined;
|
|
1129
|
+
/**
|
|
1130
|
+
* Serialize the file's AST into source code.
|
|
1131
|
+
*/
|
|
1132
|
+
parse(file: FileNode<TMeta>, options?: PrintOptions): string;
|
|
1133
|
+
/**
|
|
1134
|
+
* Render compiler AST nodes for this parser's language into source text.
|
|
1135
|
+
* Plugins call this to format the nodes they assemble before handing them
|
|
1136
|
+
* back to the parser as `FileNode.sources`.
|
|
1137
|
+
*/
|
|
1138
|
+
print(...nodes: Array<TNode>): string;
|
|
1139
|
+
};
|
|
1259
1140
|
/**
|
|
1260
|
-
*
|
|
1141
|
+
* Defines a parser with type-safe `this`. Used to register handlers for new
|
|
1142
|
+
* file extensions or to plug a non-TypeScript output into the build.
|
|
1143
|
+
*
|
|
1144
|
+
* @example
|
|
1145
|
+
* ```ts
|
|
1146
|
+
* import { defineParser } from '@kubb/core'
|
|
1147
|
+
* import { extractStringsFromNodes } from '@kubb/ast'
|
|
1261
1148
|
*
|
|
1262
|
-
*
|
|
1149
|
+
* export const jsonParser = defineParser({
|
|
1150
|
+
* name: 'json',
|
|
1151
|
+
* extNames: ['.json'],
|
|
1152
|
+
* parse(file) {
|
|
1153
|
+
* return file.sources
|
|
1154
|
+
* .map((source) => extractStringsFromNodes(source.nodes ?? []))
|
|
1155
|
+
* .join('\n')
|
|
1156
|
+
* },
|
|
1157
|
+
* print(...nodes) {
|
|
1158
|
+
* return nodes.map(String).join('\n')
|
|
1159
|
+
* },
|
|
1160
|
+
* })
|
|
1161
|
+
* ```
|
|
1162
|
+
*/
|
|
1163
|
+
declare function defineParser<T extends Parser>(parser: T): T;
|
|
1164
|
+
//#endregion
|
|
1165
|
+
//#region src/asyncEventEmitter.d.ts
|
|
1166
|
+
/**
|
|
1167
|
+
* A function that can be registered as an event listener, synchronous or async.
|
|
1168
|
+
*/
|
|
1169
|
+
type AsyncListener<TArgs extends Array<unknown>> = (...args: TArgs) => void | Promise<void>;
|
|
1170
|
+
/**
|
|
1171
|
+
* Typed `EventEmitter` that awaits all async listeners before resolving.
|
|
1172
|
+
* Wraps Node's `EventEmitter` with full TypeScript event-map inference.
|
|
1173
|
+
*
|
|
1174
|
+
* @example
|
|
1175
|
+
* ```ts
|
|
1176
|
+
* const emitter = new AsyncEventEmitter<{ build: [name: string] }>()
|
|
1177
|
+
* emitter.on('build', async (name) => { console.log(name) })
|
|
1178
|
+
* await emitter.emit('build', 'petstore') // all listeners awaited
|
|
1179
|
+
* ```
|
|
1180
|
+
*/
|
|
1181
|
+
declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: Array<unknown> }> {
|
|
1182
|
+
#private;
|
|
1183
|
+
/**
|
|
1184
|
+
* Maximum number of listeners per event before Node emits a memory-leak warning.
|
|
1185
|
+
* @default 10
|
|
1186
|
+
*/
|
|
1187
|
+
constructor(maxListener?: number);
|
|
1188
|
+
/**
|
|
1189
|
+
* Emits `eventName` and awaits all registered listeners sequentially.
|
|
1190
|
+
* Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
|
|
1191
|
+
*
|
|
1192
|
+
* @example
|
|
1193
|
+
* ```ts
|
|
1194
|
+
* await emitter.emit('build', 'petstore')
|
|
1195
|
+
* ```
|
|
1196
|
+
*/
|
|
1197
|
+
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> | void;
|
|
1198
|
+
/**
|
|
1199
|
+
* Registers a persistent listener for `eventName`.
|
|
1200
|
+
*
|
|
1201
|
+
* @example
|
|
1202
|
+
* ```ts
|
|
1203
|
+
* emitter.on('build', async (name) => { console.log(name) })
|
|
1204
|
+
* ```
|
|
1205
|
+
*/
|
|
1206
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
1207
|
+
/**
|
|
1208
|
+
* Removes a previously registered listener.
|
|
1209
|
+
*
|
|
1210
|
+
* @example
|
|
1211
|
+
* ```ts
|
|
1212
|
+
* emitter.off('build', handler)
|
|
1213
|
+
* ```
|
|
1214
|
+
*/
|
|
1215
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
1216
|
+
/**
|
|
1217
|
+
* Returns the number of listeners registered for `eventName`.
|
|
1218
|
+
*
|
|
1219
|
+
* @example
|
|
1220
|
+
* ```ts
|
|
1221
|
+
* emitter.on('build', handler)
|
|
1222
|
+
* emitter.listenerCount('build') // 1
|
|
1223
|
+
* ```
|
|
1224
|
+
*/
|
|
1225
|
+
listenerCount<TEventName extends keyof TEvents & string>(eventName: TEventName): number;
|
|
1226
|
+
/**
|
|
1227
|
+
* Raises or lowers the per-event listener ceiling before Node warns about a memory leak.
|
|
1228
|
+
* Set this above the expected listener count when many listeners attach by design.
|
|
1229
|
+
*
|
|
1230
|
+
* @example
|
|
1231
|
+
* ```ts
|
|
1232
|
+
* emitter.setMaxListeners(40)
|
|
1233
|
+
* ```
|
|
1234
|
+
*/
|
|
1235
|
+
setMaxListeners(max: number): void;
|
|
1236
|
+
/**
|
|
1237
|
+
* Removes all listeners from every event channel.
|
|
1238
|
+
*
|
|
1239
|
+
* @example
|
|
1240
|
+
* ```ts
|
|
1241
|
+
* emitter.removeAll()
|
|
1242
|
+
* ```
|
|
1243
|
+
*/
|
|
1244
|
+
removeAll(): void;
|
|
1245
|
+
}
|
|
1246
|
+
//#endregion
|
|
1247
|
+
//#region src/FileManager.d.ts
|
|
1248
|
+
/**
|
|
1249
|
+
* Hooks fired around a `FileManager#write` batch: `start` before it, `update` per file, `end` after.
|
|
1263
1250
|
*/
|
|
1264
1251
|
type FileManagerHooks = {
|
|
1265
|
-
|
|
1252
|
+
start: [files: Array<FileNode>];
|
|
1253
|
+
update: [params: {
|
|
1254
|
+
file: FileNode;
|
|
1255
|
+
source?: string;
|
|
1256
|
+
processed: number;
|
|
1257
|
+
total: number;
|
|
1258
|
+
percentage: number;
|
|
1259
|
+
}];
|
|
1260
|
+
end: [files: Array<FileNode>];
|
|
1261
|
+
};
|
|
1262
|
+
type ParseOptions = {
|
|
1263
|
+
parsers?: Map<FileNode['extname'], Parser>;
|
|
1264
|
+
extension?: Record<FileNode['extname'], FileNode['extname'] | ''>;
|
|
1265
|
+
};
|
|
1266
|
+
type WriteOptions = ParseOptions & {
|
|
1267
|
+
storage: Storage;
|
|
1266
1268
|
};
|
|
1267
1269
|
/**
|
|
1268
|
-
* In-memory file store for generated files
|
|
1269
|
-
*
|
|
1270
|
-
* path length (barrel `index.ts` last
|
|
1270
|
+
* In-memory file store for generated files, and the writer that turns them into source
|
|
1271
|
+
* strings on `storage`. Files sharing a `path` are merged (sources/imports/exports
|
|
1272
|
+
* concatenated). The `files` getter is sorted by path length (barrel `index.ts` last
|
|
1273
|
+
* within a bucket).
|
|
1271
1274
|
*
|
|
1272
1275
|
* @example
|
|
1273
1276
|
* ```ts
|
|
1274
1277
|
* const manager = new FileManager()
|
|
1275
1278
|
* manager.upsert(myFile)
|
|
1276
1279
|
* manager.files // sorted view
|
|
1280
|
+
* await manager.write(manager.files, { storage: fsStorage() })
|
|
1277
1281
|
* ```
|
|
1278
1282
|
*/
|
|
1279
1283
|
declare class FileManager {
|
|
1280
1284
|
#private;
|
|
1281
|
-
/**
|
|
1282
|
-
* Subscribe to file-store changes. Listeners on `upsert` see each resolved file as it lands
|
|
1283
|
-
* through `add` or `upsert`.
|
|
1284
|
-
*/
|
|
1285
1285
|
readonly hooks: AsyncEventEmitter<FileManagerHooks>;
|
|
1286
1286
|
add(...files: Array<FileNode>): Array<FileNode>;
|
|
1287
1287
|
upsert(...files: Array<FileNode>): Array<FileNode>;
|
|
1288
|
-
getByPath(path: string): FileNode | null;
|
|
1289
|
-
deleteByPath(path: string): void;
|
|
1290
1288
|
clear(): void;
|
|
1291
1289
|
/**
|
|
1292
1290
|
* Releases all stored files and clears every `hooks` listener. Called by the core after
|
|
1293
1291
|
* `kubb:build:end`.
|
|
1294
1292
|
*/
|
|
1295
1293
|
dispose(): void;
|
|
1296
|
-
[Symbol.dispose](): void;
|
|
1297
1294
|
/**
|
|
1298
1295
|
* All stored files in stable sort order (shortest path first, barrel files
|
|
1299
1296
|
* last within a length bucket). Returns a cached view, do not mutate.
|
|
1300
1297
|
*/
|
|
1301
1298
|
get files(): Array<FileNode>;
|
|
1299
|
+
/**
|
|
1300
|
+
* Converts a file's AST sources (or its `copy` source) into the final on-disk string.
|
|
1301
|
+
*/
|
|
1302
|
+
parse(file: FileNode, {
|
|
1303
|
+
parsers,
|
|
1304
|
+
extension
|
|
1305
|
+
}?: ParseOptions): Promise<string>;
|
|
1306
|
+
/**
|
|
1307
|
+
* Converts and writes every file at once, letting `storage.setItem` decide how much of
|
|
1308
|
+
* that runs concurrently.
|
|
1309
|
+
*/
|
|
1310
|
+
write(files: Array<FileNode>, {
|
|
1311
|
+
storage,
|
|
1312
|
+
parsers,
|
|
1313
|
+
extension
|
|
1314
|
+
}: WriteOptions): Promise<void>;
|
|
1302
1315
|
}
|
|
1303
1316
|
//#endregion
|
|
1304
1317
|
//#region src/KubbDriver.d.ts
|
|
@@ -1317,10 +1330,9 @@ declare class KubbDriver {
|
|
|
1317
1330
|
readonly config: Config;
|
|
1318
1331
|
readonly options: Options;
|
|
1319
1332
|
/**
|
|
1320
|
-
* The
|
|
1321
|
-
* Parse-only adapters are wrapped automatically.
|
|
1333
|
+
* The `InputNode` produced by the adapter. Set after adapter setup.
|
|
1322
1334
|
*/
|
|
1323
|
-
inputNode: InputNode
|
|
1335
|
+
inputNode: InputNode | null;
|
|
1324
1336
|
adapter: Adapter | null;
|
|
1325
1337
|
/**
|
|
1326
1338
|
* Central file store for all generated files.
|
|
@@ -1361,10 +1373,10 @@ declare class KubbDriver {
|
|
|
1361
1373
|
registerGenerator(pluginName: string, generator: Generator): void;
|
|
1362
1374
|
/**
|
|
1363
1375
|
* Returns `true` when at least one generator was registered for the given plugin
|
|
1364
|
-
* via `addGenerator()` in `kubb:plugin:setup
|
|
1376
|
+
* via `addGenerator()` in `kubb:plugin:setup`.
|
|
1365
1377
|
*
|
|
1366
1378
|
* Used by the build loop to decide whether to walk the AST and emit generator events
|
|
1367
|
-
* for a plugin
|
|
1379
|
+
* for a plugin.
|
|
1368
1380
|
*/
|
|
1369
1381
|
hasEventGenerators(pluginName: string): boolean;
|
|
1370
1382
|
/**
|
|
@@ -1412,12 +1424,12 @@ declare class KubbDriver {
|
|
|
1412
1424
|
* Also mirrors it onto `plugin.resolver` so callers using `getPlugin(name).resolver`
|
|
1413
1425
|
* get the up-to-date resolver without going through `getResolver()`.
|
|
1414
1426
|
*/
|
|
1415
|
-
setPluginResolver(pluginName: string, partial:
|
|
1427
|
+
setPluginResolver(pluginName: string, partial: ResolverOverride): void;
|
|
1416
1428
|
/**
|
|
1417
1429
|
* Returns the resolver for the given plugin.
|
|
1418
1430
|
*
|
|
1419
|
-
* Resolution order:
|
|
1420
|
-
*
|
|
1431
|
+
* Resolution order: resolver set via `setPluginResolver` → lazily created default
|
|
1432
|
+
* resolver (identity name, no path transforms).
|
|
1421
1433
|
*/
|
|
1422
1434
|
getResolver<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Kubb.PluginRegistry[TName]['resolver'];
|
|
1423
1435
|
getResolver<TResolver extends Resolver = Resolver>(pluginName: string): TResolver;
|
|
@@ -1491,11 +1503,11 @@ type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptio
|
|
|
1491
1503
|
* called. Kubb picks a `setResolver` registration first, then the plugin's static
|
|
1492
1504
|
* `resolver`, then the built-in default.
|
|
1493
1505
|
*
|
|
1494
|
-
* @example Resolve a
|
|
1495
|
-
* `ctx.resolver.
|
|
1506
|
+
* @example Resolve a name
|
|
1507
|
+
* `ctx.resolver.name('pet') // 'pet'`
|
|
1496
1508
|
*
|
|
1497
1509
|
* @example Resolve an output file
|
|
1498
|
-
* `ctx.resolver.
|
|
1510
|
+
* `ctx.resolver.file({ name: 'pet', extname: '.ts' }, { root, output })`
|
|
1499
1511
|
*/
|
|
1500
1512
|
resolver: TOptions['resolver'];
|
|
1501
1513
|
/**
|
|
@@ -1628,65 +1640,6 @@ type Generator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TEl
|
|
|
1628
1640
|
*/
|
|
1629
1641
|
declare function defineGenerator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown>(generator: Generator<TOptions, TElement>): Generator<TOptions, TElement>;
|
|
1630
1642
|
//#endregion
|
|
1631
|
-
//#region src/defineParser.d.ts
|
|
1632
|
-
type PrintOptions = {
|
|
1633
|
-
extname?: FileNode['extname'];
|
|
1634
|
-
};
|
|
1635
|
-
/**
|
|
1636
|
-
* Converts a resolved {@link FileNode} into the final source string that gets
|
|
1637
|
-
* written to disk. Kubb ships with TypeScript and TSX parsers. Add your own
|
|
1638
|
-
* for new file types (JSON, Markdown, ...).
|
|
1639
|
-
*/
|
|
1640
|
-
type Parser<TMeta extends object = object, TNode = unknown> = {
|
|
1641
|
-
/**
|
|
1642
|
-
* Display name used in diagnostics and the parser registry.
|
|
1643
|
-
*/
|
|
1644
|
-
name: string;
|
|
1645
|
-
/**
|
|
1646
|
-
* File extensions this parser handles. The driver registers the parser for each
|
|
1647
|
-
* extension in this list. A parser with `undefined` here is not registered, so
|
|
1648
|
-
* files of an unclaimed extension fall back to joining their sources verbatim.
|
|
1649
|
-
*
|
|
1650
|
-
* @example
|
|
1651
|
-
* `['.ts', '.js']`
|
|
1652
|
-
*/
|
|
1653
|
-
extNames: Array<FileNode['extname']> | undefined;
|
|
1654
|
-
/**
|
|
1655
|
-
* Serialize the file's AST into source code.
|
|
1656
|
-
*/
|
|
1657
|
-
parse(file: FileNode<TMeta>, options?: PrintOptions): string;
|
|
1658
|
-
/**
|
|
1659
|
-
* Render compiler AST nodes for this parser's language into source text.
|
|
1660
|
-
* Plugins call this to format the nodes they assemble before handing them
|
|
1661
|
-
* back to the parser as `FileNode.sources`.
|
|
1662
|
-
*/
|
|
1663
|
-
print(...nodes: Array<TNode>): string;
|
|
1664
|
-
};
|
|
1665
|
-
/**
|
|
1666
|
-
* Defines a parser with type-safe `this`. Used to register handlers for new
|
|
1667
|
-
* file extensions or to plug a non-TypeScript output into the build.
|
|
1668
|
-
*
|
|
1669
|
-
* @example
|
|
1670
|
-
* ```ts
|
|
1671
|
-
* import { defineParser } from '@kubb/core'
|
|
1672
|
-
* import { extractStringsFromNodes } from '@kubb/ast'
|
|
1673
|
-
*
|
|
1674
|
-
* export const jsonParser = defineParser({
|
|
1675
|
-
* name: 'json',
|
|
1676
|
-
* extNames: ['.json'],
|
|
1677
|
-
* parse(file) {
|
|
1678
|
-
* return file.sources
|
|
1679
|
-
* .map((source) => extractStringsFromNodes(source.nodes ?? []))
|
|
1680
|
-
* .join('\n')
|
|
1681
|
-
* },
|
|
1682
|
-
* print(...nodes) {
|
|
1683
|
-
* return nodes.map(String).join('\n')
|
|
1684
|
-
* },
|
|
1685
|
-
* })
|
|
1686
|
-
* ```
|
|
1687
|
-
*/
|
|
1688
|
-
declare function defineParser<T extends Parser>(parser: T): T;
|
|
1689
|
-
//#endregion
|
|
1690
1643
|
//#region src/createKubb.d.ts
|
|
1691
1644
|
type CreateKubbOptions = {
|
|
1692
1645
|
hooks?: AsyncEventEmitter<KubbHooks>;
|
|
@@ -1755,46 +1708,8 @@ declare class Kubb$1 {
|
|
|
1755
1708
|
*/
|
|
1756
1709
|
declare function createKubb(userConfig: UserConfig, options?: CreateKubbOptions): Kubb$1;
|
|
1757
1710
|
//#endregion
|
|
1758
|
-
//#region src/FileProcessor.d.ts
|
|
1759
|
-
/**
|
|
1760
|
-
* Hooks fired by a `FileProcessor`.
|
|
1761
|
-
*
|
|
1762
|
-
* - `start` opens a batch, from `run` or a queue flush.
|
|
1763
|
-
* - `update` fires once per file as it is converted.
|
|
1764
|
-
* - `end` closes a batch.
|
|
1765
|
-
* - `enqueue` fires for every `enqueue` call.
|
|
1766
|
-
* - `drain` fires when `drain()` empties the queue with no in-flight batch left.
|
|
1767
|
-
*/
|
|
1768
|
-
type FileProcessorHooks = {
|
|
1769
|
-
start: [files: Array<FileNode>];
|
|
1770
|
-
update: [params: {
|
|
1771
|
-
file: FileNode;
|
|
1772
|
-
source?: string;
|
|
1773
|
-
processed: number;
|
|
1774
|
-
total: number;
|
|
1775
|
-
percentage: number;
|
|
1776
|
-
}];
|
|
1777
|
-
end: [files: Array<FileNode>];
|
|
1778
|
-
enqueue: [file: FileNode];
|
|
1779
|
-
drain: [];
|
|
1780
|
-
};
|
|
1781
|
-
/**
|
|
1782
|
-
* Per-file progress record yielded by `stream` and surfaced through the `update` event.
|
|
1783
|
-
*/
|
|
1784
|
-
type ParsedFile = {
|
|
1785
|
-
file: FileNode;
|
|
1786
|
-
source: string;
|
|
1787
|
-
processed: number;
|
|
1788
|
-
total: number;
|
|
1789
|
-
percentage: number;
|
|
1790
|
-
};
|
|
1791
|
-
//#endregion
|
|
1792
1711
|
//#region src/types.d.ts
|
|
1793
1712
|
/**
|
|
1794
|
-
* Extracts a type from a registry, falling back to `{}` when the key doesn't exist.
|
|
1795
|
-
* Lets plugins augment `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry`
|
|
1796
|
-
* without changing core.
|
|
1797
|
-
*
|
|
1798
1713
|
* @internal
|
|
1799
1714
|
*/
|
|
1800
1715
|
type ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {};
|
|
@@ -2520,19 +2435,16 @@ type BuildOutput = {
|
|
|
2520
2435
|
*/
|
|
2521
2436
|
driver: KubbDriver;
|
|
2522
2437
|
/**
|
|
2523
|
-
*
|
|
2524
|
-
*
|
|
2438
|
+
* The configured `Storage` backend, for reading back a generated file's final content.
|
|
2439
|
+
* Use `files` to list what this build produced.
|
|
2525
2440
|
*
|
|
2526
2441
|
* @example Read a generated file
|
|
2527
2442
|
* `const code = await buildOutput.storage.getItem('/src/gen/pet.ts')`
|
|
2528
|
-
*
|
|
2529
|
-
* @example List all generated file paths
|
|
2530
|
-
* `const paths = await buildOutput.storage.getKeys()`
|
|
2531
2443
|
*/
|
|
2532
2444
|
storage: Storage;
|
|
2533
2445
|
};
|
|
2534
2446
|
//#endregion
|
|
2535
|
-
//#region src/
|
|
2447
|
+
//#region src/Diagnostics.d.ts
|
|
2536
2448
|
/**
|
|
2537
2449
|
* How serious a diagnostic is. `error` fails the build, `warning` and `info`
|
|
2538
2450
|
* are reported but do not.
|
|
@@ -2707,8 +2619,8 @@ type SerializedDiagnostic = {
|
|
|
2707
2619
|
*
|
|
2708
2620
|
* The sink lives in a single `AsyncLocalStorage` in the `@kubb/core` bundle.
|
|
2709
2621
|
* `Diagnostics.scope` activates it for a run, so anything inside that run (the
|
|
2710
|
-
* adapter parse, a
|
|
2711
|
-
*
|
|
2622
|
+
* adapter parse, a generator) reports through `Diagnostics.report` and lands
|
|
2623
|
+
* in the same run.
|
|
2712
2624
|
*/
|
|
2713
2625
|
declare class Diagnostics {
|
|
2714
2626
|
#private;
|
|
@@ -2885,5 +2797,5 @@ declare class Diagnostics {
|
|
|
2885
2797
|
static formatLines(diagnostic: Diagnostic): Array<string>;
|
|
2886
2798
|
}
|
|
2887
2799
|
//#endregion
|
|
2888
|
-
export {
|
|
2889
|
-
//# sourceMappingURL=
|
|
2800
|
+
export { Include as $, KubbHookStartContext as A, ReporterName as At, Kubb$1 as B, KubbFilesProcessingEndContext as C, RendererFactory as Ct, KubbGenerationStartContext as D, GenerationResult as Dt, KubbGenerationEndContext as E, createStorage as Et, KubbSuccessContext as F, AdapterFactoryOptions as Ft, KubbDriver as G, Generator as H, KubbWarnContext as I, AdapterSource as It, Parser as J, FileManagerHooks as K, PossibleConfig as L, createAdapter as Lt, KubbInfoContext as M, createReporter as Mt, KubbLifecycleStartContext as N, logLevel as Nt, KubbHookEndContext as O, Reporter as Ot, KubbPluginsEndContext as P, Adapter as Pt, Group as Q, UserConfig as R, KubbFileProcessingUpdate as S, Renderer as St, KubbFilesProcessingUpdateContext as T, Storage as Tt, GeneratorContext as U, createKubb as V, defineGenerator as W, Exclude$1 as X, defineParser as Y, Filter as Z, InputPath as _, ResolverDefault as _t, DiagnosticLocation as a, OutputMode as at, KubbDiagnosticContext as b, ResolverPathParams as bt, PerformanceDiagnostic as c, Plugin as ct, SerializedDiagnostic as d, BannerMeta as dt, KubbPluginEndContext as et, UpdateDiagnostic as f, ResolveBannerContext as ft, InputData as g, ResolverContext as gt, Config as h, Resolver as ht, DiagnosticKind as i, Output as it, KubbHooks as j, UserReporter as jt, KubbHookLineContext as k, ReporterContext as kt, ProblemCode as l, PluginFactoryOptions as lt, CLIOptions as m, ResolveOptionsContext as mt, DiagnosticByCode as n, KubbPluginStartContext as nt, DiagnosticSeverity as o, OutputOptions as ot, BuildOutput as p, ResolveBannerFile as pt, AsyncEventEmitter as q, DiagnosticDoc as r, NormalizedPlugin as rt, Diagnostics as s, Override as st, Diagnostic as t, KubbPluginSetupContext as tt, ProblemDiagnostic as u, definePlugin as ut, KubbBuildEndContext as v, ResolverFileParams as vt, KubbFilesProcessingStartContext as w, createRenderer as wt, KubbErrorContext as x, createResolver as xt, KubbBuildStartContext as y, ResolverOverride as yt, CreateKubbOptions as z };
|
|
2801
|
+
//# sourceMappingURL=Diagnostics-PnPLU3kj.d.ts.map
|