kubb 5.0.0-alpha.41 → 5.0.0-alpha.43

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.cjs CHANGED
@@ -33,10 +33,27 @@ function normalizeConfig(config) {
33
33
  if (Array.isArray(config)) return config.map(applyDefaults);
34
34
  return applyDefaults(config);
35
35
  }
36
+ /**
37
+ * Helper for defining a Kubb configuration with built-in defaults.
38
+ *
39
+ * When no `adapter` is provided, `adapterOas()` is used automatically.
40
+ * When no `parsers` are provided, `[parserTsx]` is used automatically.
41
+ *
42
+ * Accepts either:
43
+ * - A config object or array of configs
44
+ * - A function returning the config(s), optionally async,
45
+ * receiving the CLI options as argument
46
+ *
47
+ * @example
48
+ * export default defineConfig(({ logLevel }) => ({
49
+ * root: 'src',
50
+ * plugins: [myPlugin()],
51
+ * }))
52
+ */
36
53
  function defineConfig(config) {
37
- if (typeof config === "function") return async (cli) => {
54
+ if (typeof config === "function") return (async (cli) => {
38
55
  return normalizeConfig(await config(cli));
39
- };
56
+ });
40
57
  if (isPromise(config)) return config.then((resolved) => normalizeConfig(resolved));
41
58
  return normalizeConfig(config);
42
59
  }
