@kubb/core 5.0.0-alpha.3 → 5.0.0-alpha.30

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.
Files changed (54) hide show
  1. package/dist/PluginDriver-D110FoJ-.d.ts +1632 -0
  2. package/dist/hooks.cjs +12 -27
  3. package/dist/hooks.cjs.map +1 -1
  4. package/dist/hooks.d.ts +11 -36
  5. package/dist/hooks.js +13 -27
  6. package/dist/hooks.js.map +1 -1
  7. package/dist/index.cjs +1410 -823
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.ts +597 -95
  10. package/dist/index.js +1391 -818
  11. package/dist/index.js.map +1 -1
  12. package/package.json +7 -7
  13. package/src/Kubb.ts +40 -58
  14. package/src/{PluginManager.ts → PluginDriver.ts} +165 -177
  15. package/src/build.ts +167 -44
  16. package/src/config.ts +9 -8
  17. package/src/constants.ts +40 -7
  18. package/src/createAdapter.ts +25 -0
  19. package/src/createPlugin.ts +30 -0
  20. package/src/createStorage.ts +58 -0
  21. package/src/defineGenerator.ts +126 -0
  22. package/src/defineLogger.ts +13 -3
  23. package/src/definePresets.ts +16 -0
  24. package/src/defineResolver.ts +457 -0
  25. package/src/hooks/index.ts +1 -6
  26. package/src/hooks/useDriver.ts +11 -0
  27. package/src/hooks/useMode.ts +5 -5
  28. package/src/hooks/usePlugin.ts +3 -3
  29. package/src/index.ts +18 -7
  30. package/src/renderNode.tsx +25 -0
  31. package/src/storages/fsStorage.ts +2 -2
  32. package/src/storages/memoryStorage.ts +2 -2
  33. package/src/types.ts +589 -52
  34. package/src/utils/FunctionParams.ts +2 -2
  35. package/src/utils/TreeNode.ts +45 -7
  36. package/src/utils/diagnostics.ts +4 -1
  37. package/src/utils/executeStrategies.ts +29 -10
  38. package/src/utils/formatters.ts +10 -21
  39. package/src/utils/getBarrelFiles.ts +83 -10
  40. package/src/utils/getConfigs.ts +8 -22
  41. package/src/utils/getPreset.ts +78 -0
  42. package/src/utils/linters.ts +23 -3
  43. package/src/utils/packageJSON.ts +76 -0
  44. package/dist/types-CiPWLv-5.d.ts +0 -1001
  45. package/src/BarrelManager.ts +0 -74
  46. package/src/PackageManager.ts +0 -180
  47. package/src/PromiseManager.ts +0 -40
  48. package/src/defineAdapter.ts +0 -22
  49. package/src/definePlugin.ts +0 -12
  50. package/src/defineStorage.ts +0 -56
  51. package/src/errors.ts +0 -1
  52. package/src/hooks/useKubb.ts +0 -22
  53. package/src/hooks/usePluginManager.ts +0 -11
  54. package/src/utils/getPlugins.ts +0 -23
package/dist/index.d.ts CHANGED
@@ -1,34 +1,212 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { A as UserPluginWithLifeCycle, B as URLPath, C as PrinterFactoryOptions, D as UserConfig, E as UnknownUserPlugin, F as defineStorage, I as formatters, L as linters, M as PluginManager, N as getMode, O as UserLogger, P as DefineStorage, R as logLevel, S as Printer, T as ResolvePathParams, _ as PluginFactoryOptions, a as Config, b as PluginParameter, c as Group, d as Logger, f as LoggerContext, g as PluginContext, h as Plugin, i as BarrelType, j as KubbEvents, k as UserPlugin, l as InputData, m as Output, n as AdapterFactoryOptions, o as DevtoolsOptions, p as LoggerOptions, r as AdapterSource, s as GetPluginFactoryOptions, t as Adapter, u as InputPath, v as PluginLifecycle, w as ResolveNameParams, x as PluginWithLifeCycle, y as PluginLifecycleHooks, z as AsyncEventEmitter } from "./types-CiPWLv-5.js";
3
- import { definePrinter } from "@kubb/ast";
4
- import { Fabric } from "@kubb/react-fabric";
5
- import { KubbFile } from "@kubb/fabric-core/types";
2
+ import { $ as defineGenerator, A as Preset, B as Resolver, C as Plugin, D as PluginLifecycleHooks, E as PluginLifecycle, F as ResolveBannerContext, G as UserConfig, H as ResolverFileParams, I as ResolveNameParams, J as UserPlugin, K as UserGroup, L as ResolveOptionsContext, M as Printer, N as PrinterFactoryOptions, O as PluginParameter, P as PrinterPartial, Q as Generator, R as ResolvePathOptions, S as Override, T as PluginFactoryOptions, U as ResolverPathParams, V as ResolverContext, W as SchemaHook, X as UserResolver, Y as UserPluginWithLifeCycle, Z as KubbEvents, _ as LoggerContext, a as AdapterSource, at as logLevel, b as OperationsHook, c as Config, d as GeneratorContext, et as mergeGenerators, f as Group, g as Logger, h as InputPath, i as AdapterFactoryOptions, it as linters, j as Presets, k as PluginWithLifeCycle, l as DevtoolsOptions, m as InputData, n as getMode, nt as createStorage, o as BarrelType, ot as PossiblePromise, p as Include, q as UserLogger, r as Adapter, rt as formatters, s as CompatibilityPreset, st as AsyncEventEmitter, t as PluginDriver, tt as Storage, u as Exclude, v as LoggerOptions, w as PluginContext, x as Output, y as OperationHook, z as ResolvePathParams } from "./PluginDriver-D110FoJ-.js";
3
+ import { composeTransformers, definePrinter } from "@kubb/ast";
4
+ import { Node, RootNode, Visitor } from "@kubb/ast/types";
5
+ import { Fabric, FabricFile } from "@kubb/fabric-core/types";
6
6
 
