@kubb/core 1.15.0-canary.20231025T223729 → 1.15.0-canary.20231026T165002

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,43 +1,89 @@
1
1
  import { DirectoryTreeOptions } from 'directory-tree';
2
2
  import { Ora } from 'ora';
3
+ export { default as pc } from 'picocolors';
3
4
 
4
- declare function read(path: string): Promise<string>;
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>;
5
12
 
6
- declare function write(data: string, path: string): Promise<string | undefined>;
13
+ declare function clean(path: string): Promise<void>;
7
14
 
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;
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;
15
27
  };
16
-
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;
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;
24
48
  }
25
49
 
50
+ declare function getUniqueName(originalName: string, data: Record<string, number>): string;
51
+
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;
56
+ };
57
+
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;
76
+
26
77
  type QueueJob<T = unknown> = {
27
- (...args: unknown[]): Promise<T | void>;
78
+ (...args: unknown[]): Promise<T> | Promise<void>;
28
79
  };
29
80
  type RunOptions = {
30
81
  controller?: AbortController;
31
82
  name?: string;
32
83
  description?: string;
33
84
  };
34
- type Events$1 = {
35
- jobDone: [result: unknown];
36
- jobFailed: [error: Error];
37
- };
38
85
  declare class Queue {
39
86
  #private;
40
- readonly eventEmitter: EventEmitter<Events$1>;
41
87
  constructor(maxParallel: number, debug?: boolean);
42
88
  run<T>(job: QueueJob<T>, options?: RunOptions): Promise<T>;
43
89
  runSync<T>(job: QueueJob<T>, options?: RunOptions): void;
@@ -45,7 +91,14 @@ declare class Queue {
45
91
  get count(): number;
46
92
  }
47
93
 
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
+
48
98
  type BasePath<T extends string = string> = `${T}/`;
99
+ type CacheItem = KubbFile.ResolvedFile & {
100
+ cancel?: () => void;
101
+ };
49
102
  declare namespace KubbFile {
50
103
  type Import = {
51
104
  name: string | Array<string>;
@@ -66,15 +119,11 @@ declare namespace KubbFile {
66
119
  type Path = string;
67
120
  type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
68
121
  type OptionalPath = Path | undefined | null;
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;
122
+ type File<TMeta extends {
123
+ pluginName?: string;
124
+ } = {
125
+ pluginName?: string;
126
+ }, TBaseName extends BaseName = BaseName> = {
78
127
  /**
79
128
  * Name to be used to dynamicly create the baseName(based on input.path)
80
129
  * Based on UNIX basename
@@ -90,7 +139,6 @@ declare namespace KubbFile {
90
139
  exports?: Export[];
91
140
  /**
92
141
  * 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
94
142
  * @default `false`
95
143
  */
96
144
  override?: boolean;
@@ -99,67 +147,22 @@ declare namespace KubbFile {
99
147
  * This will override `process.env[key]` inside the `source`, see `getFileSource`.
100
148
  */
101
149
  env?: NodeJS.ProcessEnv;
102
- validate?: boolean;
103
150
  };
104
151
  type ResolvedFile = KubbFile.File & {
105
152
  /**
106
- * @default crypto.randomUUID()
153
+ * crypto.randomUUID()
107
154
  */
108
155
  id: UUID;
109
156
  };
110
157
  }
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
158
 
145
- declare class PluginError extends Error {
146
- pluginManager: PluginManager;
147
- cause: Error;
148
- constructor(message: string, options: {
149
- cause: Error;
150
- pluginManager: PluginManager;
151
- });
152
- }
153
- declare class ParallelPluginError extends Error {
154
- errors: PluginError[];
155
- pluginManager: PluginManager;
156
- constructor(message: string, options: {
157
- cause?: Error;
158
- errors: PluginError[];
159
- pluginManager: PluginManager;
160
- });
161
- findError<T extends Error = Error>(searchError: T | undefined): T | undefined;
162
- }
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
+
163
166
  declare class SummaryError extends Error {
164
167
  summary: string[];
165
168
  constructor(message: string, options: {
@@ -167,6 +170,82 @@ declare class SummaryError extends Error {
167
170
  summary?: string[];
168
171
  });
169
172
  }
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
+
170
249
  /**
171
250
  * Behaves as an Error to log a warning in the console(still stops the execution)
172
251
  */
@@ -175,28 +254,70 @@ declare class Warning extends Error {
175
254
  cause: Error;
176
255
  });
177
256
  }
178
- declare class ValidationPluginError extends Error {
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>;
179
277
  }
180
278
 
181
- declare const LogLevel: {
182
- readonly silent: "silent";
183
- readonly info: "info";
184
- readonly debug: "debug";
185
- };
186
- type LogLevel = keyof typeof LogLevel;
187
- type Logger = {
188
- /**
189
- * Optional config name to show in CLI output
190
- */
191
- name?: string;
192
- logLevel: LogLevel;
193
- log: (message: string | null) => void;
194
- error: (message: string | null) => void;
195
- info: (message: string | null) => void;
196
- warn: (message: string | null) => void;
197
- spinner?: Ora;
198
- logs: string[];
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>;
199
293
  };
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
+ }
200
321
 
201
322
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
202
323
  /**
@@ -204,9 +325,9 @@ type RequiredPluginLifecycle = Required<PluginLifecycle>;
204
325
  * @example Arg0<(a: string, b: number) => void> -> string
205
326
  */
206
327
  type Argument0<H extends keyof PluginLifecycle> = Parameters<RequiredPluginLifecycle[H]>[0];
207
- type Strategy$1 = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq';
328
+ type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq';
208
329
  type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
209
- strategy: Strategy$1;
330
+ strategy: Strategy;
210
331
  hookName: H;
211
332
  plugin: KubbPlugin;
212
333
  parameters?: unknown[] | undefined;
@@ -217,16 +338,13 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
217
338
  result: Result;
218
339
  plugin: KubbPlugin;
219
340
  };
341
+ type PluginParameter<H extends PluginLifecycleHooks> = Parameters<RequiredPluginLifecycle[H]>;
342
+
343
+ declare const hooks: [keyof PluginLifecycle<PluginFactoryOptions<string, unknown, false, unknown, Record<string, unknown>>>];
220
344
  type Options$1 = {
221
- logger: Logger;
222
- /**
223
- * Task for the FileManager
224
- */
345
+ debug?: boolean;
225
346
  task: QueueJob<KubbFile.ResolvedFile>;
226
- /**
227
- * Timeout between writes in the FileManager
228
- */
229
- writeTimeout?: number;
347
+ logger: Logger;
230
348
  };
231
349
  type Events = {
232
350
  execute: [executer: Executer];
@@ -248,16 +366,16 @@ declare class PluginManager {
248
366
  /**
249
367
  * Run only hook for a specific plugin name
250
368
  */
251
- hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
252
- pluginKey: KubbPlugin['key'];
369
+ hookForPlugin<H extends PluginLifecycleHooks>({ pluginName, hookName, parameters, }: {
370
+ pluginName: string;
253
371
  hookName: H;
254
372
  parameters: PluginParameter<H>;
255
- }): Promise<Array<ReturnType<ParseResult<H>> | null>> | null;
256
- hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
257
- pluginKey: KubbPlugin['key'];
373
+ }): Promise<ReturnType<ParseResult<H>> | null> | null;
374
+ hookForPluginSync<H extends PluginLifecycleHooks>({ pluginName, hookName, parameters, }: {
375
+ pluginName: string;
258
376
  hookName: H;
259
377
  parameters: PluginParameter<H>;
260
- }): Array<ReturnType<ParseResult<H>>> | null;
378
+ }): ReturnType<ParseResult<H>> | null;
261
379
  /**
262
380
  * Chains, first non-null result stops and returns
263
381
  */
@@ -287,7 +405,7 @@ declare class PluginManager {
287
405
  hookReduceArg0<H extends PluginLifecycleHooks>({ hookName, parameters, reduce, }: {
288
406
  hookName: H;
289
407
  parameters: PluginParameter<H>;
290
- reduce: (reduction: Argument0<H>, result: ReturnType<ParseResult<H>>, plugin: KubbPlugin) => PossiblePromise$1<Argument0<H> | null>;
408
+ reduce: (reduction: Argument0<H>, result: ReturnType<ParseResult<H>>, plugin: KubbPlugin) => PossiblePromise<Argument0<H> | null>;
291
409
  }): Promise<Argument0<H>>;
292
410
  /**
293
411
  * Chains plugins
@@ -296,18 +414,33 @@ declare class PluginManager {
296
414
  hookName: H;
297
415
  parameters?: PluginParameter<H>;
298
416
  }): Promise<void>;
299
- getPluginsByKey(hookName: keyof PluginLifecycle, pluginKey: KubbPlugin['key']): KubbPlugin[];
300
- 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;
301
- static get hooks(): readonly ["validate", "buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
417
+ getPlugin(hookName: keyof PluginLifecycle, pluginName: string): KubbPlugin;
302
418
  }
303
419
 
304
- interface Cache<TStore extends object = object> {
305
- delete(id: keyof TStore): boolean;
306
- get(id: keyof TStore): TStore[keyof TStore] | null;
307
- has(id: keyof TStore): boolean;
308
- set(id: keyof TStore, value: unknown): void;
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;
309
438
  }
310
439
 
440
+ declare class ValidationPluginError extends Error {
441
+ }
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
+
311
444
  /**
312
445
  * Config used in `kubb.config.js`
313
446
  *
@@ -328,7 +461,7 @@ type KubbUserConfig = Omit<KubbConfig, 'root' | 'plugins'> & {
328
461
  * Example: ['@kubb/swagger', { output: false }]
329
462
  * Or: createSwagger({ output: false })
330
463
  */
331
- plugins?: Array<Omit<KubbUserPlugin, 'api'> | KubbUnionPlugins | [name: string, options: object]>;
464
+ plugins?: Array<KubbPlugin> | Array<KubbJSONPlugins> | KubbObjectPlugins;
332
465
  };
