@kubb/core 5.0.0-alpha.7 → 5.0.0-alpha.9

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/hooks.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","names":[],"sources":["../src/hooks/useKubb.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts","../src/hooks/usePluginDriver.ts"],"sourcesContent":["import path from 'node:path'\nimport type { RootNode } from '@kubb/ast/types'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\nimport type { GetFileOptions, PluginDriver } from '../PluginDriver.ts'\nimport type { Config, Plugin, PluginFactoryOptions, ResolveNameParams, ResolvePathParams } from '../types.ts'\n\ntype ResolvePathOptions = {\n pluginName?: string\n group?: {\n tag?: string\n path?: string\n }\n type?: ResolveNameParams['type']\n}\n\ntype UseKubbReturn<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n config: Config\n /**\n * Returns the plugin whose `name` matches `pluginName`, defaulting to the current plugin.\n */\n getPluginByName: (pluginName?: string) => Plugin | undefined\n /**\n * Resolves a file reference, defaulting `pluginName` to the current plugin.\n */\n getFile: (params: Omit<GetFileOptions<ResolvePathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.File<{ pluginName: string }>\n /**\n * Resolves a name, defaulting `pluginName` to the current plugin.\n */\n resolveName: (params: Omit<ResolveNameParams, 'pluginName'> & { pluginName?: string }) => string\n /**\n * Resolves a path, defaulting `pluginName` to the current plugin.\n */\n resolvePath: <TPathOptions = object>(params: Omit<ResolvePathParams<TPathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.Path\n /**\n * Resolves the banner for the given node using the plugin's `output.banner` option.\n * Returns a string when `output.banner` is a string or a function, `undefined` otherwise.\n */\n resolveBanner: (node: RootNode) => string | undefined\n /**\n * Resolves the footer for the given node using the plugin's `output.footer` option.\n * Returns a string when `output.footer` is a string or a function, `undefined` otherwise.\n */\n resolveFooter: (node: RootNode) => string | undefined\n}\n\n/**\n * Generates the default \"Generated by Kubb\" banner from node metadata.\n */\nfunction buildDefaultBanner({ title, description, version, config }: { title?: string; description?: string; version?: string; config: Config }): string {\n try {\n let source = ''\n if (Array.isArray(config.input)) {\n const first = config.input[0]\n if (first && 'path' in first) {\n source = path.basename(first.path)\n }\n } else if ('path' in config.input) {\n source = path.basename(config.input.path)\n } else if ('data' in config.input) {\n source = 'text content'\n }\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\nexport function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): UseKubbReturn<TOptions> {\n const { meta } = useFabric<{\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n driver: PluginDriver\n }>()\n\n const config = meta.driver.config\n const defaultPluginName = meta.plugin.name\n\n const output = (\n meta.plugin.options as { output?: { banner?: string | ((node: RootNode) => string); footer?: string | ((node: RootNode) => string) } } | undefined\n )?.output\n\n return {\n plugin: meta.plugin as Plugin<TOptions>,\n mode: meta.mode,\n config,\n getPluginByName: (pluginName = defaultPluginName) => meta.driver.getPluginByName.call(meta.driver, pluginName),\n getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.getFile.call(meta.driver, { pluginName, ...rest }),\n resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolveName.call(meta.driver, { pluginName, ...rest }),\n resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolvePath.call(meta.driver, { pluginName, ...rest }),\n resolveBanner: (node: RootNode) => {\n if (typeof output?.banner === 'function') {\n return output.banner(node)\n }\n if (typeof output?.banner === 'string') {\n return output.banner\n }\n return buildDefaultBanner({ config })\n },\n resolveFooter: (node: RootNode) => {\n if (typeof output?.footer === 'function') {\n return output.footer(node)\n }\n if (typeof output?.footer === 'string') {\n return output.footer\n }\n return undefined\n },\n }\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function useMode(): KubbFile.Mode {\n const { meta } = useFabric<{ mode: KubbFile.Mode }>()\n\n return meta.mode\n}\n","import { useFabric } from '@kubb/react-fabric'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\n/**\n * @deprecated use useKubb instead\n */\nexport function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {\n const { meta } = useFabric<{ plugin: Plugin<TOptions> }>()\n\n return meta.plugin\n}\n","import { useFabric } from '@kubb/react-fabric'\nimport type { PluginDriver } from '../PluginDriver.ts'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function usePluginDriver(): PluginDriver {\n const { meta } = useFabric<{ driver: PluginDriver }>()\n\n return meta.driver\n}\n"],"mappings":";;;;;;;AAmDA,SAAS,mBAAmB,EAAE,OAAO,aAAa,SAAS,UAA8F;AACvJ,KAAI;EACF,IAAI,SAAS;AACb,MAAI,MAAM,QAAQ,OAAO,MAAM,EAAE;GAC/B,MAAM,QAAQ,OAAO,MAAM;AAC3B,OAAI,SAAS,UAAU,MACrB,UAAS,KAAK,SAAS,MAAM,KAAK;aAE3B,UAAU,OAAO,MAC1B,UAAS,KAAK,SAAS,OAAO,MAAM,KAAK;WAChC,UAAU,OAAO,MAC1B,UAAS;EAGX,IAAI,SAAS;AAEb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,QAAO,OAAO;;EAInB;;;;;;;AClIH,SAAgB,UAAyB;CACvC,MAAM,EAAE,SAAS,WAAoC;AAErD,QAAO,KAAK;;;;;;;ACHd,SAAgB,YAA4F;CAC1G,MAAM,EAAE,SAAS,WAAyC;AAE1D,QAAO,KAAK;;;;;;;ACHd,SAAgB,kBAAgC;CAC9C,MAAM,EAAE,SAAS,WAAqC;AAEtD,QAAO,KAAK"}
1
+ {"version":3,"file":"hooks.js","names":[],"sources":["../src/hooks/useKubb.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts","../src/hooks/usePluginDriver.ts"],"sourcesContent":["import path from 'node:path'\nimport type { RootNode } from '@kubb/ast/types'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\nimport type { GetFileOptions, PluginDriver } from '../PluginDriver.ts'\nimport type { Config, Plugin, PluginFactoryOptions, ResolveNameParams, ResolvePathParams } from '../types.ts'\n\ntype ResolvePathOptions = {\n pluginName?: string\n group?: {\n tag?: string\n path?: string\n }\n type?: ResolveNameParams['type']\n}\n\ntype UseKubbReturn<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n config: Config\n /**\n * Returns the plugin whose `name` matches `pluginName`, defaulting to the current plugin.\n */\n getPluginByName: (pluginName?: string) => Plugin | undefined\n /**\n * Resolves a file reference, defaulting `pluginName` to the current plugin.\n */\n getFile: (params: Omit<GetFileOptions<ResolvePathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.File<{ pluginName: string }>\n /**\n * Resolves a name, defaulting `pluginName` to the current plugin.\n */\n resolveName: (params: Omit<ResolveNameParams, 'pluginName'> & { pluginName?: string }) => string\n /**\n * Resolves a path, defaulting `pluginName` to the current plugin.\n */\n resolvePath: <TPathOptions = object>(params: Omit<ResolvePathParams<TPathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.Path\n /**\n * Resolves the banner using the plugin's `output.banner` option.\n * Falls back to the default \"Generated by Kubb\" banner when `output.banner` is unset.\n * When `output.banner` is a function and no node is provided, returns the default banner.\n */\n resolveBanner: (node?: RootNode) => string | undefined\n /**\n * Resolves the footer using the plugin's `output.footer` option.\n * Returns `undefined` when no footer is configured.\n * When `output.footer` is a function and no node is provided, returns `undefined`.\n */\n resolveFooter: (node?: RootNode) => string | undefined\n}\n\n/**\n * Generates the default \"Generated by Kubb\" banner from node metadata.\n */\nfunction buildDefaultBanner({ title, description, version, config }: { title?: string; description?: string; version?: string; config: Config }): string {\n try {\n let source = ''\n if (Array.isArray(config.input)) {\n const first = config.input[0]\n if (first && 'path' in first) {\n source = path.basename(first.path)\n }\n } else if ('path' in config.input) {\n source = path.basename(config.input.path)\n } else if ('data' in config.input) {\n source = 'text content'\n }\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\nexport function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): UseKubbReturn<TOptions> {\n const { meta } = useFabric<{\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n driver: PluginDriver\n }>()\n\n const config = meta.driver.config\n const defaultPluginName = meta.plugin.name\n\n const output = (\n meta.plugin.options as { output?: { banner?: string | ((node: RootNode) => string); footer?: string | ((node: RootNode) => string) } } | undefined\n )?.output\n\n return {\n plugin: meta.plugin as Plugin<TOptions>,\n mode: meta.mode,\n config,\n getPluginByName: (pluginName = defaultPluginName) => meta.driver.getPluginByName.call(meta.driver, pluginName),\n getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.getFile.call(meta.driver, { pluginName, ...rest }),\n resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolveName.call(meta.driver, { pluginName, ...rest }),\n resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.driver.resolvePath.call(meta.driver, { pluginName, ...rest }),\n resolveBanner: (node?: RootNode) => {\n if (typeof output?.banner === 'function') {\n return node ? output.banner(node) : buildDefaultBanner({ config })\n }\n if (typeof output?.banner === 'string') {\n return output.banner\n }\n if (config.output.defaultBanner === false) {\n return undefined\n }\n return buildDefaultBanner({ config })\n },\n resolveFooter: (node?: RootNode) => {\n if (typeof output?.footer === 'function') {\n return node ? output.footer(node) : undefined\n }\n if (typeof output?.footer === 'string') {\n return output.footer\n }\n return undefined\n },\n }\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function useMode(): KubbFile.Mode {\n const { meta } = useFabric<{ mode: KubbFile.Mode }>()\n\n return meta.mode\n}\n","import { useFabric } from '@kubb/react-fabric'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\n/**\n * @deprecated use useKubb instead\n */\nexport function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {\n const { meta } = useFabric<{ plugin: Plugin<TOptions> }>()\n\n return meta.plugin\n}\n","import { useFabric } from '@kubb/react-fabric'\nimport type { PluginDriver } from '../PluginDriver.ts'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function usePluginDriver(): PluginDriver {\n const { meta } = useFabric<{ driver: PluginDriver }>()\n\n return meta.driver\n}\n"],"mappings":";;;;;;;AAqDA,SAAS,mBAAmB,EAAE,OAAO,aAAa,SAAS,UAA8F;AACvJ,KAAI;EACF,IAAI,SAAS;AACb,MAAI,MAAM,QAAQ,OAAO,MAAM,EAA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,GAAG,mBAAmB,EAAE,QAAQ,CAAC;AAEpE,OAAI,OAAO,QAAQ,WAAW,SAC5B,QAAO,OAAO;AAEhB,OAAI,OAAO,OAAO,kBAAkB,MAClC;AAEF,UAAO,mBAAmB,EAAE,QAAQ,CAAC;;EAEvC,gBAAgB,SAAoB;AAClC,OAAI,OAAO,QAAQ,WAAW,WAC5B,QAAO,OAAO,OAAO,OAAO,KAAK,GAAG,KAAA;AAEtC,OAAI,OAAO,QAAQ,WAAW,SAC5B,QAAO,OAAO;;EAInB;;;;;;;ACvIH,SAAgB,UAAyB;CACvC,MAAM,EAAE,SAAS,WAAoC;AAErD,QAAO,KAAK;;;;;;;ACHd,SAAgB,YAA4F;CAC1G,MAAM,EAAE,SAAS,WAAyC;AAE1D,QAAO,KAAK;;;;;;;ACHd,SAAgB,kBAAgC;CAC9C,MAAM,EAAE,SAAS,WAAqC;AAEtD,QAAO,KAAK"}
package/dist/index.cjs CHANGED
@@ -3,13 +3,13 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("./chunk-ByKO4r7w.cjs");
6
+ let _kubb_ast = require("@kubb/ast");
7
+ let node_path = require("node:path");
8
+ node_path = require_chunk.__toESM(node_path);
6
9
  let node_events = require("node:events");
7
10
  let node_util = require("node:util");
8
11
  let node_fs = require("node:fs");
9
12
  let node_fs_promises = require("node:fs/promises");
10
- let node_path = require("node:path");
11
- node_path = require_chunk.__toESM(node_path);
12
- let _kubb_ast = require("@kubb/ast");
13
13
  let _kubb_react_fabric = require("@kubb/react-fabric");
14
14
  let _kubb_react_fabric_parsers = require("@kubb/react-fabric/parsers");
15
15
  let _kubb_react_fabric_plugins = require("@kubb/react-fabric/plugins");
@@ -17,15 +17,10 @@ let node_perf_hooks = require("node:perf_hooks");
17
17
  let fflate = require("fflate");
18
18
  let tinyexec = require("tinyexec");
19
19
  let node_process = require("node:process");
20
- let node_module = require("node:module");
21
- node_module = require_chunk.__toESM(node_module);
22
- let node_os = require("node:os");
23
- node_os = require_chunk.__toESM(node_os);
24
- let node_url = require("node:url");
20
+ let remeda = require("remeda");
25
21
  let empathic_package = require("empathic/package");
26
22
  empathic_package = require_chunk.__toESM(empathic_package);
27
23
  let semver = require("semver");
28
- let remeda = require("remeda");
29
24
  //#region ../../internals/utils/dist/index.js
30
25
  /** Thrown when a plugin's configuration or input fails validation. */
31
26
  var ValidationPluginError = class extends Error {};
@@ -142,6 +137,21 @@ function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
142
137
  } : {}));
