@xata.io/client 0.18.1 → 0.18.3

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,17 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.18.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#639](https://github.com/xataio/client-ts/pull/639) [`50fb3c0`](https://github.com/xataio/client-ts/commit/50fb3c0a1cffd03a16cc8b1b21454ea816f2edbb) Thanks [@SferaDev](https://github.com/SferaDev)! - Do not return null for columns not selected
8
+
9
+ ## 0.18.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#635](https://github.com/xataio/client-ts/pull/635) [`713f9b2`](https://github.com/xataio/client-ts/commit/713f9b2773be99c17d3fcb663e24fe096fa3da48) Thanks [@SferaDev](https://github.com/SferaDev)! - [Search] Add target columns
14
+
3
15
  ## 0.18.1
4
16
 
5
17
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -172,7 +172,7 @@ function getFetchImplementation(userFetch) {
172
172
  return fetchImpl;
173
173
  }
174
174
 
175
- const VERSION = "0.18.1";
175
+ const VERSION = "0.18.3";
176
176
 
177
177
  class ErrorWithCause extends Error {
178
178
  constructor(message, options) {
@@ -1712,7 +1712,7 @@ class RestRepository extends Query {
1712
1712
  ...fetchProps
1713
1713
  });
1714
1714
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1715
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1715
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1716
1716
  } catch (e) {
1717
1717
  if (isObject(e) && e.status === 404) {
1718
1718
  return null;
@@ -1858,7 +1858,7 @@ class RestRepository extends Query {
1858
1858
  ...fetchProps
1859
1859
  });
1860
1860
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1861
- return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1861
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
1862
1862
  });
1863
1863
  }
1864
1864
  async query(query) {
@@ -1880,7 +1880,9 @@ class RestRepository extends Query {
1880
1880
  ...fetchProps
1881
1881
  });
1882
1882
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1883
- const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1883
+ const records = objects.map(
1884
+ (record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
1885
+ );
1884
1886
  await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1885
1887
  return new Page(query, meta, records);
1886
1888
  });
@@ -1907,7 +1909,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1907
1909
  ...fetchProps
1908
1910
  });
1909
1911
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1910
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1912
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1911
1913
  };
1912
1914
  _insertRecordWithId = new WeakSet();
1913
1915
  insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
@@ -1925,7 +1927,7 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
1925
1927
  ...fetchProps
1926
1928
  });
1927
1929
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1928
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1930
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1929
1931
  };
1930
1932
  _bulkInsertTableRecords = new WeakSet();
1931
1933
  bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
@@ -1941,7 +1943,7 @@ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1941
1943
  throw new Error("Request included columns but server didn't include them");
1942
1944
  }
1943
1945
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1944
- return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1946
+ return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
1945
1947
  };
1946
1948
  _updateRecordWithID = new WeakSet();
1947
1949
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
@@ -1955,7 +1957,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1955
1957
  ...fetchProps
1956
1958
  });
1957
1959
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1958
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1960
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1959
1961
  } catch (e) {
1960
1962
  if (isObject(e) && e.status === 404) {
1961
1963
  return null;
@@ -1973,7 +1975,7 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1973
1975
  ...fetchProps
1974
1976
  });
1975
1977
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1976
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1978
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1977
1979
  };
1978
1980
  _deleteRecord = new WeakSet();
1979
1981
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
@@ -1985,7 +1987,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
1985
1987
  ...fetchProps
1986
1988
  });
1987
1989
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1988
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1990
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1989
1991
  } catch (e) {
1990
1992
  if (isObject(e) && e.status === 404) {
1991
1993
  return null;
@@ -2028,7 +2030,7 @@ const transformObjectLinks = (object) => {
2028
2030
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
2029
2031
  }, {});
2030
2032
  };
2031
- const initObject = (db, schemaTables, table, object) => {
2033
+ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2032
2034
  const result = {};
2033
2035
  const { xata, ...rest } = object ?? {};
2034
2036
  Object.assign(result, rest);
@@ -2036,6 +2038,8 @@ const initObject = (db, schemaTables, table, object) => {
2036
2038
  if (!columns)
2037
2039
  console.error(`Table ${table} not found in schema`);
2038
2040
  for (const column of columns ?? []) {
2041
+ if (!isValidColumn(selectedColumns, column))
2042
+ continue;
2039
2043
  const value = result[column.name];
2040
2044
  switch (column.type) {
2041
2045
  case "datetime": {
@@ -2052,7 +2056,17 @@ const initObject = (db, schemaTables, table, object) => {
2052
2056
  if (!linkTable) {
2053
2057
  console.error(`Failed to parse link for field ${column.name}`);
2054
2058
  } else if (isObject(value)) {
2055
- result[column.name] = initObject(db, schemaTables, linkTable, value);
2059
+ const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
2060
+ if (item === column.name) {
2061
+ return [...acc, "*"];
2062
+ }
2063
+ if (item.startsWith(`${column.name}.`)) {
2064
+ const [, ...path] = item.split(".");
2065
+ return [...acc, path.join(".")];
2066
+ }
2067
+ return acc;
2068
+ }, []);
2069
+ result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2056
2070
  } else {
2057
2071
  result[column.name] = null;
2058
2072
  }
@@ -2100,6 +2114,15 @@ function cleanFilter(filter) {
2100
2114
  const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
2101
2115
  return values.length > 0 ? filter : void 0;
2102
2116
  }
2117
+ function isValidColumn(columns, column) {
2118
+ if (columns.includes("*"))
2119
+ return true;
2120
+ if (column.type === "link") {
2121
+ const linkColumns = columns.filter((item) => item.startsWith(column.name));
2122
+ return linkColumns.length > 0;
2123
+ }
2124
+ return columns.includes(column.name);
2125
+ }
2103
2126
 
2104
2127
  var __accessCheck$3 = (obj, member, msg) => {
2105
2128
  if (!member.has(obj))
@@ -2265,7 +2288,7 @@ class SearchPlugin extends XataPlugin {
2265
2288
  const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
2266
2289
  return records.map((record) => {
2267
2290
  const { table = "orphan" } = record.xata;
2268
- return { table, record: initObject(this.db, schemaTables, table, record) };
2291
+ return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
2269
2292
  });
2270
2293
  },
2271
2294
  byTable: async (query, options = {}) => {
@@ -2274,7 +2297,7 @@ class SearchPlugin extends XataPlugin {
2274
2297
  return records.reduce((acc, record) => {
2275
2298
  const { table = "orphan" } = record.xata;
2276
2299
  const items = acc[table] ?? [];
2277
- const item = initObject(this.db, schemaTables, table, record);
2300
+ const item = initObject(this.db, schemaTables, table, record, ["*"]);
2278
2301
  return { ...acc, [table]: [...items, item] };
2279
2302
  }, {});
2280
2303
  }