@kubb/plugin-ts 4.5.1 → 4.5.3

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,14 +1,14 @@
1
- import { Fabric, FileManager } from "@kubb/react-fabric";
2
- import ts from "typescript";
3
1
  import * as OasTypes from "oas/types";
4
2
  import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
5
3
  import { Operation, Operation as Operation$1 } from "oas/operation";
6
4
  import { OpenAPIV3 } from "openapi-types";
7
5
  import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
8
6
  import BaseOas from "oas";
9
- import { KubbNode } from "@kubb/react-fabric/types";
10
7
  import { KubbFile } from "@kubb/fabric-core/types";
8
+ import { Fabric } from "@kubb/react-fabric";
11
9
  import { ConsolaInstance, LogLevel } from "consola";
10
+ import { KubbNode } from "@kubb/react-fabric/types";
11
+ import ts from "typescript";
12
12
 
13
13
  //#region ../oas/src/types.d.ts
14
14
  type contentType = 'application/json' | (string & {});
@@ -111,6 +111,21 @@ type Logger = {
111
111
  type PossiblePromise<T> = Promise<T> | T;
112
112
  //#endregion
113
113
  //#region ../core/src/types.d.ts
114
+ declare global {
115
+ namespace Kubb {
116
+ interface PluginContext {}
117
+ }
118
+ }
119
+ /**
120
+ * Config used in `kubb.config.ts`
121
+ *
122
+ * @example
123
+ * import { defineConfig } from '@kubb/core'
124
+ * export default defineConfig({
125
+ * ...
126
+ * })
127
+ */
128
+
114
129
  type InputPath = {
115
130
  /**
116
131
  * Specify your Swagger/OpenAPI file, either as an absolute path or a path relative to the root.
@@ -265,11 +280,8 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
265
280
  * Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
266
281
  */
267
282
  post?: Array<string>;
268
- } & (TOptions['context'] extends never ? {
269
- context?: never;
270
- } : {
271
- context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
272
- });
283
+ inject?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
284
+ };
273
285
  type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
274
286
  type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
275
287
  /**
@@ -295,25 +307,26 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
295
307
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
296
308
  */
297
309
  options: TOptions['resolvedOptions'];
298
- } & (TOptions['context'] extends never ? {
299
- context?: never;
300
- } : {
301
- context: TOptions['context'];
302
- });
310
+ install: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
311
+ /**
312
+ * Define a context that can be used by other plugins, see `PluginManager' where we convert from `UserPlugin` to `Plugin`(used when calling `definePlugin`).
313
+ */
314
+ inject: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => TOptions['context'];
315
+ };
303
316
  type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
304
317
  type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
305
318
  /**
306
319
  * Start of the lifecycle of a plugin.
307
320
  * @type hookParallel
308
321
  */
309
- buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
322
+ install?: (this: PluginContext<TOptions>, context: PluginContext<TOptions>) => PossiblePromise<void>;
310
323
  /**
311
324
  * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
312
325
  * Options can als be included.
313
326
  * @type hookFirst
314
327
  * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
315
328
  */
316
- resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
329
+ resolvePath?: (this: PluginContext<TOptions>, baseName: KubbFile.BaseName, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.Path;
317
330
  /**
318
331
  * Resolve to a name based on a string.
319
332
  * Useful when converting to PascalCase or camelCase.
@@ -321,11 +334,6 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
321
334
  * @example ('pet') => 'Pet'
322
335
  */
323
336
  resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
324
- /**
325
- * End of the plugin lifecycle.
326
- * @type hookParallel
327
- */
328
- buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
329
337
  };
330
338
  type PluginLifecycleHooks = keyof PluginLifecycle;
331
339
  type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
@@ -352,24 +360,15 @@ type ResolveNameParams = {
352
360
  type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
353
361
  fabric: Fabric;
354
362
  config: Config;
355
- /**
356
- * @deprecated
357
- */
358
- fileManager: FileManager;
359
363
  pluginManager: PluginManager;
360
- addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.ResolvedFile>>;
361
- resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
362
- resolveName: (params: ResolveNameParams) => string;
364
+ addFile: (...file: Array<KubbFile.File>) => Promise<void>;
363
365
  logger: Logger;
364
- /**
365
- * All plugins
366
- */
367
- plugins: Plugin[];
366
+ mode: KubbFile.Mode;
368
367
  /**
369
368
  * Current plugin
370
369
  */
371
370
  plugin: Plugin<TOptions>;
372
- };
371
+ } & Kubb.PluginContext;
373
372
  /**
374
373
  * Specify the export location for the files and define the behavior of the output
375
374
  */
@@ -444,13 +443,14 @@ type GetFileProps<TOptions = object> = {
444
443
  };
