@kubb/core 2.0.0-alpha.1 → 2.0.0-alpha.11
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 +138 -111
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +266 -223
- package/dist/index.d.ts +266 -223
- package/dist/index.js +138 -109
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +25 -13
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +7 -3
- package/dist/utils.d.ts +7 -3
- package/dist/utils.js +25 -13
- package/dist/utils.js.map +1 -1
- package/package.json +12 -10
- 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,3 +1,4 @@
|
|
|
1
|
+
import { PossiblePromise, GreaterThan, TupleToUnion, ObjValueTuple } from '@kubb/types';
|
|
1
2
|
import { DirectoryTreeOptions } from 'directory-tree';
|
|
2
3
|
import { Ora } from 'ora';
|
|
3
4
|
|
|
@@ -45,141 +46,6 @@ declare class Queue {
|
|
|
45
46
|
get count(): number;
|
|
46
47
|
}
|
|
47
48
|
|
|
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
|
-
type UUID = string;
|
|
62
|
-
type Source = string;
|
|
63
|
-
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
|
|
64
|
-
type Mode = 'file' | 'directory';
|
|
65
|
-
type BaseName = `${string}${Extname}`;
|
|
66
|
-
type Path = string;
|
|
67
|
-
type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
|
|
68
|
-
type OptionalPath = Path | undefined | null;
|
|
69
|
-
type FileMetaBase = {
|
|
70
|
-
pluginKey?: KubbPlugin['key'];
|
|
71
|
-
};
|
|
72
|
-
type File<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = {
|
|
73
|
-
/**
|
|
74
|
-
* Unique identifier to reuse later
|
|
75
|
-
* @default crypto.randomUUID()
|
|
76
|
-
*/
|
|
77
|
-
id?: string;
|
|
78
|
-
/**
|
|
79
|
-
* Name to be used to dynamicly create the baseName(based on input.path)
|
|
80
|
-
* Based on UNIX basename
|
|
81
|
-
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
82
|
-
*/
|
|
83
|
-
baseName: TBaseName;
|
|
84
|
-
/**
|
|
85
|
-
* Path will be full qualified path to a specified file
|
|
86
|
-
*/
|
|
87
|
-
path: AdvancedPath<TBaseName> | Path;
|
|
88
|
-
source: Source;
|
|
89
|
-
imports?: Import[];
|
|
90
|
-
exports?: Export[];
|
|
91
|
-
/**
|
|
92
|
-
* This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
|
|
93
|
-
* This will also ignore the combinefiles utils
|
|
94
|
-
* @default `false`
|
|
95
|
-
*/
|
|
96
|
-
override?: boolean;
|
|
97
|
-
meta?: TMeta;
|
|
98
|
-
/**
|
|
99
|
-
* This will override `process.env[key]` inside the `source`, see `getFileSource`.
|
|
100
|
-
*/
|
|
101
|
-
env?: NodeJS.ProcessEnv;
|
|
102
|
-
validate?: boolean;
|
|
103
|
-
};
|
|
104
|
-
type ResolvedFile = KubbFile.File & {
|
|
105
|
-
/**
|
|
106
|
-
* @default crypto.randomUUID()
|
|
107
|
-
*/
|
|
108
|
-
id: UUID;
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
type AddResult<T extends Array<KubbFile.File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<KubbFile.ResolvedFile[]> : Promise<KubbFile.ResolvedFile>>>;
|
|
112
|
-
type AddIndexesProps = {
|
|
113
|
-
root: KubbFile.Path;
|
|
114
|
-
extName?: KubbFile.Extname;
|
|
115
|
-
options?: BarrelManagerOptions;
|
|
116
|
-
meta?: KubbFile.File['meta'];
|
|
117
|
-
};
|
|
118
|
-
type Options$2 = {
|
|
119
|
-
queue?: Queue;
|
|
120
|
-
task?: QueueJob<KubbFile.ResolvedFile>;
|
|
121
|
-
/**
|
|
122
|
-
* Timeout between writes
|
|
123
|
-
*/
|
|
124
|
-
timeout?: number;
|
|
125
|
-
};
|
|
126
|
-
declare class FileManager {
|
|
127
|
-
#private;
|
|
128
|
-
constructor(options?: Options$2);
|
|
129
|
-
get files(): Array<KubbFile.File>;
|
|
130
|
-
get isExecuting(): boolean;
|
|
131
|
-
add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T>;
|
|
132
|
-
addIndexes({ root, extName, meta, options }: AddIndexesProps): Promise<Array<KubbFile.File> | undefined>;
|
|
133
|
-
getCacheByUUID(UUID: KubbFile.UUID): KubbFile.File | undefined;
|
|
134
|
-
get(path: KubbFile.Path): Array<KubbFile.File> | undefined;
|
|
135
|
-
remove(path: KubbFile.Path): void;
|
|
136
|
-
write(...params: Parameters<typeof write>): Promise<string | undefined>;
|
|
137
|
-
read(...params: Parameters<typeof read>): Promise<string>;
|
|
138
|
-
static getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(file: KubbFile.File<TMeta>): string;
|
|
139
|
-
static combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(files: Array<KubbFile.File<TMeta> | null>): Array<KubbFile.File<TMeta>>;
|
|
140
|
-
static getMode(path: string | undefined | null): KubbFile.Mode;
|
|
141
|
-
static get extensions(): Array<KubbFile.Extname>;
|
|
142
|
-
static isExtensionAllowed(baseName: string): boolean;
|
|
143
|
-
}
|
|
144
|
-
declare function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export>;
|
|
145
|
-
declare function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import>;
|
|
146
|
-
|
|
147
|
-
declare class PluginError extends Error {
|
|
148
|
-
pluginManager: PluginManager;
|
|
149
|
-
cause: Error;
|
|
150
|
-
constructor(message: string, options: {
|
|
151
|
-
cause: Error;
|
|
152
|
-
pluginManager: PluginManager;
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
declare class ParallelPluginError extends Error {
|
|
156
|
-
errors: PluginError[];
|
|
157
|
-
pluginManager: PluginManager;
|
|
158
|
-
constructor(message: string, options: {
|
|
159
|
-
cause?: Error;
|
|
160
|
-
errors: PluginError[];
|
|
161
|
-
pluginManager: PluginManager;
|
|
162
|
-
});
|
|
163
|
-
findError<T extends Error = Error>(searchError: T | undefined): T | undefined;
|
|
164
|
-
}
|
|
165
|
-
declare class SummaryError extends Error {
|
|
166
|
-
summary: string[];
|
|
167
|
-
constructor(message: string, options: {
|
|
168
|
-
cause: Error;
|
|
169
|
-
summary?: string[];
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Behaves as an Error to log a warning in the console(still stops the execution)
|
|
174
|
-
*/
|
|
175
|
-
declare class Warning extends Error {
|
|
176
|
-
constructor(message?: string, options?: {
|
|
177
|
-
cause: Error;
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
declare class ValidationPluginError extends Error {
|
|
181
|
-
}
|
|
182
|
-
|
|
183
49
|
declare const LogLevel: {
|
|
184
50
|
readonly silent: "silent";
|
|
185
51
|
readonly info: "info";
|
|
@@ -219,7 +85,7 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
|
|
|
219
85
|
result: Result;
|
|
220
86
|
plugin: KubbPlugin;
|
|
221
87
|
};
|
|
222
|
-
type Options$
|
|
88
|
+
type Options$2 = {
|
|
223
89
|
logger: Logger;
|
|
224
90
|
/**
|
|
225
91
|
* Task for the FileManager
|
|
@@ -233,18 +99,19 @@ type Options$1 = {
|
|
|
233
99
|
type Events = {
|
|
234
100
|
execute: [executer: Executer];
|
|
235
101
|
executed: [executer: Executer];
|
|
236
|
-
error: [
|
|
102
|
+
error: [error: Error];
|
|
237
103
|
};
|
|
238
104
|
declare class PluginManager {
|
|
239
105
|
#private;
|
|
240
|
-
plugins:
|
|
106
|
+
readonly plugins: KubbPluginWithLifeCycle[];
|
|
241
107
|
readonly fileManager: FileManager;
|
|
242
108
|
readonly eventEmitter: EventEmitter<Events>;
|
|
243
109
|
readonly queue: Queue;
|
|
110
|
+
readonly config: KubbConfig;
|
|
244
111
|
readonly executed: Executer[];
|
|
245
112
|
readonly logger: Logger;
|
|
246
|
-
constructor(config: KubbConfig, options: Options$
|
|
247
|
-
resolvePath: (params: ResolvePathParams) => KubbFile.OptionalPath;
|
|
113
|
+
constructor(config: KubbConfig, options: Options$2);
|
|
114
|
+
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
248
115
|
resolveName: (params: ResolveNameParams) => string;
|
|
249
116
|
on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
|
|
250
117
|
/**
|
|
@@ -330,7 +197,7 @@ type KubbUserConfig = Omit<KubbConfig, 'root' | 'plugins'> & {
|
|
|
330
197
|
* Example: ['@kubb/swagger', { output: false }]
|
|
331
198
|
* Or: createSwagger({ output: false })
|
|
332
199
|
*/
|
|
333
|
-
plugins?: Array<Omit<
|
|
200
|
+
plugins?: Array<Omit<UnknownKubbUserPlugin, 'api'> | KubbUnionPlugins | [name: string, options: object]>;
|
|
334
201
|
};
|
|
335
202
|
type InputPath = {
|
|
336
203
|
/**
|
|
@@ -415,13 +282,54 @@ type CLIOptions = {
|
|
|
415
282
|
*/
|
|
416
283
|
logLevel?: LogLevel;
|
|
417
284
|
};
|
|
418
|
-
type BuildOutput = {
|
|
419
|
-
files: FileManager['files'];
|
|
420
|
-
pluginManager: PluginManager;
|
|
421
|
-
};
|
|
422
285
|
type KubbPluginKind = 'schema' | 'controller';
|
|
423
286
|
type KubbUnionPlugins = PluginUnion;
|
|
424
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;
|
|
332
|
+
};
|
|
425
333
|
type GetPluginFactoryOptions<TPlugin extends KubbUserPlugin> = TPlugin extends KubbUserPlugin<infer X> ? X : never;
|
|
426
334
|
type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
427
335
|
/**
|
|
@@ -437,22 +345,26 @@ type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions
|
|
|
437
345
|
/**
|
|
438
346
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
439
347
|
*/
|
|
440
|
-
options: TOptions['
|
|
441
|
-
} &
|
|
348
|
+
options: TOptions['resolvedOptions'];
|
|
349
|
+
} & (TOptions['api'] extends never ? {
|
|
442
350
|
api?: never;
|
|
443
351
|
} : {
|
|
444
|
-
api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext
|
|
352
|
+
api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['api'];
|
|
445
353
|
}) & (TOptions['kind'] extends never ? {
|
|
446
354
|
kind?: never;
|
|
447
355
|
} : {
|
|
448
356
|
/**
|
|
449
357
|
* Kind/type for the plugin
|
|
358
|
+
*
|
|
450
359
|
* Type 'schema' can be used for JSON schema's, TypeScript types, ...
|
|
360
|
+
*
|
|
451
361
|
* Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
|
|
452
362
|
* @default undefined
|
|
453
363
|
*/
|
|
454
364
|
kind: TOptions['kind'];
|
|
455
365
|
});
|
|
366
|
+
type KubbUserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbUserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
367
|
+
type UnknownKubbUserPlugin = KubbUserPlugin<PluginFactoryOptions<any, any, any, any, any, any, any>>;
|
|
456
368
|
type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
457
369
|
/**
|
|
458
370
|
* Unique name used for the plugin
|
|
@@ -467,81 +379,70 @@ type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
467
379
|
/**
|
|
468
380
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
469
381
|
*/
|
|
470
|
-
options: TOptions['
|
|
382
|
+
options: TOptions['resolvedOptions'];
|
|
471
383
|
/**
|
|
472
384
|
* Kind/type for the plugin
|
|
473
385
|
* Type 'schema' can be used for JSON schema's, TypeScript types, ...
|
|
474
386
|
* Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
|
|
475
387
|
* @default undefined
|
|
476
388
|
*/
|
|
477
|
-
kind?:
|
|
478
|
-
} &
|
|
389
|
+
kind?: TOptions['kind'];
|
|
390
|
+
} & (TOptions['api'] extends never ? {
|
|
479
391
|
api?: never;
|
|
480
392
|
} : {
|
|
481
393
|
api: TOptions['api'];
|
|
482
394
|
});
|
|
483
|
-
type
|
|
484
|
-
name: Name;
|
|
485
|
-
kind: Kind;
|
|
486
|
-
/**
|
|
487
|
-
* Same like `QueryKey` in `@tanstack/react-query`
|
|
488
|
-
*/
|
|
489
|
-
key: [kind: Kind | undefined, name: Name, identifier?: string | number];
|
|
490
|
-
options: Options;
|
|
491
|
-
nested: Nested;
|
|
492
|
-
api: API;
|
|
493
|
-
resolvePathOptions: resolvePathOptions;
|
|
494
|
-
};
|
|
395
|
+
type KubbPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
495
396
|
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
496
397
|
/**
|
|
497
398
|
* Valdiate all plugins to see if their depended plugins are installed and configured.
|
|
498
399
|
* @type hookParallel
|
|
499
400
|
*/
|
|
500
|
-
validate?: (this: Omit<PluginContext
|
|
401
|
+
validate?: (this: Omit<PluginContext<TOptions>, 'addFile'>, plugins: NonNullable<KubbConfig['plugins']>) => PossiblePromise<true>;
|
|
501
402
|
/**
|
|
502
403
|
* Start of the lifecycle of a plugin.
|
|
503
404
|
* @type hookParallel
|
|
504
405
|
*/
|
|
505
|
-
buildStart?: (this: PluginContext
|
|
406
|
+
buildStart?: (this: PluginContext<TOptions>, kubbConfig: KubbConfig) => PossiblePromise<void>;
|
|
506
407
|
/**
|
|
507
408
|
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
508
409
|
* Options can als be included.
|
|
509
410
|
* @type hookFirst
|
|
510
411
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
511
412
|
*/
|
|
512
|
-
resolvePath?: (this: PluginContext
|
|
413
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: string, directory?: string, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
|
|
513
414
|
/**
|
|
514
415
|
* Resolve to a name based on a string.
|
|
515
416
|
* Useful when converting to PascalCase or camelCase.
|
|
516
417
|
* @type hookFirst
|
|
517
418
|
* @example ('pet') => 'Pet'
|
|
518
419
|
*/
|
|
519
|
-
resolveName?: (this: PluginContext
|
|
420
|
+
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
520
421
|
/**
|
|
521
422
|
* Makes it possible to run async logic to override the path defined previously by `resolvePath`.
|
|
522
423
|
* @type hookFirst
|
|
523
424
|
*/
|
|
524
|
-
load?: (this: Omit<PluginContext
|
|
425
|
+
load?: (this: Omit<PluginContext<TOptions>, 'addFile'>, path: KubbFile.Path) => PossiblePromise<TransformResult | null>;
|
|
525
426
|
/**
|
|
526
427
|
* Transform the source-code.
|
|
527
428
|
* @type hookReduceArg0
|
|
528
429
|
*/
|
|
529
|
-
transform?: (this: Omit<PluginContext
|
|
430
|
+
transform?: (this: Omit<PluginContext<TOptions>, 'addFile'>, source: string, path: KubbFile.Path) => PossiblePromise<TransformResult>;
|
|
530
431
|
/**
|
|
531
432
|
* Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
|
|
532
433
|
* @type hookParallel
|
|
533
434
|
*/
|
|
534
|
-
writeFile?: (this: Omit<PluginContext
|
|
435
|
+
writeFile?: (this: Omit<PluginContext<TOptions>, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<string | void>;
|
|
535
436
|
/**
|
|
536
437
|
* End of the plugin lifecycle.
|
|
537
438
|
* @type hookParallel
|
|
538
439
|
*/
|
|
539
|
-
buildEnd?: (this: PluginContext) => PossiblePromise<void>;
|
|
440
|
+
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
540
441
|
};
|
|
541
442
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
542
443
|
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
543
444
|
type PluginCache = Record<string, [number, unknown]>;
|
|
544
|
-
type ResolvePathParams<TOptions =
|
|
445
|
+
type ResolvePathParams<TOptions = object> = {
|
|
545
446
|
pluginKey?: KubbPlugin['key'];
|
|
546
447
|
baseName: string;
|
|
547
448
|
directory?: string | undefined;
|
|
@@ -553,15 +454,20 @@ type ResolvePathParams<TOptions = Record<string, unknown>> = {
|
|
|
553
454
|
type ResolveNameParams = {
|
|
554
455
|
name: string;
|
|
555
456
|
pluginKey?: KubbPlugin['key'];
|
|
556
|
-
|
|
457
|
+
/**
|
|
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)
|
|
461
|
+
*/
|
|
462
|
+
type?: 'file' | 'function' | 'type';
|
|
557
463
|
};
|
|
558
|
-
type PluginContext<TOptions =
|
|
464
|
+
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
559
465
|
config: KubbConfig;
|
|
560
466
|
cache: Cache<PluginCache>;
|
|
561
467
|
fileManager: FileManager;
|
|
562
468
|
pluginManager: PluginManager;
|
|
563
469
|
addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.File>>;
|
|
564
|
-
resolvePath: (params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
470
|
+
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
|
|
565
471
|
resolveName: (params: ResolveNameParams) => string;
|
|
566
472
|
logger: Logger;
|
|
567
473
|
/**
|
|
@@ -571,44 +477,153 @@ type PluginContext<TOptions = Record<string, unknown>> = {
|
|
|
571
477
|
/**
|
|
572
478
|
* Current plugin
|
|
573
479
|
*/
|
|
574
|
-
plugin: KubbPlugin
|
|
480
|
+
plugin: KubbPlugin<TOptions>;
|
|
575
481
|
};
|
|
576
482
|
type TransformResult = string | null;
|
|
577
|
-
|
|
578
|
-
|
|
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'];
|
|
579
598
|
};
|
|
580
|
-
type
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
/**
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
* TODO move to @kubb/types
|
|
609
|
-
* @deprecated
|
|
610
|
-
*/
|
|
611
|
-
type GreaterThan<T extends number, U extends number> = ArrayWithLength<U> extends [...ArrayWithLength<T>, ...infer _] ? false : true;
|
|
599
|
+
type Options$1 = {
|
|
600
|
+
queue?: Queue;
|
|
601
|
+
task?: QueueJob<KubbFile.ResolvedFile>;
|
|
602
|
+
/**
|
|
603
|
+
* Timeout between writes
|
|
604
|
+
*/
|
|
605
|
+
timeout?: number;
|
|
606
|
+
};
|
|
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>;
|
|
612
627
|
|
|
613
628
|
type BuildOptions = {
|
|
614
629
|
config: PluginContext['config'];
|
|
@@ -617,7 +632,16 @@ type BuildOptions = {
|
|
|
617
632
|
*/
|
|
618
633
|
logger?: Logger;
|
|
619
634
|
};
|
|
635
|
+
type BuildOutput = {
|
|
636
|
+
files: FileManager['files'];
|
|
637
|
+
pluginManager: PluginManager;
|
|
638
|
+
/**
|
|
639
|
+
* Only for safeBuild
|
|
640
|
+
*/
|
|
641
|
+
error?: Error;
|
|
642
|
+
};
|
|
620
643
|
declare function build(options: BuildOptions): Promise<BuildOutput>;
|
|
644
|
+
declare function safeBuild(options: BuildOptions): Promise<BuildOutput>;
|
|
621
645
|
|
|
622
646
|
/**
|
|
623
647
|
* Type helper to make it easier to use kubb.config.js
|
|
@@ -629,6 +653,17 @@ declare function defineConfig(options: PossiblePromise<KubbUserConfig | Array<Ku
|
|
|
629
653
|
cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig | Array<KubbUserConfig>>)): typeof options;
|
|
630
654
|
declare function isInputPath(result: KubbConfig | undefined): result is KubbConfig<InputPath>;
|
|
631
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
|
+
}
|
|
666
|
+
|
|
632
667
|
/**
|
|
633
668
|
* Abstract class that contains the building blocks for plugins to create their own Generator
|
|
634
669
|
* @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
|
|
@@ -659,24 +694,32 @@ declare class PackageManager {
|
|
|
659
694
|
getPackageJSON(): Promise<PackageJSON | undefined>;
|
|
660
695
|
getPackageJSONSync(): PackageJSON | undefined;
|
|
661
696
|
static setVersion(dependency: DependencyName, version: DependencyVersion): void;
|
|
662
|
-
getVersion(dependency: DependencyName): Promise<DependencyVersion | undefined>;
|
|
663
|
-
getVersionSync(dependency: DependencyName): DependencyVersion | undefined;
|
|
664
|
-
isValid(dependency: DependencyName, version: DependencyVersion): Promise<boolean>;
|
|
665
|
-
isValidSync(dependency: DependencyName, version: DependencyVersion): boolean;
|
|
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;
|
|
666
701
|
}
|
|
667
702
|
|
|
668
|
-
type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) =>
|
|
703
|
+
type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => KubbUserPluginWithLifeCycle<T>;
|
|
669
704
|
declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
|
|
670
705
|
declare const pluginName = "core";
|
|
671
706
|
|
|
672
|
-
type PromiseFunc<T, T2 = never> = () => T2 extends never ? Promise<T> : Promise<T> | T2;
|
|
673
|
-
type
|
|
674
|
-
type
|
|
675
|
-
type
|
|
676
|
-
|
|
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> {
|
|
677
720
|
#private;
|
|
678
|
-
constructor(options?: Options);
|
|
679
|
-
run<TInput extends Array<PromiseFunc<
|
|
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;
|
|
680
723
|
}
|
|
681
724
|
|
|
682
725
|
/**
|
|
@@ -696,4 +739,4 @@ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
|
|
|
696
739
|
type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
|
|
697
740
|
type Plugin = keyof Plugins;
|
|
698
741
|
|
|
699
|
-
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 };
|