@kubb/core 5.0.0-alpha.8 → 5.0.0-beta.75
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/README.md +23 -20
- package/dist/PluginDriver-BXibeQk-.cjs +1036 -0
- package/dist/PluginDriver-BXibeQk-.cjs.map +1 -0
- package/dist/PluginDriver-DV3p2Hky.js +945 -0
- package/dist/PluginDriver-DV3p2Hky.js.map +1 -0
- package/dist/index.cjs +756 -1693
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +297 -239
- package/dist/index.js +743 -1661
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +145 -0
- package/dist/mocks.cjs.map +1 -0
- package/dist/mocks.d.ts +80 -0
- package/dist/mocks.js +140 -0
- package/dist/mocks.js.map +1 -0
- package/dist/types-CuNocrbJ.d.ts +2148 -0
- package/package.json +51 -57
- package/src/FileManager.ts +115 -0
- package/src/FileProcessor.ts +86 -0
- package/src/Kubb.ts +208 -160
- package/src/PluginDriver.ts +326 -565
- package/src/constants.ts +20 -47
- package/src/createAdapter.ts +16 -6
- package/src/createKubb.ts +548 -0
- package/src/createRenderer.ts +57 -0
- package/src/createStorage.ts +40 -26
- package/src/defineGenerator.ts +87 -0
- package/src/defineLogger.ts +19 -0
- package/src/defineMiddleware.ts +62 -0
- package/src/defineParser.ts +44 -0
- package/src/definePlugin.ts +83 -0
- package/src/defineResolver.ts +521 -0
- package/src/devtools.ts +14 -14
- package/src/index.ts +14 -17
- package/src/mocks.ts +178 -0
- package/src/renderNode.ts +35 -0
- package/src/storages/fsStorage.ts +41 -11
- package/src/storages/memoryStorage.ts +4 -2
- package/src/types.ts +1054 -270
- package/src/utils/diagnostics.ts +4 -1
- package/src/utils/isInputPath.ts +10 -0
- package/src/utils/packageJSON.ts +99 -0
- package/dist/PluginDriver-DRfJIbG1.d.ts +0 -1056
- package/dist/chunk-ByKO4r7w.cjs +0 -38
- package/dist/hooks.cjs +0 -102
- package/dist/hooks.cjs.map +0 -1
- package/dist/hooks.d.ts +0 -75
- package/dist/hooks.js +0 -97
- package/dist/hooks.js.map +0 -1
- package/src/PackageManager.ts +0 -180
- package/src/build.ts +0 -419
- package/src/config.ts +0 -56
- package/src/createGenerator.ts +0 -106
- package/src/createLogger.ts +0 -7
- package/src/createPlugin.ts +0 -12
- package/src/errors.ts +0 -1
- package/src/hooks/index.ts +0 -4
- package/src/hooks/useKubb.ts +0 -138
- package/src/hooks/useMode.ts +0 -11
- package/src/hooks/usePlugin.ts +0 -11
- package/src/hooks/usePluginDriver.ts +0 -11
- package/src/utils/FunctionParams.ts +0 -155
- package/src/utils/TreeNode.ts +0 -215
- package/src/utils/executeStrategies.ts +0 -81
- package/src/utils/formatters.ts +0 -56
- package/src/utils/getBarrelFiles.ts +0 -141
- package/src/utils/getConfigs.ts +0 -30
- package/src/utils/getPlugins.ts +0 -23
- package/src/utils/linters.ts +0 -25
- package/src/utils/resolveOptions.ts +0 -93
|
@@ -0,0 +1,2148 @@
|
|
|
1
|
+
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
+
import { FileNode, HttpMethod, ImportNode, InputNode, Node, OperationNode, SchemaNode, UserFileNode, Visitor } from "@kubb/ast";
|
|
3
|
+
|
|
4
|
+
//#region ../../internals/utils/src/asyncEventEmitter.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* A function that can be registered as an event listener, synchronous or async.
|
|
7
|
+
*/
|
|
8
|
+
type AsyncListener<TArgs extends unknown[]> = (...args: TArgs) => void | Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Typed `EventEmitter` that awaits all async listeners before resolving.
|
|
11
|
+
* Wraps Node's `EventEmitter` with full TypeScript event-map inference.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const emitter = new AsyncEventEmitter<{ build: [name: string] }>()
|
|
16
|
+
* emitter.on('build', async (name) => { console.log(name) })
|
|
17
|
+
* await emitter.emit('build', 'petstore') // all listeners awaited
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[] }> {
|
|
21
|
+
#private;
|
|
22
|
+
/**
|
|
23
|
+
* Maximum number of listeners per event before Node emits a memory-leak warning.
|
|
24
|
+
* @default 10
|
|
25
|
+
*/
|
|
26
|
+
constructor(maxListener?: number);
|
|
27
|
+
/**
|
|
28
|
+
* Emits `eventName` and awaits all registered listeners sequentially.
|
|
29
|
+
* Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* await emitter.emit('build', 'petstore')
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Registers a persistent listener for `eventName`.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* emitter.on('build', async (name) => { console.log(name) })
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
46
|
+
/**
|
|
47
|
+
* Registers a one-shot listener that removes itself after the first invocation.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* emitter.onOnce('build', async (name) => { console.log(name) })
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
55
|
+
/**
|
|
56
|
+
* Removes a previously registered listener.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* emitter.off('build', handler)
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: AsyncListener<TEvents[TEventName]>): void;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the number of listeners registered for `eventName`.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* emitter.on('build', handler)
|
|
70
|
+
* emitter.listenerCount('build') // 1
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
listenerCount<TEventName extends keyof TEvents & string>(eventName: TEventName): number;
|
|
74
|
+
/**
|
|
75
|
+
* Removes all listeners from every event channel.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* emitter.removeAll()
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
removeAll(): void;
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region ../../internals/utils/src/promise.d.ts
|
|
86
|
+
/** A value that may already be resolved or still pending.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* function load(id: string): PossiblePromise<string> {
|
|
91
|
+
* return cache.get(id) ?? fetchRemote(id)
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
type PossiblePromise<T> = Promise<T> | T;
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/constants.d.ts
|
|
98
|
+
/**
|
|
99
|
+
* Base URL for the Kubb Studio web app.
|
|
100
|
+
*/
|
|
101
|
+
declare const DEFAULT_STUDIO_URL: "https://studio.kubb.dev";
|
|
102
|
+
/**
|
|
103
|
+
* Numeric log-level thresholds used internally to compare verbosity.
|
|
104
|
+
*
|
|
105
|
+
* Higher numbers are more verbose.
|
|
106
|
+
*/
|
|
107
|
+
declare const logLevel: {
|
|
108
|
+
readonly silent: number;
|
|
109
|
+
readonly error: 0;
|
|
110
|
+
readonly warn: 1;
|
|
111
|
+
readonly info: 3;
|
|
112
|
+
readonly verbose: 4;
|
|
113
|
+
readonly debug: 5;
|
|
114
|
+
};
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/createRenderer.d.ts
|
|
117
|
+
/**
|
|
118
|
+
* Minimal interface any Kubb renderer must satisfy.
|
|
119
|
+
*
|
|
120
|
+
* The generic `TElement` is the type of the element the renderer accepts —
|
|
121
|
+
* e.g. `KubbReactElement` for `@kubb/renderer-jsx`, or a custom type for
|
|
122
|
+
* your own renderer. Defaults to `unknown` so that generators which do not
|
|
123
|
+
* care about the element type continue to work without specifying it.
|
|
124
|
+
*
|
|
125
|
+
* This allows core to drive rendering without a hard dependency on
|
|
126
|
+
* `@kubb/renderer-jsx` or any specific renderer implementation.
|
|
127
|
+
*/
|
|
128
|
+
type Renderer<TElement = unknown> = {
|
|
129
|
+
render(element: TElement): Promise<void>;
|
|
130
|
+
unmount(error?: Error | number | null): void;
|
|
131
|
+
readonly files: Array<FileNode>;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* A factory function that produces a fresh {@link Renderer} per render.
|
|
135
|
+
*
|
|
136
|
+
* Generators use this to declare which renderer handles their output.
|
|
137
|
+
*/
|
|
138
|
+
type RendererFactory<TElement = unknown> = () => Renderer<TElement>;
|
|
139
|
+
/**
|
|
140
|
+
* Creates a renderer factory for use in generator definitions.
|
|
141
|
+
*
|
|
142
|
+
* Wrap your renderer factory function with this helper to register it as the
|
|
143
|
+
* renderer for a generator. Core will call this factory once per render cycle
|
|
144
|
+
* to obtain a fresh renderer instance.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* // packages/renderer-jsx/src/index.ts
|
|
149
|
+
* export const jsxRenderer = createRenderer(() => {
|
|
150
|
+
* const runtime = new Runtime()
|
|
151
|
+
* return {
|
|
152
|
+
* async render(element) { await runtime.render(element) },
|
|
153
|
+
* get files() { return runtime.nodes },
|
|
154
|
+
* unmount(error) { runtime.unmount(error) },
|
|
155
|
+
* }
|
|
156
|
+
* })
|
|
157
|
+
*
|
|
158
|
+
* // packages/plugin-zod/src/generators/zodGenerator.tsx
|
|
159
|
+
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
160
|
+
* export const zodGenerator = defineGenerator<PluginZod>({
|
|
161
|
+
* name: 'zod',
|
|
162
|
+
* renderer: jsxRenderer,
|
|
163
|
+
* schema(node, options) { return <File ...>...</File> },
|
|
164
|
+
* })
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
declare function createRenderer<TElement = unknown>(factory: RendererFactory<TElement>): RendererFactory<TElement>;
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region src/createStorage.d.ts
|
|
170
|
+
type Storage = {
|
|
171
|
+
/**
|
|
172
|
+
* Identifier used for logging and debugging (e.g. `'fs'`, `'s3'`).
|
|
173
|
+
*/
|
|
174
|
+
readonly name: string;
|
|
175
|
+
/**
|
|
176
|
+
* Returns `true` when an entry for `key` exists in storage.
|
|
177
|
+
*/
|
|
178
|
+
hasItem(key: string): Promise<boolean>;
|
|
179
|
+
/**
|
|
180
|
+
* Returns the stored string value, or `null` when `key` does not exist.
|
|
181
|
+
*/
|
|
182
|
+
getItem(key: string): Promise<string | null>;
|
|
183
|
+
/**
|
|
184
|
+
* Persists `value` under `key`, creating any required structure.
|
|
185
|
+
*/
|
|
186
|
+
setItem(key: string, value: string): Promise<void>;
|
|
187
|
+
/**
|
|
188
|
+
* Removes the entry for `key`. No-ops when the key does not exist.
|
|
189
|
+
*/
|
|
190
|
+
removeItem(key: string): Promise<void>;
|
|
191
|
+
/**
|
|
192
|
+
* Returns all keys, optionally filtered to those starting with `base`.
|
|
193
|
+
*/
|
|
194
|
+
getKeys(base?: string): Promise<Array<string>>;
|
|
195
|
+
/**
|
|
196
|
+
* Removes all entries, optionally scoped to those starting with `base`.
|
|
197
|
+
*/
|
|
198
|
+
clear(base?: string): Promise<void>;
|
|
199
|
+
/**
|
|
200
|
+
* Optional teardown hook called after the build completes.
|
|
201
|
+
*/
|
|
202
|
+
dispose?(): Promise<void>;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Factory for implementing custom storage backends that control where generated files are written.
|
|
206
|
+
*
|
|
207
|
+
* Takes a builder function `(options: TOptions) => Storage` and returns a factory `(options?: TOptions) => Storage`.
|
|
208
|
+
* Kubb provides filesystem and in-memory implementations out of the box.
|
|
209
|
+
*
|
|
210
|
+
* @note Call the returned factory with optional options to instantiate the storage adapter.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```ts
|
|
214
|
+
* import { createStorage } from '@kubb/core'
|
|
215
|
+
*
|
|
216
|
+
* export const memoryStorage = createStorage(() => {
|
|
217
|
+
* const store = new Map<string, string>()
|
|
218
|
+
* return {
|
|
219
|
+
* name: 'memory',
|
|
220
|
+
* async hasItem(key) { return store.has(key) },
|
|
221
|
+
* async getItem(key) { return store.get(key) ?? null },
|
|
222
|
+
* async setItem(key, value) { store.set(key, value) },
|
|
223
|
+
* async removeItem(key) { store.delete(key) },
|
|
224
|
+
* async getKeys(base) {
|
|
225
|
+
* const keys = [...store.keys()]
|
|
226
|
+
* return base ? keys.filter((k) => k.startsWith(base)) : keys
|
|
227
|
+
* },
|
|
228
|
+
* async clear(base) { if (!base) store.clear() },
|
|
229
|
+
* }
|
|
230
|
+
* })
|
|
231
|
+
*
|
|
232
|
+
* // Instantiate:
|
|
233
|
+
* const storage = memoryStorage()
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
declare function createStorage<TOptions = Record<string, never>>(build: (options: TOptions) => Storage): (options?: TOptions) => Storage;
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region src/defineGenerator.d.ts
|
|
239
|
+
/**
|
|
240
|
+
* Declares a named generator unit that walks the AST and emits files.
|
|
241
|
+
*
|
|
242
|
+
* Each method (`schema`, `operation`, `operations`) is called for the matching node type.
|
|
243
|
+
* Each method returns `TElement | Array<FileNode> | void`. JSX-based generators require a `renderer` factory.
|
|
244
|
+
* Return `Array<FileNode>` directly or call `ctx.upsertFile()` manually and return `void` to bypass rendering.
|
|
245
|
+
*
|
|
246
|
+
* @note Generators are consumed by plugins and registered via `ctx.addGenerator()` in `kubb:plugin:setup`.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* import { defineGenerator } from '@kubb/core'
|
|
251
|
+
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
252
|
+
*
|
|
253
|
+
* export const typeGenerator = defineGenerator({
|
|
254
|
+
* name: 'typescript',
|
|
255
|
+
* renderer: jsxRenderer,
|
|
256
|
+
* schema(node, ctx) {
|
|
257
|
+
* const { adapter, resolver, root, options } = ctx
|
|
258
|
+
* return <File ...><Type node={node} resolver={resolver} /></File>
|
|
259
|
+
* },
|
|
260
|
+
* })
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
type Generator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown> = {
|
|
264
|
+
/**
|
|
265
|
+
* Used in diagnostic messages and debug output.
|
|
266
|
+
*/
|
|
267
|
+
name: string;
|
|
268
|
+
/**
|
|
269
|
+
* Optional renderer factory that produces a {@link Renderer} for each render cycle.
|
|
270
|
+
*
|
|
271
|
+
* Generators that return renderer elements (e.g. JSX via `@kubb/renderer-jsx`) must set this
|
|
272
|
+
* to the matching renderer factory (e.g. `jsxRenderer` from `@kubb/renderer-jsx`).
|
|
273
|
+
*
|
|
274
|
+
* Generators that only return `Array<FileNode>` or `void` do not need to set this.
|
|
275
|
+
*
|
|
276
|
+
* Set `renderer: null` to explicitly opt out of rendering even when the parent plugin
|
|
277
|
+
* declares a `renderer` (overrides the plugin-level fallback).
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```ts
|
|
281
|
+
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
282
|
+
* export const myGenerator = defineGenerator<PluginTs>({
|
|
283
|
+
* renderer: jsxRenderer,
|
|
284
|
+
* schema(node, ctx) { return <File ...>...</File> },
|
|
285
|
+
* })
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
renderer?: RendererFactory<TElement> | null;
|
|
289
|
+
/**
|
|
290
|
+
* Called for each schema node in the AST walk.
|
|
291
|
+
* `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
|
|
292
|
+
* plus `ctx.options` with the per-node resolved options (after exclude/include/override).
|
|
293
|
+
*/
|
|
294
|
+
schema?: (node: SchemaNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
|
|
295
|
+
/**
|
|
296
|
+
* Called for each operation node in the AST walk.
|
|
297
|
+
* `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
|
|
298
|
+
* plus `ctx.options` with the per-node resolved options (after exclude/include/override).
|
|
299
|
+
*/
|
|
300
|
+
operation?: (node: OperationNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
|
|
301
|
+
/**
|
|
302
|
+
* Called once after all operations have been walked.
|
|
303
|
+
* `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
|
|
304
|
+
* plus `ctx.options` with the plugin-level options for the batch call.
|
|
305
|
+
*/
|
|
306
|
+
operations?: (nodes: Array<OperationNode>, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
|
|
307
|
+
};
|
|
308
|
+
/**
|
|
309
|
+
* Defines a generator. Returns the object as-is with correct `this` typings.
|
|
310
|
+
* `applyHookResult` handles renderer elements and `File[]` uniformly using
|
|
311
|
+
* the generator's declared `renderer` factory.
|
|
312
|
+
*/
|
|
313
|
+
declare function defineGenerator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown>(generator: Generator<TOptions, TElement>): Generator<TOptions, TElement>;
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region src/definePlugin.d.ts
|
|
316
|
+
/**
|
|
317
|
+
* A plugin object produced by `definePlugin`.
|
|
318
|
+
* Instead of flat lifecycle methods, it groups all handlers under a `hooks:` property
|
|
319
|
+
* (matching Astro's integration naming convention).
|
|
320
|
+
*
|
|
321
|
+
* @template TFactory - The plugin's `PluginFactoryOptions` type.
|
|
322
|
+
*/
|
|
323
|
+
type Plugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
324
|
+
/**
|
|
325
|
+
* Unique name for the plugin, following the same naming convention as `createPlugin`.
|
|
326
|
+
*/
|
|
327
|
+
name: string;
|
|
328
|
+
/**
|
|
329
|
+
* Plugins that must be registered before this plugin executes.
|
|
330
|
+
* An error is thrown at startup when any listed dependency is missing.
|
|
331
|
+
*/
|
|
332
|
+
dependencies?: Array<string>;
|
|
333
|
+
/**
|
|
334
|
+
* Controls the execution order of this plugin relative to others.
|
|
335
|
+
*
|
|
336
|
+
* - `'pre'` — runs before all normal plugins.
|
|
337
|
+
* - `'post'` — runs after all normal plugins.
|
|
338
|
+
* - `undefined` (default) — runs in declaration order among normal plugins.
|
|
339
|
+
*
|
|
340
|
+
* Dependency constraints always take precedence over `enforce`.
|
|
341
|
+
*/
|
|
342
|
+
enforce?: 'pre' | 'post';
|
|
343
|
+
/**
|
|
344
|
+
* The options passed by the user when calling the plugin factory.
|
|
345
|
+
*/
|
|
346
|
+
options?: TFactory['options'];
|
|
347
|
+
/**
|
|
348
|
+
* Lifecycle event handlers for this plugin.
|
|
349
|
+
* Any event from the global `KubbHooks` map can be subscribed to here.
|
|
350
|
+
*/
|
|
351
|
+
hooks: { [K in Exclude<keyof KubbHooks, 'kubb:plugin:setup'>]?: (...args: KubbHooks[K]) => void | Promise<void> } & {
|
|
352
|
+
'kubb:plugin:setup'?(ctx: KubbPluginSetupContext<TFactory>): void | Promise<void>;
|
|
353
|
+
};
|
|
354
|
+
};
|
|
355
|
+
/**
|
|
356
|
+
* Wraps a factory function and returns a typed `Plugin` with lifecycle handlers grouped under `hooks`.
|
|
357
|
+
*
|
|
358
|
+
* Handlers live in a single `hooks` object (inspired by Astro integrations).
|
|
359
|
+
* All lifecycle events from `KubbHooks` are available for subscription.
|
|
360
|
+
*
|
|
361
|
+
* @note For real plugins, use a `PluginFactoryOptions` type parameter to get type-safe context in `kubb:plugin:setup`.
|
|
362
|
+
* Plugin names should follow the convention `plugin-<feature>` (e.g., `plugin-react-query`, `plugin-zod`).
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```ts
|
|
366
|
+
* import { definePlugin } from '@kubb/core'
|
|
367
|
+
*
|
|
368
|
+
* export const pluginTs = definePlugin((options: { prefix?: string } = {}) => ({
|
|
369
|
+
* name: 'plugin-ts',
|
|
370
|
+
* hooks: {
|
|
371
|
+
* 'kubb:plugin:setup'(ctx) {
|
|
372
|
+
* ctx.setResolver(resolverTs)
|
|
373
|
+
* },
|
|
374
|
+
* },
|
|
375
|
+
* }))
|
|
376
|
+
* ```
|
|
377
|
+
*/
|
|
378
|
+
declare function definePlugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(factory: (options: TFactory['options']) => Plugin<TFactory>): (options?: TFactory['options']) => Plugin<TFactory>;
|
|
379
|
+
//#endregion
|
|
380
|
+
//#region src/FileManager.d.ts
|
|
381
|
+
/**
|
|
382
|
+
* In-memory file store for generated files.
|
|
383
|
+
*
|
|
384
|
+
* Files with the same `path` are merged — sources, imports, and exports are concatenated.
|
|
385
|
+
* The `files` getter returns all stored files sorted by path length (shortest first).
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```ts
|
|
389
|
+
* import { FileManager } from '@kubb/core'
|
|
390
|
+
*
|
|
391
|
+
* const manager = new FileManager()
|
|
392
|
+
* manager.upsert(myFile)
|
|
393
|
+
* console.log(manager.files) // all stored files
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
declare class FileManager {
|
|
397
|
+
#private;
|
|
398
|
+
/**
|
|
399
|
+
* Adds one or more files. Incoming files with the same path are merged
|
|
400
|
+
* (sources/imports/exports concatenated), but existing cache entries are
|
|
401
|
+
* replaced — use {@link upsert} when you want to merge into the cache too.
|
|
402
|
+
*/
|
|
403
|
+
add(...files: Array<FileNode>): Array<FileNode>;
|
|
404
|
+
/**
|
|
405
|
+
* Adds or merges one or more files.
|
|
406
|
+
* If a file with the same path already exists in the cache, its
|
|
407
|
+
* sources/imports/exports are merged into the incoming file.
|
|
408
|
+
*/
|
|
409
|
+
upsert(...files: Array<FileNode>): Array<FileNode>;
|
|
410
|
+
getByPath(path: string): FileNode | null;
|
|
411
|
+
deleteByPath(path: string): void;
|
|
412
|
+
clear(): void;
|
|
413
|
+
/**
|
|
414
|
+
* All stored files, sorted by path length (shorter paths first).
|
|
415
|
+
*/
|
|
416
|
+
get files(): Array<FileNode>;
|
|
417
|
+
}
|
|
418
|
+
//#endregion
|
|
419
|
+
//#region src/PluginDriver.d.ts
|
|
420
|
+
type Options = {
|
|
421
|
+
hooks: AsyncEventEmitter<KubbHooks>;
|
|
422
|
+
};
|
|
423
|
+
declare class PluginDriver {
|
|
424
|
+
#private;
|
|
425
|
+
readonly config: Config;
|
|
426
|
+
readonly options: Options;
|
|
427
|
+
/**
|
|
428
|
+
* Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* ```ts
|
|
432
|
+
* PluginDriver.getMode('src/gen/types.ts') // 'single'
|
|
433
|
+
* PluginDriver.getMode('src/gen/types') // 'split'
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
436
|
+
static getMode(fileOrFolder: string | undefined | null): 'single' | 'split';
|
|
437
|
+
/**
|
|
438
|
+
* The universal `@kubb/ast` `InputNode` produced by the adapter, set by
|
|
439
|
+
* the build pipeline after the adapter's `parse()` resolves.
|
|
440
|
+
*/
|
|
441
|
+
inputNode: InputNode | undefined;
|
|
442
|
+
adapter: Adapter | undefined;
|
|
443
|
+
/**
|
|
444
|
+
* Central file store for all generated files.
|
|
445
|
+
* Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to
|
|
446
|
+
* add files; this property gives direct read/write access when needed.
|
|
447
|
+
*/
|
|
448
|
+
readonly fileManager: FileManager;
|
|
449
|
+
readonly plugins: Map<string, NormalizedPlugin>;
|
|
450
|
+
constructor(config: Config, options: Options);
|
|
451
|
+
get hooks(): AsyncEventEmitter<KubbHooks>;
|
|
452
|
+
/**
|
|
453
|
+
* Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.
|
|
454
|
+
*
|
|
455
|
+
* For `kubb:plugin:setup`, the registered listener wraps the globally emitted context with a
|
|
456
|
+
* plugin-specific one so that `addGenerator`, `setResolver`, `setTransformer`, and
|
|
457
|
+
* `setRenderer` all target the correct `normalizedPlugin` entry in the plugins map.
|
|
458
|
+
*
|
|
459
|
+
* All other hooks are iterated and registered directly as pass-through listeners.
|
|
460
|
+
* Any event key present in the global `KubbHooks` interface can be subscribed to.
|
|
461
|
+
*
|
|
462
|
+
* External tooling can subscribe to any of these events via `hooks.on(...)` to observe
|
|
463
|
+
* the plugin lifecycle without modifying plugin behavior.
|
|
464
|
+
*
|
|
465
|
+
* @internal
|
|
466
|
+
*/
|
|
467
|
+
registerPluginHooks(hookPlugin: Plugin, normalizedPlugin: NormalizedPlugin): void;
|
|
468
|
+
/**
|
|
469
|
+
* Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners
|
|
470
|
+
* can configure generators, resolvers, transformers and renderers before `buildStart` runs.
|
|
471
|
+
*
|
|
472
|
+
* Call this once from `safeBuild` before the plugin execution loop begins.
|
|
473
|
+
*/
|
|
474
|
+
emitSetupHooks(): Promise<void>;
|
|
475
|
+
/**
|
|
476
|
+
* Registers a generator for the given plugin on the shared event emitter.
|
|
477
|
+
*
|
|
478
|
+
* The generator's `schema`, `operation`, and `operations` methods are registered as
|
|
479
|
+
* listeners on `kubb:generate:schema`, `kubb:generate:operation`, and `kubb:generate:operations`
|
|
480
|
+
* respectively. Each listener is scoped to the owning plugin via a `ctx.plugin.name` check
|
|
481
|
+
* so that generators from different plugins do not cross-fire.
|
|
482
|
+
*
|
|
483
|
+
* The renderer resolution chain is: `generator.renderer → plugin.renderer → config.renderer`.
|
|
484
|
+
* Set `generator.renderer = null` to explicitly opt out of rendering even when the plugin
|
|
485
|
+
* declares a renderer.
|
|
486
|
+
*
|
|
487
|
+
* Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.
|
|
488
|
+
*/
|
|
489
|
+
registerGenerator(pluginName: string, gen: Generator): void;
|
|
490
|
+
/**
|
|
491
|
+
* Returns `true` when at least one generator was registered for the given plugin
|
|
492
|
+
* via `addGenerator()` in `kubb:plugin:setup` (event-based path).
|
|
493
|
+
*
|
|
494
|
+
* Used by the build loop to decide whether to walk the AST and emit generator events
|
|
495
|
+
* for a plugin that has no static `plugin.generators`.
|
|
496
|
+
*/
|
|
497
|
+
hasRegisteredGenerators(pluginName: string): boolean;
|
|
498
|
+
/**
|
|
499
|
+
* Unregisters all plugin lifecycle listeners from the shared event emitter.
|
|
500
|
+
* Called at the end of a build to prevent listener leaks across repeated builds.
|
|
501
|
+
*
|
|
502
|
+
* @internal
|
|
503
|
+
*/
|
|
504
|
+
dispose(): void;
|
|
505
|
+
/**
|
|
506
|
+
* Merges `partial` with the plugin's default resolver and stores the result.
|
|
507
|
+
* Also mirrors it onto `plugin.resolver` so callers using `getPlugin(name).resolver`
|
|
508
|
+
* get the up-to-date resolver without going through `getResolver()`.
|
|
509
|
+
*/
|
|
510
|
+
setPluginResolver(pluginName: string, partial: Partial<Resolver>): void;
|
|
511
|
+
/**
|
|
512
|
+
* Returns the resolver for the given plugin.
|
|
513
|
+
*
|
|
514
|
+
* Resolution order: dynamic resolver set via `setPluginResolver` → static resolver on the
|
|
515
|
+
* plugin → lazily created default resolver (identity name, no path transforms).
|
|
516
|
+
*/
|
|
517
|
+
getResolver<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Kubb.PluginRegistry[TName]['resolver'];
|
|
518
|
+
getResolver<TResolver extends Resolver = Resolver>(pluginName: string): TResolver;
|
|
519
|
+
getContext<TOptions extends PluginFactoryOptions>(plugin: NormalizedPlugin<TOptions>): GeneratorContext<TOptions> & Record<string, unknown>;
|
|
520
|
+
getPlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
|
|
521
|
+
getPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions> | undefined;
|
|
522
|
+
/**
|
|
523
|
+
* Like `getPlugin` but throws a descriptive error when the plugin is not found.
|
|
524
|
+
*/
|
|
525
|
+
requirePlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]>;
|
|
526
|
+
requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>;
|
|
527
|
+
}
|
|
528
|
+
//#endregion
|
|
529
|
+
//#region src/createKubb.d.ts
|
|
530
|
+
/**
|
|
531
|
+
* Full output produced by a successful or failed build.
|
|
532
|
+
*/
|
|
533
|
+
type BuildOutput = {
|
|
534
|
+
/**
|
|
535
|
+
* Plugins that threw during installation, paired with the caught error.
|
|
536
|
+
*/
|
|
537
|
+
failedPlugins: Set<{
|
|
538
|
+
plugin: Plugin;
|
|
539
|
+
error: Error;
|
|
540
|
+
}>;
|
|
541
|
+
files: Array<FileNode>;
|
|
542
|
+
driver: PluginDriver;
|
|
543
|
+
/**
|
|
544
|
+
* Elapsed time in milliseconds for each plugin, keyed by plugin name.
|
|
545
|
+
*/
|
|
546
|
+
pluginTimings: Map<string, number>;
|
|
547
|
+
error?: Error;
|
|
548
|
+
/**
|
|
549
|
+
* Raw generated source, keyed by absolute file path.
|
|
550
|
+
*/
|
|
551
|
+
sources: Map<string, string>;
|
|
552
|
+
};
|
|
553
|
+
type CreateKubbOptions = {
|
|
554
|
+
hooks?: AsyncEventEmitter<KubbHooks>;
|
|
555
|
+
};
|
|
556
|
+
/**
|
|
557
|
+
* Creates a Kubb instance bound to a single config entry.
|
|
558
|
+
*
|
|
559
|
+
* Accepts a user-facing config shape and resolves it to a full {@link Config} during
|
|
560
|
+
* `setup()`. The instance then holds shared state (`hooks`, `sources`, `driver`, `config`)
|
|
561
|
+
* across the `setup → build` lifecycle. Attach event listeners to `kubb.hooks` before
|
|
562
|
+
* calling `setup()` or `build()`.
|
|
563
|
+
*
|
|
564
|
+
* @example
|
|
565
|
+
* ```ts
|
|
566
|
+
* const kubb = createKubb(userConfig)
|
|
567
|
+
*
|
|
568
|
+
* kubb.hooks.on('kubb:plugin:end', ({ plugin, duration }) => {
|
|
569
|
+
* console.log(`${plugin.name} completed in ${duration}ms`)
|
|
570
|
+
* })
|
|
571
|
+
*
|
|
572
|
+
* const { files, failedPlugins } = await kubb.safeBuild()
|
|
573
|
+
* ```
|
|
574
|
+
*/
|
|
575
|
+
declare function createKubb(userConfig: UserConfig, options?: CreateKubbOptions): Kubb$1;
|
|
576
|
+
//#endregion
|
|
577
|
+
//#region src/Kubb.d.ts
|
|
578
|
+
/**
|
|
579
|
+
* Kubb code generation instance returned by {@link createKubb}.
|
|
580
|
+
*
|
|
581
|
+
* Use this when orchestrating multiple builds, inspecting plugin timings, or integrating Kubb into a larger toolchain.
|
|
582
|
+
* For a single one-off build, chain directly: `await createKubb(config).build()`.
|
|
583
|
+
*/
|
|
584
|
+
type Kubb$1 = {
|
|
585
|
+
/**
|
|
586
|
+
* Shared event emitter for lifecycle and status events. Attach listeners before calling `setup()` or `build()`.
|
|
587
|
+
*/
|
|
588
|
+
readonly hooks: AsyncEventEmitter<KubbHooks>;
|
|
589
|
+
/**
|
|
590
|
+
* Generated source code keyed by absolute file path. Available after `build()` or `safeBuild()` completes.
|
|
591
|
+
*/
|
|
592
|
+
readonly sources: Map<string, string>;
|
|
593
|
+
/**
|
|
594
|
+
* Plugin driver managing all plugins. Available after `setup()` completes.
|
|
595
|
+
*/
|
|
596
|
+
readonly driver: PluginDriver | undefined;
|
|
597
|
+
/**
|
|
598
|
+
* Resolved configuration with defaults applied. Available after `setup()` completes.
|
|
599
|
+
*/
|
|
600
|
+
readonly config: Config | undefined;
|
|
601
|
+
/**
|
|
602
|
+
* Resolves config and initializes the driver. `build()` calls this automatically.
|
|
603
|
+
*/
|
|
604
|
+
setup(): Promise<void>;
|
|
605
|
+
/**
|
|
606
|
+
* Runs the full pipeline and throws on any plugin error. Automatically calls `setup()` if needed.
|
|
607
|
+
*/
|
|
608
|
+
build(): Promise<BuildOutput>;
|
|
609
|
+
/**
|
|
610
|
+
* Runs the full pipeline and captures errors in `BuildOutput` instead of throwing. Automatically calls `setup()` if needed.
|
|
611
|
+
*/
|
|
612
|
+
safeBuild(): Promise<BuildOutput>;
|
|
613
|
+
};
|
|
614
|
+
/**
|
|
615
|
+
* Lifecycle events emitted during Kubb code generation.
|
|
616
|
+
* Use these for logging, progress tracking, and custom integrations.
|
|
617
|
+
*
|
|
618
|
+
* @example
|
|
619
|
+
* ```typescript
|
|
620
|
+
* import type { AsyncEventEmitter } from '@internals/utils'
|
|
621
|
+
* import type { KubbHooks } from '@kubb/core'
|
|
622
|
+
*
|
|
623
|
+
* const hooks: AsyncEventEmitter<KubbHooks> = new AsyncEventEmitter()
|
|
624
|
+
*
|
|
625
|
+
* hooks.on('kubb:lifecycle:start', () => {
|
|
626
|
+
* console.log('Starting Kubb generation')
|
|
627
|
+
* })
|
|
628
|
+
*
|
|
629
|
+
* hooks.on('kubb:plugin:end', ({ plugin, duration }) => {
|
|
630
|
+
* console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
|
|
631
|
+
* })
|
|
632
|
+
* ```
|
|
633
|
+
*/
|
|
634
|
+
interface KubbHooks {
|
|
635
|
+
/**
|
|
636
|
+
* Fires at the start of the Kubb lifecycle, before code generation begins.
|
|
637
|
+
*/
|
|
638
|
+
'kubb:lifecycle:start': [ctx: KubbLifecycleStartContext];
|
|
639
|
+
/**
|
|
640
|
+
* Fires at the end of the Kubb lifecycle, after all code generation completes.
|
|
641
|
+
*/
|
|
642
|
+
'kubb:lifecycle:end': [];
|
|
643
|
+
/**
|
|
644
|
+
* Fires when configuration loading starts.
|
|
645
|
+
*/
|
|
646
|
+
'kubb:config:start': [];
|
|
647
|
+
/**
|
|
648
|
+
* Fires when configuration loading completes.
|
|
649
|
+
*/
|
|
650
|
+
'kubb:config:end': [ctx: KubbConfigEndContext];
|
|
651
|
+
/**
|
|
652
|
+
* Fires when code generation starts.
|
|
653
|
+
*/
|
|
654
|
+
'kubb:generation:start': [ctx: KubbGenerationStartContext];
|
|
655
|
+
/**
|
|
656
|
+
* Fires when code generation completes.
|
|
657
|
+
*/
|
|
658
|
+
'kubb:generation:end': [ctx: KubbGenerationEndContext];
|
|
659
|
+
/**
|
|
660
|
+
* Fires with a generation summary including summary lines, title, and success status.
|
|
661
|
+
*/
|
|
662
|
+
'kubb:generation:summary': [ctx: KubbGenerationSummaryContext];
|
|
663
|
+
/**
|
|
664
|
+
* Fires when code formatting starts (e.g., Biome or Prettier).
|
|
665
|
+
*/
|
|
666
|
+
'kubb:format:start': [];
|
|
667
|
+
/**
|
|
668
|
+
* Fires when code formatting completes.
|
|
669
|
+
*/
|
|
670
|
+
'kubb:format:end': [];
|
|
671
|
+
/**
|
|
672
|
+
* Fires when linting starts.
|
|
673
|
+
*/
|
|
674
|
+
'kubb:lint:start': [];
|
|
675
|
+
/**
|
|
676
|
+
* Fires when linting completes.
|
|
677
|
+
*/
|
|
678
|
+
'kubb:lint:end': [];
|
|
679
|
+
/**
|
|
680
|
+
* Fires when plugin hooks execution starts.
|
|
681
|
+
*/
|
|
682
|
+
'kubb:hooks:start': [];
|
|
683
|
+
/**
|
|
684
|
+
* Fires when plugin hooks execution completes.
|
|
685
|
+
*/
|
|
686
|
+
'kubb:hooks:end': [];
|
|
687
|
+
/**
|
|
688
|
+
* Fires when a single hook executes (e.g., format or lint). The callback is invoked when the command finishes.
|
|
689
|
+
*/
|
|
690
|
+
'kubb:hook:start': [ctx: KubbHookStartContext];
|
|
691
|
+
/**
|
|
692
|
+
* Fires when a single hook execution completes.
|
|
693
|
+
*/
|
|
694
|
+
'kubb:hook:end': [ctx: KubbHookEndContext];
|
|
695
|
+
/**
|
|
696
|
+
* Fires when a new Kubb version is available.
|
|
697
|
+
*/
|
|
698
|
+
'kubb:version:new': [ctx: KubbVersionNewContext];
|
|
699
|
+
/**
|
|
700
|
+
* Informational message event.
|
|
701
|
+
*/
|
|
702
|
+
'kubb:info': [ctx: KubbInfoContext];
|
|
703
|
+
/**
|
|
704
|
+
* Error event, fired when an error occurs during generation.
|
|
705
|
+
*/
|
|
706
|
+
'kubb:error': [ctx: KubbErrorContext];
|
|
707
|
+
/**
|
|
708
|
+
* Success message event.
|
|
709
|
+
*/
|
|
710
|
+
'kubb:success': [ctx: KubbSuccessContext];
|
|
711
|
+
/**
|
|
712
|
+
* Warning message event.
|
|
713
|
+
*/
|
|
714
|
+
'kubb:warn': [ctx: KubbWarnContext];
|
|
715
|
+
/**
|
|
716
|
+
* Debug event for detailed logging with timestamp and optional filename.
|
|
717
|
+
*/
|
|
718
|
+
'kubb:debug': [ctx: KubbDebugContext];
|
|
719
|
+
/**
|
|
720
|
+
* Fires when file processing starts with the list of files to process.
|
|
721
|
+
*/
|
|
722
|
+
'kubb:files:processing:start': [ctx: KubbFilesProcessingStartContext];
|
|
723
|
+
/**
|
|
724
|
+
* Fires for each file with progress updates: processed count, total, percentage, and file details.
|
|
725
|
+
*/
|
|
726
|
+
'kubb:file:processing:update': [ctx: KubbFileProcessingUpdateContext];
|
|
727
|
+
/**
|
|
728
|
+
* Fires when file processing completes with the list of processed files.
|
|
729
|
+
*/
|
|
730
|
+
'kubb:files:processing:end': [ctx: KubbFilesProcessingEndContext];
|
|
731
|
+
/**
|
|
732
|
+
* Fires when a plugin starts execution.
|
|
733
|
+
*/
|
|
734
|
+
'kubb:plugin:start': [ctx: KubbPluginStartContext];
|
|
735
|
+
/**
|
|
736
|
+
* Fires when a plugin completes execution. Duration measured in milliseconds.
|
|
737
|
+
*/
|
|
738
|
+
'kubb:plugin:end': [ctx: KubbPluginEndContext];
|
|
739
|
+
/**
|
|
740
|
+
* Fires once before plugins execute — allowing plugins to register generators, configure resolvers/transformers/renderers, or inject files.
|
|
741
|
+
*/
|
|
742
|
+
'kubb:plugin:setup': [ctx: KubbPluginSetupContext];
|
|
743
|
+
/**
|
|
744
|
+
* Fires before the plugin execution loop begins. The adapter has already parsed the source and `inputNode` is available.
|
|
745
|
+
*/
|
|
746
|
+
'kubb:build:start': [ctx: KubbBuildStartContext];
|
|
747
|
+
/**
|
|
748
|
+
* Fires after all plugins run and per-plugin barrels generate, but before files write to disk.
|
|
749
|
+
* Use this to inject final files that must persist in the same write pass as plugin output.
|
|
750
|
+
*/
|
|
751
|
+
'kubb:plugins:end': [ctx: KubbPluginsEndContext];
|
|
752
|
+
/**
|
|
753
|
+
* Fires after all files write to disk.
|
|
754
|
+
*/
|
|
755
|
+
'kubb:build:end': [ctx: KubbBuildEndContext];
|
|
756
|
+
/**
|
|
757
|
+
* Fires for each schema node during AST traversal. Generator listeners respond to this.
|
|
758
|
+
*/
|
|
759
|
+
'kubb:generate:schema': [node: SchemaNode, ctx: GeneratorContext];
|
|
760
|
+
/**
|
|
761
|
+
* Fires for each operation node during AST traversal. Generator listeners respond to this.
|
|
762
|
+
*/
|
|
763
|
+
'kubb:generate:operation': [node: OperationNode, ctx: GeneratorContext];
|
|
764
|
+
/**
|
|
765
|
+
* Fires once after all operations traverse with the full collected array. Batch generator listeners respond to this.
|
|
766
|
+
*/
|
|
767
|
+
'kubb:generate:operations': [nodes: Array<OperationNode>, ctx: GeneratorContext];
|
|
768
|
+
}
|
|
769
|
+
declare global {
|
|
770
|
+
namespace Kubb {
|
|
771
|
+
/**
|
|
772
|
+
* Registry that maps plugin names to their `PluginFactoryOptions`.
|
|
773
|
+
* Augment this interface in each plugin's `types.ts` to enable automatic
|
|
774
|
+
* typing for `getPlugin` and `requirePlugin`.
|
|
775
|
+
*
|
|
776
|
+
* @example
|
|
777
|
+
* ```ts
|
|
778
|
+
* // packages/plugin-ts/src/types.ts
|
|
779
|
+
* declare global {
|
|
780
|
+
* namespace Kubb {
|
|
781
|
+
* interface PluginRegistry {
|
|
782
|
+
* 'plugin-ts': PluginTs
|
|
783
|
+
* }
|
|
784
|
+
* }
|
|
785
|
+
* }
|
|
786
|
+
* ```
|
|
787
|
+
*/
|
|
788
|
+
interface PluginRegistry {}
|
|
789
|
+
/**
|
|
790
|
+
* Extension point for root `Config['output']` options.
|
|
791
|
+
* Augment the `output` key in middleware or plugin packages to add extra fields
|
|
792
|
+
* to the global output configuration without touching core types.
|
|
793
|
+
*
|
|
794
|
+
* @example
|
|
795
|
+
* ```ts
|
|
796
|
+
* // packages/middleware-barrel/src/types.ts
|
|
797
|
+
* declare global {
|
|
798
|
+
* namespace Kubb {
|
|
799
|
+
* interface ConfigOptionsRegistry {
|
|
800
|
+
* output: {
|
|
801
|
+
* barrelType?: import('./types.ts').BarrelType | false
|
|
802
|
+
* }
|
|
803
|
+
* }
|
|
804
|
+
* }
|
|
805
|
+
* }
|
|
806
|
+
* ```
|
|
807
|
+
*/
|
|
808
|
+
interface ConfigOptionsRegistry {}
|
|
809
|
+
/**
|
|
810
|
+
* Extension point for per-plugin `Output` options.
|
|
811
|
+
* Augment the `output` key in middleware or plugin packages to add extra fields
|
|
812
|
+
* to the per-plugin output configuration without touching core types.
|
|
813
|
+
*
|
|
814
|
+
* @example
|
|
815
|
+
* ```ts
|
|
816
|
+
* // packages/middleware-barrel/src/types.ts
|
|
817
|
+
* declare global {
|
|
818
|
+
* namespace Kubb {
|
|
819
|
+
* interface PluginOptionsRegistry {
|
|
820
|
+
* output: {
|
|
821
|
+
* barrelType?: import('./types.ts').BarrelType | false
|
|
822
|
+
* }
|
|
823
|
+
* }
|
|
824
|
+
* }
|
|
825
|
+
* }
|
|
826
|
+
* ```
|
|
827
|
+
*/
|
|
828
|
+
interface PluginOptionsRegistry {}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
//#endregion
|
|
832
|
+
//#region src/defineMiddleware.d.ts
|
|
833
|
+
/**
|
|
834
|
+
* A middleware instance produced by calling a factory created with `defineMiddleware`.
|
|
835
|
+
* It declares event handlers under a `hooks` object which are registered on the
|
|
836
|
+
* shared emitter after all plugin hooks, so middleware handlers for any event
|
|
837
|
+
* always fire last.
|
|
838
|
+
*/
|
|
839
|
+
type Middleware = {
|
|
840
|
+
/**
|
|
841
|
+
* Unique identifier for this middleware.
|
|
842
|
+
*/
|
|
843
|
+
name: string;
|
|
844
|
+
/**
|
|
845
|
+
* Lifecycle event handlers for this middleware.
|
|
846
|
+
* Any event from the global `KubbHooks` map can be subscribed to here.
|
|
847
|
+
* Handlers are registered after all plugin handlers, so they always fire last.
|
|
848
|
+
*/
|
|
849
|
+
hooks: { [K in keyof KubbHooks]?: (...args: KubbHooks[K]) => void | Promise<void> };
|
|
850
|
+
};
|
|
851
|
+
/**
|
|
852
|
+
* Creates a middleware factory using the hook-style `hooks` API.
|
|
853
|
+
*
|
|
854
|
+
* Middleware handlers fire after all plugin handlers for any given event, making them ideal for post-processing, logging, and auditing.
|
|
855
|
+
* Per-build state (such as accumulators) belongs inside the factory closure so each `createKubb` invocation gets its own isolated instance.
|
|
856
|
+
*
|
|
857
|
+
* @note The factory can accept typed options. See examples for using options and per-build state patterns.
|
|
858
|
+
*
|
|
859
|
+
* @example
|
|
860
|
+
* ```ts
|
|
861
|
+
* import { defineMiddleware } from '@kubb/core'
|
|
862
|
+
*
|
|
863
|
+
* // Stateless middleware
|
|
864
|
+
* export const logMiddleware = defineMiddleware(() => ({
|
|
865
|
+
* name: 'log-middleware',
|
|
866
|
+
* hooks: {
|
|
867
|
+
* 'kubb:build:end'({ files }) {
|
|
868
|
+
* console.log(`Build complete with ${files.length} files`)
|
|
869
|
+
* },
|
|
870
|
+
* },
|
|
871
|
+
* }))
|
|
872
|
+
*
|
|
873
|
+
* // Middleware with options and per-build state
|
|
874
|
+
* export const prefixMiddleware = defineMiddleware((options: { prefix: string } = { prefix: '' }) => {
|
|
875
|
+
* const seen = new Set<string>()
|
|
876
|
+
* return {
|
|
877
|
+
* name: 'prefix-middleware',
|
|
878
|
+
* hooks: {
|
|
879
|
+
* 'kubb:plugin:end'({ plugin }) {
|
|
880
|
+
* seen.add(`${options.prefix}${plugin.name}`)
|
|
881
|
+
* },
|
|
882
|
+
* },
|
|
883
|
+
* }
|
|
884
|
+
* })
|
|
885
|
+
* ```
|
|
886
|
+
*/
|
|
887
|
+
declare function defineMiddleware<TOptions extends object = object>(factory: (options: TOptions) => Middleware): (options?: TOptions) => Middleware;
|
|
888
|
+
//#endregion
|
|
889
|
+
//#region src/defineParser.d.ts
|
|
890
|
+
type PrintOptions = {
|
|
891
|
+
extname?: FileNode['extname'];
|
|
892
|
+
};
|
|
893
|
+
type Parser<TMeta extends object = any> = {
|
|
894
|
+
name: string;
|
|
895
|
+
/**
|
|
896
|
+
* File extensions this parser handles.
|
|
897
|
+
* Use `undefined` to create a catch-all fallback parser.
|
|
898
|
+
*
|
|
899
|
+
* @example Handled extensions
|
|
900
|
+
* `['.ts', '.js']`
|
|
901
|
+
*/
|
|
902
|
+
extNames: Array<FileNode['extname']> | undefined;
|
|
903
|
+
/**
|
|
904
|
+
* Convert a resolved file to a string.
|
|
905
|
+
*/
|
|
906
|
+
parse(file: FileNode<TMeta>, options?: PrintOptions): Promise<string> | string;
|
|
907
|
+
};
|
|
908
|
+
/**
|
|
909
|
+
* Defines a parser with type safety. Creates parsers that transform generated files to strings based on their extension.
|
|
910
|
+
*
|
|
911
|
+
* @note Call the returned factory with optional options to instantiate the parser.
|
|
912
|
+
*
|
|
913
|
+
* @example
|
|
914
|
+
* ```ts
|
|
915
|
+
* import { defineParser } from '@kubb/core'
|
|
916
|
+
*
|
|
917
|
+
* export const jsonParser = defineParser({
|
|
918
|
+
* name: 'json',
|
|
919
|
+
* extNames: ['.json'],
|
|
920
|
+
* parse(file) {
|
|
921
|
+
* const { extractStringsFromNodes } = await import('@kubb/ast')
|
|
922
|
+
* return file.sources.map((s) => extractStringsFromNodes(s.nodes ?? [])).join('\n')
|
|
923
|
+
* },
|
|
924
|
+
* })
|
|
925
|
+
* ```
|
|
926
|
+
*/
|
|
927
|
+
declare function defineParser<TMeta extends object = any>(parser: Parser<TMeta>): Parser<TMeta>;
|
|
928
|
+
//#endregion
|
|
929
|
+
//#region src/types.d.ts
|
|
930
|
+
/**
|
|
931
|
+
* Safely extracts a type from a registry, returning `{}` if the key doesn't exist.
|
|
932
|
+
* Enables optional interface augmentation for `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry`
|
|
933
|
+
* without requiring changes to core.
|
|
934
|
+
*
|
|
935
|
+
* @internal
|
|
936
|
+
*/
|
|
937
|
+
type ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {};
|
|
938
|
+
/**
|
|
939
|
+
* Reference to an input file to generate code from.
|
|
940
|
+
*
|
|
941
|
+
* Specify an absolute path or a path relative to the config file location.
|
|
942
|
+
* The adapter will parse this file (e.g., OpenAPI YAML or JSON) into the universal AST.
|
|
943
|
+
*/
|
|
944
|
+
type InputPath = {
|
|
945
|
+
/**
|
|
946
|
+
* Path to your Swagger/OpenAPI file, absolute or relative to the config file location.
|
|
947
|
+
*
|
|
948
|
+
* @example
|
|
949
|
+
* ```ts
|
|
950
|
+
* { path: './petstore.yaml' }
|
|
951
|
+
* { path: '/absolute/path/to/openapi.json' }
|
|
952
|
+
* ```
|
|
953
|
+
*/
|
|
954
|
+
path: string;
|
|
955
|
+
};
|
|
956
|
+
/**
|
|
957
|
+
* Inline input data to generate code from.
|
|
958
|
+
*
|
|
959
|
+
* Useful when you want to pass the specification directly instead of from a file.
|
|
960
|
+
* Can be a string (YAML/JSON) or a parsed object.
|
|
961
|
+
*/
|
|
962
|
+
type InputData = {
|
|
963
|
+
/**
|
|
964
|
+
* Swagger/OpenAPI data as a string (YAML/JSON) or a parsed object.
|
|
965
|
+
*
|
|
966
|
+
* @example
|
|
967
|
+
* ```ts
|
|
968
|
+
* { data: fs.readFileSync('./openapi.yaml', 'utf8') }
|
|
969
|
+
* { data: { openapi: '3.1.0', info: { ... } } }
|
|
970
|
+
* ```
|
|
971
|
+
*/
|
|
972
|
+
data: string | unknown;
|
|
973
|
+
};
|
|
974
|
+
type Input = InputPath | InputData;
|
|
975
|
+
/**
|
|
976
|
+
* Source data passed to an adapter's `parse` function.
|
|
977
|
+
* Mirrors the config input shape with paths resolved to absolute.
|
|
978
|
+
*/
|
|
979
|
+
type AdapterSource = {
|
|
980
|
+
type: 'path';
|
|
981
|
+
path: string;
|
|
982
|
+
} | {
|
|
983
|
+
type: 'data';
|
|
984
|
+
data: string | unknown;
|
|
985
|
+
} | {
|
|
986
|
+
type: 'paths';
|
|
987
|
+
paths: Array<string>;
|
|
988
|
+
};
|
|
989
|
+
/**
|
|
990
|
+
* Generic type parameters for an adapter definition.
|
|
991
|
+
*
|
|
992
|
+
* - `TName` — unique identifier (e.g. `'oas'`, `'asyncapi'`)
|
|
993
|
+
* - `TOptions` — user-facing options passed to the adapter factory
|
|
994
|
+
* - `TResolvedOptions` — options after defaults applied
|
|
995
|
+
* - `TDocument` — type of the parsed source document
|
|
996
|
+
*/
|
|
997
|
+
type AdapterFactoryOptions<TName extends string = string, TOptions extends object = object, TResolvedOptions extends object = TOptions, TDocument = unknown> = {
|
|
998
|
+
name: TName;
|
|
999
|
+
options: TOptions;
|
|
1000
|
+
resolvedOptions: TResolvedOptions;
|
|
1001
|
+
document: TDocument;
|
|
1002
|
+
};
|
|
1003
|
+
/**
|
|
1004
|
+
* Adapter that converts input files or data into an `InputNode`.
|
|
1005
|
+
*
|
|
1006
|
+
* Adapters parse different schema formats (OpenAPI, AsyncAPI, Drizzle, etc.) into Kubb's
|
|
1007
|
+
* universal intermediate representation that all plugins consume.
|
|
1008
|
+
*
|
|
1009
|
+
* @example
|
|
1010
|
+
* ```ts
|
|
1011
|
+
* import { adapterOas } from '@kubb/adapter-oas'
|
|
1012
|
+
*
|
|
1013
|
+
* export default defineConfig({
|
|
1014
|
+
* adapter: adapterOas(),
|
|
1015
|
+
* input: { path: './openapi.yaml' },
|
|
1016
|
+
* plugins: [pluginTs(), pluginZod()],
|
|
1017
|
+
* })
|
|
1018
|
+
* ```
|
|
1019
|
+
*/
|
|
1020
|
+
type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
1021
|
+
/**
|
|
1022
|
+
* Human-readable adapter identifier (e.g. `'oas'`, `'asyncapi'`).
|
|
1023
|
+
*/
|
|
1024
|
+
name: TOptions['name'];
|
|
1025
|
+
/**
|
|
1026
|
+
* Resolved adapter options after defaults have been applied.
|
|
1027
|
+
*/
|
|
1028
|
+
options: TOptions['resolvedOptions'];
|
|
1029
|
+
/**
|
|
1030
|
+
* Parsed source document after the first `parse()` call. `null` before parsing.
|
|
1031
|
+
*/
|
|
1032
|
+
document: TOptions['document'] | null;
|
|
1033
|
+
inputNode: InputNode | null;
|
|
1034
|
+
/**
|
|
1035
|
+
* Parse the source into a universal `InputNode`.
|
|
1036
|
+
*/
|
|
1037
|
+
parse: (source: AdapterSource) => PossiblePromise<InputNode>;
|
|
1038
|
+
/**
|
|
1039
|
+
* Extract `ImportNode` entries for a schema tree.
|
|
1040
|
+
* Returns an empty array before the first `parse()` call.
|
|
1041
|
+
*
|
|
1042
|
+
* The `resolve` callback receives the collision-corrected schema name and must
|
|
1043
|
+
* return `{ name, path }` for the import, or `undefined` to skip it.
|
|
1044
|
+
*/
|
|
1045
|
+
getImports: (node: SchemaNode, resolve: (schemaName: string) => {
|
|
1046
|
+
name: string;
|
|
1047
|
+
path: string;
|
|
1048
|
+
}) => Array<ImportNode>;
|
|
1049
|
+
};
|
|
1050
|
+
type DevtoolsOptions = {
|
|
1051
|
+
/**
|
|
1052
|
+
* Open the AST inspector in Kubb Studio (`/ast`). Defaults to the main Studio page.
|
|
1053
|
+
* @default false
|
|
1054
|
+
*/
|
|
1055
|
+
ast?: boolean;
|
|
1056
|
+
};
|
|
1057
|
+
/**
|
|
1058
|
+
* Build configuration for Kubb code generation.
|
|
1059
|
+
*
|
|
1060
|
+
* The Config is the main entry point for customizing how Kubb generates code. It specifies:
|
|
1061
|
+
* - What to generate from (adapter + input)
|
|
1062
|
+
* - Where to output generated code (output)
|
|
1063
|
+
* - How to generate (plugins + middleware)
|
|
1064
|
+
* - Runtime details (parsers, storage, renderer)
|
|
1065
|
+
*
|
|
1066
|
+
* See `UserConfig` for a relaxed version with sensible defaults.
|
|
1067
|
+
*
|
|
1068
|
+
* @private
|
|
1069
|
+
*/
|
|
1070
|
+
type Config<TInput = Input> = {
|
|
1071
|
+
/**
|
|
1072
|
+
* Display name for this configuration in CLI output and logs.
|
|
1073
|
+
* Useful when running multiple builds with `defineConfig` arrays.
|
|
1074
|
+
*
|
|
1075
|
+
* @example
|
|
1076
|
+
* ```ts
|
|
1077
|
+
* name: 'api-client'
|
|
1078
|
+
* ```
|
|
1079
|
+
*/
|
|
1080
|
+
name?: string;
|
|
1081
|
+
/**
|
|
1082
|
+
* Project root directory, absolute or relative to the config file.
|
|
1083
|
+
* @default process.cwd()
|
|
1084
|
+
*/
|
|
1085
|
+
root: string;
|
|
1086
|
+
/**
|
|
1087
|
+
* Parsers that convert generated files to strings.
|
|
1088
|
+
* Each parser handles specific extensions (e.g. `.ts`, `.tsx`).
|
|
1089
|
+
* A fallback parser is appended for unhandled extensions.
|
|
1090
|
+
* When omitted, defaults to `parserTs` from `@kubb/parser-ts`.
|
|
1091
|
+
*
|
|
1092
|
+
* @default [parserTs] from `@kubb/parser-ts`
|
|
1093
|
+
* @example
|
|
1094
|
+
* ```ts
|
|
1095
|
+
* import { parserTs, tsxParser } from '@kubb/parser-ts'
|
|
1096
|
+
* export default defineConfig({
|
|
1097
|
+
* parsers: [parserTs, tsxParser],
|
|
1098
|
+
* })
|
|
1099
|
+
* ```
|
|
1100
|
+
*/
|
|
1101
|
+
parsers: Array<Parser>;
|
|
1102
|
+
/**
|
|
1103
|
+
* Adapter that parses input files into the universal `InputNode` representation.
|
|
1104
|
+
* Use `@kubb/adapter-oas` for OpenAPI/Swagger or `@kubb/adapter-asyncapi` for other formats.
|
|
1105
|
+
*
|
|
1106
|
+
* @example
|
|
1107
|
+
* ```ts
|
|
1108
|
+
* import { adapterOas } from '@kubb/adapter-oas'
|
|
1109
|
+
* export default defineConfig({
|
|
1110
|
+
* adapter: adapterOas(),
|
|
1111
|
+
* input: { path: './petstore.yaml' },
|
|
1112
|
+
* })
|
|
1113
|
+
* ```
|
|
1114
|
+
*/
|
|
1115
|
+
adapter: Adapter;
|
|
1116
|
+
/**
|
|
1117
|
+
* Source file or data to generate code from.
|
|
1118
|
+
* Use `input.path` for a file path or `input.data` for inline data.
|
|
1119
|
+
*/
|
|
1120
|
+
input: TInput;
|
|
1121
|
+
output: {
|
|
1122
|
+
/**
|
|
1123
|
+
* Output directory for generated files, absolute or relative to `root`.
|
|
1124
|
+
*
|
|
1125
|
+
* All generated files will be written under this directory. Subdirectories can be created
|
|
1126
|
+
* by plugins based on grouping strategy (by tag, path, etc.).
|
|
1127
|
+
*
|
|
1128
|
+
* @example
|
|
1129
|
+
* ```ts
|
|
1130
|
+
* output: {
|
|
1131
|
+
* path: './src/gen', // generates ./src/gen/api.ts, ./src/gen/types.ts, etc.
|
|
1132
|
+
* }
|
|
1133
|
+
* ```
|
|
1134
|
+
*/
|
|
1135
|
+
path: string;
|
|
1136
|
+
/**
|
|
1137
|
+
* Remove all files from the output directory before starting the build.
|
|
1138
|
+
*
|
|
1139
|
+
* Useful to ensure old generated files aren't mixed with new ones.
|
|
1140
|
+
* Set to `true` for fresh builds, `false` to preserve manual edits in output dir.
|
|
1141
|
+
*
|
|
1142
|
+
* @default false
|
|
1143
|
+
* @example
|
|
1144
|
+
* ```ts
|
|
1145
|
+
* clean: true // wipes ./src/gen/* before generating
|
|
1146
|
+
* ```
|
|
1147
|
+
*/
|
|
1148
|
+
clean?: boolean;
|
|
1149
|
+
/**
|
|
1150
|
+
* Persists generated files to the file system.
|
|
1151
|
+
*
|
|
1152
|
+
* @default true
|
|
1153
|
+
* @deprecated Use `storage` option to control where files are written instead.
|
|
1154
|
+
*/
|
|
1155
|
+
write?: boolean;
|
|
1156
|
+
/**
|
|
1157
|
+
* Auto-format generated files after code generation completes.
|
|
1158
|
+
*
|
|
1159
|
+
* Applies a code formatter to all generated files. Use `'auto'` to detect which formatter
|
|
1160
|
+
* is available on your system. Pass `false` to skip formatting (useful for CI or specific workflows).
|
|
1161
|
+
*
|
|
1162
|
+
* @default false
|
|
1163
|
+
* @example
|
|
1164
|
+
* ```ts
|
|
1165
|
+
* format: 'auto' // auto-detect prettier, biome, or oxfmt
|
|
1166
|
+
* format: 'prettier' // force prettier
|
|
1167
|
+
* format: false // skip formatting
|
|
1168
|
+
* ```
|
|
1169
|
+
*/
|
|
1170
|
+
format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false;
|
|
1171
|
+
/**
|
|
1172
|
+
* Auto-lint generated files after code generation completes.
|
|
1173
|
+
*
|
|
1174
|
+
* Analyzes all generated files for style/correctness issues. Use `'auto'` to detect which linter
|
|
1175
|
+
* is available on your system. Pass `false` to skip linting.
|
|
1176
|
+
*
|
|
1177
|
+
* @default false
|
|
1178
|
+
* @example
|
|
1179
|
+
* ```ts
|
|
1180
|
+
* lint: 'auto' // auto-detect oxlint, biome, or eslint
|
|
1181
|
+
* lint: 'eslint' // force eslint
|
|
1182
|
+
* lint: false // skip linting
|
|
1183
|
+
* ```
|
|
1184
|
+
*/
|
|
1185
|
+
lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false;
|
|
1186
|
+
/**
|
|
1187
|
+
* Map file extensions to different output extensions.
|
|
1188
|
+
*
|
|
1189
|
+
* Useful when you want generated `.ts` imports to reference `.js` files or vice versa (e.g., for ESM dual packages).
|
|
1190
|
+
* Keys are the original extension, values are the output extension. Use empty string `''` to omit extension.
|
|
1191
|
+
*
|
|
1192
|
+
* @default { '.ts': '.ts' }
|
|
1193
|
+
* @example
|
|
1194
|
+
* ```ts
|
|
1195
|
+
* extension: { '.ts': '.js' } // generates import './api.js' instead of './api.ts'
|
|
1196
|
+
* extension: { '.ts': '', '.tsx': '.jsx' }
|
|
1197
|
+
* ```
|
|
1198
|
+
*/
|
|
1199
|
+
extension?: Record<FileNode['extname'], FileNode['extname'] | ''>;
|
|
1200
|
+
/**
|
|
1201
|
+
* Banner text prepended to every generated file.
|
|
1202
|
+
*
|
|
1203
|
+
* Useful for auto-generation notices or license headers. Choose a preset or write custom text.
|
|
1204
|
+
* Use `'simple'` for a basic Kubb banner, `'full'` for detailed metadata, or `false` to omit.
|
|
1205
|
+
*
|
|
1206
|
+
* @default 'simple'
|
|
1207
|
+
* @example
|
|
1208
|
+
* ```ts
|
|
1209
|
+
* defaultBanner: 'simple' // "This file was autogenerated by Kubb"
|
|
1210
|
+
* defaultBanner: 'full' // adds source, title, description, API version
|
|
1211
|
+
* defaultBanner: false // no banner
|
|
1212
|
+
* ```
|
|
1213
|
+
*/
|
|
1214
|
+
defaultBanner?: 'simple' | 'full' | false;
|
|
1215
|
+
/**
|
|
1216
|
+
* When `true`, overwrites existing files. When `false`, skips generated files that already exist.
|
|
1217
|
+
*
|
|
1218
|
+
* Individual plugins can override this setting. This is useful for preventing accidental data loss
|
|
1219
|
+
* when re-generating while you have local edits in the output folder.
|
|
1220
|
+
*
|
|
1221
|
+
* @default false
|
|
1222
|
+
* @example
|
|
1223
|
+
* ```ts
|
|
1224
|
+
* override: true // regenerate everything, even existing files
|
|
1225
|
+
* override: false // skip files that already exist
|
|
1226
|
+
* ```
|
|
1227
|
+
*/
|
|
1228
|
+
override?: boolean;
|
|
1229
|
+
} & ExtractRegistryKey<Kubb.ConfigOptionsRegistry, 'output'>;
|
|
1230
|
+
/**
|
|
1231
|
+
* Storage backend that controls where and how generated files are persisted.
|
|
1232
|
+
*
|
|
1233
|
+
* Defaults to `fsStorage()` which writes to the file system. Pass `memoryStorage()` to keep files in RAM,
|
|
1234
|
+
* or implement a custom `Storage` interface to write to cloud storage, databases, or other backends.
|
|
1235
|
+
*
|
|
1236
|
+
* @default fsStorage()
|
|
1237
|
+
* @example
|
|
1238
|
+
* ```ts
|
|
1239
|
+
* import { memoryStorage } from '@kubb/core'
|
|
1240
|
+
*
|
|
1241
|
+
* // Keep generated files in memory (useful for testing, CI pipelines)
|
|
1242
|
+
* storage: memoryStorage()
|
|
1243
|
+
*
|
|
1244
|
+
* // Use custom S3 storage
|
|
1245
|
+
* storage: myS3Storage()
|
|
1246
|
+
* ```
|
|
1247
|
+
*
|
|
1248
|
+
* @see {@link Storage} interface for implementing custom backends.
|
|
1249
|
+
*/
|
|
1250
|
+
storage?: Storage;
|
|
1251
|
+
/**
|
|
1252
|
+
* Plugins that execute during the build to generate code and transform the AST.
|
|
1253
|
+
*
|
|
1254
|
+
* Each plugin processes the AST produced by the adapter and can emit files for different
|
|
1255
|
+
* programming languages or formats (TypeScript, Zod schemas, Faker data, etc.).
|
|
1256
|
+
* Dependencies are enforced — an error is thrown if a plugin requires another plugin that isn't registered.
|
|
1257
|
+
*
|
|
1258
|
+
* Plugins can declare their own options via `PluginFactoryOptions`. See plugin documentation for details.
|
|
1259
|
+
*
|
|
1260
|
+
* @example
|
|
1261
|
+
* ```ts
|
|
1262
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
1263
|
+
* import { pluginZod } from '@kubb/plugin-zod'
|
|
1264
|
+
*
|
|
1265
|
+
* plugins: [
|
|
1266
|
+
* pluginTs({ output: { path: './src/gen' } }),
|
|
1267
|
+
* pluginZod({ output: { path: './src/gen' } }),
|
|
1268
|
+
* ]
|
|
1269
|
+
* ```
|
|
1270
|
+
*/
|
|
1271
|
+
plugins: Array<Plugin>;
|
|
1272
|
+
/**
|
|
1273
|
+
* Middleware instances that observe build events and post-process generated code.
|
|
1274
|
+
*
|
|
1275
|
+
* Middleware fires AFTER all plugins for each event. Perfect for tasks like:
|
|
1276
|
+
* - Auditing what was generated
|
|
1277
|
+
* - Adding barrel/index files
|
|
1278
|
+
* - Validating output
|
|
1279
|
+
* - Running custom transformations
|
|
1280
|
+
*
|
|
1281
|
+
* @example
|
|
1282
|
+
* ```ts
|
|
1283
|
+
* import { middlewareBarrel } from '@kubb/middleware-barrel'
|
|
1284
|
+
*
|
|
1285
|
+
* middleware: [middlewareBarrel()]
|
|
1286
|
+
* ```
|
|
1287
|
+
*
|
|
1288
|
+
* @see {@link defineMiddleware} to create custom middleware.
|
|
1289
|
+
*/
|
|
1290
|
+
middleware?: Array<Middleware>;
|
|
1291
|
+
/**
|
|
1292
|
+
* Default renderer factory used by all plugins and generators.
|
|
1293
|
+
* Resolution chain: `generator.renderer` → `plugin.renderer` → `config.renderer` → `undefined` (raw FileNode[] mode).
|
|
1294
|
+
*
|
|
1295
|
+
* @example
|
|
1296
|
+
* ```ts
|
|
1297
|
+
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
1298
|
+
* export default defineConfig({
|
|
1299
|
+
* renderer: jsxRenderer,
|
|
1300
|
+
* plugins: [pluginTs(), pluginZod()],
|
|
1301
|
+
* })
|
|
1302
|
+
* ```
|
|
1303
|
+
*/
|
|
1304
|
+
/**
|
|
1305
|
+
* Renderer that converts generated AST nodes to code strings.
|
|
1306
|
+
*
|
|
1307
|
+
* By default, Kubb uses the JSX renderer (`rendererJsx`). Pass a custom renderer to support
|
|
1308
|
+
* different output formats (template engines, code generation DSLs, etc.).
|
|
1309
|
+
*
|
|
1310
|
+
* @default rendererJsx() // from @kubb/renderer-jsx
|
|
1311
|
+
* @example
|
|
1312
|
+
* ```ts
|
|
1313
|
+
* import { rendererJsx } from '@kubb/renderer-jsx'
|
|
1314
|
+
* renderer: rendererJsx()
|
|
1315
|
+
* ```
|
|
1316
|
+
*
|
|
1317
|
+
* @see {@link Renderer} to implement a custom renderer.
|
|
1318
|
+
*/
|
|
1319
|
+
renderer?: RendererFactory;
|
|
1320
|
+
/**
|
|
1321
|
+
* Kubb Studio cloud integration settings.
|
|
1322
|
+
*
|
|
1323
|
+
* Kubb Studio (https://studio.kubb.dev) is a web-based IDE for managing API specs and generated code.
|
|
1324
|
+
* Set to `true` to enable with default settings, or pass an object to customize the Studio URL.
|
|
1325
|
+
*
|
|
1326
|
+
* @default false // disabled by default
|
|
1327
|
+
* @example
|
|
1328
|
+
* ```ts
|
|
1329
|
+
* devtools: true // use default Kubb Studio
|
|
1330
|
+
* devtools: { studioUrl: 'https://my-studio.dev' } // custom Studio instance
|
|
1331
|
+
* ```
|
|
1332
|
+
*/
|
|
1333
|
+
devtools?: true | {
|
|
1334
|
+
/**
|
|
1335
|
+
* Override the Kubb Studio base URL.
|
|
1336
|
+
* @default 'https://studio.kubb.dev'
|
|
1337
|
+
*/
|
|
1338
|
+
studioUrl?: typeof DEFAULT_STUDIO_URL | (string & {});
|
|
1339
|
+
};
|
|
1340
|
+
/**
|
|
1341
|
+
* Lifecycle hooks that execute during or after the build process.
|
|
1342
|
+
*
|
|
1343
|
+
* Hooks allow you to run external tools (prettier, eslint, custom scripts) based on build events.
|
|
1344
|
+
* Currently supports the `done` hook which fires after all plugins and middleware complete.
|
|
1345
|
+
*
|
|
1346
|
+
* @example
|
|
1347
|
+
* ```ts
|
|
1348
|
+
* hooks: {
|
|
1349
|
+
* done: 'prettier --write "./src/gen"', // auto-format generated files
|
|
1350
|
+
* // or multiple commands:
|
|
1351
|
+
* done: ['prettier --write "./src/gen"', 'eslint --fix "./src/gen"']
|
|
1352
|
+
* }
|
|
1353
|
+
* ```
|
|
1354
|
+
*/
|
|
1355
|
+
hooks?: {
|
|
1356
|
+
/**
|
|
1357
|
+
* Command(s) to run after all plugins and middleware complete generation.
|
|
1358
|
+
*
|
|
1359
|
+
* Useful for post-processing: formatting, linting, copying files, or custom validation.
|
|
1360
|
+
* Pass a single command string or array of command strings to run sequentially.
|
|
1361
|
+
* Commands are executed relative to the `root` directory.
|
|
1362
|
+
*
|
|
1363
|
+
* @example
|
|
1364
|
+
* ```ts
|
|
1365
|
+
* done: 'prettier --write "./src/gen"'
|
|
1366
|
+
* done: ['prettier --write "./src/gen"', 'eslint --fix "./src/gen"']
|
|
1367
|
+
* ```
|
|
1368
|
+
*/
|
|
1369
|
+
done?: string | Array<string>;
|
|
1370
|
+
};
|
|
1371
|
+
};
|
|
1372
|
+
/**
|
|
1373
|
+
* Type/string pattern filter for include/exclude/override matching.
|
|
1374
|
+
*/
|
|
1375
|
+
type PatternFilter = {
|
|
1376
|
+
type: string;
|
|
1377
|
+
pattern: string | RegExp;
|
|
1378
|
+
};
|
|
1379
|
+
/**
|
|
1380
|
+
* Pattern filter with partial option overrides applied when the pattern matches.
|
|
1381
|
+
*/
|
|
1382
|
+
type PatternOverride<TOptions> = PatternFilter & {
|
|
1383
|
+
options: Omit<Partial<TOptions>, 'override'>;
|
|
1384
|
+
};
|
|
1385
|
+
/**
|
|
1386
|
+
* Context for resolving filtered options for a given operation or schema node.
|
|
1387
|
+
*
|
|
1388
|
+
* @internal
|
|
1389
|
+
*/
|
|
1390
|
+
type ResolveOptionsContext<TOptions> = {
|
|
1391
|
+
options: TOptions;
|
|
1392
|
+
exclude?: Array<PatternFilter>;
|
|
1393
|
+
include?: Array<PatternFilter>;
|
|
1394
|
+
override?: Array<PatternOverride<TOptions>>;
|
|
1395
|
+
};
|
|
1396
|
+
/**
|
|
1397
|
+
* Base constraint for all plugin resolver objects.
|
|
1398
|
+
*
|
|
1399
|
+
* `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`
|
|
1400
|
+
* are injected automatically by `defineResolver` — extend this type to add custom resolution methods.
|
|
1401
|
+
*
|
|
1402
|
+
* @example
|
|
1403
|
+
* ```ts
|
|
1404
|
+
* type MyResolver = Resolver & {
|
|
1405
|
+
* resolveName(node: SchemaNode): string
|
|
1406
|
+
* resolveTypedName(node: SchemaNode): string
|
|
1407
|
+
* }
|
|
1408
|
+
* ```
|
|
1409
|
+
*/
|
|
1410
|
+
type Resolver = {
|
|
1411
|
+
name: string;
|
|
1412
|
+
pluginName: Plugin['name'];
|
|
1413
|
+
default(name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
|
|
1414
|
+
resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null;
|
|
1415
|
+
resolvePath(params: ResolverPathParams, context: ResolverContext): string;
|
|
1416
|
+
resolveFile(params: ResolverFileParams, context: ResolverContext): FileNode;
|
|
1417
|
+
resolveBanner(node: InputNode | null, context: ResolveBannerContext): string | undefined;
|
|
1418
|
+
resolveFooter(node: InputNode | null, context: ResolveBannerContext): string | undefined;
|
|
1419
|
+
};
|
|
1420
|
+
type PluginFactoryOptions<
|
|
1421
|
+
/**
|
|
1422
|
+
* Unique plugin name.
|
|
1423
|
+
*/
|
|
1424
|
+
TName extends string = string,
|
|
1425
|
+
/**
|
|
1426
|
+
* User-facing plugin options.
|
|
1427
|
+
*/
|
|
1428
|
+
TOptions extends object = object,
|
|
1429
|
+
/**
|
|
1430
|
+
* Plugin options after defaults are applied.
|
|
1431
|
+
*/
|
|
1432
|
+
TResolvedOptions extends object = TOptions,
|
|
1433
|
+
/**
|
|
1434
|
+
* Resolver that encapsulates naming and path-resolution helpers.
|
|
1435
|
+
* Define with `defineResolver` and export alongside the plugin.
|
|
1436
|
+
*/
|
|
1437
|
+
TResolver extends Resolver = Resolver> = {
|
|
1438
|
+
name: TName;
|
|
1439
|
+
options: TOptions;
|
|
1440
|
+
resolvedOptions: TResolvedOptions;
|
|
1441
|
+
resolver: TResolver;
|
|
1442
|
+
};
|
|
1443
|
+
/**
|
|
1444
|
+
* Normalized plugin after setup, with runtime fields populated.
|
|
1445
|
+
* For internal use only — plugins use the public `Plugin` type externally.
|
|
1446
|
+
*
|
|
1447
|
+
* @internal
|
|
1448
|
+
*/
|
|
1449
|
+
type NormalizedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & {
|
|
1450
|
+
options: TOptions['resolvedOptions'] & {
|
|
1451
|
+
output: Output;
|
|
1452
|
+
include?: Array<Include>;
|
|
1453
|
+
exclude: Array<Exclude$1>;
|
|
1454
|
+
override: Array<Override<TOptions['resolvedOptions']>>;
|
|
1455
|
+
};
|
|
1456
|
+
resolver: TOptions['resolver'];
|
|
1457
|
+
transformer?: Visitor;
|
|
1458
|
+
renderer?: RendererFactory;
|
|
1459
|
+
generators?: Array<Generator>;
|
|
1460
|
+
apply?: (config: Config) => boolean;
|
|
1461
|
+
version?: string;
|
|
1462
|
+
};
|
|
1463
|
+
/**
|
|
1464
|
+
* Partial `Config` for user-facing entry points with sensible defaults.
|
|
1465
|
+
*
|
|
1466
|
+
* `UserConfig` is what you pass to `defineConfig()`. It has optional `root`, `plugins`, `parsers`, and `adapter`
|
|
1467
|
+
* fields (which fall back to sensible defaults). All other Config options are available, including `output`, `input`,
|
|
1468
|
+
* `storage`, `middleware`, `renderer`, `devtools`, and `hooks`.
|
|
1469
|
+
*
|
|
1470
|
+
* @example
|
|
1471
|
+
* ```ts
|
|
1472
|
+
* export default defineConfig({
|
|
1473
|
+
* input: { path: './petstore.yaml' },
|
|
1474
|
+
* output: { path: './src/gen' },
|
|
1475
|
+
* plugins: [pluginTs(), pluginZod()],
|
|
1476
|
+
* })
|
|
1477
|
+
* ```
|
|
1478
|
+
*/
|
|
1479
|
+
type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter'> & {
|
|
1480
|
+
/**
|
|
1481
|
+
* Project root directory, absolute or relative to the config file location.
|
|
1482
|
+
*
|
|
1483
|
+
* Used as the base path for `root`-relative paths (e.g., `output.path`, file paths in hooks).
|
|
1484
|
+
*
|
|
1485
|
+
* @default process.cwd()
|
|
1486
|
+
* @example
|
|
1487
|
+
* ```ts
|
|
1488
|
+
* root: '/home/user/my-project'
|
|
1489
|
+
* root: './my-project' // relative to config file
|
|
1490
|
+
* ```
|
|
1491
|
+
*/
|
|
1492
|
+
root?: string;
|
|
1493
|
+
/**
|
|
1494
|
+
* Custom parsers that convert generated AST nodes to strings (TypeScript, JSON, markdown, etc.).
|
|
1495
|
+
*
|
|
1496
|
+
* Each parser handles a specific file type. By default, Kubb uses `parserTs` from `@kubb/parser-ts` for TypeScript files.
|
|
1497
|
+
* Pass custom parsers to support additional languages or custom formats.
|
|
1498
|
+
*
|
|
1499
|
+
* @default [parserTs] // from @kubb/parser-ts
|
|
1500
|
+
* @example
|
|
1501
|
+
* ```ts
|
|
1502
|
+
* import { parserTs } from '@kubb/parser-ts'
|
|
1503
|
+
* import { parserJsonSchema } from '@kubb/parser-json-schema'
|
|
1504
|
+
*
|
|
1505
|
+
* parsers: [parserTs(), parserJsonSchema()]
|
|
1506
|
+
* ```
|
|
1507
|
+
*
|
|
1508
|
+
* @see {@link Parser} to implement a custom parser.
|
|
1509
|
+
*/
|
|
1510
|
+
parsers?: Array<Parser>;
|
|
1511
|
+
/**
|
|
1512
|
+
* Adapter that parses your API specification (OpenAPI, GraphQL, AsyncAPI, etc.) into Kubb's universal AST.
|
|
1513
|
+
*
|
|
1514
|
+
* The adapter bridge between your input format and Kubb's internal representation. By default, uses the OAS adapter.
|
|
1515
|
+
* Pass an alternative adapter (or multiple configs with different adapters) to support different spec formats.
|
|
1516
|
+
*
|
|
1517
|
+
* @default new OasAdapter() // from @kubb/adapter-oas
|
|
1518
|
+
* @example
|
|
1519
|
+
* ```ts
|
|
1520
|
+
* import { Oas } from '@kubb/adapter-oas'
|
|
1521
|
+
*
|
|
1522
|
+
* adapter: new Oas({ apiVersion: '3.0.0' })
|
|
1523
|
+
* ```
|
|
1524
|
+
*
|
|
1525
|
+
* @see {@link Adapter} to implement a custom adapter for GraphQL or other formats.
|
|
1526
|
+
*/
|
|
1527
|
+
adapter?: Adapter;
|
|
1528
|
+
/**
|
|
1529
|
+
* Plugins that execute during the build to generate code and transform the AST.
|
|
1530
|
+
*
|
|
1531
|
+
* Each plugin processes the AST produced by the adapter and can emit files for different
|
|
1532
|
+
* programming languages or formats (TypeScript, Zod schemas, Faker data, etc.).
|
|
1533
|
+
*
|
|
1534
|
+
* @default [] // no plugins (useful for setup/testing)
|
|
1535
|
+
* @example
|
|
1536
|
+
* ```ts
|
|
1537
|
+
* plugins: [
|
|
1538
|
+
* pluginTs({ output: { path: './src/gen' } }),
|
|
1539
|
+
* pluginZod({ output: { path: './src/gen' } }),
|
|
1540
|
+
* ]
|
|
1541
|
+
* ```
|
|
1542
|
+
*
|
|
1543
|
+
* @see {@link definePlugin} to create a custom plugin.
|
|
1544
|
+
*/
|
|
1545
|
+
plugins?: Array<Plugin>;
|
|
1546
|
+
};
|
|
1547
|
+
type ResolveNameParams = {
|
|
1548
|
+
name: string;
|
|
1549
|
+
pluginName?: string;
|
|
1550
|
+
/**
|
|
1551
|
+
* Entity type being named.
|
|
1552
|
+
* - `'file'` — file name (camelCase)
|
|
1553
|
+
* - `'function'` — exported function name (camelCase)
|
|
1554
|
+
* - `'type'` — TypeScript type name (PascalCase)
|
|
1555
|
+
* - `'const'` — variable name (camelCase)
|
|
1556
|
+
*/
|
|
1557
|
+
type?: 'file' | 'function' | 'type' | 'const';
|
|
1558
|
+
};
|
|
1559
|
+
/**
|
|
1560
|
+
* Context object passed to generator `schema`, `operation`, and `operations` methods.
|
|
1561
|
+
*
|
|
1562
|
+
* The adapter is always defined (guaranteed by `runPluginAstHooks`) so no runtime checks
|
|
1563
|
+
* are needed. `ctx.options` carries resolved per-node options after exclude/include/override
|
|
1564
|
+
* filtering for individual schema/operation calls, or plugin-level options for operations.
|
|
1565
|
+
*/
|
|
1566
|
+
type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1567
|
+
config: Config;
|
|
1568
|
+
/**
|
|
1569
|
+
* Absolute path to the current plugin's output directory.
|
|
1570
|
+
*/
|
|
1571
|
+
root: string;
|
|
1572
|
+
/**
|
|
1573
|
+
* Determine output mode based on the output config.
|
|
1574
|
+
* Returns `'single'` when `output.path` is a file, `'split'` for a directory.
|
|
1575
|
+
*/
|
|
1576
|
+
getMode: (output: {
|
|
1577
|
+
path: string;
|
|
1578
|
+
}) => 'single' | 'split';
|
|
1579
|
+
driver: PluginDriver;
|
|
1580
|
+
/**
|
|
1581
|
+
* Get a plugin by name, typed via `Kubb.PluginRegistry` when registered.
|
|
1582
|
+
*/
|
|
1583
|
+
getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
|
|
1584
|
+
getPlugin(name: string): Plugin | undefined;
|
|
1585
|
+
/**
|
|
1586
|
+
* Get a plugin by name, throws an error if not found.
|
|
1587
|
+
*/
|
|
1588
|
+
requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>;
|
|
1589
|
+
requirePlugin(name: string): Plugin;
|
|
1590
|
+
/**
|
|
1591
|
+
* Get a resolver by plugin name, typed via `Kubb.PluginRegistry` when registered.
|
|
1592
|
+
*/
|
|
1593
|
+
getResolver<TName extends keyof Kubb.PluginRegistry>(name: TName): Kubb.PluginRegistry[TName]['resolver'];
|
|
1594
|
+
getResolver(name: string): Resolver;
|
|
1595
|
+
/**
|
|
1596
|
+
* Add files only if they don't exist.
|
|
1597
|
+
*/
|
|
1598
|
+
addFile: (...file: Array<FileNode>) => Promise<void>;
|
|
1599
|
+
/**
|
|
1600
|
+
* Merge sources into the same output file.
|
|
1601
|
+
*/
|
|
1602
|
+
upsertFile: (...file: Array<FileNode>) => Promise<void>;
|
|
1603
|
+
hooks: AsyncEventEmitter<KubbHooks>;
|
|
1604
|
+
/**
|
|
1605
|
+
* The current plugin instance.
|
|
1606
|
+
*/
|
|
1607
|
+
plugin: Plugin<TOptions>;
|
|
1608
|
+
/**
|
|
1609
|
+
* The current plugin's resolver.
|
|
1610
|
+
*/
|
|
1611
|
+
resolver: TOptions['resolver'];
|
|
1612
|
+
/**
|
|
1613
|
+
* The current plugin's transformer.
|
|
1614
|
+
*/
|
|
1615
|
+
transformer: Visitor | undefined;
|
|
1616
|
+
/**
|
|
1617
|
+
* Emit a warning.
|
|
1618
|
+
*/
|
|
1619
|
+
warn: (message: string) => void;
|
|
1620
|
+
/**
|
|
1621
|
+
* Emit an error.
|
|
1622
|
+
*/
|
|
1623
|
+
error: (error: string | Error) => void;
|
|
1624
|
+
/**
|
|
1625
|
+
* Emit an info message.
|
|
1626
|
+
*/
|
|
1627
|
+
info: (message: string) => void;
|
|
1628
|
+
/**
|
|
1629
|
+
* Open the current input node in Kubb Studio.
|
|
1630
|
+
*/
|
|
1631
|
+
openInStudio: (options?: DevtoolsOptions) => Promise<void>;
|
|
1632
|
+
/**
|
|
1633
|
+
* The configured adapter instance.
|
|
1634
|
+
*/
|
|
1635
|
+
adapter: Adapter;
|
|
1636
|
+
/**
|
|
1637
|
+
* The universal `InputNode` produced by the adapter.
|
|
1638
|
+
*/
|
|
1639
|
+
inputNode: InputNode;
|
|
1640
|
+
/**
|
|
1641
|
+
* Resolved options after exclude/include/override filtering.
|
|
1642
|
+
*/
|
|
1643
|
+
options: TOptions['resolvedOptions'];
|
|
1644
|
+
};
|
|
1645
|
+
/**
|
|
1646
|
+
* Output configuration for generated files.
|
|
1647
|
+
*/
|
|
1648
|
+
type Output<_TOptions = unknown> = {
|
|
1649
|
+
/**
|
|
1650
|
+
* Output folder or file path for generated code.
|
|
1651
|
+
*/
|
|
1652
|
+
path: string;
|
|
1653
|
+
/**
|
|
1654
|
+
* Text or function prepended to every generated file.
|
|
1655
|
+
* When a function, receives the current `InputNode` and returns a string.
|
|
1656
|
+
*/
|
|
1657
|
+
banner?: string | ((node?: InputNode) => string);
|
|
1658
|
+
/**
|
|
1659
|
+
* Text or function appended to every generated file.
|
|
1660
|
+
* When a function, receives the current `InputNode` and returns a string.
|
|
1661
|
+
*/
|
|
1662
|
+
footer?: string | ((node?: InputNode) => string);
|
|
1663
|
+
/**
|
|
1664
|
+
* Whether to override existing external files if they already exist.
|
|
1665
|
+
* @default false
|
|
1666
|
+
*/
|
|
1667
|
+
override?: boolean;
|
|
1668
|
+
} & ExtractRegistryKey<Kubb.PluginOptionsRegistry, 'output'>;
|
|
1669
|
+
type Group = {
|
|
1670
|
+
/**
|
|
1671
|
+
* How to group files into subdirectories.
|
|
1672
|
+
* - `'tag'` — group by OpenAPI tags
|
|
1673
|
+
* - `'path'` — group by OpenAPI paths
|
|
1674
|
+
*/
|
|
1675
|
+
type: 'tag' | 'path';
|
|
1676
|
+
/**
|
|
1677
|
+
* Function that returns the subdirectory name for a group value.
|
|
1678
|
+
* Defaults to `${camelCase(group)}Controller` for tags, first path segment for paths.
|
|
1679
|
+
*/
|
|
1680
|
+
name?: (context: {
|
|
1681
|
+
group: string;
|
|
1682
|
+
}) => string;
|
|
1683
|
+
};
|
|
1684
|
+
type LoggerOptions = {
|
|
1685
|
+
/**
|
|
1686
|
+
* Log level for output verbosity.
|
|
1687
|
+
* @default 3
|
|
1688
|
+
*/
|
|
1689
|
+
logLevel: (typeof logLevel)[keyof typeof logLevel];
|
|
1690
|
+
};
|
|
1691
|
+
/**
|
|
1692
|
+
* Shared context passed to plugins, parsers, and other internals.
|
|
1693
|
+
*/
|
|
1694
|
+
type LoggerContext = AsyncEventEmitter<KubbHooks>;
|
|
1695
|
+
type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
|
|
1696
|
+
name: string;
|
|
1697
|
+
install: (context: LoggerContext, options?: TOptions) => void | Promise<void>;
|
|
1698
|
+
};
|
|
1699
|
+
type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Logger<TOptions>;
|
|
1700
|
+
/**
|
|
1701
|
+
* Context for hook-style plugin `kubb:plugin:setup` handler.
|
|
1702
|
+
* Provides methods to register generators, configure resolvers, transformers, and renderers.
|
|
1703
|
+
*/
|
|
1704
|
+
type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1705
|
+
/**
|
|
1706
|
+
* Register a generator dynamically. Generators fire during the AST walk (schema/operation/operations)
|
|
1707
|
+
* just like generators declared statically on `createPlugin`.
|
|
1708
|
+
*/
|
|
1709
|
+
addGenerator<TElement = unknown>(generator: Generator<TFactory, TElement>): void;
|
|
1710
|
+
/**
|
|
1711
|
+
* Set or override the resolver for this plugin.
|
|
1712
|
+
* The resolver controls file naming and path resolution.
|
|
1713
|
+
*/
|
|
1714
|
+
setResolver(resolver: Partial<TFactory['resolver']>): void;
|
|
1715
|
+
/**
|
|
1716
|
+
* Set the AST transformer to pre-process nodes before they reach generators.
|
|
1717
|
+
*/
|
|
1718
|
+
setTransformer(visitor: Visitor): void;
|
|
1719
|
+
/**
|
|
1720
|
+
* Set the renderer factory to process JSX elements from generators.
|
|
1721
|
+
*/
|
|
1722
|
+
setRenderer(renderer: RendererFactory): void;
|
|
1723
|
+
/**
|
|
1724
|
+
* Set resolved options merged into the normalized plugin's `options`.
|
|
1725
|
+
* Call this in `kubb:plugin:setup` to provide options generators need.
|
|
1726
|
+
*/
|
|
1727
|
+
setOptions(options: TFactory['resolvedOptions']): void;
|
|
1728
|
+
/**
|
|
1729
|
+
* Inject a raw file into the build output, bypassing the generation pipeline.
|
|
1730
|
+
*/
|
|
1731
|
+
injectFile(userFileNode: UserFileNode): void;
|
|
1732
|
+
/**
|
|
1733
|
+
* Merge a partial config update into the current build configuration.
|
|
1734
|
+
*/
|
|
1735
|
+
updateConfig(config: Partial<Config>): void;
|
|
1736
|
+
/**
|
|
1737
|
+
* The resolved build configuration at setup time.
|
|
1738
|
+
*/
|
|
1739
|
+
config: Config;
|
|
1740
|
+
/**
|
|
1741
|
+
* The plugin's user-provided options.
|
|
1742
|
+
*/
|
|
1743
|
+
options: TFactory['options'];
|
|
1744
|
+
};
|
|
1745
|
+
/**
|
|
1746
|
+
* Context for hook-style plugin `kubb:build:start` handler.
|
|
1747
|
+
* Fires immediately before the plugin execution loop begins.
|
|
1748
|
+
*/
|
|
1749
|
+
type KubbBuildStartContext = {
|
|
1750
|
+
config: Config;
|
|
1751
|
+
adapter: Adapter;
|
|
1752
|
+
inputNode: InputNode;
|
|
1753
|
+
/**
|
|
1754
|
+
* Get a plugin by name, typed via `Kubb.PluginRegistry` when registered.
|
|
1755
|
+
*/
|
|
1756
|
+
getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
|
|
1757
|
+
getPlugin(name: string): Plugin | undefined;
|
|
1758
|
+
/**
|
|
1759
|
+
* Get all files currently in the file manager.
|
|
1760
|
+
* Call this lazily (e.g. in `kubb:plugin:end`) to see files added by prior plugins.
|
|
1761
|
+
*/
|
|
1762
|
+
readonly files: ReadonlyArray<FileNode>;
|
|
1763
|
+
/**
|
|
1764
|
+
* Upsert one or more files into the file manager.
|
|
1765
|
+
* Files with the same path are merged; new files are appended.
|
|
1766
|
+
* Safe to call at any point during the plugin lifecycle, including inside `kubb:plugin:end`.
|
|
1767
|
+
*/
|
|
1768
|
+
upsertFile: (...files: Array<FileNode>) => void;
|
|
1769
|
+
};
|
|
1770
|
+
/**
|
|
1771
|
+
* Context for `kubb:plugins:end` handlers.
|
|
1772
|
+
* Fires after plugins run and per-plugin barrels are written, before final write to disk.
|
|
1773
|
+
* Middleware that needs final files (e.g. root barrel) use this event.
|
|
1774
|
+
*/
|
|
1775
|
+
type KubbPluginsEndContext = {
|
|
1776
|
+
config: Config;
|
|
1777
|
+
/**
|
|
1778
|
+
* All files currently in the file manager (lazy snapshot).
|
|
1779
|
+
*/
|
|
1780
|
+
readonly files: ReadonlyArray<FileNode>;
|
|
1781
|
+
/**
|
|
1782
|
+
* Upsert files into the file manager.
|
|
1783
|
+
* Files added here are included in the write pass.
|
|
1784
|
+
*/
|
|
1785
|
+
upsertFile: (...files: Array<FileNode>) => void;
|
|
1786
|
+
};
|
|
1787
|
+
/**
|
|
1788
|
+
* Context for hook-style plugin `kubb:build:end` handler.
|
|
1789
|
+
* Fires after all files have been written to disk.
|
|
1790
|
+
*/
|
|
1791
|
+
type KubbBuildEndContext = {
|
|
1792
|
+
files: Array<FileNode>;
|
|
1793
|
+
config: Config;
|
|
1794
|
+
outputDir: string;
|
|
1795
|
+
};
|
|
1796
|
+
type KubbLifecycleStartContext = {
|
|
1797
|
+
version: string;
|
|
1798
|
+
};
|
|
1799
|
+
type KubbConfigEndContext = {
|
|
1800
|
+
configs: Array<Config>;
|
|
1801
|
+
};
|
|
1802
|
+
type KubbGenerationStartContext = {
|
|
1803
|
+
config: Config;
|
|
1804
|
+
};
|
|
1805
|
+
type KubbGenerationEndContext = {
|
|
1806
|
+
config: Config;
|
|
1807
|
+
files: Array<FileNode>;
|
|
1808
|
+
sources: Map<string, string>;
|
|
1809
|
+
};
|
|
1810
|
+
type KubbGenerationSummaryContext = {
|
|
1811
|
+
config: Config;
|
|
1812
|
+
failedPlugins: Set<{
|
|
1813
|
+
plugin: Plugin;
|
|
1814
|
+
error: Error;
|
|
1815
|
+
}>;
|
|
1816
|
+
status: 'success' | 'failed';
|
|
1817
|
+
hrStart: [number, number];
|
|
1818
|
+
filesCreated: number;
|
|
1819
|
+
pluginTimings?: Map<Plugin['name'], number>;
|
|
1820
|
+
};
|
|
1821
|
+
type KubbVersionNewContext = {
|
|
1822
|
+
currentVersion: string;
|
|
1823
|
+
latestVersion: string;
|
|
1824
|
+
};
|
|
1825
|
+
type KubbInfoContext = {
|
|
1826
|
+
message: string;
|
|
1827
|
+
info?: string;
|
|
1828
|
+
};
|
|
1829
|
+
type KubbErrorContext = {
|
|
1830
|
+
error: Error;
|
|
1831
|
+
meta?: Record<string, unknown>;
|
|
1832
|
+
};
|
|
1833
|
+
type KubbSuccessContext = {
|
|
1834
|
+
message: string;
|
|
1835
|
+
info?: string;
|
|
1836
|
+
};
|
|
1837
|
+
type KubbWarnContext = {
|
|
1838
|
+
message: string;
|
|
1839
|
+
info?: string;
|
|
1840
|
+
};
|
|
1841
|
+
type KubbDebugContext = {
|
|
1842
|
+
date: Date;
|
|
1843
|
+
logs: Array<string>;
|
|
1844
|
+
fileName?: string;
|
|
1845
|
+
};
|
|
1846
|
+
type KubbFilesProcessingStartContext = {
|
|
1847
|
+
files: Array<FileNode>;
|
|
1848
|
+
};
|
|
1849
|
+
type KubbFileProcessingUpdateContext = {
|
|
1850
|
+
/**
|
|
1851
|
+
* Number of files processed.
|
|
1852
|
+
*/
|
|
1853
|
+
processed: number;
|
|
1854
|
+
/**
|
|
1855
|
+
* Total files to process.
|
|
1856
|
+
*/
|
|
1857
|
+
total: number;
|
|
1858
|
+
/**
|
|
1859
|
+
* Processing percentage (0–100).
|
|
1860
|
+
*/
|
|
1861
|
+
percentage: number;
|
|
1862
|
+
/**
|
|
1863
|
+
* Optional source identifier.
|
|
1864
|
+
*/
|
|
1865
|
+
source?: string;
|
|
1866
|
+
/**
|
|
1867
|
+
* The file being processed.
|
|
1868
|
+
*/
|
|
1869
|
+
file: FileNode;
|
|
1870
|
+
/**
|
|
1871
|
+
* The current build configuration.
|
|
1872
|
+
*/
|
|
1873
|
+
config: Config;
|
|
1874
|
+
};
|
|
1875
|
+
type KubbFilesProcessingEndContext = {
|
|
1876
|
+
files: Array<FileNode>;
|
|
1877
|
+
};
|
|
1878
|
+
type KubbPluginStartContext = {
|
|
1879
|
+
plugin: NormalizedPlugin;
|
|
1880
|
+
};
|
|
1881
|
+
type KubbPluginEndContext = {
|
|
1882
|
+
plugin: NormalizedPlugin;
|
|
1883
|
+
duration: number;
|
|
1884
|
+
success: boolean;
|
|
1885
|
+
error?: Error;
|
|
1886
|
+
config: Config;
|
|
1887
|
+
/**
|
|
1888
|
+
* Returns all files currently in the file manager (lazy snapshot).
|
|
1889
|
+
* Includes files added by plugins that have already run.
|
|
1890
|
+
*/
|
|
1891
|
+
readonly files: ReadonlyArray<FileNode>;
|
|
1892
|
+
/**
|
|
1893
|
+
* Upsert one or more files into the file manager.
|
|
1894
|
+
*/
|
|
1895
|
+
upsertFile: (...files: Array<FileNode>) => void;
|
|
1896
|
+
};
|
|
1897
|
+
type KubbHookStartContext = {
|
|
1898
|
+
id?: string;
|
|
1899
|
+
command: string;
|
|
1900
|
+
args?: readonly string[];
|
|
1901
|
+
};
|
|
1902
|
+
type KubbHookEndContext = {
|
|
1903
|
+
id?: string;
|
|
1904
|
+
command: string;
|
|
1905
|
+
args?: readonly string[];
|
|
1906
|
+
success: boolean;
|
|
1907
|
+
error: Error | null;
|
|
1908
|
+
};
|
|
1909
|
+
type ByTag = {
|
|
1910
|
+
/**
|
|
1911
|
+
* Filter by OpenAPI `tags` field. Matches one or more tags assigned to operations.
|
|
1912
|
+
*/
|
|
1913
|
+
type: 'tag';
|
|
1914
|
+
/**
|
|
1915
|
+
* Tag name to match (case-sensitive). Can be a literal string or regex pattern.
|
|
1916
|
+
*/
|
|
1917
|
+
pattern: string | RegExp;
|
|
1918
|
+
};
|
|
1919
|
+
type ByOperationId = {
|
|
1920
|
+
/**
|
|
1921
|
+
* Filter by OpenAPI `operationId` field. Each operation (GET, POST, etc.) has a unique identifier.
|
|
1922
|
+
*/
|
|
1923
|
+
type: 'operationId';
|
|
1924
|
+
/**
|
|
1925
|
+
* Operation ID to match (case-sensitive). Can be a literal string or regex pattern.
|
|
1926
|
+
*/
|
|
1927
|
+
pattern: string | RegExp;
|
|
1928
|
+
};
|
|
1929
|
+
type ByPath = {
|
|
1930
|
+
/**
|
|
1931
|
+
* Filter by OpenAPI `path` (URL endpoint). Useful to group or filter by service segments like `/pets`, `/users`, etc.
|
|
1932
|
+
*/
|
|
1933
|
+
type: 'path';
|
|
1934
|
+
/**
|
|
1935
|
+
* URL path to match (case-sensitive). Can be a literal string or regex pattern. Matches against the full path.
|
|
1936
|
+
*/
|
|
1937
|
+
pattern: string | RegExp;
|
|
1938
|
+
};
|
|
1939
|
+
type ByMethod = {
|
|
1940
|
+
/**
|
|
1941
|
+
* Filter by HTTP method: `'get'`, `'post'`, `'put'`, `'delete'`, `'patch'`, `'head'`, `'options'`.
|
|
1942
|
+
*/
|
|
1943
|
+
type: 'method';
|
|
1944
|
+
/**
|
|
1945
|
+
* HTTP method to match (case-insensitive when using string, or regex for dynamic matching).
|
|
1946
|
+
*/
|
|
1947
|
+
pattern: HttpMethod | RegExp;
|
|
1948
|
+
};
|
|
1949
|
+
type BySchemaName = {
|
|
1950
|
+
/**
|
|
1951
|
+
* Filter by schema component name (TypeScript or JSON schema). Matches schemas in `#/components/schemas`.
|
|
1952
|
+
*/
|
|
1953
|
+
type: 'schemaName';
|
|
1954
|
+
/**
|
|
1955
|
+
* Schema name to match (case-sensitive). Can be a literal string or regex pattern.
|
|
1956
|
+
*/
|
|
1957
|
+
pattern: string | RegExp;
|
|
1958
|
+
};
|
|
1959
|
+
type ByContentType = {
|
|
1960
|
+
/**
|
|
1961
|
+
* Filter by response or request content type: `'application/json'`, `'application/xml'`, etc.
|
|
1962
|
+
*/
|
|
1963
|
+
type: 'contentType';
|
|
1964
|
+
/**
|
|
1965
|
+
* Content type to match (case-sensitive). Can be a literal string or regex pattern.
|
|
1966
|
+
*/
|
|
1967
|
+
pattern: string | RegExp;
|
|
1968
|
+
};
|
|
1969
|
+
/**
|
|
1970
|
+
* A pattern filter that prevents matching nodes from being generated.
|
|
1971
|
+
*
|
|
1972
|
+
* Use to skip code generation for specific operations or schemas. For example, exclude deprecated endpoints
|
|
1973
|
+
* or internal-only schemas. Can filter by tag, operationId, path, HTTP method, content type, or schema name.
|
|
1974
|
+
*
|
|
1975
|
+
* @example
|
|
1976
|
+
* ```ts
|
|
1977
|
+
* exclude: [
|
|
1978
|
+
* { type: 'tag', pattern: 'internal' }, // skip "internal" tag
|
|
1979
|
+
* { type: 'path', pattern: /^\/admin/ }, // skip all /admin endpoints
|
|
1980
|
+
* { type: 'operationId', pattern: 'deprecated_*' } // skip operationIds matching pattern
|
|
1981
|
+
* ]
|
|
1982
|
+
* ```
|
|
1983
|
+
*/
|
|
1984
|
+
type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
|
|
1985
|
+
/**
|
|
1986
|
+
* A pattern filter that restricts generation to only matching nodes.
|
|
1987
|
+
*
|
|
1988
|
+
* Use to generate code for a subset of operations or schemas. For example, only generate for a specific service
|
|
1989
|
+
* tag or only for "production" endpoints. Can filter by tag, operationId, path, HTTP method, content type, or schema name.
|
|
1990
|
+
*
|
|
1991
|
+
* @example
|
|
1992
|
+
* ```ts
|
|
1993
|
+
* include: [
|
|
1994
|
+
* { type: 'tag', pattern: 'public' }, // generate only "public" tag
|
|
1995
|
+
* { type: 'path', pattern: /^\/api\/v1/ }, // generate only v1 endpoints
|
|
1996
|
+
* ]
|
|
1997
|
+
* ```
|
|
1998
|
+
*/
|
|
1999
|
+
type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
|
|
2000
|
+
/**
|
|
2001
|
+
* A pattern filter paired with partial option overrides applied when the pattern matches.
|
|
2002
|
+
*
|
|
2003
|
+
* Use to customize generation for specific operations or schemas. For example, apply different output paths
|
|
2004
|
+
* for different tags, or use custom resolver functions per operation. Can filter by tag, operationId, path,
|
|
2005
|
+
* HTTP method, schema name, or content type.
|
|
2006
|
+
*
|
|
2007
|
+
* @example
|
|
2008
|
+
* ```ts
|
|
2009
|
+
* override: [
|
|
2010
|
+
* {
|
|
2011
|
+
* type: 'tag',
|
|
2012
|
+
* pattern: 'admin',
|
|
2013
|
+
* options: { output: { path: './src/gen/admin' } } // admin APIs go to separate folder
|
|
2014
|
+
* },
|
|
2015
|
+
* {
|
|
2016
|
+
* type: 'operationId',
|
|
2017
|
+
* pattern: 'listPets',
|
|
2018
|
+
* options: { exclude: true } // skip this specific operation
|
|
2019
|
+
* }
|
|
2020
|
+
* ]
|
|
2021
|
+
* ```
|
|
2022
|
+
*/
|
|
2023
|
+
type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
2024
|
+
options: Partial<TOptions>;
|
|
2025
|
+
};
|
|
2026
|
+
/**
|
|
2027
|
+
* File-specific parameters for `Resolver.resolvePath`.
|
|
2028
|
+
*
|
|
2029
|
+
* Pass alongside a `ResolverContext` to identify which file to resolve.
|
|
2030
|
+
* Provide `tag` for tag-based grouping or `path` for path-based grouping.
|
|
2031
|
+
*
|
|
2032
|
+
* @example
|
|
2033
|
+
* ```ts
|
|
2034
|
+
* resolver.resolvePath(
|
|
2035
|
+
* { baseName: 'petTypes.ts', tag: 'pets' },
|
|
2036
|
+
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
2037
|
+
* )
|
|
2038
|
+
* // → '/src/types/petsController/petTypes.ts'
|
|
2039
|
+
* ```
|
|
2040
|
+
*/
|
|
2041
|
+
type ResolverPathParams = {
|
|
2042
|
+
baseName: FileNode['baseName'];
|
|
2043
|
+
pathMode?: 'single' | 'split';
|
|
2044
|
+
/**
|
|
2045
|
+
* Tag value used when `group.type === 'tag'`.
|
|
2046
|
+
*/
|
|
2047
|
+
tag?: string;
|
|
2048
|
+
/**
|
|
2049
|
+
* Path value used when `group.type === 'path'`.
|
|
2050
|
+
*/
|
|
2051
|
+
path?: string;
|
|
2052
|
+
};
|
|
2053
|
+
/**
|
|
2054
|
+
* Shared context passed as the second argument to `Resolver.resolvePath` and `Resolver.resolveFile`.
|
|
2055
|
+
*
|
|
2056
|
+
* Describes where on disk output is rooted, which output config is active, and the optional
|
|
2057
|
+
* grouping strategy that controls subdirectory layout.
|
|
2058
|
+
*
|
|
2059
|
+
* @example
|
|
2060
|
+
* ```ts
|
|
2061
|
+
* const context: ResolverContext = {
|
|
2062
|
+
* root: config.root,
|
|
2063
|
+
* output,
|
|
2064
|
+
* group,
|
|
2065
|
+
* }
|
|
2066
|
+
* ```
|
|
2067
|
+
*/
|
|
2068
|
+
type ResolverContext = {
|
|
2069
|
+
root: string;
|
|
2070
|
+
output: Output;
|
|
2071
|
+
group?: Group;
|
|
2072
|
+
/**
|
|
2073
|
+
* Plugin name used to populate `meta.pluginName` on the resolved file.
|
|
2074
|
+
*/
|
|
2075
|
+
pluginName?: string;
|
|
2076
|
+
};
|
|
2077
|
+
/**
|
|
2078
|
+
* File-specific parameters for `Resolver.resolveFile`.
|
|
2079
|
+
*
|
|
2080
|
+
* Pass alongside a `ResolverContext` to fully describe the file to resolve.
|
|
2081
|
+
* `tag` and `path` are used only when a matching `group` is present in the context.
|
|
2082
|
+
*
|
|
2083
|
+
* @example
|
|
2084
|
+
* ```ts
|
|
2085
|
+
* resolver.resolveFile(
|
|
2086
|
+
* { name: 'listPets', extname: '.ts', tag: 'pets' },
|
|
2087
|
+
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
2088
|
+
* )
|
|
2089
|
+
* // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
|
|
2090
|
+
* ```
|
|
2091
|
+
*/
|
|
2092
|
+
type ResolverFileParams = {
|
|
2093
|
+
name: string;
|
|
2094
|
+
extname: FileNode['extname'];
|
|
2095
|
+
/**
|
|
2096
|
+
* Tag value used when `group.type === 'tag'`.
|
|
2097
|
+
*/
|
|
2098
|
+
tag?: string;
|
|
2099
|
+
/**
|
|
2100
|
+
* Path value used when `group.type === 'path'`.
|
|
2101
|
+
*/
|
|
2102
|
+
path?: string;
|
|
2103
|
+
};
|
|
2104
|
+
/**
|
|
2105
|
+
* Context passed to `Resolver.resolveBanner` and `Resolver.resolveFooter`.
|
|
2106
|
+
*
|
|
2107
|
+
* `output` is optional — not every plugin configures a banner/footer.
|
|
2108
|
+
* `config` carries the global Kubb config, used to derive the default Kubb banner.
|
|
2109
|
+
*
|
|
2110
|
+
* @example
|
|
2111
|
+
* ```ts
|
|
2112
|
+
* resolver.resolveBanner(inputNode, { output: { banner: '// generated' }, config })
|
|
2113
|
+
* // → '// generated'
|
|
2114
|
+
* ```
|
|
2115
|
+
*/
|
|
2116
|
+
type ResolveBannerContext = {
|
|
2117
|
+
output?: Pick<Output, 'banner' | 'footer'>;
|
|
2118
|
+
config: Config;
|
|
2119
|
+
};
|
|
2120
|
+
/**
|
|
2121
|
+
* CLI options derived from command-line flags.
|
|
2122
|
+
*/
|
|
2123
|
+
type CLIOptions = {
|
|
2124
|
+
/**
|
|
2125
|
+
* Path to `kubb.config.js`.
|
|
2126
|
+
*/
|
|
2127
|
+
config?: string;
|
|
2128
|
+
/**
|
|
2129
|
+
* Enable watch mode for input files.
|
|
2130
|
+
*/
|
|
2131
|
+
watch?: boolean;
|
|
2132
|
+
/**
|
|
2133
|
+
* Logging verbosity for CLI usage.
|
|
2134
|
+
* @default 'silent'
|
|
2135
|
+
*/
|
|
2136
|
+
logLevel?: 'silent' | 'info' | 'debug';
|
|
2137
|
+
};
|
|
2138
|
+
/**
|
|
2139
|
+
* All accepted forms of a Kubb configuration.
|
|
2140
|
+
*
|
|
2141
|
+
* Config is always `@kubb/core` {@link Config}.
|
|
2142
|
+
* - `PossibleConfig` accepts `Config`/`Config[]`/promise or a no-arg config factory.
|
|
2143
|
+
* - `PossibleConfig<TCliOptions>` accepts the same config forms or a config factory receiving `TCliOptions`.
|
|
2144
|
+
*/
|
|
2145
|
+
type PossibleConfig<TCliOptions = undefined> = PossiblePromise<Config | Config[]> | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Config[]>);
|
|
2146
|
+
//#endregion
|
|
2147
|
+
export { defineParser as $, KubbPluginStartContext as A, Override as B, KubbGenerationSummaryContext as C, KubbLifecycleStartContext as D, KubbInfoContext as E, Logger as F, ResolveOptionsContext as G, PossibleConfig as H, LoggerContext as I, ResolverFileParams as J, Resolver as K, LoggerOptions as L, KubbSuccessContext as M, KubbVersionNewContext as N, KubbPluginEndContext as O, KubbWarnContext as P, Parser as Q, NormalizedPlugin as R, KubbGenerationStartContext as S, KubbHookStartContext as T, ResolveBannerContext as U, PluginFactoryOptions as V, ResolveNameParams as W, UserConfig as X, ResolverPathParams as Y, UserLogger as Z, KubbErrorContext as _, logLevel as _t, Config as a, createKubb as at, KubbFilesProcessingStartContext as b, GeneratorContext as c, Plugin as ct, InputData as d, defineGenerator as dt, Middleware as et, InputPath as f, Storage as ft, KubbDebugContext as g, createRenderer as gt, KubbConfigEndContext as h, RendererFactory as ht, CLIOptions as i, BuildOutput as it, KubbPluginsEndContext as j, KubbPluginSetupContext as k, Group as l, definePlugin as lt, KubbBuildStartContext as m, Renderer as mt, AdapterFactoryOptions as n, Kubb$1 as nt, DevtoolsOptions as o, PluginDriver as ot, KubbBuildEndContext as p, createStorage as pt, ResolverContext as q, AdapterSource as r, KubbHooks as rt, Exclude$1 as s, FileManager as st, Adapter as t, defineMiddleware as tt, Include as u, Generator as ut, KubbFileProcessingUpdateContext as v, AsyncEventEmitter as vt, KubbHookEndContext as w, KubbGenerationEndContext as x, KubbFilesProcessingEndContext as y, Output as z };
|
|
2148
|
+
//# sourceMappingURL=types-CuNocrbJ.d.ts.map
|