@kubb/ast 5.8.4 → 5.9.1
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 +6 -7
- package/dist/index.cjs +1088 -1260
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -78
- package/dist/index.js +1088 -1238
- package/dist/index.js.map +1 -1
- package/dist/{types-C8GhOW_5.d.ts → types-DrSRvdtW.d.ts} +35 -203
- package/dist/types.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -112,11 +112,11 @@ const types = collectSync<string>(root, {
|
|
|
112
112
|
### Guards
|
|
113
113
|
|
|
114
114
|
```ts
|
|
115
|
-
import { narrowSchema
|
|
115
|
+
import { narrowSchema } from '@kubb/ast'
|
|
116
116
|
import type { Node } from '@kubb/ast/types'
|
|
117
117
|
|
|
118
118
|
function process(node: Node) {
|
|
119
|
-
if (
|
|
119
|
+
if (node.kind === 'Schema') {
|
|
120
120
|
const obj = narrowSchema(node, 'object')
|
|
121
121
|
obj?.properties?.forEach((p) => console.log(p.name))
|
|
122
122
|
}
|
|
@@ -133,13 +133,12 @@ resolveRefName({ kind: 'Schema', type: 'ref', ref: '#/components/schemas/Pet' })
|
|
|
133
133
|
|
|
134
134
|
## Adding a node
|
|
135
135
|
|
|
136
|
-
Adding a node touches
|
|
136
|
+
Adding a node touches four files.
|
|
137
137
|
|
|
138
|
-
1. Define the node in its own `src/nodes/*.ts` file
|
|
139
|
-
2. Add
|
|
138
|
+
1. Define the node type and its `createFoo` function in its own `src/nodes/*.ts` file, and add the kind to `NodeKind` in `src/nodes/base.ts`.
|
|
139
|
+
2. Add the type to the `Node` union in `src/nodes/index.ts` and export it from `src/types.ts`.
|
|
140
140
|
3. Re-export `createFoo` from `src/factory.ts`.
|
|
141
|
-
|
|
142
|
-
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.
|
|
141
|
+
4. When the node has children or a visitor callback, add it to `VISITOR_KEYS` and `VISITOR_KEY_BY_KIND` in `src/visitor.ts`.
|
|
143
142
|
|
|
144
143
|
## Supporting Kubb
|
|
145
144
|
|