@kubb/ast 5.14.6 → 5.15.0

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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { hash } from "node:crypto";
2
2
  import path from "node:path";
3
- //#region \0rolldown/runtime.js
3
+ // \0rolldown/runtime.js
4
4
  var __defProp = Object.defineProperty;
5
5
  var __exportAll = (all, no_symbols) => {
6
6
  let target = {};
@@ -11,8 +11,7 @@ var __exportAll = (all, no_symbols) => {
11
11
  if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
12
12
  return target;
13
13
  };
14
- //#endregion
15
- //#region src/constants.ts
14
+ // src/constants.ts
16
15
  /**
17
16
  * Node kind discriminators used by every AST node (for example `node.kind === nodeKinds.text`).
18
17
  */
@@ -150,8 +149,7 @@ const schemaTypes = {
150
149
  */
151
150
  never: "never"
152
151
  };
153
- //#endregion
154
- //#region src/guards.ts
152
+ // src/guards.ts
155
153
  /**
156
154
  * Narrows a `SchemaNode` to the variant that matches `type`.
157
155
  *
@@ -177,8 +175,7 @@ function narrowSchema(node, type) {
177
175
  function isHttpOperationNode(node) {
178
176
  return node.protocol === "http" || node.method !== void 0 && node.path !== void 0;
179
177
  }
180
- //#endregion
181
- //#region src/visitor.ts
178
+ // src/visitor.ts
182
179
  /**
183
180
  * Child node fields per node kind, in traversal order (Babel's `VISITOR_KEYS`).
184
181
  */
@@ -487,8 +484,7 @@ function collectInto(node, visitor, recurse, parent, result) {
487
484
  if (v != null) result.push(v);
488
485
  for (const child of getChildren(node, recurse)) collectInto(child, visitor, recurse, node, result);
489
486
  }
490
- //#endregion
491
- //#region src/defineMacro.ts
487
+ // src/defineMacro.ts
492
488
  /**
493
489
  * Sort weight for an `enforce` hint. `pre` sorts before unmarked items and `post` after, so a plain
494
490
  * list keeps its authored order.
@@ -580,8 +576,7 @@ function applyMacros(root, macros, options) {
580
576
  ...options
581
577
  });
582
578
  }
583
- //#endregion
584
- //#region src/optionality.ts
579
+ // src/optionality.ts
585
580
  /**
586
581
  * Generic JSON Schema optionality: a non-required field is optional, and a
587
582
  * non-required nullable field is nullish.
@@ -594,8 +589,7 @@ function optionality(schema, required) {
594
589
  nullish: !required && nullable ? true : void 0
595
590
  };
596
591
  }
597
- //#endregion
598
- //#region src/createPrinter.ts
592
+ // src/createPrinter.ts
599
593
  /**
600
594
  * Creates a schema printer: a function that takes a `SchemaNode` and emits
601
595
  * code in your target language. Each plugin that produces code from schemas
@@ -667,8 +661,7 @@ function createPrinter(build) {
667
661
  };
668
662
  };
669
663
  }
670
- //#endregion
671
- //#region src/utils/extractStringsFromNodes.ts
664
+ // src/utils/extractStringsFromNodes.ts
672
665
  /**
673
666
  * Extracts all string content from a `CodeNode` tree recursively.
674
667
  *
@@ -699,8 +692,7 @@ function extractStringsFromNodes(nodes) {
699
692
  }
700
693
  return collected.join("\n");
701
694
  }
702
- //#endregion
703
- //#region src/utils/combineFileMembers.ts
695
+ // src/utils/combineFileMembers.ts
704
696
  const IDENTIFIER_RUN = /[\w$]+/g;
705
697
  /**
706
698
  * How many imports a file needs before indexing the source beats scanning it once per name.
@@ -844,8 +836,7 @@ function combineImports(imports, exports, source) {
844
836
  }
845
837
  return result;
846
838
  }
847
- //#endregion
848
- //#region src/nodes/base.ts
839
+ // src/nodes/base.ts
849
840
  /** Builds a `createX` factory for a node whose only computed field is `kind`. */
850
841
  function nodeFactory(kind) {
851
842
  return (input) => {
@@ -855,8 +846,7 @@ function nodeFactory(kind) {
855
846
  };
856
847
  };
857
848
  }
858
- //#endregion
859
- //#region src/nodes/file.ts
849
+ // src/nodes/file.ts
860
850
  /**
861
851
  * Creates an `ImportNode` representing a language-agnostic import/dependency declaration.
862
852
  *
@@ -962,8 +952,7 @@ function createFile(input) {
962
952
  meta: input.meta ?? {}
963
953
  };
964
954
  }
965
- //#endregion
966
- //#region src/utils/inline.ts
955
+ // src/utils/inline.ts
967
956
  /**
968
957
  * Whether every source of `file` is inline. Other files absorb such a file, so it is never written.
969
958
  */
@@ -1107,21 +1096,27 @@ function rewriteNodes(nodes, rewrite) {
1107
1096
  }
1108
1097
  });
