@xata.io/client 0.10.2 → 0.11.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,25 @@
1
1
  # @xata.io/client
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#322](https://github.com/xataio/client-ts/pull/322) [`bc64c28`](https://github.com/xataio/client-ts/commit/bc64c28fbfbb000c7190ac8092e2ef6a261df86f) Thanks [@SferaDev](https://github.com/SferaDev)! - Add filter support for cross-table search operations
8
+
9
+ ### Patch Changes
10
+
11
+ - [#327](https://github.com/xataio/client-ts/pull/327) [`505257c`](https://github.com/xataio/client-ts/commit/505257c0c42ca0c8beaf5c0f638037c576dcc43c) Thanks [@SferaDev](https://github.com/SferaDev)! - Allow reading multiple uids at the same time
12
+
13
+ * [#346](https://github.com/xataio/client-ts/pull/346) [`ff7e5c6`](https://github.com/xataio/client-ts/commit/ff7e5c6f211913196d8c28600d7a7675ed261688) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix compat with TS 4.8
14
+
15
+ - [#345](https://github.com/xataio/client-ts/pull/345) [`bf64cb8`](https://github.com/xataio/client-ts/commit/bf64cb885d55a0271e966314384324f02ded084e) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix bug with nullable record filters inferred as never
16
+
17
+ * [#334](https://github.com/xataio/client-ts/pull/334) [`ce07601`](https://github.com/xataio/client-ts/commit/ce07601e4ddf9f75e20249d479dc04a63795ca96) Thanks [@SferaDev](https://github.com/SferaDev)! - Add support for TS 4.5
18
+
19
+ - [#325](https://github.com/xataio/client-ts/pull/325) [`12f1ce3`](https://github.com/xataio/client-ts/commit/12f1ce362f6cda27dfdb3afab0800282bddc8b5e) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix offset errors with operations that affect many rows
20
+
21
+ * [#345](https://github.com/xataio/client-ts/pull/345) [`a73a2a2`](https://github.com/xataio/client-ts/commit/a73a2a2014c44cf88eaef42196ba1dba9d516b4a) Thanks [@SferaDev](https://github.com/SferaDev)! - Fix issue with Filter<T> not narrowing down type on object properties
22
+
3
23
  ## 0.10.2
4
24
 
5
25
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -11,8 +11,11 @@ function compact(arr) {
11
11
  function isObject(value) {
12
12
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
13
13
  }
14
+ function isDefined(value) {
15
+ return value !== null && value !== void 0;
16
+ }
14
17
  function isString(value) {
15
- return value !== void 0 && value !== null && typeof value === "string";
18
+ return isDefined(value) && typeof value === "string";
16
19
  }
17
20
  function toBase64(value) {
18
21
  try {
@@ -74,7 +77,12 @@ function getFetchImplementation(userFetch) {
74
77
  return fetchImpl;
75
78
  }
76
79
 
77
- class FetcherError extends Error {
80
+ class ErrorWithCause extends Error {
81
+ constructor(message, options) {
82
+ super(message, options);
83
+ }
84
+ }
85
+ class FetcherError extends ErrorWithCause {
78
86
  constructor(status, data) {
79
87
  super(getMessage(data));
80
88
  this.status = status;
@@ -967,6 +975,9 @@ const PAGINATION_MAX_SIZE = 200;
967
975
  const PAGINATION_DEFAULT_SIZE = 200;
968
976
  const PAGINATION_MAX_OFFSET = 800;
969
977
  const PAGINATION_DEFAULT_OFFSET = 0;
978
+ function isCursorPaginationOptions(options) {
979
+ return isDefined(options) && (isDefined(options.first) || isDefined(options.last) || isDefined(options.after) || isDefined(options.before));
980
+ }
970
981
 
971
982
  var __accessCheck$5 = (obj, member, msg) => {
972
983
  if (!member.has(obj))
@@ -988,7 +999,7 @@ var __privateSet$4 = (obj, member, value, setter) => {
988
999
  };
989
1000
  var _table$1, _repository, _data;
990
1001
  const _Query = class {
991
- constructor(repository, table, data, parent) {
1002
+ constructor(repository, table, data, rawParent) {
992
1003
  __privateAdd$5(this, _table$1, void 0);
993
1004
  __privateAdd$5(this, _repository, void 0);
994
1005
  __privateAdd$5(this, _data, { filter: {} });
@@ -1000,6 +1011,7 @@ const _Query = class {
1000
1011
  } else {
1001
1012
  __privateSet$4(this, _repository, this);
1002
1013
  }
1014
+ const parent = cleanParent(data, rawParent);
1003
1015
  __privateGet$5(this, _data).filter = data.filter ?? parent?.filter ?? {};
1004
1016
  __privateGet$5(this, _data).filter.$any = data.filter?.$any ?? parent?.filter?.$any;
1005
1017
  __privateGet$5(this, _data).filter.$all = data.filter?.$all ?? parent?.filter?.$all;
@@ -1071,13 +1083,13 @@ const _Query = class {
1071
1083
  }
1072
1084
  async *getIterator(options = {}) {
1073
1085
  const { batchSize = 1 } = options;
1074
- let offset = 0;
1075
- let end = false;
1076
- while (!end) {
1077
- const { records, meta } = await this.getPaginated({ ...options, pagination: { size: batchSize, offset } });
1078
- yield records;
1079
- offset += batchSize;
1080
- end = !meta.page.more;
1086
+ let page = await this.getPaginated({ ...options, pagination: { size: batchSize, offset: 0 } });
1087
+ let more = page.hasNextPage();
1088
+ yield page.records;
1089
+ while (more) {
1090
+ page = await page.nextPage();
1091
+ more = page.hasNextPage();
1092
+ yield page.records;
1081
1093
  }
1082
1094
  }
1083
1095
  async getMany(options = {}) {
@@ -1119,6 +1131,12 @@ let Query = _Query;
1119
1131
  _table$1 = new WeakMap();
1120
1132
  _repository = new WeakMap();
1121
1133
  _data = new WeakMap();
1134
+ function cleanParent(data, parent) {
1135
+ if (isCursorPaginationOptions(data.pagination)) {
1136
+ return { ...parent, sorting: void 0, filter: void 0 };
1137
+ }
1138
+ return parent;
1139
+ }
1122
1140
 
1123
1141
  function isIdentifiable(x) {
1124
1142
  return isObject(x) && isString(x?.id);
@@ -1201,6 +1219,8 @@ class RestRepository extends Query {
1201
1219
  }
1202
1220
  async create(a, b) {
1203
1221
  if (Array.isArray(a)) {
1222
+ if (a.length === 0)
1223
+ return [];
1204
1224
  const records = await __privateMethod$2(this, _bulkInsertTableRecords, bulkInsertTableRecords_fn).call(this, a);
1205
1225
  await Promise.all(records.map((record) => __privateMethod$2(this, _setCacheRecord, setCacheRecord_fn).call(this, record)));
1206
1226
  return records;
@@ -1226,27 +1246,36 @@ class RestRepository extends Query {
1226
1246
  }
1227
1247
  throw new Error("Invalid arguments for create method");
1228
1248
  }
1229
- async read(recordId) {
1230
- const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, recordId);
1231
- if (cacheRecord)
1232
- return cacheRecord;
1233
- const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1234
- try {
1235
- const response = await getRecord({
1236
- pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId },
1237
- ...fetchProps
1238
- });
1239
- const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
1240
- return initObject(this.db, schema, __privateGet$4(this, _table), response);
1241
- } catch (e) {
1242
- if (isObject(e) && e.status === 404) {
1243
- return null;
1249
+ async read(a) {
1250
+ if (Array.isArray(a)) {
1251
+ if (a.length === 0)
1252
+ return [];
1253
+ return this.getAll({ filter: { id: { $any: a } } });
1254
+ }
1255
+ if (isString(a)) {
1256
+ const cacheRecord = await __privateMethod$2(this, _getCacheRecord, getCacheRecord_fn).call(this, a);
1257
+ if (cacheRecord)
1258
+ return cacheRecord;
1259
+ const fetchProps = await __privateGet$4(this, _getFetchProps).call(this);
1260
+ try {
1261
+ const response = await getRecord({
1262
+ pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}", tableName: __privateGet$4(this, _table), recordId: a },
1263
+ ...fetchProps
1264
+ });
1265
+ const schema = await __privateMethod$2(this, _getSchema$1, getSchema_fn$1).call(this);
1266
+ return initObject(this.db, schema, __privateGet$4(this, _table), response);
1267
+ } catch (e) {
1268
+ if (isObject(e) && e.status === 404) {
1269
+ return null;
1270
+ }
1271
+ throw e;
1244
1272
  }
1245
- throw e;
1246
1273
  }
1247
1274
  }
1248
1275
  async update(a, b) {
1249
1276
  if (Array.isArray(a)) {
1277
+ if (a.length === 0)
1278
+ return [];
1250
1279
  if (a.length > 100) {
1251
1280
  console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1252
1281
  }
@@ -1268,6 +1297,8 @@ class RestRepository extends Query {
1268
1297
  }
1269
1298
  async createOrUpdate(a, b) {
1270
1299
  if (Array.isArray(a)) {
1300
+ if (a.length === 0)
1301
+ return [];
1271
1302
  if (a.length > 100) {
1272
1303
  console.warn("Bulk update operation is not optimized in the Xata API yet, this request might be slow");
1273
1304
  }
@@ -1289,6 +1320,8 @@ class RestRepository extends Query {
1289
1320
  }
1290
1321
  async delete(a) {
1291
1322
  if (Array.isArray(a)) {
1323
+ if (a.length === 0)
1324
+ return;
1292
1325
  if (a.length > 100) {
1293
1326
  console.warn("Bulk delete operation is not optimized in the Xata API yet, this request might be slow");
1294
1327
  }
@@ -1314,6 +1347,7 @@ class RestRepository extends Query {
1314
1347
  body: {
1315
1348
  query,
1316
1349
  fuzziness: options.fuzziness,
1350
+ highlight: options.highlight,
1317
1351
  filter: options.filter
1318
1352
  },
1319
1353
  ...fetchProps
@@ -1716,10 +1750,10 @@ _schema = new WeakMap();
1716
1750
  _search = new WeakSet();
1717
1751
  search_fn = async function(query, options, getFetchProps) {
1718
1752
  const fetchProps = await getFetchProps();
1719
- const { tables, fuzziness } = options ?? {};
1753
+ const { tables, fuzziness, highlight } = options ?? {};
1720
1754
  const { records } = await searchBranch({
1721
1755
  pathParams: { workspace: "{workspaceId}", dbBranchName: "{dbBranch}" },
1722
- body: { tables, query, fuzziness },
1756
+ body: { tables, query, fuzziness, highlight },
1723
1757
  ...fetchProps
1724
1758
  });
1725
1759
  return records;
@@ -2009,6 +2043,7 @@ exports.insertRecord = insertRecord;
2009
2043
  exports.insertRecordWithID = insertRecordWithID;
2010
2044
  exports.inviteWorkspaceMember = inviteWorkspaceMember;
2011
2045
  exports.is = is;
2046
+ exports.isCursorPaginationOptions = isCursorPaginationOptions;
2012
2047
  exports.isIdentifiable = isIdentifiable;
2013
2048
  exports.isNot = isNot;
2014
2049
  exports.isXataRecord = isXataRecord;