7
+ //#region ../../internals/utils/src/urlPath.d.ts
8
+ type URLObject = {
9
+ /**
10
+ * The resolved URL string (Express-style or template literal, depending on context).
11
+ */
12
+ url: string;
13
+ /**
14
+ * Extracted path parameters as a key-value map, or `undefined` when the path has none.
15
+ */
16
+ params?: Record<string, string>;
17
+ };
18
+ type ObjectOptions = {
19
+ /**
20
+ * Controls whether the `url` is rendered as an Express path or a template literal.
21
+ * @default 'path'
22
+ */
23
+ type?: 'path' | 'template';
24
+ /**
25
+ * Optional transform applied to each extracted parameter name.
26
+ */
27
+ replacer?: (pathParam: string) => string;
28
+ /**
29
+ * When `true`, the result is serialized to a string expression instead of a plain object.
30
+ */
31
+ stringify?: boolean;
32
+ };
33
+ /**
34
+ * Supported identifier casing strategies for path parameters.
35
+ */
36
+ type PathCasing = 'camelcase';
37
+ type Options = {
38
+ /**
39
+ * Casing strategy applied to path parameter names.
40
+ * @default undefined (original identifier preserved)
41
+ */
42
+ casing?: PathCasing;
43
+ };
44
+ /**
45
+ * Parses and transforms an OpenAPI/Swagger path string into various URL formats.
46
+ *
47
+ * @example
48
+ * const p = new URLPath('/pet/{petId}')
49
+ * p.URL // '/pet/:petId'
50
+ * p.template // '`/pet/${petId}`'
51
+ */
52
+ declare class URLPath {
53
+ #private;
54
+ /**
55
+ * The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.
56
+ */
57
+ path: string;
58
+ constructor(path: string, options?: Options);
59
+ /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * new URLPath('/pet/{petId}').URL // '/pet/:petId'
64
+ * ```
65
+ */
66
+ get URL(): string;
67
+ /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
72
+ * new URLPath('/pet/{petId}').isURL // false
73
+ * ```
74
+ */
75
+ get isURL(): boolean;
76
+ /**
77
+ * Converts the OpenAPI path to a TypeScript template literal string.
78
+ *
79
+ * @example
80
+ * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
81
+ * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
82
+ */
83
+ get template(): string;
84
+ /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * new URLPath('/pet/{petId}').object
89
+ * // { url: '/pet/:petId', params: { petId: 'petId' } }
90
+ * ```
91
+ */
92
+ get object(): URLObject | string;
93
+ /** Returns a map of path parameter names, or `undefined` when the path has no parameters.
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * new URLPath('/pet/{petId}').params // { petId: 'petId' }
98
+ * new URLPath('/pet').params // undefined
99
+ * ```
100
+ */
101
+ get params(): Record<string, string> | undefined;
102
+ toObject({
103
+ type,
104
+ replacer,
105
+ stringify
106
+ }?: ObjectOptions): URLObject | string;
107
+ /**
108
+ * Converts the OpenAPI path to a TypeScript template literal string.
109
+ * An optional `replacer` can transform each extracted parameter name before interpolation.
110
+ *
111
+ * @example
112
+ * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
113
+ */
114
+ toTemplateString({
115
+ prefix,
116
+ replacer
117
+ }?: {
118
+ prefix?: string;
119
+ replacer?: (pathParam: string) => string;
120
+ }): string;
121
+ /**
122
+ * Extracts all `{param}` segments from the path and returns them as a key-value map.
123
+ * An optional `replacer` transforms each parameter name in both key and value positions.
124
+ * Returns `undefined` when no path parameters are found.
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * new URLPath('/pet/{petId}/tag/{tagId}').getParams()
129
+ * // { petId: 'petId', tagId: 'tagId' }
130
+ * ```
131
+ */
132
+ getParams(replacer?: (pathParam: string) => string): Record<string, string> | undefined;
133
+ /** Converts the OpenAPI path to Express-style colon syntax.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
138
+ * ```
139
+ */
140
+ toURLPath(): string;
141
+ }
142
+ //#endregion
7
143
  //#region src/build.d.ts
8
144
  type BuildOptions = {
9
145
  config: UserConfig;
10
146
  events?: AsyncEventEmitter<KubbEvents>;
11
147
  };
148
+ /**
149
+ * Full output produced by a successful or failed build.
150
+ */
12
151
  type BuildOutput = {
152
+ /**
153
+ * Plugins that threw during installation, paired with the caught error.
154
+ */
13
155
  failedPlugins: Set<{
14
156
  plugin: Plugin;
15
157
  error: Error;
16
158
  }>;
17
159
  fabric: Fabric;
18
- files: Array<KubbFile.ResolvedFile>;
19
- pluginManager: PluginManager;
160
+ files: Array<FabricFile.ResolvedFile>;
161
+ driver: PluginDriver;
162
+ /**
163
+ * Elapsed time in milliseconds for each plugin, keyed by plugin name.
164
+ */
20
165
  pluginTimings: Map<string, number>;
21
166
  error?: Error;
22
- sources: Map<KubbFile.Path, string>;
167
+ /**
168
+ * Raw generated source, keyed by absolute file path.
169
+ */
170
+ sources: Map<FabricFile.Path, string>;
23
171
  };
