@kubb/ast 5.0.0-beta.36 → 5.0.0-beta.38

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.
@@ -4,9 +4,9 @@ import type { BaseNode } from './base.ts'
4
4
  * AST node representing a language-agnostic type expression used as a function parameter
5
5
  * type annotation. Each language printer renders the variant into its own syntax.
6
6
  *
7
- * - `struct` an inline anonymous type grouping named fields.
7
+ * - `struct` an inline anonymous type grouping named fields.
8
8
  * TypeScript renders as `{ petId: string; name?: string }`.
9
- * - `member` a single named field accessed from a named group type.
9
+ * - `member` a single named field accessed from a named group type.
10
10
  * TypeScript renders as `PathParams['petId']`.
11
11
  *
12
12
  * @example Reference variant
@@ -35,7 +35,7 @@ export type ParamsTypeNode = BaseNode & {
35
35
  } & (
36
36
  | {
37
37
  /**
38
- * Reference variant a plain type name or identifier.
38
+ * Reference variant, a plain type name or identifier.
39
39
  * TypeScript renders as-is, e.g. `string`, `QueryParams`, `Partial<Config>`.
40
40
  */
41
41
  variant: 'reference'
@@ -46,7 +46,7 @@ export type ParamsTypeNode = BaseNode & {
46
46
  }
47
47
  | {
48
48
  /**
49
- * Struct variant an inline anonymous type grouping named fields.
49
+ * Struct variant, an inline anonymous type grouping named fields.
50
50
  * TypeScript renders as `{ key: Type; other?: OtherType }`.
51
51
  */
52
52
  variant: 'struct'
@@ -61,7 +61,7 @@ export type ParamsTypeNode = BaseNode & {
61
61
  }
62
62
  | {
63
63
  /**
64
- * Member variant a single named field accessed from a group type.
64
+ * Member variant, a single named field accessed from a group type.
65
65
  * TypeScript renders as `Base['key']`.
66
66
  */
67
67
  variant: 'member'
@@ -122,7 +122,7 @@ export type FunctionParameterNode = BaseNode & {
122
122
  */
123
123
  rest?: boolean
124
124
  } /**
125
- * Optional parameter rendered with `?` and may be omitted by the caller.
125
+ * Optional parameter, rendered with `?` and may be omitted by the caller.
126
126
  * Cannot be combined with `default` because a defaulted parameter is already optional.
127
127
  */ & (
128
128
  | { optional: true; default?: never }
@@ -196,10 +196,10 @@ export type ParameterGroupNode = BaseNode & {
196
196
  * Nodes are plain immutable data.
197
197
  *
198
198
  * Renders differently depending on the output mode:
199
- * - `declaration` → `(id: string, config: Config = {})` function declaration parameters
200
- * - `call` → `(id, { method, url })` function call arguments
201
- * - `keys` → `{ id, config }` key names only (for destructuring)
202
- * - `values` → `{ id: id, config: config }` key → value pairs
199
+ * - `declaration` → `(id: string, config: Config = {})` function declaration parameters
200
+ * - `call` → `(id, { method, url })` function call arguments
201
+ * - `keys` → `{ id, config }` key names only (for destructuring)
202
+ * - `values` → `{ id: id, config: config }` key → value pairs
203
203
  */
204
204
  export type FunctionParametersNode = BaseNode & {
205
205
  /**
@@ -218,6 +218,6 @@ export type FunctionParametersNode = BaseNode & {
218
218
  export type FunctionParamNode = FunctionParameterNode | ParameterGroupNode | FunctionParametersNode | ParamsTypeNode
219
219
 
220
220
  /**
221
- * Handler map keys one per `FunctionParamNode` kind.
221
+ * Handler map keys, one per `FunctionParamNode` kind.
222
222
  */
223
223
  export type FunctionNodeType = 'functionParameter' | 'parameterGroup' | 'functionParameters' | 'paramsType'
package/src/nodes/root.ts CHANGED
@@ -5,7 +5,7 @@ import type { SchemaNode } from './schema.ts'
5
5
  /**
6
6
  * Metadata for an API document, populated by the adapter and available to every generator.
7
7
  *
8
- * All fields are plain JSON-serializable values no `Set`, no `Map`, no class instances.
8
+ * All fields are plain JSON-serializable values, no `Set`, no `Map`, no class instances.
9
9
  * Computed fields (`circularNames`, `enumNames`) are pre-calculated once during the adapter
10
10
  * pre-scan so generators never need to iterate the full schema list themselves.
11
11
  *
@@ -33,7 +33,7 @@ export type InputMeta = {
33
33
  baseURL?: string | null
34
34
  /**
35
35
  * Names of schemas that participate in a circular reference chain.
36
- * Computed once during the adapter pre-scan use this instead of calling
36
+ * Computed once during the adapter pre-scan, use this instead of calling
37
37
  * `findCircularSchemas` per generator call.
38
38
  *
39
39
  * Convert to a `Set` once at the start of a generator, not per-schema,
@@ -48,7 +48,7 @@ export type InputMeta = {
48
48
  circularNames: ReadonlyArray<string>
49
49
  /**
50
50
  * Names of schemas whose type is `enum`.
51
- * Computed once during the adapter pre-scan use this instead of filtering
51
+ * Computed once during the adapter pre-scan, use this instead of filtering
52
52
  * schemas per generator call.
53
53
  *
54
54
  * Convert to a `Set` once at the start of a generator when you need repeated
@@ -96,14 +96,14 @@ export type InputNode = BaseNode & {
96
96
  /**
97
97
  * Streaming variant of `InputNode` for memory-efficient processing of large API specs.
98
98
  *
99
- * `schemas` and `operations` are `AsyncIterable` rather than arrays each `for await`
99
+ * `schemas` and `operations` are `AsyncIterable` rather than arrays, each `for await`
100
100
  * loop creates a fresh parse pass from the cached in-memory document, so multiple
101
101
  * consumers (plugins) can iterate independently without keeping all nodes in memory.
102
102
  *
103
103
  * @example
104
104
  * ```ts
105
105
  * for await (const schema of inputStreamNode.schemas) {
106
- * // only this one SchemaNode is live here; previous ones are GC-eligible
106
+ * // only this one SchemaNode is live here. Previous ones are GC-eligible
107
107
  * }
108
108
  * ```
109
109
  */
@@ -178,7 +178,7 @@ export type ObjectSchemaNode = SchemaNodeBase & {
178
178
  */
179
179
  type: 'object'
180
180
  /**
181
- * Primitive type always `'object'` for object schemas.
181
+ * Primitive type, always `'object'` for object schemas.
182
182
  */
183
183
  primitive: 'object'
184
184
  /**
@@ -381,13 +381,10 @@ export type RefSchemaNode = SchemaNodeBase & {
381
381
  */
382
382
  pattern?: string
383
383
  /**
384
- * The fully-parsed schema that this ref resolves to.
385
- * Populated during OAS parsing when the referenced definition can be resolved.
386
- * `null` when the ref cannot be resolved or is part of a circular chain.
387
- * `undefined` when resolution has not been attempted.
388
- *
389
- * Useful for inspecting the referenced schema's structure (e.g. `primitive`, `properties`)
390
- * without following the reference manually.
384
+ * The fully-parsed schema this ref resolves to, so its structure (`primitive`, `properties`)
385
+ * can be read without following the reference. Populated during OAS parsing when the
386
+ * definition resolves, `null` when it can't or the ref is circular, and `undefined` when
387
+ * resolution has not been attempted.
391
388
  */
392
389
  schema?: SchemaNode | null
393
390
  }
package/src/printer.ts CHANGED
@@ -46,7 +46,7 @@ export type PrinterHandler<TOutput, TOptions extends object, T extends SchemaTyp
46
46
  * Partial map of per-node-type handler overrides for a printer.
47
47
  *
48
48
  * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).
49
- * Supply only the handlers you want to replace; the printer's built-in
49
+ * Supply only the handlers you want to replace. The printer's built-in
50
50
  * defaults fill in the rest.
51
51
  *
52
52
  * @example
@@ -69,10 +69,10 @@ export type PrinterPartial<TOutput, TOptions extends object> = Partial<{
69
69
  /**
70
70
  * Generic shape used by `definePrinter`.
71
71
  *
72
- * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)
73
- * - `TOptions` options passed to and stored on the printer instance
74
- * - `TOutput` the type emitted by node handlers
75
- * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)
72
+ * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)
73
+ * - `TOptions` options passed to and stored on the printer instance
74
+ * - `TOutput` the type emitted by node handlers
75
+ * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)
76
76
  *
77
77
  * @example
78
78
  * ```ts
@@ -104,8 +104,8 @@ export type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {
104
104
  */
105
105
  options: T['options']
106
106
  /**
107
- * Node-level dispatcher converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.
108
- * Always dispatches through the `nodes` map; never calls the `print` override.
107
+ * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.
108
+ * Always dispatches through the `nodes` map. Never calls the `print` override.
109
109
  * Use this when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.
110
110
  */
111
111
  transform: (node: SchemaNode) => T['output'] | null
@@ -143,7 +143,7 @@ type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) =
143
143
  /**
144
144
  * Optional root-level print override. When provided, becomes the public `printer.print`.
145
145
  * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),
146
- * not the override itself so recursion is safe.
146
+ * not the override itself, so recursion is safe.
147
147
  */
148
148
  print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null
149
149
  }
@@ -155,11 +155,11 @@ type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) =
155
155
  *
156
156
  * The builder receives resolved options and returns:
157
157
  *
158
- * - `name` unique identifier for the printer.
159
- * - `options` stored on the returned printer instance.
160
- * - `nodes` map of `SchemaType` → handler. Handlers return the rendered
158
+ * - `name` unique identifier for the printer.
159
+ * - `options` stored on the returned printer instance.
160
+ * - `nodes` map of `SchemaType` → handler. Handlers return the rendered
161
161
  * output (a string, a TypeScript AST node, ...) for that schema type.
162
- * - `print` (optional) top-level override exposed as `printer.print`.
162
+ * - `print` (optional), top-level override exposed as `printer.print`.
163
163
  * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.
164
164
  *
165
165
  * Without a `print` override, `printer.print` falls back to `printer.transform`
package/src/signature.ts CHANGED
@@ -5,7 +5,7 @@ import { extractRefName } from './refs.ts'
5
5
  /**
6
6
  * The shape-affecting flags shared by every node kind: base primitive, format, and `nullable`.
7
7
  * Documentation and usage-slot flags (`optional`/`nullish`/`readOnly`/`writeOnly`) are
8
- * intentionally excluded they describe the property slot, not the type.
8
+ * intentionally excluded, they describe the property slot, not the type.
9
9
  */
10
10
  function flagsDescriptor(node: SchemaNode): string {
11
11
  return `${node.primitive ?? ''};${node.format ?? ''};${node.nullable ? 1 : 0}`
@@ -157,7 +157,7 @@ function serializeShapeField(field: ShapeField, node: SchemaNode, record: Record
157
157
 
158
158
  /**
159
159
  * Builds the local, shape-only descriptor for a node: its kind, flags, constraints, and its
160
- * children's signatures. {@link signatureOf} hashes this string; children contribute their
160
+ * children's signatures. {@link signatureOf} hashes this string. Children contribute their
161
161
  * fixed-length signature rather than their own full descriptor, which keeps the result bounded.
162
162
  */
163
163
  function describeShape(node: SchemaNode): string {
@@ -180,7 +180,7 @@ function describeShape(node: SchemaNode): string {
180
180
  * during dedupe planning is not re-hashed when the same tree is rewritten during streaming
181
181
  * (where `schemaSignature` and `applyDedupe` would otherwise each walk it from scratch). Reuse
182
182
  * across calls is sound because a signature depends only on a node's content, and schema nodes
183
- * are immutable once created transforms allocate new objects rather than mutating in place.
183
+ * are immutable once created, transforms allocate new objects rather than mutating in place.
184
184
  */
185
185
  const signatureCache = new WeakMap<SchemaNode, string>()
186
186
 
@@ -188,7 +188,7 @@ const signatureCache = new WeakMap<SchemaNode, string>()
188
188
  * Hash-consing: each node's signature is a fixed-length digest of its local shape plus its
189
189
  * children's digests (a Merkle hash). Children contribute their 64-char hash instead of their
190
190
  * full nested descriptor, so a signature stays bounded regardless of subtree depth, and the
191
- * digest is identical across calls because it depends only on content never on traversal
191
+ * digest is identical across calls because it depends only on content, never on traversal
192
192
  * order. This keeps the keys built during planning consistent with the ones recomputed later
193
193
  * during streaming. {@link signatureCache} memoizes node → digest across every computation.
194
194
  */
package/src/utils.ts CHANGED
@@ -249,7 +249,7 @@ export type CreateOperationParamsOptions = {
249
249
  * Applies a uniform transformation to every resolved type name before it is used
250
250
  * in a parameter node. Use this for framework-level type wrappers.
251
251
  *
252
- * @example Vue Query wrap every parameter type with `MaybeRefOrGetter`
252
+ * @example Vue Query, wrap every parameter type with `MaybeRefOrGetter`
253
253
  * `typeWrapper: (t) => \`MaybeRefOrGetter<${t}>\``
254
254
  */
255
255
  typeWrapper?: (type: string) => string
@@ -315,7 +315,7 @@ export function createOperationParams(node: OperationNode, options: CreateOperat
315
315
  variant: 'reference',
316
316
  name: typeWrapper ? typeWrapper(type) : type,
317
317
  })
318
- // Only reference-variant TypeNodes are wrapped they hold a plain type name string that needs casing applied.
318
+ // Only reference-variant TypeNodes are wrapped, they hold a plain type name string that needs casing applied.
319
319
  // Member and struct TypeNodes are pre-resolved structured expressions and are passed through unchanged.
320
320
  const wrapTypeNode = (type: ParamsTypeNode): ParamsTypeNode => (type.kind === 'ParamsType' && type.variant === 'reference' ? wrapType(type.name) : type)
321
321
 
@@ -570,7 +570,7 @@ function importKey(path: string, name: string | null | undefined, isTypeOnly: bo
570
570
 
571
571
  /**
572
572
  * Computes a multi-level sort key for exports and imports:
573
- * non-array names first (wildcards/namespace aliases); type-only before value; alphabetical path; unnamed before named.
573
+ * non-array names first (wildcards/namespace aliases). Type-only before value. Alphabetical path. Unnamed before named.
574
574
  */
575
575
  function sortKey(node: { name?: string | Array<unknown> | null; isTypeOnly?: boolean | null; path: string }): string {
576
576
  const isArray = Array.isArray(node.name) ? '1' : '0'
@@ -618,7 +618,7 @@ export function combineExports(exports: Array<ExportNode>): Array<ExportNode> {
618
618
  // Deduplicates non-array exports by their exact identity
619
619
  const seen = new Set<string>()
620
620
 
621
- // Precompute sort keys once avoids recomputing per comparison.
621
+ // Precompute sort keys once, avoids recomputing per comparison.
622
622
  const keyed = exports.map((node) => ({ node, key: sortKey(node) }))
623
623
  keyed.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0))
624
624
 
@@ -664,7 +664,7 @@ export function combineImports(imports: Array<ImportNode>, exports: Array<Export
664
664
  const isUsed = (importName: string): boolean => !source || source.includes(importName) || exportedNames.has(importName)
665
665
 
666
666
  // Memoize object import names so the same logical (propertyName, name) pair always
667
- // reuses the same object reference Set-based deduplication then works correctly.
667
+ // reuses the same object reference. Set-based deduplication then works correctly.
668
668
  const importNameMemo = new Map<string, { propertyName: string; name?: string }>()
669
669
  const canonicalizeName = (n: string | { propertyName: string; name?: string }): string | { propertyName: string; name?: string } => {
670
670
  if (typeof n === 'string') return n
@@ -674,7 +674,7 @@ export function combineImports(imports: Array<ImportNode>, exports: Array<Export
674
674
  }
675
675
 
676
676
  // Paths that keep at least one used named import. A default import from such a path is retained
677
- // even when its binding can't be found in `source` e.g. a generated `client` default import
677
+ // even when its binding can't be found in `source` e.g. a generated `client` default import
678
678
  // alongside `import type { Client } from <same path>`, where merged grouped output omits the body.
679
679
  const pathsWithUsedNamedImport = new Set<string>()
680
680
  for (const node of imports) {
@@ -690,7 +690,7 @@ export function combineImports(imports: Array<ImportNode>, exports: Array<Export
690
690
  // Deduplicates non-array imports by their exact identity
691
691
  const seen = new Set<string>()
692
692
 
693
- // Precompute sort keys once avoids recomputing per comparison.
693
+ // Precompute sort keys once, avoids recomputing per comparison.
694
694
  const keyed = imports.map((node) => ({ node, key: sortKey(node) }))
695
695
  keyed.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0))
696
696
 
@@ -783,7 +783,7 @@ export function resolveRefName(node: SchemaNode | undefined): string | null {
783
783
  /**
784
784
  * Collects every named schema referenced (transitively) from a node via ref edges.
785
785
  *
786
- * Refs are followed by name only the resolved `node.schema` is not traversed inline.
786
+ * Refs are followed by name only, the resolved `node.schema` is not traversed inline.
787
787
  * Use this to determine schema dependencies, build reference graphs, or detect what schemas need to be emitted.
788
788
  *
789
789
  * @example Collect refs from a single schema
@@ -823,7 +823,7 @@ export function collectReferencedSchemaNames(node: SchemaNode | undefined, out:
823
823
  * Collects the names of all top-level schemas transitively used by a set of operations.
824
824
  *
825
825
  * An operation uses a schema when any of its parameters, request body content, or responses
826
- * reference it directly or indirectly through other named schemas.
826
+ * reference it, directly or indirectly through other named schemas.
827
827
  * The walk is iterative and safe against reference cycles.
828
828
  *
829
829
  * Use this together with `include` filters to determine which schemas from `components/schemas`
@@ -934,7 +934,7 @@ export function findCircularSchemas(schemas: ReadonlyArray<SchemaNode>): Set<str
934
934
  * Use `excludeName` to ignore refs to specific schemas (useful when self-references are handled separately).
935
935
  * Commonly used with `findCircularSchemas()` to detect where lazy wrappers are needed in code generation.
936
936
  *
937
- * @note Returns `true` for the first matching circular ref found; use for fast dependency checks.
937
+ * @note Returns `true` for the first matching circular ref found. Use for fast dependency checks.
938
938
  */
939
939
  export function containsCircularRef(
940
940
  node: SchemaNode | undefined,
package/src/visitor.ts CHANGED
@@ -284,8 +284,8 @@ export type CollectOptions<T> = CollectVisitor<T> & {
284
284
  /**
285
285
  * Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`).
286
286
  *
287
- * Each listed property holds a child node, an array of child nodes, or for
288
- * `additionalProperties` a node or the literal `true` (skipped). Every value
287
+ * Each listed property holds a child node, an array of child nodes, or, for
288
+ * `additionalProperties` a node or the literal `true` (skipped). Every value
289
289
  * in a child slot is a node, so one table drives both `getChildren` and `transform`.
290
290
  */
291
291
  const VISITOR_KEYS = {
@@ -311,7 +311,7 @@ function isNode(value: unknown): value is Node {
311
311
  /**
312
312
  * Returns the immediate traversable children of `node` based on {@link VISITOR_KEYS}.
313
313
  *
314
- * `Schema` children are only included when `recurse` is `true`; shallow mode skips them.
314
+ * `Schema` children are only included when `recurse` is `true`. Shallow mode skips them.
315
315
  *
316
316
  * @example
317
317
  * ```ts
@@ -338,7 +338,7 @@ function* getChildren(node: Node, recurse: boolean): Generator<Node, void, undef
338
338
 
339
339
  /**
340
340
  * Maps a node `kind` to the matching visitor callback name. Only the seven
341
- * traversable node kinds have an entry; every other kind resolves to
341
+ * traversable node kinds have an entry. Every other kind resolves to
342
342
  * `undefined` and is skipped.
343
343
  */
344
344
  const VISITOR_KEY_BY_KIND: Partial<Record<NodeKind, keyof Visitor>> = {
@@ -375,7 +375,7 @@ function applyVisitor<TResult>(node: Node, visitor: Visitor | AsyncVisitor | Col
375
375
  *
376
376
  * Sibling nodes at each depth run concurrently up to `options.concurrency`
377
377
  * (defaults to `WALK_CONCURRENCY`). Higher values overlap I/O-bound visitor
378
- * work; lower values reduce memory pressure.
378
+ * work. Lower values reduce memory pressure.
379
379
  *
380
380
  * @example Log every operation
381
381
  * ```ts
@@ -403,7 +403,7 @@ async function _walk(node: Node, visitor: AsyncVisitor, recurse: boolean, limit:
403
403
 
404
404
  // Visit siblings concurrently and let the shared `limit` cap how many callbacks
405
405
  // run at once. Awaiting each child sequentially here would serialize the whole
406
- // traversal and make `concurrency` inert every visitor callback would run one
406
+ // traversal and make `concurrency` inert, every visitor callback would run one
407
407
  // at a time regardless of the limit.
408
408
  const children = Array.from(getChildren(node, recurse))
409
409
  if (children.length === 0) return
@@ -415,7 +415,7 @@ async function _walk(node: Node, visitor: AsyncVisitor, recurse: boolean, limit:
415
415
  * Synchronous depth-first transform. Each visitor callback gets a chance to
416
416
  * return a replacement node; `undefined` keeps the original.
417
417
  *
418
- * The transform is immutable. The original tree is not mutated; a new tree
418
+ * The transform is immutable. The original tree is not mutated. A new tree
419
419
  * is returned. Use `depth: 'shallow'` to skip recursion into children.
420
420
  *
421
421
  * @example Prefix every operationId