143
138
  return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
144
139
  }
140
+ /**
141
+ * Converts `text` to PascalCase.
142
+ * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.
143
+ *
144
+ * @example
145
+ * pascalCase('hello-world') // 'HelloWorld'
146
+ * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'
147
+ */
148
+ function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
149
+ if (isFile) return applyToFileParts(text, (part, isLast) => isLast ? pascalCase(part, {
150
+ prefix,
151
+ suffix
152
+ }) : camelCase(part));
153
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
154
+ }
145
155
  /** Returns a `CLIAdapter` with type inference. Pass a different adapter to `createCLI` to swap the CLI engine. */
146
156
  function defineCLIAdapter(adapter) {
147
157
  return adapter;
@@ -391,14 +401,6 @@ async function exists(path) {
391
401
  if (typeof Bun !== "undefined") return Bun.file(path).exists();
392
402
  return (0, node_fs_promises.access)(path).then(() => true, () => false);
393
403
  }
394
- /**
395
- * Reads the file at `path` as a UTF-8 string.
396
- * Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.
397
- */
398
- async function read(path) {
399
- if (typeof Bun !== "undefined") return Bun.file(path).text();
400
- return (0, node_fs_promises.readFile)(path, { encoding: "utf8" });
401
- }
402
404
  /** Synchronous counterpart of `read`. */
403
405
  function readSync(path) {
404
406
  return (0, node_fs.readFileSync)(path, { encoding: "utf8" });
@@ -461,7 +463,7 @@ function isPromiseRejectedResult(result) {
461
463
  * JavaScript and Java reserved words.
462
464
  * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
463
465
  */
464
- const reservedWords = [
466
+ const reservedWords = new Set([
465
467
  "abstract",
466
468
  "arguments",
467
469
  "boolean",
@@ -543,14 +545,14 @@ const reservedWords = [
543
545
  "toString",
544
546
  "undefined",
545
547
  "valueOf"
546
- ];
548
+ ]);
547
549
  /**
548
550
  * Prefixes a word with `_` when it is a reserved JavaScript/Java identifier
549
551
  * or starts with a digit.
550
552
  */
551
553
  function transformReservedWord(word) {
552
554
  const firstChar = word.charCodeAt(0);
553
- if (word && (reservedWords.includes(word) || firstChar >= 48 && firstChar <= 57)) return `_${word}`;
555
+ if (word && (reservedWords.has(word) || firstChar >= 48 && firstChar <= 57)) return `_${word}`;
554
556
  return word;
555
557
  }
556
558
  /**
@@ -682,7 +684,6 @@ const DEFAULT_STUDIO_URL = "https://studio.kubb.dev";
682
684
  const BARREL_FILENAME = "index.ts";
683
685
  const DEFAULT_BANNER = "simple";
684
686
  const DEFAULT_EXTENSION = { ".ts": ".ts" };
685
- const PATH_SEPARATORS = ["/", "\\"];
686
687
  const logLevel = {
687
688
  silent: Number.NEGATIVE_INFINITY,
688
689
  error: 0,
@@ -1345,19 +1346,12 @@ var PluginDriver = class {
1345
1346
  }
1346
1347
  };
1347
1348
  //#endregion
1348
- //#region src/defineStorage.ts
1349
+ //#region src/createStorage.ts
1349
1350
  /**
1350
- * Wraps a storage builder so the `options` argument is optional, following the
1351
- * same factory pattern as `definePlugin`, `defineLogger`, and `defineAdapter`.
1352
- *
1353
- * The builder receives the resolved options object and must return a
1354
- * `DefineStorage`-compatible object that includes a `name` string.
1351
+ * Creates a storage factory. Call the returned function with optional options to get the storage instance.
1355
1352
  *
1356
1353
  * @example
1357
- * ```ts
1358
- * import { defineStorage } from '@kubb/core'
1359
- *
1360
- * export const memoryStorage = defineStorage((_options) => {
1354
+ * export const memoryStorage = createStorage(() => {
1361
1355
  * const store = new Map<string, string>()
1362
1356
  * return {
1363
1357
  * name: 'memory',
@@ -1365,13 +1359,15 @@ var PluginDriver = class {
1365
1359
  * async getItem(key) { return store.get(key) ?? null },
1366
1360
  * async setItem(key, value) { store.set(key, value) },
1367
1361
  * async removeItem(key) { store.delete(key) },
1368
- * async getKeys() { return [...store.keys()] },
1369
- * async clear() { store.clear() },
1362
+ * async getKeys(base) {
1363
+ * const keys = [...store.keys()]
1364
+ * return base ? keys.filter((k) => k.startsWith(base)) : keys
1365
+ * },
1366
+ * async clear(base) { if (!base) store.clear() },
1370
1367
  * }
1371
1368
  * })
1372
- * ```
1373
1369
  */
1374
- function defineStorage(build) {
1370
+ function createStorage(build) {
1375
1371
  return (options) => build(options ?? {});
1376
1372
  }
1377
1373
  //#endregion
@@ -1399,7 +1395,7 @@ function defineStorage(build) {
1399
1395
  * })
1400
1396
  * ```
1401
1397
  */
1402
- const fsStorage = defineStorage(() => ({
1398
+ const fsStorage = createStorage(() => ({
1403
1399
  name: "fs",
1404
1400
  async hasItem(key) {
1405
1401
  try {
@@ -1447,7 +1443,7 @@ const fsStorage = defineStorage(() => ({
1447
1443
  }));
1448
1444
  //#endregion
1449
1445
  //#region package.json
1450
- var version = "5.0.0-alpha.7";
1446
+ var version = "5.0.0-alpha.9";
1451
1447
  //#endregion
1452
1448
  //#region src/utils/diagnostics.ts
1453
1449
  /**
@@ -1760,23 +1756,44 @@ function inputToAdapterSource(config) {
1760
1756
  };
1761
1757
  }
1762
1758
  //#endregion
1763
- //#region src/defineAdapter.ts
1759
+ //#region src/createAdapter.ts
1764
1760
  /**
1765
- * Wraps an adapter builder to make the options parameter optional.
1761
+ * Creates an adapter factory. Call the returned function with optional options to get the adapter instance.
1766
1762
  *
1767
1763
  * @example
1768
- * ```ts
1769
- * export const adapterOas = defineAdapter<OasAdapter>((options) => {
1770
- * const { validate = true, dateType = 'string' } = options
1764
+ * export const myAdapter = createAdapter<MyAdapter>((options) => {
1771
1765
  * return {
1772
- * name: adapterOasName,
1773
- * options: { validate, dateType, ... },
1774
- * parse(source) { ... },
1766
+ * name: 'my-adapter',
1767
+ * options,
1768
+ * async parse(source) { ... },
1775
1769
  * }
1776
1770
  * })
1777
- * ```
1771
+ *
1772
+ * // instantiate
1773
+ * const adapter = myAdapter({ validate: true })
1774
+ */
1775
+ function createAdapter(build) {
1776
+ return (options) => build(options ?? {});
1777
+ }
1778
+ //#endregion
1779
+ //#region src/createPlugin.ts
1780
+ /**
1781
+ * Creates a plugin factory. Call the returned function with optional options to get the plugin instance.
1782
+ *
1783
+ * @example
1784
+ * export const myPlugin = createPlugin<MyPlugin>((options) => {
1785
+ * return {
1786
+ * name: 'my-plugin',
1787
+ * options,
1788
+ * resolvePath(baseName) { ... },
1789
+ * resolveName(name, type) { ... },
1790
+ * }
1791
+ * })
1792
+ *
1793
+ * // instantiate
1794
+ * const plugin = myPlugin({ output: { path: 'src/gen' } })
1778
1795
  */
1779
- function defineAdapter(build) {
1796
+ function createPlugin(build) {
1780
1797
  return (options) => build(options ?? {});
1781
1798
  }
1782
1799
  //#endregion
@@ -1811,100 +1828,106 @@ function defineGenerator(generator) {
1811
1828
  }
1812
1829
  //#endregion
1813
1830
  //#region src/defineLogger.ts
1831
+ /**
1832
+ * Wraps a logger definition into a typed {@link Logger}.
1833
+ *
1834
+ * @example
1835
+ * export const myLogger = defineLogger({
1836
+ * name: 'my-logger',
1837
+ * install(context, options) {
1838
+ * context.on('info', (message) => console.log('ℹ', message))
1839
+ * context.on('error', (error) => console.error('✗', error.message))
1840
+ * },
1841
+ * })
1842
+ */
1814
1843
  function defineLogger(logger) {
1815
- return { ...logger };
1844
+ return logger;
1816
1845
  }
1817
1846
  //#endregion
1818
- //#region src/definePlugin.ts
1847
+ //#region src/defineResolver.ts
1819
1848
  /**
1820
- * Wraps a plugin builder to make the options parameter optional.
1849
+ * Checks if an operation matches a pattern for a given filter type (`tag`, `operationId`, `path`, `method`).
1821
1850
  */
1822
- function definePlugin(build) {
1823
- return (options) => build(options ?? {});
1851
+ function matchesOperationPattern(node, type, pattern) {
1852
+ switch (type) {
1853
+ case "tag": return node.tags.some((tag) => !!tag.match(pattern));
1854
+ case "operationId": return !!node.operationId.match(pattern);
1855
+ case "path": return !!node.path.match(pattern);
1856
+ case "method": return !!node.method.toLowerCase().match(pattern);
1857
+ default: return false;
1858
+ }
1824
1859
  }
1825
- //#endregion
1826
- //#region src/PackageManager.ts
1827
- var PackageManager = class PackageManager {
1828
- static #cache = {};
1829
- #cwd;
1830
- constructor(workspace) {
1831
- if (workspace) this.#cwd = workspace;
1832
- }
1833
- set workspace(workspace) {
1834
- this.#cwd = workspace;
1835
- }
1836
- get workspace() {
1837
- return this.#cwd;
1838
- }
1839
- normalizeDirectory(directory) {
1840
- const lastChar = directory[directory.length - 1];
1841
- if (lastChar && !PATH_SEPARATORS.includes(lastChar)) return `${directory}/`;
1842
- return directory;
1843
- }
1844
- getLocation(path) {
1845
- let location = path;
1846
- if (this.#cwd) location = node_module.default.createRequire(this.normalizeDirectory(this.#cwd)).resolve(path);
1847
- return location;
1848
- }
1849
- async import(path) {
1850
- let location = this.getLocation(path);
1851
- if (node_os.default.platform() === "win32") location = (0, node_url.pathToFileURL)(location).href;
1852
- const module = await import(location);
1853
- return module?.default ?? module;
1854
- }
1855
- async getPackageJSON() {
1856
- const pkgPath = empathic_package.up({ cwd: this.#cwd });
1857
- if (!pkgPath) return;
1858
- const json = await read(pkgPath);
1859
- return JSON.parse(json);
1860
- }
1861
- getPackageJSONSync() {
1862
- const pkgPath = empathic_package.up({ cwd: this.#cwd });
1863
- if (!pkgPath) return;
1864
- const json = readSync(pkgPath);
1865
- return JSON.parse(json);
1866
- }
1867
- static setVersion(dependency, version) {
1868
- PackageManager.#cache[dependency] = version;
1869
- }
1870
- #match(packageJSON, dependency) {
1871
- const dependencies = {
1872
- ...packageJSON.dependencies || {},
1873
- ...packageJSON.devDependencies || {}
1860
+ /**
1861
+ * Checks if a schema matches a pattern for a given filter type (`schemaName`).
1862
+ * Returns `null` when the filter type doesn't apply to schemas.
1863
+ */
1864
+ function matchesSchemaPattern(node, type, pattern) {
1865
+ switch (type) {
1866
+ case "schemaName": return node.name ? !!node.name.match(pattern) : false;
1867
+ default: return null;
1868
+ }
1869
+ }
1870
+ /**
1871
+ * Default name resolver — `camelCase` for most types, `PascalCase` for `type`.
1872
+ */
1873
+ function defaultResolver(name, type) {
1874
+ let resolvedName = camelCase(name);
1875
+ if (type === "file" || type === "function") resolvedName = camelCase(name, { isFile: type === "file" });
1876
+ if (type === "type") resolvedName = pascalCase(name);
1877
+ return resolvedName;
1878
+ }
1879
+ /**
1880
+ * Default option resolver — applies include/exclude filters and merges any matching override options.
1881
+ * Returns `null` when the node is filtered out.
1882
+ */
1883
+ function defaultResolveOptions(node, { options, exclude = [], include, override = [] }) {
1884
+ if ((0, _kubb_ast.isOperationNode)(node)) {
1885
+ if (exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
1886
+ if (include && !include.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
1887
+ const overrideOptions = override.find(({ type, pattern }) => matchesOperationPattern(node, type, pattern))?.options;
1888
+ return {
1889
+ ...options,
1890
+ ...overrideOptions
1874
1891
  };
1875
- if (typeof dependency === "string" && dependencies[dependency]) return dependencies[dependency];
1876
- const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
1877
- return matchedDependency ? dependencies[matchedDependency] : void 0;
1878
- }
1879
- async getVersion(dependency) {
1880
- if (typeof dependency === "string" && PackageManager.#cache[dependency]) return PackageManager.#cache[dependency];
1881
- const packageJSON = await this.getPackageJSON();
1882
- if (!packageJSON) return;
1883
- return this.#match(packageJSON, dependency);
1884
- }
1885
- getVersionSync(dependency) {
1886
- if (typeof dependency === "string" && PackageManager.#cache[dependency]) return PackageManager.#cache[dependency];
1887
- const packageJSON = this.getPackageJSONSync();
1888
- if (!packageJSON) return;
1889
- return this.#match(packageJSON, dependency);
1890
- }
1891
- async isValid(dependency, version) {
1892
- const packageVersion = await this.getVersion(dependency);
1893
- if (!packageVersion) return false;
1894
- if (packageVersion === version) return true;
1895
- const semVer = (0, semver.coerce)(packageVersion);
1896
- if (!semVer) return false;
1897
- return (0, semver.satisfies)(semVer, version);
1898
- }
1899
- isValidSync(dependency, version) {
1900
- const packageVersion = this.getVersionSync(dependency);
1901
- if (!packageVersion) return false;
1902
- if (packageVersion === version) return true;
1903
- const semVer = (0, semver.coerce)(packageVersion);
1904
- if (!semVer) return false;
1905
- return (0, semver.satisfies)(semVer, version);
1906
1892
  }
1907
- };
1893
+ if ((0, _kubb_ast.isSchemaNode)(node)) {
1894
+ if (exclude.some(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)) return null;
1895
+ if (include) {
1896
+ const applicable = include.map(({ type, pattern }) => matchesSchemaPattern(node, type, pattern)).filter((r) => r !== null);
1897
+ if (applicable.length > 0 && !applicable.includes(true)) return null;
1898
+ }
1899
+ const overrideOptions = override.find(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)?.options;
1900
+ return {
1901
+ ...options,
1902
+ ...overrideOptions
1903
+ };
1904
+ }
1905
+ return options;
1906
+ }
1907
+ /**
1908
+ * Defines a resolver for a plugin, with built-in defaults for name casing and include/exclude/override filtering.
1909
+ * Override `default` or `resolveOptions` in the builder to customize the behavior.
1910
+ *
1911
+ * @example
1912
+ * export const resolver = defineResolver<PluginTs>(() => ({
1913
+ * resolveName(name) {
1914
+ * return this.default(name, 'function')
1915
+ * },
1916
+ * resolveTypedName(name) {
1917
+ * return this.default(name, 'type')
1918
+ * },
1919
+ * resolveParamName(node, param) {
1920
+ * return this.resolveName(`${node.operationId} ${param.in} ${param.name}`)
1921
+ * },
1922
+ * }))
1923
+ */
1924
+ function defineResolver(build) {
1925
+ return {
1926
+ default: defaultResolver,
1927
+ resolveOptions: defaultResolveOptions,
1928
+ ...build()
1929
+ };
1930
+ }
1908
1931
  //#endregion
1909
1932
  //#region src/storages/memoryStorage.ts
1910
1933
  /**
@@ -1924,7 +1947,7 @@ var PackageManager = class PackageManager {
1924
1947
  * })
1925
1948
  * ```
1926
1949
  */
1927
- const memoryStorage = defineStorage(() => {
1950
+ const memoryStorage = createStorage(() => {
1928
1951
  const store = /* @__PURE__ */ new Map();
1929
1952
  return {
1930
1953
  name: "memory",
@@ -2070,11 +2093,12 @@ async function isFormatterAvailable(formatter) {
2070
2093
  * ```
2071
2094
  */
2072
2095
  async function detectFormatter() {
2073
- for (const formatter of [
2096
+ const formatterNames = new Set([
2074
2097
  "biome",
2075
2098
  "oxfmt",
2076
2099
  "prettier"
2077
- ]) if (await isFormatterAvailable(formatter)) return formatter;
2100
+ ]);
2101
+ for (const formatter of formatterNames) if (await isFormatterAvailable(formatter)) return formatter;
2078
2102
  }
2079
2103
  //#endregion
2080
2104
  //#region src/utils/TreeNode.ts
@@ -2266,35 +2290,13 @@ async function getBarrelFiles(files, { type, meta = {}, root, output }) {
2266
2290
  });
2267
2291
  }
2268
2292
  //#endregion
2269
- //#region src/utils/getPlugins.ts
2270
- function isJSONPlugins(plugins) {
2271
- return Array.isArray(plugins) && plugins.some((plugin) => Array.isArray(plugin) && typeof plugin[0] === "string");
2272
- }
2273
- function isObjectPlugins(plugins) {
2274
- return plugins instanceof Object && !Array.isArray(plugins);
2275
- }
2276
- function getPlugins(plugins) {
2277
- if (isObjectPlugins(plugins)) throw new Error("Object plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json");
2278
- if (isJSONPlugins(plugins)) throw new Error("JSON plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json");
2279
- return Promise.resolve(plugins);
2280
- }
2281
- //#endregion
2282
2293
  //#region src/utils/getConfigs.ts
2283
2294
  /**
2284
2295
  * Converting UserConfig to Config Array without a change in the object beside the JSON convert.
2285
2296
  */
2286
2297
  async function getConfigs(config, args) {
2287
- let userConfigs = await (typeof config === "function" ? Promise.resolve(config(args)) : Promise.resolve(config));
2288
- if (!Array.isArray(userConfigs)) userConfigs = [userConfigs];
2289
- const results = [];
2290
- for (const item of userConfigs) {
2291
- const plugins = item.plugins ? await getPlugins(item.plugins) : void 0;
2292
- results.push({
2293
- ...item,
2294
- plugins
2295
- });
2296
- }
2297
- return results;
2298
+ const resolved = await (typeof config === "function" ? config(args) : config);
2299
+ return (Array.isArray(resolved) ? resolved : [resolved]).map((item) => ({ ...item }));
2298
2300
  }
2299
2301
  //#endregion
2300
2302
  //#region src/utils/linters.ts
@@ -2307,87 +2309,60 @@ async function isLinterAvailable(linter) {
2307
2309
  }
2308
2310
  }
2309
2311
  async function detectLinter() {
2310
- for (const linter of [
2312
+ const linterNames = new Set([
2311
2313
  "biome",
2312
2314
  "oxlint",
2313
2315
  "eslint"
2314
- ]) if (await isLinterAvailable(linter)) return linter;
2316
+ ]);
2317
+ for (const linter of linterNames) if (await isLinterAvailable(linter)) return linter;
2315
2318
  }
2316
2319
  //#endregion
2317
- //#region src/utils/resolveOptions.ts
2318
- function matchesOperationPattern(node, type, pattern) {
2319
- switch (type) {
2320
- case "tag": return node.tags.some((tag) => !!tag.match(pattern));
2321
- case "operationId": return !!node.operationId.match(pattern);
2322
- case "path": return !!node.path.match(pattern);
2323
- case "method": return !!node.method.toLowerCase().match(pattern);
2324
- default: return false;
2325
- }
2326
- }
2327
- function matchesSchemaPattern(node, type, pattern) {
2328
- switch (type) {
2329
- case "schemaName": return node.name ? !!node.name.match(pattern) : false;
2330
- default: return null;
2331
- }
2332
- }
2333
- /**
2334
- * Resolves the effective plugin options for a given AST node by applying
2335
- * `exclude`, `include`, and `override` rules from the plugin configuration.
2336
- *
2337
- * Returns `null` when the node is excluded or not matched by `include`.
2338
- * Returns the merged options (base options merged with any matching `override`) otherwise.
2339
- *
2340
- * Supported filter types for `OperationNode`: `tag`, `operationId`, `path`, `method`.
2341
- * Supported filter types for `SchemaNode`: `schemaName`.
2342
- *
2343
- * @example
2344
- * const resolved = resolveOptions(operationNode, { options, exclude, include, override })
2345
- * if (!resolved) return // excluded
2346
- */
2347
- function resolveOptions(node, { options, exclude = [], include, override = [] }) {
2348
- if ((0, _kubb_ast.isOperationNode)(node)) {
2349
- if (exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
2350
- if (include && !include.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
2351
- const overrideOptions = override.find(({ type, pattern }) => matchesOperationPattern(node, type, pattern))?.options;
2352
- return {
2353
- ...options,
2354
- ...overrideOptions
2355
- };
2356
- }
2357
- if ((0, _kubb_ast.isSchemaNode)(node)) {
2358
- if (exclude.some(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)) return null;
2359
- if (include) {
2360
- const applicable = include.map(({ type, pattern }) => matchesSchemaPattern(node, type, pattern)).filter((r) => r !== null);
2361
- if (applicable.length > 0 && !applicable.includes(true)) return null;
2362
- }
2363
- const overrideOptions = override.find(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)?.options;
2364
- return {
2365
- ...options,
2366
- ...overrideOptions
2367
- };
2368
- }
2369
- return options;
2320
+ //#region src/utils/packageJSON.ts
2321
+ function getPackageJSONSync(cwd) {
2322
+ const pkgPath = empathic_package.up({ cwd });
2323
+ if (!pkgPath) return;
2324
+ return JSON.parse(readSync(pkgPath));
2325
+ }
2326
+ function match(packageJSON, dependency) {
2327
+ const dependencies = {
2328
+ ...packageJSON.dependencies || {},
2329
+ ...packageJSON.devDependencies || {}
2330
+ };
2331
+ if (typeof dependency === "string" && dependencies[dependency]) return dependencies[dependency];
2332
+ const matched = Object.keys(dependencies).find((dep) => dep.match(dependency));
2333
+ return matched ? dependencies[matched] : void 0;
2334
+ }
2335
+ function getVersionSync(dependency, cwd) {
2336
+ const packageJSON = getPackageJSONSync(cwd);
2337
+ return packageJSON ? match(packageJSON, dependency) : void 0;
2338
+ }
2339
+ function satisfiesDependency(dependency, version, cwd) {
2340
+ const packageVersion = getVersionSync(dependency, cwd);
2341
+ if (!packageVersion) return false;
2342
+ if (packageVersion === version) return true;
2343
+ const semVer = (0, semver.coerce)(packageVersion);
2344
+ if (!semVer) return false;
2345
+ return (0, semver.satisfies)(semVer, version);
2370
2346
  }
2371
2347
  //#endregion
2372
- exports.AsyncEventEmitter = AsyncEventEmitter;
2373
2348
  exports.FunctionParams = FunctionParams;
2374
- exports.PackageManager = PackageManager;
2375
2349
  exports.PluginDriver = PluginDriver;
2376
- exports.URLPath = URLPath;
2377
2350
  exports.build = build;
2351
+ exports.createAdapter = createAdapter;
2352
+ exports.createPlugin = createPlugin;
2353
+ exports.createStorage = createStorage;
2378
2354
  exports.default = build;
2379
- exports.defineAdapter = defineAdapter;
2355
+ exports.defaultResolveOptions = defaultResolveOptions;
2380
2356
  exports.defineConfig = defineConfig;
2381
2357
  exports.defineGenerator = defineGenerator;
2382
2358
  exports.defineLogger = defineLogger;
2383
- exports.definePlugin = definePlugin;
2384
2359
  Object.defineProperty(exports, "definePrinter", {
2385
2360
  enumerable: true,
2386
2361
  get: function() {
2387
2362
  return _kubb_ast.definePrinter;
2388
2363
  }
2389
2364
  });
2390
- exports.defineStorage = defineStorage;
2365
+ exports.defineResolver = defineResolver;
2391
2366
  exports.detectFormatter = detectFormatter;
2392
2367
  exports.detectLinter = detectLinter;
2393
2368
  exports.formatters = formatters;
@@ -2399,8 +2374,8 @@ exports.isInputPath = isInputPath;
2399
2374
  exports.linters = linters;
2400
2375
  exports.logLevel = logLevel;
2401
2376
  exports.memoryStorage = memoryStorage;
2402
- exports.resolveOptions = resolveOptions;
2403
2377
  exports.safeBuild = safeBuild;
2378
+ exports.satisfiesDependency = satisfiesDependency;
2404
2379
  exports.setup = setup;
2405
2380
 
2406
2381
  //# sourceMappingURL=index.cjs.map