@kubb/core 5.0.0-alpha.31 → 5.0.0-alpha.32
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-nm7tvGs9.d.ts} +105 -196
- package/dist/chunk--u3MIqq1.js +8 -0
- package/dist/{chunk-MlS0t1Af.cjs → chunk-ByKO4r7w.cjs} +0 -15
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +3 -3
- package/dist/hooks.js +1 -1
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +339 -197
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +19 -21
- package/dist/index.js +342 -194
- package/dist/index.js.map +1 -1
- package/package.json +2 -4
- package/src/FileManager.ts +131 -0
- package/src/FileProcessor.ts +83 -0
- package/src/Kubb.ts +5 -5
- package/src/PluginDriver.ts +29 -24
- package/src/build.ts +89 -107
- package/src/constants.ts +7 -2
- package/src/defineGenerator.ts +12 -13
- package/src/defineParser.ts +4 -4
- package/src/defineResolver.ts +18 -19
- package/src/devtools.ts +14 -14
- package/src/hooks/useMode.ts +2 -3
- package/src/index.ts +0 -1
- package/src/renderNode.tsx +8 -7
- package/src/types.ts +42 -45
- package/src/utils/TreeNode.ts +7 -7
- package/src/utils/getBarrelFiles.ts +30 -25
- package/dist/chunk-O_arW02_.js +0 -17
- package/src/KubbFile.ts +0 -143
|
@@ -1,6 +1,5 @@
|
|
|
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
4
|
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
6
5
|
|
|
@@ -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<FabricReactNode | Array<
|
|
283
|
+
schema?: (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | 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<FabricReactNode | Array<
|
|
288
|
+
operation?: (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | 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<FabricReactNode | Array<
|
|
293
|
+
operations?: (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<FileNode> | void>;
|
|
389
294
|
};
|
|
390
295
|
/**
|
|
391
296
|
* Defines a generator. Returns the object as-is with correct `this` typings.
|
|
@@ -419,7 +324,7 @@ 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;
|
|
@@ -430,7 +335,7 @@ type Parser<TMeta extends object = any> = {
|
|
|
430
335
|
*
|
|
431
336
|
* @example ['.ts', '.js']
|
|
432
337
|
*/
|
|
433
|
-
extNames: Array<
|
|
338
|
+
extNames: Array<FileNode['extname']> | undefined;
|
|
434
339
|
/**
|
|
435
340
|
* @deprecated Will be removed once Fabric no longer requires it.
|
|
436
341
|
* @default () => {}
|
|
@@ -439,7 +344,7 @@ type Parser<TMeta extends object = any> = {
|
|
|
439
344
|
/**
|
|
440
345
|
* Convert a resolved file to a string.
|
|
441
346
|
*/
|
|
442
|
-
parse(file:
|
|
347
|
+
parse(file: FileNode<TMeta>, options?: PrintOptions): Promise<string> | string;
|
|
443
348
|
};
|
|
444
349
|
type UserParser<TMeta extends object = any> = Omit<Parser<TMeta>, 'type' | 'install'> & {
|
|
445
350
|
install?(...args: unknown[]): void | Promise<void>;
|
|
@@ -534,7 +439,7 @@ interface KubbEvents {
|
|
|
534
439
|
/**
|
|
535
440
|
* Emitted when code generation phase completes.
|
|
536
441
|
*/
|
|
537
|
-
'generation:end': [config: Config, files: Array<
|
|
442
|
+
'generation:end': [config: Config, files: Array<FileNode>, sources: Map<string, string>];
|
|
538
443
|
/**
|
|
539
444
|
* Emitted with a summary of the generation results.
|
|
540
445
|
* Contains summary lines, title, and success status.
|
|
@@ -621,7 +526,7 @@ interface KubbEvents {
|
|
|
621
526
|
* Emitted when file processing starts.
|
|
622
527
|
* Contains the list of files to be processed.
|
|
623
528
|
*/
|
|
624
|
-
'files:processing:start': [files: Array<
|
|
529
|
+
'files:processing:start': [files: Array<FileNode>];
|
|
625
530
|
/**
|
|
626
531
|
* Emitted for each file being processed, providing progress updates.
|
|
627
532
|
* Contains processed count, total count, percentage, and file details.
|
|
@@ -646,7 +551,7 @@ interface KubbEvents {
|
|
|
646
551
|
/**
|
|
647
552
|
* The file being processed.
|
|
648
553
|
*/
|
|
649
|
-
file:
|
|
554
|
+
file: FileNode;
|
|
650
555
|
/**
|
|
651
556
|
* Kubb configuration (not present in Fabric).
|
|
652
557
|
* Provides access to the current config during file processing.
|
|
@@ -657,7 +562,7 @@ interface KubbEvents {
|
|
|
657
562
|
* Emitted when file processing completes.
|
|
658
563
|
* Contains the list of processed files.
|
|
659
564
|
*/
|
|
660
|
-
'files:processing:end': [files: Array<
|
|
565
|
+
'files:processing:end': [files: Array<FileNode>];
|
|
661
566
|
/**
|
|
662
567
|
* Emitted when a plugin starts executing.
|
|
663
568
|
*/
|
|
@@ -814,12 +719,12 @@ type AddIndexesProps = {
|
|
|
814
719
|
* - When `type` is `'all'`, strips named exports so every re-export becomes a wildcard (`export * from`).
|
|
815
720
|
* - Attaches `meta` to each barrel file for downstream plugin identification.
|
|
816
721
|
*/
|
|
817
|
-
declare function getBarrelFiles(files: Array<
|
|
722
|
+
declare function getBarrelFiles(files: Array<FileNode>, {
|
|
818
723
|
type,
|
|
819
724
|
meta,
|
|
820
725
|
root,
|
|
821
726
|
output
|
|
822
|
-
}: AddIndexesProps): Promise<Array<
|
|
727
|
+
}: AddIndexesProps): Promise<Array<FileNode>>;
|
|
823
728
|
//#endregion
|
|
824
729
|
//#region src/types.d.ts
|
|
825
730
|
declare global {
|
|
@@ -879,7 +784,7 @@ type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'par
|
|
|
879
784
|
*/
|
|
880
785
|
parsers?: Array<Parser>;
|
|
881
786
|
/**
|
|
882
|
-
* Adapter that converts the input file into a `@kubb/ast` `
|
|
787
|
+
* Adapter that converts the input file into a `@kubb/ast` `InputNode` — the universal
|
|
883
788
|
* intermediate representation consumed by all Kubb plugins.
|
|
884
789
|
*
|
|
885
790
|
* When omitted, `adapterOas()` from `@kubb/adapter-oas` is used automatically as the
|
|
@@ -939,10 +844,10 @@ type AdapterFactoryOptions<TName extends string = string, TOptions extends objec
|
|
|
939
844
|
document: TDocument;
|
|
940
845
|
};
|
|
941
846
|
/**
|
|
942
|
-
* An adapter converts a source file or data into a `@kubb/ast` `
|
|
847
|
+
* An adapter converts a source file or data into a `@kubb/ast` `InputNode`.
|
|
943
848
|
*
|
|
944
849
|
* Adapters are the single entry-point for different schema formats
|
|
945
|
-
* (OpenAPI, AsyncAPI, Drizzle, …) and produce the universal `
|
|
850
|
+
* (OpenAPI, AsyncAPI, Drizzle, …) and produce the universal `InputNode`
|
|
946
851
|
* that all Kubb plugins consume.
|
|
947
852
|
*
|
|
948
853
|
* @example
|
|
@@ -970,13 +875,13 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
|
970
875
|
* `undefined` before parsing; typed by the adapter's `TDocument` generic.
|
|
971
876
|
*/
|
|
972
877
|
document: TOptions['document'] | null;
|
|
973
|
-
|
|
878
|
+
inputNode: InputNode | null;
|
|
974
879
|
/**
|
|
975
|
-
* Convert the raw source into a universal `
|
|
880
|
+
* Convert the raw source into a universal `InputNode`.
|
|
976
881
|
*/
|
|
977
|
-
parse: (source: AdapterSource) => PossiblePromise<
|
|
882
|
+
parse: (source: AdapterSource) => PossiblePromise<InputNode>;
|
|
978
883
|
/**
|
|
979
|
-
* Extracts `
|
|
884
|
+
* Extracts `ImportNode` entries needed by a `SchemaNode` tree.
|
|
980
885
|
* Populated after the first `parse()` call. Returns an empty array before that.
|
|
981
886
|
*
|
|
982
887
|
* The `resolve` callback receives the collision-corrected schema name and must
|
|
@@ -985,7 +890,7 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
|
985
890
|
getImports: (node: SchemaNode, resolve: (schemaName: string) => {
|
|
986
891
|
name: string;
|
|
987
892
|
path: string;
|
|
988
|
-
}) => Array<
|
|
893
|
+
}) => Array<ImportNode>;
|
|
989
894
|
};
|
|
990
895
|
type BarrelType = 'all' | 'named' | 'propagate';
|
|
991
896
|
type DevtoolsOptions = {
|
|
@@ -1028,7 +933,7 @@ type Config<TInput = Input> = {
|
|
|
1028
933
|
*/
|
|
1029
934
|
parsers: Array<Parser>;
|
|
1030
935
|
/**
|
|
1031
|
-
* Adapter that converts the input file into a `@kubb/ast` `
|
|
936
|
+
* Adapter that converts the input file into a `@kubb/ast` `InputNode` — the universal
|
|
1032
937
|
* intermediate representation consumed by all Kubb plugins.
|
|
1033
938
|
*
|
|
1034
939
|
* - Use `@kubb/adapter-oas` for OpenAPI / Swagger.
|
|
@@ -1101,7 +1006,7 @@ type Config<TInput = Input> = {
|
|
|
1101
1006
|
* Overrides the extension for generated imports and exports. By default, each plugin adds an extension.
|
|
1102
1007
|
* @default { '.ts': '.ts'}
|
|
1103
1008
|
*/
|
|
1104
|
-
extension?: Record<
|
|
1009
|
+
extension?: Record<FileNode['extname'], FileNode['extname'] | ''>;
|
|
1105
1010
|
/**
|
|
1106
1011
|
* 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
1012
|
* @default 'named'
|
|
@@ -1193,10 +1098,10 @@ type Resolver = {
|
|
|
1193
1098
|
pluginName: Plugin['name'];
|
|
1194
1099
|
default(name: ResolveNameParams['name'], type?: ResolveNameParams['type']): string;
|
|
1195
1100
|
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:
|
|
1101
|
+
resolvePath(params: ResolverPathParams, context: ResolverContext): string;
|
|
1102
|
+
resolveFile(params: ResolverFileParams, context: ResolverContext): FileNode;
|
|
1103
|
+
resolveBanner(node: InputNode | null, context: ResolveBannerContext): string | undefined;
|
|
1104
|
+
resolveFooter(node: InputNode | null, context: ResolveBannerContext): string | undefined;
|
|
1200
1105
|
};
|
|
1201
1106
|
/**
|
|
1202
1107
|
* The user-facing subset of a `Resolver` — everything except the four methods injected by
|
|
@@ -1313,15 +1218,15 @@ type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<string, object, object,
|
|
|
1313
1218
|
/**
|
|
1314
1219
|
* Handler for a single schema node. Used by the `schema` hook on a plugin.
|
|
1315
1220
|
*/
|
|
1316
|
-
type SchemaHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<
|
|
1221
|
+
type SchemaHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<FileNode> | void>;
|
|
1317
1222
|
/**
|
|
1318
1223
|
* Handler for a single operation node. Used by the `operation` hook on a plugin.
|
|
1319
1224
|
*/
|
|
1320
|
-
type OperationHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<
|
|
1225
|
+
type OperationHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<FileNode> | void>;
|
|
1321
1226
|
/**
|
|
1322
1227
|
* Handler for all collected operation nodes. Used by the `operations` hook on a plugin.
|
|
1323
1228
|
*/
|
|
1324
|
-
type OperationsHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<
|
|
1229
|
+
type OperationsHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<FileNode> | void>;
|
|
1325
1230
|
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1326
1231
|
/**
|
|
1327
1232
|
* Unique name used for the plugin
|
|
@@ -1375,7 +1280,7 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
1375
1280
|
buildEnd: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1376
1281
|
/**
|
|
1377
1282
|
* Called for each schema node during the AST walk.
|
|
1378
|
-
* Return a React element, an array of `
|
|
1283
|
+
* Return a React element, an array of `FileNode`, or `void` for manual handling.
|
|
1379
1284
|
* Nodes matching `exclude`/`include` filters are skipped automatically.
|
|
1380
1285
|
*
|
|
1381
1286
|
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
@@ -1383,7 +1288,7 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
1383
1288
|
schema?: SchemaHook<TOptions>;
|
|
1384
1289
|
/**
|
|
1385
1290
|
* Called for each operation node during the AST walk.
|
|
1386
|
-
* Return a React element, an array of `
|
|
1291
|
+
* Return a React element, an array of `FileNode`, or `void` for manual handling.
|
|
1387
1292
|
*
|
|
1388
1293
|
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
1389
1294
|
*/
|
|
@@ -1416,7 +1321,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
1416
1321
|
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1417
1322
|
/**
|
|
1418
1323
|
* Called for each schema node during the AST walk.
|
|
1419
|
-
* Return a React element (`<File>...</File>`), an array of `
|
|
1324
|
+
* Return a React element (`<File>...</File>`), an array of `FileNode` objects,
|
|
1420
1325
|
* or `void` to handle file writing manually via `this.upsertFile`.
|
|
1421
1326
|
* Nodes matching `exclude` / `include` filters are skipped automatically.
|
|
1422
1327
|
*
|
|
@@ -1425,7 +1330,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
1425
1330
|
schema?: SchemaHook<TOptions>;
|
|
1426
1331
|
/**
|
|
1427
1332
|
* Called for each operation node during the AST walk.
|
|
1428
|
-
* Return a React element (`<File>...</File>`), an array of `
|
|
1333
|
+
* Return a React element (`<File>...</File>`), an array of `FileNode` objects,
|
|
1429
1334
|
* or `void` to handle file writing manually via `this.upsertFile`.
|
|
1430
1335
|
*
|
|
1431
1336
|
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
@@ -1445,7 +1350,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
1445
1350
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
1446
1351
|
* @deprecated this will be replaced by resolvers
|
|
1447
1352
|
*/
|
|
1448
|
-
resolvePath?: (this: PluginContext<TOptions>, baseName:
|
|
1353
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: FileNode['baseName'], mode?: 'single' | 'split', options?: TOptions['resolvePathOptions']) => string;
|
|
1449
1354
|
/**
|
|
1450
1355
|
* Resolve to a name based on a string.
|
|
1451
1356
|
* Useful when converting to PascalCase or camelCase.
|
|
@@ -1459,8 +1364,8 @@ type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
|
1459
1364
|
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
1460
1365
|
type ResolvePathParams<TOptions = object> = {
|
|
1461
1366
|
pluginName?: string;
|
|
1462
|
-
baseName:
|
|
1463
|
-
mode?:
|
|
1367
|
+
baseName: FileNode['baseName'];
|
|
1368
|
+
mode?: 'single' | 'split';
|
|
1464
1369
|
/**
|
|
1465
1370
|
* Options to be passed to 'resolvePath' 3th parameter
|
|
1466
1371
|
*/
|
|
@@ -1480,7 +1385,6 @@ type ResolveNameParams = {
|
|
|
1480
1385
|
type?: 'file' | 'function' | 'type' | 'const';
|
|
1481
1386
|
};
|
|
1482
1387
|
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1483
|
-
fabric: Fabric;
|
|
1484
1388
|
config: Config;
|
|
1485
1389
|
/**
|
|
1486
1390
|
* Absolute path to the output directory for the current plugin.
|
|
@@ -1494,7 +1398,7 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1494
1398
|
*/
|
|
1495
1399
|
getMode: (output: {
|
|
1496
1400
|
path: string;
|
|
1497
|
-
}) =>
|
|
1401
|
+
}) => 'single' | 'split';
|
|
1498
1402
|
driver: PluginDriver;
|
|
1499
1403
|
/**
|
|
1500
1404
|
* Get a plugin by name. Returns the plugin typed via `Kubb.PluginRegistry` when
|
|
@@ -1511,11 +1415,11 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1511
1415
|
/**
|
|
1512
1416
|
* Only add when the file does not exist yet
|
|
1513
1417
|
*/
|
|
1514
|
-
addFile: (...file: Array<
|
|
1418
|
+
addFile: (...file: Array<FileNode>) => Promise<void>;
|
|
1515
1419
|
/**
|
|
1516
1420
|
* merging multiple sources into the same output file
|
|
1517
1421
|
*/
|
|
1518
|
-
upsertFile: (...file: Array<
|
|
1422
|
+
upsertFile: (...file: Array<FileNode>) => Promise<void>;
|
|
1519
1423
|
/**
|
|
1520
1424
|
* @deprecated use this.warn, this.error, this.info instead
|
|
1521
1425
|
*/
|
|
@@ -1549,23 +1453,23 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1549
1453
|
*/
|
|
1550
1454
|
info: (message: string) => void;
|
|
1551
1455
|
/**
|
|
1552
|
-
* Opens the Kubb Studio URL for the current `
|
|
1456
|
+
* Opens the Kubb Studio URL for the current `inputNode` in the default browser.
|
|
1553
1457
|
* Falls back to printing the URL if the browser cannot be launched.
|
|
1554
|
-
* No-ops silently when no adapter has set
|
|
1458
|
+
* No-ops silently when no adapter has set an `inputNode`.
|
|
1555
1459
|
*/
|
|
1556
1460
|
openInStudio: (options?: DevtoolsOptions) => Promise<void>;
|
|
1557
1461
|
} & ({
|
|
1558
1462
|
/**
|
|
1559
|
-
* Returns the universal `@kubb/ast` `
|
|
1463
|
+
* Returns the universal `@kubb/ast` `InputNode` produced by the configured adapter.
|
|
1560
1464
|
* Returns `undefined` when no adapter was set (legacy OAS-only usage).
|
|
1561
1465
|
*/
|
|
1562
|
-
|
|
1466
|
+
inputNode: InputNode;
|
|
1563
1467
|
/**
|
|
1564
1468
|
* Return the adapter from `@kubb/ast`
|
|
1565
1469
|
*/
|
|
1566
1470
|
adapter: Adapter;
|
|
1567
1471
|
} | {
|
|
1568
|
-
|
|
1472
|
+
inputNode?: never;
|
|
1569
1473
|
adapter?: never;
|
|
1570
1474
|
}) & Kubb.PluginContext;
|
|
1571
1475
|
/**
|
|
@@ -1573,12 +1477,12 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1573
1477
|
*
|
|
1574
1478
|
* Generators and the `schema`/`operation`/`operations` plugin hooks are only invoked from
|
|
1575
1479
|
* `runPluginAstHooks`, which already guards against a missing adapter. This type reflects
|
|
1576
|
-
* that guarantee — `this.adapter` and `this.
|
|
1480
|
+
* that guarantee — `this.adapter` and `this.inputNode` are always defined, so no runtime
|
|
1577
1481
|
* checks or casts are needed inside the method bodies.
|
|
1578
1482
|
*/
|
|
1579
|
-
type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Omit<PluginContext<TOptions>, 'adapter' | '
|
|
1483
|
+
type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Omit<PluginContext<TOptions>, 'adapter' | 'inputNode'> & {
|
|
1580
1484
|
adapter: Adapter;
|
|
1581
|
-
|
|
1485
|
+
inputNode: InputNode;
|
|
1582
1486
|
};
|
|
1583
1487
|
/**
|
|
1584
1488
|
* Specify the export location for the files and define the behavior of the output
|
|
@@ -1596,11 +1500,11 @@ type Output<_TOptions = unknown> = {
|
|
|
1596
1500
|
/**
|
|
1597
1501
|
* Add a banner text in the beginning of every file
|
|
1598
1502
|
*/
|
|
1599
|
-
banner?: string | ((node?:
|
|
1503
|
+
banner?: string | ((node?: InputNode) => string);
|
|
1600
1504
|
/**
|
|
1601
1505
|
* Add a footer text in the beginning of every file
|
|
1602
1506
|
*/
|
|
1603
|
-
footer?: string | ((node?:
|
|
1507
|
+
footer?: string | ((node?: InputNode) => string);
|
|
1604
1508
|
/**
|
|
1605
1509
|
* Whether to override existing external files if they already exist.
|
|
1606
1510
|
* @default false
|
|
@@ -1748,8 +1652,8 @@ type ResolvePathOptions = {
|
|
|
1748
1652
|
* ```
|
|
1749
1653
|
*/
|
|
1750
1654
|
type ResolverPathParams = {
|
|
1751
|
-
baseName:
|
|
1752
|
-
pathMode?:
|
|
1655
|
+
baseName: FileNode['baseName'];
|
|
1656
|
+
pathMode?: 'single' | 'split';
|
|
1753
1657
|
/**
|
|
1754
1658
|
* Tag value used when `group.type === 'tag'`.
|
|
1755
1659
|
*/
|
|
@@ -1800,7 +1704,7 @@ type ResolverContext = {
|
|
|
1800
1704
|
*/
|
|
1801
1705
|
type ResolverFileParams = {
|
|
1802
1706
|
name: string;
|
|
1803
|
-
extname:
|
|
1707
|
+
extname: FileNode['extname'];
|
|
1804
1708
|
/**
|
|
1805
1709
|
* Tag value used when `group.type === 'tag'`.
|
|
1806
1710
|
*/
|
|
@@ -1818,7 +1722,7 @@ type ResolverFileParams = {
|
|
|
1818
1722
|
*
|
|
1819
1723
|
* @example
|
|
1820
1724
|
* ```ts
|
|
1821
|
-
* resolver.resolveBanner(
|
|
1725
|
+
* resolver.resolveBanner(inputNode, { output: { banner: '// generated' }, config })
|
|
1822
1726
|
* // → '// generated'
|
|
1823
1727
|
* ```
|
|
1824
1728
|
*/
|
|
@@ -1844,7 +1748,6 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
|
|
|
1844
1748
|
plugin: Plugin;
|
|
1845
1749
|
};
|
|
1846
1750
|
type Options = {
|
|
1847
|
-
fabric: Fabric;
|
|
1848
1751
|
events: AsyncEventEmitter<KubbEvents>;
|
|
1849
1752
|
/**
|
|
1850
1753
|
* @default Number.POSITIVE_INFINITY
|
|
@@ -1856,8 +1759,8 @@ type Options = {
|
|
|
1856
1759
|
*/
|
|
1857
1760
|
type GetFileOptions<TOptions = object> = {
|
|
1858
1761
|
name: string;
|
|
1859
|
-
mode?:
|
|
1860
|
-
extname:
|
|
1762
|
+
mode?: 'single' | 'split';
|
|
1763
|
+
extname: FileNode['extname'];
|
|
1861
1764
|
pluginName: string;
|
|
1862
1765
|
options?: TOptions;
|
|
1863
1766
|
};
|
|
@@ -1870,17 +1773,23 @@ type GetFileOptions<TOptions = object> = {
|
|
|
1870
1773
|
* getMode('src/gen/types') // 'split'
|
|
1871
1774
|
* ```
|
|
1872
1775
|
*/
|
|
1873
|
-
declare function getMode(fileOrFolder: string | undefined | null):
|
|
1776
|
+
declare function getMode(fileOrFolder: string | undefined | null): 'single' | 'split';
|
|
1874
1777
|
declare class PluginDriver {
|
|
1875
1778
|
#private;
|
|
1876
1779
|
readonly config: Config;
|
|
1877
1780
|
readonly options: Options;
|
|
1878
1781
|
/**
|
|
1879
|
-
* The universal `@kubb/ast` `
|
|
1782
|
+
* The universal `@kubb/ast` `InputNode` produced by the adapter, set by
|
|
1880
1783
|
* the build pipeline after the adapter's `parse()` resolves.
|
|
1881
1784
|
*/
|
|
1882
|
-
|
|
1785
|
+
inputNode: InputNode | undefined;
|
|
1883
1786
|
adapter: Adapter | undefined;
|
|
1787
|
+
/**
|
|
1788
|
+
* Central file store for all generated files.
|
|
1789
|
+
* Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to
|
|
1790
|
+
* add files; this property gives direct read/write access when needed.
|
|
1791
|
+
*/
|
|
1792
|
+
readonly fileManager: FileManager;
|
|
1884
1793
|
readonly plugins: Map<string, Plugin>;
|
|
1885
1794
|
constructor(config: Config, options: Options);
|
|
1886
1795
|
get events(): AsyncEventEmitter<KubbEvents>;
|
|
@@ -1894,13 +1803,13 @@ declare class PluginDriver {
|
|
|
1894
1803
|
extname,
|
|
1895
1804
|
pluginName,
|
|
1896
1805
|
options
|
|
1897
|
-
}: GetFileOptions<TOptions>):
|
|
1806
|
+
}: GetFileOptions<TOptions>): FileNode<{
|
|
1898
1807
|
pluginName: string;
|
|
1899
1808
|
}>;
|
|
1900
1809
|
/**
|
|
1901
1810
|
* @deprecated use resolvers context instead
|
|
1902
1811
|
*/
|
|
1903
|
-
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) =>
|
|
1812
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => string;
|
|
1904
1813
|
/**
|
|
1905
1814
|
* @deprecated use resolvers context instead
|
|
1906
1815
|
*/
|
|
@@ -1982,5 +1891,5 @@ declare class PluginDriver {
|
|
|
1982
1891
|
requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>;
|
|
1983
1892
|
}
|
|
1984
1893
|
//#endregion
|
|
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 _,
|
|
1986
|
-
//# sourceMappingURL=PluginDriver-
|
|
1894
|
+
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 _, AdapterSource as a, Parser as at, OperationsHook as b, Config as c, Generator as ct, GeneratorContext as d, Storage as dt, FunctionParamsAST as et, Group as f, createStorage as ft, Logger as g, AsyncEventEmitter 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, PluginContext as w, Output as x, OperationHook as y, ResolvePathParams as z };
|
|
1895
|
+
//# sourceMappingURL=PluginDriver-nm7tvGs9.d.ts.map
|