@kubb/ast 5.18.5 → 5.18.6
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 +8 -8
- package/dist/index.cjs +1015 -624
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1495 -1315
- package/dist/index.d.ts +1495 -1315
- package/dist/index.js +1082 -751
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ Defines the node tree, visitor pattern, factory functions, and type guards used
|
|
|
34
34
|
| `ast.factory` (via `@kubb/ast`) | Node constructors (`createSchema`, `createFile`, and friends), the `ts.factory` analogue |
|
|
35
35
|
| `kubb/kit` | Re-exports the `ast` and `factory` namespaces, the way most Kubb code reaches the AST without a direct dependency |
|
|
36
36
|
|
|
37
|
-
`@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.transform`, `ast.factory.createSchema`, and so on.
|
|
37
|
+
`@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.node.transform`, `ast.factory.createSchema`, and so on.
|
|
38
38
|
|
|
39
39
|
## Node tree
|
|
40
40
|
|
|
@@ -91,17 +91,17 @@ const root = createInput({
|
|
|
91
91
|
### Visitor
|
|
92
92
|
|
|
93
93
|
```ts
|
|
94
|
-
import {
|
|
94
|
+
import { ast } from '@kubb/ast'
|
|
95
95
|
|
|
96
96
|
// Immutable transformation
|
|
97
|
-
const updated = transform(root, {
|
|
97
|
+
const updated = ast.node.transform(root, {
|
|
98
98
|
schema(node) {
|
|
99
99
|
return { ...node, description: 'generated' }
|
|
100
100
|
},
|
|
101
101
|
})
|
|
102
102
|
|
|
103
103
|
// Extraction
|
|
104
|
-
const types =
|
|
104
|
+
const types = ast.node.collect<string>(root, {
|
|
105
105
|
schema(node) {
|
|
106
106
|
return node.type
|
|
107
107
|
},
|
|
@@ -111,12 +111,12 @@ const types = collectSync<string>(root, {
|
|
|
111
111
|
### Guards
|
|
112
112
|
|
|
113
113
|
```ts
|
|
114
|
-
import {
|
|
114
|
+
import { ast } from '@kubb/ast'
|
|
115
115
|
import type { Node } from '@kubb/ast'
|
|
116
116
|
|
|
117
117
|
function process(node: Node) {
|
|
118
118
|
if (node.kind === 'Schema') {
|
|
119
|
-
const obj =
|
|
119
|
+
const obj = ast.schema.narrow(node, 'object')
|
|
120
120
|
obj?.properties?.forEach((p) => console.log(p.name))
|
|
121
121
|
}
|
|
122
122
|
}
|
|
@@ -125,9 +125,9 @@ function process(node: Node) {
|
|
|
125
125
|
### Refs
|
|
126
126
|
|
|
127
127
|
```ts
|
|
128
|
-
import {
|
|
128
|
+
import { ast } from '@kubb/ast'
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
ast.ref.getName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' }) // 'Pet'
|
|
131
131
|
```
|
|
132
132
|
|
|
133
133
|
## Adding a node
|