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

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 (60) hide show
  1. package/dist/PluginDriver-D0dY_hpJ.d.ts +1986 -0
  2. package/dist/{chunk-ByKO4r7w.cjs → chunk-MlS0t1Af.cjs} +15 -0
  3. package/dist/chunk-O_arW02_.js +17 -0
  4. package/dist/hooks.cjs +13 -28
  5. package/dist/hooks.cjs.map +1 -1
  6. package/dist/hooks.d.ts +11 -37
  7. package/dist/hooks.js +14 -28
  8. package/dist/hooks.js.map +1 -1
  9. package/dist/index.cjs +1469 -831
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.ts +572 -191
  12. package/dist/index.js +1443 -826
  13. package/dist/index.js.map +1 -1
  14. package/package.json +7 -7
  15. package/src/Kubb.ts +38 -56
  16. package/src/KubbFile.ts +143 -0
  17. package/src/{PluginManager.ts → PluginDriver.ts} +159 -170
  18. package/src/build.ts +213 -65
  19. package/src/constants.ts +39 -6
  20. package/src/createAdapter.ts +25 -0
  21. package/src/createPlugin.ts +30 -0
  22. package/src/createStorage.ts +58 -0
  23. package/src/{config.ts → defineConfig.ts} +11 -16
  24. package/src/defineGenerator.ts +126 -0
  25. package/src/defineLogger.ts +13 -3
  26. package/src/defineParser.ts +57 -0
  27. package/src/definePresets.ts +16 -0
  28. package/src/defineResolver.ts +454 -0
  29. package/src/hooks/index.ts +1 -6
  30. package/src/hooks/useDriver.ts +11 -0
  31. package/src/hooks/useMode.ts +4 -4
  32. package/src/hooks/usePlugin.ts +3 -3
  33. package/src/index.ts +22 -10
  34. package/src/renderNode.tsx +25 -0
  35. package/src/storages/fsStorage.ts +2 -2
  36. package/src/storages/memoryStorage.ts +2 -2
  37. package/src/types.ts +639 -52
  38. package/src/utils/FunctionParams.ts +2 -2
  39. package/src/utils/TreeNode.ts +40 -2
  40. package/src/utils/diagnostics.ts +4 -1
  41. package/src/utils/executeStrategies.ts +29 -10
  42. package/src/utils/formatters.ts +10 -21
  43. package/src/utils/getBarrelFiles.ts +80 -10
  44. package/src/utils/getConfigs.ts +9 -23
  45. package/src/utils/getPreset.ts +78 -0
  46. package/src/utils/isInputPath.ts +8 -0
  47. package/src/utils/linters.ts +23 -3
  48. package/src/utils/packageJSON.ts +76 -0
  49. package/dist/chunk--u3MIqq1.js +0 -8
  50. package/dist/types-CiPWLv-5.d.ts +0 -1001
  51. package/src/BarrelManager.ts +0 -74
  52. package/src/PackageManager.ts +0 -180
  53. package/src/PromiseManager.ts +0 -40
  54. package/src/defineAdapter.ts +0 -22
  55. package/src/definePlugin.ts +0 -12
  56. package/src/defineStorage.ts +0 -56
  57. package/src/errors.ts +0 -1
  58. package/src/hooks/useKubb.ts +0 -22
  59. package/src/hooks/usePluginManager.ts +0 -11
  60. package/src/utils/getPlugins.ts +0 -23
