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

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.
Files changed (48) hide show
  1. package/dist/Queue-2-6pMcCx.d.cts +32 -0
  2. package/dist/Queue-2-6pMcCx.d.ts +32 -0
  3. package/dist/fs.cjs +2383 -0
  4. package/dist/fs.cjs.map +1 -0
  5. package/dist/fs.d.cts +5 -0
  6. package/dist/fs.d.ts +5 -0
  7. package/dist/fs.js +2380 -0
  8. package/dist/fs.js.map +1 -0
  9. package/dist/index.cjs +3336 -191
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +18 -69
  12. package/dist/index.d.ts +18 -69
  13. package/dist/index.js +3655 -226
  14. package/dist/index.js.map +1 -1
  15. package/dist/logger.cjs +148 -0
  16. package/dist/logger.cjs.map +1 -0
  17. package/dist/logger.d.cts +31 -0
  18. package/dist/logger.d.ts +31 -0
  19. package/dist/logger.js +140 -0
  20. package/dist/logger.js.map +1 -0
  21. package/dist/transformers.cjs +79 -9
  22. package/dist/transformers.cjs.map +1 -1
  23. package/dist/transformers.js +82 -8
  24. package/dist/transformers.js.map +1 -1
  25. package/dist/utils.cjs +86 -766
  26. package/dist/utils.cjs.map +1 -1
  27. package/dist/utils.d.cts +3 -595
  28. package/dist/utils.d.ts +3 -595
  29. package/dist/utils.js +87 -727
  30. package/dist/utils.js.map +1 -1
  31. package/dist/write-46ytbnu9.d.cts +7 -0
  32. package/dist/write-46ytbnu9.d.ts +7 -0
  33. package/package.json +21 -11
  34. package/src/FileManager.ts +34 -62
  35. package/src/PluginManager.ts +20 -15
  36. package/src/build.ts +11 -12
  37. package/src/fs/index.ts +3 -0
  38. package/src/index.ts +4 -4
  39. package/src/{utils/logger.ts → logger.ts} +38 -3
  40. package/src/plugin.ts +1 -1
  41. package/src/transformers/casing.ts +3 -3
  42. package/src/types.ts +1 -1
  43. package/src/utils/index.ts +10 -18
  44. package/src/utils/randomColour.ts +0 -39
  45. package/src/utils/throttle.ts +0 -30
  46. /package/src/{utils → fs}/clean.ts +0 -0
  47. /package/src/{utils → fs}/read.ts +0 -0
  48. /package/src/{utils → fs}/write.ts +0 -0
package/dist/index.d.cts CHANGED
@@ -1,10 +1,9 @@
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';
8
7
 
9
8
  type BarrelManagerOptions = {
10
9
  treeNode?: DirectoryTreeOptions;
@@ -15,57 +14,6 @@ type BarrelManagerOptions = {
15
14
  extName?: KubbFile.Extname;
16
15
  };
17
16
 
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
17
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
70
18
  /**
71
19
  * Get the type of the first argument in a function.
@@ -105,30 +53,36 @@ declare class PluginManager {
105
53
  #private;
106
54
  readonly plugins: KubbPluginWithLifeCycle[];
107
55
  readonly fileManager: FileManager;
108
- readonly eventEmitter: EventEmitter<Events>;
56
+ readonly events: EventEmitter<Events>;
109
57
  readonly queue: Queue;
110
58
  readonly config: KubbConfig;
111
- readonly executed: Executer[];
59
+ readonly executed: Array<Executer>;
112
60
  readonly logger: Logger;
113
61
  constructor(config: KubbConfig, options: Options$2);
114
62
  resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
115
63
  resolveName: (params: ResolveNameParams) => string;
64
+ /**
65
+ * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
66
+ */
116
67
  on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
117
68
  /**
118
- * Run only hook for a specific plugin name
69
+ * Run a specific hookName for plugin x.
119
70
  */
120
71
  hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
121
72
  pluginKey: KubbPlugin['key'];
122
73
  hookName: H;
123
74
  parameters: PluginParameter<H>;
124
75
  }): Promise<Array<ReturnType<ParseResult<H>> | null>> | null;
76
+ /**
77
+ * Run a specific hookName for plugin x.
78
+ */
125
79
  hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
126
80
  pluginKey: KubbPlugin['key'];
127
81
  hookName: H;
128
82
  parameters: PluginParameter<H>;
129
83
  }): Array<ReturnType<ParseResult<H>>> | null;
130
84
  /**
131
- * Chains, first non-null result stops and returns
85
+ * First non-null result stops and will return it's value.
132
86
  */
133
87
  hookFirst<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
134
88
  hookName: H;
@@ -136,7 +90,7 @@ declare class PluginManager {
136
90
  skipped?: ReadonlySet<KubbPlugin> | null;
137
91
  }): Promise<SafeParseResult<H>>;
138
92
  /**
139
- * Chains, first non-null result stops and returns
93
+ * First non-null result stops and will return it's value.
140
94
  */
141
95
  hookFirstSync<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
142
96
  hookName: H;
@@ -144,14 +98,14 @@ declare class PluginManager {
144
98
  skipped?: ReadonlySet<KubbPlugin> | null;
145
99
  }): SafeParseResult<H>;
146
100
  /**
147
- * Parallel, runs all plugins
101
+ * Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
148
102
  */
149
103
  hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ hookName, parameters, }: {
150
104
  hookName: H;
151
105
  parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
152
106
  }): Promise<Awaited<TOuput>[]>;
