@kubb/core 1.15.0-canary.20231023T125852 → 1.15.0-canary.20231024T104207
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 +447 -285
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +238 -168
- package/dist/index.d.ts +238 -168
- package/dist/index.js +427 -256
- package/dist/index.js.map +1 -1
- package/globals.d.ts +33 -16
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -47,8 +47,6 @@ declare class FunctionParams {
|
|
|
47
47
|
toString(): string;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
declare function getUniqueName(originalName: string, data: Record<string, number>): string;
|
|
51
|
-
|
|
52
50
|
declare function isPromise<T>(result: PossiblePromise<T>): result is Promise<T>;
|
|
53
51
|
declare function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T>;
|
|
54
52
|
declare function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & {
|
|
@@ -61,6 +59,11 @@ declare function createJSDocBlockText({ comments }: {
|
|
|
61
59
|
|
|
62
60
|
type LogType = 'error' | 'info' | 'warning';
|
|
63
61
|
type Logger = {
|
|
62
|
+
/**
|
|
63
|
+
* Optional config name to show in CLI output
|
|
64
|
+
*/
|
|
65
|
+
name?: string;
|
|
66
|
+
logLevel: LogLevel;
|
|
64
67
|
log: (message: string | null) => void;
|
|
65
68
|
error: (message: string | null) => void;
|
|
66
69
|
info: (message: string | null) => void;
|
|
@@ -68,22 +71,41 @@ type Logger = {
|
|
|
68
71
|
spinner?: Ora;
|
|
69
72
|
logs: string[];
|
|
70
73
|
};
|
|
71
|
-
|
|
74
|
+
type Props = {
|
|
75
|
+
name?: string;
|
|
76
|
+
logLevel: LogLevel;
|
|
77
|
+
spinner?: Ora;
|
|
78
|
+
};
|
|
79
|
+
declare function createLogger({ logLevel, name, spinner }: Props): Logger;
|
|
72
80
|
|
|
73
81
|
declare function nameSorter<T extends {
|
|
74
82
|
name: string;
|
|
75
83
|
}>(a: T, b: T): 0 | 1 | -1;
|
|
76
84
|
|
|
85
|
+
declare class EventEmitter<TEvents extends Record<string, any>> {
|
|
86
|
+
#private;
|
|
87
|
+
constructor();
|
|
88
|
+
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
|
|
89
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
90
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
91
|
+
removeAll(): void;
|
|
92
|
+
}
|
|
93
|
+
|
|
77
94
|
type QueueJob<T = unknown> = {
|
|
78
|
-
(...args: unknown[]): Promise<T
|
|
95
|
+
(...args: unknown[]): Promise<T | void>;
|
|
79
96
|
};
|
|
80
97
|
type RunOptions = {
|
|
81
98
|
controller?: AbortController;
|
|
82
99
|
name?: string;
|
|
83
100
|
description?: string;
|
|
84
101
|
};
|
|
102
|
+
type Events$1 = {
|
|
103
|
+
jobDone: [result: unknown];
|
|
104
|
+
jobFailed: [error: Error];
|
|
105
|
+
};
|
|
85
106
|
declare class Queue {
|
|
86
107
|
#private;
|
|
108
|
+
readonly eventEmitter: EventEmitter<Events$1>;
|
|
87
109
|
constructor(maxParallel: number, debug?: boolean);
|
|
88
110
|
run<T>(job: QueueJob<T>, options?: RunOptions): Promise<T>;
|
|
89
111
|
runSync<T>(job: QueueJob<T>, options?: RunOptions): void;
|
|
@@ -91,73 +113,10 @@ declare class Queue {
|
|
|
91
113
|
get count(): number;
|
|
92
114
|
}
|
|
93
115
|
|
|
94
|
-
declare const defaultColours: readonly ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"];
|
|
95
116
|
declare function randomColour(text?: string, colours?: readonly ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"]): string;
|
|
96
117
|
declare function randomPicoColour(text?: string, colors?: readonly ["black", "blue", "darkBlue", "cyan", "gray", "green", "darkGreen", "magenta", "red", "darkRed", "yellow", "darkYellow"]): string;
|
|
97
118
|
|
|
98
|
-
type BasePath<T extends string = string> = `${T}/`;
|
|
99
|
-
type CacheItem = KubbFile.ResolvedFile & {
|
|
100
|
-
cancel?: () => void;
|
|
101
|
-
};
|
|
102
|
-
declare namespace KubbFile {
|
|
103
|
-
type Import = {
|
|
104
|
-
name: string | Array<string>;
|
|
105
|
-
path: string;
|
|
106
|
-
isTypeOnly?: boolean;
|
|
107
|
-
};
|
|
108
|
-
type Export = {
|
|
109
|
-
name?: string | Array<string>;
|
|
110
|
-
path: string;
|
|
111
|
-
isTypeOnly?: boolean;
|
|
112
|
-
asAlias?: boolean;
|
|
113
|
-
};
|
|
114
|
-
type UUID = string;
|
|
115
|
-
type Source = string;
|
|
116
|
-
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
|
|
117
|
-
type Mode = 'file' | 'directory';
|
|
118
|
-
type BaseName = `${string}${Extname}`;
|
|
119
|
-
type Path = string;
|
|
120
|
-
type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
|
|
121
|
-
type OptionalPath = Path | undefined | null;
|
|
122
|
-
type File<TMeta extends {
|
|
123
|
-
pluginName?: string;
|
|
124
|
-
} = {
|
|
125
|
-
pluginName?: string;
|
|
126
|
-
}, TBaseName extends BaseName = BaseName> = {
|
|
127
|
-
/**
|
|
128
|
-
* Name to be used to dynamicly create the baseName(based on input.path)
|
|
129
|
-
* Based on UNIX basename
|
|
130
|
-
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
131
|
-
*/
|
|
132
|
-
baseName: TBaseName;
|
|
133
|
-
/**
|
|
134
|
-
* Path will be full qualified path to a specified file
|
|
135
|
-
*/
|
|
136
|
-
path: AdvancedPath<TBaseName> | Path;
|
|
137
|
-
source: Source;
|
|
138
|
-
imports?: Import[];
|
|
139
|
-
exports?: Export[];
|
|
140
|
-
/**
|
|
141
|
-
* This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
|
|
142
|
-
* @default `false`
|
|
143
|
-
*/
|
|
144
|
-
override?: boolean;
|
|
145
|
-
meta?: TMeta;
|
|
146
|
-
/**
|
|
147
|
-
* This will override `process.env[key]` inside the `source`, see `getFileSource`.
|
|
148
|
-
*/
|
|
149
|
-
env?: NodeJS.ProcessEnv;
|
|
150
|
-
};
|
|
151
|
-
type ResolvedFile = KubbFile.File & {
|
|
152
|
-
/**
|
|
153
|
-
* crypto.randomUUID()
|
|
154
|
-
*/
|
|
155
|
-
id: UUID;
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
119
|
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
120
|
declare function read(path: string): Promise<string>;
|
|
162
121
|
declare function readSync(path: string): string;
|
|
163
122
|
|
|
@@ -185,8 +144,18 @@ declare function escape(text?: string): string;
|
|
|
185
144
|
*/
|
|
186
145
|
declare function jsStringEscape(input: any): string;
|
|
187
146
|
|
|
147
|
+
declare function createIndent(size: number): string;
|
|
148
|
+
|
|
188
149
|
declare function transformReservedWord(word: string): string;
|
|
189
150
|
|
|
151
|
+
declare const transformers: {
|
|
152
|
+
readonly combineCodes: typeof combineCodes;
|
|
153
|
+
readonly escape: typeof escape;
|
|
154
|
+
readonly jsStringEscape: typeof jsStringEscape;
|
|
155
|
+
readonly createIndent: typeof createIndent;
|
|
156
|
+
readonly transformReservedWord: typeof transformReservedWord;
|
|
157
|
+
};
|
|
158
|
+
|
|
190
159
|
type TreeNodeOptions = DirectoryTreeOptions;
|
|
191
160
|
declare class TreeNode<T = unknown> {
|
|
192
161
|
data: T;
|
|
@@ -203,6 +172,9 @@ declare class TreeNode<T = unknown> {
|
|
|
203
172
|
|
|
204
173
|
declare const uniqueIdFactory: (counter: number) => (str?: string) => string;
|
|
205
174
|
|
|
175
|
+
declare function getUniqueName(originalName: string, data: Record<string, number>): string;
|
|
176
|
+
declare function setUniqueName(originalName: string, data: Record<string, number>): string;
|
|
177
|
+
|
|
206
178
|
type URLObject = {
|
|
207
179
|
url: string;
|
|
208
180
|
params?: Record<string, string>;
|
|
@@ -255,66 +227,113 @@ declare class Warning extends Error {
|
|
|
255
227
|
});
|
|
256
228
|
}
|
|
257
229
|
|
|
258
|
-
declare function write(data: string, path: string): Promise<
|
|
230
|
+
declare function write(data: string, path: string): Promise<string | undefined>;
|
|
259
231
|
|
|
232
|
+
type BasePath<T extends string = string> = `${T}/`;
|
|
233
|
+
declare namespace KubbFile {
|
|
234
|
+
type Import = {
|
|
235
|
+
name: string | Array<string>;
|
|
236
|
+
path: string;
|
|
237
|
+
isTypeOnly?: boolean;
|
|
238
|
+
};
|
|
239
|
+
type Export = {
|
|
240
|
+
name?: string | Array<string>;
|
|
241
|
+
path: string;
|
|
242
|
+
isTypeOnly?: boolean;
|
|
243
|
+
asAlias?: boolean;
|
|
244
|
+
};
|
|
245
|
+
type UUID = string;
|
|
246
|
+
type Source = string;
|
|
247
|
+
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
|
|
248
|
+
type Mode = 'file' | 'directory';
|
|
249
|
+
type BaseName = `${string}${Extname}`;
|
|
250
|
+
type Path = string;
|
|
251
|
+
type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
|
|
252
|
+
type OptionalPath = Path | undefined | null;
|
|
253
|
+
type File<TMeta extends {
|
|
254
|
+
pluginKey?: KubbPlugin['key'];
|
|
255
|
+
} = {
|
|
256
|
+
pluginKey?: KubbPlugin['key'];
|
|
257
|
+
}, TBaseName extends BaseName = BaseName> = {
|
|
258
|
+
/**
|
|
259
|
+
* Name to be used to dynamicly create the baseName(based on input.path)
|
|
260
|
+
* Based on UNIX basename
|
|
261
|
+
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
262
|
+
*/
|
|
263
|
+
baseName: TBaseName;
|
|
264
|
+
/**
|
|
265
|
+
* Path will be full qualified path to a specified file
|
|
266
|
+
*/
|
|
267
|
+
path: AdvancedPath<TBaseName> | Path;
|
|
268
|
+
source: Source;
|
|
269
|
+
imports?: Import[];
|
|
270
|
+
exports?: Export[];
|
|
271
|
+
/**
|
|
272
|
+
* This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
|
|
273
|
+
* @default `false`
|
|
274
|
+
*/
|
|
275
|
+
override?: boolean;
|
|
276
|
+
meta?: TMeta;
|
|
277
|
+
/**
|
|
278
|
+
* This will override `process.env[key]` inside the `source`, see `getFileSource`.
|
|
279
|
+
*/
|
|
280
|
+
env?: NodeJS.ProcessEnv;
|
|
281
|
+
};
|
|
282
|
+
type ResolvedFile = KubbFile.File & {
|
|
283
|
+
/**
|
|
284
|
+
* crypto.randomUUID()
|
|
285
|
+
*/
|
|
286
|
+
id: UUID;
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
type IndexesOptions = {
|
|
291
|
+
treeNode?: TreeNodeOptions;
|
|
292
|
+
isTypeOnly?: boolean;
|
|
293
|
+
filter?: (file: KubbFile.File) => boolean;
|
|
294
|
+
map?: (file: KubbFile.File) => KubbFile.File;
|
|
295
|
+
includeExt?: boolean;
|
|
296
|
+
output?: string;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
type AddIndexesProps = {
|
|
300
|
+
root: KubbFile.Path;
|
|
301
|
+
extName?: KubbFile.Extname;
|
|
302
|
+
options?: IndexesOptions;
|
|
303
|
+
meta?: KubbFile.File['meta'];
|
|
304
|
+
};
|
|
305
|
+
type Options$1 = {
|
|
306
|
+
queue?: Queue;
|
|
307
|
+
task?: QueueJob<KubbFile.ResolvedFile>;
|
|
308
|
+
/**
|
|
309
|
+
* Timeout between writes
|
|
310
|
+
*/
|
|
311
|
+
timeout?: number;
|
|
312
|
+
};
|
|
260
313
|
declare class FileManager {
|
|
261
314
|
#private;
|
|
262
|
-
constructor(options?:
|
|
263
|
-
queue?: Queue;
|
|
264
|
-
task?: QueueJob<KubbFile.ResolvedFile>;
|
|
265
|
-
});
|
|
315
|
+
constructor(options?: Options$1);
|
|
266
316
|
get extensions(): Array<KubbFile.Extname>;
|
|
267
317
|
get files(): Array<KubbFile.File>;
|
|
268
318
|
get isExecuting(): boolean;
|
|
269
319
|
add(file: KubbFile.File): Promise<KubbFile.ResolvedFile>;
|
|
270
320
|
addOrAppend(file: KubbFile.File): Promise<KubbFile.ResolvedFile>;
|
|
271
|
-
addIndexes(root
|
|
321
|
+
addIndexes({ root, extName, meta, options }: AddIndexesProps): Promise<Array<KubbFile.File> | undefined>;
|
|
272
322
|
getCacheByUUID(UUID: KubbFile.UUID): KubbFile.File | undefined;
|
|
273
323
|
get(path: KubbFile.Path): Array<KubbFile.File> | undefined;
|
|
274
324
|
remove(path: KubbFile.Path): void;
|
|
275
|
-
write(...params: Parameters<typeof write>): Promise<
|
|
325
|
+
write(...params: Parameters<typeof write>): Promise<string | undefined>;
|
|
276
326
|
read(...params: Parameters<typeof read>): Promise<string>;
|
|
327
|
+
static getSource(file: KubbFile.File): string;
|
|
328
|
+
static combineFiles(files: Array<KubbFile.File | null>): Array<KubbFile.File>;
|
|
329
|
+
static getMode(path: string | undefined | null): KubbFile.Mode;
|
|
277
330
|
}
|
|
278
331
|
|
|
279
|
-
|
|
280
|
-
declare function
|
|
281
|
-
|
|
282
|
-
|
|
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>;
|
|
332
|
+
type SeqOutput<TInput extends Array<PromiseFunc<TPromise, null>>, TPromise = unknown> = ReturnType<NonNullable<TInput[number]>>;
|
|
333
|
+
declare function hookSeq<TInput extends Array<PromiseFunc<TPromise, null>>, TPromise = unknown, TOutput = SeqOutput<TInput, TPromise>>(promises: TInput): TOutput;
|
|
334
|
+
declare const executeStrategies: {
|
|
335
|
+
readonly hookSeq: typeof hookSeq;
|
|
293
336
|
};
|
|
294
|
-
declare class PackageManager {
|
|
295
|
-
#private;
|
|
296
|
-
constructor(workspace?: string);
|
|
297
|
-
set workspace(workspace: string);
|
|
298
|
-
get workspace(): string | undefined;
|
|
299
|
-
normalizeDirectory(directory: string): string;
|
|
300
|
-
getLocation(path: string): string;
|
|
301
|
-
import(path: string): Promise<any | undefined>;
|
|
302
|
-
getPackageJSON(): Promise<PackageJSON | undefined>;
|
|
303
|
-
getPackageJSONSync(): PackageJSON | undefined;
|
|
304
|
-
getVersion(dependency: string): Promise<string | undefined>;
|
|
305
|
-
getVersionSync(dependency: string): string | undefined;
|
|
306
|
-
isValid(dependency: string, version: string): Promise<boolean>;
|
|
307
|
-
isValidSync(dependency: string, version: string): boolean;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
declare class EventEmitter<TEvents extends Record<string, any>> {
|
|
311
|
-
#private;
|
|
312
|
-
constructor();
|
|
313
|
-
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
|
|
314
|
-
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
315
|
-
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
316
|
-
removeAll(): void;
|
|
317
|
-
}
|
|
318
337
|
|
|
319
338
|
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
320
339
|
/**
|
|
@@ -337,11 +356,17 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
|
|
|
337
356
|
};
|
|
338
357
|
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<RequiredPluginLifecycle[H]>;
|
|
339
358
|
|
|
340
|
-
declare const hooks: [keyof PluginLifecycle<PluginFactoryOptions<string, unknown, false, unknown, Record<string, unknown>>>];
|
|
341
|
-
type Options
|
|
342
|
-
debug?: boolean;
|
|
343
|
-
task: QueueJob<KubbFile.ResolvedFile>;
|
|
359
|
+
declare const hooks: [keyof PluginLifecycle<PluginFactoryOptions<string, KubbPluginKind, unknown, false, unknown, Record<string, unknown>>>];
|
|
360
|
+
type Options = {
|
|
344
361
|
logger: Logger;
|
|
362
|
+
/**
|
|
363
|
+
* Task for the FileManager
|
|
364
|
+
*/
|
|
365
|
+
task: QueueJob<KubbFile.ResolvedFile>;
|
|
366
|
+
/**
|
|
367
|
+
* Timeout between writes in the FileManager
|
|
368
|
+
*/
|
|
369
|
+
writeTimeout?: number;
|
|
345
370
|
};
|
|
346
371
|
type Events = {
|
|
347
372
|
execute: [executer: Executer];
|
|
@@ -356,23 +381,24 @@ declare class PluginManager {
|
|
|
356
381
|
readonly queue: Queue;
|
|
357
382
|
readonly executed: Executer[];
|
|
358
383
|
readonly logger: Logger;
|
|
359
|
-
|
|
384
|
+
usedPluginNames: Record<string, number>;
|
|
385
|
+
constructor(config: KubbConfig, options: Options);
|
|
360
386
|
resolvePath: (params: ResolvePathParams) => KubbFile.OptionalPath;
|
|
361
387
|
resolveName: (params: ResolveNameParams) => string;
|
|
362
388
|
on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
|
|
363
389
|
/**
|
|
364
390
|
* Run only hook for a specific plugin name
|
|
365
391
|
*/
|
|
366
|
-
hookForPlugin<H extends PluginLifecycleHooks>({
|
|
367
|
-
|
|
392
|
+
hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
393
|
+
pluginKey: KubbPlugin['key'];
|
|
368
394
|
hookName: H;
|
|
369
395
|
parameters: PluginParameter<H>;
|
|
370
|
-
}): Promise<ReturnType<ParseResult<H>> | null
|
|
371
|
-
hookForPluginSync<H extends PluginLifecycleHooks>({
|
|
372
|
-
|
|
396
|
+
}): Promise<Array<ReturnType<ParseResult<H>> | null>> | null;
|
|
397
|
+
hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
398
|
+
pluginKey: KubbPlugin['key'];
|
|
373
399
|
hookName: H;
|
|
374
400
|
parameters: PluginParameter<H>;
|
|
375
|
-
}): ReturnType<ParseResult<H
|
|
401
|
+
}): Array<ReturnType<ParseResult<H>>> | null;
|
|
376
402
|
/**
|
|
377
403
|
* Chains, first non-null result stops and returns
|
|
378
404
|
*/
|
|
@@ -411,7 +437,7 @@ declare class PluginManager {
|
|
|
411
437
|
hookName: H;
|
|
412
438
|
parameters?: PluginParameter<H>;
|
|
413
439
|
}): Promise<void>;
|
|
414
|
-
|
|
440
|
+
getPluginsByKey(hookName: keyof PluginLifecycle, pluginKey: KubbPlugin['key']): KubbPlugin[];
|
|
415
441
|
}
|
|
416
442
|
|
|
417
443
|
declare class PluginError extends Error {
|
|
@@ -458,7 +484,7 @@ type KubbUserConfig = Omit<KubbConfig, 'root' | 'plugins'> & {
|
|
|
458
484
|
* Example: ['@kubb/swagger', { output: false }]
|
|
459
485
|
* Or: createSwagger({ output: false })
|
|
460
486
|
*/
|
|
461
|
-
plugins?: Array<
|
|
487
|
+
plugins?: Array<Omit<KubbUserPlugin, 'api'> | KubbUnionPlugins | [name: string, options: object]>;
|
|
462
488
|
};
|
|
463
489
|
type InputPath = {
|
|
464
490
|
/**
|
|
@@ -476,14 +502,18 @@ type Input = InputPath | InputData;
|
|
|
476
502
|
/**
|
|
477
503
|
* @private
|
|
478
504
|
*/
|
|
479
|
-
type KubbConfig = {
|
|
505
|
+
type KubbConfig<TInput = Input> = {
|
|
506
|
+
/**
|
|
507
|
+
* Optional config name to show in CLI output
|
|
508
|
+
*/
|
|
509
|
+
name?: string;
|
|
480
510
|
/**
|
|
481
511
|
* Project root directory. Can be an absolute path, or a path relative from
|
|
482
512
|
* the location of the config file itself.
|
|
483
513
|
* @default process.cwd()
|
|
484
514
|
*/
|
|
485
515
|
root: string;
|
|
486
|
-
input:
|
|
516
|
+
input: TInput;
|
|
487
517
|
output: {
|
|
488
518
|
/**
|
|
489
519
|
* Path to be used to export all generated files.
|
|
@@ -544,40 +574,50 @@ type BuildOutput = {
|
|
|
544
574
|
pluginManager: PluginManager;
|
|
545
575
|
};
|
|
546
576
|
type KubbPluginKind = 'schema' | 'controller';
|
|
547
|
-
type
|
|
548
|
-
type KubbObjectPlugin = keyof
|
|
549
|
-
type
|
|
550
|
-
[K in keyof Kubb.OptionsPlugins]: Kubb.OptionsPlugins[K] | object;
|
|
551
|
-
};
|
|
577
|
+
type KubbUnionPlugins = PluginUnion;
|
|
578
|
+
type KubbObjectPlugin = keyof OptionsPlugins;
|
|
579
|
+
type GetPluginFactoryOptions<TPlugin extends KubbUserPlugin> = TPlugin extends KubbUserPlugin<infer X> ? X : never;
|
|
552
580
|
type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
553
581
|
/**
|
|
554
582
|
* Unique name used for the plugin
|
|
555
583
|
* @example @kubb/typescript
|
|
556
584
|
*/
|
|
557
|
-
name:
|
|
585
|
+
name: TOptions['name'];
|
|
586
|
+
/**
|
|
587
|
+
* Internal key used when a developer uses more than one of the same plugin
|
|
588
|
+
* @private
|
|
589
|
+
*/
|
|
590
|
+
key?: TOptions['key'];
|
|
558
591
|
/**
|
|
559
592
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
560
593
|
*/
|
|
561
594
|
options: TOptions['options'] extends never ? undefined : TOptions['options'];
|
|
595
|
+
} & Partial<PluginLifecycle<TOptions>> & (TOptions['api'] extends never ? {
|
|
596
|
+
api?: never;
|
|
597
|
+
} : {
|
|
598
|
+
api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext, 'addFile'>) => TOptions['api'];
|
|
599
|
+
}) & (TOptions['kind'] extends never ? {
|
|
600
|
+
kind?: never;
|
|
601
|
+
} : {
|
|
562
602
|
/**
|
|
563
603
|
* Kind/type for the plugin
|
|
564
604
|
* Type 'schema' can be used for JSON schema's, TypeScript types, ...
|
|
565
605
|
* Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
|
|
566
606
|
* @default undefined
|
|
567
607
|
*/
|
|
568
|
-
kind
|
|
569
|
-
} & Partial<PluginLifecycle<TOptions>> & (TOptions['api'] extends never ? {
|
|
570
|
-
api?: never;
|
|
571
|
-
} : {
|
|
572
|
-
api: (this: Omit<PluginContext, 'addFile'>) => TOptions['api'];
|
|
608
|
+
kind: TOptions['kind'];
|
|
573
609
|
});
|
|
574
610
|
type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
575
611
|
/**
|
|
576
612
|
* Unique name used for the plugin
|
|
577
613
|
* @example @kubb/typescript
|
|
578
614
|
*/
|
|
579
|
-
name:
|
|
580
|
-
|
|
615
|
+
name: TOptions['name'];
|
|
616
|
+
/**
|
|
617
|
+
* Internal key used when a developer uses more than one of the same plugin
|
|
618
|
+
* @private
|
|
619
|
+
*/
|
|
620
|
+
key: TOptions['key'];
|
|
581
621
|
/**
|
|
582
622
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
583
623
|
*/
|
|
@@ -594,8 +634,13 @@ type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
594
634
|
} : {
|
|
595
635
|
api: TOptions['api'];
|
|
596
636
|
});
|
|
597
|
-
type PluginFactoryOptions<Name = string, Options = unknown | never, Nested extends boolean = false, API = unknown | never, resolvePathOptions = Record<string, unknown>> = {
|
|
637
|
+
type PluginFactoryOptions<Name = string, Kind extends KubbPluginKind = KubbPluginKind | never, Options = unknown | never, Nested extends boolean = false, API = unknown | never, resolvePathOptions = Record<string, unknown>> = {
|
|
598
638
|
name: Name;
|
|
639
|
+
kind: Kind;
|
|
640
|
+
/**
|
|
641
|
+
* Same like `QueryKey` in `@tanstack/react-query`
|
|
642
|
+
*/
|
|
643
|
+
key: [kind: Kind | undefined, name: Name, identifier?: string | number];
|
|
599
644
|
options: Options;
|
|
600
645
|
nested: Nested;
|
|
601
646
|
api: API;
|
|
@@ -640,7 +685,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
640
685
|
* Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
|
|
641
686
|
* @type hookParallel
|
|
642
687
|
*/
|
|
643
|
-
writeFile?: (this: Omit<PluginContext, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<void>;
|
|
688
|
+
writeFile?: (this: Omit<PluginContext, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<string | void>;
|
|
644
689
|
/**
|
|
645
690
|
* End of the plugin lifecycle.
|
|
646
691
|
* @type hookParallel
|
|
@@ -650,11 +695,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
650
695
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
651
696
|
type PluginCache = Record<string, [number, unknown]>;
|
|
652
697
|
type ResolvePathParams<TOptions = Record<string, unknown>> = {
|
|
653
|
-
|
|
654
|
-
* When set, resolvePath will only call resolvePath of the name of the plugin set here.
|
|
655
|
-
* If not defined it will fall back on the resolvePath of the core plugin.
|
|
656
|
-
*/
|
|
657
|
-
pluginName?: string;
|
|
698
|
+
pluginKey?: KubbPlugin['key'];
|
|
658
699
|
baseName: string;
|
|
659
700
|
directory?: string | undefined;
|
|
660
701
|
/**
|
|
@@ -664,11 +705,7 @@ type ResolvePathParams<TOptions = Record<string, unknown>> = {
|
|
|
664
705
|
};
|
|
665
706
|
type ResolveNameParams = {
|
|
666
707
|
name: string;
|
|
667
|
-
|
|
668
|
-
* When set, resolvePath will only call resolvePath of the name of the plugin set here.
|
|
669
|
-
* If not defined it will fall back on the resolvePath of the core plugin.
|
|
670
|
-
*/
|
|
671
|
-
pluginName?: string;
|
|
708
|
+
pluginKey?: KubbPlugin['key'];
|
|
672
709
|
type?: 'file' | 'function';
|
|
673
710
|
};
|
|
674
711
|
type PluginContext<TOptions = Record<string, unknown>> = {
|
|
@@ -680,7 +717,14 @@ type PluginContext<TOptions = Record<string, unknown>> = {
|
|
|
680
717
|
resolvePath: (params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
681
718
|
resolveName: (params: ResolveNameParams) => string;
|
|
682
719
|
logger: Logger;
|
|
720
|
+
/**
|
|
721
|
+
* All plugins
|
|
722
|
+
*/
|
|
683
723
|
plugins: KubbPlugin[];
|
|
724
|
+
/**
|
|
725
|
+
* Current plugin
|
|
726
|
+
*/
|
|
727
|
+
plugin: KubbPlugin;
|
|
684
728
|
};
|
|
685
729
|
type TransformResult = string | null;
|
|
686
730
|
declare const LogLevel: {
|
|
@@ -696,6 +740,13 @@ type Prettify<T> = {
|
|
|
696
740
|
[K in keyof T]: T[K];
|
|
697
741
|
} & {};
|
|
698
742
|
type PossiblePromise<T> = Promise<T> | T;
|
|
743
|
+
type PromiseFunc<T, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
744
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
745
|
+
type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never;
|
|
746
|
+
type Push<T extends any[], V> = [...T, V];
|
|
747
|
+
type TuplifyUnion<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<TuplifyUnion<Exclude<T, L>>, L>;
|
|
748
|
+
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;
|
|
749
|
+
type TupleToUnion<T> = T extends Array<infer ITEMS> ? ITEMS : never;
|
|
699
750
|
|
|
700
751
|
type BuildOptions = {
|
|
701
752
|
config: PluginContext['config'];
|
|
@@ -703,7 +754,6 @@ type BuildOptions = {
|
|
|
703
754
|
* @default Logger without the spinner
|
|
704
755
|
*/
|
|
705
756
|
logger?: Logger;
|
|
706
|
-
logLevel?: LogLevel;
|
|
707
757
|
};
|
|
708
758
|
declare function build(options: BuildOptions): Promise<BuildOutput>;
|
|
709
759
|
|
|
@@ -712,9 +762,10 @@ declare function build(options: BuildOptions): Promise<BuildOutput>;
|
|
|
712
762
|
* accepts a direct {@link KubbConfig} object, or a function that returns it.
|
|
713
763
|
* The function receives a {@link ConfigEnv} object that exposes two properties:
|
|
714
764
|
*/
|
|
715
|
-
declare function defineConfig(options: PossiblePromise<KubbUserConfig
|
|
765
|
+
declare function defineConfig(options: PossiblePromise<KubbUserConfig | Array<KubbUserConfig>> | ((
|
|
716
766
|
/** The options derived from the CLI flags */
|
|
717
|
-
cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig
|
|
767
|
+
cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig | Array<KubbUserConfig>>)): typeof options;
|
|
768
|
+
declare function isInputPath(result: KubbConfig | undefined): result is KubbConfig<InputPath>;
|
|
718
769
|
|
|
719
770
|
/**
|
|
720
771
|
* Abstract class that contains the building blocks for plugins to create their own Generator
|
|
@@ -736,19 +787,38 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
|
|
|
736
787
|
abstract build(schema: TInput, name: string, description?: string): TOutput;
|
|
737
788
|
}
|
|
738
789
|
|
|
739
|
-
type
|
|
790
|
+
type PackageJSON = {
|
|
791
|
+
dependencies?: Record<string, string>;
|
|
792
|
+
devDependencies?: Record<string, string>;
|
|
793
|
+
};
|
|
794
|
+
declare class PackageManager {
|
|
795
|
+
#private;
|
|
796
|
+
constructor(workspace?: string);
|
|
797
|
+
set workspace(workspace: string);
|
|
798
|
+
get workspace(): string | undefined;
|
|
799
|
+
normalizeDirectory(directory: string): string;
|
|
800
|
+
getLocation(path: string): string;
|
|
801
|
+
import(path: string): Promise<any | undefined>;
|
|
802
|
+
getPackageJSON(): Promise<PackageJSON | undefined>;
|
|
803
|
+
getPackageJSONSync(): PackageJSON | undefined;
|
|
804
|
+
getVersion(dependency: string): Promise<string | undefined>;
|
|
805
|
+
getVersionSync(dependency: string): string | undefined;
|
|
806
|
+
isValid(dependency: string, version: string): Promise<boolean>;
|
|
807
|
+
isValidSync(dependency: string, version: string): boolean;
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => KubbUserPlugin<T>;
|
|
740
811
|
declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
getPlugins: () => KubbPlugin[];
|
|
749
|
-
plugin: KubbPlugin;
|
|
812
|
+
declare const pluginName = "core";
|
|
813
|
+
|
|
814
|
+
interface _Register {
|
|
815
|
+
}
|
|
816
|
+
type Plugins = _Register;
|
|
817
|
+
type OptionsPlugins = {
|
|
818
|
+
[K in keyof Plugins]: Plugins[K]['options'];
|
|
750
819
|
};
|
|
751
|
-
type
|
|
752
|
-
|
|
820
|
+
type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
|
|
821
|
+
type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
|
|
822
|
+
type Plugin = keyof Plugins;
|
|
753
823
|
|
|
754
|
-
export { AppMeta,
|
|
824
|
+
export { AppMeta, BuildOutput, CLIOptions, Cache, FileManager, FunctionParams, FunctionParamsAST, Generator, GetPluginFactoryOptions, InputData, InputPath, KubbConfig, KubbFile, KubbObjectPlugin, KubbPlugin, KubbPluginKind, KubbUnionPlugins, KubbUserConfig, KubbUserPlugin, LogLevel, LogType, Logger, ObjValueTuple, OptionsOfPlugin, OptionsPlugins, PackageManager, ParallelPluginError, Plugin, PluginCache, PluginContext, PluginError, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PluginUnion, Plugins, PossiblePromise, Prettify, PromiseFunc, Queue, QueueJob, ResolveNameParams, ResolvePathParams, SchemaGenerator, SummaryError, TransformResult, TreeNode, TreeNodeOptions, TupleToUnion, URLObject, URLPath, ValidationPluginError, Warning, _Register, build, clean, createJSDocBlockText, createLogger, createPlugin, createPluginCache, build as default, defineConfig, executeStrategies, getDependedPlugins, getRelativePath, getUniqueName, hooks, isInputPath, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, pluginName as name, nameSorter, pluginName, randomColour, randomPicoColour, read, readSync, renderTemplate, setUniqueName, throttle, timeout, transformers, uniqueIdFactory, write };
|