kubb 5.9.2 → 5.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.cjs CHANGED
@@ -1,3 +1,3 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_defineConfig = require("./defineConfig-BNg7h8qE.cjs");
2
+ const require_defineConfig = require("./defineConfig-wAz42i-Y.cjs");
3
3
  exports.defineConfig = require_defineConfig.defineConfig;
package/dist/config.js CHANGED
@@ -1 +1 @@
1
- export { t as defineConfig } from "./defineConfig-D6VhWkUg.js";
1
+ export { t as defineConfig } from "./defineConfig-CReNal6i.js";
@@ -0,0 +1,56 @@
1
+ import "./rolldown-runtime-C0LytTxp.js";
2
+ import { applyDefaults } from "unplugin-kubb";
3
+ //#region src/defineConfig.ts
4
+ function normalizeConfig(config) {
5
+ if (Array.isArray(config)) return config.map(applyDefaults);
6
+ return applyDefaults(config);
7
+ }
8
+ /**
9
+ * Defines a Kubb build configuration and fills in defaults for any omitted fields.
10
+ *
11
+ * Defaults applied when omitted:
12
+ * - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
13
+ * - `parsers` → `[parserTs(), parserTsx(), parserMd()]`.
14
+ * - `reporters` → `[cliReporter, jsonReporter, fileReporter, htmlReporter]`.
15
+ * - `plugins` → `pluginBarrel()` is appended when not already present.
16
+ * - `output.barrel` → `false` when not set.
17
+ * - `output.format` and `output.lint` → `false`.
18
+ *
19
+ * Accepts a config object, an array of configs, a Promise resolving to one,
20
+ * or a function that receives the parsed CLI options and returns any of the
21
+ * above. The return type is preserved so async/array variants stay typed.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { defineConfig } from 'kubb'
26
+ * import { pluginTs } from '@kubb/plugin-ts'
27
+ *
28
+ * export default defineConfig({
29
+ * input: './petStore.yaml',
30
+ * output: { path: './src/gen' },
31
+ * plugins: [pluginTs()],
32
+ * })
33
+ * ```
34
+ *
35
+ * @example Function form with CLI options
36
+ * ```ts
37
+ * import { defineConfig } from 'kubb'
38
+ *
39
+ * export default defineConfig(({ input }) => ({
40
+ * input: input ?? './petStore.yaml',
41
+ * output: { path: './src/gen' },
42
+ * plugins: [],
43
+ * }))
44
+ * ```
45
+ */
46
+ function defineConfig(config) {
47
+ if (typeof config === "function") return (async (cli) => {
48
+ return normalizeConfig(await config(cli));
49
+ });
50
+ if (config instanceof Promise) return config.then(normalizeConfig);
51
+ return normalizeConfig(config);
52
+ }
53
+ //#endregion
54
+ export { defineConfig as t };
55
+
56
+ //# sourceMappingURL=defineConfig-CReNal6i.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineConfig-CReNal6i.js","names":[],"sources":["../src/defineConfig.ts"],"sourcesContent":["import type { PossiblePromise } from '@internals/utils'\nimport type { CLIOptions, UserConfig } from '@kubb/core'\nimport { applyDefaults } from 'unplugin-kubb'\n\ntype AnyConfigResult = UserConfig<unknown> | Array<UserConfig<unknown>>\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\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, htmlReporter]`.\n * - `plugins` → `pluginBarrel()` is appended when not already present.\n * - `output.barrel` → `false` 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: './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: 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 (config instanceof Promise) {\n return config.then(normalizeConfig) as DefinedConfig<TConfig>\n }\n\n return normalizeConfig(config) as DefinedConfig<TConfig>\n}\n"],"mappings":";;;AAcA,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,kBAAkB,SACpB,OAAO,OAAO,KAAK,eAAe;CAGpC,OAAO,gBAAgB,MAAM;AAC/B"}
@@ -0,0 +1,61 @@
1
+ require("./rolldown-runtime-qbf5tadS.cjs");
2
+ let unplugin_kubb = require("unplugin-kubb");
3
+ //#region src/defineConfig.ts
4
+ function normalizeConfig(config) {
5
+ if (Array.isArray(config)) return config.map(unplugin_kubb.applyDefaults);
6
+ return (0, unplugin_kubb.applyDefaults)(config);
7
+ }
8
+ /**
9
+ * Defines a Kubb build configuration and fills in defaults for any omitted fields.
10
+ *
11
+ * Defaults applied when omitted:
12
+ * - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
13
+ * - `parsers` → `[parserTs(), parserTsx(), parserMd()]`.
14
+ * - `reporters` → `[cliReporter, jsonReporter, fileReporter, htmlReporter]`.
15
+ * - `plugins` → `pluginBarrel()` is appended when not already present.
16
+ * - `output.barrel` → `false` when not set.
17
+ * - `output.format` and `output.lint` → `false`.
18
+ *
19
+ * Accepts a config object, an array of configs, a Promise resolving to one,
20
+ * or a function that receives the parsed CLI options and returns any of the
21
+ * above. The return type is preserved so async/array variants stay typed.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { defineConfig } from 'kubb'
26
+ * import { pluginTs } from '@kubb/plugin-ts'
27
+ *
28
+ * export default defineConfig({
29
+ * input: './petStore.yaml',
30
+ * output: { path: './src/gen' },
31
+ * plugins: [pluginTs()],
32
+ * })
33
+ * ```
34
+ *
35
+ * @example Function form with CLI options
36
+ * ```ts
37
+ * import { defineConfig } from 'kubb'
38
+ *
39
+ * export default defineConfig(({ input }) => ({
40
+ * input: input ?? './petStore.yaml',
41
+ * output: { path: './src/gen' },
42
+ * plugins: [],
43
+ * }))
44
+ * ```
45
+ */
46
+ function defineConfig(config) {
47
+ if (typeof config === "function") return (async (cli) => {
48
+ return normalizeConfig(await config(cli));
49
+ });
50
+ if (config instanceof Promise) return config.then(normalizeConfig);
51
+ return normalizeConfig(config);
52
+ }
53
+ //#endregion
54
+ Object.defineProperty(exports, "defineConfig", {
55
+ enumerable: true,
56
+ get: function() {
57
+ return defineConfig;
58
+ }
59
+ });
60
+
61
+ //# sourceMappingURL=defineConfig-wAz42i-Y.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineConfig-wAz42i-Y.cjs","names":["applyDefaults"],"sources":["../src/defineConfig.ts"],"sourcesContent":["import type { PossiblePromise } from '@internals/utils'\nimport type { CLIOptions, UserConfig } from '@kubb/core'\nimport { applyDefaults } from 'unplugin-kubb'\n\ntype AnyConfigResult = UserConfig<unknown> | Array<UserConfig<unknown>>\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\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, htmlReporter]`.\n * - `plugins` → `pluginBarrel()` is appended when not already present.\n * - `output.barrel` → `false` 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: './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: 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 (config instanceof Promise) {\n return config.then(normalizeConfig) as DefinedConfig<TConfig>\n }\n\n return normalizeConfig(config) as DefinedConfig<TConfig>\n}\n"],"mappings":";;;AAcA,SAAS,gBAAwB,QAAwG;CACvI,IAAI,MAAM,QAAQ,MAAM,GACtB,OAAO,OAAO,IAAIA,cAAAA,aAAa;CAGjC,QAAA,GAAOA,cAAAA,cAAAA,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,kBAAkB,SACpB,OAAO,OAAO,KAAK,eAAe;CAGpC,OAAO,gBAAgB,MAAM;AAC/B"}
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("./rolldown-runtime-qbf5tadS.cjs");
3
- const require_defineConfig = require("./defineConfig-BNg7h8qE.cjs");
3
+ const require_defineConfig = require("./defineConfig-wAz42i-Y.cjs");
4
4
  let _kubb_core = require("@kubb/core");
