@kubb/core 5.0.0-alpha.34 → 5.0.0-alpha.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PluginDriver-B_65W4fv.js +1677 -0
- package/dist/PluginDriver-B_65W4fv.js.map +1 -0
- package/dist/{PluginDriver-BBi_41VF.d.ts → PluginDriver-C9iBgYbk.d.ts} +743 -376
- package/dist/PluginDriver-CCdkwR14.cjs +1806 -0
- package/dist/PluginDriver-CCdkwR14.cjs.map +1 -0
- package/dist/hooks.d.ts +1 -1
- package/dist/index.cjs +272 -1666
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +62 -141
- package/dist/index.js +231 -1623
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +165 -0
- package/dist/mocks.cjs.map +1 -0
- package/dist/mocks.d.ts +74 -0
- package/dist/mocks.js +159 -0
- package/dist/mocks.js.map +1 -0
- package/package.json +11 -5
- package/src/FileManager.ts +1 -1
- package/src/FileProcessor.ts +1 -1
- package/src/Kubb.ts +145 -38
- package/src/PluginDriver.ts +318 -40
- package/src/constants.ts +1 -1
- package/src/{build.ts → createKubb.ts} +180 -122
- package/src/createPlugin.ts +1 -0
- package/src/createRenderer.ts +57 -0
- package/src/defineGenerator.ts +57 -84
- package/src/defineLogger.ts +2 -2
- package/src/defineParser.ts +3 -2
- package/src/definePlugin.ts +95 -0
- package/src/defineResolver.ts +1 -1
- package/src/devtools.ts +1 -1
- package/src/index.ts +7 -6
- package/src/mocks.ts +234 -0
- package/src/renderNode.ts +35 -0
- package/src/types.ts +275 -210
- package/src/utils/TreeNode.ts +1 -1
- package/src/utils/getBarrelFiles.ts +3 -3
- package/src/utils/getFunctionParams.ts +14 -7
- package/src/utils/isInputPath.ts +2 -2
- package/src/utils/packageJSON.ts +2 -3
- package/src/defineConfig.ts +0 -51
- package/src/definePresets.ts +0 -16
- package/src/renderNode.tsx +0 -28
- package/src/utils/getConfigs.ts +0 -16
- package/src/utils/getPreset.ts +0 -78
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { FileNode, ImportNode, InputNode, Node, OperationNode,
|
|
3
|
-
import { HttpMethod } from "@kubb/oas";
|
|
4
|
-
import { KubbReactNode } from "@kubb/renderer-jsx/types";
|
|
2
|
+
import { FileNode, HttpMethod, ImportNode, InputNode, Node, OperationNode, SchemaNode, Visitor } from "@kubb/ast";
|
|
5
3
|
|
|
6
4
|
//#region ../../internals/utils/src/asyncEventEmitter.d.ts
|
|
7
5
|
/**
|
|
@@ -63,6 +61,16 @@ declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[
|
|
|
63
61
|
* ```
|
|
64
62
|
*/
|
|
65
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;
|
|
66
74
|
/**
|
|
67
75
|
* Removes all listeners from every event channel.
|
|
68
76
|
*
|
|
@@ -86,43 +94,58 @@ declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[
|
|
|
86
94
|
*/
|
|
87
95
|
type PossiblePromise<T> = Promise<T> | T;
|
|
88
96
|
//#endregion
|
|
89
|
-
//#region src/
|
|
97
|
+
//#region src/createRenderer.d.ts
|
|
90
98
|
/**
|
|
91
|
-
*
|
|
99
|
+
* Minimal interface any Kubb renderer must satisfy.
|
|
92
100
|
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
101
|
+
* The generic `TElement` is the type of the element the renderer accepts —
|
|
102
|
+
* e.g. `KubbReactElement` for `@kubb/renderer-jsx`, or a custom type for
|
|
103
|
+
* your own renderer. Defaults to `unknown` so that generators which do not
|
|
104
|
+
* care about the element type continue to work without specifying it.
|
|
105
|
+
*
|
|
106
|
+
* This allows core to drive rendering without a hard dependency on
|
|
107
|
+
* `@kubb/renderer-jsx` or any specific renderer implementation.
|
|
108
|
+
*/
|
|
109
|
+
type Renderer<TElement = unknown> = {
|
|
110
|
+
render(element: TElement): Promise<void>;
|
|
111
|
+
unmount(error?: Error | number | null): void;
|
|
112
|
+
readonly files: Array<FileNode>;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* A factory function that produces a fresh {@link Renderer} per render.
|
|
116
|
+
*
|
|
117
|
+
* Generators use this to declare which renderer handles their output.
|
|
118
|
+
*/
|
|
119
|
+
type RendererFactory<TElement = unknown> = () => Renderer<TElement>;
|
|
120
|
+
/**
|
|
121
|
+
* Creates a renderer factory for use in generator definitions.
|
|
122
|
+
*
|
|
123
|
+
* Wrap your renderer factory function with this helper to register it as the
|
|
124
|
+
* renderer for a generator. Core will call this factory once per render cycle
|
|
125
|
+
* to obtain a fresh renderer instance.
|
|
95
126
|
*
|
|
96
127
|
* @example
|
|
97
128
|
* ```ts
|
|
98
|
-
*
|
|
129
|
+
* // packages/renderer-jsx/src/index.ts
|
|
130
|
+
* export const jsxRenderer = createRenderer(() => {
|
|
131
|
+
* const runtime = new Runtime()
|
|
132
|
+
* return {
|
|
133
|
+
* async render(element) { await runtime.render(element) },
|
|
134
|
+
* get files() { return runtime.nodes },
|
|
135
|
+
* unmount(error) { runtime.unmount(error) },
|
|
136
|
+
* }
|
|
137
|
+
* })
|
|
99
138
|
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
139
|
+
* // packages/plugin-zod/src/generators/zodGenerator.tsx
|
|
140
|
+
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
141
|
+
* export const zodGenerator = defineGenerator<PluginZod>({
|
|
142
|
+
* name: 'zod',
|
|
143
|
+
* renderer: jsxRenderer,
|
|
144
|
+
* schema(node, options) { return <File ...>...</File> },
|
|
145
|
+
* })
|
|
103
146
|
* ```
|
|
104
147
|
*/
|
|
105
|
-
declare
|
|
106
|
-
#private;
|
|
107
|
-
/**
|
|
108
|
-
* Adds one or more files. Files with the same path are merged — sources, imports,
|
|
109
|
-
* and exports from all calls with the same path are concatenated together.
|
|
110
|
-
*/
|
|
111
|
-
add(...files: Array<FileNode>): Array<FileNode>;
|
|
112
|
-
/**
|
|
113
|
-
* Adds or merges one or more files.
|
|
114
|
-
* If a file with the same path already exists, its sources/imports/exports are merged together.
|
|
115
|
-
*/
|
|
116
|
-
upsert(...files: Array<FileNode>): Array<FileNode>;
|
|
117
|
-
getByPath(path: string): FileNode | null;
|
|
118
|
-
deleteByPath(path: string): void;
|
|
119
|
-
clear(): void;
|
|
120
|
-
/**
|
|
121
|
-
* All stored files, sorted by path length (shorter paths first).
|
|
122
|
-
* Barrel/index files (e.g. index.ts) are sorted last within each length bucket.
|
|
123
|
-
*/
|
|
124
|
-
get files(): Array<FileNode>;
|
|
125
|
-
}
|
|
148
|
+
declare function createRenderer<TElement = unknown>(factory: RendererFactory<TElement>): RendererFactory<TElement>;
|
|
126
149
|
//#endregion
|
|
127
150
|
//#region src/constants.d.ts
|
|
128
151
|
/**
|
|
@@ -248,80 +271,6 @@ type Storage = {
|
|
|
248
271
|
*/
|
|
249
272
|
declare function createStorage<TOptions = Record<string, never>>(build: (options: TOptions) => Storage): (options?: TOptions) => Storage;
|
|
250
273
|
//#endregion
|
|
251
|
-
//#region src/defineGenerator.d.ts
|
|
252
|
-
/**
|
|
253
|
-
* A generator is a named object with optional `schema`, `operation`, and `operations`
|
|
254
|
-
* methods. Each method is called with `this = PluginContext` of the parent plugin,
|
|
255
|
-
* giving full access to `this.config`, `this.resolver`, `this.adapter`,
|
|
256
|
-
* `this.driver`, etc.
|
|
257
|
-
*
|
|
258
|
-
* Return a React element, an array of `FileNode`, or `void` to handle file
|
|
259
|
-
* writing manually via `this.upsertFile`. Both React and core (non-React) generators
|
|
260
|
-
* use the same method signatures — the return type determines how output is handled.
|
|
261
|
-
*
|
|
262
|
-
* @example
|
|
263
|
-
* ```ts
|
|
264
|
-
* export const typeGenerator = defineGenerator<PluginTs>({
|
|
265
|
-
* name: 'typescript',
|
|
266
|
-
* schema(node, options) {
|
|
267
|
-
* const { adapter, resolver, root } = this
|
|
268
|
-
* return <File ...><Type node={node} resolver={resolver} /></File>
|
|
269
|
-
* },
|
|
270
|
-
* operation(node, options) {
|
|
271
|
-
* return <File ...><OperationType node={node} /></File>
|
|
272
|
-
* },
|
|
273
|
-
* })
|
|
274
|
-
* ```
|
|
275
|
-
*/
|
|
276
|
-
type Generator<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
277
|
-
/** Used in diagnostic messages and debug output. */name: string;
|
|
278
|
-
/**
|
|
279
|
-
* Called for each schema node in the AST walk.
|
|
280
|
-
* `this` is the parent plugin's context with `adapter` and `inputNode` guaranteed present.
|
|
281
|
-
* `options` contains the per-node resolved options (after exclude/include/override).
|
|
282
|
-
*/
|
|
283
|
-
schema?: (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<KubbReactNode | Array<FileNode> | void>;
|
|
284
|
-
/**
|
|
285
|
-
* Called for each operation node in the AST walk.
|
|
286
|
-
* `this` is the parent plugin's context with `adapter` and `inputNode` guaranteed present.
|
|
287
|
-
*/
|
|
288
|
-
operation?: (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<KubbReactNode | Array<FileNode> | void>;
|
|
289
|
-
/**
|
|
290
|
-
* Called once after all operations have been walked.
|
|
291
|
-
* `this` is the parent plugin's context with `adapter` and `inputNode` guaranteed present.
|
|
292
|
-
*/
|
|
293
|
-
operations?: (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<KubbReactNode | Array<FileNode> | void>;
|
|
294
|
-
};
|
|
295
|
-
/**
|
|
296
|
-
* Defines a generator. Returns the object as-is with correct `this` typings.
|
|
297
|
-
* No type discrimination (`type: 'react' | 'core'`) needed — `applyHookResult`
|
|
298
|
-
* handles React elements and `File[]` uniformly.
|
|
299
|
-
*/
|
|
300
|
-
declare function defineGenerator<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(generator: Generator<TOptions>): Generator<TOptions>;
|
|
301
|
-
/**
|
|
302
|
-
* Merges an array of generators into a single generator.
|
|
303
|
-
*
|
|
304
|
-
* The merged generator's `schema`, `operation`, and `operations` methods run
|
|
305
|
-
* the corresponding method from each input generator in sequence, applying each
|
|
306
|
-
* result via `applyHookResult`. This eliminates the need to write the loop
|
|
307
|
-
* manually in each plugin.
|
|
308
|
-
*
|
|
309
|
-
* @param generators - Array of generators to merge into a single generator.
|
|
310
|
-
*
|
|
311
|
-
* @example
|
|
312
|
-
* ```ts
|
|
313
|
-
* const merged = mergeGenerators(generators)
|
|
314
|
-
*
|
|
315
|
-
* return {
|
|
316
|
-
* name: pluginName,
|
|
317
|
-
* schema: merged.schema,
|
|
318
|
-
* operation: merged.operation,
|
|
319
|
-
* operations: merged.operations,
|
|
320
|
-
* }
|
|
321
|
-
* ```
|
|
322
|
-
*/
|
|
323
|
-
declare function mergeGenerators<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(generators: Array<Generator<TOptions>>): Generator<TOptions>;
|
|
324
|
-
//#endregion
|
|
325
274
|
//#region src/defineParser.d.ts
|
|
326
275
|
type PrintOptions = {
|
|
327
276
|
extname?: FileNode['extname'];
|
|
@@ -332,7 +281,8 @@ type Parser<TMeta extends object = any> = {
|
|
|
332
281
|
* File extensions this parser handles.
|
|
333
282
|
* Use `undefined` to create a catch-all fallback parser.
|
|
334
283
|
*
|
|
335
|
-
* @example
|
|
284
|
+
* @example Handled extensions
|
|
285
|
+
* `['.ts', '.js']`
|
|
336
286
|
*/
|
|
337
287
|
extNames: Array<FileNode['extname']> | undefined;
|
|
338
288
|
/**
|
|
@@ -362,6 +312,54 @@ type Parser<TMeta extends object = any> = {
|
|
|
362
312
|
*/
|
|
363
313
|
declare function defineParser<TMeta extends object = any>(parser: Parser<TMeta>): Parser<TMeta>;
|
|
364
314
|
//#endregion
|
|
315
|
+
//#region src/createKubb.d.ts
|
|
316
|
+
/**
|
|
317
|
+
* Full output produced by a successful or failed build.
|
|
318
|
+
*/
|
|
319
|
+
type BuildOutput = {
|
|
320
|
+
/**
|
|
321
|
+
* Plugins that threw during installation, paired with the caught error.
|
|
322
|
+
*/
|
|
323
|
+
failedPlugins: Set<{
|
|
324
|
+
plugin: Plugin;
|
|
325
|
+
error: Error;
|
|
326
|
+
}>;
|
|
327
|
+
files: Array<FileNode>;
|
|
328
|
+
driver: PluginDriver;
|
|
329
|
+
/**
|
|
330
|
+
* Elapsed time in milliseconds for each plugin, keyed by plugin name.
|
|
331
|
+
*/
|
|
332
|
+
pluginTimings: Map<string, number>;
|
|
333
|
+
error?: Error;
|
|
334
|
+
/**
|
|
335
|
+
* Raw generated source, keyed by absolute file path.
|
|
336
|
+
*/
|
|
337
|
+
sources: Map<string, string>;
|
|
338
|
+
};
|
|
339
|
+
type KubbOptions = {
|
|
340
|
+
config: Config;
|
|
341
|
+
hooks?: AsyncEventEmitter<KubbHooks>;
|
|
342
|
+
};
|
|
343
|
+
/**
|
|
344
|
+
* Creates a Kubb instance bound to a single config entry.
|
|
345
|
+
*
|
|
346
|
+
* The instance holds shared state (`hooks`, `sources`, `driver`, `config`) across the
|
|
347
|
+
* `setup → build` lifecycle. Attach event listeners to `kubb.hooks` before
|
|
348
|
+
* calling `setup()` or `build()`.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```ts
|
|
352
|
+
* const kubb = createKubb({ config })
|
|
353
|
+
*
|
|
354
|
+
* kubb.hooks.on('kubb:plugin:end', (plugin, { duration }) => {
|
|
355
|
+
* console.log(`${plugin.name} completed in ${duration}ms`)
|
|
356
|
+
* })
|
|
357
|
+
*
|
|
358
|
+
* const { files, failedPlugins } = await kubb.safeBuild()
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
declare function createKubb(options: KubbOptions): Kubb$1;
|
|
362
|
+
//#endregion
|
|
365
363
|
//#region src/Kubb.d.ts
|
|
366
364
|
type DebugInfo = {
|
|
367
365
|
date: Date;
|
|
@@ -387,6 +385,46 @@ type HookResult<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
|
387
385
|
parameters?: Array<unknown>;
|
|
388
386
|
output?: unknown;
|
|
389
387
|
};
|
|
388
|
+
/**
|
|
389
|
+
* The instance returned by {@link createKubb}.
|
|
390
|
+
*/
|
|
391
|
+
type Kubb$1 = {
|
|
392
|
+
/**
|
|
393
|
+
* The shared event emitter. Attach listeners here before calling `setup()` or `build()`.
|
|
394
|
+
*/
|
|
395
|
+
readonly hooks: AsyncEventEmitter<KubbHooks>;
|
|
396
|
+
/**
|
|
397
|
+
* Raw generated source, keyed by absolute file path.
|
|
398
|
+
* Populated after a successful `build()` or `safeBuild()` call.
|
|
399
|
+
*/
|
|
400
|
+
readonly sources: Map<string, string>;
|
|
401
|
+
/**
|
|
402
|
+
* The plugin driver. Available after `setup()` has been called.
|
|
403
|
+
*/
|
|
404
|
+
readonly driver: PluginDriver | undefined;
|
|
405
|
+
/**
|
|
406
|
+
* The resolved config with applied defaults. Available after `setup()` has been called.
|
|
407
|
+
*/
|
|
408
|
+
readonly config: Config | undefined;
|
|
409
|
+
/**
|
|
410
|
+
* Initializes all Kubb infrastructure: validates input, applies config defaults,
|
|
411
|
+
* runs the adapter, and creates the PluginDriver.
|
|
412
|
+
*
|
|
413
|
+
* Calling `build()` or `safeBuild()` without calling `setup()` first will
|
|
414
|
+
* automatically invoke `setup()` before proceeding.
|
|
415
|
+
*/
|
|
416
|
+
setup(): Promise<void>;
|
|
417
|
+
/**
|
|
418
|
+
* Runs a full Kubb build and throws on any error or plugin failure.
|
|
419
|
+
* Automatically calls `setup()` if it has not been called yet.
|
|
420
|
+
*/
|
|
421
|
+
build(): Promise<BuildOutput>;
|
|
422
|
+
/**
|
|
423
|
+
* Runs a full Kubb build and captures errors instead of throwing.
|
|
424
|
+
* Automatically calls `setup()` if it has not been called yet.
|
|
425
|
+
*/
|
|
426
|
+
safeBuild(): Promise<BuildOutput>;
|
|
427
|
+
};
|
|
390
428
|
/**
|
|
391
429
|
* Events emitted during the Kubb code generation lifecycle.
|
|
392
430
|
* These events can be listened to for logging, progress tracking, and custom integrations.
|
|
@@ -394,49 +432,49 @@ type HookResult<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
|
394
432
|
* @example
|
|
395
433
|
* ```typescript
|
|
396
434
|
* import type { AsyncEventEmitter } from '@internals/utils'
|
|
397
|
-
* import type {
|
|
435
|
+
* import type { KubbHooks } from '@kubb/core'
|
|
398
436
|
*
|
|
399
|
-
* const
|
|
437
|
+
* const hooks: AsyncEventEmitter<KubbHooks> = new AsyncEventEmitter()
|
|
400
438
|
*
|
|
401
|
-
*
|
|
439
|
+
* hooks.on('kubb:lifecycle:start', () => {
|
|
402
440
|
* console.log('Starting Kubb generation')
|
|
403
441
|
* })
|
|
404
442
|
*
|
|
405
|
-
*
|
|
443
|
+
* hooks.on('kubb:plugin:end', (plugin, { duration }) => {
|
|
406
444
|
* console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
|
|
407
445
|
* })
|
|
408
446
|
* ```
|
|
409
447
|
*/
|
|
410
|
-
interface
|
|
448
|
+
interface KubbHooks {
|
|
411
449
|
/**
|
|
412
450
|
* Emitted at the beginning of the Kubb lifecycle, before any code generation starts.
|
|
413
451
|
*/
|
|
414
|
-
'lifecycle:start': [version: string];
|
|
452
|
+
'kubb:lifecycle:start': [version: string];
|
|
415
453
|
/**
|
|
416
454
|
* Emitted at the end of the Kubb lifecycle, after all code generation is complete.
|
|
417
455
|
*/
|
|
418
|
-
'lifecycle:end': [];
|
|
456
|
+
'kubb:lifecycle:end': [];
|
|
419
457
|
/**
|
|
420
458
|
* Emitted when configuration loading starts.
|
|
421
459
|
*/
|
|
422
|
-
'config:start': [];
|
|
460
|
+
'kubb:config:start': [];
|
|
423
461
|
/**
|
|
424
462
|
* Emitted when configuration loading is complete.
|
|
425
463
|
*/
|
|
426
|
-
'config:end': [configs: Array<Config>];
|
|
464
|
+
'kubb:config:end': [configs: Array<Config>];
|
|
427
465
|
/**
|
|
428
466
|
* Emitted when code generation phase starts.
|
|
429
467
|
*/
|
|
430
|
-
'generation:start': [config: Config];
|
|
468
|
+
'kubb:generation:start': [config: Config];
|
|
431
469
|
/**
|
|
432
470
|
* Emitted when code generation phase completes.
|
|
433
471
|
*/
|
|
434
|
-
'generation:end': [config: Config, files: Array<FileNode>, sources: Map<string, string>];
|
|
472
|
+
'kubb:generation:end': [config: Config, files: Array<FileNode>, sources: Map<string, string>];
|
|
435
473
|
/**
|
|
436
474
|
* Emitted with a summary of the generation results.
|
|
437
475
|
* Contains summary lines, title, and success status.
|
|
438
476
|
*/
|
|
439
|
-
'generation:summary': [config: Config, {
|
|
477
|
+
'kubb:generation:summary': [config: Config, {
|
|
440
478
|
failedPlugins: Set<{
|
|
441
479
|
plugin: Plugin;
|
|
442
480
|
error: Error;
|
|
@@ -449,32 +487,32 @@ interface KubbEvents {
|
|
|
449
487
|
/**
|
|
450
488
|
* Emitted when code formatting starts (e.g., running Biome or Prettier).
|
|
451
489
|
*/
|
|
452
|
-
'format:start': [];
|
|
490
|
+
'kubb:format:start': [];
|
|
453
491
|
/**
|
|
454
492
|
* Emitted when code formatting completes.
|
|
455
493
|
*/
|
|
456
|
-
'format:end': [];
|
|
494
|
+
'kubb:format:end': [];
|
|
457
495
|
/**
|
|
458
496
|
* Emitted when linting starts.
|
|
459
497
|
*/
|
|
460
|
-
'lint:start': [];
|
|
498
|
+
'kubb:lint:start': [];
|
|
461
499
|
/**
|
|
462
500
|
* Emitted when linting completes.
|
|
463
501
|
*/
|
|
464
|
-
'lint:end': [];
|
|
502
|
+
'kubb:lint:end': [];
|
|
465
503
|
/**
|
|
466
504
|
* Emitted when plugin hooks execution starts.
|
|
467
505
|
*/
|
|
468
|
-
'hooks:start': [];
|
|
506
|
+
'kubb:hooks:start': [];
|
|
469
507
|
/**
|
|
470
508
|
* Emitted when plugin hooks execution completes.
|
|
471
509
|
*/
|
|
472
|
-
'hooks:end': [];
|
|
510
|
+
'kubb:hooks:end': [];
|
|
473
511
|
/**
|
|
474
512
|
* Emitted when a single hook execution starts (e.g., format or lint).
|
|
475
513
|
* The callback should be invoked when the command completes.
|
|
476
514
|
*/
|
|
477
|
-
'hook:start': [{
|
|
515
|
+
'kubb:hook:start': [{
|
|
478
516
|
id?: string;
|
|
479
517
|
command: string;
|
|
480
518
|
args?: readonly string[];
|
|
@@ -482,7 +520,7 @@ interface KubbEvents {
|
|
|
482
520
|
/**
|
|
483
521
|
* Emitted when a single hook execution completes.
|
|
484
522
|
*/
|
|
485
|
-
'hook:end': [{
|
|
523
|
+
'kubb:hook:end': [{
|
|
486
524
|
id?: string;
|
|
487
525
|
command: string;
|
|
488
526
|
args?: readonly string[];
|
|
@@ -492,38 +530,38 @@ interface KubbEvents {
|
|
|
492
530
|
/**
|
|
493
531
|
* Emitted when a new version of Kubb is available.
|
|
494
532
|
*/
|
|
495
|
-
'version:new': [currentVersion: string, latestVersion: string];
|
|
533
|
+
'kubb:version:new': [currentVersion: string, latestVersion: string];
|
|
496
534
|
/**
|
|
497
535
|
* Informational message event.
|
|
498
536
|
*/
|
|
499
|
-
info: [message: string, info?: string];
|
|
537
|
+
'kubb:info': [message: string, info?: string];
|
|
500
538
|
/**
|
|
501
539
|
* Error event. Emitted when an error occurs during code generation.
|
|
502
540
|
*/
|
|
503
|
-
error: [error: Error, meta?: Record<string, unknown>];
|
|
541
|
+
'kubb:error': [error: Error, meta?: Record<string, unknown>];
|
|
504
542
|
/**
|
|
505
543
|
* Success message event.
|
|
506
544
|
*/
|
|
507
|
-
success: [message: string, info?: string];
|
|
545
|
+
'kubb:success': [message: string, info?: string];
|
|
508
546
|
/**
|
|
509
547
|
* Warning message event.
|
|
510
548
|
*/
|
|
511
|
-
warn: [message: string, info?: string];
|
|
549
|
+
'kubb:warn': [message: string, info?: string];
|
|
512
550
|
/**
|
|
513
551
|
* Debug event for detailed logging.
|
|
514
552
|
* Contains timestamp, log messages, and optional filename.
|
|
515
553
|
*/
|
|
516
|
-
debug: [info: DebugInfo];
|
|
554
|
+
'kubb:debug': [info: DebugInfo];
|
|
517
555
|
/**
|
|
518
556
|
* Emitted when file processing starts.
|
|
519
557
|
* Contains the list of files to be processed.
|
|
520
558
|
*/
|
|
521
|
-
'files:processing:start': [files: Array<FileNode>];
|
|
559
|
+
'kubb:files:processing:start': [files: Array<FileNode>];
|
|
522
560
|
/**
|
|
523
561
|
* Emitted for each file being processed, providing progress updates.
|
|
524
562
|
* Contains processed count, total count, percentage, and file details.
|
|
525
563
|
*/
|
|
526
|
-
'file:processing:update': [{
|
|
564
|
+
'kubb:file:processing:update': [{
|
|
527
565
|
/**
|
|
528
566
|
* Number of files processed so far.
|
|
529
567
|
*/
|
|
@@ -554,16 +592,16 @@ interface KubbEvents {
|
|
|
554
592
|
* Emitted when file processing completes.
|
|
555
593
|
* Contains the list of processed files.
|
|
556
594
|
*/
|
|
557
|
-
'files:processing:end': [files: Array<FileNode>];
|
|
595
|
+
'kubb:files:processing:end': [files: Array<FileNode>];
|
|
558
596
|
/**
|
|
559
597
|
* Emitted when a plugin starts executing.
|
|
560
598
|
*/
|
|
561
|
-
'plugin:start': [plugin: Plugin];
|
|
599
|
+
'kubb:plugin:start': [plugin: Plugin];
|
|
562
600
|
/**
|
|
563
601
|
* Emitted when a plugin completes execution.
|
|
564
602
|
* Duration in ms.
|
|
565
603
|
*/
|
|
566
|
-
'plugin:end': [plugin: Plugin, result: {
|
|
604
|
+
'kubb:plugin:end': [plugin: Plugin, result: {
|
|
567
605
|
duration: number;
|
|
568
606
|
success: boolean;
|
|
569
607
|
error?: Error;
|
|
@@ -572,70 +610,161 @@ interface KubbEvents {
|
|
|
572
610
|
* Emitted when plugin hook progress tracking starts.
|
|
573
611
|
* Contains the hook name and list of plugins to execute.
|
|
574
612
|
*/
|
|
575
|
-
'plugins:hook:progress:start': [progress: HookProgress];
|
|
613
|
+
'kubb:plugins:hook:progress:start': [progress: HookProgress];
|
|
576
614
|
/**
|
|
577
615
|
* Emitted when plugin hook progress tracking ends.
|
|
578
616
|
* Contains the hook name that completed.
|
|
579
617
|
*/
|
|
580
|
-
'plugins:hook:progress:end': [{
|
|
618
|
+
'kubb:plugins:hook:progress:end': [{
|
|
581
619
|
hookName: PluginLifecycleHooks;
|
|
582
620
|
}];
|
|
583
621
|
/**
|
|
584
622
|
* Emitted when a plugin hook starts processing.
|
|
585
623
|
* Contains strategy, hook name, plugin, parameters, and output.
|
|
586
624
|
*/
|
|
587
|
-
'plugins:hook:processing:start': [execution: HookExecution];
|
|
625
|
+
'kubb:plugins:hook:processing:start': [execution: HookExecution];
|
|
588
626
|
/**
|
|
589
627
|
* Emitted when a plugin hook completes processing.
|
|
590
628
|
* Contains duration, strategy, hook name, plugin, parameters, and output.
|
|
591
629
|
*/
|
|
592
|
-
'plugins:hook:processing:end': [result: HookResult];
|
|
630
|
+
'kubb:plugins:hook:processing:end': [result: HookResult];
|
|
631
|
+
/**
|
|
632
|
+
* Fired once — before any plugin's `buildStart` runs — so that hook-style plugins
|
|
633
|
+
* can register generators, configure resolvers/transformers/renderers, or inject
|
|
634
|
+
* extra files. All `kubb:plugin:setup` handlers registered via `definePlugin` receive
|
|
635
|
+
* a plugin-specific context (with the correct `addGenerator` closure).
|
|
636
|
+
* External tooling can observe this event via `hooks.on('kubb:plugin:setup', …)`.
|
|
637
|
+
*/
|
|
638
|
+
'kubb:plugin:setup': [ctx: KubbPluginSetupContext];
|
|
639
|
+
/**
|
|
640
|
+
* Fired immediately before the plugin execution loop begins.
|
|
641
|
+
* The adapter has already parsed the source and `inputNode` is available.
|
|
642
|
+
*/
|
|
643
|
+
'kubb:build:start': [ctx: KubbBuildStartContext];
|
|
644
|
+
/**
|
|
645
|
+
* Fired after all files have been written to disk.
|
|
646
|
+
*/
|
|
647
|
+
'kubb:build:end': [ctx: KubbBuildEndContext];
|
|
648
|
+
/**
|
|
649
|
+
* Emitted for each schema node during the AST walk.
|
|
650
|
+
* Generator listeners registered via `addGenerator()` in `kubb:plugin:setup` respond to this event.
|
|
651
|
+
* The `ctx.plugin.name` identifies which plugin is driving the current walk.
|
|
652
|
+
* `ctx.options` carries the per-node resolved options (after exclude/include/override).
|
|
653
|
+
*/
|
|
654
|
+
'kubb:generate:schema': [node: SchemaNode, ctx: GeneratorContext];
|
|
655
|
+
/**
|
|
656
|
+
* Emitted for each operation node during the AST walk.
|
|
657
|
+
* Generator listeners registered via `addGenerator()` in `kubb:plugin:setup` respond to this event.
|
|
658
|
+
* The `ctx.plugin.name` identifies which plugin is driving the current walk.
|
|
659
|
+
* `ctx.options` carries the per-node resolved options (after exclude/include/override).
|
|
660
|
+
*/
|
|
661
|
+
'kubb:generate:operation': [node: OperationNode, ctx: GeneratorContext];
|
|
662
|
+
/**
|
|
663
|
+
* Emitted once after all operations have been walked, with the full collected array.
|
|
664
|
+
* Generator listeners with an `operations()` method respond to this event.
|
|
665
|
+
* The `ctx.plugin.name` identifies which plugin is driving the current walk.
|
|
666
|
+
* `ctx.options` carries the plugin-level resolved options for the batch call.
|
|
667
|
+
*/
|
|
668
|
+
'kubb:generate:operations': [nodes: Array<OperationNode>, ctx: GeneratorContext];
|
|
669
|
+
}
|
|
670
|
+
declare global {
|
|
671
|
+
namespace Kubb {
|
|
672
|
+
interface PluginContext {}
|
|
673
|
+
/**
|
|
674
|
+
* Registry that maps plugin names to their `PluginFactoryOptions`.
|
|
675
|
+
* Augment this interface in each plugin's `types.ts` to enable automatic
|
|
676
|
+
* typing for `getPlugin` and `requirePlugin`.
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* ```ts
|
|
680
|
+
* // packages/plugin-ts/src/types.ts
|
|
681
|
+
* declare global {
|
|
682
|
+
* namespace Kubb {
|
|
683
|
+
* interface PluginRegistry {
|
|
684
|
+
* 'plugin-ts': PluginTs
|
|
685
|
+
* }
|
|
686
|
+
* }
|
|
687
|
+
* }
|
|
688
|
+
* ```
|
|
689
|
+
*/
|
|
690
|
+
interface PluginRegistry {}
|
|
691
|
+
}
|
|
593
692
|
}
|
|
594
693
|
//#endregion
|
|
595
|
-
//#region src/
|
|
694
|
+
//#region src/definePlugin.d.ts
|
|
596
695
|
/**
|
|
597
|
-
*
|
|
696
|
+
* Base hook handlers for all events except `kubb:plugin:setup`.
|
|
697
|
+
* These handlers have identical signatures regardless of the plugin's
|
|
698
|
+
* `PluginFactoryOptions` generic — they are split out so that the
|
|
699
|
+
* interface below only needs to override the one event that depends on
|
|
700
|
+
* the plugin type.
|
|
598
701
|
*/
|
|
599
|
-
type
|
|
702
|
+
type PluginHooksBase = { [K in Exclude<keyof KubbHooks, 'kubb:plugin:setup'>]?: (...args: KubbHooks[K]) => void | Promise<void> };
|
|
703
|
+
/**
|
|
704
|
+
* Plugin hook handlers.
|
|
705
|
+
*
|
|
706
|
+
* `kubb:plugin:setup` is typed with the plugin's own `PluginFactoryOptions` so
|
|
707
|
+
* `ctx.setResolver`, `ctx.setOptions`, `ctx.options` etc. use the correct types.
|
|
708
|
+
*
|
|
709
|
+
* Uses interface + method shorthand for `kubb:plugin:setup`
|
|
710
|
+
* checking, allowing `PluginHooks<PluginTs>` to be assignable to `PluginHooks`.
|
|
711
|
+
*
|
|
712
|
+
* @template TFactory - The plugin's `PluginFactoryOptions` type.
|
|
713
|
+
*/
|
|
714
|
+
interface PluginHooks<TFactory extends PluginFactoryOptions = PluginFactoryOptions> extends PluginHooksBase {
|
|
715
|
+
'kubb:plugin:setup'?(ctx: KubbPluginSetupContext<TFactory>): void | Promise<void>;
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* A hook-style plugin object produced by `definePlugin`.
|
|
719
|
+
* Instead of flat lifecycle methods, it groups all handlers under a `hooks:` property
|
|
720
|
+
* (matching Astro's integration naming convention).
|
|
721
|
+
*
|
|
722
|
+
* @template TFactory - The plugin's `PluginFactoryOptions` type.
|
|
723
|
+
*/
|
|
724
|
+
type HookStylePlugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
600
725
|
/**
|
|
601
|
-
*
|
|
726
|
+
* Unique name for the plugin, following the same naming convention as `createPlugin`.
|
|
602
727
|
*/
|
|
603
|
-
|
|
728
|
+
name: string;
|
|
604
729
|
/**
|
|
605
|
-
*
|
|
730
|
+
* Plugins that must be registered before this plugin executes.
|
|
731
|
+
* An error is thrown at startup when any listed dependency is missing.
|
|
606
732
|
*/
|
|
607
|
-
|
|
733
|
+
dependencies?: Array<string>;
|
|
608
734
|
/**
|
|
609
|
-
*
|
|
610
|
-
*
|
|
611
|
-
* - `silent`: hide non-essential logs
|
|
612
|
-
* - `info`: show general logs (non-plugin-related)
|
|
613
|
-
* - `debug`: include detailed plugin lifecycle logs
|
|
614
|
-
* @default 'silent'
|
|
735
|
+
* The options passed by the user when calling the plugin factory.
|
|
615
736
|
*/
|
|
616
|
-
|
|
737
|
+
options?: TFactory['options'];
|
|
738
|
+
/**
|
|
739
|
+
* Lifecycle event handlers for this plugin.
|
|
740
|
+
* Any event from the global `KubbHooks` map can be subscribed to here.
|
|
741
|
+
*/
|
|
742
|
+
hooks: PluginHooks<TFactory>;
|
|
617
743
|
};
|
|
618
744
|
/**
|
|
619
|
-
*
|
|
620
|
-
*/
|
|
621
|
-
type ConfigInput = PossiblePromise<UserConfig | UserConfig[]> | ((cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>);
|
|
622
|
-
/**
|
|
623
|
-
* Helper for defining a Kubb configuration.
|
|
745
|
+
* Creates a plugin factory using the new hook-style (`hooks:`) API.
|
|
624
746
|
*
|
|
625
|
-
*
|
|
626
|
-
*
|
|
627
|
-
*
|
|
628
|
-
*
|
|
747
|
+
* The returned factory is called with optional options and produces a `HookStylePlugin`
|
|
748
|
+
* that coexists with plugins created via the legacy `createPlugin` API in the same
|
|
749
|
+
* `kubb.config.ts`.
|
|
750
|
+
*
|
|
751
|
+
* Lifecycle handlers are registered on the `PluginDriver`'s `AsyncEventEmitter`, enabling
|
|
752
|
+
* both the plugin's own handlers and external tooling (CLI, devtools) to observe every event.
|
|
629
753
|
*
|
|
630
754
|
* @example
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
755
|
+
* ```ts
|
|
756
|
+
* // With PluginFactoryOptions (recommended for real plugins)
|
|
757
|
+
* export const pluginTs = definePlugin<PluginTs>((options) => ({
|
|
758
|
+
* name: 'plugin-ts',
|
|
759
|
+
* hooks: {
|
|
760
|
+
* 'kubb:plugin:setup'(ctx) {
|
|
761
|
+
* ctx.setResolver(resolverTs) // typed as Partial<ResolverTs>
|
|
762
|
+
* },
|
|
763
|
+
* },
|
|
634
764
|
* }))
|
|
635
|
-
*
|
|
765
|
+
* ```
|
|
636
766
|
*/
|
|
637
|
-
declare function
|
|
638
|
-
declare function defineConfig(config: PossiblePromise<UserConfig | UserConfig[]>): typeof config;
|
|
767
|
+
declare function definePlugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(factory: (options: TFactory['options']) => HookStylePlugin<TFactory>): (options?: TFactory['options']) => HookStylePlugin<TFactory>;
|
|
639
768
|
//#endregion
|
|
640
769
|
//#region src/utils/FunctionParams.d.ts
|
|
641
770
|
type FunctionParamsASTWithoutType = {
|
|
@@ -676,11 +805,11 @@ type FileMetaBase = {
|
|
|
676
805
|
type AddIndexesProps = {
|
|
677
806
|
type: BarrelType | false | undefined;
|
|
678
807
|
/**
|
|
679
|
-
*
|
|
808
|
+
* Absolute output root derived from config `root` and `output.path`.
|
|
680
809
|
*/
|
|
681
810
|
root: string;
|
|
682
811
|
/**
|
|
683
|
-
* Output for plugin
|
|
812
|
+
* Output settings for the plugin.
|
|
684
813
|
*/
|
|
685
814
|
output: {
|
|
686
815
|
path: string;
|
|
@@ -707,80 +836,6 @@ declare function getBarrelFiles(files: Array<FileNode>, {
|
|
|
707
836
|
}: AddIndexesProps): Promise<Array<FileNode>>;
|
|
708
837
|
//#endregion
|
|
709
838
|
//#region src/types.d.ts
|
|
710
|
-
declare global {
|
|
711
|
-
namespace Kubb {
|
|
712
|
-
interface PluginContext {}
|
|
713
|
-
/**
|
|
714
|
-
* Registry that maps plugin names to their `PluginFactoryOptions`.
|
|
715
|
-
* Augment this interface in each plugin's `types.ts` to enable automatic
|
|
716
|
-
* typing for `getPlugin` and `requirePlugin`.
|
|
717
|
-
*
|
|
718
|
-
* @example
|
|
719
|
-
* ```ts
|
|
720
|
-
* // packages/plugin-ts/src/types.ts
|
|
721
|
-
* declare global {
|
|
722
|
-
* namespace Kubb {
|
|
723
|
-
* interface PluginRegistry {
|
|
724
|
-
* 'plugin-ts': PluginTs
|
|
725
|
-
* }
|
|
726
|
-
* }
|
|
727
|
-
* }
|
|
728
|
-
* ```
|
|
729
|
-
*/
|
|
730
|
-
interface PluginRegistry {}
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
/**
|
|
734
|
-
* Config used in `kubb.config.ts`
|
|
735
|
-
*
|
|
736
|
-
* @example
|
|
737
|
-
* import { defineConfig } from '@kubb/core'
|
|
738
|
-
* export default defineConfig({
|
|
739
|
-
* ...
|
|
740
|
-
* })
|
|
741
|
-
*/
|
|
742
|
-
type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter'> & {
|
|
743
|
-
/**
|
|
744
|
-
* The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
|
|
745
|
-
* @default process.cwd()
|
|
746
|
-
*/
|
|
747
|
-
root?: string;
|
|
748
|
-
/**
|
|
749
|
-
* An array of parsers used to convert generated files to strings.
|
|
750
|
-
* Each parser handles specific file extensions (e.g. `.ts`, `.tsx`).
|
|
751
|
-
*
|
|
752
|
-
* A catch-all fallback parser is always appended last for any unhandled extension.
|
|
753
|
-
*
|
|
754
|
-
* When omitted, `parserTsx` from `@kubb/parser-ts` is used automatically as the
|
|
755
|
-
* default (requires `@kubb/parser-ts` to be installed as an optional dependency).
|
|
756
|
-
* @default [parserTsx] — from `@kubb/parser-ts`
|
|
757
|
-
* @example
|
|
758
|
-
* ```ts
|
|
759
|
-
* import { parserTs, tsxParser } from '@kubb/parser-ts'
|
|
760
|
-
* export default defineConfig({
|
|
761
|
-
* parsers: [parserTs, tsxParser],
|
|
762
|
-
* })
|
|
763
|
-
* ```
|
|
764
|
-
*/
|
|
765
|
-
parsers?: Array<Parser>;
|
|
766
|
-
/**
|
|
767
|
-
* Adapter that converts the input file into a `@kubb/ast` `InputNode` — the universal
|
|
768
|
-
* intermediate representation consumed by all Kubb plugins.
|
|
769
|
-
*
|
|
770
|
-
* When omitted, `adapterOas()` from `@kubb/adapter-oas` is used automatically as the
|
|
771
|
-
* default (requires `@kubb/adapter-oas` to be installed as an optional dependency).
|
|
772
|
-
*
|
|
773
|
-
* - Use `@kubb/adapter-oas` for OpenAPI / Swagger (default).
|
|
774
|
-
* - Use `@kubb/adapter-drizzle` or `@kubb/adapter-asyncapi` for other formats.
|
|
775
|
-
*
|
|
776
|
-
* @default adapterOas() — from `@kubb/adapter-oas`
|
|
777
|
-
*/
|
|
778
|
-
adapter?: Adapter;
|
|
779
|
-
/**
|
|
780
|
-
* An array of Kubb plugins used for generation. Each plugin may have additional configurable options (defined within the plugin itself). If a plugin relies on another plugin, an error will occur if the required dependency is missing. Refer to “pre” for more details.
|
|
781
|
-
*/
|
|
782
|
-
plugins?: Array<Omit<UnknownUserPlugin, 'inject'>>;
|
|
783
|
-
};
|
|
784
839
|
type InputPath = {
|
|
785
840
|
/**
|
|
786
841
|
* Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
|
|
@@ -872,6 +927,12 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
|
872
927
|
path: string;
|
|
873
928
|
}) => Array<ImportNode>;
|
|
874
929
|
};
|
|
930
|
+
/**
|
|
931
|
+
* Controls how `index.ts` barrel files are generated.
|
|
932
|
+
* - `'all'` — exports every generated symbol from every file.
|
|
933
|
+
* - `'named'` — exports only explicitly named exports.
|
|
934
|
+
* - `'propagate'` — propagates re-exports from nested barrel files upward.
|
|
935
|
+
*/
|
|
875
936
|
type BarrelType = 'all' | 'named' | 'propagate';
|
|
876
937
|
type DevtoolsOptions = {
|
|
877
938
|
/**
|
|
@@ -930,13 +991,14 @@ type Config<TInput = Input> = {
|
|
|
930
991
|
*/
|
|
931
992
|
adapter: Adapter;
|
|
932
993
|
/**
|
|
933
|
-
*
|
|
994
|
+
* Source file or data to generate code from.
|
|
995
|
+
* Use `input.path` for a file on disk or `input.data` for an inline string or object.
|
|
934
996
|
*/
|
|
935
997
|
input: TInput;
|
|
936
998
|
output: {
|
|
937
999
|
/**
|
|
938
|
-
*
|
|
939
|
-
*
|
|
1000
|
+
* Output directory for generated files.
|
|
1001
|
+
* Accepts an absolute path or a path relative to `root`.
|
|
940
1002
|
*/
|
|
941
1003
|
path: string;
|
|
942
1004
|
/**
|
|
@@ -1009,11 +1071,28 @@ type Config<TInput = Input> = {
|
|
|
1009
1071
|
override?: boolean;
|
|
1010
1072
|
};
|
|
1011
1073
|
/**
|
|
1012
|
-
* An array of Kubb plugins
|
|
1013
|
-
* Each plugin may
|
|
1014
|
-
* If a plugin depends on another
|
|
1074
|
+
* An array of Kubb plugins used for code generation.
|
|
1075
|
+
* Each plugin may declare additional configurable options.
|
|
1076
|
+
* If a plugin depends on another, an error is thrown when the dependency is missing.
|
|
1077
|
+
* Use `dependencies` on the plugin to declare execution order.
|
|
1015
1078
|
*/
|
|
1016
1079
|
plugins: Array<Plugin>;
|
|
1080
|
+
/**
|
|
1081
|
+
* Project-wide renderer factory. All plugins and generators that do not declare their own
|
|
1082
|
+
* `renderer` ultimately fall back to this value.
|
|
1083
|
+
*
|
|
1084
|
+
* The resolution chain is: `generator.renderer` → `plugin.renderer` → `config.renderer` → `undefined` (raw `FileNode[]` mode).
|
|
1085
|
+
*
|
|
1086
|
+
* @example
|
|
1087
|
+
* ```ts
|
|
1088
|
+
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
1089
|
+
* export default defineConfig({
|
|
1090
|
+
* renderer: jsxRenderer,
|
|
1091
|
+
* plugins: [pluginTs(), pluginZod()],
|
|
1092
|
+
* })
|
|
1093
|
+
* ```
|
|
1094
|
+
*/
|
|
1095
|
+
renderer?: RendererFactory;
|
|
1017
1096
|
/**
|
|
1018
1097
|
* Devtools configuration for Kubb Studio integration.
|
|
1019
1098
|
*/
|
|
@@ -1083,21 +1162,6 @@ type Resolver = {
|
|
|
1083
1162
|
resolveBanner(node: InputNode | null, context: ResolveBannerContext): string | undefined;
|
|
1084
1163
|
resolveFooter(node: InputNode | null, context: ResolveBannerContext): string | undefined;
|
|
1085
1164
|
};
|
|
1086
|
-
/**
|
|
1087
|
-
* The user-facing subset of a `Resolver` — everything except the four methods injected by
|
|
1088
|
-
* `defineResolver` (`default`, `resolveOptions`, `resolvePath`, and `resolveFile`).
|
|
1089
|
-
*
|
|
1090
|
-
* All four injected methods can still be overridden by providing them explicitly in the builder.
|
|
1091
|
-
*
|
|
1092
|
-
* @example
|
|
1093
|
-
* ```ts
|
|
1094
|
-
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
1095
|
-
* name: 'default',
|
|
1096
|
-
* resolveName(node) { return this.default(node.name, 'function') },
|
|
1097
|
-
* }))
|
|
1098
|
-
* ```
|
|
1099
|
-
*/
|
|
1100
|
-
type UserResolver = Omit<Resolver, 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>;
|
|
1101
1165
|
type PluginFactoryOptions<
|
|
1102
1166
|
/**
|
|
1103
1167
|
* Name to be used for the plugin.
|
|
@@ -1131,42 +1195,66 @@ TResolver extends Resolver = Resolver> = {
|
|
|
1131
1195
|
resolvePathOptions: TResolvePathOptions;
|
|
1132
1196
|
resolver: TResolver;
|
|
1133
1197
|
};
|
|
1198
|
+
/**
|
|
1199
|
+
* @deprecated
|
|
1200
|
+
*/
|
|
1134
1201
|
type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1135
1202
|
/**
|
|
1136
|
-
* Unique name used for the plugin
|
|
1137
|
-
* The name
|
|
1138
|
-
*
|
|
1203
|
+
* Unique name used for the plugin.
|
|
1204
|
+
* The name follows the format `scope:foo-bar` or `foo-bar` — adding a scope avoids conflicts with other plugins.
|
|
1205
|
+
*
|
|
1206
|
+
* @example Plugin name
|
|
1207
|
+
* `'@kubb/typescript'`
|
|
1139
1208
|
*/
|
|
1140
1209
|
name: TOptions['name'];
|
|
1141
1210
|
/**
|
|
1142
|
-
*
|
|
1211
|
+
* Resolved options merged with output/include/exclude/override defaults for the current plugin.
|
|
1143
1212
|
*/
|
|
1144
1213
|
options: TOptions['resolvedOptions'] & {
|
|
1145
1214
|
output: Output;
|
|
1146
1215
|
include?: Array<Include>;
|
|
1147
|
-
exclude: Array<Exclude>;
|
|
1216
|
+
exclude: Array<Exclude$1>;
|
|
1148
1217
|
override: Array<Override<TOptions['resolvedOptions']>>;
|
|
1149
1218
|
};
|
|
1150
1219
|
/**
|
|
1151
1220
|
* The resolver for this plugin.
|
|
1152
|
-
*
|
|
1221
|
+
* Set via `setResolver()` in `kubb:plugin:setup` or passed as a user option.
|
|
1153
1222
|
*/
|
|
1154
1223
|
resolver?: TOptions['resolver'];
|
|
1155
1224
|
/**
|
|
1156
1225
|
* The composed transformer for this plugin.
|
|
1157
|
-
*
|
|
1158
|
-
* When a visitor method returns `null`/`undefined`, the preset transformer's result is used instead.
|
|
1226
|
+
* Set via `setTransformer()` in `kubb:plugin:setup` or passed as a user option.
|
|
1159
1227
|
*/
|
|
1160
1228
|
transformer?: Visitor;
|
|
1161
1229
|
/**
|
|
1162
|
-
*
|
|
1163
|
-
*
|
|
1230
|
+
* Plugin-level renderer factory. All generators that do not declare their own `renderer`
|
|
1231
|
+
* inherit this value. A generator can explicitly opt out by setting `renderer: null`.
|
|
1232
|
+
*
|
|
1233
|
+
* @example
|
|
1234
|
+
* ```ts
|
|
1235
|
+
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
1236
|
+
* createPlugin((options) => ({
|
|
1237
|
+
* name: 'my-plugin',
|
|
1238
|
+
* renderer: jsxRenderer,
|
|
1239
|
+
* generators: [
|
|
1240
|
+
* { name: 'types', schema(node) { return <File>...</File> } }, // inherits jsxRenderer
|
|
1241
|
+
* { name: 'raw', renderer: null, schema(node) { return [...] } }, // explicit opt-out
|
|
1242
|
+
* ],
|
|
1243
|
+
* }))
|
|
1244
|
+
* ```
|
|
1164
1245
|
*/
|
|
1165
|
-
|
|
1246
|
+
renderer?: RendererFactory;
|
|
1166
1247
|
/**
|
|
1167
|
-
*
|
|
1248
|
+
* Generators declared directly on the plugin. Each generator's `renderer` takes precedence
|
|
1249
|
+
* over `plugin.renderer`; set `renderer: null` on a generator to opt out of rendering even
|
|
1250
|
+
* when the plugin declares a renderer.
|
|
1168
1251
|
*/
|
|
1169
|
-
|
|
1252
|
+
generators?: Array<Generator<any>>;
|
|
1253
|
+
/**
|
|
1254
|
+
* Specifies the plugins that the current plugin depends on. The current plugin is executed after all listed plugins.
|
|
1255
|
+
* An error is returned if any required dependency plugin is missing.
|
|
1256
|
+
*/
|
|
1257
|
+
dependencies?: Array<string>;
|
|
1170
1258
|
/**
|
|
1171
1259
|
* When `apply` is defined, the plugin is only activated when `apply(config)` returns `true`.
|
|
1172
1260
|
* Inspired by Vite's `apply` option.
|
|
@@ -1193,53 +1281,55 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
1193
1281
|
*/
|
|
1194
1282
|
inject?: (this: PluginContext<TOptions>) => TOptions['context'];
|
|
1195
1283
|
};
|
|
1284
|
+
/**
|
|
1285
|
+
* @deprecated
|
|
1286
|
+
*/
|
|
1196
1287
|
type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
1197
|
-
type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<string, object, object, unknown, object>>;
|
|
1198
1288
|
/**
|
|
1199
1289
|
* Handler for a single schema node. Used by the `schema` hook on a plugin.
|
|
1200
1290
|
*/
|
|
1201
|
-
type SchemaHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<
|
|
1291
|
+
type SchemaHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: SchemaNode, options: TOptions['resolvedOptions']) => PossiblePromise<unknown | Array<FileNode> | void>;
|
|
1202
1292
|
/**
|
|
1203
1293
|
* Handler for a single operation node. Used by the `operation` hook on a plugin.
|
|
1204
1294
|
*/
|
|
1205
|
-
type OperationHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<
|
|
1295
|
+
type OperationHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, node: OperationNode, options: TOptions['resolvedOptions']) => PossiblePromise<unknown | Array<FileNode> | void>;
|
|
1206
1296
|
/**
|
|
1207
1297
|
* Handler for all collected operation nodes. Used by the `operations` hook on a plugin.
|
|
1208
1298
|
*/
|
|
1209
|
-
type OperationsHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<
|
|
1299
|
+
type OperationsHook<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = (this: GeneratorContext<TOptions>, nodes: Array<OperationNode>, options: TOptions['resolvedOptions']) => PossiblePromise<unknown | Array<FileNode> | void>;
|
|
1300
|
+
/**
|
|
1301
|
+
* @deprecated will be replaced with HookStylePlugin
|
|
1302
|
+
*/
|
|
1210
1303
|
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1211
1304
|
/**
|
|
1212
|
-
* Unique name used for the plugin
|
|
1213
|
-
*
|
|
1305
|
+
* Unique name used for the plugin.
|
|
1306
|
+
*
|
|
1307
|
+
* @example Plugin name
|
|
1308
|
+
* `'@kubb/typescript'`
|
|
1214
1309
|
*/
|
|
1215
1310
|
name: TOptions['name'];
|
|
1216
1311
|
/**
|
|
1217
|
-
* Specifies the
|
|
1218
|
-
*
|
|
1219
|
-
*/
|
|
1220
|
-
pre?: Array<string>;
|
|
1221
|
-
/**
|
|
1222
|
-
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins.
|
|
1312
|
+
* Specifies the plugins that the current plugin depends on. The current plugin is executed after all listed plugins.
|
|
1313
|
+
* An error is returned if any required dependency plugin is missing.
|
|
1223
1314
|
*/
|
|
1224
|
-
|
|
1315
|
+
dependencies?: Array<string>;
|
|
1225
1316
|
/**
|
|
1226
1317
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
1227
1318
|
*/
|
|
1228
1319
|
options: TOptions['resolvedOptions'] & {
|
|
1229
1320
|
output: Output;
|
|
1230
1321
|
include?: Array<Include>;
|
|
1231
|
-
exclude: Array<Exclude>;
|
|
1322
|
+
exclude: Array<Exclude$1>;
|
|
1232
1323
|
override: Array<Override<TOptions['resolvedOptions']>>;
|
|
1233
1324
|
};
|
|
1234
1325
|
/**
|
|
1235
1326
|
* The resolver for this plugin.
|
|
1236
|
-
*
|
|
1327
|
+
* Set via `setResolver()` in `kubb:plugin:setup` or passed as a user option.
|
|
1237
1328
|
*/
|
|
1238
1329
|
resolver: TOptions['resolver'];
|
|
1239
1330
|
/**
|
|
1240
|
-
* The composed transformer for this plugin.
|
|
1241
|
-
*
|
|
1242
|
-
* When a visitor method returns `null`/`undefined`, the preset transformer's result is used instead.
|
|
1331
|
+
* The composed transformer for this plugin.
|
|
1332
|
+
* Set via `setTransformer()` in `kubb:plugin:setup` or passed as a user option.
|
|
1243
1333
|
*/
|
|
1244
1334
|
transformer?: Visitor;
|
|
1245
1335
|
/**
|
|
@@ -1252,6 +1342,17 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
1252
1342
|
* Used in diagnostic messages and version-conflict detection.
|
|
1253
1343
|
*/
|
|
1254
1344
|
version?: string;
|
|
1345
|
+
/**
|
|
1346
|
+
* Plugin-level renderer factory. All generators that do not declare their own `renderer`
|
|
1347
|
+
* inherit this value. A generator can explicitly opt out by setting `renderer: null`.
|
|
1348
|
+
*/
|
|
1349
|
+
renderer?: RendererFactory;
|
|
1350
|
+
/**
|
|
1351
|
+
* Generators declared directly on the plugin. Each generator's `renderer` takes precedence
|
|
1352
|
+
* over `plugin.renderer`; set `renderer: null` on a generator to opt out of rendering even
|
|
1353
|
+
* when the plugin declares a renderer.
|
|
1354
|
+
*/
|
|
1355
|
+
generators?: Array<Generator<any>>;
|
|
1255
1356
|
buildStart: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1256
1357
|
/**
|
|
1257
1358
|
* Called once per plugin after all files have been written to disk.
|
|
@@ -1285,18 +1386,22 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
1285
1386
|
*/
|
|
1286
1387
|
inject: (this: PluginContext<TOptions>) => TOptions['context'];
|
|
1287
1388
|
};
|
|
1389
|
+
/**
|
|
1390
|
+
* @deprecated
|
|
1391
|
+
*/
|
|
1288
1392
|
type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
|
|
1393
|
+
/**
|
|
1394
|
+
* @deprecated
|
|
1395
|
+
*/
|
|
1289
1396
|
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1290
1397
|
/**
|
|
1291
1398
|
* Called once per plugin at the start of its processing phase, before schema/operation/operations hooks run.
|
|
1292
1399
|
* Use this to set up shared state, fetch remote data, or perform any async initialization.
|
|
1293
|
-
* @type hookParallel
|
|
1294
1400
|
*/
|
|
1295
1401
|
buildStart?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1296
1402
|
/**
|
|
1297
1403
|
* Called once per plugin after all files have been written to disk.
|
|
1298
1404
|
* Use this for post-processing, copying assets, or generating summary reports.
|
|
1299
|
-
* @type hookParallel
|
|
1300
1405
|
*/
|
|
1301
1406
|
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1302
1407
|
/**
|
|
@@ -1324,22 +1429,29 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
1324
1429
|
*/
|
|
1325
1430
|
operations?: OperationsHook<TOptions>;
|
|
1326
1431
|
/**
|
|
1327
|
-
*
|
|
1328
|
-
* Options can
|
|
1329
|
-
*
|
|
1330
|
-
* @example
|
|
1331
|
-
*
|
|
1432
|
+
* Resolves a path from a baseName and directory.
|
|
1433
|
+
* Options can also be included.
|
|
1434
|
+
*
|
|
1435
|
+
* @example
|
|
1436
|
+
* `('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'`
|
|
1437
|
+
*
|
|
1438
|
+
* @deprecated Use resolvers instead.
|
|
1332
1439
|
*/
|
|
1333
1440
|
resolvePath?: (this: PluginContext<TOptions>, baseName: FileNode['baseName'], mode?: 'single' | 'split', options?: TOptions['resolvePathOptions']) => string;
|
|
1334
1441
|
/**
|
|
1335
|
-
*
|
|
1442
|
+
* Resolves a display name from a raw string.
|
|
1336
1443
|
* Useful when converting to PascalCase or camelCase.
|
|
1337
|
-
*
|
|
1338
|
-
* @example
|
|
1339
|
-
*
|
|
1444
|
+
*
|
|
1445
|
+
* @example
|
|
1446
|
+
* `('pet') => 'Pet'`
|
|
1447
|
+
*
|
|
1448
|
+
* @deprecated Use resolvers instead.
|
|
1340
1449
|
*/
|
|
1341
1450
|
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
1342
1451
|
};
|
|
1452
|
+
/**
|
|
1453
|
+
* @deprecated
|
|
1454
|
+
*/
|
|
1343
1455
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
1344
1456
|
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
1345
1457
|
type ResolvePathParams<TOptions = object> = {
|
|
@@ -1347,7 +1459,7 @@ type ResolvePathParams<TOptions = object> = {
|
|
|
1347
1459
|
baseName: FileNode['baseName'];
|
|
1348
1460
|
mode?: 'single' | 'split';
|
|
1349
1461
|
/**
|
|
1350
|
-
* Options
|
|
1462
|
+
* Options passed as the third argument to `resolvePath`.
|
|
1351
1463
|
*/
|
|
1352
1464
|
options?: TOptions;
|
|
1353
1465
|
};
|
|
@@ -1356,14 +1468,16 @@ type ResolveNameParams = {
|
|
|
1356
1468
|
pluginName?: string;
|
|
1357
1469
|
/**
|
|
1358
1470
|
* Specifies the type of entity being named.
|
|
1359
|
-
* - 'file' customizes the name of the created file (
|
|
1360
|
-
* - 'function' customizes the exported function names (
|
|
1361
|
-
* - 'type' customizes TypeScript
|
|
1362
|
-
* - 'const' customizes variable names (
|
|
1363
|
-
* @default undefined
|
|
1471
|
+
* - `'file'` — customizes the name of the created file (camelCase).
|
|
1472
|
+
* - `'function'` — customizes the exported function names (camelCase).
|
|
1473
|
+
* - `'type'` — customizes TypeScript type names (PascalCase).
|
|
1474
|
+
* - `'const'` — customizes variable names (camelCase).
|
|
1364
1475
|
*/
|
|
1365
1476
|
type?: 'file' | 'function' | 'type' | 'const';
|
|
1366
1477
|
};
|
|
1478
|
+
/**
|
|
1479
|
+
* @deprecated
|
|
1480
|
+
*/
|
|
1367
1481
|
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1368
1482
|
config: Config;
|
|
1369
1483
|
/**
|
|
@@ -1393,19 +1507,16 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1393
1507
|
requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>;
|
|
1394
1508
|
requirePlugin(name: string): Plugin;
|
|
1395
1509
|
/**
|
|
1396
|
-
*
|
|
1510
|
+
* Add files only when they do not exist yet.
|
|
1397
1511
|
*/
|
|
1398
1512
|
addFile: (...file: Array<FileNode>) => Promise<void>;
|
|
1399
1513
|
/**
|
|
1400
|
-
*
|
|
1514
|
+
* Merge multiple sources into the same output file.
|
|
1401
1515
|
*/
|
|
1402
1516
|
upsertFile: (...file: Array<FileNode>) => Promise<void>;
|
|
1517
|
+
hooks: AsyncEventEmitter<KubbHooks>;
|
|
1403
1518
|
/**
|
|
1404
|
-
*
|
|
1405
|
-
*/
|
|
1406
|
-
events: AsyncEventEmitter<KubbEvents>;
|
|
1407
|
-
/**
|
|
1408
|
-
* Current plugin
|
|
1519
|
+
* The current plugin.
|
|
1409
1520
|
*/
|
|
1410
1521
|
plugin: Plugin<TOptions>;
|
|
1411
1522
|
/**
|
|
@@ -1419,17 +1530,17 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1419
1530
|
transformer: Visitor | undefined;
|
|
1420
1531
|
/**
|
|
1421
1532
|
* Emit a warning via the build event system.
|
|
1422
|
-
* Shorthand for `this.
|
|
1533
|
+
* Shorthand for `this.hooks.emit('kubb:warn', message)`.
|
|
1423
1534
|
*/
|
|
1424
1535
|
warn: (message: string) => void;
|
|
1425
1536
|
/**
|
|
1426
1537
|
* Emit an error via the build event system.
|
|
1427
|
-
* Shorthand for `this.
|
|
1538
|
+
* Shorthand for `this.hooks.emit('kubb:error', error)`.
|
|
1428
1539
|
*/
|
|
1429
1540
|
error: (error: string | Error) => void;
|
|
1430
1541
|
/**
|
|
1431
1542
|
* Emit an info message via the build event system.
|
|
1432
|
-
* Shorthand for `this.
|
|
1543
|
+
* Shorthand for `this.hooks.emit('kubb:info', message)`.
|
|
1433
1544
|
*/
|
|
1434
1545
|
info: (message: string) => void;
|
|
1435
1546
|
/**
|
|
@@ -1445,7 +1556,7 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1445
1556
|
*/
|
|
1446
1557
|
inputNode: InputNode;
|
|
1447
1558
|
/**
|
|
1448
|
-
*
|
|
1559
|
+
* The adapter from `@kubb/ast`.
|
|
1449
1560
|
*/
|
|
1450
1561
|
adapter: Adapter;
|
|
1451
1562
|
} | {
|
|
@@ -1453,23 +1564,27 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1453
1564
|
adapter?: never;
|
|
1454
1565
|
}) & Kubb.PluginContext;
|
|
1455
1566
|
/**
|
|
1456
|
-
*
|
|
1567
|
+
* Context object passed as the second argument to generator `schema`, `operation`, and
|
|
1568
|
+
* `operations` methods.
|
|
1569
|
+
*
|
|
1570
|
+
* Generators are only invoked from `runPluginAstHooks`, which already guards against a
|
|
1571
|
+
* missing adapter. This type reflects that guarantee — `ctx.adapter` and `ctx.inputNode`
|
|
1572
|
+
* are always defined, so no runtime checks or casts are needed inside generator bodies.
|
|
1457
1573
|
*
|
|
1458
|
-
*
|
|
1459
|
-
*
|
|
1460
|
-
* that guarantee — `this.adapter` and `this.inputNode` are always defined, so no runtime
|
|
1461
|
-
* checks or casts are needed inside the method bodies.
|
|
1574
|
+
* `ctx.options` carries the per-node resolved options for `schema`/`operation` calls
|
|
1575
|
+
* (after exclude/include/override filtering) and the plugin-level options for `operations`.
|
|
1462
1576
|
*/
|
|
1463
1577
|
type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Omit<PluginContext<TOptions>, 'adapter' | 'inputNode'> & {
|
|
1464
1578
|
adapter: Adapter;
|
|
1465
1579
|
inputNode: InputNode;
|
|
1580
|
+
options: TOptions['resolvedOptions'];
|
|
1466
1581
|
};
|
|
1467
1582
|
/**
|
|
1468
|
-
*
|
|
1583
|
+
* Configure generated file output location and behavior.
|
|
1469
1584
|
*/
|
|
1470
1585
|
type Output<_TOptions = unknown> = {
|
|
1471
1586
|
/**
|
|
1472
|
-
* Path to the output folder or file that will contain
|
|
1587
|
+
* Path to the output folder or file that will contain generated code.
|
|
1473
1588
|
*/
|
|
1474
1589
|
path: string;
|
|
1475
1590
|
/**
|
|
@@ -1478,11 +1593,13 @@ type Output<_TOptions = unknown> = {
|
|
|
1478
1593
|
*/
|
|
1479
1594
|
barrelType?: BarrelType | false;
|
|
1480
1595
|
/**
|
|
1481
|
-
*
|
|
1596
|
+
* Text or function appended at the start of every generated file.
|
|
1597
|
+
* When a function, receives the current `InputNode` and must return a string.
|
|
1482
1598
|
*/
|
|
1483
1599
|
banner?: string | ((node?: InputNode) => string);
|
|
1484
1600
|
/**
|
|
1485
|
-
*
|
|
1601
|
+
* Text or function appended at the end of every generated file.
|
|
1602
|
+
* When a function, receives the current `InputNode` and must return a string.
|
|
1486
1603
|
*/
|
|
1487
1604
|
footer?: string | ((node?: InputNode) => string);
|
|
1488
1605
|
/**
|
|
@@ -1493,14 +1610,14 @@ type Output<_TOptions = unknown> = {
|
|
|
1493
1610
|
};
|
|
1494
1611
|
type UserGroup = {
|
|
1495
1612
|
/**
|
|
1496
|
-
*
|
|
1497
|
-
* - 'tag' groups files by OpenAPI tags.
|
|
1498
|
-
* - 'path' groups files by OpenAPI paths.
|
|
1499
|
-
* @default undefined
|
|
1613
|
+
* Determines how files are grouped into subdirectories.
|
|
1614
|
+
* - `'tag'` groups files by OpenAPI tags.
|
|
1615
|
+
* - `'path'` groups files by OpenAPI paths.
|
|
1500
1616
|
*/
|
|
1501
1617
|
type: 'tag' | 'path';
|
|
1502
1618
|
/**
|
|
1503
|
-
*
|
|
1619
|
+
* Returns the subdirectory name for a given group value.
|
|
1620
|
+
* Defaults to `${camelCase(group)}Controller` for tags and the first path segment for paths.
|
|
1504
1621
|
*/
|
|
1505
1622
|
name?: (context: {
|
|
1506
1623
|
group: string;
|
|
@@ -1508,14 +1625,13 @@ type UserGroup = {
|
|
|
1508
1625
|
};
|
|
1509
1626
|
type Group = {
|
|
1510
1627
|
/**
|
|
1511
|
-
*
|
|
1512
|
-
* - 'tag' groups files by OpenAPI tags.
|
|
1513
|
-
* - 'path' groups files by OpenAPI paths.
|
|
1514
|
-
* @default undefined
|
|
1628
|
+
* Determines how files are grouped into subdirectories.
|
|
1629
|
+
* - `'tag'` groups files by OpenAPI tags.
|
|
1630
|
+
* - `'path'` groups files by OpenAPI paths.
|
|
1515
1631
|
*/
|
|
1516
1632
|
type: 'tag' | 'path';
|
|
1517
1633
|
/**
|
|
1518
|
-
*
|
|
1634
|
+
* Returns the subdirectory name for a given group value.
|
|
1519
1635
|
*/
|
|
1520
1636
|
name: (context: {
|
|
1521
1637
|
group: string;
|
|
@@ -1530,7 +1646,7 @@ type LoggerOptions = {
|
|
|
1530
1646
|
/**
|
|
1531
1647
|
* Shared context passed to all plugins, parsers, and other internals.
|
|
1532
1648
|
*/
|
|
1533
|
-
type LoggerContext = AsyncEventEmitter<
|
|
1649
|
+
type LoggerContext = AsyncEventEmitter<KubbHooks>;
|
|
1534
1650
|
type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
|
|
1535
1651
|
name: string;
|
|
1536
1652
|
install: (context: LoggerContext, options?: TOptions) => void | Promise<void>;
|
|
@@ -1543,42 +1659,80 @@ type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Logger<TOption
|
|
|
1543
1659
|
*/
|
|
1544
1660
|
type CompatibilityPreset = 'default' | 'kubbV4';
|
|
1545
1661
|
/**
|
|
1546
|
-
*
|
|
1547
|
-
*
|
|
1548
|
-
*
|
|
1549
|
-
* @template TResolver - The concrete resolver type for this preset.
|
|
1662
|
+
* Context passed to a hook-style plugin's `kubb:plugin:setup` handler.
|
|
1663
|
+
* Provides methods to register generators, configure the resolver, transformer,
|
|
1664
|
+
* and renderer, as well as access to the current build configuration.
|
|
1550
1665
|
*/
|
|
1551
|
-
type
|
|
1666
|
+
type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
1552
1667
|
/**
|
|
1553
|
-
*
|
|
1668
|
+
* Register a generator on this plugin. Generators are invoked during the AST walk
|
|
1669
|
+
* (schema/operation/operations) exactly like generators declared statically on `createPlugin`.
|
|
1554
1670
|
*/
|
|
1555
|
-
|
|
1671
|
+
addGenerator<TElement = unknown>(generator: Generator<TFactory, TElement>): void;
|
|
1556
1672
|
/**
|
|
1557
|
-
*
|
|
1673
|
+
* Set or partially override the resolver for this plugin.
|
|
1674
|
+
* The resolver controls file naming and path resolution for generated files.
|
|
1675
|
+
*
|
|
1676
|
+
* When `TFactory` is a concrete `PluginFactoryOptions` (e.g. `PluginClient`),
|
|
1677
|
+
* the resolver parameter is typed to the plugin's own resolver type (e.g. `ResolverClient`).
|
|
1558
1678
|
*/
|
|
1559
|
-
resolver:
|
|
1679
|
+
setResolver(resolver: Partial<TFactory['resolver']>): void;
|
|
1560
1680
|
/**
|
|
1561
|
-
*
|
|
1681
|
+
* Set the AST transformer (visitor) for this plugin.
|
|
1682
|
+
* The transformer pre-processes nodes before they reach the generators.
|
|
1562
1683
|
*/
|
|
1563
|
-
|
|
1684
|
+
setTransformer(visitor: Visitor): void;
|
|
1564
1685
|
/**
|
|
1565
|
-
*
|
|
1566
|
-
* to
|
|
1686
|
+
* Set the renderer factory for this plugin.
|
|
1687
|
+
* Used to process JSX elements returned by generators.
|
|
1567
1688
|
*/
|
|
1568
|
-
|
|
1689
|
+
setRenderer(renderer: RendererFactory): void;
|
|
1690
|
+
/**
|
|
1691
|
+
* Set the resolved options for the build loop. These options are merged into the
|
|
1692
|
+
* normalized plugin's `options` object (which includes `output`, `exclude`, `override`).
|
|
1693
|
+
*
|
|
1694
|
+
* Call this in `kubb:plugin:setup` to provide the resolved options that generators
|
|
1695
|
+
* and the build loop need (e.g., `enumType`, `optionalType`, `group`).
|
|
1696
|
+
*/
|
|
1697
|
+
setOptions(options: TFactory['resolvedOptions']): void;
|
|
1698
|
+
/**
|
|
1699
|
+
* Inject a raw file into the build output, bypassing the normal generation pipeline.
|
|
1700
|
+
*/
|
|
1701
|
+
injectFile(file: Pick<FileNode, 'baseName' | 'path'> & {
|
|
1702
|
+
sources?: FileNode['sources'];
|
|
1703
|
+
}): void;
|
|
1704
|
+
/**
|
|
1705
|
+
* Merge a partial config update into the current build configuration.
|
|
1706
|
+
*/
|
|
1707
|
+
updateConfig(config: Partial<Config>): void;
|
|
1708
|
+
/**
|
|
1709
|
+
* The resolved build configuration at the time of setup.
|
|
1710
|
+
*/
|
|
1711
|
+
config: Config;
|
|
1569
1712
|
/**
|
|
1570
|
-
*
|
|
1571
|
-
* The generator calls this function at render-time to produce a configured printer instance.
|
|
1713
|
+
* The plugin's own options as passed by the user.
|
|
1572
1714
|
*/
|
|
1573
|
-
|
|
1715
|
+
options: TFactory['options'];
|
|
1574
1716
|
};
|
|
1575
1717
|
/**
|
|
1576
|
-
*
|
|
1577
|
-
*
|
|
1578
|
-
* @template TResolver - The concrete resolver type shared by all presets in this registry.
|
|
1579
|
-
* @template TName - The union of valid preset name keys.
|
|
1718
|
+
* Context passed to a hook-style plugin's `kubb:build:start` handler.
|
|
1719
|
+
* Fires immediately before the plugin execution loop begins.
|
|
1580
1720
|
*/
|
|
1581
|
-
type
|
|
1721
|
+
type KubbBuildStartContext = {
|
|
1722
|
+
config: Config;
|
|
1723
|
+
adapter: Adapter;
|
|
1724
|
+
inputNode: InputNode;
|
|
1725
|
+
getPlugin(name: string): Plugin | undefined;
|
|
1726
|
+
};
|
|
1727
|
+
/**
|
|
1728
|
+
* Context passed to a hook-style plugin's `kubb:build:end` handler.
|
|
1729
|
+
* Fires after all files have been written to disk.
|
|
1730
|
+
*/
|
|
1731
|
+
type KubbBuildEndContext = {
|
|
1732
|
+
files: Array<FileNode>;
|
|
1733
|
+
config: Config;
|
|
1734
|
+
outputDir: string;
|
|
1735
|
+
};
|
|
1582
1736
|
type ByTag = {
|
|
1583
1737
|
type: 'tag';
|
|
1584
1738
|
pattern: string | RegExp;
|
|
@@ -1603,8 +1757,20 @@ type ByContentType = {
|
|
|
1603
1757
|
type: 'contentType';
|
|
1604
1758
|
pattern: string | RegExp;
|
|
1605
1759
|
};
|
|
1606
|
-
|
|
1760
|
+
/**
|
|
1761
|
+
* A pattern filter that prevents matching nodes from being generated.
|
|
1762
|
+
* Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
|
|
1763
|
+
*/
|
|
1764
|
+
type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
|
|
1765
|
+
/**
|
|
1766
|
+
* A pattern filter that restricts generation to only matching nodes.
|
|
1767
|
+
* Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
|
|
1768
|
+
*/
|
|
1607
1769
|
type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
|
|
1770
|
+
/**
|
|
1771
|
+
* A pattern filter paired with partial option overrides applied when the pattern matches.
|
|
1772
|
+
* Match by `tag`, `operationId`, `path`, `method`, `schemaName`, or `contentType`.
|
|
1773
|
+
*/
|
|
1608
1774
|
type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
1609
1775
|
options: Partial<TOptions>;
|
|
1610
1776
|
};
|
|
@@ -1710,6 +1876,160 @@ type ResolveBannerContext = {
|
|
|
1710
1876
|
output?: Pick<Output, 'banner' | 'footer'>;
|
|
1711
1877
|
config: Config;
|
|
1712
1878
|
};
|
|
1879
|
+
/**
|
|
1880
|
+
* CLI options derived from command-line flags.
|
|
1881
|
+
*/
|
|
1882
|
+
type CLIOptions = {
|
|
1883
|
+
/**
|
|
1884
|
+
* Path to `kubb.config.js`.
|
|
1885
|
+
*/
|
|
1886
|
+
config?: string;
|
|
1887
|
+
/**
|
|
1888
|
+
* Enable watch mode for input files.
|
|
1889
|
+
*/
|
|
1890
|
+
watch?: boolean;
|
|
1891
|
+
/**
|
|
1892
|
+
* Logging verbosity for CLI usage.
|
|
1893
|
+
* @default 'silent'
|
|
1894
|
+
*/
|
|
1895
|
+
logLevel?: 'silent' | 'info' | 'debug';
|
|
1896
|
+
};
|
|
1897
|
+
/**
|
|
1898
|
+
* All accepted forms of a Kubb configuration.
|
|
1899
|
+
*
|
|
1900
|
+
* Config is always `@kubb/core` {@link Config}.
|
|
1901
|
+
* - `PossibleConfig` accepts `Config`/`Config[]`/promise or a no-arg config factory.
|
|
1902
|
+
* - `PossibleConfig<TCliOptions>` accepts the same config forms or a config factory receiving `TCliOptions`.
|
|
1903
|
+
*/
|
|
1904
|
+
type PossibleConfig<TCliOptions = undefined> = PossiblePromise<Config | Config[]> | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Config[]>);
|
|
1905
|
+
/**
|
|
1906
|
+
* All accepted forms of a Kubb configuration.
|
|
1907
|
+
* @deprecated
|
|
1908
|
+
* Kept for backward compatibility. Prefer `PossibleConfig<CLIOptions>` in new code.
|
|
1909
|
+
*/
|
|
1910
|
+
type ConfigInput = PossibleConfig<CLIOptions>;
|
|
1911
|
+
//#endregion
|
|
1912
|
+
//#region src/defineGenerator.d.ts
|
|
1913
|
+
/**
|
|
1914
|
+
* A generator is a named object with optional `schema`, `operation`, and `operations`
|
|
1915
|
+
* methods. Each method receives the AST node as the first argument and a typed
|
|
1916
|
+
* `ctx` object as the second, giving access to `ctx.config`, `ctx.resolver`,
|
|
1917
|
+
* `ctx.adapter`, `ctx.options`, `ctx.upsertFile`, etc.
|
|
1918
|
+
*
|
|
1919
|
+
* Generators that return renderer elements (e.g. JSX) must declare a `renderer`
|
|
1920
|
+
* factory so that core knows how to process the output without coupling core
|
|
1921
|
+
* to any specific renderer package.
|
|
1922
|
+
*
|
|
1923
|
+
* Return a renderer element, an array of `FileNode`, or `void` to handle file
|
|
1924
|
+
* writing manually via `ctx.upsertFile`.
|
|
1925
|
+
*
|
|
1926
|
+
* @example
|
|
1927
|
+
* ```ts
|
|
1928
|
+
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
1929
|
+
*
|
|
1930
|
+
* export const typeGenerator = defineGenerator<PluginTs>({
|
|
1931
|
+
* name: 'typescript',
|
|
1932
|
+
* renderer: jsxRenderer,
|
|
1933
|
+
* schema(node, ctx) {
|
|
1934
|
+
* const { adapter, resolver, root, options } = ctx
|
|
1935
|
+
* return <File ...><Type node={node} resolver={resolver} /></File>
|
|
1936
|
+
* },
|
|
1937
|
+
* operation(node, ctx) {
|
|
1938
|
+
* const { options } = ctx
|
|
1939
|
+
* return <File ...><OperationType node={node} /></File>
|
|
1940
|
+
* },
|
|
1941
|
+
* })
|
|
1942
|
+
* ```
|
|
1943
|
+
*/
|
|
1944
|
+
type Generator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown> = {
|
|
1945
|
+
/**
|
|
1946
|
+
* Used in diagnostic messages and debug output.
|
|
1947
|
+
*/
|
|
1948
|
+
name: string;
|
|
1949
|
+
/**
|
|
1950
|
+
* Optional renderer factory that produces a {@link Renderer} for each render cycle.
|
|
1951
|
+
*
|
|
1952
|
+
* Generators that return renderer elements (e.g. JSX via `@kubb/renderer-jsx`) must set this
|
|
1953
|
+
* to the matching renderer factory (e.g. `jsxRenderer` from `@kubb/renderer-jsx`).
|
|
1954
|
+
*
|
|
1955
|
+
* Generators that only return `Array<FileNode>` or `void` do not need to set this.
|
|
1956
|
+
*
|
|
1957
|
+
* Set `renderer: null` to explicitly opt out of rendering even when the parent plugin
|
|
1958
|
+
* declares a `renderer` (overrides the plugin-level fallback).
|
|
1959
|
+
*
|
|
1960
|
+
* @example
|
|
1961
|
+
* ```ts
|
|
1962
|
+
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
1963
|
+
* export const myGenerator = defineGenerator<PluginTs>({
|
|
1964
|
+
* renderer: jsxRenderer,
|
|
1965
|
+
* schema(node, ctx) { return <File ...>...</File> },
|
|
1966
|
+
* })
|
|
1967
|
+
* ```
|
|
1968
|
+
*/
|
|
1969
|
+
renderer?: RendererFactory<TElement> | null;
|
|
1970
|
+
/**
|
|
1971
|
+
* Called for each schema node in the AST walk.
|
|
1972
|
+
* `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
|
|
1973
|
+
* plus `ctx.options` with the per-node resolved options (after exclude/include/override).
|
|
1974
|
+
*/
|
|
1975
|
+
schema?: (node: SchemaNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
|
|
1976
|
+
/**
|
|
1977
|
+
* Called for each operation node in the AST walk.
|
|
1978
|
+
* `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
|
|
1979
|
+
* plus `ctx.options` with the per-node resolved options (after exclude/include/override).
|
|
1980
|
+
*/
|
|
1981
|
+
operation?: (node: OperationNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
|
|
1982
|
+
/**
|
|
1983
|
+
* Called once after all operations have been walked.
|
|
1984
|
+
* `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
|
|
1985
|
+
* plus `ctx.options` with the plugin-level options for the batch call.
|
|
1986
|
+
*/
|
|
1987
|
+
operations?: (nodes: Array<OperationNode>, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
|
|
1988
|
+
};
|
|
1989
|
+
/**
|
|
1990
|
+
* Defines a generator. Returns the object as-is with correct `this` typings.
|
|
1991
|
+
* `applyHookResult` handles renderer elements and `File[]` uniformly using
|
|
1992
|
+
* the generator's declared `renderer` factory.
|
|
1993
|
+
*/
|
|
1994
|
+
declare function defineGenerator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown>(generator: Generator<TOptions, TElement>): Generator<TOptions, TElement>;
|
|
1995
|
+
//#endregion
|
|
1996
|
+
//#region src/FileManager.d.ts
|
|
1997
|
+
/**
|
|
1998
|
+
* In-memory file store for generated files.
|
|
1999
|
+
*
|
|
2000
|
+
* Files with the same `path` are merged — sources, imports, and exports are concatenated.
|
|
2001
|
+
* The `files` getter returns all stored files sorted by path length (shortest first).
|
|
2002
|
+
*
|
|
2003
|
+
* @example
|
|
2004
|
+
* ```ts
|
|
2005
|
+
* import { FileManager } from '@kubb/core'
|
|
2006
|
+
*
|
|
2007
|
+
* const manager = new FileManager()
|
|
2008
|
+
* manager.upsert(myFile)
|
|
2009
|
+
* console.log(manager.files) // all stored files
|
|
2010
|
+
* ```
|
|
2011
|
+
*/
|
|
2012
|
+
declare class FileManager {
|
|
2013
|
+
#private;
|
|
2014
|
+
/**
|
|
2015
|
+
* Adds one or more files. Files with the same path are merged — sources, imports,
|
|
2016
|
+
* and exports from all calls with the same path are concatenated together.
|
|
2017
|
+
*/
|
|
2018
|
+
add(...files: Array<FileNode>): Array<FileNode>;
|
|
2019
|
+
/**
|
|
2020
|
+
* Adds or merges one or more files.
|
|
2021
|
+
* If a file with the same path already exists, its sources/imports/exports are merged together.
|
|
2022
|
+
*/
|
|
2023
|
+
upsert(...files: Array<FileNode>): Array<FileNode>;
|
|
2024
|
+
getByPath(path: string): FileNode | null;
|
|
2025
|
+
deleteByPath(path: string): void;
|
|
2026
|
+
clear(): void;
|
|
2027
|
+
/**
|
|
2028
|
+
* All stored files, sorted by path length (shorter paths first).
|
|
2029
|
+
* Barrel/index files (e.g. index.ts) are sorted last within each length bucket.
|
|
2030
|
+
*/
|
|
2031
|
+
get files(): Array<FileNode>;
|
|
2032
|
+
}
|
|
1713
2033
|
//#endregion
|
|
1714
2034
|
//#region src/PluginDriver.d.ts
|
|
1715
2035
|
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
@@ -1728,7 +2048,7 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
|
|
|
1728
2048
|
plugin: Plugin;
|
|
1729
2049
|
};
|
|
1730
2050
|
type Options = {
|
|
1731
|
-
|
|
2051
|
+
hooks?: AsyncEventEmitter<KubbHooks>;
|
|
1732
2052
|
/**
|
|
1733
2053
|
* @default Number.POSITIVE_INFINITY
|
|
1734
2054
|
*/
|
|
@@ -1772,7 +2092,54 @@ declare class PluginDriver {
|
|
|
1772
2092
|
readonly fileManager: FileManager;
|
|
1773
2093
|
readonly plugins: Map<string, Plugin>;
|
|
1774
2094
|
constructor(config: Config, options: Options);
|
|
1775
|
-
get
|
|
2095
|
+
get hooks(): AsyncEventEmitter<KubbHooks>;
|
|
2096
|
+
/**
|
|
2097
|
+
* Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.
|
|
2098
|
+
*
|
|
2099
|
+
* For `kubb:plugin:setup`, the registered listener wraps the globally emitted context with a
|
|
2100
|
+
* plugin-specific one so that `addGenerator`, `setResolver`, `setTransformer`, and
|
|
2101
|
+
* `setRenderer` all target the correct `normalizedPlugin` entry in the plugins map.
|
|
2102
|
+
*
|
|
2103
|
+
* All other hooks are iterated and registered directly as pass-through listeners.
|
|
2104
|
+
* Any event key present in the global `KubbHooks` interface can be subscribed to.
|
|
2105
|
+
*
|
|
2106
|
+
* External tooling can subscribe to any of these events via `hooks.on(...)` to observe
|
|
2107
|
+
* the plugin lifecycle without modifying plugin behavior.
|
|
2108
|
+
*/
|
|
2109
|
+
registerPluginHooks(hookPlugin: HookStylePlugin, normalizedPlugin: Plugin): void;
|
|
2110
|
+
/**
|
|
2111
|
+
* Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners
|
|
2112
|
+
* can configure generators, resolvers, transformers and renderers before `buildStart` runs.
|
|
2113
|
+
*
|
|
2114
|
+
* Call this once from `safeBuild` before the plugin execution loop begins.
|
|
2115
|
+
*/
|
|
2116
|
+
emitSetupHooks(): Promise<void>;
|
|
2117
|
+
/**
|
|
2118
|
+
* Registers a generator for the given plugin on the shared event emitter.
|
|
2119
|
+
*
|
|
2120
|
+
* The generator's `schema`, `operation`, and `operations` methods are registered as
|
|
2121
|
+
* listeners on `kubb:generate:schema`, `kubb:generate:operation`, and `kubb:generate:operations`
|
|
2122
|
+
* respectively. Each listener is scoped to the owning plugin via a `ctx.plugin.name` check
|
|
2123
|
+
* so that generators from different plugins do not cross-fire.
|
|
2124
|
+
*
|
|
2125
|
+
* The renderer resolution chain is: `generator.renderer → plugin.renderer → config.renderer`.
|
|
2126
|
+
* Set `generator.renderer = null` to explicitly opt out of rendering even when the plugin
|
|
2127
|
+
* declares a renderer.
|
|
2128
|
+
*
|
|
2129
|
+
* Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.
|
|
2130
|
+
*/
|
|
2131
|
+
registerGenerator(pluginName: string, gen: Generator<any>): void;
|
|
2132
|
+
/**
|
|
2133
|
+
* Returns `true` when at least one generator was registered for the given plugin
|
|
2134
|
+
* via `addGenerator()` in `kubb:plugin:setup` (event-based path).
|
|
2135
|
+
*
|
|
2136
|
+
* Used by the build loop to decide whether to walk the AST and emit generator events
|
|
2137
|
+
* for a plugin that has no static `plugin.generators`.
|
|
2138
|
+
*/
|
|
2139
|
+
hasRegisteredGenerators(pluginName: string): boolean;
|
|
2140
|
+
dispose(): void;
|
|
2141
|
+
setPluginResolver(pluginName: string, partial: Partial<Resolver>): void;
|
|
2142
|
+
getResolver(pluginName: string): Resolver;
|
|
1776
2143
|
getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, unknown>;
|
|
1777
2144
|
/**
|
|
1778
2145
|
* @deprecated use resolvers context instead
|
|
@@ -1843,7 +2210,7 @@ declare class PluginDriver {
|
|
|
1843
2210
|
skipped?: ReadonlySet<Plugin> | null;
|
|
1844
2211
|
}): SafeParseResult<H> | null;
|
|
1845
2212
|
/**
|
|
1846
|
-
* Runs all plugins in parallel based on `this.plugin` order and `
|
|
2213
|
+
* Runs all plugins in parallel based on `this.plugin` order and `dependencies` settings.
|
|
1847
2214
|
*/
|
|
1848
2215
|
hookParallel<H extends PluginLifecycleHooks, TOutput = void>({
|
|
1849
2216
|
hookName,
|
|
@@ -1853,7 +2220,7 @@ declare class PluginDriver {
|
|
|
1853
2220
|
parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
|
|
1854
2221
|
}): Promise<Awaited<TOutput>[]>;
|
|
1855
2222
|
/**
|
|
1856
|
-
*
|
|
2223
|
+
* Execute a lifecycle hook sequentially for all plugins that implement it.
|
|
1857
2224
|
*/
|
|
1858
2225
|
hookSeq<H extends PluginLifecycleHooks>({
|
|
1859
2226
|
hookName,
|
|
@@ -1871,5 +2238,5 @@ declare class PluginDriver {
|
|
|
1871
2238
|
requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>;
|
|
1872
2239
|
}
|
|
1873
2240
|
//#endregion
|
|
1874
|
-
export {
|
|
1875
|
-
//# sourceMappingURL=PluginDriver-
|
|
2241
|
+
export { FileMetaBase as $, Override as A, ResolveNameParams as B, KubbPluginSetupContext as C, OperationHook as D, LoggerOptions as E, PluginLifecycleHooks as F, ResolverContext as G, ResolvePathOptions as H, PluginParameter as I, SchemaHook as J, ResolverFileParams as K, PluginWithLifeCycle as L, PluginContext as M, PluginFactoryOptions as N, OperationsHook as O, PluginLifecycle as P, UserPluginWithLifeCycle as Q, PossibleConfig as R, KubbBuildStartContext as S, LoggerContext as T, ResolvePathParams as U, ResolveOptionsContext as V, Resolver as W, UserLogger as X, UserGroup as Y, UserPlugin as Z, Group as _, RendererFactory as _t, defineGenerator as a, Kubb$1 as at, InputPath as b, AdapterSource as c, createKubb as ct, CompatibilityPreset as d, Storage as dt, getBarrelFiles as et, Config as f, createStorage as ft, GeneratorContext as g, Renderer as gt, Exclude$1 as h, logLevel as ht, Generator as i, definePlugin as it, Plugin as j, Output as k, BarrelType as l, Parser as lt, DevtoolsOptions as m, linters as mt, getMode as n, HookStylePlugin as nt, Adapter as o, KubbHooks as ot, ConfigInput as p, formatters as pt, ResolverPathParams as q, FileManager as r, PluginHooks as rt, AdapterFactoryOptions as s, BuildOutput as st, PluginDriver as t, FunctionParamsAST as tt, CLIOptions as u, defineParser as ut, Include as v, createRenderer as vt, Logger as w, KubbBuildEndContext as x, InputData as y, AsyncEventEmitter as yt, ResolveBannerContext as z };
|
|
2242
|
+
//# sourceMappingURL=PluginDriver-C9iBgYbk.d.ts.map
|