@kubb/core 5.0.0-alpha.5 → 5.0.0-alpha.51
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 +3 -2
- package/dist/PluginDriver-6E8zd8MW.cjs +1086 -0
- package/dist/PluginDriver-6E8zd8MW.cjs.map +1 -0
- package/dist/PluginDriver-D6wQFD4r.js +983 -0
- package/dist/PluginDriver-D6wQFD4r.js.map +1 -0
- package/dist/index.cjs +1013 -1829
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +279 -265
- package/dist/index.js +1003 -1799
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +138 -0
- package/dist/mocks.cjs.map +1 -0
- package/dist/mocks.d.ts +74 -0
- package/dist/mocks.js +133 -0
- package/dist/mocks.js.map +1 -0
- package/dist/types-DfEv9d_c.d.ts +1721 -0
- package/package.json +51 -57
- package/src/FileManager.ts +133 -0
- package/src/FileProcessor.ts +86 -0
- package/src/Kubb.ts +154 -101
- package/src/PluginDriver.ts +418 -0
- package/src/constants.ts +43 -47
- package/src/createAdapter.ts +25 -0
- package/src/createKubb.ts +614 -0
- package/src/createRenderer.ts +57 -0
- package/src/createStorage.ts +58 -0
- package/src/defineGenerator.ts +88 -100
- package/src/defineLogger.ts +13 -3
- package/src/defineParser.ts +45 -0
- package/src/definePlugin.ts +68 -7
- package/src/defineResolver.ts +521 -0
- package/src/devtools.ts +14 -14
- package/src/index.ts +12 -17
- package/src/mocks.ts +171 -0
- package/src/renderNode.ts +35 -0
- package/src/storages/fsStorage.ts +40 -11
- package/src/storages/memoryStorage.ts +4 -3
- package/src/types.ts +575 -205
- package/src/utils/TreeNode.ts +47 -9
- package/src/utils/diagnostics.ts +4 -1
- package/src/utils/getBarrelFiles.ts +94 -16
- package/src/utils/isInputPath.ts +10 -0
- package/src/utils/packageJSON.ts +99 -0
- package/dist/PluginManager-vZodFEMe.d.ts +0 -1056
- package/dist/chunk-ByKO4r7w.cjs +0 -38
- package/dist/hooks.cjs +0 -60
- package/dist/hooks.cjs.map +0 -1
- package/dist/hooks.d.ts +0 -56
- package/dist/hooks.js +0 -56
- package/dist/hooks.js.map +0 -1
- package/src/BarrelManager.ts +0 -74
- package/src/PackageManager.ts +0 -180
- package/src/PluginManager.ts +0 -667
- package/src/PromiseManager.ts +0 -40
- package/src/build.ts +0 -419
- package/src/config.ts +0 -56
- package/src/defineAdapter.ts +0 -22
- package/src/defineStorage.ts +0 -56
- package/src/errors.ts +0 -1
- package/src/hooks/index.ts +0 -4
- package/src/hooks/useKubb.ts +0 -46
- package/src/hooks/useMode.ts +0 -11
- package/src/hooks/usePlugin.ts +0 -11
- package/src/hooks/usePluginManager.ts +0 -11
- package/src/utils/FunctionParams.ts +0 -155
- package/src/utils/executeStrategies.ts +0 -81
- package/src/utils/formatters.ts +0 -56
- 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,1721 @@
|
|
|
1
|
+
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
+
import { FileNode, HttpMethod, ImportNode, InputNode, Node, OperationNode, SchemaNode, 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
|
+
* Creates a storage factory. Call the returned function with optional options to get the storage instance.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* export const memoryStorage = createStorage(() => {
|
|
209
|
+
* const store = new Map<string, string>()
|
|
210
|
+
* return {
|
|
211
|
+
* name: 'memory',
|
|
212
|
+
* async hasItem(key) { return store.has(key) },
|
|
213
|
+
* async getItem(key) { return store.get(key) ?? null },
|
|
214
|
+
* async setItem(key, value) { store.set(key, value) },
|
|
215
|
+
* async removeItem(key) { store.delete(key) },
|
|
216
|
+
* async getKeys(base) {
|
|
217
|
+
* const keys = [...store.keys()]
|
|
218
|
+
* return base ? keys.filter((k) => k.startsWith(base)) : keys
|
|
219
|
+
* },
|
|
220
|
+
* async clear(base) { if (!base) store.clear() },
|
|
221
|
+
* }
|
|
222
|
+
* })
|
|
223
|
+
*/
|
|
224
|
+
declare function createStorage<TOptions = Record<string, never>>(build: (options: TOptions) => Storage): (options?: TOptions) => Storage;
|
|
225
|
+
//#endregion
|
|
226
|
+
//#region src/defineGenerator.d.ts
|
|
227
|
+
/**
|
|
228
|
+
* A generator is a named object with optional `schema`, `operation`, and `operations`
|
|
229
|
+
* methods. Each method receives the AST node as the first argument and a typed
|
|
230
|
+
* `ctx` object as the second, giving access to `ctx.config`, `ctx.resolver`,
|
|
231
|
+
* `ctx.adapter`, `ctx.options`, `ctx.upsertFile`, etc.
|
|
232
|
+
*
|
|
233
|
+
* Generators that return renderer elements (e.g. JSX) must declare a `renderer`
|
|
234
|
+
* factory so that core knows how to process the output without coupling core
|
|
235
|
+
* to any specific renderer package.
|
|
236
|
+
*
|
|
237
|
+
* Return a renderer element, an array of `FileNode`, or `void` to handle file
|
|
238
|
+
* writing manually via `ctx.upsertFile`.
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
243
|
+
*
|
|
244
|
+
* export const typeGenerator = defineGenerator<PluginTs>({
|
|
245
|
+
* name: 'typescript',
|
|
246
|
+
* renderer: jsxRenderer,
|
|
247
|
+
* schema(node, ctx) {
|
|
248
|
+
* const { adapter, resolver, root, options } = ctx
|
|
249
|
+
* return <File ...><Type node={node} resolver={resolver} /></File>
|
|
250
|
+
* },
|
|
251
|
+
* operation(node, ctx) {
|
|
252
|
+
* const { options } = ctx
|
|
253
|
+
* return <File ...><OperationType node={node} /></File>
|
|
254
|
+
* },
|
|
255
|
+
* })
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
type Generator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown> = {
|
|
259
|
+
/**
|
|
260
|
+
* Used in diagnostic messages and debug output.
|
|
261
|
+
*/
|
|
262
|
+
name: string;
|
|
263
|
+
/**
|
|
264
|
+
* Optional renderer factory that produces a {@link Renderer} for each render cycle.
|
|
265
|
+
*
|
|
266
|
+
* Generators that return renderer elements (e.g. JSX via `@kubb/renderer-jsx`) must set this
|
|
267
|
+
* to the matching renderer factory (e.g. `jsxRenderer` from `@kubb/renderer-jsx`).
|
|
268
|
+
*
|
|
269
|
+
* Generators that only return `Array<FileNode>` or `void` do not need to set this.
|
|
270
|
+
*
|
|
271
|
+
* Set `renderer: null` to explicitly opt out of rendering even when the parent plugin
|
|
272
|
+
* declares a `renderer` (overrides the plugin-level fallback).
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```ts
|
|
276
|
+
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
277
|
+
* export const myGenerator = defineGenerator<PluginTs>({
|
|
278
|
+
* renderer: jsxRenderer,
|
|
279
|
+
* schema(node, ctx) { return <File ...>...</File> },
|
|
280
|
+
* })
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
renderer?: RendererFactory<TElement> | null;
|
|
284
|
+
/**
|
|
285
|
+
* Called for each schema node in the AST walk.
|
|
286
|
+
* `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
|
|
287
|
+
* plus `ctx.options` with the per-node resolved options (after exclude/include/override).
|
|
288
|
+
*/
|
|
289
|
+
schema?: (node: SchemaNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
|
|
290
|
+
/**
|
|
291
|
+
* Called for each operation node in the AST walk.
|
|
292
|
+
* `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
|
|
293
|
+
* plus `ctx.options` with the per-node resolved options (after exclude/include/override).
|
|
294
|
+
*/
|
|
295
|
+
operation?: (node: OperationNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
|
|
296
|
+
/**
|
|
297
|
+
* Called once after all operations have been walked.
|
|
298
|
+
* `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
|
|
299
|
+
* plus `ctx.options` with the plugin-level options for the batch call.
|
|
300
|
+
*/
|
|
301
|
+
operations?: (nodes: Array<OperationNode>, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* Defines a generator. Returns the object as-is with correct `this` typings.
|
|
305
|
+
* `applyHookResult` handles renderer elements and `File[]` uniformly using
|
|
306
|
+
* the generator's declared `renderer` factory.
|
|
307
|
+
*/
|
|
308
|
+
declare function defineGenerator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown>(generator: Generator<TOptions, TElement>): Generator<TOptions, TElement>;
|
|
309
|
+
//#endregion
|
|
310
|
+
//#region src/defineParser.d.ts
|
|
311
|
+
type PrintOptions = {
|
|
312
|
+
extname?: FileNode['extname'];
|
|
313
|
+
};
|
|
314
|
+
type Parser<TMeta extends object = any> = {
|
|
315
|
+
name: string;
|
|
316
|
+
/**
|
|
317
|
+
* File extensions this parser handles.
|
|
318
|
+
* Use `undefined` to create a catch-all fallback parser.
|
|
319
|
+
*
|
|
320
|
+
* @example Handled extensions
|
|
321
|
+
* `['.ts', '.js']`
|
|
322
|
+
*/
|
|
323
|
+
extNames: Array<FileNode['extname']> | undefined;
|
|
324
|
+
/**
|
|
325
|
+
* Convert a resolved file to a string.
|
|
326
|
+
*/
|
|
327
|
+
parse(file: FileNode<TMeta>, options?: PrintOptions): Promise<string> | string;
|
|
328
|
+
};
|
|
329
|
+
/**
|
|
330
|
+
* Defines a parser with type safety.
|
|
331
|
+
*
|
|
332
|
+
* Use this function to create parsers that transform generated files to strings
|
|
333
|
+
* based on their extension.
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* ```ts
|
|
337
|
+
* import { defineParser } from '@kubb/core'
|
|
338
|
+
*
|
|
339
|
+
* export const jsonParser = defineParser({
|
|
340
|
+
* name: 'json',
|
|
341
|
+
* extNames: ['.json'],
|
|
342
|
+
* parse(file) {
|
|
343
|
+
* const { extractStringsFromNodes } = await import('@kubb/ast')
|
|
344
|
+
* return file.sources.map((s) => extractStringsFromNodes(s.nodes ?? [])).join('\n')
|
|
345
|
+
* },
|
|
346
|
+
* })
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
declare function defineParser<TMeta extends object = any>(parser: Parser<TMeta>): Parser<TMeta>;
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region src/FileManager.d.ts
|
|
352
|
+
/**
|
|
353
|
+
* In-memory file store for generated files.
|
|
354
|
+
*
|
|
355
|
+
* Files with the same `path` are merged — sources, imports, and exports are concatenated.
|
|
356
|
+
* The `files` getter returns all stored files sorted by path length (shortest first).
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```ts
|
|
360
|
+
* import { FileManager } from '@kubb/core'
|
|
361
|
+
*
|
|
362
|
+
* const manager = new FileManager()
|
|
363
|
+
* manager.upsert(myFile)
|
|
364
|
+
* console.log(manager.files) // all stored files
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
367
|
+
declare class FileManager {
|
|
368
|
+
#private;
|
|
369
|
+
/**
|
|
370
|
+
* Adds one or more files. Files with the same path are merged — sources, imports,
|
|
371
|
+
* and exports from all calls with the same path are concatenated together.
|
|
372
|
+
*/
|
|
373
|
+
add(...files: Array<FileNode>): Array<FileNode>;
|
|
374
|
+
/**
|
|
375
|
+
* Adds or merges one or more files.
|
|
376
|
+
* If a file with the same path already exists, its sources/imports/exports are merged together.
|
|
377
|
+
*/
|
|
378
|
+
upsert(...files: Array<FileNode>): Array<FileNode>;
|
|
379
|
+
getByPath(path: string): FileNode | null;
|
|
380
|
+
deleteByPath(path: string): void;
|
|
381
|
+
clear(): void;
|
|
382
|
+
/**
|
|
383
|
+
* All stored files, sorted by path length (shorter paths first).
|
|
384
|
+
* Barrel/index files (e.g. index.ts) are sorted last within each length bucket.
|
|
385
|
+
*/
|
|
386
|
+
get files(): Array<FileNode>;
|
|
387
|
+
}
|
|
388
|
+
//#endregion
|
|
389
|
+
//#region src/PluginDriver.d.ts
|
|
390
|
+
type Options = {
|
|
391
|
+
hooks: AsyncEventEmitter<KubbHooks>;
|
|
392
|
+
};
|
|
393
|
+
declare class PluginDriver {
|
|
394
|
+
#private;
|
|
395
|
+
readonly config: Config;
|
|
396
|
+
readonly options: Options;
|
|
397
|
+
/**
|
|
398
|
+
* Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* ```ts
|
|
402
|
+
* PluginDriver.getMode('src/gen/types.ts') // 'single'
|
|
403
|
+
* PluginDriver.getMode('src/gen/types') // 'split'
|
|
404
|
+
* ```
|
|
405
|
+
*/
|
|
406
|
+
static getMode(fileOrFolder: string | undefined | null): 'single' | 'split';
|
|
407
|
+
/**
|
|
408
|
+
* The universal `@kubb/ast` `InputNode` produced by the adapter, set by
|
|
409
|
+
* the build pipeline after the adapter's `parse()` resolves.
|
|
410
|
+
*/
|
|
411
|
+
inputNode: InputNode | undefined;
|
|
412
|
+
adapter: Adapter | undefined;
|
|
413
|
+
/**
|
|
414
|
+
* Central file store for all generated files.
|
|
415
|
+
* Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to
|
|
416
|
+
* add files; this property gives direct read/write access when needed.
|
|
417
|
+
*/
|
|
418
|
+
readonly fileManager: FileManager;
|
|
419
|
+
readonly plugins: Map<string, NormalizedPlugin>;
|
|
420
|
+
constructor(config: Config, options: Options);
|
|
421
|
+
get hooks(): AsyncEventEmitter<KubbHooks>;
|
|
422
|
+
/**
|
|
423
|
+
* Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.
|
|
424
|
+
*
|
|
425
|
+
* For `kubb:plugin:setup`, the registered listener wraps the globally emitted context with a
|
|
426
|
+
* plugin-specific one so that `addGenerator`, `setResolver`, `setTransformer`, and
|
|
427
|
+
* `setRenderer` all target the correct `normalizedPlugin` entry in the plugins map.
|
|
428
|
+
*
|
|
429
|
+
* All other hooks are iterated and registered directly as pass-through listeners.
|
|
430
|
+
* Any event key present in the global `KubbHooks` interface can be subscribed to.
|
|
431
|
+
*
|
|
432
|
+
* External tooling can subscribe to any of these events via `hooks.on(...)` to observe
|
|
433
|
+
* the plugin lifecycle without modifying plugin behavior.
|
|
434
|
+
*
|
|
435
|
+
* @internal
|
|
436
|
+
*/
|
|
437
|
+
registerPluginHooks(hookPlugin: Plugin, normalizedPlugin: NormalizedPlugin): void;
|
|
438
|
+
/**
|
|
439
|
+
* Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners
|
|
440
|
+
* can configure generators, resolvers, transformers and renderers before `buildStart` runs.
|
|
441
|
+
*
|
|
442
|
+
* Call this once from `safeBuild` before the plugin execution loop begins.
|
|
443
|
+
*/
|
|
444
|
+
emitSetupHooks(): Promise<void>;
|
|
445
|
+
/**
|
|
446
|
+
* Registers a generator for the given plugin on the shared event emitter.
|
|
447
|
+
*
|
|
448
|
+
* The generator's `schema`, `operation`, and `operations` methods are registered as
|
|
449
|
+
* listeners on `kubb:generate:schema`, `kubb:generate:operation`, and `kubb:generate:operations`
|
|
450
|
+
* respectively. Each listener is scoped to the owning plugin via a `ctx.plugin.name` check
|
|
451
|
+
* so that generators from different plugins do not cross-fire.
|
|
452
|
+
*
|
|
453
|
+
* The renderer resolution chain is: `generator.renderer → plugin.renderer → config.renderer`.
|
|
454
|
+
* Set `generator.renderer = null` to explicitly opt out of rendering even when the plugin
|
|
455
|
+
* declares a renderer.
|
|
456
|
+
*
|
|
457
|
+
* Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.
|
|
458
|
+
*/
|
|
459
|
+
registerGenerator(pluginName: string, gen: Generator): void;
|
|
460
|
+
/**
|
|
461
|
+
* Returns `true` when at least one generator was registered for the given plugin
|
|
462
|
+
* via `addGenerator()` in `kubb:plugin:setup` (event-based path).
|
|
463
|
+
*
|
|
464
|
+
* Used by the build loop to decide whether to walk the AST and emit generator events
|
|
465
|
+
* for a plugin that has no static `plugin.generators`.
|
|
466
|
+
*/
|
|
467
|
+
hasRegisteredGenerators(pluginName: string): boolean;
|
|
468
|
+
/**
|
|
469
|
+
* Unregisters all plugin lifecycle listeners from the shared event emitter.
|
|
470
|
+
* Called at the end of a build to prevent listener leaks across repeated builds.
|
|
471
|
+
*
|
|
472
|
+
* @internal
|
|
473
|
+
*/
|
|
474
|
+
dispose(): void;
|
|
475
|
+
/**
|
|
476
|
+
* Merges `partial` with the plugin's default resolver and stores the result.
|
|
477
|
+
* Also mirrors it onto `plugin.resolver` so callers using `getPlugin(name).resolver`
|
|
478
|
+
* get the up-to-date resolver without going through `getResolver()`.
|
|
479
|
+
*/
|
|
480
|
+
setPluginResolver(pluginName: string, partial: Partial<Resolver>): void;
|
|
481
|
+
/**
|
|
482
|
+
* Returns the resolver for the given plugin.
|
|
483
|
+
*
|
|
484
|
+
* Resolution order: dynamic resolver set via `setPluginResolver` → static resolver on the
|
|
485
|
+
* plugin → lazily created default resolver (identity name, no path transforms).
|
|
486
|
+
*/
|
|
487
|
+
getResolver<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Kubb.PluginRegistry[TName]['resolver'];
|
|
488
|
+
getResolver<TResolver extends Resolver = Resolver>(pluginName: string): TResolver;
|
|
489
|
+
getContext<TOptions extends PluginFactoryOptions>(plugin: NormalizedPlugin<TOptions>): GeneratorContext<TOptions> & Record<string, unknown>;
|
|
490
|
+
getPlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
|
|
491
|
+
getPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions> | undefined;
|
|
492
|
+
/**
|
|
493
|
+
* Like `getPlugin` but throws a descriptive error when the plugin is not found.
|
|
494
|
+
*/
|
|
495
|
+
requirePlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]>;
|
|
496
|
+
requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>;
|
|
497
|
+
}
|
|
498
|
+
//#endregion
|
|
499
|
+
//#region src/createKubb.d.ts
|
|
500
|
+
/**
|
|
501
|
+
* Full output produced by a successful or failed build.
|
|
502
|
+
*/
|
|
503
|
+
type BuildOutput = {
|
|
504
|
+
/**
|
|
505
|
+
* Plugins that threw during installation, paired with the caught error.
|
|
506
|
+
*/
|
|
507
|
+
failedPlugins: Set<{
|
|
508
|
+
plugin: Plugin;
|
|
509
|
+
error: Error;
|
|
510
|
+
}>;
|
|
511
|
+
files: Array<FileNode>;
|
|
512
|
+
driver: PluginDriver;
|
|
513
|
+
/**
|
|
514
|
+
* Elapsed time in milliseconds for each plugin, keyed by plugin name.
|
|
515
|
+
*/
|
|
516
|
+
pluginTimings: Map<string, number>;
|
|
517
|
+
error?: Error;
|
|
518
|
+
/**
|
|
519
|
+
* Raw generated source, keyed by absolute file path.
|
|
520
|
+
*/
|
|
521
|
+
sources: Map<string, string>;
|
|
522
|
+
};
|
|
523
|
+
type CreateKubbOptions = {
|
|
524
|
+
hooks?: AsyncEventEmitter<KubbHooks>;
|
|
525
|
+
};
|
|
526
|
+
/**
|
|
527
|
+
* Creates a Kubb instance bound to a single config entry.
|
|
528
|
+
*
|
|
529
|
+
* Accepts a user-facing config shape and resolves it to a full {@link Config} during
|
|
530
|
+
* `setup()`. The instance then holds shared state (`hooks`, `sources`, `driver`, `config`)
|
|
531
|
+
* across the `setup → build` lifecycle. Attach event listeners to `kubb.hooks` before
|
|
532
|
+
* calling `setup()` or `build()`.
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
* ```ts
|
|
536
|
+
* const kubb = createKubb(userConfig)
|
|
537
|
+
*
|
|
538
|
+
* kubb.hooks.on('kubb:plugin:end', (plugin, { duration }) => {
|
|
539
|
+
* console.log(`${plugin.name} completed in ${duration}ms`)
|
|
540
|
+
* })
|
|
541
|
+
*
|
|
542
|
+
* const { files, failedPlugins } = await kubb.safeBuild()
|
|
543
|
+
* ```
|
|
544
|
+
*/
|
|
545
|
+
declare function createKubb(userConfig: UserConfig, options?: CreateKubbOptions): Kubb$1;
|
|
546
|
+
//#endregion
|
|
547
|
+
//#region src/Kubb.d.ts
|
|
548
|
+
type DebugInfo = {
|
|
549
|
+
date: Date;
|
|
550
|
+
logs: Array<string>;
|
|
551
|
+
fileName?: string;
|
|
552
|
+
};
|
|
553
|
+
/**
|
|
554
|
+
* The instance returned by {@link createKubb}.
|
|
555
|
+
*/
|
|
556
|
+
type Kubb$1 = {
|
|
557
|
+
/**
|
|
558
|
+
* The shared event emitter. Attach listeners here before calling `setup()` or `build()`.
|
|
559
|
+
*/
|
|
560
|
+
readonly hooks: AsyncEventEmitter<KubbHooks>;
|
|
561
|
+
/**
|
|
562
|
+
* Raw generated source, keyed by absolute file path.
|
|
563
|
+
* Populated after a successful `build()` or `safeBuild()` call.
|
|
564
|
+
*/
|
|
565
|
+
readonly sources: Map<string, string>;
|
|
566
|
+
/**
|
|
567
|
+
* The plugin driver. Available after `setup()` has been called.
|
|
568
|
+
*/
|
|
569
|
+
readonly driver: PluginDriver | undefined;
|
|
570
|
+
/**
|
|
571
|
+
* The resolved config with applied defaults. Available after `setup()` has been called.
|
|
572
|
+
*/
|
|
573
|
+
readonly config: Config | undefined;
|
|
574
|
+
/**
|
|
575
|
+
* Initializes all Kubb infrastructure: validates input, applies config defaults,
|
|
576
|
+
* runs the adapter, and creates the PluginDriver.
|
|
577
|
+
*
|
|
578
|
+
* Calling `build()` or `safeBuild()` without calling `setup()` first will
|
|
579
|
+
* automatically invoke `setup()` before proceeding.
|
|
580
|
+
*/
|
|
581
|
+
setup(): Promise<void>;
|
|
582
|
+
/**
|
|
583
|
+
* Runs a full Kubb build and throws on any error or plugin failure.
|
|
584
|
+
* Automatically calls `setup()` if it has not been called yet.
|
|
585
|
+
*/
|
|
586
|
+
build(): Promise<BuildOutput>;
|
|
587
|
+
/**
|
|
588
|
+
* Runs a full Kubb build and captures errors instead of throwing.
|
|
589
|
+
* Automatically calls `setup()` if it has not been called yet.
|
|
590
|
+
*/
|
|
591
|
+
safeBuild(): Promise<BuildOutput>;
|
|
592
|
+
};
|
|
593
|
+
/**
|
|
594
|
+
* Events emitted during the Kubb code generation lifecycle.
|
|
595
|
+
* These events can be listened to for logging, progress tracking, and custom integrations.
|
|
596
|
+
*
|
|
597
|
+
* @example
|
|
598
|
+
* ```typescript
|
|
599
|
+
* import type { AsyncEventEmitter } from '@internals/utils'
|
|
600
|
+
* import type { KubbHooks } from '@kubb/core'
|
|
601
|
+
*
|
|
602
|
+
* const hooks: AsyncEventEmitter<KubbHooks> = new AsyncEventEmitter()
|
|
603
|
+
*
|
|
604
|
+
* hooks.on('kubb:lifecycle:start', () => {
|
|
605
|
+
* console.log('Starting Kubb generation')
|
|
606
|
+
* })
|
|
607
|
+
*
|
|
608
|
+
* hooks.on('kubb:plugin:end', (plugin, { duration }) => {
|
|
609
|
+
* console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
|
|
610
|
+
* })
|
|
611
|
+
* ```
|
|
612
|
+
*/
|
|
613
|
+
interface KubbHooks {
|
|
614
|
+
/**
|
|
615
|
+
* Emitted at the beginning of the Kubb lifecycle, before any code generation starts.
|
|
616
|
+
*/
|
|
617
|
+
'kubb:lifecycle:start': [version: string];
|
|
618
|
+
/**
|
|
619
|
+
* Emitted at the end of the Kubb lifecycle, after all code generation is complete.
|
|
620
|
+
*/
|
|
621
|
+
'kubb:lifecycle:end': [];
|
|
622
|
+
/**
|
|
623
|
+
* Emitted when configuration loading starts.
|
|
624
|
+
*/
|
|
625
|
+
'kubb:config:start': [];
|
|
626
|
+
/**
|
|
627
|
+
* Emitted when configuration loading is complete.
|
|
628
|
+
*/
|
|
629
|
+
'kubb:config:end': [configs: Array<Config>];
|
|
630
|
+
/**
|
|
631
|
+
* Emitted when code generation phase starts.
|
|
632
|
+
*/
|
|
633
|
+
'kubb:generation:start': [config: Config];
|
|
634
|
+
/**
|
|
635
|
+
* Emitted when code generation phase completes.
|
|
636
|
+
*/
|
|
637
|
+
'kubb:generation:end': [config: Config, files: Array<FileNode>, sources: Map<string, string>];
|
|
638
|
+
/**
|
|
639
|
+
* Emitted with a summary of the generation results.
|
|
640
|
+
* Contains summary lines, title, and success status.
|
|
641
|
+
*/
|
|
642
|
+
'kubb:generation:summary': [config: Config, {
|
|
643
|
+
failedPlugins: Set<{
|
|
644
|
+
plugin: Plugin;
|
|
645
|
+
error: Error;
|
|
646
|
+
}>;
|
|
647
|
+
status: 'success' | 'failed';
|
|
648
|
+
hrStart: [number, number];
|
|
649
|
+
filesCreated: number;
|
|
650
|
+
pluginTimings?: Map<Plugin['name'], number>;
|
|
651
|
+
}];
|
|
652
|
+
/**
|
|
653
|
+
* Emitted when code formatting starts (e.g., running Biome or Prettier).
|
|
654
|
+
*/
|
|
655
|
+
'kubb:format:start': [];
|
|
656
|
+
/**
|
|
657
|
+
* Emitted when code formatting completes.
|
|
658
|
+
*/
|
|
659
|
+
'kubb:format:end': [];
|
|
660
|
+
/**
|
|
661
|
+
* Emitted when linting starts.
|
|
662
|
+
*/
|
|
663
|
+
'kubb:lint:start': [];
|
|
664
|
+
/**
|
|
665
|
+
* Emitted when linting completes.
|
|
666
|
+
*/
|
|
667
|
+
'kubb:lint:end': [];
|
|
668
|
+
/**
|
|
669
|
+
* Emitted when plugin hooks execution starts.
|
|
670
|
+
*/
|
|
671
|
+
'kubb:hooks:start': [];
|
|
672
|
+
/**
|
|
673
|
+
* Emitted when plugin hooks execution completes.
|
|
674
|
+
*/
|
|
675
|
+
'kubb:hooks:end': [];
|
|
676
|
+
/**
|
|
677
|
+
* Emitted when a single hook execution starts (e.g., format or lint).
|
|
678
|
+
* The callback should be invoked when the command completes.
|
|
679
|
+
*/
|
|
680
|
+
'kubb:hook:start': [{
|
|
681
|
+
id?: string;
|
|
682
|
+
command: string;
|
|
683
|
+
args?: readonly string[];
|
|
684
|
+
}];
|
|
685
|
+
/**
|
|
686
|
+
* Emitted when a single hook execution completes.
|
|
687
|
+
*/
|
|
688
|
+
'kubb:hook:end': [{
|
|
689
|
+
id?: string;
|
|
690
|
+
command: string;
|
|
691
|
+
args?: readonly string[];
|
|
692
|
+
success: boolean;
|
|
693
|
+
error: Error | null;
|
|
694
|
+
}];
|
|
695
|
+
/**
|
|
696
|
+
* Emitted when a new version of Kubb is available.
|
|
697
|
+
*/
|
|
698
|
+
'kubb:version:new': [currentVersion: string, latestVersion: string];
|
|
699
|
+
/**
|
|
700
|
+
* Informational message event.
|
|
701
|
+
*/
|
|
702
|
+
'kubb:info': [message: string, info?: string];
|
|
703
|
+
/**
|
|
704
|
+
* Error event. Emitted when an error occurs during code generation.
|
|
705
|
+
*/
|
|
706
|
+
'kubb:error': [error: Error, meta?: Record<string, unknown>];
|
|
707
|
+
/**
|
|
708
|
+
* Success message event.
|
|
709
|
+
*/
|
|
710
|
+
'kubb:success': [message: string, info?: string];
|
|
711
|
+
/**
|
|
712
|
+
* Warning message event.
|
|
713
|
+
*/
|
|
714
|
+
'kubb:warn': [message: string, info?: string];
|
|
715
|
+
/**
|
|
716
|
+
* Debug event for detailed logging.
|
|
717
|
+
* Contains timestamp, log messages, and optional filename.
|
|
718
|
+
*/
|
|
719
|
+
'kubb:debug': [info: DebugInfo];
|
|
720
|
+
/**
|
|
721
|
+
* Emitted when file processing starts.
|
|
722
|
+
* Contains the list of files to be processed.
|
|
723
|
+
*/
|
|
724
|
+
'kubb:files:processing:start': [files: Array<FileNode>];
|
|
725
|
+
/**
|
|
726
|
+
* Emitted for each file being processed, providing progress updates.
|
|
727
|
+
* Contains processed count, total count, percentage, and file details.
|
|
728
|
+
*/
|
|
729
|
+
'kubb:file:processing:update': [{
|
|
730
|
+
/**
|
|
731
|
+
* Number of files processed so far.
|
|
732
|
+
*/
|
|
733
|
+
processed: number;
|
|
734
|
+
/**
|
|
735
|
+
* Total number of files to process.
|
|
736
|
+
*/
|
|
737
|
+
total: number;
|
|
738
|
+
/**
|
|
739
|
+
* Processing percentage (0–100).
|
|
740
|
+
*/
|
|
741
|
+
percentage: number;
|
|
742
|
+
/**
|
|
743
|
+
* Optional source identifier.
|
|
744
|
+
*/
|
|
745
|
+
source?: string;
|
|
746
|
+
/**
|
|
747
|
+
* The file being processed.
|
|
748
|
+
*/
|
|
749
|
+
file: FileNode;
|
|
750
|
+
/**
|
|
751
|
+
* Kubb configuration
|
|
752
|
+
* Provides access to the current config during file processing.
|
|
753
|
+
*/
|
|
754
|
+
config: Config;
|
|
755
|
+
}];
|
|
756
|
+
/**
|
|
757
|
+
* Emitted when file processing completes.
|
|
758
|
+
* Contains the list of processed files.
|
|
759
|
+
*/
|
|
760
|
+
'kubb:files:processing:end': [files: Array<FileNode>];
|
|
761
|
+
/**
|
|
762
|
+
* Emitted when a plugin starts executing.
|
|
763
|
+
*/
|
|
764
|
+
'kubb:plugin:start': [plugin: Plugin];
|
|
765
|
+
/**
|
|
766
|
+
* Emitted when a plugin completes execution.
|
|
767
|
+
* Duration in ms.
|
|
768
|
+
*/
|
|
769
|
+
'kubb:plugin:end': [plugin: Plugin, result: {
|
|
770
|
+
duration: number;
|
|
771
|
+
success: boolean;
|
|
772
|
+
error?: Error;
|
|
773
|
+
}];
|
|
774
|
+
/**
|
|
775
|
+
* Fired once — before any plugin's `buildStart` runs — so that hook-style plugins
|
|
776
|
+
* can register generators, configure resolvers/transformers/renderers, or inject
|
|
777
|
+
* extra files. All `kubb:plugin:setup` handlers registered via `definePlugin` receive
|
|
778
|
+
* a plugin-specific context (with the correct `addGenerator` closure).
|
|
779
|
+
* External tooling can observe this event via `hooks.on('kubb:plugin:setup', …)`.
|
|
780
|
+
*/
|
|
781
|
+
'kubb:plugin:setup': [ctx: KubbPluginSetupContext];
|
|
782
|
+
/**
|
|
783
|
+
* Fired immediately before the plugin execution loop begins.
|
|
784
|
+
* The adapter has already parsed the source and `inputNode` is available.
|
|
785
|
+
*/
|
|
786
|
+
'kubb:build:start': [ctx: KubbBuildStartContext];
|
|
787
|
+
/**
|
|
788
|
+
* Fired after all files have been written to disk.
|
|
789
|
+
*/
|
|
790
|
+
'kubb:build:end': [ctx: KubbBuildEndContext];
|
|
791
|
+
/**
|
|
792
|
+
* Emitted for each schema node during the AST walk.
|
|
793
|
+
* Generator listeners registered via `addGenerator()` in `kubb:plugin:setup` respond to this event.
|
|
794
|
+
* The `ctx.plugin.name` identifies which plugin is driving the current walk.
|
|
795
|
+
* `ctx.options` carries the per-node resolved options (after exclude/include/override).
|
|
796
|
+
*/
|
|
797
|
+
'kubb:generate:schema': [node: SchemaNode, ctx: GeneratorContext];
|
|
798
|
+
/**
|
|
799
|
+
* Emitted for each operation node during the AST walk.
|
|
800
|
+
* Generator listeners registered via `addGenerator()` in `kubb:plugin:setup` respond to this event.
|
|
801
|
+
* The `ctx.plugin.name` identifies which plugin is driving the current walk.
|
|
802
|
+
* `ctx.options` carries the per-node resolved options (after exclude/include/override).
|
|
803
|
+
*/
|
|
804
|
+
'kubb:generate:operation': [node: OperationNode, ctx: GeneratorContext];
|
|
805
|
+
/**
|
|
806
|
+
* Emitted once after all operations have been walked, with the full collected array.
|
|
807
|
+
* Generator listeners with an `operations()` method respond to this event.
|
|
808
|
+
* The `ctx.plugin.name` identifies which plugin is driving the current walk.
|
|
809
|
+
* `ctx.options` carries the plugin-level resolved options for the batch call.
|
|
810
|
+
*/
|
|
811
|
+
'kubb:generate:operations': [nodes: Array<OperationNode>, ctx: GeneratorContext];
|
|
812
|
+
}
|
|
813
|
+
declare global {
|
|
814
|
+
namespace Kubb {
|
|
815
|
+
/**
|
|
816
|
+
* Registry that maps plugin names to their `PluginFactoryOptions`.
|
|
817
|
+
* Augment this interface in each plugin's `types.ts` to enable automatic
|
|
818
|
+
* typing for `getPlugin` and `requirePlugin`.
|
|
819
|
+
*
|
|
820
|
+
* @example
|
|
821
|
+
* ```ts
|
|
822
|
+
* // packages/plugin-ts/src/types.ts
|
|
823
|
+
* declare global {
|
|
824
|
+
* namespace Kubb {
|
|
825
|
+
* interface PluginRegistry {
|
|
826
|
+
* 'plugin-ts': PluginTs
|
|
827
|
+
* }
|
|
828
|
+
* }
|
|
829
|
+
* }
|
|
830
|
+
* ```
|
|
831
|
+
*/
|
|
832
|
+
interface PluginRegistry {}
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
//#endregion
|
|
836
|
+
//#region src/definePlugin.d.ts
|
|
837
|
+
/**
|
|
838
|
+
* A plugin object produced by `definePlugin`.
|
|
839
|
+
* Instead of flat lifecycle methods, it groups all handlers under a `hooks:` property
|
|
840
|
+
* (matching Astro's integration naming convention).
|
|
841
|
+
*
|
|
842
|
+
* @template TFactory - The plugin's `PluginFactoryOptions` type.
|
|
843
|
+
*/
|
|
844
|
+
type Plugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
845
|
+
/**
|
|
846
|
+
* Unique name for the plugin, following the same naming convention as `createPlugin`.
|
|
847
|
+
*/
|
|
848
|
+
name: string;
|
|
849
|
+
/**
|
|
850
|
+
* Plugins that must be registered before this plugin executes.
|
|
851
|
+
* An error is thrown at startup when any listed dependency is missing.
|
|
852
|
+
*/
|
|
853
|
+
dependencies?: Array<string>;
|
|
854
|
+
/**
|
|
855
|
+
* The options passed by the user when calling the plugin factory.
|
|
856
|
+
*/
|
|
857
|
+
options?: TFactory['options'];
|
|
858
|
+
/**
|
|
859
|
+
* Lifecycle event handlers for this plugin.
|
|
860
|
+
* Any event from the global `KubbHooks` map can be subscribed to here.
|
|
861
|
+
*/
|
|
862
|
+
hooks: { [K in Exclude<keyof KubbHooks, 'kubb:plugin:setup'>]?: (...args: KubbHooks[K]) => void | Promise<void> } & {
|
|
863
|
+
'kubb:plugin:setup'?(ctx: KubbPluginSetupContext<TFactory>): void | Promise<void>;
|
|
864
|
+
};
|
|
865
|
+
};
|
|
866
|
+
/**
|
|
867
|
+
* Creates a plugin factory using the hook-style (`hooks:`) API.
|
|
868
|
+
*
|
|
869
|
+
* The returned factory is called with optional options and produces a `Plugin`
|
|
870
|
+
* that coexists with plugins created via the legacy `createPlugin` API in the same
|
|
871
|
+
* `kubb.config.ts`.
|
|
872
|
+
*
|
|
873
|
+
* Lifecycle handlers are registered on the `PluginDriver`'s `AsyncEventEmitter`, enabling
|
|
874
|
+
* both the plugin's own handlers and external tooling (CLI, devtools) to observe every event.
|
|
875
|
+
*
|
|
876
|
+
* @example
|
|
877
|
+
* ```ts
|
|
878
|
+
* // With PluginFactoryOptions (recommended for real plugins)
|
|
879
|
+
* export const pluginTs = definePlugin<PluginTs>((options) => ({
|
|
880
|
+
* name: 'plugin-ts',
|
|
881
|
+
* hooks: {
|
|
882
|
+
* 'kubb:plugin:setup'(ctx) {
|
|
883
|
+
* ctx.setResolver(resolverTs) // typed as Partial<ResolverTs>
|
|
884
|
+
* },
|
|
885
|
+
* },
|
|
886
|
+
* }))
|
|
887
|
+
* ```
|
|
888
|
+
*/
|
|
889
|
+
declare function definePlugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(factory: (options: TFactory['options']) => Plugin<TFactory>): (options?: TFactory['options']) => Plugin<TFactory>;
|
|
890
|
+
//#endregion
|
|
891
|
+
//#region src/utils/getBarrelFiles.d.ts
|
|
892
|
+
/**
|
|
893
|
+
* Minimal file metadata attached to every generated file for barrel-file bookkeeping.
|
|
894
|
+
*
|
|
895
|
+
* @internal
|
|
896
|
+
*/
|
|
897
|
+
type FileMetaBase = {
|
|
898
|
+
pluginName?: string;
|
|
899
|
+
};
|
|
900
|
+
//#endregion
|
|
901
|
+
//#region src/types.d.ts
|
|
902
|
+
type InputPath = {
|
|
903
|
+
/**
|
|
904
|
+
* Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
|
|
905
|
+
*/
|
|
906
|
+
path: string;
|
|
907
|
+
};
|
|
908
|
+
type InputData = {
|
|
909
|
+
/**
|
|
910
|
+
* A `string` or `object` that contains your Swagger/OpenAPI data.
|
|
911
|
+
*/
|
|
912
|
+
data: string | unknown;
|
|
913
|
+
};
|
|
914
|
+
type Input = InputPath | InputData;
|
|
915
|
+
/**
|
|
916
|
+
* The raw source passed to an adapter's `parse` function.
|
|
917
|
+
* Mirrors the shape of `Config['input']` with paths already resolved to absolute.
|
|
918
|
+
*/
|
|
919
|
+
type AdapterSource = {
|
|
920
|
+
type: 'path';
|
|
921
|
+
path: string;
|
|
922
|
+
} | {
|
|
923
|
+
type: 'data';
|
|
924
|
+
data: string | unknown;
|
|
925
|
+
} | {
|
|
926
|
+
type: 'paths';
|
|
927
|
+
paths: Array<string>;
|
|
928
|
+
};
|
|
929
|
+
/**
|
|
930
|
+
* Type parameters for an adapter definition.
|
|
931
|
+
*
|
|
932
|
+
* Mirrors `PluginFactoryOptions` but scoped to the adapter lifecycle:
|
|
933
|
+
* - `TName` — unique string identifier (e.g. `'oas'`, `'asyncapi'`)
|
|
934
|
+
* - `TOptions` — raw user-facing options passed to the adapter factory
|
|
935
|
+
* - `TResolvedOptions` — defaults applied; what the adapter stores as `options`
|
|
936
|
+
* - `TDocument` — type of the raw source document exposed by the adapter after `parse()`
|
|
937
|
+
*/
|
|
938
|
+
type AdapterFactoryOptions<TName extends string = string, TOptions extends object = object, TResolvedOptions extends object = TOptions, TDocument = unknown> = {
|
|
939
|
+
name: TName;
|
|
940
|
+
options: TOptions;
|
|
941
|
+
resolvedOptions: TResolvedOptions;
|
|
942
|
+
document: TDocument;
|
|
943
|
+
};
|
|
944
|
+
/**
|
|
945
|
+
* An adapter converts a source file or data into a `@kubb/ast` `InputNode`.
|
|
946
|
+
*
|
|
947
|
+
* Adapters are the single entry-point for different schema formats
|
|
948
|
+
* (OpenAPI, AsyncAPI, Drizzle, …) and produce the universal `InputNode`
|
|
949
|
+
* that all Kubb plugins consume.
|
|
950
|
+
*
|
|
951
|
+
* @example
|
|
952
|
+
* ```ts
|
|
953
|
+
* import { oasAdapter } from '@kubb/adapter-oas'
|
|
954
|
+
*
|
|
955
|
+
* export default defineConfig({
|
|
956
|
+
* adapter: adapterOas(), // default — OpenAPI / Swagger
|
|
957
|
+
* input: { path: './openapi.yaml' },
|
|
958
|
+
* plugins: [pluginTs(), pluginZod()],
|
|
959
|
+
* })
|
|
960
|
+
* ```
|
|
961
|
+
*/
|
|
962
|
+
type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
963
|
+
/**
|
|
964
|
+
* Human-readable identifier, e.g. `'oas'`, `'drizzle'`, `'asyncapi'`.
|
|
965
|
+
*/
|
|
966
|
+
name: TOptions['name'];
|
|
967
|
+
/**
|
|
968
|
+
* Resolved options (after defaults have been applied).
|
|
969
|
+
*/
|
|
970
|
+
options: TOptions['resolvedOptions'];
|
|
971
|
+
/**
|
|
972
|
+
* The raw source document produced after the first `parse()` call.
|
|
973
|
+
* `undefined` before parsing; typed by the adapter's `TDocument` generic.
|
|
974
|
+
*/
|
|
975
|
+
document: TOptions['document'] | null;
|
|
976
|
+
inputNode: InputNode | null;
|
|
977
|
+
/**
|
|
978
|
+
* Convert the raw source into a universal `InputNode`.
|
|
979
|
+
*/
|
|
980
|
+
parse: (source: AdapterSource) => PossiblePromise<InputNode>;
|
|
981
|
+
/**
|
|
982
|
+
* Extracts `ImportNode` entries needed by a `SchemaNode` tree.
|
|
983
|
+
* Populated after the first `parse()` call. Returns an empty array before that.
|
|
984
|
+
*
|
|
985
|
+
* The `resolve` callback receives the collision-corrected schema name and must
|
|
986
|
+
* return the `{ name, path }` pair for the import, or `undefined` to skip it.
|
|
987
|
+
*/
|
|
988
|
+
getImports: (node: SchemaNode, resolve: (schemaName: string) => {
|
|
989
|
+
name: string;
|
|
990
|
+
path: string;
|
|
991
|
+
}) => Array<ImportNode>;
|
|
992
|
+
};
|
|
993
|
+
/**
|
|
994
|
+
* Controls how `index.ts` barrel files are generated.
|
|
995
|
+
* - `'all'` — exports every generated symbol from every file.
|
|
996
|
+
* - `'named'` — exports only explicitly named exports.
|
|
997
|
+
* - `'propagate'` — propagates re-exports from nested barrel files upward.
|
|
998
|
+
*/
|
|
999
|
+
type BarrelType = 'all' | 'named' | 'propagate';
|
|
1000
|
+
type DevtoolsOptions = {
|
|
1001
|
+
/**
|
|
1002
|
+
* Open the AST inspector view (`/ast`) in Kubb Studio.
|
|
1003
|
+
* When `false`, opens the main Studio page instead.
|
|
1004
|
+
* @default false
|
|
1005
|
+
*/
|
|
1006
|
+
ast?: boolean;
|
|
1007
|
+
};
|
|
1008
|
+
/**
|
|
1009
|
+
* @private
|
|
1010
|
+
*/
|
|
1011
|
+
type Config<TInput = Input> = {
|
|
1012
|
+
/**
|
|
1013
|
+
* The name to display in the CLI output.
|
|
1014
|
+
*/
|
|
1015
|
+
name?: string;
|
|
1016
|
+
/**
|
|
1017
|
+
* The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
|
|
1018
|
+
* @default process.cwd()
|
|
1019
|
+
*/
|
|
1020
|
+
root: string;
|
|
1021
|
+
/**
|
|
1022
|
+
* An array of parsers used to convert generated files to strings.
|
|
1023
|
+
* Each parser handles specific file extensions (e.g. `.ts`, `.tsx`).
|
|
1024
|
+
*
|
|
1025
|
+
* A catch-all fallback parser is always appended last for any unhandled extension.
|
|
1026
|
+
*
|
|
1027
|
+
* When omitted, `parserTs` from `@kubb/parser-ts` is used automatically as the
|
|
1028
|
+
* default (requires `@kubb/parser-ts` to be installed as an optional dependency).
|
|
1029
|
+
* @default [parserTs] — from `@kubb/parser-ts`
|
|
1030
|
+
* @example
|
|
1031
|
+
* ```ts
|
|
1032
|
+
* import { parserTs, tsxParser } from '@kubb/parser-ts'
|
|
1033
|
+
* export default defineConfig({
|
|
1034
|
+
* parsers: [parserTs, tsxParser],
|
|
1035
|
+
* })
|
|
1036
|
+
* ```
|
|
1037
|
+
*/
|
|
1038
|
+
parsers: Array<Parser>;
|
|
1039
|
+
/**
|
|
1040
|
+
* Adapter that converts the input file into a `@kubb/ast` `InputNode` — the universal
|
|
1041
|
+
* intermediate representation consumed by all Kubb plugins.
|
|
1042
|
+
*
|
|
1043
|
+
* - Use `@kubb/adapter-oas` for OpenAPI / Swagger.
|
|
1044
|
+
* - Use `@kubb/adapter-drizzle` or `@kubb/adapter-asyncapi` for other formats.
|
|
1045
|
+
*
|
|
1046
|
+
* @example
|
|
1047
|
+
* ```ts
|
|
1048
|
+
* import { adapterOas } from '@kubb/adapter-oas'
|
|
1049
|
+
* export default defineConfig({
|
|
1050
|
+
* adapter: adapterOas(),
|
|
1051
|
+
* input: { path: './petStore.yaml' },
|
|
1052
|
+
* })
|
|
1053
|
+
* ```
|
|
1054
|
+
*/
|
|
1055
|
+
adapter: Adapter;
|
|
1056
|
+
/**
|
|
1057
|
+
* Source file or data to generate code from.
|
|
1058
|
+
* Use `input.path` for a file on disk or `input.data` for an inline string or object.
|
|
1059
|
+
*/
|
|
1060
|
+
input: TInput;
|
|
1061
|
+
output: {
|
|
1062
|
+
/**
|
|
1063
|
+
* Output directory for generated files.
|
|
1064
|
+
* Accepts an absolute path or a path relative to `root`.
|
|
1065
|
+
*/
|
|
1066
|
+
path: string;
|
|
1067
|
+
/**
|
|
1068
|
+
* Clean the output directory before each build.
|
|
1069
|
+
*/
|
|
1070
|
+
clean?: boolean;
|
|
1071
|
+
/**
|
|
1072
|
+
* Save files to the file system.
|
|
1073
|
+
* @default true
|
|
1074
|
+
* @deprecated Use `storage` to control where files are written.
|
|
1075
|
+
*/
|
|
1076
|
+
write?: boolean;
|
|
1077
|
+
/**
|
|
1078
|
+
* Storage backend for generated files.
|
|
1079
|
+
* Defaults to `fsStorage()` — the built-in filesystem driver.
|
|
1080
|
+
* Accepts any object implementing the {@link Storage} interface.
|
|
1081
|
+
* Keys are root-relative paths (e.g. `src/gen/api/getPets.ts`).
|
|
1082
|
+
* @default fsStorage()
|
|
1083
|
+
* @example
|
|
1084
|
+
* ```ts
|
|
1085
|
+
* import { memoryStorage } from '@kubb/core'
|
|
1086
|
+
* storage: memoryStorage()
|
|
1087
|
+
* ```
|
|
1088
|
+
*/
|
|
1089
|
+
storage?: Storage;
|
|
1090
|
+
/**
|
|
1091
|
+
* Specifies the formatting tool to be used.
|
|
1092
|
+
* - 'auto' automatically detects and uses oxfmt, biome, or prettier (in that order of preference).
|
|
1093
|
+
* - 'oxfmt' uses Oxfmt for code formatting.
|
|
1094
|
+
* - 'prettier' uses Prettier for code formatting.
|
|
1095
|
+
* - 'biome' uses Biome for code formatting.
|
|
1096
|
+
* - false disables code formatting.
|
|
1097
|
+
* @default 'prettier'
|
|
1098
|
+
*/
|
|
1099
|
+
format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false;
|
|
1100
|
+
/**
|
|
1101
|
+
* Specifies the linter that should be used to analyze the code.
|
|
1102
|
+
* - 'auto' automatically detects and uses oxlint, biome, or eslint (in that order of preference).
|
|
1103
|
+
* - 'oxlint' uses Oxlint for linting.
|
|
1104
|
+
* - 'eslint' uses ESLint for linting.
|
|
1105
|
+
* - 'biome' uses Biome for linting.
|
|
1106
|
+
* - false disables linting.
|
|
1107
|
+
* @default 'auto'
|
|
1108
|
+
*/
|
|
1109
|
+
lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false;
|
|
1110
|
+
/**
|
|
1111
|
+
* Overrides the extension for generated imports and exports. By default, each plugin adds an extension.
|
|
1112
|
+
* @default { '.ts': '.ts'}
|
|
1113
|
+
*/
|
|
1114
|
+
extension?: Record<FileNode['extname'], FileNode['extname'] | ''>;
|
|
1115
|
+
/**
|
|
1116
|
+
* Configures how `index.ts` files are created, including disabling barrel file generation. Each plugin has its own `barrelType` option; this setting controls the root barrel file (e.g., `src/gen/index.ts`).
|
|
1117
|
+
* @default 'named'
|
|
1118
|
+
*/
|
|
1119
|
+
barrelType?: 'all' | 'named' | false;
|
|
1120
|
+
/**
|
|
1121
|
+
* Adds a default banner to the start of every generated file indicating it was generated by Kubb.
|
|
1122
|
+
* - 'simple' adds banner with link to Kubb.
|
|
1123
|
+
* - 'full' adds source, title, description, and OpenAPI version.
|
|
1124
|
+
* - false disables banner generation.
|
|
1125
|
+
* @default 'simple'
|
|
1126
|
+
*/
|
|
1127
|
+
defaultBanner?: 'simple' | 'full' | false;
|
|
1128
|
+
/**
|
|
1129
|
+
* Whether to override existing external files if they already exist.
|
|
1130
|
+
* When setting the option in the global configuration, all plugins inherit the same behavior by default.
|
|
1131
|
+
* However, all plugins also have an `output.override` option, which can be used to override the behavior for a specific plugin.
|
|
1132
|
+
* @default false
|
|
1133
|
+
*/
|
|
1134
|
+
override?: boolean;
|
|
1135
|
+
};
|
|
1136
|
+
/**
|
|
1137
|
+
* An array of Kubb plugins used for code generation.
|
|
1138
|
+
* Each plugin may declare additional configurable options.
|
|
1139
|
+
* If a plugin depends on another, an error is thrown when the dependency is missing.
|
|
1140
|
+
* Use `dependencies` on the plugin to declare execution order.
|
|
1141
|
+
*/
|
|
1142
|
+
plugins: Array<Plugin>;
|
|
1143
|
+
/**
|
|
1144
|
+
* Project-wide renderer factory. All plugins and generators that do not declare their own
|
|
1145
|
+
* `renderer` ultimately fall back to this value.
|
|
1146
|
+
*
|
|
1147
|
+
* The resolution chain is: `generator.renderer` → `plugin.renderer` → `config.renderer` → `undefined` (raw `FileNode[]` mode).
|
|
1148
|
+
*
|
|
1149
|
+
* @example
|
|
1150
|
+
* ```ts
|
|
1151
|
+
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
1152
|
+
* export default defineConfig({
|
|
1153
|
+
* renderer: jsxRenderer,
|
|
1154
|
+
* plugins: [pluginTs(), pluginZod()],
|
|
1155
|
+
* })
|
|
1156
|
+
* ```
|
|
1157
|
+
*/
|
|
1158
|
+
renderer?: RendererFactory;
|
|
1159
|
+
/**
|
|
1160
|
+
* Devtools configuration for Kubb Studio integration.
|
|
1161
|
+
*/
|
|
1162
|
+
devtools?: true | {
|
|
1163
|
+
/**
|
|
1164
|
+
* Override the Kubb Studio base URL.
|
|
1165
|
+
* @default 'https://studio.kubb.dev'
|
|
1166
|
+
*/
|
|
1167
|
+
studioUrl?: typeof DEFAULT_STUDIO_URL | (string & {});
|
|
1168
|
+
};
|
|
1169
|
+
/**
|
|
1170
|
+
* Hooks triggered when a specific action occurs in Kubb.
|
|
1171
|
+
*/
|
|
1172
|
+
hooks?: {
|
|
1173
|
+
/**
|
|
1174
|
+
* Hook that triggers at the end of all executions.
|
|
1175
|
+
* Useful for running Prettier or ESLint to format/lint your code.
|
|
1176
|
+
*/
|
|
1177
|
+
done?: string | Array<string>;
|
|
1178
|
+
};
|
|
1179
|
+
};
|
|
1180
|
+
/**
|
|
1181
|
+
* A type/string-pattern filter used for `include`, `exclude`, and `override` matching.
|
|
1182
|
+
*/
|
|
1183
|
+
type PatternFilter = {
|
|
1184
|
+
type: string;
|
|
1185
|
+
pattern: string | RegExp;
|
|
1186
|
+
};
|
|
1187
|
+
/**
|
|
1188
|
+
* A pattern filter paired with partial option overrides to apply when the pattern matches.
|
|
1189
|
+
*/
|
|
1190
|
+
type PatternOverride<TOptions> = PatternFilter & {
|
|
1191
|
+
options: Omit<Partial<TOptions>, 'override'>;
|
|
1192
|
+
};
|
|
1193
|
+
/**
|
|
1194
|
+
* Context passed to `resolver.resolveOptions` to apply include/exclude/override filtering
|
|
1195
|
+
* for a given operation or schema node.
|
|
1196
|
+
*/
|
|
1197
|
+
/**
|
|
1198
|
+
* Resolves filtered options for a given operation or schema node.
|
|
1199
|
+
*
|
|
1200
|
+
* @internal
|
|
1201
|
+
*/
|
|
1202
|
+
type ResolveOptionsContext<TOptions> = {
|
|
1203
|
+
options: TOptions;
|
|
1204
|
+
exclude?: Array<PatternFilter>;
|
|
1205
|
+
include?: Array<PatternFilter>;
|
|
1206
|
+
override?: Array<PatternOverride<TOptions>>;
|
|
1207
|
+
};
|
|
1208
|
+
/**
|
|
1209
|
+
* Base constraint for all plugin resolver objects.
|
|
1210
|
+
*
|
|
1211
|
+
* `default`, `resolveOptions`, `resolvePath`, and `resolveFile` are injected automatically
|
|
1212
|
+
* by `defineResolver` — plugin authors may override them but never need to implement them
|
|
1213
|
+
* from scratch.
|
|
1214
|
+
*
|
|
1215
|
+
* @example
|
|
1216
|
+
* ```ts
|
|
1217
|
+
* type MyResolver = Resolver & {
|
|
1218
|
+
* resolveName(node: SchemaNode): string
|
|
1219
|
+
* resolveTypedName(node: SchemaNode): string
|
|
1220
|
+
* }
|
|
1221
|
+
* ```
|
|
1222
|
+
*/
|
|
1223
|
+
type Resolver = {
|
|
1224
|
+
name: string;
|
|
1225
|
+
pluginName: Plugin['name'];
|
|
1226
|
+
default(name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
|
|
1227
|
+
resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null;
|
|
1228
|
+
resolvePath(params: ResolverPathParams, context: ResolverContext): string;
|
|
1229
|
+
resolveFile(params: ResolverFileParams, context: ResolverContext): FileNode;
|
|
1230
|
+
resolveBanner(node: InputNode | null, context: ResolveBannerContext): string | undefined;
|
|
1231
|
+
resolveFooter(node: InputNode | null, context: ResolveBannerContext): string | undefined;
|
|
1232
|
+
};
|
|
1233
|
+
type PluginFactoryOptions<
|
|
1234
|
+
/**
|
|
1235
|
+
* Name to be used for the plugin.
|
|
1236
|
+
*/
|
|
1237
|
+
TName extends string = string,
|
|
1238
|
+
/**
|
|
1239
|
+
* Options of the plugin.
|
|
1240
|
+
*/
|
|
1241
|
+
TOptions extends object = object,
|
|
1242
|
+
/**
|
|
1243
|
+
* Options of the plugin that can be used later on, see `options` inside your plugin config.
|
|
1244
|
+
*/
|
|
1245
|
+
TResolvedOptions extends object = TOptions,
|
|
1246
|
+
/**
|
|
1247
|
+
* Context that you want to expose to other plugins.
|
|
1248
|
+
*/
|
|
1249
|
+
TContext = unknown,
|
|
1250
|
+
/**
|
|
1251
|
+
* When calling `resolvePath` you can specify better types.
|
|
1252
|
+
*/
|
|
1253
|
+
TResolvePathOptions extends object = object,
|
|
1254
|
+
/**
|
|
1255
|
+
* Resolver object that encapsulates the naming and path-resolution helpers used by this plugin.
|
|
1256
|
+
* Use `defineResolver` to define the resolver object and export it alongside the plugin.
|
|
1257
|
+
*/
|
|
1258
|
+
TResolver extends Resolver = Resolver> = {
|
|
1259
|
+
name: TName;
|
|
1260
|
+
options: TOptions;
|
|
1261
|
+
resolvedOptions: TResolvedOptions;
|
|
1262
|
+
context: TContext;
|
|
1263
|
+
resolvePathOptions: TResolvePathOptions;
|
|
1264
|
+
resolver: TResolver;
|
|
1265
|
+
};
|
|
1266
|
+
/**
|
|
1267
|
+
* Internal representation of a plugin after normalization.
|
|
1268
|
+
* Extends the user-facing `Plugin` with runtime fields populated during `kubb:plugin:setup`.
|
|
1269
|
+
* Not part of the public API — use `Plugin` for external-facing interactions.
|
|
1270
|
+
* @internal
|
|
1271
|
+
*/
|
|
1272
|
+
type NormalizedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & {
|
|
1273
|
+
options: TOptions['resolvedOptions'] & {
|
|
1274
|
+
output: Output;
|
|
1275
|
+
include?: Array<Include>;
|
|
1276
|
+
exclude: Array<Exclude$1>;
|
|
1277
|
+
override: Array<Override<TOptions['resolvedOptions']>>;
|
|
1278
|
+
};
|
|
1279
|
+
resolver: TOptions['resolver'];
|
|
1280
|
+
transformer?: Visitor;
|
|
1281
|
+
renderer?: RendererFactory;
|
|
1282
|
+
generators?: Array<Generator>;
|
|
1283
|
+
apply?: (config: Config) => boolean;
|
|
1284
|
+
version?: string;
|
|
1285
|
+
};
|
|
1286
|
+
/**
|
|
1287
|
+
* Partial version of {@link Config} intended for user-facing config entry points.
|
|
1288
|
+
*
|
|
1289
|
+
* Fields that have sensible defaults (`root`, `plugins`, `parsers`, `adapter`) are optional.
|
|
1290
|
+
*/
|
|
1291
|
+
type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter'> & {
|
|
1292
|
+
/**
|
|
1293
|
+
* The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
|
|
1294
|
+
* @default process.cwd()
|
|
1295
|
+
*/
|
|
1296
|
+
root?: string;
|
|
1297
|
+
/**
|
|
1298
|
+
* An array of parsers used to convert generated files to strings.
|
|
1299
|
+
* Each parser handles specific file extensions (e.g. `.ts`, `.tsx`).
|
|
1300
|
+
*
|
|
1301
|
+
* A catch-all fallback parser is always appended last for any unhandled extension.
|
|
1302
|
+
*/
|
|
1303
|
+
parsers?: Array<Parser>;
|
|
1304
|
+
/**
|
|
1305
|
+
* Adapter that converts the input file into a `@kubb/ast` `InputNode`.
|
|
1306
|
+
*/
|
|
1307
|
+
adapter?: Adapter;
|
|
1308
|
+
/**
|
|
1309
|
+
* An array of Kubb plugins used for code generation.
|
|
1310
|
+
* Each entry is a hook-style plugin created with `definePlugin`.
|
|
1311
|
+
*/
|
|
1312
|
+
plugins?: Array<Plugin>;
|
|
1313
|
+
};
|
|
1314
|
+
type ResolveNameParams = {
|
|
1315
|
+
name: string;
|
|
1316
|
+
pluginName?: string;
|
|
1317
|
+
/**
|
|
1318
|
+
* Specifies the type of entity being named.
|
|
1319
|
+
* - `'file'` — customizes the name of the created file (camelCase).
|
|
1320
|
+
* - `'function'` — customizes the exported function names (camelCase).
|
|
1321
|
+
* - `'type'` — customizes TypeScript type names (PascalCase).
|
|
1322
|
+
* - `'const'` — customizes variable names (camelCase).
|
|
1323
|
+
*/
|
|
1324
|
+
type?: 'file' | 'function' | 'type' | 'const';
|
|
1325
|
+
};
|
|
1326
|
+
/**
|
|
1327
|
+
* Context object passed as the second argument to generator `schema`, `operation`, and
|
|
1328
|
+
* `operations` methods.
|
|
1329
|
+
*
|
|
1330
|
+
* Generators are only invoked from `runPluginAstHooks`, which already guards against a
|
|
1331
|
+
* missing adapter. This type reflects that guarantee — `ctx.adapter` and `ctx.inputNode`
|
|
1332
|
+
* are always defined, so no runtime checks or casts are needed inside generator bodies.
|
|
1333
|
+
*
|
|
1334
|
+
* `ctx.options` carries the per-node resolved options for `schema`/`operation` calls
|
|
1335
|
+
* (after exclude/include/override filtering) and the plugin-level options for `operations`.
|
|
1336
|
+
*/
|
|
1337
|
+
type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1338
|
+
config: Config;
|
|
1339
|
+
/**
|
|
1340
|
+
* Absolute path to the output directory for the current plugin.
|
|
1341
|
+
* Shorthand for `path.resolve(config.root, config.output.path)`.
|
|
1342
|
+
*/
|
|
1343
|
+
root: string;
|
|
1344
|
+
/**
|
|
1345
|
+
* Returns the output mode for the given output config.
|
|
1346
|
+
* Returns `'single'` when `output.path` has a file extension, `'split'` otherwise.
|
|
1347
|
+
*/
|
|
1348
|
+
getMode: (output: {
|
|
1349
|
+
path: string;
|
|
1350
|
+
}) => 'single' | 'split';
|
|
1351
|
+
driver: PluginDriver;
|
|
1352
|
+
/**
|
|
1353
|
+
* Get a plugin by name. Returns the plugin typed via `Kubb.PluginRegistry` when
|
|
1354
|
+
* the name is a registered key, otherwise returns the generic `Plugin`.
|
|
1355
|
+
*/
|
|
1356
|
+
getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
|
|
1357
|
+
getPlugin(name: string): Plugin | undefined;
|
|
1358
|
+
/**
|
|
1359
|
+
* Like `getPlugin` but throws a descriptive error when the plugin is not found.
|
|
1360
|
+
*/
|
|
1361
|
+
requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>;
|
|
1362
|
+
requirePlugin(name: string): Plugin;
|
|
1363
|
+
/**
|
|
1364
|
+
* Get a resolver by plugin name. Returns the resolver typed via `Kubb.PluginRegistry` when
|
|
1365
|
+
* the name is a registered key, otherwise returns the generic `Resolver`.
|
|
1366
|
+
*/
|
|
1367
|
+
getResolver<TName extends keyof Kubb.PluginRegistry>(name: TName): Kubb.PluginRegistry[TName]['resolver'];
|
|
1368
|
+
getResolver(name: string): Resolver;
|
|
1369
|
+
/**
|
|
1370
|
+
* Add files only when they do not exist yet.
|
|
1371
|
+
*/
|
|
1372
|
+
addFile: (...file: Array<FileNode>) => Promise<void>;
|
|
1373
|
+
/**
|
|
1374
|
+
* Merge multiple sources into the same output file.
|
|
1375
|
+
*/
|
|
1376
|
+
upsertFile: (...file: Array<FileNode>) => Promise<void>;
|
|
1377
|
+
hooks: AsyncEventEmitter<KubbHooks>;
|
|
1378
|
+
/**
|
|
1379
|
+
* The current plugin.
|
|
1380
|
+
*/
|
|
1381
|
+
plugin: Plugin<TOptions>;
|
|
1382
|
+
/**
|
|
1383
|
+
* Resolver for the current plugin.
|
|
1384
|
+
*/
|
|
1385
|
+
resolver: TOptions['resolver'];
|
|
1386
|
+
/**
|
|
1387
|
+
* Composed transformer for the current plugin.
|
|
1388
|
+
*/
|
|
1389
|
+
transformer: Visitor | undefined;
|
|
1390
|
+
/**
|
|
1391
|
+
* Emit a warning via the build event system.
|
|
1392
|
+
*/
|
|
1393
|
+
warn: (message: string) => void;
|
|
1394
|
+
/**
|
|
1395
|
+
* Emit an error via the build event system.
|
|
1396
|
+
*/
|
|
1397
|
+
error: (error: string | Error) => void;
|
|
1398
|
+
/**
|
|
1399
|
+
* Emit an info message via the build event system.
|
|
1400
|
+
*/
|
|
1401
|
+
info: (message: string) => void;
|
|
1402
|
+
/**
|
|
1403
|
+
* Opens the Kubb Studio URL for the current `inputNode` in the default browser.
|
|
1404
|
+
*/
|
|
1405
|
+
openInStudio: (options?: DevtoolsOptions) => Promise<void>;
|
|
1406
|
+
/**
|
|
1407
|
+
* The adapter from `@kubb/ast`.
|
|
1408
|
+
*/
|
|
1409
|
+
adapter: Adapter;
|
|
1410
|
+
/**
|
|
1411
|
+
* The universal `@kubb/ast` `InputNode` produced by the configured adapter.
|
|
1412
|
+
*/
|
|
1413
|
+
inputNode: InputNode;
|
|
1414
|
+
/**
|
|
1415
|
+
* Per-node resolved options (after exclude/include/override filtering).
|
|
1416
|
+
*/
|
|
1417
|
+
options: TOptions['resolvedOptions'];
|
|
1418
|
+
};
|
|
1419
|
+
/**
|
|
1420
|
+
* Configure generated file output location and behavior.
|
|
1421
|
+
*/
|
|
1422
|
+
type Output<_TOptions = unknown> = {
|
|
1423
|
+
/**
|
|
1424
|
+
* Path to the output folder or file that will contain generated code.
|
|
1425
|
+
*/
|
|
1426
|
+
path: string;
|
|
1427
|
+
/**
|
|
1428
|
+
* Define what needs to be exported, here you can also disable the export of barrel files
|
|
1429
|
+
* @default 'named'
|
|
1430
|
+
*/
|
|
1431
|
+
barrelType?: BarrelType | false;
|
|
1432
|
+
/**
|
|
1433
|
+
* Text or function appended at the start of every generated file.
|
|
1434
|
+
* When a function, receives the current `InputNode` and must return a string.
|
|
1435
|
+
*/
|
|
1436
|
+
banner?: string | ((node?: InputNode) => string);
|
|
1437
|
+
/**
|
|
1438
|
+
* Text or function appended at the end of every generated file.
|
|
1439
|
+
* When a function, receives the current `InputNode` and must return a string.
|
|
1440
|
+
*/
|
|
1441
|
+
footer?: string | ((node?: InputNode) => string);
|
|
1442
|
+
/**
|
|
1443
|
+
* Whether to override existing external files if they already exist.
|
|
1444
|
+
* @default false
|
|
1445
|
+
*/
|
|
1446
|
+
override?: boolean;
|
|
1447
|
+
};
|
|
1448
|
+
type Group = {
|
|
1449
|
+
/**
|
|
1450
|
+
* Determines how files are grouped into subdirectories.
|
|
1451
|
+
* - `'tag'` groups files by OpenAPI tags.
|
|
1452
|
+
* - `'path'` groups files by OpenAPI paths.
|
|
1453
|
+
*/
|
|
1454
|
+
type: 'tag' | 'path';
|
|
1455
|
+
/**
|
|
1456
|
+
* Returns the subdirectory name for a given group value.
|
|
1457
|
+
* Defaults to `${camelCase(group)}Controller` for tags and the first path segment for paths.
|
|
1458
|
+
*/
|
|
1459
|
+
name?: (context: {
|
|
1460
|
+
group: string;
|
|
1461
|
+
}) => string;
|
|
1462
|
+
};
|
|
1463
|
+
type LoggerOptions = {
|
|
1464
|
+
/**
|
|
1465
|
+
* @default 3
|
|
1466
|
+
*/
|
|
1467
|
+
logLevel: (typeof logLevel)[keyof typeof logLevel];
|
|
1468
|
+
};
|
|
1469
|
+
/**
|
|
1470
|
+
* Shared context passed to all plugins, parsers, and other internals.
|
|
1471
|
+
*/
|
|
1472
|
+
type LoggerContext = AsyncEventEmitter<KubbHooks>;
|
|
1473
|
+
type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
|
|
1474
|
+
name: string;
|
|
1475
|
+
install: (context: LoggerContext, options?: TOptions) => void | Promise<void>;
|
|
1476
|
+
};
|
|
1477
|
+
type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Logger<TOptions>;
|
|
1478
|
+
/**
|
|
1479
|
+
* Context passed to a hook-style plugin's `kubb:plugin:setup` handler.
|
|
1480
|
+
* Provides methods to register generators, configure the resolver, transformer,
|
|
1481
|
+
* and renderer, as well as access to the current build configuration.
|
|
1482
|
+
*/
|
|
1483
|
+
type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1484
|
+
/**
|
|
1485
|
+
* Register a generator on this plugin. Generators are invoked during the AST walk
|
|
1486
|
+
* (schema/operation/operations) exactly like generators declared statically on `createPlugin`.
|
|
1487
|
+
*/
|
|
1488
|
+
addGenerator<TElement = unknown>(generator: Generator<TFactory, TElement>): void;
|
|
1489
|
+
/**
|
|
1490
|
+
* Set or partially override the resolver for this plugin.
|
|
1491
|
+
* The resolver controls file naming and path resolution for generated files.
|
|
1492
|
+
*
|
|
1493
|
+
* When `TFactory` is a concrete `PluginFactoryOptions` (e.g. `PluginClient`),
|
|
1494
|
+
* the resolver parameter is typed to the plugin's own resolver type (e.g. `ResolverClient`).
|
|
1495
|
+
*/
|
|
1496
|
+
setResolver(resolver: Partial<TFactory['resolver']>): void;
|
|
1497
|
+
/**
|
|
1498
|
+
* Set the AST transformer (visitor) for this plugin.
|
|
1499
|
+
* The transformer pre-processes nodes before they reach the generators.
|
|
1500
|
+
*/
|
|
1501
|
+
setTransformer(visitor: Visitor): void;
|
|
1502
|
+
/**
|
|
1503
|
+
* Set the renderer factory for this plugin.
|
|
1504
|
+
* Used to process JSX elements returned by generators.
|
|
1505
|
+
*/
|
|
1506
|
+
setRenderer(renderer: RendererFactory): void;
|
|
1507
|
+
/**
|
|
1508
|
+
* Set the resolved options for the build loop. These options are merged into the
|
|
1509
|
+
* normalized plugin's `options` object (which includes `output`, `exclude`, `override`).
|
|
1510
|
+
*
|
|
1511
|
+
* Call this in `kubb:plugin:setup` to provide the resolved options that generators
|
|
1512
|
+
* and the build loop need (e.g., `enumType`, `optionalType`, `group`).
|
|
1513
|
+
*/
|
|
1514
|
+
setOptions(options: TFactory['resolvedOptions']): void;
|
|
1515
|
+
/**
|
|
1516
|
+
* Inject a raw file into the build output, bypassing the normal generation pipeline.
|
|
1517
|
+
*/
|
|
1518
|
+
injectFile(file: Pick<FileNode, 'baseName' | 'path'> & {
|
|
1519
|
+
sources?: FileNode['sources'];
|
|
1520
|
+
}): void;
|
|
1521
|
+
/**
|
|
1522
|
+
* Merge a partial config update into the current build configuration.
|
|
1523
|
+
*/
|
|
1524
|
+
updateConfig(config: Partial<Config>): void;
|
|
1525
|
+
/**
|
|
1526
|
+
* The resolved build configuration at the time of setup.
|
|
1527
|
+
*/
|
|
1528
|
+
config: Config;
|
|
1529
|
+
/**
|
|
1530
|
+
* The plugin's own options as passed by the user.
|
|
1531
|
+
*/
|
|
1532
|
+
options: TFactory['options'];
|
|
1533
|
+
};
|
|
1534
|
+
/**
|
|
1535
|
+
* Context passed to a hook-style plugin's `kubb:build:start` handler.
|
|
1536
|
+
* Fires immediately before the plugin execution loop begins.
|
|
1537
|
+
*/
|
|
1538
|
+
type KubbBuildStartContext = {
|
|
1539
|
+
config: Config;
|
|
1540
|
+
adapter: Adapter;
|
|
1541
|
+
inputNode: InputNode;
|
|
1542
|
+
/**
|
|
1543
|
+
* Get a plugin by name. Returns the plugin typed via `Kubb.PluginRegistry` when
|
|
1544
|
+
* the name is a registered key, otherwise returns the generic `Plugin`.
|
|
1545
|
+
*/
|
|
1546
|
+
getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
|
|
1547
|
+
getPlugin(name: string): Plugin | undefined;
|
|
1548
|
+
};
|
|
1549
|
+
/**
|
|
1550
|
+
* Context passed to a hook-style plugin's `kubb:build:end` handler.
|
|
1551
|
+
* Fires after all files have been written to disk.
|
|
1552
|
+
*/
|
|
1553
|
+
type KubbBuildEndContext = {
|
|
1554
|
+
files: Array<FileNode>;
|
|
1555
|
+
config: Config;
|
|
1556
|
+
outputDir: string;
|
|
1557
|
+
};
|
|
1558
|
+
type ByTag = {
|
|
1559
|
+
type: 'tag';
|
|
1560
|
+
pattern: string | RegExp;
|
|
1561
|
+
};
|
|
1562
|
+
type ByOperationId = {
|
|
1563
|
+
type: 'operationId';
|
|
1564
|
+
pattern: string | RegExp;
|
|
1565
|
+
};
|
|
1566
|
+
type ByPath = {
|
|
1567
|
+
type: 'path';
|
|
1568
|
+
pattern: string | RegExp;
|
|
1569
|
+
};
|
|
1570
|
+
type ByMethod = {
|
|
1571
|
+
type: 'method';
|
|
1572
|
+
pattern: HttpMethod | RegExp;
|
|
1573
|
+
};
|
|
1574
|
+
type BySchemaName = {
|
|
1575
|
+
type: 'schemaName';
|
|
1576
|
+
pattern: string | RegExp;
|
|
1577
|
+
};
|
|
1578
|
+
type ByContentType = {
|
|
1579
|
+
type: 'contentType';
|
|
1580
|
+
pattern: string | RegExp;
|
|
1581
|
+
};
|
|
1582
|
+
/**
|
|
1583
|
+
* A pattern filter that prevents matching nodes from being generated.
|
|
1584
|
+
* Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
|
|
1585
|
+
*/
|
|
1586
|
+
type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
|
|
1587
|
+
/**
|
|
1588
|
+
* A pattern filter that restricts generation to only matching nodes.
|
|
1589
|
+
* Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
|
|
1590
|
+
*/
|
|
1591
|
+
type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
|
|
1592
|
+
/**
|
|
1593
|
+
* A pattern filter paired with partial option overrides applied when the pattern matches.
|
|
1594
|
+
* Match by `tag`, `operationId`, `path`, `method`, `schemaName`, or `contentType`.
|
|
1595
|
+
*/
|
|
1596
|
+
type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
1597
|
+
options: Partial<TOptions>;
|
|
1598
|
+
};
|
|
1599
|
+
/**
|
|
1600
|
+
* File-specific parameters for `Resolver.resolvePath`.
|
|
1601
|
+
*
|
|
1602
|
+
* Pass alongside a `ResolverContext` to identify which file to resolve.
|
|
1603
|
+
* Provide `tag` for tag-based grouping or `path` for path-based grouping.
|
|
1604
|
+
*
|
|
1605
|
+
* @example
|
|
1606
|
+
* ```ts
|
|
1607
|
+
* resolver.resolvePath(
|
|
1608
|
+
* { baseName: 'petTypes.ts', tag: 'pets' },
|
|
1609
|
+
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
1610
|
+
* )
|
|
1611
|
+
* // → '/src/types/petsController/petTypes.ts'
|
|
1612
|
+
* ```
|
|
1613
|
+
*/
|
|
1614
|
+
type ResolverPathParams = {
|
|
1615
|
+
baseName: FileNode['baseName'];
|
|
1616
|
+
pathMode?: 'single' | 'split';
|
|
1617
|
+
/**
|
|
1618
|
+
* Tag value used when `group.type === 'tag'`.
|
|
1619
|
+
*/
|
|
1620
|
+
tag?: string;
|
|
1621
|
+
/**
|
|
1622
|
+
* Path value used when `group.type === 'path'`.
|
|
1623
|
+
*/
|
|
1624
|
+
path?: string;
|
|
1625
|
+
};
|
|
1626
|
+
/**
|
|
1627
|
+
* Shared context passed as the second argument to `Resolver.resolvePath` and `Resolver.resolveFile`.
|
|
1628
|
+
*
|
|
1629
|
+
* Describes where on disk output is rooted, which output config is active, and the optional
|
|
1630
|
+
* grouping strategy that controls subdirectory layout.
|
|
1631
|
+
*
|
|
1632
|
+
* @example
|
|
1633
|
+
* ```ts
|
|
1634
|
+
* const context: ResolverContext = {
|
|
1635
|
+
* root: config.root,
|
|
1636
|
+
* output,
|
|
1637
|
+
* group,
|
|
1638
|
+
* }
|
|
1639
|
+
* ```
|
|
1640
|
+
*/
|
|
1641
|
+
type ResolverContext = {
|
|
1642
|
+
root: string;
|
|
1643
|
+
output: Output;
|
|
1644
|
+
group?: Group;
|
|
1645
|
+
/**
|
|
1646
|
+
* Plugin name used to populate `meta.pluginName` on the resolved file.
|
|
1647
|
+
*/
|
|
1648
|
+
pluginName?: string;
|
|
1649
|
+
};
|
|
1650
|
+
/**
|
|
1651
|
+
* File-specific parameters for `Resolver.resolveFile`.
|
|
1652
|
+
*
|
|
1653
|
+
* Pass alongside a `ResolverContext` to fully describe the file to resolve.
|
|
1654
|
+
* `tag` and `path` are used only when a matching `group` is present in the context.
|
|
1655
|
+
*
|
|
1656
|
+
* @example
|
|
1657
|
+
* ```ts
|
|
1658
|
+
* resolver.resolveFile(
|
|
1659
|
+
* { name: 'listPets', extname: '.ts', tag: 'pets' },
|
|
1660
|
+
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
1661
|
+
* )
|
|
1662
|
+
* // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
|
|
1663
|
+
* ```
|
|
1664
|
+
*/
|
|
1665
|
+
type ResolverFileParams = {
|
|
1666
|
+
name: string;
|
|
1667
|
+
extname: FileNode['extname'];
|
|
1668
|
+
/**
|
|
1669
|
+
* Tag value used when `group.type === 'tag'`.
|
|
1670
|
+
*/
|
|
1671
|
+
tag?: string;
|
|
1672
|
+
/**
|
|
1673
|
+
* Path value used when `group.type === 'path'`.
|
|
1674
|
+
*/
|
|
1675
|
+
path?: string;
|
|
1676
|
+
};
|
|
1677
|
+
/**
|
|
1678
|
+
* Context passed to `Resolver.resolveBanner` and `Resolver.resolveFooter`.
|
|
1679
|
+
*
|
|
1680
|
+
* `output` is optional — not every plugin configures a banner/footer.
|
|
1681
|
+
* `config` carries the global Kubb config, used to derive the default Kubb banner.
|
|
1682
|
+
*
|
|
1683
|
+
* @example
|
|
1684
|
+
* ```ts
|
|
1685
|
+
* resolver.resolveBanner(inputNode, { output: { banner: '// generated' }, config })
|
|
1686
|
+
* // → '// generated'
|
|
1687
|
+
* ```
|
|
1688
|
+
*/
|
|
1689
|
+
type ResolveBannerContext = {
|
|
1690
|
+
output?: Pick<Output, 'banner' | 'footer'>;
|
|
1691
|
+
config: Config;
|
|
1692
|
+
};
|
|
1693
|
+
/**
|
|
1694
|
+
* CLI options derived from command-line flags.
|
|
1695
|
+
*/
|
|
1696
|
+
type CLIOptions = {
|
|
1697
|
+
/**
|
|
1698
|
+
* Path to `kubb.config.js`.
|
|
1699
|
+
*/
|
|
1700
|
+
config?: string;
|
|
1701
|
+
/**
|
|
1702
|
+
* Enable watch mode for input files.
|
|
1703
|
+
*/
|
|
1704
|
+
watch?: boolean;
|
|
1705
|
+
/**
|
|
1706
|
+
* Logging verbosity for CLI usage.
|
|
1707
|
+
* @default 'silent'
|
|
1708
|
+
*/
|
|
1709
|
+
logLevel?: 'silent' | 'info' | 'debug';
|
|
1710
|
+
};
|
|
1711
|
+
/**
|
|
1712
|
+
* All accepted forms of a Kubb configuration.
|
|
1713
|
+
*
|
|
1714
|
+
* Config is always `@kubb/core` {@link Config}.
|
|
1715
|
+
* - `PossibleConfig` accepts `Config`/`Config[]`/promise or a no-arg config factory.
|
|
1716
|
+
* - `PossibleConfig<TCliOptions>` accepts the same config forms or a config factory receiving `TCliOptions`.
|
|
1717
|
+
*/
|
|
1718
|
+
type PossibleConfig<TCliOptions = undefined> = PossiblePromise<Config | Config[]> | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Config[]>);
|
|
1719
|
+
//#endregion
|
|
1720
|
+
export { AsyncEventEmitter as $, ResolverFileParams as A, createKubb as B, PluginFactoryOptions as C, ResolveOptionsContext as D, ResolveNameParams as E, Plugin as F, Generator as G, FileManager as H, definePlugin as I, createStorage as J, defineGenerator as K, Kubb$1 as L, UserConfig as M, UserLogger as N, Resolver as O, FileMetaBase as P, logLevel as Q, KubbHooks as R, Override as S, ResolveBannerContext as T, Parser as U, PluginDriver as V, defineParser as W, RendererFactory as X, Renderer as Y, createRenderer as Z, Logger as _, CLIOptions as a, NormalizedPlugin as b, Exclude$1 as c, Include as d, InputData as f, KubbPluginSetupContext as g, KubbBuildStartContext as h, BarrelType as i, ResolverPathParams as j, ResolverContext as k, GeneratorContext as l, KubbBuildEndContext as m, AdapterFactoryOptions as n, Config as o, InputPath as p, Storage as q, AdapterSource as r, DevtoolsOptions as s, Adapter as t, Group as u, LoggerContext as v, PossibleConfig as w, Output as x, LoggerOptions as y, BuildOutput as z };
|
|
1721
|
+
//# sourceMappingURL=types-DfEv9d_c.d.ts.map
|