172
+ /**
173
+ * Intermediate result returned by {@link setup} and accepted by {@link safeBuild}.
174
+ */
24
175
  type SetupResult = {
25
176
  events: AsyncEventEmitter<KubbEvents>;
26
177
  fabric: Fabric;
27
- pluginManager: PluginManager;
28
- sources: Map<KubbFile.Path, string>;
178
+ driver: PluginDriver;
179
+ sources: Map<FabricFile.Path, string>;
29
180
  };
181
+ /**
182
+ * Initializes all Kubb infrastructure for a build without executing any plugins.
183
+ *
184
+ * - Validates the input path (when applicable).
185
+ * - Applies config defaults (`root`, `output.*`, `devtools`).
186
+ * - Creates the Fabric instance and wires storage, format, and lint hooks.
187
+ * - Runs the adapter (if configured) to produce the universal `RootNode`.
188
+ *
189
+ * Pass the returned {@link SetupResult} directly to {@link safeBuild} or {@link build}
190
+ * via the `overrides` argument to reuse the same infrastructure across multiple runs.
191
+ */
30
192
  declare function setup(options: BuildOptions): Promise<SetupResult>;
193
+ /**
194
+ * Runs a full Kubb build and throws on any error or plugin failure.
195
+ *
196
+ * Internally delegates to {@link safeBuild} and rethrows collected errors.
197
+ * Pass an existing {@link SetupResult} via `overrides` to skip the setup phase.
198
+ */
31
199
  declare function build(options: BuildOptions, overrides?: SetupResult): Promise<BuildOutput>;
200
+ /**
201
+ * Runs a full Kubb build and captures errors instead of throwing.
202
+ *
203
+ * - Installs each plugin in order, recording failures in `failedPlugins`.
204
+ * - Generates the root barrel file when `output.barrelType` is set.
205
+ * - Writes all files through Fabric.
206
+ *
207
+ * Returns a {@link BuildOutput} even on failure — inspect `error` and
208
+ * `failedPlugins` to determine whether the build succeeded.
209
+ */
32
210
  declare function safeBuild(options: BuildOptions, overrides?: SetupResult): Promise<BuildOutput>;
33
211
  //#endregion
34
212
  //#region src/config.d.ts
@@ -36,7 +214,13 @@ declare function safeBuild(options: BuildOptions, overrides?: SetupResult): Prom
36
214
  * CLI options derived from command-line flags.
37
215
  */
38
216
  type CLIOptions = {
39
- /** Path to `kubb.config.js` */config?: string; /** Enable watch mode for input files */
217
+ /**
218
+ * Path to `kubb.config.js`.
219
+ */
220
+ config?: string;
221
+ /**
222
+ * Enable watch mode for input files.
223
+ */
40
224
  watch?: boolean;
41
225
  /**
42
226
  * Logging verbosity for CLI usage.
@@ -46,10 +230,11 @@ type CLIOptions = {
46
230
  * - `debug`: include detailed plugin lifecycle logs
47
231
  * @default 'silent'
48
232
  */
49
- logLevel?: 'silent' | 'info' | 'debug'; /** Run Kubb with Bun */
50
- bun?: boolean;
233
+ logLevel?: 'silent' | 'info' | 'debug';
51
234
  };
