@kubb/core 1.15.0-canary.20231027T173208 → 1.15.0-canary.20231027T185539

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,69 +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
- 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>;
146
158
 
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
- }
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
+
165
166
  declare class SummaryError extends Error {
166
167
  summary: string[];
167
168
  constructor(message: string, options: {
@@ -169,6 +170,82 @@ declare class SummaryError extends Error {
169
170
  summary?: string[];
170
171
  });
171
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
+
172
249
  /**
173
250
  * Behaves as an Error to log a warning in the console(still stops the execution)
174
251
  */
@@ -177,28 +254,70 @@ declare class Warning extends Error {
177
254
  cause: Error;
178
255
  });
179
256
  }
180
- 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>;
181
277
  }
182
278
 
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[];
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>;
201
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
+ }
202
321
 
203
322
  type RequiredPluginLifecycle = Required<PluginLifecycle>;
204
323
  /**
@@ -206,9 +325,9 @@ type RequiredPluginLifecycle = Required<PluginLifecycle>;
206
325
  * @example Arg0<(a: string, b: number) => void> -> string
207
326
  */
208
327
  type Argument0<H extends keyof PluginLifecycle> = Parameters<RequiredPluginLifecycle[H]>[0];
209
- type Strategy$1 = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq';
328
+ type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq';
210
329
  type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
211
- strategy: Strategy$1;
330
+ strategy: Strategy;
212
331
  hookName: H;
213
332
  plugin: KubbPlugin;
214
333
  parameters?: unknown[] | undefined;
@@ -219,16 +338,13 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
219
338
  result: Result;
220
339
  plugin: KubbPlugin;
221
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>>>];
222
344
  type Options$1 = {
223
- logger: Logger;
224
- /**
225
- * Task for the FileManager
226
- */
345
+ debug?: boolean;
227
346
  task: QueueJob<KubbFile.ResolvedFile>;
228
- /**
229
- * Timeout between writes in the FileManager
230
- */
231
- writeTimeout?: number;
347
+ logger: Logger;
232
348
  };
233
349
  type Events = {
234
350
  execute: [executer: Executer];
@@ -250,16 +366,16 @@ declare class PluginManager {
250
366
  /**
251
367
  * Run only hook for a specific plugin name
252
368
  */
253
- hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
254
- pluginKey: KubbPlugin['key'];
369
+ hookForPlugin<H extends PluginLifecycleHooks>({ pluginName, hookName, parameters, }: {
370
+ pluginName: string;
255
371
  hookName: H;
256
372
  parameters: PluginParameter<H>;
257
- }): Promise<Array<ReturnType<ParseResult<H>> | null>> | null;
258
- hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
259
- pluginKey: KubbPlugin['key'];
373
+ }): Promise<ReturnType<ParseResult<H>> | null> | null;
374
+ hookForPluginSync<H extends PluginLifecycleHooks>({ pluginName, hookName, parameters, }: {
375
+ pluginName: string;
260
376
  hookName: H;
261
377
  parameters: PluginParameter<H>;
262
- }): Array<ReturnType<ParseResult<H>>> | null;
378
+ }): ReturnType<ParseResult<H>> | null;
263
379
  /**
264
380
  * Chains, first non-null result stops and returns
265
381
  */
@@ -298,18 +414,33 @@ declare class PluginManager {
298
414
  hookName: H;
299
415
  parameters?: PluginParameter<H>;
300
416
  }): Promise<void>;
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"];
417
+ getPlugin(hookName: keyof PluginLifecycle, pluginName: string): KubbPlugin;
304
418
  }
305
419
 
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;
420
+ declare class PluginError extends Error {
421
+ pluginManager: PluginManager;
422
+ cause: Error;
423
+ constructor(message: string, options: {
424
+ cause: Error;
425
+ pluginManager: PluginManager;
426
+ });
311
427
  }
312
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 {
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
+
313
444
  /**
314
445
  * Config used in `kubb.config.js`
315
446
  *
@@ -330,7 +461,7 @@ type KubbUserConfig = Omit<KubbConfig, 'root' | 'plugins'> & {
330
461
  * Example: ['@kubb/swagger', { output: false }]
331
462
  * Or: createSwagger({ output: false })
332
463
  */
333
- plugins?: Array<Omit<KubbUserPlugin, 'api'> | KubbUnionPlugins | [name: string, options: object]>;
464
+ plugins?: Array<KubbPlugin> | Array<KubbJSONPlugins> | KubbObjectPlugins;
334
465
  };
