kubb 5.0.0-beta.84 → 5.0.0-beta.86
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/README.md +1 -1
- package/dist/astro.cjs +4 -0
- package/dist/astro.d.ts +2 -0
- package/dist/astro.js +2 -0
- package/dist/config.cjs +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -1
- package/dist/{defineConfig-BXme6pNF.cjs → defineConfig-BOa6m75p.cjs} +7 -10
- package/dist/defineConfig-BOa6m75p.cjs.map +1 -0
- package/dist/{defineConfig-Bz5OdPiM.d.ts → defineConfig-CRrw41YI.d.ts} +2 -3
- package/dist/{defineConfig-D01AIFC1.js → defineConfig-kpNEikuG.js} +6 -9
- package/dist/defineConfig-kpNEikuG.js.map +1 -0
- package/dist/esbuild.cjs +4 -0
- package/dist/esbuild.d.ts +2 -0
- package/dist/esbuild.js +2 -0
- package/dist/farm.cjs +4 -0
- package/dist/farm.d.ts +2 -0
- package/dist/farm.js +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +4 -0
- package/dist/nuxt.d.ts +2 -0
- package/dist/nuxt.js +2 -0
- package/dist/rolldown-runtime-Bx3C2hgW.cjs +38 -0
- package/dist/rolldown.cjs +4 -0
- package/dist/rolldown.d.ts +2 -0
- package/dist/rolldown.js +2 -0
- package/dist/rollup.cjs +4 -0
- package/dist/rollup.d.ts +2 -0
- package/dist/rollup.js +2 -0
- package/dist/rspack.cjs +4 -0
- package/dist/rspack.d.ts +2 -0
- package/dist/rspack.js +2 -0
- package/dist/vite.cjs +4 -0
- package/dist/vite.d.ts +2 -0
- package/dist/vite.js +2 -0
- package/dist/webpack.cjs +4 -0
- package/dist/webpack.d.ts +2 -0
- package/dist/webpack.js +2 -0
- package/package.json +56 -11
- package/dist/defineConfig-BXme6pNF.cjs.map +0 -1
- package/dist/defineConfig-D01AIFC1.js.map +0 -1
package/README.md
CHANGED
|
@@ -61,7 +61,7 @@ See the [documentation](https://kubb.dev) for detailed usage and advanced featur
|
|
|
61
61
|
- Read OpenAPI 2.0, 3.0, and 3.1 through adapters like [`@kubb/adapter-oas`](https://npmx.dev/package/@kubb/adapter-oas), with output for Node.js and Bun.
|
|
62
62
|
- Enable only the [plugins](https://github.com/kubb-labs/plugins) you need: `plugin-ts`, `plugin-axios`, `plugin-fetch`, `plugin-react-query`, `plugin-vue-query`, `plugin-swr`, `plugin-zod`, `plugin-faker`, `plugin-msw`, `plugin-cypress`, `plugin-redoc`, `plugin-mcp`.
|
|
63
63
|
- Shape the output by grouping files by tag, including or excluding operations, and writing to disk, memory, or a custom storage backend.
|
|
64
|
-
- Build your own
|
|
64
|
+
- Build your own plugins, generators, adapters, and renderers with the [`kubb/kit`](https://kubb.dev/docs/5.x/reference/kit) authoring toolkit, plus a JSX renderer for component-based output.
|
|
65
65
|
- Run generation in your bundler with `unplugin-kubb` for [Vite](https://github.com/vitejs/vite), [Nuxt](https://github.com/nuxt/nuxt), [Astro](https://github.com/withastro/astro), [webpack](https://github.com/webpack/webpack), and more.
|
|
66
66
|
- Drive generation from AI tools over the built-in MCP server ([Claude](https://claude.ai), [Cursor](https://cursor.sh)) or inside [Claude Code](https://kubb.dev/docs/5.x/ai/claude).
|
|
67
67
|
|
package/dist/astro.cjs
ADDED
package/dist/astro.d.ts
ADDED
package/dist/astro.js
ADDED
package/dist/config.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_defineConfig = require("./defineConfig-
|
|
2
|
+
const require_defineConfig = require("./defineConfig-BOa6m75p.cjs");
|
|
3
3
|
exports.defineConfig = require_defineConfig.defineConfig;
|
package/dist/config.d.ts
CHANGED
package/dist/config.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as defineConfig } from "./defineConfig-
|
|
1
|
+
import { t as defineConfig } from "./defineConfig-kpNEikuG.js";
|
|
2
2
|
export { defineConfig };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
require("./rolldown-runtime-Bx3C2hgW.cjs");
|
|
2
2
|
let _kubb_core = require("@kubb/core");
|
|
3
3
|
let _kubb_adapter_oas = require("@kubb/adapter-oas");
|
|
4
4
|
let _kubb_plugin_barrel = require("@kubb/plugin-barrel");
|
|
@@ -26,18 +26,16 @@ function isPromise(result) {
|
|
|
26
26
|
* - `parsers` defaults to `[parserTs, parserTsx, parserMd]`
|
|
27
27
|
* - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`
|
|
28
28
|
* - `plugins` gets `pluginBarrel()` appended when none is already present
|
|
29
|
-
* - `output.barrel` defaults to `{ type: 'named' }`
|
|
30
|
-
* When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.
|
|
29
|
+
* - `output.barrel` defaults to `{ type: 'named' }` when not set (`pluginBarrel` is always present after the step above)
|
|
31
30
|
* - `output.format` defaults to `false`
|
|
32
31
|
* - `output.lint` defaults to `false`
|
|
33
32
|
*/
|
|
34
33
|
function applyDefaults(config) {
|
|
35
34
|
const plugins = config.plugins?.some((p) => p.name === _kubb_plugin_barrel.pluginBarrelName) ? config.plugins ?? [] : [...config.plugins ?? [], (0, _kubb_plugin_barrel.pluginBarrel)()];
|
|
36
|
-
const hasBarrelPlugin = plugins.some((p) => p.name === _kubb_plugin_barrel.pluginBarrelName);
|
|
37
35
|
const output = { ...config.output };
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
output.barrel ??= { type: "named" };
|
|
37
|
+
output.format ??= false;
|
|
38
|
+
output.lint ??= false;
|
|
41
39
|
return {
|
|
42
40
|
...config,
|
|
43
41
|
root: config.root || process.cwd(),
|
|
@@ -68,8 +66,7 @@ function normalizeConfig(config) {
|
|
|
68
66
|
* - `parsers` → `[parserTs, parserTsx, parserMd]`.
|
|
69
67
|
* - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
|
|
70
68
|
* - `plugins` → `pluginBarrel()` is appended when not already present.
|
|
71
|
-
* - `output.barrel` → `{ type: 'named' }`
|
|
72
|
-
* in the plugins list.
|
|
69
|
+
* - `output.barrel` → `{ type: 'named' }` when not set.
|
|
73
70
|
* - `output.format` and `output.lint` → `false`.
|
|
74
71
|
*
|
|
75
72
|
* Accepts a config object, an array of configs, a Promise resolving to one,
|
|
@@ -114,4 +111,4 @@ Object.defineProperty(exports, "defineConfig", {
|
|
|
114
111
|
}
|
|
115
112
|
});
|
|
116
113
|
|
|
117
|
-
//# sourceMappingURL=defineConfig-
|
|
114
|
+
//# sourceMappingURL=defineConfig-BOa6m75p.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineConfig-BOa6m75p.cjs","names":["pluginBarrelName","parserTs","parserTsx","parserMd","cliReporter","jsonReporter","fileReporter"],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["import { toError } from './errors.ts'\n\n/** 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\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\ntype SerialRunnerOptions = {\n /**\n * The async work to serialize.\n */\n run(): Promise<void>\n /**\n * Receives errors thrown by `run`, so a failure never rejects the returned trigger.\n */\n onError(error: Error): void\n}\n\n/**\n * Wraps `run` so invocations never overlap: a trigger that lands while a run is in flight\n * marks it dirty and runs once more after it finishes, no matter how many triggers arrived.\n * Useful for event-driven reruns (a file watcher, a queue drain) where bursts should\n * coalesce into a single trailing run.\n *\n * @example\n * ```ts\n * const rebuild = createSerialRunner({\n * run: () => build(),\n * onError: (error) => log.error(error.message),\n * })\n * watcher.on('change', () => void rebuild())\n * ```\n */\nexport function createSerialRunner({ run, onError }: SerialRunnerOptions): () => Promise<void> {\n let running = false\n let dirty = false\n\n return async (): Promise<void> => {\n if (running) {\n dirty = true\n return\n }\n running = true\n do {\n dirty = false\n try {\n await run()\n } catch (error) {\n onError(toError(error))\n }\n } while (dirty)\n running = false\n }\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport { cliReporter, type CLIOptions, fileReporter, jsonReporter, type UserConfig } from '@kubb/core'\nimport { pluginBarrel, pluginBarrelName } from '@kubb/plugin-barrel'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\nimport { parserMd } from '@kubb/parser-md'\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 `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.\n *\n * - `root` defaults to `process.cwd()`\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx, parserMd]`\n * - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`\n * - `plugins` gets `pluginBarrel()` appended when none is already present\n * - `output.barrel` defaults to `{ type: 'named' }` when not set (`pluginBarrel` is always present after the step above)\n * - `output.format` defaults to `false`\n * - `output.lint` defaults to `false`\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const alreadyHasBarrel = config.plugins?.some((p) => p.name === pluginBarrelName)\n const plugins = alreadyHasBarrel ? (config.plugins ?? []) : [...(config.plugins ?? []), pluginBarrel()]\n\n const output = { ...config.output }\n output.barrel ??= { type: 'named' }\n output.format ??= false\n output.lint ??= false\n\n return {\n ...config,\n root: config.root || process.cwd(),\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx, parserMd],\n reporters: config.reporters?.length ? config.reporters : [cliReporter, jsonReporter, fileReporter],\n plugins,\n output,\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 * Defines a Kubb build configuration and fills in defaults for any omitted fields.\n *\n * Defaults applied when omitted:\n * - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).\n * - `parsers` → `[parserTs, parserTsx, parserMd]`.\n * - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.\n * - `plugins` → `pluginBarrel()` is appended when not already present.\n * - `output.barrel` → `{ type: 'named' }` when not set.\n * - `output.format` and `output.lint` → `false`.\n *\n * Accepts a config object, an array of configs, a Promise resolving to one,\n * or a function that receives the parsed CLI options and returns any of the\n * above. The return type is preserved so async/array variants stay typed.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [pluginTs()],\n * })\n * ```\n *\n * @example Function form with CLI options\n * ```ts\n * import { defineConfig } from 'kubb'\n *\n * export default defineConfig(({ input }) => ({\n * input: { path: input ?? './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [],\n * }))\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":";;;;;;;;;;;;;;;AAqBA,SAAgB,UAAa,QAAkD;CAC7E,OAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;AAC3G;;;;;;;;;;;;;;;ACMA,SAAS,cAAsB,QAAgD;CAE7E,MAAM,UADmB,OAAO,SAAS,MAAM,MAAM,EAAE,SAASA,oBAAAA,gBAAgB,IAC5C,OAAO,WAAW,CAAC,IAAK,CAAC,GAAI,OAAO,WAAW,CAAC,IAAA,GAAA,oBAAA,aAAA,CAAiB,CAAC;CAEtG,MAAM,SAAS,EAAE,GAAG,OAAO,OAAO;CAClC,OAAO,WAAW,EAAE,MAAM,QAAQ;CAClC,OAAO,WAAW;CAClB,OAAO,SAAS;CAEhB,OAAO;EACL,GAAG;EACH,MAAM,OAAO,QAAQ,QAAQ,IAAI;EACjC,SAAS,OAAO,YAAA,GAAA,kBAAA,WAAA,CAAsB;EACtC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU;GAACC,gBAAAA;GAAUC,gBAAAA;GAAWC,gBAAAA;EAAQ;EACjF,WAAW,OAAO,WAAW,SAAS,OAAO,YAAY;GAACC,WAAAA;GAAaC,WAAAA;GAAcC,WAAAA;EAAY;EACjG;EACA;CACF;AACF;AAEA,SAAS,gBAAwB,QAAwG;CACvI,IAAI,MAAM,QAAQ,MAAM,GACtB,OAAO,OAAO,IAAI,aAAa;CAGjC,OAAO,cAAc,MAAM;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,aAA0C,QAAyC;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,OAAO,QAAoB;EACjC,OAAO,gBAAgB,MAAM,OAAO,GAAG,CAAC;CAC1C;CAGF,IAAI,UAAU,MAAM,GAClB,OAAO,OAAO,MAAM,aAAa,gBAAgB,QAAQ,CAAC;CAG5D,OAAO,gBAAgB,MAAM;AAC/B"}
|
|
@@ -26,8 +26,7 @@ type DefinedConfig<TConfig extends ConfigInput> = TConfig extends ((cli: CLIOpti
|
|
|
26
26
|
* - `parsers` → `[parserTs, parserTsx, parserMd]`.
|
|
27
27
|
* - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
|
|
28
28
|
* - `plugins` → `pluginBarrel()` is appended when not already present.
|
|
29
|
-
* - `output.barrel` → `{ type: 'named' }`
|
|
30
|
-
* in the plugins list.
|
|
29
|
+
* - `output.barrel` → `{ type: 'named' }` when not set.
|
|
31
30
|
* - `output.format` and `output.lint` → `false`.
|
|
32
31
|
*
|
|
33
32
|
* Accepts a config object, an array of configs, a Promise resolving to one,
|
|
@@ -60,4 +59,4 @@ type DefinedConfig<TConfig extends ConfigInput> = TConfig extends ((cli: CLIOpti
|
|
|
60
59
|
declare function defineConfig<TConfig extends ConfigInput>(config: TConfig): DefinedConfig<TConfig>;
|
|
61
60
|
//#endregion
|
|
62
61
|
export { defineConfig as t };
|
|
63
|
-
//# sourceMappingURL=defineConfig-
|
|
62
|
+
//# sourceMappingURL=defineConfig-CRrw41YI.d.ts.map
|
|
@@ -26,18 +26,16 @@ function isPromise(result) {
|
|
|
26
26
|
* - `parsers` defaults to `[parserTs, parserTsx, parserMd]`
|
|
27
27
|
* - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`
|
|
28
28
|
* - `plugins` gets `pluginBarrel()` appended when none is already present
|
|
29
|
-
* - `output.barrel` defaults to `{ type: 'named' }`
|
|
30
|
-
* When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.
|
|
29
|
+
* - `output.barrel` defaults to `{ type: 'named' }` when not set (`pluginBarrel` is always present after the step above)
|
|
31
30
|
* - `output.format` defaults to `false`
|
|
32
31
|
* - `output.lint` defaults to `false`
|
|
33
32
|
*/
|
|
34
33
|
function applyDefaults(config) {
|
|
35
34
|
const plugins = config.plugins?.some((p) => p.name === pluginBarrelName) ? config.plugins ?? [] : [...config.plugins ?? [], pluginBarrel()];
|
|
36
|
-
const hasBarrelPlugin = plugins.some((p) => p.name === pluginBarrelName);
|
|
37
35
|
const output = { ...config.output };
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
output.barrel ??= { type: "named" };
|
|
37
|
+
output.format ??= false;
|
|
38
|
+
output.lint ??= false;
|
|
41
39
|
return {
|
|
42
40
|
...config,
|
|
43
41
|
root: config.root || process.cwd(),
|
|
@@ -68,8 +66,7 @@ function normalizeConfig(config) {
|
|
|
68
66
|
* - `parsers` → `[parserTs, parserTsx, parserMd]`.
|
|
69
67
|
* - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
|
|
70
68
|
* - `plugins` → `pluginBarrel()` is appended when not already present.
|
|
71
|
-
* - `output.barrel` → `{ type: 'named' }`
|
|
72
|
-
* in the plugins list.
|
|
69
|
+
* - `output.barrel` → `{ type: 'named' }` when not set.
|
|
73
70
|
* - `output.format` and `output.lint` → `false`.
|
|
74
71
|
*
|
|
75
72
|
* Accepts a config object, an array of configs, a Promise resolving to one,
|
|
@@ -109,4 +106,4 @@ function defineConfig(config) {
|
|
|
109
106
|
//#endregion
|
|
110
107
|
export { defineConfig as t };
|
|
111
108
|
|
|
112
|
-
//# sourceMappingURL=defineConfig-
|
|
109
|
+
//# sourceMappingURL=defineConfig-kpNEikuG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineConfig-kpNEikuG.js","names":[],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["import { toError } from './errors.ts'\n\n/** 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\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\ntype SerialRunnerOptions = {\n /**\n * The async work to serialize.\n */\n run(): Promise<void>\n /**\n * Receives errors thrown by `run`, so a failure never rejects the returned trigger.\n */\n onError(error: Error): void\n}\n\n/**\n * Wraps `run` so invocations never overlap: a trigger that lands while a run is in flight\n * marks it dirty and runs once more after it finishes, no matter how many triggers arrived.\n * Useful for event-driven reruns (a file watcher, a queue drain) where bursts should\n * coalesce into a single trailing run.\n *\n * @example\n * ```ts\n * const rebuild = createSerialRunner({\n * run: () => build(),\n * onError: (error) => log.error(error.message),\n * })\n * watcher.on('change', () => void rebuild())\n * ```\n */\nexport function createSerialRunner({ run, onError }: SerialRunnerOptions): () => Promise<void> {\n let running = false\n let dirty = false\n\n return async (): Promise<void> => {\n if (running) {\n dirty = true\n return\n }\n running = true\n do {\n dirty = false\n try {\n await run()\n } catch (error) {\n onError(toError(error))\n }\n } while (dirty)\n running = false\n }\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport { cliReporter, type CLIOptions, fileReporter, jsonReporter, type UserConfig } from '@kubb/core'\nimport { pluginBarrel, pluginBarrelName } from '@kubb/plugin-barrel'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\nimport { parserMd } from '@kubb/parser-md'\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 `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.\n *\n * - `root` defaults to `process.cwd()`\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx, parserMd]`\n * - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`\n * - `plugins` gets `pluginBarrel()` appended when none is already present\n * - `output.barrel` defaults to `{ type: 'named' }` when not set (`pluginBarrel` is always present after the step above)\n * - `output.format` defaults to `false`\n * - `output.lint` defaults to `false`\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const alreadyHasBarrel = config.plugins?.some((p) => p.name === pluginBarrelName)\n const plugins = alreadyHasBarrel ? (config.plugins ?? []) : [...(config.plugins ?? []), pluginBarrel()]\n\n const output = { ...config.output }\n output.barrel ??= { type: 'named' }\n output.format ??= false\n output.lint ??= false\n\n return {\n ...config,\n root: config.root || process.cwd(),\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx, parserMd],\n reporters: config.reporters?.length ? config.reporters : [cliReporter, jsonReporter, fileReporter],\n plugins,\n output,\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 * Defines a Kubb build configuration and fills in defaults for any omitted fields.\n *\n * Defaults applied when omitted:\n * - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).\n * - `parsers` → `[parserTs, parserTsx, parserMd]`.\n * - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.\n * - `plugins` → `pluginBarrel()` is appended when not already present.\n * - `output.barrel` → `{ type: 'named' }` when not set.\n * - `output.format` and `output.lint` → `false`.\n *\n * Accepts a config object, an array of configs, a Promise resolving to one,\n * or a function that receives the parsed CLI options and returns any of the\n * above. The return type is preserved so async/array variants stay typed.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [pluginTs()],\n * })\n * ```\n *\n * @example Function form with CLI options\n * ```ts\n * import { defineConfig } from 'kubb'\n *\n * export default defineConfig(({ input }) => ({\n * input: { path: input ?? './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [],\n * }))\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":";;;;;;;;;;;;;;;AAqBA,SAAgB,UAAa,QAAkD;CAC7E,OAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;AAC3G;;;;;;;;;;;;;;;ACMA,SAAS,cAAsB,QAAgD;CAE7E,MAAM,UADmB,OAAO,SAAS,MAAM,MAAM,EAAE,SAAS,gBAAgB,IAC5C,OAAO,WAAW,CAAC,IAAK,CAAC,GAAI,OAAO,WAAW,CAAC,GAAI,aAAa,CAAC;CAEtG,MAAM,SAAS,EAAE,GAAG,OAAO,OAAO;CAClC,OAAO,WAAW,EAAE,MAAM,QAAQ;CAClC,OAAO,WAAW;CAClB,OAAO,SAAS;CAEhB,OAAO;EACL,GAAG;EACH,MAAM,OAAO,QAAQ,QAAQ,IAAI;EACjC,SAAS,OAAO,WAAW,WAAW;EACtC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU;GAAC;GAAU;GAAW;EAAQ;EACjF,WAAW,OAAO,WAAW,SAAS,OAAO,YAAY;GAAC;GAAa;GAAc;EAAY;EACjG;EACA;CACF;AACF;AAEA,SAAS,gBAAwB,QAAwG;CACvI,IAAI,MAAM,QAAQ,MAAM,GACtB,OAAO,OAAO,IAAI,aAAa;CAGjC,OAAO,cAAc,MAAM;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,aAA0C,QAAyC;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,OAAO,QAAoB;EACjC,OAAO,gBAAgB,MAAM,OAAO,GAAG,CAAC;CAC1C;CAGF,IAAI,UAAU,MAAM,GAClB,OAAO,OAAO,MAAM,aAAa,gBAAgB,QAAQ,CAAC;CAG5D,OAAO,gBAAgB,MAAM;AAC/B"}
|
package/dist/esbuild.cjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-Bx3C2hgW.cjs");
|
|
2
|
+
let unplugin_kubb_esbuild = require("unplugin-kubb/esbuild");
|
|
3
|
+
unplugin_kubb_esbuild = require_rolldown_runtime.__toESM(unplugin_kubb_esbuild, 1);
|
|
4
|
+
module.exports = unplugin_kubb_esbuild.default;
|
package/dist/esbuild.js
ADDED
package/dist/farm.cjs
ADDED
package/dist/farm.d.ts
ADDED
package/dist/farm.js
ADDED
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_defineConfig = require("./defineConfig-
|
|
2
|
+
const require_defineConfig = require("./defineConfig-BOa6m75p.cjs");
|
|
3
3
|
let _kubb_core = require("@kubb/core");
|
|
4
4
|
Object.defineProperty(exports, "createKubb", {
|
|
5
5
|
enumerable: true,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as defineConfig } from "./defineConfig-
|
|
1
|
+
import { t as defineConfig } from "./defineConfig-CRrw41YI.js";
|
|
2
2
|
import { BuildOutput, Config, CreateKubbOptions, Kubb, UserConfig, createKubb } from "@kubb/core";
|
|
3
3
|
import { BarrelType } from "@kubb/plugin-barrel";
|
|
4
4
|
export { type BarrelType, type BuildOutput, type Config, type CreateKubbOptions, type Kubb, type UserConfig, createKubb, defineConfig };
|
package/dist/index.js
CHANGED
package/dist/nuxt.cjs
ADDED
package/dist/nuxt.d.ts
ADDED
package/dist/nuxt.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", {
|
|
5
|
+
value,
|
|
6
|
+
configurable: true
|
|
7
|
+
});
|
|
8
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
14
|
+
key = keys[i];
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: ((k) => from[k]).bind(null, key),
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
//#endregion
|
|
27
|
+
Object.defineProperty(exports, "__name", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function() {
|
|
30
|
+
return __name;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(exports, "__toESM", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function() {
|
|
36
|
+
return __toESM;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-Bx3C2hgW.cjs");
|
|
2
|
+
let unplugin_kubb_rolldown = require("unplugin-kubb/rolldown");
|
|
3
|
+
unplugin_kubb_rolldown = require_rolldown_runtime.__toESM(unplugin_kubb_rolldown, 1);
|
|
4
|
+
module.exports = unplugin_kubb_rolldown.default;
|
package/dist/rolldown.js
ADDED
package/dist/rollup.cjs
ADDED
package/dist/rollup.d.ts
ADDED
package/dist/rollup.js
ADDED
package/dist/rspack.cjs
ADDED
package/dist/rspack.d.ts
ADDED
package/dist/rspack.js
ADDED
package/dist/vite.cjs
ADDED
package/dist/vite.d.ts
ADDED
package/dist/vite.js
ADDED
package/dist/webpack.cjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-Bx3C2hgW.cjs");
|
|
2
|
+
let unplugin_kubb_webpack = require("unplugin-kubb/webpack");
|
|
3
|
+
unplugin_kubb_webpack = require_rolldown_runtime.__toESM(unplugin_kubb_webpack, 1);
|
|
4
|
+
module.exports = unplugin_kubb_webpack.default;
|
package/dist/webpack.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kubb",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.86",
|
|
4
4
|
"description": "The meta framework for code generation. Point Kubb at a schema and it generates types, clients, hooks, validators, mocks, and more.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-client",
|
|
@@ -42,10 +42,22 @@
|
|
|
42
42
|
"import": "./dist/index.js",
|
|
43
43
|
"require": "./dist/index.cjs"
|
|
44
44
|
},
|
|
45
|
+
"./astro": {
|
|
46
|
+
"import": "./dist/astro.js",
|
|
47
|
+
"require": "./dist/astro.cjs"
|
|
48
|
+
},
|
|
45
49
|
"./config": {
|
|
46
50
|
"import": "./dist/config.js",
|
|
47
51
|
"require": "./dist/config.cjs"
|
|
48
52
|
},
|
|
53
|
+
"./esbuild": {
|
|
54
|
+
"import": "./dist/esbuild.js",
|
|
55
|
+
"require": "./dist/esbuild.cjs"
|
|
56
|
+
},
|
|
57
|
+
"./farm": {
|
|
58
|
+
"import": "./dist/farm.js",
|
|
59
|
+
"require": "./dist/farm.cjs"
|
|
60
|
+
},
|
|
49
61
|
"./jsx": {
|
|
50
62
|
"import": "./dist/jsx.js",
|
|
51
63
|
"require": "./dist/jsx.cjs"
|
|
@@ -66,6 +78,30 @@
|
|
|
66
78
|
"import": "./dist/kit/testing.js",
|
|
67
79
|
"require": "./dist/kit/testing.cjs"
|
|
68
80
|
},
|
|
81
|
+
"./nuxt": {
|
|
82
|
+
"import": "./dist/nuxt.js",
|
|
83
|
+
"require": "./dist/nuxt.cjs"
|
|
84
|
+
},
|
|
85
|
+
"./rolldown": {
|
|
86
|
+
"import": "./dist/rolldown.js",
|
|
87
|
+
"require": "./dist/rolldown.cjs"
|
|
88
|
+
},
|
|
89
|
+
"./rollup": {
|
|
90
|
+
"import": "./dist/rollup.js",
|
|
91
|
+
"require": "./dist/rollup.cjs"
|
|
92
|
+
},
|
|
93
|
+
"./rspack": {
|
|
94
|
+
"import": "./dist/rspack.js",
|
|
95
|
+
"require": "./dist/rspack.cjs"
|
|
96
|
+
},
|
|
97
|
+
"./vite": {
|
|
98
|
+
"import": "./dist/vite.js",
|
|
99
|
+
"require": "./dist/vite.cjs"
|
|
100
|
+
},
|
|
101
|
+
"./webpack": {
|
|
102
|
+
"import": "./dist/webpack.js",
|
|
103
|
+
"require": "./dist/webpack.cjs"
|
|
104
|
+
},
|
|
69
105
|
"./package.json": "./package.json"
|
|
70
106
|
},
|
|
71
107
|
"publishConfig": {
|
|
@@ -73,19 +109,28 @@
|
|
|
73
109
|
"registry": "https://registry.npmjs.org/"
|
|
74
110
|
},
|
|
75
111
|
"dependencies": {
|
|
76
|
-
"@kubb/
|
|
77
|
-
"@kubb/
|
|
78
|
-
"@kubb/
|
|
79
|
-
"@kubb/
|
|
80
|
-
"@kubb/
|
|
81
|
-
"@kubb/parser-ts": "5.0.0-beta.
|
|
82
|
-
"@kubb/
|
|
83
|
-
"@kubb/
|
|
84
|
-
"@kubb/
|
|
85
|
-
"@kubb/
|
|
112
|
+
"@kubb/ast": "5.0.0-beta.86",
|
|
113
|
+
"@kubb/adapter-oas": "5.0.0-beta.86",
|
|
114
|
+
"@kubb/cli": "5.0.0-beta.86",
|
|
115
|
+
"@kubb/core": "5.0.0-beta.86",
|
|
116
|
+
"@kubb/mcp": "5.0.0-beta.86",
|
|
117
|
+
"@kubb/parser-ts": "5.0.0-beta.86",
|
|
118
|
+
"@kubb/parser-md": "5.0.0-beta.86",
|
|
119
|
+
"@kubb/kit": "5.0.0-beta.86",
|
|
120
|
+
"@kubb/renderer-jsx": "5.0.0-beta.86",
|
|
121
|
+
"@kubb/plugin-barrel": "5.0.0-beta.86",
|
|
122
|
+
"unplugin-kubb": "5.0.0-beta.86"
|
|
86
123
|
},
|
|
87
124
|
"devDependencies": {
|
|
125
|
+
"@farmfe/core": "^1.7.11",
|
|
126
|
+
"@nuxt/kit": "^4.4.8",
|
|
127
|
+
"@nuxt/schema": "^4.4.8",
|
|
128
|
+
"esbuild": "^0.28.1",
|
|
129
|
+
"rolldown": "^1.1.4",
|
|
130
|
+
"rollup": "^4.62.2",
|
|
88
131
|
"typescript": "^6.0.3",
|
|
132
|
+
"vite": "^8.1.3",
|
|
133
|
+
"webpack": "^5.108.3",
|
|
89
134
|
"@internals/utils": "0.0.0"
|
|
90
135
|
},
|
|
91
136
|
"preferGlobal": true,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defineConfig-BXme6pNF.cjs","names":["pluginBarrelName","parserTs","parserTsx","parserMd","cliReporter","jsonReporter","fileReporter"],"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\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Container that switches between an eager `Array<T>` and a lazy `AsyncIterable<T>`.\n *\n * `Array<T>` by default. With `Stream` set to `true` it becomes `AsyncIterable<T>`, so large\n * collections can be produced lazily without holding every item in memory. Pairs with\n * {@link arrayToAsyncIterable}, which lifts a plain array into the streaming form.\n *\n * @example\n * ```ts\n * type Eager = Streamable<number> // Array<number>\n * type Lazy = Streamable<number, true> // AsyncIterable<number>\n * ```\n */\nexport type Streamable<T, Stream extends boolean = false> = Stream extends true ? AsyncIterable<T> : Array<T>\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: ReadonlyArray<T>): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport { cliReporter, type CLIOptions, fileReporter, jsonReporter, type UserConfig } from '@kubb/core'\nimport { pluginBarrel, pluginBarrelName } from '@kubb/plugin-barrel'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\nimport { parserMd } from '@kubb/parser-md'\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 `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.\n *\n * - `root` defaults to `process.cwd()`\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx, parserMd]`\n * - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`\n * - `plugins` gets `pluginBarrel()` appended when none is already present\n * - `output.barrel` defaults to `{ type: 'named' }` only when `pluginBarrel` is part of `plugins`.\n * When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.\n * - `output.format` defaults to `false`\n * - `output.lint` defaults to `false`\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const alreadyHasBarrel = config.plugins?.some((p) => p.name === pluginBarrelName)\n const plugins = alreadyHasBarrel ? (config.plugins ?? []) : [...(config.plugins ?? []), pluginBarrel()]\n const hasBarrelPlugin = plugins.some((p) => p.name === pluginBarrelName)\n\n const output = { ...config.output }\n if (hasBarrelPlugin && output.barrel === undefined) {\n output.barrel = { type: 'named' }\n }\n if (output.format === undefined) {\n output.format = false\n }\n if (output.lint === undefined) {\n output.lint = false\n }\n\n return {\n ...config,\n root: config.root || process.cwd(),\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx, parserMd],\n reporters: config.reporters?.length ? config.reporters : [cliReporter, jsonReporter, fileReporter],\n plugins,\n output,\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 * Defines a Kubb build configuration and fills in defaults for any omitted fields.\n *\n * Defaults applied when omitted:\n * - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).\n * - `parsers` → `[parserTs, parserTsx, parserMd]`.\n * - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.\n * - `plugins` → `pluginBarrel()` is appended when not already present.\n * - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is\n * in the plugins list.\n * - `output.format` and `output.lint` → `false`.\n *\n * Accepts a config object, an array of configs, a Promise resolving to one,\n * or a function that receives the parsed CLI options and returns any of the\n * above. The return type is preserved so async/array variants stay typed.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [pluginTs()],\n * })\n * ```\n *\n * @example Function form with CLI options\n * ```ts\n * import { defineConfig } from 'kubb'\n *\n * export default defineConfig(({ input }) => ({\n * input: { path: input ?? './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [],\n * }))\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;CAC7E,OAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;AAC3G;;;;;;;;;;;;;;;;ACSA,SAAS,cAAsB,QAAgD;CAE7E,MAAM,UADmB,OAAO,SAAS,MAAM,MAAM,EAAE,SAASA,oBAAAA,gBAAgB,IAC5C,OAAO,WAAW,CAAC,IAAK,CAAC,GAAI,OAAO,WAAW,CAAC,IAAA,GAAA,oBAAA,aAAA,CAAiB,CAAC;CACtG,MAAM,kBAAkB,QAAQ,MAAM,MAAM,EAAE,SAASA,oBAAAA,gBAAgB;CAEvE,MAAM,SAAS,EAAE,GAAG,OAAO,OAAO;CAClC,IAAI,mBAAmB,OAAO,WAAW,KAAA,GACvC,OAAO,SAAS,EAAE,MAAM,QAAQ;CAElC,IAAI,OAAO,WAAW,KAAA,GACpB,OAAO,SAAS;CAElB,IAAI,OAAO,SAAS,KAAA,GAClB,OAAO,OAAO;CAGhB,OAAO;EACL,GAAG;EACH,MAAM,OAAO,QAAQ,QAAQ,IAAI;EACjC,SAAS,OAAO,YAAA,GAAA,kBAAA,WAAA,CAAsB;EACtC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU;GAACC,gBAAAA;GAAUC,gBAAAA;GAAWC,gBAAAA;EAAQ;EACjF,WAAW,OAAO,WAAW,SAAS,OAAO,YAAY;GAACC,WAAAA;GAAaC,WAAAA;GAAcC,WAAAA;EAAY;EACjG;EACA;CACF;AACF;AAEA,SAAS,gBAAwB,QAAwG;CACvI,IAAI,MAAM,QAAQ,MAAM,GACtB,OAAO,OAAO,IAAI,aAAa;CAGjC,OAAO,cAAc,MAAM;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,aAA0C,QAAyC;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,OAAO,QAAoB;EACjC,OAAO,gBAAgB,MAAM,OAAO,GAAG,CAAC;CAC1C;CAGF,IAAI,UAAU,MAAM,GAClB,OAAO,OAAO,MAAM,aAAa,gBAAgB,QAAQ,CAAC;CAG5D,OAAO,gBAAgB,MAAM;AAC/B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defineConfig-D01AIFC1.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\ntype Store<TKey, TValue> = {\n has(key: TKey): boolean\n get(key: TKey): TValue | undefined\n set(key: TKey, value: TValue): unknown\n}\n\n/**\n * Wraps `factory` with a keyed cache backed by the provided store.\n *\n * Pass a `WeakMap` for object keys (results are GC-eligible when the key is\n * collected) or a `Map` for primitive keys. For multi-argument functions,\n * nest two `memoize` calls — the outer keyed by the first argument, the\n * inner (created once per outer miss) keyed by the second.\n *\n * Because the cache is owned by the caller, it can be shared, inspected, or\n * cleared independently of the memoized function.\n *\n * @example Single WeakMap key\n * ```ts\n * const cache = new WeakMap<SchemaNode, Set<string>>()\n * const getRefs = memoize(cache, (node) => collectRefs(node))\n * ```\n *\n * @example Single Map key (primitive)\n * ```ts\n * const cache = new Map<string, Resolver>()\n * const getResolver = memoize(cache, (name) => buildResolver(name))\n * ```\n *\n * @example Two-level (object + primitive)\n * ```ts\n * const outer = new WeakMap<Params[], Map<string, Params[]>>()\n * const fn = memoize(outer, (params) => memoize(new Map(), (key) => transform(params, key)))\n * fn(params)('camelcase')\n * ```\n */\nexport function memoize<TKey, TValue>(store: Store<TKey, TValue>, factory: (key: TKey) => TValue): (key: TKey) => TValue {\n return (key: TKey): TValue => {\n if (store.has(key)) return store.get(key)!\n const value = factory(key)\n store.set(key, value)\n return value\n }\n}\n\n/**\n * Container that switches between an eager `Array<T>` and a lazy `AsyncIterable<T>`.\n *\n * `Array<T>` by default. With `Stream` set to `true` it becomes `AsyncIterable<T>`, so large\n * collections can be produced lazily without holding every item in memory. Pairs with\n * {@link arrayToAsyncIterable}, which lifts a plain array into the streaming form.\n *\n * @example\n * ```ts\n * type Eager = Streamable<number> // Array<number>\n * type Lazy = Streamable<number, true> // AsyncIterable<number>\n * ```\n */\nexport type Streamable<T, Stream extends boolean = false> = Stream extends true ? AsyncIterable<T> : Array<T>\n\n/**\n * Wraps a plain array in a reusable `AsyncIterable`.\n * Each `[Symbol.asyncIterator]()` call returns a fresh generator so the\n * iterable can be consumed multiple times (e.g. once per plugin pre-scan).\n *\n * @example\n * ```ts\n * const stream = arrayToAsyncIterable([1, 2, 3])\n * for await (const n of stream) console.log(n) // 1, 2, 3\n * ```\n */\nexport function arrayToAsyncIterable<T>(arr: ReadonlyArray<T>): AsyncIterable<T> {\n return {\n [Symbol.asyncIterator]() {\n return (async function* () {\n yield* arr\n })()\n },\n }\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport { cliReporter, type CLIOptions, fileReporter, jsonReporter, type UserConfig } from '@kubb/core'\nimport { pluginBarrel, pluginBarrelName } from '@kubb/plugin-barrel'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\nimport { parserMd } from '@kubb/parser-md'\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 `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.\n *\n * - `root` defaults to `process.cwd()`\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx, parserMd]`\n * - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`\n * - `plugins` gets `pluginBarrel()` appended when none is already present\n * - `output.barrel` defaults to `{ type: 'named' }` only when `pluginBarrel` is part of `plugins`.\n * When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.\n * - `output.format` defaults to `false`\n * - `output.lint` defaults to `false`\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const alreadyHasBarrel = config.plugins?.some((p) => p.name === pluginBarrelName)\n const plugins = alreadyHasBarrel ? (config.plugins ?? []) : [...(config.plugins ?? []), pluginBarrel()]\n const hasBarrelPlugin = plugins.some((p) => p.name === pluginBarrelName)\n\n const output = { ...config.output }\n if (hasBarrelPlugin && output.barrel === undefined) {\n output.barrel = { type: 'named' }\n }\n if (output.format === undefined) {\n output.format = false\n }\n if (output.lint === undefined) {\n output.lint = false\n }\n\n return {\n ...config,\n root: config.root || process.cwd(),\n adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx, parserMd],\n reporters: config.reporters?.length ? config.reporters : [cliReporter, jsonReporter, fileReporter],\n plugins,\n output,\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 * Defines a Kubb build configuration and fills in defaults for any omitted fields.\n *\n * Defaults applied when omitted:\n * - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).\n * - `parsers` → `[parserTs, parserTsx, parserMd]`.\n * - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.\n * - `plugins` → `pluginBarrel()` is appended when not already present.\n * - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is\n * in the plugins list.\n * - `output.format` and `output.lint` → `false`.\n *\n * Accepts a config object, an array of configs, a Promise resolving to one,\n * or a function that receives the parsed CLI options and returns any of the\n * above. The return type is preserved so async/array variants stay typed.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { pluginTs } from '@kubb/plugin-ts'\n *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [pluginTs()],\n * })\n * ```\n *\n * @example Function form with CLI options\n * ```ts\n * import { defineConfig } from 'kubb'\n *\n * export default defineConfig(({ input }) => ({\n * input: { path: input ?? './petStore.yaml' },\n * output: { path: './src/gen' },\n * plugins: [],\n * }))\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;CAC7E,OAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;AAC3G;;;;;;;;;;;;;;;;ACSA,SAAS,cAAsB,QAAgD;CAE7E,MAAM,UADmB,OAAO,SAAS,MAAM,MAAM,EAAE,SAAS,gBAAgB,IAC5C,OAAO,WAAW,CAAC,IAAK,CAAC,GAAI,OAAO,WAAW,CAAC,GAAI,aAAa,CAAC;CACtG,MAAM,kBAAkB,QAAQ,MAAM,MAAM,EAAE,SAAS,gBAAgB;CAEvE,MAAM,SAAS,EAAE,GAAG,OAAO,OAAO;CAClC,IAAI,mBAAmB,OAAO,WAAW,KAAA,GACvC,OAAO,SAAS,EAAE,MAAM,QAAQ;CAElC,IAAI,OAAO,WAAW,KAAA,GACpB,OAAO,SAAS;CAElB,IAAI,OAAO,SAAS,KAAA,GAClB,OAAO,OAAO;CAGhB,OAAO;EACL,GAAG;EACH,MAAM,OAAO,QAAQ,QAAQ,IAAI;EACjC,SAAS,OAAO,WAAW,WAAW;EACtC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU;GAAC;GAAU;GAAW;EAAQ;EACjF,WAAW,OAAO,WAAW,SAAS,OAAO,YAAY;GAAC;GAAa;GAAc;EAAY;EACjG;EACA;CACF;AACF;AAEA,SAAS,gBAAwB,QAAwG;CACvI,IAAI,MAAM,QAAQ,MAAM,GACtB,OAAO,OAAO,IAAI,aAAa;CAGjC,OAAO,cAAc,MAAM;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,aAA0C,QAAyC;CACjG,IAAI,OAAO,WAAW,YACpB,QAAQ,OAAO,QAAoB;EACjC,OAAO,gBAAgB,MAAM,OAAO,GAAG,CAAC;CAC1C;CAGF,IAAI,UAAU,MAAM,GAClB,OAAO,OAAO,MAAM,aAAa,gBAAgB,QAAQ,CAAC;CAG5D,OAAO,gBAAgB,MAAM;AAC/B"}
|