@kubb/core 1.12.0-canary.20231018T090722 → 1.12.0-canary.20231018T095854
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.cjs +72 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +126 -122
- package/dist/index.d.ts +126 -122
- package/dist/index.js +71 -39
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DirectoryTreeOptions } from 'directory-tree';
|
|
2
1
|
import { Ora } from 'ora';
|
|
2
|
+
import { DirectoryTreeOptions } from 'directory-tree';
|
|
3
3
|
export { default as pc } from 'picocolors';
|
|
4
4
|
|
|
5
5
|
declare function isPromise<T>(result: PossiblePromise<T>): result is Promise<T>;
|
|
@@ -18,41 +18,71 @@ interface Cache<TStore extends object = object> {
|
|
|
18
18
|
}
|
|
19
19
|
declare function createPluginCache<TStore extends PluginCache>(Store?: TStore): Cache<TStore>;
|
|
20
20
|
|
|
21
|
+
type BasePath<T extends string = string> = `${T}/`;
|
|
22
|
+
type CacheItem = KubbFile.ResolvedFile & {
|
|
23
|
+
cancel?: () => void;
|
|
24
|
+
};
|
|
25
|
+
declare namespace KubbFile {
|
|
26
|
+
type Import = {
|
|
27
|
+
name: string | Array<string>;
|
|
28
|
+
path: string;
|
|
29
|
+
isTypeOnly?: boolean;
|
|
30
|
+
};
|
|
31
|
+
type Export = {
|
|
32
|
+
name?: string | Array<string>;
|
|
33
|
+
path: string;
|
|
34
|
+
isTypeOnly?: boolean;
|
|
35
|
+
asAlias?: boolean;
|
|
36
|
+
};
|
|
37
|
+
type UUID = string;
|
|
38
|
+
type Source = string;
|
|
39
|
+
type Extname = '.ts' | '.js' | '.tsx' | `.${string}`;
|
|
40
|
+
type Mode = 'file' | 'directory';
|
|
41
|
+
type BaseName = `${string}${Extname}`;
|
|
42
|
+
type Path = string;
|
|
43
|
+
type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
|
|
44
|
+
type OptionalPath = Path | undefined | null;
|
|
45
|
+
type File<TMeta extends {
|
|
46
|
+
pluginName?: string;
|
|
47
|
+
} = {
|
|
48
|
+
pluginName?: string;
|
|
49
|
+
}, TBaseName extends BaseName = BaseName> = {
|
|
50
|
+
/**
|
|
51
|
+
* Name to be used to dynamicly create the baseName(based on input.path)
|
|
52
|
+
* Based on UNIX basename
|
|
53
|
+
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
54
|
+
*/
|
|
55
|
+
baseName: TBaseName;
|
|
56
|
+
/**
|
|
57
|
+
* Path will be full qualified path to a specified file
|
|
58
|
+
*/
|
|
59
|
+
path: AdvancedPath<TBaseName> | Path;
|
|
60
|
+
source: Source;
|
|
61
|
+
imports?: Import[];
|
|
62
|
+
exports?: Export[];
|
|
63
|
+
/**
|
|
64
|
+
* This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
|
|
65
|
+
* @default `false`
|
|
66
|
+
*/
|
|
67
|
+
override?: boolean;
|
|
68
|
+
meta?: TMeta;
|
|
69
|
+
/**
|
|
70
|
+
* This will override `process.env[key]` inside the `source`, see `getFileSource`.
|
|
71
|
+
*/
|
|
72
|
+
env?: NodeJS.ProcessEnv;
|
|
73
|
+
};
|
|
74
|
+
type ResolvedFile = KubbFile.File & {
|
|
75
|
+
/**
|
|
76
|
+
* crypto.randomUUID()
|
|
77
|
+
*/
|
|
78
|
+
id: UUID;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
21
82
|
declare function getRelativePath(rootDir?: string | null, filePath?: string | null, platform?: 'windows' | 'mac' | 'linux'): string;
|
|
22
|
-
|
|
23
|
-
declare function getPathMode(path: string | undefined | null): PathMode;
|
|
83
|
+
declare function getPathMode(path: string | undefined | null): KubbFile.Mode;
|
|
24
84
|
declare function read(path: string): Promise<string>;
|
|
25
|
-
|
|
26
|
-
type FunctionParamsAST = {
|
|
27
|
-
name?: string;
|
|
28
|
-
type?: string;
|
|
29
|
-
/**
|
|
30
|
-
* @default true
|
|
31
|
-
*/
|
|
32
|
-
required?: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* @default true
|
|
35
|
-
*/
|
|
36
|
-
enabled?: boolean;
|
|
37
|
-
default?: string;
|
|
38
|
-
} | {
|
|
39
|
-
name?: never;
|
|
40
|
-
type: string;
|
|
41
|
-
/**
|
|
42
|
-
* @default true
|
|
43
|
-
*/
|
|
44
|
-
required?: boolean;
|
|
45
|
-
/**
|
|
46
|
-
* @default true
|
|
47
|
-
*/
|
|
48
|
-
enabled?: boolean;
|
|
49
|
-
default?: string;
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* Convert an string array to a string of parameters that can be used inside a function
|
|
53
|
-
* The parameter name is converted to `camelcase`
|
|
54
|
-
*/
|
|
55
|
-
declare function createFunctionParams(ast: FunctionParamsAST[]): string;
|
|
85
|
+
declare function readSync(path: string): string;
|
|
56
86
|
|
|
57
87
|
declare function nameSorter<T extends {
|
|
58
88
|
name: string;
|
|
@@ -221,68 +251,38 @@ declare class URLPath {
|
|
|
221
251
|
static isURL(path: string): boolean;
|
|
222
252
|
}
|
|
223
253
|
|
|
224
|
-
type
|
|
225
|
-
name
|
|
226
|
-
|
|
227
|
-
isTypeOnly?: boolean;
|
|
228
|
-
};
|
|
229
|
-
type Export = {
|
|
230
|
-
name?: string | string[];
|
|
231
|
-
path: string;
|
|
232
|
-
isTypeOnly?: boolean;
|
|
233
|
-
asAlias?: boolean;
|
|
234
|
-
};
|
|
235
|
-
type UUID = string;
|
|
236
|
-
type Source = string;
|
|
237
|
-
type File<Meta extends {
|
|
238
|
-
pluginName?: string;
|
|
239
|
-
} = {
|
|
240
|
-
pluginName?: string;
|
|
241
|
-
}> = {
|
|
242
|
-
/**
|
|
243
|
-
* Name to be used to dynamicly create the fileName(based on input.path)
|
|
244
|
-
*/
|
|
245
|
-
fileName: string;
|
|
254
|
+
type FunctionParamsAST = {
|
|
255
|
+
name?: string;
|
|
256
|
+
type?: string;
|
|
246
257
|
/**
|
|
247
|
-
*
|
|
258
|
+
* @default true
|
|
248
259
|
*/
|
|
249
|
-
|
|
250
|
-
source: Source;
|
|
251
|
-
imports?: Import[];
|
|
252
|
-
exports?: Export[];
|
|
260
|
+
required?: boolean;
|
|
253
261
|
/**
|
|
254
|
-
*
|
|
255
|
-
* @default `false`
|
|
262
|
+
* @default true
|
|
256
263
|
*/
|
|
257
|
-
|
|
258
|
-
|
|
264
|
+
enabled?: boolean;
|
|
265
|
+
default?: string;
|
|
266
|
+
} | {
|
|
267
|
+
name?: never;
|
|
268
|
+
type: string;
|
|
259
269
|
/**
|
|
260
|
-
*
|
|
270
|
+
* @default true
|
|
261
271
|
*/
|
|
262
|
-
|
|
263
|
-
};
|
|
264
|
-
type ResolvedFile = File & {
|
|
272
|
+
required?: boolean;
|
|
265
273
|
/**
|
|
266
|
-
*
|
|
274
|
+
* @default true
|
|
267
275
|
*/
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
type CacheItem = ResolvedFile & {
|
|
271
|
-
cancel?: () => void;
|
|
276
|
+
enabled?: boolean;
|
|
277
|
+
default?: string;
|
|
272
278
|
};
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
type Extension = '.ts' | '.js' | '.tsx';
|
|
281
|
-
declare const extensions: Array<Extension>;
|
|
282
|
-
declare function isExtensionAllowed(fileName: string): boolean;
|
|
283
|
-
declare function combineExports(exports: Export[]): Export[];
|
|
284
|
-
declare function combineImports(imports: Import[], exports: Export[], source: string): Import[];
|
|
285
|
-
declare function createFileSource(file: File): string;
|
|
279
|
+
declare class FunctionParams {
|
|
280
|
+
type?: 'generics' | 'typed';
|
|
281
|
+
items: FunctionParamsAST[];
|
|
282
|
+
constructor(type?: 'generics' | 'typed');
|
|
283
|
+
add(item: FunctionParamsAST | Array<FunctionParamsAST | undefined> | undefined): FunctionParams;
|
|
284
|
+
toString(): string;
|
|
285
|
+
}
|
|
286
286
|
|
|
287
287
|
declare class FileManager {
|
|
288
288
|
private cache;
|
|
@@ -290,21 +290,32 @@ declare class FileManager {
|
|
|
290
290
|
private queue?;
|
|
291
291
|
constructor(options?: {
|
|
292
292
|
queue?: Queue;
|
|
293
|
-
task?: QueueJob<ResolvedFile>;
|
|
293
|
+
task?: QueueJob<KubbFile.ResolvedFile>;
|
|
294
294
|
});
|
|
295
|
-
get extensions():
|
|
296
|
-
get files(): File
|
|
295
|
+
get extensions(): Array<KubbFile.Extname>;
|
|
296
|
+
get files(): Array<KubbFile.File>;
|
|
297
297
|
get isExecuting(): boolean;
|
|
298
|
-
add(file: File): Promise<ResolvedFile>;
|
|
299
|
-
addOrAppend(file: File): Promise<ResolvedFile>;
|
|
298
|
+
add(file: KubbFile.File): Promise<KubbFile.ResolvedFile>;
|
|
299
|
+
addOrAppend(file: KubbFile.File): Promise<KubbFile.ResolvedFile>;
|
|
300
300
|
private append;
|
|
301
|
-
getCacheByUUID(UUID: UUID): File | undefined;
|
|
302
|
-
get(path: Path): File
|
|
303
|
-
remove(path: Path): void;
|
|
301
|
+
getCacheByUUID(UUID: KubbFile.UUID): KubbFile.File | undefined;
|
|
302
|
+
get(path: KubbFile.Path): Array<KubbFile.File> | undefined;
|
|
303
|
+
remove(path: KubbFile.Path): void;
|
|
304
304
|
write(...params: Parameters<typeof write>): Promise<void>;
|
|
305
305
|
read(...params: Parameters<typeof read>): Promise<string>;
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
+
declare function getIndexes(root: string, options?: TreeNodeOptions): Array<KubbFile.File> | null;
|
|
309
|
+
declare function combineFiles(files: Array<KubbFile.File | null>): Array<KubbFile.File>;
|
|
310
|
+
/**
|
|
311
|
+
* Support for js, ts and tsx(React)
|
|
312
|
+
*/
|
|
313
|
+
declare const extensions: Array<KubbFile.Extname>;
|
|
314
|
+
declare function isExtensionAllowed(baseName: string): boolean;
|
|
315
|
+
declare function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export>;
|
|
316
|
+
declare function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source: string): Array<KubbFile.Import>;
|
|
317
|
+
declare function createFileSource(file: KubbFile.File): string;
|
|
318
|
+
|
|
308
319
|
declare class EventEmitter<TEvents extends Record<string, any>> {
|
|
309
320
|
constructor();
|
|
310
321
|
private emitter;
|
|
@@ -345,7 +356,7 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
|
|
|
345
356
|
declare const hooks: [keyof PluginLifecycle<PluginFactoryOptions<string, unknown, false, any, Record<string, unknown>>>];
|
|
346
357
|
type Options$1 = {
|
|
347
358
|
debug?: boolean;
|
|
348
|
-
task: QueueJob<ResolvedFile>;
|
|
359
|
+
task: QueueJob<KubbFile.ResolvedFile>;
|
|
349
360
|
logger: Logger;
|
|
350
361
|
};
|
|
351
362
|
type Events = {
|
|
@@ -362,7 +373,7 @@ declare class PluginManager {
|
|
|
362
373
|
readonly logger: Logger;
|
|
363
374
|
private readonly core;
|
|
364
375
|
constructor(config: KubbConfig, options: Options$1);
|
|
365
|
-
resolvePath: (params: ResolvePathParams) => OptionalPath;
|
|
376
|
+
resolvePath: (params: ResolvePathParams) => KubbFile.OptionalPath;
|
|
366
377
|
resolveName: (params: ResolveNameParams) => string;
|
|
367
378
|
on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
|
|
368
379
|
/**
|
|
@@ -457,12 +468,6 @@ declare class ParallelPluginError extends Error {
|
|
|
457
468
|
findError<T extends Error = Error>(searchError: T | undefined): T | undefined;
|
|
458
469
|
}
|
|
459
470
|
|
|
460
|
-
/**
|
|
461
|
-
* @deprecated
|
|
462
|
-
*/
|
|
463
|
-
interface Register {
|
|
464
|
-
}
|
|
465
|
-
type PossiblePromise<T> = Promise<T> | T;
|
|
466
471
|
/**
|
|
467
472
|
* Config used in `kubb.config.js`
|
|
468
473
|
*
|
|
@@ -483,7 +488,7 @@ type KubbUserConfig = Omit<KubbConfig, 'root' | 'plugins'> & {
|
|
|
483
488
|
* Example: ['@kubb/swagger', { output: false }]
|
|
484
489
|
* Or: createSwagger({ output: false })
|
|
485
490
|
*/
|
|
486
|
-
plugins?: KubbPlugin
|
|
491
|
+
plugins?: Array<KubbPlugin> | Array<KubbJSONPlugins> | KubbObjectPlugins;
|
|
487
492
|
};
|
|
488
493
|
/**
|
|
489
494
|
* Global/internal config used through out the full generation.
|
|
@@ -522,7 +527,7 @@ type KubbConfig = {
|
|
|
522
527
|
* The plugin/package can forsee some options that you need to pass through.
|
|
523
528
|
* Sometimes a plugin is depended on another plugin, if that's the case you will get an error back from the plugin you installed.
|
|
524
529
|
*/
|
|
525
|
-
plugins?: KubbPlugin
|
|
530
|
+
plugins?: Array<KubbPlugin>;
|
|
526
531
|
/**
|
|
527
532
|
* Hooks that will be called when a specific action is triggered in Kubb.
|
|
528
533
|
*/
|
|
@@ -531,7 +536,7 @@ type KubbConfig = {
|
|
|
531
536
|
* Hook that will be triggerend at the end of all executions.
|
|
532
537
|
* Useful for running Prettier or ESLint to use your own linting structure.
|
|
533
538
|
*/
|
|
534
|
-
done?: string | string
|
|
539
|
+
done?: string | Array<string>;
|
|
535
540
|
};
|
|
536
541
|
};
|
|
537
542
|
type CLIOptions = {
|
|
@@ -628,34 +633,34 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
628
633
|
*/
|
|
629
634
|
buildStart: (this: PluginContext, kubbConfig: KubbConfig) => PossiblePromise<void>;
|
|
630
635
|
/**
|
|
631
|
-
* Resolve to a Path based on a
|
|
636
|
+
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
632
637
|
* Options can als be included.
|
|
633
638
|
* @type hookFirst
|
|
634
639
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
635
640
|
*/
|
|
636
|
-
resolvePath: (this: PluginContext,
|
|
641
|
+
resolvePath: (this: PluginContext, baseName: string, directory?: string, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
|
|
637
642
|
/**
|
|
638
643
|
* Resolve to a name based on a string.
|
|
639
644
|
* Useful when converting to PascalCase or camelCase.
|
|
640
645
|
* @type hookFirst
|
|
641
646
|
* @example ('pet') => 'Pet'
|
|
642
647
|
*/
|
|
643
|
-
resolveName: (this: PluginContext, name:
|
|
648
|
+
resolveName: (this: PluginContext, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
644
649
|
/**
|
|
645
650
|
* Makes it possible to run async logic to override the path defined previously by `resolvePath`.
|
|
646
651
|
* @type hookFirst
|
|
647
652
|
*/
|
|
648
|
-
load: (this: Omit<PluginContext, 'addFile'>, path: Path) => PossiblePromise<TransformResult | null>;
|
|
653
|
+
load: (this: Omit<PluginContext, 'addFile'>, path: KubbFile.Path) => PossiblePromise<TransformResult | null>;
|
|
649
654
|
/**
|
|
650
655
|
* Transform the source-code.
|
|
651
656
|
* @type hookReduceArg0
|
|
652
657
|
*/
|
|
653
|
-
transform: (this: Omit<PluginContext, 'addFile'>, source: string, path: Path) => PossiblePromise<TransformResult>;
|
|
658
|
+
transform: (this: Omit<PluginContext, 'addFile'>, source: string, path: KubbFile.Path) => PossiblePromise<TransformResult>;
|
|
654
659
|
/**
|
|
655
660
|
* Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
|
|
656
661
|
* @type hookParallel
|
|
657
662
|
*/
|
|
658
|
-
writeFile: (this: Omit<PluginContext, 'addFile'>, source: string | undefined, path: Path) => PossiblePromise<void>;
|
|
663
|
+
writeFile: (this: Omit<PluginContext, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<void>;
|
|
659
664
|
/**
|
|
660
665
|
* End of the plugin lifecycle.
|
|
661
666
|
* @type hookParallel
|
|
@@ -670,7 +675,7 @@ type ResolvePathParams<TOptions = Record<string, unknown>> = {
|
|
|
670
675
|
* If not defined it will fall back on the resolvePath of the core plugin.
|
|
671
676
|
*/
|
|
672
677
|
pluginName?: string;
|
|
673
|
-
|
|
678
|
+
baseName: string;
|
|
674
679
|
directory?: string | undefined;
|
|
675
680
|
/**
|
|
676
681
|
* Options to be passed to 'resolvePath' 3th parameter
|
|
@@ -684,25 +689,20 @@ type ResolveNameParams = {
|
|
|
684
689
|
* If not defined it will fall back on the resolvePath of the core plugin.
|
|
685
690
|
*/
|
|
686
691
|
pluginName?: string;
|
|
692
|
+
type?: 'file' | 'function';
|
|
687
693
|
};
|
|
688
694
|
type PluginContext<TOptions = Record<string, unknown>> = {
|
|
689
695
|
config: KubbConfig;
|
|
690
696
|
cache: Cache<PluginCache>;
|
|
691
697
|
fileManager: FileManager;
|
|
692
698
|
pluginManager: PluginManager;
|
|
693
|
-
addFile: (...file: File
|
|
694
|
-
resolvePath: (params: ResolvePathParams<TOptions>) => OptionalPath;
|
|
699
|
+
addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.File>>;
|
|
700
|
+
resolvePath: (params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
695
701
|
resolveName: (params: ResolveNameParams) => string;
|
|
696
702
|
logger: Logger;
|
|
697
703
|
plugins: KubbPlugin[];
|
|
698
704
|
};
|
|
699
705
|
type TransformResult = string | null;
|
|
700
|
-
/**
|
|
701
|
-
* @description Computing the name of a file or directory together with its position in relation to other directories traced back in a line to the root
|
|
702
|
-
*/
|
|
703
|
-
type Path = string;
|
|
704
|
-
type OptionalPath = Path | null | undefined;
|
|
705
|
-
type FileName = string | null | undefined;
|
|
706
706
|
declare const LogLevel: {
|
|
707
707
|
readonly silent: "silent";
|
|
708
708
|
readonly info: "info";
|
|
@@ -712,6 +712,10 @@ type LogLevel = keyof typeof LogLevel;
|
|
|
712
712
|
type AppMeta = {
|
|
713
713
|
pluginManager: PluginManager;
|
|
714
714
|
};
|
|
715
|
+
type Prettify<T> = {
|
|
716
|
+
[K in keyof T]: T[K];
|
|
717
|
+
} & {};
|
|
718
|
+
type PossiblePromise<T> = Promise<T> | T;
|
|
715
719
|
|
|
716
720
|
type BuildOptions = {
|
|
717
721
|
config: PluginContext['config'];
|
|
@@ -764,4 +768,4 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
|
|
|
764
768
|
abstract build(schema: TInput, name: string, description?: string): TOutput;
|
|
765
769
|
}
|
|
766
770
|
|
|
767
|
-
export { AppMeta, Argument0, BuildOutput, CLIOptions, Cache, CacheItem, Executer,
|
|
771
|
+
export { AppMeta, Argument0, BuildOutput, CLIOptions, Cache, CacheItem, Executer, FileManager, FunctionParams, FunctionParamsAST, Generator, KubbConfig, KubbFile, KubbJSONPlugins, KubbObjectPlugin, KubbObjectPlugins, KubbPlugin, KubbPluginKind, KubbUserConfig, KubbUserPlugin, LogLevel, LogType, Logger, ParallelPluginError, ParseResult, PluginCache, PluginContext, PluginError, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PossiblePromise, Prettify, Queue, QueueJob, 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, getLocation, getPathMode, getRelativePath, getUniqueName, hooks, importModule, isExtensionAllowed, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, jsStringEscape, pluginName as name, nameSorter, normalizeDirectory, pluginName, randomColour, randomPicoColour, read, readSync, renderTemplate, throttle, timeout, transformReservedWord, uniqueIdFactory, write };
|