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

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,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>;
@@ -111,6 +58,10 @@ declare namespace KubbFile {
111
58
  isTypeOnly?: boolean;
112
59
  asAlias?: boolean;
113
60
  };
61
+ const dataTagSymbol: unique symbol;
62
+ type DataTag<Type, Value> = Type & {
63
+ [dataTagSymbol]: Value;
64
+ };
114
65
  type UUID = string;
115
66
  type Source = string;
116
67
  type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
@@ -119,11 +70,15 @@ declare namespace KubbFile {
119
70
  type Path = string;
120
71
  type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
121
72
  type OptionalPath = Path | undefined | null;
122
- type File<TMeta extends {
123
- pluginName?: string;
124
- } = {
125
- pluginName?: string;
126
- }, TBaseName extends BaseName = BaseName> = {
73
+ type FileMetaBase = {
74
+ pluginKey?: KubbPlugin['key'];
75
+ };
76
+ type File<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = {
77
+ /**
78
+ * Unique identifier to reuse later
79
+ * @default crypto.randomUUID()
80
+ */
81
+ id?: string;
127
82
  /**
128
83
  * Name to be used to dynamicly create the baseName(based on input.path)
129
84
  * Based on UNIX basename
@@ -139,6 +94,7 @@ declare namespace KubbFile {
139
94
  exports?: Export[];
140
95
  /**
141
96
  * This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
97
+ * This will also ignore the combinefiles utils
142
98
  * @default `false`
143
99
  */
144
100
  override?: boolean;
@@ -147,22 +103,69 @@ declare namespace KubbFile {
147
103
  * This will override `process.env[key]` inside the `source`, see `getFileSource`.
148
104
  */
149
105
  env?: NodeJS.ProcessEnv;
106
+ validate?: boolean;
150
107
  };
151
- type ResolvedFile = KubbFile.File & {
108
+ type ResolvedFile<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = KubbFile.File<TMeta, TBaseName> & {
152
109
  /**
153
- * crypto.randomUUID()
110
+ * @default crypto.randomUUID()
154
111
  */
155
112
  id: UUID;
156
113
  };
157
114
  }
115
+ type AddResult<T extends Array<KubbFile.File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<KubbFile.ResolvedFile[]> : Promise<KubbFile.ResolvedFile>>>;
116
+ type AddIndexesProps = {
117
+ root: KubbFile.Path;
118
+ extName?: KubbFile.Extname;
119
+ options?: BarrelManagerOptions;
120
+ meta?: KubbFile.File['meta'];
121
+ };
122
+ type Options$2 = {
123
+ queue?: Queue;
124
+ task?: QueueJob<KubbFile.ResolvedFile>;
125
+ /**
126
+ * Timeout between writes
127
+ */
128
+ timeout?: number;
129
+ };
130
+ declare class FileManager {
131
+ #private;
132
+ constructor(options?: Options$2);
133
+ get files(): Array<KubbFile.File>;
134
+ get isExecuting(): boolean;
135
+ add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T>;
136
+ addIndexes({ root, extName, meta, options }: AddIndexesProps): Promise<Array<KubbFile.File> | undefined>;
137
+ getCacheByUUID(UUID: KubbFile.UUID): KubbFile.File | undefined;
138
+ get(path: KubbFile.Path): Array<KubbFile.File> | undefined;
139
+ remove(path: KubbFile.Path): void;
140
+ write(...params: Parameters<typeof write>): Promise<string | undefined>;
141
+ read(...params: Parameters<typeof read>): Promise<string>;
142
+ static getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(file: KubbFile.File<TMeta>): string;
143
+ static combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(files: Array<KubbFile.File<TMeta> | null>): Array<KubbFile.File<TMeta>>;
144
+ static getMode(path: string | undefined | null): KubbFile.Mode;
145
+ static get extensions(): Array<KubbFile.Extname>;
146
+ static isExtensionAllowed(baseName: string): boolean;
147
+ }
148
+ declare function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export>;
149
+ declare function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import>;
158
150
 
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
-
151
+ declare class PluginError extends Error {
152
+ pluginManager: PluginManager;
153
+ cause: Error;
154
+ constructor(message: string, options: {
155
+ cause: Error;
156
+ pluginManager: PluginManager;
157
+ });
158
+ }
159
+ declare class ParallelPluginError extends Error {
160
+ errors: PluginError[];
161
+ pluginManager: PluginManager;
162
+ constructor(message: string, options: {
163
+ cause?: Error;
164
+ errors: PluginError[];
165
+ pluginManager: PluginManager;
166
+ });
167
+ findError<T extends Error = Error>(searchError: T | undefined): T | undefined;
168
+ }
166
169
  declare class SummaryError extends Error {
167
170
  summary: string[];
168
171
  constructor(message: string, options: {
@@ -170,82 +173,6 @@ declare class SummaryError extends Error {
170
173
  summary?: string[];
171
174
  });
172
175
  }
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
176
  /**
250
177
  * Behaves as an Error to log a warning in the console(still stops the execution)
251
178
  */
@@ -254,70 +181,28 @@ declare class Warning extends Error {
254
181
  cause: Error;
255
182
  });
256
183
  }
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>;
184
+ declare class ValidationPluginError extends Error {
277
185
  }
278
186
 
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>;
187
+ declare const LogLevel: {
188
+ readonly silent: "silent";
189
+ readonly info: "info";
190
+ readonly debug: "debug";
191
+ };
192
+ type LogLevel = keyof typeof LogLevel;
193
+ type Logger = {
194
+ /**
195
+ * Optional config name to show in CLI output
196
+ */
197
+ name?: string;
198
+ logLevel: LogLevel;
199
+ log: (message: string | null) => void;
200
+ error: (message: string | null) => void;
201
+ info: (message: string | null) => void;
202
+ warn: (message: string | null) => void;
203
+ spinner?: Ora;
204
+ logs: string[];
293
205
  };
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
206
 
322
207
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
323
208
  /**
@@ -325,9 +210,9 @@ type RequiredPluginLifecycle = Required<PluginLifecycle>;
325
210
  * @example Arg0<(a: string, b: number) => void> -> string
326
211
  */
327
212
  type Argument0<H extends keyof PluginLifecycle> = Parameters<RequiredPluginLifecycle[H]>[0];
328
- type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq';
213
+ type Strategy$1 = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq';
329
214
  type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
330
- strategy: Strategy;
215
+ strategy: Strategy$1;
331
216
  hookName: H;
332
217
  plugin: KubbPlugin;
333
218
  parameters?: unknown[] | undefined;
@@ -338,13 +223,16 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
338
223
  result: Result;
339
224
  plugin: KubbPlugin;
340
225
  };
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
226
  type Options$1 = {
345
- debug?: boolean;
346
- task: QueueJob<KubbFile.ResolvedFile>;
347
227
  logger: Logger;
228
+ /**
229
+ * Task for the FileManager
230
+ */
231
+ task: QueueJob<KubbFile.ResolvedFile>;
232
+ /**
233
+ * Timeout between writes in the FileManager
234
+ */
235
+ writeTimeout?: number;
348
236
  };
349
237
  type Events = {
350
238
  execute: [executer: Executer];
@@ -366,16 +254,16 @@ declare class PluginManager {
366
254
  /**
367
255
  * Run only hook for a specific plugin name
368
256
  */
369
- hookForPlugin<H extends PluginLifecycleHooks>({ pluginName, hookName, parameters, }: {
370
- pluginName: string;
257
+ hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
258
+ pluginKey: KubbPlugin['key'];
371
259
  hookName: H;
372
260
  parameters: PluginParameter<H>;
373
- }): Promise<ReturnType<ParseResult<H>> | null> | null;
374
- hookForPluginSync<H extends PluginLifecycleHooks>({ pluginName, hookName, parameters, }: {
375
- pluginName: string;
261
+ }): Promise<Array<ReturnType<ParseResult<H>> | null>> | null;
262
+ hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
263
+ pluginKey: KubbPlugin['key'];
376
264
  hookName: H;
377
265
  parameters: PluginParameter<H>;
378
- }): ReturnType<ParseResult<H>> | null;
266
+ }): Array<ReturnType<ParseResult<H>>> | null;
379
267
  /**
380
268
  * Chains, first non-null result stops and returns
381
269
  */
