@kubb/core 1.15.0-canary.20231027T200912 → 2.0.0-canary.20231027T203719

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.ts CHANGED
@@ -1,89 +1,43 @@
1
1
  import { DirectoryTreeOptions } from 'directory-tree';
2
2
  import { Ora } from 'ora';
3
- export { default as pc } from 'picocolors';
4
3
 
5
- interface Cache<TStore extends object = object> {
6
- delete(id: keyof TStore): boolean;
7
- get(id: keyof TStore): TStore[keyof TStore] | null;
8
- has(id: keyof TStore): boolean;
9
- set(id: keyof TStore, value: unknown): void;
10
- }
11
- declare function createPluginCache<TStore extends PluginCache>(Store?: TStore): Cache<TStore>;
12
-
13
- declare function clean(path: string): Promise<void>;
14
-
15
- type FunctionParamsASTWithoutType = {
16
- name?: string;
17
- type?: string;
18
- /**
19
- * @default true
20
- */
21
- required?: boolean;
22
- /**
23
- * @default true
24
- */
25
- enabled?: boolean;
26
- default?: string;
27
- };
28
- type FunctionParamsASTWithType = {
29
- name?: never;
30
- type: string;
31
- /**
32
- * @default true
33
- */
34
- required?: boolean;
35
- /**
36
- * @default true
37
- */
38
- enabled?: boolean;
39
- default?: string;
40
- };
41
- type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType;
42
- declare class FunctionParams {
43
- type?: 'generics' | 'typed';
44
- items: FunctionParamsAST[];
45
- constructor(type?: 'generics' | 'typed');
46
- add(item: FunctionParamsAST | Array<FunctionParamsAST | undefined> | undefined): FunctionParams;
47
- toString(): string;
48
- }
4
+ declare function read(path: string): Promise<string>;
49
5
 
50
- declare function getUniqueName(originalName: string, data: Record<string, number>): string;
6
+ declare function write(data: string, path: string): Promise<string | undefined>;
51
7
 
