@xata.io/client 0.18.2 → 0.18.4

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.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#650](https://github.com/xataio/client-ts/pull/650) [`b8d441f`](https://github.com/xataio/client-ts/commit/b8d441f80867322f41989d52c94bba230632782b) Thanks [@xata-bot](https://github.com/xata-bot)! - API: Rename listMigrationRequests to queryMigrationRequests
8
+
9
+ ## 0.18.3
10
+
11
+ ### Patch Changes
12
+
13
+ - [#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
14
+
3
15
  ## 0.18.2
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.2";
175
+ const VERSION = "0.18.4";
176
176
 
177
177
  class ErrorWithCause extends Error {
178
178
  constructor(message, options) {
@@ -417,7 +417,7 @@ const resolveBranch = (variables) => fetch$1({
417
417
  method: "get",
418
418
  ...variables
419
419
  });
420
- const listMigrationRequests = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/list", method: "post", ...variables });
420
+ const queryMigrationRequests = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations/query", method: "post", ...variables });
421
421
  const createMigrationRequest = (variables) => fetch$1({ url: "/dbs/{dbName}/migrations", method: "post", ...variables });
422
422
  const getMigrationRequest = (variables) => fetch$1({
423
423
  url: "/dbs/{dbName}/migrations/{mrNumber}",
@@ -595,7 +595,7 @@ const operationsByTag = {
595
595
  getBranchStats
596
596
  },
597
597
  migrationRequests: {
598
- listMigrationRequests,
598
+ queryMigrationRequests,
599
599
  createMigrationRequest,
600
600
  getMigrationRequest,
601
601
  updateMigrationRequest,
@@ -1134,8 +1134,8 @@ class MigrationRequestsApi {
1134
1134
  constructor(extraProps) {
1135
1135
  this.extraProps = extraProps;
1136
1136
  }
1137
- listMigrationRequests(workspace, database, options = {}) {
1138
- return operationsByTag.migrationRequests.listMigrationRequests({
1137
+ queryMigrationRequests(workspace, database, options = {}) {
1138
+ return operationsByTag.migrationRequests.queryMigrationRequests({
1139
1139
  pathParams: { workspace, dbName: database },
1140
1140
  body: options,
1141
1141
  ...this.extraProps
@@ -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
  }
@@ -2684,7 +2707,6 @@ exports.le = le;
2684
2707
  exports.lessEquals = lessEquals;
2685
2708
  exports.lessThan = lessThan;
2686
2709
  exports.lessThanEquals = lessThanEquals;
2687
- exports.listMigrationRequests = listMigrationRequests;
2688
2710
  exports.listMigrationRequestsCommits = listMigrationRequestsCommits;
2689
2711
  exports.lt = lt;
2690
2712
  exports.lte = lte;
@@ -2693,6 +2715,7 @@ exports.notExists = notExists;
2693
2715
  exports.operationsByTag = operationsByTag;
2694
2716
  exports.pattern = pattern;
2695
2717
  exports.previewBranchSchemaEdit = previewBranchSchemaEdit;
2718
+ exports.queryMigrationRequests = queryMigrationRequests;
2696
2719
  exports.queryTable = queryTable;
2697
2720
  exports.removeGitBranchesEntry = removeGitBranchesEntry;
2698
2721
  exports.removeWorkspaceMember = removeWorkspaceMember;