@kubb/core 5.0.0-alpha.1 → 5.0.0-alpha.11

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 (48) hide show
  1. package/dist/{types-D30QAz2y.d.ts → PluginDriver-BkFepPdm.d.ts} +354 -291
  2. package/dist/hooks.cjs +85 -8
  3. package/dist/hooks.cjs.map +1 -1
  4. package/dist/hooks.d.ts +67 -4
  5. package/dist/hooks.js +83 -8
  6. package/dist/hooks.js.map +1 -1
  7. package/dist/index.cjs +422 -316
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.ts +134 -75
  10. package/dist/index.js +412 -307
  11. package/dist/index.js.map +1 -1
  12. package/package.json +6 -6
  13. package/src/Kubb.ts +27 -55
  14. package/src/{PluginManager.ts → PluginDriver.ts} +69 -82
  15. package/src/build.ts +37 -34
  16. package/src/constants.ts +1 -1
  17. package/src/createAdapter.ts +25 -0
  18. package/src/createPlugin.ts +28 -0
  19. package/src/createStorage.ts +58 -0
  20. package/src/defineGenerator.ts +134 -0
  21. package/src/defineLogger.ts +13 -3
  22. package/src/defineResolver.ts +131 -0
  23. package/src/hooks/index.ts +2 -1
  24. package/src/hooks/useKubb.ts +144 -0
  25. package/src/hooks/useMode.ts +5 -2
  26. package/src/hooks/usePlugin.ts +5 -2
  27. package/src/hooks/usePluginDriver.ts +11 -0
  28. package/src/index.ts +8 -7
  29. package/src/renderNode.tsx +108 -0
  30. package/src/storages/fsStorage.ts +2 -2
  31. package/src/storages/memoryStorage.ts +2 -2
  32. package/src/types.ts +94 -48
  33. package/src/utils/FunctionParams.ts +2 -2
  34. package/src/utils/TreeNode.ts +1 -1
  35. package/src/utils/formatters.ts +1 -1
  36. package/src/utils/getBarrelFiles.ts +73 -11
  37. package/src/utils/getConfigs.ts +3 -21
  38. package/src/utils/linters.ts +1 -1
  39. package/src/utils/packageJSON.ts +61 -0
  40. package/src/BarrelManager.ts +0 -74
  41. package/src/PackageManager.ts +0 -180
  42. package/src/PromiseManager.ts +0 -40
  43. package/src/defineAdapter.ts +0 -22
  44. package/src/definePlugin.ts +0 -12
  45. package/src/defineStorage.ts +0 -56
  46. package/src/errors.ts +0 -1
  47. package/src/hooks/usePluginManager.ts +0 -8
  48. package/src/utils/getPlugins.ts +0 -23
@@ -1,8 +1,8 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
2
  import { EventEmitter } from "node:events";
3
- import { Fabric } from "@kubb/react-fabric";
4
- import { KubbFile } from "@kubb/fabric-core/types";
5
- import { Printer, PrinterFactoryOptions, RootNode } from "@kubb/ast/types";
3
+ import { Node, OperationNode, Printer, PrinterFactoryOptions, RootNode, SchemaNode } from "@kubb/ast/types";
4
+ import { Fabric, KubbFile } from "@kubb/fabric-core/types";
5
+ import { FabricReactNode } from "@kubb/react-fabric/types";
6
6
 
7
7
  //#region ../../internals/utils/dist/index.d.ts
8
8
  /**
@@ -23,75 +23,6 @@ declare var AsyncEventEmitter: {
23
23
  removeAll(): void;
24
24
  };
25
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
26
  //#endregion
96
27
  //#region src/constants.d.ts
97
28
  declare const DEFAULT_STUDIO_URL: "https://studio.kubb.dev";
@@ -138,46 +69,46 @@ declare const formatters: {
138
69
  };
139
70
  };
140
71
  //#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'`). */
72
+ //#region src/createStorage.d.ts
73
+ type Storage = {
74
+ /**
75
+ * Identifier used for logging and debugging (e.g. `'fs'`, `'s3'`).
76
+ */
153
77
  readonly name: string;
154
- /** Returns `true` when an entry for `key` exists in storage. */
78
+ /**
79
+ * Returns `true` when an entry for `key` exists in storage.
80
+ */
155
81
  hasItem(key: string): Promise<boolean>;
156
- /** Returns the stored string value, or `null` when `key` does not exist. */
82
+ /**
83
+ * Returns the stored string value, or `null` when `key` does not exist.
84
+ */
157
85
  getItem(key: string): Promise<string | null>;
158
- /** Persists `value` under `key`, creating any required structure. */
86
+ /**
87
+ * Persists `value` under `key`, creating any required structure.
88
+ */
159
89
  setItem(key: string, value: string): Promise<void>;
160
- /** Removes the entry for `key`. No-ops when the key does not exist. */
90
+ /**
91
+ * Removes the entry for `key`. No-ops when the key does not exist.
92
+ */
161
93
  removeItem(key: string): Promise<void>;
162
- /** Returns all keys, optionally filtered to those starting with `base`. */
94
+ /**
95
+ * Returns all keys, optionally filtered to those starting with `base`.
96
+ */
163
97
  getKeys(base?: string): Promise<Array<string>>;
164
- /** Removes all entries, optionally scoped to those starting with `base`. */
98
+ /**
99
+ * Removes all entries, optionally scoped to those starting with `base`.
100
+ */
165
101
  clear(base?: string): Promise<void>;
166
- /** Optional teardown hook called after the build completes. */
102
+ /**
103
+ * Optional teardown hook called after the build completes.
104
+ */
167
105
  dispose?(): Promise<void>;
168
- }
106
+ };
169
107
  /**
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.
108
+ * Creates a storage factory. Call the returned function with optional options to get the storage instance.
175
109
  *
176
110
  * @example
177
- * ```ts
178
- * import { defineStorage } from '@kubb/core'
179
- *
180
- * export const memoryStorage = defineStorage((_options) => {
111
+ * export const memoryStorage = createStorage(() => {
181
112
  * const store = new Map<string, string>()
182
113
  * return {
183
114
  * name: 'memory',
@@ -185,160 +116,39 @@ interface DefineStorage {
185
116
  * async getItem(key) { return store.get(key) ?? null },
186
117
  * async setItem(key, value) { store.set(key, value) },
187
118
  * async removeItem(key) { store.delete(key) },
188
- * async getKeys() { return [...store.keys()] },
189
- * async clear() { store.clear() },
119
+ * async getKeys(base) {
120
+ * const keys = [...store.keys()]
121
+ * return base ? keys.filter((k) => k.startsWith(base)) : keys
122
+ * },
123
+ * async clear(base) { if (!base) store.clear() },
190
124
  * }
191
125
  * })
192
- * ```
193
126
  */
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
- pluginKey: Plugin['key'];
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
- constructor(config: Config, options: Options);
230
- get events(): AsyncEventEmitter<KubbEvents>;
231
- getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, unknown>;
232
- get plugins(): Array<Plugin>;
233
- getFile<TOptions = object>({
234
- name,
235
- mode,
236
- extname,
237
- pluginKey,
238
- options
239
- }: GetFileProps<TOptions>): KubbFile.File<{
240
- pluginKey: Plugin['key'];
241
- }>;
242
- resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
243
- resolveName: (params: ResolveNameParams) => string;
244
- /**
245
- * Run a specific hookName for plugin x.
246
- */
247
- hookForPlugin<H extends PluginLifecycleHooks>({
248
- pluginKey,
249
- hookName,
250
- parameters
251
- }: {
252
- pluginKey: Plugin['key'];
253
- hookName: H;
254
- parameters: PluginParameter<H>;
255
- }): Promise<Array<ReturnType<ParseResult<H>> | null>>;
256
- /**
257
- * Run a specific hookName for plugin x.
258
- */
259
- hookForPluginSync<H extends PluginLifecycleHooks>({
260
- pluginKey,
261
- hookName,
262
- parameters
263
- }: {
264
- pluginKey: Plugin['key'];
265
- hookName: H;
266
- parameters: PluginParameter<H>;
267
- }): Array<ReturnType<ParseResult<H>>> | null;
268
- /**
269
- * Returns the first non-null result.
270
- */
271
- hookFirst<H extends PluginLifecycleHooks>({
272
- hookName,
273
- parameters,
274
- skipped
275
- }: {
276
- hookName: H;
277
- parameters: PluginParameter<H>;
278
- skipped?: ReadonlySet<Plugin> | null;
279
- }): Promise<SafeParseResult<H>>;
280
- /**
281
- * Returns the first non-null result.
282
- */
283
- hookFirstSync<H extends PluginLifecycleHooks>({
284
- hookName,
285
- parameters,
286
- skipped
287
- }: {
288
- hookName: H;
289
- parameters: PluginParameter<H>;
290
- skipped?: ReadonlySet<Plugin> | null;
291
- }): SafeParseResult<H> | null;
292
- /**
293
- * Runs all plugins in parallel based on `this.plugin` order and `pre`/`post` settings.
294
- */
295
- hookParallel<H extends PluginLifecycleHooks, TOutput = void>({
296
- hookName,
297
- parameters
298
- }: {
299
- hookName: H;
300
- parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
301
- }): Promise<Awaited<TOutput>[]>;
302
- /**
303
- * Chains plugins
304
- */
305
- hookSeq<H extends PluginLifecycleHooks>({
306
- hookName,
307
- parameters
308
- }: {
309
- hookName: H;
310
- parameters?: PluginParameter<H>;
311
- }): Promise<void>;
312
- getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
313
- getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
314
- }
127
+ declare function createStorage<TOptions = Record<string, never>>(build: (options: TOptions) => Storage): (options?: TOptions) => Storage;
315
128
  //#endregion
316
129
  //#region src/Kubb.d.ts
317
- type DebugEvent = {
130
+ type DebugInfo = {
318
131
  date: Date;
319
- logs: string[];
132
+ logs: Array<string>;
320
133
  fileName?: string;
321
134
  };
322
- type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
135
+ type HookProgress<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
323
136
  hookName: H;
324
137
  plugins: Array<Plugin>;
325
138
  };
326
- type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
327
- hookName: H;
328
- };
329
- type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
139
+ type HookExecution<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
330
140
  strategy: Strategy;
331
141
  hookName: H;
332
142
  plugin: Plugin;
333
- parameters?: unknown[] | undefined;
143
+ parameters?: Array<unknown>;
334
144
  output?: unknown;
335
145
  };
336
- type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
146
+ type HookResult<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
337
147
  duration: number;
338
148
  strategy: Strategy;
339
149
  hookName: H;
340
150
  plugin: Plugin;
341
- parameters?: unknown[] | undefined;
151
+ parameters?: Array<unknown>;
342
152
  output?: unknown;
343
153
  };
344
154
  /**
@@ -347,7 +157,7 @@ type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
347
157
  *
348
158
  * @example
349
159
  * ```typescript
350
- * import type { AsyncEventEmitter } from '@kubb/core'
160
+ * import type { AsyncEventEmitter } from '@internals/utils'
351
161
  * import type { KubbEvents } from '@kubb/core'
352
162
  *
353
163
  * const events: AsyncEventEmitter<KubbEvents> = new AsyncEventEmitter()
@@ -385,12 +195,12 @@ interface KubbEvents {
385
195
  /**
386
196
  * Emitted when code generation phase completes.
387
197
  */
388
- 'generation:end': [Config: Config, files: Array<KubbFile.ResolvedFile>, sources: Map<KubbFile.Path, string>];
198
+ 'generation:end': [config: Config, files: Array<KubbFile.ResolvedFile>, sources: Map<KubbFile.Path, string>];
389
199
  /**
390
200
  * Emitted with a summary of the generation results.
391
201
  * Contains summary lines, title, and success status.
392
202
  */
393
- 'generation:summary': [Config: Config, {
203
+ 'generation:summary': [config: Config, {
394
204
  failedPlugins: Set<{
395
205
  plugin: Plugin;
396
206
  error: Error;
@@ -398,7 +208,7 @@ interface KubbEvents {
398
208
  status: 'success' | 'failed';
399
209
  hrStart: [number, number];
400
210
  filesCreated: number;
401
- pluginTimings?: Map<string, number>;
211
+ pluginTimings?: Map<Plugin['name'], number>;
402
212
  }];
403
213
  /**
404
214
  * Emitted when code formatting starts (e.g., running Biome or Prettier).
@@ -425,7 +235,7 @@ interface KubbEvents {
425
235
  */
426
236
  'hooks:end': [];
427
237
  /**
428
- * Emitted when a single hook execution starts. (e.g., format or lint).
238
+ * Emitted when a single hook execution starts (e.g., format or lint).
429
239
  * The callback should be invoked when the command completes.
430
240
  */
431
241
  'hook:start': [{
@@ -467,7 +277,7 @@ interface KubbEvents {
467
277
  * Debug event for detailed logging.
468
278
  * Contains timestamp, log messages, and optional filename.
469
279
  */
470
- debug: [meta: DebugEvent];
280
+ debug: [info: DebugInfo];
471
281
  /**
472
282
  * Emitted when file processing starts.
473
283
  * Contains the list of files to be processed.
@@ -478,10 +288,10 @@ interface KubbEvents {
478
288
  * Contains processed count, total count, percentage, and file details.
479
289
  */
480
290
  'file:processing:update': [{
481
- /** Number of files processed so far */processed: number; /** Total number of files to process */
482
- total: number; /** Processing percentage (0-100) */
483
- percentage: number; /** Optional source identifier */
484
- source?: string; /** The file being processed */
291
+ /** Number of files processed so far. */processed: number; /** Total number of files to process. */
292
+ total: number; /** Processing percentage (0100). */
293
+ percentage: number; /** Optional source identifier. */
294
+ source?: string; /** The file being processed. */
485
295
  file: KubbFile.ResolvedFile;
486
296
  /**
487
297
  * Kubb configuration (not present in Fabric).
@@ -493,16 +303,16 @@ interface KubbEvents {
493
303
  * Emitted when file processing completes.
494
304
  * Contains the list of processed files.
495
305
  */
496
- 'files:processing:end': [files: KubbFile.ResolvedFile[]];
306
+ 'files:processing:end': [files: Array<KubbFile.ResolvedFile>];
497
307
  /**
498
308
  * Emitted when a plugin starts executing.
499
309
  */
500
310
  'plugin:start': [plugin: Plugin];
501
311
  /**
502
312
  * Emitted when a plugin completes execution.
503
- * Duration in ms
313
+ * Duration in ms.
504
314
  */
505
- 'plugin:end': [plugin: Plugin, meta: {
315
+ 'plugin:end': [plugin: Plugin, result: {
506
316
  duration: number;
507
317
  success: boolean;
508
318
  error?: Error;
@@ -511,24 +321,111 @@ interface KubbEvents {
511
321
  * Emitted when plugin hook progress tracking starts.
512
322
  * Contains the hook name and list of plugins to execute.
513
323
  */
514
- 'plugins:hook:progress:start': [meta: ProgressStartMeta];
324
+ 'plugins:hook:progress:start': [progress: HookProgress];
515
325
  /**
516
326
  * Emitted when plugin hook progress tracking ends.
517
327
  * Contains the hook name that completed.
518
328
  */
519
- 'plugins:hook:progress:end': [meta: ProgressStopMeta];
329
+ 'plugins:hook:progress:end': [{
330
+ hookName: PluginLifecycleHooks;
331
+ }];
520
332
  /**
521
333
  * Emitted when a plugin hook starts processing.
522
334
  * Contains strategy, hook name, plugin, parameters, and output.
523
335
  */
524
- 'plugins:hook:processing:start': [meta: ExecutingMeta];
336
+ 'plugins:hook:processing:start': [execution: HookExecution];
525
337
  /**
526
338
  * Emitted when a plugin hook completes processing.
527
339
  * Contains duration, strategy, hook name, plugin, parameters, and output.
528
340
  */
529
- 'plugins:hook:processing:end': [meta: ExecutedMeta];
341
+ 'plugins:hook:processing:end': [result: HookResult];
530
342
  }
531
343
  //#endregion
344
+ //#region src/defineGenerator.d.ts
345
+ /**
346
+ * Props for the `operations` lifecycle — receives all operation nodes at once.
347
+ */
348
+ type OperationsV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
349
+ config: Config;
350
+ adapter: Adapter;
351
+ options: Plugin<TPlugin>['options'];
352
+ nodes: Array<OperationNode>;
353
+ };
354
+ /**
355
+ * Props for the `operation` lifecycle — receives a single operation node.
356
+ */
357
+ type OperationV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
358
+ config: Config;
359
+ adapter: Adapter;
360
+ options: Plugin<TPlugin>['options'];
361
+ node: OperationNode;
362
+ };
363
+ /**
364
+ * Props for the `schema` lifecycle — receives a single schema node.
365
+ */
366
+ type SchemaV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
367
+ config: Config;
368
+ adapter: Adapter;
369
+ options: Plugin<TPlugin>['options'];
370
+ node: SchemaNode;
371
+ };
372
+ type UserCoreGeneratorV2<TPlugin extends PluginFactoryOptions> = {
373
+ name: string;
374
+ type: 'core';
375
+ version?: '2';
376
+ operations?(props: OperationsV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
377
+ operation?(props: OperationV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
378
+ schema?(props: SchemaV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
379
+ };
380
+ type UserReactGeneratorV2<TPlugin extends PluginFactoryOptions> = {
381
+ name: string;
382
+ type: 'react';
383
+ version?: '2';
384
+ Operations?(props: OperationsV2Props<TPlugin>): FabricReactNode;
385
+ Operation?(props: OperationV2Props<TPlugin>): FabricReactNode;
386
+ Schema?(props: SchemaV2Props<TPlugin>): FabricReactNode;
387
+ };
388
+ type CoreGeneratorV2<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
389
+ name: string;
390
+ type: 'core';
391
+ version: '2';
392
+ operations(props: OperationsV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
393
+ operation(props: OperationV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
394
+ schema(props: SchemaV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
395
+ };
396
+ type ReactGeneratorV2<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
397
+ name: string;
398
+ type: 'react';
399
+ version: '2';
400
+ Operations(props: OperationsV2Props<TPlugin>): FabricReactNode;
401
+ Operation(props: OperationV2Props<TPlugin>): FabricReactNode;
402
+ Schema(props: SchemaV2Props<TPlugin>): FabricReactNode;
403
+ };
404
+ type Generator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = UserCoreGeneratorV2<TPlugin> | UserReactGeneratorV2<TPlugin>;
405
+ /**
406
+ * Defines a generator with no-op defaults for any omitted lifecycle methods.
407
+ * Works for both `core` (async file output) and `react` (JSX component) generators.
408
+ *
409
+ * @example
410
+ * // react generator
411
+ * export const typeGenerator = defineGenerator<PluginTs>({
412
+ * name: 'typescript',
413
+ * type: 'react',
414
+ * Operation({ node, options }) { return <File>...</File> },
415
+ * Schema({ node, options }) { return <File>...</File> },
416
+ * })
417
+ *
418
+ * @example
419
+ * // core generator
420
+ * export const myGenerator = defineGenerator<MyPlugin>({
421
+ * name: 'my-generator',
422
+ * type: 'core',
423
+ * async operation({ node, options }) { return [{ path: '...', content: '...' }] },
424
+ * })
425
+ */
426
+ declare function defineGenerator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions>(generator: UserReactGeneratorV2<TPlugin>): ReactGeneratorV2<TPlugin>;
427
+ declare function defineGenerator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions>(generator: UserCoreGeneratorV2<TPlugin>): CoreGeneratorV2<TPlugin>;
428
+ //#endregion
532
429
  //#region src/types.d.ts
533
430
  declare global {
534
431
  namespace Kubb {
@@ -617,6 +514,17 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
617
514
  /** Human-readable identifier, e.g. `'oas'`, `'drizzle'`, `'asyncapi'`. */name: TOptions['name']; /** Resolved options (after defaults have been applied). */
618
515
  options: TOptions['resolvedOptions']; /** Convert the raw source into a universal `RootNode`. */
619
516
  parse: (source: AdapterSource) => PossiblePromise<RootNode>;
517
+ /**
518
+ * Extracts `KubbFile.Import` entries needed by a `SchemaNode` tree.
519
+ * Populated after the first `parse()` call. Returns an empty array before that.
520
+ *
521
+ * The `resolve` callback receives the collision-corrected schema name and must
522
+ * return the `{ name, path }` pair for the import, or `undefined` to skip it.
523
+ */
524
+ getImports: (node: SchemaNode, resolve: (schemaName: string) => {
525
+ name: string;
526
+ path: string;
527
+ }) => Array<KubbFile.Import>;
620
528
  };
621
529
  type BarrelType = 'all' | 'named' | 'propagate';
622
530
  type DevtoolsOptions = {
@@ -681,16 +589,16 @@ type Config<TInput = Input> = {
681
589
  /**
682
590
  * Storage backend for generated files.
683
591
  * Defaults to `fsStorage()` — the built-in filesystem driver.
684
- * Accepts any object implementing the {@link DefineStorage} interface.
592
+ * Accepts any object implementing the {@link Storage} interface.
685
593
  * Keys are root-relative paths (e.g. `src/gen/api/getPets.ts`).
686
594
  * @default fsStorage()
687
595
  * @example
688
596
  * ```ts
689
- * import { defineStorage, fsStorage } from '@kubb/core'
690
- * storage: defineStorage(fsStorage())
597
+ * import { memoryStorage } from '@kubb/core'
598
+ * storage: memoryStorage()
691
599
  * ```
692
600
  */
693
- storage?: DefineStorage;
601
+ storage?: Storage;
694
602
  /**
695
603
  * Specifies the formatting tool to be used.
696
604
  * - 'auto' automatically detects and uses biome or prettier (in that order of preference).
@@ -764,9 +672,42 @@ type Config<TInput = Input> = {
764
672
  done?: string | Array<string>;
765
673
  };
766
674
  };
675
+ type PatternFilter = {
676
+ type: string;
677
+ pattern: string | RegExp;
678
+ };
679
+ type PatternOverride<TOptions> = PatternFilter & {
680
+ options: Omit<Partial<TOptions>, 'override'>;
681
+ };
682
+ type ResolveOptionsContext<TOptions> = {
683
+ options: TOptions;
684
+ exclude?: Array<PatternFilter>;
685
+ include?: Array<PatternFilter>;
686
+ override?: Array<PatternOverride<TOptions>>;
687
+ };
688
+ /**
689
+ * Base constraint for all plugin resolver objects.
690
+ *
691
+ * `default` and `resolveOptions` are injected automatically by `defineResolver` — plugin
692
+ * authors may override them but never need to implement them from scratch.
693
+ * Concrete plugin resolver types extend this with their own helper methods.
694
+ */
695
+ type Resolver = {
696
+ default(name: ResolveNameParams['name'], type?: ResolveNameParams['type']): string;
697
+ resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null;
698
+ };
699
+ /**
700
+ * The user-facing subset of a `Resolver` — everything except the methods injected by
701
+ * `defineResolver` (`default` and `resolveOptions`).
702
+ *
703
+ * When you pass a `UserResolver` to `defineResolver`, the standard `default` and
704
+ * `resolveOptions` implementations are injected automatically so plugin authors never
705
+ * need to define them by hand. Both can still be overridden by providing them explicitly.
706
+ */
707
+ type UserResolver = Omit<Resolver, 'default' | 'resolveOptions'>;
767
708
  type PluginFactoryOptions<
768
709
  /**
769
- * Name to be used for the plugin, this will also be used for they key.
710
+ * Name to be used for the plugin.
770
711
  */
771
712
  TName extends string = string,
772
713
  /**
@@ -784,19 +725,19 @@ TContext = unknown,
784
725
  /**
785
726
  * When calling `resolvePath` you can specify better types.
786
727
  */
787
- TResolvePathOptions extends object = object> = {
728
+ TResolvePathOptions extends object = object,
729
+ /**
730
+ * Resolver object that encapsulates the naming and path-resolution helpers used by this plugin.
731
+ * Use `defineResolver` to define the resolver object and export it alongside the plugin.
732
+ */
733
+ TResolver extends Resolver = Resolver> = {
788
734
  name: TName;
789
- /**
790
- * Same behavior like what has been done with `QueryKey` in `@tanstack/react-query`
791
- */
792
- key: PluginKey<TName | string>;
793
735
  options: TOptions;
794
736
  resolvedOptions: TResolvedOptions;
795
737
  context: TContext;
796
738
  resolvePathOptions: TResolvePathOptions;
739
+ resolver: TResolver;
797
740
  };
798
- type PluginKey<TName> = [name: TName, identifier?: string | number];
799
- type GetPluginFactoryOptions<TPlugin extends UserPlugin> = TPlugin extends UserPlugin<infer X> ? X : never;
800
741
  type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
801
742
  /**
802
743
  * Unique name used for the plugin
@@ -820,18 +761,13 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
820
761
  inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
821
762
  };
822
763
  type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
823
- type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<any, any, any, any, any>>;
764
+ type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<string, object, object, unknown, object>>;
824
765
  type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
825
766
  /**
826
767
  * Unique name used for the plugin
827
768
  * @example @kubb/typescript
828
769
  */
829
770
  name: TOptions['name'];
830
- /**
831
- * Internal key used when a developer uses more than one of the same plugin
832
- * @private
833
- */
834
- key: TOptions['key'];
835
771
  /**
836
772
  * 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.
837
773
  * Can be used to validate dependent plugins.
@@ -847,7 +783,7 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
847
783
  options: TOptions['resolvedOptions'];
848
784
  install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
849
785
  /**
850
- * Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
786
+ * Defines a context that can be used by other plugins, see `PluginDriver` where we convert from `UserPlugin` to `Plugin` (used when calling `createPlugin`).
851
787
  */
852
788
  inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
853
789
  };
@@ -876,7 +812,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
876
812
  type PluginLifecycleHooks = keyof PluginLifecycle;
877
813
  type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
878
814
  type ResolvePathParams<TOptions = object> = {
879
- pluginKey?: Plugin['key'];
815
+ pluginName?: string;
880
816
  baseName: KubbFile.BaseName;
881
817
  mode?: KubbFile.Mode;
882
818
  /**
@@ -886,7 +822,7 @@ type ResolvePathParams<TOptions = object> = {
886
822
  };
887
823
  type ResolveNameParams = {
888
824
  name: string;
889
- pluginKey?: Plugin['key'];
825
+ pluginName?: string;
890
826
  /**
891
827
  * Specifies the type of entity being named.
892
828
  * - 'file' customizes the name of the created file (uses camelCase).
@@ -900,7 +836,7 @@ type ResolveNameParams = {
900
836
  type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
901
837
  fabric: Fabric;
902
838
  config: Config;
903
- pluginManager: PluginManager;
839
+ driver: PluginDriver;
904
840
  /**
905
841
  * Only add when the file does not exist yet
906
842
  */
@@ -915,18 +851,26 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
915
851
  * Current plugin
916
852
  */
917
853
  plugin: Plugin<TOptions>;
918
- /**
919
- * Returns the universal `@kubb/ast` `RootNode` produced by the configured adapter.
920
- * Returns `undefined` when no adapter was set (legacy OAS-only usage).
921
- */
922
- rootNode: RootNode | undefined;
923
854
  /**
924
855
  * Opens the Kubb Studio URL for the current `rootNode` in the default browser.
925
856
  * Falls back to printing the URL if the browser cannot be launched.
926
857
  * No-ops silently when no adapter has set a `rootNode`.
927
858
  */
928
859
  openInStudio: (options?: DevtoolsOptions) => Promise<void>;
929
- } & Kubb.PluginContext;
860
+ } & ({
861
+ /**
862
+ * Returns the universal `@kubb/ast` `RootNode` produced by the configured adapter.
863
+ * Returns `undefined` when no adapter was set (legacy OAS-only usage).
864
+ */
865
+ rootNode: RootNode;
866
+ /**
867
+ * Return the adapter from `@kubb/ast`
868
+ */
869
+ adapter: Adapter;
870
+ } | {
871
+ rootNode?: never;
872
+ adapter?: never;
873
+ }) & Kubb.PluginContext;
930
874
  /**
931
875
  * Specify the export location for the files and define the behavior of the output
932
876
  */
@@ -954,9 +898,6 @@ type Output<TOptions> = {
954
898
  */
955
899
  override?: boolean;
956
900
  };
957
- type GroupContext = {
958
- group: string;
959
- };
960
901
  type Group = {
961
902
  /**
962
903
  * Defines the type where to group the files.
@@ -966,9 +907,11 @@ type Group = {
966
907
  */
967
908
  type: 'tag' | 'path';
968
909
  /**
969
- * Return the name of a group based on the group name, this used for the file and name generation
910
+ * Return the name of a group based on the group name, this is used for the file and name generation.
970
911
  */
971
- name?: (context: GroupContext) => string;
912
+ name?: (context: {
913
+ group: string;
914
+ }) => string;
972
915
  };
973
916
  type LoggerOptions = {
974
917
  /**
@@ -979,13 +922,133 @@ type LoggerOptions = {
979
922
  /**
980
923
  * Shared context passed to all plugins, parsers, and Fabric internals.
981
924
  */
982
- interface LoggerContext extends AsyncEventEmitter<KubbEvents> {}
983
- type Install<TOptions = unknown> = (context: LoggerContext, options?: TOptions) => void | Promise<void>;
925
+ type LoggerContext = AsyncEventEmitter<KubbEvents>;
984
926
  type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
985
927
  name: string;
986
- install: Install<TOptions>;
928
+ install: (context: LoggerContext, options?: TOptions) => void | Promise<void>;
929
+ };
930
+ type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Logger<TOptions>;
931
+ //#endregion
932
+ //#region src/PluginDriver.d.ts
933
+ type RequiredPluginLifecycle = Required<PluginLifecycle>;
934
+ type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
935
+ type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
936
+ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
937
+ result: Result;
938
+ plugin: Plugin;
939
+ };
940
+ type Options = {
941
+ fabric: Fabric;
942
+ events: AsyncEventEmitter<KubbEvents>;
943
+ /**
944
+ * @default Number.POSITIVE_INFINITY
945
+ */
946
+ concurrency?: number;
947
+ };
948
+ type GetFileOptions<TOptions = object> = {
949
+ name: string;
950
+ mode?: KubbFile.Mode;
951
+ extname: KubbFile.Extname;
952
+ pluginName: string;
953
+ options?: TOptions;
987
954
  };
988
- type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Omit<Logger<TOptions>, 'logLevel'>;
955
+ declare function getMode(fileOrFolder: string | undefined | null): KubbFile.Mode;
956
+ declare class PluginDriver {
957
+ #private;
958
+ readonly config: Config;
959
+ readonly options: Options;
960
+ /**
961
+ * The universal `@kubb/ast` `RootNode` produced by the adapter, set by
962
+ * the build pipeline after the adapter's `parse()` resolves.
963
+ */
964
+ rootNode: RootNode | undefined;
965
+ adapter: Adapter | undefined;
966
+ constructor(config: Config, options: Options);
967
+ get events(): AsyncEventEmitter<KubbEvents>;
968
+ getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, unknown>;
969
+ get plugins(): Array<Plugin>;
970
+ getFile<TOptions = object>({
971
+ name,
972
+ mode,
973
+ extname,
974
+ pluginName,
975
+ options
976
+ }: GetFileOptions<TOptions>): KubbFile.File<{
977
+ pluginName: string;
978
+ }>;
979
+ resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
980
+ resolveName: (params: ResolveNameParams) => string;
981
+ /**
982
+ * Run a specific hookName for plugin x.
983
+ */
984
+ hookForPlugin<H extends PluginLifecycleHooks>({
985
+ pluginName,
986
+ hookName,
987
+ parameters
988
+ }: {
989
+ pluginName: string;
990
+ hookName: H;
991
+ parameters: PluginParameter<H>;
992
+ }): Promise<Array<ReturnType<ParseResult<H>> | null>>;
993
+ /**
994
+ * Run a specific hookName for plugin x.
995
+ */
996
+ hookForPluginSync<H extends PluginLifecycleHooks>({
997
+ pluginName,
998
+ hookName,
999
+ parameters
1000
+ }: {
1001
+ pluginName: string;
1002
+ hookName: H;
1003
+ parameters: PluginParameter<H>;
1004
+ }): Array<ReturnType<ParseResult<H>>> | null;
1005
+ /**
1006
+ * Returns the first non-null result.
1007
+ */
1008
+ hookFirst<H extends PluginLifecycleHooks>({
1009
+ hookName,
1010
+ parameters,
1011
+ skipped
1012
+ }: {
1013
+ hookName: H;
1014
+ parameters: PluginParameter<H>;
1015
+ skipped?: ReadonlySet<Plugin> | null;
1016
+ }): Promise<SafeParseResult<H>>;
1017
+ /**
1018
+ * Returns the first non-null result.
1019
+ */
1020
+ hookFirstSync<H extends PluginLifecycleHooks>({
1021
+ hookName,
1022
+ parameters,
1023
+ skipped
1024
+ }: {
1025
+ hookName: H;
1026
+ parameters: PluginParameter<H>;
1027
+ skipped?: ReadonlySet<Plugin> | null;
1028
+ }): SafeParseResult<H> | null;
1029
+ /**
1030
+ * Runs all plugins in parallel based on `this.plugin` order and `pre`/`post` settings.
1031
+ */
1032
+ hookParallel<H extends PluginLifecycleHooks, TOutput = void>({
1033
+ hookName,
1034
+ parameters
1035
+ }: {
1036
+ hookName: H;
1037
+ parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
1038
+ }): Promise<Awaited<TOutput>[]>;
1039
+ /**
1040
+ * Chains plugins
1041
+ */
1042
+ hookSeq<H extends PluginLifecycleHooks>({
1043
+ hookName,
1044
+ parameters
1045
+ }: {
1046
+ hookName: H;
1047
+ parameters?: PluginParameter<H>;
1048
+ }): Promise<void>;
1049
+ getPluginByName(pluginName: string): Plugin | undefined;
1050
+ getPluginsByName(hookName: keyof PluginWithLifeCycle, pluginName: string): Plugin[];
1051
+ }
989
1052
  //#endregion
990
- export { UserPlugin as A, AsyncEventEmitter as B, Printer as C, UnknownUserPlugin as D, ResolvePathParams as E, DefineStorage as F, defineStorage as I, formatters as L, KubbEvents as M, PluginManager as N, UserConfig as O, getMode as P, linters as R, PluginWithLifeCycle as S, ResolveNameParams as T, URLPath as V, PluginFactoryOptions as _, Config as a, PluginLifecycleHooks as b, Group as c, Logger as d, LoggerContext as f, PluginContext as g, Plugin as h, BarrelType as i, UserPluginWithLifeCycle as j, UserLogger 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, PluginKey as v, PrinterFactoryOptions as w, PluginParameter as x, PluginLifecycle as y, logLevel as z };
991
- //# sourceMappingURL=types-D30QAz2y.d.ts.map
1053
+ export { UserConfig as A, Storage as B, PluginWithLifeCycle as C, ResolveOptionsContext as D, ResolveNameParams as E, CoreGeneratorV2 as F, AsyncEventEmitter as G, formatters as H, Generator as I, ReactGeneratorV2 as L, UserPlugin as M, UserPluginWithLifeCycle as N, ResolvePathParams as O, UserResolver as P, defineGenerator as R, PluginParameter as S, PrinterFactoryOptions as T, linters as U, createStorage as V, logLevel as W, Plugin as _, AdapterFactoryOptions as a, PluginLifecycle as b, Config as c, InputData as d, InputPath as f, Output as g, LoggerOptions as h, Adapter as i, UserLogger as j, Resolver as k, DevtoolsOptions as l, LoggerContext as m, PluginDriver as n, AdapterSource as o, Logger as p, getMode as r, BarrelType as s, GetFileOptions as t, Group as u, PluginContext as v, Printer as w, PluginLifecycleHooks as x, PluginFactoryOptions as y, KubbEvents as z };
1054
+ //# sourceMappingURL=PluginDriver-BkFepPdm.d.ts.map