52
- /** All accepted forms of a Kubb configuration. */
235
+ /**
236
+ * All accepted forms of a Kubb configuration.
237
+ */
53
238
  type ConfigInput = PossiblePromise<UserConfig | UserConfig[]> | ((cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>);
54
239
  /**
55
240
  * Helper for defining a Kubb configuration.
@@ -72,91 +257,334 @@ declare function defineConfig(config: PossiblePromise<UserConfig | UserConfig[]>
72
257
  */
73
258
  declare function isInputPath(config: UserConfig | undefined): config is UserConfig<InputPath>;
74
259
  //#endregion
75
- //#region src/defineAdapter.d.ts
260
+ //#region src/createAdapter.d.ts
261
+ /**
262
+ * Builder type for an {@link Adapter} — takes options and returns the adapter instance.
263
+ */
76
264
  type AdapterBuilder<T extends AdapterFactoryOptions> = (options: T['options']) => Adapter<T>;
77
265
  /**
78
- * Wraps an adapter builder to make the options parameter optional.
266
+ * Creates an adapter factory. Call the returned function with optional options to get the adapter instance.
267
+ *
268
+ * @example
269
+ * export const myAdapter = createAdapter<MyAdapter>((options) => {
270
+ * return {
271
+ * name: 'my-adapter',
272
+ * options,
273
+ * async parse(source) { ... },
274
+ * }
275
+ * })
276
+ *
277
+ * // instantiate
278
+ * const adapter = myAdapter({ validate: true })
279
+ */
280
+ declare function createAdapter<T extends AdapterFactoryOptions = AdapterFactoryOptions>(build: AdapterBuilder<T>): (options?: T['options']) => Adapter<T>;
281
+ //#endregion
282
+ //#region src/createPlugin.d.ts
283
+ /**
284
+ * Builder type for a {@link UserPluginWithLifeCycle} — takes options and returns the plugin instance.
285
+ */
286
+ type PluginBuilder<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => UserPluginWithLifeCycle<T>;
287
+ /**
288
+ * Creates a plugin factory. Call the returned function with optional options to get the plugin instance.
79
289
  *
80
290
  * @example
81
291
  * ```ts
82
- * export const adapterOas = defineAdapter<OasAdapter>((options) => {
83
- * const { validate = true, dateType = 'string' } = options
292
+ * export const myPlugin = createPlugin<MyPlugin>((options) => {
84
293
  * return {
85
- * name: adapterOasName,
86
- * options: { validate, dateType, ... },
87
- * parse(source) { ... },
294
+ * name: 'my-plugin',
295
+ * get options() { return options },
296
+ * resolvePath(baseName) { ... },
297
+ * resolveName(name, type) { ... },
88
298
  * }
89
299
  * })
300
+ *
301
+ * // instantiate
302
+ * const plugin = myPlugin({ output: { path: 'src/gen' } })
90
303
  * ```
91
304
  */
92
- declare function defineAdapter<T extends AdapterFactoryOptions = AdapterFactoryOptions>(build: AdapterBuilder<T>): (options?: T['options']) => Adapter<T>;
305
+ declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(build: PluginBuilder<T>): (options?: T['options']) => UserPluginWithLifeCycle<T>;
93
306
  //#endregion
94
307
  //#region src/defineLogger.d.ts
308
+ /**
309
+ * Wraps a logger definition into a typed {@link Logger}.
310
+ *
311
+ * @example
312
+ * export const myLogger = defineLogger({
313
+ * name: 'my-logger',
314
+ * install(context, options) {
315
+ * context.on('info', (message) => console.log('ℹ', message))
316
+ * context.on('error', (error) => console.error('✗', error.message))
317
+ * },
318
+ * })
319
+ */
95
320
  declare function defineLogger<Options extends LoggerOptions = LoggerOptions>(logger: UserLogger<Options>): Logger<Options>;
96
321
  //#endregion
97
- //#region src/definePlugin.d.ts
98
- type PluginBuilder<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => UserPluginWithLifeCycle<T>;
322
+ //#region src/definePresets.d.ts
99
323
  /**
100
- * Wraps a plugin builder to make the options parameter optional.
324
+ * Creates a typed presets registry object a named collection of {@link Preset} entries.
325
+ *
326
+ * @example
327
+ * import { definePreset, definePresets } from '@kubb/core'
328
+ * import { resolverTsLegacy } from '@kubb/plugin-ts'
329
+ *
330
+ * export const myPresets = definePresets({
331
+ * kubbV4: definePreset('kubbV4', { resolvers: [resolverTsLegacy] }),
332
+ * })
101
333
  */
102
- declare function definePlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(build: PluginBuilder<T>): (options?: T['options']) => UserPluginWithLifeCycle<T>;
334
+ declare function definePresets<TResolver extends Resolver = Resolver>(presets: Presets<TResolver>): Presets<TResolver>;
103
335
  //#endregion
104
- //#region src/PackageManager.d.ts
105
- type PackageJSON = {
106
- dependencies?: Record<string, string>;
107
- devDependencies?: Record<string, string>;
108
- };
109
- type DependencyName = string;
110
- type DependencyVersion = string;
111
- declare class PackageManager {
112
- #private;
113
- constructor(workspace?: string);
114
- set workspace(workspace: string);
115
- get workspace(): string | undefined;
116
- normalizeDirectory(directory: string): string;
117
- getLocation(path: string): string;
118
- import(path: string): Promise<unknown>;
119
- getPackageJSON(): Promise<PackageJSON | undefined>;
120
- getPackageJSONSync(): PackageJSON | undefined;
121
- static setVersion(dependency: DependencyName, version: DependencyVersion): void;
122
- getVersion(dependency: DependencyName | RegExp): Promise<DependencyVersion | undefined>;
123
- getVersionSync(dependency: DependencyName | RegExp): DependencyVersion | undefined;
124
- isValid(dependency: DependencyName | RegExp, version: DependencyVersion): Promise<boolean>;
125
- isValidSync(dependency: DependencyName | RegExp, version: DependencyVersion): boolean;
126
- }
127
- //#endregion
128
- //#region src/utils/executeStrategies.d.ts
129
- type PromiseFunc$1<T = unknown, T2 = never> = (state?: T) => T2 extends never ? Promise<T> : Promise<T> | T2;
130
- type ValueOfPromiseFuncArray<TInput extends Array<unknown>> = TInput extends Array<PromiseFunc$1<infer X, infer Y>> ? X | Y : never;
131
- type SeqOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Promise<Array<Awaited<ValueOfPromiseFuncArray<TInput>>>>;
336
+ //#region src/defineResolver.d.ts
337
+ /**
338
+ * Builder type for the plugin-specific resolver fields.
339
+ *
340
+ * `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`
341
+ * are optional — built-in fallbacks are injected when omitted.
342
+ */
343
+ type ResolverBuilder<T extends PluginFactoryOptions> = () => Omit<T['resolver'], 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter' | 'name' | 'pluginName'> & Partial<Pick<T['resolver'], 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>> & {
344
+ name: string;
345
+ pluginName: T['name'];
346
+ } & ThisType<T['resolver']>;
347
+ /**
348
+ * Default option resolver — applies include/exclude filters and merges matching override options.
349
+ *
350
+ * Returns `null` when the node is filtered out by an `exclude` rule or not matched by any `include` rule.
351
+ *
352
+ * @example Include/exclude filtering
353
+ * ```ts
354
+ * const options = defaultResolveOptions(operationNode, {
355
+ * options: { output: 'types' },
356
+ * exclude: [{ type: 'tag', pattern: 'internal' }],
357
+ * })
358
+ * // → null when node has tag 'internal'
359
+ * ```
360
+ *
361
+ * @example Override merging
362
+ * ```ts
363
+ * const options = defaultResolveOptions(operationNode, {
364
+ * options: { enumType: 'asConst' },
365
+ * override: [{ type: 'operationId', pattern: 'listPets', options: { enumType: 'enum' } }],
366
+ * })
367
+ * // → { enumType: 'enum' } when operationId matches
368
+ * ```
369
+ */
370
+ declare function defaultResolveOptions<TOptions>(node: Node, {
371
+ options,
372
+ exclude,
373
+ include,
374
+ override
375
+ }: ResolveOptionsContext<TOptions>): TOptions | null;
376
+ /**
377
+ * Default path resolver used by `defineResolver`.
378
+ *
379
+ * - Returns the output directory in `single` mode.
380
+ * - Resolves into a tag- or path-based subdirectory when `group` and a `tag`/`path` value are provided.
381
+ * - Falls back to a flat `output/baseName` path otherwise.
382
+ *
383
+ * A custom `group.name` function overrides the default subdirectory naming.
384
+ * For `tag` groups the default is `${camelCase(tag)}Controller`.
385
+ * For `path` groups the default is the first path segment after `/`.
386
+ *
387
+ * @example Flat output
388
+ * ```ts
389
+ * defaultResolvePath({ baseName: 'petTypes.ts' }, { root: '/src', output: { path: 'types' } })
390
+ * // → '/src/types/petTypes.ts'
391
+ * ```
392
+ *
393
+ * @example Tag-based grouping
394
+ * ```ts
395
+ * defaultResolvePath(
396
+ * { baseName: 'petTypes.ts', tag: 'pets' },
397
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
398
+ * )
399
+ * // → '/src/types/petsController/petTypes.ts'
400
+ * ```
401
+ *
402
+ * @example Path-based grouping
403
+ * ```ts
404
+ * defaultResolvePath(
405
+ * { baseName: 'petTypes.ts', path: '/pets/list' },
406
+ * { root: '/src', output: { path: 'types' }, group: { type: 'path' } },
407
+ * )
408
+ * // → '/src/types/pets/petTypes.ts'
409
+ * ```
410
+ *
411
+ * @example Single-file mode
412
+ * ```ts
413
+ * defaultResolvePath(
414
+ * { baseName: 'petTypes.ts', pathMode: 'single' },
415
+ * { root: '/src', output: { path: 'types' } },
416
+ * )
417
+ * // → '/src/types'
418
+ * ```
419
+ */
420
+ declare function defaultResolvePath({
421
+ baseName,
422
+ pathMode,
423
+ tag,
424
+ path: groupPath
425
+ }: ResolverPathParams, {
426
+ root,
427
+ output,
428
+ group
429
+ }: ResolverContext): FabricFile.Path;
132
430
  /**
133
- * Chains promises
431
+ * Default file resolver used by `defineResolver`.
432
+ *
433
+ * Resolves a `FabricFile.File` by combining name resolution (`resolver.default`) with
434
+ * path resolution (`resolver.resolvePath`). The resolved file always has empty
435
+ * `sources`, `imports`, and `exports` arrays — consumers populate those separately.
436
+ *
437
+ * In `single` mode the name is omitted and the file sits directly in the output directory.
438
+ *
439
+ * @example Resolve a schema file
440
+ * ```ts
441
+ * const file = defaultResolveFile.call(resolver,
442
+ * { name: 'pet', extname: '.ts' },
443
+ * { root: '/src', output: { path: 'types' } },
444
+ * )
445
+ * // → { baseName: 'pet.ts', path: '/src/types/pet.ts', sources: [], ... }
446
+ * ```
447
+ *
448
+ * @example Resolve an operation file with tag grouping
449
+ * ```ts
450
+ * const file = defaultResolveFile.call(resolver,
451
+ * { name: 'listPets', extname: '.ts', tag: 'pets' },
452
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
453
+ * )
454
+ * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
455
+ * ```
134
456
  */