package/dist/index.d.ts CHANGED
@@ -1,162 +1,544 @@
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";
1
+ import { n as __name } from "./chunk-O_arW02_.js";
2
+ import { $ as FunctionParams, 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 getBarrelFiles, 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 FileMetaBase, _ as LoggerContext, _t as KubbFile_d_exports, a as AdapterSource, at as Parser, b as OperationsHook, bt as ResolvedFile, c as Config, ct as Generator, d as GeneratorContext, dt as Storage, et as FunctionParamsAST, f as Group, ft as createStorage, g as Logger, gt as File, h as InputPath, ht as logLevel, i as AdapterFactoryOptions, it as KubbEvents, j as Presets, k as PluginWithLifeCycle, l as DevtoolsOptions, lt as defineGenerator, m as InputData, mt as linters, n as getMode, nt as ConfigInput, o as BarrelType, ot as UserParser, p as Include, pt as formatters, q as UserLogger, r as Adapter, rt as defineConfig, s as CompatibilityPreset, st as defineParser, t as PluginDriver, tt as CLIOptions, u as Exclude, ut as mergeGenerators, v as LoggerOptions, w as PluginContext, x as Output, xt as AsyncEventEmitter, y as OperationHook, yt as Path, z as ResolvePathParams } from "./PluginDriver-D0dY_hpJ.js";
3
+ import { composeTransformers, definePrinter } from "@kubb/ast";
4
+ import { Node, RootNode, Visitor } from "@kubb/ast/types";
5
+ import { Fabric } 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<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<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<Path, string>;
180
+ config: Config;
29
181
  };
182
+ /**
183
+ * Initializes all Kubb infrastructure for a build without executing any plugins.
184
+ *
185
+ * - Validates the input path (when applicable).
186
+ * - Applies config defaults (`root`, `output.*`, `devtools`).
187
+ * - Creates the Fabric instance and wires storage, format, and lint hooks.
188
+ * - Runs the adapter (if configured) to produce the universal `RootNode`.
189
+ * When no adapter is supplied and `@kubb/adapter-oas` is installed as an
190
+ *
191
+ * Pass the returned {@link SetupResult} directly to {@link safeBuild} or {@link build}
192
+ * via the `overrides` argument to reuse the same infrastructure across multiple runs.
193
+ */
30
194
  declare function setup(options: BuildOptions): Promise<SetupResult>;
195
+ /**
196
+ * Runs a full Kubb build and throws on any error or plugin failure.
197
+ *
198
+ * Internally delegates to {@link safeBuild} and rethrows collected errors.
199
+ * Pass an existing {@link SetupResult} via `overrides` to skip the setup phase.
200
+ */
31
201
  declare function build(options: BuildOptions, overrides?: SetupResult): Promise<BuildOutput>;
202
+ /**
203
+ * Runs a full Kubb build and captures errors instead of throwing.
204
+ *
205
+ * - Installs each plugin in order, recording failures in `failedPlugins`.
206
+ * - Generates the root barrel file when `output.barrelType` is set.
207
+ * - Writes all files through Fabric.
208
+ *
209
+ * Returns a {@link BuildOutput} even on failure — inspect `error` and
210
+ * `failedPlugins` to determine whether the build succeeded.
211
+ */
32
212
  declare function safeBuild(options: BuildOptions, overrides?: SetupResult): Promise<BuildOutput>;
33
213
  //#endregion
34
- //#region src/config.d.ts
214
+ //#region src/createAdapter.d.ts
35
215
  /**
36
- * CLI options derived from command-line flags.
216
+ * Builder type for an {@link Adapter} — takes options and returns the adapter instance.
37
217
  */
