kubb 5.0.0-beta.5 → 5.0.0-beta.50
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/LICENSE +17 -10
- package/README.md +52 -47
- package/dist/index.cjs +54 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +34 -12
- package/dist/index.js +55 -17
- package/dist/index.js.map +1 -1
- package/package.json +13 -32
- package/src/defineConfig.ts +45 -16
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
package/LICENSE
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
This repository contains software under two licenses:
|
|
1
|
+
MIT License
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
MIT License — see licenses/LICENSE-MIT for the full license text.
|
|
3
|
+
Copyright (c) 2026 Stijn Van Hulle
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
|
|
3
|
-
<img
|
|
3
|
+
<img src="https://kubb.dev/og.png" alt="Kubb banner">
|
|
4
4
|
</a>
|
|
5
5
|
|
|
6
6
|
[![npm version][npm-version-src]][npm-version-href]
|
|
7
7
|
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
8
|
-
[![
|
|
8
|
+
[![Stars][stars-src]][stars-href]
|
|
9
9
|
[![License][license-src]][license-href]
|
|
10
|
-
[![
|
|
11
|
-
|
|
12
|
-
### The meta framework for code generation
|
|
13
|
-
|
|
14
|
-
**Stop writing glue code. Define your API once and Kubb generates types, clients, hooks, validators, mocks and more.**
|
|
10
|
+
[![Coverage][coverage-src]][coverage-href]
|
|
11
|
+
[![Node][node-src]][node-href]
|
|
15
12
|
|
|
16
13
|
<h4>
|
|
17
14
|
<a href="https://kubb.dev" target="_blank">Documentation</a>
|
|
@@ -24,30 +21,31 @@
|
|
|
24
21
|
|
|
25
22
|
<br />
|
|
26
23
|
|
|
24
|
+
# Kubb
|
|
25
|
+
|
|
26
|
+
### The meta framework for code generation
|
|
27
|
+
|
|
28
|
+
Point Kubb at an OpenAPI spec and it generates types, clients, hooks, validators, mocks, and more.
|
|
29
|
+
|
|
27
30
|
## Installation
|
|
28
31
|
|
|
29
32
|
```bash
|
|
30
|
-
|
|
33
|
+
bun add kubb
|
|
31
34
|
# or
|
|
32
35
|
pnpm add kubb
|
|
36
|
+
# or
|
|
37
|
+
npm install kubb
|
|
33
38
|
```
|
|
34
39
|
|
|
35
|
-
## Quick
|
|
40
|
+
## Quick start
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
Run the setup wizard to create a `kubb.config.ts`:
|
|
38
43
|
|
|
39
44
|
```bash
|
|
40
45
|
npx kubb init
|
|
41
46
|
```
|
|
42
47
|
|
|
43
|
-
The
|
|
44
|
-
|
|
45
|
-
- Create a `package.json` (if needed)
|
|
46
|
-
- Guide you through plugin selection
|
|
47
|
-
- Install packages automatically
|
|
48
|
-
- Generate `kubb.config.ts`
|
|
49
|
-
|
|
50
|
-
Then generate your code:
|
|
48
|
+
The wizard creates a `package.json` if needed, guides you through plugin selection, installs packages, and writes `kubb.config.ts`. Then generate your code:
|
|
51
49
|
|
|
52
50
|
```bash
|
|
53
51
|
npx kubb generate
|
|
@@ -57,19 +55,22 @@ See the [documentation](https://kubb.dev) for detailed usage and advanced featur
|
|
|
57
55
|
|
|
58
56
|
## Features
|
|
59
57
|
|
|
60
|
-
-
|
|
61
|
-
-
|
|
62
|
-
-
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
- JSX-based renderer (`@kubb/renderer-jsx`) for
|
|
66
|
-
-
|
|
58
|
+
- Generate from a spec: point Kubb at an OpenAPI document and it produces TypeScript types, type-safe API clients, [TanStack Query](https://github.com/TanStack/query) hooks for React and Vue, [SWR](https://github.com/vercel/swr) hooks, [Zod](https://github.com/colinhacks/zod) validators, [Faker](https://github.com/faker-js/faker) mocks, and [MSW](https://github.com/mswjs/msw) handlers.
|
|
59
|
+
- Read Swagger 2.0, OpenAPI 3.0, and 3.1, with TypeScript-first output that runs on Node.js and Bun.
|
|
60
|
+
- Pick what you generate from the [plugin ecosystem](https://github.com/kubb-labs/kubb-plugins): `plugin-ts`, `plugin-client`, `plugin-react-query`, `plugin-vue-query`, `plugin-swr`, `plugin-zod`, `plugin-faker`, `plugin-msw`, `plugin-cypress`, `plugin-redoc`, and `plugin-mcp`. Enable only the ones a project needs.
|
|
61
|
+
- Choose your HTTP client: use the axios or fetch presets, or point at a custom client module so generated requests run through your own wrapper.
|
|
62
|
+
- Control the generated tree: group files by tag, emit barrel exports, and include or exclude operations to keep the output focused.
|
|
63
|
+
- Build your own output with custom plugins, composable middleware, and the JSX-based renderer (`@kubb/renderer-jsx`) for full control over what lands on disk.
|
|
64
|
+
- Hook into your bundler with `unplugin-kubb`, which runs generation inside [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 other build tools.
|
|
65
|
+
- Drive generation from AI tools through the built-in Model Context Protocol (MCP) server, which works with [Claude](https://claude.ai), [Cursor](https://cursor.sh), and other MCP-compatible assistants.
|
|
66
|
+
- Generate from inside [Claude Code](https://kubb.dev/docs/5.x/ai/claude) with the Kubb plugin, which adds slash commands, a config skill, and an agent that run the Kubb CLI.
|
|
67
67
|
|
|
68
68
|
## Supporting Kubb
|
|
69
69
|
|
|
70
|
-
Kubb is an open source project
|
|
70
|
+
Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
|
|
71
71
|
|
|
72
72
|
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
73
|
+
- [See sponsorship tiers and our sponsors](https://kubb.dev/sponsors)
|
|
73
74
|
|
|
74
75
|
<p align="center">
|
|
75
76
|
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
@@ -77,6 +78,16 @@ Kubb is an open source project with its ongoing development made possible entire
|
|
|
77
78
|
</a>
|
|
78
79
|
</p>
|
|
79
80
|
|
|
81
|
+
## Contributing
|
|
82
|
+
|
|
83
|
+
We welcome contributions that help improve Kubb. A few ways to get involved:
|
|
84
|
+
|
|
85
|
+
- Found a bug? File it in the [issue tracker](https://github.com/kubb-labs/kubb/issues).
|
|
86
|
+
- Have an idea to improve Kubb? [Open an issue](https://github.com/kubb-labs/kubb/issues/new) to share it.
|
|
87
|
+
- Need help? Ask the community on [Discord](https://discord.gg/4dQjA6vrWX).
|
|
88
|
+
|
|
89
|
+
See [CONTRIBUTING.md](https://github.com/kubb-labs/kubb/blob/main/CONTRIBUTING.md) for the project structure, local setup, and commands.
|
|
90
|
+
|
|
80
91
|
## Contributors [![Contributors][contributors-src]][contributors-href]
|
|
81
92
|
|
|
82
93
|
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
@@ -164,15 +175,11 @@ Kubb is an open source project with its ongoing development made possible entire
|
|
|
164
175
|
|
|
165
176
|
## License
|
|
166
177
|
|
|
167
|
-
|
|
168
|
-
under AGPL-3.0-or-later.
|
|
169
|
-
|
|
170
|
-
- **Most packages** — [MIT](./licenses/LICENSE-MIT)
|
|
171
|
-
- **`@kubb/agent`** — [AGPL-3.0-or-later](./licenses/LICENSE-AGPL-3.0)
|
|
178
|
+
This repository is licensed under the [MIT License](./licenses/LICENSE-MIT), Copyright © 2025 [Stijn Van Hulle](https://stijnvanhulle.be).
|
|
172
179
|
|
|
173
180
|
See [LICENSE](./LICENSE) for details.
|
|
174
181
|
|
|
175
|
-
## Star
|
|
182
|
+
## Star history
|
|
176
183
|
|
|
177
184
|
<a href="https://star-history.com/#kubb-labs/kubb&Date">
|
|
178
185
|
<picture>
|
|
@@ -184,19 +191,17 @@ See [LICENSE](./LICENSE) for details.
|
|
|
184
191
|
|
|
185
192
|
<!-- Badges -->
|
|
186
193
|
|
|
187
|
-
[npm-version-src]: https://
|
|
188
|
-
[npm-version-href]: https://npmx.dev/package
|
|
189
|
-
[npm-downloads-src]: https://
|
|
190
|
-
[npm-downloads-href]: https://
|
|
191
|
-
[
|
|
192
|
-
[
|
|
193
|
-
[
|
|
194
|
-
[
|
|
195
|
-
[
|
|
196
|
-
[
|
|
197
|
-
[
|
|
198
|
-
[coverage-href]: https://www.npmjs.com/package/@kubb/core
|
|
199
|
-
[contributors-src]: https://img.shields.io/github/contributors/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517&label=%20
|
|
194
|
+
[npm-version-src]: https://shieldcn.dev/npm/v/@kubb/core.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
195
|
+
[npm-version-href]: https://npmx.dev/package/kubb
|
|
196
|
+
[npm-downloads-src]: https://shieldcn.dev/npm/dm/@kubb/core.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
197
|
+
[npm-downloads-href]: https://npmx.dev/package/kubb
|
|
198
|
+
[stars-src]: https://shieldcn.dev/github/stars/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
199
|
+
[stars-href]: https://github.com/kubb-labs/kubb
|
|
200
|
+
[license-src]: https://shieldcn.dev/npm/license/kubb.svg?variant=secondary&size=xs&theme=zinc
|
|
201
|
+
[license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
|
|
202
|
+
[node-src]: https://shieldcn.dev/npm/node/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
203
|
+
[node-href]: https://npmx.dev/package/kubb
|
|
204
|
+
[contributors-src]: https://shieldcn.dev/github/contributors/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
200
205
|
[contributors-href]: #contributors-
|
|
201
|
-
[
|
|
202
|
-
[
|
|
206
|
+
[coverage-src]: https://shieldcn.dev/codecov/github/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
207
|
+
[coverage-href]: https://app.codecov.io/gh/kubb-labs/kubb
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#endregion
|
|
3
3
|
let _kubb_adapter_oas = require("@kubb/adapter-oas");
|
|
4
|
+
let _kubb_core = require("@kubb/core");
|
|
4
5
|
let _kubb_middleware_barrel = require("@kubb/middleware-barrel");
|
|
5
6
|
let _kubb_parser_ts = require("@kubb/parser-ts");
|
|
7
|
+
let _kubb_parser_md = require("@kubb/parser-md");
|
|
6
8
|
//#region ../../internals/utils/src/promise.ts
|
|
7
9
|
/** Returns `true` when `result` is a thenable `Promise`.
|
|
8
10
|
*
|
|
@@ -18,15 +20,18 @@ function isPromise(result) {
|
|
|
18
20
|
//#endregion
|
|
19
21
|
//#region src/defineConfig.ts
|
|
20
22
|
/**
|
|
21
|
-
* Applies default adapter, parsers, middleware, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
|
|
23
|
+
* Applies default `root`, adapter, parsers, middleware, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
|
|
22
24
|
*
|
|
25
|
+
* - `root` defaults to `process.cwd()`
|
|
23
26
|
* - `adapter` defaults to `adapterOas()`
|
|
24
|
-
* - `parsers` defaults to `[parserTs, parserTsx]`
|
|
27
|
+
* - `parsers` defaults to `[parserTs, parserTsx, parserMd]`
|
|
28
|
+
* - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`
|
|
25
29
|
* - `middleware` defaults to `[middlewareBarrel()]`
|
|
26
30
|
* - `output.barrel` defaults to `{ type: 'named' }` **only when `middlewareBarrel` is part of `middleware`**.
|
|
27
31
|
* When the user provides a custom middleware list without `middlewareBarrel`, `barrel` is left untouched.
|
|
28
|
-
* - `output.format` defaults to `
|
|
29
|
-
* - `output.lint` defaults to `
|
|
32
|
+
* - `output.format` defaults to `false`
|
|
33
|
+
* - `output.lint` defaults to `false`
|
|
34
|
+
* - `cache` defaults to `fsCache()`; pass `false` to turn caching off
|
|
30
35
|
*/
|
|
31
36
|
function applyDefaults(config) {
|
|
32
37
|
const middleware = config.middleware?.length ? config.middleware : [(0, _kubb_middleware_barrel.middlewareBarrel)()];
|
|
@@ -37,10 +42,21 @@ function applyDefaults(config) {
|
|
|
37
42
|
if (output.lint === void 0) output.lint = false;
|
|
38
43
|
return {
|
|
39
44
|
...config,
|
|
45
|
+
root: config.root || process.cwd(),
|
|
40
46
|
adapter: config.adapter ?? (0, _kubb_adapter_oas.adapterOas)(),
|
|
41
|
-
parsers: config.parsers?.length ? config.parsers : [
|
|
47
|
+
parsers: config.parsers?.length ? config.parsers : [
|
|
48
|
+
_kubb_parser_ts.parserTs,
|
|
49
|
+
_kubb_parser_ts.parserTsx,
|
|
50
|
+
_kubb_parser_md.parserMd
|
|
51
|
+
],
|
|
52
|
+
reporters: config.reporters?.length ? config.reporters : [
|
|
53
|
+
_kubb_core.cliReporter,
|
|
54
|
+
_kubb_core.jsonReporter,
|
|
55
|
+
_kubb_core.fileReporter
|
|
56
|
+
],
|
|
42
57
|
middleware,
|
|
43
|
-
output
|
|
58
|
+
output,
|
|
59
|
+
cache: config.cache === void 0 ? (0, _kubb_core.fsCache)() : config.cache
|
|
44
60
|
};
|
|
45
61
|
}
|
|
46
62
|
function normalizeConfig(config) {
|
|
@@ -48,21 +64,43 @@ function normalizeConfig(config) {
|
|
|
48
64
|
return applyDefaults(config);
|
|
49
65
|
}
|
|
50
66
|
/**
|
|
51
|
-
*
|
|
67
|
+
* Defines a Kubb build configuration and applies sensible defaults so the
|
|
68
|
+
* minimal config stays small.
|
|
52
69
|
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
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]`.
|
|
74
|
+
* - `middleware` → `[middlewareBarrel()]`.
|
|
75
|
+
* - `output.barrel` → `{ type: 'named' }` only when `middlewareBarrel` is
|
|
76
|
+
* in the middleware list.
|
|
77
|
+
* - `output.format` and `output.lint` → `false`.
|
|
78
|
+
* - `cache` → `fsCache()` (local disk); pass `false` to turn caching off.
|
|
55
79
|
*
|
|
56
|
-
* Accepts
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* receiving the CLI options as argument
|
|
80
|
+
* Accepts a config object, an array of configs, a Promise resolving to one,
|
|
81
|
+
* or a function that receives the parsed CLI options and returns any of the
|
|
82
|
+
* above. The return type is preserved so async/array variants stay typed.
|
|
60
83
|
*
|
|
61
84
|
* @example
|
|
62
85
|
* ```ts
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
86
|
+
* import { defineConfig } from 'kubb'
|
|
87
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
88
|
+
*
|
|
89
|
+
* export default defineConfig({
|
|
90
|
+
* input: { path: './petStore.yaml' },
|
|
91
|
+
* output: { path: './src/gen' },
|
|
92
|
+
* plugins: [pluginTs()],
|
|
93
|
+
* })
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @example Function form with CLI options
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { defineConfig } from 'kubb'
|
|
99
|
+
*
|
|
100
|
+
* export default defineConfig(({ input }) => ({
|
|
101
|
+
* input: { path: input ?? './petStore.yaml' },
|
|
102
|
+
* output: { path: './src/gen' },
|
|
103
|
+
* plugins: [],
|
|
66
104
|
* }))
|
|
67
105
|
* ```
|
|
68
106
|
*/
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["middlewareBarrelName","parserTs","parserTsx"],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\n/** Returns `true` when `result` is a fulfilled `Promise.allSettled` result.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseFulfilledResult).map((r) => r.value)\n * ```\n */\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport type { CLIOptions, UserConfig } from '@kubb/core'\nimport { middlewareBarrel, middlewareBarrelName } from '@kubb/middleware-barrel'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\n\ntype AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>\ntype ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>)\ntype NormalizeConfig<TConfig> =\n TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never\ntype DefinedConfig<TConfig extends ConfigInput> = TConfig extends (cli: CLIOptions) => PossiblePromise<infer TResult>\n ? (cli: CLIOptions) => Promise<NormalizeConfig<TResult>>\n : TConfig extends Promise<infer TResult>\n ? Promise<NormalizeConfig<TResult>>\n : NormalizeConfig<TConfig>\n\n/**\n * Applies default adapter, parsers, middleware, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.\n *\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx]`\n * - `middleware` defaults to `[middlewareBarrel()]`\n * - `output.barrel` defaults to `{ type: 'named' }` **only when `middlewareBarrel` is part of `middleware`**.\n * When the user provides a custom middleware list without `middlewareBarrel`, `barrel` is left untouched.\n * - `output.format` defaults to `'auto'`\n * - `output.lint` defaults to `'auto'`\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const middleware = config.middleware?.length ? config.middleware : [middlewareBarrel()]\n const hasBarrelMiddleware = middleware.some((m) => m.name === middlewareBarrelName)\n\n const output = { ...config.output }\n if (hasBarrelMiddleware && 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 adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx],\n middleware,\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 * Helper for defining a Kubb configuration with built-in defaults.\n *\n * When no `adapter` is provided, `adapterOas()` is used automatically.\n * When no `parsers` are provided, `[parserTs, parserTsx]` is used automatically.\n *\n * Accepts either:\n * - A config object or array of configs\n * - A function returning the config(s), optionally async,\n * receiving the CLI options as argument\n *\n * @example\n * ```ts\n * export default defineConfig(({ logLevel }) => ({\n * root: 'src',\n * plugins: [myPlugin()],\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;AAC7E,QAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;;;;;;;;;;;;;;;ACO3G,SAAS,cAAsB,QAAgD;CAC7E,MAAM,aAAa,OAAO,YAAY,SAAS,OAAO,aAAa,EAAA,GAAA,wBAAA,mBAAmB,CAAC;CACvF,MAAM,sBAAsB,WAAW,MAAM,MAAM,EAAE,SAASA,wBAAAA,qBAAqB;CAEnF,MAAM,SAAS,EAAE,GAAG,OAAO,QAAQ;AACnC,KAAI,uBAAuB,OAAO,WAAW,KAAA,EAC3C,QAAO,SAAS,EAAE,MAAM,SAAS;AAEnC,KAAI,OAAO,WAAW,KAAA,EACpB,QAAO,SAAS;AAElB,KAAI,OAAO,SAAS,KAAA,EAClB,QAAO,OAAO;AAGhB,QAAO;EACL,GAAG;EACH,SAAS,OAAO,YAAA,GAAA,kBAAA,aAAuB;EACvC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU,CAACC,gBAAAA,UAAUC,gBAAAA,UAAU;EACxE;EACA;EACD;;AAGH,SAAS,gBAAwB,QAAwG;AACvI,KAAI,MAAM,QAAQ,OAAO,CACvB,QAAO,OAAO,IAAI,cAAc;AAGlC,QAAO,cAAc,OAAO;;;;;;;;;;;;;;;;;;;;;AAsB9B,SAAgB,aAA0C,QAAyC;AACjG,KAAI,OAAO,WAAW,WACpB,SAAQ,OAAO,QAAoB;AACjC,SAAO,gBAAgB,MAAM,OAAO,IAAI,CAAC;;AAI7C,KAAI,UAAU,OAAO,CACnB,QAAO,OAAO,MAAM,aAAa,gBAAgB,SAAS,CAAC;AAG7D,QAAO,gBAAgB,OAAO"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["middlewareBarrelName","parserTs","parserTsx","parserMd","cliReporter","jsonReporter","fileReporter"],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["function* chunks<T>(arr: readonly T[], size: number): Generator<T[]> {\n for (let i = 0; i < arr.length; i += size) {\n yield arr.slice(i, i + size)\n }\n}\n\nexport type ForBatchesOptions = {\n /**\n * Maximum batch size handed to `process`.\n * Parallel dispatch within a batch is the caller's responsibility\n * (typically via `Promise.all(batch.map(...))`).\n */\n concurrency: number\n /**\n * Called after every batch.\n *\n * Use a cheap, idempotent callback (e.g. one that short-circuits when there\n * is nothing new to do). The helper does not coalesce calls — if you need\n * throttling, do it inside `flush` itself.\n */\n flush?: () => Promise<void>\n}\n\n/**\n * Slices `source` into batches of `concurrency` items and awaits `process` for each batch.\n * Accepts both plain arrays (sync) and `AsyncIterable` (streaming).\n *\n * `process` controls whether items inside a batch run in parallel; this helper only\n * controls batch size and per-batch flushing.\n *\n * @example\n * ```ts\n * // parallel dispatch inside each batch\n * await forBatches(schemas, (batch) => Promise.all(batch.map(process)), { concurrency: 8 })\n *\n * // async iterable with a flush after every batch\n * await forBatches(stream.schemas, (batch) => dispatch(batch), { concurrency: 8, flush })\n * ```\n */\nexport async function forBatches<T>(\n source: readonly T[] | AsyncIterable<T>,\n process: (batch: T[]) => Promise<unknown>,\n options: ForBatchesOptions,\n): Promise<void> {\n const { concurrency, flush } = options\n\n if (Array.isArray(source)) {\n for (const batch of chunks(source, concurrency)) {\n await process(batch)\n if (flush) await flush()\n }\n return\n }\n\n const batch: T[] = []\n for await (const item of source) {\n batch.push(item)\n if (batch.length >= concurrency) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n }\n if (batch.length > 0) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n}\n\n/**\n * Runs `work`, passing `flush` as its periodic-flush callback, then calls\n * `flush` once more to drain any items that did not cross a flush boundary.\n *\n * @example\n * ```ts\n * await withDrain(\n * (flush) => processItems(items, { flush }),\n * () => writeRemainingFiles(),\n * )\n * ```\n */\nexport async function withDrain(work: (flush: () => Promise<void>) => Promise<void>, flush: () => Promise<void>): Promise<void> {\n await work(flush)\n await flush()\n}\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\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n\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 * 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: readonly 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, fsCache, jsonReporter, type UserConfig } from '@kubb/core'\nimport { middlewareBarrel, middlewareBarrelName } from '@kubb/middleware-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, middleware, `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 * - `middleware` defaults to `[middlewareBarrel()]`\n * - `output.barrel` defaults to `{ type: 'named' }` **only when `middlewareBarrel` is part of `middleware`**.\n * When the user provides a custom middleware list without `middlewareBarrel`, `barrel` is left untouched.\n * - `output.format` defaults to `false`\n * - `output.lint` defaults to `false`\n * - `cache` defaults to `fsCache()`; pass `false` to turn caching off\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const middleware = config.middleware?.length ? config.middleware : [middlewareBarrel()]\n const hasBarrelMiddleware = middleware.some((m) => m.name === middlewareBarrelName)\n\n const output = { ...config.output }\n if (hasBarrelMiddleware && 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 middleware,\n output,\n cache: config.cache === undefined ? fsCache() : config.cache,\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 applies sensible defaults so the\n * minimal config stays small.\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 * - `middleware` → `[middlewareBarrel()]`.\n * - `output.barrel` → `{ type: 'named' }` only when `middlewareBarrel` is\n * in the middleware list.\n * - `output.format` and `output.lint` → `false`.\n * - `cache` → `fsCache()` (local disk); pass `false` to turn caching off.\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":";;;;;;;;;;;;;;;;AA0GA,SAAgB,UAAa,QAAkD;CAC7E,OAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;AAC3G;;;;;;;;;;;;;;;;;AC7EA,SAAS,cAAsB,QAAgD;CAC7E,MAAM,aAAa,OAAO,YAAY,SAAS,OAAO,aAAa,EAAA,GAAA,wBAAA,iBAAA,CAAkB,CAAC;CACtF,MAAM,sBAAsB,WAAW,MAAM,MAAM,EAAE,SAASA,wBAAAA,oBAAoB;CAElF,MAAM,SAAS,EAAE,GAAG,OAAO,OAAO;CAClC,IAAI,uBAAuB,OAAO,WAAW,KAAA,GAC3C,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;EACA,OAAO,OAAO,UAAU,KAAA,KAAA,GAAA,WAAA,QAAA,CAAoB,IAAI,OAAO;CACzD;AACF;AAEA,SAAS,gBAAwB,QAAwG;CACvI,IAAI,MAAM,QAAQ,MAAM,GACtB,OAAO,OAAO,IAAI,aAAa;CAGjC,OAAO,cAAc,MAAM;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,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.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as __name } from "./chunk
|
|
2
|
-
import { BarrelType } from "@kubb/middleware-barrel";
|
|
1
|
+
import { t as __name } from "./chunk-C0LytTxp.js";
|
|
3
2
|
import { CLIOptions, UserConfig } from "@kubb/core";
|
|
3
|
+
import { BarrelType } from "@kubb/middleware-barrel";
|
|
4
4
|
|
|
5
5
|
//#region ../../internals/utils/src/promise.d.ts
|
|
6
6
|
/** A value that may already be resolved or still pending.
|
|
@@ -20,21 +20,43 @@ type ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOption
|
|
|
20
20
|
type NormalizeConfig<TConfig> = TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never;
|
|
21
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
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Defines a Kubb build configuration and applies sensible defaults so the
|
|
24
|
+
* minimal config stays small.
|
|
24
25
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
26
|
+
* Defaults applied when omitted:
|
|
27
|
+
* - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
|
|
28
|
+
* - `parsers` → `[parserTs, parserTsx, parserMd]`.
|
|
29
|
+
* - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
|
|
30
|
+
* - `middleware` → `[middlewareBarrel()]`.
|
|
31
|
+
* - `output.barrel` → `{ type: 'named' }` only when `middlewareBarrel` is
|
|
32
|
+
* in the middleware list.
|
|
33
|
+
* - `output.format` and `output.lint` → `false`.
|
|
34
|
+
* - `cache` → `fsCache()` (local disk); pass `false` to turn caching off.
|
|
27
35
|
*
|
|
28
|
-
* Accepts
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* receiving the CLI options as argument
|
|
36
|
+
* Accepts a config object, an array of configs, a Promise resolving to one,
|
|
37
|
+
* or a function that receives the parsed CLI options and returns any of the
|
|
38
|
+
* above. The return type is preserved so async/array variants stay typed.
|
|
32
39
|
*
|
|
33
40
|
* @example
|
|
34
41
|
* ```ts
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
42
|
+
* import { defineConfig } from 'kubb'
|
|
43
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
44
|
+
*
|
|
45
|
+
* export default defineConfig({
|
|
46
|
+
* input: { path: './petStore.yaml' },
|
|
47
|
+
* output: { path: './src/gen' },
|
|
48
|
+
* plugins: [pluginTs()],
|
|
49
|
+
* })
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example Function form with CLI options
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { defineConfig } from 'kubb'
|
|
55
|
+
*
|
|
56
|
+
* export default defineConfig(({ input }) => ({
|
|
57
|
+
* input: { path: input ?? './petStore.yaml' },
|
|
58
|
+
* output: { path: './src/gen' },
|
|
59
|
+
* plugins: [],
|
|
38
60
|
* }))
|
|
39
61
|
* ```
|
|
40
62
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import "./chunk
|
|
1
|
+
import "./chunk-C0LytTxp.js";
|
|
2
2
|
import { adapterOas } from "@kubb/adapter-oas";
|
|
3
|
+
import { cliReporter, fileReporter, fsCache, jsonReporter } from "@kubb/core";
|
|
3
4
|
import { middlewareBarrel, middlewareBarrelName } from "@kubb/middleware-barrel";
|
|
4
5
|
import { parserTs, parserTsx } from "@kubb/parser-ts";
|
|
6
|
+
import { parserMd } from "@kubb/parser-md";
|
|
5
7
|
//#region ../../internals/utils/src/promise.ts
|
|
6
8
|
/** Returns `true` when `result` is a thenable `Promise`.
|
|
7
9
|
*
|
|
@@ -17,15 +19,18 @@ function isPromise(result) {
|
|
|
17
19
|
//#endregion
|
|
18
20
|
//#region src/defineConfig.ts
|
|
19
21
|
/**
|
|
20
|
-
* Applies default adapter, parsers, middleware, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
|
|
22
|
+
* Applies default `root`, adapter, parsers, middleware, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
|
|
21
23
|
*
|
|
24
|
+
* - `root` defaults to `process.cwd()`
|
|
22
25
|
* - `adapter` defaults to `adapterOas()`
|
|
23
|
-
* - `parsers` defaults to `[parserTs, parserTsx]`
|
|
26
|
+
* - `parsers` defaults to `[parserTs, parserTsx, parserMd]`
|
|
27
|
+
* - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`
|
|
24
28
|
* - `middleware` defaults to `[middlewareBarrel()]`
|
|
25
29
|
* - `output.barrel` defaults to `{ type: 'named' }` **only when `middlewareBarrel` is part of `middleware`**.
|
|
26
30
|
* When the user provides a custom middleware list without `middlewareBarrel`, `barrel` is left untouched.
|
|
27
|
-
* - `output.format` defaults to `
|
|
28
|
-
* - `output.lint` defaults to `
|
|
31
|
+
* - `output.format` defaults to `false`
|
|
32
|
+
* - `output.lint` defaults to `false`
|
|
33
|
+
* - `cache` defaults to `fsCache()`; pass `false` to turn caching off
|
|
29
34
|
*/
|
|
30
35
|
function applyDefaults(config) {
|
|
31
36
|
const middleware = config.middleware?.length ? config.middleware : [middlewareBarrel()];
|
|
@@ -36,10 +41,21 @@ function applyDefaults(config) {
|
|
|
36
41
|
if (output.lint === void 0) output.lint = false;
|
|
37
42
|
return {
|
|
38
43
|
...config,
|
|
44
|
+
root: config.root || process.cwd(),
|
|
39
45
|
adapter: config.adapter ?? adapterOas(),
|
|
40
|
-
parsers: config.parsers?.length ? config.parsers : [
|
|
46
|
+
parsers: config.parsers?.length ? config.parsers : [
|
|
47
|
+
parserTs,
|
|
48
|
+
parserTsx,
|
|
49
|
+
parserMd
|
|
50
|
+
],
|
|
51
|
+
reporters: config.reporters?.length ? config.reporters : [
|
|
52
|
+
cliReporter,
|
|
53
|
+
jsonReporter,
|
|
54
|
+
fileReporter
|
|
55
|
+
],
|
|
41
56
|
middleware,
|
|
42
|
-
output
|
|
57
|
+
output,
|
|
58
|
+
cache: config.cache === void 0 ? fsCache() : config.cache
|
|
43
59
|
};
|
|
44
60
|
}
|
|
45
61
|
function normalizeConfig(config) {
|
|
@@ -47,21 +63,43 @@ function normalizeConfig(config) {
|
|
|
47
63
|
return applyDefaults(config);
|
|
48
64
|
}
|
|
49
65
|
/**
|
|
50
|
-
*
|
|
66
|
+
* Defines a Kubb build configuration and applies sensible defaults so the
|
|
67
|
+
* minimal config stays small.
|
|
51
68
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
69
|
+
* Defaults applied when omitted:
|
|
70
|
+
* - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
|
|
71
|
+
* - `parsers` → `[parserTs, parserTsx, parserMd]`.
|
|
72
|
+
* - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
|
|
73
|
+
* - `middleware` → `[middlewareBarrel()]`.
|
|
74
|
+
* - `output.barrel` → `{ type: 'named' }` only when `middlewareBarrel` is
|
|
75
|
+
* in the middleware list.
|
|
76
|
+
* - `output.format` and `output.lint` → `false`.
|
|
77
|
+
* - `cache` → `fsCache()` (local disk); pass `false` to turn caching off.
|
|
54
78
|
*
|
|
55
|
-
* Accepts
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* receiving the CLI options as argument
|
|
79
|
+
* Accepts a config object, an array of configs, a Promise resolving to one,
|
|
80
|
+
* or a function that receives the parsed CLI options and returns any of the
|
|
81
|
+
* above. The return type is preserved so async/array variants stay typed.
|
|
59
82
|
*
|
|
60
83
|
* @example
|
|
61
84
|
* ```ts
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
85
|
+
* import { defineConfig } from 'kubb'
|
|
86
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
87
|
+
*
|
|
88
|
+
* export default defineConfig({
|
|
89
|
+
* input: { path: './petStore.yaml' },
|
|
90
|
+
* output: { path: './src/gen' },
|
|
91
|
+
* plugins: [pluginTs()],
|
|
92
|
+
* })
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @example Function form with CLI options
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { defineConfig } from 'kubb'
|
|
98
|
+
*
|
|
99
|
+
* export default defineConfig(({ input }) => ({
|
|
100
|
+
* input: { path: input ?? './petStore.yaml' },
|
|
101
|
+
* output: { path: './src/gen' },
|
|
102
|
+
* plugins: [],
|
|
65
103
|
* }))
|
|
66
104
|
* ```
|
|
67
105
|
*/
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["/** A value that may already be resolved or still pending.\n *\n * @example\n * ```ts\n * function load(id: string): PossiblePromise<string> {\n * return cache.get(id) ?? fetchRemote(id)\n * }\n * ```\n */\nexport type PossiblePromise<T> = Promise<T> | T\n\n/** Returns `true` when `result` is a thenable `Promise`.\n *\n * @example\n * ```ts\n * isPromise(Promise.resolve(1)) // true\n * isPromise(42) // false\n * ```\n */\nexport function isPromise<T>(result: PossiblePromise<T>): result is Promise<T> {\n return result !== null && result !== undefined && typeof (result as Record<string, unknown>)['then'] === 'function'\n}\n\n/** Returns `true` when `result` is a fulfilled `Promise.allSettled` result.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseFulfilledResult).map((r) => r.value)\n * ```\n */\nexport function isPromiseFulfilledResult<T = unknown>(result: PromiseSettledResult<unknown>): result is PromiseFulfilledResult<T> {\n return result.status === 'fulfilled'\n}\n\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n","import { isPromise, type PossiblePromise } from '@internals/utils'\nimport { adapterOas } from '@kubb/adapter-oas'\nimport type { CLIOptions, UserConfig } from '@kubb/core'\nimport { middlewareBarrel, middlewareBarrelName } from '@kubb/middleware-barrel'\nimport { parserTs, parserTsx } from '@kubb/parser-ts'\n\ntype AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>\ntype ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>)\ntype NormalizeConfig<TConfig> =\n TConfig extends Array<UserConfig<infer TInput>> ? Array<UserConfig<TInput>> : TConfig extends UserConfig<infer TInput> ? UserConfig<TInput> : never\ntype DefinedConfig<TConfig extends ConfigInput> = TConfig extends (cli: CLIOptions) => PossiblePromise<infer TResult>\n ? (cli: CLIOptions) => Promise<NormalizeConfig<TResult>>\n : TConfig extends Promise<infer TResult>\n ? Promise<NormalizeConfig<TResult>>\n : NormalizeConfig<TConfig>\n\n/**\n * Applies default adapter, parsers, middleware, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.\n *\n * - `adapter` defaults to `adapterOas()`\n * - `parsers` defaults to `[parserTs, parserTsx]`\n * - `middleware` defaults to `[middlewareBarrel()]`\n * - `output.barrel` defaults to `{ type: 'named' }` **only when `middlewareBarrel` is part of `middleware`**.\n * When the user provides a custom middleware list without `middlewareBarrel`, `barrel` is left untouched.\n * - `output.format` defaults to `'auto'`\n * - `output.lint` defaults to `'auto'`\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const middleware = config.middleware?.length ? config.middleware : [middlewareBarrel()]\n const hasBarrelMiddleware = middleware.some((m) => m.name === middlewareBarrelName)\n\n const output = { ...config.output }\n if (hasBarrelMiddleware && 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 adapter: config.adapter ?? adapterOas(),\n parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx],\n middleware,\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 * Helper for defining a Kubb configuration with built-in defaults.\n *\n * When no `adapter` is provided, `adapterOas()` is used automatically.\n * When no `parsers` are provided, `[parserTs, parserTsx]` is used automatically.\n *\n * Accepts either:\n * - A config object or array of configs\n * - A function returning the config(s), optionally async,\n * receiving the CLI options as argument\n *\n * @example\n * ```ts\n * export default defineConfig(({ logLevel }) => ({\n * root: 'src',\n * plugins: [myPlugin()],\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;AAC7E,QAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;;;;;;;;;;;;;;;ACO3G,SAAS,cAAsB,QAAgD;CAC7E,MAAM,aAAa,OAAO,YAAY,SAAS,OAAO,aAAa,CAAC,kBAAkB,CAAC;CACvF,MAAM,sBAAsB,WAAW,MAAM,MAAM,EAAE,SAAS,qBAAqB;CAEnF,MAAM,SAAS,EAAE,GAAG,OAAO,QAAQ;AACnC,KAAI,uBAAuB,OAAO,WAAW,KAAA,EAC3C,QAAO,SAAS,EAAE,MAAM,SAAS;AAEnC,KAAI,OAAO,WAAW,KAAA,EACpB,QAAO,SAAS;AAElB,KAAI,OAAO,SAAS,KAAA,EAClB,QAAO,OAAO;AAGhB,QAAO;EACL,GAAG;EACH,SAAS,OAAO,WAAW,YAAY;EACvC,SAAS,OAAO,SAAS,SAAS,OAAO,UAAU,CAAC,UAAU,UAAU;EACxE;EACA;EACD;;AAGH,SAAS,gBAAwB,QAAwG;AACvI,KAAI,MAAM,QAAQ,OAAO,CACvB,QAAO,OAAO,IAAI,cAAc;AAGlC,QAAO,cAAc,OAAO;;;;;;;;;;;;;;;;;;;;;AAsB9B,SAAgB,aAA0C,QAAyC;AACjG,KAAI,OAAO,WAAW,WACpB,SAAQ,OAAO,QAAoB;AACjC,SAAO,gBAAgB,MAAM,OAAO,IAAI,CAAC;;AAI7C,KAAI,UAAU,OAAO,CACnB,QAAO,OAAO,MAAM,aAAa,gBAAgB,SAAS,CAAC;AAG7D,QAAO,gBAAgB,OAAO"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../internals/utils/src/promise.ts","../src/defineConfig.ts"],"sourcesContent":["function* chunks<T>(arr: readonly T[], size: number): Generator<T[]> {\n for (let i = 0; i < arr.length; i += size) {\n yield arr.slice(i, i + size)\n }\n}\n\nexport type ForBatchesOptions = {\n /**\n * Maximum batch size handed to `process`.\n * Parallel dispatch within a batch is the caller's responsibility\n * (typically via `Promise.all(batch.map(...))`).\n */\n concurrency: number\n /**\n * Called after every batch.\n *\n * Use a cheap, idempotent callback (e.g. one that short-circuits when there\n * is nothing new to do). The helper does not coalesce calls — if you need\n * throttling, do it inside `flush` itself.\n */\n flush?: () => Promise<void>\n}\n\n/**\n * Slices `source` into batches of `concurrency` items and awaits `process` for each batch.\n * Accepts both plain arrays (sync) and `AsyncIterable` (streaming).\n *\n * `process` controls whether items inside a batch run in parallel; this helper only\n * controls batch size and per-batch flushing.\n *\n * @example\n * ```ts\n * // parallel dispatch inside each batch\n * await forBatches(schemas, (batch) => Promise.all(batch.map(process)), { concurrency: 8 })\n *\n * // async iterable with a flush after every batch\n * await forBatches(stream.schemas, (batch) => dispatch(batch), { concurrency: 8, flush })\n * ```\n */\nexport async function forBatches<T>(\n source: readonly T[] | AsyncIterable<T>,\n process: (batch: T[]) => Promise<unknown>,\n options: ForBatchesOptions,\n): Promise<void> {\n const { concurrency, flush } = options\n\n if (Array.isArray(source)) {\n for (const batch of chunks(source, concurrency)) {\n await process(batch)\n if (flush) await flush()\n }\n return\n }\n\n const batch: T[] = []\n for await (const item of source) {\n batch.push(item)\n if (batch.length >= concurrency) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n }\n if (batch.length > 0) {\n await process(batch.splice(0))\n\n if (flush) await flush()\n }\n}\n\n/**\n * Runs `work`, passing `flush` as its periodic-flush callback, then calls\n * `flush` once more to drain any items that did not cross a flush boundary.\n *\n * @example\n * ```ts\n * await withDrain(\n * (flush) => processItems(items, { flush }),\n * () => writeRemainingFiles(),\n * )\n * ```\n */\nexport async function withDrain(work: (flush: () => Promise<void>) => Promise<void>, flush: () => Promise<void>): Promise<void> {\n await work(flush)\n await flush()\n}\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\n/** Returns `true` when `result` is a rejected `Promise.allSettled` result with a typed `reason`.\n *\n * @example\n * ```ts\n * const results = await Promise.allSettled([p1, p2])\n * results.filter(isPromiseRejectedResult<Error>).map((r) => r.reason.message)\n * ```\n */\nexport function isPromiseRejectedResult<T>(result: PromiseSettledResult<unknown>): result is Omit<PromiseRejectedResult, 'reason'> & { reason: T } {\n return result.status === 'rejected'\n}\n\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 * 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: readonly 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, fsCache, jsonReporter, type UserConfig } from '@kubb/core'\nimport { middlewareBarrel, middlewareBarrelName } from '@kubb/middleware-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, middleware, `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 * - `middleware` defaults to `[middlewareBarrel()]`\n * - `output.barrel` defaults to `{ type: 'named' }` **only when `middlewareBarrel` is part of `middleware`**.\n * When the user provides a custom middleware list without `middlewareBarrel`, `barrel` is left untouched.\n * - `output.format` defaults to `false`\n * - `output.lint` defaults to `false`\n * - `cache` defaults to `fsCache()`; pass `false` to turn caching off\n */\nfunction applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {\n const middleware = config.middleware?.length ? config.middleware : [middlewareBarrel()]\n const hasBarrelMiddleware = middleware.some((m) => m.name === middlewareBarrelName)\n\n const output = { ...config.output }\n if (hasBarrelMiddleware && 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 middleware,\n output,\n cache: config.cache === undefined ? fsCache() : config.cache,\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 applies sensible defaults so the\n * minimal config stays small.\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 * - `middleware` → `[middlewareBarrel()]`.\n * - `output.barrel` → `{ type: 'named' }` only when `middlewareBarrel` is\n * in the middleware list.\n * - `output.format` and `output.lint` → `false`.\n * - `cache` → `fsCache()` (local disk); pass `false` to turn caching off.\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":";;;;;;;;;;;;;;;AA0GA,SAAgB,UAAa,QAAkD;CAC7E,OAAO,WAAW,QAAQ,WAAW,KAAA,KAAa,OAAQ,OAAmC,YAAY;AAC3G;;;;;;;;;;;;;;;;;AC7EA,SAAS,cAAsB,QAAgD;CAC7E,MAAM,aAAa,OAAO,YAAY,SAAS,OAAO,aAAa,CAAC,iBAAiB,CAAC;CACtF,MAAM,sBAAsB,WAAW,MAAM,MAAM,EAAE,SAAS,oBAAoB;CAElF,MAAM,SAAS,EAAE,GAAG,OAAO,OAAO;CAClC,IAAI,uBAAuB,OAAO,WAAW,KAAA,GAC3C,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;EACA,OAAO,OAAO,UAAU,KAAA,IAAY,QAAQ,IAAI,OAAO;CACzD;AACF;AAEA,SAAS,gBAAwB,QAAwG;CACvI,IAAI,MAAM,QAAQ,MAAM,GACtB,OAAO,OAAO,IAAI,aAAa;CAGjC,OAAO,cAAc,MAAM;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,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/package.json
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kubb",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "5.0.0-beta.50",
|
|
4
|
+
"description": "Meta-package and entry point for Kubb — a plugin-based code generation framework for OpenAPI. Includes defineConfig, all public APIs, and serves as the gateway to the entire Kubb ecosystem.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-client",
|
|
7
|
-
"cli",
|
|
8
7
|
"code-generator",
|
|
9
8
|
"codegen",
|
|
10
9
|
"faker",
|
|
11
10
|
"kubb",
|
|
11
|
+
"meta-framework",
|
|
12
12
|
"msw",
|
|
13
|
-
"oas",
|
|
14
13
|
"openapi",
|
|
15
14
|
"plugin-system",
|
|
16
|
-
"plugins",
|
|
17
15
|
"react-query",
|
|
18
16
|
"sdk-generator",
|
|
19
17
|
"swagger",
|
|
20
18
|
"tanstack-query",
|
|
21
|
-
"type-safe",
|
|
22
19
|
"typescript",
|
|
23
20
|
"zod"
|
|
24
21
|
],
|
|
@@ -57,47 +54,31 @@
|
|
|
57
54
|
"registry": "https://registry.npmjs.org/"
|
|
58
55
|
},
|
|
59
56
|
"dependencies": {
|
|
60
|
-
"@kubb/adapter-oas": "5.0.0-beta.
|
|
61
|
-
"@kubb/cli": "5.0.0-beta.
|
|
62
|
-
"@kubb/core": "5.0.0-beta.
|
|
63
|
-
"@kubb/
|
|
64
|
-
"@kubb/
|
|
65
|
-
"@kubb/
|
|
57
|
+
"@kubb/adapter-oas": "5.0.0-beta.50",
|
|
58
|
+
"@kubb/cli": "5.0.0-beta.50",
|
|
59
|
+
"@kubb/core": "5.0.0-beta.50",
|
|
60
|
+
"@kubb/mcp": "5.0.0-beta.50",
|
|
61
|
+
"@kubb/middleware-barrel": "5.0.0-beta.50",
|
|
62
|
+
"@kubb/parser-md": "5.0.0-beta.50",
|
|
63
|
+
"@kubb/parser-ts": "5.0.0-beta.50",
|
|
64
|
+
"@kubb/renderer-jsx": "5.0.0-beta.50"
|
|
66
65
|
},
|
|
67
66
|
"devDependencies": {
|
|
68
67
|
"typescript": "^6.0.3",
|
|
69
68
|
"@internals/utils": "0.0.0"
|
|
70
69
|
},
|
|
71
|
-
"peerDependencies": {
|
|
72
|
-
"@kubb/agent": "5.0.0-beta.5",
|
|
73
|
-
"@kubb/mcp": "5.0.0-beta.5"
|
|
74
|
-
},
|
|
75
|
-
"peerDependenciesMeta": {
|
|
76
|
-
"@kubb/agent": {
|
|
77
|
-
"optional": true
|
|
78
|
-
},
|
|
79
|
-
"@kubb/mcp": {
|
|
80
|
-
"optional": true
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
"size-limit": [
|
|
84
|
-
{
|
|
85
|
-
"path": "./dist/*.js",
|
|
86
|
-
"limit": "510 KiB",
|
|
87
|
-
"gzip": true
|
|
88
|
-
}
|
|
89
|
-
],
|
|
90
70
|
"preferGlobal": true,
|
|
91
71
|
"engines": {
|
|
92
72
|
"node": ">=22"
|
|
93
73
|
},
|
|
94
74
|
"scripts": {
|
|
95
75
|
"build": "tsdown",
|
|
96
|
-
"clean": "
|
|
76
|
+
"clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
|
|
97
77
|
"lint": "oxlint .",
|
|
98
78
|
"lint:fix": "oxlint --fix .",
|
|
99
79
|
"release": "pnpm publish --no-git-check",
|
|
100
80
|
"release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
|
|
81
|
+
"release:stage": "pnpm stage publish --no-git-check",
|
|
101
82
|
"start": "tsdown --watch",
|
|
102
83
|
"test": "vitest --passWithNoTests",
|
|
103
84
|
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
package/src/defineConfig.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { isPromise, type PossiblePromise } from '@internals/utils'
|
|
2
2
|
import { adapterOas } from '@kubb/adapter-oas'
|
|
3
|
-
import type
|
|
3
|
+
import { cliReporter, type CLIOptions, fileReporter, fsCache, jsonReporter, type UserConfig } from '@kubb/core'
|
|
4
4
|
import { middlewareBarrel, middlewareBarrelName } from '@kubb/middleware-barrel'
|
|
5
5
|
import { parserTs, parserTsx } from '@kubb/parser-ts'
|
|
6
|
+
import { parserMd } from '@kubb/parser-md'
|
|
6
7
|
|
|
7
8
|
type AnyConfigResult = UserConfig<any> | Array<UserConfig<any>>
|
|
8
9
|
type ConfigInput = AnyConfigResult | Promise<AnyConfigResult> | ((cli: CLIOptions) => PossiblePromise<AnyConfigResult>)
|
|
@@ -15,15 +16,18 @@ type DefinedConfig<TConfig extends ConfigInput> = TConfig extends (cli: CLIOptio
|
|
|
15
16
|
: NormalizeConfig<TConfig>
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
|
-
* Applies default adapter, parsers, middleware, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
|
|
19
|
+
* Applies default `root`, adapter, parsers, middleware, `output.barrel`, `output.format`, and `output.lint` to a single user config when not set.
|
|
19
20
|
*
|
|
21
|
+
* - `root` defaults to `process.cwd()`
|
|
20
22
|
* - `adapter` defaults to `adapterOas()`
|
|
21
|
-
* - `parsers` defaults to `[parserTs, parserTsx]`
|
|
23
|
+
* - `parsers` defaults to `[parserTs, parserTsx, parserMd]`
|
|
24
|
+
* - `reporters` defaults to `[cliReporter, jsonReporter, fileReporter]`
|
|
22
25
|
* - `middleware` defaults to `[middlewareBarrel()]`
|
|
23
26
|
* - `output.barrel` defaults to `{ type: 'named' }` **only when `middlewareBarrel` is part of `middleware`**.
|
|
24
27
|
* When the user provides a custom middleware list without `middlewareBarrel`, `barrel` is left untouched.
|
|
25
|
-
* - `output.format` defaults to `
|
|
26
|
-
* - `output.lint` defaults to `
|
|
28
|
+
* - `output.format` defaults to `false`
|
|
29
|
+
* - `output.lint` defaults to `false`
|
|
30
|
+
* - `cache` defaults to `fsCache()`; pass `false` to turn caching off
|
|
27
31
|
*/
|
|
28
32
|
function applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {
|
|
29
33
|
const middleware = config.middleware?.length ? config.middleware : [middlewareBarrel()]
|
|
@@ -42,10 +46,13 @@ function applyDefaults<TInput>(config: UserConfig<TInput>): UserConfig<TInput> {
|
|
|
42
46
|
|
|
43
47
|
return {
|
|
44
48
|
...config,
|
|
49
|
+
root: config.root || process.cwd(),
|
|
45
50
|
adapter: config.adapter ?? adapterOas(),
|
|
46
|
-
parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx],
|
|
51
|
+
parsers: config.parsers?.length ? config.parsers : [parserTs, parserTsx, parserMd],
|
|
52
|
+
reporters: config.reporters?.length ? config.reporters : [cliReporter, jsonReporter, fileReporter],
|
|
47
53
|
middleware,
|
|
48
54
|
output,
|
|
55
|
+
cache: config.cache === undefined ? fsCache() : config.cache,
|
|
49
56
|
}
|
|
50
57
|
}
|
|
51
58
|
|
|
@@ -58,21 +65,43 @@ function normalizeConfig<TInput>(config: UserConfig<TInput> | Array<UserConfig<T
|
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
/**
|
|
61
|
-
*
|
|
68
|
+
* Defines a Kubb build configuration and applies sensible defaults so the
|
|
69
|
+
* minimal config stays small.
|
|
62
70
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
71
|
+
* Defaults applied when omitted:
|
|
72
|
+
* - `adapter` → `adapterOas()` (OpenAPI 2.0/3.0/3.1).
|
|
73
|
+
* - `parsers` → `[parserTs, parserTsx, parserMd]`.
|
|
74
|
+
* - `reporters` → `[cliReporter, jsonReporter, fileReporter]`.
|
|
75
|
+
* - `middleware` → `[middlewareBarrel()]`.
|
|
76
|
+
* - `output.barrel` → `{ type: 'named' }` only when `middlewareBarrel` is
|
|
77
|
+
* in the middleware list.
|
|
78
|
+
* - `output.format` and `output.lint` → `false`.
|
|
79
|
+
* - `cache` → `fsCache()` (local disk); pass `false` to turn caching off.
|
|
65
80
|
*
|
|
66
|
-
* Accepts
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* receiving the CLI options as argument
|
|
81
|
+
* Accepts a config object, an array of configs, a Promise resolving to one,
|
|
82
|
+
* or a function that receives the parsed CLI options and returns any of the
|
|
83
|
+
* above. The return type is preserved so async/array variants stay typed.
|
|
70
84
|
*
|
|
71
85
|
* @example
|
|
72
86
|
* ```ts
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
87
|
+
* import { defineConfig } from 'kubb'
|
|
88
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
89
|
+
*
|
|
90
|
+
* export default defineConfig({
|
|
91
|
+
* input: { path: './petStore.yaml' },
|
|
92
|
+
* output: { path: './src/gen' },
|
|
93
|
+
* plugins: [pluginTs()],
|
|
94
|
+
* })
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @example Function form with CLI options
|
|
98
|
+
* ```ts
|
|
99
|
+
* import { defineConfig } from 'kubb'
|
|
100
|
+
*
|
|
101
|
+
* export default defineConfig(({ input }) => ({
|
|
102
|
+
* input: { path: input ?? './petStore.yaml' },
|
|
103
|
+
* output: { path: './src/gen' },
|
|
104
|
+
* plugins: [],
|
|
76
105
|
* }))
|
|
77
106
|
* ```
|
|
78
107
|
*/
|
|
File without changes
|