@kubb/core 5.0.0-alpha.16 → 5.0.0-alpha.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,16 +1,158 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { A as ResolveOptionsContext, B as ReactGeneratorV2, C as PluginParameter, D as Printer, E as Presets, F as UserPlugin, G as formatters, H as KubbEvents, I as UserPluginWithLifeCycle, J as AsyncEventEmitter, K as linters, L as UserResolver, M as Resolver, N as UserConfig, O as PrinterFactoryOptions, P as UserLogger, R as CoreGeneratorV2, S as PluginLifecycleHooks, T as Preset, U as Storage, V as defineGenerator, W as createStorage, _ as Output, a as AdapterFactoryOptions, b as PluginFactoryOptions, c as CompatibilityPreset, d as Group, f as InputData, g as LoggerOptions, h as LoggerContext, i as Adapter, j as ResolvePathParams, k as ResolveNameParams, l as Config, m as Logger, n as PluginDriver, o as AdapterSource, p as InputPath, q as logLevel, r as getMode, s as BarrelType, u as DevtoolsOptions, v as Plugin, w as PluginWithLifeCycle, x as PluginLifecycle, y as PluginContext, z as Generator } from "./PluginDriver-CNKhDf-w.js";
2
+ import { A as ResolveOptionsContext, B as ReactGeneratorV2, C as PluginParameter, D as Printer, E as Presets, F as UserPlugin, G as formatters, H as KubbEvents, I as UserPluginWithLifeCycle, J as PossiblePromise, K as linters, L as UserResolver, M as Resolver, N as UserConfig, O as PrinterFactoryOptions, P as UserLogger, R as CoreGeneratorV2, S as PluginLifecycleHooks, T as Preset, U as Storage, V as defineGenerator, W as createStorage, Y as AsyncEventEmitter, _ as Output, a as AdapterFactoryOptions, b as PluginFactoryOptions, c as CompatibilityPreset, d as Group, f as InputData, g as LoggerOptions, h as LoggerContext, i as Adapter, j as ResolvePathParams, k as ResolveNameParams, l as Config, m as Logger, n as PluginDriver, o as AdapterSource, p as InputPath, q as logLevel, r as getMode, s as BarrelType, u as DevtoolsOptions, v as Plugin, w as PluginWithLifeCycle, x as PluginLifecycle, y as PluginContext, z as Generator } from "./PluginDriver-BRTrzfiD.js";
3
3
  import { definePrinter } from "@kubb/ast";
4
4
  import { Node, OperationNode, SchemaNode, Visitor } from "@kubb/ast/types";
5
5
  import { Fabric, KubbFile } from "@kubb/fabric-core/types";
6
6
  import { Fabric as Fabric$1 } from "@kubb/react-fabric/types";
7
7
 
