webpipe-js 2.0.43 → 2.0.45

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,7 +1648,8 @@ 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(/\.(.*?)$/, " $1");
1652
+ return `${indent}with mock ${target} returning \`${mock.returnValue}\``;
1652
1653
  }
1653
1654
  function printCondition(condition, indent = " ") {
1654
1655
  const condType = condition.conditionType.toLowerCase();
@@ -1693,17 +1694,25 @@ function printTest(test) {
1693
1694
  lines.push("");
1694
1695
  }
1695
1696
  lines.push(` when ${formatWhen(test.when)}`);
1696
- if (test.input) {
1697
- lines.push(` with input \`${test.input}\``);
1697
+ let hasWithClause = false;
1698
+ if (test.headers) {
1699
+ lines.push(` with headers \`${test.headers}\``);
1700
+ hasWithClause = true;
1698
1701
  }
1699
1702
  if (test.body) {
1700
- lines.push(` with body \`${test.body}\``);
1703
+ const prefix = hasWithClause ? "and with" : "with";
1704
+ lines.push(` ${prefix} body \`${test.body}\``);
1705
+ hasWithClause = true;
1701
1706
  }
1702
- if (test.headers) {
1703
- lines.push(` with headers \`${test.headers}\``);
1707
+ if (test.input) {
1708
+ const prefix = hasWithClause ? "and with" : "with";
1709
+ lines.push(` ${prefix} input \`${test.input}\``);
1710
+ hasWithClause = true;
1704
1711
  }
1705
1712
  if (test.cookies) {
1706
- lines.push(` with cookies \`${test.cookies}\``);
1713
+ const prefix = hasWithClause ? "and with" : "with";
1714
+ lines.push(` ${prefix} cookies \`${test.cookies}\``);
1715
+ hasWithClause = true;
1707
1716
  }
1708
1717
  test.conditions.forEach((condition) => {
1709
1718
  lines.push(printCondition(condition));
@@ -1781,48 +1790,56 @@ function prettyPrint(program) {
1781
1790
  });
1782
1791
  allItems.sort((a, b) => a.lineNumber - b.lineNumber);
1783
1792
  allItems.forEach((entry, index) => {
1793
+ const nextItem = allItems[index + 1];
1794
+ const shouldAddBlankLine = () => {
1795
+ if (!nextItem) return false;
1796
+ if (entry.type === "comment") {
1797
+ if (nextItem.type === "comment") return false;
1798
+ return nextItem.lineNumber - entry.lineNumber > 1;
1799
+ }
1800
+ if (entry.type === "variable") {
1801
+ return nextItem.type !== "variable";
1802
+ }
1803
+ if (nextItem.type === "comment") {
1804
+ return nextItem.lineNumber - entry.lineNumber > 1;
1805
+ }
1806
+ return true;
1807
+ };
1784
1808
  switch (entry.type) {
1785
1809
  case "comment":
1786
1810
  lines.push(printComment(entry.item));
1787
1811
  break;
1788
1812
  case "config":
1789
1813
  lines.push(printConfig(entry.item));
1790
- lines.push("");
1791
1814
  break;
1792
1815
  case "graphqlSchema":
1793
1816
  lines.push(printGraphQLSchema(entry.item));
1794
- lines.push("");
1795
1817
  break;
1796
1818
  case "query":
1797
1819
  lines.push(printQueryResolver(entry.item));
1798
- lines.push("");
1799
1820
  break;
1800
1821
  case "mutation":
1801
1822
  lines.push(printMutationResolver(entry.item));
1802
- lines.push("");
1803
1823
  break;
1804
1824
  case "resolver":
1805
1825
  lines.push(printTypeResolver(entry.item));
1806
- lines.push("");
1807
1826
  break;
1808
1827
  case "route":
1809
1828
  lines.push(printRoute(entry.item));
1810
- lines.push("");
1811
1829
  break;
1812
1830
  case "pipeline":
1813
1831
  lines.push(printPipeline(entry.item));
1814
- lines.push("");
1815
1832
  break;
1816
1833
  case "variable":
1817
1834
  lines.push(printVariable(entry.item));
1818
- const nextNonVariable = allItems.slice(index + 1).find((item) => item.type !== "variable");
1819
- if (nextNonVariable) lines.push("");
1820
1835
  break;
1821
1836
  case "describe":
1822
1837
  lines.push(printDescribe(entry.item));
1823
- lines.push("");
1824
1838
  break;
1825
1839
  }
1840
+ if (shouldAddBlankLine()) {
1841
+ lines.push("");
1842
+ }
1826
1843
  });
1827
1844
  return lines.join("\n").trim() + "\n";
1828
1845
  }
package/dist/index.mjs CHANGED
@@ -1595,7 +1595,8 @@ 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(/\.(.*?)$/, " $1");
1599
+ return `${indent}with mock ${target} returning \`${mock.returnValue}\``;
1599
1600
  }
1600
1601
  function printCondition(condition, indent = " ") {
1601
1602
  const condType = condition.conditionType.toLowerCase();
@@ -1640,17 +1641,25 @@ function printTest(test) {
1640
1641
  lines.push("");
1641
1642
  }
1642
1643
  lines.push(` when ${formatWhen(test.when)}`);
1643
- if (test.input) {
1644
- lines.push(` with input \`${test.input}\``);
1644
+ let hasWithClause = false;
1645
+ if (test.headers) {
1646
+ lines.push(` with headers \`${test.headers}\``);
1647
+ hasWithClause = true;
1645
1648
  }
1646
1649
  if (test.body) {
1647
- lines.push(` with body \`${test.body}\``);
1650
+ const prefix = hasWithClause ? "and with" : "with";
1651
+ lines.push(` ${prefix} body \`${test.body}\``);
1652
+ hasWithClause = true;
1648
1653
  }
1649
- if (test.headers) {
1650
- lines.push(` with headers \`${test.headers}\``);
1654
+ if (test.input) {
1655
+ const prefix = hasWithClause ? "and with" : "with";
1656
+ lines.push(` ${prefix} input \`${test.input}\``);
1657
+ hasWithClause = true;
1651
1658
  }
1652
1659
  if (test.cookies) {
1653
- lines.push(` with cookies \`${test.cookies}\``);
1660
+ const prefix = hasWithClause ? "and with" : "with";
1661
+ lines.push(` ${prefix} cookies \`${test.cookies}\``);
1662
+ hasWithClause = true;
1654
1663
  }
1655
1664
  test.conditions.forEach((condition) => {
1656
1665
  lines.push(printCondition(condition));
@@ -1728,48 +1737,56 @@ function prettyPrint(program) {
1728
1737
  });
1729
1738
  allItems.sort((a, b) => a.lineNumber - b.lineNumber);
1730
1739
  allItems.forEach((entry, index) => {
1740
+ const nextItem = allItems[index + 1];
1741
+ const shouldAddBlankLine = () => {
1742
+ if (!nextItem) return false;
1743
+ if (entry.type === "comment") {
1744
+ if (nextItem.type === "comment") return false;
1745
+ return nextItem.lineNumber - entry.lineNumber > 1;
1746
+ }
1747
+ if (entry.type === "variable") {
1748
+ return nextItem.type !== "variable";
1749
+ }
1750
+ if (nextItem.type === "comment") {
1751
+ return nextItem.lineNumber - entry.lineNumber > 1;
1752
+ }
1753
+ return true;
1754
+ };
1731
1755
  switch (entry.type) {
1732
1756
  case "comment":
1733
1757
  lines.push(printComment(entry.item));
1734
1758
  break;
1735
1759
  case "config":
1736
1760
  lines.push(printConfig(entry.item));
1737
- lines.push("");
1738
1761
  break;
1739
1762
  case "graphqlSchema":
1740
1763
  lines.push(printGraphQLSchema(entry.item));
1741
- lines.push("");
1742
1764
  break;
1743
1765
  case "query":
1744
1766
  lines.push(printQueryResolver(entry.item));
1745
- lines.push("");
1746
1767
  break;
1747
1768
  case "mutation":
1748
1769
  lines.push(printMutationResolver(entry.item));
1749
- lines.push("");
1750
1770
  break;
1751
1771
  case "resolver":
1752
1772
  lines.push(printTypeResolver(entry.item));
1753
- lines.push("");
1754
1773
  break;
1755
1774
  case "route":
1756
1775
  lines.push(printRoute(entry.item));
1757
- lines.push("");
1758
1776
  break;
1759
1777
  case "pipeline":
1760
1778
  lines.push(printPipeline(entry.item));
1761
- lines.push("");
1762
1779
  break;
1763
1780
  case "variable":
1764
1781
  lines.push(printVariable(entry.item));
1765
- const nextNonVariable = allItems.slice(index + 1).find((item) => item.type !== "variable");
1766
- if (nextNonVariable) lines.push("");
1767
1782
  break;
1768
1783
  case "describe":
1769
1784
  lines.push(printDescribe(entry.item));
1770
- lines.push("");
1771
1785
  break;
1772
1786
  }
1787
+ if (shouldAddBlankLine()) {
1788
+ lines.push("");
1789
+ }
1773
1790
  });
1774
1791
  return lines.join("\n").trim() + "\n";
1775
1792
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "2.0.43",
3
+ "version": "2.0.45",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",