153
107
  /**
154
- * Chains, reduces returned value, handling the reduced value as the first hook argument
108
+ * 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
109
  */
156
110
  hookReduceArg0<H extends PluginLifecycleHooks>({ hookName, parameters, reduce, }: {
157
111
  hookName: H;
@@ -624,13 +578,10 @@ declare class FileManager {
624
578
  write(...params: Parameters<typeof write>): Promise<string | undefined>;
625
579
  read(...params: Parameters<typeof read>): Promise<string>;
626
580
  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
581
  static getMode(path: string | undefined | null): KubbFile.Mode;
629
582
  static get extensions(): Array<KubbFile.Extname>;
630
583
  static isExtensionAllowed(baseName: string): boolean;
631
584
  }
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
585
 
635
586
  type BuildOptions = {
636
587
  config: PluginContext['config'];
@@ -668,8 +619,6 @@ declare class Warning extends Error {
668
619
  cause: Error;
669
620
  });
670
621
  }
671
- declare class ValidationPluginError extends Error {
672
- }
673
622
 
674
623
  /**
675
624
  * Abstract class that contains the building blocks for plugins to create their own Generator
@@ -739,4 +688,4 @@ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
739
688
  type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
740
689
  type Plugin = keyof Plugins;
741
690
 
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 };
691
+ 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,9 @@
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';
8
7
 
9
8
  type BarrelManagerOptions = {
10
9
  treeNode?: DirectoryTreeOptions;
@@ -15,57 +14,6 @@ type BarrelManagerOptions = {
15
14
  extName?: KubbFile.Extname;
16
15
  };
17
16
 
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
17
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
70
18
  /**
71
19
  * Get the type of the first argument in a function.
@@ -105,30 +53,36 @@ declare class PluginManager {
105
53
  #private;
106
54
  readonly plugins: KubbPluginWithLifeCycle[];
107
55
  readonly fileManager: FileManager;
108
- readonly eventEmitter: EventEmitter<Events>;
56
+ readonly events: EventEmitter<Events>;
109
57
  readonly queue: Queue;
110
58
  readonly config: KubbConfig;
111
- readonly executed: Executer[];
59
+ readonly executed: Array<Executer>;
112
60
  readonly logger: Logger;
113
61
  constructor(config: KubbConfig, options: Options$2);
114
62
  resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
115
63
  resolveName: (params: ResolveNameParams) => string;
64
+ /**
65
+ * Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
66
+ */
116
67
  on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
117
68
  /**
118
- * Run only hook for a specific plugin name
69
+ * Run a specific hookName for plugin x.
119
70
  */
120
71
  hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
121
72
  pluginKey: KubbPlugin['key'];
122
73
  hookName: H;
123
74
  parameters: PluginParameter<H>;
124
75
  }): Promise<Array<ReturnType<ParseResult<H>> | null>> | null;
76
+ /**
77
+ * Run a specific hookName for plugin x.
78
+ */
125
79
  hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
126
80
  pluginKey: KubbPlugin['key'];
127
81
  hookName: H;
128
82
  parameters: PluginParameter<H>;
129
83
  }): Array<ReturnType<ParseResult<H>>> | null;
130
84
  /**
131
- * Chains, first non-null result stops and returns
85
+ * First non-null result stops and will return it's value.
132
86
  */
133
87
  hookFirst<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
134
88
  hookName: H;
@@ -136,7 +90,7 @@ declare class PluginManager {
136
90
  skipped?: ReadonlySet<KubbPlugin> | null;
137
91
  }): Promise<SafeParseResult<H>>;
138
92
  /**
139
- * Chains, first non-null result stops and returns
93
+ * First non-null result stops and will return it's value.
140
94
  */
141
95
  hookFirstSync<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
142
96
  hookName: H;
@@ -144,14 +98,14 @@ declare class PluginManager {
144
98
  skipped?: ReadonlySet<KubbPlugin> | null;
145
99
  }): SafeParseResult<H>;
146
100
  /**
147
- * Parallel, runs all plugins
101
+ * Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
148
102
  */
149
103
  hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ hookName, parameters, }: {
150
104
  hookName: H;
151
105
  parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
152
106
  }): Promise<Awaited<TOuput>[]>;
153
107
  /**
154
- * Chains, reduces returned value, handling the reduced value as the first hook argument
108
+ * 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
109
  */
156
110
  hookReduceArg0<H extends PluginLifecycleHooks>({ hookName, parameters, reduce, }: {
157
111
  hookName: H;
@@ -624,13 +578,10 @@ declare class FileManager {
624
578
  write(...params: Parameters<typeof write>): Promise<string | undefined>;
625
579
  read(...params: Parameters<typeof read>): Promise<string>;
626
580
  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
581
  static getMode(path: string | undefined | null): KubbFile.Mode;
629
582
  static get extensions(): Array<KubbFile.Extname>;
630
583
  static isExtensionAllowed(baseName: string): boolean;
631
584
  }
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
585
 
635
586
  type BuildOptions = {
636
587
  config: PluginContext['config'];
@@ -668,8 +619,6 @@ declare class Warning extends Error {
668
619
  cause: Error;
669
620
  });
670
621
  }
671
- declare class ValidationPluginError extends Error {
672
- }
673
622
 
674
623
  /**
675
624
  * Abstract class that contains the building blocks for plugins to create their own Generator
@@ -739,4 +688,4 @@ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
739
688
  type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
740
689
  type Plugin = keyof Plugins;
741
690
 
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 };
691
+ 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 };