webpipe-js 2.0.44 → 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();
@@ -1789,48 +1790,56 @@ function prettyPrint(program) {
1789
1790
  });
1790
1791
  allItems.sort((a, b) => a.lineNumber - b.lineNumber);
1791
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
+ };
1792
1808
  switch (entry.type) {
1793
1809
  case "comment":
1794
1810
  lines.push(printComment(entry.item));
1795
1811
  break;
1796
1812
  case "config":
1797
1813
  lines.push(printConfig(entry.item));
1798
- lines.push("");
1799
1814
  break;
1800
1815
  case "graphqlSchema":
1801
1816
  lines.push(printGraphQLSchema(entry.item));
1802
- lines.push("");
1803
1817
  break;
1804
1818
  case "query":
1805
1819
  lines.push(printQueryResolver(entry.item));
1806
- lines.push("");
1807
1820
  break;
1808
1821
  case "mutation":
1809
1822
  lines.push(printMutationResolver(entry.item));
1810
- lines.push("");
1811
1823
  break;
1812
1824
  case "resolver":
1813
1825
  lines.push(printTypeResolver(entry.item));
1814
- lines.push("");
1815
1826
  break;
1816
1827
  case "route":
1817
1828
  lines.push(printRoute(entry.item));
1818
- lines.push("");
1819
1829
  break;
1820
1830
  case "pipeline":
1821
1831
  lines.push(printPipeline(entry.item));
1822
- lines.push("");
1823
1832
  break;
1824
1833
  case "variable":
1825
1834
  lines.push(printVariable(entry.item));
1826
- const nextNonVariable = allItems.slice(index + 1).find((item) => item.type !== "variable");
1827
- if (nextNonVariable) lines.push("");
1828
1835
  break;
1829
1836
  case "describe":
1830
1837
  lines.push(printDescribe(entry.item));
1831
- lines.push("");
1832
1838
  break;
1833
1839
  }
1840
+ if (shouldAddBlankLine()) {
1841
+ lines.push("");
1842
+ }
1834
1843
  });
1835
1844
  return lines.join("\n").trim() + "\n";
1836
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();
@@ -1736,48 +1737,56 @@ function prettyPrint(program) {
1736
1737
  });
1737
1738
  allItems.sort((a, b) => a.lineNumber - b.lineNumber);
1738
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
+ };
1739
1755
  switch (entry.type) {
1740
1756
  case "comment":
1741
1757
  lines.push(printComment(entry.item));
1742
1758
  break;
1743
1759
  case "config":
1744
1760
  lines.push(printConfig(entry.item));
1745
- lines.push("");
1746
1761
  break;
1747
1762
  case "graphqlSchema":
1748
1763
  lines.push(printGraphQLSchema(entry.item));
1749
- lines.push("");
1750
1764
  break;
1751
1765
  case "query":
1752
1766
  lines.push(printQueryResolver(entry.item));
1753
- lines.push("");
1754
1767
  break;
1755
1768
  case "mutation":
1756
1769
  lines.push(printMutationResolver(entry.item));
1757
- lines.push("");
1758
1770
  break;
1759
1771
  case "resolver":
1760
1772
  lines.push(printTypeResolver(entry.item));
1761
- lines.push("");
1762
1773
  break;
1763
1774
  case "route":
1764
1775
  lines.push(printRoute(entry.item));
1765
- lines.push("");
1766
1776
  break;
1767
1777
  case "pipeline":
1768
1778
  lines.push(printPipeline(entry.item));
1769
- lines.push("");
1770
1779
  break;
1771
1780
  case "variable":
1772
1781
  lines.push(printVariable(entry.item));
1773
- const nextNonVariable = allItems.slice(index + 1).find((item) => item.type !== "variable");
1774
- if (nextNonVariable) lines.push("");
1775
1782
  break;
1776
1783
  case "describe":
1777
1784
  lines.push(printDescribe(entry.item));
1778
- lines.push("");
1779
1785
  break;
1780
1786
  }
1787
+ if (shouldAddBlankLine()) {
1788
+ lines.push("");
1789
+ }
1781
1790
  });
1782
1791
  return lines.join("\n").trim() + "\n";
1783
1792
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpipe-js",
3
- "version": "2.0.44",
3
+ "version": "2.0.45",
4
4
  "description": "Web Pipe parser",
5
5
  "license": "ISC",
6
6
  "author": "William Cotton",