@kubb/core 5.0.0-beta.6 → 5.0.0-beta.60
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/LICENSE +17 -10
- package/README.md +25 -158
- package/dist/diagnostics-B-UZnFqP.d.ts +2906 -0
- package/dist/index.cjs +2497 -1071
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +80 -273
- package/dist/index.js +2487 -1067
- package/dist/index.js.map +1 -1
- package/dist/memoryStorage-CUj1hrxa.cjs +823 -0
- package/dist/memoryStorage-CUj1hrxa.cjs.map +1 -0
- package/dist/memoryStorage-CWFzAz4o.js +714 -0
- package/dist/memoryStorage-CWFzAz4o.js.map +1 -0
- package/dist/mocks.cjs +79 -19
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.ts +35 -9
- package/dist/mocks.js +80 -22
- package/dist/mocks.js.map +1 -1
- package/package.json +8 -28
- package/src/FileManager.ts +86 -64
- package/src/FileProcessor.ts +170 -44
- package/src/KubbDriver.ts +908 -0
- package/src/Transform.ts +75 -0
- package/src/constants.ts +111 -20
- package/src/createAdapter.ts +112 -17
- package/src/createKubb.ts +140 -517
- package/src/createRenderer.ts +43 -28
- package/src/createReporter.ts +134 -0
- package/src/createStorage.ts +36 -23
- package/src/defineGenerator.ts +147 -17
- package/src/defineParser.ts +30 -12
- package/src/definePlugin.ts +370 -21
- package/src/defineResolver.ts +402 -212
- package/src/diagnostics.ts +662 -0
- package/src/index.ts +8 -8
- package/src/mocks.ts +91 -20
- package/src/reporters/cliReporter.ts +89 -0
- package/src/reporters/fileReporter.ts +103 -0
- package/src/reporters/jsonReporter.ts +20 -0
- package/src/reporters/report.ts +85 -0
- package/src/storages/fsStorage.ts +23 -55
- package/src/types.ts +411 -887
- package/dist/PluginDriver-BkTRD2H2.js +0 -946
- package/dist/PluginDriver-BkTRD2H2.js.map +0 -1
- package/dist/PluginDriver-Cadu4ORh.cjs +0 -1037
- package/dist/PluginDriver-Cadu4ORh.cjs.map +0 -1
- package/dist/types-DVPKmzw_.d.ts +0 -2159
- package/src/Kubb.ts +0 -300
- package/src/PluginDriver.ts +0 -426
- package/src/defineLogger.ts +0 -19
- package/src/defineMiddleware.ts +0 -62
- package/src/devtools.ts +0 -59
- package/src/renderNode.ts +0 -35
- package/src/utils/diagnostics.ts +0 -18
- package/src/utils/isInputPath.ts +0 -10
- package/src/utils/packageJSON.ts +0 -99
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
package/src/types.ts
CHANGED
|
@@ -1,31 +1,26 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { FileNode,
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
1
|
+
import type { PossiblePromise } from '@internals/utils'
|
|
2
|
+
import type { FileNode, InputMeta, OperationNode, SchemaNode } from '@kubb/ast'
|
|
3
|
+
import type { Adapter } from './createAdapter.ts'
|
|
4
|
+
import type { Reporter, ReporterName } from './createReporter.ts'
|
|
5
5
|
import type { Storage } from './createStorage.ts'
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
6
|
+
import type { Diagnostic, ProblemDiagnostic, UpdateDiagnostic } from './diagnostics.ts'
|
|
7
|
+
import type { GeneratorContext } from './defineGenerator.ts'
|
|
8
8
|
import type { Parser } from './defineParser.ts'
|
|
9
|
-
import type { Plugin } from './definePlugin.ts'
|
|
10
|
-
import type {
|
|
11
|
-
import type { PluginDriver } from './PluginDriver.ts'
|
|
12
|
-
|
|
13
|
-
export type { Renderer, RendererFactory } from './createRenderer.ts'
|
|
9
|
+
import type { KubbPluginEndContext, KubbPluginSetupContext, KubbPluginStartContext, Plugin } from './definePlugin.ts'
|
|
10
|
+
import type { KubbDriver } from './KubbDriver.ts'
|
|
14
11
|
|
|
15
12
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* without
|
|
13
|
+
* Extracts a type from a registry, falling back to `{}` when the key doesn't exist.
|
|
14
|
+
* Lets plugins augment `Kubb.ConfigOptionsRegistry` and `Kubb.PluginOptionsRegistry`
|
|
15
|
+
* without changing core.
|
|
19
16
|
*
|
|
20
17
|
* @internal
|
|
21
18
|
*/
|
|
22
19
|
type ExtractRegistryKey<T, K extends PropertyKey> = K extends keyof T ? T[K] : {}
|
|
23
20
|
|
|
24
21
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* Specify an absolute path or a path relative to the config file location.
|
|
28
|
-
* The adapter will parse this file (e.g., OpenAPI YAML or JSON) into the universal AST.
|
|
22
|
+
* Path to an input file to generate from, absolute or relative to the config file. The adapter
|
|
23
|
+
* parses it (e.g. an OpenAPI YAML or JSON spec) into the universal AST.
|
|
29
24
|
*/
|
|
30
25
|
export type InputPath = {
|
|
31
26
|
/**
|
|
@@ -41,10 +36,8 @@ export type InputPath = {
|
|
|
41
36
|
}
|
|
42
37
|
|
|
43
38
|
/**
|
|
44
|
-
* Inline
|
|
45
|
-
*
|
|
46
|
-
* Useful when you want to pass the specification directly instead of from a file.
|
|
47
|
-
* Can be a string (YAML/JSON) or a parsed object.
|
|
39
|
+
* Inline spec to generate from, passed directly instead of read from a file. A string
|
|
40
|
+
* (YAML/JSON) or a parsed object.
|
|
48
41
|
*/
|
|
49
42
|
export type InputData = {
|
|
50
43
|
/**
|
|
@@ -62,98 +55,9 @@ export type InputData = {
|
|
|
62
55
|
type Input = InputPath | InputData
|
|
63
56
|
|
|
64
57
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
export type AdapterSource = { type: 'path'; path: string } | { type: 'data'; data: string | unknown } | { type: 'paths'; paths: Array<string> }
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Generic type parameters for an adapter definition.
|
|
72
|
-
*
|
|
73
|
-
* - `TName` — unique identifier (e.g. `'oas'`, `'asyncapi'`)
|
|
74
|
-
* - `TOptions` — user-facing options passed to the adapter factory
|
|
75
|
-
* - `TResolvedOptions` — options after defaults applied
|
|
76
|
-
* - `TDocument` — type of the parsed source document
|
|
77
|
-
*/
|
|
78
|
-
export type AdapterFactoryOptions<
|
|
79
|
-
TName extends string = string,
|
|
80
|
-
TOptions extends object = object,
|
|
81
|
-
TResolvedOptions extends object = TOptions,
|
|
82
|
-
TDocument = unknown,
|
|
83
|
-
> = {
|
|
84
|
-
name: TName
|
|
85
|
-
options: TOptions
|
|
86
|
-
resolvedOptions: TResolvedOptions
|
|
87
|
-
document: TDocument
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Adapter that converts input files or data into an `InputNode`.
|
|
92
|
-
*
|
|
93
|
-
* Adapters parse different schema formats (OpenAPI, AsyncAPI, Drizzle, etc.) into Kubb's
|
|
94
|
-
* universal intermediate representation that all plugins consume.
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* ```ts
|
|
98
|
-
* import { adapterOas } from '@kubb/adapter-oas'
|
|
99
|
-
*
|
|
100
|
-
* export default defineConfig({
|
|
101
|
-
* adapter: adapterOas(),
|
|
102
|
-
* input: { path: './openapi.yaml' },
|
|
103
|
-
* plugins: [pluginTs(), pluginZod()],
|
|
104
|
-
* })
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
export type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
|
|
108
|
-
/**
|
|
109
|
-
* Human-readable adapter identifier (e.g. `'oas'`, `'asyncapi'`).
|
|
110
|
-
*/
|
|
111
|
-
name: TOptions['name']
|
|
112
|
-
/**
|
|
113
|
-
* Resolved adapter options after defaults have been applied.
|
|
114
|
-
*/
|
|
115
|
-
options: TOptions['resolvedOptions']
|
|
116
|
-
/**
|
|
117
|
-
* Parsed source document after the first `parse()` call. `null` before parsing.
|
|
118
|
-
*/
|
|
119
|
-
document: TOptions['document'] | null
|
|
120
|
-
inputNode: InputNode | null
|
|
121
|
-
/**
|
|
122
|
-
* Parse the source into a universal `InputNode`.
|
|
123
|
-
*/
|
|
124
|
-
parse: (source: AdapterSource) => PossiblePromise<InputNode>
|
|
125
|
-
/**
|
|
126
|
-
* Extract `ImportNode` entries for a schema tree.
|
|
127
|
-
* Returns an empty array before the first `parse()` call.
|
|
128
|
-
*
|
|
129
|
-
* The `resolve` callback receives the collision-corrected schema name and must
|
|
130
|
-
* return `{ name, path }` for the import, or `undefined` to skip it.
|
|
131
|
-
*/
|
|
132
|
-
getImports: (node: SchemaNode, resolve: (schemaName: string) => { name: string; path: string }) => Array<ImportNode>
|
|
133
|
-
/**
|
|
134
|
-
* Validate the document at the given path or URL.
|
|
135
|
-
*/
|
|
136
|
-
validate: (input: string, options?: { throwOnError?: boolean }) => Promise<void>
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export type DevtoolsOptions = {
|
|
140
|
-
/**
|
|
141
|
-
* Open the AST inspector in Kubb Studio (`/ast`). Defaults to the main Studio page.
|
|
142
|
-
* @default false
|
|
143
|
-
*/
|
|
144
|
-
ast?: boolean
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Build configuration for Kubb code generation.
|
|
149
|
-
*
|
|
150
|
-
* The Config is the main entry point for customizing how Kubb generates code. It specifies:
|
|
151
|
-
* - What to generate from (adapter + input)
|
|
152
|
-
* - Where to output generated code (output)
|
|
153
|
-
* - How to generate (plugins + middleware)
|
|
154
|
-
* - Runtime details (parsers, storage, renderer)
|
|
155
|
-
*
|
|
156
|
-
* See `UserConfig` for a relaxed version with sensible defaults.
|
|
58
|
+
* Resolved build configuration for a Kubb run: what to generate from (adapter, input), where to
|
|
59
|
+
* write it (output), how (plugins), and the runtime pieces (parsers, storage). See
|
|
60
|
+
* `UserConfig` for the relaxed form with defaults applied.
|
|
157
61
|
*
|
|
158
62
|
* @private
|
|
159
63
|
*/
|
|
@@ -169,28 +73,31 @@ export type Config<TInput = Input> = {
|
|
|
169
73
|
*/
|
|
170
74
|
name?: string
|
|
171
75
|
/**
|
|
172
|
-
* Project root directory, absolute or relative to the config file.
|
|
173
|
-
*
|
|
76
|
+
* Project root directory, absolute or relative to the config file. Already
|
|
77
|
+
* resolved on the `Config` instance (see `UserConfig` for the optional
|
|
78
|
+
* form that defaults to `process.cwd()`).
|
|
174
79
|
*/
|
|
175
80
|
root: string
|
|
176
81
|
/**
|
|
177
|
-
* Parsers that convert generated files
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
82
|
+
* Parsers that convert generated files into strings. Each parser handles a
|
|
83
|
+
* set of file extensions, and a fallback parser handles anything else.
|
|
84
|
+
*
|
|
85
|
+
* Already resolved on the `Config` instance (see `UserConfig` for the
|
|
86
|
+
* optional form that defaults to `[parserTs, parserTsx, parserMd]`).
|
|
181
87
|
*
|
|
182
|
-
* @default [parserTs] from `@kubb/parser-ts`
|
|
183
88
|
* @example
|
|
184
89
|
* ```ts
|
|
185
|
-
* import {
|
|
90
|
+
* import { defineConfig } from 'kubb'
|
|
91
|
+
* import { parserTs, parserTsx } from '@kubb/parser-ts'
|
|
92
|
+
*
|
|
186
93
|
* export default defineConfig({
|
|
187
|
-
* parsers: [parserTs,
|
|
94
|
+
* parsers: [parserTs, parserTsx],
|
|
188
95
|
* })
|
|
189
96
|
* ```
|
|
190
97
|
*/
|
|
191
98
|
parsers: Array<Parser>
|
|
192
99
|
/**
|
|
193
|
-
* Adapter that parses input files into the universal
|
|
100
|
+
* Adapter that parses input files into the universal AST representation.
|
|
194
101
|
* Use `@kubb/adapter-oas` for OpenAPI/Swagger or `@kubb/adapter-asyncapi` for other formats.
|
|
195
102
|
*
|
|
196
103
|
* When omitted, Kubb runs in plugin-only mode: `kubb:plugin:setup` fires and files
|
|
@@ -210,15 +117,13 @@ export type Config<TInput = Input> = {
|
|
|
210
117
|
/**
|
|
211
118
|
* Source file or data to generate code from.
|
|
212
119
|
* Use `input.path` for a file path or `input.data` for inline data.
|
|
213
|
-
* Required when an adapter is configured
|
|
120
|
+
* Required when an adapter is configured. Omit it when running in plugin-only mode.
|
|
214
121
|
*/
|
|
215
122
|
input?: TInput
|
|
216
123
|
output: {
|
|
217
124
|
/**
|
|
218
|
-
* Output directory for generated files, absolute or relative to `root`.
|
|
219
|
-
*
|
|
220
|
-
* All generated files will be written under this directory. Subdirectories can be created
|
|
221
|
-
* by plugins based on grouping strategy (by tag, path, etc.).
|
|
125
|
+
* Output directory for generated files, absolute or relative to `root`. Plugins can nest
|
|
126
|
+
* subdirectories under it by grouping strategy (tag, path).
|
|
222
127
|
*
|
|
223
128
|
* @example
|
|
224
129
|
* ```ts
|
|
@@ -229,12 +134,9 @@ export type Config<TInput = Input> = {
|
|
|
229
134
|
*/
|
|
230
135
|
path: string
|
|
231
136
|
/**
|
|
232
|
-
* Remove
|
|
233
|
-
*
|
|
234
|
-
* Useful to ensure old generated files aren't mixed with new ones.
|
|
235
|
-
* Set to `true` for fresh builds, `false` to preserve manual edits in output dir.
|
|
137
|
+
* Remove every file in the output directory before the build, so stale output isn't mixed
|
|
138
|
+
* with new files. Leave `false` to preserve manual edits in the output directory.
|
|
236
139
|
*
|
|
237
|
-
* @default false
|
|
238
140
|
* @example
|
|
239
141
|
* ```ts
|
|
240
142
|
* clean: true // wipes ./src/gen/* before generating
|
|
@@ -242,19 +144,9 @@ export type Config<TInput = Input> = {
|
|
|
242
144
|
*/
|
|
243
145
|
clean?: boolean
|
|
244
146
|
/**
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
* @default true
|
|
248
|
-
* @deprecated Use `storage` option to control where files are written instead.
|
|
249
|
-
*/
|
|
250
|
-
write?: boolean
|
|
251
|
-
/**
|
|
252
|
-
* Auto-format generated files after code generation completes.
|
|
253
|
-
*
|
|
254
|
-
* Applies a code formatter to all generated files. Use `'auto'` to detect which formatter
|
|
255
|
-
* is available on your system. Pass `false` to skip formatting (useful for CI or specific workflows).
|
|
147
|
+
* Format the generated files after generation. `'auto'` runs the first formatter it finds
|
|
148
|
+
* (oxfmt, biome, or prettier), a named tool forces that one, and `false` skips formatting.
|
|
256
149
|
*
|
|
257
|
-
* @default false
|
|
258
150
|
* @example
|
|
259
151
|
* ```ts
|
|
260
152
|
* format: 'auto' // auto-detect prettier, biome, or oxfmt
|
|
@@ -264,12 +156,9 @@ export type Config<TInput = Input> = {
|
|
|
264
156
|
*/
|
|
265
157
|
format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false
|
|
266
158
|
/**
|
|
267
|
-
*
|
|
159
|
+
* Lint the generated files after generation. `'auto'` runs the first linter it finds
|
|
160
|
+
* (oxlint, biome, or eslint), a named tool forces that one, and `false` skips linting.
|
|
268
161
|
*
|
|
269
|
-
* Analyzes all generated files for style/correctness issues. Use `'auto'` to detect which linter
|
|
270
|
-
* is available on your system. Pass `false` to skip linting.
|
|
271
|
-
*
|
|
272
|
-
* @default false
|
|
273
162
|
* @example
|
|
274
163
|
* ```ts
|
|
275
164
|
* lint: 'auto' // auto-detect oxlint, biome, or eslint
|
|
@@ -279,10 +168,8 @@ export type Config<TInput = Input> = {
|
|
|
279
168
|
*/
|
|
280
169
|
lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false
|
|
281
170
|
/**
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
* Useful when you want generated `.ts` imports to reference `.js` files or vice versa (e.g., for ESM dual packages).
|
|
285
|
-
* Keys are the original extension, values are the output extension. Use empty string `''` to omit extension.
|
|
171
|
+
* Rewrite import extensions in generated files, e.g. emit `.js` imports from `.ts` sources for
|
|
172
|
+
* ESM dual packages. Keys are the source extension, values the output, and `''` drops it.
|
|
286
173
|
*
|
|
287
174
|
* @default { '.ts': '.ts' }
|
|
288
175
|
* @example
|
|
@@ -293,10 +180,8 @@ export type Config<TInput = Input> = {
|
|
|
293
180
|
*/
|
|
294
181
|
extension?: Record<FileNode['extname'], FileNode['extname'] | ''>
|
|
295
182
|
/**
|
|
296
|
-
* Banner
|
|
297
|
-
*
|
|
298
|
-
* Useful for auto-generation notices or license headers. Choose a preset or write custom text.
|
|
299
|
-
* Use `'simple'` for a basic Kubb banner, `'full'` for detailed metadata, or `false` to omit.
|
|
183
|
+
* Banner prepended to every generated file. `'simple'` is the basic Kubb notice, `'full'` adds
|
|
184
|
+
* source, title, description, and API version, and `false` omits it.
|
|
300
185
|
*
|
|
301
186
|
* @default 'simple'
|
|
302
187
|
* @example
|
|
@@ -308,12 +193,9 @@ export type Config<TInput = Input> = {
|
|
|
308
193
|
*/
|
|
309
194
|
defaultBanner?: 'simple' | 'full' | false
|
|
310
195
|
/**
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
* Individual plugins can override this setting. This is useful for preventing accidental data loss
|
|
314
|
-
* when re-generating while you have local edits in the output folder.
|
|
196
|
+
* Overwrite existing files when `true`, skip files that already exist when `false`. Individual
|
|
197
|
+
* plugins can override it. Keep `false` to avoid clobbering local edits in the output folder.
|
|
315
198
|
*
|
|
316
|
-
* @default false
|
|
317
199
|
* @example
|
|
318
200
|
* ```ts
|
|
319
201
|
* override: true // regenerate everything, even existing files
|
|
@@ -323,10 +205,8 @@ export type Config<TInput = Input> = {
|
|
|
323
205
|
override?: boolean
|
|
324
206
|
} & ExtractRegistryKey<Kubb.ConfigOptionsRegistry, 'output'>
|
|
325
207
|
/**
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
* Defaults to `fsStorage()` which writes to the file system. Pass `memoryStorage()` to keep files in RAM,
|
|
329
|
-
* or implement a custom `Storage` interface to write to cloud storage, databases, or other backends.
|
|
208
|
+
* Where generated files are persisted. Defaults to `fsStorage()` (disk). Pass `memoryStorage()`
|
|
209
|
+
* to keep files in RAM, or implement `Storage` for a custom backend such as cloud or a database.
|
|
330
210
|
*
|
|
331
211
|
* @default fsStorage()
|
|
332
212
|
* @example
|
|
@@ -342,15 +222,11 @@ export type Config<TInput = Input> = {
|
|
|
342
222
|
*
|
|
343
223
|
* @see {@link Storage} interface for implementing custom backends.
|
|
344
224
|
*/
|
|
345
|
-
storage
|
|
225
|
+
storage: Storage
|
|
346
226
|
/**
|
|
347
|
-
* Plugins that
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
* programming languages or formats (TypeScript, Zod schemas, Faker data, etc.).
|
|
351
|
-
* Dependencies are enforced — an error is thrown if a plugin requires another plugin that isn't registered.
|
|
352
|
-
*
|
|
353
|
-
* Plugins can declare their own options via `PluginFactoryOptions`. See plugin documentation for details.
|
|
227
|
+
* Plugins that run during the build to generate code and transform the AST. Each one processes
|
|
228
|
+
* the adapter's AST and can emit files for a different target (TypeScript, Zod, Faker). A plugin
|
|
229
|
+
* that depends on another throws when that plugin isn't registered.
|
|
354
230
|
*
|
|
355
231
|
* @example
|
|
356
232
|
* ```ts
|
|
@@ -365,80 +241,9 @@ export type Config<TInput = Input> = {
|
|
|
365
241
|
*/
|
|
366
242
|
plugins: Array<Plugin>
|
|
367
243
|
/**
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
* Middleware fires AFTER all plugins for each event. Perfect for tasks like:
|
|
371
|
-
* - Auditing what was generated
|
|
372
|
-
* - Adding barrel/index files
|
|
373
|
-
* - Validating output
|
|
374
|
-
* - Running custom transformations
|
|
375
|
-
*
|
|
376
|
-
* @example
|
|
377
|
-
* ```ts
|
|
378
|
-
* import { middlewareBarrel } from '@kubb/middleware-barrel'
|
|
379
|
-
*
|
|
380
|
-
* middleware: [middlewareBarrel()]
|
|
381
|
-
* ```
|
|
382
|
-
*
|
|
383
|
-
* @see {@link defineMiddleware} to create custom middleware.
|
|
384
|
-
*/
|
|
385
|
-
middleware?: Array<Middleware>
|
|
386
|
-
/**
|
|
387
|
-
* Default renderer factory used by all plugins and generators.
|
|
388
|
-
* Resolution chain: `generator.renderer` → `plugin.renderer` → `config.renderer` → `undefined` (raw FileNode[] mode).
|
|
389
|
-
*
|
|
390
|
-
* @example
|
|
391
|
-
* ```ts
|
|
392
|
-
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
393
|
-
* export default defineConfig({
|
|
394
|
-
* renderer: jsxRenderer,
|
|
395
|
-
* plugins: [pluginTs(), pluginZod()],
|
|
396
|
-
* })
|
|
397
|
-
* ```
|
|
398
|
-
*/
|
|
399
|
-
/**
|
|
400
|
-
* Renderer that converts generated AST nodes to code strings.
|
|
244
|
+
* Lifecycle hooks that run external tools (prettier, eslint, a custom script) on build events.
|
|
401
245
|
*
|
|
402
|
-
*
|
|
403
|
-
* different output formats (template engines, code generation DSLs, etc.).
|
|
404
|
-
*
|
|
405
|
-
* @default rendererJsx() // from @kubb/renderer-jsx
|
|
406
|
-
* @example
|
|
407
|
-
* ```ts
|
|
408
|
-
* import { rendererJsx } from '@kubb/renderer-jsx'
|
|
409
|
-
* renderer: rendererJsx()
|
|
410
|
-
* ```
|
|
411
|
-
*
|
|
412
|
-
* @see {@link Renderer} to implement a custom renderer.
|
|
413
|
-
*/
|
|
414
|
-
renderer?: RendererFactory
|
|
415
|
-
/**
|
|
416
|
-
* Kubb Studio cloud integration settings.
|
|
417
|
-
*
|
|
418
|
-
* Kubb Studio (https://kubb.studio) is a web-based IDE for managing API specs and generated code.
|
|
419
|
-
* Set to `true` to enable with default settings, or pass an object to customize the Studio URL.
|
|
420
|
-
*
|
|
421
|
-
* @default false // disabled by default
|
|
422
|
-
* @example
|
|
423
|
-
* ```ts
|
|
424
|
-
* devtools: true // use default Kubb Studio
|
|
425
|
-
* devtools: { studioUrl: 'https://my-studio.dev' } // custom Studio instance
|
|
426
|
-
* ```
|
|
427
|
-
*/
|
|
428
|
-
devtools?:
|
|
429
|
-
| true
|
|
430
|
-
| {
|
|
431
|
-
/**
|
|
432
|
-
* Override the Kubb Studio base URL.
|
|
433
|
-
* @default 'https://kubb.studio'
|
|
434
|
-
*/
|
|
435
|
-
studioUrl?: typeof DEFAULT_STUDIO_URL | (string & {})
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Lifecycle hooks that execute during or after the build process.
|
|
439
|
-
*
|
|
440
|
-
* Hooks allow you to run external tools (prettier, eslint, custom scripts) based on build events.
|
|
441
|
-
* Currently supports the `done` hook which fires after all plugins and middleware complete.
|
|
246
|
+
* Currently supports the `done` hook, which fires after all plugins complete.
|
|
442
247
|
*
|
|
443
248
|
* @example
|
|
444
249
|
* ```ts
|
|
@@ -451,11 +256,10 @@ export type Config<TInput = Input> = {
|
|
|
451
256
|
*/
|
|
452
257
|
hooks?: {
|
|
453
258
|
/**
|
|
454
|
-
* Command(s) to run after all plugins
|
|
259
|
+
* Command(s) to run after all plugins finish generating, for post-processing the output.
|
|
455
260
|
*
|
|
456
|
-
*
|
|
457
|
-
*
|
|
458
|
-
* Commands are executed relative to the `root` directory.
|
|
261
|
+
* Pass a single command string, or an array to run them in sequence.
|
|
262
|
+
* Commands run relative to the `root` directory.
|
|
459
263
|
*
|
|
460
264
|
* @example
|
|
461
265
|
* ```ts
|
|
@@ -465,106 +269,24 @@ export type Config<TInput = Input> = {
|
|
|
465
269
|
*/
|
|
466
270
|
done?: string | Array<string>
|
|
467
271
|
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
// plugin
|
|
471
|
-
|
|
472
|
-
/**
|
|
473
|
-
* Type/string pattern filter for include/exclude/override matching.
|
|
474
|
-
*/
|
|
475
|
-
type PatternFilter = {
|
|
476
|
-
type: string
|
|
477
|
-
pattern: string | RegExp
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* Pattern filter with partial option overrides applied when the pattern matches.
|
|
482
|
-
*/
|
|
483
|
-
type PatternOverride<TOptions> = PatternFilter & {
|
|
484
|
-
options: Omit<Partial<TOptions>, 'override'>
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
/**
|
|
488
|
-
* Context for resolving filtered options for a given operation or schema node.
|
|
489
|
-
*
|
|
490
|
-
* @internal
|
|
491
|
-
*/
|
|
492
|
-
export type ResolveOptionsContext<TOptions> = {
|
|
493
|
-
options: TOptions
|
|
494
|
-
exclude?: Array<PatternFilter>
|
|
495
|
-
include?: Array<PatternFilter>
|
|
496
|
-
override?: Array<PatternOverride<TOptions>>
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Base constraint for all plugin resolver objects.
|
|
501
|
-
*
|
|
502
|
-
* `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`
|
|
503
|
-
* are injected automatically by `defineResolver` — extend this type to add custom resolution methods.
|
|
504
|
-
*
|
|
505
|
-
* @example
|
|
506
|
-
* ```ts
|
|
507
|
-
* type MyResolver = Resolver & {
|
|
508
|
-
* resolveName(node: SchemaNode): string
|
|
509
|
-
* resolveTypedName(node: SchemaNode): string
|
|
510
|
-
* }
|
|
511
|
-
* ```
|
|
512
|
-
*/
|
|
513
|
-
export type Resolver = {
|
|
514
|
-
name: string
|
|
515
|
-
pluginName: Plugin['name']
|
|
516
|
-
default(name: string, type?: 'file' | 'function' | 'type' | 'const'): string
|
|
517
|
-
resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null
|
|
518
|
-
resolvePath(params: ResolverPathParams, context: ResolverContext): string
|
|
519
|
-
resolveFile(params: ResolverFileParams, context: ResolverContext): FileNode
|
|
520
|
-
resolveBanner(node: InputNode | null, context: ResolveBannerContext): string | undefined
|
|
521
|
-
resolveFooter(node: InputNode | null, context: ResolveBannerContext): string | undefined
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
export type PluginFactoryOptions<
|
|
525
|
-
/**
|
|
526
|
-
* Unique plugin name.
|
|
527
|
-
*/
|
|
528
|
-
TName extends string = string,
|
|
529
|
-
/**
|
|
530
|
-
* User-facing plugin options.
|
|
531
|
-
*/
|
|
532
|
-
TOptions extends object = object,
|
|
533
|
-
/**
|
|
534
|
-
* Plugin options after defaults are applied.
|
|
535
|
-
*/
|
|
536
|
-
TResolvedOptions extends object = TOptions,
|
|
537
272
|
/**
|
|
538
|
-
*
|
|
539
|
-
*
|
|
273
|
+
* The reporters available to the run, registered as instances. The host
|
|
274
|
+
* (the CLI via `--reporter`) selects which ones to trigger by `name` with {@link selectReporters}.
|
|
275
|
+
* `defineConfig` from the `kubb` package registers the built-in `cli`, `json`, and `file`
|
|
276
|
+
* reporters by default.
|
|
277
|
+
*
|
|
278
|
+
* - `cli` writes the end-of-run summary to the terminal.
|
|
279
|
+
* - `json` writes a machine-readable report to stdout, for CI.
|
|
280
|
+
* - `file` writes a debug log to `.kubb/<name>-<timestamp>.log`.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```ts
|
|
284
|
+
* import { cliReporter, jsonReporter } from '@kubb/core'
|
|
285
|
+
*
|
|
286
|
+
* reporters: [cliReporter, jsonReporter, myReporter]
|
|
287
|
+
* ```
|
|
540
288
|
*/
|
|
541
|
-
|
|
542
|
-
> = {
|
|
543
|
-
name: TName
|
|
544
|
-
options: TOptions
|
|
545
|
-
resolvedOptions: TResolvedOptions
|
|
546
|
-
resolver: TResolver
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
/**
|
|
550
|
-
* Normalized plugin after setup, with runtime fields populated.
|
|
551
|
-
* For internal use only — plugins use the public `Plugin` type externally.
|
|
552
|
-
*
|
|
553
|
-
* @internal
|
|
554
|
-
*/
|
|
555
|
-
export type NormalizedPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & {
|
|
556
|
-
options: TOptions['resolvedOptions'] & {
|
|
557
|
-
output: Output
|
|
558
|
-
include?: Array<Include>
|
|
559
|
-
exclude: Array<Exclude>
|
|
560
|
-
override: Array<Override<TOptions['resolvedOptions']>>
|
|
561
|
-
}
|
|
562
|
-
resolver: TOptions['resolver']
|
|
563
|
-
transformer?: Visitor
|
|
564
|
-
renderer?: RendererFactory
|
|
565
|
-
generators?: Array<Generator>
|
|
566
|
-
apply?: (config: Config) => boolean
|
|
567
|
-
version?: string
|
|
289
|
+
reporters: Array<Reporter>
|
|
568
290
|
}
|
|
569
291
|
|
|
570
292
|
/**
|
|
@@ -572,7 +294,7 @@ export type NormalizedPlugin<TOptions extends PluginFactoryOptions = PluginFacto
|
|
|
572
294
|
*
|
|
573
295
|
* `UserConfig` is what you pass to `defineConfig()`. It has optional `root`, `plugins`, `parsers`, and `adapter`
|
|
574
296
|
* fields (which fall back to sensible defaults). All other Config options are available, including `output`, `input`,
|
|
575
|
-
* `storage`,
|
|
297
|
+
* `storage`, and `hooks`.
|
|
576
298
|
*
|
|
577
299
|
* @example
|
|
578
300
|
* ```ts
|
|
@@ -583,723 +305,525 @@ export type NormalizedPlugin<TOptions extends PluginFactoryOptions = PluginFacto
|
|
|
583
305
|
* })
|
|
584
306
|
* ```
|
|
585
307
|
*/
|
|
586
|
-
export type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter'> & {
|
|
308
|
+
export type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter' | 'storage' | 'reporters'> & {
|
|
587
309
|
/**
|
|
588
310
|
* Project root directory, absolute or relative to the config file location.
|
|
589
|
-
*
|
|
590
|
-
* Used as the base path for `root`-relative paths (e.g., `output.path`, file paths in hooks).
|
|
591
|
-
*
|
|
592
311
|
* @default process.cwd()
|
|
593
|
-
* @example
|
|
594
|
-
* ```ts
|
|
595
|
-
* root: '/home/user/my-project'
|
|
596
|
-
* root: './my-project' // relative to config file
|
|
597
|
-
* ```
|
|
598
312
|
*/
|
|
599
313
|
root?: string
|
|
600
314
|
/**
|
|
601
315
|
* Custom parsers that convert generated AST nodes to strings (TypeScript, JSON, markdown, etc.).
|
|
602
|
-
*
|
|
603
|
-
* Each parser handles a specific file type. By default, Kubb uses `parserTs` from `@kubb/parser-ts` for TypeScript files.
|
|
604
|
-
* Pass custom parsers to support additional languages or custom formats.
|
|
605
|
-
*
|
|
606
|
-
* @default [parserTs] // from `@kubb/parser-ts`
|
|
607
|
-
* @example
|
|
608
|
-
* ```ts
|
|
609
|
-
* import { parserTs } from '@kubb/parser-ts'
|
|
610
|
-
* import { parserJsonSchema } from '@kubb/parser-json-schema'
|
|
611
|
-
*
|
|
612
|
-
* parsers: [parserTs(), parserJsonSchema()]
|
|
613
|
-
* ```
|
|
614
|
-
*
|
|
615
|
-
* @see {@link Parser} to implement a custom parser.
|
|
316
|
+
* @default [parserTs, parserTsx, parserMd] // applied by `defineConfig` from the `kubb` package
|
|
616
317
|
*/
|
|
617
318
|
parsers?: Array<Parser>
|
|
618
319
|
/**
|
|
619
|
-
* Adapter that parses your API specification
|
|
620
|
-
*
|
|
621
|
-
* Pass an adapter to support different spec formats. When omitted, Kubb runs in plugin-only mode —
|
|
622
|
-
* `kubb:plugin:setup` fires and `injectFile` works, but no AST walk occurs and generator hooks
|
|
623
|
-
* (`kubb:generate:schema`, `kubb:generate:operation`) are never emitted.
|
|
624
|
-
*
|
|
625
|
-
* @example
|
|
626
|
-
* ```ts
|
|
627
|
-
* import { adapterOas } from '@kubb/adapter-oas'
|
|
628
|
-
*
|
|
629
|
-
* adapter: adapterOas()
|
|
630
|
-
* ```
|
|
631
|
-
*
|
|
632
|
-
* @see {@link Adapter} to implement a custom adapter for GraphQL or other formats.
|
|
320
|
+
* Adapter that parses your API specification into Kubb's universal AST.
|
|
321
|
+
* When omitted, Kubb runs in plugin-only mode.
|
|
633
322
|
*/
|
|
634
323
|
adapter?: Adapter
|
|
635
324
|
/**
|
|
636
325
|
* Plugins that execute during the build to generate code and transform the AST.
|
|
637
|
-
*
|
|
638
|
-
* Each plugin processes the AST produced by the adapter and can emit files for different
|
|
639
|
-
* programming languages or formats (TypeScript, Zod schemas, Faker data, etc.).
|
|
640
|
-
*
|
|
641
|
-
* @default [] // no plugins (useful for setup/testing)
|
|
642
|
-
* @example
|
|
643
|
-
* ```ts
|
|
644
|
-
* plugins: [
|
|
645
|
-
* pluginTs({ output: { path: './src/gen' } }),
|
|
646
|
-
* pluginZod({ output: { path: './src/gen' } }),
|
|
647
|
-
* ]
|
|
648
|
-
* ```
|
|
649
|
-
*
|
|
650
|
-
* @see {@link definePlugin} to create a custom plugin.
|
|
326
|
+
* @default []
|
|
651
327
|
*/
|
|
652
328
|
plugins?: Array<Plugin>
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
export type ResolveNameParams = {
|
|
656
|
-
name: string
|
|
657
|
-
pluginName?: string
|
|
658
|
-
/**
|
|
659
|
-
* Entity type being named.
|
|
660
|
-
* - `'file'` — file name (camelCase)
|
|
661
|
-
* - `'function'` — exported function name (camelCase)
|
|
662
|
-
* - `'type'` — TypeScript type name (PascalCase)
|
|
663
|
-
* - `'const'` — variable name (camelCase)
|
|
664
|
-
*/
|
|
665
|
-
type?: 'file' | 'function' | 'type' | 'const'
|
|
666
|
-
}
|
|
667
|
-
/**
|
|
668
|
-
* Context object passed to generator `schema`, `operation`, and `operations` methods.
|
|
669
|
-
*
|
|
670
|
-
* The adapter is always defined (guaranteed by `runPluginAstHooks`) so no runtime checks
|
|
671
|
-
* are needed. `ctx.options` carries resolved per-node options after exclude/include/override
|
|
672
|
-
* filtering for individual schema/operation calls, or plugin-level options for operations.
|
|
673
|
-
*/
|
|
674
|
-
export type GeneratorContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
675
|
-
config: Config
|
|
676
329
|
/**
|
|
677
|
-
*
|
|
678
|
-
|
|
679
|
-
root: string
|
|
680
|
-
/**
|
|
681
|
-
* Determine output mode based on the output config.
|
|
682
|
-
* Returns `'single'` when `output.path` is a file, `'split'` for a directory.
|
|
683
|
-
*/
|
|
684
|
-
getMode: (output: { path: string }) => 'single' | 'split'
|
|
685
|
-
driver: PluginDriver
|
|
686
|
-
/**
|
|
687
|
-
* Get a plugin by name, typed via `Kubb.PluginRegistry` when registered.
|
|
688
|
-
*/
|
|
689
|
-
getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined
|
|
690
|
-
getPlugin(name: string): Plugin | undefined
|
|
691
|
-
/**
|
|
692
|
-
* Get a plugin by name, throws an error if not found.
|
|
693
|
-
*/
|
|
694
|
-
requirePlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]>
|
|
695
|
-
requirePlugin(name: string): Plugin
|
|
696
|
-
/**
|
|
697
|
-
* Get a resolver by plugin name, typed via `Kubb.PluginRegistry` when registered.
|
|
698
|
-
*/
|
|
699
|
-
getResolver<TName extends keyof Kubb.PluginRegistry>(name: TName): Kubb.PluginRegistry[TName]['resolver']
|
|
700
|
-
getResolver(name: string): Resolver
|
|
701
|
-
/**
|
|
702
|
-
* Add files only if they don't exist.
|
|
703
|
-
*/
|
|
704
|
-
addFile: (...file: Array<FileNode>) => Promise<void>
|
|
705
|
-
/**
|
|
706
|
-
* Merge sources into the same output file.
|
|
707
|
-
*/
|
|
708
|
-
upsertFile: (...file: Array<FileNode>) => Promise<void>
|
|
709
|
-
hooks: AsyncEventEmitter<KubbHooks>
|
|
710
|
-
/**
|
|
711
|
-
* The current plugin instance.
|
|
712
|
-
*/
|
|
713
|
-
plugin: Plugin<TOptions>
|
|
714
|
-
/**
|
|
715
|
-
* The current plugin's resolver.
|
|
716
|
-
*/
|
|
717
|
-
resolver: TOptions['resolver']
|
|
718
|
-
/**
|
|
719
|
-
* The current plugin's transformer.
|
|
720
|
-
*/
|
|
721
|
-
transformer: Visitor | undefined
|
|
722
|
-
/**
|
|
723
|
-
* Emit a warning.
|
|
724
|
-
*/
|
|
725
|
-
warn: (message: string) => void
|
|
726
|
-
/**
|
|
727
|
-
* Emit an error.
|
|
728
|
-
*/
|
|
729
|
-
error: (error: string | Error) => void
|
|
730
|
-
/**
|
|
731
|
-
* Emit an info message.
|
|
732
|
-
*/
|
|
733
|
-
info: (message: string) => void
|
|
734
|
-
/**
|
|
735
|
-
* Open the current input node in Kubb Studio.
|
|
736
|
-
*/
|
|
737
|
-
openInStudio: (options?: DevtoolsOptions) => Promise<void>
|
|
738
|
-
/**
|
|
739
|
-
* The configured adapter instance.
|
|
740
|
-
*/
|
|
741
|
-
adapter: Adapter
|
|
742
|
-
/**
|
|
743
|
-
* The universal `InputNode` produced by the adapter.
|
|
330
|
+
* Storage backend that controls where and how generated files are persisted.
|
|
331
|
+
* @default fsStorage()
|
|
744
332
|
*/
|
|
745
|
-
|
|
333
|
+
storage?: Storage
|
|
746
334
|
/**
|
|
747
|
-
*
|
|
335
|
+
* Reporters available to the run. `defineConfig` registers the built-in `cli`, `json`, and
|
|
336
|
+
* `file` reporters when omitted.
|
|
337
|
+
* @default [cliReporter, jsonReporter, fileReporter] // applied by `defineConfig` from the `kubb` package
|
|
748
338
|
*/
|
|
749
|
-
|
|
339
|
+
reporters?: Array<Reporter>
|
|
750
340
|
}
|
|
751
|
-
/**
|
|
752
|
-
* Output configuration for generated files.
|
|
753
|
-
*/
|
|
754
|
-
export type Output<_TOptions = unknown> = {
|
|
755
|
-
/**
|
|
756
|
-
* Output folder or file path for generated code.
|
|
757
|
-
*/
|
|
758
|
-
path: string
|
|
759
|
-
/**
|
|
760
|
-
* Text or function prepended to every generated file.
|
|
761
|
-
* When a function, receives the current `InputNode` and returns a string.
|
|
762
|
-
*/
|
|
763
|
-
banner?: string | ((node?: InputNode) => string)
|
|
764
|
-
/**
|
|
765
|
-
* Text or function appended to every generated file.
|
|
766
|
-
* When a function, receives the current `InputNode` and returns a string.
|
|
767
|
-
*/
|
|
768
|
-
footer?: string | ((node?: InputNode) => string)
|
|
769
|
-
/**
|
|
770
|
-
* Whether to override existing external files if they already exist.
|
|
771
|
-
* @default false
|
|
772
|
-
*/
|
|
773
|
-
override?: boolean
|
|
774
|
-
} & ExtractRegistryKey<Kubb.PluginOptionsRegistry, 'output'>
|
|
775
341
|
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
342
|
+
declare global {
|
|
343
|
+
namespace Kubb {
|
|
344
|
+
/**
|
|
345
|
+
* Registry that maps plugin names to their `PluginFactoryOptions`.
|
|
346
|
+
* Augment this interface in each plugin's `types.ts` to enable automatic
|
|
347
|
+
* typing for `getPlugin` and `requirePlugin`.
|
|
348
|
+
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```ts
|
|
351
|
+
* // packages/plugin-ts/src/types.ts
|
|
352
|
+
* declare global {
|
|
353
|
+
* namespace Kubb {
|
|
354
|
+
* interface PluginRegistry {
|
|
355
|
+
* 'plugin-ts': PluginTs
|
|
356
|
+
* }
|
|
357
|
+
* }
|
|
358
|
+
* }
|
|
359
|
+
* ```
|
|
360
|
+
*/
|
|
361
|
+
interface PluginRegistry {}
|
|
789
362
|
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
363
|
+
/**
|
|
364
|
+
* Extension point for root `Config['output']` options.
|
|
365
|
+
* Augment the `output` key in plugin packages to add extra fields
|
|
366
|
+
* to the global output configuration without touching core types.
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```ts
|
|
370
|
+
* // packages/plugin-barrel/src/plugin.ts
|
|
371
|
+
* declare global {
|
|
372
|
+
* namespace Kubb {
|
|
373
|
+
* interface ConfigOptionsRegistry {
|
|
374
|
+
* output: {
|
|
375
|
+
* barrel?: import('./types.ts').BarrelConfig | false
|
|
376
|
+
* }
|
|
377
|
+
* }
|
|
378
|
+
* }
|
|
379
|
+
* }
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
interface ConfigOptionsRegistry {}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Extension point for per-plugin `Output` options.
|
|
386
|
+
* Augment the `output` key in plugin packages to add extra fields
|
|
387
|
+
* to the per-plugin output configuration without touching core types.
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```ts
|
|
391
|
+
* // packages/plugin-barrel/src/plugin.ts
|
|
392
|
+
* declare global {
|
|
393
|
+
* namespace Kubb {
|
|
394
|
+
* interface PluginOptionsRegistry {
|
|
395
|
+
* output: {
|
|
396
|
+
* barrel?: import('./types.ts').PluginBarrelConfig | false
|
|
397
|
+
* }
|
|
398
|
+
* }
|
|
399
|
+
* }
|
|
400
|
+
* }
|
|
401
|
+
* ```
|
|
402
|
+
*/
|
|
403
|
+
interface PluginOptionsRegistry {}
|
|
404
|
+
}
|
|
796
405
|
}
|
|
797
406
|
|
|
798
407
|
/**
|
|
799
|
-
*
|
|
408
|
+
* Lifecycle events emitted during Kubb code generation.
|
|
409
|
+
* Attach listeners before calling `setup()` or `build()` to observe and react to build progress.
|
|
410
|
+
*
|
|
411
|
+
* @example
|
|
412
|
+
* ```ts
|
|
413
|
+
* kubb.hooks.on('kubb:lifecycle:start', () => {
|
|
414
|
+
* console.log('Starting Kubb generation')
|
|
415
|
+
* })
|
|
416
|
+
*
|
|
417
|
+
* kubb.hooks.on('kubb:plugin:end', ({ plugin, duration }) => {
|
|
418
|
+
* console.log(`${plugin.name} completed in ${duration}ms`)
|
|
419
|
+
* })
|
|
420
|
+
* ```
|
|
800
421
|
*/
|
|
801
|
-
export
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
422
|
+
export interface KubbHooks {
|
|
423
|
+
'kubb:lifecycle:start': [ctx: KubbLifecycleStartContext]
|
|
424
|
+
'kubb:lifecycle:end': []
|
|
425
|
+
'kubb:generation:start': [ctx: KubbGenerationStartContext]
|
|
426
|
+
'kubb:generation:end': [ctx: KubbGenerationEndContext]
|
|
427
|
+
'kubb:format:start': []
|
|
428
|
+
'kubb:format:end': []
|
|
429
|
+
'kubb:lint:start': []
|
|
430
|
+
'kubb:lint:end': []
|
|
431
|
+
'kubb:hooks:start': []
|
|
432
|
+
'kubb:hooks:end': []
|
|
433
|
+
'kubb:hook:start': [ctx: KubbHookStartContext]
|
|
434
|
+
'kubb:hook:line': [ctx: KubbHookLineContext]
|
|
435
|
+
'kubb:hook:end': [ctx: KubbHookEndContext]
|
|
436
|
+
'kubb:info': [ctx: KubbInfoContext]
|
|
437
|
+
'kubb:error': [ctx: KubbErrorContext]
|
|
438
|
+
'kubb:success': [ctx: KubbSuccessContext]
|
|
439
|
+
'kubb:warn': [ctx: KubbWarnContext]
|
|
440
|
+
'kubb:diagnostic': [ctx: KubbDiagnosticContext]
|
|
441
|
+
'kubb:files:processing:start': [ctx: KubbFilesProcessingStartContext]
|
|
442
|
+
'kubb:files:processing:update': [ctx: KubbFilesProcessingUpdateContext]
|
|
443
|
+
'kubb:files:processing:end': [ctx: KubbFilesProcessingEndContext]
|
|
444
|
+
'kubb:plugin:start': [ctx: KubbPluginStartContext]
|
|
445
|
+
'kubb:plugin:end': [ctx: KubbPluginEndContext]
|
|
446
|
+
'kubb:plugin:setup': [ctx: KubbPluginSetupContext]
|
|
447
|
+
'kubb:build:start': [ctx: KubbBuildStartContext]
|
|
448
|
+
'kubb:plugins:end': [ctx: KubbPluginsEndContext]
|
|
449
|
+
'kubb:build:end': [ctx: KubbBuildEndContext]
|
|
450
|
+
'kubb:generate:schema': [node: SchemaNode, ctx: GeneratorContext]
|
|
451
|
+
'kubb:generate:operation': [node: OperationNode, ctx: GeneratorContext]
|
|
452
|
+
'kubb:generate:operations': [nodes: Array<OperationNode>, ctx: GeneratorContext]
|
|
806
453
|
}
|
|
807
454
|
|
|
808
|
-
export type
|
|
809
|
-
|
|
810
|
-
export type { Storage } from './createStorage.ts'
|
|
811
|
-
export type { Generator } from './defineGenerator.ts'
|
|
812
|
-
export type { Middleware } from './defineMiddleware.ts'
|
|
813
|
-
export type { Plugin } from './definePlugin.ts'
|
|
814
|
-
export type { Kubb, KubbHooks } from './Kubb.ts'
|
|
815
|
-
|
|
816
|
-
/**
|
|
817
|
-
* Context for hook-style plugin `kubb:plugin:setup` handler.
|
|
818
|
-
* Provides methods to register generators, configure resolvers, transformers, and renderers.
|
|
819
|
-
*/
|
|
820
|
-
export type KubbPluginSetupContext<TFactory extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
821
|
-
/**
|
|
822
|
-
* Register a generator dynamically. Generators fire during the AST walk (schema/operation/operations)
|
|
823
|
-
* just like generators declared statically on `createPlugin`.
|
|
824
|
-
*/
|
|
825
|
-
addGenerator<TElement = unknown>(generator: Generator<TFactory, TElement>): void
|
|
826
|
-
/**
|
|
827
|
-
* Set or override the resolver for this plugin.
|
|
828
|
-
* The resolver controls file naming and path resolution.
|
|
829
|
-
*/
|
|
830
|
-
setResolver(resolver: Partial<TFactory['resolver']>): void
|
|
831
|
-
/**
|
|
832
|
-
* Set the AST transformer to pre-process nodes before they reach generators.
|
|
833
|
-
*/
|
|
834
|
-
setTransformer(visitor: Visitor): void
|
|
835
|
-
/**
|
|
836
|
-
* Set the renderer factory to process JSX elements from generators.
|
|
837
|
-
*/
|
|
838
|
-
setRenderer(renderer: RendererFactory): void
|
|
839
|
-
/**
|
|
840
|
-
* Set resolved options merged into the normalized plugin's `options`.
|
|
841
|
-
* Call this in `kubb:plugin:setup` to provide options generators need.
|
|
842
|
-
*/
|
|
843
|
-
setOptions(options: TFactory['resolvedOptions']): void
|
|
844
|
-
/**
|
|
845
|
-
* Inject a raw file into the build output, bypassing the generation pipeline.
|
|
846
|
-
*/
|
|
847
|
-
injectFile(userFileNode: UserFileNode): void
|
|
848
|
-
/**
|
|
849
|
-
* Merge a partial config update into the current build configuration.
|
|
850
|
-
*/
|
|
851
|
-
updateConfig(config: Partial<Config>): void
|
|
455
|
+
export type KubbBuildStartContext = {
|
|
852
456
|
/**
|
|
853
|
-
*
|
|
457
|
+
* Resolved configuration for this build.
|
|
854
458
|
*/
|
|
855
459
|
config: Config
|
|
856
460
|
/**
|
|
857
|
-
*
|
|
461
|
+
* Adapter that parsed the input into the universal AST.
|
|
858
462
|
*/
|
|
859
|
-
options: TFactory['options']
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
/**
|
|
863
|
-
* Context for hook-style plugin `kubb:build:start` handler.
|
|
864
|
-
* Fires immediately before the plugin execution loop begins.
|
|
865
|
-
*/
|
|
866
|
-
export type KubbBuildStartContext = {
|
|
867
|
-
config: Config
|
|
868
463
|
adapter: Adapter
|
|
869
|
-
inputNode: InputNode
|
|
870
464
|
/**
|
|
871
|
-
*
|
|
465
|
+
* Metadata about the parsed document (title, version, base URL, circular schema names, enum names).
|
|
466
|
+
* To observe individual schemas and operations use the `kubb:generate:schema` / `kubb:generate:operation` hooks.
|
|
467
|
+
*/
|
|
468
|
+
meta: InputMeta | undefined
|
|
469
|
+
/**
|
|
470
|
+
* Looks up a registered plugin by name, typed by the plugin registry.
|
|
872
471
|
*/
|
|
873
472
|
getPlugin<TName extends keyof Kubb.PluginRegistry>(name: TName): Plugin<Kubb.PluginRegistry[TName]> | undefined
|
|
874
473
|
getPlugin(name: string): Plugin | undefined
|
|
875
474
|
/**
|
|
876
|
-
*
|
|
877
|
-
* Call this lazily (e.g. in `kubb:plugin:end`) to see files added by prior plugins.
|
|
475
|
+
* Snapshot of all files accumulated so far.
|
|
878
476
|
*/
|
|
879
477
|
readonly files: ReadonlyArray<FileNode>
|
|
880
478
|
/**
|
|
881
|
-
*
|
|
882
|
-
* Files with the same path are merged; new files are appended.
|
|
883
|
-
* Safe to call at any point during the plugin lifecycle, including inside `kubb:plugin:end`.
|
|
479
|
+
* Adds or merges one or more files into the file manager.
|
|
884
480
|
*/
|
|
885
481
|
upsertFile: (...files: Array<FileNode>) => void
|
|
886
482
|
}
|
|
887
483
|
|
|
888
|
-
/**
|
|
889
|
-
* Context for `kubb:plugins:end` handlers.
|
|
890
|
-
* Fires after plugins run and per-plugin barrels are written, before final write to disk.
|
|
891
|
-
* Middleware that needs final files (e.g. root barrel) use this event.
|
|
892
|
-
*/
|
|
893
484
|
export type KubbPluginsEndContext = {
|
|
485
|
+
/**
|
|
486
|
+
* Resolved configuration for this build.
|
|
487
|
+
*/
|
|
894
488
|
config: Config
|
|
895
489
|
/**
|
|
896
|
-
*
|
|
490
|
+
* Snapshot of all files accumulated across all plugins.
|
|
897
491
|
*/
|
|
898
492
|
readonly files: ReadonlyArray<FileNode>
|
|
899
493
|
/**
|
|
900
|
-
*
|
|
901
|
-
* Files added here are included in the write pass.
|
|
494
|
+
* Adds or merges one or more files into the file manager.
|
|
902
495
|
*/
|
|
903
496
|
upsertFile: (...files: Array<FileNode>) => void
|
|
904
497
|
}
|
|
905
498
|
|
|
906
|
-
/**
|
|
907
|
-
* Context for hook-style plugin `kubb:build:end` handler.
|
|
908
|
-
* Fires after all files have been written to disk.
|
|
909
|
-
*/
|
|
910
499
|
export type KubbBuildEndContext = {
|
|
500
|
+
/**
|
|
501
|
+
* All files generated during this build.
|
|
502
|
+
*/
|
|
911
503
|
files: Array<FileNode>
|
|
504
|
+
/**
|
|
505
|
+
* Resolved configuration for this build.
|
|
506
|
+
*/
|
|
912
507
|
config: Config
|
|
508
|
+
/**
|
|
509
|
+
* Absolute path to the output directory.
|
|
510
|
+
*/
|
|
913
511
|
outputDir: string
|
|
914
512
|
}
|
|
915
513
|
|
|
916
514
|
export type KubbLifecycleStartContext = {
|
|
515
|
+
/**
|
|
516
|
+
* Current Kubb version string.
|
|
517
|
+
*/
|
|
917
518
|
version: string
|
|
918
519
|
}
|
|
919
520
|
|
|
920
|
-
export type KubbConfigEndContext = {
|
|
921
|
-
configs: Array<Config>
|
|
922
|
-
}
|
|
923
|
-
|
|
924
521
|
export type KubbGenerationStartContext = {
|
|
522
|
+
/**
|
|
523
|
+
* Resolved configuration for this generation run.
|
|
524
|
+
*/
|
|
925
525
|
config: Config
|
|
926
526
|
}
|
|
927
527
|
|
|
928
528
|
export type KubbGenerationEndContext = {
|
|
529
|
+
/**
|
|
530
|
+
* Resolved configuration for this generation run.
|
|
531
|
+
*/
|
|
929
532
|
config: Config
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
533
|
+
/**
|
|
534
|
+
* Read-only view of the files written during this build.
|
|
535
|
+
* Reads go directly to `config.storage`, nothing extra is held in memory.
|
|
536
|
+
*
|
|
537
|
+
* @example Read a generated file
|
|
538
|
+
* `const code = await storage.getItem('/src/gen/pet.ts')`
|
|
539
|
+
*
|
|
540
|
+
* @example Walk every generated file
|
|
541
|
+
* ```ts
|
|
542
|
+
* for (const path of await storage.getKeys()) {
|
|
543
|
+
* const code = await storage.getItem(path)
|
|
544
|
+
* }
|
|
545
|
+
* ```
|
|
546
|
+
*/
|
|
547
|
+
storage: Storage
|
|
548
|
+
/**
|
|
549
|
+
* Diagnostics collected during the build: error/warning/info problems plus a
|
|
550
|
+
* `performance` diagnostic per plugin. The end-of-run summary derives its failure counts
|
|
551
|
+
* and per-plugin timings from these. Set by the CLI runner, omitted by other callers.
|
|
552
|
+
*/
|
|
553
|
+
diagnostics?: Array<Diagnostic>
|
|
554
|
+
/**
|
|
555
|
+
* `'success'` when all plugins completed without errors, `'failed'` otherwise.
|
|
556
|
+
*/
|
|
557
|
+
status?: 'success' | 'failed'
|
|
558
|
+
/**
|
|
559
|
+
* High-resolution start time from `process.hrtime()`, used to compute the elapsed time.
|
|
560
|
+
*/
|
|
561
|
+
hrStart?: [number, number]
|
|
562
|
+
/**
|
|
563
|
+
* Total number of files created during this run.
|
|
564
|
+
*/
|
|
565
|
+
filesCreated?: number
|
|
946
566
|
}
|
|
947
567
|
|
|
948
568
|
export type KubbInfoContext = {
|
|
569
|
+
/**
|
|
570
|
+
* Human-readable info message.
|
|
571
|
+
*/
|
|
949
572
|
message: string
|
|
573
|
+
/**
|
|
574
|
+
* Optional supplementary detail.
|
|
575
|
+
*/
|
|
950
576
|
info?: string
|
|
951
577
|
}
|
|
952
578
|
|
|
953
579
|
export type KubbErrorContext = {
|
|
580
|
+
/**
|
|
581
|
+
* The caught error.
|
|
582
|
+
*/
|
|
954
583
|
error: Error
|
|
584
|
+
/**
|
|
585
|
+
* Optional structured metadata for additional context.
|
|
586
|
+
*/
|
|
955
587
|
meta?: Record<string, unknown>
|
|
956
588
|
}
|
|
957
589
|
|
|
958
590
|
export type KubbSuccessContext = {
|
|
591
|
+
/**
|
|
592
|
+
* Human-readable success message.
|
|
593
|
+
*/
|
|
959
594
|
message: string
|
|
595
|
+
/**
|
|
596
|
+
* Optional supplementary detail.
|
|
597
|
+
*/
|
|
960
598
|
info?: string
|
|
961
599
|
}
|
|
962
600
|
|
|
963
601
|
export type KubbWarnContext = {
|
|
602
|
+
/**
|
|
603
|
+
* Human-readable warning message.
|
|
604
|
+
*/
|
|
964
605
|
message: string
|
|
606
|
+
/**
|
|
607
|
+
* Optional supplementary detail.
|
|
608
|
+
*/
|
|
965
609
|
info?: string
|
|
966
610
|
}
|
|
967
611
|
|
|
968
|
-
export type
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
612
|
+
export type KubbDiagnosticContext = {
|
|
613
|
+
/**
|
|
614
|
+
* The structured diagnostic to render: a build problem or a version-update notice.
|
|
615
|
+
*/
|
|
616
|
+
diagnostic: ProblemDiagnostic | UpdateDiagnostic
|
|
972
617
|
}
|
|
973
618
|
|
|
974
619
|
export type KubbFilesProcessingStartContext = {
|
|
620
|
+
/**
|
|
621
|
+
* Files about to be serialized and written.
|
|
622
|
+
*/
|
|
975
623
|
files: Array<FileNode>
|
|
976
624
|
}
|
|
977
625
|
|
|
978
|
-
export type
|
|
626
|
+
export type KubbFileProcessingUpdate = {
|
|
979
627
|
/**
|
|
980
|
-
* Number of files processed.
|
|
628
|
+
* Number of files processed so far in this batch.
|
|
981
629
|
*/
|
|
982
630
|
processed: number
|
|
983
631
|
/**
|
|
984
|
-
* Total files
|
|
632
|
+
* Total number of files in this batch.
|
|
985
633
|
*/
|
|
986
634
|
total: number
|
|
987
635
|
/**
|
|
988
|
-
*
|
|
636
|
+
* Completion percentage, `0` to `100`.
|
|
989
637
|
*/
|
|
990
638
|
percentage: number
|
|
991
639
|
/**
|
|
992
|
-
*
|
|
640
|
+
* Serialized file content, or `undefined` when the file produced no output.
|
|
993
641
|
*/
|
|
994
642
|
source?: string
|
|
995
643
|
/**
|
|
996
|
-
* The file
|
|
644
|
+
* The file that was just processed.
|
|
997
645
|
*/
|
|
998
646
|
file: FileNode
|
|
999
647
|
/**
|
|
1000
|
-
*
|
|
648
|
+
* Resolved configuration for this build.
|
|
1001
649
|
*/
|
|
1002
650
|
config: Config
|
|
1003
651
|
}
|
|
1004
652
|
|
|
1005
|
-
export type
|
|
1006
|
-
files: Array<FileNode>
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
export type KubbPluginStartContext = {
|
|
1010
|
-
plugin: NormalizedPlugin
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
export type KubbPluginEndContext = {
|
|
1014
|
-
plugin: NormalizedPlugin
|
|
1015
|
-
duration: number
|
|
1016
|
-
success: boolean
|
|
1017
|
-
error?: Error
|
|
1018
|
-
config: Config
|
|
653
|
+
export type KubbFilesProcessingUpdateContext = {
|
|
1019
654
|
/**
|
|
1020
|
-
*
|
|
1021
|
-
* Includes files added by plugins that have already run.
|
|
655
|
+
* All files processed in this flush chunk.
|
|
1022
656
|
*/
|
|
1023
|
-
|
|
657
|
+
files: Array<KubbFileProcessingUpdate>
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
export type KubbFilesProcessingEndContext = {
|
|
1024
661
|
/**
|
|
1025
|
-
*
|
|
662
|
+
* All files that were serialized in this batch.
|
|
1026
663
|
*/
|
|
1027
|
-
|
|
664
|
+
files: Array<FileNode>
|
|
1028
665
|
}
|
|
1029
666
|
|
|
1030
667
|
export type KubbHookStartContext = {
|
|
668
|
+
/**
|
|
669
|
+
* Optional identifier for correlating start/end events.
|
|
670
|
+
*/
|
|
1031
671
|
id?: string
|
|
1032
|
-
command: string
|
|
1033
|
-
args?: readonly string[]
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
|
-
export type KubbHookEndContext = {
|
|
1037
|
-
id?: string
|
|
1038
|
-
command: string
|
|
1039
|
-
args?: readonly string[]
|
|
1040
|
-
success: boolean
|
|
1041
|
-
error: Error | null
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
type ByTag = {
|
|
1045
672
|
/**
|
|
1046
|
-
*
|
|
673
|
+
* The shell command that is about to run.
|
|
1047
674
|
*/
|
|
1048
|
-
|
|
675
|
+
command: string
|
|
1049
676
|
/**
|
|
1050
|
-
*
|
|
677
|
+
* Parsed argument list, when available.
|
|
1051
678
|
*/
|
|
1052
|
-
|
|
679
|
+
args?: ReadonlyArray<string>
|
|
1053
680
|
}
|
|
1054
681
|
|
|
1055
|
-
|
|
682
|
+
/**
|
|
683
|
+
* Emitted for each line streamed from a hook's stdout while it runs.
|
|
684
|
+
* A logger correlates the line to its active UI element via `id`.
|
|
685
|
+
*/
|
|
686
|
+
export type KubbHookLineContext = {
|
|
1056
687
|
/**
|
|
1057
|
-
*
|
|
688
|
+
* Identifier matching the corresponding `kubb:hook:start` event.
|
|
1058
689
|
*/
|
|
1059
|
-
|
|
690
|
+
id: string
|
|
1060
691
|
/**
|
|
1061
|
-
*
|
|
692
|
+
* A single streamed stdout line, without its trailing newline.
|
|
1062
693
|
*/
|
|
1063
|
-
|
|
694
|
+
line: string
|
|
1064
695
|
}
|
|
1065
696
|
|
|
1066
|
-
type
|
|
1067
|
-
/**
|
|
1068
|
-
* Filter by OpenAPI `path` (URL endpoint). Useful to group or filter by service segments like `/pets`, `/users`, etc.
|
|
1069
|
-
*/
|
|
1070
|
-
type: 'path'
|
|
697
|
+
export type KubbHookEndContext = {
|
|
1071
698
|
/**
|
|
1072
|
-
*
|
|
699
|
+
* Optional identifier matching the corresponding `kubb:hook:start` event.
|
|
1073
700
|
*/
|
|
1074
|
-
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
type ByMethod = {
|
|
701
|
+
id?: string
|
|
1078
702
|
/**
|
|
1079
|
-
*
|
|
703
|
+
* The shell command that ran.
|
|
1080
704
|
*/
|
|
1081
|
-
|
|
705
|
+
command: string
|
|
1082
706
|
/**
|
|
1083
|
-
*
|
|
707
|
+
* Parsed argument list, when available.
|
|
1084
708
|
*/
|
|
1085
|
-
|
|
1086
|
-
}
|
|
1087
|
-
// TODO implement as alternative for ByMethod
|
|
1088
|
-
// type ByMethods = {
|
|
1089
|
-
// type: 'methods'
|
|
1090
|
-
// pattern: Array<HttpMethod>
|
|
1091
|
-
// }
|
|
1092
|
-
|
|
1093
|
-
type BySchemaName = {
|
|
709
|
+
args?: ReadonlyArray<string>
|
|
1094
710
|
/**
|
|
1095
|
-
*
|
|
711
|
+
* `true` when the command exited with code `0`.
|
|
1096
712
|
*/
|
|
1097
|
-
|
|
713
|
+
success: boolean
|
|
1098
714
|
/**
|
|
1099
|
-
*
|
|
715
|
+
* Error thrown by the command, or `null` on success.
|
|
1100
716
|
*/
|
|
1101
|
-
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
type ByContentType = {
|
|
717
|
+
error: Error | null
|
|
1105
718
|
/**
|
|
1106
|
-
*
|
|
719
|
+
* Captured stdout from the process, populated when it exits non-zero.
|
|
1107
720
|
*/
|
|
1108
|
-
|
|
721
|
+
stdout?: string
|
|
1109
722
|
/**
|
|
1110
|
-
*
|
|
723
|
+
* Captured stderr from the process, populated when it exits non-zero.
|
|
1111
724
|
*/
|
|
1112
|
-
|
|
725
|
+
stderr?: string
|
|
1113
726
|
}
|
|
1114
727
|
|
|
1115
728
|
/**
|
|
1116
|
-
*
|
|
1117
|
-
*
|
|
1118
|
-
* Use to skip code generation for specific operations or schemas. For example, exclude deprecated endpoints
|
|
1119
|
-
* or internal-only schemas. Can filter by tag, operationId, path, HTTP method, content type, or schema name.
|
|
1120
|
-
*
|
|
1121
|
-
* @example
|
|
1122
|
-
* ```ts
|
|
1123
|
-
* exclude: [
|
|
1124
|
-
* { type: 'tag', pattern: 'internal' }, // skip "internal" tag
|
|
1125
|
-
* { type: 'path', pattern: /^\/admin/ }, // skip all /admin endpoints
|
|
1126
|
-
* { type: 'operationId', pattern: 'deprecated_*' } // skip operationIds matching pattern
|
|
1127
|
-
* ]
|
|
1128
|
-
* ```
|
|
1129
|
-
*/
|
|
1130
|
-
export type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
|
|
1131
|
-
|
|
1132
|
-
/**
|
|
1133
|
-
* A pattern filter that restricts generation to only matching nodes.
|
|
1134
|
-
*
|
|
1135
|
-
* Use to generate code for a subset of operations or schemas. For example, only generate for a specific service
|
|
1136
|
-
* tag or only for "production" endpoints. Can filter by tag, operationId, path, HTTP method, content type, or schema name.
|
|
1137
|
-
*
|
|
1138
|
-
* @example
|
|
1139
|
-
* ```ts
|
|
1140
|
-
* include: [
|
|
1141
|
-
* { type: 'tag', pattern: 'public' }, // generate only "public" tag
|
|
1142
|
-
* { type: 'path', pattern: /^\/api\/v1/ }, // generate only v1 endpoints
|
|
1143
|
-
* ]
|
|
1144
|
-
* ```
|
|
1145
|
-
*/
|
|
1146
|
-
export type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName
|
|
1147
|
-
|
|
1148
|
-
/**
|
|
1149
|
-
* A pattern filter paired with partial option overrides applied when the pattern matches.
|
|
1150
|
-
*
|
|
1151
|
-
* Use to customize generation for specific operations or schemas. For example, apply different output paths
|
|
1152
|
-
* for different tags, or use custom resolver functions per operation. Can filter by tag, operationId, path,
|
|
1153
|
-
* HTTP method, schema name, or content type.
|
|
1154
|
-
*
|
|
1155
|
-
* @example
|
|
1156
|
-
* ```ts
|
|
1157
|
-
* override: [
|
|
1158
|
-
* {
|
|
1159
|
-
* type: 'tag',
|
|
1160
|
-
* pattern: 'admin',
|
|
1161
|
-
* options: { output: { path: './src/gen/admin' } } // admin APIs go to separate folder
|
|
1162
|
-
* },
|
|
1163
|
-
* {
|
|
1164
|
-
* type: 'operationId',
|
|
1165
|
-
* pattern: 'listPets',
|
|
1166
|
-
* options: { exclude: true } // skip this specific operation
|
|
1167
|
-
* }
|
|
1168
|
-
* ]
|
|
1169
|
-
* ```
|
|
1170
|
-
*/
|
|
1171
|
-
export type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
|
|
1172
|
-
//TODO should be options: Omit<Partial<TOptions>, 'override'>
|
|
1173
|
-
options: Partial<TOptions>
|
|
1174
|
-
}
|
|
1175
|
-
|
|
1176
|
-
/**
|
|
1177
|
-
* File-specific parameters for `Resolver.resolvePath`.
|
|
1178
|
-
*
|
|
1179
|
-
* Pass alongside a `ResolverContext` to identify which file to resolve.
|
|
1180
|
-
* Provide `tag` for tag-based grouping or `path` for path-based grouping.
|
|
1181
|
-
*
|
|
1182
|
-
* @example
|
|
1183
|
-
* ```ts
|
|
1184
|
-
* resolver.resolvePath(
|
|
1185
|
-
* { baseName: 'petTypes.ts', tag: 'pets' },
|
|
1186
|
-
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
1187
|
-
* )
|
|
1188
|
-
* // → '/src/types/petsController/petTypes.ts'
|
|
1189
|
-
* ```
|
|
729
|
+
* CLI options derived from command-line flags.
|
|
1190
730
|
*/
|
|
1191
|
-
export type
|
|
1192
|
-
baseName: FileNode['baseName']
|
|
1193
|
-
pathMode?: 'single' | 'split'
|
|
731
|
+
export type CLIOptions = {
|
|
1194
732
|
/**
|
|
1195
|
-
*
|
|
733
|
+
* Path to the Kubb config file.
|
|
1196
734
|
*/
|
|
1197
|
-
|
|
735
|
+
config?: string
|
|
1198
736
|
/**
|
|
1199
|
-
*
|
|
737
|
+
* OpenAPI input path passed as the positional argument to `kubb generate`.
|
|
738
|
+
* Overrides `config.input.path` when set.
|
|
1200
739
|
*/
|
|
1201
|
-
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
/**
|
|
1205
|
-
* Shared context passed as the second argument to `Resolver.resolvePath` and `Resolver.resolveFile`.
|
|
1206
|
-
*
|
|
1207
|
-
* Describes where on disk output is rooted, which output config is active, and the optional
|
|
1208
|
-
* grouping strategy that controls subdirectory layout.
|
|
1209
|
-
*
|
|
1210
|
-
* @example
|
|
1211
|
-
* ```ts
|
|
1212
|
-
* const context: ResolverContext = {
|
|
1213
|
-
* root: config.root,
|
|
1214
|
-
* output,
|
|
1215
|
-
* group,
|
|
1216
|
-
* }
|
|
1217
|
-
* ```
|
|
1218
|
-
*/
|
|
1219
|
-
export type ResolverContext = {
|
|
1220
|
-
root: string
|
|
1221
|
-
output: Output
|
|
1222
|
-
group?: Group
|
|
740
|
+
input?: string
|
|
1223
741
|
/**
|
|
1224
|
-
*
|
|
742
|
+
* Re-run generation whenever input files change.
|
|
1225
743
|
*/
|
|
1226
|
-
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
/**
|
|
1230
|
-
* File-specific parameters for `Resolver.resolveFile`.
|
|
1231
|
-
*
|
|
1232
|
-
* Pass alongside a `ResolverContext` to fully describe the file to resolve.
|
|
1233
|
-
* `tag` and `path` are used only when a matching `group` is present in the context.
|
|
1234
|
-
*
|
|
1235
|
-
* @example
|
|
1236
|
-
* ```ts
|
|
1237
|
-
* resolver.resolveFile(
|
|
1238
|
-
* { name: 'listPets', extname: '.ts', tag: 'pets' },
|
|
1239
|
-
* { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
|
|
1240
|
-
* )
|
|
1241
|
-
* // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
|
|
1242
|
-
* ```
|
|
1243
|
-
*/
|
|
1244
|
-
export type ResolverFileParams = {
|
|
1245
|
-
name: string
|
|
1246
|
-
extname: FileNode['extname']
|
|
744
|
+
watch?: boolean
|
|
1247
745
|
/**
|
|
1248
|
-
*
|
|
746
|
+
* Controls how much output the CLI prints.
|
|
747
|
+
*
|
|
748
|
+
* @default 'info'
|
|
1249
749
|
*/
|
|
1250
|
-
|
|
750
|
+
logLevel?: 'silent' | 'info' | 'verbose'
|
|
1251
751
|
/**
|
|
1252
|
-
*
|
|
752
|
+
* Reporters selected on the CLI via `--reporter`, overriding `config.reporters`.
|
|
1253
753
|
*/
|
|
1254
|
-
|
|
754
|
+
reporters?: Array<ReporterName>
|
|
1255
755
|
}
|
|
1256
756
|
|
|
1257
757
|
/**
|
|
1258
|
-
*
|
|
1259
|
-
*
|
|
1260
|
-
* `output` is optional — not every plugin configures a banner/footer.
|
|
1261
|
-
* `config` carries the global Kubb config, used to derive the default Kubb banner.
|
|
1262
|
-
*
|
|
1263
|
-
* @example
|
|
1264
|
-
* ```ts
|
|
1265
|
-
* resolver.resolveBanner(inputNode, { output: { banner: '// generated' }, config })
|
|
1266
|
-
* // → '// generated'
|
|
1267
|
-
* ```
|
|
758
|
+
* All accepted forms of a Kubb configuration.
|
|
759
|
+
* Accepts `Config`/`Config[]`/promise or a factory (optionally receiving `TCliOptions`).
|
|
1268
760
|
*/
|
|
1269
|
-
export type
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
}
|
|
761
|
+
export type PossibleConfig<TCliOptions = undefined> =
|
|
762
|
+
| PossiblePromise<Config | Array<Config>>
|
|
763
|
+
| ((...args: [TCliOptions] extends [undefined] ? [] : [TCliOptions]) => PossiblePromise<Config | Array<Config>>)
|
|
1273
764
|
|
|
1274
765
|
/**
|
|
1275
|
-
*
|
|
766
|
+
* Full output produced by a successful or failed build.
|
|
1276
767
|
*/
|
|
1277
|
-
export type
|
|
768
|
+
export type BuildOutput = {
|
|
1278
769
|
/**
|
|
1279
|
-
*
|
|
770
|
+
* Structured diagnostics collected during the build: error/warning/info problems
|
|
771
|
+
* (each with a code, severity, and where known a JSON-pointer location) plus a
|
|
772
|
+
* `performance` diagnostic per plugin. Includes a top-level diagnostic when the build
|
|
773
|
+
* threw before completing. Use {@link Diagnostics.hasError} to test for failure.
|
|
1280
774
|
*/
|
|
1281
|
-
|
|
775
|
+
diagnostics: Array<Diagnostic>
|
|
1282
776
|
/**
|
|
1283
|
-
*
|
|
777
|
+
* All files generated during this build.
|
|
1284
778
|
*/
|
|
1285
|
-
|
|
779
|
+
files: Array<FileNode>
|
|
1286
780
|
/**
|
|
1287
|
-
*
|
|
1288
|
-
* @default 'silent'
|
|
781
|
+
* The plugin driver that orchestrated this build.
|
|
1289
782
|
*/
|
|
1290
|
-
|
|
783
|
+
driver: KubbDriver
|
|
784
|
+
/**
|
|
785
|
+
* Read-only view of every file written during this build.
|
|
786
|
+
* Reads go straight to `config.storage`, nothing extra is held in memory.
|
|
787
|
+
*
|
|
788
|
+
* @example Read a generated file
|
|
789
|
+
* `const code = await buildOutput.storage.getItem('/src/gen/pet.ts')`
|
|
790
|
+
*
|
|
791
|
+
* @example List all generated file paths
|
|
792
|
+
* `const paths = await buildOutput.storage.getKeys()`
|
|
793
|
+
*/
|
|
794
|
+
storage: Storage
|
|
1291
795
|
}
|
|
1292
796
|
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
797
|
+
export type { Adapter, AdapterFactoryOptions, AdapterSource } from './createAdapter.ts'
|
|
798
|
+
export type {
|
|
799
|
+
Diagnostic,
|
|
800
|
+
DiagnosticByCode,
|
|
801
|
+
DiagnosticDoc,
|
|
802
|
+
DiagnosticKind,
|
|
803
|
+
DiagnosticLocation,
|
|
804
|
+
DiagnosticSeverity,
|
|
805
|
+
PerformanceDiagnostic,
|
|
806
|
+
ProblemCode,
|
|
807
|
+
ProblemDiagnostic,
|
|
808
|
+
SerializedDiagnostic,
|
|
809
|
+
UpdateDiagnostic,
|
|
810
|
+
} from './diagnostics.ts'
|
|
811
|
+
export type { Kubb } from './createKubb.ts'
|
|
812
|
+
export type { GenerationResult, Reporter, ReporterContext, ReporterName, UserReporter } from './createReporter.ts'
|
|
813
|
+
export type { Renderer, RendererFactory } from './createRenderer.ts'
|
|
814
|
+
export type { Storage } from './createStorage.ts'
|
|
815
|
+
export type { FileProcessorHooks, ParsedFile } from './FileProcessor.ts'
|
|
816
|
+
export type { Generator, GeneratorContext } from './defineGenerator.ts'
|
|
1305
817
|
export type { Parser } from './defineParser.ts'
|
|
818
|
+
export type { Exclude, Group, Include, Output, OutputMode, OutputOptions, Override } from './definePlugin.ts'
|
|
819
|
+
export type { KubbPluginEndContext, KubbPluginSetupContext, KubbPluginStartContext, NormalizedPlugin, Plugin, PluginFactoryOptions } from './definePlugin.ts'
|
|
820
|
+
export type {
|
|
821
|
+
BannerMeta,
|
|
822
|
+
ResolveBannerContext,
|
|
823
|
+
ResolveBannerFile,
|
|
824
|
+
ResolveOptionsContext,
|
|
825
|
+
Resolver,
|
|
826
|
+
ResolverContext,
|
|
827
|
+
ResolverFileParams,
|
|
828
|
+
ResolverPathParams,
|
|
829
|
+
} from './defineResolver.ts'
|