@kubb/core 5.0.0-alpha.20 → 5.0.0-alpha.21

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,7 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
2
  import { Node, OperationNode, Printer, PrinterFactoryOptions, RootNode, SchemaNode, Visitor } from "@kubb/ast/types";
3
3
  import { Fabric, KubbFile } from "@kubb/fabric-core/types";
4
+ import { HttpMethod } from "@kubb/oas";
4
5
  import { FabricReactNode } from "@kubb/react-fabric/types";
5
6
 
6
7
  //#region ../../internals/utils/src/asyncEventEmitter.d.ts
@@ -210,6 +211,94 @@ type Storage = {
210
211
  */
211
212
  declare function createStorage<TOptions = Record<string, never>>(build: (options: TOptions) => Storage): (options?: TOptions) => Storage;
212
213
  //#endregion
214
+ //#region src/defineGenerator.d.ts
215
+ /**
216
+ * Props for the `operations` lifecycle — receives all operation nodes at once.
217
+ */
218
+ type OperationsV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
219
+ config: Config;
220
+ plugin: Plugin<TPlugin>;
221
+ adapter: Adapter;
222
+ options: Plugin<TPlugin>['options'];
223
+ nodes: Array<OperationNode>;
224
+ };
225
+ /**
226
+ * Props for the `operation` lifecycle — receives a single operation node.
227
+ */
228
+ type OperationV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
229
+ config: Config;
230
+ adapter: Adapter;
231
+ plugin: Plugin<TPlugin>;
232
+ options: Plugin<TPlugin>['options'];
233
+ node: OperationNode;
234
+ };
235
+ /**
236
+ * Props for the `schema` lifecycle — receives a single schema node.
237
+ */
238
+ type SchemaV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
239
+ config: Config;
240
+ adapter: Adapter;
241
+ plugin: Plugin<TPlugin>;
242
+ options: Plugin<TPlugin>['options'];
243
+ node: SchemaNode;
244
+ };
245
+ type UserCoreGeneratorV2<TPlugin extends PluginFactoryOptions> = {
246
+ name: string;
247
+ type: 'core';
248
+ version?: '2';
249
+ operations?(props: OperationsV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
250
+ operation?(props: OperationV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
251
+ schema?(props: SchemaV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
252
+ };
253
+ type UserReactGeneratorV2<TPlugin extends PluginFactoryOptions> = {
254
+ name: string;
255
+ type: 'react';
256
+ version?: '2';
257
+ Operations?(props: OperationsV2Props<TPlugin>): FabricReactNode;
258
+ Operation?(props: OperationV2Props<TPlugin>): FabricReactNode;
259
+ Schema?(props: SchemaV2Props<TPlugin>): FabricReactNode;
260
+ };
261
+ type CoreGeneratorV2<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
262
+ name: string;
263
+ type: 'core';
264
+ version: '2';
265
+ operations(props: OperationsV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
266
+ operation(props: OperationV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
267
+ schema(props: SchemaV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
268
+ };
269
+ type ReactGeneratorV2<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
270
+ name: string;
271
+ type: 'react';
272
+ version: '2';
273
+ Operations(props: OperationsV2Props<TPlugin>): FabricReactNode;
274
+ Operation(props: OperationV2Props<TPlugin>): FabricReactNode;
275
+ Schema(props: SchemaV2Props<TPlugin>): FabricReactNode;
276
+ };
277
+ type Generator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = UserCoreGeneratorV2<TPlugin> | UserReactGeneratorV2<TPlugin>;
278
+ /**
279
+ * Defines a generator with no-op defaults for any omitted lifecycle methods.
280
+ * Works for both `core` (async file output) and `react` (JSX component) generators.
281
+ *
282
+ * @example
283
+ * // react generator
284
+ * export const typeGenerator = defineGenerator<PluginTs>({
285
+ * name: 'typescript',
286
+ * type: 'react',
287
+ * Operation({ node, options }) { return <File>...</File> },
288
+ * Schema({ node, options }) { return <File>...</File> },
289
+ * })
290
+ *
291
+ * @example
292
+ * // core generator
293
+ * export const myGenerator = defineGenerator<MyPlugin>({
294
+ * name: 'my-generator',
295
+ * type: 'core',
296
+ * async operation({ node, options }) { return [{ path: '...', content: '...' }] },
297
+ * })
298
+ */
299
+ declare function defineGenerator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions>(generator: UserReactGeneratorV2<TPlugin>): ReactGeneratorV2<TPlugin>;
300
+ declare function defineGenerator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions>(generator: UserCoreGeneratorV2<TPlugin>): CoreGeneratorV2<TPlugin>;
301
+ //#endregion
213
302
  //#region src/Kubb.d.ts
214
303
  type DebugInfo = {
215
304
  date: Date;
@@ -440,91 +529,6 @@ interface KubbEvents {
440
529
  'plugins:hook:processing:end': [result: HookResult];
441
530
  }
442
531
  //#endregion
443
- //#region src/defineGenerator.d.ts
444
- /**
445
- * Props for the `operations` lifecycle — receives all operation nodes at once.
446
- */
447
- type OperationsV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
448
- config: Config;
449
- adapter: Adapter;
450
- options: Plugin<TPlugin>['options'];
451
- nodes: Array<OperationNode>;
452
- };
453
- /**
454
- * Props for the `operation` lifecycle — receives a single operation node.
455
- */
456
- type OperationV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
457
- config: Config;
458
- adapter: Adapter;
459
- options: Plugin<TPlugin>['options'];
460
- node: OperationNode;
461
- };
462
- /**
463
- * Props for the `schema` lifecycle — receives a single schema node.
464
- */
465
- type SchemaV2Props<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
466
- config: Config;
467
- adapter: Adapter;
468
- options: Plugin<TPlugin>['options'];
469
- node: SchemaNode;
470
- };
471
- type UserCoreGeneratorV2<TPlugin extends PluginFactoryOptions> = {
472
- name: string;
473
- type: 'core';
474
- version?: '2';
475
- operations?(props: OperationsV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
476
- operation?(props: OperationV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
477
- schema?(props: SchemaV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
478
- };
479
- type UserReactGeneratorV2<TPlugin extends PluginFactoryOptions> = {
480
- name: string;
481
- type: 'react';
482
- version?: '2';
483
- Operations?(props: OperationsV2Props<TPlugin>): FabricReactNode;
484
- Operation?(props: OperationV2Props<TPlugin>): FabricReactNode;
485
- Schema?(props: SchemaV2Props<TPlugin>): FabricReactNode;
486
- };
487
- type CoreGeneratorV2<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
488
- name: string;
489
- type: 'core';
490
- version: '2';
491
- operations(props: OperationsV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
492
- operation(props: OperationV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
493
- schema(props: SchemaV2Props<TPlugin>): Promise<Array<KubbFile.File>>;
494
- };
495
- type ReactGeneratorV2<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = {
496
- name: string;
497
- type: 'react';
498
- version: '2';
499
- Operations(props: OperationsV2Props<TPlugin>): FabricReactNode;
500
- Operation(props: OperationV2Props<TPlugin>): FabricReactNode;
501
- Schema(props: SchemaV2Props<TPlugin>): FabricReactNode;
502
- };
503
- type Generator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions> = UserCoreGeneratorV2<TPlugin> | UserReactGeneratorV2<TPlugin>;
504
- /**
505
- * Defines a generator with no-op defaults for any omitted lifecycle methods.
506
- * Works for both `core` (async file output) and `react` (JSX component) generators.
507
- *
508
- * @example
509
- * // react generator
510
- * export const typeGenerator = defineGenerator<PluginTs>({
511
- * name: 'typescript',
512
- * type: 'react',
513
- * Operation({ node, options }) { return <File>...</File> },
514
- * Schema({ node, options }) { return <File>...</File> },
515
- * })
516
- *
517
- * @example
518
- * // core generator
519
- * export const myGenerator = defineGenerator<MyPlugin>({
520
- * name: 'my-generator',
521
- * type: 'core',
522
- * async operation({ node, options }) { return [{ path: '...', content: '...' }] },
523
- * })
524
- */
525
- declare function defineGenerator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions>(generator: UserReactGeneratorV2<TPlugin>): ReactGeneratorV2<TPlugin>;
526
- declare function defineGenerator<TPlugin extends PluginFactoryOptions = PluginFactoryOptions>(generator: UserCoreGeneratorV2<TPlugin>): CoreGeneratorV2<TPlugin>;
527
- //#endregion
528
532
  //#region src/types.d.ts
529
533
  declare global {
530
534
  namespace Kubb {
@@ -624,7 +628,8 @@ type Adapter<TOptions extends AdapterFactoryOptions = AdapterFactoryOptions> = {
624
628
  * The raw source document produced after the first `parse()` call.
625
629
  * `undefined` before parsing; typed by the adapter's `TDocument` generic.
626
630
  */
627
- document?: TOptions['document'];
631
+ document: TOptions['document'] | null;
632
+ rootNode: RootNode | null;
628
633
  /**
629
634
  * Convert the raw source into a universal `RootNode`.
630
635
  */
@@ -743,7 +748,7 @@ type Config<TInput = Input> = {
743
748
  * 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`).
744
749
  * @default 'named'
745
750
  */
746
- barrelType?: Exclude<BarrelType, 'propagate'> | false;
751
+ barrelType?: 'all' | 'named' | false;
747
752
  /**
748
753
  * Adds a default banner to the start of every generated file indicating it was generated by Kubb.
749
754
  * - 'simple' adds banner with link to Kubb.
@@ -803,24 +808,51 @@ type ResolveOptionsContext<TOptions> = {
803
808
  /**
804
809
  * Base constraint for all plugin resolver objects.
805
810
  *
806
- * `default` and `resolveOptions` are injected automatically by `defineResolver` — plugin
807
- * authors may override them but never need to implement them from scratch.
808
- * Concrete plugin resolver types extend this with their own helper methods.
811
+ * `default`, `resolveOptions`, `resolvePath`, and `resolveFile` are injected automatically
812
+ * by `defineResolver` — plugin authors may override them but never need to implement them
813
+ * from scratch.
814
+ *
815
+ * @example
816
+ * ```ts
817
+ * type MyResolver = Resolver & {
818
+ * resolveName(node: SchemaNode): string
819
+ * resolveTypedName(node: SchemaNode): string
820
+ * }
821
+ * ```
809
822
  */
810
823
  type Resolver = {
811
824
  name: string;
825
+ pluginName: Plugin['name'];
812
826
  default(name: ResolveNameParams['name'], type?: ResolveNameParams['type']): string;
813
827
  resolveOptions<TOptions>(node: Node, context: ResolveOptionsContext<TOptions>): TOptions | null;
828
+ resolvePath(params: ResolverPathParams, context: ResolverContext): KubbFile.Path;
829
+ resolveFile(params: ResolverFileParams, context: ResolverContext): KubbFile.File;
830
+ resolveBanner(node: RootNode | null, context: ResolveBannerContext): string | undefined;
831
+ resolveFooter(node: RootNode | null, context: ResolveBannerContext): string | undefined;
814
832
  };
815
833
  /**
816
- * The user-facing subset of a `Resolver` — everything except the methods injected by
817
- * `defineResolver` (`default` and `resolveOptions`).
834
+ * The user-facing subset of a `Resolver` — everything except the four methods injected by
835
+ * `defineResolver` (`default`, `resolveOptions`, `resolvePath`, and `resolveFile`).
818
836
  *
819
- * When you pass a `UserResolver` to `defineResolver`, the standard `default` and
820
- * `resolveOptions` implementations are injected automatically so plugin authors never
821
- * need to define them by hand. Both can still be overridden by providing them explicitly.
837
+ * All four injected methods can still be overridden by providing them explicitly in the builder.
838
+ *
839
+ * @example
840
+ * ```ts
841
+ * export const resolver = defineResolver<PluginTs>(() => ({
842
+ * name: 'default',
843
+ * resolveName(node) { return this.default(node.name, 'function') },
844
+ * }))
845
+ * ```
846
+ */
847
+ type UserResolver = Omit<Resolver, 'default' | 'resolveOptions' | 'resolvePath' | 'resolveFile' | 'resolveBanner' | 'resolveFooter'>;
848
+ /**
849
+ * Base type for plugin builder objects.
850
+ * Concrete plugin builder types extend this with their own schema-building helpers.
851
+ * Use `defineBuilder` to define a builder object and export it alongside the plugin.
822
852
  */
823
- type UserResolver = Omit<Resolver, 'default' | 'resolveOptions'>;
853
+ type Builder = {
854
+ name: string;
855
+ };
824
856
  type PluginFactoryOptions<
825
857
  /**
826
858
  * Name to be used for the plugin.
@@ -846,13 +878,19 @@ TResolvePathOptions extends object = object,
846
878
  * Resolver object that encapsulates the naming and path-resolution helpers used by this plugin.
847
879
  * Use `defineResolver` to define the resolver object and export it alongside the plugin.
848
880
  */
849
- TResolver extends Resolver = Resolver> = {
881
+ TResolver extends Resolver = Resolver,
882
+ /**
883
+ * Builder object that encapsulates the schema-building helpers used by this plugin.
884
+ * Use `defineBuilder` to define the builder object and export it alongside the plugin.
885
+ */
886
+ TBuilder extends Builder = Builder> = {
850
887
  name: TName;
851
888
  options: TOptions;
852
889
  resolvedOptions: TResolvedOptions;
853
890
  context: TContext;
854
891
  resolvePathOptions: TResolvePathOptions;
855
892
  resolver: TResolver;
893
+ builder: TBuilder;
856
894
  };
857
895
  type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
858
896
  /**
@@ -915,6 +953,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
915
953
  * Options can als be included.
916
954
  * @type hookFirst
917
955
  * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
956
+ * @deprecated this will be replaced by resolvers
918
957
  */
919
958
  resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path;
920
959
  /**
@@ -922,6 +961,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
922
961
  * Useful when converting to PascalCase or camelCase.
923
962
  * @type hookFirst
924
963
  * @example ('pet') => 'Pet'
964
+ * @deprecated this will be replaced by resolvers
925
965
  */
926
966
  resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
927
967
  };
@@ -990,7 +1030,7 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
990
1030
  /**
991
1031
  * Specify the export location for the files and define the behavior of the output
992
1032
  */
993
- type Output<TOptions> = {
1033
+ type Output<_TOptions = unknown> = {
994
1034
  /**
995
1035
  * Path to the output folder or file that will contain the generated code
996
1036
  */
@@ -1003,11 +1043,11 @@ type Output<TOptions> = {
1003
1043
  /**
1004
1044
  * Add a banner text in the beginning of every file
1005
1045
  */
1006
- banner?: string | ((options: TOptions) => string);
1046
+ banner?: string | ((node: RootNode) => string);
1007
1047
  /**
1008
1048
  * Add a footer text in the beginning of every file
1009
1049
  */
1010
- footer?: string | ((options: TOptions) => string);
1050
+ footer?: string | ((node: RootNode) => string);
1011
1051
  /**
1012
1052
  * Whether to override existing external files if they already exist.
1013
1053
  * @default false
@@ -1051,8 +1091,8 @@ type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Logger<TOption
1051
1091
  */
1052
1092
  type CompatibilityPreset = 'default' | 'kubbV4';
1053
1093
  /**
1054
- * A preset bundles a name, one or more resolvers, and optional AST transformers
1055
- * into a single reusable configuration object.
1094
+ * A preset bundles a name, one or more resolvers, optional AST transformers,
1095
+ * and optional generators into a single reusable configuration object.
1056
1096
  *
1057
1097
  * @template TResolver - The concrete resolver type for this preset.
1058
1098
  */
@@ -1069,6 +1109,11 @@ type Preset<TResolver extends Resolver = Resolver> = {
1069
1109
  * Optional AST visitors / transformers applied after resolving.
1070
1110
  */
1071
1111
  transformers?: Array<Visitor>;
1112
+ /**
1113
+ * Optional generators used by this preset. Plugin implementations cast this
1114
+ * to their concrete generator type.
1115
+ */
1116
+ generators?: Array<Generator<any>>;
1072
1117
  };
1073
1118
  /**
1074
1119
  * A named registry of presets, keyed by preset name.
@@ -1077,6 +1122,128 @@ type Preset<TResolver extends Resolver = Resolver> = {
1077
1122
  * @template TName - The union of valid preset name keys.
1078
1123
  */
1079
1124
  type Presets<TResolver extends Resolver = Resolver> = Record<CompatibilityPreset, Preset<TResolver>>;
1125
+ type ByTag = {
1126
+ type: 'tag';
1127
+ pattern: string | RegExp;
1128
+ };
1129
+ type ByOperationId = {
1130
+ type: 'operationId';
1131
+ pattern: string | RegExp;
1132
+ };
1133
+ type ByPath = {
1134
+ type: 'path';
1135
+ pattern: string | RegExp;
1136
+ };
1137
+ type ByMethod = {
1138
+ type: 'method';
1139
+ pattern: HttpMethod | RegExp;
1140
+ };
1141
+ type BySchemaName = {
1142
+ type: 'schemaName';
1143
+ pattern: string | RegExp;
1144
+ };
1145
+ type ByContentType = {
1146
+ type: 'contentType';
1147
+ pattern: string | RegExp;
1148
+ };
1149
+ type Exclude = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
1150
+ type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType | BySchemaName;
1151
+ type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
1152
+ options: Partial<TOptions>;
1153
+ };
1154
+ type ResolvePathOptions = {
1155
+ pluginName?: string;
1156
+ group?: {
1157
+ tag?: string;
1158
+ path?: string;
1159
+ };
1160
+ type?: ResolveNameParams['type'];
1161
+ };
1162
+ /**
1163
+ * File-specific parameters for `Resolver.resolvePath`.
1164
+ *
1165
+ * Pass alongside a `ResolverContext` to identify which file to resolve.
1166
+ * Provide `tag` for tag-based grouping or `path` for path-based grouping.
1167
+ *
1168
+ * @example
1169
+ * ```ts
1170
+ * resolver.resolvePath(
1171
+ * { baseName: 'petTypes.ts', tag: 'pets' },
1172
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
1173
+ * )
1174
+ * // → '/src/types/petsController/petTypes.ts'
1175
+ * ```
1176
+ */
1177
+ type ResolverPathParams = {
1178
+ baseName: KubbFile.BaseName;
1179
+ pathMode?: KubbFile.Mode;
1180
+ /**
1181
+ * Tag value used when `group.type === 'tag'`.
1182
+ */
1183
+ tag?: string;
1184
+ /**
1185
+ * Path value used when `group.type === 'path'`.
1186
+ */
1187
+ path?: string;
1188
+ };
1189
+ /**
1190
+ * Shared context passed as the second argument to `Resolver.resolvePath` and `Resolver.resolveFile`.
1191
+ *
1192
+ * Describes where on disk output is rooted, which output config is active, and the optional
1193
+ * grouping strategy that controls subdirectory layout.
1194
+ *
1195
+ * @example
1196
+ * ```ts
1197
+ * const context: ResolverContext = {
1198
+ * root: config.root,
1199
+ * output,
1200
+ * group,
1201
+ * }
1202
+ * ```
1203
+ */
1204
+ type ResolverContext = {
1205
+ root: string;
1206
+ output: Output;
1207
+ group?: Group; /** Plugin name used to populate `meta.pluginName` on the resolved file. */
1208
+ pluginName?: string;
1209
+ };
1210
+ /**
1211
+ * File-specific parameters for `Resolver.resolveFile`.
1212
+ *
1213
+ * Pass alongside a `ResolverContext` to fully describe the file to resolve.
1214
+ * `tag` and `path` are used only when a matching `group` is present in the context.
1215
+ *
1216
+ * @example
1217
+ * ```ts
1218
+ * resolver.resolveFile(
1219
+ * { name: 'listPets', extname: '.ts', tag: 'pets' },
1220
+ * { root: '/src', output: { path: 'types' }, group: { type: 'tag' } },
1221
+ * )
1222
+ * // → { baseName: 'listPets.ts', path: '/src/types/petsController/listPets.ts', ... }
1223
+ * ```
1224
+ */
1225
+ type ResolverFileParams = {
1226
+ name: string;
1227
+ extname: KubbFile.Extname; /** Tag value used when `group.type === 'tag'`. */
1228
+ tag?: string; /** Path value used when `group.type === 'path'`. */
1229
+ path?: string;
1230
+ };
1231
+ /**
1232
+ * Context passed to `Resolver.resolveBanner` and `Resolver.resolveFooter`.
1233
+ *
1234
+ * `output` is optional — not every plugin configures a banner/footer.
1235
+ * `config` carries the global Kubb config, used to derive the default Kubb banner.
1236
+ *
1237
+ * @example
1238
+ * ```ts
1239
+ * resolver.resolveBanner(rootNode, { output: { banner: '// generated' }, config })
1240
+ * // → '// generated'
1241
+ * ```
1242
+ */
1243
+ type ResolveBannerContext = {
1244
+ output?: Pick<Output, 'banner' | 'footer'>;
1245
+ config: Config;
1246
+ };
1080
1247
  //#endregion
1081
1248
  //#region src/PluginDriver.d.ts
1082
1249
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
@@ -1199,5 +1366,5 @@ declare class PluginDriver {
1199
1366
  getPluginsByName(hookName: keyof PluginWithLifeCycle, pluginName: string): Plugin[];
1200
1367
  }
1201
1368
  //#endregion
1202
- export { ResolveOptionsContext as A, ReactGeneratorV2 as B, PluginParameter as C, Printer as D, Presets as E, UserPlugin as F, formatters as G, KubbEvents as H, UserPluginWithLifeCycle as I, PossiblePromise as J, linters as K, UserResolver as L, Resolver as M, UserConfig as N, PrinterFactoryOptions as O, UserLogger as P, CoreGeneratorV2 as R, PluginLifecycleHooks as S, Preset as T, Storage as U, defineGenerator as V, createStorage as W, AsyncEventEmitter as Y, Output as _, AdapterFactoryOptions as a, PluginFactoryOptions as b, CompatibilityPreset as c, Group as d, InputData as f, LoggerOptions as g, LoggerContext as h, Adapter as i, ResolvePathParams as j, ResolveNameParams as k, Config as l, Logger as m, PluginDriver as n, AdapterSource as o, InputPath as p, logLevel as q, getMode as r, BarrelType as s, GetFileOptions as t, DevtoolsOptions as u, Plugin as v, PluginWithLifeCycle as w, PluginLifecycle as x, PluginContext as y, Generator as z };
1203
- //# sourceMappingURL=PluginDriver-BkSenc-R.d.ts.map
1369
+ export { formatters as $, Printer as A, ResolverPathParams as B, PluginFactoryOptions as C, PluginWithLifeCycle as D, PluginParameter as E, ResolvePathOptions as F, UserResolver as G, UserLogger as H, ResolvePathParams as I, Generator as J, KubbEvents as K, Resolver as L, ResolveBannerContext as M, ResolveNameParams as N, Preset as O, ResolveOptionsContext as P, createStorage as Q, ResolverContext as R, PluginContext as S, PluginLifecycleHooks as T, UserPlugin as U, UserConfig as V, UserPluginWithLifeCycle as W, defineGenerator as X, ReactGeneratorV2 as Y, Storage as Z, LoggerContext as _, AdapterSource as a, Override as b, CompatibilityPreset as c, Exclude as d, linters as et, Group as f, Logger as g, InputPath as h, AdapterFactoryOptions as i, PrinterFactoryOptions as j, Presets as k, Config as l, InputData as m, getMode as n, PossiblePromise as nt, BarrelType as o, Include as p, CoreGeneratorV2 as q, Adapter as r, AsyncEventEmitter as rt, Builder as s, PluginDriver as t, logLevel as tt, DevtoolsOptions as u, LoggerOptions as v, PluginLifecycle as w, Plugin as x, Output as y, ResolverFileParams as z };
1370
+ //# sourceMappingURL=PluginDriver-CEQPafXV.d.ts.map
package/dist/hooks.cjs CHANGED
@@ -1,92 +1,15 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_chunk = require("./chunk-ByKO4r7w.cjs");
3
- let node_path = require("node:path");
4
- node_path = require_chunk.__toESM(node_path);
2
+ require("./chunk-ByKO4r7w.cjs");
5
3
  let _kubb_react_fabric = require("@kubb/react-fabric");
6
- //#region src/hooks/useKubb.ts
7
- /**
8
- * Generates the default "Generated by Kubb" banner from node metadata.
9
- */
10
- function buildDefaultBanner({ title, description, version, config }) {
11
- try {
12
- let source = "";
13
- if (Array.isArray(config.input)) {
14
- const first = config.input[0];
15
- if (first && "path" in first) source = node_path.default.basename(first.path);
16
- } else if ("path" in config.input) source = node_path.default.basename(config.input.path);
17
- else if ("data" in config.input) source = "text content";
18
- let banner = "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n";
19
- if (config.output.defaultBanner === "simple") {
20
- banner += "*/\n";
21
- return banner;
22
- }
23
- if (source) banner += `* Source: ${source}\n`;
24
- if (title) banner += `* Title: ${title}\n`;
25
- if (description) {
26
- const formattedDescription = description.replace(/\n/gm, "\n* ");
27
- banner += `* Description: ${formattedDescription}\n`;
28
- }
29
- if (version) banner += `* OpenAPI spec version: ${version}\n`;
30
- banner += "*/\n";
31
- return banner;
32
- } catch (_error) {
33
- return "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n*/";
34
- }
35
- }
36
- /**
37
- * React-Fabric hook that exposes the current plugin context inside a generator component.
38
- *
39
- * Returns the active `plugin`, `mode`, `config`, and a set of resolver helpers
40
- * (`getFile`, `resolveName`, `resolvePath`, `resolveBanner`, `resolveFooter`) that
41
- * all default to the current plugin when no explicit `pluginName` is provided.
42
- *
43
- * @example
44
- * ```ts
45
- * function Operation({ node }: OperationProps) {
46
- * const { config, resolvePath } = useKubb()
47
- * const filePath = resolvePath({ baseName: node.operationId })
48
- * return <File path={filePath}>...</File>
49
- * }
50
- * ```
51
- */
52
- function useKubb() {
4
+ //#region src/hooks/useDriver.ts
5
+ function useDriver() {
53
6
  const { meta } = (0, _kubb_react_fabric.useFabric)();
54
- const config = meta.driver.config;
55
- const defaultPluginName = meta.plugin.name;
56
- const output = meta.plugin.options?.output;
57
- return {
58
- plugin: meta.plugin,
59
- mode: meta.mode,
60
- config,
61
- getPluginByName: (pluginName = defaultPluginName) => meta.driver.getPluginByName.call(meta.driver, pluginName),
62
- getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.getFile.call(meta.driver, {
63
- pluginName,
64
- ...rest
65
- }),
66
- resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolveName.call(meta.driver, {
67
- pluginName,
68
- ...rest
69
- }),
70
- resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolvePath.call(meta.driver, {
71
- pluginName,
72
- ...rest
73
- }),
74
- resolveBanner: (node) => {
75
- if (typeof output?.banner === "function") return node ? output.banner(node) : buildDefaultBanner({ config });
76
- if (typeof output?.banner === "string") return output.banner;
77
- if (config.output.defaultBanner === false) return;
78
- return buildDefaultBanner({ config });
79
- },
80
- resolveFooter: (node) => {
81
- if (typeof output?.footer === "function") return node ? output.footer(node) : void 0;
82
- if (typeof output?.footer === "string") return output.footer;
83
- }
84
- };
7
+ return meta.driver;
85
8
  }
86
9
  //#endregion
87
10
  //#region src/hooks/useMode.ts
88
11
  /**
89
- * @deprecated use `useKubb` instead
12
+ * @deprecated use `mode` from the generator component props instead
90
13
  */
91
14
  function useMode() {
92
15
  const { meta } = (0, _kubb_react_fabric.useFabric)();
@@ -95,25 +18,15 @@ function useMode() {
95
18
  //#endregion
96
19
  //#region src/hooks/usePlugin.ts
97
20
  /**
98
- * @deprecated use useKubb instead
21
+ * @deprecated use `plugin` from the generator component props instead
99
22
  */
100
23
  function usePlugin() {
101
24
  const { meta } = (0, _kubb_react_fabric.useFabric)();
102
25
  return meta.plugin;
103
26
  }
104
27
  //#endregion
105
- //#region src/hooks/usePluginDriver.ts
106
- /**
107
- * @deprecated use `useKubb` instead
108
- */
109
- function usePluginDriver() {
110
- const { meta } = (0, _kubb_react_fabric.useFabric)();
111
- return meta.driver;
112
- }
113
- //#endregion
114
- exports.useKubb = useKubb;
28
+ exports.useDriver = useDriver;
115
29
  exports.useMode = useMode;
116
30
  exports.usePlugin = usePlugin;
117
- exports.usePluginDriver = usePluginDriver;
118
31
 
119
32
  //# sourceMappingURL=hooks.cjs.map
@@ -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 * @deprecated user `resolver` from options instead\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\n/**\n * React-Fabric hook that exposes the current plugin context inside a generator component.\n *\n * Returns the active `plugin`, `mode`, `config`, and a set of resolver helpers\n * (`getFile`, `resolveName`, `resolvePath`, `resolveBanner`, `resolveFooter`) that\n * all default to the current plugin when no explicit `pluginName` is provided.\n *\n * @example\n * ```ts\n * function Operation({ node }: OperationProps) {\n * const { config, resolvePath } = useKubb()\n * const filePath = resolvePath({ baseName: node.operationId })\n * return <File path={filePath}>...</File>\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":";;;;;;;;;AAsDA,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;;;;;;;;;;;;;;;;;;;AAoBX,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;;;;;;;ACxJH,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":[],"sources":["../src/hooks/useDriver.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts"],"sourcesContent":["import { useFabric } from '@kubb/react-fabric'\nimport type { PluginDriver } from '../PluginDriver.ts'\n\nexport function useDriver(): PluginDriver {\n const { meta } = useFabric<{ driver: PluginDriver }>()\n\n return meta.driver\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\n\n/**\n * @deprecated use `mode` from the generator component props 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 `plugin` from the generator component props 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"],"mappings":";;;;AAGA,SAAgB,YAA0B;CACxC,MAAM,EAAE,UAAA,GAAA,mBAAA,YAA8C;AAEtD,QAAO,KAAK;;;;;;;ACAd,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"}