@hey-api/shared 0.0.0-next-20260701201812 → 0.0.0-next-20260701212054
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.d.mts +29 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +296 -143
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1602,63 +1602,83 @@ async function getSpec({ fetchOptions, inputPath, timeout, watch }) {
|
|
|
1602
1602
|
}
|
|
1603
1603
|
//#endregion
|
|
1604
1604
|
//#region src/utils/minHeap.ts
|
|
1605
|
+
/**
|
|
1606
|
+
* Binary min-heap keyed by a numeric priority. Priorities are passed in
|
|
1607
|
+
* alongside each item (rather than looked up from a `Map` on every
|
|
1608
|
+
* comparison) so heap operations do plain number comparisons instead of
|
|
1609
|
+
* string-keyed map lookups — significant on graphs with hundreds of
|
|
1610
|
+
* thousands of nodes, since each push/pop does O(log n) comparisons.
|
|
1611
|
+
*/
|
|
1605
1612
|
var MinHeap = class {
|
|
1606
|
-
declIndex;
|
|
1607
1613
|
heap = [];
|
|
1608
|
-
|
|
1609
|
-
this.declIndex = declIndex;
|
|
1610
|
-
}
|
|
1614
|
+
priorities = [];
|
|
1611
1615
|
isEmpty() {
|
|
1612
1616
|
return !this.heap.length;
|
|
1613
1617
|
}
|
|
1614
1618
|
pop() {
|
|
1615
|
-
const
|
|
1619
|
+
const top = this.heap[0];
|
|
1616
1620
|
if (!this.heap.length) return;
|
|
1617
1621
|
const last = this.heap.pop();
|
|
1622
|
+
const lastPriority = this.priorities.pop();
|
|
1618
1623
|
if (!this.heap.length) return top;
|
|
1619
1624
|
this.heap[0] = last;
|
|
1625
|
+
this.priorities[0] = lastPriority;
|
|
1620
1626
|
this.sinkDown(0);
|
|
1621
1627
|
return top;
|
|
1622
1628
|
}
|
|
1623
|
-
push(item) {
|
|
1629
|
+
push(item, priority) {
|
|
1624
1630
|
this.heap.push(item);
|
|
1631
|
+
this.priorities.push(priority);
|
|
1625
1632
|
this.bubbleUp(this.heap.length - 1);
|
|
1626
1633
|
}
|
|
1627
1634
|
bubbleUp(index) {
|
|
1628
1635
|
const heap = this.heap;
|
|
1636
|
+
const priorities = this.priorities;
|
|
1637
|
+
const curVal = heap[index];
|
|
1638
|
+
const curPriority = priorities[index];
|
|
1629
1639
|
while (index > 0) {
|
|
1630
|
-
const parent =
|
|
1631
|
-
const
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
heap[index] = parentVal;
|
|
1640
|
+
const parent = index - 1 >> 1;
|
|
1641
|
+
const parentPriority = priorities[parent];
|
|
1642
|
+
if (parentPriority <= curPriority) break;
|
|
1643
|
+
heap[index] = heap[parent];
|
|
1644
|
+
priorities[index] = parentPriority;
|
|
1636
1645
|
index = parent;
|
|
1637
1646
|
}
|
|
1647
|
+
heap[index] = curVal;
|
|
1648
|
+
priorities[index] = curPriority;
|
|
1638
1649
|
}
|
|
1639
1650
|
sinkDown(index) {
|
|
1640
1651
|
const heap = this.heap;
|
|
1652
|
+
const priorities = this.priorities;
|
|
1641
1653
|
const len = heap.length;
|
|
1654
|
+
const curVal = heap[index];
|
|
1655
|
+
const curPriority = priorities[index];
|
|
1642
1656
|
while (true) {
|
|
1643
1657
|
const left = 2 * index + 1;
|
|
1644
1658
|
const right = 2 * index + 2;
|
|
1645
1659
|
let smallest = index;
|
|
1660
|
+
let smallestPriority = curPriority;
|
|
1646
1661
|
if (left < len) {
|
|
1647
|
-
const
|
|
1648
|
-
|
|
1649
|
-
|
|
1662
|
+
const leftPriority = priorities[left];
|
|
1663
|
+
if (leftPriority < smallestPriority) {
|
|
1664
|
+
smallest = left;
|
|
1665
|
+
smallestPriority = leftPriority;
|
|
1666
|
+
}
|
|
1650
1667
|
}
|
|
1651
1668
|
if (right < len) {
|
|
1652
|
-
const
|
|
1653
|
-
|
|
1654
|
-
|
|
1669
|
+
const rightPriority = priorities[right];
|
|
1670
|
+
if (rightPriority < smallestPriority) {
|
|
1671
|
+
smallest = right;
|
|
1672
|
+
smallestPriority = rightPriority;
|
|
1673
|
+
}
|
|
1655
1674
|
}
|
|
1656
1675
|
if (smallest === index) break;
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
heap[index] = tmp;
|
|
1676
|
+
heap[index] = heap[smallest];
|
|
1677
|
+
priorities[index] = priorities[smallest];
|
|
1660
1678
|
index = smallest;
|
|
1661
1679
|
}
|
|
1680
|
+
heap[index] = curVal;
|
|
1681
|
+
priorities[index] = curPriority;
|
|
1662
1682
|
}
|
|
1663
1683
|
};
|
|
1664
1684
|
//#endregion
|
|
@@ -1703,42 +1723,71 @@ const walkDeclarations = (graph, callback, options) => {
|
|
|
1703
1723
|
}
|
|
1704
1724
|
for (const [pointer, node] of graph.nodes) callback(pointer, node);
|
|
1705
1725
|
};
|
|
1726
|
+
const topologicalOrderCache = /* @__PURE__ */ new WeakMap();
|
|
1727
|
+
const referenceIds = /* @__PURE__ */ new WeakMap();
|
|
1728
|
+
let nextReferenceId = 0;
|
|
1729
|
+
function referenceId(value) {
|
|
1730
|
+
if (value === void 0) return 0;
|
|
1731
|
+
let id = referenceIds.get(value);
|
|
1732
|
+
if (id === void 0) {
|
|
1733
|
+
id = ++nextReferenceId;
|
|
1734
|
+
referenceIds.set(value, id);
|
|
1735
|
+
}
|
|
1736
|
+
return id;
|
|
1737
|
+
}
|
|
1738
|
+
function computeTopologicalOrder(graph, options) {
|
|
1739
|
+
let cacheForGraph = topologicalOrderCache.get(graph);
|
|
1740
|
+
const cacheKey = `${referenceId(options?.getPointerPriority)}:${referenceId(options?.matchPointerToGroup)}:${referenceId(options?.preferGroups)}`;
|
|
1741
|
+
if (cacheForGraph) {
|
|
1742
|
+
const cached = cacheForGraph.get(cacheKey);
|
|
1743
|
+
if (cached) return cached;
|
|
1744
|
+
} else {
|
|
1745
|
+
cacheForGraph = /* @__PURE__ */ new Map();
|
|
1746
|
+
topologicalOrderCache.set(graph, cacheForGraph);
|
|
1747
|
+
}
|
|
1748
|
+
const order = computeTopologicalOrderUncached(graph, options);
|
|
1749
|
+
cacheForGraph.set(cacheKey, order);
|
|
1750
|
+
return order;
|
|
1751
|
+
}
|
|
1706
1752
|
/**
|
|
1707
|
-
*
|
|
1708
|
-
*
|
|
1709
|
-
*
|
|
1710
|
-
*
|
|
1711
|
-
* @param graph - The dependency graph
|
|
1712
|
-
* @param callback - Function to call for each node pointer
|
|
1753
|
+
* Computes the topological order (dependencies before dependents) of the
|
|
1754
|
+
* graph's nodes. Nodes in cycles are grouped together and emitted in
|
|
1755
|
+
* arbitrary order within the group.
|
|
1713
1756
|
*/
|
|
1714
|
-
|
|
1757
|
+
function computeTopologicalOrderUncached(graph, options) {
|
|
1715
1758
|
const pointers = Array.from(graph.nodes.keys());
|
|
1716
1759
|
const declIndex = /* @__PURE__ */ new Map();
|
|
1717
1760
|
const depsOf = /* @__PURE__ */ new Map();
|
|
1718
1761
|
const inDegree = /* @__PURE__ */ new Map();
|
|
1719
1762
|
const dependents = /* @__PURE__ */ new Map();
|
|
1720
|
-
const heap = new MinHeap(
|
|
1721
|
-
|
|
1722
|
-
const
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
const
|
|
1726
|
-
|
|
1763
|
+
const heap = new MinHeap();
|
|
1764
|
+
for (let index = 0, len = pointers.length; index < len; index++) {
|
|
1765
|
+
const pointer = pointers[index];
|
|
1766
|
+
const declPriority = (options?.getPointerPriority?.(pointer) ?? 10) * 1e6 + index;
|
|
1767
|
+
declIndex.set(pointer, declPriority);
|
|
1768
|
+
const raw = graph.subtreeDependencies?.get(pointer);
|
|
1769
|
+
let deps;
|
|
1770
|
+
if (raw && raw.size) for (const rawPointer of raw) {
|
|
1727
1771
|
if (rawPointer === pointer) continue;
|
|
1728
|
-
if (graph.nodes.has(rawPointer))
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
dep =
|
|
1736
|
-
|
|
1772
|
+
if (!graph.nodes.has(rawPointer)) continue;
|
|
1773
|
+
(deps ??= /* @__PURE__ */ new Set()).add(rawPointer);
|
|
1774
|
+
}
|
|
1775
|
+
if (deps) {
|
|
1776
|
+
depsOf.set(pointer, deps);
|
|
1777
|
+
inDegree.set(pointer, deps.size);
|
|
1778
|
+
for (const d of deps) {
|
|
1779
|
+
let dep = dependents.get(d);
|
|
1780
|
+
if (!dep) {
|
|
1781
|
+
dep = /* @__PURE__ */ new Set();
|
|
1782
|
+
dependents.set(d, dep);
|
|
1783
|
+
}
|
|
1784
|
+
dep.add(pointer);
|
|
1737
1785
|
}
|
|
1738
|
-
|
|
1786
|
+
} else {
|
|
1787
|
+
inDegree.set(pointer, 0);
|
|
1788
|
+
heap.push(pointer, declPriority);
|
|
1739
1789
|
}
|
|
1740
|
-
|
|
1741
|
-
});
|
|
1790
|
+
}
|
|
1742
1791
|
const emitted = /* @__PURE__ */ new Set();
|
|
1743
1792
|
const order = [];
|
|
1744
1793
|
while (!heap.isEmpty()) {
|
|
@@ -1751,14 +1800,20 @@ const walkTopological = (graph, callback, options) => {
|
|
|
1751
1800
|
for (const dep of deps) {
|
|
1752
1801
|
const v = (inDegree.get(dep) ?? 0) - 1;
|
|
1753
1802
|
inDegree.set(dep, v);
|
|
1754
|
-
if (v === 0) heap.push(dep);
|
|
1803
|
+
if (v === 0) heap.push(dep, declIndex.get(dep));
|
|
1755
1804
|
}
|
|
1756
1805
|
}
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1806
|
+
if (emitted.size < pointers.length) {
|
|
1807
|
+
const remaining = [];
|
|
1808
|
+
for (let i = 0, len = pointers.length; i < len; i++) {
|
|
1809
|
+
const pointer = pointers[i];
|
|
1810
|
+
if (!emitted.has(pointer)) remaining.push(pointer);
|
|
1811
|
+
}
|
|
1812
|
+
remaining.sort((a, b) => declIndex.get(a) - declIndex.get(b));
|
|
1813
|
+
for (const pointer of remaining) {
|
|
1814
|
+
emitted.add(pointer);
|
|
1815
|
+
order.push(pointer);
|
|
1816
|
+
}
|
|
1762
1817
|
}
|
|
1763
1818
|
let finalOrder = order;
|
|
1764
1819
|
if (options?.preferGroups && options.preferGroups.length) {
|
|
@@ -1774,8 +1829,6 @@ const walkTopological = (graph, callback, options) => {
|
|
|
1774
1829
|
}
|
|
1775
1830
|
return options.preferGroups.length;
|
|
1776
1831
|
};
|
|
1777
|
-
const orderIndex = /* @__PURE__ */ new Map();
|
|
1778
|
-
for (let i = 0; i < order.length; i++) orderIndex.set(order[i], i);
|
|
1779
1832
|
const groupCache = /* @__PURE__ */ new Map();
|
|
1780
1833
|
const getCachedGroup = (pointer) => {
|
|
1781
1834
|
let g = groupCache.get(pointer);
|
|
@@ -1785,11 +1838,7 @@ const walkTopological = (graph, callback, options) => {
|
|
|
1785
1838
|
}
|
|
1786
1839
|
return g;
|
|
1787
1840
|
};
|
|
1788
|
-
const proposed = [...order].sort((a, b) =>
|
|
1789
|
-
const ga = getCachedGroup(a);
|
|
1790
|
-
const gb = getCachedGroup(b);
|
|
1791
|
-
return ga !== gb ? ga - gb : orderIndex.get(a) - orderIndex.get(b);
|
|
1792
|
-
});
|
|
1841
|
+
const proposed = [...order].sort((a, b) => getCachedGroup(a) - getCachedGroup(b));
|
|
1793
1842
|
const proposedIndex = /* @__PURE__ */ new Map();
|
|
1794
1843
|
for (let i = 0; i < proposed.length; i++) proposedIndex.set(proposed[i], i);
|
|
1795
1844
|
if (!(() => {
|
|
@@ -1800,6 +1849,18 @@ const walkTopological = (graph, callback, options) => {
|
|
|
1800
1849
|
return false;
|
|
1801
1850
|
})()) finalOrder = proposed;
|
|
1802
1851
|
}
|
|
1852
|
+
return finalOrder;
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* Walks the nodes of the graph in topological order (dependencies before dependents).
|
|
1856
|
+
* Calls the callback for each node pointer in order.
|
|
1857
|
+
* Nodes in cycles are grouped together and emitted in arbitrary order within the group.
|
|
1858
|
+
*
|
|
1859
|
+
* @param graph - The dependency graph
|
|
1860
|
+
* @param callback - Function to call for each node pointer
|
|
1861
|
+
*/
|
|
1862
|
+
const walkTopological = (graph, callback, options) => {
|
|
1863
|
+
const finalOrder = computeTopologicalOrder(graph, options);
|
|
1803
1864
|
for (const pointer of finalOrder) callback(pointer, graph.nodes.get(pointer));
|
|
1804
1865
|
};
|
|
1805
1866
|
const walk = (graph, callback, options) => {
|
|
@@ -1824,6 +1885,14 @@ const irPatterns = {
|
|
|
1824
1885
|
server: /^#\/servers\/(\d+|[^/]+)$/,
|
|
1825
1886
|
webhook: /^#\/webhooks\/[^/]+\/(get|put|post|delete|options|head|patch|trace)$/
|
|
1826
1887
|
};
|
|
1888
|
+
const irPrefixes = [
|
|
1889
|
+
["#/paths/", "operation"],
|
|
1890
|
+
["#/components/parameters/", "parameter"],
|
|
1891
|
+
["#/components/requestBodies/", "requestBody"],
|
|
1892
|
+
["#/components/schemas/", "schema"],
|
|
1893
|
+
["#/servers/", "server"],
|
|
1894
|
+
["#/webhooks/", "webhook"]
|
|
1895
|
+
];
|
|
1827
1896
|
/**
|
|
1828
1897
|
* Checks if a pointer matches a known top-level IR component (schema, parameter, etc) and returns match info.
|
|
1829
1898
|
*
|
|
@@ -1836,10 +1905,13 @@ const matchIrPointerToGroup = (pointer, kind) => {
|
|
|
1836
1905
|
kind,
|
|
1837
1906
|
matched: true
|
|
1838
1907
|
} : { matched: false };
|
|
1839
|
-
for (
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1908
|
+
for (let i = 0, len = irPrefixes.length; i < len; i++) {
|
|
1909
|
+
const [prefix, key] = irPrefixes[i];
|
|
1910
|
+
if (pointer.startsWith(prefix) && irPatterns[key].test(pointer)) return {
|
|
1911
|
+
kind: key,
|
|
1912
|
+
matched: true
|
|
1913
|
+
};
|
|
1914
|
+
}
|
|
1843
1915
|
return { matched: false };
|
|
1844
1916
|
};
|
|
1845
1917
|
const preferGroups = [
|
|
@@ -1874,6 +1946,7 @@ function refToName($ref) {
|
|
|
1874
1946
|
const path = jsonPointerToPath($ref);
|
|
1875
1947
|
return path[path.length - 1];
|
|
1876
1948
|
}
|
|
1949
|
+
const jsonPointerSegmentEscapeNeeded = /[~/]/;
|
|
1877
1950
|
/**
|
|
1878
1951
|
* Encodes a path segment for use in a JSON Pointer (RFC 6901).
|
|
1879
1952
|
*
|
|
@@ -1883,11 +1956,40 @@ function refToName($ref) {
|
|
|
1883
1956
|
* This ensures that path segments containing these characters are safely
|
|
1884
1957
|
* represented in JSON Pointer strings.
|
|
1885
1958
|
*
|
|
1959
|
+
* Core idea: rather than always running two full-string `.replaceAll`
|
|
1960
|
+
* passes, find the index of the first character that needs escaping. If
|
|
1961
|
+
* there is none, the input is returned as-is with zero allocation. If there
|
|
1962
|
+
* is one, only that point onward needs a char-by-char scan — the untouched
|
|
1963
|
+
* prefix is reused verbatim via `slice`, and the loop copies unescaped runs
|
|
1964
|
+
* in bulk (via a pending start index) instead of appending one character at
|
|
1965
|
+
* a time.
|
|
1966
|
+
*
|
|
1886
1967
|
* @param segment - The path segment (string or number) to encode.
|
|
1887
1968
|
* @returns The encoded segment as a string.
|
|
1888
1969
|
*/
|
|
1889
1970
|
function encodeJsonPointerSegment(segment) {
|
|
1890
|
-
|
|
1971
|
+
const str = typeof segment === "string" ? segment : String(segment);
|
|
1972
|
+
const match = jsonPointerSegmentEscapeNeeded.exec(str);
|
|
1973
|
+
if (match === null) return str;
|
|
1974
|
+
let result = str.slice(0, match.index);
|
|
1975
|
+
let runStart = match.index;
|
|
1976
|
+
for (let i = match.index, len = str.length; i < len; i++) {
|
|
1977
|
+
let escape;
|
|
1978
|
+
switch (str.charCodeAt(i)) {
|
|
1979
|
+
case 126:
|
|
1980
|
+
escape = "~0";
|
|
1981
|
+
break;
|
|
1982
|
+
case 47:
|
|
1983
|
+
escape = "~1";
|
|
1984
|
+
break;
|
|
1985
|
+
default: continue;
|
|
1986
|
+
}
|
|
1987
|
+
if (runStart !== i) result += str.slice(runStart, i);
|
|
1988
|
+
result += escape;
|
|
1989
|
+
runStart = i + 1;
|
|
1990
|
+
}
|
|
1991
|
+
if (runStart !== str.length) result += str.slice(runStart);
|
|
1992
|
+
return result;
|
|
1891
1993
|
}
|
|
1892
1994
|
/**
|
|
1893
1995
|
* Converts a JSON Pointer string (RFC 6901) to an array of path segments.
|
|
@@ -1933,8 +2035,14 @@ function normalizeJsonPointer(pointer) {
|
|
|
1933
2035
|
* @returns
|
|
1934
2036
|
*/
|
|
1935
2037
|
function pathToJsonPointer(path) {
|
|
1936
|
-
const
|
|
1937
|
-
|
|
2038
|
+
const len = path.length;
|
|
2039
|
+
if (len === 0) return "#";
|
|
2040
|
+
let segments = encodeJsonPointerSegment(path[0]);
|
|
2041
|
+
for (let i = 1; i < len; i++) {
|
|
2042
|
+
segments += "/";
|
|
2043
|
+
segments += encodeJsonPointerSegment(path[i]);
|
|
2044
|
+
}
|
|
2045
|
+
return `#/${segments}`;
|
|
1938
2046
|
}
|
|
1939
2047
|
/**
|
|
1940
2048
|
* Checks if a $ref or path points to a top-level component (not a deep path reference).
|
|
@@ -3524,7 +3632,7 @@ function annotateChildScopes(nodes) {
|
|
|
3524
3632
|
/**
|
|
3525
3633
|
* Recursively collects all $ref dependencies in the subtree rooted at `pointer`.
|
|
3526
3634
|
*/
|
|
3527
|
-
function collectPointerDependencies(
|
|
3635
|
+
function collectPointerDependencies(cache, graph, pointer, visited) {
|
|
3528
3636
|
if (cache.transitiveDependencies.has(pointer)) return {
|
|
3529
3637
|
subtreeDependencies: cache.subtreeDependencies.get(pointer) ?? null,
|
|
3530
3638
|
transitiveDependencies: cache.transitiveDependencies.get(pointer) ?? null
|
|
@@ -3544,23 +3652,13 @@ function collectPointerDependencies({ cache, graph, pointer, visited }) {
|
|
|
3544
3652
|
if (nodeDependencies) for (const depPointer of nodeDependencies) {
|
|
3545
3653
|
(transitiveDependencies ??= /* @__PURE__ */ new Set()).add(depPointer);
|
|
3546
3654
|
(subtreeDependencies ??= /* @__PURE__ */ new Set()).add(depPointer);
|
|
3547
|
-
const depResult = collectPointerDependencies(
|
|
3548
|
-
cache,
|
|
3549
|
-
graph,
|
|
3550
|
-
pointer: depPointer,
|
|
3551
|
-
visited
|
|
3552
|
-
});
|
|
3655
|
+
const depResult = collectPointerDependencies(cache, graph, depPointer, visited);
|
|
3553
3656
|
if (depResult.transitiveDependencies) for (const dependency of depResult.transitiveDependencies) transitiveDependencies.add(dependency);
|
|
3554
3657
|
}
|
|
3555
3658
|
const children = cache.parentToChildren.get(pointer) ?? [];
|
|
3556
3659
|
for (const childPointer of children) {
|
|
3557
3660
|
if (!cache.transitiveDependencies.has(childPointer)) {
|
|
3558
|
-
const childResult = collectPointerDependencies(
|
|
3559
|
-
cache,
|
|
3560
|
-
graph,
|
|
3561
|
-
pointer: childPointer,
|
|
3562
|
-
visited
|
|
3563
|
-
});
|
|
3661
|
+
const childResult = collectPointerDependencies(cache, graph, childPointer, visited);
|
|
3564
3662
|
cache.transitiveDependencies.set(childPointer, childResult.transitiveDependencies);
|
|
3565
3663
|
cache.subtreeDependencies.set(childPointer, childResult.subtreeDependencies);
|
|
3566
3664
|
}
|
|
@@ -3577,36 +3675,53 @@ function collectPointerDependencies({ cache, graph, pointer, visited }) {
|
|
|
3577
3675
|
};
|
|
3578
3676
|
}
|
|
3579
3677
|
/**
|
|
3580
|
-
* Propagates scopes through the graph using a
|
|
3678
|
+
* Propagates scopes through the graph using a worklist algorithm.
|
|
3581
3679
|
*
|
|
3582
|
-
*
|
|
3583
|
-
*
|
|
3584
|
-
*
|
|
3585
|
-
*
|
|
3586
|
-
*
|
|
3587
|
-
*
|
|
3588
|
-
*
|
|
3589
|
-
* it
|
|
3590
|
-
* can only grow
|
|
3591
|
-
*
|
|
3680
|
+
* A node's scopes only ever flow to two places: its parent (tree edge) and
|
|
3681
|
+
* any node that references it via `$ref` (dependency edge). So instead of
|
|
3682
|
+
* repeatedly re-scanning every node until a full pass makes no changes (which
|
|
3683
|
+
* on a large spec means re-visiting hundreds of thousands of already-settled
|
|
3684
|
+
* nodes on every one of several passes), we seed a queue with the nodes that
|
|
3685
|
+
* start out with scopes and only re-examine a node when one of its actual
|
|
3686
|
+
* scope sources has just changed. Each node is processed once per net scope
|
|
3687
|
+
* change it receives (at most 3 times, since scopes are one of 'normal' /
|
|
3688
|
+
* 'read' / 'write' and can only grow), giving work proportional to the number
|
|
3689
|
+
* of changes rather than (passes × total node count).
|
|
3592
3690
|
*
|
|
3593
3691
|
* @param graph - The Graph structure containing nodes and dependencies.
|
|
3594
3692
|
*/
|
|
3595
3693
|
function propagateScopes(graph) {
|
|
3596
|
-
const
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3694
|
+
const refDependents = /* @__PURE__ */ new Map();
|
|
3695
|
+
for (const [pointer, deps] of graph.nodeDependencies) for (const depPointer of deps) {
|
|
3696
|
+
let dependents = refDependents.get(depPointer);
|
|
3697
|
+
if (!dependents) {
|
|
3698
|
+
dependents = [];
|
|
3699
|
+
refDependents.set(depPointer, dependents);
|
|
3700
|
+
}
|
|
3701
|
+
dependents.push(pointer);
|
|
3702
|
+
}
|
|
3703
|
+
const queued = /* @__PURE__ */ new Set();
|
|
3704
|
+
const queue = [];
|
|
3705
|
+
const enqueue = (pointer) => {
|
|
3706
|
+
if (queued.has(pointer)) return;
|
|
3707
|
+
queued.add(pointer);
|
|
3708
|
+
queue.push(pointer);
|
|
3709
|
+
};
|
|
3710
|
+
for (const [pointer, nodeInfo] of graph.nodes) if (nodeInfo.scopes) enqueue(pointer);
|
|
3711
|
+
let head = 0;
|
|
3712
|
+
while (head < queue.length) {
|
|
3713
|
+
const pointer = queue[head++];
|
|
3714
|
+
queued.delete(pointer);
|
|
3715
|
+
const nodeInfo = graph.nodes.get(pointer);
|
|
3716
|
+
if (!nodeInfo?.scopes) continue;
|
|
3717
|
+
if (nodeInfo.parentPointer) {
|
|
3718
|
+
const parentInfo = graph.nodes.get(nodeInfo.parentPointer);
|
|
3719
|
+
if (parentInfo && propagateScopesToNode(nodeInfo, parentInfo)) enqueue(nodeInfo.parentPointer);
|
|
3720
|
+
}
|
|
3721
|
+
const dependents = refDependents.get(pointer);
|
|
3722
|
+
if (dependents) for (const dependentPointer of dependents) {
|
|
3723
|
+
const dependentInfo = graph.nodes.get(dependentPointer);
|
|
3724
|
+
if (dependentInfo && propagateScopesToNode(nodeInfo, dependentInfo)) enqueue(dependentPointer);
|
|
3610
3725
|
}
|
|
3611
3726
|
}
|
|
3612
3727
|
}
|
|
@@ -3651,45 +3766,36 @@ function buildGraph(root, logger) {
|
|
|
3651
3766
|
subtreeDependencies: /* @__PURE__ */ new Map(),
|
|
3652
3767
|
transitiveDependencies: /* @__PURE__ */ new Map()
|
|
3653
3768
|
};
|
|
3654
|
-
|
|
3769
|
+
function walk(key, node, parentPointer, pointer) {
|
|
3655
3770
|
if (typeof node !== "object" || node === null) return;
|
|
3656
3771
|
let deprecated;
|
|
3657
3772
|
let tags;
|
|
3658
|
-
if (typeof node === "
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3773
|
+
if ("deprecated" in node && typeof node.deprecated === "boolean") deprecated = Boolean(node.deprecated);
|
|
3774
|
+
if ("$ref" in node && typeof node.$ref === "string") {
|
|
3775
|
+
const refPointer = normalizeJsonPointer(node.$ref);
|
|
3776
|
+
let deps = graph.nodeDependencies.get(pointer);
|
|
3777
|
+
if (!deps) {
|
|
3778
|
+
deps = /* @__PURE__ */ new Set();
|
|
3779
|
+
graph.nodeDependencies.set(pointer, deps);
|
|
3664
3780
|
}
|
|
3665
|
-
|
|
3781
|
+
deps.add(refPointer);
|
|
3782
|
+
}
|
|
3783
|
+
if ("tags" in node && Array.isArray(node.tags)) for (let i = 0, len = node.tags.length; i < len; i++) {
|
|
3784
|
+
const tag = node.tags[i];
|
|
3785
|
+
if (typeof tag === "string") (tags ??= /* @__PURE__ */ new Set()).add(tag);
|
|
3666
3786
|
}
|
|
3667
3787
|
graph.nodes.set(pointer, {
|
|
3668
3788
|
deprecated,
|
|
3669
3789
|
key,
|
|
3670
3790
|
node,
|
|
3671
3791
|
parentPointer,
|
|
3792
|
+
scopes: void 0,
|
|
3672
3793
|
tags
|
|
3673
3794
|
});
|
|
3674
|
-
if (Array.isArray(node)) node.
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
pointer: pointer + "/" + encodeJsonPointerSegment(index)
|
|
3679
|
-
}));
|
|
3680
|
-
else for (const [childKey, value] of Object.entries(node)) walk({
|
|
3681
|
-
key: childKey,
|
|
3682
|
-
node: value,
|
|
3683
|
-
parentPointer: pointer,
|
|
3684
|
-
pointer: pointer + "/" + encodeJsonPointerSegment(childKey)
|
|
3685
|
-
});
|
|
3686
|
-
};
|
|
3687
|
-
walk({
|
|
3688
|
-
key: null,
|
|
3689
|
-
node: root,
|
|
3690
|
-
parentPointer: null,
|
|
3691
|
-
pointer: "#"
|
|
3692
|
-
});
|
|
3795
|
+
if (Array.isArray(node)) for (let index = 0, len = node.length; index < len; index++) walk(index, node[index], pointer, pointer + "/" + encodeJsonPointerSegment(index));
|
|
3796
|
+
else for (const childKey in node) walk(childKey, node[childKey], pointer, pointer + "/" + encodeJsonPointerSegment(childKey));
|
|
3797
|
+
}
|
|
3798
|
+
walk(null, root, null, "#");
|
|
3693
3799
|
const cache = {
|
|
3694
3800
|
parentToChildren: /* @__PURE__ */ new Map(),
|
|
3695
3801
|
subtreeDependencies: /* @__PURE__ */ new Map(),
|
|
@@ -3719,14 +3825,18 @@ function buildGraph(root, logger) {
|
|
|
3719
3825
|
propagateScopes(graph);
|
|
3720
3826
|
annotateChildScopes(graph.nodes);
|
|
3721
3827
|
for (const pointer of graph.nodes.keys()) {
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
pointer
|
|
3726
|
-
|
|
3727
|
-
}
|
|
3728
|
-
|
|
3729
|
-
|
|
3828
|
+
let transitiveDependencies;
|
|
3829
|
+
let subtreeDependencies;
|
|
3830
|
+
if (cache.transitiveDependencies.has(pointer)) {
|
|
3831
|
+
transitiveDependencies = cache.transitiveDependencies.get(pointer) ?? null;
|
|
3832
|
+
subtreeDependencies = cache.subtreeDependencies.get(pointer) ?? null;
|
|
3833
|
+
} else {
|
|
3834
|
+
const result = collectPointerDependencies(cache, graph, pointer, /* @__PURE__ */ new Set());
|
|
3835
|
+
transitiveDependencies = result.transitiveDependencies;
|
|
3836
|
+
subtreeDependencies = result.subtreeDependencies;
|
|
3837
|
+
}
|
|
3838
|
+
if (transitiveDependencies) graph.transitiveDependencies.set(pointer, transitiveDependencies);
|
|
3839
|
+
if (subtreeDependencies) graph.subtreeDependencies.set(pointer, subtreeDependencies);
|
|
3730
3840
|
}
|
|
3731
3841
|
eventBuildGraph.timeEnd();
|
|
3732
3842
|
return { graph };
|
|
@@ -4055,7 +4165,7 @@ function splitSchemas({ config, graph, logger, spec }) {
|
|
|
4055
4165
|
function updateRefsInSpec({ logger, spec, split }) {
|
|
4056
4166
|
const event = logger.timeEvent("update-refs-in-spec");
|
|
4057
4167
|
const schemasPointerNamespace = specToSchemasPointerNamespace(spec);
|
|
4058
|
-
|
|
4168
|
+
function walk({ context, currentPointer, inSchema, node, path, visited = /* @__PURE__ */ new Set() }) {
|
|
4059
4169
|
if (node instanceof Array) node.forEach((item, index) => walk({
|
|
4060
4170
|
context,
|
|
4061
4171
|
currentPointer,
|
|
@@ -4212,7 +4322,7 @@ function updateRefsInSpec({ logger, spec, split }) {
|
|
|
4212
4322
|
});
|
|
4213
4323
|
}
|
|
4214
4324
|
}
|
|
4215
|
-
}
|
|
4325
|
+
}
|
|
4216
4326
|
walk({
|
|
4217
4327
|
context: null,
|
|
4218
4328
|
currentPointer: null,
|
|
@@ -9047,8 +9157,51 @@ function resolveValidatorLayer(layers, key, defaultValues) {
|
|
|
9047
9157
|
}
|
|
9048
9158
|
//#endregion
|
|
9049
9159
|
//#region src/utils/escape.ts
|
|
9160
|
+
const commentEscapeNeeded = /\*\/|\/\*|\r?\n/;
|
|
9161
|
+
/**
|
|
9162
|
+
* Core idea: instead of three separate full-string `.replace` passes (one
|
|
9163
|
+
* per comment-terminator pair, plus one regex+callback pass for line
|
|
9164
|
+
* normalization/trimming), find the index of the first character that
|
|
9165
|
+
* starts any of those patterns. If none is found, the string is returned
|
|
9166
|
+
* untouched. Otherwise walk from that index once: unescaped runs are copied
|
|
9167
|
+
* in bulk via `slice` (tracked with `runStart`), each terminator pair
|
|
9168
|
+
* collapses to a single asterisk (both characters consumed together), and
|
|
9169
|
+
* each line break consumes the rest of that line in one step — normalizing
|
|
9170
|
+
* it to `EOL` and trimming the following line's content — so no line is
|
|
9171
|
+
* scanned twice.
|
|
9172
|
+
*/
|
|
9050
9173
|
function escapeComment(value) {
|
|
9051
|
-
|
|
9174
|
+
const match = commentEscapeNeeded.exec(value);
|
|
9175
|
+
if (match === null) return value;
|
|
9176
|
+
let result = value.slice(0, match.index);
|
|
9177
|
+
let runStart = match.index;
|
|
9178
|
+
const len = value.length;
|
|
9179
|
+
for (let i = match.index; i < len; i++) {
|
|
9180
|
+
const code = value.charCodeAt(i);
|
|
9181
|
+
let replacement;
|
|
9182
|
+
let consumed;
|
|
9183
|
+
if (code === 42 && value.charCodeAt(i + 1) === 47) {
|
|
9184
|
+
replacement = "*";
|
|
9185
|
+
consumed = 2;
|
|
9186
|
+
} else if (code === 47 && value.charCodeAt(i + 1) === 42) {
|
|
9187
|
+
replacement = "*";
|
|
9188
|
+
consumed = 2;
|
|
9189
|
+
} else if (code === 13 && value.charCodeAt(i + 1) === 10) {
|
|
9190
|
+
const lineEnd = value.indexOf("\n", i + 2);
|
|
9191
|
+
replacement = EOL + (lineEnd === -1 ? value.slice(i + 2) : value.slice(i + 2, lineEnd)).trim();
|
|
9192
|
+
consumed = (lineEnd === -1 ? len : lineEnd) - i;
|
|
9193
|
+
} else if (code === 10) {
|
|
9194
|
+
const lineEnd = value.indexOf("\n", i + 1);
|
|
9195
|
+
replacement = EOL + (lineEnd === -1 ? value.slice(i + 1) : value.slice(i + 1, lineEnd)).trim();
|
|
9196
|
+
consumed = (lineEnd === -1 ? len : lineEnd) - i;
|
|
9197
|
+
} else continue;
|
|
9198
|
+
if (runStart !== i) result += value.slice(runStart, i);
|
|
9199
|
+
result += replacement;
|
|
9200
|
+
i += consumed - 1;
|
|
9201
|
+
runStart = i + 1;
|
|
9202
|
+
}
|
|
9203
|
+
if (runStart !== len) result += value.slice(runStart);
|
|
9204
|
+
return result;
|
|
9052
9205
|
}
|
|
9053
9206
|
//#endregion
|
|
9054
9207
|
//#region src/utils/exports.ts
|