@optique/core 1.0.0-dev.1574 → 1.0.0-dev.1580

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.
@@ -1672,6 +1672,13 @@ function socketAddress(options) {
1672
1672
  ...options?.host?.ip,
1673
1673
  metavar: "HOST"
1674
1674
  });
1675
+ const disambiguationParser = hostType === "ip" ? hostname({
1676
+ metavar: "HOST",
1677
+ allowWildcard: true,
1678
+ allowUnderscore: true,
1679
+ maxLength: Math.max(253, options?.host?.hostname?.maxLength ?? 0)
1680
+ }) : hostnameParser;
1681
+ const separatorIsHostChar = /^[a-zA-Z0-9._-]+$/.test(separator);
1675
1682
  const portParser = port({
1676
1683
  ...options?.port,
1677
1684
  metavar: "PORT",
@@ -1739,7 +1746,7 @@ function socketAddress(options) {
1739
1746
  const trimmed = input.trim();
1740
1747
  const canOmitPort = defaultPort !== void 0 && !requirePort;
1741
1748
  let firstHostError;
1742
- let validHostNumericPortInvalid = false;
1749
+ let validHostInvalidPortError;
1743
1750
  let trailingSepHost;
1744
1751
  let trailingSepHostError;
1745
1752
  let anySeparatorFound = false;
@@ -1774,15 +1781,22 @@ function socketAddress(options) {
1774
1781
  hostPart,
1775
1782
  error: hostResult.error
1776
1783
  };
1777
- } else if (!validHostNumericPortInvalid && hostPart !== "" && /^[0-9]+$/.test(portPart)) if (looksLikeIpv4(hostPart) || looksLikeAltIpv4Literal(hostPart)) {
1784
+ } else if (validHostInvalidPortError === void 0 && hostPart !== "" && /^[0-9]+$/.test(portPart)) if (looksLikeIpv4(hostPart) || looksLikeAltIpv4Literal(hostPart)) {
1778
1785
  const hostResult = parseHost(hostPart);
1779
1786
  if (!hostResult.success) {
1780
1787
  if (firstHostError === void 0 || !looksLikeIpv4(firstHostError.hostPart) && !looksLikeAltIpv4Literal(firstHostError.hostPart)) firstHostError = {
1781
1788
  hostPart,
1782
1789
  error: hostResult.error
1783
1790
  };
1784
- } else validHostNumericPortInvalid = true;
1785
- } else validHostNumericPortInvalid = true;
1791
+ } else validHostInvalidPortError = portResult.error;
1792
+ } else {
1793
+ validHostInvalidPortError = portResult.error;
1794
+ const hostResult = parseHost(hostPart);
1795
+ if (!hostResult.success && firstHostError === void 0) firstHostError = {
1796
+ hostPart,
1797
+ error: hostResult.error
1798
+ };
1799
+ }
1786
1800
  else if ((firstHostError === void 0 || !looksLikeIpv4(firstHostError.hostPart) && !looksLikeAltIpv4Literal(firstHostError.hostPart)) && (looksLikeIpv4(hostPart) || looksLikeAltIpv4Literal(hostPart))) {
1787
1801
  const hostResult = parseHost(hostPart);
1788
1802
  if (!hostResult.success) firstHostError = {
@@ -1793,7 +1807,7 @@ function socketAddress(options) {
1793
1807
  }
1794
1808
  searchFrom = separatorIndex;
1795
1809
  }
1796
- if (validHostNumericPortInvalid) {
1810
+ if (validHostInvalidPortError !== void 0) {
1797
1811
  const errorMsg$1 = options?.errors?.invalidFormat;
1798
1812
  if (errorMsg$1) {
1799
1813
  const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1;
@@ -1802,10 +1816,25 @@ function socketAddress(options) {
1802
1816
  error: msg
1803
1817
  };
1804
1818
  }
1805
- return {
1819
+ if (firstHostError !== void 0 && firstHostError.hostPart !== "") {
1820
+ const portSplitHostIsDegenerate = separatorIsHostChar ? firstHostError.hostPart.replaceAll(separator, "") === "" : firstHostError.hostPart.includes(separator);
1821
+ if (portSplitHostIsDegenerate) return {
1822
+ success: false,
1823
+ error: require_message.message`Expected a socket address in format host${separator}port, but got ${input}.`
1824
+ };
1825
+ if (!disambiguationParser.parse(trimmed).success) return {
1826
+ success: false,
1827
+ error: firstHostError.error
1828
+ };
1829
+ }
1830
+ if (disambiguationParser.parse(trimmed).success) return {
1806
1831
  success: false,
1807
1832
  error: require_message.message`Expected a socket address in format host${separator}port, but got ${input}.`
1808
1833
  };
1834
+ return {
1835
+ success: false,
1836
+ error: validHostInvalidPortError
1837
+ };
1809
1838
  }
1810
1839
  if (firstHostError !== void 0) {
1811
1840
  if (looksLikeIpv4(firstHostError.hostPart) || looksLikeAltIpv4Literal(firstHostError.hostPart)) {
@@ -1858,14 +1887,11 @@ function socketAddress(options) {
1858
1887
  error: msg
1859
1888
  };
1860
1889
  }
1861
- if (looksLikeIpv4(trailingSepHostError.hostPart) || looksLikeAltIpv4Literal(trailingSepHostError.hostPart)) return {
1890
+ const trailingHostIsDegenerate = separatorIsHostChar ? trailingSepHostError.hostPart.replaceAll(separator, "") === "" : trailingSepHostError.hostPart.includes(separator);
1891
+ if (trailingSepHostError.hostPart !== "" && !trailingHostIsDegenerate && !disambiguationParser.parse(trimmed).success) return {
1862
1892
  success: false,
1863
1893
  error: trailingSepHostError.error
1864
1894
  };
1865
- return {
1866
- success: false,
1867
- error: require_message.message`Expected a socket address in format host${separator}port, but got ${input}.`
1868
- };
1869
1895
  }
1870
1896
  if (!canOmitPort && !requirePort && hostOnlyResult !== void 0 && hostOnlyResult.success) {
1871
1897
  const errorMsg$1 = options?.errors?.missingPort;
@@ -1895,6 +1921,11 @@ function socketAddress(options) {
1895
1921
  error: msg
1896
1922
  };
1897
1923
  }
1924
+ const hostPartIsDegenerate = separatorIsHostChar ? firstHostError.hostPart.replaceAll(separator, "") === "" : firstHostError.hostPart.includes(separator);
1925
+ if (firstHostError.hostPart !== "" && !hostPartIsDegenerate && !disambiguationParser.parse(trimmed).success) return {
1926
+ success: false,
1927
+ error: firstHostError.error
1928
+ };
1898
1929
  }
1899
1930
  const errorMsg = options?.errors?.invalidFormat;
1900
1931
  if (errorMsg) {
@@ -1672,6 +1672,13 @@ function socketAddress(options) {
1672
1672
  ...options?.host?.ip,
1673
1673
  metavar: "HOST"
1674
1674
  });
1675
+ const disambiguationParser = hostType === "ip" ? hostname({
1676
+ metavar: "HOST",
1677
+ allowWildcard: true,
1678
+ allowUnderscore: true,
1679
+ maxLength: Math.max(253, options?.host?.hostname?.maxLength ?? 0)
1680
+ }) : hostnameParser;
1681
+ const separatorIsHostChar = /^[a-zA-Z0-9._-]+$/.test(separator);
1675
1682
  const portParser = port({
1676
1683
  ...options?.port,
1677
1684
  metavar: "PORT",
@@ -1739,7 +1746,7 @@ function socketAddress(options) {
1739
1746
  const trimmed = input.trim();
1740
1747
  const canOmitPort = defaultPort !== void 0 && !requirePort;
1741
1748
  let firstHostError;
1742
- let validHostNumericPortInvalid = false;
1749
+ let validHostInvalidPortError;
1743
1750
  let trailingSepHost;
1744
1751
  let trailingSepHostError;
1745
1752
  let anySeparatorFound = false;
@@ -1774,15 +1781,22 @@ function socketAddress(options) {
1774
1781
  hostPart,
1775
1782
  error: hostResult.error
1776
1783
  };
1777
- } else if (!validHostNumericPortInvalid && hostPart !== "" && /^[0-9]+$/.test(portPart)) if (looksLikeIpv4(hostPart) || looksLikeAltIpv4Literal(hostPart)) {
1784
+ } else if (validHostInvalidPortError === void 0 && hostPart !== "" && /^[0-9]+$/.test(portPart)) if (looksLikeIpv4(hostPart) || looksLikeAltIpv4Literal(hostPart)) {
1778
1785
  const hostResult = parseHost(hostPart);
1779
1786
  if (!hostResult.success) {
1780
1787
  if (firstHostError === void 0 || !looksLikeIpv4(firstHostError.hostPart) && !looksLikeAltIpv4Literal(firstHostError.hostPart)) firstHostError = {
1781
1788
  hostPart,
1782
1789
  error: hostResult.error
1783
1790
  };
1784
- } else validHostNumericPortInvalid = true;
1785
- } else validHostNumericPortInvalid = true;
1791
+ } else validHostInvalidPortError = portResult.error;
1792
+ } else {
1793
+ validHostInvalidPortError = portResult.error;
1794
+ const hostResult = parseHost(hostPart);
1795
+ if (!hostResult.success && firstHostError === void 0) firstHostError = {
1796
+ hostPart,
1797
+ error: hostResult.error
1798
+ };
1799
+ }
1786
1800
  else if ((firstHostError === void 0 || !looksLikeIpv4(firstHostError.hostPart) && !looksLikeAltIpv4Literal(firstHostError.hostPart)) && (looksLikeIpv4(hostPart) || looksLikeAltIpv4Literal(hostPart))) {
1787
1801
  const hostResult = parseHost(hostPart);
1788
1802
  if (!hostResult.success) firstHostError = {
@@ -1793,7 +1807,7 @@ function socketAddress(options) {
1793
1807
  }
1794
1808
  searchFrom = separatorIndex;
1795
1809
  }
1796
- if (validHostNumericPortInvalid) {
1810
+ if (validHostInvalidPortError !== void 0) {
1797
1811
  const errorMsg$1 = options?.errors?.invalidFormat;
1798
1812
  if (errorMsg$1) {
1799
1813
  const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1;
@@ -1802,10 +1816,25 @@ function socketAddress(options) {
1802
1816
  error: msg
1803
1817
  };
1804
1818
  }
1805
- return {
1819
+ if (firstHostError !== void 0 && firstHostError.hostPart !== "") {
1820
+ const portSplitHostIsDegenerate = separatorIsHostChar ? firstHostError.hostPart.replaceAll(separator, "") === "" : firstHostError.hostPart.includes(separator);
1821
+ if (portSplitHostIsDegenerate) return {
1822
+ success: false,
1823
+ error: message`Expected a socket address in format host${separator}port, but got ${input}.`
1824
+ };
1825
+ if (!disambiguationParser.parse(trimmed).success) return {
1826
+ success: false,
1827
+ error: firstHostError.error
1828
+ };
1829
+ }
1830
+ if (disambiguationParser.parse(trimmed).success) return {
1806
1831
  success: false,
1807
1832
  error: message`Expected a socket address in format host${separator}port, but got ${input}.`
1808
1833
  };
1834
+ return {
1835
+ success: false,
1836
+ error: validHostInvalidPortError
1837
+ };
1809
1838
  }
1810
1839
  if (firstHostError !== void 0) {
1811
1840
  if (looksLikeIpv4(firstHostError.hostPart) || looksLikeAltIpv4Literal(firstHostError.hostPart)) {
@@ -1858,14 +1887,11 @@ function socketAddress(options) {
1858
1887
  error: msg
1859
1888
  };
1860
1889
  }
1861
- if (looksLikeIpv4(trailingSepHostError.hostPart) || looksLikeAltIpv4Literal(trailingSepHostError.hostPart)) return {
1890
+ const trailingHostIsDegenerate = separatorIsHostChar ? trailingSepHostError.hostPart.replaceAll(separator, "") === "" : trailingSepHostError.hostPart.includes(separator);
1891
+ if (trailingSepHostError.hostPart !== "" && !trailingHostIsDegenerate && !disambiguationParser.parse(trimmed).success) return {
1862
1892
  success: false,
1863
1893
  error: trailingSepHostError.error
1864
1894
  };
1865
- return {
1866
- success: false,
1867
- error: message`Expected a socket address in format host${separator}port, but got ${input}.`
1868
- };
1869
1895
  }
1870
1896
  if (!canOmitPort && !requirePort && hostOnlyResult !== void 0 && hostOnlyResult.success) {
1871
1897
  const errorMsg$1 = options?.errors?.missingPort;
@@ -1895,6 +1921,11 @@ function socketAddress(options) {
1895
1921
  error: msg
1896
1922
  };
1897
1923
  }
1924
+ const hostPartIsDegenerate = separatorIsHostChar ? firstHostError.hostPart.replaceAll(separator, "") === "" : firstHostError.hostPart.includes(separator);
1925
+ if (firstHostError.hostPart !== "" && !hostPartIsDegenerate && !disambiguationParser.parse(trimmed).success) return {
1926
+ success: false,
1927
+ error: firstHostError.error
1928
+ };
1898
1929
  }
1899
1930
  const errorMsg = options?.errors?.invalidFormat;
1900
1931
  if (errorMsg) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1574+d9b3596d",
3
+ "version": "1.0.0-dev.1580+2d932679",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",