@kubb/ast 5.14.6 → 5.15.1
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 +37 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -64
- package/dist/index.d.ts +11 -64
- package/dist/index.js +37 -57
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
// \0rolldown/runtime.js
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -29,11 +29,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
29
|
value: mod,
|
|
30
30
|
enumerable: true
|
|
31
31
|
}) : target, mod));
|
|
32
|
-
//#endregion
|
|
33
32
|
let node_crypto = require("node:crypto");
|
|
34
33
|
let node_path = require("node:path");
|
|
35
34
|
node_path = __toESM(node_path, 1);
|
|
36
|
-
|
|
35
|
+
// src/constants.ts
|
|
37
36
|
/**
|
|
38
37
|
* Node kind discriminators used by every AST node (for example `node.kind === nodeKinds.text`).
|
|
39
38
|
*/
|
|
@@ -171,8 +170,7 @@ const schemaTypes = {
|
|
|
171
170
|
*/
|
|
172
171
|
never: "never"
|
|
173
172
|
};
|
|
174
|
-
|
|
175
|
-
//#region src/guards.ts
|
|
173
|
+
// src/guards.ts
|
|
176
174
|
/**
|
|
177
175
|
* Narrows a `SchemaNode` to the variant that matches `type`.
|
|
178
176
|
*
|
|
@@ -198,8 +196,7 @@ function narrowSchema(node, type) {
|
|
|
198
196
|
function isHttpOperationNode(node) {
|
|
199
197
|
return node.protocol === "http" || node.method !== void 0 && node.path !== void 0;
|
|
200
198
|
}
|
|
201
|
-
|
|
202
|
-
//#region src/visitor.ts
|
|
199
|
+
// src/visitor.ts
|
|
203
200
|
/**
|
|
204
201
|
* Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`).
|
|
205
202
|
*/
|
|
@@ -508,8 +505,7 @@ function collectInto(node, visitor, recurse, parent, result) {
|
|
|
508
505
|
if (v != null) result.push(v);
|
|
509
506
|
for (const child of getChildren(node, recurse)) collectInto(child, visitor, recurse, node, result);
|
|
510
507
|
}
|
|
511
|
-
|
|
512
|
-
//#region src/defineMacro.ts
|
|
508
|
+
// src/defineMacro.ts
|
|
513
509
|
/**
|
|
514
510
|
* Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain
|
|
515
511
|
* list keeps its authored order.
|
|
@@ -601,8 +597,7 @@ function applyMacros(root, macros, options) {
|
|
|
601
597
|
...options
|
|
602
598
|
});
|
|
603
599
|
}
|
|
604
|
-
|
|
605
|
-
//#region src/optionality.ts
|
|
600
|
+
// src/optionality.ts
|
|
606
601
|
/**
|
|
607
602
|
* Generic JSON Schema optionality: a non-required field is optional, and a
|
|
608
603
|
* non-required nullable field is nullish.
|
|
@@ -615,8 +610,7 @@ function optionality(schema, required) {
|
|
|
615
610
|
nullish: !required && nullable ? true : void 0
|
|
616
611
|
};
|
|
617
612
|
}
|
|
618
|
-
|
|
619
|
-
//#region src/createPrinter.ts
|
|
613
|
+
// src/createPrinter.ts
|
|
620
614
|
/**
|
|
621
615
|
* Creates a schema printer: a function that takes a `SchemaNode` and emits
|
|
622
616
|
* code in your target language. Each plugin that produces code from schemas
|
|
@@ -688,8 +682,7 @@ function createPrinter(build) {
|
|
|
688
682
|
};
|
|
689
683
|
};
|
|
690
684
|
}
|
|
691
|
-
|
|
692
|
-
//#region src/utils/extractStringsFromNodes.ts
|
|
685
|
+
// src/utils/extractStringsFromNodes.ts
|
|
693
686
|
/**
|
|
694
687
|
* Extracts all string content from a `CodeNode` tree recursively.
|
|
695
688
|
*
|
|
@@ -720,8 +713,7 @@ function extractStringsFromNodes(nodes) {
|
|
|
720
713
|
}
|
|
721
714
|
return collected.join("\n");
|
|
722
715
|
}
|
|
723
|
-
|
|
724
|
-
//#region src/utils/combineFileMembers.ts
|
|
716
|
+
// src/utils/combineFileMembers.ts
|
|
725
717
|
const IDENTIFIER_RUN = /[\w$]+/g;
|
|
726
718
|
/**
|
|
727
719
|
* How many imports a file needs before indexing the source beats scanning it once per name.
|
|
@@ -865,8 +857,7 @@ function combineImports(imports, exports, source) {
|
|
|
865
857
|
}
|
|
866
858
|
return result;
|
|
867
859
|
}
|
|
868
|
-
|
|
869
|
-
//#region src/nodes/base.ts
|
|
860
|
+
// src/nodes/base.ts
|
|
870
861
|
/** Builds a `createX` factory for a node whose only computed field is `kind`. */
|
|
871
862
|
function nodeFactory(kind) {
|
|
872
863
|
return (input) => {
|
|
@@ -876,8 +867,7 @@ function nodeFactory(kind) {
|
|
|
876
867
|
};
|
|
877
868
|
};
|
|
878
869
|
}
|
|
879
|
-
|
|
880
|
-
//#region src/nodes/file.ts
|
|
870
|
+
// src/nodes/file.ts
|
|
881
871
|
/**
|
|
882
872
|
* Creates an `ImportNode` representing a language-agnostic import/dependency declaration.
|
|
883
873
|
*
|
|
@@ -983,8 +973,7 @@ function createFile(input) {
|
|
|
983
973
|
meta: input.meta ?? {}
|
|
984
974
|
};
|
|
985
975
|
}
|
|
986
|
-
|
|
987
|
-
//#region src/utils/inline.ts
|
|
976
|
+
// src/utils/inline.ts
|
|
988
977
|
/**
|
|
989
978
|
* Whether every source of `file` is inline. Other files absorb such a file, so it is never written.
|
|
990
979
|
*/
|
|
@@ -1128,21 +1117,27 @@ function rewriteNodes(nodes, rewrite) {
|
|
|
1128
1117
|
}
|
|
1129
1118
|
});
|
|
1130
1119
|
}
|
|
1131
|
-
|
|
1132
|
-
//#region src/utils/refs.ts
|
|
1120
|
+
// src/utils/refs.ts
|
|
1133
1121
|
/**
|
|
1134
1122
|
* Returns the last segment of a `$ref` pointer, for example `'Pet'` for `#/components/schemas/Pet`.
|
|
1135
1123
|
* The segment is decoded like the pointer resolver does: percent-escapes first, then `~1` and `~0`
|
|
1136
1124
|
* (RFC 6901), so `a~1b~0c` names the component `a/b~c`.
|
|
1137
1125
|
*/
|
|
1138
1126
|
function refName(ref) {
|
|
1127
|
+
const cached = refNames.get(ref);
|
|
1128
|
+
if (cached !== void 0) return cached;
|
|
1139
1129
|
const segment = ref.split("/").at(-1) ?? ref;
|
|
1140
1130
|
let decoded = segment;
|
|
1141
1131
|
try {
|
|
1142
1132
|
decoded = decodeURIComponent(segment);
|
|
1143
1133
|
} catch {}
|
|
1144
|
-
|
|
1134
|
+
const name = decoded.replaceAll("~1", "/").replaceAll("~0", "~");
|
|
1135
|
+
if (refNames.size >= memoLimit) refNames.clear();
|
|
1136
|
+
refNames.set(ref, name);
|
|
1137
|
+
return name;
|
|
1145
1138
|
}
|
|
1139
|
+
const refNames = /* @__PURE__ */ new Map();
|
|
1140
|
+
const memoLimit = 1e5;
|
|
1146
1141
|
/**
|
|
1147
1142
|
* Resolves the emitted name of the schema a ref node points at. Prefers `targetName` (set when
|
|
1148
1143
|
* the referenced schema was renamed, e.g. to break a collision), then the last segment of `ref`,
|
|
@@ -1223,8 +1218,7 @@ function isBareRef(node, keysToOmit) {
|
|
|
1223
1218
|
const meta = mergeRefWithSchema(node);
|
|
1224
1219
|
return !meta.nullable && !meta.optional && !meta.nullish && meta.default === void 0 && !meta.description && !meta.examples?.length && !keysToOmit?.length;
|
|
1225
1220
|
}
|
|
1226
|
-
|
|
1227
|
-
//#region ../../internals/utils/src/promise.ts
|
|
1221
|
+
// ../../internals/utils/src/promise.ts
|
|
1228
1222
|
/**
|
|
1229
1223
|
* Wraps `factory` with a keyed cache backed by the provided store.
|
|
1230
1224
|
*
|
|
@@ -1263,8 +1257,7 @@ function memoize(store, factory) {
|
|
|
1263
1257
|
return value;
|
|
1264
1258
|
};
|
|
1265
1259
|
}
|
|
1266
|
-
|
|
1267
|
-
//#region src/utils/schemaGraph.ts
|
|
1260
|
+
// src/utils/schemaGraph.ts
|
|
1268
1261
|
/**
|
|
1269
1262
|
* Collects the names of every schema a node's subtree references, resolved with `resolveRefName`.
|
|
1270
1263
|
* Each ref contributes its name only, so the schema it points to is never traversed. The walk is
|
|
@@ -1403,8 +1396,7 @@ function findCircularSchemas(schemas) {
|
|
|
1403
1396
|
for (const schema of schemas) if (schema.name) graph.set(schema.name, collectSchemaRefs(schema));
|
|
1404
1397
|
return findCircularSchemasFromGraph(graph);
|
|
1405
1398
|
}
|
|
1406
|
-
|
|
1407
|
-
//#region src/utils/schemaProperties.ts
|
|
1399
|
+
// src/utils/schemaProperties.ts
|
|
1408
1400
|
/**
|
|
1409
1401
|
* Finds every matching property exposed by an object, resolved reference, or intersection.
|
|
1410
1402
|
*
|
|
@@ -1520,8 +1512,7 @@ function inferDiscriminatorPropertyName(members) {
|
|
|
1520
1512
|
if (values.every((value) => value !== void 0) && new Set(values).size === members.length) return name;
|
|
1521
1513
|
}
|
|
1522
1514
|
}
|
|
1523
|
-
|
|
1524
|
-
//#region src/nodes/code.ts
|
|
1515
|
+
// src/nodes/code.ts
|
|
1525
1516
|
/**
|
|
1526
1517
|
* Creates a `ConstNode` representing a TypeScript `const` declaration.
|
|
1527
1518
|
*
|
|
@@ -1604,14 +1595,12 @@ function createJsx(value) {
|
|
|
1604
1595
|
value
|
|
1605
1596
|
};
|
|
1606
1597
|
}
|
|
1607
|
-
|
|
1608
|
-
//#region src/nodes/content.ts
|
|
1598
|
+
// src/nodes/content.ts
|
|
1609
1599
|
/**
|
|
1610
1600
|
* Creates a `ContentNode` for a single request-body or response content type.
|
|
1611
1601
|
*/
|
|
1612
1602
|
const createContent = nodeFactory(nodeKinds.content);
|
|
1613
|
-
|
|
1614
|
-
//#region src/nodes/input.ts
|
|
1603
|
+
// src/nodes/input.ts
|
|
1615
1604
|
/**
|
|
1616
1605
|
* Creates an `InputNode`, defaulting `schemas`/`operations` to empty arrays and `meta` to empty
|
|
1617
1606
|
* name lists. Every call allocates fresh defaults so no two inputs share them.
|
|
@@ -1627,21 +1616,19 @@ function createInput(overrides = {}) {
|
|
|
1627
1616
|
schemas: [],
|
|
1628
1617
|
operations: [],
|
|
1629
1618
|
meta: {
|
|
1630
|
-
circularNames:
|
|
1631
|
-
enumNames:
|
|
1619
|
+
circularNames: /* @__PURE__ */ new Set(),
|
|
1620
|
+
enumNames: /* @__PURE__ */ new Set()
|
|
1632
1621
|
},
|
|
1633
1622
|
...overrides,
|
|
1634
1623
|
kind: nodeKinds.input
|
|
1635
1624
|
};
|
|
1636
1625
|
}
|
|
1637
|
-
|
|
1638
|
-
//#region src/nodes/requestBody.ts
|
|
1626
|
+
// src/nodes/requestBody.ts
|
|
1639
1627
|
/**
|
|
1640
1628
|
* Creates a `RequestBodyNode`.
|
|
1641
1629
|
*/
|
|
1642
1630
|
const createRequestBody = nodeFactory(nodeKinds.requestBody);
|
|
1643
|
-
|
|
1644
|
-
//#region src/nodes/operation.ts
|
|
1631
|
+
// src/nodes/operation.ts
|
|
1645
1632
|
function createOperation(props) {
|
|
1646
1633
|
const { requestBody, ...rest } = props;
|
|
1647
1634
|
const isHttp = rest.method !== void 0 && rest.path !== void 0;
|
|
@@ -1655,8 +1642,7 @@ function createOperation(props) {
|
|
|
1655
1642
|
requestBody: requestBody ? createRequestBody(requestBody) : void 0
|
|
1656
1643
|
};
|
|
1657
1644
|
}
|
|
1658
|
-
|
|
1659
|
-
//#region src/nodes/parameter.ts
|
|
1645
|
+
// src/nodes/parameter.ts
|
|
1660
1646
|
/**
|
|
1661
1647
|
* Creates a `ParameterNode`. `required` defaults to `false`, and the schema's
|
|
1662
1648
|
* `optional`/`nullish` flags are derived from it.
|
|
@@ -1680,8 +1666,7 @@ function createParameter(input) {
|
|
|
1680
1666
|
kind: nodeKinds.parameter
|
|
1681
1667
|
};
|
|
1682
1668
|
}
|
|
1683
|
-
|
|
1684
|
-
//#region src/nodes/property.ts
|
|
1669
|
+
// src/nodes/property.ts
|
|
1685
1670
|
/**
|
|
1686
1671
|
* Creates a `PropertyNode`. `required` defaults to `false`, and the schema's
|
|
1687
1672
|
* `optional`/`nullish` flags are derived from it.
|
|
@@ -1705,8 +1690,7 @@ function createProperty(input) {
|
|
|
1705
1690
|
kind: nodeKinds.property
|
|
1706
1691
|
};
|
|
1707
1692
|
}
|
|
1708
|
-
|
|
1709
|
-
//#region src/nodes/response.ts
|
|
1693
|
+
// src/nodes/response.ts
|
|
1710
1694
|
/**
|
|
1711
1695
|
* Creates a `ResponseNode`. A single legacy `schema` (with optional `mediaType`/`keysToOmit`)
|
|
1712
1696
|
* is normalized into one `content` entry.
|
|
@@ -1732,8 +1716,7 @@ function createResponse(props) {
|
|
|
1732
1716
|
kind: nodeKinds.response
|
|
1733
1717
|
};
|
|
1734
1718
|
}
|
|
1735
|
-
|
|
1736
|
-
//#region src/nodes/schema.ts
|
|
1719
|
+
// src/nodes/schema.ts
|
|
1737
1720
|
/**
|
|
1738
1721
|
* Maps schema `type` to its underlying `primitive`.
|
|
1739
1722
|
* Primitive types map to themselves and special string formats map to `'string'`.
|
|
@@ -1772,8 +1755,7 @@ function createSchema(props) {
|
|
|
1772
1755
|
kind: nodeKinds.schema
|
|
1773
1756
|
};
|
|
1774
1757
|
}
|
|
1775
|
-
|
|
1776
|
-
//#region src/nodes/index.ts
|
|
1758
|
+
// src/nodes/index.ts
|
|
1777
1759
|
var nodes_exports = /* @__PURE__ */ __exportAll({
|
|
1778
1760
|
createArrowFunction: () => createArrowFunction,
|
|
1779
1761
|
createBreak: () => createBreak,
|
|
@@ -1795,8 +1777,7 @@ var nodes_exports = /* @__PURE__ */ __exportAll({
|
|
|
1795
1777
|
createText: () => createText,
|
|
1796
1778
|
createType: () => createType
|
|
1797
1779
|
});
|
|
1798
|
-
|
|
1799
|
-
//#region src/index.ts
|
|
1780
|
+
// src/index.ts
|
|
1800
1781
|
var src_exports = /* @__PURE__ */ __exportAll({
|
|
1801
1782
|
applyMacros: () => applyMacros,
|
|
1802
1783
|
ast: () => src_exports,
|
|
@@ -1832,7 +1813,6 @@ var src_exports = /* @__PURE__ */ __exportAll({
|
|
|
1832
1813
|
schemaTypes: () => schemaTypes,
|
|
1833
1814
|
transform: () => transform
|
|
1834
1815
|
});
|
|
1835
|
-
//#endregion
|
|
1836
1816
|
exports.applyMacros = applyMacros;
|
|
1837
1817
|
Object.defineProperty(exports, "ast", {
|
|
1838
1818
|
enumerable: true,
|