335
466
  type InputPath = {
336
467
  /**
@@ -348,18 +479,14 @@ type Input = InputPath | InputData;
348
479
  /**
349
480
  * @private
350
481
  */
351
- type KubbConfig<TInput = Input> = {
352
- /**
353
- * Optional config name to show in CLI output
354
- */
355
- name?: string;
482
+ type KubbConfig = {
356
483
  /**
357
484
  * Project root directory. Can be an absolute path, or a path relative from
358
485
  * the location of the config file itself.
359
486
  * @default process.cwd()
360
487
  */
361
488
  root: string;
362
- input: TInput;
489
+ input: Input;
363
490
  output: {
364
491
  /**
365
492
  * Path to be used to export all generated files.
@@ -420,50 +547,40 @@ type BuildOutput = {
420
547
  pluginManager: PluginManager;
421
548
  };
422
549
  type KubbPluginKind = 'schema' | 'controller';
423
- type KubbUnionPlugins = PluginUnion;
424
- type KubbObjectPlugin = keyof OptionsPlugins;
425
- 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
+ };
426
555
  type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
427
556
  /**
428
557
  * Unique name used for the plugin
429
558
  * @example @kubb/typescript
430
559
  */
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'];
560
+ name: PluginFactoryOptions['name'];
437
561
  /**
438
562
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
439
563
  */
440
564
  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
- } : {
448
565
  /**
449
566
  * Kind/type for the plugin
450
567
  * Type 'schema' can be used for JSON schema's, TypeScript types, ...
451
568
  * Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
452
569
  * @default undefined
453
570
  */
454
- 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'];
455
576
  });
456
577
  type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
457
578
  /**
458
579
  * Unique name used for the plugin
459
580
  * @example @kubb/typescript
460
581
  */
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'];
582
+ name: PluginFactoryOptions['name'];
583
+ key?: [kind: KubbPluginKind | undefined, name: PluginFactoryOptions['name'], identifier: string];
467
584
  /**
468
585
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
469
586
  */
@@ -480,13 +597,8 @@ type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
480
597
  } : {
481
598
  api: TOptions['api'];
482
599
  });
483
- 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>> = {
484
601
  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];
490
602
  options: Options;
491
603
  nested: Nested;
492
604
  api: API;
@@ -531,7 +643,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
531
643
  * Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
532
644
  * @type hookParallel
533
645
  */
534
- writeFile?: (this: Omit<PluginContext, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<string | void>;
646
+ writeFile?: (this: Omit<PluginContext, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<void>;
535
647
  /**
536
648
  * End of the plugin lifecycle.
537
649
  * @type hookParallel
@@ -539,10 +651,13 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
539
651
  buildEnd?: (this: PluginContext) => PossiblePromise<void>;
540
652
  };
541
653
  type PluginLifecycleHooks = keyof PluginLifecycle;
542
- type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
543
654
  type PluginCache = Record<string, [number, unknown]>;
544
655
  type ResolvePathParams<TOptions = Record<string, unknown>> = {
545
- 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;
546
661
  baseName: string;
547
662
  directory?: string | undefined;
548
663
  /**
@@ -552,7 +667,11 @@ type ResolvePathParams<TOptions = Record<string, unknown>> = {
552
667
  };
553
668
  type ResolveNameParams = {
554
669
  name: string;
555
- 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;
556
675
  type?: 'file' | 'function';
557
676
  };
558
677
  type PluginContext<TOptions = Record<string, unknown>> = {
@@ -564,51 +683,22 @@ type PluginContext<TOptions = Record<string, unknown>> = {
564
683
  resolvePath: (params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
565
684
  resolveName: (params: ResolveNameParams) => string;
566
685
  logger: Logger;
567
- /**
568
- * All plugins
569
- */
570
686
  plugins: KubbPlugin[];
571
- /**
572
- * Current plugin
573
- */
574
- plugin: KubbPlugin;
575
687
  };
576
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;
577
695
  type AppMeta = {
578
696
  pluginManager: PluginManager;
579
697
  };
580
698
  type Prettify<T> = {
581
699
  [K in keyof T]: T[K];
582
700
  } & {};
583
- /**
584
- * TODO move to @kubb/types
585
- * @deprecated
586
- */
587
701
  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;
612
702
 
613
703
  type BuildOptions = {
614
704
  config: PluginContext['config'];
@@ -616,6 +706,7 @@ type BuildOptions = {
616
706
  * @default Logger without the spinner
617
707
  */
618
708
  logger?: Logger;
709
+ logLevel?: LogLevel;
619
710
  };
620
711
  declare function build(options: BuildOptions): Promise<BuildOutput>;
621
712
 
@@ -624,10 +715,9 @@ declare function build(options: BuildOptions): Promise<BuildOutput>;
624
715
  * accepts a direct {@link KubbConfig} object, or a function that returns it.
625
716
  * The function receives a {@link ConfigEnv} object that exposes two properties:
626
717
  */
627
- declare function defineConfig(options: PossiblePromise<KubbUserConfig | Array<KubbUserConfig>> | ((
718
+ declare function defineConfig(options: PossiblePromise<KubbUserConfig> | ((
628
719
  /** The options derived from the CLI flags */
629
- cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig | Array<KubbUserConfig>>)): typeof options;
630
- declare function isInputPath(result: KubbConfig | undefined): result is KubbConfig<InputPath>;
720
+ cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig>)): typeof options;
631
721
 
632
722
  /**
633
723
  * Abstract class that contains the building blocks for plugins to create their own Generator
@@ -642,43 +732,6 @@ declare abstract class Generator<TOptions = unknown, TContext = unknown> {
642
732
  abstract build(...params: unknown[]): unknown;
643
733
  }
644
734
 
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
-
682
735
  /**
683
736
  * Abstract class that contains the building blocks for plugins to create their own SchemaGenerator
684
737
  */
@@ -686,14 +739,19 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
686
739
  abstract build(schema: TInput, name: string, description?: string): TOutput;
687
740
  }
688
741
 
689
- interface _Register {
690
- }
691
- type Plugins = _Register;
692
- type OptionsPlugins = {
693
- [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;
694
753
  };
695
- type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
696
- type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
697
- type Plugin = keyof Plugins;
754
+ type CorePluginOptions = PluginFactoryOptions<'core', Options, false, PluginContext>;
755
+ declare const pluginName: CorePluginOptions['name'];
698
756
 
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 };
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 };