@kubb/core 1.2.0 → 1.2.1
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 +224 -164
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +83 -40
- package/dist/index.js +217 -163
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
package/dist/index.d.ts
CHANGED
|
@@ -11,8 +11,9 @@ type Logger = {
|
|
|
11
11
|
spinner?: Ora;
|
|
12
12
|
};
|
|
13
13
|
declare function createLogger(spinner?: Ora): Logger;
|
|
14
|
+
declare function canLogHierarchy(input: LogLevels | undefined, compareTo: LogLevels): boolean;
|
|
14
15
|
|
|
15
|
-
declare function isPromise<T>(result:
|
|
16
|
+
declare function isPromise<T>(result: PossiblePromise<T>): result is Promise<T>;
|
|
16
17
|
declare function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T>;
|
|
17
18
|
declare function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & {
|
|
18
19
|
reason: T;
|
|
@@ -60,12 +61,17 @@ declare function timeout(ms: number): Promise<unknown>;
|
|
|
60
61
|
type QueueTask<T = unknown> = {
|
|
61
62
|
(...args: unknown[]): Promise<T> | Promise<void>;
|
|
62
63
|
};
|
|
64
|
+
type RunOptions = {
|
|
65
|
+
name: string;
|
|
66
|
+
description: string;
|
|
67
|
+
};
|
|
63
68
|
declare class Queue {
|
|
64
69
|
private readonly queue;
|
|
65
70
|
workerCount: number;
|
|
66
71
|
private maxParallel;
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
private debug;
|
|
73
|
+
constructor(maxParallel: number, debug?: boolean);
|
|
74
|
+
run<T>(task: QueueTask<T>, options?: RunOptions): Promise<T>;
|
|
69
75
|
private work;
|
|
70
76
|
}
|
|
71
77
|
|
|
@@ -128,6 +134,10 @@ declare class Warning extends Error {
|
|
|
128
134
|
});
|
|
129
135
|
}
|
|
130
136
|
|
|
137
|
+
declare const defaultColours: readonly ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"];
|
|
138
|
+
declare function randomColour(text?: string, colours?: readonly ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"]): string;
|
|
139
|
+
declare function randomPicoColour(text?: string, colors?: readonly ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"]): string;
|
|
140
|
+
|
|
131
141
|
type Import = {
|
|
132
142
|
name: string | string[];
|
|
133
143
|
path: string;
|
|
@@ -139,6 +149,8 @@ type Export = {
|
|
|
139
149
|
isTypeOnly?: boolean;
|
|
140
150
|
asAlias?: boolean;
|
|
141
151
|
};
|
|
152
|
+
type UUID = string;
|
|
153
|
+
type Source = string;
|
|
142
154
|
type File = {
|
|
143
155
|
/**
|
|
144
156
|
* Name to be used to dynamicly create the fileName(based on input.path)
|
|
@@ -147,8 +159,8 @@ type File = {
|
|
|
147
159
|
/**
|
|
148
160
|
* Path will be full qualified path to a specified file
|
|
149
161
|
*/
|
|
150
|
-
path:
|
|
151
|
-
source:
|
|
162
|
+
path: Path;
|
|
163
|
+
source: Source;
|
|
152
164
|
imports?: Import[];
|
|
153
165
|
exports?: Export[];
|
|
154
166
|
/**
|
|
@@ -164,11 +176,11 @@ type File = {
|
|
|
164
176
|
*/
|
|
165
177
|
env?: NodeJS.ProcessEnv;
|
|
166
178
|
};
|
|
167
|
-
type
|
|
168
|
-
|
|
179
|
+
type ResolvedFile = File & {
|
|
180
|
+
/**
|
|
181
|
+
* crypto.randomUUID()
|
|
182
|
+
*/
|
|
169
183
|
id: UUID;
|
|
170
|
-
file: File;
|
|
171
|
-
status: Status;
|
|
172
184
|
};
|
|
173
185
|
type Status = 'new' | 'success' | 'removed';
|
|
174
186
|
|
|
@@ -184,18 +196,16 @@ declare class FileManager {
|
|
|
184
196
|
private queue?;
|
|
185
197
|
constructor(options?: {
|
|
186
198
|
queue: Queue;
|
|
187
|
-
task?: QueueTask<
|
|
199
|
+
task?: QueueTask<ResolvedFile>;
|
|
188
200
|
});
|
|
189
|
-
private getCache;
|
|
190
201
|
get extensions(): Extension[];
|
|
191
|
-
getCacheByPath(path: string | undefined): CacheStore | undefined;
|
|
192
202
|
get files(): File[];
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
get(
|
|
198
|
-
remove(
|
|
203
|
+
add(file: File): Promise<ResolvedFile>;
|
|
204
|
+
addOrAppend(file: File): Promise<ResolvedFile>;
|
|
205
|
+
private append;
|
|
206
|
+
getCacheByUUID(UUID: UUID): File | undefined;
|
|
207
|
+
get(path: Path): File[] | undefined;
|
|
208
|
+
remove(path: Path): void;
|
|
199
209
|
write(...params: Parameters<typeof write>): Promise<void>;
|
|
200
210
|
read(...params: Parameters<typeof read>): Promise<string>;
|
|
201
211
|
}
|
|
@@ -210,6 +220,8 @@ type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
|
210
220
|
strategy: Strategy;
|
|
211
221
|
hookName: H;
|
|
212
222
|
plugin: KubbPlugin;
|
|
223
|
+
input?: unknown[] | undefined;
|
|
224
|
+
output?: unknown;
|
|
213
225
|
};
|
|
214
226
|
type OnExecute<H extends PluginLifecycleHooks = PluginLifecycleHooks> = (this: PluginManager, executer: Executer<H> | undefined, pluginManager: PluginManager) => void;
|
|
215
227
|
type ParseResult<H extends PluginLifecycleHooks> = PluginLifecycle[H];
|
|
@@ -220,7 +232,8 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
|
|
|
220
232
|
|
|
221
233
|
declare const hooks: [keyof PluginLifecycle<PluginFactoryOptions<string, unknown, false, any, Record<string, any>>>];
|
|
222
234
|
type Options$1 = {
|
|
223
|
-
|
|
235
|
+
debug?: boolean;
|
|
236
|
+
task: QueueTask<ResolvedFile>;
|
|
224
237
|
logger: Logger;
|
|
225
238
|
onExecute?: OnExecute<PluginLifecycleHooks>;
|
|
226
239
|
};
|
|
@@ -230,11 +243,9 @@ declare class PluginManager {
|
|
|
230
243
|
private readonly onExecute?;
|
|
231
244
|
private readonly core;
|
|
232
245
|
queue: Queue;
|
|
233
|
-
executer: Executer | undefined;
|
|
234
246
|
executed: Executer[];
|
|
235
247
|
logger: Logger;
|
|
236
248
|
constructor(config: KubbConfig, options: Options$1);
|
|
237
|
-
getExecuter(): Executer | undefined;
|
|
238
249
|
resolvePath: (params: ResolvePathParams) => OptionalPath;
|
|
239
250
|
resolveName: (params: ResolveNameParams) => string | null;
|
|
240
251
|
load: (id: string) => Promise<SafeParseResult<"load">>;
|
|
@@ -285,7 +296,7 @@ declare class PluginManager {
|
|
|
285
296
|
hookReduceArg0<H extends PluginLifecycleHooks>({ hookName, parameters, reduce, }: {
|
|
286
297
|
hookName: H;
|
|
287
298
|
parameters: Parameters<PluginLifecycle[H]>;
|
|
288
|
-
reduce: (reduction: Argument0<H>, result: ReturnType<ParseResult<H>>, plugin: KubbPlugin) =>
|
|
299
|
+
reduce: (reduction: Argument0<H>, result: ReturnType<ParseResult<H>>, plugin: KubbPlugin) => PossiblePromise<Argument0<H> | null>;
|
|
289
300
|
}): Promise<Argument0<H>>;
|
|
290
301
|
/**
|
|
291
302
|
* Chains plugins
|
|
@@ -296,7 +307,7 @@ declare class PluginManager {
|
|
|
296
307
|
}): Promise<void>;
|
|
297
308
|
private getSortedPlugins;
|
|
298
309
|
getPlugin(hookName: keyof PluginLifecycle, pluginName: string): KubbPlugin;
|
|
299
|
-
private
|
|
310
|
+
private addExecutedToCallStack;
|
|
300
311
|
/**
|
|
301
312
|
* Run an async plugin hook and return the result.
|
|
302
313
|
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
@@ -341,7 +352,7 @@ declare class ParallelPluginError extends Error {
|
|
|
341
352
|
|
|
342
353
|
interface Register {
|
|
343
354
|
}
|
|
344
|
-
type
|
|
355
|
+
type PossiblePromise<T> = Promise<T> | T;
|
|
345
356
|
/**
|
|
346
357
|
* Config used in `kubb.config.js`
|
|
347
358
|
*
|
|
@@ -414,10 +425,15 @@ type KubbConfig = {
|
|
|
414
425
|
};
|
|
415
426
|
/**
|
|
416
427
|
* Log level to report when using the CLI
|
|
417
|
-
*
|
|
428
|
+
*
|
|
429
|
+
* `silent` will hide all information that is not relevant
|
|
430
|
+
*
|
|
431
|
+
* `info` will show all information possible(not related to the PluginManager)
|
|
432
|
+
*
|
|
433
|
+
* `stacktrace` will show all information possible(related to the PluginManager), handy for seeing logs
|
|
418
434
|
* @default `silent`
|
|
419
435
|
*/
|
|
420
|
-
logLevel?:
|
|
436
|
+
logLevel?: LogLevels;
|
|
421
437
|
};
|
|
422
438
|
type CLIOptions = {
|
|
423
439
|
/**
|
|
@@ -440,7 +456,7 @@ type CLIOptions = {
|
|
|
440
456
|
* Override `logLevel` defined in `kubb.config.js`
|
|
441
457
|
* @default `'silent'`
|
|
442
458
|
*/
|
|
443
|
-
logLevel?:
|
|
459
|
+
logLevel?: LogLevels;
|
|
444
460
|
init?: unknown;
|
|
445
461
|
};
|
|
446
462
|
type BuildOutput = {
|
|
@@ -453,6 +469,28 @@ type KubbObjectPlugin = keyof Register;
|
|
|
453
469
|
type KubbObjectPlugins = {
|
|
454
470
|
[K in keyof Register]: Register[K] | object;
|
|
455
471
|
};
|
|
472
|
+
type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
473
|
+
/**
|
|
474
|
+
* Unique name used for the plugin
|
|
475
|
+
* @example @kubb/typescript
|
|
476
|
+
*/
|
|
477
|
+
name: PluginFactoryOptions['name'];
|
|
478
|
+
/**
|
|
479
|
+
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
480
|
+
*/
|
|
481
|
+
options?: TOptions['options'];
|
|
482
|
+
/**
|
|
483
|
+
* Kind/type for the plugin
|
|
484
|
+
* Type 'schema' can be used for JSON schema's, TypeScript types, ...
|
|
485
|
+
* Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
|
|
486
|
+
* @default undefined
|
|
487
|
+
*/
|
|
488
|
+
kind?: KubbPluginKind;
|
|
489
|
+
/**
|
|
490
|
+
* Define an api that can be used by other plugins, see `PluginManager' where we convert from `KubbUserPlugin` to `KubbPlugin`(used when calling `createPlugin`).
|
|
491
|
+
*/
|
|
492
|
+
api?: (this: Omit<PluginContext, 'addFile'>) => TOptions['api'];
|
|
493
|
+
} & Partial<PluginLifecycle<TOptions>>;
|
|
456
494
|
type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
457
495
|
/**
|
|
458
496
|
* Unique name used for the plugin
|
|
@@ -471,7 +509,7 @@ type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
471
509
|
*/
|
|
472
510
|
kind?: KubbPluginKind;
|
|
473
511
|
/**
|
|
474
|
-
*
|
|
512
|
+
* Define an api that can be used by other plugins, see `PluginManager' where we convert from `KubbUserPlugin` to `KubbPlugin`(used when calling `createPlugin`).
|
|
475
513
|
*/
|
|
476
514
|
api?: TOptions['api'];
|
|
477
515
|
} & Partial<PluginLifecycle<TOptions>>;
|
|
@@ -487,12 +525,12 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
487
525
|
* Valdiate all plugins to see if their depended plugins are installed and configured.
|
|
488
526
|
* @type hookParallel
|
|
489
527
|
*/
|
|
490
|
-
validate: (this: Omit<PluginContext, 'addFile'>, plugins: KubbPlugin[]) =>
|
|
528
|
+
validate: (this: Omit<PluginContext, 'addFile'>, plugins: KubbPlugin[]) => PossiblePromise<true>;
|
|
491
529
|
/**
|
|
492
530
|
* Start of the lifecycle of a plugin.
|
|
493
531
|
* @type hookParallel
|
|
494
532
|
*/
|
|
495
|
-
buildStart: (this: PluginContext, kubbConfig: KubbConfig) =>
|
|
533
|
+
buildStart: (this: PluginContext, kubbConfig: KubbConfig) => PossiblePromise<void>;
|
|
496
534
|
/**
|
|
497
535
|
* Resolve to a Path based on a fileName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
498
536
|
* Options can als be included.
|
|
@@ -511,22 +549,22 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
511
549
|
* Makes it possible to run async logic to override the path defined previously by `resolvePath`.
|
|
512
550
|
* @type hookFirst
|
|
513
551
|
*/
|
|
514
|
-
load: (this: Omit<PluginContext, 'addFile'>, path: Path) =>
|
|
552
|
+
load: (this: Omit<PluginContext, 'addFile'>, path: Path) => PossiblePromise<TransformResult | null>;
|
|
515
553
|
/**
|
|
516
554
|
* Transform the source-code.
|
|
517
555
|
* @type hookReduceArg0
|
|
518
556
|
*/
|
|
519
|
-
transform: (this: Omit<PluginContext, 'addFile'>, source: string, path: Path) =>
|
|
557
|
+
transform: (this: Omit<PluginContext, 'addFile'>, source: string, path: Path) => PossiblePromise<TransformResult>;
|
|
520
558
|
/**
|
|
521
559
|
* Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
|
|
522
560
|
* @type hookParallel
|
|
523
561
|
*/
|
|
524
|
-
writeFile: (this: Omit<PluginContext, 'addFile'>, source: string | undefined, path: Path) =>
|
|
562
|
+
writeFile: (this: Omit<PluginContext, 'addFile'>, source: string | undefined, path: Path) => PossiblePromise<void>;
|
|
525
563
|
/**
|
|
526
564
|
* End of the plugin lifecycle.
|
|
527
565
|
* @type hookParallel
|
|
528
566
|
*/
|
|
529
|
-
buildEnd: (this: PluginContext) =>
|
|
567
|
+
buildEnd: (this: PluginContext) => PossiblePromise<void>;
|
|
530
568
|
};
|
|
531
569
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
532
570
|
type ResolvePathParams<TOptions = Record<string, any>> = {
|
|
@@ -567,7 +605,12 @@ type TransformResult = string | null;
|
|
|
567
605
|
type Path = string;
|
|
568
606
|
type OptionalPath = Path | null | undefined;
|
|
569
607
|
type FileName = string | null | undefined;
|
|
570
|
-
|
|
608
|
+
declare const LogLevel: {
|
|
609
|
+
readonly silent: "silent";
|
|
610
|
+
readonly info: "info";
|
|
611
|
+
readonly stacktrace: "stacktrace";
|
|
612
|
+
};
|
|
613
|
+
type LogLevels = keyof typeof LogLevel;
|
|
571
614
|
|
|
572
615
|
type BuildOptions = {
|
|
573
616
|
config: PluginContext['config'];
|
|
@@ -575,6 +618,7 @@ type BuildOptions = {
|
|
|
575
618
|
* @default Logger without the spinner
|
|
576
619
|
*/
|
|
577
620
|
logger?: Logger;
|
|
621
|
+
debug?: boolean;
|
|
578
622
|
};
|
|
579
623
|
declare function build(options: BuildOptions): Promise<BuildOutput>;
|
|
580
624
|
|
|
@@ -583,10 +627,10 @@ declare function build(options: BuildOptions): Promise<BuildOutput>;
|
|
|
583
627
|
* accepts a direct {@link KubbConfig} object, or a function that returns it.
|
|
584
628
|
* The function receives a {@link ConfigEnv} object that exposes two properties:
|
|
585
629
|
*/
|
|
586
|
-
declare const defineConfig: (options:
|
|
630
|
+
declare const defineConfig: (options: PossiblePromise<KubbUserConfig> | ((cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig>)) => PossiblePromise<KubbUserConfig> | ((cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig>);
|
|
587
631
|
|
|
588
|
-
type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => T['nested'] extends true ? Array<
|
|
589
|
-
declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => T["nested"] extends true ?
|
|
632
|
+
type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => T['nested'] extends true ? Array<KubbUserPlugin<T>> : KubbUserPlugin<T>;
|
|
633
|
+
declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => T["nested"] extends true ? KubbUserPlugin<T>[] : KubbUserPlugin<T>;
|
|
590
634
|
type Options = {
|
|
591
635
|
config: PluginContext['config'];
|
|
592
636
|
fileManager: FileManager;
|
|
@@ -594,7 +638,6 @@ type Options = {
|
|
|
594
638
|
resolveName: PluginContext['resolveName'];
|
|
595
639
|
load: PluginContext['load'];
|
|
596
640
|
logger: PluginContext['logger'];
|
|
597
|
-
getExecuter: () => Executer<PluginLifecycleHooks> | undefined;
|
|
598
641
|
};
|
|
599
642
|
type CorePluginOptions = PluginFactoryOptions<'core', Options, false, PluginContext>;
|
|
600
643
|
declare const pluginName: CorePluginOptions['name'];
|
|
@@ -617,4 +660,4 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
|
|
|
617
660
|
abstract build(schema: TInput, name: string, description?: string): TOutput;
|
|
618
661
|
}
|
|
619
662
|
|
|
620
|
-
export { Argument0, BuildOutput, CLIOptions, Cache,
|
|
663
|
+
export { Argument0, BuildOutput, CLIOptions, Cache, CorePluginOptions, Executer, Extension, File, FileManager, FileName, Generator, KubbConfig, KubbJSONPlugins, KubbObjectPlugin, KubbObjectPlugins, KubbPlugin, KubbPluginKind, KubbUserConfig, KubbUserPlugin, LogLevel, LogLevels, LogType, Logger, OnExecute, OptionalPath, ParallelPluginError, ParseResult, Path, PathMode, PluginContext, PluginError, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PossiblePromise, Queue, QueueTask, Register, ResolveNameParams, ResolvePathParams, ResolvedFile, SafeParseResult, SchemaGenerator, Source, Status, Strategy, SummaryError, TransformResult, TreeNode, TreeNodeOptions, UUID, ValidationPluginError, Warning, build, canLogHierarchy, clean, combineFiles, createJSDocBlockText, createLogger, createPlugin, createPluginCache, build as default, defaultColours, defineConfig, extensions, getEncodedText, getFileSource, getLocation, getPathMode, getRelativePath, getStackTrace, getUniqueName, hooks, importModule, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, isURL, pluginName as name, nameSorter, normalizeDirectory, objectToParameters, pluginName, randomColour, randomPicoColour, read, renderTemplate, throttle, timeout, transformReservedWord, uniqueId, validatePlugins, write, writeIndexes };
|