@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/dist/index.d.ts CHANGED
@@ -478,6 +478,23 @@ declare type FuzzinessExpression = number;
478
478
  * If the prefix type is set to "disabled" (the default), the search only matches full words. If the prefix type is set to "phrase", the search will return results that match prefixes of the search phrase.
479
479
  */
480
480
  declare type PrefixExpression = 'phrase' | 'disabled';
481
+ /**
482
+ * The target expression is used to filter the search results by the target columns.
483
+ */
484
+ declare type TargetExpression = (string | {
485
+ /**
486
+ * The name of the column.
487
+ */
488
+ column: string;
489
+ /**
490
+ * The weight of the column.
491
+ *
492
+ * @default 1
493
+ * @maximum 10
494
+ * @minimum 1
495
+ */
496
+ weight?: number;
497
+ })[];
481
498
  /**
482
499
  * @minProperties 1
483
500
  */
@@ -816,6 +833,7 @@ type schemas_SortExpression = SortExpression;
816
833
  type schemas_SortOrder = SortOrder;
817
834
  type schemas_FuzzinessExpression = FuzzinessExpression;
818
835
  type schemas_PrefixExpression = PrefixExpression;
836
+ type schemas_TargetExpression = TargetExpression;
819
837
  type schemas_FilterExpression = FilterExpression;
820
838
  type schemas_SummaryExpressionList = SummaryExpressionList;
821
839
  type schemas_SummaryExpression = SummaryExpression;
@@ -891,6 +909,7 @@ declare namespace schemas {
891
909
  schemas_SortOrder as SortOrder,
892
910
  schemas_FuzzinessExpression as FuzzinessExpression,
893
911
  schemas_PrefixExpression as PrefixExpression,
912
+ schemas_TargetExpression as TargetExpression,
894
913
  schemas_FilterExpression as FilterExpression,
895
914
  schemas_SummaryExpressionList as SummaryExpressionList,
896
915
  schemas_SummaryExpression as SummaryExpression,
@@ -970,10 +989,11 @@ declare type QueryResponse = {
970
989
  meta: RecordsMetadata;
971
990
  };
972
991
  declare type SummarizeResponse = {
973
- summary: Record<string, any>[];
992
+ summaries: Record<string, any>[];
974
993
  };
975
994
  declare type SearchResponse = {
976
995
  records: XataRecord$1[];
996
+ warning?: string;
977
997
  };
978
998
  /**
979
999
  * @example {"migrationID":"mig_c7m19ilcefoebpqj12p0"}
@@ -3825,8 +3845,8 @@ declare type QueryTableVariables = {
3825
3845
  *
3826
3846
  * ### Pagination
3827
3847
  *
3828
- * We offer cursor pagination and offset pagination. The offset pagination is limited
3829
- * in the amount of data it can retrieve, so we recommend the cursor pagination if you have more than 1000 records.
3848
+ * We offer cursor pagination and offset pagination. For queries that are expected to return more than 1000 records,
3849
+ * cursor pagination is needed in order to retrieve all of their results. The offset pagination method is limited to 1000 records.
3830
3850
  *
3831
3851
  * Example of size + offset pagination:
3832
3852
  *
@@ -3955,6 +3975,7 @@ declare type SearchTableRequestBody = {
3955
3975
  */
3956
3976
  query: string;
3957
3977
  fuzziness?: FuzzinessExpression;
3978
+ target?: TargetExpression;
3958
3979
  prefix?: PrefixExpression;
3959
3980
  filter?: FilterExpression;
3960
3981
  highlight?: HighlightExpression;
@@ -3999,6 +4020,7 @@ declare type SearchBranchRequestBody = {
3999
4020
  */
4000
4021
  table: string;
4001
4022
  filter?: FilterExpression;
4023
+ target?: TargetExpression;
4002
4024
  boosters?: BoosterExpression[];
4003
4025
  })[];