38
- type CLIOptions = {
39
- /** Path to `kubb.config.js` */config?: string; /** Enable watch mode for input files */
40
- watch?: boolean;
41
- /**
42
- * Logging verbosity for CLI usage.
43
- *
44
- * - `silent`: hide non-essential logs
45
- * - `info`: show general logs (non-plugin-related)
46
- * - `debug`: include detailed plugin lifecycle logs
47
- * @default 'silent'
48
- */
49
- logLevel?: 'silent' | 'info' | 'debug'; /** Run Kubb with Bun */
50
- bun?: boolean;
51
- };
52
- /** All accepted forms of a Kubb configuration. */
53
- type ConfigInput = PossiblePromise<UserConfig | UserConfig[]> | ((cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>);
218
+ type AdapterBuilder<T extends AdapterFactoryOptions> = (options: T['options']) => Adapter<T>;
54
219
  /**
55
- * Helper for defining a Kubb configuration.
56
- *
57
- * Accepts either:
58
- * - A config object or array of configs
59
- * - A function returning the config(s), optionally async,
60
- * receiving the CLI options as argument
220
+ * Creates an adapter factory. Call the returned function with optional options to get the adapter instance.
61
221
  *
62
222
  * @example
63
- * export default defineConfig(({ logLevel }) => ({
64
- * root: 'src',
65
- * plugins: [myPlugin()],
66
- * }))
223
+ * export const myAdapter = createAdapter<MyAdapter>((options) => {
224
+ * return {
225
+ * name: 'my-adapter',
226
+ * options,
227
+ * async parse(source) { ... },
228
+ * }
229
+ * })
230
+ *
231
+ * // instantiate
232
+ * const adapter = myAdapter({ validate: true })
67
233
  */
68
- declare function defineConfig(config: (cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>): typeof config;
69
- declare function defineConfig(config: PossiblePromise<UserConfig | UserConfig[]>): typeof config;
234
+ declare function createAdapter<T extends AdapterFactoryOptions = AdapterFactoryOptions>(build: AdapterBuilder<T>): (options?: T['options']) => Adapter<T>;
235
+ //#endregion
236
+ //#region src/createPlugin.d.ts
70
237
  /**
71
- * Type guard to check if a given config has an `input.path`.
238
+ * Builder type for a {@link UserPluginWithLifeCycle} takes options and returns the plugin instance.
72
239
  */
73
- declare function isInputPath(config: UserConfig | undefined): config is UserConfig<InputPath>;
74
- //#endregion
75
- //#region src/defineAdapter.d.ts
76
- type AdapterBuilder<T extends AdapterFactoryOptions> = (options: T['options']) => Adapter<T>;
240
+ type PluginBuilder<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => UserPluginWithLifeCycle<T>;
77
241
  /**
78
- * Wraps an adapter builder to make the options parameter optional.
242
+ * Creates a plugin factory. Call the returned function with optional options to get the plugin instance.
79
243
  *
80
244
  * @example
81
245
  * ```ts
82
- * export const adapterOas = defineAdapter<OasAdapter>((options) => {
83
- * const { validate = true, dateType = 'string' } = options
246
+ * export const myPlugin = createPlugin<MyPlugin>((options) => {
84
247
  * return {
85
- * name: adapterOasName,
86
- * options: { validate, dateType, ... },
87
- * parse(source) { ... },
248
+ * name: 'my-plugin',
249
+ * get options() { return options },
250
+ * resolvePath(baseName) { ... },
251
+ * resolveName(name, type) { ... },
88
252
  * }
89
253
  * })
254
+ *
255
+ * // instantiate
256
+ * const plugin = myPlugin({ output: { path: 'src/gen' } })
90
257
  * ```
91
258
  */
92
- declare function defineAdapter<T extends AdapterFactoryOptions = AdapterFactoryOptions>(build: AdapterBuilder<T>): (options?: T['options']) => Adapter<T>;
259
+ declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(build: PluginBuilder<T>): (options?: T['options']) => UserPluginWithLifeCycle<T>;
93
260
  //#endregion
94
261
  //#region src/defineLogger.d.ts
262
+ /**
263
+ * Wraps a logger definition into a typed {@link Logger}.
264
+ *
265
+ * @example
266
+ * export const myLogger = defineLogger({
267
+ * name: 'my-logger',
268
+ * install(context, options) {
269
+ * context.on('info', (message) => console.log('ℹ', message))
270
+ * context.on('error', (error) => console.error('✗', error.message))
271
+ * },
272
+ * })
273
+ */
95
274
  declare function defineLogger<Options extends LoggerOptions = LoggerOptions>(logger: UserLogger<Options>): Logger<Options>;
96
275
  //#endregion
97
- //#region src/definePlugin.d.ts
98
- type PluginBuilder<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => UserPluginWithLifeCycle<T>;
276
+ //#region src/definePresets.d.ts
99
277
  /**
100
- * Wraps a plugin builder to make the options parameter optional.
278
+ * Creates a typed presets registry object a named collection of {@link Preset} entries.
279
+ *
280
+ * @example
281
+ * import { definePreset, definePresets } from '@kubb/core'
282
+ * import { resolverTsLegacy } from '@kubb/plugin-ts'
283
+ *
284
+ * export const myPresets = definePresets({
285
+ * kubbV4: definePreset('kubbV4', { resolvers: [resolverTsLegacy] }),
286
+ * })
101
287
  */
102
- declare function definePlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(build: PluginBuilder<T>): (options?: T['options']) => UserPluginWithLifeCycle<T>;
288
+ declare function definePresets<TResolver extends Resolver = Resolver>(presets: Presets<TResolver>): Presets<TResolver>;
103
289
  //#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>>>>;
290
+ //#region src/defineResolver.d.ts
132
291
  /**
133
- * Chains promises
292
+ * Builder type for the plugin-specific resolver fields.
293
+ *
294
+ * `default`, `resolveOptions`, `resolvePath`, `resolveFile`, `resolveBanner`, and `resolveFooter`
295
+ * are optional — built-in fallbacks are injected when omitted.
134
296
  */
135
- type HookFirstOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue = unknown> = ValueOfPromiseFuncArray<TInput>;
297
+ 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'>> & {
298
+ name: string;
299
+ pluginName: T['name'];
300
+ } & ThisType<T['resolver']>;
136
301
  /**
137
- * Chains promises, first non-null result stops and returns
302
+ * Default option resolver applies include/exclude filters and merges matching override options.
303
+ *
304
+ * Returns `null` when the node is filtered out by an `exclude` rule or not matched by any `include` rule.
305
+ *
306
+ * @example Include/exclude filtering
307
+ * ```ts
308
+ * const options = defaultResolveOptions(operationNode, {
309
+ * options: { output: 'types' },
310
+ * exclude: [{ type: 'tag', pattern: 'internal' }],
311
+ * })
312
+ * // → null when node has tag 'internal'
313
+ * ```
314
+ *
315
+ * @example Override merging
316
+ * ```ts
317
+ * const options = defaultResolveOptions(operationNode, {
318
+ * options: { enumType: 'asConst' },
319
+ * override: [{ type: 'operationId', pattern: 'listPets', options: { enumType: 'enum' } }],
320
+ * })
321
+ * // → { enumType: 'enum' } when operationId matches
322
+ * ```
138
323
  */
139
- type HookParallelOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Promise<PromiseSettledResult<Awaited<ValueOfPromiseFuncArray<TInput>>>[]>;
324
+ declare function defaultResolveOptions<TOptions>(node: Node, {
325
+ options,
326
+ exclude,
327
+ include,
328
+ override
329
+ }: ResolveOptionsContext<TOptions>): TOptions | null;
140
330
  /**
141
- * Runs an array of promise functions with optional concurrency limit.
331
+ * Default path resolver used by `defineResolver`.
332
+ *
333
+ * - Returns the output directory in `single` mode.
334
+ * - Resolves into a tag- or path-based subdirectory when `group` and a `tag`/`path` value are provided.
335
+ * - Falls back to a flat `output/baseName` path otherwise.
336
+ *
337
+ * A custom `group.name` function overrides the default subdirectory naming.
338
+ * For `tag` groups the default is `${camelCase(tag)}Controller`.
339
+ * For `path` groups the default is the first path segment after `/`.
340
+ *
341
+ * @example Flat output
342
+ * ```ts
343
+ * defaultResolvePath({ baseName: 'petTypes.ts' }, { root: '/src', output: { path: 'types' } })
344
+ * // → '/src/types/petTypes.ts'
345
+ * ```
346
+ *
347
+ * @example Tag-based grouping
348
+ * ```ts
349
+ * defaultResolvePath(
350
+ * { baseName: 'petTypes.ts', tag: 'pets' },
351
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
352
+ * )
353
+ * // → '/src/types/petsController/petTypes.ts'
354
+ * ```
355
+ *
356
+ * @example Path-based grouping
357
+ * ```ts
358
+ * defaultResolvePath(
359
+ * { baseName: 'petTypes.ts', path: '/pets/list' },
360
+ * { root: '/src', output: { path: 'types' }, group: { type: 'path' } },
361
+ * )
362
+ * // → '/src/types/pets/petTypes.ts'
363
+ * ```
364
+ *
365
+ * @example Single-file mode
366
+ * ```ts
367
+ * defaultResolvePath(
368
+ * { baseName: 'petTypes.ts', pathMode: 'single' },
369
+ * { root: '/src', output: { path: 'types' } },
370
+ * )
371
+ * // → '/src/types'
372
+ * ```
142
373
  */
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
- }
374
+ declare function defaultResolvePath({
375
+ baseName,
376
+ pathMode,
377
+ tag,
378
+ path: groupPath
379
+ }: ResolverPathParams, {
380
+ root,
381
+ output,
382
+ group
383
+ }: ResolverContext): Path;
384
+ /**
385
+ * Default file resolver used by `defineResolver`.
386
+ *
387
+ * Resolves a `KubbFile.File` by combining name resolution (`resolver.default`) with
388
+ * path resolution (`resolver.resolvePath`). The resolved file always has empty
389
+ * `sources`, `imports`, and `exports` arrays — consumers populate those separately.
390
+ *
391
+ * In `single` mode the name is omitted and the file sits directly in the output directory.
392
+ *
393
+ * @example Resolve a schema file
394
+ * ```ts
395
+ * const file = defaultResolveFile.call(resolver,
396
+ * { name: 'pet', extname: '.ts' },
397
+ * { root: '/src', output: { path: 'types' } },
398
+ * )
399
+ * // → { baseName: 'pet.ts', path: '/src/types/pet.ts', sources: [], ... }
400
+ * ```
401
+ *
402
+ * @example Resolve an operation file with tag grouping
403
+ * ```ts
404
+ * const file = defaultResolveFile.call(resolver,
405
+ * { name: 'listPets', extname: '.ts', tag: 'pets' },
406
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
407
+ * )
408
+ * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
409
+ * ```
410
+ */
411
+ declare function defaultResolveFile(this: Resolver, {
412
+ name,
413
+ extname,
414
+ tag,
415
+ path: groupPath
416
+ }: ResolverFileParams, context: ResolverContext): File;
417
+ /**
418
+ * Generates the default "Generated by Kubb" banner from config and optional node metadata.
419
+ */
420
+ declare function buildDefaultBanner({
421
+ title,
422
+ description,
423
+ version,
424
+ config
425
+ }: {
426
+ title?: string;
427
+ description?: string;
428
+ version?: string;
429
+ config: Config;
430
+ }): string;
431
+ /**
432
+ * Default banner resolver — returns the banner string for a generated file.
433
+ *
434
+ * A user-supplied `output.banner` overrides the default Kubb "Generated by Kubb" notice.
435
+ * When no `output.banner` is set, the Kubb notice is used (including `title` and `version`
436
+ * from the OAS spec when a `node` is provided).
437
+ *
438
+ * - When `output.banner` is a function and `node` is provided, returns `output.banner(node)`.
439
+ * - When `output.banner` is a function and `node` is absent, falls back to the Kubb notice.
440
+ * - When `output.banner` is a string, returns it directly.
441
+ * - When `config.output.defaultBanner` is `false`, returns `undefined`.
442
+ * - Otherwise returns the Kubb "Generated by Kubb" notice.
443
+ *
444
+ * @example String banner overrides default
445
+ * ```ts
446
+ * defaultResolveBanner(undefined, { output: { banner: '// my banner' }, config })
447
+ * // → '// my banner'
448
+ * ```
449
+ *
450
+ * @example Function banner with node
451
+ * ```ts
452
+ * defaultResolveBanner(rootNode, { output: { banner: (node) => `// v${node.version}` }, config })
453
+ * // → '// v3.0.0'
454
+ * ```
455
+ *
456
+ * @example No user banner — Kubb notice with OAS metadata
457
+ * ```ts
458
+ * defaultResolveBanner(rootNode, { config })
459
+ * // → '/** Generated by Kubb ... Title: Pet Store ... *\/'
460
+ * ```
461
+ *
462
+ * @example Disabled default banner
463
+ * ```ts
464
+ * defaultResolveBanner(undefined, { config: { output: { defaultBanner: false }, ...config } })
465
+ * // → undefined
466
+ * ```
467
+ */
468
+ declare function defaultResolveBanner(node: RootNode | undefined, {
469
+ output,
470
+ config
471
+ }: ResolveBannerContext): string | undefined;
472
+ /**
473
+ * Default footer resolver — returns the footer string for a generated file.
474
+ *
475
+ * - When `output.footer` is a function and `node` is provided, calls it with the node.
476
+ * - When `output.footer` is a function and `node` is absent, returns `undefined`.
477
+ * - When `output.footer` is a string, returns it directly.
478
+ * - Otherwise returns `undefined`.
479
+ *
480
+ * @example String footer
481
+ * ```ts
482
+ * defaultResolveFooter(undefined, { output: { footer: '// end of file' }, config })
483
+ * // → '// end of file'
484
+ * ```
485
+ *
486
+ * @example Function footer with node
487
+ * ```ts
488
+ * defaultResolveFooter(rootNode, { output: { footer: (node) => `// ${node.title}` }, config })
489
+ * // → '// Pet Store'
490
+ * ```
491
+ */
492
+ declare function defaultResolveFooter(node: RootNode | undefined, {
493
+ output
494
+ }: ResolveBannerContext): string | undefined;
495
+ /**
496
+ * Defines a resolver for a plugin, injecting built-in defaults for name casing,
497
+ * include/exclude/override filtering, path resolution, and file construction.
498
+ *
499
+ * All four defaults can be overridden by providing them in the builder function:
500
+ * - `default` — name casing strategy (camelCase / PascalCase)
501
+ * - `resolveOptions` — include/exclude/override filtering
502
+ * - `resolvePath` — output path computation
503
+ * - `resolveFile` — full `KubbFile.File` construction
504
+ *
505
+ * Methods in the builder have access to `this` (the full resolver object), so they
506
+ * can call other resolver methods without circular imports.
507
+ *
508
+ * @example Basic resolver with naming helpers
509
+ * ```ts
510
+ * export const resolver = defineResolver<PluginTs>(() => ({
511
+ * name: 'default',
512
+ * resolveName(node) {
513
+ * return this.default(node.name, 'function')
514
+ * },
515
+ * resolveTypedName(node) {
516
+ * return this.default(node.name, 'type')
517
+ * },
518
+ * }))
519
+ * ```
520
+ *
521
+ * @example Override resolvePath for a custom output structure
522
+ * ```ts
523
+ * export const resolver = defineResolver<PluginTs>(() => ({
524
+ * name: 'custom',
525
+ * resolvePath({ baseName }, { root, output }) {
526
+ * return path.resolve(root, output.path, 'generated', baseName)
527
+ * },
528
+ * }))
529
+ * ```
530
+ *
531
+ * @example Use this.default inside a helper
532
+ * ```ts
533
+ * export const resolver = defineResolver<PluginTs>(() => ({
534
+ * name: 'default',
535
+ * resolveParamName(node, param) {
536
+ * return this.default(`${node.operationId} ${param.in} ${param.name}`, 'type')
537
+ * },
538
+ * }))
539
+ * ```
540
+ */
541
+ declare function defineResolver<T extends PluginFactoryOptions>(build: ResolverBuilder<T>): T['resolver'];
160
542
  //#endregion
