@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 CHANGED
@@ -112,11 +112,11 @@ const types = collectSync<string>(root, {
112
112
  ### Guards
113
113
 
114
114
  ```ts
115
- import { narrowSchema, schemaDef } from '@kubb/ast'
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 (schemaDef.is(node)) {
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 three files. The barrels and visitor tables derive the rest.
136
+ Adding a node touches four files.
137
137
 
138
- 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.
139
- 2. Add `fooDef` to the `nodeDefs` array in `src/registry.ts`.
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