kubb 5.0.0-beta.8 → 5.0.0-beta.81

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.
@@ -0,0 +1,112 @@
1
+ import "./rolldown-runtime-C0LytTxp.js";
2
+ import { adapterOas } from "@kubb/adapter-oas";
3
+ import { cliReporter, fileReporter, jsonReporter } from "@kubb/core";
4
+ import { pluginBarrel, pluginBarrelName } from "@kubb/plugin-barrel";
5
+ import { parserTs, parserTsx } from "@kubb/parser-ts";
6
+ import { parserMd } from "@kubb/parser-md";
7
+ //#region ../../internals/utils/src/promise.ts
8
+ /** Returns `true` when `result` is a thenable `Promise`.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * isPromise(Promise.resolve(1)) // true
13
+ * isPromise(42) // false
14
+ * ```
15
+ */
16
+ function isPromise(result) {
17
+ return result !== null && result !== void 0 && typeof result["then"] === "function";
18
+ }
19
+ //#endregion
20
+ //#region src/defineConfig.ts
21
+ /**
22
+ * Applies default `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
23
+ *
24
+ * - `root` defaults to `process.cwd()`
25
+ * - `adapter` defaults to `adapterOas()`
26
+ * - `parsers` defaults to `[parserTs, parserTsx, parserMd]`
27
+ * - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`
28
+ * - `plugins` gets `pluginBarrel()` appended when none is already present
29
+ * - `output.barrel` defaults to `{ type: 'named' }` only when `pluginBarrel` is part of `plugins`.
30
+ * When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.
31
+ * - `output.format` defaults to `false`
32
+ * - `output.lint` defaults to `false`
33
+ */
34
+ function applyDefaults(config) {
35
+ const plugins = config.plugins?.some((p) => p.name === pluginBarrelName) ? config.plugins ?? [] : [...config.plugins ?? [], pluginBarrel()];
36
+ const hasBarrelPlugin = plugins.some((p) => p.name === pluginBarrelName);
37
+ const output = { ...config.output };
38
+ if (hasBarrelPlugin && output.barrel === void 0) output.barrel = { type: "named" };
39
+ if (output.format === void 0) output.format = false;
40
+ if (output.lint === void 0) output.lint = false;
41
+ return {
42
+ ...config,
43
+ root: config.root || process.cwd(),
44
+ adapter: config.adapter ?? adapterOas(),
45
+ parsers: config.parsers?.length ? config.parsers : [
46
+ parserTs,
47
+ parserTsx,
48
+ parserMd
49
+ ],
50
+ reporters: config.reporters?.length ? config.reporters : [
51
+ cliReporter,
52
+ jsonReporter,
53
+ fileReporter
54
+ ],
55
+ plugins,
56
+ output
57
+ };
58
+ }
59
+ function normalizeConfig(config) {
60
+ if (Array.isArray(config)) return config.map(applyDefaults);
61
+ return applyDefaults(config);
62
+ }
63
+ /**
64
+ * Defines a Kubb build configuration and fills in defaults for any omitted fields.
65
+ *
66
+ * Defaults applied when omitted:
67
+ * - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
68
+ * - `parsers` → `[parserTs, parserTsx, parserMd]`.
69
+ * - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
70
+ * - `plugins` → `pluginBarrel()` is appended when not already present.
71
+ * - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is
72
+ * in the plugins list.
73
+ * - `output.format` and `output.lint` → `false`.
74
+ *
75
+ * Accepts a config object, an array of configs, a Promise resolving to one,
76
+ * or a function that receives the parsed CLI options and returns any of the
77
+ * above. The return type is preserved so async/array variants stay typed.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * import { defineConfig } from 'kubb'
82
+ * import { pluginTs } from '@kubb/plugin-ts'
83
+ *
84
+ * export default defineConfig({
85
+ * input: { path: './petStore.yaml' },
86
+ * output: { path: './src/gen' },
87
+ * plugins: [pluginTs()],
88
+ * })
89
+ * ```
90
+ *
91
+ * @example Function form with CLI options
92
+ * ```ts
93
+ * import { defineConfig } from 'kubb'
94
+ *
95
+ * export default defineConfig(({ input }) => ({
96
+ * input: { path: input ?? './petStore.yaml' },
97
+ * output: { path: './src/gen' },
98
+ * plugins: [],
99
+ * }))
100
+ * ```
101
+ */
102
+ function defineConfig(config) {
103
+ if (typeof config === "function") return (async (cli) => {
104
+ return normalizeConfig(await config(cli));
105
+ });
106
+ if (isPromise(config)) return config.then((resolved) => normalizeConfig(resolved));
107
+ return normalizeConfig(config);
108
+ }
109
+ //#endregion
110
+ export { defineConfig as t };
111
+
112
+ //# sourceMappingURL=defineConfig-DrauI0Xo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineConfig-DrauI0Xo.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"}
@@ -0,0 +1,117 @@
1
+ //#endregion
2
+ let _kubb_adapter_oas = require("@kubb/adapter-oas");
3
+ let _kubb_core = require("@kubb/core");
4
+ let _kubb_plugin_barrel = require("@kubb/plugin-barrel");
5
+ let _kubb_parser_ts = require("@kubb/parser-ts");
6
+ let _kubb_parser_md = require("@kubb/parser-md");
7
+ //#region ../../internals/utils/src/promise.ts
8
+ /** Returns `true` when `result` is a thenable `Promise`.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * isPromise(Promise.resolve(1)) // true
13
+ * isPromise(42) // false
14
+ * ```
15
+ */
16
+ function isPromise(result) {
17
+ return result !== null && result !== void 0 && typeof result["then"] === "function";
18
+ }
19
+ //#endregion
20
+ //#region src/defineConfig.ts
21
+ /**
22
+ * Applies default `root`, adapter, parsers, plugins, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
23
+ *
24
+ * - `root` defaults to `process.cwd()`
25
+ * - `adapter` defaults to `adapterOas()`
26
+ * - `parsers` defaults to `[parserTs, parserTsx, parserMd]`
27
+ * - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`
28
+ * - `plugins` gets `pluginBarrel()` appended when none is already present
29
+ * - `output.barrel` defaults to `{ type: 'named' }` only when `pluginBarrel` is part of `plugins`.
30
+ * When the user provides a plugins list without `pluginBarrel`, `barrel` is left untouched.
31
+ * - `output.format` defaults to `false`
32
+ * - `output.lint` defaults to `false`
33
+ */
34
+ function applyDefaults(config) {
35
+ 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
+ const output = { ...config.output };
38
+ if (hasBarrelPlugin && output.barrel === void 0) output.barrel = { type: "named" };
39
+ if (output.format === void 0) output.format = false;
40
+ if (output.lint === void 0) output.lint = false;
41
+ return {
42
+ ...config,
43
+ root: config.root || process.cwd(),
44
+ adapter: config.adapter ?? (0, _kubb_adapter_oas.adapterOas)(),
45
+ parsers: config.parsers?.length ? config.parsers : [
46
+ _kubb_parser_ts.parserTs,
47
+ _kubb_parser_ts.parserTsx,
48
+ _kubb_parser_md.parserMd
49
+ ],
50
+ reporters: config.reporters?.length ? config.reporters : [
51
+ _kubb_core.cliReporter,
52
+ _kubb_core.jsonReporter,
53
+ _kubb_core.fileReporter
54
+ ],
55
+ plugins,
56
+ output
57
+ };
58
+ }
59
+ function normalizeConfig(config) {
60
+ if (Array.isArray(config)) return config.map(applyDefaults);
61
+ return applyDefaults(config);
62
+ }
63
+ /**
64
+ * Defines a Kubb build configuration and fills in defaults for any omitted fields.
65
+ *
66
+ * Defaults applied when omitted:
67
+ * - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
68
+ * - `parsers` → `[parserTs, parserTsx, parserMd]`.
69
+ * - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
70
+ * - `plugins` → `pluginBarrel()` is appended when not already present.
71
+ * - `output.barrel` → `{ type: 'named' }` only when `pluginBarrel` is
72
+ * in the plugins list.
73
+ * - `output.format` and `output.lint` → `false`.
74
+ *
75
+ * Accepts a config object, an array of configs, a Promise resolving to one,
76
+ * or a function that receives the parsed CLI options and returns any of the
77
+ * above. The return type is preserved so async/array variants stay typed.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * import { defineConfig } from 'kubb'
82
+ * import { pluginTs } from '@kubb/plugin-ts'
83
+ *
84
+ * export default defineConfig({
85
+ * input: { path: './petStore.yaml' },
86
+ * output: { path: './src/gen' },
87
+ * plugins: [pluginTs()],
88
+ * })
89
+ * ```
90
+ *
91
+ * @example Function form with CLI options
92
+ * ```ts
93
+ * import { defineConfig } from 'kubb'
94
+ *
95
+ * export default defineConfig(({ input }) => ({
96
+ * input: { path: input ?? './petStore.yaml' },
97
+ * output: { path: './src/gen' },
98
+ * plugins: [],
99
+ * }))
100
+ * ```
101
+ */
102
+ function defineConfig(config) {
103
+ if (typeof config === "function") return (async (cli) => {
104
+ return normalizeConfig(await config(cli));
105
+ });
106
+ if (isPromise(config)) return config.then((resolved) => normalizeConfig(resolved));
107
+ return normalizeConfig(config);
108
+ }
109
+ //#endregion
110
+ Object.defineProperty(exports, "defineConfig", {
111
+ enumerable: true,
112
+ get: function() {
113
+ return defineConfig;
114
+ }
115
+ });
116
+
117
+ //# sourceMappingURL=defineConfig-T5v3Qrv-.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineConfig-T5v3Qrv-.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"}
package/dist/index.cjs CHANGED
@@ -1,79 +1,3 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#endregion
3
- let _kubb_adapter_oas = require("@kubb/adapter-oas");
4
- let _kubb_middleware_barrel = require("@kubb/middleware-barrel");
5
- let _kubb_parser_ts = require("@kubb/parser-ts");
6
- //#region ../../internals/utils/src/promise.ts
7
- /** Returns `true` when `result` is a thenable `Promise`.
8
- *
9
- * @example
10
- * ```ts
11
- * isPromise(Promise.resolve(1)) // true
12
- * isPromise(42) // false
13
- * ```
14
- */
15
- function isPromise(result) {
16
- return result !== null && result !== void 0 && typeof result["then"] === "function";
17
- }
18
- //#endregion
19
- //#region src/defineConfig.ts
20
- /**
21
- * Applies default adapter, parsers, middleware, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
22
- *
23
- * - `adapter` defaults to `adapterOas()`
24
- * - `parsers` defaults to `[parserTs, parserTsx]`
25
- * - `middleware` defaults to `[middlewareBarrel()]`
26
- * - `output.barrel` defaults to `{ type: 'named' }` **only when `middlewareBarrel` is part of `middleware`**.
27
- * When the user provides a custom middleware list without `middlewareBarrel`, `barrel` is left untouched.
28
- * - `output.format` defaults to `'auto'`
29
- * - `output.lint` defaults to `'auto'`
30
- */
31
- function applyDefaults(config) {
32
- const middleware = config.middleware?.length ? config.middleware : [(0, _kubb_middleware_barrel.middlewareBarrel)()];
33
- const hasBarrelMiddleware = middleware.some((m) => m.name === _kubb_middleware_barrel.middlewareBarrelName);
34
- const output = { ...config.output };
35
- if (hasBarrelMiddleware && output.barrel === void 0) output.barrel = { type: "named" };
36
- if (output.format === void 0) output.format = false;
37
- if (output.lint === void 0) output.lint = false;
38
- return {
39
- ...config,
40
- adapter: config.adapter ?? (0, _kubb_adapter_oas.adapterOas)(),
41
- parsers: config.parsers?.length ? config.parsers : [_kubb_parser_ts.parserTs, _kubb_parser_ts.parserTsx],
42
- middleware,
43
- output
44
- };
45
- }
46
- function normalizeConfig(config) {
47
- if (Array.isArray(config)) return config.map(applyDefaults);
48
- return applyDefaults(config);
49
- }
50
- /**
51
- * Helper for defining a Kubb configuration with built-in defaults.
52
- *
53
- * When no `adapter` is provided, `adapterOas()` is used automatically.
54
- * When no `parsers` are provided, `[parserTs, parserTsx]` is used automatically.
55
- *
56
- * Accepts either:
57
- * - A config object or array of configs
58
- * - A function returning the config(s), optionally async,
59
- * receiving the CLI options as argument
60
- *
61
- * @example
62
- * ```ts
63
- * export default defineConfig(({ logLevel }) => ({
64
- * root: 'src',
65
- * plugins: [myPlugin()],
66
- * }))
67
- * ```
68
- */
69
- function defineConfig(config) {
70
- if (typeof config === "function") return (async (cli) => {
71
- return normalizeConfig(await config(cli));
72
- });
73
- if (isPromise(config)) return config.then((resolved) => normalizeConfig(resolved));
74
- return normalizeConfig(config);
75
- }
76
- //#endregion
77
- exports.defineConfig = defineConfig;
78
-
79
- //# sourceMappingURL=index.cjs.map
2
+ const require_defineConfig = require("./defineConfig-T5v3Qrv-.cjs");
3
+ exports.defineConfig = require_defineConfig.defineConfig;
package/dist/index.d.ts CHANGED
@@ -1,44 +1,3 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { BarrelType } from "@kubb/middleware-barrel";
3
- import { CLIOptions, UserConfig } from "@kubb/core";
4
-
5
- //#region ../../internals/utils/src/promise.d.ts
6
- /** A value that may already be resolved or still pending.
7
- *
8
- * @example
9
- * ```ts
10
- * function load(id: string): PossiblePromise<string> {
11
- * return cache.get(id) ?? fetchRemote(id)
12
- * }
13
- * ```
14
- */
15
- type PossiblePromise<T> = Promise<T> | T;
16
- //#endregion
17
- //#region src/defineConfig.d.ts
18
- type AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>;
19
- type ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>);
20
- type NormalizeConfig<TConfig> = TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never;
21
- 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>;
22
- /**
23
- * Helper for defining a Kubb configuration with built-in defaults.
24
- *
25
- * When no `adapter` is provided, `adapterOas()` is used automatically.
26
- * When no `parsers` are provided, `[parserTs, parserTsx]` is used automatically.
27
- *
28
- * Accepts either:
29
- * - A config object or array of configs
30
- * - A function returning the config(s), optionally async,
31
- * receiving the CLI options as argument
32
- *
33
- * @example
34
- * ```ts
35
- * export default defineConfig(({ logLevel }) => ({
36
- * root: 'src',
37
- * plugins: [myPlugin()],
38
- * }))
39
- * ```
40
- */
41
- declare function defineConfig<TConfig extends ConfigInput>(config: TConfig): DefinedConfig<TConfig>;
42
- //#endregion
43
- export { type BarrelType, defineConfig };
44
- //# sourceMappingURL=index.d.ts.map
1
+ import { t as defineConfig } from "./defineConfig-Bz5OdPiM.js";
2
+ import { BarrelType } from "@kubb/plugin-barrel";
3
+ export { type BarrelType, defineConfig };
package/dist/index.js CHANGED
@@ -1,78 +1,2 @@
1
- import "./chunk--u3MIqq1.js";
2
- import { adapterOas } from "@kubb/adapter-oas";
3
- import { middlewareBarrel, middlewareBarrelName } from "@kubb/middleware-barrel";
4
- import { parserTs, parserTsx } from "@kubb/parser-ts";
5
- //#region ../../internals/utils/src/promise.ts
6
- /** Returns `true` when `result` is a thenable `Promise`.
7
- *
8
- * @example
9
- * ```ts
10
- * isPromise(Promise.resolve(1)) // true
11
- * isPromise(42) // false
12
- * ```
13
- */
14
- function isPromise(result) {
15
- return result !== null && result !== void 0 && typeof result["then"] === "function";
16
- }
17
- //#endregion
18
- //#region src/defineConfig.ts
19
- /**
20
- * Applies default adapter, parsers, middleware, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
21
- *
22
- * - `adapter` defaults to `adapterOas()`
23
- * - `parsers` defaults to `[parserTs, parserTsx]`
24
- * - `middleware` defaults to `[middlewareBarrel()]`
25
- * - `output.barrel` defaults to `{ type: 'named' }` **only when `middlewareBarrel` is part of `middleware`**.
26
- * When the user provides a custom middleware list without `middlewareBarrel`, `barrel` is left untouched.
27
- * - `output.format` defaults to `'auto'`
28
- * - `output.lint` defaults to `'auto'`
29
- */
30
- function applyDefaults(config) {
31
- const middleware = config.middleware?.length ? config.middleware : [middlewareBarrel()];
32
- const hasBarrelMiddleware = middleware.some((m) => m.name === middlewareBarrelName);
33
- const output = { ...config.output };
34
- if (hasBarrelMiddleware && output.barrel === void 0) output.barrel = { type: "named" };
35
- if (output.format === void 0) output.format = false;
36
- if (output.lint === void 0) output.lint = false;
37
- return {
38
- ...config,
39
- adapter: config.adapter ?? adapterOas(),
40
- parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx],
41
- middleware,
42
- output
43
- };
44
- }
45
- function normalizeConfig(config) {
46
- if (Array.isArray(config)) return config.map(applyDefaults);
47
- return applyDefaults(config);
48
- }
49
- /**
50
- * Helper for defining a Kubb configuration with built-in defaults.
51
- *
52
- * When no `adapter` is provided, `adapterOas()` is used automatically.
53
- * When no `parsers` are provided, `[parserTs, parserTsx]` is used automatically.
54
- *
55
- * Accepts either:
56
- * - A config object or array of configs
57
- * - A function returning the config(s), optionally async,
58
- * receiving the CLI options as argument
59
- *
60
- * @example
61
- * ```ts
62
- * export default defineConfig(({ logLevel }) => ({
63
- * root: 'src',
64
- * plugins: [myPlugin()],
65
- * }))
66
- * ```
67
- */
68
- function defineConfig(config) {
69
- if (typeof config === "function") return (async (cli) => {
70
- return normalizeConfig(await config(cli));
71
- });
72
- if (isPromise(config)) return config.then((resolved) => normalizeConfig(resolved));
73
- return normalizeConfig(config);
74
- }
75
- //#endregion
1
+ import { t as defineConfig } from "./defineConfig-DrauI0Xo.js";
76
2
  export { defineConfig };