445
444
  declare class PluginManager {
446
445
  #private;
447
- readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
448
446
  readonly events: EventEmitter<Events>;
449
447
  readonly config: Config;
450
448
  readonly executed: Array<Executer>;
451
449
  readonly logger: Logger;
452
450
  readonly options: Options$2;
453
451
  constructor(config: Config, options: Options$2);
452
+ getContext<TOptions extends PluginFactoryOptions>(plugin: Plugin<TOptions>): PluginContext<TOptions> & Record<string, any>;
453
+ get plugins(): Array<Plugin>;
454
454
  getFile<TOptions = object>({
455
455
  name,
456
456
  mode,
@@ -460,7 +460,7 @@ declare class PluginManager {
460
460
  }: GetFileProps<TOptions>): KubbFile.File<{
461
461
  pluginKey: Plugin['key'];
462
462
  }>;
463
- resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
463
+ resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.Path;
464
464
  resolveName: (params: ResolveNameParams) => string;
465
465
  /**
466
466
  * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
@@ -548,15 +548,140 @@ declare class PluginManager {
548
548
  }): Promise<void>;
549
549
  getPluginByKey(pluginKey: Plugin['key']): Plugin | undefined;
550
550
  getPluginsByKey(hookName: keyof PluginWithLifeCycle, pluginKey: Plugin['key']): Plugin[];
551
- static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = (T3 extends never ? (T2 extends never ? [T1: Plugin<T1>] : [T1: Plugin<T1>, T2: Plugin<T2>]) : [T1: Plugin<T1>, T2: Plugin<T2>, T3: Plugin<T3>])>(plugins: Array<Plugin>, dependedPluginNames: string | string[]): TOutput;
552
- static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
553
551
  }
554
552
  //#endregion
555
- //#region ../core/src/FileManager.d.ts
553
+ //#region ../core/src/utils/getBarrelFiles.d.ts
556
554
  type FileMetaBase = {
557
555
  pluginKey?: Plugin['key'];
558
556
  };
559
557
  //#endregion
558
+ //#region ../plugin-oas/src/types.d.ts
559
+ type Context$2 = {
560
+ getOas(): Promise<Oas>;
561
+ getBaseURL(): Promise<string | undefined>;
562
+ };
563
+ declare global {
564
+ namespace Kubb {
565
+ interface PluginContext extends Context$2 {}
566
+ }
567
+ }
568
+ type ResolvePathOptions = {
569
+ pluginKey?: Plugin['key'];
570
+ group?: {
571
+ tag?: string;
572
+ path?: string;
573
+ };
574
+ type?: ResolveNameParams['type'];
575
+ };
576
+ /**
577
+ * `propertyName` is the ref name + resolved with the nameResolver
578
+ * @example import { Pet } from './Pet'
579
+ *
580
+ * `originalName` is the original name used(in PascalCase), only used to remove duplicates
581
+ *
582
+ * `pluginKey` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
583
+ * @example import a type(plugin-ts) for a mock file(swagger-faker)
584
+ */
585
+ type Ref = {
586
+ propertyName: string;
587
+ originalName: string;
588
+ path: KubbFile.Path;
589
+ pluginKey?: Plugin['key'];
590
+ };
591
+ type Refs = Record<string, Ref>;
592
+ type OperationSchema = {
593
+ /**
594
+ * Converted name, contains already `PathParams`, `QueryParams`, ...
595
+ */
596
+ name: string;
597
+ schema: SchemaObject$1;
598
+ operation?: Operation$1;
599
+ /**
600
+ * OperationName in PascalCase, only being used in OperationGenerator
601
+ */
602
+ operationName: string;
603
+ description?: string;
604
+ statusCode?: number;
605
+ keys?: string[];
606
+ keysToOmit?: string[];
607
+ withData?: boolean;
608
+ };
609
+ type OperationSchemas = {
610
+ pathParams?: OperationSchema & {
611
+ keysToOmit?: never;
612
+ };
613
+ queryParams?: OperationSchema & {
614
+ keysToOmit?: never;
615
+ };
616
+ headerParams?: OperationSchema & {
617
+ keysToOmit?: never;
618
+ };
619
+ request?: OperationSchema;
620
+ response: OperationSchema;
621
+ responses: Array<OperationSchema>;
622
+ statusCodes?: Array<OperationSchema>;
623
+ errors?: Array<OperationSchema>;
624
+ };
625
+ type ByTag = {
626
+ type: 'tag';
627
+ pattern: string | RegExp;
628
+ };
629
+ type ByOperationId = {
630
+ type: 'operationId';
631
+ pattern: string | RegExp;
632
+ };
633
+ type ByPath = {
634
+ type: 'path';
635
+ pattern: string | RegExp;
636
+ };
637
+ type ByMethod = {
638
+ type: 'method';
639
+ pattern: HttpMethod | RegExp;
640
+ };
641
+ type BySchemaName = {
642
+ type: 'schemaName';
643
+ pattern: string | RegExp;
644
+ };
645
+ type ByContentType = {
646
+ type: 'contentType';
647
+ pattern: string | RegExp;
648
+ };
649
+ type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
650
+ type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
651
+ type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
652
+ options: Partial<TOptions>;
653
+ };
654
+ //#endregion
655
+ //#region ../plugin-oas/src/OperationGenerator.d.ts
656
+ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
657
+ fabric: Fabric;
658
+ oas: Oas;
659
+ exclude: Array<Exclude$1> | undefined;
660
+ include: Array<Include> | undefined;
661
+ override: Array<Override<TOptions>> | undefined;
662
+ contentType: contentType | undefined;
663
+ pluginManager: PluginManager;
664
+ /**
665
+ * Current plugin
666
+ */
667
+ plugin: Plugin<TPluginOptions>;
668
+ mode: KubbFile.Mode;
669
+ };
670
+ declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context$1<TPluginOptions['resolvedOptions'], TPluginOptions>> {
671
+ #private;
672
+ getSchemas(operation: Operation$1, {
673
+ resolveName
674
+ }?: {
675
+ resolveName?: (name: string) => string;
676
+ }): OperationSchemas;
677
+ getOperations(): Promise<Array<{
678
+ path: string;
679
+ method: HttpMethod;
680
+ operation: Operation$1;
681
+ }>>;
682
+ build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
683
+ }
684
+ //#endregion
560
685
  //#region ../plugin-oas/src/SchemaMapper.d.ts
