convex 0.9.0 → 0.9.1

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.
@@ -212,7 +212,7 @@ var convex = (() => {
212
212
  var v4_default = v4;
213
213
 
214
214
  // src/index.ts
215
- var version = "0.9.0";
215
+ var version = "0.9.1";
216
216
 
217
217
  // src/values/values.ts
218
218
  var Base64 = __toESM(require_base64_js());
@@ -1711,26 +1711,39 @@ var convex = (() => {
1711
1711
  }
1712
1712
  query(name) {
1713
1713
  return async (...args) => {
1714
- const argsJSON = JSON.stringify(convexToJson(args));
1715
- const argsComponent = encodeURIComponent(argsJSON);
1716
- const url = `${this.address}/${version}/udf?path=${name}&args=${argsComponent}`;
1717
- const headers = this.auth ? { Authorization: `Bearer ${this.auth}` } : {};
1718
- const response = await fetch(url, {
1719
- credentials: "include",
1720
- headers
1714
+ const body = JSON.stringify({
1715
+ path: name,
1716
+ args: convexToJson(args),
1717
+ debug: this.debug
1718
+ });
1719
+ const headers = {
1720
+ "Content-Type": "application/json",
1721
+ "Convex-Client": `npm-${version}`
1722
+ };
1723
+ if (this.auth) {
1724
+ headers["Authorization"] = `Bearer ${this.auth}`;
1725
+ }
1726
+ const response = await fetch(`${this.address}/query`, {
1727
+ body,
1728
+ method: "POST",
1729
+ headers,
1730
+ credentials: "include"
1721
1731
  });
1722
1732
  if (!response.ok && response.status !== STATUS_CODE_UDF_FAILED) {
1723
1733
  throw new Error(await response.text());
1724
1734
  }
1725
1735
  const respJSON = await response.json();
1726
- const value = jsonToConvex(respJSON.value);
1727
- for (const line of respJSON.logs) {
1736
+ for (const line of respJSON.logLines ?? []) {
1728
1737
  logToConsole("info", "query", name, line);
1729
1738
  }
1730
- if (!respJSON.success) {
1731
- throw createError("query", name, value);
1739
+ switch (respJSON.status) {
1740
+ case "success":
1741
+ return jsonToConvex(respJSON.value);
1742
+ case "error":
1743
+ throw new Error(respJSON.errorMessage);
1744
+ default:
1745
+ throw new Error(`Invalid response: ${JSON.stringify(respJSON)}`);
1732
1746
  }
1733
- return value;
1734
1747
  };
1735
1748
  }
1736
1749
  mutation(name) {
@@ -1738,15 +1751,16 @@ var convex = (() => {
1738
1751
  const body = JSON.stringify({
1739
1752
  path: name,
1740
1753
  args: convexToJson(args),
1741
- tokens: []
1754
+ debug: this.debug
1742
1755
  });
1743
1756
  const headers = {
1744
- "Content-Type": "application/json"
1757
+ "Content-Type": "application/json",
1758
+ "Convex-Client": `npm-${version}`
1745
1759
  };
1746
1760
  if (this.auth) {
1747
1761
  headers["Authorization"] = `Bearer ${this.auth}`;
1748
1762
  }
1749
- const response = await fetch(`${this.address}/${version}/udf`, {
1763
+ const response = await fetch(`${this.address}/mutation`, {
1750
1764
  body,
1751
1765
  method: "POST",
1752
1766
  headers,
@@ -1756,14 +1770,17 @@ var convex = (() => {
1756
1770
  throw new Error(await response.text());
1757
1771
  }
1758
1772
  const respJSON = await response.json();
1759
- const value = jsonToConvex(respJSON.value);
1760
- for (const line of respJSON.logs) {
1773
+ for (const line of respJSON.logLines ?? []) {
1761
1774
  logToConsole("info", "mutation", name, line);
1762
1775
  }
1763
- if (!respJSON.success) {
1764
- throw createError("mutation", name, value);
1776
+ switch (respJSON.status) {
1777
+ case "success":
1778
+ return jsonToConvex(respJSON.value);
1779
+ case "error":
1780
+ throw new Error(respJSON.errorMessage);
1781
+ default:
1782
+ throw new Error(`Invalid response: ${JSON.stringify(respJSON)}`);
1765
1783
  }
1766
- return value;
1767
1784
  };
1768
1785
  }
1769
1786
  action(name) {
@@ -1774,7 +1791,8 @@ var convex = (() => {
1774
1791
  debug: this.debug
1775
1792
  });
1776
1793
  const headers = {
1777
- "Content-Type": "application/json"
1794
+ "Content-Type": "application/json",
1795
+ "Convex-Client": `npm-${version}`
1778
1796
  };
1779
1797
  if (this.auth) {
1780
1798
  headers["Authorization"] = `Bearer ${this.auth}`;
@@ -1794,8 +1812,7 @@ var convex = (() => {
1794
1812
  }
1795
1813
  switch (respJSON.status) {
1796
1814
  case "success":
1797
- jsonToConvex(respJSON.value);
1798
- return respJSON.value;
1815
+ return jsonToConvex(respJSON.value);
1799
1816
  case "error":
1800
1817
  throw new Error(respJSON.errorMessage);
1801
1818
  default: