@kubb/core 5.0.0-alpha.8 → 5.0.0-alpha.9

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.
@@ -1,6 +1,6 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
2
  import { EventEmitter } from "node:events";
3
- import { OperationNode, Printer, PrinterFactoryOptions, RootNode, SchemaNode } from "@kubb/ast/types";
3
+ import { Node, OperationNode, Printer, PrinterFactoryOptions, RootNode, SchemaNode } from "@kubb/ast/types";
4
4
  import { Fabric, KubbFile } from "@kubb/fabric-core/types";
5
5
  import { FabricReactNode } from "@kubb/react-fabric/types";
6
6
 
@@ -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";
@@ -139,45 +70,45 @@ declare const formatters: {
139
70
  };
140
71
  //#endregion
141
72
  //#region src/createStorage.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 `createStorage` to create a typed storage driver.
150
- */
151
- interface DefineStorage {
152
- /** Identifier used for logging and debugging (e.g. `'fs'`, `'s3'`). */
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 `createPlugin`, `createLogger`, and `createAdapter`.
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 { createStorage } from '@kubb/core'
179
- *
180
- * export const memoryStorage = createStorage((_options) => {
111
+ * export const memoryStorage = createStorage(() => {
181
112
  * const store = new Map<string, string>()
182
113
  * return {
183
114
  * name: 'memory',
@@ -185,40 +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 createStorage<TOptions = Record<string, never>>(build: (options: TOptions) => DefineStorage): (options?: TOptions) => DefineStorage;
127
+ declare function createStorage<TOptions = Record<string, never>>(build: (options: TOptions) => Storage): (options?: TOptions) => Storage;
195
128
  //#endregion
196
129
  //#region src/Kubb.d.ts
197
- type DebugEvent = {
130
+ type DebugInfo = {
198
131
  date: Date;
199
- logs: string[];
132
+ logs: Array<string>;
200
133
  fileName?: string;
201
134
  };
202
- type ProgressStartMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
135
+ type HookProgress<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
203
136
  hookName: H;
204
137
  plugins: Array<Plugin>;
205
138
  };
206
- type ProgressStopMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
207
- hookName: H;
208
- };
209
- type ExecutingMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
139
+ type HookExecution<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
210
140
  strategy: Strategy;
211
141
  hookName: H;
212
142
  plugin: Plugin;
213
- parameters?: unknown[] | undefined;
143
+ parameters?: Array<unknown>;
214
144
  output?: unknown;
215
145
  };
216
- type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
146
+ type HookResult<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
217
147
  duration: number;
218
148
  strategy: Strategy;
219
149
  hookName: H;
220
150
  plugin: Plugin;
221
- parameters?: unknown[] | undefined;
151
+ parameters?: Array<unknown>;
222
152
  output?: unknown;
223
153
  };
224
154
  /**
@@ -227,7 +157,7 @@ type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
227
157
  *
228
158
  * @example
229
159
  * ```typescript
230
- * import type { AsyncEventEmitter } from '@kubb/core'
160
+ * import type { AsyncEventEmitter } from '@internals/utils'
231
161
  * import type { KubbEvents } from '@kubb/core'
232
162
  *
233
163
  * const events: AsyncEventEmitter<KubbEvents> = new AsyncEventEmitter()
@@ -265,12 +195,12 @@ interface KubbEvents {
265
195
  /**
266
196
  * Emitted when code generation phase completes.
267
197
  */
268
- '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>];
269
199
  /**
270
200
  * Emitted with a summary of the generation results.
271
201
  * Contains summary lines, title, and success status.
272
202
  */
273
- 'generation:summary': [Config: Config, {
203
+ 'generation:summary': [config: Config, {
274
204
  failedPlugins: Set<{
275
205
  plugin: Plugin;
276
206
  error: Error;
@@ -278,7 +208,7 @@ interface KubbEvents {
278
208
  status: 'success' | 'failed';
279
209
  hrStart: [number, number];
280
210
  filesCreated: number;
281
- pluginTimings?: Map<string, number>;
211
+ pluginTimings?: Map<Plugin['name'], number>;
282
212
  }];
283
213
  /**
284
214
  * Emitted when code formatting starts (e.g., running Biome or Prettier).
@@ -305,7 +235,7 @@ interface KubbEvents {
305
235
  */
306
236
  'hooks:end': [];
307
237
  /**
308
- * 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).
309
239
  * The callback should be invoked when the command completes.
310
240
  */
311
241
  'hook:start': [{
@@ -347,7 +277,7 @@ interface KubbEvents {
347
277
  * Debug event for detailed logging.
348
278
  * Contains timestamp, log messages, and optional filename.
349
279
  */
350
- debug: [meta: DebugEvent];
280
+ debug: [info: DebugInfo];
351
281
  /**
352
282
  * Emitted when file processing starts.
353
283
  * Contains the list of files to be processed.
@@ -358,10 +288,10 @@ interface KubbEvents {
358
288
  * Contains processed count, total count, percentage, and file details.
359
289
  */
360
290
  'file:processing:update': [{
361
- /** Number of files processed so far */processed: number; /** Total number of files to process */
362
- total: number; /** Processing percentage (0-100) */
363
- percentage: number; /** Optional source identifier */
364
- 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. */
365
295
  file: KubbFile.ResolvedFile;
366
296
  /**
367
297
  * Kubb configuration (not present in Fabric).
@@ -373,16 +303,16 @@ interface KubbEvents {
373
303
  * Emitted when file processing completes.
374
304
  * Contains the list of processed files.
375
305
  */
376
- 'files:processing:end': [files: KubbFile.ResolvedFile[]];
306
+ 'files:processing:end': [files: Array<KubbFile.ResolvedFile>];
377
307
  /**
378
308
  * Emitted when a plugin starts executing.
379
309
  */
380
310
  'plugin:start': [plugin: Plugin];
381
311
  /**
382
312
  * Emitted when a plugin completes execution.
383
- * Duration in ms
313
+ * Duration in ms.
384
314
  */
385
- 'plugin:end': [plugin: Plugin, meta: {
315
+ 'plugin:end': [plugin: Plugin, result: {
386
316
  duration: number;
387
317
  success: boolean;
388
318
  error?: Error;
@@ -391,37 +321,48 @@ interface KubbEvents {
391
321
  * Emitted when plugin hook progress tracking starts.
392
322
  * Contains the hook name and list of plugins to execute.
393
323
  */
394
- 'plugins:hook:progress:start': [meta: ProgressStartMeta];
324
+ 'plugins:hook:progress:start': [progress: HookProgress];
395
325
  /**
396
326
  * Emitted when plugin hook progress tracking ends.
397
327
  * Contains the hook name that completed.
398
328
  */
399
- 'plugins:hook:progress:end': [meta: ProgressStopMeta];
329
+ 'plugins:hook:progress:end': [{
330
+ hookName: PluginLifecycleHooks;
331
+ }];
400
332
  /**
401
333
  * Emitted when a plugin hook starts processing.
402
334
  * Contains strategy, hook name, plugin, parameters, and output.
403
335
  */
404
- 'plugins:hook:processing:start': [meta: ExecutingMeta];
336
+ 'plugins:hook:processing:start': [execution: HookExecution];
405
337
  /**
406
338
  * Emitted when a plugin hook completes processing.
407
339
  * Contains duration, strategy, hook name, plugin, parameters, and output.
408
340
  */
409
- 'plugins:hook:processing:end': [meta: ExecutedMeta];
341
+ 'plugins:hook:processing:end': [result: HookResult];
410
342
  }
411
343
  //#endregion
412
- //#region src/createGenerator.d.ts
344
+ //#region src/defineGenerator.d.ts
345
+ /**
346
+ * Props for the `operations` lifecycle — receives all operation nodes at once.
347
+ */
413
348
  type OperationsV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
414
349
  config: Config;
415
350
  adapter: Adapter;
416
351
  options: Plugin<TPlugin>['options'];
417
352
  nodes: Array<OperationNode>;
418
353
  };
354
+ /**
355
+ * Props for the `operation` lifecycle — receives a single operation node.
356
+ */
419
357
  type OperationV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
420
358
  config: Config;
421
359
  adapter: Adapter;
422
360
  options: Plugin<TPlugin>['options'];
423
361
  node: OperationNode;
424
362
  };
363
+ /**
364
+ * Props for the `schema` lifecycle — receives a single schema node.
365
+ */
425
366
  type SchemaV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
426
367
  config: Config;
427
368
  adapter: Adapter;
@@ -461,8 +402,29 @@ type ReactGeneratorV2<TPlugin extends PluginFactoryOptions = PluginFactoryOption
461
402
  Schema(props: SchemaV2Props<TPlugin>): FabricReactNode;
462
403
  };
463
404
  type Generator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = UserCoreGeneratorV2<TPlugin> | UserReactGeneratorV2<TPlugin>;
464
- declare function createGenerator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions>(generator: UserReactGeneratorV2<TPlugin>): ReactGeneratorV2<TPlugin>;
465
- declare function createGenerator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions>(generator: UserCoreGeneratorV2<TPlugin>): CoreGeneratorV2<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>;
466
428
  //#endregion
467
429
  //#region src/types.d.ts
468
430
  declare global {
@@ -627,16 +589,16 @@ type Config<TInput = Input> = {
627
589
  /**
628
590
  * Storage backend for generated files.
629
591
  * Defaults to `fsStorage()` — the built-in filesystem driver.
630
- * Accepts any object implementing the {@link DefineStorage} interface.
592
+ * Accepts any object implementing the {@link Storage} interface.
631
593
  * Keys are root-relative paths (e.g. `src/gen/api/getPets.ts`).
632
594
  * @default fsStorage()
633
595
  * @example
634
596
  * ```ts
635
- * import { createStorage, fsStorage } from '@kubb/core'
636
- * storage: createStorage(fsStorage())
597
+ * import { memoryStorage } from '@kubb/core'
598
+ * storage: memoryStorage()
637
599
  * ```
638
600
  */
639
- storage?: DefineStorage;
601
+ storage?: Storage;
640
602
  /**
641
603
  * Specifies the formatting tool to be used.
642
604
  * - 'auto' automatically detects and uses biome or prettier (in that order of preference).
@@ -710,6 +672,39 @@ type Config<TInput = Input> = {
710
672
  done?: string | Array<string>;
711
673
  };
712
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'>;
713
708
  type PluginFactoryOptions<
714
709
  /**
715
710
  * Name to be used for the plugin.
@@ -730,14 +725,19 @@ TContext = unknown,
730
725
  /**
731
726
  * When calling `resolvePath` you can specify better types.
732
727
  */
733
- 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> = {
734
734
  name: TName;
735
735
  options: TOptions;
736
736
  resolvedOptions: TResolvedOptions;
737
737
  context: TContext;
738
738
  resolvePathOptions: TResolvePathOptions;
739
+ resolver: TResolver;
739
740
  };
740
- type GetPluginFactoryOptions<TPlugin extends UserPlugin> = TPlugin extends UserPlugin<infer X> ? X : never;
741
741
  type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
742
742
  /**
743
743
  * Unique name used for the plugin
@@ -761,7 +761,7 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
761
761
  inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
762
762
  };
763
763
  type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
764
- type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<any, any, any, any, any>>;
764
+ type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<string, object, object, unknown, object>>;
765
765
  type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
766
766
  /**
767
767
  * Unique name used for the plugin
@@ -783,7 +783,7 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
783
783
  options: TOptions['resolvedOptions'];
784
784
  install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
785
785
  /**
786
- * Define a context that can be used by other plugins, see `PluginDriver' where we convert from `UserPlugin` to `Plugin`(used when calling `createPlugin`).
786
+ * Defines a context that can be used by other plugins, see `PluginDriver` where we convert from `UserPlugin` to `Plugin` (used when calling `createPlugin`).
787
787
  */
788
788
  inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
789
789
  };
@@ -898,9 +898,6 @@ type Output<TOptions> = {
898
898
  */
899
899
  override?: boolean;
900
900
  };
901
- type GroupContext = {
902
- group: string;
903
- };
904
901
  type Group = {
905
902
  /**
906
903
  * Defines the type where to group the files.
@@ -910,9 +907,11 @@ type Group = {
910
907
  */
911
908
  type: 'tag' | 'path';
912
909
  /**
913
- * 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.
914
911
  */
915
- name?: (context: GroupContext) => string;
912
+ name?: (context: {
913
+ group: string;
914
+ }) => string;
916
915
  };
917
916
  type LoggerOptions = {
918
917
  /**
@@ -923,13 +922,12 @@ type LoggerOptions = {
923
922
  /**
924
923
  * Shared context passed to all plugins, parsers, and Fabric internals.
925
924
  */
926
- interface LoggerContext extends AsyncEventEmitter<KubbEvents> {}
927
- type Install<TOptions = unknown> = (context: LoggerContext, options?: TOptions) => void | Promise<void>;
925
+ type LoggerContext = AsyncEventEmitter<KubbEvents>;
928
926
  type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
929
927
  name: string;
930
- install: Install<TOptions>;
928
+ install: (context: LoggerContext, options?: TOptions) => void | Promise<void>;
931
929
  };
932
- type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Omit<Logger<TOptions>, 'logLevel'>;
930
+ type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Logger<TOptions>;
933
931
  //#endregion
934
932
  //#region src/PluginDriver.d.ts
935
933
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
@@ -1052,5 +1050,5 @@ declare class PluginDriver {
1052
1050
  getPluginsByName(hookName: keyof PluginWithLifeCycle, pluginName: string): Plugin[];
1053
1051
  }
1054
1052
  //#endregion
1055
- export { UserConfig as A, createStorage as B, PluginParameter as C, ResolveNameParams as D, PrinterFactoryOptions as E, Generator as F, URLPath as G, linters as H, ReactGeneratorV2 as I, createGenerator as L, UserPlugin as M, UserPluginWithLifeCycle as N, ResolvePathParams as O, CoreGeneratorV2 as P, KubbEvents as R, PluginLifecycleHooks as S, Printer as T, logLevel as U, formatters as V, AsyncEventEmitter as W, Output as _, AdapterFactoryOptions as a, PluginFactoryOptions as b, Config as c, Group as d, InputData as f, LoggerOptions as g, LoggerContext as h, Adapter as i, UserLogger as j, UnknownUserPlugin as k, DevtoolsOptions as l, Logger as m, PluginDriver as n, AdapterSource as o, InputPath as p, getMode as r, BarrelType as s, GetFileOptions as t, GetPluginFactoryOptions as u, Plugin as v, PluginWithLifeCycle as w, PluginLifecycle as x, PluginContext as y, DefineStorage as z };
1056
- //# sourceMappingURL=PluginDriver-DRfJIbG1.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
package/dist/hooks.cjs CHANGED
@@ -56,12 +56,13 @@ function useKubb() {
56
56
  ...rest
57
57
  }),
58
58
  resolveBanner: (node) => {
59
- if (typeof output?.banner === "function") return output.banner(node);
59
+ if (typeof output?.banner === "function") return node ? output.banner(node) : buildDefaultBanner({ config });
60
60
  if (typeof output?.banner === "string") return output.banner;
61
+ if (config.output.defaultBanner === false) return;
61
62
  return buildDefaultBanner({ config });
62
63
  },
63
64
  resolveFooter: (node) => {
64
- if (typeof output?.footer === "function") return output.footer(node);
65
+ if (typeof output?.footer === "function") return node ? output.footer(node) : void 0;
65
66
  if (typeof output?.footer === "string") return output.footer;
66
67
  }
67
68
  };
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.cjs","names":["path"],"sources":["../src/hooks/useKubb.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts","../src/hooks/usePluginDriver.ts"],"sourcesContent":["import path from 'node:path'\nimport type { RootNode } from '@kubb/ast/types'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\nimport type { GetFileOptions, PluginDriver } from '../PluginDriver.ts'\nimport type { Config, Plugin, PluginFactoryOptions, ResolveNameParams, ResolvePathParams } from '../types.ts'\n\ntype ResolvePathOptions = {\n pluginName?: string\n group?: {\n tag?: string\n path?: string\n }\n type?: ResolveNameParams['type']\n}\n\ntype UseKubbReturn<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n config: Config\n /**\n * Returns the plugin whose `name` matches `pluginName`, defaulting to the current plugin.\n */\n getPluginByName: (pluginName?: string) => Plugin | undefined\n /**\n * Resolves a file reference, defaulting `pluginName` to the current plugin.\n */\n getFile: (params: Omit<GetFileOptions<ResolvePathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.File<{ pluginName: string }>\n /**\n * Resolves a name, defaulting `pluginName` to the current plugin.\n */\n resolveName: (params: Omit<ResolveNameParams, 'pluginName'> & { pluginName?: string }) => string\n /**\n * Resolves a path, defaulting `pluginName` to the current plugin.\n */\n resolvePath: <TPathOptions = object>(params: Omit<ResolvePathParams<TPathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.Path\n /**\n * Resolves the banner for the given node using the plugin's `output.banner` option.\n * Returns a string when `output.banner` is a string or a function, `undefined` otherwise.\n */\n resolveBanner: (node: RootNode) => string | undefined\n /**\n * Resolves the footer for the given node using the plugin's `output.footer` option.\n * Returns a string when `output.footer` is a string or a function, `undefined` otherwise.\n */\n resolveFooter: (node: RootNode) => string | undefined\n}\n\n/**\n * Generates the default \"Generated by Kubb\" banner from node metadata.\n */\nfunction buildDefaultBanner({ title, description, version, config }: { title?: string; description?: string; version?: string; config: Config }): string {\n try {\n let source = ''\n if (Array.isArray(config.input)) {\n const first = config.input[0]\n if (first && 'path' in first) {\n source = path.basename(first.path)\n }\n } else if ('path' in config.input) {\n source = path.basename(config.input.path)\n } else if ('data' in config.input) {\n source = 'text content'\n }\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\nexport function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): UseKubbReturn<TOptions> {\n const { meta } = useFabric<{\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n driver: PluginDriver\n }>()\n\n const config = meta.driver.config\n const defaultPluginName = meta.plugin.name\n\n const output = (\n meta.plugin.options as { output?: { banner?: string | ((node: RootNode) => string); footer?: string | ((node: RootNode) => string) } } | undefined\n )?.output\n\n return {\n plugin: meta.plugin as Plugin<TOptions>,\n mode: meta.mode,\n config,\n getPluginByName: (pluginName = defaultPluginName) => meta.driver.getPluginByName.call(meta.driver, pluginName),\n getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.getFile.call(meta.driver, { pluginName, ...rest }),\n resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolveName.call(meta.driver, { pluginName, ...rest }),\n resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolvePath.call(meta.driver, { pluginName, ...rest }),\n resolveBanner: (node: RootNode) => {\n if (typeof output?.banner === 'function') {\n return output.banner(node)\n }\n if (typeof output?.banner === 'string') {\n return output.banner\n }\n return buildDefaultBanner({ config })\n },\n resolveFooter: (node: RootNode) => {\n if (typeof output?.footer === 'function') {\n return output.footer(node)\n }\n if (typeof output?.footer === 'string') {\n return output.footer\n }\n return undefined\n },\n }\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function useMode(): KubbFile.Mode {\n const { meta } = useFabric<{ mode: KubbFile.Mode }>()\n\n return meta.mode\n}\n","import { useFabric } from '@kubb/react-fabric'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\n/**\n * @deprecated use useKubb instead\n */\nexport function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {\n const { meta } = useFabric<{ plugin: Plugin<TOptions> }>()\n\n return meta.plugin\n}\n","import { useFabric } from '@kubb/react-fabric'\nimport type { PluginDriver } from '../PluginDriver.ts'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function usePluginDriver(): PluginDriver {\n const { meta } = useFabric<{ driver: PluginDriver }>()\n\n return meta.driver\n}\n"],"mappings":";;;;;;;;;AAmDA,SAAS,mBAAmB,EAAE,OAAO,aAAa,SAAS,UAA8F;AACvJ,KAAI;EACF,IAAI,SAAS;AACb,MAAI,MAAM,QAAQ,OAAO,MAAM,EAAE;GAC/B,MAAM,QAAQ,OAAO,MAAM;AAC3B,OAAI,SAAS,UAAU,MACrB,UAASA,UAAAA,QAAK,SAAS,MAAM,KAAK;aAE3B,UAAU,OAAO,MAC1B,UAASA,UAAAA,QAAK,SAAS,OAAO,MAAM,KAAK;WAChC,UAAU,OAAO,MAC1B,UAAS;EAGX,IAAI,SAAS;AAEb,MAAI,OAAO,OAAO,kBAAkB,UAAU;AAC5C,aAAU;AACV,UAAO;;AAGT,MAAI,OACF,WAAU,aAAa,OAAO;AAGhC,MAAI,MACF,WAAU,YAAY,MAAM;AAG9B,MAAI,aAAa;GACf,MAAM,uBAAuB,YAAY,QAAQ,QAAQ,OAAO;AAChE,aAAU,kBAAkB,qBAAqB;;AAGnD,MAAI,QACF,WAAU,2BAA2B,QAAQ;AAG/C,YAAU;AACV,SAAO;UACA,QAAQ;AACf,SAAO;;;AAIX,SAAgB,UAAiG;CAC/G,MAAM,EAAE,UAAA,GAAA,mBAAA,YAIJ;CAEJ,MAAM,SAAS,KAAK,OAAO;CAC3B,MAAM,oBAAoB,KAAK,OAAO;CAEtC,MAAM,SACJ,KAAK,OAAO,SACX;AAEH,QAAO;EACL,QAAQ,KAAK;EACb,MAAM,KAAK;EACX;EACA,kBAAkB,aAAa,sBAAsB,KAAK,OAAO,gBAAgB,KAAK,KAAK,QAAQ,WAAW;EAC9G,UAAU,EAAE,aAAa,mBAAmB,GAAG,WAAW,KAAK,OAAO,QAAQ,KAAK,KAAK,QAAQ;GAAE;GAAY,GAAG;GAAM,CAAC;EACxH,cAAc,EAAE,aAAa,mBAAmB,GAAG,WAAW,KAAK,OAAO,YAAY,KAAK,KAAK,QAAQ;GAAE;GAAY,GAAG;GAAM,CAAC;EAChI,cAAc,EAAE,aAAa,mBAAmB,GAAG,WAAW,KAAK,OAAO,YAAY,KAAK,KAAK,QAAQ;GAAE;GAAY,GAAG;GAAM,CAAC;EAChI,gBAAgB,SAAmB;AACjC,OAAI,OAAO,QAAQ,WAAW,WAC5B,QAAO,OAAO,OAAO,KAAK;AAE5B,OAAI,OAAO,QAAQ,WAAW,SAC5B,QAAO,OAAO;AAEhB,UAAO,mBAAmB,EAAE,QAAQ,CAAC;;EAEvC,gBAAgB,SAAmB;AACjC,OAAI,OAAO,QAAQ,WAAW,WAC5B,QAAO,OAAO,OAAO,KAAK;AAE5B,OAAI,OAAO,QAAQ,WAAW,SAC5B,QAAO,OAAO;;EAInB;;;;;;;AClIH,SAAgB,UAAyB;CACvC,MAAM,EAAE,UAAA,GAAA,mBAAA,YAA6C;AAErD,QAAO,KAAK;;;;;;;ACHd,SAAgB,YAA4F;CAC1G,MAAM,EAAE,UAAA,GAAA,mBAAA,YAAkD;AAE1D,QAAO,KAAK;;;;;;;ACHd,SAAgB,kBAAgC;CAC9C,MAAM,EAAE,UAAA,GAAA,mBAAA,YAA8C;AAEtD,QAAO,KAAK"}
1
+ {"version":3,"file":"hooks.cjs","names":["path"],"sources":["../src/hooks/useKubb.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts","../src/hooks/usePluginDriver.ts"],"sourcesContent":["import path from 'node:path'\nimport type { RootNode } from '@kubb/ast/types'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\nimport type { GetFileOptions, PluginDriver } from '../PluginDriver.ts'\nimport type { Config, Plugin, PluginFactoryOptions, ResolveNameParams, ResolvePathParams } from '../types.ts'\n\ntype ResolvePathOptions = {\n pluginName?: string\n group?: {\n tag?: string\n path?: string\n }\n type?: ResolveNameParams['type']\n}\n\ntype UseKubbReturn<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n config: Config\n /**\n * Returns the plugin whose `name` matches `pluginName`, defaulting to the current plugin.\n */\n getPluginByName: (pluginName?: string) => Plugin | undefined\n /**\n * Resolves a file reference, defaulting `pluginName` to the current plugin.\n */\n getFile: (params: Omit<GetFileOptions<ResolvePathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.File<{ pluginName: string }>\n /**\n * Resolves a name, defaulting `pluginName` to the current plugin.\n */\n resolveName: (params: Omit<ResolveNameParams, 'pluginName'> & { pluginName?: string }) => string\n /**\n * Resolves a path, defaulting `pluginName` to the current plugin.\n */\n resolvePath: <TPathOptions = object>(params: Omit<ResolvePathParams<TPathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.Path\n /**\n * Resolves the banner using the plugin's `output.banner` option.\n * Falls back to the default \"Generated by Kubb\" banner when `output.banner` is unset.\n * When `output.banner` is a function and no node is provided, returns the default banner.\n */\n resolveBanner: (node?: RootNode) => string | undefined\n /**\n * Resolves the footer using the plugin's `output.footer` option.\n * Returns `undefined` when no footer is configured.\n * When `output.footer` is a function and no node is provided, returns `undefined`.\n */\n resolveFooter: (node?: RootNode) => string | undefined\n}\n\n/**\n * Generates the default \"Generated by Kubb\" banner from node metadata.\n */\nfunction buildDefaultBanner({ title, description, version, config }: { title?: string; description?: string; version?: string; config: Config }): string {\n try {\n let source = ''\n if (Array.isArray(config.input)) {\n const first = config.input[0]\n if (first && 'path' in first) {\n source = path.basename(first.path)\n }\n } else if ('path' in config.input) {\n source = path.basename(config.input.path)\n } else if ('data' in config.input) {\n source = 'text content'\n }\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\nexport function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): UseKubbReturn<TOptions> {\n const { meta } = useFabric<{\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n driver: PluginDriver\n }>()\n\n const config = meta.driver.config\n const defaultPluginName = meta.plugin.name\n\n const output = (\n meta.plugin.options as { output?: { banner?: string | ((node: RootNode) => string); footer?: string | ((node: RootNode) => string) } } | undefined\n )?.output\n\n return {\n plugin: meta.plugin as Plugin<TOptions>,\n mode: meta.mode,\n config,\n getPluginByName: (pluginName = defaultPluginName) => meta.driver.getPluginByName.call(meta.driver, pluginName),\n getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.getFile.call(meta.driver, { pluginName, ...rest }),\n resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolveName.call(meta.driver, { pluginName, ...rest }),\n resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolvePath.call(meta.driver, { pluginName, ...rest }),\n resolveBanner: (node?: RootNode) => {\n if (typeof output?.banner === 'function') {\n return node ? output.banner(node) : buildDefaultBanner({ config })\n }\n if (typeof output?.banner === 'string') {\n return output.banner\n }\n if (config.output.defaultBanner === false) {\n return undefined\n }\n return buildDefaultBanner({ config })\n },\n resolveFooter: (node?: RootNode) => {\n if (typeof output?.footer === 'function') {\n return node ? output.footer(node) : undefined\n }\n if (typeof output?.footer === 'string') {\n return output.footer\n }\n return undefined\n },\n }\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function useMode(): KubbFile.Mode {\n const { meta } = useFabric<{ mode: KubbFile.Mode }>()\n\n return meta.mode\n}\n","import { useFabric } from '@kubb/react-fabric'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\n/**\n * @deprecated use useKubb instead\n */\nexport function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {\n const { meta } = useFabric<{ plugin: Plugin<TOptions> }>()\n\n return meta.plugin\n}\n","import { useFabric } from '@kubb/react-fabric'\nimport type { PluginDriver } from '../PluginDriver.ts'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function usePluginDriver(): PluginDriver {\n const { meta } = useFabric<{ driver: PluginDriver }>()\n\n return meta.driver\n}\n"],"mappings":";;;;;;;;;AAqDA,SAAS,mBAAmB,EAAE,OAAO,aAAa,SAAS,UAA8F;AACvJ,KAAI;EACF,IAAI,SAAS;AACb,MAAI,MAAM,QAAQ,OAAO,MAAM,EAAE;GAC/B,MAAM,QAAQ,OAAO,MAAM;AAC3B,OAAI,SAAS,UAAU,MACrB,UAASA,UAAAA,QAAK,SAAS,MAAM,KAAK;aAE3B,UAAU,OAAO,MAC1B,UAASA,UAAAA,QAAK,SAAS,OAAO,MAAM,KAAK;WAChC,UAAU,OAAO,MAC1B,UAAS;EAGX,IAAI,SAAS;AAEb,MAAI,OAAO,OAAO,kBAAkB,UAAU;AAC5C,aAAU;AACV,UAAO;;AAGT,MAAI,OACF,WAAU,aAAa,OAAO;AAGhC,MAAI,MACF,WAAU,YAAY,MAAM;AAG9B,MAAI,aAAa;GACf,MAAM,uBAAuB,YAAY,QAAQ,QAAQ,OAAO;AAChE,aAAU,kBAAkB,qBAAqB;;AAGnD,MAAI,QACF,WAAU,2BAA2B,QAAQ;AAG/C,YAAU;AACV,SAAO;UACA,QAAQ;AACf,SAAO;;;AAIX,SAAgB,UAAiG;CAC/G,MAAM,EAAE,UAAA,GAAA,mBAAA,YAIJ;CAEJ,MAAM,SAAS,KAAK,OAAO;CAC3B,MAAM,oBAAoB,KAAK,OAAO;CAEtC,MAAM,SACJ,KAAK,OAAO,SACX;AAEH,QAAO;EACL,QAAQ,KAAK;EACb,MAAM,KAAK;EACX;EACA,kBAAkB,aAAa,sBAAsB,KAAK,OAAO,gBAAgB,KAAK,KAAK,QAAQ,WAAW;EAC9G,UAAU,EAAE,aAAa,mBAAmB,GAAG,WAAW,KAAK,OAAO,QAAQ,KAAK,KAAK,QAAQ;GAAE;GAAY,GAAG;GAAM,CAAC;EACxH,cAAc,EAAE,aAAa,mBAAmB,GAAG,WAAW,KAAK,OAAO,YAAY,KAAK,KAAK,QAAQ;GAAE;GAAY,GAAG;GAAM,CAAC;EAChI,cAAc,EAAE,aAAa,mBAAmB,GAAG,WAAW,KAAK,OAAO,YAAY,KAAK,KAAK,QAAQ;GAAE;GAAY,GAAG;GAAM,CAAC;EAChI,gBAAgB,SAAoB;AAClC,OAAI,OAAO,QAAQ,WAAW,WAC5B,QAAO,OAAO,OAAO,OAAO,KAAK,GAAG,mBAAmB,EAAE,QAAQ,CAAC;AAEpE,OAAI,OAAO,QAAQ,WAAW,SAC5B,QAAO,OAAO;AAEhB,OAAI,OAAO,OAAO,kBAAkB,MAClC;AAEF,UAAO,mBAAmB,EAAE,QAAQ,CAAC;;EAEvC,gBAAgB,SAAoB;AAClC,OAAI,OAAO,QAAQ,WAAW,WAC5B,QAAO,OAAO,OAAO,OAAO,KAAK,GAAG,KAAA;AAEtC,OAAI,OAAO,QAAQ,WAAW,SAC5B,QAAO,OAAO;;EAInB;;;;;;;ACvIH,SAAgB,UAAyB;CACvC,MAAM,EAAE,UAAA,GAAA,mBAAA,YAA6C;AAErD,QAAO,KAAK;;;;;;;ACHd,SAAgB,YAA4F;CAC1G,MAAM,EAAE,UAAA,GAAA,mBAAA,YAAkD;AAE1D,QAAO,KAAK;;;;;;;ACHd,SAAgB,kBAAgC;CAC9C,MAAM,EAAE,UAAA,GAAA,mBAAA,YAA8C;AAEtD,QAAO,KAAK"}
package/dist/hooks.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { D as ResolveNameParams, O as ResolvePathParams, b as PluginFactoryOptions, c as Config, n as PluginDriver, t as GetFileOptions, v as Plugin } from "./PluginDriver-DRfJIbG1.js";
2
+ import { E as ResolveNameParams, O as ResolvePathParams, _ as Plugin, c as Config, n as PluginDriver, t as GetFileOptions, y as PluginFactoryOptions } from "./PluginDriver-BkFepPdm.js";
3
3
  import { RootNode } from "@kubb/ast/types";
4
4
  import { KubbFile } from "@kubb/fabric-core/types";
5
5
 
@@ -41,15 +41,17 @@ type UseKubbReturn<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
41
41
  pluginName?: string;
42
42
  }) => KubbFile.Path;
43
43
  /**
44
- * Resolves the banner for the given node using the plugin's `output.banner` option.
45
- * Returns a string when `output.banner` is a string or a function, `undefined` otherwise.
44
+ * Resolves the banner using the plugin's `output.banner` option.
45
+ * Falls back to the default "Generated by Kubb" banner when `output.banner` is unset.
46
+ * When `output.banner` is a function and no node is provided, returns the default banner.
46
47
  */
47
- resolveBanner: (node: RootNode) => string | undefined;
48
+ resolveBanner: (node?: RootNode) => string | undefined;
48
49
  /**
49
- * Resolves the footer for the given node using the plugin's `output.footer` option.
50
- * Returns a string when `output.footer` is a string or a function, `undefined` otherwise.
50
+ * Resolves the footer using the plugin's `output.footer` option.
51
+ * Returns `undefined` when no footer is configured.
52
+ * When `output.footer` is a function and no node is provided, returns `undefined`.
51
53
  */
52
- resolveFooter: (node: RootNode) => string | undefined;
54
+ resolveFooter: (node?: RootNode) => string | undefined;
53
55
  };
54
56
  declare function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): UseKubbReturn<TOptions>;
55
57
  //#endregion
package/dist/hooks.js CHANGED
@@ -54,12 +54,13 @@ function useKubb() {
54
54
  ...rest
55
55
  }),
56
56
  resolveBanner: (node) => {
57
- if (typeof output?.banner === "function") return output.banner(node);
57
+ if (typeof output?.banner === "function") return node ? output.banner(node) : buildDefaultBanner({ config });
58
58
  if (typeof output?.banner === "string") return output.banner;
59
+ if (config.output.defaultBanner === false) return;
59
60
  return buildDefaultBanner({ config });
60
61
  },
61
62
  resolveFooter: (node) => {
62
- if (typeof output?.footer === "function") return output.footer(node);
63
+ if (typeof output?.footer === "function") return node ? output.footer(node) : void 0;
63
64
  if (typeof output?.footer === "string") return output.footer;
64
65
  }
65
66
  };