@kubb/core 1.12.0 → 1.13.0-canary.20231018T144840

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.cts CHANGED
@@ -468,6 +468,21 @@ declare class ParallelPluginError extends Error {
468
468
  findError<T extends Error = Error>(searchError: T | undefined): T | undefined;
469
469
  }
470
470
 
471
+ type PackageJSON = {
472
+ dependencies?: Record<string, string>;
473
+ devDependencies?: Record<string, string>;
474
+ };
475
+ declare class PackageManager {
476
+ private cwd;
477
+ constructor(workspace?: string);
478
+ getPackageJSON(): Promise<PackageJSON | undefined>;
479
+ getPackageJSONSync(): PackageJSON | undefined;
480
+ getVersion(dependency: string): Promise<string | undefined>;
481
+ getVersionSync(dependency: string): string | undefined;
482
+ isValid(dependency: string, version: string): Promise<boolean>;
483
+ isValidSync(dependency: string, version: string): boolean;
484
+ }
485
+
471
486
  /**
472
487
  * Config used in `kubb.config.js`
473
488
  *
@@ -506,6 +521,11 @@ type KubbConfig = {
506
521
  * the defined root option.
507
522
  */
508
523
  path: string;
524
+ } | {
525
+ /**
526
+ * String or object containing the data that you would normally import.
527
+ */
528
+ data: string | unknown;
509
529
  };
510
530
  output: {
511
531
  /**
@@ -768,4 +788,4 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
768
788
  abstract build(schema: TInput, name: string, description?: string): TOutput;
769
789
  }
770
790
 
771
- export { AppMeta, Argument0, BuildOutput, CLIOptions, Cache, CacheItem, Executer, FileManager, FunctionParams, FunctionParamsAST, Generator, KubbConfig, KubbFile, KubbJSONPlugins, KubbObjectPlugin, KubbObjectPlugins, KubbPlugin, KubbPluginKind, KubbUserConfig, KubbUserPlugin, LogLevel, LogType, Logger, ParallelPluginError, ParseResult, PluginCache, PluginContext, PluginError, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PossiblePromise, Prettify, Queue, QueueJob, ResolveNameParams, ResolvePathParams, SafeParseResult, SchemaGenerator, Strategy, SummaryError, TransformResult, TreeNode, TreeNodeOptions, URLObject, URLPath, ValidationPluginError, Warning, build, clean, combineCodes, combineExports, combineFiles, combineImports, createFileSource, createJSDocBlockText, createLogger, createPlugin, createPluginCache, build as default, defaultColours, defineConfig, escape, extensions, getDependedPlugins, getIndexes, getLocation, getPathMode, getRelativePath, getUniqueName, hooks, importModule, isExtensionAllowed, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, jsStringEscape, pluginName as name, nameSorter, normalizeDirectory, pluginName, randomColour, randomPicoColour, read, readSync, renderTemplate, throttle, timeout, transformReservedWord, uniqueIdFactory, write };
791
+ export { AppMeta, Argument0, BuildOutput, CLIOptions, Cache, CacheItem, Executer, FileManager, FunctionParams, FunctionParamsAST, Generator, KubbConfig, KubbFile, KubbJSONPlugins, KubbObjectPlugin, KubbObjectPlugins, KubbPlugin, KubbPluginKind, KubbUserConfig, KubbUserPlugin, LogLevel, LogType, Logger, PackageManager, ParallelPluginError, ParseResult, PluginCache, PluginContext, PluginError, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PossiblePromise, Prettify, Queue, QueueJob, ResolveNameParams, ResolvePathParams, SafeParseResult, SchemaGenerator, Strategy, SummaryError, TransformResult, TreeNode, TreeNodeOptions, URLObject, URLPath, ValidationPluginError, Warning, build, clean, combineCodes, combineExports, combineFiles, combineImports, createFileSource, createJSDocBlockText, createLogger, createPlugin, createPluginCache, build as default, defaultColours, defineConfig, escape, extensions, getDependedPlugins, getIndexes, getLocation, getPathMode, getRelativePath, getUniqueName, hooks, importModule, isExtensionAllowed, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, jsStringEscape, pluginName as name, nameSorter, normalizeDirectory, pluginName, randomColour, randomPicoColour, read, readSync, renderTemplate, throttle, timeout, transformReservedWord, uniqueIdFactory, write };
package/dist/index.d.ts CHANGED
@@ -468,6 +468,21 @@ declare class ParallelPluginError extends Error {
468
468
  findError<T extends Error = Error>(searchError: T | undefined): T | undefined;
469
469
  }
470
470
 
471
+ type PackageJSON = {
472
+ dependencies?: Record<string, string>;
473
+ devDependencies?: Record<string, string>;
474
+ };
475
+ declare class PackageManager {
476
+ private cwd;
477
+ constructor(workspace?: string);
478
+ getPackageJSON(): Promise<PackageJSON | undefined>;
479
+ getPackageJSONSync(): PackageJSON | undefined;
480
+ getVersion(dependency: string): Promise<string | undefined>;
481
+ getVersionSync(dependency: string): string | undefined;
482
+ isValid(dependency: string, version: string): Promise<boolean>;
483
+ isValidSync(dependency: string, version: string): boolean;
484
+ }
485
+
471
486
  /**
472
487
  * Config used in `kubb.config.js`
473
488
  *
@@ -506,6 +521,11 @@ type KubbConfig = {
506
521
  * the defined root option.
507
522
  */
508
523
  path: string;
524
+ } | {
525
+ /**
526
+ * String or object containing the data that you would normally import.
527
+ */
528
+ data: string | unknown;
509
529
  };
