@kubb/core 2.0.0-alpha.4 → 2.0.0-alpha.6

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.d.ts 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$1 = {
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: KubbPlugin[];
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$1);
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<KubbUserPlugin, 'api'> | KubbUnionPlugins | [name: string, options: object]>;
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['options'] extends never ? undefined : TOptions['options'];
413
- } & Partial<PluginLifecycle<TOptions>> & (TOptions['api'] extends never ? {
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, 'addFile'>) => TOptions['api'];
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['options'] extends never ? undefined : TOptions['options'];
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?: KubbPluginKind;
450
- } & PluginLifecycle<TOptions> & (TOptions['api'] extends never ? {
387
+ kind?: TOptions['kind'];
388
+ } & (TOptions['api'] extends never ? {
451
389
  api?: never;
452
390
  } : {
453
391
  api: TOptions['api'];
454
392
  });
455
- type PluginFactoryOptions<Name = string, Kind extends KubbPluginKind = KubbPluginKind | never, Options = unknown | never, Nested extends boolean = false, API = unknown | never, resolvePathOptions = Record<string, unknown>> = {
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, 'addFile'>, plugins: NonNullable<KubbConfig['plugins']>) => PossiblePromise<true>;
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, kubbConfig: KubbConfig) => PossiblePromise<void>;
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, baseName: string, directory?: string, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
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, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
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, 'addFile'>, path: KubbFile.Path) => PossiblePromise<TransformResult | null>;
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, 'addFile'>, source: string, path: KubbFile.Path) => PossiblePromise<TransformResult>;
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, '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>;
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 = Record<string, unknown>> = {
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 = Record<string, unknown>> = {
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,153 @@ 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
- type AppMeta = {
550
- pluginManager: PluginManager;
476
+
477
+ type BasePath<T extends string = string> = `${T}/`;
478
+ declare namespace KubbFile {
479
+ type Import = {
480
+ /**
481
+ * Import name to be used
482
+ * @example ["useState"]
483
+ * @examples "React"
484
+ */
485
+ name: string | Array<string>;
486
+ /**
487
+ * Path for the import
488
+ * @xample '@kubb/core'
489
+ */
490
+ path: string;
491
+ /**
492
+ * Add `type` prefix to the import, this will result in: `import type { Type } from './path'`
493
+ */
494
+ isTypeOnly?: boolean;
495
+ };
496
+ type Export = {
497
+ /**
498
+ * Export name to be used
499
+ * @example ["useState"]
500
+ * @examples "React"
501
+ */
502
+ name?: string | Array<string>;
503
+ /**
504
+ * Path for the import
505
+ * @xample '@kubb/core'
506
+ */
507
+ path: string;
508
+ /**
509
+ * Add `type` prefix to the export, this will result in: `export type { Type } from './path'`
510
+ */
511
+ isTypeOnly?: boolean;
512
+ /**
513
+ * Make it possible to override the name, this will result in: `export * as aliasName from './path'`
514
+ */
515
+ asAlias?: boolean;
516
+ };
517
+ const dataTagSymbol: unique symbol;
518
+ type DataTag<Type, Value> = Type & {
519
+ [dataTagSymbol]: Value;
520
+ };
521
+ type UUID = string;
522
+ type Source = string;
523
+ type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
524
+ type Mode = 'file' | 'directory';
525
+ /**
526
+ * Name to be used to dynamicly create the baseName(based on input.path)
527
+ * Based on UNIX basename
528
+ * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
529
+ */
530
+ type BaseName = `${string}${Extname}`;
531
+ /**
532
+ * Path will be full qualified path to a specified file
533
+ */
534
+ type Path = string;
535
+ type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
536
+ type OptionalPath = Path | undefined | null;
537
+ type FileMetaBase = {
538
+ pluginKey?: KubbPlugin['key'];
539
+ };
540
+ type File<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = {
541
+ /**
542
+ * Unique identifier to reuse later
543
+ * @default crypto.randomUUID()
544
+ */
545
+ id?: string;
546
+ /**
547
+ * Name to be used to dynamicly create the baseName(based on input.path)
548
+ * Based on UNIX basename
549
+ * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
550
+ */
551
+ baseName: TBaseName;
552
+ /**
553
+ * Path will be full qualified path to a specified file
554
+ */
555
+ path: AdvancedPath<TBaseName> | Path;
556
+ source: Source;
557
+ imports?: Import[];
558
+ exports?: Export[];
559
+ /**
560
+ * This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
561
+ * This will also ignore the combinefiles utils
562
+ * @default `false`
563
+ */
564
+ override?: boolean;
565
+ /**
566
+ * Use extra meta, this is getting used to generate the barrel/index files.
567
+ */
568
+ meta?: TMeta;
569
+ /**
570
+ * This will override `process.env[key]` inside the `source`, see `getFileSource`.
571
+ */
572
+ env?: NodeJS.ProcessEnv;
573
+ /**
574
+ * @deprecated
575
+ */
576
+ validate?: boolean;
577
+ };
578
+ type ResolvedFile<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = KubbFile.File<TMeta, TBaseName> & {
579
+ /**
580
+ * @default crypto.randomUUID()
581
+ */
582
+ id: UUID;
583
+ };
584
+ }
585
+ type AddResult<T extends Array<KubbFile.File>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<KubbFile.ResolvedFile[]> : Promise<KubbFile.ResolvedFile>>>;
586
+ type AddIndexesProps = {
587
+ root: KubbFile.Path;
588
+ extName?: KubbFile.Extname;
589
+ options?: BarrelManagerOptions;
590
+ meta?: KubbFile.File['meta'];
551
591
  };
552
- type Prettify<T> = {
553
- [K in keyof T]: T[K];
554
- } & {};
555
- /**
556
- * TODO move to @kubb/types
557
- * @deprecated
558
- */
559
- type PossiblePromise<T> = Promise<T> | T;
560
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
561
- type LastOf<T> = UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never;
562
- type Push<T extends any[], V> = [...T, V];
563
- type TuplifyUnion<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<TuplifyUnion<Exclude<T, L>>, L>;
564
- /**
565
- * TODO move to @kubb/types
566
- * @deprecated
567
- */
568
- 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;
569
- /**
570
- * TODO move to @kubb/types
571
- * @deprecated
572
- */
573
- type TupleToUnion<T> = T extends Array<infer ITEMS> ? ITEMS : never;
574
- /**
575
- * TODO move to @kubb/types
576
- * @deprecated
577
- */
578
- type ArrayWithLength<T extends number, U extends any[] = []> = U['length'] extends T ? U : ArrayWithLength<T, [true, ...U]>;
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;
592
+ type Options$1 = {
593
+ queue?: Queue;
594
+ task?: QueueJob<KubbFile.ResolvedFile>;
595
+ /**
596
+ * Timeout between writes
597
+ */
598
+ timeout?: number;
599
+ };
600
+ declare class FileManager {
601
+ #private;
602
+ constructor(options?: Options$1);
603
+ get files(): Array<KubbFile.File>;
604
+ get isExecuting(): boolean;
605
+ add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T>;
606
+ addIndexes({ root, extName, meta, options }: AddIndexesProps): Promise<Array<KubbFile.File> | undefined>;
607
+ getCacheByUUID(UUID: KubbFile.UUID): KubbFile.File | undefined;
608
+ get(path: KubbFile.Path): Array<KubbFile.File> | undefined;
609
+ remove(path: KubbFile.Path): void;
610
+ write(...params: Parameters<typeof write>): Promise<string | undefined>;
611
+ read(...params: Parameters<typeof read>): Promise<string>;
612
+ static getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(file: KubbFile.File<TMeta>): string;
613
+ static combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(files: Array<KubbFile.File<TMeta> | null>): Array<KubbFile.File<TMeta>>;
614
+ static getMode(path: string | undefined | null): KubbFile.Mode;
615
+ static get extensions(): Array<KubbFile.Extname>;
616
+ static isExtensionAllowed(baseName: string): boolean;
617
+ }
618
+ declare function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export>;
619
+ declare function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import>;
584
620
 
585
621
  type BuildOptions = {
586
622
  config: PluginContext['config'];
@@ -589,6 +625,14 @@ type BuildOptions = {
589
625
  */
590
626
  logger?: Logger;
591
627
  };
628
+ type BuildOutput = {
629
+ files: FileManager['files'];
630
+ pluginManager: PluginManager;
631
+ /**
632
+ * Only for safeBuild
633
+ */
634
+ error?: Error;
635
+ };
592
636
  declare function build(options: BuildOptions): Promise<BuildOutput>;
593
637
  declare function safeBuild(options: BuildOptions): Promise<BuildOutput>;
594
638
 
@@ -643,13 +687,13 @@ declare class PackageManager {
643
687
  getPackageJSON(): Promise<PackageJSON | undefined>;
644
688
  getPackageJSONSync(): PackageJSON | undefined;
645
689
  static setVersion(dependency: DependencyName, version: DependencyVersion): void;
646
- getVersion(dependency: DependencyName): Promise<DependencyVersion | undefined>;
647
- getVersionSync(dependency: DependencyName): DependencyVersion | undefined;
648
- isValid(dependency: DependencyName, version: DependencyVersion): Promise<boolean>;
649
- isValidSync(dependency: DependencyName, version: DependencyVersion): boolean;
690
+ getVersion(dependency: DependencyName | RegExp): Promise<DependencyVersion | undefined>;
691
+ getVersionSync(dependency: DependencyName | RegExp): DependencyVersion | undefined;
692
+ isValid(dependency: DependencyName | RegExp, version: DependencyVersion): Promise<boolean>;
693
+ isValidSync(dependency: DependencyName | RegExp, version: DependencyVersion): boolean;
650
694
  }
651
695
 
652
- type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => KubbUserPlugin<T>;
696
+ type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => KubbUserPluginWithLifeCycle<T>;
653
697
  declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
654
698
  declare const pluginName = "core";
655
699
 
@@ -687,4 +731,4 @@ type OptionsOfPlugin<K extends keyof Plugins> = Plugins[K]['options'];
687
731
  type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
688
732
  type Plugin = keyof Plugins;
689
733
 
690
- export { AppMeta, BuildOutput, CLIOptions, FileManager, Generator, GetPluginFactoryOptions, GreaterThan, InputData, InputPath, KubbConfig, KubbFile, KubbObjectPlugin, KubbPlugin, KubbPluginKind, KubbUnionPlugins, KubbUserConfig, KubbUserPlugin, ObjValueTuple, OptionsOfPlugin, OptionsPlugins, PackageManager, Plugin, PluginCache, PluginContext, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PluginParameter, PluginUnion, Plugins, PossiblePromise, Prettify, PromiseManager, ResolveNameParams, ResolvePathParams, SchemaGenerator, TransformResult, TupleToUnion, ValidationPluginError, Warning, _Register, build, combineExports, combineImports, createPlugin, build as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
734
+ 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 };
package/dist/index.js CHANGED
@@ -85,7 +85,7 @@ function createLogger({ logLevel, name, spinner }) {
85
85
  }
86
86
  };
87
87
  const info = (message) => {
88
- if (message && spinner) {
88
+ if (message && spinner && logLevel !== LogLevel.silent) {
89
89
  spinner.info(message);
90
90
  logs.push(message);
91
91
  }
@@ -436,6 +436,11 @@ function transformReservedWord(word) {
436
436
  return word;
437
437
  }
438
438
 
439
+ // src/utils/transformers/trim.ts
440
+ function trim(text) {
441
+ return text.replaceAll(/\n/g, "").trim();
442
+ }
443
+
439
444
  // src/utils/transformers/index.ts
440
445
  var transformers = {
441
446
  combineCodes,
@@ -445,6 +450,7 @@ var transformers = {
445
450
  transformReservedWord,
446
451
  nameSorter,
447
452
  searchAndReplace,
453
+ trim,
448
454
  JSDoc: {
449
455
  createJSDocBlockText
450
456
  }
@@ -1285,6 +1291,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
1285
1291
  }).result;
1286
1292
  return transformReservedWord(name);
1287
1293
  };
1294
+ this.config = config;
1288
1295
  this.logger = options.logger;
1289
1296
  this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
1290
1297
  this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
@@ -1797,9 +1804,10 @@ var Generator = class {
1797
1804
  };
1798
1805
  _options3 = new WeakMap();
1799
1806
  _context = new WeakMap();
1800
- var _cache2, _cwd, _SLASHES;
1807
+ var _cache2, _cwd, _SLASHES, _match, match_fn;
1801
1808
  var _PackageManager = class _PackageManager {
1802
1809
  constructor(workspace) {
1810
+ __privateAdd(this, _match);
1803
1811
  __privateAdd(this, _cwd, void 0);
1804
1812
  __privateAdd(this, _SLASHES, /* @__PURE__ */ new Set(["/", "\\"]));
1805
1813
  if (workspace) {
@@ -1862,24 +1870,24 @@ var _PackageManager = class _PackageManager {
1862
1870
  __privateGet(_PackageManager, _cache2)[dependency] = version;
1863
1871
  }
1864
1872
  async getVersion(dependency) {
1865
- if (__privateGet(_PackageManager, _cache2)[dependency]) {
1873
+ if (typeof dependency === "string" && __privateGet(_PackageManager, _cache2)[dependency]) {
1866
1874
  return __privateGet(_PackageManager, _cache2)[dependency];
1867
1875
  }
1868
1876
  const packageJSON = await this.getPackageJSON();
1869
1877
  if (!packageJSON) {
1870
1878
  return void 0;
1871
1879
  }
1872
- return packageJSON["dependencies"]?.[dependency] || packageJSON["devDependencies"]?.[dependency];
1880
+ return __privateMethod(this, _match, match_fn).call(this, packageJSON, dependency);
1873
1881
  }
1874
1882
  getVersionSync(dependency) {
1875
- if (__privateGet(_PackageManager, _cache2)[dependency]) {
1883
+ if (typeof dependency === "string" && __privateGet(_PackageManager, _cache2)[dependency]) {
1876
1884
  return __privateGet(_PackageManager, _cache2)[dependency];
1877
1885
  }
1878
1886
  const packageJSON = this.getPackageJSONSync();
1879
1887
  if (!packageJSON) {
1880
1888
  return void 0;
1881
1889
  }
1882
- return packageJSON["dependencies"]?.[dependency] || packageJSON["devDependencies"]?.[dependency];
1890
+ return __privateMethod(this, _match, match_fn).call(this, packageJSON, dependency);
1883
1891
  }
1884
1892
  async isValid(dependency, version) {
1885
1893
  const packageVersion = await this.getVersion(dependency);
@@ -1910,6 +1918,18 @@ var _PackageManager = class _PackageManager {
1910
1918
  _cache2 = new WeakMap();
1911
1919
  _cwd = new WeakMap();
1912
1920
  _SLASHES = new WeakMap();
1921
+ _match = new WeakSet();
1922
+ match_fn = function(packageJSON, dependency) {
1923
+ const dependencies = {
1924
+ ...packageJSON["dependencies"] || {},
1925
+ ...packageJSON["devDependencies"] || {}
1926
+ };
1927
+ if (typeof dependency === "string" && dependencies[dependency]) {
1928
+ return dependencies[dependency];
1929
+ }
1930
+ const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
1931
+ return matchedDependency ? dependencies[matchedDependency] : void 0;
1932
+ };
1913
1933
  __privateAdd(_PackageManager, _cache2, {});
1914
1934
  var PackageManager = _PackageManager;
1915
1935