@kubb/ast 5.0.0-beta.13 → 5.0.0-beta.15
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/dist/index.cjs +71 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -21
- package/dist/index.js +70 -51
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/transformers.ts +19 -14
- package/src/utils.ts +22 -11
- package/src/visitor.ts +31 -31
package/dist/index.cjs
CHANGED
|
@@ -533,32 +533,36 @@ function createLimit(concurrency) {
|
|
|
533
533
|
* // returns parameters, requestBody schema (if present), and responses
|
|
534
534
|
* ```
|
|
535
535
|
*/
|
|
536
|
-
function getChildren(node, recurse) {
|
|
536
|
+
function* getChildren(node, recurse) {
|
|
537
537
|
switch (node.kind) {
|
|
538
|
-
case "Input":
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
if (
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
case "
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
case "
|
|
561
|
-
|
|
538
|
+
case "Input":
|
|
539
|
+
yield* node.schemas;
|
|
540
|
+
yield* node.operations;
|
|
541
|
+
break;
|
|
542
|
+
case "Output": break;
|
|
543
|
+
case "Operation":
|
|
544
|
+
yield* node.parameters;
|
|
545
|
+
if (node.requestBody?.content) {
|
|
546
|
+
for (const c of node.requestBody.content) if (c.schema) yield c.schema;
|
|
547
|
+
}
|
|
548
|
+
yield* node.responses;
|
|
549
|
+
break;
|
|
550
|
+
case "Schema":
|
|
551
|
+
if (!recurse) break;
|
|
552
|
+
if ("properties" in node && node.properties.length > 0) yield* node.properties;
|
|
553
|
+
if ("items" in node && node.items) yield* node.items;
|
|
554
|
+
if ("members" in node && node.members) yield* node.members;
|
|
555
|
+
if ("additionalProperties" in node && node.additionalProperties && node.additionalProperties !== true) yield node.additionalProperties;
|
|
556
|
+
break;
|
|
557
|
+
case "Property":
|
|
558
|
+
yield node.schema;
|
|
559
|
+
break;
|
|
560
|
+
case "Parameter":
|
|
561
|
+
yield node.schema;
|
|
562
|
+
break;
|
|
563
|
+
case "Response":
|
|
564
|
+
if (node.schema) yield node.schema;
|
|
565
|
+
break;
|
|
562
566
|
}
|
|
563
567
|
}
|
|
564
568
|
/**
|
|
@@ -745,10 +749,9 @@ function transform(node, options) {
|
|
|
745
749
|
* const values = collect(root, { depth: 'shallow', root: () => 'root' })
|
|
746
750
|
* ```
|
|
747
751
|
*/
|
|
748
|
-
function
|
|
752
|
+
function* collectLazy(node, options) {
|
|
749
753
|
const { depth, parent, ...visitor } = options;
|
|
750
754
|
const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep;
|
|
751
|
-
const results = [];
|
|
752
755
|
let v;
|
|
753
756
|
switch (node.kind) {
|
|
754
757
|
case "Input":
|
|
@@ -776,12 +779,14 @@ function collect(node, options) {
|
|
|
776
779
|
case "ParameterGroup":
|
|
777
780
|
case "FunctionParameters": break;
|
|
778
781
|
}
|
|
779
|
-
if (v !== void 0)
|
|
780
|
-
for (const child of getChildren(node, recurse))
|
|
782
|
+
if (v !== void 0) yield v;
|
|
783
|
+
for (const child of getChildren(node, recurse)) yield* collectLazy(child, {
|
|
781
784
|
...options,
|
|
782
785
|
parent: node
|
|
783
|
-
})
|
|
784
|
-
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
function collect(node, options) {
|
|
789
|
+
return Array.from(collectLazy(node, options));
|
|
785
790
|
}
|
|
786
791
|
//#endregion
|
|
787
792
|
//#region src/utils.ts
|
|
@@ -1281,14 +1286,23 @@ function resolveRefName(node) {
|
|
|
1281
1286
|
* }
|
|
1282
1287
|
* ```
|
|
1283
1288
|
*/
|
|
1284
|
-
|
|
1285
|
-
|
|
1289
|
+
const schemaRefCache = /* @__PURE__ */ new WeakMap();
|
|
1290
|
+
function collectSchemaRefs(node) {
|
|
1291
|
+
const cached = schemaRefCache.get(node);
|
|
1292
|
+
if (cached) return cached;
|
|
1293
|
+
const refs = /* @__PURE__ */ new Set();
|
|
1286
1294
|
collect(node, { schema(child) {
|
|
1287
1295
|
if (child.type === "ref") {
|
|
1288
1296
|
const name = resolveRefName(child);
|
|
1289
|
-
if (name)
|
|
1297
|
+
if (name) refs.add(name);
|
|
1290
1298
|
}
|
|
1291
1299
|
} });
|
|
1300
|
+
schemaRefCache.set(node, refs);
|
|
1301
|
+
return refs;
|
|
1302
|
+
}
|
|
1303
|
+
function collectReferencedSchemaNames(node, out = /* @__PURE__ */ new Set()) {
|
|
1304
|
+
if (!node) return out;
|
|
1305
|
+
for (const name of collectSchemaRefs(node)) out.add(name);
|
|
1292
1306
|
return out;
|
|
1293
1307
|
}
|
|
1294
1308
|
/**
|
|
@@ -1331,7 +1345,7 @@ function collectUsedSchemaNames(operations, schemas) {
|
|
|
1331
1345
|
if (namedSchema) visitSchema(namedSchema);
|
|
1332
1346
|
}
|
|
1333
1347
|
}
|
|
1334
|
-
for (const op of operations) for (const schema of
|
|
1348
|
+
for (const op of operations) for (const schema of collectLazy(op, {
|
|
1335
1349
|
depth: "shallow",
|
|
1336
1350
|
schema: (node) => node
|
|
1337
1351
|
})) visitSchema(schema);
|
|
@@ -1380,11 +1394,12 @@ function findCircularSchemas(schemas) {
|
|
|
1380
1394
|
*/
|
|
1381
1395
|
function containsCircularRef(node, { circularSchemas, excludeName }) {
|
|
1382
1396
|
if (!node || circularSchemas.size === 0) return false;
|
|
1383
|
-
|
|
1397
|
+
for (const _ of collectLazy(node, { schema(child) {
|
|
1384
1398
|
if (child.type !== "ref") return void 0;
|
|
1385
1399
|
const name = resolveRefName(child);
|
|
1386
1400
|
return name && name !== excludeName && circularSchemas.has(name) ? true : void 0;
|
|
1387
|
-
} })
|
|
1401
|
+
} })) return true;
|
|
1402
|
+
return false;
|
|
1388
1403
|
}
|
|
1389
1404
|
//#endregion
|
|
1390
1405
|
//#region src/factory.ts
|
|
@@ -2158,23 +2173,27 @@ function setDiscriminatorEnum({ node, propertyName, values, enumName }) {
|
|
|
2158
2173
|
* ])
|
|
2159
2174
|
* ```
|
|
2160
2175
|
*/
|
|
2161
|
-
function
|
|
2162
|
-
|
|
2176
|
+
function* mergeAdjacentObjectsLazy(members) {
|
|
2177
|
+
let acc;
|
|
2178
|
+
for (const member of members) {
|
|
2163
2179
|
const objectMember = narrowSchema(member, "object");
|
|
2164
|
-
if (objectMember && !objectMember.name) {
|
|
2165
|
-
const
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
...
|
|
2170
|
-
properties: [...previousObject.properties ?? [], ...objectMember.properties ?? []]
|
|
2180
|
+
if (objectMember && !objectMember.name && acc !== void 0) {
|
|
2181
|
+
const accObject = narrowSchema(acc, "object");
|
|
2182
|
+
if (accObject && !accObject.name) {
|
|
2183
|
+
acc = createSchema({
|
|
2184
|
+
...accObject,
|
|
2185
|
+
properties: [...accObject.properties ?? [], ...objectMember.properties ?? []]
|
|
2171
2186
|
});
|
|
2172
|
-
|
|
2187
|
+
continue;
|
|
2173
2188
|
}
|
|
2174
2189
|
}
|
|
2175
|
-
acc
|
|
2176
|
-
|
|
2177
|
-
}
|
|
2190
|
+
if (acc !== void 0) yield acc;
|
|
2191
|
+
acc = member;
|
|
2192
|
+
}
|
|
2193
|
+
if (acc !== void 0) yield acc;
|
|
2194
|
+
}
|
|
2195
|
+
function mergeAdjacentObjects(members) {
|
|
2196
|
+
return [...mergeAdjacentObjectsLazy(members)];
|
|
2178
2197
|
}
|
|
2179
2198
|
/**
|
|
2180
2199
|
* Removes enum members that are covered by broader scalar primitives in the same union.
|
|
@@ -2219,6 +2238,7 @@ exports.caseParams = caseParams;
|
|
|
2219
2238
|
exports.childName = childName;
|
|
2220
2239
|
exports.collect = collect;
|
|
2221
2240
|
exports.collectImports = collectImports;
|
|
2241
|
+
exports.collectLazy = collectLazy;
|
|
2222
2242
|
exports.collectReferencedSchemaNames = collectReferencedSchemaNames;
|
|
2223
2243
|
exports.collectUsedSchemaNames = collectUsedSchemaNames;
|
|
2224
2244
|
exports.containsCircularRef = containsCircularRef;
|
|
@@ -2262,6 +2282,7 @@ exports.isSchemaNode = isSchemaNode;
|
|
|
2262
2282
|
exports.isStringType = isStringType;
|
|
2263
2283
|
exports.mediaTypes = mediaTypes;
|
|
2264
2284
|
exports.mergeAdjacentObjects = mergeAdjacentObjects;
|
|
2285
|
+
exports.mergeAdjacentObjectsLazy = mergeAdjacentObjectsLazy;
|
|
2265
2286
|
exports.narrowSchema = narrowSchema;
|
|
2266
2287
|
exports.nodeKinds = nodeKinds;
|
|
2267
2288
|
exports.resolveRefName = resolveRefName;
|