@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.
- package/dist/{PluginDriver-BkSenc-R.d.ts → PluginDriver-CEQPafXV.d.ts} +271 -104
- package/dist/hooks.cjs +7 -94
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +6 -79
- package/dist/hooks.js +6 -91
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +313 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +260 -24
- package/dist/index.js +308 -33
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/defineBuilder.ts +26 -0
- package/src/defineGenerator.ts +3 -0
- package/src/definePreset.ts +9 -5
- package/src/defineResolver.ts +333 -16
- package/src/hooks/index.ts +1 -2
- package/src/hooks/{usePluginDriver.ts → useDriver.ts} +1 -4
- package/src/hooks/useMode.ts +1 -1
- package/src/hooks/usePlugin.ts +1 -1
- package/src/index.ts +10 -1
- package/src/renderNode.tsx +10 -13
- package/src/types.ts +204 -16
- package/src/utils/getBarrelFiles.ts +1 -1
- package/src/utils/getPreset.ts +17 -6
- package/src/hooks/useKubb.ts +0 -160
|
@@ -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
|
|
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?:
|
|
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 `
|
|
807
|
-
* authors may override them but never need to implement them
|
|
808
|
-
*
|
|
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 `
|
|
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
|
-
*
|
|
820
|
-
*
|
|
821
|
-
*
|
|
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
|
|
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<
|
|
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 | ((
|
|
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 | ((
|
|
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,
|
|
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 {
|
|
1203
|
-
//# sourceMappingURL=PluginDriver-
|
|
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
|
-
|
|
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/
|
|
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
|
-
|
|
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 `
|
|
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
|
|
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
|
-
|
|
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
|
package/dist/hooks.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.cjs","names":[
|
|
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"}
|