webpipe-js 2.0.44 → 2.0.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1648,36 +1648,42 @@ function printTypeResolver(resolver) {
1648
1648
  return lines.join("\n");
1649
1649
  }
1650
1650
  function printMock(mock, indent = " ") {
1651
- return `${indent}with mock ${mock.target} returning \`${mock.returnValue}\``;
1651
+ const target = mock.target.replace(/^(query|mutation)\.(.*)$/, "$1 $2");
1652
+ return `${indent}with mock ${target} returning \`${mock.returnValue}\``;
1652
1653
  }
1653
1654
  function printCondition(condition, indent = " ") {
1654
1655
  const condType = condition.conditionType.toLowerCase();
1656
+ const formatConditionValue = (val) => {
1657
+ if (val.startsWith("`") || val.startsWith('"')) return val;
1658
+ const isBareTemplate = /^\{\{[^}]+\}\}$/.test(val);
1659
+ if (isBareTemplate) return val;
1660
+ const hasTemplateVars = /\{\{[^}]+\}\}/.test(val);
1661
+ if (hasTemplateVars) return `"${val}"`;
1662
+ if (val.includes("\n") || val.includes("{") && val.includes("}") || val.includes("[") && val.includes("]")) {
1663
+ return `\`${val}\``;
1664
+ }
1665
+ if (val.includes(" ") || val.includes(",")) return `"${val}"`;
1666
+ return val;
1667
+ };
1655
1668
  if (condition.isCallAssertion && condition.callTarget) {
1656
1669
  const [callType, callName] = condition.callTarget.split(".");
1657
- const value2 = condition.value.startsWith("`") ? condition.value : condition.value.includes("\n") || condition.value.includes("{") || condition.value.includes("[") ? `\`${condition.value}\`` : condition.value;
1658
- return `${indent}${condType} call ${callType} ${callName} ${condition.comparison} ${value2}`;
1670
+ return `${indent}${condType} call ${callType} ${callName} ${condition.comparison} ${formatConditionValue(condition.value)}`;
1659
1671
  }
1660
1672
  if (condition.field === "selector" && condition.selector && condition.domAssert) {
1661
1673
  const selector = condition.selector;
1662
- const formatValue = (val) => {
1663
- if (val.startsWith("`") || val.startsWith('"')) return val;
1664
- if (val.includes("\n") || val.includes("{") || val.includes("[")) return `\`${val}\``;
1665
- return `"${val}"`;
1666
- };
1667
1674
  if (condition.domAssert.kind === "Exists") {
1668
1675
  const operation = condition.comparison === "exists" ? "exists" : "does not exist";
1669
1676
  return `${indent}${condType} selector \`${selector}\` ${operation}`;
1670
1677
  } else if (condition.domAssert.kind === "Text") {
1671
- return `${indent}${condType} selector \`${selector}\` text ${condition.comparison} ${formatValue(condition.value)}`;
1678
+ return `${indent}${condType} selector \`${selector}\` text ${condition.comparison} ${formatConditionValue(condition.value)}`;
1672
1679
  } else if (condition.domAssert.kind === "Count") {
1673
1680
  return `${indent}${condType} selector \`${selector}\` count ${condition.comparison} ${condition.value}`;
1674
1681
  } else if (condition.domAssert.kind === "Attribute") {
1675
- return `${indent}${condType} selector \`${selector}\` attribute "${condition.domAssert.name}" ${condition.comparison} ${formatValue(condition.value)}`;
1682
+ return `${indent}${condType} selector \`${selector}\` attribute "${condition.domAssert.name}" ${condition.comparison} ${formatConditionValue(condition.value)}`;
1676
1683
  }
1677
1684
  }
1678
1685
  const fieldPart = condition.headerName ? `${condition.field} "${condition.headerName}"` : condition.jqExpr ? `${condition.field} \`${condition.jqExpr}\`` : condition.field;
1679
- const value = condition.value.startsWith("`") ? condition.value : condition.value.includes("\n") || condition.value.includes("{") || condition.value.includes("[") ? `\`${condition.value}\`` : condition.value;
1680
- return `${indent}${condType} ${fieldPart} ${condition.comparison} ${value}`;
1686
+ return `${indent}${condType} ${fieldPart} ${condition.comparison} ${formatConditionValue(condition.value)}`;
1681
1687
  }
1682
1688
  function printTest(test) {
1683
1689
  const lines = [];
@@ -1789,48 +1795,56 @@ function prettyPrint(program) {
1789
1795
  });
1790
1796
  allItems.sort((a, b) => a.lineNumber - b.lineNumber);
