@kubb/ast 5.0.0-alpha.9 → 5.0.0-beta.75
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 +24 -10
- package/dist/index.cjs +1975 -531
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3379 -24
- package/dist/index.js +1911 -519
- package/dist/index.js.map +1 -1
- package/package.json +23 -34
- package/src/constants.ts +133 -15
- package/src/factory.ts +677 -21
- package/src/guards.ts +77 -9
- package/src/index.ts +44 -6
- package/src/infer.ts +130 -0
- package/src/mocks.ts +95 -25
- package/src/nodes/base.ts +44 -4
- package/src/nodes/code.ts +304 -0
- package/src/nodes/file.ts +230 -0
- package/src/nodes/function.ts +223 -0
- package/src/nodes/http.ts +17 -5
- package/src/nodes/index.ts +47 -7
- package/src/nodes/operation.ts +84 -6
- package/src/nodes/output.ts +26 -0
- package/src/nodes/parameter.ts +27 -1
- package/src/nodes/property.ts +23 -1
- package/src/nodes/response.ts +28 -2
- package/src/nodes/root.ts +34 -12
- package/src/nodes/schema.ts +419 -42
- package/src/printer.ts +152 -59
- package/src/refs.ts +39 -7
- package/src/resolvers.ts +45 -0
- package/src/transformers.ts +159 -0
- package/src/types.ts +32 -4
- package/src/utils.ts +798 -13
- package/src/visitor.ts +411 -96
- package/dist/types.cjs +0 -0
- package/dist/types.d.ts +0 -2
- package/dist/types.js +0 -1
- package/dist/visitor-Ci6rmtT9.d.ts +0 -702
package/package.json
CHANGED
|
@@ -1,67 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/ast",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-beta.75",
|
|
4
4
|
"description": "Spec-agnostic AST layer for Kubb. Defines nodes, visitor pattern, and factory functions used across codegen plugins.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"kubb",
|
|
7
6
|
"ast",
|
|
8
|
-
"typescript",
|
|
9
7
|
"codegen",
|
|
10
|
-
"
|
|
8
|
+
"kubb",
|
|
9
|
+
"openapi",
|
|
10
|
+
"typescript"
|
|
11
11
|
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"author": "stijnvanhulle",
|
|
12
14
|
"repository": {
|
|
13
15
|
"type": "git",
|
|
14
16
|
"url": "git+https://github.com/kubb-labs/kubb.git",
|
|
15
17
|
"directory": "packages/ast"
|
|
16
18
|
},
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
"files": [
|
|
20
|
+
"src",
|
|
21
|
+
"dist",
|
|
22
|
+
"!/**/**.test.**",
|
|
23
|
+
"!/**/__tests__/**",
|
|
24
|
+
"!/**/__snapshots__/**"
|
|
25
|
+
],
|
|
20
26
|
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"main": "./dist/index.cjs",
|
|
29
|
+
"module": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
21
31
|
"exports": {
|
|
22
32
|
".": {
|
|
23
33
|
"import": "./dist/index.js",
|
|
24
34
|
"require": "./dist/index.cjs"
|
|
25
35
|
},
|
|
26
|
-
"./types": {
|
|
27
|
-
"import": "./dist/types.js",
|
|
28
|
-
"require": "./dist/types.cjs"
|
|
29
|
-
},
|
|
30
36
|
"./package.json": "./package.json"
|
|
31
37
|
},
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
"types": [
|
|
36
|
-
"./dist/types.d.ts"
|
|
37
|
-
]
|
|
38
|
-
}
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"registry": "https://registry.npmjs.org/"
|
|
39
41
|
},
|
|
40
|
-
"files": [
|
|
41
|
-
"src",
|
|
42
|
-
"dist",
|
|
43
|
-
"!/**/**.test.**",
|
|
44
|
-
"!/**/__tests__/**",
|
|
45
|
-
"!/**/__snapshots__/**"
|
|
46
|
-
],
|
|
47
42
|
"devDependencies": {
|
|
48
|
-
"@types/node": "^
|
|
43
|
+
"@types/node": "^25.6.0",
|
|
49
44
|
"@internals/utils": "0.0.0"
|
|
50
45
|
},
|
|
51
|
-
"main": "./dist/index.cjs",
|
|
52
|
-
"module": "./dist/index.js",
|
|
53
46
|
"engines": {
|
|
54
47
|
"node": ">=22"
|
|
55
48
|
},
|
|
56
|
-
"publishConfig": {
|
|
57
|
-
"access": "public",
|
|
58
|
-
"registry": "https://registry.npmjs.org/"
|
|
59
|
-
},
|
|
60
49
|
"scripts": {
|
|
61
50
|
"build": "tsdown",
|
|
62
51
|
"clean": "npx rimraf ./dist",
|
|
63
|
-
"lint": "
|
|
64
|
-
"lint:fix": "
|
|
52
|
+
"lint": "oxlint .",
|
|
53
|
+
"lint:fix": "oxlint --fix .",
|
|
65
54
|
"release": "pnpm publish --no-git-check",
|
|
66
55
|
"release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
|
|
67
56
|
"start": "tsdown --watch",
|
package/src/constants.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
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
|
-
*
|
|
7
|
+
* Traversal depth for AST visitor utilities.
|
|
8
|
+
*
|
|
9
|
+
* - `'shallow'` — visits only the immediate node, skipping children.
|
|
10
|
+
* - `'deep'` — recursively visits all descendant nodes.
|
|
9
11
|
*/
|
|
10
12
|
export type VisitorDepth = 'shallow' | 'deep'
|
|
11
13
|
|
|
@@ -15,15 +17,36 @@ export const visitorDepths = {
|
|
|
15
17
|
} as const satisfies Record<VisitorDepth, VisitorDepth>
|
|
16
18
|
|
|
17
19
|
export const nodeKinds = {
|
|
18
|
-
|
|
20
|
+
input: 'Input',
|
|
21
|
+
output: 'Output',
|
|
19
22
|
operation: 'Operation',
|
|
20
23
|
schema: 'Schema',
|
|
21
24
|
property: 'Property',
|
|
22
25
|
parameter: 'Parameter',
|
|
23
26
|
response: 'Response',
|
|
24
|
-
|
|
27
|
+
functionParameter: 'FunctionParameter',
|
|
28
|
+
parameterGroup: 'ParameterGroup',
|
|
29
|
+
functionParameters: 'FunctionParameters',
|
|
30
|
+
type: 'Type',
|
|
31
|
+
file: 'File',
|
|
32
|
+
import: 'Import',
|
|
33
|
+
export: 'Export',
|
|
34
|
+
source: 'Source',
|
|
35
|
+
text: 'Text',
|
|
36
|
+
break: 'Break',
|
|
37
|
+
} as const satisfies Record<string, NodeKind>
|
|
25
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Schema type discriminators used by all AST schema nodes.
|
|
41
|
+
*
|
|
42
|
+
* These values serve as stable discriminators across the AST (e.g., `schema.type === schemaTypes.object`).
|
|
43
|
+
* Grouped by category: primitives (`string`, `number`, `boolean`), structural types (`object`, `array`, `union`),
|
|
44
|
+
* and format-specific types (`date`, `uuid`, `email`). Use `isScalarPrimitive()` to check for scalar types.
|
|
45
|
+
*/
|
|
26
46
|
export const schemaTypes = {
|
|
47
|
+
/**
|
|
48
|
+
* Text value.
|
|
49
|
+
*/
|
|
27
50
|
string: 'string',
|
|
28
51
|
/**
|
|
29
52
|
* Floating-point number (`float`, `double`).
|
|
@@ -37,28 +60,119 @@ export const schemaTypes = {
|
|
|
37
60
|
* 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.
|
|
38
61
|
*/
|
|
39
62
|
bigint: 'bigint',
|
|
63
|
+
/**
|
|
64
|
+
* Boolean value
|
|
65
|
+
*/
|
|
40
66
|
boolean: 'boolean',
|
|
67
|
+
/**
|
|
68
|
+
* Explicit null value.
|
|
69
|
+
*/
|
|
41
70
|
null: 'null',
|
|
71
|
+
/**
|
|
72
|
+
* Any value (no type restriction).
|
|
73
|
+
*/
|
|
42
74
|
any: 'any',
|
|
75
|
+
/**
|
|
76
|
+
* Unknown value (must be narrowed before usage).
|
|
77
|
+
*/
|
|
43
78
|
unknown: 'unknown',
|
|
79
|
+
/**
|
|
80
|
+
* No return value (`void`).
|
|
81
|
+
*/
|
|
44
82
|
void: 'void',
|
|
83
|
+
/**
|
|
84
|
+
* Object with named properties.
|
|
85
|
+
*/
|
|
45
86
|
object: 'object',
|
|
87
|
+
/**
|
|
88
|
+
* Sequential list of items.
|
|
89
|
+
*/
|
|
46
90
|
array: 'array',
|
|
91
|
+
/**
|
|
92
|
+
* Fixed-length list with position-specific items.
|
|
93
|
+
*/
|
|
47
94
|
tuple: 'tuple',
|
|
95
|
+
/**
|
|
96
|
+
* "One of" multiple schema members.
|
|
97
|
+
*/
|
|
48
98
|
union: 'union',
|
|
99
|
+
/**
|
|
100
|
+
* "All of" multiple schema members.
|
|
101
|
+
*/
|
|
49
102
|
intersection: 'intersection',
|
|
103
|
+
/**
|
|
104
|
+
* Enum schema.
|
|
105
|
+
*/
|
|
50
106
|
enum: 'enum',
|
|
107
|
+
/**
|
|
108
|
+
* Reference to another schema.
|
|
109
|
+
*/
|
|
51
110
|
ref: 'ref',
|
|
111
|
+
/**
|
|
112
|
+
* Calendar date (for example `2026-03-24`).
|
|
113
|
+
*/
|
|
52
114
|
date: 'date',
|
|
115
|
+
/**
|
|
116
|
+
* Date-time value (for example `2026-03-24T09:00:00Z`).
|
|
117
|
+
*/
|
|
53
118
|
datetime: 'datetime',
|
|
119
|
+
/**
|
|
120
|
+
* Time-only value (for example `09:00:00`).
|
|
121
|
+
*/
|
|
54
122
|
time: 'time',
|
|
123
|
+
/**
|
|
124
|
+
* UUID value.
|
|
125
|
+
*/
|
|
55
126
|
uuid: 'uuid',
|
|
127
|
+
/**
|
|
128
|
+
* Email address value.
|
|
129
|
+
*/
|
|
56
130
|
email: 'email',
|
|
131
|
+
/**
|
|
132
|
+
* URL value.
|
|
133
|
+
*/
|
|
57
134
|
url: 'url',
|
|
135
|
+
/**
|
|
136
|
+
* IPv4 address value.
|
|
137
|
+
*/
|
|
138
|
+
ipv4: 'ipv4',
|
|
139
|
+
/**
|
|
140
|
+
* IPv6 address value.
|
|
141
|
+
*/
|
|
142
|
+
ipv6: 'ipv6',
|
|
143
|
+
/**
|
|
144
|
+
* Binary/blob value.
|
|
145
|
+
*/
|
|
58
146
|
blob: 'blob',
|
|
147
|
+
/**
|
|
148
|
+
* Impossible value (`never`).
|
|
149
|
+
*/
|
|
59
150
|
never: 'never',
|
|
60
151
|
} as const satisfies Record<SchemaType, SchemaType>
|
|
61
152
|
|
|
153
|
+
export type ScalarPrimitive = 'string' | 'number' | 'integer' | 'bigint' | 'boolean'
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Scalar primitive schema types used for union simplification and type narrowing.
|
|
157
|
+
*
|
|
158
|
+
* Use `isScalarPrimitive()` to safely check whether a type is a scalar primitive.
|
|
159
|
+
*/
|
|
160
|
+
export const SCALAR_PRIMITIVE_TYPES = new Set<ScalarPrimitive>(['string', 'number', 'integer', 'bigint', 'boolean'])
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Type guard that returns `true` when `type` is a scalar primitive schema type.
|
|
164
|
+
*
|
|
165
|
+
* Use this to check if a schema type can be directly assigned without wrapping (e.g., `string | number | boolean`).
|
|
166
|
+
*/
|
|
167
|
+
export function isScalarPrimitive(type: string): type is ScalarPrimitive {
|
|
168
|
+
return SCALAR_PRIMITIVE_TYPES.has(type as ScalarPrimitive)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* HTTP method identifiers used by operation nodes.
|
|
173
|
+
*
|
|
174
|
+
* Includes all standard HTTP methods (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, TRACE).
|
|
175
|
+
*/
|
|
62
176
|
export const httpMethods = {
|
|
63
177
|
get: 'GET',
|
|
64
178
|
post: 'POST',
|
|
@@ -70,23 +184,27 @@ export const httpMethods = {
|
|
|
70
184
|
trace: 'TRACE',
|
|
71
185
|
} as const satisfies Record<Lowercase<HttpMethod>, HttpMethod>
|
|
72
186
|
|
|
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
187
|
/**
|
|
81
|
-
* Default
|
|
188
|
+
* Default concurrency limit for `walk()` traversal utility.
|
|
189
|
+
*
|
|
190
|
+
* Set to 30 to balance I/O-bound resolver parallelism against event loop pressure and memory usage during large spec traversals.
|
|
191
|
+
* Use `WALK_CONCURRENCY` when calling `walk()` or override for different hardware constraints.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* import { walk, WALK_CONCURRENCY } from '@kubb/ast'
|
|
196
|
+
*
|
|
197
|
+
* walk(root, { concurrency: WALK_CONCURRENCY, root: () => {} })
|
|
198
|
+
* ```
|
|
82
199
|
*/
|
|
83
200
|
export const WALK_CONCURRENCY = 30
|
|
84
201
|
|
|
85
202
|
/**
|
|
86
|
-
*
|
|
203
|
+
* Common MIME types used in request/response content negotiation.
|
|
204
|
+
*
|
|
205
|
+
* Covers JSON, XML, form data, PDFs, images, audio, and video formats.
|
|
206
|
+
* Use these as keys when serializing request/response bodies.
|
|
87
207
|
*/
|
|
88
|
-
export const DEFAULT_STATUS_CODE = 'default' as const
|
|
89
|
-
|
|
90
208
|
export const mediaTypes = {
|
|
91
209
|
applicationJson: 'application/json',
|
|
92
210
|
applicationXml: 'application/xml',
|