@kubb/core 2.0.0-canary.20231030T124950 → 2.0.0
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/chunk-4A7WG6IA.js +128 -0
- package/dist/chunk-4A7WG6IA.js.map +1 -0
- package/dist/chunk-54P4AWHI.js +71 -0
- package/dist/chunk-54P4AWHI.js.map +1 -0
- package/dist/chunk-5TK7TMV6.cjs +131 -0
- package/dist/chunk-5TK7TMV6.cjs.map +1 -0
- package/dist/chunk-7S67BJXQ.js +85 -0
- package/dist/chunk-7S67BJXQ.js.map +1 -0
- package/dist/chunk-E3ANGQ5N.cjs +2290 -0
- package/dist/chunk-E3ANGQ5N.cjs.map +1 -0
- package/dist/chunk-H47IKRXJ.cjs +129 -0
- package/dist/chunk-H47IKRXJ.cjs.map +1 -0
- package/dist/chunk-HIE46T3F.js +129 -0
- package/dist/chunk-HIE46T3F.js.map +1 -0
- package/dist/chunk-K2H7BYQB.js +155 -0
- package/dist/chunk-K2H7BYQB.js.map +1 -0
- package/dist/chunk-NAWI7UXW.js +67 -0
- package/dist/chunk-NAWI7UXW.js.map +1 -0
- package/dist/chunk-PLVKILIY.cjs +162 -0
- package/dist/chunk-PLVKILIY.cjs.map +1 -0
- package/dist/chunk-W2FP7ZWW.cjs +71 -0
- package/dist/chunk-W2FP7ZWW.cjs.map +1 -0
- package/dist/chunk-WZQO3EPM.cjs +91 -0
- package/dist/chunk-WZQO3EPM.cjs.map +1 -0
- package/dist/chunk-XDHI63G7.cjs +104 -0
- package/dist/chunk-XDHI63G7.cjs.map +1 -0
- package/dist/chunk-XPOF4D5N.js +18 -0
- package/dist/chunk-XPOF4D5N.js.map +1 -0
- package/dist/fs.cjs +31 -0
- package/dist/fs.cjs.map +1 -0
- package/dist/fs.d.cts +5 -0
- package/dist/fs.d.ts +5 -0
- package/dist/fs.js +11 -0
- package/dist/fs.js.map +1 -0
- package/dist/index.cjs +1866 -977
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +302 -319
- package/dist/index.d.ts +302 -319
- package/dist/index.js +1071 -846
- package/dist/index.js.map +1 -1
- package/dist/logger.cjs +26 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +32 -0
- package/dist/logger.d.ts +32 -0
- package/dist/logger.js +8 -0
- package/dist/logger.js.map +1 -0
- package/dist/transformers.cjs +124 -0
- package/dist/transformers.cjs.map +1 -0
- package/dist/transformers.d.cts +55 -0
- package/dist/transformers.d.ts +55 -0
- package/dist/transformers.js +95 -0
- package/dist/transformers.js.map +1 -0
- package/dist/utils.cjs +23 -1163
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +2 -143
- package/dist/utils.d.ts +2 -143
- package/dist/utils.js +15 -1118
- package/dist/utils.js.map +1 -1
- package/dist/write-A6VgHkYA.d.cts +10 -0
- package/dist/write-A6VgHkYA.d.ts +10 -0
- package/package.json +40 -23
- package/src/BarrelManager.ts +113 -0
- package/src/FileManager.ts +581 -0
- package/src/Generator.ts +34 -0
- package/src/PackageManager.ts +178 -0
- package/src/PluginManager.ts +645 -0
- package/src/PromiseManager.ts +51 -0
- package/src/build.ts +221 -0
- package/src/config.ts +22 -0
- package/src/errors.ts +12 -0
- package/src/fs/clean.ts +5 -0
- package/src/fs/index.ts +3 -0
- package/src/fs/read.ts +68 -0
- package/src/fs/write.ts +79 -0
- package/src/index.ts +27 -0
- package/src/logger.ts +121 -0
- package/src/plugin.ts +80 -0
- package/src/transformers/casing.ts +9 -0
- package/src/transformers/combineCodes.ts +3 -0
- package/src/transformers/createJSDocBlockText.ts +9 -0
- package/src/transformers/escape.ts +31 -0
- package/src/transformers/indent.ts +3 -0
- package/src/transformers/index.ts +36 -0
- package/src/transformers/nameSorter.ts +9 -0
- package/src/transformers/searchAndReplace.ts +25 -0
- package/src/transformers/transformReservedWord.ts +97 -0
- package/src/transformers/trim.ts +7 -0
- package/src/types.ts +334 -0
- package/src/utils/EventEmitter.ts +24 -0
- package/src/utils/FunctionParams.ts +86 -0
- package/src/utils/TreeNode.ts +125 -0
- package/src/utils/URLPath.ts +133 -0
- package/src/utils/cache.ts +35 -0
- package/src/utils/executeStrategies.ts +83 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/promise.ts +13 -0
- package/src/utils/renderTemplate.ts +31 -0
- package/src/utils/timeout.ts +7 -0
- package/src/utils/uniqueName.ts +20 -0
package/dist/index.d.cts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
import PQueue from 'p-queue';
|
|
2
|
+
import { w as write, r as read } from './write-A6VgHkYA.cjs';
|
|
3
|
+
import { PossiblePromise, GreaterThan, TupleToUnion, ObjValueTuple } from '@kubb/types';
|
|
1
4
|
import { DirectoryTreeOptions } from 'directory-tree';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
declare function read(path: string): Promise<string>;
|
|
5
|
-
|
|
6
|
-
declare function write(data: string, path: string): Promise<string | undefined>;
|
|
5
|
+
import { Logger, LogLevel } from './logger.cjs';
|
|
6
|
+
import 'ora';
|
|
7
7
|
|
|
8
8
|
type BarrelManagerOptions = {
|
|
9
9
|
treeNode?: DirectoryTreeOptions;
|
|
10
10
|
isTypeOnly?: boolean;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Add .ts or .js
|
|
13
|
+
*/
|
|
14
|
+
extName?: KubbFile.Extname;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
declare class EventEmitter<TEvents extends Record<string, any>> {
|
|
@@ -23,187 +23,6 @@ declare class EventEmitter<TEvents extends Record<string, any>> {
|
|
|
23
23
|
removeAll(): void;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
type QueueJob<T = unknown> = {
|
|
27
|
-
(...args: unknown[]): Promise<T | void>;
|
|
28
|
-
};
|
|
29
|
-
type RunOptions = {
|
|
30
|
-
controller?: AbortController;
|
|
31
|
-
name?: string;
|
|
32
|
-
description?: string;
|
|
33
|
-
};
|
|
34
|
-
type Events$1 = {
|
|
35
|
-
jobDone: [result: unknown];
|
|
36
|
-
jobFailed: [error: Error];
|
|
37
|
-
};
|
|
38
|
-
declare class Queue {
|
|
39
|
-
#private;
|
|
40
|
-
readonly eventEmitter: EventEmitter<Events$1>;
|
|
41
|
-
constructor(maxParallel: number, debug?: boolean);
|
|
42
|
-
run<T>(job: QueueJob<T>, options?: RunOptions): Promise<T>;
|
|
43
|
-
runSync<T>(job: QueueJob<T>, options?: RunOptions): void;
|
|
44
|
-
get hasJobs(): boolean;
|
|
45
|
-
get count(): number;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
type BasePath<T extends string = string> = `${T}/`;
|
|
49
|
-
declare namespace KubbFile {
|
|
50
|
-
type Import = {
|
|
51
|
-
name: string | Array<string>;
|
|
52
|
-
path: string;
|
|
53
|
-
isTypeOnly?: boolean;
|
|
54
|
-
};
|
|
55
|
-
type Export = {
|
|
56
|
-
name?: string | Array<string>;
|
|
57
|
-
path: string;
|
|
58
|
-
isTypeOnly?: boolean;
|
|
59
|
-
asAlias?: boolean;
|
|
60
|
-
};
|
|
61
|
-
const dataTagSymbol: unique symbol;
|
|
62
|
-
type DataTag<Type, Value> = Type & {
|
|
63
|
-
[dataTagSymbol]: Value;
|
|
64
|
-
};
|
|
65
|
-
type UUID = string;
|
|
66
|
-
type Source = string;
|
|
67
|
-
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
|
|
68
|
-
type Mode = 'file' | 'directory';
|
|
69
|
-
type BaseName = `${string}${Extname}`;
|
|
70
|
-
type Path = string;
|
|
71
|
-
type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
|
|
72
|
-
type OptionalPath = Path | undefined | null;
|
|
73
|
-
type FileMetaBase = {
|
|
74
|
-
pluginKey?: KubbPlugin['key'];
|
|
75
|
-
};
|
|
76
|
-
type File<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = {
|
|
77
|
-
/**
|
|
78
|
-
* Unique identifier to reuse later
|
|
79
|
-
* @default crypto.randomUUID()
|
|
80
|
-
*/
|
|
81
|
-
id?: string;
|
|
82
|
-
/**
|
|
83
|
-
* Name to be used to dynamicly create the baseName(based on input.path)
|
|
84
|
-
* Based on UNIX basename
|
|
85
|
-
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
86
|
-
*/
|
|
87
|
-
baseName: TBaseName;
|
|
88
|
-
/**
|
|
89
|
-
* Path will be full qualified path to a specified file
|
|
90
|
-
*/
|
|
91
|
-
path: AdvancedPath<TBaseName> | Path;
|
|
92
|
-
source: Source;
|
|
93
|
-
imports?: Import[];
|
|
94
|
-
exports?: Export[];
|
|
95
|
-
/**
|
|
96
|
-
* This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
|
|
97
|
-
* This will also ignore the combinefiles utils
|
|
98
|
-
* @default `false`
|
|
99
|
-
*/
|
|
100
|
-
override?: boolean;
|
|
101
|
-
meta?: TMeta;
|
|
102
|
-
/**
|
|
103
|
-
* This will override `process.env[key]` inside the `source`, see `getFileSource`.
|
|
104
|
-
*/
|
|
105
|
-
env?: NodeJS.ProcessEnv;
|
|
106
|
-
validate?: boolean;
|
|
107
|
-
};
|
|
108
|
-
type ResolvedFile<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = KubbFile.File<TMeta, TBaseName> & {
|
|
109
|
-
/**
|
|
110
|
-
* @default crypto.randomUUID()
|
|
111
|
-
*/
|
|
112
|
-
id: UUID;
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
type AddResult<T extends Array<KubbFile.File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<KubbFile.ResolvedFile[]> : Promise<KubbFile.ResolvedFile>>>;
|
|
116
|
-
type AddIndexesProps = {
|
|
117
|
-
root: KubbFile.Path;
|
|
118
|
-
extName?: KubbFile.Extname;
|
|
119
|
-
options?: BarrelManagerOptions;
|
|
120
|
-
meta?: KubbFile.File['meta'];
|
|
121
|
-
};
|
|
122
|
-
type Options$2 = {
|
|
123
|
-
queue?: Queue;
|
|
124
|
-
task?: QueueJob<KubbFile.ResolvedFile>;
|
|
125
|
-
/**
|
|
126
|
-
* Timeout between writes
|
|
127
|
-
*/
|
|
128
|
-
timeout?: number;
|
|
129
|
-
};
|
|
130
|
-
declare class FileManager {
|
|
131
|
-
#private;
|
|
132
|
-
constructor(options?: Options$2);
|
|
133
|
-
get files(): Array<KubbFile.File>;
|
|
134
|
-
get isExecuting(): boolean;
|
|
135
|
-
add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T>;
|
|
136
|
-
addIndexes({ root, extName, meta, options }: AddIndexesProps): Promise<Array<KubbFile.File> | undefined>;
|
|
137
|
-
getCacheByUUID(UUID: KubbFile.UUID): KubbFile.File | undefined;
|
|
138
|
-
get(path: KubbFile.Path): Array<KubbFile.File> | undefined;
|
|
139
|
-
remove(path: KubbFile.Path): void;
|
|
140
|
-
write(...params: Parameters<typeof write>): Promise<string | undefined>;
|
|
141
|
-
read(...params: Parameters<typeof read>): Promise<string>;
|
|
142
|
-
static getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(file: KubbFile.File<TMeta>): string;
|
|
143
|
-
static combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(files: Array<KubbFile.File<TMeta> | null>): Array<KubbFile.File<TMeta>>;
|
|
144
|
-
static getMode(path: string | undefined | null): KubbFile.Mode;
|
|
145
|
-
static get extensions(): Array<KubbFile.Extname>;
|
|
146
|
-
static isExtensionAllowed(baseName: string): boolean;
|
|
147
|
-
}
|
|
148
|
-
declare function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export>;
|
|
149
|
-
declare function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import>;
|
|
150
|
-
|
|
151
|
-
declare class PluginError extends Error {
|
|
152
|
-
pluginManager: PluginManager;
|
|
153
|
-
cause: Error;
|
|
154
|
-
constructor(message: string, options: {
|
|
155
|
-
cause: Error;
|
|
156
|
-
pluginManager: PluginManager;
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
declare class ParallelPluginError extends Error {
|
|
160
|
-
errors: PluginError[];
|
|
161
|
-
pluginManager: PluginManager;
|
|
162
|
-
constructor(message: string, options: {
|
|
163
|
-
cause?: Error;
|
|
164
|
-
errors: PluginError[];
|
|
165
|
-
pluginManager: PluginManager;
|
|
166
|
-
});
|
|
167
|
-
findError<T extends Error = Error>(searchError: T | undefined): T | undefined;
|
|
168
|
-
}
|
|
169
|
-
declare class SummaryError extends Error {
|
|
170
|
-
summary: string[];
|
|
171
|
-
constructor(message: string, options: {
|
|
172
|
-
cause: Error;
|
|
173
|
-
summary?: string[];
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Behaves as an Error to log a warning in the console(still stops the execution)
|
|
178
|
-
*/
|
|
179
|
-
declare class Warning extends Error {
|
|
180
|
-
constructor(message?: string, options?: {
|
|
181
|
-
cause: Error;
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
declare class ValidationPluginError extends Error {
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
declare const LogLevel: {
|
|
188
|
-
readonly silent: "silent";
|
|
189
|
-
readonly info: "info";
|
|
190
|
-
readonly debug: "debug";
|
|
191
|
-
};
|
|
192
|
-
type LogLevel = keyof typeof LogLevel;
|
|
193
|
-
type Logger = {
|
|
194
|
-
/**
|
|
195
|
-
* Optional config name to show in CLI output
|
|
196
|
-
*/
|
|
197
|
-
name?: string;
|
|
198
|
-
logLevel: LogLevel;
|
|
199
|
-
log: (message: string | null) => void;
|
|
200
|
-
error: (message: string | null) => void;
|
|
201
|
-
info: (message: string | null) => void;
|
|
202
|
-
warn: (message: string | null) => void;
|
|
203
|
-
spinner?: Ora;
|
|
204
|
-
logs: string[];
|
|
205
|
-
};
|
|
206
|
-
|
|
207
26
|
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
208
27
|
/**
|
|
209
28
|
* Get the type of the first argument in a function.
|
|
@@ -223,49 +42,52 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
|
|
|
223
42
|
result: Result;
|
|
224
43
|
plugin: KubbPlugin;
|
|
225
44
|
};
|
|
226
|
-
type Options$
|
|
45
|
+
type Options$2 = {
|
|
227
46
|
logger: Logger;
|
|
228
47
|
/**
|
|
229
48
|
* Task for the FileManager
|
|
230
49
|
*/
|
|
231
|
-
task:
|
|
232
|
-
/**
|
|
233
|
-
* Timeout between writes in the FileManager
|
|
234
|
-
*/
|
|
235
|
-
writeTimeout?: number;
|
|
50
|
+
task: (file: KubbFile.ResolvedFile) => Promise<KubbFile.ResolvedFile>;
|
|
236
51
|
};
|
|
237
52
|
type Events = {
|
|
238
53
|
execute: [executer: Executer];
|
|
239
54
|
executed: [executer: Executer];
|
|
240
|
-
error: [
|
|
55
|
+
error: [error: Error];
|
|
241
56
|
};
|
|
242
57
|
declare class PluginManager {
|
|
243
58
|
#private;
|
|
244
|
-
plugins:
|
|
59
|
+
readonly plugins: KubbPluginWithLifeCycle[];
|
|
245
60
|
readonly fileManager: FileManager;
|
|
246
|
-
readonly
|
|
247
|
-
readonly
|
|
248
|
-
readonly executed: Executer
|
|
61
|
+
readonly events: EventEmitter<Events>;
|
|
62
|
+
readonly config: KubbConfig;
|
|
63
|
+
readonly executed: Array<Executer>;
|
|
249
64
|
readonly logger: Logger;
|
|
250
|
-
|
|
251
|
-
|
|
65
|
+
readonly queue: PQueue;
|
|
66
|
+
constructor(config: KubbConfig, options: Options$2);
|
|
67
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
252
68
|
resolveName: (params: ResolveNameParams) => string;
|
|
69
|
+
/**
|
|
70
|
+
* Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
|
|
71
|
+
*/
|
|
253
72
|
on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
|
|
254
73
|
/**
|
|
255
|
-
* Run
|
|
74
|
+
* Run a specific hookName for plugin x.
|
|
256
75
|
*/
|
|
257
76
|
hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
258
77
|
pluginKey: KubbPlugin['key'];
|
|
259
78
|
hookName: H;
|
|
260
79
|
parameters: PluginParameter<H>;
|
|
261
80
|
}): Promise<Array<ReturnType<ParseResult<H>> | null>> | null;
|
|
81
|
+
/**
|
|
82
|
+
* Run a specific hookName for plugin x.
|
|
83
|
+
*/
|
|
262
84
|
hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
263
85
|
pluginKey: KubbPlugin['key'];
|
|
264
86
|
hookName: H;
|
|
265
87
|
parameters: PluginParameter<H>;
|
|
266
88
|
}): Array<ReturnType<ParseResult<H>>> | null;
|
|
267
89
|
/**
|
|
268
|
-
*
|
|
90
|
+
* First non-null result stops and will return it's value.
|
|
269
91
|
*/
|
|
270
92
|
hookFirst<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
|
|
271
93
|
hookName: H;
|
|
@@ -273,7 +95,7 @@ declare class PluginManager {
|
|
|
273
95
|
skipped?: ReadonlySet<KubbPlugin> | null;
|
|
274
96
|
}): Promise<SafeParseResult<H>>;
|
|
275
97
|
/**
|
|
276
|
-
*
|
|
98
|
+
* First non-null result stops and will return it's value.
|
|
277
99
|
*/
|
|
278
100
|
hookFirstSync<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
|
|
279
101
|
hookName: H;
|
|
@@ -281,14 +103,14 @@ declare class PluginManager {
|
|
|
281
103
|
skipped?: ReadonlySet<KubbPlugin> | null;
|
|
282
104
|
}): SafeParseResult<H>;
|
|
283
105
|
/**
|
|
284
|
-
*
|
|
106
|
+
* Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
|
|
285
107
|
*/
|
|
286
108
|
hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ hookName, parameters, }: {
|
|
287
109
|
hookName: H;
|
|
288
110
|
parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
|
|
289
111
|
}): Promise<Awaited<TOuput>[]>;
|
|
290
112
|
/**
|
|
291
|
-
*
|
|
113
|
+
* Chain all plugins, `reduce` can be passed through to handle every returned value. The return value of the first plugin will be used as the first parameter for the plugin after that.
|
|
292
114
|
*/
|
|
293
115
|
hookReduceArg0<H extends PluginLifecycleHooks>({ hookName, parameters, reduce, }: {
|
|
294
116
|
hookName: H;
|
|
@@ -304,7 +126,7 @@ declare class PluginManager {
|
|
|
304
126
|
}): Promise<void>;
|
|
305
127
|
getPluginsByKey(hookName: keyof PluginLifecycle, pluginKey: KubbPlugin['key']): KubbPlugin[];
|
|
306
128
|
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;
|
|
307
|
-
static get hooks(): readonly ["
|
|
129
|
+
static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
|
|
308
130
|
}
|
|
309
131
|
|
|
310
132
|
interface Cache<TStore extends object = object> {
|
|
@@ -334,7 +156,7 @@ type KubbUserConfig = Omit<KubbConfig, 'root' | 'plugins'> & {
|
|
|
334
156
|
* Example: ['@kubb/swagger', { output: false }]
|
|
335
157
|
* Or: createSwagger({ output: false })
|
|
336
158
|
*/
|
|
337
|
-
plugins?: Array<Omit<
|
|
159
|
+
plugins?: Array<Omit<UnknownKubbUserPlugin, 'api'> | KubbUnionPlugins | [name: string, options: object]>;
|
|
338
160
|
};
|
|
339
161
|
type InputPath = {
|
|
340
162
|
/**
|
|
@@ -419,44 +241,76 @@ type CLIOptions = {
|
|
|
419
241
|
*/
|
|
420
242
|
logLevel?: LogLevel;
|
|
421
243
|
};
|
|
422
|
-
type BuildOutput = {
|
|
423
|
-
files: FileManager['files'];
|
|
424
|
-
pluginManager: PluginManager;
|
|
425
|
-
};
|
|
426
|
-
type KubbPluginKind = 'schema' | 'controller';
|
|
427
244
|
type KubbUnionPlugins = PluginUnion;
|
|
428
245
|
type KubbObjectPlugin = keyof OptionsPlugins;
|
|
246
|
+
type PluginFactoryOptions<
|
|
247
|
+
/**
|
|
248
|
+
* Name to be used for the plugin, this will also be used for they key.
|
|
249
|
+
*/
|
|
250
|
+
TName extends string = string,
|
|
251
|
+
/**
|
|
252
|
+
* Options of the plugin.
|
|
253
|
+
*/
|
|
254
|
+
TOptions extends object = object,
|
|
255
|
+
/**
|
|
256
|
+
* Options of the plugin that can be used later on, see `options` inside your plugin config.
|
|
257
|
+
*/
|
|
258
|
+
TResolvedOptions extends object = TOptions,
|
|
259
|
+
/**
|
|
260
|
+
* API that you want to expose to other plugins.
|
|
261
|
+
*/
|
|
262
|
+
TAPI = any,
|
|
263
|
+
/**
|
|
264
|
+
* When calling `resolvePath` you can specify better types.
|
|
265
|
+
*/
|
|
266
|
+
TResolvePathOptions extends object = object,
|
|
267
|
+
/**
|
|
268
|
+
* When using @kubb/react(based on React) you can specify here which types should be used when calling render.
|
|
269
|
+
* Always extend from `AppMeta` of the core.
|
|
270
|
+
*/
|
|
271
|
+
TAppMeta = unknown> = {
|
|
272
|
+
name: TName;
|
|
273
|
+
/**
|
|
274
|
+
* Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
|
|
275
|
+
*/
|
|
276
|
+
key: [name: TName | string, identifier?: string | number];
|
|
277
|
+
options: TOptions;
|
|
278
|
+
resolvedOptions: TResolvedOptions;
|
|
279
|
+
api: TAPI;
|
|
280
|
+
resolvePathOptions: TResolvePathOptions;
|
|
281
|
+
appMeta: {
|
|
282
|
+
pluginManager: PluginManager;
|
|
283
|
+
plugin: KubbPlugin<PluginFactoryOptions<TName, TOptions, TResolvedOptions, TAPI, TResolvePathOptions, TAppMeta>>;
|
|
284
|
+
} & TAppMeta;
|
|
285
|
+
};
|
|
429
286
|
type GetPluginFactoryOptions<TPlugin extends KubbUserPlugin> = TPlugin extends KubbUserPlugin<infer X> ? X : never;
|
|
430
287
|
type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
431
288
|
/**
|
|
432
289
|
* Unique name used for the plugin
|
|
290
|
+
* The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
|
|
433
291
|
* @example @kubb/typescript
|
|
434
292
|
*/
|
|
435
293
|
name: TOptions['name'];
|
|
436
294
|
/**
|
|
437
|
-
*
|
|
438
|
-
* @private
|
|
295
|
+
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
439
296
|
*/
|
|
440
|
-
|
|
297
|
+
options: TOptions['resolvedOptions'];
|
|
441
298
|
/**
|
|
442
|
-
*
|
|
299
|
+
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
|
|
300
|
+
* Can be used to validate depended plugins.
|
|
443
301
|
*/
|
|
444
|
-
|
|
445
|
-
} & Partial<PluginLifecycle<TOptions>> & (TOptions['api'] extends never ? {
|
|
446
|
-
api?: never;
|
|
447
|
-
} : {
|
|
448
|
-
api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext, 'addFile'>) => TOptions['api'];
|
|
449
|
-
}) & (TOptions['kind'] extends never ? {
|
|
450
|
-
kind?: never;
|
|
451
|
-
} : {
|
|
302
|
+
pre?: Array<string>;
|
|
452
303
|
/**
|
|
453
|
-
*
|
|
454
|
-
* Type 'schema' can be used for JSON schema's, TypeScript types, ...
|
|
455
|
-
* Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
|
|
456
|
-
* @default undefined
|
|
304
|
+
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
|
|
457
305
|
*/
|
|
458
|
-
|
|
306
|
+
post?: Array<string>;
|
|
307
|
+
} & (TOptions['api'] extends never ? {
|
|
308
|
+
api?: never;
|
|
309
|
+
} : {
|
|
310
|
+
api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['api'];
|
|
459
311
|
});
|
|
312
|
+
type KubbUserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbUserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
313
|
+
type UnknownKubbUserPlugin = KubbUserPlugin<PluginFactoryOptions<any, any, any, any, any, any>>;
|
|
460
314
|
type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
461
315
|
/**
|
|
462
316
|
* Unique name used for the plugin
|
|
@@ -469,83 +323,69 @@ type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
469
323
|
*/
|
|
470
324
|
key: TOptions['key'];
|
|
471
325
|
/**
|
|
472
|
-
*
|
|
326
|
+
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
|
|
327
|
+
* Can be used to validate depended plugins.
|
|
473
328
|
*/
|
|
474
|
-
|
|
329
|
+
pre?: Array<string>;
|
|
475
330
|
/**
|
|
476
|
-
*
|
|
477
|
-
* Type 'schema' can be used for JSON schema's, TypeScript types, ...
|
|
478
|
-
* Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
|
|
479
|
-
* @default undefined
|
|
331
|
+
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
|
|
480
332
|
*/
|
|
481
|
-
|
|
482
|
-
|
|
333
|
+
post?: Array<string>;
|
|
334
|
+
/**
|
|
335
|
+
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
336
|
+
*/
|
|
337
|
+
options: TOptions['resolvedOptions'];
|
|
338
|
+
} & (TOptions['api'] extends never ? {
|
|
483
339
|
api?: never;
|
|
484
340
|
} : {
|
|
485
341
|
api: TOptions['api'];
|
|
486
342
|
});
|
|
487
|
-
type
|
|
488
|
-
name: Name;
|
|
489
|
-
kind: Kind;
|
|
490
|
-
/**
|
|
491
|
-
* Same like `QueryKey` in `@tanstack/react-query`
|
|
492
|
-
*/
|
|
493
|
-
key: [kind: Kind | undefined, name: Name, identifier?: string | number];
|
|
494
|
-
options: Options;
|
|
495
|
-
nested: Nested;
|
|
496
|
-
api: API;
|
|
497
|
-
resolvePathOptions: resolvePathOptions;
|
|
498
|
-
};
|
|
343
|
+
type KubbPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
499
344
|
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
500
|
-
/**
|
|
501
|
-
* Valdiate all plugins to see if their depended plugins are installed and configured.
|
|
502
|
-
* @type hookParallel
|
|
503
|
-
*/
|
|
504
|
-
validate?: (this: Omit<PluginContext, 'addFile'>, plugins: NonNullable<KubbConfig['plugins']>) => PossiblePromise<true>;
|
|
505
345
|
/**
|
|
506
346
|
* Start of the lifecycle of a plugin.
|
|
507
347
|
* @type hookParallel
|
|
508
348
|
*/
|
|
509
|
-
buildStart?: (this: PluginContext
|
|
349
|
+
buildStart?: (this: PluginContext<TOptions>, kubbConfig: KubbConfig) => PossiblePromise<void>;
|
|
510
350
|
/**
|
|
511
351
|
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
512
352
|
* Options can als be included.
|
|
513
353
|
* @type hookFirst
|
|
514
354
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
515
355
|
*/
|
|
516
|
-
resolvePath?: (this: PluginContext
|
|
356
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: string, directory?: string, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
|
|
517
357
|
/**
|
|
518
358
|
* Resolve to a name based on a string.
|
|
519
359
|
* Useful when converting to PascalCase or camelCase.
|
|
520
360
|
* @type hookFirst
|
|
521
361
|
* @example ('pet') => 'Pet'
|
|
522
362
|
*/
|
|
523
|
-
resolveName?: (this: PluginContext
|
|
363
|
+
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
524
364
|
/**
|
|
525
365
|
* Makes it possible to run async logic to override the path defined previously by `resolvePath`.
|
|
526
366
|
* @type hookFirst
|
|
527
367
|
*/
|
|
528
|
-
load?: (this: Omit<PluginContext
|
|
368
|
+
load?: (this: Omit<PluginContext<TOptions>, 'addFile'>, path: KubbFile.Path) => PossiblePromise<TransformResult | null>;
|
|
529
369
|
/**
|
|
530
370
|
* Transform the source-code.
|
|
531
371
|
* @type hookReduceArg0
|
|
532
372
|
*/
|
|
533
|
-
transform?: (this: Omit<PluginContext
|
|
373
|
+
transform?: (this: Omit<PluginContext<TOptions>, 'addFile'>, source: string, path: KubbFile.Path) => PossiblePromise<TransformResult>;
|
|
534
374
|
/**
|
|
535
375
|
* Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
|
|
536
376
|
* @type hookParallel
|
|
537
377
|
*/
|
|
538
|
-
writeFile?: (this: Omit<PluginContext
|
|
378
|
+
writeFile?: (this: Omit<PluginContext<TOptions>, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<string | void>;
|
|
539
379
|
/**
|
|
540
380
|
* End of the plugin lifecycle.
|
|
541
381
|
* @type hookParallel
|
|
542
382
|
*/
|
|
543
|
-
buildEnd?: (this: PluginContext) => PossiblePromise<void>;
|
|
383
|
+
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
544
384
|
};
|
|
545
385
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
546
386
|
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
547
387
|
type PluginCache = Record<string, [number, unknown]>;
|
|
548
|
-
type ResolvePathParams<TOptions =
|
|
388
|
+
type ResolvePathParams<TOptions = object> = {
|
|
549
389
|
pluginKey?: KubbPlugin['key'];
|
|
550
390
|
baseName: string;
|
|
551
391
|
directory?: string | undefined;
|
|
@@ -557,15 +397,20 @@ type ResolvePathParams<TOptions = Record<string, unknown>> = {
|
|
|
557
397
|
type ResolveNameParams = {
|
|
558
398
|
name: string;
|
|
559
399
|
pluginKey?: KubbPlugin['key'];
|
|
560
|
-
|
|
400
|
+
/**
|
|
401
|
+
* `file` will be used to customize the name of the created file(use of camelCase)
|
|
402
|
+
* `function` can be used used to customize the exported functions(use of camelCase)
|
|
403
|
+
* `type` is a special type for TypeScript(use of PascalCase)
|
|
404
|
+
*/
|
|
405
|
+
type?: 'file' | 'function' | 'type';
|
|
561
406
|
};
|
|
562
|
-
type PluginContext<TOptions =
|
|
407
|
+
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
563
408
|
config: KubbConfig;
|
|
564
409
|
cache: Cache<PluginCache>;
|
|
565
410
|
fileManager: FileManager;
|
|
566
411
|
pluginManager: PluginManager;
|
|
567
412
|
addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.File>>;
|
|
568
|
-
resolvePath: (params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
413
|
+
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
|
|
569
414
|
resolveName: (params: ResolveNameParams) => string;
|
|
570
415
|
logger: Logger;
|
|
571
416
|
/**
|
|
@@ -575,44 +420,170 @@ type PluginContext<TOptions = Record<string, unknown>> = {
|
|
|
575
420
|
/**
|
|
576
421
|
* Current plugin
|
|
577
422
|
*/
|
|
578
|
-
plugin: KubbPlugin
|
|
423
|
+
plugin: KubbPlugin<TOptions>;
|
|
579
424
|
};
|
|
580
425
|
type TransformResult = string | null;
|
|
581
|
-
|
|
582
|
-
|
|
426
|
+
|
|
427
|
+
type BasePath<T extends string = string> = `${T}/`;
|
|
428
|
+
declare namespace KubbFile {
|
|
429
|
+
type Import = {
|
|
430
|
+
/**
|
|
431
|
+
* Import name to be used
|
|
432
|
+
* @example ["useState"]
|
|
433
|
+
* @example "React"
|
|
434
|
+
*/
|
|
435
|
+
name: string | Array<string | {
|
|
436
|
+
propertyName: string;
|
|
437
|
+
name?: string;
|
|
438
|
+
}>;
|
|
439
|
+
/**
|
|
440
|
+
* Path for the import
|
|
441
|
+
* @xample '@kubb/core'
|
|
442
|
+
*/
|
|
443
|
+
path: string;
|
|
444
|
+
/**
|
|
445
|
+
* Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.
|
|
446
|
+
*/
|
|
447
|
+
isTypeOnly?: boolean;
|
|
448
|
+
/**
|
|
449
|
+
* Add `* as` prefix to the import, this will result in: `import * as path from './path'`.
|
|
450
|
+
*/
|
|
451
|
+
isNameSpace?: boolean;
|
|
452
|
+
/**
|
|
453
|
+
* When root is set it will get the path with relative getRelativePath(root, path).
|
|
454
|
+
*/
|
|
455
|
+
root?: string;
|
|
456
|
+
};
|
|
457
|
+
type Export = {
|
|
458
|
+
/**
|
|
459
|
+
* Export name to be used.
|
|
460
|
+
* @example ["useState"]
|
|
461
|
+
* @example "React"
|
|
462
|
+
*/
|
|
463
|
+
name?: string | Array<string>;
|
|
464
|
+
/**
|
|
465
|
+
* Path for the import.
|
|
466
|
+
* @xample '@kubb/core'
|
|
467
|
+
*/
|
|
468
|
+
path: string;
|
|
469
|
+
/**
|
|
470
|
+
* Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.
|
|
471
|
+
*/
|
|
472
|
+
isTypeOnly?: boolean;
|
|
473
|
+
/**
|
|
474
|
+
* Make it possible to override the name, this will result in: `export * as aliasName from './path'`.
|
|
475
|
+
*/
|
|
476
|
+
asAlias?: boolean;
|
|
477
|
+
};
|
|
478
|
+
const dataTagSymbol: unique symbol;
|
|
479
|
+
type DataTag<Type, Value> = Type & {
|
|
480
|
+
[dataTagSymbol]: Value;
|
|
481
|
+
};
|
|
482
|
+
type UUID = string;
|
|
483
|
+
type Source = string;
|
|
484
|
+
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
|
|
485
|
+
type Mode = 'file' | 'directory';
|
|
486
|
+
/**
|
|
487
|
+
* Name to be used to dynamicly create the baseName(based on input.path)
|
|
488
|
+
* Based on UNIX basename
|
|
489
|
+
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
490
|
+
*/
|
|
491
|
+
type BaseName = `${string}${Extname}`;
|
|
492
|
+
/**
|
|
493
|
+
* Path will be full qualified path to a specified file
|
|
494
|
+
*/
|
|
495
|
+
type Path = string;
|
|
496
|
+
type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
|
|
497
|
+
type OptionalPath = Path | undefined | null;
|
|
498
|
+
type FileMetaBase = {
|
|
499
|
+
pluginKey?: KubbPlugin['key'];
|
|
500
|
+
};
|
|
501
|
+
type File<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = {
|
|
502
|
+
/**
|
|
503
|
+
* Unique identifier to reuse later
|
|
504
|
+
* @default crypto.randomUUID()
|
|
505
|
+
*/
|
|
506
|
+
id?: string;
|
|
507
|
+
/**
|
|
508
|
+
* Name to be used to create the path
|
|
509
|
+
* Based on UNIX basename, `${name}.extName`
|
|
510
|
+
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
511
|
+
*/
|
|
512
|
+
baseName: TBaseName;
|
|
513
|
+
/**
|
|
514
|
+
* Path will be full qualified path to a specified file
|
|
515
|
+
*/
|
|
516
|
+
path: AdvancedPath<TBaseName> | Path;
|
|
517
|
+
source: Source;
|
|
518
|
+
imports?: Import[];
|
|
519
|
+
exports?: Export[];
|
|
520
|
+
/**
|
|
521
|
+
* This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
|
|
522
|
+
* This will also ignore the combinefiles utils
|
|
523
|
+
* @default `false`
|
|
524
|
+
*/
|
|
525
|
+
override?: boolean;
|
|
526
|
+
/**
|
|
527
|
+
* Use extra meta, this is getting used to generate the barrel/index files.
|
|
528
|
+
*/
|
|
529
|
+
meta?: TMeta;
|
|
530
|
+
/**
|
|
531
|
+
* This will override `process.env[key]` inside the `source`, see `getFileSource`.
|
|
532
|
+
*/
|
|
533
|
+
env?: NodeJS.ProcessEnv;
|
|
534
|
+
};
|
|
535
|
+
type ResolvedFile<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = KubbFile.File<TMeta, TBaseName> & {
|
|
536
|
+
/**
|
|
537
|
+
* @default crypto.randomUUID()
|
|
538
|
+
*/
|
|
539
|
+
id: UUID;
|
|
540
|
+
/**
|
|
541
|
+
* Contains the first part of the baseName, generated based on baseName
|
|
542
|
+
* @link https://nodejs.org/api/path.html#pathformatpathobject
|
|
543
|
+
*/
|
|
544
|
+
name: string;
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
type AddResult<T extends Array<KubbFile.File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<KubbFile.ResolvedFile[]> : Promise<KubbFile.ResolvedFile>>>;
|
|
548
|
+
type AddIndexesProps = {
|
|
549
|
+
/**
|
|
550
|
+
* Root based on root and output.path specified in the config
|
|
551
|
+
*/
|
|
552
|
+
root: string;
|
|
553
|
+
/**
|
|
554
|
+
* Output for plugin
|
|
555
|
+
*/
|
|
556
|
+
output: {
|
|
557
|
+
path: string;
|
|
558
|
+
exportAs?: string;
|
|
559
|
+
extName?: KubbFile.Extname;
|
|
560
|
+
exportType?: 'barrel' | false;
|
|
561
|
+
};
|
|
562
|
+
options?: BarrelManagerOptions;
|
|
563
|
+
meta?: KubbFile.File['meta'];
|
|
583
564
|
};
|
|
584
|
-
type
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
/**
|
|
607
|
-
* TODO move to @kubb/types
|
|
608
|
-
* @deprecated
|
|
609
|
-
*/
|
|
610
|
-
type ArrayWithLength<T extends number, U extends any[] = []> = U['length'] extends T ? U : ArrayWithLength<T, [true, ...U]>;
|
|
611
|
-
/**
|
|
612
|
-
* TODO move to @kubb/types
|
|
613
|
-
* @deprecated
|
|
614
|
-
*/
|
|
615
|
-
type GreaterThan<T extends number, U extends number> = ArrayWithLength<U> extends [...ArrayWithLength<T>, ...infer _] ? false : true;
|
|
565
|
+
type Options$1 = {
|
|
566
|
+
queue?: PQueue;
|
|
567
|
+
task?: (file: KubbFile.ResolvedFile) => Promise<KubbFile.ResolvedFile>;
|
|
568
|
+
};
|
|
569
|
+
declare class FileManager {
|
|
570
|
+
#private;
|
|
571
|
+
constructor({ task, queue }?: Options$1);
|
|
572
|
+
get files(): Array<KubbFile.File>;
|
|
573
|
+
get isExecuting(): boolean;
|
|
574
|
+
add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T>;
|
|
575
|
+
addIndexes({ root, output, meta, options }: AddIndexesProps): Promise<Array<KubbFile.File> | undefined>;
|
|
576
|
+
getCacheByUUID(UUID: KubbFile.UUID): KubbFile.File | undefined;
|
|
577
|
+
get(path: KubbFile.Path): Array<KubbFile.File> | undefined;
|
|
578
|
+
remove(path: KubbFile.Path): void;
|
|
579
|
+
write(...params: Parameters<typeof write>): Promise<string | undefined>;
|
|
580
|
+
read(...params: Parameters<typeof read>): Promise<string>;
|
|
581
|
+
static getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(file: KubbFile.File<TMeta>): string;
|
|
582
|
+
static combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(files: Array<KubbFile.File<TMeta> | null>): Array<KubbFile.File<TMeta>>;
|
|
583
|
+
static getMode(path: string | undefined | null): KubbFile.Mode;
|
|
584
|
+
static get extensions(): Array<KubbFile.Extname>;
|
|
585
|
+
static isExtensionAllowed(baseName: string): boolean;
|
|
586
|
+
}
|
|
616
587
|
|
|
617
588
|
type BuildOptions = {
|
|
618
589
|
config: PluginContext['config'];
|
|
@@ -621,7 +592,16 @@ type BuildOptions = {
|
|
|
621
592
|
*/
|
|
622
593
|
logger?: Logger;
|
|
623
594
|
};
|
|
595
|
+
type BuildOutput = {
|
|
596
|
+
files: FileManager['files'];
|
|
597
|
+
pluginManager: PluginManager;
|
|
598
|
+
/**
|
|
599
|
+
* Only for safeBuild
|
|
600
|
+
*/
|
|
601
|
+
error?: Error;
|
|
602
|
+
};
|
|
624
603
|
declare function build(options: BuildOptions): Promise<BuildOutput>;
|
|
604
|
+
declare function safeBuild(options: BuildOptions): Promise<BuildOutput>;
|
|
625
605
|
|
|
626
606
|
/**
|
|
627
607
|
* Type helper to make it easier to use kubb.config.js
|
|
@@ -633,6 +613,15 @@ declare function defineConfig(options: PossiblePromise<KubbUserConfig | Array<Ku
|
|
|
633
613
|
cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig | Array<KubbUserConfig>>)): typeof options;
|
|
634
614
|
declare function isInputPath(result: KubbConfig | undefined): result is KubbConfig<InputPath>;
|
|
635
615
|
|
|
616
|
+
/**
|
|
617
|
+
* Behaves as an Error to log a warning in the console(still stops the execution)
|
|
618
|
+
*/
|
|
619
|
+
declare class Warning extends Error {
|
|
620
|
+
constructor(message?: string, options?: {
|
|
621
|
+
cause: Error;
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
|
|
636
625
|
/**
|
|
637
626
|
* Abstract class that contains the building blocks for plugins to create their own Generator
|
|
638
627
|
* @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
|
|
@@ -663,22 +652,23 @@ declare class PackageManager {
|
|
|
663
652
|
getPackageJSON(): Promise<PackageJSON | undefined>;
|
|
664
653
|
getPackageJSONSync(): PackageJSON | undefined;
|
|
665
654
|
static setVersion(dependency: DependencyName, version: DependencyVersion): void;
|
|
666
|
-
getVersion(dependency: DependencyName): Promise<DependencyVersion | undefined>;
|
|
667
|
-
getVersionSync(dependency: DependencyName): DependencyVersion | undefined;
|
|
668
|
-
isValid(dependency: DependencyName, version: DependencyVersion): Promise<boolean>;
|
|
669
|
-
isValidSync(dependency: DependencyName, version: DependencyVersion): boolean;
|
|
655
|
+
getVersion(dependency: DependencyName | RegExp): Promise<DependencyVersion | undefined>;
|
|
656
|
+
getVersionSync(dependency: DependencyName | RegExp): DependencyVersion | undefined;
|
|
657
|
+
isValid(dependency: DependencyName | RegExp, version: DependencyVersion): Promise<boolean>;
|
|
658
|
+
isValidSync(dependency: DependencyName | RegExp, version: DependencyVersion): boolean;
|
|
670
659
|
}
|
|
671
660
|
|
|
672
|
-
type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) =>
|
|
661
|
+
type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => KubbUserPluginWithLifeCycle<T>;
|
|
673
662
|
declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
|
|
674
663
|
declare const pluginName = "core";
|
|
675
664
|
|
|
676
|
-
type PromiseFunc$1<T = unknown, T2 = never> = (state
|
|
665
|
+
type PromiseFunc$1<T = unknown, T2 = never> = (state?: T) => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
677
666
|
type ValueOfPromiseFuncArray<TInput extends Array<unknown>> = TInput extends Array<PromiseFunc$1<infer X, infer Y>> ? X | Y : never;
|
|
678
667
|
type SeqOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Array<Awaited<ValueOfPromiseFuncArray<TInput>>>;
|
|
679
668
|
type HookFirstOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue = unknown> = ValueOfPromiseFuncArray<TInput>;
|
|
680
|
-
type
|
|
681
|
-
type
|
|
669
|
+
type HookParallelOutput<TInput extends Array<PromiseFunc$1<TValue, null>>, TValue> = Promise<PromiseSettledResult<Awaited<ValueOfPromiseFuncArray<TInput>>>[]>;
|
|
670
|
+
type Strategy = 'seq' | 'first' | 'parallel';
|
|
671
|
+
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;
|
|
682
672
|
|
|
683
673
|
type PromiseFunc<T = unknown, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
684
674
|
type Options<TState = any> = {
|
|
@@ -690,13 +680,6 @@ declare class PromiseManager<TState = any> {
|
|
|
690
680
|
run<TInput extends Array<PromiseFunc<TValue, null>>, TValue, TStrategy extends Strategy, TOutput = StrategySwitch<TStrategy, TInput, TValue>>(strategy: TStrategy, promises: TInput): TOutput;
|
|
691
681
|
}
|
|
692
682
|
|
|
693
|
-
/**
|
|
694
|
-
* Abstract class that contains the building blocks for plugins to create their own SchemaGenerator
|
|
695
|
-
*/
|
|
696
|
-
declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput> extends Generator<TOptions> {
|
|
697
|
-
abstract build(schema: TInput, name: string, description?: string): TOutput;
|
|
698
|
-
}
|
|
699
|
-
|
|
700
683
|
interface _Register {
|
|
701
684
|
}
|
|
702
685
|
type Plugins = _Register;
|
|
@@ -707,4 +690,4 @@ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
|
|
|
707
690
|
type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
|
|
708
691
|
type Plugin = keyof Plugins;
|
|
709
692
|
|
|
710
|
-
export {
|
|
693
|
+
export { type CLIOptions, FileManager, Generator, type GetPluginFactoryOptions, type InputData, type InputPath, type KubbConfig, KubbFile, type KubbObjectPlugin, type KubbPlugin, 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, type TransformResult, Warning, type _Register, build, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
|