@kubb/ast 5.0.0-beta.32 → 5.0.0-beta.34
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 +17 -8
- package/dist/index.cjs +3 -72
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -3705
- package/dist/index.js +4 -63
- package/dist/index.js.map +1 -1
- package/dist/types-CE8VJ5_y.d.ts +3605 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +1 -0
- package/package.json +5 -1
- package/src/constants.ts +0 -50
- package/src/index.ts +4 -8
- package/src/infer.ts +0 -9
- package/src/refs.ts +0 -7
- package/src/types.ts +1 -2
- package/src/visitor.ts +8 -4
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<h1>@kubb/ast</h1>
|
|
3
2
|
<a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
|
|
4
|
-
<img
|
|
3
|
+
<img src="https://kubb.dev/og.png" alt="Kubb banner">
|
|
5
4
|
</a>
|
|
6
5
|
|
|
7
6
|
[![npm version][npm-version-src]][npm-version-href]
|
|
@@ -11,7 +10,7 @@
|
|
|
11
10
|
[![Sponsors][sponsors-src]][sponsors-href]
|
|
12
11
|
|
|
13
12
|
<h4>
|
|
14
|
-
<a href="https://kubb.dev
|
|
13
|
+
<a href="https://kubb.dev" target="_blank">Documentation</a>
|
|
15
14
|
<span> · </span>
|
|
16
15
|
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
|
|
17
16
|
<span> · </span>
|
|
@@ -19,7 +18,13 @@
|
|
|
19
18
|
</h4>
|
|
20
19
|
</div>
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
<br />
|
|
22
|
+
|
|
23
|
+
# @kubb/ast
|
|
24
|
+
|
|
25
|
+
### Spec-agnostic AST layer for Kubb
|
|
26
|
+
|
|
27
|
+
Defines the node tree, visitor pattern, factory functions, and type guards used across every Kubb code generation plugin.
|
|
23
28
|
|
|
24
29
|
## Imports
|
|
25
30
|
|
|
@@ -120,17 +125,17 @@ function process(node: Node) {
|
|
|
120
125
|
### Refs
|
|
121
126
|
|
|
122
127
|
```ts
|
|
123
|
-
import {
|
|
128
|
+
import { extractRefName } from '@kubb/ast'
|
|
124
129
|
|
|
125
|
-
|
|
126
|
-
const pet = resolveRef(refMap, 'Pet')
|
|
130
|
+
extractRefName('#/components/schemas/Pet') // 'Pet'
|
|
127
131
|
```
|
|
128
132
|
|
|
129
133
|
## Supporting Kubb
|
|
130
134
|
|
|
131
|
-
Kubb is an
|
|
135
|
+
Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
|
|
132
136
|
|
|
133
137
|
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
138
|
+
- [See sponsorship tiers and our sponsors](https://kubb.dev/sponsors)
|
|
134
139
|
|
|
135
140
|
<p align="center">
|
|
136
141
|
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
@@ -138,6 +143,10 @@ Kubb is an MIT-licensed open source project with its ongoing development made po
|
|
|
138
143
|
</a>
|
|
139
144
|
</p>
|
|
140
145
|
|
|
146
|
+
## License
|
|
147
|
+
|
|
148
|
+
[MIT](https://github.com/kubb-labs/kubb/blob/main/licenses/LICENSE-MIT)
|
|
149
|
+
|
|
141
150
|
<!-- Badges -->
|
|
142
151
|
|
|
143
152
|
[npm-version-src]: https://img.shields.io/npm/v/@kubb/ast?flat&colorA=18181B&colorB=f58517
|
package/dist/index.cjs
CHANGED
|
@@ -29,25 +29,6 @@ const visitorDepths = {
|
|
|
29
29
|
shallow: "shallow",
|
|
30
30
|
deep: "deep"
|
|
31
31
|
};
|
|
32
|
-
const nodeKinds = {
|
|
33
|
-
input: "Input",
|
|
34
|
-
output: "Output",
|
|
35
|
-
operation: "Operation",
|
|
36
|
-
schema: "Schema",
|
|
37
|
-
property: "Property",
|
|
38
|
-
parameter: "Parameter",
|
|
39
|
-
response: "Response",
|
|
40
|
-
functionParameter: "FunctionParameter",
|
|
41
|
-
parameterGroup: "ParameterGroup",
|
|
42
|
-
functionParameters: "FunctionParameters",
|
|
43
|
-
type: "Type",
|
|
44
|
-
file: "File",
|
|
45
|
-
import: "Import",
|
|
46
|
-
export: "Export",
|
|
47
|
-
source: "Source",
|
|
48
|
-
text: "Text",
|
|
49
|
-
break: "Break"
|
|
50
|
-
};
|
|
51
32
|
/**
|
|
52
33
|
* Schema type discriminators used by all AST schema nodes.
|
|
53
34
|
*
|
|
@@ -196,33 +177,6 @@ const httpMethods = {
|
|
|
196
177
|
options: "OPTIONS",
|
|
197
178
|
trace: "TRACE"
|
|
198
179
|
};
|
|
199
|
-
/**
|
|
200
|
-
* Common MIME types used in request/response content negotiation.
|
|
201
|
-
*
|
|
202
|
-
* Covers JSON, XML, form data, PDFs, images, audio, and video formats.
|
|
203
|
-
* Use these as keys when serializing request/response bodies.
|
|
204
|
-
*/
|
|
205
|
-
const mediaTypes = {
|
|
206
|
-
applicationJson: "application/json",
|
|
207
|
-
applicationXml: "application/xml",
|
|
208
|
-
applicationFormUrlEncoded: "application/x-www-form-urlencoded",
|
|
209
|
-
applicationOctetStream: "application/octet-stream",
|
|
210
|
-
applicationPdf: "application/pdf",
|
|
211
|
-
applicationZip: "application/zip",
|
|
212
|
-
applicationGraphql: "application/graphql",
|
|
213
|
-
multipartFormData: "multipart/form-data",
|
|
214
|
-
textPlain: "text/plain",
|
|
215
|
-
textHtml: "text/html",
|
|
216
|
-
textCsv: "text/csv",
|
|
217
|
-
textXml: "text/xml",
|
|
218
|
-
imagePng: "image/png",
|
|
219
|
-
imageJpeg: "image/jpeg",
|
|
220
|
-
imageGif: "image/gif",
|
|
221
|
-
imageWebp: "image/webp",
|
|
222
|
-
imageSvgXml: "image/svg+xml",
|
|
223
|
-
audioMpeg: "audio/mpeg",
|
|
224
|
-
videoMp4: "video/mp4"
|
|
225
|
-
};
|
|
226
180
|
//#endregion
|
|
227
181
|
//#region ../../internals/utils/src/casing.ts
|
|
228
182
|
/**
|
|
@@ -677,8 +631,9 @@ async function walk(node, options) {
|
|
|
677
631
|
}
|
|
678
632
|
async function _walk(node, visitor, recurse, limit, parent) {
|
|
679
633
|
await limit(() => applyVisitor(node, visitor, parent));
|
|
680
|
-
const children = getChildren(node, recurse);
|
|
681
|
-
|
|
634
|
+
const children = Array.from(getChildren(node, recurse));
|
|
635
|
+
if (children.length === 0) return;
|
|
636
|
+
await Promise.all(children.map((child) => _walk(child, visitor, recurse, limit, node)));
|
|
682
637
|
}
|
|
683
638
|
function transform(node, options) {
|
|
684
639
|
const { depth, parent, ...visitor } = options;
|
|
@@ -2356,17 +2311,6 @@ function signatureOf(node) {
|
|
|
2356
2311
|
function schemaSignature(node) {
|
|
2357
2312
|
return signatureOf(node);
|
|
2358
2313
|
}
|
|
2359
|
-
/**
|
|
2360
|
-
* Returns `true` when two schema nodes are structurally identical under shape-only equality.
|
|
2361
|
-
*
|
|
2362
|
-
* @example
|
|
2363
|
-
* ```ts
|
|
2364
|
-
* isSchemaEqual(a, b) // a and b produce the same TypeScript type
|
|
2365
|
-
* ```
|
|
2366
|
-
*/
|
|
2367
|
-
function isSchemaEqual(a, b) {
|
|
2368
|
-
return schemaSignature(a) === schemaSignature(b);
|
|
2369
|
-
}
|
|
2370
2314
|
//#endregion
|
|
2371
2315
|
//#region src/dedupe.ts
|
|
2372
2316
|
/**
|
|
@@ -2706,9 +2650,6 @@ function* mergeAdjacentObjectsLazy(members) {
|
|
|
2706
2650
|
}
|
|
2707
2651
|
if (acc !== void 0) yield acc;
|
|
2708
2652
|
}
|
|
2709
|
-
function mergeAdjacentObjects(members) {
|
|
2710
|
-
return [...mergeAdjacentObjectsLazy(members)];
|
|
2711
|
-
}
|
|
2712
2653
|
/**
|
|
2713
2654
|
* Removes enum members that are covered by broader scalar primitives in the same union.
|
|
2714
2655
|
*
|
|
@@ -2754,14 +2695,11 @@ exports.caseParams = caseParams;
|
|
|
2754
2695
|
exports.childName = childName;
|
|
2755
2696
|
exports.collect = collect;
|
|
2756
2697
|
exports.collectImports = collectImports;
|
|
2757
|
-
exports.collectLazy = collectLazy;
|
|
2758
|
-
exports.collectReferencedSchemaNames = collectReferencedSchemaNames;
|
|
2759
2698
|
exports.collectUsedSchemaNames = collectUsedSchemaNames;
|
|
2760
2699
|
exports.containsCircularRef = containsCircularRef;
|
|
2761
2700
|
exports.createArrowFunction = createArrowFunction;
|
|
2762
2701
|
exports.createBreak = createBreak;
|
|
2763
2702
|
exports.createConst = createConst;
|
|
2764
|
-
exports.createContent = createContent;
|
|
2765
2703
|
exports.createDiscriminantNode = createDiscriminantNode;
|
|
2766
2704
|
exports.createExport = createExport;
|
|
2767
2705
|
exports.createFile = createFile;
|
|
@@ -2779,7 +2717,6 @@ exports.createParameterGroup = createParameterGroup;
|
|
|
2779
2717
|
exports.createParamsType = createParamsType;
|
|
2780
2718
|
exports.createPrinterFactory = createPrinterFactory;
|
|
2781
2719
|
exports.createProperty = createProperty;
|
|
2782
|
-
exports.createRequestBody = createRequestBody;
|
|
2783
2720
|
exports.createResponse = createResponse;
|
|
2784
2721
|
exports.createSchema = createSchema;
|
|
2785
2722
|
exports.createSource = createSource;
|
|
@@ -2799,16 +2736,10 @@ exports.isHttpOperationNode = isHttpOperationNode;
|
|
|
2799
2736
|
exports.isInputNode = isInputNode;
|
|
2800
2737
|
exports.isOperationNode = isOperationNode;
|
|
2801
2738
|
exports.isOutputNode = isOutputNode;
|
|
2802
|
-
exports.isScalarPrimitive = isScalarPrimitive;
|
|
2803
|
-
exports.isSchemaEqual = isSchemaEqual;
|
|
2804
2739
|
exports.isSchemaNode = isSchemaNode;
|
|
2805
2740
|
exports.isStringType = isStringType;
|
|
2806
|
-
exports.mediaTypes = mediaTypes;
|
|
2807
|
-
exports.mergeAdjacentObjects = mergeAdjacentObjects;
|
|
2808
2741
|
exports.mergeAdjacentObjectsLazy = mergeAdjacentObjectsLazy;
|
|
2809
2742
|
exports.narrowSchema = narrowSchema;
|
|
2810
|
-
exports.nodeKinds = nodeKinds;
|
|
2811
|
-
exports.resolveRefName = resolveRefName;
|
|
2812
2743
|
exports.schemaSignature = schemaSignature;
|
|
2813
2744
|
exports.schemaTypes = schemaTypes;
|
|
2814
2745
|
exports.setDiscriminatorEnum = setDiscriminatorEnum;
|