@kubb/core 2.0.0-alpha.3 → 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.
Files changed (53) hide show
  1. package/dist/index.cjs +70 -75
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +198 -215
  4. package/dist/index.d.ts +198 -215
  5. package/dist/index.js +70 -73
  6. package/dist/index.js.map +1 -1
  7. package/dist/utils.cjs +19 -8
  8. package/dist/utils.cjs.map +1 -1
  9. package/dist/utils.d.cts +6 -2
  10. package/dist/utils.d.ts +6 -2
  11. package/dist/utils.js +19 -8
  12. package/dist/utils.js.map +1 -1
  13. package/package.json +7 -5
  14. package/src/BarrelManager.ts +123 -0
  15. package/src/FileManager.ts +483 -0
  16. package/src/Generator.ts +34 -0
  17. package/src/PackageManager.ts +163 -0
  18. package/src/PluginManager.ts +644 -0
  19. package/src/PromiseManager.ts +47 -0
  20. package/src/SchemaGenerator.ts +8 -0
  21. package/src/build.ts +207 -0
  22. package/src/config.ts +22 -0
  23. package/src/errors.ts +12 -0
  24. package/src/index.ts +28 -0
  25. package/src/plugin.ts +80 -0
  26. package/src/types.ts +346 -0
  27. package/src/utils/EventEmitter.ts +24 -0
  28. package/src/utils/FunctionParams.ts +85 -0
  29. package/src/utils/Queue.ts +110 -0
  30. package/src/utils/TreeNode.ts +122 -0
  31. package/src/utils/URLPath.ts +128 -0
  32. package/src/utils/cache.ts +35 -0
  33. package/src/utils/clean.ts +5 -0
  34. package/src/utils/executeStrategies.ts +71 -0
  35. package/src/utils/index.ts +19 -0
  36. package/src/utils/logger.ts +76 -0
  37. package/src/utils/promise.ts +13 -0
  38. package/src/utils/randomColour.ts +39 -0
  39. package/src/utils/read.ts +68 -0
  40. package/src/utils/renderTemplate.ts +31 -0
  41. package/src/utils/throttle.ts +30 -0
  42. package/src/utils/timeout.ts +7 -0
  43. package/src/utils/transformers/combineCodes.ts +3 -0
  44. package/src/utils/transformers/createJSDocBlockText.ts +15 -0
  45. package/src/utils/transformers/escape.ts +31 -0
  46. package/src/utils/transformers/indent.ts +3 -0
  47. package/src/utils/transformers/index.ts +22 -0
  48. package/src/utils/transformers/nameSorter.ts +9 -0
  49. package/src/utils/transformers/searchAndReplace.ts +25 -0
  50. package/src/utils/transformers/transformReservedWord.ts +97 -0
  51. package/src/utils/transformers/trim.ts +3 -0
  52. package/src/utils/uniqueName.ts +20 -0
  53. 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,145 +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
- 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
49
  declare const LogLevel: {
188
50
  readonly silent: "silent";
189
51
  readonly info: "info";
@@ -223,7 +85,7 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
223
85
  result: Result;
224
86
  plugin: KubbPlugin;
225
87
  };
226
- type Options$1 = {
88
+ type Options$2 = {
227
89
  logger: Logger;
228
90
  /**
229
91
  * Task for the FileManager
@@ -237,17 +99,18 @@ type Options$1 = {
237
99
  type Events = {
238
100
  execute: [executer: Executer];
239
101
  executed: [executer: Executer];
240
- error: [pluginError: PluginError];
102
+ error: [error: Error];
241
103
  };
242
104
  declare class PluginManager {
243
105
  #private;
244
- plugins: KubbPlugin[];
106
+ readonly plugins: KubbPluginWithLifeCycle[];
245
107
  readonly fileManager: FileManager;
246
108
  readonly eventEmitter: EventEmitter<Events>;
247
109
  readonly queue: Queue;
110
+ readonly config: KubbConfig;
248
111
  readonly executed: Executer[];
249
112
  readonly logger: Logger;
250
- constructor(config: KubbConfig, options: Options$1);
113
+ constructor(config: KubbConfig, options: Options$2);
251
114
  resolvePath: (params: ResolvePathParams) => KubbFile.OptionalPath;
252
115
  resolveName: (params: ResolveNameParams) => string;
253
116
  on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
@@ -334,7 +197,7 @@ type KubbUserConfig = Omit<KubbConfig, 'root' | 'plugins'> & {
334
197
  * Example: ['@kubb/swagger', { output: false }]
335
198
  * Or: createSwagger({ output: false })
336
199
  */
337
- plugins?: Array<Omit<KubbUserPlugin, 'api'> | KubbUnionPlugins | [name: string, options: object]>;
200
+ plugins?: Array<Omit<UnknownKubbUserPlugin, 'api'> | KubbUnionPlugins | [name: string, options: object]>;
338
201
  };
339
202
  type InputPath = {
340
203
  /**
@@ -419,13 +282,54 @@ type CLIOptions = {
419
282
  */
420
283
  logLevel?: LogLevel;
421
284
  };
422
- type BuildOutput = {
423
- files: FileManager['files'];
424
- pluginManager: PluginManager;
425
- };
426
285
  type KubbPluginKind = 'schema' | 'controller';
427
286
  type KubbUnionPlugins = PluginUnion;
428
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
+ };
429
333
  type GetPluginFactoryOptions<TPlugin extends KubbUserPlugin> = TPlugin extends KubbUserPlugin<infer X> ? X : never;
430
334
  type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
431
335
  /**
@@ -441,11 +345,11 @@ type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions
441
345
  /**
442
346
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
443
347
  */
444
- options: TOptions['options'] extends never ? undefined : TOptions['options'];
445
- } & Partial<PluginLifecycle<TOptions>> & (TOptions['api'] extends never ? {
348
+ options: TOptions['resolvedOptions'];
349
+ } & (TOptions['api'] extends never ? {
446
350
  api?: never;
447
351
  } : {
448
- api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext, 'addFile'>) => TOptions['api'];
352
+ api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['api'];
449
353
  }) & (TOptions['kind'] extends never ? {
450
354
  kind?: never;
451
355
  } : {
@@ -457,6 +361,8 @@ type KubbUserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions
457
361
  */
458
362
  kind: TOptions['kind'];
459
363
  });
364
+ type KubbUserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbUserPlugin<TOptions> & PluginLifecycle<TOptions>;
365
+ type UnknownKubbUserPlugin = KubbUserPlugin<PluginFactoryOptions<any, any, any, any, any, any, any>>;
460
366
  type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
461
367
  /**
462
368
  * Unique name used for the plugin
@@ -471,81 +377,70 @@ type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
471
377
  /**
472
378
  * Options set for a specific plugin(see kubb.config.js), passthrough of options.
473
379
  */
474
- options: TOptions['options'] extends never ? undefined : TOptions['options'];
380
+ options: TOptions['resolvedOptions'];
475
381
  /**
476
382
  * Kind/type for the plugin
477
383
  * Type 'schema' can be used for JSON schema's, TypeScript types, ...
478
384
  * Type 'controller' can be used to create generate API calls, React-Query hooks, Axios controllers, ...
479
385
  * @default undefined
480
386
  */
481
- kind?: KubbPluginKind;
482
- } & PluginLifecycle<TOptions> & (TOptions['api'] extends never ? {
387
+ kind?: TOptions['kind'];
388
+ } & (TOptions['api'] extends never ? {
483
389
  api?: never;
484
390
  } : {
485
391
  api: TOptions['api'];
486
392
  });
487
- type PluginFactoryOptions<Name = string, Kind extends KubbPluginKind = KubbPluginKind | never, Options = unknown | never, Nested extends boolean = false, API = unknown | never, resolvePathOptions = Record<string, unknown>> = {
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
- };
393
+ type KubbPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = KubbPlugin<TOptions> & PluginLifecycle<TOptions>;
499
394
  type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
500
395
  /**
501
396
  * Valdiate all plugins to see if their depended plugins are installed and configured.
502
397
  * @type hookParallel
503
398
  */
504
- validate?: (this: Omit<PluginContext, 'addFile'>, plugins: NonNullable<KubbConfig['plugins']>) => PossiblePromise<true>;
399
+ validate?: (this: Omit<PluginContext<TOptions>, 'addFile'>, plugins: NonNullable<KubbConfig['plugins']>) => PossiblePromise<true>;
505
400
  /**
506
401
  * Start of the lifecycle of a plugin.
507
402
  * @type hookParallel
508
403
  */
509
- buildStart?: (this: PluginContext, kubbConfig: KubbConfig) => PossiblePromise<void>;
404
+ buildStart?: (this: PluginContext<TOptions>, kubbConfig: KubbConfig) => PossiblePromise<void>;
510
405
  /**
511
406
  * Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
512
407
  * Options can als be included.
513
408
  * @type hookFirst
514
409
  * @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
515
410
  */
516
- resolvePath?: (this: PluginContext, baseName: string, directory?: string, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
411
+ resolvePath?: (this: PluginContext<TOptions>, baseName: string, directory?: string, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
517
412
  /**
518
413
  * Resolve to a name based on a string.
519
414
  * Useful when converting to PascalCase or camelCase.
520
415
  * @type hookFirst
521
416
  * @example ('pet') => 'Pet'
522
417
  */
523
- resolveName?: (this: PluginContext, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
418
+ resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
524
419
  /**
525
420
  * Makes it possible to run async logic to override the path defined previously by `resolvePath`.
526
421
  * @type hookFirst
527
422
  */
528
- load?: (this: Omit<PluginContext, 'addFile'>, path: KubbFile.Path) => PossiblePromise<TransformResult | null>;
423
+ load?: (this: Omit<PluginContext<TOptions>, 'addFile'>, path: KubbFile.Path) => PossiblePromise<TransformResult | null>;
529
424
  /**
530
425
  * Transform the source-code.
531
426
  * @type hookReduceArg0
532
427
  */
533
- transform?: (this: Omit<PluginContext, 'addFile'>, source: string, path: KubbFile.Path) => PossiblePromise<TransformResult>;
428
+ transform?: (this: Omit<PluginContext<TOptions>, 'addFile'>, source: string, path: KubbFile.Path) => PossiblePromise<TransformResult>;
534
429
  /**
535
430
  * Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
536
431
  * @type hookParallel
537
432
  */
538
- writeFile?: (this: Omit<PluginContext, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<string | void>;
433
+ writeFile?: (this: Omit<PluginContext<TOptions>, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<string | void>;
539
434
  /**
540
435
  * End of the plugin lifecycle.
541
436
  * @type hookParallel
542
437
  */
543
- buildEnd?: (this: PluginContext) => PossiblePromise<void>;
438
+ buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
544
439
  };
545
440
  type PluginLifecycleHooks = keyof PluginLifecycle;
546
441
  type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
547
442
  type PluginCache = Record<string, [number, unknown]>;
548
- type ResolvePathParams<TOptions = Record<string, unknown>> = {
443
+ type ResolvePathParams<TOptions = object> = {
549
444
  pluginKey?: KubbPlugin['key'];
550
445
  baseName: string;
551
446
  directory?: string | undefined;
@@ -557,15 +452,15 @@ type ResolvePathParams<TOptions = Record<string, unknown>> = {
557
452
  type ResolveNameParams = {
558
453
  name: string;
559
454
  pluginKey?: KubbPlugin['key'];
560
- type?: 'file' | 'function';
455
+ type?: 'file' | 'function' | 'type';
561
456
  };
562
- type PluginContext<TOptions = Record<string, unknown>> = {
457
+ type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
563
458
  config: KubbConfig;
564
459
  cache: Cache<PluginCache>;
565
460
  fileManager: FileManager;
566
461
  pluginManager: PluginManager;
567
462
  addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.File>>;
568
- resolvePath: (params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
463
+ resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
569
464
  resolveName: (params: ResolveNameParams) => string;
570
465
  logger: Logger;
571
466
  /**
@@ -575,44 +470,112 @@ type PluginContext<TOptions = Record<string, unknown>> = {
575
470
  /**
576
471
  * Current plugin
577
472
  */
578
- plugin: KubbPlugin;
473
+ plugin: KubbPlugin<TOptions>;
579
474
  };
580
475
  type TransformResult = string | null;
581
- type AppMeta = {
582
- pluginManager: PluginManager;
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'];
583
550
  };
584
- type Prettify<T> = {
585
- [K in keyof T]: T[K];
586
- } & {};
587
- /**
588
- * TODO move to @kubb/types
589
- * @deprecated
590
- */
591
- type PossiblePromise<T> = Promise<T> | T;
592
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
593
- type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never;
594
- type Push<T extends any[], V> = [...T, V];
595
- type TuplifyUnion<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<TuplifyUnion<Exclude<T, L>>, L>;
596
- /**
597
- * TODO move to @kubb/types
598
- * @deprecated
599
- */
600
- type ObjValueTuple<T, KS extends any[] = TuplifyUnion<keyof T>, R extends any[] = []> = KS extends [infer K, ...infer KT] ? ObjValueTuple<T, KT, [...R, [name: K & keyof T, options: T[K & keyof T]]]> : R;
601
- /**
602
- * TODO move to @kubb/types
603
- * @deprecated
604
- */
605
- type TupleToUnion<T> = T extends Array<infer ITEMS> ? ITEMS : never;
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;
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>;
616
579
 
617
580
  type BuildOptions = {
618
581
  config: PluginContext['config'];
@@ -621,7 +584,16 @@ type BuildOptions = {
621
584
  */
622
585
  logger?: Logger;
623
586
  };
587
+ type BuildOutput = {
588
+ files: FileManager['files'];
589
+ pluginManager: PluginManager;
590
+ /**
591
+ * Only for safeBuild
592
+ */
593
+ error?: Error;
594
+ };
624
595
  declare function build(options: BuildOptions): Promise<BuildOutput>;
596
+ declare function safeBuild(options: BuildOptions): Promise<BuildOutput>;
625
597
 
626
598
  /**
627
599
  * Type helper to make it easier to use kubb.config.js
@@ -633,6 +605,17 @@ declare function defineConfig(options: PossiblePromise<KubbUserConfig | Array<Ku
633
605
  cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig | Array<KubbUserConfig>>)): typeof options;
634
606
  declare function isInputPath(result: KubbConfig | undefined): result is KubbConfig<InputPath>;
635
607
 
608
+ /**
609
+ * Behaves as an Error to log a warning in the console(still stops the execution)
610
+ */
611
+ declare class Warning extends Error {
612
+ constructor(message?: string, options?: {
613
+ cause: Error;
614
+ });
615
+ }
616
+ declare class ValidationPluginError extends Error {
617
+ }
618
+
636
619
  /**
637
620
  * Abstract class that contains the building blocks for plugins to create their own Generator
638
621
  * @link idea based on https://github.com/colinhacks/zod/blob/master/src/types.ts#L137
@@ -669,7 +652,7 @@ declare class PackageManager {
669
652
  isValidSync(dependency: DependencyName, version: DependencyVersion): boolean;
670
653
  }
671
654
 
672
- type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => KubbUserPlugin<T>;
655
+ type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => KubbUserPluginWithLifeCycle<T>;
673
656
  declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
674
657
  declare const pluginName = "core";
675
658
 
@@ -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 { AppMeta, BuildOutput, CLIOptions, FileManager, Generator, GetPluginFactoryOptions, GreaterThan, InputData, InputPath, KubbConfig, KubbFile, KubbObjectPlugin, KubbPlugin, KubbPluginKind, KubbUnionPlugins, KubbUserConfig, KubbUserPlugin, ObjValueTuple, OptionsOfPlugin, OptionsPlugins, PackageManager, ParallelPluginError, Plugin, PluginCache, PluginContext, PluginError, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PluginParameter, PluginUnion, Plugins, PossiblePromise, Prettify, PromiseManager, ResolveNameParams, ResolvePathParams, SchemaGenerator, SummaryError, TransformResult, TupleToUnion, ValidationPluginError, Warning, _Register, build, combineExports, combineImports, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName };
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 };