@@ -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 { CLIOptions, UserConfig } from '@kubb/core'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\n\ntype ConfigValue<TInput> = UserConfig<TInput>\ntype ConfigArray<TInput> = Array<ConfigValue<TInput>>\ntype ConfigResult<TInput> = ConfigValue<TInput> | ConfigArray<TInput>\ntype ConfigPromise<TInput> = Promise<ConfigResult<TInput>>\ntype ConfigFactory<TInput> = (cli: CLIOptions) => PossiblePromise<ConfigResult<TInput>>\ntype DefinedConfig<TInput> = ConfigResult<TInput> | ConfigPromise<TInput> | ((cli: CLIOptions) => Promise<ConfigResult<TInput>>)\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<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n return {\n ...config,\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx],\n }\n}\n\nfunction normalizeConfig<TInput>(config: UserConfig<TInput> | Array<UserConfig<TInput>>): UserConfig<TInput> | Array<UserConfig<TInput>> {\n if (Array.isArray(config)) {\n return config.map(applyDefaults)\n }\n\n return applyDefaults(config)\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<TInput>(config: (cli: CLIOptions) => PossiblePromise<UserConfig<TInput>>): (cli: CLIOptions) => Promise<UserConfig<TInput>>\nexport function defineConfig<TInput>(\n config: (cli: CLIOptions) => PossiblePromise<Array<UserConfig<TInput>>>,\n): (cli: CLIOptions) => Promise<Array<UserConfig<TInput>>>\nexport function defineConfig<TInput>(config: Promise<UserConfig<TInput>>): Promise<UserConfig<TInput>>\nexport function defineConfig<TInput>(config: Promise<Array<UserConfig<TInput>>>): Promise<Array<UserConfig<TInput>>>\nexport function defineConfig<TInput>(config: UserConfig<TInput>): UserConfig<TInput>\nexport function defineConfig<TInput>(config: Array<UserConfig<TInput>>): Array<UserConfig<TInput>>\nexport function defineConfig<TInput>(config: ConfigFactory<TInput>): (cli: CLIOptions) => Promise<ConfigResult<TInput>>\nexport function defineConfig<TInput>(config: ConfigResult<TInput> | ConfigPromise<TInput> | ConfigFactory<TInput>): DefinedConfig<TInput> {\n if (typeof config === 'function') {\n return async (cli: CLIOptions) => {\n return normalizeConfig(await config(cli))\n }\n }\n\n if (isPromise(config)) {\n return config.then((resolved) => normalizeConfig(resolved))\n }\n\n return normalizeConfig(config)\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,SAAgB,UAAa,QAAkD;AAC7E,QAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;;;;;;;;;;ACF3G,SAAS,cAAsB,QAAgD;AAC7E,QAAO;EACL,GAAG;EACH,SAAS,OAAO,YAAA,GAAA,kBAAA,aAAuB;EACvC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU,CAACA,gBAAAA,UAAUC,gBAAAA,UAAU;EACzE;;AAGH,SAAS,gBAAwB,QAAwG;AACvI,KAAI,MAAM,QAAQ,OAAO,CACvB,QAAO,OAAO,IAAI,cAAc;AAGlC,QAAO,cAAc,OAAO;;AA6B9B,SAAgB,aAAqB,QAAqG;AACxI,KAAI,OAAO,WAAW,WACpB,QAAO,OAAO,QAAoB;AAChC,SAAO,gBAAgB,MAAM,OAAO,IAAI,CAAC;;AAI7C,KAAI,UAAU,OAAO,CACnB,QAAO,OAAO,MAAM,aAAa,gBAAgB,SAAS,CAAC;AAG7D,QAAO,gBAAgB,OAAO"}
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, UserConfig } from '@kubb/core'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\n\ntype AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>\ntype ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>)\ntype NormalizeConfig<TConfig> =\n TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never\ntype DefinedConfig<TConfig extends ConfigInput> = TConfig extends (cli: CLIOptions) => PossiblePromise<infer TResult>\n ? (cli: CLIOptions) => Promise<NormalizeConfig<TResult>>\n : TConfig extends Promise<infer TResult>\n ? Promise<NormalizeConfig<TResult>>\n : NormalizeConfig<TConfig>\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<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n return {\n ...config,\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx],\n }\n}\n\nfunction normalizeConfig<TInput>(config: UserConfig<TInput> | Array<UserConfig<TInput>>): UserConfig<TInput> | Array<UserConfig<TInput>> {\n if (Array.isArray(config)) {\n return config.map(applyDefaults)\n }\n\n return applyDefaults(config)\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<TConfig extends ConfigInput>(config: TConfig): DefinedConfig<TConfig> {\n if (typeof config === 'function') {\n return (async (cli: CLIOptions) => {\n return normalizeConfig(await config(cli))\n }) as DefinedConfig<TConfig>\n }\n\n if (isPromise(config)) {\n return config.then((resolved) => normalizeConfig(resolved)) as DefinedConfig<TConfig>\n }\n\n return normalizeConfig(config) as DefinedConfig<TConfig>\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,SAAgB,UAAa,QAAkD;AAC7E,QAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;;;;;;;;;;ACC3G,SAAS,cAAsB,QAAgD;AAC7E,QAAO;EACL,GAAG;EACH,SAAS,OAAO,YAAA,GAAA,kBAAA,aAAuB;EACvC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU,CAACA,gBAAAA,UAAUC,gBAAAA,UAAU;EACzE;;AAGH,SAAS,gBAAwB,QAAwG;AACvI,KAAI,MAAM,QAAQ,OAAO,CACvB,QAAO,OAAO,IAAI,cAAc;AAGlC,QAAO,cAAc,OAAO;;;;;;;;;;;;;;;;;;;AAoB9B,SAAgB,aAA0C,QAAyC;AACjG,KAAI,OAAO,WAAW,WACpB,SAAQ,OAAO,QAAoB;AACjC,SAAO,gBAAgB,MAAM,OAAO,IAAI,CAAC;;AAI7C,KAAI,UAAU,OAAO,CACnB,QAAO,OAAO,MAAM,aAAa,gBAAgB,SAAS,CAAC;AAG7D,QAAO,gBAAgB,OAAO"}
package/dist/index.d.ts CHANGED
@@ -14,10 +14,10 @@ import { CLIOptions, UserConfig } from "@kubb/core";
14
14
  type PossiblePromise<T> = Promise<T> | T;
15
15
  //#endregion
16
16
  //#region src/defineConfig.d.ts
17
- type ConfigValue<TInput> = UserConfig<TInput>;
18
- type ConfigArray<TInput> = Array<ConfigValue<TInput>>;
19
- type ConfigResult<TInput> = ConfigValue<TInput> | ConfigArray<TInput>;
20
- type ConfigFactory<TInput> = (cli: CLIOptions) => PossiblePromise<ConfigResult<TInput>>;
17
+ type AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>;
18
+ type ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>);
19
+ type NormalizeConfig<TConfig> = TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never;
20
+ type DefinedConfig<TConfig extends ConfigInput> = TConfig extends ((cli: CLIOptions) => PossiblePromise<infer TResult>) ? (cli: CLIOptions) => Promise<NormalizeConfig<TResult>> : TConfig extends Promise<infer TResult> ? Promise<NormalizeConfig<TResult>> : NormalizeConfig<TConfig>;
21
21
  /**
22
22
  * Helper for defining a Kubb configuration with built-in defaults.
23
23
  *
@@ -35,13 +35,7 @@ type ConfigFactory<TInput> = (cli: CLIOptions) => PossiblePromise<ConfigResult<T
35
35
  * plugins: [myPlugin()],
36
36
  * }))
37
37
  */
38
- declare function defineConfig<TInput>(config: (cli: CLIOptions) => PossiblePromise<UserConfig<TInput>>): (cli: CLIOptions) => Promise<UserConfig<TInput>>;
39
- declare function defineConfig<TInput>(config: (cli: CLIOptions) => PossiblePromise<Array<UserConfig<TInput>>>): (cli: CLIOptions) => Promise<Array<UserConfig<TInput>>>;
40
- declare function defineConfig<TInput>(config: Promise<UserConfig<TInput>>): Promise<UserConfig<TInput>>;
41
- declare function defineConfig<TInput>(config: Promise<Array<UserConfig<TInput>>>): Promise<Array<UserConfig<TInput>>>;
42
- declare function defineConfig<TInput>(config: UserConfig<TInput>): UserConfig<TInput>;
43
- declare function defineConfig<TInput>(config: Array<UserConfig<TInput>>): Array<UserConfig<TInput>>;
44
- declare function defineConfig<TInput>(config: ConfigFactory<TInput>): (cli: CLIOptions) => Promise<ConfigResult<TInput>>;
38
+ declare function defineConfig<TConfig extends ConfigInput>(config: TConfig): DefinedConfig<TConfig>;
45
39
  //#endregion
46
40
  export { defineConfig };
47
41
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -32,10 +32,27 @@ function normalizeConfig(config) {
32
32
  if (Array.isArray(config)) return config.map(applyDefaults);
33
33
  return applyDefaults(config);
34
34
  }
35
+ /**
36
+ * Helper for defining a Kubb configuration with built-in defaults.
37
+ *
38
+ * When no `adapter` is provided, `adapterOas()` is used automatically.
39
+ * When no `parsers` are provided, `[parserTsx]` is used automatically.
40
+ *
41
+ * Accepts either:
42
+ * - A config object or array of configs
43
+ * - A function returning the config(s), optionally async,
44
+ * receiving the CLI options as argument
45
+ *
46
+ * @example
47
+ * export default defineConfig(({ logLevel }) => ({
48
+ * root: 'src',
49
+ * plugins: [myPlugin()],
50
+ * }))
51
+ */
35
52
  function defineConfig(config) {
36
- if (typeof config === "function") return async (cli) => {
53
+ if (typeof config === "function") return (async (cli) => {
37
54
  return normalizeConfig(await config(cli));
38
- };
55
+ });
39
56
  if (isPromise(config)) return config.then((resolved) => normalizeConfig(resolved));
40
57
  return normalizeConfig(config);
41
58
  }
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 { CLIOptions, UserConfig } from '@kubb/core'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\n\ntype ConfigValue<TInput> = UserConfig<TInput>\ntype ConfigArray<TInput> = Array<ConfigValue<TInput>>\ntype ConfigResult<TInput> = ConfigValue<TInput> | ConfigArray<TInput>\ntype ConfigPromise<TInput> = Promise<ConfigResult<TInput>>\ntype ConfigFactory<TInput> = (cli: CLIOptions) => PossiblePromise<ConfigResult<TInput>>\ntype DefinedConfig<TInput> = ConfigResult<TInput> | ConfigPromise<TInput> | ((cli: CLIOptions) => Promise<ConfigResult<TInput>>)\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<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n return {\n ...config,\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx],\n }\n}\n\nfunction normalizeConfig<TInput>(config: UserConfig<TInput> | Array<UserConfig<TInput>>): UserConfig<TInput> | Array<UserConfig<TInput>> {\n if (Array.isArray(config)) {\n return config.map(applyDefaults)\n }\n\n return applyDefaults(config)\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<TInput>(config: (cli: CLIOptions) => PossiblePromise<UserConfig<TInput>>): (cli: CLIOptions) => Promise<UserConfig<TInput>>\nexport function defineConfig<TInput>(\n config: (cli: CLIOptions) => PossiblePromise<Array<UserConfig<TInput>>>,\n): (cli: CLIOptions) => Promise<Array<UserConfig<TInput>>>\nexport function defineConfig<TInput>(config: Promise<UserConfig<TInput>>): Promise<UserConfig<TInput>>\nexport function defineConfig<TInput>(config: Promise<Array<UserConfig<TInput>>>): Promise<Array<UserConfig<TInput>>>\nexport function defineConfig<TInput>(config: UserConfig<TInput>): UserConfig<TInput>\nexport function defineConfig<TInput>(config: Array<UserConfig<TInput>>): Array<UserConfig<TInput>>\nexport function defineConfig<TInput>(config: ConfigFactory<TInput>): (cli: CLIOptions) => Promise<ConfigResult<TInput>>\nexport function defineConfig<TInput>(config: ConfigResult<TInput> | ConfigPromise<TInput> | ConfigFactory<TInput>): DefinedConfig<TInput> {\n if (typeof config === 'function') {\n return async (cli: CLIOptions) => {\n return normalizeConfig(await config(cli))\n }\n }\n\n if (isPromise(config)) {\n return config.then((resolved) => normalizeConfig(resolved))\n }\n\n return normalizeConfig(config)\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,SAAgB,UAAa,QAAkD;AAC7E,QAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;;;;;;;;;;ACF3G,SAAS,cAAsB,QAAgD;AAC7E,QAAO;EACL,GAAG;EACH,SAAS,OAAO,WAAW,YAAY;EACvC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU,CAAC,UAAU,UAAU;EACzE;;AAGH,SAAS,gBAAwB,QAAwG;AACvI,KAAI,MAAM,QAAQ,OAAO,CACvB,QAAO,OAAO,IAAI,cAAc;AAGlC,QAAO,cAAc,OAAO;;AA6B9B,SAAgB,aAAqB,QAAqG;AACxI,KAAI,OAAO,WAAW,WACpB,QAAO,OAAO,QAAoB;AAChC,SAAO,gBAAgB,MAAM,OAAO,IAAI,CAAC;;AAI7C,KAAI,UAAU,OAAO,CACnB,QAAO,OAAO,MAAM,aAAa,gBAAgB,SAAS,CAAC;AAG7D,QAAO,gBAAgB,OAAO"}
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, UserConfig } from '@kubb/core'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\n\ntype AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>\ntype ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>)\ntype NormalizeConfig<TConfig> =\n TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never\ntype DefinedConfig<TConfig extends ConfigInput> = TConfig extends (cli: CLIOptions) => PossiblePromise<infer TResult>\n ? (cli: CLIOptions) => Promise<NormalizeConfig<TResult>>\n : TConfig extends Promise<infer TResult>\n ? Promise<NormalizeConfig<TResult>>\n : NormalizeConfig<TConfig>\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<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n return {\n ...config,\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx],\n }\n}\n\nfunction normalizeConfig<TInput>(config: UserConfig<TInput> | Array<UserConfig<TInput>>): UserConfig<TInput> | Array<UserConfig<TInput>> {\n if (Array.isArray(config)) {\n return config.map(applyDefaults)\n }\n\n return applyDefaults(config)\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<TConfig extends ConfigInput>(config: TConfig): DefinedConfig<TConfig> {\n if (typeof config === 'function') {\n return (async (cli: CLIOptions) => {\n return normalizeConfig(await config(cli))\n }) as DefinedConfig<TConfig>\n }\n\n if (isPromise(config)) {\n return config.then((resolved) => normalizeConfig(resolved)) as DefinedConfig<TConfig>\n }\n\n return normalizeConfig(config) as DefinedConfig<TConfig>\n}\n"],"mappings":";;;;;;;;;;;;AAmBA,SAAgB,UAAa,QAAkD;AAC7E,QAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;;;;;;;;;;ACC3G,SAAS,cAAsB,QAAgD;AAC7E,QAAO;EACL,GAAG;EACH,SAAS,OAAO,WAAW,YAAY;EACvC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU,CAAC,UAAU,UAAU;EACzE;;AAGH,SAAS,gBAAwB,QAAwG;AACvI,KAAI,MAAM,QAAQ,OAAO,CACvB,QAAO,OAAO,IAAI,cAAc;AAGlC,QAAO,cAAc,OAAO;;;;;;;;;;;;;;;;;;;AAoB9B,SAAgB,aAA0C,QAAyC;AACjG,KAAI,OAAO,WAAW,WACpB,SAAQ,OAAO,QAAoB;AACjC,SAAO,gBAAgB,MAAM,OAAO,IAAI,CAAC;;AAI7C,KAAI,UAAU,OAAO,CACnB,QAAO,OAAO,MAAM,aAAa,gBAAgB,SAAS,CAAC;AAG7D,QAAO,gBAAgB,OAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kubb",
3
- "version": "5.0.0-alpha.41",
3
+ "version": "5.0.0-alpha.43",
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.41",
55
- "@kubb/agent": "5.0.0-alpha.41",
56
- "@kubb/cli": "5.0.0-alpha.41",
57
- "@kubb/core": "5.0.0-alpha.41",
58
- "@kubb/mcp": "5.0.0-alpha.41",
59
- "@kubb/parser-ts": "5.0.0-alpha.41"
54
+ "@kubb/adapter-oas": "5.0.0-alpha.43",
55
+ "@kubb/agent": "5.0.0-alpha.43",
56
+ "@kubb/cli": "5.0.0-alpha.43",
57
+ "@kubb/core": "5.0.0-alpha.43",
58
+ "@kubb/mcp": "5.0.0-alpha.43",
59
+ "@kubb/parser-ts": "5.0.0-alpha.43"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@internals/utils": "0.0.0"
@@ -3,12 +3,15 @@ import { adapterOas } from '@kubb/adapter-oas'
3
3
  import type { CLIOptions, UserConfig } from '@kubb/core'
4
4
  import { parserTs, parserTsx } from '@kubb/parser-ts'
5
5
 
6
- type ConfigValue<TInput> = UserConfig<TInput>
7
- type ConfigArray<TInput> = Array<ConfigValue<TInput>>
8
- type ConfigResult<TInput> = ConfigValue<TInput> | ConfigArray<TInput>
9
- type ConfigPromise<TInput> = Promise<ConfigResult<TInput>>
10
- type ConfigFactory<TInput> = (cli: CLIOptions) => PossiblePromise<ConfigResult<TInput>>
11
- type DefinedConfig<TInput> = ConfigResult<TInput> | ConfigPromise<TInput> | ((cli: CLIOptions) => Promise<ConfigResult<TInput>>)
6
+ type AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>
7
+ type ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>)
8
+ type NormalizeConfig<TConfig> =
9
+ TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never
10
+ type DefinedConfig<TConfig extends ConfigInput> = TConfig extends (cli: CLIOptions) => PossiblePromise<infer TResult>
11
+ ? (cli: CLIOptions) => Promise<NormalizeConfig<TResult>>
12
+ : TConfig extends Promise<infer TResult>
13
+ ? Promise<NormalizeConfig<TResult>>
14
+ : NormalizeConfig<TConfig>
12
15
 
