@kubb/ast 5.0.0-beta.18 → 5.0.0-beta.19
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 +33 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -35
- package/dist/index.js +33 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/utils.ts +41 -10
- package/src/visitor.ts +7 -36
package/dist/index.cjs
CHANGED
|
@@ -623,9 +623,7 @@ function transform(node, options) {
|
|
|
623
623
|
const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep;
|
|
624
624
|
switch (node.kind) {
|
|
625
625
|
case "Input": {
|
|
626
|
-
|
|
627
|
-
const replaced = visitor.input?.(input, { parent });
|
|
628
|
-
if (replaced) input = replaced;
|
|
626
|
+
const input = visitor.input?.(node, { parent }) ?? node;
|
|
629
627
|
return {
|
|
630
628
|
...input,
|
|
631
629
|
schemas: input.schemas.map((s) => transform(s, {
|
|
@@ -638,16 +636,9 @@ function transform(node, options) {
|
|
|
638
636
|
}))
|
|
639
637
|
};
|
|
640
638
|
}
|
|
641
|
-
case "Output": {
|
|
642
|
-
let output = node;
|
|
643
|
-
const replaced = visitor.output?.(output, { parent });
|
|
644
|
-
if (replaced) output = replaced;
|
|
645
|
-
return output;
|
|
646
|
-
}
|
|
639
|
+
case "Output": return visitor.output?.(node, { parent }) ?? node;
|
|
647
640
|
case "Operation": {
|
|
648
|
-
|
|
649
|
-
const replaced = visitor.operation?.(op, { parent });
|
|
650
|
-
if (replaced) op = replaced;
|
|
641
|
+
const op = visitor.operation?.(node, { parent }) ?? node;
|
|
651
642
|
return {
|
|
652
643
|
...op,
|
|
653
644
|
parameters: op.parameters.map((p) => transform(p, {
|
|
@@ -671,9 +662,7 @@ function transform(node, options) {
|
|
|
671
662
|
};
|
|
672
663
|
}
|
|
673
664
|
case "Schema": {
|
|
674
|
-
|
|
675
|
-
const replaced = visitor.schema?.(schema, { parent });
|
|
676
|
-
if (replaced) schema = replaced;
|
|
665
|
+
const schema = visitor.schema?.(node, { parent }) ?? node;
|
|
677
666
|
const childOptions = {
|
|
678
667
|
...options,
|
|
679
668
|
parent: schema
|
|
@@ -687,9 +676,7 @@ function transform(node, options) {
|
|
|
687
676
|
};
|
|
688
677
|
}
|
|
689
678
|
case "Property": {
|
|
690
|
-
|
|
691
|
-
const replaced = visitor.property?.(prop, { parent });
|
|
692
|
-
if (replaced) prop = replaced;
|
|
679
|
+
const prop = visitor.property?.(node, { parent }) ?? node;
|
|
693
680
|
return createProperty({
|
|
694
681
|
...prop,
|
|
695
682
|
schema: transform(prop.schema, {
|
|
@@ -699,9 +686,7 @@ function transform(node, options) {
|
|
|
699
686
|
});
|
|
700
687
|
}
|
|
701
688
|
case "Parameter": {
|
|
702
|
-
|
|
703
|
-
const replaced = visitor.parameter?.(param, { parent });
|
|
704
|
-
if (replaced) param = replaced;
|
|
689
|
+
const param = visitor.parameter?.(node, { parent }) ?? node;
|
|
705
690
|
return createParameter({
|
|
706
691
|
...param,
|
|
707
692
|
schema: transform(param.schema, {
|
|
@@ -711,9 +696,7 @@ function transform(node, options) {
|
|
|
711
696
|
});
|
|
712
697
|
}
|
|
713
698
|
case "Response": {
|
|
714
|
-
|
|
715
|
-
const replaced = visitor.response?.(response, { parent });
|
|
716
|
-
if (replaced) response = replaced;
|
|
699
|
+
const response = visitor.response?.(node, { parent }) ?? node;
|
|
717
700
|
return {
|
|
718
701
|
...response,
|
|
719
702
|
schema: transform(response.schema, {
|
|
@@ -840,15 +823,25 @@ function isStringType(node) {
|
|
|
840
823
|
* the desired casing while preserving `OperationNode.parameters` for other consumers.
|
|
841
824
|
* The input array is not mutated. When `casing` is not set, the original array is returned unchanged.
|
|
842
825
|
*/
|
|
826
|
+
const caseParamsCache = /* @__PURE__ */ new WeakMap();
|
|
843
827
|
function caseParams(params, casing) {
|
|
844
828
|
if (!casing) return params;
|
|
845
|
-
|
|
829
|
+
let byParams = caseParamsCache.get(params);
|
|
830
|
+
if (!byParams) {
|
|
831
|
+
byParams = /* @__PURE__ */ new Map();
|
|
832
|
+
caseParamsCache.set(params, byParams);
|
|
833
|
+
}
|
|
834
|
+
const cached = byParams.get(casing);
|
|
835
|
+
if (cached) return cached;
|
|
836
|
+
const result = params.map((param) => {
|
|
846
837
|
const transformed = casing === "camelcase" || !isValidVarName(param.name) ? camelCase(param.name) : param.name;
|
|
847
838
|
return {
|
|
848
839
|
...param,
|
|
849
840
|
name: transformed
|
|
850
841
|
};
|
|
851
842
|
});
|
|
843
|
+
byParams.set(casing, result);
|
|
844
|
+
return result;
|
|
852
845
|
}
|
|
853
846
|
/**
|
|
854
847
|
* Creates a single-property object schema used as a discriminator literal.
|
|
@@ -1333,7 +1326,15 @@ function collectReferencedSchemaNames(node, out = /* @__PURE__ */ new Set()) {
|
|
|
1333
1326
|
* allowed.has('OrderStatus') // false when no included operation references OrderStatus
|
|
1334
1327
|
* ```
|
|
1335
1328
|
*/
|
|
1329
|
+
const usedSchemaNamesCache = /* @__PURE__ */ new WeakMap();
|
|
1336
1330
|
function collectUsedSchemaNames(operations, schemas) {
|
|
1331
|
+
let byOps = usedSchemaNamesCache.get(operations);
|
|
1332
|
+
if (!byOps) {
|
|
1333
|
+
byOps = /* @__PURE__ */ new WeakMap();
|
|
1334
|
+
usedSchemaNamesCache.set(operations, byOps);
|
|
1335
|
+
}
|
|
1336
|
+
const cached = byOps.get(schemas);
|
|
1337
|
+
if (cached) return cached;
|
|
1337
1338
|
const schemaMap = /* @__PURE__ */ new Map();
|
|
1338
1339
|
for (const schema of schemas) if (schema.name) schemaMap.set(schema.name, schema);
|
|
1339
1340
|
const result = /* @__PURE__ */ new Set();
|
|
@@ -1349,8 +1350,11 @@ function collectUsedSchemaNames(operations, schemas) {
|
|
|
1349
1350
|
depth: "shallow",
|
|
1350
1351
|
schema: (node) => node
|
|
1351
1352
|
})) visitSchema(schema);
|
|
1353
|
+
byOps.set(schemas, result);
|
|
1352
1354
|
return result;
|
|
1353
1355
|
}
|
|
1356
|
+
const EMPTY_CIRCULAR_SET = /* @__PURE__ */ new Set();
|
|
1357
|
+
const circularSchemaCache = /* @__PURE__ */ new WeakMap();
|
|
1354
1358
|
/**
|
|
1355
1359
|
* Identifies all schemas that participate in circular dependency chains, including direct self-loops.
|
|
1356
1360
|
*
|
|
@@ -1361,6 +1365,9 @@ function collectUsedSchemaNames(operations, schemas) {
|
|
|
1361
1365
|
* @note Call this once on the full schema graph, then use `containsCircularRef()` to check individual schemas.
|
|
1362
1366
|
*/
|
|
1363
1367
|
function findCircularSchemas(schemas) {
|
|
1368
|
+
if (schemas.length === 0) return EMPTY_CIRCULAR_SET;
|
|
1369
|
+
const cached = circularSchemaCache.get(schemas);
|
|
1370
|
+
if (cached) return cached;
|
|
1364
1371
|
const graph = /* @__PURE__ */ new Map();
|
|
1365
1372
|
for (const schema of schemas) {
|
|
1366
1373
|
if (!schema.name) continue;
|
|
@@ -1382,6 +1389,7 @@ function findCircularSchemas(schemas) {
|
|
|
1382
1389
|
if (next) for (const r of next) stack.push(r);
|
|
1383
1390
|
}
|
|
1384
1391
|
}
|
|
1392
|
+
circularSchemaCache.set(schemas, circular);
|
|
1385
1393
|
return circular;
|
|
1386
1394
|
}
|
|
1387
1395
|
/**
|