@kubb/core 5.0.0-alpha.30 → 5.0.0-alpha.31
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/{PluginDriver-D110FoJ-.d.ts → PluginDriver-D0dY_hpJ.d.ts} +400 -46
- package/dist/{chunk-ByKO4r7w.cjs → chunk-MlS0t1Af.cjs} +15 -0
- package/dist/chunk-O_arW02_.js +17 -0
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +3 -4
- package/dist/hooks.js +1 -1
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +98 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +19 -140
- package/dist/index.js +92 -48
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/Kubb.ts +5 -5
- package/src/KubbFile.ts +143 -0
- package/src/PluginDriver.ts +11 -10
- package/src/build.ts +70 -45
- package/src/constants.ts +2 -2
- package/src/{config.ts → defineConfig.ts} +2 -8
- package/src/defineGenerator.ts +5 -5
- package/src/defineParser.ts +57 -0
- package/src/defineResolver.ts +10 -13
- package/src/hooks/useMode.ts +3 -3
- package/src/index.ts +4 -3
- package/src/renderNode.tsx +4 -4
- package/src/types.ts +85 -35
- package/src/utils/TreeNode.ts +7 -7
- package/src/utils/getBarrelFiles.ts +6 -9
- package/src/utils/getConfigs.ts +1 -1
- package/src/utils/isInputPath.ts +8 -0
- package/dist/chunk--u3MIqq1.js +0 -8
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as __name, t as __exportAll } from "./chunk-O_arW02_.js";
|
|
2
2
|
import { Node, OperationNode, Printer, Printer as Printer$1, PrinterFactoryOptions, PrinterPartial, RootNode, SchemaNode, Visitor } from "@kubb/ast/types";
|
|
3
|
-
import { Fabric
|
|
3
|
+
import { Fabric } from "@kubb/fabric-core/types";
|
|
4
4
|
import { HttpMethod } from "@kubb/oas";
|
|
5
5
|
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
6
6
|
|
|
@@ -86,6 +86,138 @@ declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[
|
|
|
86
86
|
* ```
|
|
87
87
|
*/
|
|
88
88
|
type PossiblePromise<T> = Promise<T> | T;
|
|
89
|
+
declare namespace KubbFile_d_exports {
|
|
90
|
+
export { BaseName, Export, Extname, File, Import, Mode, Path, ResolvedFile, Source };
|
|
91
|
+
}
|
|
92
|
+
type ImportName = string | Array<string | {
|
|
93
|
+
propertyName: string;
|
|
94
|
+
name?: string;
|
|
95
|
+
}>;
|
|
96
|
+
type Import = {
|
|
97
|
+
/**
|
|
98
|
+
* Import name to be used.
|
|
99
|
+
* @example ["useState"]
|
|
100
|
+
* @example "React"
|
|
101
|
+
*/
|
|
102
|
+
name: ImportName;
|
|
103
|
+
/**
|
|
104
|
+
* Path for the import.
|
|
105
|
+
* @example '@kubb/core'
|
|
106
|
+
*/
|
|
107
|
+
path: string;
|
|
108
|
+
/**
|
|
109
|
+
* Add type-only import prefix.
|
|
110
|
+
* - `true` generates `import type { Type } from './path'`
|
|
111
|
+
* - `false` generates `import { Type } from './path'`
|
|
112
|
+
* @default false
|
|
113
|
+
*/
|
|
114
|
+
isTypeOnly?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Import entire module as namespace.
|
|
117
|
+
* - `true` generates `import * as Name from './path'`
|
|
118
|
+
* - `false` generates standard import
|
|
119
|
+
* @default false
|
|
120
|
+
*/
|
|
121
|
+
isNameSpace?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* When root is set it will compute a relative path with `getRelativePath(root, path)`.
|
|
124
|
+
*/
|
|
125
|
+
root?: string;
|
|
126
|
+
};
|
|
127
|
+
type Source = {
|
|
128
|
+
name?: string;
|
|
129
|
+
value?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Make this source a type-only export.
|
|
132
|
+
* @default false
|
|
133
|
+
*/
|
|
134
|
+
isTypeOnly?: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Include export keyword in source.
|
|
137
|
+
* @default false
|
|
138
|
+
*/
|
|
139
|
+
isExportable?: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Include in barrel file generation.
|
|
142
|
+
* @default false
|
|
143
|
+
*/
|
|
144
|
+
isIndexable?: boolean;
|
|
145
|
+
};
|
|
146
|
+
type Export = {
|
|
147
|
+
/**
|
|
148
|
+
* Export name to be used.
|
|
149
|
+
* @example ["useState"]
|
|
150
|
+
* @example "React"
|
|
151
|
+
*/
|
|
152
|
+
name?: string | Array<string>;
|
|
153
|
+
/**
|
|
154
|
+
* Path for the export.
|
|
155
|
+
* @example '@kubb/core'
|
|
156
|
+
*/
|
|
157
|
+
path: string;
|
|
158
|
+
/**
|
|
159
|
+
* Add type-only export prefix.
|
|
160
|
+
* - `true` generates `export type { Type } from './path'`
|
|
161
|
+
* - `false` generates `export { Type } from './path'`
|
|
162
|
+
* @default false
|
|
163
|
+
*/
|
|
164
|
+
isTypeOnly?: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Export as aliased namespace.
|
|
167
|
+
* - `true` generates `export * as aliasName from './path'`
|
|
168
|
+
* - `false` generates standard export
|
|
169
|
+
* @default false
|
|
170
|
+
*/
|
|
171
|
+
asAlias?: boolean;
|
|
172
|
+
};
|
|
173
|
+
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
|
|
174
|
+
type Mode = 'single' | 'split';
|
|
175
|
+
/**
|
|
176
|
+
* Name to be used to dynamically create the baseName (based on input.path).
|
|
177
|
+
* Based on UNIX basename.
|
|
178
|
+
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
179
|
+
*/
|
|
180
|
+
type BaseName = `${string}.${string}`;
|
|
181
|
+
/**
|
|
182
|
+
* Fully qualified path to a specified file.
|
|
183
|
+
*/
|
|
184
|
+
type Path = string;
|
|
185
|
+
type File<TMeta extends object = object> = {
|
|
186
|
+
/**
|
|
187
|
+
* Name used to create the path.
|
|
188
|
+
* Based on UNIX basename, `${name}${extname}`.
|
|
189
|
+
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
190
|
+
*/
|
|
191
|
+
baseName: BaseName;
|
|
192
|
+
/**
|
|
193
|
+
* Fully qualified path to the file.
|
|
194
|
+
*/
|
|
195
|
+
path: Path;
|
|
196
|
+
sources: Array<Source>;
|
|
197
|
+
imports: Array<Import>;
|
|
198
|
+
exports: Array<Export>;
|
|
199
|
+
/**
|
|
200
|
+
* Extra metadata used for barrel/index file generation.
|
|
201
|
+
*/
|
|
202
|
+
meta?: TMeta;
|
|
203
|
+
banner?: string;
|
|
204
|
+
footer?: string;
|
|
205
|
+
};
|
|
206
|
+
type ResolvedFile<TMeta extends object = object> = File<TMeta> & {
|
|
207
|
+
/**
|
|
208
|
+
* Unique identifier, generated from a hash.
|
|
209
|
+
* @default hash
|
|
210
|
+
*/
|
|
211
|
+
id: string;
|
|
212
|
+
/**
|
|
213
|
+
* First part of the `baseName`, derived from the file name.
|
|
214
|
+
* @link https://nodejs.org/api/path.html#pathformatpathobject
|
|
215
|
+
*/
|
|
216
|
+
name: string;
|
|
217
|
+
extname: Extname;
|
|
218
|
+
imports: Array<Import>;
|
|
219
|
+
exports: Array<Export>;
|
|
220
|
+
};
|
|
89
221
|
//#endregion
|
|
90
222
|
//#region src/constants.d.ts
|
|
91
223
|
/**
|
|
@@ -218,7 +350,7 @@ declare function createStorage<TOptions = Record<string, never>>(build: (options
|
|
|
218
350
|
* giving full access to `this.config`, `this.resolver`, `this.adapter`, `this.fabric`,
|
|
219
351
|
* `this.driver`, etc.
|
|
220
352
|
*
|
|
221
|
-
* Return a React element, an array of `
|
|
353
|
+
* Return a React element, an array of `KubbFile.File`, or `void` to handle file
|
|
222
354
|
* writing manually via `this.upsertFile`. Both React and core (non-React) generators
|
|
223
355
|
* use the same method signatures — the return type determines how output is handled.
|
|
224
356
|
*
|
|
@@ -243,17 +375,17 @@ type Generator<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
243
375
|
* `this` is the parent plugin's context with `adapter` and `rootNode` guaranteed present.
|
|
244
376
|
* `options` contains the per-node resolved options (after exclude/include/override).
|
|
245
377
|
*/
|
|
246
|
-
schema?: (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<
|
|
378
|
+
schema?: (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<File> | void>;
|
|
247
379
|
/**
|
|
248
380
|
* Called for each operation node in the AST walk.
|
|
249
381
|
* `this` is the parent plugin's context with `adapter` and `rootNode` guaranteed present.
|
|
250
382
|
*/
|
|
251
|
-
operation?: (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<
|
|
383
|
+
operation?: (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<File> | void>;
|
|
252
384
|
/**
|
|
253
385
|
* Called once after all operations have been walked.
|
|
254
386
|
* `this` is the parent plugin's context with `adapter` and `rootNode` guaranteed present.
|
|
255
387
|
*/
|
|
256
|
-
operations?: (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<
|
|
388
|
+
operations?: (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<File> | void>;
|
|
257
389
|
};
|
|
258
390
|
/**
|
|
259
391
|
* Defines a generator. Returns the object as-is with correct `this` typings.
|
|
@@ -285,6 +417,54 @@ declare function defineGenerator<TOptions extends PluginFactoryOptions = PluginF
|
|
|
285
417
|
*/
|
|
286
418
|
declare function mergeGenerators<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(generators: Array<Generator<TOptions>>): Generator<TOptions>;
|
|
287
419
|
//#endregion
|
|
420
|
+
//#region src/defineParser.d.ts
|
|
421
|
+
type PrintOptions = {
|
|
422
|
+
extname?: Extname;
|
|
423
|
+
};
|
|
424
|
+
type Parser<TMeta extends object = any> = {
|
|
425
|
+
name: string;
|
|
426
|
+
type: 'parser';
|
|
427
|
+
/**
|
|
428
|
+
* File extensions this parser handles.
|
|
429
|
+
* Use `undefined` to create a catch-all fallback parser.
|
|
430
|
+
*
|
|
431
|
+
* @example ['.ts', '.js']
|
|
432
|
+
*/
|
|
433
|
+
extNames: Array<Extname> | undefined;
|
|
434
|
+
/**
|
|
435
|
+
* @deprecated Will be removed once Fabric no longer requires it.
|
|
436
|
+
* @default () => {}
|
|
437
|
+
*/
|
|
438
|
+
install(...args: unknown[]): void | Promise<void>;
|
|
439
|
+
/**
|
|
440
|
+
* Convert a resolved file to a string.
|
|
441
|
+
*/
|
|
442
|
+
parse(file: ResolvedFile<TMeta>, options?: PrintOptions): Promise<string> | string;
|
|
443
|
+
};
|
|
444
|
+
type UserParser<TMeta extends object = any> = Omit<Parser<TMeta>, 'type' | 'install'> & {
|
|
445
|
+
install?(...args: unknown[]): void | Promise<void>;
|
|
446
|
+
};
|
|
447
|
+
/**
|
|
448
|
+
* Defines a parser with type safety.
|
|
449
|
+
*
|
|
450
|
+
* Use this function to create parsers that transform generated files to strings
|
|
451
|
+
* based on their extension.
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* ```ts
|
|
455
|
+
* import { defineParser } from '@kubb/core'
|
|
456
|
+
*
|
|
457
|
+
* export const jsonParser = defineParser({
|
|
458
|
+
* name: 'json',
|
|
459
|
+
* extNames: ['.json'],
|
|
460
|
+
* parse(file) {
|
|
461
|
+
* return file.sources.map((s) => s.value).join('\n')
|
|
462
|
+
* },
|
|
463
|
+
* })
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
declare function defineParser<TMeta extends object = any>(parser: UserParser<TMeta>): Parser<TMeta>;
|
|
467
|
+
//#endregion
|
|
288
468
|
//#region src/Kubb.d.ts
|
|
289
469
|
type DebugInfo = {
|
|
290
470
|
date: Date;
|
|
@@ -354,7 +534,7 @@ interface KubbEvents {
|
|
|
354
534
|
/**
|
|
355
535
|
* Emitted when code generation phase completes.
|
|
356
536
|
*/
|
|
357
|
-
'generation:end': [config: Config, files: Array<
|
|
537
|
+
'generation:end': [config: Config, files: Array<ResolvedFile>, sources: Map<Path, string>];
|
|
358
538
|
/**
|
|
359
539
|
* Emitted with a summary of the generation results.
|
|
360
540
|
* Contains summary lines, title, and success status.
|
|
@@ -441,7 +621,7 @@ interface KubbEvents {
|
|
|
441
621
|
* Emitted when file processing starts.
|
|
442
622
|
* Contains the list of files to be processed.
|
|
443
623
|
*/
|
|
444
|
-
'files:processing:start': [files: Array<
|
|
624
|
+
'files:processing:start': [files: Array<ResolvedFile>];
|
|
445
625
|
/**
|
|
446
626
|
* Emitted for each file being processed, providing progress updates.
|
|
447
627
|
* Contains processed count, total count, percentage, and file details.
|
|
@@ -466,7 +646,7 @@ interface KubbEvents {
|
|
|
466
646
|
/**
|
|
467
647
|
* The file being processed.
|
|
468
648
|
*/
|
|
469
|
-
file:
|
|
649
|
+
file: ResolvedFile;
|
|
470
650
|
/**
|
|
471
651
|
* Kubb configuration (not present in Fabric).
|
|
472
652
|
* Provides access to the current config during file processing.
|
|
@@ -477,7 +657,7 @@ interface KubbEvents {
|
|
|
477
657
|
* Emitted when file processing completes.
|
|
478
658
|
* Contains the list of processed files.
|
|
479
659
|
*/
|
|
480
|
-
'files:processing:end': [files: Array<
|
|
660
|
+
'files:processing:end': [files: Array<ResolvedFile>];
|
|
481
661
|
/**
|
|
482
662
|
* Emitted when a plugin starts executing.
|
|
483
663
|
*/
|
|
@@ -515,6 +695,132 @@ interface KubbEvents {
|
|
|
515
695
|
'plugins:hook:processing:end': [result: HookResult];
|
|
516
696
|
}
|
|
517
697
|
//#endregion
|
|
698
|
+
//#region src/defineConfig.d.ts
|
|
699
|
+
/**
|
|
700
|
+
* CLI options derived from command-line flags.
|
|
701
|
+
*/
|
|
702
|
+
type CLIOptions = {
|
|
703
|
+
/**
|
|
704
|
+
* Path to `kubb.config.js`.
|
|
705
|
+
*/
|
|
706
|
+
config?: string;
|
|
707
|
+
/**
|
|
708
|
+
* Enable watch mode for input files.
|
|
709
|
+
*/
|
|
710
|
+
watch?: boolean;
|
|
711
|
+
/**
|
|
712
|
+
* Logging verbosity for CLI usage.
|
|
713
|
+
*
|
|
714
|
+
* - `silent`: hide non-essential logs
|
|
715
|
+
* - `info`: show general logs (non-plugin-related)
|
|
716
|
+
* - `debug`: include detailed plugin lifecycle logs
|
|
717
|
+
* @default 'silent'
|
|
718
|
+
*/
|
|
719
|
+
logLevel?: 'silent' | 'info' | 'debug';
|
|
720
|
+
};
|
|
721
|
+
/**
|
|
722
|
+
* All accepted forms of a Kubb configuration.
|
|
723
|
+
*/
|
|
724
|
+
type ConfigInput = PossiblePromise<UserConfig | UserConfig[]> | ((cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>);
|
|
725
|
+
/**
|
|
726
|
+
* Helper for defining a Kubb configuration.
|
|
727
|
+
*
|
|
728
|
+
* Accepts either:
|
|
729
|
+
* - A config object or array of configs
|
|
730
|
+
* - A function returning the config(s), optionally async,
|
|
731
|
+
* receiving the CLI options as argument
|
|
732
|
+
*
|
|
733
|
+
* @example
|
|
734
|
+
* export default defineConfig(({ logLevel }) => ({
|
|
735
|
+
* root: 'src',
|
|
736
|
+
* plugins: [myPlugin()],
|
|
737
|
+
* }))
|
|
738
|
+
* @deprecated as of Kubb v5, @kubb/core will not expose `defineConfig` anymore. use the `kubb` package instead
|
|
739
|
+
*/
|
|
740
|
+
declare function defineConfig(config: (cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>): typeof config;
|
|
741
|
+
declare function defineConfig(config: PossiblePromise<UserConfig | UserConfig[]>): typeof config;
|
|
742
|
+
//#endregion
|
|
743
|
+
//#region src/utils/FunctionParams.d.ts
|
|
744
|
+
type FunctionParamsASTWithoutType = {
|
|
745
|
+
name?: string;
|
|
746
|
+
type?: string;
|
|
747
|
+
/**
|
|
748
|
+
* @default true
|
|
749
|
+
*/
|
|
750
|
+
required?: boolean;
|
|
751
|
+
/**
|
|
752
|
+
* @default true
|
|
753
|
+
*/
|
|
754
|
+
enabled?: boolean;
|
|
755
|
+
default?: string;
|
|
756
|
+
};
|
|
757
|
+
type FunctionParamsASTWithType = {
|
|
758
|
+
name?: never;
|
|
759
|
+
type: string;
|
|
760
|
+
/**
|
|
761
|
+
* @default true
|
|
762
|
+
*/
|
|
763
|
+
required?: boolean;
|
|
764
|
+
/**
|
|
765
|
+
* @default true
|
|
766
|
+
*/
|
|
767
|
+
enabled?: boolean;
|
|
768
|
+
default?: string;
|
|
769
|
+
};
|
|
770
|
+
/**
|
|
771
|
+
* @deprecated use ast package instead
|
|
772
|
+
*/
|
|
773
|
+
type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType;
|
|
774
|
+
/**
|
|
775
|
+
* @deprecated use ast package instead
|
|
776
|
+
*/
|
|
777
|
+
declare class FunctionParams {
|
|
778
|
+
#private;
|
|
779
|
+
get items(): FunctionParamsAST[];
|
|
780
|
+
add(item: FunctionParamsAST | Array<FunctionParamsAST | FunctionParamsAST[] | undefined> | undefined): FunctionParams;
|
|
781
|
+
static toObject(items: FunctionParamsAST[]): FunctionParamsAST;
|
|
782
|
+
toObject(): FunctionParamsAST;
|
|
783
|
+
static toString(items: (FunctionParamsAST | FunctionParamsAST[])[]): string;
|
|
784
|
+
toString(): string;
|
|
785
|
+
}
|
|
786
|
+
//#endregion
|
|
787
|
+
//#region src/utils/getBarrelFiles.d.ts
|
|
788
|
+
type FileMetaBase = {
|
|
789
|
+
pluginName?: string;
|
|
790
|
+
};
|
|
791
|
+
type AddIndexesProps = {
|
|
792
|
+
type: BarrelType | false | undefined;
|
|
793
|
+
/**
|
|
794
|
+
* Root based on root and output.path specified in the config
|
|
795
|
+
*/
|
|
796
|
+
root: string;
|
|
797
|
+
/**
|
|
798
|
+
* Output for plugin
|
|
799
|
+
*/
|
|
800
|
+
output: {
|
|
801
|
+
path: string;
|
|
802
|
+
};
|
|
803
|
+
group?: {
|
|
804
|
+
output: string;
|
|
805
|
+
exportAs: string;
|
|
806
|
+
};
|
|
807
|
+
meta?: FileMetaBase;
|
|
808
|
+
};
|
|
809
|
+
/**
|
|
810
|
+
* Generates `index.ts` barrel files for all directories under `root/output.path`.
|
|
811
|
+
*
|
|
812
|
+
* - Returns an empty array when `type` is falsy or `'propagate'`.
|
|
813
|
+
* - Skips generation when the output path itself ends with `index` (already a barrel).
|
|
814
|
+
* - When `type` is `'all'`, strips named exports so every re-export becomes a wildcard (`export * from`).
|
|
815
|
+
* - Attaches `meta` to each barrel file for downstream plugin identification.
|
|
816
|
+
*/
|
|
817
|
+
declare function getBarrelFiles(files: Array<ResolvedFile>, {
|
|
818
|
+
type,
|
|
819
|
+
meta,
|
|
820
|
+
root,
|
|
821
|
+
output
|
|
822
|
+
}: AddIndexesProps): Promise<Array<File>>;
|
|
823
|
+
//#endregion
|
|
518
824
|
//#region src/types.d.ts
|
|
519
825
|
declare global {
|
|
520
826
|
namespace Kubb {
|
|
@@ -548,12 +854,43 @@ declare global {
|
|
|
548
854
|
* ...
|
|
549
855
|
* })
|
|
550
856
|
*/
|
|
551
|
-
type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins'> & {
|
|
857
|
+
type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter'> & {
|
|
552
858
|
/**
|
|
553
859
|
* The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
|
|
554
860
|
* @default process.cwd()
|
|
555
861
|
*/
|
|
556
862
|
root?: string;
|
|
863
|
+
/**
|
|
864
|
+
* An array of parsers used to convert generated files to strings.
|
|
865
|
+
* Each parser handles specific file extensions (e.g. `.ts`, `.tsx`).
|
|
866
|
+
*
|
|
867
|
+
* A catch-all fallback parser is always appended last for any unhandled extension.
|
|
868
|
+
*
|
|
869
|
+
* When omitted, `parserTs` from `@kubb/parser-ts` is used automatically as the
|
|
870
|
+
* default (requires `@kubb/parser-ts` to be installed as an optional dependency).
|
|
871
|
+
* @default [parserTs] — from `@kubb/parser-ts`
|
|
872
|
+
* @example
|
|
873
|
+
* ```ts
|
|
874
|
+
* import { parserTs, tsxParser } from '@kubb/parser-ts'
|
|
875
|
+
* export default defineConfig({
|
|
876
|
+
* parsers: [parserTs, tsxParser],
|
|
877
|
+
* })
|
|
878
|
+
* ```
|
|
879
|
+
*/
|
|
880
|
+
parsers?: Array<Parser>;
|
|
881
|
+
/**
|
|
882
|
+
* Adapter that converts the input file into a `@kubb/ast` `RootNode` — the universal
|
|
883
|
+
* intermediate representation consumed by all Kubb plugins.
|
|
884
|
+
*
|
|
885
|
+
* When omitted, `adapterOas()` from `@kubb/adapter-oas` is used automatically as the
|
|
886
|
+
* default (requires `@kubb/adapter-oas` to be installed as an optional dependency).
|
|
887
|
+
*
|
|
888
|
+
* - Use `@kubb/adapter-oas` for OpenAPI / Swagger (default).
|
|
889
|
+
* - Use `@kubb/adapter-drizzle` or `@kubb/adapter-asyncapi` for other formats.
|
|
890
|
+
*
|
|
891
|
+
* @default adapterOas() — from `@kubb/adapter-oas`
|
|
892
|
+
*/
|
|
893
|
+
adapter?: Adapter;
|
|
557
894
|
/**
|
|
558
895
|
* An array of Kubb plugins used for generation. Each plugin may have additional configurable options (defined within the plugin itself). If a plugin relies on another plugin, an error will occur if the required dependency is missing. Refer to “pre” for more details.
|
|
559
896
|
*/
|
|
@@ -571,7 +908,7 @@ type InputData = {
|
|
|
571
908
|
*/
|
|
572
909
|
data: string | unknown;
|
|
573
910
|
};
|
|
574
|
-
type Input = InputPath | InputData
|
|
911
|
+
type Input = InputPath | InputData;
|
|
575
912
|
/**
|
|
576
913
|
* The raw source passed to an adapter's `parse` function.
|
|
577
914
|
* Mirrors the shape of `Config['input']` with paths already resolved to absolute.
|
|
@@ -639,7 +976,7 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
|
639
976
|
*/
|
|
640
977
|
parse: (source: AdapterSource) => PossiblePromise<RootNode>;
|
|
641
978
|
/**
|
|
642
|
-
* Extracts `
|
|
979
|
+
* Extracts `KubbFile.Import` entries needed by a `SchemaNode` tree.
|
|
643
980
|
* Populated after the first `parse()` call. Returns an empty array before that.
|
|
644
981
|
*
|
|
645
982
|
* The `resolve` callback receives the collision-corrected schema name and must
|
|
@@ -648,7 +985,7 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
|
648
985
|
getImports: (node: SchemaNode, resolve: (schemaName: string) => {
|
|
649
986
|
name: string;
|
|
650
987
|
path: string;
|
|
651
|
-
}) => Array<
|
|
988
|
+
}) => Array<Import>;
|
|
652
989
|
};
|
|
653
990
|
type BarrelType = 'all' | 'named' | 'propagate';
|
|
654
991
|
type DevtoolsOptions = {
|
|
@@ -672,24 +1009,41 @@ type Config<TInput = Input> = {
|
|
|
672
1009
|
* @default process.cwd()
|
|
673
1010
|
*/
|
|
674
1011
|
root: string;
|
|
1012
|
+
/**
|
|
1013
|
+
* An array of parsers used to convert generated files to strings.
|
|
1014
|
+
* Each parser handles specific file extensions (e.g. `.ts`, `.tsx`).
|
|
1015
|
+
*
|
|
1016
|
+
* A catch-all fallback parser is always appended last for any unhandled extension.
|
|
1017
|
+
*
|
|
1018
|
+
* When omitted, `parserTs` from `@kubb/parser-ts` is used automatically as the
|
|
1019
|
+
* default (requires `@kubb/parser-ts` to be installed as an optional dependency).
|
|
1020
|
+
* @default [parserTs] — from `@kubb/parser-ts`
|
|
1021
|
+
* @example
|
|
1022
|
+
* ```ts
|
|
1023
|
+
* import { parserTs, tsxParser } from '@kubb/parser-ts'
|
|
1024
|
+
* export default defineConfig({
|
|
1025
|
+
* parsers: [parserTs, tsxParser],
|
|
1026
|
+
* })
|
|
1027
|
+
* ```
|
|
1028
|
+
*/
|
|
1029
|
+
parsers: Array<Parser>;
|
|
675
1030
|
/**
|
|
676
1031
|
* Adapter that converts the input file into a `@kubb/ast` `RootNode` — the universal
|
|
677
1032
|
* intermediate representation consumed by all Kubb plugins.
|
|
678
1033
|
*
|
|
679
|
-
* -
|
|
680
|
-
* - Use `@kubb/adapter-oas` for explicit OpenAPI configuration (validate, contentType, …).
|
|
1034
|
+
* - Use `@kubb/adapter-oas` for OpenAPI / Swagger.
|
|
681
1035
|
* - Use `@kubb/adapter-drizzle` or `@kubb/adapter-asyncapi` for other formats.
|
|
682
1036
|
*
|
|
683
1037
|
* @example
|
|
684
1038
|
* ```ts
|
|
685
|
-
* import {
|
|
1039
|
+
* import { adapterOas } from '@kubb/adapter-oas'
|
|
686
1040
|
* export default defineConfig({
|
|
687
|
-
* adapter:
|
|
688
|
-
* input: { path: './
|
|
1041
|
+
* adapter: adapterOas(),
|
|
1042
|
+
* input: { path: './petStore.yaml' },
|
|
689
1043
|
* })
|
|
690
1044
|
* ```
|
|
691
1045
|
*/
|
|
692
|
-
adapter
|
|
1046
|
+
adapter: Adapter;
|
|
693
1047
|
/**
|
|
694
1048
|
* You can use either `input.path` or `input.data`, depending on your specific needs.
|
|
695
1049
|
*/
|
|
@@ -747,7 +1101,7 @@ type Config<TInput = Input> = {
|
|
|
747
1101
|
* Overrides the extension for generated imports and exports. By default, each plugin adds an extension.
|
|
748
1102
|
* @default { '.ts': '.ts'}
|
|
749
1103
|
*/
|
|
750
|
-
extension?: Record<
|
|
1104
|
+
extension?: Record<Extname, Extname | ''>;
|
|
751
1105
|
/**
|
|
752
1106
|
* Configures how `index.ts` files are created, including disabling barrel file generation. Each plugin has its own `barrelType` option; this setting controls the root barrel file (e.g., `src/gen/index.ts`).
|
|
753
1107
|
* @default 'named'
|
|
@@ -839,8 +1193,8 @@ type Resolver = {
|
|
|
839
1193
|
pluginName: Plugin['name'];
|
|
840
1194
|
default(name: ResolveNameParams['name'], type?: ResolveNameParams['type']): string;
|
|
841
1195
|
resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null;
|
|
842
|
-
resolvePath(params: ResolverPathParams, context: ResolverContext):
|
|
843
|
-
resolveFile(params: ResolverFileParams, context: ResolverContext):
|
|
1196
|
+
resolvePath(params: ResolverPathParams, context: ResolverContext): Path;
|
|
1197
|
+
resolveFile(params: ResolverFileParams, context: ResolverContext): File;
|
|
844
1198
|
resolveBanner(node: RootNode | null, context: ResolveBannerContext): string | undefined;
|
|
845
1199
|
resolveFooter(node: RootNode | null, context: ResolveBannerContext): string | undefined;
|
|
846
1200
|
};
|
|
@@ -959,15 +1313,15 @@ type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<string, object, object,
|
|
|
959
1313
|
/**
|
|
960
1314
|
* Handler for a single schema node. Used by the `schema` hook on a plugin.
|
|
961
1315
|
*/
|
|
962
|
-
type SchemaHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<
|
|
1316
|
+
type SchemaHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<File> | void>;
|
|
963
1317
|
/**
|
|
964
1318
|
* Handler for a single operation node. Used by the `operation` hook on a plugin.
|
|
965
1319
|
*/
|
|
966
|
-
type OperationHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<
|
|
1320
|
+
type OperationHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<File> | void>;
|
|
967
1321
|
/**
|
|
968
1322
|
* Handler for all collected operation nodes. Used by the `operations` hook on a plugin.
|
|
969
1323
|
*/
|
|
970
|
-
type OperationsHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<
|
|
1324
|
+
type OperationsHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<File> | void>;
|
|
971
1325
|
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
972
1326
|
/**
|
|
973
1327
|
* Unique name used for the plugin
|
|
@@ -1021,7 +1375,7 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
1021
1375
|
buildEnd: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1022
1376
|
/**
|
|
1023
1377
|
* Called for each schema node during the AST walk.
|
|
1024
|
-
* Return a React element, an array of `
|
|
1378
|
+
* Return a React element, an array of `KubbFile.File`, or `void` for manual handling.
|
|
1025
1379
|
* Nodes matching `exclude`/`include` filters are skipped automatically.
|
|
1026
1380
|
*
|
|
1027
1381
|
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
@@ -1029,7 +1383,7 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
1029
1383
|
schema?: SchemaHook<TOptions>;
|
|
1030
1384
|
/**
|
|
1031
1385
|
* Called for each operation node during the AST walk.
|
|
1032
|
-
* Return a React element, an array of `
|
|
1386
|
+
* Return a React element, an array of `KubbFile.File`, or `void` for manual handling.
|
|
1033
1387
|
*
|
|
1034
1388
|
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
1035
1389
|
*/
|
|
@@ -1062,7 +1416,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
1062
1416
|
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1063
1417
|
/**
|
|
1064
1418
|
* Called for each schema node during the AST walk.
|
|
1065
|
-
* Return a React element (`<File>...</File>`), an array of `
|
|
1419
|
+
* Return a React element (`<File>...</File>`), an array of `KubbFile.File` objects,
|
|
1066
1420
|
* or `void` to handle file writing manually via `this.upsertFile`.
|
|
1067
1421
|
* Nodes matching `exclude` / `include` filters are skipped automatically.
|
|
1068
1422
|
*
|
|
@@ -1071,7 +1425,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
1071
1425
|
schema?: SchemaHook<TOptions>;
|
|
1072
1426
|
/**
|
|
1073
1427
|
* Called for each operation node during the AST walk.
|
|
1074
|
-
* Return a React element (`<File>...</File>`), an array of `
|
|
1428
|
+
* Return a React element (`<File>...</File>`), an array of `KubbFile.File` objects,
|
|
1075
1429
|
* or `void` to handle file writing manually via `this.upsertFile`.
|
|
1076
1430
|
*
|
|
1077
1431
|
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
@@ -1091,7 +1445,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
1091
1445
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
1092
1446
|
* @deprecated this will be replaced by resolvers
|
|
1093
1447
|
*/
|
|
1094
|
-
resolvePath?: (this: PluginContext<TOptions>, baseName:
|
|
1448
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: BaseName, mode?: Mode, options?: TOptions['resolvePathOptions']) => Path;
|
|
1095
1449
|
/**
|
|
1096
1450
|
* Resolve to a name based on a string.
|
|
1097
1451
|
* Useful when converting to PascalCase or camelCase.
|
|
@@ -1105,8 +1459,8 @@ type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
|
1105
1459
|
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
1106
1460
|
type ResolvePathParams<TOptions = object> = {
|
|
1107
1461
|
pluginName?: string;
|
|
1108
|
-
baseName:
|
|
1109
|
-
mode?:
|
|
1462
|
+
baseName: BaseName;
|
|
1463
|
+
mode?: Mode;
|
|
1110
1464
|
/**
|
|
1111
1465
|
* Options to be passed to 'resolvePath' 3th parameter
|
|
1112
1466
|
*/
|
|
@@ -1140,7 +1494,7 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1140
1494
|
*/
|
|
1141
1495
|
getMode: (output: {
|
|
1142
1496
|
path: string;
|
|
1143
|
-
}) =>
|
|
1497
|
+
}) => Mode;
|
|
1144
1498
|
driver: PluginDriver;
|
|
1145
1499
|
/**
|
|
1146
1500
|
* Get a plugin by name. Returns the plugin typed via `Kubb.PluginRegistry` when
|
|
@@ -1157,11 +1511,11 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1157
1511
|
/**
|
|
1158
1512
|
* Only add when the file does not exist yet
|
|
1159
1513
|
*/
|
|
1160
|
-
addFile: (...file: Array<
|
|
1514
|
+
addFile: (...file: Array<File>) => Promise<void>;
|
|
1161
1515
|
/**
|
|
1162
1516
|
* merging multiple sources into the same output file
|
|
1163
1517
|
*/
|
|
1164
|
-
upsertFile: (...file: Array<
|
|
1518
|
+
upsertFile: (...file: Array<File>) => Promise<void>;
|
|
1165
1519
|
/**
|
|
1166
1520
|
* @deprecated use this.warn, this.error, this.info instead
|
|
1167
1521
|
*/
|
|
@@ -1394,8 +1748,8 @@ type ResolvePathOptions = {
|
|
|
1394
1748
|
* ```
|
|
1395
1749
|
*/
|
|
1396
1750
|
type ResolverPathParams = {
|
|
1397
|
-
baseName:
|
|
1398
|
-
pathMode?:
|
|
1751
|
+
baseName: BaseName;
|
|
1752
|
+
pathMode?: Mode;
|
|
1399
1753
|
/**
|
|
1400
1754
|
* Tag value used when `group.type === 'tag'`.
|
|
1401
1755
|
*/
|
|
@@ -1446,7 +1800,7 @@ type ResolverContext = {
|
|
|
1446
1800
|
*/
|
|
1447
1801
|
type ResolverFileParams = {
|
|
1448
1802
|
name: string;
|
|
1449
|
-
extname:
|
|
1803
|
+
extname: Extname;
|
|
1450
1804
|
/**
|
|
1451
1805
|
* Tag value used when `group.type === 'tag'`.
|
|
1452
1806
|
*/
|
|
@@ -1502,8 +1856,8 @@ type Options = {
|
|
|
1502
1856
|
*/
|
|
1503
1857
|
type GetFileOptions<TOptions = object> = {
|
|
1504
1858
|
name: string;
|
|
1505
|
-
mode?:
|
|
1506
|
-
extname:
|
|
1859
|
+
mode?: Mode;
|
|
1860
|
+
extname: Extname;
|
|
1507
1861
|
pluginName: string;
|
|
1508
1862
|
options?: TOptions;
|
|
1509
1863
|
};
|
|
@@ -1516,7 +1870,7 @@ type GetFileOptions<TOptions = object> = {
|
|
|
1516
1870
|
* getMode('src/gen/types') // 'split'
|
|
1517
1871
|
* ```
|
|
1518
1872
|
*/
|
|
1519
|
-
declare function getMode(fileOrFolder: string | undefined | null):
|
|
1873
|
+
declare function getMode(fileOrFolder: string | undefined | null): Mode;
|
|
1520
1874
|
declare class PluginDriver {
|
|
1521
1875
|
#private;
|
|
1522
1876
|
readonly config: Config;
|
|
@@ -1540,13 +1894,13 @@ declare class PluginDriver {
|
|
|
1540
1894
|
extname,
|
|
1541
1895
|
pluginName,
|
|
1542
1896
|
options
|
|
1543
|
-
}: GetFileOptions<TOptions>):
|
|
1897
|
+
}: GetFileOptions<TOptions>): File<{
|
|
1544
1898
|
pluginName: string;
|
|
1545
1899
|
}>;
|
|
1546
1900
|
/**
|
|
1547
1901
|
* @deprecated use resolvers context instead
|
|
1548
1902
|
*/
|
|
1549
|
-
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) =>
|
|
1903
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => Path;
|
|
1550
1904
|
/**
|
|
1551
1905
|
* @deprecated use resolvers context instead
|
|
1552
1906
|
*/
|
|
@@ -1628,5 +1982,5 @@ declare class PluginDriver {
|
|
|
1628
1982
|
requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>;
|
|
1629
1983
|
}
|
|
1630
1984
|
//#endregion
|
|
1631
|
-
export {
|
|
1632
|
-
//# sourceMappingURL=PluginDriver-
|
|
1985
|
+
export { FunctionParams as $, Preset as A, Resolver as B, Plugin as C, PluginLifecycleHooks as D, PluginLifecycle as E, ResolveBannerContext as F, UserConfig as G, ResolverFileParams as H, ResolveNameParams as I, UserPlugin as J, UserGroup as K, ResolveOptionsContext as L, Printer$1 as M, PrinterFactoryOptions as N, PluginParameter as O, PrinterPartial as P, getBarrelFiles as Q, ResolvePathOptions as R, Override as S, PluginFactoryOptions as T, ResolverPathParams as U, ResolverContext as V, SchemaHook as W, UserResolver as X, UserPluginWithLifeCycle as Y, FileMetaBase as Z, LoggerContext as _, KubbFile_d_exports as _t, AdapterSource as a, Parser as at, OperationsHook as b, ResolvedFile as bt, Config as c, Generator as ct, GeneratorContext as d, Storage as dt, FunctionParamsAST as et, Group as f, createStorage as ft, Logger as g, File as gt, InputPath as h, logLevel as ht, AdapterFactoryOptions as i, KubbEvents as it, Presets as j, PluginWithLifeCycle as k, DevtoolsOptions as l, defineGenerator as lt, InputData as m, linters as mt, getMode as n, ConfigInput as nt, BarrelType as o, UserParser as ot, Include as p, formatters as pt, UserLogger as q, Adapter as r, defineConfig as rt, CompatibilityPreset as s, defineParser as st, PluginDriver as t, CLIOptions as tt, Exclude as u, mergeGenerators as ut, LoggerOptions as v, Mode as vt, PluginContext as w, Output as x, AsyncEventEmitter as xt, OperationHook as y, Path as yt, ResolvePathParams as z };
|
|
1986
|
+
//# sourceMappingURL=PluginDriver-D0dY_hpJ.d.ts.map
|