4004
4026
  /**
@@ -4560,6 +4582,21 @@ declare type Boosters<O extends XataRecord> = Values<{
4560
4582
  } : never;
4561
4583
  }>;
4562
4584
 
4585
+ declare type TargetColumn<T extends XataRecord> = SelectableColumn<T> | {
4586
+ /**
4587
+ * The name of the column.
4588
+ */
4589
+ column: SelectableColumn<T>;
4590
+ /**
4591
+ * The weight of the column.
4592
+ *
4593
+ * @default 1
4594
+ * @maximum 10
4595
+ * @minimum 1
4596
+ */
4597
+ weight?: number;
4598
+ };
4599
+
4563
4600
  declare type SearchOptions<Schemas extends Record<string, BaseData>, Tables extends StringKeys<Schemas>> = {
4564
4601
  fuzziness?: FuzzinessExpression;
4565
4602
  prefix?: PrefixExpression;
@@ -4567,6 +4604,7 @@ declare type SearchOptions<Schemas extends Record<string, BaseData>, Tables exte
4567
4604
  tables?: Array<Tables | Values<{
4568
4605
  [Model in GetArrayInnerType<NonNullable<Tables[]>>]: {
4569
4606
  table: Model;
4607
+ target?: TargetColumn<Schemas[Model] & XataRecord>[];
4570
4608
  filter?: Filter<SelectedPick<Schemas[Model] & XataRecord, ['*']>>;
4571
4609
  boosters?: Boosters<Schemas[Model] & XataRecord>[];
4572
4610
  };
package/dist/index.mjs CHANGED
@@ -150,7 +150,7 @@ function getFetchImplementation(userFetch) {
150
150
  return fetchImpl;
151
151
  }
152
152
 
153
- const VERSION = "0.18.1";
153
+ const VERSION = "0.18.3";
154
154
 
155
155
  class ErrorWithCause extends Error {
156
156
  constructor(message, options) {
@@ -1690,7 +1690,7 @@ class RestRepository extends Query {
1690
1690
  ...fetchProps
1691
1691
  });
1692
1692
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1693
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1693
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1694
1694
  } catch (e) {
1695
1695
  if (isObject(e) && e.status === 404) {
1696
1696
  return null;
@@ -1836,7 +1836,7 @@ class RestRepository extends Query {
1836
1836
  ...fetchProps
1837
1837
  });
1838
1838
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1839
- return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1839
+ return records.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, ["*"]));
1840
1840
  });
1841
1841
  }
1842
1842
  async query(query) {
@@ -1858,7 +1858,9 @@ 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
- const records = objects.map((record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record));
1861
+ const records = objects.map(
1862
+ (record) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), record, data.columns ?? ["*"])
1863
+ );
1862
1864
  await __privateMethod$2(this, _setCacheQuery, setCacheQuery_fn).call(this, query, meta, records);
1863
1865
  return new Page(query, meta, records);
1864
1866
  });
@@ -1885,7 +1887,7 @@ insertRecordWithoutId_fn = async function(object, columns = ["*"]) {
1885
1887
  ...fetchProps
1886
1888
  });
1887
1889
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1888
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1890
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1889
1891
  };
1890
1892
  _insertRecordWithId = new WeakSet();
1891
1893
  insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
@@ -1903,7 +1905,7 @@ insertRecordWithId_fn = async function(recordId, object, columns = ["*"]) {
1903
1905
  ...fetchProps
1904
1906
  });
1905
1907
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1906
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1908
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1907
1909
  };
1908
1910
  _bulkInsertTableRecords = new WeakSet();
1909
1911
  bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
@@ -1919,7 +1921,7 @@ bulkInsertTableRecords_fn = async function(objects, columns = ["*"]) {
1919
1921
  throw new Error("Request included columns but server didn't include them");
1920
1922
  }
1921
1923
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1922
- return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item));
1924
+ return response.records?.map((item) => initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), item, columns));
1923
1925
  };
1924
1926
  _updateRecordWithID = new WeakSet();
1925
1927
  updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
@@ -1933,7 +1935,7 @@ updateRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1933
1935
  ...fetchProps
1934
1936
  });
1935
1937
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1936
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1938
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1937
1939
  } catch (e) {
1938
1940
  if (isObject(e) && e.status === 404) {
1939
1941
  return null;
@@ -1951,7 +1953,7 @@ upsertRecordWithID_fn = async function(recordId, object, columns = ["*"]) {
1951
1953
  ...fetchProps
1952
1954
  });
1953
1955
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1954
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1956
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1955
1957
  };
1956
1958
  _deleteRecord = new WeakSet();
1957
1959
  deleteRecord_fn = async function(recordId, columns = ["*"]) {
@@ -1963,7 +1965,7 @@ deleteRecord_fn = async function(recordId, columns = ["*"]) {
1963
1965
  ...fetchProps
1964
1966
  });