1109
1098
  }
1110
- //#endregion
1111
- //#region src/utils/refs.ts
1099
+ // src/utils/refs.ts
1112
1100
  /**
1113
1101
  * Returns the last segment of a `$ref` pointer, for example `'Pet'` for `#/components/schemas/Pet`.
1114
1102
  * The segment is decoded like the pointer resolver does: percent-escapes first, then `~1` and `~0`
1115
1103
  * (RFC 6901), so `a~1b~0c` names the component `a/b~c`.
1116
1104
  */
1117
1105
  function refName(ref) {
1106
+ const cached = refNames.get(ref);
1107
+ if (cached !== void 0) return cached;
1118
1108
  const segment = ref.split("/").at(-1) ?? ref;
1119
1109
  let decoded = segment;
1120
1110
  try {
1121
1111
  decoded = decodeURIComponent(segment);
1122
1112
  } catch {}
1123
- return decoded.replaceAll("~1", "/").replaceAll("~0", "~");
1113
+ const name = decoded.replaceAll("~1", "/").replaceAll("~0", "~");
1114
+ if (refNames.size >= memoLimit) refNames.clear();
1115
+ refNames.set(ref, name);
1116
+ return name;
1124
1117
  }
1118
+ const refNames = /* @__PURE__ */ new Map();
1119
+ const memoLimit = 1e5;
1125
1120
  /**
1126
1121
  * Resolves the emitted name of the schema a ref node points at. Prefers `targetName` (set when
1127
1122
  * the referenced schema was renamed, e.g. to break a collision), then the last segment of `ref`,
@@ -1202,8 +1197,7 @@ function isBareRef(node, keysToOmit) {
1202
1197
  const meta = mergeRefWithSchema(node);
1203
1198
  return !meta.nullable && !meta.optional && !meta.nullish && meta.default === void 0 && !meta.description && !meta.examples?.length && !keysToOmit?.length;
1204
1199
  }
1205
- //#endregion
1206
- //#region ../../internals/utils/src/promise.ts
1200
+ // ../../internals/utils/src/promise.ts
1207
1201
  /**
1208
1202
  * Wraps `factory` with a keyed cache backed by the provided store.
1209
1203
  *
@@ -1242,8 +1236,7 @@ function memoize(store, factory) {
1242
1236
  return value;
1243
1237
  };
1244
1238
  }
1245
- //#endregion
1246
- //#region src/utils/schemaGraph.ts
1239
+ // src/utils/schemaGraph.ts
1247
1240
  /**
1248
1241
  * Collects the names of every schema a node's subtree references, resolved with `resolveRefName`.
1249
1242
  * Each ref contributes its name only, so the schema it points to is never traversed. The walk is
@@ -1382,8 +1375,7 @@ function findCircularSchemas(schemas) {
1382
1375
  for (const schema of schemas) if (schema.name) graph.set(schema.name, collectSchemaRefs(schema));
1383
1376
  return findCircularSchemasFromGraph(graph);
1384
1377
  }
1385
- //#endregion
1386
- //#region src/utils/schemaProperties.ts
1378
+ // src/utils/schemaProperties.ts
1387
1379
  /**
1388
1380
  * Finds every matching property exposed by an object, resolved reference, or intersection.
1389
1381
  *
@@ -1499,8 +1491,7 @@ function inferDiscriminatorPropertyName(members) {
1499
1491
  if (values.every((value) => value !== void 0) && new Set(values).size === members.length) return name;
1500
1492
  }
1501
1493
  }
1502
- //#endregion
1503
- //#region src/nodes/code.ts
1494
+ // src/nodes/code.ts
1504
1495
  /**
1505
1496
  * Creates a `ConstNode` representing a TypeScript `const` declaration.
1506
1497
  *
@@ -1583,14 +1574,12 @@ function createJsx(value) {
1583
1574
  value
1584
1575
  };
1585
1576
  }
1586
- //#endregion
1587
- //#region src/nodes/content.ts
1577
+ // src/nodes/content.ts
1588
1578
  /**
1589
1579
  * Creates a `ContentNode` for a single request-body or response content type.
1590
1580
  */
1591
1581
  const createContent = nodeFactory(nodeKinds.content);