1791
1797
  allItems.forEach((entry, index) => {
1798
+ const nextItem = allItems[index + 1];
1799
+ const shouldAddBlankLine = () => {
1800
+ if (!nextItem) return false;
1801
+ if (entry.type === "comment") {
1802
+ if (nextItem.type === "comment") return false;
1803
+ return nextItem.lineNumber - entry.lineNumber > 1;
1804
+ }
1805
+ if (entry.type === "variable") {
1806
+ return nextItem.type !== "variable";
1807
+ }
1808
+ if (nextItem.type === "comment") {
1809
+ return nextItem.lineNumber - entry.lineNumber > 1;
1810
+ }
1811
+ return true;
1812
+ };
1792
1813
  switch (entry.type) {
1793
1814
  case "comment":
1794
1815
  lines.push(printComment(entry.item));
1795
1816
  break;
1796
1817
  case "config":
1797
1818
  lines.push(printConfig(entry.item));
1798
- lines.push("");
1799
1819
  break;
1800
1820
  case "graphqlSchema":
1801
1821
  lines.push(printGraphQLSchema(entry.item));
1802
- lines.push("");
1803
1822
  break;
1804
1823
  case "query":
1805
1824
  lines.push(printQueryResolver(entry.item));
1806
- lines.push("");
1807
1825
  break;
1808
1826
  case "mutation":
1809
1827
  lines.push(printMutationResolver(entry.item));
1810
- lines.push("");
1811
1828
  break;
1812
1829
  case "resolver":
1813
1830
  lines.push(printTypeResolver(entry.item));
1814
- lines.push("");
1815
1831
  break;
1816
1832
  case "route":
1817
1833
  lines.push(printRoute(entry.item));
1818
- lines.push("");
1819
1834
  break;
1820
1835
  case "pipeline":
1821
1836
  lines.push(printPipeline(entry.item));
1822
- lines.push("");
1823
1837
  break;
1824
1838
  case "variable":
1825
1839
  lines.push(printVariable(entry.item));
1826
- const nextNonVariable = allItems.slice(index + 1).find((item) => item.type !== "variable");
1827
- if (nextNonVariable) lines.push("");
1828
1840
  break;
1829
1841
  case "describe":
1830
1842
  lines.push(printDescribe(entry.item));
1831
- lines.push("");
1832
1843
  break;
1833
1844
  }
1845
+ if (shouldAddBlankLine()) {
1846
+ lines.push("");
1847
+ }
1834
1848
  });
1835
1849
  return lines.join("\n").trim() + "\n";
1836
1850
  }
package/dist/index.mjs CHANGED
@@ -1595,36 +1595,42 @@ function printTypeResolver(resolver) {
1595
1595
  return lines.join("\n");
1596
1596
  }
1597
1597
  function printMock(mock, indent = " ") {
1598
- return `${indent}with mock ${mock.target} returning \`${mock.returnValue}\``;
1598
+ const target = mock.target.replace(/^(query|mutation)\.(.*)$/, "$1 $2");
1599
+ return `${indent}with mock ${target} returning \`${mock.returnValue}\``;
1599
1600
  }
1600
1601
  function printCondition(condition, indent = " ") {
1601
1602
  const condType = condition.conditionType.toLowerCase();
1603
+ const formatConditionValue = (val) => {
1604
+ if (val.startsWith("`") || val.startsWith('"')) return val;
1605
+ const isBareTemplate = /^\{\{[^}]+\}\}$/.test(val);
1606
+ if (isBareTemplate) return val;
1607
+ const hasTemplateVars = /\{\{[^}]+\}\}/.test(val);
1608
+ if (hasTemplateVars) return `"${val}"`;
1609
+ if (val.includes("\n") || val.includes("{") && val.includes("}") || val.includes("[") && val.includes("]")) {
1610
+ return `\`${val}\``;
1611
+ }
1612
+ if (val.includes(" ") || val.includes(",")) return `"${val}"`;
1613
+ return val;
1614
+ };
1602
1615
  if (condition.isCallAssertion && condition.callTarget) {
1603
1616
  const [callType, callName] = condition.callTarget.split(".");
1604
- const value2 = condition.value.startsWith("`") ? condition.value : condition.value.includes("\n") || condition.value.includes("{") || condition.value.includes("[") ? `\`${condition.value}\`` : condition.value;
1605
- return `${indent}${condType} call ${callType} ${callName} ${condition.comparison} ${value2}`;
1617
+ return `${indent}${condType} call ${callType} ${callName} ${condition.comparison} ${formatConditionValue(condition.value)}`;
1606
1618
  }
