@kubb/ast 5.0.0-alpha.7 → 5.0.0-alpha.71

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