135
- type HookFirstOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue = unknown> = ValueOfPromiseFuncArray<TInput>;
457
+ declare function defaultResolveFile(this: Resolver, {
458
+ name,
459
+ extname,
460
+ tag,
461
+ path: groupPath
462
+ }: ResolverFileParams, context: ResolverContext): FabricFile.File;
136
463
  /**
137
- * Chains promises, first non-null result stops and returns
464
+ * Generates the default "Generated by Kubb" banner from config and optional node metadata.
138
465
  */
139
- type HookParallelOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Promise<PromiseSettledResult<Awaited<ValueOfPromiseFuncArray<TInput>>>[]>;
466
+ declare function buildDefaultBanner({
467
+ title,
468
+ description,
469
+ version,
470
+ config
471
+ }: {
472
+ title?: string;
473
+ description?: string;
474
+ version?: string;
475
+ config: Config;
476
+ }): string;
140
477
  /**
141
- * Runs an array of promise functions with optional concurrency limit.
478
+ * Default banner resolver returns the banner string for a generated file.
479
+ *
480
+ * A user-supplied `output.banner` overrides the default Kubb "Generated by Kubb" notice.
481
+ * When no `output.banner` is set, the Kubb notice is used (including `title` and `version`
482
+ * from the OAS spec when a `node` is provided).
483
+ *
484
+ * - When `output.banner` is a function and `node` is provided, returns `output.banner(node)`.
485
+ * - When `output.banner` is a function and `node` is absent, falls back to the Kubb notice.
486
+ * - When `output.banner` is a string, returns it directly.
487
+ * - When `config.output.defaultBanner` is `false`, returns `undefined`.
488
+ * - Otherwise returns the Kubb "Generated by Kubb" notice.
489
+ *
490
+ * @example String banner overrides default
491
+ * ```ts
492
+ * defaultResolveBanner(undefined, { output: { banner: '// my banner' }, config })
493
+ * // → '// my banner'
494
+ * ```
495
+ *
496
+ * @example Function banner with node
497
+ * ```ts
498
+ * defaultResolveBanner(rootNode, { output: { banner: (node) => `// v${node.version}` }, config })
499
+ * // → '// v3.0.0'
500
+ * ```
501
+ *
502
+ * @example No user banner — Kubb notice with OAS metadata
503
+ * ```ts
504
+ * defaultResolveBanner(rootNode, { config })
505
+ * // → '/** Generated by Kubb ... Title: Pet Store ... *\/'
506
+ * ```
507
+ *
508
+ * @example Disabled default banner
509
+ * ```ts
510
+ * defaultResolveBanner(undefined, { config: { output: { defaultBanner: false }, ...config } })
511
+ * // → undefined
512
+ * ```
142
513
  */
