@kubb/core 2.0.0-beta.10 → 2.0.0-beta.11

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/index.d.cts CHANGED
@@ -1,10 +1,10 @@
1
+ import { w as write, r as read } from './write-46ytbnu9.cjs';
1
2
  import { PossiblePromise, GreaterThan, TupleToUnion, ObjValueTuple } from '@kubb/types';
2
3
  import { DirectoryTreeOptions } from 'directory-tree';
3
- import { Ora } from 'ora';
4
-
5
- declare function read(path: string): Promise<string>;
6
-
7
- declare function write(data: string, path: string): Promise<string | undefined>;
4
+ import { E as EventEmitter, Q as Queue, a as QueueJob } from './Queue-2-6pMcCx.cjs';
5
+ import { Logger, LogLevel } from './logger.cjs';
6
+ import 'ora';
7
+ import 'picocolors';
8
8
 
9
9
  type BarrelManagerOptions = {
10
10
  treeNode?: DirectoryTreeOptions;
@@ -15,57 +15,6 @@ type BarrelManagerOptions = {
15
15
  extName?: KubbFile.Extname;
16
16
  };
17
17
 
18
- declare class EventEmitter<TEvents extends Record<string, any>> {
19
- #private;
20
- constructor();
21
- emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
22
- on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
23
- off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
24
- removeAll(): void;
25
- }
26
-
27
- type QueueJob<T = unknown> = {
28
- (...args: unknown[]): Promise<T | void>;
29
- };
30
- type RunOptions = {
31
- controller?: AbortController;
32
- name?: string;
33
- description?: string;
34
- };
35
- type Events$1 = {
36
- jobDone: [result: unknown];
37
- jobFailed: [error: Error];
38
- };
39
- declare class Queue {
40
- #private;
41
- readonly eventEmitter: EventEmitter<Events$1>;
42
- constructor(maxParallel: number, debug?: boolean);
43
- run<T>(job: QueueJob<T>, options?: RunOptions): Promise<T>;
44
- runSync<T>(job: QueueJob<T>, options?: RunOptions): void;
45
- get hasJobs(): boolean;
46
- get count(): number;
47
- }
48
-
49
- declare const LogLevel: {
50
- readonly silent: "silent";
51
- readonly info: "info";
52
- readonly debug: "debug";
53
- };
54
- type LogLevel = keyof typeof LogLevel;
55
- type Logger = {
56
- /**
57
- * Optional config name to show in CLI output
58
- */
59
- name?: string;
60
- logLevel: LogLevel;
61
- log: (message: string | null) => void;
62
- error: (message: string | null) => void;
63
- info: (message: string | null) => void;
64
- warn: (message: string | null) => void;
65
- spinner?: Ora;
66
- logs: string[];
67
- };
68
-
69
18
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
70
19
  /**
71
20
  * Get the type of the first argument in a function.
@@ -105,30 +54,36 @@ declare class PluginManager {
105
54
  #private;
106
55
  readonly plugins: KubbPluginWithLifeCycle[];
107
56
  readonly fileManager: FileManager;
108
- readonly eventEmitter: EventEmitter<Events>;
57
+ readonly events: EventEmitter<Events>;
109
58
  readonly queue: Queue;
110
59
  readonly config: KubbConfig;
111
- readonly executed: Executer[];
60
+ readonly executed: Array<Executer>;
112
61
  readonly logger: Logger;
113
62
  constructor(config: KubbConfig, options: Options$2);
114
63
  resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
115
64
  resolveName: (params: ResolveNameParams) => string;
65
+ /**
66
+ * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
67
+ */
116
68
  on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
117
69
  /**
118
- * Run only hook for a specific plugin name
70
+ * Run a specific hookName for plugin x.
119
71
  */
120
72
  hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
121
73
  pluginKey: KubbPlugin['key'];
122
74
  hookName: H;
123
75
  parameters: PluginParameter<H>;
124
76
  }): Promise<Array<ReturnType<ParseResult<H>> | null>> | null;
77
+ /**
78
+ * Run a specific hookName for plugin x.
79
+ */
125
80
  hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
126
81
  pluginKey: KubbPlugin['key'];
127
82
  hookName: H;
128
83
  parameters: PluginParameter<H>;
129
84
  }): Array<ReturnType<ParseResult<H>>> | null;
130
85
  /**
131
- * Chains, first non-null result stops and returns
86
+ * First non-null result stops and will return it's value.
132
87
  */
133
88
  hookFirst<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
134
89
  hookName: H;
@@ -136,7 +91,7 @@ declare class PluginManager {
136
91
  skipped?: ReadonlySet<KubbPlugin> | null;
137
92
  }): Promise<SafeParseResult<H>>;
138
93
  /**
139
- * Chains, first non-null result stops and returns
94
+ * First non-null result stops and will return it's value.
140
95
  */
141
96
  hookFirstSync<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
142
97
  hookName: H;
@@ -144,14 +99,14 @@ declare class PluginManager {
144
99
  skipped?: ReadonlySet<KubbPlugin> | null;
145
100
  }): SafeParseResult<H>;
146
101
  /**
147
- * Parallel, runs all plugins
102
+ * Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
148
103
  */
149
104
  hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ hookName, parameters, }: {
150
105
  hookName: H;
151
106
  parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
152
107
  }): Promise<Awaited<TOuput>[]>;
153
108
  /**
154
- * Chains, reduces returned value, handling the reduced value as the first hook argument
109
+ * Chain all plugins, `reduce` can be passed through to handle every returned value. The return value of the first plugin will be used as the first parameter for the plugin after that.
155
110
  */
