@kubb/core 1.15.0-canary.20231112T135011 → 2.0.0-alpha.10
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/README.md +1 -1
- package/dist/index.cjs +1253 -1088
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +396 -411
- package/dist/index.d.ts +396 -411
- package/dist/index.js +1194 -1018
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +1272 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +239 -0
- package/dist/utils.d.ts +239 -0
- package/dist/utils.js +1219 -0
- package/dist/utils.js.map +1 -0
- package/globals.d.ts +33 -16
- package/package.json +21 -14
- package/src/BarrelManager.ts +123 -0
- package/src/FileManager.ts +524 -0
- package/src/Generator.ts +34 -0
- package/src/PackageManager.ts +178 -0
- package/src/PluginManager.ts +629 -0
- package/src/PromiseManager.ts +51 -0
- package/src/SchemaGenerator.ts +8 -0
- package/src/build.ts +207 -0
- package/src/config.ts +22 -0
- package/src/errors.ts +12 -0
- package/src/index.ts +28 -0
- package/src/plugin.ts +80 -0
- package/src/types.ts +353 -0
- package/src/utils/EventEmitter.ts +24 -0
- package/src/utils/FunctionParams.ts +85 -0
- package/src/utils/Queue.ts +110 -0
- package/src/utils/TreeNode.ts +122 -0
- package/src/utils/URLPath.ts +133 -0
- package/src/utils/cache.ts +35 -0
- package/src/utils/clean.ts +5 -0
- package/src/utils/executeStrategies.ts +83 -0
- package/src/utils/index.ts +19 -0
- package/src/utils/logger.ts +76 -0
- package/src/utils/promise.ts +13 -0
- package/src/utils/randomColour.ts +39 -0
- package/src/utils/read.ts +68 -0
- package/src/utils/renderTemplate.ts +31 -0
- package/src/utils/throttle.ts +30 -0
- package/src/utils/timeout.ts +7 -0
- package/src/utils/transformers/combineCodes.ts +3 -0
- package/src/utils/transformers/createJSDocBlockText.ts +15 -0
- package/src/utils/transformers/escape.ts +31 -0
- package/src/utils/transformers/indent.ts +3 -0
- package/src/utils/transformers/index.ts +22 -0
- package/src/utils/transformers/nameSorter.ts +9 -0
- package/src/utils/transformers/searchAndReplace.ts +25 -0
- package/src/utils/transformers/transformReservedWord.ts +97 -0
- package/src/utils/transformers/trim.ts +3 -0
- package/src/utils/uniqueName.ts +20 -0
- package/src/utils/write.ts +63 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,89 +1,44 @@
|
|
|
1
|
+
import { PossiblePromise, GreaterThan, TupleToUnion, ObjValueTuple } from '@kubb/types';
|
|
1
2
|
import { DirectoryTreeOptions } from 'directory-tree';
|
|
2
3
|
import { Ora } from 'ora';
|
|
3
|
-
export { default as pc } from 'picocolors';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
delete(id: keyof TStore): boolean;
|
|
7
|
-
get(id: keyof TStore): TStore[keyof TStore] | null;
|
|
8
|
-
has(id: keyof TStore): boolean;
|
|
9
|
-
set(id: keyof TStore, value: unknown): void;
|
|
10
|
-
}
|
|
11
|
-
declare function createPluginCache<TStore extends PluginCache>(Store?: TStore): Cache<TStore>;
|
|
12
|
-
|
|
13
|
-
declare function clean(path: string): Promise<void>;
|
|
14
|
-
|
|
15
|
-
type FunctionParamsASTWithoutType = {
|
|
16
|
-
name?: string;
|
|
17
|
-
type?: string;
|
|
18
|
-
/**
|
|
19
|
-
* @default true
|
|
20
|
-
*/
|
|
21
|
-
required?: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* @default true
|
|
24
|
-
*/
|
|
25
|
-
enabled?: boolean;
|
|
26
|
-
default?: string;
|
|
27
|
-
};
|
|
28
|
-
type FunctionParamsASTWithType = {
|
|
29
|
-
name?: never;
|
|
30
|
-
type: string;
|
|
31
|
-
/**
|
|
32
|
-
* @default true
|
|
33
|
-
*/
|
|
34
|
-
required?: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* @default true
|
|
37
|
-
*/
|
|
38
|
-
enabled?: boolean;
|
|
39
|
-
default?: string;
|
|
40
|
-
};
|
|
41
|
-
type FunctionParamsAST = FunctionParamsASTWithoutType | FunctionParamsASTWithType;
|
|
42
|
-
declare class FunctionParams {
|
|
43
|
-
type?: 'generics' | 'typed';
|
|
44
|
-
items: FunctionParamsAST[];
|
|
45
|
-
constructor(type?: 'generics' | 'typed');
|
|
46
|
-
add(item: FunctionParamsAST | Array<FunctionParamsAST | undefined> | undefined): FunctionParams;
|
|
47
|
-
toString(): string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
declare function getUniqueName(originalName: string, data: Record<string, number>): string;
|
|
51
|
-
|
|
52
|
-
declare function isPromise<T>(result: PossiblePromise<T>): result is Promise<T>;
|
|
53
|
-
declare function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T>;
|
|
54
|
-
declare function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & {
|
|
55
|
-
reason: T;
|
|
56
|
-
};
|
|
5
|
+
declare function read(path: string): Promise<string>;
|
|
57
6
|
|
|
58
|
-
declare function
|
|
59
|
-
comments: Array<string>;
|
|
60
|
-
}): string;
|
|
7
|
+
declare function write(data: string, path: string): Promise<string | undefined>;
|
|
61
8
|
|
|
62
|
-
type
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
logs: string[];
|
|
9
|
+
type BarrelManagerOptions = {
|
|
10
|
+
treeNode?: DirectoryTreeOptions;
|
|
11
|
+
isTypeOnly?: boolean;
|
|
12
|
+
filter?: (file: KubbFile.File) => boolean;
|
|
13
|
+
map?: (file: KubbFile.File) => KubbFile.File;
|
|
14
|
+
includeExt?: boolean;
|
|
15
|
+
output?: string;
|
|
70
16
|
};
|
|
71
|
-
declare function createLogger(spinner?: Ora): Logger;
|
|
72
17
|
|
|
73
|
-
declare
|
|
74
|
-
|
|
75
|
-
|
|
18
|
+
declare class EventEmitter<TEvents extends Record<string, any>> {
|
|
19
|
+
#private;
|
|
20
|
+
constructor();
|
|
21
|
+
emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
|
|
22
|
+
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
23
|
+
off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
|
|
24
|
+
removeAll(): void;
|
|
25
|
+
}
|
|
76
26
|
|
|
77
27
|
type QueueJob<T = unknown> = {
|
|
78
|
-
(...args: unknown[]): Promise<T
|
|
28
|
+
(...args: unknown[]): Promise<T | void>;
|
|
79
29
|
};
|
|
80
30
|
type RunOptions = {
|
|
81
31
|
controller?: AbortController;
|
|
82
32
|
name?: string;
|
|
83
33
|
description?: string;
|
|
84
34
|
};
|
|
35
|
+
type Events$1 = {
|
|
36
|
+
jobDone: [result: unknown];
|
|
37
|
+
jobFailed: [error: Error];
|
|
38
|
+
};
|
|
85
39
|
declare class Queue {
|
|
86
40
|
#private;
|
|
41
|
+
readonly eventEmitter: EventEmitter<Events$1>;
|
|
87
42
|
constructor(maxParallel: number, debug?: boolean);
|
|
88
43
|
run<T>(job: QueueJob<T>, options?: RunOptions): Promise<T>;
|
|
89
44
|
runSync<T>(job: QueueJob<T>, options?: RunOptions): void;
|
|
@@ -91,233 +46,25 @@ declare class Queue {
|
|
|
91
46
|
get count(): number;
|
|
92
47
|
}
|
|
93
48
|
|
|
94
|
-
declare const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
declare function getRelativePath(rootDir?: string | null, filePath?: string | null, platform?: 'windows' | 'mac' | 'linux'): string;
|
|
160
|
-
declare function getPathMode(path: string | undefined | null): KubbFile.Mode;
|
|
161
|
-
declare function read(path: string): Promise<string>;
|
|
162
|
-
declare function readSync(path: string): string;
|
|
163
|
-
|
|
164
|
-
declare function renderTemplate<TData extends Record<string, unknown> = Record<string, unknown>>(template: string, data?: TData | undefined): string;
|
|
165
|
-
|
|
166
|
-
declare class SummaryError extends Error {
|
|
167
|
-
summary: string[];
|
|
168
|
-
constructor(message: string, options: {
|
|
169
|
-
cause: Error;
|
|
170
|
-
summary?: string[];
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
declare const throttle: <R, A extends any[]>(fn: (...args: A) => R, delay: number) => [(...args: A) => R | undefined, () => void];
|
|
175
|
-
|
|
176
|
-
declare function timeout(ms: number): Promise<unknown>;
|
|
177
|
-
|
|
178
|
-
declare function combineCodes(codes: string[]): string;
|
|
179
|
-
|
|
180
|
-
declare function escape(text?: string): string;
|
|
181
|
-
/**
|
|
182
|
-
* Escape all characters not included in SingleStringCharacters and DoubleStringCharacters on
|
|
183
|
-
* @link http://www.ecma-international.org/ecma-262/5.1/#sec-7.8.4
|
|
184
|
-
* @link https://github.com/joliss/js-string-escape/blob/master/index.js
|
|
185
|
-
*/
|
|
186
|
-
declare function jsStringEscape(input: any): string;
|
|
187
|
-
|
|
188
|
-
declare function transformReservedWord(word: string): string;
|
|
189
|
-
|
|
190
|
-
type TreeNodeOptions = DirectoryTreeOptions;
|
|
191
|
-
declare class TreeNode<T = unknown> {
|
|
192
|
-
data: T;
|
|
193
|
-
parent?: TreeNode<T>;
|
|
194
|
-
children: Array<TreeNode<T>>;
|
|
195
|
-
constructor(data: T, parent?: TreeNode<T>);
|
|
196
|
-
addChild(data: T): TreeNode<T>;
|
|
197
|
-
find(data?: T): TreeNode<T> | null;
|
|
198
|
-
get leaves(): TreeNode<T>[];
|
|
199
|
-
get root(): TreeNode<T>;
|
|
200
|
-
forEach(callback: (treeNode: TreeNode<T>) => void): this;
|
|
201
|
-
static build<T = unknown>(path: string, options?: TreeNodeOptions): TreeNode<T> | null;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
declare const uniqueIdFactory: (counter: number) => (str?: string) => string;
|
|
205
|
-
|
|
206
|
-
type URLObject = {
|
|
207
|
-
url: string;
|
|
208
|
-
params?: Record<string, string>;
|
|
209
|
-
};
|
|
210
|
-
type ObjectOptions = {
|
|
211
|
-
type?: 'path' | 'template';
|
|
212
|
-
replacer?: (pathParam: string) => string;
|
|
213
|
-
stringify?: boolean;
|
|
49
|
+
declare const LogLevel: {
|
|
50
|
+
readonly silent: "silent";
|
|
51
|
+
readonly info: "info";
|
|
52
|
+
readonly debug: "debug";
|
|
214
53
|
};
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
constructor(path: string);
|
|
218
|
-
/**
|
|
219
|
-
* Convert Swagger path to URLPath(syntax of Express)
|
|
220
|
-
* @example /pet/{petId} => /pet/:petId
|
|
221
|
-
*/
|
|
222
|
-
get URL(): string;
|
|
223
|
-
get isURL(): boolean;
|
|
224
|
-
/**
|
|
225
|
-
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
226
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
227
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
228
|
-
* @example /account/userID => `/account/${userId}`
|
|
229
|
-
*/
|
|
230
|
-
get template(): string;
|
|
231
|
-
get object(): URLObject | string;
|
|
232
|
-
get params(): Record<string, string> | undefined;
|
|
233
|
-
toObject({ type, replacer, stringify }?: ObjectOptions): URLObject | string;
|
|
234
|
-
/**
|
|
235
|
-
* Convert Swagger path to template literals/ template strings(camelcase)
|
|
236
|
-
* @example /pet/{petId} => `/pet/${petId}`
|
|
237
|
-
* @example /account/monetary-accountID => `/account/${monetaryAccountId}`
|
|
238
|
-
* @example /account/userID => `/account/${userId}`
|
|
239
|
-
*/
|
|
240
|
-
toTemplateString(replacer?: (pathParam: string) => string): string;
|
|
241
|
-
getParams(replacer?: (pathParam: string) => string): Record<string, string> | undefined;
|
|
54
|
+
type LogLevel = keyof typeof LogLevel;
|
|
55
|
+
type Logger = {
|
|
242
56
|
/**
|
|
243
|
-
*
|
|
244
|
-
* @example /pet/{petId} => /pet/:petId
|
|
57
|
+
* Optional config name to show in CLI output
|
|
245
58
|
*/
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
cause: Error;
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
declare function write(data: string, path: string): Promise<void>;
|
|
259
|
-
|
|
260
|
-
declare class FileManager {
|
|
261
|
-
#private;
|
|
262
|
-
constructor(options?: {
|
|
263
|
-
queue?: Queue;
|
|
264
|
-
task?: QueueJob<KubbFile.ResolvedFile>;
|
|
265
|
-
});
|
|
266
|
-
get extensions(): Array<KubbFile.Extname>;
|
|
267
|
-
get files(): Array<KubbFile.File>;
|
|
268
|
-
get isExecuting(): boolean;
|
|
269
|
-
add(file: KubbFile.File): Promise<KubbFile.ResolvedFile>;
|
|
270
|
-
addOrAppend(file: KubbFile.File): Promise<KubbFile.ResolvedFile>;
|
|
271
|
-
addIndexes(root: KubbFile.Path, extName?: KubbFile.Extname, options?: TreeNodeOptions): Promise<Array<KubbFile.File> | undefined>;
|
|
272
|
-
getCacheByUUID(UUID: KubbFile.UUID): KubbFile.File | undefined;
|
|
273
|
-
get(path: KubbFile.Path): Array<KubbFile.File> | undefined;
|
|
274
|
-
remove(path: KubbFile.Path): void;
|
|
275
|
-
write(...params: Parameters<typeof write>): Promise<void>;
|
|
276
|
-
read(...params: Parameters<typeof read>): Promise<string>;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
declare function getIndexes(root: string, extName?: KubbFile.Extname, options?: TreeNodeOptions): Array<KubbFile.File> | null;
|
|
280
|
-
declare function combineFiles(files: Array<KubbFile.File | null>): Array<KubbFile.File>;
|
|
281
|
-
/**
|
|
282
|
-
* Support for js, ts and tsx(React)
|
|
283
|
-
*/
|
|
284
|
-
declare const extensions: Array<KubbFile.Extname>;
|
|
285
|
-
declare function isExtensionAllowed(baseName: string): boolean;
|
|
286
|
-
declare function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export>;
|
|
287
|
-
declare function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source: string): Array<KubbFile.Import>;
|
|
288
|
-
declare function createFileSource(file: KubbFile.File): string;
|
|
289
|
-
|
|
290
|
-
type PackageJSON = {
|
|
291
|
-
dependencies?: Record<string, string>;
|
|
292
|
-
devDependencies?: Record<string, string>;
|
|
59
|
+
name?: string;
|
|
60
|
+
logLevel: LogLevel;
|
|
61
|
+
log: (message: string | null) => void;
|
|
62
|
+
error: (message: string | null) => void;
|
|
63
|
+
info: (message: string | null) => void;
|
|
64
|
+
warn: (message: string | null) => void;
|
|
65
|
+
spinner?: Ora;
|
|
66
|
+
logs: string[];
|
|
293
67
|
};
|
|
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
68
|
|
|
322
69
|
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
323
70
|
/**
|
|
@@ -325,9 +72,9 @@ type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
|
325
72
|
* @example Arg0<(a: string, b: number) => void> -> string
|
|
326
73
|
*/
|
|
327
74
|
type Argument0<H extends keyof PluginLifecycle> = Parameters<RequiredPluginLifecycle[H]>[0];
|
|
328
|
-
type Strategy = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq';
|
|
75
|
+
type Strategy$1 = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq';
|
|
329
76
|
type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
330
|
-
strategy: Strategy;
|
|
77
|
+
strategy: Strategy$1;
|
|
331
78
|
hookName: H;
|
|
332
79
|
plugin: KubbPlugin;
|
|
333
80
|
parameters?: unknown[] | undefined;
|
|
@@ -338,44 +85,48 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
|
|
|
338
85
|
result: Result;
|
|
339
86
|
plugin: KubbPlugin;
|
|
340
87
|
};
|
|
341
|
-
type
|
|
342
|
-
|
|
343
|
-
declare const hooks: [keyof PluginLifecycle<PluginFactoryOptions<string, unknown, false, unknown, Record<string, unknown>>>];
|
|
344
|
-
type Options$1 = {
|
|
345
|
-
debug?: boolean;
|
|
346
|
-
task: QueueJob<KubbFile.ResolvedFile>;
|
|
88
|
+
type Options$2 = {
|
|
347
89
|
logger: Logger;
|
|
90
|
+
/**
|
|
91
|
+
* Task for the FileManager
|
|
92
|
+
*/
|
|
93
|
+
task: QueueJob<KubbFile.ResolvedFile>;
|
|
94
|
+
/**
|
|
95
|
+
* Timeout between writes in the FileManager
|
|
96
|
+
*/
|
|
97
|
+
writeTimeout?: number;
|
|
348
98
|
};
|
|
349
99
|
type Events = {
|
|
350
100
|
execute: [executer: Executer];
|
|
351
101
|
executed: [executer: Executer];
|
|
352
|
-
error: [
|
|
102
|
+
error: [error: Error];
|
|
353
103
|
};
|
|
354
104
|
declare class PluginManager {
|
|
355
105
|
#private;
|
|
356
|
-
plugins:
|
|
106
|
+
readonly plugins: KubbPluginWithLifeCycle[];
|
|
357
107
|
readonly fileManager: FileManager;
|
|
358
108
|
readonly eventEmitter: EventEmitter<Events>;
|
|
359
109
|
readonly queue: Queue;
|
|
110
|
+
readonly config: KubbConfig;
|
|
360
111
|
readonly executed: Executer[];
|
|
361
112
|
readonly logger: Logger;
|
|
362
|
-
constructor(config: KubbConfig, options: Options$
|
|
363
|
-
resolvePath: (params: ResolvePathParams) => KubbFile.OptionalPath;
|
|
113
|
+
constructor(config: KubbConfig, options: Options$2);
|
|
114
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
364
115
|
resolveName: (params: ResolveNameParams) => string;
|
|
365
116
|
on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
|
|
366
117
|
/**
|
|
367
118
|
* Run only hook for a specific plugin name
|
|
368
119
|
*/
|
|
369
|
-
hookForPlugin<H extends PluginLifecycleHooks>({
|
|
370
|
-
|
|
120
|
+
hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
121
|
+
pluginKey: KubbPlugin['key'];
|
|
371
122
|
hookName: H;
|
|
372
123
|
parameters: PluginParameter<H>;
|
|
373
|
-
}): Promise<ReturnType<ParseResult<H>> | null
|
|
374
|
-
hookForPluginSync<H extends PluginLifecycleHooks>({
|
|
375
|
-
|
|
124
|
+
}): Promise<Array<ReturnType<ParseResult<H>> | null>> | null;
|
|
125
|
+
hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
126
|
+
pluginKey: KubbPlugin['key'];
|
|
376
127
|
hookName: H;
|
|
377
128
|
parameters: PluginParameter<H>;
|
|
378
|
-
}): ReturnType<ParseResult<H
|
|
129
|
+
}): Array<ReturnType<ParseResult<H>>> | null;
|
|
379
130
|
/**
|
|
380
131
|
* Chains, first non-null result stops and returns
|
|
381
132
|
*/
|
|
@@ -414,32 +165,17 @@ declare class PluginManager {
|
|
|
414
165
|
hookName: H;
|
|
415
166
|
parameters?: PluginParameter<H>;
|
|
416
167
|
}): Promise<void>;
|
|
417
|
-
|
|
168
|
+
getPluginsByKey(hookName: keyof PluginLifecycle, pluginKey: KubbPlugin['key']): KubbPlugin[];
|
|
169
|
+
static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = T3 extends never ? T2 extends never ? [T1: KubbPlugin<T1>] : [T1: KubbPlugin<T1>, T2: KubbPlugin<T2>] : [T1: KubbPlugin<T1>, T2: KubbPlugin<T2>, T3: KubbPlugin<T3>]>(plugins: Array<KubbPlugin>, dependedPluginNames: string | string[]): TOutput;
|
|
170
|
+
static get hooks(): readonly ["validate", "buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
|
|
418
171
|
}
|
|
419
172
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
pluginManager: PluginManager;
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
declare class ParallelPluginError extends Error {
|
|
430
|
-
errors: PluginError[];
|
|
431
|
-
pluginManager: PluginManager;
|
|
432
|
-
constructor(message: string, options: {
|
|
433
|
-
cause?: Error;
|
|
434
|
-
errors: PluginError[];
|
|
435
|
-
pluginManager: PluginManager;
|
|
436
|
-
});
|
|
437
|
-
findError<T extends Error = Error>(searchError: T | undefined): T | undefined;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
declare class ValidationPluginError extends Error {
|
|
173
|
+
interface Cache<TStore extends object = object> {
|
|
174
|
+
delete(id: keyof TStore): boolean;
|
|
175
|
+
get(id: keyof TStore): TStore[keyof TStore] | null;
|
|
176
|
+
has(id: keyof TStore): boolean;
|
|
177
|
+
set(id: keyof TStore, value: unknown): void;
|
|
441
178
|
}
|
|
442
|
-
declare function getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = T3 extends never ? T2 extends never ? [T1: KubbPlugin<T1>] : [T1: KubbPlugin<T1>, T2: KubbPlugin<T2>] : [T1: KubbPlugin<T1>, T2: KubbPlugin<T2>, T3: KubbPlugin<T3>]>(plugins: Array<KubbPlugin>, dependedPluginNames: string | string[]): TOutput;
|
|
443
179
|
|
|
444
180
|
/**
|
|
445
181
|
* Config used in `kubb.config.js`
|
|
@@ -461,7 +197,7 @@ type KubbUserConfig = Omit<KubbConfig, 'root' | 'plugins'> & {
|
|
|
461
197
|
* Example: ['@kubb/swagger', { output: false }]
|
|
462
198
|
* Or: createSwagger({ output: false })
|
|
463
199
|
*/
|
|
464
|
-
plugins?: Array<
|
|
200
|
+
plugins?: Array<Omit<UnknownKubbUserPlugin, 'api'> | KubbUnionPlugins | [name: string, options: object]>;
|
|
465
201
|
};
|
|
466
202
|
type InputPath = {
|
|
467
203
|
/**
|
|
@@ -479,14 +215,18 @@ type Input = InputPath | InputData;
|
|
|
479
215
|
/**
|
|
480
216
|
* @private
|
|
481
217
|
*/
|
|
482
|
-
type KubbConfig = {
|
|
218
|
+
type KubbConfig<TInput = Input> = {
|
|
219
|
+
/**
|
|
220
|
+
* Optional config name to show in CLI output
|
|
221
|
+
*/
|
|
222
|
+
name?: string;
|
|
483
223
|
/**
|
|
484
224
|
* Project root directory. Can be an absolute path, or a path relative from
|
|
485
225
|
* the location of the config file itself.
|
|
486
226
|
* @default process.cwd()
|
|
487
227
|
*/
|
|
488
228
|
root: string;
|
|
489
|
-
input:
|
|
229
|
+
input: TInput;
|
|
490
230
|
output: {
|
|
491
231
|
/**
|
|
492
232
|
* Path to be used to export all generated files.
|
|
@@ -542,122 +282,168 @@ type CLIOptions = {
|
|
|
542
282
|
*/
|
|
543
283
|
logLevel?: LogLevel;
|
|
544
284
|
};
|
|
545
|
-
type BuildOutput = {
|
|
546
|
-
files: FileManager['files'];
|
|
547
|
-
pluginManager: PluginManager;
|
|
548
|
-
};
|
|
549
285
|
type KubbPluginKind = 'schema' | 'controller';
|
|
550
|
-
type
|
|
551
|
-
type KubbObjectPlugin = keyof
|
|
552
|
-
type
|
|
553
|
-
|
|
286
|
+
type KubbUnionPlugins = PluginUnion;
|
|
287
|
+
type KubbObjectPlugin = keyof OptionsPlugins;
|
|
288
|
+
type PluginFactoryOptions<
|
|
289
|
+
/**
|
|
290
|
+
* Name to be used for the plugin, this will also be used for they key.
|
|
291
|
+
*/
|
|
292
|
+
TName extends string = string,
|
|
293
|
+
/**
|
|
294
|
+
* @type "schema" | "controller"
|
|
295
|
+
*/
|
|
296
|
+
TKind extends KubbPluginKind = KubbPluginKind,
|
|
297
|
+
/**
|
|
298
|
+
* Options of the plugin.
|
|
299
|
+
*/
|
|
300
|
+
TOptions extends object = object,
|
|
301
|
+
/**
|
|
302
|
+
* Options of the plugin that can be used later on, see `options` inside your plugin config.
|
|
303
|
+
*/
|
|
304
|
+
TResolvedOptions extends object = TOptions,
|
|
305
|
+
/**
|
|
306
|
+
* API that you want to expose to other plugins.
|
|
307
|
+
*/
|
|
308
|
+
TAPI = any,
|
|
309
|
+
/**
|
|
310
|
+
* When calling `resolvePath` you can specify better types.
|
|
311
|
+
*/
|
|
312
|
+
TResolvePathOptions extends object = object,
|
|
313
|
+
/**
|
|
314
|
+
* When using @kubb/react(based on React) you can specify here which types should be used when calling render.
|
|
315
|
+
* Always extend from `AppMeta` of the core.
|
|
316
|
+
*/
|
|
317
|
+
TAppMeta = unknown> = {
|
|
318
|
+
name: TName;
|
|
319
|
+
kind: TKind;
|
|
320
|
+
/**
|
|
321
|
+
* Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
|
|
322
|
+
*/
|
|
323
|
+
key: [kind: TKind | undefined, name: TName | string, identifier?: string | number];
|
|
324
|
+
options: TOptions;
|
|
325
|
+
resolvedOptions: TResolvedOptions;
|
|
326
|
+
api: TAPI;
|
|
327
|
+
resolvePathOptions: TResolvePathOptions;
|
|
328
|
+
appMeta: {
|
|
329
|
+
pluginManager: PluginManager;
|
|
330
|
+
plugin: KubbPlugin<PluginFactoryOptions<TName, TKind, TOptions, TResolvedOptions, TAPI, TResolvePathOptions, TAppMeta>>;
|
|
331
|
+
} & TAppMeta;
|
|
554
332
|
};
|
|
333
|
+
type GetPluginFactoryOptions<TPlugin extends KubbUserPlugin> = TPlugin extends KubbUserPlugin<infer X> ? X : never;
|
|
555
334
|
type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
556
335
|
/**
|
|
557
336
|
* Unique name used for the plugin
|
|
558
337
|
* @example @kubb/typescript
|
|
559
338
|
*/
|
|
560
|
-
name:
|
|
339
|
+
name: TOptions['name'];
|
|
340
|
+
/**
|
|
341
|
+
* Internal key used when a developer uses more than one of the same plugin
|
|
342
|
+
* @private
|
|
343
|
+
*/
|
|
344
|
+
key?: TOptions['key'];
|
|
561
345
|
/**
|
|
562
346
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
563
347
|
*/
|
|
564
|
-
options: TOptions['
|
|
348
|
+
options: TOptions['resolvedOptions'];
|
|
349
|
+
} & (TOptions['api'] extends never ? {
|
|
350
|
+
api?: never;
|
|
351
|
+
} : {
|
|
352
|
+
api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['api'];
|
|
353
|
+
}) & (TOptions['kind'] extends never ? {
|
|
354
|
+
kind?: never;
|
|
355
|
+
} : {
|
|
565
356
|
/**
|
|
566
357
|
* Kind/type for the plugin
|
|
358
|
+
*
|
|
567
359
|
* Type 'schema' can be used for JSON schema's, TypeScript types, ...
|
|
360
|
+
*
|
|
568
361
|
* Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
|
|
569
362
|
* @default undefined
|
|
570
363
|
*/
|
|
571
|
-
kind
|
|
572
|
-
} & Partial<PluginLifecycle<TOptions>> & (TOptions['api'] extends never ? {
|
|
573
|
-
api?: never;
|
|
574
|
-
} : {
|
|
575
|
-
api: (this: Omit<PluginContext, 'addFile'>) => TOptions['api'];
|
|
364
|
+
kind: TOptions['kind'];
|
|
576
365
|
});
|
|
366
|
+
type KubbUserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbUserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
367
|
+
type UnknownKubbUserPlugin = KubbUserPlugin<PluginFactoryOptions<any, any, any, any, any, any, any>>;
|
|
577
368
|
type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
578
369
|
/**
|
|
579
370
|
* Unique name used for the plugin
|
|
580
371
|
* @example @kubb/typescript
|
|
581
372
|
*/
|
|
582
|
-
name:
|
|
583
|
-
|
|
373
|
+
name: TOptions['name'];
|
|
374
|
+
/**
|
|
375
|
+
* Internal key used when a developer uses more than one of the same plugin
|
|
376
|
+
* @private
|
|
377
|
+
*/
|
|
378
|
+
key: TOptions['key'];
|
|
584
379
|
/**
|
|
585
380
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
586
381
|
*/
|
|
587
|
-
options: TOptions['
|
|
382
|
+
options: TOptions['resolvedOptions'];
|
|
588
383
|
/**
|
|
589
384
|
* Kind/type for the plugin
|
|
590
385
|
* Type 'schema' can be used for JSON schema's, TypeScript types, ...
|
|
591
386
|
* Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
|
|
592
387
|
* @default undefined
|
|
593
388
|
*/
|
|
594
|
-
kind?:
|
|
595
|
-
} &
|
|
389
|
+
kind?: TOptions['kind'];
|
|
390
|
+
} & (TOptions['api'] extends never ? {
|
|
596
391
|
api?: never;
|
|
597
392
|
} : {
|
|
598
393
|
api: TOptions['api'];
|
|
599
394
|
});
|
|
600
|
-
type
|
|
601
|
-
name: Name;
|
|
602
|
-
options: Options;
|
|
603
|
-
nested: Nested;
|
|
604
|
-
api: API;
|
|
605
|
-
resolvePathOptions: resolvePathOptions;
|
|
606
|
-
};
|
|
395
|
+
type KubbPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
607
396
|
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
608
397
|
/**
|
|
609
398
|
* Valdiate all plugins to see if their depended plugins are installed and configured.
|
|
610
399
|
* @type hookParallel
|
|
611
400
|
*/
|
|
612
|
-
validate?: (this: Omit<PluginContext
|
|
401
|
+
validate?: (this: Omit<PluginContext<TOptions>, 'addFile'>, plugins: NonNullable<KubbConfig['plugins']>) => PossiblePromise<true>;
|
|
613
402
|
/**
|
|
614
403
|
* Start of the lifecycle of a plugin.
|
|
615
404
|
* @type hookParallel
|
|
616
405
|
*/
|
|
617
|
-
buildStart?: (this: PluginContext
|
|
406
|
+
buildStart?: (this: PluginContext<TOptions>, kubbConfig: KubbConfig) => PossiblePromise<void>;
|
|
618
407
|
/**
|
|
619
408
|
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
620
409
|
* Options can als be included.
|
|
621
410
|
* @type hookFirst
|
|
622
411
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
623
412
|
*/
|
|
624
|
-
resolvePath?: (this: PluginContext
|
|
413
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: string, directory?: string, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
|
|
625
414
|
/**
|
|
626
415
|
* Resolve to a name based on a string.
|
|
627
416
|
* Useful when converting to PascalCase or camelCase.
|
|
628
417
|
* @type hookFirst
|
|
629
418
|
* @example ('pet') => 'Pet'
|
|
630
419
|
*/
|
|
631
|
-
resolveName?: (this: PluginContext
|
|
420
|
+
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
632
421
|
/**
|
|
633
422
|
* Makes it possible to run async logic to override the path defined previously by `resolvePath`.
|
|
634
423
|
* @type hookFirst
|
|
635
424
|
*/
|
|
636
|
-
load?: (this: Omit<PluginContext
|
|
425
|
+
load?: (this: Omit<PluginContext<TOptions>, 'addFile'>, path: KubbFile.Path) => PossiblePromise<TransformResult | null>;
|
|
637
426
|
/**
|
|
638
427
|
* Transform the source-code.
|
|
639
428
|
* @type hookReduceArg0
|
|
640
429
|
*/
|
|
641
|
-
transform?: (this: Omit<PluginContext
|
|
430
|
+
transform?: (this: Omit<PluginContext<TOptions>, 'addFile'>, source: string, path: KubbFile.Path) => PossiblePromise<TransformResult>;
|
|
642
431
|
/**
|
|
643
432
|
* Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
|
|
644
433
|
* @type hookParallel
|
|
645
434
|
*/
|
|
646
|
-
writeFile?: (this: Omit<PluginContext
|
|
435
|
+
writeFile?: (this: Omit<PluginContext<TOptions>, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<string | void>;
|
|
647
436
|
/**
|
|
648
437
|
* End of the plugin lifecycle.
|
|
649
438
|
* @type hookParallel
|
|
650
439
|
*/
|
|
651
|
-
buildEnd?: (this: PluginContext) => PossiblePromise<void>;
|
|
440
|
+
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
652
441
|
};
|
|
653
442
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
443
|
+
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
654
444
|
type PluginCache = Record<string, [number, unknown]>;
|
|
655
|
-
type ResolvePathParams<TOptions =
|
|
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;
|
|
445
|
+
type ResolvePathParams<TOptions = object> = {
|
|
446
|
+
pluginKey?: KubbPlugin['key'];
|
|
661
447
|
baseName: string;
|
|
662
448
|
directory?: string | undefined;
|
|
663
449
|
/**
|
|
@@ -667,38 +453,177 @@ type ResolvePathParams<TOptions = Record<string, unknown>> = {
|
|
|
667
453
|
};
|
|
668
454
|
type ResolveNameParams = {
|
|
669
455
|
name: string;
|
|
456
|
+
pluginKey?: KubbPlugin['key'];
|
|
670
457
|
/**
|
|
671
|
-
*
|
|
672
|
-
*
|
|
458
|
+
* `file` will be used to customize the name of the created file(use of camelCase)
|
|
459
|
+
* `function` can be used used to customize the exported functions(use of camelCase)
|
|
460
|
+
* `type` is a special type for TypeScript(use of PascalCase)
|
|
673
461
|
*/
|
|
674
|
-
|
|
675
|
-
type?: 'file' | 'function';
|
|
462
|
+
type?: 'file' | 'function' | 'type';
|
|
676
463
|
};
|
|
677
|
-
type PluginContext<TOptions =
|
|
464
|
+
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
678
465
|
config: KubbConfig;
|
|
679
466
|
cache: Cache<PluginCache>;
|
|
680
467
|
fileManager: FileManager;
|
|
681
468
|
pluginManager: PluginManager;
|
|
682
469
|
addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.File>>;
|
|
683
|
-
resolvePath: (params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
470
|
+
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
|
|
684
471
|
resolveName: (params: ResolveNameParams) => string;
|
|
685
472
|
logger: Logger;
|
|
473
|
+
/**
|
|
474
|
+
* All plugins
|
|
475
|
+
*/
|
|
686
476
|
plugins: KubbPlugin[];
|
|
477
|
+
/**
|
|
478
|
+
* Current plugin
|
|
479
|
+
*/
|
|
480
|
+
plugin: KubbPlugin<TOptions>;
|
|
687
481
|
};
|
|
688
482
|
type TransformResult = string | null;
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
483
|
+
|
|
484
|
+
type BasePath<T extends string = string> = `${T}/`;
|
|
485
|
+
declare namespace KubbFile {
|
|
486
|
+
type Import = {
|
|
487
|
+
/**
|
|
488
|
+
* Import name to be used
|
|
489
|
+
* @example ["useState"]
|
|
490
|
+
* @example "React"
|
|
491
|
+
*/
|
|
492
|
+
name: string | Array<string>;
|
|
493
|
+
/**
|
|
494
|
+
* Path for the import
|
|
495
|
+
* @xample '@kubb/core'
|
|
496
|
+
*/
|
|
497
|
+
path: string;
|
|
498
|
+
/**
|
|
499
|
+
* Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.
|
|
500
|
+
*/
|
|
501
|
+
isTypeOnly?: boolean;
|
|
502
|
+
};
|
|
503
|
+
type Export = {
|
|
504
|
+
/**
|
|
505
|
+
* Export name to be used.
|
|
506
|
+
* @example ["useState"]
|
|
507
|
+
* @example "React"
|
|
508
|
+
*/
|
|
509
|
+
name?: string | Array<string>;
|
|
510
|
+
/**
|
|
511
|
+
* Path for the import.
|
|
512
|
+
* @xample '@kubb/core'
|
|
513
|
+
*/
|
|
514
|
+
path: string;
|
|
515
|
+
/**
|
|
516
|
+
* Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.
|
|
517
|
+
*/
|
|
518
|
+
isTypeOnly?: boolean;
|
|
519
|
+
/**
|
|
520
|
+
* Make it possible to override the name, this will result in: `export * as aliasName from './path'`.
|
|
521
|
+
*/
|
|
522
|
+
asAlias?: boolean;
|
|
523
|
+
};
|
|
524
|
+
const dataTagSymbol: unique symbol;
|
|
525
|
+
type DataTag<Type, Value> = Type & {
|
|
526
|
+
[dataTagSymbol]: Value;
|
|
527
|
+
};
|
|
528
|
+
type UUID = string;
|
|
529
|
+
type Source = string;
|
|
530
|
+
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
|
|
531
|
+
type Mode = 'file' | 'directory';
|
|
532
|
+
/**
|
|
533
|
+
* Name to be used to dynamicly create the baseName(based on input.path)
|
|
534
|
+
* Based on UNIX basename
|
|
535
|
+
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
536
|
+
*/
|
|
537
|
+
type BaseName = `${string}${Extname}`;
|
|
538
|
+
/**
|
|
539
|
+
* Path will be full qualified path to a specified file
|
|
540
|
+
*/
|
|
541
|
+
type Path = string;
|
|
542
|
+
type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
|
|
543
|
+
type OptionalPath = Path | undefined | null;
|
|
544
|
+
type FileMetaBase = {
|
|
545
|
+
pluginKey?: KubbPlugin['key'];
|
|
546
|
+
};
|
|
547
|
+
type File<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = {
|
|
548
|
+
/**
|
|
549
|
+
* Unique identifier to reuse later
|
|
550
|
+
* @default crypto.randomUUID()
|
|
551
|
+
*/
|
|
552
|
+
id?: string;
|
|
553
|
+
/**
|
|
554
|
+
* Name to be used to dynamicly create the baseName(based on input.path)
|
|
555
|
+
* Based on UNIX basename
|
|
556
|
+
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
557
|
+
*/
|
|
558
|
+
baseName: TBaseName;
|
|
559
|
+
/**
|
|
560
|
+
* Path will be full qualified path to a specified file
|
|
561
|
+
*/
|
|
562
|
+
path: AdvancedPath<TBaseName> | Path;
|
|
563
|
+
source: Source;
|
|
564
|
+
imports?: Import[];
|
|
565
|
+
exports?: Export[];
|
|
566
|
+
/**
|
|
567
|
+
* This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
|
|
568
|
+
* This will also ignore the combinefiles utils
|
|
569
|
+
* @default `false`
|
|
570
|
+
*/
|
|
571
|
+
override?: boolean;
|
|
572
|
+
/**
|
|
573
|
+
* Use extra meta, this is getting used to generate the barrel/index files.
|
|
574
|
+
*/
|
|
575
|
+
meta?: TMeta;
|
|
576
|
+
/**
|
|
577
|
+
* This will override `process.env[key]` inside the `source`, see `getFileSource`.
|
|
578
|
+
*/
|
|
579
|
+
env?: NodeJS.ProcessEnv;
|
|
580
|
+
/**
|
|
581
|
+
* @deprecated
|
|
582
|
+
*/
|
|
583
|
+
validate?: boolean;
|
|
584
|
+
};
|
|
585
|
+
type ResolvedFile<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = KubbFile.File<TMeta, TBaseName> & {
|
|
586
|
+
/**
|
|
587
|
+
* @default crypto.randomUUID()
|
|
588
|
+
*/
|
|
589
|
+
id: UUID;
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
type AddResult<T extends Array<KubbFile.File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<KubbFile.ResolvedFile[]> : Promise<KubbFile.ResolvedFile>>>;
|
|
593
|
+
type AddIndexesProps = {
|
|
594
|
+
root: KubbFile.Path;
|
|
595
|
+
extName?: KubbFile.Extname;
|
|
596
|
+
options?: BarrelManagerOptions;
|
|
597
|
+
meta?: KubbFile.File['meta'];
|
|
693
598
|
};
|
|
694
|
-
type
|
|
695
|
-
|
|
696
|
-
|
|
599
|
+
type Options$1 = {
|
|
600
|
+
queue?: Queue;
|
|
601
|
+
task?: QueueJob<KubbFile.ResolvedFile>;
|
|
602
|
+
/**
|
|
603
|
+
* Timeout between writes
|
|
604
|
+
*/
|
|
605
|
+
timeout?: number;
|
|
697
606
|
};
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
607
|
+
declare class FileManager {
|
|
608
|
+
#private;
|
|
609
|
+
constructor(options?: Options$1);
|
|
610
|
+
get files(): Array<KubbFile.File>;
|
|
611
|
+
get isExecuting(): boolean;
|
|
612
|
+
add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T>;
|
|
613
|
+
addIndexes({ root, extName, meta, options }: AddIndexesProps): Promise<Array<KubbFile.File> | undefined>;
|
|
614
|
+
getCacheByUUID(UUID: KubbFile.UUID): KubbFile.File | undefined;
|
|
615
|
+
get(path: KubbFile.Path): Array<KubbFile.File> | undefined;
|
|
616
|
+
remove(path: KubbFile.Path): void;
|
|
617
|
+
write(...params: Parameters<typeof write>): Promise<string | undefined>;
|
|
618
|
+
read(...params: Parameters<typeof read>): Promise<string>;
|
|
619
|
+
static getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(file: KubbFile.File<TMeta>): string;
|
|
620
|
+
static combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(files: Array<KubbFile.File<TMeta> | null>): Array<KubbFile.File<TMeta>>;
|
|
621
|
+
static getMode(path: string | undefined | null): KubbFile.Mode;
|
|
622
|
+
static get extensions(): Array<KubbFile.Extname>;
|
|
623
|
+
static isExtensionAllowed(baseName: string): boolean;
|
|
624
|
+
}
|
|
625
|
+
declare function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export>;
|
|
626
|
+
declare function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import>;
|
|
702
627
|
|
|
703
628
|
type BuildOptions = {
|
|
704
629
|
config: PluginContext['config'];
|
|
@@ -706,18 +631,38 @@ type BuildOptions = {
|
|
|
706
631
|
* @default Logger without the spinner
|
|
707
632
|
*/
|
|
708
633
|
logger?: Logger;
|
|
709
|
-
|
|
634
|
+
};
|
|
635
|
+
type BuildOutput = {
|
|
636
|
+
files: FileManager['files'];
|
|
637
|
+
pluginManager: PluginManager;
|
|
638
|
+
/**
|
|
639
|
+
* Only for safeBuild
|
|
640
|
+
*/
|
|
641
|
+
error?: Error;
|
|
710
642
|
};
|
|
711
643
|
declare function build(options: BuildOptions): Promise<BuildOutput>;
|
|
644
|
+
declare function safeBuild(options: BuildOptions): Promise<BuildOutput>;
|
|
712
645
|
|
|
713
646
|
/**
|
|
714
647
|
* Type helper to make it easier to use kubb.config.js
|
|
715
648
|
* accepts a direct {@link KubbConfig} object, or a function that returns it.
|
|
716
649
|
* The function receives a {@link ConfigEnv} object that exposes two properties:
|
|
717
650
|
*/
|
|
718
|
-
declare function defineConfig(options: PossiblePromise<KubbUserConfig
|
|
651
|
+
declare function defineConfig(options: PossiblePromise<KubbUserConfig | Array<KubbUserConfig>> | ((
|
|
719
652
|
/** The options derived from the CLI flags */
|
|
720
|
-
cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig
|
|
653
|
+
cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig | Array<KubbUserConfig>>)): typeof options;
|
|
654
|
+
declare function isInputPath(result: KubbConfig | undefined): result is KubbConfig<InputPath>;
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Behaves as an Error to log a warning in the console(still stops the execution)
|
|
658
|
+
*/
|
|
659
|
+
declare class Warning extends Error {
|
|
660
|
+
constructor(message?: string, options?: {
|
|
661
|
+
cause: Error;
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
declare class ValidationPluginError extends Error {
|
|
665
|
+
}
|
|
721
666
|
|
|
722
667
|
/**
|
|
723
668
|
* Abstract class that contains the building blocks for plugins to create their own Generator
|
|
@@ -732,6 +677,51 @@ declare abstract class Generator<TOptions = unknown, TContext = unknown> {
|
|
|
732
677
|
abstract build(...params: unknown[]): unknown;
|
|
733
678
|
}
|
|
734
679
|
|
|
680
|
+
type PackageJSON = {
|
|
681
|
+
dependencies?: Record<string, string>;
|
|
682
|
+
devDependencies?: Record<string, string>;
|
|
683
|
+
};
|
|
684
|
+
type DependencyName = string;
|
|
685
|
+
type DependencyVersion = string;
|
|
686
|
+
declare class PackageManager {
|
|
687
|
+
#private;
|
|
688
|
+
constructor(workspace?: string);
|
|
689
|
+
set workspace(workspace: string);
|
|
690
|
+
get workspace(): string | undefined;
|
|
691
|
+
normalizeDirectory(directory: string): string;
|
|
692
|
+
getLocation(path: string): string;
|
|
693
|
+
import(path: string): Promise<any | undefined>;
|
|
694
|
+
getPackageJSON(): Promise<PackageJSON | undefined>;
|
|
695
|
+
getPackageJSONSync(): PackageJSON | undefined;
|
|
696
|
+
static setVersion(dependency: DependencyName, version: DependencyVersion): void;
|
|
697
|
+
getVersion(dependency: DependencyName | RegExp): Promise<DependencyVersion | undefined>;
|
|
698
|
+
getVersionSync(dependency: DependencyName | RegExp): DependencyVersion | undefined;
|
|
699
|
+
isValid(dependency: DependencyName | RegExp, version: DependencyVersion): Promise<boolean>;
|
|
700
|
+
isValidSync(dependency: DependencyName | RegExp, version: DependencyVersion): boolean;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => KubbUserPluginWithLifeCycle<T>;
|
|
704
|
+
declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
|
|
705
|
+
declare const pluginName = "core";
|
|
706
|
+
|
|
707
|
+
type PromiseFunc$1<T = unknown, T2 = never> = (state?: T) => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
708
|
+
type ValueOfPromiseFuncArray<TInput extends Array<unknown>> = TInput extends Array<PromiseFunc$1<infer X, infer Y>> ? X | Y : never;
|
|
709
|
+
type SeqOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Array<Awaited<ValueOfPromiseFuncArray<TInput>>>;
|
|
710
|
+
type HookFirstOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue = unknown> = ValueOfPromiseFuncArray<TInput>;
|
|
711
|
+
type HookParallelOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Promise<PromiseSettledResult<Awaited<ValueOfPromiseFuncArray<TInput>>>[]>;
|
|
712
|
+
type Strategy = 'seq' | 'first' | 'parallel';
|
|
713
|
+
type StrategySwitch<TStrategy extends Strategy, TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = TStrategy extends 'first' ? HookFirstOutput<TInput, TValue> : TStrategy extends 'seq' ? SeqOutput<TInput, TValue> : TStrategy extends 'parallel' ? HookParallelOutput<TInput, TValue> : never;
|
|
714
|
+
|
|
715
|
+
type PromiseFunc<T = unknown, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
716
|
+
type Options<TState = any> = {
|
|
717
|
+
nullCheck?: (state: TState) => boolean;
|
|
718
|
+
};
|
|
719
|
+
declare class PromiseManager<TState = any> {
|
|
720
|
+
#private;
|
|
721
|
+
constructor(options?: Options<TState>);
|
|
722
|
+
run<TInput extends Array<PromiseFunc<TValue, null>>, TValue, TStrategy extends Strategy, TOutput = StrategySwitch<TStrategy, TInput, TValue>>(strategy: TStrategy, promises: TInput): TOutput;
|
|
723
|
+
}
|
|
724
|
+
|
|
735
725
|
/**
|
|
736
726
|
* Abstract class that contains the building blocks for plugins to create their own SchemaGenerator
|
|
737
727
|
*/
|
|
@@ -739,19 +729,14 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
|
|
|
739
729
|
abstract build(schema: TInput, name: string, description?: string): TOutput;
|
|
740
730
|
}
|
|
741
731
|
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
type
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
pluginManager: PluginManager;
|
|
748
|
-
resolvePath: PluginContext['resolvePath'];
|
|
749
|
-
resolveName: PluginContext['resolveName'];
|
|
750
|
-
logger: PluginContext['logger'];
|
|
751
|
-
getPlugins: () => KubbPlugin[];
|
|
752
|
-
plugin: KubbPlugin;
|
|
732
|
+
interface _Register {
|
|
733
|
+
}
|
|
734
|
+
type Plugins = _Register;
|
|
735
|
+
type OptionsPlugins = {
|
|
736
|
+
[K in keyof Plugins]: Plugins[K]['options'];
|
|
753
737
|
};
|
|
754
|
-
type
|
|
755
|
-
|
|
738
|
+
type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
|
|
739
|
+
type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
|
|
740
|
+
type Plugin = keyof Plugins;
|
|
756
741
|
|
|
757
|
-
export {
|
|
742
|
+
export { type CLIOptions, FileManager, Generator, type GetPluginFactoryOptions, type InputData, type InputPath, type KubbConfig, KubbFile, type KubbObjectPlugin, type KubbPlugin, type KubbPluginKind, type KubbPluginWithLifeCycle, type KubbUnionPlugins, type KubbUserConfig, type KubbUserPlugin, type KubbUserPluginWithLifeCycle, type OptionsOfPlugin, type OptionsPlugins, PackageManager, type Plugin, type PluginCache, type PluginContext, type PluginFactoryOptions, type PluginLifecycle, type PluginLifecycleHooks, PluginManager, type PluginParameter, type PluginUnion, type Plugins, PromiseManager, type ResolveNameParams, type ResolvePathParams, SchemaGenerator, type TransformResult, ValidationPluginError, Warning, type _Register, build, combineExports, combineImports, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
|