@@ -414,32 +302,17 @@ declare class PluginManager {
414
302
  hookName: H;
415
303
  parameters?: PluginParameter<H>;
416
304
  }): Promise<void>;
417
- getPlugin(hookName: keyof PluginLifecycle, pluginName: string): KubbPlugin;
305
+ getPluginsByKey(hookName: keyof PluginLifecycle, pluginKey: KubbPlugin['key']): KubbPlugin[];
306
+ 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;
307
+ static get hooks(): readonly ["validate", "buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
418
308
  }
419
309
 
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 {
310
+ interface Cache<TStore extends object = object> {
311
+ delete(id: keyof TStore): boolean;
312
+ get(id: keyof TStore): TStore[keyof TStore] | null;
313
+ has(id: keyof TStore): boolean;
314
+ set(id: keyof TStore, value: unknown): void;
441
315
  }
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
316
 
444
317
  /**
445
318
  * Config used in `kubb.config.js`
@@ -461,7 +334,7 @@ type KubbUserConfig = Omit<KubbConfig, 'root' | 'plugins'> & {
461
334
  * Example: ['@kubb/swagger', { output: false }]
462
335
  * Or: createSwagger({ output: false })
463
336
  */
464
- plugins?: Array<KubbPlugin> | Array<KubbJSONPlugins> | KubbObjectPlugins;
337
+ plugins?: Array<Omit<KubbUserPlugin, 'api'> | KubbUnionPlugins | [name: string, options: object]>;
465
338
  };
