@kubb/core 5.0.0-beta.57 → 5.0.0-beta.59
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-Bf2bC8lV.d.ts → diagnostics-B-UZnFqP.d.ts} +54 -68
- package/dist/index.cjs +34 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +34 -28
- package/dist/index.js.map +1 -1
- package/dist/{memoryStorage-skOz0dXZ.cjs → memoryStorage-CUj1hrxa.cjs} +9 -7
- package/dist/memoryStorage-CUj1hrxa.cjs.map +1 -0
- package/dist/{memoryStorage-B0W-w994.js → memoryStorage-CWFzAz4o.js} +7 -6
- package/dist/memoryStorage-CWFzAz4o.js.map +1 -0
- package/dist/mocks.cjs +1 -2
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.ts +1 -2
- package/dist/mocks.js +1 -2
- package/dist/mocks.js.map +1 -1
- package/package.json +4 -4
- package/src/FileManager.ts +2 -2
- package/src/FileProcessor.ts +1 -1
- package/src/KubbDriver.ts +13 -6
- package/src/createAdapter.ts +5 -6
- package/src/createRenderer.ts +3 -4
- package/src/createReporter.ts +1 -1
- package/src/createStorage.ts +4 -4
- package/src/defineGenerator.ts +2 -2
- package/src/defineParser.ts +3 -2
- package/src/definePlugin.ts +13 -18
- package/src/defineResolver.ts +7 -6
- package/src/diagnostics.ts +8 -11
- package/src/index.ts +1 -0
- package/src/mocks.ts +0 -1
- package/src/reporters/cliReporter.ts +1 -1
- package/src/types.ts +9 -15
- package/dist/memoryStorage-B0W-w994.js.map +0 -1
- package/dist/memoryStorage-skOz0dXZ.cjs.map +0 -1
|
@@ -145,8 +145,8 @@ type AdapterFactoryOptions<TName extends string = string, TOptions extends objec
|
|
|
145
145
|
* Converts input files or inline data into Kubb's universal AST `InputNode`.
|
|
146
146
|
*
|
|
147
147
|
* Adapters live between the spec format and the plugins. The built-in
|
|
148
|
-
* `@kubb/adapter-oas` handles OpenAPI 2.0, 3.0, and 3.1
|
|
149
|
-
* support GraphQL, gRPC,
|
|
148
|
+
* `@kubb/adapter-oas` handles OpenAPI 2.0, 3.0, and 3.1. A custom adapter can
|
|
149
|
+
* support GraphQL, gRPC, or another schema language.
|
|
150
150
|
*
|
|
151
151
|
* @example
|
|
152
152
|
* ```ts
|
|
@@ -208,9 +208,8 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
|
208
208
|
type AdapterBuilder<T extends AdapterFactoryOptions> = (options: T['options']) => Adapter<T>;
|
|
209
209
|
/**
|
|
210
210
|
* Defines a custom adapter that translates a spec format into Kubb's universal
|
|
211
|
-
* AST
|
|
212
|
-
*
|
|
213
|
-
* OpenAPI/Swagger documents.
|
|
211
|
+
* AST, for example GraphQL, gRPC, or AsyncAPI. The built-in `@kubb/adapter-oas`
|
|
212
|
+
* handles OpenAPI/Swagger documents.
|
|
214
213
|
*
|
|
215
214
|
* Adapters must return an `InputNode` from `parse`. That node is what every
|
|
216
215
|
* plugin in the build consumes.
|
|
@@ -227,7 +226,7 @@ type AdapterBuilder<T extends AdapterFactoryOptions> = (options: T['options']) =
|
|
|
227
226
|
* document: null,
|
|
228
227
|
* async parse(_source) {
|
|
229
228
|
* // Convert `source` (path or inline data) into an InputNode.
|
|
230
|
-
* return ast.createInput()
|
|
229
|
+
* return ast.factory.createInput()
|
|
231
230
|
* },
|
|
232
231
|
* getImports: () => [],
|
|
233
232
|
* async validate() {
|
|
@@ -384,7 +383,7 @@ type ReporterContext = {
|
|
|
384
383
|
};
|
|
385
384
|
/**
|
|
386
385
|
* Host-facing reporter, as installed onto a run. Unlike a Logger (the live TUI view), a reporter
|
|
387
|
-
* never sees the event emitter. `report` runs once per config
|
|
386
|
+
* never sees the event emitter. `report` runs once per config. `drain`, when present, runs once
|
|
388
387
|
* after the last config.
|
|
389
388
|
*/
|
|
390
389
|
type Reporter = {
|
|
@@ -439,7 +438,7 @@ declare function createReporter<T = void>(reporter: UserReporter<T>): Reporter;
|
|
|
439
438
|
/**
|
|
440
439
|
* Backend that persists generated files. Kubb ships with `fsStorage` (writes
|
|
441
440
|
* to disk) and `memoryStorage` (keeps everything in RAM). Implement this
|
|
442
|
-
* interface to write
|
|
441
|
+
* interface to write somewhere else, such as S3 or a database.
|
|
443
442
|
*/
|
|
444
443
|
type Storage = {
|
|
445
444
|
/**
|
|
@@ -479,9 +478,9 @@ type Storage = {
|
|
|
479
478
|
};
|
|
480
479
|
/**
|
|
481
480
|
* Defines a custom storage backend. The builder receives user options and
|
|
482
|
-
* returns a `Storage` implementation. Kubb ships with filesystem and
|
|
483
|
-
*
|
|
484
|
-
*
|
|
481
|
+
* returns a `Storage` implementation. Kubb ships with filesystem and in-memory
|
|
482
|
+
* storages. A custom backend writes generated files elsewhere, such as cloud
|
|
483
|
+
* storage or a database.
|
|
485
484
|
*
|
|
486
485
|
* @example In-memory storage (the built-in implementation)
|
|
487
486
|
* ```ts
|
|
@@ -559,10 +558,9 @@ type RendererFactory<TElement = unknown> = () => Renderer<TElement>;
|
|
|
559
558
|
* (JSX, a template string, a tree of any shape) into `FileNode`s that get
|
|
560
559
|
* written to disk.
|
|
561
560
|
*
|
|
562
|
-
*
|
|
563
|
-
* renderer
|
|
564
|
-
*
|
|
565
|
-
* field on `defineGenerator`.
|
|
561
|
+
* A renderer can target output formats beyond JSX, for instance a Handlebars
|
|
562
|
+
* renderer or one that writes binary files. Plugins and generators pick the
|
|
563
|
+
* renderer to use via the `renderer` field on `defineGenerator`.
|
|
566
564
|
*
|
|
567
565
|
* @example A minimal renderer that wraps a custom runtime
|
|
568
566
|
* ```ts
|
|
@@ -797,8 +795,8 @@ type ResolverBuilder<T extends PluginFactoryOptions> = () => Omit<T['resolver'],
|
|
|
797
795
|
/**
|
|
798
796
|
* Default path resolver used by `defineResolver`.
|
|
799
797
|
*
|
|
800
|
-
* - `mode: 'file'`
|
|
801
|
-
* - `mode: 'directory'` (default)
|
|
798
|
+
* - `mode: 'file'` resolves directly to `output.path` (the full file path, extension included).
|
|
799
|
+
* - `mode: 'directory'` (default) resolves to `output.path/{baseName}`, or into a
|
|
802
800
|
* subdirectory when `group` and a `tag`/`path` value are provided.
|
|
803
801
|
*
|
|
804
802
|
* A custom `group.name` function overrides the default subdirectory naming.
|
|
@@ -850,8 +848,8 @@ type ResolverBuilder<T extends PluginFactoryOptions> = () => Omit<T['resolver'],
|
|
|
850
848
|
* - `resolveFile` builds the full `FileNode`.
|
|
851
849
|
* - `resolveBanner` and `resolveFooter` produce the top and bottom of file text.
|
|
852
850
|
*
|
|
853
|
-
* Methods in the returned object can call sibling resolver methods via `this
|
|
854
|
-
*
|
|
851
|
+
* Methods in the returned object can call sibling resolver methods via `this`.
|
|
852
|
+
* A custom rule can delegate to a default, for example `this.default(name, 'type')`.
|
|
855
853
|
*
|
|
856
854
|
* @example Basic resolver with naming helpers
|
|
857
855
|
* ```ts
|
|
@@ -882,9 +880,9 @@ declare function defineResolver<T extends PluginFactoryOptions>(build: ResolverB
|
|
|
882
880
|
//#endregion
|
|
883
881
|
//#region src/definePlugin.d.ts
|
|
884
882
|
/**
|
|
885
|
-
*
|
|
886
|
-
*
|
|
887
|
-
*
|
|
883
|
+
* Reads a type from a registry, falling back to `{}` when the key is absent. Lets
|
|
884
|
+
* `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry` be augmented without
|
|
885
|
+
* touching core.
|
|
888
886
|
*
|
|
889
887
|
* @internal
|
|
890
888
|
*/
|
|
@@ -966,7 +964,7 @@ type Group = {
|
|
|
966
964
|
* files into per-group subdirectories.
|
|
967
965
|
*
|
|
968
966
|
* Intersect into a plugin's `Options` type instead of declaring `output` and
|
|
969
|
-
* `group` directly
|
|
967
|
+
* `group` directly, since `mode` lives inside `output` while `group` is its sibling.
|
|
970
968
|
* The generic keeps a plugin's extended `Output` shape intact.
|
|
971
969
|
*
|
|
972
970
|
* @example
|
|
@@ -1048,9 +1046,8 @@ type ByContentType = {
|
|
|
1048
1046
|
pattern: string | RegExp;
|
|
1049
1047
|
};
|
|
1050
1048
|
/**
|
|
1051
|
-
* Filter that skips matching operations or schemas during generation
|
|
1052
|
-
*
|
|
1053
|
-
* not want code generated for.
|
|
1049
|
+
* Filter that skips matching operations or schemas during generation, for example
|
|
1050
|
+
* deprecated endpoints or internal-only schemas.
|
|
1054
1051
|
*
|
|
1055
1052
|
* @example
|
|
1056
1053
|
* ```ts
|
|
@@ -1125,8 +1122,8 @@ TResolver extends Resolver = Resolver> = {
|
|
|
1125
1122
|
resolver: TResolver;
|
|
1126
1123
|
};
|
|
1127
1124
|
/**
|
|
1128
|
-
* Context
|
|
1129
|
-
*
|
|
1125
|
+
* Context passed to a plugin's `kubb:plugin:setup` handler, where it registers generators and
|
|
1126
|
+
* sets its resolver, transformer, and options.
|
|
1130
1127
|
*/
|
|
1131
1128
|
type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1132
1129
|
/**
|
|
@@ -1166,11 +1163,8 @@ type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactor
|
|
|
1166
1163
|
options: TFactory['options'];
|
|
1167
1164
|
};
|
|
1168
1165
|
/**
|
|
1169
|
-
* A plugin object produced by `definePlugin`.
|
|
1170
|
-
*
|
|
1171
|
-
* (matching Astro's integration naming convention).
|
|
1172
|
-
*
|
|
1173
|
-
* @template TFactory - The plugin's `PluginFactoryOptions` type.
|
|
1166
|
+
* A plugin object produced by `definePlugin`. Its lifecycle handlers live under a single
|
|
1167
|
+
* `hooks` property rather than flat methods.
|
|
1174
1168
|
*/
|
|
1175
1169
|
type Plugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1176
1170
|
/**
|
|
@@ -1205,8 +1199,8 @@ type Plugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
1205
1199
|
};
|
|
1206
1200
|
};
|
|
1207
1201
|
/**
|
|
1208
|
-
* Normalized plugin after setup, with runtime fields populated.
|
|
1209
|
-
*
|
|
1202
|
+
* Normalized plugin after setup, with runtime fields populated. Internal only. Plugins use the
|
|
1203
|
+
* public `Plugin` type.
|
|
1210
1204
|
*
|
|
1211
1205
|
* @internal
|
|
1212
1206
|
*/
|
|
@@ -1244,8 +1238,7 @@ type KubbPluginEndContext = {
|
|
|
1244
1238
|
};
|
|
1245
1239
|
/**
|
|
1246
1240
|
* Wraps a plugin factory and returns a function that accepts user options and
|
|
1247
|
-
* yields a
|
|
1248
|
-
* `hooks` object (inspired by Astro integrations).
|
|
1241
|
+
* yields a typed `Plugin`. Lifecycle handlers go inside a single `hooks` object.
|
|
1249
1242
|
*
|
|
1250
1243
|
* Pass a `PluginFactoryOptions` type parameter to get a typed `ctx` inside
|
|
1251
1244
|
* `kubb:plugin:setup`. Plugin names should follow the `plugin-<feature>`
|
|
@@ -1329,7 +1322,8 @@ declare class KubbDriver {
|
|
|
1329
1322
|
readonly config: Config;
|
|
1330
1323
|
readonly options: Options;
|
|
1331
1324
|
/**
|
|
1332
|
-
* The streaming `InputNode<true>` produced by the adapter.
|
|
1325
|
+
* The streaming `InputNode<true>` produced by the adapter. Set after adapter setup.
|
|
1326
|
+
* Parse-only adapters are wrapped automatically.
|
|
1333
1327
|
*/
|
|
1334
1328
|
inputNode: InputNode<true> | null;
|
|
1335
1329
|
adapter: Adapter | null;
|
|
@@ -1545,8 +1539,8 @@ type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptio
|
|
|
1545
1539
|
* Declares a named generator unit that walks the AST and emits files.
|
|
1546
1540
|
*
|
|
1547
1541
|
* Each method (`schema`, `operation`, `operations`) is called for the matching node type.
|
|
1548
|
-
*
|
|
1549
|
-
*
|
|
1542
|
+
* JSX-based generators require a `renderer` factory. Return `Array<FileNode>` directly, or call
|
|
1543
|
+
* `ctx.upsertFile()` manually and return `null` to bypass rendering.
|
|
1550
1544
|
*
|
|
1551
1545
|
* @note Generators are consumed by plugins and registered via `ctx.addGenerator()` in `kubb:plugin:setup`.
|
|
1552
1546
|
*
|
|
@@ -1678,14 +1672,15 @@ type Parser<TMeta extends object = object, TNode = unknown> = {
|
|
|
1678
1672
|
*
|
|
1679
1673
|
* @example
|
|
1680
1674
|
* ```ts
|
|
1681
|
-
* import { defineParser
|
|
1675
|
+
* import { defineParser } from '@kubb/core'
|
|
1676
|
+
* import { extractStringsFromNodes } from '@kubb/ast/utils'
|
|
1682
1677
|
*
|
|
1683
1678
|
* export const jsonParser = defineParser({
|
|
1684
1679
|
* name: 'json',
|
|
1685
1680
|
* extNames: ['.json'],
|
|
1686
1681
|
* parse(file) {
|
|
1687
1682
|
* return file.sources
|
|
1688
|
-
* .map((source) =>
|
|
1683
|
+
* .map((source) => extractStringsFromNodes(source.nodes ?? []))
|
|
1689
1684
|
* .join('\n')
|
|
1690
1685
|
* },
|
|
1691
1686
|
* print(...nodes) {
|
|
@@ -1801,9 +1796,9 @@ type ParsedFile = {
|
|
|
1801
1796
|
//#endregion
|
|
1802
1797
|
//#region src/types.d.ts
|
|
1803
1798
|
/**
|
|
1804
|
-
*
|
|
1805
|
-
*
|
|
1806
|
-
* without
|
|
1799
|
+
* Extracts a type from a registry, falling back to `{}` when the key doesn't exist.
|
|
1800
|
+
* Lets plugins augment `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry`
|
|
1801
|
+
* without changing core.
|
|
1807
1802
|
*
|
|
1808
1803
|
* @internal
|
|
1809
1804
|
*/
|
|
@@ -1924,7 +1919,6 @@ type Config<TInput = Input> = {
|
|
|
1924
1919
|
* Remove every file in the output directory before the build, so stale output isn't mixed
|
|
1925
1920
|
* with new files. Leave `false` to preserve manual edits in the output directory.
|
|
1926
1921
|
*
|
|
1927
|
-
* @default false
|
|
1928
1922
|
* @example
|
|
1929
1923
|
* ```ts
|
|
1930
1924
|
* clean: true // wipes ./src/gen/* before generating
|
|
@@ -1935,7 +1929,6 @@ type Config<TInput = Input> = {
|
|
|
1935
1929
|
* Format the generated files after generation. `'auto'` runs the first formatter it finds
|
|
1936
1930
|
* (oxfmt, biome, or prettier), a named tool forces that one, and `false` skips formatting.
|
|
1937
1931
|
*
|
|
1938
|
-
* @default false
|
|
1939
1932
|
* @example
|
|
1940
1933
|
* ```ts
|
|
1941
1934
|
* format: 'auto' // auto-detect prettier, biome, or oxfmt
|
|
@@ -1948,7 +1941,6 @@ type Config<TInput = Input> = {
|
|
|
1948
1941
|
* Lint the generated files after generation. `'auto'` runs the first linter it finds
|
|
1949
1942
|
* (oxlint, biome, or eslint), a named tool forces that one, and `false` skips linting.
|
|
1950
1943
|
*
|
|
1951
|
-
* @default false
|
|
1952
1944
|
* @example
|
|
1953
1945
|
* ```ts
|
|
1954
1946
|
* lint: 'auto' // auto-detect oxlint, biome, or eslint
|
|
@@ -1986,7 +1978,6 @@ type Config<TInput = Input> = {
|
|
|
1986
1978
|
* Overwrite existing files when `true`, skip files that already exist when `false`. Individual
|
|
1987
1979
|
* plugins can override it. Keep `false` to avoid clobbering local edits in the output folder.
|
|
1988
1980
|
*
|
|
1989
|
-
* @default false
|
|
1990
1981
|
* @example
|
|
1991
1982
|
* ```ts
|
|
1992
1983
|
* override: true // regenerate everything, even existing files
|
|
@@ -2032,10 +2023,9 @@ type Config<TInput = Input> = {
|
|
|
2032
2023
|
*/
|
|
2033
2024
|
plugins: Array<Plugin>;
|
|
2034
2025
|
/**
|
|
2035
|
-
* Lifecycle hooks that
|
|
2026
|
+
* Lifecycle hooks that run external tools (prettier, eslint, a custom script) on build events.
|
|
2036
2027
|
*
|
|
2037
|
-
*
|
|
2038
|
-
* Currently supports the `done` hook which fires after all plugins complete.
|
|
2028
|
+
* Currently supports the `done` hook, which fires after all plugins complete.
|
|
2039
2029
|
*
|
|
2040
2030
|
* @example
|
|
2041
2031
|
* ```ts
|
|
@@ -2048,11 +2038,10 @@ type Config<TInput = Input> = {
|
|
|
2048
2038
|
*/
|
|
2049
2039
|
hooks?: {
|
|
2050
2040
|
/**
|
|
2051
|
-
* Command(s) to run after all plugins
|
|
2041
|
+
* Command(s) to run after all plugins finish generating, for post-processing the output.
|
|
2052
2042
|
*
|
|
2053
|
-
*
|
|
2054
|
-
*
|
|
2055
|
-
* Commands are executed relative to the `root` directory.
|
|
2043
|
+
* Pass a single command string, or an array to run them in sequence.
|
|
2044
|
+
* Commands run relative to the `root` directory.
|
|
2056
2045
|
*
|
|
2057
2046
|
* @example
|
|
2058
2047
|
* ```ts
|
|
@@ -2524,7 +2513,7 @@ type CLIOptions = {
|
|
|
2524
2513
|
};
|
|
2525
2514
|
/**
|
|
2526
2515
|
* All accepted forms of a Kubb configuration.
|
|
2527
|
-
* Accepts `Config`/`Config[]`/promise or a factory (optionally receiving `TCliOptions
|
|
2516
|
+
* Accepts `Config`/`Config[]`/promise or a factory (optionally receiving `TCliOptions`).
|
|
2528
2517
|
*/
|
|
2529
2518
|
type PossibleConfig<TCliOptions = undefined> = PossiblePromise<Config | Array<Config>> | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Array<Config>>);
|
|
2530
2519
|
/**
|
|
@@ -2567,9 +2556,8 @@ type BuildOutput = {
|
|
|
2567
2556
|
type DiagnosticSeverity = 'error' | 'warning' | 'info';
|
|
2568
2557
|
/**
|
|
2569
2558
|
* A human-readable explanation of a diagnostic code: a short title, what triggers it, and how
|
|
2570
|
-
* to resolve it. This is the
|
|
2571
|
-
*
|
|
2572
|
-
* {@link DiagnosticCode}, so adding a code without documenting it fails the build.
|
|
2559
|
+
* to resolve it. This is the source of truth the kubb.dev `/diagnostics/<slug>` pages mirror, so
|
|
2560
|
+
* every code stays documented in one place. Adding a code without documenting it fails the build.
|
|
2573
2561
|
*/
|
|
2574
2562
|
type DiagnosticDoc = {
|
|
2575
2563
|
/**
|
|
@@ -2624,9 +2612,7 @@ type DiagnosticKind = 'problem' | 'performance' | 'update';
|
|
|
2624
2612
|
type ProblemCode = Exclude<DiagnosticCode, typeof diagnosticCode.performance | typeof diagnosticCode.updateAvailable>;
|
|
2625
2613
|
/**
|
|
2626
2614
|
* A build problem collected during a run, gathered into the result instead of
|
|
2627
|
-
* aborting on the first failure.
|
|
2628
|
-
* `severity`, a `message`, and optionally a `location` into the source document,
|
|
2629
|
-
* a `help`, the `plugin` that produced it, and the `cause` it wraps.
|
|
2615
|
+
* aborting on the first failure.
|
|
2630
2616
|
*/
|
|
2631
2617
|
type ProblemDiagnostic = {
|
|
2632
2618
|
/**
|
|
@@ -2654,9 +2640,9 @@ type ProblemDiagnostic = {
|
|
|
2654
2640
|
cause?: Error;
|
|
2655
2641
|
};
|
|
2656
2642
|
/**
|
|
2657
|
-
* A per-plugin performance record, built with {@link Diagnostics.performance}.
|
|
2658
|
-
*
|
|
2659
|
-
*
|
|
2643
|
+
* A per-plugin performance record, built with {@link Diagnostics.performance}. The `performance`
|
|
2644
|
+
* kind keeps it out of the problem list. It feeds the per-plugin timing bars, and reporters sum
|
|
2645
|
+
* these into the run total.
|
|
2660
2646
|
*/
|
|
2661
2647
|
type PerformanceDiagnostic = {
|
|
2662
2648
|
kind: 'performance';
|
|
@@ -2674,7 +2660,7 @@ type PerformanceDiagnostic = {
|
|
|
2674
2660
|
};
|
|
2675
2661
|
/**
|
|
2676
2662
|
* A notice that a newer Kubb version is available on npm, built with {@link Diagnostics.update}.
|
|
2677
|
-
* It
|
|
2663
|
+
* It renders like any info diagnostic.
|
|
2678
2664
|
*/
|
|
2679
2665
|
type UpdateDiagnostic = {
|
|
2680
2666
|
kind: 'update';
|
|
@@ -2917,4 +2903,4 @@ declare class Diagnostics {
|
|
|
2917
2903
|
}
|
|
2918
2904
|
//#endregion
|
|
2919
2905
|
export { KubbPluginSetupContext as $, KubbHookStartContext as A, Adapter as At, ParsedFile as B, KubbFilesProcessingEndContext as C, GenerationResult as Ct, KubbGenerationStartContext as D, UserReporter as Dt, KubbGenerationEndContext as E, ReporterName as Et, KubbSuccessContext as F, Generator$1 as G, createKubb as H, KubbWarnContext as I, KubbDriver as J, GeneratorContext as K, PossibleConfig as L, KubbInfoContext as M, AdapterSource as Mt, KubbLifecycleStartContext as N, createAdapter as Nt, KubbHookEndContext as O, createReporter as Ot, KubbPluginsEndContext as P, AsyncEventEmitter as Pt, KubbPluginEndContext as Q, UserConfig as R, KubbFileProcessingUpdate as S, createStorage as St, KubbFilesProcessingUpdateContext as T, ReporterContext as Tt, Parser as U, Kubb$1 as V, defineParser as W, Group as X, Exclude$1 as Y, Include as Z, InputPath as _, defineResolver as _t, DiagnosticLocation as a, Override as at, KubbDiagnosticContext as b, createRenderer as bt, PerformanceDiagnostic as c, definePlugin as ct, SerializedDiagnostic as d, ResolveBannerFile as dt, KubbPluginStartContext as et, UpdateDiagnostic as f, ResolveOptionsContext as ft, InputData as g, ResolverPathParams as gt, Config as h, ResolverFileParams as ht, DiagnosticKind as i, OutputOptions as it, KubbHooks as j, AdapterFactoryOptions as jt, KubbHookLineContext as k, logLevel as kt, ProblemCode as l, BannerMeta as lt, CLIOptions as m, ResolverContext as mt, DiagnosticByCode as n, Output as nt, DiagnosticSeverity as o, Plugin as ot, BuildOutput as p, Resolver as pt, defineGenerator as q, DiagnosticDoc as r, OutputMode as rt, Diagnostics as s, PluginFactoryOptions as st, Diagnostic as t, NormalizedPlugin as tt, ProblemDiagnostic as u, ResolveBannerContext as ut, KubbBuildEndContext as v, Renderer as vt, KubbFilesProcessingStartContext as w, Reporter as wt, KubbErrorContext as x, Storage as xt, KubbBuildStartContext as y, RendererFactory as yt, FileProcessorHooks as z };
|
|
2920
|
-
//# sourceMappingURL=diagnostics-
|
|
2906
|
+
//# sourceMappingURL=diagnostics-B-UZnFqP.d.ts.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_memoryStorage = require("./memoryStorage-
|
|
2
|
+
const require_memoryStorage = require("./memoryStorage-CUj1hrxa.cjs");
|
|
3
3
|
let node_crypto = require("node:crypto");
|
|
4
4
|
let node_util = require("node:util");
|
|
5
5
|
let node_fs_promises = require("node:fs/promises");
|
|
@@ -8,6 +8,9 @@ node_path = require_memoryStorage.__toESM(node_path, 1);
|
|
|
8
8
|
let _kubb_ast = require("@kubb/ast");
|
|
9
9
|
_kubb_ast = require_memoryStorage.__toESM(_kubb_ast, 1);
|
|
10
10
|
let node_async_hooks = require("node:async_hooks");
|
|
11
|
+
let _kubb_ast_factory = require("@kubb/ast/factory");
|
|
12
|
+
_kubb_ast_factory = require_memoryStorage.__toESM(_kubb_ast_factory, 1);
|
|
13
|
+
let _kubb_ast_utils = require("@kubb/ast/utils");
|
|
11
14
|
let node_process = require("node:process");
|
|
12
15
|
node_process = require_memoryStorage.__toESM(node_process, 1);
|
|
13
16
|
//#region ../../internals/utils/src/time.ts
|
|
@@ -573,9 +576,8 @@ var Url = class Url {
|
|
|
573
576
|
//#region src/createAdapter.ts
|
|
574
577
|
/**
|
|
575
578
|
* Defines a custom adapter that translates a spec format into Kubb's universal
|
|
576
|
-
* AST
|
|
577
|
-
*
|
|
578
|
-
* OpenAPI/Swagger documents.
|
|
579
|
+
* AST, for example GraphQL, gRPC, or AsyncAPI. The built-in `@kubb/adapter-oas`
|
|
580
|
+
* handles OpenAPI/Swagger documents.
|
|
579
581
|
*
|
|
580
582
|
* Adapters must return an `InputNode` from `parse`. That node is what every
|
|
581
583
|
* plugin in the build consumes.
|
|
@@ -592,7 +594,7 @@ var Url = class Url {
|
|
|
592
594
|
* document: null,
|
|
593
595
|
* async parse(_source) {
|
|
594
596
|
* // Convert `source` (path or inline data) into an InputNode.
|
|
595
|
-
* return ast.createInput()
|
|
597
|
+
* return ast.factory.createInput()
|
|
596
598
|
* },
|
|
597
599
|
* getImports: () => [],
|
|
598
600
|
* async validate() {
|
|
@@ -607,9 +609,9 @@ function createAdapter(build) {
|
|
|
607
609
|
//#endregion
|
|
608
610
|
//#region src/diagnostics.ts
|
|
609
611
|
/**
|
|
610
|
-
* Docs major, derived from the package version so the link tracks the published major.
|
|
612
|
+
* Docs major version, derived from the package version so the link tracks the published major.
|
|
611
613
|
*/
|
|
612
|
-
const docsMajor = "5.0.0-beta.
|
|
614
|
+
const docsMajor = "5.0.0-beta.59".split(".")[0] ?? "5";
|
|
613
615
|
/**
|
|
614
616
|
* Narrows a {@link Diagnostic} to the variant for `code`, or `null` when it does not match.
|
|
615
617
|
*
|
|
@@ -1056,8 +1058,7 @@ function normalizeOutput({ output, group, pluginName }) {
|
|
|
1056
1058
|
}
|
|
1057
1059
|
/**
|
|
1058
1060
|
* Wraps a plugin factory and returns a function that accepts user options and
|
|
1059
|
-
* yields a
|
|
1060
|
-
* `hooks` object (inspired by Astro integrations).
|
|
1061
|
+
* yields a typed `Plugin`. Lifecycle handlers go inside a single `hooks` object.
|
|
1061
1062
|
*
|
|
1062
1063
|
* Pass a `PluginFactoryOptions` type parameter to get a typed `ctx` inside
|
|
1063
1064
|
* `kubb:plugin:setup`. Plugin names should follow the `plugin-<feature>`
|
|
@@ -1209,8 +1210,8 @@ function defaultResolveOptions(node, { options, exclude = [], include, override
|
|
|
1209
1210
|
/**
|
|
1210
1211
|
* Default path resolver used by `defineResolver`.
|
|
1211
1212
|
*
|
|
1212
|
-
* - `mode: 'file'`
|
|
1213
|
-
* - `mode: 'directory'` (default)
|
|
1213
|
+
* - `mode: 'file'` resolves directly to `output.path` (the full file path, extension included).
|
|
1214
|
+
* - `mode: 'directory'` (default) resolves to `output.path/{baseName}`, or into a
|
|
1214
1215
|
* subdirectory when `group` and a `tag`/`path` value are provided.
|
|
1215
1216
|
*
|
|
1216
1217
|
* A custom `group.name` function overrides the default subdirectory naming.
|
|
@@ -1311,7 +1312,7 @@ function defaultResolveFile({ name, extname, tag, path: groupPath }, context) {
|
|
|
1311
1312
|
tag,
|
|
1312
1313
|
path: groupPath
|
|
1313
1314
|
}, context);
|
|
1314
|
-
return
|
|
1315
|
+
return _kubb_ast_factory.createFile({
|
|
1315
1316
|
path: filePath,
|
|
1316
1317
|
baseName: node_path.default.basename(filePath),
|
|
1317
1318
|
meta: { pluginName: this.pluginName },
|
|
@@ -1447,8 +1448,8 @@ function defaultResolveFooter(meta, { output, file }) {
|
|
|
1447
1448
|
* - `resolveFile` builds the full `FileNode`.
|
|
1448
1449
|
* - `resolveBanner` and `resolveFooter` produce the top and bottom of file text.
|
|
1449
1450
|
*
|
|
1450
|
-
* Methods in the returned object can call sibling resolver methods via `this
|
|
1451
|
-
*
|
|
1451
|
+
* Methods in the returned object can call sibling resolver methods via `this`.
|
|
1452
|
+
* A custom rule can delegate to a default, for example `this.default(name, 'type')`.
|
|
1452
1453
|
*
|
|
1453
1454
|
* @example Basic resolver with naming helpers
|
|
1454
1455
|
* ```ts
|
|
@@ -1560,7 +1561,8 @@ var KubbDriver = class {
|
|
|
1560
1561
|
config;
|
|
1561
1562
|
options;
|
|
1562
1563
|
/**
|
|
1563
|
-
* The streaming `InputNode<true>` produced by the adapter.
|
|
1564
|
+
* The streaming `InputNode<true>` produced by the adapter. Set after adapter setup.
|
|
1565
|
+
* Parse-only adapters are wrapped automatically.
|
|
1564
1566
|
*/
|
|
1565
1567
|
inputNode = null;
|
|
1566
1568
|
adapter = null;
|
|
@@ -1649,7 +1651,7 @@ var KubbDriver = class {
|
|
|
1649
1651
|
/**
|
|
1650
1652
|
* Parses the adapter source into `this.inputNode`. Idempotent, so repeated calls from
|
|
1651
1653
|
* `run` do not re-parse. Adapters with `stream()` are used directly.
|
|
1652
|
-
* Adapters with only `parse()` are wrapped via `
|
|
1654
|
+
* Adapters with only `parse()` are wrapped via `factory.createInput({ stream: true })` so the dispatch loop
|
|
1653
1655
|
* stays stream-only.
|
|
1654
1656
|
*/
|
|
1655
1657
|
async #parseInput() {
|
|
@@ -1661,7 +1663,12 @@ var KubbDriver = class {
|
|
|
1661
1663
|
return;
|
|
1662
1664
|
}
|
|
1663
1665
|
const parsed = await adapter.parse(source);
|
|
1664
|
-
this.inputNode =
|
|
1666
|
+
this.inputNode = _kubb_ast_factory.createInput({
|
|
1667
|
+
stream: true,
|
|
1668
|
+
schemas: arrayToAsyncIterable(parsed.schemas),
|
|
1669
|
+
operations: arrayToAsyncIterable(parsed.operations),
|
|
1670
|
+
meta: parsed.meta
|
|
1671
|
+
});
|
|
1665
1672
|
}
|
|
1666
1673
|
/**
|
|
1667
1674
|
* Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.
|
|
@@ -1705,7 +1712,7 @@ var KubbDriver = class {
|
|
|
1705
1712
|
}
|
|
1706
1713
|
},
|
|
1707
1714
|
injectFile: (userFileNode) => {
|
|
1708
|
-
this.fileManager.add(
|
|
1715
|
+
this.fileManager.add(_kubb_ast_factory.createFile(userFileNode));
|
|
1709
1716
|
}
|
|
1710
1717
|
};
|
|
1711
1718
|
return hooks["kubb:plugin:setup"](pluginCtx);
|
|
@@ -1932,7 +1939,7 @@ var KubbDriver = class {
|
|
|
1932
1939
|
*
|
|
1933
1940
|
* Plugins run sequentially so `kubb:plugin:end` fires as each plugin completes, instead
|
|
1934
1941
|
* of all at once after every plugin has marched through the parallel batches together.
|
|
1935
|
-
* That ordering is what drives the CLI's `Plugins N/M` counter
|
|
1942
|
+
* That ordering is what drives the CLI's `Plugins N/M` counter. Without it the bar would
|
|
1936
1943
|
* sit at the initial value until the very end of the run.
|
|
1937
1944
|
*
|
|
1938
1945
|
* When `entries` is empty or `this.inputNode` is `null`, every entry still gets a
|
|
@@ -1998,7 +2005,7 @@ var KubbDriver = class {
|
|
|
1998
2005
|
}) !== null) includedOpsByState.get(state)?.push(operation);
|
|
1999
2006
|
}
|
|
2000
2007
|
for (const state of pruningStates) {
|
|
2001
|
-
state.allowedSchemaNames = (0,
|
|
2008
|
+
state.allowedSchemaNames = (0, _kubb_ast_utils.collectUsedSchemaNames)(includedOpsByState.get(state) ?? [], schemasBuffer);
|
|
2002
2009
|
includedOpsByState.delete(state);
|
|
2003
2010
|
}
|
|
2004
2011
|
}
|
|
@@ -2672,7 +2679,7 @@ function renderSummary(lines, { title, status }) {
|
|
|
2672
2679
|
}
|
|
2673
2680
|
/**
|
|
2674
2681
|
* The default `cli` reporter. Renders the {@link Report} for each config as it finishes, independent
|
|
2675
|
-
* of the live logger view. Suppressed at `silent
|
|
2682
|
+
* of the live logger view. Suppressed at `silent`. The `verbose` level adds the per-plugin timings.
|
|
2676
2683
|
*/
|
|
2677
2684
|
const cliReporter = createReporter({
|
|
2678
2685
|
name: "cli",
|
|
@@ -2794,10 +2801,9 @@ const jsonReporter = createReporter({
|
|
|
2794
2801
|
* (JSX, a template string, a tree of any shape) into `FileNode`s that get
|
|
2795
2802
|
* written to disk.
|
|
2796
2803
|
*
|
|
2797
|
-
*
|
|
2798
|
-
* renderer
|
|
2799
|
-
*
|
|
2800
|
-
* field on `defineGenerator`.
|
|
2804
|
+
* A renderer can target output formats beyond JSX, for instance a Handlebars
|
|
2805
|
+
* renderer or one that writes binary files. Plugins and generators pick the
|
|
2806
|
+
* renderer to use via the `renderer` field on `defineGenerator`.
|
|
2801
2807
|
*
|
|
2802
2808
|
* @example A minimal renderer that wraps a custom runtime
|
|
2803
2809
|
* ```ts
|
|
@@ -2863,14 +2869,15 @@ function defineGenerator(generator) {
|
|
|
2863
2869
|
*
|
|
2864
2870
|
* @example
|
|
2865
2871
|
* ```ts
|
|
2866
|
-
* import { defineParser
|
|
2872
|
+
* import { defineParser } from '@kubb/core'
|
|
2873
|
+
* import { extractStringsFromNodes } from '@kubb/ast/utils'
|
|
2867
2874
|
*
|
|
2868
2875
|
* export const jsonParser = defineParser({
|
|
2869
2876
|
* name: 'json',
|
|
2870
2877
|
* extNames: ['.json'],
|
|
2871
2878
|
* parse(file) {
|
|
2872
2879
|
* return file.sources
|
|
2873
|
-
* .map((source) =>
|
|
2880
|
+
* .map((source) => extractStringsFromNodes(source.nodes ?? []))
|
|
2874
2881
|
* .join('\n')
|
|
2875
2882
|
* },
|
|
2876
2883
|
* print(...nodes) {
|