52
- declare function isPromise<T>(result: PossiblePromise<T>): result is Promise<T>;
53
- declare function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T>;
54
- declare function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & {
55
- reason: T;
8
+ type BarrelManagerOptions = {
9
+ treeNode?: DirectoryTreeOptions;
10
+ isTypeOnly?: boolean;
11
+ filter?: (file: KubbFile.File) => boolean;
12
+ map?: (file: KubbFile.File) => KubbFile.File;
13
+ includeExt?: boolean;
14
+ output?: string;
56
15
  };
57
16
 
58
- declare function createJSDocBlockText({ comments }: {
59
- comments: Array<string>;
60
- }): string;
61
-
62
- type LogType = 'error' | 'info' | 'warning';
63
- type Logger = {
64
- log: (message: string | null) => void;
65
- error: (message: string | null) => void;
66
- info: (message: string | null) => void;
67
- warn: (message: string | null) => void;
68
- spinner?: Ora;
69
- logs: string[];
70
- };
71
- declare function createLogger(spinner?: Ora): Logger;
72
-
73
- declare function nameSorter<T extends {
74
- name: string;
75
- }>(a: T, b: T): 0 | 1 | -1;
17
+ declare class EventEmitter<TEvents extends Record<string, any>> {
18
+ #private;
19
+ constructor();
20
+ emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
21
+ on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
22
+ off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
23
+ removeAll(): void;
24
+ }
76
25
 
77
26
  type QueueJob<T = unknown> = {
78
- (...args: unknown[]): Promise<T> | Promise<void>;
27
+ (...args: unknown[]): Promise<T | void>;
79
28
  };
80
29
  type RunOptions = {
81
30
  controller?: AbortController;
82
31
  name?: string;
83
32
  description?: string;
84
33
  };
34
+ type Events$1 = {
35
+ jobDone: [result: unknown];
36
+ jobFailed: [error: Error];
37
+ };
85
38
  declare class Queue {
86
39
  #private;
40
+ readonly eventEmitter: EventEmitter<Events$1>;
87
41
  constructor(maxParallel: number, debug?: boolean);
88
42
  run<T>(job: QueueJob<T>, options?: RunOptions): Promise<T>;
89
43
  runSync<T>(job: QueueJob<T>, options?: RunOptions): void;
@@ -91,14 +45,7 @@ declare class Queue {
91
45
  get count(): number;
92
46
  }
93
47
 
94
- declare const defaultColours: readonly ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"];
95
- declare function randomColour(text?: string, colours?: readonly ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"]): string;
96
- declare function randomPicoColour(text?: string, colors?: readonly ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"]): string;
97
-
98
48
  type BasePath<T extends string = string> = `${T}/`;
99
- type CacheItem = KubbFile.ResolvedFile & {
100
- cancel?: () => void;
101
- };
102
49
  declare namespace KubbFile {
103
50
  type Import = {
104
51
  name: string | Array<string>;
@@ -119,11 +66,15 @@ declare namespace KubbFile {
119
66
  type Path = string;
120
67
  type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
121
68
  type OptionalPath = Path | undefined | null;
122
- type File<TMeta extends {
123
- pluginName?: string;
124
- } = {
125
- pluginName?: string;
126
- }, TBaseName extends BaseName = BaseName> = {
69
+ type FileMetaBase = {
70
+ pluginKey?: KubbPlugin['key'];
71
+ };
72
+ type File<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = {
73
+ /**
74
+ * Unique identifier to reuse later
75
+ * @default crypto.randomUUID()
76
+ */
77
+ id?: string;
127
78
  /**
128
79
  * Name to be used to dynamicly create the baseName(based on input.path)
129
80
  * Based on UNIX basename
@@ -139,6 +90,7 @@ declare namespace KubbFile {
139
90
  exports?: Export[];
140
91
  /**
141
92
  * This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
93
+ * This will also ignore the combinefiles utils
142
94
  * @default `false`
143
95
  */
144
96
  override?: boolean;
@@ -147,22 +99,69 @@ declare namespace KubbFile {
147
99
  * This will override `process.env[key]` inside the `source`, see `getFileSource`.
148
100
  */
149
101
  env?: NodeJS.ProcessEnv;
102
+ validate?: boolean;
150
103
  };
151
104
  type ResolvedFile = KubbFile.File & {
152
105
  /**
153
- * crypto.randomUUID()
106
+ * @default crypto.randomUUID()
154
107
  */
155
108
  id: UUID;
156
109
  };
157
110
  }
111
+ type AddResult<T extends Array<KubbFile.File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<KubbFile.ResolvedFile[]> : Promise<KubbFile.ResolvedFile>>>;
112
+ type AddIndexesProps = {
113
+ root: KubbFile.Path;
114
+ extName?: KubbFile.Extname;
115
+ options?: BarrelManagerOptions;
116
+ meta?: KubbFile.File['meta'];
117
+ };
118
+ type Options$2 = {
119
+ queue?: Queue;
120
+ task?: QueueJob<KubbFile.ResolvedFile>;
121
+ /**
122
+ * Timeout between writes
123
+ */
124
+ timeout?: number;
125
+ };
126
+ declare class FileManager {
127
+ #private;
128
+ constructor(options?: Options$2);
129
+ get files(): Array<KubbFile.File>;
130
+ get isExecuting(): boolean;
131
+ add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T>;
132
+ addIndexes({ root, extName, meta, options }: AddIndexesProps): Promise<Array<KubbFile.File> | undefined>;
133
+ getCacheByUUID(UUID: KubbFile.UUID): KubbFile.File | undefined;
134
+ get(path: KubbFile.Path): Array<KubbFile.File> | undefined;
135
+ remove(path: KubbFile.Path): void;
136
+ write(...params: Parameters<typeof write>): Promise<string | undefined>;
137
+ read(...params: Parameters<typeof read>): Promise<string>;
138
+ static getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(file: KubbFile.File<TMeta>): string;
139
+ static combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(files: Array<KubbFile.File<TMeta> | null>): Array<KubbFile.File<TMeta>>;
140
+ static getMode(path: string | undefined | null): KubbFile.Mode;
141
+ static get extensions(): Array<KubbFile.Extname>;
142
+ static isExtensionAllowed(baseName: string): boolean;
143
+ }
144
+ declare function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export>;
145
+ declare function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import>;
158
146
 
159
- declare function getRelativePath(rootDir?: string | null, filePath?: string | null, platform?: 'windows' | 'mac' | 'linux'): string;
160
- declare function getPathMode(path: string | undefined | null): KubbFile.Mode;
161
- declare function read(path: string): Promise<string>;
162
- declare function readSync(path: string): string;
163
-
164
- declare function renderTemplate<TData extends Record<string, unknown> = Record<string, unknown>>(template: string, data?: TData | undefined): string;
165
-
147
+ declare class PluginError extends Error {
148
+ pluginManager: PluginManager;
149
+ cause: Error;
150
+ constructor(message: string, options: {
151
+ cause: Error;
152
+ pluginManager: PluginManager;
153
+ });
154
+ }
155
+ declare class ParallelPluginError extends Error {
156
+ errors: PluginError[];
157
+ pluginManager: PluginManager;
158
+ constructor(message: string, options: {
159
+ cause?: Error;
160
+ errors: PluginError[];
161
+ pluginManager: PluginManager;
162
+ });
163
+ findError<T extends Error = Error>(searchError: T | undefined): T | undefined;
164
+ }
166
165
  declare class SummaryError extends Error {
167
166
  summary: string[];
168
167
  constructor(message: string, options: {
@@ -170,82 +169,6 @@ declare class SummaryError extends Error {
170
169
  summary?: string[];
171
170
  });
172
171
  }
173
-
174
- declare const throttle: <R, A extends any[]>(fn: (...args: A) => R, delay: number) => [(...args: A) => R | undefined, () => void];
175
-
176
- declare function timeout(ms: number): Promise<unknown>;
177
-
178
- declare function combineCodes(codes: string[]): string;
179
-
180
- declare function escape(text?: string): string;
181
- /**
182
- * Escape all characters not included in SingleStringCharacters and DoubleStringCharacters on
183
- * @link http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
184
- * @link https://github.com/joliss/js-string-escape/blob/master/index.js
185
- */
186
- declare function jsStringEscape(input: any): string;
187
-
188
- declare function transformReservedWord(word: string): string;
189
-
190
- type TreeNodeOptions = DirectoryTreeOptions;
191
- declare class TreeNode<T = unknown> {
192
- data: T;
193
- parent?: TreeNode<T>;
194
- children: Array<TreeNode<T>>;
195
- constructor(data: T, parent?: TreeNode<T>);
196
- addChild(data: T): TreeNode<T>;
197
- find(data?: T): TreeNode<T> | null;
198
- get leaves(): TreeNode<T>[];
199
- get root(): TreeNode<T>;
200
- forEach(callback: (treeNode: TreeNode<T>) => void): this;
201
- static build<T = unknown>(path: string, options?: TreeNodeOptions): TreeNode<T> | null;
202
- }
203
-
204
- declare const uniqueIdFactory: (counter: number) => (str?: string) => string;
205
-
206
- type URLObject = {
207
- url: string;
208
- params?: Record<string, string>;
209
- };
210
- type ObjectOptions = {
211
- type?: 'path' | 'template';
212
- replacer?: (pathParam: string) => string;
213
- stringify?: boolean;
214
- };
215
- declare class URLPath {
216
- path: string;
217
- constructor(path: string);
218
- /**
219
- * Convert Swagger path to URLPath(syntax of Express)
220
- * @example /pet/{petId} => /pet/:petId
221
- */
222
- get URL(): string;
223
- get isURL(): boolean;
224
- /**
225
- * Convert Swagger path to template literals/ template strings(camelcase)
226
- * @example /pet/{petId} => `/pet/${petId}`
227
- * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
228
- * @example /account/userID => `/account/${userId}`
229
- */
230
- get template(): string;
231
- get object(): URLObject | string;
232
- get params(): Record<string, string> | undefined;
233
- toObject({ type, replacer, stringify }?: ObjectOptions): URLObject | string;
234
- /**
235
- * Convert Swagger path to template literals/ template strings(camelcase)
236
- * @example /pet/{petId} => `/pet/${petId}`
237
- * @example /account/monetary-accountID => `/account/${monetaryAccountId}`
238
- * @example /account/userID => `/account/${userId}`
239
- */
240
- toTemplateString(replacer?: (pathParam: string) => string): string;
241
- getParams(replacer?: (pathParam: string) => string): Record<string, string> | undefined;
242
- /**
243
- * Convert Swagger path to URLPath(syntax of Express)
244
- * @example /pet/{petId} => /pet/:petId
245
- */
246
- toURLPath(): string;
247
- }
248
-
249
172
  /**
250
173
  * Behaves as an Error to log a warning in the console(still stops the execution)
251
174
  */
@@ -254,70 +177,28 @@ declare class Warning extends Error {
254
177
  cause: Error;
255
178
  });
256
179
  }
257
-
258
- declare function write(data: string, path: string): Promise<void>;
259
-
260
- declare class FileManager {
261
- #private;
262
- constructor(options?: {
263
- queue?: Queue;
264
- task?: QueueJob<KubbFile.ResolvedFile>;
265
- });
266
- get extensions(): Array<KubbFile.Extname>;
267
- get files(): Array<KubbFile.File>;
268
- get isExecuting(): boolean;
269
- add(file: KubbFile.File): Promise<KubbFile.ResolvedFile>;
270
- addOrAppend(file: KubbFile.File): Promise<KubbFile.ResolvedFile>;
271
- addIndexes(root: KubbFile.Path, extName?: KubbFile.Extname, options?: TreeNodeOptions): Promise<Array<KubbFile.File> | undefined>;
272
- getCacheByUUID(UUID: KubbFile.UUID): KubbFile.File | undefined;
273
- get(path: KubbFile.Path): Array<KubbFile.File> | undefined;
274
- remove(path: KubbFile.Path): void;
275
- write(...params: Parameters<typeof write>): Promise<void>;
276
- read(...params: Parameters<typeof read>): Promise<string>;
180
+ declare class ValidationPluginError extends Error {
277
181
  }
278
182
 
279
- declare function getIndexes(root: string, extName?: KubbFile.Extname, options?: TreeNodeOptions): Array<KubbFile.File> | null;
280
- declare function combineFiles(files: Array<KubbFile.File | null>): Array<KubbFile.File>;
281
- /**
282
- * Support for js, ts and tsx(React)
283
- */
284
- declare const extensions: Array<KubbFile.Extname>;
285
- declare function isExtensionAllowed(baseName: string): boolean;
286
- declare function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export>;
287
- declare function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source: string): Array<KubbFile.Import>;
288
- declare function createFileSource(file: KubbFile.File): string;
289
-
290
- type PackageJSON = {
291
- dependencies?: Record<string, string>;
292
- devDependencies?: Record<string, string>;
183
+ declare const LogLevel: {
184
+ readonly silent: "silent";
185
+ readonly info: "info";
186
+ readonly debug: "debug";
187
+ };
188
+ type LogLevel = keyof typeof LogLevel;
189
+ type Logger = {
190
+ /**
191
+ * Optional config name to show in CLI output
192
+ */
193
+ name?: string;
194
+ logLevel: LogLevel;
195
+ log: (message: string | null) => void;
196
+ error: (message: string | null) => void;
197
+ info: (message: string | null) => void;
198
+ warn: (message: string | null) => void;
199
+ spinner?: Ora;
200
+ logs: string[];
293
201
  };
294
- type DependencyName = string;
295
- type DependencyVersion = string;
296
- declare class PackageManager {
297
- #private;
298
- constructor(workspace?: string);
299
- set workspace(workspace: string);
300
- get workspace(): string | undefined;
301
- normalizeDirectory(directory: string): string;
302
- getLocation(path: string): string;
303
- import(path: string): Promise<any | undefined>;
304
- getPackageJSON(): Promise<PackageJSON | undefined>;
305
- getPackageJSONSync(): PackageJSON | undefined;
306
- static setVersion(dependency: DependencyName, version: DependencyVersion): void;
307
- getVersion(dependency: DependencyName): Promise<DependencyVersion | undefined>;
308
- getVersionSync(dependency: DependencyName): DependencyVersion | undefined;
309
- isValid(dependency: DependencyName, version: DependencyVersion): Promise<boolean>;
310
- isValidSync(dependency: DependencyName, version: DependencyVersion): boolean;
311
- }
312
-
313
- declare class EventEmitter<TEvents extends Record<string, any>> {
314
- #private;
315
- constructor();
316
- emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
317
- on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
318
- off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
319
- removeAll(): void;
320
- }
321
202
 
322
203
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
323
204
  /**
@@ -325,9 +206,9 @@ type RequiredPluginLifecycle = Required<PluginLifecycle>;
325
206
  * @example Arg0<(a: string, b: number) => void> -> string
326
207
  */
327
208
  type Argument0<H extends keyof PluginLifecycle> = Parameters<RequiredPluginLifecycle[H]>[0];
328
- type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq';
209
+ type Strategy$1 = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq';
329
210
  type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
330
- strategy: Strategy;
211
+ strategy: Strategy$1;
331
212
  hookName: H;
332
213
  plugin: KubbPlugin;
333
214
  parameters?: unknown[] | undefined;
@@ -338,13 +219,16 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
338
219
  result: Result;
339
220
  plugin: KubbPlugin;
340
221
  };
341
- type PluginParameter<H extends PluginLifecycleHooks> = Parameters<RequiredPluginLifecycle[H]>;
342
-
343
- declare const hooks: [keyof PluginLifecycle<PluginFactoryOptions<string, unknown, false, unknown, Record<string, unknown>>>];
344
222
  type Options$1 = {
345
- debug?: boolean;
346
- task: QueueJob<KubbFile.ResolvedFile>;
347
223
  logger: Logger;
224
+ /**
225
+ * Task for the FileManager
226
+ */
227
+ task: QueueJob<KubbFile.ResolvedFile>;
228
+ /**
229
+ * Timeout between writes in the FileManager
230
+ */
231
+ writeTimeout?: number;
348
232
  };
349
233
  type Events = {
350
234
  execute: [executer: Executer];
@@ -366,16 +250,16 @@ declare class PluginManager {
366
250
  /**
367
251
  * Run only hook for a specific plugin name
368
252
  */
369
- hookForPlugin<H extends PluginLifecycleHooks>({ pluginName, hookName, parameters, }: {
370
- pluginName: string;
253
+ hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
254
+ pluginKey: KubbPlugin['key'];
371
255
  hookName: H;
372
256
  parameters: PluginParameter<H>;
373
- }): Promise<ReturnType<ParseResult<H>> | null> | null;
374
- hookForPluginSync<H extends PluginLifecycleHooks>({ pluginName, hookName, parameters, }: {
375
- pluginName: string;
257
+ }): Promise<Array<ReturnType<ParseResult<H>> | null>> | null;
258
+ hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
259
+ pluginKey: KubbPlugin['key'];
376
260
  hookName: H;
377
261
  parameters: PluginParameter<H>;
378
- }): ReturnType<ParseResult<H>> | null;
262
+ }): Array<ReturnType<ParseResult<H>>> | null;
379
263
  /**
380
264
  * Chains, first non-null result stops and returns
381
265
  */
@@ -414,32 +298,17 @@ declare class PluginManager {
414
298
  hookName: H;
415
299
  parameters?: PluginParameter<H>;
416
300
  }): Promise<void>;
417
- getPlugin(hookName: keyof PluginLifecycle, pluginName: string): KubbPlugin;
301
+ getPluginsByKey(hookName: keyof PluginLifecycle, pluginKey: KubbPlugin['key']): KubbPlugin[];
302
+ static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = T3 extends never ? T2 extends never ? [T1: KubbPlugin<T1>] : [T1: KubbPlugin<T1>, T2: KubbPlugin<T2>] : [T1: KubbPlugin<T1>, T2: KubbPlugin<T2>, T3: KubbPlugin<T3>]>(plugins: Array<KubbPlugin>, dependedPluginNames: string | string[]): TOutput;
303
+ static get hooks(): readonly ["validate", "buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
418
304
  }
419
305
 
420
- declare class PluginError extends Error {
421
- pluginManager: PluginManager;
422
- cause: Error;
423
- constructor(message: string, options: {
424
- cause: Error;
425
- pluginManager: PluginManager;
426
- });
427
- }
428
-
429
- declare class ParallelPluginError extends Error {
430
- errors: PluginError[];
431
- pluginManager: PluginManager;
432
- constructor(message: string, options: {
433
- cause?: Error;
434
- errors: PluginError[];
435
- pluginManager: PluginManager;
436
- });
437
- findError<T extends Error = Error>(searchError: T | undefined): T | undefined;
438
- }
439
-
440
- declare class ValidationPluginError extends Error {
306
+ interface Cache<TStore extends object = object> {
307
+ delete(id: keyof TStore): boolean;
308
+ get(id: keyof TStore): TStore[keyof TStore] | null;
309
+ has(id: keyof TStore): boolean;
310
+ set(id: keyof TStore, value: unknown): void;
441
311
  }
442
- declare function getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = T3 extends never ? T2 extends never ? [T1: KubbPlugin<T1>] : [T1: KubbPlugin<T1>, T2: KubbPlugin<T2>] : [T1: KubbPlugin<T1>, T2: KubbPlugin<T2>, T3: KubbPlugin<T3>]>(plugins: Array<KubbPlugin>, dependedPluginNames: string | string[]): TOutput;
443
312
 
444
313
  /**
445
314
  * Config used in `kubb.config.js`
@@ -461,7 +330,7 @@ type KubbUserConfig = Omit<KubbConfig, 'root' | 'plugins'> & {
461
330
  * Example: ['@kubb/swagger', { output: false }]
462
331
  * Or: createSwagger({ output: false })
463
332
  */
464
- plugins?: Array<KubbPlugin> | Array<KubbJSONPlugins> | KubbObjectPlugins;
333
+ plugins?: Array<Omit<KubbUserPlugin, 'api'> | KubbUnionPlugins | [name: string, options: object]>;
465
334
  };
466
335
  type InputPath = {
467
336
  /**
@@ -479,14 +348,18 @@ type Input = InputPath | InputData;
479
348
  /**
480
349
  * @private
481
350
  */
482
- type KubbConfig = {
351
+ type KubbConfig<TInput = Input> = {
352
+ /**
353
+ * Optional config name to show in CLI output
354
+ */
355
+ name?: string;
483
356
  /**
484
357
  * Project root directory. Can be an absolute path, or a path relative from
485
358
  * the location of the config file itself.
486
359
  * @default process.cwd()
487
360
  */
488
361
  root: string;
489
- input: Input;
362
+ input: TInput;
490
363
  output: {
491
364
  /**
492
365
  * Path to be used to export all generated files.
@@ -547,40 +420,50 @@ type BuildOutput = {
547
420
  pluginManager: PluginManager;
548
421
  };
549
422
  type KubbPluginKind = 'schema' | 'controller';
550
- type KubbJSONPlugins = [plugin: keyof Kubb.OptionsPlugins | (string & {}), options: Kubb.OptionsPlugins[keyof Kubb.OptionsPlugins]];
551
- type KubbObjectPlugin = keyof Kubb.OptionsPlugins;
552
- type KubbObjectPlugins = {
553
- [K in keyof Kubb.OptionsPlugins]: Kubb.OptionsPlugins[K] | object;
554
- };
423
+ type KubbUnionPlugins = PluginUnion;
424
+ type KubbObjectPlugin = keyof OptionsPlugins;
425
+ type GetPluginFactoryOptions<TPlugin extends KubbUserPlugin> = TPlugin extends KubbUserPlugin<infer X> ? X : never;
555
426
  type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
556
427
  /**
557
428
  * Unique name used for the plugin
558
429
  * @example @kubb/typescript
559
430
  */
560
- name: PluginFactoryOptions['name'];
431
+ name: TOptions['name'];
432
+ /**
433
+ * Internal key used when a developer uses more than one of the same plugin
434
+ * @private
435
+ */
436
+ key?: TOptions['key'];
561
437
  /**
562
438
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
563
439
  */
564
440
  options: TOptions['options'] extends never ? undefined : TOptions['options'];
441
+ } & Partial<PluginLifecycle<TOptions>> & (TOptions['api'] extends never ? {
442
+ api?: never;
443
+ } : {
444
+ api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext, 'addFile'>) => TOptions['api'];
445
+ }) & (TOptions['kind'] extends never ? {
446
+ kind?: never;
447
+ } : {
565
448
  /**
566
449
  * Kind/type for the plugin
567
450
  * Type 'schema' can be used for JSON schema's, TypeScript types, ...
568
451
  * Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
569
452
  * @default undefined
570
453
  */
571
- kind?: KubbPluginKind;
572
- } & Partial<PluginLifecycle<TOptions>> & (TOptions['api'] extends never ? {
573
- api?: never;
574
- } : {
575
- api: (this: Omit<PluginContext, 'addFile'>) => TOptions['api'];
454
+ kind: TOptions['kind'];
576
455
  });
577
456
  type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
578
457
  /**
579
458
  * Unique name used for the plugin
580
459
  * @example @kubb/typescript
581
460
  */
582
- name: PluginFactoryOptions['name'];
583
- key?: [kind: KubbPluginKind | undefined, name: PluginFactoryOptions['name'], identifier: string];
461
+ name: TOptions['name'];
462
+ /**
463
+ * Internal key used when a developer uses more than one of the same plugin
464
+ * @private
465
+ */
466
+ key: TOptions['key'];
584
467
  /**
585
468
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
586
469
  */
@@ -597,8 +480,13 @@ type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
597
480
  } : {
598
481
  api: TOptions['api'];
599
482
  });
600
- type PluginFactoryOptions<Name = string, Options = unknown | never, Nested extends boolean = false, API = unknown | never, resolvePathOptions = Record<string, unknown>> = {
483
+ type PluginFactoryOptions<Name = string, Kind extends KubbPluginKind = KubbPluginKind | never, Options = unknown | never, Nested extends boolean = false, API = unknown | never, resolvePathOptions = Record<string, unknown>> = {
601
484
  name: Name;
485
+ kind: Kind;
486
+ /**
487
+ * Same like `QueryKey` in `@tanstack/react-query`
488
+ */
489
+ key: [kind: Kind | undefined, name: Name, identifier?: string | number];
602
490
  options: Options;
603
491
  nested: Nested;
604
492
  api: API;
@@ -643,7 +531,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
643
531
  * Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
644
532
  * @type hookParallel
645
533
  */
646
- writeFile?: (this: Omit<PluginContext, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<void>;
534
+ writeFile?: (this: Omit<PluginContext, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<string | void>;
647
535
  /**
648
536
  * End of the plugin lifecycle.
649
537
  * @type hookParallel
@@ -651,13 +539,10 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
651
539
  buildEnd?: (this: PluginContext) => PossiblePromise<void>;
652
540
  };
653
541
  type PluginLifecycleHooks = keyof PluginLifecycle;
542
+ type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
654
543
  type PluginCache = Record<string, [number, unknown]>;
655
544
  type ResolvePathParams<TOptions = Record<string, unknown>> = {
656
- /**
657
- * When set, resolvePath will only call resolvePath of the name of the plugin set here.
658
- * If not defined it will fall back on the resolvePath of the core plugin.
659
- */
660
- pluginName?: string;
545
+ pluginKey?: KubbPlugin['key'];
661
546
  baseName: string;
662
547
  directory?: string | undefined;
663
548
  /**
@@ -667,11 +552,7 @@ type ResolvePathParams<TOptions = Record<string, unknown>> = {
667
552
  };
668
553
  type ResolveNameParams = {
669
554
  name: string;
670
- /**
671
- * When set, resolvePath will only call resolvePath of the name of the plugin set here.
672
- * If not defined it will fall back on the resolvePath of the core plugin.
673
- */
674
- pluginName?: string;
555
+ pluginKey?: KubbPlugin['key'];
675
556
  type?: 'file' | 'function';
676
557
  };
677
558
  type PluginContext<TOptions = Record<string, unknown>> = {
@@ -683,22 +564,51 @@ type PluginContext<TOptions = Record<string, unknown>> = {
683
564
  resolvePath: (params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
684
565
  resolveName: (params: ResolveNameParams) => string;
685
566
  logger: Logger;
567
+ /**
568
+ * All plugins
569
+ */
686
570
  plugins: KubbPlugin[];
571
+ /**
572
+ * Current plugin
573
+ */
574
+ plugin: KubbPlugin;
687
575
  };
688
576
  type TransformResult = string | null;
689
- declare const LogLevel: {
690
- readonly silent: "silent";
691
- readonly info: "info";
692
- readonly debug: "debug";
693
- };
694
- type LogLevel = keyof typeof LogLevel;
695
577
  type AppMeta = {
696
578
  pluginManager: PluginManager;
697
579
  };
698
580
  type Prettify<T> = {
699
581
  [K in keyof T]: T[K];
700
582
  } & {};
583
+ /**
584
+ * TODO move to @kubb/types
585
+ * @deprecated
586
+ */
701
587
  type PossiblePromise<T> = Promise<T> | T;
588
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
589
+ type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never;
590
+ type Push<T extends any[], V> = [...T, V];
591
+ type TuplifyUnion<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<TuplifyUnion<Exclude<T, L>>, L>;
592
+ /**
593
+ * TODO move to @kubb/types
594
+ * @deprecated
595
+ */
596
+ type ObjValueTuple<T, KS extends any[] = TuplifyUnion<keyof T>, R extends any[] = []> = KS extends [infer K, ...infer KT] ? ObjValueTuple<T, KT, [...R, [name: K & keyof T, options: T[K & keyof T]]]> : R;
597
+ /**
598
+ * TODO move to @kubb/types
599
+ * @deprecated
600
+ */
601
+ type TupleToUnion<T> = T extends Array<infer ITEMS> ? ITEMS : never;
602
+ /**
603
+ * TODO move to @kubb/types
604
+ * @deprecated
605
+ */
606
+ type ArrayWithLength<T extends number, U extends any[] = []> = U['length'] extends T ? U : ArrayWithLength<T, [true, ...U]>;
607
+ /**
608
+ * TODO move to @kubb/types
609
+ * @deprecated
610
+ */
611
+ type GreaterThan<T extends number, U extends number> = ArrayWithLength<U> extends [...ArrayWithLength<T>, ...infer _] ? false : true;
702
612
 
703
613
  type BuildOptions = {
704
614
  config: PluginContext['config'];
@@ -706,7 +616,6 @@ type BuildOptions = {
706
616
  * @default Logger without the spinner
707
617
  */
708
618
  logger?: Logger;
709
- logLevel?: LogLevel;
710
619
  };
711
620
  declare function build(options: BuildOptions): Promise<BuildOutput>;
712
621
 
@@ -715,9 +624,10 @@ declare function build(options: BuildOptions): Promise<BuildOutput>;
715
624
  * accepts a direct {@link KubbConfig} object, or a function that returns it.
716
625
  * The function receives a {@link ConfigEnv} object that exposes two properties:
717
626
  */
718
- declare function defineConfig(options: PossiblePromise<KubbUserConfig> | ((
627
+ declare function defineConfig(options: PossiblePromise<KubbUserConfig | Array<KubbUserConfig>> | ((
719
628
  /** The options derived from the CLI flags */
720
- cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig>)): typeof options;
629
+ cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig | Array<KubbUserConfig>>)): typeof options;
630
+ declare function isInputPath(result: KubbConfig | undefined): result is KubbConfig<InputPath>;
721
631
 
722
632
  /**
723
633
  * Abstract class that contains the building blocks for plugins to create their own Generator
@@ -732,6 +642,43 @@ declare abstract class Generator<TOptions = unknown, TContext = unknown> {
732
642
  abstract build(...params: unknown[]): unknown;
733
643
  }
734
644
 
645
+ type PackageJSON = {
646
+ dependencies?: Record<string, string>;
647
+ devDependencies?: Record<string, string>;
648
+ };
649
+ type DependencyName = string;
650
+ type DependencyVersion = string;
651
+ declare class PackageManager {
652
+ #private;
653
+ constructor(workspace?: string);
654
+ set workspace(workspace: string);
655
+ get workspace(): string | undefined;
656
+ normalizeDirectory(directory: string): string;
657
+ getLocation(path: string): string;
658
+ import(path: string): Promise<any | undefined>;
659
+ getPackageJSON(): Promise<PackageJSON | undefined>;
660
+ getPackageJSONSync(): PackageJSON | undefined;
661
+ static setVersion(dependency: DependencyName, version: DependencyVersion): void;
662
+ getVersion(dependency: DependencyName): Promise<DependencyVersion | undefined>;
663
+ getVersionSync(dependency: DependencyName): DependencyVersion | undefined;
664
+ isValid(dependency: DependencyName, version: DependencyVersion): Promise<boolean>;
665
+ isValidSync(dependency: DependencyName, version: DependencyVersion): boolean;
666
+ }
667
+
668
+ type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => KubbUserPlugin<T>;
669
+ declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
670
+ declare const pluginName = "core";
671
+
672
+ type PromiseFunc<T, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
673
+ type SeqOutput<TInput extends Array<PromiseFunc<TPromise, null>>, TPromise = unknown> = ReturnType<NonNullable<TInput[number]>>;
674
+ type Options = {};
675
+ type Strategy = 'seq';
676
+ declare class PromiseManager {
677
+ #private;
678
+ constructor(options?: Options);
679
+ run<TInput extends Array<PromiseFunc<TPromise, null>>, TPromise = unknown, TOutput = SeqOutput<TInput, TPromise>>(strategy: Strategy, promises: TInput): TOutput;
680
+ }
681
+
735
682
  /**
736
683
  * Abstract class that contains the building blocks for plugins to create their own SchemaGenerator
737
684
  */
@@ -739,19 +686,14 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
739
686
  abstract build(schema: TInput, name: string, description?: string): TOutput;
740
687
  }
741
688
 
742
- type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => T['nested'] extends true ? Array<KubbUserPlugin<T>> : KubbUserPlugin<T>;
743
- declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
744
- type Options = {
745
- config: PluginContext['config'];
746
- fileManager: FileManager;
747
- pluginManager: PluginManager;
748
- resolvePath: PluginContext['resolvePath'];
749
- resolveName: PluginContext['resolveName'];
750
- logger: PluginContext['logger'];
751
- getPlugins: () => KubbPlugin[];
752
- plugin: KubbPlugin;
689
+ interface _Register {
690
+ }
691
+ type Plugins = _Register;
692
+ type OptionsPlugins = {
693
+ [K in keyof Plugins]: Plugins[K]['options'];
753
694
  };
754
- type CorePluginOptions = PluginFactoryOptions<'core', Options, false, PluginContext>;
755
- declare const pluginName: CorePluginOptions['name'];
695
+ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
696
+ type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
697
+ type Plugin = keyof Plugins;
756
698
 
757
- export { AppMeta, Argument0, BuildOutput, CLIOptions, Cache, CacheItem, Executer, FileManager, FunctionParams, FunctionParamsAST, Generator, KubbConfig, KubbFile, KubbJSONPlugins, KubbObjectPlugin, KubbObjectPlugins, KubbPlugin, KubbPluginKind, KubbUserConfig, KubbUserPlugin, LogLevel, LogType, Logger, PackageManager, ParallelPluginError, ParseResult, PluginCache, PluginContext, PluginError, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PluginParameter, PossiblePromise, Prettify, Queue, QueueJob, RequiredPluginLifecycle, ResolveNameParams, ResolvePathParams, SafeParseResult, SchemaGenerator, Strategy, SummaryError, TransformResult, TreeNode, TreeNodeOptions, URLObject, URLPath, ValidationPluginError, Warning, build, clean, combineCodes, combineExports, combineFiles, combineImports, createFileSource, createJSDocBlockText, createLogger, createPlugin, createPluginCache, build as default, defaultColours, defineConfig, escape, extensions, getDependedPlugins, getIndexes, getPathMode, getRelativePath, getUniqueName, hooks, isExtensionAllowed, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, jsStringEscape, pluginName as name, nameSorter, pluginName, randomColour, randomPicoColour, read, readSync, renderTemplate, throttle, timeout, transformReservedWord, uniqueIdFactory, write };
699
+ export { AppMeta, BuildOutput, CLIOptions, FileManager, Generator, GetPluginFactoryOptions, GreaterThan, InputData, InputPath, KubbConfig, KubbFile, KubbObjectPlugin, KubbPlugin, KubbPluginKind, KubbUnionPlugins, KubbUserConfig, KubbUserPlugin, ObjValueTuple, OptionsOfPlugin, OptionsPlugins, PackageManager, ParallelPluginError, Plugin, PluginCache, PluginContext, PluginError, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PluginParameter, PluginUnion, Plugins, PossiblePromise, Prettify, PromiseManager, ResolveNameParams, ResolvePathParams, SchemaGenerator, SummaryError, TransformResult, TupleToUnion, ValidationPluginError, Warning, _Register, build, combineExports, combineImports, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName };