kubb 5.0.0-alpha.34 → 5.0.0-alpha.36

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["parserTs","parserTsx"],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\n/** Returns `true` when `result` is a fulfilled `Promise.allSettled` result.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseFulfilledResult).map((r) => r.value)\n * ```\n */\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport type { UserConfig } from '@kubb/core'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\n\n/**\n * CLI options derived from command-line flags.\n */\nexport type CLIOptions = {\n /**\n * Path to `kubb.config.js`.\n */\n config?: string\n /**\n * Enable watch mode for input files.\n */\n watch?: boolean\n /**\n * Logging verbosity for CLI usage.\n *\n * - `silent`: hide non-essential logs\n * - `info`: show general logs (non-plugin-related)\n * - `debug`: include detailed plugin lifecycle logs\n * @default 'silent'\n */\n logLevel?: 'silent' | 'info' | 'debug'\n}\n\n/**\n * All accepted forms of a Kubb configuration.\n */\nexport type ConfigInput = PossiblePromise<UserConfig | UserConfig[]> | ((cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>)\n\n/**\n * Applies default adapter and parsers to a single user config when not set.\n *\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx]`\n */\nfunction applyDefaults(config: UserConfig): UserConfig {\n return {\n ...config,\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx],\n }\n}\n\n/**\n * Helper for defining a Kubb configuration with built-in defaults.\n *\n * When no `adapter` is provided, `adapterOas()` is used automatically.\n * When no `parsers` are provided, `[parserTsx]` is used automatically.\n *\n * Accepts either:\n * - A config object or array of configs\n * - A function returning the config(s), optionally async,\n * receiving the CLI options as argument\n *\n * @example\n * export default defineConfig(({ logLevel }) => ({\n * root: 'src',\n * plugins: [myPlugin()],\n * }))\n */\nexport function defineConfig(config: (cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>): (cli: CLIOptions) => Promise<UserConfig | UserConfig[]>\nexport function defineConfig(config: Promise<UserConfig | UserConfig[]>): Promise<UserConfig | UserConfig[]>\nexport function defineConfig(config: UserConfig | UserConfig[]): UserConfig | UserConfig[]\nexport function defineConfig(config: ConfigInput): ConfigInput {\n if (typeof config === 'function') {\n return async (cli: CLIOptions) => {\n const resolved = await config(cli)\n const configs = Array.isArray(resolved) ? resolved : [resolved]\n const result = configs.map(applyDefaults)\n\n return result.length === 1 ? result[0]! : result\n }\n }\n\n if (isPromise(config)) {\n return config.then((resolved) => {\n const configs = Array.isArray(resolved) ? resolved : [resolved]\n const result = configs.map(applyDefaults)\n\n return result.length === 1 ? result[0]! : result\n })\n }\n\n const configs = Array.isArray(config) ? config : [config]\n const result = configs.map(applyDefaults)\n\n return result.length === 1 ? result[0]! : result\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,SAAgB,UAAa,QAAkD;AAC7E,QAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;;;;;;;;;;ACmB3G,SAAS,cAAc,QAAgC;AACrD,QAAO;EACL,GAAG;EACH,SAAS,OAAO,YAAA,GAAA,kBAAA,aAAuB;EACvC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU,CAACA,gBAAAA,UAAUC,gBAAAA,UAAU;EACzE;;AAuBH,SAAgB,aAAa,QAAkC;AAC7D,KAAI,OAAO,WAAW,WACpB,QAAO,OAAO,QAAoB;EAChC,MAAM,WAAW,MAAM,OAAO,IAAI;EAElC,MAAM,UADU,MAAM,QAAQ,SAAS,GAAG,WAAW,CAAC,SAAS,EACxC,IAAI,cAAc;AAEzC,SAAO,OAAO,WAAW,IAAI,OAAO,KAAM;;AAI9C,KAAI,UAAU,OAAO,CACnB,QAAO,OAAO,MAAM,aAAa;EAE/B,MAAM,UADU,MAAM,QAAQ,SAAS,GAAG,WAAW,CAAC,SAAS,EACxC,IAAI,cAAc;AAEzC,SAAO,OAAO,WAAW,IAAI,OAAO,KAAM;GAC1C;CAIJ,MAAM,UADU,MAAM,QAAQ,OAAO,GAAG,SAAS,CAAC,OAAO,EAClC,IAAI,cAAc;AAEzC,QAAO,OAAO,WAAW,IAAI,OAAO,KAAM"}
1
+ {"version":3,"file":"index.cjs","names":["parserTs","parserTsx"],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\n/** Returns `true` when `result` is a fulfilled `Promise.allSettled` result.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseFulfilledResult).map((r) => r.value)\n * ```\n */\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport type { CLIOptions } from '@kubb/core'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\nimport type { ConfigInput, UserConfig } from './types.ts'\n\n/**\n * Applies default adapter and parsers to a single user config when not set.\n *\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx]`\n */\nfunction applyDefaults(config: UserConfig): UserConfig {\n return {\n ...config,\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx],\n }\n}\n\n/**\n * Helper for defining a Kubb configuration with built-in defaults.\n *\n * When no `adapter` is provided, `adapterOas()` is used automatically.\n * When no `parsers` are provided, `[parserTsx]` is used automatically.\n *\n * Accepts either:\n * - A config object or array of configs\n * - A function returning the config(s), optionally async,\n * receiving the CLI options as argument\n *\n * @example\n * export default defineConfig(({ logLevel }) => ({\n * root: 'src',\n * plugins: [myPlugin()],\n * }))\n */\nexport function defineConfig(config: (cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>): (cli: CLIOptions) => Promise<UserConfig | UserConfig[]>\nexport function defineConfig(config: Promise<UserConfig | UserConfig[]>): Promise<UserConfig | UserConfig[]>\nexport function defineConfig(config: UserConfig | UserConfig[]): UserConfig | UserConfig[]\nexport function defineConfig(config: ConfigInput): ConfigInput {\n if (typeof config === 'function') {\n return async (cli: CLIOptions) => {\n const resolved = await config(cli)\n const configs = Array.isArray(resolved) ? resolved : [resolved]\n const result = configs.map(applyDefaults)\n\n return result.length === 1 ? result[0]! : result\n }\n }\n\n if (isPromise(config)) {\n return config.then((resolved) => {\n const configs = Array.isArray(resolved) ? resolved : [resolved]\n const result = configs.map(applyDefaults)\n\n return result.length === 1 ? result[0]! : result\n })\n }\n\n const configs = Array.isArray(config) ? config : [config]\n const result = configs.map(applyDefaults)\n\n return result.length === 1 ? result[0]! : result\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,SAAgB,UAAa,QAAkD;AAC7E,QAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;;;;;;;;;;ACR3G,SAAS,cAAc,QAAgC;AACrD,QAAO;EACL,GAAG;EACH,SAAS,OAAO,YAAA,GAAA,kBAAA,aAAuB;EACvC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU,CAACA,gBAAAA,UAAUC,gBAAAA,UAAU;EACzE;;AAuBH,SAAgB,aAAa,QAAkC;AAC7D,KAAI,OAAO,WAAW,WACpB,QAAO,OAAO,QAAoB;EAChC,MAAM,WAAW,MAAM,OAAO,IAAI;EAElC,MAAM,UADU,MAAM,QAAQ,SAAS,GAAG,WAAW,CAAC,SAAS,EACxC,IAAI,cAAc;AAEzC,SAAO,OAAO,WAAW,IAAI,OAAO,KAAM;;AAI9C,KAAI,UAAU,OAAO,CACnB,QAAO,OAAO,MAAM,aAAa;EAE/B,MAAM,UADU,MAAM,QAAQ,SAAS,GAAG,WAAW,CAAC,SAAS,EACxC,IAAI,cAAc;AAEzC,SAAO,OAAO,WAAW,IAAI,OAAO,KAAM;GAC1C;CAIJ,MAAM,UADU,MAAM,QAAQ,OAAO,GAAG,SAAS,CAAC,OAAO,EAClC,IAAI,cAAc;AAEzC,QAAO,OAAO,WAAW,IAAI,OAAO,KAAM"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { UserConfig } from "@kubb/core";
2
+ import { Adapter, CLIOptions, Config, HookStylePlugin, InputData, InputPath, Parser, PluginFactoryOptions, UserPlugin } from "@kubb/core";
3
3
 
4
4
  //#region ../../internals/utils/src/promise.d.ts
5
5
  /** A value that may already be resolved or still pending.
@@ -13,29 +13,51 @@ import { UserConfig } from "@kubb/core";
13
13
  */
14
14
  type PossiblePromise<T> = Promise<T> | T;
15
15
  //#endregion
16
- //#region src/defineConfig.d.ts
16
+ //#region src/types.d.ts
17
+ type Input = InputPath | InputData;
18
+ type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<string, object, object, unknown, object>>;
17
19
  /**
18
- * CLI options derived from command-line flags.
20
+ * Partial version of {@link Config} intended for use in `kubb.config.ts`.
21
+ *
22
+ * Fields that have sensible defaults (`root`, `plugins`, `parsers`, `adapter`) are optional.
19
23
  */
20
- type CLIOptions = {
24
+ type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter'> & {
21
25
  /**
22
- * Path to `kubb.config.js`.
26
+ * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
27
+ * @default process.cwd()
23
28
  */
24
- config?: string;
29
+ root?: string;
25
30
  /**
26
- * Enable watch mode for input files.
31
+ * An array of parsers used to convert generated files to strings.
32
+ * Each parser handles specific file extensions (e.g. `.ts`, `.tsx`).
33
+ *
34
+ * A catch-all fallback parser is always appended last for any unhandled extension.
35
+ *
36
+ * When omitted, `parserTsx` from `@kubb/parser-ts` is used automatically as the
37
+ * default (requires `@kubb/parser-ts` to be installed as an optional dependency).
38
+ * @default [parserTsx] — from `@kubb/parser-ts`
27
39
  */
28
- watch?: boolean;
40
+ parsers?: Array<Parser>;
29
41
  /**
30
- * Logging verbosity for CLI usage.
42
+ * Adapter that converts the input file into a `@kubb/ast` `InputNode` — the universal
43
+ * intermediate representation consumed by all Kubb plugins.
44
+ *
45
+ * When omitted, `adapterOas()` from `@kubb/adapter-oas` is used automatically as the
46
+ * default (requires `@kubb/adapter-oas` to be installed as an optional dependency).
31
47
  *
32
- * - `silent`: hide non-essential logs
33
- * - `info`: show general logs (non-plugin-related)
34
- * - `debug`: include detailed plugin lifecycle logs
35
- * @default 'silent'
48
+ * @default adapterOas() from `@kubb/adapter-oas`
36
49
  */
37
- logLevel?: 'silent' | 'info' | 'debug';
50
+ adapter?: Adapter;
51
+ /**
52
+ * An array of Kubb plugins used for code generation.
53
+ * Each plugin may declare additional configurable options.
54
+ * If a plugin depends on another, an error is thrown when the dependency is missing.
55
+ * Use `dependencies` on the plugin to declare execution order.
56
+ */
57
+ plugins?: Array<Omit<UnknownUserPlugin, 'inject'> | HookStylePlugin>;
38
58
  };
59
+ //#endregion
60
+ //#region src/defineConfig.d.ts
39
61
  /**
40
62
  * Helper for defining a Kubb configuration with built-in defaults.
41
63
  *
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\n/** Returns `true` when `result` is a fulfilled `Promise.allSettled` result.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseFulfilledResult).map((r) => r.value)\n * ```\n */\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport type { UserConfig } from '@kubb/core'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\n\n/**\n * CLI options derived from command-line flags.\n */\nexport type CLIOptions = {\n /**\n * Path to `kubb.config.js`.\n */\n config?: string\n /**\n * Enable watch mode for input files.\n */\n watch?: boolean\n /**\n * Logging verbosity for CLI usage.\n *\n * - `silent`: hide non-essential logs\n * - `info`: show general logs (non-plugin-related)\n * - `debug`: include detailed plugin lifecycle logs\n * @default 'silent'\n */\n logLevel?: 'silent' | 'info' | 'debug'\n}\n\n/**\n * All accepted forms of a Kubb configuration.\n */\nexport type ConfigInput = PossiblePromise<UserConfig | UserConfig[]> | ((cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>)\n\n/**\n * Applies default adapter and parsers to a single user config when not set.\n *\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx]`\n */\nfunction applyDefaults(config: UserConfig): UserConfig {\n return {\n ...config,\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx],\n }\n}\n\n/**\n * Helper for defining a Kubb configuration with built-in defaults.\n *\n * When no `adapter` is provided, `adapterOas()` is used automatically.\n * When no `parsers` are provided, `[parserTsx]` is used automatically.\n *\n * Accepts either:\n * - A config object or array of configs\n * - A function returning the config(s), optionally async,\n * receiving the CLI options as argument\n *\n * @example\n * export default defineConfig(({ logLevel }) => ({\n * root: 'src',\n * plugins: [myPlugin()],\n * }))\n */\nexport function defineConfig(config: (cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>): (cli: CLIOptions) => Promise<UserConfig | UserConfig[]>\nexport function defineConfig(config: Promise<UserConfig | UserConfig[]>): Promise<UserConfig | UserConfig[]>\nexport function defineConfig(config: UserConfig | UserConfig[]): UserConfig | UserConfig[]\nexport function defineConfig(config: ConfigInput): ConfigInput {\n if (typeof config === 'function') {\n return async (cli: CLIOptions) => {\n const resolved = await config(cli)\n const configs = Array.isArray(resolved) ? resolved : [resolved]\n const result = configs.map(applyDefaults)\n\n return result.length === 1 ? result[0]! : result\n }\n }\n\n if (isPromise(config)) {\n return config.then((resolved) => {\n const configs = Array.isArray(resolved) ? resolved : [resolved]\n const result = configs.map(applyDefaults)\n\n return result.length === 1 ? result[0]! : result\n })\n }\n\n const configs = Array.isArray(config) ? config : [config]\n const result = configs.map(applyDefaults)\n\n return result.length === 1 ? result[0]! : result\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,SAAgB,UAAa,QAAkD;AAC7E,QAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;;;;;;;;;;ACmB3G,SAAS,cAAc,QAAgC;AACrD,QAAO;EACL,GAAG;EACH,SAAS,OAAO,WAAW,YAAY;EACvC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU,CAAC,UAAU,UAAU;EACzE;;AAuBH,SAAgB,aAAa,QAAkC;AAC7D,KAAI,OAAO,WAAW,WACpB,QAAO,OAAO,QAAoB;EAChC,MAAM,WAAW,MAAM,OAAO,IAAI;EAElC,MAAM,UADU,MAAM,QAAQ,SAAS,GAAG,WAAW,CAAC,SAAS,EACxC,IAAI,cAAc;AAEzC,SAAO,OAAO,WAAW,IAAI,OAAO,KAAM;;AAI9C,KAAI,UAAU,OAAO,CACnB,QAAO,OAAO,MAAM,aAAa;EAE/B,MAAM,UADU,MAAM,QAAQ,SAAS,GAAG,WAAW,CAAC,SAAS,EACxC,IAAI,cAAc;AAEzC,SAAO,OAAO,WAAW,IAAI,OAAO,KAAM;GAC1C;CAIJ,MAAM,UADU,MAAM,QAAQ,OAAO,GAAG,SAAS,CAAC,OAAO,EAClC,IAAI,cAAc;AAEzC,QAAO,OAAO,WAAW,IAAI,OAAO,KAAM"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\n/** Returns `true` when `result` is a fulfilled `Promise.allSettled` result.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseFulfilledResult).map((r) => r.value)\n * ```\n */\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport type { CLIOptions } from '@kubb/core'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\nimport type { ConfigInput, UserConfig } from './types.ts'\n\n/**\n * Applies default adapter and parsers to a single user config when not set.\n *\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx]`\n */\nfunction applyDefaults(config: UserConfig): UserConfig {\n return {\n ...config,\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx],\n }\n}\n\n/**\n * Helper for defining a Kubb configuration with built-in defaults.\n *\n * When no `adapter` is provided, `adapterOas()` is used automatically.\n * When no `parsers` are provided, `[parserTsx]` is used automatically.\n *\n * Accepts either:\n * - A config object or array of configs\n * - A function returning the config(s), optionally async,\n * receiving the CLI options as argument\n *\n * @example\n * export default defineConfig(({ logLevel }) => ({\n * root: 'src',\n * plugins: [myPlugin()],\n * }))\n */\nexport function defineConfig(config: (cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>): (cli: CLIOptions) => Promise<UserConfig | UserConfig[]>\nexport function defineConfig(config: Promise<UserConfig | UserConfig[]>): Promise<UserConfig | UserConfig[]>\nexport function defineConfig(config: UserConfig | UserConfig[]): UserConfig | UserConfig[]\nexport function defineConfig(config: ConfigInput): ConfigInput {\n if (typeof config === 'function') {\n return async (cli: CLIOptions) => {\n const resolved = await config(cli)\n const configs = Array.isArray(resolved) ? resolved : [resolved]\n const result = configs.map(applyDefaults)\n\n return result.length === 1 ? result[0]! : result\n }\n }\n\n if (isPromise(config)) {\n return config.then((resolved) => {\n const configs = Array.isArray(resolved) ? resolved : [resolved]\n const result = configs.map(applyDefaults)\n\n return result.length === 1 ? result[0]! : result\n })\n }\n\n const configs = Array.isArray(config) ? config : [config]\n const result = configs.map(applyDefaults)\n\n return result.length === 1 ? result[0]! : result\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,SAAgB,UAAa,QAAkD;AAC7E,QAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;;;;;;;;;;ACR3G,SAAS,cAAc,QAAgC;AACrD,QAAO;EACL,GAAG;EACH,SAAS,OAAO,WAAW,YAAY;EACvC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU,CAAC,UAAU,UAAU;EACzE;;AAuBH,SAAgB,aAAa,QAAkC;AAC7D,KAAI,OAAO,WAAW,WACpB,QAAO,OAAO,QAAoB;EAChC,MAAM,WAAW,MAAM,OAAO,IAAI;EAElC,MAAM,UADU,MAAM,QAAQ,SAAS,GAAG,WAAW,CAAC,SAAS,EACxC,IAAI,cAAc;AAEzC,SAAO,OAAO,WAAW,IAAI,OAAO,KAAM;;AAI9C,KAAI,UAAU,OAAO,CACnB,QAAO,OAAO,MAAM,aAAa;EAE/B,MAAM,UADU,MAAM,QAAQ,SAAS,GAAG,WAAW,CAAC,SAAS,EACxC,IAAI,cAAc;AAEzC,SAAO,OAAO,WAAW,IAAI,OAAO,KAAM;GAC1C;CAIJ,MAAM,UADU,MAAM,QAAQ,OAAO,GAAG,SAAS,CAAC,OAAO,EAClC,IAAI,cAAc;AAEzC,QAAO,OAAO,WAAW,IAAI,OAAO,KAAM"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kubb",
3
- "version": "5.0.0-alpha.34",
3
+ "version": "5.0.0-alpha.36",
4
4
  "description": "Transform OpenAPI specifications into TypeScript, React-Query, Zod, Faker.js, MSW and more with a plugin-based code generation tool.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -51,12 +51,12 @@
51
51
  }
52
52
  ],
53
53
  "dependencies": {
54
- "@kubb/adapter-oas": "5.0.0-alpha.34",
55
- "@kubb/agent": "5.0.0-alpha.34",
56
- "@kubb/cli": "5.0.0-alpha.34",
57
- "@kubb/core": "5.0.0-alpha.34",
58
- "@kubb/mcp": "5.0.0-alpha.34",
59
- "@kubb/parser-ts": "5.0.0-alpha.34"
54
+ "@kubb/adapter-oas": "5.0.0-alpha.36",
55
+ "@kubb/agent": "5.0.0-alpha.36",
56
+ "@kubb/cli": "5.0.0-alpha.36",
57
+ "@kubb/core": "5.0.0-alpha.36",
58
+ "@kubb/mcp": "5.0.0-alpha.36",
59
+ "@kubb/parser-ts": "5.0.0-alpha.36"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@internals/utils": "0.0.0"
@@ -1,35 +1,8 @@
1
1
  import { isPromise, type PossiblePromise } from '@internals/utils'
2
2
  import { adapterOas } from '@kubb/adapter-oas'
3
- import type { UserConfig } from '@kubb/core'
3
+ import type { CLIOptions } from '@kubb/core'
4
4
  import { parserTs, parserTsx } from '@kubb/parser-ts'
5
-
6
- /**
7
- * CLI options derived from command-line flags.
8
- */
9
- export type CLIOptions = {
10
- /**
11
- * Path to `kubb.config.js`.
12
- */
13
- config?: string
14
- /**
15
- * Enable watch mode for input files.
16
- */
17
- watch?: boolean
18
- /**
19
- * Logging verbosity for CLI usage.
20
- *
21
- * - `silent`: hide non-essential logs
22
- * - `info`: show general logs (non-plugin-related)
23
- * - `debug`: include detailed plugin lifecycle logs
24
- * @default 'silent'
25
- */
26
- logLevel?: 'silent' | 'info' | 'debug'
27
- }
28
-
29
- /**
30
- * All accepted forms of a Kubb configuration.
31
- */
32
- export type ConfigInput = PossiblePromise<UserConfig | UserConfig[]> | ((cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>)
5
+ import type { ConfigInput, UserConfig } from './types.ts'
33
6
 
34
7
  /**
35
8
  * Applies default adapter and parsers to a single user config when not set.
package/src/types.ts ADDED
@@ -0,0 +1,52 @@
1
+ import type { PossiblePromise } from '@internals/utils'
2
+ import type { Adapter, CLIOptions, Config, HookStylePlugin, InputData, InputPath, Parser, PluginFactoryOptions, UserPlugin } from '@kubb/core'
3
+
4
+ type Input = InputPath | InputData
5
+ type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<string, object, object, unknown, object>>
6
+
7
+ /**
8
+ * Partial version of {@link Config} intended for use in `kubb.config.ts`.
9
+ *
10
+ * Fields that have sensible defaults (`root`, `plugins`, `parsers`, `adapter`) are optional.
11
+ */
12
+ export type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter'> & {
13
+ /**
14
+ * The project root directory, which can be either an absolute path or a path relative to the location of your `kubb.config.ts` file.
15
+ * @default process.cwd()
16
+ */
17
+ root?: string
18
+ /**
19
+ * An array of parsers used to convert generated files to strings.
20
+ * Each parser handles specific file extensions (e.g. `.ts`, `.tsx`).
21
+ *
22
+ * A catch-all fallback parser is always appended last for any unhandled extension.
23
+ *
24
+ * When omitted, `parserTsx` from `@kubb/parser-ts` is used automatically as the
25
+ * default (requires `@kubb/parser-ts` to be installed as an optional dependency).
26
+ * @default [parserTsx] — from `@kubb/parser-ts`
27
+ */
28
+ parsers?: Array<Parser>
29
+ /**
30
+ * Adapter that converts the input file into a `@kubb/ast` `InputNode` — the universal
31
+ * intermediate representation consumed by all Kubb plugins.
32
+ *
33
+ * When omitted, `adapterOas()` from `@kubb/adapter-oas` is used automatically as the
34
+ * default (requires `@kubb/adapter-oas` to be installed as an optional dependency).
35
+ *
36
+ * @default adapterOas() — from `@kubb/adapter-oas`
37
+ */
38
+ adapter?: Adapter
39
+ /**
40
+ * An array of Kubb plugins used for code generation.
41
+ * Each plugin may declare additional configurable options.
42
+ * If a plugin depends on another, an error is thrown when the dependency is missing.
43
+ * Use `dependencies` on the plugin to declare execution order.
44
+ */
45
+ // inject needs to be omitted because else we have a clash with the PluginDriver instance
46
+ plugins?: Array<Omit<UnknownUserPlugin, 'inject'> | HookStylePlugin>
47
+ }
48
+
49
+ /**
50
+ * All accepted forms of a Kubb configuration.
51
+ */
52
+ export type ConfigInput = PossiblePromise<UserConfig | UserConfig[]> | ((cli: CLIOptions) => PossiblePromise<UserConfig | UserConfig[]>)