333
466
  type InputPath = {
334
467
  /**
@@ -346,18 +479,14 @@ type Input = InputPath | InputData;
346
479
  /**
347
480
  * @private
348
481
  */
349
- type KubbConfig<TInput = Input> = {
350
- /**
351
- * Optional config name to show in CLI output
352
- */
353
- name?: string;
482
+ type KubbConfig = {
354
483
  /**
355
484
  * Project root directory. Can be an absolute path, or a path relative from
356
485
  * the location of the config file itself.
357
486
  * @default process.cwd()
358
487
  */
359
488
  root: string;
360
- input: TInput;
489
+ input: Input;
361
490
  output: {
362
491
  /**
363
492
  * Path to be used to export all generated files.
@@ -418,50 +547,40 @@ type BuildOutput = {
418
547
  pluginManager: PluginManager;
419
548
  };
420
549
  type KubbPluginKind = 'schema' | 'controller';
421
- type KubbUnionPlugins = PluginUnion;
422
- type KubbObjectPlugin = keyof OptionsPlugins;
423
- type GetPluginFactoryOptions<TPlugin extends KubbUserPlugin> = TPlugin extends KubbUserPlugin<infer X> ? X : never;
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
+ };
424
555
  type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
425
556
  /**
426
557
  * Unique name used for the plugin
427
558
  * @example @kubb/typescript
428
559
  */
429
- name: TOptions['name'];
430
- /**
431
- * Internal key used when a developer uses more than one of the same plugin
432
- * @private
433
- */
434
- key?: TOptions['key'];
560
+ name: PluginFactoryOptions['name'];
435
561
  /**
436
562
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
437
563
  */
438
564
  options: TOptions['options'] extends never ? undefined : TOptions['options'];
439
- } & Partial<PluginLifecycle<TOptions>> & (TOptions['api'] extends never ? {
440
- api?: never;
441
- } : {
442
- api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext, 'addFile'>) => TOptions['api'];
443
- }) & (TOptions['kind'] extends never ? {
444
- kind?: never;
445
- } : {
446
565
  /**
447
566
  * Kind/type for the plugin
448
567
  * Type 'schema' can be used for JSON schema's, TypeScript types, ...
449
568
  * Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
450
569
  * @default undefined
451
570
  */
452
- kind: TOptions['kind'];
571
+ kind?: KubbPluginKind;
572
+ } & Partial<PluginLifecycle<TOptions>> & (TOptions['api'] extends never ? {
573
+ api?: never;
574
+ } : {
575
+ api: (this: Omit<PluginContext, 'addFile'>) => TOptions['api'];
453
576
  });
454
577
  type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
455
578
  /**
456
579
  * Unique name used for the plugin
457
580
  * @example @kubb/typescript
458
581
  */
459
- name: TOptions['name'];
460
- /**
461
- * Internal key used when a developer uses more than one of the same plugin
462
- * @private
463
- */
464
- key: TOptions['key'];
582
+ name: PluginFactoryOptions['name'];
583
+ key?: [kind: KubbPluginKind | undefined, name: PluginFactoryOptions['name'], identifier: string];
465
584
  /**
466
585
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
467
586
  */
@@ -478,13 +597,8 @@ type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
478
597
  } : {
479
598
  api: TOptions['api'];
480
599
  });
481
- type PluginFactoryOptions<Name = string, Kind extends KubbPluginKind = KubbPluginKind | never, Options = unknown | never, Nested extends boolean = false, API = unknown | never, resolvePathOptions = Record<string, unknown>> = {
600
+ type PluginFactoryOptions<Name = string, Options = unknown | never, Nested extends boolean = false, API = unknown | never, resolvePathOptions = Record<string, unknown>> = {
482
601
  name: Name;
483
- kind: Kind;
484
- /**
485
- * Same like `QueryKey` in `@tanstack/react-query`
486
- */
487
- key: [kind: Kind | undefined, name: Name, identifier?: string | number];
488
602
  options: Options;
489
603
  nested: Nested;
490
604
  api: API;
@@ -495,12 +609,12 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
495
609
  * Valdiate all plugins to see if their depended plugins are installed and configured.
496
610
  * @type hookParallel
497
611
  */
498
- validate?: (this: Omit<PluginContext, 'addFile'>, plugins: NonNullable<KubbConfig['plugins']>) => PossiblePromise$1<true>;
612
+ validate?: (this: Omit<PluginContext, 'addFile'>, plugins: NonNullable<KubbConfig['plugins']>) => PossiblePromise<true>;
499
613
  /**
500
614
  * Start of the lifecycle of a plugin.
501
615
  * @type hookParallel
502
616
  */
503
- buildStart?: (this: PluginContext, kubbConfig: KubbConfig) => PossiblePromise$1<void>;
617
+ buildStart?: (this: PluginContext, kubbConfig: KubbConfig) => PossiblePromise<void>;
504
618
  /**
505
619
  * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
506
620
  * Options can als be included.
@@ -519,28 +633,31 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
519
633
  * Makes it possible to run async logic to override the path defined previously by `resolvePath`.
520
634
  * @type hookFirst
521
635
  */
522
- load?: (this: Omit<PluginContext, 'addFile'>, path: KubbFile.Path) => PossiblePromise$1<TransformResult | null>;
636
+ load?: (this: Omit<PluginContext, 'addFile'>, path: KubbFile.Path) => PossiblePromise<TransformResult | null>;
523
637
  /**
524
638
  * Transform the source-code.
525
639
  * @type hookReduceArg0
526
640
  */
527
- transform?: (this: Omit<PluginContext, 'addFile'>, source: string, path: KubbFile.Path) => PossiblePromise$1<TransformResult>;
641
+ transform?: (this: Omit<PluginContext, 'addFile'>, source: string, path: KubbFile.Path) => PossiblePromise<TransformResult>;
528
642
  /**
529
643
  * Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
530
644
  * @type hookParallel
531
645
  */
532
- writeFile?: (this: Omit<PluginContext, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise$1<string | void>;
646
+ writeFile?: (this: Omit<PluginContext, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<void>;
533
647
  /**
534
648
  * End of the plugin lifecycle.
535
649
  * @type hookParallel
536
650
  */
537
- buildEnd?: (this: PluginContext) => PossiblePromise$1<void>;
651
+ buildEnd?: (this: PluginContext) => PossiblePromise<void>;
538
652
  };
539
653
  type PluginLifecycleHooks = keyof PluginLifecycle;
540
- type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
541
654
  type PluginCache = Record<string, [number, unknown]>;
542
655
  type ResolvePathParams<TOptions = Record<string, unknown>> = {
543
- pluginKey?: KubbPlugin['key'];
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;
544
661
  baseName: string;
545
662
  directory?: string | undefined;
546
663
  /**
@@ -550,7 +667,11 @@ type ResolvePathParams<TOptions = Record<string, unknown>> = {
550
667
  };
551
668
  type ResolveNameParams = {
552
669
  name: string;
553
- pluginKey?: KubbPlugin['key'];
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;
554
675
  type?: 'file' | 'function';
555
676
  };
556
677
  type PluginContext<TOptions = Record<string, unknown>> = {
@@ -562,51 +683,22 @@ type PluginContext<TOptions = Record<string, unknown>> = {
562
683
  resolvePath: (params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
563
684
  resolveName: (params: ResolveNameParams) => string;
564
685
  logger: Logger;
565
- /**
566
- * All plugins
567
- */
568
686
  plugins: KubbPlugin[];
569
- /**
570
- * Current plugin
571
- */
572
- plugin: KubbPlugin;
573
687
  };
574
688
  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;
575
695
  type AppMeta = {
576
696
  pluginManager: PluginManager;
577
697
  };
578
698
  type Prettify<T> = {
579
699
  [K in keyof T]: T[K];
580
700
  } & {};
581
- /**
582
- * TODO move to @kubb/types
583
- * @deprecated
584
- */
585
- type PossiblePromise$1<T> = Promise<T> | T;
586
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
587
- type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never;
588
- type Push<T extends any[], V> = [...T, V];
589
- type TuplifyUnion<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<TuplifyUnion<Exclude<T, L>>, L>;
590
- /**
591
- * TODO move to @kubb/types
592
- * @deprecated
593
- */
594
- 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;
595
- /**
596
- * TODO move to @kubb/types
597
- * @deprecated
598
- */
599
- type TupleToUnion<T> = T extends Array<infer ITEMS> ? ITEMS : never;
600
- /**
601
- * TODO move to @kubb/types
602
- * @deprecated
603
- */
604
- type ArrayWithLength<T extends number, U extends any[] = []> = U['length'] extends T ? U : ArrayWithLength<T, [true, ...U]>;
605
- /**
606
- * TODO move to @kubb/types
607
- * @deprecated
608
- */
609
- type GreaterThan<T extends number, U extends number> = ArrayWithLength<U> extends [...ArrayWithLength<T>, ...infer _] ? false : true;
701
+ type PossiblePromise<T> = Promise<T> | T;
610
702
 
611
703
  type BuildOptions = {
612
704
  config: PluginContext['config'];
@@ -614,6 +706,7 @@ type BuildOptions = {
614
706
  * @default Logger without the spinner
615
707
  */
616
708
  logger?: Logger;
709
+ logLevel?: LogLevel;
617
710
  };
618
711
  declare function build(options: BuildOptions): Promise<BuildOutput>;
619
712
 
@@ -622,10 +715,9 @@ declare function build(options: BuildOptions): Promise<BuildOutput>;
622
715
  * accepts a direct {@link KubbConfig} object, or a function that returns it.
623
716
  * The function receives a {@link ConfigEnv} object that exposes two properties:
624
717
  */
625
- declare function defineConfig(options: PossiblePromise$1<KubbUserConfig | Array<KubbUserConfig>> | ((
718
+ declare function defineConfig(options: PossiblePromise<KubbUserConfig> | ((
626
719
  /** The options derived from the CLI flags */
627
- cliOptions: CLIOptions) => PossiblePromise$1<KubbUserConfig | Array<KubbUserConfig>>)): typeof options;
628
- declare function isInputPath(result: KubbConfig | undefined): result is KubbConfig<InputPath>;
720
+ cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig>)): typeof options;
629
721
 
630
722
  /**
631
723
  * Abstract class that contains the building blocks for plugins to create their own Generator
@@ -640,49 +732,6 @@ declare abstract class Generator<TOptions = unknown, TContext = unknown> {
640
732
  abstract build(...params: unknown[]): unknown;
641
733
  }
642
734
 
643
- type PackageJSON = {
644
- dependencies?: Record<string, string>;
645
- devDependencies?: Record<string, string>;
646
- };
647
- type DependencyName = string;
648
- type DependencyVersion = string;
649
- declare class PackageManager {
650
- #private;
651
- constructor(workspace?: string);
652
- set workspace(workspace: string);
653
- get workspace(): string | undefined;
654
- normalizeDirectory(directory: string): string;
655
- getLocation(path: string): string;
656
- import(path: string): Promise<any | undefined>;
657
- getPackageJSON(): Promise<PackageJSON | undefined>;
658
- getPackageJSONSync(): PackageJSON | undefined;
659
- static setVersion(dependency: DependencyName, version: DependencyVersion): void;
660
- getVersion(dependency: DependencyName): Promise<DependencyVersion | undefined>;
661
- getVersionSync(dependency: DependencyName): DependencyVersion | undefined;
662
- isValid(dependency: DependencyName, version: DependencyVersion): Promise<boolean>;
663
- isValidSync(dependency: DependencyName, version: DependencyVersion): boolean;
664
- }
665
-
666
- type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => KubbUserPlugin<T>;
667
- declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
668
- declare const pluginName = "core";
669
-
670
- type PossiblePromise<T> = Promise<T> | T;
671
- type PromiseFunc<T, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
672
- type SeqOutput<TInput extends Array<PromiseFunc<TPromise, null>>, TPromise = unknown> = ReturnType<NonNullable<TInput[number]>>;
673
- type Options = {};
674
- type Strategy = 'seq';
675
- declare class PromiseManager {
676
- #private;
677
- constructor(options?: Options);
678
- run<TInput extends Array<PromiseFunc<TPromise, null>>, TPromise = unknown, TOutput = SeqOutput<TInput, TPromise>>(strategy: Strategy, promises: TInput): TOutput;
679
- }
680
- declare function isPromise<T>(result: PossiblePromise<T>): result is Promise<T>;
681
- declare function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T>;
682
- declare function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & {
683
- reason: T;
684
- };
685
-
686
735
  /**
687
736
  * Abstract class that contains the building blocks for plugins to create their own SchemaGenerator
688
737
  */
@@ -690,14 +739,19 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
690
739
  abstract build(schema: TInput, name: string, description?: string): TOutput;
691
740
  }
692
741
 
693
- interface _Register {
694
- }
695
- type Plugins = _Register;
696
- type OptionsPlugins = {
697
- [K in keyof Plugins]: Plugins[K]['options'];
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;
698
753
  };
699
- type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
700
- type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
701
- type Plugin = keyof Plugins;
754
+ type CorePluginOptions = PluginFactoryOptions<'core', Options, false, PluginContext>;
755
+ declare const pluginName: CorePluginOptions['name'];
702
756
 
703
- 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$1 as PossiblePromise, Prettify, PromiseManager, ResolveNameParams, ResolvePathParams, SchemaGenerator, SummaryError, TransformResult, TupleToUnion, ValidationPluginError, Warning, _Register, build, createPlugin, build as default, defineConfig, isInputPath, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, pluginName as name, pluginName };
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 };