143
- type Strategy = 'seq' | 'first' | 'parallel';
144
- type StrategySwitch<TStrategy extends Strategy, TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = TStrategy extends 'first' ? HookFirstOutput<TInput, TValue> : TStrategy extends 'seq' ? SeqOutput<TInput, TValue> : TStrategy extends 'parallel' ? HookParallelOutput<TInput, TValue> : never;
145
- //#endregion
146
- //#region src/PromiseManager.d.ts
147
- type PromiseFunc<T = unknown, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
148
- type Options<TState = unknown> = {
149
- nullCheck?: (state: TState) => boolean;
150
- };
151
- declare class PromiseManager<TState = unknown> {
152
- #private;
153
- constructor(options?: Options<TState>);
154
- run<TInput extends Array<PromiseFunc<TValue, null>>, TValue, TStrategy extends Strategy, TOutput = StrategySwitch<TStrategy, TInput, TValue>>(strategy: TStrategy, promises: TInput, {
155
- concurrency
156
- }?: {
157
- concurrency?: number;
158
- }): TOutput;
159
- }
514
+ declare function defaultResolveBanner(node: RootNode | undefined, {
515
+ output,
516
+ config
517
+ }: ResolveBannerContext): string | undefined;
518
+ /**
519
+ * Default footer resolver — returns the footer string for a generated file.
520
+ *
521
+ * - When `output.footer` is a function and `node` is provided, calls it with the node.
522
+ * - When `output.footer` is a function and `node` is absent, returns `undefined`.
523
+ * - When `output.footer` is a string, returns it directly.
524
+ * - Otherwise returns `undefined`.
525
+ *
526
+ * @example String footer
527
+ * ```ts
528
+ * defaultResolveFooter(undefined, { output: { footer: '// end of file' }, config })
529
+ * // → '// end of file'
530
+ * ```
531
+ *
532
+ * @example Function footer with node
533
+ * ```ts
534
+ * defaultResolveFooter(rootNode, { output: { footer: (node) => `// ${node.title}` }, config })
535
+ * // → '// Pet Store'
536
+ * ```
537
+ */
538
+ declare function defaultResolveFooter(node: RootNode | undefined, {
539
+ output
540
+ }: ResolveBannerContext): string | undefined;
541
+ /**
542
+ * Defines a resolver for a plugin, injecting built-in defaults for name casing,
543
+ * include/exclude/override filtering, path resolution, and file construction.
544
+ *
545
+ * All four defaults can be overridden by providing them in the builder function:
546
+ * - `default` — name casing strategy (camelCase / PascalCase)
547
+ * - `resolveOptions` — include/exclude/override filtering
548
+ * - `resolvePath` — output path computation
549
+ * - `resolveFile` — full `FabricFile.File` construction
550
+ *
551
+ * Methods in the builder have access to `this` (the full resolver object), so they
552
+ * can call other resolver methods without circular imports.
553
+ *
554
+ * @example Basic resolver with naming helpers
555
+ * ```ts
556
+ * export const resolver = defineResolver<PluginTs>(() => ({
557
+ * name: 'default',
558
+ * resolveName(node) {
559
+ * return this.default(node.name, 'function')
560
+ * },
561
+ * resolveTypedName(node) {
562
+ * return this.default(node.name, 'type')
563
+ * },
564
+ * }))
565
+ * ```
566
+ *
567
+ * @example Override resolvePath for a custom output structure
568
+ * ```ts
569
+ * export const resolver = defineResolver<PluginTs>(() => ({
570
+ * name: 'custom',
571
+ * resolvePath({ baseName }, { root, output }) {
572
+ * return path.resolve(root, output.path, 'generated', baseName)
573
+ * },
574
+ * }))
575
+ * ```
576
+ *
577
+ * @example Use this.default inside a helper
578
+ * ```ts
579
+ * export const resolver = defineResolver<PluginTs>(() => ({
580
+ * name: 'default',
581
+ * resolveParamName(node, param) {
582
+ * return this.default(`${node.operationId} ${param.in} ${param.name}`, 'type')
583
+ * },
584
+ * }))
585
+ * ```
586
+ */
587
+ declare function defineResolver<T extends PluginFactoryOptions>(build: ResolverBuilder<T>): T['resolver'];
160
588
  //#endregion