156
111
  hookReduceArg0<H extends PluginLifecycleHooks>({ hookName, parameters, reduce, }: {
157
112
  hookName: H;
@@ -624,13 +579,10 @@ declare class FileManager {
624
579
  write(...params: Parameters<typeof write>): Promise<string | undefined>;
625
580
  read(...params: Parameters<typeof read>): Promise<string>;
626
581
  static getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(file: KubbFile.File<TMeta>): string;
627
- static combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(files: Array<KubbFile.File<TMeta> | null>): Array<KubbFile.File<TMeta>>;
628
582
  static getMode(path: string | undefined | null): KubbFile.Mode;
629
583
  static get extensions(): Array<KubbFile.Extname>;
630
584
  static isExtensionAllowed(baseName: string): boolean;
631
585
  }
632
- declare function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export>;
633
- declare function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import>;
634
586
 
635
587
  type BuildOptions = {
636
588
  config: PluginContext['config'];
@@ -668,8 +620,6 @@ declare class Warning extends Error {
668
620
  cause: Error;
669
621
  });
670
622
  }
671
- declare class ValidationPluginError extends Error {
672
- }
673
623
 
674
624
  /**
675
625
  * Abstract class that contains the building blocks for plugins to create their own Generator
@@ -739,4 +689,4 @@ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
739
689
  type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
740
690
  type Plugin = keyof Plugins;
741
691
 
742
- export { type CLIOptions, FileManager, Generator, type GetPluginFactoryOptions, type InputData, type InputPath, type KubbConfig, KubbFile, type KubbObjectPlugin, type KubbPlugin, type KubbPluginWithLifeCycle, type KubbUnionPlugins, type KubbUserConfig, type KubbUserPlugin, type KubbUserPluginWithLifeCycle, type OptionsOfPlugin, type OptionsPlugins, PackageManager, type Plugin, type PluginCache, type PluginContext, type PluginFactoryOptions, type PluginLifecycle, type PluginLifecycleHooks, PluginManager, type PluginParameter, type PluginUnion, type Plugins, PromiseManager, type ResolveNameParams, type ResolvePathParams, type TransformResult, ValidationPluginError, Warning, type _Register, build, combineExports, combineImports, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
692
+ export { type CLIOptions, FileManager, Generator, type GetPluginFactoryOptions, type InputData, type InputPath, type KubbConfig, KubbFile, type KubbObjectPlugin, type KubbPlugin, type KubbPluginWithLifeCycle, type KubbUnionPlugins, type KubbUserConfig, type KubbUserPlugin, type KubbUserPluginWithLifeCycle, type OptionsOfPlugin, type OptionsPlugins, PackageManager, type Plugin, type PluginCache, type PluginContext, type PluginFactoryOptions, type PluginLifecycle, type PluginLifecycleHooks, PluginManager, type PluginParameter, type PluginUnion, type Plugins, PromiseManager, type ResolveNameParams, type ResolvePathParams, type TransformResult, Warning, type _Register, build, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
+ import { w as write, r as read } from './write-46ytbnu9.js';
1
2
  import { PossiblePromise, GreaterThan, TupleToUnion, ObjValueTuple } from '@kubb/types';
2
3
  import { DirectoryTreeOptions } from 'directory-tree';
3
- import { Ora } from 'ora';
4
-
5
- declare function read(path: string): Promise<string>;
6
-
7
- declare function write(data: string, path: string): Promise<string | undefined>;
4
+ import { E as EventEmitter, Q as Queue, a as QueueJob } from './Queue-2-6pMcCx.js';
5
+ import { Logger, LogLevel } from './logger.js';
6
+ import 'ora';
7
+ import 'picocolors';
8
8
 
9
9
  type BarrelManagerOptions = {
10
10
  treeNode?: DirectoryTreeOptions;
@@ -15,57 +15,6 @@ type BarrelManagerOptions = {
15
15
  extName?: KubbFile.Extname;
16
16
  };
17
17
 
18
- declare class EventEmitter<TEvents extends Record<string, any>> {
19
- #private;
20
- constructor();
21
- emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
22
- on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
23
- off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
24
- removeAll(): void;
25
- }
26
-
27
- type QueueJob<T = unknown> = {
28
- (...args: unknown[]): Promise<T | void>;
29
- };
30
- type RunOptions = {
31
- controller?: AbortController;
32
- name?: string;
33
- description?: string;
34
- };
35
- type Events$1 = {
36
- jobDone: [result: unknown];
37
- jobFailed: [error: Error];
38
- };
39
- declare class Queue {
40
- #private;
41
- readonly eventEmitter: EventEmitter<Events$1>;
42
- constructor(maxParallel: number, debug?: boolean);
43
- run<T>(job: QueueJob<T>, options?: RunOptions): Promise<T>;
44
- runSync<T>(job: QueueJob<T>, options?: RunOptions): void;
45
- get hasJobs(): boolean;
46
- get count(): number;
47
- }
48
-
49
- declare const LogLevel: {
50
- readonly silent: "silent";
51
- readonly info: "info";
52
- readonly debug: "debug";
53
- };
54
- type LogLevel = keyof typeof LogLevel;
55
- type Logger = {
56
- /**
57
- * Optional config name to show in CLI output
58
- */
59
- name?: string;
60
- logLevel: LogLevel;
61
- log: (message: string | null) => void;
62
- error: (message: string | null) => void;
63
- info: (message: string | null) => void;
64
- warn: (message: string | null) => void;
65
- spinner?: Ora;
66
- logs: string[];
67
- };
68
-
69
18
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
70
19
  /**
71
20
  * Get the type of the first argument in a function.
@@ -105,30 +54,36 @@ declare class PluginManager {
105
54
  #private;
106
55
  readonly plugins: KubbPluginWithLifeCycle[];
107
56
  readonly fileManager: FileManager;
108
- readonly eventEmitter: EventEmitter<Events>;
57
+ readonly events: EventEmitter<Events>;
109
58
  readonly queue: Queue;
110
59
  readonly config: KubbConfig;
111
- readonly executed: Executer[];
60
+ readonly executed: Array<Executer>;
112
61
  readonly logger: Logger;
113
62
  constructor(config: KubbConfig, options: Options$2);
114
63
  resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
115
64
  resolveName: (params: ResolveNameParams) => string;
65
+ /**
66
+ * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
67
+ */
116
68
  on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
117
69
  /**
118
- * Run only hook for a specific plugin name
70
+ * Run a specific hookName for plugin x.
119
71
  */
120
72
  hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
121
73
  pluginKey: KubbPlugin['key'];
122
74
  hookName: H;
123
75
  parameters: PluginParameter<H>;
124
76
  }): Promise<Array<ReturnType<ParseResult<H>> | null>> | null;
77
+ /**
78
+ * Run a specific hookName for plugin x.
79
+ */
125
80
  hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
126
81
  pluginKey: KubbPlugin['key'];
127
82
  hookName: H;
128
83
  parameters: PluginParameter<H>;
129
84
  }): Array<ReturnType<ParseResult<H>>> | null;
