@kubb/ast 5.0.0-beta.8 → 5.0.0-beta.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +17 -10
- package/README.md +53 -27
- package/dist/index.cjs +1726 -1593
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +357 -3272
- package/dist/index.js +1663 -1555
- package/dist/index.js.map +1 -1
- package/dist/rolldown-runtime-CNktS9qV.js +17 -0
- package/dist/types-XcYJovdT.d.ts +2903 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +1 -0
- package/package.json +9 -5
- package/dist/chunk--u3MIqq1.js +0 -8
- package/src/constants.ts +0 -228
- package/src/factory.ts +0 -742
- package/src/guards.ts +0 -110
- package/src/index.ts +0 -46
- package/src/infer.ts +0 -130
- package/src/mocks.ts +0 -176
- package/src/nodes/base.ts +0 -56
- package/src/nodes/code.ts +0 -304
- package/src/nodes/file.ts +0 -230
- package/src/nodes/function.ts +0 -223
- package/src/nodes/http.ts +0 -119
- package/src/nodes/index.ts +0 -86
- package/src/nodes/operation.ts +0 -111
- package/src/nodes/output.ts +0 -26
- package/src/nodes/parameter.ts +0 -41
- package/src/nodes/property.ts +0 -34
- package/src/nodes/response.ts +0 -43
- package/src/nodes/root.ts +0 -64
- package/src/nodes/schema.ts +0 -656
- package/src/printer.ts +0 -250
- package/src/refs.ts +0 -67
- package/src/resolvers.ts +0 -45
- package/src/transformers.ts +0 -159
- package/src/types.ts +0 -70
- package/src/utils.ts +0 -915
- package/src/visitor.ts +0 -592
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,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
|
|
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
|
-
[![
|
|
8
|
+
[![Stars][stars-src]][stars-href]
|
|
10
9
|
[![License][license-src]][license-href]
|
|
11
|
-
[![
|
|
10
|
+
[![Node][node-src]][node-href]
|
|
12
11
|
|
|
13
12
|
<h4>
|
|
14
|
-
<a href="https://kubb.dev
|
|
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,23 @@
|
|
|
19
18
|
</h4>
|
|
20
19
|
</div>
|
|
21
20
|
|
|
22
|
-
|
|
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
|
|
27
|
-
|
|
|
28
|
-
| `@kubb/ast`
|
|
29
|
-
| `@kubb/ast
|
|
31
|
+
| Path | Contents |
|
|
32
|
+
| ------------------------------- | ---------------------------------------------------------------------------------------- |
|
|
33
|
+
| `@kubb/ast` | Runtime: node definitions, guards, visitor, macro engine, constants |
|
|
34
|
+
| `ast.factory` (via `@kubb/ast`) | Node constructors (`createSchema`, `createFile`, and friends), the `ts.factory` analogue |
|
|
35
|
+
| `@kubb/ast/macros` | Built-in macro presets: `macroDiscriminatorEnum`, `macroSimplifyUnion`, `macroEnumName` |
|
|
36
|
+
| `@kubb/ast/types` | Types only: all node interfaces, type aliases, visitor types |
|
|
37
|
+
| `@kubb/ast/utils` | Spec-agnostic string and identifier helpers, ref helpers |
|
|
30
38
|
|
|
31
39
|
## Node tree
|
|
32
40
|
|
|
@@ -51,10 +59,14 @@ SchemaNode (discriminated union)
|
|
|
51
59
|
|
|
52
60
|
### Factory
|
|
53
61
|
|
|
62
|
+
Constructors are available as `ast.factory` from `@kubb/ast`, mirroring `ts.factory.createX`.
|
|
63
|
+
|
|
54
64
|
```ts
|
|
55
|
-
import {
|
|
65
|
+
import { ast } from '@kubb/ast'
|
|
66
|
+
|
|
67
|
+
const { createInput, createSchema, createProperty } = ast.factory
|
|
56
68
|
|
|
57
|
-
const root =
|
|
69
|
+
const root = createInput({
|
|
58
70
|
schemas: [
|
|
59
71
|
createSchema({
|
|
60
72
|
name: 'Pet',
|
|
@@ -106,11 +118,11 @@ const types = collect<string>(root, {
|
|
|
106
118
|
### Guards
|
|
107
119
|
|
|
108
120
|
```ts
|
|
109
|
-
import {
|
|
121
|
+
import { narrowSchema, schemaDef } from '@kubb/ast'
|
|
110
122
|
import type { Node } from '@kubb/ast/types'
|
|
111
123
|
|
|
112
124
|
function process(node: Node) {
|
|
113
|
-
if (
|
|
125
|
+
if (schemaDef.is(node)) {
|
|
114
126
|
const obj = narrowSchema(node, 'object')
|
|
115
127
|
obj?.properties?.forEach((p) => console.log(p.name))
|
|
116
128
|
}
|
|
@@ -120,17 +132,27 @@ function process(node: Node) {
|
|
|
120
132
|
### Refs
|
|
121
133
|
|
|
122
134
|
```ts
|
|
123
|
-
import {
|
|
135
|
+
import { extractRefName } from '@kubb/ast/utils'
|
|
124
136
|
|
|
125
|
-
|
|
126
|
-
const pet = resolveRef(refMap, 'Pet')
|
|
137
|
+
extractRefName('#/components/schemas/Pet') // 'Pet'
|
|
127
138
|
```
|
|
128
139
|
|
|
140
|
+
## Adding a node
|
|
141
|
+
|
|
142
|
+
Adding a node touches three files. The barrels and visitor tables derive the rest.
|
|
143
|
+
|
|
144
|
+
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.
|
|
145
|
+
2. Add `fooDef` to the `nodeDefs` array in `src/registry.ts`.
|
|
146
|
+
3. Re-export `createFoo` from `src/factory.ts`.
|
|
147
|
+
|
|
148
|
+
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.
|
|
149
|
+
|
|
129
150
|
## Supporting Kubb
|
|
130
151
|
|
|
131
|
-
Kubb is an
|
|
152
|
+
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
153
|
|
|
133
154
|
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
155
|
+
- [See sponsorship tiers and our sponsors](https://kubb.dev/sponsors)
|
|
134
156
|
|
|
135
157
|
<p align="center">
|
|
136
158
|
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
@@ -138,15 +160,19 @@ Kubb is an MIT-licensed open source project with its ongoing development made po
|
|
|
138
160
|
</a>
|
|
139
161
|
</p>
|
|
140
162
|
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
[MIT](https://github.com/kubb-labs/kubb/blob/main/licenses/LICENSE-MIT)
|
|
166
|
+
|
|
141
167
|
<!-- Badges -->
|
|
142
168
|
|
|
143
|
-
[npm-version-src]: https://
|
|
144
|
-
[npm-version-href]: https://
|
|
145
|
-
[npm-downloads-src]: https://
|
|
146
|
-
[npm-downloads-href]: https://
|
|
147
|
-
[
|
|
169
|
+
[npm-version-src]: https://shieldcn.dev/npm/v/@kubb/ast.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
170
|
+
[npm-version-href]: https://npmx.dev/package/@kubb/ast
|
|
171
|
+
[npm-downloads-src]: https://shieldcn.dev/npm/dm/@kubb/ast.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
172
|
+
[npm-downloads-href]: https://npmx.dev/package/@kubb/ast
|
|
173
|
+
[stars-src]: https://shieldcn.dev/github/stars/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
174
|
+
[stars-href]: https://github.com/kubb-labs/kubb
|
|
175
|
+
[license-src]: https://shieldcn.dev/npm/license/@kubb/ast.svg?variant=secondary&size=xs&theme=zinc
|
|
148
176
|
[license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
|
|
149
|
-
[
|
|
150
|
-
[
|
|
151
|
-
[sponsors-src]: https://img.shields.io/github/sponsors/stijnvanhulle?style=flat&colorA=18181B&colorB=f58517
|
|
152
|
-
[sponsors-href]: https://github.com/sponsors/stijnvanhulle/
|
|
177
|
+
[node-src]: https://shieldcn.dev/npm/node/@kubb/ast.svg?variant=secondary&size=xs&theme=zinc&mode=dark
|
|
178
|
+
[node-href]: https://npmx.dev/package/@kubb/ast
|