@stacksjs/ts-cloud 0.1.14 → 0.2.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/bin/cli.js +229 -228
- package/dist/index.d.ts +3 -7
- package/dist/index.js +615 -164
- package/package.json +4 -5
package/dist/index.js
CHANGED
|
@@ -1057,6 +1057,14 @@ function normalizeProcessEntities(value) {
|
|
|
1057
1057
|
var defaultOptions2, buildOptions = function(options) {
|
|
1058
1058
|
const built = Object.assign({}, defaultOptions2, options);
|
|
1059
1059
|
built.processEntities = normalizeProcessEntities(built.processEntities);
|
|
1060
|
+
if (built.stopNodes && Array.isArray(built.stopNodes)) {
|
|
1061
|
+
built.stopNodes = built.stopNodes.map((node) => {
|
|
1062
|
+
if (typeof node === "string" && node.startsWith("*.")) {
|
|
1063
|
+
return ".." + node.substring(2);
|
|
1064
|
+
}
|
|
1065
|
+
return node;
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1060
1068
|
return built;
|
|
1061
1069
|
};
|
|
1062
1070
|
var init_OptionsBuilder = __esm(() => {
|
|
@@ -1099,7 +1107,8 @@ var init_OptionsBuilder = __esm(() => {
|
|
|
1099
1107
|
},
|
|
1100
1108
|
captureMetaData: false,
|
|
1101
1109
|
maxNestedTags: 100,
|
|
1102
|
-
strictReservedNames: true
|
|
1110
|
+
strictReservedNames: true,
|
|
1111
|
+
jPath: true
|
|
1103
1112
|
};
|
|
1104
1113
|
});
|
|
1105
1114
|
|
|
@@ -1571,7 +1580,382 @@ function getIgnoreAttributesFn(ignoreAttributes) {
|
|
|
1571
1580
|
return () => false;
|
|
1572
1581
|
}
|
|
1573
1582
|
|
|
1583
|
+
// ../../node_modules/path-expression-matcher/src/Expression.js
|
|
1584
|
+
class Expression {
|
|
1585
|
+
constructor(pattern, options = {}) {
|
|
1586
|
+
this.pattern = pattern;
|
|
1587
|
+
this.separator = options.separator || ".";
|
|
1588
|
+
this.segments = this._parse(pattern);
|
|
1589
|
+
this._hasDeepWildcard = this.segments.some((seg) => seg.type === "deep-wildcard");
|
|
1590
|
+
this._hasAttributeCondition = this.segments.some((seg) => seg.attrName !== undefined);
|
|
1591
|
+
this._hasPositionSelector = this.segments.some((seg) => seg.position !== undefined);
|
|
1592
|
+
}
|
|
1593
|
+
_parse(pattern) {
|
|
1594
|
+
const segments = [];
|
|
1595
|
+
let i = 0;
|
|
1596
|
+
let currentPart = "";
|
|
1597
|
+
while (i < pattern.length) {
|
|
1598
|
+
if (pattern[i] === this.separator) {
|
|
1599
|
+
if (i + 1 < pattern.length && pattern[i + 1] === this.separator) {
|
|
1600
|
+
if (currentPart.trim()) {
|
|
1601
|
+
segments.push(this._parseSegment(currentPart.trim()));
|
|
1602
|
+
currentPart = "";
|
|
1603
|
+
}
|
|
1604
|
+
segments.push({ type: "deep-wildcard" });
|
|
1605
|
+
i += 2;
|
|
1606
|
+
} else {
|
|
1607
|
+
if (currentPart.trim()) {
|
|
1608
|
+
segments.push(this._parseSegment(currentPart.trim()));
|
|
1609
|
+
}
|
|
1610
|
+
currentPart = "";
|
|
1611
|
+
i++;
|
|
1612
|
+
}
|
|
1613
|
+
} else {
|
|
1614
|
+
currentPart += pattern[i];
|
|
1615
|
+
i++;
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
if (currentPart.trim()) {
|
|
1619
|
+
segments.push(this._parseSegment(currentPart.trim()));
|
|
1620
|
+
}
|
|
1621
|
+
return segments;
|
|
1622
|
+
}
|
|
1623
|
+
_parseSegment(part) {
|
|
1624
|
+
const segment = { type: "tag" };
|
|
1625
|
+
let bracketContent = null;
|
|
1626
|
+
let withoutBrackets = part;
|
|
1627
|
+
const bracketMatch = part.match(/^([^\[]+)(\[[^\]]*\])(.*)$/);
|
|
1628
|
+
if (bracketMatch) {
|
|
1629
|
+
withoutBrackets = bracketMatch[1] + bracketMatch[3];
|
|
1630
|
+
if (bracketMatch[2]) {
|
|
1631
|
+
const content = bracketMatch[2].slice(1, -1);
|
|
1632
|
+
if (content) {
|
|
1633
|
+
bracketContent = content;
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
let namespace = undefined;
|
|
1638
|
+
let tagAndPosition = withoutBrackets;
|
|
1639
|
+
if (withoutBrackets.includes("::")) {
|
|
1640
|
+
const nsIndex = withoutBrackets.indexOf("::");
|
|
1641
|
+
namespace = withoutBrackets.substring(0, nsIndex).trim();
|
|
1642
|
+
tagAndPosition = withoutBrackets.substring(nsIndex + 2).trim();
|
|
1643
|
+
if (!namespace) {
|
|
1644
|
+
throw new Error(`Invalid namespace in pattern: ${part}`);
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
let tag = undefined;
|
|
1648
|
+
let positionMatch = null;
|
|
1649
|
+
if (tagAndPosition.includes(":")) {
|
|
1650
|
+
const colonIndex = tagAndPosition.lastIndexOf(":");
|
|
1651
|
+
const tagPart = tagAndPosition.substring(0, colonIndex).trim();
|
|
1652
|
+
const posPart = tagAndPosition.substring(colonIndex + 1).trim();
|
|
1653
|
+
const isPositionKeyword = ["first", "last", "odd", "even"].includes(posPart) || /^nth\(\d+\)$/.test(posPart);
|
|
1654
|
+
if (isPositionKeyword) {
|
|
1655
|
+
tag = tagPart;
|
|
1656
|
+
positionMatch = posPart;
|
|
1657
|
+
} else {
|
|
1658
|
+
tag = tagAndPosition;
|
|
1659
|
+
}
|
|
1660
|
+
} else {
|
|
1661
|
+
tag = tagAndPosition;
|
|
1662
|
+
}
|
|
1663
|
+
if (!tag) {
|
|
1664
|
+
throw new Error(`Invalid segment pattern: ${part}`);
|
|
1665
|
+
}
|
|
1666
|
+
segment.tag = tag;
|
|
1667
|
+
if (namespace) {
|
|
1668
|
+
segment.namespace = namespace;
|
|
1669
|
+
}
|
|
1670
|
+
if (bracketContent) {
|
|
1671
|
+
if (bracketContent.includes("=")) {
|
|
1672
|
+
const eqIndex = bracketContent.indexOf("=");
|
|
1673
|
+
segment.attrName = bracketContent.substring(0, eqIndex).trim();
|
|
1674
|
+
segment.attrValue = bracketContent.substring(eqIndex + 1).trim();
|
|
1675
|
+
} else {
|
|
1676
|
+
segment.attrName = bracketContent.trim();
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
if (positionMatch) {
|
|
1680
|
+
const nthMatch = positionMatch.match(/^nth\((\d+)\)$/);
|
|
1681
|
+
if (nthMatch) {
|
|
1682
|
+
segment.position = "nth";
|
|
1683
|
+
segment.positionValue = parseInt(nthMatch[1], 10);
|
|
1684
|
+
} else {
|
|
1685
|
+
segment.position = positionMatch;
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
return segment;
|
|
1689
|
+
}
|
|
1690
|
+
get length() {
|
|
1691
|
+
return this.segments.length;
|
|
1692
|
+
}
|
|
1693
|
+
hasDeepWildcard() {
|
|
1694
|
+
return this._hasDeepWildcard;
|
|
1695
|
+
}
|
|
1696
|
+
hasAttributeCondition() {
|
|
1697
|
+
return this._hasAttributeCondition;
|
|
1698
|
+
}
|
|
1699
|
+
hasPositionSelector() {
|
|
1700
|
+
return this._hasPositionSelector;
|
|
1701
|
+
}
|
|
1702
|
+
toString() {
|
|
1703
|
+
return this.pattern;
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
// ../../node_modules/path-expression-matcher/src/Matcher.js
|
|
1708
|
+
class Matcher {
|
|
1709
|
+
constructor(options = {}) {
|
|
1710
|
+
this.separator = options.separator || ".";
|
|
1711
|
+
this.path = [];
|
|
1712
|
+
this.siblingStacks = [];
|
|
1713
|
+
}
|
|
1714
|
+
push(tagName, attrValues = null, namespace = null) {
|
|
1715
|
+
if (this.path.length > 0) {
|
|
1716
|
+
const prev = this.path[this.path.length - 1];
|
|
1717
|
+
prev.values = undefined;
|
|
1718
|
+
}
|
|
1719
|
+
const currentLevel = this.path.length;
|
|
1720
|
+
if (!this.siblingStacks[currentLevel]) {
|
|
1721
|
+
this.siblingStacks[currentLevel] = new Map;
|
|
1722
|
+
}
|
|
1723
|
+
const siblings = this.siblingStacks[currentLevel];
|
|
1724
|
+
const siblingKey = namespace ? `${namespace}:${tagName}` : tagName;
|
|
1725
|
+
const counter = siblings.get(siblingKey) || 0;
|
|
1726
|
+
let position = 0;
|
|
1727
|
+
for (const count of siblings.values()) {
|
|
1728
|
+
position += count;
|
|
1729
|
+
}
|
|
1730
|
+
siblings.set(siblingKey, counter + 1);
|
|
1731
|
+
const node = {
|
|
1732
|
+
tag: tagName,
|
|
1733
|
+
position,
|
|
1734
|
+
counter
|
|
1735
|
+
};
|
|
1736
|
+
if (namespace !== null && namespace !== undefined) {
|
|
1737
|
+
node.namespace = namespace;
|
|
1738
|
+
}
|
|
1739
|
+
if (attrValues !== null && attrValues !== undefined) {
|
|
1740
|
+
node.values = attrValues;
|
|
1741
|
+
}
|
|
1742
|
+
this.path.push(node);
|
|
1743
|
+
}
|
|
1744
|
+
pop() {
|
|
1745
|
+
if (this.path.length === 0) {
|
|
1746
|
+
return;
|
|
1747
|
+
}
|
|
1748
|
+
const node = this.path.pop();
|
|
1749
|
+
if (this.siblingStacks.length > this.path.length + 1) {
|
|
1750
|
+
this.siblingStacks.length = this.path.length + 1;
|
|
1751
|
+
}
|
|
1752
|
+
return node;
|
|
1753
|
+
}
|
|
1754
|
+
updateCurrent(attrValues) {
|
|
1755
|
+
if (this.path.length > 0) {
|
|
1756
|
+
const current = this.path[this.path.length - 1];
|
|
1757
|
+
if (attrValues !== null && attrValues !== undefined) {
|
|
1758
|
+
current.values = attrValues;
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
getCurrentTag() {
|
|
1763
|
+
return this.path.length > 0 ? this.path[this.path.length - 1].tag : undefined;
|
|
1764
|
+
}
|
|
1765
|
+
getCurrentNamespace() {
|
|
1766
|
+
return this.path.length > 0 ? this.path[this.path.length - 1].namespace : undefined;
|
|
1767
|
+
}
|
|
1768
|
+
getAttrValue(attrName) {
|
|
1769
|
+
if (this.path.length === 0)
|
|
1770
|
+
return;
|
|
1771
|
+
const current = this.path[this.path.length - 1];
|
|
1772
|
+
return current.values?.[attrName];
|
|
1773
|
+
}
|
|
1774
|
+
hasAttr(attrName) {
|
|
1775
|
+
if (this.path.length === 0)
|
|
1776
|
+
return false;
|
|
1777
|
+
const current = this.path[this.path.length - 1];
|
|
1778
|
+
return current.values !== undefined && attrName in current.values;
|
|
1779
|
+
}
|
|
1780
|
+
getPosition() {
|
|
1781
|
+
if (this.path.length === 0)
|
|
1782
|
+
return -1;
|
|
1783
|
+
return this.path[this.path.length - 1].position ?? 0;
|
|
1784
|
+
}
|
|
1785
|
+
getCounter() {
|
|
1786
|
+
if (this.path.length === 0)
|
|
1787
|
+
return -1;
|
|
1788
|
+
return this.path[this.path.length - 1].counter ?? 0;
|
|
1789
|
+
}
|
|
1790
|
+
getIndex() {
|
|
1791
|
+
return this.getPosition();
|
|
1792
|
+
}
|
|
1793
|
+
getDepth() {
|
|
1794
|
+
return this.path.length;
|
|
1795
|
+
}
|
|
1796
|
+
toString(separator, includeNamespace = true) {
|
|
1797
|
+
const sep = separator || this.separator;
|
|
1798
|
+
return this.path.map((n) => {
|
|
1799
|
+
if (includeNamespace && n.namespace) {
|
|
1800
|
+
return `${n.namespace}:${n.tag}`;
|
|
1801
|
+
}
|
|
1802
|
+
return n.tag;
|
|
1803
|
+
}).join(sep);
|
|
1804
|
+
}
|
|
1805
|
+
toArray() {
|
|
1806
|
+
return this.path.map((n) => n.tag);
|
|
1807
|
+
}
|
|
1808
|
+
reset() {
|
|
1809
|
+
this.path = [];
|
|
1810
|
+
this.siblingStacks = [];
|
|
1811
|
+
}
|
|
1812
|
+
matches(expression) {
|
|
1813
|
+
const segments = expression.segments;
|
|
1814
|
+
if (segments.length === 0) {
|
|
1815
|
+
return false;
|
|
1816
|
+
}
|
|
1817
|
+
if (expression.hasDeepWildcard()) {
|
|
1818
|
+
return this._matchWithDeepWildcard(segments);
|
|
1819
|
+
}
|
|
1820
|
+
return this._matchSimple(segments);
|
|
1821
|
+
}
|
|
1822
|
+
_matchSimple(segments) {
|
|
1823
|
+
if (this.path.length !== segments.length) {
|
|
1824
|
+
return false;
|
|
1825
|
+
}
|
|
1826
|
+
for (let i = 0;i < segments.length; i++) {
|
|
1827
|
+
const segment = segments[i];
|
|
1828
|
+
const node = this.path[i];
|
|
1829
|
+
const isCurrentNode = i === this.path.length - 1;
|
|
1830
|
+
if (!this._matchSegment(segment, node, isCurrentNode)) {
|
|
1831
|
+
return false;
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
return true;
|
|
1835
|
+
}
|
|
1836
|
+
_matchWithDeepWildcard(segments) {
|
|
1837
|
+
let pathIdx = this.path.length - 1;
|
|
1838
|
+
let segIdx = segments.length - 1;
|
|
1839
|
+
while (segIdx >= 0 && pathIdx >= 0) {
|
|
1840
|
+
const segment = segments[segIdx];
|
|
1841
|
+
if (segment.type === "deep-wildcard") {
|
|
1842
|
+
segIdx--;
|
|
1843
|
+
if (segIdx < 0) {
|
|
1844
|
+
return true;
|
|
1845
|
+
}
|
|
1846
|
+
const nextSeg = segments[segIdx];
|
|
1847
|
+
let found = false;
|
|
1848
|
+
for (let i = pathIdx;i >= 0; i--) {
|
|
1849
|
+
const isCurrentNode = i === this.path.length - 1;
|
|
1850
|
+
if (this._matchSegment(nextSeg, this.path[i], isCurrentNode)) {
|
|
1851
|
+
pathIdx = i - 1;
|
|
1852
|
+
segIdx--;
|
|
1853
|
+
found = true;
|
|
1854
|
+
break;
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
if (!found) {
|
|
1858
|
+
return false;
|
|
1859
|
+
}
|
|
1860
|
+
} else {
|
|
1861
|
+
const isCurrentNode = pathIdx === this.path.length - 1;
|
|
1862
|
+
if (!this._matchSegment(segment, this.path[pathIdx], isCurrentNode)) {
|
|
1863
|
+
return false;
|
|
1864
|
+
}
|
|
1865
|
+
pathIdx--;
|
|
1866
|
+
segIdx--;
|
|
1867
|
+
}
|
|
1868
|
+
}
|
|
1869
|
+
return segIdx < 0;
|
|
1870
|
+
}
|
|
1871
|
+
_matchSegment(segment, node, isCurrentNode) {
|
|
1872
|
+
if (segment.tag !== "*" && segment.tag !== node.tag) {
|
|
1873
|
+
return false;
|
|
1874
|
+
}
|
|
1875
|
+
if (segment.namespace !== undefined) {
|
|
1876
|
+
if (segment.namespace !== "*" && segment.namespace !== node.namespace) {
|
|
1877
|
+
return false;
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
if (segment.attrName !== undefined) {
|
|
1881
|
+
if (!isCurrentNode) {
|
|
1882
|
+
return false;
|
|
1883
|
+
}
|
|
1884
|
+
if (!node.values || !(segment.attrName in node.values)) {
|
|
1885
|
+
return false;
|
|
1886
|
+
}
|
|
1887
|
+
if (segment.attrValue !== undefined) {
|
|
1888
|
+
const actualValue = node.values[segment.attrName];
|
|
1889
|
+
if (String(actualValue) !== String(segment.attrValue)) {
|
|
1890
|
+
return false;
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
if (segment.position !== undefined) {
|
|
1895
|
+
if (!isCurrentNode) {
|
|
1896
|
+
return false;
|
|
1897
|
+
}
|
|
1898
|
+
const counter = node.counter ?? 0;
|
|
1899
|
+
if (segment.position === "first" && counter !== 0) {
|
|
1900
|
+
return false;
|
|
1901
|
+
} else if (segment.position === "odd" && counter % 2 !== 1) {
|
|
1902
|
+
return false;
|
|
1903
|
+
} else if (segment.position === "even" && counter % 2 !== 0) {
|
|
1904
|
+
return false;
|
|
1905
|
+
} else if (segment.position === "nth") {
|
|
1906
|
+
if (counter !== segment.positionValue) {
|
|
1907
|
+
return false;
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
return true;
|
|
1912
|
+
}
|
|
1913
|
+
snapshot() {
|
|
1914
|
+
return {
|
|
1915
|
+
path: this.path.map((node) => ({ ...node })),
|
|
1916
|
+
siblingStacks: this.siblingStacks.map((map) => new Map(map))
|
|
1917
|
+
};
|
|
1918
|
+
}
|
|
1919
|
+
restore(snapshot) {
|
|
1920
|
+
this.path = snapshot.path.map((node) => ({ ...node }));
|
|
1921
|
+
this.siblingStacks = snapshot.siblingStacks.map((map) => new Map(map));
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
// ../../node_modules/path-expression-matcher/src/index.js
|
|
1926
|
+
var init_src = () => {};
|
|
1927
|
+
|
|
1574
1928
|
// ../../node_modules/fast-xml-parser/src/xmlparser/OrderedObjParser.js
|
|
1929
|
+
function extractRawAttributes(prefixedAttrs, options) {
|
|
1930
|
+
if (!prefixedAttrs)
|
|
1931
|
+
return {};
|
|
1932
|
+
const attrs = options.attributesGroupName ? prefixedAttrs[options.attributesGroupName] : prefixedAttrs;
|
|
1933
|
+
if (!attrs)
|
|
1934
|
+
return {};
|
|
1935
|
+
const rawAttrs = {};
|
|
1936
|
+
for (const key in attrs) {
|
|
1937
|
+
if (key.startsWith(options.attributeNamePrefix)) {
|
|
1938
|
+
const rawName = key.substring(options.attributeNamePrefix.length);
|
|
1939
|
+
rawAttrs[rawName] = attrs[key];
|
|
1940
|
+
} else {
|
|
1941
|
+
rawAttrs[key] = attrs[key];
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
return rawAttrs;
|
|
1945
|
+
}
|
|
1946
|
+
function extractNamespace(rawTagName) {
|
|
1947
|
+
if (!rawTagName || typeof rawTagName !== "string")
|
|
1948
|
+
return;
|
|
1949
|
+
const colonIndex = rawTagName.indexOf(":");
|
|
1950
|
+
if (colonIndex !== -1 && colonIndex > 0) {
|
|
1951
|
+
const ns = rawTagName.substring(0, colonIndex);
|
|
1952
|
+
if (ns !== "xmlns") {
|
|
1953
|
+
return ns;
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
return;
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1575
1959
|
class OrderedObjParser {
|
|
1576
1960
|
constructor(options) {
|
|
1577
1961
|
this.options = options;
|
|
@@ -1610,17 +1994,16 @@ class OrderedObjParser {
|
|
|
1610
1994
|
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes);
|
|
1611
1995
|
this.entityExpansionCount = 0;
|
|
1612
1996
|
this.currentExpandedLength = 0;
|
|
1997
|
+
this.matcher = new Matcher;
|
|
1998
|
+
this.isCurrentNodeStopNode = false;
|
|
1613
1999
|
if (this.options.stopNodes && this.options.stopNodes.length > 0) {
|
|
1614
|
-
this.
|
|
1615
|
-
this.stopNodesWildcard = new Set;
|
|
2000
|
+
this.stopNodeExpressions = [];
|
|
1616
2001
|
for (let i = 0;i < this.options.stopNodes.length; i++) {
|
|
1617
2002
|
const stopNodeExp = this.options.stopNodes[i];
|
|
1618
|
-
if (typeof stopNodeExp
|
|
1619
|
-
|
|
1620
|
-
if (stopNodeExp
|
|
1621
|
-
this.
|
|
1622
|
-
} else {
|
|
1623
|
-
this.stopNodesExact.add(stopNodeExp);
|
|
2003
|
+
if (typeof stopNodeExp === "string") {
|
|
2004
|
+
this.stopNodeExpressions.push(new Expression(stopNodeExp));
|
|
2005
|
+
} else if (stopNodeExp instanceof Expression) {
|
|
2006
|
+
this.stopNodeExpressions.push(stopNodeExp);
|
|
1624
2007
|
}
|
|
1625
2008
|
}
|
|
1626
2009
|
}
|
|
@@ -1645,7 +2028,8 @@ function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode,
|
|
|
1645
2028
|
if (val.length > 0) {
|
|
1646
2029
|
if (!escapeEntities)
|
|
1647
2030
|
val = this.replaceEntitiesValue(val, tagName, jPath);
|
|
1648
|
-
const
|
|
2031
|
+
const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath;
|
|
2032
|
+
const newval = this.options.tagValueProcessor(tagName, val, jPathOrMatcher, hasAttributes, isLeafNode);
|
|
1649
2033
|
if (newval === null || newval === undefined) {
|
|
1650
2034
|
return val;
|
|
1651
2035
|
} else if (typeof newval !== typeof val || newval !== val) {
|
|
@@ -1681,9 +2065,26 @@ function buildAttributesMap(attrStr, jPath, tagName) {
|
|
|
1681
2065
|
const matches = getAllMatches(attrStr, attrsRegx);
|
|
1682
2066
|
const len = matches.length;
|
|
1683
2067
|
const attrs = {};
|
|
2068
|
+
const rawAttrsForMatcher = {};
|
|
1684
2069
|
for (let i = 0;i < len; i++) {
|
|
1685
2070
|
const attrName = this.resolveNameSpace(matches[i][1]);
|
|
1686
|
-
|
|
2071
|
+
const oldVal = matches[i][4];
|
|
2072
|
+
if (attrName.length && oldVal !== undefined) {
|
|
2073
|
+
let parsedVal = oldVal;
|
|
2074
|
+
if (this.options.trimValues) {
|
|
2075
|
+
parsedVal = parsedVal.trim();
|
|
2076
|
+
}
|
|
2077
|
+
parsedVal = this.replaceEntitiesValue(parsedVal, tagName, jPath);
|
|
2078
|
+
rawAttrsForMatcher[attrName] = parsedVal;
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
if (Object.keys(rawAttrsForMatcher).length > 0 && typeof jPath === "object" && jPath.updateCurrent) {
|
|
2082
|
+
jPath.updateCurrent(rawAttrsForMatcher);
|
|
2083
|
+
}
|
|
2084
|
+
for (let i = 0;i < len; i++) {
|
|
2085
|
+
const attrName = this.resolveNameSpace(matches[i][1]);
|
|
2086
|
+
const jPathStr = this.options.jPath ? jPath.toString() : jPath;
|
|
2087
|
+
if (this.ignoreAttributesFn(attrName, jPathStr)) {
|
|
1687
2088
|
continue;
|
|
1688
2089
|
}
|
|
1689
2090
|
let oldVal = matches[i][4];
|
|
@@ -1699,7 +2100,8 @@ function buildAttributesMap(attrStr, jPath, tagName) {
|
|
|
1699
2100
|
oldVal = oldVal.trim();
|
|
1700
2101
|
}
|
|
1701
2102
|
oldVal = this.replaceEntitiesValue(oldVal, tagName, jPath);
|
|
1702
|
-
const
|
|
2103
|
+
const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath;
|
|
2104
|
+
const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPathOrMatcher);
|
|
1703
2105
|
if (newVal === null || newVal === undefined) {
|
|
1704
2106
|
attrs[aName] = oldVal;
|
|
1705
2107
|
} else if (typeof newVal !== typeof oldVal || newVal !== oldVal) {
|
|
@@ -1723,10 +2125,11 @@ function buildAttributesMap(attrStr, jPath, tagName) {
|
|
|
1723
2125
|
return attrs;
|
|
1724
2126
|
}
|
|
1725
2127
|
}
|
|
1726
|
-
function addChild(currentNode, childNode,
|
|
2128
|
+
function addChild(currentNode, childNode, matcher, startIndex) {
|
|
1727
2129
|
if (!this.options.captureMetaData)
|
|
1728
2130
|
startIndex = undefined;
|
|
1729
|
-
const
|
|
2131
|
+
const jPathOrMatcher = this.options.jPath ? matcher.toString() : matcher;
|
|
2132
|
+
const result = this.options.updateTag(childNode.tagname, jPathOrMatcher, childNode[":@"]);
|
|
1730
2133
|
if (result === false) {} else if (typeof result === "string") {
|
|
1731
2134
|
childNode.tagname = result;
|
|
1732
2135
|
currentNode.addChild(childNode, startIndex);
|
|
@@ -1734,22 +2137,78 @@ function addChild(currentNode, childNode, jPath, startIndex) {
|
|
|
1734
2137
|
currentNode.addChild(childNode, startIndex);
|
|
1735
2138
|
}
|
|
1736
2139
|
}
|
|
1737
|
-
function
|
|
2140
|
+
function replaceEntitiesValue(val, tagName, jPath) {
|
|
2141
|
+
const entityConfig = this.options.processEntities;
|
|
2142
|
+
if (!entityConfig || !entityConfig.enabled) {
|
|
2143
|
+
return val;
|
|
2144
|
+
}
|
|
2145
|
+
if (entityConfig.allowedTags) {
|
|
2146
|
+
const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath;
|
|
2147
|
+
const allowed = Array.isArray(entityConfig.allowedTags) ? entityConfig.allowedTags.includes(tagName) : entityConfig.allowedTags(tagName, jPathOrMatcher);
|
|
2148
|
+
if (!allowed) {
|
|
2149
|
+
return val;
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
if (entityConfig.tagFilter) {
|
|
2153
|
+
const jPathOrMatcher = this.options.jPath ? jPath.toString() : jPath;
|
|
2154
|
+
if (!entityConfig.tagFilter(tagName, jPathOrMatcher)) {
|
|
2155
|
+
return val;
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
for (let entityName in this.docTypeEntities) {
|
|
2159
|
+
const entity = this.docTypeEntities[entityName];
|
|
2160
|
+
const matches = val.match(entity.regx);
|
|
2161
|
+
if (matches) {
|
|
2162
|
+
this.entityExpansionCount += matches.length;
|
|
2163
|
+
if (entityConfig.maxTotalExpansions && this.entityExpansionCount > entityConfig.maxTotalExpansions) {
|
|
2164
|
+
throw new Error(`Entity expansion limit exceeded: ${this.entityExpansionCount} > ${entityConfig.maxTotalExpansions}`);
|
|
2165
|
+
}
|
|
2166
|
+
const lengthBefore = val.length;
|
|
2167
|
+
val = val.replace(entity.regx, entity.val);
|
|
2168
|
+
if (entityConfig.maxExpandedLength) {
|
|
2169
|
+
this.currentExpandedLength += val.length - lengthBefore;
|
|
2170
|
+
if (this.currentExpandedLength > entityConfig.maxExpandedLength) {
|
|
2171
|
+
throw new Error(`Total expanded content size exceeded: ${this.currentExpandedLength} > ${entityConfig.maxExpandedLength}`);
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
if (val.indexOf("&") === -1)
|
|
2177
|
+
return val;
|
|
2178
|
+
for (let entityName in this.lastEntities) {
|
|
2179
|
+
const entity = this.lastEntities[entityName];
|
|
2180
|
+
val = val.replace(entity.regex, entity.val);
|
|
2181
|
+
}
|
|
2182
|
+
if (val.indexOf("&") === -1)
|
|
2183
|
+
return val;
|
|
2184
|
+
if (this.options.htmlEntities) {
|
|
2185
|
+
for (let entityName in this.htmlEntities) {
|
|
2186
|
+
const entity = this.htmlEntities[entityName];
|
|
2187
|
+
val = val.replace(entity.regex, entity.val);
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2190
|
+
val = val.replace(this.ampEntity.regex, this.ampEntity.val);
|
|
2191
|
+
return val;
|
|
2192
|
+
}
|
|
2193
|
+
function saveTextToParentTag(textData, parentNode, matcher, isLeafNode) {
|
|
1738
2194
|
if (textData) {
|
|
1739
2195
|
if (isLeafNode === undefined)
|
|
1740
2196
|
isLeafNode = parentNode.child.length === 0;
|
|
1741
|
-
textData = this.parseTextData(textData, parentNode.tagname,
|
|
2197
|
+
textData = this.parseTextData(textData, parentNode.tagname, matcher, false, parentNode[":@"] ? Object.keys(parentNode[":@"]).length !== 0 : false, isLeafNode);
|
|
1742
2198
|
if (textData !== undefined && textData !== "")
|
|
1743
2199
|
parentNode.add(this.options.textNodeName, textData);
|
|
1744
2200
|
textData = "";
|
|
1745
2201
|
}
|
|
1746
2202
|
return textData;
|
|
1747
2203
|
}
|
|
1748
|
-
function isItStopNode(
|
|
1749
|
-
if (
|
|
1750
|
-
return
|
|
1751
|
-
|
|
1752
|
-
|
|
2204
|
+
function isItStopNode(stopNodeExpressions, matcher) {
|
|
2205
|
+
if (!stopNodeExpressions || stopNodeExpressions.length === 0)
|
|
2206
|
+
return false;
|
|
2207
|
+
for (let i = 0;i < stopNodeExpressions.length; i++) {
|
|
2208
|
+
if (matcher.matches(stopNodeExpressions[i])) {
|
|
2209
|
+
return true;
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
1753
2212
|
return false;
|
|
1754
2213
|
}
|
|
1755
2214
|
function tagExpWithClosingIndex(xmlData, i, closingChar = ">") {
|
|
@@ -1890,7 +2349,7 @@ var attrsRegx, parseXml = function(xmlData) {
|
|
|
1890
2349
|
const xmlObj = new XmlNode("!xml");
|
|
1891
2350
|
let currentNode = xmlObj;
|
|
1892
2351
|
let textData = "";
|
|
1893
|
-
|
|
2352
|
+
this.matcher.reset();
|
|
1894
2353
|
this.entityExpansionCount = 0;
|
|
1895
2354
|
this.currentExpandedLength = 0;
|
|
1896
2355
|
const docTypeReader = new DocTypeReader(this.options.processEntities);
|
|
@@ -1910,20 +2369,18 @@ var attrsRegx, parseXml = function(xmlData) {
|
|
|
1910
2369
|
tagName = this.options.transformTagName(tagName);
|
|
1911
2370
|
}
|
|
1912
2371
|
if (currentNode) {
|
|
1913
|
-
textData = this.saveTextToParentTag(textData, currentNode,
|
|
2372
|
+
textData = this.saveTextToParentTag(textData, currentNode, this.matcher);
|
|
1914
2373
|
}
|
|
1915
|
-
const lastTagName =
|
|
2374
|
+
const lastTagName = this.matcher.getCurrentTag();
|
|
1916
2375
|
if (tagName && this.options.unpairedTags.indexOf(tagName) !== -1) {
|
|
1917
2376
|
throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);
|
|
1918
2377
|
}
|
|
1919
|
-
let propIndex = 0;
|
|
1920
2378
|
if (lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1) {
|
|
1921
|
-
|
|
2379
|
+
this.matcher.pop();
|
|
1922
2380
|
this.tagsNodeStack.pop();
|
|
1923
|
-
} else {
|
|
1924
|
-
propIndex = jPath.lastIndexOf(".");
|
|
1925
2381
|
}
|
|
1926
|
-
|
|
2382
|
+
this.matcher.pop();
|
|
2383
|
+
this.isCurrentNodeStopNode = false;
|
|
1927
2384
|
currentNode = this.tagsNodeStack.pop();
|
|
1928
2385
|
textData = "";
|
|
1929
2386
|
i = closeIndex;
|
|
@@ -1931,21 +2388,21 @@ var attrsRegx, parseXml = function(xmlData) {
|
|
|
1931
2388
|
let tagData = readTagExp(xmlData, i, false, "?>");
|
|
1932
2389
|
if (!tagData)
|
|
1933
2390
|
throw new Error("Pi Tag is not closed.");
|
|
1934
|
-
textData = this.saveTextToParentTag(textData, currentNode,
|
|
2391
|
+
textData = this.saveTextToParentTag(textData, currentNode, this.matcher);
|
|
1935
2392
|
if (this.options.ignoreDeclaration && tagData.tagName === "?xml" || this.options.ignorePiTags) {} else {
|
|
1936
2393
|
const childNode = new XmlNode(tagData.tagName);
|
|
1937
2394
|
childNode.add(this.options.textNodeName, "");
|
|
1938
2395
|
if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent) {
|
|
1939
|
-
childNode[":@"] = this.buildAttributesMap(tagData.tagExp,
|
|
2396
|
+
childNode[":@"] = this.buildAttributesMap(tagData.tagExp, this.matcher, tagData.tagName);
|
|
1940
2397
|
}
|
|
1941
|
-
this.addChild(currentNode, childNode,
|
|
2398
|
+
this.addChild(currentNode, childNode, this.matcher, i);
|
|
1942
2399
|
}
|
|
1943
2400
|
i = tagData.closeIndex + 1;
|
|
1944
2401
|
} else if (xmlData.substr(i + 1, 3) === "!--") {
|
|
1945
2402
|
const endIndex = findClosingIndex(xmlData, "-->", i + 4, "Comment is not closed.");
|
|
1946
2403
|
if (this.options.commentPropName) {
|
|
1947
2404
|
const comment = xmlData.substring(i + 4, endIndex - 2);
|
|
1948
|
-
textData = this.saveTextToParentTag(textData, currentNode,
|
|
2405
|
+
textData = this.saveTextToParentTag(textData, currentNode, this.matcher);
|
|
1949
2406
|
currentNode.add(this.options.commentPropName, [{ [this.options.textNodeName]: comment }]);
|
|
1950
2407
|
}
|
|
1951
2408
|
i = endIndex;
|
|
@@ -1956,8 +2413,8 @@ var attrsRegx, parseXml = function(xmlData) {
|
|
|
1956
2413
|
} else if (xmlData.substr(i + 1, 2) === "![") {
|
|
1957
2414
|
const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
|
|
1958
2415
|
const tagExp = xmlData.substring(i + 9, closeIndex);
|
|
1959
|
-
textData = this.saveTextToParentTag(textData, currentNode,
|
|
1960
|
-
let val = this.parseTextData(tagExp, currentNode.tagname,
|
|
2416
|
+
textData = this.saveTextToParentTag(textData, currentNode, this.matcher);
|
|
2417
|
+
let val = this.parseTextData(tagExp, currentNode.tagname, this.matcher, true, false, true, true);
|
|
1961
2418
|
if (val == undefined)
|
|
1962
2419
|
val = "";
|
|
1963
2420
|
if (this.options.cdataPropName) {
|
|
@@ -1968,6 +2425,10 @@ var attrsRegx, parseXml = function(xmlData) {
|
|
|
1968
2425
|
i = closeIndex + 2;
|
|
1969
2426
|
} else {
|
|
1970
2427
|
let result = readTagExp(xmlData, i, this.options.removeNSPrefix);
|
|
2428
|
+
if (!result) {
|
|
2429
|
+
const context = xmlData.substring(Math.max(0, i - 50), Math.min(xmlData.length, i + 50));
|
|
2430
|
+
throw new Error(`readTagExp returned undefined at position ${i}. Context: "${context}"`);
|
|
2431
|
+
}
|
|
1971
2432
|
let tagName = result.tagName;
|
|
1972
2433
|
const rawTagName = result.rawTagName;
|
|
1973
2434
|
let tagExp = result.tagExp;
|
|
@@ -1985,28 +2446,45 @@ var attrsRegx, parseXml = function(xmlData) {
|
|
|
1985
2446
|
}
|
|
1986
2447
|
if (currentNode && textData) {
|
|
1987
2448
|
if (currentNode.tagname !== "!xml") {
|
|
1988
|
-
textData = this.saveTextToParentTag(textData, currentNode,
|
|
2449
|
+
textData = this.saveTextToParentTag(textData, currentNode, this.matcher, false);
|
|
1989
2450
|
}
|
|
1990
2451
|
}
|
|
1991
2452
|
const lastTag = currentNode;
|
|
1992
2453
|
if (lastTag && this.options.unpairedTags.indexOf(lastTag.tagname) !== -1) {
|
|
1993
2454
|
currentNode = this.tagsNodeStack.pop();
|
|
1994
|
-
|
|
2455
|
+
this.matcher.pop();
|
|
2456
|
+
}
|
|
2457
|
+
let isSelfClosing = false;
|
|
2458
|
+
if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
|
|
2459
|
+
isSelfClosing = true;
|
|
2460
|
+
if (tagName[tagName.length - 1] === "/") {
|
|
2461
|
+
tagName = tagName.substr(0, tagName.length - 1);
|
|
2462
|
+
tagExp = tagName;
|
|
2463
|
+
} else {
|
|
2464
|
+
tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
2465
|
+
}
|
|
2466
|
+
attrExpPresent = tagName !== tagExp;
|
|
1995
2467
|
}
|
|
2468
|
+
let prefixedAttrs = null;
|
|
2469
|
+
let rawAttrs = {};
|
|
2470
|
+
let namespace = undefined;
|
|
2471
|
+
namespace = extractNamespace(rawTagName);
|
|
1996
2472
|
if (tagName !== xmlObj.tagname) {
|
|
1997
|
-
|
|
2473
|
+
this.matcher.push(tagName, {}, namespace);
|
|
2474
|
+
}
|
|
2475
|
+
if (tagName !== tagExp && attrExpPresent) {
|
|
2476
|
+
prefixedAttrs = this.buildAttributesMap(tagExp, this.matcher, tagName);
|
|
2477
|
+
if (prefixedAttrs) {
|
|
2478
|
+
rawAttrs = extractRawAttributes(prefixedAttrs, this.options);
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
if (tagName !== xmlObj.tagname) {
|
|
2482
|
+
this.isCurrentNodeStopNode = this.isItStopNode(this.stopNodeExpressions, this.matcher);
|
|
1998
2483
|
}
|
|
1999
2484
|
const startIndex = i;
|
|
2000
|
-
if (this.
|
|
2485
|
+
if (this.isCurrentNodeStopNode) {
|
|
2001
2486
|
let tagContent = "";
|
|
2002
|
-
if (
|
|
2003
|
-
if (tagName[tagName.length - 1] === "/") {
|
|
2004
|
-
tagName = tagName.substr(0, tagName.length - 1);
|
|
2005
|
-
jPath = jPath.substr(0, jPath.length - 1);
|
|
2006
|
-
tagExp = tagName;
|
|
2007
|
-
} else {
|
|
2008
|
-
tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
2009
|
-
}
|
|
2487
|
+
if (isSelfClosing) {
|
|
2010
2488
|
i = result.closeIndex;
|
|
2011
2489
|
} else if (this.options.unpairedTags.indexOf(tagName) !== -1) {
|
|
2012
2490
|
i = result.closeIndex;
|
|
@@ -2018,24 +2496,15 @@ var attrsRegx, parseXml = function(xmlData) {
|
|
|
2018
2496
|
tagContent = result2.tagContent;
|
|
2019
2497
|
}
|
|
2020
2498
|
const childNode = new XmlNode(tagName);
|
|
2021
|
-
if (
|
|
2022
|
-
childNode[":@"] =
|
|
2023
|
-
}
|
|
2024
|
-
if (tagContent) {
|
|
2025
|
-
tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
|
|
2499
|
+
if (prefixedAttrs) {
|
|
2500
|
+
childNode[":@"] = prefixedAttrs;
|
|
2026
2501
|
}
|
|
2027
|
-
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
2028
2502
|
childNode.add(this.options.textNodeName, tagContent);
|
|
2029
|
-
this.
|
|
2503
|
+
this.matcher.pop();
|
|
2504
|
+
this.isCurrentNodeStopNode = false;
|
|
2505
|
+
this.addChild(currentNode, childNode, this.matcher, startIndex);
|
|
2030
2506
|
} else {
|
|
2031
|
-
if (
|
|
2032
|
-
if (tagName[tagName.length - 1] === "/") {
|
|
2033
|
-
tagName = tagName.substr(0, tagName.length - 1);
|
|
2034
|
-
jPath = jPath.substr(0, jPath.length - 1);
|
|
2035
|
-
tagExp = tagName;
|
|
2036
|
-
} else {
|
|
2037
|
-
tagExp = tagExp.substr(0, tagExp.length - 1);
|
|
2038
|
-
}
|
|
2507
|
+
if (isSelfClosing) {
|
|
2039
2508
|
if (this.options.transformTagName) {
|
|
2040
2509
|
const newTagName = this.options.transformTagName(tagName);
|
|
2041
2510
|
if (tagExp === tagName) {
|
|
@@ -2044,18 +2513,20 @@ var attrsRegx, parseXml = function(xmlData) {
|
|
|
2044
2513
|
tagName = newTagName;
|
|
2045
2514
|
}
|
|
2046
2515
|
const childNode = new XmlNode(tagName);
|
|
2047
|
-
if (
|
|
2048
|
-
childNode[":@"] =
|
|
2516
|
+
if (prefixedAttrs) {
|
|
2517
|
+
childNode[":@"] = prefixedAttrs;
|
|
2049
2518
|
}
|
|
2050
|
-
this.addChild(currentNode, childNode,
|
|
2051
|
-
|
|
2519
|
+
this.addChild(currentNode, childNode, this.matcher, startIndex);
|
|
2520
|
+
this.matcher.pop();
|
|
2521
|
+
this.isCurrentNodeStopNode = false;
|
|
2052
2522
|
} else if (this.options.unpairedTags.indexOf(tagName) !== -1) {
|
|
2053
2523
|
const childNode = new XmlNode(tagName);
|
|
2054
|
-
if (
|
|
2055
|
-
childNode[":@"] =
|
|
2524
|
+
if (prefixedAttrs) {
|
|
2525
|
+
childNode[":@"] = prefixedAttrs;
|
|
2056
2526
|
}
|
|
2057
|
-
this.addChild(currentNode, childNode,
|
|
2058
|
-
|
|
2527
|
+
this.addChild(currentNode, childNode, this.matcher, startIndex);
|
|
2528
|
+
this.matcher.pop();
|
|
2529
|
+
this.isCurrentNodeStopNode = false;
|
|
2059
2530
|
i = result.closeIndex;
|
|
2060
2531
|
continue;
|
|
2061
2532
|
} else {
|
|
@@ -2064,10 +2535,10 @@ var attrsRegx, parseXml = function(xmlData) {
|
|
|
2064
2535
|
throw new Error("Maximum nested tags exceeded");
|
|
2065
2536
|
}
|
|
2066
2537
|
this.tagsNodeStack.push(currentNode);
|
|
2067
|
-
if (
|
|
2068
|
-
childNode[":@"] =
|
|
2538
|
+
if (prefixedAttrs) {
|
|
2539
|
+
childNode[":@"] = prefixedAttrs;
|
|
2069
2540
|
}
|
|
2070
|
-
this.addChild(currentNode, childNode,
|
|
2541
|
+
this.addChild(currentNode, childNode, this.matcher, startIndex);
|
|
2071
2542
|
currentNode = childNode;
|
|
2072
2543
|
}
|
|
2073
2544
|
textData = "";
|
|
@@ -2079,82 +2550,46 @@ var attrsRegx, parseXml = function(xmlData) {
|
|
|
2079
2550
|
}
|
|
2080
2551
|
}
|
|
2081
2552
|
return xmlObj.child;
|
|
2082
|
-
}, replaceEntitiesValue = function(val, tagName, jPath) {
|
|
2083
|
-
if (val.indexOf("&") === -1) {
|
|
2084
|
-
return val;
|
|
2085
|
-
}
|
|
2086
|
-
const entityConfig = this.options.processEntities;
|
|
2087
|
-
if (!entityConfig.enabled) {
|
|
2088
|
-
return val;
|
|
2089
|
-
}
|
|
2090
|
-
if (entityConfig.allowedTags) {
|
|
2091
|
-
if (!entityConfig.allowedTags.includes(tagName)) {
|
|
2092
|
-
return val;
|
|
2093
|
-
}
|
|
2094
|
-
}
|
|
2095
|
-
if (entityConfig.tagFilter) {
|
|
2096
|
-
if (!entityConfig.tagFilter(tagName, jPath)) {
|
|
2097
|
-
return val;
|
|
2098
|
-
}
|
|
2099
|
-
}
|
|
2100
|
-
for (let entityName in this.docTypeEntities) {
|
|
2101
|
-
const entity = this.docTypeEntities[entityName];
|
|
2102
|
-
const matches = val.match(entity.regx);
|
|
2103
|
-
if (matches) {
|
|
2104
|
-
this.entityExpansionCount += matches.length;
|
|
2105
|
-
if (entityConfig.maxTotalExpansions && this.entityExpansionCount > entityConfig.maxTotalExpansions) {
|
|
2106
|
-
throw new Error(`Entity expansion limit exceeded: ${this.entityExpansionCount} > ${entityConfig.maxTotalExpansions}`);
|
|
2107
|
-
}
|
|
2108
|
-
const lengthBefore = val.length;
|
|
2109
|
-
val = val.replace(entity.regx, entity.val);
|
|
2110
|
-
if (entityConfig.maxExpandedLength) {
|
|
2111
|
-
this.currentExpandedLength += val.length - lengthBefore;
|
|
2112
|
-
if (this.currentExpandedLength > entityConfig.maxExpandedLength) {
|
|
2113
|
-
throw new Error(`Total expanded content size exceeded: ${this.currentExpandedLength} > ${entityConfig.maxExpandedLength}`);
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2117
|
-
}
|
|
2118
|
-
if (val.indexOf("&") === -1)
|
|
2119
|
-
return val;
|
|
2120
|
-
for (let entityName in this.lastEntities) {
|
|
2121
|
-
const entity = this.lastEntities[entityName];
|
|
2122
|
-
val = val.replace(entity.regex, entity.val);
|
|
2123
|
-
}
|
|
2124
|
-
if (val.indexOf("&") === -1)
|
|
2125
|
-
return val;
|
|
2126
|
-
if (this.options.htmlEntities) {
|
|
2127
|
-
for (let entityName in this.htmlEntities) {
|
|
2128
|
-
const entity = this.htmlEntities[entityName];
|
|
2129
|
-
val = val.replace(entity.regex, entity.val);
|
|
2130
|
-
}
|
|
2131
|
-
}
|
|
2132
|
-
val = val.replace(this.ampEntity.regex, this.ampEntity.val);
|
|
2133
|
-
return val;
|
|
2134
2553
|
};
|
|
2135
2554
|
var init_OrderedObjParser = __esm(() => {
|
|
2136
2555
|
init_util();
|
|
2137
2556
|
init_xmlNode();
|
|
2138
2557
|
init_DocTypeReader();
|
|
2139
2558
|
init_strnum();
|
|
2559
|
+
init_src();
|
|
2140
2560
|
attrsRegx = new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`, "gm");
|
|
2141
2561
|
});
|
|
2142
2562
|
|
|
2143
2563
|
// ../../node_modules/fast-xml-parser/src/xmlparser/node2json.js
|
|
2144
|
-
function
|
|
2145
|
-
|
|
2564
|
+
function stripAttributePrefix(attrs, prefix) {
|
|
2565
|
+
if (!attrs || typeof attrs !== "object")
|
|
2566
|
+
return {};
|
|
2567
|
+
if (!prefix)
|
|
2568
|
+
return attrs;
|
|
2569
|
+
const rawAttrs = {};
|
|
2570
|
+
for (const key in attrs) {
|
|
2571
|
+
if (key.startsWith(prefix)) {
|
|
2572
|
+
const rawName = key.substring(prefix.length);
|
|
2573
|
+
rawAttrs[rawName] = attrs[key];
|
|
2574
|
+
} else {
|
|
2575
|
+
rawAttrs[key] = attrs[key];
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
return rawAttrs;
|
|
2146
2579
|
}
|
|
2147
|
-
function
|
|
2580
|
+
function prettify(node, options, matcher) {
|
|
2581
|
+
return compress(node, options, matcher);
|
|
2582
|
+
}
|
|
2583
|
+
function compress(arr, options, matcher) {
|
|
2148
2584
|
let text;
|
|
2149
2585
|
const compressedObj = {};
|
|
2150
2586
|
for (let i = 0;i < arr.length; i++) {
|
|
2151
2587
|
const tagObj = arr[i];
|
|
2152
2588
|
const property = propName(tagObj);
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
newJpath = jPath + "." + property;
|
|
2589
|
+
if (property !== undefined && property !== options.textNodeName) {
|
|
2590
|
+
const rawAttrs = stripAttributePrefix(tagObj[":@"] || {}, options.attributeNamePrefix);
|
|
2591
|
+
matcher.push(property, rawAttrs);
|
|
2592
|
+
}
|
|
2158
2593
|
if (property === options.textNodeName) {
|
|
2159
2594
|
if (text === undefined)
|
|
2160
2595
|
text = tagObj[property];
|
|
@@ -2163,10 +2598,10 @@ function compress(arr, options, jPath) {
|
|
|
2163
2598
|
} else if (property === undefined) {
|
|
2164
2599
|
continue;
|
|
2165
2600
|
} else if (tagObj[property]) {
|
|
2166
|
-
let val = compress(tagObj[property], options,
|
|
2601
|
+
let val = compress(tagObj[property], options, matcher);
|
|
2167
2602
|
const isLeaf = isLeafTag(val, options);
|
|
2168
2603
|
if (tagObj[":@"]) {
|
|
2169
|
-
assignAttributes(val, tagObj[":@"],
|
|
2604
|
+
assignAttributes(val, tagObj[":@"], matcher, options);
|
|
2170
2605
|
} else if (Object.keys(val).length === 1 && val[options.textNodeName] !== undefined && !options.alwaysCreateTextNode) {
|
|
2171
2606
|
val = val[options.textNodeName];
|
|
2172
2607
|
} else if (Object.keys(val).length === 0) {
|
|
@@ -2184,12 +2619,16 @@ function compress(arr, options, jPath) {
|
|
|
2184
2619
|
}
|
|
2185
2620
|
compressedObj[property].push(val);
|
|
2186
2621
|
} else {
|
|
2187
|
-
|
|
2622
|
+
const jPathOrMatcher = options.jPath ? matcher.toString() : matcher;
|
|
2623
|
+
if (options.isArray(property, jPathOrMatcher, isLeaf)) {
|
|
2188
2624
|
compressedObj[property] = [val];
|
|
2189
2625
|
} else {
|
|
2190
2626
|
compressedObj[property] = val;
|
|
2191
2627
|
}
|
|
2192
2628
|
}
|
|
2629
|
+
if (property !== undefined && property !== options.textNodeName) {
|
|
2630
|
+
matcher.pop();
|
|
2631
|
+
}
|
|
2193
2632
|
}
|
|
2194
2633
|
}
|
|
2195
2634
|
if (typeof text === "string") {
|
|
@@ -2207,13 +2646,15 @@ function propName(obj) {
|
|
|
2207
2646
|
return key;
|
|
2208
2647
|
}
|
|
2209
2648
|
}
|
|
2210
|
-
function assignAttributes(obj, attrMap,
|
|
2649
|
+
function assignAttributes(obj, attrMap, matcher, options) {
|
|
2211
2650
|
if (attrMap) {
|
|
2212
2651
|
const keys = Object.keys(attrMap);
|
|
2213
2652
|
const len = keys.length;
|
|
2214
2653
|
for (let i = 0;i < len; i++) {
|
|
2215
2654
|
const atrrName = keys[i];
|
|
2216
|
-
|
|
2655
|
+
const rawAttrName = atrrName.startsWith(options.attributeNamePrefix) ? atrrName.substring(options.attributeNamePrefix.length) : atrrName;
|
|
2656
|
+
const jPathOrMatcher = options.jPath ? matcher.toString() + "." + rawAttrName : matcher;
|
|
2657
|
+
if (options.isArray(atrrName, jPathOrMatcher, true, true)) {
|
|
2217
2658
|
obj[atrrName] = [attrMap[atrrName]];
|
|
2218
2659
|
} else {
|
|
2219
2660
|
obj[atrrName] = attrMap[atrrName];
|
|
@@ -2235,6 +2676,7 @@ function isLeafTag(obj, options) {
|
|
|
2235
2676
|
var METADATA_SYMBOL2;
|
|
2236
2677
|
var init_node2json = __esm(() => {
|
|
2237
2678
|
init_xmlNode();
|
|
2679
|
+
init_src();
|
|
2238
2680
|
METADATA_SYMBOL2 = XmlNode.getMetaDataSymbol();
|
|
2239
2681
|
});
|
|
2240
2682
|
|
|
@@ -2264,7 +2706,7 @@ class XMLParser {
|
|
|
2264
2706
|
if (this.options.preserveOrder || orderedResult === undefined)
|
|
2265
2707
|
return orderedResult;
|
|
2266
2708
|
else
|
|
2267
|
-
return prettify(orderedResult, this.options);
|
|
2709
|
+
return prettify(orderedResult, this.options, orderedObjParser.matcher);
|
|
2268
2710
|
}
|
|
2269
2711
|
addEntity(key, value) {
|
|
2270
2712
|
if (value.indexOf("&") !== -1) {
|
|
@@ -8539,7 +8981,8 @@ function generateExternalDnsStaticSiteTemplate(config4) {
|
|
|
8539
8981
|
aliases,
|
|
8540
8982
|
certificateArn,
|
|
8541
8983
|
defaultRootObject = "index.html",
|
|
8542
|
-
errorDocument = "404.html"
|
|
8984
|
+
errorDocument = "404.html",
|
|
8985
|
+
passthroughUrls = false
|
|
8543
8986
|
} = config4;
|
|
8544
8987
|
const resources = {};
|
|
8545
8988
|
const outputs = {};
|
|
@@ -8579,16 +9022,17 @@ function generateExternalDnsStaticSiteTemplate(config4) {
|
|
|
8579
9022
|
}
|
|
8580
9023
|
}
|
|
8581
9024
|
};
|
|
8582
|
-
|
|
8583
|
-
|
|
8584
|
-
|
|
8585
|
-
|
|
8586
|
-
|
|
8587
|
-
|
|
8588
|
-
|
|
8589
|
-
|
|
8590
|
-
|
|
8591
|
-
|
|
9025
|
+
if (!passthroughUrls) {
|
|
9026
|
+
resources.UrlRewriteFunction = {
|
|
9027
|
+
Type: "AWS::CloudFront::Function",
|
|
9028
|
+
Properties: {
|
|
9029
|
+
Name: { "Fn::Sub": "${AWS::StackName}-url-rewrite" },
|
|
9030
|
+
AutoPublish: true,
|
|
9031
|
+
FunctionConfig: {
|
|
9032
|
+
Comment: "Append .html extension to URLs without extensions",
|
|
9033
|
+
Runtime: "cloudfront-js-2.0"
|
|
9034
|
+
},
|
|
9035
|
+
FunctionCode: `function handler(event) {
|
|
8592
9036
|
const request = event.request;
|
|
8593
9037
|
var uri = request.uri;
|
|
8594
9038
|
|
|
@@ -8603,8 +9047,9 @@ function generateExternalDnsStaticSiteTemplate(config4) {
|
|
|
8603
9047
|
|
|
8604
9048
|
return request;
|
|
8605
9049
|
}`
|
|
8606
|
-
|
|
8607
|
-
|
|
9050
|
+
}
|
|
9051
|
+
};
|
|
9052
|
+
}
|
|
8608
9053
|
const distributionConfig = {
|
|
8609
9054
|
Enabled: true,
|
|
8610
9055
|
DefaultRootObject: defaultRootObject,
|
|
@@ -8628,12 +9073,14 @@ function generateExternalDnsStaticSiteTemplate(config4) {
|
|
|
8628
9073
|
CachedMethods: ["GET", "HEAD"],
|
|
8629
9074
|
Compress: true,
|
|
8630
9075
|
CachePolicyId: "658327ea-f89d-4fab-a63d-7e88639e58f6",
|
|
8631
|
-
|
|
8632
|
-
|
|
8633
|
-
|
|
8634
|
-
|
|
8635
|
-
|
|
8636
|
-
|
|
9076
|
+
...!passthroughUrls && {
|
|
9077
|
+
FunctionAssociations: [
|
|
9078
|
+
{
|
|
9079
|
+
EventType: "viewer-request",
|
|
9080
|
+
FunctionARN: { "Fn::GetAtt": ["UrlRewriteFunction", "FunctionARN"] }
|
|
9081
|
+
}
|
|
9082
|
+
]
|
|
9083
|
+
}
|
|
8637
9084
|
},
|
|
8638
9085
|
CustomErrorResponses: [
|
|
8639
9086
|
{
|
|
@@ -8664,7 +9111,7 @@ function generateExternalDnsStaticSiteTemplate(config4) {
|
|
|
8664
9111
|
}
|
|
8665
9112
|
resources.CloudFrontDistribution = {
|
|
8666
9113
|
Type: "AWS::CloudFront::Distribution",
|
|
8667
|
-
DependsOn: ["S3Bucket", "CloudFrontOAC", "UrlRewriteFunction"],
|
|
9114
|
+
DependsOn: passthroughUrls ? ["S3Bucket", "CloudFrontOAC"] : ["S3Bucket", "CloudFrontOAC", "UrlRewriteFunction"],
|
|
8668
9115
|
Properties: {
|
|
8669
9116
|
DistributionConfig: distributionConfig
|
|
8670
9117
|
}
|
|
@@ -8910,7 +9357,8 @@ async function deployStaticSiteWithExternalDns(config4) {
|
|
|
8910
9357
|
aliases,
|
|
8911
9358
|
certificateArn,
|
|
8912
9359
|
defaultRootObject: config4.defaultRootObject,
|
|
8913
|
-
errorDocument: config4.errorDocument
|
|
9360
|
+
errorDocument: config4.errorDocument,
|
|
9361
|
+
passthroughUrls: config4.passthroughUrls
|
|
8914
9362
|
});
|
|
8915
9363
|
const tags = Object.entries(config4.tags || {}).map(([Key, Value]) => ({ Key, Value }));
|
|
8916
9364
|
tags.push({ Key: "ManagedBy", Value: "ts-cloud" });
|
|
@@ -9940,7 +10388,7 @@ async function uploadStaticFiles(options) {
|
|
|
9940
10388
|
}
|
|
9941
10389
|
function getContentType(filePath) {
|
|
9942
10390
|
const ext = filePath.split(".").pop()?.toLowerCase();
|
|
9943
|
-
const
|
|
10391
|
+
const types4 = {
|
|
9944
10392
|
html: "text/html; charset=utf-8",
|
|
9945
10393
|
css: "text/css; charset=utf-8",
|
|
9946
10394
|
js: "application/javascript; charset=utf-8",
|
|
@@ -9956,9 +10404,12 @@ async function uploadStaticFiles(options) {
|
|
|
9956
10404
|
woff2: "font/woff2",
|
|
9957
10405
|
ttf: "font/ttf",
|
|
9958
10406
|
xml: "application/xml",
|
|
9959
|
-
txt: "text/plain; charset=utf-8"
|
|
10407
|
+
txt: "text/plain; charset=utf-8",
|
|
10408
|
+
sh: "text/plain; charset=utf-8",
|
|
10409
|
+
bash: "text/plain; charset=utf-8",
|
|
10410
|
+
ps1: "text/plain; charset=utf-8"
|
|
9960
10411
|
};
|
|
9961
|
-
return
|
|
10412
|
+
return types4[ext || ""] || "application/octet-stream";
|
|
9962
10413
|
}
|
|
9963
10414
|
function computeMD5(content) {
|
|
9964
10415
|
return createHash7("md5").update(content).digest("hex");
|
|
@@ -15168,7 +15619,7 @@ async function getConfig() {
|
|
|
15168
15619
|
}
|
|
15169
15620
|
var loadCloudConfig = getConfig;
|
|
15170
15621
|
var config3 = defaultConfig3;
|
|
15171
|
-
// ../
|
|
15622
|
+
// ../core/src/types.ts
|
|
15172
15623
|
var QueuePresets = {
|
|
15173
15624
|
backgroundJobs: {
|
|
15174
15625
|
visibilityTimeout: 120,
|