@kubb/core 2.0.0-alpha.4 → 2.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +8 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +185 -182
- package/dist/index.d.ts +185 -182
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +7 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +4 -1
- package/dist/utils.d.ts +4 -1
- package/dist/utils.js +7 -1
- package/dist/utils.js.map +1 -1
- package/package.json +6 -5
- package/src/FileManager.ts +2 -1
- package/src/PluginManager.ts +10 -6
- package/src/PromiseManager.ts +1 -2
- package/src/build.ts +10 -1
- package/src/config.ts +2 -1
- package/src/index.ts +1 -1
- package/src/plugin.ts +3 -3
- package/src/types.ts +88 -112
- package/src/utils/logger.ts +1 -1
- package/src/utils/promise.ts +1 -1
- package/src/utils/transformers/index.ts +2 -0
- package/src/utils/transformers/trim.ts +3 -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,109 +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
|
-
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
49
|
declare const LogLevel: {
|
|
152
50
|
readonly silent: "silent";
|
|
153
51
|
readonly info: "info";
|
|
@@ -187,7 +85,7 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
|
|
|
187
85
|
result: Result;
|
|
188
86
|
plugin: KubbPlugin;
|
|
189
87
|
};
|
|
190
|
-
type Options$
|
|
88
|
+
type Options$2 = {
|
|
191
89
|
logger: Logger;
|
|
192
90
|
/**
|
|
193
91
|
* Task for the FileManager
|
|
@@ -205,13 +103,14 @@ type Events = {
|
|
|
205
103
|
};
|
|
206
104
|
declare class PluginManager {
|
|
207
105
|
#private;
|
|
208
|
-
plugins:
|
|
106
|
+
readonly plugins: KubbPluginWithLifeCycle[];
|
|
209
107
|
readonly fileManager: FileManager;
|
|
210
108
|
readonly eventEmitter: EventEmitter<Events>;
|
|
211
109
|
readonly queue: Queue;
|
|
110
|
+
readonly config: KubbConfig;
|
|
212
111
|
readonly executed: Executer[];
|
|
213
112
|
readonly logger: Logger;
|
|
214
|
-
constructor(config: KubbConfig, options: Options$
|
|
113
|
+
constructor(config: KubbConfig, options: Options$2);
|
|
215
114
|
resolvePath: (params: ResolvePathParams) => KubbFile.OptionalPath;
|
|
216
115
|
resolveName: (params: ResolveNameParams) => string;
|
|
217
116
|
on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
|
|
@@ -298,7 +197,7 @@ type KubbUserConfig = Omit<KubbConfig, 'root' | 'plugins'> & {
|
|
|
298
197
|
* Example: ['@kubb/swagger', { output: false }]
|
|
299
198
|
* Or: createSwagger({ output: false })
|
|
300
199
|
*/
|
|
301
|
-
plugins?: Array<Omit<
|
|
200
|
+
plugins?: Array<Omit<UnknownKubbUserPlugin, 'api'> | KubbUnionPlugins | [name: string, options: object]>;
|
|
302
201
|
};
|
|
303
202
|
type InputPath = {
|
|
304
203
|
/**
|
|
@@ -383,17 +282,54 @@ type CLIOptions = {
|
|
|
383
282
|
*/
|
|
384
283
|
logLevel?: LogLevel;
|
|
385
284
|
};
|
|
386
|
-
type BuildOutput = {
|
|
387
|
-
files: FileManager['files'];
|
|
388
|
-
pluginManager: PluginManager;
|
|
389
|
-
/**
|
|
390
|
-
* Only for safeBuild
|
|
391
|
-
*/
|
|
392
|
-
error?: Error;
|
|
393
|
-
};
|
|
394
285
|
type KubbPluginKind = 'schema' | 'controller';
|
|
395
286
|
type KubbUnionPlugins = PluginUnion;
|
|
396
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
|
+
};
|
|
397
333
|
type GetPluginFactoryOptions<TPlugin extends KubbUserPlugin> = TPlugin extends KubbUserPlugin<infer X> ? X : never;
|
|
398
334
|
type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
399
335
|
/**
|
|
@@ -409,11 +345,11 @@ type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions
|
|
|
409
345
|
/**
|
|
410
346
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
411
347
|
*/
|
|
412
|
-
options: TOptions['
|
|
413
|
-
} &
|
|
348
|
+
options: TOptions['resolvedOptions'];
|
|
349
|
+
} & (TOptions['api'] extends never ? {
|
|
414
350
|
api?: never;
|
|
415
351
|
} : {
|
|
416
|
-
api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext
|
|
352
|
+
api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['api'];
|
|
417
353
|
}) & (TOptions['kind'] extends never ? {
|
|
418
354
|
kind?: never;
|
|
419
355
|
} : {
|
|
@@ -425,6 +361,8 @@ type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions
|
|
|
425
361
|
*/
|
|
426
362
|
kind: TOptions['kind'];
|
|
427
363
|
});
|
|
364
|
+
type KubbUserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbUserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
365
|
+
type UnknownKubbUserPlugin = KubbUserPlugin<PluginFactoryOptions<any, any, any, any, any, any, any>>;
|
|
428
366
|
type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
429
367
|
/**
|
|
430
368
|
* Unique name used for the plugin
|
|
@@ -439,81 +377,70 @@ type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
|
|
|
439
377
|
/**
|
|
440
378
|
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
441
379
|
*/
|
|
442
|
-
options: TOptions['
|
|
380
|
+
options: TOptions['resolvedOptions'];
|
|
443
381
|
/**
|
|
444
382
|
* Kind/type for the plugin
|
|
445
383
|
* Type 'schema' can be used for JSON schema's, TypeScript types, ...
|
|
446
384
|
* Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
|
|
447
385
|
* @default undefined
|
|
448
386
|
*/
|
|
449
|
-
kind?:
|
|
450
|
-
} &
|
|
387
|
+
kind?: TOptions['kind'];
|
|
388
|
+
} & (TOptions['api'] extends never ? {
|
|
451
389
|
api?: never;
|
|
452
390
|
} : {
|
|
453
391
|
api: TOptions['api'];
|
|
454
392
|
});
|
|
455
|
-
type
|
|
456
|
-
name: Name;
|
|
457
|
-
kind: Kind;
|
|
458
|
-
/**
|
|
459
|
-
* Same like `QueryKey` in `@tanstack/react-query`
|
|
460
|
-
*/
|
|
461
|
-
key: [kind: Kind | undefined, name: Name, identifier?: string | number];
|
|
462
|
-
options: Options;
|
|
463
|
-
nested: Nested;
|
|
464
|
-
api: API;
|
|
465
|
-
resolvePathOptions: resolvePathOptions;
|
|
466
|
-
};
|
|
393
|
+
type KubbPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
467
394
|
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
468
395
|
/**
|
|
469
396
|
* Valdiate all plugins to see if their depended plugins are installed and configured.
|
|
470
397
|
* @type hookParallel
|
|
471
398
|
*/
|
|
472
|
-
validate?: (this: Omit<PluginContext
|
|
399
|
+
validate?: (this: Omit<PluginContext<TOptions>, 'addFile'>, plugins: NonNullable<KubbConfig['plugins']>) => PossiblePromise<true>;
|
|
473
400
|
/**
|
|
474
401
|
* Start of the lifecycle of a plugin.
|
|
475
402
|
* @type hookParallel
|
|
476
403
|
*/
|
|
477
|
-
buildStart?: (this: PluginContext
|
|
404
|
+
buildStart?: (this: PluginContext<TOptions>, kubbConfig: KubbConfig) => PossiblePromise<void>;
|
|
478
405
|
/**
|
|
479
406
|
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
480
407
|
* Options can als be included.
|
|
481
408
|
* @type hookFirst
|
|
482
409
|
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
483
410
|
*/
|
|
484
|
-
resolvePath?: (this: PluginContext
|
|
411
|
+
resolvePath?: (this: PluginContext<TOptions>, baseName: string, directory?: string, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
|
|
485
412
|
/**
|
|
486
413
|
* Resolve to a name based on a string.
|
|
487
414
|
* Useful when converting to PascalCase or camelCase.
|
|
488
415
|
* @type hookFirst
|
|
489
416
|
* @example ('pet') => 'Pet'
|
|
490
417
|
*/
|
|
491
|
-
resolveName?: (this: PluginContext
|
|
418
|
+
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
492
419
|
/**
|
|
493
420
|
* Makes it possible to run async logic to override the path defined previously by `resolvePath`.
|
|
494
421
|
* @type hookFirst
|
|
495
422
|
*/
|
|
496
|
-
load?: (this: Omit<PluginContext
|
|
423
|
+
load?: (this: Omit<PluginContext<TOptions>, 'addFile'>, path: KubbFile.Path) => PossiblePromise<TransformResult | null>;
|
|
497
424
|
/**
|
|
498
425
|
* Transform the source-code.
|
|
499
426
|
* @type hookReduceArg0
|
|
500
427
|
*/
|
|
501
|
-
transform?: (this: Omit<PluginContext
|
|
428
|
+
transform?: (this: Omit<PluginContext<TOptions>, 'addFile'>, source: string, path: KubbFile.Path) => PossiblePromise<TransformResult>;
|
|
502
429
|
/**
|
|
503
430
|
* Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
|
|
504
431
|
* @type hookParallel
|
|
505
432
|
*/
|
|
506
|
-
writeFile?: (this: Omit<PluginContext
|
|
433
|
+
writeFile?: (this: Omit<PluginContext<TOptions>, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<string | void>;
|
|
507
434
|
/**
|
|
508
435
|
* End of the plugin lifecycle.
|
|
509
436
|
* @type hookParallel
|
|
510
437
|
*/
|
|
511
|
-
buildEnd?: (this: PluginContext) => PossiblePromise<void>;
|
|
438
|
+
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
512
439
|
};
|
|
513
440
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
514
441
|
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
515
442
|
type PluginCache = Record<string, [number, unknown]>;
|
|
516
|
-
type ResolvePathParams<TOptions =
|
|
443
|
+
type ResolvePathParams<TOptions = object> = {
|
|
517
444
|
pluginKey?: KubbPlugin['key'];
|
|
518
445
|
baseName: string;
|
|
519
446
|
directory?: string | undefined;
|
|
@@ -525,15 +452,15 @@ type ResolvePathParams<TOptions = Record<string, unknown>> = {
|
|
|
525
452
|
type ResolveNameParams = {
|
|
526
453
|
name: string;
|
|
527
454
|
pluginKey?: KubbPlugin['key'];
|
|
528
|
-
type?: 'file' | 'function';
|
|
455
|
+
type?: 'file' | 'function' | 'type';
|
|
529
456
|
};
|
|
530
|
-
type PluginContext<TOptions =
|
|
457
|
+
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
531
458
|
config: KubbConfig;
|
|
532
459
|
cache: Cache<PluginCache>;
|
|
533
460
|
fileManager: FileManager;
|
|
534
461
|
pluginManager: PluginManager;
|
|
535
462
|
addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.File>>;
|
|
536
|
-
resolvePath: (params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
463
|
+
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
|
|
537
464
|
resolveName: (params: ResolveNameParams) => string;
|
|
538
465
|
logger: Logger;
|
|
539
466
|
/**
|
|
@@ -543,44 +470,112 @@ type PluginContext<TOptions = Record<string, unknown>> = {
|
|
|
543
470
|
/**
|
|
544
471
|
* Current plugin
|
|
545
472
|
*/
|
|
546
|
-
plugin: KubbPlugin
|
|
473
|
+
plugin: KubbPlugin<TOptions>;
|
|
547
474
|
};
|
|
548
475
|
type TransformResult = string | null;
|
|
549
|
-
|
|
550
|
-
|
|
476
|
+
|
|
477
|
+
type BasePath<T extends string = string> = `${T}/`;
|
|
478
|
+
declare namespace KubbFile {
|
|
479
|
+
type Import = {
|
|
480
|
+
name: string | Array<string>;
|
|
481
|
+
path: string;
|
|
482
|
+
isTypeOnly?: boolean;
|
|
483
|
+
};
|
|
484
|
+
type Export = {
|
|
485
|
+
name?: string | Array<string>;
|
|
486
|
+
path: string;
|
|
487
|
+
isTypeOnly?: boolean;
|
|
488
|
+
asAlias?: boolean;
|
|
489
|
+
};
|
|
490
|
+
const dataTagSymbol: unique symbol;
|
|
491
|
+
type DataTag<Type, Value> = Type & {
|
|
492
|
+
[dataTagSymbol]: Value;
|
|
493
|
+
};
|
|
494
|
+
type UUID = string;
|
|
495
|
+
type Source = string;
|
|
496
|
+
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
|
|
497
|
+
type Mode = 'file' | 'directory';
|
|
498
|
+
type BaseName = `${string}${Extname}`;
|
|
499
|
+
type Path = string;
|
|
500
|
+
type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
|
|
501
|
+
type OptionalPath = Path | undefined | null;
|
|
502
|
+
type FileMetaBase = {
|
|
503
|
+
pluginKey?: KubbPlugin['key'];
|
|
504
|
+
};
|
|
505
|
+
type File<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = {
|
|
506
|
+
/**
|
|
507
|
+
* Unique identifier to reuse later
|
|
508
|
+
* @default crypto.randomUUID()
|
|
509
|
+
*/
|
|
510
|
+
id?: string;
|
|
511
|
+
/**
|
|
512
|
+
* Name to be used to dynamicly create the baseName(based on input.path)
|
|
513
|
+
* Based on UNIX basename
|
|
514
|
+
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
515
|
+
*/
|
|
516
|
+
baseName: TBaseName;
|
|
517
|
+
/**
|
|
518
|
+
* Path will be full qualified path to a specified file
|
|
519
|
+
*/
|
|
520
|
+
path: AdvancedPath<TBaseName> | Path;
|
|
521
|
+
source: Source;
|
|
522
|
+
imports?: Import[];
|
|
523
|
+
exports?: Export[];
|
|
524
|
+
/**
|
|
525
|
+
* This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
|
|
526
|
+
* This will also ignore the combinefiles utils
|
|
527
|
+
* @default `false`
|
|
528
|
+
*/
|
|
529
|
+
override?: boolean;
|
|
530
|
+
meta?: TMeta;
|
|
531
|
+
/**
|
|
532
|
+
* This will override `process.env[key]` inside the `source`, see `getFileSource`.
|
|
533
|
+
*/
|
|
534
|
+
env?: NodeJS.ProcessEnv;
|
|
535
|
+
validate?: boolean;
|
|
536
|
+
};
|
|
537
|
+
type ResolvedFile<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = KubbFile.File<TMeta, TBaseName> & {
|
|
538
|
+
/**
|
|
539
|
+
* @default crypto.randomUUID()
|
|
540
|
+
*/
|
|
541
|
+
id: UUID;
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
type AddResult<T extends Array<KubbFile.File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<KubbFile.ResolvedFile[]> : Promise<KubbFile.ResolvedFile>>>;
|
|
545
|
+
type AddIndexesProps = {
|
|
546
|
+
root: KubbFile.Path;
|
|
547
|
+
extName?: KubbFile.Extname;
|
|
548
|
+
options?: BarrelManagerOptions;
|
|
549
|
+
meta?: KubbFile.File['meta'];
|
|
551
550
|
};
|
|
552
|
-
type
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
/**
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
* TODO move to @kubb/types
|
|
581
|
-
* @deprecated
|
|
582
|
-
*/
|
|
583
|
-
type GreaterThan<T extends number, U extends number> = ArrayWithLength<U> extends [...ArrayWithLength<T>, ...infer _] ? false : true;
|
|
551
|
+
type Options$1 = {
|
|
552
|
+
queue?: Queue;
|
|
553
|
+
task?: QueueJob<KubbFile.ResolvedFile>;
|
|
554
|
+
/**
|
|
555
|
+
* Timeout between writes
|
|
556
|
+
*/
|
|
557
|
+
timeout?: number;
|
|
558
|
+
};
|
|
559
|
+
declare class FileManager {
|
|
560
|
+
#private;
|
|
561
|
+
constructor(options?: Options$1);
|
|
562
|
+
get files(): Array<KubbFile.File>;
|
|
563
|
+
get isExecuting(): boolean;
|
|
564
|
+
add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T>;
|
|
565
|
+
addIndexes({ root, extName, meta, options }: AddIndexesProps): Promise<Array<KubbFile.File> | undefined>;
|
|
566
|
+
getCacheByUUID(UUID: KubbFile.UUID): KubbFile.File | undefined;
|
|
567
|
+
get(path: KubbFile.Path): Array<KubbFile.File> | undefined;
|
|
568
|
+
remove(path: KubbFile.Path): void;
|
|
569
|
+
write(...params: Parameters<typeof write>): Promise<string | undefined>;
|
|
570
|
+
read(...params: Parameters<typeof read>): Promise<string>;
|
|
571
|
+
static getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(file: KubbFile.File<TMeta>): string;
|
|
572
|
+
static combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(files: Array<KubbFile.File<TMeta> | null>): Array<KubbFile.File<TMeta>>;
|
|
573
|
+
static getMode(path: string | undefined | null): KubbFile.Mode;
|
|
574
|
+
static get extensions(): Array<KubbFile.Extname>;
|
|
575
|
+
static isExtensionAllowed(baseName: string): boolean;
|
|
576
|
+
}
|
|
577
|
+
declare function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export>;
|
|
578
|
+
declare function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import>;
|
|
584
579
|
|
|
585
580
|
type BuildOptions = {
|
|
586
581
|
config: PluginContext['config'];
|
|
@@ -589,6 +584,14 @@ type BuildOptions = {
|
|
|
589
584
|
*/
|
|
590
585
|
logger?: Logger;
|
|
591
586
|
};
|
|
587
|
+
type BuildOutput = {
|
|
588
|
+
files: FileManager['files'];
|
|
589
|
+
pluginManager: PluginManager;
|
|
590
|
+
/**
|
|
591
|
+
* Only for safeBuild
|
|
592
|
+
*/
|
|
593
|
+
error?: Error;
|
|
594
|
+
};
|
|
592
595
|
declare function build(options: BuildOptions): Promise<BuildOutput>;
|
|
593
596
|
declare function safeBuild(options: BuildOptions): Promise<BuildOutput>;
|
|
594
597
|
|
|
@@ -649,7 +652,7 @@ declare class PackageManager {
|
|
|
649
652
|
isValidSync(dependency: DependencyName, version: DependencyVersion): boolean;
|
|
650
653
|
}
|
|
651
654
|
|
|
652
|
-
type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) =>
|
|
655
|
+
type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => KubbUserPluginWithLifeCycle<T>;
|
|
653
656
|
declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
|
|
654
657
|
declare const pluginName = "core";
|
|
655
658
|
|
|
@@ -687,4 +690,4 @@ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
|
|
|
687
690
|
type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
|
|
688
691
|
type Plugin = keyof Plugins;
|
|
689
692
|
|
|
690
|
-
export {
|
|
693
|
+
export { CLIOptions, FileManager, Generator, GetPluginFactoryOptions, InputData, InputPath, KubbConfig, KubbFile, KubbObjectPlugin, KubbPlugin, KubbPluginKind, KubbPluginWithLifeCycle, KubbUnionPlugins, KubbUserConfig, KubbUserPlugin, KubbUserPluginWithLifeCycle, OptionsOfPlugin, OptionsPlugins, PackageManager, Plugin, PluginCache, PluginContext, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PluginParameter, PluginUnion, Plugins, PromiseManager, ResolveNameParams, ResolvePathParams, SchemaGenerator, TransformResult, ValidationPluginError, Warning, _Register, build, combineExports, combineImports, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
|