561
686
  type SchemaKeywordMapper = {
562
687
  object: {
@@ -670,7 +795,7 @@ type SchemaKeywordMapper = {
670
795
  /**
671
796
  * Full qualified path.
672
797
  */
673
- path: KubbFile.OptionalPath;
798
+ path: KubbFile.Path;
674
799
  /**
675
800
  * When true `File.Import` will be used.
676
801
  * When false a reference will be used inside the current file.
@@ -774,96 +899,8 @@ type Schema = {
774
899
  keyword: string;
775
900
  } | SchemaKeywordMapper[keyof SchemaKeywordMapper];
776
901
  //#endregion
777
- //#region ../plugin-oas/src/types.d.ts
778
- type ResolvePathOptions = {
779
- pluginKey?: Plugin['key'];
780
- group?: {
781
- tag?: string;
782
- path?: string;
783
- };
784
- type?: ResolveNameParams['type'];
785
- };
786
- /**
787
- * `propertyName` is the ref name + resolved with the nameResolver
788
- * @example import { Pet } from './Pet'
789
- *
790
- * `originalName` is the original name used(in PascalCase), only used to remove duplicates
791
- *
792
- * `pluginKey` can be used to override the current plugin being used, handy when you want to import a type/schema out of another plugin
793
- * @example import a type(plugin-ts) for a mock file(swagger-faker)
794
- */
795
- type Ref = {
796
- propertyName: string;
797
- originalName: string;
798
- path: KubbFile.OptionalPath;
799
- pluginKey?: Plugin['key'];
800
- };
801
- type Refs = Record<string, Ref>;
802
- type OperationSchema = {
803
- /**
804
- * Converted name, contains already `PathParams`, `QueryParams`, ...
805
- */
806
- name: string;
807
- schema: SchemaObject$1;
808
- operation?: Operation$1;
809
- /**
810
- * OperationName in PascalCase, only being used in OperationGenerator
811
- */
812
- operationName: string;
813
- description?: string;
814
- statusCode?: number;
815
- keys?: string[];
816
- keysToOmit?: string[];
817
- withData?: boolean;
818
- };
819
- type OperationSchemas = {
820
- pathParams?: OperationSchema & {
821
- keysToOmit?: never;
822
- };
823
- queryParams?: OperationSchema & {
824
- keysToOmit?: never;
825
- };
826
- headerParams?: OperationSchema & {
827
- keysToOmit?: never;
828
- };
829
- request?: OperationSchema;
830
- response: OperationSchema;
831
- responses: Array<OperationSchema>;
832
- statusCodes?: Array<OperationSchema>;
833
- errors?: Array<OperationSchema>;
834
- };
835
- type ByTag = {
836
- type: 'tag';
837
- pattern: string | RegExp;
838
- };
839
- type ByOperationId = {
840
- type: 'operationId';
841
- pattern: string | RegExp;
842
- };
843
- type ByPath = {
844
- type: 'path';
845
- pattern: string | RegExp;
846
- };
847
- type ByMethod = {
848
- type: 'method';
849
- pattern: HttpMethod | RegExp;
850
- };
851
- type BySchemaName = {
852
- type: 'schemaName';
853
- pattern: string | RegExp;
854
- };
855
- type ByContentType = {
856
- type: 'contentType';
857
- pattern: string | RegExp;
858
- };
859
- type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
860
- type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
861
- type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
862
- options: Partial<TOptions>;
863
- };
864
- //#endregion
865
902
  //#region ../plugin-oas/src/SchemaGenerator.d.ts
866
- type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
903
+ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
867
904
  fabric: Fabric;
868
905
  oas: Oas;
869
906
  pluginManager: PluginManager;
@@ -904,7 +941,7 @@ type SchemaProps$1 = {
904
941
  name?: string;
905
942
  parentName?: string;
906
943
  };
907
- declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context$1<TOptions, TPluginOptions>> {
944
+ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context<TOptions, TPluginOptions>> {
908
945
  #private;
909
946
  refs: Refs;
910
947
  /**
@@ -919,15 +956,6 @@ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGe
919
956
  build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
920
957
  }
921
958
  //#endregion
922
- //#region ../plugin-oas/src/generators/createGenerator.d.ts
923
- type CoreGenerator<TOptions extends PluginFactoryOptions> = {
924
- name: string;
925
- type: 'core';
926
- operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
927
- operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
928
- schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
929
- };
930
- //#endregion
931
959
  //#region ../plugin-oas/src/generators/createReactGenerator.d.ts
932
960
  type ReactGenerator<TOptions extends PluginFactoryOptions> = {
933
961
  name: string;
@@ -962,35 +990,14 @@ type SchemaProps<TOptions extends PluginFactoryOptions> = {
962
990
  };
963
991
  type Generator<TOptions extends PluginFactoryOptions> = CoreGenerator<TOptions> | ReactGenerator<TOptions>;
964
992
  //#endregion
965
- //#region ../plugin-oas/src/OperationGenerator.d.ts
966
- type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
967
- fabric: Fabric;
968
- oas: Oas;
969
- exclude: Array<Exclude$1> | undefined;
970
- include: Array<Include> | undefined;
971
- override: Array<Override<TOptions>> | undefined;
972
- contentType: contentType | undefined;
973
- pluginManager: PluginManager;
974
- /**
975
- * Current plugin
976
- */
977
- plugin: Plugin<TPluginOptions>;
978
- mode: KubbFile.Mode;
993
+ //#region ../plugin-oas/src/generators/createGenerator.d.ts
994
+ type CoreGenerator<TOptions extends PluginFactoryOptions> = {
995
+ name: string;
996
+ type: 'core';
997
+ operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>;
998
+ operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>;
999
+ schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>;
979
1000
  };
980
- declare class OperationGenerator<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TPluginOptions['resolvedOptions'], Context<TPluginOptions['resolvedOptions'], TPluginOptions>> {
981
- #private;
982
- getSchemas(operation: Operation$1, {
983
- resolveName
984
- }?: {
985
- resolveName?: (name: string) => string;
986
- }): OperationSchemas;
987
- getOperations(): Promise<Array<{
988
- path: string;
989
- method: HttpMethod;
990
- operation: Operation$1;
991
- }>>;
992
- build(...generators: Array<Generator<TPluginOptions>>): Promise<Array<KubbFile.File<TFileMeta>>>;
993
- }
994
1001
  //#endregion
995
1002
  //#region src/types.d.ts
996
1003
  type Options$1 = {
@@ -1100,9 +1107,7 @@ type ResolvedOptions = {
1100
1107
  syntaxType: NonNullable<Options$1['syntaxType']>;
1101
1108
  mapper: Record<string, any>;
1102
1109
  };
1103
- type PluginTs = PluginFactoryOptions<'plugin-ts', Options$1, ResolvedOptions, {
1104
- usedEnumNames: Record<string, number>;
1105
- }, ResolvePathOptions>;
1110
+ type PluginTs = PluginFactoryOptions<'plugin-ts', Options$1, ResolvedOptions, never, ResolvePathOptions>;
1106
1111
  //#endregion
1107
1112
  export { UserPluginWithLifeCycle as a, Schema as i, PluginTs as n, OasTypes as o, ReactGenerator as r, SchemaObject$1 as s, Options$1 as t };
1108
- //# sourceMappingURL=types-BXlkWRNi.d.ts.map
1113
+ //# sourceMappingURL=types-3bqiJQCB.d.cts.map