130
85
  /**
131
- * Chains, first non-null result stops and returns
86
+ * First non-null result stops and will return it's value.
132
87
  */
133
88
  hookFirst<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
134
89
  hookName: H;
@@ -136,7 +91,7 @@ declare class PluginManager {
136
91
  skipped?: ReadonlySet<KubbPlugin> | null;
137
92
  }): Promise<SafeParseResult<H>>;
138
93
  /**
139
- * Chains, first non-null result stops and returns
94
+ * First non-null result stops and will return it's value.
140
95
  */
141
96
  hookFirstSync<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
142
97
  hookName: H;
@@ -144,14 +99,14 @@ declare class PluginManager {
144
99
  skipped?: ReadonlySet<KubbPlugin> | null;
145
100
  }): SafeParseResult<H>;
146
101
  /**
147
- * Parallel, runs all plugins
102
+ * Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
148
103
  */
149
104
  hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ hookName, parameters, }: {
150
105
  hookName: H;
151
106
  parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
152
107
  }): Promise<Awaited<TOuput>[]>;
153
108
  /**
154
- * Chains, reduces returned value, handling the reduced value as the first hook argument
109
+ * Chain all plugins, `reduce` can be passed through to handle every returned value. The return value of the first plugin will be used as the first parameter for the plugin after that.
155
110
  */
156
111
  hookReduceArg0<H extends PluginLifecycleHooks>({ hookName, parameters, reduce, }: {
157
112
  hookName: H;
@@ -624,13 +579,10 @@ declare class FileManager {
624
579
  write(...params: Parameters<typeof write>): Promise<string | undefined>;
625
580
  read(...params: Parameters<typeof read>): Promise<string>;
626
581
  static getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(file: KubbFile.File<TMeta>): string;
627
- static combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(files: Array<KubbFile.File<TMeta> | null>): Array<KubbFile.File<TMeta>>;
628
582
  static getMode(path: string | undefined | null): KubbFile.Mode;
629
583
  static get extensions(): Array<KubbFile.Extname>;
630
584
  static isExtensionAllowed(baseName: string): boolean;
631
585
  }
632
- declare function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export>;
633
- declare function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import>;
634
586
 
635
587
  type BuildOptions = {
636
588
  config: PluginContext['config'];
@@ -668,8 +620,6 @@ declare class Warning extends Error {
668
620
  cause: Error;
669
621
  });
670
622
  }
671
- declare class ValidationPluginError extends Error {
672
- }
673
623
 
674
624
  /**
675
625
  * Abstract class that contains the building blocks for plugins to create their own Generator
@@ -739,4 +689,4 @@ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
739
689
  type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
740
690
  type Plugin = keyof Plugins;
741
691
 
742
- export { type CLIOptions, FileManager, Generator, type GetPluginFactoryOptions, type InputData, type InputPath, type KubbConfig, KubbFile, type KubbObjectPlugin, type KubbPlugin, type KubbPluginWithLifeCycle, type KubbUnionPlugins, type KubbUserConfig, type KubbUserPlugin, type KubbUserPluginWithLifeCycle, type OptionsOfPlugin, type OptionsPlugins, PackageManager, type Plugin, type PluginCache, type PluginContext, type PluginFactoryOptions, type PluginLifecycle, type PluginLifecycleHooks, PluginManager, type PluginParameter, type PluginUnion, type Plugins, PromiseManager, type ResolveNameParams, type ResolvePathParams, type TransformResult, ValidationPluginError, Warning, type _Register, build, combineExports, combineImports, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
692
+ export { type CLIOptions, FileManager, Generator, type GetPluginFactoryOptions, type InputData, type InputPath, type KubbConfig, KubbFile, type KubbObjectPlugin, type KubbPlugin, type KubbPluginWithLifeCycle, type KubbUnionPlugins, type KubbUserConfig, type KubbUserPlugin, type KubbUserPluginWithLifeCycle, type OptionsOfPlugin, type OptionsPlugins, PackageManager, type Plugin, type PluginCache, type PluginContext, type PluginFactoryOptions, type PluginLifecycle, type PluginLifecycleHooks, PluginManager, type PluginParameter, type PluginUnion, type Plugins, PromiseManager, type ResolveNameParams, type ResolvePathParams, type TransformResult, Warning, type _Register, build, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };