@xata.io/client 0.16.2 → 0.17.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.17.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#563](https://github.com/xataio/client-ts/pull/563) [`26e91d1`](https://github.com/xataio/client-ts/commit/26e91d1d84df082dedd7159271fc7c27ec87fefe) Thanks [@SferaDev](https://github.com/SferaDev)! - Return nulls on operations that can fail
8
+
9
+ * [#563](https://github.com/xataio/client-ts/pull/563) [`3332d43`](https://github.com/xataio/client-ts/commit/3332d43121367f61c8d87dfb7da2af65bd1c278f) Thanks [@SferaDev](https://github.com/SferaDev)! - Return object on delete operation
10
+
3
11
  ## 0.16.2
4
12
 
5
13
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -174,7 +174,7 @@ function getFetchImplementation(userFetch) {
174
174
  return fetchImpl;
175
175
  }
176
176
 
177
- const VERSION = "0.16.2";
177
+ const VERSION = "0.17.0";
178
178
 
179
179
  class ErrorWithCause extends Error {
180
180
  constructor(message, options) {
@@ -1470,16 +1470,16 @@ class RestRepository extends Query {
1470
1470
  if (Array.isArray(a)) {
1471
1471
  if (a.length === 0)
1472
1472
  return [];
1473
- const ids = a.map((item) => isString(item) ? item : item.id).filter((id2) => isString(id2));
1474
- const finalObjects = await this.getAll({ filter: { id: { $any: ids } }, columns });
1473
+ const ids = a.map((item) => extractId(item));
1474
+ const finalObjects = await this.getAll({ filter: { id: { $any: compact(ids) } }, columns });
1475
1475
  const dictionary = finalObjects.reduce((acc, object) => {
1476
1476
  acc[object.id] = object;
1477
1477
  return acc;
1478
1478
  }, {});
1479
- return ids.map((id2) => dictionary[id2] ?? null);
1479
+ return ids.map((id2) => dictionary[id2 ?? ""] ?? null);
1480
1480
  }
1481
- const id = isString(a) ? a : a.id;
1482
- if (isString(id)) {
1481
+ const id = extractId(a);
1482
+ if (id) {
1483
1483
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1484
1484
  try {
1485
1485
  const response = await getRecord({
@@ -1548,24 +1548,21 @@ class RestRepository extends Query {
1548
1548
  throw new Error("Invalid arguments for createOrUpdate method");
1549
1549
  });
1550
1550
  }
1551
- async delete(a) {
1551
+ async delete(a, b) {
1552
1552
  return __privateGet$4(this, _trace).call(this, "delete", async () => {
1553
1553
  if (Array.isArray(a)) {
1554
1554
  if (a.length === 0)
1555
- return;
1555
+ return [];
1556
1556
  if (a.length > 100) {
1557
1557
  console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1558
1558
  }
1559
- await Promise.all(a.map((id) => this.delete(id)));
1560
- return;
1559
+ return Promise.all(a.map((id) => this.delete(id, b)));
1561
1560
  }
1562
1561
  if (isString(a)) {
1563
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a);
1564
- return;
1562
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a, b);
1565
1563
  }
1566
1564
  if (isObject(a) && isString(a.id)) {
1567
- await __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id);
1568
- return;
1565
+ return __privateMethod$2(this, _deleteRecord, deleteRecord_fn).call(this, a.id, b);
1569
1566
  }
1570
1567
  throw new Error("Invalid arguments for delete method");
1571
1568
  });
@@ -1675,14 +1672,21 @@ _updateRecordWithID = new WeakSet();
1675
1672
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1676
1673
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1677
1674
  const record = transformObjectLinks(object);
1678
- const response = await updateRecordWithID({
1679
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1680
- queryParams: { columns },
1681
- body: record,
1682
- ...fetchProps
1683
- });
1684
- const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1685
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1675
+ try {
1676
+ const response = await updateRecordWithID({
1677
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1678
+ queryParams: { columns },
1679
+ body: record,
1680
+ ...fetchProps
1681
+ });
1682
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1683
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1684
+ } catch (e) {
1685
+ if (isObject(e) && e.status === 404) {
1686
+ return null;
1687
+ }
1688
+ throw e;
1689
+ }
1686
1690
  };
1687
1691
  _upsertRecordWithID = new WeakSet();
1688
1692
  upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
@@ -1697,12 +1701,22 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1697
1701
  return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1698
1702
  };
1699
1703
  _deleteRecord = new WeakSet();
1700
- deleteRecord_fn = async function(recordId) {
1704
+ deleteRecord_fn = async function(recordId, columns = ["*"]) {
1701
1705
  const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1702
- await deleteRecord({
1703
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1704
- ...fetchProps
1705
- });
1706
+ try {
1707
+ const response = await deleteRecord({
1708
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1709
+ queryParams: { columns },
1710
+ ...fetchProps
1711
+ });
1712
+ const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1713
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1714
+ } catch (e) {
1715
+ if (isObject(e) && e.status === 404) {
1716
+ return null;
1717
+ }
1718
+ throw e;
1719
+ }
1706
1720
  };
1707
1721
  _setCacheQuery = new WeakSet();
1708
1722
  setCacheQuery_fn = async function(query, meta, records) {
@@ -1790,6 +1804,13 @@ const initObject = (db, schemaTables, table, object) => {
1790
1804
  function isResponseWithRecords(value) {
1791
1805
  return isObject(value) && Array.isArray(value.records);
1792
1806
  }
1807
+ function extractId(value) {
1808
+ if (isString(value))
1809
+ return value;
1810
+ if (isObject(value) && isString(value.id))
1811
+ return value.id;
1812
+ return void 0;
1813
+ }
1793
1814
 
1794
1815
  var __accessCheck$3 = (obj, member, msg) => {
1795
1816
  if (!member.has(obj))