8
+ //#region ../../internals/utils/src/urlPath.d.ts
9
+ type URLObject = {
10
+ /**
11
+ * The resolved URL string (Express-style or template literal, depending on context).
12
+ */
13
+ url: string;
14
+ /**
15
+ * Extracted path parameters as a key-value map, or `undefined` when the path has none.
16
+ */
17
+ params?: Record<string, string>;
18
+ };
19
+ type ObjectOptions = {
20
+ /**
21
+ * Controls whether the `url` is rendered as an Express path or a template literal.
22
+ * @default 'path'
23
+ */
24
+ type?: 'path' | 'template';
25
+ /**
26
+ * Optional transform applied to each extracted parameter name.
27
+ */
28
+ replacer?: (pathParam: string) => string;
29
+ /**
30
+ * When `true`, the result is serialized to a string expression instead of a plain object.
31
+ */
32
+ stringify?: boolean;
33
+ };
34
+ /**
35
+ * Supported identifier casing strategies for path parameters.
36
+ */
37
+ type PathCasing = 'camelcase';
38
+ type Options = {
39
+ /**
40
+ * Casing strategy applied to path parameter names.
41
+ * @default undefined (original identifier preserved)
42
+ */
43
+ casing?: PathCasing;
44
+ };
45
+ /**
46
+ * Parses and transforms an OpenAPI/Swagger path string into various URL formats.
47
+ *
48
+ * @example
49
+ * const p = new URLPath('/pet/{petId}')
50
+ * p.URL // '/pet/:petId'
51
+ * p.template // '`/pet/${petId}`'
52
+ */
53
+ declare class URLPath {
54
+ #private;
55
+ /**
56
+ * The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.
57
+ */
58
+ path: string;
59
+ constructor(path: string, options?: Options);
60
+ /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * new URLPath('/pet/{petId}').URL // '/pet/:petId'
65
+ * ```
66
+ */
67
+ get URL(): string;
68
+ /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
73
+ * new URLPath('/pet/{petId}').isURL // false
74
+ * ```
75
+ */
76
+ get isURL(): boolean;
77
+ /**
78
+ * Converts the OpenAPI path to a TypeScript template literal string.
79
+ *
80
+ * @example
81
+ * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
82
+ * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
83
+ */
84
+ get template(): string;
85
+ /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * new URLPath('/pet/{petId}').object
90
+ * // { url: '/pet/:petId', params: { petId: 'petId' } }
91
+ * ```
92
+ */
93
+ get object(): URLObject | string;
94
+ /** Returns a map of path parameter names, or `undefined` when the path has no parameters.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * new URLPath('/pet/{petId}').params // { petId: 'petId' }
99
+ * new URLPath('/pet').params // undefined
100
+ * ```
101
+ */
102
+ get params(): Record<string, string> | undefined;
103
+ toObject({
104
+ type,
105
+ replacer,
106
+ stringify
107
+ }?: ObjectOptions): URLObject | string;
108
+ /**
109
+ * Converts the OpenAPI path to a TypeScript template literal string.
110
+ * An optional `replacer` can transform each extracted parameter name before interpolation.
111
+ *
112
+ * @example
113
+ * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
114
+ */
115
+ toTemplateString({
116
+ prefix,
117
+ replacer
118
+ }?: {
119
+ prefix?: string;
120
+ replacer?: (pathParam: string) => string;
121
+ }): string;
122
+ /**
123
+ * Extracts all `{param}` segments from the path and returns them as a key-value map.
124
+ * An optional `replacer` transforms each parameter name in both key and value positions.
125
+ * Returns `undefined` when no path parameters are found.
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * new URLPath('/pet/{petId}/tag/{tagId}').getParams()
130
+ * // { petId: 'petId', tagId: 'tagId' }
131
+ * ```
132
+ */
133
+ getParams(replacer?: (pathParam: string) => string): Record<string, string> | undefined;
134
+ /** Converts the OpenAPI path to Express-style colon syntax.
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
139
+ * ```
140
+ */
141
+ toURLPath(): string;
142
+ }
143
+ //#endregion
8
144
  //#region src/build.d.ts
9
145
  type BuildOptions = {
10
146
  config: UserConfig;
11
147
  events?: AsyncEventEmitter<KubbEvents>;
12
148
  };
