@kubb/core 1.2.1 → 1.2.2

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
@@ -27,7 +27,7 @@ interface Cache<TStore extends object = object> {
27
27
  has(id: keyof TStore): boolean;
28
28
  set(id: keyof TStore, value: unknown): void;
29
29
  }
30
- declare function createPluginCache<TStore extends Record<string, [number, unknown]>>(Store: TStore): Cache<TStore>;
30
+ declare function createPluginCache<TStore extends PluginCache>(Store?: TStore): Cache<TStore>;
31
31
 
32
32
  declare function getRelativePath(rootDir?: string | null, filePath?: string | null, platform?: 'windows' | 'mac' | 'linux'): string;
33
33
  type PathMode = 'file' | 'directory';
@@ -48,7 +48,7 @@ declare function objectToParameters(data: Data, options?: Options$2): string;
48
48
 
49
49
  declare function nameSorter<T extends {
50
50
  name: string;
51
- }>(a: T, b: T): 1 | -1 | 0;
51
+ }>(a: T, b: T): 0 | 1 | -1;
52
52
 
53
53
  declare function createJSDocBlockText({ comments }: {
54
54
  comments: Array<string>;
@@ -95,7 +95,7 @@ declare class TreeNode<T = unknown> {
95
95
  static build<T = unknown>(path: string, options?: TreeNodeOptions): TreeNode<T> | null;
96
96
  }
97
97
 
98
- declare function transformReservedWord(word?: string | null): string | null | undefined;
98
+ declare function transformReservedWord(word: string): string;
99
99
 
100
100
  declare function getStackTrace(belowFn?: Function): NodeJS.CallSite[];
101
101
 
@@ -230,7 +230,7 @@ type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseRe
230
230
  plugin: KubbPlugin;
231
231
  };
232
232
 
233
- declare const hooks: [keyof PluginLifecycle<PluginFactoryOptions<string, unknown, false, any, Record<string, any>>>];
233
+ declare const hooks: [keyof PluginLifecycle<PluginFactoryOptions<string, unknown, false, any, Record<string, unknown>>>];
234
234
  type Options$1 = {
235
235
  debug?: boolean;
236
236
  task: QueueTask<ResolvedFile>;
@@ -247,8 +247,8 @@ declare class PluginManager {
247
247
  logger: Logger;
248
248
  constructor(config: KubbConfig, options: Options$1);
249
249
  resolvePath: (params: ResolvePathParams) => OptionalPath;
250
- resolveName: (params: ResolveNameParams) => string | null;
251
- load: (id: string) => Promise<SafeParseResult<"load">>;
250
+ resolveName: (params: ResolveNameParams) => string;
251
+ load: (id: string) => Promise<SafeParseResult<'load'>>;
252
252
  /**
253
253
  *
254
254
  * Run only hook for a specific plugin name
@@ -448,10 +448,6 @@ type CLIOptions = {
448
448
  * Watch changes on input
449
449
  */
450
450
  watch?: string;
451
- /**
452
- * Override `input` defined in `kubb.config.js`
453
- */
454
- input?: string;
455
451
  /**
456
452
  * Override `logLevel` defined in `kubb.config.js`
457
453
  * @default `'silent'`
@@ -513,7 +509,7 @@ type KubbPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> =
513
509
  */
514
510
  api?: TOptions['api'];
515
511
  } & Partial<PluginLifecycle<TOptions>>;
516
- type PluginFactoryOptions<Name = string, Options = unknown, Nested extends boolean = false, API = any, resolvePathOptions = Record<string, any>> = {
512
+ type PluginFactoryOptions<Name = string, Options = unknown, Nested extends boolean = false, API = any, resolvePathOptions = Record<string, unknown>> = {
517
513
  name: Name;
518
514
  options: Options;
519
515
  nested: Nested;
@@ -567,7 +563,8 @@ type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOption
567
563
  buildEnd: (this: PluginContext) => PossiblePromise<void>;
568
564
  };
569
565
  type PluginLifecycleHooks = keyof PluginLifecycle;
570
- type ResolvePathParams<TOptions = Record<string, any>> = {
566
+ type PluginCache = Record<string, [number, unknown]>;
567
+ type ResolvePathParams<TOptions = Record<string, unknown>> = {
571
568
  /**
572
569
  * When set, resolvePath will only call resolvePath of the name of the plugin set here.
573
570
  * If not defined it will fall back on the resolvePath of the core plugin.
@@ -588,13 +585,13 @@ type ResolveNameParams = {
588
585
  pluginName?: string;
589
586
  name: string;
590
587
  };
591
- type PluginContext<TOptions = Record<string, any>> = {
588
+ type PluginContext<TOptions = Record<string, unknown>> = {
592
589
  config: KubbConfig;
593
- cache: Cache;
590
+ cache: Cache<PluginCache>;
594
591
  fileManager: FileManager;
595
592
  addFile: (...file: File[]) => Promise<File[]>;
596
593
  resolvePath: (params: ResolvePathParams<TOptions>) => OptionalPath;
597
- resolveName: (params: ResolveNameParams) => string | null | undefined;
594
+ resolveName: (params: ResolveNameParams) => string;
598
595
  load: (id: string) => Promise<SafeParseResult<'load'>>;
599
596
  logger: Logger;
600
597
  };
@@ -627,10 +624,12 @@ declare function build(options: BuildOptions): Promise<BuildOutput>;
627
624
  * accepts a direct {@link KubbConfig} object, or a function that returns it.
628
625
  * The function receives a {@link ConfigEnv} object that exposes two properties:
629
626
  */
630
- declare const defineConfig: (options: PossiblePromise<KubbUserConfig> | ((cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig>)) => PossiblePromise<KubbUserConfig> | ((cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig>);
627
+ declare function defineConfig(options: PossiblePromise<KubbUserConfig> | ((
628
+ /** The options derived from the CLI flags */
629
+ cliOptions: CLIOptions) => PossiblePromise<KubbUserConfig>)): typeof options;
631
630
 
632
631
  type KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (options: T['options']) => T['nested'] extends true ? Array<KubbUserPlugin<T>> : KubbUserPlugin<T>;
633
- declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => T["nested"] extends true ? KubbUserPlugin<T>[] : KubbUserPlugin<T>;
632
+ declare function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>): (options: T['options']) => ReturnType<KubbPluginFactory<T>>;
634
633
  type Options = {
635
634
  config: PluginContext['config'];
636
635
  fileManager: FileManager;
@@ -660,4 +659,4 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
660
659
  abstract build(schema: TInput, name: string, description?: string): TOutput;
661
660
  }
662
661
 
663
- export { Argument0, BuildOutput, CLIOptions, Cache, CorePluginOptions, Executer, Extension, File, FileManager, FileName, Generator, KubbConfig, KubbJSONPlugins, KubbObjectPlugin, KubbObjectPlugins, KubbPlugin, KubbPluginKind, KubbUserConfig, KubbUserPlugin, LogLevel, LogLevels, LogType, Logger, OnExecute, OptionalPath, ParallelPluginError, ParseResult, Path, PathMode, PluginContext, PluginError, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PossiblePromise, Queue, QueueTask, Register, ResolveNameParams, ResolvePathParams, ResolvedFile, SafeParseResult, SchemaGenerator, Source, Status, Strategy, SummaryError, TransformResult, TreeNode, TreeNodeOptions, UUID, ValidationPluginError, Warning, build, canLogHierarchy, clean, combineFiles, createJSDocBlockText, createLogger, createPlugin, createPluginCache, build as default, defaultColours, defineConfig, extensions, getEncodedText, getFileSource, getLocation, getPathMode, getRelativePath, getStackTrace, getUniqueName, hooks, importModule, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, isURL, pluginName as name, nameSorter, normalizeDirectory, objectToParameters, pluginName, randomColour, randomPicoColour, read, renderTemplate, throttle, timeout, transformReservedWord, uniqueId, validatePlugins, write, writeIndexes };
662
+ export { Argument0, BuildOutput, CLIOptions, Cache, CorePluginOptions, Executer, Extension, File, FileManager, FileName, Generator, KubbConfig, KubbJSONPlugins, KubbObjectPlugin, KubbObjectPlugins, KubbPlugin, KubbPluginKind, KubbUserConfig, KubbUserPlugin, LogLevel, LogLevels, LogType, Logger, OnExecute, OptionalPath, ParallelPluginError, ParseResult, Path, PathMode, PluginCache, PluginContext, PluginError, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PossiblePromise, Queue, QueueTask, Register, ResolveNameParams, ResolvePathParams, ResolvedFile, SafeParseResult, SchemaGenerator, Source, Status, Strategy, SummaryError, TransformResult, TreeNode, TreeNodeOptions, UUID, ValidationPluginError, Warning, build, canLogHierarchy, clean, combineFiles, createJSDocBlockText, createLogger, createPlugin, createPluginCache, build as default, defaultColours, defineConfig, extensions, getEncodedText, getFileSource, getLocation, getPathMode, getRelativePath, getStackTrace, getUniqueName, hooks, importModule, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, isURL, pluginName as name, nameSorter, normalizeDirectory, objectToParameters, pluginName, randomColour, randomPicoColour, read, renderTemplate, throttle, timeout, transformReservedWord, uniqueId, validatePlugins, write, writeIndexes };
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import { rimraf } from 'rimraf';
8
8
  import dirTree from 'directory-tree';
9
9
  import mod from 'node:module';
10
10
  import { pathToFileURL } from 'node:url';
11
- import pc2 from 'picocolors';
11
+ import pc3 from 'picocolors';
12
12
  export { default as pc } from 'picocolors';
13
13
  import seedrandom from 'seedrandom';
14
14
  import { createImportDeclaration, print, createExportDeclaration } from '@kubb/ts-codegen';
@@ -44,7 +44,7 @@ async function write(data, path) {
44
44
  }
45
45
 
46
46
  // src/utils/cache.ts
47
- function createPluginCache(Store) {
47
+ function createPluginCache(Store = /* @__PURE__ */ Object.create(null)) {
48
48
  return {
49
49
  set(id, value) {
50
50
  Store[id] = [0, value];
@@ -506,7 +506,7 @@ function createLogger(spinner) {
506
506
  };
507
507
  const warn = (message) => {
508
508
  if (message && spinner) {
509
- spinner.warn(pc2.yellow(message));
509
+ spinner.warn(pc3.yellow(message));
510
510
  }
511
511
  };
512
512
  const info = (message) => {
@@ -539,7 +539,7 @@ function randomColour(text, colours = defaultColours) {
539
539
  return colour;
540
540
  }
541
541
  function randomPicoColour(text, colors = defaultColours) {
542
- const colours = pc2.createColors(true);
542
+ const colours = pc3.createColors(true);
543
543
  if (!text) {
544
544
  return colours.white(text);
545
545
  }
@@ -548,7 +548,7 @@ function randomPicoColour(text, colors = defaultColours) {
548
548
  const key = colour.replace("dark", "").toLowerCase();
549
549
  const formatter = colours[key];
550
550
  if (isDark) {
551
- return pc2.bold(formatter(text));
551
+ return pc3.bold(formatter(text));
552
552
  }
553
553
  if (typeof formatter !== "function") {
554
554
  throw new Error("Formatter for picoColor is not of type function/Formatter");
@@ -870,7 +870,7 @@ var definePlugin = createPlugin((options) => {
870
870
  return transformReservedWord(name);
871
871
  },
872
872
  load,
873
- cache: createPluginCache(/* @__PURE__ */ Object.create(null))
873
+ cache: createPluginCache()
874
874
  };
875
875
  },
876
876
  resolvePath(fileName) {
@@ -990,7 +990,7 @@ var PluginManager = class {
990
990
  pluginName: params.pluginName,
991
991
  hookName: "resolveName",
992
992
  parameters: [params.name]
993
- });
993
+ }) || params.name;
994
994
  }
995
995
  return this.hookFirstSync({
996
996
  hookName: "resolveName",
@@ -1309,7 +1309,12 @@ async function build(options) {
1309
1309
  await read(config.input.path);
1310
1310
  }
1311
1311
  } catch (e) {
1312
- throw new Error("Cannot read file/URL defined in `input.path` or set with --input in the CLI of your Kubb config", { cause: e });
1312
+ throw new Error(
1313
+ "Cannot read file/URL defined in `input.path` or set with `kubb generate PATH` in the CLI of your Kubb config " + pc3.dim(config.input.path),
1314
+ {
1315
+ cause: e
1316
+ }
1317
+ );
1313
1318
  }
1314
1319
  if (config.output.clean) {
1315
1320
  await clean(config.output.path);
@@ -1357,9 +1362,9 @@ async function build(options) {
1357
1362
  if (config.logLevel === LogLevel.stacktrace && logger?.spinner && input) {
1358
1363
  logger.info(messsage);
1359
1364
  const logs = [
1360
- input && `${pc2.bgWhite(`Input`)} ${randomPicoColour(plugin.name)} ${hookName}`,
1365
+ input && `${pc3.bgWhite(`Input`)} ${randomPicoColour(plugin.name)} ${hookName}`,
1361
1366
  JSON.stringify(input, void 0, 2),
1362
- output && `${pc2.bgWhite("Output")} ${randomPicoColour(plugin.name)} ${hookName}`,
1367
+ output && `${pc3.bgWhite("Output")} ${randomPicoColour(plugin.name)} ${hookName}`,
1363
1368
  output
1364
1369
  ].filter(Boolean);
1365
1370
  console.log(logs.join("\n"));
@@ -1380,7 +1385,9 @@ async function build(options) {
1380
1385
  }
1381
1386
 
1382
1387
  // src/config.ts
1383
- var defineConfig = (options) => options;
1388
+ function defineConfig(options) {
1389
+ return options;
1390
+ }
1384
1391
 
1385
1392
  // src/generators/Generator.ts
1386
1393
  var Generator = class {