@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
@@ -1,1001 +0,0 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { EventEmitter } from "node:events";
3
- import { Fabric } from "@kubb/react-fabric";
4
- import { Printer, PrinterFactoryOptions, RootNode, SchemaNode } from "@kubb/ast/types";
5
- import { KubbFile } from "@kubb/fabric-core/types";
6
-
7
- //#region ../../internals/utils/dist/index.d.ts
8
- /**
9
- * A typed EventEmitter that awaits all async listeners before resolving.
10
- * Wraps Node's `EventEmitter` with full TypeScript event-map inference.
11
- */
12
- declare var AsyncEventEmitter: {
13
- new (maxListener?: number): {
14
- "__#private@#emitter": EventEmitter<[never]>;
15
- /**
16
- * Emits an event and awaits all registered listeners in parallel.
17
- * Throws if any listener rejects, wrapping the cause with the event name and serialized arguments.
18
- */
19
- emit(eventName: any, ...eventArgs: any[]): Promise<void>; /** Registers a persistent listener for the given event. */
20
- on(eventName: any, handler: any): void; /** Registers a one-shot listener that removes itself after the first invocation. */
21
- onOnce(eventName: any, handler: any): void; /** Removes a previously registered listener. */
22
- off(eventName: any, handler: any): void; /** Removes all listeners from every event channel. */
23
- removeAll(): void;
24
- };
25
- };
26
- /**
27
- * Parses and transforms an OpenAPI/Swagger path string into various URL formats.
28
- *
29
- * @example
30
- * const p = new URLPath('/pet/{petId}')
31
- * p.URL // '/pet/:petId'
32
- * p.template // '`/pet/${petId}`'
33
- */
34
- declare var URLPath: {
35
- new (path: any, options?: {}): {
36
- /** The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`. */path: any;
37
- "__#private@#options": {}; /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
38
- get URL(): any; /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`). */
39
- get isURL(): boolean;
40
- /**
41
- * Converts the OpenAPI path to a TypeScript template literal string.
42
- *
43
- * @example
44
- * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
45
- * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
46
- */
47
- get template(): string; /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set. */
48
- get object(): string | {
49
- url: any;
50
- params: {} | undefined;
51
- }; /** Returns a map of path parameter names, or `undefined` when the path has no parameters. */
52
- get params(): {} | undefined;
53
- "__#private@#transformParam"(raw: any): any; /** Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name. */
54
- "__#private@#eachParam"(fn: any): void;
55
- toObject({
56
- type,
57
- replacer,
58
- stringify
59
- }?: {
60
- type?: string | undefined;
61
- }): string | {
62
- url: any;
63
- params: {} | undefined;
64
- };
65
- /**
66
- * Converts the OpenAPI path to a TypeScript template literal string.
67
- * An optional `replacer` can transform each extracted parameter name before interpolation.
68
- *
69
- * @example
70
- * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
71
- */
72
- toTemplateString({
73
- prefix,
74
- replacer
75
- }?: {
76
- prefix?: string | undefined;
77
- }): string;
78
- /**
79
- * Extracts all `{param}` segments from the path and returns them as a key-value map.
80
- * An optional `replacer` transforms each parameter name in both key and value positions.
81
- * Returns `undefined` when no path parameters are found.
82
- */
83
- getParams(replacer: any): {} | undefined; /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
84
- toURLPath(): any;
85
- };
86
- };
87
- /**
88
- * Serializes a primitive value to a JSON string literal, stripping any surrounding quote characters first.
89
- *
90
- * @example
91
- * stringify('hello') // '"hello"'
92
- * stringify('"hello"') // '"hello"'
93
- */
94
- declare function stringify(value: any): string;
95
- //#endregion
96
- //#region src/constants.d.ts
97
- declare const DEFAULT_STUDIO_URL: "https://studio.kubb.dev";
98
- declare const logLevel: {
99
- readonly silent: number;
100
- readonly error: 0;
101
- readonly warn: 1;
102
- readonly info: 3;
103
- readonly verbose: 4;
104
- readonly debug: 5;
105
- };
106
- declare const linters: {
107
- readonly eslint: {
108
- readonly command: "eslint";
109
- readonly args: (outputPath: string) => string[];
110
- readonly errorMessage: "Eslint not found";
111
- };
112
- readonly biome: {
113
- readonly command: "biome";
114
- readonly args: (outputPath: string) => string[];
115
- readonly errorMessage: "Biome not found";
116
- };
117
- readonly oxlint: {
118
- readonly command: "oxlint";
119
- readonly args: (outputPath: string) => string[];
120
- readonly errorMessage: "Oxlint not found";
121
- };
122
- };
123
- declare const formatters: {
124
- readonly prettier: {
125
- readonly command: "prettier";
126
- readonly args: (outputPath: string) => string[];
127
- readonly errorMessage: "Prettier not found";
128
- };
129
- readonly biome: {
130
- readonly command: "biome";
131
- readonly args: (outputPath: string) => string[];
132
- readonly errorMessage: "Biome not found";
133
- };
134
- readonly oxfmt: {
135
- readonly command: "oxfmt";
136
- readonly args: (outputPath: string) => string[];
137
- readonly errorMessage: "Oxfmt not found";
138
- };
139
- };
140
- //#endregion
141
- //#region src/defineStorage.d.ts
142
- /**
143
- * Storage interface for persisting Kubb output.
144
- *
145
- * Keys are root-relative forward-slash paths (e.g. `src/gen/api/getPets.ts`).
146
- * Implement this interface to route generated files to any backend — filesystem,
147
- * S3, Redis, in-memory, etc.
148
- *
149
- * Use `defineStorage` to create a typed storage driver.
150
- */
151
- interface DefineStorage {
152
- /** Identifier used for logging and debugging (e.g. `'fs'`, `'s3'`). */
153
- readonly name: string;
154
- /** Returns `true` when an entry for `key` exists in storage. */
155
- hasItem(key: string): Promise<boolean>;
156
- /** Returns the stored string value, or `null` when `key` does not exist. */
157
- getItem(key: string): Promise<string | null>;
158
- /** Persists `value` under `key`, creating any required structure. */
159
- setItem(key: string, value: string): Promise<void>;
160
- /** Removes the entry for `key`. No-ops when the key does not exist. */
161
- removeItem(key: string): Promise<void>;
162
- /** Returns all keys, optionally filtered to those starting with `base`. */
163
- getKeys(base?: string): Promise<Array<string>>;
164
- /** Removes all entries, optionally scoped to those starting with `base`. */
165
- clear(base?: string): Promise<void>;
166
- /** Optional teardown hook called after the build completes. */
167
- dispose?(): Promise<void>;
168
- }
169
- /**
170
- * Wraps a storage builder so the `options` argument is optional, following the
171
- * same factory pattern as `definePlugin`, `defineLogger`, and `defineAdapter`.
172
- *
173
- * The builder receives the resolved options object and must return a
174
- * `DefineStorage`-compatible object that includes a `name` string.
175
- *
176
- * @example
177
- * ```ts
178
- * import { defineStorage } from '@kubb/core'
179
- *
180
- * export const memoryStorage = defineStorage((_options) => {
181
- * const store = new Map<string, string>()
182
- * return {
183
- * name: 'memory',
184
- * async hasItem(key) { return store.has(key) },
185
- * async getItem(key) { return store.get(key) ?? null },
186
- * async setItem(key, value) { store.set(key, value) },
187
- * async removeItem(key) { store.delete(key) },
188
- * async getKeys() { return [...store.keys()] },
189
- * async clear() { store.clear() },
190
- * }
191
- * })
192
- * ```
193
- */
194
- declare function defineStorage<TOptions = Record<string, never>>(build: (options: TOptions) => DefineStorage): (options?: TOptions) => DefineStorage;
195
- //#endregion
196
- //#region src/PluginManager.d.ts
197
- type RequiredPluginLifecycle = Required<PluginLifecycle>;
198
- type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
199
- type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
200
- type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
201
- result: Result;
202
- plugin: Plugin;
203
- };
204
- type Options = {
205
- fabric: Fabric;
206
- events: AsyncEventEmitter<KubbEvents>;
207
- /**
208
- * @default Number.POSITIVE_INFINITY
209
- */
210
- concurrency?: number;
211
- };
212
- type GetFileProps<TOptions = object> = {
213
- name: string;
214
- mode?: KubbFile.Mode;
215
- extname: KubbFile.Extname;
216
- pluginName: string;
217
- options?: TOptions;
218
- };
219
- declare function getMode(fileOrFolder: string | undefined | null): KubbFile.Mode;
220
- declare class PluginManager {
221
- #private;
222
- readonly config: Config;
223
- readonly options: Options;
224
- /**
225
- * The universal `@kubb/ast` `RootNode` produced by the adapter, set by
226
- * the build pipeline after the adapter's `parse()` resolves.
227
- */
228
- rootNode: RootNode | undefined;
229
- adapter: Adapter | undefined;
230
- constructor(config: Config, options: Options);
231
- get events(): AsyncEventEmitter<KubbEvents>;
232
- getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, unknown>;
233
- get plugins(): Array<Plugin>;
234
- getFile<TOptions = object>({
235
- name,
236
- mode,
237
- extname,
238
- pluginName,
239
- options
240
- }: GetFileProps<TOptions>): KubbFile.File<{
241
- pluginName: string;
242
- }>;
243
- resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
244
- resolveName: (params: ResolveNameParams) => string;
245
- /**
246
- * Run a specific hookName for plugin x.
247
- */
248
- hookForPlugin<H extends PluginLifecycleHooks>({
249
- pluginName,
250
- hookName,
251
- parameters
252
- }: {
253
- pluginName: string;
254
- hookName: H;
255
- parameters: PluginParameter<H>;
256
- }): Promise<Array<ReturnType<ParseResult<H>> | null>>;
257
- /**
258
- * Run a specific hookName for plugin x.
259
- */
260
- hookForPluginSync<H extends PluginLifecycleHooks>({
261
- pluginName,
262
- hookName,
263
- parameters
264
- }: {
265
- pluginName: string;
266
- hookName: H;
267
- parameters: PluginParameter<H>;
268
- }): Array<ReturnType<ParseResult<H>>> | null;
269
- /**
270
- * Returns the first non-null result.
271
- */
272
- hookFirst<H extends PluginLifecycleHooks>({
273
- hookName,
274
- parameters,
275
- skipped
276
- }: {
277
- hookName: H;
278
- parameters: PluginParameter<H>;
279
- skipped?: ReadonlySet<Plugin> | null;
280
- }): Promise<SafeParseResult<H>>;
281
- /**
282
- * Returns the first non-null result.
283
- */
284
- hookFirstSync<H extends PluginLifecycleHooks>({
285
- hookName,
286
- parameters,
287
- skipped
288
- }: {
289
- hookName: H;
290
- parameters: PluginParameter<H>;
291
- skipped?: ReadonlySet<Plugin> | null;
292
- }): SafeParseResult<H> | null;
293
- /**
294
- * Runs all plugins in parallel based on `this.plugin` order and `pre`/`post` settings.
295
- */
296
- hookParallel<H extends PluginLifecycleHooks, TOutput = void>({
297
- hookName,
298
- parameters
299
- }: {
300
- hookName: H;
301
- parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
302
- }): Promise<Awaited<TOutput>[]>;
303
- /**
304
- * Chains plugins
305
- */
306
- hookSeq<H extends PluginLifecycleHooks>({
307
- hookName,
308
- parameters
309
- }: {
310
- hookName: H;
311
- parameters?: PluginParameter<H>;
312
- }): Promise<void>;
313
- getPluginByName(pluginName: string): Plugin | undefined;
314
- getPluginsByName(hookName: keyof PluginWithLifeCycle, pluginName: string): Plugin[];
315
- }
316
- //#endregion
317
- //#region src/Kubb.d.ts
318
- type DebugEvent = {
319
- date: Date;
320
- logs: string[];
321
- fileName?: string;
322
- };
323
- type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
324
- hookName: H;
325
- plugins: Array<Plugin>;
326
- };
327
- type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
328
- hookName: H;
329
- };
330
- type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
331
- strategy: Strategy;
332
- hookName: H;
333
- plugin: Plugin;
334
- parameters?: unknown[] | undefined;
335
- output?: unknown;
336
- };
337
- type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
338
- duration: number;
339
- strategy: Strategy;
340
- hookName: H;
341
- plugin: Plugin;
342
- parameters?: unknown[] | undefined;
343
- output?: unknown;
344
- };
345
- /**
346
- * Events emitted during the Kubb code generation lifecycle.
347
- * These events can be listened to for logging, progress tracking, and custom integrations.
348
- *
349
- * @example
350
- * ```typescript
351
- * import type { AsyncEventEmitter } from '@kubb/core'
352
- * import type { KubbEvents } from '@kubb/core'
353
- *
354
- * const events: AsyncEventEmitter<KubbEvents> = new AsyncEventEmitter()
355
- *
356
- * events.on('lifecycle:start', () => {
357
- * console.log('Starting Kubb generation')
358
- * })
359
- *
360
- * events.on('plugin:end', (plugin, { duration }) => {
361
- * console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
362
- * })
363
- * ```
364
- */
365
- interface KubbEvents {
366
- /**
367
- * Emitted at the beginning of the Kubb lifecycle, before any code generation starts.
368
- */
369
- 'lifecycle:start': [version: string];
370
- /**
371
- * Emitted at the end of the Kubb lifecycle, after all code generation is complete.
372
- */
373
- 'lifecycle:end': [];
374
- /**
375
- * Emitted when configuration loading starts.
376
- */
377
- 'config:start': [];
378
- /**
379
- * Emitted when configuration loading is complete.
380
- */
381
- 'config:end': [configs: Array<Config>];
382
- /**
383
- * Emitted when code generation phase starts.
384
- */
385
- 'generation:start': [config: Config];
386
- /**
387
- * Emitted when code generation phase completes.
388
- */
389
- 'generation:end': [Config: Config, files: Array<KubbFile.ResolvedFile>, sources: Map<KubbFile.Path, string>];
390
- /**
391
- * Emitted with a summary of the generation results.
392
- * Contains summary lines, title, and success status.
393
- */
394
- 'generation:summary': [Config: Config, {
395
- failedPlugins: Set<{
396
- plugin: Plugin;
397
- error: Error;
398
- }>;
399
- status: 'success' | 'failed';
400
- hrStart: [number, number];
401
- filesCreated: number;
402
- pluginTimings?: Map<string, number>;
403
- }];
404
- /**
405
- * Emitted when code formatting starts (e.g., running Biome or Prettier).
406
- */
407
- 'format:start': [];
408
- /**
409
- * Emitted when code formatting completes.
410
- */
411
- 'format:end': [];
412
- /**
413
- * Emitted when linting starts.
414
- */
415
- 'lint:start': [];
416
- /**
417
- * Emitted when linting completes.
418
- */
419
- 'lint:end': [];
420
- /**
421
- * Emitted when plugin hooks execution starts.
422
- */
423
- 'hooks:start': [];
424
- /**
425
- * Emitted when plugin hooks execution completes.
426
- */
427
- 'hooks:end': [];
428
- /**
429
- * Emitted when a single hook execution starts. (e.g., format or lint).
430
- * The callback should be invoked when the command completes.
431
- */
432
- 'hook:start': [{
433
- id?: string;
434
- command: string;
435
- args?: readonly string[];
436
- }];
437
- /**
438
- * Emitted when a single hook execution completes.
439
- */
440
- 'hook:end': [{
441
- id?: string;
442
- command: string;
443
- args?: readonly string[];
444
- success: boolean;
445
- error: Error | null;
446
- }];
447
- /**
448
- * Emitted when a new version of Kubb is available.
449
- */
450
- 'version:new': [currentVersion: string, latestVersion: string];
451
- /**
452
- * Informational message event.
453
- */
454
- info: [message: string, info?: string];
455
- /**
456
- * Error event. Emitted when an error occurs during code generation.
457
- */
458
- error: [error: Error, meta?: Record<string, unknown>];
459
- /**
460
- * Success message event.
461
- */
462
- success: [message: string, info?: string];
463
- /**
464
- * Warning message event.
465
- */
466
- warn: [message: string, info?: string];
467
- /**
468
- * Debug event for detailed logging.
469
- * Contains timestamp, log messages, and optional filename.
470
- */
471
- debug: [meta: DebugEvent];
472
- /**
473
- * Emitted when file processing starts.
474
- * Contains the list of files to be processed.
475
- */
476
- 'files:processing:start': [files: Array<KubbFile.ResolvedFile>];
477
- /**
478
- * Emitted for each file being processed, providing progress updates.
479
- * Contains processed count, total count, percentage, and file details.
480
- */
481
- 'file:processing:update': [{
482
- /** Number of files processed so far */processed: number; /** Total number of files to process */
483
- total: number; /** Processing percentage (0-100) */
484
- percentage: number; /** Optional source identifier */
485
- source?: string; /** The file being processed */
486
- file: KubbFile.ResolvedFile;
487
- /**
488
- * Kubb configuration (not present in Fabric).
489
- * Provides access to the current config during file processing.
490
- */
491
- config: Config;
492
- }];
493
- /**
494
- * Emitted when file processing completes.
495
- * Contains the list of processed files.
496
- */
497
- 'files:processing:end': [files: KubbFile.ResolvedFile[]];
498
- /**
499
- * Emitted when a plugin starts executing.
500
- */
501
- 'plugin:start': [plugin: Plugin];
502
- /**
503
- * Emitted when a plugin completes execution.
504
- * Duration in ms
505
- */
506
- 'plugin:end': [plugin: Plugin, meta: {
507
- duration: number;
508
- success: boolean;
509
- error?: Error;
510
- }];
511
- /**
512
- * Emitted when plugin hook progress tracking starts.
513
- * Contains the hook name and list of plugins to execute.
514
- */
515
- 'plugins:hook:progress:start': [meta: ProgressStartMeta];
516
- /**
517
- * Emitted when plugin hook progress tracking ends.
518
- * Contains the hook name that completed.
519
- */
520
- 'plugins:hook:progress:end': [meta: ProgressStopMeta];
521
- /**
522
- * Emitted when a plugin hook starts processing.
523
- * Contains strategy, hook name, plugin, parameters, and output.
524
- */
525
- 'plugins:hook:processing:start': [meta: ExecutingMeta];
526
- /**
527
- * Emitted when a plugin hook completes processing.
528
- * Contains duration, strategy, hook name, plugin, parameters, and output.
529
- */
530
- 'plugins:hook:processing:end': [meta: ExecutedMeta];
531
- }
532
- //#endregion
533
- //#region src/types.d.ts
534
- declare global {
535
- namespace Kubb {
536
- interface PluginContext {}
537
- }
538
- }
539
- /**
540
- * Config used in `kubb.config.ts`
541
- *
542
- * @example
543
- * import { defineConfig } from '@kubb/core'
544
- * export default defineConfig({
545
- * ...
546
- * })
547
- */
548
- type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins'> & {
549
- /**
550
- * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
551
- * @default process.cwd()
552
- */
553
- root?: string;
554
- /**
555
- * An array of Kubb plugins used for generation. Each plugin may have additional configurable options (defined within the plugin itself). If a plugin relies on another plugin, an error will occur if the required dependency is missing. Refer to “pre” for more details.
556
- */
557
- plugins?: Array<Omit<UnknownUserPlugin, 'inject'>>;
558
- };
559
- type InputPath = {
560
- /**
561
- * Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
562
- */
563
- path: string;
564
- };
565
- type InputData = {
566
- /**
567
- * A `string` or `object` that contains your Swagger/OpenAPI data.
568
- */
569
- data: string | unknown;
570
- };
571
- type Input = InputPath | InputData | Array<InputPath>;
572
- /**
573
- * The raw source passed to an adapter's `parse` function.
574
- * Mirrors the shape of `Config['input']` with paths already resolved to absolute.
575
- */
576
- type AdapterSource = {
577
- type: 'path';
578
- path: string;
579
- } | {
580
- type: 'data';
581
- data: string | unknown;
582
- } | {
583
- type: 'paths';
584
- paths: Array<string>;
585
- };
586
- /**
587
- * Type parameters for an adapter definition.
588
- *
589
- * Mirrors `PluginFactoryOptions` but scoped to the adapter lifecycle:
590
- * - `TName` — unique string identifier (e.g. `'oas'`, `'asyncapi'`)
591
- * - `TOptions` — raw user-facing options passed to the adapter factory
592
- * - `TResolvedOptions` — defaults applied; what the adapter stores as `options`
593
- */
594
- type AdapterFactoryOptions<TName extends string = string, TOptions extends object = object, TResolvedOptions extends object = TOptions> = {
595
- name: TName;
596
- options: TOptions;
597
- resolvedOptions: TResolvedOptions;
598
- };
599
- /**
600
- * An adapter converts a source file or data into a `@kubb/ast` `RootNode`.
601
- *
602
- * Adapters are the single entry-point for different schema formats
603
- * (OpenAPI, AsyncAPI, Drizzle, …) and produce the universal `RootNode`
604
- * that all Kubb plugins consume.
605
- *
606
- * @example
607
- * ```ts
608
- * import { oasAdapter } from '@kubb/adapter-oas'
609
- *
610
- * export default defineConfig({
611
- * adapter: adapterOas(), // default — OpenAPI / Swagger
612
- * input: { path: './openapi.yaml' },
613
- * plugins: [pluginTs(), pluginZod()],
614
- * })
615
- * ```
616
- */
617
- type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
618
- /** Human-readable identifier, e.g. `'oas'`, `'drizzle'`, `'asyncapi'`. */name: TOptions['name']; /** Resolved options (after defaults have been applied). */
619
- options: TOptions['resolvedOptions']; /** Convert the raw source into a universal `RootNode`. */
620
- parse: (source: AdapterSource) => PossiblePromise<RootNode>;
621
- /**
622
- * Extracts `KubbFile.Import` entries needed by a `SchemaNode` tree.
623
- * Populated after the first `parse()` call. Returns an empty array before that.
624
- *
625
- * The `resolve` callback receives the collision-corrected schema name and must
626
- * return the `{ name, path }` pair for the import, or `undefined` to skip it.
627
- */
628
- getImports: (node: SchemaNode, resolve: (schemaName: string) => {
629
- name: string;
630
- path: string;
631
- }) => Array<KubbFile.Import>;
632
- };
633
- type BarrelType = 'all' | 'named' | 'propagate';
634
- type DevtoolsOptions = {
635
- /**
636
- * Open the AST inspector view (`/ast`) in Kubb Studio.
637
- * When `false`, opens the main Studio page instead.
638
- * @default false
639
- */
640
- ast?: boolean;
641
- };
642
- /**
643
- * @private
644
- */
645
- type Config<TInput = Input> = {
646
- /**
647
- * The name to display in the CLI output.
648
- */
649
- name?: string;
650
- /**
651
- * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
652
- * @default process.cwd()
653
- */
654
- root: string;
655
- /**
656
- * Adapter that converts the input file into a `@kubb/ast` `RootNode` — the universal
657
- * intermediate representation consumed by all Kubb plugins.
658
- *
659
- * - Omit (or pass `undefined`) to use the built-in OpenAPI/Swagger adapter.
660
- * - Use `@kubb/adapter-oas` for explicit OpenAPI configuration (validate, contentType, …).
661
- * - Use `@kubb/adapter-drizzle` or `@kubb/adapter-asyncapi` for other formats.
662
- *
663
- * @example
664
- * ```ts
665
- * import { drizzleAdapter } from '@kubb/adapter-drizzle'
666
- * export default defineConfig({
667
- * adapter: drizzleAdapter(),
668
- * input: { path: './src/schema.ts' },
669
- * })
670
- * ```
671
- */
672
- adapter?: Adapter;
673
- /**
674
- * You can use either `input.path` or `input.data`, depending on your specific needs.
675
- */
676
- input: TInput;
677
- output: {
678
- /**
679
- * The path where all generated files receives exported.
680
- * This can be an absolute path or a path relative to the specified root option.
681
- */
682
- path: string;
683
- /**
684
- * Clean the output directory before each build.
685
- */
686
- clean?: boolean;
687
- /**
688
- * Save files to the file system.
689
- * @default true
690
- * @deprecated Use `storage` to control where files are written.
691
- */
692
- write?: boolean;
693
- /**
694
- * Storage backend for generated files.
695
- * Defaults to `fsStorage()` — the built-in filesystem driver.
696
- * Accepts any object implementing the {@link DefineStorage} interface.
697
- * Keys are root-relative paths (e.g. `src/gen/api/getPets.ts`).
698
- * @default fsStorage()
699
- * @example
700
- * ```ts
701
- * import { defineStorage, fsStorage } from '@kubb/core'
702
- * storage: defineStorage(fsStorage())
703
- * ```
704
- */
705
- storage?: DefineStorage;
706
- /**
707
- * Specifies the formatting tool to be used.
708
- * - 'auto' automatically detects and uses biome or prettier (in that order of preference).
709
- * - 'prettier' uses Prettier for code formatting.
710
- * - 'biome' uses Biome for code formatting.
711
- * - 'oxfmt' uses Oxfmt for code formatting.
712
- * - false disables code formatting.
713
- * @default 'prettier'
714
- */
715
- format?: 'auto' | 'prettier' | 'biome' | 'oxfmt' | false;
716
- /**
717
- * Specifies the linter that should be used to analyze the code.
718
- * - 'auto' automatically detects and uses biome, oxlint, or eslint (in that order of preference).
719
- * - 'eslint' uses ESLint for linting.
720
- * - 'biome' uses Biome for linting.
721
- * - 'oxlint' uses Oxlint for linting.
722
- * - false disables linting.
723
- * @default 'auto'
724
- */
725
- lint?: 'auto' | 'eslint' | 'biome' | 'oxlint' | false;
726
- /**
727
- * Overrides the extension for generated imports and exports. By default, each plugin adds an extension.
728
- * @default { '.ts': '.ts'}
729
- */
730
- extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>;
731
- /**
732
- * Configures how `index.ts` files are created, including disabling barrel file generation. Each plugin has its own `barrelType` option; this setting controls the root barrel file (e.g., `src/gen/index.ts`).
733
- * @default 'named'
734
- */
735
- barrelType?: Exclude<BarrelType, 'propagate'> | false;
736
- /**
737
- * Adds a default banner to the start of every generated file indicating it was generated by Kubb.
738
- * - 'simple' adds banner with link to Kubb.
739
- * - 'full' adds source, title, description, and OpenAPI version.
740
- * - false disables banner generation.
741
- * @default 'simple'
742
- */
743
- defaultBanner?: 'simple' | 'full' | false;
744
- /**
745
- * Whether to override existing external files if they already exist.
746
- * When setting the option in the global configuration, all plugins inherit the same behavior by default.
747
- * However, all plugins also have an `output.override` option, which can be used to override the behavior for a specific plugin.
748
- * @default false
749
- */
750
- override?: boolean;
751
- };
752
- /**
753
- * An array of Kubb plugins that used in the generation.
754
- * Each plugin may include additional configurable options(defined in the plugin itself).
755
- * If a plugin depends on another plugin, an error is returned if the required dependency is missing. See pre for more details.
756
- */
757
- plugins?: Array<Plugin>;
758
- /**
759
- * Devtools configuration for Kubb Studio integration.
760
- */
761
- devtools?: true | {
762
- /**
763
- * Override the Kubb Studio base URL.
764
- * @default 'https://studio.kubb.dev'
765
- */
766
- studioUrl?: typeof DEFAULT_STUDIO_URL | (string & {});
767
- };
768
- /**
769
- * Hooks triggered when a specific action occurs in Kubb.
770
- */
771
- hooks?: {
772
- /**
773
- * Hook that triggers at the end of all executions.
774
- * Useful for running Prettier or ESLint to format/lint your code.
775
- */
776
- done?: string | Array<string>;
777
- };
778
- };
779
- type PluginFactoryOptions<
780
- /**
781
- * Name to be used for the plugin.
782
- */
783
- TName extends string = string,
784
- /**
785
- * Options of the plugin.
786
- */
787
- TOptions extends object = object,
788
- /**
789
- * Options of the plugin that can be used later on, see `options` inside your plugin config.
790
- */
791
- TResolvedOptions extends object = TOptions,
792
- /**
793
- * Context that you want to expose to other plugins.
794
- */
795
- TContext = unknown,
796
- /**
797
- * When calling `resolvePath` you can specify better types.
798
- */
799
- TResolvePathOptions extends object = object> = {
800
- name: TName;
801
- options: TOptions;
802
- resolvedOptions: TResolvedOptions;
803
- context: TContext;
804
- resolvePathOptions: TResolvePathOptions;
805
- };
806
- type GetPluginFactoryOptions<TPlugin extends UserPlugin> = TPlugin extends UserPlugin<infer X> ? X : never;
807
- type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
808
- /**
809
- * Unique name used for the plugin
810
- * The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
811
- * @example @kubb/typescript
812
- */
813
- name: TOptions['name'];
814
- /**
815
- * Options set for a specific plugin(see kubb.config.js), passthrough of options.
816
- */
817
- options: TOptions['resolvedOptions'];
818
- /**
819
- * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins.
820
- * Can be used to validate dependent plugins.
821
- */
822
- pre?: Array<string>;
823
- /**
824
- * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins.
825
- */
826
- post?: Array<string>;
827
- inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
828
- };
829
- type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
830
- type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<any, any, any, any, any>>;
831
- type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
832
- /**
833
- * Unique name used for the plugin
834
- * @example @kubb/typescript
835
- */
836
- name: TOptions['name'];
837
- /**
838
- * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin is executed after these plugins.
839
- * Can be used to validate dependent plugins.
840
- */
841
- pre?: Array<string>;
842
- /**
843
- * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin is executed before these plugins.
844
- */
845
- post?: Array<string>;
846
- /**
847
- * Options set for a specific plugin(see kubb.config.js), passthrough of options.
848
- */
849
- options: TOptions['resolvedOptions'];
850
- install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
851
- /**
852
- * Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
853
- */
854
- inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
855
- };
856
- type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
857
- type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
858
- /**
859
- * Start of the lifecycle of a plugin.
860
- * @type hookParallel
861
- */
862
- install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
863
- /**
864
- * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
865
- * Options can als be included.
866
- * @type hookFirst
867
- * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
868
- */
869
- resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path;
870
- /**
871
- * Resolve to a name based on a string.
872
- * Useful when converting to PascalCase or camelCase.
873
- * @type hookFirst
874
- * @example ('pet') => 'Pet'
875
- */
876
- resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
877
- };
878
- type PluginLifecycleHooks = keyof PluginLifecycle;
879
- type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
880
- type ResolvePathParams<TOptions = object> = {
881
- pluginName?: string;
882
- baseName: KubbFile.BaseName;
883
- mode?: KubbFile.Mode;
884
- /**
885
- * Options to be passed to 'resolvePath' 3th parameter
886
- */
887
- options?: TOptions;
888
- };
889
- type ResolveNameParams = {
890
- name: string;
891
- pluginName?: string;
892
- /**
893
- * Specifies the type of entity being named.
894
- * - 'file' customizes the name of the created file (uses camelCase).
895
- * - 'function' customizes the exported function names (uses camelCase).
896
- * - 'type' customizes TypeScript types (uses PascalCase).
897
- * - 'const' customizes variable names (uses camelCase).
898
- * @default undefined
899
- */
900
- type?: 'file' | 'function' | 'type' | 'const';
901
- };
902
- type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
903
- fabric: Fabric;
904
- config: Config;
905
- pluginManager: PluginManager;
906
- /**
907
- * Only add when the file does not exist yet
908
- */
909
- addFile: (...file: Array<KubbFile.File>) => Promise<void>;
910
- /**
911
- * merging multiple sources into the same output file
912
- */
913
- upsertFile: (...file: Array<KubbFile.File>) => Promise<void>;
914
- events: AsyncEventEmitter<KubbEvents>;
915
- mode: KubbFile.Mode;
916
- /**
917
- * Current plugin
918
- */
919
- plugin: Plugin<TOptions>;
920
- /**
921
- * Opens the Kubb Studio URL for the current `rootNode` in the default browser.
922
- * Falls back to printing the URL if the browser cannot be launched.
923
- * No-ops silently when no adapter has set a `rootNode`.
924
- */
925
- openInStudio: (options?: DevtoolsOptions) => Promise<void>;
926
- } & ({
927
- /**
928
- * Returns the universal `@kubb/ast` `RootNode` produced by the configured adapter.
929
- * Returns `undefined` when no adapter was set (legacy OAS-only usage).
930
- */
931
- rootNode: RootNode;
932
- /**
933
- * Return the adapter from `@kubb/ast`
934
- */
935
- adapter: Adapter;
936
- } | {
937
- rootNode?: never;
938
- adapter?: never;
939
- }) & Kubb.PluginContext;
940
- /**
941
- * Specify the export location for the files and define the behavior of the output
942
- */
943
- type Output<TOptions> = {
944
- /**
945
- * Path to the output folder or file that will contain the generated code
946
- */
947
- path: string;
948
- /**
949
- * Define what needs to be exported, here you can also disable the export of barrel files
950
- * @default 'named'
951
- */
952
- barrelType?: BarrelType | false;
953
- /**
954
- * Add a banner text in the beginning of every file
955
- */
956
- banner?: string | ((options: TOptions) => string);
957
- /**
958
- * Add a footer text in the beginning of every file
959
- */
960
- footer?: string | ((options: TOptions) => string);
961
- /**
962
- * Whether to override existing external files if they already exist.
963
- * @default false
964
- */
965
- override?: boolean;
966
- };
967
- type GroupContext = {
968
- group: string;
969
- };
970
- type Group = {
971
- /**
972
- * Defines the type where to group the files.
973
- * - 'tag' groups files by OpenAPI tags.
974
- * - 'path' groups files by OpenAPI paths.
975
- * @default undefined
976
- */
977
- type: 'tag' | 'path';
978
- /**
979
- * Return the name of a group based on the group name, this used for the file and name generation
980
- */
981
- name?: (context: GroupContext) => string;
982
- };
983
- type LoggerOptions = {
984
- /**
985
- * @default 3
986
- */
987
- logLevel: (typeof logLevel)[keyof typeof logLevel];
988
- };
989
- /**
990
- * Shared context passed to all plugins, parsers, and Fabric internals.
991
- */
992
- interface LoggerContext extends AsyncEventEmitter<KubbEvents> {}
993
- type Install<TOptions = unknown> = (context: LoggerContext, options?: TOptions) => void | Promise<void>;
994
- type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
995
- name: string;
996
- install: Install<TOptions>;
997
- };
998
- type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Omit<Logger<TOptions>, 'logLevel'>;
999
- //#endregion
1000
- export { UserPluginWithLifeCycle as A, URLPath as B, PrinterFactoryOptions as C, UserConfig as D, UnknownUserPlugin as E, defineStorage as F, formatters as I, linters as L, PluginManager as M, getMode as N, UserLogger as O, DefineStorage as P, logLevel as R, Printer as S, ResolvePathParams as T, PluginFactoryOptions as _, Config as a, PluginParameter as b, Group as c, Logger as d, LoggerContext as f, PluginContext as g, Plugin as h, BarrelType as i, KubbEvents as j, UserPlugin as k, InputData as l, Output as m, AdapterFactoryOptions as n, DevtoolsOptions as o, LoggerOptions as p, AdapterSource as r, GetPluginFactoryOptions as s, Adapter as t, InputPath as u, PluginLifecycle as v, ResolveNameParams as w, PluginWithLifeCycle as x, PluginLifecycleHooks as y, AsyncEventEmitter as z };
1001
- //# sourceMappingURL=types-CiPWLv-5.d.ts.map