149
+ /**
150
+ * Full output produced by a successful or failed build.
151
+ */
13
152
  type BuildOutput = {
153
+ /**
154
+ * Plugins that threw during installation, paired with the caught error.
155
+ */
14
156
  failedPlugins: Set<{
15
157
  plugin: Plugin;
16
158
  error: Error;
@@ -18,18 +160,54 @@ type BuildOutput = {
18
160
  fabric: Fabric;
19
161
  files: Array<KubbFile.ResolvedFile>;
20
162
  driver: PluginDriver;
163
+ /**
164
+ * Elapsed time in milliseconds for each plugin, keyed by plugin name.
165
+ */
21
166
  pluginTimings: Map<string, number>;
22
167
  error?: Error;
168
+ /**
169
+ * Raw generated source, keyed by absolute file path.
170
+ */
23
171
  sources: Map<KubbFile.Path, string>;
24
172
  };
173
+ /**
174
+ * Intermediate result returned by {@link setup} and accepted by {@link safeBuild}.
175
+ */
25
176
  type SetupResult = {
26
177
  events: AsyncEventEmitter<KubbEvents>;
27
178
  fabric: Fabric;
28
179
  driver: PluginDriver;
29
180
  sources: Map<KubbFile.Path, string>;
30
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
+ *
190
+ * Pass the returned {@link SetupResult} directly to {@link safeBuild} or {@link build}
191
+ * via the `overrides` argument to reuse the same infrastructure across multiple runs.
192
+ */
31
193
  declare function setup(options: BuildOptions): Promise<SetupResult>;
194
+ /**
195
+ * Runs a full Kubb build and throws on any error or plugin failure.
196
+ *
197
+ * Internally delegates to {@link safeBuild} and rethrows collected errors.
198
+ * Pass an existing {@link SetupResult} via `overrides` to skip the setup phase.
199
+ */
32
200
  declare function build(options: BuildOptions, overrides?: SetupResult): Promise<BuildOutput>;
201
+ /**
202
+ * Runs a full Kubb build and captures errors instead of throwing.
203
+ *
204
+ * - Installs each plugin in order, recording failures in `failedPlugins`.
205
+ * - Generates the root barrel file when `output.barrelType` is set.
206
+ * - Writes all files through Fabric.
207
+ *
208
+ * Returns a {@link BuildOutput} even on failure — inspect `error` and
209
+ * `failedPlugins` to determine whether the build succeeded.
210
+ */
33
211
  declare function safeBuild(options: BuildOptions, overrides?: SetupResult): Promise<BuildOutput>;
34
212
  //#endregion
35
213
  //#region src/config.d.ts
@@ -37,7 +215,13 @@ declare function safeBuild(options: BuildOptions, overrides?: SetupResult): Prom
37
215
  * CLI options derived from command-line flags.
38
216
  */
39
217
  type CLIOptions = {
40
- /** Path to `kubb.config.js` */config?: string; /** Enable watch mode for input files */
218
+ /**
219
+ * Path to `kubb.config.js`.
220
+ */
221
+ config?: string;
222
+ /**
223
+ * Enable watch mode for input files.
224
+ */
41
225
  watch?: boolean;
42
226
  /**
43
227
  * Logging verbosity for CLI usage.
@@ -47,10 +231,11 @@ type CLIOptions = {
47
231
  * - `debug`: include detailed plugin lifecycle logs
48
232
  * @default 'silent'
49
233
  */
50
- logLevel?: 'silent' | 'info' | 'debug'; /** Run Kubb with Bun */
51
- bun?: boolean;
234
+ logLevel?: 'silent' | 'info' | 'debug';
52
235
  };
53
- /** All accepted forms of a Kubb configuration. */
236
+ /**
237
+ * All accepted forms of a Kubb configuration.
238
+ */
54
239
  type ConfigInput = PossiblePromise<UserConfig | UserConfig[]> | ((cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>);
55
240
  /**
56
241
  * Helper for defining a Kubb configuration.
@@ -347,26 +532,20 @@ declare class FunctionParams {
347
532
  //#region src/utils/formatters.d.ts
348
533
  type Formatter = keyof typeof formatters;
349
534
  /**
350
- * Detect which formatter is available in the system.
535
+ * Detects the first available code formatter on the current system.
351
536
  *
352
- * @returns Promise that resolves to the first available formatter or undefined if none are found
353
- *
354
- * @remarks
355
- * Checks in order of preference: biome, oxfmt, prettier.
356
- * Uses the `--version` flag to detect if each formatter command is available.
357
- * This is a reliable method as all supported formatters implement this flag.
537
+ * - Checks in preference order: `biome`, `oxfmt`, `prettier`.
538
+ * - Returns `null` when none are found.
358
539
  *
359
540
  * @example
360
- * ```typescript
541
+ * ```ts
361
542
  * const formatter = await detectFormatter()
362
543
  * if (formatter) {
363
544
  * console.log(`Using ${formatter} for formatting`)
364
- * } else {
365
- * console.log('No formatter found')
366
545
  * }
367
546
  * ```
368
547
  */
369
- declare function detectFormatter(): Promise<Formatter | undefined>;
548
+ declare function detectFormatter(): Promise<Formatter | null>;
370
549
  //#endregion
371
550
  //#region src/utils/getBarrelFiles.d.ts
372
551
  type FileMetaBase = {
@@ -390,6 +569,14 @@ type AddIndexesProps = {
390
569
  };
391
570
  meta?: FileMetaBase;
392
571
  };
572
+ /**
573
+ * Generates `index.ts` barrel files for all directories under `root/output.path`.
574
+ *
575
+ * - Returns an empty array when `type` is falsy or `'propagate'`.
576
+ * - Skips generation when the output path itself ends with `index` (already a barrel).
577
+ * - When `type` is `'all'`, strips named exports so every re-export becomes a wildcard (`export * from`).
578
+ * - Attaches `meta` to each barrel file for downstream plugin identification.
579
+ */
393
580
  declare function getBarrelFiles(files: Array<KubbFile.ResolvedFile>, {
394
581
  type,
395
582
  meta,
@@ -399,7 +586,11 @@ declare function getBarrelFiles(files: Array<KubbFile.ResolvedFile>, {
399
586
  //#endregion
400
587
  //#region src/utils/getConfigs.d.ts
401
588
  /**
402
- * Converting UserConfig to Config Array without a change in the object beside the JSON convert.
589
+ * Resolves a {@link ConfigInput} into a normalized array of {@link Config} objects.
590
+ *
591
+ * - Awaits the config when it is a `Promise`.
592
+ * - Calls the factory function with `args` when the config is a function.
593
+ * - Wraps a single config object in an array for uniform downstream handling.
403
594
  */
404
595
  declare function getConfigs(config: ConfigInput | UserConfig, args: CLIOptions): Promise<Array<Config>>;
405
596
  //#endregion
@@ -416,11 +607,32 @@ type GetPresetResult<TResolver extends Resolver> = {
416
607
  transformers: Array<Visitor>;
417
608
  preset: Preset<TResolver> | undefined;
418
609
  };
610
+ /**
611
+ * Resolves a named preset into merged resolvers and transformers.
612
+ *
613
+ * - Merges the preset's resolvers on top of the first (default) resolver to produce `baseResolver`.
614
+ * - Merges any additional user-supplied resolvers on top of that to produce the final `resolver`.
615
+ * - Concatenates preset transformers before user-supplied transformers.
616
+ */
419
617
  declare function getPreset<TResolver extends Resolver = Resolver>(params: GetPresetParams<TResolver>): GetPresetResult<TResolver>;
420
618
  //#endregion
421
619
  //#region src/utils/linters.d.ts
422
620
  type Linter = keyof typeof linters;
423
- declare function detectLinter(): Promise<Linter | undefined>;
621
+ /**
622
+ * Detects the first available linter on the current system.
623
+ *
624
+ * - Checks in preference order: `biome`, `oxlint`, `eslint`.
625
+ * - Returns `null` when none are found.
626
+ *
627
+ * @example
628
+ * ```ts
629
+ * const linter = await detectLinter()
630
+ * if (linter) {
631
+ * console.log(`Using ${linter} for linting`)
632
+ * }
633
+ * ```
634
+ */
635
+ declare function detectLinter(): Promise<Linter | null>;
424
636
  //#endregion
425
637
  //#region src/utils/mergeResolvers.d.ts
426
638
  /**
@@ -431,7 +643,22 @@ declare function mergeResolvers<T extends Resolver>(...resolvers: Array<T>): T;
431
643
  //#region src/utils/packageJSON.d.ts
432
644
  type DependencyName = string;
433
645
  type DependencyVersion = string;
646
+ /**
647
+ * Returns `true` when the nearest `package.json` declares a dependency that
648
+ * satisfies the given semver range.
649
+ *
650
+ * - Searches both `dependencies` and `devDependencies`.
651
+ * - Accepts a string package name or a `RegExp` to match scoped/pattern packages.
652
+ * - Uses `semver.satisfies` for range comparison; returns `false` when the
653
+ * version string cannot be coerced into a valid semver.
654
+ *
655
+ * @example
656
+ * ```ts
657
+ * satisfiesDependency('react', '>=18') // true when react@18.x is installed
658
+ * satisfiesDependency(/^@tanstack\//, '>=5') // true when any @tanstack/* >=5 is found
659
+ * ```
660
+ */
434
661
  declare function satisfiesDependency(dependency: DependencyName | RegExp, version: DependencyVersion, cwd?: string): boolean;
435
662
  //#endregion
436
- export { Adapter, AdapterFactoryOptions, AdapterSource, BarrelType, type CLIOptions, CompatibilityPreset, Config, type ConfigInput, CoreGeneratorV2, DevtoolsOptions, type FileMetaBase, FunctionParams, type FunctionParamsAST, Generator, Group, InputData, InputPath, KubbEvents, Logger, LoggerContext, LoggerOptions, Output, Plugin, PluginContext, PluginDriver, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginParameter, PluginWithLifeCycle, Preset, Presets, Printer, PrinterFactoryOptions, ReactGeneratorV2, ResolveNameParams, ResolveOptionsContext, ResolvePathParams, Resolver, Storage, UserConfig, UserLogger, UserPlugin, UserPluginWithLifeCycle, UserResolver, build, build as default, createAdapter, createPlugin, createStorage, defaultResolveOptions, defineConfig, defineGenerator, defineLogger, definePreset, definePresets, definePrinter, defineResolver, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, getPreset, isInputPath, linters, logLevel, memoryStorage, mergeResolvers, renderOperation, renderOperations, renderSchema, safeBuild, satisfiesDependency, setup };
663
+ export { Adapter, AdapterFactoryOptions, AdapterSource, AsyncEventEmitter, BarrelType, type CLIOptions, CompatibilityPreset, Config, type ConfigInput, CoreGeneratorV2, DevtoolsOptions, type FileMetaBase, FunctionParams, type FunctionParamsAST, Generator, Group, InputData, InputPath, KubbEvents, Logger, LoggerContext, LoggerOptions, Output, Plugin, PluginContext, PluginDriver, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginParameter, PluginWithLifeCycle, Preset, Presets, Printer, PrinterFactoryOptions, ReactGeneratorV2, ResolveNameParams, ResolveOptionsContext, ResolvePathParams, Resolver, Storage, URLPath, UserConfig, UserLogger, UserPlugin, UserPluginWithLifeCycle, UserResolver, build, build as default, createAdapter, createPlugin, createStorage, defaultResolveOptions, defineConfig, defineGenerator, defineLogger, definePreset, definePresets, definePrinter, defineResolver, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, getPreset, isInputPath, linters, logLevel, memoryStorage, mergeResolvers, renderOperation, renderOperations, renderSchema, safeBuild, satisfiesDependency, setup };
437
664
  //# sourceMappingURL=index.d.ts.map