@kubb/ast 5.0.0-alpha.9 → 5.0.0-beta.10
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 +25 -11
- package/dist/index.cjs +2035 -531
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3420 -24
- package/dist/index.js +1970 -519
- package/dist/index.js.map +1 -1
- package/package.json +23 -35
- package/src/constants.ts +133 -15
- package/src/factory.ts +677 -21
- package/src/guards.ts +77 -9
- package/src/index.ts +45 -6
- package/src/infer.ts +130 -0
- package/src/mocks.ts +95 -25
- package/src/nodes/base.ts +44 -4
- package/src/nodes/code.ts +304 -0
- package/src/nodes/file.ts +230 -0
- package/src/nodes/function.ts +223 -0
- package/src/nodes/http.ts +17 -5
- package/src/nodes/index.ts +47 -7
- package/src/nodes/operation.ts +84 -6
- package/src/nodes/output.ts +26 -0
- package/src/nodes/parameter.ts +27 -1
- package/src/nodes/property.ts +23 -1
- package/src/nodes/response.ts +28 -2
- package/src/nodes/root.ts +34 -12
- package/src/nodes/schema.ts +419 -42
- package/src/printer.ts +152 -59
- package/src/refs.ts +39 -7
- package/src/resolvers.ts +45 -0
- package/src/transformers.ts +159 -0
- package/src/types.ts +32 -4
- package/src/utils.ts +880 -13
- package/src/visitor.ts +411 -96
- package/dist/types.cjs +0 -0
- package/dist/types.d.ts +0 -2
- package/dist/types.js +0 -1
- package/dist/visitor-Ci6rmtT9.d.ts +0 -702
package/README.md
CHANGED
|
@@ -23,10 +23,10 @@ Spec-agnostic AST layer for Kubb. Defines nodes, visitor pattern, factory functi
|
|
|
23
23
|
|
|
24
24
|
## Imports
|
|
25
25
|
|
|
26
|
-
| Path
|
|
27
|
-
|
|
28
|
-
| `@kubb/ast`
|
|
29
|
-
| `@kubb/ast/types` | Types only: all node interfaces, type aliases, visitor types
|
|
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 |
|
|
30
30
|
|
|
31
31
|
## Node tree
|
|
32
32
|
|
|
@@ -60,8 +60,16 @@ const root = createRoot({
|
|
|
60
60
|
name: 'Pet',
|
|
61
61
|
type: 'object',
|
|
62
62
|
properties: [
|
|
63
|
-
createProperty({
|
|
64
|
-
|
|
63
|
+
createProperty({
|
|
64
|
+
name: 'id',
|
|
65
|
+
schema: createSchema({ type: 'integer' }),
|
|
66
|
+
required: true,
|
|
67
|
+
}),
|
|
68
|
+
createProperty({
|
|
69
|
+
name: 'name',
|
|
70
|
+
schema: createSchema({ type: 'string' }),
|
|
71
|
+
required: true,
|
|
72
|
+
}),
|
|
65
73
|
],
|
|
66
74
|
}),
|
|
67
75
|
],
|
|
@@ -75,17 +83,23 @@ import { walk, transform, collect } from '@kubb/ast'
|
|
|
75
83
|
|
|
76
84
|
// Side effects
|
|
77
85
|
await walk(root, {
|
|
78
|
-
schema(node) {
|
|
86
|
+
schema(node) {
|
|
87
|
+
console.log(node.type)
|
|
88
|
+
},
|
|
79
89
|
})
|
|
80
90
|
|
|
81
91
|
// Immutable transformation
|
|
82
92
|
const updated = transform(root, {
|
|
83
|
-
schema(node) {
|
|
93
|
+
schema(node) {
|
|
94
|
+
return { ...node, description: 'generated' }
|
|
95
|
+
},
|
|
84
96
|
})
|
|
85
97
|
|
|
86
98
|
// Extraction
|
|
87
99
|
const types = collect<string>(root, {
|
|
88
|
-
schema(node) {
|
|
100
|
+
schema(node) {
|
|
101
|
+
return node.type
|
|
102
|
+
},
|
|
89
103
|
})
|
|
90
104
|
```
|
|
91
105
|
|
|
@@ -98,7 +112,7 @@ import type { Node } from '@kubb/ast/types'
|
|
|
98
112
|
function process(node: Node) {
|
|
99
113
|
if (isSchemaNode(node)) {
|
|
100
114
|
const obj = narrowSchema(node, 'object')
|
|
101
|
-
obj?.properties?.forEach(p => console.log(p.name))
|
|
115
|
+
obj?.properties?.forEach((p) => console.log(p.name))
|
|
102
116
|
}
|
|
103
117
|
}
|
|
104
118
|
```
|
|
@@ -114,7 +128,7 @@ const pet = resolveRef(refMap, 'Pet')
|
|
|
114
128
|
|
|
115
129
|
## Supporting Kubb
|
|
116
130
|
|
|
117
|
-
Kubb
|
|
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:
|
|
118
132
|
|
|
119
133
|
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
120
134
|
|