@kubb/core 1.15.0-canary.20231025T103357 → 1.15.0-canary.20231025T123615
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 +241 -171
- package/dist/index.d.ts +241 -171
- package/dist/index.js +427 -256
- package/dist/index.js.map +1 -1
- package/globals.d.ts +33 -16
- package/package.json +3 -3
package/dist/index.d.cts
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,69 +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
|
-
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
|
-
}
|
|
321
337
|
|
|
322
338
|
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
323
339
|
/**
|
|
@@ -340,11 +356,17 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
|
|
|
340
356
|
};
|
|
341
357
|
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<RequiredPluginLifecycle[H]>;
|
|
342
358
|
|
|
343
|
-
declare const hooks: [keyof PluginLifecycle<PluginFactoryOptions<string, unknown, false, unknown, Record<string, unknown>>>];
|
|
344
|
-
type Options
|
|
345
|
-
debug?: boolean;
|
|
346
|
-
task: QueueJob<KubbFile.ResolvedFile>;
|
|
359
|
+
declare const hooks: [keyof PluginLifecycle<PluginFactoryOptions<string, KubbPluginKind, unknown, false, unknown, Record<string, unknown>>>];
|
|
360
|
+
type Options = {
|
|
347
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;
|
|
348
370
|
};
|
|
349
371
|
type Events = {
|
|
350
372
|
execute: [executer: Executer];
|
|
@@ -359,23 +381,24 @@ declare class PluginManager {
|
|
|
359
381
|
readonly queue: Queue;
|
|
360
382
|
readonly executed: Executer[];
|
|
361
383
|
readonly logger: Logger;
|
|
362
|
-
|
|
384
|
+
usedPluginNames: Record<string, number>;
|
|
385
|
+
constructor(config: KubbConfig, options: Options);
|
|
363
386
|
resolvePath: (params: ResolvePathParams) => KubbFile.OptionalPath;
|
|
364
387
|
resolveName: (params: ResolveNameParams) => string;
|
|
365
388
|
on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
|
|
366
389
|
/**
|
|
367
390
|
* Run only hook for a specific plugin name
|
|
368
391
|
*/
|
|
369
|
-
hookForPlugin<H extends PluginLifecycleHooks>({
|
|
370
|
-
|
|
392
|
+
hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
393
|
+
pluginKey: KubbPlugin['key'];
|
|
371
394
|
hookName: H;
|
|
372
395
|
parameters: PluginParameter<H>;
|
|
373
|
-
}): Promise<ReturnType<ParseResult<H>> | null
|
|
374
|
-
hookForPluginSync<H extends PluginLifecycleHooks>({
|
|
375
|
-
|
|
396
|
+
}): Promise<Array<ReturnType<ParseResult<H>> | null>> | null;
|
|
397
|
+
hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
398
|
+
pluginKey: KubbPlugin['key'];
|
|
376
399
|
hookName: H;
|
|
377
400
|
parameters: PluginParameter<H>;
|
|
378
|
-
}): ReturnType<ParseResult<H
|
|
401
|
+
}): Array<ReturnType<ParseResult<H>>> | null;
|
|
379
402
|
/**
|
|
380
403
|
* Chains, first non-null result stops and returns
|
|
381
404
|
*/
|
|
@@ -414,7 +437,7 @@ declare class PluginManager {
|
|
|
414
437
|
hookName: H;
|
|
415
438
|
parameters?: PluginParameter<H>;
|
|
416
439
|
}): Promise<void>;
|
|
417
|
-
|
|
440
|
+
getPluginsByKey(hookName: keyof PluginLifecycle, pluginKey: KubbPlugin['key']): KubbPlugin[];
|
|
418
441
|
}
|
|
419
442
|
|
|
420
443
|
declare class PluginError extends Error {
|
|
@@ -461,7 +484,7 @@ type KubbUserConfig = Omit<KubbConfig, 'root' | 'plugins'> & {
|
|
|
461
484
|
* Example: ['@kubb/swagger', { output: false }]
|
|
462
485
|
* Or: createSwagger({ output: false })
|
|
463
486
|
*/
|
|
464
|
-
plugins?: Array<
|
|
487
|
+
plugins?: Array<Omit<KubbUserPlugin, 'api'> | KubbUnionPlugins | [name: string, options: object]>;
|
|
465
488
|
};
|
|
466
489
|
type InputPath = {
|
|
467
490
|
/**
|
|
@@ -479,14 +502,18 @@ type Input = InputPath | InputData;
|
|
|
479
502
|
/**
|
|
480
503
|
* @private
|
|
481
504
|
*/
|
|
482
|
-
type KubbConfig = {
|
|
505
|
+
type KubbConfig<TInput = Input> = {
|
|
506
|
+
/**
|
|
507
|
+
* Optional config name to show in CLI output
|
|
508
|
+
*/
|
|
509
|
+
name?: string;
|
|
483
510
|
/**
|
|
484
511
|
* Project root directory. Can be an absolute path, or a path relative from
|
|
485
512
|
* the location of the config file itself.
|
|
486
513
|
* @default process.cwd()
|
|
487
514
|
*/
|
|
488
515
|
root: string;
|
|
489
|
-
input:
|
|
516
|
+
input: TInput;
|
|
490
517
|
output: {
|
|
491
518
|
/**
|
|
492
519
|
* Path to be used to export all generated files.
|
|
@@ -547,40 +574,50 @@ type BuildOutput = {
|
|
|
547
574
|
pluginManager: PluginManager;
|
|
548
575
|
};
|
|
549
576
|
type KubbPluginKind = 'schema' | 'controller';
|
|
550
|
-
type
|
|
551
|
-
type KubbObjectPlugin = keyof
|
|
552
|
-
type
|
|
553
|
-
[K in keyof Kubb.OptionsPlugins]: Kubb.OptionsPlugins[K] | object;
|
|
554
|
-
};
|
|
577
|
+
type KubbUnionPlugins = PluginUnion;
|
|
578
|
+
type KubbObjectPlugin = keyof OptionsPlugins;
|
|
579
|
+
type GetPluginFactoryOptions<TPlugin extends KubbUserPlugin> = TPlugin extends KubbUserPlugin<infer X> ? X : never;
|
|
555
580
|
type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
556
581
|
/**
|
|
557
582
|
* Unique name used for the plugin
|
|
558
583
|
* @example @kubb/typescript
|
|
559
584
|
*/
|
|
560
|
-
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'];
|
|
561
591
|
/**
|
|
562
592
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
563
593
|
*/
|
|
564
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
|
+
} : {
|
|
565
602
|
/**
|
|
566
603
|
* Kind/type for the plugin
|
|
567
604
|
* Type 'schema' can be used for JSON schema's, TypeScript types, ...
|
|
568
605
|
* Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
|
|
569
606
|
* @default undefined
|
|
570
607
|
*/
|
|
571
|
-
kind
|
|
572
|
-
} & Partial<PluginLifecycle<TOptions>> & (TOptions['api'] extends never ? {
|
|
573
|
-
api?: never;
|
|
574
|
-
} : {
|
|
575
|
-
api: (this: Omit<PluginContext, 'addFile'>) => TOptions['api'];
|
|
608
|
+
kind: TOptions['kind'];
|
|
576
609
|
});
|
|
577
610
|
type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
578
611
|
/**
|
|
579
612
|
* Unique name used for the plugin
|
|
580
613
|
* @example @kubb/typescript
|
|
581
614
|
*/
|
|
582
|
-
name:
|
|
583
|
-
|
|
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'];
|
|
584
621
|
/**
|
|
585
622
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
586
623
|
*/
|
|
@@ -597,8 +634,13 @@ type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
597
634
|
} : {
|
|
598
635
|
api: TOptions['api'];
|
|
599
636
|
});
|
|
600
|
-
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>> = {
|
|
601
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];
|
|
602
644
|
options: Options;
|
|
603
645
|
nested: Nested;
|
|
604
646
|
api: API;
|
|
@@ -643,7 +685,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
643
685
|
* Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
|
|
644
686
|
* @type hookParallel
|
|
645
687
|
*/
|
|
646
|
-
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>;
|
|
647
689
|
/**
|
|
648
690
|
* End of the plugin lifecycle.
|
|
649
691
|
* @type hookParallel
|
|
@@ -653,11 +695,7 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
|
|
|
653
695
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
654
696
|
type PluginCache = Record<string, [number, unknown]>;
|
|
655
697
|
type ResolvePathParams<TOptions = Record<string, unknown>> = {
|
|
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;
|
|
698
|
+
pluginKey?: KubbPlugin['key'];
|
|
661
699
|
baseName: string;
|
|
662
700
|
directory?: string | undefined;
|
|
663
701
|
/**
|
|
@@ -667,11 +705,7 @@ type ResolvePathParams<TOptions = Record<string, unknown>> = {
|
|
|
667
705
|
};
|
|
668
706
|
type ResolveNameParams = {
|
|
669
707
|
name: string;
|
|
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;
|
|
708
|
+
pluginKey?: KubbPlugin['key'];
|
|
675
709
|
type?: 'file' | 'function';
|
|
676
710
|
};
|
|
677
711
|
type PluginContext<TOptions = Record<string, unknown>> = {
|
|
@@ -683,7 +717,14 @@ type PluginContext<TOptions = Record<string, unknown>> = {
|
|
|
683
717
|
resolvePath: (params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
684
718
|
resolveName: (params: ResolveNameParams) => string;
|
|
685
719
|
logger: Logger;
|
|
720
|
+
/**
|
|
721
|
+
* All plugins
|
|
722
|
+
*/
|
|
686
723
|
plugins: KubbPlugin[];
|
|
724
|
+
/**
|
|
725
|
+
* Current plugin
|
|
726
|
+
*/
|
|
727
|
+
plugin: KubbPlugin;
|
|
687
728
|
};
|
|
688
729
|
type TransformResult = string | null;
|
|
689
730
|
declare const LogLevel: {
|
|
@@ -699,6 +740,13 @@ type Prettify<T> = {
|
|
|
699
740
|
[K in keyof T]: T[K];
|
|
700
741
|
} & {};
|
|
701
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;
|
|
702
750
|
|
|
703
751
|
type BuildOptions = {
|
|
704
752
|
config: PluginContext['config'];
|
|
@@ -706,7 +754,6 @@ type BuildOptions = {
|
|
|
706
754
|
* @default Logger without the spinner
|
|
707
755
|
*/
|
|
708
756
|
logger?: Logger;
|
|
709
|
-
logLevel?: LogLevel;
|
|
710
757
|
};
|
|
711
758
|
declare function build(options: BuildOptions): Promise<BuildOutput>;
|
|
712
759
|
|
|
@@ -715,9 +762,10 @@ declare function build(options: BuildOptions): Promise<BuildOutput>;
|
|
|
715
762
|
* accepts a direct {@link KubbConfig} object, or a function that returns it.
|
|
716
763
|
* The function receives a {@link ConfigEnv} object that exposes two properties:
|
|
717
764
|
*/
|
|
718
|
-
declare function defineConfig(options: PossiblePromise<KubbUserConfig
|
|
765
|
+
declare function defineConfig(options: PossiblePromise<KubbUserConfig | Array<KubbUserConfig>> | ((
|
|
719
766
|
/** The options derived from the CLI flags */
|
|
720
|
-
cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig
|
|
767
|
+
cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig | Array<KubbUserConfig>>)): typeof options;
|
|
768
|
+
declare function isInputPath(result: KubbConfig | undefined): result is KubbConfig<InputPath>;
|
|
721
769
|
|
|
722
770
|
/**
|
|
723
771
|
* Abstract class that contains the building blocks for plugins to create their own Generator
|
|
@@ -739,19 +787,41 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
|
|
|
739
787
|
abstract build(schema: TInput, name: string, description?: string): TOutput;
|
|
740
788
|
}
|
|
741
789
|
|
|
742
|
-
type
|
|
790
|
+
type PackageJSON = {
|
|
791
|
+
dependencies?: Record<string, string>;
|
|
792
|
+
devDependencies?: Record<string, string>;
|
|
793
|
+
};
|
|
794
|
+
type DependencyName = string;
|
|
795
|
+
type DependencyVersion = string;
|
|
796
|
+
declare class PackageManager {
|
|
797
|
+
#private;
|
|
798
|
+
constructor(workspace?: string);
|
|
799
|
+
set workspace(workspace: string);
|
|
800
|
+
get workspace(): string | undefined;
|
|
801
|
+
normalizeDirectory(directory: string): string;
|
|
802
|
+
getLocation(path: string): string;
|
|
803
|
+
import(path: string): Promise<any | undefined>;
|
|
804
|
+
getPackageJSON(): Promise<PackageJSON | undefined>;
|
|
805
|
+
getPackageJSONSync(): PackageJSON | undefined;
|
|
806
|
+
static setVersion(dependency: DependencyName, version: DependencyVersion): void;
|
|
807
|
+
getVersion(dependency: DependencyName): Promise<DependencyVersion | undefined>;
|
|
808
|
+
getVersionSync(dependency: DependencyName): DependencyVersion | undefined;
|
|
809
|
+
isValid(dependency: DependencyName, version: DependencyVersion): Promise<boolean>;
|
|
810
|
+
isValidSync(dependency: DependencyName, version: DependencyVersion): boolean;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => KubbUserPlugin<T>;
|
|
743
814
|
declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
getPlugins: () => KubbPlugin[];
|
|
752
|
-
plugin: KubbPlugin;
|
|
815
|
+
declare const pluginName = "core";
|
|
816
|
+
|
|
817
|
+
interface _Register {
|
|
818
|
+
}
|
|
819
|
+
type Plugins = _Register;
|
|
820
|
+
type OptionsPlugins = {
|
|
821
|
+
[K in keyof Plugins]: Plugins[K]['options'];
|
|
753
822
|
};
|
|
754
|
-
type
|
|
755
|
-
|
|
823
|
+
type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
|
|
824
|
+
type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
|
|
825
|
+
type Plugin = keyof Plugins;
|
|
756
826
|
|
|
757
|
-
export { AppMeta,
|
|
827
|
+
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 };
|