@kubb/core 5.0.0-alpha.3 → 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-D0dY_hpJ.d.ts +1986 -0
- package/dist/{chunk-ByKO4r7w.cjs → chunk-MlS0t1Af.cjs} +15 -0
- package/dist/chunk-O_arW02_.js +17 -0
- package/dist/hooks.cjs +13 -28
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +11 -37
- package/dist/hooks.js +14 -28
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +1469 -831
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +572 -191
- package/dist/index.js +1443 -826
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/Kubb.ts +38 -56
- package/src/KubbFile.ts +143 -0
- package/src/{PluginManager.ts → PluginDriver.ts} +159 -170
- package/src/build.ts +213 -65
- package/src/constants.ts +39 -6
- package/src/createAdapter.ts +25 -0
- package/src/createPlugin.ts +30 -0
- package/src/createStorage.ts +58 -0
- package/src/{config.ts → defineConfig.ts} +11 -16
- package/src/defineGenerator.ts +126 -0
- package/src/defineLogger.ts +13 -3
- package/src/defineParser.ts +57 -0
- package/src/definePresets.ts +16 -0
- package/src/defineResolver.ts +454 -0
- package/src/hooks/index.ts +1 -6
- package/src/hooks/useDriver.ts +11 -0
- package/src/hooks/useMode.ts +4 -4
- package/src/hooks/usePlugin.ts +3 -3
- package/src/index.ts +22 -10
- package/src/renderNode.tsx +25 -0
- package/src/storages/fsStorage.ts +2 -2
- package/src/storages/memoryStorage.ts +2 -2
- package/src/types.ts +639 -52
- package/src/utils/FunctionParams.ts +2 -2
- package/src/utils/TreeNode.ts +40 -2
- package/src/utils/diagnostics.ts +4 -1
- package/src/utils/executeStrategies.ts +29 -10
- package/src/utils/formatters.ts +10 -21
- package/src/utils/getBarrelFiles.ts +80 -10
- package/src/utils/getConfigs.ts +9 -23
- package/src/utils/getPreset.ts +78 -0
- package/src/utils/isInputPath.ts +8 -0
- package/src/utils/linters.ts +23 -3
- package/src/utils/packageJSON.ts +76 -0
- package/dist/chunk--u3MIqq1.js +0 -8
- package/dist/types-CiPWLv-5.d.ts +0 -1001
- package/src/BarrelManager.ts +0 -74
- package/src/PackageManager.ts +0 -180
- package/src/PromiseManager.ts +0 -40
- package/src/defineAdapter.ts +0 -22
- package/src/definePlugin.ts +0 -12
- package/src/defineStorage.ts +0 -56
- package/src/errors.ts +0 -1
- package/src/hooks/useKubb.ts +0 -22
- package/src/hooks/usePluginManager.ts +0 -11
- package/src/utils/getPlugins.ts +0 -23
|
@@ -0,0 +1,1986 @@
|
|
|
1
|
+
import { n as __name, t as __exportAll } from "./chunk-O_arW02_.js";
|
|
2
|
+
import { Node, OperationNode, Printer, Printer as Printer$1, PrinterFactoryOptions, PrinterPartial, RootNode, SchemaNode, Visitor } from "@kubb/ast/types";
|
|
3
|
+
import { Fabric } from "@kubb/fabric-core/types";
|
|
4
|
+
import { HttpMethod } from "@kubb/oas";
|
|
5
|
+
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
6
|
+
|
|
7
|
+
//#region ../../internals/utils/src/asyncEventEmitter.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* A function that can be registered as an event listener, synchronous or async.
|
|
10
|
+
*/
|
|
11
|
+
type AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Typed `EventEmitter` that awaits all async listeners before resolving.
|
|
14
|
+
* Wraps Node's `EventEmitter` with full TypeScript event-map inference.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const emitter = new AsyncEventEmitter<{ build: [name: string] }>()
|
|
19
|
+
* emitter.on('build', async (name) => { console.log(name) })
|
|
20
|
+
* await emitter.emit('build', 'petstore') // all listeners awaited
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {
|
|
24
|
+
#private;
|
|
25
|
+
/**
|
|
26
|
+
* Maximum number of listeners per event before Node emits a memory-leak warning.
|
|
27
|
+
* @default 10
|
|
28
|
+
*/
|
|
29
|
+
constructor(maxListener?: number);
|
|
30
|
+
/**
|
|
31
|
+
* Emits `eventName` and awaits all registered listeners sequentially.
|
|
32
|
+
* Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* await emitter.emit('build', 'petstore')
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Registers a persistent listener for `eventName`.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* emitter.on('build', async (name) => { console.log(name) })
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
49
|
+
/**
|
|
50
|
+
* Registers a one-shot listener that removes itself after the first invocation.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* emitter.onOnce('build', async (name) => { console.log(name) })
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
58
|
+
/**
|
|
59
|
+
* Removes a previously registered listener.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* emitter.off('build', handler)
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
67
|
+
/**
|
|
68
|
+
* Removes all listeners from every event channel.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* emitter.removeAll()
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
removeAll(): void;
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region ../../internals/utils/src/promise.d.ts
|
|
79
|
+
/** A value that may already be resolved or still pending.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* function load(id: string): PossiblePromise<string> {
|
|
84
|
+
* return cache.get(id) ?? fetchRemote(id)
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
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
|
+
};
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/constants.d.ts
|
|
223
|
+
/**
|
|
224
|
+
* Base URL for the Kubb Studio web app.
|
|
225
|
+
*/
|
|
226
|
+
declare const DEFAULT_STUDIO_URL: "https://studio.kubb.dev";
|
|
227
|
+
/**
|
|
228
|
+
* Numeric log-level thresholds used internally to compare verbosity.
|
|
229
|
+
*
|
|
230
|
+
* Higher numbers are more verbose.
|
|
231
|
+
*/
|
|
232
|
+
declare const logLevel: {
|
|
233
|
+
readonly silent: number;
|
|
234
|
+
readonly error: 0;
|
|
235
|
+
readonly warn: 1;
|
|
236
|
+
readonly info: 3;
|
|
237
|
+
readonly verbose: 4;
|
|
238
|
+
readonly debug: 5;
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* CLI command descriptors for each supported linter.
|
|
242
|
+
*
|
|
243
|
+
* Each entry contains the executable `command`, an `args` factory that maps an
|
|
244
|
+
* output path to the correct argument list, and an `errorMessage` shown when
|
|
245
|
+
* the linter is not found.
|
|
246
|
+
*/
|
|
247
|
+
declare const linters: {
|
|
248
|
+
readonly eslint: {
|
|
249
|
+
readonly command: "eslint";
|
|
250
|
+
readonly args: (outputPath: string) => string[];
|
|
251
|
+
readonly errorMessage: "Eslint not found";
|
|
252
|
+
};
|
|
253
|
+
readonly biome: {
|
|
254
|
+
readonly command: "biome";
|
|
255
|
+
readonly args: (outputPath: string) => string[];
|
|
256
|
+
readonly errorMessage: "Biome not found";
|
|
257
|
+
};
|
|
258
|
+
readonly oxlint: {
|
|
259
|
+
readonly command: "oxlint";
|
|
260
|
+
readonly args: (outputPath: string) => string[];
|
|
261
|
+
readonly errorMessage: "Oxlint not found";
|
|
262
|
+
};
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* CLI command descriptors for each supported code formatter.
|
|
266
|
+
*
|
|
267
|
+
* Each entry contains the executable `command`, an `args` factory that maps an
|
|
268
|
+
* output path to the correct argument list, and an `errorMessage` shown when
|
|
269
|
+
* the formatter is not found.
|
|
270
|
+
*/
|
|
271
|
+
declare const formatters: {
|
|
272
|
+
readonly prettier: {
|
|
273
|
+
readonly command: "prettier";
|
|
274
|
+
readonly args: (outputPath: string) => string[];
|
|
275
|
+
readonly errorMessage: "Prettier not found";
|
|
276
|
+
};
|
|
277
|
+
readonly biome: {
|
|
278
|
+
readonly command: "biome";
|
|
279
|
+
readonly args: (outputPath: string) => string[];
|
|
280
|
+
readonly errorMessage: "Biome not found";
|
|
281
|
+
};
|
|
282
|
+
readonly oxfmt: {
|
|
283
|
+
readonly command: "oxfmt";
|
|
284
|
+
readonly args: (outputPath: string) => string[];
|
|
285
|
+
readonly errorMessage: "Oxfmt not found";
|
|
286
|
+
};
|
|
287
|
+
};
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/createStorage.d.ts
|
|
290
|
+
type Storage = {
|
|
291
|
+
/**
|
|
292
|
+
* Identifier used for logging and debugging (e.g. `'fs'`, `'s3'`).
|
|
293
|
+
*/
|
|
294
|
+
readonly name: string;
|
|
295
|
+
/**
|
|
296
|
+
* Returns `true` when an entry for `key` exists in storage.
|
|
297
|
+
*/
|
|
298
|
+
hasItem(key: string): Promise<boolean>;
|
|
299
|
+
/**
|
|
300
|
+
* Returns the stored string value, or `null` when `key` does not exist.
|
|
301
|
+
*/
|
|
302
|
+
getItem(key: string): Promise<string | null>;
|
|
303
|
+
/**
|
|
304
|
+
* Persists `value` under `key`, creating any required structure.
|
|
305
|
+
*/
|
|
306
|
+
setItem(key: string, value: string): Promise<void>;
|
|
307
|
+
/**
|
|
308
|
+
* Removes the entry for `key`. No-ops when the key does not exist.
|
|
309
|
+
*/
|
|
310
|
+
removeItem(key: string): Promise<void>;
|
|
311
|
+
/**
|
|
312
|
+
* Returns all keys, optionally filtered to those starting with `base`.
|
|
313
|
+
*/
|
|
314
|
+
getKeys(base?: string): Promise<Array<string>>;
|
|
315
|
+
/**
|
|
316
|
+
* Removes all entries, optionally scoped to those starting with `base`.
|
|
317
|
+
*/
|
|
318
|
+
clear(base?: string): Promise<void>;
|
|
319
|
+
/**
|
|
320
|
+
* Optional teardown hook called after the build completes.
|
|
321
|
+
*/
|
|
322
|
+
dispose?(): Promise<void>;
|
|
323
|
+
};
|
|
324
|
+
/**
|
|
325
|
+
* Creates a storage factory. Call the returned function with optional options to get the storage instance.
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* export const memoryStorage = createStorage(() => {
|
|
329
|
+
* const store = new Map<string, string>()
|
|
330
|
+
* return {
|
|
331
|
+
* name: 'memory',
|
|
332
|
+
* async hasItem(key) { return store.has(key) },
|
|
333
|
+
* async getItem(key) { return store.get(key) ?? null },
|
|
334
|
+
* async setItem(key, value) { store.set(key, value) },
|
|
335
|
+
* async removeItem(key) { store.delete(key) },
|
|
336
|
+
* async getKeys(base) {
|
|
337
|
+
* const keys = [...store.keys()]
|
|
338
|
+
* return base ? keys.filter((k) => k.startsWith(base)) : keys
|
|
339
|
+
* },
|
|
340
|
+
* async clear(base) { if (!base) store.clear() },
|
|
341
|
+
* }
|
|
342
|
+
* })
|
|
343
|
+
*/
|
|
344
|
+
declare function createStorage<TOptions = Record<string, never>>(build: (options: TOptions) => Storage): (options?: TOptions) => Storage;
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region src/defineGenerator.d.ts
|
|
347
|
+
/**
|
|
348
|
+
* A generator is a named object with optional `schema`, `operation`, and `operations`
|
|
349
|
+
* methods. Each method is called with `this = PluginContext` of the parent plugin,
|
|
350
|
+
* giving full access to `this.config`, `this.resolver`, `this.adapter`, `this.fabric`,
|
|
351
|
+
* `this.driver`, etc.
|
|
352
|
+
*
|
|
353
|
+
* Return a React element, an array of `KubbFile.File`, or `void` to handle file
|
|
354
|
+
* writing manually via `this.upsertFile`. Both React and core (non-React) generators
|
|
355
|
+
* use the same method signatures — the return type determines how output is handled.
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* ```ts
|
|
359
|
+
* export const typeGenerator = defineGenerator<PluginTs>({
|
|
360
|
+
* name: 'typescript',
|
|
361
|
+
* schema(node, options) {
|
|
362
|
+
* const { adapter, resolver, root } = this
|
|
363
|
+
* return <File ...><Type node={node} resolver={resolver} /></File>
|
|
364
|
+
* },
|
|
365
|
+
* operation(node, options) {
|
|
366
|
+
* return <File ...><OperationType node={node} /></File>
|
|
367
|
+
* },
|
|
368
|
+
* })
|
|
369
|
+
* ```
|
|
370
|
+
*/
|
|
371
|
+
type Generator<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
372
|
+
/** Used in diagnostic messages and debug output. */name: string;
|
|
373
|
+
/**
|
|
374
|
+
* Called for each schema node in the AST walk.
|
|
375
|
+
* `this` is the parent plugin's context with `adapter` and `rootNode` guaranteed present.
|
|
376
|
+
* `options` contains the per-node resolved options (after exclude/include/override).
|
|
377
|
+
*/
|
|
378
|
+
schema?: (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<File> | void>;
|
|
379
|
+
/**
|
|
380
|
+
* Called for each operation node in the AST walk.
|
|
381
|
+
* `this` is the parent plugin's context with `adapter` and `rootNode` guaranteed present.
|
|
382
|
+
*/
|
|
383
|
+
operation?: (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<File> | void>;
|
|
384
|
+
/**
|
|
385
|
+
* Called once after all operations have been walked.
|
|
386
|
+
* `this` is the parent plugin's context with `adapter` and `rootNode` guaranteed present.
|
|
387
|
+
*/
|
|
388
|
+
operations?: (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<File> | void>;
|
|
389
|
+
};
|
|
390
|
+
/**
|
|
391
|
+
* Defines a generator. Returns the object as-is with correct `this` typings.
|
|
392
|
+
* No type discrimination (`type: 'react' | 'core'`) needed — `applyHookResult`
|
|
393
|
+
* handles React elements and `File[]` uniformly.
|
|
394
|
+
*/
|
|
395
|
+
declare function defineGenerator<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(generator: Generator<TOptions>): Generator<TOptions>;
|
|
396
|
+
/**
|
|
397
|
+
* Merges an array of generators into a single generator.
|
|
398
|
+
*
|
|
399
|
+
* The merged generator's `schema`, `operation`, and `operations` methods run
|
|
400
|
+
* the corresponding method from each input generator in sequence, applying each
|
|
401
|
+
* result via `applyHookResult`. This eliminates the need to write the loop
|
|
402
|
+
* manually in each plugin.
|
|
403
|
+
*
|
|
404
|
+
* @param generators - Array of generators to merge into a single generator.
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```ts
|
|
408
|
+
* const merged = mergeGenerators(generators)
|
|
409
|
+
*
|
|
410
|
+
* return {
|
|
411
|
+
* name: pluginName,
|
|
412
|
+
* schema: merged.schema,
|
|
413
|
+
* operation: merged.operation,
|
|
414
|
+
* operations: merged.operations,
|
|
415
|
+
* }
|
|
416
|
+
* ```
|
|
417
|
+
*/
|
|
418
|
+
declare function mergeGenerators<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(generators: Array<Generator<TOptions>>): Generator<TOptions>;
|
|
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
|
|
468
|
+
//#region src/Kubb.d.ts
|
|
469
|
+
type DebugInfo = {
|
|
470
|
+
date: Date;
|
|
471
|
+
logs: Array<string>;
|
|
472
|
+
fileName?: string;
|
|
473
|
+
};
|
|
474
|
+
type HookProgress<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
475
|
+
hookName: H;
|
|
476
|
+
plugins: Array<Plugin>;
|
|
477
|
+
};
|
|
478
|
+
type HookExecution<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
479
|
+
strategy: Strategy;
|
|
480
|
+
hookName: H;
|
|
481
|
+
plugin: Plugin;
|
|
482
|
+
parameters?: Array<unknown>;
|
|
483
|
+
output?: unknown;
|
|
484
|
+
};
|
|
485
|
+
type HookResult<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
486
|
+
duration: number;
|
|
487
|
+
strategy: Strategy;
|
|
488
|
+
hookName: H;
|
|
489
|
+
plugin: Plugin;
|
|
490
|
+
parameters?: Array<unknown>;
|
|
491
|
+
output?: unknown;
|
|
492
|
+
};
|
|
493
|
+
/**
|
|
494
|
+
* Events emitted during the Kubb code generation lifecycle.
|
|
495
|
+
* These events can be listened to for logging, progress tracking, and custom integrations.
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
* ```typescript
|
|
499
|
+
* import type { AsyncEventEmitter } from '@internals/utils'
|
|
500
|
+
* import type { KubbEvents } from '@kubb/core'
|
|
501
|
+
*
|
|
502
|
+
* const events: AsyncEventEmitter<KubbEvents> = new AsyncEventEmitter()
|
|
503
|
+
*
|
|
504
|
+
* events.on('lifecycle:start', () => {
|
|
505
|
+
* console.log('Starting Kubb generation')
|
|
506
|
+
* })
|
|
507
|
+
*
|
|
508
|
+
* events.on('plugin:end', (plugin, { duration }) => {
|
|
509
|
+
* console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
|
|
510
|
+
* })
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
513
|
+
interface KubbEvents {
|
|
514
|
+
/**
|
|
515
|
+
* Emitted at the beginning of the Kubb lifecycle, before any code generation starts.
|
|
516
|
+
*/
|
|
517
|
+
'lifecycle:start': [version: string];
|
|
518
|
+
/**
|
|
519
|
+
* Emitted at the end of the Kubb lifecycle, after all code generation is complete.
|
|
520
|
+
*/
|
|
521
|
+
'lifecycle:end': [];
|
|
522
|
+
/**
|
|
523
|
+
* Emitted when configuration loading starts.
|
|
524
|
+
*/
|
|
525
|
+
'config:start': [];
|
|
526
|
+
/**
|
|
527
|
+
* Emitted when configuration loading is complete.
|
|
528
|
+
*/
|
|
529
|
+
'config:end': [configs: Array<Config>];
|
|
530
|
+
/**
|
|
531
|
+
* Emitted when code generation phase starts.
|
|
532
|
+
*/
|
|
533
|
+
'generation:start': [config: Config];
|
|
534
|
+
/**
|
|
535
|
+
* Emitted when code generation phase completes.
|
|
536
|
+
*/
|
|
537
|
+
'generation:end': [config: Config, files: Array<ResolvedFile>, sources: Map<Path, string>];
|
|
538
|
+
/**
|
|
539
|
+
* Emitted with a summary of the generation results.
|
|
540
|
+
* Contains summary lines, title, and success status.
|
|
541
|
+
*/
|
|
542
|
+
'generation:summary': [config: Config, {
|
|
543
|
+
failedPlugins: Set<{
|
|
544
|
+
plugin: Plugin;
|
|
545
|
+
error: Error;
|
|
546
|
+
}>;
|
|
547
|
+
status: 'success' | 'failed';
|
|
548
|
+
hrStart: [number, number];
|
|
549
|
+
filesCreated: number;
|
|
550
|
+
pluginTimings?: Map<Plugin['name'], number>;
|
|
551
|
+
}];
|
|
552
|
+
/**
|
|
553
|
+
* Emitted when code formatting starts (e.g., running Biome or Prettier).
|
|
554
|
+
*/
|
|
555
|
+
'format:start': [];
|
|
556
|
+
/**
|
|
557
|
+
* Emitted when code formatting completes.
|
|
558
|
+
*/
|
|
559
|
+
'format:end': [];
|
|
560
|
+
/**
|
|
561
|
+
* Emitted when linting starts.
|
|
562
|
+
*/
|
|
563
|
+
'lint:start': [];
|
|
564
|
+
/**
|
|
565
|
+
* Emitted when linting completes.
|
|
566
|
+
*/
|
|
567
|
+
'lint:end': [];
|
|
568
|
+
/**
|
|
569
|
+
* Emitted when plugin hooks execution starts.
|
|
570
|
+
*/
|
|
571
|
+
'hooks:start': [];
|
|
572
|
+
/**
|
|
573
|
+
* Emitted when plugin hooks execution completes.
|
|
574
|
+
*/
|
|
575
|
+
'hooks:end': [];
|
|
576
|
+
/**
|
|
577
|
+
* Emitted when a single hook execution starts (e.g., format or lint).
|
|
578
|
+
* The callback should be invoked when the command completes.
|
|
579
|
+
*/
|
|
580
|
+
'hook:start': [{
|
|
581
|
+
id?: string;
|
|
582
|
+
command: string;
|
|
583
|
+
args?: readonly string[];
|
|
584
|
+
}];
|
|
585
|
+
/**
|
|
586
|
+
* Emitted when a single hook execution completes.
|
|
587
|
+
*/
|
|
588
|
+
'hook:end': [{
|
|
589
|
+
id?: string;
|
|
590
|
+
command: string;
|
|
591
|
+
args?: readonly string[];
|
|
592
|
+
success: boolean;
|
|
593
|
+
error: Error | null;
|
|
594
|
+
}];
|
|
595
|
+
/**
|
|
596
|
+
* Emitted when a new version of Kubb is available.
|
|
597
|
+
*/
|
|
598
|
+
'version:new': [currentVersion: string, latestVersion: string];
|
|
599
|
+
/**
|
|
600
|
+
* Informational message event.
|
|
601
|
+
*/
|
|
602
|
+
info: [message: string, info?: string];
|
|
603
|
+
/**
|
|
604
|
+
* Error event. Emitted when an error occurs during code generation.
|
|
605
|
+
*/
|
|
606
|
+
error: [error: Error, meta?: Record<string, unknown>];
|
|
607
|
+
/**
|
|
608
|
+
* Success message event.
|
|
609
|
+
*/
|
|
610
|
+
success: [message: string, info?: string];
|
|
611
|
+
/**
|
|
612
|
+
* Warning message event.
|
|
613
|
+
*/
|
|
614
|
+
warn: [message: string, info?: string];
|
|
615
|
+
/**
|
|
616
|
+
* Debug event for detailed logging.
|
|
617
|
+
* Contains timestamp, log messages, and optional filename.
|
|
618
|
+
*/
|
|
619
|
+
debug: [info: DebugInfo];
|
|
620
|
+
/**
|
|
621
|
+
* Emitted when file processing starts.
|
|
622
|
+
* Contains the list of files to be processed.
|
|
623
|
+
*/
|
|
624
|
+
'files:processing:start': [files: Array<ResolvedFile>];
|
|
625
|
+
/**
|
|
626
|
+
* Emitted for each file being processed, providing progress updates.
|
|
627
|
+
* Contains processed count, total count, percentage, and file details.
|
|
628
|
+
*/
|
|
629
|
+
'file:processing:update': [{
|
|
630
|
+
/**
|
|
631
|
+
* Number of files processed so far.
|
|
632
|
+
*/
|
|
633
|
+
processed: number;
|
|
634
|
+
/**
|
|
635
|
+
* Total number of files to process.
|
|
636
|
+
*/
|
|
637
|
+
total: number;
|
|
638
|
+
/**
|
|
639
|
+
* Processing percentage (0–100).
|
|
640
|
+
*/
|
|
641
|
+
percentage: number;
|
|
642
|
+
/**
|
|
643
|
+
* Optional source identifier.
|
|
644
|
+
*/
|
|
645
|
+
source?: string;
|
|
646
|
+
/**
|
|
647
|
+
* The file being processed.
|
|
648
|
+
*/
|
|
649
|
+
file: ResolvedFile;
|
|
650
|
+
/**
|
|
651
|
+
* Kubb configuration (not present in Fabric).
|
|
652
|
+
* Provides access to the current config during file processing.
|
|
653
|
+
*/
|
|
654
|
+
config: Config;
|
|
655
|
+
}];
|
|
656
|
+
/**
|
|
657
|
+
* Emitted when file processing completes.
|
|
658
|
+
* Contains the list of processed files.
|
|
659
|
+
*/
|
|
660
|
+
'files:processing:end': [files: Array<ResolvedFile>];
|
|
661
|
+
/**
|
|
662
|
+
* Emitted when a plugin starts executing.
|
|
663
|
+
*/
|
|
664
|
+
'plugin:start': [plugin: Plugin];
|
|
665
|
+
/**
|
|
666
|
+
* Emitted when a plugin completes execution.
|
|
667
|
+
* Duration in ms.
|
|
668
|
+
*/
|
|
669
|
+
'plugin:end': [plugin: Plugin, result: {
|
|
670
|
+
duration: number;
|
|
671
|
+
success: boolean;
|
|
672
|
+
error?: Error;
|
|
673
|
+
}];
|
|
674
|
+
/**
|
|
675
|
+
* Emitted when plugin hook progress tracking starts.
|
|
676
|
+
* Contains the hook name and list of plugins to execute.
|
|
677
|
+
*/
|
|
678
|
+
'plugins:hook:progress:start': [progress: HookProgress];
|
|
679
|
+
/**
|
|
680
|
+
* Emitted when plugin hook progress tracking ends.
|
|
681
|
+
* Contains the hook name that completed.
|
|
682
|
+
*/
|
|
683
|
+
'plugins:hook:progress:end': [{
|
|
684
|
+
hookName: PluginLifecycleHooks;
|
|
685
|
+
}];
|
|
686
|
+
/**
|
|
687
|
+
* Emitted when a plugin hook starts processing.
|
|
688
|
+
* Contains strategy, hook name, plugin, parameters, and output.
|
|
689
|
+
*/
|
|
690
|
+
'plugins:hook:processing:start': [execution: HookExecution];
|
|
691
|
+
/**
|
|
692
|
+
* Emitted when a plugin hook completes processing.
|
|
693
|
+
* Contains duration, strategy, hook name, plugin, parameters, and output.
|
|
694
|
+
*/
|
|
695
|
+
'plugins:hook:processing:end': [result: HookResult];
|
|
696
|
+
}
|
|
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
|
|
824
|
+
//#region src/types.d.ts
|
|
825
|
+
declare global {
|
|
826
|
+
namespace Kubb {
|
|
827
|
+
interface PluginContext {}
|
|
828
|
+
/**
|
|
829
|
+
* Registry that maps plugin names to their `PluginFactoryOptions`.
|
|
830
|
+
* Augment this interface in each plugin's `types.ts` to enable automatic
|
|
831
|
+
* typing for `getPlugin` and `requirePlugin`.
|
|
832
|
+
*
|
|
833
|
+
* @example
|
|
834
|
+
* ```ts
|
|
835
|
+
* // packages/plugin-ts/src/types.ts
|
|
836
|
+
* declare global {
|
|
837
|
+
* namespace Kubb {
|
|
838
|
+
* interface PluginRegistry {
|
|
839
|
+
* 'plugin-ts': PluginTs
|
|
840
|
+
* }
|
|
841
|
+
* }
|
|
842
|
+
* }
|
|
843
|
+
* ```
|
|
844
|
+
*/
|
|
845
|
+
interface PluginRegistry {}
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Config used in `kubb.config.ts`
|
|
850
|
+
*
|
|
851
|
+
* @example
|
|
852
|
+
* import { defineConfig } from '@kubb/core'
|
|
853
|
+
* export default defineConfig({
|
|
854
|
+
* ...
|
|
855
|
+
* })
|
|
856
|
+
*/
|
|
857
|
+
type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter'> & {
|
|
858
|
+
/**
|
|
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.
|
|
860
|
+
* @default process.cwd()
|
|
861
|
+
*/
|
|
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;
|
|
894
|
+
/**
|
|
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.
|
|
896
|
+
*/
|
|
897
|
+
plugins?: Array<Omit<UnknownUserPlugin, 'inject'>>;
|
|
898
|
+
};
|
|
899
|
+
type InputPath = {
|
|
900
|
+
/**
|
|
901
|
+
* Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
|
|
902
|
+
*/
|
|
903
|
+
path: string;
|
|
904
|
+
};
|
|
905
|
+
type InputData = {
|
|
906
|
+
/**
|
|
907
|
+
* A `string` or `object` that contains your Swagger/OpenAPI data.
|
|
908
|
+
*/
|
|
909
|
+
data: string | unknown;
|
|
910
|
+
};
|
|
911
|
+
type Input = InputPath | InputData;
|
|
912
|
+
/**
|
|
913
|
+
* The raw source passed to an adapter's `parse` function.
|
|
914
|
+
* Mirrors the shape of `Config['input']` with paths already resolved to absolute.
|
|
915
|
+
*/
|
|
916
|
+
type AdapterSource = {
|
|
917
|
+
type: 'path';
|
|
918
|
+
path: string;
|
|
919
|
+
} | {
|
|
920
|
+
type: 'data';
|
|
921
|
+
data: string | unknown;
|
|
922
|
+
} | {
|
|
923
|
+
type: 'paths';
|
|
924
|
+
paths: Array<string>;
|
|
925
|
+
};
|
|
926
|
+
/**
|
|
927
|
+
* Type parameters for an adapter definition.
|
|
928
|
+
*
|
|
929
|
+
* Mirrors `PluginFactoryOptions` but scoped to the adapter lifecycle:
|
|
930
|
+
* - `TName` — unique string identifier (e.g. `'oas'`, `'asyncapi'`)
|
|
931
|
+
* - `TOptions` — raw user-facing options passed to the adapter factory
|
|
932
|
+
* - `TResolvedOptions` — defaults applied; what the adapter stores as `options`
|
|
933
|
+
* - `TDocument` — type of the raw source document exposed by the adapter after `parse()`
|
|
934
|
+
*/
|
|
935
|
+
type AdapterFactoryOptions<TName extends string = string, TOptions extends object = object, TResolvedOptions extends object = TOptions, TDocument = unknown> = {
|
|
936
|
+
name: TName;
|
|
937
|
+
options: TOptions;
|
|
938
|
+
resolvedOptions: TResolvedOptions;
|
|
939
|
+
document: TDocument;
|
|
940
|
+
};
|
|
941
|
+
/**
|
|
942
|
+
* An adapter converts a source file or data into a `@kubb/ast` `RootNode`.
|
|
943
|
+
*
|
|
944
|
+
* Adapters are the single entry-point for different schema formats
|
|
945
|
+
* (OpenAPI, AsyncAPI, Drizzle, …) and produce the universal `RootNode`
|
|
946
|
+
* that all Kubb plugins consume.
|
|
947
|
+
*
|
|
948
|
+
* @example
|
|
949
|
+
* ```ts
|
|
950
|
+
* import { oasAdapter } from '@kubb/adapter-oas'
|
|
951
|
+
*
|
|
952
|
+
* export default defineConfig({
|
|
953
|
+
* adapter: adapterOas(), // default — OpenAPI / Swagger
|
|
954
|
+
* input: { path: './openapi.yaml' },
|
|
955
|
+
* plugins: [pluginTs(), pluginZod()],
|
|
956
|
+
* })
|
|
957
|
+
* ```
|
|
958
|
+
*/
|
|
959
|
+
type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
960
|
+
/**
|
|
961
|
+
* Human-readable identifier, e.g. `'oas'`, `'drizzle'`, `'asyncapi'`.
|
|
962
|
+
*/
|
|
963
|
+
name: TOptions['name'];
|
|
964
|
+
/**
|
|
965
|
+
* Resolved options (after defaults have been applied).
|
|
966
|
+
*/
|
|
967
|
+
options: TOptions['resolvedOptions'];
|
|
968
|
+
/**
|
|
969
|
+
* The raw source document produced after the first `parse()` call.
|
|
970
|
+
* `undefined` before parsing; typed by the adapter's `TDocument` generic.
|
|
971
|
+
*/
|
|
972
|
+
document: TOptions['document'] | null;
|
|
973
|
+
rootNode: RootNode | null;
|
|
974
|
+
/**
|
|
975
|
+
* Convert the raw source into a universal `RootNode`.
|
|
976
|
+
*/
|
|
977
|
+
parse: (source: AdapterSource) => PossiblePromise<RootNode>;
|
|
978
|
+
/**
|
|
979
|
+
* Extracts `KubbFile.Import` entries needed by a `SchemaNode` tree.
|
|
980
|
+
* Populated after the first `parse()` call. Returns an empty array before that.
|
|
981
|
+
*
|
|
982
|
+
* The `resolve` callback receives the collision-corrected schema name and must
|
|
983
|
+
* return the `{ name, path }` pair for the import, or `undefined` to skip it.
|
|
984
|
+
*/
|
|
985
|
+
getImports: (node: SchemaNode, resolve: (schemaName: string) => {
|
|
986
|
+
name: string;
|
|
987
|
+
path: string;
|
|
988
|
+
}) => Array<Import>;
|
|
989
|
+
};
|
|
990
|
+
type BarrelType = 'all' | 'named' | 'propagate';
|
|
991
|
+
type DevtoolsOptions = {
|
|
992
|
+
/**
|
|
993
|
+
* Open the AST inspector view (`/ast`) in Kubb Studio.
|
|
994
|
+
* When `false`, opens the main Studio page instead.
|
|
995
|
+
* @default false
|
|
996
|
+
*/
|
|
997
|
+
ast?: boolean;
|
|
998
|
+
};
|
|
999
|
+
/**
|
|
1000
|
+
* @private
|
|
1001
|
+
*/
|
|
1002
|
+
type Config<TInput = Input> = {
|
|
1003
|
+
/**
|
|
1004
|
+
* The name to display in the CLI output.
|
|
1005
|
+
*/
|
|
1006
|
+
name?: string;
|
|
1007
|
+
/**
|
|
1008
|
+
* The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
|
|
1009
|
+
* @default process.cwd()
|
|
1010
|
+
*/
|
|
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>;
|
|
1030
|
+
/**
|
|
1031
|
+
* Adapter that converts the input file into a `@kubb/ast` `RootNode` — the universal
|
|
1032
|
+
* intermediate representation consumed by all Kubb plugins.
|
|
1033
|
+
*
|
|
1034
|
+
* - Use `@kubb/adapter-oas` for OpenAPI / Swagger.
|
|
1035
|
+
* - Use `@kubb/adapter-drizzle` or `@kubb/adapter-asyncapi` for other formats.
|
|
1036
|
+
*
|
|
1037
|
+
* @example
|
|
1038
|
+
* ```ts
|
|
1039
|
+
* import { adapterOas } from '@kubb/adapter-oas'
|
|
1040
|
+
* export default defineConfig({
|
|
1041
|
+
* adapter: adapterOas(),
|
|
1042
|
+
* input: { path: './petStore.yaml' },
|
|
1043
|
+
* })
|
|
1044
|
+
* ```
|
|
1045
|
+
*/
|
|
1046
|
+
adapter: Adapter;
|
|
1047
|
+
/**
|
|
1048
|
+
* You can use either `input.path` or `input.data`, depending on your specific needs.
|
|
1049
|
+
*/
|
|
1050
|
+
input: TInput;
|
|
1051
|
+
output: {
|
|
1052
|
+
/**
|
|
1053
|
+
* The path where all generated files receives exported.
|
|
1054
|
+
* This can be an absolute path or a path relative to the specified root option.
|
|
1055
|
+
*/
|
|
1056
|
+
path: string;
|
|
1057
|
+
/**
|
|
1058
|
+
* Clean the output directory before each build.
|
|
1059
|
+
*/
|
|
1060
|
+
clean?: boolean;
|
|
1061
|
+
/**
|
|
1062
|
+
* Save files to the file system.
|
|
1063
|
+
* @default true
|
|
1064
|
+
* @deprecated Use `storage` to control where files are written.
|
|
1065
|
+
*/
|
|
1066
|
+
write?: boolean;
|
|
1067
|
+
/**
|
|
1068
|
+
* Storage backend for generated files.
|
|
1069
|
+
* Defaults to `fsStorage()` — the built-in filesystem driver.
|
|
1070
|
+
* Accepts any object implementing the {@link Storage} interface.
|
|
1071
|
+
* Keys are root-relative paths (e.g. `src/gen/api/getPets.ts`).
|
|
1072
|
+
* @default fsStorage()
|
|
1073
|
+
* @example
|
|
1074
|
+
* ```ts
|
|
1075
|
+
* import { memoryStorage } from '@kubb/core'
|
|
1076
|
+
* storage: memoryStorage()
|
|
1077
|
+
* ```
|
|
1078
|
+
*/
|
|
1079
|
+
storage?: Storage;
|
|
1080
|
+
/**
|
|
1081
|
+
* Specifies the formatting tool to be used.
|
|
1082
|
+
* - 'auto' automatically detects and uses biome or prettier (in that order of preference).
|
|
1083
|
+
* - 'prettier' uses Prettier for code formatting.
|
|
1084
|
+
* - 'biome' uses Biome for code formatting.
|
|
1085
|
+
* - 'oxfmt' uses Oxfmt for code formatting.
|
|
1086
|
+
* - false disables code formatting.
|
|
1087
|
+
* @default 'prettier'
|
|
1088
|
+
*/
|
|
1089
|
+
format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false;
|
|
1090
|
+
/**
|
|
1091
|
+
* Specifies the linter that should be used to analyze the code.
|
|
1092
|
+
* - 'auto' automatically detects and uses biome, oxlint, or eslint (in that order of preference).
|
|
1093
|
+
* - 'eslint' uses ESLint for linting.
|
|
1094
|
+
* - 'biome' uses Biome for linting.
|
|
1095
|
+
* - 'oxlint' uses Oxlint for linting.
|
|
1096
|
+
* - false disables linting.
|
|
1097
|
+
* @default 'auto'
|
|
1098
|
+
*/
|
|
1099
|
+
lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false;
|
|
1100
|
+
/**
|
|
1101
|
+
* Overrides the extension for generated imports and exports. By default, each plugin adds an extension.
|
|
1102
|
+
* @default { '.ts': '.ts'}
|
|
1103
|
+
*/
|
|
1104
|
+
extension?: Record<Extname, Extname | ''>;
|
|
1105
|
+
/**
|
|
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`).
|
|
1107
|
+
* @default 'named'
|
|
1108
|
+
*/
|
|
1109
|
+
barrelType?: 'all' | 'named' | false;
|
|
1110
|
+
/**
|
|
1111
|
+
* Adds a default banner to the start of every generated file indicating it was generated by Kubb.
|
|
1112
|
+
* - 'simple' adds banner with link to Kubb.
|
|
1113
|
+
* - 'full' adds source, title, description, and OpenAPI version.
|
|
1114
|
+
* - false disables banner generation.
|
|
1115
|
+
* @default 'simple'
|
|
1116
|
+
*/
|
|
1117
|
+
defaultBanner?: 'simple' | 'full' | false;
|
|
1118
|
+
/**
|
|
1119
|
+
* Whether to override existing external files if they already exist.
|
|
1120
|
+
* When setting the option in the global configuration, all plugins inherit the same behavior by default.
|
|
1121
|
+
* However, all plugins also have an `output.override` option, which can be used to override the behavior for a specific plugin.
|
|
1122
|
+
* @default false
|
|
1123
|
+
*/
|
|
1124
|
+
override?: boolean;
|
|
1125
|
+
};
|
|
1126
|
+
/**
|
|
1127
|
+
* An array of Kubb plugins that used in the generation.
|
|
1128
|
+
* Each plugin may include additional configurable options(defined in the plugin itself).
|
|
1129
|
+
* If a plugin depends on another plugin, an error is returned if the required dependency is missing. See pre for more details.
|
|
1130
|
+
*/
|
|
1131
|
+
plugins: Array<Plugin>;
|
|
1132
|
+
/**
|
|
1133
|
+
* Devtools configuration for Kubb Studio integration.
|
|
1134
|
+
*/
|
|
1135
|
+
devtools?: true | {
|
|
1136
|
+
/**
|
|
1137
|
+
* Override the Kubb Studio base URL.
|
|
1138
|
+
* @default 'https://studio.kubb.dev'
|
|
1139
|
+
*/
|
|
1140
|
+
studioUrl?: typeof DEFAULT_STUDIO_URL | (string & {});
|
|
1141
|
+
};
|
|
1142
|
+
/**
|
|
1143
|
+
* Hooks triggered when a specific action occurs in Kubb.
|
|
1144
|
+
*/
|
|
1145
|
+
hooks?: {
|
|
1146
|
+
/**
|
|
1147
|
+
* Hook that triggers at the end of all executions.
|
|
1148
|
+
* Useful for running Prettier or ESLint to format/lint your code.
|
|
1149
|
+
*/
|
|
1150
|
+
done?: string | Array<string>;
|
|
1151
|
+
};
|
|
1152
|
+
};
|
|
1153
|
+
/**
|
|
1154
|
+
* A type/string-pattern filter used for `include`, `exclude`, and `override` matching.
|
|
1155
|
+
*/
|
|
1156
|
+
type PatternFilter = {
|
|
1157
|
+
type: string;
|
|
1158
|
+
pattern: string | RegExp;
|
|
1159
|
+
};
|
|
1160
|
+
/**
|
|
1161
|
+
* A pattern filter paired with partial option overrides to apply when the pattern matches.
|
|
1162
|
+
*/
|
|
1163
|
+
type PatternOverride<TOptions> = PatternFilter & {
|
|
1164
|
+
options: Omit<Partial<TOptions>, 'override'>;
|
|
1165
|
+
};
|
|
1166
|
+
/**
|
|
1167
|
+
* Context passed to `resolver.resolveOptions` to apply include/exclude/override filtering
|
|
1168
|
+
* for a given operation or schema node.
|
|
1169
|
+
*/
|
|
1170
|
+
type ResolveOptionsContext<TOptions> = {
|
|
1171
|
+
options: TOptions;
|
|
1172
|
+
exclude?: Array<PatternFilter>;
|
|
1173
|
+
include?: Array<PatternFilter>;
|
|
1174
|
+
override?: Array<PatternOverride<TOptions>>;
|
|
1175
|
+
};
|
|
1176
|
+
/**
|
|
1177
|
+
* Base constraint for all plugin resolver objects.
|
|
1178
|
+
*
|
|
1179
|
+
* `default`, `resolveOptions`, `resolvePath`, and `resolveFile` are injected automatically
|
|
1180
|
+
* by `defineResolver` — plugin authors may override them but never need to implement them
|
|
1181
|
+
* from scratch.
|
|
1182
|
+
*
|
|
1183
|
+
* @example
|
|
1184
|
+
* ```ts
|
|
1185
|
+
* type MyResolver = Resolver & {
|
|
1186
|
+
* resolveName(node: SchemaNode): string
|
|
1187
|
+
* resolveTypedName(node: SchemaNode): string
|
|
1188
|
+
* }
|
|
1189
|
+
* ```
|
|
1190
|
+
*/
|
|
1191
|
+
type Resolver = {
|
|
1192
|
+
name: string;
|
|
1193
|
+
pluginName: Plugin['name'];
|
|
1194
|
+
default(name: ResolveNameParams['name'], type?: ResolveNameParams['type']): string;
|
|
1195
|
+
resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null;
|
|
1196
|
+
resolvePath(params: ResolverPathParams, context: ResolverContext): Path;
|
|
1197
|
+
resolveFile(params: ResolverFileParams, context: ResolverContext): File;
|
|
1198
|
+
resolveBanner(node: RootNode | null, context: ResolveBannerContext): string | undefined;
|
|
1199
|
+
resolveFooter(node: RootNode | null, context: ResolveBannerContext): string | undefined;
|
|
1200
|
+
};
|
|
1201
|
+
/**
|
|
1202
|
+
* The user-facing subset of a `Resolver` — everything except the four methods injected by
|
|
1203
|
+
* `defineResolver` (`default`, `resolveOptions`, `resolvePath`, and `resolveFile`).
|
|
1204
|
+
*
|
|
1205
|
+
* All four injected methods can still be overridden by providing them explicitly in the builder.
|
|
1206
|
+
*
|
|
1207
|
+
* @example
|
|
1208
|
+
* ```ts
|
|
1209
|
+
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
1210
|
+
* name: 'default',
|
|
1211
|
+
* resolveName(node) { return this.default(node.name, 'function') },
|
|
1212
|
+
* }))
|
|
1213
|
+
* ```
|
|
1214
|
+
*/
|
|
1215
|
+
type UserResolver = Omit<Resolver, 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>;
|
|
1216
|
+
type PluginFactoryOptions<
|
|
1217
|
+
/**
|
|
1218
|
+
* Name to be used for the plugin.
|
|
1219
|
+
*/
|
|
1220
|
+
TName extends string = string,
|
|
1221
|
+
/**
|
|
1222
|
+
* Options of the plugin.
|
|
1223
|
+
*/
|
|
1224
|
+
TOptions extends object = object,
|
|
1225
|
+
/**
|
|
1226
|
+
* Options of the plugin that can be used later on, see `options` inside your plugin config.
|
|
1227
|
+
*/
|
|
1228
|
+
TResolvedOptions extends object = TOptions,
|
|
1229
|
+
/**
|
|
1230
|
+
* Context that you want to expose to other plugins.
|
|
1231
|
+
*/
|
|
1232
|
+
TContext = unknown,
|
|
1233
|
+
/**
|
|
1234
|
+
* When calling `resolvePath` you can specify better types.
|
|
1235
|
+
*/
|
|
1236
|
+
TResolvePathOptions extends object = object,
|
|
1237
|
+
/**
|
|
1238
|
+
* Resolver object that encapsulates the naming and path-resolution helpers used by this plugin.
|
|
1239
|
+
* Use `defineResolver` to define the resolver object and export it alongside the plugin.
|
|
1240
|
+
*/
|
|
1241
|
+
TResolver extends Resolver = Resolver> = {
|
|
1242
|
+
name: TName;
|
|
1243
|
+
options: TOptions;
|
|
1244
|
+
resolvedOptions: TResolvedOptions;
|
|
1245
|
+
context: TContext;
|
|
1246
|
+
resolvePathOptions: TResolvePathOptions;
|
|
1247
|
+
resolver: TResolver;
|
|
1248
|
+
};
|
|
1249
|
+
type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1250
|
+
/**
|
|
1251
|
+
* Unique name used for the plugin
|
|
1252
|
+
* The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
|
|
1253
|
+
* @example @kubb/typescript
|
|
1254
|
+
*/
|
|
1255
|
+
name: TOptions['name'];
|
|
1256
|
+
/**
|
|
1257
|
+
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
1258
|
+
*/
|
|
1259
|
+
options: TOptions['resolvedOptions'] & {
|
|
1260
|
+
output: Output;
|
|
1261
|
+
include?: Array<Include>;
|
|
1262
|
+
exclude: Array<Exclude>;
|
|
1263
|
+
override: Array<Override<TOptions['resolvedOptions']>>;
|
|
1264
|
+
};
|
|
1265
|
+
/**
|
|
1266
|
+
* The resolver for this plugin.
|
|
1267
|
+
* Composed by `getPreset` from the preset resolver and the user's `resolver` partial override.
|
|
1268
|
+
*/
|
|
1269
|
+
resolver?: TOptions['resolver'];
|
|
1270
|
+
/**
|
|
1271
|
+
* The composed transformer for this plugin.
|
|
1272
|
+
* Composed by `getPreset` from the preset's transformers and the user's `transformer` visitor.
|
|
1273
|
+
* When a visitor method returns `null`/`undefined`, the preset transformer's result is used instead.
|
|
1274
|
+
*/
|
|
1275
|
+
transformer?: Visitor;
|
|
1276
|
+
/**
|
|
1277
|
+
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins.
|
|
1278
|
+
* Can be used to validate dependent plugins.
|
|
1279
|
+
*/
|
|
1280
|
+
pre?: Array<string>;
|
|
1281
|
+
/**
|
|
1282
|
+
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins.
|
|
1283
|
+
*/
|
|
1284
|
+
post?: Array<string>;
|
|
1285
|
+
/**
|
|
1286
|
+
* When `apply` is defined, the plugin is only activated when `apply(config)` returns `true`.
|
|
1287
|
+
* Inspired by Vite's `apply` option.
|
|
1288
|
+
*
|
|
1289
|
+
* @example
|
|
1290
|
+
* ```ts
|
|
1291
|
+
* apply: (config) => config.output.path !== 'disabled'
|
|
1292
|
+
* ```
|
|
1293
|
+
*/
|
|
1294
|
+
apply?: (config: Config) => boolean;
|
|
1295
|
+
/**
|
|
1296
|
+
* Expose shared helpers or data to all other plugins via `PluginContext`.
|
|
1297
|
+
* The object returned is merged into the context that every plugin receives.
|
|
1298
|
+
* Use the `declare global { namespace Kubb { interface PluginContext { … } } }` pattern
|
|
1299
|
+
* to make the injected properties type-safe.
|
|
1300
|
+
*
|
|
1301
|
+
* @example
|
|
1302
|
+
* ```ts
|
|
1303
|
+
* inject() {
|
|
1304
|
+
* return { getOas: () => parseSpec(this.config) }
|
|
1305
|
+
* }
|
|
1306
|
+
* // Other plugins can then call `this.getOas()` inside buildStart()
|
|
1307
|
+
* ```
|
|
1308
|
+
*/
|
|
1309
|
+
inject?: (this: PluginContext<TOptions>) => TOptions['context'];
|
|
1310
|
+
};
|
|
1311
|
+
type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
1312
|
+
type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<string, object, object, unknown, object>>;
|
|
1313
|
+
/**
|
|
1314
|
+
* Handler for a single schema node. Used by the `schema` hook on a plugin.
|
|
1315
|
+
*/
|
|
1316
|
+
type SchemaHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<File> | void>;
|
|
1317
|
+
/**
|
|
1318
|
+
* Handler for a single operation node. Used by the `operation` hook on a plugin.
|
|
1319
|
+
*/
|
|
1320
|
+
type OperationHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<File> | void>;
|
|
1321
|
+
/**
|
|
1322
|
+
* Handler for all collected operation nodes. Used by the `operations` hook on a plugin.
|
|
1323
|
+
*/
|
|
1324
|
+
type OperationsHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<FabricReactNode | Array<File> | void>;
|
|
1325
|
+
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1326
|
+
/**
|
|
1327
|
+
* Unique name used for the plugin
|
|
1328
|
+
* @example @kubb/typescript
|
|
1329
|
+
*/
|
|
1330
|
+
name: TOptions['name'];
|
|
1331
|
+
/**
|
|
1332
|
+
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins.
|
|
1333
|
+
* Can be used to validate dependent plugins.
|
|
1334
|
+
*/
|
|
1335
|
+
pre?: Array<string>;
|
|
1336
|
+
/**
|
|
1337
|
+
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins.
|
|
1338
|
+
*/
|
|
1339
|
+
post?: Array<string>;
|
|
1340
|
+
/**
|
|
1341
|
+
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
1342
|
+
*/
|
|
1343
|
+
options: TOptions['resolvedOptions'] & {
|
|
1344
|
+
output: Output;
|
|
1345
|
+
include?: Array<Include>;
|
|
1346
|
+
exclude: Array<Exclude>;
|
|
1347
|
+
override: Array<Override<TOptions['resolvedOptions']>>;
|
|
1348
|
+
};
|
|
1349
|
+
/**
|
|
1350
|
+
* The resolver for this plugin.
|
|
1351
|
+
* Composed by `getPreset` from the preset resolver and the user's `resolver` partial override.
|
|
1352
|
+
*/
|
|
1353
|
+
resolver: TOptions['resolver'];
|
|
1354
|
+
/**
|
|
1355
|
+
* The composed transformer for this plugin. Accessible via `context.transformer`.
|
|
1356
|
+
* Composed by `getPreset` from the preset's transformers and the user's `transformer` visitor.
|
|
1357
|
+
* When a visitor method returns `null`/`undefined`, the preset transformer's result is used instead.
|
|
1358
|
+
*/
|
|
1359
|
+
transformer?: Visitor;
|
|
1360
|
+
/**
|
|
1361
|
+
* When `apply` is defined, the plugin is only activated when `apply(config)` returns `true`.
|
|
1362
|
+
* Inspired by Vite's `apply` option.
|
|
1363
|
+
*/
|
|
1364
|
+
apply?: (config: Config) => boolean;
|
|
1365
|
+
/**
|
|
1366
|
+
* Optional semver version string for this plugin, e.g. `"1.2.3"`.
|
|
1367
|
+
* Used in diagnostic messages and version-conflict detection.
|
|
1368
|
+
*/
|
|
1369
|
+
version?: string;
|
|
1370
|
+
buildStart: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1371
|
+
/**
|
|
1372
|
+
* Called once per plugin after all files have been written to disk.
|
|
1373
|
+
* Use this for post-processing, copying assets, or generating summary reports.
|
|
1374
|
+
*/
|
|
1375
|
+
buildEnd: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1376
|
+
/**
|
|
1377
|
+
* Called for each schema node during the AST walk.
|
|
1378
|
+
* Return a React element, an array of `KubbFile.File`, or `void` for manual handling.
|
|
1379
|
+
* Nodes matching `exclude`/`include` filters are skipped automatically.
|
|
1380
|
+
*
|
|
1381
|
+
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
1382
|
+
*/
|
|
1383
|
+
schema?: SchemaHook<TOptions>;
|
|
1384
|
+
/**
|
|
1385
|
+
* Called for each operation node during the AST walk.
|
|
1386
|
+
* Return a React element, an array of `KubbFile.File`, or `void` for manual handling.
|
|
1387
|
+
*
|
|
1388
|
+
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
1389
|
+
*/
|
|
1390
|
+
operation?: OperationHook<TOptions>;
|
|
1391
|
+
/**
|
|
1392
|
+
* Called once after all operations have been walked, with the full collected set.
|
|
1393
|
+
*
|
|
1394
|
+
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
1395
|
+
*/
|
|
1396
|
+
operations?: OperationsHook<TOptions>;
|
|
1397
|
+
/**
|
|
1398
|
+
* Expose shared helpers or data to all other plugins via `PluginContext`.
|
|
1399
|
+
* The returned object is merged into the context received by every plugin.
|
|
1400
|
+
*/
|
|
1401
|
+
inject: (this: PluginContext<TOptions>) => TOptions['context'];
|
|
1402
|
+
};
|
|
1403
|
+
type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
|
|
1404
|
+
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1405
|
+
/**
|
|
1406
|
+
* Called once per plugin at the start of its processing phase, before schema/operation/operations hooks run.
|
|
1407
|
+
* Use this to set up shared state, fetch remote data, or perform any async initialization.
|
|
1408
|
+
* @type hookParallel
|
|
1409
|
+
*/
|
|
1410
|
+
buildStart?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1411
|
+
/**
|
|
1412
|
+
* Called once per plugin after all files have been written to disk.
|
|
1413
|
+
* Use this for post-processing, copying assets, or generating summary reports.
|
|
1414
|
+
* @type hookParallel
|
|
1415
|
+
*/
|
|
1416
|
+
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1417
|
+
/**
|
|
1418
|
+
* Called for each schema node during the AST walk.
|
|
1419
|
+
* Return a React element (`<File>...</File>`), an array of `KubbFile.File` objects,
|
|
1420
|
+
* or `void` to handle file writing manually via `this.upsertFile`.
|
|
1421
|
+
* Nodes matching `exclude` / `include` filters are skipped automatically.
|
|
1422
|
+
*
|
|
1423
|
+
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
1424
|
+
*/
|
|
1425
|
+
schema?: SchemaHook<TOptions>;
|
|
1426
|
+
/**
|
|
1427
|
+
* Called for each operation node during the AST walk.
|
|
1428
|
+
* Return a React element (`<File>...</File>`), an array of `KubbFile.File` objects,
|
|
1429
|
+
* or `void` to handle file writing manually via `this.upsertFile`.
|
|
1430
|
+
*
|
|
1431
|
+
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
1432
|
+
*/
|
|
1433
|
+
operation?: OperationHook<TOptions>;
|
|
1434
|
+
/**
|
|
1435
|
+
* Called once after all operation nodes have been walked, with the full collection.
|
|
1436
|
+
* Useful for generating index/barrel files per group or aggregate operation handlers.
|
|
1437
|
+
*
|
|
1438
|
+
* For multiple generators, use `composeGenerators` inside the plugin factory.
|
|
1439
|
+
*/
|
|
1440
|
+
operations?: OperationsHook<TOptions>;
|
|
1441
|
+
/**
|
|
1442
|
+
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
1443
|
+
* Options can als be included.
|
|
1444
|
+
* @type hookFirst
|
|
1445
|
+
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
1446
|
+
* @deprecated this will be replaced by resolvers
|
|
1447
|
+
*/
|
|
1448
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: BaseName, mode?: Mode, options?: TOptions['resolvePathOptions']) => Path;
|
|
1449
|
+
/**
|
|
1450
|
+
* Resolve to a name based on a string.
|
|
1451
|
+
* Useful when converting to PascalCase or camelCase.
|
|
1452
|
+
* @type hookFirst
|
|
1453
|
+
* @example ('pet') => 'Pet'
|
|
1454
|
+
* @deprecated this will be replaced by resolvers
|
|
1455
|
+
*/
|
|
1456
|
+
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
1457
|
+
};
|
|
1458
|
+
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
1459
|
+
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
1460
|
+
type ResolvePathParams<TOptions = object> = {
|
|
1461
|
+
pluginName?: string;
|
|
1462
|
+
baseName: BaseName;
|
|
1463
|
+
mode?: Mode;
|
|
1464
|
+
/**
|
|
1465
|
+
* Options to be passed to 'resolvePath' 3th parameter
|
|
1466
|
+
*/
|
|
1467
|
+
options?: TOptions;
|
|
1468
|
+
};
|
|
1469
|
+
type ResolveNameParams = {
|
|
1470
|
+
name: string;
|
|
1471
|
+
pluginName?: string;
|
|
1472
|
+
/**
|
|
1473
|
+
* Specifies the type of entity being named.
|
|
1474
|
+
* - 'file' customizes the name of the created file (uses camelCase).
|
|
1475
|
+
* - 'function' customizes the exported function names (uses camelCase).
|
|
1476
|
+
* - 'type' customizes TypeScript types (uses PascalCase).
|
|
1477
|
+
* - 'const' customizes variable names (uses camelCase).
|
|
1478
|
+
* @default undefined
|
|
1479
|
+
*/
|
|
1480
|
+
type?: 'file' | 'function' | 'type' | 'const';
|
|
1481
|
+
};
|
|
1482
|
+
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1483
|
+
fabric: Fabric;
|
|
1484
|
+
config: Config;
|
|
1485
|
+
/**
|
|
1486
|
+
* Absolute path to the output directory for the current plugin.
|
|
1487
|
+
* Shorthand for `path.resolve(config.root, config.output.path)`.
|
|
1488
|
+
*/
|
|
1489
|
+
root: string;
|
|
1490
|
+
/**
|
|
1491
|
+
* Returns the output mode for the given output config.
|
|
1492
|
+
* Returns `'single'` when `output.path` has a file extension, `'split'` otherwise.
|
|
1493
|
+
* Shorthand for `getMode(path.resolve(this.root, output.path))`.
|
|
1494
|
+
*/
|
|
1495
|
+
getMode: (output: {
|
|
1496
|
+
path: string;
|
|
1497
|
+
}) => Mode;
|
|
1498
|
+
driver: PluginDriver;
|
|
1499
|
+
/**
|
|
1500
|
+
* Get a plugin by name. Returns the plugin typed via `Kubb.PluginRegistry` when
|
|
1501
|
+
* the name is a registered key, otherwise returns the generic `Plugin`.
|
|
1502
|
+
*/
|
|
1503
|
+
getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
|
|
1504
|
+
getPlugin(name: string): Plugin | undefined;
|
|
1505
|
+
/**
|
|
1506
|
+
* Like `getPlugin` but throws a descriptive error when the plugin is not found.
|
|
1507
|
+
* Useful for enforcing dependencies inside `buildStart()`.
|
|
1508
|
+
*/
|
|
1509
|
+
requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>;
|
|
1510
|
+
requirePlugin(name: string): Plugin;
|
|
1511
|
+
/**
|
|
1512
|
+
* Only add when the file does not exist yet
|
|
1513
|
+
*/
|
|
1514
|
+
addFile: (...file: Array<File>) => Promise<void>;
|
|
1515
|
+
/**
|
|
1516
|
+
* merging multiple sources into the same output file
|
|
1517
|
+
*/
|
|
1518
|
+
upsertFile: (...file: Array<File>) => Promise<void>;
|
|
1519
|
+
/**
|
|
1520
|
+
* @deprecated use this.warn, this.error, this.info instead
|
|
1521
|
+
*/
|
|
1522
|
+
events: AsyncEventEmitter<KubbEvents>;
|
|
1523
|
+
/**
|
|
1524
|
+
* Current plugin
|
|
1525
|
+
*/
|
|
1526
|
+
plugin: Plugin<TOptions>;
|
|
1527
|
+
/**
|
|
1528
|
+
* Resolver for the current plugin. Shorthand for `plugin.resolver`.
|
|
1529
|
+
*/
|
|
1530
|
+
resolver: TOptions['resolver'];
|
|
1531
|
+
/**
|
|
1532
|
+
* Composed transformer for the current plugin. Shorthand for `plugin.transformer`.
|
|
1533
|
+
* Apply with `transform(node, context.transformer)` to pre-process AST nodes before printing.
|
|
1534
|
+
*/
|
|
1535
|
+
transformer: Visitor | undefined;
|
|
1536
|
+
/**
|
|
1537
|
+
* Emit a warning via the build event system.
|
|
1538
|
+
* Shorthand for `this.events.emit('warn', message)`.
|
|
1539
|
+
*/
|
|
1540
|
+
warn: (message: string) => void;
|
|
1541
|
+
/**
|
|
1542
|
+
* Emit an error via the build event system.
|
|
1543
|
+
* Shorthand for `this.events.emit('error', error)`.
|
|
1544
|
+
*/
|
|
1545
|
+
error: (error: string | Error) => void;
|
|
1546
|
+
/**
|
|
1547
|
+
* Emit an info message via the build event system.
|
|
1548
|
+
* Shorthand for `this.events.emit('info', message)`.
|
|
1549
|
+
*/
|
|
1550
|
+
info: (message: string) => void;
|
|
1551
|
+
/**
|
|
1552
|
+
* Opens the Kubb Studio URL for the current `rootNode` in the default browser.
|
|
1553
|
+
* Falls back to printing the URL if the browser cannot be launched.
|
|
1554
|
+
* No-ops silently when no adapter has set a `rootNode`.
|
|
1555
|
+
*/
|
|
1556
|
+
openInStudio: (options?: DevtoolsOptions) => Promise<void>;
|
|
1557
|
+
} & ({
|
|
1558
|
+
/**
|
|
1559
|
+
* Returns the universal `@kubb/ast` `RootNode` produced by the configured adapter.
|
|
1560
|
+
* Returns `undefined` when no adapter was set (legacy OAS-only usage).
|
|
1561
|
+
*/
|
|
1562
|
+
rootNode: RootNode;
|
|
1563
|
+
/**
|
|
1564
|
+
* Return the adapter from `@kubb/ast`
|
|
1565
|
+
*/
|
|
1566
|
+
adapter: Adapter;
|
|
1567
|
+
} | {
|
|
1568
|
+
rootNode?: never;
|
|
1569
|
+
adapter?: never;
|
|
1570
|
+
}) & Kubb.PluginContext;
|
|
1571
|
+
/**
|
|
1572
|
+
* Narrowed `PluginContext` used as the `this` type inside generator and plugin AST hook methods.
|
|
1573
|
+
*
|
|
1574
|
+
* Generators and the `schema`/`operation`/`operations` plugin hooks are only invoked from
|
|
1575
|
+
* `runPluginAstHooks`, which already guards against a missing adapter. This type reflects
|
|
1576
|
+
* that guarantee — `this.adapter` and `this.rootNode` are always defined, so no runtime
|
|
1577
|
+
* checks or casts are needed inside the method bodies.
|
|
1578
|
+
*/
|
|
1579
|
+
type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Omit<PluginContext<TOptions>, 'adapter' | 'rootNode'> & {
|
|
1580
|
+
adapter: Adapter;
|
|
1581
|
+
rootNode: RootNode;
|
|
1582
|
+
};
|
|
1583
|
+
/**
|
|
1584
|
+
* Specify the export location for the files and define the behavior of the output
|
|
1585
|
+
*/
|
|
1586
|
+
type Output<_TOptions = unknown> = {
|
|
1587
|
+
/**
|
|
1588
|
+
* Path to the output folder or file that will contain the generated code
|
|
1589
|
+
*/
|
|
1590
|
+
path: string;
|
|
1591
|
+
/**
|
|
1592
|
+
* Define what needs to be exported, here you can also disable the export of barrel files
|
|
1593
|
+
* @default 'named'
|
|
1594
|
+
*/
|
|
1595
|
+
barrelType?: BarrelType | false;
|
|
1596
|
+
/**
|
|
1597
|
+
* Add a banner text in the beginning of every file
|
|
1598
|
+
*/
|
|
1599
|
+
banner?: string | ((node?: RootNode) => string);
|
|
1600
|
+
/**
|
|
1601
|
+
* Add a footer text in the beginning of every file
|
|
1602
|
+
*/
|
|
1603
|
+
footer?: string | ((node?: RootNode) => string);
|
|
1604
|
+
/**
|
|
1605
|
+
* Whether to override existing external files if they already exist.
|
|
1606
|
+
* @default false
|
|
1607
|
+
*/
|
|
1608
|
+
override?: boolean;
|
|
1609
|
+
};
|
|
1610
|
+
type UserGroup = {
|
|
1611
|
+
/**
|
|
1612
|
+
* Defines the type where to group the files.
|
|
1613
|
+
* - 'tag' groups files by OpenAPI tags.
|
|
1614
|
+
* - 'path' groups files by OpenAPI paths.
|
|
1615
|
+
* @default undefined
|
|
1616
|
+
*/
|
|
1617
|
+
type: 'tag' | 'path';
|
|
1618
|
+
/**
|
|
1619
|
+
* Return the name of a group based on the group name, this is used for the file and name generation.
|
|
1620
|
+
*/
|
|
1621
|
+
name?: (context: {
|
|
1622
|
+
group: string;
|
|
1623
|
+
}) => string;
|
|
1624
|
+
};
|
|
1625
|
+
type Group = {
|
|
1626
|
+
/**
|
|
1627
|
+
* Defines the type where to group the files.
|
|
1628
|
+
* - 'tag' groups files by OpenAPI tags.
|
|
1629
|
+
* - 'path' groups files by OpenAPI paths.
|
|
1630
|
+
* @default undefined
|
|
1631
|
+
*/
|
|
1632
|
+
type: 'tag' | 'path';
|
|
1633
|
+
/**
|
|
1634
|
+
* Return the name of a group based on the group name, this is used for the file and name generation.
|
|
1635
|
+
*/
|
|
1636
|
+
name: (context: {
|
|
1637
|
+
group: string;
|
|
1638
|
+
}) => string;
|
|
1639
|
+
};
|
|
1640
|
+
type LoggerOptions = {
|
|
1641
|
+
/**
|
|
1642
|
+
* @default 3
|
|
1643
|
+
*/
|
|
1644
|
+
logLevel: (typeof logLevel)[keyof typeof logLevel];
|
|
1645
|
+
};
|
|
1646
|
+
/**
|
|
1647
|
+
* Shared context passed to all plugins, parsers, and Fabric internals.
|
|
1648
|
+
*/
|
|
1649
|
+
type LoggerContext = AsyncEventEmitter<KubbEvents>;
|
|
1650
|
+
type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
|
|
1651
|
+
name: string;
|
|
1652
|
+
install: (context: LoggerContext, options?: TOptions) => void | Promise<void>;
|
|
1653
|
+
};
|
|
1654
|
+
type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Logger<TOptions>;
|
|
1655
|
+
/**
|
|
1656
|
+
* Compatibility preset for code generation tools.
|
|
1657
|
+
* - `'default'` – no compatibility adjustments (default behavior).
|
|
1658
|
+
* - `'kubbV4'` – align generated names and structures with Kubb v4 output.
|
|
1659
|
+
*/
|
|
1660
|
+
type CompatibilityPreset = 'default' | 'kubbV4';
|
|
1661
|
+
/**
|
|
1662
|
+
* A preset bundles a name, a resolver, optional AST transformers,
|
|
1663
|
+
* and optional generators into a single reusable configuration object.
|
|
1664
|
+
*
|
|
1665
|
+
* @template TResolver - The concrete resolver type for this preset.
|
|
1666
|
+
*/
|
|
1667
|
+
type Preset<TResolver extends Resolver = Resolver> = {
|
|
1668
|
+
/**
|
|
1669
|
+
* Unique identifier for this preset.
|
|
1670
|
+
*/
|
|
1671
|
+
name: string;
|
|
1672
|
+
/**
|
|
1673
|
+
* The resolver used by this preset.
|
|
1674
|
+
*/
|
|
1675
|
+
resolver: TResolver;
|
|
1676
|
+
/**
|
|
1677
|
+
* Optional AST visitors / transformers applied after resolving.
|
|
1678
|
+
*/
|
|
1679
|
+
transformers?: Array<Visitor>;
|
|
1680
|
+
/**
|
|
1681
|
+
* Optional generators used by this preset. Plugin implementations cast this
|
|
1682
|
+
* to their concrete generator type.
|
|
1683
|
+
*/
|
|
1684
|
+
generators?: Array<Generator<any>>;
|
|
1685
|
+
/**
|
|
1686
|
+
* Optional printer factory used by this preset.
|
|
1687
|
+
* The generator calls this function at render-time to produce a configured printer instance.
|
|
1688
|
+
*/
|
|
1689
|
+
printer?: (options: any) => Printer;
|
|
1690
|
+
};
|
|
1691
|
+
/**
|
|
1692
|
+
* A named registry of presets, keyed by preset name.
|
|
1693
|
+
*
|
|
1694
|
+
* @template TResolver - The concrete resolver type shared by all presets in this registry.
|
|
1695
|
+
* @template TName - The union of valid preset name keys.
|
|
1696
|
+
*/
|
|
1697
|
+
type Presets<TResolver extends Resolver = Resolver> = Record<CompatibilityPreset, Preset<TResolver>>;
|
|
1698
|
+
type ByTag = {
|
|
1699
|
+
type: 'tag';
|
|
1700
|
+
pattern: string | RegExp;
|
|
1701
|
+
};
|
|
1702
|
+
type ByOperationId = {
|
|
1703
|
+
type: 'operationId';
|
|
1704
|
+
pattern: string | RegExp;
|
|
1705
|
+
};
|
|
1706
|
+
type ByPath = {
|
|
1707
|
+
type: 'path';
|
|
1708
|
+
pattern: string | RegExp;
|
|
1709
|
+
};
|
|
1710
|
+
type ByMethod = {
|
|
1711
|
+
type: 'method';
|
|
1712
|
+
pattern: HttpMethod | RegExp;
|
|
1713
|
+
};
|
|
1714
|
+
type BySchemaName = {
|
|
1715
|
+
type: 'schemaName';
|
|
1716
|
+
pattern: string | RegExp;
|
|
1717
|
+
};
|
|
1718
|
+
type ByContentType = {
|
|
1719
|
+
type: 'contentType';
|
|
1720
|
+
pattern: string | RegExp;
|
|
1721
|
+
};
|
|
1722
|
+
type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
|
|
1723
|
+
type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
|
|
1724
|
+
type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
1725
|
+
options: Partial<TOptions>;
|
|
1726
|
+
};
|
|
1727
|
+
type ResolvePathOptions = {
|
|
1728
|
+
pluginName?: string;
|
|
1729
|
+
group?: {
|
|
1730
|
+
tag?: string;
|
|
1731
|
+
path?: string;
|
|
1732
|
+
};
|
|
1733
|
+
type?: ResolveNameParams['type'];
|
|
1734
|
+
};
|
|
1735
|
+
/**
|
|
1736
|
+
* File-specific parameters for `Resolver.resolvePath`.
|
|
1737
|
+
*
|
|
1738
|
+
* Pass alongside a `ResolverContext` to identify which file to resolve.
|
|
1739
|
+
* Provide `tag` for tag-based grouping or `path` for path-based grouping.
|
|
1740
|
+
*
|
|
1741
|
+
* @example
|
|
1742
|
+
* ```ts
|
|
1743
|
+
* resolver.resolvePath(
|
|
1744
|
+
* { baseName: 'petTypes.ts', tag: 'pets' },
|
|
1745
|
+
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
1746
|
+
* )
|
|
1747
|
+
* // → '/src/types/petsController/petTypes.ts'
|
|
1748
|
+
* ```
|
|
1749
|
+
*/
|
|
1750
|
+
type ResolverPathParams = {
|
|
1751
|
+
baseName: BaseName;
|
|
1752
|
+
pathMode?: Mode;
|
|
1753
|
+
/**
|
|
1754
|
+
* Tag value used when `group.type === 'tag'`.
|
|
1755
|
+
*/
|
|
1756
|
+
tag?: string;
|
|
1757
|
+
/**
|
|
1758
|
+
* Path value used when `group.type === 'path'`.
|
|
1759
|
+
*/
|
|
1760
|
+
path?: string;
|
|
1761
|
+
};
|
|
1762
|
+
/**
|
|
1763
|
+
* Shared context passed as the second argument to `Resolver.resolvePath` and `Resolver.resolveFile`.
|
|
1764
|
+
*
|
|
1765
|
+
* Describes where on disk output is rooted, which output config is active, and the optional
|
|
1766
|
+
* grouping strategy that controls subdirectory layout.
|
|
1767
|
+
*
|
|
1768
|
+
* @example
|
|
1769
|
+
* ```ts
|
|
1770
|
+
* const context: ResolverContext = {
|
|
1771
|
+
* root: config.root,
|
|
1772
|
+
* output,
|
|
1773
|
+
* group,
|
|
1774
|
+
* }
|
|
1775
|
+
* ```
|
|
1776
|
+
*/
|
|
1777
|
+
type ResolverContext = {
|
|
1778
|
+
root: string;
|
|
1779
|
+
output: Output;
|
|
1780
|
+
group?: Group;
|
|
1781
|
+
/**
|
|
1782
|
+
* Plugin name used to populate `meta.pluginName` on the resolved file.
|
|
1783
|
+
*/
|
|
1784
|
+
pluginName?: string;
|
|
1785
|
+
};
|
|
1786
|
+
/**
|
|
1787
|
+
* File-specific parameters for `Resolver.resolveFile`.
|
|
1788
|
+
*
|
|
1789
|
+
* Pass alongside a `ResolverContext` to fully describe the file to resolve.
|
|
1790
|
+
* `tag` and `path` are used only when a matching `group` is present in the context.
|
|
1791
|
+
*
|
|
1792
|
+
* @example
|
|
1793
|
+
* ```ts
|
|
1794
|
+
* resolver.resolveFile(
|
|
1795
|
+
* { name: 'listPets', extname: '.ts', tag: 'pets' },
|
|
1796
|
+
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
1797
|
+
* )
|
|
1798
|
+
* // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
|
|
1799
|
+
* ```
|
|
1800
|
+
*/
|
|
1801
|
+
type ResolverFileParams = {
|
|
1802
|
+
name: string;
|
|
1803
|
+
extname: Extname;
|
|
1804
|
+
/**
|
|
1805
|
+
* Tag value used when `group.type === 'tag'`.
|
|
1806
|
+
*/
|
|
1807
|
+
tag?: string;
|
|
1808
|
+
/**
|
|
1809
|
+
* Path value used when `group.type === 'path'`.
|
|
1810
|
+
*/
|
|
1811
|
+
path?: string;
|
|
1812
|
+
};
|
|
1813
|
+
/**
|
|
1814
|
+
* Context passed to `Resolver.resolveBanner` and `Resolver.resolveFooter`.
|
|
1815
|
+
*
|
|
1816
|
+
* `output` is optional — not every plugin configures a banner/footer.
|
|
1817
|
+
* `config` carries the global Kubb config, used to derive the default Kubb banner.
|
|
1818
|
+
*
|
|
1819
|
+
* @example
|
|
1820
|
+
* ```ts
|
|
1821
|
+
* resolver.resolveBanner(rootNode, { output: { banner: '// generated' }, config })
|
|
1822
|
+
* // → '// generated'
|
|
1823
|
+
* ```
|
|
1824
|
+
*/
|
|
1825
|
+
type ResolveBannerContext = {
|
|
1826
|
+
output?: Pick<Output, 'banner' | 'footer'>;
|
|
1827
|
+
config: Config;
|
|
1828
|
+
};
|
|
1829
|
+
//#endregion
|
|
1830
|
+
//#region src/PluginDriver.d.ts
|
|
1831
|
+
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
1832
|
+
/**
|
|
1833
|
+
* Hook dispatch strategy used by the `PluginDriver`.
|
|
1834
|
+
*
|
|
1835
|
+
* - `hookFirst` — stops at the first non-null result.
|
|
1836
|
+
* - `hookForPlugin` — calls only the matching plugin.
|
|
1837
|
+
* - `hookParallel` — calls all plugins concurrently.
|
|
1838
|
+
* - `hookSeq` — calls all plugins in order, threading the result.
|
|
1839
|
+
*/
|
|
1840
|
+
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
|
|
1841
|
+
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
1842
|
+
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
1843
|
+
result: Result;
|
|
1844
|
+
plugin: Plugin;
|
|
1845
|
+
};
|
|
1846
|
+
type Options = {
|
|
1847
|
+
fabric: Fabric;
|
|
1848
|
+
events: AsyncEventEmitter<KubbEvents>;
|
|
1849
|
+
/**
|
|
1850
|
+
* @default Number.POSITIVE_INFINITY
|
|
1851
|
+
*/
|
|
1852
|
+
concurrency?: number;
|
|
1853
|
+
};
|
|
1854
|
+
/**
|
|
1855
|
+
* Parameters accepted by `PluginDriver.getFile` to resolve a generated file descriptor.
|
|
1856
|
+
*/
|
|
1857
|
+
type GetFileOptions<TOptions = object> = {
|
|
1858
|
+
name: string;
|
|
1859
|
+
mode?: Mode;
|
|
1860
|
+
extname: Extname;
|
|
1861
|
+
pluginName: string;
|
|
1862
|
+
options?: TOptions;
|
|
1863
|
+
};
|
|
1864
|
+
/**
|
|
1865
|
+
* Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.
|
|
1866
|
+
*
|
|
1867
|
+
* @example
|
|
1868
|
+
* ```ts
|
|
1869
|
+
* getMode('src/gen/types.ts') // 'single'
|
|
1870
|
+
* getMode('src/gen/types') // 'split'
|
|
1871
|
+
* ```
|
|
1872
|
+
*/
|
|
1873
|
+
declare function getMode(fileOrFolder: string | undefined | null): Mode;
|
|
1874
|
+
declare class PluginDriver {
|
|
1875
|
+
#private;
|
|
1876
|
+
readonly config: Config;
|
|
1877
|
+
readonly options: Options;
|
|
1878
|
+
/**
|
|
1879
|
+
* The universal `@kubb/ast` `RootNode` produced by the adapter, set by
|
|
1880
|
+
* the build pipeline after the adapter's `parse()` resolves.
|
|
1881
|
+
*/
|
|
1882
|
+
rootNode: RootNode | undefined;
|
|
1883
|
+
adapter: Adapter | undefined;
|
|
1884
|
+
readonly plugins: Map<string, Plugin>;
|
|
1885
|
+
constructor(config: Config, options: Options);
|
|
1886
|
+
get events(): AsyncEventEmitter<KubbEvents>;
|
|
1887
|
+
getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, unknown>;
|
|
1888
|
+
/**
|
|
1889
|
+
* @deprecated use resolvers context instead
|
|
1890
|
+
*/
|
|
1891
|
+
getFile<TOptions = object>({
|
|
1892
|
+
name,
|
|
1893
|
+
mode,
|
|
1894
|
+
extname,
|
|
1895
|
+
pluginName,
|
|
1896
|
+
options
|
|
1897
|
+
}: GetFileOptions<TOptions>): File<{
|
|
1898
|
+
pluginName: string;
|
|
1899
|
+
}>;
|
|
1900
|
+
/**
|
|
1901
|
+
* @deprecated use resolvers context instead
|
|
1902
|
+
*/
|
|
1903
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => Path;
|
|
1904
|
+
/**
|
|
1905
|
+
* @deprecated use resolvers context instead
|
|
1906
|
+
*/
|
|
1907
|
+
resolveName: (params: ResolveNameParams) => string;
|
|
1908
|
+
/**
|
|
1909
|
+
* Run a specific hookName for plugin x.
|
|
1910
|
+
*/
|
|
1911
|
+
hookForPlugin<H extends PluginLifecycleHooks>({
|
|
1912
|
+
pluginName,
|
|
1913
|
+
hookName,
|
|
1914
|
+
parameters
|
|
1915
|
+
}: {
|
|
1916
|
+
pluginName: string;
|
|
1917
|
+
hookName: H;
|
|
1918
|
+
parameters: PluginParameter<H>;
|
|
1919
|
+
}): Promise<Array<ReturnType<ParseResult<H>> | null>>;
|
|
1920
|
+
/**
|
|
1921
|
+
* Run a specific hookName for plugin x.
|
|
1922
|
+
*/
|
|
1923
|
+
hookForPluginSync<H extends PluginLifecycleHooks>({
|
|
1924
|
+
pluginName,
|
|
1925
|
+
hookName,
|
|
1926
|
+
parameters
|
|
1927
|
+
}: {
|
|
1928
|
+
pluginName: string;
|
|
1929
|
+
hookName: H;
|
|
1930
|
+
parameters: PluginParameter<H>;
|
|
1931
|
+
}): Array<ReturnType<ParseResult<H>>> | null;
|
|
1932
|
+
/**
|
|
1933
|
+
* Returns the first non-null result.
|
|
1934
|
+
*/
|
|
1935
|
+
hookFirst<H extends PluginLifecycleHooks>({
|
|
1936
|
+
hookName,
|
|
1937
|
+
parameters,
|
|
1938
|
+
skipped
|
|
1939
|
+
}: {
|
|
1940
|
+
hookName: H;
|
|
1941
|
+
parameters: PluginParameter<H>;
|
|
1942
|
+
skipped?: ReadonlySet<Plugin> | null;
|
|
1943
|
+
}): Promise<SafeParseResult<H>>;
|
|
1944
|
+
/**
|
|
1945
|
+
* Returns the first non-null result.
|
|
1946
|
+
*/
|
|
1947
|
+
hookFirstSync<H extends PluginLifecycleHooks>({
|
|
1948
|
+
hookName,
|
|
1949
|
+
parameters,
|
|
1950
|
+
skipped
|
|
1951
|
+
}: {
|
|
1952
|
+
hookName: H;
|
|
1953
|
+
parameters: PluginParameter<H>;
|
|
1954
|
+
skipped?: ReadonlySet<Plugin> | null;
|
|
1955
|
+
}): SafeParseResult<H> | null;
|
|
1956
|
+
/**
|
|
1957
|
+
* Runs all plugins in parallel based on `this.plugin` order and `pre`/`post` settings.
|
|
1958
|
+
*/
|
|
1959
|
+
hookParallel<H extends PluginLifecycleHooks, TOutput = void>({
|
|
1960
|
+
hookName,
|
|
1961
|
+
parameters
|
|
1962
|
+
}: {
|
|
1963
|
+
hookName: H;
|
|
1964
|
+
parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
|
|
1965
|
+
}): Promise<Awaited<TOutput>[]>;
|
|
1966
|
+
/**
|
|
1967
|
+
* Chains plugins
|
|
1968
|
+
*/
|
|
1969
|
+
hookSeq<H extends PluginLifecycleHooks>({
|
|
1970
|
+
hookName,
|
|
1971
|
+
parameters
|
|
1972
|
+
}: {
|
|
1973
|
+
hookName: H;
|
|
1974
|
+
parameters?: PluginParameter<H>;
|
|
1975
|
+
}): Promise<void>;
|
|
1976
|
+
getPlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
|
|
1977
|
+
getPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions> | undefined;
|
|
1978
|
+
/**
|
|
1979
|
+
* Like `getPlugin` but throws a descriptive error when the plugin is not found.
|
|
1980
|
+
*/
|
|
1981
|
+
requirePlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]>;
|
|
1982
|
+
requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>;
|
|
1983
|
+
}
|
|
1984
|
+
//#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 _, 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
|