466
339
  type InputPath = {
467
340
  /**
@@ -479,14 +352,18 @@ type Input = InputPath | InputData;
479
352
  /**
480
353
  * @private
481
354
  */
482
- type KubbConfig = {
355
+ type KubbConfig<TInput = Input> = {
356
+ /**
357
+ * Optional config name to show in CLI output
358
+ */
359
+ name?: string;
483
360
  /**
484
361
  * Project root directory. Can be an absolute path, or a path relative from
485
362
  * the location of the config file itself.
486
363
  * @default process.cwd()
487
364
  */
488
365
  root: string;
489
- input: Input;
366
+ input: TInput;
490
367
  output: {
491
368
  /**
492
369
  * Path to be used to export all generated files.
@@ -547,40 +424,50 @@ type BuildOutput = {
547
424
  pluginManager: PluginManager;
548
425
  };
549
426
  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
- };
427
+ type KubbUnionPlugins = PluginUnion;
428
+ type KubbObjectPlugin = keyof OptionsPlugins;
429
+ type GetPluginFactoryOptions<TPlugin extends KubbUserPlugin> = TPlugin extends KubbUserPlugin<infer X> ? X : never;
555
430
  type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
556
431
  /**
557
432
  * Unique name used for the plugin
558
433
  * @example @kubb/typescript
559
434
  */
560
- name: PluginFactoryOptions['name'];
435
+ name: TOptions['name'];
436
+ /**
437
+ * Internal key used when a developer uses more than one of the same plugin
438
+ * @private
439
+ */
440
+ key?: TOptions['key'];
561
441
  /**
562
442
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
563
443
  */
564
444
  options: TOptions['options'] extends never ? undefined : TOptions['options'];
445
+ } & Partial<PluginLifecycle<TOptions>> & (TOptions['api'] extends never ? {
446
+ api?: never;
447
+ } : {
448
+ api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext, 'addFile'>) => TOptions['api'];
449
+ }) & (TOptions['kind'] extends never ? {
450
+ kind?: never;
451
+ } : {
565
452
  /**
566
453
  * Kind/type for the plugin
567
454
  * Type 'schema' can be used for JSON schema's, TypeScript types, ...
568
455
  * Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
569
456
  * @default undefined
570
457
  */
571
- kind?: KubbPluginKind;
572
- } & Partial<PluginLifecycle<TOptions>> & (TOptions['api'] extends never ? {
573
- api?: never;
574
- } : {
575
- api: (this: Omit<PluginContext, 'addFile'>) => TOptions['api'];
458
+ kind: TOptions['kind'];
576
459
  });
577
460
  type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
578
461
  /**
579
462
  * Unique name used for the plugin
580
463
  * @example @kubb/typescript
581
464
  */
582
- name: PluginFactoryOptions['name'];
583
- key?: [kind: KubbPluginKind | undefined, name: PluginFactoryOptions['name'], identifier: string];
465
+ name: TOptions['name'];
466
+ /**
467
+ * Internal key used when a developer uses more than one of the same plugin
468
+ * @private
469
+ */
470
+ key: TOptions['key'];
584
471
  /**
585
472
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
586
473
  */
@@ -597,8 +484,13 @@ type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
597
484
  } : {
598
485
  api: TOptions['api'];
599
486
  });
600
- type PluginFactoryOptions<Name = string, Options = unknown | never, Nested extends boolean = false, API = unknown | never, resolvePathOptions = Record<string, unknown>> = {
487
+ type PluginFactoryOptions<Name = string, Kind extends KubbPluginKind = KubbPluginKind | never, Options = unknown | never, Nested extends boolean = false, API = unknown | never, resolvePathOptions = Record<string, unknown>> = {
601
488
  name: Name;
489
+ kind: Kind;
490
+ /**
491
+ * Same like `QueryKey` in `@tanstack/react-query`
492
+ */
493
+ key: [kind: Kind | undefined, name: Name, identifier?: string | number];
602
494
  options: Options;
603
495
  nested: Nested;
604
496
  api: API;
@@ -643,7 +535,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
643
535
  * Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
644
536
  * @type hookParallel
645
537
  */
646
- writeFile?: (this: Omit<PluginContext, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<void>;
538
+ writeFile?: (this: Omit<PluginContext, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<string | void>;
647
539
  /**
648
540
  * End of the plugin lifecycle.
649
541
  * @type hookParallel
@@ -651,13 +543,10 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
651
543
  buildEnd?: (this: PluginContext) => PossiblePromise<void>;
652
544
  };
653
545
  type PluginLifecycleHooks = keyof PluginLifecycle;
546
+ type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
654
547
  type PluginCache = Record<string, [number, unknown]>;
655
548
  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;
549
+ pluginKey?: KubbPlugin['key'];
661
550
  baseName: string;
662
551
  directory?: string | undefined;
663
552
  /**
@@ -667,11 +556,7 @@ type ResolvePathParams<TOptions = Record<string, unknown>> = {
667
556
  };
668
557
  type ResolveNameParams = {
669
558
  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;
559
+ pluginKey?: KubbPlugin['key'];
675
560
  type?: 'file' | 'function';
676
561
  };
677
562
  type PluginContext<TOptions = Record<string, unknown>> = {
@@ -683,22 +568,51 @@ type PluginContext<TOptions = Record<string, unknown>> = {
683
568
  resolvePath: (params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
684
569
  resolveName: (params: ResolveNameParams) => string;
685
570
  logger: Logger;
571
+ /**
572
+ * All plugins
573
+ */
686
574
  plugins: KubbPlugin[];
575
+ /**
576
+ * Current plugin
577
+ */
578
+ plugin: KubbPlugin;
687
579
  };
688
580
  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
581
  type AppMeta = {
696
582
  pluginManager: PluginManager;
697
583
  };
698
584
  type Prettify<T> = {
699
585
  [K in keyof T]: T[K];
700
586
  } & {};
587
+ /**
588
+ * TODO move to @kubb/types
589
+ * @deprecated
590
+ */
701
591
  type PossiblePromise<T> = Promise<T> | T;
592
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
593
+ type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never;
594
+ type Push<T extends any[], V> = [...T, V];
595
+ type TuplifyUnion<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<TuplifyUnion<Exclude<T, L>>, L>;
596
+ /**
597
+ * TODO move to @kubb/types
598
+ * @deprecated
599
+ */
600
+ 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;
601
+ /**
602
+ * TODO move to @kubb/types
603
+ * @deprecated
604
+ */
605
+ type TupleToUnion<T> = T extends Array<infer ITEMS> ? ITEMS : never;
606
+ /**
607
+ * TODO move to @kubb/types
608
+ * @deprecated
609
+ */
610
+ type ArrayWithLength<T extends number, U extends any[] = []> = U['length'] extends T ? U : ArrayWithLength<T, [true, ...U]>;
611
+ /**
612
+ * TODO move to @kubb/types
613
+ * @deprecated
614
+ */
615
+ type GreaterThan<T extends number, U extends number> = ArrayWithLength<U> extends [...ArrayWithLength<T>, ...infer _] ? false : true;
702
616
 
703
617
  type BuildOptions = {
704
618
  config: PluginContext['config'];
@@ -706,7 +620,6 @@ type BuildOptions = {
706
620
  * @default Logger without the spinner
707
621
  */
708
622
  logger?: Logger;
709
- logLevel?: LogLevel;
710
623
  };
711
624
  declare function build(options: BuildOptions): Promise<BuildOutput>;
712
625
 
@@ -715,9 +628,10 @@ declare function build(options: BuildOptions): Promise<BuildOutput>;
715
628
  * accepts a direct {@link KubbConfig} object, or a function that returns it.
716
629
  * The function receives a {@link ConfigEnv} object that exposes two properties:
717
630
  */
718
- declare function defineConfig(options: PossiblePromise<KubbUserConfig> | ((
631
+ declare function defineConfig(options: PossiblePromise<KubbUserConfig | Array<KubbUserConfig>> | ((
719
632
  /** The options derived from the CLI flags */
720
- cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig>)): typeof options;
633
+ cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig | Array<KubbUserConfig>>)): typeof options;
634
+ declare function isInputPath(result: KubbConfig | undefined): result is KubbConfig<InputPath>;
721
635
 
722
636
  /**
723
637
  * Abstract class that contains the building blocks for plugins to create their own Generator
@@ -732,6 +646,50 @@ declare abstract class Generator<TOptions = unknown, TContext = unknown> {
732
646
  abstract build(...params: unknown[]): unknown;
733
647
  }
734
648
 
649
+ type PackageJSON = {
650
+ dependencies?: Record<string, string>;
651
+ devDependencies?: Record<string, string>;
652
+ };
653
+ type DependencyName = string;
654
+ type DependencyVersion = string;
655
+ declare class PackageManager {
656
+ #private;
657
+ constructor(workspace?: string);
658
+ set workspace(workspace: string);
659
+ get workspace(): string | undefined;
660
+ normalizeDirectory(directory: string): string;
661
+ getLocation(path: string): string;
662
+ import(path: string): Promise<any | undefined>;
663
+ getPackageJSON(): Promise<PackageJSON | undefined>;
664
+ getPackageJSONSync(): PackageJSON | undefined;
665
+ static setVersion(dependency: DependencyName, version: DependencyVersion): void;
666
+ getVersion(dependency: DependencyName): Promise<DependencyVersion | undefined>;
667
+ getVersionSync(dependency: DependencyName): DependencyVersion | undefined;
668
+ isValid(dependency: DependencyName, version: DependencyVersion): Promise<boolean>;
669
+ isValidSync(dependency: DependencyName, version: DependencyVersion): boolean;
670
+ }
671
+
672
+ type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => KubbUserPlugin<T>;
673
+ declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
674
+ declare const pluginName = "core";
675
+
676
+ type PromiseFunc$1<T = unknown, T2 = never> = (state: T) => T2 extends never ? Promise<T> : Promise<T> | T2;
677
+ type ValueOfPromiseFuncArray<TInput extends Array<unknown>> = TInput extends Array<PromiseFunc$1<infer X, infer Y>> ? X | Y : never;
678
+ type SeqOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Array<Awaited<ValueOfPromiseFuncArray<TInput>>>;
679
+ type HookFirstOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue = unknown> = ValueOfPromiseFuncArray<TInput>;
680
+ type Strategy = 'seq' | 'first';
681
+ type StrategySwitch<TStrategy extends Strategy, TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = TStrategy extends 'first' ? HookFirstOutput<TInput, TValue> : TStrategy extends 'seq' ? SeqOutput<TInput, TValue> : never;
682
+
683
+ type PromiseFunc<T = unknown, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
684
+ type Options<TState = any> = {
685
+ nullCheck?: (state: TState) => boolean;
686
+ };
687
+ declare class PromiseManager<TState = any> {
688
+ #private;
689
+ constructor(options?: Options<TState>);
690
+ run<TInput extends Array<PromiseFunc<TValue, null>>, TValue, TStrategy extends Strategy, TOutput = StrategySwitch<TStrategy, TInput, TValue>>(strategy: TStrategy, promises: TInput): TOutput;
691
+ }
692
+
735
693
  /**
736
694
  * Abstract class that contains the building blocks for plugins to create their own SchemaGenerator
737
695
  */
@@ -739,19 +697,14 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
739
697
  abstract build(schema: TInput, name: string, description?: string): TOutput;
740
698
  }
741
699
 
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;
700
+ interface _Register {
701
+ }
702
+ type Plugins = _Register;
703
+ type OptionsPlugins = {
704
+ [K in keyof Plugins]: Plugins[K]['options'];
753
705
  };
754
- type CorePluginOptions = PluginFactoryOptions<'core', Options, false, PluginContext>;
755
- declare const pluginName: CorePluginOptions['name'];
706
+ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
707
+ type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
708
+ type Plugin = keyof Plugins;
756
709
 
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 };
710
+ 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 };