510
530
  output: {
511
531
  /**
@@ -768,4 +788,4 @@ declare abstract class SchemaGenerator<TOptions extends object, TInput, TOutput>
768
788
  abstract build(schema: TInput, name: string, description?: string): TOutput;
769
789
  }
770
790
 
771
- export { AppMeta, Argument0, BuildOutput, CLIOptions, Cache, CacheItem, Executer, FileManager, FunctionParams, FunctionParamsAST, Generator, KubbConfig, KubbFile, KubbJSONPlugins, KubbObjectPlugin, KubbObjectPlugins, KubbPlugin, KubbPluginKind, KubbUserConfig, KubbUserPlugin, LogLevel, LogType, Logger, ParallelPluginError, ParseResult, PluginCache, PluginContext, PluginError, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PossiblePromise, Prettify, Queue, QueueJob, ResolveNameParams, ResolvePathParams, SafeParseResult, SchemaGenerator, Strategy, SummaryError, TransformResult, TreeNode, TreeNodeOptions, URLObject, URLPath, ValidationPluginError, Warning, build, clean, combineCodes, combineExports, combineFiles, combineImports, createFileSource, createJSDocBlockText, createLogger, createPlugin, createPluginCache, build as default, defaultColours, defineConfig, escape, extensions, getDependedPlugins, getIndexes, getLocation, getPathMode, getRelativePath, getUniqueName, hooks, importModule, isExtensionAllowed, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, jsStringEscape, pluginName as name, nameSorter, normalizeDirectory, pluginName, randomColour, randomPicoColour, read, readSync, renderTemplate, throttle, timeout, transformReservedWord, uniqueIdFactory, write };
791
+ export { AppMeta, Argument0, BuildOutput, CLIOptions, Cache, CacheItem, Executer, FileManager, FunctionParams, FunctionParamsAST, Generator, KubbConfig, KubbFile, KubbJSONPlugins, KubbObjectPlugin, KubbObjectPlugins, KubbPlugin, KubbPluginKind, KubbUserConfig, KubbUserPlugin, LogLevel, LogType, Logger, PackageManager, ParallelPluginError, ParseResult, PluginCache, PluginContext, PluginError, PluginFactoryOptions, PluginLifecycle, PluginLifecycleHooks, PluginManager, PossiblePromise, Prettify, Queue, QueueJob, ResolveNameParams, ResolvePathParams, SafeParseResult, SchemaGenerator, Strategy, SummaryError, TransformResult, TreeNode, TreeNodeOptions, URLObject, URLPath, ValidationPluginError, Warning, build, clean, combineCodes, combineExports, combineFiles, combineImports, createFileSource, createJSDocBlockText, createLogger, createPlugin, createPluginCache, build as default, defaultColours, defineConfig, escape, extensions, getDependedPlugins, getIndexes, getLocation, getPathMode, getRelativePath, getUniqueName, hooks, importModule, isExtensionAllowed, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, jsStringEscape, pluginName as name, nameSorter, normalizeDirectory, pluginName, randomColour, randomPicoColour, read, readSync, renderTemplate, throttle, timeout, transformReservedWord, uniqueIdFactory, write };
package/dist/index.js CHANGED
@@ -15,8 +15,18 @@ import { orderBy } from 'natural-orderby';
15
15
  import { createImportDeclaration, print, createExportDeclaration } from '@kubb/parser';
16
16
  import isEqual from 'lodash.isequal';
17
17
  import { EventEmitter as EventEmitter$1 } from 'events';
18
+ import { findUp, findUpSync } from 'find-up';
19
+ import { coerce, satisfies } from 'semver';
18
20
 
19
- createRequire(import.meta.url);
21
+ const require = createRequire(import.meta.url);
22
+
23
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
24
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
25
+ }) : x)(function(x) {
26
+ if (typeof require !== "undefined")
27
+ return require.apply(this, arguments);
28
+ throw Error('Dynamic require of "' + x + '" is not supported');
29
+ });
20
30
 
21
31
  // src/utils/isPromise.ts
22
32
  function isPromise(result) {
@@ -1561,16 +1571,18 @@ async function transformReducer(_previousCode, result, _plugin) {
1561
1571
  async function build(options) {
1562
1572
  const { config, logLevel, logger = createLogger() } = options;
1563
1573
  try {
1564
- if (!URLPath.isURL(config.input.path)) {
1574
+ if ("path" in config.input && !URLPath.isURL(config.input.path)) {
1565
1575
  await read(config.input.path);
1566
1576
  }
1567
1577
  } catch (e) {
1568
- throw new Error(
1569
- "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),
1570
- {
1571
- cause: e
1572
- }
1573
- );
1578
+ if ("path" in config.input) {
1579
+ throw new Error(
1580
+ "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),
1581
+ {
1582
+ cause: e
1583
+ }
1584
+ );
1585
+ }
1574
1586
  }
1575
1587
  if (config.output.clean) {
1576
1588
  await clean(config.output.path);
@@ -1639,6 +1651,67 @@ async function build(options) {
1639
1651
  function defineConfig(options) {
1640
1652
  return options;
1641
1653
  }
1654
+ var PackageManager = class {
1655
+ cwd;
1656
+ constructor(workspace = process.cwd()) {
1657
+ this.cwd = workspace;
1658
+ return this;
1659
+ }
1660
+ async getPackageJSON() {
1661
+ const pkgPath = await findUp(["package.json"], {
1662
+ cwd: this.cwd
1663
+ });
1664
+ if (!pkgPath) {
1665
+ return void 0;
1666
+ }
1667
+ return __require(pkgPath);
1668
+ }
1669
+ getPackageJSONSync() {
1670
+ const pkgPath = findUpSync(["package.json"], {
1671
+ cwd: this.cwd
1672
+ });
1673
+ if (!pkgPath) {
1674
+ return void 0;
1675
+ }
1676
+ return __require(pkgPath);
1677
+ }
1678
+ async getVersion(dependency) {
1679
+ const packageJSON = await this.getPackageJSON();
1680
+ if (!packageJSON) {
1681
+ return void 0;
1682
+ }
1683
+ return packageJSON["dependencies"]?.[dependency] || packageJSON["devDependencies"]?.[dependency];
1684
+ }
1685
+ getVersionSync(dependency) {
1686
+ const packageJSON = this.getPackageJSONSync();
1687
+ if (!packageJSON) {
1688
+ return void 0;
1689
+ }
1690
+ return packageJSON["dependencies"]?.[dependency] || packageJSON["devDependencies"]?.[dependency];
1691
+ }
1692
+ async isValid(dependency, version) {
1693
+ const packageVersion = await this.getVersion(dependency);
1694
+ if (!packageVersion) {
1695
+ return false;
1696
+ }
1697
+ const semVer = coerce(packageVersion);
1698
+ if (!semVer) {
1699
+ throw new Error(`${packageVersion} is not valid`);
1700
+ }
1701
+ return satisfies(semVer, version);
1702
+ }
1703
+ isValidSync(dependency, version) {
1704
+ const packageVersion = this.getVersionSync(dependency);
1705
+ if (!packageVersion) {
1706
+ return false;
1707
+ }
1708
+ const semVer = coerce(packageVersion);
1709
+ if (!semVer) {
1710
+ throw new Error(`${packageVersion} is not valid`);
1711
+ }
1712
+ return satisfies(semVer, version);
1713
+ }
1714
+ };
1642
1715
 
1643
1716
  // src/generators/Generator.ts
1644
1717
  var Generator = class {
@@ -1664,6 +1737,6 @@ var SchemaGenerator = class extends Generator {
1664
1737
  // src/index.ts
1665
1738
  var src_default = build;
1666
1739
 
1667
- export { FileManager, FunctionParams, Generator, LogLevel, ParallelPluginError, PluginError, PluginManager, Queue, SchemaGenerator, SummaryError, TreeNode, URLPath, ValidationPluginError, Warning, build, clean, combineCodes, combineExports, combineFiles, combineImports, createFileSource, createJSDocBlockText, createLogger, createPlugin, createPluginCache, src_default as default, defaultColours, defineConfig, escape, extensions, getDependedPlugins, getIndexes, getLocation, getPathMode, getRelativePath, getUniqueName, hooks, importModule, isExtensionAllowed, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, jsStringEscape, pluginName as name, nameSorter, normalizeDirectory, pluginName, randomColour, randomPicoColour, read, readSync, renderTemplate, throttle, timeout, transformReservedWord, uniqueIdFactory, write };
1740
+ export { FileManager, FunctionParams, Generator, LogLevel, PackageManager, ParallelPluginError, PluginError, PluginManager, Queue, SchemaGenerator, SummaryError, TreeNode, URLPath, ValidationPluginError, Warning, build, clean, combineCodes, combineExports, combineFiles, combineImports, createFileSource, createJSDocBlockText, createLogger, createPlugin, createPluginCache, src_default as default, defaultColours, defineConfig, escape, extensions, getDependedPlugins, getIndexes, getLocation, getPathMode, getRelativePath, getUniqueName, hooks, importModule, isExtensionAllowed, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, jsStringEscape, pluginName as name, nameSorter, normalizeDirectory, pluginName, randomColour, randomPicoColour, read, readSync, renderTemplate, throttle, timeout, transformReservedWord, uniqueIdFactory, write };
1668
1741
  //# sourceMappingURL=out.js.map
1669
1742
  //# sourceMappingURL=index.js.map