77
-
78
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,9 @@
1
+ var _kubb_renderer_jsx_jsx_dev_runtime = require("@kubb/renderer-jsx/jsx-dev-runtime");
2
+ Object.keys(_kubb_renderer_jsx_jsx_dev_runtime).forEach(function(k) {
3
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
4
+ enumerable: true,
5
+ get: function() {
6
+ return _kubb_renderer_jsx_jsx_dev_runtime[k];
7
+ }
8
+ });
9
+ });
@@ -0,0 +1 @@
1
+ export * from "@kubb/renderer-jsx/jsx-dev-runtime";
@@ -0,0 +1,2 @@
1
+ export * from "@kubb/renderer-jsx/jsx-dev-runtime";
2
+ export {};
@@ -0,0 +1,9 @@
1
+ var _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
2
+ Object.keys(_kubb_renderer_jsx_jsx_runtime).forEach(function(k) {
3
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
4
+ enumerable: true,
5
+ get: function() {
6
+ return _kubb_renderer_jsx_jsx_runtime[k];
7
+ }
8
+ });
9
+ });
@@ -0,0 +1 @@
1
+ export * from "@kubb/renderer-jsx/jsx-runtime";
@@ -0,0 +1,2 @@
1
+ export * from "@kubb/renderer-jsx/jsx-runtime";
2
+ export {};
package/dist/jsx.cjs ADDED
@@ -0,0 +1,18 @@
1
+ var _kubb_renderer_jsx = require("@kubb/renderer-jsx");
2
+ Object.keys(_kubb_renderer_jsx).forEach(function(k) {
3
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
4
+ enumerable: true,
5
+ get: function() {
6
+ return _kubb_renderer_jsx[k];
7
+ }
8
+ });
9
+ });
10
+ var _kubb_renderer_jsx_types = require("@kubb/renderer-jsx/types");
11
+ Object.keys(_kubb_renderer_jsx_types).forEach(function(k) {
12
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
13
+ enumerable: true,
14
+ get: function() {
15
+ return _kubb_renderer_jsx_types[k];
16
+ }
17
+ });
18
+ });
package/dist/jsx.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "@kubb/renderer-jsx";
2
+ export * from "@kubb/renderer-jsx/types";
package/dist/jsx.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "@kubb/renderer-jsx";
2
+ export * from "@kubb/renderer-jsx/types";
3
+ export {};
@@ -0,0 +1,9 @@
1
+ var _kubb_kit_testing = require("@kubb/kit/testing");
2
+ Object.keys(_kubb_kit_testing).forEach(function(k) {
3
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
4
+ enumerable: true,
5
+ get: function() {
6
+ return _kubb_kit_testing[k];
7
+ }
8
+ });
9
+ });
@@ -0,0 +1 @@
1
+ export * from "@kubb/kit/testing";
@@ -0,0 +1,2 @@
1
+ export * from "@kubb/kit/testing";
2
+ export {};
package/dist/kit.cjs ADDED
@@ -0,0 +1,9 @@
1
+ var _kubb_kit = require("@kubb/kit");
2
+ Object.keys(_kubb_kit).forEach(function(k) {
3
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
4
+ enumerable: true,
5
+ get: function() {
6
+ return _kubb_kit[k];
7
+ }
8
+ });
9
+ });
package/dist/kit.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "@kubb/kit";
package/dist/kit.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "@kubb/kit";
2
+ export {};