@kubb/plugin-zod 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.
@@ -5,6 +5,7 @@ import { OpenAPIV3 } from "openapi-types";
5
5
  import * as oas_normalize_lib_types0 from "oas-normalize/lib/types";
6
6
  import BaseOas from "oas";
7
7
  import { ConsolaInstance, LogLevel } from "consola";
8
+ import { FileManager } from "@kubb/fabric-core";
8
9
 
9
10
  //#region ../oas/src/types.d.ts
10
11
  type contentType = 'application/json' | (string & {});
@@ -46,17 +47,17 @@ declare class Oas<const TOAS = unknown> extends BaseOas {
46
47
  * Abstract class that contains the building blocks for plugins to create their own Generator
47
48
  * @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
48
49
  */
49
- declare abstract class BaseGenerator<TOptions = unknown, TContext = unknown> {
50
+ declare abstract class BaseGenerator<TOptions$1 = unknown, TContext = unknown> {
50
51
  #private;
51
- constructor(options?: TOptions, context?: TContext);
52
- get options(): TOptions;
52
+ constructor(options?: TOptions$1, context?: TContext);
53
+ get options(): TOptions$1;
53
54
  get context(): TContext;
54
- set options(options: TOptions);
55
+ set options(options: TOptions$1);
55
56
  abstract build(...params: unknown[]): unknown;
56
57
  }
57
58
  //#endregion
58
59
  //#region ../core/src/fs/types.d.ts
59
- type BasePath<T extends string = string> = `${T}/`;
60
+ type BasePath<T$1 extends string = string> = `${T$1}/`;
60
61
  type Import = {
61
62
  /**
62
63
  * Import name to be used
@@ -130,7 +131,7 @@ type BaseName = `${string}.${string}`;
130
131
  * Path will be full qualified path to a specified file
131
132
  */
132
133
  type Path = string;
133
- type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
134
+ type AdvancedPath<T$1 extends BaseName = BaseName> = `${BasePath}${T$1}`;
134
135
  type OptionalPath = Path | undefined | null;
135
136
  type File<TMeta extends object = object> = {
136
137
  /**
@@ -219,9 +220,7 @@ type Logger = {
219
220
  };
220
221
  //#endregion
221
222
  //#region ../core/src/utils/types.d.ts
222
- type PossiblePromise<T> = Promise<T> | T;
223
- type ArrayWithLength<T extends number, U extends any[] = []> = U['length'] extends T ? U : ArrayWithLength<T, [true, ...U]>;
224
- type GreaterThan<T extends number, U extends number> = ArrayWithLength<U> extends [...ArrayWithLength<T>, ...infer _] ? false : true;
223
+ type PossiblePromise<T$1> = Promise<T$1> | T$1;
225
224
  //#endregion
226
225
  //#region ../core/src/types.d.ts
227
226
  type InputPath = {
@@ -334,11 +333,11 @@ TName extends string = string,
334
333
  /**
335
334
  * Options of the plugin.
336
335
  */
337
- TOptions extends object = object,
336
+ TOptions$1 extends object = object,
338
337
  /**
339
338
  * Options of the plugin that can be used later on, see `options` inside your plugin config.
340
339
  */
341
- TResolvedOptions extends object = TOptions,
340
+ TResolvedOptions extends object = TOptions$1,
342
341
  /**
343
342
  * Context that you want to expose to other plugins.
344
343
  */
@@ -352,23 +351,23 @@ TResolvePathOptions extends object = object> = {
352
351
  * Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
353
352
  */
354
353
  key: PluginKey<TName | string>;
355
- options: TOptions;
354
+ options: TOptions$1;
356
355
  resolvedOptions: TResolvedOptions;
357
356
  context: TContext;
358
357
  resolvePathOptions: TResolvePathOptions;
359
358
  };
360
359
  type PluginKey<TName> = [name: TName, identifier?: string | number];
361
- type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
360
+ type UserPlugin<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
362
361
  /**
363
362
  * Unique name used for the plugin
364
363
  * The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
365
364
  * @example @kubb/typescript
366
365
  */
367
- name: TOptions['name'];
366
+ name: TOptions$1['name'];
368
367
  /**
369
368
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
370
369
  */
371
- options: TOptions['resolvedOptions'];
370
+ options: TOptions$1['resolvedOptions'];
372
371
  /**
373
372
  * 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.
374
373
  * Can be used to validate dependent plugins.
@@ -378,23 +377,23 @@ type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
378
377
  * 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.
379
378
  */
380
379
  post?: Array<string>;
381
- } & (TOptions['context'] extends never ? {
380
+ } & (TOptions$1['context'] extends never ? {
382
381
  context?: never;
383
382
  } : {
384
- context: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['context'];
383
+ context: (this: TOptions$1['name'] extends 'core' ? null : Omit<PluginContext<TOptions$1>, 'addFile'>) => TOptions$1['context'];
385
384
  });
386
- type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
387
- type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
385
+ type UserPluginWithLifeCycle<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions$1> & PluginLifecycle<TOptions$1>;
386
+ type Plugin<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
388
387
  /**
389
388
  * Unique name used for the plugin
390
389
  * @example @kubb/typescript
391
390
  */
392
- name: TOptions['name'];
391
+ name: TOptions$1['name'];
393
392
  /**
394
393
  * Internal key used when a developer uses more than one of the same plugin
395
394
  * @private
396
395
  */
397
- key: TOptions['key'];
396
+ key: TOptions$1['key'];
398
397
  /**
399
398
  * 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.
400
399
  * Can be used to validate dependent plugins.
@@ -407,49 +406,49 @@ type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
407
406
  /**
408
407
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
409
408
  */
410
- options: TOptions['resolvedOptions'];
411
- } & (TOptions['context'] extends never ? {
409
+ options: TOptions$1['resolvedOptions'];
410
+ } & (TOptions$1['context'] extends never ? {
412
411
  context?: never;
413
412
  } : {
414
- context: TOptions['context'];
413
+ context: TOptions$1['context'];
415
414
  });
416
- type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
417
- type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
415
+ type PluginWithLifeCycle<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions$1> & PluginLifecycle<TOptions$1>;
416
+ type PluginLifecycle<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
418
417
  /**
419
418
  * Start of the lifecycle of a plugin.
420
419
  * @type hookParallel
421
420
  */
422
- buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
421
+ buildStart?: (this: PluginContext<TOptions$1>, Config: Config) => PossiblePromise<void>;
423
422
  /**
424
423
  * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
425
424
  * Options can als be included.
426
425
  * @type hookFirst
427
426
  * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
428
427
  */
429
- resolvePath?: (this: PluginContext<TOptions>, baseName: BaseName, mode?: Mode, options?: TOptions['resolvePathOptions']) => OptionalPath;
428
+ resolvePath?: (this: PluginContext<TOptions$1>, baseName: BaseName, mode?: Mode, options?: TOptions$1['resolvePathOptions']) => OptionalPath;
430
429
  /**
431
430
  * Resolve to a name based on a string.
432
431
  * Useful when converting to PascalCase or camelCase.
433
432
  * @type hookFirst
434
433
  * @example ('pet') => 'Pet'
435
434
  */
436
- resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
435
+ resolveName?: (this: PluginContext<TOptions$1>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
437
436
  /**
438
437
  * End of the plugin lifecycle.
439
438
  * @type hookParallel
440
439
  */
441
- buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
440
+ buildEnd?: (this: PluginContext<TOptions$1>) => PossiblePromise<void>;
442
441
  };
443
442
  type PluginLifecycleHooks = keyof PluginLifecycle;
444
- type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
445
- type ResolvePathParams<TOptions = object> = {
443
+ type PluginParameter<H$1 extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H$1]>;
444
+ type ResolvePathParams<TOptions$1 = object> = {
446
445
  pluginKey?: Plugin['key'];
447
446
  baseName: BaseName;
448
447
  mode?: Mode;
449
448
  /**
450
449
  * Options to be passed to 'resolvePath' 3th parameter
451
450
  */
452
- options?: TOptions;
451
+ options?: TOptions$1;
453
452
  };
454
453
  type ResolveNameParams = {
455
454
  name: string;
@@ -462,12 +461,15 @@ type ResolveNameParams = {
462
461
  */
463
462
  type?: 'file' | 'function' | 'type' | 'const';
464
463
  };
465
- type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
464
+ type PluginContext<TOptions$1 extends PluginFactoryOptions = PluginFactoryOptions> = {
466
465
  config: Config;
466
+ /**
467
+ * @deprecated
468
+ */
467
469
  fileManager: FileManager;
468
470
  pluginManager: PluginManager;
469
471
  addFile: (...file: Array<File>) => Promise<Array<ResolvedFile>>;
470
- resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => OptionalPath;
472
+ resolvePath: (params: ResolvePathParams<TOptions$1['resolvePathOptions']>) => OptionalPath;
471
473
  resolveName: (params: ResolveNameParams) => string;
472
474
  logger: Logger;
473
475
  /**
@@ -477,12 +479,12 @@ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions>
477
479
  /**
478
480
  * Current plugin
479
481
  */
480
- plugin: Plugin<TOptions>;
482
+ plugin: Plugin<TOptions$1>;
481
483
  };
482
484
  /**
483
485
  * Specify the export location for the files and define the behavior of the output
484
486
  */
485
- type Output<TOptions> = {
487
+ type Output<TOptions$1> = {
486
488
  /**
487
489
  * Path to the output folder or file that will contain the generated code
488
490
  */
@@ -495,11 +497,11 @@ type Output<TOptions> = {
495
497
  /**
496
498
  * Add a banner text in the beginning of every file
497
499
  */
498
- banner?: string | ((options: TOptions) => string);
500
+ banner?: string | ((options: TOptions$1) => string);
499
501
  /**
500
502
  * Add a footer text in the beginning of every file
501
503
  */
502
- footer?: string | ((options: TOptions) => string);
504
+ footer?: string | ((options: TOptions$1) => string);
503
505
  };
504
506
  type GroupContext = {
505
507
  group: string;
@@ -515,73 +517,19 @@ type Group = {
515
517
  name?: (context: GroupContext) => string;
516
518
  };
517
519
  //#endregion
518
- //#region ../core/src/FileManager.d.ts
519
- type FileMetaBase = {
520
- pluginKey?: Plugin['key'];
521
- };
522
- type AddResult<T extends Array<File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<ResolvedFile[]> : Promise<ResolvedFile>>>;
523
- type AddIndexesProps = {
524
- type: BarrelType | false | undefined;
525
- /**
526
- * Root based on root and output.path specified in the config
527
- */
528
- root: string;
529
- /**
530
- * Output for plugin
531
- */
532
- output: {
533
- path: string;
534
- };
535
- group?: {
536
- output: string;
537
- exportAs: string;
538
- };
539
- logger?: Logger;
540
- meta?: FileMetaBase;
541
- };
542
- type WriteFilesProps = {
543
- root: Config['root'];
544
- extension?: Record<Extname, Extname | ''>;
545
- logger?: Logger;
546
- dryRun?: boolean;
547
- };
548
- declare class FileManager {
549
- #private;
550
- constructor();
551
- add<T extends Array<File> = Array<File>>(...files: T): AddResult<T>;
552
- getByPath(path: Path): Promise<ResolvedFile | null>;
553
- deleteByPath(path: Path): Promise<void>;
554
- clear(): Promise<void>;
555
- getFiles(): Promise<Array<ResolvedFile>>;
556
- processFiles({
557
- dryRun,
558
- root,
559
- extension,
560
- logger
561
- }: WriteFilesProps): Promise<Array<ResolvedFile>>;
562
- getBarrelFiles({
563
- type,
564
- meta,
565
- root,
566
- output,
567
- logger
568
- }: AddIndexesProps): Promise<File[]>;
569
- static getMode(path: string | undefined | null): Mode;
570
- }
571
- //#endregion
572
520
  //#region ../core/src/PluginManager.d.ts
573
521
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
574
522
  type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookSeq';
575
- type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
523
+ type Executer<H$1 extends PluginLifecycleHooks = PluginLifecycleHooks> = {
576
524
  message: string;
577
525
  strategy: Strategy;
578
- hookName: H;
526
+ hookName: H$1;
579
527
  plugin: Plugin;
580
528
  parameters?: unknown[] | undefined;
581
529
  output?: unknown;
582
530
  };
583
- type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
584
- type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
531
+ type ParseResult<H$1 extends PluginLifecycleHooks> = RequiredPluginLifecycle[H$1];
532
+ type SafeParseResult<H$1 extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H$1>>> = {
585
533
  result: Result;
586
534
  plugin: Plugin;
587
535
  };
@@ -597,16 +545,19 @@ type Events = {
597
545
  executed: [executer: Executer];
598
546
  error: [error: Error];
599
547
  };
600
- type GetFileProps<TOptions = object> = {
548
+ type GetFileProps<TOptions$1 = object> = {
601
549
  name: string;
602
550
  mode?: Mode;
603
551
  extname: Extname;
604
552
  pluginKey: Plugin['key'];
605
- options?: TOptions;
553
+ options?: TOptions$1;
606
554
  };
607
555
  declare class PluginManager {
608
556
  #private;
609
557
  readonly plugins: Set<Plugin<PluginFactoryOptions<string, object, object, any, object>>>;
558
+ /**
559
+ * @deprecated do not use from pluginManager
560
+ */
610
561
  readonly fileManager: FileManager;
611
562
  readonly events: EventEmitter<Events>;
612
563
  readonly config: Config;
@@ -715,12 +666,17 @@ declare class PluginManager {
715
666
  static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "buildEnd"];
716
667
  }
717
668
  //#endregion
669
+ //#region ../core/src/FileManager.d.ts
670
+ type FileMetaBase = {
671
+ pluginKey?: Plugin['key'];
672
+ };
673
+ //#endregion
718
674
  //#region ../plugin-oas/src/OperationGenerator.d.ts
719
- type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
675
+ type Context$1<TOptions$1, TPluginOptions extends PluginFactoryOptions> = {
720
676
  oas: Oas;
721
677
  exclude: Array<Exclude$1> | undefined;
722
678
  include: Array<Include> | undefined;
723
- override: Array<Override<TOptions>> | undefined;
679
+ override: Array<Override<TOptions$1>> | undefined;
724
680
  contentType: contentType | undefined;
725
681
  pluginManager: PluginManager;
726
682
  /**
@@ -954,7 +910,7 @@ type Schema = {
954
910
  } | SchemaKeywordMapper[keyof SchemaKeywordMapper];
955
911
  //#endregion
956
912
  //#region ../plugin-oas/src/SchemaGenerator.d.ts
957
- type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
913
+ type Context<TOptions$1, TPluginOptions extends PluginFactoryOptions> = {
958
914
  oas: Oas;
959
915
  pluginManager: PluginManager;
960
916
  /**
@@ -963,7 +919,7 @@ type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
963
919
  plugin: Plugin<TPluginOptions>;
964
920
  mode: Mode;
965
921
  include?: Array<'schemas' | 'responses' | 'requestBodies'>;
966
- override: Array<Override<TOptions>> | undefined;
922
+ override: Array<Override<TOptions$1>> | undefined;
967
923
  contentType?: contentType;
968
924
  output?: string;
969
925
  };
@@ -994,7 +950,7 @@ type SchemaProps$1 = {
994
950
  name?: string;
995
951
  parentName?: string;
996
952
  };
997
- declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions, Context<TOptions, TPluginOptions>> {
953
+ declare class SchemaGenerator<TOptions$1 extends SchemaGeneratorOptions = SchemaGeneratorOptions, TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions, TFileMeta extends FileMetaBase = FileMetaBase> extends BaseGenerator<TOptions$1, Context<TOptions$1, TPluginOptions>> {
998
954
  #private;
999
955
  refs: Refs;
1000
956
  /**
@@ -1013,32 +969,32 @@ declare class SchemaGenerator<TOptions extends SchemaGeneratorOptions = SchemaGe
1013
969
  }
1014
970
  //#endregion
1015
971
  //#region ../plugin-oas/src/generator.d.ts
1016
- type OperationsProps<TOptions extends PluginFactoryOptions> = {
1017
- instance: Omit<OperationGenerator<TOptions>, 'build'>;
1018
- options: TOptions['resolvedOptions'];
972
+ type OperationsProps<TOptions$1 extends PluginFactoryOptions> = {
973
+ instance: Omit<OperationGenerator<TOptions$1>, 'build'>;
974
+ options: TOptions$1['resolvedOptions'];
1019
975
  operations: Array<Operation$1>;
1020
976
  };
1021
- type OperationProps<TOptions extends PluginFactoryOptions> = {
1022
- instance: Omit<OperationGenerator<TOptions>, 'build'>;
1023
- options: TOptions['resolvedOptions'];
977
+ type OperationProps<TOptions$1 extends PluginFactoryOptions> = {
978
+ instance: Omit<OperationGenerator<TOptions$1>, 'build'>;
979
+ options: TOptions$1['resolvedOptions'];
1024
980
  operation: Operation$1;
1025
981
  };
1026
- type SchemaProps<TOptions extends PluginFactoryOptions> = {
1027
- instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>;
1028
- options: TOptions['resolvedOptions'];
982
+ type SchemaProps<TOptions$1 extends PluginFactoryOptions> = {
983
+ instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions$1>, 'build'>;
984
+ options: TOptions$1['resolvedOptions'];
1029
985
  schema: {
1030
986
  name: string;
1031
987
  tree: Array<Schema>;
1032
988
  value: SchemaObject$1;
1033
989
  };
1034
990
  };
1035
- type GeneratorOptions<TOptions extends PluginFactoryOptions> = {
991
+ type GeneratorOptions<TOptions$1 extends PluginFactoryOptions> = {
1036
992
  name: string;
1037
- operations?: (this: GeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => Promise<File[]>;
1038
- operation?: (this: GeneratorOptions<TOptions>, props: OperationProps<TOptions>) => Promise<File[]>;
1039
- schema?: (this: GeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => Promise<File[]>;
993
+ operations?: (this: GeneratorOptions<TOptions$1>, props: OperationsProps<TOptions$1>) => Promise<File[]>;
994
+ operation?: (this: GeneratorOptions<TOptions$1>, props: OperationProps<TOptions$1>) => Promise<File[]>;
995
+ schema?: (this: GeneratorOptions<TOptions$1>, props: SchemaProps<TOptions$1>) => Promise<File[]>;
1040
996
  };
1041
- type Generator<TOptions extends PluginFactoryOptions> = GeneratorOptions<TOptions>;
997
+ type Generator<TOptions$1 extends PluginFactoryOptions> = GeneratorOptions<TOptions$1>;
1042
998
  //#endregion
1043
999
  //#region ../plugin-oas/src/types.d.ts
1044
1000
  type ResolvePathOptions = {
@@ -1124,8 +1080,8 @@ type ByContentType = {
1124
1080
  };
1125
1081
  type Exclude$1 = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
1126
1082
  type Include = ByTag | ByOperationId | ByPath | ByMethod | ByContentType;
1127
- type Override<TOptions> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
1128
- options: Partial<TOptions>;
1083
+ type Override<TOptions$1> = (ByTag | ByOperationId | ByPath | ByMethod | BySchemaName | ByContentType) & {
1084
+ options: Partial<TOptions$1>;
1129
1085
  };
1130
1086
  //#endregion
1131
1087
  //#region src/types.d.ts
@@ -1254,5 +1210,5 @@ type ResolvedOptions = {
1254
1210
  };
1255
1211
  type PluginZod = PluginFactoryOptions<'plugin-zod', Options$1, ResolvedOptions, never, ResolvePathOptions>;
1256
1212
  //#endregion
1257
- export { Generator, type Operation$1 as Operation, Options$1 as Options, PluginZod, Schema, SchemaObject$1 as SchemaObject, UserPluginWithLifeCycle };
1258
- //# sourceMappingURL=types-C4zDVwZ4.d.cts.map
1213
+ export { UserPluginWithLifeCycle as a, Schema as i, PluginZod as n, Operation$1 as o, Generator as r, SchemaObject$1 as s, Options$1 as t };
1214
+ //# sourceMappingURL=types-vzmWp6Js.d.cts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-zod",
3
- "version": "4.1.4",
3
+ "version": "4.2.1",
4
4
  "description": "Zod schema generator plugin for Kubb, creating type-safe validation schemas from OpenAPI specifications for runtime data validation.",
5
5
  "keywords": [
6
6
  "zod",
@@ -69,19 +69,18 @@
69
69
  "!/**/__tests__/**"
70
70
  ],
71
71
  "dependencies": {
72
- "@kubb/core": "4.1.4",
73
- "@kubb/plugin-oas": "4.1.4",
74
- "@kubb/plugin-ts": "4.1.4",
75
- "@kubb/parser-ts": "4.1.4",
76
- "@kubb/react": "4.1.4",
77
- "@kubb/oas": "4.1.4"
72
+ "@kubb/core": "4.2.1",
73
+ "@kubb/oas": "4.2.1",
74
+ "@kubb/plugin-oas": "4.2.1",
75
+ "@kubb/plugin-ts": "4.2.1",
76
+ "@kubb/react": "4.2.1"
78
77
  },
79
78
  "devDependencies": {
80
- "@asteasolutions/zod-to-openapi": "^7.3.4",
79
+ "@asteasolutions/zod-to-openapi": "^8.1.0",
81
80
  "@hono/zod-openapi": "0.19.2",
82
- "tsdown": "^0.14.2",
81
+ "tsdown": "^0.15.9",
83
82
  "zod": "^3.25.76",
84
- "@kubb/plugin-oas": "4.1.4"
83
+ "@kubb/plugin-oas": "4.2.1"
85
84
  },
86
85
  "peerDependencies": {
87
86
  "@kubb/react": "^4.0.0"
@@ -1,20 +1,20 @@
1
+ import { usePlugin, usePluginManager } from '@kubb/core/hooks'
1
2
  import { createReactGenerator } from '@kubb/plugin-oas'
2
3
  import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
3
4
  import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
4
- import { File, useApp } from '@kubb/react'
5
- import { Operations } from '../components/Operations'
5
+ import { File } from '@kubb/react'
6
+ import { Operations } from '../components/Operations.tsx'
6
7
  import type { PluginZod } from '../types'
7
8
 
8
9
  export const operationsGenerator = createReactGenerator<PluginZod>({
9
10
  name: 'operations',
10
11
  Operations({ operations }) {
11
12
  const {
12
- pluginManager,
13
- plugin: {
14
- key: pluginKey,
15
- options: { output, importPath },
16
- },
17
- } = useApp<PluginZod>()
13
+ key: pluginKey,
14
+ options: { output, importPath },
15
+ } = usePlugin<PluginZod>()
16
+ const pluginManager = usePluginManager()
17
+
18
18
  const oas = useOas()
19
19
  const { getFile, groupSchemasByName } = useOperationManager()
20
20
 
@@ -1,9 +1,10 @@
1
+ import { useMode, usePlugin, usePluginManager } from '@kubb/core/hooks'
1
2
  import { createReactGenerator, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'
2
3
  import { Oas } from '@kubb/plugin-oas/components'
3
4
  import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'
4
5
  import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
5
6
  import { pluginTsName } from '@kubb/plugin-ts'
6
- import { File, useApp } from '@kubb/react'
7
+ import { File } from '@kubb/react'
7
8
  import { Zod } from '../components'
8
9
  import type { PluginZod } from '../types'
9
10
 
@@ -12,7 +13,10 @@ export const zodGenerator = createReactGenerator<PluginZod>({
12
13
  Operation({ operation, options }) {
13
14
  const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options
14
15
 
15
- const { plugin, pluginManager, mode } = useApp<PluginZod>()
16
+ const plugin = usePlugin<PluginZod>()
17
+ const mode = useMode()
18
+ const pluginManager = usePluginManager()
19
+
16
20
  const oas = useOas()
17
21
  const { getSchemas, getFile, getGroup } = useOperationManager()
18
22
  const schemaManager = useSchemaManager()
@@ -103,11 +107,9 @@ export const zodGenerator = createReactGenerator<PluginZod>({
103
107
 
104
108
  const { getName, getFile, getImports } = useSchemaManager()
105
109
  const {
106
- pluginManager,
107
- plugin: {
108
- options: { output, emptySchemaType },
109
- },
110
- } = useApp<PluginZod>()
110
+ options: { output, emptySchemaType },
111
+ } = usePlugin<PluginZod>()
112
+ const pluginManager = usePluginManager()
111
113
  const oas = useOas()
112
114
 
113
115
  const imports = getImports(schema.tree)
package/src/plugin.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import path from 'node:path'
2
- import { createPlugin, FileManager, type Group, PackageManager, type Plugin, PluginManager } from '@kubb/core'
2
+ import { createPlugin, type Group, getBarrelFiles, getMode, PackageManager, type Plugin, PluginManager } from '@kubb/core'
3
3
  import { camelCase, pascalCase } from '@kubb/core/transformers'
4
4
  import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
5
5
  import { OperationGenerator, pluginOasName, SchemaGenerator } from '@kubb/plugin-oas'
@@ -57,7 +57,7 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
57
57
  pre: [pluginOasName, typed ? pluginTsName : undefined].filter(Boolean),
58
58
  resolvePath(baseName, pathMode, options) {
59
59
  const root = path.resolve(this.config.root, this.config.output.path)
60
- const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
60
+ const mode = pathMode ?? getMode(path.resolve(root, output.path))
61
61
 
62
62
  if (mode === 'single') {
63
63
  /**
@@ -110,7 +110,7 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
110
110
 
111
111
  const oas = await swaggerPlugin.context.getOas()
112
112
  const root = path.resolve(this.config.root, this.config.output.path)
113
- const mode = FileManager.getMode(path.resolve(root, output.path))
113
+ const mode = getMode(path.resolve(root, output.path))
114
114
 
115
115
  const schemaGenerator = new SchemaGenerator(this.plugin.options, {
116
116
  oas,
@@ -140,7 +140,7 @@ export const pluginZod = createPlugin<PluginZod>((options) => {
140
140
  const operationFiles = await operationGenerator.build(...generators)
141
141
  await this.addFile(...operationFiles)
142
142
 
143
- const barrelFiles = await this.fileManager.getBarrelFiles({
143
+ const barrelFiles = await getBarrelFiles(this.fileManager.files, {
144
144
  type: output.barrelType ?? 'named',
145
145
  root,
146
146
  output,
@@ -1 +0,0 @@
1
- {"version":3,"file":"generators-D7INxuXC.cjs","names":["SchemaGenerator","options","schemaKeywords","pluginTsName","Oas","File","Zod","File","Operations"],"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"sourcesContent":["import { createReactGenerator, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options }) {\n const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required\n const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, 'default') && property.default !== undefined)\n const optional = !required && !someDefaults && name.includes('Params')\n\n const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const coercion = name.includes('Params') ? { numbers: true, strings: false, dates: true } : globalCoercion\n\n const zod = {\n name: schemaManager.getName(name, { type: 'function' }),\n inferTypeName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, {\n type: 'type',\n pluginKey: [pluginTsName],\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginKey: [pluginTsName],\n group,\n }),\n }\n\n return (\n <Oas.Schema key={i} name={name} schemaObject={schemaObject} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && plugin.options.version === '3' && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={description}\n tree={tree}\n rawSchema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n version={plugin.options.version}\n emptySchemaType={plugin.options.emptySchemaType}\n />\n </Oas.Schema>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n pluginManager,\n plugin: {\n options: { output, emptySchemaType },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File\n baseName={zod.file.baseName}\n path={zod.file.path}\n meta={zod.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={options.version === '4' ? '@kubb/plugin-zod/utils/v4' : '@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n rawSchema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n version={version}\n emptySchemaType={emptySchemaType}\n />\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { output, importPath },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import isTypeOnly name={['z']} path={importPath} />\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;AASA,MAAa,2DAA+C;CAC1D,MAAM;CACN,UAAU,EAAE,WAAW,WAAW;EAChC,MAAM,EAAE,UAAU,gBAAgB,UAAU,OAAO,QAAQ,eAAe;EAE1E,MAAM,EAAE,QAAQ,eAAe,mCAA4B;EAC3D,MAAM,2CAAc;EACpB,MAAM,EAAE,YAAY,SAAS,+DAAkC;EAC/D,MAAM,+DAAkC;EAExC,MAAM,OAAO,QAAQ,UAAU;EAC/B,MAAM,UAAU,WAAW,UAAU;EACrC,MAAM,kBAAkB,IAAIA,kCAAgB,SAAS;GACnD;GACA;GACA;GACA;GACA,UAAU,QAAQ;GACnB,CAAC;EAEF,MAAM,mBAAmB;GAAC,QAAQ;GAAY,QAAQ;GAAa,QAAQ;GAAc,QAAQ;GAAa,QAAQ;GAAS,QAAQ;GAAS,CAC7I,MAAM,CACN,OAAO,QAAQ;EAElB,MAAM,sBAAsB,EAAE,MAAM,QAAQ,cAAc,aAAa,WAAY,GAAGC,aAAgC,MAAc;GAElI,MAAM,WAAW,MAAM,QAAQ,cAAc,SAAS,GAAG,CAAC,CAAC,aAAa,SAAS,SAAS,CAAC,CAAC,cAAc;GAC1G,MAAM,eAAe,OAAO,OAAO,aAAa,cAAc,EAAE,CAAC,CAAC,MAAM,aAAa,OAAO,OAAO,UAAU,UAAU,IAAI,SAAS,YAAY,OAAU;GAC1J,MAAM,WAAW,CAAC,YAAY,CAAC,gBAAgB,KAAK,SAAS,SAAS;GAEtE,MAAM,OAAO,CAAC,GAAG,gBAAgB,MAAM;IAAE;IAAc;IAAM,CAAC,EAAE,WAAW,EAAE,SAASC,iCAAe,UAAU,GAAG,OAAU,CAAC,OAAO,QAAQ;GAC5I,MAAM,UAAU,cAAc,W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,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,+CAAkB;IAAE;IAAK;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GAChE,+CAAkB;IAAE;IAAK;IAAQ,CAAC;;IAElC,kDAACA,kBAAK;KAAO;KAAW,MAAM,CAAC,IAAI;KAAE,MAAM;MAAc;IACxD;IACD,kDAACC;KAAiB;KAAM,YAAY;MAAyB;;IACxD;;CAGZ,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"generators-DJH-fpYZ.js","names":["options"],"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"sourcesContent":["import { createReactGenerator, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options }) {\n const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required\n const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, 'default') && property.default !== undefined)\n const optional = !required && !someDefaults && name.includes('Params')\n\n const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const coercion = name.includes('Params') ? { numbers: true, strings: false, dates: true } : globalCoercion\n\n const zod = {\n name: schemaManager.getName(name, { type: 'function' }),\n inferTypeName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, {\n type: 'type',\n pluginKey: [pluginTsName],\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginKey: [pluginTsName],\n group,\n }),\n }\n\n return (\n <Oas.Schema key={i} name={name} schemaObject={schemaObject} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && plugin.options.version === '3' && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={description}\n tree={tree}\n rawSchema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n version={plugin.options.version}\n emptySchemaType={plugin.options.emptySchemaType}\n />\n </Oas.Schema>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n pluginManager,\n plugin: {\n options: { output, emptySchemaType },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File\n baseName={zod.file.baseName}\n path={zod.file.path}\n meta={zod.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={options.version === '4' ? '@kubb/plugin-zod/utils/v4' : '@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n rawSchema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n version={version}\n emptySchemaType={emptySchemaType}\n />\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { output, importPath },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import isTypeOnly name={['z']} path={importPath} />\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;AASA,MAAa,eAAe,qBAAgC;CAC1D,MAAM;CACN,UAAU,EAAE,WAAW,WAAW;EAChC,MAAM,EAAE,UAAU,gBAAgB,UAAU,OAAO,QAAQ,eAAe;EAE1E,MAAM,EAAE,QAAQ,eAAe,SAAS,QAAmB;EAC3D,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,YAAY,SAAS,aAAa,qBAAqB;EAC/D,MAAM,gBAAgB,kBAAkB;EAExC,MAAM,OAAO,QAAQ,UAAU;EAC/B,MAAM,UAAU,WAAW,UAAU;EACrC,MAAM,kBAAkB,IAAI,gBAAgB,SAAS;GACnD;GACA;GACA;GACA;GACA,UAAU,QAAQ;GACnB,CAAC;EAEF,MAAM,mBAAmB;GAAC,QAAQ;GAAY,QAAQ;GAAa,QAAQ;GAAc,QAAQ;GAAa,QAAQ;GAAS,QAAQ;GAAS,CAC7I,MAAM,CACN,OAAO,QAAQ;EAElB,MAAM,sBAAsB,EAAE,MAAM,QAAQ,cAAc,aAAa,WAAY,GAAGA,aAAgC,MAAc;GAElI,MAAM,WAAW,MAAM,QAAQ,cAAc,SAAS,GAAG,CAAC,CAAC,aAAa,SAAS,S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