1607
1619
  if (condition.field === "selector" && condition.selector && condition.domAssert) {
1608
1620
  const selector = condition.selector;
1609
- const formatValue = (val) => {
1610
- if (val.startsWith("`") || val.startsWith('"')) return val;
1611
- if (val.includes("\n") || val.includes("{") || val.includes("[")) return `\`${val}\``;
1612
- return `"${val}"`;
1613
- };
1614
1621
  if (condition.domAssert.kind === "Exists") {
1615
1622
  const operation = condition.comparison === "exists" ? "exists" : "does not exist";
1616
1623
  return `${indent}${condType} selector \`${selector}\` ${operation}`;
1617
1624
  } else if (condition.domAssert.kind === "Text") {
1618
- return `${indent}${condType} selector \`${selector}\` text ${condition.comparison} ${formatValue(condition.value)}`;
1625
+ return `${indent}${condType} selector \`${selector}\` text ${condition.comparison} ${formatConditionValue(condition.value)}`;
1619
1626
  } else if (condition.domAssert.kind === "Count") {
1620
1627
  return `${indent}${condType} selector \`${selector}\` count ${condition.comparison} ${condition.value}`;
1621
1628
  } else if (condition.domAssert.kind === "Attribute") {
1622
- return `${indent}${condType} selector \`${selector}\` attribute "${condition.domAssert.name}" ${condition.comparison} ${formatValue(condition.value)}`;
1629
+ return `${indent}${condType} selector \`${selector}\` attribute "${condition.domAssert.name}" ${condition.comparison} ${formatConditionValue(condition.value)}`;
1623
1630
  }
1624
1631
  }
1625
1632
  const fieldPart = condition.headerName ? `${condition.field} "${condition.headerName}"` : condition.jqExpr ? `${condition.field} \`${condition.jqExpr}\`` : condition.field;
1626
- const value = condition.value.startsWith("`") ? condition.value : condition.value.includes("\n") || condition.value.includes("{") || condition.value.includes("[") ? `\`${condition.value}\`` : condition.value;
1627
- return `${indent}${condType} ${fieldPart} ${condition.comparison} ${value}`;
1633
+ return `${indent}${condType} ${fieldPart} ${condition.comparison} ${formatConditionValue(condition.value)}`;
1628
1634
  }
1629
1635
  function printTest(test) {
1630
1636
  const lines = [];
@@ -1736,48 +1742,56 @@ function prettyPrint(program) {
1736
1742
  });
1737
1743
  allItems.sort((a, b) => a.lineNumber - b.lineNumber);
1738
1744
  allItems.forEach((entry, index) => {
1745
+ const nextItem = allItems[index + 1];
1746
+ const shouldAddBlankLine = () => {
1747
+ if (!nextItem) return false;
1748
+ if (entry.type === "comment") {
1749
+ if (nextItem.type === "comment") return false;
1750
+ return nextItem.lineNumber - entry.lineNumber > 1;
1751
+ }
1752
+ if (entry.type === "variable") {
1753
+ return nextItem.type !== "variable";
1754
+ }
1755
+ if (nextItem.type === "comment") {
1756
+ return nextItem.lineNumber - entry.lineNumber > 1;
1757
+ }
1758
+ return true;
1759
+ };
1739
1760
  switch (entry.type) {
1740
1761
  case "comment":
1741
1762
  lines.push(printComment(entry.item));
1742
1763
  break;
1743
1764
  case "config":
1744
1765
  lines.push(printConfig(entry.item));
1745
- lines.push("");
1746
1766
  break;
1747
1767
  case "graphqlSchema":
1748
1768
  lines.push(printGraphQLSchema(entry.item));
1749
- lines.push("");
1750
1769
  break;
1751
1770
  case "query":
1752
1771
  lines.push(printQueryResolver(entry.item));
1753
- lines.push("");
1754
1772
  break;
1755
1773
  case "mutation":
1756
1774
  lines.push(printMutationResolver(entry.item));
1757
- lines.push("");
1758
1775
  break;
1759
1776
  case "resolver":
1760
1777
  lines.push(printTypeResolver(entry.item));
1761
- lines.push("");
1762
1778
  break;
1763
1779
  case "route":
1764
1780
  lines.push(printRoute(entry.item));
1765
- lines.push("");
1766
1781
  break;
1767
1782
  case "pipeline":
1768
1783
  lines.push(printPipeline(entry.item));
1769
- lines.push("");
1770
1784
  break;
1771
1785
  case "variable":
1772
1786
  lines.push(printVariable(entry.item));
1773
- const nextNonVariable = allItems.slice(index + 1).find((item) => item.type !== "variable");
1774
- if (nextNonVariable) lines.push("");
1775
1787
  break;
1776
1788
  case "describe":
1777
1789
  lines.push(printDescribe(entry.item));
1778
- lines.push("");
1779
1790
  break;
1780
1791
  }
1792
+ if (shouldAddBlankLine()) {
1793
+ lines.push("");
1794
+ }
1781
1795
  });
1782
1796
  return lines.join("\n").trim() + "\n";
1783
1797
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "2.0.44",
3
+ "version": "2.0.46",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",