1965
1967
  const schemaTables = await __privateMethod$2(this, _getSchemaTables$1, getSchemaTables_fn$1).call(this);
1966
- return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response);
1968
+ return initObject(__privateGet$4(this, _db), schemaTables, __privateGet$4(this, _table), response, columns);
1967
1969
  } catch (e) {
1968
1970
  if (isObject(e) && e.status === 404) {
1969
1971
  return null;
@@ -2006,7 +2008,7 @@ const transformObjectLinks = (object) => {
2006
2008
  return { ...acc, [key]: isIdentifiable(value) ? value.id : value };
2007
2009
  }, {});
2008
2010
  };
2009
- const initObject = (db, schemaTables, table, object) => {
2011
+ const initObject = (db, schemaTables, table, object, selectedColumns) => {
2010
2012
  const result = {};
2011
2013
  const { xata, ...rest } = object ?? {};
2012
2014
  Object.assign(result, rest);
@@ -2014,6 +2016,8 @@ const initObject = (db, schemaTables, table, object) => {
2014
2016
  if (!columns)
2015
2017
  console.error(`Table ${table} not found in schema`);
2016
2018
  for (const column of columns ?? []) {
2019
+ if (!isValidColumn(selectedColumns, column))
2020
+ continue;
2017
2021
  const value = result[column.name];
2018
2022
  switch (column.type) {
2019
2023
  case "datetime": {
@@ -2030,7 +2034,17 @@ const initObject = (db, schemaTables, table, object) => {
2030
2034
  if (!linkTable) {
2031
2035
  console.error(`Failed to parse link for field ${column.name}`);
2032
2036
  } else if (isObject(value)) {
2033
- result[column.name] = initObject(db, schemaTables, linkTable, value);
2037
+ const selectedLinkColumns = selectedColumns.reduce((acc, item) => {
2038
+ if (item === column.name) {
2039
+ return [...acc, "*"];
2040
+ }
2041
+ if (item.startsWith(`${column.name}.`)) {
2042
+ const [, ...path] = item.split(".");
2043
+ return [...acc, path.join(".")];
2044
+ }
2045
+ return acc;
2046
+ }, []);
2047
+ result[column.name] = initObject(db, schemaTables, linkTable, value, selectedLinkColumns);
2034
2048
  } else {
2035
2049
  result[column.name] = null;
2036
2050
  }
@@ -2078,6 +2092,15 @@ function cleanFilter(filter) {
2078
2092
  const values = Object.values(filter).filter(Boolean).filter((value) => Array.isArray(value) ? value.length > 0 : true);
2079
2093
  return values.length > 0 ? filter : void 0;
2080
2094
  }
2095
+ function isValidColumn(columns, column) {
2096
+ if (columns.includes("*"))
2097
+ return true;
2098
+ if (column.type === "link") {
2099
+ const linkColumns = columns.filter((item) => item.startsWith(column.name));
2100
+ return linkColumns.length > 0;
2101
+ }
2102
+ return columns.includes(column.name);
2103
+ }
2081
2104
 
2082
2105
  var __accessCheck$3 = (obj, member, msg) => {
2083
2106
  if (!member.has(obj))
@@ -2243,7 +2266,7 @@ class SearchPlugin extends XataPlugin {
2243
2266
  const schemaTables = await __privateMethod$1(this, _getSchemaTables, getSchemaTables_fn).call(this, getFetchProps);
2244
2267
  return records.map((record) => {
2245
2268
  const { table = "orphan" } = record.xata;
2246
- return { table, record: initObject(this.db, schemaTables, table, record) };
2269
+ return { table, record: initObject(this.db, schemaTables, table, record, ["*"]) };
2247
2270
  });
2248
2271
  },
2249
2272
  byTable: async (query, options = {}) => {
@@ -2252,7 +2275,7 @@ class SearchPlugin extends XataPlugin {
2252
2275
  return records.reduce((acc, record) => {
2253
2276
  const { table = "orphan" } = record.xata;
2254
2277
  const items = acc[table] ?? [];
2255
- const item = initObject(this.db, schemaTables, table, record);
2278
+ const item = initObject(this.db, schemaTables, table, record, ["*"]);
2256
2279
  return { ...acc, [table]: [...items, item] };
2257
2280
  }, {});
2258
2281
  }