@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
package/src/types.ts
CHANGED
|
@@ -1,92 +1,14 @@
|
|
|
1
1
|
import type { AsyncEventEmitter, PossiblePromise } from '@internals/utils'
|
|
2
|
-
import type { FileNode, ImportNode, InputNode, Node, OperationNode,
|
|
3
|
-
import type { HttpMethod } from '@kubb/oas'
|
|
4
|
-
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
2
|
+
import type { FileNode, HttpMethod, ImportNode, InputNode, Node, OperationNode, SchemaNode, Visitor } from '@kubb/ast'
|
|
5
3
|
import type { DEFAULT_STUDIO_URL, logLevel } from './constants.ts'
|
|
4
|
+
import type { RendererFactory } from './createRenderer.ts'
|
|
6
5
|
import type { Storage } from './createStorage.ts'
|
|
7
6
|
import type { Generator } from './defineGenerator.ts'
|
|
8
7
|
import type { Parser } from './defineParser.ts'
|
|
9
|
-
import type {
|
|
8
|
+
import type { KubbHooks } from './Kubb.ts'
|
|
10
9
|
import type { PluginDriver } from './PluginDriver.ts'
|
|
11
10
|
|
|
12
|
-
export type {
|
|
13
|
-
|
|
14
|
-
declare global {
|
|
15
|
-
namespace Kubb {
|
|
16
|
-
interface PluginContext {}
|
|
17
|
-
/**
|
|
18
|
-
* Registry that maps plugin names to their `PluginFactoryOptions`.
|
|
19
|
-
* Augment this interface in each plugin's `types.ts` to enable automatic
|
|
20
|
-
* typing for `getPlugin` and `requirePlugin`.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* // packages/plugin-ts/src/types.ts
|
|
25
|
-
* declare global {
|
|
26
|
-
* namespace Kubb {
|
|
27
|
-
* interface PluginRegistry {
|
|
28
|
-
* 'plugin-ts': PluginTs
|
|
29
|
-
* }
|
|
30
|
-
* }
|
|
31
|
-
* }
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
interface PluginRegistry {}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Config used in `kubb.config.ts`
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* import { defineConfig } from '@kubb/core'
|
|
43
|
-
* export default defineConfig({
|
|
44
|
-
* ...
|
|
45
|
-
* })
|
|
46
|
-
*/
|
|
47
|
-
export type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter'> & {
|
|
48
|
-
/**
|
|
49
|
-
* The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
|
|
50
|
-
* @default process.cwd()
|
|
51
|
-
*/
|
|
52
|
-
root?: string
|
|
53
|
-
/**
|
|
54
|
-
* An array of parsers used to convert generated files to strings.
|
|
55
|
-
* Each parser handles specific file extensions (e.g. `.ts`, `.tsx`).
|
|
56
|
-
*
|
|
57
|
-
* A catch-all fallback parser is always appended last for any unhandled extension.
|
|
58
|
-
*
|
|
59
|
-
* When omitted, `parserTsx` from `@kubb/parser-ts` is used automatically as the
|
|
60
|
-
* default (requires `@kubb/parser-ts` to be installed as an optional dependency).
|
|
61
|
-
* @default [parserTsx] — from `@kubb/parser-ts`
|
|
62
|
-
* @example
|
|
63
|
-
* ```ts
|
|
64
|
-
* import { parserTs, tsxParser } from '@kubb/parser-ts'
|
|
65
|
-
* export default defineConfig({
|
|
66
|
-
* parsers: [parserTs, tsxParser],
|
|
67
|
-
* })
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
parsers?: Array<Parser>
|
|
71
|
-
/**
|
|
72
|
-
* Adapter that converts the input file into a `@kubb/ast` `InputNode` — the universal
|
|
73
|
-
* intermediate representation consumed by all Kubb plugins.
|
|
74
|
-
*
|
|
75
|
-
* When omitted, `adapterOas()` from `@kubb/adapter-oas` is used automatically as the
|
|
76
|
-
* default (requires `@kubb/adapter-oas` to be installed as an optional dependency).
|
|
77
|
-
*
|
|
78
|
-
* - Use `@kubb/adapter-oas` for OpenAPI / Swagger (default).
|
|
79
|
-
* - Use `@kubb/adapter-drizzle` or `@kubb/adapter-asyncapi` for other formats.
|
|
80
|
-
*
|
|
81
|
-
* @default adapterOas() — from `@kubb/adapter-oas`
|
|
82
|
-
*/
|
|
83
|
-
adapter?: Adapter
|
|
84
|
-
/**
|
|
85
|
-
* 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.
|
|
86
|
-
*/
|
|
87
|
-
// inject needs to be omitted because else we have a clash with the PluginDriver instance
|
|
88
|
-
plugins?: Array<Omit<UnknownUserPlugin, 'inject'>>
|
|
89
|
-
}
|
|
11
|
+
export type { Renderer, RendererFactory } from './createRenderer.ts'
|
|
90
12
|
|
|
91
13
|
export type InputPath = {
|
|
92
14
|
/**
|
|
@@ -178,6 +100,12 @@ export type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptio
|
|
|
178
100
|
getImports: (node: SchemaNode, resolve: (schemaName: string) => { name: string; path: string }) => Array<ImportNode>
|
|
179
101
|
}
|
|
180
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Controls how `index.ts` barrel files are generated.
|
|
105
|
+
* - `'all'` — exports every generated symbol from every file.
|
|
106
|
+
* - `'named'` — exports only explicitly named exports.
|
|
107
|
+
* - `'propagate'` — propagates re-exports from nested barrel files upward.
|
|
108
|
+
*/
|
|
181
109
|
export type BarrelType = 'all' | 'named' | 'propagate'
|
|
182
110
|
|
|
183
111
|
export type DevtoolsOptions = {
|
|
@@ -238,13 +166,14 @@ export type Config<TInput = Input> = {
|
|
|
238
166
|
*/
|
|
239
167
|
adapter: Adapter
|
|
240
168
|
/**
|
|
241
|
-
*
|
|
169
|
+
* Source file or data to generate code from.
|
|
170
|
+
* Use `input.path` for a file on disk or `input.data` for an inline string or object.
|
|
242
171
|
*/
|
|
243
172
|
input: TInput
|
|
244
173
|
output: {
|
|
245
174
|
/**
|
|
246
|
-
*
|
|
247
|
-
*
|
|
175
|
+
* Output directory for generated files.
|
|
176
|
+
* Accepts an absolute path or a path relative to `root`.
|
|
248
177
|
*/
|
|
249
178
|
path: string
|
|
250
179
|
/**
|
|
@@ -317,11 +246,28 @@ export type Config<TInput = Input> = {
|
|
|
317
246
|
override?: boolean
|
|
318
247
|
}
|
|
319
248
|
/**
|
|
320
|
-
* An array of Kubb plugins
|
|
321
|
-
* Each plugin may
|
|
322
|
-
* If a plugin depends on another
|
|
249
|
+
* An array of Kubb plugins used for code generation.
|
|
250
|
+
* Each plugin may declare additional configurable options.
|
|
251
|
+
* If a plugin depends on another, an error is thrown when the dependency is missing.
|
|
252
|
+
* Use `dependencies` on the plugin to declare execution order.
|
|
323
253
|
*/
|
|
324
254
|
plugins: Array<Plugin>
|
|
255
|
+
/**
|
|
256
|
+
* Project-wide renderer factory. All plugins and generators that do not declare their own
|
|
257
|
+
* `renderer` ultimately fall back to this value.
|
|
258
|
+
*
|
|
259
|
+
* The resolution chain is: `generator.renderer` → `plugin.renderer` → `config.renderer` → `undefined` (raw `FileNode[]` mode).
|
|
260
|
+
*
|
|
261
|
+
* @example
|
|
262
|
+
* ```ts
|
|
263
|
+
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
264
|
+
* export default defineConfig({
|
|
265
|
+
* renderer: jsxRenderer,
|
|
266
|
+
* plugins: [pluginTs(), pluginZod()],
|
|
267
|
+
* })
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
renderer?: RendererFactory
|
|
325
271
|
/**
|
|
326
272
|
* Devtools configuration for Kubb Studio integration.
|
|
327
273
|
*/
|
|
@@ -400,22 +346,6 @@ export type Resolver = {
|
|
|
400
346
|
resolveFooter(node: InputNode | null, context: ResolveBannerContext): string | undefined
|
|
401
347
|
}
|
|
402
348
|
|
|
403
|
-
/**
|
|
404
|
-
* The user-facing subset of a `Resolver` — everything except the four methods injected by
|
|
405
|
-
* `defineResolver` (`default`, `resolveOptions`, `resolvePath`, and `resolveFile`).
|
|
406
|
-
*
|
|
407
|
-
* All four injected methods can still be overridden by providing them explicitly in the builder.
|
|
408
|
-
*
|
|
409
|
-
* @example
|
|
410
|
-
* ```ts
|
|
411
|
-
* export const resolver = defineResolver<PluginTs>(() => ({
|
|
412
|
-
* name: 'default',
|
|
413
|
-
* resolveName(node) { return this.default(node.name, 'function') },
|
|
414
|
-
* }))
|
|
415
|
-
* ```
|
|
416
|
-
*/
|
|
417
|
-
export type UserResolver = Omit<Resolver, 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>
|
|
418
|
-
|
|
419
349
|
export type PluginFactoryOptions<
|
|
420
350
|
/**
|
|
421
351
|
* Name to be used for the plugin.
|
|
@@ -451,15 +381,20 @@ export type PluginFactoryOptions<
|
|
|
451
381
|
resolver: TResolver
|
|
452
382
|
}
|
|
453
383
|
|
|
384
|
+
/**
|
|
385
|
+
* @deprecated
|
|
386
|
+
*/
|
|
454
387
|
export type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
455
388
|
/**
|
|
456
|
-
* Unique name used for the plugin
|
|
457
|
-
* The name
|
|
458
|
-
*
|
|
389
|
+
* Unique name used for the plugin.
|
|
390
|
+
* The name follows the format `scope:foo-bar` or `foo-bar` — adding a scope avoids conflicts with other plugins.
|
|
391
|
+
*
|
|
392
|
+
* @example Plugin name
|
|
393
|
+
* `'@kubb/typescript'`
|
|
459
394
|
*/
|
|
460
395
|
name: TOptions['name']
|
|
461
396
|
/**
|
|
462
|
-
*
|
|
397
|
+
* Resolved options merged with output/include/exclude/override defaults for the current plugin.
|
|
463
398
|
*/
|
|
464
399
|
options: TOptions['resolvedOptions'] & {
|
|
465
400
|
output: Output
|
|
@@ -469,24 +404,43 @@ export type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOpti
|
|
|
469
404
|
}
|
|
470
405
|
/**
|
|
471
406
|
* The resolver for this plugin.
|
|
472
|
-
*
|
|
407
|
+
* Set via `setResolver()` in `kubb:plugin:setup` or passed as a user option.
|
|
473
408
|
*/
|
|
474
409
|
resolver?: TOptions['resolver']
|
|
475
410
|
/**
|
|
476
411
|
* The composed transformer for this plugin.
|
|
477
|
-
*
|
|
478
|
-
* When a visitor method returns `null`/`undefined`, the preset transformer's result is used instead.
|
|
412
|
+
* Set via `setTransformer()` in `kubb:plugin:setup` or passed as a user option.
|
|
479
413
|
*/
|
|
480
414
|
transformer?: Visitor
|
|
481
415
|
/**
|
|
482
|
-
*
|
|
483
|
-
*
|
|
416
|
+
* Plugin-level renderer factory. All generators that do not declare their own `renderer`
|
|
417
|
+
* inherit this value. A generator can explicitly opt out by setting `renderer: null`.
|
|
418
|
+
*
|
|
419
|
+
* @example
|
|
420
|
+
* ```ts
|
|
421
|
+
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
422
|
+
* createPlugin((options) => ({
|
|
423
|
+
* name: 'my-plugin',
|
|
424
|
+
* renderer: jsxRenderer,
|
|
425
|
+
* generators: [
|
|
426
|
+
* { name: 'types', schema(node) { return <File>...</File> } }, // inherits jsxRenderer
|
|
427
|
+
* { name: 'raw', renderer: null, schema(node) { return [...] } }, // explicit opt-out
|
|
428
|
+
* ],
|
|
429
|
+
* }))
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
renderer?: RendererFactory
|
|
433
|
+
/**
|
|
434
|
+
* Generators declared directly on the plugin. Each generator's `renderer` takes precedence
|
|
435
|
+
* over `plugin.renderer`; set `renderer: null` on a generator to opt out of rendering even
|
|
436
|
+
* when the plugin declares a renderer.
|
|
484
437
|
*/
|
|
485
|
-
|
|
438
|
+
generators?: Array<Generator<any>>
|
|
486
439
|
/**
|
|
487
|
-
* Specifies the
|
|
440
|
+
* Specifies the plugins that the current plugin depends on. The current plugin is executed after all listed plugins.
|
|
441
|
+
* An error is returned if any required dependency plugin is missing.
|
|
488
442
|
*/
|
|
489
|
-
|
|
443
|
+
dependencies?: Array<string>
|
|
490
444
|
/**
|
|
491
445
|
* When `apply` is defined, the plugin is only activated when `apply(config)` returns `true`.
|
|
492
446
|
* Inspired by Vite's `apply` option.
|
|
@@ -514,10 +468,11 @@ export type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOpti
|
|
|
514
468
|
inject?: (this: PluginContext<TOptions>) => TOptions['context']
|
|
515
469
|
}
|
|
516
470
|
|
|
471
|
+
/**
|
|
472
|
+
* @deprecated
|
|
473
|
+
*/
|
|
517
474
|
export type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>
|
|
518
475
|
|
|
519
|
-
type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<string, object, object, unknown, object>>
|
|
520
|
-
|
|
521
476
|
/**
|
|
522
477
|
* Handler for a single schema node. Used by the `schema` hook on a plugin.
|
|
523
478
|
*/
|
|
@@ -525,7 +480,7 @@ export type SchemaHook<TOptions extends PluginFactoryOptions = PluginFactoryOpti
|
|
|
525
480
|
this: GeneratorContext<TOptions>,
|
|
526
481
|
node: SchemaNode,
|
|
527
482
|
options: TOptions['resolvedOptions'],
|
|
528
|
-
) => PossiblePromise<
|
|
483
|
+
) => PossiblePromise<unknown | Array<FileNode> | void>
|
|
529
484
|
|
|
530
485
|
/**
|
|
531
486
|
* Handler for a single operation node. Used by the `operation` hook on a plugin.
|
|
@@ -534,7 +489,7 @@ export type OperationHook<TOptions extends PluginFactoryOptions = PluginFactoryO
|
|
|
534
489
|
this: GeneratorContext<TOptions>,
|
|
535
490
|
node: OperationNode,
|
|
536
491
|
options: TOptions['resolvedOptions'],
|
|
537
|
-
) => PossiblePromise<
|
|
492
|
+
) => PossiblePromise<unknown | Array<FileNode> | void>
|
|
538
493
|
|
|
539
494
|
/**
|
|
540
495
|
* Handler for all collected operation nodes. Used by the `operations` hook on a plugin.
|
|
@@ -543,23 +498,23 @@ export type OperationsHook<TOptions extends PluginFactoryOptions = PluginFactory
|
|
|
543
498
|
this: GeneratorContext<TOptions>,
|
|
544
499
|
nodes: Array<OperationNode>,
|
|
545
500
|
options: TOptions['resolvedOptions'],
|
|
546
|
-
) => PossiblePromise<
|
|
547
|
-
|
|
501
|
+
) => PossiblePromise<unknown | Array<FileNode> | void>
|
|
502
|
+
/**
|
|
503
|
+
* @deprecated will be replaced with HookStylePlugin
|
|
504
|
+
*/
|
|
548
505
|
export type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
549
506
|
/**
|
|
550
|
-
* Unique name used for the plugin
|
|
551
|
-
*
|
|
507
|
+
* Unique name used for the plugin.
|
|
508
|
+
*
|
|
509
|
+
* @example Plugin name
|
|
510
|
+
* `'@kubb/typescript'`
|
|
552
511
|
*/
|
|
553
512
|
name: TOptions['name']
|
|
554
513
|
/**
|
|
555
|
-
* Specifies the
|
|
556
|
-
*
|
|
557
|
-
*/
|
|
558
|
-
pre?: Array<string>
|
|
559
|
-
/**
|
|
560
|
-
* 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.
|
|
514
|
+
* Specifies the plugins that the current plugin depends on. The current plugin is executed after all listed plugins.
|
|
515
|
+
* An error is returned if any required dependency plugin is missing.
|
|
561
516
|
*/
|
|
562
|
-
|
|
517
|
+
dependencies?: Array<string>
|
|
563
518
|
/**
|
|
564
519
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
565
520
|
*/
|
|
@@ -571,13 +526,12 @@ export type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
571
526
|
}
|
|
572
527
|
/**
|
|
573
528
|
* The resolver for this plugin.
|
|
574
|
-
*
|
|
529
|
+
* Set via `setResolver()` in `kubb:plugin:setup` or passed as a user option.
|
|
575
530
|
*/
|
|
576
531
|
resolver: TOptions['resolver']
|
|
577
532
|
/**
|
|
578
|
-
* The composed transformer for this plugin.
|
|
579
|
-
*
|
|
580
|
-
* When a visitor method returns `null`/`undefined`, the preset transformer's result is used instead.
|
|
533
|
+
* The composed transformer for this plugin.
|
|
534
|
+
* Set via `setTransformer()` in `kubb:plugin:setup` or passed as a user option.
|
|
581
535
|
*/
|
|
582
536
|
transformer?: Visitor
|
|
583
537
|
|
|
@@ -591,6 +545,17 @@ export type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
591
545
|
* Used in diagnostic messages and version-conflict detection.
|
|
592
546
|
*/
|
|
593
547
|
version?: string
|
|
548
|
+
/**
|
|
549
|
+
* Plugin-level renderer factory. All generators that do not declare their own `renderer`
|
|
550
|
+
* inherit this value. A generator can explicitly opt out by setting `renderer: null`.
|
|
551
|
+
*/
|
|
552
|
+
renderer?: RendererFactory
|
|
553
|
+
/**
|
|
554
|
+
* Generators declared directly on the plugin. Each generator's `renderer` takes precedence
|
|
555
|
+
* over `plugin.renderer`; set `renderer: null` on a generator to opt out of rendering even
|
|
556
|
+
* when the plugin declares a renderer.
|
|
557
|
+
*/
|
|
558
|
+
generators?: Array<Generator<any>>
|
|
594
559
|
|
|
595
560
|
buildStart: (this: PluginContext<TOptions>) => PossiblePromise<void>
|
|
596
561
|
/**
|
|
@@ -625,20 +590,22 @@ export type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
|
|
|
625
590
|
*/
|
|
626
591
|
inject: (this: PluginContext<TOptions>) => TOptions['context']
|
|
627
592
|
}
|
|
628
|
-
|
|
593
|
+
/**
|
|
594
|
+
* @deprecated
|
|
595
|
+
*/
|
|
629
596
|
export type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>
|
|
630
|
-
|
|
597
|
+
/**
|
|
598
|
+
* @deprecated
|
|
599
|
+
*/
|
|
631
600
|
export type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
632
601
|
/**
|
|
633
602
|
* Called once per plugin at the start of its processing phase, before schema/operation/operations hooks run.
|
|
634
603
|
* Use this to set up shared state, fetch remote data, or perform any async initialization.
|
|
635
|
-
* @type hookParallel
|
|
636
604
|
*/
|
|
637
605
|
buildStart?: (this: PluginContext<TOptions>) => PossiblePromise<void>
|
|
638
606
|
/**
|
|
639
607
|
* Called once per plugin after all files have been written to disk.
|
|
640
608
|
* Use this for post-processing, copying assets, or generating summary reports.
|
|
641
|
-
* @type hookParallel
|
|
642
609
|
*/
|
|
643
610
|
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>
|
|
644
611
|
/**
|
|
@@ -666,23 +633,30 @@ export type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactor
|
|
|
666
633
|
*/
|
|
667
634
|
operations?: OperationsHook<TOptions>
|
|
668
635
|
/**
|
|
669
|
-
*
|
|
670
|
-
* Options can
|
|
671
|
-
*
|
|
672
|
-
* @example
|
|
673
|
-
*
|
|
636
|
+
* Resolves a path from a baseName and directory.
|
|
637
|
+
* Options can also be included.
|
|
638
|
+
*
|
|
639
|
+
* @example
|
|
640
|
+
* `('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'`
|
|
641
|
+
*
|
|
642
|
+
* @deprecated Use resolvers instead.
|
|
674
643
|
*/
|
|
675
644
|
resolvePath?: (this: PluginContext<TOptions>, baseName: FileNode['baseName'], mode?: 'single' | 'split', options?: TOptions['resolvePathOptions']) => string
|
|
676
645
|
/**
|
|
677
|
-
*
|
|
646
|
+
* Resolves a display name from a raw string.
|
|
678
647
|
* Useful when converting to PascalCase or camelCase.
|
|
679
|
-
*
|
|
680
|
-
* @example
|
|
681
|
-
*
|
|
648
|
+
*
|
|
649
|
+
* @example
|
|
650
|
+
* `('pet') => 'Pet'`
|
|
651
|
+
*
|
|
652
|
+
* @deprecated Use resolvers instead.
|
|
682
653
|
*/
|
|
683
654
|
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
|
|
684
655
|
}
|
|
685
656
|
|
|
657
|
+
/**
|
|
658
|
+
* @deprecated
|
|
659
|
+
*/
|
|
686
660
|
export type PluginLifecycleHooks = keyof PluginLifecycle
|
|
687
661
|
|
|
688
662
|
export type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>
|
|
@@ -692,7 +666,7 @@ export type ResolvePathParams<TOptions = object> = {
|
|
|
692
666
|
baseName: FileNode['baseName']
|
|
693
667
|
mode?: 'single' | 'split'
|
|
694
668
|
/**
|
|
695
|
-
* Options
|
|
669
|
+
* Options passed as the third argument to `resolvePath`.
|
|
696
670
|
*/
|
|
697
671
|
options?: TOptions
|
|
698
672
|
}
|
|
@@ -702,15 +676,16 @@ export type ResolveNameParams = {
|
|
|
702
676
|
pluginName?: string
|
|
703
677
|
/**
|
|
704
678
|
* Specifies the type of entity being named.
|
|
705
|
-
* - 'file' customizes the name of the created file (
|
|
706
|
-
* - 'function' customizes the exported function names (
|
|
707
|
-
* - 'type' customizes TypeScript
|
|
708
|
-
* - 'const' customizes variable names (
|
|
709
|
-
* @default undefined
|
|
679
|
+
* - `'file'` — customizes the name of the created file (camelCase).
|
|
680
|
+
* - `'function'` — customizes the exported function names (camelCase).
|
|
681
|
+
* - `'type'` — customizes TypeScript type names (PascalCase).
|
|
682
|
+
* - `'const'` — customizes variable names (camelCase).
|
|
710
683
|
*/
|
|
711
684
|
type?: 'file' | 'function' | 'type' | 'const'
|
|
712
685
|
}
|
|
713
|
-
|
|
686
|
+
/**
|
|
687
|
+
* @deprecated
|
|
688
|
+
*/
|
|
714
689
|
export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
715
690
|
config: Config
|
|
716
691
|
/**
|
|
@@ -738,19 +713,16 @@ export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryO
|
|
|
738
713
|
requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>
|
|
739
714
|
requirePlugin(name: string): Plugin
|
|
740
715
|
/**
|
|
741
|
-
*
|
|
716
|
+
* Add files only when they do not exist yet.
|
|
742
717
|
*/
|
|
743
718
|
addFile: (...file: Array<FileNode>) => Promise<void>
|
|
744
719
|
/**
|
|
745
|
-
*
|
|
720
|
+
* Merge multiple sources into the same output file.
|
|
746
721
|
*/
|
|
747
722
|
upsertFile: (...file: Array<FileNode>) => Promise<void>
|
|
723
|
+
hooks: AsyncEventEmitter<KubbHooks>
|
|
748
724
|
/**
|
|
749
|
-
*
|
|
750
|
-
*/
|
|
751
|
-
events: AsyncEventEmitter<KubbEvents>
|
|
752
|
-
/**
|
|
753
|
-
* Current plugin
|
|
725
|
+
* The current plugin.
|
|
754
726
|
*/
|
|
755
727
|
plugin: Plugin<TOptions>
|
|
756
728
|
/**
|
|
@@ -765,17 +737,17 @@ export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryO
|
|
|
765
737
|
|
|
766
738
|
/**
|
|
767
739
|
* Emit a warning via the build event system.
|
|
768
|
-
* Shorthand for `this.
|
|
740
|
+
* Shorthand for `this.hooks.emit('kubb:warn', message)`.
|
|
769
741
|
*/
|
|
770
742
|
warn: (message: string) => void
|
|
771
743
|
/**
|
|
772
744
|
* Emit an error via the build event system.
|
|
773
|
-
* Shorthand for `this.
|
|
745
|
+
* Shorthand for `this.hooks.emit('kubb:error', error)`.
|
|
774
746
|
*/
|
|
775
747
|
error: (error: string | Error) => void
|
|
776
748
|
/**
|
|
777
749
|
* Emit an info message via the build event system.
|
|
778
|
-
* Shorthand for `this.
|
|
750
|
+
* Shorthand for `this.hooks.emit('kubb:info', message)`.
|
|
779
751
|
*/
|
|
780
752
|
info: (message: string) => void
|
|
781
753
|
/**
|
|
@@ -792,7 +764,7 @@ export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryO
|
|
|
792
764
|
*/
|
|
793
765
|
inputNode: InputNode
|
|
794
766
|
/**
|
|
795
|
-
*
|
|
767
|
+
* The adapter from `@kubb/ast`.
|
|
796
768
|
*/
|
|
797
769
|
adapter: Adapter
|
|
798
770
|
}
|
|
@@ -804,23 +776,27 @@ export type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryO
|
|
|
804
776
|
Kubb.PluginContext
|
|
805
777
|
|
|
806
778
|
/**
|
|
807
|
-
*
|
|
779
|
+
* Context object passed as the second argument to generator `schema`, `operation`, and
|
|
780
|
+
* `operations` methods.
|
|
808
781
|
*
|
|
809
|
-
* Generators
|
|
810
|
-
*
|
|
811
|
-
*
|
|
812
|
-
*
|
|
782
|
+
* Generators are only invoked from `runPluginAstHooks`, which already guards against a
|
|
783
|
+
* missing adapter. This type reflects that guarantee — `ctx.adapter` and `ctx.inputNode`
|
|
784
|
+
* are always defined, so no runtime checks or casts are needed inside generator bodies.
|
|
785
|
+
*
|
|
786
|
+
* `ctx.options` carries the per-node resolved options for `schema`/`operation` calls
|
|
787
|
+
* (after exclude/include/override filtering) and the plugin-level options for `operations`.
|
|
813
788
|
*/
|
|
814
789
|
export type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Omit<PluginContext<TOptions>, 'adapter' | 'inputNode'> & {
|
|
815
790
|
adapter: Adapter
|
|
816
791
|
inputNode: InputNode
|
|
792
|
+
options: TOptions['resolvedOptions']
|
|
817
793
|
}
|
|
818
794
|
/**
|
|
819
|
-
*
|
|
795
|
+
* Configure generated file output location and behavior.
|
|
820
796
|
*/
|
|
821
797
|
export type Output<_TOptions = unknown> = {
|
|
822
798
|
/**
|
|
823
|
-
* Path to the output folder or file that will contain
|
|
799
|
+
* Path to the output folder or file that will contain generated code.
|
|
824
800
|
*/
|
|
825
801
|
path: string
|
|
826
802
|
/**
|
|
@@ -829,11 +805,13 @@ export type Output<_TOptions = unknown> = {
|
|
|
829
805
|
*/
|
|
830
806
|
barrelType?: BarrelType | false
|
|
831
807
|
/**
|
|
832
|
-
*
|
|
808
|
+
* Text or function appended at the start of every generated file.
|
|
809
|
+
* When a function, receives the current `InputNode` and must return a string.
|
|
833
810
|
*/
|
|
834
811
|
banner?: string | ((node?: InputNode) => string)
|
|
835
812
|
/**
|
|
836
|
-
*
|
|
813
|
+
* Text or function appended at the end of every generated file.
|
|
814
|
+
* When a function, receives the current `InputNode` and must return a string.
|
|
837
815
|
*/
|
|
838
816
|
footer?: string | ((node?: InputNode) => string)
|
|
839
817
|
/**
|
|
@@ -845,28 +823,27 @@ export type Output<_TOptions = unknown> = {
|
|
|
845
823
|
|
|
846
824
|
export type UserGroup = {
|
|
847
825
|
/**
|
|
848
|
-
*
|
|
849
|
-
* - 'tag' groups files by OpenAPI tags.
|
|
850
|
-
* - 'path' groups files by OpenAPI paths.
|
|
851
|
-
* @default undefined
|
|
826
|
+
* Determines how files are grouped into subdirectories.
|
|
827
|
+
* - `'tag'` groups files by OpenAPI tags.
|
|
828
|
+
* - `'path'` groups files by OpenAPI paths.
|
|
852
829
|
*/
|
|
853
830
|
type: 'tag' | 'path'
|
|
854
831
|
/**
|
|
855
|
-
*
|
|
832
|
+
* Returns the subdirectory name for a given group value.
|
|
833
|
+
* Defaults to `${camelCase(group)}Controller` for tags and the first path segment for paths.
|
|
856
834
|
*/
|
|
857
835
|
name?: (context: { group: string }) => string
|
|
858
836
|
}
|
|
859
837
|
|
|
860
838
|
export type Group = {
|
|
861
839
|
/**
|
|
862
|
-
*
|
|
863
|
-
* - 'tag' groups files by OpenAPI tags.
|
|
864
|
-
* - 'path' groups files by OpenAPI paths.
|
|
865
|
-
* @default undefined
|
|
840
|
+
* Determines how files are grouped into subdirectories.
|
|
841
|
+
* - `'tag'` groups files by OpenAPI tags.
|
|
842
|
+
* - `'path'` groups files by OpenAPI paths.
|
|
866
843
|
*/
|
|
867
844
|
type: 'tag' | 'path'
|
|
868
845
|
/**
|
|
869
|
-
*
|
|
846
|
+
* Returns the subdirectory name for a given group value.
|
|
870
847
|
*/
|
|
871
848
|
name: (context: { group: string }) => string
|
|
872
849
|
}
|
|
@@ -881,7 +858,7 @@ export type LoggerOptions = {
|
|
|
881
858
|
/**
|
|
882
859
|
* Shared context passed to all plugins, parsers, and other internals.
|
|
883
860
|
*/
|
|
884
|
-
export type LoggerContext = AsyncEventEmitter<
|
|
861
|
+
export type LoggerContext = AsyncEventEmitter<KubbHooks>
|
|
885
862
|
|
|
886
863
|
export type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
|
|
887
864
|
name: string
|
|
@@ -899,46 +876,84 @@ export type CompatibilityPreset = 'default' | 'kubbV4'
|
|
|
899
876
|
|
|
900
877
|
export type { Storage } from './createStorage.ts'
|
|
901
878
|
export type { Generator } from './defineGenerator.ts'
|
|
902
|
-
export type {
|
|
879
|
+
export type { HookStylePlugin, PluginHooks } from './definePlugin.ts'
|
|
880
|
+
export type { Kubb, KubbHooks } from './Kubb.ts'
|
|
903
881
|
|
|
904
882
|
/**
|
|
905
|
-
*
|
|
906
|
-
*
|
|
907
|
-
*
|
|
908
|
-
* @template TResolver - The concrete resolver type for this preset.
|
|
883
|
+
* Context passed to a hook-style plugin's `kubb:plugin:setup` handler.
|
|
884
|
+
* Provides methods to register generators, configure the resolver, transformer,
|
|
885
|
+
* and renderer, as well as access to the current build configuration.
|
|
909
886
|
*/
|
|
910
|
-
export type
|
|
887
|
+
export type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
911
888
|
/**
|
|
912
|
-
*
|
|
889
|
+
* Register a generator on this plugin. Generators are invoked during the AST walk
|
|
890
|
+
* (schema/operation/operations) exactly like generators declared statically on `createPlugin`.
|
|
913
891
|
*/
|
|
914
|
-
|
|
892
|
+
addGenerator<TElement = unknown>(generator: Generator<TFactory, TElement>): void
|
|
915
893
|
/**
|
|
916
|
-
*
|
|
894
|
+
* Set or partially override the resolver for this plugin.
|
|
895
|
+
* The resolver controls file naming and path resolution for generated files.
|
|
896
|
+
*
|
|
897
|
+
* When `TFactory` is a concrete `PluginFactoryOptions` (e.g. `PluginClient`),
|
|
898
|
+
* the resolver parameter is typed to the plugin's own resolver type (e.g. `ResolverClient`).
|
|
917
899
|
*/
|
|
918
|
-
resolver:
|
|
900
|
+
setResolver(resolver: Partial<TFactory['resolver']>): void
|
|
919
901
|
/**
|
|
920
|
-
*
|
|
902
|
+
* Set the AST transformer (visitor) for this plugin.
|
|
903
|
+
* The transformer pre-processes nodes before they reach the generators.
|
|
921
904
|
*/
|
|
922
|
-
|
|
905
|
+
setTransformer(visitor: Visitor): void
|
|
923
906
|
/**
|
|
924
|
-
*
|
|
925
|
-
* to
|
|
907
|
+
* Set the renderer factory for this plugin.
|
|
908
|
+
* Used to process JSX elements returned by generators.
|
|
926
909
|
*/
|
|
927
|
-
|
|
910
|
+
setRenderer(renderer: RendererFactory): void
|
|
911
|
+
/**
|
|
912
|
+
* Set the resolved options for the build loop. These options are merged into the
|
|
913
|
+
* normalized plugin's `options` object (which includes `output`, `exclude`, `override`).
|
|
914
|
+
*
|
|
915
|
+
* Call this in `kubb:plugin:setup` to provide the resolved options that generators
|
|
916
|
+
* and the build loop need (e.g., `enumType`, `optionalType`, `group`).
|
|
917
|
+
*/
|
|
918
|
+
setOptions(options: TFactory['resolvedOptions']): void
|
|
919
|
+
/**
|
|
920
|
+
* Inject a raw file into the build output, bypassing the normal generation pipeline.
|
|
921
|
+
*/
|
|
922
|
+
injectFile(file: Pick<FileNode, 'baseName' | 'path'> & { sources?: FileNode['sources'] }): void
|
|
928
923
|
/**
|
|
929
|
-
*
|
|
930
|
-
* The generator calls this function at render-time to produce a configured printer instance.
|
|
924
|
+
* Merge a partial config update into the current build configuration.
|
|
931
925
|
*/
|
|
932
|
-
|
|
926
|
+
updateConfig(config: Partial<Config>): void
|
|
927
|
+
/**
|
|
928
|
+
* The resolved build configuration at the time of setup.
|
|
929
|
+
*/
|
|
930
|
+
config: Config
|
|
931
|
+
/**
|
|
932
|
+
* The plugin's own options as passed by the user.
|
|
933
|
+
*/
|
|
934
|
+
options: TFactory['options']
|
|
933
935
|
}
|
|
934
936
|
|
|
935
937
|
/**
|
|
936
|
-
*
|
|
937
|
-
*
|
|
938
|
-
|
|
939
|
-
|
|
938
|
+
* Context passed to a hook-style plugin's `kubb:build:start` handler.
|
|
939
|
+
* Fires immediately before the plugin execution loop begins.
|
|
940
|
+
*/
|
|
941
|
+
export type KubbBuildStartContext = {
|
|
942
|
+
config: Config
|
|
943
|
+
adapter: Adapter
|
|
944
|
+
inputNode: InputNode
|
|
945
|
+
getPlugin(name: string): Plugin | undefined
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* Context passed to a hook-style plugin's `kubb:build:end` handler.
|
|
950
|
+
* Fires after all files have been written to disk.
|
|
940
951
|
*/
|
|
941
|
-
export type
|
|
952
|
+
export type KubbBuildEndContext = {
|
|
953
|
+
files: Array<FileNode>
|
|
954
|
+
config: Config
|
|
955
|
+
outputDir: string
|
|
956
|
+
}
|
|
942
957
|
|
|
943
958
|
type ByTag = {
|
|
944
959
|
type: 'tag'
|
|
@@ -975,9 +990,22 @@ type ByContentType = {
|
|
|
975
990
|
pattern: string | RegExp
|
|
976
991
|
}
|
|
977
992
|
|
|
993
|
+
/**
|
|
994
|
+
* A pattern filter that prevents matching nodes from being generated.
|
|
995
|
+
* Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
|
|
996
|
+
*/
|
|
978
997
|
export type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* A pattern filter that restricts generation to only matching nodes.
|
|
1001
|
+
* Match by `tag`, `operationId`, `path`, `method`, `contentType`, or `schemaName`.
|
|
1002
|
+
*/
|
|
979
1003
|
export type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
|
|
980
1004
|
|
|
1005
|
+
/**
|
|
1006
|
+
* A pattern filter paired with partial option overrides applied when the pattern matches.
|
|
1007
|
+
* Match by `tag`, `operationId`, `path`, `method`, `schemaName`, or `contentType`.
|
|
1008
|
+
*/
|
|
981
1009
|
export type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
982
1010
|
//TODO should be options: Omit<Partial<TOptions>, 'override'>
|
|
983
1011
|
options: Partial<TOptions>
|
|
@@ -1090,7 +1118,44 @@ export type ResolveBannerContext = {
|
|
|
1090
1118
|
config: Config
|
|
1091
1119
|
}
|
|
1092
1120
|
|
|
1093
|
-
|
|
1121
|
+
/**
|
|
1122
|
+
* CLI options derived from command-line flags.
|
|
1123
|
+
*/
|
|
1124
|
+
export type CLIOptions = {
|
|
1125
|
+
/**
|
|
1126
|
+
* Path to `kubb.config.js`.
|
|
1127
|
+
*/
|
|
1128
|
+
config?: string
|
|
1129
|
+
/**
|
|
1130
|
+
* Enable watch mode for input files.
|
|
1131
|
+
*/
|
|
1132
|
+
watch?: boolean
|
|
1133
|
+
/**
|
|
1134
|
+
* Logging verbosity for CLI usage.
|
|
1135
|
+
* @default 'silent'
|
|
1136
|
+
*/
|
|
1137
|
+
logLevel?: 'silent' | 'info' | 'debug'
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
/**
|
|
1141
|
+
* All accepted forms of a Kubb configuration.
|
|
1142
|
+
*
|
|
1143
|
+
* Config is always `@kubb/core` {@link Config}.
|
|
1144
|
+
* - `PossibleConfig` accepts `Config`/`Config[]`/promise or a no-arg config factory.
|
|
1145
|
+
* - `PossibleConfig<TCliOptions>` accepts the same config forms or a config factory receiving `TCliOptions`.
|
|
1146
|
+
*/
|
|
1147
|
+
export type PossibleConfig<TCliOptions = undefined> =
|
|
1148
|
+
| PossiblePromise<Config | Config[]>
|
|
1149
|
+
| ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Config[]>)
|
|
1150
|
+
|
|
1151
|
+
/**
|
|
1152
|
+
* All accepted forms of a Kubb configuration.
|
|
1153
|
+
* @deprecated
|
|
1154
|
+
* Kept for backward compatibility. Prefer `PossibleConfig<CLIOptions>` in new code.
|
|
1155
|
+
*/
|
|
1156
|
+
export type ConfigInput = PossibleConfig<CLIOptions>
|
|
1157
|
+
|
|
1158
|
+
export type { BuildOutput } from './createKubb.ts'
|
|
1094
1159
|
export type { Parser } from './defineParser.ts'
|
|
1095
1160
|
export type { FunctionParamsAST } from './utils/FunctionParams.ts'
|
|
1096
1161
|
export type { FileMetaBase } from './utils/getBarrelFiles.ts'
|