161
543
  //#region src/storages/fsStorage.d.ts
162
544
  /**
@@ -182,7 +564,7 @@ declare class PromiseManager<TState = unknown> {
182
564
  * })
183
565
  * ```
184
566
  */
185
- declare const fsStorage: (options?: Record<string, never> | undefined) => DefineStorage;
567
+ declare const fsStorage: (options?: Record<string, never> | undefined) => Storage;
186
568
  //#endregion
187
569
  //#region src/storages/memoryStorage.d.ts
188
570
  /**
@@ -202,114 +584,113 @@ declare const fsStorage: (options?: Record<string, never> | undefined) => Define
202
584
  * })
203
585
  * ```
204
586
  */
205
- declare const memoryStorage: (options?: Record<string, never> | undefined) => DefineStorage;
206
- //#endregion
207
- //#region src/utils/FunctionParams.d.ts
208
- type FunctionParamsASTWithoutType = {
209
- name?: string;
210
- type?: string;
211
- /**
212
- * @default true
213
- */
214
- required?: boolean;
215
- /**
216
- * @default true
217
- */
218
- enabled?: boolean;
219
- default?: string;
220
- };
221
- type FunctionParamsASTWithType = {
222
- name?: never;
223
- type: string;
224
- /**
225
- * @default true
226
- */
227
- required?: boolean;
228
- /**
229
- * @default true
230
- */
231
- enabled?: boolean;
232
- default?: string;
233
- };
234
- /**
235
- * @deprecated
236
- */
237
- type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType;
238
- /**
239
- * @deprecated
240
- */
241
- declare class FunctionParams {
242
- #private;
243
- get items(): FunctionParamsAST[];
244
- add(item: FunctionParamsAST | Array<FunctionParamsAST | FunctionParamsAST[] | undefined> | undefined): FunctionParams;
245
- static toObject(items: FunctionParamsAST[]): FunctionParamsAST;
246
- toObject(): FunctionParamsAST;
247
- static toString(items: (FunctionParamsAST | FunctionParamsAST[])[]): string;
248
- toString(): string;
249
- }
587
+ declare const memoryStorage: (options?: Record<string, never> | undefined) => Storage;
250
588
  //#endregion
