@kubb/core 5.0.0-alpha.72 → 5.0.0-alpha.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -18
- package/dist/index.cjs +49 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +14 -7
- package/dist/index.js +49 -28
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +6 -6
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.ts +7 -7
- package/dist/mocks.js +6 -6
- package/dist/mocks.js.map +1 -1
- package/dist/{types-CNhttEMO.d.ts → types-CuNocrbJ.d.ts} +559 -326
- package/package.json +5 -5
- package/src/Kubb.ts +44 -71
- package/src/createAdapter.ts +13 -6
- package/src/createKubb.ts +2 -0
- package/src/createStorage.ts +13 -1
- package/src/defineGenerator.ts +7 -14
- package/src/defineMiddleware.ts +9 -11
- package/src/defineParser.ts +2 -3
- package/src/definePlugin.ts +9 -9
- package/src/mocks.ts +6 -6
- package/src/types.ts +474 -216
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<a href="https://kubb.dev
|
|
2
|
+
<a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
|
|
3
3
|
<img width="180" src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/logo.png" alt="Kubb logo">
|
|
4
4
|
</a>
|
|
5
5
|
|
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
[![License][license-src]][license-href]
|
|
10
10
|
[![Sponsors][sponsors-src]][sponsors-href]
|
|
11
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.**
|
|
15
|
+
|
|
12
16
|
<h4>
|
|
13
|
-
<a href="https://
|
|
14
|
-
<span> · </span>
|
|
15
|
-
<a href="https://kubb.dev/kubb" target="_blank">Documentation</a>
|
|
17
|
+
<a href="https://kubb.dev" target="_blank">Documentation</a>
|
|
16
18
|
<span> · </span>
|
|
17
19
|
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
|
|
18
20
|
<span> · </span>
|
|
@@ -22,6 +24,14 @@
|
|
|
22
24
|
|
|
23
25
|
<br />
|
|
24
26
|
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install @kubb/core
|
|
31
|
+
# or
|
|
32
|
+
pnpm add @kubb/core
|
|
33
|
+
```
|
|
34
|
+
|
|
25
35
|
## Quick Start
|
|
26
36
|
|
|
27
37
|
Get started with Kubb in seconds:
|
|
@@ -47,14 +57,13 @@ See the [documentation](https://kubb.dev) for detailed usage and advanced featur
|
|
|
47
57
|
|
|
48
58
|
## Features
|
|
49
59
|
|
|
50
|
-
- Works with Node.js
|
|
51
|
-
- Convert Swagger 2.0, OpenAPI 3.0, and OpenAPI 3.1 to TypeScript,
|
|
52
|
-
-
|
|
53
|
-
- CLI support with progress bar and detailed logs.
|
|
60
|
+
- Works with Node.js 22+ and TypeScript 6.
|
|
61
|
+
- Convert Swagger 2.0, OpenAPI 3.0, and OpenAPI 3.1 to TypeScript types, API clients, and more via the [plugin ecosystem](https://github.com/kubb-labs/kubb-plugins).
|
|
62
|
+
- Extensible plugin and middleware system for customizing and composing code generation.
|
|
63
|
+
- CLI support with interactive setup, progress bar, and detailed logs.
|
|
54
64
|
- Model Context Protocol (MCP) server for AI assistants like [Claude](https://claude.ai), [Cursor](https://cursor.sh), and other MCP-compatible tools.
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
- And so much more ...
|
|
65
|
+
- JSX-based renderer (`@kubb/renderer-jsx`) for building custom plugin output.
|
|
66
|
+
- Barrel file generation via the `@kubb/middleware-barrel` middleware.
|
|
58
67
|
|
|
59
68
|
## Supporting Kubb
|
|
60
69
|
|
|
@@ -151,13 +160,6 @@ Kubb is an open source project with its ongoing development made possible entire
|
|
|
151
160
|
<!-- markdownlint-restore -->
|
|
152
161
|
<!-- prettier-ignore-end -->
|
|
153
162
|
|
|
154
|
-
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
155
|
-
<!-- prettier-ignore-start -->
|
|
156
|
-
<!-- markdownlint-disable -->
|
|
157
|
-
|
|
158
|
-
<!-- markdownlint-restore -->
|
|
159
|
-
<!-- prettier-ignore-end -->
|
|
160
|
-
|
|
161
163
|
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
162
164
|
|
|
163
165
|
## License
|
package/dist/index.cjs
CHANGED
|
@@ -496,19 +496,29 @@ var URLPath = class {
|
|
|
496
496
|
//#endregion
|
|
497
497
|
//#region src/createAdapter.ts
|
|
498
498
|
/**
|
|
499
|
-
*
|
|
499
|
+
* Factory for implementing custom adapters that translate non-OpenAPI specs into Kubb's AST.
|
|
500
|
+
*
|
|
501
|
+
* Use this to support GraphQL schemas, gRPC definitions, AsyncAPI, or custom domain-specific languages.
|
|
502
|
+
* Built-in adapters include `@kubb/adapter-oas` for OpenAPI and Swagger documents.
|
|
503
|
+
*
|
|
504
|
+
* @note Adapters must parse their input format to Kubb's `InputNode` structure.
|
|
500
505
|
*
|
|
501
506
|
* @example
|
|
507
|
+
* ```ts
|
|
502
508
|
* export const myAdapter = createAdapter<MyAdapter>((options) => {
|
|
503
509
|
* return {
|
|
504
510
|
* name: 'my-adapter',
|
|
505
511
|
* options,
|
|
506
|
-
* async parse(source) {
|
|
512
|
+
* async parse(source) {
|
|
513
|
+
* // Transform source format to InputNode
|
|
514
|
+
* return { ... }
|
|
515
|
+
* },
|
|
507
516
|
* }
|
|
508
517
|
* })
|
|
509
518
|
*
|
|
510
|
-
* //
|
|
519
|
+
* // Instantiate:
|
|
511
520
|
* const adapter = myAdapter({ validate: true })
|
|
521
|
+
* ```
|
|
512
522
|
*/
|
|
513
523
|
function createAdapter(build) {
|
|
514
524
|
return (options) => build(options ?? {});
|
|
@@ -688,9 +698,17 @@ var FileProcessor = class {
|
|
|
688
698
|
//#endregion
|
|
689
699
|
//#region src/createStorage.ts
|
|
690
700
|
/**
|
|
691
|
-
*
|
|
701
|
+
* Factory for implementing custom storage backends that control where generated files are written.
|
|
702
|
+
*
|
|
703
|
+
* Takes a builder function `(options: TOptions) => Storage` and returns a factory `(options?: TOptions) => Storage`.
|
|
704
|
+
* Kubb provides filesystem and in-memory implementations out of the box.
|
|
705
|
+
*
|
|
706
|
+
* @note Call the returned factory with optional options to instantiate the storage adapter.
|
|
692
707
|
*
|
|
693
708
|
* @example
|
|
709
|
+
* ```ts
|
|
710
|
+
* import { createStorage } from '@kubb/core'
|
|
711
|
+
*
|
|
694
712
|
* export const memoryStorage = createStorage(() => {
|
|
695
713
|
* const store = new Map<string, string>()
|
|
696
714
|
* return {
|
|
@@ -706,6 +724,10 @@ var FileProcessor = class {
|
|
|
706
724
|
* async clear(base) { if (!base) store.clear() },
|
|
707
725
|
* }
|
|
708
726
|
* })
|
|
727
|
+
*
|
|
728
|
+
* // Instantiate:
|
|
729
|
+
* const storage = memoryStorage()
|
|
730
|
+
* ```
|
|
709
731
|
*/
|
|
710
732
|
function createStorage(build) {
|
|
711
733
|
return (options) => build(options ?? {});
|
|
@@ -795,7 +817,7 @@ const fsStorage = createStorage(() => ({
|
|
|
795
817
|
}));
|
|
796
818
|
//#endregion
|
|
797
819
|
//#region package.json
|
|
798
|
-
var version = "5.0.0-alpha.
|
|
820
|
+
var version = "5.0.0-alpha.74";
|
|
799
821
|
//#endregion
|
|
800
822
|
//#region src/utils/diagnostics.ts
|
|
801
823
|
/**
|
|
@@ -862,6 +884,8 @@ async function setup(userConfig, options = {}) {
|
|
|
862
884
|
parsers: userConfig.parsers ?? [],
|
|
863
885
|
adapter: userConfig.adapter,
|
|
864
886
|
output: {
|
|
887
|
+
format: false,
|
|
888
|
+
lint: false,
|
|
865
889
|
write: true,
|
|
866
890
|
extension: require_PluginDriver.DEFAULT_EXTENSION,
|
|
867
891
|
defaultBanner: require_PluginDriver.DEFAULT_BANNER,
|
|
@@ -1273,14 +1297,17 @@ function defineLogger(logger) {
|
|
|
1273
1297
|
//#endregion
|
|
1274
1298
|
//#region src/defineMiddleware.ts
|
|
1275
1299
|
/**
|
|
1276
|
-
* Creates a middleware factory using the hook-style
|
|
1300
|
+
* Creates a middleware factory using the hook-style `hooks` API.
|
|
1277
1301
|
*
|
|
1278
|
-
*
|
|
1279
|
-
*
|
|
1280
|
-
*
|
|
1302
|
+
* Middleware handlers fire after all plugin handlers for any given event, making them ideal for post-processing, logging, and auditing.
|
|
1303
|
+
* Per-build state (such as accumulators) belongs inside the factory closure so each `createKubb` invocation gets its own isolated instance.
|
|
1304
|
+
*
|
|
1305
|
+
* @note The factory can accept typed options. See examples for using options and per-build state patterns.
|
|
1281
1306
|
*
|
|
1282
1307
|
* @example
|
|
1283
1308
|
* ```ts
|
|
1309
|
+
* import { defineMiddleware } from '@kubb/core'
|
|
1310
|
+
*
|
|
1284
1311
|
* // Stateless middleware
|
|
1285
1312
|
* export const logMiddleware = defineMiddleware(() => ({
|
|
1286
1313
|
* name: 'log-middleware',
|
|
@@ -1292,10 +1319,10 @@ function defineLogger(logger) {
|
|
|
1292
1319
|
* }))
|
|
1293
1320
|
*
|
|
1294
1321
|
* // Middleware with options and per-build state
|
|
1295
|
-
* export const
|
|
1322
|
+
* export const prefixMiddleware = defineMiddleware((options: { prefix: string } = { prefix: '' }) => {
|
|
1296
1323
|
* const seen = new Set<string>()
|
|
1297
1324
|
* return {
|
|
1298
|
-
* name: '
|
|
1325
|
+
* name: 'prefix-middleware',
|
|
1299
1326
|
* hooks: {
|
|
1300
1327
|
* 'kubb:plugin:end'({ plugin }) {
|
|
1301
1328
|
* seen.add(`${options.prefix}${plugin.name}`)
|
|
@@ -1303,11 +1330,6 @@ function defineLogger(logger) {
|
|
|
1303
1330
|
* },
|
|
1304
1331
|
* }
|
|
1305
1332
|
* })
|
|
1306
|
-
*
|
|
1307
|
-
* // Usage in kubb.config.ts:
|
|
1308
|
-
* export default defineConfig({
|
|
1309
|
-
* middleware: [logMiddleware(), myMiddleware({ prefix: 'pfx:' })],
|
|
1310
|
-
* })
|
|
1311
1333
|
* ```
|
|
1312
1334
|
*/
|
|
1313
1335
|
function defineMiddleware(factory) {
|
|
@@ -1316,10 +1338,9 @@ function defineMiddleware(factory) {
|
|
|
1316
1338
|
//#endregion
|
|
1317
1339
|
//#region src/defineParser.ts
|
|
1318
1340
|
/**
|
|
1319
|
-
* Defines a parser with type safety.
|
|
1341
|
+
* Defines a parser with type safety. Creates parsers that transform generated files to strings based on their extension.
|
|
1320
1342
|
*
|
|
1321
|
-
*
|
|
1322
|
-
* based on their extension.
|
|
1343
|
+
* @note Call the returned factory with optional options to instantiate the parser.
|
|
1323
1344
|
*
|
|
1324
1345
|
* @example
|
|
1325
1346
|
* ```ts
|
|
@@ -1341,23 +1362,23 @@ function defineParser(parser) {
|
|
|
1341
1362
|
//#endregion
|
|
1342
1363
|
//#region src/definePlugin.ts
|
|
1343
1364
|
/**
|
|
1344
|
-
*
|
|
1365
|
+
* Wraps a factory function and returns a typed `Plugin` with lifecycle handlers grouped under `hooks`.
|
|
1345
1366
|
*
|
|
1346
|
-
*
|
|
1347
|
-
*
|
|
1348
|
-
* `kubb.config.ts`.
|
|
1367
|
+
* Handlers live in a single `hooks` object (inspired by Astro integrations).
|
|
1368
|
+
* All lifecycle events from `KubbHooks` are available for subscription.
|
|
1349
1369
|
*
|
|
1350
|
-
*
|
|
1351
|
-
*
|
|
1370
|
+
* @note For real plugins, use a `PluginFactoryOptions` type parameter to get type-safe context in `kubb:plugin:setup`.
|
|
1371
|
+
* Plugin names should follow the convention `plugin-<feature>` (e.g., `plugin-react-query`, `plugin-zod`).
|
|
1352
1372
|
*
|
|
1353
1373
|
* @example
|
|
1354
1374
|
* ```ts
|
|
1355
|
-
*
|
|
1356
|
-
*
|
|
1375
|
+
* import { definePlugin } from '@kubb/core'
|
|
1376
|
+
*
|
|
1377
|
+
* export const pluginTs = definePlugin((options: { prefix?: string } = {}) => ({
|
|
1357
1378
|
* name: 'plugin-ts',
|
|
1358
1379
|
* hooks: {
|
|
1359
1380
|
* 'kubb:plugin:setup'(ctx) {
|
|
1360
|
-
* ctx.setResolver(resolverTs)
|
|
1381
|
+
* ctx.setResolver(resolverTs)
|
|
1361
1382
|
* },
|
|
1362
1383
|
* },
|
|
1363
1384
|
* }))
|