161
589
  //#region src/storages/fsStorage.d.ts
162
590
  /**
@@ -182,7 +610,7 @@ declare class PromiseManager<TState = unknown> {
182
610
  * })
183
611
  * ```
184
612
  */
185
- declare const fsStorage: (options?: Record<string, never> | undefined) => DefineStorage;
613
+ declare const fsStorage: (options?: Record<string, never> | undefined) => Storage;
186
614
  //#endregion
187
615
  //#region src/storages/memoryStorage.d.ts
188
616
  /**
@@ -202,7 +630,7 @@ declare const fsStorage: (options?: Record<string, never> | undefined) => Define
202
630
  * })
203
631
  * ```
204
632
  */
205
- declare const memoryStorage: (options?: Record<string, never> | undefined) => DefineStorage;
633
+ declare const memoryStorage: (options?: Record<string, never> | undefined) => Storage;
206
634
  //#endregion
207
635
  //#region src/utils/FunctionParams.d.ts
208
636
  type FunctionParamsASTWithoutType = {
@@ -232,11 +660,11 @@ type FunctionParamsASTWithType = {
232
660
  default?: string;
233
661
  };
234
662
  /**
235
- * @deprecated
663
+ * @deprecated use ast package instead
236
664
  */
237
665
  type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType;
238
666
  /**
239
- * @deprecated
667
+ * @deprecated use ast package instead
240
668
  */
241
669
  declare class FunctionParams {
242
670
  #private;
@@ -251,26 +679,20 @@ declare class FunctionParams {
251
679
  //#region src/utils/formatters.d.ts
252
680
  type Formatter = keyof typeof formatters;
253
681
  /**
254
- * Detect which formatter is available in the system.
255
- *
256
- * @returns Promise that resolves to the first available formatter or undefined if none are found
682
+ * Detects the first available code formatter on the current system.
257
683
  *
258
- * @remarks
259
- * Checks in order of preference: biome, oxfmt, prettier.
260
- * Uses the `--version` flag to detect if each formatter command is available.
261
- * This is a reliable method as all supported formatters implement this flag.
684
+ * - Checks in preference order: `biome`, `oxfmt`, `prettier`.
685
+ * - Returns `null` when none are found.
262
686
  *
263
687
  * @example
264
- * ```typescript
688
+ * ```ts
265
689
  * const formatter = await detectFormatter()
266
690
  * if (formatter) {
267
691
  * console.log(`Using ${formatter} for formatting`)
268
- * } else {
269
- * console.log('No formatter found')
270
692
  * }
271
693
  * ```
272
694
  */
273
- declare function detectFormatter(): Promise<Formatter | undefined>;
695
+ declare function detectFormatter(): Promise<Formatter | null>;
274
696
  //#endregion
275
697
  //#region src/utils/getBarrelFiles.d.ts
276
698
  type FileMetaBase = {
@@ -294,22 +716,102 @@ type AddIndexesProps = {
294
716
  };
295
717
  meta?: FileMetaBase;
296
718
  };
297
- declare function getBarrelFiles(files: Array<KubbFile.ResolvedFile>, {
719
+ /**
720
+ * Generates `index.ts` barrel files for all directories under `root/output.path`.
721
+ *
722
+ * - Returns an empty array when `type` is falsy or `'propagate'`.
723
+ * - Skips generation when the output path itself ends with `index` (already a barrel).
724
+ * - When `type` is `'all'`, strips named exports so every re-export becomes a wildcard (`export * from`).
725
+ * - Attaches `meta` to each barrel file for downstream plugin identification.
726
+ */
727
+ declare function getBarrelFiles(files: Array<FabricFile.ResolvedFile>, {
298
728
  type,
299
729
  meta,
300
730
  root,
301
731
  output
302
- }: AddIndexesProps): Promise<KubbFile.File[]>;
732
+ }: AddIndexesProps): Promise<Array<FabricFile.File>>;
303
733
  //#endregion
304
734
  //#region src/utils/getConfigs.d.ts
305
735
  /**
306
- * Converting UserConfig to Config Array without a change in the object beside the JSON convert.
736
+ * Resolves a {@link ConfigInput} into a normalized array of {@link Config} objects.
737
+ *
738
+ * - Awaits the config when it is a `Promise`.
739
+ * - Calls the factory function with `args` when the config is a function.
740
+ * - Wraps a single config object in an array for uniform downstream handling.
307
741
  */
308
742
  declare function getConfigs(config: ConfigInput | UserConfig, args: CLIOptions): Promise<Array<Config>>;
309
743
  //#endregion
744
+ //#region src/utils/getPreset.d.ts
745
+ type GetPresetParams<TResolver extends Resolver> = {
746
+ preset: CompatibilityPreset;
747
+ presets: Presets<TResolver>;
748
+ /**
749
+ * Optional single resolver whose methods override the preset resolver.
750
+ * When a method returns `null` or `undefined` the preset resolver's method is used instead.
751
+ */
752
+ resolver?: Partial<TResolver> & ThisType<TResolver>;
753
+ /**
754
+ * User-supplied generators to append after the preset's generators.
755
+ */
756
+ generators?: Array<Generator<any>>;
757
+ /**
758
+ * Optional single transformer visitor whose methods override the preset transformer.
759
+ * When a method returns `null` or `undefined` the preset transformer's method is used instead.
760
+ */
761
+ transformer?: Visitor;
762
+ };
763
+ type GetPresetResult<TResolver extends Resolver> = {
764
+ resolver: TResolver;
765
+ transformer: Visitor | undefined;
766
+ generators: Array<Generator<any>>;
767
+ preset: Preset<TResolver> | undefined;
768
+ };
769
+ /**
770
+ * Resolves a named preset into a resolver, transformer, and generators.
771
+ *
772
+ * - Selects the preset resolver; wraps it with user overrides using null/undefined fallback.
773
+ * - Composes the preset's transformers into a single visitor; wraps it with the user transformer using null/undefined fallback.
774
+ * - Combines preset generators with user-supplied generators; falls back to the `default` preset's generators when neither provides any.
775
+ */
776
+ declare function getPreset<TResolver extends Resolver = Resolver>(params: GetPresetParams<TResolver>): GetPresetResult<TResolver>;
777
+ //#endregion
310
778
  //#region src/utils/linters.d.ts
311
779
  type Linter = keyof typeof linters;
312
- declare function detectLinter(): Promise<Linter | undefined>;
780
+ /**
781
+ * Detects the first available linter on the current system.
782
+ *
783
+ * - Checks in preference order: `biome`, `oxlint`, `eslint`.
784
+ * - Returns `null` when none are found.
785
+ *
786
+ * @example
787
+ * ```ts
788
+ * const linter = await detectLinter()
789
+ * if (linter) {
790
+ * console.log(`Using ${linter} for linting`)
791
+ * }
792
+ * ```
793
+ */
794
+ declare function detectLinter(): Promise<Linter | null>;
795
+ //#endregion
796
+ //#region src/utils/packageJSON.d.ts
797
+ type DependencyName = string;
798
+ type DependencyVersion = string;
799
+ /**
800
+ * Returns `true` when the nearest `package.json` declares a dependency that
801
+ * satisfies the given semver range.
802
+ *
803
+ * - Searches both `dependencies` and `devDependencies`.
804
+ * - Accepts a string package name or a `RegExp` to match scoped/pattern packages.
805
+ * - Uses `semver.satisfies` for range comparison; returns `false` when the
806
+ * version string cannot be coerced into a valid semver.
807
+ *
808
+ * @example
809
+ * ```ts
810
+ * satisfiesDependency('react', '>=18') // true when react@18.x is installed
811
+ * satisfiesDependency(/^@tanstack\//, '>=5') // true when any @tanstack/* >=5 is found
812
+ * ```
813
+ */
814
+ declare function satisfiesDependency(dependency: DependencyName | RegExp, version: DependencyVersion, cwd?: string): boolean;
313
815
  //#endregion
314
- export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, BarrelType, type CLIOptions, Config, type ConfigInput, DefineStorage, DevtoolsOptions, type FileMetaBase, FunctionParams, type FunctionParamsAST, GetPluginFactoryOptions, Group, InputData, InputPath, KubbEvents, Logger, LoggerContext, LoggerOptions, Output, PackageManager, Plugin, PluginContext, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PluginParameter, PluginWithLifeCycle, Printer, PrinterFactoryOptions, PromiseManager, ResolveNameParams, ResolvePathParams, URLPath, UnknownUserPlugin, UserConfig, UserLogger, UserPlugin, UserPluginWithLifeCycle, build, build as default, defineAdapter, defineConfig, defineLogger, definePlugin, definePrinter, defineStorage, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, isInputPath, linters, logLevel, memoryStorage, safeBuild, setup };
816
+ export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, BarrelType, type CLIOptions, CompatibilityPreset, Config, type ConfigInput, DevtoolsOptions, Exclude, type FileMetaBase, FunctionParams, type FunctionParamsAST, Generator, GeneratorContext, Group, Include, InputData, InputPath, KubbEvents, Logger, LoggerContext, LoggerOptions, OperationHook, OperationsHook, Output, Override, Plugin, PluginContext, PluginDriver, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginParameter, PluginWithLifeCycle, Preset, Presets, Printer, PrinterFactoryOptions, PrinterPartial, ResolveBannerContext, ResolveNameParams, ResolveOptionsContext, ResolvePathOptions, ResolvePathParams, Resolver, ResolverContext, ResolverFileParams, ResolverPathParams, SchemaHook, Storage, URLPath, UserConfig, UserGroup, UserLogger, UserPlugin, UserPluginWithLifeCycle, UserResolver, build, build as default, buildDefaultBanner, composeTransformers, createAdapter, createPlugin, createStorage, defaultResolveBanner, defaultResolveFile, defaultResolveFooter, defaultResolveOptions, defaultResolvePath, defineConfig, defineGenerator, defineLogger, definePresets, definePrinter, defineResolver, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, getPreset, isInputPath, linters, logLevel, memoryStorage, mergeGenerators, safeBuild, satisfiesDependency, setup };
315
817
  //# sourceMappingURL=index.d.ts.map