@kubb/ast 5.0.0-beta.9 → 5.0.0-beta.91

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 CHANGED
@@ -1,14 +1,21 @@
1
- Copyright (c) 2026 Stijn Van Hulle
2
-
3
- This repository contains software under two licenses:
1
+ MIT License
4
2
 
5
- 1. Most of the code in this repository is licensed under the
6
- MIT License — see licenses/LICENSE-MIT for the full license text.
3
+ Copyright (c) 2026 Stijn Van Hulle
7
4
 
8
- 2. The following components are licensed under the
9
- GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later)
10
- see licenses/LICENSE-AGPL-3.0 for the full license text:
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
- - packages/agent (published as @kubb/agent)
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
- Each package's own LICENSE file or package.json specifies its applicable license.
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,16 @@
1
1
  <div align="center">
2
- <h1>@kubb/ast</h1>
3
2
  <a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
4
- <img width="180" src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/logo.png" alt="Kubb logo">
3
+ <img src="https://kubb.dev/og.png" alt="Kubb banner">
5
4
  </a>
6
5
 
7
6
  [![npm version][npm-version-src]][npm-version-href]
8
7
  [![npm downloads][npm-downloads-src]][npm-downloads-href]
9
- [![Coverage][coverage-src]][coverage-href]
8
+ [![Stars][stars-src]][stars-href]
10
9
  [![License][license-src]][license-href]
11
- [![Sponsors][sponsors-src]][sponsors-href]
10
+ [![Node][node-src]][node-href]
12
11
 
13
12
  <h4>
14
- <a href="https://kubb.dev/" target="_blank">Documentation</a>
13
+ <a href="https://kubb.dev" target="_blank">Documentation</a>
15
14
  <span> · </span>
16
15
  <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
17
16
  <span> · </span>
@@ -19,14 +18,26 @@
19
18
  </h4>
20
19
  </div>
21
20
 
22
- Spec-agnostic AST layer for Kubb. Defines nodes, visitor pattern, factory functions, and type guards used across codegen plugins.
21
+ <br />
22
+
23
+ # @kubb/ast
24
+
25
+ ### Spec-agnostic AST layer for Kubb
26
+
27
+ Defines the node tree, visitor pattern, factory functions, and type guards used across every Kubb code generation plugin.
23
28
 
24
29
  ## Imports
25
30
 
26
- | Path | Contents |
27
- | ----------------- | ------------------------------------------------------------------- |
28
- | `@kubb/ast` | Runtime: factory functions, guards, visitor, ref helpers, constants |
29
- | `@kubb/ast/types` | Types only: all node interfaces, type aliases, visitor types |
31
+ | Path | Contents |
32
+ | ------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
33
+ | `@kubb/ast` | Runtime: node definitions, guards, visitor, macro engine, string and ref helpers, constants |
34
+ | `ast.factory` (via `@kubb/ast`) | Node constructors (`createSchema`, `createFile`, and friends), the `ts.factory` analogue |
35
+ | `@kubb/ast/types` | Types only: all node interfaces, type aliases, visitor types |
36
+ | `kubb/kit` | Re-exports the `ast` and `factory` namespaces, the way most Kubb code reaches the AST without a direct dependency |
37
+
38
+ `@kubb/ast` is an internal library. Inside the Kubb ecosystem the whole surface travels on the `ast` namespace from `kubb/kit`, so plugins and generators reach it there instead of depending on this package directly. The examples below import from `@kubb/ast` for clarity; through `kubb/kit` the same calls read as `ast.walk`, `ast.factory.createSchema`, and so on.
39
+
40
+ The macro presets (`macroDiscriminatorEnum`, `macroSimplifyUnion`, `macroEnumName`) and the string, identifier, and ref helpers live on the root `@kubb/ast` export. They no longer ship as separate `@kubb/ast/macros` and `@kubb/ast/utils` subpaths.
30
41
 
31
42
  ## Node tree
32
43
 
@@ -51,10 +62,14 @@ SchemaNode (discriminated union)
51
62
 
52
63
  ### Factory
53
64
 
65
+ Constructors are available as `ast.factory` from `@kubb/ast`, mirroring `ts.factory.createX`.
66
+
54
67
  ```ts
55
- import { createRoot, createOperation, createSchema, createProperty } from '@kubb/ast'
68
+ import { ast } from '@kubb/ast'
69
+
70
+ const { createInput, createSchema, createProperty } = ast.factory
56
71
 
57
- const root = createRoot({
72
+ const root = createInput({
58
73
  schemas: [
59
74
  createSchema({
60
75
  name: 'Pet',
@@ -106,11 +121,11 @@ const types = collect<string>(root, {
106
121
  ### Guards
107
122
 
108
123
  ```ts