251
589
  //#region src/utils/formatters.d.ts
252
590
  type Formatter = keyof typeof formatters;
253
591
  /**
254
- * Detect which formatter is available in the system.
592
+ * Detects the first available code formatter on the current system.
255
593
  *
256
- * @returns Promise that resolves to the first available formatter or undefined if none are found
257
- *
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.
594
+ * - Checks in preference order: `biome`, `oxfmt`, `prettier`.
595
+ * - Returns `null` when none are found.
262
596
  *
263
597
  * @example
264
- * ```typescript
598
+ * ```ts
265
599
  * const formatter = await detectFormatter()
266
600
  * if (formatter) {
267
601
  * console.log(`Using ${formatter} for formatting`)
268
- * } else {
269
- * console.log('No formatter found')
270
602
  * }
271
603
  * ```
272
604
  */
273
- declare function detectFormatter(): Promise<Formatter | undefined>;
605
+ declare function detectFormatter(): Promise<Formatter | null>;
274
606
  //#endregion
275
- //#region src/utils/getBarrelFiles.d.ts
276
- type FileMetaBase = {
277
- pluginName?: string;
278
- };
279
- type AddIndexesProps = {
280
- type: BarrelType | false | undefined;
607
+ //#region src/utils/getConfigs.d.ts
608
+ /**
609
+ * Resolves a {@link ConfigInput} into a normalized array of {@link Config} objects.
610
+ *
611
+ * - Awaits the config when it is a `Promise`.
612
+ * - Calls the factory function with `args` when the config is a function.
613
+ * - Wraps a single config object in an array for uniform downstream handling.
614
+ */
615
+ declare function getConfigs(config: ConfigInput | UserConfig, args: CLIOptions): Promise<Array<Config>>;
616
+ //#endregion
617
+ //#region src/utils/getPreset.d.ts
618
+ type GetPresetParams<TResolver extends Resolver> = {
619
+ preset: CompatibilityPreset;
620
+ presets: Presets<TResolver>;
281
621
  /**
282
- * Root based on root and output.path specified in the config
622
+ * Optional single resolver whose methods override the preset resolver.
623
+ * When a method returns `null` or `undefined` the preset resolver's method is used instead.
283
624
  */
284
- root: string;
625
+ resolver?: Partial<TResolver> & ThisType<TResolver>;
285
626
  /**
286
- * Output for plugin
627
+ * User-supplied generators to append after the preset's generators.
287
628
  */
288
- output: {
289
- path: string;
290
- };
291
- group?: {
292
- output: string;
293
- exportAs: string;
294
- };
295
- meta?: FileMetaBase;
629
+ generators?: Array<Generator<any>>;
630
+ /**
631
+ * Optional single transformer visitor whose methods override the preset transformer.
632
+ * When a method returns `null` or `undefined` the preset transformer's method is used instead.
633
+ */
634
+ transformer?: Visitor;
296
635
  };
297
- declare function getBarrelFiles(files: Array<KubbFile.ResolvedFile>, {
298
- type,
299
- meta,
300
- root,
301
- output
302
- }: AddIndexesProps): Promise<KubbFile.File[]>;
636
+ type GetPresetResult<TResolver extends Resolver> = {
637
+ resolver: TResolver;
638
+ transformer: Visitor | undefined;
639
+ generators: Array<Generator<any>>;
640
+ preset: Preset<TResolver> | undefined;
641
+ };
642
+ /**
643
+ * Resolves a named preset into a resolver, transformer, and generators.
644
+ *
645
+ * - Selects the preset resolver; wraps it with user overrides using null/undefined fallback.
646
+ * - Composes the preset's transformers into a single visitor; wraps it with the user transformer using null/undefined fallback.
647
+ * - Combines preset generators with user-supplied generators; falls back to the `default` preset's generators when neither provides any.
648
+ */
649
+ declare function getPreset<TResolver extends Resolver = Resolver>(params: GetPresetParams<TResolver>): GetPresetResult<TResolver>;
303
650
  //#endregion
304
- //#region src/utils/getConfigs.d.ts
651
+ //#region src/utils/isInputPath.d.ts
305
652
  /**
306
- * Converting UserConfig to Config Array without a change in the object beside the JSON convert.
653
+ * Type guard to check if a given config has an `input.path`.
307
654
  */
308
- declare function getConfigs(config: ConfigInput | UserConfig, args: CLIOptions): Promise<Array<Config>>;
655
+ declare function isInputPath(config: UserConfig | undefined): config is UserConfig<InputPath>;
309
656
  //#endregion
310
657
  //#region src/utils/linters.d.ts
311
658
  type Linter = keyof typeof linters;
312
- declare function detectLinter(): Promise<Linter | undefined>;
659
+ /**
660
+ * Detects the first available linter on the current system.
661
+ *
662
+ * - Checks in preference order: `biome`, `oxlint`, `eslint`.
663
+ * - Returns `null` when none are found.
664
+ *
665
+ * @example
666
+ * ```ts
667
+ * const linter = await detectLinter()
668
+ * if (linter) {
669
+ * console.log(`Using ${linter} for linting`)
670
+ * }
671
+ * ```
672
+ */
673
+ declare function detectLinter(): Promise<Linter | null>;
674
+ //#endregion
675
+ //#region src/utils/packageJSON.d.ts
676
+ type DependencyName = string;
677
+ type DependencyVersion = string;
678
+ /**
679
+ * Returns `true` when the nearest `package.json` declares a dependency that
680
+ * satisfies the given semver range.
681
+ *
682
+ * - Searches both `dependencies` and `devDependencies`.
683
+ * - Accepts a string package name or a `RegExp` to match scoped/pattern packages.
684
+ * - Uses `semver.satisfies` for range comparison; returns `false` when the
685
+ * version string cannot be coerced into a valid semver.
686
+ *
687
+ * @example
688
+ * ```ts
689
+ * satisfiesDependency('react', '>=18') // true when react@18.x is installed
690
+ * satisfiesDependency(/^@tanstack\//, '>=5') // true when any @tanstack/* >=5 is found
691
+ * ```
692
+ */
693
+ declare function satisfiesDependency(dependency: DependencyName | RegExp, version: DependencyVersion, cwd?: string): boolean;
313
694
  //#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 };
695
+ export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, BarrelType, CLIOptions, CompatibilityPreset, Config, ConfigInput, DevtoolsOptions, Exclude, FileMetaBase, FunctionParams, FunctionParamsAST, Generator, GeneratorContext, Group, Include, InputData, InputPath, KubbEvents, KubbFile_d_exports as KubbFile, Logger, LoggerContext, LoggerOptions, OperationHook, OperationsHook, Output, Override, Parser, 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, UserParser, UserPlugin, UserPluginWithLifeCycle, UserResolver, build, build as default, buildDefaultBanner, composeTransformers, createAdapter, createPlugin, createStorage, defaultResolveBanner, defaultResolveFile, defaultResolveFooter, defaultResolveOptions, defaultResolvePath, defineConfig, defineGenerator, defineLogger, defineParser, definePresets, definePrinter, defineResolver, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, getPreset, isInputPath, linters, logLevel, memoryStorage, mergeGenerators, safeBuild, satisfiesDependency, setup };
315
696
  //# sourceMappingURL=index.d.ts.map