@kubb/core 5.0.0-alpha.31 → 5.0.0-alpha.33
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-D0dY_hpJ.d.ts → PluginDriver-BBi_41VF.d.ts} +113 -224
- package/dist/chunk--u3MIqq1.js +8 -0
- package/dist/{chunk-MlS0t1Af.cjs → chunk-ByKO4r7w.cjs} +0 -15
- package/dist/hooks.cjs +5 -8
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +3 -3
- package/dist/hooks.js +5 -8
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +460 -279
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +73 -24
- package/dist/index.js +461 -276
- package/dist/index.js.map +1 -1
- package/package.json +5 -7
- package/src/FileManager.ts +131 -0
- package/src/FileProcessor.ts +84 -0
- package/src/Kubb.ts +6 -6
- package/src/PluginDriver.ts +29 -24
- package/src/build.ts +89 -108
- package/src/constants.ts +7 -2
- package/src/defineGenerator.ts +13 -18
- package/src/defineParser.ts +8 -21
- package/src/defineResolver.ts +18 -19
- package/src/devtools.ts +14 -14
- package/src/hooks/useDriver.ts +2 -4
- package/src/hooks/useMode.ts +3 -6
- package/src/hooks/usePlugin.ts +2 -4
- package/src/index.ts +3 -2
- package/src/renderNode.tsx +15 -12
- package/src/types.ts +47 -50
- package/src/utils/TreeNode.ts +7 -7
- package/src/utils/getBarrelFiles.ts +28 -25
- package/src/utils/getFunctionParams.ts +247 -0
- package/dist/chunk-O_arW02_.js +0 -17
- package/src/KubbFile.ts +0 -143
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Node, OperationNode, Printer, Printer as Printer$1, PrinterFactoryOptions, PrinterPartial,
|
|
3
|
-
import { Fabric } from "@kubb/fabric-core/types";
|
|
1
|
+
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
+
import { FileNode, ImportNode, InputNode, Node, OperationNode, Printer, Printer as Printer$1, PrinterFactoryOptions, PrinterPartial, SchemaNode, Visitor } from "@kubb/ast/types";
|
|
4
3
|
import { HttpMethod } from "@kubb/oas";
|
|
5
|
-
import {
|
|
4
|
+
import { KubbReactNode } from "@kubb/renderer-jsx/types";
|
|
6
5
|
|
|
7
6
|
//#region ../../internals/utils/src/asyncEventEmitter.d.ts
|
|
8
7
|
/**
|
|
@@ -86,138 +85,44 @@ declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[
|
|
|
86
85
|
* ```
|
|
87
86
|
*/
|
|
88
87
|
type PossiblePromise<T> = Promise<T> | T;
|
|
89
|
-
|
|
90
|
-
|
|
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}`;
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/FileManager.d.ts
|
|
181
90
|
/**
|
|
182
|
-
*
|
|
91
|
+
* In-memory file store for generated files.
|
|
92
|
+
*
|
|
93
|
+
* Files with the same `path` are merged — sources, imports, and exports are concatenated.
|
|
94
|
+
* The `files` getter returns all stored files sorted by path length (shortest first).
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { FileManager } from '@kubb/core'
|
|
99
|
+
*
|
|
100
|
+
* const manager = new FileManager()
|
|
101
|
+
* manager.upsert(myFile)
|
|
102
|
+
* console.log(manager.files) // all stored files
|
|
103
|
+
* ```
|
|
183
104
|
*/
|
|
184
|
-
|
|
185
|
-
|
|
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>;
|
|
105
|
+
declare class FileManager {
|
|
106
|
+
#private;
|
|
199
107
|
/**
|
|
200
|
-
*
|
|
108
|
+
* Adds one or more files. Files with the same path are merged — sources, imports,
|
|
109
|
+
* and exports from all calls with the same path are concatenated together.
|
|
201
110
|
*/
|
|
202
|
-
|
|
203
|
-
banner?: string;
|
|
204
|
-
footer?: string;
|
|
205
|
-
};
|
|
206
|
-
type ResolvedFile<TMeta extends object = object> = File<TMeta> & {
|
|
111
|
+
add(...files: Array<FileNode>): Array<FileNode>;
|
|
207
112
|
/**
|
|
208
|
-
*
|
|
209
|
-
*
|
|
113
|
+
* Adds or merges one or more files.
|
|
114
|
+
* If a file with the same path already exists, its sources/imports/exports are merged together.
|
|
210
115
|
*/
|
|
211
|
-
|
|
116
|
+
upsert(...files: Array<FileNode>): Array<FileNode>;
|
|
117
|
+
getByPath(path: string): FileNode | null;
|
|
118
|
+
deleteByPath(path: string): void;
|
|
119
|
+
clear(): void;
|
|
212
120
|
/**
|
|
213
|
-
*
|
|
214
|
-
*
|
|
121
|
+
* All stored files, sorted by path length (shorter paths first).
|
|
122
|
+
* Barrel/index files (e.g. index.ts) are sorted last within each length bucket.
|
|
215
123
|
*/
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
imports: Array<Import>;
|
|
219
|
-
exports: Array<Export>;
|
|
220
|
-
};
|
|
124
|
+
get files(): Array<FileNode>;
|
|
125
|
+
}
|
|
221
126
|
//#endregion
|
|
222
127
|
//#region src/constants.d.ts
|
|
223
128
|
/**
|
|
@@ -347,10 +252,10 @@ declare function createStorage<TOptions = Record<string, never>>(build: (options
|
|
|
347
252
|
/**
|
|
348
253
|
* A generator is a named object with optional `schema`, `operation`, and `operations`
|
|
349
254
|
* methods. Each method is called with `this = PluginContext` of the parent plugin,
|
|
350
|
-
* giving full access to `this.config`, `this.resolver`, `this.adapter`,
|
|
255
|
+
* giving full access to `this.config`, `this.resolver`, `this.adapter`,
|
|
351
256
|
* `this.driver`, etc.
|
|
352
257
|
*
|
|
353
|
-
* Return a React element, an array of `
|
|
258
|
+
* Return a React element, an array of `FileNode`, or `void` to handle file
|
|
354
259
|
* writing manually via `this.upsertFile`. Both React and core (non-React) generators
|
|
355
260
|
* use the same method signatures — the return type determines how output is handled.
|
|
356
261
|
*
|
|
@@ -372,20 +277,20 @@ type Generator<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
372
277
|
/** Used in diagnostic messages and debug output. */name: string;
|
|
373
278
|
/**
|
|
374
279
|
* Called for each schema node in the AST walk.
|
|
375
|
-
* `this` is the parent plugin's context with `adapter` and `
|
|
280
|
+
* `this` is the parent plugin's context with `adapter` and `inputNode` guaranteed present.
|
|
376
281
|
* `options` contains the per-node resolved options (after exclude/include/override).
|
|
377
282
|
*/
|
|
378
|
-
schema?: (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<
|
|
283
|
+
schema?: (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<KubbReactNode | Array<FileNode> | void>;
|
|
379
284
|
/**
|
|
380
285
|
* Called for each operation node in the AST walk.
|
|
381
|
-
* `this` is the parent plugin's context with `adapter` and `
|
|
286
|
+
* `this` is the parent plugin's context with `adapter` and `inputNode` guaranteed present.
|
|
382
287
|
*/
|
|
383
|
-
operation?: (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<
|
|
288
|
+
operation?: (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<KubbReactNode | Array<FileNode> | void>;
|
|
384
289
|
/**
|
|
385
290
|
* Called once after all operations have been walked.
|
|
386
|
-
* `this` is the parent plugin's context with `adapter` and `
|
|
291
|
+
* `this` is the parent plugin's context with `adapter` and `inputNode` guaranteed present.
|
|
387
292
|
*/
|
|
388
|
-
operations?: (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<
|
|
293
|
+
operations?: (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<KubbReactNode | Array<FileNode> | void>;
|
|
389
294
|
};
|
|
390
295
|
/**
|
|
391
296
|
* Defines a generator. Returns the object as-is with correct `this` typings.
|
|
@@ -419,30 +324,21 @@ declare function mergeGenerators<TOptions extends PluginFactoryOptions = PluginF
|
|
|
419
324
|
//#endregion
|
|
420
325
|
//#region src/defineParser.d.ts
|
|
421
326
|
type PrintOptions = {
|
|
422
|
-
extname?:
|
|
327
|
+
extname?: FileNode['extname'];
|
|
423
328
|
};
|
|
424
329
|
type Parser<TMeta extends object = any> = {
|
|
425
330
|
name: string;
|
|
426
|
-
type: 'parser';
|
|
427
331
|
/**
|
|
428
332
|
* File extensions this parser handles.
|
|
429
333
|
* Use `undefined` to create a catch-all fallback parser.
|
|
430
334
|
*
|
|
431
335
|
* @example ['.ts', '.js']
|
|
432
336
|
*/
|
|
433
|
-
extNames: Array<
|
|
434
|
-
/**
|
|
435
|
-
* @deprecated Will be removed once Fabric no longer requires it.
|
|
436
|
-
* @default () => {}
|
|
437
|
-
*/
|
|
438
|
-
install(...args: unknown[]): void | Promise<void>;
|
|
337
|
+
extNames: Array<FileNode['extname']> | undefined;
|
|
439
338
|
/**
|
|
440
339
|
* Convert a resolved file to a string.
|
|
441
340
|
*/
|
|
442
|
-
parse(file:
|
|
443
|
-
};
|
|
444
|
-
type UserParser<TMeta extends object = any> = Omit<Parser<TMeta>, 'type' | 'install'> & {
|
|
445
|
-
install?(...args: unknown[]): void | Promise<void>;
|
|
341
|
+
parse(file: FileNode<TMeta>, options?: PrintOptions): Promise<string> | string;
|
|
446
342
|
};
|
|
447
343
|
/**
|
|
448
344
|
* Defines a parser with type safety.
|
|
@@ -458,12 +354,13 @@ type UserParser<TMeta extends object = any> = Omit<Parser<TMeta>, 'type' | 'inst
|
|
|
458
354
|
* name: 'json',
|
|
459
355
|
* extNames: ['.json'],
|
|
460
356
|
* parse(file) {
|
|
461
|
-
*
|
|
357
|
+
* const { extractStringsFromNodes } = await import('@kubb/ast')
|
|
358
|
+
* return file.sources.map((s) => extractStringsFromNodes(s.nodes ?? [])).join('\n')
|
|
462
359
|
* },
|
|
463
360
|
* })
|
|
464
361
|
* ```
|
|
465
362
|
*/
|
|
466
|
-
declare function defineParser<TMeta extends object = any>(parser:
|
|
363
|
+
declare function defineParser<TMeta extends object = any>(parser: Parser<TMeta>): Parser<TMeta>;
|
|
467
364
|
//#endregion
|
|
468
365
|
//#region src/Kubb.d.ts
|
|
469
366
|
type DebugInfo = {
|
|
@@ -534,7 +431,7 @@ interface KubbEvents {
|
|
|
534
431
|
/**
|
|
535
432
|
* Emitted when code generation phase completes.
|
|
536
433
|
*/
|
|
537
|
-
'generation:end': [config: Config, files: Array<
|
|
434
|
+
'generation:end': [config: Config, files: Array<FileNode>, sources: Map<string, string>];
|
|
538
435
|
/**
|
|
539
436
|
* Emitted with a summary of the generation results.
|
|
540
437
|
* Contains summary lines, title, and success status.
|
|
@@ -621,7 +518,7 @@ interface KubbEvents {
|
|
|
621
518
|
* Emitted when file processing starts.
|
|
622
519
|
* Contains the list of files to be processed.
|
|
623
520
|
*/
|
|
624
|
-
'files:processing:start': [files: Array<
|
|
521
|
+
'files:processing:start': [files: Array<FileNode>];
|
|
625
522
|
/**
|
|
626
523
|
* Emitted for each file being processed, providing progress updates.
|
|
627
524
|
* Contains processed count, total count, percentage, and file details.
|
|
@@ -646,9 +543,9 @@ interface KubbEvents {
|
|
|
646
543
|
/**
|
|
647
544
|
* The file being processed.
|
|
648
545
|
*/
|
|
649
|
-
file:
|
|
546
|
+
file: FileNode;
|
|
650
547
|
/**
|
|
651
|
-
* Kubb configuration
|
|
548
|
+
* Kubb configuration
|
|
652
549
|
* Provides access to the current config during file processing.
|
|
653
550
|
*/
|
|
654
551
|
config: Config;
|
|
@@ -657,7 +554,7 @@ interface KubbEvents {
|
|
|
657
554
|
* Emitted when file processing completes.
|
|
658
555
|
* Contains the list of processed files.
|
|
659
556
|
*/
|
|
660
|
-
'files:processing:end': [files: Array<
|
|
557
|
+
'files:processing:end': [files: Array<FileNode>];
|
|
661
558
|
/**
|
|
662
559
|
* Emitted when a plugin starts executing.
|
|
663
560
|
*/
|
|
@@ -771,18 +668,6 @@ type FunctionParamsASTWithType = {
|
|
|
771
668
|
* @deprecated use ast package instead
|
|
772
669
|
*/
|
|
773
670
|
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
671
|
//#endregion
|
|
787
672
|
//#region src/utils/getBarrelFiles.d.ts
|
|
788
673
|
type FileMetaBase = {
|
|
@@ -814,12 +699,12 @@ type AddIndexesProps = {
|
|
|
814
699
|
* - When `type` is `'all'`, strips named exports so every re-export becomes a wildcard (`export * from`).
|
|
815
700
|
* - Attaches `meta` to each barrel file for downstream plugin identification.
|
|
816
701
|
*/
|
|
817
|
-
declare function getBarrelFiles(files: Array<
|
|
702
|
+
declare function getBarrelFiles(files: Array<FileNode>, {
|
|
818
703
|
type,
|
|
819
704
|
meta,
|
|
820
705
|
root,
|
|
821
706
|
output
|
|
822
|
-
}: AddIndexesProps): Promise<Array<
|
|
707
|
+
}: AddIndexesProps): Promise<Array<FileNode>>;
|
|
823
708
|
//#endregion
|
|
824
709
|
//#region src/types.d.ts
|
|
825
710
|
declare global {
|
|
@@ -866,9 +751,9 @@ type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'par
|
|
|
866
751
|
*
|
|
867
752
|
* A catch-all fallback parser is always appended last for any unhandled extension.
|
|
868
753
|
*
|
|
869
|
-
* When omitted, `
|
|
754
|
+
* When omitted, `parserTsx` from `@kubb/parser-ts` is used automatically as the
|
|
870
755
|
* default (requires `@kubb/parser-ts` to be installed as an optional dependency).
|
|
871
|
-
* @default [
|
|
756
|
+
* @default [parserTsx] — from `@kubb/parser-ts`
|
|
872
757
|
* @example
|
|
873
758
|
* ```ts
|
|
874
759
|
* import { parserTs, tsxParser } from '@kubb/parser-ts'
|
|
@@ -879,7 +764,7 @@ type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'par
|
|
|
879
764
|
*/
|
|
880
765
|
parsers?: Array<Parser>;
|
|
881
766
|
/**
|
|
882
|
-
* Adapter that converts the input file into a `@kubb/ast` `
|
|
767
|
+
* Adapter that converts the input file into a `@kubb/ast` `InputNode` — the universal
|
|
883
768
|
* intermediate representation consumed by all Kubb plugins.
|
|
884
769
|
*
|
|
885
770
|
* When omitted, `adapterOas()` from `@kubb/adapter-oas` is used automatically as the
|
|
@@ -939,10 +824,10 @@ type AdapterFactoryOptions<TName extends string = string, TOptions extends objec
|
|
|
939
824
|
document: TDocument;
|
|
940
825
|
};
|
|
941
826
|
/**
|
|
942
|
-
* An adapter converts a source file or data into a `@kubb/ast` `
|
|
827
|
+
* An adapter converts a source file or data into a `@kubb/ast` `InputNode`.
|
|
943
828
|
*
|
|
944
829
|
* Adapters are the single entry-point for different schema formats
|
|
945
|
-
* (OpenAPI, AsyncAPI, Drizzle, …) and produce the universal `
|
|
830
|
+
* (OpenAPI, AsyncAPI, Drizzle, …) and produce the universal `InputNode`
|
|
946
831
|
* that all Kubb plugins consume.
|
|
947
832
|
*
|
|
948
833
|
* @example
|
|
@@ -970,13 +855,13 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
|
970
855
|
* `undefined` before parsing; typed by the adapter's `TDocument` generic.
|
|
971
856
|
*/
|
|
972
857
|
document: TOptions['document'] | null;
|
|
973
|
-
|
|
858
|
+
inputNode: InputNode | null;
|
|
974
859
|
/**
|
|
975
|
-
* Convert the raw source into a universal `
|
|
860
|
+
* Convert the raw source into a universal `InputNode`.
|
|
976
861
|
*/
|
|
977
|
-
parse: (source: AdapterSource) => PossiblePromise<
|
|
862
|
+
parse: (source: AdapterSource) => PossiblePromise<InputNode>;
|
|
978
863
|
/**
|
|
979
|
-
* Extracts `
|
|
864
|
+
* Extracts `ImportNode` entries needed by a `SchemaNode` tree.
|
|
980
865
|
* Populated after the first `parse()` call. Returns an empty array before that.
|
|
981
866
|
*
|
|
982
867
|
* The `resolve` callback receives the collision-corrected schema name and must
|
|
@@ -985,7 +870,7 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
|
985
870
|
getImports: (node: SchemaNode, resolve: (schemaName: string) => {
|
|
986
871
|
name: string;
|
|
987
872
|
path: string;
|
|
988
|
-
}) => Array<
|
|
873
|
+
}) => Array<ImportNode>;
|
|
989
874
|
};
|
|
990
875
|
type BarrelType = 'all' | 'named' | 'propagate';
|
|
991
876
|
type DevtoolsOptions = {
|
|
@@ -1028,7 +913,7 @@ type Config<TInput = Input> = {
|
|
|
1028
913
|
*/
|
|
1029
914
|
parsers: Array<Parser>;
|
|
1030
915
|
/**
|
|
1031
|
-
* Adapter that converts the input file into a `@kubb/ast` `
|
|
916
|
+
* Adapter that converts the input file into a `@kubb/ast` `InputNode` — the universal
|
|
1032
917
|
* intermediate representation consumed by all Kubb plugins.
|
|
1033
918
|
*
|
|
1034
919
|
* - Use `@kubb/adapter-oas` for OpenAPI / Swagger.
|
|
@@ -1101,7 +986,7 @@ type Config<TInput = Input> = {
|
|
|
1101
986
|
* Overrides the extension for generated imports and exports. By default, each plugin adds an extension.
|
|
1102
987
|
* @default { '.ts': '.ts'}
|
|
1103
988
|
*/
|
|
1104
|
-
extension?: Record<
|
|
989
|
+
extension?: Record<FileNode['extname'], FileNode['extname'] | ''>;
|
|
1105
990
|
/**
|
|
1106
991
|
* 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`).
|
|
1107
992
|
* @default 'named'
|
|
@@ -1193,10 +1078,10 @@ type Resolver = {
|
|
|
1193
1078
|
pluginName: Plugin['name'];
|
|
1194
1079
|
default(name: ResolveNameParams['name'], type?: ResolveNameParams['type']): string;
|
|
1195
1080
|
resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null;
|
|
1196
|
-
resolvePath(params: ResolverPathParams, context: ResolverContext):
|
|
1197
|
-
resolveFile(params: ResolverFileParams, context: ResolverContext):
|
|
1198
|
-
resolveBanner(node:
|
|
1199
|
-
resolveFooter(node:
|
|
1081
|
+
resolvePath(params: ResolverPathParams, context: ResolverContext): string;
|
|
1082
|
+
resolveFile(params: ResolverFileParams, context: ResolverContext): FileNode;
|
|
1083
|
+
resolveBanner(node: InputNode | null, context: ResolveBannerContext): string | undefined;
|
|
1084
|
+
resolveFooter(node: InputNode | null, context: ResolveBannerContext): string | undefined;
|
|
1200
1085
|
};
|
|
1201
1086
|
/**
|
|
1202
1087
|
* The user-facing subset of a `Resolver` — everything except the four methods injected by
|
|
@@ -1313,15 +1198,15 @@ type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<string, object, object,
|
|
|
1313
1198
|
/**
|
|
1314
1199
|
* Handler for a single schema node. Used by the `schema` hook on a plugin.
|
|
1315
1200
|
*/
|
|
1316
|
-
type SchemaHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<
|
|
1201
|
+
type SchemaHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<KubbReactNode | Array<FileNode> | void>;
|
|
1317
1202
|
/**
|
|
1318
1203
|
* Handler for a single operation node. Used by the `operation` hook on a plugin.
|
|
1319
1204
|
*/
|
|
1320
|
-
type OperationHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<
|
|
1205
|
+
type OperationHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<KubbReactNode | Array<FileNode> | void>;
|
|
1321
1206
|
/**
|
|
1322
1207
|
* Handler for all collected operation nodes. Used by the `operations` hook on a plugin.
|
|
1323
1208
|
*/
|
|
1324
|
-
type OperationsHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<
|
|
1209
|
+
type OperationsHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<KubbReactNode | Array<FileNode> | void>;
|
|
1325
1210
|
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1326
1211
|
/**
|
|
1327
1212
|
* Unique name used for the plugin
|
|
@@ -1375,7 +1260,7 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
1375
1260
|
buildEnd: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1376
1261
|
/**
|
|
1377
1262
|
* Called for each schema node during the AST walk.
|
|
1378
|
-
* Return a React element, an array of `
|
|
1263
|
+
* Return a React element, an array of `FileNode`, or `void` for manual handling.
|
|
1379
1264
|
* Nodes matching `exclude`/`include` filters are skipped automatically.
|
|
1380
1265
|
*
|
|
1381
1266
|
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
@@ -1383,7 +1268,7 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
1383
1268
|
schema?: SchemaHook<TOptions>;
|
|
1384
1269
|
/**
|
|
1385
1270
|
* Called for each operation node during the AST walk.
|
|
1386
|
-
* Return a React element, an array of `
|
|
1271
|
+
* Return a React element, an array of `FileNode`, or `void` for manual handling.
|
|
1387
1272
|
*
|
|
1388
1273
|
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
1389
1274
|
*/
|
|
@@ -1416,7 +1301,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
1416
1301
|
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1417
1302
|
/**
|
|
1418
1303
|
* Called for each schema node during the AST walk.
|
|
1419
|
-
* Return a React element (`<File>...</File>`), an array of `
|
|
1304
|
+
* Return a React element (`<File>...</File>`), an array of `FileNode` objects,
|
|
1420
1305
|
* or `void` to handle file writing manually via `this.upsertFile`.
|
|
1421
1306
|
* Nodes matching `exclude` / `include` filters are skipped automatically.
|
|
1422
1307
|
*
|
|
@@ -1425,7 +1310,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
1425
1310
|
schema?: SchemaHook<TOptions>;
|
|
1426
1311
|
/**
|
|
1427
1312
|
* Called for each operation node during the AST walk.
|
|
1428
|
-
* Return a React element (`<File>...</File>`), an array of `
|
|
1313
|
+
* Return a React element (`<File>...</File>`), an array of `FileNode` objects,
|
|
1429
1314
|
* or `void` to handle file writing manually via `this.upsertFile`.
|
|
1430
1315
|
*
|
|
1431
1316
|
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
@@ -1445,7 +1330,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
1445
1330
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
1446
1331
|
* @deprecated this will be replaced by resolvers
|
|
1447
1332
|
*/
|
|
1448
|
-
resolvePath?: (this: PluginContext<TOptions>, baseName:
|
|
1333
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: FileNode['baseName'], mode?: 'single' | 'split', options?: TOptions['resolvePathOptions']) => string;
|
|
1449
1334
|
/**
|
|
1450
1335
|
* Resolve to a name based on a string.
|
|
1451
1336
|
* Useful when converting to PascalCase or camelCase.
|
|
@@ -1459,8 +1344,8 @@ type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
|
1459
1344
|
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
1460
1345
|
type ResolvePathParams<TOptions = object> = {
|
|
1461
1346
|
pluginName?: string;
|
|
1462
|
-
baseName:
|
|
1463
|
-
mode?:
|
|
1347
|
+
baseName: FileNode['baseName'];
|
|
1348
|
+
mode?: 'single' | 'split';
|
|
1464
1349
|
/**
|
|
1465
1350
|
* Options to be passed to 'resolvePath' 3th parameter
|
|
1466
1351
|
*/
|
|
@@ -1480,7 +1365,6 @@ type ResolveNameParams = {
|
|
|
1480
1365
|
type?: 'file' | 'function' | 'type' | 'const';
|
|
1481
1366
|
};
|
|
1482
1367
|
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1483
|
-
fabric: Fabric;
|
|
1484
1368
|
config: Config;
|
|
1485
1369
|
/**
|
|
1486
1370
|
* Absolute path to the output directory for the current plugin.
|
|
@@ -1494,7 +1378,7 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1494
1378
|
*/
|
|
1495
1379
|
getMode: (output: {
|
|
1496
1380
|
path: string;
|
|
1497
|
-
}) =>
|
|
1381
|
+
}) => 'single' | 'split';
|
|
1498
1382
|
driver: PluginDriver;
|
|
1499
1383
|
/**
|
|
1500
1384
|
* Get a plugin by name. Returns the plugin typed via `Kubb.PluginRegistry` when
|
|
@@ -1511,11 +1395,11 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1511
1395
|
/**
|
|
1512
1396
|
* Only add when the file does not exist yet
|
|
1513
1397
|
*/
|
|
1514
|
-
addFile: (...file: Array<
|
|
1398
|
+
addFile: (...file: Array<FileNode>) => Promise<void>;
|
|
1515
1399
|
/**
|
|
1516
1400
|
* merging multiple sources into the same output file
|
|
1517
1401
|
*/
|
|
1518
|
-
upsertFile: (...file: Array<
|
|
1402
|
+
upsertFile: (...file: Array<FileNode>) => Promise<void>;
|
|
1519
1403
|
/**
|
|
1520
1404
|
* @deprecated use this.warn, this.error, this.info instead
|
|
1521
1405
|
*/
|
|
@@ -1549,23 +1433,23 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1549
1433
|
*/
|
|
1550
1434
|
info: (message: string) => void;
|
|
1551
1435
|
/**
|
|
1552
|
-
* Opens the Kubb Studio URL for the current `
|
|
1436
|
+
* Opens the Kubb Studio URL for the current `inputNode` in the default browser.
|
|
1553
1437
|
* Falls back to printing the URL if the browser cannot be launched.
|
|
1554
|
-
* No-ops silently when no adapter has set
|
|
1438
|
+
* No-ops silently when no adapter has set an `inputNode`.
|
|
1555
1439
|
*/
|
|
1556
1440
|
openInStudio: (options?: DevtoolsOptions) => Promise<void>;
|
|
1557
1441
|
} & ({
|
|
1558
1442
|
/**
|
|
1559
|
-
* Returns the universal `@kubb/ast` `
|
|
1443
|
+
* Returns the universal `@kubb/ast` `InputNode` produced by the configured adapter.
|
|
1560
1444
|
* Returns `undefined` when no adapter was set (legacy OAS-only usage).
|
|
1561
1445
|
*/
|
|
1562
|
-
|
|
1446
|
+
inputNode: InputNode;
|
|
1563
1447
|
/**
|
|
1564
1448
|
* Return the adapter from `@kubb/ast`
|
|
1565
1449
|
*/
|
|
1566
1450
|
adapter: Adapter;
|
|
1567
1451
|
} | {
|
|
1568
|
-
|
|
1452
|
+
inputNode?: never;
|
|
1569
1453
|
adapter?: never;
|
|
1570
1454
|
}) & Kubb.PluginContext;
|
|
1571
1455
|
/**
|
|
@@ -1573,12 +1457,12 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1573
1457
|
*
|
|
1574
1458
|
* Generators and the `schema`/`operation`/`operations` plugin hooks are only invoked from
|
|
1575
1459
|
* `runPluginAstHooks`, which already guards against a missing adapter. This type reflects
|
|
1576
|
-
* that guarantee — `this.adapter` and `this.
|
|
1460
|
+
* that guarantee — `this.adapter` and `this.inputNode` are always defined, so no runtime
|
|
1577
1461
|
* checks or casts are needed inside the method bodies.
|
|
1578
1462
|
*/
|
|
1579
|
-
type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Omit<PluginContext<TOptions>, 'adapter' | '
|
|
1463
|
+
type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Omit<PluginContext<TOptions>, 'adapter' | 'inputNode'> & {
|
|
1580
1464
|
adapter: Adapter;
|
|
1581
|
-
|
|
1465
|
+
inputNode: InputNode;
|
|
1582
1466
|
};
|
|
1583
1467
|
/**
|
|
1584
1468
|
* Specify the export location for the files and define the behavior of the output
|
|
@@ -1596,11 +1480,11 @@ type Output<_TOptions = unknown> = {
|
|
|
1596
1480
|
/**
|
|
1597
1481
|
* Add a banner text in the beginning of every file
|
|
1598
1482
|
*/
|
|
1599
|
-
banner?: string | ((node?:
|
|
1483
|
+
banner?: string | ((node?: InputNode) => string);
|
|
1600
1484
|
/**
|
|
1601
1485
|
* Add a footer text in the beginning of every file
|
|
1602
1486
|
*/
|
|
1603
|
-
footer?: string | ((node?:
|
|
1487
|
+
footer?: string | ((node?: InputNode) => string);
|
|
1604
1488
|
/**
|
|
1605
1489
|
* Whether to override existing external files if they already exist.
|
|
1606
1490
|
* @default false
|
|
@@ -1644,7 +1528,7 @@ type LoggerOptions = {
|
|
|
1644
1528
|
logLevel: (typeof logLevel)[keyof typeof logLevel];
|
|
1645
1529
|
};
|
|
1646
1530
|
/**
|
|
1647
|
-
* Shared context passed to all plugins, parsers, and
|
|
1531
|
+
* Shared context passed to all plugins, parsers, and other internals.
|
|
1648
1532
|
*/
|
|
1649
1533
|
type LoggerContext = AsyncEventEmitter<KubbEvents>;
|
|
1650
1534
|
type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
|
|
@@ -1748,8 +1632,8 @@ type ResolvePathOptions = {
|
|
|
1748
1632
|
* ```
|
|
1749
1633
|
*/
|
|
1750
1634
|
type ResolverPathParams = {
|
|
1751
|
-
baseName:
|
|
1752
|
-
pathMode?:
|
|
1635
|
+
baseName: FileNode['baseName'];
|
|
1636
|
+
pathMode?: 'single' | 'split';
|
|
1753
1637
|
/**
|
|
1754
1638
|
* Tag value used when `group.type === 'tag'`.
|
|
1755
1639
|
*/
|
|
@@ -1800,7 +1684,7 @@ type ResolverContext = {
|
|
|
1800
1684
|
*/
|
|
1801
1685
|
type ResolverFileParams = {
|
|
1802
1686
|
name: string;
|
|
1803
|
-
extname:
|
|
1687
|
+
extname: FileNode['extname'];
|
|
1804
1688
|
/**
|
|
1805
1689
|
* Tag value used when `group.type === 'tag'`.
|
|
1806
1690
|
*/
|
|
@@ -1818,7 +1702,7 @@ type ResolverFileParams = {
|
|
|
1818
1702
|
*
|
|
1819
1703
|
* @example
|
|
1820
1704
|
* ```ts
|
|
1821
|
-
* resolver.resolveBanner(
|
|
1705
|
+
* resolver.resolveBanner(inputNode, { output: { banner: '// generated' }, config })
|
|
1822
1706
|
* // → '// generated'
|
|
1823
1707
|
* ```
|
|
1824
1708
|
*/
|
|
@@ -1844,7 +1728,6 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
|
|
|
1844
1728
|
plugin: Plugin;
|
|
1845
1729
|
};
|
|
1846
1730
|
type Options = {
|
|
1847
|
-
fabric: Fabric;
|
|
1848
1731
|
events: AsyncEventEmitter<KubbEvents>;
|
|
1849
1732
|
/**
|
|
1850
1733
|
* @default Number.POSITIVE_INFINITY
|
|
@@ -1856,8 +1739,8 @@ type Options = {
|
|
|
1856
1739
|
*/
|
|
1857
1740
|
type GetFileOptions<TOptions = object> = {
|
|
1858
1741
|
name: string;
|
|
1859
|
-
mode?:
|
|
1860
|
-
extname:
|
|
1742
|
+
mode?: 'single' | 'split';
|
|
1743
|
+
extname: FileNode['extname'];
|
|
1861
1744
|
pluginName: string;
|
|
1862
1745
|
options?: TOptions;
|
|
1863
1746
|
};
|
|
@@ -1870,17 +1753,23 @@ type GetFileOptions<TOptions = object> = {
|
|
|
1870
1753
|
* getMode('src/gen/types') // 'split'
|
|
1871
1754
|
* ```
|
|
1872
1755
|
*/
|
|
1873
|
-
declare function getMode(fileOrFolder: string | undefined | null):
|
|
1756
|
+
declare function getMode(fileOrFolder: string | undefined | null): 'single' | 'split';
|
|
1874
1757
|
declare class PluginDriver {
|
|
1875
1758
|
#private;
|
|
1876
1759
|
readonly config: Config;
|
|
1877
1760
|
readonly options: Options;
|
|
1878
1761
|
/**
|
|
1879
|
-
* The universal `@kubb/ast` `
|
|
1762
|
+
* The universal `@kubb/ast` `InputNode` produced by the adapter, set by
|
|
1880
1763
|
* the build pipeline after the adapter's `parse()` resolves.
|
|
1881
1764
|
*/
|
|
1882
|
-
|
|
1765
|
+
inputNode: InputNode | undefined;
|
|
1883
1766
|
adapter: Adapter | undefined;
|
|
1767
|
+
/**
|
|
1768
|
+
* Central file store for all generated files.
|
|
1769
|
+
* Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to
|
|
1770
|
+
* add files; this property gives direct read/write access when needed.
|
|
1771
|
+
*/
|
|
1772
|
+
readonly fileManager: FileManager;
|
|
1884
1773
|
readonly plugins: Map<string, Plugin>;
|
|
1885
1774
|
constructor(config: Config, options: Options);
|
|
1886
1775
|
get events(): AsyncEventEmitter<KubbEvents>;
|
|
@@ -1894,13 +1783,13 @@ declare class PluginDriver {
|
|
|
1894
1783
|
extname,
|
|
1895
1784
|
pluginName,
|
|
1896
1785
|
options
|
|
1897
|
-
}: GetFileOptions<TOptions>):
|
|
1786
|
+
}: GetFileOptions<TOptions>): FileNode<{
|
|
1898
1787
|
pluginName: string;
|
|
1899
1788
|
}>;
|
|
1900
1789
|
/**
|
|
1901
1790
|
* @deprecated use resolvers context instead
|
|
1902
1791
|
*/
|
|
1903
|
-
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) =>
|
|
1792
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => string;
|
|
1904
1793
|
/**
|
|
1905
1794
|
* @deprecated use resolvers context instead
|
|
1906
1795
|
*/
|
|
@@ -1982,5 +1871,5 @@ declare class PluginDriver {
|
|
|
1982
1871
|
requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>;
|
|
1983
1872
|
}
|
|
1984
1873
|
//#endregion
|
|
1985
|
-
export {
|
|
1986
|
-
//# sourceMappingURL=PluginDriver-
|
|
1874
|
+
export { FunctionParamsAST 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 _, AdapterSource as a, defineParser as at, OperationsHook as b, Config as c, mergeGenerators as ct, GeneratorContext as d, formatters as dt, CLIOptions as et, Group as f, linters as ft, Logger as g, InputPath as h, AdapterFactoryOptions as i, Parser as it, Presets as j, PluginWithLifeCycle as k, DevtoolsOptions as l, Storage as lt, InputData as m, AsyncEventEmitter as mt, getMode as n, defineConfig as nt, BarrelType as o, Generator as ot, Include as p, logLevel as pt, UserLogger as q, Adapter as r, KubbEvents as rt, CompatibilityPreset as s, defineGenerator as st, PluginDriver as t, ConfigInput as tt, Exclude as u, createStorage as ut, LoggerOptions as v, PluginContext as w, Output as x, OperationHook as y, ResolvePathParams as z };
|
|
1875
|
+
//# sourceMappingURL=PluginDriver-BBi_41VF.d.ts.map
|