1592
- //#endregion
1593
- //#region src/nodes/input.ts
1582
+ // src/nodes/input.ts
1594
1583
  /**
1595
1584
  * Creates an `InputNode`, defaulting `schemas`/`operations` to empty arrays and `meta` to empty
1596
1585
  * name lists. Every call allocates fresh defaults so no two inputs share them.
@@ -1613,14 +1602,12 @@ function createInput(overrides = {}) {
1613
1602
  kind: nodeKinds.input
1614
1603
  };
1615
1604
  }
1616
- //#endregion
1617
- //#region src/nodes/requestBody.ts
1605
+ // src/nodes/requestBody.ts
1618
1606
  /**
1619
1607
  * Creates a `RequestBodyNode`.
1620
1608
  */
1621
1609
  const createRequestBody = nodeFactory(nodeKinds.requestBody);
1622
- //#endregion
1623
- //#region src/nodes/operation.ts
1610
+ // src/nodes/operation.ts
1624
1611
  function createOperation(props) {
1625
1612
  const { requestBody, ...rest } = props;
1626
1613
  const isHttp = rest.method !== void 0 && rest.path !== void 0;
@@ -1634,8 +1621,7 @@ function createOperation(props) {
1634
1621
  requestBody: requestBody ? createRequestBody(requestBody) : void 0
1635
1622
  };
1636
1623
  }
1637
- //#endregion
1638
- //#region src/nodes/parameter.ts
1624
+ // src/nodes/parameter.ts
1639
1625
  /**
1640
1626
  * Creates a `ParameterNode`. `required` defaults to `false`, and the schema's
1641
1627
  * `optional`/`nullish` flags are derived from it.
@@ -1659,8 +1645,7 @@ function createParameter(input) {
1659
1645
  kind: nodeKinds.parameter
1660
1646
  };
1661
1647
  }
1662
- //#endregion
1663
- //#region src/nodes/property.ts
1648
+ // src/nodes/property.ts
1664
1649
  /**
1665
1650
  * Creates a `PropertyNode`. `required` defaults to `false`, and the schema's
1666
1651
  * `optional`/`nullish` flags are derived from it.
@@ -1684,8 +1669,7 @@ function createProperty(input) {
1684
1669
  kind: nodeKinds.property
1685
1670
  };
1686
1671
  }
1687
- //#endregion
1688
- //#region src/nodes/response.ts
1672
+ // src/nodes/response.ts
1689
1673
  /**
1690
1674
  * Creates a `ResponseNode`. A single legacy `schema` (with optional `mediaType`/`keysToOmit`)
1691
1675
  * is normalized into one `content` entry.
@@ -1711,8 +1695,7 @@ function createResponse(props) {
1711
1695
  kind: nodeKinds.response
1712
1696
  };
1713
1697
  }
1714
- //#endregion
1715
- //#region src/nodes/schema.ts
1698
+ // src/nodes/schema.ts
1716
1699
  /**
1717
1700
  * Maps schema `type` to its underlying `primitive`.
1718
1701
  * Primitive types map to themselves and special string formats map to `'string'`.
@@ -1751,8 +1734,7 @@ function createSchema(props) {
1751
1734
  kind: nodeKinds.schema
1752
1735
  };
1753
1736
  }
1754
- //#endregion
1755
- //#region src/nodes/index.ts
1737
+ // src/nodes/index.ts
1756
1738
  var nodes_exports = /* @__PURE__ */ __exportAll({
1757
1739
  createArrowFunction: () => createArrowFunction,
1758
1740
  createBreak: () => createBreak,
@@ -1774,8 +1756,7 @@ var nodes_exports = /* @__PURE__ */ __exportAll({
1774
1756
  createText: () => createText,
1775
1757
  createType: () => createType
1776
1758
  });
1777
- //#endregion
1778
- //#region src/index.ts
1759
+ // src/index.ts
1779
1760
  var src_exports = /* @__PURE__ */ __exportAll({
1780
1761
  applyMacros: () => applyMacros,
1781
1762
  ast: () => src_exports,
@@ -1811,7 +1792,6 @@ var src_exports = /* @__PURE__ */ __exportAll({
1811
1792
  schemaTypes: () => schemaTypes,
1812
1793
  transform: () => transform
1813
1794
  });
1814
- //#endregion
1815
1795
  export { applyMacros, src_exports as ast, collect, collectImportedRefNames, collectSchemaRefs, collectSync, collectUsedSchemaNames, composeMacros, createPrinter, defineMacro, extractStringsFromNodes, nodes_exports as factory, findCircularSchemas, findCircularSchemasFromGraph, findSchema, forEachChild, forEachSchema, getSchemaLiteralValues, inferDiscriminatorPropertyName, inlineFiles, isBareRef, isHttpOperationNode, isVirtualFile, mergeRefWithSchema, narrowSchema, nodeKinds, optionality, refName, resolveRef, resolveRefName, resolveSchemaProperties, schemaTypes, transform };
1816
1796
 
1817
1797
  //# sourceMappingURL=index.js.map