@kubb/plugin-faker 4.1.4 → 4.2.1

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,4 +1,5 @@
1
1
  import { ConsolaInstance, LogLevel } from "consola";
2
+ import { FileManager } from "@kubb/fabric-core";
2
3
  import * as OasTypes from "oas/types";
3
4
  import { HttpMethods as HttpMethod, OASDocument, SchemaObject, User } from "oas/types";
4
5
  import { Operation, Operation as Operation$1 } from "oas/operation";
@@ -11,17 +12,17 @@ import BaseOas from "oas";
11
12
  * Abstract class that contains the building blocks for plugins to create their own Generator
12
13
  * @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
13
14
  */
14
- declare abstract class BaseGenerator<TOptions = unknown, TContext = unknown> {
15
+ declare abstract class BaseGenerator<TOptions$1 = unknown, TContext = unknown> {
15
16
  #private;
16
- constructor(options?: TOptions, context?: TContext);
17
- get options(): TOptions;
17
+ constructor(options?: TOptions$1, context?: TContext);
18
+ get options(): TOptions$1;
18
19
  get context(): TContext;
19
- set options(options: TOptions);
20
+ set options(options: TOptions$1);
20
21
  abstract build(...params: unknown[]): unknown;
21
22
  }
22
23
  //#endregion
23
24
  //#region ../core/src/fs/types.d.ts
24
- type BasePath<T extends string = string> = `${T}/`;
25
+ type BasePath<T$1 extends string = string> = `${T$1}/`;
25
26
  type Import = {
26
27
  /**
27
28
  * Import name to be used
@@ -95,7 +96,7 @@ type BaseName = `${string}.${string}`;
95
96
  * Path will be full qualified path to a specified file
96
97
  */
97
98
  type Path = string;
98
- type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
99
+ type AdvancedPath<T$1 extends BaseName = BaseName> = `${BasePath}${T$1}`;
99
100
  type OptionalPath = Path | undefined | null;
100
101
  type File<TMeta extends object = object> = {
101
102
  /**
@@ -184,9 +185,7 @@ type Logger = {
184
185
  };
185
186
  //#endregion
186
187
  //#region ../core/src/utils/types.d.ts
187
- type PossiblePromise<T> = Promise<T> | T;
188
- type ArrayWithLength<T extends number, U extends any[] = []> = U['length'] extends T ? U : ArrayWithLength<T, [true, ...U]>;
189
- type GreaterThan<T extends number, U extends number> = ArrayWithLength<U> extends [...ArrayWithLength<T>, ...infer _] ? false : true;
188
+ type PossiblePromise<T$1> = Promise<T$1> | T$1;
190
189
  //#endregion
191
190
  //#region ../core/src/types.d.ts
192
191
  type InputPath = {
@@ -299,11 +298,11 @@ TName extends string = string,
299
298
  /**
300
299
  * Options of the plugin.
301
300
  */
302
- TOptions extends object = object,
301
+ TOptions$1 extends object = object,
303
302
  /**
304
303
  * Options of the plugin that can be used later on, see `options` inside your plugin config.
305
304
  */
306
- TResolvedOptions extends object = TOptions,
305
+ TResolvedOptions extends object = TOptions$1,
307
306
  /**
308
307
  * Context that you want to expose to other plugins.
309
308
  */
@@ -317,23 +316,23 @@ TResolvePathOptions extends object = object> = {
317
316
  * Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
318
317
  */
319
318
  key: PluginKey<TName | string>;
320
- options: TOptions;
319
+ options: TOptions$1;
321
320
  resolvedOptions: TResolvedOptions;
322
321
  context: TContext;
323
322
  resolvePathOptions: TResolvePathOptions;
324
323
  };
325
324
  type PluginKey<TName> = [name: TName, identifier?: string | number];
326
- type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
325
+ type UserPlugin<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
327
326
  /**
328
327
  * Unique name used for the plugin
329
328
  * The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
330
329
  * @example @kubb/typescript
331
330
  */
332
- name: TOptions['name'];
331
+ name: TOptions$1['name'];
333
332
  /**
334
333
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
335
334
  */
336
- options: TOptions['resolvedOptions'];
335
+ options: TOptions$1['resolvedOptions'];
337
336
  /**
338
337
  * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
339
338
  * Can be used to validate dependent plugins.
@@ -343,23 +342,23 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
343
342
  * 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.
344
343
  */
345
344
  post?: Array<string>;
346
- } & (TOptions['context'] extends never ? {
345
+ } & (TOptions$1['context'] extends never ? {
347
346
  context?: never;
348
347
  } : {
349
- context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
348
+ context: (this: TOptions$1['name'] extends 'core' ? null : Omit<PluginContext<TOptions$1>, 'addFile'>) => TOptions$1['context'];
350
349
  });
351
- type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
352
- type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
350
+ type UserPluginWithLifeCycle<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions$1> & PluginLifecycle<TOptions$1>;
351
+ type Plugin<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
353
352
  /**
354
353
  * Unique name used for the plugin
355
354
  * @example @kubb/typescript
356
355
  */
357
- name: TOptions['name'];
356
+ name: TOptions$1['name'];
358
357
  /**
359
358
  * Internal key used when a developer uses more than one of the same plugin
360
359
  * @private
361
360
  */
362
- key: TOptions['key'];
361
+ key: TOptions$1['key'];
363
362
  /**
364
363
  * Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
365
364
  * Can be used to validate dependent plugins.
@@ -372,49 +371,49 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
372
371
  /**
373
372
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
374
373
  */
375
- options: TOptions['resolvedOptions'];
376
- } & (TOptions['context'] extends never ? {
374
+ options: TOptions$1['resolvedOptions'];
375
+ } & (TOptions$1['context'] extends never ? {
377
376
  context?: never;
378
377
  } : {
379
- context: TOptions['context'];
378
+ context: TOptions$1['context'];
380
379
  });
381
- type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
382
- type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
380
+ type PluginWithLifeCycle<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions$1> & PluginLifecycle<TOptions$1>;
381
+ type PluginLifecycle<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
383
382
  /**
384
383
  * Start of the lifecycle of a plugin.
385
384
  * @type hookParallel
386
385
  */
387
- buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
386
+ buildStart?: (this: PluginContext<TOptions$1>, Config: Config) => PossiblePromise<void>;
388
387
  /**
389
388
  * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
390
389
  * Options can als be included.
391
390
  * @type hookFirst
392
391
  * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
393
392
  */
394
- resolvePath?: (this: PluginContext<TOptions>, baseName: BaseName, mode?: Mode, options?: TOptions['resolvePathOptions']) => OptionalPath;
393
+ resolvePath?: (this: PluginContext<TOptions$1>, baseName: BaseName, mode?: Mode, options?: TOptions$1['resolvePathOptions']) => OptionalPath;
395
394
  /**
396
395
  * Resolve to a name based on a string.
397
396
  * Useful when converting to PascalCase or camelCase.
398
397
  * @type hookFirst
399
398
  * @example ('pet') => 'Pet'
400
399
  */
401
- resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
400
+ resolveName?: (this: PluginContext<TOptions$1>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
402
401
  /**
403
402
  * End of the plugin lifecycle.
404
403
  * @type hookParallel
405
404
  */
406
- buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
405
+ buildEnd?: (this: PluginContext<TOptions$1>) => PossiblePromise<void>;
407
406
  };
408
407
  type PluginLifecycleHooks = keyof PluginLifecycle;
409
- type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
410
- type ResolvePathParams<TOptions = object> = {
408
+ type PluginParameter<H$1 extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H$1]>;
409
+ type ResolvePathParams<TOptions$1 = object> = {
411
410
  pluginKey?: Plugin['key'];
412
411
  baseName: BaseName;
413
412
  mode?: Mode;
414
413
  /**
415
414
  * Options to be passed to 'resolvePath' 3th parameter
416
415
  */
417
- options?: TOptions;
416
+ options?: TOptions$1;
418
417
  };
419
418
  type ResolveNameParams = {
420
419
  name: string;
@@ -427,12 +426,15 @@ type ResolveNameParams = {
427
426
  */
428
427
  type?: 'file' | 'function' | 'type' | 'const';
429
428
  };
430
- type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
429
+ type PluginContext<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
431
430
  config: Config;
431
+ /**
432
+ * @deprecated
433
+ */
432
434
  fileManager: FileManager;
433
435
  pluginManager: PluginManager;
434
436
  addFile: (...file: Array<File>) => Promise<Array<ResolvedFile>>;
435
- resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => OptionalPath;
437
+ resolvePath: (params: ResolvePathParams<TOptions$1['resolvePathOptions']>) => OptionalPath;
436
438
  resolveName: (params: ResolveNameParams) => string;
437
439
  logger: Logger;
438
440
  /**
@@ -442,12 +444,12 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
442
444
  /**
443
445
  * Current plugin
444
446
  */
445
- plugin: Plugin<TOptions>;
447
+ plugin: Plugin<TOptions$1>;
446
448
  };
447
449
  /**
448
450
  * Specify the export location for the files and define the behavior of the output
449
451
  */
450
- type Output<TOptions> = {
452
+ type Output<TOptions$1> = {
451
453
  /**
452
454
  * Path to the output folder or file that will contain the generated code
453
455
  */
@@ -460,11 +462,11 @@ type Output<TOptions> = {
460
462
  /**
461
463
  * Add a banner text in the beginning of every file
462
464
  */
463
- banner?: string | ((options: TOptions) => string);
465
+ banner?: string | ((options: TOptions$1) => string);
464
466
  /**
465
467
  * Add a footer text in the beginning of every file
466
468
  */
467
- footer?: string | ((options: TOptions) => string);
469
+ footer?: string | ((options: TOptions$1) => string);
468
470
  };
469
471
  type GroupContext = {
470
472
  group: string;
@@ -480,73 +482,19 @@ type Group = {
480
482
  name?: (context: GroupContext) => string;
481
483
  };
482
484
  //#endregion
483
- //#region ../core/src/FileManager.d.ts
484
- type FileMetaBase = {
485
- pluginKey?: Plugin['key'];
486
- };
487
- type AddResult<T extends Array<File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<ResolvedFile[]> : Promise<ResolvedFile>>>;
488
- type AddIndexesProps = {
489
- type: BarrelType | false | undefined;
490
- /**
491
- * Root based on root and output.path specified in the config
492
- */
493
- root: string;
494
- /**
495
- * Output for plugin
496
- */
497
- output: {
498
- path: string;
499
- };
500
- group?: {
501
- output: string;
502
- exportAs: string;
503
- };
504
- logger?: Logger;
505
- meta?: FileMetaBase;
506
- };
507
- type WriteFilesProps = {
508
- root: Config['root'];
509
- extension?: Record<Extname, Extname | ''>;
510
- logger?: Logger;
511
- dryRun?: boolean;
512
- };
513
- declare class FileManager {
514
- #private;
515
- constructor();
516
- add<T extends Array<File> = Array<File>>(...files: T): AddResult<T>;
517
- getByPath(path: Path): Promise<ResolvedFile | null>;
518
- deleteByPath(path: Path): Promise<void>;
519
- clear(): Promise<void>;
520
- getFiles(): Promise<Array<ResolvedFile>>;
521
- processFiles({
522
- dryRun,
523
- root,
524
- extension,
525
- logger
526
- }: WriteFilesProps): Promise<Array<ResolvedFile>>;
527
- getBarrelFiles({
528
- type,
529
- meta,
530
- root,
531
- output,
532
- logger
533
- }: AddIndexesProps): Promise<File[]>;
534
- static getMode(path: string | undefined | null): Mode;
535
- }
536
- //#endregion
537
485
  //#region ../core/src/PluginManager.d.ts
538
486
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
539
487
  type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
540
- type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
488
+ type Executer<H$1 extends PluginLifecycleHooks = PluginLifecycleHooks> = {
541
489
  message: string;
542
490
  strategy: Strategy;
543
- hookName: H;
491
+ hookName: H$1;
544
492
  plugin: Plugin;
545
493
  parameters?: unknown[] | undefined;
546
494
  output?: unknown;
547
495
  };
548
- type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
549
- type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
496
+ type ParseResult<H$1 extends PluginLifecycleHooks> = RequiredPluginLifecycle[H$1];
497
+ type SafeParseResult<H$1 extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H$1>>> = {
550
498
  result: Result;
551
499
  plugin: Plugin;
552
500
  };
@@ -562,16 +510,19 @@ type Events = {
562
510
  executed: [executer: Executer];
563
511
  error: [error: Error];
564
512
  };
565
- type GetFileProps<TOptions = object> = {
513
+ type GetFileProps<TOptions$1 = object> = {
566
514
  name: string;
567
515
  mode?: Mode;
568
516
  extname: Extname;
569
517
  pluginKey: Plugin['key'];
570
- options?: TOptions;
518
+ options?: TOptions$1;
571
519
  };
572
520
  declare class PluginManager {
573
521
  #private;
574
522
  readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
523
+ /**
524
+ * @deprecated do not use from pluginManager
525
+ */
575
526
  readonly fileManager: FileManager;
576
527
  readonly events: EventEmitter<Events>;
577
528
  readonly config: Config;
@@ -680,6 +631,11 @@ declare class PluginManager {
680
631
  static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
681
632
  }
682
633
  //#endregion
634
+ //#region ../core/src/FileManager.d.ts
635
+ type FileMetaBase = {
636
+ pluginKey?: Plugin['key'];
637
+ };
638
+ //#endregion
683
639
  //#region ../oas/src/types.d.ts
684
640
  type contentType = 'application/json' | (string & {});
685
641
  type SchemaObject$1 = OasTypes.SchemaObject & {
@@ -1008,12 +964,12 @@ type ByContentType = {
1008
964
  };
1009
965
  type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
1010
966
  type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
1011
- type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
1012
- options: Partial<TOptions>;
967
+ type Override<TOptions$1> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
968
+ options: Partial<TOptions$1>;
1013
969
  };
1014
970
  //#endregion
1015
971
  //#region ../plugin-oas/src/SchemaGenerator.d.ts
1016
- type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
972
+ type Context$1<TOptions$1, TPluginOptions extends PluginFactoryOptions> = {
1017
973
  oas: Oas;
1018
974
  pluginManager: PluginManager;
1019
975
  /**
@@ -1022,7 +978,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
1022
978
  plugin: Plugin<TPluginOptions>;
1023
979
  mode: Mode;
1024
980
  include?: Array<'schemas' | 'responses' | 'requestBodies'>;
1025
- override: Array<Override<TOptions>> | undefined;
981
+ override: Array<Override<TOptions$1>> | undefined;
1026
982
  contentType?: contentType;
1027
983
  output?: string;
1028
984
  };
@@ -1053,7 +1009,7 @@ type SchemaProps$1 = {
1053
1009
  name?: string;
1054
1010
  parentName?: string;
1055
1011
  };
1056
- declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context$1<TOptions, TPluginOptions>> {
1012
+ declare class SchemaGenerator<TOptions$1 extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions$1, Context$1<TOptions$1, TPluginOptions>> {
1057
1013
  #private;
1058
1014
  refs: Refs;
1059
1015
  /**
@@ -1072,39 +1028,39 @@ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGe
1072
1028
  }
1073
1029
  //#endregion
1074
1030
  //#region ../plugin-oas/src/generator.d.ts
1075
- type OperationsProps<TOptions extends PluginFactoryOptions> = {
1076
- instance: Omit<OperationGenerator<TOptions>, 'build'>;
1077
- options: TOptions['resolvedOptions'];
1031
+ type OperationsProps<TOptions$1 extends PluginFactoryOptions> = {
1032
+ instance: Omit<OperationGenerator<TOptions$1>, 'build'>;
1033
+ options: TOptions$1['resolvedOptions'];
1078
1034
  operations: Array<Operation$1>;
1079
1035
  };
1080
- type OperationProps<TOptions extends PluginFactoryOptions> = {
1081
- instance: Omit<OperationGenerator<TOptions>, 'build'>;
1082
- options: TOptions['resolvedOptions'];
1036
+ type OperationProps<TOptions$1 extends PluginFactoryOptions> = {
1037
+ instance: Omit<OperationGenerator<TOptions$1>, 'build'>;
1038
+ options: TOptions$1['resolvedOptions'];
1083
1039
  operation: Operation$1;
1084
1040
  };
1085
- type SchemaProps<TOptions extends PluginFactoryOptions> = {
1086
- instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
1087
- options: TOptions['resolvedOptions'];
1041
+ type SchemaProps<TOptions$1 extends PluginFactoryOptions> = {
1042
+ instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions$1>, 'build'>;
1043
+ options: TOptions$1['resolvedOptions'];
1088
1044
  schema: {
1089
1045
  name: string;
1090
1046
  tree: Array<Schema>;
1091
1047
  value: SchemaObject$1;
1092
1048
  };
1093
1049
  };
1094
- type GeneratorOptions<TOptions extends PluginFactoryOptions> = {
1050
+ type GeneratorOptions<TOptions$1 extends PluginFactoryOptions> = {
1095
1051
  name: string;
1096
- operations?: (this: GeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => Promise<File[]>;
1097
- operation?: (this: GeneratorOptions<TOptions>, props: OperationProps<TOptions>) => Promise<File[]>;
1098
- schema?: (this: GeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => Promise<File[]>;
1052
+ operations?: (this: GeneratorOptions<TOptions$1>, props: OperationsProps<TOptions$1>) => Promise<File[]>;
1053
+ operation?: (this: GeneratorOptions<TOptions$1>, props: OperationProps<TOptions$1>) => Promise<File[]>;
1054
+ schema?: (this: GeneratorOptions<TOptions$1>, props: SchemaProps<TOptions$1>) => Promise<File[]>;
1099
1055
  };
1100
- type Generator<TOptions extends PluginFactoryOptions> = GeneratorOptions<TOptions>;
1056
+ type Generator<TOptions$1 extends PluginFactoryOptions> = GeneratorOptions<TOptions$1>;
1101
1057
  //#endregion
1102
1058
  //#region ../plugin-oas/src/OperationGenerator.d.ts
1103
- type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
1059
+ type Context<TOptions$1, TPluginOptions extends PluginFactoryOptions> = {
1104
1060
  oas: Oas;
1105
1061
  exclude: Array<Exclude$1> | undefined;
1106
1062
  include: Array<Include> | undefined;
1107
- override: Array<Override<TOptions>> | undefined;
1063
+ override: Array<Override<TOptions$1>> | undefined;
1108
1064
  contentType: contentType | undefined;
1109
1065
  pluginManager: PluginManager;
1110
1066
  /**
@@ -1231,5 +1187,5 @@ type ResolvedOptions = {
1231
1187
  };
1232
1188
  type PluginFaker = PluginFactoryOptions<'plugin-faker', Options$1, ResolvedOptions, never, ResolvePathOptions>;
1233
1189
  //#endregion
1234
- export { Generator, Options$1 as Options, PluginFaker, Schema, UserPluginWithLifeCycle };
1235
- //# sourceMappingURL=types-DsDfBfOk.d.ts.map
1190
+ export { UserPluginWithLifeCycle as a, Schema as i, PluginFaker as n, Generator as r, Options$1 as t };
1191
+ //# sourceMappingURL=types-CE8sVPcD.d.ts.map