5
5
  //#region src/createKubb.ts
6
6
  /**
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./rolldown-runtime-C0LytTxp.js";
2
- import { t as defineConfig } from "./defineConfig-D6VhWkUg.js";
2
+ import { t as defineConfig } from "./defineConfig-CReNal6i.js";
3
3
  import { createKubb as createKubb$1 } from "@kubb/core";
4
4
  //#region src/createKubb.ts
5
5
  /**
package/dist/jsx.cjs CHANGED
@@ -7,12 +7,3 @@ Object.keys(_kubb_renderer_jsx).forEach(function(k) {
7
7
  }
8
8
  });
9
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 CHANGED
@@ -1,2 +1 @@
1
- export * from "@kubb/renderer-jsx";
2
- export * from "@kubb/renderer-jsx/types";
1
+ export * from "@kubb/renderer-jsx";
package/dist/jsx.js CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from "@kubb/renderer-jsx";
2
- export * from "@kubb/renderer-jsx/types";
3
2
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kubb",
3
- "version": "5.9.2",
3
+ "version": "5.9.4",
4
4
  "description": "Turn your API spec into type-safe code. Generate TypeScript types, API clients, hooks, validators and mocks from a spec such as OpenAPI.",
5
5
  "keywords": [
6
6
  "api-client",
@@ -140,17 +140,17 @@
140
140
  "registry": "https://registry.npmjs.org/"
141
141
  },
142
142
  "dependencies": {
143
- "@kubb/adapter-oas": "5.9.2",
144
- "@kubb/cli": "5.9.2",
145
- "@kubb/core": "5.9.2",
146
- "@kubb/kit": "5.9.2",
147
- "@kubb/mcp": "5.9.2",
148
- "@kubb/parser-md": "5.9.2",
149
- "@kubb/parser-ts": "5.9.2",
150
- "@kubb/plugin-barrel": "5.9.2",
151
- "@kubb/renderer-jsx": "5.9.2",
152
- "@kubb/studio": "5.9.2",
153
- "unplugin-kubb": "5.9.2"
143
+ "@kubb/adapter-oas": "5.9.4",
144
+ "@kubb/cli": "5.9.4",
145
+ "@kubb/core": "5.9.4",
146
+ "@kubb/kit": "5.9.4",
147
+ "@kubb/mcp": "5.9.4",
148
+ "@kubb/parser-md": "5.9.4",
149
+ "@kubb/parser-ts": "5.9.4",
150
+ "@kubb/plugin-barrel": "5.9.4",
151
+ "@kubb/renderer-jsx": "5.9.4",
152
+ "@kubb/studio": "5.9.4",
153
+ "unplugin-kubb": "5.9.4"
154
154
  },
155
155
  "devDependencies": {
156
156
  "@farmfe/core": "^1.7.11",
@@ -1,120 +0,0 @@
1
- require("./rolldown-runtime-qbf5tadS.cjs");
2
- let _kubb_core = require("@kubb/core");
3
- let _kubb_adapter_oas = require("@kubb/adapter-oas");
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, htmlReporter]`
28
- * - `plugins` gets `pluginBarrel()` appended when none is already present
29
- * - `output.barrel` defaults to `false` when not set (`pluginBarrel` is always present after the step above, but generates nothing until configured)
30
- * - `output.format` defaults to `false`
31
- * - `output.lint` defaults to `false`
32
- */
33
- function applyDefaults(config) {
34
- const { adapter, output, plugins } = (0, _kubb_core.applyConfigDefaults)(config, {
35
- defaultAdapter: (0, _kubb_adapter_oas.adapterOas)(),
36
- barrelPlugin: (0, _kubb_plugin_barrel.pluginBarrel)(),
37
- barrelPluginName: _kubb_plugin_barrel.pluginBarrelName,
38
- defaultOutput: {
39
- barrel: false,
40
- format: false,
41
- lint: false
42
- }
43
- });
44
- return {
45
- ...config,
46
- root: config.root || process.cwd(),
47
- adapter,
48
- parsers: config.parsers?.length ? config.parsers : [
49
- (0, _kubb_parser_ts.parserTs)(),
50
- (0, _kubb_parser_ts.parserTsx)(),
51
- (0, _kubb_parser_md.parserMd)()
52
- ],
53
- reporters: config.reporters?.length ? config.reporters : [
54
- _kubb_core.cliReporter,
55
- _kubb_core.jsonReporter,
56
- _kubb_core.fileReporter,
57
- _kubb_core.htmlReporter
58
- ],
59
- plugins,
60
- output
61
- };
62
- }
63
- function normalizeConfig(config) {
64
- if (Array.isArray(config)) return config.map(applyDefaults);
65
- return applyDefaults(config);
66
- }
67
- /**
68
- * Defines a Kubb build configuration and fills in defaults for any omitted fields.
69
- *
70
- * Defaults applied when omitted:
71
- * - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
72
- * - `parsers` → `[parserTs(), parserTsx(), parserMd()]`.
73
- * - `reporters` → `[cliReporter, jsonReporter, fileReporter, htmlReporter]`.
74
- * - `plugins` → `pluginBarrel()` is appended when not already present.
75
- * - `output.barrel` → `false` when not set.
76
- * - `output.format` and `output.lint` → `false`.
77
- *
78
- * Accepts a config object, an array of configs, a Promise resolving to one,
79
- * or a function that receives the parsed CLI options and returns any of the
80
- * above. The return type is preserved so async/array variants stay typed.
81
- *
82
- * @example
83
- * ```ts
84
- * import { defineConfig } from 'kubb'
85
- * import { pluginTs } from '@kubb/plugin-ts'
86
- *
87
- * export default defineConfig({
88
- * input: './petStore.yaml',
89
- * output: { path: './src/gen' },
90
- * plugins: [pluginTs()],
91
- * })
92
- * ```
93
- *
94
- * @example Function form with CLI options
95
- * ```ts
96
- * import { defineConfig } from 'kubb'
97
- *
98
- * export default defineConfig(({ input }) => ({
99
- * input: input ?? './petStore.yaml',
100
- * output: { path: './src/gen' },
101
- * plugins: [],
102
- * }))
103
- * ```
104
- */
105
- function defineConfig(config) {
106
- if (typeof config === "function") return (async (cli) => {
107
- return normalizeConfig(await config(cli));
108
- });
109
- if (isPromise(config)) return config.then((resolved) => normalizeConfig(resolved));
110
- return normalizeConfig(config);
111
- }
112
- //#endregion
113
- Object.defineProperty(exports, "defineConfig", {
114
- enumerable: true,
115
- get: function() {
116
- return defineConfig;
117
- }
118
- });
119
-
120
- //# sourceMappingURL=defineConfig-BNg7h8qE.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"defineConfig-BNg7h8qE.cjs","names":["applyConfigDefaults","adapterOas","pluginBarrel","pluginBarrelName","parserTs","parserTsx","parserMd","cliReporter","jsonReporter","fileReporter","htmlReporter"],"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\ntype ParallelOptions<TItem> = {\n /**\n * Items to work through, handed out in order.\n */\n items: ReadonlyArray<TItem>\n /**\n * How many items may be in flight at once.\n */\n limit: number\n /**\n * Runs once per item, with the item's position so a caller can report progress.\n */\n run(item: TItem, index: number): Promise<void>\n}\n\n/**\n * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each\n * takes the next item the moment it frees up instead of waiting for a batch to drain.\n *\n * @example\n * ```ts\n * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })\n * ```\n */\nexport async function inParallel<TItem>({ items, limit, run }: ParallelOptions<TItem>): Promise<void> {\n const queue = items.entries()\n\n const worker = async (): Promise<void> => {\n for (const [index, item] of queue) await run(item, index)\n }\n\n await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()))\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport { applyConfigDefaults, cliReporter, type CLIOptions, fileReporter, htmlReporter, 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<unknown> | Array<UserConfig<unknown>>\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, htmlReporter]`\n * - `plugins` gets `pluginBarrel()` appended when none is already present\n * - `output.barrel` defaults to `false` when not set (`pluginBarrel` is always present after the step above, but generates nothing until configured)\n * - `output.format` defaults to `false`\n * - `output.lint` defaults to `false`\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const { adapter, output, plugins } = applyConfigDefaults(config, {\n defaultAdapter: adapterOas(),\n barrelPlugin: pluginBarrel(),\n barrelPluginName: pluginBarrelName,\n defaultOutput: { barrel: false, format: false, lint: false },\n })\n\n return {\n ...config,\n root: config.root || process.cwd(),\n adapter,\n parsers: config.parsers?.length ? config.parsers : [parserTs(), parserTsx(), parserMd()],\n reporters: config.reporters?.length ? config.reporters : [cliReporter, jsonReporter, fileReporter, htmlReporter],\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, htmlReporter]`.\n * - `plugins` → `pluginBarrel()` is appended when not already present.\n * - `output.barrel` → `false` 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: './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: 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;;;;;;;;;;;;;;;ACQA,SAAS,cAAsB,QAAgD;CAC7E,MAAM,EAAE,SAAS,QAAQ,aAAA,GAAYA,WAAAA,oBAAAA,CAAoB,QAAQ;EAC/D,iBAAA,GAAgBC,kBAAAA,WAAAA,CAAW;EAC3B,eAAA,GAAcC,oBAAAA,aAAAA,CAAa;EAC3B,kBAAkBC,oBAAAA;EAClB,eAAe;GAAE,QAAQ;GAAO,QAAQ;GAAO,MAAM;EAAM;CAC7D,CAAC;CAED,OAAO;EACL,GAAG;EACH,MAAM,OAAO,QAAQ,QAAQ,IAAI;EACjC;EACA,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU;IAACC,GAAAA,gBAAAA,SAAAA,CAAS;IAAGC,GAAAA,gBAAAA,UAAAA,CAAU;IAAGC,GAAAA,gBAAAA,SAAAA,CAAS;EAAC;EACvF,WAAW,OAAO,WAAW,SAAS,OAAO,YAAY;GAACC,WAAAA;GAAaC,WAAAA;GAAcC,WAAAA;GAAcC,WAAAA;EAAY;EAC/G;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"}
@@ -1,115 +0,0 @@
1
- import "./rolldown-runtime-C0LytTxp.js";
2
- import { applyConfigDefaults, cliReporter, fileReporter, htmlReporter, jsonReporter } from "@kubb/core";
3
- import { adapterOas } from "@kubb/adapter-oas";
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, htmlReporter]`
28
- * - `plugins` gets `pluginBarrel()` appended when none is already present
29
- * - `output.barrel` defaults to `false` when not set (`pluginBarrel` is always present after the step above, but generates nothing until configured)
30
- * - `output.format` defaults to `false`
31
- * - `output.lint` defaults to `false`
32
- */
33
- function applyDefaults(config) {
34
- const { adapter, output, plugins } = applyConfigDefaults(config, {
35
- defaultAdapter: adapterOas(),
36
- barrelPlugin: pluginBarrel(),
37
- barrelPluginName: pluginBarrelName,
38
- defaultOutput: {
39
- barrel: false,
40
- format: false,
41
- lint: false
42
- }
43
- });
44
- return {
45
- ...config,
46
- root: config.root || process.cwd(),
47
- adapter,
48
- parsers: config.parsers?.length ? config.parsers : [
49
- parserTs(),
50
- parserTsx(),
51
- parserMd()
52
- ],
53
- reporters: config.reporters?.length ? config.reporters : [
54
- cliReporter,
55
- jsonReporter,
56
- fileReporter,
57
- htmlReporter
58
- ],
59
- plugins,
60
- output
61
- };
62
- }
63
- function normalizeConfig(config) {
64
- if (Array.isArray(config)) return config.map(applyDefaults);
65
- return applyDefaults(config);
66
- }
67
- /**
68
- * Defines a Kubb build configuration and fills in defaults for any omitted fields.
69
- *
70
- * Defaults applied when omitted:
71
- * - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
72
- * - `parsers` → `[parserTs(), parserTsx(), parserMd()]`.
73
- * - `reporters` → `[cliReporter, jsonReporter, fileReporter, htmlReporter]`.
74
- * - `plugins` → `pluginBarrel()` is appended when not already present.
75
- * - `output.barrel` → `false` when not set.
76
- * - `output.format` and `output.lint` → `false`.
77
- *
78
- * Accepts a config object, an array of configs, a Promise resolving to one,
79
- * or a function that receives the parsed CLI options and returns any of the
80
- * above. The return type is preserved so async/array variants stay typed.
81
- *
82
- * @example
83
- * ```ts
84
- * import { defineConfig } from 'kubb'
85
- * import { pluginTs } from '@kubb/plugin-ts'
86
- *
87
- * export default defineConfig({
88
- * input: './petStore.yaml',
89
- * output: { path: './src/gen' },
90
- * plugins: [pluginTs()],
91
- * })
92
- * ```
93
- *
94
- * @example Function form with CLI options
95
- * ```ts
96
- * import { defineConfig } from 'kubb'
97
- *
98
- * export default defineConfig(({ input }) => ({
99
- * input: input ?? './petStore.yaml',
100
- * output: { path: './src/gen' },
101
- * plugins: [],
102
- * }))
103
- * ```
104
- */
105
- function defineConfig(config) {
106
- if (typeof config === "function") return (async (cli) => {
107
- return normalizeConfig(await config(cli));
108
- });
109
- if (isPromise(config)) return config.then((resolved) => normalizeConfig(resolved));
110
- return normalizeConfig(config);
111
- }
112
- //#endregion
113
- export { defineConfig as t };
114
-
115
- //# sourceMappingURL=defineConfig-D6VhWkUg.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"defineConfig-D6VhWkUg.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\ntype ParallelOptions<TItem> = {\n /**\n * Items to work through, handed out in order.\n */\n items: ReadonlyArray<TItem>\n /**\n * How many items may be in flight at once.\n */\n limit: number\n /**\n * Runs once per item, with the item's position so a caller can report progress.\n */\n run(item: TItem, index: number): Promise<void>\n}\n\n/**\n * Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each\n * takes the next item the moment it frees up instead of waiting for a batch to drain.\n *\n * @example\n * ```ts\n * await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })\n * ```\n */\nexport async function inParallel<TItem>({ items, limit, run }: ParallelOptions<TItem>): Promise<void> {\n const queue = items.entries()\n\n const worker = async (): Promise<void> => {\n for (const [index, item] of queue) await run(item, index)\n }\n\n await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()))\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport { applyConfigDefaults, cliReporter, type CLIOptions, fileReporter, htmlReporter, 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<unknown> | Array<UserConfig<unknown>>\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, htmlReporter]`\n * - `plugins` gets `pluginBarrel()` appended when none is already present\n * - `output.barrel` defaults to `false` when not set (`pluginBarrel` is always present after the step above, but generates nothing until configured)\n * - `output.format` defaults to `false`\n * - `output.lint` defaults to `false`\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const { adapter, output, plugins } = applyConfigDefaults(config, {\n defaultAdapter: adapterOas(),\n barrelPlugin: pluginBarrel(),\n barrelPluginName: pluginBarrelName,\n defaultOutput: { barrel: false, format: false, lint: false },\n })\n\n return {\n ...config,\n root: config.root || process.cwd(),\n adapter,\n parsers: config.parsers?.length ? config.parsers : [parserTs(), parserTsx(), parserMd()],\n reporters: config.reporters?.length ? config.reporters : [cliReporter, jsonReporter, fileReporter, htmlReporter],\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, htmlReporter]`.\n * - `plugins` → `pluginBarrel()` is appended when not already present.\n * - `output.barrel` → `false` 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: './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: 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;;;;;;;;;;;;;;;ACQA,SAAS,cAAsB,QAAgD;CAC7E,MAAM,EAAE,SAAS,QAAQ,YAAY,oBAAoB,QAAQ;EAC/D,gBAAgB,WAAW;EAC3B,cAAc,aAAa;EAC3B,kBAAkB;EAClB,eAAe;GAAE,QAAQ;GAAO,QAAQ;GAAO,MAAM;EAAM;CAC7D,CAAC;CAED,OAAO;EACL,GAAG;EACH,MAAM,OAAO,QAAQ,QAAQ,IAAI;EACjC;EACA,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU;GAAC,SAAS;GAAG,UAAU;GAAG,SAAS;EAAC;EACvF,WAAW,OAAO,WAAW,SAAS,OAAO,YAAY;GAAC;GAAa;GAAc;GAAc;EAAY;EAC/G;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"}