@kubb/core 5.0.0-alpha.35 → 5.0.0-alpha.38
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-BQwm8hDd.cjs +1729 -0
- package/dist/PluginDriver-BQwm8hDd.cjs.map +1 -0
- package/dist/PluginDriver-CgXFtmNP.js +1617 -0
- package/dist/PluginDriver-CgXFtmNP.js.map +1 -0
- package/dist/index.cjs +149 -2142
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +45 -317
- package/dist/index.js +142 -2110
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +164 -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/dist/{PluginDriver-D8lWvtUg.d.ts → types-DUc5lEUp.d.ts} +597 -716
- package/package.json +9 -9
- package/src/PluginDriver.ts +18 -17
- package/src/constants.ts +0 -48
- package/src/createKubb.ts +1 -1
- package/src/defineResolver.ts +3 -3
- package/src/index.ts +5 -20
- package/src/mocks.ts +234 -0
- package/src/types.ts +4 -13
- package/src/utils/TreeNode.ts +3 -3
- package/src/utils/executeStrategies.ts +0 -16
- package/dist/chunk-ByKO4r7w.cjs +0 -38
- package/dist/hooks.cjs +0 -32
- package/dist/hooks.cjs.map +0 -1
- package/dist/hooks.d.ts +0 -23
- package/dist/hooks.js +0 -29
- package/dist/hooks.js.map +0 -1
- package/src/hooks/index.ts +0 -3
- package/src/hooks/useDriver.ts +0 -9
- package/src/hooks/useMode.ts +0 -8
- package/src/hooks/usePlugin.ts +0 -9
- package/src/utils/FunctionParams.ts +0 -155
- package/src/utils/formatters.ts +0 -45
- package/src/utils/getFunctionParams.ts +0 -254
- package/src/utils/linters.ts +0 -45
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { FileNode, ImportNode, InputNode, Node, OperationNode, SchemaNode, Visitor } from "@kubb/ast";
|
|
3
|
-
import { HttpMethod } from "@kubb/oas";
|
|
2
|
+
import { FileNode, HttpMethod, ImportNode, InputNode, Node, OperationNode, SchemaNode, Visitor } from "@kubb/ast";
|
|
4
3
|
|
|
5
4
|
//#region ../../internals/utils/src/asyncEventEmitter.d.ts
|
|
6
5
|
/**
|
|
@@ -95,6 +94,25 @@ declare class AsyncEventEmitter<TEvents extends { [K in keyof TEvents]: unknown[
|
|
|
95
94
|
*/
|
|
96
95
|
type PossiblePromise<T> = Promise<T> | T;
|
|
97
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
|
|
98
116
|
//#region src/createRenderer.d.ts
|
|
99
117
|
/**
|
|
100
118
|
* Minimal interface any Kubb renderer must satisfy.
|
|
@@ -148,73 +166,6 @@ type RendererFactory<TElement = unknown> = () => Renderer<TElement>;
|
|
|
148
166
|
*/
|
|
149
167
|
declare function createRenderer<TElement = unknown>(factory: RendererFactory<TElement>): RendererFactory<TElement>;
|
|
150
168
|
//#endregion
|
|
151
|
-
//#region src/constants.d.ts
|
|
152
|
-
/**
|
|
153
|
-
* Base URL for the Kubb Studio web app.
|
|
154
|
-
*/
|
|
155
|
-
declare const DEFAULT_STUDIO_URL: "https://studio.kubb.dev";
|
|
156
|
-
/**
|
|
157
|
-
* Numeric log-level thresholds used internally to compare verbosity.
|
|
158
|
-
*
|
|
159
|
-
* Higher numbers are more verbose.
|
|
160
|
-
*/
|
|
161
|
-
declare const logLevel: {
|
|
162
|
-
readonly silent: number;
|
|
163
|
-
readonly error: 0;
|
|
164
|
-
readonly warn: 1;
|
|
165
|
-
readonly info: 3;
|
|
166
|
-
readonly verbose: 4;
|
|
167
|
-
readonly debug: 5;
|
|
168
|
-
};
|
|
169
|
-
/**
|
|
170
|
-
* CLI command descriptors for each supported linter.
|
|
171
|
-
*
|
|
172
|
-
* Each entry contains the executable `command`, an `args` factory that maps an
|
|
173
|
-
* output path to the correct argument list, and an `errorMessage` shown when
|
|
174
|
-
* the linter is not found.
|
|
175
|
-
*/
|
|
176
|
-
declare const linters: {
|
|
177
|
-
readonly eslint: {
|
|
178
|
-
readonly command: "eslint";
|
|
179
|
-
readonly args: (outputPath: string) => string[];
|
|
180
|
-
readonly errorMessage: "Eslint not found";
|
|
181
|
-
};
|
|
182
|
-
readonly biome: {
|
|
183
|
-
readonly command: "biome";
|
|
184
|
-
readonly args: (outputPath: string) => string[];
|
|
185
|
-
readonly errorMessage: "Biome not found";
|
|
186
|
-
};
|
|
187
|
-
readonly oxlint: {
|
|
188
|
-
readonly command: "oxlint";
|
|
189
|
-
readonly args: (outputPath: string) => string[];
|
|
190
|
-
readonly errorMessage: "Oxlint not found";
|
|
191
|
-
};
|
|
192
|
-
};
|
|
193
|
-
/**
|
|
194
|
-
* CLI command descriptors for each supported code formatter.
|
|
195
|
-
*
|
|
196
|
-
* Each entry contains the executable `command`, an `args` factory that maps an
|
|
197
|
-
* output path to the correct argument list, and an `errorMessage` shown when
|
|
198
|
-
* the formatter is not found.
|
|
199
|
-
*/
|
|
200
|
-
declare const formatters: {
|
|
201
|
-
readonly prettier: {
|
|
202
|
-
readonly command: "prettier";
|
|
203
|
-
readonly args: (outputPath: string) => string[];
|
|
204
|
-
readonly errorMessage: "Prettier not found";
|
|
205
|
-
};
|
|
206
|
-
readonly biome: {
|
|
207
|
-
readonly command: "biome";
|
|
208
|
-
readonly args: (outputPath: string) => string[];
|
|
209
|
-
readonly errorMessage: "Biome not found";
|
|
210
|
-
};
|
|
211
|
-
readonly oxfmt: {
|
|
212
|
-
readonly command: "oxfmt";
|
|
213
|
-
readonly args: (outputPath: string) => string[];
|
|
214
|
-
readonly errorMessage: "Oxfmt not found";
|
|
215
|
-
};
|
|
216
|
-
};
|
|
217
|
-
//#endregion
|
|
218
169
|
//#region src/createStorage.d.ts
|
|
219
170
|
type Storage = {
|
|
220
171
|
/**
|
|
@@ -272,6 +223,90 @@ type Storage = {
|
|
|
272
223
|
*/
|
|
273
224
|
declare function createStorage<TOptions = Record<string, never>>(build: (options: TOptions) => Storage): (options?: TOptions) => Storage;
|
|
274
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
|
|
275
310
|
//#region src/defineParser.d.ts
|
|
276
311
|
type PrintOptions = {
|
|
277
312
|
extname?: FileNode['extname'];
|
|
@@ -313,213 +348,533 @@ type Parser<TMeta extends object = any> = {
|
|
|
313
348
|
*/
|
|
314
349
|
declare function defineParser<TMeta extends object = any>(parser: Parser<TMeta>): Parser<TMeta>;
|
|
315
350
|
//#endregion
|
|
316
|
-
//#region src/
|
|
351
|
+
//#region src/definePlugin.d.ts
|
|
317
352
|
/**
|
|
318
|
-
*
|
|
353
|
+
* Base hook handlers for all events except `kubb:plugin:setup`.
|
|
354
|
+
* These handlers have identical signatures regardless of the plugin's
|
|
355
|
+
* `PluginFactoryOptions` generic — they are split out so that the
|
|
356
|
+
* interface below only needs to override the one event that depends on
|
|
357
|
+
* the plugin type.
|
|
319
358
|
*/
|
|
320
|
-
type
|
|
359
|
+
type PluginHooksBase = { [K in Exclude<keyof KubbHooks, 'kubb:plugin:setup'>]?: (...args: KubbHooks[K]) => void | Promise<void> };
|
|
360
|
+
/**
|
|
361
|
+
* Plugin hook handlers.
|
|
362
|
+
*
|
|
363
|
+
* `kubb:plugin:setup` is typed with the plugin's own `PluginFactoryOptions` so
|
|
364
|
+
* `ctx.setResolver`, `ctx.setOptions`, `ctx.options` etc. use the correct types.
|
|
365
|
+
*
|
|
366
|
+
* Uses interface + method shorthand for `kubb:plugin:setup`
|
|
367
|
+
* checking, allowing `PluginHooks<PluginTs>` to be assignable to `PluginHooks`.
|
|
368
|
+
*
|
|
369
|
+
* @template TFactory - The plugin's `PluginFactoryOptions` type.
|
|
370
|
+
*/
|
|
371
|
+
interface PluginHooks<TFactory extends PluginFactoryOptions = PluginFactoryOptions> extends PluginHooksBase {
|
|
372
|
+
'kubb:plugin:setup'?(ctx: KubbPluginSetupContext<TFactory>): void | Promise<void>;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* A hook-style plugin object produced by `definePlugin`.
|
|
376
|
+
* Instead of flat lifecycle methods, it groups all handlers under a `hooks:` property
|
|
377
|
+
* (matching Astro's integration naming convention).
|
|
378
|
+
*
|
|
379
|
+
* @template TFactory - The plugin's `PluginFactoryOptions` type.
|
|
380
|
+
*/
|
|
381
|
+
type HookStylePlugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
321
382
|
/**
|
|
322
|
-
*
|
|
383
|
+
* Unique name for the plugin, following the same naming convention as `createPlugin`.
|
|
323
384
|
*/
|
|
324
|
-
|
|
325
|
-
plugin: Plugin;
|
|
326
|
-
error: Error;
|
|
327
|
-
}>;
|
|
328
|
-
files: Array<FileNode>;
|
|
329
|
-
driver: PluginDriver;
|
|
385
|
+
name: string;
|
|
330
386
|
/**
|
|
331
|
-
*
|
|
387
|
+
* Plugins that must be registered before this plugin executes.
|
|
388
|
+
* An error is thrown at startup when any listed dependency is missing.
|
|
332
389
|
*/
|
|
333
|
-
|
|
334
|
-
error?: Error;
|
|
390
|
+
dependencies?: Array<string>;
|
|
335
391
|
/**
|
|
336
|
-
*
|
|
392
|
+
* The options passed by the user when calling the plugin factory.
|
|
337
393
|
*/
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
394
|
+
options?: TFactory['options'];
|
|
395
|
+
/**
|
|
396
|
+
* Lifecycle event handlers for this plugin.
|
|
397
|
+
* Any event from the global `KubbHooks` map can be subscribed to here.
|
|
398
|
+
*/
|
|
399
|
+
hooks: PluginHooks<TFactory>;
|
|
343
400
|
};
|
|
344
401
|
/**
|
|
345
|
-
* Creates a
|
|
402
|
+
* Creates a plugin factory using the new hook-style (`hooks:`) API.
|
|
346
403
|
*
|
|
347
|
-
* The
|
|
348
|
-
*
|
|
349
|
-
*
|
|
404
|
+
* The returned factory is called with optional options and produces a `HookStylePlugin`
|
|
405
|
+
* that coexists with plugins created via the legacy `createPlugin` API in the same
|
|
406
|
+
* `kubb.config.ts`.
|
|
407
|
+
*
|
|
408
|
+
* Lifecycle handlers are registered on the `PluginDriver`'s `AsyncEventEmitter`, enabling
|
|
409
|
+
* both the plugin's own handlers and external tooling (CLI, devtools) to observe every event.
|
|
350
410
|
*
|
|
351
411
|
* @example
|
|
352
412
|
* ```ts
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
413
|
+
* // With PluginFactoryOptions (recommended for real plugins)
|
|
414
|
+
* export const pluginTs = definePlugin<PluginTs>((options) => ({
|
|
415
|
+
* name: 'plugin-ts',
|
|
416
|
+
* hooks: {
|
|
417
|
+
* 'kubb:plugin:setup'(ctx) {
|
|
418
|
+
* ctx.setResolver(resolverTs) // typed as Partial<ResolverTs>
|
|
419
|
+
* },
|
|
420
|
+
* },
|
|
421
|
+
* }))
|
|
360
422
|
* ```
|
|
361
423
|
*/
|
|
362
|
-
declare function
|
|
424
|
+
declare function definePlugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(factory: (options: TFactory['options']) => HookStylePlugin<TFactory>): (options?: TFactory['options']) => HookStylePlugin<TFactory>;
|
|
363
425
|
//#endregion
|
|
364
|
-
//#region src/
|
|
365
|
-
type DebugInfo = {
|
|
366
|
-
date: Date;
|
|
367
|
-
logs: Array<string>;
|
|
368
|
-
fileName?: string;
|
|
369
|
-
};
|
|
370
|
-
type HookProgress<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
371
|
-
hookName: H;
|
|
372
|
-
plugins: Array<Plugin>;
|
|
373
|
-
};
|
|
374
|
-
type HookExecution<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
375
|
-
strategy: Strategy;
|
|
376
|
-
hookName: H;
|
|
377
|
-
plugin: Plugin;
|
|
378
|
-
parameters?: Array<unknown>;
|
|
379
|
-
output?: unknown;
|
|
380
|
-
};
|
|
381
|
-
type HookResult<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
382
|
-
duration: number;
|
|
383
|
-
strategy: Strategy;
|
|
384
|
-
hookName: H;
|
|
385
|
-
plugin: Plugin;
|
|
386
|
-
parameters?: Array<unknown>;
|
|
387
|
-
output?: unknown;
|
|
388
|
-
};
|
|
426
|
+
//#region src/FileManager.d.ts
|
|
389
427
|
/**
|
|
390
|
-
*
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
428
|
+
* In-memory file store for generated files.
|
|
429
|
+
*
|
|
430
|
+
* Files with the same `path` are merged — sources, imports, and exports are concatenated.
|
|
431
|
+
* The `files` getter returns all stored files sorted by path length (shortest first).
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* ```ts
|
|
435
|
+
* import { FileManager } from '@kubb/core'
|
|
436
|
+
*
|
|
437
|
+
* const manager = new FileManager()
|
|
438
|
+
* manager.upsert(myFile)
|
|
439
|
+
* console.log(manager.files) // all stored files
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
declare class FileManager {
|
|
443
|
+
#private;
|
|
406
444
|
/**
|
|
407
|
-
*
|
|
445
|
+
* Adds one or more files. Files with the same path are merged — sources, imports,
|
|
446
|
+
* and exports from all calls with the same path are concatenated together.
|
|
408
447
|
*/
|
|
409
|
-
|
|
448
|
+
add(...files: Array<FileNode>): Array<FileNode>;
|
|
410
449
|
/**
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
* Calling `build()` or `safeBuild()` without calling `setup()` first will
|
|
415
|
-
* automatically invoke `setup()` before proceeding.
|
|
450
|
+
* Adds or merges one or more files.
|
|
451
|
+
* If a file with the same path already exists, its sources/imports/exports are merged together.
|
|
416
452
|
*/
|
|
417
|
-
|
|
453
|
+
upsert(...files: Array<FileNode>): Array<FileNode>;
|
|
454
|
+
getByPath(path: string): FileNode | null;
|
|
455
|
+
deleteByPath(path: string): void;
|
|
456
|
+
clear(): void;
|
|
418
457
|
/**
|
|
419
|
-
*
|
|
420
|
-
*
|
|
458
|
+
* All stored files, sorted by path length (shorter paths first).
|
|
459
|
+
* Barrel/index files (e.g. index.ts) are sorted last within each length bucket.
|
|
421
460
|
*/
|
|
422
|
-
|
|
461
|
+
get files(): Array<FileNode>;
|
|
462
|
+
}
|
|
463
|
+
//#endregion
|
|
464
|
+
//#region src/PluginDriver.d.ts
|
|
465
|
+
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
466
|
+
/**
|
|
467
|
+
* Hook dispatch strategy used by the `PluginDriver`.
|
|
468
|
+
*
|
|
469
|
+
* - `hookFirst` — stops at the first non-null result.
|
|
470
|
+
* - `hookForPlugin` — calls only the matching plugin.
|
|
471
|
+
* - `hookParallel` — calls all plugins concurrently.
|
|
472
|
+
* - `hookSeq` — calls all plugins in order, threading the result.
|
|
473
|
+
*/
|
|
474
|
+
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
|
|
475
|
+
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
476
|
+
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
477
|
+
result: Result;
|
|
478
|
+
plugin: Plugin;
|
|
479
|
+
};
|
|
480
|
+
type Options = {
|
|
481
|
+
hooks?: AsyncEventEmitter<KubbHooks>;
|
|
423
482
|
/**
|
|
424
|
-
*
|
|
425
|
-
* Automatically calls `setup()` if it has not been called yet.
|
|
483
|
+
* @default Number.POSITIVE_INFINITY
|
|
426
484
|
*/
|
|
427
|
-
|
|
485
|
+
concurrency?: number;
|
|
428
486
|
};
|
|
429
487
|
/**
|
|
430
|
-
*
|
|
431
|
-
* These events can be listened to for logging, progress tracking, and custom integrations.
|
|
432
|
-
*
|
|
433
|
-
* @example
|
|
434
|
-
* ```typescript
|
|
435
|
-
* import type { AsyncEventEmitter } from '@internals/utils'
|
|
436
|
-
* import type { KubbHooks } from '@kubb/core'
|
|
437
|
-
*
|
|
438
|
-
* const hooks: AsyncEventEmitter<KubbHooks> = new AsyncEventEmitter()
|
|
439
|
-
*
|
|
440
|
-
* hooks.on('kubb:lifecycle:start', () => {
|
|
441
|
-
* console.log('Starting Kubb generation')
|
|
442
|
-
* })
|
|
443
|
-
*
|
|
444
|
-
* hooks.on('kubb:plugin:end', (plugin, { duration }) => {
|
|
445
|
-
* console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
|
|
446
|
-
* })
|
|
447
|
-
* ```
|
|
488
|
+
* Parameters accepted by `PluginDriver.getFile` to resolve a generated file descriptor.
|
|
448
489
|
*/
|
|
449
|
-
|
|
490
|
+
type GetFileOptions<TOptions = object> = {
|
|
491
|
+
name: string;
|
|
492
|
+
mode?: 'single' | 'split';
|
|
493
|
+
extname: FileNode['extname'];
|
|
494
|
+
pluginName: string;
|
|
495
|
+
options?: TOptions;
|
|
496
|
+
};
|
|
497
|
+
declare class PluginDriver {
|
|
498
|
+
#private;
|
|
499
|
+
readonly config: Config;
|
|
500
|
+
readonly options: Options;
|
|
450
501
|
/**
|
|
451
|
-
*
|
|
502
|
+
* Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
* ```ts
|
|
506
|
+
* PluginDriver.getMode('src/gen/types.ts') // 'single'
|
|
507
|
+
* PluginDriver.getMode('src/gen/types') // 'split'
|
|
508
|
+
* ```
|
|
452
509
|
*/
|
|
453
|
-
|
|
510
|
+
static getMode(fileOrFolder: string | undefined | null): 'single' | 'split';
|
|
454
511
|
/**
|
|
455
|
-
*
|
|
512
|
+
* The universal `@kubb/ast` `InputNode` produced by the adapter, set by
|
|
513
|
+
* the build pipeline after the adapter's `parse()` resolves.
|
|
456
514
|
*/
|
|
457
|
-
|
|
515
|
+
inputNode: InputNode | undefined;
|
|
516
|
+
adapter: Adapter | undefined;
|
|
458
517
|
/**
|
|
459
|
-
*
|
|
518
|
+
* Central file store for all generated files.
|
|
519
|
+
* Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to
|
|
520
|
+
* add files; this property gives direct read/write access when needed.
|
|
460
521
|
*/
|
|
461
|
-
|
|
522
|
+
readonly fileManager: FileManager;
|
|
523
|
+
readonly plugins: Map<string, Plugin>;
|
|
524
|
+
constructor(config: Config, options: Options);
|
|
525
|
+
get hooks(): AsyncEventEmitter<KubbHooks>;
|
|
462
526
|
/**
|
|
463
|
-
*
|
|
527
|
+
* Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.
|
|
528
|
+
*
|
|
529
|
+
* For `kubb:plugin:setup`, the registered listener wraps the globally emitted context with a
|
|
530
|
+
* plugin-specific one so that `addGenerator`, `setResolver`, `setTransformer`, and
|
|
531
|
+
* `setRenderer` all target the correct `normalizedPlugin` entry in the plugins map.
|
|
532
|
+
*
|
|
533
|
+
* All other hooks are iterated and registered directly as pass-through listeners.
|
|
534
|
+
* Any event key present in the global `KubbHooks` interface can be subscribed to.
|
|
535
|
+
*
|
|
536
|
+
* External tooling can subscribe to any of these events via `hooks.on(...)` to observe
|
|
537
|
+
* the plugin lifecycle without modifying plugin behavior.
|
|
464
538
|
*/
|
|
465
|
-
|
|
539
|
+
registerPluginHooks(hookPlugin: HookStylePlugin, normalizedPlugin: Plugin): void;
|
|
466
540
|
/**
|
|
467
|
-
*
|
|
541
|
+
* Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners
|
|
542
|
+
* can configure generators, resolvers, transformers and renderers before `buildStart` runs.
|
|
543
|
+
*
|
|
544
|
+
* Call this once from `safeBuild` before the plugin execution loop begins.
|
|
468
545
|
*/
|
|
469
|
-
|
|
546
|
+
emitSetupHooks(): Promise<void>;
|
|
470
547
|
/**
|
|
471
|
-
*
|
|
548
|
+
* Registers a generator for the given plugin on the shared event emitter.
|
|
549
|
+
*
|
|
550
|
+
* The generator's `schema`, `operation`, and `operations` methods are registered as
|
|
551
|
+
* listeners on `kubb:generate:schema`, `kubb:generate:operation`, and `kubb:generate:operations`
|
|
552
|
+
* respectively. Each listener is scoped to the owning plugin via a `ctx.plugin.name` check
|
|
553
|
+
* so that generators from different plugins do not cross-fire.
|
|
554
|
+
*
|
|
555
|
+
* The renderer resolution chain is: `generator.renderer → plugin.renderer → config.renderer`.
|
|
556
|
+
* Set `generator.renderer = null` to explicitly opt out of rendering even when the plugin
|
|
557
|
+
* declares a renderer.
|
|
558
|
+
*
|
|
559
|
+
* Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.
|
|
472
560
|
*/
|
|
473
|
-
|
|
561
|
+
registerGenerator(pluginName: string, gen: Generator): void;
|
|
474
562
|
/**
|
|
475
|
-
*
|
|
476
|
-
*
|
|
563
|
+
* Returns `true` when at least one generator was registered for the given plugin
|
|
564
|
+
* via `addGenerator()` in `kubb:plugin:setup` (event-based path).
|
|
565
|
+
*
|
|
566
|
+
* Used by the build loop to decide whether to walk the AST and emit generator events
|
|
567
|
+
* for a plugin that has no static `plugin.generators`.
|
|
477
568
|
*/
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
status: 'success' | 'failed';
|
|
484
|
-
hrStart: [number, number];
|
|
485
|
-
filesCreated: number;
|
|
486
|
-
pluginTimings?: Map<Plugin['name'], number>;
|
|
487
|
-
}];
|
|
569
|
+
hasRegisteredGenerators(pluginName: string): boolean;
|
|
570
|
+
dispose(): void;
|
|
571
|
+
setPluginResolver(pluginName: string, partial: Partial<Resolver>): void;
|
|
572
|
+
getResolver(pluginName: string): Resolver;
|
|
573
|
+
getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, unknown>;
|
|
488
574
|
/**
|
|
489
|
-
*
|
|
575
|
+
* @deprecated use resolvers context instead
|
|
490
576
|
*/
|
|
491
|
-
|
|
577
|
+
getFile<TOptions = object>({
|
|
578
|
+
name,
|
|
579
|
+
mode,
|
|
580
|
+
extname,
|
|
581
|
+
pluginName,
|
|
582
|
+
options
|
|
583
|
+
}: GetFileOptions<TOptions>): FileNode<{
|
|
584
|
+
pluginName: string;
|
|
585
|
+
}>;
|
|
492
586
|
/**
|
|
493
|
-
*
|
|
587
|
+
* @deprecated use resolvers context instead
|
|
494
588
|
*/
|
|
495
|
-
|
|
589
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => string;
|
|
496
590
|
/**
|
|
497
|
-
*
|
|
591
|
+
* @deprecated use resolvers context instead
|
|
498
592
|
*/
|
|
499
|
-
|
|
593
|
+
resolveName: (params: ResolveNameParams) => string;
|
|
500
594
|
/**
|
|
501
|
-
*
|
|
595
|
+
* Run a specific hookName for plugin x.
|
|
502
596
|
*/
|
|
503
|
-
|
|
597
|
+
hookForPlugin<H extends PluginLifecycleHooks>({
|
|
598
|
+
pluginName,
|
|
599
|
+
hookName,
|
|
600
|
+
parameters
|
|
601
|
+
}: {
|
|
602
|
+
pluginName: string;
|
|
603
|
+
hookName: H;
|
|
604
|
+
parameters: PluginParameter<H>;
|
|
605
|
+
}): Promise<Array<ReturnType<ParseResult<H>> | null>>;
|
|
504
606
|
/**
|
|
505
|
-
*
|
|
607
|
+
* Run a specific hookName for plugin x.
|
|
506
608
|
*/
|
|
507
|
-
|
|
609
|
+
hookForPluginSync<H extends PluginLifecycleHooks>({
|
|
610
|
+
pluginName,
|
|
611
|
+
hookName,
|
|
612
|
+
parameters
|
|
613
|
+
}: {
|
|
614
|
+
pluginName: string;
|
|
615
|
+
hookName: H;
|
|
616
|
+
parameters: PluginParameter<H>;
|
|
617
|
+
}): Array<ReturnType<ParseResult<H>>> | null;
|
|
508
618
|
/**
|
|
509
|
-
*
|
|
619
|
+
* Returns the first non-null result.
|
|
510
620
|
*/
|
|
511
|
-
|
|
621
|
+
hookFirst<H extends PluginLifecycleHooks>({
|
|
622
|
+
hookName,
|
|
623
|
+
parameters,
|
|
624
|
+
skipped
|
|
625
|
+
}: {
|
|
626
|
+
hookName: H;
|
|
627
|
+
parameters: PluginParameter<H>;
|
|
628
|
+
skipped?: ReadonlySet<Plugin> | null;
|
|
629
|
+
}): Promise<SafeParseResult<H>>;
|
|
512
630
|
/**
|
|
513
|
-
*
|
|
514
|
-
* The callback should be invoked when the command completes.
|
|
631
|
+
* Returns the first non-null result.
|
|
515
632
|
*/
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
}
|
|
633
|
+
hookFirstSync<H extends PluginLifecycleHooks>({
|
|
634
|
+
hookName,
|
|
635
|
+
parameters,
|
|
636
|
+
skipped
|
|
637
|
+
}: {
|
|
638
|
+
hookName: H;
|
|
639
|
+
parameters: PluginParameter<H>;
|
|
640
|
+
skipped?: ReadonlySet<Plugin> | null;
|
|
641
|
+
}): SafeParseResult<H> | null;
|
|
521
642
|
/**
|
|
522
|
-
*
|
|
643
|
+
* Runs all plugins in parallel based on `this.plugin` order and `dependencies` settings.
|
|
644
|
+
*/
|
|
645
|
+
hookParallel<H extends PluginLifecycleHooks, TOutput = void>({
|
|
646
|
+
hookName,
|
|
647
|
+
parameters
|
|
648
|
+
}: {
|
|
649
|
+
hookName: H;
|
|
650
|
+
parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
|
|
651
|
+
}): Promise<Awaited<TOutput>[]>;
|
|
652
|
+
/**
|
|
653
|
+
* Execute a lifecycle hook sequentially for all plugins that implement it.
|
|
654
|
+
*/
|
|
655
|
+
hookSeq<H extends PluginLifecycleHooks>({
|
|
656
|
+
hookName,
|
|
657
|
+
parameters
|
|
658
|
+
}: {
|
|
659
|
+
hookName: H;
|
|
660
|
+
parameters?: PluginParameter<H>;
|
|
661
|
+
}): Promise<void>;
|
|
662
|
+
getPlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
|
|
663
|
+
getPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions> | undefined;
|
|
664
|
+
/**
|
|
665
|
+
* Like `getPlugin` but throws a descriptive error when the plugin is not found.
|
|
666
|
+
*/
|
|
667
|
+
requirePlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]>;
|
|
668
|
+
requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>;
|
|
669
|
+
}
|
|
670
|
+
//#endregion
|
|
671
|
+
//#region src/createKubb.d.ts
|
|
672
|
+
/**
|
|
673
|
+
* Full output produced by a successful or failed build.
|
|
674
|
+
*/
|
|
675
|
+
type BuildOutput = {
|
|
676
|
+
/**
|
|
677
|
+
* Plugins that threw during installation, paired with the caught error.
|
|
678
|
+
*/
|
|
679
|
+
failedPlugins: Set<{
|
|
680
|
+
plugin: Plugin;
|
|
681
|
+
error: Error;
|
|
682
|
+
}>;
|
|
683
|
+
files: Array<FileNode>;
|
|
684
|
+
driver: PluginDriver;
|
|
685
|
+
/**
|
|
686
|
+
* Elapsed time in milliseconds for each plugin, keyed by plugin name.
|
|
687
|
+
*/
|
|
688
|
+
pluginTimings: Map<string, number>;
|
|
689
|
+
error?: Error;
|
|
690
|
+
/**
|
|
691
|
+
* Raw generated source, keyed by absolute file path.
|
|
692
|
+
*/
|
|
693
|
+
sources: Map<string, string>;
|
|
694
|
+
};
|
|
695
|
+
type KubbOptions = {
|
|
696
|
+
config: Config;
|
|
697
|
+
hooks?: AsyncEventEmitter<KubbHooks>;
|
|
698
|
+
};
|
|
699
|
+
/**
|
|
700
|
+
* Creates a Kubb instance bound to a single config entry.
|
|
701
|
+
*
|
|
702
|
+
* The instance holds shared state (`hooks`, `sources`, `driver`, `config`) across the
|
|
703
|
+
* `setup → build` lifecycle. Attach event listeners to `kubb.hooks` before
|
|
704
|
+
* calling `setup()` or `build()`.
|
|
705
|
+
*
|
|
706
|
+
* @example
|
|
707
|
+
* ```ts
|
|
708
|
+
* const kubb = createKubb({ config })
|
|
709
|
+
*
|
|
710
|
+
* kubb.hooks.on('kubb:plugin:end', (plugin, { duration }) => {
|
|
711
|
+
* console.log(`${plugin.name} completed in ${duration}ms`)
|
|
712
|
+
* })
|
|
713
|
+
*
|
|
714
|
+
* const { files, failedPlugins } = await kubb.safeBuild()
|
|
715
|
+
* ```
|
|
716
|
+
*/
|
|
717
|
+
declare function createKubb(options: KubbOptions): Kubb$1;
|
|
718
|
+
//#endregion
|
|
719
|
+
//#region src/Kubb.d.ts
|
|
720
|
+
type DebugInfo = {
|
|
721
|
+
date: Date;
|
|
722
|
+
logs: Array<string>;
|
|
723
|
+
fileName?: string;
|
|
724
|
+
};
|
|
725
|
+
type HookProgress<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
726
|
+
hookName: H;
|
|
727
|
+
plugins: Array<Plugin>;
|
|
728
|
+
};
|
|
729
|
+
type HookExecution<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
730
|
+
strategy: Strategy;
|
|
731
|
+
hookName: H;
|
|
732
|
+
plugin: Plugin;
|
|
733
|
+
parameters?: Array<unknown>;
|
|
734
|
+
output?: unknown;
|
|
735
|
+
};
|
|
736
|
+
type HookResult<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
737
|
+
duration: number;
|
|
738
|
+
strategy: Strategy;
|
|
739
|
+
hookName: H;
|
|
740
|
+
plugin: Plugin;
|
|
741
|
+
parameters?: Array<unknown>;
|
|
742
|
+
output?: unknown;
|
|
743
|
+
};
|
|
744
|
+
/**
|
|
745
|
+
* The instance returned by {@link createKubb}.
|
|
746
|
+
*/
|
|
747
|
+
type Kubb$1 = {
|
|
748
|
+
/**
|
|
749
|
+
* The shared event emitter. Attach listeners here before calling `setup()` or `build()`.
|
|
750
|
+
*/
|
|
751
|
+
readonly hooks: AsyncEventEmitter<KubbHooks>;
|
|
752
|
+
/**
|
|
753
|
+
* Raw generated source, keyed by absolute file path.
|
|
754
|
+
* Populated after a successful `build()` or `safeBuild()` call.
|
|
755
|
+
*/
|
|
756
|
+
readonly sources: Map<string, string>;
|
|
757
|
+
/**
|
|
758
|
+
* The plugin driver. Available after `setup()` has been called.
|
|
759
|
+
*/
|
|
760
|
+
readonly driver: PluginDriver | undefined;
|
|
761
|
+
/**
|
|
762
|
+
* The resolved config with applied defaults. Available after `setup()` has been called.
|
|
763
|
+
*/
|
|
764
|
+
readonly config: Config | undefined;
|
|
765
|
+
/**
|
|
766
|
+
* Initializes all Kubb infrastructure: validates input, applies config defaults,
|
|
767
|
+
* runs the adapter, and creates the PluginDriver.
|
|
768
|
+
*
|
|
769
|
+
* Calling `build()` or `safeBuild()` without calling `setup()` first will
|
|
770
|
+
* automatically invoke `setup()` before proceeding.
|
|
771
|
+
*/
|
|
772
|
+
setup(): Promise<void>;
|
|
773
|
+
/**
|
|
774
|
+
* Runs a full Kubb build and throws on any error or plugin failure.
|
|
775
|
+
* Automatically calls `setup()` if it has not been called yet.
|
|
776
|
+
*/
|
|
777
|
+
build(): Promise<BuildOutput>;
|
|
778
|
+
/**
|
|
779
|
+
* Runs a full Kubb build and captures errors instead of throwing.
|
|
780
|
+
* Automatically calls `setup()` if it has not been called yet.
|
|
781
|
+
*/
|
|
782
|
+
safeBuild(): Promise<BuildOutput>;
|
|
783
|
+
};
|
|
784
|
+
/**
|
|
785
|
+
* Events emitted during the Kubb code generation lifecycle.
|
|
786
|
+
* These events can be listened to for logging, progress tracking, and custom integrations.
|
|
787
|
+
*
|
|
788
|
+
* @example
|
|
789
|
+
* ```typescript
|
|
790
|
+
* import type { AsyncEventEmitter } from '@internals/utils'
|
|
791
|
+
* import type { KubbHooks } from '@kubb/core'
|
|
792
|
+
*
|
|
793
|
+
* const hooks: AsyncEventEmitter<KubbHooks> = new AsyncEventEmitter()
|
|
794
|
+
*
|
|
795
|
+
* hooks.on('kubb:lifecycle:start', () => {
|
|
796
|
+
* console.log('Starting Kubb generation')
|
|
797
|
+
* })
|
|
798
|
+
*
|
|
799
|
+
* hooks.on('kubb:plugin:end', (plugin, { duration }) => {
|
|
800
|
+
* console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
|
|
801
|
+
* })
|
|
802
|
+
* ```
|
|
803
|
+
*/
|
|
804
|
+
interface KubbHooks {
|
|
805
|
+
/**
|
|
806
|
+
* Emitted at the beginning of the Kubb lifecycle, before any code generation starts.
|
|
807
|
+
*/
|
|
808
|
+
'kubb:lifecycle:start': [version: string];
|
|
809
|
+
/**
|
|
810
|
+
* Emitted at the end of the Kubb lifecycle, after all code generation is complete.
|
|
811
|
+
*/
|
|
812
|
+
'kubb:lifecycle:end': [];
|
|
813
|
+
/**
|
|
814
|
+
* Emitted when configuration loading starts.
|
|
815
|
+
*/
|
|
816
|
+
'kubb:config:start': [];
|
|
817
|
+
/**
|
|
818
|
+
* Emitted when configuration loading is complete.
|
|
819
|
+
*/
|
|
820
|
+
'kubb:config:end': [configs: Array<Config>];
|
|
821
|
+
/**
|
|
822
|
+
* Emitted when code generation phase starts.
|
|
823
|
+
*/
|
|
824
|
+
'kubb:generation:start': [config: Config];
|
|
825
|
+
/**
|
|
826
|
+
* Emitted when code generation phase completes.
|
|
827
|
+
*/
|
|
828
|
+
'kubb:generation:end': [config: Config, files: Array<FileNode>, sources: Map<string, string>];
|
|
829
|
+
/**
|
|
830
|
+
* Emitted with a summary of the generation results.
|
|
831
|
+
* Contains summary lines, title, and success status.
|
|
832
|
+
*/
|
|
833
|
+
'kubb:generation:summary': [config: Config, {
|
|
834
|
+
failedPlugins: Set<{
|
|
835
|
+
plugin: Plugin;
|
|
836
|
+
error: Error;
|
|
837
|
+
}>;
|
|
838
|
+
status: 'success' | 'failed';
|
|
839
|
+
hrStart: [number, number];
|
|
840
|
+
filesCreated: number;
|
|
841
|
+
pluginTimings?: Map<Plugin['name'], number>;
|
|
842
|
+
}];
|
|
843
|
+
/**
|
|
844
|
+
* Emitted when code formatting starts (e.g., running Biome or Prettier).
|
|
845
|
+
*/
|
|
846
|
+
'kubb:format:start': [];
|
|
847
|
+
/**
|
|
848
|
+
* Emitted when code formatting completes.
|
|
849
|
+
*/
|
|
850
|
+
'kubb:format:end': [];
|
|
851
|
+
/**
|
|
852
|
+
* Emitted when linting starts.
|
|
853
|
+
*/
|
|
854
|
+
'kubb:lint:start': [];
|
|
855
|
+
/**
|
|
856
|
+
* Emitted when linting completes.
|
|
857
|
+
*/
|
|
858
|
+
'kubb:lint:end': [];
|
|
859
|
+
/**
|
|
860
|
+
* Emitted when plugin hooks execution starts.
|
|
861
|
+
*/
|
|
862
|
+
'kubb:hooks:start': [];
|
|
863
|
+
/**
|
|
864
|
+
* Emitted when plugin hooks execution completes.
|
|
865
|
+
*/
|
|
866
|
+
'kubb:hooks:end': [];
|
|
867
|
+
/**
|
|
868
|
+
* Emitted when a single hook execution starts (e.g., format or lint).
|
|
869
|
+
* The callback should be invoked when the command completes.
|
|
870
|
+
*/
|
|
871
|
+
'kubb:hook:start': [{
|
|
872
|
+
id?: string;
|
|
873
|
+
command: string;
|
|
874
|
+
args?: readonly string[];
|
|
875
|
+
}];
|
|
876
|
+
/**
|
|
877
|
+
* Emitted when a single hook execution completes.
|
|
523
878
|
*/
|
|
524
879
|
'kubb:hook:end': [{
|
|
525
880
|
id?: string;
|
|
@@ -692,164 +1047,25 @@ declare global {
|
|
|
692
1047
|
}
|
|
693
1048
|
}
|
|
694
1049
|
//#endregion
|
|
695
|
-
//#region src/
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
*/
|
|
715
|
-
interface PluginHooks<TFactory extends PluginFactoryOptions = PluginFactoryOptions> extends PluginHooksBase {
|
|
716
|
-
'kubb:plugin:setup'?(ctx: KubbPluginSetupContext<TFactory>): void | Promise<void>;
|
|
717
|
-
}
|
|
718
|
-
/**
|
|
719
|
-
* A hook-style plugin object produced by `definePlugin`.
|
|
720
|
-
* Instead of flat lifecycle methods, it groups all handlers under a `hooks:` property
|
|
721
|
-
* (matching Astro's integration naming convention).
|
|
722
|
-
*
|
|
723
|
-
* @template TFactory - The plugin's `PluginFactoryOptions` type.
|
|
724
|
-
*/
|
|
725
|
-
type HookStylePlugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
726
|
-
/**
|
|
727
|
-
* Unique name for the plugin, following the same naming convention as `createPlugin`.
|
|
728
|
-
*/
|
|
729
|
-
name: string;
|
|
730
|
-
/**
|
|
731
|
-
* Plugins that must be registered before this plugin executes.
|
|
732
|
-
* An error is thrown at startup when any listed dependency is missing.
|
|
733
|
-
*/
|
|
734
|
-
dependencies?: Array<string>;
|
|
735
|
-
/**
|
|
736
|
-
* The options passed by the user when calling the plugin factory.
|
|
737
|
-
*/
|
|
738
|
-
options?: TFactory['options'];
|
|
739
|
-
/**
|
|
740
|
-
* Lifecycle event handlers for this plugin.
|
|
741
|
-
* Any event from the global `KubbHooks` map can be subscribed to here.
|
|
742
|
-
*/
|
|
743
|
-
hooks: PluginHooks<TFactory>;
|
|
744
|
-
};
|
|
745
|
-
/**
|
|
746
|
-
* Creates a plugin factory using the new hook-style (`hooks:`) API.
|
|
747
|
-
*
|
|
748
|
-
* The returned factory is called with optional options and produces a `HookStylePlugin`
|
|
749
|
-
* that coexists with plugins created via the legacy `createPlugin` API in the same
|
|
750
|
-
* `kubb.config.ts`.
|
|
751
|
-
*
|
|
752
|
-
* Lifecycle handlers are registered on the `PluginDriver`'s `AsyncEventEmitter`, enabling
|
|
753
|
-
* both the plugin's own handlers and external tooling (CLI, devtools) to observe every event.
|
|
754
|
-
*
|
|
755
|
-
* @example
|
|
756
|
-
* ```ts
|
|
757
|
-
* // With PluginFactoryOptions (recommended for real plugins)
|
|
758
|
-
* export const pluginTs = definePlugin<PluginTs>((options) => ({
|
|
759
|
-
* name: 'plugin-ts',
|
|
760
|
-
* hooks: {
|
|
761
|
-
* 'kubb:plugin:setup'(ctx) {
|
|
762
|
-
* ctx.setResolver(resolverTs) // typed as Partial<ResolverTs>
|
|
763
|
-
* },
|
|
764
|
-
* },
|
|
765
|
-
* }))
|
|
766
|
-
* ```
|
|
767
|
-
*/
|
|
768
|
-
declare function definePlugin<TFactory extends PluginFactoryOptions = PluginFactoryOptions>(factory: (options: TFactory['options']) => HookStylePlugin<TFactory>): (options?: TFactory['options']) => HookStylePlugin<TFactory>;
|
|
769
|
-
//#endregion
|
|
770
|
-
//#region src/utils/FunctionParams.d.ts
|
|
771
|
-
type FunctionParamsASTWithoutType = {
|
|
772
|
-
name?: string;
|
|
773
|
-
type?: string;
|
|
774
|
-
/**
|
|
775
|
-
* @default true
|
|
776
|
-
*/
|
|
777
|
-
required?: boolean;
|
|
778
|
-
/**
|
|
779
|
-
* @default true
|
|
780
|
-
*/
|
|
781
|
-
enabled?: boolean;
|
|
782
|
-
default?: string;
|
|
783
|
-
};
|
|
784
|
-
type FunctionParamsASTWithType = {
|
|
785
|
-
name?: never;
|
|
786
|
-
type: string;
|
|
787
|
-
/**
|
|
788
|
-
* @default true
|
|
789
|
-
*/
|
|
790
|
-
required?: boolean;
|
|
791
|
-
/**
|
|
792
|
-
* @default true
|
|
793
|
-
*/
|
|
794
|
-
enabled?: boolean;
|
|
795
|
-
default?: string;
|
|
796
|
-
};
|
|
797
|
-
/**
|
|
798
|
-
* @deprecated use ast package instead
|
|
799
|
-
*/
|
|
800
|
-
type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType;
|
|
801
|
-
//#endregion
|
|
802
|
-
//#region src/utils/getBarrelFiles.d.ts
|
|
803
|
-
type FileMetaBase = {
|
|
804
|
-
pluginName?: string;
|
|
805
|
-
};
|
|
806
|
-
type AddIndexesProps = {
|
|
807
|
-
type: BarrelType | false | undefined;
|
|
808
|
-
/**
|
|
809
|
-
* Absolute output root derived from config `root` and `output.path`.
|
|
810
|
-
*/
|
|
811
|
-
root: string;
|
|
812
|
-
/**
|
|
813
|
-
* Output settings for the plugin.
|
|
814
|
-
*/
|
|
815
|
-
output: {
|
|
816
|
-
path: string;
|
|
817
|
-
};
|
|
818
|
-
group?: {
|
|
819
|
-
output: string;
|
|
820
|
-
exportAs: string;
|
|
821
|
-
};
|
|
822
|
-
meta?: FileMetaBase;
|
|
823
|
-
};
|
|
824
|
-
/**
|
|
825
|
-
* Generates `index.ts` barrel files for all directories under `root/output.path`.
|
|
826
|
-
*
|
|
827
|
-
* - Returns an empty array when `type` is falsy or `'propagate'`.
|
|
828
|
-
* - Skips generation when the output path itself ends with `index` (already a barrel).
|
|
829
|
-
* - When `type` is `'all'`, strips named exports so every re-export becomes a wildcard (`export * from`).
|
|
830
|
-
* - Attaches `meta` to each barrel file for downstream plugin identification.
|
|
831
|
-
*/
|
|
832
|
-
declare function getBarrelFiles(files: Array<FileNode>, {
|
|
833
|
-
type,
|
|
834
|
-
meta,
|
|
835
|
-
root,
|
|
836
|
-
output
|
|
837
|
-
}: AddIndexesProps): Promise<Array<FileNode>>;
|
|
838
|
-
//#endregion
|
|
839
|
-
//#region src/types.d.ts
|
|
840
|
-
type InputPath = {
|
|
841
|
-
/**
|
|
842
|
-
* Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
|
|
843
|
-
*/
|
|
844
|
-
path: string;
|
|
845
|
-
};
|
|
846
|
-
type InputData = {
|
|
847
|
-
/**
|
|
848
|
-
* A `string` or `object` that contains your Swagger/OpenAPI data.
|
|
849
|
-
*/
|
|
850
|
-
data: string | unknown;
|
|
851
|
-
};
|
|
852
|
-
type Input = InputPath | InputData;
|
|
1050
|
+
//#region src/utils/getBarrelFiles.d.ts
|
|
1051
|
+
type FileMetaBase = {
|
|
1052
|
+
pluginName?: string;
|
|
1053
|
+
};
|
|
1054
|
+
//#endregion
|
|
1055
|
+
//#region src/types.d.ts
|
|
1056
|
+
type InputPath = {
|
|
1057
|
+
/**
|
|
1058
|
+
* Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
|
|
1059
|
+
*/
|
|
1060
|
+
path: string;
|
|
1061
|
+
};
|
|
1062
|
+
type InputData = {
|
|
1063
|
+
/**
|
|
1064
|
+
* A `string` or `object` that contains your Swagger/OpenAPI data.
|
|
1065
|
+
*/
|
|
1066
|
+
data: string | unknown;
|
|
1067
|
+
};
|
|
1068
|
+
type Input = InputPath | InputData;
|
|
853
1069
|
/**
|
|
854
1070
|
* The raw source passed to an adapter's `parse` function.
|
|
855
1071
|
* Mirrors the shape of `Config['input']` with paths already resolved to absolute.
|
|
@@ -1250,7 +1466,7 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
1250
1466
|
* over `plugin.renderer`; set `renderer: null` on a generator to opt out of rendering even
|
|
1251
1467
|
* when the plugin declares a renderer.
|
|
1252
1468
|
*/
|
|
1253
|
-
generators?: Array<Generator
|
|
1469
|
+
generators?: Array<Generator>;
|
|
1254
1470
|
/**
|
|
1255
1471
|
* Specifies the plugins that the current plugin depends on. The current plugin is executed after all listed plugins.
|
|
1256
1472
|
* An error is returned if any required dependency plugin is missing.
|
|
@@ -1353,7 +1569,7 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
|
1353
1569
|
* over `plugin.renderer`; set `renderer: null` on a generator to opt out of rendering even
|
|
1354
1570
|
* when the plugin declares a renderer.
|
|
1355
1571
|
*/
|
|
1356
|
-
generators?: Array<Generator
|
|
1572
|
+
generators?: Array<Generator>;
|
|
1357
1573
|
buildStart: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
1358
1574
|
/**
|
|
1359
1575
|
* Called once per plugin after all files have been written to disk.
|
|
@@ -1489,7 +1705,7 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
1489
1705
|
/**
|
|
1490
1706
|
* Returns the output mode for the given output config.
|
|
1491
1707
|
* Returns `'single'` when `output.path` has a file extension, `'split'` otherwise.
|
|
1492
|
-
* Shorthand for `getMode(path.resolve(this.root, output.path))`.
|
|
1708
|
+
* Shorthand for `PluginDriver.getMode(path.resolve(this.root, output.path))`.
|
|
1493
1709
|
*/
|
|
1494
1710
|
getMode: (output: {
|
|
1495
1711
|
path: string;
|
|
@@ -1903,341 +2119,6 @@ type CLIOptions = {
|
|
|
1903
2119
|
* - `PossibleConfig<TCliOptions>` accepts the same config forms or a config factory receiving `TCliOptions`.
|
|
1904
2120
|
*/
|
|
1905
2121
|
type PossibleConfig<TCliOptions = undefined> = PossiblePromise<Config | Config[]> | ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Config[]>);
|
|
1906
|
-
/**
|
|
1907
|
-
* All accepted forms of a Kubb configuration.
|
|
1908
|
-
* @deprecated
|
|
1909
|
-
* Kept for backward compatibility. Prefer `PossibleConfig<CLIOptions>` in new code.
|
|
1910
|
-
*/
|
|
1911
|
-
type ConfigInput = PossibleConfig<CLIOptions>;
|
|
1912
|
-
//#endregion
|
|
1913
|
-
//#region src/defineGenerator.d.ts
|
|
1914
|
-
/**
|
|
1915
|
-
* A generator is a named object with optional `schema`, `operation`, and `operations`
|
|
1916
|
-
* methods. Each method receives the AST node as the first argument and a typed
|
|
1917
|
-
* `ctx` object as the second, giving access to `ctx.config`, `ctx.resolver`,
|
|
1918
|
-
* `ctx.adapter`, `ctx.options`, `ctx.upsertFile`, etc.
|
|
1919
|
-
*
|
|
1920
|
-
* Generators that return renderer elements (e.g. JSX) must declare a `renderer`
|
|
1921
|
-
* factory so that core knows how to process the output without coupling core
|
|
1922
|
-
* to any specific renderer package.
|
|
1923
|
-
*
|
|
1924
|
-
* Return a renderer element, an array of `FileNode`, or `void` to handle file
|
|
1925
|
-
* writing manually via `ctx.upsertFile`.
|
|
1926
|
-
*
|
|
1927
|
-
* @example
|
|
1928
|
-
* ```ts
|
|
1929
|
-
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
1930
|
-
*
|
|
1931
|
-
* export const typeGenerator = defineGenerator<PluginTs>({
|
|
1932
|
-
* name: 'typescript',
|
|
1933
|
-
* renderer: jsxRenderer,
|
|
1934
|
-
* schema(node, ctx) {
|
|
1935
|
-
* const { adapter, resolver, root, options } = ctx
|
|
1936
|
-
* return <File ...><Type node={node} resolver={resolver} /></File>
|
|
1937
|
-
* },
|
|
1938
|
-
* operation(node, ctx) {
|
|
1939
|
-
* const { options } = ctx
|
|
1940
|
-
* return <File ...><OperationType node={node} /></File>
|
|
1941
|
-
* },
|
|
1942
|
-
* })
|
|
1943
|
-
* ```
|
|
1944
|
-
*/
|
|
1945
|
-
type Generator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown> = {
|
|
1946
|
-
/**
|
|
1947
|
-
* Used in diagnostic messages and debug output.
|
|
1948
|
-
*/
|
|
1949
|
-
name: string;
|
|
1950
|
-
/**
|
|
1951
|
-
* Optional renderer factory that produces a {@link Renderer} for each render cycle.
|
|
1952
|
-
*
|
|
1953
|
-
* Generators that return renderer elements (e.g. JSX via `@kubb/renderer-jsx`) must set this
|
|
1954
|
-
* to the matching renderer factory (e.g. `jsxRenderer` from `@kubb/renderer-jsx`).
|
|
1955
|
-
*
|
|
1956
|
-
* Generators that only return `Array<FileNode>` or `void` do not need to set this.
|
|
1957
|
-
*
|
|
1958
|
-
* Set `renderer: null` to explicitly opt out of rendering even when the parent plugin
|
|
1959
|
-
* declares a `renderer` (overrides the plugin-level fallback).
|
|
1960
|
-
*
|
|
1961
|
-
* @example
|
|
1962
|
-
* ```ts
|
|
1963
|
-
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
1964
|
-
* export const myGenerator = defineGenerator<PluginTs>({
|
|
1965
|
-
* renderer: jsxRenderer,
|
|
1966
|
-
* schema(node, ctx) { return <File ...>...</File> },
|
|
1967
|
-
* })
|
|
1968
|
-
* ```
|
|
1969
|
-
*/
|
|
1970
|
-
renderer?: RendererFactory<TElement> | null;
|
|
1971
|
-
/**
|
|
1972
|
-
* Called for each schema node in the AST walk.
|
|
1973
|
-
* `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
|
|
1974
|
-
* plus `ctx.options` with the per-node resolved options (after exclude/include/override).
|
|
1975
|
-
*/
|
|
1976
|
-
schema?: (node: SchemaNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
|
|
1977
|
-
/**
|
|
1978
|
-
* Called for each operation node in the AST walk.
|
|
1979
|
-
* `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
|
|
1980
|
-
* plus `ctx.options` with the per-node resolved options (after exclude/include/override).
|
|
1981
|
-
*/
|
|
1982
|
-
operation?: (node: OperationNode, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
|
|
1983
|
-
/**
|
|
1984
|
-
* Called once after all operations have been walked.
|
|
1985
|
-
* `ctx` carries the plugin context with `adapter` and `inputNode` guaranteed present,
|
|
1986
|
-
* plus `ctx.options` with the plugin-level options for the batch call.
|
|
1987
|
-
*/
|
|
1988
|
-
operations?: (nodes: Array<OperationNode>, ctx: GeneratorContext<TOptions>) => PossiblePromise<TElement | Array<FileNode> | void>;
|
|
1989
|
-
};
|
|
1990
|
-
/**
|
|
1991
|
-
* Defines a generator. Returns the object as-is with correct `this` typings.
|
|
1992
|
-
* `applyHookResult` handles renderer elements and `File[]` uniformly using
|
|
1993
|
-
* the generator's declared `renderer` factory.
|
|
1994
|
-
*/
|
|
1995
|
-
declare function defineGenerator<TOptions extends PluginFactoryOptions = PluginFactoryOptions, TElement = unknown>(generator: Generator<TOptions, TElement>): Generator<TOptions, TElement>;
|
|
1996
|
-
//#endregion
|
|
1997
|
-
//#region src/FileManager.d.ts
|
|
1998
|
-
/**
|
|
1999
|
-
* In-memory file store for generated files.
|
|
2000
|
-
*
|
|
2001
|
-
* Files with the same `path` are merged — sources, imports, and exports are concatenated.
|
|
2002
|
-
* The `files` getter returns all stored files sorted by path length (shortest first).
|
|
2003
|
-
*
|
|
2004
|
-
* @example
|
|
2005
|
-
* ```ts
|
|
2006
|
-
* import { FileManager } from '@kubb/core'
|
|
2007
|
-
*
|
|
2008
|
-
* const manager = new FileManager()
|
|
2009
|
-
* manager.upsert(myFile)
|
|
2010
|
-
* console.log(manager.files) // all stored files
|
|
2011
|
-
* ```
|
|
2012
|
-
*/
|
|
2013
|
-
declare class FileManager {
|
|
2014
|
-
#private;
|
|
2015
|
-
/**
|
|
2016
|
-
* Adds one or more files. Files with the same path are merged — sources, imports,
|
|
2017
|
-
* and exports from all calls with the same path are concatenated together.
|
|
2018
|
-
*/
|
|
2019
|
-
add(...files: Array<FileNode>): Array<FileNode>;
|
|
2020
|
-
/**
|
|
2021
|
-
* Adds or merges one or more files.
|
|
2022
|
-
* If a file with the same path already exists, its sources/imports/exports are merged together.
|
|
2023
|
-
*/
|
|
2024
|
-
upsert(...files: Array<FileNode>): Array<FileNode>;
|
|
2025
|
-
getByPath(path: string): FileNode | null;
|
|
2026
|
-
deleteByPath(path: string): void;
|
|
2027
|
-
clear(): void;
|
|
2028
|
-
/**
|
|
2029
|
-
* All stored files, sorted by path length (shorter paths first).
|
|
2030
|
-
* Barrel/index files (e.g. index.ts) are sorted last within each length bucket.
|
|
2031
|
-
*/
|
|
2032
|
-
get files(): Array<FileNode>;
|
|
2033
|
-
}
|
|
2034
|
-
//#endregion
|
|
2035
|
-
//#region src/PluginDriver.d.ts
|
|
2036
|
-
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
2037
|
-
/**
|
|
2038
|
-
* Hook dispatch strategy used by the `PluginDriver`.
|
|
2039
|
-
*
|
|
2040
|
-
* - `hookFirst` — stops at the first non-null result.
|
|
2041
|
-
* - `hookForPlugin` — calls only the matching plugin.
|
|
2042
|
-
* - `hookParallel` — calls all plugins concurrently.
|
|
2043
|
-
* - `hookSeq` — calls all plugins in order, threading the result.
|
|
2044
|
-
*/
|
|
2045
|
-
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
|
|
2046
|
-
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
2047
|
-
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
2048
|
-
result: Result;
|
|
2049
|
-
plugin: Plugin;
|
|
2050
|
-
};
|
|
2051
|
-
type Options = {
|
|
2052
|
-
hooks?: AsyncEventEmitter<KubbHooks>;
|
|
2053
|
-
/**
|
|
2054
|
-
* @default Number.POSITIVE_INFINITY
|
|
2055
|
-
*/
|
|
2056
|
-
concurrency?: number;
|
|
2057
|
-
};
|
|
2058
|
-
/**
|
|
2059
|
-
* Parameters accepted by `PluginDriver.getFile` to resolve a generated file descriptor.
|
|
2060
|
-
*/
|
|
2061
|
-
type GetFileOptions<TOptions = object> = {
|
|
2062
|
-
name: string;
|
|
2063
|
-
mode?: 'single' | 'split';
|
|
2064
|
-
extname: FileNode['extname'];
|
|
2065
|
-
pluginName: string;
|
|
2066
|
-
options?: TOptions;
|
|
2067
|
-
};
|
|
2068
|
-
/**
|
|
2069
|
-
* Returns `'single'` when `fileOrFolder` has a file extension, `'split'` otherwise.
|
|
2070
|
-
*
|
|
2071
|
-
* @example
|
|
2072
|
-
* ```ts
|
|
2073
|
-
* getMode('src/gen/types.ts') // 'single'
|
|
2074
|
-
* getMode('src/gen/types') // 'split'
|
|
2075
|
-
* ```
|
|
2076
|
-
*/
|
|
2077
|
-
declare function getMode(fileOrFolder: string | undefined | null): 'single' | 'split';
|
|
2078
|
-
declare class PluginDriver {
|
|
2079
|
-
#private;
|
|
2080
|
-
readonly config: Config;
|
|
2081
|
-
readonly options: Options;
|
|
2082
|
-
/**
|
|
2083
|
-
* The universal `@kubb/ast` `InputNode` produced by the adapter, set by
|
|
2084
|
-
* the build pipeline after the adapter's `parse()` resolves.
|
|
2085
|
-
*/
|
|
2086
|
-
inputNode: InputNode | undefined;
|
|
2087
|
-
adapter: Adapter | undefined;
|
|
2088
|
-
/**
|
|
2089
|
-
* Central file store for all generated files.
|
|
2090
|
-
* Plugins should use `this.addFile()` / `this.upsertFile()` (via their context) to
|
|
2091
|
-
* add files; this property gives direct read/write access when needed.
|
|
2092
|
-
*/
|
|
2093
|
-
readonly fileManager: FileManager;
|
|
2094
|
-
readonly plugins: Map<string, Plugin>;
|
|
2095
|
-
constructor(config: Config, options: Options);
|
|
2096
|
-
get hooks(): AsyncEventEmitter<KubbHooks>;
|
|
2097
|
-
/**
|
|
2098
|
-
* Registers a hook-style plugin's lifecycle handlers on the shared `AsyncEventEmitter`.
|
|
2099
|
-
*
|
|
2100
|
-
* For `kubb:plugin:setup`, the registered listener wraps the globally emitted context with a
|
|
2101
|
-
* plugin-specific one so that `addGenerator`, `setResolver`, `setTransformer`, and
|
|
2102
|
-
* `setRenderer` all target the correct `normalizedPlugin` entry in the plugins map.
|
|
2103
|
-
*
|
|
2104
|
-
* All other hooks are iterated and registered directly as pass-through listeners.
|
|
2105
|
-
* Any event key present in the global `KubbHooks` interface can be subscribed to.
|
|
2106
|
-
*
|
|
2107
|
-
* External tooling can subscribe to any of these events via `hooks.on(...)` to observe
|
|
2108
|
-
* the plugin lifecycle without modifying plugin behavior.
|
|
2109
|
-
*/
|
|
2110
|
-
registerPluginHooks(hookPlugin: HookStylePlugin, normalizedPlugin: Plugin): void;
|
|
2111
|
-
/**
|
|
2112
|
-
* Emits the `kubb:plugin:setup` event so that all registered hook-style plugin listeners
|
|
2113
|
-
* can configure generators, resolvers, transformers and renderers before `buildStart` runs.
|
|
2114
|
-
*
|
|
2115
|
-
* Call this once from `safeBuild` before the plugin execution loop begins.
|
|
2116
|
-
*/
|
|
2117
|
-
emitSetupHooks(): Promise<void>;
|
|
2118
|
-
/**
|
|
2119
|
-
* Registers a generator for the given plugin on the shared event emitter.
|
|
2120
|
-
*
|
|
2121
|
-
* The generator's `schema`, `operation`, and `operations` methods are registered as
|
|
2122
|
-
* listeners on `kubb:generate:schema`, `kubb:generate:operation`, and `kubb:generate:operations`
|
|
2123
|
-
* respectively. Each listener is scoped to the owning plugin via a `ctx.plugin.name` check
|
|
2124
|
-
* so that generators from different plugins do not cross-fire.
|
|
2125
|
-
*
|
|
2126
|
-
* The renderer resolution chain is: `generator.renderer → plugin.renderer → config.renderer`.
|
|
2127
|
-
* Set `generator.renderer = null` to explicitly opt out of rendering even when the plugin
|
|
2128
|
-
* declares a renderer.
|
|
2129
|
-
*
|
|
2130
|
-
* Call this method inside `addGenerator()` (in `kubb:plugin:setup`) to wire up a generator.
|
|
2131
|
-
*/
|
|
2132
|
-
registerGenerator(pluginName: string, gen: Generator<any>): void;
|
|
2133
|
-
/**
|
|
2134
|
-
* Returns `true` when at least one generator was registered for the given plugin
|
|
2135
|
-
* via `addGenerator()` in `kubb:plugin:setup` (event-based path).
|
|
2136
|
-
*
|
|
2137
|
-
* Used by the build loop to decide whether to walk the AST and emit generator events
|
|
2138
|
-
* for a plugin that has no static `plugin.generators`.
|
|
2139
|
-
*/
|
|
2140
|
-
hasRegisteredGenerators(pluginName: string): boolean;
|
|
2141
|
-
dispose(): void;
|
|
2142
|
-
setPluginResolver(pluginName: string, partial: Partial<Resolver>): void;
|
|
2143
|
-
getResolver(pluginName: string): Resolver;
|
|
2144
|
-
getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, unknown>;
|
|
2145
|
-
/**
|
|
2146
|
-
* @deprecated use resolvers context instead
|
|
2147
|
-
*/
|
|
2148
|
-
getFile<TOptions = object>({
|
|
2149
|
-
name,
|
|
2150
|
-
mode,
|
|
2151
|
-
extname,
|
|
2152
|
-
pluginName,
|
|
2153
|
-
options
|
|
2154
|
-
}: GetFileOptions<TOptions>): FileNode<{
|
|
2155
|
-
pluginName: string;
|
|
2156
|
-
}>;
|
|
2157
|
-
/**
|
|
2158
|
-
* @deprecated use resolvers context instead
|
|
2159
|
-
*/
|
|
2160
|
-
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => string;
|
|
2161
|
-
/**
|
|
2162
|
-
* @deprecated use resolvers context instead
|
|
2163
|
-
*/
|
|
2164
|
-
resolveName: (params: ResolveNameParams) => string;
|
|
2165
|
-
/**
|
|
2166
|
-
* Run a specific hookName for plugin x.
|
|
2167
|
-
*/
|
|
2168
|
-
hookForPlugin<H extends PluginLifecycleHooks>({
|
|
2169
|
-
pluginName,
|
|
2170
|
-
hookName,
|
|
2171
|
-
parameters
|
|
2172
|
-
}: {
|
|
2173
|
-
pluginName: string;
|
|
2174
|
-
hookName: H;
|
|
2175
|
-
parameters: PluginParameter<H>;
|
|
2176
|
-
}): Promise<Array<ReturnType<ParseResult<H>> | null>>;
|
|
2177
|
-
/**
|
|
2178
|
-
* Run a specific hookName for plugin x.
|
|
2179
|
-
*/
|
|
2180
|
-
hookForPluginSync<H extends PluginLifecycleHooks>({
|
|
2181
|
-
pluginName,
|
|
2182
|
-
hookName,
|
|
2183
|
-
parameters
|
|
2184
|
-
}: {
|
|
2185
|
-
pluginName: string;
|
|
2186
|
-
hookName: H;
|
|
2187
|
-
parameters: PluginParameter<H>;
|
|
2188
|
-
}): Array<ReturnType<ParseResult<H>>> | null;
|
|
2189
|
-
/**
|
|
2190
|
-
* Returns the first non-null result.
|
|
2191
|
-
*/
|
|
2192
|
-
hookFirst<H extends PluginLifecycleHooks>({
|
|
2193
|
-
hookName,
|
|
2194
|
-
parameters,
|
|
2195
|
-
skipped
|
|
2196
|
-
}: {
|
|
2197
|
-
hookName: H;
|
|
2198
|
-
parameters: PluginParameter<H>;
|
|
2199
|
-
skipped?: ReadonlySet<Plugin> | null;
|
|
2200
|
-
}): Promise<SafeParseResult<H>>;
|
|
2201
|
-
/**
|
|
2202
|
-
* Returns the first non-null result.
|
|
2203
|
-
*/
|
|
2204
|
-
hookFirstSync<H extends PluginLifecycleHooks>({
|
|
2205
|
-
hookName,
|
|
2206
|
-
parameters,
|
|
2207
|
-
skipped
|
|
2208
|
-
}: {
|
|
2209
|
-
hookName: H;
|
|
2210
|
-
parameters: PluginParameter<H>;
|
|
2211
|
-
skipped?: ReadonlySet<Plugin> | null;
|
|
2212
|
-
}): SafeParseResult<H> | null;
|
|
2213
|
-
/**
|
|
2214
|
-
* Runs all plugins in parallel based on `this.plugin` order and `dependencies` settings.
|
|
2215
|
-
*/
|
|
2216
|
-
hookParallel<H extends PluginLifecycleHooks, TOutput = void>({
|
|
2217
|
-
hookName,
|
|
2218
|
-
parameters
|
|
2219
|
-
}: {
|
|
2220
|
-
hookName: H;
|
|
2221
|
-
parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
|
|
2222
|
-
}): Promise<Awaited<TOutput>[]>;
|
|
2223
|
-
/**
|
|
2224
|
-
* Execute a lifecycle hook sequentially for all plugins that implement it.
|
|
2225
|
-
*/
|
|
2226
|
-
hookSeq<H extends PluginLifecycleHooks>({
|
|
2227
|
-
hookName,
|
|
2228
|
-
parameters
|
|
2229
|
-
}: {
|
|
2230
|
-
hookName: H;
|
|
2231
|
-
parameters?: PluginParameter<H>;
|
|
2232
|
-
}): Promise<void>;
|
|
2233
|
-
getPlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined;
|
|
2234
|
-
getPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions> | undefined;
|
|
2235
|
-
/**
|
|
2236
|
-
* Like `getPlugin` but throws a descriptive error when the plugin is not found.
|
|
2237
|
-
*/
|
|
2238
|
-
requirePlugin<TName extends keyof Kubb.PluginRegistry>(pluginName: TName): Plugin<Kubb.PluginRegistry[TName]>;
|
|
2239
|
-
requirePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(pluginName: string): Plugin<TOptions>;
|
|
2240
|
-
}
|
|
2241
2122
|
//#endregion
|
|
2242
|
-
export {
|
|
2243
|
-
//# sourceMappingURL=
|
|
2123
|
+
export { FileManager as $, PluginParameter as A, ResolverFileParams as B, Output as C, PluginFactoryOptions as D, PluginContext as E, ResolveOptionsContext as F, UserPlugin as G, SchemaHook as H, ResolvePathOptions as I, Kubb$1 as J, UserPluginWithLifeCycle as K, ResolvePathParams as L, PossibleConfig as M, ResolveBannerContext as N, PluginLifecycle as O, ResolveNameParams as P, PluginDriver as Q, Resolver as R, OperationsHook as S, Plugin as T, UserGroup as U, ResolverPathParams as V, UserLogger as W, BuildOutput as X, KubbHooks as Y, createKubb as Z, KubbPluginSetupContext as _, CLIOptions as a, Generator as at, LoggerOptions as b, DevtoolsOptions as c, createStorage as ct, Group as d, createRenderer as dt, HookStylePlugin as et, Include as f, logLevel as ft, KubbBuildStartContext as g, KubbBuildEndContext as h, BarrelType as i, defineParser as it, PluginWithLifeCycle as j, PluginLifecycleHooks as k, Exclude$1 as l, Renderer as lt, InputPath as m, AdapterFactoryOptions as n, definePlugin as nt, CompatibilityPreset as o, defineGenerator as ot, InputData as p, AsyncEventEmitter as pt, FileMetaBase as q, AdapterSource as r, Parser as rt, Config as s, Storage as st, Adapter as t, PluginHooks as tt, GeneratorContext as u, RendererFactory as ut, Logger as v, Override as w, OperationHook as x, LoggerContext as y, ResolverContext as z };
|
|
2124
|
+
//# sourceMappingURL=types-DUc5lEUp.d.ts.map
|