@kubb/ast 5.0.0-alpha.5 → 5.0.0-alpha.51

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/src/constants.ts CHANGED
@@ -5,7 +5,7 @@ import type { ParameterLocation } from './nodes/parameter.ts'
5
5
  import type { SchemaType } from './nodes/schema.ts'
6
6
 
7
7
  /**
8
- * Depth for schema traversal in visitor functions.
8
+ * Traversal depth used by AST visitor utilities.
9
9
  */
10
10
  export type VisitorDepth = 'shallow' | 'deep'
11
11
 
@@ -15,15 +15,40 @@ export const visitorDepths = {
15
15
  } as const satisfies Record<VisitorDepth, VisitorDepth>
16
16
 
17
17
  export const nodeKinds = {
18
- root: 'Root',
18
+ input: 'Input',
19
+ output: 'Output',
19
20
  operation: 'Operation',
20
21
  schema: 'Schema',
21
22
  property: 'Property',
22
23
  parameter: 'Parameter',
23
24
  response: 'Response',
24
- } as const satisfies Record<Lowercase<NodeKind>, NodeKind>
25
+ functionParameter: 'FunctionParameter',
26
+ parameterGroup: 'ParameterGroup',
27
+ functionParameters: 'FunctionParameters',
28
+ type: 'Type',
29
+ file: 'File',
30
+ import: 'Import',
31
+ export: 'Export',
32
+ source: 'Source',
33
+ text: 'Text',
34
+ break: 'Break',
35
+ } as const satisfies Record<string, NodeKind>
25
36
 
37
+ /**
38
+ * Canonical schema type strings used by AST schema nodes.
39
+ *
40
+ * These values are used across the AST as stable discriminators
41
+ * (for example `schema.type === schemaTypes.object`).
42
+ *
43
+ * The map is grouped by intent:
44
+ * - primitives (`string`, `number`, `boolean`, ...)
45
+ * - structural/composite (`object`, `array`, `union`, ...)
46
+ * - special OpenAPI-oriented types (`ref`, `datetime`, `uuid`, ...)
47
+ */
26
48
  export const schemaTypes = {
49
+ /**
50
+ * Text value.
51
+ */
27
52
  string: 'string',
28
53
  /**
29
54
  * Floating-point number (`float`, `double`).
@@ -37,28 +62,110 @@ export const schemaTypes = {
37
62
  * 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.
38
63
  */
39
64
  bigint: 'bigint',
65
+ /**
66
+ * Boolean value
67
+ */
40
68
  boolean: 'boolean',
69
+ /**
70
+ * Explicit null value.
71
+ */
41
72
  null: 'null',
73
+ /**
74
+ * Any value (no type restriction).
75
+ */
42
76
  any: 'any',
77
+ /**
78
+ * Unknown value (must be narrowed before usage).
79
+ */
43
80
  unknown: 'unknown',
81
+ /**
82
+ * No return value (`void`).
83
+ */
44
84
  void: 'void',
85
+ /**
86
+ * Object with named properties.
87
+ */
45
88
  object: 'object',
89
+ /**
90
+ * Sequential list of items.
91
+ */
46
92
  array: 'array',
93
+ /**
94
+ * Fixed-length list with position-specific items.
95
+ */
47
96
  tuple: 'tuple',
97
+ /**
98
+ * "One of" multiple schema members.
99
+ */
48
100
  union: 'union',
101
+ /**
102
+ * "All of" multiple schema members.
103
+ */
49
104
  intersection: 'intersection',
105
+ /**
106
+ * Enum schema.
107
+ */
50
108
  enum: 'enum',
109
+ /**
110
+ * Reference to another schema.
111
+ */
51
112
  ref: 'ref',
113
+ /**
114
+ * Calendar date (for example `2026-03-24`).
115
+ */
52
116
  date: 'date',
117
+ /**
118
+ * Date-time value (for example `2026-03-24T09:00:00Z`).
119
+ */
53
120
  datetime: 'datetime',
121
+ /**
122
+ * Time-only value (for example `09:00:00`).
123
+ */
54
124
  time: 'time',
125
+ /**
126
+ * UUID value.
127
+ */
55
128
  uuid: 'uuid',
129
+ /**
130
+ * Email address value.
131
+ */
56
132
  email: 'email',
133
+ /**
134
+ * URL value.
135
+ */
57
136
  url: 'url',
137
+ /**
138
+ * IPv4 address value.
139
+ */
140
+ ipv4: 'ipv4',
141
+ /**
142
+ * IPv6 address value.
143
+ */
144
+ ipv6: 'ipv6',
145
+ /**
146
+ * Binary/blob value.
147
+ */
58
148
  blob: 'blob',
149
+ /**
150
+ * Impossible value (`never`).
151
+ */
59
152
  never: 'never',
60
153
  } as const satisfies Record<SchemaType, SchemaType>
61
154
 
155
+ export type ScalarPrimitive = 'string' | 'number' | 'integer' | 'bigint' | 'boolean'
156
+
157
+ /**
158
+ * Primitive scalar schema types used when simplifying union members.
159
+ */
160
+ export const SCALAR_PRIMITIVE_TYPES = new Set<ScalarPrimitive>(['string', 'number', 'integer', 'bigint', 'boolean'])
161
+
162
+ /**
163
+ * Returns `true` when `type` is a scalar primitive schema type.
164
+ */
165
+ export function isScalarPrimitive(type: string): type is ScalarPrimitive {
166
+ return SCALAR_PRIMITIVE_TYPES.has(type as ScalarPrimitive)
167
+ }
168
+
62
169
  export const httpMethods = {
63
170
  get: 'GET',
64
171
  post: 'POST',
@@ -78,12 +185,26 @@ export const parameterLocations = {
78
185
  } as const satisfies Record<ParameterLocation, ParameterLocation>
79
186
 
80
187
  /**
81
- * Default max concurrent visitor calls in `walk`.
188
+ * Default maximum number of concurrent callbacks used by `walk`.
189
+ *
190
+ * 30 is chosen to allow enough parallelism to overlap I/O-bound resolver calls
191
+ * without overwhelming the event loop or causing excessive memory pressure during
192
+ * large spec traversals.
193
+ *
194
+ * @example
195
+ * ```ts
196
+ * walk(root, { concurrency: WALK_CONCURRENCY, root: () => {} })
197
+ * ```
82
198
  */
83
199
  export const WALK_CONCURRENCY = 30
84
200
 
85
201
  /**
86
- * Fallback status code string for API spec responses.
202
+ * Fallback response status code used for catch-all responses.
203
+ *
204
+ * @example
205
+ * ```ts
206
+ * const status = DEFAULT_STATUS_CODE // 'default'
207
+ * ```
87
208
  */
88
209
  export const DEFAULT_STATUS_CODE = 'default' as const
89
210