13
16
  /**
14
17
  * Applies default adapter and parsers to a single user config when not set.
@@ -49,25 +52,16 @@ function normalizeConfig<TInput>(config: UserConfig<TInput> | Array<UserConfig<T
49
52
  * plugins: [myPlugin()],
50
53
  * }))
51
54
  */
52
- export function defineConfig<TInput>(config: (cli: CLIOptions) => PossiblePromise<UserConfig<TInput>>): (cli: CLIOptions) => Promise<UserConfig<TInput>>
53
- export function defineConfig<TInput>(
54
- config: (cli: CLIOptions) => PossiblePromise<Array<UserConfig<TInput>>>,
55
- ): (cli: CLIOptions) => Promise<Array<UserConfig<TInput>>>
56
- export function defineConfig<TInput>(config: Promise<UserConfig<TInput>>): Promise<UserConfig<TInput>>
57
- export function defineConfig<TInput>(config: Promise<Array<UserConfig<TInput>>>): Promise<Array<UserConfig<TInput>>>
58
- export function defineConfig<TInput>(config: UserConfig<TInput>): UserConfig<TInput>
59
- export function defineConfig<TInput>(config: Array<UserConfig<TInput>>): Array<UserConfig<TInput>>
60
- export function defineConfig<TInput>(config: ConfigFactory<TInput>): (cli: CLIOptions) => Promise<ConfigResult<TInput>>
61
- export function defineConfig<TInput>(config: ConfigResult<TInput> | ConfigPromise<TInput> | ConfigFactory<TInput>): DefinedConfig<TInput> {
55
+ export function defineConfig<TConfig extends ConfigInput>(config: TConfig): DefinedConfig<TConfig> {
62
56
  if (typeof config === 'function') {
63
- return async (cli: CLIOptions) => {
57
+ return (async (cli: CLIOptions) => {
64
58
  return normalizeConfig(await config(cli))
65
- }
59
+ }) as DefinedConfig<TConfig>
66
60
  }
67
61
 
68
62
  if (isPromise(config)) {
69
- return config.then((resolved) => normalizeConfig(resolved))
63
+ return config.then((resolved) => normalizeConfig(resolved)) as DefinedConfig<TConfig>
70
64
  }
71
65
 
72
- return normalizeConfig(config)
66
+ return normalizeConfig(config) as DefinedConfig<TConfig>
73
67
  }