109
- import { isSchemaNode, narrowSchema } from '@kubb/ast'
124
+ import { narrowSchema, schemaDef } from '@kubb/ast'
110
125
  import type { Node } from '@kubb/ast/types'
111
126
 
112
127
  function process(node: Node) {
113
- if (isSchemaNode(node)) {
128
+ if (schemaDef.is(node)) {
114
129
  const obj = narrowSchema(node, 'object')
115
130
  obj?.properties?.forEach((p) => console.log(p.name))
116
131
  }
@@ -120,17 +135,27 @@ function process(node: Node) {
120
135
  ### Refs
121
136
 
122
137
  ```ts
123
- import { buildRefMap, resolveRef } from '@kubb/ast'
138
+ import { extractRefName } from '@kubb/ast'
124
139
 
125
- const refMap = buildRefMap(root)
126
- const pet = resolveRef(refMap, 'Pet')
140
+ extractRefName('#/components/schemas/Pet') // 'Pet'
127
141
  ```
128
142
 
143
+ ## Adding a node
144
+
145
+ Adding a node touches three files. The barrels and visitor tables derive the rest.
146
+
147
+ 1. Define the node in its own `src/nodes/*.ts` file. Call `defineNode` and export the resulting `fooDef`, the `createFoo` constructor, and the node's type.
148
+ 2. Add `fooDef` to the `nodeDefs` array in `src/registry.ts`.
149
+ 3. Re-export `createFoo` from `src/factory.ts`.
150
+
151
+ Everything else follows from there. `@kubb/ast/types` picks up the node type through `export type *`, the `@kubb/ast` barrel picks up `fooDef` through `export * from './registry.ts'`, and the visitor tables (`VISITOR_KEYS`, `VISITOR_KEY_BY_KIND`, `nodeRebuilders`) come from the def's `children`, `visitorKey`, and `rebuild` fields. `registry.test.ts` fails when a def has no matching `factory.create*`, so missing wiring is caught in CI.
152
+
129
153
  ## Supporting Kubb
130
154
 
131
- Kubb is an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
155
+ Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
132
156
 
133
157
  - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
158
+ - [See sponsorship tiers and our sponsors](https://kubb.dev/sponsors)
134
159
 
135
160
  <p align="center">
136
161
  <a href="https://github.com/sponsors/stijnvanhulle">
@@ -138,15 +163,19 @@ Kubb is an MIT-licensed open source project with its ongoing development made po
138
163
  </a>
139
164
  </p>
140
165
 
166
+ ## License
167
+
168
+ [MIT](https://github.com/kubb-labs/kubb/blob/main/licenses/LICENSE-MIT)
169
+
141
170
  <!-- Badges -->
142
171
 
143
- [npm-version-src]: https://img.shields.io/npm/v/@kubb/ast?flat&colorA=18181B&colorB=f58517
144
- [npm-version-href]: https://npmjs.com/package/@kubb/ast
145
- [npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/ast?flat&colorA=18181B&colorB=f58517
146
- [npm-downloads-href]: https://npmjs.com/package/@kubb/ast
147
- [license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517
172
+ [npm-version-src]: https://shieldcn.dev/npm/v/@kubb/ast.svg?variant=secondary&size=xs&theme=zinc&mode=dark
173
+ [npm-version-href]: https://npmx.dev/package/@kubb/ast
174
+ [npm-downloads-src]: https://shieldcn.dev/npm/dm/@kubb/ast.svg?variant=secondary&size=xs&theme=zinc&mode=dark
175
+ [npm-downloads-href]: https://npmx.dev/package/@kubb/ast
176
+ [stars-src]: https://shieldcn.dev/github/stars/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
177
+ [stars-href]: https://github.com/kubb-labs/kubb
178
+ [license-src]: https://shieldcn.dev/npm/license/@kubb/ast.svg?variant=secondary&size=xs&theme=zinc
148
179
  [license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
149
- [coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
150
- [coverage-href]: https://www.npmjs.com/package/@kubb/ast
151
- [sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
152
- [sponsors-href]: https://github.com/sponsors/stijnvanhulle/
180
+ [node-src]: https://shieldcn.dev/npm/node/@kubb/ast.svg?variant=secondary&size=xs&theme=zinc&mode=dark
181
+ [node-href]: https://npmx.dev/package/@kubb/ast